@opencode-ai/ai
Advanced tools
@@ -60,2 +60,5 @@ import { Effect, Schema, Stream } from "effect"; | ||
| } | ||
| // Keepalives carry no response state and may arrive before response.created. | ||
| if (event.type === "keepalive") | ||
| return { type: "frame", frame }; | ||
| if (!responseID) | ||
@@ -62,0 +65,0 @@ return yield* ProviderShared.eventError(options.id, `${options.name} emitted ${event.type} before response.created`, frame); |
@@ -419,4 +419,8 @@ import { Effect, Schema } from "effect"; | ||
| input.push({ type: "item_reference", id }); | ||
| if (store === false && part.result.type === "content") { | ||
| const content = part.result.value; | ||
| if (store === false) { | ||
| // The server is not storing this exchange, so the tool outcome has to | ||
| // travel in the input. Non-content results degrade to their text form. | ||
| const content = part.result.type === "content" | ||
| ? part.result.value | ||
| : [{ type: "text", text: ProviderShared.toolResultText(part) }]; | ||
| input.push({ | ||
@@ -460,2 +464,3 @@ role: "user", | ||
| const options = OpenResponsesOptions.resolve(request); | ||
| const cacheKey = ProviderShared.clampPromptCacheKey(request.promptCacheKey); | ||
| return { | ||
@@ -470,3 +475,3 @@ ...(options.instructions ? { instructions: options.instructions } : {}), | ||
| ...(options.topLogprobs !== undefined ? { top_logprobs: options.topLogprobs } : {}), | ||
| ...(request.promptCacheKey ? { prompt_cache_key: request.promptCacheKey } : {}), | ||
| ...(cacheKey ? { prompt_cache_key: cacheKey } : {}), | ||
| ...(options.include ? { include: options.include } : {}), | ||
@@ -473,0 +478,0 @@ ...(options.reasoningEffort || options.reasoningSummary |
@@ -418,5 +418,6 @@ import { Effect, Schema } from "effect"; | ||
| const options = OpenAIOptions.resolve(request); | ||
| const cacheKey = ProviderShared.clampPromptCacheKey(request.promptCacheKey); | ||
| return { | ||
| ...(options.store !== undefined ? { store: options.store } : {}), | ||
| ...(request.promptCacheKey ? { prompt_cache_key: request.promptCacheKey } : {}), | ||
| ...(cacheKey ? { prompt_cache_key: cacheKey } : {}), | ||
| ...(options.reasoningEffort ? { reasoning_effort: options.reasoningEffort } : {}), | ||
@@ -423,0 +424,0 @@ }; |
@@ -13,2 +13,4 @@ import { Tool } from "@opencode-ai/schema/tool"; | ||
| export declare const optionalNull: <const S extends Schema.Top>(schema: S) => Schema.optional<Schema.NullOr<S>>; | ||
| export declare const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64; | ||
| export declare const clampPromptCacheKey: (key: string | undefined) => string | undefined; | ||
| /** | ||
@@ -15,0 +17,0 @@ * Streaming tool-call accumulator. Adapters that build a tool call across |
@@ -16,2 +16,13 @@ import { Buffer } from "node:buffer"; | ||
| export const optionalNull = (schema) => Schema.optional(Schema.NullOr(schema)); | ||
| export const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64; | ||
| // OpenAI limits `prompt_cache_key` to 64 chars; DeepSeek and Zai inherit the same | ||
| // limit via their OpenAI-compatible APIs. Clamp with unicode-aware slicing. | ||
| export const clampPromptCacheKey = (key) => { | ||
| if (key === undefined) | ||
| return undefined; | ||
| const chars = Array.from(key); | ||
| if (chars.length <= OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH) | ||
| return key; | ||
| return chars.slice(0, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH).join(""); | ||
| }; | ||
| /** | ||
@@ -18,0 +29,0 @@ * `Usage.totalTokens` policy shared by every route. Honors a provider- |
@@ -11,3 +11,3 @@ import { Effect, Schema } from "effect"; | ||
| import { newBreakpoints, ttlBucket } from "../protocols/utils/cache.js"; | ||
| import { isRecord } from "../protocols/shared.js"; | ||
| import { isRecord, ProviderShared } from "../protocols/shared.js"; | ||
| export const profile = OpenAICompatibleProfiles.profiles.openrouter; | ||
@@ -43,2 +43,3 @@ export const id = ProviderID.make(profile.provider); | ||
| }); | ||
| const cacheKey = ProviderShared.clampPromptCacheKey(request.promptCacheKey); | ||
| return { | ||
@@ -48,3 +49,3 @@ ...body, | ||
| ...bodyOptions(request.providerOptions), | ||
| ...(request.promptCacheKey ? { prompt_cache_key: request.promptCacheKey } : {}), | ||
| ...(cacheKey ? { prompt_cache_key: cacheKey } : {}), | ||
| }; | ||
@@ -51,0 +52,0 @@ })), |
+3
-3
| { | ||
| "$schema": "https://json.schemastore.org/package.json", | ||
| "version": "0.0.0-dev-18035", | ||
| "version": "0.0.0-dev-18039", | ||
| "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-18035", | ||
| "@opencode-ai/http-recorder": "0.0.0-dev-18039", | ||
| "@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-18035", | ||
| "@opencode-ai/schema": "0.0.0-dev-18039", | ||
| "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.
1200765
0.11%27577
0.08%+ Added
- Removed