@zimtsui/brainswitch 0.0.55 → 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/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 +3 -3
- 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
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Function } from '#@/function.ts';
|
|
2
|
+
import OpenAI from 'openai';
|
|
3
|
+
import { ResponseInvalid } from '#@/engine.ts';
|
|
4
|
+
import Ajv from 'ajv';
|
|
5
|
+
const ajv = new Ajv();
|
|
6
|
+
export class OpenAIChatCompletionsToolCodec {
|
|
7
|
+
ctx;
|
|
8
|
+
constructor(ctx) {
|
|
9
|
+
this.ctx = ctx;
|
|
10
|
+
}
|
|
11
|
+
convertFromFunctionCall(fc) {
|
|
12
|
+
if (fc.id) { }
|
|
13
|
+
else
|
|
14
|
+
throw new Error();
|
|
15
|
+
return {
|
|
16
|
+
id: fc.id,
|
|
17
|
+
type: 'function',
|
|
18
|
+
function: {
|
|
19
|
+
name: fc.name,
|
|
20
|
+
arguments: JSON.stringify(fc.args),
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
convertToFunctionCall(apifc) {
|
|
25
|
+
const fditem = this.ctx.fdm[apifc.function.name];
|
|
26
|
+
if (fditem) { }
|
|
27
|
+
else
|
|
28
|
+
throw new ResponseInvalid('Unknown function call', { cause: apifc });
|
|
29
|
+
const args = (() => {
|
|
30
|
+
try {
|
|
31
|
+
return JSON.parse(apifc.function.arguments);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
return new ResponseInvalid('Invalid JSON of function call', { cause: apifc });
|
|
35
|
+
}
|
|
36
|
+
})();
|
|
37
|
+
if (ajv.validate(fditem.paraschema, args)) { }
|
|
38
|
+
else
|
|
39
|
+
throw new ResponseInvalid('Invalid function arguments', { cause: apifc });
|
|
40
|
+
return Function.Call.create({
|
|
41
|
+
id: apifc.id,
|
|
42
|
+
name: apifc.function.name,
|
|
43
|
+
args,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
convertFromFunctionResponse(fr) {
|
|
47
|
+
if (fr.id) { }
|
|
48
|
+
else
|
|
49
|
+
throw new Error();
|
|
50
|
+
return {
|
|
51
|
+
role: 'tool',
|
|
52
|
+
tool_call_id: fr.id,
|
|
53
|
+
content: fr.text,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
convertFromFunctionDeclarationEntry(fdentry) {
|
|
57
|
+
return {
|
|
58
|
+
type: 'function',
|
|
59
|
+
function: {
|
|
60
|
+
name: fdentry[0],
|
|
61
|
+
description: fdentry[1].description,
|
|
62
|
+
strict: true,
|
|
63
|
+
parameters: fdentry[1].paraschema,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
convertFromFunctionDeclarationMap(fdm) {
|
|
68
|
+
const fdentries = Object.entries(fdm);
|
|
69
|
+
return fdentries.map(fdentry => this.convertFromFunctionDeclarationEntry(fdentry));
|
|
70
|
+
}
|
|
71
|
+
convertFromToolChoice(toolChoice) {
|
|
72
|
+
if (toolChoice === Function.ToolChoice.NONE)
|
|
73
|
+
return 'none';
|
|
74
|
+
else if (toolChoice === Function.ToolChoice.REQUIRED)
|
|
75
|
+
return 'required';
|
|
76
|
+
else if (toolChoice === Function.ToolChoice.AUTO)
|
|
77
|
+
return 'auto';
|
|
78
|
+
else {
|
|
79
|
+
if (toolChoice.length === 1) { }
|
|
80
|
+
else
|
|
81
|
+
throw new Error();
|
|
82
|
+
return { type: 'function', function: { name: toolChoice[0] } };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=tool-codec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-codec.js","sourceRoot":"","sources":["../../../src/api-types/openai-chatcompletion/tool-codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;AAGtB,MAAM,OAAO,8BAA8B;IACV;IAA7B,YAA6B,GAAgD;QAAhD,QAAG,GAAH,GAAG,CAA6C;IAAG,CAAC;IAG1E,uBAAuB,CAC1B,EAA2B;QAE3B,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA,CAAC;;YAAM,MAAM,IAAI,KAAK,EAAE,CAAC;QACrC,OAAO;YACH,EAAE,EAAE,EAAE,CAAC,EAAE;YACT,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE;gBACN,IAAI,EAAE,EAAE,CAAC,IAAI;gBACb,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC;aACrC;SACJ,CAAC;IACN,CAAC;IAEM,qBAAqB,CACxB,KAAmD;QAEnD,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAwC,CAAC;QAC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BACnC,MAAM,EAAE,IAAI;gBACZ,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU;aACpC;SACJ,CAAC;IACN,CAAC;IAEM,iCAAiC,CAAC,GAAQ;QAC7C,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAA2C,CAAC;QAChF,OAAO,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,mCAAmC,CAAC,OAAO,CAAC,CAAC,CAAC;IACvF,CAAC;IAEM,qBAAqB,CACxB,UAAoC;QAEpC,IAAI,UAAU,KAAK,QAAQ,CAAC,UAAU,CAAC,IAAI;YAAE,OAAO,MAAM,CAAC;aACtD,IAAI,UAAU,KAAK,QAAQ,CAAC,UAAU,CAAC,QAAQ;YAAE,OAAO,UAAU,CAAC;aACnE,IAAI,UAAU,KAAK,QAAQ,CAAC,UAAU,CAAC,IAAI;YAAE,OAAO,MAAM,CAAC;aAC3D,CAAC;YACF,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC,CAAA,CAAC;;gBAAM,MAAM,IAAI,KAAK,EAAE,CAAC;YACvD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAE,EAAE,EAAE,CAAC;QACpE,CAAC;IACL,CAAC;CAEJ"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
import type { Pricing } from '#@/engine.ts';
|
|
3
|
+
export declare class OpenAIResponsesBilling {
|
|
4
|
+
protected ctx: OpenAIResponsesBilling.Context;
|
|
5
|
+
constructor(ctx: OpenAIResponsesBilling.Context);
|
|
6
|
+
charge(usage: OpenAI.Responses.ResponseUsage): number;
|
|
7
|
+
}
|
|
8
|
+
export declare namespace OpenAIResponsesBilling {
|
|
9
|
+
interface Context {
|
|
10
|
+
pricing: Pricing;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
export class OpenAIResponsesBilling {
|
|
3
|
+
ctx;
|
|
4
|
+
constructor(ctx) {
|
|
5
|
+
this.ctx = ctx;
|
|
6
|
+
}
|
|
7
|
+
charge(usage) {
|
|
8
|
+
const cacheHitTokenCount = usage.input_tokens_details.cached_tokens;
|
|
9
|
+
const cacheMissTokenCount = usage.input_tokens - cacheHitTokenCount;
|
|
10
|
+
return (this.ctx.pricing.inputPrice * cacheMissTokenCount / 1e6 +
|
|
11
|
+
this.ctx.pricing.cachePrice * cacheHitTokenCount / 1e6 +
|
|
12
|
+
this.ctx.pricing.outputPrice * usage.output_tokens / 1e6);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=billing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../../../src/api-types/openai-responses/billing.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAI5B,MAAM,OAAO,sBAAsB;IACF;IAA7B,YAA6B,GAAmC;QAAnC,QAAG,GAAH,GAAG,CAAgC;IAAG,CAAC;IAG7D,MAAM,CAAC,KAAqC;QAC/C,MAAM,kBAAkB,GAAG,KAAK,CAAC,oBAAoB,CAAC,aAAa,CAAC;QACpE,MAAM,mBAAmB,GAAG,KAAK,CAAC,YAAY,GAAG,kBAAkB,CAAC;QACpE,OAAO,CACH,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,GAAG,mBAAmB,GAAG,GAAG;YACvD,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,GAAG,kBAAkB,GAAG,GAAG;YACtD,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC,aAAa,GAAG,GAAG,CAC3D,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
import { Function } from '#@/function.ts';
|
|
3
|
+
export declare class OpenAIResponsesToolCodec<in out fdm extends Function.Declaration.Map> {
|
|
4
|
+
protected ctx: OpenAIResponsesToolCodec.Context<fdm>;
|
|
5
|
+
constructor(ctx: OpenAIResponsesToolCodec.Context<fdm>);
|
|
6
|
+
convertFromFunctionResponse(fr: Function.Response.Distributive<fdm>): OpenAI.Responses.ResponseInputItem.FunctionCallOutput;
|
|
7
|
+
protected convertFromFunctionDeclarationEntry(fdentry: Function.Declaration.Entry.From<fdm>): OpenAI.Responses.FunctionTool;
|
|
8
|
+
convertFromFunctionDeclarationMap(fdm: fdm): OpenAI.Responses.FunctionTool[];
|
|
9
|
+
convertFromToolChoice(toolChoice: Function.ToolChoice<fdm>): OpenAI.Responses.ToolChoiceOptions | OpenAI.Responses.ToolChoiceAllowed;
|
|
10
|
+
convertToFunctionCall(apifc: OpenAI.Responses.ResponseFunctionToolCall): Function.Call.From<fdm>;
|
|
11
|
+
}
|
|
12
|
+
export declare namespace OpenAIResponsesToolCodec {
|
|
13
|
+
interface Context<in out fdm extends Function.Declaration.Map> {
|
|
14
|
+
fdm: fdm;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
import { Function } from '#@/function.ts';
|
|
3
|
+
import { ResponseInvalid } from '#@/engine.ts';
|
|
4
|
+
import Ajv from 'ajv';
|
|
5
|
+
const ajv = new Ajv();
|
|
6
|
+
export class OpenAIResponsesToolCodec {
|
|
7
|
+
ctx;
|
|
8
|
+
constructor(ctx) {
|
|
9
|
+
this.ctx = ctx;
|
|
10
|
+
}
|
|
11
|
+
convertFromFunctionResponse(fr) {
|
|
12
|
+
if (fr.id) { }
|
|
13
|
+
else
|
|
14
|
+
throw new Error();
|
|
15
|
+
return {
|
|
16
|
+
type: 'function_call_output',
|
|
17
|
+
call_id: fr.id,
|
|
18
|
+
output: fr.text,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
convertFromFunctionDeclarationEntry(fdentry) {
|
|
22
|
+
return {
|
|
23
|
+
name: fdentry[0],
|
|
24
|
+
description: fdentry[1].description,
|
|
25
|
+
parameters: fdentry[1].paraschema,
|
|
26
|
+
strict: true,
|
|
27
|
+
type: 'function',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
convertFromFunctionDeclarationMap(fdm) {
|
|
31
|
+
const fdentries = Object.entries(fdm);
|
|
32
|
+
return fdentries.map(fdentry => this.convertFromFunctionDeclarationEntry(fdentry));
|
|
33
|
+
}
|
|
34
|
+
convertFromToolChoice(toolChoice) {
|
|
35
|
+
if (toolChoice === Function.ToolChoice.NONE)
|
|
36
|
+
return 'none';
|
|
37
|
+
else if (toolChoice === Function.ToolChoice.REQUIRED)
|
|
38
|
+
return 'required';
|
|
39
|
+
else if (toolChoice === Function.ToolChoice.AUTO)
|
|
40
|
+
return 'auto';
|
|
41
|
+
else {
|
|
42
|
+
return {
|
|
43
|
+
type: 'allowed_tools',
|
|
44
|
+
mode: 'required',
|
|
45
|
+
tools: toolChoice.map(name => ({ type: 'function', name })),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
convertToFunctionCall(apifc) {
|
|
50
|
+
const fditem = this.ctx.fdm[apifc.name];
|
|
51
|
+
if (fditem) { }
|
|
52
|
+
else
|
|
53
|
+
throw new ResponseInvalid('Unknown function call', { cause: apifc });
|
|
54
|
+
const args = (() => {
|
|
55
|
+
try {
|
|
56
|
+
return JSON.parse(apifc.arguments);
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
throw new ResponseInvalid('Invalid JSON of function call', { cause: apifc });
|
|
60
|
+
}
|
|
61
|
+
})();
|
|
62
|
+
if (ajv.validate(fditem.paraschema, args)) { }
|
|
63
|
+
else
|
|
64
|
+
throw new ResponseInvalid('Function call not conforming to schema', { cause: apifc });
|
|
65
|
+
return Function.Call.create({
|
|
66
|
+
id: apifc.call_id,
|
|
67
|
+
name: apifc.name,
|
|
68
|
+
args,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=tool-codec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-codec.js","sourceRoot":"","sources":["../../../src/api-types/openai-responses/tool-codec.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;AAItB,MAAM,OAAO,wBAAwB;IACJ;IAA7B,YAA6B,GAA0C;QAA1C,QAAG,GAAH,GAAG,CAAuC;IAAG,CAAC;IAEpE,2BAA2B,CAC9B,EAAuC;QAEvC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA,CAAC;;YAAM,MAAM,IAAI,KAAK,EAAE,CAAC;QACrC,OAAO;YACH,IAAI,EAAE,sBAAsB;YAC5B,OAAO,EAAE,EAAE,CAAC,EAAE;YACd,MAAM,EAAE,EAAE,CAAC,IAAI;SAClB,CAAC;IACN,CAAC;IAES,mCAAmC,CACzC,OAA6C;QAE7C,OAAO;YACH,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;YAChB,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW;YACnC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU;YACjC,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,UAAU;SACnB,CAAC;IACN,CAAC;IAEM,iCAAiC,CAAC,GAAQ;QAC7C,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAA2C,CAAC;QAChF,OAAO,SAAS,CAAC,GAAG,CAA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AAC;;YACxC,MAAM,IAAI,eAAe,CAAC,wCAAwC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3F,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;YACxB,EAAE,EAAE,KAAK,CAAC,OAAO;YACjB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,IAAI;SAC8B,CAAC,CAAC;IAC5C,CAAC;CACJ"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Function } from '#@/function.ts';
|
|
2
|
+
import { CompatibleEngine } from '#@/compatible/engine.ts';
|
|
3
|
+
import { type InferenceContext } from '#@/inference-context.ts';
|
|
4
|
+
import { type Session, RoleMessage } from '#@/compatible/session.ts';
|
|
5
|
+
import { OpenAIChatCompletionsToolCodec } from '#@/api-types/openai-chatcompletion/tool-codec.ts';
|
|
6
|
+
import { OpenAIChatCompletionsCompatibleMessageCodec } from '#@/compatible.d/openai-chatcompletions/message-codec.ts';
|
|
7
|
+
import { OpenAIChatCompletionsBilling } from '#@/api-types/openai-chatcompletion/billing.ts';
|
|
8
|
+
import { ToolCallValidator } from '#@/compatible/tool-call-validator.ts';
|
|
9
|
+
import { AliyunTransport } from '#@/compatible.d/aliyun/transport.ts';
|
|
10
|
+
export declare class AliyunEngine<in out fdm extends Function.Declaration.Map> extends CompatibleEngine<fdm> {
|
|
11
|
+
protected toolCodec: OpenAIChatCompletionsToolCodec<fdm>;
|
|
12
|
+
protected messageCodec: OpenAIChatCompletionsCompatibleMessageCodec<fdm>;
|
|
13
|
+
protected billing: OpenAIChatCompletionsBilling<fdm>;
|
|
14
|
+
protected toolCallValidator: ToolCallValidator<fdm>;
|
|
15
|
+
protected transport: AliyunTransport<fdm>;
|
|
16
|
+
protected parallelToolCall: boolean;
|
|
17
|
+
constructor(options: AliyunEngine.Options<fdm>);
|
|
18
|
+
infer(wfctx: InferenceContext, session: Session<fdm>, signal?: AbortSignal): Promise<RoleMessage.Ai<fdm>>;
|
|
19
|
+
}
|
|
20
|
+
export declare namespace AliyunEngine {
|
|
21
|
+
interface Options<in out fdm extends Function.Declaration.Map> extends CompatibleEngine.Options<fdm> {
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Function } from '#@/function.ts';
|
|
2
|
+
import { CompatibleEngine } from '#@/compatible/engine.ts';
|
|
3
|
+
import {} from '#@/inference-context.ts';
|
|
4
|
+
import { RoleMessage } from '#@/compatible/session.ts';
|
|
5
|
+
import { OpenAIChatCompletionsToolCodec } from '#@/api-types/openai-chatcompletion/tool-codec.ts';
|
|
6
|
+
import { OpenAIChatCompletionsCompatibleMessageCodec } from '#@/compatible.d/openai-chatcompletions/message-codec.ts';
|
|
7
|
+
import { OpenAIChatCompletionsBilling } from '#@/api-types/openai-chatcompletion/billing.ts';
|
|
8
|
+
import { ToolCallValidator } from '#@/compatible/tool-call-validator.ts';
|
|
9
|
+
import { AliyunTransport } from '#@/compatible.d/aliyun/transport.ts';
|
|
10
|
+
export class AliyunEngine extends CompatibleEngine {
|
|
11
|
+
toolCodec;
|
|
12
|
+
messageCodec;
|
|
13
|
+
billing;
|
|
14
|
+
toolCallValidator;
|
|
15
|
+
transport;
|
|
16
|
+
parallelToolCall;
|
|
17
|
+
constructor(options) {
|
|
18
|
+
super(options);
|
|
19
|
+
this.parallelToolCall = options.parallelToolCall ?? false;
|
|
20
|
+
this.toolCodec = new OpenAIChatCompletionsToolCodec({
|
|
21
|
+
fdm: this.fdm,
|
|
22
|
+
parallelToolCall: this.parallelToolCall,
|
|
23
|
+
});
|
|
24
|
+
this.messageCodec = new OpenAIChatCompletionsCompatibleMessageCodec({ toolCodec: this.toolCodec });
|
|
25
|
+
this.billing = new OpenAIChatCompletionsBilling({ pricing: this.pricing });
|
|
26
|
+
this.toolCallValidator = new ToolCallValidator({ toolChoice: this.toolChoice });
|
|
27
|
+
this.transport = new AliyunTransport({
|
|
28
|
+
inferenceParams: this.inferenceParams,
|
|
29
|
+
providerSpec: this.providerSpec,
|
|
30
|
+
fdm: this.fdm,
|
|
31
|
+
throttle: this.throttle,
|
|
32
|
+
toolChoice: this.toolChoice,
|
|
33
|
+
messageCodec: this.messageCodec,
|
|
34
|
+
toolCodec: this.toolCodec,
|
|
35
|
+
billing: this.billing,
|
|
36
|
+
toolCallValidator: this.toolCallValidator,
|
|
37
|
+
parallelToolCall: this.parallelToolCall,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
infer(wfctx, session, signal) {
|
|
41
|
+
return this.transport.fetch(wfctx, session, signal);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=aliyun.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aliyun.js","sourceRoot":"","sources":["../../../src/compatible/engine.d/aliyun.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAyB,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAgB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,8BAA8B,EAAE,MAAM,kDAAkD,CAAC;AAClG,OAAO,EAAE,2CAA2C,EAAE,MAAM,yDAAyD,CAAC;AACtH,OAAO,EAAE,4BAA4B,EAAE,MAAM,+CAA+C,CAAC;AAC7F,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAItE,MAAM,OAAO,YAA0D,SAAQ,gBAAqB;IACtF,SAAS,CAAsC;IAC/C,YAAY,CAAmD;IAC/D,OAAO,CAAoC;IAC3C,iBAAiB,CAAyB;IAC1C,SAAS,CAAuB;IACvB,gBAAgB,CAAU;IAE7C,YAAmB,OAAkC;QACjD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,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from '#@/compatible/session.ts';
|
|
3
|
+
import { Function } from '#@/function.ts';
|
|
4
|
+
import { type InferenceContext } from '#@/inference-context.ts';
|
|
5
|
+
import { AnthropicToolCodec } from '#@/api-types/anthropic/tool-codec.ts';
|
|
6
|
+
import { AnthropicBilling } from '#@/api-types/anthropic/billing.ts';
|
|
7
|
+
import { ToolCallValidator } from '#@/compatible/tool-call-validator.ts';
|
|
8
|
+
import { AnthropicCompatibleMessageCodec } from '#@/compatible.d/anthropic/message-codec.ts';
|
|
9
|
+
import { AnthropicCompatibleTransport } from '#@/compatible.d/anthropic/transport.ts';
|
|
10
|
+
export declare class AnthropicCompatibleEngine<in out fdm extends Function.Declaration.Map> extends CompatibleEngine<fdm> {
|
|
11
|
+
protected toolCodec: AnthropicToolCodec<fdm>;
|
|
12
|
+
protected messageCodec: AnthropicCompatibleMessageCodec<fdm>;
|
|
13
|
+
protected billing: AnthropicBilling;
|
|
14
|
+
protected toolCallValidator: ToolCallValidator<fdm>;
|
|
15
|
+
protected transport: AnthropicCompatibleTransport<fdm>;
|
|
16
|
+
protected parallelToolCall: boolean;
|
|
17
|
+
constructor(options: AnthropicCompatibleEngine.Options<fdm>);
|
|
18
|
+
infer(wfctx: InferenceContext, session: Session<fdm>, signal?: AbortSignal): Promise<RoleMessage.Ai<fdm>>;
|
|
19
|
+
}
|
|
20
|
+
export declare namespace AnthropicCompatibleEngine {
|
|
21
|
+
interface Options<in out fdm extends Function.Declaration.Map> extends CompatibleEngine.Options<fdm> {
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { CompatibleEngine } from '#@/compatible/engine.ts';
|
|
2
|
+
import { RoleMessage } from '#@/compatible/session.ts';
|
|
3
|
+
import { Function } from '#@/function.ts';
|
|
4
|
+
import {} from '#@/inference-context.ts';
|
|
5
|
+
import { AnthropicToolCodec } from '#@/api-types/anthropic/tool-codec.ts';
|
|
6
|
+
import { AnthropicBilling } from '#@/api-types/anthropic/billing.ts';
|
|
7
|
+
import { ToolCallValidator } from '#@/compatible/tool-call-validator.ts';
|
|
8
|
+
import { AnthropicCompatibleMessageCodec } from '#@/compatible.d/anthropic/message-codec.ts';
|
|
9
|
+
import { AnthropicCompatibleTransport } from '#@/compatible.d/anthropic/transport.ts';
|
|
10
|
+
export class AnthropicCompatibleEngine extends CompatibleEngine {
|
|
11
|
+
toolCodec;
|
|
12
|
+
messageCodec;
|
|
13
|
+
billing;
|
|
14
|
+
toolCallValidator;
|
|
15
|
+
transport;
|
|
16
|
+
parallelToolCall;
|
|
17
|
+
constructor(options) {
|
|
18
|
+
super(options);
|
|
19
|
+
this.parallelToolCall = options.parallelToolCall ?? false;
|
|
20
|
+
this.toolCodec = new AnthropicToolCodec({ fdm: this.fdm });
|
|
21
|
+
this.messageCodec = new AnthropicCompatibleMessageCodec({ toolCodec: this.toolCodec });
|
|
22
|
+
this.billing = new AnthropicBilling({ pricing: this.pricing });
|
|
23
|
+
this.toolCallValidator = new ToolCallValidator({ toolChoice: this.toolChoice });
|
|
24
|
+
this.transport = new AnthropicCompatibleTransport({
|
|
25
|
+
providerSpec: this.providerSpec,
|
|
26
|
+
inferenceSpec: this.inferenceParams,
|
|
27
|
+
fdm: this.fdm,
|
|
28
|
+
throttle: this.throttle,
|
|
29
|
+
toolChoice: this.toolChoice,
|
|
30
|
+
parallelToolCall: this.parallelToolCall,
|
|
31
|
+
messageCodec: this.messageCodec,
|
|
32
|
+
toolCodec: this.toolCodec,
|
|
33
|
+
billing: this.billing,
|
|
34
|
+
toolCallValidator: this.toolCallValidator,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
infer(wfctx, session, signal) {
|
|
38
|
+
return this.transport.fetch(wfctx, session, signal);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/compatible/engine.d/anthropic.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IAAI,4BAA4B,CAAC;YAC9C,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,aAAa,EAAE,IAAI,CAAC,eAAe;YACnC,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;SAC5C,CAAC,CAAC;IACP,CAAC;IAEe,KAAK,CACjB,KAAuB,EACvB,OAAqB,EACrB,MAAoB;QAEpB,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;CACJ"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CompatibleEngine } from '#@/compatible/engine.ts';
|
|
2
|
+
import { RoleMessage, type Session } from '#@/compatible/session.ts';
|
|
3
|
+
import { Function } from '#@/function.ts';
|
|
4
|
+
import { type InferenceContext } from '#@/inference-context.ts';
|
|
5
|
+
import { GoogleCompatibleMessageCodec } from '#@/compatible.d/google/message-codec.ts';
|
|
6
|
+
import { GoogleToolCodec } from '#@/api-types/google/tool-codec.ts';
|
|
7
|
+
import { GoogleBilling } from '#@/api-types/google/billing.ts';
|
|
8
|
+
import { ToolCallValidator } from '#@/compatible/tool-call-validator.ts';
|
|
9
|
+
import { GoogleCompatibleTransport } from '#@/compatible.d/google/transport.ts';
|
|
10
|
+
export declare class GoogleCompatibleEngine<in out fdm extends Function.Declaration.Map> extends CompatibleEngine<fdm> {
|
|
11
|
+
protected toolCodec: GoogleToolCodec<fdm>;
|
|
12
|
+
protected messageCodec: GoogleCompatibleMessageCodec<fdm>;
|
|
13
|
+
protected billing: GoogleBilling;
|
|
14
|
+
protected toolCallValidator: ToolCallValidator<fdm>;
|
|
15
|
+
protected transport: GoogleCompatibleTransport<fdm>;
|
|
16
|
+
protected parallelToolCall: boolean;
|
|
17
|
+
constructor(options: GoogleCompatibleEngine.Options<fdm>);
|
|
18
|
+
infer(wfctx: InferenceContext, session: Session<fdm>, signal?: AbortSignal): Promise<RoleMessage.Ai<fdm>>;
|
|
19
|
+
}
|
|
20
|
+
export declare namespace GoogleCompatibleEngine {
|
|
21
|
+
interface Options<in out fdm extends Function.Declaration.Map> extends CompatibleEngine.Options<fdm> {
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CompatibleEngine } from '#@/compatible/engine.ts';
|
|
2
|
+
import { RoleMessage } from '#@/compatible/session.ts';
|
|
3
|
+
import { Function } from '#@/function.ts';
|
|
4
|
+
import {} from '#@/inference-context.ts';
|
|
5
|
+
import { GoogleCompatibleMessageCodec } from '#@/compatible.d/google/message-codec.ts';
|
|
6
|
+
import { GoogleToolCodec } from '#@/api-types/google/tool-codec.ts';
|
|
7
|
+
import { GoogleBilling } from '#@/api-types/google/billing.ts';
|
|
8
|
+
import { ToolCallValidator } from '#@/compatible/tool-call-validator.ts';
|
|
9
|
+
import { GoogleCompatibleTransport } from '#@/compatible.d/google/transport.ts';
|
|
10
|
+
export class GoogleCompatibleEngine extends CompatibleEngine {
|
|
11
|
+
toolCodec;
|
|
12
|
+
messageCodec;
|
|
13
|
+
billing;
|
|
14
|
+
toolCallValidator;
|
|
15
|
+
transport;
|
|
16
|
+
parallelToolCall;
|
|
17
|
+
constructor(options) {
|
|
18
|
+
super(options);
|
|
19
|
+
this.parallelToolCall = options.parallelToolCall ?? true;
|
|
20
|
+
if (this.parallelToolCall) { }
|
|
21
|
+
else
|
|
22
|
+
throw new Error('Parallel tool calling is required by Google engine.');
|
|
23
|
+
this.toolCodec = new GoogleToolCodec({
|
|
24
|
+
fdm: this.fdm,
|
|
25
|
+
});
|
|
26
|
+
this.messageCodec = new GoogleCompatibleMessageCodec({ toolCodec: this.toolCodec });
|
|
27
|
+
this.billing = new GoogleBilling({ pricing: this.pricing });
|
|
28
|
+
this.toolCallValidator = new ToolCallValidator({ toolChoice: this.toolChoice });
|
|
29
|
+
this.transport = new GoogleCompatibleTransport({
|
|
30
|
+
inferenceParams: this.inferenceParams,
|
|
31
|
+
providerSpec: this.providerSpec,
|
|
32
|
+
fdm: this.fdm,
|
|
33
|
+
throttle: this.throttle,
|
|
34
|
+
toolChoice: this.toolChoice,
|
|
35
|
+
messageCodec: this.messageCodec,
|
|
36
|
+
toolCodec: this.toolCodec,
|
|
37
|
+
billing: this.billing,
|
|
38
|
+
toolCallValidator: this.toolCallValidator,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
infer(wfctx, session, signal) {
|
|
42
|
+
return this.transport.fetch(wfctx, session, signal);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=google.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google.js","sourceRoot":"","sources":["../../../src/compatible/engine.d/google.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAgB,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAyB,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAIhF,MAAM,OAAO,sBAAoE,SAAQ,gBAAqB;IAChG,SAA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;QAEpB,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;CACJ"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CompatibleEngine } from '#@/compatible/engine.ts';
|
|
2
|
+
import { RoleMessage, type Session } from '#@/compatible/session.ts';
|
|
3
|
+
import { Function } from '#@/function.ts';
|
|
4
|
+
import { type InferenceContext } from '#@/inference-context.ts';
|
|
5
|
+
import { OpenAIResponsesToolCodec } from '#@/api-types/openai-responses/tool-codec.ts';
|
|
6
|
+
import { OpenAIResponsesBilling } from '#@/api-types/openai-responses/billing.ts';
|
|
7
|
+
import { ToolCallValidator } from '#@/compatible/tool-call-validator.ts';
|
|
8
|
+
import { OpenAIResponsesCompatibleMessageCodec } from '#@/compatible.d/openai-responses/message-codec.ts';
|
|
9
|
+
import { OpenAIResponsesCompatibleTransport } from '#@/compatible.d/openai-responses/transport.ts';
|
|
10
|
+
export declare class OpenAIResponsesCompatibleEngine<in out fdm extends Function.Declaration.Map> extends CompatibleEngine<fdm> {
|
|
11
|
+
protected toolCodec: OpenAIResponsesToolCodec<fdm>;
|
|
12
|
+
protected messageCodec: OpenAIResponsesCompatibleMessageCodec<fdm>;
|
|
13
|
+
protected billing: OpenAIResponsesBilling;
|
|
14
|
+
protected toolCallValidator: ToolCallValidator<fdm>;
|
|
15
|
+
protected transport: OpenAIResponsesCompatibleTransport<fdm>;
|
|
16
|
+
protected parallelToolCall: boolean;
|
|
17
|
+
constructor(options: OpenAIResponsesCompatibleEngine.Options<fdm>);
|
|
18
|
+
infer(wfctx: InferenceContext, session: Session<fdm>, signal?: AbortSignal): Promise<RoleMessage.Ai<fdm>>;
|
|
19
|
+
}
|
|
20
|
+
export declare namespace OpenAIResponsesCompatibleEngine {
|
|
21
|
+
interface Options<in out fdm extends Function.Declaration.Map> extends CompatibleEngine.Options<fdm> {
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { CompatibleEngine } from '#@/compatible/engine.ts';
|
|
2
|
+
import { RoleMessage } from '#@/compatible/session.ts';
|
|
3
|
+
import { Function } from '#@/function.ts';
|
|
4
|
+
import {} from '#@/inference-context.ts';
|
|
5
|
+
import { OpenAIResponsesToolCodec } from '#@/api-types/openai-responses/tool-codec.ts';
|
|
6
|
+
import { OpenAIResponsesBilling } from '#@/api-types/openai-responses/billing.ts';
|
|
7
|
+
import { ToolCallValidator } from '#@/compatible/tool-call-validator.ts';
|
|
8
|
+
import { OpenAIResponsesCompatibleMessageCodec } from '#@/compatible.d/openai-responses/message-codec.ts';
|
|
9
|
+
import { OpenAIResponsesCompatibleTransport } from '#@/compatible.d/openai-responses/transport.ts';
|
|
10
|
+
export class OpenAIResponsesCompatibleEngine extends CompatibleEngine {
|
|
11
|
+
toolCodec;
|
|
12
|
+
messageCodec;
|
|
13
|
+
billing;
|
|
14
|
+
toolCallValidator;
|
|
15
|
+
transport;
|
|
16
|
+
parallelToolCall;
|
|
17
|
+
constructor(options) {
|
|
18
|
+
super(options);
|
|
19
|
+
this.parallelToolCall = options.parallelToolCall ?? false;
|
|
20
|
+
this.toolCodec = new OpenAIResponsesToolCodec({ fdm: this.fdm });
|
|
21
|
+
this.messageCodec = new OpenAIResponsesCompatibleMessageCodec({ toolCodec: this.toolCodec });
|
|
22
|
+
this.billing = new OpenAIResponsesBilling({ pricing: this.pricing });
|
|
23
|
+
this.toolCallValidator = new ToolCallValidator({ toolChoice: this.toolChoice });
|
|
24
|
+
this.transport = new OpenAIResponsesCompatibleTransport({
|
|
25
|
+
inferenceSpec: this.inferenceParams,
|
|
26
|
+
providerSpec: this.providerSpec,
|
|
27
|
+
fdm: this.fdm,
|
|
28
|
+
throttle: this.throttle,
|
|
29
|
+
toolChoice: this.toolChoice,
|
|
30
|
+
parallelToolCall: this.parallelToolCall,
|
|
31
|
+
messageCodec: this.messageCodec,
|
|
32
|
+
toolCodec: this.toolCodec,
|
|
33
|
+
billing: this.billing,
|
|
34
|
+
toolCallValidator: this.toolCallValidator,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
infer(wfctx, session, signal) {
|
|
38
|
+
return this.transport.fetch(wfctx, session, signal);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=openai-responses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-responses.js","sourceRoot":"","sources":["../../../src/compatible/engine.d/openai-responses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAgB,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAyB,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAC;AACvF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,qCAAqC,EAAE,MAAM,mDAAmD,CAAC;AAC1G,OAAO,EAAE,kCAAkC,EAAE,MAAM,+CAA+C,CAAC;AAGnG,MAAM,OAAO,+BAA6E,SAAQ,gBAAqB;IACzG,SAAS,CAAgC;IACzC,YAAY,CAA6C;IACzD,OAAO,CAAyB;IAChC,iBAAiB,CAAyB;IAC1C,SAAS,CAA0C;IAC1C,gBAAgB,CAAU;IAE7C,YAAmB,OAAqD;QACpE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,IAAI,KAAK,CAAC;QAC1D,IAAI,CAAC,SAAS,GAAG,IAAI,wBAAwB,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QACjE,IAAI,CAAC,YAAY,GAAG,IAAI,qCAAqC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QAC7F,IAAI,CAAC,OAAO,GAAG,IAAI,sBAAsB,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QACrE,IAAI,CAAC,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QAChF,IAAI,CAAC,SAAS,GAAG,IAAI,kCAAkC,CAAC;YACpD,aAAa,EAAE,IAAI,CAAC,eAAe;YACnC,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;SAC5C,CAAC,CAAC;IACP,CAAC;IAEe,KAAK,CACjB,KAAuB,EACvB,OAAqB,EACrB,MAAoB;QAEpB,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;CACJ"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RoleMessage, type Session } from '#@/compatible/session.ts';
|
|
2
|
+
import { Function } from '#@/function.ts';
|
|
3
|
+
import { Engine } from '#@/engine.ts';
|
|
4
|
+
export declare abstract class CompatibleEngine<in out fdm extends Function.Declaration.Map> extends Engine<fdm, RoleMessage.User<fdm>, RoleMessage.Ai<fdm>, RoleMessage.Developer, Session<fdm>> {
|
|
5
|
+
protected toolChoice: Function.ToolChoice<fdm>;
|
|
6
|
+
constructor(options: CompatibleEngine.Options<fdm>);
|
|
7
|
+
appendUserMessage(session: Session<fdm>, message: RoleMessage.User<fdm>): Session<fdm>;
|
|
8
|
+
pushUserMessage(session: Session<fdm>, message: RoleMessage.User<fdm>): Session<fdm>;
|
|
9
|
+
}
|
|
10
|
+
export declare namespace CompatibleEngine {
|
|
11
|
+
interface Options<in out fdm extends Function.Declaration.Map> extends Engine.Options<fdm>, CompatibleEngine.Options.Tools<fdm> {
|
|
12
|
+
}
|
|
13
|
+
namespace Options {
|
|
14
|
+
interface Tools<in out fdm extends Function.Declaration.Map> extends Engine.Options.Tools<fdm> {
|
|
15
|
+
toolChoice?: Function.ToolChoice<fdm>;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { RoleMessage } from '#@/compatible/session.ts';
|
|
2
|
+
import { Function } from '#@/function.ts';
|
|
3
|
+
import { Engine } from '#@/engine.ts';
|
|
4
|
+
export class CompatibleEngine extends Engine {
|
|
5
|
+
toolChoice;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super(options);
|
|
8
|
+
this.toolChoice = options.toolChoice ?? Function.ToolChoice.AUTO;
|
|
9
|
+
}
|
|
10
|
+
appendUserMessage(session, message) {
|
|
11
|
+
return {
|
|
12
|
+
developerMessage: session.developerMessage,
|
|
13
|
+
chatMessages: [...session.chatMessages, message],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
pushUserMessage(session, message) {
|
|
17
|
+
session.chatMessages.push(message);
|
|
18
|
+
return session;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/compatible/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC,MAAM,OAAgB,gBAA8D,SAChF,MAMC;IAES,UAAU,CAA2B;IAE/C,YAAmB,OAAsC;QACrD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC;IACrE,CAAC;IAEe,iBAAiB,CAC7B,OAAqB,EACrB,OAA8B;QAE9B,OAAO;YACH,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;YAC1C,YAAY,EAAE,CAAC,GAAG,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC;SACnD,CAAC;IACN,CAAC;IAEe,eAAe,CAC3B,OAAqB,EACrB,OAA8B;QAE9B,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACnC,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ"}
|