@revojs/ai 0.3.2 → 0.3.4

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.
@@ -234,11 +234,14 @@ async function* readParts(response, warnings) {
234
234
  }
235
235
  for (const partial of delta.tool_calls ?? []) {
236
236
  const index = partial.index ?? 0;
237
+ const id = typeof partial.id === "string" && partial.id.length > 0 ? partial.id : void 0;
238
+ const name = typeof partial.function?.name === "string" ? partial.function.name : "";
239
+ const input = typeof partial.function?.arguments === "string" ? partial.function.arguments : "";
237
240
  let accumulator = tools.get(index);
238
241
  if (accumulator === void 0) {
239
242
  accumulator = {
240
- streamId: partial.id ?? `openai-tool-${index}`,
241
- callId: partial.id ?? "",
243
+ streamId: id ?? `openai-tool-${index}`,
244
+ callId: id ?? "",
242
245
  name: "",
243
246
  arguments: ""
244
247
  };
@@ -246,17 +249,17 @@ async function* readParts(response, warnings) {
246
249
  yield {
247
250
  type: "tool-input-start",
248
251
  id: accumulator.streamId,
249
- toolName: partial.function?.name ?? ""
252
+ toolName: name
250
253
  };
251
254
  }
252
- if (partial.id !== void 0 && partial.id !== accumulator.callId) accumulator.callId = partial.id;
253
- if (partial.function?.name !== void 0) accumulator.name += partial.function.name;
254
- if (partial.function?.arguments !== void 0) {
255
- accumulator.arguments += partial.function.arguments;
255
+ if (id !== void 0) accumulator.callId = id;
256
+ accumulator.name += name;
257
+ if (input.length > 0) {
258
+ accumulator.arguments += input;
256
259
  yield {
257
260
  type: "tool-input-delta",
258
261
  id: accumulator.streamId,
259
- delta: partial.function.arguments
262
+ delta: input
260
263
  };
261
264
  }
262
265
  }
@@ -313,9 +316,9 @@ function chatCompletionsGenerateProtocol(config) {
313
316
  });
314
317
  for (const call of choice.message.tool_calls ?? []) content.push({
315
318
  type: "tool-call",
316
- toolCallId: call.id ?? "",
317
- toolName: call.function?.name ?? "",
318
- input: toToolInput(call.function?.arguments)
319
+ toolCallId: typeof call.id === "string" ? call.id : "",
320
+ toolName: typeof call.function?.name === "string" ? call.function.name : "",
321
+ input: toToolInput(typeof call.function?.arguments === "string" ? call.function.arguments : void 0)
319
322
  });
320
323
  return {
321
324
  content,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revojs/ai",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,10 +30,10 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@cfworker/json-schema": "^4.1.1",
33
- "@revojs/server": "0.3.2",
34
- "revojs": "0.3.2"
33
+ "@revojs/server": "0.3.4",
34
+ "revojs": "0.3.4"
35
35
  },
36
36
  "devDependencies": {
37
- "@revojs/tsconfig": "0.3.2"
37
+ "@revojs/tsconfig": "0.3.4"
38
38
  }
39
39
  }