refactor(plugin): simplify session request hook
This commit is contained in:
parent
7edaa05869
commit
a84babca73
3 changed files with 11 additions and 11 deletions
|
|
@ -235,14 +235,14 @@ export const json = <Body, Message>(input: JsonInput<Body, Message>): JsonTransp
|
|||
const transformRequest = prepareInput.transformRequest
|
||||
const transformed = transformRequest
|
||||
? yield* transformRequest({ headers: parts.headers, body: yield* HttpTransport.decodeRequestBody(message) })
|
||||
: { headers: parts.headers, body: yield* HttpTransport.decodeRequestBody(message) }
|
||||
const bodyText = transformRequest ? encodeJson(transformed.body) : message
|
||||
: undefined
|
||||
const bodyText = transformed ? encodeJson(transformed.body) : message
|
||||
const headers = yield* Auth.toEffect(prepareInput.auth)({
|
||||
request: prepareInput.request,
|
||||
method: "POST",
|
||||
url: parts.url,
|
||||
body: bodyText,
|
||||
headers: Headers.fromInput(transformed.headers),
|
||||
headers: Headers.fromInput(transformed?.headers ?? parts.headers),
|
||||
})
|
||||
return {
|
||||
url: yield* webSocketUrl(parts.url),
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { LLMError, LLMEvent, isContextOverflowFailure, type ProviderErrorEvent }
|
|||
import { SessionError } from "@opencode-ai/schema/session-error"
|
||||
import { Cause, Effect, Exit, Fiber, FiberSet, Layer, Option, Semaphore, Stream } from "effect"
|
||||
import { Database } from "../../database/database"
|
||||
import { AgentV2 } from "../../agent"
|
||||
import { EventV2 } from "../../event"
|
||||
import { PermissionV2 } from "../../permission"
|
||||
import { QuestionTool } from "../../tool/question"
|
||||
|
|
@ -40,6 +41,7 @@ const layer = Layer.effect(
|
|||
const db = (yield* Database.Service).db
|
||||
const compaction = yield* SessionCompaction.Service
|
||||
const title = yield* SessionTitle.Service
|
||||
const agents = yield* AgentV2.Service
|
||||
// Title generation is a side effect of the first step; it must not delay step continuation.
|
||||
// Tracked per process so repeated wakes before the second user message arrives don't
|
||||
// re-fire a redundant LLM call; `SessionTitle` itself is idempotent based on durable history.
|
||||
|
|
@ -415,8 +417,10 @@ const layer = Layer.effect(
|
|||
Effect.gen(function* () {
|
||||
const compacted = yield* restore(
|
||||
Effect.gen(function* () {
|
||||
const agent = yield* agents.select(session.agent)
|
||||
return yield* compaction.compactManual({
|
||||
session,
|
||||
agent: agent.id,
|
||||
messages: yield* store.context(sessionID),
|
||||
inputID: pending.id,
|
||||
})
|
||||
|
|
@ -501,6 +505,7 @@ export const node = makeLocationNode({
|
|||
SessionStore.node,
|
||||
SessionCompaction.node,
|
||||
SessionTitle.node,
|
||||
AgentV2.node,
|
||||
Snapshot.node,
|
||||
Database.node,
|
||||
],
|
||||
|
|
|
|||
|
|
@ -1,16 +1,11 @@
|
|||
import type { RequestData } from "@opencode-ai/ai/route"
|
||||
import type { Agent } from "@opencode-ai/schema/agent"
|
||||
import type { Model } from "@opencode-ai/schema/model"
|
||||
import type { Session } from "@opencode-ai/schema/session"
|
||||
|
||||
export type RequestValue =
|
||||
| null
|
||||
| boolean
|
||||
| number
|
||||
| string
|
||||
| Array<RequestValue>
|
||||
| { [key: string]: RequestValue }
|
||||
export type RequestValue = RequestData["body"][string]
|
||||
|
||||
export type RequestBody = Record<string, RequestValue>
|
||||
export type RequestBody = RequestData["body"]
|
||||
|
||||
export interface SessionRequest {
|
||||
readonly sessionID: Session.ID
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue