@agentica/core 0.41.0 → 0.41.1

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.
@@ -23,8 +23,8 @@ function transformCompletionChunk(source: string | Uint8Array): ChatCompletionCh
23
23
  }
24
24
 
25
25
  function accumulate(origin: ChatCompletion, chunk: ChatCompletionChunk): ChatCompletion {
26
- const choices = origin.choices;
27
- chunk.choices.forEach((choice) => {
26
+ const choices = origin.choices ?? [];
27
+ (chunk.choices ?? []).forEach((choice) => {
28
28
  const accChoice = choices[choice.index];
29
29
  if (accChoice != null) {
30
30
  choices[choice.index] = mergeChoice(accChoice, choice);
@@ -101,7 +101,7 @@ function merge(chunks: ChatCompletionChunk[]): ChatCompletion {
101
101
  } as ChatCompletion);
102
102
 
103
103
  // post-process
104
- result.choices.forEach((choice) => {
104
+ result.choices?.forEach((choice) => {
105
105
  choice.message.tool_calls?.filter(tc => tc.type === "function").forEach((toolCall) => {
106
106
  if (toolCall.function.arguments === "") {
107
107
  toolCall.function.arguments = "{}";
@@ -55,10 +55,10 @@ async function reduceStreamingWithDispatch(stream: ReadableStream<ChatCompletion
55
55
  }
56
56
  };
57
57
  if (acc.object === "chat.completion.chunk") {
58
- registerContext([acc, chunk].flatMap(v => v.choices));
58
+ registerContext([acc, chunk].flatMap(v => v.choices ?? []));
59
59
  return ChatGptCompletionMessageUtil.merge([acc, chunk]);
60
60
  }
61
- registerContext(chunk.choices);
61
+ registerContext(chunk.choices ?? []);
62
62
  return ChatGptCompletionMessageUtil.accumulate(acc, chunk);
63
63
  }, { abortSignal });
64
64