@copilotkit/runtime 1.3.14 → 1.3.15

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 (39) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/{chunk-I5X63624.mjs → chunk-3RAQGSAI.mjs} +3 -3
  3. package/dist/{chunk-I5X63624.mjs.map → chunk-3RAQGSAI.mjs.map} +1 -1
  4. package/dist/{chunk-TOIJ5IIA.mjs → chunk-CUN5GXCO.mjs} +3 -3
  5. package/dist/{chunk-EN2GQDJF.mjs → chunk-FH4SPOAG.mjs} +2 -2
  6. package/dist/{chunk-CPAHDRLS.mjs → chunk-MXXPWWBF.mjs} +4 -8
  7. package/dist/chunk-MXXPWWBF.mjs.map +1 -0
  8. package/dist/{chunk-Y6RQG5HF.mjs → chunk-NMV7A7VP.mjs} +2 -2
  9. package/dist/{chunk-6TFW5P6C.mjs → chunk-R3IJK6GR.mjs} +2 -2
  10. package/dist/{chunk-HTQXEUKU.mjs → chunk-WYB2Z6SM.mjs} +2 -2
  11. package/dist/index.js +4 -8
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +7 -7
  14. package/dist/lib/index.js +4 -8
  15. package/dist/lib/index.js.map +1 -1
  16. package/dist/lib/index.mjs +7 -7
  17. package/dist/lib/integrations/index.js +1 -1
  18. package/dist/lib/integrations/index.js.map +1 -1
  19. package/dist/lib/integrations/index.mjs +5 -5
  20. package/dist/lib/integrations/nest/index.js +1 -1
  21. package/dist/lib/integrations/nest/index.js.map +1 -1
  22. package/dist/lib/integrations/nest/index.mjs +3 -3
  23. package/dist/lib/integrations/node-express/index.js +1 -1
  24. package/dist/lib/integrations/node-express/index.js.map +1 -1
  25. package/dist/lib/integrations/node-express/index.mjs +3 -3
  26. package/dist/lib/integrations/node-http/index.js +1 -1
  27. package/dist/lib/integrations/node-http/index.js.map +1 -1
  28. package/dist/lib/integrations/node-http/index.mjs +2 -2
  29. package/dist/service-adapters/index.js +3 -7
  30. package/dist/service-adapters/index.js.map +1 -1
  31. package/dist/service-adapters/index.mjs +2 -2
  32. package/package.json +4 -4
  33. package/src/service-adapters/langchain/utils.ts +3 -7
  34. package/dist/chunk-CPAHDRLS.mjs.map +0 -1
  35. /package/dist/{chunk-TOIJ5IIA.mjs.map → chunk-CUN5GXCO.mjs.map} +0 -0
  36. /package/dist/{chunk-EN2GQDJF.mjs.map → chunk-FH4SPOAG.mjs.map} +0 -0
  37. /package/dist/{chunk-Y6RQG5HF.mjs.map → chunk-NMV7A7VP.mjs.map} +0 -0
  38. /package/dist/{chunk-6TFW5P6C.mjs.map → chunk-R3IJK6GR.mjs.map} +0 -0
  39. /package/dist/{chunk-HTQXEUKU.mjs.map → chunk-WYB2Z6SM.mjs.map} +0 -0
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  RemoteChain
3
- } from "./chunk-Y6RQG5HF.mjs";
3
+ } from "./chunk-NMV7A7VP.mjs";
4
4
  import {
5
5
  RuntimeEventSource,
6
6
  isLangGraphAgentAction,
7
7
  setupRemoteActions
8
- } from "./chunk-I5X63624.mjs";
8
+ } from "./chunk-3RAQGSAI.mjs";
9
9
  import {
10
10
  ActionExecutionMessage,
11
11
  AgentStateMessage,
@@ -258,4 +258,4 @@ export {
258
258
  CopilotRuntime,
259
259
  flattenToolCallsNoDuplicates
260
260
  };
261
- //# sourceMappingURL=chunk-TOIJ5IIA.mjs.map
261
+ //# sourceMappingURL=chunk-CUN5GXCO.mjs.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  copilotRuntimeNodeHttpEndpoint,
3
3
  telemetry_client_default
4
- } from "./chunk-I5X63624.mjs";
4
+ } from "./chunk-3RAQGSAI.mjs";
5
5
  import {
6
6
  __name
7
7
  } from "./chunk-44O2JGUY.mjs";
@@ -21,4 +21,4 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
21
21
  export {
22
22
  copilotRuntimeNestEndpoint
23
23
  };
24
- //# sourceMappingURL=chunk-EN2GQDJF.mjs.map
24
+ //# sourceMappingURL=chunk-FH4SPOAG.mjs.map
@@ -44,7 +44,7 @@ function convertJsonSchemaToZodSchema(jsonSchema, required) {
44
44
  for (const [key, value] of Object.entries(jsonSchema.properties)) {
45
45
  spec[key] = convertJsonSchemaToZodSchema(value, jsonSchema.required ? jsonSchema.required.includes(key) : false);
46
46
  }
47
- let schema = z.object(spec);
47
+ let schema = z.object(spec).describe(jsonSchema.description);
48
48
  return required ? schema : schema.optional();
49
49
  } else if (jsonSchema.type === "string") {
50
50
  let schema = z.string().describe(jsonSchema.description);
@@ -57,7 +57,7 @@ function convertJsonSchemaToZodSchema(jsonSchema, required) {
57
57
  return required ? schema : schema.optional();
58
58
  } else if (jsonSchema.type === "array") {
59
59
  let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);
60
- let schema = z.array(itemSchema);
60
+ let schema = z.array(itemSchema).describe(jsonSchema.description);
61
61
  return required ? schema : schema.optional();
62
62
  }
63
63
  }
@@ -133,8 +133,6 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
133
133
  let toolCallName = void 0;
134
134
  let toolCallId = void 0;
135
135
  let toolCallArgs = void 0;
136
- let toolCallIndex = void 0;
137
- let toolCallPrevIndex = void 0;
138
136
  let hasToolCall = false;
139
137
  let content = value == null ? void 0 : value.content;
140
138
  if (isAIMessageChunk(value)) {
@@ -152,8 +150,6 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
152
150
  toolCallDetails.id = chunk.index != null ? `${chunk.id}-idx-${chunk.index}` : chunk.id;
153
151
  toolCallName = toolCallDetails.name;
154
152
  toolCallId = toolCallDetails.id;
155
- toolCallIndex = toolCallDetails.index;
156
- toolCallPrevIndex = toolCallDetails.prevIndex;
157
153
  } else if (isBaseMessageChunk(value)) {
158
154
  let chunk = (_f = (_e = value.additional_kwargs) == null ? void 0 : _e.tool_calls) == null ? void 0 : _f[0];
159
155
  toolCallName = (_g = chunk == null ? void 0 : chunk.function) == null ? void 0 : _g.name;
@@ -183,7 +179,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
183
179
  if (mode === "message" && content) {
184
180
  eventStream$.sendTextMessageContent(Array.isArray(content) ? ((_i = content[0]) == null ? void 0 : _i.text) ?? "" : content);
185
181
  } else if (mode === "function" && toolCallArgs) {
186
- if (toolCallIndex !== toolCallPrevIndex) {
182
+ if (toolCallDetails.index !== toolCallDetails.prevIndex) {
187
183
  eventStream$.sendActionExecutionEnd();
188
184
  eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
189
185
  toolCallDetails.prevIndex = toolCallDetails.index;
@@ -219,4 +215,4 @@ export {
219
215
  convertActionInputToLangChainTool,
220
216
  streamLangChainResponse
221
217
  };
222
- //# sourceMappingURL=chunk-CPAHDRLS.mjs.map
218
+ //# sourceMappingURL=chunk-MXXPWWBF.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/service-adapters/langchain/utils.ts"],"sourcesContent":["import {\n ActionExecutionMessage,\n Message,\n ResultMessage,\n TextMessage,\n} from \"../../graphql/types/converted\";\nimport {\n AIMessage,\n AIMessageChunk,\n BaseMessage,\n BaseMessageChunk,\n HumanMessage,\n SystemMessage,\n ToolMessage,\n} from \"@langchain/core/messages\";\nimport { DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { z } from \"zod\";\nimport { ActionInput } from \"../../graphql/inputs/action.input\";\nimport { LangChainReturnType } from \"./types\";\nimport { RuntimeEventSubject } from \"../events\";\nimport { randomId } from \"@copilotkit/shared\";\n\nexport function convertMessageToLangChainMessage(message: Message): BaseMessage {\n if (message.isTextMessage()) {\n if (message.role == \"user\") {\n return new HumanMessage(message.content);\n } else if (message.role == \"assistant\") {\n return new AIMessage(message.content);\n } else if (message.role === \"system\") {\n return new SystemMessage(message.content);\n }\n } else if (message.isActionExecutionMessage()) {\n return new AIMessage({\n content: \"\",\n tool_calls: [\n {\n id: message.id,\n args: message.arguments,\n name: message.name,\n },\n ],\n });\n } else if (message.isResultMessage()) {\n return new ToolMessage({\n content: message.result,\n tool_call_id: message.actionExecutionId,\n });\n }\n}\n\nexport function convertJsonSchemaToZodSchema(jsonSchema: any, required: boolean): z.ZodSchema {\n if (jsonSchema.type === \"object\") {\n const spec: { [key: string]: z.ZodSchema } = {};\n\n if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {\n return !required ? z.object(spec).optional() : z.object(spec);\n }\n\n for (const [key, value] of Object.entries(jsonSchema.properties)) {\n spec[key] = convertJsonSchemaToZodSchema(\n value,\n jsonSchema.required ? jsonSchema.required.includes(key) : false,\n );\n }\n let schema = z.object(spec).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"string\") {\n let schema = z.string().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"number\") {\n let schema = z.number().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"boolean\") {\n let schema = z.boolean().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"array\") {\n let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);\n let schema = z.array(itemSchema).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n }\n}\n\nexport function convertActionInputToLangChainTool(actionInput: ActionInput): any {\n return new DynamicStructuredTool({\n name: actionInput.name,\n description: actionInput.description,\n schema: convertJsonSchemaToZodSchema(\n JSON.parse(actionInput.jsonSchema),\n true,\n ) as z.ZodObject<any>,\n func: async () => {\n return \"\";\n },\n });\n}\n\ninterface StreamLangChainResponseParams {\n result: LangChainReturnType;\n eventStream$: RuntimeEventSubject;\n actionExecution?: {\n id: string;\n name: string;\n };\n}\n\nfunction getConstructorName(object: any): string {\n if (object && typeof object === \"object\" && object.constructor && object.constructor.name) {\n return object.constructor.name;\n }\n return \"\";\n}\n\nfunction isAIMessage(message: any): message is AIMessage {\n return Object.prototype.toString.call(message) === \"[object AIMessage]\";\n}\n\nfunction isAIMessageChunk(message: any): message is AIMessageChunk {\n return Object.prototype.toString.call(message) === \"[object AIMessageChunk]\";\n}\n\nfunction isBaseMessageChunk(message: any): message is BaseMessageChunk {\n return Object.prototype.toString.call(message) === \"[object BaseMessageChunk]\";\n}\n\nfunction maybeSendActionExecutionResultIsMessage(\n eventStream$: RuntimeEventSubject,\n actionExecution?: { id: string; name: string },\n) {\n // language models need a result after the function call\n // we simply let them know that we are sending a message\n if (actionExecution) {\n eventStream$.sendActionExecutionResult(\n actionExecution.id,\n actionExecution.name,\n \"Sending a message\",\n );\n }\n}\n\nexport async function streamLangChainResponse({\n result,\n eventStream$,\n actionExecution,\n}: StreamLangChainResponseParams) {\n // We support several types of return values from LangChain functions:\n\n // 1. string\n\n if (typeof result === \"string\") {\n if (!actionExecution) {\n // Just send one chunk with the string as the content.\n eventStream$.sendTextMessage(randomId(), result);\n } else {\n // Send as a result\n eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, result);\n }\n }\n\n // 2. AIMessage\n // Send the content and function call of the AIMessage as the content of the chunk.\n else if (isAIMessage(result)) {\n maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);\n\n if (result.content) {\n eventStream$.sendTextMessage(randomId(), result.content as string);\n }\n for (const toolCall of result.tool_calls) {\n eventStream$.sendActionExecution(\n toolCall.id || randomId(),\n toolCall.name,\n JSON.stringify(toolCall.args),\n );\n }\n }\n\n // 3. BaseMessageChunk\n // Send the content and function call of the AIMessage as the content of the chunk.\n else if (isBaseMessageChunk(result)) {\n maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);\n\n if (result.lc_kwargs?.content) {\n eventStream$.sendTextMessage(randomId(), result.content as string);\n }\n if (result.lc_kwargs?.tool_calls) {\n for (const toolCall of result.lc_kwargs?.tool_calls) {\n eventStream$.sendActionExecution(\n toolCall.id || randomId(),\n toolCall.name,\n JSON.stringify(toolCall.args),\n );\n }\n }\n }\n\n // 4. IterableReadableStream\n // Stream the result of the LangChain function.\n else if (result && \"getReader\" in result) {\n maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);\n\n let reader = result.getReader();\n\n let mode: \"function\" | \"message\" | null = null;\n\n const toolCallDetails = {\n name: null,\n id: null,\n index: null,\n prevIndex: null,\n };\n\n while (true) {\n try {\n const { done, value } = await reader.read();\n\n let toolCallName: string | undefined = undefined;\n let toolCallId: string | undefined = undefined;\n let toolCallArgs: string | undefined = undefined;\n let hasToolCall: boolean = false;\n let content = value?.content as string;\n\n if (isAIMessageChunk(value)) {\n let chunk = value.tool_call_chunks?.[0];\n toolCallArgs = chunk?.args;\n hasToolCall = chunk != undefined;\n if (chunk?.name) toolCallDetails.name = chunk.name;\n // track different index on the same tool cool\n if (chunk?.index != null) {\n toolCallDetails.index = chunk.index; // 1\n if (toolCallDetails.prevIndex == null) toolCallDetails.prevIndex = chunk.index;\n }\n // Differentiate when calling the same tool but with different index\n if (chunk?.id)\n toolCallDetails.id = chunk.index != null ? `${chunk.id}-idx-${chunk.index}` : chunk.id;\n\n // Assign to internal variables that the entire script here knows how to work with\n toolCallName = toolCallDetails.name;\n toolCallId = toolCallDetails.id;\n } else if (isBaseMessageChunk(value)) {\n let chunk = value.additional_kwargs?.tool_calls?.[0];\n toolCallName = chunk?.function?.name;\n toolCallId = chunk?.id;\n toolCallArgs = chunk?.function?.arguments;\n hasToolCall = chunk?.function != undefined;\n }\n\n // When switching from message to function or vice versa,\n // send the respective end event.\n // If toolCallName is defined, it means a new tool call starts.\n if (mode === \"message\" && (toolCallId || done)) {\n mode = null;\n eventStream$.sendTextMessageEnd();\n } else if (mode === \"function\" && (!hasToolCall || done)) {\n mode = null;\n eventStream$.sendActionExecutionEnd();\n }\n\n if (done) {\n break;\n }\n\n // If we send a new message type, send the appropriate start event.\n if (mode === null) {\n if (hasToolCall && toolCallId && toolCallName) {\n mode = \"function\";\n eventStream$.sendActionExecutionStart(toolCallId, toolCallName);\n } else if (content) {\n mode = \"message\";\n eventStream$.sendTextMessageStart(randomId());\n }\n }\n\n // send the content events\n if (mode === \"message\" && content) {\n eventStream$.sendTextMessageContent(\n Array.isArray(content) ? (content[0]?.text ?? \"\") : content,\n );\n } else if (mode === \"function\" && toolCallArgs) {\n // For calls of the same tool with different index, we seal last tool call and register a new one\n if (toolCallDetails.index !== toolCallDetails.prevIndex) {\n eventStream$.sendActionExecutionEnd();\n eventStream$.sendActionExecutionStart(toolCallId, toolCallName);\n toolCallDetails.prevIndex = toolCallDetails.index;\n }\n eventStream$.sendActionExecutionArgs(toolCallArgs);\n }\n } catch (error) {\n console.error(\"Error reading from stream\", error);\n break;\n }\n }\n } else if (actionExecution) {\n eventStream$.sendActionExecutionResult(\n actionExecution.id,\n actionExecution.name,\n encodeResult(result),\n );\n }\n\n // unsupported type\n else {\n throw new Error(\"Invalid return type from LangChain function.\");\n }\n\n eventStream$.complete();\n}\n\nfunction encodeResult(result: any): string {\n if (result === undefined) {\n return \"\";\n } else if (typeof result === \"string\") {\n return result;\n } else {\n return JSON.stringify(result);\n }\n}\n"],"mappings":";;;;;AAMA,SACEA,WAIAC,cACAC,eACAC,mBACK;AACP,SAASC,6BAA6B;AACtC,SAASC,SAAS;AAIlB,SAASC,gBAAgB;AAElB,SAASC,iCAAiCC,SAAgB;AAC/D,MAAIA,QAAQC,cAAa,GAAI;AAC3B,QAAID,QAAQE,QAAQ,QAAQ;AAC1B,aAAO,IAAIC,aAAaH,QAAQI,OAAO;IACzC,WAAWJ,QAAQE,QAAQ,aAAa;AACtC,aAAO,IAAIG,UAAUL,QAAQI,OAAO;IACtC,WAAWJ,QAAQE,SAAS,UAAU;AACpC,aAAO,IAAII,cAAcN,QAAQI,OAAO;IAC1C;EACF,WAAWJ,QAAQO,yBAAwB,GAAI;AAC7C,WAAO,IAAIF,UAAU;MACnBD,SAAS;MACTI,YAAY;QACV;UACEC,IAAIT,QAAQS;UACZC,MAAMV,QAAQW;UACdC,MAAMZ,QAAQY;QAChB;;IAEJ,CAAA;EACF,WAAWZ,QAAQa,gBAAe,GAAI;AACpC,WAAO,IAAIC,YAAY;MACrB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MAAAA,CAAAA;EAEjB,OAGK;AACH,UAAM,IAAI0C,MAAM,8CAAA;EAClB;AAEAhD,eAAaiD,SAAQ;AACvB;AArKsB5C;AAuKtB,SAAS0C,aAAazC,QAAW;AAC/B,MAAIA,WAAWqB,QAAW;AACxB,WAAO;EACT,WAAW,OAAOrB,WAAW,UAAU;AACrC,WAAOA;EACT,OAAO;AACL,WAAOO,KAAKC,UAAUR,MAAAA;EACxB;AACF;AARSyC;","names":["AIMessage","HumanMessage","SystemMessage","ToolMessage","DynamicStructuredTool","z","randomId","convertMessageToLangChainMessage","message","isTextMessage","role","HumanMessage","content","AIMessage","SystemMessage","isActionExecutionMessage","tool_calls","id","args","arguments","name","isResultMessage","ToolMessage","result","tool_call_id","actionExecutionId","convertJsonSchemaToZodSchema","jsonSchema","required","type","spec","properties","Object","keys","length","z","object","optional","key","value","entries","includes","schema","describe","description","string","number","boolean","itemSchema","items","array","convertActionInputToLangChainTool","actionInput","DynamicStructuredTool","JSON","parse","func","isAIMessage","message","Object","prototype","toString","call","isAIMessageChunk","isBaseMessageChunk","maybeSendActionExecutionResultIsMessage","eventStream$","actionExecution","sendActionExecutionResult","id","name","streamLangChainResponse","result","sendTextMessage","randomId","content","toolCall","tool_calls","sendActionExecution","JSON","stringify","args","lc_kwargs","reader","getReader","mode","toolCallDetails","index","prevIndex","done","value","read","toolCallName","undefined","toolCallId","toolCallArgs","hasToolCall","chunk","tool_call_chunks","additional_kwargs","function","arguments","sendTextMessageEnd","sendActionExecutionEnd","sendActionExecutionStart","sendTextMessageStart","sendTextMessageContent","Array","isArray","text","sendActionExecutionArgs","error","console","encodeResult","Error","complete"]}
@@ -2,7 +2,7 @@ import {
2
2
  convertActionInputToLangChainTool,
3
3
  convertMessageToLangChainMessage,
4
4
  streamLangChainResponse
5
- } from "./chunk-CPAHDRLS.mjs";
5
+ } from "./chunk-MXXPWWBF.mjs";
6
6
  import {
7
7
  __name
8
8
  } from "./chunk-44O2JGUY.mjs";
@@ -981,4 +981,4 @@ export {
981
981
  GroqAdapter,
982
982
  AnthropicAdapter
983
983
  };
984
- //# sourceMappingURL=chunk-Y6RQG5HF.mjs.map
984
+ //# sourceMappingURL=chunk-NMV7A7VP.mjs.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  copilotRuntimeNodeHttpEndpoint,
3
3
  telemetry_client_default
4
- } from "./chunk-I5X63624.mjs";
4
+ } from "./chunk-3RAQGSAI.mjs";
5
5
  import {
6
6
  __name
7
7
  } from "./chunk-44O2JGUY.mjs";
@@ -21,4 +21,4 @@ __name(copilotRuntimeNodeExpressEndpoint, "copilotRuntimeNodeExpressEndpoint");
21
21
  export {
22
22
  copilotRuntimeNodeExpressEndpoint
23
23
  };
24
- //# sourceMappingURL=chunk-6TFW5P6C.mjs.map
24
+ //# sourceMappingURL=chunk-R3IJK6GR.mjs.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getCommonConfig,
3
3
  telemetry_client_default
4
- } from "./chunk-I5X63624.mjs";
4
+ } from "./chunk-3RAQGSAI.mjs";
5
5
  import {
6
6
  __name
7
7
  } from "./chunk-44O2JGUY.mjs";
@@ -76,4 +76,4 @@ export {
76
76
  config,
77
77
  copilotRuntimeNextJSPagesRouterEndpoint
78
78
  };
79
- //# sourceMappingURL=chunk-HTQXEUKU.mjs.map
79
+ //# sourceMappingURL=chunk-WYB2Z6SM.mjs.map
package/dist/index.js CHANGED
@@ -44,7 +44,7 @@ var require_package = __commonJS({
44
44
  publishConfig: {
45
45
  access: "public"
46
46
  },
47
- version: "1.3.14",
47
+ version: "1.3.15",
48
48
  sideEffects: false,
49
49
  main: "./dist/index.js",
50
50
  module: "./dist/index.mjs",
@@ -506,7 +506,7 @@ function convertJsonSchemaToZodSchema(jsonSchema, required) {
506
506
  for (const [key, value] of Object.entries(jsonSchema.properties)) {
507
507
  spec[key] = convertJsonSchemaToZodSchema(value, jsonSchema.required ? jsonSchema.required.includes(key) : false);
508
508
  }
509
- let schema = import_zod.z.object(spec);
509
+ let schema = import_zod.z.object(spec).describe(jsonSchema.description);
510
510
  return required ? schema : schema.optional();
511
511
  } else if (jsonSchema.type === "string") {
512
512
  let schema = import_zod.z.string().describe(jsonSchema.description);
@@ -519,7 +519,7 @@ function convertJsonSchemaToZodSchema(jsonSchema, required) {
519
519
  return required ? schema : schema.optional();
520
520
  } else if (jsonSchema.type === "array") {
521
521
  let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);
522
- let schema = import_zod.z.array(itemSchema);
522
+ let schema = import_zod.z.array(itemSchema).describe(jsonSchema.description);
523
523
  return required ? schema : schema.optional();
524
524
  }
525
525
  }
@@ -595,8 +595,6 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
595
595
  let toolCallName = void 0;
596
596
  let toolCallId = void 0;
597
597
  let toolCallArgs = void 0;
598
- let toolCallIndex = void 0;
599
- let toolCallPrevIndex = void 0;
600
598
  let hasToolCall = false;
601
599
  let content = value == null ? void 0 : value.content;
602
600
  if (isAIMessageChunk(value)) {
@@ -614,8 +612,6 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
614
612
  toolCallDetails.id = chunk.index != null ? `${chunk.id}-idx-${chunk.index}` : chunk.id;
615
613
  toolCallName = toolCallDetails.name;
616
614
  toolCallId = toolCallDetails.id;
617
- toolCallIndex = toolCallDetails.index;
618
- toolCallPrevIndex = toolCallDetails.prevIndex;
619
615
  } else if (isBaseMessageChunk(value)) {
620
616
  let chunk = (_f = (_e = value.additional_kwargs) == null ? void 0 : _e.tool_calls) == null ? void 0 : _f[0];
621
617
  toolCallName = (_g = chunk == null ? void 0 : chunk.function) == null ? void 0 : _g.name;
@@ -645,7 +641,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
645
641
  if (mode === "message" && content) {
646
642
  eventStream$.sendTextMessageContent(Array.isArray(content) ? ((_i = content[0]) == null ? void 0 : _i.text) ?? "" : content);
647
643
  } else if (mode === "function" && toolCallArgs) {
648
- if (toolCallIndex !== toolCallPrevIndex) {
644
+ if (toolCallDetails.index !== toolCallDetails.prevIndex) {
649
645
  eventStream$.sendActionExecutionEnd();
650
646
  eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
651
647
  toolCallDetails.prevIndex = toolCallDetails.index;