Explorar o código

feat(simulation): support multiple tool calls (#35861)

James Long hai 1 mes
pai
achega
8d00a51766

+ 7 - 1
packages/simulation/src/backend/llm-exchange.ts

@@ -18,7 +18,13 @@ import { Effect, Queue } from "effect"
 export type Item =
   | { readonly type: "textDelta"; readonly text: string }
   | { readonly type: "reasoningDelta"; readonly text: string }
-  | { readonly type: "toolCall"; readonly id: string; readonly name: string; readonly input: unknown }
+  | {
+      readonly type: "toolCall"
+      readonly index: number
+      readonly id: string
+      readonly name: string
+      readonly input: unknown
+    }
   | { readonly type: "raw"; readonly chunk: unknown }
 
 export type FinishReason = "stop" | "tool-calls" | "length" | "content-filter"

+ 5 - 1
packages/simulation/src/backend/openai.ts

@@ -30,7 +30,11 @@ function chunkOf(item: SimulationLLMExchange.Item): OpenAIChatEvent | unknown {
         {
           delta: {
             tool_calls: [
-              { index: 0, id: item.id, function: { name: item.name, arguments: JSON.stringify(item.input) } },
+              {
+                index: item.index,
+                id: item.id,
+                function: { name: item.name, arguments: JSON.stringify(item.input) },
+              },
             ],
           },
         },

+ 7 - 1
packages/simulation/src/protocol/index.ts

@@ -141,7 +141,13 @@ export namespace Backend {
   export const Item = Schema.Union([
     Schema.Struct({ type: Schema.Literal("textDelta"), text: Schema.String }),
     Schema.Struct({ type: Schema.Literal("reasoningDelta"), text: Schema.String }),
-    Schema.Struct({ type: Schema.Literal("toolCall"), id: Schema.String, name: Schema.String, input: Schema.Json }),
+    Schema.Struct({
+      type: Schema.Literal("toolCall"),
+      index: Schema.Number,
+      id: Schema.String,
+      name: Schema.String,
+      input: Schema.Json,
+    }),
     Schema.Struct({ type: Schema.Literal("raw"), chunk: Schema.Json }),
   ])
   export type Item = Schema.Schema.Type<typeof Item>