@toren-run/client 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -87,6 +87,19 @@ export declare class TorenClient {
87
87
  listRuns(): Promise<RunSummary[]>;
88
88
  getRun(runId: string): Promise<RunDetail>;
89
89
  getEvents(runId: string): Promise<RunEvents>;
90
+ /**
91
+ * Follow a run's events live over SSE until it settles. Calls onEvent per
92
+ * event; resolves when the run is terminal or the server closes the stream.
93
+ */
94
+ tailRun(runId: string, onEvent: (e: {
95
+ streamId: string;
96
+ seq: number;
97
+ type: string;
98
+ payload: Record<string, unknown>;
99
+ recordedAt: string;
100
+ }) => void): Promise<void>;
101
+ /** Retire a run: retries stop and queued work for it becomes a no-op. */
102
+ cancelRun(runId: string): Promise<void>;
90
103
  approve(runId: string, req: {
91
104
  taskId: string;
92
105
  stepId: string;
package/dist/index.js CHANGED
@@ -63,6 +63,40 @@ export class TorenClient {
63
63
  async getEvents(runId) {
64
64
  return this.request("GET", `/runs/${encodeURIComponent(runId)}/events`);
65
65
  }
66
+ /**
67
+ * Follow a run's events live over SSE until it settles. Calls onEvent per
68
+ * event; resolves when the run is terminal or the server closes the stream.
69
+ */
70
+ async tailRun(runId, onEvent) {
71
+ const res = await this.fetchImpl(`${this.base}/runs/${encodeURIComponent(runId)}/events/stream`, {
72
+ headers: { authorization: `Bearer ${this.cfg.token}` },
73
+ });
74
+ if (!res.ok || !res.body)
75
+ throw new TorenApiError(res.status, `tail failed: HTTP ${res.status}`);
76
+ const reader = res.body.getReader();
77
+ const decoder = new TextDecoder();
78
+ let buf = "";
79
+ for (;;) {
80
+ const { value, done } = await reader.read();
81
+ if (done)
82
+ return;
83
+ buf += decoder.decode(value, { stream: true });
84
+ let i;
85
+ while ((i = buf.indexOf("\n\n")) >= 0) {
86
+ const frame = buf.slice(0, i);
87
+ buf = buf.slice(i + 2);
88
+ if (frame.includes("event: done"))
89
+ return;
90
+ const data = frame.split("\n").find((l) => l.startsWith("data: "));
91
+ if (data)
92
+ onEvent(JSON.parse(data.slice(6)));
93
+ }
94
+ }
95
+ }
96
+ /** Retire a run: retries stop and queued work for it becomes a no-op. */
97
+ async cancelRun(runId) {
98
+ await this.request("POST", `/runs/${encodeURIComponent(runId)}/cancel`);
99
+ }
66
100
  async approve(runId, req) {
67
101
  await this.request("POST", `/runs/${encodeURIComponent(runId)}/approvals`, req);
68
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toren-run/client",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -10,8 +10,8 @@
10
10
  },
11
11
  "devDependencies": {
12
12
  "zod": "^3.23.0",
13
- "@toren-run/core": "^0.1.1",
14
- "toren-run": "^0.1.1"
13
+ "@toren-run/core": "^0.1.3",
14
+ "toren-run": "^0.1.3"
15
15
  },
16
16
  "description": "TypeScript client SDK for the Toren HTTP API.",
17
17
  "license": "Apache-2.0",