@parcha/agentrun-client 0.1.0-beta.33 → 0.1.0-beta.34

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/README.md CHANGED
@@ -59,6 +59,11 @@ const bytes = await client.runs.readFile(done.run_id, "notes.md"); // a Uint8Arr
59
59
  const response = await client.runs.readFile(done.run_id, "notes.md", undefined, { stream: true }); // the Response, unread
60
60
  ```
61
61
 
62
+ With `{ stream: true }` a download resolves to a `Response` of the client's own: the server's status and headers on it
63
+ (its `url` is empty), its body unread. A read of that body that fails (the call's `timeoutMs` passes before the body
64
+ ends, or the body is cut before its length) rejects with `AgentRunUnreachable` and the failure's code, or with your
65
+ `signal`'s reason once you aborted, never the platform's own error. Nothing is tried again: what was read is yours.
66
+
62
67
  `runs.follow` reads the route's event stream and resumes a dropped connection with `Last-Event-ID`, so no page comes twice.
63
68
  Only the server's silence counts as a dropped connection (`idleMs`, default 45000), never the time your loop spends on a
64
69
  page.
package/dist/client.js CHANGED
@@ -123,6 +123,8 @@ export class AgentRun {
123
123
  streamed: op.answer === "bytes" && options?.stream === true,
124
124
  });
125
125
  const answer = await readAnswer(op, route, response, options?.stream === true, secretOp ? scrubberOf(secrets) : undefined);
126
+ if (answer instanceof Response)
127
+ return guarded(answer, this.baseUrl, options?.signal);
126
128
  return op.tagged ? { body: answer, etag: response.headers.get("etag") } : answer;
127
129
  }
128
130
  /** One request to the server with the key: tried again when it may be, its redirects followed only within the base
@@ -237,6 +239,32 @@ async function refusal(x, response, apiKey, late) {
237
239
  return new AgentRunRefused(x.route, response.status, code, error, undefined, wait > 0 ? wait : undefined);
238
240
  }
239
241
  const badAnswer = (route, status, what) => new AgentRunRefused(route, status, "bad_answer", undefined, `The server's answer to ${route} is not ${what}.`);
242
+ /** A download's Response, asked to stream, with its body guarded: a read that fails (the call's timeout passes before
243
+ * the body ends, the body is cut before its length) rejects with AgentRunUnreachable and the failure's code, or with the
244
+ * caller's own reason once its signal aborted, never the platform's error. It is a Response of the client's own, the
245
+ * server's status and headers on it (its `url` is empty); nothing is tried again, since what was read is the caller's. */
246
+ function guarded(response, baseUrl, signal) {
247
+ const source = response.body;
248
+ if (source === null)
249
+ return response;
250
+ const reader = source.getReader();
251
+ const body = new ReadableStream({
252
+ async pull(controller) {
253
+ try {
254
+ const { done, value } = await reader.read();
255
+ if (done)
256
+ controller.close();
257
+ else
258
+ controller.enqueue(value);
259
+ }
260
+ catch (error) {
261
+ controller.error(signal?.aborted ? signal.reason : new AgentRunUnreachable(baseUrl, causeOf(error)));
262
+ }
263
+ },
264
+ cancel: (reason) => reader.cancel(reason),
265
+ });
266
+ return new Response(body, { status: response.status, statusText: response.statusText, headers: response.headers });
267
+ }
240
268
  /** A success's body as the operation answers: JSON parsed (a secret body's values cut from it), text as a string, a
241
269
  * file's bytes as they came, or the Response itself for a download asked to stream. */
242
270
  async function readAnswer(op, route, response, stream, scrub) {
package/dist/http.d.ts CHANGED
@@ -28,7 +28,11 @@ export declare const MAX_RETRY_AFTER_MS = 60000;
28
28
  export declare const wholeMs: (ms: number) => number;
29
29
  /** The wait before try `tries + 1`: doubling up to its cap, and never under the server's own (`floor`). */
30
30
  export declare const backoff: (tries: number, floor?: number) => number;
31
- /** Waits `ms`, or rejects with the signal's reason once it aborts. */
31
+ /**
32
+ * Waits `ms` by the wall clock (Date.now), or rejects with the signal's reason once it aborts. A timer can fire up to a
33
+ * millisecond before the wall clock says `ms` have passed (its loop clock counts whole milliseconds), so the rest is
34
+ * waited out: a server's Retry-After is never cut short.
35
+ */
32
36
  export declare function pause(ms: number, signal?: AbortSignal): Promise<void>;
33
37
  /** A path argument checked and encoded: whole, or, for a file path, segment by segment. One that fetch or the server
34
38
  * would read as another route (empty, `.`, `..`, plain or encoded, or an encoded slash in a file path) is refused. */
package/dist/http.js CHANGED
@@ -14,13 +14,28 @@ const MAX_BACKOFF_MS = 30_000;
14
14
  export const wholeMs = (ms) => Math.max(1, Math.ceil(ms));
15
15
  /** The wait before try `tries + 1`: doubling up to its cap, and never under the server's own (`floor`). */
16
16
  export const backoff = (tries, floor = 0) => Math.max(floor, Math.min(MAX_BACKOFF_MS, BACKOFF_MS * 2 ** (tries - 1)));
17
- /** Waits `ms`, or rejects with the signal's reason once it aborts. */
17
+ /**
18
+ * Waits `ms` by the wall clock (Date.now), or rejects with the signal's reason once it aborts. A timer can fire up to a
19
+ * millisecond before the wall clock says `ms` have passed (its loop clock counts whole milliseconds), so the rest is
20
+ * waited out: a server's Retry-After is never cut short.
21
+ */
18
22
  export function pause(ms, signal) {
19
23
  return new Promise((resolve, reject) => {
20
24
  if (signal?.aborted)
21
25
  return reject(signal.reason);
22
- const timer = setTimeout(() => (signal?.removeEventListener("abort", stop), resolve()), wholeMs(ms));
26
+ const until = Date.now() + wholeMs(ms);
27
+ let timer;
28
+ const arm = (left) => {
29
+ timer = setTimeout(() => {
30
+ const rest = until - Date.now();
31
+ if (rest > 0)
32
+ return arm(rest);
33
+ signal?.removeEventListener("abort", stop);
34
+ resolve();
35
+ }, left);
36
+ };
23
37
  const stop = () => (clearTimeout(timer), reject(signal.reason));
38
+ arm(wholeMs(ms));
24
39
  signal?.addEventListener("abort", stop, { once: true });
25
40
  });
26
41
  }
@@ -28,6 +28,10 @@ export type DefinitionInput = {
28
28
  computer?: {
29
29
  kind: "none" | "sandbox" | "desktop" | "phone" | "browser";
30
30
  provider?: string;
31
+ gpu?: {
32
+ type: string;
33
+ count: number;
34
+ };
31
35
  };
32
36
  tool_settings?: {
33
37
  read?: {
@@ -41,6 +45,7 @@ export type DefinitionInput = {
41
45
  };
42
46
  bash?: {
43
47
  permission?: "allow" | "ask" | "deny";
48
+ policy?: "read-only";
44
49
  };
45
50
  ask_person?: {
46
51
  permission?: "allow" | "deny";
@@ -377,7 +382,7 @@ export type Run = {
377
382
  epoch: number;
378
383
  until: string;
379
384
  } | null;
380
- place?: {
385
+ place: {
381
386
  mode: "runner";
382
387
  } | {
383
388
  mode: "sandbox";
@@ -582,7 +587,7 @@ export type Capabilities = {
582
587
  platform?: string;
583
588
  };
584
589
  runtimes: Array<string>;
585
- models?: {
590
+ models: {
586
591
  source: "managed" | "chatgpt" | "env" | "faux" | "gateway" | "providers";
587
592
  default?: string | null;
588
593
  fast?: string | null;
@@ -595,13 +600,13 @@ export type Capabilities = {
595
600
  features: Features;
596
601
  regions: Array<Region>;
597
602
  limits: Limits;
598
- learning?: {
603
+ learning: {
599
604
  grade_model: string | null;
600
605
  pending: true;
601
606
  approve: boolean;
602
607
  approve_needs?: "password";
603
608
  };
604
- places?: {
609
+ places: {
605
610
  modes: Array<"runner" | "sandbox">;
606
611
  boxes: Array<{
607
612
  id: "bwrap" | "docker" | "modal" | "daytona";
@@ -612,7 +617,7 @@ export type Capabilities = {
612
617
  network_reason?: string;
613
618
  host_addresses?: Array<string>;
614
619
  }>;
615
- default_place?: {
620
+ default_place: {
616
621
  mode: "runner";
617
622
  } | {
618
623
  mode: "sandbox";
@@ -631,7 +636,7 @@ export type Capabilities = {
631
636
  reason?: string;
632
637
  installs?: "on_first_use";
633
638
  }>;
634
- tools?: Array<{
639
+ tools: Array<{
635
640
  name: string;
636
641
  summary: string;
637
642
  blurb?: string;
@@ -1210,6 +1215,23 @@ export type ListComputersResponse = {
1210
1215
  required: Array<string>;
1211
1216
  ready: boolean;
1212
1217
  why?: string;
1218
+ gpu?: {
1219
+ types: Array<string>;
1220
+ max: number;
1221
+ isolation?: "container" | "gvisor" | "microvm" | "vm" | "machine";
1222
+ preemptible?: boolean;
1223
+ stopDeletes?: boolean;
1224
+ region?: string;
1225
+ perGpu?: {
1226
+ cpus: number;
1227
+ memoryMb: number;
1228
+ diskMb: number;
1229
+ };
1230
+ mounts?: Array<string>;
1231
+ fence?: "netns" | "userns-netns";
1232
+ why?: string;
1233
+ };
1234
+ network?: string;
1213
1235
  }>;
1214
1236
  why?: string;
1215
1237
  }>;
@@ -1237,50 +1259,6 @@ export type PutWorkspaceArchilResponse = {
1237
1259
  s3Url?: string;
1238
1260
  image?: string;
1239
1261
  };
1240
- /** Fire a GitHub trigger: a request it checks, no token (POST /hooks/github). */
1241
- export type ReceiveHookGithubResponse = {
1242
- firings: Array<{
1243
- key: string;
1244
- by: "schedule" | "manual" | "webhook" | "github";
1245
- nominal_at: string;
1246
- status: "due" | "started" | "sent" | "skipped" | "failed" | "missed";
1247
- at: string;
1248
- run_id: string | null;
1249
- reason: string | null;
1250
- error: {
1251
- code: string;
1252
- message: string;
1253
- } | null;
1254
- count?: number;
1255
- attempts?: number;
1256
- retry_at?: string;
1257
- catch_up?: true;
1258
- } | {
1259
- ok: "duplicate";
1260
- }>;
1261
- } | {
1262
- ok: "ignored";
1263
- } | Record<string, unknown> | {
1264
- firings: Array<{
1265
- key: string;
1266
- by: "schedule" | "manual" | "webhook" | "github";
1267
- nominal_at: string;
1268
- status: "due" | "started" | "sent" | "skipped" | "failed" | "missed";
1269
- at: string;
1270
- run_id: string | null;
1271
- reason: string | null;
1272
- error: {
1273
- code: string;
1274
- message: string;
1275
- } | null;
1276
- count?: number;
1277
- attempts?: number;
1278
- retry_at?: string;
1279
- catch_up?: true;
1280
- } | {
1281
- ok: "duplicate";
1282
- }>;
1283
- };
1284
1262
  /** Save a computer provider's keys, sealed (PUT /computers/{provider}/keys). */
1285
1263
  export type SaveComputerKeysBody = Record<string, string | null>;
1286
1264
  export type SaveComputerKeysResponse = {
@@ -1296,6 +1274,23 @@ export type SaveComputerKeysResponse = {
1296
1274
  required: Array<string>;
1297
1275
  ready: boolean;
1298
1276
  why?: string;
1277
+ gpu?: {
1278
+ types: Array<string>;
1279
+ max: number;
1280
+ isolation?: "container" | "gvisor" | "microvm" | "vm" | "machine";
1281
+ preemptible?: boolean;
1282
+ stopDeletes?: boolean;
1283
+ region?: string;
1284
+ perGpu?: {
1285
+ cpus: number;
1286
+ memoryMb: number;
1287
+ diskMb: number;
1288
+ };
1289
+ mounts?: Array<string>;
1290
+ fence?: "netns" | "userns-netns";
1291
+ why?: string;
1292
+ };
1293
+ network?: string;
1299
1294
  };
1300
1295
  /** Start signing in to an MCP server with OAuth: the page the owner opens (POST /settings/mcp-servers/{name}/oauth/start). Its body's string values are secrets: each copy is cut from the answer, and a refusal keeps only its code. */
1301
1296
  export type StartMcpOAuthBody = {
@@ -1399,7 +1394,6 @@ export type ListMcpServersResponse = {
1399
1394
  updated_at: string;
1400
1395
  secret?: SecretMeta;
1401
1396
  }>;
1402
- file_unreadable?: true;
1403
1397
  };
1404
1398
  /** This server's OAuth client metadata document (GET /settings/mcp-servers/oauth/client.json). */
1405
1399
  export type McpOAuthClientResponse = Record<string, unknown>;
@@ -1972,6 +1966,9 @@ export type ListTemplatesResponse = {
1972
1966
  } | null;
1973
1967
  effort: string | null;
1974
1968
  tools: Array<string> | null;
1969
+ tool_policy: {
1970
+ bash: "read-only";
1971
+ } | null;
1975
1972
  mcp: Array<{
1976
1973
  server: string;
1977
1974
  required: boolean;
@@ -1988,6 +1985,7 @@ export type ListTemplatesResponse = {
1988
1985
  description: string;
1989
1986
  pattern?: string;
1990
1987
  enum?: Array<string | number | boolean>;
1988
+ format?: "cron" | "timezone";
1991
1989
  default?: string | number | boolean;
1992
1990
  }>;
1993
1991
  secrets: Array<string>;
@@ -2031,7 +2029,7 @@ export type ListToolKeysResponse = {
2031
2029
  } | null;
2032
2030
  }>;
2033
2031
  reenter: {
2034
- reason: "seal_key_missing" | "seal_key_changed" | "file_unreadable";
2032
+ reason: "seal_key_changed" | "file_unreadable";
2035
2033
  fields: Array<string>;
2036
2034
  } | null;
2037
2035
  };
@@ -2750,7 +2748,7 @@ export type GetWebhookResponse = {
2750
2748
  configured: true;
2751
2749
  url: string;
2752
2750
  secret: SecretMeta;
2753
- signing: "sealed" | "seal_key_missing" | "unreadable";
2751
+ signing: "sealed" | "unreadable";
2754
2752
  disabled: {
2755
2753
  at: string;
2756
2754
  reason: string;
@@ -2776,7 +2774,7 @@ export type SaveWebhookResponse = {
2776
2774
  configured: true;
2777
2775
  url: string;
2778
2776
  secret: SecretMeta;
2779
- signing: "sealed" | "seal_key_missing" | "unreadable";
2777
+ signing: "sealed" | "unreadable";
2780
2778
  disabled: {
2781
2779
  at: string;
2782
2780
  reason: string;
@@ -2786,7 +2784,7 @@ export type SaveWebhookResponse = {
2786
2784
  configured: true;
2787
2785
  url: string;
2788
2786
  secret: SecretMeta;
2789
- signing: "sealed" | "seal_key_missing" | "unreadable";
2787
+ signing: "sealed" | "unreadable";
2790
2788
  disabled: {
2791
2789
  at: string;
2792
2790
  reason: string;
@@ -2797,7 +2795,7 @@ export type SaveWebhookResponse = {
2797
2795
  configured: true;
2798
2796
  url: string;
2799
2797
  secret: SecretMeta;
2800
- signing: "sealed" | "seal_key_missing" | "unreadable";
2798
+ signing: "sealed" | "unreadable";
2801
2799
  disabled: {
2802
2800
  at: string;
2803
2801
  reason: string;
@@ -2889,8 +2887,6 @@ export declare function resources(call: Call): {
2889
2887
  write: (agentId: string, file: string, body: WriteLearningFileBody | RawBody, params?: WriteLearningFileParams, options?: BodyOptions) => Promise<Tagged<string>>;
2890
2888
  };
2891
2889
  local: {
2892
- /** Start Connect GitHub: the app-manifest form the console posts to GitHub (POST /integrations/github/connect). */
2893
- connectGitHub: (body?: ConnectGitHubBody, options?: RequestOptions) => Promise<ConnectGitHubResponse>;
2894
2890
  /** Turn Mode 2 off: run folders on this server's own disk (DELETE /workspace/archil). */
2895
2891
  deleteWorkspaceArchil: (options?: RequestOptions) => Promise<DeleteWorkspaceArchilResponse>;
2896
2892
  /** Disconnect GitHub: the App's credentials gone from this server, and every github trigger off (DELETE /integrations/github). */
@@ -2899,20 +2895,12 @@ export declare function resources(call: Call): {
2899
2895
  getGitHubConnection: (options?: RequestOptions) => Promise<GetGitHubConnectionResponse>;
2900
2896
  /** Whether run folders are on an Archil disk (Mode 2), its settings, and whether its keys are saved (GET /workspace/archil). */
2901
2897
  getWorkspaceArchil: (options?: RequestOptions) => Promise<GetWorkspaceArchilResponse>;
2902
- /** Where GitHub sends the owner's browser back with the new App's code (GET /integrations/github/callback). */
2903
- gitHubCallback: (params?: GitHubCallbackParams, options?: RequestOptions) => Promise<void>;
2904
- /** Where GitHub sends the browser once the App is installed (GET /integrations/github/installed). */
2905
- gitHubInstalled: (params?: GitHubInstalledParams, options?: RequestOptions) => Promise<void>;
2906
2898
  /** Settings → Computers: the kinds of computer this server offers, each provider and whether its keys are saved (GET /computers). */
2907
2899
  listComputers: (options?: RequestOptions) => Promise<ListComputersResponse>;
2908
2900
  /** Turn Mode 2 on: run folders on this Archil disk (PUT /workspace/archil). */
2909
2901
  putWorkspaceArchil: (body: PutWorkspaceArchilBody, options?: RequestOptions) => Promise<PutWorkspaceArchilResponse>;
2910
- /** Fire a GitHub trigger: a request it checks, no token (POST /hooks/github). */
2911
- receiveHookGithub: (body: RawBody, options?: BodyOptions) => Promise<ReceiveHookGithubResponse>;
2912
2902
  /** Save a computer provider's keys, sealed (PUT /computers/{provider}/keys). */
2913
2903
  saveComputerKeys: (provider: string, body: SaveComputerKeysBody, options?: RequestOptions) => Promise<SaveComputerKeysResponse>;
2914
- /** Start signing in to an MCP server with OAuth: the page the owner opens (POST /settings/mcp-servers/{name}/oauth/start). */
2915
- startMcpOauth: (name: string, body: StartMcpOAuthBody, options?: RequestOptions) => Promise<StartMcpOAuthResponse>;
2916
2904
  /** Test a computer provider's account with its saved keys (POST /computers/{provider}/test). */
2917
2905
  testComputer: (provider: string, options?: RequestOptions) => Promise<TestComputerResponse>;
2918
2906
  /** Test the Archil disk with its saved account key (POST /workspace/archil/test). */
@@ -32,7 +32,6 @@ export const OPERATIONS = {
32
32
  gitHubInstalled: { "method": "GET", "path": "/integrations/github/installed", "pathParams": [], "multiSegment": [], "query": ["installation_id", "setup_action", "state"], "headers": [], "body": null, "answer": "none", "secret": false, "publicFields": [], "tagged": false },
33
33
  listComputers: { "method": "GET", "path": "/computers", "pathParams": [], "multiSegment": [], "query": [], "headers": [], "body": null, "answer": "json", "secret": false, "publicFields": [], "tagged": false },
34
34
  putWorkspaceArchil: { "method": "PUT", "path": "/workspace/archil", "pathParams": [], "multiSegment": [], "query": [], "headers": [], "body": { "required": true, "types": ["application/json"] }, "answer": "json", "secret": false, "publicFields": [], "tagged": false },
35
- receiveHook_github: { "method": "POST", "path": "/hooks/github", "pathParams": [], "multiSegment": [], "query": [], "headers": [], "body": { "required": true, "types": ["*/*"] }, "answer": "json", "secret": false, "publicFields": [], "tagged": false },
36
35
  saveComputerKeys: { "method": "PUT", "path": "/computers/{provider}/keys", "pathParams": ["provider"], "multiSegment": [], "query": [], "headers": [], "body": { "required": true, "types": ["application/json"] }, "answer": "json", "secret": false, "publicFields": [], "tagged": false },
37
36
  startMcpOAuth: { "method": "POST", "path": "/settings/mcp-servers/{name}/oauth/start", "pathParams": ["name"], "multiSegment": [], "query": [], "headers": [], "body": { "required": true, "types": ["application/json"] }, "answer": "json", "secret": true, "publicFields": ["url", "scopes.[]", "client_id"], "tagged": false },
38
37
  testComputer: { "method": "POST", "path": "/computers/{provider}/test", "pathParams": ["provider"], "multiSegment": [], "query": [], "headers": [], "body": null, "answer": "json", "secret": false, "publicFields": [], "tagged": false },
@@ -154,8 +153,6 @@ export function resources(call) {
154
153
  write: (agentId, file, body, params, options) => call("writeLearningFile", [agentId, file], body, params, options),
155
154
  },
156
155
  local: {
157
- /** Start Connect GitHub: the app-manifest form the console posts to GitHub (POST /integrations/github/connect). */
158
- connectGitHub: (body, options) => call("connectGitHub", [], body, undefined, options),
159
156
  /** Turn Mode 2 off: run folders on this server's own disk (DELETE /workspace/archil). */
160
157
  deleteWorkspaceArchil: (options) => call("deleteWorkspaceArchil", [], undefined, undefined, options),
161
158
  /** Disconnect GitHub: the App's credentials gone from this server, and every github trigger off (DELETE /integrations/github). */
@@ -164,20 +161,12 @@ export function resources(call) {
164
161
  getGitHubConnection: (options) => call("getGitHubConnection", [], undefined, undefined, options),
165
162
  /** Whether run folders are on an Archil disk (Mode 2), its settings, and whether its keys are saved (GET /workspace/archil). */
166
163
  getWorkspaceArchil: (options) => call("getWorkspaceArchil", [], undefined, undefined, options),
167
- /** Where GitHub sends the owner's browser back with the new App's code (GET /integrations/github/callback). */
168
- gitHubCallback: (params, options) => call("gitHubCallback", [], undefined, params, options),
169
- /** Where GitHub sends the browser once the App is installed (GET /integrations/github/installed). */
170
- gitHubInstalled: (params, options) => call("gitHubInstalled", [], undefined, params, options),
171
164
  /** Settings → Computers: the kinds of computer this server offers, each provider and whether its keys are saved (GET /computers). */
172
165
  listComputers: (options) => call("listComputers", [], undefined, undefined, options),
173
166
  /** Turn Mode 2 on: run folders on this Archil disk (PUT /workspace/archil). */
174
167
  putWorkspaceArchil: (body, options) => call("putWorkspaceArchil", [], body, undefined, options),
175
- /** Fire a GitHub trigger: a request it checks, no token (POST /hooks/github). */
176
- receiveHookGithub: (body, options) => call("receiveHook_github", [], body, undefined, options),
177
168
  /** Save a computer provider's keys, sealed (PUT /computers/{provider}/keys). */
178
169
  saveComputerKeys: (provider, body, options) => call("saveComputerKeys", [provider], body, undefined, options),
179
- /** Start signing in to an MCP server with OAuth: the page the owner opens (POST /settings/mcp-servers/{name}/oauth/start). */
180
- startMcpOauth: (name, body, options) => call("startMcpOAuth", [name], body, undefined, options),
181
170
  /** Test a computer provider's account with its saved keys (POST /computers/{provider}/test). */
182
171
  testComputer: (provider, options) => call("testComputer", [provider], undefined, undefined, options),
183
172
  /** Test the Archil disk with its saved account key (POST /workspace/archil/test). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-client",
3
- "version": "0.1.0-beta.33",
3
+ "version": "0.1.0-beta.34",
4
4
  "description": "A typed TypeScript client for a self-hosted AgentRun server: a method per operation of its API, typed from its OpenAPI document, with waiting for a run and following its timeline. No dependencies; fetch only.",
5
5
  "keywords": [
6
6
  "agentrun",