@zimtsui/typechat 0.0.144 → 0.0.146

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 (49) hide show
  1. package/README.md +1 -2
  2. package/build/adaptor.js +3 -6
  3. package/build/adaptor.js.map +1 -1
  4. package/build/config.d.ts +2 -2
  5. package/build/config.js +3 -4
  6. package/build/config.js.map +1 -1
  7. package/build/engines/google/message-codec.d.ts +3 -3
  8. package/build/engines/google/message-codec.js +10 -7
  9. package/build/engines/google/message-codec.js.map +1 -1
  10. package/build/engines/google/tool-codec.d.ts +1 -1
  11. package/build/engines/google/tool-codec.js +3 -3
  12. package/build/engines/google/tool-codec.js.map +1 -1
  13. package/build/engines/google/transport.js +1 -1
  14. package/build/engines/google/transport.js.map +1 -1
  15. package/build/engines/openai-responses/input-content.d.ts +4 -0
  16. package/build/engines/openai-responses/input-content.js +28 -0
  17. package/build/engines/openai-responses/input-content.js.map +1 -0
  18. package/build/engines/openai-responses/message-codec.d.ts +3 -6
  19. package/build/engines/openai-responses/message-codec.js +8 -33
  20. package/build/engines/openai-responses/message-codec.js.map +1 -1
  21. package/build/engines/openai-responses/tool-codec.d.ts +1 -4
  22. package/build/engines/openai-responses/tool-codec.js +8 -30
  23. package/build/engines/openai-responses/tool-codec.js.map +1 -1
  24. package/build/engines/openai-responses/transport.d.ts +1 -1
  25. package/build/engines/openai-responses/transport.js +8 -4
  26. package/build/engines/openai-responses/transport.js.map +1 -1
  27. package/build/media.d.ts +6 -6
  28. package/build/media.js +6 -6
  29. package/build/media.js.map +1 -1
  30. package/build/tsconfig.tsbuildinfo +1 -1
  31. package/package.json +5 -6
  32. package/build/engines/anthropic/billing.d.ts +0 -12
  33. package/build/engines/anthropic/billing.js +0 -15
  34. package/build/engines/anthropic/billing.js.map +0 -1
  35. package/build/engines/anthropic/message-codec.d.ts +0 -23
  36. package/build/engines/anthropic/message-codec.js +0 -82
  37. package/build/engines/anthropic/message-codec.js.map +0 -1
  38. package/build/engines/anthropic/tool-choice-codec.d.ts +0 -3
  39. package/build/engines/anthropic/tool-choice-codec.js +0 -15
  40. package/build/engines/anthropic/tool-choice-codec.js.map +0 -1
  41. package/build/engines/anthropic/tool-codec.d.ts +0 -17
  42. package/build/engines/anthropic/tool-codec.js +0 -96
  43. package/build/engines/anthropic/tool-codec.js.map +0 -1
  44. package/build/engines/anthropic/transport.d.ts +0 -35
  45. package/build/engines/anthropic/transport.js +0 -160
  46. package/build/engines/anthropic/transport.js.map +0 -1
  47. package/build/engines/anthropic.d.ts +0 -19
  48. package/build/engines/anthropic.js +0 -43
  49. package/build/engines/anthropic.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zimtsui/typechat",
3
- "version": "0.0.144",
3
+ "version": "0.0.146",
4
4
  "exports": {
5
5
  ".": "./build/exports.js",
6
6
  "./xml": "./build/exports/xml.js",
@@ -8,7 +8,7 @@
8
8
  "./retry": "./build/retry.js"
9
9
  },
10
10
  "engines": {
11
- "node": ">=24"
11
+ "node": ">=26"
12
12
  },
13
13
  "type": "module",
14
14
  "scripts": {
@@ -23,10 +23,9 @@
23
23
  "url": "git+https://github.com/zimtsui/typechat.git"
24
24
  },
25
25
  "dependencies": {
26
- "@anthropic-ai/sdk": "^0.133.0",
27
- "@google/genai": "^2.7.0",
26
+ "@google/genai": "^3.6.1",
28
27
  "@types/node": "^24.12.2",
29
- "@zimtsui/node-utilities": "^0.0.11",
28
+ "@zimtsui/node-utilities": "^0.0.12",
30
29
  "handlebars": "^4.7.8",
31
30
  "openai": "^7.23.0",
32
31
  "strings-to-regex": "^1.3.0",
@@ -35,7 +34,7 @@
35
34
  "peerDependencies": {
36
35
  "@types/whatwg-mimetype": "^5.0.0",
37
36
  "@zimtsui/typelemetry": "^0.0.54",
38
- "@zimtsui/typelocks": "^0.0.31",
37
+ "@zimtsui/typelocks": "^0.0.32",
39
38
  "typebox": "^1.1.31"
40
39
  },
41
40
  "devDependencies": {
@@ -1,12 +0,0 @@
1
- import type { Pricing } from '../../engine.ts';
2
- import Anthropic from '@anthropic-ai/sdk';
3
- export declare class Billing {
4
- protected pricing: Pricing;
5
- constructor(options: Billing.Options);
6
- charge(usage: Anthropic.Usage): number;
7
- }
8
- export declare namespace Billing {
9
- interface Options {
10
- pricing: Pricing;
11
- }
12
- }
@@ -1,15 +0,0 @@
1
- export class Billing {
2
- pricing;
3
- constructor(options) {
4
- this.pricing = options.pricing;
5
- }
6
- charge(usage) {
7
- const cacheReadTokenCount = usage.cache_read_input_tokens ?? 0;
8
- const cacheWriteTokenCount = usage.cache_creation_input_tokens ?? 0;
9
- return (this.pricing.inputPrice * usage.input_tokens / 1e6 +
10
- this.pricing.cacheReadPrice * cacheReadTokenCount / 1e6 +
11
- this.pricing.cacheWritePrice * cacheWriteTokenCount / 1e6 +
12
- this.pricing.outputPrice * usage.output_tokens / 1e6);
13
- }
14
- }
15
- //# sourceMappingURL=billing.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"billing.js","sourceRoot":"","sources":["../../../src/engines/anthropic/billing.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,OAAO;IACN,OAAO,CAAU;IAC3B,YAAmB,OAAwB;QACvC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACnC,CAAC;IAEM,MAAM,CAAC,KAAsB;QAChC,MAAM,mBAAmB,GAAG,KAAK,CAAC,uBAAuB,IAAI,CAAC,CAAC;QAC/D,MAAM,oBAAoB,GAAG,KAAK,CAAC,2BAA2B,IAAI,CAAC,CAAC;QACpE,OAAO,CACH,IAAI,CAAC,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC,YAAY,GAAG,GAAG;YAClD,IAAI,CAAC,OAAO,CAAC,cAAc,GAAG,mBAAmB,GAAG,GAAG;YACvD,IAAI,CAAC,OAAO,CAAC,eAAe,GAAG,oBAAoB,GAAG,GAAG;YACzD,IAAI,CAAC,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC,aAAa,GAAG,GAAG,CACvD,CAAC;IACN,CAAC;CACJ"}
@@ -1,23 +0,0 @@
1
- import { Engine } from '../../engine.ts';
2
- import { Function } from '../../function.ts';
3
- import Anthropic from '@anthropic-ai/sdk';
4
- import type { ToolCodec } from './tool-codec.ts';
5
- export declare class MessageCodec<in out fdm extends Function.Decl.Map.Proto> {
6
- protected cacheDeveloperMessages: WeakMap<Engine.Message.Developer, Anthropic.Messages.TextBlockParam[]>;
7
- protected cacheInputMessages: WeakMap<Engine.Message.Input<Function.Decl.Proto>, Anthropic.Messages.ContentBlockParam[]>;
8
- protected cacheOutputMessages: WeakMap<Engine.Message.Output<Function.Decl.Proto>, Anthropic.Messages.ContentBlockParam[]>;
9
- protected toolCodec: ToolCodec<fdm>;
10
- protected messageValidator: Engine.MessageValidator.From<fdm>;
11
- constructor(options: MessageCodec.Options<fdm>);
12
- encodeInputMessage(inm: Engine.Message.Input.From<fdm>): Anthropic.ContentBlockParam[];
13
- encodeOutputMessage(outm: Engine.Message.Output.From<fdm>): Anthropic.ContentBlockParam[];
14
- encodeDeveloperMessage(developerMessage: Engine.Message.Developer): Anthropic.TextBlockParam[];
15
- encodeChatMessage(chatMessage: Engine.Session.ChatMessage.From<fdm>): Anthropic.MessageParam;
16
- decodeOutputMessage(raw: Anthropic.ContentBlock[]): Engine.Message.Output.From<fdm>;
17
- }
18
- export declare namespace MessageCodec {
19
- interface Options<in out fdm extends Function.Decl.Map.Proto> {
20
- toolCodec: ToolCodec<fdm>;
21
- messageValidator: Engine.MessageValidator.From<fdm>;
22
- }
23
- }
@@ -1,82 +0,0 @@
1
- import { Engine } from "../../engine.js";
2
- import { Function } from "../../function.js";
3
- import { Media } from "../../media.js";
4
- import { Text } from "../../text.js";
5
- export class MessageCodec {
6
- cacheDeveloperMessages = new WeakMap();
7
- cacheInputMessages = new WeakMap();
8
- cacheOutputMessages = new WeakMap();
9
- toolCodec;
10
- messageValidator;
11
- constructor(options) {
12
- this.toolCodec = options.toolCodec;
13
- this.messageValidator = options.messageValidator;
14
- }
15
- encodeInputMessage(inm) {
16
- if (this.cacheInputMessages.has(inm))
17
- return this.cacheInputMessages.get(inm);
18
- this.messageValidator.validateInputMessage(inm);
19
- const blocks = [];
20
- for (const part of inm.parts)
21
- if (part instanceof Text)
22
- blocks.push({
23
- type: 'text',
24
- text: part.raw,
25
- });
26
- else if (part instanceof Function.Response) {
27
- const fr = part;
28
- blocks.push(this.toolCodec.encodeFunctionResponse(fr));
29
- }
30
- else if (part instanceof Media.Text)
31
- blocks.push({
32
- type: 'text',
33
- text: part.quote(),
34
- });
35
- else
36
- throw new Error('Unknown user message part type', { cause: part });
37
- this.cacheInputMessages.set(inm, blocks);
38
- return blocks;
39
- }
40
- encodeOutputMessage(outm) {
41
- if (this.cacheOutputMessages.has(outm))
42
- return this.cacheOutputMessages.get(outm);
43
- throw new Error('Only native output message allowed.', { cause: outm });
44
- }
45
- encodeDeveloperMessage(developerMessage) {
46
- if (this.cacheDeveloperMessages.has(developerMessage))
47
- return this.cacheDeveloperMessages.get(developerMessage);
48
- const raw = developerMessage.getOnlyTextParts().map(part => ({ type: 'text', text: part.raw }));
49
- this.cacheDeveloperMessages.set(developerMessage, raw);
50
- return raw;
51
- }
52
- encodeChatMessage(chatMessage) {
53
- if (chatMessage instanceof Engine.Message.Input) {
54
- const inm = chatMessage;
55
- return { role: 'user', content: this.encodeInputMessage(inm) };
56
- }
57
- else if (chatMessage instanceof Engine.Message.Output) {
58
- const outm = chatMessage;
59
- return { role: 'assistant', content: this.encodeOutputMessage(outm) };
60
- }
61
- else
62
- throw new Error('Unsupported chat message type.');
63
- }
64
- decodeOutputMessage(raw) {
65
- const parts = [];
66
- for (const item of raw) {
67
- if (item.type === 'text')
68
- parts.push(new Text(item.text));
69
- else if (item.type === 'tool_use')
70
- parts.push(this.toolCodec.decodeFunctionCall(item));
71
- else if (item.type === 'thinking') { }
72
- else if (item.type === 'redacted_thinking') { }
73
- else
74
- throw new Error('Unsupported API output block.', { cause: item });
75
- }
76
- const outm = new Engine.Message.Output(parts);
77
- this.messageValidator.validateOutputMessage(outm);
78
- this.cacheOutputMessages.set(outm, raw);
79
- return outm;
80
- }
81
- }
82
- //# sourceMappingURL=message-codec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message-codec.js","sourceRoot":"","sources":["../../../src/engines/anthropic/message-codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG7C,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAGrC,MAAM,OAAO,YAAY;IAGX,sBAAsB,GAAG,IAAI,OAAO,EAAwD,CAAC;IAC7F,kBAAkB,GAAG,IAAI,OAAO,EAA4E,CAAC;IAC7G,mBAAmB,GAAG,IAAI,OAAO,EAA6E,CAAC;IAC/G,SAAS,CAAiB;IAC1B,gBAAgB,CAAoC;IAC9D,YAAmB,OAAkC;QACjD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IACrD,CAAC;IAEM,kBAAkB,CACrB,GAAmC;QAEnC,IAAI,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;QAC/E,IAAI,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;QAChD,MAAM,MAAM,GAAkC,EAAE,CAAC;QACjD,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,KAAK;YACxB,IAAI,IAAI,YAAY,IAAI;gBACpB,MAAM,CAAC,IAAI,CAAC;oBACR,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,IAAI,CAAC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,CAAC;QACD,MAAM,IAAI,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC9C,IAAI,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
@@ -1,3 +0,0 @@
1
- import { ToolChoice } from '../../tool-choice.ts';
2
- import Anthropic from '@anthropic-ai/sdk';
3
- export declare function encode(toolChoice: ToolChoice, parallelToolCall?: boolean): Anthropic.ToolChoice;
@@ -1,15 +0,0 @@
1
- import { ToolChoice } from "../../tool-choice.js";
2
- export function encode(toolChoice, parallelToolCall) {
3
- const disable_parallel_tool_use = typeof parallelToolCall === 'boolean' ? !parallelToolCall : undefined;
4
- if (toolChoice === ToolChoice.NONE)
5
- return { type: 'none' };
6
- else if (toolChoice === ToolChoice.REQUIRED)
7
- return { type: 'any', disable_parallel_tool_use };
8
- else if (toolChoice === ToolChoice.ANYONE)
9
- return { type: 'any', disable_parallel_tool_use };
10
- else if (toolChoice === ToolChoice.AUTO)
11
- return { type: 'auto', disable_parallel_tool_use };
12
- else
13
- throw new Error('Invalid tool choice');
14
- }
15
- //# sourceMappingURL=tool-choice-codec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool-choice-codec.js","sourceRoot":"","sources":["../../../src/engines/anthropic/tool-choice-codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIlD,MAAM,UAAU,MAAM,CAClB,UAAsB,EACtB,gBAA0B;IAE1B,MAAM,yBAAyB,GAAwB,OAAO,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAC;IAE7H,IAAI,UAAU,KAAK,UAAU,CAAC,IAAI;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;SACvD,IAAI,UAAU,KAAK,UAAU,CAAC,QAAQ;QAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,yBAAyB,EAAE,CAAC;SAC1F,IAAI,UAAU,KAAK,UAAU,CAAC,MAAM;QAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,yBAAyB,EAAE,CAAC;SACxF,IAAI,UAAU,KAAK,UAAU,CAAC,IAAI;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,yBAAyB,EAAE,CAAC;;QACvF,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;AAChD,CAAC"}
@@ -1,17 +0,0 @@
1
- import { Function } from '../../function.ts';
2
- import Anthropic from '@anthropic-ai/sdk';
3
- export declare class ToolCodec<in out fdm extends Function.Decl.Map.Proto> {
4
- protected fdm: fdm;
5
- protected rawfds: Anthropic.Tool[];
6
- constructor(options: ToolCodec.Options<fdm>);
7
- decodeFunctionCall(rawfc: Anthropic.ToolUseBlock): Function.Call.From<fdm>;
8
- encodeFunctionResponse(fr: Function.Response.From<fdm>): Anthropic.ToolResultBlockParam;
9
- encodeFunctionResponsePart(part: Function.Response.Successful.Part): Anthropic.TextBlockParam | Anthropic.ImageBlockParam | Anthropic.DocumentBlockParam;
10
- protected static encodeFunctionDeclarationEntry<fdu extends Function.Decl.Proto>(fdentry: Function.Decl.Entry.Of<fdu>): Anthropic.Tool;
11
- encodeFunctionDeclarationMap(): Anthropic.Tool[];
12
- }
13
- export declare namespace ToolCodec {
14
- interface Options<in out fdm extends Function.Decl.Map.Proto> {
15
- fdm: fdm;
16
- }
17
- }
@@ -1,96 +0,0 @@
1
- import { Function } from "../../function.js";
2
- import { Parse, ParseError } from 'typebox/schema';
3
- import { Engine } from "../../engine.js";
4
- import { Text } from "../../text.js";
5
- import { Media } from "../../media.js";
6
- export class ToolCodec {
7
- fdm;
8
- rawfds;
9
- constructor(options) {
10
- this.fdm = options.fdm;
11
- const fdentries = Object.entries(this.fdm);
12
- this.rawfds = fdentries.map(fdentry => ToolCodec.encodeFunctionDeclarationEntry(fdentry));
13
- }
14
- decodeFunctionCall(rawfc) {
15
- const fditem = this.fdm[rawfc.name];
16
- if (fditem) { }
17
- else
18
- throw new Engine.Exceptions.InferenceError('Unknown function call', { cause: rawfc });
19
- try {
20
- Parse(fditem.parameters, rawfc.input);
21
- }
22
- catch (e) {
23
- if (e instanceof ParseError)
24
- throw new Engine.Exceptions.InferenceError('Invalid arguments of function call.', { cause: e });
25
- else
26
- throw e;
27
- }
28
- return Function.Call.of({
29
- id: rawfc.id,
30
- name: rawfc.name,
31
- args: rawfc.input,
32
- });
33
- }
34
- encodeFunctionResponse(fr) {
35
- if (fr.id) { }
36
- else
37
- throw new Error();
38
- if (fr instanceof Function.Response.Successful)
39
- return {
40
- type: 'tool_result',
41
- tool_use_id: fr.id,
42
- content: fr.parts.map(part => this.encodeFunctionResponsePart(part)),
43
- };
44
- else if (fr instanceof Function.Response.Failed)
45
- return {
46
- type: 'tool_result',
47
- tool_use_id: fr.id,
48
- content: fr.error,
49
- };
50
- else
51
- throw new Error();
52
- }
53
- encodeFunctionResponsePart(part) {
54
- if (part instanceof Text)
55
- return {
56
- type: 'text',
57
- text: part.raw,
58
- };
59
- else if (part instanceof Media.Text)
60
- return {
61
- type: 'text',
62
- text: part.quote(),
63
- };
64
- else if (part instanceof Media.Image)
65
- return {
66
- type: 'image',
67
- source: {
68
- type: 'base64',
69
- data: String(part),
70
- media_type: String(part.mimeType.essence),
71
- },
72
- };
73
- else if (part instanceof Media.Pdf)
74
- return {
75
- type: 'document',
76
- source: {
77
- type: 'base64',
78
- data: String(part),
79
- media_type: 'application/pdf',
80
- },
81
- };
82
- else
83
- throw new Error('Unsupported function response part.', { cause: part });
84
- }
85
- static encodeFunctionDeclarationEntry(fdentry) {
86
- return {
87
- name: fdentry[0],
88
- description: fdentry[1].description,
89
- input_schema: fdentry[1].parameters,
90
- };
91
- }
92
- encodeFunctionDeclarationMap() {
93
- return this.rawfds.slice();
94
- }
95
- }
96
- //# sourceMappingURL=tool-codec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool-codec.js","sourceRoot":"","sources":["../../../src/engines/anthropic/tool-codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGvC,MAAM,OAAO,SAAS;IACR,GAAG,CAAM;IACT,MAAM,CAAmB;IACnC,YAAmB,OAA+B;QAC9C,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;QACvB,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAoC,CAAC;QAC9E,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,SAAS,CAAC,8BAA8B,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9F,CAAC;IAEM,kBAAkB,CACrB,KAA6B;QAE7B,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,MAAM,EAAE,CAAC,CAAA,CAAC;;YAAM,MAAM,IAAI,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,uBAAuB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1G,IAAI,CAAC;YACD,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,IAAI,CAAC,YAAY,UAAU;gBACvB,MAA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AAI,YAAY,KAAK,CAAC,KAAK;YAChC,OAAO;gBACH,IAAI,EAAE,OAAO;gBACb,MAAM,EAAE;oBACJ,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC;oBAClB,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAA8C;iBACzF;aACJ,CAAC;aACD,IAAI,IAAI,YAAY,KAAK,CAAC,GAAG;YAC9B,OAAO;gBACH,IAAI,EAAE,UAAU;gBAChB,MAAM,EAAE;oBACJ,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC;oBAClB,UAAU,EAAE,iBAAiB;iBAChC;aACJ,CAAC;;YACD,MAAM,IAAI,KAAK,CAAC,qCAAqC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACjF,CAAC;IAES,MAAM,CAAC,8BAA8B,CAC3C,OAAoC;QAEpC,OAAO;YACH,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;YAChB,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW;YACnC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,UAAmD;SAC/E,CAAC;IACN,CAAC;IAEM,4BAA4B;QAC/B,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;CACJ"}
@@ -1,35 +0,0 @@
1
- import { type InferenceOptions, type ProviderSpecs, Engine } from '../../engine.ts';
2
- import { Function } from '../../function.ts';
3
- import Anthropic from '@anthropic-ai/sdk';
4
- import { type InferenceContext } from '../../inference-context.ts';
5
- import { Throttle } from '../../throttle.ts';
6
- import type { MessageCodec } from './message-codec.ts';
7
- import type { Billing } from './billing.ts';
8
- import type { ToolCodec } from './tool-codec.ts';
9
- import type { ToolChoice } from '../../tool-choice.ts';
10
- export declare class Transport<in out fdm extends Function.Decl.Map.Proto> implements Engine.Transport<fdm> {
11
- protected client: Anthropic;
12
- protected providerSpec: ProviderSpecs;
13
- protected inferenceParams: InferenceOptions;
14
- protected fdm: fdm;
15
- protected throttle: Throttle;
16
- protected toolChoice: ToolChoice;
17
- protected messageCodec: MessageCodec<fdm>;
18
- protected toolCodec: ToolCodec<fdm>;
19
- protected billing: Billing;
20
- constructor(options: Transport.Options<fdm>);
21
- protected makeParams(session: Engine.Session.From<fdm>): Anthropic.MessageCreateParamsStreaming;
22
- fetch(wfctx: InferenceContext, session: Engine.Session.From<fdm>, signal?: AbortSignal): Promise<Engine.Message.Output.From<fdm>>;
23
- }
24
- export declare namespace Transport {
25
- interface Options<in out fdm extends Function.Decl.Map.Proto> {
26
- providerSpec: ProviderSpecs;
27
- inferenceParams: InferenceOptions;
28
- fdm: fdm;
29
- throttle: Throttle;
30
- toolChoice: ToolChoice;
31
- messageCodec: MessageCodec<fdm>;
32
- toolCodec: ToolCodec<fdm>;
33
- billing: Billing;
34
- }
35
- }
@@ -1,160 +0,0 @@
1
- import { Engine } from "../../engine.js";
2
- import Anthropic from '@anthropic-ai/sdk';
3
- import { loggers } from "../../telemetry.js";
4
- import * as ToolChoiceCodec from "./tool-choice-codec.js";
5
- import * as Undici from 'undici';
6
- export class Transport {
7
- client;
8
- providerSpec;
9
- inferenceParams;
10
- fdm;
11
- throttle;
12
- toolChoice;
13
- messageCodec;
14
- toolCodec;
15
- billing;
16
- constructor(options) {
17
- this.client = new Anthropic({
18
- baseURL: options.providerSpec.baseUrl,
19
- apiKey: options.providerSpec.apiKey,
20
- fetch: Undici.fetch,
21
- fetchOptions: { dispatcher: options.providerSpec.dispatcher },
22
- defaultHeaders: new Undici.Headers(options.inferenceParams.additionalHeaders),
23
- });
24
- this.providerSpec = options.providerSpec;
25
- this.inferenceParams = options.inferenceParams;
26
- this.fdm = options.fdm;
27
- this.throttle = options.throttle;
28
- this.toolChoice = options.toolChoice;
29
- this.messageCodec = options.messageCodec;
30
- this.toolCodec = options.toolCodec;
31
- this.billing = options.billing;
32
- }
33
- makeParams(session) {
34
- const tools = this.toolCodec.encodeFunctionDeclarationMap();
35
- return {
36
- model: this.inferenceParams.model,
37
- stream: true,
38
- messages: session.chatMessages.map(chatMessage => this.messageCodec.encodeChatMessage(chatMessage)),
39
- system: session.developerMessage && this.messageCodec.encodeDeveloperMessage(session.developerMessage),
40
- tools: tools.length ? tools : undefined,
41
- tool_choice: tools.length ? ToolChoiceCodec.encode(this.toolChoice, this.inferenceParams.parallelToolCall) : undefined,
42
- max_tokens: 64 * 1024,
43
- ...this.inferenceParams.additionalOptions,
44
- };
45
- }
46
- async fetch(wfctx, session, signal) {
47
- await this.throttle.requests(wfctx);
48
- const params = this.makeParams(session);
49
- loggers.message.debug(params);
50
- let response = null;
51
- try {
52
- const stream = this.client.messages.stream(params, {
53
- signal,
54
- fetchOptions: { dispatcher: this.providerSpec.dispatcher },
55
- });
56
- for await (const event of stream) {
57
- loggers.stream.trace(event);
58
- if (event.type === 'message_start') {
59
- response = structuredClone(event.message);
60
- }
61
- else {
62
- if (response) { }
63
- else
64
- throw new Error();
65
- if (event.type === 'message_delta') {
66
- response.stop_sequence = event.delta.stop_sequence ?? response.stop_sequence;
67
- response.stop_reason = event.delta.stop_reason ?? response.stop_reason;
68
- response.usage.input_tokens = event.usage.input_tokens ?? response.usage.input_tokens;
69
- response.usage.output_tokens = event.usage.output_tokens;
70
- response.usage.cache_read_input_tokens = event.usage.cache_read_input_tokens ?? response.usage.cache_read_input_tokens;
71
- response.usage.cache_creation_input_tokens = event.usage.cache_creation_input_tokens ?? response.usage.cache_creation_input_tokens;
72
- response.usage.server_tool_use = event.usage.server_tool_use ?? response.usage.server_tool_use;
73
- }
74
- else if (event.type === 'message_stop') {
75
- }
76
- else if (event.type === 'content_block_start') {
77
- const contentBlock = structuredClone(event.content_block);
78
- response.content.push(contentBlock);
79
- if (contentBlock.type === 'tool_use')
80
- contentBlock.input = '';
81
- }
82
- else if (event.type === 'content_block_delta') {
83
- const contentBlock = response.content[event.index];
84
- if (event.delta.type === 'text_delta') {
85
- if (contentBlock?.type === 'text') { }
86
- else
87
- throw new Error();
88
- contentBlock.text += event.delta.text;
89
- }
90
- else if (event.delta.type === 'thinking_delta') {
91
- if (contentBlock?.type === 'thinking') { }
92
- else
93
- throw new Error();
94
- contentBlock.thinking += event.delta.thinking;
95
- }
96
- else if (event.delta.type === 'signature_delta') {
97
- if (contentBlock?.type === 'thinking') { }
98
- else
99
- throw new Error();
100
- contentBlock.signature += event.delta.signature;
101
- }
102
- else if (event.delta.type === 'input_json_delta') {
103
- if (contentBlock?.type === 'tool_use') { }
104
- else
105
- throw new Error();
106
- if (typeof contentBlock.input === 'string') { }
107
- else
108
- throw new Error();
109
- contentBlock.input += event.delta.partial_json;
110
- }
111
- else
112
- throw new Error('Unknown type of content block delta', { cause: event.delta });
113
- }
114
- else if (event.type === 'content_block_stop') {
115
- const contentBlock = response.content[event.index];
116
- if (contentBlock?.type === 'text')
117
- loggers.inference.info(contentBlock.text);
118
- else if (contentBlock?.type === 'thinking')
119
- loggers.inference.debug(contentBlock.thinking);
120
- if (contentBlock?.type === 'tool_use') {
121
- if (typeof contentBlock.input === 'string') { }
122
- else
123
- throw new Error();
124
- try {
125
- contentBlock.input = JSON.parse(contentBlock.input);
126
- }
127
- catch (e) {
128
- throw new Engine.Exceptions.InferenceError('Invalid JSON of tool use input', { cause: contentBlock.input });
129
- }
130
- loggers.message.info(contentBlock);
131
- }
132
- }
133
- else
134
- throw new Error('Unknown stream event', { cause: event });
135
- }
136
- }
137
- }
138
- catch (e) {
139
- if (e instanceof Anthropic.APIError)
140
- throw new Engine.Exceptions.APIError(undefined, { cause: e });
141
- else if (e instanceof TypeError)
142
- throw new Engine.Exceptions.APIError(undefined, { cause: e });
143
- else
144
- throw e;
145
- }
146
- if (response) { }
147
- else
148
- throw new Error();
149
- loggers.message.debug(response);
150
- if (response.stop_reason === 'max_tokens')
151
- throw new Engine.Exceptions.InferenceError('Token limit exceeded.', { cause: response });
152
- if (response.stop_reason === 'end_turn' || response.stop_reason === 'tool_use') { }
153
- else
154
- throw new Engine.Exceptions.InferenceError('Abnormal stop reason', { cause: response });
155
- loggers.message.info(response.usage);
156
- await wfctx.cost?.(this.billing.charge(response.usage));
157
- return this.messageCodec.decodeOutputMessage(response.content);
158
- }
159
- }
160
- //# sourceMappingURL=transport.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../src/engines/anthropic/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6C,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEpF,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAG1C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAI7C,OAAO,KAAK,eAAe,MAAM,wBAAwB,CAAC;AAE1D,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAGjC,MAAM,OAAO,SAAS;IAGR,MAAM,CAAY;IAClB,YAAY,CAAgB;IAC5B,eAAe,CAAmB;IAClC,GAAG,CAAM;IACT,QAAQ,CAAW;IACnB,UAAU,CAAa;IACvB,YAAY,CAAoB;IAChC,SAAS,CAAiB;IAC1B,OAAO,CAAU;IAE3B,YAAmB,OAA+B;QAC9C,IAAI,CAAC,MAAM,GAAG,IAAI,SAAS,CAAC;YACxB,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,OAAO;YACrC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,MAAM;YACnC,KAAK,EAAE,MAAM,CAAC,KAAgC;YAC9C,YAAY,EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,YAAY,CAAC,UAAU,EAAE;YAC7D,cAAc,EAAE,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC;SAChF,CAAC,CAAC;QACH,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;QAC/C,IAAI,CAAC,GAA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AC,cAAc,CAAC,uBAAuB,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC7F,IAAI,QAAQ,CAAC,WAAW,KAAK,UAAU,IAAI,QAAQ,CAAC,WAAW,KAAK,UAAU,EAAE,CAAC,CAAA,CAAC;;YAC9E,MAAM,IAAI,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,sBAAsB,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC5F,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACrC,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QAExD,OAAO,IAAI,CAAC,YAAY,CAAC,mBAAmB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACnE,CAAC;CACJ"}
@@ -1,19 +0,0 @@
1
- import { Engine } from '../engine.ts';
2
- import { Function } from '../function.ts';
3
- import { ToolCodec } from './anthropic/tool-codec.ts';
4
- import { Billing } from './anthropic/billing.ts';
5
- import { MessageCodec } from './anthropic/message-codec.ts';
6
- import * as TransportModule from './anthropic/transport.ts';
7
- export type AnthropicEngine<fdm extends Function.Decl.Map.Proto> = AnthropicEngine.Instance<fdm>;
8
- export declare namespace AnthropicEngine {
9
- class Instance<in out fdm extends Function.Decl.Map.Proto> extends Engine.Instance<fdm> {
10
- protected options: Engine.Options<fdm>;
11
- protected toolCodec: ToolCodec<fdm>;
12
- protected messageCodec: MessageCodec<fdm>;
13
- protected billing: Billing;
14
- protected transport: Transport<fdm>;
15
- constructor(options: Engine.Options<fdm>);
16
- }
17
- function create<fdm extends Function.Decl.Map.Proto>(options: Engine.Options<fdm>): Engine<fdm>;
18
- export import Transport = TransportModule.Transport;
19
- }
@@ -1,43 +0,0 @@
1
- import { Engine } from "../engine.js";
2
- import { ToolCodec } from "./anthropic/tool-codec.js";
3
- import { Billing } from "./anthropic/billing.js";
4
- import { MessageCodec } from "./anthropic/message-codec.js";
5
- import * as TransportModule from "./anthropic/transport.js";
6
- export var AnthropicEngine;
7
- (function (AnthropicEngine) {
8
- class Instance extends Engine.Instance {
9
- options;
10
- toolCodec;
11
- messageCodec;
12
- billing;
13
- transport;
14
- constructor(options) {
15
- super(options);
16
- this.options = options;
17
- this.toolCodec = new ToolCodec({ fdm: this.fdm });
18
- this.messageCodec = new MessageCodec({
19
- toolCodec: this.toolCodec,
20
- messageValidator: this.messageValidator,
21
- });
22
- this.billing = new Billing({ pricing: this.pricing });
23
- this.transport = new AnthropicEngine.Transport({
24
- providerSpec: this.providerSpecs,
25
- inferenceParams: this.inferenceOptions,
26
- fdm: this.fdm,
27
- throttle: this.throttle,
28
- toolChoice: this.toolChoice,
29
- messageCodec: this.messageCodec,
30
- toolCodec: this.toolCodec,
31
- billing: this.billing,
32
- });
33
- }
34
- }
35
- AnthropicEngine.Instance = Instance;
36
- create;
37
- function create(options) {
38
- return new Instance(options);
39
- }
40
- AnthropicEngine.create = create;
41
- AnthropicEngine.Transport = TransportModule.Transport;
42
- })(AnthropicEngine || (AnthropicEngine = {}));
43
- //# sourceMappingURL=anthropic.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/engines/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,KAAK,eAAe,MAAM,0BAA0B,CAAC;AAM5D,MAAM,KAAW,eAAe,CAsC/B;AAtCD,WAAiB,eAAe;IAC5B,MAAa,QAEX,SAAQ,MAAM,CAAC,QAAa;QAMG;QALnB,SAAS,CAAiB;QAC1B,YA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