@zimtsui/typechat 0.0.126 → 0.0.127
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/adaptor.d.ts +0 -10
- package/build/adaptor.js +0 -32
- package/build/adaptor.js.map +1 -1
- package/build/engine/exceptions.d.ts +7 -7
- package/build/engine/exceptions.js.map +1 -1
- package/build/engine/message-validator.d.ts +9 -0
- package/build/engine/message-validator.js +28 -0
- package/build/engine/message-validator.js.map +1 -0
- package/build/engine/message.d.ts +33 -31
- package/build/engine/message.js +26 -75
- package/build/engine/message.js.map +1 -1
- package/build/engine/middleware.d.ts +2 -2
- package/build/engine/session.d.ts +4 -4
- package/build/engine/tool-choice-validator.d.ts +2 -2
- package/build/engine/tool-choice-validator.js +18 -21
- package/build/engine/tool-choice-validator.js.map +1 -1
- package/build/engine/transport.d.ts +2 -2
- package/build/engine.d.ts +11 -11
- package/build/engine.js +29 -56
- package/build/engine.js.map +1 -1
- package/build/engines/anthropic/message-codec.d.ts +9 -5
- package/build/engines/anthropic/message-codec.js +37 -35
- package/build/engines/anthropic/message-codec.js.map +1 -1
- package/build/engines/anthropic/tool-codec.d.ts +3 -3
- package/build/engines/anthropic/tool-codec.js +45 -14
- package/build/engines/anthropic/tool-codec.js.map +1 -1
- package/build/engines/anthropic/transport.d.ts +1 -2
- package/build/engines/anthropic/transport.js +1 -1
- package/build/engines/anthropic/transport.js.map +1 -1
- package/build/engines/anthropic.d.ts +0 -3
- package/build/engines/anthropic.js +1 -8
- package/build/engines/anthropic.js.map +1 -1
- package/build/engines/google/message-codec.d.ts +10 -7
- package/build/engines/google/message-codec.js +50 -70
- package/build/engines/google/message-codec.js.map +1 -1
- package/build/engines/google/tool-codec.d.ts +2 -3
- package/build/engines/google/tool-codec.js +51 -22
- package/build/engines/google/tool-codec.js.map +1 -1
- package/build/engines/google/transport.d.ts +1 -8
- package/build/engines/google/transport.js +1 -13
- package/build/engines/google/transport.js.map +1 -1
- package/build/engines/google.d.ts +3 -25
- package/build/engines/google.js +1 -124
- package/build/engines/google.js.map +1 -1
- package/build/engines/openai-chatcompletions/message-codec.d.ts +11 -7
- package/build/engines/openai-chatcompletions/message-codec.js +45 -45
- package/build/engines/openai-chatcompletions/message-codec.js.map +1 -1
- package/build/engines/openai-chatcompletions/tool-codec.d.ts +3 -3
- package/build/engines/openai-chatcompletions/tool-codec.js +31 -31
- package/build/engines/openai-chatcompletions/tool-codec.js.map +1 -1
- package/build/engines/openai-chatcompletions/transport.d.ts +2 -2
- package/build/engines/openai-chatcompletions/transport.js +12 -12
- package/build/engines/openai-chatcompletions/transport.js.map +1 -1
- package/build/engines/openai-chatcompletions.d.ts +0 -3
- package/build/engines/openai-chatcompletions.js +1 -8
- package/build/engines/openai-chatcompletions.js.map +1 -1
- package/build/engines/openai-compatible/message-codec.d.ts +14 -5
- package/build/engines/openai-compatible/message-codec.js +72 -71
- package/build/engines/openai-compatible/message-codec.js.map +1 -1
- package/build/engines/openai-compatible/transport.d.ts +3 -6
- package/build/engines/openai-compatible/transport.js +6 -7
- package/build/engines/openai-compatible/transport.js.map +1 -1
- package/build/engines/openai-compatible.d.ts +0 -3
- package/build/engines/openai-compatible.js +1 -8
- package/build/engines/openai-compatible.js.map +1 -1
- package/build/engines/openai-responses/message-codec.d.ts +12 -5
- package/build/engines/openai-responses/message-codec.js +72 -88
- package/build/engines/openai-responses/message-codec.js.map +1 -1
- package/build/engines/openai-responses/tool-codec.d.ts +5 -3
- package/build/engines/openai-responses/tool-codec.js +43 -28
- package/build/engines/openai-responses/tool-codec.js.map +1 -1
- package/build/engines/openai-responses/transport.d.ts +2 -6
- package/build/engines/openai-responses/transport.js +1 -7
- package/build/engines/openai-responses/transport.js.map +1 -1
- package/build/engines/openai-responses.d.ts +3 -24
- package/build/engines/openai-responses.js +1 -111
- package/build/engines/openai-responses.js.map +1 -1
- package/build/exports/xml.d.ts +2 -2
- package/build/exports/xml.js +2 -2
- package/build/exports/xml.js.map +1 -1
- package/build/exports.d.ts +1 -5
- package/build/exports.js +1 -5
- package/build/exports.js.map +1 -1
- package/build/function.d.ts +4 -2
- package/build/function.js +2 -2
- package/build/function.js.map +1 -1
- package/build/media.d.ts +2 -2
- package/build/media.js +5 -5
- package/build/media.js.map +1 -1
- package/build/text.d.ts +8 -0
- package/build/text.js +11 -0
- package/build/text.js.map +1 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/DEVELOPMENT.md +0 -11
- package/build/engine/parts-validator.d.ts +0 -8
- package/build/engine/parts-validator.js +0 -12
- package/build/engine/parts-validator.js.map +0 -1
- package/build/engines/anthropic/message.d.ts +0 -19
- package/build/engines/anthropic/message.js +0 -20
- package/build/engines/anthropic/message.js.map +0 -1
- package/build/engines/google/message.d.ts +0 -36
- package/build/engines/google/message.js +0 -58
- package/build/engines/google/message.js.map +0 -1
- package/build/engines/openai-chatcompletions/message.d.ts +0 -19
- package/build/engines/openai-chatcompletions/message.js +0 -20
- package/build/engines/openai-chatcompletions/message.js.map +0 -1
- package/build/engines/openai-compatible/message.d.ts +0 -19
- package/build/engines/openai-compatible/message.js +0 -20
- package/build/engines/openai-compatible/message.js.map +0 -1
- package/build/engines/openai-responses/message.d.ts +0 -22
- package/build/engines/openai-responses/message.js +0 -38
- package/build/engines/openai-responses/message.js.map +0 -1
- package/build/engines/openai-responses/tool-choice-validator.d.ts +0 -11
- package/build/engines/openai-responses/tool-choice-validator.js +0 -50
- package/build/engines/openai-responses/tool-choice-validator.js.map +0 -1
- package/build/engines/openai-responses/tool.d.ts +0 -53
- package/build/engines/openai-responses/tool.js +0 -24
- package/build/engines/openai-responses/tool.js.map +0 -1
package/build/adaptor.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Config } from './config.ts';
|
|
2
2
|
import { Function } from './function.ts';
|
|
3
3
|
import { Throttle } from './throttle.ts';
|
|
4
|
-
import { GoogleEngine } from './engines/google.ts';
|
|
5
|
-
import { OpenAIResponsesEngine } from './engines/openai-responses.ts';
|
|
6
4
|
import { Engine } from './engine.ts';
|
|
7
5
|
export declare class Adaptor {
|
|
8
6
|
config: Config;
|
|
@@ -10,17 +8,9 @@ export declare class Adaptor {
|
|
|
10
8
|
protected throttles: Map<string, Throttle>;
|
|
11
9
|
protected constructor(config: Config);
|
|
12
10
|
makeEngine<fdm extends Function.Decl.Map.Proto>(adaptorOptions: Adaptor.Params<fdm>): Engine<fdm>;
|
|
13
|
-
makeGoogleEngine<fdm extends Function.Decl.Map.Proto>(adaptorOptions: Adaptor.GoogleParams<fdm>): GoogleEngine<fdm>;
|
|
14
|
-
makeOpenAIResponsesEngine<fdm extends Function.Decl.Map.Proto>(adaptorOptions: Adaptor.OpenAIResponsesParams<fdm>): OpenAIResponsesEngine<fdm>;
|
|
15
11
|
}
|
|
16
12
|
export declare namespace Adaptor {
|
|
17
13
|
interface Params<in out fdm extends Function.Decl.Map.Proto> extends Omit<Engine.Options<fdm>, 'endpointSpec' | 'throttle'> {
|
|
18
14
|
endpoint: string;
|
|
19
15
|
}
|
|
20
|
-
interface GoogleParams<in out fdm extends Function.Decl.Map.Proto> extends Omit<GoogleEngine.Options<fdm>, 'endpointSpec' | 'throttle'> {
|
|
21
|
-
endpoint: string;
|
|
22
|
-
}
|
|
23
|
-
interface OpenAIResponsesParams<in out fdm extends Function.Decl.Map.Proto> extends Omit<OpenAIResponsesEngine.Options<fdm>, 'endpointSpec' | 'throttle'> {
|
|
24
|
-
endpoint: string;
|
|
25
|
-
}
|
|
26
16
|
}
|
package/build/adaptor.js
CHANGED
|
@@ -44,37 +44,5 @@ export class Adaptor {
|
|
|
44
44
|
else
|
|
45
45
|
throw new Error();
|
|
46
46
|
}
|
|
47
|
-
makeGoogleEngine(adaptorOptions) {
|
|
48
|
-
const endpointSpec = this.config.endpoints[adaptorOptions.endpoint];
|
|
49
|
-
if (endpointSpec?.apiType === 'google') { }
|
|
50
|
-
else
|
|
51
|
-
throw new Error();
|
|
52
|
-
const throttle = this.throttles.get(adaptorOptions.endpoint);
|
|
53
|
-
if (throttle) { }
|
|
54
|
-
else
|
|
55
|
-
throw new Error();
|
|
56
|
-
const options = {
|
|
57
|
-
...adaptorOptions,
|
|
58
|
-
endpointSpec,
|
|
59
|
-
throttle,
|
|
60
|
-
};
|
|
61
|
-
return new GoogleEngine.Instance(options);
|
|
62
|
-
}
|
|
63
|
-
makeOpenAIResponsesEngine(adaptorOptions) {
|
|
64
|
-
const endpointSpec = this.config.endpoints[adaptorOptions.endpoint];
|
|
65
|
-
if (endpointSpec?.apiType === 'openai-responses') { }
|
|
66
|
-
else
|
|
67
|
-
throw new Error();
|
|
68
|
-
const throttle = this.throttles.get(adaptorOptions.endpoint);
|
|
69
|
-
if (throttle) { }
|
|
70
|
-
else
|
|
71
|
-
throw new Error();
|
|
72
|
-
const options = {
|
|
73
|
-
...adaptorOptions,
|
|
74
|
-
endpointSpec,
|
|
75
|
-
throttle,
|
|
76
|
-
};
|
|
77
|
-
return new OpenAIResponsesEngine.Instance(options);
|
|
78
|
-
}
|
|
79
47
|
}
|
|
80
48
|
//# sourceMappingURL=adaptor.js.map
|
package/build/adaptor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../src/adaptor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAIxE,MAAM,OAAO,OAAO;IAMa;IALtB,MAAM,CAAC,MAAM,CAAC,MAAc;QAC/B,OAAO,IAAI,OAAO,CAAC,MAAM,CAA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QACpE,IAAI,YAAY,EAAE,CAAC,CAAA,CAAC;;YAAM,MAAM,IAAI,KAAK,EAAE,CAAC;QAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC7D,IAAI,QAAQ,EAAE,CAAC,CAAA,CAAC;;YAAM,MAAM,IAAI,KAAK,EAAE,CAAC;QACxC,MAAM,OAAO,GAAwB;YACjC,GAAG,cAAc;YACjB,YAAY;YACZ,QAAQ;SACX,CAAC;QACF,IAAI,YAAY,CAAC,OAAO,KAAK,kBAAkB;YAC3C,OAAO,qBAAqB,CAAC,YAAY,CAAM,OAAO,CAAC,CAAC;aACvD,IAAI,YAAY,CAAC,OAAO,KAAK,QAAQ;YACtC,OAAO,YAAY,CAAC,YAAY,CAAM,OAAO,CAAC,CAAC;aAC9C,IAAI,YAAY,CAAC,OAAO,KAAK,WAAW;YACzC,OAAO,eAAe,CAAC,YAAY,CAAM,OAAO,CAAC,CAAC;aACjD,IAAI,YAAY,CAAC,OAAO,KAAK,wBAAwB;YACtD,OAAO,2BAA2B,CAAC,YAAY,CAAM,OAAO,CAAC,CAAC;aAC7D,IAAI,YAAY,CAAC,OAAO,KAAK,mBAAmB;YACjD,OAAO,sBAAsB,CAAC,YAAY,CAAM,OAAO,CAAC,CAAC;;YACxD,MAAM,IAAI,KAAK,EAAE,CAAC;IAC3B,CAAC;CACJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Function } from '../function.ts';
|
|
2
2
|
import { type InferenceContext } from '../inference-context.ts';
|
|
3
3
|
import { Session } from './session.ts';
|
|
4
|
-
import {
|
|
4
|
+
import { Message } from './message.ts';
|
|
5
5
|
export declare class InferenceTimeout extends Error {
|
|
6
6
|
}
|
|
7
7
|
export declare class ConnectionError extends Error {
|
|
@@ -10,11 +10,11 @@ export declare class InferenceError extends Error {
|
|
|
10
10
|
}
|
|
11
11
|
export declare namespace InferenceError {
|
|
12
12
|
class Recoverable<in out fdu extends Function.Decl.Proto> extends InferenceError {
|
|
13
|
-
protected response:
|
|
14
|
-
protected rejection:
|
|
15
|
-
constructor(response:
|
|
16
|
-
resume():
|
|
17
|
-
recover():
|
|
18
|
-
static recover<fdu extends Function.Decl.Proto, aim extends
|
|
13
|
+
protected response: Message.Output<fdu>;
|
|
14
|
+
protected rejection: Message.Input<fdu>;
|
|
15
|
+
constructor(response: Message.Output<fdu>, rejection: Message.Input<fdu>, ...rest: ConstructorParameters<typeof InferenceError>);
|
|
16
|
+
resume(): Message.Output<fdu>;
|
|
17
|
+
recover(): Message.Input<fdu>;
|
|
18
|
+
static recover<fdu extends Function.Decl.Proto, aim extends Message.Output<fdu>>(wfctx: InferenceContext, session: Session<fdu>, next: () => Promise<aim>): Promise<aim>;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../../src/engine/exceptions.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,gBAAiB,SAAQ,KAAK;CAAG;AAC9C,MAAM,OAAO,eAAgB,SAAQ,KAAK;CAAG;AAE7C,MAAM,OAAO,cAAe,SAAQ,KAAK;CAAG;AAC5C,WAAiB,cAAc;IAC3B,MAAa,WAEX,SAAQ,cAAc;QAEN;QACA;QAFd,YACc,QAA6B,EAC7B,
|
|
1
|
+
{"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../../src/engine/exceptions.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,gBAAiB,SAAQ,KAAK;CAAG;AAC9C,MAAM,OAAO,eAAgB,SAAQ,KAAK;CAAG;AAE7C,MAAM,OAAO,cAAe,SAAQ,KAAK;CAAG;AAC5C,WAAiB,cAAc;IAC3B,MAAa,WAEX,SAAQ,cAAc;QAEN;QACA;QAFd,YACc,QAA6B,EAC7B,SAA6B,EACvC,GAAG,IAAkD;YAErD,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YAJL,aAAQ,GAAR,QAAQ,CAAqB;YAC7B,cAAS,GAAT,SAAS,CAAoB;QAI3C,CAAC;QACM,MAAM;YACT,OAAO,IAAI,CAAC,QAAQ,CAAC;QACzB,CAAC;QACM,OAAO;YACV,OAAO,IAAI,CAAC,SAAS,CAAC;QAC1B,CAAC;QAEM,MAAM,CAAC,KAAK,CAAC,OAAO,CAIvB,KAAuB,EACvB,OAAqB,EACrB,IAAwB;YAExB,IAAI,CAAC;gBACD,OAAO,MAAM,IAAI,EAAE,CAAC;YACxB,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACT,IAAI,CAAC,YAAY,WAAW,EAAE,CAAC,CAAA,CAAC;;oBAAM,MAAM,CAAC,CAAC;gBAC9C,MAAM,WAAW,GAAG,CAAqB,CAAC;gBAC1C,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC;gBACvE,MAAM,CAAC,CAAC;YACZ,CAAC;QACL,CAAC;KACJ;IAlCY,0BAAW,cAkCvB,CAAA;AACL,CAAC,EApCgB,cAAc,KAAd,cAAc,QAoC9B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Function } from '../function.ts';
|
|
2
|
+
import { Message } from './message.ts';
|
|
3
|
+
export declare class MessageValidator<in out fdu extends Function.Decl.Proto> {
|
|
4
|
+
validateOutputMessage(message: Message.Output<fdu>): void;
|
|
5
|
+
validateInputMessage(message: Message.Input<fdu>): void;
|
|
6
|
+
}
|
|
7
|
+
export declare namespace MessageValidator {
|
|
8
|
+
type From<fdm extends Function.Decl.Map.Proto> = MessageValidator<Function.Decl.From<fdm>>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Function } from "../function.js";
|
|
2
|
+
import { isRepeating } from "../repetition.js";
|
|
3
|
+
import * as Exceptions from "./exceptions.js";
|
|
4
|
+
import { Text } from "../text.js";
|
|
5
|
+
import { Media } from "../media.js";
|
|
6
|
+
export class MessageValidator {
|
|
7
|
+
validateOutputMessage(message) {
|
|
8
|
+
if (message.parts.length) { }
|
|
9
|
+
else
|
|
10
|
+
throw new Exceptions.InferenceError('Empty message.');
|
|
11
|
+
if (isRepeating(message.joinText()))
|
|
12
|
+
throw new Exceptions.InferenceError('Repeating');
|
|
13
|
+
}
|
|
14
|
+
validateInputMessage(message) {
|
|
15
|
+
let i = 0;
|
|
16
|
+
for (; i < message.parts.length; i++)
|
|
17
|
+
if (message.parts[i] instanceof Function.Response) { }
|
|
18
|
+
else
|
|
19
|
+
break;
|
|
20
|
+
for (; i < message.parts.length; i++)
|
|
21
|
+
if (message.parts[i] instanceof Text || message.parts[i] instanceof Media) { }
|
|
22
|
+
else
|
|
23
|
+
break;
|
|
24
|
+
if (i < message.parts.length)
|
|
25
|
+
throw new Error();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=message-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-validator.js","sourceRoot":"","sources":["../../src/engine/message-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC,MAAM,OAAO,gBAAgB;IAIlB,qBAAqB,CACxB,OAA4B;QAE5B,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA,CAAC;;YAAM,MAAM,IAAI,UAAU,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC;QACxF,IAAI,WAAW,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YAAE,MAAM,IAAI,UAAU,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;IAC1F,CAAC;IAEM,oBAAoB,CACvB,OAA2B;QAE3B,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,OAAO,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE;YAChC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAE,YAAY,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAA,CAAC;;gBAAM,MAAM;QACtE,OAAO,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE;YAChC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAE,YAAY,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAE,YAAY,KAAK,EAAE,CAAC,CAAA,CAAC;;gBAAM,MAAM;QAC/F,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,EAAE,CAAC;IACpD,CAAC;CAEJ"}
|
|
@@ -1,49 +1,51 @@
|
|
|
1
1
|
import { Function } from '../function.ts';
|
|
2
|
+
import { Media } from '../media.ts';
|
|
3
|
+
import { Text } from '../text.ts';
|
|
2
4
|
declare const NOMINAL: unique symbol;
|
|
3
|
-
export declare namespace
|
|
4
|
-
namespace Part {
|
|
5
|
-
class Text {
|
|
6
|
-
text: string;
|
|
7
|
-
protected [NOMINAL]: never;
|
|
8
|
-
static paragraph(text: string): Text;
|
|
9
|
-
constructor(text: string);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
5
|
+
export declare namespace Message {
|
|
12
6
|
class Developer {
|
|
13
|
-
|
|
7
|
+
parts: Message.Developer.Part[];
|
|
14
8
|
protected [NOMINAL]: never;
|
|
15
|
-
constructor(parts:
|
|
9
|
+
constructor(parts: Message.Developer.Part[]);
|
|
16
10
|
allTextParts(): boolean;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
getOnlyTextParts(): Text[];
|
|
12
|
+
getTextParts(): Text[];
|
|
13
|
+
joinText(delimiter?: string): string;
|
|
14
|
+
}
|
|
15
|
+
namespace Developer {
|
|
16
|
+
type Part = Text | Media;
|
|
21
17
|
}
|
|
22
|
-
class
|
|
23
|
-
|
|
18
|
+
class Output<out fdu extends Function.Decl.Proto> {
|
|
19
|
+
parts: Message.Output.Part<fdu>[];
|
|
24
20
|
protected [NOMINAL]: never;
|
|
25
|
-
constructor(parts:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
getText(): string;
|
|
21
|
+
constructor(parts: Message.Output.Part<fdu>[]);
|
|
22
|
+
allTextParts(): boolean;
|
|
23
|
+
getTextParts(): Text[];
|
|
24
|
+
joinText(delimiter?: string): string;
|
|
30
25
|
getFunctionCalls(): Function.Call.Of<fdu>[];
|
|
31
26
|
getOnlyFunctionCall(): Function.Call.Of<fdu>;
|
|
32
27
|
}
|
|
33
|
-
namespace
|
|
34
|
-
type From<fdm extends Function.Decl.Map.Proto> =
|
|
28
|
+
namespace Output {
|
|
29
|
+
type From<fdm extends Function.Decl.Map.Proto> = Message.Output<Function.Decl.From<fdm>>;
|
|
30
|
+
type Part<fdu extends Function.Decl.Proto> = Text | Media | Function.Call.Of<fdu>;
|
|
31
|
+
namespace Part {
|
|
32
|
+
type From<fdm extends Function.Decl.Map.Proto> = Message.Output.Part<Function.Decl.From<fdm>>;
|
|
33
|
+
}
|
|
35
34
|
}
|
|
36
|
-
class
|
|
37
|
-
|
|
35
|
+
class Input<out fdu extends Function.Decl.Proto> {
|
|
36
|
+
parts: Message.Input.Part<fdu>[];
|
|
38
37
|
protected [NOMINAL]: never;
|
|
39
|
-
constructor(parts:
|
|
40
|
-
getParts(): unknown[];
|
|
38
|
+
constructor(parts: Message.Input.Part<fdu>[]);
|
|
41
39
|
getFunctionResponses(): Function.Response.Of<fdu>[];
|
|
42
40
|
getOnlyFunctionResponse(): Function.Response.Of<fdu>;
|
|
43
|
-
getTextParts():
|
|
41
|
+
getTextParts(): Text[];
|
|
44
42
|
}
|
|
45
|
-
namespace
|
|
46
|
-
type From<fdm extends Function.Decl.Map.Proto> =
|
|
43
|
+
namespace Input {
|
|
44
|
+
type From<fdm extends Function.Decl.Map.Proto> = Message.Input<Function.Decl.From<fdm>>;
|
|
45
|
+
type Part<fdu extends Function.Decl.Proto> = Text | Media | Function.Response.Of<fdu>;
|
|
46
|
+
namespace Part {
|
|
47
|
+
type From<fdm extends Function.Decl.Map.Proto> = Message.Input.Part<Function.Decl.From<fdm>>;
|
|
48
|
+
}
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
export {};
|
package/build/engine/message.js
CHANGED
|
@@ -1,118 +1,69 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
1
2
|
import { Function } from "../function.js";
|
|
3
|
+
import { Text } from "../text.js";
|
|
2
4
|
const NOMINAL = Symbol();
|
|
3
|
-
export var
|
|
4
|
-
(function (
|
|
5
|
-
let Part;
|
|
6
|
-
(function (Part) {
|
|
7
|
-
class Text {
|
|
8
|
-
text;
|
|
9
|
-
static paragraph(text) {
|
|
10
|
-
return new RoleMessage.Part.Text(text.trimEnd() + '\n\n');
|
|
11
|
-
}
|
|
12
|
-
constructor(text) {
|
|
13
|
-
this.text = text;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
Part.Text = Text;
|
|
17
|
-
})(Part = RoleMessage.Part || (RoleMessage.Part = {}));
|
|
5
|
+
export var Message;
|
|
6
|
+
(function (Message) {
|
|
18
7
|
class Developer {
|
|
19
8
|
parts;
|
|
20
9
|
constructor(parts) {
|
|
21
10
|
this.parts = parts;
|
|
22
11
|
}
|
|
23
12
|
allTextParts() {
|
|
24
|
-
return this.parts.every(part => part instanceof
|
|
25
|
-
}
|
|
26
|
-
getParts() {
|
|
27
|
-
return this.parts;
|
|
13
|
+
return this.parts.every(part => part instanceof Text);
|
|
28
14
|
}
|
|
29
15
|
getOnlyTextParts() {
|
|
30
|
-
|
|
31
|
-
else
|
|
32
|
-
throw new Error();
|
|
16
|
+
assert(this.allTextParts());
|
|
33
17
|
return this.getTextParts();
|
|
34
18
|
}
|
|
35
19
|
getTextParts() {
|
|
36
|
-
|
|
37
|
-
for (const part of this.parts)
|
|
38
|
-
if (part instanceof RoleMessage.Part.Text) {
|
|
39
|
-
const textPart = part;
|
|
40
|
-
textParts.push(textPart);
|
|
41
|
-
}
|
|
42
|
-
return textParts;
|
|
20
|
+
return this.parts.filter(part => part instanceof Text);
|
|
43
21
|
}
|
|
44
|
-
|
|
45
|
-
return this.getTextParts().map(part => part.
|
|
22
|
+
joinText(delimiter = '') {
|
|
23
|
+
return this.getTextParts().map(part => part.raw).join(delimiter);
|
|
46
24
|
}
|
|
47
25
|
}
|
|
48
|
-
|
|
49
|
-
class
|
|
26
|
+
Message.Developer = Developer;
|
|
27
|
+
class Output {
|
|
50
28
|
parts;
|
|
51
29
|
constructor(parts) {
|
|
52
30
|
this.parts = parts;
|
|
53
31
|
}
|
|
54
|
-
|
|
55
|
-
return this.parts;
|
|
56
|
-
}
|
|
57
|
-
allText() {
|
|
58
|
-
return this.parts.every(part => part instanceof RoleMessage.Part.Text);
|
|
32
|
+
allTextParts() {
|
|
33
|
+
return this.parts.every(part => part instanceof Text);
|
|
59
34
|
}
|
|
60
35
|
getTextParts() {
|
|
61
|
-
return this.parts.filter(part => part instanceof
|
|
36
|
+
return this.parts.filter(part => part instanceof Text);
|
|
62
37
|
}
|
|
63
|
-
|
|
64
|
-
return this.getTextParts().map(part => part.
|
|
38
|
+
joinText(delimiter = '') {
|
|
39
|
+
return this.getTextParts().map(part => part.raw).join(delimiter);
|
|
65
40
|
}
|
|
66
41
|
getFunctionCalls() {
|
|
67
|
-
|
|
68
|
-
for (const part of this.parts)
|
|
69
|
-
if (part instanceof Function.Call) {
|
|
70
|
-
const fc = part;
|
|
71
|
-
fcs.push(fc);
|
|
72
|
-
}
|
|
73
|
-
return fcs;
|
|
42
|
+
return this.parts.filter(part => part instanceof Function.Call);
|
|
74
43
|
}
|
|
75
44
|
getOnlyFunctionCall() {
|
|
76
45
|
const fcs = this.getFunctionCalls();
|
|
77
|
-
|
|
78
|
-
else
|
|
79
|
-
throw new Error();
|
|
46
|
+
assert(fcs.length === 1);
|
|
80
47
|
return fcs[0];
|
|
81
48
|
}
|
|
82
49
|
}
|
|
83
|
-
|
|
84
|
-
class
|
|
50
|
+
Message.Output = Output;
|
|
51
|
+
class Input {
|
|
85
52
|
parts;
|
|
86
53
|
constructor(parts) {
|
|
87
54
|
this.parts = parts;
|
|
88
55
|
}
|
|
89
|
-
getParts() {
|
|
90
|
-
return this.parts;
|
|
91
|
-
}
|
|
92
56
|
getFunctionResponses() {
|
|
93
|
-
|
|
94
|
-
for (const part of this.parts)
|
|
95
|
-
if (part instanceof Function.Response) {
|
|
96
|
-
const fr = part;
|
|
97
|
-
frs.push(fr);
|
|
98
|
-
}
|
|
99
|
-
return frs;
|
|
57
|
+
return this.parts.filter(part => part instanceof Function.Response);
|
|
100
58
|
}
|
|
101
59
|
getOnlyFunctionResponse() {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
throw new Error();
|
|
105
|
-
const part = this.parts[0];
|
|
106
|
-
if (part instanceof Function.Response) { }
|
|
107
|
-
else
|
|
108
|
-
throw new Error();
|
|
109
|
-
const fr = part;
|
|
110
|
-
return fr;
|
|
60
|
+
assert(this.parts.length === 1 && this.parts[0] instanceof Function.Response);
|
|
61
|
+
return this.parts[0];
|
|
111
62
|
}
|
|
112
63
|
getTextParts() {
|
|
113
|
-
return this.parts.filter(part => part instanceof
|
|
64
|
+
return this.parts.filter(part => part instanceof Text);
|
|
114
65
|
}
|
|
115
66
|
}
|
|
116
|
-
|
|
117
|
-
})(
|
|
67
|
+
Message.Input = Input;
|
|
68
|
+
})(Message || (Message = {}));
|
|
118
69
|
//# sourceMappingURL=message.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/engine/message.ts"],"names":[],"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I,CAAC,CAAC;QAC3D,CAAC;KACJ;IAhBY,aAAK,QAgBjB,CAAA;AAcL,CAAC,EA7FgB,OAAO,KAAP,OAAO,QA6FvB"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Function } from '../function.ts';
|
|
2
2
|
import { type InferenceContext } from '../inference-context.ts';
|
|
3
3
|
import { Session } from './session.ts';
|
|
4
|
-
import {
|
|
4
|
+
import { Message } from './message.ts';
|
|
5
5
|
export interface Middleware<in out fdu extends Function.Decl.Proto> {
|
|
6
|
-
<aim extends
|
|
6
|
+
<aim extends Message.Output<fdu>>(wfctx: InferenceContext, session: Session<fdu>, next: () => Promise<aim>): Promise<aim>;
|
|
7
7
|
}
|
|
8
8
|
export declare namespace Middleware {
|
|
9
9
|
type From<fdm extends Function.Decl.Map.Proto> = Middleware<Function.Decl.From<fdm>>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Function } from '../function.ts';
|
|
2
|
-
import {
|
|
3
|
-
export interface Session<
|
|
2
|
+
import { Message } from './message.ts';
|
|
3
|
+
export interface Session<out fdu extends Function.Decl.Proto> {
|
|
4
4
|
chatMessages: Session.ChatMessage<fdu>[];
|
|
5
|
-
developerMessage?:
|
|
5
|
+
developerMessage?: Message.Developer;
|
|
6
6
|
}
|
|
7
7
|
export declare namespace Session {
|
|
8
8
|
type From<fdm extends Function.Decl.Map.Proto> = Session<Function.Decl.From<fdm>>;
|
|
9
|
-
type ChatMessage<fdu extends Function.Decl.Proto> =
|
|
9
|
+
type ChatMessage<fdu extends Function.Decl.Proto> = Message.Input<fdu> | Message.Output<fdu>;
|
|
10
10
|
namespace ChatMessage {
|
|
11
11
|
type From<fdm extends Function.Decl.Map.Proto> = ChatMessage<Function.Decl.From<fdm>>;
|
|
12
12
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ToolChoice } from '../tool-choice.ts';
|
|
2
2
|
import { Function } from '../function.ts';
|
|
3
|
-
import {
|
|
3
|
+
import { Message } from './message.ts';
|
|
4
4
|
export declare class ToolChoiceValidator<in out fdu extends Function.Decl.Proto> {
|
|
5
5
|
protected toolChoice: ToolChoice;
|
|
6
6
|
constructor(options: ToolChoiceValidator.Options);
|
|
7
|
-
validate(aiMessage:
|
|
7
|
+
validate(aiMessage: Message.Output<fdu>): Message.Input<fdu> | void;
|
|
8
8
|
}
|
|
9
9
|
export declare namespace ToolChoiceValidator {
|
|
10
10
|
type From<fdm extends Function.Decl.Map.Proto> = ToolChoiceValidator<Function.Decl.From<fdm>>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ToolChoice } from "../tool-choice.js";
|
|
2
2
|
import { Function } from "../function.js";
|
|
3
|
-
import {
|
|
3
|
+
import { Message } from "./message.js";
|
|
4
4
|
import * as XmlCodec from "../xml.js";
|
|
5
|
+
import { Text } from "../text.js";
|
|
5
6
|
export class ToolChoiceValidator {
|
|
6
7
|
toolChoice;
|
|
7
8
|
constructor(options) {
|
|
@@ -9,35 +10,31 @@ export class ToolChoiceValidator {
|
|
|
9
10
|
}
|
|
10
11
|
validate(aiMessage) {
|
|
11
12
|
const fcs = aiMessage.getFunctionCalls();
|
|
12
|
-
const frs = fcs.map(fc => Function.Response.Failed.of({
|
|
13
|
-
id: fc.id,
|
|
14
|
-
name: fc.name,
|
|
15
|
-
error: XmlCodec.System.encode('Cancelled by system.'),
|
|
16
|
-
}));
|
|
17
13
|
if (this.toolChoice === ToolChoice.REQUIRED) {
|
|
18
|
-
if (fcs.length
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
new RoleMessage.Part.Text(XmlCodec.System.encode(`Error: Function call required, but not found.`)),
|
|
14
|
+
if (fcs.length === 0)
|
|
15
|
+
return new Message.Input([
|
|
16
|
+
new Text(XmlCodec.System.encode(`Error: Function call required, but not found.`)),
|
|
22
17
|
]);
|
|
23
18
|
}
|
|
24
19
|
else if (this.toolChoice === ToolChoice.ANYONE) {
|
|
25
|
-
if (
|
|
26
|
-
return new
|
|
27
|
-
new
|
|
20
|
+
if (fcs.length === 0)
|
|
21
|
+
return new Message.Input([
|
|
22
|
+
new Text(XmlCodec.System.encode(`Error: Function call required, but not found.`)),
|
|
28
23
|
]);
|
|
29
24
|
if (fcs.length > 1)
|
|
30
|
-
return new
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
return new Message.Input(fcs.map(fc => Function.Response.Failed.of({
|
|
26
|
+
id: fc.id,
|
|
27
|
+
name: fc.name,
|
|
28
|
+
error: XmlCodec.System.encode('Error: Only 1 function call allowed, but multiple found. This function call is cancelled by system.'),
|
|
29
|
+
})));
|
|
34
30
|
}
|
|
35
31
|
else if (this.toolChoice === ToolChoice.NONE) {
|
|
36
32
|
if (fcs.length)
|
|
37
|
-
return new
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
return new Message.Input(fcs.map(fc => Function.Response.Failed.of({
|
|
34
|
+
id: fc.id,
|
|
35
|
+
name: fc.name,
|
|
36
|
+
error: XmlCodec.System.encode('Error: No function call allowed. This function call is cancelled by system.'),
|
|
37
|
+
})));
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-choice-validator.js","sourceRoot":"","sources":["../../src/engine/tool-choice-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"tool-choice-validator.js","sourceRoot":"","sources":["../../src/engine/tool-choice-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,QAAQ,MAAM,WAAW,CAA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;YAC7C,IAAI,GAAG,CAAC,MAAM;gBACV,OAAO,IAAI,OAAO,CAAC,KAAK,CACpB,GAAG,CAAC,GAAG,CACH,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC9B,EAAE,EAAE,EAAE,CAAC,EAAE;oBACT,IAAI,EAAE,EAAE,CAAC,IAAI;oBACb,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,6EAA6E,CAAC;iBACnE,CAAC,CACjD,CACJ,CAAC;QACV,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Function } from '../function.ts';
|
|
2
2
|
import { type InferenceContext } from '../inference-context.ts';
|
|
3
3
|
import { Session } from './session.ts';
|
|
4
|
-
import {
|
|
4
|
+
import { Message } from './message.ts';
|
|
5
5
|
export interface Transport<in out fdm extends Function.Decl.Map.Proto> {
|
|
6
|
-
fetch(wfctx: InferenceContext, session: Session.From<fdm>, signal?: AbortSignal): Promise<
|
|
6
|
+
fetch(wfctx: InferenceContext, session: Session.From<fdm>, signal?: AbortSignal): Promise<Message.Output.From<fdm>>;
|
|
7
7
|
}
|
package/build/engine.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Function } from './function.ts';
|
|
2
2
|
import { EndpointSpec } from './endpoint-spec.ts';
|
|
3
3
|
import { Throttle } from './throttle.ts';
|
|
4
|
-
import
|
|
4
|
+
import * as Undici from 'undici';
|
|
5
5
|
import { type InferenceContext } from './inference-context.ts';
|
|
6
6
|
import * as SessionModule from './engine/session.ts';
|
|
7
7
|
import * as MessageModule from './engine/message.ts';
|
|
8
|
-
import
|
|
8
|
+
import * as MessageValidatorModule from './engine/message-validator.ts';
|
|
9
9
|
import * as ExceptionsModule from './engine/exceptions.ts';
|
|
10
10
|
import * as MiddlewareModule from './engine/middleware.ts';
|
|
11
11
|
import * as ToolChoiceValidatorModule from './engine/tool-choice-validator.ts';
|
|
@@ -19,7 +19,7 @@ export interface Pricing {
|
|
|
19
19
|
export interface ProviderSpecs {
|
|
20
20
|
baseUrl: string;
|
|
21
21
|
apiKey: string;
|
|
22
|
-
dispatcher: Dispatcher;
|
|
22
|
+
dispatcher: Undici.Dispatcher;
|
|
23
23
|
retry: number;
|
|
24
24
|
}
|
|
25
25
|
export interface InferenceOptions {
|
|
@@ -41,7 +41,7 @@ export declare namespace Engine {
|
|
|
41
41
|
protected throttle: Throttle;
|
|
42
42
|
protected toolChoice: ToolChoice;
|
|
43
43
|
protected toolChoiceValidator: Engine.ToolChoiceValidator.From<fdm>;
|
|
44
|
-
protected
|
|
44
|
+
protected messageValidator: Engine.MessageValidator.From<fdm>;
|
|
45
45
|
protected abstract transport: Engine.Transport<fdm>;
|
|
46
46
|
constructor(options: Engine.Options<fdm>);
|
|
47
47
|
/**
|
|
@@ -50,25 +50,24 @@ export declare namespace Engine {
|
|
|
50
50
|
* @throws {@link Exceptions.Recoverable} 模型抽风但可恢复
|
|
51
51
|
* @throws {@link Exceptions.ConnectionError} 网络故障
|
|
52
52
|
*/
|
|
53
|
-
protected infer(wfctx: InferenceContext, session: Session.From<fdm>): Promise<
|
|
53
|
+
protected infer(wfctx: InferenceContext, session: Session.From<fdm>): Promise<Message.Output.From<fdm>>;
|
|
54
54
|
/**
|
|
55
55
|
* @throws {@link Exceptions.InferenceTimeout} 推理超时
|
|
56
56
|
* @throws {@link Exceptions.InferenceError} 模型抽风
|
|
57
57
|
* @throws {@link Exceptions.ConnectionError} 网络故障
|
|
58
58
|
*/
|
|
59
|
-
stateless(wfctx: InferenceContext, session: Session.From<fdm>): Promise<
|
|
59
|
+
stateless(wfctx: InferenceContext, session: Session.From<fdm>): Promise<Message.Output.From<fdm>>;
|
|
60
60
|
/**
|
|
61
61
|
* @throws {@link Exceptions.InferenceTimeout} 推理超时
|
|
62
62
|
* @throws {@link Exceptions.InferenceError} 模型抽风
|
|
63
63
|
* @throws {@link Exceptions.ConnectionError} 网络故障
|
|
64
64
|
* @param session mutable
|
|
65
65
|
*/
|
|
66
|
-
stateful(wfctx: InferenceContext, session: Session.From<fdm>): Promise<
|
|
67
|
-
abstract clone(): Engine<fdm>;
|
|
66
|
+
stateful(wfctx: InferenceContext, session: Session.From<fdm>): Promise<Message.Output.From<fdm>>;
|
|
68
67
|
protected middlewaresStateless: Middleware.From<fdm>[];
|
|
69
|
-
useStateless(middleware: Middleware.From<fdm>):
|
|
68
|
+
useStateless(middleware: Middleware.From<fdm>): this;
|
|
70
69
|
protected middlewaresStateful: Middleware.From<fdm>[];
|
|
71
|
-
useStateful(middleware: Middleware.From<fdm>):
|
|
70
|
+
useStateful(middleware: Middleware.From<fdm>): this;
|
|
72
71
|
protected compose(middlewares: Middleware.From<fdm>[]): Middleware.From<fdm>;
|
|
73
72
|
/**
|
|
74
73
|
* @param session mutable
|
|
@@ -91,9 +90,10 @@ export declare namespace Engine {
|
|
|
91
90
|
export import Transport = TransportModule.Transport;
|
|
92
91
|
export import ToolChoiceValidator = ToolChoiceValidatorModule.ToolChoiceValidator;
|
|
93
92
|
export import Session = SessionModule.Session;
|
|
94
|
-
export import
|
|
93
|
+
export import Message = MessageModule.Message;
|
|
95
94
|
export import Exceptions = ExceptionsModule;
|
|
96
95
|
export import Middleware = MiddlewareModule.Middleware;
|
|
96
|
+
export import MessageValidator = MessageValidatorModule.MessageValidator;
|
|
97
97
|
}
|
|
98
98
|
declare global {
|
|
99
99
|
export namespace NodeJS {
|