@opencode-ai/ai
Advanced tools
@@ -464,2 +464,3 @@ import { Effect, Schema } from "effect"; | ||
| readonly summaryParts: Readonly<Record<number, ReasoningSummaryStatus>>; | ||
| readonly deltaIndexes: ReadonlySet<number>; | ||
| } | ||
@@ -655,3 +656,3 @@ export declare const lowerTool: (protocolName: string, tool: ToolDefinition, inputSchema: { | ||
| export declare const onReasoningDelta: (state: ParserState, event: Event, itemID: string) => StepResult; | ||
| export declare const onReasoningDone: (state: ParserState, _event: Event) => StepResult; | ||
| export declare const onReasoningDone: (state: ParserState, event: Event, itemID: string) => StepResult; | ||
| export declare const providerFailure: (id: string, event: Event, fallback: string) => AIError; | ||
@@ -658,0 +659,0 @@ export declare const step: (state: ParserState, event: Event) => AIError | Effect.Effect<StepResult, never, never> | Effect.Effect<[ParserState, readonly ({ |
@@ -598,10 +598,15 @@ import { Effect, Schema } from "effect"; | ||
| export const onReasoningDelta = (state, event, itemID) => { | ||
| if (!event.delta || !state.reasoningItems[itemID]) | ||
| const item = state.reasoningItems[itemID]; | ||
| if (!event.delta || !item) | ||
| return [state, NO_EVENTS]; | ||
| const index = event.summary_index ?? 0; | ||
| const events = []; | ||
| const id = `${itemID}:${event.summary_index ?? 0}`; | ||
| return [ | ||
| { | ||
| ...state, | ||
| lifecycle: Lifecycle.reasoningDelta(state.lifecycle, events, id, event.delta), | ||
| lifecycle: Lifecycle.reasoningDelta(state.lifecycle, events, `${itemID}:${index}`, event.delta), | ||
| reasoningItems: { | ||
| ...state.reasoningItems, | ||
| [itemID]: { ...item, deltaIndexes: new Set([...item.deltaIndexes, index]) }, | ||
| }, | ||
| }, | ||
@@ -611,3 +616,14 @@ events, | ||
| }; | ||
| export const onReasoningDone = (state, _event) => [state, NO_EVENTS]; | ||
| // Some compatible gateways emit a reasoning final without streaming any | ||
| // deltas, mirroring `response.output_text.done`. Reconcile the complete text | ||
| // as a single delta unless that summary index already streamed one. | ||
| export const onReasoningDone = (state, event, itemID) => { | ||
| const item = state.reasoningItems[itemID]; | ||
| if (!item || typeof event.text !== "string") | ||
| return [state, NO_EVENTS]; | ||
| const index = event.summary_index ?? 0; | ||
| if (item.deltaIndexes.has(index)) | ||
| return [state, NO_EVENTS]; | ||
| return onReasoningDelta(state, { ...event, delta: event.text }, itemID); | ||
| }; | ||
| const reasoningMetadata = (state, item) => providerMetadata(state, { itemId: item.id, reasoningEncryptedContent: item.encrypted_content ?? null }); | ||
@@ -647,3 +663,7 @@ // Responses APIs stream reasoning items in a stable order: | ||
| ...state.reasoningItems, | ||
| [item.id]: { encryptedContent: item.encrypted_content, summaryParts: { 0: "active" } }, | ||
| [item.id]: { | ||
| encryptedContent: item.encrypted_content, | ||
| summaryParts: { 0: "active" }, | ||
| deltaIndexes: new Set(), | ||
| }, | ||
| }, | ||
@@ -901,2 +921,10 @@ }, | ||
| } | ||
| if (event.type === "response.reasoning.done" || | ||
| event.type === "response.reasoning_summary_text.done" || | ||
| event.type === "response.reasoning_summary.done" || | ||
| event.type === "response.reasoning_text.done") { | ||
| if (!event.item_id) | ||
| return ProviderShared.eventError(state.id, `${event.type} is missing item_id`); | ||
| return Effect.succeed(onReasoningDone(state, event, event.item_id)); | ||
| } | ||
| if (event.type === "response.reasoning_summary_part.added") | ||
@@ -903,0 +931,0 @@ return event.item_id |
@@ -142,6 +142,2 @@ import { Effect, Encoding, Schema } from "effect"; | ||
| : ProviderShared.eventError(ADAPTER, `${event.type} is missing item_id`); | ||
| if (event.type === "response.reasoning_text.done" || event.type === "response.reasoning_summary.done") | ||
| return event.item_id | ||
| ? Effect.succeed(OpenResponses.onReasoningDone(state, event)) | ||
| : ProviderShared.eventError(ADAPTER, `${event.type} is missing item_id`); | ||
| if (event.type === "response.output_item.done" && event.item && ResponsesHostedTools.isItem(event.item, HOSTED_TOOLS)) | ||
@@ -148,0 +144,0 @@ return ResponsesHostedTools.onDone(state, event.item, HOSTED_TOOLS); |
@@ -1,5 +0,3 @@ | ||
| import { Effect } from "effect"; | ||
| import { Protocol } from "../route/protocol.js"; | ||
| import { OpenResponses } from "./open-responses.js"; | ||
| import { ProviderShared } from "./shared.js"; | ||
| import { ResponsesHostedTools } from "./utils/responses-hosted-tools.js"; | ||
@@ -26,11 +24,5 @@ const ADAPTER = "xai-responses"; | ||
| }; | ||
| // Grok speaks the standard Responses reasoning dialect (`reasoning_summary_text.*`, | ||
| // handled by the baseline); only its hosted tool vocabulary differs. | ||
| const step = (state, event) => { | ||
| if (event.type === "response.reasoning_text.delta" || event.type === "response.reasoning_summary.delta") | ||
| return event.item_id | ||
| ? Effect.succeed(OpenResponses.onReasoningDelta(state, event, event.item_id)) | ||
| : ProviderShared.eventError(ADAPTER, `${event.type} is missing item_id`); | ||
| if (event.type === "response.reasoning_text.done" || event.type === "response.reasoning_summary.done") | ||
| return event.item_id | ||
| ? Effect.succeed(OpenResponses.onReasoningDone(state, event)) | ||
| : ProviderShared.eventError(ADAPTER, `${event.type} is missing item_id`); | ||
| if (event.type === "response.output_item.done" && event.item && ResponsesHostedTools.isItem(event.item, HOSTED_TOOLS)) | ||
@@ -37,0 +29,0 @@ return ResponsesHostedTools.onDone(state, event.item, HOSTED_TOOLS); |
+3
-3
| { | ||
| "$schema": "https://json.schemastore.org/package.json", | ||
| "version": "0.0.0-dev-18059", | ||
| "version": "0.0.0-dev-18060", | ||
| "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-18059", | ||
| "@opencode-ai/http-recorder": "0.0.0-dev-18060", | ||
| "@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-18059", | ||
| "@opencode-ai/schema": "0.0.0-dev-18060", | ||
| "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.
1235885
0.04%28365
0.06%+ Added
- Removed