@zimtsui/brainswitch 0.0.41 → 0.0.42
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/build/adaptor.d.ts +4 -2
- package/build/adaptor.js +9 -3
- package/build/adaptor.js.map +1 -1
- package/build/agentloop.d.ts +1 -1
- package/build/agentloop.js +2 -2
- package/build/agentloop.js.map +1 -1
- package/build/api-types/anthropic.d.ts +18 -22
- package/build/api-types/anthropic.js +81 -79
- package/build/api-types/anthropic.js.map +1 -1
- package/build/api-types/google.d.ts +13 -18
- package/build/api-types/google.js +23 -31
- package/build/api-types/google.js.map +1 -1
- package/build/api-types/openai-chat-completions.d.ts +17 -19
- package/build/api-types/openai-chat-completions.js +101 -96
- package/build/api-types/openai-chat-completions.js.map +1 -1
- package/build/api-types/openai-responses.d.ts +13 -13
- package/build/api-types/openai-responses.js +59 -56
- package/build/api-types/openai-responses.js.map +1 -1
- package/build/compatible-engine.d.ts +19 -24
- package/build/compatible-engine.js +54 -56
- package/build/compatible-engine.js.map +1 -1
- package/build/compatible-engines.d/aliyun.d.ts +38 -55
- package/build/compatible-engines.d/aliyun.js +91 -143
- package/build/compatible-engines.d/aliyun.js.map +1 -1
- package/build/compatible-engines.d/anthropic.d.ts +35 -60
- package/build/compatible-engines.d/anthropic.js +230 -296
- package/build/compatible-engines.d/anthropic.js.map +1 -1
- package/build/compatible-engines.d/google.d.ts +38 -59
- package/build/compatible-engines.d/google.js +165 -237
- package/build/compatible-engines.d/google.js.map +1 -1
- package/build/compatible-engines.d/openai-chatcompletions.d/monolith.d.ts +7 -14
- package/build/compatible-engines.d/openai-chatcompletions.d/monolith.js +64 -71
- package/build/compatible-engines.d/openai-chatcompletions.d/monolith.js.map +1 -1
- package/build/compatible-engines.d/openai-chatcompletions.d/stream.d.ts +10 -16
- package/build/compatible-engines.d/openai-chatcompletions.d/stream.js +169 -184
- package/build/compatible-engines.d/openai-chatcompletions.d/stream.js.map +1 -1
- package/build/compatible-engines.d/openai-chatcompletions.d.ts +12 -18
- package/build/compatible-engines.d/openai-chatcompletions.js +64 -67
- package/build/compatible-engines.d/openai-chatcompletions.js.map +1 -1
- package/build/compatible-engines.d/openai-responses.d.ts +46 -68
- package/build/compatible-engines.d/openai-responses.js +218 -281
- package/build/compatible-engines.d/openai-responses.js.map +1 -1
- package/build/engine.d.ts +10 -24
- package/build/engine.js +25 -38
- package/build/engine.js.map +1 -1
- package/build/exports.d.ts +1 -0
- package/build/exports.js +1 -0
- package/build/exports.js.map +1 -1
- package/build/inference-context.d.ts +1 -10
- package/build/inference-context.js +0 -2
- package/build/inference-context.js.map +1 -1
- package/build/native-engines.d/google/agentloop.d.ts +1 -1
- package/build/native-engines.d/google/agentloop.js +2 -2
- package/build/native-engines.d/google/agentloop.js.map +1 -1
- package/build/native-engines.d/google/engine.d.ts +56 -73
- package/build/native-engines.d/google/engine.js +262 -309
- package/build/native-engines.d/google/engine.js.map +1 -1
- package/build/native-engines.d/google/exports.d.ts +3 -2
- package/build/native-engines.d/google/exports.js +3 -2
- package/build/native-engines.d/google/exports.js.map +1 -1
- package/build/native-engines.d/openai-responses/agentloop.d.ts +1 -1
- package/build/native-engines.d/openai-responses/agentloop.js +2 -2
- package/build/native-engines.d/openai-responses/agentloop.js.map +1 -1
- package/build/native-engines.d/openai-responses/engine.d.ts +59 -78
- package/build/native-engines.d/openai-responses/engine.js +281 -334
- package/build/native-engines.d/openai-responses/engine.js.map +1 -1
- package/build/native-engines.d/openai-responses/exports.d.ts +4 -2
- package/build/native-engines.d/openai-responses/exports.js +4 -2
- package/build/native-engines.d/openai-responses/exports.js.map +1 -1
- package/build/telemetry.d.ts +6 -0
- package/build/telemetry.js +3 -0
- package/build/telemetry.js.map +1 -0
- package/build/throttle.d.ts +1 -1
- package/build/throttle.js +6 -6
- package/build/throttle.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
package/build/adaptor.d.ts
CHANGED
|
@@ -3,11 +3,13 @@ import { Function } from './function.ts';
|
|
|
3
3
|
import { type CompatibleEngine } from './compatible-engine.ts';
|
|
4
4
|
import { OpenAIResponsesNativeEngine } from './native-engines.d/openai-responses/engine.ts';
|
|
5
5
|
import { GoogleNativeEngine } from './native-engines.d/google/engine.ts';
|
|
6
|
+
import { type Logger } from './telemetry.ts';
|
|
6
7
|
export declare class Adaptor {
|
|
7
8
|
config: Config;
|
|
8
|
-
|
|
9
|
+
logger: Logger;
|
|
10
|
+
static create(config: Config, logger: Logger): Adaptor;
|
|
9
11
|
private throttles;
|
|
10
|
-
protected constructor(config: Config);
|
|
12
|
+
protected constructor(config: Config, logger: Logger);
|
|
11
13
|
makeEngine<fdm extends Function.Declaration.Map>(endpoint: string, functionDeclarationMap: fdm, toolChoice?: Function.ToolChoice<fdm>, parallelToolCall?: boolean): CompatibleEngine<fdm>;
|
|
12
14
|
makeOpenAIResponsesNativeEngine<fdm extends Function.Declaration.Map>(endpoint: string, functionDeclarationMap: fdm, applyPatch?: boolean, toolChoice?: Function.ToolChoice<fdm>, parallelToolCall?: boolean): OpenAIResponsesNativeEngine<fdm>;
|
|
13
15
|
makeGoogleNativeEngine<fdm extends Function.Declaration.Map>(endpoint: string, functionDeclarationMap: fdm, toolChoice?: Function.ToolChoice<fdm>, codeExecution?: boolean, urlContext?: boolean, googleSearch?: boolean, parallelToolCall?: boolean): GoogleNativeEngine<fdm>;
|
package/build/adaptor.js
CHANGED
|
@@ -8,14 +8,17 @@ import { OpenAIResponsesCompatibleEngine } from "./compatible-engines.d/openai-r
|
|
|
8
8
|
import { AnthropicCompatibleEngine } from "./compatible-engines.d/anthropic.js";
|
|
9
9
|
import { OpenAIResponsesNativeEngine } from "./native-engines.d/openai-responses/engine.js";
|
|
10
10
|
import { GoogleNativeEngine } from "./native-engines.d/google/engine.js";
|
|
11
|
+
import {} from "./telemetry.js";
|
|
11
12
|
export class Adaptor {
|
|
12
13
|
config;
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
logger;
|
|
15
|
+
static create(config, logger) {
|
|
16
|
+
return new Adaptor(config, logger);
|
|
15
17
|
}
|
|
16
18
|
throttles = new Map();
|
|
17
|
-
constructor(config) {
|
|
19
|
+
constructor(config, logger) {
|
|
18
20
|
this.config = config;
|
|
21
|
+
this.logger = logger;
|
|
19
22
|
for (const endpointId in this.config.brainswitch.endpoints) {
|
|
20
23
|
const rpm = this.config.brainswitch.endpoints[endpointId].rpm ?? Number.POSITIVE_INFINITY;
|
|
21
24
|
this.throttles.set(endpointId, new Throttle(rpm));
|
|
@@ -36,6 +39,7 @@ export class Adaptor {
|
|
|
36
39
|
toolChoice,
|
|
37
40
|
parallelToolCall,
|
|
38
41
|
throttle,
|
|
42
|
+
logger: this.logger,
|
|
39
43
|
};
|
|
40
44
|
if (endpointSpec.apiType === 'openai-responses')
|
|
41
45
|
return OpenAIResponsesCompatibleEngine.create(options);
|
|
@@ -64,6 +68,7 @@ export class Adaptor {
|
|
|
64
68
|
parallelToolCall,
|
|
65
69
|
throttle,
|
|
66
70
|
applyPatch,
|
|
71
|
+
logger: this.logger,
|
|
67
72
|
};
|
|
68
73
|
return OpenAIResponsesNativeEngine.create(options);
|
|
69
74
|
}
|
|
@@ -85,6 +90,7 @@ export class Adaptor {
|
|
|
85
90
|
codeExecution,
|
|
86
91
|
urlContext,
|
|
87
92
|
googleSearch,
|
|
93
|
+
logger: this.logger,
|
|
88
94
|
};
|
|
89
95
|
return GoogleNativeEngine.create(options);
|
|
90
96
|
}
|
package/build/adaptor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../src/adaptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAyB,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,O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AAC;QACxC,MAAM,OAAO,GAAoC;YAC7C,GAAG,YAAY;YACf,sBAAsB;YACtB,UAAU;YACV,gBAAgB;YAChB,QAAQ;YACR,aAAa;YACb,UAAU;YACV,YAAY;YACZ,MAAM,EAAE,IAAI,CAAC,MAAM;SACtB,CAAC;QACF,OAAO,kBAAkB,CAAC,MAAM,CAAM,OAAO,CAAC,CAAC;IACnD,CAAC;CACJ"}
|
package/build/agentloop.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { type CompatibleEngine } from './compatible-engine.ts';
|
|
|
5
5
|
/**
|
|
6
6
|
* @param session mutable
|
|
7
7
|
*/
|
|
8
|
-
export declare function agentloop<fdm extends Function.Declaration.Map>(
|
|
8
|
+
export declare function agentloop<fdm extends Function.Declaration.Map>(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>, engine: CompatibleEngine<fdm>, fnm: Function.Map<fdm>, limit?: number): AsyncGenerator<string, string, void>;
|
|
9
9
|
export declare namespace agentloop {
|
|
10
10
|
class FunctionCallLimitExceeded extends Error {
|
|
11
11
|
}
|
package/build/agentloop.js
CHANGED
|
@@ -5,9 +5,9 @@ import {} from "./compatible-engine.js";
|
|
|
5
5
|
/**
|
|
6
6
|
* @param session mutable
|
|
7
7
|
*/
|
|
8
|
-
export async function* agentloop(
|
|
8
|
+
export async function* agentloop(wfctx, session, engine, fnm, limit = Number.POSITIVE_INFINITY) {
|
|
9
9
|
for (let i = 0; i < limit; i++) {
|
|
10
|
-
const response = await engine.stateful(
|
|
10
|
+
const response = await engine.stateful(wfctx, session);
|
|
11
11
|
const fcs = response.getFunctionCalls();
|
|
12
12
|
if (!fcs.length)
|
|
13
13
|
return response.getOnlyText();
|
package/build/agentloop.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentloop.js","sourceRoot":"","sources":["../src/agentloop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,WAAW,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uC,CAAC;gBACnD,MAAM,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;gBACvB,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE;oBAClB,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAM;wBACjC,EAAE,EAAE,EAAE,CAAC,EAAE;wBACT,IAAI,EAAE,EAAE,CAAC,IAAI;wBACb,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC;qBACM,CAAC,CAAC;gBAChD,CAAC,CAAC,EAAE,CAAC,CAAC;YACV,CAAC;;gBAAM,MAAM,IAAI,KAAK,EAAE,CAAC;QAC7B,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,WAAW,CAAC,IAAI,CAAC,MAAM,CAAM,GAAG,CAAC,CAAC,CAAC;IACvE,CAAC;IACD,MAAM,IAAI,SAAS,CAAC,yBAAyB,CAAC,+BAA+B,CAAC,CAAC;AACnF,CAAC;AAED,WAAiB,SAAS;IACtB,MAAa,yBAA0B,SAAQ,KAAK;KAAG;IAA1C,mCAAyB,4BAAiB,CAAA;AAC3D,CAAC,EAFgB,SAAS,KAAT,SAAS,QAEzB"}
|
|
@@ -1,33 +1,29 @@
|
|
|
1
1
|
import { Function } from '../function.ts';
|
|
2
|
-
import { Engine } from '../engine.ts';
|
|
2
|
+
import { type Engine } from '../engine.ts';
|
|
3
3
|
import Anthropic from '@anthropic-ai/sdk';
|
|
4
4
|
export declare namespace AnthropicEngine {
|
|
5
|
-
interface
|
|
5
|
+
interface Options<in out fdm extends Function.Declaration.Map> extends Engine.Options<fdm> {
|
|
6
|
+
}
|
|
7
|
+
interface OwnProps {
|
|
8
|
+
parallelToolCall: boolean;
|
|
6
9
|
anthropic: Anthropic;
|
|
7
|
-
|
|
10
|
+
}
|
|
11
|
+
namespace OwnProps {
|
|
12
|
+
function init<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, options: Options<fdm>): OwnProps;
|
|
13
|
+
}
|
|
14
|
+
interface Underhood<in out fdm extends Function.Declaration.Map> extends Engine.Underhood<fdm>, OwnProps {
|
|
15
|
+
parallelToolCall: boolean;
|
|
8
16
|
convertFromFunctionCall(fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): Anthropic.ToolUseBlock;
|
|
9
17
|
convertToFunctionCall(apifc: Anthropic.ToolUseBlock): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
10
18
|
convertFromFunctionResponse(fr: Function.Response.Distributive<Function.Declaration.From<fdm>>): Anthropic.ToolResultBlockParam;
|
|
11
19
|
convertFromFunctionDeclarationEntry(fdentry: Function.Declaration.Entry.From<fdm>): Anthropic.Tool;
|
|
12
|
-
convertFromToolChoice(toolChoice: Function.ToolChoice<fdm>,
|
|
20
|
+
convertFromToolChoice(toolChoice: Function.ToolChoice<fdm>, parallelToolCall: boolean): Anthropic.ToolChoice;
|
|
13
21
|
calcCost(usage: Anthropic.Usage): number;
|
|
14
22
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
parallel: boolean;
|
|
22
|
-
constructor(instance: AnthropicEngine.Instance<fdm>, options: AnthropicEngine.Options<fdm>);
|
|
23
|
-
convertFromFunctionCall(fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): Anthropic.ToolUseBlock;
|
|
24
|
-
convertToFunctionCall(apifc: Anthropic.ToolUseBlock): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
25
|
-
convertFromFunctionResponse(fr: Function.Response.Distributive<Function.Declaration.From<fdm>>): Anthropic.ToolResultBlockParam;
|
|
26
|
-
convertFromFunctionDeclarationEntry(fdentry: Function.Declaration.Entry.From<fdm>): Anthropic.Tool;
|
|
27
|
-
convertFromToolChoice(toolChoice: Function.ToolChoice<fdm>, parallel: boolean): Anthropic.ToolChoice;
|
|
28
|
-
calcCost(usage: Anthropic.Usage): number;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
interface Options<fdm extends Function.Declaration.Map> extends Engine.Options<fdm> {
|
|
32
|
-
}
|
|
23
|
+
function convertFromFunctionCall<fdm extends Function.Declaration.Map>(fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): Anthropic.ToolUseBlock;
|
|
24
|
+
function convertToFunctionCall<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, apifc: Anthropic.ToolUseBlock): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
25
|
+
function convertFromFunctionResponse<fdm extends Function.Declaration.Map>(fr: Function.Response.Distributive<Function.Declaration.From<fdm>>): Anthropic.ToolResultBlockParam;
|
|
26
|
+
function convertFromFunctionDeclarationEntry<fdm extends Function.Declaration.Map>(fdentry: Function.Declaration.Entry.From<fdm>): Anthropic.Tool;
|
|
27
|
+
function convertFromToolChoice<fdm extends Function.Declaration.Map>(toolChoice: Function.ToolChoice<fdm>, parallelToolCall: boolean): Anthropic.ToolChoice;
|
|
28
|
+
function calcCost<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, usage: Anthropic.Usage): number;
|
|
33
29
|
}
|
|
@@ -1,91 +1,93 @@
|
|
|
1
1
|
import { Function } from "../function.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ResponseInvalid } from "../engine.js";
|
|
3
3
|
import Anthropic from '@anthropic-ai/sdk';
|
|
4
4
|
import Ajv from 'ajv';
|
|
5
5
|
import {} from '@sinclair/typebox';
|
|
6
6
|
const ajv = new Ajv();
|
|
7
7
|
export var AnthropicEngine;
|
|
8
8
|
(function (AnthropicEngine) {
|
|
9
|
-
let
|
|
10
|
-
(function (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
throw new ResponseInvalid('Invalid JSON of function call', { cause: apifc });
|
|
38
|
-
}
|
|
39
|
-
})();
|
|
40
|
-
if (ajv.validate(fditem.paraschema, args)) { }
|
|
41
|
-
else
|
|
42
|
-
throw new ResponseInvalid('Function call not conforming to schema', { cause: apifc });
|
|
43
|
-
return Function.Call.create({
|
|
44
|
-
id: apifc.id,
|
|
45
|
-
name: apifc.name,
|
|
46
|
-
args,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
convertFromFunctionResponse(fr) {
|
|
50
|
-
if (fr.id) { }
|
|
51
|
-
else
|
|
52
|
-
throw new Error();
|
|
53
|
-
return {
|
|
54
|
-
type: 'tool_result',
|
|
55
|
-
tool_use_id: fr.id,
|
|
56
|
-
content: fr.text,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
convertFromFunctionDeclarationEntry(fdentry) {
|
|
60
|
-
return {
|
|
61
|
-
name: fdentry[0],
|
|
62
|
-
description: fdentry[1].description,
|
|
63
|
-
input_schema: fdentry[1].paraschema,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
convertFromToolChoice(toolChoice, parallel) {
|
|
67
|
-
if (toolChoice === Function.ToolChoice.NONE)
|
|
68
|
-
return { type: 'none' };
|
|
69
|
-
else if (toolChoice === Function.ToolChoice.REQUIRED)
|
|
70
|
-
return { type: 'any', disable_parallel_tool_use: !parallel };
|
|
71
|
-
else if (toolChoice === Function.ToolChoice.AUTO)
|
|
72
|
-
return { type: 'auto', disable_parallel_tool_use: !parallel };
|
|
73
|
-
else {
|
|
74
|
-
if (toolChoice.length === 1) { }
|
|
75
|
-
else
|
|
76
|
-
throw new Error();
|
|
77
|
-
return { type: 'tool', name: toolChoice[0], disable_parallel_tool_use: !parallel };
|
|
78
|
-
}
|
|
9
|
+
let OwnProps;
|
|
10
|
+
(function (OwnProps) {
|
|
11
|
+
function init(options) {
|
|
12
|
+
return {
|
|
13
|
+
parallelToolCall: options.parallelToolCall ?? false,
|
|
14
|
+
anthropic: new Anthropic({
|
|
15
|
+
baseURL: this.baseUrl,
|
|
16
|
+
apiKey: this.apiKey,
|
|
17
|
+
fetchOptions: { dispatcher: this.proxyAgent },
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
OwnProps.init = init;
|
|
22
|
+
})(OwnProps = AnthropicEngine.OwnProps || (AnthropicEngine.OwnProps = {}));
|
|
23
|
+
function convertFromFunctionCall(fc) {
|
|
24
|
+
throw new Error('Anthropic compatible engine requires native function calls.');
|
|
25
|
+
}
|
|
26
|
+
AnthropicEngine.convertFromFunctionCall = convertFromFunctionCall;
|
|
27
|
+
function convertToFunctionCall(apifc) {
|
|
28
|
+
const fditem = this.fdm[apifc.name];
|
|
29
|
+
if (fditem) { }
|
|
30
|
+
else
|
|
31
|
+
throw new ResponseInvalid('Unknown function call', { cause: apifc });
|
|
32
|
+
const args = (() => {
|
|
33
|
+
try {
|
|
34
|
+
return JSON.parse(apifc.input);
|
|
79
35
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const cacheMissTokenCount = usage.input_tokens - cacheHitTokenCount;
|
|
83
|
-
return this.instance.inputPrice * cacheMissTokenCount / 1e6 +
|
|
84
|
-
this.instance.cachedPrice * cacheHitTokenCount / 1e6 +
|
|
85
|
-
this.instance.outputPrice * usage.output_tokens / 1e6;
|
|
36
|
+
catch (e) {
|
|
37
|
+
throw new ResponseInvalid('Invalid JSON of function call', { cause: apifc });
|
|
86
38
|
}
|
|
39
|
+
})();
|
|
40
|
+
if (ajv.validate(fditem.paraschema, args)) { }
|
|
41
|
+
else
|
|
42
|
+
throw new ResponseInvalid('Function call not conforming to schema', { cause: apifc });
|
|
43
|
+
return Function.Call.create({
|
|
44
|
+
id: apifc.id,
|
|
45
|
+
name: apifc.name,
|
|
46
|
+
args,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
AnthropicEngine.convertToFunctionCall = convertToFunctionCall;
|
|
50
|
+
function convertFromFunctionResponse(fr) {
|
|
51
|
+
if (fr.id) { }
|
|
52
|
+
else
|
|
53
|
+
throw new Error();
|
|
54
|
+
return {
|
|
55
|
+
type: 'tool_result',
|
|
56
|
+
tool_use_id: fr.id,
|
|
57
|
+
content: fr.text,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
AnthropicEngine.convertFromFunctionResponse = convertFromFunctionResponse;
|
|
61
|
+
function convertFromFunctionDeclarationEntry(fdentry) {
|
|
62
|
+
return {
|
|
63
|
+
name: fdentry[0],
|
|
64
|
+
description: fdentry[1].description,
|
|
65
|
+
input_schema: fdentry[1].paraschema,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
AnthropicEngine.convertFromFunctionDeclarationEntry = convertFromFunctionDeclarationEntry;
|
|
69
|
+
function convertFromToolChoice(toolChoice, parallelToolCall) {
|
|
70
|
+
if (toolChoice === Function.ToolChoice.NONE)
|
|
71
|
+
return { type: 'none' };
|
|
72
|
+
else if (toolChoice === Function.ToolChoice.REQUIRED)
|
|
73
|
+
return { type: 'any', disable_parallel_tool_use: !parallelToolCall };
|
|
74
|
+
else if (toolChoice === Function.ToolChoice.AUTO)
|
|
75
|
+
return { type: 'auto', disable_parallel_tool_use: !parallelToolCall };
|
|
76
|
+
else {
|
|
77
|
+
if (toolChoice.length === 1) { }
|
|
78
|
+
else
|
|
79
|
+
throw new Error();
|
|
80
|
+
return { type: 'tool', name: toolChoice[0], disable_parallel_tool_use: !parallelToolCall };
|
|
87
81
|
}
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
}
|
|
83
|
+
AnthropicEngine.convertFromToolChoice = convertFromToolChoice;
|
|
84
|
+
function calcCost(usage) {
|
|
85
|
+
const cacheHitTokenCount = usage.cache_read_input_tokens || 0;
|
|
86
|
+
const cacheMissTokenCount = usage.input_tokens - cacheHitTokenCount;
|
|
87
|
+
return this.inputPrice * cacheMissTokenCount / 1e6 +
|
|
88
|
+
this.cachePrice * cacheHitTokenCount / 1e6 +
|
|
89
|
+
this.outputPrice * usage.output_tokens / 1e6;
|
|
90
|
+
}
|
|
91
|
+
AnthropicEngine.calcCost = calcCost;
|
|
90
92
|
})(AnthropicEngine || (AnthropicEngine = {}));
|
|
91
93
|
//# sourceMappingURL=anthropic.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/api-types/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/api-types/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAe,eAAe,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAgB,MAAM,mBAAmB,CAAC;AAEjD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;AAItB,MAAM,KAAW,eAAe,CA8G/B;AA9GD,WAAiB,eAAe;IAO5B,IAAiB,QAAQ,CAcxB;IAdD,WAAiB,QAAQ;QACrB,SAAgB,IAAI,CAEhB,OAAqB;YAErB,OAAO;gBACH,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,IAAI,KAAK;gBACnD,SAAS,EAAE,IAAI,SAAS,CAAC;oBACrB,OAAO,EAAE,IAAI,CAAC,OAAO;oBACrB,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,YAAY,EAAE,EAAE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ED,SAAgB,QAAQ,CAEpB,KAAsB;QAEtB,MAAM,kBAAkB,GAAG,KAAK,CAAC,uBAAuB,IAAI,CAAC,CAAC;QAC9D,MAAM,mBAAmB,GAAG,KAAK,CAAC,YAAY,GAAG,kBAAkB,CAAC;QACpE,OAAO,IAAI,CAAC,UAAU,GAAG,mBAAmB,GAAG,GAAG;YAC1C,IAAI,CAAC,UAAU,GAAG,kBAAkB,GAAG,GAAG;YAC1C,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,aAAa,GAAG,GAAG,CAAC;IACzD,CAAC;IATe,wBAAQ,WASvB,CAAA;AAEL,CAAC,EA9GgB,eAAe,KAAf,eAAe,QA8G/B"}
|
|
@@ -1,28 +1,23 @@
|
|
|
1
|
-
import { Engine } from '../engine.ts';
|
|
1
|
+
import { type Engine } from '../engine.ts';
|
|
2
2
|
import { Function } from '../function.ts';
|
|
3
3
|
import * as Google from '@google/genai';
|
|
4
|
-
import { CompatibleEngine } from '../compatible-engine.ts';
|
|
5
4
|
export declare namespace GoogleEngine {
|
|
6
|
-
interface
|
|
7
|
-
|
|
5
|
+
interface Options<in out fdm extends Function.Declaration.Map> extends Engine.Options<fdm> {
|
|
6
|
+
}
|
|
7
|
+
interface OwnProps {
|
|
8
|
+
parallelToolCall: boolean;
|
|
9
|
+
}
|
|
10
|
+
namespace OwnProps {
|
|
11
|
+
function init<fdm extends Function.Declaration.Map>(options: Options<fdm>): OwnProps;
|
|
12
|
+
}
|
|
13
|
+
interface Underhood<in out fdm extends Function.Declaration.Map> extends Engine.Underhood<fdm>, OwnProps {
|
|
8
14
|
convertFromFunctionCall(fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): Google.FunctionCall;
|
|
9
15
|
convertToFunctionCall(googlefc: Google.FunctionCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
10
16
|
convertFromFunctionDeclarationEntry(fdentry: Function.Declaration.Entry.From<fdm>): Google.FunctionDeclaration;
|
|
11
17
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class Instance<in out fdm extends Function.Declaration.Map> implements GoogleEngine.Base<fdm> {
|
|
16
|
-
protected instance: GoogleEngine.Instance<fdm>;
|
|
17
|
-
parallel: boolean;
|
|
18
|
-
constructor(instance: GoogleEngine.Instance<fdm>, options: CompatibleEngine.Options<fdm>);
|
|
19
|
-
convertFromFunctionCall(fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): Google.FunctionCall;
|
|
20
|
-
convertToFunctionCall(googlefc: Google.FunctionCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
21
|
-
convertFromFunctionDeclarationEntry(fdentry: Function.Declaration.Entry.From<fdm>): Google.FunctionDeclaration;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function convertFromFunctionDeclarationEntry<fdm extends Function.Declaration.Map>(fdentry: Function.Declaration.Entry.From<fdm>): Google.FunctionDeclaration;
|
|
25
|
-
function convertToFunctionCall<fdm extends Function.Declaration.Map>(googlefc: Google.FunctionCall, fdm: fdm): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
18
|
+
function convertFromFunctionCall<fdm extends Function.Declaration.Map>(this: GoogleEngine.Underhood<fdm>, fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): Google.FunctionCall;
|
|
19
|
+
function convertFromFunctionDeclarationEntry<fdm extends Function.Declaration.Map>(this: GoogleEngine.Underhood<fdm>, fdentry: Function.Declaration.Entry.From<fdm>): Google.FunctionDeclaration;
|
|
20
|
+
function convertToFunctionCall<fdm extends Function.Declaration.Map>(this: GoogleEngine.Underhood<fdm>, googlefc: Google.FunctionCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
26
21
|
interface RestfulRequest {
|
|
27
22
|
contents: Google.Content[];
|
|
28
23
|
tools?: Google.Tool[];
|
|
@@ -1,39 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ResponseInvalid } from "../engine.js";
|
|
2
2
|
import { Function } from "../function.js";
|
|
3
3
|
import * as Google from '@google/genai';
|
|
4
|
-
import { CompatibleEngine } from "../compatible-engine.js";
|
|
5
4
|
import Ajv from 'ajv';
|
|
6
5
|
const ajv = new Ajv();
|
|
7
6
|
export var GoogleEngine;
|
|
8
7
|
(function (GoogleEngine) {
|
|
9
|
-
let
|
|
10
|
-
(function (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
throw new Error('Google API requires parallel tool calls.');
|
|
20
|
-
}
|
|
21
|
-
convertFromFunctionCall(fc) {
|
|
22
|
-
return {
|
|
23
|
-
id: fc.id,
|
|
24
|
-
name: fc.name,
|
|
25
|
-
args: fc.args,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
convertToFunctionCall(googlefc) {
|
|
29
|
-
return GoogleEngine.convertToFunctionCall(googlefc, this.instance.fdm);
|
|
30
|
-
}
|
|
31
|
-
convertFromFunctionDeclarationEntry(fdentry) {
|
|
32
|
-
return GoogleEngine.convertFromFunctionDeclarationEntry(fdentry);
|
|
33
|
-
}
|
|
8
|
+
let OwnProps;
|
|
9
|
+
(function (OwnProps) {
|
|
10
|
+
function init(options) {
|
|
11
|
+
const parallelToolCall = options.parallelToolCall ?? true;
|
|
12
|
+
if (parallelToolCall) { }
|
|
13
|
+
else
|
|
14
|
+
throw new Error('Google API requires parallel tool calls.');
|
|
15
|
+
return {
|
|
16
|
+
parallelToolCall,
|
|
17
|
+
};
|
|
34
18
|
}
|
|
35
|
-
|
|
36
|
-
})(
|
|
19
|
+
OwnProps.init = init;
|
|
20
|
+
})(OwnProps = GoogleEngine.OwnProps || (GoogleEngine.OwnProps = {}));
|
|
21
|
+
function convertFromFunctionCall(fc) {
|
|
22
|
+
return {
|
|
23
|
+
id: fc.id,
|
|
24
|
+
name: fc.name,
|
|
25
|
+
args: fc.args,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
GoogleEngine.convertFromFunctionCall = convertFromFunctionCall;
|
|
37
29
|
function convertFromFunctionDeclarationEntry(fdentry) {
|
|
38
30
|
const json = JSON.stringify(fdentry[1].paraschema);
|
|
39
31
|
const parsed = JSON.parse(json, (key, value) => {
|
|
@@ -63,11 +55,11 @@ export var GoogleEngine;
|
|
|
63
55
|
};
|
|
64
56
|
}
|
|
65
57
|
GoogleEngine.convertFromFunctionDeclarationEntry = convertFromFunctionDeclarationEntry;
|
|
66
|
-
function convertToFunctionCall(googlefc
|
|
58
|
+
function convertToFunctionCall(googlefc) {
|
|
67
59
|
if (googlefc.name) { }
|
|
68
60
|
else
|
|
69
61
|
throw new Error();
|
|
70
|
-
const fditem = fdm[googlefc.name];
|
|
62
|
+
const fditem = this.fdm[googlefc.name];
|
|
71
63
|
if (fditem) { }
|
|
72
64
|
else
|
|
73
65
|
throw new ResponseInvalid('Unknown function call', { cause: googlefc });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google.js","sourceRoot":"","sources":["../../src/api-types/google.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"google.js","sourceRoot":"","sources":["../../src/api-types/google.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,eAAe,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;AAItB,MAAM,KAAW,YAAY,CAoF5B;AApFD,WAAiB,YAAY;IAMzB,IAAiB,QAAQ,CAQxB;IARD,WAAiB,QAAQ;QACrB,SAAgB,IAAI,CAAuC,OAAqB;YAC5E,MAAM,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,IAAI,IAAI,CAAC;YAC1D,IAAI,gBAAgB,EAAE,CAAC,CAAA,CAAC;;gBAAM,MAAM,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,KAAK,CAAC;QACtB,CAAC,CAAkB,CAAC;QACpB,OAAO;YACH,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;YAChB,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW;YACnC,UAAU,EAAE,MAAM;SACrB,CAAC;IACN,CAAC;IAtBe,gDAAmC,sCAsBlD,CAAA;IAED,SAAgB,qBAAqB,CAEjC,QAA6B;QAE7B,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA,CAAC;;YAAM,MAAM,IAAI,KAAK,EAAE,CAAC;QAC7C,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAoD,CAAC;QAC1F,IAAI,MAAM,EAAE,CAAC,CAAA,CAAC;;YAAM,MAAM,IAAI,eAAe,CAAC,uBAAuB,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC5F,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA,CAAC;;YACjD,MAAM,IAAI,eAAe,CAAC,wCAAwC,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC9F,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;YACxB,EAAE,EAAE,QAAQ,CAAC,EAAE;YACf,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,IAAI,EAAE,QAAQ,CAAC,IAAI;SAC0C,CAAC,CAAC;IACvE,CAAC;IAde,kCAAqB,wBAcpC,CAAA;AAUL,CAAC,EApFgB,YAAY,KAAZ,YAAY,QAoF5B"}
|
|
@@ -2,8 +2,15 @@ import { type Engine } from '../engine.ts';
|
|
|
2
2
|
import { Function } from '../function.ts';
|
|
3
3
|
import OpenAI from 'openai';
|
|
4
4
|
export declare namespace OpenAIChatCompletionsEngine {
|
|
5
|
-
interface
|
|
6
|
-
|
|
5
|
+
interface Options<in out fdm extends Function.Declaration.Map> extends Engine.Options<fdm> {
|
|
6
|
+
}
|
|
7
|
+
interface OwnProps {
|
|
8
|
+
parallelToolCall: boolean;
|
|
9
|
+
}
|
|
10
|
+
namespace OwnProps {
|
|
11
|
+
function init<fdm extends Function.Declaration.Map>(options: Options<fdm>): OwnProps;
|
|
12
|
+
}
|
|
13
|
+
interface Underhood<in out fdm extends Function.Declaration.Map> extends Engine.Underhood<fdm>, OwnProps {
|
|
7
14
|
convertFromFunctionCall(fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): OpenAI.ChatCompletionMessageToolCall;
|
|
8
15
|
convertToFunctionCall(apifc: OpenAI.ChatCompletionMessageFunctionToolCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
9
16
|
convertFromFunctionResponse(fr: Function.Response.Distributive<Function.Declaration.From<fdm>>): OpenAI.ChatCompletionToolMessageParam;
|
|
@@ -13,21 +20,12 @@ export declare namespace OpenAIChatCompletionsEngine {
|
|
|
13
20
|
extractContent(completionContent: string): string;
|
|
14
21
|
handleFinishReason(completion: OpenAI.ChatCompletion, finishReason: OpenAI.ChatCompletion.Choice['finish_reason']): void;
|
|
15
22
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
convertToFunctionCall(apifc: OpenAI.ChatCompletionMessageFunctionToolCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
25
|
-
convertFromFunctionResponse(fr: Function.Response.Distributive<Function.Declaration.From<fdm>>): OpenAI.ChatCompletionToolMessageParam;
|
|
26
|
-
convertFromFunctionDeclarationEntry(fdentry: Function.Declaration.Entry.From<fdm>): OpenAI.ChatCompletionTool;
|
|
27
|
-
convertFromToolChoice(toolChoice: Function.ToolChoice<fdm>): OpenAI.ChatCompletionToolChoiceOption;
|
|
28
|
-
calcCost(usage: OpenAI.CompletionUsage): number;
|
|
29
|
-
extractContent(completionContent: string): string;
|
|
30
|
-
handleFinishReason(completion: OpenAI.ChatCompletion, finishReason: OpenAI.ChatCompletion.Choice['finish_reason']): void;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
23
|
+
function convertFromFunctionCall<fdm extends Function.Declaration.Map>(fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): OpenAI.ChatCompletionMessageToolCall;
|
|
24
|
+
function convertToFunctionCall<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, apifc: OpenAI.ChatCompletionMessageFunctionToolCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
25
|
+
function convertFromFunctionResponse<fdm extends Function.Declaration.Map>(fr: Function.Response.Distributive<Function.Declaration.From<fdm>>): OpenAI.ChatCompletionToolMessageParam;
|
|
26
|
+
function convertFromFunctionDeclarationEntry<fdm extends Function.Declaration.Map>(fdentry: Function.Declaration.Entry.From<fdm>): OpenAI.ChatCompletionTool;
|
|
27
|
+
function convertFromToolChoice<fdm extends Function.Declaration.Map>(toolChoice: Function.ToolChoice<fdm>): OpenAI.ChatCompletionToolChoiceOption;
|
|
28
|
+
function calcCost<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, usage: OpenAI.CompletionUsage): number;
|
|
29
|
+
function extractContent(completionContent: string): string;
|
|
30
|
+
function handleFinishReason(completion: OpenAI.ChatCompletion, finishReason: OpenAI.ChatCompletion.Choice['finish_reason']): void;
|
|
33
31
|
}
|