@zimtsui/brainswitch 0.0.40 → 0.0.42

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 (88) hide show
  1. package/README.md +9 -20
  2. package/build/adaptor.d.ts +4 -2
  3. package/build/adaptor.js +27 -10
  4. package/build/adaptor.js.map +1 -1
  5. package/build/agentloop.d.ts +1 -1
  6. package/build/agentloop.js +2 -4
  7. package/build/agentloop.js.map +1 -1
  8. package/build/api-types/anthropic.d.ts +18 -22
  9. package/build/api-types/anthropic.js +81 -72
  10. package/build/api-types/anthropic.js.map +1 -1
  11. package/build/api-types/google.d.ts +13 -18
  12. package/build/api-types/google.js +32 -33
  13. package/build/api-types/google.js.map +1 -1
  14. package/build/api-types/openai-chat-completions.d.ts +17 -19
  15. package/build/api-types/openai-chat-completions.js +101 -85
  16. package/build/api-types/openai-chat-completions.js.map +1 -1
  17. package/build/api-types/openai-responses.d.ts +13 -13
  18. package/build/api-types/openai-responses.js +59 -51
  19. package/build/api-types/openai-responses.js.map +1 -1
  20. package/build/compatible-engine.d.ts +19 -24
  21. package/build/compatible-engine.js +54 -56
  22. package/build/compatible-engine.js.map +1 -1
  23. package/build/compatible-engines.d/aliyun.d.ts +38 -55
  24. package/build/compatible-engines.d/aliyun.js +91 -143
  25. package/build/compatible-engines.d/aliyun.js.map +1 -1
  26. package/build/compatible-engines.d/anthropic.d.ts +35 -60
  27. package/build/compatible-engines.d/anthropic.js +233 -282
  28. package/build/compatible-engines.d/anthropic.js.map +1 -1
  29. package/build/compatible-engines.d/google.d.ts +38 -59
  30. package/build/compatible-engines.d/google.js +172 -231
  31. package/build/compatible-engines.d/google.js.map +1 -1
  32. package/build/compatible-engines.d/openai-chatcompletions.d/monolith.d.ts +7 -14
  33. package/build/compatible-engines.d/openai-chatcompletions.d/monolith.js +64 -66
  34. package/build/compatible-engines.d/openai-chatcompletions.d/monolith.js.map +1 -1
  35. package/build/compatible-engines.d/openai-chatcompletions.d/stream.d.ts +10 -16
  36. package/build/compatible-engines.d/openai-chatcompletions.d/stream.js +169 -165
  37. package/build/compatible-engines.d/openai-chatcompletions.d/stream.js.map +1 -1
  38. package/build/compatible-engines.d/openai-chatcompletions.d.ts +12 -18
  39. package/build/compatible-engines.d/openai-chatcompletions.js +64 -64
  40. package/build/compatible-engines.d/openai-chatcompletions.js.map +1 -1
  41. package/build/compatible-engines.d/openai-responses.d.ts +46 -68
  42. package/build/compatible-engines.d/openai-responses.js +222 -274
  43. package/build/compatible-engines.d/openai-responses.js.map +1 -1
  44. package/build/engine.d.ts +10 -24
  45. package/build/engine.js +25 -38
  46. package/build/engine.js.map +1 -1
  47. package/build/exports.d.ts +1 -0
  48. package/build/exports.js +1 -0
  49. package/build/exports.js.map +1 -1
  50. package/build/frontmatter.js +2 -2
  51. package/build/frontmatter.js.map +1 -1
  52. package/build/function.js +9 -4
  53. package/build/function.js.map +1 -1
  54. package/build/inference-context.d.ts +1 -10
  55. package/build/inference-context.js +0 -2
  56. package/build/inference-context.js.map +1 -1
  57. package/build/native-engines.d/google/agentloop.d.ts +1 -1
  58. package/build/native-engines.d/google/agentloop.js +2 -4
  59. package/build/native-engines.d/google/agentloop.js.map +1 -1
  60. package/build/native-engines.d/google/engine.d.ts +56 -73
  61. package/build/native-engines.d/google/engine.js +265 -295
  62. package/build/native-engines.d/google/engine.js.map +1 -1
  63. package/build/native-engines.d/google/exports.d.ts +3 -2
  64. package/build/native-engines.d/google/exports.js +3 -2
  65. package/build/native-engines.d/google/exports.js.map +1 -1
  66. package/build/native-engines.d/google/session.js +6 -3
  67. package/build/native-engines.d/google/session.js.map +1 -1
  68. package/build/native-engines.d/openai-responses/agentloop.d.ts +1 -1
  69. package/build/native-engines.d/openai-responses/agentloop.js +2 -5
  70. package/build/native-engines.d/openai-responses/agentloop.js.map +1 -1
  71. package/build/native-engines.d/openai-responses/engine.d.ts +59 -78
  72. package/build/native-engines.d/openai-responses/engine.js +285 -321
  73. package/build/native-engines.d/openai-responses/engine.js.map +1 -1
  74. package/build/native-engines.d/openai-responses/exports.d.ts +4 -2
  75. package/build/native-engines.d/openai-responses/exports.js +4 -2
  76. package/build/native-engines.d/openai-responses/exports.js.map +1 -1
  77. package/build/native-engines.d/openai-responses/session.js +21 -8
  78. package/build/native-engines.d/openai-responses/session.js.map +1 -1
  79. package/build/session.js +12 -5
  80. package/build/session.js.map +1 -1
  81. package/build/telemetry.d.ts +6 -0
  82. package/build/telemetry.js +3 -0
  83. package/build/telemetry.js.map +1 -0
  84. package/build/throttle.d.ts +1 -1
  85. package/build/throttle.js +6 -6
  86. package/build/throttle.js.map +1 -1
  87. package/build/tsconfig.tsbuildinfo +1 -1
  88. package/package.json +2 -2
@@ -2,8 +2,15 @@ import { type Engine } from '../engine.ts';
2
2
  import { Function } from '../function.ts';
3
3
  import OpenAI from 'openai';
4
4
  export declare namespace OpenAIChatCompletionsEngine {
5
- interface Base<in out fdm extends Function.Declaration.Map> {
6
- parallel: boolean;
5
+ interface Options<in out fdm extends Function.Declaration.Map> extends Engine.Options<fdm> {
6
+ }
7
+ interface OwnProps {
8
+ parallelToolCall: boolean;
9
+ }
10
+ namespace OwnProps {
11
+ function init<fdm extends Function.Declaration.Map>(options: Options<fdm>): OwnProps;
12
+ }
13
+ interface Underhood<in out fdm extends Function.Declaration.Map> extends Engine.Underhood<fdm>, OwnProps {
7
14
  convertFromFunctionCall(fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): OpenAI.ChatCompletionMessageToolCall;
8
15
  convertToFunctionCall(apifc: OpenAI.ChatCompletionMessageFunctionToolCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
9
16
  convertFromFunctionResponse(fr: Function.Response.Distributive<Function.Declaration.From<fdm>>): OpenAI.ChatCompletionToolMessageParam;
@@ -13,21 +20,12 @@ export declare namespace OpenAIChatCompletionsEngine {
13
20
  extractContent(completionContent: string): string;
14
21
  handleFinishReason(completion: OpenAI.ChatCompletion, finishReason: OpenAI.ChatCompletion.Choice['finish_reason']): void;
15
22
  }
16
- interface Instance<in out fdm extends Function.Declaration.Map> extends Engine.Instance<fdm>, OpenAIChatCompletionsEngine.Base<fdm> {
17
- }
18
- namespace Base {
19
- class Instance<in out fdm extends Function.Declaration.Map> implements OpenAIChatCompletionsEngine.Base<fdm> {
20
- protected instance: Engine.Instance<fdm>;
21
- parallel: boolean;
22
- constructor(instance: Engine.Instance<fdm>, options: Engine.Options<fdm>);
23
- convertFromFunctionCall(fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): OpenAI.ChatCompletionMessageToolCall;
24
- convertToFunctionCall(apifc: OpenAI.ChatCompletionMessageFunctionToolCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
25
- convertFromFunctionResponse(fr: Function.Response.Distributive<Function.Declaration.From<fdm>>): OpenAI.ChatCompletionToolMessageParam;
26
- convertFromFunctionDeclarationEntry(fdentry: Function.Declaration.Entry.From<fdm>): OpenAI.ChatCompletionTool;
27
- convertFromToolChoice(mode: Function.ToolChoice<fdm>): OpenAI.ChatCompletionToolChoiceOption;
28
- calcCost(usage: OpenAI.CompletionUsage): number;
29
- extractContent(completionContent: string): string;
30
- handleFinishReason(completion: OpenAI.ChatCompletion, finishReason: OpenAI.ChatCompletion.Choice['finish_reason']): void;
31
- }
32
- }
23
+ function convertFromFunctionCall<fdm extends Function.Declaration.Map>(fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): OpenAI.ChatCompletionMessageToolCall;
24
+ function convertToFunctionCall<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, apifc: OpenAI.ChatCompletionMessageFunctionToolCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
25
+ function convertFromFunctionResponse<fdm extends Function.Declaration.Map>(fr: Function.Response.Distributive<Function.Declaration.From<fdm>>): OpenAI.ChatCompletionToolMessageParam;
26
+ function convertFromFunctionDeclarationEntry<fdm extends Function.Declaration.Map>(fdentry: Function.Declaration.Entry.From<fdm>): OpenAI.ChatCompletionTool;
27
+ function convertFromToolChoice<fdm extends Function.Declaration.Map>(toolChoice: Function.ToolChoice<fdm>): OpenAI.ChatCompletionToolChoiceOption;
28
+ function calcCost<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, usage: OpenAI.CompletionUsage): number;
29
+ function extractContent(completionContent: string): string;
30
+ function handleFinishReason(completion: OpenAI.ChatCompletion, finishReason: OpenAI.ChatCompletion.Choice['finish_reason']): void;
33
31
  }
@@ -1,97 +1,113 @@
1
1
  import { ResponseInvalid } from "../engine.js";
2
2
  import { Function } from "../function.js";
3
3
  import OpenAI from 'openai';
4
- import assert from 'node:assert';
5
4
  import { Ajv } from 'ajv';
6
5
  const ajv = new Ajv();
7
6
  export var OpenAIChatCompletionsEngine;
8
7
  (function (OpenAIChatCompletionsEngine) {
9
- let Base;
10
- (function (Base) {
11
- class Instance {
12
- instance;
13
- parallel;
14
- constructor(instance, options) {
15
- this.instance = instance;
16
- this.parallel = options.parallelToolCall ?? false;
17
- }
18
- convertFromFunctionCall(fc) {
19
- assert(fc.id);
20
- return {
21
- id: fc.id,
22
- type: 'function',
23
- function: {
24
- name: fc.name,
25
- arguments: JSON.stringify(fc.args),
26
- },
27
- };
28
- }
29
- convertToFunctionCall(apifc) {
30
- const fditem = this.instance.fdm[apifc.function.name];
31
- assert(fditem, new ResponseInvalid('Unknown function call', { cause: apifc }));
32
- const args = (() => {
33
- try {
34
- return JSON.parse(apifc.function.arguments);
35
- }
36
- catch (e) {
37
- return new ResponseInvalid('Invalid JSON of function call', { cause: apifc });
38
- }
39
- })();
40
- assert(ajv.validate(fditem.paraschema, args), new ResponseInvalid('Invalid function arguments', { cause: apifc }));
41
- return Function.Call.create({
42
- id: apifc.id,
43
- name: apifc.function.name,
44
- args,
45
- });
46
- }
47
- convertFromFunctionResponse(fr) {
48
- assert(fr.id);
49
- return {
50
- role: 'tool',
51
- tool_call_id: fr.id,
52
- content: fr.text,
53
- };
54
- }
55
- convertFromFunctionDeclarationEntry(fdentry) {
56
- return {
57
- type: 'function',
58
- function: {
59
- name: fdentry[0],
60
- description: fdentry[1].description,
61
- strict: true,
62
- parameters: fdentry[1].paraschema,
63
- },
64
- };
65
- }
66
- convertFromToolChoice(mode) {
67
- if (mode === Function.ToolChoice.NONE)
68
- return 'none';
69
- else if (mode === Function.ToolChoice.REQUIRED)
70
- return 'required';
71
- else if (mode === Function.ToolChoice.AUTO)
72
- return 'auto';
73
- else {
74
- assert(mode.length === 1);
75
- return { type: 'function', function: { name: mode[0] } };
76
- }
77
- }
78
- calcCost(usage) {
79
- const cacheHitTokenCount = usage.prompt_tokens_details?.cached_tokens ?? 0;
80
- const cacheMissTokenCount = usage.prompt_tokens - cacheHitTokenCount;
81
- return this.instance.inputPrice * cacheMissTokenCount / 1e6 +
82
- this.instance.cachedPrice * cacheHitTokenCount / 1e6 +
83
- this.instance.outputPrice * usage.completion_tokens / 1e6;
84
- }
85
- extractContent(completionContent) {
86
- return completionContent;
8
+ let OwnProps;
9
+ (function (OwnProps) {
10
+ function init(options) {
11
+ return {
12
+ parallelToolCall: options.parallelToolCall ?? false,
13
+ };
14
+ }
15
+ OwnProps.init = init;
16
+ })(OwnProps = OpenAIChatCompletionsEngine.OwnProps || (OpenAIChatCompletionsEngine.OwnProps = {}));
17
+ function convertFromFunctionCall(fc) {
18
+ if (fc.id) { }
19
+ else
20
+ throw new Error();
21
+ return {
22
+ id: fc.id,
23
+ type: 'function',
24
+ function: {
25
+ name: fc.name,
26
+ arguments: JSON.stringify(fc.args),
27
+ },
28
+ };
29
+ }
30
+ OpenAIChatCompletionsEngine.convertFromFunctionCall = convertFromFunctionCall;
31
+ function convertToFunctionCall(apifc) {
32
+ const fditem = this.fdm[apifc.function.name];
33
+ if (fditem) { }
34
+ else
35
+ throw new ResponseInvalid('Unknown function call', { cause: apifc });
36
+ const args = (() => {
37
+ try {
38
+ return JSON.parse(apifc.function.arguments);
87
39
  }
88
- handleFinishReason(completion, finishReason) {
89
- if (finishReason === 'length')
90
- throw new ResponseInvalid('Token limit exceeded.', { cause: completion });
91
- assert(['stop', 'tool_calls'].includes(finishReason), new ResponseInvalid('Abnormal finish reason', { cause: finishReason }));
40
+ catch (e) {
41
+ return new ResponseInvalid('Invalid JSON of function call', { cause: apifc });
92
42
  }
43
+ })();
44
+ if (ajv.validate(fditem.paraschema, args)) { }
45
+ else
46
+ throw new ResponseInvalid('Invalid function arguments', { cause: apifc });
47
+ return Function.Call.create({
48
+ id: apifc.id,
49
+ name: apifc.function.name,
50
+ args,
51
+ });
52
+ }
53
+ OpenAIChatCompletionsEngine.convertToFunctionCall = convertToFunctionCall;
54
+ function convertFromFunctionResponse(fr) {
55
+ if (fr.id) { }
56
+ else
57
+ throw new Error();
58
+ return {
59
+ role: 'tool',
60
+ tool_call_id: fr.id,
61
+ content: fr.text,
62
+ };
63
+ }
64
+ OpenAIChatCompletionsEngine.convertFromFunctionResponse = convertFromFunctionResponse;
65
+ function convertFromFunctionDeclarationEntry(fdentry) {
66
+ return {
67
+ type: 'function',
68
+ function: {
69
+ name: fdentry[0],
70
+ description: fdentry[1].description,
71
+ strict: true,
72
+ parameters: fdentry[1].paraschema,
73
+ },
74
+ };
75
+ }
76
+ OpenAIChatCompletionsEngine.convertFromFunctionDeclarationEntry = convertFromFunctionDeclarationEntry;
77
+ function convertFromToolChoice(toolChoice) {
78
+ if (toolChoice === Function.ToolChoice.NONE)
79
+ return 'none';
80
+ else if (toolChoice === Function.ToolChoice.REQUIRED)
81
+ return 'required';
82
+ else if (toolChoice === Function.ToolChoice.AUTO)
83
+ return 'auto';
84
+ else {
85
+ if (toolChoice.length === 1) { }
86
+ else
87
+ throw new Error();
88
+ return { type: 'function', function: { name: toolChoice[0] } };
93
89
  }
94
- Base.Instance = Instance;
95
- })(Base = OpenAIChatCompletionsEngine.Base || (OpenAIChatCompletionsEngine.Base = {}));
90
+ }
91
+ OpenAIChatCompletionsEngine.convertFromToolChoice = convertFromToolChoice;
92
+ function calcCost(usage) {
93
+ const cacheHitTokenCount = usage.prompt_tokens_details?.cached_tokens ?? 0;
94
+ const cacheMissTokenCount = usage.prompt_tokens - cacheHitTokenCount;
95
+ return this.inputPrice * cacheMissTokenCount / 1e6 +
96
+ this.cachePrice * cacheHitTokenCount / 1e6 +
97
+ this.outputPrice * usage.completion_tokens / 1e6;
98
+ }
99
+ OpenAIChatCompletionsEngine.calcCost = calcCost;
100
+ function extractContent(completionContent) {
101
+ return completionContent;
102
+ }
103
+ OpenAIChatCompletionsEngine.extractContent = extractContent;
104
+ function handleFinishReason(completion, finishReason) {
105
+ if (finishReason === 'length')
106
+ throw new ResponseInvalid('Token limit exceeded.', { cause: completion });
107
+ if (['stop', 'tool_calls'].includes(finishReason)) { }
108
+ else
109
+ throw new ResponseInvalid('Abnormal finish reason', { cause: finishReason });
110
+ }
111
+ OpenAIChatCompletionsEngine.handleFinishReason = handleFinishReason;
96
112
  })(OpenAIChatCompletionsEngine || (OpenAIChatCompletionsEngine = {}));
97
113
  //# sourceMappingURL=openai-chat-completions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"openai-chat-completions.js","sourceRoot":"","sources":["../../src/api-types/openai-chat-completions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAe,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAG1B,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;AAGtB,MAAM,KAAW,2BAA2B,CAqH3C;AArHD,WAAiB,2BAA2B;IAmBxC,IAAiB,IAAI,CAiGpB;IAjGD,WAAiB,IAAI;QACjB,MAAa,QAAQ;YAIH;YAHP,QAAQ,CAAU;YAEzB,YACc,QAA8B,EACxC,OAA4B;gBADlB,aAAQ,GAAR,QAAQ,CAAsB;gBAGxC,IAAI,CAAC,QAAQ,GAAG,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
4
4
  export declare namespace OpenAIResponsesEngine {
5
- interface Base<in out fdm extends Function.Declaration.Map> {
5
+ interface Options<in out fdm extends Function.Declaration.Map> extends Engine.Options<fdm> {
6
+ }
7
+ interface OwnProps {
8
+ parallelToolCall: boolean;
9
+ }
10
+ namespace OwnProps {
11
+ function init<fdm extends Function.Declaration.Map>(options: Options<fdm>): OwnProps;
12
+ }
13
+ interface Underhood<in out fdm extends Function.Declaration.Map> extends Engine.Underhood<fdm>, OwnProps {
6
14
  convertFromFunctionResponse(fr: Function.Response.Distributive<Function.Declaration.From<fdm>>): OpenAI.Responses.ResponseInputItem.FunctionCallOutput;
7
15
  calcCost(usage: OpenAI.Responses.ResponseUsage): number;
8
16
  convertFromFunctionDeclarationEntry(fdentry: Function.Declaration.Entry.From<fdm>): OpenAI.Responses.FunctionTool;
9
17
  convertToFunctionCall(apifc: OpenAI.Responses.ResponseFunctionToolCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
10
18
  }
11
- interface Instance<in out fdm extends Function.Declaration.Map> extends Engine.Instance<fdm>, OpenAIResponsesEngine.Base<fdm> {
12
- }
13
- namespace Base {
14
- class Instance<fdm extends Function.Declaration.Map> {
15
- protected instance: OpenAIResponsesEngine.Instance<fdm>;
16
- constructor(instance: OpenAIResponsesEngine.Instance<fdm>);
17
- convertFromFunctionResponse(fr: Function.Response.Distributive<Function.Declaration.From<fdm>>): OpenAI.Responses.ResponseInputItem.FunctionCallOutput;
18
- calcCost(usage: OpenAI.Responses.ResponseUsage): number;
19
- convertFromFunctionDeclarationEntry(fdentry: Function.Declaration.Entry.From<fdm>): OpenAI.Responses.FunctionTool;
20
- convertToFunctionCall(apifc: OpenAI.Responses.ResponseFunctionToolCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
21
- }
22
- }
19
+ function convertFromFunctionResponse<fdm extends Function.Declaration.Map>(fr: Function.Response.Distributive<Function.Declaration.From<fdm>>): OpenAI.Responses.ResponseInputItem.FunctionCallOutput;
20
+ function calcCost<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, usage: OpenAI.Responses.ResponseUsage): number;
21
+ function convertFromFunctionDeclarationEntry<fdm extends Function.Declaration.Map>(fdentry: Function.Declaration.Entry.From<fdm>): OpenAI.Responses.FunctionTool;
22
+ function convertToFunctionCall<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, apifc: OpenAI.Responses.ResponseFunctionToolCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
23
23
  }
@@ -1,4 +1,3 @@
1
- import assert from 'node:assert';
2
1
  import OpenAI from 'openai';
3
2
  import { Function } from "../function.js";
4
3
  import { ResponseInvalid } from "../engine.js";
@@ -7,57 +6,66 @@ import {} from "../engine.js";
7
6
  const ajv = new Ajv();
8
7
  export var OpenAIResponsesEngine;
9
8
  (function (OpenAIResponsesEngine) {
10
- let Base;
11
- (function (Base) {
12
- class Instance {
13
- instance;
14
- constructor(instance) {
15
- this.instance = instance;
16
- }
17
- convertFromFunctionResponse(fr) {
18
- assert(fr.id);
19
- return {
20
- type: 'function_call_output',
21
- call_id: fr.id,
22
- output: fr.text,
23
- };
24
- }
25
- calcCost(usage) {
26
- const cacheHitTokenCount = usage.input_tokens_details.cached_tokens;
27
- const cacheMissTokenCount = usage.input_tokens - cacheHitTokenCount;
28
- return this.instance.inputPrice * cacheMissTokenCount / 1e6 +
29
- this.instance.cachedPrice * cacheHitTokenCount / 1e6 +
30
- this.instance.outputPrice * usage.output_tokens / 1e6;
31
- }
32
- convertFromFunctionDeclarationEntry(fdentry) {
33
- return {
34
- name: fdentry[0],
35
- description: fdentry[1].description,
36
- parameters: fdentry[1].paraschema,
37
- strict: true,
38
- type: 'function',
39
- };
9
+ let OwnProps;
10
+ (function (OwnProps) {
11
+ function init(options) {
12
+ return {
13
+ parallelToolCall: options.parallelToolCall ?? false,
14
+ };
15
+ }
16
+ OwnProps.init = init;
17
+ })(OwnProps = OpenAIResponsesEngine.OwnProps || (OpenAIResponsesEngine.OwnProps = {}));
18
+ function convertFromFunctionResponse(fr) {
19
+ if (fr.id) { }
20
+ else
21
+ throw new Error();
22
+ return {
23
+ type: 'function_call_output',
24
+ call_id: fr.id,
25
+ output: fr.text,
26
+ };
27
+ }
28
+ OpenAIResponsesEngine.convertFromFunctionResponse = convertFromFunctionResponse;
29
+ function calcCost(usage) {
30
+ const cacheHitTokenCount = usage.input_tokens_details.cached_tokens;
31
+ const cacheMissTokenCount = usage.input_tokens - cacheHitTokenCount;
32
+ return this.inputPrice * cacheMissTokenCount / 1e6 +
33
+ this.cachePrice * cacheHitTokenCount / 1e6 +
34
+ this.outputPrice * usage.output_tokens / 1e6;
35
+ }
36
+ OpenAIResponsesEngine.calcCost = calcCost;
37
+ function convertFromFunctionDeclarationEntry(fdentry) {
38
+ return {
39
+ name: fdentry[0],
40
+ description: fdentry[1].description,
41
+ parameters: fdentry[1].paraschema,
42
+ strict: true,
43
+ type: 'function',
44
+ };
45
+ }
46
+ OpenAIResponsesEngine.convertFromFunctionDeclarationEntry = convertFromFunctionDeclarationEntry;
47
+ function convertToFunctionCall(apifc) {
48
+ const fditem = this.fdm[apifc.name];
49
+ if (fditem) { }
50
+ else
51
+ throw new ResponseInvalid('Unknown function call', { cause: apifc });
52
+ const args = (() => {
53
+ try {
54
+ return JSON.parse(apifc.arguments);
40
55
  }
41
- convertToFunctionCall(apifc) {
42
- const fditem = this.instance.fdm[apifc.name];
43
- assert(fditem, new ResponseInvalid('Unknown function call', { cause: apifc }));
44
- const args = (() => {
45
- try {
46
- return JSON.parse(apifc.arguments);
47
- }
48
- catch (e) {
49
- return new ResponseInvalid('Invalid JSON of function call', { cause: apifc });
50
- }
51
- })();
52
- assert(ajv.validate(fditem.paraschema, args), new ResponseInvalid('Function call not conforming to schema', { cause: apifc }));
53
- return Function.Call.create({
54
- id: apifc.call_id,
55
- name: apifc.name,
56
- args,
57
- });
56
+ catch (e) {
57
+ return new ResponseInvalid('Invalid JSON of function call', { cause: apifc });
58
58
  }
59
- }
60
- Base.Instance = Instance;
61
- })(Base = OpenAIResponsesEngine.Base || (OpenAIResponsesEngine.Base = {}));
59
+ })();
60
+ if (ajv.validate(fditem.paraschema, args)) { }
61
+ else
62
+ throw new ResponseInvalid('Function call not conforming to schema', { cause: apifc });
63
+ return Function.Call.create({
64
+ id: apifc.call_id,
65
+ name: apifc.name,
66
+ args,
67
+ });
68
+ }
69
+ OpenAIResponsesEngine.convertToFunctionCall = convertToFunctionCall;
62
70
  })(OpenAIResponsesEngine || (OpenAIResponsesEngine = {}));
63
71
  //# sourceMappingURL=openai-responses.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"openai-responses.js","sourceRoot":"","sources":["../../src/api-types/openai-responses.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAe,MAAM,cAAc,CAAC;AAE3C,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;AAItB,MAAM,KAAW,qBAAqB,CAqErC;AArED,WAAiB,qBAAqB;IAclC,IAAiB,IAAI,CAsDpB;IAtDD,WAAiB,IAAI;QACjB,MAAa,QAAQ;YACY;YAA7B,YAA6B,QAA6C;gBAA7C,aAAQ,GAAR,QAAQ,CAAqC;YAAG,CAAC;YAEvE,2BAA2B,CAAC,EAAkE;gBACjG,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;gBACd,OAAO;oBACH,IAAI,EAAE,sBAAsB;oBAC5B,OAAO,EAAE,EAAE,CAAC,EAAE;oBACd,MAAM,EAAE,EAAE,CAAC,IAAI;iBAClB,CAAC;YACN,CAAC;YAEM,QAAQ,CAAC,KAAqC;gBACjD,MAAM,kBAAkB,GAAG,KAAK,CAAC,oBAAoB,CAAC,aAA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AAC;YAClF,CAAC;QACL,CAAC,CAAC,EAAE,CAAC;QACL,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA,CAAC;;YACxC,MAAM,IAAI,eAAe,CAAC,wCAAwC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3F,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;YACxB,EAAE,EAAE,KAAK,CAAC,OAAO;YACjB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,IAAI;SACyD,CAAC,CAAC;IACvE,CAAC;IApBe,2CAAqB,wBAoBpC,CAAA;AACL,CAAC,EA/EgB,qBAAqB,KAArB,qBAAqB,QA+ErC"}
@@ -4,16 +4,16 @@ import { type InferenceContext } from './inference-context.ts';
4
4
  import { type Engine } from './engine.ts';
5
5
  export interface CompatibleEngine<in out fdm extends Function.Declaration.Map> extends Engine {
6
6
  /**
7
- * @throws {@link UserAbortion} 用户中止
7
+ * @throws {@link USER_ABORTION} 用户中止
8
8
  * @throws {@link InferenceTimeout} 推理超时
9
9
  * @throws {@link ResponseInvalid} 模型抽风
10
10
  * @throws {TypeError} 网络故障
11
11
  */
12
- stateless(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
12
+ stateless(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
13
13
  /**
14
14
  * @param session mutable
15
15
  */
16
- stateful(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
16
+ stateful(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
17
17
  appendUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
18
18
  /**
19
19
  * @param session mutable
@@ -21,36 +21,31 @@ export interface CompatibleEngine<in out fdm extends Function.Declaration.Map> e
21
21
  pushUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
22
22
  }
23
23
  export declare namespace CompatibleEngine {
24
- interface Options<in out fdm extends Function.Declaration.Map> extends Engine.Options<fdm>, CompatibleEngine.Options.Tools<fdm> {
24
+ interface Options<in out fdm extends Function.Declaration.Map> extends Engine.Options<fdm>, Options.Tools<fdm> {
25
25
  }
26
26
  namespace Options {
27
27
  interface Tools<in out fdm extends Function.Declaration.Map> extends Engine.Options.Tools<fdm> {
28
28
  toolChoice?: Function.ToolChoice<fdm>;
29
29
  }
30
30
  }
31
- interface Base<in out fdm extends Function.Declaration.Map> {
31
+ interface OwnProps<in out fdm extends Function.Declaration.Map> {
32
32
  toolChoice: Function.ToolChoice<fdm>;
33
- stateless(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
34
- stateful(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
33
+ }
34
+ namespace OwnProps {
35
+ function init<fdm extends Function.Declaration.Map>(options: CompatibleEngine.Options<fdm>): OwnProps<fdm>;
36
+ }
37
+ interface Underhood<in out fdm extends Function.Declaration.Map> extends Engine.Underhood<fdm>, CompatibleEngine<fdm>, OwnProps<fdm> {
38
+ parallelToolCall: boolean;
39
+ fetch(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>, signal?: AbortSignal): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
40
+ stateless(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
41
+ stateful(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
35
42
  appendUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
36
43
  pushUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
37
44
  validateToolCallsByToolChoice(toolCalls: Function.Call.Distributive<Function.Declaration.From<fdm>>[]): void;
38
45
  }
39
- interface Instance<in out fdm extends Function.Declaration.Map> extends Engine.Instance<fdm>, CompatibleEngine.Base<fdm>, CompatibleEngine<fdm> {
40
- parallel: boolean;
41
- fetch(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>, signal?: AbortSignal): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
42
- }
43
- namespace Base {
44
- class Instance<in out fdm extends Function.Declaration.Map> implements CompatibleEngine.Base<fdm> {
45
- protected instance: CompatibleEngine.Instance<fdm>;
46
- toolChoice: Function.ToolChoice<fdm>;
47
- constructor(instance: CompatibleEngine.Instance<fdm>, options: CompatibleEngine.Options<fdm>);
48
- stateless(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
49
- stateful(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
50
- appendUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
51
- pushUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
52
- validateToolCallsByToolChoice(toolCalls: Function.Call.Distributive<Function.Declaration.From<fdm>>[]): void;
53
- }
54
- }
55
- function validateToolCallsByToolChoice<fdm extends Function.Declaration.Map>(toolCalls: Function.Call.Distributive<Function.Declaration.From<fdm>>[], toolChoice: Function.ToolChoice<fdm>): void;
46
+ function stateless<fdm extends Function.Declaration.Map>(this: CompatibleEngine.Underhood<fdm>, wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
47
+ function stateful<fdm extends Function.Declaration.Map>(this: CompatibleEngine.Underhood<fdm>, wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
48
+ function appendUserMessage<fdm extends Function.Declaration.Map>(this: CompatibleEngine.Underhood<fdm>, session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
49
+ function pushUserMessage<fdm extends Function.Declaration.Map>(this: CompatibleEngine.Underhood<fdm>, session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
50
+ function validateToolCallsByToolChoice<fdm extends Function.Declaration.Map>(this: CompatibleEngine.Underhood<fdm>, toolCalls: Function.Call.Distributive<Function.Declaration.From<fdm>>[]): void;
56
51
  }