@zimtsui/brainswitch 0.0.56 → 0.0.57
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 +10 -9
- 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
package/build/engine.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { Function } from '
|
|
2
|
-
import { EndpointSpec } from '
|
|
3
|
-
import { Throttle } from '
|
|
1
|
+
import { Function } from './function.ts';
|
|
2
|
+
import { EndpointSpec } from './endpoint-spec.ts';
|
|
3
|
+
import { Throttle } from './throttle.ts';
|
|
4
4
|
import { ProxyAgent } from 'undici';
|
|
5
|
-
import { type InferenceContext } from '
|
|
6
|
-
import
|
|
5
|
+
import { type InferenceContext } from './inference-context.ts';
|
|
6
|
+
import * as SessionModule from './engine/session.ts';
|
|
7
|
+
import type { Verbatim } from './verbatim.ts';
|
|
8
|
+
import * as ValidationModule from './engine/validation.ts';
|
|
9
|
+
import * as TransportModule from './engine/transport.ts';
|
|
7
10
|
export interface Pricing {
|
|
8
11
|
inputPrice: number;
|
|
9
12
|
cachePrice: number;
|
|
@@ -20,50 +23,56 @@ export interface InferenceParams {
|
|
|
20
23
|
maxTokens?: number;
|
|
21
24
|
timeout?: number;
|
|
22
25
|
}
|
|
23
|
-
export
|
|
24
|
-
protected providerSpec: ProviderSpec;
|
|
25
|
-
protected inferenceParams: InferenceParams;
|
|
26
|
-
name: string;
|
|
27
|
-
pricing: Pricing;
|
|
28
|
-
fdm: fdm;
|
|
29
|
-
protected throttle: Throttle;
|
|
30
|
-
protected abstract parallelToolCall: boolean;
|
|
31
|
-
constructor(options: Engine.Options<fdm>);
|
|
32
|
-
protected abstract infer(wfctx: InferenceContext, session: session, signal?: AbortSignal): Promise<aim>;
|
|
33
|
-
/**
|
|
34
|
-
* @throws {@link UserAbortion} 用户中止
|
|
35
|
-
* @throws {@link InferenceTimeout} 推理超时
|
|
36
|
-
* @throws {@link ResponseInvalid} 模型抽风
|
|
37
|
-
* @throws {TypeError} 网络故障
|
|
38
|
-
*/
|
|
39
|
-
stateless(wfctx: InferenceContext, session: session): Promise<aim>;
|
|
40
|
-
/**
|
|
41
|
-
* @param session mutable
|
|
42
|
-
*/
|
|
43
|
-
stateful(wfctx: InferenceContext, session: session): Promise<aim>;
|
|
44
|
-
abstract appendUserMessage(session: session, message: userm): session;
|
|
45
|
-
/**
|
|
46
|
-
* @param session mutable
|
|
47
|
-
*/
|
|
48
|
-
abstract pushUserMessage(session: session, message: userm): session;
|
|
49
|
-
}
|
|
26
|
+
export type Engine<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto, userm, aim, devm, session extends Engine.Session<userm, aim, devm>> = Engine.Instance<fdm, vdm, userm, aim, devm, session>;
|
|
50
27
|
export declare namespace Engine {
|
|
51
|
-
|
|
52
|
-
|
|
28
|
+
abstract class Instance<in out fdm extends Function.Decl.Map.Proto, in out vdm extends Verbatim.Decl.Map.Proto, in out userm, in out aim, in out devm, in out session extends Engine.Session<userm, aim, devm>> {
|
|
29
|
+
protected providerSpec: ProviderSpec;
|
|
30
|
+
protected inferenceParams: InferenceParams;
|
|
31
|
+
name: string;
|
|
32
|
+
pricing: Pricing;
|
|
33
|
+
fdm: fdm;
|
|
34
|
+
vdm: vdm;
|
|
35
|
+
protected throttle: Throttle;
|
|
36
|
+
protected abstract parallelToolCall: boolean;
|
|
37
|
+
protected abstract validator: Engine.Validator.From<fdm, vdm, aim>;
|
|
38
|
+
protected abstract transport: Engine.Transport<userm, aim, devm, session>;
|
|
39
|
+
constructor(options: Engine.Options<fdm, vdm>);
|
|
40
|
+
protected infer(wfctx: InferenceContext, session: session, signal?: AbortSignal): Promise<aim>;
|
|
41
|
+
/**
|
|
42
|
+
* @throws {@link UserAbortion} 用户中止
|
|
43
|
+
* @throws {@link InferenceTimeout} 推理超时
|
|
44
|
+
* @throws {@link ResponseInvalid} 模型抽风
|
|
45
|
+
* @throws {@link NetworkError} 网络故障
|
|
46
|
+
*/
|
|
47
|
+
stateless(wfctx: InferenceContext, session: session): Promise<aim>;
|
|
48
|
+
/**
|
|
49
|
+
* @param session mutable
|
|
50
|
+
*/
|
|
51
|
+
stateful(wfctx: InferenceContext, session: session): Promise<aim>;
|
|
52
|
+
abstract appendUserMessage(session: session, message: userm): session;
|
|
53
|
+
/**
|
|
54
|
+
* @param session mutable
|
|
55
|
+
*/
|
|
56
|
+
abstract pushUserMessage(session: session, message: userm): session;
|
|
53
57
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
interface Options<in out fdm extends Function.Decl.Map.Proto, in out vdm extends Verbatim.Decl.Map.Proto> extends EndpointSpec {
|
|
59
|
+
throttle: Throttle;
|
|
60
|
+
functionDeclarationMap: fdm;
|
|
61
|
+
verbatimDeclarationMap: vdm;
|
|
62
|
+
parallelToolCall?: boolean;
|
|
59
63
|
}
|
|
64
|
+
export import Session = SessionModule.Session;
|
|
65
|
+
export import Validator = ValidationModule.Validator;
|
|
66
|
+
export import Transport = TransportModule.Transport;
|
|
60
67
|
}
|
|
61
68
|
export declare class ResponseInvalid extends Error {
|
|
62
69
|
}
|
|
63
|
-
export declare class UserAbortion {
|
|
70
|
+
export declare class UserAbortion extends Error {
|
|
64
71
|
}
|
|
65
72
|
export declare class InferenceTimeout extends Error {
|
|
66
73
|
}
|
|
74
|
+
export declare class NetworkError extends Error {
|
|
75
|
+
}
|
|
67
76
|
declare global {
|
|
68
77
|
export namespace NodeJS {
|
|
69
78
|
interface ProcessEnv {
|
package/build/engine.js
CHANGED
|
@@ -1,86 +1,104 @@
|
|
|
1
|
-
import { Function } from '#@/function.ts';
|
|
2
|
-
import { EndpointSpec } from '#@/endpoint-spec.ts';
|
|
3
|
-
import { Throttle } from '#@/throttle.ts';
|
|
4
1
|
import { ProxyAgent } from 'undici';
|
|
5
2
|
import { env } from 'node:process';
|
|
6
|
-
import {} from
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
inputPrice
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
* @throws {TypeError} 网络故障
|
|
44
|
-
*/
|
|
45
|
-
async stateless(wfctx, session) {
|
|
46
|
-
for (let retry = 0;; retry++) {
|
|
47
|
-
const signalTimeout = this.inferenceParams.timeout ? AbortSignal.timeout(this.inferenceParams.timeout) : undefined;
|
|
48
|
-
const signal = wfctx.signal && signalTimeout ? AbortSignal.any([
|
|
49
|
-
wfctx.signal,
|
|
50
|
-
signalTimeout,
|
|
51
|
-
]) : wfctx.signal || signalTimeout;
|
|
3
|
+
import { logger } from "./telemetry.js";
|
|
4
|
+
import * as VerbatimCodec from "./verbatim/codec.js";
|
|
5
|
+
export var Engine;
|
|
6
|
+
(function (Engine) {
|
|
7
|
+
class Instance {
|
|
8
|
+
providerSpec;
|
|
9
|
+
inferenceParams;
|
|
10
|
+
name;
|
|
11
|
+
pricing;
|
|
12
|
+
fdm;
|
|
13
|
+
vdm;
|
|
14
|
+
throttle;
|
|
15
|
+
constructor(options) {
|
|
16
|
+
const proxyUrl = options.proxy || env.https_proxy || env.HTTPS_PROXY;
|
|
17
|
+
this.providerSpec = {
|
|
18
|
+
baseUrl: options.baseUrl,
|
|
19
|
+
apiKey: options.apiKey,
|
|
20
|
+
proxyAgent: proxyUrl ? new ProxyAgent(proxyUrl) : undefined,
|
|
21
|
+
};
|
|
22
|
+
this.name = options.name;
|
|
23
|
+
this.inferenceParams = {
|
|
24
|
+
model: options.model,
|
|
25
|
+
additionalOptions: options.additionalOptions,
|
|
26
|
+
timeout: options.timeout,
|
|
27
|
+
maxTokens: options.maxTokens,
|
|
28
|
+
};
|
|
29
|
+
const inputPrice = options.inputPrice ?? 0;
|
|
30
|
+
this.pricing = {
|
|
31
|
+
inputPrice,
|
|
32
|
+
outputPrice: options.outputPrice ?? 0,
|
|
33
|
+
cachePrice: options.cachePrice ?? inputPrice,
|
|
34
|
+
};
|
|
35
|
+
this.fdm = options.functionDeclarationMap;
|
|
36
|
+
this.vdm = options.verbatimDeclarationMap;
|
|
37
|
+
this.throttle = options.throttle;
|
|
38
|
+
}
|
|
39
|
+
async infer(wfctx, session, signal) {
|
|
52
40
|
try {
|
|
53
|
-
|
|
41
|
+
const aiMessage = await this.transport.fetch(wfctx, session, signal);
|
|
42
|
+
this.validator.validateParts(aiMessage);
|
|
43
|
+
this.validator.validateChoice(aiMessage);
|
|
44
|
+
return aiMessage;
|
|
54
45
|
}
|
|
55
46
|
catch (e) {
|
|
56
|
-
if (
|
|
57
|
-
throw new
|
|
58
|
-
else if (signalTimeout?.aborted)
|
|
59
|
-
e = new InferenceTimeout(undefined, { cause: e }); // 推理超时
|
|
60
|
-
else if (e instanceof ResponseInvalid) { } // 模型抽风
|
|
61
|
-
else if (e instanceof TypeError) { } // 网络故障
|
|
62
|
-
else
|
|
63
|
-
throw e;
|
|
64
|
-
if (retry < 3)
|
|
65
|
-
logger.message.warn(e);
|
|
47
|
+
if (e instanceof VerbatimCodec.Request.Invalid)
|
|
48
|
+
throw new ResponseInvalid('Invalid verbatim message', { cause: e });
|
|
66
49
|
else
|
|
67
50
|
throw e;
|
|
68
51
|
}
|
|
69
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* @throws {@link UserAbortion} 用户中止
|
|
55
|
+
* @throws {@link InferenceTimeout} 推理超时
|
|
56
|
+
* @throws {@link ResponseInvalid} 模型抽风
|
|
57
|
+
* @throws {@link NetworkError} 网络故障
|
|
58
|
+
*/
|
|
59
|
+
async stateless(wfctx, session) {
|
|
60
|
+
for (let retry = 0;; retry++) {
|
|
61
|
+
const signalTimeout = this.inferenceParams.timeout ? AbortSignal.timeout(this.inferenceParams.timeout) : undefined;
|
|
62
|
+
const signal = wfctx.signal && signalTimeout ? AbortSignal.any([
|
|
63
|
+
wfctx.signal,
|
|
64
|
+
signalTimeout,
|
|
65
|
+
]) : wfctx.signal || signalTimeout;
|
|
66
|
+
try {
|
|
67
|
+
return await this.infer(wfctx, session, signal);
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
if (wfctx.signal?.aborted)
|
|
71
|
+
throw new UserAbortion(); // 用户中止
|
|
72
|
+
else if (signalTimeout?.aborted)
|
|
73
|
+
e = new InferenceTimeout(undefined, { cause: e }); // 推理超时
|
|
74
|
+
else if (e instanceof ResponseInvalid) { } // 模型抽风
|
|
75
|
+
else if (e instanceof NetworkError) { } // 网络故障
|
|
76
|
+
else
|
|
77
|
+
throw e;
|
|
78
|
+
if (retry < 3)
|
|
79
|
+
logger.message.warn(e);
|
|
80
|
+
else
|
|
81
|
+
throw e;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @param session mutable
|
|
87
|
+
*/
|
|
88
|
+
async stateful(wfctx, session) {
|
|
89
|
+
const response = await this.stateless(wfctx, session);
|
|
90
|
+
session.chatMessages.push(response);
|
|
91
|
+
return response;
|
|
92
|
+
}
|
|
70
93
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
*/
|
|
74
|
-
async stateful(wfctx, session) {
|
|
75
|
-
const response = await this.stateless(wfctx, session);
|
|
76
|
-
session.chatMessages.push(response);
|
|
77
|
-
return response;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
94
|
+
Engine.Instance = Instance;
|
|
95
|
+
})(Engine || (Engine = {}));
|
|
80
96
|
export class ResponseInvalid extends Error {
|
|
81
97
|
}
|
|
82
|
-
export class UserAbortion {
|
|
98
|
+
export class UserAbortion extends Error {
|
|
83
99
|
}
|
|
84
100
|
export class InferenceTimeout extends Error {
|
|
85
101
|
}
|
|
102
|
+
export class NetworkError extends Error {
|
|
103
|
+
}
|
|
86
104
|
//# sourceMappingURL=engine.js.map
|
package/build/engine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"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"}
|
package/build/exports.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export * from '
|
|
3
|
-
export * from '
|
|
4
|
-
export * from '
|
|
5
|
-
export * from '
|
|
6
|
-
export * from '
|
|
7
|
-
export * from '
|
|
8
|
-
export * from '
|
|
9
|
-
export * from '
|
|
10
|
-
export * from '
|
|
11
|
-
export * from '
|
|
12
|
-
export * from '
|
|
13
|
-
export * from '
|
|
14
|
-
export * from '
|
|
1
|
+
export * from './adaptor.ts';
|
|
2
|
+
export * from './throttle.ts';
|
|
3
|
+
export * from './compatible-engine/session.ts';
|
|
4
|
+
export * from './compatible-engine.ts';
|
|
5
|
+
export * from './function.ts';
|
|
6
|
+
export * from './verbatim.ts';
|
|
7
|
+
export * from './compatible-engine/structuring.ts';
|
|
8
|
+
export * from './config.ts';
|
|
9
|
+
export * from './inference-context.ts';
|
|
10
|
+
export * from './endpoint-spec.ts';
|
|
11
|
+
export * from './compatible-engine.d/agentloop.ts';
|
|
12
|
+
export * from './engine.ts';
|
|
13
|
+
export * from './compatible-engine.ts';
|
|
14
|
+
export * from './telemetry.ts';
|
package/build/exports.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
1
|
+
export * from "./adaptor.js";
|
|
2
|
+
export * from "./throttle.js";
|
|
3
|
+
export * from "./compatible-engine/session.js";
|
|
4
|
+
export * from "./compatible-engine.js";
|
|
5
|
+
export * from "./function.js";
|
|
6
|
+
export * from "./verbatim.js";
|
|
7
|
+
export * from "./compatible-engine/structuring.js";
|
|
8
|
+
export * from "./config.js";
|
|
9
|
+
export * from "./inference-context.js";
|
|
10
|
+
export * from "./endpoint-spec.js";
|
|
11
|
+
export * from "./compatible-engine.d/agentloop.js";
|
|
12
|
+
export * from "./engine.js";
|
|
13
|
+
export * from "./compatible-engine.js";
|
|
14
|
+
export * from "./telemetry.js";
|
|
15
15
|
//# sourceMappingURL=exports.js.map
|
package/build/exports.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.js","sourceRoot":"","sources":["../src/exports.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"exports.js","sourceRoot":"","sources":["../src/exports.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,oCAAoC,CAAC;AACnD,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oCAAoC,CAAC;AACnD,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC"}
|
package/build/function.d.ts
CHANGED
|
@@ -1,93 +1,106 @@
|
|
|
1
|
-
import { type Static, type TSchema } from '@sinclair/typebox';
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { type Static, type TObject, type TSchema } from '@sinclair/typebox';
|
|
2
|
+
declare const NOMINAL: unique symbol;
|
|
3
|
+
export interface Function<in out fd extends Function.Decl.Proto> {
|
|
4
|
+
(params: Static<fd['parameters']>): Promise<string>;
|
|
4
5
|
}
|
|
5
6
|
export declare namespace Function {
|
|
6
|
-
|
|
7
|
+
namespace Name {
|
|
8
|
+
type From<fdm extends Function.Decl.Map.Proto> = globalThis.Extract<keyof fdm, string>;
|
|
9
|
+
}
|
|
10
|
+
type Extract<fdm extends Function.Decl.Map.Proto, nameu extends Function.Name.From<fdm>> = Function.Of<Function.Decl.Extract<fdm, nameu>>;
|
|
11
|
+
type Of<fdu extends Function.Decl.Proto> = fdu extends infer fd extends Function.Decl.Proto ? Function<fd> : never;
|
|
12
|
+
interface Decl<in out name extends string, in out params extends Function.Decl.Params.Proto> extends Function.Decl.Body<params> {
|
|
7
13
|
name: name;
|
|
8
14
|
}
|
|
9
|
-
namespace
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
type
|
|
15
|
+
namespace Decl {
|
|
16
|
+
interface Proto extends Function.Decl.Body<Function.Decl.Params.Proto> {
|
|
17
|
+
name: string;
|
|
18
|
+
}
|
|
19
|
+
type Args<params extends Params.Proto> = Static<params>;
|
|
20
|
+
namespace Params {
|
|
21
|
+
type Proto = TObject<Record<string, TSchema>>;
|
|
22
|
+
}
|
|
23
|
+
type Extract<fdm extends Function.Decl.Map.Proto, nameu extends Function.Name.From<fdm>> = nameu extends infer name extends Function.Name.From<fdm> ? Function.Decl<name, fdm[name]['parameters']> : never;
|
|
24
|
+
type From<fdm extends Function.Decl.Map.Proto> = Function.Decl.Extract<fdm, Function.Name.From<fdm>>;
|
|
14
25
|
namespace Map {
|
|
15
|
-
type
|
|
26
|
+
type Proto = Record<string, Body.Prototype>;
|
|
16
27
|
}
|
|
17
|
-
interface
|
|
28
|
+
interface Body<in out params extends Function.Decl.Params.Proto> {
|
|
18
29
|
description?: string;
|
|
19
|
-
|
|
30
|
+
parameters: params;
|
|
20
31
|
}
|
|
21
|
-
namespace
|
|
22
|
-
|
|
32
|
+
namespace Body {
|
|
33
|
+
interface Prototype {
|
|
34
|
+
description?: string;
|
|
35
|
+
parameters: Function.Decl.Params.Proto;
|
|
36
|
+
}
|
|
23
37
|
}
|
|
24
|
-
type Entry<name extends string,
|
|
38
|
+
type Entry<name extends string, params extends Function.Decl.Params.Proto> = [name, Function.Decl.Body<params>];
|
|
25
39
|
namespace Entry {
|
|
26
|
-
type
|
|
40
|
+
type Of<fdu extends Function.Decl.Proto> = fdu extends infer fd extends Function.Decl.Proto ? Entry<fd['name'], fd['parameters']> : never;
|
|
41
|
+
type From<fdm extends Function.Decl.Map.Proto> = Function.Decl.Entry.Of<Function.Decl.From<fdm>>;
|
|
27
42
|
}
|
|
28
43
|
}
|
|
29
|
-
class Call<in out fd extends
|
|
30
|
-
|
|
31
|
-
private readonly [Call.NOMINAL];
|
|
44
|
+
class Call<in out fd extends Function.Decl.Proto> {
|
|
45
|
+
protected [NOMINAL]: never;
|
|
32
46
|
id?: string;
|
|
33
47
|
name: fd['name'];
|
|
34
|
-
args: Static<fd['
|
|
35
|
-
|
|
36
|
-
static
|
|
37
|
-
static restore<fdm extends Declaration.Map>(snapshot: Call.Snapshot.Distributive<fdm>): Call.From<fdm>;
|
|
38
|
-
static capture<fdm extends Declaration.Map>(fc: Call.From<fdm>): Call.Snapshot.Distributive<fdm>;
|
|
48
|
+
args: Static<fd['parameters']>;
|
|
49
|
+
protected constructor(fc: Omit<Call<fd>, never>);
|
|
50
|
+
static of<fdu extends Function.Decl.Proto>(fc: Function.Call.Options.Of<fdu>): Function.Call.Of<fdu>;
|
|
39
51
|
}
|
|
40
52
|
namespace Call {
|
|
41
|
-
type
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
type
|
|
47
|
-
[name in Declaration.Map.NameOf<fdm>]: Snapshot<Declaration.From<fdm, name>>;
|
|
48
|
-
}[Declaration.Map.NameOf<fdm>];
|
|
49
|
-
}
|
|
50
|
-
namespace create {
|
|
51
|
-
type Options<fdm extends Declaration.Map> = {
|
|
52
|
-
[name in Declaration.Map.NameOf<fdm>]: Omit<Call<Declaration.From<fdm, name>>, never>;
|
|
53
|
-
}[Declaration.Map.NameOf<fdm>];
|
|
53
|
+
type Of<fdu extends Function.Decl.Proto> = fdu extends infer fd extends Function.Decl.Proto ? Function.Call<fd> : never;
|
|
54
|
+
type From<fdm extends Function.Decl.Map.Proto> = Function.Call.Of<Function.Decl.From<fdm>>;
|
|
55
|
+
type Options<fd extends Function.Decl.Proto> = Omit<Function.Call<fd>, never>;
|
|
56
|
+
namespace Options {
|
|
57
|
+
type Of<fdu extends Function.Decl.Proto> = fdu extends infer fd extends Function.Decl.Proto ? Options<fd> : never;
|
|
58
|
+
type From<fdm extends Function.Decl.Map.Proto> = Function.Call.Options.Of<Function.Decl.From<fdm>>;
|
|
54
59
|
}
|
|
55
|
-
function validate<fdm extends Function.Declaration.Map>(toolCalls: Function.Call.From<fdm>[], toolChoice: Function.ToolChoice<fdm>, e: Error): void;
|
|
56
60
|
}
|
|
57
|
-
class Response<in out fd extends
|
|
58
|
-
static readonly NOMINAL: unique symbol;
|
|
59
|
-
private readonly [Response.NOMINAL];
|
|
61
|
+
abstract class Response<in out fd extends Function.Decl.Proto> {
|
|
60
62
|
id?: string;
|
|
61
63
|
name: fd['name'];
|
|
62
|
-
|
|
63
|
-
private constructor();
|
|
64
|
-
static create<fdm extends Declaration.Map>(fr: Response.create.Options<fdm>): Response.Distributive<fdm>;
|
|
65
|
-
static capture<fdm extends Declaration.Map>(response: Response.Distributive<fdm>): Response.Snapshot.Distributive<fdm>;
|
|
66
|
-
static restore<fdm extends Declaration.Map>(snapshot: Response.Snapshot.Distributive<fdm>): Response.Distributive<fdm>;
|
|
64
|
+
protected constructor(fr: Omit<Function.Response<fd>, never>);
|
|
67
65
|
}
|
|
68
66
|
namespace Response {
|
|
69
|
-
type
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
type Of<fdu extends Function.Decl.Proto> = fdu extends infer fd extends Function.Decl.Proto ? Function.Response<fd> : never;
|
|
68
|
+
type From<fdm extends Function.Decl.Map.Proto> = Function.Response.Of<Function.Decl.From<fdm>>;
|
|
69
|
+
class Successful<in out fd extends Function.Decl.Proto> extends Function.Response<fd> {
|
|
70
|
+
protected [NOMINAL]: never;
|
|
71
|
+
text: string;
|
|
72
|
+
protected constructor(fr: Function.Response.Successful.Options<fd>);
|
|
73
|
+
static of<fdu extends Function.Decl.Proto>(fr: Function.Response.Successful.Options.Of<fdu>): Function.Response.Successful.Of<fdu>;
|
|
74
74
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
namespace Successful {
|
|
76
|
+
type Of<fdu extends Function.Decl.Proto> = fdu extends infer fd extends Function.Decl.Proto ? Function.Response.Successful<fd> : never;
|
|
77
|
+
type From<fdm extends Function.Decl.Map.Proto> = Function.Response.Successful.Of<Function.Decl.From<fdm>>;
|
|
78
|
+
type Options<fd extends Function.Decl.Proto> = Omit<Function.Response.Successful<fd>, never>;
|
|
79
|
+
namespace Options {
|
|
80
|
+
type Of<fdu extends Function.Decl.Proto> = fdu extends infer fd extends Function.Decl.Proto ? Options<fd> : never;
|
|
81
|
+
type From<fdm extends Function.Decl.Map.Proto> = Function.Response.Successful.Options.Of<Function.Decl.From<fdm>>;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
class Failed<in out fd extends Function.Decl.Proto> extends Function.Response<fd> {
|
|
85
|
+
protected [NOMINAL]: never;
|
|
86
|
+
error: string;
|
|
87
|
+
protected constructor(fr: Function.Response.Failed.Options<fd>);
|
|
88
|
+
static of<fdu extends Function.Decl.Proto>(fr: Function.Response.Failed.Options.Of<fdu>): Function.Response.Failed.Of<fdu>;
|
|
89
|
+
}
|
|
90
|
+
namespace Failed {
|
|
91
|
+
type Options<fd extends Function.Decl.Proto> = Omit<Function.Response.Failed<fd>, never>;
|
|
92
|
+
namespace Options {
|
|
93
|
+
type Of<fdu extends Function.Decl.Proto> = fdu extends infer fd extends Function.Decl.Proto ? Options<fd> : never;
|
|
94
|
+
type From<fdm extends Function.Decl.Map.Proto> = Function.Response.Failed.Options.Of<Function.Decl.From<fdm>>;
|
|
95
|
+
}
|
|
96
|
+
type Of<fdu extends Function.Decl.Proto> = fdu extends infer fd extends Function.Decl.Proto ? Function.Response.Failed<fd> : never;
|
|
97
|
+
type From<fdm extends Function.Decl.Map.Proto> = Function.Response.Failed.Of<Function.Decl.From<fdm>>;
|
|
82
98
|
}
|
|
83
99
|
}
|
|
84
|
-
type
|
|
85
|
-
|
|
86
|
-
const NONE: unique symbol;
|
|
87
|
-
const REQUIRED: unique symbol;
|
|
88
|
-
const AUTO: unique symbol;
|
|
89
|
-
}
|
|
90
|
-
type Map<fdm extends Function.Declaration.Map> = {
|
|
91
|
-
[name in Function.Declaration.Map.NameOf<fdm>]: Function<Function.Declaration.From<fdm, name>>;
|
|
100
|
+
type Map<fdm extends Function.Decl.Map.Proto> = {
|
|
101
|
+
[name in Function.Name.From<fdm>]: Function<Function.Decl.Extract<fdm, name>>;
|
|
92
102
|
};
|
|
103
|
+
class Error extends globalThis.Error {
|
|
104
|
+
}
|
|
93
105
|
}
|
|
106
|
+
export {};
|