UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

66 lines • 4.37 kB
/** * The request-hook contract of hosted model-key custody (row CK21; custody design 4.9, round-10 fold section 15). * * `HookRequestInput` is the serializable projection of the fused `before_provider_request` input: the provider payload * and the effective request model, without the request headers or the model's own headers, which can carry a * credential and never leave the side that dials. A step call has this input; an aux call has none. A hand serves * `hook.model_request` by running its user's request hooks on the input, only after the request's placement claim * verified, and replies with the payload they produced, with their failures and the messages and notices they sent. */ import type { Api, Model } from "@earendil-works/pi-ai"; import type { ExecutionScope } from "@earendil-works/pi-agent-core"; import { type ClaimVerdict } from "../egress/placement-claim.ts"; import type { HookModelRequest, HookModelRequestReply, ProviderCallErrorCode, ProviderCallKind, WireJson } from "../egress/wire.ts"; import type { BeforeProviderRequestEvent } from "../extensions/types.ts"; /** The pinned shape of `HookModelRequestInput` (and of the reply's `output`). */ export type HookRequestInput = { readonly payload: WireJson; readonly model?: { readonly [key: string]: WireJson; }; }; /** The input or output cannot cross the wire: it is not JSON, or not the closed envelope. */ export declare class HookContractError extends Error { readonly name = "HookContractError"; } /** The request's placement claim did not verify, so no hook ran; `code`/`retryable` are the claim's wire answer. */ export declare class HookRequestRefusedError extends Error { readonly name = "HookRequestRefusedError"; readonly verdict: Exclude<ClaimVerdict, "valid">; readonly code: ProviderCallErrorCode; readonly retryable: boolean; constructor(verdict: Exclude<ClaimVerdict, "valid">); } /** The projection of a fused `before_provider_request` input. */ export declare function hookRequestInputOf(event: Omit<BeforeProviderRequestEvent, "type"> & { type?: string; }): HookRequestInput; /** A step call's hook input; an aux call runs no request hooks on the hand and has none. */ export declare function hookRequestInputForCall(call: ProviderCallKind, event: Omit<BeforeProviderRequestEvent, "type"> & { type?: string; }): HookRequestInput | undefined; /** The reply's `output`: the payload the hooks produced, with the model the request carried. */ export declare function hookRequestOutputOf(input: HookRequestInput, payload: unknown): HookRequestInput; /** Reads a wire value back as the closed envelope `{ payload, model? }`; the model never carries headers. */ export declare function parseHookRequestInput(value: unknown): HookRequestInput; /** The effective model a hand hands its hooks, as the loop sent it. */ export declare function hookModelOf(input: HookRequestInput): Model<Api> | undefined; /** What the user's request hooks produced: the reply's `output`, their failures and what they sent. */ export type HookRequestHooksResult = Omit<HookModelRequestReply, "t" | "sessionId" | "stepId" | "output"> & { readonly output: HookRequestInput; }; export interface HookServePorts { /** The hand's placement-claim check (CK7's verifier with the hand's trust and clock). */ verifyClaim(claim: unknown): Promise<ClaimVerdict>; /** Runs the user's request hooks of `sessionId` on `input` and returns what they produced. */ runRequestHooks(sessionId: string, input: HookRequestInput): Promise<HookRequestHooksResult>; } /** Serves one `hook.model_request`: claim first, then the closed input, then the hooks. */ export declare function serveHookModelRequest(request: HookModelRequest, ports: HookServePorts): Promise<HookModelRequestReply>; /** * `runRequestHooks` over a hand's loop-hook runner (`LooplessHand.loopHooks`): the session's hooks run on the runtime of * `scope`, inside a loop-hook call bound to that session, with the loop busy (a model request is mid-turn). The hooks' * failures and what they sent travel with the output, as they do on every loop-hook reply. */ export declare function loopHookRequestHooks(loopHooks: (event: string, payload: WireJson) => Promise<unknown>, scope: ExecutionScope): HookServePorts["runRequestHooks"]; //# sourceMappingURL=hook-contract.d.ts.map