mirror of
https://gitee.com/zhangsken/opencode.git
synced 2026-11-18 09:42:01 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 264071f901 | |||
| 283ba56335 | |||
| c7b551fbe1 | |||
| 85e931ff44 | |||
| c7f93304b6 |
@@ -0,0 +1,9 @@
|
||||
---
|
||||
"@opencode-ai/protocol": minor
|
||||
"@opencode-ai/client": minor
|
||||
"@opencode-ai/plugin": minor
|
||||
"@opencode-ai/schema": minor
|
||||
"@opencode-ai/sdk": minor
|
||||
---
|
||||
|
||||
Expose process-local execution status on session get responses.
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Effect, Option, Schema } from "effect"
|
||||
import { Effect, Schema } from "effect"
|
||||
import { Tool } from "@opencode-ai/schema/tool"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Auth } from "../route/auth.js"
|
||||
@@ -125,7 +125,6 @@ const GeminiContentPart = Schema.Union([
|
||||
GeminiFunctionCallPart,
|
||||
GeminiFunctionResponsePart,
|
||||
])
|
||||
const decodeGeminiContentPart = Schema.decodeUnknownOption(GeminiContentPart)
|
||||
|
||||
const GeminiContent = Schema.Struct({
|
||||
role: optionalNull(Schema.Literals(["user", "model"])),
|
||||
@@ -133,11 +132,6 @@ const GeminiContent = Schema.Struct({
|
||||
})
|
||||
type GeminiContent = Schema.Schema.Type<typeof GeminiContent>
|
||||
|
||||
const GeminiResponseContent = Schema.Struct({
|
||||
role: optionalNull(Schema.Literals(["user", "model"])),
|
||||
parts: optionalNull(Schema.Array(Schema.Unknown)),
|
||||
})
|
||||
|
||||
const GeminiSystemInstruction = Schema.Struct({
|
||||
parts: Schema.Array(Schema.Struct({ text: Schema.String })),
|
||||
})
|
||||
@@ -206,7 +200,7 @@ const GeminiUsage = Schema.Struct({
|
||||
type GeminiUsage = Schema.Schema.Type<typeof GeminiUsage>
|
||||
|
||||
const GeminiCandidate = Schema.Struct({
|
||||
content: optionalNull(GeminiResponseContent),
|
||||
content: optionalNull(GeminiContent),
|
||||
finishReason: optionalNull(Schema.String),
|
||||
})
|
||||
|
||||
@@ -228,7 +222,6 @@ const GeminiEvent = Schema.Struct({
|
||||
type GeminiEvent = Schema.Schema.Type<typeof GeminiEvent>
|
||||
|
||||
interface ParserState {
|
||||
readonly route: string
|
||||
readonly finishReason?: string
|
||||
readonly hasToolCalls: boolean
|
||||
readonly promptFeedback?: GeminiPromptFeedback
|
||||
@@ -605,21 +598,7 @@ const step = (state: ParserState, event: GeminiEvent) => {
|
||||
// Supplier ids must be tracked across chunks of the same response, not just within one event's parts.
|
||||
const seenCallIds = new Set(nextState.seenCallIds)
|
||||
|
||||
for (const input of candidate.content.parts ?? []) {
|
||||
if (
|
||||
ProviderShared.isRecord(input) &&
|
||||
!("text" in input) &&
|
||||
!("inlineData" in input) &&
|
||||
!("functionCall" in input) &&
|
||||
!("functionResponse" in input)
|
||||
)
|
||||
continue
|
||||
const decoded = decodeGeminiContentPart(input)
|
||||
if (Option.isNone(decoded))
|
||||
return Effect.fail(
|
||||
ProviderShared.eventError(ADAPTER, `Invalid ${state.route} stream event`, ProviderShared.encodeJson(event)),
|
||||
)
|
||||
const part = decoded.value
|
||||
for (const part of candidate.content.parts ?? []) {
|
||||
const signature = "thoughtSignature" in part && part.thoughtSignature ? part.thoughtSignature : undefined
|
||||
// Gemini attaches replay signatures to thought parts, visible text, or function calls;
|
||||
// each block kind must retain the signature attached to its own parts.
|
||||
@@ -712,11 +691,7 @@ export const protocol = Protocol.make({
|
||||
},
|
||||
stream: {
|
||||
event: Protocol.jsonEvent(GeminiEvent),
|
||||
initial: (request) => ({
|
||||
route: `${request.model.provider}/${request.model.route.id}`,
|
||||
hasToolCalls: false,
|
||||
lifecycle: Lifecycle.initial(),
|
||||
}),
|
||||
initial: () => ({ hasToolCalls: false, lifecycle: Lifecycle.initial() }),
|
||||
step,
|
||||
onHalt: finish,
|
||||
},
|
||||
|
||||
@@ -906,54 +906,6 @@ describe("Gemini route", () => {
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("ignores unknown response parts", () =>
|
||||
Effect.gen(function* () {
|
||||
const response = yield* LLMClient.generate(request).pipe(
|
||||
Effect.provide(
|
||||
fixedResponse(
|
||||
sseEvents({
|
||||
candidates: [
|
||||
{
|
||||
content: {
|
||||
role: "model",
|
||||
parts: [
|
||||
{ text: "Hello " },
|
||||
{ executableCode: { language: "PYTHON", code: "print('ignored')" } },
|
||||
{ text: "world" },
|
||||
],
|
||||
},
|
||||
finishReason: "STOP",
|
||||
},
|
||||
],
|
||||
}),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
expect(response.text).toBe("Hello world")
|
||||
expect(response.finishReason).toEqual({ normalized: "stop", raw: "STOP" })
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("rejects malformed recognized response parts", () =>
|
||||
Effect.gen(function* () {
|
||||
const error = yield* LLMClient.generate(request).pipe(
|
||||
Effect.provide(
|
||||
fixedResponse(
|
||||
sseEvents({
|
||||
candidates: [{ content: { role: "model", parts: [{ text: 42 }] } }],
|
||||
}),
|
||||
),
|
||||
),
|
||||
Effect.flip,
|
||||
)
|
||||
|
||||
expect(error).toBeInstanceOf(AIError)
|
||||
expect(error.reason).toMatchObject({ _tag: "InvalidProviderOutput" })
|
||||
expect(error.message).toContain("Invalid google/gemini stream event")
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("preserves thoughtSignature for reasoning and tool-call continuation", () =>
|
||||
Effect.gen(function* () {
|
||||
const body = sseEvents({
|
||||
|
||||
@@ -29,7 +29,10 @@ afterEach(() => mock.restore())
|
||||
describe("session target resolver", () => {
|
||||
test("adopts an explicit Session location and model", async () => {
|
||||
const client = OpenCode.make({ baseUrl: "https://opencode.test" })
|
||||
const selected = session("ses_resume", "/session", "work_1", { providerID: "openai", id: "gpt-5" })
|
||||
const selected = {
|
||||
...session("ses_resume", "/session", "work_1", { providerID: "openai", id: "gpt-5" }),
|
||||
executing: false,
|
||||
}
|
||||
spyOn(client.session, "get").mockResolvedValue(selected)
|
||||
spyOn(client.location, "get").mockResolvedValue(location("/session", "work_1"))
|
||||
|
||||
@@ -57,7 +60,7 @@ describe("session target resolver", () => {
|
||||
|
||||
test("attaches the terminal environment to the resolved local Session", async () => {
|
||||
const client = OpenCode.make({ baseUrl: "https://opencode.test" })
|
||||
const selected = session("ses_resume", "/session")
|
||||
const selected = { ...session("ses_resume", "/session"), executing: false }
|
||||
spyOn(client.session, "get").mockResolvedValue(selected)
|
||||
spyOn(client.location, "get").mockResolvedValue(location("/session"))
|
||||
const environment = spyOn(client.session, "environment").mockResolvedValue()
|
||||
|
||||
@@ -203,7 +203,7 @@ export type SessionActiveOutput = { readonly [x: Session.ID]: { readonly type: "
|
||||
export type SessionActiveOperation<E = never> = () => Effect.Effect<SessionActiveOutput, E>
|
||||
|
||||
export type SessionGetInput = { readonly sessionID: Session.ID }
|
||||
export type SessionGetOutput = Session.Info
|
||||
export type SessionGetOutput = Session.GetInfo
|
||||
export type SessionGetOperation<E = never> = (input: SessionGetInput) => Effect.Effect<SessionGetOutput, E>
|
||||
|
||||
export type SessionRemoveInput = { readonly sessionID: Session.ID }
|
||||
|
||||
@@ -1545,6 +1545,24 @@ export type SessionInfo = {
|
||||
revert?: SessionRevert
|
||||
}
|
||||
|
||||
export type SessionGetInfo = {
|
||||
id: string
|
||||
parentID?: string
|
||||
fork?: { sessionID: string; boundary: SessionForkBoundary }
|
||||
projectID: string
|
||||
agent?: string
|
||||
model?: ModelRef
|
||||
cost: MoneyUSD
|
||||
tokens: TokenUsageInfo
|
||||
outcome?: "succeeded" | "failed" | "interrupted"
|
||||
time: { created: number; updated: number; idle?: number; viewed?: number; archived?: number }
|
||||
title?: string
|
||||
location: LocationRef
|
||||
subpath?: string
|
||||
revert?: SessionRevert
|
||||
executing: boolean
|
||||
}
|
||||
|
||||
export type SessionRevertStaged = {
|
||||
id: string
|
||||
created: number
|
||||
@@ -3399,7 +3417,7 @@ export type SessionActiveOutput = { data: { [x: string]: SessionActive } }["data
|
||||
|
||||
export type SessionGetInput = { readonly sessionID: { readonly sessionID: string }["sessionID"] }
|
||||
|
||||
export type SessionGetOutput = { data: SessionInfo }["data"]
|
||||
export type SessionGetOutput = { data: SessionGetInfo }["data"]
|
||||
|
||||
export type SessionRemoveInput = { readonly sessionID: { readonly sessionID: string }["sessionID"] }
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ test("effect entrypoint exposes canonical Schema contracts", () => {
|
||||
test("generated Effect API names canonical and composed outputs", async () => {
|
||||
const source = await Bun.file(new URL("../src/effect/api/api.ts", import.meta.url)).text()
|
||||
|
||||
expect(source).toContain("export type SessionGetOutput = Session.Info")
|
||||
expect(source).toContain("export type SessionGetOutput = Session.GetInfo")
|
||||
expect(source).toContain("export type EventSubscribeOutput = OpenCodeEvent")
|
||||
expect(source).not.toContain("HttpApiClient.ForApi")
|
||||
})
|
||||
|
||||
@@ -37,6 +37,7 @@ test("session.get returns the decoded Effect projection", async () => {
|
||||
}).pipe(Effect.provideService(HttpClient.HttpClient, httpClient), Effect.runPromise)
|
||||
|
||||
expect(DateTime.toEpochMillis(result.time.created)).toBe(1_717_171_717_000)
|
||||
expect(result.executing).toBe(true)
|
||||
})
|
||||
|
||||
test("session instructions methods use the public HTTP contract", async () => {
|
||||
@@ -279,6 +280,7 @@ const session = {
|
||||
},
|
||||
title: "Test",
|
||||
location: { directory: "/tmp/project" },
|
||||
executing: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -360,6 +360,7 @@ test("session.get returns the wire projection", async () => {
|
||||
const result = await client.session.get({ sessionID: "ses_test" })
|
||||
|
||||
expect(result.time.created).toBe(1_717_171_717_000)
|
||||
expect(result.executing).toBe(true)
|
||||
})
|
||||
|
||||
test("session instructions methods use the public HTTP contract", async () => {
|
||||
@@ -680,6 +681,7 @@ const session = {
|
||||
},
|
||||
title: "Test",
|
||||
location: { directory: "/tmp/project" },
|
||||
executing: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -29,10 +29,6 @@
|
||||
"./*": "./src/*.ts"
|
||||
},
|
||||
"imports": {
|
||||
"#plugin-imports": {
|
||||
"bun": "./src/plugin/imports.bun.ts",
|
||||
"default": "./src/plugin/imports.noop.ts"
|
||||
},
|
||||
"#sqlite": {
|
||||
"workerd": "./src/database/sqlite.workerd.ts",
|
||||
"bun": "./src/database/sqlite.bun.ts",
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { IntegrationMethodRegistration } from "@opencode-ai/plugin/effect/i
|
||||
import { EventManifest } from "@opencode-ai/schema/event-manifest"
|
||||
import { Mcp } from "@opencode-ai/schema/mcp"
|
||||
import { App } from "../app.js"
|
||||
import { Effect, Schema, Stream } from "effect"
|
||||
import { Effect, Schema, Stream, Struct } from "effect"
|
||||
import { Agent } from "../agent.js"
|
||||
import { AISDK } from "../aisdk.js"
|
||||
import { Catalog } from "../catalog.js"
|
||||
@@ -394,7 +394,11 @@ export const make = Effect.fn("PluginHost.make")(function* (plugin: Interface, p
|
||||
location:
|
||||
input?.location ?? Location.Ref.make({ directory: location.directory, workspaceID: location.workspaceID }),
|
||||
}),
|
||||
get: (input) => runtime.session.get(input.sessionID),
|
||||
get: (input) =>
|
||||
Effect.gen(function* () {
|
||||
const info = yield* runtime.session.get(input.sessionID)
|
||||
return Struct.assign(info, { executing: (yield* runtime.session.active).has(info.id) })
|
||||
}),
|
||||
switchAgent: runtime.session.switchAgent,
|
||||
switchModel: runtime.session.switchModel,
|
||||
prompt: runtime.session.prompt,
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
import { plugin } from "bun"
|
||||
|
||||
const modules = await Promise.all([
|
||||
load("effect", import("effect")),
|
||||
load("@opencode-ai/plugin", import("@opencode-ai/plugin")),
|
||||
load("@opencode-ai/plugin/app", import("@opencode-ai/plugin/app")),
|
||||
load("@opencode-ai/plugin/options", import("@opencode-ai/plugin/options")),
|
||||
load("@opencode-ai/plugin/storage", import("@opencode-ai/plugin/storage")),
|
||||
load("@opencode-ai/plugin/promise/adapter", import("@opencode-ai/plugin/promise/adapter")),
|
||||
load("@opencode-ai/plugin/promise/agent", import("@opencode-ai/plugin/promise/agent")),
|
||||
load("@opencode-ai/plugin/promise/aisdk", import("@opencode-ai/plugin/promise/aisdk")),
|
||||
load("@opencode-ai/plugin/promise/catalog", import("@opencode-ai/plugin/promise/catalog")),
|
||||
load("@opencode-ai/plugin/promise/command", import("@opencode-ai/plugin/promise/command")),
|
||||
load("@opencode-ai/plugin/promise/event", import("@opencode-ai/plugin/promise/event")),
|
||||
load("@opencode-ai/plugin/promise/index", import("@opencode-ai/plugin/promise/index")),
|
||||
load("@opencode-ai/plugin/promise/integration", import("@opencode-ai/plugin/promise/integration")),
|
||||
load("@opencode-ai/plugin/promise/mcp", import("@opencode-ai/plugin/promise/mcp")),
|
||||
load("@opencode-ai/plugin/promise/plugin", import("@opencode-ai/plugin/promise/plugin")),
|
||||
load("@opencode-ai/plugin/promise/reference", import("@opencode-ai/plugin/promise/reference")),
|
||||
load("@opencode-ai/plugin/promise/registration", import("@opencode-ai/plugin/promise/registration")),
|
||||
load("@opencode-ai/plugin/promise/session", import("@opencode-ai/plugin/promise/session")),
|
||||
load("@opencode-ai/plugin/promise/shell", import("@opencode-ai/plugin/promise/shell")),
|
||||
load("@opencode-ai/plugin/promise/skill", import("@opencode-ai/plugin/promise/skill")),
|
||||
load("@opencode-ai/plugin/promise/storage", import("@opencode-ai/plugin/promise/storage")),
|
||||
load("@opencode-ai/plugin/promise/tool", import("@opencode-ai/plugin/promise/tool")),
|
||||
load("@opencode-ai/plugin/promise/types", import("@opencode-ai/plugin/promise/types")),
|
||||
load("@opencode-ai/plugin/promise/websearch", import("@opencode-ai/plugin/promise/websearch")),
|
||||
load("@opencode-ai/plugin/effect", import("@opencode-ai/plugin/effect")),
|
||||
load("@opencode-ai/plugin/effect/agent", import("@opencode-ai/plugin/effect/agent")),
|
||||
load("@opencode-ai/plugin/effect/aisdk", import("@opencode-ai/plugin/effect/aisdk")),
|
||||
load("@opencode-ai/plugin/effect/catalog", import("@opencode-ai/plugin/effect/catalog")),
|
||||
load("@opencode-ai/plugin/effect/command", import("@opencode-ai/plugin/effect/command")),
|
||||
load("@opencode-ai/plugin/effect/event", import("@opencode-ai/plugin/effect/event")),
|
||||
load("@opencode-ai/plugin/effect/index", import("@opencode-ai/plugin/effect/index")),
|
||||
load("@opencode-ai/plugin/effect/integration", import("@opencode-ai/plugin/effect/integration")),
|
||||
load("@opencode-ai/plugin/effect/mcp", import("@opencode-ai/plugin/effect/mcp")),
|
||||
load("@opencode-ai/plugin/effect/plugin", import("@opencode-ai/plugin/effect/plugin")),
|
||||
load("@opencode-ai/plugin/effect/reference", import("@opencode-ai/plugin/effect/reference")),
|
||||
load("@opencode-ai/plugin/effect/registration", import("@opencode-ai/plugin/effect/registration")),
|
||||
load("@opencode-ai/plugin/effect/session", import("@opencode-ai/plugin/effect/session")),
|
||||
load("@opencode-ai/plugin/effect/shell", import("@opencode-ai/plugin/effect/shell")),
|
||||
load("@opencode-ai/plugin/effect/skill", import("@opencode-ai/plugin/effect/skill")),
|
||||
load("@opencode-ai/plugin/effect/storage", import("@opencode-ai/plugin/effect/storage")),
|
||||
load("@opencode-ai/plugin/effect/tool", import("@opencode-ai/plugin/effect/tool")),
|
||||
load("@opencode-ai/plugin/effect/websearch", import("@opencode-ai/plugin/effect/websearch")),
|
||||
])
|
||||
|
||||
plugin({
|
||||
name: "opencode-host-modules",
|
||||
setup(build) {
|
||||
modules.forEach(([specifier, exports]) => {
|
||||
build.module(specifier, () => ({ exports, loader: "object" }))
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
function load(specifier: string, module: Promise<object>) {
|
||||
return module.then((exports) => [specifier, Object.fromEntries(Object.entries(exports))] as const)
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export {}
|
||||
@@ -14,6 +14,7 @@ export interface Interface {
|
||||
readonly session: Pick<
|
||||
Session.Interface,
|
||||
| "get"
|
||||
| "active"
|
||||
| "create"
|
||||
| "messages"
|
||||
| "prompt"
|
||||
@@ -69,6 +70,7 @@ export const layerWithCell = (cell: Cell) =>
|
||||
Service.of({
|
||||
session: {
|
||||
get: (sessionID) => require(cell, (runtime) => runtime.session.get(sessionID)),
|
||||
active: require(cell, (runtime) => runtime.session.active),
|
||||
create: (input) => require(cell, (runtime) => runtime.session.create(input)),
|
||||
messages: (input) => require(cell, (runtime) => runtime.session.messages(input)),
|
||||
prompt: (input) => require(cell, (runtime) => runtime.session.prompt(input)),
|
||||
|
||||
@@ -138,14 +138,14 @@ V2 config uses more ergonomic shapes, but conversion is optional. When the user
|
||||
requests conversion, inspect the complete configuration, preserve behavior and
|
||||
unrelated settings, and apply only the relevant migrations from the guide. For
|
||||
plugin migrations, fetch and follow both the migration guide and the full
|
||||
[plugins guide](https://opencode.ai/v2/docs/build/plugins). If non-API V1
|
||||
[plugins guide](https://opencode.ai/v2/docs/build/plugins/overview). If non-API V1
|
||||
functionality fails in V2, use the `report` skill to file it as a compatibility
|
||||
bug.
|
||||
|
||||
## [Plugins](https://opencode.ai/v2/docs/build/plugins)
|
||||
## [Plugins](https://opencode.ai/v2/docs/build/plugins/overview)
|
||||
|
||||
For questions about creating, configuring, loading, publishing, or migrating
|
||||
plugins, fetch the full [plugins guide](https://opencode.ai/v2/docs/build/plugins)
|
||||
plugins, fetch the full [plugins guide](https://opencode.ai/v2/docs/build/plugins/overview)
|
||||
before answering. Refer to this guide when the user wants to build a plugin. It
|
||||
covers hooks, transforms, tools, plugin context capabilities, and package
|
||||
entrypoints. Plugins can also extend the TUI; for those, fetch the
|
||||
|
||||
@@ -16,7 +16,6 @@ import { PluginInternal } from "./internal.js"
|
||||
import { SdkPlugins } from "./sdk.js"
|
||||
import { importModule } from "@opencode-ai/util/runtime-import"
|
||||
import { Service } from "./supervisor-service.js"
|
||||
import "#plugin-imports"
|
||||
|
||||
const PluginModule = Schema.Struct({
|
||||
default: Schema.Union([
|
||||
|
||||
@@ -95,50 +95,6 @@ describe("PluginSupervisor config", () => {
|
||||
),
|
||||
)
|
||||
|
||||
it.live("loads plugins without local runtime packages", () =>
|
||||
withLocation(
|
||||
{ plugins: ["-*", "./promise.ts", "./effect.ts"] },
|
||||
Effect.gen(function* () {
|
||||
yield* ready()
|
||||
const plugins = yield* Plugin.Service
|
||||
expect((yield* plugins.list()).map((plugin) => String(plugin.id))).toEqual([
|
||||
"host-plugin-package",
|
||||
"host-effect-packages",
|
||||
])
|
||||
}),
|
||||
false,
|
||||
(directory) =>
|
||||
Promise.all([
|
||||
fs.writeFile(
|
||||
path.join(directory, "promise.ts"),
|
||||
`import { Plugin } from "@opencode-ai/plugin"
|
||||
import { fromPromise } from "@opencode-ai/plugin/promise/adapter"
|
||||
|
||||
export default Plugin.define({
|
||||
id: "host-plugin-package",
|
||||
setup() {
|
||||
if (typeof fromPromise !== "function") throw new Error("missing Promise adapter")
|
||||
},
|
||||
})
|
||||
`,
|
||||
),
|
||||
fs.writeFile(
|
||||
path.join(directory, "effect.ts"),
|
||||
`import { Plugin } from "@opencode-ai/plugin/effect/index"
|
||||
import { Effect } from "effect"
|
||||
|
||||
export default Plugin.define({
|
||||
id: "host-effect-packages",
|
||||
effect() {
|
||||
return Effect.void
|
||||
},
|
||||
})
|
||||
`,
|
||||
),
|
||||
]).then(() => undefined),
|
||||
),
|
||||
)
|
||||
|
||||
it.live("disables configured plugins by exported ID", () => {
|
||||
const plugin = path.join(import.meta.dir, "../plugin/fixtures/config-promise-plugin.ts")
|
||||
return withLocation(
|
||||
|
||||
@@ -229,13 +229,13 @@ export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S>(sessionLo
|
||||
.add(
|
||||
HttpApiEndpoint.get("session.get", "/api/session/:sessionID", {
|
||||
params: { sessionID: Session.ID },
|
||||
success: Schema.Struct({ data: Session.Info }),
|
||||
success: Schema.Struct({ data: Session.GetInfo }),
|
||||
error: SessionNotFoundError,
|
||||
}).annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "v2.session.get",
|
||||
summary: "Get session",
|
||||
description: "Retrieve a session by ID.",
|
||||
description: "Retrieve a session by ID with its process-local runtime execution status.",
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -52,6 +52,15 @@ export const Info = Schema.Struct({
|
||||
revert: Revert.pipe(optional),
|
||||
}).annotate({ identifier: "Session.Info" })
|
||||
|
||||
/** Session projection enriched with process-local runtime liveness. */
|
||||
export interface GetInfo extends Schema.Schema.Type<typeof GetInfo> {}
|
||||
export const GetInfo = Schema.Struct({
|
||||
...Info.fields,
|
||||
executing: Schema.Boolean.annotate({
|
||||
description: "Whether this OpenCode process is currently executing the session.",
|
||||
}),
|
||||
}).annotate({ identifier: "Session.GetInfo" })
|
||||
|
||||
export const ListAnchor = Schema.Struct({
|
||||
id: ID,
|
||||
time: Schema.Finite,
|
||||
|
||||
@@ -301,6 +301,7 @@ it.live(
|
||||
expect(created.id).toBe(id)
|
||||
expect(selected.model?.id).toBe(model.id)
|
||||
expect(selected.model?.providerID).toBe(model.providerID)
|
||||
expect(selected.executing).toBe(false)
|
||||
expect(page.data.some((session) => session.id === id)).toBe(true)
|
||||
expect(active).toEqual({})
|
||||
expect(admitted.sessionID).toBe(id)
|
||||
|
||||
@@ -43,6 +43,7 @@ test("Promise host uses the embedded router and releases plugins", async () => {
|
||||
const events = Array.fromAsync(opencode.sessions.log({ sessionID: session.id }))
|
||||
|
||||
expect(selected.id).toBe(session.id)
|
||||
expect(selected.executing).toBe(false)
|
||||
expect(page.data.some((item) => item.id === session.id)).toBe(true)
|
||||
expect((await events).some((event) => event.type === "session.created")).toBe(true)
|
||||
expect(setup).toBe(true)
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Session } from "@opencode-ai/core/session"
|
||||
import { SessionStats } from "@opencode-ai/core/session/stats"
|
||||
import { SessionTransfer } from "@opencode-ai/core/session/transfer"
|
||||
import { InstructionEntry } from "@opencode-ai/core/session/instruction-entry"
|
||||
import { DateTime, Effect, Stream } from "effect"
|
||||
import { DateTime, Effect, Stream, Struct } from "effect"
|
||||
import { HttpApiBuilder, HttpApiSchema } from "effect/unstable/httpapi"
|
||||
import { Api } from "../api"
|
||||
import { SessionsCursor } from "@opencode-ai/protocol/groups/session"
|
||||
@@ -171,10 +171,11 @@ export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handl
|
||||
.handle(
|
||||
"session.get",
|
||||
Effect.fn(function* (ctx) {
|
||||
const info = yield* session
|
||||
.get(ctx.params.sessionID)
|
||||
.pipe(Effect.catchTag("Session.NotFoundError", missingSession))
|
||||
return {
|
||||
data: yield* session
|
||||
.get(ctx.params.sessionID)
|
||||
.pipe(Effect.catchTag("Session.NotFoundError", missingSession)),
|
||||
data: Struct.assign(info, { executing: (yield* session.active).has(info.id) }),
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { expect } from "bun:test"
|
||||
import { createServer, type Server } from "node:http"
|
||||
import { makeMemoryDriver } from "@opencode-ai/core/environment/index"
|
||||
import { Session } from "@opencode-ai/core/session"
|
||||
import { SessionExecution } from "@opencode-ai/core/session/execution"
|
||||
import { Workspace } from "@opencode-ai/core/workspace"
|
||||
import { WorkspaceDriver } from "@opencode-ai/core/workspace/driver"
|
||||
import { Effect } from "effect"
|
||||
import { Effect, Layer } from "effect"
|
||||
import { it } from "../../core/test/lib/effect"
|
||||
import { ServerFetch } from "../src/fetch"
|
||||
|
||||
@@ -253,6 +255,52 @@ it.live("serves the session view operation and missing-session error", () =>
|
||||
}).pipe(Effect.scoped),
|
||||
)
|
||||
|
||||
it.live("reports per-session runtime execution status", () =>
|
||||
Effect.gen(function* () {
|
||||
const executing = Session.ID.make("ses_executing")
|
||||
const idle = Session.ID.make("ses_idle")
|
||||
const handler = yield* ServerFetch.make(options, {
|
||||
overrides: [
|
||||
[
|
||||
SessionExecution.node,
|
||||
Layer.succeed(
|
||||
SessionExecution.Service,
|
||||
SessionExecution.Service.of({
|
||||
active: Effect.succeed(new Set([executing])),
|
||||
resume: () => Effect.void,
|
||||
wake: () => Effect.void,
|
||||
interrupt: () => Effect.succeed(false),
|
||||
awaitIdle: () => Effect.void,
|
||||
}),
|
||||
),
|
||||
],
|
||||
],
|
||||
})
|
||||
|
||||
yield* Effect.forEach([executing, idle], (id) =>
|
||||
Effect.promise(() =>
|
||||
handler(
|
||||
new Request("http://opencode.local/api/session", {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ id }),
|
||||
}),
|
||||
),
|
||||
),
|
||||
)
|
||||
const responses = yield* Effect.forEach([executing, idle], (id) =>
|
||||
Effect.promise(() =>
|
||||
handler(new Request(`http://opencode.local/api/session/${id}`)).then((response) => response.json()),
|
||||
),
|
||||
)
|
||||
|
||||
expect(responses).toMatchObject([
|
||||
{ data: { id: executing, executing: true } },
|
||||
{ data: { id: idle, executing: false } },
|
||||
])
|
||||
}).pipe(Effect.scoped),
|
||||
)
|
||||
|
||||
// Pins the eager-boot guarantee: the application layer is built before the handler returns, so
|
||||
// an aborted first request cannot interrupt layer construction and wedge every later request
|
||||
// (the Effect-TS/effect#6319 failure class that lazy first-request builds are prone to).
|
||||
|
||||
@@ -190,6 +190,7 @@ describe("run session shared", () => {
|
||||
cost: 0,
|
||||
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
|
||||
model: { providerID: "openai", id: "gpt-5", variant: "high" },
|
||||
executing: false,
|
||||
}),
|
||||
)
|
||||
|
||||
|
||||
@@ -3753,15 +3753,8 @@
|
||||
],
|
||||
"security": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "SessionInterruptResponse",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/SessionInterruptResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
"204": {
|
||||
"description": "<No Content>"
|
||||
},
|
||||
"400": {
|
||||
"description": "InvalidRequestError",
|
||||
@@ -3801,7 +3794,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "Interrupt active execution owned by this OpenCode process. Returns interrupted=true when an active execution was interrupted and false for the idle no-op. When continue=true, execution resumes pending steering input and next-in-line control items (manual compaction, moves) while queued prompts remain parked.",
|
||||
"description": "Interrupt active execution owned by this OpenCode process. Idle interruption is a no-op. When continue=true, execution resumes pending steering input and next-in-line control items (manual compaction, moves) while queued prompts remain parked.",
|
||||
"summary": "Interrupt session execution"
|
||||
}
|
||||
},
|
||||
@@ -16439,17 +16432,6 @@
|
||||
"required": ["data"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"SessionInterruptResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"interrupted": {
|
||||
"type": "boolean",
|
||||
"description": "Whether an active execution owned by this OpenCode process was interrupted."
|
||||
}
|
||||
},
|
||||
"required": ["interrupted"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"SessionLogItemEncoded": {
|
||||
"type": "string",
|
||||
"contentMediaType": "application/json"
|
||||
|
||||
@@ -3753,15 +3753,8 @@
|
||||
],
|
||||
"security": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "SessionInterruptResponse",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/SessionInterruptResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
"204": {
|
||||
"description": "<No Content>"
|
||||
},
|
||||
"400": {
|
||||
"description": "InvalidRequestError",
|
||||
@@ -3801,7 +3794,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "Interrupt active execution owned by this OpenCode process. Returns interrupted=true when an active execution was interrupted and false for the idle no-op. When continue=true, execution resumes pending steering input and next-in-line control items (manual compaction, moves) while queued prompts remain parked.",
|
||||
"description": "Interrupt active execution owned by this OpenCode process. Idle interruption is a no-op. When continue=true, execution resumes pending steering input and next-in-line control items (manual compaction, moves) while queued prompts remain parked.",
|
||||
"summary": "Interrupt session execution"
|
||||
}
|
||||
},
|
||||
@@ -16439,17 +16432,6 @@
|
||||
"required": ["data"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"SessionInterruptResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"interrupted": {
|
||||
"type": "boolean",
|
||||
"description": "Whether an active execution owned by this OpenCode process was interrupted."
|
||||
}
|
||||
},
|
||||
"required": ["interrupted"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"SessionLogItemEncoded": {
|
||||
"type": "string",
|
||||
"contentMediaType": "application/json"
|
||||
|
||||
@@ -3,7 +3,7 @@ title: "Intro"
|
||||
---
|
||||
|
||||
<CardGroup cols={1}>
|
||||
<Card title="Extend OpenCode" href="/build/plugins">
|
||||
<Card title="Extend OpenCode" href="/build/plugins/overview">
|
||||
Build plugins that add tools, integrations, commands, agents, and custom behavior while keeping the rest of OpenCode
|
||||
intact.
|
||||
</Card>
|
||||
|
||||
@@ -433,7 +433,7 @@ Expose the CLI plugin through `./tui`; add OpenTUI peers when the plugin renders
|
||||
}
|
||||
```
|
||||
|
||||
Set `tui: true` on the [main plugin](/build/plugins) for automatic loading.
|
||||
Set `tui: true` on the [main plugin](/build/plugins/overview) for automatic loading.
|
||||
|
||||
```ts title="src/index.ts"
|
||||
import { Plugin } from "@opencode-ai/plugin"
|
||||
|
||||
@@ -70,7 +70,7 @@ await using opencode = await OpenCode.create({ plugins: [plugin] })
|
||||
|
||||
Call `await opencode.plugin(plugin)` to register another plugin after startup.
|
||||
|
||||
See the [Plugins guide](/build/plugins) for the plugin context and available
|
||||
See the [Plugins guide](/build/plugins/overview) for the plugin context and available
|
||||
hooks.
|
||||
|
||||
## Workerd
|
||||
|
||||
@@ -3,7 +3,7 @@ title: "Plugins"
|
||||
---
|
||||
|
||||
Plugins configured in `opencode.json(c)` that expose a TUI component are loaded automatically by the CLI. To learn how
|
||||
to build plugins, see [Building plugins](/build/plugins). You do not need to add the same package to `cli.json`. The CLI
|
||||
to build plugins, see [Building plugins](/build/plugins/overview). You do not need to add the same package to `cli.json`. The CLI
|
||||
gets the active plugin list from the connected OpenCode server, so this also works when the server is remote.
|
||||
|
||||
Use `cli.json` for CLI-only plugins. These plugins run locally in the terminal and remain active when the CLI connects
|
||||
|
||||
@@ -544,7 +544,7 @@ plugin API is still being finalized during beta, and detailed plugin migration g
|
||||
ready.
|
||||
|
||||
Once the V2 plugin API is finalized, OpenCode should be able to migrate the majority of V1 plugins while keeping related
|
||||
local modules and dependencies together. See the current beta [Plugins guide](/build/plugins).
|
||||
local modules and dependencies together. See the current beta [Plugins guide](/build/plugins/overview).
|
||||
|
||||
## Server API and clients
|
||||
|
||||
|
||||
@@ -102,6 +102,6 @@ CLI-only plugins are configured separately and remain active when connected to a
|
||||
}
|
||||
```
|
||||
|
||||
<Card title="Build a plugin" href="/build/plugins">
|
||||
<Card title="Build a plugin" href="/build/plugins/overview">
|
||||
Create plugins that add tools, hooks, integrations, commands, agents, and other behavior.
|
||||
</Card>
|
||||
|
||||
@@ -93,7 +93,7 @@ export const docsSections: DocsSection[] = [
|
||||
{
|
||||
title: "Plugins",
|
||||
items: [
|
||||
{ title: "Overview", slug: "build/plugins" },
|
||||
{ title: "Overview", slug: "build/plugins/overview" },
|
||||
{ title: "Effect", slug: "build/plugins/effect" },
|
||||
{ title: "CLI", slug: "build/plugins/cli" },
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user