@naturali/sdk 0.269.0 → 0.270.0

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
@@ -22,7 +22,7 @@ const { data, error } = await naturali.agents.listAgents({
22
22
  });
23
23
 
24
24
  if (error) {
25
- // The platform's error envelope, typed: { error: { code, message, details } }
25
+ // The platform's error envelope, typed: { error: { code, message, meta } }
26
26
  console.error(error);
27
27
  } else {
28
28
  console.log(data.data);
@@ -31,7 +31,7 @@ if (error) {
31
31
 
32
32
  A method never throws on a non-2xx response — it resolves to `{ data, error }`,
33
33
  so the machine-readable `code` (`approval_required`, `budget_exceeded`,
34
- `access_denied`, …) is available as typed data.
34
+ `FORBIDDEN`, …) is available as typed data.
35
35
 
36
36
  ## Options
37
37
 
package/dist/index.cjs CHANGED
@@ -839,7 +839,7 @@ var Channels = class {
839
839
  /**
840
840
  * Create a route
841
841
  *
842
- * `action` is required; `agent_id` is required when it is `agent`, `text` when it is `message`; `repeat` is only valid alongside `action: message`. `surface`, when present, must be one this channel's kind serves (`GET /v1/channel-kinds`) — otherwise `400 unknown_surface`. `match` keys must be predicates that kind's registry declares — otherwise `400 unknown_predicate`. Writing a route for a surface whose transport mode is off (e.g. a Discord `guild_thread` route before `mention_threads` is enabled) still succeeds, with `unreachable_surface` in the response `warnings`.
842
+ * `action` is required; `agent_id` is required when it is `agent`, `text` when it is `message`; `repeat` is only valid alongside `action: message`. `surface`, when present, must be one this channel's kind serves (`GET /v1/channel-kinds`) — otherwise `400 UNKNOWN_SURFACE`. `match` keys must be predicates that kind's registry declares — otherwise `400 UNKNOWN_PREDICATE`. Writing a route for a surface whose transport mode is off (e.g. a Discord `guild_thread` route before `mention_threads` is enabled) still succeeds, with `unreachable_surface` in the response `warnings`.
843
843
  *
844
844
  */
845
845
  static createChannelRoute(options) {
@@ -879,7 +879,7 @@ var Channels = class {
879
879
  /**
880
880
  * Replace a route
881
881
  *
882
- * Full replace, the same validation as create: an omitted field takes its create default. Where that default would widen a value the route sets, omission is `400 replace_omits_fields`, naming the fields in `details.fields`, and nothing is written: a set `surface` (the default is any surface), a non-empty `match` (every message), a non-empty `config` (it carries the Discord allowlist), and `status` on a `disabled` route (the default re-activates it). Send the value to keep it, or `"surface": null`, `"match": {}`, `"config": null`, `"status": "active"` to clear it.
882
+ * Full replace, the same validation as create: an omitted field takes its create default. Where that default would widen a value the route sets, omission is `400 REPLACE_OMITS_FIELDS`, naming the fields in `meta.fields`, and nothing is written: a set `surface` (the default is any surface), a non-empty `match` (every message), a non-empty `config` (it carries the Discord allowlist), and `status` on a `disabled` route (the default re-activates it). Send the value to keep it, or `"surface": null`, `"match": {}`, `"config": null`, `"status": "active"` to clear it.
883
883
  *
884
884
  */
885
885
  static replaceChannelRoute(options) {
@@ -919,17 +919,17 @@ var Channels = class {
919
919
  * Connect a channel
920
920
  *
921
921
  * Connect a channel. The required fields depend on `channel`; no credential is ever returned.
922
- * **Discord** (`channel: discord`) — supply `application_id` and `bot_token`, plus the `modes` selecting which Gateway flows to serve (direct messages, and/or @mention-opens-a-thread). The token is checked with Discord first: `400 invalid_bot_token` when Discord rejects it, `400 application_mismatch` when it belongs to another application, `502 discord_unavailable` when Discord cannot be read. Returns `501` when this deployment does not enable Discord channels.
923
- * **X** (`channel: x`) — supply the bot's `bot_token` (X developer portal, Chat bots) and the `consumer_key` and `consumer_secret` of the app that issued it. naturali then registers its own webhook on that app, subscribes it to the bot's incoming direct messages and registers the bot's chat encryption key, keeping the private key sealed: replies are end-to-end encrypted, and the project never handles keys, webhooks or ciphertext. Pass `chat_private_keys` and `chat_key_version` instead to keep a key the bot already registered. `400 invalid_bot_token` or `400 invalid_consumer_credentials` when X rejects a credential, `409 bot_in_use` when another channel holds the bot, `502 x_provisioning_failed` when X refuses the webhook or the subscription (an app holds a limited number of webhooks), `429 x_key_registration_limited` when the bot used its few daily key registrations, `502 x_unavailable` when X cannot be reached. Returns `501` when this deployment does not enable X channels.
922
+ * **Discord** (`channel: discord`) — supply `application_id` and `bot_token`, plus the `modes` selecting which Gateway flows to serve (direct messages, and/or @mention-opens-a-thread). The token is checked with Discord first: `400 INVALID_BOT_TOKEN` when Discord rejects it, `400 APPLICATION_MISMATCH` when it belongs to another application, `502 DISCORD_UNAVAILABLE` when Discord cannot be read. Returns `501` when this deployment does not enable Discord channels.
923
+ * **X** (`channel: x`) — supply the bot's `bot_token` (X developer portal, Chat bots) and the `consumer_key` and `consumer_secret` of the app that issued it. naturali then registers its own webhook on that app, subscribes it to the bot's incoming direct messages and registers the bot's chat encryption key, keeping the private key sealed: replies are end-to-end encrypted, and the project never handles keys, webhooks or ciphertext. Pass `chat_private_keys` and `chat_key_version` instead to keep a key the bot already registered. `400 INVALID_BOT_TOKEN` or `400 INVALID_CONSUMER_CREDENTIALS` when X rejects a credential, `409 BOT_IN_USE` when another channel holds the bot, `502 X_PROVISIONING_FAILED` when X refuses the webhook or the subscription (an app holds a limited number of webhooks), `429 X_KEY_REGISTRATION_LIMITED` when the bot used its few daily key registrations, `502 X_UNAVAILABLE` when X cannot be reached. Returns `501` when this deployment does not enable X channels.
924
924
  * **WhatsApp** (default) — one of two credential paths, both filling the same write-only secret:
925
925
  * * **BYOT** (`credential_source: byot`, default) — supply
926
926
  * `phone_number_id` and `access_token` from your own Meta app. The
927
- * number is read with the token first: `400 invalid_access_token` when
928
- * Meta rejects the token, `400 phone_number_not_accessible` when it
929
- * cannot reach that number, `502 meta_unavailable` when Meta fails.
927
+ * number is read with the token first: `400 INVALID_ACCESS_TOKEN` when
928
+ * Meta rejects the token, `400 PHONE_NUMBER_NOT_ACCESSIBLE` when it
929
+ * cannot reach that number, `502 META_UNAVAILABLE` when Meta fails.
930
930
  * The token's app is then subscribed to the WABA Meta reports as the
931
931
  * number's owner, which is the `waba_id` stored:
932
- * `400 waba_not_manageable` when the token cannot subscribe to it.
932
+ * `400 WABA_NOT_MANAGEABLE` when the token cannot subscribe to it.
933
933
  *
934
934
  * * **Embedded signup** (`credential_source: embedded_signup`) — supply
935
935
  * `code` and `waba_id` from the Meta popup; naturali exchanges the
@@ -939,7 +939,7 @@ var Channels = class {
939
939
  * are not configured.
940
940
  *
941
941
  *
942
- * The project's plan limits how many channels it may hold. At the limit this responds `403` with `plan_limit_reached`, whose `details` carry the `plan` and the `limit`, before any credential is acquired. Only `active` channels count, so disabling one frees allowance without deleting it.
942
+ * The project's plan limits how many channels it may hold. At the limit this responds `403` with `PLAN_LIMIT_REACHED`, whose `meta` carries the `plan` and the `limit`, before any credential is acquired. Only `active` channels count, so disabling one frees allowance without deleting it.
943
943
  *
944
944
  */
945
945
  static createChannel(options) {
@@ -971,7 +971,7 @@ var Channels = class {
971
971
  /**
972
972
  * Complete a WhatsApp signup
973
973
  *
974
- * Finish a signup link: the app's result page receives `pending` and the numbers Meta granted, and sends back the one to connect. The caller must be a member of the project the link was created for (`404` otherwise), so a link opened by anyone else connects nothing. `pending` expires 10 minutes after the dialog returns (`400 link_expired`).
974
+ * Finish a signup link: the app's result page receives `pending` and the numbers Meta granted, and sends back the one to connect. The caller must be a member of the project the link was created for (`404` otherwise), so a link opened by anyone else connects nothing. `pending` expires 10 minutes after the dialog returns (`400 LINK_EXPIRED`).
975
975
  *
976
976
  */
977
977
  static completeWhatsappSignup(options) {
@@ -1011,7 +1011,7 @@ var Channels = class {
1011
1011
  /**
1012
1012
  * Update a channel
1013
1013
  *
1014
- * Rotate the credential, update the kind's config (`waba_id` / `credential_source` for WhatsApp, `modes` for Discord), or flip the naturali-side status. At least one field is required. Rotating a WhatsApp token first reads the number with it, as connect does (`400 invalid_access_token`, `400 phone_number_not_accessible`, `502 meta_unavailable`, keeping the old token), then stores a new write-only secret, repoints the send tool and deletes the old secret; rotating a Discord bot token reseals it and the gateway worker reconnects with it.
1014
+ * Rotate the credential, update the kind's config (`waba_id` / `credential_source` for WhatsApp, `modes` for Discord), or flip the naturali-side status. At least one field is required. Rotating a WhatsApp token first reads the number with it, as connect does (`400 INVALID_ACCESS_TOKEN`, `400 PHONE_NUMBER_NOT_ACCESSIBLE`, `502 META_UNAVAILABLE`, keeping the old token), then stores a new write-only secret, repoints the send tool and deletes the old secret; rotating a Discord bot token reseals it and the gateway worker reconnects with it.
1015
1015
  *
1016
1016
  */
1017
1017
  static updateChannel(options) {
@@ -5190,7 +5190,7 @@ var Projects = class {
5190
5190
  *
5191
5191
  * Creates a project (one per client or per environment).
5192
5192
  *
5193
- * Your plan limits how many projects you may own. At the limit this responds `403` with `plan_limit_reached`, whose `details` carry the `plan` and the `limit`. An archived project still counts — archiving keeps every resource, so it frees nothing; deleting a project does.
5193
+ * Your plan limits how many projects you may own. At the limit this responds `403` with `PLAN_LIMIT_REACHED`, whose `meta` carries the `plan` and the `limit`. An archived project still counts — archiving keeps every resource, so it frees nothing; deleting a project does.
5194
5194
  *
5195
5195
  * A new project starts at the content-retention window your plan sets (`trace_content_retention_days`); `PATCH` it to anything shorter.
5196
5196
  *
@@ -5238,11 +5238,11 @@ var Projects = class {
5238
5238
  * Rename or archive a project, and/or change its content-retention settings (`trace_content_retention_days`, `trace_content_mode`), its execution ceilings (`max_concurrent_runs`, `max_chain_generations`, `max_orchestration_run_depth`), its priced-model gate (`require_priced_model`), its project-scope guardrails (`guardrail_ids`), the policies capping every agent turn in it (`agent_policy_ids`), the tag keys a change of agent-readable text removes (`content_bound_tag_keys`) and managed conversion (`managed_conversion`). Archiving is reversible; resources are retained.
5239
5239
  * Requires the `admin` role in the project (an `owner` has it too). These are the terms every member works under, which is why setting them sits above the role that works under them.
5240
5240
  * The ceilings and the priced-model gate are uncapped by plan: each one only ever narrows what the project may spend, so setting one takes on a restriction rather than claiming an entitlement. On the three ceilings `null` clears the project's own bound and omission leaves it alone — they are different instructions.
5241
- * `guardrail_ids` is the floor under every tool call by every agent in the project, including tools added later. The list is replaced wholesale, so send the ids you want to keep; `[]` detaches every one. An id naming no guardrail in the project responds `400` with `guardrail_not_found`, whose `details.missing` lists the ids. It is uncapped by plan, like the ceilings: a guardrail can only tighten what runs.
5241
+ * `guardrail_ids` is the floor under every tool call by every agent in the project, including tools added later. The list is replaced wholesale, so send the ids you want to keep; `[]` detaches every one. An id naming no guardrail in the project responds `400` with `GUARDRAIL_NOT_FOUND`, whose `meta.missing` lists the ids. It is uncapped by plan, like the ceilings: a guardrail can only tighten what runs.
5242
5242
  * `agent_policy_ids` caps every turn of every agent the project owns: an action they deny is refused even where the agent's own `policy_ids` allow it, and the refusal's `meta.denied_by` is `{ type: project, id: <project_id> }`. `null` or `[]` removes the cap. The credential must hold every grant the policies carry, else `403` with `POLICY_GRANT_NOT_HELD`; an id naming no policy responds `400` with `POLICY_NOT_FOUND`, and a policy of another project `400` with `POLICY_OUTSIDE_PROJECT`.
5243
5243
  * The two retention controls answer different questions. The window bounds how long content *stays* — a daily sweep purges anything past it, leaving auditable skeletons behind. `trace_content_mode: none` means content is never *written*, which is the stronger guarantee: it cannot be missed by a sweep or survive in a backup.
5244
5244
  *
5245
- * Your plan sets the longest window you may keep content for. A wider one — `null` included, which keeps content indefinitely — responds `403` with `plan_limit_reached`, whose `details` carry the `plan` and the `limit` in days. Anything shorter is always allowed. Moving to a plan with a shorter window takes effect at the end of the billing cycle, and content already stored is then purged by age like everything else.
5245
+ * Your plan sets the longest window you may keep content for. A wider one — `null` included, which keeps content indefinitely — responds `403` with `PLAN_LIMIT_REACHED`, whose `meta` carries the `plan` and the `limit` in days. Anything shorter is always allowed. Moving to a plan with a shorter window takes effect at the end of the billing cycle, and content already stored is then purged by age like everything else.
5246
5246
  *
5247
5247
  */
5248
5248
  static updateProject(options) {
@@ -5408,7 +5408,7 @@ var Projects = class {
5408
5408
  *
5409
5409
  * Makes the caller — the member the transfer names — the project's owner.
5410
5410
  *
5411
- * Usage up to this moment is settled on the previous owner's credit; from here on the project's usage is billed to the caller, and its runs count against the caller's allowance. The project counts toward the caller's plan limits at once: its active channels and triggers, and on Free the project itself. A transfer the caller's plan cannot hold is refused with `403 plan_limit_reached`, and the project's retention window is brought within the caller's plan.
5411
+ * Usage up to this moment is settled on the previous owner's credit; from here on the project's usage is billed to the caller, and its runs count against the caller's allowance. The project counts toward the caller's plan limits at once: its active channels and triggers, and on Free the project itself. A transfer the caller's plan cannot hold is refused with `403 PLAN_LIMIT_REACHED`, and the project's retention window is brought within the caller's plan.
5412
5412
  *
5413
5413
  * The previous owner stays in the project as an `admin`. Stops recorded against the project's spend move to the caller. Refused to a connected app.
5414
5414
  *
@@ -6365,7 +6365,7 @@ var Users = class {
6365
6365
  *
6366
6366
  * The plan the account is on, how long its projects may keep content, how much indexed storage it is holding, and the credit it has left — the figures the platform already enforces against, readable by the account they are enforced against.
6367
6367
  *
6368
- * A managed-model generation is refused with `402 insufficient_credit` while `credit_balance_usd` is negative, and a feature or a resource count outside the plan is refused with `403`, as is a retention window wider than `retention_days` or an ingest past `storage.limit`. Every refusal names what is missing; this is where the numbers behind them are read.
6368
+ * A managed-model generation is refused with `402 INSUFFICIENT_CREDIT` while `credit_balance_usd` is negative, and a feature or a resource count outside the plan is refused with `403`, as is a retention window wider than `retention_days` or an ingest past `storage.limit`. Every refusal names what is missing; this is where the numbers behind them are read.
6369
6369
  *
6370
6370
  * Every figure here is a local read, which is what keeps this route cheap enough to poll — unlike `GET /v1/users/me/usage`, which asks the meter once per project.
6371
6371
  *
@@ -6387,7 +6387,7 @@ var Users = class {
6387
6387
  *
6388
6388
  * Counted across the projects this account is the billing owner of, over the current UTC calendar month, from the meter itself. Archived projects are included: the runs they already made were made.
6389
6389
  *
6390
- * **On the `free` plan the allowance is enforced.** An account that has used it is refused `403 plan_limit_reached` with `resource: "runs"` on everything that starts a generation and on a direct tool call — on its own provider credential as much as on a managed model, because a run is a run — until the billing month turns or it upgrades. On `pro` and `business` nothing is refused: runs past the allowance are billed at the overage rate those plans are sold with. A contract plan is not counted.
6390
+ * **On the `free` plan the allowance is enforced.** An account that has used it is refused `403 PLAN_LIMIT_REACHED` with `resource: "runs"` on everything that starts a generation and on a direct tool call — on its own provider credential as much as on a managed model, because a run is a run — until the billing month turns or it upgrades. On `pro` and `business` nothing is refused: runs past the allowance are billed at the overage rate those plans are sold with. A contract plan is not counted.
6391
6391
  *
6392
6392
  * The other thing that stops a managed-model generation is a negative credit balance, which is `GET /v1/users/me/billing`, and it never applies to your own credential.
6393
6393
  *
@@ -6435,7 +6435,7 @@ var Users = class {
6435
6435
  *
6436
6436
  * Turns one stopped item back on — re-enables the schedule trigger, or resumes the orchestration run or workflow task — and stops listing it. An item that is no longer stopped (resumed already, finished or deleted) is marked restored too.
6437
6437
  *
6438
- * Refused with `409 stop_ceiling_closed` while a ceiling is still closed, naming it in `details.blocked_by`, and with `409 stop_not_restorable` for a cancelled eval run, which can only be dismissed.
6438
+ * Refused with `409 STOP_CEILING_CLOSED` while a ceiling is still closed, naming it in `meta.blocked_by`, and with `409 STOP_NOT_RESTORABLE` for a cancelled eval run, which can only be dismissed.
6439
6439
  *
6440
6440
  */
6441
6441
  static restoreCurrentUserStop(options) {
@@ -6628,7 +6628,7 @@ var Webhooks = class {
6628
6628
  *
6629
6629
  * Register an endpoint and subscribe it to one or more event types.
6630
6630
  * The response carries `secret` — the signing key, in plaintext. **This is the only time it is returned.** Store it where your receiver can read it; if you lose it, rotate rather than re-create, so the endpoint keeps its delivery history. Send `secret` yourself to sign with a key your receiver already holds; the response then returns that one.
6631
- * A project holds at most 20 webhooks, inactive ones included; the 21st is refused with `409 webhook_limit_reached`.
6631
+ * A project holds at most 20 webhooks, inactive ones included; the 21st is refused with `409 WEBHOOK_LIMIT_REACHED`.
6632
6632
  * Returns `501` on a deployment with no credential-sealing key configured, since the secret could not then be stored safely.
6633
6633
  *
6634
6634
  */
@@ -6727,7 +6727,7 @@ var Webhooks = class {
6727
6727
  *
6728
6728
  * Queue the same event at the same endpoint again — the recovery path for a delivery that failed, or one your receiver dropped. This is the `…:redeliver` action; the path segment is `{delivery_id}:redeliver`.
6729
6729
  * A **new** delivery is created and returned; the original record is left untouched, because its attempt history is the evidence you redelivered on. The event's `id` is carried over unchanged, so a receiver deduping on the event sees the same event twice while one deduping on `X-Naturali-Delivery` sees a distinct delivery.
6730
- * An inactive webhook is refused with `409 webhook_inactive`.
6730
+ * An inactive webhook is refused with `409 WEBHOOK_INACTIVE`.
6731
6731
  *
6732
6732
  */
6733
6733
  static redeliverWebhookDelivery(options) {