🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@agenite/llm

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@agenite/llm - npm Package Compare versions

Comparing version
0.4.0
to
0.5.0
+6
-0
CHANGELOG.md
# @agenite/llm
## 0.5.0
### Minor Changes
- b2bc136: Update token usage and have common provider interface
## 0.4.0

@@ -4,0 +10,0 @@

@@ -42,8 +42,34 @@ 'use strict';

};
var assistantTextMessage = (message) => {
return {
role: "assistant",
content: [
{
type: "text",
text: message
}
]
};
};
var toolUseMessage = (toolUse) => {
return {
role: "assistant",
content: [toolUse]
};
};
var toolResultMessage = (toolResult) => {
return {
role: "user",
content: [toolResult]
};
};
exports.BaseLLMProvider = BaseLLMProvider;
exports.assistantTextMessage = assistantTextMessage;
exports.convertStringToMessages = convertStringToMessages;
exports.iterateFromMethods = iterateFromMethods;
exports.toolResultMessage = toolResultMessage;
exports.toolUseMessage = toolUseMessage;
exports.userTextMessage = userTextMessage;
//# sourceMappingURL=index.cjs.map
//# sourceMappingURL=index.cjs.map
+1
-1

@@ -1,1 +0,1 @@

{"version":3,"sources":["../src/utils.ts","../src/messages/utils.ts"],"names":[],"mappings":";;;AAYO,SAAS,wBACd,OACe,EAAA;AACf,EAAI,IAAA,OAAO,YAAY,QAAU,EAAA;AAC/B,IAAO,OAAA;AAAA,MACL;AAAA,QACE,IAAM,EAAA,MAAA;AAAA,QACN,SAAS,CAAC,EAAE,MAAM,MAAQ,EAAA,IAAA,EAAM,SAAS;AAAA;AAC3C,KACF;AAAA;AAGF,EAAO,OAAA,OAAA;AACT;AAKA,gBAAuB,kBAAA,CACrB,QACA,EAAA,KAAA,EACA,OAC0D,EAAA;AAC1D,EAAM,MAAA,EAAE,QAAW,GAAA,OAAA;AAEnB,EAAA,IAAI,MAAQ,EAAA;AAEV,IAAA,MAAM,SAAY,GAAA,QAAA,CAAS,MAAO,CAAA,KAAA,EAAO,OAAO,CAAA;AAEhD,IAAA,OAAO,OAAO,SAAA;AAAA,GACT,MAAA;AAEL,IAAA,OAAO,MAAM,QAAA,CAAS,QAAS,CAAA,KAAA,EAAO,OAAO,CAAA;AAAA;AAEjD;AAKO,IAAe,kBAAf,MAAsD;AAAA,EAc3D,OAAO,OACL,CAAA,KAAA,EACA,OAC0D,EAAA;AAC1D,IAAA,OAAO,OAAO,kBAAA,CAAmB,IAAM,EAAA,KAAA,EAAO,OAAO,CAAA;AAAA;AAEzD;;;ACrEa,IAAA,eAAA,GAAkB,CAAC,OAAiC,KAAA;AAC/D,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP;AAAA,QACE,IAAM,EAAA,MAAA;AAAA,QACN,IAAM,EAAA;AAAA;AACR;AACF,GACF;AACF","file":"index.cjs","sourcesContent":["import type {\n BaseMessage,\n GenerateOptions,\n IterateGenerateOptions,\n LLMProvider,\n GenerateResponse,\n PartialReturn,\n} from './types';\n\n/**\n * Converts a string message to BaseMessage array\n */\nexport function convertStringToMessages(\n message: string | BaseMessage[]\n): BaseMessage[] {\n if (typeof message === 'string') {\n return [\n {\n role: 'user',\n content: [{ type: 'text', text: message }],\n },\n ];\n }\n\n return message;\n}\n\n/**\n * Base implementation of iterate using generate and stream\n */\nexport async function* iterateFromMethods(\n provider: LLMProvider,\n input: string | BaseMessage[],\n options: IterateGenerateOptions\n): AsyncGenerator<PartialReturn, GenerateResponse, unknown> {\n const { stream } = options;\n\n if (stream) {\n // For streaming, use the stream method and yield each chunk\n const streamGen = provider.stream(input, options);\n\n return yield* streamGen;\n } else {\n // For non-streaming, use generate and return the response\n return await provider.generate(input, options);\n }\n}\n\n/**\n * Base class for LLM providers that implements iterate using generate and stream\n */\nexport abstract class BaseLLMProvider implements LLMProvider {\n abstract name: string;\n abstract version?: string;\n\n abstract generate(\n input: string,\n options?: Partial<GenerateOptions>\n ): Promise<GenerateResponse>;\n\n abstract stream(\n input: string,\n options?: Partial<GenerateOptions>\n ): AsyncGenerator<PartialReturn, GenerateResponse, unknown>;\n\n async *iterate(\n input: string | BaseMessage[],\n options: IterateGenerateOptions\n ): AsyncGenerator<PartialReturn, GenerateResponse, unknown> {\n return yield* iterateFromMethods(this, input, options);\n }\n}\n","import { BaseMessage } from '../types';\n\nexport const userTextMessage = (message: string): BaseMessage => {\n return {\n role: 'user',\n content: [\n {\n type: 'text',\n text: message,\n },\n ],\n };\n};\n"]}
{"version":3,"sources":["../src/utils.ts","../src/messages/utils.ts"],"names":[],"mappings":";;;AAYO,SAAS,wBACd,OACe,EAAA;AACf,EAAI,IAAA,OAAO,YAAY,QAAU,EAAA;AAC/B,IAAO,OAAA;AAAA,MACL;AAAA,QACE,IAAM,EAAA,MAAA;AAAA,QACN,SAAS,CAAC,EAAE,MAAM,MAAQ,EAAA,IAAA,EAAM,SAAS;AAAA;AAC3C,KACF;AAAA;AAGF,EAAO,OAAA,OAAA;AACT;AAKA,gBAAuB,kBAAA,CACrB,QACA,EAAA,KAAA,EACA,OAC0D,EAAA;AAC1D,EAAM,MAAA,EAAE,QAAW,GAAA,OAAA;AAEnB,EAAA,IAAI,MAAQ,EAAA;AAEV,IAAA,MAAM,SAAY,GAAA,QAAA,CAAS,MAAO,CAAA,KAAA,EAAO,OAAO,CAAA;AAEhD,IAAA,OAAO,OAAO,SAAA;AAAA,GACT,MAAA;AAEL,IAAA,OAAO,MAAM,QAAA,CAAS,QAAS,CAAA,KAAA,EAAO,OAAO,CAAA;AAAA;AAEjD;AAKO,IAAe,kBAAf,MAAsD;AAAA,EAc3D,OAAO,OACL,CAAA,KAAA,EACA,OAC0D,EAAA;AAC1D,IAAA,OAAO,OAAO,kBAAA,CAAmB,IAAM,EAAA,KAAA,EAAO,OAAO,CAAA;AAAA;AAEzD;;;ACrEa,IAAA,eAAA,GAAkB,CAAC,OAAiC,KAAA;AAC/D,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP;AAAA,QACE,IAAM,EAAA,MAAA;AAAA,QACN,IAAM,EAAA;AAAA;AACR;AACF,GACF;AACF;AACa,IAAA,oBAAA,GAAuB,CAAC,OAAiC,KAAA;AACpE,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,WAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP;AAAA,QACE,IAAM,EAAA,MAAA;AAAA,QACN,IAAM,EAAA;AAAA;AACR;AACF,GACF;AACF;AAEa,IAAA,cAAA,GAAiB,CAAC,OAAuC,KAAA;AACpE,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,WAAA;AAAA,IACN,OAAA,EAAS,CAAC,OAAO;AAAA,GACnB;AACF;AAEa,IAAA,iBAAA,GAAoB,CAAC,UAA6C,KAAA;AAC7E,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,OAAA,EAAS,CAAC,UAAU;AAAA,GACtB;AACF","file":"index.cjs","sourcesContent":["import type {\n BaseMessage,\n GenerateOptions,\n IterateGenerateOptions,\n LLMProvider,\n GenerateResponse,\n PartialReturn,\n} from './types';\n\n/**\n * Converts a string message to BaseMessage array\n */\nexport function convertStringToMessages(\n message: string | BaseMessage[]\n): BaseMessage[] {\n if (typeof message === 'string') {\n return [\n {\n role: 'user',\n content: [{ type: 'text', text: message }],\n },\n ];\n }\n\n return message;\n}\n\n/**\n * Base implementation of iterate using generate and stream\n */\nexport async function* iterateFromMethods(\n provider: LLMProvider,\n input: string | BaseMessage[],\n options: IterateGenerateOptions\n): AsyncGenerator<PartialReturn, GenerateResponse, unknown> {\n const { stream } = options;\n\n if (stream) {\n // For streaming, use the stream method and yield each chunk\n const streamGen = provider.stream(input, options);\n\n return yield* streamGen;\n } else {\n // For non-streaming, use generate and return the response\n return await provider.generate(input, options);\n }\n}\n\n/**\n * Base class for LLM providers that implements iterate using generate and stream\n */\nexport abstract class BaseLLMProvider implements LLMProvider {\n abstract name: string;\n abstract version?: string;\n\n abstract generate(\n input: string,\n options?: Partial<GenerateOptions>\n ): Promise<GenerateResponse>;\n\n abstract stream(\n input: string,\n options?: Partial<GenerateOptions>\n ): AsyncGenerator<PartialReturn, GenerateResponse, unknown>;\n\n async *iterate(\n input: string | BaseMessage[],\n options: IterateGenerateOptions\n ): AsyncGenerator<PartialReturn, GenerateResponse, unknown> {\n return yield* iterateFromMethods(this, input, options);\n }\n}\n","import { BaseMessage, ToolResultBlock, ToolUseBlock } from '../types';\n\nexport const userTextMessage = (message: string): BaseMessage => {\n return {\n role: 'user',\n content: [\n {\n type: 'text',\n text: message,\n },\n ],\n };\n};\nexport const assistantTextMessage = (message: string): BaseMessage => {\n return {\n role: 'assistant',\n content: [\n {\n type: 'text',\n text: message,\n },\n ],\n };\n};\n\nexport const toolUseMessage = (toolUse: ToolUseBlock): BaseMessage => {\n return {\n role: 'assistant',\n content: [toolUse],\n };\n};\n\nexport const toolResultMessage = (toolResult: ToolResultBlock): BaseMessage => {\n return {\n role: 'user',\n content: [toolResult],\n };\n};\n"]}

@@ -67,7 +67,9 @@ /**

*/
interface TokenUsage {
type TokenUsage = {
inputTokens: number;
outputTokens: number;
modelId: string;
}
inputCost: number;
outputCost: number;
model: string;
};
/**

@@ -82,16 +84,32 @@ * Stop reasons for generation

content: Array<ContentBlock>;
tokens: TokenUsage[];
duration: number;
tokenUsage: TokenUsage;
stopReason?: StopReason;
}
/**
* Base configuration for any LLM provider
* Base configuration for any LLM provider to use for the provider
* This maintains consistency across all providers, although some providers may not use all of these options
*/
interface BaseLLMConfig {
organization?: string;
/**
* Model ID to use for the provider
*/
model?: string;
/**
* Whether to enable thinking
*/
enableThinking?: boolean;
/**
* Base URL for the provider
*/
baseURL?: string;
maxRetries?: number;
timeout?: number;
}
type PartialReturn = {
/**
* Partial return type for streaming
*/
type PartialReturn =
/**
* Text block
* isStart and isEnd are used to determine if the text is the start or end of the response
*/
{
type: 'text';

@@ -101,3 +119,8 @@ text: string;

isEnd?: boolean;
} | {
}
/**
* Thinking block
* isStart and isEnd are used to determine if the thinking is the start or end of the response
*/
| {
type: 'thinking';

@@ -107,5 +130,12 @@ thinking: string;

isEnd?: boolean;
} | {
}
/**
* Tool use block
* isStart and isEnd are used to determine if the tool use is the start or end of the response
* toolUseInputString as string until the tool call is complete
*/
| {
type: 'toolUse';
toolUse: ToolUseBlock;
toolUseInputString?: string;
toolUse?: ToolUseBlock;
isStart?: boolean;

@@ -134,4 +164,2 @@ isEnd?: boolean;

interface LLMProvider {
name: string;
version?: string;
/**

@@ -181,3 +209,6 @@ * Simple text generation with full response

declare const userTextMessage: (message: string) => BaseMessage;
declare const assistantTextMessage: (message: string) => BaseMessage;
declare const toolUseMessage: (toolUse: ToolUseBlock) => BaseMessage;
declare const toolResultMessage: (toolResult: ToolResultBlock) => BaseMessage;
export { type BaseLLMConfig, BaseLLMProvider, type BaseMessage, type ContentBlock, type DocumentBlock, type GenerateOptions, type GenerateResponse, type ImageBlock, type IterateGenerateOptions, type LLMProvider, type PartialReturn, type RedactedThinkingBlock, type Role, type StopReason, type TextBlock, type ThinkingBlock, type TokenUsage, type ToolDefinition, type ToolResultBlock, type ToolSchema, type ToolUseBlock, convertStringToMessages, iterateFromMethods, userTextMessage };
export { type BaseLLMConfig, BaseLLMProvider, type BaseMessage, type ContentBlock, type DocumentBlock, type GenerateOptions, type GenerateResponse, type ImageBlock, type IterateGenerateOptions, type LLMProvider, type PartialReturn, type RedactedThinkingBlock, type Role, type StopReason, type TextBlock, type ThinkingBlock, type TokenUsage, type ToolDefinition, type ToolResultBlock, type ToolSchema, type ToolUseBlock, assistantTextMessage, convertStringToMessages, iterateFromMethods, toolResultMessage, toolUseMessage, userTextMessage };

@@ -67,7 +67,9 @@ /**

*/
interface TokenUsage {
type TokenUsage = {
inputTokens: number;
outputTokens: number;
modelId: string;
}
inputCost: number;
outputCost: number;
model: string;
};
/**

@@ -82,16 +84,32 @@ * Stop reasons for generation

content: Array<ContentBlock>;
tokens: TokenUsage[];
duration: number;
tokenUsage: TokenUsage;
stopReason?: StopReason;
}
/**
* Base configuration for any LLM provider
* Base configuration for any LLM provider to use for the provider
* This maintains consistency across all providers, although some providers may not use all of these options
*/
interface BaseLLMConfig {
organization?: string;
/**
* Model ID to use for the provider
*/
model?: string;
/**
* Whether to enable thinking
*/
enableThinking?: boolean;
/**
* Base URL for the provider
*/
baseURL?: string;
maxRetries?: number;
timeout?: number;
}
type PartialReturn = {
/**
* Partial return type for streaming
*/
type PartialReturn =
/**
* Text block
* isStart and isEnd are used to determine if the text is the start or end of the response
*/
{
type: 'text';

@@ -101,3 +119,8 @@ text: string;

isEnd?: boolean;
} | {
}
/**
* Thinking block
* isStart and isEnd are used to determine if the thinking is the start or end of the response
*/
| {
type: 'thinking';

@@ -107,5 +130,12 @@ thinking: string;

isEnd?: boolean;
} | {
}
/**
* Tool use block
* isStart and isEnd are used to determine if the tool use is the start or end of the response
* toolUseInputString as string until the tool call is complete
*/
| {
type: 'toolUse';
toolUse: ToolUseBlock;
toolUseInputString?: string;
toolUse?: ToolUseBlock;
isStart?: boolean;

@@ -134,4 +164,2 @@ isEnd?: boolean;

interface LLMProvider {
name: string;
version?: string;
/**

@@ -181,3 +209,6 @@ * Simple text generation with full response

declare const userTextMessage: (message: string) => BaseMessage;
declare const assistantTextMessage: (message: string) => BaseMessage;
declare const toolUseMessage: (toolUse: ToolUseBlock) => BaseMessage;
declare const toolResultMessage: (toolResult: ToolResultBlock) => BaseMessage;
export { type BaseLLMConfig, BaseLLMProvider, type BaseMessage, type ContentBlock, type DocumentBlock, type GenerateOptions, type GenerateResponse, type ImageBlock, type IterateGenerateOptions, type LLMProvider, type PartialReturn, type RedactedThinkingBlock, type Role, type StopReason, type TextBlock, type ThinkingBlock, type TokenUsage, type ToolDefinition, type ToolResultBlock, type ToolSchema, type ToolUseBlock, convertStringToMessages, iterateFromMethods, userTextMessage };
export { type BaseLLMConfig, BaseLLMProvider, type BaseMessage, type ContentBlock, type DocumentBlock, type GenerateOptions, type GenerateResponse, type ImageBlock, type IterateGenerateOptions, type LLMProvider, type PartialReturn, type RedactedThinkingBlock, type Role, type StopReason, type TextBlock, type ThinkingBlock, type TokenUsage, type ToolDefinition, type ToolResultBlock, type ToolSchema, type ToolUseBlock, assistantTextMessage, convertStringToMessages, iterateFromMethods, toolResultMessage, toolUseMessage, userTextMessage };

@@ -40,5 +40,28 @@ // src/utils.ts

};
var assistantTextMessage = (message) => {
return {
role: "assistant",
content: [
{
type: "text",
text: message
}
]
};
};
var toolUseMessage = (toolUse) => {
return {
role: "assistant",
content: [toolUse]
};
};
var toolResultMessage = (toolResult) => {
return {
role: "user",
content: [toolResult]
};
};
export { BaseLLMProvider, convertStringToMessages, iterateFromMethods, userTextMessage };
export { BaseLLMProvider, assistantTextMessage, convertStringToMessages, iterateFromMethods, toolResultMessage, toolUseMessage, userTextMessage };
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map

@@ -1,1 +0,1 @@

{"version":3,"sources":["../src/utils.ts","../src/messages/utils.ts"],"names":[],"mappings":";AAYO,SAAS,wBACd,OACe,EAAA;AACf,EAAI,IAAA,OAAO,YAAY,QAAU,EAAA;AAC/B,IAAO,OAAA;AAAA,MACL;AAAA,QACE,IAAM,EAAA,MAAA;AAAA,QACN,SAAS,CAAC,EAAE,MAAM,MAAQ,EAAA,IAAA,EAAM,SAAS;AAAA;AAC3C,KACF;AAAA;AAGF,EAAO,OAAA,OAAA;AACT;AAKA,gBAAuB,kBAAA,CACrB,QACA,EAAA,KAAA,EACA,OAC0D,EAAA;AAC1D,EAAM,MAAA,EAAE,QAAW,GAAA,OAAA;AAEnB,EAAA,IAAI,MAAQ,EAAA;AAEV,IAAA,MAAM,SAAY,GAAA,QAAA,CAAS,MAAO,CAAA,KAAA,EAAO,OAAO,CAAA;AAEhD,IAAA,OAAO,OAAO,SAAA;AAAA,GACT,MAAA;AAEL,IAAA,OAAO,MAAM,QAAA,CAAS,QAAS,CAAA,KAAA,EAAO,OAAO,CAAA;AAAA;AAEjD;AAKO,IAAe,kBAAf,MAAsD;AAAA,EAc3D,OAAO,OACL,CAAA,KAAA,EACA,OAC0D,EAAA;AAC1D,IAAA,OAAO,OAAO,kBAAA,CAAmB,IAAM,EAAA,KAAA,EAAO,OAAO,CAAA;AAAA;AAEzD;;;ACrEa,IAAA,eAAA,GAAkB,CAAC,OAAiC,KAAA;AAC/D,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP;AAAA,QACE,IAAM,EAAA,MAAA;AAAA,QACN,IAAM,EAAA;AAAA;AACR;AACF,GACF;AACF","file":"index.js","sourcesContent":["import type {\n BaseMessage,\n GenerateOptions,\n IterateGenerateOptions,\n LLMProvider,\n GenerateResponse,\n PartialReturn,\n} from './types';\n\n/**\n * Converts a string message to BaseMessage array\n */\nexport function convertStringToMessages(\n message: string | BaseMessage[]\n): BaseMessage[] {\n if (typeof message === 'string') {\n return [\n {\n role: 'user',\n content: [{ type: 'text', text: message }],\n },\n ];\n }\n\n return message;\n}\n\n/**\n * Base implementation of iterate using generate and stream\n */\nexport async function* iterateFromMethods(\n provider: LLMProvider,\n input: string | BaseMessage[],\n options: IterateGenerateOptions\n): AsyncGenerator<PartialReturn, GenerateResponse, unknown> {\n const { stream } = options;\n\n if (stream) {\n // For streaming, use the stream method and yield each chunk\n const streamGen = provider.stream(input, options);\n\n return yield* streamGen;\n } else {\n // For non-streaming, use generate and return the response\n return await provider.generate(input, options);\n }\n}\n\n/**\n * Base class for LLM providers that implements iterate using generate and stream\n */\nexport abstract class BaseLLMProvider implements LLMProvider {\n abstract name: string;\n abstract version?: string;\n\n abstract generate(\n input: string,\n options?: Partial<GenerateOptions>\n ): Promise<GenerateResponse>;\n\n abstract stream(\n input: string,\n options?: Partial<GenerateOptions>\n ): AsyncGenerator<PartialReturn, GenerateResponse, unknown>;\n\n async *iterate(\n input: string | BaseMessage[],\n options: IterateGenerateOptions\n ): AsyncGenerator<PartialReturn, GenerateResponse, unknown> {\n return yield* iterateFromMethods(this, input, options);\n }\n}\n","import { BaseMessage } from '../types';\n\nexport const userTextMessage = (message: string): BaseMessage => {\n return {\n role: 'user',\n content: [\n {\n type: 'text',\n text: message,\n },\n ],\n };\n};\n"]}
{"version":3,"sources":["../src/utils.ts","../src/messages/utils.ts"],"names":[],"mappings":";AAYO,SAAS,wBACd,OACe,EAAA;AACf,EAAI,IAAA,OAAO,YAAY,QAAU,EAAA;AAC/B,IAAO,OAAA;AAAA,MACL;AAAA,QACE,IAAM,EAAA,MAAA;AAAA,QACN,SAAS,CAAC,EAAE,MAAM,MAAQ,EAAA,IAAA,EAAM,SAAS;AAAA;AAC3C,KACF;AAAA;AAGF,EAAO,OAAA,OAAA;AACT;AAKA,gBAAuB,kBAAA,CACrB,QACA,EAAA,KAAA,EACA,OAC0D,EAAA;AAC1D,EAAM,MAAA,EAAE,QAAW,GAAA,OAAA;AAEnB,EAAA,IAAI,MAAQ,EAAA;AAEV,IAAA,MAAM,SAAY,GAAA,QAAA,CAAS,MAAO,CAAA,KAAA,EAAO,OAAO,CAAA;AAEhD,IAAA,OAAO,OAAO,SAAA;AAAA,GACT,MAAA;AAEL,IAAA,OAAO,MAAM,QAAA,CAAS,QAAS,CAAA,KAAA,EAAO,OAAO,CAAA;AAAA;AAEjD;AAKO,IAAe,kBAAf,MAAsD;AAAA,EAc3D,OAAO,OACL,CAAA,KAAA,EACA,OAC0D,EAAA;AAC1D,IAAA,OAAO,OAAO,kBAAA,CAAmB,IAAM,EAAA,KAAA,EAAO,OAAO,CAAA;AAAA;AAEzD;;;ACrEa,IAAA,eAAA,GAAkB,CAAC,OAAiC,KAAA;AAC/D,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP;AAAA,QACE,IAAM,EAAA,MAAA;AAAA,QACN,IAAM,EAAA;AAAA;AACR;AACF,GACF;AACF;AACa,IAAA,oBAAA,GAAuB,CAAC,OAAiC,KAAA;AACpE,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,WAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP;AAAA,QACE,IAAM,EAAA,MAAA;AAAA,QACN,IAAM,EAAA;AAAA;AACR;AACF,GACF;AACF;AAEa,IAAA,cAAA,GAAiB,CAAC,OAAuC,KAAA;AACpE,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,WAAA;AAAA,IACN,OAAA,EAAS,CAAC,OAAO;AAAA,GACnB;AACF;AAEa,IAAA,iBAAA,GAAoB,CAAC,UAA6C,KAAA;AAC7E,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,OAAA,EAAS,CAAC,UAAU;AAAA,GACtB;AACF","file":"index.js","sourcesContent":["import type {\n BaseMessage,\n GenerateOptions,\n IterateGenerateOptions,\n LLMProvider,\n GenerateResponse,\n PartialReturn,\n} from './types';\n\n/**\n * Converts a string message to BaseMessage array\n */\nexport function convertStringToMessages(\n message: string | BaseMessage[]\n): BaseMessage[] {\n if (typeof message === 'string') {\n return [\n {\n role: 'user',\n content: [{ type: 'text', text: message }],\n },\n ];\n }\n\n return message;\n}\n\n/**\n * Base implementation of iterate using generate and stream\n */\nexport async function* iterateFromMethods(\n provider: LLMProvider,\n input: string | BaseMessage[],\n options: IterateGenerateOptions\n): AsyncGenerator<PartialReturn, GenerateResponse, unknown> {\n const { stream } = options;\n\n if (stream) {\n // For streaming, use the stream method and yield each chunk\n const streamGen = provider.stream(input, options);\n\n return yield* streamGen;\n } else {\n // For non-streaming, use generate and return the response\n return await provider.generate(input, options);\n }\n}\n\n/**\n * Base class for LLM providers that implements iterate using generate and stream\n */\nexport abstract class BaseLLMProvider implements LLMProvider {\n abstract name: string;\n abstract version?: string;\n\n abstract generate(\n input: string,\n options?: Partial<GenerateOptions>\n ): Promise<GenerateResponse>;\n\n abstract stream(\n input: string,\n options?: Partial<GenerateOptions>\n ): AsyncGenerator<PartialReturn, GenerateResponse, unknown>;\n\n async *iterate(\n input: string | BaseMessage[],\n options: IterateGenerateOptions\n ): AsyncGenerator<PartialReturn, GenerateResponse, unknown> {\n return yield* iterateFromMethods(this, input, options);\n }\n}\n","import { BaseMessage, ToolResultBlock, ToolUseBlock } from '../types';\n\nexport const userTextMessage = (message: string): BaseMessage => {\n return {\n role: 'user',\n content: [\n {\n type: 'text',\n text: message,\n },\n ],\n };\n};\nexport const assistantTextMessage = (message: string): BaseMessage => {\n return {\n role: 'assistant',\n content: [\n {\n type: 'text',\n text: message,\n },\n ],\n };\n};\n\nexport const toolUseMessage = (toolUse: ToolUseBlock): BaseMessage => {\n return {\n role: 'assistant',\n content: [toolUse],\n };\n};\n\nexport const toolResultMessage = (toolResult: ToolResultBlock): BaseMessage => {\n return {\n role: 'user',\n content: [toolResult],\n };\n};\n"]}
{
"name": "@agenite/llm",
"version": "0.4.0",
"version": "0.5.0",
"description": "LLM interface for Agenite",

@@ -18,8 +18,8 @@ "private": false,

"devDependencies": {
"@types/node": "^20.17.24",
"@types/node": "^20.17.30",
"tsup": "^8.4.0",
"typescript": "^5.8.2",
"@repo/typescript-config": "0.1.0",
"@repo/tsup-config": "0.0.3",
"@repo/eslint-config": "0.1.0"
"typescript": "^5.8.3",
"@repo/eslint-config": "0.2.0",
"@repo/tsup-config": "0.1.0",
"@repo/typescript-config": "0.1.0"
},

@@ -26,0 +26,0 @@ "publishConfig": {