open-agent-sdk 0.1.0-alpha.0
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.
- package/LICENSE +21 -0
- package/README.md +284 -0
- package/README.zh.md +285 -0
- package/dist/agent/agent-definition.d.ts +107 -0
- package/dist/agent/agent-definition.d.ts.map +1 -0
- package/dist/agent/agent-definition.js +90 -0
- package/dist/agent/agent-definition.js.map +1 -0
- package/dist/agent/react-loop.d.ts +117 -0
- package/dist/agent/react-loop.d.ts.map +1 -0
- package/dist/agent/react-loop.js +674 -0
- package/dist/agent/react-loop.js.map +1 -0
- package/dist/agent/subagent-runner.d.ts +67 -0
- package/dist/agent/subagent-runner.d.ts.map +1 -0
- package/dist/agent/subagent-runner.js +168 -0
- package/dist/agent/subagent-runner.js.map +1 -0
- package/dist/hooks/index.d.ts +8 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +9 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/inputs.d.ts +56 -0
- package/dist/hooks/inputs.d.ts.map +1 -0
- package/dist/hooks/inputs.js +150 -0
- package/dist/hooks/inputs.js.map +1 -0
- package/dist/hooks/manager.d.ts +63 -0
- package/dist/hooks/manager.d.ts.map +1 -0
- package/dist/hooks/manager.js +137 -0
- package/dist/hooks/manager.js.map +1 -0
- package/dist/hooks/types.d.ts +191 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +6 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +218 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/errors.d.ts +26 -0
- package/dist/mcp/errors.d.ts.map +1 -0
- package/dist/mcp/errors.js +43 -0
- package/dist/mcp/errors.js.map +1 -0
- package/dist/mcp/index.d.ts +11 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +13 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/manager.d.ts +50 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/manager.js +170 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/server-registry.d.ts +48 -0
- package/dist/mcp/server-registry.d.ts.map +1 -0
- package/dist/mcp/server-registry.js +121 -0
- package/dist/mcp/server-registry.js.map +1 -0
- package/dist/mcp/tool-adapter.d.ts +42 -0
- package/dist/mcp/tool-adapter.d.ts.map +1 -0
- package/dist/mcp/tool-adapter.js +89 -0
- package/dist/mcp/tool-adapter.js.map +1 -0
- package/dist/mcp/types.d.ts +74 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +21 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/permissions/index.d.ts +3 -0
- package/dist/permissions/index.d.ts.map +1 -0
- package/dist/permissions/index.js +4 -0
- package/dist/permissions/index.js.map +1 -0
- package/dist/permissions/manager.d.ts +40 -0
- package/dist/permissions/manager.d.ts.map +1 -0
- package/dist/permissions/manager.js +115 -0
- package/dist/permissions/manager.js.map +1 -0
- package/dist/permissions/types.d.ts +124 -0
- package/dist/permissions/types.d.ts.map +1 -0
- package/dist/permissions/types.js +25 -0
- package/dist/permissions/types.js.map +1 -0
- package/dist/providers/anthropic.d.ts +18 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +126 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/base.d.ts +85 -0
- package/dist/providers/base.d.ts.map +1 -0
- package/dist/providers/base.js +36 -0
- package/dist/providers/base.js.map +1 -0
- package/dist/providers/google.d.ts +12 -0
- package/dist/providers/google.d.ts.map +1 -0
- package/dist/providers/google.js +123 -0
- package/dist/providers/google.js.map +1 -0
- package/dist/providers/openai.d.ts +12 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +110 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/session/factory.d.ts +156 -0
- package/dist/session/factory.d.ts.map +1 -0
- package/dist/session/factory.js +311 -0
- package/dist/session/factory.js.map +1 -0
- package/dist/session/index.d.ts +8 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +7 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/session.d.ts +144 -0
- package/dist/session/session.d.ts.map +1 -0
- package/dist/session/session.js +319 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/storage.d.ts +105 -0
- package/dist/session/storage.d.ts.map +1 -0
- package/dist/session/storage.js +148 -0
- package/dist/session/storage.js.map +1 -0
- package/dist/tools/ask-user-question.d.ts +31 -0
- package/dist/tools/ask-user-question.d.ts.map +1 -0
- package/dist/tools/ask-user-question.js +66 -0
- package/dist/tools/ask-user-question.js.map +1 -0
- package/dist/tools/bash-output.d.ts +22 -0
- package/dist/tools/bash-output.d.ts.map +1 -0
- package/dist/tools/bash-output.js +43 -0
- package/dist/tools/bash-output.js.map +1 -0
- package/dist/tools/bash.d.ts +36 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +161 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/edit.d.ts +24 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/edit.js +83 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/glob.d.ts +22 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/glob.js +248 -0
- package/dist/tools/glob.js.map +1 -0
- package/dist/tools/grep.d.ts +39 -0
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/grep.js +312 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/kill-bash.d.ts +19 -0
- package/dist/tools/kill-bash.d.ts.map +1 -0
- package/dist/tools/kill-bash.js +64 -0
- package/dist/tools/kill-bash.js.map +1 -0
- package/dist/tools/read.d.ts +26 -0
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/read.js +87 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/registry.d.ts +32 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +91 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/task-create.d.ts +22 -0
- package/dist/tools/task-create.d.ts.map +1 -0
- package/dist/tools/task-create.js +42 -0
- package/dist/tools/task-create.js.map +1 -0
- package/dist/tools/task-get.d.ts +19 -0
- package/dist/tools/task-get.d.ts.map +1 -0
- package/dist/tools/task-get.js +38 -0
- package/dist/tools/task-get.js.map +1 -0
- package/dist/tools/task-list.d.ts +18 -0
- package/dist/tools/task-list.d.ts.map +1 -0
- package/dist/tools/task-list.js +27 -0
- package/dist/tools/task-list.js.map +1 -0
- package/dist/tools/task-storage.d.ts +6 -0
- package/dist/tools/task-storage.d.ts.map +1 -0
- package/dist/tools/task-storage.js +83 -0
- package/dist/tools/task-storage.js.map +1 -0
- package/dist/tools/task-update.d.ts +28 -0
- package/dist/tools/task-update.d.ts.map +1 -0
- package/dist/tools/task-update.js +118 -0
- package/dist/tools/task-update.js.map +1 -0
- package/dist/tools/task.d.ts +80 -0
- package/dist/tools/task.d.ts.map +1 -0
- package/dist/tools/task.js +99 -0
- package/dist/tools/task.js.map +1 -0
- package/dist/tools/web-fetch.d.ts +21 -0
- package/dist/tools/web-fetch.d.ts.map +1 -0
- package/dist/tools/web-fetch.js +124 -0
- package/dist/tools/web-fetch.js.map +1 -0
- package/dist/tools/web-search.d.ts +20 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +127 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/tools/write.d.ts +22 -0
- package/dist/tools/write.d.ts.map +1 -0
- package/dist/tools/write.js +46 -0
- package/dist/tools/write.js.map +1 -0
- package/dist/types/messages.d.ts +138 -0
- package/dist/types/messages.d.ts.map +1 -0
- package/dist/types/messages.js +88 -0
- package/dist/types/messages.js.map +1 -0
- package/dist/types/task.d.ts +29 -0
- package/dist/types/task.d.ts.map +1 -0
- package/dist/types/task.js +5 -0
- package/dist/types/task.js.map +1 -0
- package/dist/types/tools.d.ts +56 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +25 -0
- package/dist/types/tools.js.map +1 -0
- package/dist/utils/logger.d.ts +19 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +46 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/uuid.d.ts +3 -0
- package/dist/utils/uuid.d.ts.map +1 -0
- package/dist/utils/uuid.js +5 -0
- package/dist/utils/uuid.js.map +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Permission system types
|
|
3
|
+
* Aligned with Claude Agent SDK
|
|
4
|
+
*/
|
|
5
|
+
/** Permission behavior - defined in hooks/types.ts */
|
|
6
|
+
export type PermissionBehavior = 'allow' | 'deny' | 'ask';
|
|
7
|
+
/** Permission update destination - defined in hooks/types.ts */
|
|
8
|
+
export type PermissionUpdateDestination = 'userSettings' | 'projectSettings' | 'localSettings' | 'session';
|
|
9
|
+
/** Permission rule value - defined in hooks/types.ts */
|
|
10
|
+
export type PermissionRuleValue = {
|
|
11
|
+
toolName: string;
|
|
12
|
+
ruleContent?: string;
|
|
13
|
+
};
|
|
14
|
+
/** Permission update operations - defined in hooks/types.ts */
|
|
15
|
+
export type PermissionUpdate = {
|
|
16
|
+
type: 'addRules';
|
|
17
|
+
rules: PermissionRuleValue[];
|
|
18
|
+
behavior: PermissionBehavior;
|
|
19
|
+
destination: PermissionUpdateDestination;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'replaceRules';
|
|
22
|
+
rules: PermissionRuleValue[];
|
|
23
|
+
behavior: PermissionBehavior;
|
|
24
|
+
destination: PermissionUpdateDestination;
|
|
25
|
+
} | {
|
|
26
|
+
type: 'removeRules';
|
|
27
|
+
rules: PermissionRuleValue[];
|
|
28
|
+
behavior: PermissionBehavior;
|
|
29
|
+
destination: PermissionUpdateDestination;
|
|
30
|
+
} | {
|
|
31
|
+
type: 'setMode';
|
|
32
|
+
mode: string;
|
|
33
|
+
destination: PermissionUpdateDestination;
|
|
34
|
+
} | {
|
|
35
|
+
type: 'addDirectories';
|
|
36
|
+
directories: string[];
|
|
37
|
+
destination: PermissionUpdateDestination;
|
|
38
|
+
} | {
|
|
39
|
+
type: 'removeDirectories';
|
|
40
|
+
directories: string[];
|
|
41
|
+
destination: PermissionUpdateDestination;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Permission mode for controlling tool execution behavior
|
|
45
|
+
*/
|
|
46
|
+
export type PermissionMode = 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan';
|
|
47
|
+
/**
|
|
48
|
+
* Options for configuring permission behavior
|
|
49
|
+
*/
|
|
50
|
+
export interface PermissionOptions {
|
|
51
|
+
/** Current permission mode */
|
|
52
|
+
mode: PermissionMode;
|
|
53
|
+
/** Required to be true when using bypassPermissions mode */
|
|
54
|
+
allowDangerouslySkipPermissions?: boolean;
|
|
55
|
+
/** Custom callback for tool permission checks */
|
|
56
|
+
canUseTool?: CanUseTool;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Result from a custom permission check callback
|
|
60
|
+
* Aligned with Claude Agent SDK
|
|
61
|
+
*/
|
|
62
|
+
export type PermissionResult = {
|
|
63
|
+
/** Allow the tool to execute */
|
|
64
|
+
behavior: 'allow';
|
|
65
|
+
/** Input to use (may be modified from original) */
|
|
66
|
+
updatedInput: Record<string, unknown>;
|
|
67
|
+
/** Optional permission updates to apply */
|
|
68
|
+
updatedPermissions?: PermissionUpdate[];
|
|
69
|
+
} | {
|
|
70
|
+
/** Deny the tool execution */
|
|
71
|
+
behavior: 'deny';
|
|
72
|
+
/** Message explaining why (shown to LLM) */
|
|
73
|
+
message: string;
|
|
74
|
+
/** Whether to interrupt the session */
|
|
75
|
+
interrupt?: boolean;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Custom permission check callback
|
|
79
|
+
* Called when a sensitive tool needs permission verification
|
|
80
|
+
* Aligned with Claude Agent SDK
|
|
81
|
+
*/
|
|
82
|
+
export type CanUseTool = (toolName: string, input: Record<string, unknown>, options: {
|
|
83
|
+
signal: AbortSignal;
|
|
84
|
+
suggestions?: PermissionUpdate[];
|
|
85
|
+
}) => Promise<PermissionResult>;
|
|
86
|
+
/**
|
|
87
|
+
* Result from PermissionManager.checkPermission()
|
|
88
|
+
*/
|
|
89
|
+
export interface PermissionCheckResult {
|
|
90
|
+
/** Whether the tool is approved for execution */
|
|
91
|
+
approved: boolean;
|
|
92
|
+
/** Modified input (if any) */
|
|
93
|
+
updatedInput?: Record<string, unknown>;
|
|
94
|
+
/** Error message if denied */
|
|
95
|
+
error?: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Entry in the plan log (used in plan mode)
|
|
99
|
+
*/
|
|
100
|
+
export interface PlanLogEntry {
|
|
101
|
+
/** Name of the tool that was called */
|
|
102
|
+
toolName: string;
|
|
103
|
+
/** Input parameters */
|
|
104
|
+
input: Record<string, unknown>;
|
|
105
|
+
/** Timestamp of the call */
|
|
106
|
+
timestamp: number;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Sensitive tools that require permission confirmation in default mode
|
|
110
|
+
*/
|
|
111
|
+
export declare const SENSITIVE_TOOLS: string[];
|
|
112
|
+
/**
|
|
113
|
+
* Edit tools that are auto-approved in acceptEdits mode
|
|
114
|
+
*/
|
|
115
|
+
export declare const EDIT_TOOLS: string[];
|
|
116
|
+
/**
|
|
117
|
+
* Check if a tool is a sensitive tool
|
|
118
|
+
*/
|
|
119
|
+
export declare function isSensitiveTool(toolName: string): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Check if a tool is an edit tool
|
|
122
|
+
*/
|
|
123
|
+
export declare function isEditTool(toolName: string): boolean;
|
|
124
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/permiss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AE,OAAO,CAAC,CAAC;IAC/B,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,UAAqD,CAAC;AAElF;;GAEG;AACH,eAAO,MAAM,UAAU,UAAoB,CAAC;AAE5C;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEpD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Permission system types
|
|
3
|
+
* Aligned with Claude Agent SDK
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Sensitive tools that require permission confirmation in default mode
|
|
7
|
+
*/
|
|
8
|
+
export const SENSITIVE_TOOLS = ['Bash', 'Write', 'Edit', 'WebSearch', 'WebFetch'];
|
|
9
|
+
/**
|
|
10
|
+
* Edit tools that are auto-approved in acceptEdits mode
|
|
11
|
+
*/
|
|
12
|
+
export const EDIT_TOOLS = ['Write', 'Edit'];
|
|
13
|
+
/**
|
|
14
|
+
* Check if a tool is a sensitive tool
|
|
15
|
+
*/
|
|
16
|
+
export function isSensitiveTool(toolName) {
|
|
17
|
+
return SENSITIVE_TOOLS.includes(toolName);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Check if a tool is an edit tool
|
|
21
|
+
*/
|
|
22
|
+
export function isEditTool(toolName) {
|
|
23
|
+
return EDIT_TOOLS.includes(toolName);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/permissions/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqIH;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;AAElF;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAE5C;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,OAAO,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,QAAgB;IACzC,OAAO,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LLMProvider, type ProviderConfig, type LLMChunk, type ChatOptions, type TokenUsage } from './base';
|
|
2
|
+
import type { SDKMessage } from '../types/messages';
|
|
3
|
+
import type { ToolDefinition } from '../types/tools';
|
|
4
|
+
export interface AnthropicConfig extends ProviderConfig {
|
|
5
|
+
}
|
|
6
|
+
export declare class AnthropicProvider extends LLMProvider {
|
|
7
|
+
private anthropic;
|
|
8
|
+
constructor(config: AnthropicConfig);
|
|
9
|
+
chat(messages: SDKMessage[], tools?: ToolDefinition[], signal?: AbortSignal, options?: ChatOptions): AsyncIterable<LLMChunk>;
|
|
10
|
+
/**
|
|
11
|
+
* Calculate cost for token usage based on Anthropic pricing
|
|
12
|
+
* @param usage Token usage statistics
|
|
13
|
+
* @returns Cost in USD, or undefined if pricing not available for the model
|
|
14
|
+
*/
|
|
15
|
+
getCost(usage: TokenUsage): number | undefined;
|
|
16
|
+
private convertToCoreMessages;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC5G,OAAO,KAAK,EAAE,UAAU,EAAyB,MAAM,mBAAmB,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAiBrD,MAAM,WAAW,eAAgB,SAAQ,cAAc;CAEtD;AAED,qBAAa,iBAAkB,SAAQ,WAAW;IAChD,OAAO,CAAC,SAAS,CAAqC;gBAE1C,MAAM,EAAE,eAAe;IAQ5B,IAAI,CACT,QAAQ,EAAE,UAAU,EAAE,EACtB,KAAK,CAAC,EAAE,cAAc,EAAE,EACxB,MAAM,CAAC,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,WAAW,GACpB,aAAa,CAAC,QAAQ,CAAC;IA8D1B;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS;IAY9C,OAAO,CAAC,qBAAqB;CAsC9B"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { createAnthropic } from '@ai-sdk/anthropic';
|
|
2
|
+
import { streamText, jsonSchema } from 'ai';
|
|
3
|
+
import { LLMProvider } from './base';
|
|
4
|
+
/** Anthropic pricing per million tokens (in USD) */
|
|
5
|
+
const ANTHROPIC_PRICING = {
|
|
6
|
+
'claude-sonnet-4-20250514': { input: 3, output: 15 },
|
|
7
|
+
'claude-haiku-35-20241022': { input: 0.8, output: 4 },
|
|
8
|
+
'claude-opus-4-20250514': { input: 15, output: 75 },
|
|
9
|
+
};
|
|
10
|
+
export class AnthropicProvider extends LLMProvider {
|
|
11
|
+
anthropic;
|
|
12
|
+
constructor(config) {
|
|
13
|
+
super(config);
|
|
14
|
+
this.anthropic = createAnthropic({
|
|
15
|
+
apiKey: config.apiKey,
|
|
16
|
+
baseURL: config.baseURL,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async *chat(messages, tools, signal, options) {
|
|
20
|
+
// Convert message format
|
|
21
|
+
const coreMessages = this.convertToCoreMessages(messages);
|
|
22
|
+
// Convert tools to Vercel AI SDK format
|
|
23
|
+
// ToolDefinition format: { type: 'function', function: { name, description, parameters } }
|
|
24
|
+
// Vercel AI SDK expects: { [name]: { description, inputSchema: Schema } }
|
|
25
|
+
const vercelTools = tools?.length
|
|
26
|
+
? Object.fromEntries(tools.map((toolDef) => [
|
|
27
|
+
toolDef.function.name,
|
|
28
|
+
{
|
|
29
|
+
description: toolDef.function.description,
|
|
30
|
+
inputSchema: jsonSchema(toolDef.function.parameters),
|
|
31
|
+
},
|
|
32
|
+
]))
|
|
33
|
+
: undefined;
|
|
34
|
+
// Use Vercel AI SDK's streamText
|
|
35
|
+
const result = streamText({
|
|
36
|
+
model: this.anthropic(this.config.model),
|
|
37
|
+
messages: coreMessages,
|
|
38
|
+
system: options?.systemInstruction,
|
|
39
|
+
maxOutputTokens: this.config.maxTokens,
|
|
40
|
+
temperature: this.config.temperature,
|
|
41
|
+
abortSignal: signal,
|
|
42
|
+
tools: vercelTools,
|
|
43
|
+
});
|
|
44
|
+
// Process stream response
|
|
45
|
+
for await (const textDelta of result.textStream) {
|
|
46
|
+
yield { type: 'content', delta: textDelta };
|
|
47
|
+
}
|
|
48
|
+
// Get tool calls after stream completes (they are complete at this point)
|
|
49
|
+
const toolCalls = await result.toolCalls;
|
|
50
|
+
for (const toolCall of toolCalls) {
|
|
51
|
+
yield {
|
|
52
|
+
type: 'tool_call',
|
|
53
|
+
tool_call: {
|
|
54
|
+
id: toolCall.toolCallId,
|
|
55
|
+
name: toolCall.toolName,
|
|
56
|
+
// input can be undefined if the tool has no parameters, default to empty object
|
|
57
|
+
arguments: JSON.stringify(toolCall.input ?? {}),
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// Get usage stats
|
|
62
|
+
const usage = await result.usage;
|
|
63
|
+
yield {
|
|
64
|
+
type: 'usage',
|
|
65
|
+
usage: {
|
|
66
|
+
input_tokens: usage.inputTokens ?? 0,
|
|
67
|
+
output_tokens: usage.outputTokens ?? 0,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
yield { type: 'done' };
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Calculate cost for token usage based on Anthropic pricing
|
|
74
|
+
* @param usage Token usage statistics
|
|
75
|
+
* @returns Cost in USD, or undefined if pricing not available for the model
|
|
76
|
+
*/
|
|
77
|
+
getCost(usage) {
|
|
78
|
+
const pricing = ANTHROPIC_PRICING[this.config.model];
|
|
79
|
+
if (!pricing) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
// Calculate cost: (input_tokens / 1M) * input_price + (output_tokens / 1M) * output_price
|
|
83
|
+
const inputCost = (usage.input_tokens / 1000000) * pricing.input;
|
|
84
|
+
const outputCost = (usage.output_tokens / 1000000) * pricing.output;
|
|
85
|
+
return inputCost + outputCost;
|
|
86
|
+
}
|
|
87
|
+
convertToCoreMessages(messages) {
|
|
88
|
+
return messages
|
|
89
|
+
.filter((msg) => msg.type !== 'system')
|
|
90
|
+
.map((msg) => {
|
|
91
|
+
switch (msg.type) {
|
|
92
|
+
case 'user':
|
|
93
|
+
return { role: 'user', content: msg.message.content };
|
|
94
|
+
case 'assistant': {
|
|
95
|
+
const text = msg.message.content
|
|
96
|
+
.filter((c) => c.type === 'text')
|
|
97
|
+
.map((c) => c.text)
|
|
98
|
+
.join('');
|
|
99
|
+
return { role: 'assistant', content: text };
|
|
100
|
+
}
|
|
101
|
+
case 'tool_result': {
|
|
102
|
+
// Get tool name from the tool call in the previous assistant message
|
|
103
|
+
const toolName = msg.tool_use_id ? 'Tool' : 'unknown';
|
|
104
|
+
// Output must be wrapped in {type, value} format per Vercel AI SDK schema
|
|
105
|
+
const outputValue = typeof msg.result === 'string' ? msg.result : JSON.stringify(msg.result);
|
|
106
|
+
return {
|
|
107
|
+
role: 'tool',
|
|
108
|
+
content: [{
|
|
109
|
+
type: 'tool-result',
|
|
110
|
+
toolCallId: msg.tool_use_id,
|
|
111
|
+
toolName,
|
|
112
|
+
output: {
|
|
113
|
+
type: 'text',
|
|
114
|
+
value: outputValue,
|
|
115
|
+
},
|
|
116
|
+
}],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
default:
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
.filter((m) => m !== null);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAqB,UAAU,EAAE,MAAM,IAAI,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAyE,MAAM,QAAQ,CAAC;AAY5G,oDAAoD;AACpD,MAAM,iBAAiB,GAAsD;IAC3E,0BAA0B,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;IACpD,0BAA0B,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE;IACrD,wBAAwB,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;CACpD,CAAC;AAMF,MAAM,OAAO,iBAAkB,SAAQ,WAAW;IACxC,SAAS,CAAqC;IAEtD,YAAY,MAAuB;QACjC,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,SAAS,GAAG,eAAe,CAAC;YAC/B,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,CAAC,IAAI,CACT,QAAsB,EACtB,KAAwB,EACxB,MAAoB,EACpB,OAAqB;QAErB,yBAAyB;QACzB,MAAM,YAAY,GAAG,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;QAE1D,wCAAwC;QACxC,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,CAAC,CAAC,CAAwB,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC;yBACvD,GAAG,CAAC,CAAC,CAA2C,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;yBAC5D,IAAI,CAAC,EAAE,CAAC,CAAC;oBACZ,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9C,CAAC;gBACD,KAAK,aAAa,CAAC,CAAC,CAAC;oBACnB,qEAAqE;oBACrE,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;oBACtD,0EAA0E;oBAC1E,MAAM,WAAW,GAAG,OAAO,GAAG,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;oBAC7F,OAAO;wBACL,IAAI,EAAE,MAAM;wBACZ,OAAO,EAAE,CAAC;gCACR,IAAI,EAAE,aAAa;gCACnB,UAAU,EAAE,GAAG,CAAC,WAAW;gCAC3B,QAAQ;gCACR,MAAM,EAAE;oCACN,IAAI,EAAE,MAAM;oCACZ,KAAK,EAAE,WAAW;iCACnB;6BACF,CAAC;qBACwB,CAAC;gBAC/B,CAAC;gBACD;oBACE,OAAO,IAAI,CAAC;YAChB,CAAC;QACH,CAAC,CAAC;aACD,MAAM,CAAC,CAAC,CAAC,EAAqB,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;IAClD,CAAC;CACF"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base provider interface for LLM integrations
|
|
3
|
+
*/
|
|
4
|
+
import { SDKMessage } from '../types/messages';
|
|
5
|
+
import { ToolDefinition } from '../types/tools';
|
|
6
|
+
/** Chunk from streaming LLM response */
|
|
7
|
+
export interface LLMChunk {
|
|
8
|
+
/** Type of chunk */
|
|
9
|
+
type: 'content' | 'tool_call' | 'usage' | 'done' | 'error';
|
|
10
|
+
/** Content delta (for content type) */
|
|
11
|
+
delta?: string;
|
|
12
|
+
/** Tool call info (for tool_call type) */
|
|
13
|
+
tool_call?: {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
arguments: string;
|
|
17
|
+
};
|
|
18
|
+
/** Usage info (for usage type) */
|
|
19
|
+
usage?: {
|
|
20
|
+
input_tokens: number;
|
|
21
|
+
output_tokens: number;
|
|
22
|
+
};
|
|
23
|
+
/** Error message (for error type) */
|
|
24
|
+
error?: string;
|
|
25
|
+
}
|
|
26
|
+
/** Provider configuration */
|
|
27
|
+
export interface ProviderConfig {
|
|
28
|
+
/** API key for the provider */
|
|
29
|
+
apiKey: string;
|
|
30
|
+
/** Base URL for API (for custom endpoints like Gemini) */
|
|
31
|
+
baseURL?: string;
|
|
32
|
+
/** Model identifier */
|
|
33
|
+
model: string;
|
|
34
|
+
/** Maximum tokens to generate */
|
|
35
|
+
maxTokens?: number;
|
|
36
|
+
/** Temperature (0-2) */
|
|
37
|
+
temperature?: number;
|
|
38
|
+
}
|
|
39
|
+
/** Options for chat method */
|
|
40
|
+
export interface ChatOptions {
|
|
41
|
+
/** System instruction to prepend to the conversation (not part of message history) */
|
|
42
|
+
systemInstruction?: string;
|
|
43
|
+
}
|
|
44
|
+
/** Token usage for cost calculation */
|
|
45
|
+
export interface TokenUsage {
|
|
46
|
+
input_tokens: number;
|
|
47
|
+
output_tokens: number;
|
|
48
|
+
}
|
|
49
|
+
/** Abstract base class for LLM providers */
|
|
50
|
+
export declare abstract class LLMProvider {
|
|
51
|
+
protected config: ProviderConfig;
|
|
52
|
+
constructor(config: ProviderConfig);
|
|
53
|
+
/**
|
|
54
|
+
* Send messages to the LLM and get streaming response
|
|
55
|
+
* @param messages - Conversation history (SDKSystemMessage is metadata only, skipped during conversion)
|
|
56
|
+
* @param tools - Available tools
|
|
57
|
+
* @param signal - Optional AbortSignal for cancellation
|
|
58
|
+
* @param options - Optional chat configuration including systemInstruction
|
|
59
|
+
* @returns Async iterable of response chunks
|
|
60
|
+
*/
|
|
61
|
+
abstract chat(messages: SDKMessage[], tools?: ToolDefinition[], signal?: AbortSignal, options?: ChatOptions): AsyncIterable<LLMChunk>;
|
|
62
|
+
/**
|
|
63
|
+
* Get the model identifier
|
|
64
|
+
*/
|
|
65
|
+
getModel(): string;
|
|
66
|
+
/**
|
|
67
|
+
* Calculate cost for token usage
|
|
68
|
+
* Override this method to provide accurate cost calculation
|
|
69
|
+
* @param usage Token usage statistics
|
|
70
|
+
* @returns Cost in USD, or undefined if not available
|
|
71
|
+
*/
|
|
72
|
+
getCost?(usage: TokenUsage): number | undefined;
|
|
73
|
+
}
|
|
74
|
+
/** Provider factory type */
|
|
75
|
+
export type ProviderFactory = (config: ProviderConfig) => LLMProvider;
|
|
76
|
+
/** Registry of available providers */
|
|
77
|
+
export declare class ProviderRegistry {
|
|
78
|
+
private providers;
|
|
79
|
+
register(name: string, factory: ProviderFactory): void;
|
|
80
|
+
create(name: string, config: ProviderConfig): LLMProvider;
|
|
81
|
+
has(name: string): boolean;
|
|
82
|
+
}
|
|
83
|
+
/** Global provider registry instance */
|
|
84
|
+
export declare const providerRegistry: ProviderRegistry;
|
|
85
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/providers/base.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,wCAAwC;AACxC,MAAM,WAAW,QAAQ;IACvB,oBAAoB;IACpB,IAAI,EAAE,SAAS,GAAG,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC;IAC3D,uCAAuC;IACvC,KAAK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AAG,SAAS;CAChD;AAED,4BAA4B;AAC5B,MAAM,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,cAAc,KAAK,WAAW,CAAC;AAEtE,sCAAsC;AACtC,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,SAAS,CAAsC;IAEvD,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,IAAI;IAItD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,WAAW;IAQzD,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAG3B;AAED,wCAAwC;AACxC,eAAO,MAAM,gBAAgB,kBAAyB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base provider interface for LLM integrations
|
|
3
|
+
*/
|
|
4
|
+
/** Abstract base class for LLM providers */
|
|
5
|
+
export class LLMProvider {
|
|
6
|
+
config;
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.config = config;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Get the model identifier
|
|
12
|
+
*/
|
|
13
|
+
getModel() {
|
|
14
|
+
return this.config.model;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Registry of available providers */
|
|
18
|
+
export class ProviderRegistry {
|
|
19
|
+
providers = new Map();
|
|
20
|
+
register(name, factory) {
|
|
21
|
+
this.providers.set(name, factory);
|
|
22
|
+
}
|
|
23
|
+
create(name, config) {
|
|
24
|
+
const factory = this.providers.get(name);
|
|
25
|
+
if (!factory) {
|
|
26
|
+
throw new Error(`Unknown provider: ${name}`);
|
|
27
|
+
}
|
|
28
|
+
return factory(config);
|
|
29
|
+
}
|
|
30
|
+
has(name) {
|
|
31
|
+
return this.providers.has(name);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Global provider registry instance */
|
|
35
|
+
export const providerRegistry = new ProviderRegistry();
|
|
36
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/providers/base.ts"],"names":[],"mappings":"AAAA;;GAEG;AAoDH,4CAA4C;AAC5C,MAAM,OAAgB,WAAW;IACrB,MAAM,CAAiB;IAEjC,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAiBD;;OAEG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;IAC3B,CAAC;CASF;AAKD,sCAAsC;AACtC,MAAM,OAAO,gBAAgB;IACnB,SAAS,GAAG,IAAI,GAAG,EAA2B,CAAC;IAEvD,QAAQ,CAAC,IAAY,EAAE,OAAwB;QAC7C,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,IAAY,EAAE,MAAsB;QACzC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;IAED,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACF;AAED,wCAAwC;AACxC,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LLMProvider, type ProviderConfig, type LLMChunk, type ChatOptions } from './base';
|
|
2
|
+
import type { SDKMessage } from '../types/messages';
|
|
3
|
+
import type { ToolDefinition } from '../types/tools';
|
|
4
|
+
export interface GoogleConfig extends ProviderConfig {
|
|
5
|
+
}
|
|
6
|
+
export declare class GoogleProvider extends LLMProvider {
|
|
7
|
+
private googleAI;
|
|
8
|
+
constructor(config: GoogleConfig);
|
|
9
|
+
chat(messages: SDKMessage[], tools?: ToolDefinition[], signal?: AbortSignal, options?: ChatOptions): AsyncIterable<LLMChunk>;
|
|
10
|
+
private convertToCoreMessages;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=google.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC3F,OAAO,KAAK,EAAE,UAAU,EAAyB,MAAM,mBAAmB,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAUrD,MAAM,WAAW,YAAa,SAAQ,cAAc;CAEnD;AAED,qBAAa,cAAe,SAAQ,WAAW;IAC7C,OAAO,CAAC,QAAQ,CAA8C;gBAElD,MAAM,EAAE,YAAY;IAOzB,IAAI,CACT,QAAQ,EAAE,UAAU,EAAE,EACtB,KAAK,CAAC,EAAE,cAAc,EAAE,EACxB,MAAM,CAAC,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,WAAW,GACpB,aAAa,CAAC,QAAQ,CAAC;IAmF1B,OAAO,CAAC,qBAAqB;CAsC9B"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { createGoogleGenerativeAI } from '@ai-sdk/google';
|
|
2
|
+
import { streamText, jsonSchema } from 'ai';
|
|
3
|
+
import { LLMProvider } from './base';
|
|
4
|
+
export class GoogleProvider extends LLMProvider {
|
|
5
|
+
googleAI;
|
|
6
|
+
constructor(config) {
|
|
7
|
+
super(config);
|
|
8
|
+
this.googleAI = createGoogleGenerativeAI({
|
|
9
|
+
apiKey: config.apiKey,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
async *chat(messages, tools, signal, options) {
|
|
13
|
+
try {
|
|
14
|
+
// Convert message format
|
|
15
|
+
const coreMessages = this.convertToCoreMessages(messages);
|
|
16
|
+
// Convert tools to Vercel AI SDK format
|
|
17
|
+
// ToolDefinition format: { type: 'function', function: { name, description, parameters } }
|
|
18
|
+
// Vercel AI SDK expects: { [name]: { description, inputSchema: Schema } }
|
|
19
|
+
// Note: Google Gemini API requires additionalProperties to be explicitly set
|
|
20
|
+
const vercelTools = tools?.length
|
|
21
|
+
? Object.fromEntries(tools.map((toolDef) => [
|
|
22
|
+
toolDef.function.name,
|
|
23
|
+
{
|
|
24
|
+
description: toolDef.function.description,
|
|
25
|
+
inputSchema: jsonSchema({
|
|
26
|
+
...toolDef.function.parameters,
|
|
27
|
+
additionalProperties: toolDef.function.parameters.additionalProperties ?? false,
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
]))
|
|
31
|
+
: undefined;
|
|
32
|
+
// Use Vercel AI SDK's streamText
|
|
33
|
+
const result = streamText({
|
|
34
|
+
model: this.googleAI(this.config.model),
|
|
35
|
+
messages: coreMessages,
|
|
36
|
+
system: options?.systemInstruction,
|
|
37
|
+
maxOutputTokens: this.config.maxTokens,
|
|
38
|
+
temperature: this.config.temperature,
|
|
39
|
+
abortSignal: signal,
|
|
40
|
+
tools: vercelTools,
|
|
41
|
+
});
|
|
42
|
+
// Process stream response
|
|
43
|
+
for await (const textDelta of result.textStream) {
|
|
44
|
+
yield { type: 'content', delta: textDelta };
|
|
45
|
+
}
|
|
46
|
+
// Get tool calls after stream completes (they are complete at this point)
|
|
47
|
+
const toolCalls = await result.toolCalls;
|
|
48
|
+
for (const toolCall of toolCalls) {
|
|
49
|
+
yield {
|
|
50
|
+
type: 'tool_call',
|
|
51
|
+
tool_call: {
|
|
52
|
+
id: toolCall.toolCallId,
|
|
53
|
+
name: toolCall.toolName,
|
|
54
|
+
// input can be undefined if the tool has no parameters, default to empty object
|
|
55
|
+
arguments: JSON.stringify(toolCall.input ?? {}),
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// Get usage stats
|
|
60
|
+
const usage = await result.usage;
|
|
61
|
+
yield {
|
|
62
|
+
type: 'usage',
|
|
63
|
+
usage: {
|
|
64
|
+
input_tokens: usage.inputTokens ?? 0,
|
|
65
|
+
output_tokens: usage.outputTokens ?? 0,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
yield { type: 'done' };
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
// Handle AbortError (including DOMException from Google SDK)
|
|
72
|
+
if (error instanceof Error &&
|
|
73
|
+
(error.name === 'AbortError' || error.message?.toLowerCase().includes('abort'))) {
|
|
74
|
+
yield { type: 'error', error: 'Operation aborted' };
|
|
75
|
+
yield { type: 'done' };
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Handle API errors - yield as error content instead of throwing
|
|
79
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
80
|
+
yield { type: 'error', error: errorMessage };
|
|
81
|
+
yield { type: 'done' };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
convertToCoreMessages(messages) {
|
|
85
|
+
return messages
|
|
86
|
+
.filter((msg) => msg.type !== 'system')
|
|
87
|
+
.map((msg) => {
|
|
88
|
+
switch (msg.type) {
|
|
89
|
+
case 'user':
|
|
90
|
+
return { role: 'user', content: msg.message.content };
|
|
91
|
+
case 'assistant': {
|
|
92
|
+
const text = msg.message.content
|
|
93
|
+
.filter((c) => c.type === 'text')
|
|
94
|
+
.map((c) => c.text)
|
|
95
|
+
.join('');
|
|
96
|
+
return { role: 'assistant', content: text };
|
|
97
|
+
}
|
|
98
|
+
case 'tool_result': {
|
|
99
|
+
// Get tool name from the tool call in the previous assistant message
|
|
100
|
+
const toolName = msg.tool_use_id ? 'Tool' : 'unknown';
|
|
101
|
+
// Output must be wrapped in {type, value} format per Vercel AI SDK schema
|
|
102
|
+
const outputValue = typeof msg.result === 'string' ? msg.result : JSON.stringify(msg.result);
|
|
103
|
+
return {
|
|
104
|
+
role: 'tool',
|
|
105
|
+
content: [{
|
|
106
|
+
type: 'tool-result',
|
|
107
|
+
toolCallId: msg.tool_use_id,
|
|
108
|
+
toolName,
|
|
109
|
+
output: {
|
|
110
|
+
type: 'text',
|
|
111
|
+
value: outputValue,
|
|
112
|
+
},
|
|
113
|
+
}],
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
default:
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
.filter((m) => m !== null);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=google.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google.js","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAqB,UAAU,EAAE,MAAM,IAAI,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAwD,MAAM,QAAQ,CAAC;AAgB3F,MAAM,OAAO,cAAe,SAAQ,WAAW;IACrC,QAAQ,CAA8C;IAE9D,YAAY,MAAoB;QAC9B,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,QAAQ,GAAG,wBAAwB,CAAC;YACvC,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,CAAC,IAAI,CACT,QAAsB,EACtB,KAAwB,EACxB,MAAoB,EACpB,OAAqB;QAErB,IAAI,CAAC;YACH,yBAAyB;YACzB,MAAM,YAAY,GAAG,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;YAE1D,wCAAwC;YACxC,2FAA2F;YAC3F,0EAA0E;YAC1E,6EAA6E;YAC7E,MAAM,WAAW,GAA2C,KAAK,EAAE,MAAM;gB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K,IAAI,CAAC,CAAC;IAClD,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LLMProvider, type ProviderConfig, type LLMChunk, type ChatOptions } from './base';
|
|
2
|
+
import type { SDKMessage } from '../types/messages';
|
|
3
|
+
import type { ToolDefinition } from '../types/tools';
|
|
4
|
+
export interface OpenAIConfig extends ProviderConfig {
|
|
5
|
+
}
|
|
6
|
+
export declare class OpenAIProvider extends LLMProvider {
|
|
7
|
+
private openAI;
|
|
8
|
+
constructor(config: OpenAIConfig);
|
|
9
|
+
chat(messages: SDKMessage[], tools?: ToolDefinition[], signal?: AbortSignal, options?: ChatOptions): AsyncIterable<LLMChunk>;
|
|
10
|
+
private convertToCoreMessages;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC3F,OAAO,KAAK,EAAE,UAAU,EAAyB,MAAM,mBAAmB,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAUrD,MAAM,WAAW,YAAa,SAAQ,cAAc;CAEnD;AAED,qBAAa,cAAe,SAAQ,WAAW;IAC7C,OAAO,CAAC,MAAM,CAAkC;gBAEpC,MAAM,EAAE,YAAY;IAQzB,IAAI,CACT,QAAQ,EAAE,UAAU,EAAE,EACtB,KAAK,CAAC,EAAE,cAAc,EAAE,EACxB,MAAM,CAAC,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,WAAW,GACpB,aAAa,CAAC,QAAQ,CAAC;IAmE1B,OAAO,CAAC,qBAAqB;CAsC9B"}
|