@easynet/agent-llm 1.0.15 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/api/create-agent-llm.d.ts +1 -19
  2. package/dist/api/create-agent-llm.d.ts.map +1 -1
  3. package/dist/{chunk-AZDHRCIM.js → chunk-CWU7GNFB.js} +38 -263
  4. package/dist/chunk-CWU7GNFB.js.map +1 -0
  5. package/dist/cli/index.d.ts +0 -7
  6. package/dist/cli/index.d.ts.map +1 -1
  7. package/dist/cli/index.js +3 -7
  8. package/dist/cli/index.js.map +1 -1
  9. package/dist/config/index.d.ts +0 -3
  10. package/dist/config/index.d.ts.map +1 -1
  11. package/dist/config/loader.d.ts +0 -14
  12. package/dist/config/loader.d.ts.map +1 -1
  13. package/dist/config/parser.d.ts +0 -3
  14. package/dist/config/parser.d.ts.map +1 -1
  15. package/dist/connectivity/check.d.ts +0 -23
  16. package/dist/connectivity/check.d.ts.map +1 -1
  17. package/dist/connectivity/index.d.ts +2 -4
  18. package/dist/connectivity/index.d.ts.map +1 -1
  19. package/dist/connectivity/types.d.ts +0 -11
  20. package/dist/connectivity/types.d.ts.map +1 -1
  21. package/dist/extensions/index.d.ts +2 -5
  22. package/dist/extensions/index.d.ts.map +1 -1
  23. package/dist/extensions/loader.d.ts +1 -17
  24. package/dist/extensions/loader.d.ts.map +1 -1
  25. package/dist/extensions/npm-protocol.d.ts +2 -33
  26. package/dist/extensions/npm-protocol.d.ts.map +1 -1
  27. package/dist/index.d.ts +9 -11
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +2 -41
  30. package/dist/index.js.map +1 -1
  31. package/dist/langchain/index.d.ts +13 -3
  32. package/dist/langchain/index.d.ts.map +1 -1
  33. package/dist/registry/chat-model.d.ts +1 -8
  34. package/dist/registry/chat-model.d.ts.map +1 -1
  35. package/dist/registry/index.d.ts +0 -5
  36. package/dist/registry/index.d.ts.map +1 -1
  37. package/dist/types.d.ts +8 -165
  38. package/dist/types.d.ts.map +1 -1
  39. package/package.json +6 -5
  40. package/dist/chunk-AZDHRCIM.js.map +0 -1
  41. package/dist/langchain/adapter.d.ts +0 -21
  42. package/dist/langchain/adapter.d.ts.map +0 -1
  43. package/dist/providers/index.d.ts +0 -7
  44. package/dist/providers/index.d.ts.map +0 -1
  45. package/dist/providers/openai.d.ts +0 -9
  46. package/dist/providers/openai.d.ts.map +0 -1
  47. package/dist/registry/client.d.ts +0 -13
  48. package/dist/registry/client.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ AGENT_LLM_PROVIDER_FIELD,
2
3
  CIS_UNREACHABLE_REMINDER,
3
4
  NPM_PROTOCOL_PREFIX,
4
5
  buildUnreachableError,
@@ -6,10 +7,6 @@ import {
6
7
  createAgentLlM,
7
8
  createChatModelFromLlmConfig,
8
9
  createChatModelFromLlmConfigWithNpm,
9
- createClient,
10
- createOpenAIChatClient,
11
- createOpenAIClient,
12
- createOpenAIImageClient,
13
10
  discoverLLMExtensions,
14
11
  ensureNpmPackageInstalled,
15
12
  getChatModelFactory,
@@ -23,41 +20,11 @@ import {
23
20
  parseLlmYaml,
24
21
  parseNpmProviderSpec,
25
22
  registerChatModelProvider,
26
- registerProvider,
27
23
  resolveLLMExtensionPackages,
28
24
  resolveLlmSectionWithNpm,
29
25
  resolveNpmProvider,
30
26
  substituteEnv
31
- } from "./chunk-AZDHRCIM.js";
32
-
33
- // src/registry/client.ts
34
- function createLLMRegistry(options) {
35
- const { defaultId, configs } = parseLlmSection(options.llmSection);
36
- const map = /* @__PURE__ */ new Map();
37
- for (const config of configs) {
38
- try {
39
- const client = createClient(config);
40
- map.set(config.id, client);
41
- } catch (err) {
42
- console.warn(`[agent-llm] Skip LLM "${config.id}": ${err instanceof Error ? err.message : String(err)}`);
43
- }
44
- }
45
- return {
46
- get(id) {
47
- return map.get(id);
48
- },
49
- defaultId() {
50
- if (map.has(defaultId)) return defaultId;
51
- return map.size > 0 ? [...map.keys()][0] : void 0;
52
- },
53
- ids() {
54
- return [...map.keys()];
55
- }
56
- };
57
- }
58
-
59
- // src/types.ts
60
- var AGENT_LLM_PROVIDER_FIELD = "agentLlmProvider";
27
+ } from "./chunk-CWU7GNFB.js";
61
28
  export {
62
29
  AGENT_LLM_PROVIDER_FIELD,
63
30
  CIS_UNREACHABLE_REMINDER,
@@ -67,11 +34,6 @@ export {
67
34
  createAgentLlM,
68
35
  createChatModelFromLlmConfig,
69
36
  createChatModelFromLlmConfigWithNpm,
70
- createClient,
71
- createLLMRegistry,
72
- createOpenAIChatClient,
73
- createOpenAIClient,
74
- createOpenAIImageClient,
75
37
  discoverLLMExtensions,
76
38
  ensureNpmPackageInstalled,
77
39
  getChatModelFactory,
@@ -85,7 +47,6 @@ export {
85
47
  parseLlmYaml,
86
48
  parseNpmProviderSpec,
87
49
  registerChatModelProvider,
88
- registerProvider,
89
50
  resolveLLMExtensionPackages,
90
51
  resolveLlmSectionWithNpm,
91
52
  resolveNpmProvider,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/registry/client.ts","../src/types.ts"],"sourcesContent":["/**\n * Create LLM registry from agent.yaml llm section.\n */\n\nimport { parseLlmSection } from \"../config/parser.js\";\nimport { createClient } from \"../providers/index.js\";\nimport type { AgentConfigLlmSection, ILLMClient, ILLMRegistry } from \"../types.js\";\n\nexport interface CreateLLMRegistryOptions {\n /** Parsed llm section (e.g. from loadAgentConfig's config.llm) */\n llmSection: AgentConfigLlmSection | null | undefined;\n}\n\n/**\n * Create LLM registry from agent config llm section; supports multiple providers/models, each LLM has id and type.\n */\nexport function createLLMRegistry(options: CreateLLMRegistryOptions): ILLMRegistry {\n const { defaultId, configs } = parseLlmSection(options.llmSection);\n const map = new Map<string, ILLMClient>();\n\n for (const config of configs) {\n try {\n const client = createClient(config);\n map.set(config.id, client);\n } catch (err) {\n console.warn(`[agent-llm] Skip LLM \"${config.id}\": ${err instanceof Error ? err.message : String(err)}`);\n }\n }\n\n return {\n get(id: string): ILLMClient | undefined {\n return map.get(id);\n },\n defaultId(): string | undefined {\n if (map.has(defaultId)) return defaultId;\n return map.size > 0 ? [...map.keys()][0] : undefined;\n },\n ids(): string[] {\n return [...map.keys()];\n },\n };\n}\n","/**\n * Agent LLM: OpenAI-compatible format only (/v1/chat/completions etc.).\n * Multi-instance: each LLM has id and type; optional baseURL for other compatible endpoints.\n */\n\n/** LLM type: chat = conversation, image = image generation (OpenAI-compatible format) */\nexport type LLMType = \"chat\" | \"image\";\n\n/** Single LLM config: id, type, model; OpenAI-compatible API only */\nexport interface LLMConfig {\n /** Unique id for fetching the instance from the registry */\n id: string;\n /** chat | image */\n type: LLMType;\n /** Must be openai or openai-compatible; only this format is supported */\n provider: string;\n /** Model name, e.g. gpt-4o-mini, dall-e-3 */\n model?: string;\n /** Temperature etc.; commonly used for chat */\n temperature?: number;\n /** API key; can also be set via env */\n apiKey?: string;\n /** OpenAI-compatible endpoint baseURL (e.g. Azure, local proxy, other /v1-compatible vendors) */\n baseURL?: string;\n /** Other options (passed through) */\n [key: string]: unknown;\n}\n\n/** agent.yaml llm section: flat (each model keyed by name), default+instances, or single object */\nexport interface AgentConfigLlmSection {\n /** Default model name (id) to use */\n default?: string;\n /** npm package name or array for dynamic load; e.g. \"wallee-llm\" or [\"wallee-llm\"] */\n type?: string | string[];\n /** Array of LLM configs */\n instances?: LLMConfig[];\n /** Single-object form: provider, model etc., parsed as id=default chat */\n provider?: string;\n model?: string;\n name?: string;\n temperature?: number;\n apiKey?: string;\n baseURL?: string;\n base_url?: string;\n /** Flat: strong/medium/fast etc. name → config (provider, base_url, name, options) */\n [key: string]: unknown;\n}\n\n/** Single chat message */\nexport interface ChatMessage {\n role: \"system\" | \"user\" | \"assistant\";\n content: string;\n}\n\n/** Minimal chat result */\nexport interface ChatResult {\n content: string;\n usage?: { promptTokens?: number; completionTokens?: number };\n}\n\n/** Stream chunk for chat responses */\nexport interface ChatStreamChunk {\n content: string;\n done: boolean;\n usage?: { promptTokens?: number; completionTokens?: number };\n}\n\n/** OpenAI-compatible tool definition (function) */\nexport interface ToolDefinition {\n type: \"function\";\n function: {\n name: string;\n description?: string;\n parameters?: object;\n };\n}\n\n/** Message with tool calls (assistant may include tool_calls; tool = tool result) */\nexport type ChatWithToolsMessage =\n | ChatMessage\n | { role: \"tool\"; content: string; tool_call_id: string }\n | {\n role: \"assistant\";\n content?: string | null;\n tool_calls?: Array<{\n id: string;\n type: \"function\";\n function: { name: string; arguments: string };\n }>;\n };\n\n/** Chat result with tool calls */\nexport interface ChatWithToolsResult {\n message: {\n role: \"assistant\";\n content?: string | null;\n tool_calls?: Array<{\n id: string;\n type: \"function\";\n function: { name: string; arguments: string };\n }>;\n };\n usage?: { promptTokens?: number; completionTokens?: number };\n}\n\n/** Stream chunk for chat with tools responses */\nexport interface ChatWithToolsStreamChunk {\n delta: {\n role?: \"assistant\";\n content?: string | null;\n tool_calls?: Array<{\n index: number;\n id?: string;\n type?: \"function\";\n function?: { name?: string; arguments?: string };\n }>;\n };\n done: boolean;\n usage?: { promptTokens?: number; completionTokens?: number };\n}\n\n/** Image generation result */\nexport interface ImageResult {\n url?: string;\n b64?: string;\n}\n\n/**\n * Minimal interface for a single LLM instance.\n * type=chat provides chat; type=image provides generateImage.\n * chat type may optionally provide chatWithTools for ReAct/Agent tool calling.\n */\nexport interface ILLMClient {\n readonly id: string;\n readonly type: LLMType;\n /** Chat (available when type=chat) */\n chat(messages: ChatMessage[]): Promise<ChatResult>;\n /**\n * Chat with streaming (optional when type=chat).\n * Returns an async generator that yields chunks as they arrive.\n */\n chatStream?(messages: ChatMessage[]): AsyncGenerator<ChatStreamChunk, void, unknown>;\n /**\n * Chat with tools (optional when type=chat; for ReAct/Agent).\n * If not implemented, caller may poll with chat or use another client.\n */\n chatWithTools?(\n messages: ChatWithToolsMessage[],\n tools: ToolDefinition[],\n options?: { timeoutMs?: number }\n ): Promise<ChatWithToolsResult>;\n /**\n * Chat with tools and streaming (optional when type=chat).\n * Returns an async generator that yields chunks as they arrive.\n */\n chatWithToolsStream?(\n messages: ChatWithToolsMessage[],\n tools: ToolDefinition[],\n options?: { timeoutMs?: number }\n ): AsyncGenerator<ChatWithToolsStreamChunk, void, unknown>;\n /** Image generation (when type=image); otherwise may throw or be ignored */\n generateImage?(options: { prompt: string; size?: string; n?: number }): Promise<ImageResult>;\n}\n\n/**\n * LLM registry created from llm section: get instance by id.\n */\nexport interface ILLMRegistry {\n get(id: string): ILLMClient | undefined;\n defaultId(): string | undefined;\n ids(): string[];\n}\n\n/**\n * Generic interface for an LLM provider extension (npm package).\n * Implement getLLMExtension() returning this; framework will register the provider when loading.\n * Prefer createClient + createChatModel so the framework does registration (extension need not call register).\n */\nexport interface ILLMExtension {\n /** Provider name (e.g. \"openai\" or extension-specific name). Framework registers under this name. */\n readonly providerName: string;\n /** ILLMClient factory. If present with createChatModel, framework calls registerProvider(providerName, createClient). */\n readonly createClient?: (config: LLMConfig) => ILLMClient;\n /** LangChain ChatModel factory. If present with createClient, framework calls registerChatModelProvider(providerName, createChatModel). */\n readonly createChatModel?: (config: LLMConfig) => unknown;\n /** Legacy: if extension provides register(), framework calls it. Prefer createClient + createChatModel so framework registers. */\n register?(): void;\n}\n\n/** package.json field: when true, the package is an agent-llm provider (for discovery). */\nexport const AGENT_LLM_PROVIDER_FIELD = \"agentLlmProvider\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBO,SAAS,kBAAkB,SAAiD;AACjF,QAAM,EAAE,WAAW,QAAQ,IAAI,gBAAgB,QAAQ,UAAU;AACjE,QAAM,MAAM,oBAAI,IAAwB;AAExC,aAAW,UAAU,SAAS;AAC5B,QAAI;AACF,YAAM,SAAS,aAAa,MAAM;AAClC,UAAI,IAAI,OAAO,IAAI,MAAM;AAAA,IAC3B,SAAS,KAAK;AACZ,cAAQ,KAAK,yBAAyB,OAAO,EAAE,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC,EAAE;AAAA,IACzG;AAAA,EACF;AAEA,SAAO;AAAA,IACL,IAAI,IAAoC;AACtC,aAAO,IAAI,IAAI,EAAE;AAAA,IACnB;AAAA,IACA,YAAgC;AAC9B,UAAI,IAAI,IAAI,SAAS,EAAG,QAAO;AAC/B,aAAO,IAAI,OAAO,IAAI,CAAC,GAAG,IAAI,KAAK,CAAC,EAAE,CAAC,IAAI;AAAA,IAC7C;AAAA,IACA,MAAgB;AACd,aAAO,CAAC,GAAG,IAAI,KAAK,CAAC;AAAA,IACvB;AAAA,EACF;AACF;;;ACqJO,IAAM,2BAA2B;","names":[]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,6 +1,16 @@
1
1
  /**
2
- * LangChain module: adapter for creating LangChain ChatModels from config.
2
+ * LangChain module: create ChatOpenAI from llm config.
3
+ * Uses @langchain/openai only; extensions can register custom ChatModel factories.
3
4
  */
4
- export { createChatModelFromLlmConfig } from "./adapter.js";
5
- export type { CreateChatModelFromLlmConfigOptions } from "./adapter.js";
5
+ import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
6
+ export interface CreateChatModelFromLlmConfigOptions {
7
+ llmSection?: unknown;
8
+ modelEnv?: string;
9
+ apiKeyEnv?: string;
10
+ }
11
+ /**
12
+ * Create a LangChain ChatModel from agent config llm section.
13
+ * Uses extension-registered factory when available; otherwise ChatOpenAI from @langchain/openai.
14
+ */
15
+ export declare function createChatModelFromLlmConfig(options: CreateChatModelFromLlmConfigOptions): BaseChatModel;
6
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/langchain/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AAC5D,YAAY,EAAE,mCAAmC,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/langchain/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAMjF,MAAM,WAAW,mCAAmC;IAClD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAOD;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,mCAAmC,GAC3C,aAAa,CA0Ef"}
@@ -1,17 +1,10 @@
1
1
  /**
2
2
  * Registry for LangChain ChatModel by provider name.
3
- * Extensions register via registerChatModelProvider; llmAdapter uses getChatModelFactory.
3
+ * Extensions register via registerChatModelProvider.
4
4
  */
5
5
  import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
6
6
  import type { LLMConfig } from "../types.js";
7
7
  export type ChatModelFactory = (config: LLMConfig) => BaseChatModel;
8
- /**
9
- * Register a ChatModel factory for a provider name.
10
- * Called by extensions (e.g. wallee-llm) on load.
11
- */
12
8
  export declare function registerChatModelProvider(providerName: string, factory: ChatModelFactory): void;
13
- /**
14
- * Get the ChatModel factory for a provider name, if registered.
15
- */
16
9
  export declare function getChatModelFactory(providerName: string): ChatModelFactory | undefined;
17
10
  //# sourceMappingURL=chat-model.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"chat-model.d.ts","sourceRoot":"","sources":["../../src/registry/chat-model.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,SAAS,KAAK,aAAa,CAAC;AAIpE;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAE/F;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAEtF"}
1
+ {"version":3,"file":"chat-model.d.ts","sourceRoot":"","sources":["../../src/registry/chat-model.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,SAAS,KAAK,aAAa,CAAC;AAIpE,wBAAgB,yBAAyB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAE/F;AAED,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAEtF"}
@@ -1,8 +1,3 @@
1
- /**
2
- * Registry module: manage LLM client and ChatModel registries.
3
- */
4
- export { createLLMRegistry } from "./client.js";
5
- export type { CreateLLMRegistryOptions } from "./client.js";
6
1
  export { registerChatModelProvider, getChatModelFactory } from "./chat-model.js";
7
2
  export type { ChatModelFactory } from "./chat-model.js";
8
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/registry/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACjF,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/registry/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACjF,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/types.d.ts CHANGED
@@ -1,37 +1,22 @@
1
1
  /**
2
- * Agent LLM: OpenAI-compatible format only (/v1/chat/completions etc.).
3
- * Multi-instance: each LLM has id and type; optional baseURL for other compatible endpoints.
2
+ * Agent LLM: OpenAI-compatible config only. No custom client types.
3
+ * LangChain ChatOpenAI is the single implementation.
4
4
  */
5
- /** LLM type: chat = conversation, image = image generation (OpenAI-compatible format) */
6
5
  export type LLMType = "chat" | "image";
7
- /** Single LLM config: id, type, model; OpenAI-compatible API only */
8
6
  export interface LLMConfig {
9
- /** Unique id for fetching the instance from the registry */
10
7
  id: string;
11
- /** chat | image */
12
8
  type: LLMType;
13
- /** Must be openai or openai-compatible; only this format is supported */
14
9
  provider: string;
15
- /** Model name, e.g. gpt-4o-mini, dall-e-3 */
16
10
  model?: string;
17
- /** Temperature etc.; commonly used for chat */
18
11
  temperature?: number;
19
- /** API key; can also be set via env */
20
12
  apiKey?: string;
21
- /** OpenAI-compatible endpoint baseURL (e.g. Azure, local proxy, other /v1-compatible vendors) */
22
13
  baseURL?: string;
23
- /** Other options (passed through) */
24
14
  [key: string]: unknown;
25
15
  }
26
- /** agent.yaml llm section: flat (each model keyed by name), default+instances, or single object */
27
16
  export interface AgentConfigLlmSection {
28
- /** Default model name (id) to use */
29
17
  default?: string;
30
- /** npm package name or array for dynamic load; e.g. "wallee-llm" or ["wallee-llm"] */
31
18
  type?: string | string[];
32
- /** Array of LLM configs */
33
19
  instances?: LLMConfig[];
34
- /** Single-object form: provider, model etc., parsed as id=default chat */
35
20
  provider?: string;
36
21
  model?: string;
37
22
  name?: string;
@@ -39,161 +24,19 @@ export interface AgentConfigLlmSection {
39
24
  apiKey?: string;
40
25
  baseURL?: string;
41
26
  base_url?: string;
42
- /** Flat: strong/medium/fast etc. name → config (provider, base_url, name, options) */
43
27
  [key: string]: unknown;
44
28
  }
45
- /** Single chat message */
46
- export interface ChatMessage {
47
- role: "system" | "user" | "assistant";
48
- content: string;
49
- }
50
- /** Minimal chat result */
51
- export interface ChatResult {
52
- content: string;
53
- usage?: {
54
- promptTokens?: number;
55
- completionTokens?: number;
56
- };
57
- }
58
- /** Stream chunk for chat responses */
59
- export interface ChatStreamChunk {
60
- content: string;
61
- done: boolean;
62
- usage?: {
63
- promptTokens?: number;
64
- completionTokens?: number;
65
- };
66
- }
67
- /** OpenAI-compatible tool definition (function) */
68
- export interface ToolDefinition {
69
- type: "function";
70
- function: {
71
- name: string;
72
- description?: string;
73
- parameters?: object;
74
- };
75
- }
76
- /** Message with tool calls (assistant may include tool_calls; tool = tool result) */
77
- export type ChatWithToolsMessage = ChatMessage | {
78
- role: "tool";
79
- content: string;
80
- tool_call_id: string;
81
- } | {
82
- role: "assistant";
83
- content?: string | null;
84
- tool_calls?: Array<{
85
- id: string;
86
- type: "function";
87
- function: {
88
- name: string;
89
- arguments: string;
90
- };
91
- }>;
92
- };
93
- /** Chat result with tool calls */
94
- export interface ChatWithToolsResult {
95
- message: {
96
- role: "assistant";
97
- content?: string | null;
98
- tool_calls?: Array<{
99
- id: string;
100
- type: "function";
101
- function: {
102
- name: string;
103
- arguments: string;
104
- };
105
- }>;
106
- };
107
- usage?: {
108
- promptTokens?: number;
109
- completionTokens?: number;
110
- };
111
- }
112
- /** Stream chunk for chat with tools responses */
113
- export interface ChatWithToolsStreamChunk {
114
- delta: {
115
- role?: "assistant";
116
- content?: string | null;
117
- tool_calls?: Array<{
118
- index: number;
119
- id?: string;
120
- type?: "function";
121
- function?: {
122
- name?: string;
123
- arguments?: string;
124
- };
125
- }>;
126
- };
127
- done: boolean;
128
- usage?: {
129
- promptTokens?: number;
130
- completionTokens?: number;
131
- };
132
- }
133
- /** Image generation result */
134
- export interface ImageResult {
135
- url?: string;
136
- b64?: string;
137
- }
138
- /**
139
- * Minimal interface for a single LLM instance.
140
- * type=chat provides chat; type=image provides generateImage.
141
- * chat type may optionally provide chatWithTools for ReAct/Agent tool calling.
142
- */
143
- export interface ILLMClient {
144
- readonly id: string;
145
- readonly type: LLMType;
146
- /** Chat (available when type=chat) */
147
- chat(messages: ChatMessage[]): Promise<ChatResult>;
148
- /**
149
- * Chat with streaming (optional when type=chat).
150
- * Returns an async generator that yields chunks as they arrive.
151
- */
152
- chatStream?(messages: ChatMessage[]): AsyncGenerator<ChatStreamChunk, void, unknown>;
153
- /**
154
- * Chat with tools (optional when type=chat; for ReAct/Agent).
155
- * If not implemented, caller may poll with chat or use another client.
156
- */
157
- chatWithTools?(messages: ChatWithToolsMessage[], tools: ToolDefinition[], options?: {
158
- timeoutMs?: number;
159
- }): Promise<ChatWithToolsResult>;
160
- /**
161
- * Chat with tools and streaming (optional when type=chat).
162
- * Returns an async generator that yields chunks as they arrive.
163
- */
164
- chatWithToolsStream?(messages: ChatWithToolsMessage[], tools: ToolDefinition[], options?: {
165
- timeoutMs?: number;
166
- }): AsyncGenerator<ChatWithToolsStreamChunk, void, unknown>;
167
- /** Image generation (when type=image); otherwise may throw or be ignored */
168
- generateImage?(options: {
169
- prompt: string;
170
- size?: string;
171
- n?: number;
172
- }): Promise<ImageResult>;
173
- }
174
- /**
175
- * LLM registry created from llm section: get instance by id.
176
- */
177
- export interface ILLMRegistry {
178
- get(id: string): ILLMClient | undefined;
179
- defaultId(): string | undefined;
180
- ids(): string[];
181
- }
29
+ /** package.json field: when true, the package is an agent-llm provider (for discovery). */
30
+ export declare const AGENT_LLM_PROVIDER_FIELD = "agentLlmProvider";
182
31
  /**
183
- * Generic interface for an LLM provider extension (npm package).
184
- * Implement getLLMExtension() returning this; framework will register the provider when loading.
185
- * Prefer createClient + createChatModel so the framework does registration (extension need not call register).
32
+ * Extension interface: register a ChatModel factory by provider name.
33
+ * Extensions implement getLLMExtension(); framework registers the factory when loading.
186
34
  */
187
35
  export interface ILLMExtension {
188
- /** Provider name (e.g. "openai" or extension-specific name). Framework registers under this name. */
189
36
  readonly providerName: string;
190
- /** ILLMClient factory. If present with createChatModel, framework calls registerProvider(providerName, createClient). */
191
- readonly createClient?: (config: LLMConfig) => ILLMClient;
192
- /** LangChain ChatModel factory. If present with createClient, framework calls registerChatModelProvider(providerName, createChatModel). */
37
+ /** LangChain ChatModel factory. Framework calls registerChatModelProvider(providerName, createChatModel). */
193
38
  readonly createChatModel?: (config: LLMConfig) => unknown;
194
- /** Legacy: if extension provides register(), framework calls it. Prefer createClient + createChatModel so framework registers. */
39
+ /** Legacy: if extension provides register(), framework calls it. */
195
40
  register?(): void;
196
41
  }
197
- /** package.json field: when true, the package is an agent-llm provider (for discovery). */
198
- export declare const AGENT_LLM_PROVIDER_FIELD = "agentLlmProvider";
199
42
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,yFAAyF;AACzF,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC;AAEvC,qEAAqE;AACrE,MAAM,WAAW,SAAS;IACxB,4DAA4D;IAC5D,EAAE,EAAE,MAAM,CAAC;IACX,mBAAmB;IACnB,IAAI,EAAE,OAAO,CAAC;IACd,yEAAyE;IACzE,QAAQ,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iGAAiG;IACjG,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qCAAqC;IACrC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,mGAAmG;AACnG,MAAM,WAAW,qBAAqB;IACpC,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sFAAsF;IACtF,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,2BAA2B;IAC3B,SAAS,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,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,2FAA2F;AAC3F,eAAO,MAAM,wBAAwB,qBAAqB,CAAC;AAE3D;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,6GAA6G;IAC7G,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,OAAO,CAAC;IAC1D,oEAAoE;IACpE,QAAQ,CAAC,IAAI,IAAI,CAAC;CACnB"}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@easynet/agent-llm",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "Agent LLM: multi-provider, multi-model, simple chat/image API. Consumes agent.yaml llm section.",
5
5
  "type": "module",
6
6
  "bin": {
7
- "agent-llm": "./dist/cli.js",
8
- "@easynet/agent-llm": "./dist/cli.js"
7
+ "agent-llm": "./dist/cli/index.js",
8
+ "@easynet/agent-llm": "./dist/cli/index.js"
9
9
  },
10
10
  "main": "./dist/index.js",
11
11
  "types": "./dist/index.d.ts",
@@ -14,8 +14,9 @@
14
14
  "dev": "tsup --watch",
15
15
  "test": "vitest run",
16
16
  "test:watch": "vitest",
17
- "test:llm-live": "vitest run llm-live.test.ts",
18
- "test:link": "vitest run -t 'invokes OpenAI-compatible API'",
17
+ "test:unit": "vitest run test/unit",
18
+ "test:integration": "vitest run test/integration",
19
+ "test:live": "vitest run test/integration/llm-live.test.ts",
19
20
  "example:agent": "cd examples && npm run start",
20
21
  "typecheck": "tsc --noEmit"
21
22
  },