mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-21 18:53:28 +00:00
feat(plugin): expose session selection methods (#43718)
This commit is contained in:
parent
58f909d5b9
commit
5970537a8a
6 changed files with 42 additions and 2 deletions
|
|
@ -401,6 +401,8 @@ export const make = Effect.fn("PluginHost.make")(function* (
|
|||
input?.location ?? Location.Ref.make({ directory: location.directory, workspaceID: location.workspaceID }),
|
||||
}),
|
||||
get: (input) => runtime.session.get(input.sessionID),
|
||||
switchAgent: runtime.session.switchAgent,
|
||||
switchModel: runtime.session.switchModel,
|
||||
prompt: runtime.session.prompt,
|
||||
generate: (input) => runtime.session.generate(input).pipe(Effect.map((text) => ({ text }))),
|
||||
command: runtime.session.command,
|
||||
|
|
|
|||
|
|
@ -117,6 +117,8 @@ export function host(overrides: Overrides = {}): Plugin.Context {
|
|||
hook: overrides.session?.hook ?? (() => Effect.die("unused session.hook")),
|
||||
create: overrides.session?.create ?? (() => Effect.die("unused session.create")),
|
||||
get: overrides.session?.get ?? (() => Effect.die("unused session.get")),
|
||||
switchAgent: overrides.session?.switchAgent ?? (() => Effect.die("unused session.switchAgent")),
|
||||
switchModel: overrides.session?.switchModel ?? (() => Effect.die("unused session.switchModel")),
|
||||
prompt: overrides.session?.prompt ?? (() => Effect.die("unused session.prompt")),
|
||||
generate: overrides.session?.generate ?? (() => Effect.die("unused session.generate")),
|
||||
command: overrides.session?.command ?? (() => Effect.die("unused session.command")),
|
||||
|
|
|
|||
|
|
@ -133,6 +133,8 @@ describe("fromPromise", () => {
|
|||
expect(input.continue).toBe(true)
|
||||
return Effect.void
|
||||
},
|
||||
switchAgent: (input) => Effect.sync(() => seen.push(input)),
|
||||
switchModel: (input) => Effect.sync(() => seen.push(input)),
|
||||
rename: (input) => Effect.sync(() => seen.push(input)),
|
||||
wait: (input) => Effect.sync(() => seen.push(input)),
|
||||
},
|
||||
|
|
@ -144,6 +146,13 @@ describe("fromPromise", () => {
|
|||
setup: async (ctx) => {
|
||||
expect(await ctx.session.interrupt({ sessionID: "ses_success", continue: true })).toBeUndefined()
|
||||
await expect(ctx.session.interrupt({ sessionID: "ses_failure" })).rejects.toThrow("interrupt failed")
|
||||
expect(await ctx.session.switchAgent({ sessionID: "ses_success", agent: "build" })).toBeUndefined()
|
||||
expect(
|
||||
await ctx.session.switchModel({
|
||||
sessionID: "ses_success",
|
||||
model: { providerID: "openai", id: "gpt-5" },
|
||||
}),
|
||||
).toBeUndefined()
|
||||
expect(await ctx.session.rename({ sessionID: "ses_success", title: "Renamed" })).toBeUndefined()
|
||||
expect(await ctx.session.wait({ sessionID: "ses_success" })).toBeUndefined()
|
||||
},
|
||||
|
|
@ -151,6 +160,11 @@ describe("fromPromise", () => {
|
|||
).effect(host)
|
||||
|
||||
expect(seen).toEqual([
|
||||
{ sessionID: Session.ID.make("ses_success"), agent: Agent.ID.make("build") },
|
||||
{
|
||||
sessionID: Session.ID.make("ses_success"),
|
||||
model: { providerID: Provider.ID.make("openai"), id: Model.ID.make("gpt-5") },
|
||||
},
|
||||
{ sessionID: Session.ID.make("ses_success"), title: "Renamed" },
|
||||
{ sessionID: Session.ID.make("ses_success") },
|
||||
])
|
||||
|
|
|
|||
|
|
@ -47,7 +47,17 @@ export interface SessionHooks {
|
|||
|
||||
export type SessionDomain = Pick<
|
||||
SessionApi<unknown>,
|
||||
"create" | "get" | "prompt" | "generate" | "command" | "synthetic" | "interrupt" | "rename" | "wait"
|
||||
| "create"
|
||||
| "get"
|
||||
| "switchAgent"
|
||||
| "switchModel"
|
||||
| "prompt"
|
||||
| "generate"
|
||||
| "command"
|
||||
| "synthetic"
|
||||
| "interrupt"
|
||||
| "rename"
|
||||
| "wait"
|
||||
> & {
|
||||
readonly hook: ModelHooks<SessionHooks>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -309,6 +309,8 @@ export function fromPromise(plugin: Plugin) {
|
|||
),
|
||||
create: adaptApiMethod(SessionEndpoints["session.create"], host.session.create),
|
||||
get: adaptApiMethod(SessionEndpoints["session.get"], host.session.get),
|
||||
switchAgent: adaptApiMethod(SessionEndpoints["session.switchAgent"], host.session.switchAgent),
|
||||
switchModel: adaptApiMethod(SessionEndpoints["session.switchModel"], host.session.switchModel),
|
||||
prompt: adaptApiMethod(SessionEndpoints["session.prompt"], host.session.prompt),
|
||||
generate: adaptApiMethod(SessionEndpoints["session.generate"], host.session.generate),
|
||||
command: adaptApiMethod(SessionEndpoints["session.command"], host.session.command),
|
||||
|
|
|
|||
|
|
@ -47,7 +47,17 @@ export interface SessionHooks {
|
|||
|
||||
export type SessionDomain = Pick<
|
||||
SessionApi,
|
||||
"create" | "get" | "prompt" | "generate" | "command" | "synthetic" | "interrupt" | "rename" | "wait"
|
||||
| "create"
|
||||
| "get"
|
||||
| "switchAgent"
|
||||
| "switchModel"
|
||||
| "prompt"
|
||||
| "generate"
|
||||
| "command"
|
||||
| "synthetic"
|
||||
| "interrupt"
|
||||
| "rename"
|
||||
| "wait"
|
||||
> & {
|
||||
readonly hook: ModelHooks<SessionHooks>
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue