@langchain/core 1.2.5 → 1.2.7

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 (80) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/language_models/base.cjs +1 -1
  3. package/dist/language_models/base.js +1 -1
  4. package/dist/messages/ai.cjs +6 -0
  5. package/dist/messages/ai.cjs.map +1 -1
  6. package/dist/messages/ai.d.cts +3 -1
  7. package/dist/messages/ai.d.cts.map +1 -1
  8. package/dist/messages/ai.d.ts +3 -1
  9. package/dist/messages/ai.d.ts.map +1 -1
  10. package/dist/messages/ai.js +6 -0
  11. package/dist/messages/ai.js.map +1 -1
  12. package/dist/messages/base.cjs +6 -0
  13. package/dist/messages/base.cjs.map +1 -1
  14. package/dist/messages/base.d.cts +3 -1
  15. package/dist/messages/base.d.cts.map +1 -1
  16. package/dist/messages/base.d.ts +3 -1
  17. package/dist/messages/base.d.ts.map +1 -1
  18. package/dist/messages/base.js +6 -0
  19. package/dist/messages/base.js.map +1 -1
  20. package/dist/messages/chat.cjs +6 -0
  21. package/dist/messages/chat.cjs.map +1 -1
  22. package/dist/messages/chat.d.cts +3 -1
  23. package/dist/messages/chat.d.cts.map +1 -1
  24. package/dist/messages/chat.d.ts +3 -1
  25. package/dist/messages/chat.d.ts.map +1 -1
  26. package/dist/messages/chat.js +6 -0
  27. package/dist/messages/chat.js.map +1 -1
  28. package/dist/messages/function.cjs +12 -0
  29. package/dist/messages/function.cjs.map +1 -1
  30. package/dist/messages/function.d.cts +5 -1
  31. package/dist/messages/function.d.cts.map +1 -1
  32. package/dist/messages/function.d.ts +5 -1
  33. package/dist/messages/function.d.ts.map +1 -1
  34. package/dist/messages/function.js +12 -0
  35. package/dist/messages/function.js.map +1 -1
  36. package/dist/messages/human.cjs +6 -0
  37. package/dist/messages/human.cjs.map +1 -1
  38. package/dist/messages/human.d.cts +3 -1
  39. package/dist/messages/human.d.cts.map +1 -1
  40. package/dist/messages/human.d.ts +3 -1
  41. package/dist/messages/human.d.ts.map +1 -1
  42. package/dist/messages/human.js +6 -0
  43. package/dist/messages/human.js.map +1 -1
  44. package/dist/messages/modifier.cjs +3 -0
  45. package/dist/messages/modifier.cjs.map +1 -1
  46. package/dist/messages/modifier.d.cts +1 -0
  47. package/dist/messages/modifier.d.cts.map +1 -1
  48. package/dist/messages/modifier.d.ts +1 -0
  49. package/dist/messages/modifier.d.ts.map +1 -1
  50. package/dist/messages/modifier.js +3 -0
  51. package/dist/messages/modifier.js.map +1 -1
  52. package/dist/messages/system.cjs +6 -0
  53. package/dist/messages/system.cjs.map +1 -1
  54. package/dist/messages/system.d.cts +3 -1
  55. package/dist/messages/system.d.cts.map +1 -1
  56. package/dist/messages/system.d.ts +3 -1
  57. package/dist/messages/system.d.ts.map +1 -1
  58. package/dist/messages/system.js +6 -0
  59. package/dist/messages/system.js.map +1 -1
  60. package/dist/messages/tool.cjs +9 -0
  61. package/dist/messages/tool.cjs.map +1 -1
  62. package/dist/messages/tool.d.cts +4 -1
  63. package/dist/messages/tool.d.cts.map +1 -1
  64. package/dist/messages/tool.d.ts +4 -1
  65. package/dist/messages/tool.d.ts.map +1 -1
  66. package/dist/messages/tool.js +9 -0
  67. package/dist/messages/tool.js.map +1 -1
  68. package/dist/utils/gateway.cjs +5 -1
  69. package/dist/utils/gateway.cjs.map +1 -1
  70. package/dist/utils/gateway.d.cts +2 -1
  71. package/dist/utils/gateway.d.cts.map +1 -1
  72. package/dist/utils/gateway.d.ts +2 -1
  73. package/dist/utils/gateway.d.ts.map +1 -1
  74. package/dist/utils/gateway.js +5 -2
  75. package/dist/utils/gateway.js.map +1 -1
  76. package/dist/utils/namespace.cjs +3 -0
  77. package/dist/utils/namespace.cjs.map +1 -1
  78. package/dist/utils/namespace.js +3 -0
  79. package/dist/utils/namespace.js.map +1 -1
  80. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import { BaseMessage, BaseMessageChunk, BaseMessageFields } from "./base.js";
2
- import { $InferMessageContent, MessageStructure } from "./message.js";
2
+ import { $InferMessageContent, MessageStructure, MessageToolSet } from "./message.js";
3
3
  //#region src/messages/human.d.ts
4
4
  interface HumanMessageFields<TStructure extends MessageStructure = MessageStructure> extends BaseMessageFields<TStructure, "human"> {}
5
5
  /**
@@ -10,6 +10,7 @@ declare class HumanMessage<TStructure extends MessageStructure = MessageStructur
10
10
  readonly type: "human";
11
11
  constructor(fields: $InferMessageContent<TStructure, "human"> | HumanMessageFields<TStructure>);
12
12
  static isInstance(obj: unknown): obj is HumanMessage;
13
+ static [Symbol.hasInstance](obj: unknown): obj is HumanMessage<MessageStructure<MessageToolSet>>;
13
14
  }
14
15
  /**
15
16
  * Represents a chunk of a human message, which can be concatenated with
@@ -21,6 +22,7 @@ declare class HumanMessageChunk<TStructure extends MessageStructure = MessageStr
21
22
  constructor(fields: $InferMessageContent<TStructure, "human"> | HumanMessageFields<TStructure>);
22
23
  concat(chunk: HumanMessageChunk<TStructure>): this;
23
24
  static isInstance(obj: unknown): obj is HumanMessageChunk;
25
+ static [Symbol.hasInstance](obj: unknown): obj is HumanMessageChunk<MessageStructure<MessageToolSet>>;
24
26
  }
25
27
  /**
26
28
  * @deprecated Use {@link HumanMessage.isInstance} instead
@@ -1 +1 @@
1
- {"version":3,"file":"human.d.ts","names":[],"sources":["../../src/messages/human.ts"],"mappings":";;;UAUiB,mBACf,mBAAmB,mBAAmB,0BAC9B,kBAAkB;;;;cAKf,aACX,mBAAmB,mBAAmB,0BAC9B,YAAY;SACb;WAIE;EAET,YACE,QACI,qBAAqB,uBACrB,mBAAmB;SAKlB,WAAW,eAAe,OAAO;;;;;;cAS7B,kBACX,mBAAmB,mBAAmB,0BAC9B,iBAAiB;SAClB;WAIE;EAET,YACE,QACI,qBAAqB,uBACrB,mBAAmB;EAKzB,OAAO,OAAO,kBAAkB;SAgBzB,WAAW,eAAe,OAAO;;;;;iBAQ1B,eAAe,mBAAmB,kBAChD,GAAG,cACF,KAAK,aAAa;;;;iBAOL,oBAAoB,mBAAmB,kBACrD,GAAG,mBACF,KAAK,kBAAkB"}
1
+ {"version":3,"file":"human.d.ts","names":[],"sources":["../../src/messages/human.ts"],"mappings":";;;UAUiB,mBACf,mBAAmB,mBAAmB,0BAC9B,kBAAkB;;;;cAKf,aACX,mBAAmB,mBAAmB,0BAC9B,YAAY;SACb;WAIE;EAET,YACE,QACI,qBAAqB,uBACrB,mBAAmB;SAKlB,WAAW,eAAe,OAAO;UAIhC,OAAO,aAAa,eAAY,OAAA,aAAA,iBAJA;;;;;;cAa7B,kBACX,mBAAmB,mBAAmB,0BAC9B,iBAAiB;SAClB;WAIE;EAET,YACE,QACI,qBAAqB,uBACrB,mBAAmB;EAKzB,OAAO,OAAO,kBAAkB;SAgBzB,WAAW,eAAe,OAAO;UAIhC,OAAO,aAAa,eAAY,OAAA,kBAAA,iBAJA;;;;;iBAY1B,eAAe,mBAAmB,kBAChD,GAAG,cACF,KAAK,aAAa;;;;iBAOL,oBAAoB,mBAAmB,kBACrD,GAAG,mBACF,KAAK,kBAAkB"}
@@ -14,6 +14,9 @@ var HumanMessage = class extends BaseMessage {
14
14
  static isInstance(obj) {
15
15
  return super.isInstance(obj) && obj.type === "human";
16
16
  }
17
+ static [Symbol.hasInstance](obj) {
18
+ return this.isInstance(obj);
19
+ }
17
20
  };
18
21
  /**
19
22
  * Represents a chunk of a human message, which can be concatenated with
@@ -39,6 +42,9 @@ var HumanMessageChunk = class extends BaseMessageChunk {
39
42
  static isInstance(obj) {
40
43
  return super.isInstance(obj) && obj.type === "human";
41
44
  }
45
+ static [Symbol.hasInstance](obj) {
46
+ return this.isInstance(obj);
47
+ }
42
48
  };
43
49
  /**
44
50
  * @deprecated Use {@link HumanMessage.isInstance} instead
@@ -1 +1 @@
1
- {"version":3,"file":"human.js","names":[],"sources":["../../src/messages/human.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageChunk,\n mergeContent,\n _mergeDicts,\n type BaseMessageFields,\n} from \"./base.js\";\nimport type { $InferMessageContent, MessageStructure } from \"./message.js\";\nimport { Constructor } from \"./utils.js\";\n\nexport interface HumanMessageFields<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageFields<TStructure, \"human\"> {}\n\n/**\n * Represents a human message in a conversation.\n */\nexport class HumanMessage<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessage<TStructure, \"human\"> {\n static lc_name() {\n return \"HumanMessage\";\n }\n\n readonly type = \"human\" as const;\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"human\">\n | HumanMessageFields<TStructure>\n ) {\n super(fields);\n }\n\n static isInstance(obj: unknown): obj is HumanMessage {\n return super.isInstance(obj) && obj.type === \"human\";\n }\n}\n\n/**\n * Represents a chunk of a human message, which can be concatenated with\n * other human message chunks.\n */\nexport class HumanMessageChunk<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageChunk<TStructure, \"human\"> {\n static lc_name() {\n return \"HumanMessageChunk\";\n }\n\n readonly type = \"human\" as const;\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"human\">\n | HumanMessageFields<TStructure>\n ) {\n super(fields);\n }\n\n concat(chunk: HumanMessageChunk<TStructure>) {\n const Cls = this.constructor as Constructor<this>;\n return new Cls({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: _mergeDicts(\n this.additional_kwargs,\n chunk.additional_kwargs\n ),\n response_metadata: _mergeDicts(\n this.response_metadata,\n chunk.response_metadata\n ),\n id: this.id ?? chunk.id,\n });\n }\n\n static isInstance(obj: unknown): obj is HumanMessageChunk {\n return super.isInstance(obj) && obj.type === \"human\";\n }\n}\n\n/**\n * @deprecated Use {@link HumanMessage.isInstance} instead\n */\nexport function isHumanMessage<TStructure extends MessageStructure>(\n x: BaseMessage\n): x is HumanMessage<TStructure> {\n return x.getType() === \"human\";\n}\n\n/**\n * @deprecated Use {@link HumanMessageChunk.isInstance} instead\n */\nexport function isHumanMessageChunk<TStructure extends MessageStructure>(\n x: BaseMessageChunk\n): x is HumanMessageChunk<TStructure> {\n return x.getType() === \"human\";\n}\n"],"mappings":";;;;;AAiBA,IAAa,eAAb,cAEU,YAAiC;CACzC,OAAO,UAAU;EACf,OAAO;CACT;CAEA,OAAgB;CAEhB,YACE,QAGA;EACA,MAAM,MAAM;CACd;CAEA,OAAO,WAAW,KAAmC;EACnD,OAAO,MAAM,WAAW,GAAG,KAAK,IAAI,SAAS;CAC/C;AACF;;;;;AAMA,IAAa,oBAAb,cAEU,iBAAsC;CAC9C,OAAO,UAAU;EACf,OAAO;CACT;CAEA,OAAgB;CAEhB,YACE,QAGA;EACA,MAAM,MAAM;CACd;CAEA,OAAO,OAAsC;EAC3C,MAAM,MAAM,KAAK;EACjB,OAAO,IAAI,IAAI;GACb,SAAS,aAAa,KAAK,SAAS,MAAM,OAAO;GACjD,mBAAmB,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,mBAAmB,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,IAAI,KAAK,MAAM,MAAM;EACvB,CAAC;CACH;CAEA,OAAO,WAAW,KAAwC;EACxD,OAAO,MAAM,WAAW,GAAG,KAAK,IAAI,SAAS;CAC/C;AACF;;;;AAKA,SAAgB,eACd,GAC+B;CAC/B,OAAO,EAAE,QAAQ,MAAM;AACzB;;;;AAKA,SAAgB,oBACd,GACoC;CACpC,OAAO,EAAE,QAAQ,MAAM;AACzB"}
1
+ {"version":3,"file":"human.js","names":[],"sources":["../../src/messages/human.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageChunk,\n mergeContent,\n _mergeDicts,\n type BaseMessageFields,\n} from \"./base.js\";\nimport type { $InferMessageContent, MessageStructure } from \"./message.js\";\nimport { Constructor } from \"./utils.js\";\n\nexport interface HumanMessageFields<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageFields<TStructure, \"human\"> {}\n\n/**\n * Represents a human message in a conversation.\n */\nexport class HumanMessage<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessage<TStructure, \"human\"> {\n static lc_name() {\n return \"HumanMessage\";\n }\n\n readonly type = \"human\" as const;\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"human\">\n | HumanMessageFields<TStructure>\n ) {\n super(fields);\n }\n\n static isInstance(obj: unknown): obj is HumanMessage {\n return super.isInstance(obj) && obj.type === \"human\";\n }\n\n static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\n }\n}\n\n/**\n * Represents a chunk of a human message, which can be concatenated with\n * other human message chunks.\n */\nexport class HumanMessageChunk<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageChunk<TStructure, \"human\"> {\n static lc_name() {\n return \"HumanMessageChunk\";\n }\n\n readonly type = \"human\" as const;\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"human\">\n | HumanMessageFields<TStructure>\n ) {\n super(fields);\n }\n\n concat(chunk: HumanMessageChunk<TStructure>) {\n const Cls = this.constructor as Constructor<this>;\n return new Cls({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: _mergeDicts(\n this.additional_kwargs,\n chunk.additional_kwargs\n ),\n response_metadata: _mergeDicts(\n this.response_metadata,\n chunk.response_metadata\n ),\n id: this.id ?? chunk.id,\n });\n }\n\n static isInstance(obj: unknown): obj is HumanMessageChunk {\n return super.isInstance(obj) && obj.type === \"human\";\n }\n\n static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\n }\n}\n\n/**\n * @deprecated Use {@link HumanMessage.isInstance} instead\n */\nexport function isHumanMessage<TStructure extends MessageStructure>(\n x: BaseMessage\n): x is HumanMessage<TStructure> {\n return x.getType() === \"human\";\n}\n\n/**\n * @deprecated Use {@link HumanMessageChunk.isInstance} instead\n */\nexport function isHumanMessageChunk<TStructure extends MessageStructure>(\n x: BaseMessageChunk\n): x is HumanMessageChunk<TStructure> {\n return x.getType() === \"human\";\n}\n"],"mappings":";;;;;AAiBA,IAAa,eAAb,cAEU,YAAiC;CACzC,OAAO,UAAU;EACf,OAAO;CACT;CAEA,OAAgB;CAEhB,YACE,QAGA;EACA,MAAM,MAAM;CACd;CAEA,OAAO,WAAW,KAAmC;EACnD,OAAO,MAAM,WAAW,GAAG,KAAK,IAAI,SAAS;CAC/C;CAEA,QAAQ,OAAO,aAAa,KAAc;EACxC,OAAO,KAAK,WAAW,GAAG;CAC5B;AACF;;;;;AAMA,IAAa,oBAAb,cAEU,iBAAsC;CAC9C,OAAO,UAAU;EACf,OAAO;CACT;CAEA,OAAgB;CAEhB,YACE,QAGA;EACA,MAAM,MAAM;CACd;CAEA,OAAO,OAAsC;EAC3C,MAAM,MAAM,KAAK;EACjB,OAAO,IAAI,IAAI;GACb,SAAS,aAAa,KAAK,SAAS,MAAM,OAAO;GACjD,mBAAmB,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,mBAAmB,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,IAAI,KAAK,MAAM,MAAM;EACvB,CAAC;CACH;CAEA,OAAO,WAAW,KAAwC;EACxD,OAAO,MAAM,WAAW,GAAG,KAAK,IAAI,SAAS;CAC/C;CAEA,QAAQ,OAAO,aAAa,KAAc;EACxC,OAAO,KAAK,WAAW,GAAG;CAC5B;AACF;;;;AAKA,SAAgB,eACd,GAC+B;CAC/B,OAAO,EAAE,QAAQ,MAAM;AACzB;;;;AAKA,SAAgB,oBACd,GACoC;CACpC,OAAO,EAAE,QAAQ,MAAM;AACzB"}
@@ -31,6 +31,9 @@ var RemoveMessage = class extends require_base.BaseMessage {
31
31
  static isInstance(obj) {
32
32
  return super.isInstance(obj) && obj.type === "remove";
33
33
  }
34
+ static [Symbol.hasInstance](obj) {
35
+ return this.isInstance(obj);
36
+ }
34
37
  };
35
38
  //#endregion
36
39
  exports.RemoveMessage = RemoveMessage;
@@ -1 +1 @@
1
- {"version":3,"file":"modifier.cjs","names":["BaseMessage"],"sources":["../../src/messages/modifier.ts"],"sourcesContent":["import { BaseMessage, BaseMessageFields } from \"./base.js\";\n\nexport interface RemoveMessageFields extends Omit<\n BaseMessageFields,\n \"content\"\n> {\n /**\n * The ID of the message to remove.\n */\n id: string;\n}\n\n/**\n * Message responsible for deleting other messages.\n *\n * `RemoveMessage` is intentionally not generic over `MessageStructure`.\n * Its content is always `[]` (empty), so carrying a structure type parameter\n * would only cause unnecessary type incompatibilities when mixing messages\n * from different structure configurations (e.g. passing a `RemoveMessage`\n * into an API that expects `Message<CustomToolCall>`).\n */\nexport class RemoveMessage extends BaseMessage {\n readonly type = \"remove\" as const;\n\n /**\n * The ID of the message to remove.\n */\n id: string;\n\n constructor(fields: RemoveMessageFields) {\n super({\n ...fields,\n content: [],\n });\n this.id = fields.id;\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n id: this.id,\n };\n }\n\n static isInstance(obj: unknown): obj is RemoveMessage {\n return super.isInstance(obj) && obj.type === \"remove\";\n }\n}\n"],"mappings":";;;;;;;;;;;AAqBA,IAAa,gBAAb,cAAmCA,aAAAA,YAAY;CAC7C,OAAgB;;;;CAKhB;CAEA,YAAY,QAA6B;EACvC,MAAM;GACJ,GAAG;GACH,SAAS,CAAC;EACZ,CAAC;EACD,KAAK,KAAK,OAAO;CACnB;CAEA,IAAa,mBAA4C;EACvD,OAAO;GACL,GAAG,MAAM;GACT,IAAI,KAAK;EACX;CACF;CAEA,OAAO,WAAW,KAAoC;EACpD,OAAO,MAAM,WAAW,GAAG,KAAK,IAAI,SAAS;CAC/C;AACF"}
1
+ {"version":3,"file":"modifier.cjs","names":["BaseMessage"],"sources":["../../src/messages/modifier.ts"],"sourcesContent":["import { BaseMessage, BaseMessageFields } from \"./base.js\";\n\nexport interface RemoveMessageFields extends Omit<\n BaseMessageFields,\n \"content\"\n> {\n /**\n * The ID of the message to remove.\n */\n id: string;\n}\n\n/**\n * Message responsible for deleting other messages.\n *\n * `RemoveMessage` is intentionally not generic over `MessageStructure`.\n * Its content is always `[]` (empty), so carrying a structure type parameter\n * would only cause unnecessary type incompatibilities when mixing messages\n * from different structure configurations (e.g. passing a `RemoveMessage`\n * into an API that expects `Message<CustomToolCall>`).\n */\nexport class RemoveMessage extends BaseMessage {\n readonly type = \"remove\" as const;\n\n /**\n * The ID of the message to remove.\n */\n id: string;\n\n constructor(fields: RemoveMessageFields) {\n super({\n ...fields,\n content: [],\n });\n this.id = fields.id;\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n id: this.id,\n };\n }\n\n static isInstance(obj: unknown): obj is RemoveMessage {\n return super.isInstance(obj) && obj.type === \"remove\";\n }\n\n static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\n }\n}\n"],"mappings":";;;;;;;;;;;AAqBA,IAAa,gBAAb,cAAmCA,aAAAA,YAAY;CAC7C,OAAgB;;;;CAKhB;CAEA,YAAY,QAA6B;EACvC,MAAM;GACJ,GAAG;GACH,SAAS,CAAC;EACZ,CAAC;EACD,KAAK,KAAK,OAAO;CACnB;CAEA,IAAa,mBAA4C;EACvD,OAAO;GACL,GAAG,MAAM;GACT,IAAI,KAAK;EACX;CACF;CAEA,OAAO,WAAW,KAAoC;EACpD,OAAO,MAAM,WAAW,GAAG,KAAK,IAAI,SAAS;CAC/C;CAEA,QAAQ,OAAO,aAAa,KAAc;EACxC,OAAO,KAAK,WAAW,GAAG;CAC5B;AACF"}
@@ -24,6 +24,7 @@ declare class RemoveMessage extends BaseMessage {
24
24
  constructor(fields: RemoveMessageFields);
25
25
  get _printableFields(): Record<string, unknown>;
26
26
  static isInstance(obj: unknown): obj is RemoveMessage;
27
+ static [Symbol.hasInstance](obj: unknown): obj is RemoveMessage;
27
28
  }
28
29
  //#endregion
29
30
  export { RemoveMessage, RemoveMessageFields };
@@ -1 +1 @@
1
- {"version":3,"file":"modifier.d.cts","names":[],"sources":["../../src/messages/modifier.ts"],"mappings":";;UAEiB,4BAA4B,KAC3C;;;;EAMA;;;;;;;;;;;cAYW,sBAAsB;WACxB;;;;EAKT;EAEA,YAAY,QAAQ;MAQP,oBAAoB;SAO1B,WAAW,eAAe,OAAO"}
1
+ {"version":3,"file":"modifier.d.cts","names":[],"sources":["../../src/messages/modifier.ts"],"mappings":";;UAEiB,4BAA4B,KAC3C;;;;EAMA;;;;;;;;;;;cAYW,sBAAsB;WACxB;;;;EAKT;EAEA,YAAY,QAAQ;MAQP,oBAAoB;SAO1B,WAAW,eAAe,OAAO;UAIhC,OAAO,aAAa,eAAY,OAAA"}
@@ -24,6 +24,7 @@ declare class RemoveMessage extends BaseMessage {
24
24
  constructor(fields: RemoveMessageFields);
25
25
  get _printableFields(): Record<string, unknown>;
26
26
  static isInstance(obj: unknown): obj is RemoveMessage;
27
+ static [Symbol.hasInstance](obj: unknown): obj is RemoveMessage;
27
28
  }
28
29
  //#endregion
29
30
  export { RemoveMessage, RemoveMessageFields };
@@ -1 +1 @@
1
- {"version":3,"file":"modifier.d.ts","names":[],"sources":["../../src/messages/modifier.ts"],"mappings":";;UAEiB,4BAA4B,KAC3C;;;;EAMA;;;;;;;;;;;cAYW,sBAAsB;WACxB;;;;EAKT;EAEA,YAAY,QAAQ;MAQP,oBAAoB;SAO1B,WAAW,eAAe,OAAO"}
1
+ {"version":3,"file":"modifier.d.ts","names":[],"sources":["../../src/messages/modifier.ts"],"mappings":";;UAEiB,4BAA4B,KAC3C;;;;EAMA;;;;;;;;;;;cAYW,sBAAsB;WACxB;;;;EAKT;EAEA,YAAY,QAAQ;MAQP,oBAAoB;SAO1B,WAAW,eAAe,OAAO;UAIhC,OAAO,aAAa,eAAY,OAAA"}
@@ -31,6 +31,9 @@ var RemoveMessage = class extends BaseMessage {
31
31
  static isInstance(obj) {
32
32
  return super.isInstance(obj) && obj.type === "remove";
33
33
  }
34
+ static [Symbol.hasInstance](obj) {
35
+ return this.isInstance(obj);
36
+ }
34
37
  };
35
38
  //#endregion
36
39
  export { RemoveMessage };
@@ -1 +1 @@
1
- {"version":3,"file":"modifier.js","names":[],"sources":["../../src/messages/modifier.ts"],"sourcesContent":["import { BaseMessage, BaseMessageFields } from \"./base.js\";\n\nexport interface RemoveMessageFields extends Omit<\n BaseMessageFields,\n \"content\"\n> {\n /**\n * The ID of the message to remove.\n */\n id: string;\n}\n\n/**\n * Message responsible for deleting other messages.\n *\n * `RemoveMessage` is intentionally not generic over `MessageStructure`.\n * Its content is always `[]` (empty), so carrying a structure type parameter\n * would only cause unnecessary type incompatibilities when mixing messages\n * from different structure configurations (e.g. passing a `RemoveMessage`\n * into an API that expects `Message<CustomToolCall>`).\n */\nexport class RemoveMessage extends BaseMessage {\n readonly type = \"remove\" as const;\n\n /**\n * The ID of the message to remove.\n */\n id: string;\n\n constructor(fields: RemoveMessageFields) {\n super({\n ...fields,\n content: [],\n });\n this.id = fields.id;\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n id: this.id,\n };\n }\n\n static isInstance(obj: unknown): obj is RemoveMessage {\n return super.isInstance(obj) && obj.type === \"remove\";\n }\n}\n"],"mappings":";;;;;;;;;;;AAqBA,IAAa,gBAAb,cAAmC,YAAY;CAC7C,OAAgB;;;;CAKhB;CAEA,YAAY,QAA6B;EACvC,MAAM;GACJ,GAAG;GACH,SAAS,CAAC;EACZ,CAAC;EACD,KAAK,KAAK,OAAO;CACnB;CAEA,IAAa,mBAA4C;EACvD,OAAO;GACL,GAAG,MAAM;GACT,IAAI,KAAK;EACX;CACF;CAEA,OAAO,WAAW,KAAoC;EACpD,OAAO,MAAM,WAAW,GAAG,KAAK,IAAI,SAAS;CAC/C;AACF"}
1
+ {"version":3,"file":"modifier.js","names":[],"sources":["../../src/messages/modifier.ts"],"sourcesContent":["import { BaseMessage, BaseMessageFields } from \"./base.js\";\n\nexport interface RemoveMessageFields extends Omit<\n BaseMessageFields,\n \"content\"\n> {\n /**\n * The ID of the message to remove.\n */\n id: string;\n}\n\n/**\n * Message responsible for deleting other messages.\n *\n * `RemoveMessage` is intentionally not generic over `MessageStructure`.\n * Its content is always `[]` (empty), so carrying a structure type parameter\n * would only cause unnecessary type incompatibilities when mixing messages\n * from different structure configurations (e.g. passing a `RemoveMessage`\n * into an API that expects `Message<CustomToolCall>`).\n */\nexport class RemoveMessage extends BaseMessage {\n readonly type = \"remove\" as const;\n\n /**\n * The ID of the message to remove.\n */\n id: string;\n\n constructor(fields: RemoveMessageFields) {\n super({\n ...fields,\n content: [],\n });\n this.id = fields.id;\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n id: this.id,\n };\n }\n\n static isInstance(obj: unknown): obj is RemoveMessage {\n return super.isInstance(obj) && obj.type === \"remove\";\n }\n\n static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\n }\n}\n"],"mappings":";;;;;;;;;;;AAqBA,IAAa,gBAAb,cAAmC,YAAY;CAC7C,OAAgB;;;;CAKhB;CAEA,YAAY,QAA6B;EACvC,MAAM;GACJ,GAAG;GACH,SAAS,CAAC;EACZ,CAAC;EACD,KAAK,KAAK,OAAO;CACnB;CAEA,IAAa,mBAA4C;EACvD,OAAO;GACL,GAAG,MAAM;GACT,IAAI,KAAK;EACX;CACF;CAEA,OAAO,WAAW,KAAoC;EACpD,OAAO,MAAM,WAAW,GAAG,KAAK,IAAI,SAAS;CAC/C;CAEA,QAAQ,OAAO,aAAa,KAAc;EACxC,OAAO,KAAK,WAAW,GAAG;CAC5B;AACF"}
@@ -42,6 +42,9 @@ var SystemMessage = class SystemMessage extends require_base.BaseMessage {
42
42
  static isInstance(obj) {
43
43
  return super.isInstance(obj) && obj.type === "system";
44
44
  }
45
+ static [Symbol.hasInstance](obj) {
46
+ return this.isInstance(obj);
47
+ }
45
48
  };
46
49
  /**
47
50
  * Represents a chunk of a system message, which can be concatenated with
@@ -67,6 +70,9 @@ var SystemMessageChunk = class extends require_base.BaseMessageChunk {
67
70
  static isInstance(obj) {
68
71
  return super.isInstance(obj) && obj.type === "system";
69
72
  }
73
+ static [Symbol.hasInstance](obj) {
74
+ return this.isInstance(obj);
75
+ }
70
76
  };
71
77
  /**
72
78
  * @deprecated Use {@link SystemMessage.isInstance} instead
@@ -1 +1 @@
1
- {"version":3,"file":"system.cjs","names":["BaseMessage","mergeContent","BaseMessageChunk","_mergeDicts"],"sources":["../../src/messages/system.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageChunk,\n mergeContent,\n _mergeDicts,\n type BaseMessageFields,\n} from \"./base.js\";\nimport { $InferMessageContent, MessageStructure } from \"./message.js\";\nimport { Constructor } from \"./utils.js\";\n\nexport interface SystemMessageFields<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageFields<TStructure, \"system\"> {}\n\n/**\n * Represents a system message in a conversation.\n */\nexport class SystemMessage<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessage<TStructure, \"system\"> {\n static lc_name() {\n return \"SystemMessage\";\n }\n\n readonly type = \"system\" as const;\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"system\">\n | SystemMessageFields<TStructure>\n ) {\n super(fields);\n }\n\n /**\n * Concatenates a string or another system message with the current system message.\n * @param chunk - The chunk to concatenate with the system message.\n * @returns A new system message with the concatenated content.\n */\n concat(chunk: string | SystemMessage) {\n if (typeof chunk === \"string\") {\n return new SystemMessage({\n content: mergeContent(this.content, chunk),\n additional_kwargs: this.additional_kwargs,\n response_metadata: this.response_metadata,\n id: this.id,\n name: this.name,\n } as SystemMessageFields<TStructure>);\n }\n\n if (SystemMessage.isInstance(chunk)) {\n return new SystemMessage({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: {\n ...this.additional_kwargs,\n ...chunk.additional_kwargs,\n },\n response_metadata: {\n ...this.response_metadata,\n ...chunk.response_metadata,\n },\n id: this.id ?? chunk.id,\n name: this.name ?? chunk.name,\n } as SystemMessageFields<TStructure>);\n }\n\n throw new Error(\"Unexpected chunk type for system message\");\n }\n\n static isInstance(obj: unknown): obj is SystemMessage {\n return super.isInstance(obj) && obj.type === \"system\";\n }\n}\n\n/**\n * Represents a chunk of a system message, which can be concatenated with\n * other system message chunks.\n */\nexport class SystemMessageChunk<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageChunk<TStructure, \"system\"> {\n static lc_name() {\n return \"SystemMessageChunk\";\n }\n\n readonly type = \"system\" as const;\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"system\">\n | SystemMessageFields<TStructure>\n ) {\n super(fields);\n }\n\n concat(chunk: SystemMessageChunk<TStructure>) {\n const Cls = this.constructor as Constructor<this>;\n return new Cls({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: _mergeDicts(\n this.additional_kwargs,\n chunk.additional_kwargs\n ),\n response_metadata: _mergeDicts(\n this.response_metadata,\n chunk.response_metadata\n ),\n id: this.id ?? chunk.id,\n });\n }\n\n static isInstance(obj: unknown): obj is SystemMessageChunk {\n return super.isInstance(obj) && obj.type === \"system\";\n }\n}\n\n/**\n * @deprecated Use {@link SystemMessage.isInstance} instead\n */\nexport function isSystemMessage<TStructure extends MessageStructure>(\n x: BaseMessage\n): x is SystemMessage<TStructure> {\n return x._getType() === \"system\";\n}\n\n/**\n * @deprecated Use {@link SystemMessageChunk.isInstance} instead\n */\nexport function isSystemMessageChunk<TStructure extends MessageStructure>(\n x: BaseMessageChunk\n): x is SystemMessageChunk<TStructure> {\n return x._getType() === \"system\";\n}\n"],"mappings":";;;;;AAiBA,IAAa,gBAAb,MAAa,sBAEHA,aAAAA,YAAkC;CAC1C,OAAO,UAAU;EACf,OAAO;CACT;CAEA,OAAgB;CAEhB,YACE,QAGA;EACA,MAAM,MAAM;CACd;;;;;;CAOA,OAAO,OAA+B;EACpC,IAAI,OAAO,UAAU,UACnB,OAAO,IAAI,cAAc;GACvB,SAASC,aAAAA,aAAa,KAAK,SAAS,KAAK;GACzC,mBAAmB,KAAK;GACxB,mBAAmB,KAAK;GACxB,IAAI,KAAK;GACT,MAAM,KAAK;EACb,CAAoC;EAGtC,IAAI,cAAc,WAAW,KAAK,GAChC,OAAO,IAAI,cAAc;GACvB,SAASA,aAAAA,aAAa,KAAK,SAAS,MAAM,OAAO;GACjD,mBAAmB;IACjB,GAAG,KAAK;IACR,GAAG,MAAM;GACX;GACA,mBAAmB;IACjB,GAAG,KAAK;IACR,GAAG,MAAM;GACX;GACA,IAAI,KAAK,MAAM,MAAM;GACrB,MAAM,KAAK,QAAQ,MAAM;EAC3B,CAAoC;EAGtC,MAAM,IAAI,MAAM,0CAA0C;CAC5D;CAEA,OAAO,WAAW,KAAoC;EACpD,OAAO,MAAM,WAAW,GAAG,KAAK,IAAI,SAAS;CAC/C;AACF;;;;;AAMA,IAAa,qBAAb,cAEUC,aAAAA,iBAAuC;CAC/C,OAAO,UAAU;EACf,OAAO;CACT;CAEA,OAAgB;CAEhB,YACE,QAGA;EACA,MAAM,MAAM;CACd;CAEA,OAAO,OAAuC;EAC5C,MAAM,MAAM,KAAK;EACjB,OAAO,IAAI,IAAI;GACb,SAASD,aAAAA,aAAa,KAAK,SAAS,MAAM,OAAO;GACjD,mBAAmBE,aAAAA,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,mBAAmBA,aAAAA,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,IAAI,KAAK,MAAM,MAAM;EACvB,CAAC;CACH;CAEA,OAAO,WAAW,KAAyC;EACzD,OAAO,MAAM,WAAW,GAAG,KAAK,IAAI,SAAS;CAC/C;AACF;;;;AAKA,SAAgB,gBACd,GACgC;CAChC,OAAO,EAAE,SAAS,MAAM;AAC1B;;;;AAKA,SAAgB,qBACd,GACqC;CACrC,OAAO,EAAE,SAAS,MAAM;AAC1B"}
1
+ {"version":3,"file":"system.cjs","names":["BaseMessage","mergeContent","BaseMessageChunk","_mergeDicts"],"sources":["../../src/messages/system.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageChunk,\n mergeContent,\n _mergeDicts,\n type BaseMessageFields,\n} from \"./base.js\";\nimport { $InferMessageContent, MessageStructure } from \"./message.js\";\nimport { Constructor } from \"./utils.js\";\n\nexport interface SystemMessageFields<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageFields<TStructure, \"system\"> {}\n\n/**\n * Represents a system message in a conversation.\n */\nexport class SystemMessage<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessage<TStructure, \"system\"> {\n static lc_name() {\n return \"SystemMessage\";\n }\n\n readonly type = \"system\" as const;\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"system\">\n | SystemMessageFields<TStructure>\n ) {\n super(fields);\n }\n\n /**\n * Concatenates a string or another system message with the current system message.\n * @param chunk - The chunk to concatenate with the system message.\n * @returns A new system message with the concatenated content.\n */\n concat(chunk: string | SystemMessage) {\n if (typeof chunk === \"string\") {\n return new SystemMessage({\n content: mergeContent(this.content, chunk),\n additional_kwargs: this.additional_kwargs,\n response_metadata: this.response_metadata,\n id: this.id,\n name: this.name,\n } as SystemMessageFields<TStructure>);\n }\n\n if (SystemMessage.isInstance(chunk)) {\n return new SystemMessage({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: {\n ...this.additional_kwargs,\n ...chunk.additional_kwargs,\n },\n response_metadata: {\n ...this.response_metadata,\n ...chunk.response_metadata,\n },\n id: this.id ?? chunk.id,\n name: this.name ?? chunk.name,\n } as SystemMessageFields<TStructure>);\n }\n\n throw new Error(\"Unexpected chunk type for system message\");\n }\n\n static isInstance(obj: unknown): obj is SystemMessage {\n return super.isInstance(obj) && obj.type === \"system\";\n }\n\n static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\n }\n}\n\n/**\n * Represents a chunk of a system message, which can be concatenated with\n * other system message chunks.\n */\nexport class SystemMessageChunk<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageChunk<TStructure, \"system\"> {\n static lc_name() {\n return \"SystemMessageChunk\";\n }\n\n readonly type = \"system\" as const;\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"system\">\n | SystemMessageFields<TStructure>\n ) {\n super(fields);\n }\n\n concat(chunk: SystemMessageChunk<TStructure>) {\n const Cls = this.constructor as Constructor<this>;\n return new Cls({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: _mergeDicts(\n this.additional_kwargs,\n chunk.additional_kwargs\n ),\n response_metadata: _mergeDicts(\n this.response_metadata,\n chunk.response_metadata\n ),\n id: this.id ?? chunk.id,\n });\n }\n\n static isInstance(obj: unknown): obj is SystemMessageChunk {\n return super.isInstance(obj) && obj.type === \"system\";\n }\n\n static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\n }\n}\n\n/**\n * @deprecated Use {@link SystemMessage.isInstance} instead\n */\nexport function isSystemMessage<TStructure extends MessageStructure>(\n x: BaseMessage\n): x is SystemMessage<TStructure> {\n return x._getType() === \"system\";\n}\n\n/**\n * @deprecated Use {@link SystemMessageChunk.isInstance} instead\n */\nexport function isSystemMessageChunk<TStructure extends MessageStructure>(\n x: BaseMessageChunk\n): x is SystemMessageChunk<TStructure> {\n return x._getType() === \"system\";\n}\n"],"mappings":";;;;;AAiBA,IAAa,gBAAb,MAAa,sBAEHA,aAAAA,YAAkC;CAC1C,OAAO,UAAU;EACf,OAAO;CACT;CAEA,OAAgB;CAEhB,YACE,QAGA;EACA,MAAM,MAAM;CACd;;;;;;CAOA,OAAO,OAA+B;EACpC,IAAI,OAAO,UAAU,UACnB,OAAO,IAAI,cAAc;GACvB,SAASC,aAAAA,aAAa,KAAK,SAAS,KAAK;GACzC,mBAAmB,KAAK;GACxB,mBAAmB,KAAK;GACxB,IAAI,KAAK;GACT,MAAM,KAAK;EACb,CAAoC;EAGtC,IAAI,cAAc,WAAW,KAAK,GAChC,OAAO,IAAI,cAAc;GACvB,SAASA,aAAAA,aAAa,KAAK,SAAS,MAAM,OAAO;GACjD,mBAAmB;IACjB,GAAG,KAAK;IACR,GAAG,MAAM;GACX;GACA,mBAAmB;IACjB,GAAG,KAAK;IACR,GAAG,MAAM;GACX;GACA,IAAI,KAAK,MAAM,MAAM;GACrB,MAAM,KAAK,QAAQ,MAAM;EAC3B,CAAoC;EAGtC,MAAM,IAAI,MAAM,0CAA0C;CAC5D;CAEA,OAAO,WAAW,KAAoC;EACpD,OAAO,MAAM,WAAW,GAAG,KAAK,IAAI,SAAS;CAC/C;CAEA,QAAQ,OAAO,aAAa,KAAc;EACxC,OAAO,KAAK,WAAW,GAAG;CAC5B;AACF;;;;;AAMA,IAAa,qBAAb,cAEUC,aAAAA,iBAAuC;CAC/C,OAAO,UAAU;EACf,OAAO;CACT;CAEA,OAAgB;CAEhB,YACE,QAGA;EACA,MAAM,MAAM;CACd;CAEA,OAAO,OAAuC;EAC5C,MAAM,MAAM,KAAK;EACjB,OAAO,IAAI,IAAI;GACb,SAASD,aAAAA,aAAa,KAAK,SAAS,MAAM,OAAO;GACjD,mBAAmBE,aAAAA,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,mBAAmBA,aAAAA,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,IAAI,KAAK,MAAM,MAAM;EACvB,CAAC;CACH;CAEA,OAAO,WAAW,KAAyC;EACzD,OAAO,MAAM,WAAW,GAAG,KAAK,IAAI,SAAS;CAC/C;CAEA,QAAQ,OAAO,aAAa,KAAc;EACxC,OAAO,KAAK,WAAW,GAAG;CAC5B;AACF;;;;AAKA,SAAgB,gBACd,GACgC;CAChC,OAAO,EAAE,SAAS,MAAM;AAC1B;;;;AAKA,SAAgB,qBACd,GACqC;CACrC,OAAO,EAAE,SAAS,MAAM;AAC1B"}
@@ -1,5 +1,5 @@
1
1
  import { BaseMessage, BaseMessageChunk, BaseMessageFields } from "./base.cjs";
2
- import { $InferMessageContent, MessageStructure } from "./message.cjs";
2
+ import { $InferMessageContent, MessageStructure, MessageToolSet } from "./message.cjs";
3
3
  //#region src/messages/system.d.ts
4
4
  interface SystemMessageFields<TStructure extends MessageStructure = MessageStructure> extends BaseMessageFields<TStructure, "system"> {}
5
5
  /**
@@ -16,6 +16,7 @@ declare class SystemMessage<TStructure extends MessageStructure = MessageStructu
16
16
  */
17
17
  concat(chunk: string | SystemMessage): SystemMessage<TStructure>;
18
18
  static isInstance(obj: unknown): obj is SystemMessage;
19
+ static [Symbol.hasInstance](obj: unknown): obj is SystemMessage<MessageStructure<MessageToolSet>>;
19
20
  }
20
21
  /**
21
22
  * Represents a chunk of a system message, which can be concatenated with
@@ -27,6 +28,7 @@ declare class SystemMessageChunk<TStructure extends MessageStructure = MessageSt
27
28
  constructor(fields: $InferMessageContent<TStructure, "system"> | SystemMessageFields<TStructure>);
28
29
  concat(chunk: SystemMessageChunk<TStructure>): this;
29
30
  static isInstance(obj: unknown): obj is SystemMessageChunk;
31
+ static [Symbol.hasInstance](obj: unknown): obj is SystemMessageChunk<MessageStructure<MessageToolSet>>;
30
32
  }
31
33
  /**
32
34
  * @deprecated Use {@link SystemMessage.isInstance} instead
@@ -1 +1 @@
1
- {"version":3,"file":"system.d.cts","names":[],"sources":["../../src/messages/system.ts"],"mappings":";;;UAUiB,oBACf,mBAAmB,mBAAmB,0BAC9B,kBAAkB;;;;cAKf,cACX,mBAAmB,mBAAmB,0BAC9B,YAAY;SACb;WAIE;EAET,YACE,QACI,qBAAqB,wBACrB,oBAAoB;;;;;;EAU1B,OAAO,gBAAgB,gBAAa,cAAA;SA8B7B,WAAW,eAAe,OAAO;;;;;;cAS7B,mBACX,mBAAmB,mBAAmB,0BAC9B,iBAAiB;SAClB;WAIE;EAET,YACE,QACI,qBAAqB,wBACrB,oBAAoB;EAK1B,OAAO,OAAO,mBAAmB;SAgB1B,WAAW,eAAe,OAAO;;;;;iBAQ1B,gBAAgB,mBAAmB,kBACjD,GAAG,cACF,KAAK,cAAc;;;;iBAON,qBAAqB,mBAAmB,kBACtD,GAAG,mBACF,KAAK,mBAAmB"}
1
+ {"version":3,"file":"system.d.cts","names":[],"sources":["../../src/messages/system.ts"],"mappings":";;;UAUiB,oBACf,mBAAmB,mBAAmB,0BAC9B,kBAAkB;;;;cAKf,cACX,mBAAmB,mBAAmB,0BAC9B,YAAY;SACb;WAIE;EAET,YACE,QACI,qBAAqB,wBACrB,oBAAoB;;;;;;EAU1B,OAAO,gBAAgB,gBAAa,cAAA;SA8B7B,WAAW,eAAe,OAAO;UAIhC,OAAO,aAAa,eAAY,OAAA,cAAA,iBAJA;;;;;;cAa7B,mBACX,mBAAmB,mBAAmB,0BAC9B,iBAAiB;SAClB;WAIE;EAET,YACE,QACI,qBAAqB,wBACrB,oBAAoB;EAK1B,OAAO,OAAO,mBAAmB;SAgB1B,WAAW,eAAe,OAAO;UAIhC,OAAO,aAAa,eAAY,OAAA,mBAAA,iBAJA;;;;;iBAY1B,gBAAgB,mBAAmB,kBACjD,GAAG,cACF,KAAK,cAAc;;;;iBAON,qBAAqB,mBAAmB,kBACtD,GAAG,mBACF,KAAK,mBAAmB"}
@@ -1,5 +1,5 @@
1
1
  import { BaseMessage, BaseMessageChunk, BaseMessageFields } from "./base.js";
2
- import { $InferMessageContent, MessageStructure } from "./message.js";
2
+ import { $InferMessageContent, MessageStructure, MessageToolSet } from "./message.js";
3
3
  //#region src/messages/system.d.ts
4
4
  interface SystemMessageFields<TStructure extends MessageStructure = MessageStructure> extends BaseMessageFields<TStructure, "system"> {}
5
5
  /**
@@ -16,6 +16,7 @@ declare class SystemMessage<TStructure extends MessageStructure = MessageStructu
16
16
  */
17
17
  concat(chunk: string | SystemMessage): SystemMessage<TStructure>;
18
18
  static isInstance(obj: unknown): obj is SystemMessage;
19
+ static [Symbol.hasInstance](obj: unknown): obj is SystemMessage<MessageStructure<MessageToolSet>>;
19
20
  }
20
21
  /**
21
22
  * Represents a chunk of a system message, which can be concatenated with
@@ -27,6 +28,7 @@ declare class SystemMessageChunk<TStructure extends MessageStructure = MessageSt
27
28
  constructor(fields: $InferMessageContent<TStructure, "system"> | SystemMessageFields<TStructure>);
28
29
  concat(chunk: SystemMessageChunk<TStructure>): this;
29
30
  static isInstance(obj: unknown): obj is SystemMessageChunk;
31
+ static [Symbol.hasInstance](obj: unknown): obj is SystemMessageChunk<MessageStructure<MessageToolSet>>;
30
32
  }
31
33
  /**
32
34
  * @deprecated Use {@link SystemMessage.isInstance} instead
@@ -1 +1 @@
1
- {"version":3,"file":"system.d.ts","names":[],"sources":["../../src/messages/system.ts"],"mappings":";;;UAUiB,oBACf,mBAAmB,mBAAmB,0BAC9B,kBAAkB;;;;cAKf,cACX,mBAAmB,mBAAmB,0BAC9B,YAAY;SACb;WAIE;EAET,YACE,QACI,qBAAqB,wBACrB,oBAAoB;;;;;;EAU1B,OAAO,gBAAgB,gBAAa,cAAA;SA8B7B,WAAW,eAAe,OAAO;;;;;;cAS7B,mBACX,mBAAmB,mBAAmB,0BAC9B,iBAAiB;SAClB;WAIE;EAET,YACE,QACI,qBAAqB,wBACrB,oBAAoB;EAK1B,OAAO,OAAO,mBAAmB;SAgB1B,WAAW,eAAe,OAAO;;;;;iBAQ1B,gBAAgB,mBAAmB,kBACjD,GAAG,cACF,KAAK,cAAc;;;;iBAON,qBAAqB,mBAAmB,kBACtD,GAAG,mBACF,KAAK,mBAAmB"}
1
+ {"version":3,"file":"system.d.ts","names":[],"sources":["../../src/messages/system.ts"],"mappings":";;;UAUiB,oBACf,mBAAmB,mBAAmB,0BAC9B,kBAAkB;;;;cAKf,cACX,mBAAmB,mBAAmB,0BAC9B,YAAY;SACb;WAIE;EAET,YACE,QACI,qBAAqB,wBACrB,oBAAoB;;;;;;EAU1B,OAAO,gBAAgB,gBAAa,cAAA;SA8B7B,WAAW,eAAe,OAAO;UAIhC,OAAO,aAAa,eAAY,OAAA,cAAA,iBAJA;;;;;;cAa7B,mBACX,mBAAmB,mBAAmB,0BAC9B,iBAAiB;SAClB;WAIE;EAET,YACE,QACI,qBAAqB,wBACrB,oBAAoB;EAK1B,OAAO,OAAO,mBAAmB;SAgB1B,WAAW,eAAe,OAAO;UAIhC,OAAO,aAAa,eAAY,OAAA,mBAAA,iBAJA;;;;;iBAY1B,gBAAgB,mBAAmB,kBACjD,GAAG,cACF,KAAK,cAAc;;;;iBAON,qBAAqB,mBAAmB,kBACtD,GAAG,mBACF,KAAK,mBAAmB"}
@@ -42,6 +42,9 @@ var SystemMessage = class SystemMessage extends BaseMessage {
42
42
  static isInstance(obj) {
43
43
  return super.isInstance(obj) && obj.type === "system";
44
44
  }
45
+ static [Symbol.hasInstance](obj) {
46
+ return this.isInstance(obj);
47
+ }
45
48
  };
46
49
  /**
47
50
  * Represents a chunk of a system message, which can be concatenated with
@@ -67,6 +70,9 @@ var SystemMessageChunk = class extends BaseMessageChunk {
67
70
  static isInstance(obj) {
68
71
  return super.isInstance(obj) && obj.type === "system";
69
72
  }
73
+ static [Symbol.hasInstance](obj) {
74
+ return this.isInstance(obj);
75
+ }
70
76
  };
71
77
  /**
72
78
  * @deprecated Use {@link SystemMessage.isInstance} instead
@@ -1 +1 @@
1
- {"version":3,"file":"system.js","names":[],"sources":["../../src/messages/system.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageChunk,\n mergeContent,\n _mergeDicts,\n type BaseMessageFields,\n} from \"./base.js\";\nimport { $InferMessageContent, MessageStructure } from \"./message.js\";\nimport { Constructor } from \"./utils.js\";\n\nexport interface SystemMessageFields<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageFields<TStructure, \"system\"> {}\n\n/**\n * Represents a system message in a conversation.\n */\nexport class SystemMessage<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessage<TStructure, \"system\"> {\n static lc_name() {\n return \"SystemMessage\";\n }\n\n readonly type = \"system\" as const;\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"system\">\n | SystemMessageFields<TStructure>\n ) {\n super(fields);\n }\n\n /**\n * Concatenates a string or another system message with the current system message.\n * @param chunk - The chunk to concatenate with the system message.\n * @returns A new system message with the concatenated content.\n */\n concat(chunk: string | SystemMessage) {\n if (typeof chunk === \"string\") {\n return new SystemMessage({\n content: mergeContent(this.content, chunk),\n additional_kwargs: this.additional_kwargs,\n response_metadata: this.response_metadata,\n id: this.id,\n name: this.name,\n } as SystemMessageFields<TStructure>);\n }\n\n if (SystemMessage.isInstance(chunk)) {\n return new SystemMessage({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: {\n ...this.additional_kwargs,\n ...chunk.additional_kwargs,\n },\n response_metadata: {\n ...this.response_metadata,\n ...chunk.response_metadata,\n },\n id: this.id ?? chunk.id,\n name: this.name ?? chunk.name,\n } as SystemMessageFields<TStructure>);\n }\n\n throw new Error(\"Unexpected chunk type for system message\");\n }\n\n static isInstance(obj: unknown): obj is SystemMessage {\n return super.isInstance(obj) && obj.type === \"system\";\n }\n}\n\n/**\n * Represents a chunk of a system message, which can be concatenated with\n * other system message chunks.\n */\nexport class SystemMessageChunk<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageChunk<TStructure, \"system\"> {\n static lc_name() {\n return \"SystemMessageChunk\";\n }\n\n readonly type = \"system\" as const;\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"system\">\n | SystemMessageFields<TStructure>\n ) {\n super(fields);\n }\n\n concat(chunk: SystemMessageChunk<TStructure>) {\n const Cls = this.constructor as Constructor<this>;\n return new Cls({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: _mergeDicts(\n this.additional_kwargs,\n chunk.additional_kwargs\n ),\n response_metadata: _mergeDicts(\n this.response_metadata,\n chunk.response_metadata\n ),\n id: this.id ?? chunk.id,\n });\n }\n\n static isInstance(obj: unknown): obj is SystemMessageChunk {\n return super.isInstance(obj) && obj.type === \"system\";\n }\n}\n\n/**\n * @deprecated Use {@link SystemMessage.isInstance} instead\n */\nexport function isSystemMessage<TStructure extends MessageStructure>(\n x: BaseMessage\n): x is SystemMessage<TStructure> {\n return x._getType() === \"system\";\n}\n\n/**\n * @deprecated Use {@link SystemMessageChunk.isInstance} instead\n */\nexport function isSystemMessageChunk<TStructure extends MessageStructure>(\n x: BaseMessageChunk\n): x is SystemMessageChunk<TStructure> {\n return x._getType() === \"system\";\n}\n"],"mappings":";;;;;AAiBA,IAAa,gBAAb,MAAa,sBAEH,YAAkC;CAC1C,OAAO,UAAU;EACf,OAAO;CACT;CAEA,OAAgB;CAEhB,YACE,QAGA;EACA,MAAM,MAAM;CACd;;;;;;CAOA,OAAO,OAA+B;EACpC,IAAI,OAAO,UAAU,UACnB,OAAO,IAAI,cAAc;GACvB,SAAS,aAAa,KAAK,SAAS,KAAK;GACzC,mBAAmB,KAAK;GACxB,mBAAmB,KAAK;GACxB,IAAI,KAAK;GACT,MAAM,KAAK;EACb,CAAoC;EAGtC,IAAI,cAAc,WAAW,KAAK,GAChC,OAAO,IAAI,cAAc;GACvB,SAAS,aAAa,KAAK,SAAS,MAAM,OAAO;GACjD,mBAAmB;IACjB,GAAG,KAAK;IACR,GAAG,MAAM;GACX;GACA,mBAAmB;IACjB,GAAG,KAAK;IACR,GAAG,MAAM;GACX;GACA,IAAI,KAAK,MAAM,MAAM;GACrB,MAAM,KAAK,QAAQ,MAAM;EAC3B,CAAoC;EAGtC,MAAM,IAAI,MAAM,0CAA0C;CAC5D;CAEA,OAAO,WAAW,KAAoC;EACpD,OAAO,MAAM,WAAW,GAAG,KAAK,IAAI,SAAS;CAC/C;AACF;;;;;AAMA,IAAa,qBAAb,cAEU,iBAAuC;CAC/C,OAAO,UAAU;EACf,OAAO;CACT;CAEA,OAAgB;CAEhB,YACE,QAGA;EACA,MAAM,MAAM;CACd;CAEA,OAAO,OAAuC;EAC5C,MAAM,MAAM,KAAK;EACjB,OAAO,IAAI,IAAI;GACb,SAAS,aAAa,KAAK,SAAS,MAAM,OAAO;GACjD,mBAAmB,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,mBAAmB,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,IAAI,KAAK,MAAM,MAAM;EACvB,CAAC;CACH;CAEA,OAAO,WAAW,KAAyC;EACzD,OAAO,MAAM,WAAW,GAAG,KAAK,IAAI,SAAS;CAC/C;AACF;;;;AAKA,SAAgB,gBACd,GACgC;CAChC,OAAO,EAAE,SAAS,MAAM;AAC1B;;;;AAKA,SAAgB,qBACd,GACqC;CACrC,OAAO,EAAE,SAAS,MAAM;AAC1B"}
1
+ {"version":3,"file":"system.js","names":[],"sources":["../../src/messages/system.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageChunk,\n mergeContent,\n _mergeDicts,\n type BaseMessageFields,\n} from \"./base.js\";\nimport { $InferMessageContent, MessageStructure } from \"./message.js\";\nimport { Constructor } from \"./utils.js\";\n\nexport interface SystemMessageFields<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageFields<TStructure, \"system\"> {}\n\n/**\n * Represents a system message in a conversation.\n */\nexport class SystemMessage<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessage<TStructure, \"system\"> {\n static lc_name() {\n return \"SystemMessage\";\n }\n\n readonly type = \"system\" as const;\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"system\">\n | SystemMessageFields<TStructure>\n ) {\n super(fields);\n }\n\n /**\n * Concatenates a string or another system message with the current system message.\n * @param chunk - The chunk to concatenate with the system message.\n * @returns A new system message with the concatenated content.\n */\n concat(chunk: string | SystemMessage) {\n if (typeof chunk === \"string\") {\n return new SystemMessage({\n content: mergeContent(this.content, chunk),\n additional_kwargs: this.additional_kwargs,\n response_metadata: this.response_metadata,\n id: this.id,\n name: this.name,\n } as SystemMessageFields<TStructure>);\n }\n\n if (SystemMessage.isInstance(chunk)) {\n return new SystemMessage({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: {\n ...this.additional_kwargs,\n ...chunk.additional_kwargs,\n },\n response_metadata: {\n ...this.response_metadata,\n ...chunk.response_metadata,\n },\n id: this.id ?? chunk.id,\n name: this.name ?? chunk.name,\n } as SystemMessageFields<TStructure>);\n }\n\n throw new Error(\"Unexpected chunk type for system message\");\n }\n\n static isInstance(obj: unknown): obj is SystemMessage {\n return super.isInstance(obj) && obj.type === \"system\";\n }\n\n static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\n }\n}\n\n/**\n * Represents a chunk of a system message, which can be concatenated with\n * other system message chunks.\n */\nexport class SystemMessageChunk<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageChunk<TStructure, \"system\"> {\n static lc_name() {\n return \"SystemMessageChunk\";\n }\n\n readonly type = \"system\" as const;\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"system\">\n | SystemMessageFields<TStructure>\n ) {\n super(fields);\n }\n\n concat(chunk: SystemMessageChunk<TStructure>) {\n const Cls = this.constructor as Constructor<this>;\n return new Cls({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: _mergeDicts(\n this.additional_kwargs,\n chunk.additional_kwargs\n ),\n response_metadata: _mergeDicts(\n this.response_metadata,\n chunk.response_metadata\n ),\n id: this.id ?? chunk.id,\n });\n }\n\n static isInstance(obj: unknown): obj is SystemMessageChunk {\n return super.isInstance(obj) && obj.type === \"system\";\n }\n\n static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\n }\n}\n\n/**\n * @deprecated Use {@link SystemMessage.isInstance} instead\n */\nexport function isSystemMessage<TStructure extends MessageStructure>(\n x: BaseMessage\n): x is SystemMessage<TStructure> {\n return x._getType() === \"system\";\n}\n\n/**\n * @deprecated Use {@link SystemMessageChunk.isInstance} instead\n */\nexport function isSystemMessageChunk<TStructure extends MessageStructure>(\n x: BaseMessageChunk\n): x is SystemMessageChunk<TStructure> {\n return x._getType() === \"system\";\n}\n"],"mappings":";;;;;AAiBA,IAAa,gBAAb,MAAa,sBAEH,YAAkC;CAC1C,OAAO,UAAU;EACf,OAAO;CACT;CAEA,OAAgB;CAEhB,YACE,QAGA;EACA,MAAM,MAAM;CACd;;;;;;CAOA,OAAO,OAA+B;EACpC,IAAI,OAAO,UAAU,UACnB,OAAO,IAAI,cAAc;GACvB,SAAS,aAAa,KAAK,SAAS,KAAK;GACzC,mBAAmB,KAAK;GACxB,mBAAmB,KAAK;GACxB,IAAI,KAAK;GACT,MAAM,KAAK;EACb,CAAoC;EAGtC,IAAI,cAAc,WAAW,KAAK,GAChC,OAAO,IAAI,cAAc;GACvB,SAAS,aAAa,KAAK,SAAS,MAAM,OAAO;GACjD,mBAAmB;IACjB,GAAG,KAAK;IACR,GAAG,MAAM;GACX;GACA,mBAAmB;IACjB,GAAG,KAAK;IACR,GAAG,MAAM;GACX;GACA,IAAI,KAAK,MAAM,MAAM;GACrB,MAAM,KAAK,QAAQ,MAAM;EAC3B,CAAoC;EAGtC,MAAM,IAAI,MAAM,0CAA0C;CAC5D;CAEA,OAAO,WAAW,KAAoC;EACpD,OAAO,MAAM,WAAW,GAAG,KAAK,IAAI,SAAS;CAC/C;CAEA,QAAQ,OAAO,aAAa,KAAc;EACxC,OAAO,KAAK,WAAW,GAAG;CAC5B;AACF;;;;;AAMA,IAAa,qBAAb,cAEU,iBAAuC;CAC/C,OAAO,UAAU;EACf,OAAO;CACT;CAEA,OAAgB;CAEhB,YACE,QAGA;EACA,MAAM,MAAM;CACd;CAEA,OAAO,OAAuC;EAC5C,MAAM,MAAM,KAAK;EACjB,OAAO,IAAI,IAAI;GACb,SAAS,aAAa,KAAK,SAAS,MAAM,OAAO;GACjD,mBAAmB,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,mBAAmB,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,IAAI,KAAK,MAAM,MAAM;EACvB,CAAC;CACH;CAEA,OAAO,WAAW,KAAyC;EACzD,OAAO,MAAM,WAAW,GAAG,KAAK,IAAI,SAAS;CAC/C;CAEA,QAAQ,OAAO,aAAa,KAAc;EACxC,OAAO,KAAK,WAAW,GAAG;CAC5B;AACF;;;;AAKA,SAAgB,gBACd,GACgC;CAChC,OAAO,EAAE,SAAS,MAAM;AAC1B;;;;AAKA,SAAgB,qBACd,GACqC;CACrC,OAAO,EAAE,SAAS,MAAM;AAC1B"}
@@ -55,6 +55,9 @@ var ToolMessage = class extends require_base.BaseMessage {
55
55
  static isInstance(message) {
56
56
  return super.isInstance(message) && message.type === "tool";
57
57
  }
58
+ static [Symbol.hasInstance](obj) {
59
+ return this.isInstance(obj);
60
+ }
58
61
  get _printableFields() {
59
62
  return {
60
63
  ...super._printableFields,
@@ -104,6 +107,12 @@ var ToolMessageChunk = class extends require_base.BaseMessageChunk {
104
107
  status: require_base._mergeStatus(this.status, chunk.status)
105
108
  });
106
109
  }
110
+ static isInstance(obj) {
111
+ return super.isInstance(obj) && obj.type === "tool";
112
+ }
113
+ static [Symbol.hasInstance](obj) {
114
+ return this.isInstance(obj);
115
+ }
107
116
  get _printableFields() {
108
117
  return {
109
118
  ...super._printableFields,
@@ -1 +1 @@
1
- {"version":3,"file":"tool.cjs","names":["BaseMessage","BaseMessageChunk","mergeContent","_mergeDicts","_mergeObj","_mergeStatus"],"sources":["../../src/messages/tool.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageChunk,\n type BaseMessageFields,\n mergeContent,\n _mergeDicts,\n _mergeObj,\n _mergeStatus,\n} from \"./base.js\";\nimport { $InferMessageContent, MessageStructure } from \"./message.js\";\nimport { Constructor } from \"./utils.js\";\n\nexport interface ToolMessageFields<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageFields<TStructure, \"tool\"> {\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n tool_call_id: string;\n status?: \"success\" | \"error\";\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Marker parameter for objects that tools can return directly.\n *\n * If a custom BaseTool is invoked with a ToolCall and the output of custom code is\n * not an instance of DirectToolOutput, the output will automatically be coerced to\n * a string and wrapped in a ToolMessage.\n */\nexport interface DirectToolOutput {\n readonly lc_direct_tool_output: true;\n}\n\nexport function isDirectToolOutput(x: unknown): x is DirectToolOutput {\n return (\n x != null &&\n typeof x === \"object\" &&\n \"lc_direct_tool_output\" in x &&\n x.lc_direct_tool_output === true\n );\n}\n\n/**\n * Represents a tool message in a conversation.\n */\nexport class ToolMessage<TStructure extends MessageStructure = MessageStructure>\n extends BaseMessage<TStructure, \"tool\">\n implements DirectToolOutput\n{\n static lc_name() {\n return \"ToolMessage\";\n }\n\n get lc_aliases(): Record<string, string> {\n // exclude snake case conversion to pascal case\n return { tool_call_id: \"tool_call_id\" };\n }\n\n lc_direct_tool_output = true as const;\n\n readonly type = \"tool\" as const;\n\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n\n tool_call_id: string;\n\n metadata?: Record<string, unknown>;\n\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n\n constructor(\n fields: $InferMessageContent<TStructure, \"tool\"> | ToolMessageFields,\n tool_call_id: string,\n name?: string\n );\n\n constructor(fields: ToolMessageFields<TStructure>);\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"tool\">\n | ToolMessageFields<TStructure>,\n tool_call_id?: string,\n name?: string\n ) {\n const toolMessageFields: ToolMessageFields<TStructure> =\n typeof fields === \"string\" || Array.isArray(fields)\n ? ({\n content: fields,\n name,\n tool_call_id: tool_call_id!,\n } as ToolMessageFields<TStructure>)\n : fields;\n super(toolMessageFields);\n this.tool_call_id = toolMessageFields.tool_call_id;\n this.artifact = toolMessageFields.artifact;\n this.status = toolMessageFields.status;\n this.metadata = toolMessageFields.metadata;\n }\n\n /**\n * Type guard to check if an object is a ToolMessage.\n * Preserves the MessageStructure type parameter when called with a typed BaseMessage.\n * @overload When called with a typed BaseMessage, preserves the TStructure type\n */\n static isInstance<T extends MessageStructure>(\n message: BaseMessage<T>\n ): message is BaseMessage<T> & ToolMessage<T>;\n /**\n * Type guard to check if an object is a ToolMessage.\n * @overload When called with unknown, returns base ToolMessage type\n */\n static isInstance(message: unknown): message is ToolMessage;\n static isInstance<T extends MessageStructure = MessageStructure>(\n message: BaseMessage<T> | unknown\n ): message is ToolMessage<T> {\n return (\n super.isInstance(message) && (message as { type: string }).type === \"tool\"\n );\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact,\n };\n }\n}\n\n/**\n * Represents a chunk of a tool message, which can be concatenated\n * with other tool message chunks.\n */\nexport class ToolMessageChunk<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageChunk<TStructure, \"tool\"> {\n readonly type = \"tool\" as const;\n\n tool_call_id: string;\n\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n\n constructor(fields: ToolMessageFields<TStructure>) {\n super(fields);\n this.tool_call_id = fields.tool_call_id;\n this.artifact = fields.artifact;\n this.status = fields.status;\n }\n\n static lc_name() {\n return \"ToolMessageChunk\";\n }\n\n concat(chunk: ToolMessageChunk<TStructure>) {\n const Cls = this.constructor as Constructor<this>;\n return new Cls({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: _mergeDicts(\n this.additional_kwargs,\n chunk.additional_kwargs\n ),\n response_metadata: _mergeDicts(\n this.response_metadata,\n chunk.response_metadata\n ),\n artifact: _mergeObj(this.artifact, chunk.artifact),\n tool_call_id: this.tool_call_id,\n id: this.id ?? chunk.id,\n status: _mergeStatus(this.status, chunk.status),\n });\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact,\n };\n }\n}\n\nexport interface ToolCall<\n TName extends string = string,\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n TArgs extends Record<string, any> = Record<string, any>,\n> {\n readonly type?: \"tool_call\";\n /**\n * If provided, an identifier associated with the tool call\n */\n id?: string;\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n}\n\n/**\n * A chunk of a tool call (e.g., as part of a stream).\n * When merging ToolCallChunks (e.g., via AIMessageChunk.__add__),\n * all string attributes are concatenated. Chunks are only merged if their\n * values of `index` are equal and not None.\n *\n * @example\n * ```ts\n * const leftChunks = [\n * {\n * name: \"foo\",\n * args: '{\"a\":',\n * index: 0\n * }\n * ];\n *\n * const leftAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: leftChunks\n * });\n *\n * const rightChunks = [\n * {\n * name: undefined,\n * args: '1}',\n * index: 0\n * }\n * ];\n *\n * const rightAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: rightChunks\n * });\n *\n * const result = leftAIMessageChunk.concat(rightAIMessageChunk);\n * // result.tool_call_chunks is equal to:\n * // [\n * // {\n * // name: \"foo\",\n * // args: '{\"a\":1}'\n * // index: 0\n * // }\n * // ]\n * ```\n */\nexport interface ToolCallChunk<TName extends string = string> {\n readonly type?: \"tool_call_chunk\";\n /**\n * If provided, a substring of an identifier for the tool call\n */\n id?: string;\n /**\n * If provided, a substring of the name of the tool to be called\n */\n name?: TName;\n /**\n * If provided, a JSON substring of the arguments to the tool call\n */\n args?: string;\n /**\n * If provided, the index of the tool call in a sequence\n */\n index?: number;\n}\n\nexport interface InvalidToolCall<TName extends string = string> {\n readonly type?: \"invalid_tool_call\";\n /**\n * If provided, an identifier associated with the tool call\n */\n id?: string;\n /**\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n}\n\nexport function defaultToolCallParser(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCalls: Record<string, any>[]\n): [ToolCall[], InvalidToolCall[]] {\n const toolCalls: ToolCall[] = [];\n const invalidToolCalls: InvalidToolCall[] = [];\n for (const toolCall of rawToolCalls) {\n if (!toolCall.function) {\n continue;\n } else {\n const functionName = toolCall.function.name;\n try {\n const functionArgs = JSON.parse(toolCall.function.arguments);\n toolCalls.push({\n name: functionName || \"\",\n args: functionArgs || {},\n id: toolCall.id,\n });\n } catch {\n invalidToolCalls.push({\n name: functionName,\n args: toolCall.function.arguments,\n id: toolCall.id,\n error: \"Malformed args.\",\n });\n }\n }\n }\n return [toolCalls, invalidToolCalls];\n}\n\n/**\n * @deprecated Use {@link ToolMessage.isInstance} instead\n */\nexport function isToolMessage(x: unknown): x is ToolMessage {\n return (\n typeof x === \"object\" &&\n x !== null &&\n \"getType\" in x &&\n typeof x.getType === \"function\" &&\n x.getType() === \"tool\"\n );\n}\n\n/**\n * @deprecated Use {@link ToolMessageChunk.isInstance} instead\n */\nexport function isToolMessageChunk(x: BaseMessageChunk): x is ToolMessageChunk {\n return x._getType() === \"tool\";\n}\n"],"mappings":";;;;;;;;;;;;AAwCA,SAAgB,mBAAmB,GAAmC;CACpE,OACE,KAAK,QACL,OAAO,MAAM,YACb,2BAA2B,KAC3B,EAAE,0BAA0B;AAEhC;;;;AAKA,IAAa,cAAb,cACUA,aAAAA,YAEV;CACE,OAAO,UAAU;EACf,OAAO;CACT;CAEA,IAAI,aAAqC;EAEvC,OAAO,EAAE,cAAc,eAAe;CACxC;CAEA,wBAAwB;CAExB,OAAgB;;;;;CAMhB;CAEA;CAEA;;;;;;;;CAUA;CAUA,YACE,QAGA,cACA,MACA;EACA,MAAM,oBACJ,OAAO,WAAW,YAAY,MAAM,QAAQ,MAAM,IAC7C;GACC,SAAS;GACT;GACc;EAChB,IACA;EACN,MAAM,iBAAiB;EACvB,KAAK,eAAe,kBAAkB;EACtC,KAAK,WAAW,kBAAkB;EAClC,KAAK,SAAS,kBAAkB;EAChC,KAAK,WAAW,kBAAkB;CACpC;CAeA,OAAO,WACL,SAC2B;EAC3B,OACE,MAAM,WAAW,OAAO,KAAM,QAA6B,SAAS;CAExE;CAEA,IAAa,mBAA4C;EACvD,OAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EACjB;CACF;AACF;;;;;AAMA,IAAa,mBAAb,cAEUC,aAAAA,iBAAqC;CAC7C,OAAgB;CAEhB;;;;;CAMA;;;;;;;;CAUA;CAEA,YAAY,QAAuC;EACjD,MAAM,MAAM;EACZ,KAAK,eAAe,OAAO;EAC3B,KAAK,WAAW,OAAO;EACvB,KAAK,SAAS,OAAO;CACvB;CAEA,OAAO,UAAU;EACf,OAAO;CACT;CAEA,OAAO,OAAqC;EAC1C,MAAM,MAAM,KAAK;EACjB,OAAO,IAAI,IAAI;GACb,SAASC,aAAAA,aAAa,KAAK,SAAS,MAAM,OAAO;GACjD,mBAAmBC,aAAAA,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,mBAAmBA,aAAAA,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,UAAUC,aAAAA,UAAU,KAAK,UAAU,MAAM,QAAQ;GACjD,cAAc,KAAK;GACnB,IAAI,KAAK,MAAM,MAAM;GACrB,QAAQC,aAAAA,aAAa,KAAK,QAAQ,MAAM,MAAM;EAChD,CAAC;CACH;CAEA,IAAa,mBAA4C;EACvD,OAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EACjB;CACF;AACF;AAgHA,SAAgB,sBAEd,cACiC;CACjC,MAAM,YAAwB,CAAC;CAC/B,MAAM,mBAAsC,CAAC;CAC7C,KAAK,MAAM,YAAY,cACrB,IAAI,CAAC,SAAS,UACZ;MACK;EACL,MAAM,eAAe,SAAS,SAAS;EACvC,IAAI;GACF,MAAM,eAAe,KAAK,MAAM,SAAS,SAAS,SAAS;GAC3D,UAAU,KAAK;IACb,MAAM,gBAAgB;IACtB,MAAM,gBAAgB,CAAC;IACvB,IAAI,SAAS;GACf,CAAC;EACH,QAAQ;GACN,iBAAiB,KAAK;IACpB,MAAM;IACN,MAAM,SAAS,SAAS;IACxB,IAAI,SAAS;IACb,OAAO;GACT,CAAC;EACH;CACF;CAEF,OAAO,CAAC,WAAW,gBAAgB;AACrC;;;;AAKA,SAAgB,cAAc,GAA8B;CAC1D,OACE,OAAO,MAAM,YACb,MAAM,QACN,aAAa,KACb,OAAO,EAAE,YAAY,cACrB,EAAE,QAAQ,MAAM;AAEpB;;;;AAKA,SAAgB,mBAAmB,GAA4C;CAC7E,OAAO,EAAE,SAAS,MAAM;AAC1B"}
1
+ {"version":3,"file":"tool.cjs","names":["BaseMessage","BaseMessageChunk","mergeContent","_mergeDicts","_mergeObj","_mergeStatus"],"sources":["../../src/messages/tool.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageChunk,\n type BaseMessageFields,\n mergeContent,\n _mergeDicts,\n _mergeObj,\n _mergeStatus,\n} from \"./base.js\";\nimport { $InferMessageContent, MessageStructure } from \"./message.js\";\nimport { Constructor } from \"./utils.js\";\n\nexport interface ToolMessageFields<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageFields<TStructure, \"tool\"> {\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n tool_call_id: string;\n status?: \"success\" | \"error\";\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Marker parameter for objects that tools can return directly.\n *\n * If a custom BaseTool is invoked with a ToolCall and the output of custom code is\n * not an instance of DirectToolOutput, the output will automatically be coerced to\n * a string and wrapped in a ToolMessage.\n */\nexport interface DirectToolOutput {\n readonly lc_direct_tool_output: true;\n}\n\nexport function isDirectToolOutput(x: unknown): x is DirectToolOutput {\n return (\n x != null &&\n typeof x === \"object\" &&\n \"lc_direct_tool_output\" in x &&\n x.lc_direct_tool_output === true\n );\n}\n\n/**\n * Represents a tool message in a conversation.\n */\nexport class ToolMessage<TStructure extends MessageStructure = MessageStructure>\n extends BaseMessage<TStructure, \"tool\">\n implements DirectToolOutput\n{\n static lc_name() {\n return \"ToolMessage\";\n }\n\n get lc_aliases(): Record<string, string> {\n // exclude snake case conversion to pascal case\n return { tool_call_id: \"tool_call_id\" };\n }\n\n lc_direct_tool_output = true as const;\n\n readonly type = \"tool\" as const;\n\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n\n tool_call_id: string;\n\n metadata?: Record<string, unknown>;\n\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n\n constructor(\n fields: $InferMessageContent<TStructure, \"tool\"> | ToolMessageFields,\n tool_call_id: string,\n name?: string\n );\n\n constructor(fields: ToolMessageFields<TStructure>);\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"tool\">\n | ToolMessageFields<TStructure>,\n tool_call_id?: string,\n name?: string\n ) {\n const toolMessageFields: ToolMessageFields<TStructure> =\n typeof fields === \"string\" || Array.isArray(fields)\n ? ({\n content: fields,\n name,\n tool_call_id: tool_call_id!,\n } as ToolMessageFields<TStructure>)\n : fields;\n super(toolMessageFields);\n this.tool_call_id = toolMessageFields.tool_call_id;\n this.artifact = toolMessageFields.artifact;\n this.status = toolMessageFields.status;\n this.metadata = toolMessageFields.metadata;\n }\n\n /**\n * Type guard to check if an object is a ToolMessage.\n * Preserves the MessageStructure type parameter when called with a typed BaseMessage.\n * @overload When called with a typed BaseMessage, preserves the TStructure type\n */\n static isInstance<T extends MessageStructure>(\n message: BaseMessage<T>\n ): message is BaseMessage<T> & ToolMessage<T>;\n /**\n * Type guard to check if an object is a ToolMessage.\n * @overload When called with unknown, returns base ToolMessage type\n */\n static isInstance(message: unknown): message is ToolMessage;\n static isInstance<T extends MessageStructure = MessageStructure>(\n message: BaseMessage<T> | unknown\n ): message is ToolMessage<T> {\n return (\n super.isInstance(message) && (message as { type: string }).type === \"tool\"\n );\n }\n\n static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact,\n };\n }\n}\n\n/**\n * Represents a chunk of a tool message, which can be concatenated\n * with other tool message chunks.\n */\nexport class ToolMessageChunk<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageChunk<TStructure, \"tool\"> {\n readonly type = \"tool\" as const;\n\n tool_call_id: string;\n\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n\n constructor(fields: ToolMessageFields<TStructure>) {\n super(fields);\n this.tool_call_id = fields.tool_call_id;\n this.artifact = fields.artifact;\n this.status = fields.status;\n }\n\n static lc_name() {\n return \"ToolMessageChunk\";\n }\n\n concat(chunk: ToolMessageChunk<TStructure>) {\n const Cls = this.constructor as Constructor<this>;\n return new Cls({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: _mergeDicts(\n this.additional_kwargs,\n chunk.additional_kwargs\n ),\n response_metadata: _mergeDicts(\n this.response_metadata,\n chunk.response_metadata\n ),\n artifact: _mergeObj(this.artifact, chunk.artifact),\n tool_call_id: this.tool_call_id,\n id: this.id ?? chunk.id,\n status: _mergeStatus(this.status, chunk.status),\n });\n }\n\n static isInstance(obj: unknown): obj is ToolMessageChunk {\n return super.isInstance(obj) && obj.type === \"tool\";\n }\n\n static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact,\n };\n }\n}\n\nexport interface ToolCall<\n TName extends string = string,\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n TArgs extends Record<string, any> = Record<string, any>,\n> {\n readonly type?: \"tool_call\";\n /**\n * If provided, an identifier associated with the tool call\n */\n id?: string;\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n}\n\n/**\n * A chunk of a tool call (e.g., as part of a stream).\n * When merging ToolCallChunks (e.g., via AIMessageChunk.__add__),\n * all string attributes are concatenated. Chunks are only merged if their\n * values of `index` are equal and not None.\n *\n * @example\n * ```ts\n * const leftChunks = [\n * {\n * name: \"foo\",\n * args: '{\"a\":',\n * index: 0\n * }\n * ];\n *\n * const leftAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: leftChunks\n * });\n *\n * const rightChunks = [\n * {\n * name: undefined,\n * args: '1}',\n * index: 0\n * }\n * ];\n *\n * const rightAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: rightChunks\n * });\n *\n * const result = leftAIMessageChunk.concat(rightAIMessageChunk);\n * // result.tool_call_chunks is equal to:\n * // [\n * // {\n * // name: \"foo\",\n * // args: '{\"a\":1}'\n * // index: 0\n * // }\n * // ]\n * ```\n */\nexport interface ToolCallChunk<TName extends string = string> {\n readonly type?: \"tool_call_chunk\";\n /**\n * If provided, a substring of an identifier for the tool call\n */\n id?: string;\n /**\n * If provided, a substring of the name of the tool to be called\n */\n name?: TName;\n /**\n * If provided, a JSON substring of the arguments to the tool call\n */\n args?: string;\n /**\n * If provided, the index of the tool call in a sequence\n */\n index?: number;\n}\n\nexport interface InvalidToolCall<TName extends string = string> {\n readonly type?: \"invalid_tool_call\";\n /**\n * If provided, an identifier associated with the tool call\n */\n id?: string;\n /**\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n}\n\nexport function defaultToolCallParser(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCalls: Record<string, any>[]\n): [ToolCall[], InvalidToolCall[]] {\n const toolCalls: ToolCall[] = [];\n const invalidToolCalls: InvalidToolCall[] = [];\n for (const toolCall of rawToolCalls) {\n if (!toolCall.function) {\n continue;\n } else {\n const functionName = toolCall.function.name;\n try {\n const functionArgs = JSON.parse(toolCall.function.arguments);\n toolCalls.push({\n name: functionName || \"\",\n args: functionArgs || {},\n id: toolCall.id,\n });\n } catch {\n invalidToolCalls.push({\n name: functionName,\n args: toolCall.function.arguments,\n id: toolCall.id,\n error: \"Malformed args.\",\n });\n }\n }\n }\n return [toolCalls, invalidToolCalls];\n}\n\n/**\n * @deprecated Use {@link ToolMessage.isInstance} instead\n */\nexport function isToolMessage(x: unknown): x is ToolMessage {\n return (\n typeof x === \"object\" &&\n x !== null &&\n \"getType\" in x &&\n typeof x.getType === \"function\" &&\n x.getType() === \"tool\"\n );\n}\n\n/**\n * @deprecated Use {@link ToolMessageChunk.isInstance} instead\n */\nexport function isToolMessageChunk(x: BaseMessageChunk): x is ToolMessageChunk {\n return x._getType() === \"tool\";\n}\n"],"mappings":";;;;;;;;;;;;AAwCA,SAAgB,mBAAmB,GAAmC;CACpE,OACE,KAAK,QACL,OAAO,MAAM,YACb,2BAA2B,KAC3B,EAAE,0BAA0B;AAEhC;;;;AAKA,IAAa,cAAb,cACUA,aAAAA,YAEV;CACE,OAAO,UAAU;EACf,OAAO;CACT;CAEA,IAAI,aAAqC;EAEvC,OAAO,EAAE,cAAc,eAAe;CACxC;CAEA,wBAAwB;CAExB,OAAgB;;;;;CAMhB;CAEA;CAEA;;;;;;;;CAUA;CAUA,YACE,QAGA,cACA,MACA;EACA,MAAM,oBACJ,OAAO,WAAW,YAAY,MAAM,QAAQ,MAAM,IAC7C;GACC,SAAS;GACT;GACc;EAChB,IACA;EACN,MAAM,iBAAiB;EACvB,KAAK,eAAe,kBAAkB;EACtC,KAAK,WAAW,kBAAkB;EAClC,KAAK,SAAS,kBAAkB;EAChC,KAAK,WAAW,kBAAkB;CACpC;CAeA,OAAO,WACL,SAC2B;EAC3B,OACE,MAAM,WAAW,OAAO,KAAM,QAA6B,SAAS;CAExE;CAEA,QAAQ,OAAO,aAAa,KAAc;EACxC,OAAO,KAAK,WAAW,GAAG;CAC5B;CAEA,IAAa,mBAA4C;EACvD,OAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EACjB;CACF;AACF;;;;;AAMA,IAAa,mBAAb,cAEUC,aAAAA,iBAAqC;CAC7C,OAAgB;CAEhB;;;;;CAMA;;;;;;;;CAUA;CAEA,YAAY,QAAuC;EACjD,MAAM,MAAM;EACZ,KAAK,eAAe,OAAO;EAC3B,KAAK,WAAW,OAAO;EACvB,KAAK,SAAS,OAAO;CACvB;CAEA,OAAO,UAAU;EACf,OAAO;CACT;CAEA,OAAO,OAAqC;EAC1C,MAAM,MAAM,KAAK;EACjB,OAAO,IAAI,IAAI;GACb,SAASC,aAAAA,aAAa,KAAK,SAAS,MAAM,OAAO;GACjD,mBAAmBC,aAAAA,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,mBAAmBA,aAAAA,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,UAAUC,aAAAA,UAAU,KAAK,UAAU,MAAM,QAAQ;GACjD,cAAc,KAAK;GACnB,IAAI,KAAK,MAAM,MAAM;GACrB,QAAQC,aAAAA,aAAa,KAAK,QAAQ,MAAM,MAAM;EAChD,CAAC;CACH;CAEA,OAAO,WAAW,KAAuC;EACvD,OAAO,MAAM,WAAW,GAAG,KAAK,IAAI,SAAS;CAC/C;CAEA,QAAQ,OAAO,aAAa,KAAc;EACxC,OAAO,KAAK,WAAW,GAAG;CAC5B;CAEA,IAAa,mBAA4C;EACvD,OAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EACjB;CACF;AACF;AAgHA,SAAgB,sBAEd,cACiC;CACjC,MAAM,YAAwB,CAAC;CAC/B,MAAM,mBAAsC,CAAC;CAC7C,KAAK,MAAM,YAAY,cACrB,IAAI,CAAC,SAAS,UACZ;MACK;EACL,MAAM,eAAe,SAAS,SAAS;EACvC,IAAI;GACF,MAAM,eAAe,KAAK,MAAM,SAAS,SAAS,SAAS;GAC3D,UAAU,KAAK;IACb,MAAM,gBAAgB;IACtB,MAAM,gBAAgB,CAAC;IACvB,IAAI,SAAS;GACf,CAAC;EACH,QAAQ;GACN,iBAAiB,KAAK;IACpB,MAAM;IACN,MAAM,SAAS,SAAS;IACxB,IAAI,SAAS;IACb,OAAO;GACT,CAAC;EACH;CACF;CAEF,OAAO,CAAC,WAAW,gBAAgB;AACrC;;;;AAKA,SAAgB,cAAc,GAA8B;CAC1D,OACE,OAAO,MAAM,YACb,MAAM,QACN,aAAa,KACb,OAAO,EAAE,YAAY,cACrB,EAAE,QAAQ,MAAM;AAEpB;;;;AAKA,SAAgB,mBAAmB,GAA4C;CAC7E,OAAO,EAAE,SAAS,MAAM;AAC1B"}
@@ -1,5 +1,5 @@
1
1
  import { BaseMessage, BaseMessageChunk, BaseMessageFields } from "./base.cjs";
2
- import { $InferMessageContent, MessageStructure } from "./message.cjs";
2
+ import { $InferMessageContent, MessageStructure, MessageToolSet } from "./message.cjs";
3
3
  //#region src/messages/tool.d.ts
4
4
  interface ToolMessageFields<TStructure extends MessageStructure = MessageStructure> extends BaseMessageFields<TStructure, "tool"> {
5
5
  /**
@@ -61,6 +61,7 @@ declare class ToolMessage<TStructure extends MessageStructure = MessageStructure
61
61
  * @overload When called with unknown, returns base ToolMessage type
62
62
  */
63
63
  static isInstance(message: unknown): message is ToolMessage;
64
+ static [Symbol.hasInstance](obj: unknown): obj is ToolMessage<MessageStructure<MessageToolSet>>;
64
65
  get _printableFields(): Record<string, unknown>;
65
66
  }
66
67
  /**
@@ -86,6 +87,8 @@ declare class ToolMessageChunk<TStructure extends MessageStructure = MessageStru
86
87
  constructor(fields: ToolMessageFields<TStructure>);
87
88
  static lc_name(): string;
88
89
  concat(chunk: ToolMessageChunk<TStructure>): this;
90
+ static isInstance(obj: unknown): obj is ToolMessageChunk;
91
+ static [Symbol.hasInstance](obj: unknown): obj is ToolMessageChunk<MessageStructure<MessageToolSet>>;
89
92
  get _printableFields(): Record<string, unknown>;
90
93
  }
91
94
  interface ToolCall<TName extends string = string, TArgs extends Record<string, any> = Record<string, any>> {
@@ -1 +1 @@
1
- {"version":3,"file":"tool.d.cts","names":[],"sources":["../../src/messages/tool.ts"],"mappings":";;;UAYiB,kBACf,mBAAmB,mBAAmB,0BAC9B,kBAAkB;;;;;;;;EAS1B;EACA;EACA;EACA,WAAW;;;;;;;;;UAUI;WACN;;iBAGK,mBAAmB,aAAa,KAAK;;;;cAYxC,YAAY,mBAAmB,mBAAmB,0BACrD,YAAY,+BACT;SAEJ;MAIH,cAAc;EAKlB;WAES;;;;;EAMT;EAEA;EAEA,WAAW;;;;;;;;EAUX;EAEA,YACE,QAAQ,qBAAqB,sBAAsB,mBACnD,sBACA;EAGF,YAAY,QAAQ,kBAAkB;;;;;;SA6B/B,WAAW,UAAU,kBAC1B,SAAS,YAAY,KACpB,WAAW,YAAY,KAAK,YAAY;;;;;SAKpC,WAAW,mBAAmB,WAAW;MASnC,oBAAoB;;;;;;cAatB,iBACX,mBAAmB,mBAAmB,0BAC9B,iBAAiB;WAChB;EAET;;;;;EAMA;;;;;;;;EAUA;EAEA,YAAY,QAAQ,kBAAkB;SAO/B;EAIP,OAAO,OAAO,iBAAiB;MAmBlB,oBAAoB;;UASlB,SACf,+BAEA,cAAc,sBAAsB;WAE3B;;;;EAIT;;;;EAIA,MAAM;;;;EAIN,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAgDS,cAAc;WACpB;;;;EAIT;;;;EAIA,OAAO;;;;EAIP;;;;EAIA;;UAGe,gBAAgB;WACtB;;;;EAIT;;;;;EAKA,OAAO;;;;EAIP;;;;EAIA;;;;EAIA;;iBAGc,sBAEd,cAAc,yBACZ,YAAY;;;;iBA+BA,cAAc,aAAa,KAAK;;;;iBAahC,mBAAmB,GAAG,mBAAmB,KAAK"}
1
+ {"version":3,"file":"tool.d.cts","names":[],"sources":["../../src/messages/tool.ts"],"mappings":";;;UAYiB,kBACf,mBAAmB,mBAAmB,0BAC9B,kBAAkB;;;;;;;;EAS1B;EACA;EACA;EACA,WAAW;;;;;;;;;UAUI;WACN;;iBAGK,mBAAmB,aAAa,KAAK;;;;cAYxC,YAAY,mBAAmB,mBAAmB,0BACrD,YAAY,+BACT;SAEJ;MAIH,cAAc;EAKlB;WAES;;;;;EAMT;EAEA;EAEA,WAAW;;;;;;;;EAUX;EAEA,YACE,QAAQ,qBAAqB,sBAAsB,mBACnD,sBACA;EAGF,YAAY,QAAQ,kBAAkB;;;;;;SA6B/B,WAAW,UAAU,kBAC1B,SAAS,YAAY,KACpB,WAAW,YAAY,KAAK,YAAY;;;;;SAKpC,WAAW,mBAAmB,WAAW;UASxC,OAAO,aAAa,eAAY,OAAA,YAAA,iBATQ;MAanC,oBAAoB;;;;;;cAatB,iBACX,mBAAmB,mBAAmB,0BAC9B,iBAAiB;WAChB;EAET;;;;;EAMA;;;;;;;;EAUA;EAEA,YAAY,QAAQ,kBAAkB;SAO/B;EAIP,OAAO,OAAO,iBAAiB;SAmBxB,WAAW,eAAe,OAAO;UAIhC,OAAO,aAAa,eAAY,OAAA,iBAAA,iBAJA;MAQ3B,oBAAoB;;UASlB,SACf,+BAEA,cAAc,sBAAsB;WAE3B;;;;EAIT;;;;EAIA,MAAM;;;;EAIN,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAgDS,cAAc;WACpB;;;;EAIT;;;;EAIA,OAAO;;;;EAIP;;;;EAIA;;UAGe,gBAAgB;WACtB;;;;EAIT;;;;;EAKA,OAAO;;;;EAIP;;;;EAIA;;;;EAIA;;iBAGc,sBAEd,cAAc,yBACZ,YAAY;;;;iBA+BA,cAAc,aAAa,KAAK;;;;iBAahC,mBAAmB,GAAG,mBAAmB,KAAK"}
@@ -1,5 +1,5 @@
1
1
  import { BaseMessage, BaseMessageChunk, BaseMessageFields } from "./base.js";
2
- import { $InferMessageContent, MessageStructure } from "./message.js";
2
+ import { $InferMessageContent, MessageStructure, MessageToolSet } from "./message.js";
3
3
  //#region src/messages/tool.d.ts
4
4
  interface ToolMessageFields<TStructure extends MessageStructure = MessageStructure> extends BaseMessageFields<TStructure, "tool"> {
5
5
  /**
@@ -61,6 +61,7 @@ declare class ToolMessage<TStructure extends MessageStructure = MessageStructure
61
61
  * @overload When called with unknown, returns base ToolMessage type
62
62
  */
63
63
  static isInstance(message: unknown): message is ToolMessage;
64
+ static [Symbol.hasInstance](obj: unknown): obj is ToolMessage<MessageStructure<MessageToolSet>>;
64
65
  get _printableFields(): Record<string, unknown>;
65
66
  }
66
67
  /**
@@ -86,6 +87,8 @@ declare class ToolMessageChunk<TStructure extends MessageStructure = MessageStru
86
87
  constructor(fields: ToolMessageFields<TStructure>);
87
88
  static lc_name(): string;
88
89
  concat(chunk: ToolMessageChunk<TStructure>): this;
90
+ static isInstance(obj: unknown): obj is ToolMessageChunk;
91
+ static [Symbol.hasInstance](obj: unknown): obj is ToolMessageChunk<MessageStructure<MessageToolSet>>;
89
92
  get _printableFields(): Record<string, unknown>;
90
93
  }
91
94
  interface ToolCall<TName extends string = string, TArgs extends Record<string, any> = Record<string, any>> {
@@ -1 +1 @@
1
- {"version":3,"file":"tool.d.ts","names":[],"sources":["../../src/messages/tool.ts"],"mappings":";;;UAYiB,kBACf,mBAAmB,mBAAmB,0BAC9B,kBAAkB;;;;;;;;EAS1B;EACA;EACA;EACA,WAAW;;;;;;;;;UAUI;WACN;;iBAGK,mBAAmB,aAAa,KAAK;;;;cAYxC,YAAY,mBAAmB,mBAAmB,0BACrD,YAAY,+BACT;SAEJ;MAIH,cAAc;EAKlB;WAES;;;;;EAMT;EAEA;EAEA,WAAW;;;;;;;;EAUX;EAEA,YACE,QAAQ,qBAAqB,sBAAsB,mBACnD,sBACA;EAGF,YAAY,QAAQ,kBAAkB;;;;;;SA6B/B,WAAW,UAAU,kBAC1B,SAAS,YAAY,KACpB,WAAW,YAAY,KAAK,YAAY;;;;;SAKpC,WAAW,mBAAmB,WAAW;MASnC,oBAAoB;;;;;;cAatB,iBACX,mBAAmB,mBAAmB,0BAC9B,iBAAiB;WAChB;EAET;;;;;EAMA;;;;;;;;EAUA;EAEA,YAAY,QAAQ,kBAAkB;SAO/B;EAIP,OAAO,OAAO,iBAAiB;MAmBlB,oBAAoB;;UASlB,SACf,+BAEA,cAAc,sBAAsB;WAE3B;;;;EAIT;;;;EAIA,MAAM;;;;EAIN,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAgDS,cAAc;WACpB;;;;EAIT;;;;EAIA,OAAO;;;;EAIP;;;;EAIA;;UAGe,gBAAgB;WACtB;;;;EAIT;;;;;EAKA,OAAO;;;;EAIP;;;;EAIA;;;;EAIA;;iBAGc,sBAEd,cAAc,yBACZ,YAAY;;;;iBA+BA,cAAc,aAAa,KAAK;;;;iBAahC,mBAAmB,GAAG,mBAAmB,KAAK"}
1
+ {"version":3,"file":"tool.d.ts","names":[],"sources":["../../src/messages/tool.ts"],"mappings":";;;UAYiB,kBACf,mBAAmB,mBAAmB,0BAC9B,kBAAkB;;;;;;;;EAS1B;EACA;EACA;EACA,WAAW;;;;;;;;;UAUI;WACN;;iBAGK,mBAAmB,aAAa,KAAK;;;;cAYxC,YAAY,mBAAmB,mBAAmB,0BACrD,YAAY,+BACT;SAEJ;MAIH,cAAc;EAKlB;WAES;;;;;EAMT;EAEA;EAEA,WAAW;;;;;;;;EAUX;EAEA,YACE,QAAQ,qBAAqB,sBAAsB,mBACnD,sBACA;EAGF,YAAY,QAAQ,kBAAkB;;;;;;SA6B/B,WAAW,UAAU,kBAC1B,SAAS,YAAY,KACpB,WAAW,YAAY,KAAK,YAAY;;;;;SAKpC,WAAW,mBAAmB,WAAW;UASxC,OAAO,aAAa,eAAY,OAAA,YAAA,iBATQ;MAanC,oBAAoB;;;;;;cAatB,iBACX,mBAAmB,mBAAmB,0BAC9B,iBAAiB;WAChB;EAET;;;;;EAMA;;;;;;;;EAUA;EAEA,YAAY,QAAQ,kBAAkB;SAO/B;EAIP,OAAO,OAAO,iBAAiB;SAmBxB,WAAW,eAAe,OAAO;UAIhC,OAAO,aAAa,eAAY,OAAA,iBAAA,iBAJA;MAQ3B,oBAAoB;;UASlB,SACf,+BAEA,cAAc,sBAAsB;WAE3B;;;;EAIT;;;;EAIA,MAAM;;;;EAIN,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAgDS,cAAc;WACpB;;;;EAIT;;;;EAIA,OAAO;;;;EAIP;;;;EAIA;;UAGe,gBAAgB;WACtB;;;;EAIT;;;;;EAKA,OAAO;;;;EAIP;;;;EAIA;;;;EAIA;;iBAGc,sBAEd,cAAc,yBACZ,YAAY;;;;iBA+BA,cAAc,aAAa,KAAK;;;;iBAahC,mBAAmB,GAAG,mBAAmB,KAAK"}
@@ -54,6 +54,9 @@ var ToolMessage = class extends BaseMessage {
54
54
  static isInstance(message) {
55
55
  return super.isInstance(message) && message.type === "tool";
56
56
  }
57
+ static [Symbol.hasInstance](obj) {
58
+ return this.isInstance(obj);
59
+ }
57
60
  get _printableFields() {
58
61
  return {
59
62
  ...super._printableFields,
@@ -103,6 +106,12 @@ var ToolMessageChunk = class extends BaseMessageChunk {
103
106
  status: _mergeStatus(this.status, chunk.status)
104
107
  });
105
108
  }
109
+ static isInstance(obj) {
110
+ return super.isInstance(obj) && obj.type === "tool";
111
+ }
112
+ static [Symbol.hasInstance](obj) {
113
+ return this.isInstance(obj);
114
+ }
106
115
  get _printableFields() {
107
116
  return {
108
117
  ...super._printableFields,
@@ -1 +1 @@
1
- {"version":3,"file":"tool.js","names":[],"sources":["../../src/messages/tool.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageChunk,\n type BaseMessageFields,\n mergeContent,\n _mergeDicts,\n _mergeObj,\n _mergeStatus,\n} from \"./base.js\";\nimport { $InferMessageContent, MessageStructure } from \"./message.js\";\nimport { Constructor } from \"./utils.js\";\n\nexport interface ToolMessageFields<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageFields<TStructure, \"tool\"> {\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n tool_call_id: string;\n status?: \"success\" | \"error\";\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Marker parameter for objects that tools can return directly.\n *\n * If a custom BaseTool is invoked with a ToolCall and the output of custom code is\n * not an instance of DirectToolOutput, the output will automatically be coerced to\n * a string and wrapped in a ToolMessage.\n */\nexport interface DirectToolOutput {\n readonly lc_direct_tool_output: true;\n}\n\nexport function isDirectToolOutput(x: unknown): x is DirectToolOutput {\n return (\n x != null &&\n typeof x === \"object\" &&\n \"lc_direct_tool_output\" in x &&\n x.lc_direct_tool_output === true\n );\n}\n\n/**\n * Represents a tool message in a conversation.\n */\nexport class ToolMessage<TStructure extends MessageStructure = MessageStructure>\n extends BaseMessage<TStructure, \"tool\">\n implements DirectToolOutput\n{\n static lc_name() {\n return \"ToolMessage\";\n }\n\n get lc_aliases(): Record<string, string> {\n // exclude snake case conversion to pascal case\n return { tool_call_id: \"tool_call_id\" };\n }\n\n lc_direct_tool_output = true as const;\n\n readonly type = \"tool\" as const;\n\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n\n tool_call_id: string;\n\n metadata?: Record<string, unknown>;\n\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n\n constructor(\n fields: $InferMessageContent<TStructure, \"tool\"> | ToolMessageFields,\n tool_call_id: string,\n name?: string\n );\n\n constructor(fields: ToolMessageFields<TStructure>);\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"tool\">\n | ToolMessageFields<TStructure>,\n tool_call_id?: string,\n name?: string\n ) {\n const toolMessageFields: ToolMessageFields<TStructure> =\n typeof fields === \"string\" || Array.isArray(fields)\n ? ({\n content: fields,\n name,\n tool_call_id: tool_call_id!,\n } as ToolMessageFields<TStructure>)\n : fields;\n super(toolMessageFields);\n this.tool_call_id = toolMessageFields.tool_call_id;\n this.artifact = toolMessageFields.artifact;\n this.status = toolMessageFields.status;\n this.metadata = toolMessageFields.metadata;\n }\n\n /**\n * Type guard to check if an object is a ToolMessage.\n * Preserves the MessageStructure type parameter when called with a typed BaseMessage.\n * @overload When called with a typed BaseMessage, preserves the TStructure type\n */\n static isInstance<T extends MessageStructure>(\n message: BaseMessage<T>\n ): message is BaseMessage<T> & ToolMessage<T>;\n /**\n * Type guard to check if an object is a ToolMessage.\n * @overload When called with unknown, returns base ToolMessage type\n */\n static isInstance(message: unknown): message is ToolMessage;\n static isInstance<T extends MessageStructure = MessageStructure>(\n message: BaseMessage<T> | unknown\n ): message is ToolMessage<T> {\n return (\n super.isInstance(message) && (message as { type: string }).type === \"tool\"\n );\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact,\n };\n }\n}\n\n/**\n * Represents a chunk of a tool message, which can be concatenated\n * with other tool message chunks.\n */\nexport class ToolMessageChunk<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageChunk<TStructure, \"tool\"> {\n readonly type = \"tool\" as const;\n\n tool_call_id: string;\n\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n\n constructor(fields: ToolMessageFields<TStructure>) {\n super(fields);\n this.tool_call_id = fields.tool_call_id;\n this.artifact = fields.artifact;\n this.status = fields.status;\n }\n\n static lc_name() {\n return \"ToolMessageChunk\";\n }\n\n concat(chunk: ToolMessageChunk<TStructure>) {\n const Cls = this.constructor as Constructor<this>;\n return new Cls({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: _mergeDicts(\n this.additional_kwargs,\n chunk.additional_kwargs\n ),\n response_metadata: _mergeDicts(\n this.response_metadata,\n chunk.response_metadata\n ),\n artifact: _mergeObj(this.artifact, chunk.artifact),\n tool_call_id: this.tool_call_id,\n id: this.id ?? chunk.id,\n status: _mergeStatus(this.status, chunk.status),\n });\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact,\n };\n }\n}\n\nexport interface ToolCall<\n TName extends string = string,\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n TArgs extends Record<string, any> = Record<string, any>,\n> {\n readonly type?: \"tool_call\";\n /**\n * If provided, an identifier associated with the tool call\n */\n id?: string;\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n}\n\n/**\n * A chunk of a tool call (e.g., as part of a stream).\n * When merging ToolCallChunks (e.g., via AIMessageChunk.__add__),\n * all string attributes are concatenated. Chunks are only merged if their\n * values of `index` are equal and not None.\n *\n * @example\n * ```ts\n * const leftChunks = [\n * {\n * name: \"foo\",\n * args: '{\"a\":',\n * index: 0\n * }\n * ];\n *\n * const leftAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: leftChunks\n * });\n *\n * const rightChunks = [\n * {\n * name: undefined,\n * args: '1}',\n * index: 0\n * }\n * ];\n *\n * const rightAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: rightChunks\n * });\n *\n * const result = leftAIMessageChunk.concat(rightAIMessageChunk);\n * // result.tool_call_chunks is equal to:\n * // [\n * // {\n * // name: \"foo\",\n * // args: '{\"a\":1}'\n * // index: 0\n * // }\n * // ]\n * ```\n */\nexport interface ToolCallChunk<TName extends string = string> {\n readonly type?: \"tool_call_chunk\";\n /**\n * If provided, a substring of an identifier for the tool call\n */\n id?: string;\n /**\n * If provided, a substring of the name of the tool to be called\n */\n name?: TName;\n /**\n * If provided, a JSON substring of the arguments to the tool call\n */\n args?: string;\n /**\n * If provided, the index of the tool call in a sequence\n */\n index?: number;\n}\n\nexport interface InvalidToolCall<TName extends string = string> {\n readonly type?: \"invalid_tool_call\";\n /**\n * If provided, an identifier associated with the tool call\n */\n id?: string;\n /**\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n}\n\nexport function defaultToolCallParser(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCalls: Record<string, any>[]\n): [ToolCall[], InvalidToolCall[]] {\n const toolCalls: ToolCall[] = [];\n const invalidToolCalls: InvalidToolCall[] = [];\n for (const toolCall of rawToolCalls) {\n if (!toolCall.function) {\n continue;\n } else {\n const functionName = toolCall.function.name;\n try {\n const functionArgs = JSON.parse(toolCall.function.arguments);\n toolCalls.push({\n name: functionName || \"\",\n args: functionArgs || {},\n id: toolCall.id,\n });\n } catch {\n invalidToolCalls.push({\n name: functionName,\n args: toolCall.function.arguments,\n id: toolCall.id,\n error: \"Malformed args.\",\n });\n }\n }\n }\n return [toolCalls, invalidToolCalls];\n}\n\n/**\n * @deprecated Use {@link ToolMessage.isInstance} instead\n */\nexport function isToolMessage(x: unknown): x is ToolMessage {\n return (\n typeof x === \"object\" &&\n x !== null &&\n \"getType\" in x &&\n typeof x.getType === \"function\" &&\n x.getType() === \"tool\"\n );\n}\n\n/**\n * @deprecated Use {@link ToolMessageChunk.isInstance} instead\n */\nexport function isToolMessageChunk(x: BaseMessageChunk): x is ToolMessageChunk {\n return x._getType() === \"tool\";\n}\n"],"mappings":";;;;;;;;;;;AAwCA,SAAgB,mBAAmB,GAAmC;CACpE,OACE,KAAK,QACL,OAAO,MAAM,YACb,2BAA2B,KAC3B,EAAE,0BAA0B;AAEhC;;;;AAKA,IAAa,cAAb,cACU,YAEV;CACE,OAAO,UAAU;EACf,OAAO;CACT;CAEA,IAAI,aAAqC;EAEvC,OAAO,EAAE,cAAc,eAAe;CACxC;CAEA,wBAAwB;CAExB,OAAgB;;;;;CAMhB;CAEA;CAEA;;;;;;;;CAUA;CAUA,YACE,QAGA,cACA,MACA;EACA,MAAM,oBACJ,OAAO,WAAW,YAAY,MAAM,QAAQ,MAAM,IAC7C;GACC,SAAS;GACT;GACc;EAChB,IACA;EACN,MAAM,iBAAiB;EACvB,KAAK,eAAe,kBAAkB;EACtC,KAAK,WAAW,kBAAkB;EAClC,KAAK,SAAS,kBAAkB;EAChC,KAAK,WAAW,kBAAkB;CACpC;CAeA,OAAO,WACL,SAC2B;EAC3B,OACE,MAAM,WAAW,OAAO,KAAM,QAA6B,SAAS;CAExE;CAEA,IAAa,mBAA4C;EACvD,OAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EACjB;CACF;AACF;;;;;AAMA,IAAa,mBAAb,cAEU,iBAAqC;CAC7C,OAAgB;CAEhB;;;;;CAMA;;;;;;;;CAUA;CAEA,YAAY,QAAuC;EACjD,MAAM,MAAM;EACZ,KAAK,eAAe,OAAO;EAC3B,KAAK,WAAW,OAAO;EACvB,KAAK,SAAS,OAAO;CACvB;CAEA,OAAO,UAAU;EACf,OAAO;CACT;CAEA,OAAO,OAAqC;EAC1C,MAAM,MAAM,KAAK;EACjB,OAAO,IAAI,IAAI;GACb,SAAS,aAAa,KAAK,SAAS,MAAM,OAAO;GACjD,mBAAmB,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,mBAAmB,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,UAAU,UAAU,KAAK,UAAU,MAAM,QAAQ;GACjD,cAAc,KAAK;GACnB,IAAI,KAAK,MAAM,MAAM;GACrB,QAAQ,aAAa,KAAK,QAAQ,MAAM,MAAM;EAChD,CAAC;CACH;CAEA,IAAa,mBAA4C;EACvD,OAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EACjB;CACF;AACF;AAgHA,SAAgB,sBAEd,cACiC;CACjC,MAAM,YAAwB,CAAC;CAC/B,MAAM,mBAAsC,CAAC;CAC7C,KAAK,MAAM,YAAY,cACrB,IAAI,CAAC,SAAS,UACZ;MACK;EACL,MAAM,eAAe,SAAS,SAAS;EACvC,IAAI;GACF,MAAM,eAAe,KAAK,MAAM,SAAS,SAAS,SAAS;GAC3D,UAAU,KAAK;IACb,MAAM,gBAAgB;IACtB,MAAM,gBAAgB,CAAC;IACvB,IAAI,SAAS;GACf,CAAC;EACH,QAAQ;GACN,iBAAiB,KAAK;IACpB,MAAM;IACN,MAAM,SAAS,SAAS;IACxB,IAAI,SAAS;IACb,OAAO;GACT,CAAC;EACH;CACF;CAEF,OAAO,CAAC,WAAW,gBAAgB;AACrC;;;;AAKA,SAAgB,cAAc,GAA8B;CAC1D,OACE,OAAO,MAAM,YACb,MAAM,QACN,aAAa,KACb,OAAO,EAAE,YAAY,cACrB,EAAE,QAAQ,MAAM;AAEpB;;;;AAKA,SAAgB,mBAAmB,GAA4C;CAC7E,OAAO,EAAE,SAAS,MAAM;AAC1B"}
1
+ {"version":3,"file":"tool.js","names":[],"sources":["../../src/messages/tool.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageChunk,\n type BaseMessageFields,\n mergeContent,\n _mergeDicts,\n _mergeObj,\n _mergeStatus,\n} from \"./base.js\";\nimport { $InferMessageContent, MessageStructure } from \"./message.js\";\nimport { Constructor } from \"./utils.js\";\n\nexport interface ToolMessageFields<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageFields<TStructure, \"tool\"> {\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n tool_call_id: string;\n status?: \"success\" | \"error\";\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Marker parameter for objects that tools can return directly.\n *\n * If a custom BaseTool is invoked with a ToolCall and the output of custom code is\n * not an instance of DirectToolOutput, the output will automatically be coerced to\n * a string and wrapped in a ToolMessage.\n */\nexport interface DirectToolOutput {\n readonly lc_direct_tool_output: true;\n}\n\nexport function isDirectToolOutput(x: unknown): x is DirectToolOutput {\n return (\n x != null &&\n typeof x === \"object\" &&\n \"lc_direct_tool_output\" in x &&\n x.lc_direct_tool_output === true\n );\n}\n\n/**\n * Represents a tool message in a conversation.\n */\nexport class ToolMessage<TStructure extends MessageStructure = MessageStructure>\n extends BaseMessage<TStructure, \"tool\">\n implements DirectToolOutput\n{\n static lc_name() {\n return \"ToolMessage\";\n }\n\n get lc_aliases(): Record<string, string> {\n // exclude snake case conversion to pascal case\n return { tool_call_id: \"tool_call_id\" };\n }\n\n lc_direct_tool_output = true as const;\n\n readonly type = \"tool\" as const;\n\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n\n tool_call_id: string;\n\n metadata?: Record<string, unknown>;\n\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n\n constructor(\n fields: $InferMessageContent<TStructure, \"tool\"> | ToolMessageFields,\n tool_call_id: string,\n name?: string\n );\n\n constructor(fields: ToolMessageFields<TStructure>);\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"tool\">\n | ToolMessageFields<TStructure>,\n tool_call_id?: string,\n name?: string\n ) {\n const toolMessageFields: ToolMessageFields<TStructure> =\n typeof fields === \"string\" || Array.isArray(fields)\n ? ({\n content: fields,\n name,\n tool_call_id: tool_call_id!,\n } as ToolMessageFields<TStructure>)\n : fields;\n super(toolMessageFields);\n this.tool_call_id = toolMessageFields.tool_call_id;\n this.artifact = toolMessageFields.artifact;\n this.status = toolMessageFields.status;\n this.metadata = toolMessageFields.metadata;\n }\n\n /**\n * Type guard to check if an object is a ToolMessage.\n * Preserves the MessageStructure type parameter when called with a typed BaseMessage.\n * @overload When called with a typed BaseMessage, preserves the TStructure type\n */\n static isInstance<T extends MessageStructure>(\n message: BaseMessage<T>\n ): message is BaseMessage<T> & ToolMessage<T>;\n /**\n * Type guard to check if an object is a ToolMessage.\n * @overload When called with unknown, returns base ToolMessage type\n */\n static isInstance(message: unknown): message is ToolMessage;\n static isInstance<T extends MessageStructure = MessageStructure>(\n message: BaseMessage<T> | unknown\n ): message is ToolMessage<T> {\n return (\n super.isInstance(message) && (message as { type: string }).type === \"tool\"\n );\n }\n\n static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact,\n };\n }\n}\n\n/**\n * Represents a chunk of a tool message, which can be concatenated\n * with other tool message chunks.\n */\nexport class ToolMessageChunk<\n TStructure extends MessageStructure = MessageStructure,\n> extends BaseMessageChunk<TStructure, \"tool\"> {\n readonly type = \"tool\" as const;\n\n tool_call_id: string;\n\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n\n constructor(fields: ToolMessageFields<TStructure>) {\n super(fields);\n this.tool_call_id = fields.tool_call_id;\n this.artifact = fields.artifact;\n this.status = fields.status;\n }\n\n static lc_name() {\n return \"ToolMessageChunk\";\n }\n\n concat(chunk: ToolMessageChunk<TStructure>) {\n const Cls = this.constructor as Constructor<this>;\n return new Cls({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: _mergeDicts(\n this.additional_kwargs,\n chunk.additional_kwargs\n ),\n response_metadata: _mergeDicts(\n this.response_metadata,\n chunk.response_metadata\n ),\n artifact: _mergeObj(this.artifact, chunk.artifact),\n tool_call_id: this.tool_call_id,\n id: this.id ?? chunk.id,\n status: _mergeStatus(this.status, chunk.status),\n });\n }\n\n static isInstance(obj: unknown): obj is ToolMessageChunk {\n return super.isInstance(obj) && obj.type === \"tool\";\n }\n\n static [Symbol.hasInstance](obj: unknown) {\n return this.isInstance(obj);\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact,\n };\n }\n}\n\nexport interface ToolCall<\n TName extends string = string,\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n TArgs extends Record<string, any> = Record<string, any>,\n> {\n readonly type?: \"tool_call\";\n /**\n * If provided, an identifier associated with the tool call\n */\n id?: string;\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n}\n\n/**\n * A chunk of a tool call (e.g., as part of a stream).\n * When merging ToolCallChunks (e.g., via AIMessageChunk.__add__),\n * all string attributes are concatenated. Chunks are only merged if their\n * values of `index` are equal and not None.\n *\n * @example\n * ```ts\n * const leftChunks = [\n * {\n * name: \"foo\",\n * args: '{\"a\":',\n * index: 0\n * }\n * ];\n *\n * const leftAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: leftChunks\n * });\n *\n * const rightChunks = [\n * {\n * name: undefined,\n * args: '1}',\n * index: 0\n * }\n * ];\n *\n * const rightAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: rightChunks\n * });\n *\n * const result = leftAIMessageChunk.concat(rightAIMessageChunk);\n * // result.tool_call_chunks is equal to:\n * // [\n * // {\n * // name: \"foo\",\n * // args: '{\"a\":1}'\n * // index: 0\n * // }\n * // ]\n * ```\n */\nexport interface ToolCallChunk<TName extends string = string> {\n readonly type?: \"tool_call_chunk\";\n /**\n * If provided, a substring of an identifier for the tool call\n */\n id?: string;\n /**\n * If provided, a substring of the name of the tool to be called\n */\n name?: TName;\n /**\n * If provided, a JSON substring of the arguments to the tool call\n */\n args?: string;\n /**\n * If provided, the index of the tool call in a sequence\n */\n index?: number;\n}\n\nexport interface InvalidToolCall<TName extends string = string> {\n readonly type?: \"invalid_tool_call\";\n /**\n * If provided, an identifier associated with the tool call\n */\n id?: string;\n /**\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n}\n\nexport function defaultToolCallParser(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCalls: Record<string, any>[]\n): [ToolCall[], InvalidToolCall[]] {\n const toolCalls: ToolCall[] = [];\n const invalidToolCalls: InvalidToolCall[] = [];\n for (const toolCall of rawToolCalls) {\n if (!toolCall.function) {\n continue;\n } else {\n const functionName = toolCall.function.name;\n try {\n const functionArgs = JSON.parse(toolCall.function.arguments);\n toolCalls.push({\n name: functionName || \"\",\n args: functionArgs || {},\n id: toolCall.id,\n });\n } catch {\n invalidToolCalls.push({\n name: functionName,\n args: toolCall.function.arguments,\n id: toolCall.id,\n error: \"Malformed args.\",\n });\n }\n }\n }\n return [toolCalls, invalidToolCalls];\n}\n\n/**\n * @deprecated Use {@link ToolMessage.isInstance} instead\n */\nexport function isToolMessage(x: unknown): x is ToolMessage {\n return (\n typeof x === \"object\" &&\n x !== null &&\n \"getType\" in x &&\n typeof x.getType === \"function\" &&\n x.getType() === \"tool\"\n );\n}\n\n/**\n * @deprecated Use {@link ToolMessageChunk.isInstance} instead\n */\nexport function isToolMessageChunk(x: BaseMessageChunk): x is ToolMessageChunk {\n return x._getType() === \"tool\";\n}\n"],"mappings":";;;;;;;;;;;AAwCA,SAAgB,mBAAmB,GAAmC;CACpE,OACE,KAAK,QACL,OAAO,MAAM,YACb,2BAA2B,KAC3B,EAAE,0BAA0B;AAEhC;;;;AAKA,IAAa,cAAb,cACU,YAEV;CACE,OAAO,UAAU;EACf,OAAO;CACT;CAEA,IAAI,aAAqC;EAEvC,OAAO,EAAE,cAAc,eAAe;CACxC;CAEA,wBAAwB;CAExB,OAAgB;;;;;CAMhB;CAEA;CAEA;;;;;;;;CAUA;CAUA,YACE,QAGA,cACA,MACA;EACA,MAAM,oBACJ,OAAO,WAAW,YAAY,MAAM,QAAQ,MAAM,IAC7C;GACC,SAAS;GACT;GACc;EAChB,IACA;EACN,MAAM,iBAAiB;EACvB,KAAK,eAAe,kBAAkB;EACtC,KAAK,WAAW,kBAAkB;EAClC,KAAK,SAAS,kBAAkB;EAChC,KAAK,WAAW,kBAAkB;CACpC;CAeA,OAAO,WACL,SAC2B;EAC3B,OACE,MAAM,WAAW,OAAO,KAAM,QAA6B,SAAS;CAExE;CAEA,QAAQ,OAAO,aAAa,KAAc;EACxC,OAAO,KAAK,WAAW,GAAG;CAC5B;CAEA,IAAa,mBAA4C;EACvD,OAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EACjB;CACF;AACF;;;;;AAMA,IAAa,mBAAb,cAEU,iBAAqC;CAC7C,OAAgB;CAEhB;;;;;CAMA;;;;;;;;CAUA;CAEA,YAAY,QAAuC;EACjD,MAAM,MAAM;EACZ,KAAK,eAAe,OAAO;EAC3B,KAAK,WAAW,OAAO;EACvB,KAAK,SAAS,OAAO;CACvB;CAEA,OAAO,UAAU;EACf,OAAO;CACT;CAEA,OAAO,OAAqC;EAC1C,MAAM,MAAM,KAAK;EACjB,OAAO,IAAI,IAAI;GACb,SAAS,aAAa,KAAK,SAAS,MAAM,OAAO;GACjD,mBAAmB,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,mBAAmB,YACjB,KAAK,mBACL,MAAM,iBACR;GACA,UAAU,UAAU,KAAK,UAAU,MAAM,QAAQ;GACjD,cAAc,KAAK;GACnB,IAAI,KAAK,MAAM,MAAM;GACrB,QAAQ,aAAa,KAAK,QAAQ,MAAM,MAAM;EAChD,CAAC;CACH;CAEA,OAAO,WAAW,KAAuC;EACvD,OAAO,MAAM,WAAW,GAAG,KAAK,IAAI,SAAS;CAC/C;CAEA,QAAQ,OAAO,aAAa,KAAc;EACxC,OAAO,KAAK,WAAW,GAAG;CAC5B;CAEA,IAAa,mBAA4C;EACvD,OAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EACjB;CACF;AACF;AAgHA,SAAgB,sBAEd,cACiC;CACjC,MAAM,YAAwB,CAAC;CAC/B,MAAM,mBAAsC,CAAC;CAC7C,KAAK,MAAM,YAAY,cACrB,IAAI,CAAC,SAAS,UACZ;MACK;EACL,MAAM,eAAe,SAAS,SAAS;EACvC,IAAI;GACF,MAAM,eAAe,KAAK,MAAM,SAAS,SAAS,SAAS;GAC3D,UAAU,KAAK;IACb,MAAM,gBAAgB;IACtB,MAAM,gBAAgB,CAAC;IACvB,IAAI,SAAS;GACf,CAAC;EACH,QAAQ;GACN,iBAAiB,KAAK;IACpB,MAAM;IACN,MAAM,SAAS,SAAS;IACxB,IAAI,SAAS;IACb,OAAO;GACT,CAAC;EACH;CACF;CAEF,OAAO,CAAC,WAAW,gBAAgB;AACrC;;;;AAKA,SAAgB,cAAc,GAA8B;CAC1D,OACE,OAAO,MAAM,YACb,MAAM,QACN,aAAa,KACb,OAAO,EAAE,YAAY,cACrB,EAAE,QAAQ,MAAM;AAEpB;;;;AAKA,SAAgB,mBAAmB,GAA4C;CAC7E,OAAO,EAAE,SAAS,MAAM;AAC1B"}
@@ -2,7 +2,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
3
3
  const require_utils_env = require("./env.cjs");
4
4
  //#region src/utils/gateway.ts
5
- var gateway_exports = /* @__PURE__ */ require_runtime.__exportAll({ resolveLangSmithGatewayConfig: () => resolveLangSmithGatewayConfig });
5
+ var gateway_exports = /* @__PURE__ */ require_runtime.__exportAll({
6
+ DEFAULT_LANGSMITH_GATEWAY: () => DEFAULT_LANGSMITH_GATEWAY,
7
+ resolveLangSmithGatewayConfig: () => resolveLangSmithGatewayConfig
8
+ });
6
9
  const LANGSMITH_GATEWAY = "LANGSMITH_GATEWAY";
7
10
  const LANGSMITH_GATEWAY_API_KEY = "LANGSMITH_GATEWAY_API_KEY";
8
11
  const LANGSMITH_API_KEY = "LANGSMITH_API_KEY";
@@ -32,6 +35,7 @@ function resolveLangSmithGatewayConfig({ baseURL, providerPath }) {
32
35
  };
33
36
  }
34
37
  //#endregion
38
+ exports.DEFAULT_LANGSMITH_GATEWAY = DEFAULT_LANGSMITH_GATEWAY;
35
39
  Object.defineProperty(exports, "gateway_exports", {
36
40
  enumerable: true,
37
41
  get: function() {
@@ -1 +1 @@
1
- {"version":3,"file":"gateway.cjs","names":["getEnvironmentVariable"],"sources":["../../src/utils/gateway.ts"],"sourcesContent":["import { getEnvironmentVariable } from \"./env.js\";\n\nconst LANGSMITH_GATEWAY = \"LANGSMITH_GATEWAY\";\nconst LANGSMITH_GATEWAY_API_KEY = \"LANGSMITH_GATEWAY_API_KEY\";\nconst LANGSMITH_API_KEY = \"LANGSMITH_API_KEY\";\nconst DEFAULT_LANGSMITH_GATEWAY = \"https://gateway.smith.langchain.com\";\nconst TRUE_VALUES = [\"true\", \"1\", \"yes\"];\nconst FALSE_VALUES = [\"false\", \"0\", \"no\"];\n\nexport interface LangSmithGatewayConfigOptions {\n baseURL?: string;\n providerPath: string;\n}\n\nexport interface LangSmithGatewayConfig {\n baseURL?: string;\n apiKey?: string;\n}\n\nfunction resolveLangSmithGatewayBaseURL(\n providerPath: string\n): string | undefined {\n const value = getEnvironmentVariable(LANGSMITH_GATEWAY);\n if (!value || FALSE_VALUES.includes(value.toLowerCase())) {\n return undefined;\n }\n const baseURL = TRUE_VALUES.includes(value.toLowerCase())\n ? DEFAULT_LANGSMITH_GATEWAY\n : value.replace(/\\/+$/, \"\");\n return `${baseURL}/${providerPath}`;\n}\n\nexport function resolveLangSmithGatewayConfig({\n baseURL,\n providerPath,\n}: LangSmithGatewayConfigOptions): LangSmithGatewayConfig {\n if (baseURL !== undefined) {\n return { baseURL };\n }\n\n const gatewayBaseURL = resolveLangSmithGatewayBaseURL(providerPath);\n if (gatewayBaseURL === undefined) {\n return {};\n }\n\n return {\n baseURL: gatewayBaseURL,\n apiKey:\n getEnvironmentVariable(LANGSMITH_GATEWAY_API_KEY) ||\n getEnvironmentVariable(LANGSMITH_API_KEY),\n };\n}\n"],"mappings":";;;;;AAEA,MAAM,oBAAoB;AAC1B,MAAM,4BAA4B;AAClC,MAAM,oBAAoB;AAC1B,MAAM,4BAA4B;AAClC,MAAM,cAAc;CAAC;CAAQ;CAAK;AAAK;AACvC,MAAM,eAAe;CAAC;CAAS;CAAK;AAAI;AAYxC,SAAS,+BACP,cACoB;CACpB,MAAM,QAAQA,kBAAAA,uBAAuB,iBAAiB;CACtD,IAAI,CAAC,SAAS,aAAa,SAAS,MAAM,YAAY,CAAC,GACrD;CAKF,OAAO,GAHS,YAAY,SAAS,MAAM,YAAY,CAAC,IACpD,4BACA,MAAM,QAAQ,QAAQ,EAAE,EACV,GAAG;AACvB;AAEA,SAAgB,8BAA8B,EAC5C,SACA,gBACwD;CACxD,IAAI,YAAY,KAAA,GACd,OAAO,EAAE,QAAQ;CAGnB,MAAM,iBAAiB,+BAA+B,YAAY;CAClE,IAAI,mBAAmB,KAAA,GACrB,OAAO,CAAC;CAGV,OAAO;EACL,SAAS;EACT,QACEA,kBAAAA,uBAAuB,yBAAyB,KAChDA,kBAAAA,uBAAuB,iBAAiB;CAC5C;AACF"}
1
+ {"version":3,"file":"gateway.cjs","names":["getEnvironmentVariable"],"sources":["../../src/utils/gateway.ts"],"sourcesContent":["import { getEnvironmentVariable } from \"./env.js\";\n\nconst LANGSMITH_GATEWAY = \"LANGSMITH_GATEWAY\";\nconst LANGSMITH_GATEWAY_API_KEY = \"LANGSMITH_GATEWAY_API_KEY\";\nconst LANGSMITH_API_KEY = \"LANGSMITH_API_KEY\";\nexport const DEFAULT_LANGSMITH_GATEWAY = \"https://gateway.smith.langchain.com\";\nconst TRUE_VALUES = [\"true\", \"1\", \"yes\"];\nconst FALSE_VALUES = [\"false\", \"0\", \"no\"];\n\nexport interface LangSmithGatewayConfigOptions {\n baseURL?: string;\n providerPath: string;\n}\n\nexport interface LangSmithGatewayConfig {\n baseURL?: string;\n apiKey?: string;\n}\n\nfunction resolveLangSmithGatewayBaseURL(\n providerPath: string\n): string | undefined {\n const value = getEnvironmentVariable(LANGSMITH_GATEWAY);\n if (!value || FALSE_VALUES.includes(value.toLowerCase())) {\n return undefined;\n }\n const baseURL = TRUE_VALUES.includes(value.toLowerCase())\n ? DEFAULT_LANGSMITH_GATEWAY\n : value.replace(/\\/+$/, \"\");\n return `${baseURL}/${providerPath}`;\n}\n\nexport function resolveLangSmithGatewayConfig({\n baseURL,\n providerPath,\n}: LangSmithGatewayConfigOptions): LangSmithGatewayConfig {\n if (baseURL !== undefined) {\n return { baseURL };\n }\n\n const gatewayBaseURL = resolveLangSmithGatewayBaseURL(providerPath);\n if (gatewayBaseURL === undefined) {\n return {};\n }\n\n return {\n baseURL: gatewayBaseURL,\n apiKey:\n getEnvironmentVariable(LANGSMITH_GATEWAY_API_KEY) ||\n getEnvironmentVariable(LANGSMITH_API_KEY),\n };\n}\n"],"mappings":";;;;;;;;AAEA,MAAM,oBAAoB;AAC1B,MAAM,4BAA4B;AAClC,MAAM,oBAAoB;AAC1B,MAAa,4BAA4B;AACzC,MAAM,cAAc;CAAC;CAAQ;CAAK;AAAK;AACvC,MAAM,eAAe;CAAC;CAAS;CAAK;AAAI;AAYxC,SAAS,+BACP,cACoB;CACpB,MAAM,QAAQA,kBAAAA,uBAAuB,iBAAiB;CACtD,IAAI,CAAC,SAAS,aAAa,SAAS,MAAM,YAAY,CAAC,GACrD;CAKF,OAAO,GAHS,YAAY,SAAS,MAAM,YAAY,CAAC,IACpD,4BACA,MAAM,QAAQ,QAAQ,EAAE,EACV,GAAG;AACvB;AAEA,SAAgB,8BAA8B,EAC5C,SACA,gBACwD;CACxD,IAAI,YAAY,KAAA,GACd,OAAO,EAAE,QAAQ;CAGnB,MAAM,iBAAiB,+BAA+B,YAAY;CAClE,IAAI,mBAAmB,KAAA,GACrB,OAAO,CAAC;CAGV,OAAO;EACL,SAAS;EACT,QACEA,kBAAAA,uBAAuB,yBAAyB,KAChDA,kBAAAA,uBAAuB,iBAAiB;CAC5C;AACF"}
@@ -1,4 +1,5 @@
1
1
  //#region src/utils/gateway.d.ts
2
+ declare const DEFAULT_LANGSMITH_GATEWAY = "https://gateway.smith.langchain.com";
2
3
  interface LangSmithGatewayConfigOptions {
3
4
  baseURL?: string;
4
5
  providerPath: string;
@@ -9,5 +10,5 @@ interface LangSmithGatewayConfig {
9
10
  }
10
11
  declare function resolveLangSmithGatewayConfig({ baseURL, providerPath }: LangSmithGatewayConfigOptions): LangSmithGatewayConfig;
11
12
  //#endregion
12
- export { LangSmithGatewayConfig, LangSmithGatewayConfigOptions, resolveLangSmithGatewayConfig };
13
+ export { DEFAULT_LANGSMITH_GATEWAY, LangSmithGatewayConfig, LangSmithGatewayConfigOptions, resolveLangSmithGatewayConfig };
13
14
  //# sourceMappingURL=gateway.d.cts.map