Compare commits

..
129 changed files with 2763 additions and 1778 deletions
+3 -3
View File
@@ -42,7 +42,7 @@ jobs:
- name: Find affected packages
id: packages
env:
TURBO_SCM_BASE: ${{ github.event_name == 'pull_request' && format('{0}^1', github.sha) || github.event.before }}
TURBO_SCM_BASE: ${{ github.event.pull_request.base.sha || github.event.before }}
TURBO_SCM_HEAD: ${{ github.sha }}
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
@@ -119,7 +119,7 @@ jobs:
GITHUB_ACTIONS=false bun turbo test --affected
env:
OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER: ${{ runner.os == 'Windows' && 'true' || 'false' }}
TURBO_SCM_BASE: ${{ github.event_name == 'pull_request' && format('{0}^1', github.sha) || github.event.before }}
TURBO_SCM_BASE: ${{ github.event.pull_request.base.sha || github.event.before }}
TURBO_SCM_HEAD: ${{ github.sha }}
- name: Verify published codemode package
@@ -137,7 +137,7 @@ jobs:
fi
bun turbo verify:package --affected --filter=@opencode-ai/sdk
env:
TURBO_SCM_BASE: ${{ github.event_name == 'pull_request' && format('{0}^1', github.sha) || github.event.before }}
TURBO_SCM_BASE: ${{ github.event.pull_request.base.sha || github.event.before }}
TURBO_SCM_HEAD: ${{ github.sha }}
- name: Verify compiled service lifecycle
+9
View File
@@ -347,6 +347,7 @@
"@ai-sdk/anthropic": "3.0.82",
"@ai-sdk/azure": "3.0.88",
"@ai-sdk/cohere": "3.0.27",
"@ai-sdk/deepinfra": "2.0.41",
"@ai-sdk/gateway": "3.0.104",
"@ai-sdk/google-vertex": "4.0.128",
"@ai-sdk/groq": "3.0.31",
@@ -985,6 +986,7 @@
"mime-types": "3.0.2",
"minimatch": "10.2.5",
"npm-package-arg": "13.0.2",
"pacote": "21.5.1",
"resolve.exports": "catalog:",
},
"devDependencies": {
@@ -994,6 +996,7 @@
"@types/node": "catalog:",
"@types/npm-package-arg": "6.1.4",
"@types/npmcli__arborist": "6.3.3",
"@types/pacote": "11.1.8",
"@typescript/native-preview": "catalog:",
},
},
@@ -1177,6 +1180,8 @@
"@ai-sdk/deepgram": ["@ai-sdk/deepgram@2.0.52", "", { "dependencies": { "@ai-sdk/provider": "3.0.15", "@ai-sdk/provider-utils": "4.0.46" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-8pcrQvEQCbvrrQKnD6hclBbI0hUgSrgyADykRbabxv/g9vPurfMC6n23J7dD+KZ3EcCoW+qz3IUIfySJ58gBOg=="],
"@ai-sdk/deepinfra": ["@ai-sdk/deepinfra@2.0.41", "", { "dependencies": { "@ai-sdk/openai-compatible": "2.0.37", "@ai-sdk/provider": "3.0.8", "@ai-sdk/provider-utils": "4.0.21" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-y6RoOP7DGWmDSiSxrUSt5p18sbz+Ixe5lMVPmdE7x+Tr5rlrzvftyHhjWHfqlAtoYERZTGFbP6tPW1OfQcrb4A=="],
"@ai-sdk/deepseek": ["@ai-sdk/deepseek@2.0.47", "", { "dependencies": { "@ai-sdk/provider": "3.0.14", "@ai-sdk/provider-utils": "4.0.38" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-MzcQ321JO8OY+TVLFI81A7cIIuoeLLxrLCDD+8C1E3Ro6UFyfMtRXo9bw9OhTMRSDMo6hgSDOo4Fekz8aJtQYQ=="],
"@ai-sdk/elevenlabs": ["@ai-sdk/elevenlabs@2.0.52", "", { "dependencies": { "@ai-sdk/provider": "3.0.15", "@ai-sdk/provider-utils": "4.0.46" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-ZgkausouWvO9U4ZtowNJ093bSNYOvH8zqls3uLC3+oxzWvbbTZO8SOdmFk0+gGafsXFJvq2yUX9+rEeJPwOJLw=="],
@@ -5907,6 +5912,10 @@
"@ai-sdk/deepgram/@ai-sdk/provider-utils": ["@ai-sdk/provider-utils@4.0.46", "", { "dependencies": { "@ai-sdk/provider": "3.0.15", "@standard-schema/spec": "^1.1.0", "eventsource-parser": "^3.0.8", "undici": "^6.28.0" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-tEtld97plCFiYevsJuOkGkeuhQndeMWFBVrJS4AjnbD5AqrNSXRCe0p+BZ3Cju/sxDeeZ9ym3q9YUV8fASA7aQ=="],
"@ai-sdk/deepinfra/@ai-sdk/openai-compatible": ["@ai-sdk/openai-compatible@2.0.37", "", { "dependencies": { "@ai-sdk/provider": "3.0.8", "@ai-sdk/provider-utils": "4.0.21" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-+POSFVcgiu47BK64dhsI6OpcDC0/VAE2ZSaXdXGNNhpC/ava++uSRJYks0k2bpfY0wwCTgpAWZsXn/dG2Yppiw=="],
"@ai-sdk/deepinfra/@ai-sdk/provider-utils": ["@ai-sdk/provider-utils@4.0.21", "", { "dependencies": { "@ai-sdk/provider": "3.0.8", "@standard-schema/spec": "^1.1.0", "eventsource-parser": "^3.0.6" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-MtFUYI1/8mgDvRmaBDjbLJPFFrMG777AvSgyIFQtZHIMzm88R/12vYBBpnk7pfiWLFE1DSZzY4WDYzGbKAcmiw=="],
"@ai-sdk/deepseek/@ai-sdk/provider": ["@ai-sdk/provider@3.0.14", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-5X1k57JBJ4H7H1QjX7CnJYAB1I19r/trVZTMcSms7/kLNZ8RaU4Nt2agcwZzv82Hfx6Q7/TOLU7agAKeFfc8cA=="],
"@ai-sdk/deepseek/@ai-sdk/provider-utils": ["@ai-sdk/provider-utils@4.0.38", "", { "dependencies": { "@ai-sdk/provider": "3.0.14", "@standard-schema/spec": "^1.1.0", "eventsource-parser": "^3.0.8" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-/HHGmtKllqjg1OLc023v9w9kK3laW7Z6TzfZukYQWCsGBbzB9p60zTvvpXFVcs44NZBVXL3viOa1HRKUbeee8g=="],
+4 -4
View File
@@ -1,8 +1,8 @@
{
"nodeModules": {
"x86_64-linux": "sha256-t7k0Nk9Z7FMkAKt2UReI1jD1KoPB+LhQQx1x1p5Htlc=",
"aarch64-linux": "sha256-tU7C2zYKiX+RpwBBBLjX7vrqQNLPvDc5Uz9EbgGJvSA=",
"aarch64-darwin": "sha256-A3o+2zNuFHV5FZx/azdXBjcKdS5o41b2e2Q1Qq8C1m0=",
"x86_64-darwin": "sha256-NXgvteaxJQqBBZIHnQbivghHTJnL2IMZiFPNssGp2Os="
"x86_64-linux": "sha256-fOM/kGJJ1cipCHQIxioDZEB7NZykpSiqgwm7gIS6THI=",
"aarch64-linux": "sha256-XTY2C33HjsBMWO7VIiWc2MynjJrxbTLrOJ+6pM+afI0=",
"aarch64-darwin": "sha256-wX6+bC18djtPZ7A9ch+wryM7tDFfrAlT0xx0QTk6EJQ=",
"x86_64-darwin": "sha256-dcRRX4bYq5AmG4GcVmYq/M+06dlf4KJHn+clT2JY48g="
}
}
+41 -17
View File
@@ -196,7 +196,7 @@ type LoweredInputItem =
// multiple streamed summary parts into the same item before flushing.
type OpenResponsesReasoningInput = {
type: "reasoning"
id?: string
id: string
summary: Array<{ type: "summary_text"; text: string }>
encrypted_content?: string | null
}
@@ -372,6 +372,9 @@ export const Event = Schema.StructWithRest(
)
export type Event = Schema.Schema.Type<typeof Event>
// Which lowered input item a persisted item id is about to be attached to.
export type ItemKind = "message" | "reasoning" | "function-call" | "hosted-tool"
export interface Extension {
readonly id: string
readonly name: string
@@ -381,6 +384,10 @@ export interface Extension {
readonly request: LLMRequest
}) => MediaInput | undefined
readonly lowerHostedToolItem?: (item: unknown) => ExtendedHostedToolItem | undefined
// Optional grammar check applied before a persisted item id is resent as
// part of replayed history. Returning false drops the id; every lowered
// item treats a dropped id the same as an absent one.
readonly acceptsItemID?: (kind: ItemKind, id: string) => boolean
}
const BASE: Extension = { id: ADAPTER, name: NAME }
@@ -440,37 +447,53 @@ export const lowerToolChoice = (protocolName: string, toolChoice: NonNullable<LL
tool: (toolName) => ({ type: "function" as const, name: toolName }),
})
// Server-issued item ids need a nonempty prefix and suffix, but the prefix is
// provider-defined and does not necessarily identify the item's semantic type.
// Servers validate item ids on replayed history, and a malformed or oversized
// id can fail an otherwise valid request. Only server-issued tokens are worth
// resending; anything else is treated as absent so the item is resent without
// an id (or skipped, for items that cannot be expressed without one).
const ITEM_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/
const itemID = (providerMetadata: ProviderMetadata | undefined, providerMetadataKey: string) => {
const metadata = providerMetadata?.[providerMetadataKey]
if (!ProviderShared.isRecord(metadata) || typeof metadata.itemId !== "string") return undefined
const separator = metadata.itemId.indexOf("_")
return separator > 0 && separator < metadata.itemId.length - 1 ? metadata.itemId : undefined
return ProviderShared.isRecord(metadata) &&
typeof metadata.itemId === "string" &&
ITEM_ID_PATTERN.test(metadata.itemId)
? metadata.itemId
: undefined
}
const lowerToolCall = (part: ToolCallPart, providerMetadataKey: string): OpenResponsesInputItem => {
const acceptsItemID = (extension: Extension, kind: ItemKind, id: string | undefined): id is string =>
id !== undefined && (extension.acceptsItemID?.(kind, id) ?? true)
const lowerToolCall = (
part: ToolCallPart,
providerMetadataKey: string,
extension: Extension,
): OpenResponsesInputItem => {
const id = itemID(part.providerMetadata, providerMetadataKey)
return {
type: "function_call",
...(id === undefined ? {} : { id }),
...(acceptsItemID(extension, "function-call", id) ? { id } : {}),
call_id: part.id,
name: part.name,
arguments: ProviderShared.encodeJson(part.input),
}
}
const lowerReasoning = (part: ReasoningPart, providerMetadataKey: string): OpenResponsesReasoningInput | undefined => {
const lowerReasoning = (
part: ReasoningPart,
providerMetadataKey: string,
extension: Extension,
): OpenResponsesReasoningInput | undefined => {
const metadata = part.providerMetadata?.[providerMetadataKey]
if (!ProviderShared.isRecord(metadata)) return undefined
const id = itemID(part.providerMetadata, providerMetadataKey)
if (!ProviderShared.isRecord(metadata) || !acceptsItemID(extension, "reasoning", id)) return undefined
const encryptedContent =
typeof metadata.reasoningEncryptedContent === "string" || metadata.reasoningEncryptedContent === null
? metadata.reasoningEncryptedContent
: undefined
return {
type: "reasoning",
...(id === undefined ? {} : { id }),
id,
summary: part.text.length > 0 ? [{ type: "summary_text", text: part.text }] : [],
encrypted_content: encryptedContent,
}
@@ -591,7 +614,8 @@ const lowerMessages = Effect.fn("OpenResponses.lowerMessages")(function* (reques
Array<{ id: string | undefined; phase: MessagePhase | null | undefined; parts: TextPart[] }>
>((groups, part) => {
const metadata = part.providerMetadata?.[providerMetadataKey]
const id = itemID(part.providerMetadata, providerMetadataKey)
const rawID = itemID(part.providerMetadata, providerMetadataKey)
const id = acceptsItemID(extension, "message", rawID) ? rawID : undefined
const phase = ProviderShared.isRecord(metadata) ? messagePhase(metadata.phase) : undefined
const group = groups.at(-1)
if (group && group.id === id && group.phase === phase) group.parts.push(part)
@@ -616,23 +640,23 @@ const lowerMessages = Effect.fn("OpenResponses.lowerMessages")(function* (reques
}
if (part.type === "reasoning") {
flushText()
const reasoning = lowerReasoning(part, providerMetadataKey)
const reasoning = lowerReasoning(part, providerMetadataKey, extension)
if (!reasoning) continue
const existing = reasoning.id === undefined ? undefined : reasoningItems[reasoning.id]
const existing = reasoningItems[reasoning.id]
if (existing) {
existing.summary.push(...reasoning.summary)
if (typeof reasoning.encrypted_content === "string")
existing.encrypted_content = reasoning.encrypted_content
continue
}
if (reasoning.id !== undefined) reasoningItems[reasoning.id] = reasoning
reasoningItems[reasoning.id] = reasoning
input.push(reasoning)
continue
}
if (part.type === "tool-call") {
flushText()
if (part.providerExecuted === true) continue
input.push(lowerToolCall(part, providerMetadataKey))
input.push(lowerToolCall(part, providerMetadataKey, extension))
continue
}
if (part.type === "tool-result" && part.providerExecuted === true) {
@@ -644,7 +668,7 @@ const lowerMessages = Effect.fn("OpenResponses.lowerMessages")(function* (reques
: Schema.is(HostedToolItem)(part.result.value)
? part.result.value
: extension.lowerHostedToolItem?.(part.result.value)
if (id !== undefined && hosted?.id === id) {
if (acceptsItemID(extension, "hosted-tool", id) && hosted?.id === id) {
if (!hostedToolItems.has(id)) {
input.push(hosted)
hostedToolItems.add(id)
@@ -86,10 +86,28 @@ const OpenAIResponsesBody = Schema.Struct({
})
export type OpenAIResponsesBody = Schema.Schema.Type<typeof OpenAIResponsesBody>
// Replayed items are paired with stored server state by id, so a foreign or
// synthetic token can fail request validation even when `call_id` pairing is
// intact. Only resend ids in each item kind's own grammar; hosted tool
// items keep generic validation because every hosted tool mints its own
// prefix. The same allowlist approach codex uses before resending history
// (codex-rs core/src/client.rs, `prepare_response_items_for_request`).
const ITEM_ID_PREFIXES: Record<OpenResponses.ItemKind, ReadonlyArray<string>> = {
message: ["msg_"],
reasoning: ["rs_"],
"function-call": ["fc_"],
// Every hosted tool mints its own id prefix, so items keep generic validation.
"hosted-tool": [],
}
const extension = {
id: ADAPTER,
name: NAME,
lowerHostedToolItem: (item: unknown) => (Schema.is(OpenAIResponsesHostedToolItem)(item) ? item : undefined),
acceptsItemID: (kind: OpenResponses.ItemKind, id: string) => {
const prefixes = ITEM_ID_PREFIXES[kind]
return prefixes.length === 0 || prefixes.some((prefix) => id.startsWith(prefix))
},
} satisfies OpenResponses.Extension
const nativeImageToolInput = (tool: ToolDefinition) => {
+2 -4
View File
@@ -40,16 +40,15 @@ const patterns = [
/model_context_window_exceeded/i,
/too many tokens/i,
/token limit exceeded/i,
/request_too_large/i,
]
const payloadPatterns = [/request entity too large/i, /payload too large/i, /request too large/i]
const payloadPatterns = [/request_too_large/i, /request entity too large/i, /payload too large/i, /request too large/i]
const exclusions = [/^(throttling error|service unavailable):/i, /rate limit/i, /too many requests/i]
export const isContextOverflow = (message: string) =>
!exclusions.some((pattern) => pattern.test(message)) &&
(patterns.some((pattern) => pattern.test(message)) || /^4(?:00|13)\s*(status code)?\s*\(no body\)/i.test(message))
(patterns.some((pattern) => pattern.test(message)) || /^400\s*(status code)?\s*\(no body\)/i.test(message))
export const isPayloadTooLarge = (message: string) => payloadPatterns.some((pattern) => pattern.test(message))
@@ -107,7 +106,6 @@ export function classifyProviderFailure(input: ProviderFailure): AIError["reason
clientScoped &&
(codes.includes("context_length_exceeded") ||
codes.includes("model_context_window_exceeded") ||
codes.includes("request_too_large") ||
isContextOverflow(text))
)
return new InvalidRequestReason({ ...common, classification: "context-overflow" })
-61
View File
@@ -1,61 +0,0 @@
import type { ProviderPackage } from "../provider-package.js"
import { OpenAICompatibleChat } from "../protocols/openai-compatible-chat.js"
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options.js"
import type { RouteDefaultsInput } from "../route/client.js"
import { ProviderID, type ModelID } from "../schema/index.js"
import { profiles } from "./openai-compatible-profile.js"
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
export const id = ProviderID.make("deepinfra")
export type LanguageModelOptions = Omit<RouteDefaultsInput, "providerOptions"> &
ProviderAuthOption<"optional"> & {
readonly baseURL?: string
readonly providerOptions?: OpenAIProviderOptionsInput
}
export interface Settings extends ProviderPackage.Settings {
readonly apiKey?: string
readonly baseURL?: string
readonly providerOptions?: OpenAIProviderOptionsInput
}
export const route = OpenAICompatibleChat.route.with({
id: "deepinfra-chat",
provider: id,
endpoint: { baseURL: profiles.deepinfra.baseURL },
})
export const routes = [route]
export const configure = (input: LanguageModelOptions = {}) => {
const { apiKey: _apiKey, auth: _auth, baseURL, ...defaults } = input
const root = baseURL?.replace(/\/+$/, "")
const configured = route.with({
...defaults,
endpoint: {
baseURL: root === undefined ? profiles.deepinfra.baseURL : root.endsWith("/openai") ? root : `${root}/openai`,
},
auth: AuthOptions.bearer(input, "DEEPINFRA_API_KEY"),
})
return {
id,
model: (modelID: string | ModelID) =>
configured.model<OpenAIProviderOptionsInput>({
id: modelID,
compatibility: { maxTokensField: "max_tokens", reasoningField: "reasoning_content", supportsStore: false },
}),
configure,
}
}
export const provider = configure()
export const model: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"] = (modelID, settings) =>
configure({
apiKey: settings.apiKey,
baseURL: settings.baseURL,
headers: settings.headers === undefined ? undefined : { ...settings.headers },
http: settings.body === undefined ? undefined : { body: { ...settings.body } },
providerOptions: settings.providerOptions,
}).model(modelID)
-1
View File
@@ -6,7 +6,6 @@ export * as Azure from "./azure.js"
export * as Cerebras from "./cerebras.js"
export * as Cloudflare from "./cloudflare.js"
export { CloudflareAIGateway, CloudflareWorkersAI } from "./cloudflare.js"
export * as DeepInfra from "./deepinfra.js"
export * as Google from "./google.js"
export * as GoogleVertex from "./google-vertex.js"
export * as GoogleVertexChat from "./google-vertex-chat.js"
-22
View File
@@ -211,28 +211,6 @@ describe("RequestExecutor", () => {
}).pipe(Effect.provide(responsesLayer([new Response("request too large", { status: 413 })]))),
)
it.effect("classifies Anthropic request_too_large as context overflow", () =>
Effect.gen(function* () {
const executor = yield* RequestExecutor.Service
const error = yield* executor.execute(request).pipe(Effect.flip)
expectAIError(error)
expect(error.reason).toMatchObject({
_tag: "InvalidRequest",
classification: "context-overflow",
http: { response: { status: 413 } },
})
}).pipe(
Effect.provide(
responsesLayer([
new Response('{"error":{"type":"request_too_large","message":"Request exceeds the maximum size"}}', {
status: 413,
}),
]),
),
),
)
it.effect("does not classify ordinary invalid requests as context overflow", () =>
Effect.gen(function* () {
const executor = yield* RequestExecutor.Service
@@ -1,32 +0,0 @@
{
"version": 1,
"metadata": {
"provider": "deepinfra",
"route": "deepinfra-chat",
"transport": "http",
"model": "meta-llama/Llama-3.3-70B-Instruct-Turbo",
"tags": ["prefix:deepinfra-chat", "provider:deepinfra", "text", "golden"],
"name": "deepinfra-chat/deepinfra-llama-3-3-70b-text",
"recordedAt": "2026-08-26T00:34:03.019Z"
},
"interactions": [
{
"transport": "http",
"request": {
"method": "POST",
"url": "https://api.deepinfra.com/v1/openai/chat/completions",
"headers": {
"content-type": "application/json"
},
"body": "{\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"messages\":[{\"role\":\"system\",\"content\":\"You are concise.\"},{\"role\":\"user\",\"content\":\"Reply exactly with: Hello!\"}],\"stream\":true,\"stream_options\":{\"include_usage\":true},\"max_tokens\":40,\"temperature\":0}"
},
"response": {
"status": 200,
"headers": {
"content-type": "text/event-stream; charset=utf-8"
},
"body": "data: {\"service_tier\":null,\"id\":\"chatcmpl-RbZ8MyY5pos2MShihSmoXoRe\",\"object\":\"chat.completion.chunk\",\"created\":1787704442,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"\",\"reasoning_content\":null,\"tool_calls\":null},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null}\n\ndata: {\"service_tier\":\"default\",\"id\":\"chatcmpl-RbZ8MyY5pos2MShihSmoXoRe\",\"object\":\"chat.completion.chunk\",\"created\":1787704442,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"Hello\",\"reasoning_content\":null,\"tool_calls\":null},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null}\n\ndata: {\"service_tier\":\"default\",\"id\":\"chatcmpl-RbZ8MyY5pos2MShihSmoXoRe\",\"object\":\"chat.completion.chunk\",\"created\":1787704442,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"!\",\"reasoning_content\":null,\"tool_calls\":null},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null}\n\ndata: {\"service_tier\":\"default\",\"id\":\"chatcmpl-RbZ8MyY5pos2MShihSmoXoRe\",\"object\":\"chat.completion.chunk\",\"created\":1787704442,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"\",\"reasoning_content\":null,\"tool_calls\":null},\"logprobs\":null,\"finish_reason\":\"stop\"}],\"usage\":{\"prompt_tokens\":25,\"total_tokens\":28,\"completion_tokens\":3,\"estimated_cost\":null,\"prompt_tokens_details\":null}}\n\ndata: {\"service_tier\":\"default\",\"id\":\"chatcmpl-RbZ8MyY5pos2MShihSmoXoRe\",\"object\":\"chat.completion.chunk\",\"created\":1787704442,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[],\"usage\":{\"prompt_tokens\":25,\"total_tokens\":28,\"completion_tokens\":3,\"estimated_cost\":3.46e-6,\"prompt_tokens_details\":null}}\n\ndata: [DONE]\n\n"
}
}
]
}
@@ -1,32 +0,0 @@
{
"version": 1,
"metadata": {
"provider": "deepinfra",
"route": "deepinfra-chat",
"transport": "http",
"model": "meta-llama/Llama-3.3-70B-Instruct-Turbo",
"tags": ["prefix:deepinfra-chat", "provider:deepinfra", "tool", "tool-call", "golden"],
"name": "deepinfra-chat/deepinfra-llama-3-3-70b-tool-call",
"recordedAt": "2026-08-26T00:34:04.173Z"
},
"interactions": [
{
"transport": "http",
"request": {
"method": "POST",
"url": "https://api.deepinfra.com/v1/openai/chat/completions",
"headers": {
"content-type": "application/json"
},
"body": "{\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"messages\":[{\"role\":\"system\",\"content\":\"Call tools exactly as requested.\"},{\"role\":\"user\",\"content\":\"Call get_weather with city exactly Paris.\"}],\"tools\":[{\"type\":\"function\",\"function\":{\"name\":\"get_weather\",\"description\":\"Get current weather for a city.\",\"parameters\":{\"type\":\"object\",\"properties\":{\"city\":{\"type\":\"string\"}},\"required\":[\"city\"],\"additionalProperties\":false},\"strict\":false}}],\"tool_choice\":{\"type\":\"function\",\"function\":{\"name\":\"get_weather\"}},\"stream\":true,\"stream_options\":{\"include_usage\":true},\"max_tokens\":80,\"temperature\":0}"
},
"response": {
"status": 200,
"headers": {
"content-type": "text/event-stream; charset=utf-8"
},
"body": "data: {\"service_tier\":null,\"id\":\"chatcmpl-RFOwhlB2PhZrgMLviGrx5BQf\",\"object\":\"chat.completion.chunk\",\"created\":1787704443,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"\",\"reasoning_content\":null,\"tool_calls\":null},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null}\n\ndata: {\"service_tier\":\"default\",\"id\":\"chatcmpl-RFOwhlB2PhZrgMLviGrx5BQf\",\"object\":\"chat.completion.chunk\",\"created\":1787704443,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"\",\"reasoning_content\":null,\"tool_calls\":[{\"index\":0,\"id\":\"call_SMfBjXa8eCmHLyjfeyARxe3a\",\"function\":{\"arguments\":\"{\\\"city\\\": \\\"Paris\\\"}\",\"name\":\"get_weather\"},\"type\":\"function\"}]},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null}\n\ndata: {\"service_tier\":\"default\",\"id\":\"chatcmpl-RFOwhlB2PhZrgMLviGrx5BQf\",\"object\":\"chat.completion.chunk\",\"created\":1787704443,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"\",\"reasoning_content\":null,\"tool_calls\":null},\"logprobs\":null,\"finish_reason\":\"stop\"}],\"usage\":{\"prompt_tokens\":230,\"total_tokens\":244,\"completion_tokens\":14,\"estimated_cost\":null,\"prompt_tokens_details\":null}}\n\ndata: {\"service_tier\":\"default\",\"id\":\"chatcmpl-RFOwhlB2PhZrgMLviGrx5BQf\",\"object\":\"chat.completion.chunk\",\"created\":1787704443,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[],\"usage\":{\"prompt_tokens\":230,\"total_tokens\":244,\"completion_tokens\":14,\"estimated_cost\":0.000027480000000000005,\"prompt_tokens_details\":null}}\n\ndata: [DONE]\n\n"
}
}
]
}
@@ -1,50 +0,0 @@
{
"version": 1,
"metadata": {
"provider": "deepinfra",
"route": "deepinfra-chat",
"transport": "http",
"model": "meta-llama/Llama-3.3-70B-Instruct-Turbo",
"tags": ["prefix:deepinfra-chat", "provider:deepinfra", "tool", "tool-loop", "golden"],
"name": "deepinfra-chat/deepinfra-llama-3-3-70b-tool-loop",
"recordedAt": "2026-08-26T00:34:05.656Z"
},
"interactions": [
{
"transport": "http",
"request": {
"method": "POST",
"url": "https://api.deepinfra.com/v1/openai/chat/completions",
"headers": {
"content-type": "application/json"
},
"body": "{\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"messages\":[{\"role\":\"system\",\"content\":\"Use the get_weather tool exactly once. After the tool result, reply exactly: Paris is sunny.\"},{\"role\":\"user\",\"content\":\"What is the weather in Paris?\"}],\"tools\":[{\"type\":\"function\",\"function\":{\"name\":\"get_weather\",\"description\":\"Get current weather for a city.\",\"parameters\":{\"type\":\"object\",\"properties\":{\"city\":{\"type\":\"string\"}},\"required\":[\"city\"],\"additionalProperties\":false},\"strict\":false}}],\"stream\":true,\"stream_options\":{\"include_usage\":true},\"max_tokens\":80,\"temperature\":0}"
},
"response": {
"status": 200,
"headers": {
"content-type": "text/event-stream; charset=utf-8"
},
"body": "data: {\"service_tier\":null,\"id\":\"chatcmpl-RxlHFSnlLbUUz6XSxqBQj7TC\",\"object\":\"chat.completion.chunk\",\"created\":1787704444,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"\",\"reasoning_content\":null,\"tool_calls\":null},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null}\n\ndata: {\"service_tier\":\"default\",\"id\":\"chatcmpl-RxlHFSnlLbUUz6XSxqBQj7TC\",\"object\":\"chat.completion.chunk\",\"created\":1787704444,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"\",\"reasoning_content\":null,\"tool_calls\":[{\"index\":0,\"id\":\"call_W3stxe7FNHozlB4tDxlTVZou\",\"function\":{\"arguments\":\"{\\\"city\\\": \\\"Paris\\\"}\",\"name\":\"get_weather\"},\"type\":\"function\"}]},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null}\n\ndata: {\"service_tier\":\"default\",\"id\":\"chatcmpl-RxlHFSnlLbUUz6XSxqBQj7TC\",\"object\":\"chat.completion.chunk\",\"created\":1787704444,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"\",\"reasoning_content\":null,\"tool_calls\":null},\"logprobs\":null,\"finish_reason\":\"stop\"}],\"usage\":{\"prompt_tokens\":243,\"total_tokens\":257,\"completion_tokens\":14,\"estimated_cost\":null,\"prompt_tokens_details\":null}}\n\ndata: {\"service_tier\":\"default\",\"id\":\"chatcmpl-RxlHFSnlLbUUz6XSxqBQj7TC\",\"object\":\"chat.completion.chunk\",\"created\":1787704444,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[],\"usage\":{\"prompt_tokens\":243,\"total_tokens\":257,\"completion_tokens\":14,\"estimated_cost\":0.000028780000000000002,\"prompt_tokens_details\":null}}\n\ndata: [DONE]\n\n"
}
},
{
"transport": "http",
"request": {
"method": "POST",
"url": "https://api.deepinfra.com/v1/openai/chat/completions",
"headers": {
"content-type": "application/json"
},
"body": "{\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"messages\":[{\"role\":\"system\",\"content\":\"Use the get_weather tool exactly once. After the tool result, reply exactly: Paris is sunny.\"},{\"role\":\"user\",\"content\":\"What is the weather in Paris?\"},{\"role\":\"assistant\",\"content\":null,\"tool_calls\":[{\"id\":\"call_W3stxe7FNHozlB4tDxlTVZou\",\"type\":\"function\",\"function\":{\"name\":\"get_weather\",\"arguments\":\"{\\\"city\\\":\\\"Paris\\\"}\"}}],\"reasoning_content\":\"\"},{\"role\":\"tool\",\"tool_call_id\":\"call_W3stxe7FNHozlB4tDxlTVZou\",\"content\":\"{\\\"temperature\\\":22,\\\"condition\\\":\\\"sunny\\\"}\"}],\"tools\":[{\"type\":\"function\",\"function\":{\"name\":\"get_weather\",\"description\":\"Get current weather for a city.\",\"parameters\":{\"type\":\"object\",\"properties\":{\"city\":{\"type\":\"string\"}},\"required\":[\"city\"],\"additionalProperties\":false},\"strict\":false}}],\"stream\":true,\"stream_options\":{\"include_usage\":true},\"max_tokens\":80,\"temperature\":0}"
},
"response": {
"status": 200,
"headers": {
"content-type": "text/event-stream; charset=utf-8"
},
"body": "data: {\"service_tier\":null,\"id\":\"chatcmpl-RHESVChSFPybgK1eUj2cLLY0\",\"object\":\"chat.completion.chunk\",\"created\":1787704445,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"\",\"reasoning_content\":null,\"tool_calls\":null},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null}\n\ndata: {\"service_tier\":\"default\",\"id\":\"chatcmpl-RHESVChSFPybgK1eUj2cLLY0\",\"object\":\"chat.completion.chunk\",\"created\":1787704445,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"Paris\",\"reasoning_content\":null,\"tool_calls\":null},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null}\n\ndata: {\"service_tier\":\"default\",\"id\":\"chatcmpl-RHESVChSFPybgK1eUj2cLLY0\",\"object\":\"chat.completion.chunk\",\"created\":1787704445,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\" is\",\"reasoning_content\":null,\"tool_calls\":null},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null}\n\ndata: {\"service_tier\":\"default\",\"id\":\"chatcmpl-RHESVChSFPybgK1eUj2cLLY0\",\"object\":\"chat.completion.chunk\",\"created\":1787704445,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\" sunny\",\"reasoning_content\":null,\"tool_calls\":null},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null}\n\ndata: {\"service_tier\":\"default\",\"id\":\"chatcmpl-RHESVChSFPybgK1eUj2cLLY0\",\"object\":\"chat.completion.chunk\",\"created\":1787704445,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\".\",\"reasoning_content\":null,\"tool_calls\":null},\"logprobs\":null,\"finish_reason\":null}],\"usage\":null}\n\ndata: {\"service_tier\":\"default\",\"id\":\"chatcmpl-RHESVChSFPybgK1eUj2cLLY0\",\"object\":\"chat.completion.chunk\",\"created\":1787704445,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"\",\"reasoning_content\":null,\"tool_calls\":null},\"logprobs\":null,\"finish_reason\":\"stop\"}],\"usage\":{\"prompt_tokens\":276,\"total_tokens\":281,\"completion_tokens\":5,\"estimated_cost\":null,\"prompt_tokens_details\":null}}\n\ndata: {\"service_tier\":\"default\",\"id\":\"chatcmpl-RHESVChSFPybgK1eUj2cLLY0\",\"object\":\"chat.completion.chunk\",\"created\":1787704445,\"model\":\"meta-llama/Llama-3.3-70B-Instruct-Turbo\",\"choices\":[],\"usage\":{\"prompt_tokens\":276,\"total_tokens\":281,\"completion_tokens\":5,\"estimated_cost\":0.0000292,\"prompt_tokens_details\":null}}\n\ndata: [DONE]\n\n"
}
}
]
}
+4 -9
View File
@@ -18,19 +18,13 @@ describe("provider error classification", () => {
expect(messages.every(isContextOverflow)).toBe(true)
})
test("classifies Anthropic request_too_large as recoverable overflow", () => {
expect(
test("classifies request size failures separately from context overflow", () => {
const failures = [
classifyProviderFailure({ message: "request too large", status: 413 }),
classifyProviderFailure({
message: '{"error":{"type":"request_too_large","message":"Request exceeds the maximum size"}}',
status: 400,
}),
).toMatchObject({ _tag: "InvalidRequest", classification: "context-overflow" })
expect(isContextOverflow("413 status code (no body)")).toBe(true)
})
test("classifies generic request size failures separately from context overflow", () => {
const failures = [
classifyProviderFailure({ message: "request too large", status: 413 }),
classifyProviderFailure({ message: "upstream request entity too large", status: 502 }),
]
@@ -39,6 +33,7 @@ describe("provider error classification", () => {
expect.objectContaining({ _tag: "InvalidRequest", classification: "payload-too-large" }),
),
)
expect(isContextOverflow("413 status code (no body)")).toBe(false)
})
test("does not classify rate limits as context overflow", () => {
-19
View File
@@ -28,7 +28,6 @@ describe("provider package entrypoints", () => {
import("@opencode-ai/ai/providers/amazon-bedrock/mantle/responses"),
import("@opencode-ai/ai/providers/togetherai"),
import("@opencode-ai/ai/providers/cerebras"),
import("@opencode-ai/ai/providers/deepinfra"),
])
for (const module of modules) expect(module.model).toBeFunction()
@@ -38,24 +37,6 @@ describe("provider package entrypoints", () => {
expect(modules[19].model).toBe(modules[20].model)
})
test("maps DeepInfra package settings onto its native executable model", async () => {
const DeepInfra = await import("@opencode-ai/ai/providers/deepinfra")
const settings = {
apiKey: "fixture",
baseURL: "https://provider.example.test/v1/",
headers: { "x-application": "opencode" },
body: { service_tier: "priority" },
providerOptions: { reasoningEffort: "high" as const },
}
const deepinfra = DeepInfra.model("google/gemma-3-27b-it", settings)
expect(deepinfra.route.id).toBe("deepinfra-chat")
expect(deepinfra.route.endpoint.baseURL).toBe("https://provider.example.test/v1/openai")
expect(deepinfra.route.defaults.providerOptions).toEqual(settings.providerOptions)
expect(deepinfra.route.defaults.headers).toEqual(settings.headers)
expect(deepinfra.route.defaults.http?.body).toEqual(settings.body)
})
test("maps OpenRouter and xAI package settings onto executable models", async () => {
const OpenRouter = await import("@opencode-ai/ai/providers/openrouter")
const XAI = await import("@opencode-ai/ai/providers/xai")
@@ -1,11 +1,11 @@
import { describe, expect } from "bun:test"
import { Effect } from "effect"
import { HttpClientRequest } from "effect/unstable/http"
import { LLM, Message } from "../../src/index.js"
import { LLM } from "../../src/index.js"
import { AmazonBedrockMantle } from "../../src/providers.js"
import { compileRequest, LLMClient } from "../../src/route/client.js"
import { it } from "../lib/effect.js"
import { dynamicResponse, fixedResponse } from "../lib/http.js"
import { dynamicResponse } from "../lib/http.js"
import { sseEvents } from "../lib/sse.js"
import { recordedTests } from "../recorded-test.js"
@@ -83,39 +83,6 @@ describe("Amazon Bedrock Mantle provider", () => {
expect(seen).toEqual([{ url: "https://mantle.test/v1/chat/completions", authorization: "Bearer test-key" }])
}),
)
it.effect("replays reasoning with Mantle's message-prefixed item ids", () =>
Effect.gen(function* () {
const model = AmazonBedrockMantle.configure({ apiKey: "test-key" }).responses("openai.gpt-oss-120b")
const item = { type: "reasoning", id: "msg_95d4d0af4350432a", encrypted_content: "mantle-state" }
const response = yield* LLMClient.generate(LLM.request({ model, prompt: "Think." })).pipe(
Effect.provide(
fixedResponse(
sseEvents(
{ type: "response.output_item.added", item },
{ type: "response.reasoning_summary_text.delta", item_id: item.id, delta: "Considering." },
{ type: "response.output_item.done", item },
{ type: "response.completed", response: { id: "resp_1" } },
),
),
),
)
const prepared = yield* compileRequest(
LLM.request({ model, messages: [response.message, Message.user("Continue.")] }),
)
expect(prepared.body.input).toEqual([
{
type: "reasoning",
id: "msg_95d4d0af4350432a",
summary: [{ type: "summary_text", text: "Considering." }],
encrypted_content: "mantle-state",
},
{ role: "user", content: [{ type: "input_text", text: "Continue." }] },
])
}),
)
})
const recorded = recordedTests({
@@ -1,6 +1,6 @@
import * as Anthropic from "../../src/providers/anthropic.js"
import * as AnthropicCompatible from "../../src/providers/anthropic-compatible.js"
import { Cerebras, DeepInfra, TogetherAI } from "../../src/providers/index.js"
import { Cerebras, TogetherAI } from "../../src/providers/index.js"
import { CloudflareAIGateway, CloudflareWorkersAI } from "../../src/providers/cloudflare.js"
import * as Google from "../../src/providers/google.js"
import * as OpenAI from "../../src/providers/openai.js"
@@ -55,9 +55,6 @@ const cerebras = Cerebras.configure({ apiKey: process.env.CEREBRAS_API_KEY ?? "f
const groq = OpenAICompatible.groq
.configure({ apiKey: process.env.GROQ_API_KEY ?? "fixture" })
.model("llama-3.3-70b-versatile")
const deepInfra = DeepInfra.configure({ apiKey: process.env.DEEPINFRA_API_KEY ?? "fixture" }).model(
"meta-llama/Llama-3.3-70B-Instruct-Turbo",
)
const openRouter = OpenRouter.configure({ apiKey: process.env.OPENROUTER_API_KEY ?? "fixture" })
const openrouter = openRouter.model("openai/gpt-4o-mini")
const openrouterGpt55 = openRouter.model("openai/gpt-5.5")
@@ -225,13 +222,6 @@ describeRecordedGoldenScenarios([
requires: ["GROQ_API_KEY"],
scenarios: ["text", "tool-call", { id: "tool-loop", timeout: 30_000 }],
},
{
name: "DeepInfra Llama 3.3 70B",
prefix: "deepinfra-chat",
model: deepInfra,
requires: ["DEEPINFRA_API_KEY"],
scenarios: ["text", "tool-call", { id: "tool-loop", timeout: 30_000 }],
},
{
name: "OpenRouter gpt-4o-mini",
prefix: "openai-compatible-chat",
@@ -2,7 +2,7 @@ import { describe, expect } from "bun:test"
import { ConfigProvider, Effect } from "effect"
import { HttpClientRequest } from "effect/unstable/http"
import { LLM, Message, ToolDefinition } from "../../src/index.js"
import { Cerebras, DeepInfra, TogetherAI } from "../../src/providers/index.js"
import { Cerebras, TogetherAI } from "../../src/providers/index.js"
import { compileRequest } from "../../src/route/client.js"
import { it } from "../lib/effect.js"
import { dynamicResponse } from "../lib/http.js"
@@ -29,18 +29,6 @@ describe("native OpenAI-compatible providers", () => {
}),
)
it.effect("preserves native DeepInfra provider and route identity", () =>
Effect.gen(function* () {
const deepinfra = DeepInfra.configure({ apiKey: "fixture" }).model("google/gemma-3-27b-it")
expect(deepinfra).toMatchObject({
provider: "deepinfra",
compatibility: { maxTokensField: "max_tokens", reasoningField: "reasoning_content", supportsStore: false },
route: { id: "deepinfra-chat", protocol: "openai-chat" },
})
expect(deepinfra.route.endpoint.baseURL).toBe("https://api.deepinfra.com/v1/openai")
}),
)
it.effect("applies native provider request defaults even with a custom gateway URL", () =>
Effect.gen(function* () {
const together = yield* compileRequest(
@@ -94,21 +82,6 @@ describe("native OpenAI-compatible providers", () => {
}),
)
it.effect("normalizes DeepInfra API roots without duplicating the OpenAI path", () =>
Effect.gen(function* () {
for (const baseURL of [
"https://gateway.example/v1",
"https://gateway.example/v1/",
"https://gateway.example/v1/openai",
"https://gateway.example/v1/openai/",
]) {
expect(DeepInfra.configure({ apiKey: "fixture", baseURL }).model("gemma").route.endpoint.baseURL).toBe(
"https://gateway.example/v1/openai",
)
}
}),
)
it.effect("maps package settings onto native executable models", () =>
Effect.gen(function* () {
for (const native of [TogetherAI, Cerebras]) {
@@ -149,12 +122,6 @@ describe("native OpenAI-compatible providers", () => {
token: "cerebras-secret",
url: "https://api.cerebras.ai/v1/chat/completions",
},
{
model: DeepInfra.configure().model("gemma"),
env: { DEEPINFRA_API_KEY: "deepinfra-secret" },
token: "deepinfra-secret",
url: "https://api.deepinfra.com/v1/openai/chat/completions",
},
]
yield* Effect.forEach(scenarios, (scenario) =>
@@ -195,19 +195,15 @@ describe("Open Responses-compatible route", () => {
model,
messages: [
Message.assistant([
// The baseline does not enforce a provider id grammar, so a
// non-OpenAI but well-formed token is resent as-is.
{ type: "text", text: "Kept.", providerMetadata: { openresponses: { itemId: "history_1" } } },
// Shape violations are dropped even without a grammar policy.
{
type: "text",
text: "Long.",
providerMetadata: { openresponses: { itemId: `history_${"a".repeat(64)}` } },
text: "Dropped.",
providerMetadata: { openresponses: { itemId: `m${"a".repeat(64)}` } },
},
{
type: "text",
text: "Opaque.",
providerMetadata: { openresponses: { itemId: "provider_value/with+symbols" } },
},
{ type: "text", text: "No suffix.", providerMetadata: { openresponses: { itemId: "msg_" } } },
{ type: "text", text: "No prefix.", providerMetadata: { openresponses: { itemId: "_item" } } },
]),
],
}),
@@ -222,23 +218,8 @@ describe("Open Responses-compatible route", () => {
},
{
type: "message",
id: `history_${"a".repeat(64)}`,
role: "assistant",
content: [{ type: "output_text", text: "Long." }],
},
{
type: "message",
id: "provider_value/with+symbols",
role: "assistant",
content: [{ type: "output_text", text: "Opaque." }],
},
{
type: "message",
role: "assistant",
content: [
{ type: "output_text", text: "No suffix." },
{ type: "output_text", text: "No prefix." },
],
content: [{ type: "output_text", text: "Dropped." }],
},
])
}),
@@ -3150,50 +3150,38 @@ describe("OpenAI Responses route", () => {
}),
)
it.effect("preserves provider-issued item ids and removes malformed ids without dropping items", () =>
it.effect("drops replayed item ids outside the server's grammar", () =>
Effect.gen(function* () {
const prepared = yield* compileRequest(
LLM.request({
model,
messages: [
Message.assistant([
// Fails the message id prefix.
{
type: "text",
text: "Hello",
providerMetadata: { openai: { itemId: "history_1" } },
},
// Oversized for the Responses item id limit.
{
type: "text",
text: "World",
providerMetadata: { openai: { itemId: `message_${"a".repeat(64)}` } },
providerMetadata: { openai: { itemId: `m${"a".repeat(64)}` } },
},
// Fails the reasoning id prefix, so the whole item is unreplayable
// statelessly and is skipped rather than sent malformed.
{
type: "reasoning",
text: "Checked the diff.",
providerMetadata: { openai: { itemId: "thinking_1", reasoningEncryptedContent: "encrypted-state" } },
},
{
type: "reasoning",
text: "Missing suffix.",
providerMetadata: { openai: { itemId: "rs_", reasoningEncryptedContent: "another-state" } },
},
{
type: "reasoning",
text: "No prefix separator.",
providerMetadata: { openai: { itemId: "550e8400-e29b-41d4-a716-446655440000" } },
},
ToolCallPart.make({
id: "call_1",
name: "lookup",
input: { query: "weather" },
providerMetadata: { openai: { itemId: "toolu_01A" } },
}),
ToolCallPart.make({
id: "call_2",
name: "lookup",
input: { query: "news" },
providerMetadata: { openai: { itemId: "fc_" } },
}),
]),
],
}),
@@ -3202,44 +3190,18 @@ describe("OpenAI Responses route", () => {
expect(prepared.body.input).toEqual([
{
type: "message",
id: "history_1",
role: "assistant",
content: [{ type: "output_text", text: "Hello" }],
},
{
type: "message",
id: `message_${"a".repeat(64)}`,
role: "assistant",
content: [{ type: "output_text", text: "World" }],
},
{
type: "reasoning",
id: "thinking_1",
summary: [{ type: "summary_text", text: "Checked the diff." }],
encrypted_content: "encrypted-state",
},
{
type: "reasoning",
summary: [{ type: "summary_text", text: "Missing suffix." }],
encrypted_content: "another-state",
},
{
type: "reasoning",
summary: [{ type: "summary_text", text: "No prefix separator." }],
content: [
{ type: "output_text", text: "Hello" },
{ type: "output_text", text: "World" },
],
},
{
type: "function_call",
id: "toolu_01A",
call_id: "call_1",
name: "lookup",
arguments: '{"query":"weather"}',
},
{
type: "function_call",
call_id: "call_2",
name: "lookup",
arguments: '{"query":"news"}',
},
])
}),
)
@@ -11,8 +11,7 @@ import { useLanguage } from "@/runtime/i18n/language"
import { getProjectAvatarVariant, type LocalProject } from "@/shell/state/layout"
import { ServerConnection } from "@/runtime/server/registry"
import { LocationProvider } from "@/workspaces/location"
import { displayName } from "@/shell/layout/helpers"
import { ProjectIcon } from "@/shell/layout/project-icon"
import { displayName, getProjectAvatarSource } from "@/shell/layout/helpers"
import { createEditProjectModel } from "./project-model"
import { ProjectSettingsExtensions } from "./project-extensions"
import { SettingsServerDataScope } from "@/settings/server-scope"
@@ -58,7 +57,11 @@ function ProjectSettingsDialog(props: { project: LocalProject; server: ServerCon
<Tabs.List>
<div class="project-settings-nav">
<Tabs.Trigger value="general">
<ProjectIcon project={props.project} class="!size-4 shrink-0" />
<ProjectAvatar
fallback={projectName()}
variant={getProjectAvatarVariant(props.project.icon?.color)}
class="!size-4 shrink-0"
/>
<span class="truncate">{projectName()}</span>
</Tabs.Trigger>
<Tabs.Trigger value="scripts">
@@ -111,14 +114,14 @@ function ProjectSettingsDialog(props: { project: LocalProject; server: ServerCon
onDragLeave={model.dragLeave}
onClick={model.iconClick}
>
<ProjectIcon
project={props.project}
<ProjectAvatar
fallback={model.store.name || model.defaultName()}
icon={{
src={getProjectAvatarSource(props.project.id, {
color: model.store.color,
url: props.project.icon?.url,
override: model.store.iconOverride,
}}
})}
variant={getProjectAvatarVariant(model.store.color)}
class="!size-16 [&_[data-slot=project-avatar-surface]]:!rounded-[6px] [&_[data-slot=project-avatar-surface]]:!text-[32px]"
/>
<span
@@ -1,12 +1,13 @@
import { Component, For, Show, createMemo, createSignal } from "solid-js"
import { IconButton } from "@opencode-ai/ui/icon-button"
import { Icon } from "@opencode-ai/ui/icon"
import { ProjectAvatar } from "@opencode-ai/ui/project-avatar"
import { useDialog } from "@opencode-ai/ui/context/dialog"
import { useLanguage } from "@/runtime/i18n/language"
import { useGlobal } from "@/runtime/server/runtime"
import { getProjectAvatarVariant } from "@/shell/state/layout"
import { ServerConnection, serverName } from "@/runtime/server/registry"
import { displayName } from "@/shell/layout/helpers"
import { ProjectIcon } from "@/shell/layout/project-icon"
import { InlineServerSelect } from "@/settings/server-select"
import { DialogEditProject } from "./project-dialog"
import "@/settings/settings.css"
@@ -39,13 +40,14 @@ export const SettingsProjects: Component = () => {
const ProjectRow: Component<{ project: ProjectItem; server: ServerConnection.Any }> = (props) => {
const name = () => displayName(props.project)
const color = () => getProjectAvatarVariant(props.project.icon?.color)
return (
<div
class="group flex items-center justify-between gap-5 px-4 py-2.5 rounded-lg bg-v2-background-bg-base shadow-[var(--v2-elevation-raised)] cursor-pointer transition-all hover:bg-v2-background-bg-layer-01"
onClick={() => openProjectSettings(props.project, props.server)}
>
<div class="flex items-center gap-2.5 min-w-0 flex-1">
<ProjectIcon project={props.project} class="shrink-0" />
<ProjectAvatar fallback={name()} variant={color()} class="shrink-0" />
<span class="text-13-medium text-v2-text-text-base truncate">{name()}</span>
</div>
<div class="flex items-center gap-2 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity">
@@ -1,24 +0,0 @@
import { ProjectAvatar, type ProjectAvatarProps } from "@opencode-ai/ui/project-avatar"
import { splitProps } from "solid-js"
import { displayName, getProjectAvatarSource } from "@/shell/layout/helpers"
import { getProjectAvatarVariant, type LocalProject } from "@/shell/state/layout"
type ProjectIconProps = Omit<ProjectAvatarProps, "fallback" | "src" | "variant"> & {
project: LocalProject
fallback?: string
icon?: LocalProject["icon"]
}
export function ProjectIcon(props: ProjectIconProps) {
const [local, rest] = splitProps(props, ["project", "fallback", "icon"])
const icon = () => local.icon ?? local.project.icon
return (
<ProjectAvatar
{...rest}
fallback={local.fallback ?? displayName(local.project)}
src={getProjectAvatarSource(local.project.id, icon())}
variant={getProjectAvatarVariant(icon()?.color)}
/>
)
}
+27
View File
@@ -88,8 +88,35 @@ export type PluginListInput = {
export type PluginListOutput = { readonly location: Location.Info; readonly data: ReadonlyArray<Plugin.Info> }
export type PluginListOperation<E = never> = (input?: PluginListInput) => Effect.Effect<PluginListOutput, E>
export type PluginCheckInput = {
readonly location?: { readonly directory?: string | undefined; readonly workspace?: string | undefined } | undefined
}
export type PluginCheckOutput = { readonly location: Location.Info; readonly data: ReadonlyArray<Plugin.UpdateInfo> }
export type PluginCheckOperation<E = never> = (input?: PluginCheckInput) => Effect.Effect<PluginCheckOutput, E>
export type PluginUpdateInput = {
readonly location?: { readonly directory?: string | undefined; readonly workspace?: string | undefined } | undefined
readonly name: string
}
export type PluginUpdateOutput = { readonly location: Location.Info; readonly data: Plugin.UpdateResult }
export type PluginUpdateOperation<E = never> = (input: PluginUpdateInput) => Effect.Effect<PluginUpdateOutput, E>
export type PluginUpdateAllInput = {
readonly location?: { readonly directory?: string | undefined; readonly workspace?: string | undefined } | undefined
}
export type PluginUpdateAllOutput = {
readonly location: Location.Info
readonly data: ReadonlyArray<Plugin.UpdateResult>
}
export type PluginUpdateAllOperation<E = never> = (
input?: PluginUpdateAllInput,
) => Effect.Effect<PluginUpdateAllOutput, E>
export interface PluginApi<E = never> {
readonly list: PluginListOperation<E>
readonly check: PluginCheckOperation<E>
readonly update: PluginUpdateOperation<E>
readonly updateAll: PluginUpdateAllOperation<E>
}
export type SessionListInput = {
+29 -1
View File
@@ -15,6 +15,12 @@ import type {
AgentGetOutput,
PluginListInput,
PluginListOutput,
PluginCheckInput,
PluginCheckOutput,
PluginUpdateInput,
PluginUpdateOutput,
PluginUpdateAllInput,
PluginUpdateAllOutput,
SessionListInput,
SessionListOutput,
SessionStatsInput,
@@ -313,7 +319,29 @@ const EndpointPluginList = (raw: RawClient["server.plugin"]) => (input?: PluginL
raw["plugin.list"]({ query: { location: input?.["location"] } }).pipe(Effect.mapError(mapClientError)),
)
const adaptGroupPlugin = (raw: RawClient["server.plugin"]) => ({ list: EndpointPluginList(raw) })
const EndpointPluginCheck = (raw: RawClient["server.plugin"]) => (input?: PluginCheckInput) =>
preserveEffect<PluginCheckOutput>()(
raw["plugin.check"]({ query: { location: input?.["location"] } }).pipe(Effect.mapError(mapClientError)),
)
const EndpointPluginUpdate = (raw: RawClient["server.plugin"]) => (input: PluginUpdateInput) =>
preserveEffect<PluginUpdateOutput>()(
raw["plugin.update"]({ query: { location: input["location"] }, payload: { name: input["name"] } }).pipe(
Effect.mapError(mapClientError),
),
)
const EndpointPluginUpdateAll = (raw: RawClient["server.plugin"]) => (input?: PluginUpdateAllInput) =>
preserveEffect<PluginUpdateAllOutput>()(
raw["plugin.updateAll"]({ query: { location: input?.["location"] } }).pipe(Effect.mapError(mapClientError)),
)
const adaptGroupPlugin = (raw: RawClient["server.plugin"]) => ({
list: EndpointPluginList(raw),
check: EndpointPluginCheck(raw),
update: EndpointPluginUpdate(raw),
updateAll: EndpointPluginUpdateAll(raw),
})
const EndpointSessionList = (raw: RawClient["server.session"]) => (input?: SessionListInput) =>
preserveEffect<SessionListOutput>()(
@@ -9,6 +9,12 @@ import type {
AgentGetOutput,
PluginListInput,
PluginListOutput,
PluginCheckInput,
PluginCheckOutput,
PluginUpdateInput,
PluginUpdateOutput,
PluginUpdateAllInput,
PluginUpdateAllOutput,
SessionListInput,
SessionListOutput,
SessionStatsInput,
@@ -457,6 +463,43 @@ export function make(options: ClientOptions) {
},
requestOptions,
),
check: (input?: PluginCheckInput, requestOptions?: RequestOptions) =>
request<PluginCheckOutput>(
{
method: "GET",
path: `/api/plugin/update`,
query: { location: input?.["location"] },
successStatus: 200,
declaredStatuses: [401, 400],
empty: false,
},
requestOptions,
),
update: (input: PluginUpdateInput, requestOptions?: RequestOptions) =>
request<PluginUpdateOutput>(
{
method: "POST",
path: `/api/plugin/update`,
query: { location: input["location"] },
body: { name: input["name"] },
successStatus: 200,
declaredStatuses: [401, 400],
empty: false,
},
requestOptions,
),
updateAll: (input?: PluginUpdateAllInput, requestOptions?: RequestOptions) =>
request<PluginUpdateAllOutput>(
{
method: "POST",
path: `/api/plugin/update-all`,
query: { location: input?.["location"] },
successStatus: 200,
declaredStatuses: [401, 400],
empty: false,
},
requestOptions,
),
},
session: {
list: (input?: SessionListInput, requestOptions?: RequestOptions) =>
+54 -5
View File
@@ -426,6 +426,24 @@ export type PluginInfo =
| { id: string; source: PluginSource; status: "active"; tui: boolean }
| { id?: string; source: PluginSource; status: "failed"; error: string; tui: boolean }
export type PluginUpdateInfo = {
name: string
source: PluginSource
status: "not-updateable" | "pinned" | "up-to-date" | "available" | "failed"
currentVersion?: string
latestVersion?: string
error?: string
}
export type PluginUpdateResult = {
name: string
source: PluginSource
status: "not-updateable" | "pinned" | "up-to-date" | "updated" | "failed"
previousVersion?: string
version?: string
error?: string
}
export type SessionMessageLocationSwitched = {
id: string
metadata?: { [x: string]: JsonValue }
@@ -476,7 +494,7 @@ export type PromptFileAttachment = {
export type PromptAgentAttachment = { name: string; mention?: PromptMention }
export type PromptSkillAttachment = { id: string; name: string; text?: string; mention?: PromptMention }
export type PromptSkillAttachment = { id: string; name: string; mention?: PromptMention }
export type SessionMessageAssistantText = { type: "text"; text: string; state?: SessionMessageProviderState }
@@ -974,7 +992,7 @@ export type WorktreeResolved = {
type: "worktree.resolved"
durable: { aggregateID: string; seq: number; version: 1 }
location?: LocationRef
data: { projectID: string; directory: string; previous: string; adopted?: Array<string> }
data: { projectID: string; directory: string; previous: string }
}
export type CommandUpdated = {
@@ -2460,6 +2478,40 @@ export type PluginListOutput = {
data: Array<PluginInfo>
}
export type PluginCheckInput = {
readonly location?: {
readonly location?: { readonly directory?: string | undefined; readonly workspace?: string | undefined } | undefined
}["location"]
}
export type PluginCheckOutput = {
location: { directory: string; workspaceID?: string; project: { id: string; directory: string; canonical: string } }
data: Array<PluginUpdateInfo>
}
export type PluginUpdateInput = {
readonly location?: {
readonly location?: { readonly directory?: string | undefined; readonly workspace?: string | undefined } | undefined
}["location"]
readonly name: { readonly name: string }["name"]
}
export type PluginUpdateOutput = {
location: { directory: string; workspaceID?: string; project: { id: string; directory: string; canonical: string } }
data: PluginUpdateResult
}
export type PluginUpdateAllInput = {
readonly location?: {
readonly location?: { readonly directory?: string | undefined; readonly workspace?: string | undefined } | undefined
}["location"]
}
export type PluginUpdateAllOutput = {
location: { directory: string; workspaceID?: string; project: { id: string; directory: string; canonical: string } }
data: Array<PluginUpdateResult>
}
export type SessionListInput = {
readonly workspace?: {
readonly workspace?: string | undefined
@@ -2740,7 +2792,6 @@ export type SessionImportInput = {
readonly skills?: ReadonlyArray<{
readonly id: string
readonly name: string
readonly text?: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly type: "user"
@@ -3016,7 +3067,6 @@ export type SessionImportInput = {
readonly skills?: ReadonlyArray<{
readonly id: string
readonly name: string
readonly text?: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly type: "user"
@@ -3292,7 +3342,6 @@ export type SessionImportInput = {
readonly skills?: ReadonlyArray<{
readonly id: string
readonly name: string
readonly text?: string
readonly mention?: { readonly start: number; readonly end: number; readonly text: string }
}>
readonly type: "user"
+1 -16
View File
@@ -617,22 +617,7 @@ export function createData(config: CreateDataInput) {
}
case "worktree.resolved": {
for (const [sessionID, info] of Object.entries(store.session.info)) {
const explicit = event.data.adopted?.includes(info.projectID)
const directory = explicit ? store.project.info[info.projectID]?.canonical : info.location.directory
if (!directory) {
if (info.location.workspaceID) continue
result.session.invalidate(sessionID)
void result.session.sync(sessionID)
continue
}
const adopted = Worktree.adopt(
{
projectID: info.projectID,
directory,
workspaceID: info.location.workspaceID,
},
event.data,
)
const adopted = Worktree.adopt({ projectID: info.projectID, directory: info.location.directory }, event.data)
if (!adopted) continue
setStore("session", "info", sessionID, "projectID", adopted.projectID)
setStore("session", "info", sessionID, "subpath", adopted.subpath)
-100
View File
@@ -154,106 +154,6 @@ test("updates authoritative cached project metadata from live events", async ()
}
})
test("adopts cached directory-project sessions when their repository is resolved", async () => {
const listeners = new Set<Parameters<CreateDataInput["event"]["listen"]>[0]>()
const refreshed: SessionInfo = {
...session(0),
id: "ses_uncached",
projectID: "repository",
location: { directory: "/unknown-alias" },
subpath: "app",
}
const api = OpenCode.make({
baseUrl: "http://opencode.local",
fetch: async (input, init) => {
const request = input instanceof Request ? input : new Request(input, init)
if (!request.url.endsWith("/api/session/ses_uncached")) throw new Error(`Unexpected request: ${request.url}`)
return Response.json({ data: refreshed })
},
})
const setup = createRoot((dispose) => ({
data: createData({
api: () => api,
directory: "/repo",
event: {
on: () => () => {},
listen(handler) {
listeners.add(handler)
return () => listeners.delete(handler)
},
},
}),
dispose,
}))
try {
const sessions: SessionInfo[] = [
{ ...session(0), id: "ses_root", projectID: "directory-root", location: { directory: "/repo" } },
{ ...session(0), id: "ses_nested", projectID: "directory-nested", location: { directory: "/repo/app" } },
{
...session(0),
id: "ses_alias",
projectID: "directory-nested",
location: { directory: "/repo/alias/../app" },
},
{ ...session(0), id: "ses_symlink", projectID: "directory-nested", location: { directory: "/shortcut" } },
{ ...refreshed, projectID: "directory-uncached" },
{ ...session(0), id: "ses_global", projectID: "global", location: { directory: "/repo/legacy" } },
{ ...session(0), id: "ses_escaped", projectID: "global", location: { directory: "/repo/../other" } },
{ ...session(0), id: "ses_other", projectID: "other-repository", location: { directory: "/repo/vendor" } },
{ ...session(0), id: "ses_sibling", projectID: "global", location: { directory: "/repo-other" } },
{
...session(0),
id: "ses_remote",
projectID: "directory-root",
location: { directory: "/repo", workspaceID: "workspace-remote" },
},
]
sessions.forEach((item) => setup.data.session.remember(item))
for (const project of [
{ id: "directory-root", canonical: "/repo" },
{ id: "directory-nested", canonical: "/repo/app" },
]) {
const updated: OpenCodeEvent = {
id: `evt_${project.id}`,
created: 0,
type: "project.updated",
data: { ...project, time: { created: 0, updated: 0 }, sandboxes: [] },
}
listeners.forEach((listener) => listener({ name: updated.type, details: updated }))
}
const resolved: OpenCodeEvent = {
id: "evt_repository_resolved",
created: 1,
type: "worktree.resolved",
durable: { aggregateID: "repository", seq: 0, version: 1 },
data: {
projectID: "repository",
directory: "/repo",
previous: "global",
adopted: ["directory-root", "directory-nested", "directory-uncached"],
},
}
listeners.forEach((listener) => listener({ name: resolved.type, details: resolved }))
expect(setup.data.session.get("ses_root")?.projectID).toBe("repository")
expect(setup.data.session.get("ses_root")?.subpath).toBeUndefined()
expect(setup.data.session.get("ses_nested")).toMatchObject({ projectID: "repository", subpath: "app" })
expect(setup.data.session.get("ses_alias")).toMatchObject({ projectID: "repository", subpath: "app" })
expect(setup.data.session.get("ses_symlink")).toMatchObject({ projectID: "repository", subpath: "app" })
expect(setup.data.session.get("ses_global")).toMatchObject({ projectID: "repository", subpath: "legacy" })
expect(setup.data.session.get("ses_escaped")?.projectID).toBe("global")
expect(setup.data.session.get("ses_other")?.projectID).toBe("other-repository")
expect(setup.data.session.get("ses_sibling")?.projectID).toBe("global")
expect(setup.data.session.get("ses_remote")?.projectID).toBe("directory-root")
await wait(() => setup.data.session.get("ses_uncached")?.projectID === "repository")
expect(setup.data.session.get("ses_uncached")?.subpath).toBe("app")
} finally {
setup.dispose()
}
})
test("refreshes global credential events across every loaded location and workspace", async () => {
const listeners = new Set<Parameters<CreateDataInput["event"]["listen"]>[0]>()
const requests: URL[] = []
-80
View File
@@ -1,80 +0,0 @@
import { describe, expect, test } from "bun:test"
import { Schema } from "effect"
import { Worktree } from "@opencode-ai/schema/worktree"
describe("Worktree.adopt", () => {
const event = {
projectID: "repository",
directory: "/repo",
previous: "previous",
adopted: ["directory-root", "directory-nested"],
}
test("adopts explicitly superseded directory projects", () => {
expect(Worktree.adopt({ projectID: "directory-root", directory: "/repo" }, event)).toEqual({
projectID: "repository",
subpath: undefined,
})
expect(Worktree.adopt({ projectID: "directory-nested", directory: "/repo/packages/app" }, event)).toEqual({
projectID: "repository",
subpath: "packages/app",
})
})
test("preserves existing previous-project and global adoption", () => {
expect(Worktree.adopt({ projectID: "previous", directory: "/repo/packages/app" }, event)).toEqual({
projectID: "repository",
subpath: "packages/app",
})
expect(Worktree.adopt({ projectID: "global", directory: "/repo/packages/app" }, event)).toEqual({
projectID: "repository",
subpath: "packages/app",
})
})
test("leaves unrelated projects, sibling directories, and workspaces unchanged", () => {
expect(Worktree.adopt({ projectID: "other", directory: "/repo/vendor" }, event)).toBeUndefined()
expect(Worktree.adopt({ projectID: "global", directory: "/repo-other" }, event)).toBeUndefined()
expect(Worktree.adopt({ projectID: "repository", directory: "/repo" }, event)).toBeUndefined()
expect(
Worktree.adopt({ projectID: "directory-root", directory: "/repo", workspaceID: "remote" }, event),
).toBeUndefined()
})
test("normalizes Windows directory separators", () => {
expect(
Worktree.adopt(
{ projectID: "directory-nested", directory: "C:\\repo\\packages\\app" },
{ ...event, directory: "C:\\repo" },
),
).toEqual({ projectID: "repository", subpath: "packages/app" })
expect(
Worktree.adopt(
{ projectID: "directory-nested", directory: "c:/Repo/packages/App" },
{ ...event, directory: "C:\\repo" },
),
).toEqual({ projectID: "repository", subpath: "packages/App" })
})
test("normalizes aliases and rejects paths that leave the repository", () => {
expect(Worktree.adopt({ projectID: "directory-nested", directory: "/repo/alias/../packages/app" }, event)).toEqual({
projectID: "repository",
subpath: "packages/app",
})
expect(Worktree.adopt({ projectID: "global", directory: "/repo/../other" }, event)).toBeUndefined()
expect(Worktree.adopt({ projectID: "global", directory: "/app" }, { ...event, directory: "/" })).toEqual({
projectID: "repository",
subpath: "app",
})
})
test("decodes existing durable events without adopted project IDs", () => {
expect(
Schema.decodeUnknownSync(Worktree.Event.Resolved.data)({
projectID: "repository",
directory: "/repo",
previous: "global",
}),
).toEqual({ projectID: "repository", directory: "/repo", previous: "global" })
})
})
+1
View File
@@ -103,6 +103,7 @@
"@ai-sdk/anthropic": "3.0.82",
"@ai-sdk/azure": "3.0.88",
"@ai-sdk/cohere": "3.0.27",
"@ai-sdk/deepinfra": "2.0.41",
"@ai-sdk/gateway": "3.0.104",
"@ai-sdk/google-vertex": "4.0.128",
"@ai-sdk/groq": "3.0.31",
+1 -2
View File
@@ -54,10 +54,9 @@ export function map(input: MapInput): Mapping | undefined {
},
}
case "@ai-sdk/cerebras":
case "@ai-sdk/deepinfra":
case "@ai-sdk/togetherai":
return {
package: `@opencode-ai/ai/providers/${input.packageName.slice("@ai-sdk/".length)}`,
package: `@opencode-ai/ai/providers/${input.packageName === "@ai-sdk/cerebras" ? "cerebras" : "togetherai"}`,
settings: {
...baseSettings,
...mapAPIKey(input.settings),
-2
View File
@@ -334,7 +334,6 @@ function usesAPIKeyAuth(packageName: string | undefined) {
name === "@ai-sdk/openai" ||
name === "@ai-sdk/anthropic" ||
name === "@ai-sdk/cerebras" ||
name === "@ai-sdk/deepinfra" ||
name === "@ai-sdk/openai-compatible" ||
name === "@ai-sdk/google" ||
name === "@ai-sdk/togetherai" ||
@@ -346,7 +345,6 @@ function usesAPIKeyAuth(packageName: string | undefined) {
name === "@opencode-ai/ai/providers/anthropic" ||
name === "@opencode-ai/ai/providers/anthropic-compatible" ||
name === "@opencode-ai/ai/providers/cerebras" ||
name === "@opencode-ai/ai/providers/deepinfra" ||
name === "@opencode-ai/ai/providers/openai-compatible" ||
name === "@opencode-ai/ai/providers/google" ||
name === "@opencode-ai/ai/providers/togetherai" ||
+1 -1
View File
@@ -1,5 +1,5 @@
export * as Plugin from "./plugin.js"
export { Event, ID, Info, Source } from "@opencode-ai/schema/plugin"
export { Event, ID, Info, Source, UpdateInfo, UpdateResult } from "@opencode-ai/schema/plugin"
import { Plugin } from "@opencode-ai/schema/plugin"
import type { Plugin as PluginDefinition } from "@opencode-ai/plugin/effect/plugin"
+2
View File
@@ -6,6 +6,7 @@ import { CerebrasPlugin } from "./provider/cerebras.js"
import { CloudflareAIGatewayPlugin } from "./provider/cloudflare-ai-gateway.js"
import { CloudflareWorkersAIPlugin } from "./provider/cloudflare-workers-ai.js"
import { CoherePlugin } from "./provider/cohere.js"
import { DeepInfraPlugin } from "./provider/deepinfra.js"
import { DynamicProviderPlugin } from "./provider/dynamic.js"
import { GatewayPlugin } from "./provider/gateway.js"
import { GithubCopilotPlugin } from "./provider/github-copilot.js"
@@ -41,6 +42,7 @@ export const ProviderPlugins: PluginInternal.InternalPlugin[] = [
CloudflareAIGatewayPlugin,
CloudflareWorkersAIPlugin,
CoherePlugin,
DeepInfraPlugin,
GatewayPlugin,
GithubCopilotPlugin,
GitLabPlugin,
@@ -0,0 +1,10 @@
import { createProviderPlugin } from "./factory.js"
export const DeepInfraPlugin = createProviderPlugin({
id: "opencode.provider.deepinfra",
package: "@ai-sdk/deepinfra",
load: async (options) => {
const { createDeepInfra } = await import("@ai-sdk/deepinfra")
return createDeepInfra(options)
},
})
@@ -1,6 +1,7 @@
export * as PluginSupervisor from "./supervisor-service.js"
import { Context, Effect } from "effect"
import { Plugin } from "@opencode-ai/schema/plugin"
/**
* Dependency-only supervisor seam. Keep this module free of implementation
@@ -9,6 +10,15 @@ import { Context, Effect } from "effect"
export interface Interface {
/** Wait for the initial plugin generation and startup updates to settle. */
readonly flush: Effect.Effect<void>
readonly check: () => Effect.Effect<Plugin.UpdateInfo[]>
readonly update: (name: string) => Effect.Effect<Plugin.UpdateResult>
readonly updateAll: () => Effect.Effect<Plugin.UpdateResult[]>
}
export class Service extends Context.Service<Service, Interface>()("@opencode/PluginSupervisor") {}
export const noUpdates = {
check: () => Effect.succeed([]),
update: () => Effect.die("Plugin updates unavailable"),
updateAll: () => Effect.succeed([]),
} satisfies Omit<Interface, "flush">
+146 -13
View File
@@ -1,9 +1,9 @@
export * as PluginSupervisor from "./supervisor.js"
export { Service, type Interface } from "./supervisor-service.js"
export { Service, type Interface, noUpdates } from "./supervisor-service.js"
import type { Plugin as PluginDefinition } from "@opencode-ai/plugin/effect/plugin"
import { Event } from "@opencode-ai/schema/config"
import { Cause, Effect, Latch, Layer, Schema, Stream } from "effect"
import { Cause, Effect, Latch, Layer, Schema, Semaphore, Stream } from "effect"
import path from "path"
import { pathToFileURL } from "url"
import { ConfigPluginSource } from "../config/plugin/source.js"
@@ -106,25 +106,30 @@ const load = Effect.fn("PluginSupervisor.load")(function* (
operation: Extract<ConfigPluginSource.Operation, { type: "add" }>,
) {
const npm = yield* Npm.Service
const entrypoint = path.isAbsolute(operation.target)
? pathToFileURL(operation.target).href
: (yield* npm.add(operation.target, { subpaths: ["server", ""], refresh: true })).entrypoint
const local = path.isAbsolute(operation.target)
const installed = local
? { entrypoint: pathToFileURL(operation.target).href, revision: operation.mtime?.toString() }
: yield* npm.add(operation.target, { subpaths: ["server", ""] })
const entrypoint = installed.entrypoint
if (!entrypoint) return yield* Effect.fail(new Error(`Plugin entrypoint not found: ${operation.target}`))
// Bun currently ignores query parameters when caching file:// imports.
const source =
operation.mtime === undefined
const source = local
? operation.mtime === undefined
? entrypoint
: typeof Bun !== "undefined"
? `${operation.target.replaceAll("\\", "/")}?mtime=${operation.mtime}`
: `${entrypoint}?mtime=${operation.mtime}`
yield* Effect.log({ msg: "loading plugin", id: operation.target, entrypoint: source })
: installed.revision
? `${entrypoint}?revision=${encodeURIComponent(installed.revision)}`
: entrypoint
yield* Effect.log({ msg: "loading plugin", local })
const mod = yield* Effect.promise(() => importModule(source))
const value = (yield* Schema.decodeUnknownEffect(PluginModule)(mod)).default
const plugin = "effect" in value ? value : PluginPromise.fromPromise(value)
return {
id: plugin.id,
tui: plugin.tui,
version: JSON.stringify(operation),
version: `${JSON.stringify(operation)}:${installed.revision ?? ""}`,
source: pluginSource(operation.target),
effect: (host) => plugin.effect({ ...host, options: operation.options }),
} satisfies Plugin.Versioned
@@ -134,15 +139,16 @@ export const layer = Layer.effect(
Service,
Effect.gen(function* () {
const registry = yield* Plugin.Service
const npm = yield* Npm.Service
const sdk = yield* SdkPlugins.Service
const sources = yield* ConfigPluginSource.Service
const bus = yield* Bus.Service
const ready = yield* Latch.make()
const activationLock = Semaphore.makeUnsafe(1)
const internal = yield* PluginInternal.list()
let observed = 0
const activate = Effect.fn("PluginSupervisor.activate")(function* () {
// Resolve OpenCode's internal plugins with their privileged Location services.
const internal = yield* PluginInternal.list()
// Combine internal plugins with host-contributed SDK plugins in boot order.
const pre = [
...internal.pre.map((plugin) => ({ ...plugin, version: "internal", source: { type: "builtin" as const } })),
@@ -159,6 +165,73 @@ export const layer = Layer.effect(
// Replace the active generation in one scoped, batched activation.
yield* registry.activate(resolved.plugins, resolved.failures)
})
const checkOne = Effect.fn("PluginSupervisor.checkOne")(function* (info: Plugin.Info) {
const name = pluginName(info)
if (info.source.type !== "package") {
return { name, source: info.source, status: "not-updateable" } satisfies Plugin.UpdateInfo
}
const source = info.source
return yield* npm.check(source.package).pipe(
Effect.map(
(update): Plugin.UpdateInfo => ({
name,
source: info.source,
status: update.pinned
? "pinned"
: !update.updateable
? "not-updateable"
: update.updateAvailable
? "available"
: "up-to-date",
currentVersion: update.currentVersion,
latestVersion: update.latestVersion,
}),
),
Effect.catchCause(() =>
Effect.succeed({
name,
source: info.source,
status: "failed",
error: "Failed to check plugin update",
} satisfies Plugin.UpdateInfo),
),
)
})
const check = Effect.fn("PluginSupervisor.check")(function* () {
return yield* Effect.forEach(yield* registry.list(), checkOne, { concurrency: "unbounded" })
})
const updateOne = Effect.fn("PluginSupervisor.updateOne")(function* (info: Plugin.Info) {
const name = pluginName(info)
if (info.source.type !== "package") {
return { name, source: info.source, status: "not-updateable" } satisfies Plugin.UpdateResult
}
const source = info.source
return yield* npm.update(source.package).pipe(
Effect.map(
(update): Plugin.UpdateResult => ({
name,
source: info.source,
status: update.pinned
? "pinned"
: !update.updateable
? "not-updateable"
: update.updated
? "updated"
: "up-to-date",
previousVersion: update.previousVersion,
version: update.latestVersion ?? update.currentVersion,
}),
),
Effect.catchCause(() =>
Effect.succeed({
name,
source: info.source,
status: "failed",
error: "Failed to update plugin",
} satisfies Plugin.UpdateResult),
),
)
})
const updates = Stream.merge(sources.changes(), bus.subscribe([Event.Updated, SdkPlugins.Updated])).pipe(
// Make accepted work visible to flush before coalescing the burst.
Stream.mapEffect(() =>
@@ -169,19 +242,73 @@ export const layer = Layer.effect(
}),
),
)
const reload = (packages: readonly string[]) =>
activationLock.withPermit(
Effect.gen(function* () {
yield* activate().pipe(Effect.scoped, Effect.provideService(Npm.Service, npm))
const failed = (yield* registry.list()).flatMap((info) =>
info.status === "failed" && info.source.type === "package" && packages.includes(info.source.package)
? [info.source.package]
: [],
)
if (failed.length === 0) return failed
yield* Effect.forEach(failed, (pkg) =>
npm
.rollback(pkg)
.pipe(
Effect.catchCause((cause) => Effect.logError("failed to restore plugin package revision", { cause })),
),
)
yield* activate().pipe(Effect.scoped, Effect.provideService(Npm.Service, npm))
return failed
}),
)
yield* Stream.concat(Stream.succeed(0), updates).pipe(
// Keep observing updates while activation runs, retaining only the latest generation request.
Stream.buffer({ capacity: 1, strategy: "sliding" }),
Stream.debounce("100 millis"),
Stream.runForEach((target) =>
Effect.gen(function* () {
yield* activate()
yield* activationLock.withPermit(activate())
if (observed === target) yield* ready.open
}).pipe(Effect.catchCause((cause) => Effect.logError("failed to reload plugins", { cause }))),
),
Effect.forkScoped({ startImmediately: true }),
)
return Service.of({ flush: ready.await })
return Service.of({
flush: ready.await,
check,
update: Effect.fn("PluginSupervisor.update")(function* (name) {
const info = (yield* registry.list()).find((info) => pluginName(info) === name || info.id === name)
if (!info) {
return {
name,
source: { type: "package", package: name },
status: "failed",
error: "Plugin not found",
}
}
const result = yield* updateOne(info)
if (result.status === "updated" && result.source.type === "package") {
const failed = yield* reload([result.source.package])
if (failed.length > 0)
return { ...result, status: "failed" as const, error: "Updated plugin failed to activate" }
}
return result
}),
updateAll: Effect.fn("PluginSupervisor.updateAll")(function* () {
const results = yield* Effect.forEach(yield* registry.list(), updateOne)
const packages = results.flatMap((result) =>
result.status === "updated" && result.source.type === "package" ? [result.source.package] : [],
)
if (packages.length === 0) return results
const failed = yield* reload(packages)
return results.map((result) => {
if (result.source.type !== "package" || !failed.includes(result.source.package)) return result
return { ...result, status: "failed" as const, error: "Updated plugin failed to activate" }
})
}),
})
}),
)
@@ -199,4 +326,10 @@ function pluginSource(target: string): Plugin.Source {
return { type: "package", package: target }
}
function pluginName(info: Plugin.Info) {
if (info.source.type === "package") return info.source.package
if (info.source.type === "local") return info.source.path
return info.id ?? info.source.type
}
export const node = makeLocationNode({ service: Service, layer, deps: nodeDeps })
+13 -54
View File
@@ -2,7 +2,7 @@ export * as Project from "./project.js"
import { Context, Effect, Layer, Schema } from "effect"
import { ChildProcess } from "effect/unstable/process"
import { and, asc, desc, eq, gte, isNull, lte } from "drizzle-orm"
import { and, asc, desc, eq } from "drizzle-orm"
import path from "path"
import { AbsolutePath } from "./schema.js"
import { Bus } from "./bus.js"
@@ -104,12 +104,7 @@ const layer = Layer.effect(
.pipe(Effect.orDie)
yield* upsertProject(db, project).pipe(Effect.orDie)
if (previous && previous.canonical !== project.canonical) {
const row = yield* db
.select()
.from(ProjectTable)
.where(eq(ProjectTable.id, project.id))
.get()
.pipe(Effect.orDie)
const row = yield* db.select().from(ProjectTable).where(eq(ProjectTable.id, project.id)).get().pipe(Effect.orDie)
if (row) yield* bus.publish(ProjectSchema.Event.Updated, fromRow(row))
}
if (!project.vcs) return project
@@ -140,38 +135,9 @@ const layer = Layer.effect(
.get()
.pipe(Effect.orDie)
if (stored) return
const directory = AbsolutePath.make(yield* fs.resolve(item.directory))
const markerless = yield* db
.select({ id: ProjectTable.id, directory: ProjectTable.worktree })
.from(ProjectTable)
.where(
and(
isNull(ProjectTable.vcs),
gte(ProjectTable.worktree, directory),
lte(ProjectTable.worktree, AbsolutePath.make(directory + "\uffff")),
),
)
.all()
.pipe(Effect.orDie)
const adopted = yield* Effect.filter(markerless, (candidate) =>
Effect.gen(function* () {
if (candidate.id === item.projectID) return false
if (!FSUtil.contains(directory, candidate.directory)) return false
const markers = yield* fs
.up({ targets: [".git", ".hg"], start: candidate.directory, stop: directory, mode: "first" })
.pipe(Effect.orElseSucceed(() => []))
if (!markers[0]) return false
return (yield* fs.resolve(path.dirname(markers[0]))) === directory
}),
)
yield* bus.publish(
Worktree.Event.Resolved,
{
projectID: item.projectID,
directory: item.directory,
previous: project.previous ?? ID.global,
...(adopted.length ? { adopted: adopted.map((candidate) => candidate.id) } : {}),
},
{ projectID: item.projectID, directory: item.directory, previous: project.previous ?? ID.global },
{
commit: () =>
db
@@ -290,7 +256,12 @@ const layer = Layer.effect(
return node ? ID.make(node) : undefined
})
const hgDiscover = Effect.fnUntraced(function* (dotHg: AbsolutePath) {
const hgDiscover = Effect.fnUntraced(function* (input: AbsolutePath) {
const dotHg = yield* fs.up({ targets: [".hg"], start: input, mode: "first" }).pipe(
Effect.map((matches) => matches[0]),
Effect.orElseSucceed(() => undefined),
)
if (!dotHg) return undefined
const worktree = AbsolutePath.make(path.dirname(dotHg))
const store = AbsolutePath.make(dotHg)
const previous = yield* cached(store)
@@ -304,15 +275,7 @@ const layer = Layer.effect(
})
const resolve = Effect.fn("Project.resolve")(function* (input: AbsolutePath) {
const directory = AbsolutePath.make(yield* fs.resolve(input))
const marker = yield* fs.up({ targets: [".git", ".hg"], start: directory, mode: "first" }).pipe(
Effect.map((matches) => matches[0]),
Effect.orElseSucceed(() => undefined),
)
const repo =
marker && path.basename(marker) === ".git"
? yield* git.repo.discover(AbsolutePath.make(path.dirname(marker)))
: undefined
const repo = yield* git.repo.discover(input)
if (repo) {
const previous = yield* cached(repo.commonDirectory)
const id = (yield* remote(repo)) ?? previous ?? (yield* rootCommit(repo))
@@ -332,14 +295,10 @@ const layer = Layer.effect(
})
}
const hg = marker && path.basename(marker) === ".hg" ? yield* hgDiscover(AbsolutePath.make(marker)) : undefined
const hg = yield* hgDiscover(input)
if (hg) return yield* persist({ ...hg, canonical: hg.directory })
return yield* persist({
id: ID.make(Hash.fast(`directory:${directory}`)),
directory,
canonical: directory,
vcs: undefined,
})
const directory = AbsolutePath.make(path.parse(input).root)
return yield* persist({ id: ID.global, directory, canonical: directory, vcs: undefined })
})
return Service.of({ list, update, resolve })
-1
View File
@@ -49,7 +49,6 @@ const builtins = new Map<string, () => Promise<unknown>>([
["@opencode-ai/ai/providers/azure/chat", () => import("@opencode-ai/ai/providers/azure/chat")],
["@opencode-ai/ai/providers/azure/responses", () => import("@opencode-ai/ai/providers/azure/responses")],
["@opencode-ai/ai/providers/cerebras", () => import("@opencode-ai/ai/providers/cerebras")],
["@opencode-ai/ai/providers/deepinfra", () => import("@opencode-ai/ai/providers/deepinfra")],
["@opencode-ai/ai/providers/google", () => import("@opencode-ai/ai/providers/google")],
["@opencode-ai/ai/providers/google-vertex", () => import("@opencode-ai/ai/providers/google-vertex")],
["@opencode-ai/ai/providers/google-vertex/gemini", () => import("@opencode-ai/ai/providers/google-vertex/gemini")],
+12 -22
View File
@@ -596,11 +596,7 @@ const layer = Layer.effect(
yield* plugins.flush
return yield* Image.Service
}).pipe(Effect.provide(locations.get(session.location)))
const skills = Effect.gen(function* () {
const plugins = yield* PluginSupervisor.Service
yield* plugins.flush
return yield* Skill.Service
}).pipe(Effect.provide(locations.get(session.location)))
const skills = Skill.Service.pipe(Effect.provide(locations.get(session.location)))
const prompt = yield* resolvePrompt(
{ text: input.text, files: input.files, agents: input.agents, skills: input.skills },
image,
@@ -722,7 +718,7 @@ const layer = Layer.effect(
skill: Effect.fn("Session.skill")(function* (input) {
const session = yield* result.get(input.sessionID)
const skills = yield* Skill.Service.pipe(Effect.provide(locations.get(session.location)))
const skill = yield* skills.get(input.skill)
const skill = (yield* skills.list()).find((item) => item.id === input.skill)
if (!skill) return yield* new SkillNotFoundError({ skill: input.skill })
yield* bus.publish(
SessionEvent.Skill.Activated,
@@ -974,22 +970,16 @@ const resolvePrompt = Effect.fn("Session.resolvePrompt")(function* (
const selected = yield* Effect.gen(function* () {
if (!requested?.length) return undefined
const skillService = yield* skills
const prepared = new Map<Skill.ID, Skill.Name>()
return yield* Effect.forEach(requested, (attachment) =>
Effect.gen(function* () {
const name = prepared.get(attachment.id)
if (name !== undefined) return { id: attachment.id, name, mention: attachment.mention }
const skill = yield* skillService.get(attachment.id)
if (!skill) return yield* new SkillNotFoundError({ skill: attachment.id })
prepared.set(skill.id, skill.name)
return {
id: skill.id,
name: skill.name,
text: (yield* Skill.prepare(fs, skill).pipe(Effect.orDie)).output,
mention: attachment.mention,
}
}),
)
const available = yield* skillService.list()
return yield* Effect.forEach(requested, (attachment) => {
const skill = available.find((item) => item.id === attachment.id)
if (!skill) return Effect.fail(new SkillNotFoundError({ skill: attachment.id }))
return Effect.succeed({
id: skill.id,
name: skill.name,
mention: attachment.mention,
})
})
})
return Prompt.make({ text: input.text, agents: input.agents, files, skills: selected?.length ? selected : undefined })
})
+1 -5
View File
@@ -139,11 +139,7 @@ const serialize = (message: SessionMessage.Info) => {
(file) =>
`[Attached ${file.mime}: ${file.name ?? (file.source.type === "uri" ? file.source.uri : "inline attachment")}]`,
) ?? []
const skills =
message.skills?.flatMap((skill) =>
skill.text === undefined ? [] : [`[Skill activated: ${skill.name}]\n${skill.text}`],
) ?? []
return [...skills, `[User]: ${message.text}`, ...files].join("\n")
return [`[User]: ${message.text}`, ...files].join("\n")
}
if (message.type === "location-switched")
return `[User]: The working directory has been changed to ${message.location.directory}.`
+11 -31
View File
@@ -1,6 +1,6 @@
export * as SessionProjector from "./projector.js"
import { and, asc, desc, eq, gt, gte, inArray, isNull, lt, lte, or, sql } from "drizzle-orm"
import { and, asc, desc, eq, gt, gte, inArray, lt, lte, sql } from "drizzle-orm"
import { DateTime, Effect, Layer, Schema, Stream } from "effect"
import path from "path"
import { Database } from "../database/database.js"
@@ -23,7 +23,6 @@ import { Worktree } from "@opencode-ai/schema/worktree"
import { Project } from "@opencode-ai/schema/project"
import { AbsolutePath, RelativePath } from "../schema.js"
import type { SessionSchema } from "./schema.js"
import { ProjectTable } from "../project/sql.js"
type DatabaseService = Database.Interface["db"]
type CurrentDurableEvent = Extract<SessionEvent.Event, { readonly durable: object }>
@@ -479,34 +478,18 @@ const layer = Layer.effectDiscard(
// are untouched: the session did not move, its directory got identified.
yield* bus.project(Worktree.Event.Resolved, (event) =>
Effect.gen(function* () {
const candidates = [
...new Set(
[event.data.previous, Project.ID.global, ...(event.data.adopted ?? [])].filter(
(id) => id !== event.data.projectID,
),
),
]
if (candidates.length === 0) return
const stale = [event.data.previous, Project.ID.global].filter((id) => id !== event.data.projectID)
if (stale.length === 0) return
const rows = yield* db
.select({
id: SessionTable.id,
directory: SessionTable.directory,
projectID: SessionTable.project_id,
canonical: ProjectTable.worktree,
})
.select({ id: SessionTable.id, directory: SessionTable.directory })
.from(SessionTable)
.innerJoin(ProjectTable, eq(SessionTable.project_id, ProjectTable.id))
.where(
and(
inArray(SessionTable.project_id, candidates),
isNull(SessionTable.workspace_id),
or(
event.data.adopted?.length ? inArray(SessionTable.project_id, event.data.adopted) : undefined,
and(
gte(SessionTable.directory, event.data.directory),
lte(SessionTable.directory, AbsolutePath.make(event.data.directory + "\uffff")),
),
),
inArray(SessionTable.project_id, stale),
// Lexicographic range narrows the scan to prefix neighbors without
// LIKE escaping; FSUtil.contains below decides containment exactly.
gte(SessionTable.directory, event.data.directory),
lte(SessionTable.directory, AbsolutePath.make(event.data.directory + "\uffff")),
),
)
.all()
@@ -514,15 +497,12 @@ const layer = Layer.effectDiscard(
yield* Effect.forEach(
rows,
(row) => {
const directory = event.data.adopted?.includes(row.projectID)
? row.canonical
: AbsolutePath.make(path.resolve(row.directory))
if (!FSUtil.contains(event.data.directory, directory)) return Effect.void
if (!FSUtil.contains(event.data.directory, row.directory)) return Effect.void
return db
.update(SessionTable)
.set({
project_id: event.data.projectID,
path: RelativePath.make(path.relative(event.data.directory, directory).replaceAll("\\", "/")),
path: RelativePath.make(path.relative(event.data.directory, row.directory).replaceAll("\\", "/")),
// Self-assignment suppresses the column's $onUpdate: adoption is not activity.
time_updated: sql`${SessionTable.time_updated}`,
})
@@ -236,7 +236,6 @@ function toLLMMessage(message: SessionMessage.Info, model: Model.Ref, providerMe
]
case "user":
const content = [
...(message.skills ?? []).flatMap((skill) => (skill.text === undefined ? [] : [Message.text(skill.text)])),
...(message.text === "" ? [] : [Message.text(message.text)]),
...userAttachmentContent(message.files ?? []),
]
-1
View File
@@ -220,7 +220,6 @@ function sanitizeMessage(message: SessionMessage.Info): SessionMessage.Info {
skills: message.skills?.map((skill, index) => ({
...skill,
name: Skill.Name.make(redact("skill-name", String(index), skill.name)),
text: skill.text === undefined ? undefined : redact("skill", String(index), skill.text),
mention: skill.mention
? { ...skill.mention, text: redact("skill-mention", String(index), skill.mention.text) }
: undefined,
-20
View File
@@ -1,7 +1,6 @@
export * as Skill from "./skill.js"
import { makeLocationNode } from "@opencode-ai/util/effect/app-node"
import type { FSUtil } from "@opencode-ai/util/fs-util"
import path from "path"
import { Context, Effect, Layer, Types } from "effect"
import { Skill } from "@opencode-ai/schema/skill"
@@ -53,21 +52,6 @@ export const toModelOutput = (skill: Info, files: ReadonlyArray<string>) => {
].join("\n")
}
export const prepare = Effect.fn("Skill.prepare")(function* (fs: FSUtil.Interface, skill: Info) {
const directory = path.dirname(skill.location)
const files =
path.basename(skill.location) === "SKILL.md"
? (yield* fs.scan("**/*", { cwd: directory, absolute: true, include: "file", dot: true }))
.filter((file) => path.basename(file) !== "SKILL.md")
.toSorted()
.slice(0, 10)
: []
return {
directory,
output: toModelOutput(skill, files),
}
})
export type Data = {
skills: Map<ID, Types.DeepMutable<Info>>
}
@@ -80,7 +64,6 @@ export type Draft = {
}
export interface Interface extends State.Transformable<Draft> {
readonly get: (id: ID) => Effect.Effect<Info | undefined>
readonly list: () => Effect.Effect<Info[]>
}
@@ -115,9 +98,6 @@ const layer = Layer.effect(
return Service.of({
transform: state.transform,
reload: state.reload,
get: Effect.fn("Skill.get")(function* (id) {
return state.get().skills.get(id)
}),
list: Effect.fn("Skill.list")(function* () {
return Array.from(state.get().skills.values())
}),
+1
View File
@@ -26,6 +26,7 @@ const render = (skills: ReadonlyArray<Summary>) =>
[
"Skills provide specialized instructions and workflows for specific tasks.",
"Use the skill tool to load a skill when a task matches its description.",
"When the user references a skill with @skill-id, load that skill with the skill tool.",
...(skills.length === 0
? ["No skills are currently available."]
: ["<available_skills>", ...entries(skills), "</available_skills>"]),
+17 -2
View File
@@ -1,6 +1,7 @@
export * as SkillTool from "./skill.js"
import type { Context as PluginContext } from "@opencode-ai/plugin/effect/plugin"
import path from "path"
import { ToolFailure } from "@opencode-ai/ai"
import { Effect, Schema } from "effect"
import { FSUtil } from "@opencode-ai/util/fs-util"
@@ -8,6 +9,7 @@ import { Skill } from "../../skill.js"
import { Permission } from "../../permission.js"
export const name = "skill"
const FILE_LIMIT = 10
export const Input = Schema.Struct({
id: Skill.ID.annotate({ description: "The ID of an available skill or a skill explicitly referenced by the user" }),
@@ -45,7 +47,8 @@ export const Plugin = {
output: Output,
execute: (input, context) =>
Effect.gen(function* () {
const skill = yield* skills.get(input.id)
const current = yield* skills.list()
const skill = current.find((skill) => skill.id === input.id)
if (!skill) return yield* unableToLoad(input.id)
return yield* Effect.gen(function* () {
yield* permission.assert({
@@ -56,7 +59,19 @@ export const Plugin = {
agent: context.agent,
source: { type: "tool", messageID: context.messageID, id: context.id },
})
return { name: skill.name, ...(yield* Skill.prepare(fs, skill)) }
const directory = path.dirname(skill.location)
const files =
path.basename(skill.location) === "SKILL.md"
? (yield* fs.scan("**/*", { cwd: directory, absolute: true, include: "file", dot: true }))
.filter((file) => path.basename(file) !== "SKILL.md")
.toSorted()
.slice(0, FILE_LIMIT)
: []
return {
name: skill.name,
directory,
output: Skill.toModelOutput(skill, files),
}
}).pipe(Effect.mapError((error) => unableToLoad(input.id, error)))
}).pipe(
Effect.map((output) => ({
+2 -2
View File
@@ -61,8 +61,8 @@ describe("AISDKNative", () => {
})
})
test("maps Cerebras, DeepInfra, and Together AI settings, headers, and reasoning options to native providers", () => {
for (const name of ["cerebras", "deepinfra", "togetherai"]) {
test("maps Cerebras and Together AI settings, headers, and reasoning options to native providers", () => {
for (const name of ["cerebras", "togetherai"]) {
expect(
map(`@ai-sdk/${name}`, {
apiKey: "secret",
+24
View File
@@ -37,6 +37,30 @@ const staticIt = testEffect(
)
describe("PluginSupervisor config", () => {
it.live("reports local and builtin plugins as not updateable", () => {
const plugin = path.join(import.meta.dir, "../plugin/fixtures/config-promise-plugin.ts")
return withLocation(
{ plugins: [plugin] },
Effect.gen(function* () {
yield* ready()
const supervisor = yield* PluginSupervisor.Service
const updates = yield* supervisor.check()
expect(updates.find((update) => update.name === plugin)).toEqual({
name: plugin,
source: { type: "local", path: plugin },
status: "not-updateable",
})
expect(updates.find((update) => update.source.type === "builtin")?.status).toBe("not-updateable")
expect(yield* supervisor.update(plugin)).toEqual({
name: plugin,
source: { type: "local", path: plugin },
status: "not-updateable",
})
}),
)
})
it.live("applies selectors in order", () =>
withLocation(
{ plugins: ["-opencode.provider.*", "opencode.provider.openai"] },
@@ -25,13 +25,18 @@ import { host } from "../plugin/host"
type WatcherEvent = { file: string; event: "add" | "change" | "unlink" }
const describeNative = process.env.CI ? describe.skip : describe
const pluginUpdates = {
check: () => Effect.succeed([]),
update: () => Effect.die("unused"),
updateAll: () => Effect.succeed([]),
}
const it = testEffect(AppNodeBuilder.build(LayerNode.group([FSUtil.node, Bus.node])))
const configLayer = Config.testLayer()
const pluginNode = makeLocationNode({
service: PluginSupervisor.Service,
layer: Layer.succeed(PluginSupervisor.Service, PluginSupervisor.Service.of({ flush: Effect.void })),
layer: Layer.succeed(PluginSupervisor.Service, PluginSupervisor.Service.of({ ...pluginUpdates, flush: Effect.void })),
deps: [],
})
@@ -314,7 +319,7 @@ describe("LocationWatcher subscriptions", () => {
Effect.gen(function* () {
const policy = yield* LocationWatcherPolicy.Service
yield* policy.transform((draft) => draft.add([".git"]))
return PluginSupervisor.Service.of({ flush: Effect.void })
return PluginSupervisor.Service.of({ ...pluginUpdates, flush: Effect.void })
}),
),
deps: [LocationWatcherPolicy.node],
-16
View File
@@ -885,12 +885,6 @@ describe("ModelResolver", () => {
{ reasoningEffort: "high" },
{ reasoningEffort: "high" },
],
[
"@ai-sdk/deepinfra",
"@opencode-ai/ai/providers/deepinfra",
{ reasoningEffort: "none" },
{ reasoningEffort: "none" },
],
[
"@ai-sdk/openai-compatible",
"@opencode-ai/ai/providers/openai-compatible",
@@ -969,7 +963,6 @@ describe("ModelResolver", () => {
],
["@ai-sdk/azure", "@opencode-ai/ai/providers/azure/responses", "api-model"],
["@ai-sdk/cerebras", "@opencode-ai/ai/providers/cerebras", "api-model"],
["@ai-sdk/deepinfra", "@opencode-ai/ai/providers/deepinfra", "api-model"],
["@ai-sdk/google", "@opencode-ai/ai/providers/google", "api-model"],
["@ai-sdk/google-vertex", "@opencode-ai/ai/providers/google-vertex", "api-model"],
["@ai-sdk/google-vertex/anthropic", "@opencode-ai/ai/providers/google-vertex/messages", "claude-sonnet-4-6"],
@@ -1094,11 +1087,6 @@ describe("ModelResolver", () => {
const cerebras = yield* ModelResolver.fromCatalogModel(
model(Provider.aisdk("@ai-sdk/cerebras"), { settings: { reasoningEffort: "high" } }),
)
const deepinfra = yield* ModelResolver.fromCatalogModel(
model(Provider.aisdk("@ai-sdk/deepinfra"), {
settings: { baseURL: "https://deepinfra.example/provider-root", reasoningEffort: "none" },
}),
)
const togetherai = yield* ModelResolver.fromCatalogModel(
model(Provider.aisdk("@ai-sdk/togetherai"), { settings: { reasoningEffort: "high" } }),
)
@@ -1125,10 +1113,6 @@ describe("ModelResolver", () => {
expect(cerebras.route.id).toBe("cerebras-chat")
expect(cerebras.route.defaults.providerOptions).toEqual({ reasoningEffort: "high" })
expect(String(cerebras.provider)).toBe("test-provider")
expect(deepinfra.route.id).toBe("deepinfra-chat")
expect(deepinfra.route.endpoint.baseURL).toBe("https://deepinfra.example/provider-root/openai")
expect(deepinfra.route.defaults.providerOptions).toEqual({ reasoningEffort: "none" })
expect(String(deepinfra.provider)).toBe("test-provider")
expect(togetherai.route.id).toBe("togetherai-chat")
expect(togetherai.route.defaults.providerOptions).toEqual({ reasoningEffort: "high" })
expect(String(togetherai.provider)).toBe("test-provider")
+178
View File
@@ -0,0 +1,178 @@
import fs from "fs/promises"
import path from "path"
import { fileURLToPath, pathToFileURL } from "url"
import { describe, expect, test } from "bun:test"
import { Effect } from "effect"
import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
import { Global } from "@opencode-ai/util/global"
import { Npm } from "@opencode-ai/util/npm"
import { tmpdir } from "./fixture/tmpdir"
const npmLayer = (cache: string) =>
AppNodeBuilder.build(Npm.node, [[Global.node, Global.layerWith({ cache, state: path.join(cache, "state") })]])
describe("Npm plugin updates", () => {
test("checks a moving Git ref without installing and explicitly updates its cached revision", async () => {
await using tmp = await tmpdir()
const repository = path.join(tmp.path, "plugin")
const cache = path.join(tmp.path, "cache")
await fs.mkdir(repository)
await Bun.write(
path.join(repository, "package.json"),
JSON.stringify({ name: "fixture-plugin", version: "1.0.0", exports: "./index.js" }),
)
await Bun.write(path.join(repository, "index.js"), "export default 'first'\n")
await Bun.$`git init -q -b main ${repository}`
await commit(repository, "first")
const first = await revision(repository)
const spec = `git+${pathToFileURL(repository).href}#main`
const layer = npmLayer(cache)
const installed = await Effect.gen(function* () {
const npm = yield* Npm.Service
return yield* npm.add(spec)
}).pipe(Effect.scoped, Effect.provide(layer), Effect.runPromise)
expect(installed.revision).toBe(first)
await Bun.write(path.join(repository, "index.js"), "export default 'second'\n")
await commit(repository, "second")
const second = await revision(repository)
const checked = await Effect.gen(function* () {
const npm = yield* Npm.Service
return yield* npm.check(spec)
}).pipe(Effect.provide(layer), Effect.runPromise)
expect(checked).toMatchObject({
currentVersion: first,
latestVersion: second,
updateAvailable: true,
})
const updated = await Effect.gen(function* () {
const npm = yield* Npm.Service
return yield* npm.update(spec)
}).pipe(Effect.scoped, Effect.provide(layer), Effect.runPromise)
expect(updated).toMatchObject({
previousVersion: first,
currentVersion: second,
updated: true,
})
const current = await Effect.gen(function* () {
const npm = yield* Npm.Service
return yield* npm.add(spec)
}).pipe(Effect.scoped, Effect.provide(layer), Effect.runPromise)
expect(current.directory).not.toBe(installed.directory)
expect(current.revision).toBe(second)
if (!current.entrypoint) throw new Error("Updated plugin entrypoint missing")
expect(
await Bun.file(
current.entrypoint.startsWith("file:") ? fileURLToPath(current.entrypoint) : current.entrypoint,
).text(),
).toContain("second")
const unchanged = await Effect.gen(function* () {
const npm = yield* Npm.Service
return yield* npm.update(spec)
}).pipe(Effect.scoped, Effect.provide(layer), Effect.runPromise)
expect(unchanged).toMatchObject({
previousVersion: second,
currentVersion: second,
latestVersion: second,
updateAvailable: false,
updated: false,
})
expect(
await Effect.gen(function* () {
const npm = yield* Npm.Service
return yield* npm.resolve(spec)
}).pipe(Effect.provide(layer), Effect.runPromise),
).toMatchObject({ directory: current.directory, revision: second })
await Effect.gen(function* () {
const npm = yield* Npm.Service
yield* npm.rollback(spec)
}).pipe(Effect.provide(layer), Effect.runPromise)
expect(
await Effect.gen(function* () {
const npm = yield* Npm.Service
return yield* npm.resolve(spec)
}).pipe(Effect.provide(layer), Effect.runPromise),
).toMatchObject({ directory: installed.directory, revision: first })
})
test("resolves a Git semver selector without installing HEAD outside the configured range", async () => {
await using tmp = await tmpdir()
const repository = path.join(tmp.path, "plugin")
const cache = path.join(tmp.path, "cache")
await fs.mkdir(repository)
await writePlugin(repository, "1.0.0", "one")
await Bun.$`git init -q -b main ${repository}`
await commit(repository, "one")
await Bun.$`git -C ${repository} tag v1.0.0`
const first = await revision(repository)
const spec = `git+${pathToFileURL(repository).href}#semver:^1`
const layer = npmLayer(cache)
const installed = await Effect.gen(function* () {
const npm = yield* Npm.Service
return yield* npm.add(spec)
}).pipe(Effect.scoped, Effect.provide(layer), Effect.runPromise)
expect(installed.revision).toBe(first)
await writePlugin(repository, "1.1.0", "one-one")
await commit(repository, "one-one")
await Bun.$`git -C ${repository} tag v1.1.0`
const latest = await revision(repository)
await writePlugin(repository, "2.0.0", "two")
await commit(repository, "two")
await Bun.$`git -C ${repository} tag v2.0.0`
expect(await revision(repository)).not.toBe(latest)
const checked = await Effect.gen(function* () {
const npm = yield* Npm.Service
return yield* npm.check(spec)
}).pipe(Effect.provide(layer), Effect.runPromise)
expect(checked).toMatchObject({ currentVersion: first, latestVersion: latest, updateAvailable: true })
const updated = await Effect.gen(function* () {
const npm = yield* Npm.Service
return yield* npm.update(spec)
}).pipe(Effect.scoped, Effect.provide(layer), Effect.runPromise)
expect(updated).toMatchObject({ currentVersion: latest, latestVersion: latest, updated: true })
})
test("fails checks for missing Git refs", async () => {
await using tmp = await tmpdir()
const repository = path.join(tmp.path, "plugin")
await fs.mkdir(repository)
await writePlugin(repository, "1.0.0", "one")
await Bun.$`git init -q -b main ${repository}`
await commit(repository, "one")
const layer = npmLayer(path.join(tmp.path, "cache"))
await expect(
Effect.gen(function* () {
const npm = yield* Npm.Service
return yield* npm.check(`git+${pathToFileURL(repository).href}#missing`)
}).pipe(Effect.provide(layer), Effect.runPromise),
).rejects.toMatchObject({ _tag: "NpmInstallFailedError" })
})
})
async function writePlugin(repository: string, version: string, value: string) {
await Bun.write(
path.join(repository, "package.json"),
JSON.stringify({ name: "fixture-plugin", version, exports: "./index.js" }),
)
await Bun.write(path.join(repository, "index.js"), `export default '${value}'\n`)
}
async function commit(repository: string, message: string) {
await Bun.$`git -C ${repository} add .`
await Bun.$`git -C ${repository} -c user.name=fixture -c user.email=fixture@example.com commit -qm ${message}`
}
async function revision(repository: string) {
return Bun.$`git -C ${repository} rev-parse HEAD`.text().then((value) => value.trim())
}
-42
View File
@@ -1,6 +1,5 @@
import fs from "fs/promises"
import path from "path"
import { pathToFileURL } from "url"
import { describe, expect, test } from "bun:test"
import { Effect } from "effect"
import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
@@ -222,47 +221,6 @@ describe("Npm.add", () => {
await fs.stat(path.join(path.dirname(entry.directory), "fixture-subdirectory-dependency", "package.json")),
).toBeTruthy()
})
test("refreshes mutable Git packages once per service lifetime and preserves pinned or cached installs", async () => {
await using tmp = await tmpdir()
const fixture = await createGitFixture(tmp.path)
const cache = path.join(tmp.path, "cache")
const repository = pathToFileURL(fixture.repository).href
const mutable = `git+${repository}#fixture-branch`
const pinned = `git+${repository}#${fixture.commit}`
const first = await Effect.gen(function* () {
const npm = yield* Npm.Service
const mutableEntry = yield* npm.add(mutable, { refresh: true })
const pinnedEntry = yield* npm.add(pinned, { refresh: true })
yield* Effect.promise(async () => {
await Bun.write(path.join(fixture.repository, "index.js"), 'export default { root: "second" }\n')
await Bun.$`git -C ${fixture.repository} add .`
await Bun.$`git -C ${fixture.repository} -c user.name=fixture -c user.email=fixture@example.com commit -qm second`
})
yield* npm.add(mutable, { refresh: true })
return { mutable: mutableEntry, pinned: pinnedEntry }
}).pipe(Effect.scoped, Effect.provide(npmLayer(cache)), Effect.runPromise)
expect(await Bun.file(path.join(first.mutable.directory, "index.js")).text()).toContain("root: true")
expect(await Bun.file(path.join(first.pinned.directory, "index.js")).text()).toContain("root: true")
const second = await Effect.gen(function* () {
const npm = yield* Npm.Service
return {
mutable: yield* npm.add(mutable, { refresh: true }),
pinned: yield* npm.add(pinned, { refresh: true }),
}
}).pipe(Effect.scoped, Effect.provide(npmLayer(cache)), Effect.runPromise)
expect(await Bun.file(path.join(second.mutable.directory, "index.js")).text()).toContain('root: "second"')
expect(await Bun.file(path.join(second.pinned.directory, "index.js")).text()).toContain("root: true")
await fs.rename(fixture.repository, `${fixture.repository}-offline`)
const offline = await Effect.gen(function* () {
const npm = yield* Npm.Service
return yield* npm.add(mutable, { refresh: true })
}).pipe(Effect.scoped, Effect.provide(npmLayer(cache)), Effect.runPromise)
expect(await Bun.file(path.join(offline.directory, "index.js")).text()).toContain('root: "second"')
})
})
describe("Npm.resolve", () => {
+3
View File
@@ -35,7 +35,10 @@ const npmLayer = Layer.succeed(
Npm.Service,
Npm.Service.of({
add: () => Effect.succeed({ directory: "", entrypoint: undefined }),
check: () => Effect.succeed({ updateable: false, pinned: false, updateAvailable: false }),
resolve: () => Effect.succeed({ directory: "", entrypoint: undefined }),
update: () => Effect.succeed({ updateable: false, pinned: false, updateAvailable: false, updated: false }),
rollback: () => Effect.void,
which: () => Effect.undefined,
}),
)
@@ -23,7 +23,10 @@ const itWithAISDK = testEffect(Layer.mergeAll(PluginTestLayer, AppNodeBuilder.bu
function npmEntrypoint(entrypoint?: string) {
return Npm.Service.of({
add: () => Effect.succeed({ directory: "", entrypoint }),
check: () => Effect.succeed({ updateable: false, pinned: false, updateAvailable: false }),
resolve: () => Effect.succeed({ directory: "", entrypoint }),
update: () => Effect.succeed({ updateable: false, pinned: false, updateAvailable: false, updated: false }),
rollback: () => Effect.void,
which: () => Effect.undefined,
})
}
@@ -6,6 +6,7 @@ import { Plugin } from "@opencode-ai/core/plugin"
import { PluginHost } from "@opencode-ai/core/plugin/host"
import { AlibabaPlugin } from "@opencode-ai/core/plugin/provider/alibaba"
import { CoherePlugin } from "@opencode-ai/core/plugin/provider/cohere"
import { DeepInfraPlugin } from "@opencode-ai/core/plugin/provider/deepinfra"
import { GatewayPlugin } from "@opencode-ai/core/plugin/provider/gateway"
import { GroqPlugin } from "@opencode-ai/core/plugin/provider/groq"
import { MistralPlugin } from "@opencode-ai/core/plugin/provider/mistral"
@@ -20,6 +21,7 @@ const options = { name: "custom-provider", apiKey: "test", baseURL: "https://exa
const providers = [
{ id: "alibaba", plugin: AlibabaPlugin, package: "@ai-sdk/alibaba", provider: "alibaba.chat" },
{ id: "cohere", plugin: CoherePlugin, package: "@ai-sdk/cohere", provider: "cohere.chat" },
{ id: "deepinfra", plugin: DeepInfraPlugin, package: "@ai-sdk/deepinfra", provider: "deepinfra.chat" },
{ id: "gateway", plugin: GatewayPlugin, package: "@ai-sdk/gateway", provider: "gateway" },
{ id: "groq", plugin: GroqPlugin, package: "@ai-sdk/groq", provider: "groq.chat" },
{ id: "mistral", plugin: MistralPlugin, package: "@ai-sdk/mistral", provider: "mistral.chat" },
@@ -14,7 +14,10 @@ const fixtureProvider = new URL("./fixtures/provider-factory.ts", import.meta.ur
const it = testEffect(PluginTestLayer)
const npm = Npm.Service.of({
add: () => Effect.succeed({ directory: "", entrypoint: undefined }),
check: () => Effect.succeed({ updateable: false, pinned: false, updateAvailable: false }),
resolve: () => Effect.succeed({ directory: "", entrypoint: undefined }),
update: () => Effect.succeed({ updateable: false, pinned: false, updateAvailable: false, updated: false }),
rollback: () => Effect.void,
which: () => Effect.undefined,
})
+3 -75
View File
@@ -145,54 +145,24 @@ async function rootCommit(dir: string) {
}
describe("Project.resolve", () => {
it.live("creates distinct deterministic projects for exact markerless directories", () =>
it.live("returns global for non-git directory", () =>
Effect.gen(function* () {
const tmp = yield* Effect.acquireRelease(
Effect.promise(() => tmpdir()),
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
)
const project = yield* Project.Service
const nested = path.join(tmp.path, "notes", "drafts")
yield* Effect.promise(() => fs.mkdir(nested, { recursive: true }))
const result = yield* project.resolve(abs(tmp.path))
const repeated = yield* project.resolve(abs(`${tmp.path}${path.sep}.`))
const child = yield* project.resolve(abs(nested))
expect(result.id).not.toBe(Project.ID.global)
expect(repeated.id).toBe(result.id)
expect(child.id).not.toBe(result.id)
expect(result.directory).toBe(yield* real(tmp.path))
expect(child.directory).toBe(yield* real(nested))
expect(result.id).toBe(Project.ID.make("global"))
expect(path.resolve(result.directory)).toBe(path.parse(tmp.path).root)
expect(result.canonical).toBe(result.directory)
expect(result.previous).toBeUndefined()
expect(result.vcs).toBeUndefined()
}),
)
it.live("repository markers override markerless directory projects", () =>
Effect.gen(function* () {
const tmp = yield* Effect.acquireRelease(
Effect.promise(() => tmpdir()),
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
)
const nested = path.join(tmp.path, "packages", "app")
yield* Effect.promise(() => fs.mkdir(nested, { recursive: true }))
const project = yield* Project.Service
const root = yield* project.resolve(abs(tmp.path))
const child = yield* project.resolve(abs(nested))
yield* Effect.promise(() => initRepo(tmp.path, { commit: true }))
const repository = yield* project.resolve(abs(nested))
expect(root.id).not.toBe(child.id)
expect(repository.id).not.toBe(root.id)
expect(repository.id).not.toBe(child.id)
expect(repository.directory).toBe(yield* real(tmp.path))
expect(repository.vcs?.type).toBe("git")
}),
)
it.live("does not publish project updates for first or repeated resolutions", () =>
Effect.gen(function* () {
const tmp = yield* Effect.acquireRelease(
@@ -441,48 +411,6 @@ describe("Project.resolve", () => {
}),
)
it.live("prefers the nearest mercurial marker over an outer git repository", () =>
Effect.gen(function* () {
const tmp = yield* Effect.acquireRelease(
Effect.promise(() => tmpdir()),
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
)
const nested = path.join(tmp.path, "nested")
yield* Effect.promise(async () => {
await initRepo(tmp.path, { commit: true })
await fs.mkdir(path.join(nested, ".hg"), { recursive: true })
await fs.mkdir(path.join(nested, "app"))
})
const project = yield* Project.Service
const result = yield* project.resolve(abs(path.join(nested, "app")))
expect(result.vcs?.type).toBe("hg")
expect(result.directory).toBe(yield* real(nested))
}),
)
it.live("prefers the nearest git marker over an outer mercurial repository", () =>
Effect.gen(function* () {
const tmp = yield* Effect.acquireRelease(
Effect.promise(() => tmpdir()),
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
)
const nested = path.join(tmp.path, "nested")
yield* Effect.promise(async () => {
await fs.mkdir(path.join(tmp.path, ".hg"))
await fs.mkdir(path.join(nested, "app"), { recursive: true })
await initRepo(nested, { commit: true })
})
const project = yield* Project.Service
const result = yield* project.resolve(abs(path.join(nested, "app")))
expect(result.vcs?.type).toBe("git")
expect(result.directory).toBe(yield* real(nested))
}),
)
it.live("returns global id for unreadable mercurial metadata", () =>
Effect.gen(function* () {
const tmp = yield* Effect.acquireRelease(
-1
View File
@@ -6,7 +6,6 @@ describe("Provider", () => {
test("loads bundled native provider entrypoints", async () => {
const packages = [
"@opencode-ai/ai/providers/cerebras",
"@opencode-ai/ai/providers/deepinfra",
"@opencode-ai/ai/providers/google-vertex",
"@opencode-ai/ai/providers/google-vertex/gemini",
"@opencode-ai/ai/providers/google-vertex/chat",
@@ -23,7 +23,6 @@ import { PluginHooks } from "@opencode-ai/core/plugin/hooks"
import { Location } from "@opencode-ai/core/location"
import { AbsolutePath } from "@opencode-ai/core/schema"
import { Money } from "@opencode-ai/schema/money"
import { Skill } from "@opencode-ai/schema/skill"
import { DateTime, Effect, Fiber, Layer, Schema, Stream } from "effect"
import { asc, eq } from "drizzle-orm"
import { testEffect } from "./lib/effect"
@@ -232,13 +231,6 @@ it.effect("manual compaction summarizes short context instead of no-op", () =>
id: SessionMessage.ID.create(),
type: "user" as const,
text: "Manual compaction should include this short conversation.",
skills: [
{
id: Skill.ID.make("effect"),
name: Skill.Name.make("Effect"),
text: "Use Effect services and generators.",
},
],
time: { created: DateTime.makeUnsafe(0) },
}
const session = yield* insertSession(sessionID, { parent_id: parentID })
@@ -269,7 +261,6 @@ it.effect("manual compaction summarizes short context instead of no-op", () =>
})
expect(requests[0]?.generation).toBeUndefined()
expect(JSON.stringify(requests[0]?.messages)).toContain("Manual compaction should include this short conversation.")
expect(JSON.stringify(requests[0]?.messages)).toContain("Use Effect services and generators.")
expect(yield* store.context(sessionID)).toMatchObject([
{ type: "compaction", reason: "manual", summary: "manual summary", recent: "" },
])
+6 -117
View File
@@ -5,7 +5,6 @@ import path from "path"
import { DateTime, Effect, Layer, Stream } from "effect"
import { Money } from "@opencode-ai/schema/money"
import { Shell } from "@opencode-ai/schema/shell"
import { Skill } from "@opencode-ai/schema/skill"
import { Agent } from "@opencode-ai/core/agent"
import { asc, eq } from "drizzle-orm"
import { Database } from "@opencode-ai/core/database/database"
@@ -96,37 +95,14 @@ describe("Session.create", () => {
const { db } = yield* Database.Service
const ref = Location.Ref.make({ directory: AbsolutePath.make(directory) })
const nested = Location.Ref.make({ directory: AbsolutePath.make(path.join(directory, "packages", "app")) })
const aliased = Location.Ref.make({
directory: AbsolutePath.make([path.join(directory, "alias"), "..", "packages", "app"].join(path.sep)),
})
const created = yield* session.create({ location: ref, title: "Before git" })
const child = yield* session.create({ location: nested, title: "Nested before git" })
const alias = yield* session.create({ location: aliased, title: "Aliased before git" })
const bus = yield* Bus.Service
const store = yield* SessionStore.Service
yield* session.prompt({ sessionID: created.id, text: "Preserved history", resume: false })
yield* SessionInbox.promote(db, bus, created.id, "steer")
const pending = yield* session.prompt({ sessionID: created.id, text: "Preserved inbox", resume: false })
yield* store.claim(created.id)
const before = yield* db
.select()
.from(SessionTable)
.where(eq(SessionTable.id, created.id))
.get()
.pipe(Effect.orDie)
if (!before) return yield* Effect.die(new Error("created session not found"))
const originalUpdated = created.time.updated
yield* Effect.promise(async () => {
await $`git init -q`.cwd(directory)
await $`git config user.email test@example.com`.cwd(directory)
await $`git config user.name Test`.cwd(directory)
})
const unborn = yield* projects.resolve(ref.directory)
const unbornRoot = yield* session.get(created.id)
const unbornNested = yield* session.get(child.id)
const unbornAlias = yield* session.get(alias.id)
yield* Effect.promise(async () => {
await fs.writeFile(path.join(directory, "README.md"), "test\n")
await $`git add README.md`.cwd(directory)
await $`git commit -qm initial`.cwd(directory)
@@ -137,25 +113,10 @@ describe("Session.create", () => {
const repeat = yield* projects.resolve(ref.directory)
const adopted = yield* session.get(created.id)
const nestedAdopted = yield* session.get(child.id)
const aliasAdopted = yield* session.get(alias.id)
const page = yield* session.list({ project: project.id })
const log = Array.from(yield* Stream.runCollect(logEvents(session, created.id)))
expect(created.projectID).not.toBe(Project.ID.global)
expect(child.projectID).not.toBe(created.projectID)
expect(alias.projectID).toBe(child.projectID)
expect(unborn.id).toBe(Project.ID.global)
expect(unbornRoot).toMatchObject({ projectID: Project.ID.global, subpath: undefined })
expect(unbornNested).toMatchObject({ projectID: Project.ID.global, subpath: "packages/app" })
expect(unbornAlias).toMatchObject({ projectID: Project.ID.global, subpath: "packages/app" })
expect(
yield* db
.select({ data: EventTable.data })
.from(EventTable)
.where(eq(EventTable.aggregate_id, Project.ID.global))
.get()
.pipe(Effect.orDie),
).toMatchObject({ data: { adopted: expect.arrayContaining([created.projectID, child.projectID]) } })
expect(created.projectID).toBe(Project.ID.global)
expect(project.id).toBe(Project.ID.make(Hash.fast("git-remote:github.com/owner/adopted")))
expect(repeat.id).toBe(project.id)
expect(page.data.map((item) => item.id)).toEqual(expect.arrayContaining([created.id, child.id]))
@@ -163,37 +124,16 @@ describe("Session.create", () => {
projectID: project.id,
location: ref,
subpath: undefined,
time: { updated: DateTime.makeUnsafe(before.time_updated) },
time: { updated: originalUpdated },
})
expect(nestedAdopted).toMatchObject({
projectID: project.id,
location: nested,
subpath: RelativePath.make("packages/app"),
})
expect(aliasAdopted).toMatchObject({
projectID: project.id,
location: aliased,
subpath: RelativePath.make("packages/app"),
})
// Adoption is a project-domain fact; the session log records nothing new.
expect(log.map((event) => event.type)).toEqual([
"session.created",
"session.inbox.enqueued",
"session.inbox.delivered",
"session.inbox.enqueued",
])
expect(yield* session.messages({ sessionID: created.id })).toMatchObject([
{ id: expect.any(String), type: "user", text: "Preserved history" },
])
expect(yield* SessionInbox.find(db, pending.id)).toMatchObject({ payload: { text: "Preserved inbox" } })
expect(
yield* db.select().from(SessionTable).where(eq(SessionTable.id, created.id)).get().pipe(Effect.orDie),
).toMatchObject({
time_created: before.time_created,
time_updated: before.time_updated,
time_suspended: before.time_suspended,
resume_attempts: before.resume_attempts,
})
expect(log.map((event) => event.type)).toEqual(["session.created"])
expect(yield* session.messages({ sessionID: created.id })).toEqual([])
// Repeated resolution announces the directory's identity exactly once.
const announced = yield* db
.select({ type: EventTable.type })
@@ -206,46 +146,6 @@ describe("Session.create", () => {
),
)
liveIt.live("does not adopt nested repositories or sessions in another workspace", () =>
withTmp((directory) =>
Effect.gen(function* () {
const session = yield* Session.Service
const projects = yield* Project.Service
const outer = path.join(directory, "outer")
const nested = path.join(outer, "nested")
const child = AbsolutePath.make(path.join(nested, "app"))
yield* Effect.promise(() => fs.mkdir(child, { recursive: true }))
const local = yield* session.create({ location: Location.Ref.make({ directory: AbsolutePath.make(outer) }) })
const inside = yield* session.create({ location: Location.Ref.make({ directory: child }) })
const remote = yield* session.create({
location: Location.Ref.make({
directory: AbsolutePath.make(outer),
workspaceID: Workspace.ID.make("wrk_remote"),
}),
})
yield* Effect.promise(async () => {
for (const root of [nested, outer]) {
await $`git init -q`.cwd(root)
await $`git config user.email test@example.com`.cwd(root)
await $`git config user.name Test`.cwd(root)
await $`git commit --allow-empty -qm initial`.cwd(root)
}
})
const parent = yield* projects.resolve(AbsolutePath.make(outer))
expect((yield* session.get(local.id)).projectID).toBe(parent.id)
expect((yield* session.get(inside.id)).projectID).toBe(inside.projectID)
expect((yield* session.get(remote.id)).projectID).toBe(remote.projectID)
const repository = yield* projects.resolve(AbsolutePath.make(nested))
expect((yield* session.get(inside.id)).projectID).toBe(repository.id)
expect((yield* session.get(remote.id)).projectID).toBe(remote.projectID)
}),
),
)
it.effect("persists a missing title until one is generated or supplied", () =>
Effect.gen(function* () {
const session = yield* Session.Service
@@ -1278,13 +1178,6 @@ describe("SessionTransfer", () => {
id: sourceMessageID,
type: "user",
text: "Imported message",
skills: [
{
id: Skill.ID.make("effect"),
name: Skill.Name.make("Effect"),
text: "Private skill instructions from /private/project",
},
],
time: { created: DateTime.makeUnsafe(100) },
},
{
@@ -1314,11 +1207,7 @@ describe("SessionTransfer", () => {
const sanitized = yield* transfer.export({ sessionID, sanitize: true })
expect(sanitized.info.time).toMatchObject({ idle: DateTime.makeUnsafe(200), viewed: DateTime.makeUnsafe(150) })
expect(sanitized.messages).toMatchObject([
{
id: sourceMessageID,
text: `[redacted:text:${sourceMessageID}]`,
skills: [{ id: "effect", name: "[redacted:skill-name:0]", text: "[redacted:skill:0]" }],
},
{ id: sourceMessageID, text: `[redacted:text:${sourceMessageID}]` },
{ id: errorMessageID, error: { type: "test_error", message: "Original error" } },
])
+2 -4
View File
@@ -110,7 +110,7 @@ const discovery = Layer.mock(InstructionDiscovery.Service, {
const skills = Layer.mock(SkillInstructions.Service, { load: () => Effect.succeed(Instructions.empty) })
const references = Layer.mock(ReferenceInstructions.Service, { load: () => Effect.succeed(Instructions.empty) })
const mcp = Layer.mock(McpInstructions.Service, { load: () => Effect.succeed(Instructions.empty) })
const plugins = Layer.mock(PluginSupervisor.Service, { flush: Effect.void })
const plugins = Layer.mock(PluginSupervisor.Service, { ...PluginSupervisor.noUpdates, flush: Effect.void })
const tools = Layer.mock(Tool.Service, {
snapshot: () =>
Effect.succeed({
@@ -132,7 +132,6 @@ const it = testEffect(
LayerNode.group([
Database.node,
Bus.node,
Project.node,
SessionProjector.node,
SessionStore.node,
Agent.node,
@@ -201,7 +200,6 @@ const setup = Effect.gen(function* () {
const { db } = yield* Database.Service
const bus = yield* Bus.Service
const agents = yield* Agent.Service
const projects = yield* Project.Service
const instructionBuiltIns = yield* InstructionBuiltIns.Service
yield* agents.transform((draft) =>
draft.update(Agent.ID.make("build"), (agent) => {
@@ -212,7 +210,7 @@ const setup = Effect.gen(function* () {
.insert(SessionTable)
.values({
id: sessionID,
project_id: (yield* projects.resolve(AbsolutePath.make("/project"))).id,
project_id: Project.ID.global,
slug: "generate-test",
directory: "/project",
title: "Generate test",
+5 -3
View File
@@ -76,12 +76,14 @@ const locations = Layer.effect(
Layer.mock(Snapshot.Service, {
capture: () =>
ready ? Effect.undefined : Effect.die(new Error("Snapshot used before plugins were ready")),
restore: () =>
ready ? Effect.void : Effect.die(new Error("Snapshot used before plugins were ready")),
restore: () => (ready ? Effect.void : Effect.die(new Error("Snapshot used before plugins were ready"))),
}),
Layer.succeed(
PluginSupervisor.Service,
PluginSupervisor.Service.of({ flush: Effect.sync(() => (ready = true)) }),
PluginSupervisor.Service.of({
...PluginSupervisor.noUpdates,
flush: Effect.sync(() => (ready = true)),
}),
),
)
}),
@@ -205,44 +205,6 @@ Recent work
})
})
test("lowers each prepared skill once before the prompt", () => {
const effect = SkillAttachment.make({
id: Skill.ID.make("effect"),
name: Skill.Name.make("Effect"),
text: "<skill_content>Use Effect</skill_content>",
})
const api = SkillAttachment.make({
id: Skill.ID.make("api-design"),
name: Skill.Name.make("API design"),
text: "<skill_content>Design APIs</skill_content>",
})
const messages = toLLMMessages(
[
SessionMessage.User.make({
id: id("user-skill-content"),
type: "user",
text: "Use @effect and @api-design",
skills: [effect, api, SkillAttachment.make({ id: effect.id, name: effect.name })],
time: { created },
}),
],
model,
)
expect(messages).toEqual([
Message.make({
id: id("user-skill-content"),
role: "user",
content: [
{ type: "text", text: "<skill_content>Use Effect</skill_content>" },
{ type: "text", text: "<skill_content>Design APIs</skill_content>" },
{ type: "text", text: "Use @effect and @api-design" },
],
metadata: {},
}),
])
})
test("does not inject skill content for reference-only attachments", () => {
const messages = toLLMMessages(
[
@@ -85,7 +85,10 @@ const referenceInstructions = Layer.mock(ReferenceInstructions.Service, {
})
const mcpInstructions = Layer.mock(McpInstructions.Service, { load: () => Effect.succeed(Instructions.empty) })
const config = Config.testLayer()
const pluginSupervisor = Layer.succeed(PluginSupervisor.Service, PluginSupervisor.Service.of({ flush: Effect.void }))
const pluginSupervisor = Layer.succeed(
PluginSupervisor.Service,
PluginSupervisor.Service.of({ ...PluginSupervisor.noUpdates, flush: Effect.void }),
)
const promptCatalog = Layer.mock(Catalog.Service, {
provider: {
get: () => Effect.undefined,
@@ -374,6 +374,7 @@ let pluginFlushHook = Effect.void
const pluginSupervisor = Layer.succeed(
PluginSupervisor.Service,
PluginSupervisor.Service.of({
...PluginSupervisor.noUpdates,
flush: Effect.suspend(() => pluginFlushHook),
}),
)
+17 -57
View File
@@ -9,7 +9,6 @@ import { Location } from "@opencode-ai/core/location"
import { LocationServiceMap } from "@opencode-ai/core/location-service-map"
import type { LocationServices } from "@opencode-ai/core/location-services"
import { Project } from "@opencode-ai/core/project"
import { PluginSupervisor } from "@opencode-ai/core/plugin/supervisor-service"
import { AbsolutePath } from "@opencode-ai/core/schema"
import { Session } from "@opencode-ai/core/session"
import { SessionExecution } from "@opencode-ai/core/session/execution"
@@ -24,20 +23,18 @@ const location = Location.Ref.make({ directory: AbsolutePath.make("/project") })
const projects = Layer.mock(Project.Service, {
resolve: (directory) => Effect.succeed({ id: Project.ID.global, directory, canonical: directory }),
})
const info = Skill.Info.make({
id: Skill.ID.make("effect"),
name: Skill.Name.make("Effect"),
description: "Effect guidance",
location: AbsolutePath.make(path.resolve("/skills/effect.md")),
content: "Use Effect",
const skills = Layer.mock(Skill.Service, {
list: () =>
Effect.succeed([
Skill.Info.make({
id: Skill.ID.make("effect"),
name: Skill.Name.make("Effect"),
description: "Effect guidance",
location: AbsolutePath.make(path.resolve("/skills/effect/SKILL.md")),
content: "Use Effect",
}),
]),
})
const skills = Layer.merge(
Layer.mock(Skill.Service, {
get: (id) => Effect.succeed(id === info.id ? info : undefined),
list: () => Effect.succeed([info]),
}),
Layer.succeed(PluginSupervisor.Service, { flush: Effect.void }),
)
const locations = Layer.effect(
LocationServiceMap.Service,
LayerMap.make(
@@ -59,7 +56,7 @@ const it = testEffect(
)
describe("Session.skill", () => {
it.effect("materializes mentioned skills on their owning prompt", () =>
it.effect("keeps skill mentions as references on a normal prompt", () =>
Effect.gen(function* () {
const sessions = yield* Session.Service
const database = yield* Database.Service
@@ -70,63 +67,26 @@ describe("Session.skill", () => {
yield* sessions.prompt({
id,
sessionID: session.id,
text: "Apply @effect and @effect",
skills: [
{ id: Skill.ID.make("effect"), mention: { start: 6, end: 13, text: "@effect" } },
{ id: Skill.ID.make("effect"), mention: { start: 18, end: 25, text: "@effect" } },
],
text: "Apply @effect",
skills: [{ id: Skill.ID.make("effect"), mention: { start: 6, end: 13, text: "@effect" } }],
resume: false,
})
expect(yield* sessions.messages({ sessionID: session.id })).toEqual([])
yield* SessionInbox.promote(database.db, bus, session.id, "steer")
expect(yield* sessions.messages({ sessionID: session.id })).toEqual([
expect(yield* sessions.messages({ sessionID: session.id })).toContainEqual(
expect.objectContaining({
id,
type: "user",
text: "Apply @effect and @effect",
text: "Apply @effect",
skills: [
{
id: "effect",
name: "Effect",
text: Skill.toModelOutput(info, []),
mention: { start: 6, end: 13, text: "@effect" },
},
{
id: "effect",
name: "Effect",
mention: { start: 18, end: 25, text: "@effect" },
},
],
}),
])
}),
)
it.effect("excludes mentioned skills when forking before their prompt", () =>
Effect.gen(function* () {
const sessions = yield* Session.Service
const database = yield* Database.Service
const bus = yield* Bus.Service
const session = yield* sessions.create({ location })
const initial = SessionMessage.ID.make("msg_before_skill_attachment")
const selected = SessionMessage.ID.make("msg_fork_skill_attachment")
yield* sessions.prompt({ id: initial, sessionID: session.id, text: "Before the skill", resume: false })
yield* SessionInbox.promote(database.db, bus, session.id, "steer")
yield* sessions.prompt({
id: selected,
sessionID: session.id,
text: "Apply @effect",
skills: [{ id: info.id, mention: { start: 6, end: 13, text: "@effect" } }],
resume: false,
})
yield* SessionInbox.promote(database.db, bus, session.id, "steer")
const forked = yield* sessions.fork({ sessionID: session.id, boundary: { type: "before", messageID: selected } })
expect(yield* sessions.messages({ sessionID: forked.id })).toEqual([
expect.objectContaining({ type: "user", text: "Before the skill" }),
])
)
}),
)
-2
View File
@@ -31,8 +31,6 @@ describe("Skill", () => {
})
expect(yield* skill.list()).toEqual([info("review", "Second"), info("deploy", "Deploy")])
expect(yield* skill.get(Skill.ID.make("review"))).toEqual(info("review", "Second"))
expect(yield* skill.get(Skill.ID.make("missing"))).toBeUndefined()
}),
)
@@ -59,6 +59,7 @@ describe("SkillInstructions", () => {
[
"Skills provide specialized instructions and workflows for specific tasks.",
"Use the skill tool to load a skill when a task matches its description.",
"When the user references a skill with @skill-id, load that skill with the skill tool.",
"<available_skills>",
" <skill>",
" <id>effect</id>",
+3 -1
View File
@@ -125,7 +125,9 @@ const shellPluginSupervisor = makeLocationNode({
service: PluginSupervisor.Service,
layer: Layer.effect(
PluginSupervisor.Service,
registerToolPlugin(ShellTool.Plugin).pipe(Effect.as(PluginSupervisor.Service.of({ flush: Effect.void }))),
registerToolPlugin(ShellTool.Plugin).pipe(
Effect.as(PluginSupervisor.Service.of({ ...PluginSupervisor.noUpdates, flush: Effect.void })),
),
),
deps: [
Config.node,
-1
View File
@@ -74,7 +74,6 @@ describe("SkillTool", () => {
Skill.Service.of({
transform: (_transform) => Effect.die("unused"),
reload: () => Effect.die("unused"),
get: (id) => Effect.succeed(current.find((skill) => skill.id === id)),
list: () => Effect.succeed(current),
}),
)
+3 -1
View File
@@ -100,7 +100,9 @@ const subagentPluginSupervisor = makeLocationNode({
service: PluginSupervisor.Service,
layer: Layer.effect(
PluginSupervisor.Service,
registerToolPlugin(SubagentTool.Plugin).pipe(Effect.as(PluginSupervisor.Service.of({ flush: Effect.void }))),
registerToolPlugin(SubagentTool.Plugin).pipe(
Effect.as(PluginSupervisor.Service.of({ ...PluginSupervisor.noUpdates, flush: Effect.void })),
),
),
deps: [Agent.node, Config.node, Permission.node, PluginRuntime.node, Tool.node],
})
+1 -1
View File
@@ -31,7 +31,7 @@ export interface Context {
readonly mcp: MCPDomain
readonly generate: GenerateApi<unknown>
readonly permission: PermissionDomain
readonly plugin: PluginApi<unknown>
readonly plugin: Pick<PluginApi<unknown>, "list">
readonly reference: ReferenceDomain
readonly session: SessionDomain
readonly shell: ShellDomain
+1 -1
View File
@@ -30,7 +30,7 @@ export interface Context {
readonly mcp: MCPDomain
readonly generate: GenerateApi
readonly permission: PermissionDomain
readonly plugin: PluginApi
readonly plugin: Pick<PluginApi, "list">
readonly reference: ReferenceDomain
readonly session: SessionDomain
readonly shell: ShellDomain
+358 -3
View File
@@ -486,6 +486,306 @@
"summary": "List plugins"
}
},
"/api/plugin/update": {
"get": {
"tags": ["plugin"],
"operationId": "v2.plugin.check",
"parameters": [
{
"name": "location",
"in": "query",
"schema": {
"anyOf": [
{
"type": "object",
"properties": {
"directory": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"workspace": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
},
{
"type": "null"
}
]
},
"required": false,
"style": "deepObject",
"explode": true
}
],
"security": [],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"location": {
"$ref": "#/components/schemas/Location.InfoEncoded"
},
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Plugin.UpdateInfo"
}
}
},
"required": ["location", "data"],
"additionalProperties": false
}
}
}
},
"400": {
"description": "InvalidRequestError",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/InvalidRequestErrorEncoded"
}
}
}
},
"401": {
"description": "UnauthorizedError",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UnauthorizedErrorEncoded"
}
}
}
}
},
"description": "Check configured plugins for explicitly available updates.",
"summary": "Check plugin updates"
},
"post": {
"tags": ["plugin"],
"operationId": "v2.plugin.update",
"parameters": [
{
"name": "location",
"in": "query",
"schema": {
"anyOf": [
{
"type": "object",
"properties": {
"directory": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"workspace": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
},
{
"type": "null"
}
]
},
"required": false,
"style": "deepObject",
"explode": true
}
],
"security": [],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"location": {
"$ref": "#/components/schemas/Location.InfoEncoded"
},
"data": {
"$ref": "#/components/schemas/Plugin.UpdateResult"
}
},
"required": ["location", "data"],
"additionalProperties": false
}
}
}
},
"400": {
"description": "InvalidRequestError",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/InvalidRequestErrorEncoded"
}
}
}
},
"401": {
"description": "UnauthorizedError",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UnauthorizedErrorEncoded"
}
}
}
}
},
"description": "Explicitly update one configured plugin and reload plugins when it changes.",
"summary": "Update plugin",
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"required": ["name"],
"additionalProperties": false
}
}
},
"required": true
}
}
},
"/api/plugin/update-all": {
"post": {
"tags": ["plugin"],
"operationId": "v2.plugin.updateAll",
"parameters": [
{
"name": "location",
"in": "query",
"schema": {
"anyOf": [
{
"type": "object",
"properties": {
"directory": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"workspace": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
},
{
"type": "null"
}
]
},
"required": false,
"style": "deepObject",
"explode": true
}
],
"security": [],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"location": {
"$ref": "#/components/schemas/Location.InfoEncoded"
},
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Plugin.UpdateResult"
}
}
},
"required": ["location", "data"],
"additionalProperties": false
}
}
}
},
"400": {
"description": "InvalidRequestError",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/InvalidRequestErrorEncoded"
}
}
}
},
"401": {
"description": "UnauthorizedError",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UnauthorizedErrorEncoded"
}
}
}
}
},
"description": "Explicitly update every updateable configured plugin and reload changed plugins.",
"summary": "Update plugins"
}
},
"/api/session": {
"get": {
"tags": ["session"],
@@ -14846,6 +15146,9 @@
"name": {
"type": "string"
},
"metadata": {
"type": "object"
},
"methods": {
"type": "array",
"items": {
@@ -15356,6 +15659,9 @@
"reasoningField": {
"$ref": "#/components/schemas/Model.ReasoningField"
},
"requireReasoning": {
"type": "boolean"
},
"maxTokensField": {
"$ref": "#/components/schemas/Model.MaxTokensField"
},
@@ -15989,6 +16295,58 @@
}
]
},
"Plugin.UpdateInfo": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"source": {
"$ref": "#/components/schemas/Plugin.Source"
},
"status": {
"type": "string",
"enum": ["not-updateable", "pinned", "up-to-date", "available", "failed"]
},
"currentVersion": {
"type": "string"
},
"latestVersion": {
"type": "string"
},
"error": {
"type": "string"
}
},
"required": ["name", "source", "status"],
"additionalProperties": false
},
"Plugin.UpdateResult": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"source": {
"$ref": "#/components/schemas/Plugin.Source"
},
"status": {
"type": "string",
"enum": ["not-updateable", "pinned", "up-to-date", "updated", "failed"]
},
"previousVersion": {
"type": "string"
},
"version": {
"type": "string"
},
"error": {
"type": "string"
}
},
"required": ["name", "source", "status"],
"additionalProperties": false
},
"Project": {
"type": "object",
"properties": {
@@ -16200,9 +16558,6 @@
"name": {
"type": "string"
},
"text": {
"type": "string"
},
"mention": {
"$ref": "#/components/schemas/Prompt.Mention"
}
+43
View File
@@ -19,6 +19,49 @@ export const PluginGroup = HttpApiGroup.make("server.plugin")
}),
),
)
.add(
HttpApiEndpoint.get("plugin.check", "/api/plugin/update", {
query: LocationQuery,
success: Location.response(Schema.Array(Plugin.UpdateInfo)),
})
.annotateMerge(locationQueryOpenApi)
.annotateMerge(
OpenApi.annotations({
identifier: "v2.plugin.check",
summary: "Check plugin updates",
description: "Check configured plugins for explicitly available updates.",
}),
),
)
.add(
HttpApiEndpoint.post("plugin.update", "/api/plugin/update", {
payload: Schema.Struct({ name: Schema.String }),
query: LocationQuery,
success: Location.response(Plugin.UpdateResult),
})
.annotateMerge(locationQueryOpenApi)
.annotateMerge(
OpenApi.annotations({
identifier: "v2.plugin.update",
summary: "Update plugin",
description: "Explicitly update one configured plugin and reload plugins when it changes.",
}),
),
)
.add(
HttpApiEndpoint.post("plugin.updateAll", "/api/plugin/update-all", {
query: LocationQuery,
success: Location.response(Schema.Array(Plugin.UpdateResult)),
})
.annotateMerge(locationQueryOpenApi)
.annotateMerge(
OpenApi.annotations({
identifier: "v2.plugin.updateAll",
summary: "Update plugins",
description: "Explicitly update every updateable configured plugin and reload changed plugins.",
}),
),
)
.annotateMerge(
OpenApi.annotations({
title: "plugin",
+20
View File
@@ -32,6 +32,26 @@ export const Info = Schema.Union([
]).annotate({ identifier: "Plugin.Info" })
export type Info = typeof Info.Type
export interface UpdateInfo extends Schema.Schema.Type<typeof UpdateInfo> {}
export const UpdateInfo = Schema.Struct({
name: Schema.String,
source: Source,
status: Schema.Literals(["not-updateable", "pinned", "up-to-date", "available", "failed"]),
currentVersion: Schema.String.pipe(optional),
latestVersion: Schema.String.pipe(optional),
error: Schema.String.pipe(optional),
}).annotate({ identifier: "Plugin.UpdateInfo" })
export interface UpdateResult extends Schema.Schema.Type<typeof UpdateResult> {}
export const UpdateResult = Schema.Struct({
name: Schema.String,
source: Source,
status: Schema.Literals(["not-updateable", "pinned", "up-to-date", "updated", "failed"]),
previousVersion: Schema.String.pipe(optional),
version: Schema.String.pipe(optional),
error: Schema.String.pipe(optional),
}).annotate({ identifier: "Plugin.UpdateResult" })
const Added = ephemeral({
type: "plugin.added",
schema: { id: ID },
-1
View File
@@ -57,7 +57,6 @@ export interface SkillAttachment extends Schema.Schema.Type<typeof SkillAttachme
export const SkillAttachment = Schema.Struct({
id: Skill.ID,
name: Skill.Name,
text: Schema.String.pipe(optional),
mention: PromptMention.pipe(optional),
}).annotate({ identifier: "Prompt.SkillAttachment" })
+12 -31
View File
@@ -57,46 +57,27 @@ const Resolved = durable({
projectID: Project.ID,
directory: AbsolutePath,
previous: Project.ID,
adopted: optional(Schema.Array(Project.ID)),
},
})
export const Event = { Updated, Resolved, Definitions: inventory(Updated, Resolved) }
export function adopt(
session: { readonly projectID: string; readonly directory: string; readonly workspaceID?: string },
event: {
readonly projectID: string
readonly directory: string
readonly previous: string
readonly adopted?: ReadonlyArray<string>
},
session: { readonly projectID: string; readonly directory: string },
event: { readonly projectID: string; readonly directory: string; readonly previous: string },
) {
if (session.workspaceID) return
if (
session.projectID !== event.previous &&
session.projectID !== Project.ID.global &&
!event.adopted?.includes(session.projectID)
)
return
if (session.projectID !== event.previous && session.projectID !== Project.ID.global) return
if (session.projectID === event.projectID) return
const normalize = (value: string) =>
value
.replaceAll("\\", "/")
.split("/")
.reduce((result, segment) => {
if (!segment || segment === ".") return result
if (segment === "..") return result.slice(0, result.lastIndexOf("/"))
return `${result}/${segment}`
}, "")
const directory = normalize(session.directory)
const root = normalize(event.directory)
const windows = /^\/[a-z]:/i.test(root)
const key = windows ? directory.toLowerCase() : directory
const parent = windows ? root.toLowerCase() : root
if (key !== parent && !key.startsWith(parent + "/")) return
const inside =
session.directory === event.directory ||
session.directory.startsWith(event.directory + "/") ||
session.directory.startsWith(event.directory + "\\")
if (!inside) return
return {
projectID: event.projectID,
subpath: key === parent ? undefined : directory.slice(root.length + 1),
subpath:
session.directory === event.directory
? undefined
: session.directory.slice(event.directory.length + 1).replaceAll("\\", "/"),
}
}
@@ -6,7 +6,6 @@ import { Form } from "../src/form.js"
import { Mcp } from "../src/mcp.js"
import { Model } from "../src/model.js"
import { Project } from "../src/project.js"
import { SkillAttachment } from "../src/prompt.js"
import { Provider } from "../src/provider.js"
import { Pty } from "../src/pty.js"
import { Session } from "../src/session.js"
@@ -80,16 +79,6 @@ describe("contract hygiene", () => {
).toEqual({ created: 0, updated: 0, idle: 2, viewed: 1 })
})
test("skill attachments retain legacy references while accepting prepared instructions", () => {
const reference = { id: Skill.ID.make("effect"), name: Skill.Name.make("Effect") }
expect(Schema.decodeUnknownSync(SkillAttachment)(reference)).toEqual(reference)
expect(Schema.encodeSync(SkillAttachment)({ ...reference, text: undefined })).toEqual(reference)
expect(Schema.decodeUnknownSync(SkillAttachment)({ ...reference, text: "Use Effect" })).toEqual({
...reference,
text: "Use Effect",
})
})
test("session inbox items omit the internal enqueue sequence", () => {
expect(
Schema.encodeSync(SessionInbox.Info)(
+8 -6
View File
@@ -1,13 +1,15 @@
import { Plugin } from "@opencode-ai/core/plugin"
import { Effect } from "effect"
import { PluginSupervisor } from "@opencode-ai/core/plugin/supervisor"
import { HttpApiBuilder } from "effect/unstable/httpapi"
import { Api } from "../api"
import { response } from "../location"
export const PluginHandler = HttpApiBuilder.group(Api, "server.plugin", (handlers) =>
handlers.handle("plugin.list", () =>
Effect.gen(function* () {
return yield* response(Plugin.Service.use((plugin) => plugin.list()))
}),
),
handlers
.handle("plugin.list", () => response(Plugin.Service.use((plugin) => plugin.list())))
.handle("plugin.check", () => response(PluginSupervisor.Service.use((plugins) => plugins.check())))
.handle("plugin.update", (ctx) =>
response(PluginSupervisor.Service.use((plugins) => plugins.update(ctx.payload.name))),
)
.handle("plugin.updateAll", () => response(PluginSupervisor.Service.use((plugins) => plugins.updateAll()))),
)
+29
View File
@@ -96,6 +96,35 @@ it.live("serves unauthenticated and answers CORS preflight when no password is c
}).pipe(Effect.scoped),
)
it.live("serves plugin update operations through the HttpApi", () =>
Effect.gen(function* () {
const handler = yield* ServerFetch.make(options)
const check = yield* Effect.promise(() => handler(new Request("http://opencode.local/api/plugin/update")))
expect(check.status).toBe(200)
expect(yield* Effect.promise(() => check.json())).toMatchObject({ data: expect.any(Array) })
const update = yield* Effect.promise(() =>
handler(
new Request("http://opencode.local/api/plugin/update", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ name: "missing-plugin" }),
}),
),
)
expect(update.status).toBe(200)
expect(yield* Effect.promise(() => update.json())).toMatchObject({
data: { name: "missing-plugin", status: "failed", error: "Plugin not found" },
})
const updateAll = yield* Effect.promise(() =>
handler(new Request("http://opencode.local/api/plugin/update-all", { method: "POST" })),
)
expect(updateAll.status).toBe(200)
expect(yield* Effect.promise(() => updateAll.json())).toMatchObject({ data: expect.any(Array) })
}).pipe(Effect.scoped),
)
it.live("cancels a stale OpenAI OAuth callback server before falling back", () =>
Effect.gen(function* () {
const requests: string[] = []
@@ -50,9 +50,12 @@ test("plugin readiness stays lazy and resolves the supervisor for every executio
() => new ServiceUnavailableError({ message: "initialization timed out", service: "test" }),
)
const layer = Layer.succeed(PluginSupervisor.Service, {
check: () => Effect.succeed([]),
flush: Effect.sync(() => {
flushes++
}),
update: () => Effect.die("unused"),
updateAll: () => Effect.succeed([]),
})
expect(flushes).toBe(0)
+2 -2
View File
@@ -614,7 +614,7 @@ function App(props: { pair?: DialogPairCredentials }) {
return
}
renderer.setTerminalTitle(`OC | ${title.length > 40 ? title.slice(0, 37) + "" : title}`)
renderer.setTerminalTitle(`OC | ${title.length > 40 ? title.slice(0, 37) + "..." : title}`)
return
}
@@ -971,7 +971,7 @@ function App(props: { pair?: DialogPairCredentials }) {
const restart = client.restart
if (!restart) return
dialog.clear()
toast.show({ variant: "info", message: "Restarting service", duration: 30000 })
toast.show({ variant: "info", message: "Restarting service...", duration: 30000 })
// restart resolves once the replacement service is healthy; the
// event stream reattaches through the reconnect loop.
await restart()
+2 -10
View File
@@ -86,15 +86,7 @@ export function DevToolsBar() {
const offEscape = keymap.intercept(
"key",
({ event }) => {
if (!panel() || keymap.mode.current() !== "base") return
if (event.name !== "escape" && !(event.ctrl && event.name === "c")) return
if (renderer.getSelection()?.getSelectedText()) {
if ((config.data.terminal?.copy ?? (process.platform === "win32" ? "manual" : "select")) !== "select") return
renderer.clearSelection()
event.preventDefault()
event.stopPropagation()
return
}
if (!panel() || event.name !== "escape") return
event.preventDefault()
event.stopPropagation()
close()
@@ -360,7 +352,7 @@ export function DevToolsBar() {
<PanelBox>
<PanelTitle>Tools</PanelTitle>
<Action onClick={() => void dump()} disabled={dumping()} hoverBackground>
{dumping() ? "Writing debug snapshot" : "Write debug snapshot"}
{dumping() ? "Writing debug snapshot..." : "Write debug snapshot"}
</Action>
<Show when={dumpPath()}>
{(file) => (
@@ -3,22 +3,13 @@ import { useKeyboard, useRenderer, useTerminalDimensions } from "@opentui/solid"
import { createEffect, createMemo, createSignal, onCleanup } from "solid-js"
import { useConfig } from "../config"
import { useClipboard } from "../context/clipboard"
import { useData } from "../context/data"
import { Keymap } from "../context/keymap"
import { useLocation } from "../context/location"
import { useRoute } from "../context/route"
import { getScrollAcceleration } from "../util/scroll"
import { useTheme } from "../context/theme"
import { emptyPrompt } from "../prompt/history"
import { useDialog } from "../ui/dialog"
import { useToast } from "../ui/toast"
export function DialogErrorDetails(props: { title: string; error: string; onBack: () => void }) {
const clipboard = useClipboard()
const data = useData()
const dialog = useDialog()
const location = useLocation()
const route = useRoute()
const toast = useToast()
const theme = useTheme("elevated")
const overlayTheme = useTheme("overlay")
@@ -58,25 +49,11 @@ export function DialogErrorDetails(props: { title: string; error: string; onBack
.catch(toast.error)
}
const investigate = () => {
const target = location.ref ?? data.location.default()
route.navigate({
type: "home",
location: target,
prompt: {
...emptyPrompt(),
text: `Investigate this OpenCode failure in ${target.directory}.\n\n${props.title}\n${props.error}\n\nInspect the relevant configuration and logs, identify the root cause, and suggest a fix.`,
},
})
dialog.clear()
}
Keymap.createLayer(() => ({
mode: "modal",
commands: [
{ bind: "escape", title: "Back", group: "Dialog", run: props.onBack },
{ bind: "c", title: "Copy details", group: "Dialog", run: copy },
{ bind: "i", title: "Investigate error", group: "Dialog", run: investigate },
],
}))
@@ -125,20 +102,12 @@ export function DialogErrorDetails(props: { title: string; error: string; onBack
</span>
<span style={{ fg: theme.text.subdued }}>{scrollable() ? " scroll" : ""}</span>
</text>
<box flexDirection="row" gap={3}>
<text onMouseUp={investigate}>
<span style={{ fg: theme.text.default }}>
<b>i</b>
</span>
<span style={{ fg: theme.text.subdued }}> investigate</span>
</text>
<text onMouseUp={copy}>
<span style={{ fg: copied() ? theme.text.feedback.success.default : theme.text.default }}>
<b>{copied() ? "✓ copied" : "c"}</b>
</span>
<span style={{ fg: theme.text.subdued }}>{copied() ? "" : " copy details"}</span>
</text>
</box>
<text onMouseUp={copy}>
<span style={{ fg: copied() ? theme.text.feedback.success.default : theme.text.default }}>
<b>{copied() ? "✓ copied" : "c"}</b>
</span>
<span style={{ fg: theme.text.subdued }}>{copied() ? "" : " copy details"}</span>
</text>
</box>
</box>
)
@@ -352,7 +352,7 @@ function CommandStarting(props: {
if (!handedOff) closed = true
})
return <CommandView title={props.method.label} output="" message="Starting command" />
return <CommandView title={props.method.label} output="" message="Starting command..." />
}
function CommandPending(props: {
@@ -412,7 +412,7 @@ function CommandPending(props: {
})
})
return <CommandView title={props.title} output={output()} message="Waiting for command to finish" />
return <CommandView title={props.title} output={output()} message="Waiting for command to finish..." />
}
function CommandView(props: { title: string; output: string; message: string }) {
@@ -541,7 +541,7 @@ function OAuthStarting(props: {
})
})
return <OAuthView title={props.method.label} message="Starting authorization" />
return <OAuthView title={props.method.label} message="Starting authorization..." />
}
function OAuthAuto(props: {
@@ -629,7 +629,7 @@ function OAuthAuto(props: {
title={props.title}
url={props.attempt.url}
instructions={props.attempt.instructions}
message="Waiting for authorization"
message="Waiting for authorization..."
copy
open
/>
@@ -953,7 +953,7 @@ async function externalAnswer(
if (choice === true) return true
const result = await new Promise<boolean | typeof CANCELLED>((resolve) => {
dialog.replace(
() => <OAuthView title={formLabel(field) || title} message="Opening link" />,
() => <OAuthView title={formLabel(field) || title} message="Opening link..." />,
() => resolve(CANCELLED),
)
void open(field.url).then(
@@ -237,7 +237,7 @@ function buildIssueURL(message: string, stack: string, version: string) {
// clipped trace is obvious. searchParams.set handles encoding without throwing,
// so measuring url.toString() is both correct and safe on any input.
const MAX_URL_LENGTH = 6000
const marker = "\n (truncated)"
const marker = "\n... (truncated)"
const head = `The OpenCode TUI crashed with an unexpected error.\n\n**Error:** ${message}\n\n**Stack trace:**\n`
const setBody = (body: string) => url.searchParams.set("description", head + "```\n" + body + "\n```")
@@ -759,14 +759,6 @@ export function Autocomplete(props: {
hide()
},
},
{
id: "prompt.clear",
title: "Dismiss autocomplete",
group: "Autocomplete",
run() {
hide(true)
},
},
{
id: "prompt.autocomplete.select",
title: "Select autocomplete item",
+3 -13
View File
@@ -987,19 +987,9 @@ export function Prompt(props: PromptProps) {
Keymap.createLayer(() => {
return {
priority: 1,
target: inputTarget,
enabled: inputTarget() !== undefined && store.mode === "shell",
commands: [
{ bind: "escape", title: "Exit shell mode", group: "Prompt", run: () => setStore("mode", "normal") },
{
bind: "ctrl+c",
title: "Exit shell mode",
group: "Prompt",
enabled: () => store.prompt.text === "",
run: () => setStore("mode", "normal"),
},
],
commands: [{ bind: "escape", title: "Exit shell mode", group: "Prompt", run: () => setStore("mode", "normal") }],
}
})
@@ -1641,10 +1631,10 @@ export function Prompt(props: PromptProps) {
const value = (() => {
if (store.mode === "shell") {
if (!shell().length) return undefined
return `Run a command "${shell()[store.placeholder % shell().length]}"`
return `Run a command... "${shell()[store.placeholder % shell().length]}"`
}
if (!list().length) return undefined
return `Ask anything "${list()[store.placeholder % list().length]}"`
return `Ask anything... "${list()[store.placeholder % list().length]}"`
})()
if (!value) return undefined
const width = dimensions().width < 44 ? dimensions().width - 5 : Math.min(75, dimensions().width - 4) - 5
+1 -1
View File
@@ -28,7 +28,7 @@ export function Reconnecting(props: { managed?: boolean }) {
paddingRight={2}
gap={1}
>
<Spinner color={theme.text.default}>{props.managed ? "Restarting service" : "Connection lost"}</Spinner>
<Spinner color={theme.text.default}>{props.managed ? "Restarting service..." : "Connection lost..."}</Spinner>
<text fg={theme.text.subdued}>
{props.managed
? "Your session will resume automatically."
+1 -12
View File
@@ -38,7 +38,6 @@ import { projectName } from "../util/project"
import { marqueeCycleWidth, marqueeOverflows, marqueeTextParts } from "../util/marquee"
import { useDialog } from "../ui/dialog"
import { DialogSessionRename } from "./dialog-session-rename"
import { Keymap } from "../context/keymap"
// A long title fades out over its last cells instead of cutting hard.
const FADE_WIDTH = 4
@@ -267,11 +266,6 @@ function TabContextMenu(props: { state: TabContextMenuState; tabs: SessionTabsCo
const dimensions = useTerminalDimensions()
const theme = useTheme("elevated")
const dialog = useDialog()
onCleanup(Keymap.use().mode.push("menu"))
Keymap.createLayer(() => ({
mode: "menu",
commands: [{ bind: "escape,ctrl+c", title: "Close tab menu", group: "Tabs", run: props.onClose }],
}))
const actions = createMemo(() => {
const sessionID = props.state.sessionID
return [
@@ -1056,12 +1050,7 @@ function HorizontalSessionTabs(props: { controller?: SessionTabsController; anim
if (closeHold() && heldLayout()) {
const current = untrack(motion.value)
const seeded = changed
? seedSessionTabMotion(
previous.split(":"),
layout().tabs.map((tab) => tab.sessionID),
current,
next,
)
? seedSessionTabMotion(previous.split(":"), layout().tabs.map((tab) => tab.sessionID), current, next)
: current
if (!seeded) return motion.jump(next)
motion.jump({ ...seeded, widths: next.widths })
@@ -5,7 +5,7 @@ import { Spinner } from "./spinner"
export function StartupLoading(props: { ready: () => boolean }) {
const theme = useTheme("elevated")
const [show, setShow] = createSignal(false)
const text = createMemo(() => (props.ready() ? "Finishing startup" : "Loading plugins"))
const text = createMemo(() => (props.ready() ? "Finishing startup..." : "Loading plugins..."))
let wait: NodeJS.Timeout | undefined
let hold: NodeJS.Timeout | undefined
let stamp = 0
+2
View File
@@ -258,6 +258,8 @@ export const Definitions = {
"plugins.toggle": keybind("space", "Toggle plugin"),
"dialog.mcp.toggle": keybind("space", "Toggle MCP server"),
"dialog.plugins.install": keybind("shift+i", "Install plugin from plugin dialog"),
"dialog.plugins.update": keybind("ctrl+r", "Update selected plugin"),
"dialog.plugins.update_all": keybind("ctrl+shift+r", "Update all plugins"),
"terminal.suspend": keybind("ctrl+z", "Suspend terminal"),
"terminal.title.toggle": keybind("none", "Toggle terminal title"),
@@ -423,12 +423,6 @@ function DiffViewer(props: { context: Plugin.Context }) {
group: "VCS",
run: close,
},
{
id: "app.exit",
title: "Close diff viewer",
group: "VCS",
run: close,
},
{
id: "diff.down",
title: "Move diff viewer down",
@@ -0,0 +1,19 @@
import type { PluginInfo, PluginUpdateInfo, PluginUpdateResult } from "@opencode-ai/client"
export type UpdateEntry = PluginUpdateInfo | PluginUpdateResult
export function matchesPluginUpdate(plugin: PluginInfo, update: UpdateEntry) {
if (plugin.source.type !== update.source.type) return false
if (plugin.source.type === "package" && update.source.type === "package") {
return plugin.source.package === update.source.package
}
if (plugin.source.type === "local" && update.source.type === "local") return plugin.source.path === update.source.path
return plugin.id === update.name
}
export function pluginServerKey(plugin: PluginInfo) {
if (plugin.id) return `server:${plugin.id}`
if (plugin.source.type === "package") return `server:package:${plugin.source.package}`
if (plugin.source.type === "local") return `server:local:${plugin.source.path}`
return `server:${plugin.source.type}`
}
@@ -1,15 +1,17 @@
import type { PluginInfo } from "@opencode-ai/client"
import type { PluginInfo, PluginUpdateInfo, PluginUpdateResult } from "@opencode-ai/client"
import { Plugin } from "@opencode-ai/plugin/tui"
import { createEffect, createMemo, createResource, createSignal, onMount, Show } from "solid-js"
import { DialogErrorDetails } from "../../component/dialog-error-details"
import { usePlugin } from "../../plugin/context"
import { DialogSelect, type DialogSelectOption } from "../../ui/dialog-select"
import { useDialog } from "../../ui/dialog"
import { errorMessage } from "../../util/error"
import { matchesPluginUpdate, pluginServerKey, type UpdateEntry } from "./plugins-model"
const id = "opencode.plugins"
type Entry =
| { readonly key: string; readonly runtime: "server"; readonly plugin: PluginInfo }
| { readonly key: string; readonly runtime: "server"; readonly plugin: PluginInfo; readonly update?: UpdateEntry }
| {
readonly key: string
readonly runtime: "tui"
@@ -19,21 +21,47 @@ type Entry =
readonly error?: string
}
type PluginUpdateOperations = {
check(): Promise<readonly PluginUpdateInfo[]>
update(name: string): Promise<PluginUpdateResult>
updateAll(): Promise<readonly PluginUpdateResult[]>
}
export type PluginRegistry = Pick<ReturnType<typeof usePlugin>, "registered" | "list" | "activate" | "deactivate">
export function PluginsDialog(props: {
context: Plugin.Context
plugins: ReturnType<typeof usePlugin>
plugins: PluginRegistry
server?: () => readonly PluginInfo[]
updates?: PluginUpdateOperations
}) {
const dialog = useDialog()
const [locked, setLocked] = createSignal(false)
const [focused, setFocused] = createSignal<string>()
const [detail, setDetail] = createSignal<Entry>()
const [initial, setInitial] = createSignal<string>()
const [server] = createResource(
() => (props.server ? undefined : (props.context.location ?? props.context.data.location.default())),
const [checking, setChecking] = createSignal(true)
const [operationError, setOperationError] = createSignal(false)
const [updateEntries, setUpdateEntries] = createSignal<readonly UpdateEntry[]>([])
const [updating, setUpdating] = createSignal<string>()
const location = () => props.context.location ?? props.context.data.location.default()
const operations: PluginUpdateOperations = props.updates ?? {
check: () => props.context.client.plugin.check({ location: location() }).then((result) => result.data),
update: (name) => props.context.client.plugin.update({ name, location: location() }).then((result) => result.data),
updateAll: () => props.context.client.plugin.updateAll({ location: location() }).then((result) => result.data),
}
const [server, { refetch: refetchServer }] = createResource(
() => (props.server ? undefined : location()),
(location) => props.context.client.plugin.list({ location }).then((result) => result.data),
)
onMount(() => dialog.setSize("medium"))
onMount(() => {
dialog.setSize("medium")
void operations
.check()
.then(setUpdateEntries)
.catch(() => setOperationError(true))
.finally(() => setChecking(false))
})
const entries = createMemo<Entry[]>(() => {
const builtins: Entry[] = props.plugins
.registered()
@@ -56,10 +84,12 @@ export function PluginsDialog(props: {
status: plugin.status,
error: plugin.status === "failed" ? plugin.error : undefined,
}))
const serverEntries: Entry[] = (props.server?.() ?? server() ?? []).map((plugin) => ({
key: `server:${plugin.id ?? source(plugin, props.context)}`,
runtime: "server" as const,
const runtime = props.server?.() ?? server() ?? []
const serverEntries: Entry[] = runtime.map((plugin) => ({
key: pluginServerKey(plugin),
runtime: "server",
plugin,
update: updateEntries().find((update) => matchesPluginUpdate(plugin, update)),
}))
return [
...[...builtins, ...external].sort((a, b) => label(a, props.context).localeCompare(label(b, props.context))),
@@ -81,11 +111,15 @@ export function PluginsDialog(props: {
value: entry.key,
category: entry.runtime === "tui" ? "TUI" : "Server",
searchText: entry.runtime === "tui" ? entry.target : source(entry.plugin, props.context),
footer: status(entry) === "active" ? undefined : status(entry),
footer: statusLabel(entry, checking(), updating()),
footerColor:
status(entry) === "failed"
status(entry) === "failed" || updateStatus(entry) === "failed"
? props.context.theme.text.feedback.error.default
: props.context.theme.text.subdued,
: updateStatus(entry) === "updated" || updateStatus(entry) === "up-to-date"
? props.context.theme.text.feedback.success.default
: updateStatus(entry) === "available"
? props.context.theme.text.feedback.info.default
: props.context.theme.text.subdued,
gutter:
status(entry) === "active"
? () => <text fg={props.context.theme.text.feedback.success.default}></text>
@@ -96,6 +130,11 @@ export function PluginsDialog(props: {
),
)
const focusedEntry = createMemo(() => entries().find((entry) => entry.key === focused()))
const focusedUpdate = createMemo(() => {
const entry = focusedEntry()
if (entry?.runtime !== "server") return
return entry.update
})
const focusedTui = createMemo(() => {
const entry = focusedEntry()
if (entry?.runtime !== "tui" || !entry.id) return
@@ -119,11 +158,38 @@ export function PluginsDialog(props: {
.catch((cause) => {
props.context.ui.toast.show({
variant: "error",
message: cause instanceof Error ? cause.message : String(cause),
message: errorMessage(cause),
})
})
.finally(() => setLocked(false))
}
const runUpdate = (updating: string, operation: () => Promise<void>) => {
if (locked()) return
setLocked(true)
setUpdating(updating)
setOperationError(false)
void operation()
.catch((cause) => {
setOperationError(true)
props.context.ui.toast.show({ variant: "error", message: errorMessage(cause) })
})
.finally(() => {
setUpdating()
setLocked(false)
})
}
const update = (name: string) =>
runUpdate(name, async () => {
const result = await operations.update(name)
setUpdateEntries((current) => current.map((entry) => (entry.name === name ? result : entry)))
if (!props.server && result.status === "updated") await refetchServer()
})
const updateAll = () =>
runUpdate("*", async () => {
const results = await operations.updateAll()
setUpdateEntries(results)
if (!props.server && results.some((result) => result.status === "updated")) await refetchServer()
})
return (
<box>
@@ -141,19 +207,47 @@ export function PluginsDialog(props: {
const entry = entries().find((entry) => entry.key === option.value)
if (pluginError(entry)) setDetail(entry)
}}
actions={
focusedTui()
actions={[
...(focusedTui()
? [
{
title: toggleTitle(),
command: "plugins.toggle",
onTrigger: (option) => toggle(entries().find((entry) => entry.key === option.value)),
onTrigger: (option: DialogSelectOption<string>) =>
toggle(entries().find((entry) => entry.key === option.value)),
},
]
: []
}
: []),
...(focusedUpdate()?.status === "available"
? [
{
title: "update",
command: "dialog.plugins.update",
onTrigger: (_option: DialogSelectOption<string>) => update(focusedUpdate()!.name),
},
]
: []),
...(updateEntries().some((entry) => entry.status === "available")
? [
{
title: "update all",
command: "dialog.plugins.update_all",
selection: "none" as const,
side: "right" as const,
onTrigger: updateAll,
},
]
: []),
]}
footer={
<Show when={pluginError(focusedEntry())}>
<Show
when={pluginError(focusedEntry())}
fallback={
<Show when={operationError()}>
<text fg={props.context.theme.text.feedback.error.default}>Plugin update failed</text>
</Show>
}
>
<text>
<span style={{ fg: props.context.theme.text.default }}>
<b>enter</b>
@@ -196,8 +290,35 @@ function status(entry: Entry) {
return entry.status
}
function updateStatus(entry: Entry) {
if (entry.runtime !== "server") return
return entry.update?.status
}
function statusLabel(entry: Entry, checking: boolean, updating: string | undefined) {
if (entry.runtime === "tui") return status(entry) === "active" ? undefined : status(entry)
const update = entry.update
if (updating === "*" || (update && updating === update.name)) return "updating …"
if (entry.plugin.status === "failed") return "failed"
if (!update) return checking ? "checking …" : undefined
if (update.status === "not-updateable") return update.source.type === "local" ? "local" : undefined
const currentVersion =
"currentVersion" in update ? update.currentVersion : "version" in update ? update.version : undefined
if (update.status === "pinned") return currentVersion ? `${currentVersion} pinned` : "pinned"
if (update.status === "up-to-date") return currentVersion ? `${currentVersion} up to date` : "up to date"
if (update.status === "available") {
return `${update.currentVersion ?? "installed"}${update.latestVersion ?? "update available"}`
}
if (update.status === "updated") return `${update.previousVersion ?? "installed"}${update.version ?? "updated"}`
return "failed"
}
function pluginError(entry: Entry | undefined) {
if (entry?.runtime === "server") return entry.plugin.status === "failed" ? entry.plugin.error : undefined
if (entry?.runtime === "server") {
if (entry.plugin.status === "failed") return entry.plugin.error
if (entry.update?.status === "failed") return entry.update.error
return
}
return entry?.error
}
@@ -3,6 +3,7 @@ import { useTerminalDimensions } from "@opentui/solid"
import { createSignal, For, type JSX } from "solid-js"
import { StoryFooter } from "./footer"
import { mermanLayoutsStory } from "./merman-layouts"
import { pluginUpdatesStory } from "./plugin-updates"
import { sessionTabsStory } from "./session-tabs"
import { sessionLocationMissingStory } from "./session-location-missing"
@@ -16,7 +17,7 @@ export type Story = {
render: (context: Plugin.Context) => JSX.Element
}
const stories: Story[] = [mermanLayoutsStory, sessionTabsStory, sessionLocationMissingStory]
const stories: Story[] = [mermanLayoutsStory, sessionTabsStory, sessionLocationMissingStory, pluginUpdatesStory]
function Commands(props: { context: Plugin.Context }) {
props.context.keymap.layer(() => ({
@@ -0,0 +1,184 @@
import type { PluginInfo, PluginUpdateInfo, PluginUpdateResult } from "@opencode-ai/client"
import type { Plugin } from "@opencode-ai/plugin/tui"
import { useTerminalDimensions } from "@opentui/solid"
import { onMount } from "solid-js"
import { PluginsDialog, type PluginRegistry } from "../plugins"
import type { Story } from "./index"
import { StoryFooter } from "./footer"
const server: PluginInfo[] = [
{
id: "fixture.analytics",
source: { type: "package", package: "@fixture/analytics@latest" },
status: "active",
tui: false,
},
{
id: "fixture.theme",
source: { type: "package", package: "@fixture/theme@2.4.0" },
status: "active",
tui: false,
},
{
id: "fixture.local",
source: { type: "local", path: "/fixture/plugins/local.ts" },
status: "active",
tui: false,
},
{
source: { type: "package", package: "@fixture/broken@latest" },
status: "failed",
error: "Plugin entrypoint could not be loaded",
tui: false,
},
]
const initial = (): PluginUpdateInfo[] => [
{
name: "@fixture/analytics@latest",
source: { type: "package", package: "@fixture/analytics@latest" },
status: "available",
currentVersion: "1.8.0",
latestVersion: "1.9.0",
},
{
name: "@fixture/theme@2.4.0",
source: { type: "package", package: "@fixture/theme@2.4.0" },
status: "pinned",
currentVersion: "2.4.0",
},
{
name: "/fixture/plugins/local.ts",
source: { type: "local", path: "/fixture/plugins/local.ts" },
status: "not-updateable",
},
{
name: "@fixture/broken@latest",
source: { type: "package", package: "@fixture/broken@latest" },
status: "failed",
error: "Registry request failed with status 503",
},
]
const plugins: PluginRegistry = {
registered: () => [{ id: "fixture.ui", source: "builtin", active: true }],
list: () => [],
activate: async () => true,
deactivate: async () => true,
}
function PluginUpdatesStory(props: { context: Plugin.Context }) {
const dimensions = useTerminalDimensions()
const theme = props.context.theme.contextual.elevated
let fixture = initial()
const wait = () => new Promise<void>((resolve) => setTimeout(resolve, 500))
const open = () =>
props.context.ui.dialog.show(() => (
<PluginsDialog
context={props.context}
plugins={plugins}
server={() => server}
updates={{
async check() {
await wait()
return fixture
},
async update(name) {
await wait()
const current = fixture.find((entry) => entry.name === name)
const result: PluginUpdateResult = {
name,
source: current?.source ?? { type: "package", package: name },
status: "updated",
previousVersion: current?.currentVersion,
version: current?.latestVersion,
}
fixture = fixture.map((entry) =>
entry.name === name ? { ...entry, status: "up-to-date", currentVersion: entry.latestVersion } : entry,
)
return result
},
async updateAll() {
await wait()
const results: PluginUpdateResult[] = fixture.map((entry) =>
entry.status === "available"
? {
name: entry.name,
source: entry.source,
status: "updated",
previousVersion: entry.currentVersion,
version: entry.latestVersion,
}
: {
name: entry.name,
source: entry.source,
status: entry.status,
version: entry.currentVersion,
error: entry.error,
},
)
fixture = initial().map((entry) =>
entry.status === "available"
? { ...entry, status: "up-to-date", currentVersion: entry.latestVersion }
: entry,
)
return results
},
}}
/>
))
props.context.keymap.layer(() => ({
commands: [
{
bind: "escape",
title: "Back to storybook",
group: "Storybook",
run: () => props.context.ui.router.navigate({ type: "plugin", name: "storybook" }),
},
{ bind: "return", title: "Open plugin controls", group: "Storybook", run: open },
{
bind: "r",
title: "Reset plugin controls",
group: "Storybook",
run() {
fixture = initial()
open()
},
},
],
}))
onMount(open)
return (
<box
width={dimensions().width}
height={dimensions().height}
flexDirection="column"
backgroundColor={theme.background.default}
>
<box flexGrow={1} paddingLeft={2} paddingTop={1}>
<text fg={theme.text.default}>Plugin update controls fixture</text>
<text fg={theme.text.subdued}>The production Plugins dialog opens automatically.</text>
</box>
<StoryFooter
context={props.context}
title="storybook / plugin updates"
status="fixture API · 500ms operations"
controls={[
{ shortcut: "enter", label: "open" },
{ shortcut: "r", label: "reset" },
{ shortcut: "esc", label: "back" },
]}
/>
</box>
)
}
export const pluginUpdatesStory: Story = {
id: "plugin-updates",
title: "Plugin update controls",
render: (context) => <PluginUpdatesStory context={context} />,
}
+13 -21
View File
@@ -190,9 +190,6 @@ function pendingPrompt(item: SessionInboxInfo): FooterQueuedPrompt | undefined {
messageID: item.id,
prompt: { messageID: item.id, text: item.payload.text, parts: [] },
delivery: item.delivery,
...(item.payload.skills?.length
? { skills: item.payload.skills.map((skill) => ({ id: skill.id, name: skill.name })) }
: {}),
}
}
@@ -391,12 +388,6 @@ function skillCommit(messageID: string, name: string, skillID = messageID): Stre
}
}
function skillCommits(messageID: string, skills: FooterQueuedPrompt["skills"] = []) {
return Array.from(new Map(skills.map((skill) => [skill.id, skill])).values(), (skill) =>
skillCommit(messageID, skill.name, skill.id),
)
}
function compactionCommit(messageID: string): StreamCommit {
return {
kind: "system",
@@ -676,7 +667,7 @@ export async function createSessionTransport(input: StreamInput): Promise<Sessio
if (!render) return
if (reuseVisibleWait && waiting) return
write([
...skillCommits(message.id, message.skills),
...(message.skills ?? []).map((skill) => skillCommit(message.id, skill.name, skill.id)),
{ kind: "user", source: "system", text: message.text, phase: "start", messageID: message.id },
])
return
@@ -965,16 +956,18 @@ export async function createSessionTransport(input: StreamInput): Promise<Sessio
syncPending()
const visible = state.messageIDs.has(event.data.inboxID)
if (waiting || pending) state.messageIDs.add(event.data.inboxID)
const commits = pending && !visible ? skillCommits(event.data.inboxID, pending.skills) : []
if (!waiting && pending && !visible)
commits.push({
kind: "user",
source: "system",
text: pending.prompt.text,
phase: "start",
messageID: event.data.inboxID,
})
write(commits, { phase: "running", status: "waiting for assistant" })
if (!waiting && pending && !visible) {
write([
{
kind: "user",
source: "system",
text: pending.prompt.text,
phase: "start",
messageID: event.data.inboxID,
},
])
}
write([], { phase: "running", status: "waiting for assistant" })
return
}
if (event.type === "session.inbox.delivery.changed") {
@@ -986,7 +979,6 @@ export async function createSessionTransport(input: StreamInput): Promise<Sessio
if (state.messageIDs.has(event.data.inboxID)) return
state.messageIDs.add(event.data.inboxID)
write([
...skillCommits(event.data.inboxID, pending.skills),
{
kind: "user",
source: "system",

Some files were not shown because too many files have changed in this diff Show More