mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-04 17:29:53 +00:00
refactor(plugin): isolate HTTP hook dispatch
This commit is contained in:
parent
eb16388ec6
commit
654da1336a
6 changed files with 20 additions and 14 deletions
|
|
@ -339,7 +339,7 @@ export const make = Effect.fn("PluginHost.make")(function* (plugin: import("../p
|
|||
},
|
||||
session: {
|
||||
hook: (...registration: SessionHookRegistration) => {
|
||||
if (registration[0] === "context") return hooks.register("session", "context", registration[1])
|
||||
if (registration[0] !== "http") return hooks.register("session", ...registration)
|
||||
const middleware = registration[1]
|
||||
return hooks.register("session", "http", (event) =>
|
||||
Effect.sync(() => {
|
||||
|
|
|
|||
|
|
@ -267,9 +267,9 @@ export function fromPromise(plugin: Plugin) {
|
|||
},
|
||||
session: {
|
||||
hook: (...registration: SessionHookRegistration) => {
|
||||
if (registration[0] === "context")
|
||||
if (registration[0] !== "http")
|
||||
return register(
|
||||
host.session.hook("context", (event) =>
|
||||
host.session.hook(registration[0], (event) =>
|
||||
Effect.promise(() => Promise.resolve(registration[1](event))),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ describe("SessionRunnerLLM recorded", () => {
|
|||
session: {
|
||||
hook: (...registration: SessionHookRegistration) => {
|
||||
if (registration[0] === "http") return Effect.die("unused session HTTP hook")
|
||||
return hooks.register("session", "context", registration[1])
|
||||
return hooks.register("session", ...registration)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
@ -302,7 +302,7 @@ describe("SessionModelRequest HTTP bridge", () => {
|
|||
catalog: catalogHost(catalog),
|
||||
session: {
|
||||
hook: (...registration: SessionHookRegistration) => {
|
||||
if (registration[0] === "context") return hooks.register("session", "context", registration[1])
|
||||
if (registration[0] !== "http") return hooks.register("session", ...registration)
|
||||
const middleware = registration[1]
|
||||
return hooks.register("session", "http", (event) =>
|
||||
Effect.sync(() => {
|
||||
|
|
|
|||
|
|
@ -478,7 +478,7 @@ const setup = Effect.gen(function* () {
|
|||
session: {
|
||||
hook: (...registration: SessionHookRegistration) => {
|
||||
if (registration[0] === "http") return Effect.die("unused session HTTP hook")
|
||||
return hooks.register("session", "context", registration[1])
|
||||
return hooks.register("session", ...registration)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -32,15 +32,16 @@ export interface SessionHooks {
|
|||
}
|
||||
|
||||
export type SessionHookRegistration =
|
||||
| [name: "context", callback: (event: SessionContext) => Effect.Effect<void>]
|
||||
| {
|
||||
[Name in keyof SessionHooks]: [name: Name, callback: (event: SessionHooks[Name]) => Effect.Effect<void>]
|
||||
}[keyof SessionHooks]
|
||||
| [name: "http", middleware: SessionHttpMiddleware]
|
||||
|
||||
export interface SessionHook {
|
||||
(name: "context", callback: (event: SessionContext) => Effect.Effect<void>): Effect.Effect<
|
||||
Registration,
|
||||
never,
|
||||
Scope.Scope
|
||||
>
|
||||
<Name extends keyof SessionHooks>(
|
||||
name: Name,
|
||||
callback: (event: SessionHooks[Name]) => Effect.Effect<void>,
|
||||
): Effect.Effect<Registration, never, Scope.Scope>
|
||||
(name: "http", middleware: SessionHttpMiddleware): Effect.Effect<Registration, never, Scope.Scope>
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,11 +32,16 @@ export interface SessionHooks {
|
|||
}
|
||||
|
||||
export type SessionHookRegistration =
|
||||
| [name: "context", callback: (event: SessionContext) => Promise<void> | void]
|
||||
| {
|
||||
[Name in keyof SessionHooks]: [name: Name, callback: (event: SessionHooks[Name]) => Promise<void> | void]
|
||||
}[keyof SessionHooks]
|
||||
| [name: "http", middleware: SessionHttpMiddleware]
|
||||
|
||||
export interface SessionHook {
|
||||
(name: "context", callback: (event: SessionContext) => Promise<void> | void): Promise<Registration>
|
||||
<Name extends keyof SessionHooks>(
|
||||
name: Name,
|
||||
callback: (event: SessionHooks[Name]) => Promise<void> | void,
|
||||
): Promise<Registration>
|
||||
(name: "http", middleware: SessionHttpMiddleware): Promise<Registration>
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue