@opencode-ai/ai
Advanced tools
@@ -615,5 +615,9 @@ import { Buffer } from "node:buffer"; | ||
| }; | ||
| const canUseNativeSystemUpdate = (messages, index) => { | ||
| const previous = messages[index - 1]; | ||
| const next = messages[index + 1]; | ||
| const canUseNativeSystemUpdate = (request, index) => { | ||
| const previous = request.messages[index - 1]; | ||
| const next = request.messages[index + 1]; | ||
| // Vertex currently rejects/404s for a system message after local tool results, | ||
| // so fold it into the user tool-result turn across continuations and history. | ||
| if (request.model.route.id === "google-vertex-messages" && previous?.role === "tool") | ||
| return false; | ||
| return (previous !== undefined && | ||
@@ -654,3 +658,3 @@ previous.role !== "system" && | ||
| return yield* invalid("Anthropic Messages system updates cannot split a local tool call from its tool result"); | ||
| if (supportsNativeSystemUpdates(request) && canUseNativeSystemUpdate(request.messages, index)) { | ||
| if (supportsNativeSystemUpdates(request) && canUseNativeSystemUpdate(request, index)) { | ||
| messages.push(yield* lowerNativeSystemUpdate(message, breakpoints)); | ||
@@ -657,0 +661,0 @@ continue; |
@@ -706,5 +706,6 @@ import { Effect, Schema } from "effect"; | ||
| } | ||
| if (item?.type !== "function_call" || !item.id) | ||
| if (item?.type !== "function_call" || !item.call_id) | ||
| return [state, NO_EVENTS]; | ||
| const metadata = providerMetadata(state, { itemId: item.id }); | ||
| const id = item.id ?? item.call_id; | ||
| const metadata = item.id ? providerMetadata(state, { itemId: item.id }) : undefined; | ||
| const events = []; | ||
@@ -716,4 +717,4 @@ const lifecycle = Lifecycle.stepStart(state.lifecycle, events); | ||
| lifecycle, | ||
| tools: ToolStream.start(state.tools, item.id, { | ||
| id: item.call_id ?? item.id, | ||
| tools: ToolStream.start(state.tools, id, { | ||
| id: item.call_id, | ||
| name: item.name ?? "", | ||
@@ -724,6 +725,3 @@ input: item.arguments ?? "", | ||
| }, | ||
| [ | ||
| ...events, | ||
| LLMEvent.toolInputStart({ id: item.call_id ?? item.id, name: item.name ?? "", providerMetadata: metadata }), | ||
| ], | ||
| [...events, LLMEvent.toolInputStart({ id: item.call_id, name: item.name ?? "", providerMetadata: metadata })], | ||
| ]; | ||
@@ -831,14 +829,15 @@ }; | ||
| if (item.type === "function_call") { | ||
| if (!item.id || !item.call_id || !item.name) | ||
| if (!item.call_id || !item.name) | ||
| return [state, NO_EVENTS]; | ||
| const tools = state.tools[item.id] | ||
| const id = item.id ?? item.call_id; | ||
| const tools = state.tools[id] | ||
| ? state.tools | ||
| : ToolStream.start(state.tools, item.id, { | ||
| : ToolStream.start(state.tools, id, { | ||
| id: item.call_id, | ||
| name: item.name, | ||
| providerMetadata: providerMetadata(state, { itemId: item.id }), | ||
| providerMetadata: item.id ? providerMetadata(state, { itemId: item.id }) : undefined, | ||
| }); | ||
| const result = item.arguments === undefined | ||
| ? yield* ToolStream.finish(state.id, tools, item.id) | ||
| : yield* ToolStream.finishWithInput(state.id, tools, item.id, item.arguments); | ||
| ? yield* ToolStream.finish(state.id, tools, id) | ||
| : yield* ToolStream.finishWithInput(state.id, tools, id, item.arguments); | ||
| const events = []; | ||
@@ -886,5 +885,6 @@ const resultEvents = result.events ?? []; | ||
| ? yield* Effect.reduce(event.response?.output ?? [], () => [state, NO_EVENTS], ([current, events], item) => { | ||
| if (!item.id || | ||
| ((item.type !== "function_call" || !current.tools[item.id]) && | ||
| (item.type !== "reasoning" || !current.reasoningItems[item.id]))) | ||
| const id = item.id ?? (item.type === "function_call" ? item.call_id : undefined); | ||
| if (!id || | ||
| ((item.type !== "function_call" || !current.tools[id]) && | ||
| (item.type !== "reasoning" || !current.reasoningItems[id]))) | ||
| return Effect.succeed([current, events]); | ||
@@ -999,4 +999,5 @@ return onOutputItemDone(current, { type: "response.output_item.done", item }).pipe(Effect.map(([next, emitted]) => [next, [...events, ...emitted]])); | ||
| return ProviderShared.eventError(state.id, `${event.type} message is missing id`); | ||
| return Effect.succeed(onOutputItemAdded(event.output_index !== undefined && event.item?.id | ||
| ? { ...state, outputItems: { ...state.outputItems, [event.output_index]: event.item.id } } | ||
| const id = event.item?.id ?? (event.item?.type === "function_call" ? event.item.call_id : undefined); | ||
| return Effect.succeed(onOutputItemAdded(event.output_index !== undefined && id | ||
| ? { ...state, outputItems: { ...state.outputItems, [event.output_index]: id } } | ||
| : state, event)); | ||
@@ -1003,0 +1004,0 @@ } |
+3
-3
| { | ||
| "$schema": "https://json.schemastore.org/package.json", | ||
| "version": "0.0.0-dev-18235", | ||
| "version": "0.0.0-dev-18237", | ||
| "name": "@opencode-ai/ai", | ||
@@ -33,3 +33,3 @@ "type": "module", | ||
| "@effect/platform-node": "4.0.0-rc.111", | ||
| "@opencode-ai/http-recorder": "0.0.0-dev-18235", | ||
| "@opencode-ai/http-recorder": "0.0.0-dev-18237", | ||
| "@tsconfig/bun": "1.0.9", | ||
@@ -43,3 +43,3 @@ "@types/bun": "1.3.13", | ||
| "@smithy/util-utf8": "4.2.2", | ||
| "@opencode-ai/schema": "0.0.0-dev-18235", | ||
| "@opencode-ai/schema": "0.0.0-dev-18237", | ||
| "aws4fetch": "1.0.20", | ||
@@ -46,0 +46,0 @@ "effect": "4.0.0-rc.111", |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
1314976
0.04%30164
0.02%+ Added
- Removed