@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
|
@@ -1,59 +1,61 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Function } from '
|
|
3
|
-
import { Tool } from '
|
|
4
|
-
import type {
|
|
1
|
+
import { RoleMessage as CompatibleRoleMessage } from '../../compatible-engine/session.ts';
|
|
2
|
+
import { Function } from '../../function.ts';
|
|
3
|
+
import { Tool } from './tool.ts';
|
|
4
|
+
import type { Engine } from '../../engine.ts';
|
|
5
|
+
import type { Verbatim } from '../../verbatim.ts';
|
|
5
6
|
import OpenAI from 'openai';
|
|
6
|
-
|
|
7
|
+
declare const NOMINAL: unique symbol;
|
|
8
|
+
export interface Session<in out fdu extends Function.Decl.Proto, in out vdu extends Verbatim.Decl.Proto> extends Engine.Session<RoleMessage.User<fdu>, RoleMessage.Ai<fdu, vdu>, RoleMessage.Developer> {
|
|
7
9
|
}
|
|
8
10
|
export declare namespace Session {
|
|
9
|
-
type
|
|
11
|
+
type From<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto> = Session<Function.Decl.From<fdm>, Verbatim.Decl.From<vdm>>;
|
|
12
|
+
type ChatMessage<fdu extends Function.Decl.Proto, vdu extends Verbatim.Decl.Proto> = Engine.Session.ChatMessage<RoleMessage.User<fdu>, RoleMessage.Ai<fdu, vdu>>;
|
|
13
|
+
namespace ChatMessage {
|
|
14
|
+
type From<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto> = Session.ChatMessage<Function.Decl.From<fdm>, Verbatim.Decl.From<vdm>>;
|
|
15
|
+
}
|
|
10
16
|
}
|
|
11
|
-
export type RoleMessage = RoleMessage.Instance;
|
|
12
17
|
export declare namespace RoleMessage {
|
|
13
|
-
const NOMINAL: unique symbol;
|
|
14
|
-
abstract class Instance {
|
|
15
|
-
private readonly [NOMINAL];
|
|
16
|
-
abstract getText(): string;
|
|
17
|
-
abstract getOnlyText(): string;
|
|
18
|
-
}
|
|
19
18
|
namespace Part {
|
|
20
|
-
export import Text =
|
|
19
|
+
export import Text = CompatibleRoleMessage.Part.Text;
|
|
20
|
+
}
|
|
21
|
+
class Ai<in out fdu extends Function.Decl.Proto, in out vdu extends Verbatim.Decl.Proto> {
|
|
22
|
+
protected parts: RoleMessage.Ai.Part<fdu, vdu>[];
|
|
23
|
+
protected raw: OpenAI.Responses.ResponseOutputItem[];
|
|
24
|
+
protected [NOMINAL]: never;
|
|
25
|
+
constructor(parts: RoleMessage.Ai.Part<fdu, vdu>[], raw: OpenAI.Responses.ResponseOutputItem[]);
|
|
26
|
+
getParts(): RoleMessage.Ai.Part<fdu, vdu>[];
|
|
27
|
+
getRaw(): OpenAI.Responses.ResponseOutputItem[];
|
|
28
|
+
allTextPart(): boolean;
|
|
29
|
+
getTextParts(): RoleMessage.Part.Text<vdu>[];
|
|
30
|
+
getText(): string;
|
|
31
|
+
getToolCalls(): Tool.Call.Of<fdu>[];
|
|
32
|
+
getFunctionCalls(): Function.Call.Of<fdu>[];
|
|
33
|
+
getVerbatimRequests(): Verbatim.Request.Of<vdu>[];
|
|
34
|
+
getOnlyFunctionCall(): Function.Call.Of<fdu>;
|
|
35
|
+
getOnlyToolCall(): Tool.Call.Of<fdu>;
|
|
36
|
+
getOnlyVerbatimRequest(): Verbatim.Request.Of<vdu>;
|
|
21
37
|
}
|
|
22
|
-
type Ai<fdm extends Function.Declaration.Map> = Ai.Instance<fdm>;
|
|
23
38
|
namespace Ai {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
protected raw: OpenAI.Responses.ResponseOutputItem[];
|
|
29
|
-
readonly [NOMINAL]: void;
|
|
30
|
-
constructor(parts: RoleMessage.Ai.Part<fdm>[], raw: OpenAI.Responses.ResponseOutputItem[]);
|
|
31
|
-
getParts(): RoleMessage.Ai.Part<fdm>[];
|
|
32
|
-
getRaw(): OpenAI.Responses.ResponseOutputItem[];
|
|
33
|
-
getText(): string;
|
|
34
|
-
getOnlyText(): string;
|
|
35
|
-
getOnlyFunctionCall(): Function.Call.From<fdm>;
|
|
36
|
-
getOnlyApplyPatchCall(): Tool.ApplyPatch.Call;
|
|
37
|
-
getToolCalls(): Tool.Call<fdm>[];
|
|
38
|
-
getFunctionCalls(): Function.Call.From<fdm>[];
|
|
39
|
-
getOnlyFunctionCalls(): Function.Call.From<fdm>[];
|
|
39
|
+
type From<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto> = RoleMessage.Ai<Function.Decl.From<fdm>, Verbatim.Decl.From<vdm>>;
|
|
40
|
+
type Part<fdu extends Function.Decl.Proto, vdu extends Verbatim.Decl.Proto> = RoleMessage.Part.Text<vdu> | Tool.Call.Of<fdu>;
|
|
41
|
+
namespace Part {
|
|
42
|
+
type From<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto> = RoleMessage.Ai.Part<Function.Decl.From<fdm>, Verbatim.Decl.From<vdm>>;
|
|
40
43
|
}
|
|
41
|
-
type Part<fdm extends Function.Declaration.Map> = RoleMessage.Part.Text | Tool.Call<fdm>;
|
|
42
44
|
}
|
|
43
|
-
|
|
45
|
+
class User<in out fdu extends Function.Decl.Proto> {
|
|
46
|
+
protected parts: RoleMessage.User.Part<fdu>[];
|
|
47
|
+
protected [NOMINAL]: never;
|
|
48
|
+
constructor(parts: RoleMessage.User.Part<fdu>[]);
|
|
49
|
+
getParts(): RoleMessage.User.Part<fdu>[];
|
|
50
|
+
getToolResponses(): Tool.Response.Of<fdu>[];
|
|
51
|
+
}
|
|
44
52
|
namespace User {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
private readonly [NOMINAL];
|
|
50
|
-
constructor(parts: RoleMessage.User.Part<fdm>[]);
|
|
51
|
-
getParts(): RoleMessage.User.Part<fdm>[];
|
|
52
|
-
getText(): string;
|
|
53
|
-
getOnlyText(): string;
|
|
54
|
-
getToolResponses(): Tool.Response<fdm>[];
|
|
53
|
+
type From<fdm extends Function.Decl.Map.Proto> = RoleMessage.User<Function.Decl.From<fdm>>;
|
|
54
|
+
type Part<fdu extends Function.Decl.Proto> = RoleMessage.Part.Text<never> | Tool.Response.Of<fdu>;
|
|
55
|
+
namespace Part {
|
|
56
|
+
type From<fdm extends Function.Decl.Map.Proto> = RoleMessage.User.Part<Function.Decl.From<fdm>>;
|
|
55
57
|
}
|
|
56
|
-
type Part<fdm extends Function.Declaration.Map> = RoleMessage.Part.Text | Tool.Response<fdm>;
|
|
57
58
|
}
|
|
58
|
-
export import Developer =
|
|
59
|
+
export import Developer = CompatibleRoleMessage.Developer;
|
|
59
60
|
}
|
|
61
|
+
export {};
|
|
@@ -1,116 +1,86 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Function } from
|
|
3
|
-
import { Tool } from
|
|
4
|
-
|
|
1
|
+
import { RoleMessage as CompatibleRoleMessage } from "../../compatible-engine/session.js";
|
|
2
|
+
import { Function } from "../../function.js";
|
|
3
|
+
import { Tool } from "./tool.js";
|
|
4
|
+
const NOMINAL = Symbol();
|
|
5
5
|
export var RoleMessage;
|
|
6
6
|
(function (RoleMessage) {
|
|
7
|
-
RoleMessage.NOMINAL = Symbol();
|
|
8
|
-
class Instance {
|
|
9
|
-
}
|
|
10
|
-
RoleMessage.Instance = Instance;
|
|
11
7
|
let Part;
|
|
12
8
|
(function (Part) {
|
|
13
|
-
Part.Text =
|
|
9
|
+
Part.Text = CompatibleRoleMessage.Part.Text;
|
|
14
10
|
})(Part = RoleMessage.Part || (RoleMessage.Part = {}));
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
class Ai {
|
|
12
|
+
parts;
|
|
13
|
+
raw;
|
|
14
|
+
constructor(parts, raw) {
|
|
15
|
+
this.parts = parts;
|
|
16
|
+
this.raw = raw;
|
|
17
|
+
}
|
|
18
|
+
getParts() {
|
|
19
|
+
return this.parts;
|
|
20
|
+
}
|
|
21
|
+
getRaw() {
|
|
22
|
+
return this.raw;
|
|
23
|
+
}
|
|
24
|
+
allTextPart() {
|
|
25
|
+
return this.parts.every(part => part instanceof RoleMessage.Part.Text);
|
|
26
|
+
}
|
|
27
|
+
getTextParts() {
|
|
28
|
+
return this.parts.filter(part => part instanceof RoleMessage.Part.Text);
|
|
29
|
+
}
|
|
30
|
+
getText() {
|
|
31
|
+
return this.getTextParts().map(part => part.text).join('');
|
|
32
|
+
}
|
|
33
|
+
getToolCalls() {
|
|
34
|
+
return this.parts.filter(part => part instanceof Function.Call || part instanceof Tool.ApplyPatch.Call);
|
|
19
35
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class Instance extends RoleMessage.Instance {
|
|
23
|
-
parts;
|
|
24
|
-
raw;
|
|
25
|
-
constructor(parts, raw) {
|
|
26
|
-
super();
|
|
27
|
-
this.parts = parts;
|
|
28
|
-
this.raw = raw;
|
|
29
|
-
}
|
|
30
|
-
getParts() {
|
|
31
|
-
return this.parts;
|
|
32
|
-
}
|
|
33
|
-
getRaw() {
|
|
34
|
-
return this.raw;
|
|
35
|
-
}
|
|
36
|
-
getText() {
|
|
37
|
-
return this.parts.filter(part => part instanceof RoleMessage.Part.Text.Instance).map(part => part.text).join('');
|
|
38
|
-
}
|
|
39
|
-
getOnlyText() {
|
|
40
|
-
if (this.parts.every(part => part instanceof RoleMessage.Part.Text.Instance)) { }
|
|
41
|
-
else
|
|
42
|
-
throw new Error();
|
|
43
|
-
return this.getText();
|
|
44
|
-
}
|
|
45
|
-
getOnlyFunctionCall() {
|
|
46
|
-
const tcs = this.getToolCalls();
|
|
47
|
-
if (tcs.length === 1) { }
|
|
48
|
-
else
|
|
49
|
-
throw new Error();
|
|
50
|
-
const tc = tcs[0];
|
|
51
|
-
if (tc instanceof Function.Call) { }
|
|
52
|
-
else
|
|
53
|
-
throw new Error();
|
|
54
|
-
return tc;
|
|
55
|
-
}
|
|
56
|
-
getOnlyApplyPatchCall() {
|
|
57
|
-
const tcs = this.getToolCalls();
|
|
58
|
-
if (tcs.length === 1) { }
|
|
59
|
-
else
|
|
60
|
-
throw new Error();
|
|
61
|
-
const tc = tcs[0];
|
|
62
|
-
if (tc instanceof Tool.ApplyPatch.Call) { }
|
|
63
|
-
else
|
|
64
|
-
throw new Error();
|
|
65
|
-
return tc;
|
|
66
|
-
}
|
|
67
|
-
getToolCalls() {
|
|
68
|
-
return this.parts.filter(part => part instanceof Function.Call || part instanceof Tool.ApplyPatch.Call);
|
|
69
|
-
}
|
|
70
|
-
getFunctionCalls() {
|
|
71
|
-
return this.parts.filter(part => part instanceof Function.Call);
|
|
72
|
-
}
|
|
73
|
-
getOnlyFunctionCalls() {
|
|
74
|
-
const tcs = this.getToolCalls();
|
|
75
|
-
if (tcs.every(tc => tc instanceof Function.Call)) { }
|
|
76
|
-
else
|
|
77
|
-
throw new Error();
|
|
78
|
-
return tcs;
|
|
79
|
-
}
|
|
36
|
+
getFunctionCalls() {
|
|
37
|
+
return this.parts.filter(part => part instanceof Function.Call);
|
|
80
38
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
function create(parts) {
|
|
86
|
-
return new Instance(parts);
|
|
39
|
+
getVerbatimRequests() {
|
|
40
|
+
return this.parts
|
|
41
|
+
.filter(part => part instanceof RoleMessage.Part.Text)
|
|
42
|
+
.flatMap(part => part.vrs);
|
|
87
43
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
getText() {
|
|
100
|
-
return this.parts.filter(part => part instanceof RoleMessage.Part.Text.Instance).map(part => part.text).join('');
|
|
101
|
-
}
|
|
102
|
-
getOnlyText() {
|
|
103
|
-
if (this.parts.every(part => part instanceof RoleMessage.Part.Text.Instance)) { }
|
|
104
|
-
else
|
|
105
|
-
throw new Error();
|
|
106
|
-
return this.getText();
|
|
107
|
-
}
|
|
108
|
-
getToolResponses() {
|
|
109
|
-
return this.parts.filter(part => part instanceof Function.Response || part instanceof Tool.ApplyPatch.Response);
|
|
110
|
-
}
|
|
44
|
+
getOnlyFunctionCall() {
|
|
45
|
+
const tcs = this.getToolCalls();
|
|
46
|
+
if (tcs.length === 1) { }
|
|
47
|
+
else
|
|
48
|
+
throw new Error();
|
|
49
|
+
const tc = tcs[0];
|
|
50
|
+
if (tc instanceof Function.Call) { }
|
|
51
|
+
else
|
|
52
|
+
throw new Error();
|
|
53
|
+
return tc;
|
|
111
54
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
55
|
+
getOnlyToolCall() {
|
|
56
|
+
const tcs = this.getToolCalls();
|
|
57
|
+
if (tcs.length === 1) { }
|
|
58
|
+
else
|
|
59
|
+
throw new Error();
|
|
60
|
+
return tcs[0];
|
|
61
|
+
}
|
|
62
|
+
getOnlyVerbatimRequest() {
|
|
63
|
+
const vrs = this.getVerbatimRequests();
|
|
64
|
+
if (vrs.length === 1) { }
|
|
65
|
+
else
|
|
66
|
+
throw new Error();
|
|
67
|
+
return vrs[0];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
RoleMessage.Ai = Ai;
|
|
71
|
+
class User {
|
|
72
|
+
parts;
|
|
73
|
+
constructor(parts) {
|
|
74
|
+
this.parts = parts;
|
|
75
|
+
}
|
|
76
|
+
getParts() {
|
|
77
|
+
return this.parts;
|
|
78
|
+
}
|
|
79
|
+
getToolResponses() {
|
|
80
|
+
return this.parts.filter(part => part instanceof Function.Response || part instanceof Tool.ApplyPatch.Response);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
RoleMessage.User = User;
|
|
84
|
+
RoleMessage.Developer = CompatibleRoleMessage.Developer;
|
|
115
85
|
})(RoleMessage || (RoleMessage = {}));
|
|
116
86
|
//# sourceMappingURL=session.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/native-engines.d/openai-responses/session.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/native-engines.d/openai-responses/session.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Structuring as CompatibleStructuring } from '../../compatible-engine/structuring.ts';
|
|
2
|
+
import type { Function } from '../../function.ts';
|
|
3
|
+
import type { Verbatim } from '../../verbatim.ts';
|
|
4
|
+
export declare namespace Structuring {
|
|
5
|
+
type Choice<fdu extends Function.Decl.Proto, vdu extends Verbatim.Decl.Proto> = Structuring.Choice.TCall.FCall.Of<fdu> | typeof Structuring.Choice.TCall.REQUIRED | typeof Structuring.Choice.TCall.ANYONE | Structuring.Choice.VRequest.Of<vdu> | typeof Structuring.Choice.VRequest.REQUIRED | typeof Structuring.Choice.VRequest.ANYONE | typeof Structuring.Choice.NONE | typeof Structuring.Choice.AUTO | typeof Structuring.Choice.REQUIRED | typeof Structuring.Choice.ANYONE;
|
|
6
|
+
namespace Choice {
|
|
7
|
+
type From<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto> = Structuring.Choice<Function.Decl.From<fdm>, Verbatim.Decl.From<vdm>>;
|
|
8
|
+
export import REQUIRED = CompatibleStructuring.Choice.REQUIRED;
|
|
9
|
+
export import ANYONE = CompatibleStructuring.Choice.ANYONE;
|
|
10
|
+
namespace TCall {
|
|
11
|
+
const REQUIRED: unique symbol;
|
|
12
|
+
const ANYONE: unique symbol;
|
|
13
|
+
export import FCall = CompatibleStructuring.Choice.FCall;
|
|
14
|
+
}
|
|
15
|
+
export import VRequest = CompatibleStructuring.Choice.VRequest;
|
|
16
|
+
export import NONE = CompatibleStructuring.Choice.NONE;
|
|
17
|
+
export import AUTO = CompatibleStructuring.Choice.AUTO;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Structuring as CompatibleStructuring } from "../../compatible-engine/structuring.js";
|
|
2
|
+
export var Structuring;
|
|
3
|
+
(function (Structuring) {
|
|
4
|
+
let Choice;
|
|
5
|
+
(function (Choice) {
|
|
6
|
+
Choice.REQUIRED = CompatibleStructuring.Choice.REQUIRED;
|
|
7
|
+
Choice.ANYONE = CompatibleStructuring.Choice.ANYONE;
|
|
8
|
+
let TCall;
|
|
9
|
+
(function (TCall) {
|
|
10
|
+
TCall.REQUIRED = Symbol();
|
|
11
|
+
TCall.ANYONE = Symbol();
|
|
12
|
+
TCall.FCall = CompatibleStructuring.Choice.FCall;
|
|
13
|
+
})(TCall = Choice.TCall || (Choice.TCall = {}));
|
|
14
|
+
Choice.VRequest = CompatibleStructuring.Choice.VRequest;
|
|
15
|
+
Choice.NONE = CompatibleStructuring.Choice.NONE;
|
|
16
|
+
Choice.AUTO = CompatibleStructuring.Choice.AUTO;
|
|
17
|
+
})(Choice = Structuring.Choice || (Structuring.Choice = {}));
|
|
18
|
+
})(Structuring || (Structuring = {}));
|
|
19
|
+
//# sourceMappingURL=structuring.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structuring.js","sourceRoot":"","sources":["../../../src/native-engines.d/openai-responses/structuring.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,IAAI,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAK9F,MAAM,KAAW,WAAW,CAuC3B;AAvCD,WAAiB,WAAW;IAmBxB,IAAiB,MAAM,CAmBtB;IAnBD,WAAiB,MAAM;QAML,eAAQ,GAAG,qBAAqB,CAAC,MAAM,CAAC,QAAQ,CAAC;QACjD,aAAM,GAAG,qBAAqB,CAAC,MAAM,CAAC,MAAM,CAAC;QAE3D,IAAiB,KAAK,CAKrB;QALD,WAAiB,KAAK;YACL,cAAQ,GAAG,MAAM,EAAE,CAAC;YACpB,YAAM,GAAG,MAAM,EAAE,CAAC;YAEjB,WAAK,GAAG,qBAAqB,CAAC,MAAM,CAAC,KAAK,CAAC;QAC7D,CAAC,EALgB,KAAK,GAAL,YAAK,KAAL,YAAK,QAKrB;QAEa,eAAQ,GAAG,qBAAqB,CAAC,MAAM,CAAC,QAAQ,CAAC;QACjD,WAAI,GAAG,qBAAqB,CAAC,MAAM,CAAC,IAAI,CAAC;QACzC,WAAI,GAAG,qBAAqB,CAAC,MAAM,CAAC,IAAI,CAAC;IAC3D,CAAC,EAnBgB,MAAM,GAAN,kBAAM,KAAN,kBAAM,QAmBtB;AACL,CAAC,EAvCgB,WAAW,KAAX,WAAW,QAuC3B"}
|
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
import { Function } from '
|
|
1
|
+
import { Function } from '../../function.ts';
|
|
2
2
|
import OpenAI from 'openai';
|
|
3
3
|
export declare namespace Tool {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const APPLY_PATCH: unique symbol;
|
|
5
|
+
namespace Name {
|
|
6
|
+
type From<fdm extends Function.Decl.Map.Proto> = Function.Name.From<fdm> | typeof Tool.APPLY_PATCH;
|
|
7
|
+
}
|
|
8
|
+
type Map<fdm extends Function.Decl.Map.Proto> = {
|
|
9
|
+
[name in Tool.Name.From<fdm>]: name extends typeof Tool.APPLY_PATCH ? Tool.ApplyPatch : name extends Function.Name.From<fdm> ? Function.Extract<fdm, name> : never;
|
|
7
10
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
namespace Call {
|
|
12
|
+
type Of<fdu extends Function.Decl.Proto> = Function.Call.Of<fdu> | ApplyPatch.Call;
|
|
13
|
+
type From<fdm extends Function.Decl.Map.Proto> = Call.Of<Function.Decl.From<fdm>>;
|
|
14
|
+
}
|
|
15
|
+
namespace Response {
|
|
16
|
+
type Of<fdu extends Function.Decl.Proto> = Function.Response.Of<fdu> | ApplyPatch.Response;
|
|
17
|
+
type From<fdm extends Function.Decl.Map.Proto> = Response.Of<Function.Decl.From<fdm>>;
|
|
11
18
|
}
|
|
12
|
-
type Call<fdm extends Function.Declaration.Map> = Function.Call.From<fdm> | ApplyPatch.Call;
|
|
13
|
-
type Response<fdm extends Function.Declaration.Map> = Function.Response.Distributive<fdm> | ApplyPatch.Response;
|
|
14
19
|
interface ApplyPatch {
|
|
15
20
|
/**
|
|
16
21
|
* @returns empty string on success
|
|
17
22
|
*/
|
|
18
|
-
(operation: ApplyPatch.Operation): string
|
|
23
|
+
(operation: ApplyPatch.Operation): Promise<string>;
|
|
19
24
|
}
|
|
20
25
|
namespace ApplyPatch {
|
|
21
26
|
type Operation = Operation.UpdateFile | Operation.CreateFile | Operation.DeleteFile;
|
|
@@ -39,13 +44,11 @@ export declare namespace Tool {
|
|
|
39
44
|
namespace ApplyPatch {
|
|
40
45
|
class Call {
|
|
41
46
|
raw: OpenAI.Responses.ResponseApplyPatchToolCall;
|
|
42
|
-
static create(raw: OpenAI.Responses.ResponseApplyPatchToolCall): ApplyPatch.Call;
|
|
43
47
|
constructor(raw: OpenAI.Responses.ResponseApplyPatchToolCall);
|
|
44
48
|
}
|
|
45
49
|
class Response {
|
|
46
50
|
id: string;
|
|
47
51
|
failure: string;
|
|
48
|
-
static create(apr: Omit<ApplyPatch.Response, never>): ApplyPatch.Response;
|
|
49
52
|
constructor(apr: Omit<ApplyPatch.Response, never>);
|
|
50
53
|
}
|
|
51
54
|
}
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import { Function } from '#@/function.ts';
|
|
2
|
-
import OpenAI from 'openai';
|
|
3
1
|
export var Tool;
|
|
4
2
|
(function (Tool) {
|
|
5
|
-
|
|
6
|
-
(function (Choice) {
|
|
7
|
-
Choice.APPLY_PATCH = Symbol();
|
|
8
|
-
})(Choice = Tool.Choice || (Tool.Choice = {}));
|
|
3
|
+
Tool.APPLY_PATCH = Symbol();
|
|
9
4
|
let ApplyPatch;
|
|
10
5
|
(function (ApplyPatch) {
|
|
11
6
|
class Call {
|
|
12
7
|
raw;
|
|
13
|
-
static create(raw) {
|
|
14
|
-
return new ApplyPatch.Call(raw);
|
|
15
|
-
}
|
|
16
8
|
constructor(raw) {
|
|
17
9
|
this.raw = raw;
|
|
18
10
|
}
|
|
@@ -21,9 +13,6 @@ export var Tool;
|
|
|
21
13
|
class Response {
|
|
22
14
|
id;
|
|
23
15
|
failure;
|
|
24
|
-
static create(apr) {
|
|
25
|
-
return new ApplyPatch.Response(apr);
|
|
26
|
-
}
|
|
27
16
|
constructor(apr) {
|
|
28
17
|
this.id = apr.id;
|
|
29
18
|
this.failure = apr.failure;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../src/native-engines.d/openai-responses/tool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../src/native-engines.d/openai-responses/tool.ts"],"names":[],"mappings":"AAIA,MAAM,KAAW,IAAI,CAkFpB;AAlFD,WAAiB,IAAI;IACJ,gBAAW,GAAG,MAAM,EAAE,CAAC;IA+DpC,IAAiB,UAAU,CAe1B;IAfD,WAAiB,UAAU;QAEvB,MAAa,IAAI;YACa;YAA1B,YAA0B,GAAgD;gBAAhD,QAAG,GAAH,GAAG,CAA6C;YAAG,CAAC;SACjF;QAFY,eAAI,OAEhB,CAAA;QAED,MAAa,QAAQ;YACV,EAAE,CAAS;YACX,OAAO,CAAS;YACvB,YAAmB,GAAqC;gBACpD,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,CAAC;gBACjB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;YAC/B,CAAC;SACJ;QAPY,mBAAQ,WAOpB,CAAA;IAEL,CAAC,EAfgB,UAAU,GAAV,eAAU,KAAV,eAAU,QAe1B;AAGL,CAAC,EAlFgB,IAAI,KAAJ,IAAI,QAkFpB"}
|
|
@@ -1,36 +1,35 @@
|
|
|
1
|
-
import { type InferenceParams, type ProviderSpec } from '
|
|
2
|
-
import { RoleMessage, type Session } from '
|
|
3
|
-
import { Function } from '
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import type {
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
11
|
-
import type {
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { type InferenceParams, type ProviderSpec } from '../../engine.ts';
|
|
2
|
+
import { RoleMessage, type Session } from './session.ts';
|
|
3
|
+
import { Function } from '../../function.ts';
|
|
4
|
+
import type OpenAI from 'openai';
|
|
5
|
+
import { type InferenceContext } from '../../inference-context.ts';
|
|
6
|
+
import { Throttle } from '../../throttle.ts';
|
|
7
|
+
import type { MessageCodec } from './message-codec.ts';
|
|
8
|
+
import type { ToolCodec } from '../../api-types/openai-responses/tool-codec.ts';
|
|
9
|
+
import type { Billing } from '../../api-types/openai-responses/billing.ts';
|
|
10
|
+
import type { Validator } from './validation.ts';
|
|
11
|
+
import type { Verbatim } from '../../verbatim.ts';
|
|
12
|
+
import { Structuring } from './structuring.ts';
|
|
13
|
+
export declare class Transport<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto> {
|
|
14
|
+
protected ctx: Transport.Context<fdm, vdm>;
|
|
14
15
|
protected apiURL: URL;
|
|
15
|
-
constructor(ctx:
|
|
16
|
-
protected makeParams(session: Session<fdm>): OpenAI.Responses.ResponseCreateParamsNonStreaming;
|
|
17
|
-
protected convertFromToolChoice(toolChoice: Tool.Choice<fdm>): OpenAI.Responses.ToolChoiceOptions | OpenAI.Responses.ToolChoiceAllowed;
|
|
16
|
+
constructor(ctx: Transport.Context<fdm, vdm>);
|
|
17
|
+
protected makeParams(session: Session.From<fdm, vdm>): OpenAI.Responses.ResponseCreateParamsNonStreaming;
|
|
18
18
|
protected logAiMessage(output: OpenAI.Responses.ResponseOutputItem[]): void;
|
|
19
|
-
|
|
20
|
-
fetch(wfctx: InferenceContext, session: Session<fdm>, signal?: AbortSignal): Promise<RoleMessage.Ai<fdm>>;
|
|
19
|
+
fetch(wfctx: InferenceContext, session: Session.From<fdm, vdm>, signal?: AbortSignal): Promise<RoleMessage.Ai.From<fdm, vdm>>;
|
|
21
20
|
}
|
|
22
|
-
export declare namespace
|
|
23
|
-
interface Context<fdm extends Function.
|
|
21
|
+
export declare namespace Transport {
|
|
22
|
+
interface Context<in out fdm extends Function.Decl.Map.Proto, in out vdm extends Verbatim.Decl.Map.Proto> {
|
|
24
23
|
inferenceParams: InferenceParams;
|
|
25
24
|
providerSpec: ProviderSpec;
|
|
26
25
|
fdm: fdm;
|
|
27
26
|
throttle: Throttle;
|
|
28
|
-
|
|
27
|
+
choice: Structuring.Choice.From<fdm, vdm>;
|
|
29
28
|
parallelToolCall: boolean;
|
|
30
29
|
applyPatch: boolean;
|
|
31
|
-
messageCodec:
|
|
32
|
-
toolCodec:
|
|
33
|
-
billing:
|
|
34
|
-
|
|
30
|
+
messageCodec: MessageCodec<fdm, vdm>;
|
|
31
|
+
toolCodec: ToolCodec<fdm>;
|
|
32
|
+
billing: Billing;
|
|
33
|
+
validator: Validator.From<fdm, vdm>;
|
|
35
34
|
}
|
|
36
35
|
}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import { ResponseInvalid } from
|
|
2
|
-
import { RoleMessage } from '#@/native-engines.d/openai-responses/session.ts';
|
|
3
|
-
import { Function } from '#@/function.ts';
|
|
4
|
-
import { Tool } from '#@/native-engines.d/openai-responses/tool.ts';
|
|
5
|
-
import OpenAI from 'openai';
|
|
1
|
+
import { NetworkError, ResponseInvalid } from "../../engine.js";
|
|
6
2
|
import * as Undici from 'undici';
|
|
7
|
-
import {} from
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
export class OpenAIResponsesNativeTransport {
|
|
3
|
+
import { logger } from "../../telemetry.js";
|
|
4
|
+
import * as ChoiceCodec from "./choice-codec.js";
|
|
5
|
+
export class Transport {
|
|
11
6
|
ctx;
|
|
12
7
|
apiURL;
|
|
13
8
|
constructor(ctx) {
|
|
@@ -15,41 +10,22 @@ export class OpenAIResponsesNativeTransport {
|
|
|
15
10
|
this.apiURL = new URL(`${this.ctx.providerSpec.baseUrl}/responses`);
|
|
16
11
|
}
|
|
17
12
|
makeParams(session) {
|
|
18
|
-
const tools = this.ctx.toolCodec.
|
|
13
|
+
const tools = this.ctx.toolCodec.encodeFunctionDeclarationMap(this.ctx.fdm);
|
|
19
14
|
if (this.ctx.applyPatch)
|
|
20
15
|
tools.push({ type: 'apply_patch' });
|
|
21
16
|
return {
|
|
22
17
|
model: this.ctx.inferenceParams.model,
|
|
23
18
|
include: ['reasoning.encrypted_content'],
|
|
24
19
|
store: false,
|
|
25
|
-
input: session.chatMessages.flatMap(chatMessage => this.ctx.messageCodec.
|
|
26
|
-
instructions: session.developerMessage && this.ctx.messageCodec.
|
|
20
|
+
input: session.chatMessages.flatMap(chatMessage => this.ctx.messageCodec.encodeChatMessage(chatMessage)),
|
|
21
|
+
instructions: session.developerMessage && this.ctx.messageCodec.encodeDeveloperMessage(session.developerMessage),
|
|
27
22
|
tools: tools.length ? tools : undefined,
|
|
28
|
-
tool_choice: tools.length ?
|
|
23
|
+
tool_choice: tools.length ? ChoiceCodec.encode(this.ctx.choice) : undefined,
|
|
29
24
|
parallel_tool_calls: tools.length ? this.ctx.parallelToolCall : undefined,
|
|
30
25
|
max_output_tokens: this.ctx.inferenceParams.maxTokens,
|
|
31
26
|
...this.ctx.inferenceParams.additionalOptions,
|
|
32
27
|
};
|
|
33
28
|
}
|
|
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 => {
|
|
46
|
-
if (name === Tool.Choice.APPLY_PATCH)
|
|
47
|
-
return { type: 'apply_patch' };
|
|
48
|
-
else
|
|
49
|
-
return { type: 'function', name };
|
|
50
|
-
}),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
29
|
logAiMessage(output) {
|
|
54
30
|
for (const item of output)
|
|
55
31
|
if (item.type === 'message') {
|
|
@@ -63,10 +39,12 @@ export class OpenAIResponsesNativeTransport {
|
|
|
63
39
|
else if (item.type === 'apply_patch_call')
|
|
64
40
|
logger.message.debug(item);
|
|
65
41
|
}
|
|
66
|
-
async
|
|
42
|
+
async fetch(wfctx, session, signal) {
|
|
43
|
+
await this.ctx.throttle.requests(wfctx);
|
|
44
|
+
// Prepare request
|
|
67
45
|
const params = this.makeParams(session);
|
|
68
46
|
logger.message.trace(params);
|
|
69
|
-
|
|
47
|
+
// Send request
|
|
70
48
|
const res = await Undici.fetch(this.apiURL, {
|
|
71
49
|
method: 'POST',
|
|
72
50
|
headers: new Headers({
|
|
@@ -76,29 +54,31 @@ export class OpenAIResponsesNativeTransport {
|
|
|
76
54
|
body: JSON.stringify(params),
|
|
77
55
|
dispatcher: this.ctx.providerSpec.proxyAgent,
|
|
78
56
|
signal,
|
|
57
|
+
}).catch(e => {
|
|
58
|
+
if (e instanceof TypeError)
|
|
59
|
+
throw new NetworkError(undefined, { cause: e });
|
|
60
|
+
else
|
|
61
|
+
throw e;
|
|
79
62
|
});
|
|
63
|
+
// Get response
|
|
80
64
|
if (res.ok) { }
|
|
81
65
|
else
|
|
82
66
|
throw new Error(undefined, { cause: res });
|
|
83
67
|
const response = await res.json();
|
|
84
68
|
logger.message.trace(response);
|
|
69
|
+
// Validate response
|
|
85
70
|
if (response.status === 'incomplete' && response.incomplete_details?.reason === 'max_output_tokens')
|
|
86
71
|
throw new ResponseInvalid('Token limit exceeded.', { cause: response });
|
|
87
72
|
if (response.status === 'completed') { }
|
|
88
73
|
else
|
|
89
74
|
throw new ResponseInvalid('Abnormal response status', { cause: response });
|
|
90
|
-
this.logAiMessage(response.output);
|
|
91
75
|
if (response.usage) { }
|
|
92
76
|
else
|
|
93
77
|
throw new Error();
|
|
78
|
+
this.logAiMessage(response.output);
|
|
94
79
|
wfctx.cost?.(this.ctx.billing.charge(response.usage));
|
|
95
80
|
logger.message.debug(response.usage);
|
|
96
|
-
|
|
97
|
-
this.ctx.toolCallValidator.validate(aiMessage.getToolCalls());
|
|
98
|
-
return aiMessage;
|
|
99
|
-
}
|
|
100
|
-
async fetch(wfctx, session, signal) {
|
|
101
|
-
return await this.fetchRaw(wfctx, session, signal).catch(e => Promise.reject(e instanceof OpenAI.APIError ? new ResponseInvalid(undefined, { cause: e }) : e));
|
|
81
|
+
return this.ctx.messageCodec.decodeAiMessage(response.output);
|
|
102
82
|
}
|
|
103
83
|
}
|
|
104
84
|
//# sourceMappingURL=transport.js.map
|