@opencode-ai/ai
Advanced tools
+8
-2
@@ -179,3 +179,6 @@ import { Effect, JsonSchema, Schema } from "effect"; | ||
| readonly type: "step-finish"; | ||
| readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly reason: { | ||
| readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly raw?: string | undefined; | ||
| }; | ||
| readonly index: number; | ||
@@ -190,3 +193,6 @@ readonly providerMetadata?: { | ||
| readonly type: "finish"; | ||
| readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly reason: { | ||
| readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly raw?: string | undefined; | ||
| }; | ||
| readonly providerMetadata?: { | ||
@@ -193,0 +199,0 @@ readonly [x: string]: { |
@@ -501,3 +501,3 @@ import { Effect, Schema } from "effect"; | ||
| return "stop"; | ||
| if (reason === "max_tokens") | ||
| if (reason === "max_tokens" || reason === "model_context_window_exceeded") | ||
| return "length"; | ||
@@ -705,3 +705,6 @@ if (reason === "tool_use") | ||
| const lifecycle = Lifecycle.finish(state.lifecycle, events, { | ||
| reason: mapFinishReason(event.delta?.stop_reason), | ||
| reason: { | ||
| normalized: mapFinishReason(event.delta?.stop_reason), | ||
| raw: event.delta?.stop_reason ?? undefined, | ||
| }, | ||
| usage, | ||
@@ -708,0 +711,0 @@ providerMetadata: event.delta?.stop_sequence |
| import { Schema } from "effect"; | ||
| import { Route } from "../route/client"; | ||
| import { Protocol } from "../route/protocol"; | ||
| import { Usage, type FinishReason } from "../schema"; | ||
| import { Usage, type FinishReasonDetails } from "../schema"; | ||
| import { BedrockAuth } from "./utils/bedrock-auth"; | ||
@@ -130,3 +130,3 @@ import { Lifecycle } from "./utils/lifecycle"; | ||
| readonly pendingFinish: { | ||
| readonly reason: FinishReason; | ||
| readonly reason: FinishReasonDetails; | ||
| readonly usage?: Usage; | ||
@@ -133,0 +133,0 @@ } | undefined; |
@@ -339,3 +339,3 @@ import { Effect, Schema } from "effect"; | ||
| return "stop"; | ||
| if (reason === "max_tokens") | ||
| if (reason === "max_tokens" || reason === "model_context_window_exceeded") | ||
| return "length"; | ||
@@ -346,2 +346,4 @@ if (reason === "tool_use") | ||
| return "content-filter"; | ||
| if (reason === "malformed_model_output" || reason === "malformed_tool_use") | ||
| return "error"; | ||
| return "unknown"; | ||
@@ -452,3 +454,9 @@ }; | ||
| ...state, | ||
| pendingFinish: { reason: mapFinishReason(event.messageStop.stopReason), usage: state.pendingFinish?.usage }, | ||
| pendingFinish: { | ||
| reason: { | ||
| normalized: mapFinishReason(event.messageStop.stopReason), | ||
| raw: event.messageStop.stopReason, | ||
| }, | ||
| usage: state.pendingFinish?.usage, | ||
| }, | ||
| }, | ||
@@ -460,3 +468,12 @@ [], | ||
| const usage = mapUsage(event.metadata.usage); | ||
| return [{ ...state, pendingFinish: { reason: state.pendingFinish?.reason ?? "stop", usage } }, []]; | ||
| return [ | ||
| { | ||
| ...state, | ||
| pendingFinish: { | ||
| reason: state.pendingFinish?.reason ?? { normalized: "stop" }, | ||
| usage, | ||
| }, | ||
| }, | ||
| [], | ||
| ]; | ||
| } | ||
@@ -487,3 +504,8 @@ const exception = [ | ||
| Lifecycle.finish(state.lifecycle, events, { | ||
| reason: state.pendingFinish.reason === "stop" && state.hasToolCalls ? "tool-calls" : state.pendingFinish.reason, | ||
| reason: { | ||
| ...state.pendingFinish.reason, | ||
| normalized: state.pendingFinish.reason.normalized === "stop" && state.hasToolCalls | ||
| ? "tool-calls" | ||
| : state.pendingFinish.reason.normalized, | ||
| }, | ||
| usage: state.pendingFinish.usage, | ||
@@ -490,0 +512,0 @@ }); |
@@ -323,5 +323,14 @@ import { Effect, Schema } from "effect"; | ||
| finishReason === "PROHIBITED_CONTENT" || | ||
| finishReason === "SPII") | ||
| finishReason === "SPII" || | ||
| finishReason === "MODEL_ARMOR" || | ||
| finishReason === "IMAGE_PROHIBITED_CONTENT" || | ||
| finishReason === "IMAGE_RECITATION" || | ||
| finishReason === "LANGUAGE") | ||
| return "content-filter"; | ||
| if (finishReason === "MALFORMED_FUNCTION_CALL") | ||
| if (finishReason === "MALFORMED_FUNCTION_CALL" || | ||
| finishReason === "UNEXPECTED_TOOL_CALL" || | ||
| finishReason === "NO_IMAGE" || | ||
| finishReason === "TOO_MANY_TOOL_CALLS" || | ||
| finishReason === "MISSING_THOUGHT_SIGNATURE" || | ||
| finishReason === "MALFORMED_RESPONSE") | ||
| return "error"; | ||
@@ -337,3 +346,6 @@ return "unknown"; | ||
| Lifecycle.finish(lifecycle, events, { | ||
| reason: mapFinishReason(state.finishReason, state.hasToolCalls), | ||
| reason: { | ||
| normalized: mapFinishReason(state.finishReason, state.hasToolCalls), | ||
| raw: state.finishReason, | ||
| }, | ||
| usage: state.usage, | ||
@@ -340,0 +352,0 @@ }); |
@@ -5,3 +5,3 @@ import { Schema } from "effect"; | ||
| import { Protocol } from "../route/protocol"; | ||
| import { LLMEvent, Usage, type FinishReason } from "../schema"; | ||
| import { LLMEvent, Usage, type FinishReasonDetails } from "../schema"; | ||
| import { Lifecycle } from "./utils/lifecycle"; | ||
@@ -141,3 +141,3 @@ import { ToolStream } from "./utils/tool-stream"; | ||
| export declare const OpenAIChatEvent: Schema.Struct<{ | ||
| readonly choices: Schema.$Array<Schema.Struct<{ | ||
| readonly choices: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Struct<{ | ||
| readonly delta: Schema.optional<Schema.NullOr<Schema.StructWithRest<Schema.Struct<{ | ||
@@ -159,3 +159,4 @@ readonly content: Schema.optional<Schema.NullOr<Schema.String>>; | ||
| readonly finish_reason: Schema.optional<Schema.NullOr<Schema.String>>; | ||
| }>>; | ||
| readonly native_finish_reason: Schema.optional<Schema.NullOr<Schema.String>>; | ||
| }>>>>; | ||
| readonly usage: Schema.optional<Schema.NullOr<Schema.Struct<{ | ||
@@ -172,2 +173,6 @@ readonly prompt_tokens: Schema.optional<Schema.Number>; | ||
| }>>>; | ||
| readonly error: Schema.optional<Schema.NullOr<Schema.Struct<{ | ||
| readonly code: Schema.optional<Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.Number]>>>; | ||
| readonly message: Schema.String; | ||
| }>>>; | ||
| }>; | ||
@@ -185,3 +190,3 @@ export type OpenAIChatEvent = Schema.Schema.Type<typeof OpenAIChatEvent>; | ||
| readonly usage?: Usage; | ||
| readonly finishReason?: FinishReason; | ||
| readonly finishReason?: FinishReasonDetails; | ||
| readonly lifecycle: Lifecycle.State; | ||
@@ -264,3 +269,18 @@ readonly reasoningField?: string; | ||
| }, string, { | ||
| readonly choices: readonly { | ||
| readonly error?: { | ||
| readonly message: string; | ||
| readonly code?: string | number | null | undefined; | ||
| } | null | undefined; | ||
| readonly usage?: { | ||
| readonly prompt_tokens?: number | undefined; | ||
| readonly completion_tokens?: number | undefined; | ||
| readonly total_tokens?: number | undefined; | ||
| readonly prompt_tokens_details?: { | ||
| readonly cached_tokens?: number | undefined; | ||
| } | null | undefined; | ||
| readonly completion_tokens_details?: { | ||
| readonly reasoning_tokens?: number | undefined; | ||
| } | null | undefined; | ||
| } | null | undefined; | ||
| readonly choices?: readonly { | ||
| readonly delta?: { | ||
@@ -283,14 +303,4 @@ readonly [x: string]: unknown; | ||
| readonly finish_reason?: string | null | undefined; | ||
| }[]; | ||
| readonly usage?: { | ||
| readonly prompt_tokens?: number | undefined; | ||
| readonly completion_tokens?: number | undefined; | ||
| readonly total_tokens?: number | undefined; | ||
| readonly prompt_tokens_details?: { | ||
| readonly cached_tokens?: number | undefined; | ||
| } | null | undefined; | ||
| readonly completion_tokens_details?: { | ||
| readonly reasoning_tokens?: number | undefined; | ||
| } | null | undefined; | ||
| } | null | undefined; | ||
| readonly native_finish_reason?: string | null | undefined; | ||
| }[] | null | undefined; | ||
| }, ParserState>; | ||
@@ -297,0 +307,0 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{ |
@@ -7,3 +7,4 @@ import { Effect, Schema } from "effect"; | ||
| import { Protocol } from "../route/protocol"; | ||
| import { LLMEvent, Usage, } from "../schema"; | ||
| import { LLMError, LLMEvent, Usage, } from "../schema"; | ||
| import { classifyProviderFailure } from "../provider-error"; | ||
| import { isRecord, JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared"; | ||
@@ -128,6 +129,12 @@ import { OpenAIOptions } from "./utils/openai-options"; | ||
| finish_reason: optionalNull(Schema.String), | ||
| native_finish_reason: optionalNull(Schema.String), | ||
| }); | ||
| const OpenAIChatError = Schema.Struct({ | ||
| code: optionalNull(Schema.Union([Schema.String, Schema.Number])), | ||
| message: Schema.String, | ||
| }); | ||
| export const OpenAIChatEvent = Schema.Struct({ | ||
| choices: Schema.Array(OpenAIChatChoice), | ||
| choices: optionalNull(Schema.Array(OpenAIChatChoice)), | ||
| usage: optionalNull(OpenAIChatUsage), | ||
| error: optionalNull(OpenAIChatError), | ||
| }); | ||
@@ -367,2 +374,4 @@ // ============================================================================= | ||
| return "tool-calls"; | ||
| if (reason === "error") | ||
| return "error"; | ||
| return "unknown"; | ||
@@ -450,6 +459,18 @@ }; | ||
| const step = (state, event) => Effect.gen(function* () { | ||
| if (event.error) | ||
| return yield* new LLMError({ | ||
| module: ADAPTER, | ||
| method: "stream", | ||
| reason: classifyProviderFailure({ | ||
| message: event.error.message, | ||
| code: event.error.code === undefined || event.error.code === null ? undefined : String(event.error.code), | ||
| status: typeof event.error.code === "number" ? event.error.code : undefined, | ||
| }), | ||
| }); | ||
| const events = []; | ||
| const usage = mapUsage(event.usage) ?? state.usage; | ||
| const choice = event.choices[0]; | ||
| const finishReason = choice?.finish_reason ? mapFinishReason(choice.finish_reason) : state.finishReason; | ||
| const choice = event.choices?.[0]; | ||
| const finishReason = choice?.finish_reason | ||
| ? { normalized: mapFinishReason(choice.finish_reason), raw: choice.native_finish_reason ?? choice.finish_reason } | ||
| : state.finishReason; | ||
| const delta = choice?.delta; | ||
@@ -527,3 +548,8 @@ const toolDeltas = delta?.tool_calls ?? []; | ||
| const hasToolCalls = state.toolCallEvents.length > 0; | ||
| const reason = state.finishReason === "stop" && hasToolCalls ? "tool-calls" : state.finishReason; | ||
| const reason = state.finishReason | ||
| ? { | ||
| ...state.finishReason, | ||
| normalized: state.finishReason.normalized === "stop" && hasToolCalls ? "tool-calls" : state.finishReason.normalized, | ||
| } | ||
| : undefined; | ||
| const metadata = reasoningMetadata(state.reasoningField, state.reasoningDetailsObserved ? state.reasoningDetails : undefined); | ||
@@ -530,0 +556,0 @@ const started = state.reasoningDetailsObserved && !state.reasoningEmitted |
@@ -792,3 +792,6 @@ import { Effect, Encoding, Schema } from "effect"; | ||
| const lifecycle = Lifecycle.finish(state.lifecycle, events, { | ||
| reason: mapFinishReason(event, state.hasFunctionCall), | ||
| reason: { | ||
| normalized: mapFinishReason(event, state.hasFunctionCall), | ||
| raw: event.response?.incomplete_details?.reason, | ||
| }, | ||
| usage: mapUsage(event.response?.usage), | ||
@@ -795,0 +798,0 @@ providerMetadata: event.response?.id || event.response?.service_tier |
@@ -1,2 +0,2 @@ | ||
| import { LLMEvent, type FinishReason, type ProviderMetadata, type Usage } from "../../schema"; | ||
| import { LLMEvent, type FinishReasonDetails, type ProviderMetadata, type Usage } from "../../schema"; | ||
| export interface State { | ||
@@ -15,3 +15,3 @@ readonly stepStarted: boolean; | ||
| export declare const finish: (state: State, events: LLMEvent[], input: { | ||
| readonly reason: FinishReason; | ||
| readonly reason: FinishReasonDetails; | ||
| readonly usage?: Usage; | ||
@@ -18,0 +18,0 @@ readonly providerMetadata?: ProviderMetadata; |
@@ -222,3 +222,6 @@ import { Effect } from "effect"; | ||
| readonly type: "step-finish"; | ||
| readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly reason: { | ||
| readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly raw?: string | undefined; | ||
| }; | ||
| readonly index: number; | ||
@@ -233,3 +236,6 @@ readonly providerMetadata?: { | ||
| readonly type: "finish"; | ||
| readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly reason: { | ||
| readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly raw?: string | undefined; | ||
| }; | ||
| readonly providerMetadata?: { | ||
@@ -411,3 +417,6 @@ readonly [x: string]: { | ||
| readonly type: "step-finish"; | ||
| readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly reason: { | ||
| readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly raw?: string | undefined; | ||
| }; | ||
| readonly index: number; | ||
@@ -422,3 +431,6 @@ readonly providerMetadata?: { | ||
| readonly type: "finish"; | ||
| readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly reason: { | ||
| readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly raw?: string | undefined; | ||
| }; | ||
| readonly providerMetadata?: { | ||
@@ -597,3 +609,6 @@ readonly [x: string]: { | ||
| readonly type: "step-finish"; | ||
| readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly reason: { | ||
| readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly raw?: string | undefined; | ||
| }; | ||
| readonly index: number; | ||
@@ -608,3 +623,6 @@ readonly providerMetadata?: { | ||
| readonly type: "finish"; | ||
| readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly reason: { | ||
| readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly raw?: string | undefined; | ||
| }; | ||
| readonly providerMetadata?: { | ||
@@ -611,0 +629,0 @@ readonly [x: string]: { |
@@ -156,3 +156,18 @@ import { Schema } from "effect"; | ||
| }, string, { | ||
| readonly choices: readonly { | ||
| readonly error?: { | ||
| readonly message: string; | ||
| readonly code?: string | number | null | undefined; | ||
| } | null | undefined; | ||
| readonly usage?: { | ||
| readonly prompt_tokens?: number | undefined; | ||
| readonly completion_tokens?: number | undefined; | ||
| readonly total_tokens?: number | undefined; | ||
| readonly prompt_tokens_details?: { | ||
| readonly cached_tokens?: number | undefined; | ||
| } | null | undefined; | ||
| readonly completion_tokens_details?: { | ||
| readonly reasoning_tokens?: number | undefined; | ||
| } | null | undefined; | ||
| } | null | undefined; | ||
| readonly choices?: readonly { | ||
| readonly delta?: { | ||
@@ -175,14 +190,4 @@ readonly [x: string]: unknown; | ||
| readonly finish_reason?: string | null | undefined; | ||
| }[]; | ||
| readonly usage?: { | ||
| readonly prompt_tokens?: number | undefined; | ||
| readonly completion_tokens?: number | undefined; | ||
| readonly total_tokens?: number | undefined; | ||
| readonly prompt_tokens_details?: { | ||
| readonly cached_tokens?: number | undefined; | ||
| } | null | undefined; | ||
| readonly completion_tokens_details?: { | ||
| readonly reasoning_tokens?: number | undefined; | ||
| } | null | undefined; | ||
| } | null | undefined; | ||
| readonly native_finish_reason?: string | null | undefined; | ||
| }[] | null | undefined; | ||
| }, OpenAIChat.ParserState>; | ||
@@ -189,0 +194,0 @@ export declare const route: Route<{ |
@@ -298,3 +298,6 @@ import { Context, Effect, Layer, Schema, Stream } from "effect"; | ||
| readonly type: "step-finish"; | ||
| readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly reason: { | ||
| readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly raw?: string | undefined; | ||
| }; | ||
| readonly index: number; | ||
@@ -309,3 +312,6 @@ readonly providerMetadata?: { | ||
| readonly type: "finish"; | ||
| readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly reason: { | ||
| readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown"; | ||
| readonly raw?: string | undefined; | ||
| }; | ||
| readonly providerMetadata?: { | ||
@@ -312,0 +318,0 @@ readonly [x: string]: { |
@@ -161,6 +161,10 @@ import { Schema } from "effect"; | ||
| }).annotate({ identifier: "LLM.Event.ToolError" }); | ||
| export const FinishReasonDetails = Schema.Struct({ | ||
| normalized: FinishReason, | ||
| raw: Schema.optional(Schema.String), | ||
| }).annotate({ identifier: "LLM.FinishReasonDetails" }); | ||
| export const StepFinish = Schema.Struct({ | ||
| type: Schema.tag("step-finish"), | ||
| index: Schema.Number, | ||
| reason: FinishReason, | ||
| reason: FinishReasonDetails, | ||
| usage: Schema.optional(Usage), | ||
@@ -171,3 +175,3 @@ providerMetadata: Schema.optional(ProviderMetadata), | ||
| type: Schema.tag("finish"), | ||
| reason: FinishReason, | ||
| reason: FinishReasonDetails, | ||
| usage: Schema.optional(Usage), | ||
@@ -295,3 +299,3 @@ providerMetadata: Schema.optional(ProviderMetadata), | ||
| events, | ||
| finishReason: state.finishReason ?? "error", | ||
| finishReason: state.finishReason ?? { normalized: "error" }, | ||
| }; | ||
@@ -462,3 +466,3 @@ } | ||
| usage: Schema.optional(Usage), | ||
| finishReason: FinishReason, | ||
| finishReason: FinishReasonDetails, | ||
| }) { | ||
@@ -465,0 +469,0 @@ /** Concatenated assistant text assembled from streamed `text-delta` events. */ |
+3
-3
| { | ||
| "$schema": "https://json.schemastore.org/package.json", | ||
| "version": "0.0.0-next-16093", | ||
| "version": "0.0.0-next-16094", | ||
| "name": "@opencode-ai/ai", | ||
@@ -29,3 +29,3 @@ "type": "module", | ||
| "@effect/platform-node": "4.0.0-beta.98", | ||
| "@opencode-ai/http-recorder": "0.0.0-next-16093", | ||
| "@opencode-ai/http-recorder": "0.0.0-next-16094", | ||
| "@tsconfig/bun": "1.0.9", | ||
@@ -39,3 +39,3 @@ "@types/bun": "1.3.13", | ||
| "@smithy/util-utf8": "4.2.2", | ||
| "@opencode-ai/schema": "0.0.0-next-16093", | ||
| "@opencode-ai/schema": "0.0.0-next-16094", | ||
| "aws4fetch": "1.0.20", | ||
@@ -42,0 +42,0 @@ "effect": "4.0.0-beta.98", |
Sorry, the diff of this file is too big to display
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.
1047089
0.98%22048
1.23%+ Added
- Removed