mirror of
https://gitee.com/zhangsken/opencode.git
synced 2026-10-16 10:30:01 +08:00
113 lines
3.3 KiB
TypeScript
113 lines
3.3 KiB
TypeScript
import type { SessionApi } from "@opencode/client/effect/api"
|
|
import type { GenerationOptionsFields, Message, SystemPart } from "@opencode/ai"
|
|
import type { Agent } from "@opencode/schema/agent"
|
|
import type { Model } from "@opencode/schema/model"
|
|
import type { PromptInput } from "@opencode/schema/prompt-input"
|
|
import type { Session } from "@opencode/schema/session"
|
|
import type { SessionInbox } from "@opencode/schema/session-inbox"
|
|
import type { SessionError } from "@opencode/schema/session-error"
|
|
import type { SessionMessage } from "@opencode/schema/session-message"
|
|
import type { JsonSchema, Types } from "effect"
|
|
import type { ModelHooks } from "./registration.js"
|
|
|
|
export interface SessionPrompt {
|
|
readonly sessionID: Session.ID
|
|
readonly messageID: SessionMessage.ID
|
|
prompt: Types.DeepMutable<PromptInput.Prompt>
|
|
metadata?: Record<string, unknown>
|
|
delivery: SessionInbox.Delivery
|
|
}
|
|
|
|
/** Request overrides. Typed keys are generation settings; any other key is a provider option. */
|
|
export type SessionRequestOptions = Types.DeepMutable<GenerationOptionsFields> & Record<string, unknown>
|
|
|
|
export interface SessionRequest {
|
|
readonly sessionID: Session.ID
|
|
readonly model: Model.Ref
|
|
system: Array<SystemPart>
|
|
messages: Array<Message>
|
|
options: SessionRequestOptions
|
|
}
|
|
|
|
export interface SessionContext extends SessionRequest {
|
|
readonly agent: Agent.ID
|
|
tools: Record<string, { description: string; input: JsonSchema.JsonSchema }>
|
|
}
|
|
|
|
export interface SessionTitle extends SessionRequest {
|
|
/** Set to use this title and skip the model request. */
|
|
result?: string
|
|
}
|
|
|
|
/**
|
|
* Why a Session request is being made. Auxiliary requests share the Session's
|
|
* hook identity but need to be told apart from the agent loop.
|
|
*/
|
|
export type SessionRequestKind = "primary" | "compaction" | "title" | "generate"
|
|
|
|
export interface SessionModelRequest {
|
|
readonly sessionID: Session.ID
|
|
readonly agent: Agent.ID
|
|
readonly model: Model.Ref
|
|
readonly kind: SessionRequestKind
|
|
baseURL?: string
|
|
headers: Record<string, string>
|
|
}
|
|
|
|
export interface SessionHttpRequest {
|
|
readonly sessionID: Session.ID
|
|
readonly agent: Agent.ID
|
|
readonly model: Model.Ref
|
|
readonly kind: SessionRequestKind
|
|
request: Request
|
|
}
|
|
|
|
export interface SessionHttpResponse {
|
|
readonly sessionID: Session.ID
|
|
readonly agent: Agent.ID
|
|
readonly model: Model.Ref
|
|
readonly kind: SessionRequestKind
|
|
readonly request: Request
|
|
response: Response
|
|
}
|
|
|
|
export type SessionRetryDecision = { retry: false } | { retry: true; delay: number }
|
|
|
|
export interface SessionRetry {
|
|
readonly sessionID: Session.ID
|
|
readonly agent: Agent.ID
|
|
readonly model: Model.Ref
|
|
readonly error: SessionError.Error
|
|
readonly attempt: number
|
|
decision: SessionRetryDecision
|
|
}
|
|
|
|
export interface SessionHooks {
|
|
readonly prompt: SessionPrompt
|
|
readonly context: SessionContext
|
|
readonly title: SessionTitle
|
|
readonly "model.request": SessionModelRequest
|
|
readonly "http.request": SessionHttpRequest
|
|
readonly "http.response": SessionHttpResponse
|
|
readonly retry: SessionRetry
|
|
}
|
|
|
|
export type SessionDomain = Pick<
|
|
SessionApi<unknown>,
|
|
| "create"
|
|
| "get"
|
|
| "switchAgent"
|
|
| "switchModel"
|
|
| "prompt"
|
|
| "generate"
|
|
| "command"
|
|
| "synthetic"
|
|
| "interrupt"
|
|
| "rename"
|
|
| "move"
|
|
| "wait"
|
|
| "context"
|
|
> & {
|
|
readonly hook: ModelHooks<SessionHooks>
|
|
}
|