SPB Git

Repository Public

kernel-port.ts 2.6 KB 51 lines typescript

1/**2 * The narrow slice of `@aos/kernel` the server needs (CONTRACT §2). Everything the kernel owns3 * as a WRITE goes through this port; reads are plain SQL in the server. `buildServer` receives an4 * implementation: `kernel-adapter.ts` (real kernel) or `testkit/fake-kernel.ts` (tests).5 */6import type { Readable } from 'node:stream';7import type { AosEvent, Effort, Provider } from '@aos/shared';89export interface CreateMissionInput {10  ownerId: string;11  projectId: string;12  title: string;13  objective: string;14  /**15   * The owner's done criteria, possibly EMPTY. The kernel builds the root `DelegationContract`16   * itself and stores the list as given (the `min(1)` of the shared schema applies to spawns17   * only): an empty `contract.doneCriteria` / `missions.done_criteria = []` is the signal for the18   * engine to propose criteria first and have the owner confirm them (CONTRACT §5.1).19   */20  doneCriteria: string[];21  provider: Provider;22  model: string;23  effort: Effort | null;24  /** Mission budget = usd limit of the root run; turns / wall-clock limits are the kernel defaults. */25  budgetUsd: number;26  network: 'none' | 'open';27  /** realpath(AOS_WORKSPACE_ROOT/rel_path), verified by the server. */28  workspaceAbs: string;29}3031export interface KernelPort {32  /** Creates the mission and its queued root run in one transaction; emits mission.created / run.created. */33  createMission(input: CreateMissionInput): Promise<{ missionId: string; rootRunId: string }>;34  /** Cascades to every run of the mission; pending waits → cancelled; queued / waiting runs → cancelled at once. Idempotent. */35  requestCancel(missionId: string): Promise<void>;36  /**37   * Marks a pending approval / question resolved, emits wait.resolved, re-queues the run.38   * `resolved: false` ⇒ the wait was no longer pending (nothing changed). Rejects when unknown.39   */40  resolveWait(waitId: string, resolution: Record<string, unknown>, actor: string): Promise<{ resolved: boolean }>;41  /** Appends an `owner.message` event (trust 'owner') for a live run; rejects when the run has ended. */42  postOwnerMessage(runId: string, text: string): Promise<void>;43  /**44   * Every event appended from now on (LISTEN + poll fallback), exactly once and in id order, plus45   * transient `model.delta` events (`id: -1`). Resolves once listening; the returned function stops it.46   */47  listenEvents(cb: (event: AosEvent) => void): Promise<() => Promise<void>>;48  /** Content stream of an artifact under `$AOS_DATA_DIR/artifacts`; null when the blob is missing. */49  openArtifact(sha256: string): Promise<Readable | null>;50}51
Files main
Menu

Theme