@m8tes/sdk 0.1.0-alpha.5 → 0.1.0-alpha.7

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
@@ -214,6 +214,19 @@ interface Run {
214
214
  retry_count?: number;
215
215
  output_data?: JsonObject | null;
216
216
  usage?: RunUsage | null;
217
+ /**
218
+ * Which meter the run settles on: "api" (prepaid balance — end-user-scoped /
219
+ * embedding work) or "platform" (subscription plan — first-party work, INCLUDING
220
+ * the account's own API-key calls). Stamped at creation.
221
+ */
222
+ billing_surface?: string;
223
+ /**
224
+ * Where the run came in: "api", "app", "cli", "email", "slack", "imessage",
225
+ * "webhook". Attribution only, never billing — a first-party API-key call is
226
+ * channel "api" but billing_surface "platform", so filtering a developer view
227
+ * on surface alone hides your own traffic.
228
+ */
229
+ channel?: string | null;
217
230
  }
218
231
  /** Condensed run result: what happened, without replaying the transcript. */
219
232
  interface RunOutcome {
@@ -244,10 +257,15 @@ interface PermissionRequest {
244
257
  created_at: string;
245
258
  resolved_at: string | null;
246
259
  auto_resolved?: boolean;
260
+ /** Actual saved cross-run grant outcome, also present on listings. Null means unknown. */
261
+ remembered?: boolean | null;
247
262
  /** False when the runtime would ignore an "always allow" for this tool. */
248
263
  can_remember?: boolean;
249
264
  /** False when the Always-allow control must start unticked (force-ask floor). */
250
265
  remember_default?: boolean;
266
+ ask_reason?: string;
267
+ surface?: string;
268
+ surface_label?: string | null;
251
269
  }
252
270
  interface Task {
253
271
  id: number;
@@ -409,6 +427,8 @@ interface Webhook {
409
427
  /** Signing secret. Returned on create only — store it, you cannot read it back. */
410
428
  secret: string | null;
411
429
  active: boolean;
430
+ /** End-user scope. Null/omitted = account-level. */
431
+ user_id?: string | null;
412
432
  created_at: string;
413
433
  updated_at?: string | null;
414
434
  }
@@ -442,12 +462,12 @@ interface WebhookDelivery {
442
462
  next_retry_at: string | null;
443
463
  created_at: string;
444
464
  }
445
- /** A standing tool permission policy: one pre-approved tool for one end-user.
446
- * Note the asymmetry you create it with `tool`, the API returns it as
447
- * `tool_name`. */
465
+ /** A standing tool permission policy: one pre-approved tool for one scope.
466
+ * `user_id` is null for the account-level scope. Note the asymmetry you
467
+ * create it with `tool`, the API returns it as `tool_name`. */
448
468
  interface PermissionPolicy {
449
469
  id: number;
450
- user_id: string;
470
+ user_id: string | null;
451
471
  tool_name: string;
452
472
  created_at: string;
453
473
  /** Which surface minted the grant ("run_approval" / "api"); null on legacy rows. */
@@ -469,7 +489,9 @@ interface Usage {
469
489
  cost_limit: string;
470
490
  period_end: string;
471
491
  subscription_status: string | null;
472
- /** Authoritative eligibility for the model-subscription-funded Free path. */
492
+ /** Current paid subscription cadence, when known. */
493
+ subscription_billing_period?: "monthly" | "annual" | null;
494
+ /** Authoritative eligibility for the model-subscription-funded Hobby path. */
473
495
  free_path_available: boolean;
474
496
  overage_enabled: boolean;
475
497
  overage_used_cents: number;
@@ -518,7 +540,7 @@ interface Receipt {
518
540
  receipt_url: string | null;
519
541
  created_at: string;
520
542
  }
521
- /** A public (paid) plan from the canonical catalog. All prices in cents. */
543
+ /** A public Hobby or paid plan from the canonical catalog. All prices in cents. */
522
544
  interface Plan {
523
545
  slug: string;
524
546
  display_name: string;
@@ -526,9 +548,20 @@ interface Plan {
526
548
  monthly_price_cents: number;
527
549
  annual_price_cents: number;
528
550
  overage_rate_cents: number;
551
+ /** `own_subscription` uses the customer's connected model plan; `platform` includes inference. */
552
+ inference_mode: "own_subscription" | "platform";
553
+ /** Whether this plan may opt into metered usage beyond its included runs. */
554
+ overage_available: boolean;
529
555
  /** Per-period model-spend fair-use cap; `0` on servers that predate the field. */
530
556
  fair_use_cost_limit_cents: number;
531
557
  }
558
+ type SubscriptionPlanId = "individual" | "pro" | "max_5x" | "max_20x";
559
+ type SubscriptionBillingPeriod = "monthly" | "annual";
560
+ /** Stripe redirect returned when starting checkout or managing the current plan. */
561
+ interface SubscriptionCheckout {
562
+ url: string;
563
+ destination: "checkout" | "portal" | "sales";
564
+ }
532
565
  /** One prepaid token-balance ledger entry. Micro-USD; debits are negative. */
533
566
  interface TokenTransaction {
534
567
  type: string;
@@ -842,6 +875,18 @@ interface OverageParams {
842
875
  /** Hard ceiling on overage spend per period, in cents. */
843
876
  monthly_cap_cents: number;
844
877
  }
878
+ interface SubscriptionCheckoutParams {
879
+ plan_id: SubscriptionPlanId;
880
+ billing_period?: SubscriptionBillingPeriod;
881
+ }
882
+ interface BillingPortalParams {
883
+ /** Kept for wire compatibility; `subscription_update` returns a sales-contact URL. */
884
+ flow?: "subscription_update";
885
+ }
886
+ interface BillingPlansParams {
887
+ /** Include Hobby, which is activated separately and cannot be submitted to checkout. */
888
+ include_free?: boolean;
889
+ }
845
890
  interface TopupParams {
846
891
  /** Cents to add. $5 minimum, $1M maximum. */
847
892
  amount_cents: number;
@@ -883,13 +928,19 @@ interface BillingResource {
883
928
  * `receipt_url` can be `null` when Stripe can no longer retrieve the session.
884
929
  */
885
930
  receipts(params?: PageParams): Promise<Page<Receipt>>;
886
- /** What the paid plans include and cost for your own pricing page or upgrade
887
- * prompt. Public (paid) plans only, straight from the canonical catalog, and
888
- * returned as a plain array rather than a page. */
889
- plans(): Promise<Plan[]>;
931
+ /** Purchasable plans from the canonical catalog. Pass `include_free` to also render Hobby. */
932
+ plans(params?: BillingPlansParams): Promise<Plan[]>;
933
+ /** Start a paid subscription. Existing customers may manage their current tier and cadence;
934
+ * changing either returns `destination="sales"` with a contact URL. */
935
+ checkout(params: SubscriptionCheckoutParams): Promise<SubscriptionCheckout>;
936
+ /** Open Stripe for payment methods, invoices, or cancellation. */
937
+ portal(params?: BillingPortalParams): Promise<string>;
938
+ /** Activate Hobby using a connected model subscription. */
939
+ activateFree(): Promise<Usage>;
890
940
  /**
891
941
  * Decide whether runs may continue past your plan's included allotment, and how
892
- * far. Off by default; once enabled, extra runs bill at the per-run overage rate
942
+ * far. Available only when the current catalog plan has `overage_available=true`.
943
+ * Off by default; once enabled, extra runs bill at the per-run overage rate
893
944
  * until `monthly_cap_cents` is reached. Returns the refreshed usage so you can
894
945
  * confirm the new state without a second call.
895
946
  */
@@ -1026,6 +1077,7 @@ interface ModelConnection {
1026
1077
  provider: ModelConnectionProvider;
1027
1078
  display_name: string;
1028
1079
  connected: boolean;
1080
+ is_default: boolean;
1029
1081
  status?: string | null;
1030
1082
  account_label?: string | null;
1031
1083
  expires_at?: string | null;
@@ -1060,46 +1112,72 @@ interface ModelConnectionsResource {
1060
1112
  declare function createModelConnectionsResource(http: Http): ModelConnectionsResource;
1061
1113
 
1062
1114
  /**
1063
- * `client.permissions` — standing tool allow-lists, one end-user at a time.
1115
+ * `client.permissions` — standing tool allow-lists.
1064
1116
  *
1065
1117
  * A run pauses whenever the agent reaches for a tool that is not pre-approved,
1066
1118
  * and stays paused until somebody answers. That is the right default for a first
1067
1119
  * run and the wrong one for a tool your product has already decided is fine. A
1068
- * policy here says "this end-user's runs may use this tool" once, so their runs
1069
- * stop stopping.
1120
+ * policy here says "these runs may use this tool" once, so they stop stopping.
1121
+ *
1122
+ * TWO SCOPES, and `user_id` is what selects between them — it is not a required
1123
+ * argument. Pass it to reach one end-user's policies. OMIT it to reach the
1124
+ * ACCOUNT-LEVEL scope (`end_user_id IS NULL`), which is the scope a run with no
1125
+ * `user_id` matches and the one the platform writes to when somebody picks
1126
+ * "always allow" on a first-party run. Requiring `user_id` here is exactly what
1127
+ * made those policies ungovernable — grantable, but never listable or revocable
1128
+ * through this SDK. The API stopped requiring it on 2026-08-01
1129
+ * (`PermissionPolicyCreate.user_id`, `_end_user_id_query`); this client did not
1130
+ * follow, and its own docstring asserted the account scope did not exist.
1131
+ *
1132
+ * The two scopes never overlap: a delete must name the SAME scope the policy
1133
+ * lives in, so an end-user-scoped delete cannot reach an account-level policy
1134
+ * (404), and neither can the reverse.
1135
+ *
1136
+ * One account setting narrows this: with strict multi-tenant mode on
1137
+ * (`require_end_user_id`, the default for API-key signups) the server rejects a
1138
+ * programmatic call that resolves to no end-user with a 422 naming the setting.
1139
+ * Omitting `user_id` is still how you ASK for the account scope — on those
1140
+ * accounts the answer is just no.
1070
1141
  *
1071
- * Scope: policies are per end-user (`user_id` is required on every call — there
1072
- * is no account-wide policy) and outlive the run, unlike `runs.answerPermission()`
1073
- * which unblocks a single gate. `/docs/users` documents this surface; mirrors
1142
+ * Policies outlive the run, unlike `runs.answerPermission()` which unblocks a
1143
+ * single gate. `/docs/users` documents this surface; mirrors
1074
1144
  * `sdk/py/m8tes/_resources/permissions.py`.
1075
1145
  */
1076
1146
 
1077
1147
  interface PermissionCreateParams {
1078
- /** The end-user whose runs this policy applies to. Required — policies never span end-users. */
1079
- user_id: string;
1148
+ /**
1149
+ * The end-user whose runs this policy applies to. Omit for the account-level
1150
+ * scope — the one runs that carry no `user_id` match.
1151
+ */
1152
+ user_id?: string;
1080
1153
  /** The tool to pre-approve, e.g. `"Bash"` or an `mcp__*` tool name. */
1081
1154
  tool: string;
1082
1155
  }
1083
1156
  interface PermissionListParams extends PageParams {
1084
- /** Required: you list one end-user's policies, never the account's. */
1085
- user_id: string;
1157
+ /** One end-user's policies. Omit to list the account-level scope. */
1158
+ user_id?: string;
1159
+ }
1160
+ interface PermissionDeleteParams {
1161
+ /**
1162
+ * The scope the policy lives in. Omit to delete an account-level policy.
1163
+ * A scope that does not match the policy is a 404, never a silent no-op.
1164
+ */
1165
+ user_id?: string;
1086
1166
  }
1087
1167
  interface PermissionsResource {
1088
1168
  /**
1089
- * Pre-approve a tool so this end-user's runs no longer pause on it.
1169
+ * Pre-approve a tool so matching runs no longer pause on it.
1090
1170
  * Idempotent — re-approving the same tool returns the existing policy rather
1091
1171
  * than erroring or duplicating. Send `tool`; the policy comes back as `tool_name`.
1092
1172
  */
1093
1173
  create(params: PermissionCreateParams): Promise<PermissionPolicy>;
1094
- /** Audit what an end-user's runs are allowed to do without asking. */
1095
- list(params: PermissionListParams): Promise<Page<PermissionPolicy>>;
1174
+ /** Audit what one scope's runs are allowed to do without asking. */
1175
+ list(params?: PermissionListParams): Promise<Page<PermissionPolicy>>;
1096
1176
  /**
1097
1177
  * Revoke a pre-approval, so the tool gates again on the next run.
1098
- * `user_id` is required and scopes the delete an id alone will not resolve.
1178
+ * `user_id` scopes the delete and must match the policy's own scope.
1099
1179
  */
1100
- delete(permissionId: number, params: {
1101
- user_id: string;
1102
- }): Promise<void>;
1180
+ delete(permissionId: number, params?: PermissionDeleteParams): Promise<void>;
1103
1181
  }
1104
1182
  declare function createPermissionsResource(http: Http): PermissionsResource;
1105
1183
 
@@ -1192,6 +1270,7 @@ interface PollDeps {
1192
1270
  }, signal?: AbortSignal): Promise<unknown>;
1193
1271
  answer(runId: number, params: {
1194
1272
  answers: Record<string, string>;
1273
+ request_id?: string;
1195
1274
  }, signal?: AbortSignal): Promise<unknown>;
1196
1275
  }
1197
1276
  /** Thrown when the caller aborts the wait. */
@@ -1285,6 +1364,44 @@ declare class RunStream implements AsyncIterable<M8tesStreamEvent> {
1285
1364
  * request. Mirrors `sdk/py/m8tes/_resources/runs.py`, field for field.
1286
1365
  */
1287
1366
 
1367
+ /**
1368
+ * Per-reply overrides accepted by `POST /runs/{id}/reply`.
1369
+ *
1370
+ * These mirror the server's `RunReply` model. Every field is optional; omit one
1371
+ * to inherit whatever the run last ran with. (The Python SDK also takes `files`;
1372
+ * TypeScript has no attachment path on reply yet.)
1373
+ *
1374
+ * SETTING ANY OF THESE CHANGES HOW A MID-TURN REPLY BEHAVES. A reply to a run
1375
+ * whose current turn is still executing is normally QUEUED and delivered as the
1376
+ * next turn. The server refuses to queue overrides — it cannot apply them to a
1377
+ * turn already running under the run's persisted settings — so a reply carrying
1378
+ * any field below fails with 409 instead. Send the message bare, or retry once
1379
+ * the turn ends.
1380
+ */
1381
+ interface RunReplyOptions extends RunStreamOptions {
1382
+ /**
1383
+ * Override this reply's app toolset (names from `client.apps.list()`).
1384
+ * A changed set persists to the run, so later replies inherit it.
1385
+ * `[]` means "inherit the run's current set", NOT "no tools".
1386
+ */
1387
+ tools?: string[];
1388
+ /** Execution-mode override for this and later replies. Omit to inherit the run's mode. */
1389
+ permission_mode?: PermissionMode;
1390
+ /** Override whether the internal same-scope management tools are enabled for this reply. */
1391
+ task_setup_tools?: boolean;
1392
+ /** Override whether the internal issue-reporting feedback tool is enabled for this reply. */
1393
+ feedback?: boolean;
1394
+ /**
1395
+ * Override whether the agent may ask questions (AskUserQuestion) during this reply.
1396
+ * Pass `false` to pin non-interactive behavior, so an unattended reply loop on a
1397
+ * run created with `human_in_the_loop: true` cannot pause on a question.
1398
+ *
1399
+ * Note the 409 above: `false` is still an override, so a loop that sets it on
1400
+ * every reply will fail whenever it catches the run mid-turn. Set it on the
1401
+ * replies that start a turn, not blindly on all of them.
1402
+ */
1403
+ human_in_the_loop?: boolean;
1404
+ }
1288
1405
  interface RunCreateParams {
1289
1406
  /** What the agent should do. */
1290
1407
  message: string;
@@ -1357,6 +1474,10 @@ interface RunListParams {
1357
1474
  teammate_id?: number;
1358
1475
  task_id?: number;
1359
1476
  status?: string;
1477
+ /** `created` (newest first, the default) or `priority` (runs waiting on a human first). */
1478
+ sort?: "created" | "priority";
1479
+ /** Hide Company Agent Day-1 / pulse / maintenance (Platform accounts only) — ask whether the user has run anything. */
1480
+ exclude_platform_runs?: boolean;
1360
1481
  limit?: number;
1361
1482
  starting_after?: number;
1362
1483
  }
@@ -1374,6 +1495,13 @@ interface ApproveParams {
1374
1495
  * stored policy).
1375
1496
  */
1376
1497
  remember?: boolean;
1498
+ /**
1499
+ * Steering in your own words, e.g. with `decision: "deny"`, "use the staging
1500
+ * board instead". The agent reads it and adapts rather than silently skipping
1501
+ * the action. Delivered on both decisions when the run is paused; a deny's
1502
+ * reason also reaches a still-live run.
1503
+ */
1504
+ reason?: string;
1377
1505
  }
1378
1506
  interface AnswerParams {
1379
1507
  /**
@@ -1381,6 +1509,20 @@ interface AnswerParams {
1381
1509
  * `question` strings from the `question` event.
1382
1510
  */
1383
1511
  answers: Record<string, string>;
1512
+ /**
1513
+ * The gate this answer is for — `requestId` off the `question` event (the
1514
+ * stream normalises it to camelCase), or `request_id` from
1515
+ * `runs.permissions()`. Required whenever the run has more than one
1516
+ * unresolved `AskUserQuestion`.
1517
+ *
1518
+ * A run accumulates asks over its life, and only some of them get resolved.
1519
+ * With no `request_id` the server does not know which one you answered, so it
1520
+ * falls back to position: the OLDEST ask that is not already allowed. A gate
1521
+ * that timed out earlier still matches that, so the answer you wrote for the
1522
+ * live question is merged into the stale one and the run resumes on the wrong
1523
+ * selection. Send the id and the server targets exactly that gate.
1524
+ */
1525
+ request_id?: string;
1384
1526
  }
1385
1527
  interface RunsResource {
1386
1528
  /** Start a run and stream it. */
@@ -1416,7 +1558,7 @@ interface RunsResource {
1416
1558
  stream(runId: number, options?: RunStreamOptions): RunStream;
1417
1559
  /** Continue the same run, streaming only this follow-up. After a provider failure,
1418
1560
  * the reply follows the account's current connected/preferred provider. */
1419
- reply(runId: number, message: string, options?: RunStreamOptions): RunStream;
1561
+ reply(runId: number, message: string, options?: RunReplyOptions): RunStream;
1420
1562
  /** GET /runs/{id}. Pass `user_id` to scope to one end-user (required when the
1421
1563
  * account has strict multi-tenant mode on). */
1422
1564
  get(runId: number, params?: {
@@ -1430,7 +1572,11 @@ interface RunsResource {
1430
1572
  }): Promise<Run>;
1431
1573
  /** Approve or deny a pending tool-permission gate. */
1432
1574
  approve(runId: number, params: ApproveParams): Promise<PermissionRequest>;
1433
- /** Answer a pending AskUserQuestion gate, resuming the run. */
1575
+ /**
1576
+ * Answer a pending AskUserQuestion gate, resuming the run. Pass `request_id`
1577
+ * when the run has more than one unresolved ask, or the server picks by
1578
+ * position instead.
1579
+ */
1434
1580
  answer(runId: number, params: AnswerParams): Promise<{
1435
1581
  status: string;
1436
1582
  resumed: boolean;
@@ -1649,6 +1795,9 @@ interface TasksResource {
1649
1795
  * byte on the signing scheme, so a payload verified by one SDK verifies in the
1650
1796
  * other.
1651
1797
  *
1798
+ * `user_id` scopes an endpoint to one end-user; omit for account-level. The
1799
+ * scopes never mix: an end-user run only delivers to that end-user's endpoints.
1800
+ *
1652
1801
  * Scheme: HMAC-SHA256 over `"{webhook-id}.{webhook-timestamp}.{raw body}"`, hex,
1653
1802
  * prefixed `v1=`, compared in constant time.
1654
1803
  */
@@ -1683,22 +1832,31 @@ interface WebhooksResource {
1683
1832
  create(params: {
1684
1833
  url: string;
1685
1834
  events?: string[];
1835
+ user_id?: string;
1686
1836
  }): Promise<Webhook>;
1687
1837
  list(params?: {
1688
1838
  limit?: number;
1689
1839
  starting_after?: number;
1840
+ user_id?: string;
1690
1841
  }): Promise<Page<Webhook>>;
1691
- get(webhookId: number): Promise<Webhook>;
1842
+ get(webhookId: number, params?: {
1843
+ user_id?: string;
1844
+ }): Promise<Webhook>;
1692
1845
  update(webhookId: number, params: {
1693
1846
  url?: string;
1694
1847
  events?: string[];
1695
1848
  active?: boolean;
1849
+ rotate_secret?: boolean;
1850
+ user_id?: string;
1696
1851
  }): Promise<Webhook>;
1697
- delete(webhookId: number): Promise<void>;
1852
+ delete(webhookId: number, params?: {
1853
+ user_id?: string;
1854
+ }): Promise<void>;
1698
1855
  /** Delivery attempts, for debugging a receiver that is not getting events. */
1699
1856
  listDeliveries(webhookId: number, params?: {
1700
1857
  limit?: number;
1701
1858
  starting_after?: number;
1859
+ user_id?: string;
1702
1860
  }): Promise<Page<WebhookDelivery>>;
1703
1861
  }
1704
1862
 
@@ -1726,7 +1884,7 @@ interface WebhooksResource {
1726
1884
  */
1727
1885
 
1728
1886
  /** Kept in lockstep with package.json "version" — guarded by test/version.test.ts. */
1729
- declare const M8TES_SDK_VERSION = "0.1.0-alpha.5";
1887
+ declare const M8TES_SDK_VERSION = "0.1.0-alpha.7";
1730
1888
  declare class M8tes {
1731
1889
  readonly runs: RunsResource;
1732
1890
  readonly agents: AgentsResource;
@@ -1748,4 +1906,4 @@ declare class M8tes {
1748
1906
  constructor(options?: ClientOptions);
1749
1907
  }
1750
1908
 
1751
- export { type AccountDeletion, type AccountExport, type AccountResource, type AccountSettings, type AccountSettingsUpdateParams, type Agent, type AgentCreateParams, type AgentListParams, type AgentUpdateParams, type AgentsResource, type AlertThresholdParams, type App, type AppConnectionInitiation, type AppConnectionResult, type AppsResource, type AuthorizableModelConnectionProvider, type AutoReloadParams, type Balance, type BillingResource, type ClientOptions, type CodeModelConnectionProvider, ConversationState, DEFAULT_BASE_URL, type DeviceModelConnectionProvider, type EmailInbox, type EndUser, type EndUserCreateParams, type EndUserUpdateParams, type EndUserUsage, type FetchLike, type Http, type JsonObject, type ListResponse, M8TES_SDK_VERSION, M8tes, M8tesStreamEvent, type MemoriesResource, type Memory, type MemoryCreateParams, type MemoryListParams, type MemoryUpdateParams, type Model, type ModelAuthorization, type ModelConnection, type ModelConnectionProvider, type ModelConnectionsResource, type ModelPricing, type ModelsResource, Normalizer, type OverageParams, Page, type PageParams, type PermissionCreateParams, type PermissionListParams, type PermissionMode, type PermissionPolicy, type PermissionRequest, type PermissionsResource, type Plan, type PollOptions, type Receipt, type Run, type RunCreateParams, type RunFile, type RunListParams, type RunOutcome, RunPausedError, RunStream, type RunStreamOptions, RunTimeoutError, type RunUsage, RunWaitAbortedError, type RunsResource, type SettingsResource, TERMINAL_STATUSES, type Task, type TaskCreateParams, type TaskListParams, type TaskRunParams, type TaskUpdateParams, type TasksResource, type Teammate, type TokenTransaction, type TopupParams, type Trigger, type TriggerCreateParams, type TriggerType, type TriggersResource, type Usage, type UsageBucket, type UsageModelSlice, type UsageTimeseries, type UsageTimeseriesParams, type UsageTotals, type UsersResource, type VerifySignatureOptions, type WaitOptions, type Webhook, type WebhookDelivery, type WebhookToggle, type WebhooksResource, createAccountResource, createBillingResource, createHttp, createMemoriesResource, createModelConnectionsResource, createModelsResource, createPermissionsResource, isPlanApproval, planText, pollRun, verifySignature, waitForRun };
1909
+ export { type AccountDeletion, type AccountExport, type AccountResource, type AccountSettings, type AccountSettingsUpdateParams, type Agent, type AgentCreateParams, type AgentListParams, type AgentUpdateParams, type AgentsResource, type AlertThresholdParams, type App, type AppConnectionInitiation, type AppConnectionResult, type AppsResource, type AuthorizableModelConnectionProvider, type AutoReloadParams, type Balance, type BillingPlansParams, type BillingPortalParams, type BillingResource, type ClientOptions, type CodeModelConnectionProvider, ConversationState, DEFAULT_BASE_URL, type DeviceModelConnectionProvider, type EmailInbox, type EndUser, type EndUserCreateParams, type EndUserUpdateParams, type EndUserUsage, type FetchLike, type Http, type JsonObject, type ListResponse, M8TES_SDK_VERSION, M8tes, M8tesStreamEvent, type MemoriesResource, type Memory, type MemoryCreateParams, type MemoryListParams, type MemoryUpdateParams, type Model, type ModelAuthorization, type ModelConnection, type ModelConnectionProvider, type ModelConnectionsResource, type ModelPricing, type ModelsResource, Normalizer, type OverageParams, Page, type PageParams, type PermissionCreateParams, type PermissionDeleteParams, type PermissionListParams, type PermissionMode, type PermissionPolicy, type PermissionRequest, type PermissionsResource, type Plan, type PollOptions, type Receipt, type Run, type RunCreateParams, type RunFile, type RunListParams, type RunOutcome, RunPausedError, type RunReplyOptions, RunStream, type RunStreamOptions, RunTimeoutError, type RunUsage, RunWaitAbortedError, type RunsResource, type SettingsResource, type SubscriptionBillingPeriod, type SubscriptionCheckout, type SubscriptionCheckoutParams, type SubscriptionPlanId, TERMINAL_STATUSES, type Task, type TaskCreateParams, type TaskListParams, type TaskRunParams, type TaskUpdateParams, type TasksResource, type Teammate, type TokenTransaction, type TopupParams, type Trigger, type TriggerCreateParams, type TriggerType, type TriggersResource, type Usage, type UsageBucket, type UsageModelSlice, type UsageTimeseries, type UsageTimeseriesParams, type UsageTotals, type UsersResource, type VerifySignatureOptions, type WaitOptions, type Webhook, type WebhookDelivery, type WebhookToggle, type WebhooksResource, createAccountResource, createBillingResource, createHttp, createMemoriesResource, createModelConnectionsResource, createModelsResource, createPermissionsResource, isPlanApproval, planText, pollRun, verifySignature, waitForRun };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { createNormalizer, createSseDecoder, initialConversationState, accumulate, RunFailedError, APIError, parseRetryAfter, ConflictError, NotFoundError, AuthenticationError, PermissionDeniedError, ValidationError, seg, parseErrorEnvelope, errorClassForStatus } from './chunk-CURNMC4F.js';
2
- export { APIError, AuthenticationError, BillingError, ConflictError, M8tesApiError, NotFoundError, PROTOCOL_VERSION, PermissionDeniedError, RateLimitError, RunFailedError, RunNotStreamingError, TERMINAL_EVENT_TYPES, ValidationError, accumulate, createAccumulator, createNormalizer, createSseDecoder, errorClassForStatus, errorFromResponse, initialConversationState, isTerminalEvent, parseErrorEnvelope, parseRetryAfter, parseSse, seg, splitConcatenatedJson } from './chunk-CURNMC4F.js';
1
+ import { createNormalizer, createSseDecoder, initialConversationState, accumulate, RunFailedError, APIError, parseRetryAfter, ConflictError, NotFoundError, AuthenticationError, PermissionDeniedError, ValidationError, seg, parseErrorEnvelope, errorClassForStatus } from './chunk-5X7I2XPE.js';
2
+ export { APIError, AuthenticationError, BillingError, ConflictError, M8tesApiError, NotFoundError, PROTOCOL_VERSION, PermissionDeniedError, RateLimitError, RunFailedError, RunNotStreamingError, TERMINAL_EVENT_TYPES, ValidationError, accumulate, createAccumulator, createNormalizer, createSseDecoder, errorClassForStatus, errorFromResponse, initialConversationState, isTerminalEvent, parseErrorEnvelope, parseRetryAfter, parseSse, seg, splitConcatenatedJson } from './chunk-5X7I2XPE.js';
3
3
  import { createHmac, timingSafeEqual } from 'crypto';
4
4
 
5
5
  // src/http.ts
@@ -157,7 +157,9 @@ function createHttp(options = {}) {
157
157
  return send(method, path, opts);
158
158
  },
159
159
  async *stream(method, path, opts = {}) {
160
- const res = await send(method, path, opts, { conflictIsNotStreaming: true });
160
+ const res = await send(method, path, opts, {
161
+ conflictIsNotStreaming: method === "GET"
162
+ });
161
163
  if (opts.onReplay && res.headers.get(REPLAY_HEADER)) {
162
164
  const run = await res.json();
163
165
  yield* opts.onReplay(run);
@@ -417,13 +419,39 @@ function createBillingResource(http) {
417
419
  const query = toQuery(
418
420
  toBody({ ...rest, teammate_id: resolveAgentId(teammate_id, agent_id) })
419
421
  );
420
- return http.request("GET", "/usage/timeseries", { query });
422
+ return http.request("GET", "/usage/timeseries", {
423
+ query
424
+ });
421
425
  },
422
426
  receipts(params = {}) {
423
427
  return pager(http, "/billing/receipts")({ ...params });
424
428
  },
425
- plans() {
426
- return http.request("GET", "/billing/plans");
429
+ plans(params = {}) {
430
+ return http.request("GET", "/billing/plans", {
431
+ query: toQuery(toBody({ ...params }))
432
+ });
433
+ },
434
+ checkout(params) {
435
+ return http.request("POST", "/billing/checkout", {
436
+ body: toBody({ billing_period: "monthly", ...params })
437
+ });
438
+ },
439
+ async portal(params = {}) {
440
+ const response = await http.request(
441
+ "POST",
442
+ "/billing/portal",
443
+ {
444
+ body: toBody({ ...params })
445
+ }
446
+ );
447
+ return response.url;
448
+ },
449
+ async activateFree() {
450
+ const usage = await http.request("POST", "/billing/activate-free");
451
+ return {
452
+ ...usage,
453
+ free_path_available: usage.free_path_available ?? false
454
+ };
427
455
  },
428
456
  async setOverage(params) {
429
457
  const usage = await http.request("PATCH", "/billing/overage", {
@@ -438,9 +466,13 @@ function createBillingResource(http) {
438
466
  return http.request("GET", "/billing/balance");
439
467
  },
440
468
  async topup(params) {
441
- const res = await http.request("POST", "/billing/topup", {
442
- body: toBody({ ...params })
443
- });
469
+ const res = await http.request(
470
+ "POST",
471
+ "/billing/topup",
472
+ {
473
+ body: toBody({ ...params })
474
+ }
475
+ );
444
476
  return res.checkout_url;
445
477
  },
446
478
  setAutoReload(params) {
@@ -539,10 +571,10 @@ function createPermissionsResource(http) {
539
571
  body: toBody({ ...params })
540
572
  });
541
573
  },
542
- list(params) {
574
+ list(params = {}) {
543
575
  return pager(http, "/permissions/")({ ...params });
544
576
  },
545
- async delete(permissionId, params) {
577
+ async delete(permissionId, params = {}) {
546
578
  await http.request("DELETE", `/permissions/${seg(permissionId)}`, {
547
579
  query: toQuery({ user_id: params.user_id })
548
580
  });
@@ -810,7 +842,7 @@ async function waitForRun(deps, runId, options = {}) {
810
842
  );
811
843
  }
812
844
  const answers = await bound(async () => options.onQuestion(request));
813
- await resolveGate(() => deps.answer(runId, { answers }, signal));
845
+ await resolveGate(() => deps.answer(runId, { answers, request_id: request.request_id }, signal));
814
846
  } else {
815
847
  if (!options.onApproval) {
816
848
  throw new RunPausedError(
@@ -919,6 +951,10 @@ function withRunId(err, runId) {
919
951
  }
920
952
  return err;
921
953
  }
954
+ function replyBody(message, options) {
955
+ const { raiseOnError: _raiseOnError, idempotencyKey: _idempotencyKey, ...overrides } = options ?? {};
956
+ return toBody({ ...overrides, message, stream: true });
957
+ }
922
958
  function items(payload) {
923
959
  return Array.isArray(payload) ? payload : payload?.data ?? [];
924
960
  }
@@ -1022,7 +1058,7 @@ function createRunsResource(http) {
1022
1058
  reply(runId, message, options) {
1023
1059
  return new RunStream(
1024
1060
  http.stream("POST", `/runs/${seg(runId)}/reply`, {
1025
- body: { message },
1061
+ body: replyBody(message, options),
1026
1062
  headers: idempotencyHeaders(options?.idempotencyKey),
1027
1063
  onReplay: replayJoin(http)
1028
1064
  }),
@@ -1061,8 +1097,12 @@ function createRunsResource(http) {
1061
1097
  });
1062
1098
  },
1063
1099
  answer(runId, params) {
1100
+ const body = {
1101
+ answers: params.answers
1102
+ };
1103
+ if (params.request_id !== void 0) body.request_id = params.request_id;
1064
1104
  return http.request("POST", `/runs/${seg(runId)}/answer`, {
1065
- body: { answers: params.answers }
1105
+ body
1066
1106
  });
1067
1107
  },
1068
1108
  async permissions(runId) {
@@ -1232,23 +1272,32 @@ function createWebhooksResource(http) {
1232
1272
  list(params = {}) {
1233
1273
  return pager(http, "/webhooks/")({ ...params });
1234
1274
  },
1235
- get(webhookId) {
1236
- return http.request("GET", `/webhooks/${seg(webhookId)}`);
1275
+ get(webhookId, params = {}) {
1276
+ return http.request("GET", `/webhooks/${seg(webhookId)}`, {
1277
+ query: toQuery({ user_id: params.user_id })
1278
+ });
1237
1279
  },
1238
- update(webhookId, params) {
1239
- return http.request("PATCH", `/webhooks/${seg(webhookId)}`, { body: toBody({ ...params }) });
1280
+ update(webhookId, { user_id, ...body }) {
1281
+ return http.request("PATCH", `/webhooks/${seg(webhookId)}`, {
1282
+ query: toQuery({ user_id }),
1283
+ body: toBody({ ...body })
1284
+ });
1240
1285
  },
1241
- async delete(webhookId) {
1242
- await http.request("DELETE", `/webhooks/${seg(webhookId)}`);
1286
+ async delete(webhookId, params = {}) {
1287
+ await http.request("DELETE", `/webhooks/${seg(webhookId)}`, {
1288
+ query: toQuery({ user_id: params.user_id })
1289
+ });
1243
1290
  },
1244
1291
  listDeliveries(webhookId, params = {}) {
1245
- return pager(http, `/webhooks/${seg(webhookId)}/deliveries`)({ ...params });
1292
+ return pager(http, `/webhooks/${seg(webhookId)}/deliveries`)({
1293
+ ...params
1294
+ });
1246
1295
  }
1247
1296
  };
1248
1297
  }
1249
1298
 
1250
1299
  // src/index.ts
1251
- var M8TES_SDK_VERSION = "0.1.0-alpha.5";
1300
+ var M8TES_SDK_VERSION = "0.1.0-alpha.7";
1252
1301
  var M8tes = class {
1253
1302
  runs;
1254
1303
  agents;