@m8tes/sdk 0.1.0-alpha.2 → 0.1.0-alpha.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.cts CHANGED
@@ -91,14 +91,17 @@ declare function createHttp(options?: ClientOptions): Http;
91
91
  interface ListResponse<T> {
92
92
  data: T[];
93
93
  hasMore: boolean;
94
+ /** Cursor for `?starting_after=` when `hasMore` is true; mirrors the Python SDK. */
95
+ nextStartingAfter?: string | number | null;
94
96
  }
95
97
  /** A page of results. `for await (const item of page)` walks ALL pages. */
96
98
  declare class Page<T> implements ListResponse<T>, AsyncIterable<T> {
97
99
  readonly data: T[];
98
100
  readonly hasMore: boolean;
101
+ readonly nextStartingAfter?: string | number | null;
99
102
  /** Fetches the next page given a cursor. Absent on a terminal page. */
100
103
  private readonly fetchNext?;
101
- constructor(data: T[], hasMore: boolean, fetchNext?: (startingAfter: string | number) => Promise<Page<T>>);
104
+ constructor(data: T[], hasMore: boolean, fetchNext?: (startingAfter: string | number) => Promise<Page<T>>, nextStartingAfter?: string | number | null);
102
105
  /**
103
106
  * Auto-paging: yields every item across every page.
104
107
  *
@@ -228,6 +231,10 @@ interface PermissionRequest {
228
231
  created_at: string;
229
232
  resolved_at: string | null;
230
233
  auto_resolved?: boolean;
234
+ /** False when the runtime would ignore an "always allow" for this tool. */
235
+ can_remember?: boolean;
236
+ /** False when the Always-allow control must start unticked (force-ask floor). */
237
+ remember_default?: boolean;
231
238
  }
232
239
  interface Task {
233
240
  id: number;
@@ -429,6 +436,8 @@ interface PermissionPolicy {
429
436
  user_id: string;
430
437
  tool_name: string;
431
438
  created_at: string;
439
+ /** Which surface minted the grant ("run_approval" / "api"); null on legacy rows. */
440
+ source?: string | null;
432
441
  }
433
442
  /**
434
443
  * Billing usage and limits for the current period.
@@ -452,6 +461,8 @@ interface Usage {
452
461
  overage_cap_cents: number;
453
462
  overage_rate_cents: number;
454
463
  trial_ends_at?: string | null;
464
+ /** True when the account bypasses the included-runs meter (admin/unlimited). */
465
+ unlimited_runs?: boolean;
455
466
  }
456
467
  /** Token + USD totals over a usage-timeseries window. `cost_usd` is a string. */
457
468
  interface UsageTotals {
@@ -1104,6 +1115,11 @@ interface PollOptions {
1104
1115
  timeout?: number;
1105
1116
  /** Abort the wait early. The in-flight request is cancelled with it. */
1106
1117
  signal?: AbortSignal;
1118
+ /**
1119
+ * End-user scope for each `GET /runs/{id}` poll. Required when the account
1120
+ * has strict multi-tenant mode on — without it every poll 422s.
1121
+ */
1122
+ user_id?: string;
1107
1123
  }
1108
1124
  interface WaitOptions extends PollOptions {
1109
1125
  /**
@@ -1329,8 +1345,13 @@ interface ApproveParams {
1329
1345
  request_id: string;
1330
1346
  decision: "allow" | "deny";
1331
1347
  /**
1332
- * Apply the same decision to matching tool requests for the rest of THIS run.
1333
- * For a policy that outlives the run, use the permissions API instead.
1348
+ * Persist beyond this single gate.
1349
+ * - `false` (default): this request only.
1350
+ * - `true` + allow: also silence matching tools for the rest of THIS run AND
1351
+ * store a cross-run always-allow policy (scoped to the run's end-user when
1352
+ * set; revoke via `/permissions`).
1353
+ * - `true` + deny: deny matching tools for the rest of THIS run only (no
1354
+ * stored policy).
1334
1355
  */
1335
1356
  remember?: boolean;
1336
1357
  }
@@ -1371,12 +1392,17 @@ interface RunsResource {
1371
1392
  stream(runId: number, options?: RunStreamOptions): RunStream;
1372
1393
  /** Continue the conversation on an existing run, streaming the reply. */
1373
1394
  reply(runId: number, message: string, options?: RunStreamOptions): RunStream;
1374
- /** GET /runs/{id} takes NO query params it is already account-scoped, and
1375
- * sending `user_id` returns 422 `unknown_query_parameter`. */
1376
- get(runId: number): Promise<Run>;
1395
+ /** GET /runs/{id}. Pass `user_id` to scope to one end-user (required when the
1396
+ * account has strict multi-tenant mode on). */
1397
+ get(runId: number, params?: {
1398
+ user_id?: string;
1399
+ }): Promise<Run>;
1377
1400
  list(params?: RunListParams): Promise<Page<Run>>;
1378
- /** Cancel a running run. Returns the updated Run, like the Python SDK. */
1379
- cancel(runId: number): Promise<Run>;
1401
+ /** Cancel a running run. Returns the updated Run, like the Python SDK.
1402
+ * Pass `user_id` when the account has strict multi-tenant mode on. */
1403
+ cancel(runId: number, params?: {
1404
+ user_id?: string;
1405
+ }): Promise<Run>;
1380
1406
  /** Approve or deny a pending tool-permission gate. */
1381
1407
  approve(runId: number, params: ApproveParams): Promise<PermissionRequest>;
1382
1408
  /** Answer a pending AskUserQuestion gate, resuming the run. */
@@ -1672,7 +1698,7 @@ interface WebhooksResource {
1672
1698
  */
1673
1699
 
1674
1700
  /** Kept in lockstep with package.json "version" — guarded by test/version.test.ts. */
1675
- declare const M8TES_SDK_VERSION = "0.1.0-alpha.2";
1701
+ declare const M8TES_SDK_VERSION = "0.1.0-alpha.3";
1676
1702
  declare class M8tes {
1677
1703
  readonly runs: RunsResource;
1678
1704
  readonly agents: AgentsResource;
package/dist/index.d.ts CHANGED
@@ -91,14 +91,17 @@ declare function createHttp(options?: ClientOptions): Http;
91
91
  interface ListResponse<T> {
92
92
  data: T[];
93
93
  hasMore: boolean;
94
+ /** Cursor for `?starting_after=` when `hasMore` is true; mirrors the Python SDK. */
95
+ nextStartingAfter?: string | number | null;
94
96
  }
95
97
  /** A page of results. `for await (const item of page)` walks ALL pages. */
96
98
  declare class Page<T> implements ListResponse<T>, AsyncIterable<T> {
97
99
  readonly data: T[];
98
100
  readonly hasMore: boolean;
101
+ readonly nextStartingAfter?: string | number | null;
99
102
  /** Fetches the next page given a cursor. Absent on a terminal page. */
100
103
  private readonly fetchNext?;
101
- constructor(data: T[], hasMore: boolean, fetchNext?: (startingAfter: string | number) => Promise<Page<T>>);
104
+ constructor(data: T[], hasMore: boolean, fetchNext?: (startingAfter: string | number) => Promise<Page<T>>, nextStartingAfter?: string | number | null);
102
105
  /**
103
106
  * Auto-paging: yields every item across every page.
104
107
  *
@@ -228,6 +231,10 @@ interface PermissionRequest {
228
231
  created_at: string;
229
232
  resolved_at: string | null;
230
233
  auto_resolved?: boolean;
234
+ /** False when the runtime would ignore an "always allow" for this tool. */
235
+ can_remember?: boolean;
236
+ /** False when the Always-allow control must start unticked (force-ask floor). */
237
+ remember_default?: boolean;
231
238
  }
232
239
  interface Task {
233
240
  id: number;
@@ -429,6 +436,8 @@ interface PermissionPolicy {
429
436
  user_id: string;
430
437
  tool_name: string;
431
438
  created_at: string;
439
+ /** Which surface minted the grant ("run_approval" / "api"); null on legacy rows. */
440
+ source?: string | null;
432
441
  }
433
442
  /**
434
443
  * Billing usage and limits for the current period.
@@ -452,6 +461,8 @@ interface Usage {
452
461
  overage_cap_cents: number;
453
462
  overage_rate_cents: number;
454
463
  trial_ends_at?: string | null;
464
+ /** True when the account bypasses the included-runs meter (admin/unlimited). */
465
+ unlimited_runs?: boolean;
455
466
  }
456
467
  /** Token + USD totals over a usage-timeseries window. `cost_usd` is a string. */
457
468
  interface UsageTotals {
@@ -1104,6 +1115,11 @@ interface PollOptions {
1104
1115
  timeout?: number;
1105
1116
  /** Abort the wait early. The in-flight request is cancelled with it. */
1106
1117
  signal?: AbortSignal;
1118
+ /**
1119
+ * End-user scope for each `GET /runs/{id}` poll. Required when the account
1120
+ * has strict multi-tenant mode on — without it every poll 422s.
1121
+ */
1122
+ user_id?: string;
1107
1123
  }
1108
1124
  interface WaitOptions extends PollOptions {
1109
1125
  /**
@@ -1329,8 +1345,13 @@ interface ApproveParams {
1329
1345
  request_id: string;
1330
1346
  decision: "allow" | "deny";
1331
1347
  /**
1332
- * Apply the same decision to matching tool requests for the rest of THIS run.
1333
- * For a policy that outlives the run, use the permissions API instead.
1348
+ * Persist beyond this single gate.
1349
+ * - `false` (default): this request only.
1350
+ * - `true` + allow: also silence matching tools for the rest of THIS run AND
1351
+ * store a cross-run always-allow policy (scoped to the run's end-user when
1352
+ * set; revoke via `/permissions`).
1353
+ * - `true` + deny: deny matching tools for the rest of THIS run only (no
1354
+ * stored policy).
1334
1355
  */
1335
1356
  remember?: boolean;
1336
1357
  }
@@ -1371,12 +1392,17 @@ interface RunsResource {
1371
1392
  stream(runId: number, options?: RunStreamOptions): RunStream;
1372
1393
  /** Continue the conversation on an existing run, streaming the reply. */
1373
1394
  reply(runId: number, message: string, options?: RunStreamOptions): RunStream;
1374
- /** GET /runs/{id} takes NO query params it is already account-scoped, and
1375
- * sending `user_id` returns 422 `unknown_query_parameter`. */
1376
- get(runId: number): Promise<Run>;
1395
+ /** GET /runs/{id}. Pass `user_id` to scope to one end-user (required when the
1396
+ * account has strict multi-tenant mode on). */
1397
+ get(runId: number, params?: {
1398
+ user_id?: string;
1399
+ }): Promise<Run>;
1377
1400
  list(params?: RunListParams): Promise<Page<Run>>;
1378
- /** Cancel a running run. Returns the updated Run, like the Python SDK. */
1379
- cancel(runId: number): Promise<Run>;
1401
+ /** Cancel a running run. Returns the updated Run, like the Python SDK.
1402
+ * Pass `user_id` when the account has strict multi-tenant mode on. */
1403
+ cancel(runId: number, params?: {
1404
+ user_id?: string;
1405
+ }): Promise<Run>;
1380
1406
  /** Approve or deny a pending tool-permission gate. */
1381
1407
  approve(runId: number, params: ApproveParams): Promise<PermissionRequest>;
1382
1408
  /** Answer a pending AskUserQuestion gate, resuming the run. */
@@ -1672,7 +1698,7 @@ interface WebhooksResource {
1672
1698
  */
1673
1699
 
1674
1700
  /** Kept in lockstep with package.json "version" — guarded by test/version.test.ts. */
1675
- declare const M8TES_SDK_VERSION = "0.1.0-alpha.2";
1701
+ declare const M8TES_SDK_VERSION = "0.1.0-alpha.3";
1676
1702
  declare class M8tes {
1677
1703
  readonly runs: RunsResource;
1678
1704
  readonly agents: AgentsResource;
package/dist/index.js CHANGED
@@ -195,12 +195,14 @@ function createHttp(options = {}) {
195
195
  var Page = class {
196
196
  data;
197
197
  hasMore;
198
+ nextStartingAfter;
198
199
  /** Fetches the next page given a cursor. Absent on a terminal page. */
199
200
  fetchNext;
200
- constructor(data, hasMore, fetchNext) {
201
+ constructor(data, hasMore, fetchNext, nextStartingAfter) {
201
202
  this.data = data;
202
203
  this.hasMore = hasMore;
203
204
  this.fetchNext = fetchNext;
205
+ this.nextStartingAfter = nextStartingAfter ?? null;
204
206
  }
205
207
  /**
206
208
  * Auto-paging: yields every item across every page.
@@ -218,7 +220,10 @@ var Page = class {
218
220
  yield* page.data;
219
221
  const last = page.data.at(-1);
220
222
  if (!page.hasMore || !last || !page.fetchNext) return;
221
- const cursor = typeof last.id === "number" || typeof last.id === "string" ? last.id : typeof last.name === "string" ? last.name : void 0;
223
+ let cursor = page.nextStartingAfter === null || page.nextStartingAfter === void 0 ? void 0 : page.nextStartingAfter;
224
+ if (cursor === void 0) {
225
+ cursor = typeof last.id === "number" || typeof last.id === "string" ? last.id : typeof last.name === "string" ? last.name : void 0;
226
+ }
222
227
  if (cursor === void 0 || seen.has(cursor)) return;
223
228
  seen.add(cursor);
224
229
  page = await page.fetchNext(cursor);
@@ -270,7 +275,8 @@ function createAgentsResource(http) {
270
275
  return new Page(
271
276
  res?.data ?? [],
272
277
  res?.has_more ?? false,
273
- (starting_after) => fetchPage({ ...p, starting_after })
278
+ (starting_after) => fetchPage({ ...p, starting_after }),
279
+ res?.next_starting_after
274
280
  );
275
281
  };
276
282
  return fetchPage({ ...params });
@@ -315,7 +321,7 @@ function createAppsResource(http) {
315
321
  const res = await http.request("GET", "/apps/", {
316
322
  query: toQuery({ user_id: params.user_id })
317
323
  });
318
- return new Page(res?.data ?? [], res?.has_more ?? false);
324
+ return new Page(res?.data ?? [], res?.has_more ?? false, void 0, res?.next_starting_after);
319
325
  };
320
326
  return {
321
327
  list,
@@ -365,7 +371,8 @@ function pager(http, path) {
365
371
  return new Page(
366
372
  res?.data ?? [],
367
373
  res?.has_more ?? false,
368
- (starting_after) => fetchPage({ ...p, starting_after })
374
+ (starting_after) => fetchPage({ ...p, starting_after }),
375
+ res?.next_starting_after
369
376
  );
370
377
  };
371
378
  return fetchPage;
@@ -467,7 +474,7 @@ function createModelsResource(http) {
467
474
  return {
468
475
  async list() {
469
476
  const res = await http.request("GET", "/models/");
470
- return new Page(res?.data ?? [], res?.has_more ?? false);
477
+ return new Page(res?.data ?? [], res?.has_more ?? false, void 0, res?.next_starting_after);
471
478
  }
472
479
  };
473
480
  }
@@ -935,12 +942,15 @@ function createRunsResource(http) {
935
942
  return form;
936
943
  };
937
944
  const hasFiles = (p) => (p.files?.length ?? 0) > 0;
938
- const deps = {
939
- get: (runId, signal) => http.request("GET", `/runs/${seg(runId)}`, { signal }),
945
+ const pollDeps = (userId) => ({
946
+ get: (runId, signal) => http.request("GET", `/runs/${seg(runId)}`, {
947
+ query: toQuery({ user_id: userId }),
948
+ signal
949
+ }),
940
950
  permissions: async (runId, signal) => items(await http.request("GET", `/runs/${seg(runId)}/permissions`, { signal })),
941
951
  approve: (runId, params, signal) => http.request("POST", `/runs/${seg(runId)}/approve`, { body: { remember: false, ...params }, signal }),
942
952
  answer: (runId, params, signal) => http.request("POST", `/runs/${seg(runId)}/answer`, { body: params, signal })
943
- };
953
+ });
944
954
  const createAsync = async (params) => {
945
955
  const headers = idempotencyHeaders(params.idempotencyKey);
946
956
  return hasFiles(params) ? http.request("POST", "/runs/with-files", { form: createForm(params, false), headers }) : http.request("POST", "/runs", { body: createBody(params, false), headers });
@@ -958,18 +968,26 @@ function createRunsResource(http) {
958
968
  createAsync,
959
969
  async createAndWait(params, options = {}) {
960
970
  if (options.signal?.aborted) throw new RunWaitAbortedError();
961
- const started = await createAsync(params);
971
+ if (options.user_id != null && params.user_id != null && options.user_id !== params.user_id) {
972
+ throw new ValidationError(
973
+ `createAndWait: options.user_id (${JSON.stringify(options.user_id)}) conflicts with params.user_id (${JSON.stringify(params.user_id)}). Use one scope for create and poll.`,
974
+ { type: "invalid_request_error", code: 0, status: 0 }
975
+ );
976
+ }
977
+ const createParams = params.user_id == null && options.user_id != null ? { ...params, user_id: options.user_id } : params;
978
+ const started = await createAsync(createParams);
979
+ const userId = started.user_id ?? createParams.user_id ?? void 0;
962
980
  try {
963
- return await waitForRun(deps, started.id, options);
981
+ return await waitForRun(pollDeps(userId), started.id, { ...options, user_id: userId });
964
982
  } catch (err) {
965
983
  throw withRunId(err, started.id);
966
984
  }
967
985
  },
968
- poll(runId, options) {
969
- return pollRun(deps, runId, options);
986
+ poll(runId, options = {}) {
987
+ return pollRun(pollDeps(options.user_id), runId, options);
970
988
  },
971
- wait(runId, options) {
972
- return waitForRun(deps, runId, options);
989
+ wait(runId, options = {}) {
990
+ return waitForRun(pollDeps(options.user_id), runId, options);
973
991
  },
974
992
  // `confirm` is a QUERY param and the route takes no body (verified against
975
993
  // fastapi/app/routers/v2/runs.py::retry_run), so send neither.
@@ -991,8 +1009,10 @@ function createRunsResource(http) {
991
1009
  options
992
1010
  );
993
1011
  },
994
- get(runId) {
995
- return http.request("GET", `/runs/${seg(runId)}`);
1012
+ get(runId, params = {}) {
1013
+ return http.request("GET", `/runs/${seg(runId)}`, {
1014
+ query: toQuery({ user_id: params.user_id })
1015
+ });
996
1016
  },
997
1017
  async list(params = {}) {
998
1018
  const { agent_id, teammate_id, ...rest } = params;
@@ -1004,13 +1024,16 @@ function createRunsResource(http) {
1004
1024
  return new Page(
1005
1025
  res?.data ?? [],
1006
1026
  res?.has_more ?? false,
1007
- (starting_after) => fetchPage({ ...p, starting_after })
1027
+ (starting_after) => fetchPage({ ...p, starting_after }),
1028
+ res?.next_starting_after
1008
1029
  );
1009
1030
  };
1010
1031
  return fetchPage(q);
1011
1032
  },
1012
- cancel(runId) {
1013
- return http.request("POST", `/runs/${seg(runId)}/cancel`, { body: {} });
1033
+ cancel(runId, params = {}) {
1034
+ return http.request("POST", `/runs/${seg(runId)}/cancel`, {
1035
+ query: toQuery({ user_id: params.user_id })
1036
+ });
1014
1037
  },
1015
1038
  approve(runId, params) {
1016
1039
  return http.request("POST", `/runs/${seg(runId)}/approve`, {
@@ -1101,7 +1124,8 @@ function createTasksResource(http) {
1101
1124
  return new Page(
1102
1125
  res?.data ?? [],
1103
1126
  res?.has_more ?? false,
1104
- (starting_after) => fetchPage({ ...p, starting_after })
1127
+ (starting_after) => fetchPage({ ...p, starting_after }),
1128
+ res?.next_starting_after
1105
1129
  );
1106
1130
  };
1107
1131
  return fetchPage(q);
@@ -1204,7 +1228,7 @@ function createWebhooksResource(http) {
1204
1228
  }
1205
1229
 
1206
1230
  // src/index.ts
1207
- var M8TES_SDK_VERSION = "0.1.0-alpha.2";
1231
+ var M8TES_SDK_VERSION = "0.1.0-alpha.3";
1208
1232
  var M8tes = class {
1209
1233
  runs;
1210
1234
  agents;