@zimtsui/typechat 0.0.89 → 0.0.91

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.
Files changed (45) hide show
  1. package/assets/verbatim/declarations.handlebars +6 -4
  2. package/assets/verbatim/instruction.md +19 -8
  3. package/assets/verbatim/meta.handlebars +1 -0
  4. package/build/assets.d.ts +1 -0
  5. package/build/assets.js +1 -0
  6. package/build/assets.js.map +1 -1
  7. package/build/compatible-engine/validation.d.ts +4 -4
  8. package/build/compatible-engine/validation.js +45 -31
  9. package/build/compatible-engine/validation.js.map +1 -1
  10. package/build/engine/validation.d.ts +4 -6
  11. package/build/engine.d.ts +8 -4
  12. package/build/engine.js +47 -11
  13. package/build/engine.js.map +1 -1
  14. package/build/native-engines.d/google/validation.d.ts +4 -3
  15. package/build/native-engines.d/google/validation.js +8 -3
  16. package/build/native-engines.d/google/validation.js.map +1 -1
  17. package/build/native-engines.d/openai-responses/validation.d.ts +3 -3
  18. package/build/native-engines.d/openai-responses/validation.js +41 -26
  19. package/build/native-engines.d/openai-responses/validation.js.map +1 -1
  20. package/build/tsconfig.tsbuildinfo +1 -1
  21. package/build/verbatim/codec/declarations.d.ts +1 -1
  22. package/build/verbatim/codec/declarations.js +1 -1
  23. package/build/verbatim/codec/declarations.js.map +1 -1
  24. package/build/verbatim/codec/escape.js +33 -0
  25. package/build/verbatim/codec/escape.js.map +1 -0
  26. package/build/verbatim/codec/meta.d.ts +2 -0
  27. package/build/verbatim/codec/meta.js +8 -0
  28. package/build/verbatim/codec/meta.js.map +1 -0
  29. package/build/verbatim/codec/quotation.d.ts +1 -1
  30. package/build/verbatim/codec/quotation.js +1 -1
  31. package/build/verbatim/codec/quotation.js.map +1 -1
  32. package/build/verbatim/codec/request.d.ts +6 -0
  33. package/build/verbatim/codec/request.js +44 -18
  34. package/build/verbatim/codec/request.js.map +1 -1
  35. package/build/verbatim/codec/response.d.ts +1 -1
  36. package/build/verbatim/codec/response.js +1 -1
  37. package/build/verbatim/codec/response.js.map +1 -1
  38. package/build/verbatim/codec.d.ts +1 -0
  39. package/build/verbatim/codec.js +1 -0
  40. package/build/verbatim/codec.js.map +1 -1
  41. package/package.json +1 -1
  42. package/.codex +0 -0
  43. package/build/verbatim/codec/attr-escape.js +0 -11
  44. package/build/verbatim/codec/attr-escape.js.map +0 -1
  45. /package/build/verbatim/codec/{attr-escape.d.ts → escape.d.ts} +0 -0
@@ -1,9 +1,11 @@
1
1
  {{#each declarations}}
2
- <verbatim:declaration name="{{this.name}}">
3
- <verbatim:description>{{this.description}}</verbatim:description>
2
+ <verbatim:declaration name="{{AssertXmlAttr this.name}}">
3
+ <verbatim:description mime-type="text/markdown"><![CDATA[{{{this.description}}}]]></verbatim:description>
4
4
  {{#each this.parameters}}
5
- <verbatim:parameter name="{{this.name}}" mime-type="{{XmlAttr this.mimeType}}" required="{{#if this.required}}true{{else}}false{{/if}}">
6
- <verbatim:description>{{this.description}}</verbatim:description>
5
+ <verbatim:parameter name="{{AssertXmlAttr this.name}}">
6
+ <verbatim:description mime-type="text/markdown"><![CDATA[{{{this.description}}}]]></verbatim:description>
7
+ <verbatim:mime-type>{{XmlBody this.mimeType}}</verbatim:mime-type>
8
+ <verbatim:required>{{#if this.required}}true{{else}}false{{/if}}</verbatim:required>
7
9
  </verbatim:parameter>
8
10
  {{/each}}
9
11
  </verbatim:declaration>
@@ -8,15 +8,19 @@ XML Verbatim Channel is designed to avoid escaping in structured output of large
8
8
 
9
9
  ## Declaration
10
10
 
11
- The system or the user is expected to declare all available XML Verbatim Channels in the form of
11
+ The LLM system/user message is expected to declare all available XML Verbatim Channels in the form of
12
12
 
13
13
  <verbatim:declaration name="NAME_OF_CHANNEL">
14
14
  <verbatim:description>DESCRIPTION_OF_CHANNEL</verbatim:description>
15
- <verbatim:parameter name="NAME_OF_PARAMETER_1" mime-type="MIME_TYPE_OF_PARAMETER" required="WHETHER_PARAMETER_IS_REQUIRED">
15
+ <verbatim:parameter name="NAME_OF_PARAMETER_1">
16
16
  <verbatim:description>DESCRIPTION_OF_PARAMETER</verbatim:description>
17
+ <verbatim:mime-type>MIME_TYPE_OF_PARAMETER</verbatim:mime-type>
18
+ <verbatim:required>WHETHER_PARAMETER_IS_REQUIRED</verbatim:required>
17
19
  </verbatim:parameter>
18
- <verbatim:parameter name="NAME_OF_PARAMETER_2" mime-type="MIME_TYPE_OF_PARAMETER" required="WHETHER_PARAMETER_IS_REQUIRED">
20
+ <verbatim:parameter name="NAME_OF_PARAMETER_2">
19
21
  <verbatim:description>DESCRIPTION_OF_PARAMETER</verbatim:description>
22
+ <verbatim:mime-type>MIME_TYPE_OF_PARAMETER</verbatim:mime-type>
23
+ <verbatim:required>WHETHER_PARAMETER_IS_REQUIRED</verbatim:required>
20
24
  </verbatim:parameter>
21
25
  </verbatim:declaration>
22
26
 
@@ -29,19 +33,26 @@ You can make a request through a channel in the form of
29
33
  <verbatim:parameter name="NAME_OF_PARAMETER_2"><![CDATA[ARGUMENT_OF_PARAMETER]]></verbatim:parameter>
30
34
  </verbatim:request>
31
35
 
36
+ - The only attribute of <verbatim:request> is `name`. Additional attributes will be ignored.
37
+ - The only attribute of <verbatim:parameter> is `name`. Additional attributes will be ignored.
32
38
  - All arguments must be wrapped in CDATA.
33
- - Additional XML attributes are not allowed.
34
39
 
35
40
  ## Response
36
41
 
37
- The user message may contain the response of your request in the form of
42
+ The LLM system/user message may contain the responses of your request in the form of
38
43
 
39
- <verbatim:response name="NAME_OF_CHANNEL" mime-type="MIME_TYPE_OF_RESPONSE"><![CDATA[RESPONSE]]></verbatim:response>
44
+ <verbatim:response name="NAME_OF_CHANNEL"><![CDATA[RESPONSE]]></verbatim:response>
40
45
 
41
46
  Not all requests have a response.
42
47
 
43
48
  ## Quotation
44
49
 
45
- The user message may contain verbatim quotation in the form of
50
+ The LLM system/user message may contain verbatim quotations in the form of
46
51
 
47
- <verbatim:quotation mime-type="MIME_TYPE_OF_TEXT"><![CDATA[QUOTATION]]></verbatim:quotation>
52
+ <verbatim:quotation><![CDATA[QUOTATION]]></verbatim:quotation>
53
+
54
+ ## Meta Message
55
+
56
+ The LLM system/user message may contain meta messages from the agent loop infrastructure in the form of
57
+
58
+ <verbatim:meta></verbatim:meta>
@@ -0,0 +1 @@
1
+ <verbatim:meta>{{this.text}}</verbatim:meta>
package/build/assets.d.ts CHANGED
@@ -4,6 +4,7 @@ declare const _default: {
4
4
  readonly declarations: string;
5
5
  readonly quotation: string;
6
6
  readonly response: string;
7
+ readonly meta: string;
7
8
  };
8
9
  };
9
10
  export default _default;
package/build/assets.js CHANGED
@@ -5,6 +5,7 @@ export default {
5
5
  declarations: loadtext(import.meta.resolve('../assets/verbatim/declarations.handlebars')),
6
6
  quotation: loadtext(import.meta.resolve('../assets/verbatim/quotation.handlebars')),
7
7
  response: loadtext(import.meta.resolve('../assets/verbatim/response.handlebars')),
8
+ meta: loadtext(import.meta.resolve('../assets/verbatim/meta.handlebars')),
8
9
  },
9
10
  };
10
11
  //# sourceMappingURL=assets.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"assets.js","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjD,eAAe;IACX,QAAQ,EAAE;QACN,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,mCAAmC,CAAC,CAAC;QAC/E,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,4CAA4C,CAAC,CAAC;QACzF,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,yCAAyC,CAAC,CAAC;QACnF,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,wCAAwC,CAAC,CAAC;KACpF;CACK,CAAC"}
1
+ {"version":3,"file":"assets.js","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjD,eAAe;IACX,QAAQ,EAAE;QACN,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,mCAAmC,CAAC,CAAC;QAC/E,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,4CAA4C,CAAC,CAAC;QACzF,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,yCAAyC,CAAC,CAAC;QACnF,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,wCAAwC,CAAC,CAAC;QACjF,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,oCAAoC,CAAC,CAAC;KAC5E;CACK,CAAC"}
@@ -3,12 +3,12 @@ import { Function } from '../function.ts';
3
3
  import { Verbatim } from '../verbatim.ts';
4
4
  import { RoleMessage } from './session.ts';
5
5
  import type { Engine } from '../engine.ts';
6
- export declare class Validator<in out fdu extends Function.Decl.Proto, in out vdu extends Verbatim.Decl.Proto> implements Engine.Validator<fdu, vdu, RoleMessage.Ai<fdu, vdu>> {
6
+ export declare class Validator<in out fdu extends Function.Decl.Proto, in out vdu extends Verbatim.Decl.Proto> implements Engine.Validator<RoleMessage.User<fdu>, RoleMessage.Ai<fdu, vdu>> {
7
7
  protected ctx: Validator.Context<fdu, vdu>;
8
8
  constructor(ctx: Validator.Context<fdu, vdu>);
9
- validateChoice(message: RoleMessage.Ai<fdu, vdu>): void;
10
- validateStructuring(fcs: Function.Call.Of<fdu>[], vrs: Verbatim.Request.Of<vdu>[]): void;
11
- validateParts(message: RoleMessage.Ai<fdu, vdu>): void;
9
+ validateMessageStructuring(aiMessage: RoleMessage.Ai<fdu, vdu>): RoleMessage.User<fdu> | void;
10
+ validateStructuring(fcs: Function.Call.Of<fdu>[], vrs: Verbatim.Request.Of<vdu>[]): RoleMessage.User<fdu> | void;
11
+ validateMessageParts(message: RoleMessage.Ai<fdu, vdu>): void;
12
12
  }
13
13
  export declare namespace Validator {
14
14
  type From<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto> = Validator<Function.Decl.From<fdm>, Verbatim.Decl.From<vdm>>;
@@ -1,78 +1,92 @@
1
1
  import { Structuring } from "./structuring.js";
2
+ import { RoleMessage } from "./session.js";
2
3
  import { ResponseInvalid } from "../engine.js";
4
+ import * as VerbatimCodec from "../verbatim/codec.js";
3
5
  export class Validator {
4
6
  ctx;
5
7
  constructor(ctx) {
6
8
  this.ctx = ctx;
7
9
  }
8
- validateChoice(message) {
9
- const fcs = message.getFunctionCalls();
10
- const vrs = message.getVerbatimRequests();
11
- this.validateStructuring(fcs, vrs);
10
+ validateMessageStructuring(aiMessage) {
11
+ const fcs = aiMessage.getFunctionCalls();
12
+ const vrs = aiMessage.getVerbatimRequests();
13
+ return this.validateStructuring(fcs, vrs);
12
14
  }
13
15
  validateStructuring(fcs, vrs) {
14
16
  if (this.ctx.choice === Structuring.Choice.FCall.REQUIRED) {
15
- if (fcs.length) { }
16
- else
17
+ if (!fcs.length)
17
18
  throw new ResponseInvalid('Function call required.');
18
19
  }
19
20
  else if (this.ctx.choice === Structuring.Choice.FCall.ANYONE) {
20
- if (fcs.length) { }
21
- else
21
+ if (!fcs.length)
22
22
  throw new ResponseInvalid('Function call required.');
23
23
  if (fcs.length > 1)
24
24
  throw new ResponseInvalid('Only one function call allowed.');
25
25
  }
26
26
  else if (this.ctx.choice instanceof Structuring.Choice.FCall) {
27
- if (fcs.length) { }
28
- else
27
+ if (!fcs.length)
29
28
  throw new ResponseInvalid(`Function call of ${this.ctx.choice.name} required.`);
30
29
  if (fcs.length > 1)
31
30
  throw new ResponseInvalid('Only one function call allowed.');
32
- if (fcs[0].name === this.ctx.choice.name) { }
33
- else
31
+ if (fcs[0].name !== this.ctx.choice.name)
34
32
  throw new ResponseInvalid(`Only function call of ${this.ctx.choice.name} allowed.`);
35
33
  }
36
34
  else if (this.ctx.choice === Structuring.Choice.VRequest.REQUIRED) {
37
- if (vrs.length) { }
38
- else
39
- throw new ResponseInvalid('Verbatim message required.');
35
+ if (!vrs.length)
36
+ return new RoleMessage.User([
37
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`No valid verbatim request found.`)),
38
+ ]);
40
39
  }
41
40
  else if (this.ctx.choice === Structuring.Choice.VRequest.ANYONE) {
42
- if (vrs.length) { }
43
- else
44
- throw new ResponseInvalid('Verbatim message required.');
41
+ if (!vrs.length)
42
+ return new RoleMessage.User([
43
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`No valid verbatim request found.`)),
44
+ ]);
45
45
  if (vrs.length > 1)
46
- throw new ResponseInvalid('Only one verbatim message allowed.');
46
+ return new RoleMessage.User([
47
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`Only 1 verbatim request allowed, but multiple found.`)),
48
+ ]);
47
49
  }
48
50
  else if (this.ctx.choice instanceof Structuring.Choice.VRequest) {
49
- if (vrs.length) { }
50
- else
51
- throw new ResponseInvalid(`Verbatim message through channel ${this.ctx.choice.name} required.`);
51
+ if (!vrs.length)
52
+ return new RoleMessage.User([
53
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`No valid verbatim request through channel \`${this.ctx.choice.name}\` found.`)),
54
+ ]);
52
55
  if (vrs.length > 1)
53
- throw new ResponseInvalid('Only one verbatim message allowed.');
54
- if (vrs[0].name === this.ctx.choice.name) { }
55
- else
56
- throw new ResponseInvalid(`Only verbatim message through channel ${this.ctx.choice.name} allowed.`);
56
+ return new RoleMessage.User([
57
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`Only 1 verbatim request through channel \`${this.ctx.choice.name}\` allowed.`)),
58
+ ]);
59
+ if (vrs[0].name !== this.ctx.choice.name)
60
+ return new RoleMessage.User([
61
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`Only verbatim request through channel \`${this.ctx.choice.name}\` allowed.`)),
62
+ ]);
57
63
  }
58
64
  else if (this.ctx.choice === Structuring.Choice.REQUIRED) {
59
65
  if (fcs.length + vrs.length) { }
60
66
  else
61
- throw new ResponseInvalid('Either function call or verbatim message required.');
67
+ return new RoleMessage.User([
68
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`No function call or valid verbatim request found.`)),
69
+ ]);
62
70
  }
63
71
  else if (this.ctx.choice === Structuring.Choice.ANYONE) {
64
72
  if (fcs.length + vrs.length) { }
65
73
  else
66
- throw new ResponseInvalid('Either function call or verbatim message required.');
74
+ return new RoleMessage.User([
75
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`No function call or valid verbatim request found.`)),
76
+ ]);
67
77
  if (fcs.length + vrs.length > 1)
68
- throw new ResponseInvalid('Only one function call or verbatim message allowed.');
78
+ return new RoleMessage.User([
79
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`Only 1 function call or verbatim request allowed, but multiple found.`)),
80
+ ]);
69
81
  }
70
82
  else if (this.ctx.choice === Structuring.Choice.NONE) {
71
83
  if (fcs.length + vrs.length)
72
- throw new ResponseInvalid('Neither function call nor verbatim message allowed.');
84
+ return new RoleMessage.User([
85
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`Neither function call nor verbatim request allowed.`)),
86
+ ]);
73
87
  }
74
88
  }
75
- validateParts(message) {
89
+ validateMessageParts(message) {
76
90
  const parts = message.getParts();
77
91
  if (parts.length) { }
78
92
  else
@@ -1 +1 @@
1
- {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/compatible-engine/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAI/C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAK/C,MAAM,OAAO,SAAS;IAIW;IAA7B,YAA6B,GAAgC;QAAhC,QAAG,GA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3
- export interface Validator<fdu extends Function.Decl.Proto, vdu extends Verbatim.Decl.Proto, aim> {
4
- validateChoice(message: aim): void;
5
- validateParts(message: aim): void;
1
+ export interface Validator<out userm, in aim> {
2
+ validateMessageStructuring(aiMessage: aim): userm | void;
3
+ validateMessageParts(aiMessage: aim): void;
6
4
  }
7
5
  export declare namespace Validator {
8
- type From<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto, aim> = Validator<Function.Decl.From<fdm>, Verbatim.Decl.From<vdm>, aim>;
6
+ type From<userm, aim> = Validator<userm, aim>;
9
7
  }
package/build/engine.d.ts CHANGED
@@ -4,7 +4,7 @@ import { Throttle } from './throttle.ts';
4
4
  import { ProxyAgent } from 'undici';
5
5
  import { type InferenceContext } from './inference-context.ts';
6
6
  import * as SessionModule from './engine/session.ts';
7
- import type { Verbatim } from './verbatim.ts';
7
+ import { Verbatim } from "./verbatim.js";
8
8
  import * as ValidationModule from './engine/validation.ts';
9
9
  import * as TransportModule from './engine/transport.ts';
10
10
  export interface Pricing {
@@ -35,7 +35,7 @@ export declare namespace Engine {
35
35
  protected throttle: Throttle;
36
36
  protected abstract parallelToolCall: boolean;
37
37
  protected retry: number;
38
- protected abstract validator: Engine.Validator.From<fdm, vdm, aim>;
38
+ protected abstract validator: Engine.Validator.From<userm, aim>;
39
39
  protected abstract transport: Engine.Transport<userm, aim, devm, session>;
40
40
  constructor(options: Engine.Options<fdm, vdm>);
41
41
  protected infer(wfctx: InferenceContext, session: session, signal?: AbortSignal): Promise<aim>;
@@ -67,14 +67,18 @@ export declare namespace Engine {
67
67
  export import Validator = ValidationModule.Validator;
68
68
  export import Transport = TransportModule.Transport;
69
69
  }
70
- export declare class ResponseInvalid extends Error {
71
- }
72
70
  export declare class InferenceTimeout extends Error {
73
71
  }
74
72
  export declare class NetworkError extends Error {
75
73
  }
76
74
  export declare class CustomRetry extends Error {
77
75
  }
76
+ export declare class ResponseInvalid extends Error {
77
+ }
78
+ export declare namespace ResponseInvalid {
79
+ class Recoverable extends ResponseInvalid {
80
+ }
81
+ }
78
82
  declare global {
79
83
  export namespace NodeJS {
80
84
  interface ProcessEnv {
package/build/engine.js CHANGED
@@ -39,8 +39,7 @@ export var Engine;
39
39
  }
40
40
  async infer(wfctx, session, signal) {
41
41
  const aiMessage = await this.transport.fetch(wfctx, session, signal);
42
- this.validator.validateParts(aiMessage);
43
- this.validator.validateChoice(aiMessage);
42
+ this.validator.validateMessageParts(aiMessage);
44
43
  return aiMessage;
45
44
  }
46
45
  /**
@@ -58,10 +57,13 @@ export var Engine;
58
57
  ]) : wfctx.signal || signalTimeout;
59
58
  try {
60
59
  const response = await this.infer(wfctx, session, signal);
61
- if (await validate(response))
62
- return response;
60
+ const rejection = this.validator.validateMessageStructuring(response);
61
+ if (rejection)
62
+ throw new ResponseInvalid.Recoverable();
63
+ if (await validate(response)) { }
63
64
  else
64
65
  throw new CustomRetry(undefined, { cause: response });
66
+ return response;
65
67
  }
66
68
  catch (e) {
67
69
  if (signalTimeout?.aborted)
@@ -71,7 +73,6 @@ export var Engine;
71
73
  else if (e instanceof CustomRetry) { } // 自定义重试
72
74
  else
73
75
  throw e;
74
- wfctx.cost?.(0); // 心跳
75
76
  if (retry < this.retry)
76
77
  loggers.message.warn(e);
77
78
  else
@@ -82,20 +83,55 @@ export var Engine;
82
83
  /**
83
84
  * @param session mutable
84
85
  */
85
- async stateful(wfctx, session, validate) {
86
- const response = await this.stateless(wfctx, session, validate);
87
- session.chatMessages.push(response);
88
- return response;
86
+ async stateful(wfctx, session, validate = () => Promise.resolve(true)) {
87
+ for (let retry = 0;; retry++) {
88
+ const signalTimeout = this.inferenceParams.timeout ? AbortSignal.timeout(this.inferenceParams.timeout) : undefined;
89
+ const signal = wfctx.signal && signalTimeout ? AbortSignal.any([
90
+ wfctx.signal,
91
+ signalTimeout,
92
+ ]) : wfctx.signal || signalTimeout;
93
+ try {
94
+ const response = await this.infer(wfctx, session, signal);
95
+ const rejection = this.validator.validateMessageStructuring(response);
96
+ if (rejection) {
97
+ session.chatMessages.push(response, rejection);
98
+ throw new ResponseInvalid.Recoverable();
99
+ }
100
+ if (await validate(response)) { }
101
+ else
102
+ throw new CustomRetry(undefined, { cause: response });
103
+ session.chatMessages.push(response);
104
+ return response;
105
+ }
106
+ catch (e) {
107
+ if (signalTimeout?.aborted)
108
+ e = new InferenceTimeout(undefined, { cause: e }); // 推理超时
109
+ else if (e instanceof ResponseInvalid) { } // 模型抽风
110
+ else if (e instanceof NetworkError) { } // 网络故障
111
+ else if (e instanceof CustomRetry) { } // 自定义重试
112
+ else
113
+ throw e;
114
+ if (retry < this.retry) { }
115
+ else
116
+ throw e;
117
+ loggers.message.warn(e);
118
+ }
119
+ }
89
120
  }
90
121
  }
91
122
  Engine.Instance = Instance;
92
123
  })(Engine || (Engine = {}));
93
- export class ResponseInvalid extends Error {
94
- }
95
124
  export class InferenceTimeout extends Error {
96
125
  }
97
126
  export class NetworkError extends Error {
98
127
  }
99
128
  export class CustomRetry extends Error {
100
129
  }
130
+ export class ResponseInvalid extends Error {
131
+ }
132
+ (function (ResponseInvalid) {
133
+ class Recoverable extends ResponseInvalid {
134
+ }
135
+ ResponseInvalid.Recoverable = Recoverable;
136
+ })(ResponseInvalid || (ResponseInvalid = {}));
101
137
  //# sourceMappingURL=engine.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AA+BzC,MAAM,KAAW,MAAM,CAsItB;AAtID,WAAiB,MAAM;IACnB,MAAsB,QAAQ;QAMhB,YAAY,CAAe;QAC3B,eAAe,CAAkB;QACpC,IAAI,CAAS;QACb,OAAO,CAAU;QACjB,GAAG,CAAM;QACT,GAAG,CAAM;QACN,QAAQ,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7B,CAAA;AAiBL,CAAC,EA7JgB,MAAM,KAAN,MAAM,QA6JtB;AAED,MAAM,OAAO,gBAAiB,SAAQ,KAAK;CAAG;AAC9C,MAAM,OAAO,YAAa,SAAQ,KAAK;CAAG;AAC1C,MAAM,OAAO,WAAY,SAAQ,KAAK;CAAG;AACzC,MAAM,OAAO,eAAgB,SAAQ,KAAK;CAAG;AAC7C,WAAiB,eAAe;IAC5B,MAAa,WAAY,SAAQ,eAAe;KAAG;IAAtC,2BAAW,cAA2B,CAAA;AACvD,CAAC,EAFgB,eAAe,KAAf,eAAe,QAE/B"}
@@ -4,12 +4,13 @@ import { Verbatim } from '../../verbatim.ts';
4
4
  import { RoleMessage } from './session.ts';
5
5
  import { Validator as CompatibleValidator } from '../../compatible-engine/validation.ts';
6
6
  import { Engine } from '../../engine.ts';
7
- export declare class Validator<in out fdu extends Function.Decl.Proto, in out vdu extends Verbatim.Decl.Proto> implements Engine.Validator<fdu, vdu, RoleMessage.Ai<fdu, vdu>> {
7
+ export declare class Validator<in out fdu extends Function.Decl.Proto, in out vdu extends Verbatim.Decl.Proto> implements Engine.Validator<RoleMessage.User<fdu>, RoleMessage.Ai<fdu, vdu>> {
8
8
  protected ctx: Validator.Context<fdu, vdu>;
9
9
  protected compatibleValidator: CompatibleValidator<fdu, vdu>;
10
10
  constructor(ctx: Validator.Context<fdu, vdu>);
11
- validateParts(message: RoleMessage.Ai<fdu, vdu>): void;
12
- validateChoice(message: RoleMessage.Ai<fdu, vdu>): void;
11
+ validateMessageParts(message: RoleMessage.Ai<fdu, vdu>): void;
12
+ validateStructuring(fcs: Function.Call.Of<fdu>[], vrs: Verbatim.Request.Of<vdu>[]): void | RoleMessage.User<fdu>;
13
+ validateMessageStructuring(message: RoleMessage.Ai<fdu, vdu>): void | RoleMessage.User<fdu>;
13
14
  }
14
15
  export declare namespace Validator {
15
16
  type From<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto> = Validator<Function.Decl.From<fdm>, Verbatim.Decl.From<vdm>>;
@@ -7,14 +7,19 @@ export class Validator {
7
7
  this.ctx = ctx;
8
8
  this.compatibleValidator = new CompatibleValidator({ choice: ctx.choice });
9
9
  }
10
- validateParts(message) {
10
+ validateMessageParts(message) {
11
11
  const parts = message.getParts();
12
12
  if (parts.length) { }
13
13
  else
14
14
  throw new ResponseInvalid('Empty message.');
15
15
  }
16
- validateChoice(message) {
17
- this.compatibleValidator.validateStructuring(message.getFunctionCalls(), message.getVerbatimRequests());
16
+ validateStructuring(fcs, vrs) {
17
+ return this.compatibleValidator.validateStructuring(fcs, vrs);
18
+ }
19
+ validateMessageStructuring(message) {
20
+ const fcs = message.getFunctionCalls();
21
+ const vrs = message.getVerbatimRequests();
22
+ return this.validateStructuring(fcs, vrs);
18
23
  }
19
24
  }
20
25
  //# sourceMappingURL=validation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../src/native-engines.d/google/validation.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,IAAI,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AACzF,OAAO,EAAE,eAAe,EAAU,MAAM,iBAAiB,CAAC;AAI1D,MAAM,OAAO,SAAS;IAKW;IADnB,mBAAmB,CAAgC;IAC7D,YAA6B,GAAgC;QAAhC,QAAG,GAAH,GAAG,CAA6B;QACzD,IAAI,CAAC,mBAAmB,GAAG,IAAI,mBAAmB,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;IAC/E,CAAC;IAEM,aAAa,CAChB,OAAiC;QAEjC,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;QACjC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA,CAAC;;YAAM,MAAM,IAAI,eAAe,CAAC,gBAAgB,CAAC,CAAC;IAC1E,CAAC;IAEM,cAAc,CACjB,OAAiC;QAEjC,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAC;IAC5G,CAAC;CACJ"}
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../src/native-engines.d/google/validation.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,IAAI,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AACzF,OAAO,EAAE,eAAe,EAAU,MAAM,iBAAiB,CAAC;AAI1D,MAAM,OAAO,SAAS;IAKW;IADnB,mBAAmB,CAAgC;IAC7D,YAA6B,GAAgC;QAAhC,QAAG,GAAH,GAAG,CAA6B;QACzD,IAAI,CAAC,mBAAmB,GAAG,IAAI,mBAAmB,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;IAC/E,CAAC;IAEM,oBAAoB,CACvB,OAAiC;QAEjC,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;QACjC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA,CAAC;;YAAM,MAAM,IAAI,eAAe,CAAC,gBAAgB,CAAC,CAAC;IAC1E,CAAC;IAEM,mBAAmB,CACtB,GAA4B,EAC5B,GAA+B;QAE/B,OAAO,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAClE,CAAC;IAEM,0BAA0B,CAC7B,OAAiC;QAEjC,MAAM,GAAG,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;QACvC,MAAM,GAAG,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC;QAC1C,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;CACJ"}
@@ -3,11 +3,11 @@ import { Function } from '../../function.ts';
3
3
  import { Verbatim } from '../../verbatim.ts';
4
4
  import { RoleMessage } from './session.ts';
5
5
  import type { Engine } from '../../engine.ts';
6
- export declare class Validator<in out fdu extends Function.Decl.Proto, in out vdu extends Verbatim.Decl.Proto> implements Engine.Validator<fdu, vdu, RoleMessage.Ai<fdu, vdu>> {
6
+ export declare class Validator<in out fdu extends Function.Decl.Proto, in out vdu extends Verbatim.Decl.Proto> implements Engine.Validator<RoleMessage.User<fdu>, RoleMessage.Ai<fdu, vdu>> {
7
7
  protected ctx: Validator.Context<fdu, vdu>;
8
8
  constructor(ctx: Validator.Context<fdu, vdu>);
9
- validateChoice(message: RoleMessage.Ai<fdu, vdu>): void;
10
- validateParts(message: RoleMessage.Ai<fdu, vdu>): void;
9
+ validateMessageStructuring(message: RoleMessage.Ai<fdu, vdu>): RoleMessage.User<fdu> | undefined;
10
+ validateMessageParts(message: RoleMessage.Ai<fdu, vdu>): void;
11
11
  }
12
12
  export declare namespace Validator {
13
13
  type From<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto> = Validator<Function.Decl.From<fdm>, Verbatim.Decl.From<vdm>>;
@@ -1,29 +1,28 @@
1
1
  import { Structuring } from "./structuring.js";
2
2
  import { Function } from "../../function.js";
3
+ import { RoleMessage } from "./session.js";
3
4
  import { ResponseInvalid } from "../../engine.js";
5
+ import * as VerbatimCodec from "../../verbatim/codec.js";
4
6
  export class Validator {
5
7
  ctx;
6
8
  constructor(ctx) {
7
9
  this.ctx = ctx;
8
10
  }
9
- validateChoice(message) {
11
+ validateMessageStructuring(message) {
10
12
  const tcs = message.getToolCalls();
11
13
  const vrs = message.getVerbatimRequests();
12
14
  if (this.ctx.choice === Structuring.Choice.TCall.REQUIRED) {
13
- if (tcs.length) { }
14
- else
15
+ if (!tcs.length)
15
16
  throw new ResponseInvalid('Tool call required.');
16
17
  }
17
18
  else if (this.ctx.choice === Structuring.Choice.TCall.ANYONE) {
18
- if (tcs.length) { }
19
- else
19
+ if (!tcs.length)
20
20
  throw new ResponseInvalid('Tool call required.');
21
21
  if (tcs.length > 1)
22
22
  throw new ResponseInvalid('Only one tool call allowed.');
23
23
  }
24
24
  else if (this.ctx.choice instanceof Structuring.Choice.TCall.FCall) {
25
- if (tcs.length) { }
26
- else
25
+ if (!tcs.length)
27
26
  throw new ResponseInvalid(`Function call of ${this.ctx.choice.name} required.`);
28
27
  if (tcs.length > 1)
29
28
  throw new ResponseInvalid('Only one function call allowed.');
@@ -32,45 +31,61 @@ export class Validator {
32
31
  throw new ResponseInvalid(`Only function call of ${this.ctx.choice.name} allowed.`);
33
32
  }
34
33
  else if (this.ctx.choice === Structuring.Choice.VRequest.REQUIRED) {
35
- if (vrs.length) { }
36
- else
37
- throw new ResponseInvalid('Verbatim message required.');
34
+ if (!vrs.length)
35
+ return new RoleMessage.User([
36
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`No valid verbatim request found.`)),
37
+ ]);
38
38
  }
39
39
  else if (this.ctx.choice === Structuring.Choice.VRequest.ANYONE) {
40
- if (vrs.length) { }
41
- else
42
- throw new ResponseInvalid('Verbatim message required.');
40
+ if (!vrs.length)
41
+ return new RoleMessage.User([
42
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`No valid verbatim request found.`)),
43
+ ]);
43
44
  if (vrs.length > 1)
44
- throw new ResponseInvalid('Only one verbatim message allowed.');
45
+ return new RoleMessage.User([
46
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`Only 1 verbatim request allowed, but multiple found.`)),
47
+ ]);
45
48
  }
46
49
  else if (this.ctx.choice instanceof Structuring.Choice.VRequest) {
47
- if (vrs.length) { }
48
- else
49
- throw new ResponseInvalid(`Verbatim message through channel ${this.ctx.choice.name} required.`);
50
+ if (!vrs.length)
51
+ return new RoleMessage.User([
52
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`No valid verbatim request through channel \`${this.ctx.choice.name}\` found.`)),
53
+ ]);
50
54
  if (vrs.length > 1)
51
- throw new ResponseInvalid('Only one verbatim message allowed.');
52
- if (vrs[0].name === this.ctx.choice.name) { }
53
- else
54
- throw new ResponseInvalid(`Only verbatim message through channel ${this.ctx.choice.name} allowed.`);
55
+ return new RoleMessage.User([
56
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`Only 1 verbatim request through channel \`${this.ctx.choice.name}\` allowed.`)),
57
+ ]);
58
+ if (vrs[0].name !== this.ctx.choice.name)
59
+ return new RoleMessage.User([
60
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`Only verbatim request through channel \`${this.ctx.choice.name}\` allowed.`)),
61
+ ]);
55
62
  }
56
63
  else if (this.ctx.choice === Structuring.Choice.REQUIRED) {
57
64
  if (tcs.length + vrs.length) { }
58
65
  else
59
- throw new ResponseInvalid('Either tool call or verbatim message required.');
66
+ return new RoleMessage.User([
67
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`No function call or valid verbatim request found.`)),
68
+ ]);
60
69
  }
61
70
  else if (this.ctx.choice === Structuring.Choice.ANYONE) {
62
71
  if (tcs.length + vrs.length) { }
63
72
  else
64
- throw new ResponseInvalid('Either tool call or verbatim message required.');
73
+ return new RoleMessage.User([
74
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`No function call or valid verbatim request found.`)),
75
+ ]);
65
76
  if (tcs.length + vrs.length > 1)
66
- throw new ResponseInvalid('Only one tool call or verbatim message allowed.');
77
+ return new RoleMessage.User([
78
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`Only 1 function call or verbatim request allowed, but multiple found.`)),
79
+ ]);
67
80
  }
68
81
  else if (this.ctx.choice === Structuring.Choice.NONE) {
69
82
  if (tcs.length + vrs.length)
70
- throw new ResponseInvalid('Neither tool call nor verbatim message allowed.');
83
+ return new RoleMessage.User([
84
+ RoleMessage.Part.Text.paragraph(VerbatimCodec.Meta.encode(`Neither function call nor verbatim request allowed.`)),
85
+ ]);
71
86
  }
72
87
  }
73
- validateParts(message) {
88
+ validateMessageParts(message) {
74
89
  const parts = message.getParts();
75
90
  if (parts.length) { }
76
91
  else