@zimtsui/brainswitch 0.0.56 → 0.0.59
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/README.md +109 -54
- package/assets/verbatim/declarations.handlebars +11 -0
- package/assets/verbatim/instruction.md +49 -0
- package/build/adaptor.d.ts +40 -9
- package/build/adaptor.js +36 -38
- package/build/adaptor.js.map +1 -1
- package/build/api-types/anthropic/billing.d.ts +5 -5
- package/build/api-types/anthropic/billing.js +1 -2
- package/build/api-types/anthropic/billing.js.map +1 -1
- package/build/api-types/anthropic/tool-codec.d.ts +11 -12
- package/build/api-types/anthropic/tool-codec.js +27 -42
- package/build/api-types/anthropic/tool-codec.js.map +1 -1
- package/build/api-types/google/billing.d.ts +5 -5
- package/build/api-types/google/billing.js +2 -3
- package/build/api-types/google/billing.js.map +1 -1
- package/build/api-types/google/restful-request.d.ts +1 -1
- package/build/api-types/google/restful-request.js +0 -1
- package/build/api-types/google/restful-request.js.map +1 -1
- package/build/api-types/google/tool-codec.d.ts +11 -11
- package/build/api-types/google/tool-codec.js +21 -19
- package/build/api-types/google/tool-codec.js.map +1 -1
- package/build/api-types/{openai-chatcompletion → openai-chatcompletions}/billing.d.ts +2 -3
- package/build/api-types/{openai-chatcompletion → openai-chatcompletions}/billing.js +0 -2
- package/build/api-types/openai-chatcompletions/billing.js.map +1 -0
- package/build/api-types/openai-chatcompletions/tool-codec.d.ts +17 -0
- package/build/api-types/{openai-chatcompletion → openai-chatcompletions}/tool-codec.js +26 -32
- package/build/api-types/openai-chatcompletions/tool-codec.js.map +1 -0
- package/build/api-types/openai-responses/billing.d.ts +5 -5
- package/build/api-types/openai-responses/billing.js +1 -2
- package/build/api-types/openai-responses/billing.js.map +1 -1
- package/build/api-types/openai-responses/tool-codec.d.ts +11 -11
- package/build/api-types/openai-responses/tool-codec.js +36 -32
- package/build/api-types/openai-responses/tool-codec.js.map +1 -1
- package/build/assets.d.ts +7 -0
- package/build/assets.js +8 -0
- package/build/assets.js.map +1 -0
- package/build/compatible-engine/session.d.ts +67 -0
- package/build/compatible-engine/session.js +92 -0
- package/build/compatible-engine/session.js.map +1 -0
- package/build/compatible-engine/structuring.d.ts +36 -0
- package/build/compatible-engine/structuring.js +34 -0
- package/build/compatible-engine/structuring.js.map +1 -0
- package/build/compatible-engine/validation.d.ts +21 -0
- package/build/compatible-engine/validation.js +82 -0
- package/build/compatible-engine/validation.js.map +1 -0
- package/build/compatible-engine.d/agentloop.d.ts +12 -0
- package/build/compatible-engine.d/agentloop.js +52 -0
- package/build/compatible-engine.d/agentloop.js.map +1 -0
- package/build/compatible-engine.d/aliyun/transport.d.ts +12 -0
- package/build/compatible-engine.d/aliyun/transport.js +7 -0
- package/build/compatible-engine.d/aliyun/transport.js.map +1 -0
- package/build/compatible-engine.d/aliyun.d.ts +24 -0
- package/build/compatible-engine.d/aliyun.js +46 -0
- package/build/compatible-engine.d/aliyun.js.map +1 -0
- package/build/compatible-engine.d/anthropic/choice-codec.d.ts +5 -0
- package/build/compatible-engine.d/anthropic/choice-codec.js +26 -0
- package/build/compatible-engine.d/anthropic/choice-codec.js.map +1 -0
- package/build/compatible-engine.d/anthropic/message-codec.d.ts +36 -0
- package/build/compatible-engine.d/anthropic/message-codec.js +86 -0
- package/build/compatible-engine.d/anthropic/message-codec.js.map +1 -0
- package/build/compatible-engine.d/anthropic/transport.d.ts +34 -0
- package/build/compatible-engine.d/anthropic/transport.js +150 -0
- package/build/compatible-engine.d/anthropic/transport.js.map +1 -0
- package/build/compatible-engine.d/anthropic.d.ts +26 -0
- package/build/compatible-engine.d/anthropic.js +46 -0
- package/build/compatible-engine.d/anthropic.js.map +1 -0
- package/build/compatible-engine.d/google/choice-codec.d.ts +5 -0
- package/build/compatible-engine.d/google/choice-codec.js +27 -0
- package/build/compatible-engine.d/google/choice-codec.js.map +1 -0
- package/build/compatible-engine.d/google/message-codec.d.ts +36 -0
- package/build/compatible-engine.d/google/message-codec.js +94 -0
- package/build/compatible-engine.d/google/message-codec.js.map +1 -0
- package/build/compatible-engine.d/google/transport.d.ts +30 -0
- package/build/{compatible.d → compatible-engine.d}/google/transport.js +22 -18
- package/build/compatible-engine.d/google/transport.js.map +1 -0
- package/build/compatible-engine.d/google.d.ts +26 -0
- package/build/compatible-engine.d/google.js +50 -0
- package/build/compatible-engine.d/google.js.map +1 -0
- package/build/compatible-engine.d/openai-chatcompletions/choice-codec.d.ts +5 -0
- package/build/compatible-engine.d/openai-chatcompletions/choice-codec.js +31 -0
- package/build/compatible-engine.d/openai-chatcompletions/choice-codec.js.map +1 -0
- package/build/compatible-engine.d/openai-chatcompletions/message-codec.d.ts +24 -0
- package/build/compatible-engine.d/openai-chatcompletions/message-codec.js +71 -0
- package/build/compatible-engine.d/openai-chatcompletions/message-codec.js.map +1 -0
- package/build/compatible-engine.d/openai-chatcompletions/transport.d/monolith.d.ts +38 -0
- package/build/{compatible.d/openai-chatcompletions.d → compatible-engine.d/openai-chatcompletions/transport.d}/monolith.js +25 -22
- package/build/compatible-engine.d/openai-chatcompletions/transport.d/monolith.js.map +1 -0
- package/build/compatible-engine.d/openai-chatcompletions/transport.d/stream.d.ts +37 -0
- package/build/compatible-engine.d/openai-chatcompletions/transport.d/stream.js +190 -0
- package/build/compatible-engine.d/openai-chatcompletions/transport.d/stream.js.map +1 -0
- package/build/compatible-engine.d/openai-chatcompletions/transport.d.ts +10 -0
- package/build/compatible-engine.d/openai-chatcompletions/transport.js +11 -0
- package/build/compatible-engine.d/openai-chatcompletions/transport.js.map +1 -0
- package/build/compatible-engine.d/openai-chatcompletions.d.ts +17 -0
- package/build/compatible-engine.d/openai-chatcompletions.js +14 -0
- package/build/compatible-engine.d/openai-chatcompletions.js.map +1 -0
- package/build/compatible-engine.d/openai-responses/choice-codec.d.ts +5 -0
- package/build/compatible-engine.d/openai-responses/choice-codec.js +30 -0
- package/build/compatible-engine.d/openai-responses/choice-codec.js.map +1 -0
- package/build/compatible-engine.d/openai-responses/message-codec.d.ts +36 -0
- package/build/compatible-engine.d/openai-responses/message-codec.js +96 -0
- package/build/compatible-engine.d/openai-responses/message-codec.js.map +1 -0
- package/build/compatible-engine.d/openai-responses/transport.d.ts +35 -0
- package/build/{compatible.d → compatible-engine.d}/openai-responses/transport.js +21 -29
- package/build/compatible-engine.d/openai-responses/transport.js.map +1 -0
- package/build/compatible-engine.d/openai-responses.d.ts +26 -0
- package/build/compatible-engine.d/openai-responses.js +46 -0
- package/build/compatible-engine.d/openai-responses.js.map +1 -0
- package/build/compatible-engine.d.ts +22 -0
- package/build/compatible-engine.js +29 -0
- package/build/compatible-engine.js.map +1 -0
- package/build/config.d.ts +1 -0
- package/build/config.js +1 -2
- package/build/config.js.map +1 -1
- package/build/endpoint-spec.d.ts +1 -0
- package/build/endpoint-spec.js +2 -1
- package/build/endpoint-spec.js.map +1 -1
- package/build/engine/session.d.ts +7 -0
- package/build/{session.js.map → engine/session.js.map} +1 -1
- package/build/engine/transport.d.ts +5 -0
- package/build/engine/transport.js +1 -0
- package/build/engine/transport.js.map +1 -0
- package/build/engine/validation.d.ts +9 -0
- package/build/engine/validation.js +1 -0
- package/build/engine/validation.js.map +1 -0
- package/build/engine.d.ts +49 -40
- package/build/engine.js +88 -70
- package/build/engine.js.map +1 -1
- package/build/exports.d.ts +14 -14
- package/build/exports.js +14 -14
- package/build/exports.js.map +1 -1
- package/build/function.d.ts +79 -66
- package/build/function.js +30 -47
- package/build/function.js.map +1 -1
- package/build/inference-context.d.ts +2 -2
- package/build/inference-context.js +0 -1
- package/build/inference-context.js.map +1 -1
- package/build/native-engines.d/google/message-codec.d.ts +18 -16
- package/build/native-engines.d/google/message-codec.js +31 -33
- package/build/native-engines.d/google/message-codec.js.map +1 -1
- package/build/native-engines.d/google/session.d.ts +44 -51
- package/build/native-engines.d/google/session.js +85 -81
- package/build/native-engines.d/google/session.js.map +1 -1
- package/build/native-engines.d/google/transport.d.ts +22 -19
- package/build/native-engines.d/google/transport.js +13 -13
- package/build/native-engines.d/google/transport.js.map +1 -1
- package/build/native-engines.d/google/validation.d.ts +22 -0
- package/build/native-engines.d/google/validation.js +20 -0
- package/build/native-engines.d/google/validation.js.map +1 -0
- package/build/native-engines.d/google.d/agentloop.d.ts +12 -0
- package/build/native-engines.d/google.d/agentloop.js +57 -0
- package/build/native-engines.d/google.d/agentloop.js.map +1 -0
- package/build/native-engines.d/google.d/exports.d.ts +3 -0
- package/build/native-engines.d/google.d/exports.js +4 -0
- package/build/native-engines.d/google.d/exports.js.map +1 -0
- package/build/native-engines.d/google.d.ts +42 -0
- package/build/native-engines.d/google.js +83 -0
- package/build/native-engines.d/google.js.map +1 -0
- package/build/native-engines.d/openai-responses/choice-codec.d.ts +5 -0
- package/build/native-engines.d/openai-responses/choice-codec.js +30 -0
- package/build/native-engines.d/openai-responses/choice-codec.js.map +1 -0
- package/build/native-engines.d/openai-responses/message-codec.d.ts +19 -17
- package/build/native-engines.d/openai-responses/message-codec.js +31 -25
- package/build/native-engines.d/openai-responses/message-codec.js.map +1 -1
- package/build/native-engines.d/openai-responses/session.d.ts +47 -45
- package/build/native-engines.d/openai-responses/session.js +75 -105
- package/build/native-engines.d/openai-responses/session.js.map +1 -1
- package/build/native-engines.d/openai-responses/structuring.d.ts +19 -0
- package/build/native-engines.d/openai-responses/structuring.js +19 -0
- package/build/native-engines.d/openai-responses/structuring.js.map +1 -0
- package/build/native-engines.d/openai-responses/tool.d.ts +15 -12
- package/build/native-engines.d/openai-responses/tool.js +1 -12
- package/build/native-engines.d/openai-responses/tool.js.map +1 -1
- package/build/native-engines.d/openai-responses/transport.d.ts +24 -25
- package/build/native-engines.d/openai-responses/transport.js +21 -41
- package/build/native-engines.d/openai-responses/transport.js.map +1 -1
- package/build/native-engines.d/openai-responses/validation.d.ts +20 -0
- package/build/native-engines.d/openai-responses/validation.js +80 -0
- package/build/native-engines.d/openai-responses/validation.js.map +1 -0
- package/build/native-engines.d/openai-responses.d/agentloop.d.ts +12 -0
- package/build/native-engines.d/openai-responses.d/agentloop.js +61 -0
- package/build/native-engines.d/openai-responses.d/agentloop.js.map +1 -0
- package/build/native-engines.d/openai-responses.d/exports.d.ts +4 -0
- package/build/native-engines.d/openai-responses.d/exports.js +5 -0
- package/build/native-engines.d/openai-responses.d/exports.js.map +1 -0
- package/build/native-engines.d/openai-responses.d.ts +44 -0
- package/build/native-engines.d/openai-responses.js +78 -0
- package/build/native-engines.d/openai-responses.js.map +1 -0
- package/build/throttle.d.ts +6 -5
- package/build/throttle.js +17 -14
- package/build/throttle.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/verbatim/codec/declarations.d.ts +2 -0
- package/build/verbatim/codec/declarations.js +22 -0
- package/build/verbatim/codec/declarations.js.map +1 -0
- package/build/verbatim/codec/request.d.ts +7 -0
- package/build/verbatim/codec/request.js +53 -0
- package/build/verbatim/codec/request.js.map +1 -0
- package/build/verbatim/codec.d.ts +2 -0
- package/build/verbatim/codec.js +3 -0
- package/build/verbatim/codec.js.map +1 -0
- package/build/verbatim.d.ts +74 -0
- package/build/verbatim.js +17 -0
- package/build/verbatim.js.map +1 -0
- package/examples/agent.ts +65 -0
- package/examples/chat.ts +24 -0
- package/examples/config.ts +24 -0
- package/{test/src → examples}/tsconfig.json +6 -2
- package/examples/verbatim.ts +44 -0
- package/package.json +15 -13
- package/build/agentloop.d.ts +0 -12
- package/build/agentloop.js +0 -43
- package/build/agentloop.js.map +0 -1
- package/build/api-types/openai-chatcompletion/billing.js.map +0 -1
- package/build/api-types/openai-chatcompletion/tool-codec.d.ts +0 -18
- package/build/api-types/openai-chatcompletion/tool-codec.js.map +0 -1
- package/build/compatible/engine.d/aliyun.d.ts +0 -23
- package/build/compatible/engine.d/aliyun.js +0 -44
- package/build/compatible/engine.d/aliyun.js.map +0 -1
- package/build/compatible/engine.d/anthropic.d.ts +0 -23
- package/build/compatible/engine.d/anthropic.js +0 -41
- package/build/compatible/engine.d/anthropic.js.map +0 -1
- package/build/compatible/engine.d/google.d.ts +0 -23
- package/build/compatible/engine.d/google.js +0 -45
- package/build/compatible/engine.d/google.js.map +0 -1
- package/build/compatible/engine.d/openai-responses.d.ts +0 -23
- package/build/compatible/engine.d/openai-responses.js +0 -41
- package/build/compatible/engine.d/openai-responses.js.map +0 -1
- package/build/compatible/engine.d.ts +0 -18
- package/build/compatible/engine.js +0 -21
- package/build/compatible/engine.js.map +0 -1
- package/build/compatible/session.d.ts +0 -78
- package/build/compatible/session.js +0 -138
- package/build/compatible/session.js.map +0 -1
- package/build/compatible/tool-call-validator.d.ts +0 -11
- package/build/compatible/tool-call-validator.js +0 -12
- package/build/compatible/tool-call-validator.js.map +0 -1
- package/build/compatible.d/aliyun/transport.d.ts +0 -11
- package/build/compatible.d/aliyun/transport.js +0 -9
- package/build/compatible.d/aliyun/transport.js.map +0 -1
- package/build/compatible.d/anthropic/message-codec.d.ts +0 -31
- package/build/compatible.d/anthropic/message-codec.js +0 -88
- package/build/compatible.d/anthropic/message-codec.js.map +0 -1
- package/build/compatible.d/anthropic/transport.d.ts +0 -31
- package/build/compatible.d/anthropic/transport.js +0 -137
- package/build/compatible.d/anthropic/transport.js.map +0 -1
- package/build/compatible.d/google/message-codec.d.ts +0 -31
- package/build/compatible.d/google/message-codec.js +0 -98
- package/build/compatible.d/google/message-codec.js.map +0 -1
- package/build/compatible.d/google/transport.d.ts +0 -28
- package/build/compatible.d/google/transport.js.map +0 -1
- package/build/compatible.d/openai-chatcompletions/message-codec.d.ts +0 -19
- package/build/compatible.d/openai-chatcompletions/message-codec.js +0 -66
- package/build/compatible.d/openai-chatcompletions/message-codec.js.map +0 -1
- package/build/compatible.d/openai-chatcompletions/transport.d.ts +0 -9
- package/build/compatible.d/openai-chatcompletions/transport.js +0 -25
- package/build/compatible.d/openai-chatcompletions/transport.js.map +0 -1
- package/build/compatible.d/openai-chatcompletions.d/monolith.d.ts +0 -36
- package/build/compatible.d/openai-chatcompletions.d/monolith.js.map +0 -1
- package/build/compatible.d/openai-chatcompletions.d/stream.d.ts +0 -35
- package/build/compatible.d/openai-chatcompletions.d/stream.js +0 -196
- package/build/compatible.d/openai-chatcompletions.d/stream.js.map +0 -1
- package/build/compatible.d/openai-responses/message-codec.d.ts +0 -32
- package/build/compatible.d/openai-responses/message-codec.js +0 -105
- package/build/compatible.d/openai-responses/message-codec.js.map +0 -1
- package/build/compatible.d/openai-responses/transport.d.ts +0 -33
- package/build/compatible.d/openai-responses/transport.js.map +0 -1
- package/build/frontmatter.d.ts +0 -5
- package/build/frontmatter.js +0 -13
- package/build/frontmatter.js.map +0 -1
- package/build/native-engines.d/google/agentloop.d.ts +0 -12
- package/build/native-engines.d/google/agentloop.js +0 -42
- package/build/native-engines.d/google/agentloop.js.map +0 -1
- package/build/native-engines.d/google/engine.d.ts +0 -35
- package/build/native-engines.d/google/engine.js +0 -73
- package/build/native-engines.d/google/engine.js.map +0 -1
- package/build/native-engines.d/google/exports.d.ts +0 -5
- package/build/native-engines.d/google/exports.js +0 -6
- package/build/native-engines.d/google/exports.js.map +0 -1
- package/build/native-engines.d/openai-responses/agentloop.d.ts +0 -13
- package/build/native-engines.d/openai-responses/agentloop.js +0 -53
- package/build/native-engines.d/openai-responses/agentloop.js.map +0 -1
- package/build/native-engines.d/openai-responses/engine.d.ts +0 -32
- package/build/native-engines.d/openai-responses/engine.js +0 -63
- package/build/native-engines.d/openai-responses/engine.js.map +0 -1
- package/build/native-engines.d/openai-responses/exports.d.ts +0 -6
- package/build/native-engines.d/openai-responses/exports.js +0 -7
- package/build/native-engines.d/openai-responses/exports.js.map +0 -1
- package/build/native-engines.d/openai-responses/tool-call-validator.d.ts +0 -12
- package/build/native-engines.d/openai-responses/tool-call-validator.js +0 -33
- package/build/native-engines.d/openai-responses/tool-call-validator.js.map +0 -1
- package/build/session.d.ts +0 -7
- package/test/build/test-codecs.d.ts +0 -1
- package/test/build/test-codecs.js +0 -230
- package/test/build/test-codecs.js.map +0 -1
- package/test/build/test-compatible-engine.d.ts +0 -1
- package/test/build/test-compatible-engine.js +0 -27
- package/test/build/test-compatible-engine.js.map +0 -1
- package/test/build/test-compatible-engines.d.ts +0 -1
- package/test/build/test-compatible-engines.js +0 -112
- package/test/build/test-compatible-engines.js.map +0 -1
- package/test/build/test-engine.d.ts +0 -1
- package/test/build/test-engine.js +0 -97
- package/test/build/test-engine.js.map +0 -1
- package/test/build/test-helpers.d.ts +0 -46
- package/test/build/test-helpers.js +0 -45
- package/test/build/test-helpers.js.map +0 -1
- package/test/build/test-native-engines.d.ts +0 -1
- package/test/build/test-native-engines.js +0 -64
- package/test/build/test-native-engines.js.map +0 -1
- package/test/build/test.d.ts +0 -5
- package/test/build/test.js +0 -6
- package/test/build/test.js.map +0 -1
- package/test/build/tsconfig.tsbuildinfo +0 -1
- package/test/src/test-codecs.ts +0 -256
- package/test/src/test-compatible-engine.ts +0 -45
- package/test/src/test-compatible-engines.ts +0 -129
- package/test/src/test-engine.ts +0 -144
- package/test/src/test-helpers.ts +0 -53
- package/test/src/test-native-engines.ts +0 -75
- package/test/src/test.ts +0 -5
- /package/build/{session.js → engine/session.js} +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Handlebars from 'handlebars';
|
|
2
|
+
import Assets from "../../assets.js";
|
|
3
|
+
const template = Handlebars.compile(Assets.verbatim.declarations);
|
|
4
|
+
export function encode(vdm) {
|
|
5
|
+
const vds = Object.entries(vdm).map(([name, body]) => ({
|
|
6
|
+
name,
|
|
7
|
+
description: body.description,
|
|
8
|
+
parameters: body.parameters,
|
|
9
|
+
}));
|
|
10
|
+
return template({
|
|
11
|
+
declarations: vds.map(declaration => ({
|
|
12
|
+
name: declaration.name,
|
|
13
|
+
description: declaration.description,
|
|
14
|
+
parameters: Object.entries(declaration.parameters).map(([name, parameter]) => ({
|
|
15
|
+
name,
|
|
16
|
+
description: parameter.description,
|
|
17
|
+
mimeType: parameter.mimeType,
|
|
18
|
+
})),
|
|
19
|
+
})),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=declarations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declarations.js","sourceRoot":"","sources":["../../../src/verbatim/codec/declarations.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAGrC,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAiB,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;AAqBlF,MAAM,UAAU,MAAM,CAClB,GAAQ;IAER,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAC/B,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;QACf,IAAI;QACJ,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;KAC9B,CAA4B,CAChC,CAAC;IAEF,OAAO,QAAQ,CAAC;QACZ,YAAY,EAAE,GAAG,CAAC,GAAG,CACjB,WAAW,CAAC,EAAE,CAAC,CAAC;YACZ,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,WAAW,EAAE,WAAW,CAAC,WAAW;YACpC,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,GAAG,CAClD,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;gBACpB,IAAI;gBACJ,WAAW,EAAE,SAAS,CAAC,WAAW;gBAClC,QAAQ,EAAE,SAAS,CAAC,QAAQ;aAC/B,CAAC,CACL;SACJ,CAAC,CACL;KACJ,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Verbatim } from "../../verbatim.js";
|
|
2
|
+
/**
|
|
3
|
+
* @throws {@link RequestInvalid}
|
|
4
|
+
*/
|
|
5
|
+
export function decode(str, vdm) {
|
|
6
|
+
const parts = [];
|
|
7
|
+
const requests = extractRequests(str);
|
|
8
|
+
for (const [channelName, args] of requests) {
|
|
9
|
+
const vdbody = vdm[channelName];
|
|
10
|
+
if (vdbody) { }
|
|
11
|
+
else
|
|
12
|
+
throw new Invalid('Channel not found: ' + channelName);
|
|
13
|
+
const paramNames = Object.keys(vdbody.parameters);
|
|
14
|
+
const argNames = Object.keys(args);
|
|
15
|
+
for (const paramName of paramNames)
|
|
16
|
+
if (argNames.includes(paramName)) { }
|
|
17
|
+
else
|
|
18
|
+
throw new Invalid(`Argument ${paramName} of channel ${channelName} is missing.`);
|
|
19
|
+
for (const argName of argNames)
|
|
20
|
+
if (paramNames.includes(argName)) { }
|
|
21
|
+
else
|
|
22
|
+
throw new Invalid(`Argument ${argName} is not defined in channel ${channelName}.`);
|
|
23
|
+
const options = { name: channelName, args };
|
|
24
|
+
parts.push(Verbatim.Request.create(options));
|
|
25
|
+
}
|
|
26
|
+
return parts;
|
|
27
|
+
}
|
|
28
|
+
export class Invalid extends Error {
|
|
29
|
+
}
|
|
30
|
+
const XML_ATTR_VAL = /(?<attr_val_quote>['"])(?<attr_val_body>[\s\S]+?)\k<attr_val_quote>/;
|
|
31
|
+
const REQUEST = new RegExp(`<verbatim:request\\s+name\\s*=\\s*(?:${XML_ATTR_VAL.source})\\s*>` +
|
|
32
|
+
`(?<verbatim_body>[\\s\\S]*?)` +
|
|
33
|
+
`</verbatim:request\\s*>`);
|
|
34
|
+
const ARG_CDATA = new RegExp(`<verbatim:argument\\s+name\\s*=\\s*(?:${XML_ATTR_VAL.source})\\s*>` +
|
|
35
|
+
`\\s*<!\\[CDATA\\[(?<arg_cdata_body>[\\s\\S]*?)\\]\\]>\\s*` +
|
|
36
|
+
`</verbatim:argument\\s*>`);
|
|
37
|
+
function extractArgs(str) {
|
|
38
|
+
const results = {};
|
|
39
|
+
for (const match of str.matchAll(new RegExp(ARG_CDATA, 'g'))) {
|
|
40
|
+
if (results[match.groups.attr_val_body] === undefined) { }
|
|
41
|
+
else
|
|
42
|
+
throw new Invalid('Duplicate argument: ' + match.groups.attr_val_body);
|
|
43
|
+
results[match.groups.attr_val_body] = match.groups.arg_cdata_body;
|
|
44
|
+
}
|
|
45
|
+
return results;
|
|
46
|
+
}
|
|
47
|
+
function extractRequests(requests) {
|
|
48
|
+
const results = [];
|
|
49
|
+
for (const match of requests.matchAll(new RegExp(REQUEST, 'g')))
|
|
50
|
+
results.push([match.groups.attr_val_body, extractArgs(match.groups.verbatim_body)]);
|
|
51
|
+
return results;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/verbatim/codec/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG7C;;GAEG;AACH,MAAM,UAAU,MAAM,CAEpB,GAAW,EAAE,GAAQ;IAEnB,MAAM,KAAK,GAA+B,EAAE,CAAC;IAC7C,MAAM,QAAQ,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IACtC,KAAK,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,QAAQ,EAAE,CAAC;QACzC,MAAM,MAAM,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC;QAChC,IAAI,MAAM,EAAE,CAAC,CAAA,CAAC;;YAAM,MAAM,IAAI,OAAO,CAAC,qBAAqB,GAAG,WAAW,CAAC,CAAC;QAC3E,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAClD,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnC,KAAK,MAAM,SAAS,IAAI,UAAU;YAC9B,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA,CAAC;;gBAChC,MAAM,IAAI,OAAO,CAAC,YAAY,SAAS,eAAe,WAAW,cAAc,CAAC,CAAC;QACzF,KAA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ED,SAAS,eAAe,CAAC,QAAgB;IACrC,MAAM,OAAO,GAAqD,EAAE,CAAC;IACrE,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC3D,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,MAAO,CAAC,aAAc,EAAE,WAAW,CAAC,KAAK,CAAC,MAAO,CAAC,aAAc,CAAC,CAAC,CAAC,CAAC;IAC5F,OAAO,OAAO,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../src/verbatim/codec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
declare const NOMINAL: unique symbol;
|
|
2
|
+
export declare namespace Verbatim {
|
|
3
|
+
namespace Name {
|
|
4
|
+
type From<fdm extends Verbatim.Decl.Map.Proto> = globalThis.Extract<keyof fdm, string>;
|
|
5
|
+
}
|
|
6
|
+
interface Decl<in out name extends string, in out params extends Decl.Params.Proto> extends Verbatim.Decl.Body<params> {
|
|
7
|
+
name: name;
|
|
8
|
+
}
|
|
9
|
+
namespace Decl {
|
|
10
|
+
interface Proto extends Verbatim.Decl.Body.Proto {
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
type Args<parameters extends Verbatim.Decl.Params.Proto> = {
|
|
14
|
+
[name in keyof parameters]: string;
|
|
15
|
+
};
|
|
16
|
+
namespace Params {
|
|
17
|
+
type Proto = Record<string, Verbatim.Decl.Para.Body>;
|
|
18
|
+
}
|
|
19
|
+
namespace Para {
|
|
20
|
+
interface Body {
|
|
21
|
+
description: string;
|
|
22
|
+
mimeType: string;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
type Extract<vdm extends Verbatim.Decl.Map.Proto, nameu extends Verbatim.Name.From<vdm>> = nameu extends infer name extends Verbatim.Name.From<vdm> ? Verbatim.Decl<name, vdm[name]['parameters']> : never;
|
|
26
|
+
type From<vdm extends Verbatim.Decl.Map.Proto> = Verbatim.Decl.Extract<vdm, Verbatim.Name.From<vdm>>;
|
|
27
|
+
namespace Map {
|
|
28
|
+
type Proto = Record<string, Verbatim.Decl.Body<Verbatim.Decl.Params.Proto>>;
|
|
29
|
+
}
|
|
30
|
+
interface Body<in out params extends Verbatim.Decl.Params.Proto> {
|
|
31
|
+
description: string;
|
|
32
|
+
parameters: params;
|
|
33
|
+
}
|
|
34
|
+
namespace Body {
|
|
35
|
+
interface Proto {
|
|
36
|
+
description: string;
|
|
37
|
+
parameters: Verbatim.Decl.Params.Proto;
|
|
38
|
+
}
|
|
39
|
+
type Extract<vdm extends Verbatim.Decl.Map.Proto, name extends Verbatim.Name.From<vdm>> = Verbatim.Decl.Body<vdm[name]['parameters']>;
|
|
40
|
+
}
|
|
41
|
+
type Entry<name extends string, ps extends Verbatim.Decl.Params.Proto> = [name, Verbatim.Decl.Body<ps>];
|
|
42
|
+
namespace Entry {
|
|
43
|
+
type Of<vdu extends Verbatim.Decl.Proto> = vdu extends infer vd extends Verbatim.Decl.Proto ? Entry<vd['name'], vd['parameters']> : never;
|
|
44
|
+
type From<vdm extends Verbatim.Decl.Map.Proto> = Verbatim.Decl.Entry.Of<Verbatim.Decl.From<vdm>>;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
class Request<in out vd extends Verbatim.Decl.Proto> {
|
|
48
|
+
protected [NOMINAL]: never;
|
|
49
|
+
name: vd['name'];
|
|
50
|
+
args: Verbatim.Decl.Args<vd['parameters']>;
|
|
51
|
+
protected constructor(vm: Request.Options<vd>);
|
|
52
|
+
static create<vdu extends Verbatim.Decl.Proto>(vm: Verbatim.Request.Options.Of<vdu>): Verbatim.Request.Of<vdu>;
|
|
53
|
+
}
|
|
54
|
+
namespace Request {
|
|
55
|
+
type Of<vdu extends Verbatim.Decl.Proto> = vdu extends infer vd extends Verbatim.Decl.Proto ? Verbatim.Request<vd> : never;
|
|
56
|
+
type From<vdm extends Verbatim.Decl.Map.Proto> = Verbatim.Request.Of<Verbatim.Decl.From<vdm>>;
|
|
57
|
+
type Options<vd extends Verbatim.Decl.Proto> = Omit<Verbatim.Request<vd>, never>;
|
|
58
|
+
namespace Options {
|
|
59
|
+
type Of<vdu extends Verbatim.Decl.Proto> = vdu extends infer vd extends Verbatim.Decl.Proto ? Verbatim.Request.Options<vd> : never;
|
|
60
|
+
type From<vdm extends Verbatim.Decl.Map.Proto> = Verbatim.Request.Options.Of<Verbatim.Decl.From<vdm>>;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
interface Handler<vd extends Verbatim.Decl.Proto> {
|
|
64
|
+
(params: Verbatim.Decl.Args<vd['parameters']>): Promise<string>;
|
|
65
|
+
}
|
|
66
|
+
namespace Handler {
|
|
67
|
+
type Extract<vdm extends Verbatim.Decl.Map.Proto, nameu extends Verbatim.Name.From<vdm>> = Verbatim.Handler.Of<Verbatim.Decl.Extract<vdm, nameu>>;
|
|
68
|
+
type Of<vdu extends Verbatim.Decl.Proto> = vdu extends infer vd extends Verbatim.Decl.Proto ? Handler<vd> : never;
|
|
69
|
+
type Map<vdm extends Verbatim.Decl.Map.Proto> = {
|
|
70
|
+
[name in Verbatim.Name.From<vdm>]: Verbatim.Handler<Verbatim.Decl.Extract<vdm, name>>;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const NOMINAL = Symbol();
|
|
2
|
+
export var Verbatim;
|
|
3
|
+
(function (Verbatim) {
|
|
4
|
+
class Request {
|
|
5
|
+
name;
|
|
6
|
+
args;
|
|
7
|
+
constructor(vm) {
|
|
8
|
+
this.name = vm.name;
|
|
9
|
+
this.args = vm.args;
|
|
10
|
+
}
|
|
11
|
+
static create(vm) {
|
|
12
|
+
return new Verbatim.Request(vm);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
Verbatim.Request = Request;
|
|
16
|
+
})(Verbatim || (Verbatim = {}));
|
|
17
|
+
//# sourceMappingURL=verbatim.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verbatim.js","sourceRoot":"","sources":["../src/verbatim.ts"],"names":[],"mappings":"AACA,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC;AAGzB,MAAM,KAAW,QAAQ,CA2IxB;AA3ID,WAAiB,QAAQ;IAkFrB,MAAa,OAAO;QAET,IAAI,CAAa;QACjB,IAAI,CAAuC;QAClD,YAAsB,EAAuB;YACzC,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC;YACpB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC;QACxB,CAAC;QAEM,MAAM,CAAC,MAAM,CAChB,EAAoC;YAEpC,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,EAAE,CAA6B,CAAC;QAChE,CAAC;KACJ;IAdY,gBAAO,UAcnB,CAAA;AA2CL,CAAC,EA3IgB,QAAQ,KAAR,QAAQ,QA2IxB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Adaptor, agentloop, RoleMessage, Function, type Session, Structuring } from '@zimtsui/brainswitch';
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
|
+
import { config } from './config.ts';
|
|
4
|
+
|
|
5
|
+
// 声明函数工具
|
|
6
|
+
const fdm = {
|
|
7
|
+
get_weather: {
|
|
8
|
+
description: '获取指定城市的天气',
|
|
9
|
+
parameters: Type.Object({
|
|
10
|
+
city: Type.String(),
|
|
11
|
+
unit: Type.Optional(Type.Union([Type.Literal('C'), Type.Literal('F')]))
|
|
12
|
+
}),
|
|
13
|
+
},
|
|
14
|
+
submit_result: {
|
|
15
|
+
description: '提交最终结果',
|
|
16
|
+
parameters: Type.Object({
|
|
17
|
+
weather: Type.String(),
|
|
18
|
+
advice: Type.String(),
|
|
19
|
+
}),
|
|
20
|
+
},
|
|
21
|
+
} satisfies Function.Decl.Map.Proto;
|
|
22
|
+
type fdm = typeof fdm;
|
|
23
|
+
type fdu = Function.Decl.From<fdm>;
|
|
24
|
+
|
|
25
|
+
// 实现函数工具
|
|
26
|
+
export class Submission {
|
|
27
|
+
public constructor(public weather: string, public advice: string) {}
|
|
28
|
+
}
|
|
29
|
+
const fnm: Function.Map<fdm> = {
|
|
30
|
+
async get_weather({ city, unit }) {
|
|
31
|
+
const data = { city, unit: unit ?? 'C', temperature: 26, sky: 'sunny' };
|
|
32
|
+
return JSON.stringify(data);
|
|
33
|
+
},
|
|
34
|
+
async submit_result({ weather, advice }) {
|
|
35
|
+
throw new Submission(weather, advice);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// 创建会话
|
|
40
|
+
const session: Session<fdu, never> = {
|
|
41
|
+
developerMessage: new RoleMessage.Developer([
|
|
42
|
+
RoleMessage.Part.Text.paragraph('你的工作是为用户查询天气,并给出穿衣建议。调用工具提交最终结果'),
|
|
43
|
+
]),
|
|
44
|
+
chatMessages: [
|
|
45
|
+
new RoleMessage.User([ RoleMessage.Part.Text.paragraph('请查询现在北京的天气,并给穿衣建议。') ]),
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// 选择推理引擎
|
|
50
|
+
const adaptor = Adaptor.create(config);
|
|
51
|
+
const engine = adaptor.makeCompatibleEngine<fdm, {}>({
|
|
52
|
+
endpoint: 'gpt-5.4-mini',
|
|
53
|
+
functionDeclarationMap: fdm,
|
|
54
|
+
verbatimDeclarationMap: {},
|
|
55
|
+
structuringChoice: Structuring.Choice.FCall.REQUIRED,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// 使用 agentloop 驱动智能体循环,最多 8 轮对话
|
|
59
|
+
try {
|
|
60
|
+
for await (const text of agentloop({}, session, engine, fnm, 8)) console.log(text);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
if (e instanceof Submission) {} else throw e;
|
|
63
|
+
console.log(e.weather);
|
|
64
|
+
console.log(e.advice);
|
|
65
|
+
}
|
package/examples/chat.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Adaptor, RoleMessage, type Session } from '@zimtsui/brainswitch';
|
|
2
|
+
import { config } from './config.ts';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
// 创建会话
|
|
6
|
+
const session: Session<never, never> = {
|
|
7
|
+
developerMessage: new RoleMessage.Developer([
|
|
8
|
+
RoleMessage.Part.Text.paragraph('You are a helpful assistant.'),
|
|
9
|
+
]),
|
|
10
|
+
chatMessages: [
|
|
11
|
+
new RoleMessage.User([ RoleMessage.Part.Text.paragraph('Hello!') ]),
|
|
12
|
+
],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// 选择推理引擎
|
|
16
|
+
const adaptor = Adaptor.create(config);
|
|
17
|
+
const engine = adaptor.makeCompatibleEngine<{}, {}>({
|
|
18
|
+
endpoint: 'gpt-5.4-mini',
|
|
19
|
+
functionDeclarationMap: {},
|
|
20
|
+
verbatimDeclarationMap: {},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const response = await engine.stateless({}, session);
|
|
24
|
+
console.log(response.getText());
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Config } from '@zimtsui/brainswitch';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
// 配置推理服务商 API 接入点
|
|
5
|
+
export const config: Config = {
|
|
6
|
+
brainswitch: {
|
|
7
|
+
endpoints: {
|
|
8
|
+
'gpt-5.4-mini': {
|
|
9
|
+
name: 'GPT-5.4 mini',
|
|
10
|
+
apiType: 'openai-responses',
|
|
11
|
+
baseUrl: 'https://api.openai.com/v1',
|
|
12
|
+
apiKey: process.env.OPENAI_API_KEY!,
|
|
13
|
+
model: 'gpt-5-mini',
|
|
14
|
+
},
|
|
15
|
+
'gemini-3-flash': {
|
|
16
|
+
name: 'Gemini 3 Flash',
|
|
17
|
+
apiType: 'google',
|
|
18
|
+
baseUrl: 'https://generativelanguage.googleapis.com',
|
|
19
|
+
apiKey: process.env.GOOGLE_API_KEY!,
|
|
20
|
+
model: 'gemini-3-flash',
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -18,13 +18,17 @@
|
|
|
18
18
|
"verbatimModuleSyntax": true,
|
|
19
19
|
"checkJs": true,
|
|
20
20
|
"composite": true,
|
|
21
|
-
"outDir": "../build",
|
|
22
21
|
"skipLibCheck": true,
|
|
22
|
+
"paths": {
|
|
23
|
+
"@zimtsui/brainswitch": ["../src/exports.ts"],
|
|
24
|
+
"@zimtsui/brainswitch/assets": ["../src/assets.ts"],
|
|
25
|
+
"@zimtsui/brainswitch/codec": ["../src/verbatim/codec.ts"],
|
|
26
|
+
}
|
|
23
27
|
},
|
|
24
28
|
"include": [
|
|
25
29
|
"./**/*",
|
|
26
30
|
],
|
|
27
31
|
"references": [
|
|
28
|
-
{ "path": "
|
|
32
|
+
{ "path": "../src/tsconfig.json" },
|
|
29
33
|
]
|
|
30
34
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Adaptor, RoleMessage, type Session, Structuring, Verbatim } from '@zimtsui/brainswitch';
|
|
2
|
+
import Assets from '@zimtsui/brainswitch/assets';
|
|
3
|
+
import * as Codec from '@zimtsui/brainswitch/codec';
|
|
4
|
+
import { config } from './config.ts';
|
|
5
|
+
|
|
6
|
+
// 声明 XML Verbatim 频道
|
|
7
|
+
const vdm = {
|
|
8
|
+
bash: {
|
|
9
|
+
description: '执行 Bash 命令',
|
|
10
|
+
parameters: {
|
|
11
|
+
command: {
|
|
12
|
+
description: 'Bash 命令',
|
|
13
|
+
mimeType: 'text/plain',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
} satisfies Verbatim.Decl.Map.Proto;
|
|
18
|
+
type vdm = typeof vdm;
|
|
19
|
+
type vdu = Verbatim.Decl.From<vdm>;
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
// 创建会话
|
|
23
|
+
const session: Session<never, vdu> = {
|
|
24
|
+
developerMessage: new RoleMessage.Developer([
|
|
25
|
+
Assets.verbatim.instruction,
|
|
26
|
+
RoleMessage.Part.Text.paragraph('# Available Verbatim Channels'),
|
|
27
|
+
RoleMessage.Part.Text.paragraph(Codec.Declarations.encode(vdm)),
|
|
28
|
+
]),
|
|
29
|
+
chatMessages: [
|
|
30
|
+
new RoleMessage.User([ RoleMessage.Part.Text.paragraph('请使用 Bash 命令查询当前系统时间。') ]),
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// 选择推理引擎
|
|
35
|
+
const adaptor = Adaptor.create(config);
|
|
36
|
+
const engine = adaptor.makeCompatibleEngine<{}, vdm>({
|
|
37
|
+
endpoint: 'gpt-5.4-mini',
|
|
38
|
+
functionDeclarationMap: {},
|
|
39
|
+
verbatimDeclarationMap: vdm,
|
|
40
|
+
structuringChoice: Structuring.Choice.VRequest.ANYONE,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const response = await engine.stateless({}, session);
|
|
44
|
+
console.log(response.getOnlyVerbatimRequest().args.command);
|
package/package.json
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zimtsui/brainswitch",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.59",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": "./build/exports.js",
|
|
6
|
-
"./
|
|
7
|
-
"./
|
|
6
|
+
"./assets": "./build/assets.js",
|
|
7
|
+
"./codec": "./build/verbatim/codec.js",
|
|
8
|
+
"./openai-responses": "./build/native-engines.d/openai-responses.d/exports.js",
|
|
9
|
+
"./google": "./build/native-engines.d/google.d/exports.js"
|
|
8
10
|
},
|
|
9
|
-
"imports": {
|
|
10
|
-
"#@/*.ts": "./build/*.js"
|
|
11
|
-
},
|
|
12
|
-
"description": "",
|
|
13
11
|
"engines": {
|
|
14
12
|
"node": ">=22"
|
|
15
13
|
},
|
|
16
14
|
"type": "module",
|
|
17
15
|
"scripts": {
|
|
18
|
-
"test": "
|
|
16
|
+
"test": "npm run build && ava ./test/test.ts",
|
|
19
17
|
"build": "tsc -b ./src/tsconfig.json",
|
|
20
|
-
"clean": "rm -rf ./build
|
|
18
|
+
"clean": "rm -rf ./build",
|
|
21
19
|
"docs": "rm -rf ./docs && typedoc --tsconfig ./src/tsconfig.json ./src/exports.ts ./src/native-engines.d/*/exports.ts",
|
|
22
|
-
"prepublishOnly": "npm run clean && npm run build
|
|
20
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
23
21
|
},
|
|
24
22
|
"author": "Zim",
|
|
25
23
|
"repository": {
|
|
@@ -29,18 +27,22 @@
|
|
|
29
27
|
"dependencies": {
|
|
30
28
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
31
29
|
"@google/genai": "^1.33.0",
|
|
30
|
+
"@zimtsui/node-loaders": "^0.0.2",
|
|
32
31
|
"ajv": "^8.17.1",
|
|
32
|
+
"handlebars": "^4.7.8",
|
|
33
33
|
"openai": "^6.10.0",
|
|
34
|
+
"strings-to-regex": "^1.3.0",
|
|
34
35
|
"undici": "^7.16.0"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
37
38
|
"@sinclair/typebox": "^0.34.40",
|
|
38
39
|
"@types/node": "^22.17.2",
|
|
39
|
-
"@zimtsui/coroutine-locks": "^0.0.
|
|
40
|
-
"@zimtsui/typelog": "^0.0.
|
|
40
|
+
"@zimtsui/coroutine-locks": "^0.0.27",
|
|
41
|
+
"@zimtsui/typelog": "^0.0.30"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"ava": "^7.0.0"
|
|
44
|
+
"ava": "^7.0.0",
|
|
45
|
+
"typescript": "^5.9.3"
|
|
44
46
|
},
|
|
45
47
|
"ava": {
|
|
46
48
|
"failWithoutAssertions": false,
|
package/build/agentloop.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type InferenceContext } from '#@/inference-context.ts';
|
|
2
|
-
import { type Session } from '#@/compatible/session.ts';
|
|
3
|
-
import { Function } from '#@/function.ts';
|
|
4
|
-
import { type CompatibleEngine } from '#@/compatible/engine.ts';
|
|
5
|
-
/**
|
|
6
|
-
* @param session mutable
|
|
7
|
-
*/
|
|
8
|
-
export declare function agentloop<fdm extends Function.Declaration.Map>(wfctx: InferenceContext, session: Session<fdm>, engine: CompatibleEngine<fdm>, fnm: Function.Map<fdm>, limit?: number): AsyncGenerator<string, string, void>;
|
|
9
|
-
export declare namespace agentloop {
|
|
10
|
-
class FunctionCallLimitExceeded extends Error {
|
|
11
|
-
}
|
|
12
|
-
}
|
package/build/agentloop.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import {} from '#@/inference-context.ts';
|
|
2
|
-
import { RoleMessage } from '#@/compatible/session.ts';
|
|
3
|
-
import { Function } from '#@/function.ts';
|
|
4
|
-
import {} from '#@/compatible/engine.ts';
|
|
5
|
-
/**
|
|
6
|
-
* @param session mutable
|
|
7
|
-
*/
|
|
8
|
-
export async function* agentloop(wfctx, session, engine, fnm, limit = Number.POSITIVE_INFINITY) {
|
|
9
|
-
for (let i = 0; i < limit; i++) {
|
|
10
|
-
const response = await engine.stateful(wfctx, session);
|
|
11
|
-
const fcs = response.getFunctionCalls();
|
|
12
|
-
if (!fcs.length)
|
|
13
|
-
return response.getOnlyText();
|
|
14
|
-
const pfrs = [];
|
|
15
|
-
for (const part of response.getParts()) {
|
|
16
|
-
if (part instanceof RoleMessage.Part.Text.Instance) {
|
|
17
|
-
yield part.text;
|
|
18
|
-
}
|
|
19
|
-
else if (part instanceof Function.Call) {
|
|
20
|
-
const fc = part;
|
|
21
|
-
const f = fnm[fc.name];
|
|
22
|
-
pfrs.push((async () => {
|
|
23
|
-
return Function.Response.create({
|
|
24
|
-
id: fc.id,
|
|
25
|
-
name: fc.name,
|
|
26
|
-
text: await f.call(fnm, fc.args),
|
|
27
|
-
});
|
|
28
|
-
})());
|
|
29
|
-
}
|
|
30
|
-
else
|
|
31
|
-
throw new Error();
|
|
32
|
-
}
|
|
33
|
-
const frs = await Promise.all(pfrs);
|
|
34
|
-
engine.pushUserMessage(session, RoleMessage.User.create(frs));
|
|
35
|
-
}
|
|
36
|
-
throw new agentloop.FunctionCallLimitExceeded('Function call limit exceeded.');
|
|
37
|
-
}
|
|
38
|
-
(function (agentloop) {
|
|
39
|
-
class FunctionCallLimitExceeded extends Error {
|
|
40
|
-
}
|
|
41
|
-
agentloop.FunctionCallLimitExceeded = FunctionCallLimitExceeded;
|
|
42
|
-
})(agentloop || (agentloop = {}));
|
|
43
|
-
//# sourceMappingURL=agentloop.js.map
|
package/build/agentloop.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agentloop.js","sourceRoot":"","sources":["../src/agentloop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAgB,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAyB,MAAM,yBAAyB,CAAC;AAGhE;;GAEG;AACH,MAAM,CAAC,KAAK,SAAU,CAAC,CAAA,SAAS,CAC5B,KAAuB,EACvB,OAAqB,EACrB,MAA6B,EAC7B,GAAsB,EACtB,KAAK,GAAG,MAAM,CAAC,iBAAiB;IAEhC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACvD,MAAM,GAAG,GAAG,QAAQ,CAAC,gBAAgB,EAAE,CAAC;Q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AS,KAAT,SAAS,QAEzB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../../../src/api-types/openai-chatcompletion/billing.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,MAAM,OAAO,4BAA4B;IACR;IAA7B,YAA6B,GAAyC;QAAzC,QAAG,GAAH,GAAG,CAAsC;IAAG,CAAC;IAEnE,MAAM,CAAC,KAA6B;QACvC,MAAM,kBAAkB,GAAG,KAAK,CAAC,qBAAqB,EAAE,aAAa,IAAI,CAAC,CAAC;QAC3E,MAAM,mBAAmB,GAAG,KAAK,CAAC,aAAa,GAAG,kBAAkB,CAAC;QACrE,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,iBAAiB,GAAG,GAAG,CAC/D,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Function } from '#@/function.ts';
|
|
2
|
-
import OpenAI from 'openai';
|
|
3
|
-
export declare class OpenAIChatCompletionsToolCodec<in out fdm extends Function.Declaration.Map> {
|
|
4
|
-
protected ctx: OpenAIChatCompletionsToolCodec.Context<fdm>;
|
|
5
|
-
constructor(ctx: OpenAIChatCompletionsToolCodec.Context<fdm>);
|
|
6
|
-
convertFromFunctionCall(fc: Function.Call.From<fdm>): OpenAI.ChatCompletionMessageToolCall;
|
|
7
|
-
convertToFunctionCall(apifc: OpenAI.ChatCompletionMessageFunctionToolCall): Function.Call.From<fdm>;
|
|
8
|
-
convertFromFunctionResponse(fr: Function.Response.Distributive<fdm>): OpenAI.ChatCompletionToolMessageParam;
|
|
9
|
-
protected convertFromFunctionDeclarationEntry(fdentry: Function.Declaration.Entry.From<fdm>): OpenAI.ChatCompletionTool;
|
|
10
|
-
convertFromFunctionDeclarationMap(fdm: fdm): OpenAI.ChatCompletionTool[];
|
|
11
|
-
convertFromToolChoice(toolChoice: Function.ToolChoice<fdm>): OpenAI.ChatCompletionToolChoiceOption;
|
|
12
|
-
}
|
|
13
|
-
export declare namespace OpenAIChatCompletionsToolCodec {
|
|
14
|
-
interface Context<in out fdm extends Function.Declaration.Map> {
|
|
15
|
-
parallelToolCall: boolean;
|
|
16
|
-
fdm: fdm;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
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,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ChB,QAAQ,EAAE;gBACN,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;gBAChB,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW;gBACnC,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"}
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aliyun.js","sourceRoot":"","sources":["../../../src/compatible/engine.d/aliyun.ts"],"names":[],"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