@opencode-ai/ai 0.0.0-dev-18220 → 0.0.0-dev-18222

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.
@@ -285,6 +285,7 @@ export interface ParserState {
285
285
  }
286
286
  interface LoweringOptions {
287
287
  readonly cacheControl?: (cache: CacheHint | undefined) => Schema.Schema.Type<typeof OpenAIChatCacheControl> | undefined;
288
+ readonly toolCallID?: (id: string) => string;
288
289
  }
289
290
  export declare const fromRequest: (request: LLMRequest, options?: LoweringOptions | undefined) => Effect.Effect<{
290
291
  reasoning_effort?: import("./utils/open-responses-options.js").ReasoningEffort | undefined;
@@ -192,8 +192,8 @@ const lowerToolChoice = (toolChoice) => ProviderShared.matchToolChoice("OpenAI C
192
192
  required: () => "required",
193
193
  tool: (name) => ({ type: "function", function: { name } }),
194
194
  });
195
- const lowerToolCall = (part) => ({
196
- id: part.id,
195
+ const lowerToolCall = (part, options) => ({
196
+ id: options.toolCallID?.(part.id) ?? part.id,
197
197
  type: "function",
198
198
  function: {
199
199
  name: part.name,
@@ -257,7 +257,7 @@ const lowerAssistantMessage = Effect.fn("OpenAIChat.lowerAssistantMessage")(func
257
257
  continue;
258
258
  }
259
259
  if (part.type === "tool-call") {
260
- toolCalls.push(lowerToolCall(part));
260
+ toolCalls.push(lowerToolCall(part, options));
261
261
  continue;
262
262
  }
263
263
  }
@@ -307,7 +307,7 @@ const lowerToolMessages = Effect.fn("OpenAIChat.lowerToolMessages")(function* (m
307
307
  if (part.result.type !== "content") {
308
308
  messages.push({
309
309
  role: "tool",
310
- tool_call_id: part.id,
310
+ tool_call_id: options.toolCallID?.(part.id) ?? part.id,
311
311
  content: ProviderShared.toolResultText(part),
312
312
  cache_control: options.cacheControl?.(part.cache),
313
313
  });
@@ -317,7 +317,7 @@ const lowerToolMessages = Effect.fn("OpenAIChat.lowerToolMessages")(function* (m
317
317
  const text = content.filter((item) => item.type === "text").map((item) => item.text);
318
318
  messages.push({
319
319
  role: "tool",
320
- tool_call_id: part.id,
320
+ tool_call_id: options.toolCallID?.(part.id) ?? part.id,
321
321
  content: text.join("\n"),
322
322
  cache_control: options.cacheControl?.(part.cache),
323
323
  });
@@ -349,8 +349,21 @@ const lowerMessages = Effect.fn("OpenAIChat.lowerMessages")(function* (request,
349
349
  ]
350
350
  : [{ role: "system", content: ProviderShared.joinText(request.system) }];
351
351
  const messages = [...system];
352
- const requireAssistantAfterTool = request.model.compatibility?.requireAssistantAfterTool ??
353
- ["mistral", "devstral", "codestral", "pixtral", "mixtral"].some((family) => request.model.id.toLowerCase().includes(family));
352
+ const modelID = request.model.id.toLowerCase();
353
+ const mistral = ["mistral", "devstral", "codestral", "pixtral", "mixtral"].some((family) => modelID.includes(family));
354
+ const lowering = {
355
+ ...options,
356
+ toolCallID: (id) => {
357
+ if (mistral)
358
+ return id.replace(/[^a-zA-Z0-9]/g, "").slice(0, 9).padEnd(9, "0");
359
+ if (modelID.includes("claude"))
360
+ return id.replace(/[^a-zA-Z0-9_-]/g, "_");
361
+ if (request.model.provider === "openai" || request.model.provider === "azure" || modelID.startsWith("openai/"))
362
+ return id.slice(0, 40);
363
+ return id;
364
+ },
365
+ };
366
+ const requireAssistantAfterTool = request.model.compatibility?.requireAssistantAfterTool ?? mistral;
354
367
  const bridgeTools = () => {
355
368
  if (requireAssistantAfterTool && messages.at(-1)?.role === "tool")
356
369
  messages.push({ role: "assistant", content: "Done." });
@@ -408,13 +421,13 @@ const lowerMessages = Effect.fn("OpenAIChat.lowerMessages")(function* (request,
408
421
  if (message.role === "assistant" && message.content.every((part) => part.type === "text" && part.text.trim() === ""))
409
422
  continue;
410
423
  if (message.role === "tool") {
411
- const lowered = yield* lowerToolMessages(message, options);
424
+ const lowered = yield* lowerToolMessages(message, lowering);
412
425
  messages.push(...lowered.messages);
413
426
  pendingImages.push(...lowered.images);
414
427
  continue;
415
428
  }
416
429
  flushImages();
417
- messages.push(...(yield* lowerMessage(message, request.model.compatibility?.reasoningField, options)));
430
+ messages.push(...(yield* lowerMessage(message, request.model.compatibility?.reasoningField, lowering)));
418
431
  }
419
432
  flushImages();
420
433
  return messages;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "0.0.0-dev-18220",
3
+ "version": "0.0.0-dev-18222",
4
4
  "name": "@opencode-ai/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -30,7 +30,7 @@
30
30
  "devDependencies": {
31
31
  "@clack/prompts": "1.0.0-alpha.1",
32
32
  "@effect/platform-node": "4.0.0-rc.111",
33
- "@opencode-ai/http-recorder": "0.0.0-dev-18220",
33
+ "@opencode-ai/http-recorder": "0.0.0-dev-18222",
34
34
  "@tsconfig/bun": "1.0.9",
35
35
  "@types/bun": "1.3.13",
36
36
  "@typescript/native-preview": "7.0.0-dev.20251207.1",
@@ -39,7 +39,7 @@
39
39
  "dependencies": {
40
40
  "@smithy/eventstream-codec": "4.2.14",
41
41
  "@smithy/util-utf8": "4.2.2",
42
- "@opencode-ai/schema": "0.0.0-dev-18220",
42
+ "@opencode-ai/schema": "0.0.0-dev-18222",
43
43
  "aws4fetch": "1.0.20",
44
44
  "effect": "4.0.0-rc.111",
45
45
  "google-auth-library": "10.5.0"