@zimtsui/brainswitch 0.0.54 → 0.0.56
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/DEVELOPMENT.md +13 -14
- package/README.md +7 -14
- package/build/adaptor.d.ts +5 -5
- package/build/adaptor.js +16 -16
- package/build/adaptor.js.map +1 -1
- package/build/agentloop.d.ts +5 -5
- package/build/agentloop.js +4 -4
- package/build/agentloop.js.map +1 -1
- package/build/api-types/anthropic/billing.d.ts +12 -0
- package/build/api-types/anthropic/billing.js +15 -0
- package/build/api-types/anthropic/billing.js.map +1 -0
- package/build/api-types/anthropic/tool-codec.d.ts +17 -0
- package/build/api-types/anthropic/tool-codec.js +73 -0
- package/build/api-types/anthropic/tool-codec.js.map +1 -0
- package/build/api-types/google/billing.d.ts +12 -0
- package/build/api-types/google/billing.js +24 -0
- package/build/api-types/google/billing.js.map +1 -0
- package/build/api-types/google/restful-request.d.ts +8 -0
- package/build/api-types/google/restful-request.js +2 -0
- package/build/api-types/google/restful-request.js.map +1 -0
- package/build/api-types/google/tool-codec.d.ts +16 -0
- package/build/api-types/{google.js → google/tool-codec.js} +27 -26
- package/build/api-types/google/tool-codec.js.map +1 -0
- package/build/api-types/openai-chatcompletion/billing.d.ts +13 -0
- package/build/api-types/openai-chatcompletion/billing.js +16 -0
- package/build/api-types/openai-chatcompletion/billing.js.map +1 -0
- package/build/api-types/openai-chatcompletion/tool-codec.d.ts +18 -0
- package/build/api-types/openai-chatcompletion/tool-codec.js +86 -0
- package/build/api-types/openai-chatcompletion/tool-codec.js.map +1 -0
- package/build/api-types/openai-responses/billing.d.ts +12 -0
- package/build/api-types/openai-responses/billing.js +15 -0
- package/build/api-types/openai-responses/billing.js.map +1 -0
- package/build/api-types/openai-responses/tool-codec.d.ts +16 -0
- package/build/api-types/openai-responses/tool-codec.js +72 -0
- package/build/api-types/openai-responses/tool-codec.js.map +1 -0
- package/build/compatible/engine.d/aliyun.d.ts +23 -0
- package/build/compatible/engine.d/aliyun.js +44 -0
- package/build/compatible/engine.d/aliyun.js.map +1 -0
- package/build/compatible/engine.d/anthropic.d.ts +23 -0
- package/build/compatible/engine.d/anthropic.js +41 -0
- package/build/compatible/engine.d/anthropic.js.map +1 -0
- package/build/compatible/engine.d/google.d.ts +23 -0
- package/build/compatible/engine.d/google.js +45 -0
- package/build/compatible/engine.d/google.js.map +1 -0
- package/build/compatible/engine.d/openai-responses.d.ts +23 -0
- package/build/compatible/engine.d/openai-responses.js +41 -0
- package/build/compatible/engine.d/openai-responses.js.map +1 -0
- package/build/compatible/engine.d.ts +18 -0
- package/build/compatible/engine.js +21 -0
- package/build/compatible/engine.js.map +1 -0
- package/build/compatible/session.d.ts +78 -0
- package/build/compatible/session.js +138 -0
- package/build/compatible/session.js.map +1 -0
- package/build/compatible/tool-call-validator.d.ts +11 -0
- package/build/compatible/tool-call-validator.js +12 -0
- package/build/compatible/tool-call-validator.js.map +1 -0
- package/build/compatible.d/aliyun/transport.d.ts +11 -0
- package/build/compatible.d/aliyun/transport.js +9 -0
- package/build/compatible.d/aliyun/transport.js.map +1 -0
- package/build/compatible.d/anthropic/message-codec.d.ts +31 -0
- package/build/compatible.d/anthropic/message-codec.js +88 -0
- package/build/compatible.d/anthropic/message-codec.js.map +1 -0
- package/build/compatible.d/anthropic/transport.d.ts +31 -0
- package/build/compatible.d/anthropic/transport.js +137 -0
- package/build/compatible.d/anthropic/transport.js.map +1 -0
- package/build/compatible.d/google/message-codec.d.ts +31 -0
- package/build/compatible.d/google/message-codec.js +98 -0
- package/build/compatible.d/google/message-codec.js.map +1 -0
- package/build/compatible.d/google/transport.d.ts +28 -0
- package/build/compatible.d/google/transport.js +74 -0
- package/build/compatible.d/google/transport.js.map +1 -0
- package/build/compatible.d/openai-chatcompletions/message-codec.d.ts +19 -0
- package/build/compatible.d/openai-chatcompletions/message-codec.js +66 -0
- package/build/compatible.d/openai-chatcompletions/message-codec.js.map +1 -0
- package/build/compatible.d/openai-chatcompletions/transport.d.ts +9 -0
- package/build/compatible.d/openai-chatcompletions/transport.js +25 -0
- package/build/compatible.d/openai-chatcompletions/transport.js.map +1 -0
- package/build/compatible.d/openai-chatcompletions.d/monolith.d.ts +36 -0
- package/build/compatible.d/openai-chatcompletions.d/monolith.js +74 -0
- package/build/compatible.d/openai-chatcompletions.d/monolith.js.map +1 -0
- package/build/compatible.d/openai-chatcompletions.d/stream.d.ts +35 -0
- package/build/{compatible-engines.d → compatible.d}/openai-chatcompletions.d/stream.js +52 -42
- package/build/compatible.d/openai-chatcompletions.d/stream.js.map +1 -0
- package/build/compatible.d/openai-responses/message-codec.d.ts +32 -0
- package/build/compatible.d/openai-responses/message-codec.js +105 -0
- package/build/compatible.d/openai-responses/message-codec.js.map +1 -0
- package/build/compatible.d/openai-responses/transport.d.ts +33 -0
- package/build/compatible.d/openai-responses/transport.js +88 -0
- package/build/compatible.d/openai-responses/transport.js.map +1 -0
- package/build/config.js +1 -1
- package/build/config.js.map +1 -1
- package/build/engine.d.ts +48 -26
- package/build/engine.js +78 -29
- package/build/engine.js.map +1 -1
- package/build/exports.d.ts +14 -13
- package/build/exports.js +14 -13
- package/build/exports.js.map +1 -1
- package/build/function.d.ts +25 -13
- package/build/function.js +2 -1
- package/build/function.js.map +1 -1
- package/build/inference-context.d.ts +1 -1
- package/build/native-engines.d/google/agentloop.d.ts +6 -6
- package/build/native-engines.d/google/agentloop.js +5 -5
- package/build/native-engines.d/google/agentloop.js.map +1 -1
- package/build/native-engines.d/google/engine.d.ts +28 -103
- package/build/native-engines.d/google/engine.js +63 -304
- package/build/native-engines.d/google/engine.js.map +1 -1
- package/build/native-engines.d/google/exports.d.ts +5 -5
- package/build/native-engines.d/google/exports.js +5 -5
- package/build/native-engines.d/google/exports.js.map +1 -1
- package/build/native-engines.d/google/message-codec.d.ts +21 -0
- package/build/native-engines.d/google/message-codec.js +69 -0
- package/build/native-engines.d/google/message-codec.js.map +1 -0
- package/build/native-engines.d/google/session.d.ts +16 -15
- package/build/native-engines.d/google/session.js +2 -2
- package/build/native-engines.d/google/session.js.map +1 -1
- package/build/native-engines.d/google/transport.d.ts +31 -0
- package/build/native-engines.d/google/transport.js +81 -0
- package/build/native-engines.d/google/transport.js.map +1 -0
- package/build/native-engines.d/openai-responses/agentloop.d.ts +7 -7
- package/build/native-engines.d/openai-responses/agentloop.js +6 -6
- package/build/native-engines.d/openai-responses/agentloop.js.map +1 -1
- package/build/native-engines.d/openai-responses/engine.d.ts +26 -106
- package/build/native-engines.d/openai-responses/engine.js +53 -334
- package/build/native-engines.d/openai-responses/engine.js.map +1 -1
- package/build/native-engines.d/openai-responses/exports.d.ts +6 -7
- package/build/native-engines.d/openai-responses/exports.js +6 -7
- package/build/native-engines.d/openai-responses/exports.js.map +1 -1
- package/build/native-engines.d/openai-responses/message-codec.d.ts +21 -0
- package/build/native-engines.d/openai-responses/message-codec.js +69 -0
- package/build/native-engines.d/openai-responses/message-codec.js.map +1 -0
- package/build/native-engines.d/openai-responses/session.d.ts +27 -26
- package/build/native-engines.d/openai-responses/session.js +3 -3
- package/build/native-engines.d/openai-responses/session.js.map +1 -1
- package/build/native-engines.d/openai-responses/tool-call-validator.d.ts +12 -0
- package/build/native-engines.d/openai-responses/tool-call-validator.js +33 -0
- package/build/native-engines.d/openai-responses/tool-call-validator.js.map +1 -0
- package/build/native-engines.d/openai-responses/tool.d.ts +3 -3
- package/build/native-engines.d/openai-responses/tool.js +1 -1
- package/build/native-engines.d/openai-responses/tool.js.map +1 -1
- package/build/native-engines.d/openai-responses/transport.d.ts +36 -0
- package/build/native-engines.d/openai-responses/transport.js +104 -0
- package/build/native-engines.d/openai-responses/transport.js.map +1 -0
- package/build/session.d.ts +5 -75
- package/build/session.js +0 -136
- package/build/session.js.map +1 -1
- package/build/throttle.d.ts +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/test/build/test-codecs.js +230 -0
- package/test/build/test-codecs.js.map +1 -0
- package/test/build/test-compatible-engine.d.ts +1 -0
- package/test/build/test-compatible-engine.js +27 -0
- package/test/build/test-compatible-engine.js.map +1 -0
- package/test/build/test-compatible-engines.d.ts +1 -0
- package/test/build/test-compatible-engines.js +112 -0
- package/test/build/test-compatible-engines.js.map +1 -0
- package/test/build/test-engine.d.ts +1 -0
- package/test/build/test-engine.js +97 -0
- package/test/build/test-engine.js.map +1 -0
- package/test/build/test-helpers.d.ts +46 -0
- package/test/build/test-helpers.js +45 -0
- package/test/build/test-helpers.js.map +1 -0
- package/test/build/test-native-engines.d.ts +1 -0
- package/test/build/test-native-engines.js +64 -0
- package/test/build/test-native-engines.js.map +1 -0
- package/test/build/test.d.ts +5 -0
- package/test/build/test.js +6 -0
- package/test/build/test.js.map +1 -0
- package/test/build/tsconfig.tsbuildinfo +1 -0
- package/test/src/test-codecs.ts +256 -0
- package/test/src/test-compatible-engine.ts +45 -0
- package/test/src/test-compatible-engines.ts +129 -0
- package/test/src/test-engine.ts +144 -0
- package/test/src/test-helpers.ts +53 -0
- package/test/src/test-native-engines.ts +75 -0
- package/test/src/test.ts +5 -0
- package/test/src/tsconfig.json +30 -0
- package/build/api-types/anthropic.d.ts +0 -29
- package/build/api-types/anthropic.js +0 -93
- package/build/api-types/anthropic.js.map +0 -1
- package/build/api-types/google.d.ts +0 -28
- package/build/api-types/google.js.map +0 -1
- package/build/api-types/openai-chat-completions.d.ts +0 -31
- package/build/api-types/openai-chat-completions.js +0 -113
- package/build/api-types/openai-chat-completions.js.map +0 -1
- package/build/api-types/openai-responses.d.ts +0 -23
- package/build/api-types/openai-responses.js +0 -71
- package/build/api-types/openai-responses.js.map +0 -1
- package/build/compatible-engine.d.ts +0 -51
- package/build/compatible-engine.js +0 -67
- package/build/compatible-engine.js.map +0 -1
- package/build/compatible-engines.d/aliyun.d.ts +0 -69
- package/build/compatible-engines.d/aliyun.js +0 -149
- package/build/compatible-engines.d/aliyun.js.map +0 -1
- package/build/compatible-engines.d/anthropic.d.ts +0 -78
- package/build/compatible-engines.d/anthropic.js +0 -312
- package/build/compatible-engines.d/anthropic.js.map +0 -1
- package/build/compatible-engines.d/google.d.ts +0 -83
- package/build/compatible-engines.d/google.js +0 -279
- package/build/compatible-engines.d/google.js.map +0 -1
- package/build/compatible-engines.d/openai-chatcompletions.d/monolith.d.ts +0 -15
- package/build/compatible-engines.d/openai-chatcompletions.d/monolith.js +0 -75
- package/build/compatible-engines.d/openai-chatcompletions.d/monolith.js.map +0 -1
- package/build/compatible-engines.d/openai-chatcompletions.d/stream.d.ts +0 -21
- package/build/compatible-engines.d/openai-chatcompletions.d/stream.js.map +0 -1
- package/build/compatible-engines.d/openai-chatcompletions.d.ts +0 -27
- package/build/compatible-engines.d/openai-chatcompletions.js +0 -76
- package/build/compatible-engines.d/openai-chatcompletions.js.map +0 -1
- package/build/compatible-engines.d/openai-responses.d.ts +0 -93
- package/build/compatible-engines.d/openai-responses.js +0 -300
- package/build/compatible-engines.d/openai-responses.js.map +0 -1
- package/build/test.js +0 -198
- package/build/test.js.map +0 -1
- /package/{build/test.d.ts → test/build/test-codecs.d.ts} +0 -0
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
import { CompatibleEngine } from "../compatible-engine.js";
|
|
2
|
-
import { Function } from "../function.js";
|
|
3
|
-
import { RoleMessage } from "../session.js";
|
|
4
|
-
import { Engine, ResponseInvalid } from "../engine.js";
|
|
5
|
-
import {} from "../inference-context.js";
|
|
6
|
-
import Anthropic from '@anthropic-ai/sdk';
|
|
7
|
-
import { AnthropicEngine } from "../api-types/anthropic.js";
|
|
8
|
-
import * as Undici from 'undici';
|
|
9
|
-
import { Throttle } from "../throttle.js";
|
|
10
|
-
import { logger } from "../telemetry.js";
|
|
11
|
-
export var AnthropicCompatibleEngine;
|
|
12
|
-
(function (AnthropicCompatibleEngine) {
|
|
13
|
-
function convertFromUserMessage(userMessage) {
|
|
14
|
-
return userMessage.getParts().map(part => {
|
|
15
|
-
if (part instanceof RoleMessage.Part.Text.Instance)
|
|
16
|
-
return {
|
|
17
|
-
type: 'text',
|
|
18
|
-
text: part.text,
|
|
19
|
-
};
|
|
20
|
-
else if (part instanceof Function.Response)
|
|
21
|
-
return this.convertFromFunctionResponse(part);
|
|
22
|
-
else
|
|
23
|
-
throw new Error();
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
AnthropicCompatibleEngine.convertFromUserMessage = convertFromUserMessage;
|
|
27
|
-
function convertFromAiMessage(aiMessage) {
|
|
28
|
-
if (aiMessage instanceof AnthropicCompatibleEngine.Message.Ai.Instance)
|
|
29
|
-
return aiMessage.raw;
|
|
30
|
-
else {
|
|
31
|
-
return aiMessage.getParts().map(part => {
|
|
32
|
-
if (part instanceof RoleMessage.Part.Text.Instance)
|
|
33
|
-
return {
|
|
34
|
-
type: 'text',
|
|
35
|
-
text: part.text,
|
|
36
|
-
};
|
|
37
|
-
else if (part instanceof Function.Call)
|
|
38
|
-
return this.convertFromFunctionCall(part);
|
|
39
|
-
else
|
|
40
|
-
throw new Error();
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
AnthropicCompatibleEngine.convertFromAiMessage = convertFromAiMessage;
|
|
45
|
-
function convertFromDeveloperMessage(developerMessage) {
|
|
46
|
-
return developerMessage.getParts().map(part => ({ type: 'text', text: part.text }));
|
|
47
|
-
}
|
|
48
|
-
AnthropicCompatibleEngine.convertFromDeveloperMessage = convertFromDeveloperMessage;
|
|
49
|
-
function convertFromChatMessage(chatMessage) {
|
|
50
|
-
if (chatMessage instanceof RoleMessage.User.Instance)
|
|
51
|
-
return { role: 'user', content: this.convertFromUserMessage(chatMessage) };
|
|
52
|
-
else if (chatMessage instanceof RoleMessage.Ai.Instance)
|
|
53
|
-
return { role: 'assistant', content: this.convertFromAiMessage(chatMessage) };
|
|
54
|
-
else
|
|
55
|
-
throw new Error();
|
|
56
|
-
}
|
|
57
|
-
AnthropicCompatibleEngine.convertFromChatMessage = convertFromChatMessage;
|
|
58
|
-
function makeParams(session) {
|
|
59
|
-
const fdentries = Object.entries(this.fdm);
|
|
60
|
-
const tools = fdentries.map(fdentry => this.convertFromFunctionDeclarationEntry(fdentry));
|
|
61
|
-
return {
|
|
62
|
-
model: this.model,
|
|
63
|
-
stream: true,
|
|
64
|
-
messages: session.chatMessages.map(chatMessage => this.convertFromChatMessage(chatMessage)),
|
|
65
|
-
system: session.developerMessage && this.convertFromDeveloperMessage(session.developerMessage),
|
|
66
|
-
tools: tools.length ? tools : undefined,
|
|
67
|
-
max_tokens: this.maxTokens ?? 64 * 1024,
|
|
68
|
-
...this.additionalOptions,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
AnthropicCompatibleEngine.makeParams = makeParams;
|
|
72
|
-
function convertToAiMessage(raw) {
|
|
73
|
-
const parts = raw.flatMap((item) => {
|
|
74
|
-
if (item.type === 'text') {
|
|
75
|
-
return [RoleMessage.Part.Text.create(item.text)];
|
|
76
|
-
}
|
|
77
|
-
else if (item.type === 'tool_use')
|
|
78
|
-
return [this.convertToFunctionCall(item)];
|
|
79
|
-
else if (item.type === 'thinking')
|
|
80
|
-
return [];
|
|
81
|
-
else
|
|
82
|
-
throw new Error();
|
|
83
|
-
});
|
|
84
|
-
return AnthropicCompatibleEngine.Message.Ai.create(parts, raw);
|
|
85
|
-
}
|
|
86
|
-
AnthropicCompatibleEngine.convertToAiMessage = convertToAiMessage;
|
|
87
|
-
async function fetch(wfctx, session, signal) {
|
|
88
|
-
const params = this.makeParams(session);
|
|
89
|
-
logger.message?.trace(params);
|
|
90
|
-
await this.throttle.requests(wfctx);
|
|
91
|
-
const stream = this.anthropic.messages.stream(params, { signal });
|
|
92
|
-
let response = null;
|
|
93
|
-
for await (const event of stream) {
|
|
94
|
-
if (event.type === 'message_start') {
|
|
95
|
-
logger.message?.trace(event);
|
|
96
|
-
response = structuredClone(event.message);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
if (response) { }
|
|
100
|
-
else
|
|
101
|
-
throw new Error();
|
|
102
|
-
if (event.type === 'message_delta') {
|
|
103
|
-
logger.message?.trace(event);
|
|
104
|
-
response.stop_sequence = event.delta.stop_sequence ?? response.stop_sequence;
|
|
105
|
-
response.stop_reason = event.delta.stop_reason ?? response.stop_reason;
|
|
106
|
-
response.usage.input_tokens = event.usage.input_tokens ?? response.usage.input_tokens;
|
|
107
|
-
response.usage.output_tokens = event.usage.output_tokens;
|
|
108
|
-
response.usage.cache_read_input_tokens = event.usage.cache_read_input_tokens ?? response.usage.cache_read_input_tokens;
|
|
109
|
-
response.usage.cache_creation_input_tokens = event.usage.cache_creation_input_tokens ?? response.usage.cache_creation_input_tokens;
|
|
110
|
-
response.usage.server_tool_use = event.usage.server_tool_use ?? response.usage.server_tool_use;
|
|
111
|
-
}
|
|
112
|
-
else if (event.type === 'message_stop') {
|
|
113
|
-
logger.message?.trace(event);
|
|
114
|
-
}
|
|
115
|
-
else if (event.type === 'content_block_start') {
|
|
116
|
-
logger.message?.trace(event);
|
|
117
|
-
const contentBlock = structuredClone(event.content_block);
|
|
118
|
-
response.content.push(contentBlock);
|
|
119
|
-
if (contentBlock.type === 'tool_use')
|
|
120
|
-
contentBlock.input = '';
|
|
121
|
-
}
|
|
122
|
-
else if (event.type === 'content_block_delta') {
|
|
123
|
-
const contentBlock = response.content[event.index];
|
|
124
|
-
if (event.delta.type === 'text_delta') {
|
|
125
|
-
logger.inference?.debug(event.delta.text);
|
|
126
|
-
if (contentBlock?.type === 'text') { }
|
|
127
|
-
else
|
|
128
|
-
throw new Error();
|
|
129
|
-
contentBlock.text += event.delta.text;
|
|
130
|
-
}
|
|
131
|
-
else if (event.delta.type === 'thinking_delta') {
|
|
132
|
-
logger.inference?.trace(event.delta.thinking);
|
|
133
|
-
if (contentBlock?.type === 'thinking') { }
|
|
134
|
-
else
|
|
135
|
-
throw new Error();
|
|
136
|
-
contentBlock.thinking += event.delta.thinking;
|
|
137
|
-
}
|
|
138
|
-
else if (event.delta.type === 'signature_delta') {
|
|
139
|
-
if (contentBlock?.type === 'thinking') { }
|
|
140
|
-
else
|
|
141
|
-
throw new Error();
|
|
142
|
-
contentBlock.signature += event.delta.signature;
|
|
143
|
-
}
|
|
144
|
-
else if (event.delta.type === 'input_json_delta') {
|
|
145
|
-
logger.inference?.trace(event.delta.partial_json);
|
|
146
|
-
if (contentBlock?.type === 'tool_use') { }
|
|
147
|
-
else
|
|
148
|
-
throw new Error();
|
|
149
|
-
if (typeof contentBlock.input === 'string') { }
|
|
150
|
-
else
|
|
151
|
-
throw new Error();
|
|
152
|
-
contentBlock.input += event.delta.partial_json;
|
|
153
|
-
}
|
|
154
|
-
else
|
|
155
|
-
throw new Error('Unknown type of content block delta', { cause: event.delta });
|
|
156
|
-
}
|
|
157
|
-
else if (event.type === 'content_block_stop') {
|
|
158
|
-
const contentBlock = response.content[event.index];
|
|
159
|
-
if (contentBlock?.type === 'text')
|
|
160
|
-
logger.inference?.debug('\n');
|
|
161
|
-
else if (contentBlock?.type === 'thinking')
|
|
162
|
-
logger.inference?.trace('\n');
|
|
163
|
-
else if (contentBlock?.type === 'tool_use')
|
|
164
|
-
logger.inference?.debug('\n');
|
|
165
|
-
logger.message?.trace(event);
|
|
166
|
-
if (contentBlock?.type === 'tool_use') {
|
|
167
|
-
if (typeof contentBlock.input === 'string') { }
|
|
168
|
-
else
|
|
169
|
-
throw new Error();
|
|
170
|
-
logger.message?.debug(contentBlock);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
else
|
|
174
|
-
throw new Error('Unknown stream event', { cause: event });
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (response) { }
|
|
178
|
-
else
|
|
179
|
-
throw new Error();
|
|
180
|
-
if (response.stop_reason === 'max_tokens')
|
|
181
|
-
throw new ResponseInvalid('Token limit exceeded.', { cause: response });
|
|
182
|
-
if (response.stop_reason === 'end_turn' || response.stop_reason === 'tool_use') { }
|
|
183
|
-
else
|
|
184
|
-
throw new ResponseInvalid('Abnormal stop reason', { cause: response });
|
|
185
|
-
const cost = this.calcCost(response.usage);
|
|
186
|
-
wfctx.cost?.(cost);
|
|
187
|
-
logger.message?.debug(response.usage);
|
|
188
|
-
const aiMessage = this.convertToAiMessage(response.content);
|
|
189
|
-
this.validateToolCallsByToolChoice(aiMessage.getFunctionCalls());
|
|
190
|
-
return aiMessage;
|
|
191
|
-
}
|
|
192
|
-
AnthropicCompatibleEngine.fetch = fetch;
|
|
193
|
-
let Message;
|
|
194
|
-
(function (Message) {
|
|
195
|
-
let Ai;
|
|
196
|
-
(function (Ai) {
|
|
197
|
-
function create(parts, raw) {
|
|
198
|
-
return new Instance(parts, raw);
|
|
199
|
-
}
|
|
200
|
-
Ai.create = create;
|
|
201
|
-
Ai.NOMINAL = Symbol();
|
|
202
|
-
class Instance extends RoleMessage.Ai.Instance {
|
|
203
|
-
raw;
|
|
204
|
-
constructor(parts, raw) {
|
|
205
|
-
super(parts);
|
|
206
|
-
this.raw = raw;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
Ai.Instance = Instance;
|
|
210
|
-
})(Ai = Message.Ai || (Message.Ai = {}));
|
|
211
|
-
})(Message = AnthropicCompatibleEngine.Message || (AnthropicCompatibleEngine.Message = {}));
|
|
212
|
-
class Instance {
|
|
213
|
-
baseUrl;
|
|
214
|
-
apiKey;
|
|
215
|
-
model;
|
|
216
|
-
name;
|
|
217
|
-
inputPrice;
|
|
218
|
-
outputPrice;
|
|
219
|
-
cachePrice;
|
|
220
|
-
fdm;
|
|
221
|
-
additionalOptions;
|
|
222
|
-
throttle;
|
|
223
|
-
timeout;
|
|
224
|
-
maxTokens;
|
|
225
|
-
proxyAgent;
|
|
226
|
-
toolChoice;
|
|
227
|
-
anthropic;
|
|
228
|
-
parallelToolCall;
|
|
229
|
-
constructor(options) {
|
|
230
|
-
({
|
|
231
|
-
baseUrl: this.baseUrl,
|
|
232
|
-
apiKey: this.apiKey,
|
|
233
|
-
model: this.model,
|
|
234
|
-
name: this.name,
|
|
235
|
-
inputPrice: this.inputPrice,
|
|
236
|
-
outputPrice: this.outputPrice,
|
|
237
|
-
cachePrice: this.cachePrice,
|
|
238
|
-
fdm: this.fdm,
|
|
239
|
-
additionalOptions: this.additionalOptions,
|
|
240
|
-
throttle: this.throttle,
|
|
241
|
-
timeout: this.timeout,
|
|
242
|
-
maxTokens: this.maxTokens,
|
|
243
|
-
proxyAgent: this.proxyAgent,
|
|
244
|
-
} = (Engine.OwnProps.init).call(this, options));
|
|
245
|
-
({ toolChoice: this.toolChoice } = (CompatibleEngine.OwnProps.init).call(this, options));
|
|
246
|
-
({
|
|
247
|
-
parallelToolCall: this.parallelToolCall,
|
|
248
|
-
anthropic: this.anthropic,
|
|
249
|
-
} = (AnthropicEngine.OwnProps.init).call(this, options));
|
|
250
|
-
}
|
|
251
|
-
stateless(wfctx, session) {
|
|
252
|
-
return (CompatibleEngine.stateless).call(this, wfctx, session);
|
|
253
|
-
}
|
|
254
|
-
stateful(wfctx, session) {
|
|
255
|
-
return (CompatibleEngine.stateful).call(this, wfctx, session);
|
|
256
|
-
}
|
|
257
|
-
appendUserMessage(session, message) {
|
|
258
|
-
return (CompatibleEngine.appendUserMessage).call(this, session, message);
|
|
259
|
-
}
|
|
260
|
-
pushUserMessage(session, message) {
|
|
261
|
-
return (CompatibleEngine.pushUserMessage).call(this, session, message);
|
|
262
|
-
}
|
|
263
|
-
validateToolCallsByToolChoice(toolCalls) {
|
|
264
|
-
return (CompatibleEngine.validateToolCallsByToolChoice).call(this, toolCalls);
|
|
265
|
-
}
|
|
266
|
-
convertFromFunctionCall(fc) {
|
|
267
|
-
return (AnthropicEngine.convertFromFunctionCall).call(this, fc);
|
|
268
|
-
}
|
|
269
|
-
convertToFunctionCall(apifc) {
|
|
270
|
-
return (AnthropicEngine.convertToFunctionCall).call(this, apifc);
|
|
271
|
-
}
|
|
272
|
-
convertFromFunctionResponse(fr) {
|
|
273
|
-
return (AnthropicEngine.convertFromFunctionResponse).call(this, fr);
|
|
274
|
-
}
|
|
275
|
-
convertFromFunctionDeclarationEntry(fdentry) {
|
|
276
|
-
return (AnthropicEngine.convertFromFunctionDeclarationEntry).call(this, fdentry);
|
|
277
|
-
}
|
|
278
|
-
convertFromToolChoice(toolChoice, parallel) {
|
|
279
|
-
return (AnthropicEngine.convertFromToolChoice).call(this, toolChoice, parallel);
|
|
280
|
-
}
|
|
281
|
-
calcCost(usage) {
|
|
282
|
-
return (AnthropicEngine.calcCost).call(this, usage);
|
|
283
|
-
}
|
|
284
|
-
convertFromUserMessage(userMessage) {
|
|
285
|
-
return (AnthropicCompatibleEngine.convertFromUserMessage).call(this, userMessage);
|
|
286
|
-
}
|
|
287
|
-
convertFromAiMessage(aiMessage) {
|
|
288
|
-
return (AnthropicCompatibleEngine.convertFromAiMessage).call(this, aiMessage);
|
|
289
|
-
}
|
|
290
|
-
convertFromDeveloperMessage(developerMessage) {
|
|
291
|
-
return (AnthropicCompatibleEngine.convertFromDeveloperMessage).call(this, developerMessage);
|
|
292
|
-
}
|
|
293
|
-
convertFromChatMessage(chatMessage) {
|
|
294
|
-
return (AnthropicCompatibleEngine.convertFromChatMessage).call(this, chatMessage);
|
|
295
|
-
}
|
|
296
|
-
makeParams(session) {
|
|
297
|
-
return (AnthropicCompatibleEngine.makeParams).call(this, session);
|
|
298
|
-
}
|
|
299
|
-
convertToAiMessage(raw) {
|
|
300
|
-
return (AnthropicCompatibleEngine.convertToAiMessage).call(this, raw);
|
|
301
|
-
}
|
|
302
|
-
fetch(wfctx, session, signal) {
|
|
303
|
-
return (AnthropicCompatibleEngine.fetch).call(this, wfctx, session, signal);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
AnthropicCompatibleEngine.Instance = Instance;
|
|
307
|
-
function create(options) {
|
|
308
|
-
return new AnthropicCompatibleEngine.Instance(options);
|
|
309
|
-
}
|
|
310
|
-
AnthropicCompatibleEngine.create = create;
|
|
311
|
-
})(AnthropicCompatibleEngine || (AnthropicCompatibleEngine = {}));
|
|
312
|
-
//# sourceMappingURL=anthropic.js.map
|
|
@@ -1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6B;YACnD,OAAO,CAAC,yBAAyB,CAAC,kBAAuB,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAC/E,CAAC;QACM,KAAK,CAAC,KAAuB,EAAE,OAAgD,EAAE,MAAoB;YACxG,OAAO,CAAC,yBAAyB,CAAC,KAAU,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QACrF,CAAC;KAEJ;IAzGY,kCAAQ,WAyGpB,CAAA;IAED,SAAgB,MAAM,CAAuC,OAA+C;QACxG,OAAO,IAAI,yBAAyB,CAAC,QAAQ,CAAM,OAAO,CAAC,CAAC;IAChE,CAAC;IAFe,gCAAM,SAErB,CAAA;AAEL,CAAC,EApUgB,yBAAyB,KAAzB,yBAAyB,QAoUzC"}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { CompatibleEngine } from '../compatible-engine.ts';
|
|
2
|
-
import { Engine } from '../engine.ts';
|
|
3
|
-
import { RoleMessage, type Session, type ChatMessage } from '../session.ts';
|
|
4
|
-
import { Function } from '../function.ts';
|
|
5
|
-
import * as Google from '@google/genai';
|
|
6
|
-
import * as Undici from 'undici';
|
|
7
|
-
import { type InferenceContext } from '../inference-context.ts';
|
|
8
|
-
import { GoogleEngine } from '../api-types/google.ts';
|
|
9
|
-
import { Throttle } from '../throttle.ts';
|
|
10
|
-
export declare namespace GoogleCompatibleEngine {
|
|
11
|
-
interface Options<in out fdm extends Function.Declaration.Map> extends CompatibleEngine.Options<fdm>, GoogleEngine.Options<fdm> {
|
|
12
|
-
}
|
|
13
|
-
interface OwnProps<in out fdm extends Function.Declaration.Map> {
|
|
14
|
-
apiURL: URL;
|
|
15
|
-
}
|
|
16
|
-
namespace OwnProps {
|
|
17
|
-
function init<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, options: Options<fdm>): OwnProps<fdm>;
|
|
18
|
-
}
|
|
19
|
-
interface Underhood<in out fdm extends Function.Declaration.Map> extends GoogleEngine.Underhood<fdm>, CompatibleEngine.Underhood<fdm>, OwnProps<fdm> {
|
|
20
|
-
convertFromUserMessage(userMessage: RoleMessage.User<Function.Declaration.From<fdm>>): Google.Content;
|
|
21
|
-
convertFromAiMessage(aiMessage: RoleMessage.Ai<Function.Declaration.From<fdm>>): Google.Content;
|
|
22
|
-
convertFromDeveloperMessage(developerMessage: RoleMessage.Developer): Google.Content;
|
|
23
|
-
convertFromChatMessages(chatMessages: ChatMessage<Function.Declaration.From<fdm>>[]): Google.Content[];
|
|
24
|
-
convertToAiMessage(content: Google.Content): GoogleCompatibleEngine.Message.Ai<Function.Declaration.From<fdm>>;
|
|
25
|
-
convertFromToolChoice(toolChoice: Function.ToolChoice<fdm>): Google.FunctionCallingConfig;
|
|
26
|
-
fetch(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>, signal?: AbortSignal): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
|
|
27
|
-
}
|
|
28
|
-
function convertFromAiMessage<fdm extends Function.Declaration.Map>(this: GoogleCompatibleEngine.Underhood<fdm>, aiMessage: RoleMessage.Ai<Function.Declaration.From<fdm>>): Google.Content;
|
|
29
|
-
function convertFromChatMessages<fdm extends Function.Declaration.Map>(this: GoogleCompatibleEngine.Underhood<fdm>, chatMessages: ChatMessage<Function.Declaration.From<fdm>>[]): Google.Content[];
|
|
30
|
-
function fetch<fdm extends Function.Declaration.Map>(this: GoogleCompatibleEngine.Underhood<fdm>, wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>, signal?: AbortSignal): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
|
|
31
|
-
function convertFromUserMessage<fdm extends Function.Declaration.Map>(userMessage: RoleMessage.User<Function.Declaration.From<fdm>>): Google.Content;
|
|
32
|
-
function convertFromDeveloperMessage(developerMessage: RoleMessage.Developer): Google.Content;
|
|
33
|
-
function convertFromToolChoice<fdm extends Function.Declaration.Map>(toolChoice: Function.ToolChoice<fdm>): Google.FunctionCallingConfig;
|
|
34
|
-
function convertToAiMessage<fdm extends Function.Declaration.Map>(this: GoogleCompatibleEngine.Underhood<fdm>, content: Google.Content): GoogleCompatibleEngine.Message.Ai<Function.Declaration.From<fdm>>;
|
|
35
|
-
namespace Message {
|
|
36
|
-
type Ai<fdu extends Function.Declaration> = Ai.Instance<fdu>;
|
|
37
|
-
namespace Ai {
|
|
38
|
-
function create<fdu extends Function.Declaration>(parts: RoleMessage.Ai.Part<fdu>[], raw: Google.Content): Ai<fdu>;
|
|
39
|
-
const NOMINAL: unique symbol;
|
|
40
|
-
class Instance<out fdu extends Function.Declaration> extends RoleMessage.Ai.Instance<fdu> {
|
|
41
|
-
protected raw: Google.Content;
|
|
42
|
-
readonly [NOMINAL]: void;
|
|
43
|
-
constructor(parts: RoleMessage.Ai.Part<fdu>[], raw: Google.Content);
|
|
44
|
-
getRaw(): Google.Content;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
class Instance<in out fdm extends Function.Declaration.Map> implements GoogleCompatibleEngine.Underhood<fdm> {
|
|
49
|
-
baseUrl: string;
|
|
50
|
-
apiKey: string;
|
|
51
|
-
model: string;
|
|
52
|
-
name: string;
|
|
53
|
-
inputPrice: number;
|
|
54
|
-
outputPrice: number;
|
|
55
|
-
cachePrice: number;
|
|
56
|
-
fdm: fdm;
|
|
57
|
-
additionalOptions?: Record<string, unknown>;
|
|
58
|
-
throttle: Throttle;
|
|
59
|
-
timeout?: number;
|
|
60
|
-
maxTokens?: number;
|
|
61
|
-
proxyAgent?: Undici.ProxyAgent;
|
|
62
|
-
toolChoice: Function.ToolChoice<fdm>;
|
|
63
|
-
parallelToolCall: boolean;
|
|
64
|
-
apiURL: URL;
|
|
65
|
-
constructor(options: GoogleCompatibleEngine.Options<fdm>);
|
|
66
|
-
stateless(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm, Extract<keyof fdm, string>>>>;
|
|
67
|
-
stateful(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm, Extract<keyof fdm, string>>>>;
|
|
68
|
-
appendUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm, Extract<keyof fdm, string>>>;
|
|
69
|
-
pushUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm, Extract<keyof fdm, string>>>;
|
|
70
|
-
validateToolCallsByToolChoice(toolCalls: Function.Call.Distributive<Function.Declaration.From<fdm>>[]): void;
|
|
71
|
-
convertFromFunctionCall(fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): Google.FunctionCall;
|
|
72
|
-
convertToFunctionCall(googlefc: Google.FunctionCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
73
|
-
convertFromFunctionDeclarationEntry(fdentry: Function.Declaration.Entry.From<fdm>): Google.FunctionDeclaration;
|
|
74
|
-
convertFromUserMessage(userMessage: RoleMessage.User<Function.Declaration.From<fdm>>): Google.Content;
|
|
75
|
-
convertFromAiMessage(aiMessage: RoleMessage.Ai<Function.Declaration.From<fdm>>): Google.Content;
|
|
76
|
-
convertFromDeveloperMessage(developerMessage: RoleMessage.Developer): Google.Content;
|
|
77
|
-
convertFromChatMessages(chatMessages: ChatMessage<Function.Declaration.From<fdm>>[]): Google.Content[];
|
|
78
|
-
convertToAiMessage(content: Google.Content): GoogleCompatibleEngine.Message.Ai<Function.Declaration.From<fdm>>;
|
|
79
|
-
convertFromToolChoice(toolChoice: Function.ToolChoice<fdm>): Google.FunctionCallingConfig;
|
|
80
|
-
fetch(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>, signal?: AbortSignal): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
|
|
81
|
-
}
|
|
82
|
-
function create<fdm extends Function.Declaration.Map>(options: CompatibleEngine.Options<fdm>): CompatibleEngine<fdm>;
|
|
83
|
-
}
|