Fork Horse repository, listed by its owner. Publisher snapshot.

packages/forkhorse-gatekeeper/src/worker/workflow-session.ts

Snapshot at 34e3175

Containing directory

1,705 bytes · typescriptView raw
1import { RpcTarget, RpcStub } from "cloudflare:workers";
2import { validateRpc } from "capnweb-validate";
3import type { ApprovalQueue } from "@gadgets/workshop-shared/gatekeeper";
4import type { ReadReviewResponse, ReadReceiptsResponse } from "../../../forkhorse-stable/src/index.ts";
5import type { AgentWorkflowSession, WorkflowContext } from "../workflow-types.d.ts";
6import { WorkflowActions } from "./workflow.ts";
7
8/** Native RPC workflow; writes return after queuing, never fabricated applied results. */
9@validateRpc()
10export class WorkflowSession extends RpcTarget implements AgentWorkflowSession {
11  constructor(private readonly actions: WorkflowActions, protected readonly queue: RpcStub<ApprovalQueue>) { super(); }
12  async context(): Promise<WorkflowContext> { return this.actions.context(this.queue); }
13  async readReview(review: string): Promise<ReadReviewResponse> { return this.actions.readReview(this.queue, review); }
14  async readReceipts(review: string): Promise<ReadReceiptsResponse> { return this.actions.readReceipts(this.queue, review); }
15  async join(): Promise<void> { await this.actions.submit(this.queue, { kind: "join" }); }
16  async claim(packet: string, repoName?: string): Promise<void> {
17    await this.actions.submit(this.queue, { kind: "claim", packet, ...(repoName === undefined ? {} : { repoName }) });
18  }
19  async requestReview(packet: string, repoName: string, sha: string): Promise<void> {
20    await this.actions.submit(this.queue, { kind: "requestReview", packet, repoName, sha });
21  }
22  async release(packet: string): Promise<void> { await this.actions.submit(this.queue, { kind: "release", packet }); }
23  [Symbol.dispose](): void { this.queue[Symbol.dispose](); }
24}
25