sarvam-agents-client 0.5.2 → 0.5.4

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.
Files changed (174) hide show
  1. package/README.md +52 -29
  2. package/dist/apis/AgentsApi.d.ts +96 -11
  3. package/dist/apis/AgentsApi.js +229 -9
  4. package/dist/apis/ConversationsApi.d.ts +5 -2
  5. package/dist/apis/ConversationsApi.js +7 -2
  6. package/dist/client.d.ts +3 -2
  7. package/dist/client.js +2 -1
  8. package/dist/compat/core/agents.d.ts +6 -1
  9. package/dist/compat/core/agents.js +237 -27
  10. package/dist/compat/core/customApis.d.ts +76 -0
  11. package/dist/compat/core/customApis.js +424 -0
  12. package/dist/compat/core/data.js +1 -1
  13. package/dist/compat/openai/client.d.ts +3 -0
  14. package/dist/compat/openai/client.js +5 -1
  15. package/dist/compat/openai/index.d.ts +1 -0
  16. package/dist/compat/openai/index.js +0 -1
  17. package/dist/compat/openai/resources/agents.js +8 -1
  18. package/dist/compat/openai/resources/sarvam.d.ts +26 -0
  19. package/dist/compat/openai/resources/sarvam.js +56 -0
  20. package/dist/compose/deploy.d.ts +14 -3
  21. package/dist/compose/deploy.js +60 -7
  22. package/dist/compose/errors.d.ts +4 -0
  23. package/dist/compose/errors.js +6 -1
  24. package/dist/compose/settingsTransport.d.ts +18 -13
  25. package/dist/compose/settingsTransport.js +78 -130
  26. package/dist/compose/transport.d.ts +12 -2
  27. package/dist/compose/webhook.d.ts +10 -13
  28. package/dist/compose/webhook.js +48 -45
  29. package/dist/compose/webhookSecrets.d.ts +79 -49
  30. package/dist/compose/webhookSecrets.js +244 -195
  31. package/dist/esm/apis/AgentsApi.d.ts +96 -11
  32. package/dist/esm/apis/AgentsApi.js +230 -10
  33. package/dist/esm/apis/ConversationsApi.d.ts +5 -2
  34. package/dist/esm/apis/ConversationsApi.js +7 -2
  35. package/dist/esm/client.d.ts +3 -2
  36. package/dist/esm/client.js +2 -1
  37. package/dist/esm/compat/core/agents.d.ts +6 -1
  38. package/dist/esm/compat/core/agents.js +237 -27
  39. package/dist/esm/compat/core/customApis.d.ts +76 -0
  40. package/dist/esm/compat/core/customApis.js +419 -0
  41. package/dist/esm/compat/core/data.js +1 -1
  42. package/dist/esm/compat/openai/client.d.ts +3 -0
  43. package/dist/esm/compat/openai/client.js +5 -1
  44. package/dist/esm/compat/openai/index.d.ts +1 -0
  45. package/dist/esm/compat/openai/index.js +0 -1
  46. package/dist/esm/compat/openai/resources/agents.js +8 -1
  47. package/dist/esm/compat/openai/resources/sarvam.d.ts +26 -0
  48. package/dist/esm/compat/openai/resources/sarvam.js +51 -0
  49. package/dist/esm/compose/deploy.d.ts +14 -3
  50. package/dist/esm/compose/deploy.js +60 -7
  51. package/dist/esm/compose/errors.d.ts +4 -0
  52. package/dist/esm/compose/errors.js +4 -0
  53. package/dist/esm/compose/settingsTransport.d.ts +18 -13
  54. package/dist/esm/compose/settingsTransport.js +80 -132
  55. package/dist/esm/compose/transport.d.ts +12 -2
  56. package/dist/esm/compose/webhook.d.ts +10 -13
  57. package/dist/esm/compose/webhook.js +45 -42
  58. package/dist/esm/compose/webhookSecrets.d.ts +79 -49
  59. package/dist/esm/compose/webhookSecrets.js +241 -193
  60. package/dist/esm/index.d.ts +2 -1
  61. package/dist/esm/index.js +2 -1
  62. package/dist/esm/models/AgentConversationDetail.d.ts +12 -0
  63. package/dist/esm/models/AgentConversationDetail.js +4 -0
  64. package/dist/esm/models/AgentConversationView.d.ts +12 -0
  65. package/dist/esm/models/AgentConversationView.js +4 -0
  66. package/dist/esm/models/AgentResource.d.ts +7 -0
  67. package/dist/esm/models/AgentResource.js +3 -0
  68. package/dist/esm/models/AgentVersionSavedResource.d.ts +65 -0
  69. package/dist/esm/models/AgentVersionSavedResource.js +60 -0
  70. package/dist/esm/models/AgentWebhookList.d.ts +33 -0
  71. package/dist/esm/models/AgentWebhookList.js +44 -0
  72. package/dist/esm/models/AgentWebhookView.d.ts +76 -0
  73. package/dist/esm/models/AgentWebhookView.js +70 -0
  74. package/dist/esm/models/ConversationDetail.d.ts +6 -0
  75. package/dist/esm/models/ConversationDetail.js +2 -0
  76. package/dist/esm/models/ConversationView.d.ts +6 -0
  77. package/dist/esm/models/ConversationView.js +2 -0
  78. package/dist/esm/models/ErrorDetailItem.d.ts +3 -0
  79. package/dist/esm/models/FileNodeView.d.ts +7 -0
  80. package/dist/esm/models/FileNodeView.js +3 -0
  81. package/dist/esm/models/QueueMessageInput.d.ts +6 -0
  82. package/dist/esm/models/QueueMessageInput.js +2 -0
  83. package/dist/esm/models/RotatedWebhookSecretView.d.ts +58 -0
  84. package/dist/esm/models/RotatedWebhookSecretView.js +61 -0
  85. package/dist/esm/models/SaveWarningView.d.ts +44 -0
  86. package/dist/esm/models/SaveWarningView.js +51 -0
  87. package/dist/esm/models/ShareSkippedResource.d.ts +41 -0
  88. package/dist/esm/models/ShareSkippedResource.js +47 -0
  89. package/dist/esm/models/WebhookSecretPutBody.d.ts +32 -0
  90. package/dist/esm/models/WebhookSecretPutBody.js +43 -0
  91. package/dist/esm/models/WebhookSecretStateView.d.ts +52 -0
  92. package/dist/esm/models/WebhookSecretStateView.js +56 -0
  93. package/dist/esm/models/WebhookSecretValueView.d.ts +32 -0
  94. package/dist/esm/models/WebhookSecretValueView.js +44 -0
  95. package/dist/esm/models/WebhookWarning.d.ts +44 -0
  96. package/dist/esm/models/WebhookWarning.js +51 -0
  97. package/dist/esm/models/index.d.ts +10 -0
  98. package/dist/esm/models/index.js +10 -0
  99. package/dist/index.d.ts +2 -1
  100. package/dist/index.js +4 -1
  101. package/dist/models/AgentConversationDetail.d.ts +12 -0
  102. package/dist/models/AgentConversationDetail.js +4 -0
  103. package/dist/models/AgentConversationView.d.ts +12 -0
  104. package/dist/models/AgentConversationView.js +4 -0
  105. package/dist/models/AgentResource.d.ts +7 -0
  106. package/dist/models/AgentResource.js +3 -0
  107. package/dist/models/AgentVersionSavedResource.d.ts +65 -0
  108. package/dist/models/AgentVersionSavedResource.js +67 -0
  109. package/dist/models/AgentWebhookList.d.ts +33 -0
  110. package/dist/models/AgentWebhookList.js +51 -0
  111. package/dist/models/AgentWebhookView.d.ts +76 -0
  112. package/dist/models/AgentWebhookView.js +78 -0
  113. package/dist/models/ConversationDetail.d.ts +6 -0
  114. package/dist/models/ConversationDetail.js +2 -0
  115. package/dist/models/ConversationView.d.ts +6 -0
  116. package/dist/models/ConversationView.js +2 -0
  117. package/dist/models/ErrorDetailItem.d.ts +3 -0
  118. package/dist/models/FileNodeView.d.ts +7 -0
  119. package/dist/models/FileNodeView.js +3 -0
  120. package/dist/models/QueueMessageInput.d.ts +6 -0
  121. package/dist/models/QueueMessageInput.js +2 -0
  122. package/dist/models/RotatedWebhookSecretView.d.ts +58 -0
  123. package/dist/models/RotatedWebhookSecretView.js +69 -0
  124. package/dist/models/SaveWarningView.d.ts +44 -0
  125. package/dist/models/SaveWarningView.js +58 -0
  126. package/dist/models/ShareSkippedResource.d.ts +41 -0
  127. package/dist/models/ShareSkippedResource.js +54 -0
  128. package/dist/models/WebhookSecretPutBody.d.ts +32 -0
  129. package/dist/models/WebhookSecretPutBody.js +50 -0
  130. package/dist/models/WebhookSecretStateView.d.ts +52 -0
  131. package/dist/models/WebhookSecretStateView.js +64 -0
  132. package/dist/models/WebhookSecretValueView.d.ts +32 -0
  133. package/dist/models/WebhookSecretValueView.js +51 -0
  134. package/dist/models/WebhookWarning.d.ts +44 -0
  135. package/dist/models/WebhookWarning.js +58 -0
  136. package/dist/models/index.d.ts +10 -0
  137. package/dist/models/index.js +10 -0
  138. package/package.json +1 -1
  139. package/src/apis/AgentsApi.ts +366 -11
  140. package/src/apis/ConversationsApi.ts +9 -2
  141. package/src/client.ts +3 -2
  142. package/src/compat/core/agents.ts +265 -36
  143. package/src/compat/core/customApis.ts +506 -0
  144. package/src/compat/core/data.ts +1 -1
  145. package/src/compat/openai/client.ts +7 -1
  146. package/src/compat/openai/index.ts +9 -0
  147. package/src/compat/openai/resources/agents.ts +9 -1
  148. package/src/compat/openai/resources/sarvam.ts +94 -0
  149. package/src/compose/deploy.ts +71 -10
  150. package/src/compose/errors.ts +4 -0
  151. package/src/compose/settingsTransport.ts +78 -131
  152. package/src/compose/transport.ts +10 -2
  153. package/src/compose/webhook.ts +49 -45
  154. package/src/compose/webhookSecrets.ts +227 -179
  155. package/src/index.ts +2 -1
  156. package/src/models/AgentConversationDetail.ts +16 -0
  157. package/src/models/AgentConversationView.ts +16 -0
  158. package/src/models/AgentResource.ts +15 -0
  159. package/src/models/AgentVersionSavedResource.ts +119 -0
  160. package/src/models/AgentWebhookList.ts +74 -0
  161. package/src/models/AgentWebhookView.ts +129 -0
  162. package/src/models/ConversationDetail.ts +8 -0
  163. package/src/models/ConversationView.ts +8 -0
  164. package/src/models/ErrorDetailItem.ts +3 -0
  165. package/src/models/FileNodeView.ts +16 -0
  166. package/src/models/QueueMessageInput.ts +8 -0
  167. package/src/models/RotatedWebhookSecretView.ts +103 -0
  168. package/src/models/SaveWarningView.ts +84 -0
  169. package/src/models/ShareSkippedResource.ts +78 -0
  170. package/src/models/WebhookSecretPutBody.ts +66 -0
  171. package/src/models/WebhookSecretStateView.ts +94 -0
  172. package/src/models/WebhookSecretValueView.ts +66 -0
  173. package/src/models/WebhookWarning.ts +84 -0
  174. package/src/models/index.ts +10 -0
@@ -1,20 +1,21 @@
1
1
  /**
2
2
  * `webhooks` entries of `agent.json`, checked locally with the server's cheap rules (as the Python SDK does).
3
3
  *
4
- * The server (`claw_common/agent_settings/webhooks.py`) also checks that the host resolves to a public address and
5
- * that `secret_credential` names a vault credential bound to the agent whose allowed hosts cover the URL; those need
6
- * I/O and stay on the server, which refuses the save with a 422 that `deploy` throws as `UserError`.
4
+ * The server (`claw_common/agent_settings/webhooks.py`) also checks that the host resolves to a public address; that
5
+ * needs I/O and stays on the server, which refuses the save with a 422 that `deploy` throws as `UserError`.
7
6
  *
8
- * `secretCredential` is optional and deprecated: left out, `deploy` writes the name `client.webhooks` uses for the
9
- * agent and host (`secretCredentialName`). Given, the deploy that creates the agent binds the caller's Custom API of
10
- * that name first (`SettingsTransport.createAgent`).
7
+ * A webhook is identified by its URL. Its signing secret lives in the server's webhook secret store (panja #1857):
8
+ * `deploy` creates it for each webhook it adds and returns it once (`Deployment.webhookSecrets`);
9
+ * `client.webhooks` views, rotates, sets and deletes it.
10
+ *
11
+ * `secretCredential` is deprecated and ignored: the server no longer reads the vault for signing. It is still
12
+ * accepted and never sent, so `agent.json` stays clean.
11
13
  */
12
14
  import { createHash } from "node:crypto";
13
15
  import { UserError } from "./errors.js";
14
16
  import { WEBHOOK_EVENTS } from "../webhooks.js";
15
17
  export const WEBHOOKS_MAX = 5;
16
18
  const WEBHOOK_URL_MAX = 2048;
17
- const SECRET_CREDENTIAL_MAX = 256;
18
19
  const LABEL = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
19
20
  // A last label that is a number (decimal, or 0x hex) makes resolvers read the whole host as an IPv4 address.
20
21
  const NUMERIC_LABEL = /^(?:[0-9]+|0x[0-9a-f]*)$/;
@@ -146,7 +147,8 @@ export function checkWebhooks(webhooks) {
146
147
  throw new UserError(where + "secretCredential: must be a string");
147
148
  }
148
149
  // Python's Webhook is extra="forbid": a key dropped silently (a misplaced secret) would never verify.
149
- const extra = Object.keys(hook).find((k) => k !== "url" && k !== "events" && k !== "secretCredential");
150
+ // A webhook is identified by its URL: a `name` is refused here, as the server does.
151
+ const extra = Object.keys(hook).find((k) => !["url", "events", "secretCredential"].includes(k));
150
152
  if (extra !== undefined)
151
153
  throw new UserError(where + extra + ": Extra inputs are not permitted");
152
154
  const problem = urlProblem(url);
@@ -160,11 +162,6 @@ export function checkWebhooks(webhooks) {
160
162
  }
161
163
  if (new Set(events).size !== events.length)
162
164
  throw new UserError(where + "events: events must not repeat an event.");
163
- const n = typeof secretCredential === "string" ? codePoints(secretCredential) : 1;
164
- if (n < 1 || n > SECRET_CREDENTIAL_MAX) {
165
- throw new UserError(where + "secret_credential: secret_credential must be the name of a vault credential " +
166
- `(1 to ${SECRET_CREDENTIAL_MAX} characters).`);
167
- }
168
165
  const key = urlKey(url);
169
166
  if (seen.has(key)) {
170
167
  throw new UserError(where + "url: webhooks must not list the same url twice; put all its events on one entry.");
@@ -172,47 +169,30 @@ export function checkWebhooks(webhooks) {
172
169
  seen.add(key);
173
170
  });
174
171
  }
175
- /** Only the three fields (a copy). `secretCredential` is left out when absent, or when it is the name `deploy`
176
- * writes anyway (one spelling keeps one fingerprint). */
172
+ /** Only `url` and `events` (a copy): `secretCredential` is ignored, so it is dropped here. */
177
173
  export function copyWebhooks(webhooks) {
178
- return webhooks.map((h) => {
179
- const copy = { url: h.url, events: [...h.events] };
180
- const name = h.secretCredential;
181
- if (name !== undefined && !isSdkCredentialName(name, h.url))
182
- copy.secretCredential = name;
183
- return copy;
184
- });
174
+ return webhooks.map((h) => ({ url: h.url, events: [...h.events] }));
185
175
  }
186
176
  export function webhooksJson(webhooks) {
187
- return webhooks.map((h) => {
188
- const out = { url: h.url, events: [...h.events] };
189
- if (h.secretCredential !== undefined)
190
- out["secret_credential"] = h.secretCredential;
191
- return out;
192
- });
177
+ return webhooks.map((h) => ({ url: h.url, events: [...h.events] }));
193
178
  }
194
179
  /** The host of an allowed webhook URL, lowercased, without a trailing dot or a port. */
195
180
  export function webhookHost(url) {
196
181
  return stripTrailingDots(hostPort(split(url)[1])[0]);
197
182
  }
198
- /** Every Custom API the SDK creates for a webhook secret is named `webhook-secret:<agentId>:<host>`. */
199
- export const SECRET_NAME_PREFIX = "webhook-secret:";
200
- const SECRET_NAME_MAX = 256;
183
+ // -- 0.5.x compatibility ----------------------------------------------------------------------------------------
184
+ // The 0.5.x SDK filled in `secret_credential` as `webhook-secret:<agentId>:<host>` on every webhook it deployed. An
185
+ // agent it deployed still has that name in agent.json; the deploy reads such a webhook without it, so the stored
186
+ // `sdk_hash` (computed without it) still matches and the agent does not read as edited outside the SDK.
187
+ const LEGACY_PREFIX = "webhook-secret:";
201
188
  function hashedHost(host) {
202
189
  return "sha256-" + createHash("sha256").update(host, "utf8").digest("hex").slice(0, 32);
203
190
  }
204
- /** The credential name the SDK uses for `url`'s signing secret on agent `agentId` (what `deploy` writes as
205
- * `secret_credential` when a webhook leaves it out). A host too long to fit 256 characters is hashed. */
206
- export function secretCredentialName(agentId, url) {
207
- const host = webhookHost(url);
208
- const name = `${SECRET_NAME_PREFIX}${agentId}:${host}`;
209
- return codePoints(name) <= SECRET_NAME_MAX ? name : `${SECRET_NAME_PREFIX}${agentId}:${hashedHost(host)}`;
210
- }
211
- /** Whether `name` is the SDK's credential name for `url`'s host, for any agent. */
212
- export function isSdkCredentialName(name, url) {
213
- if (typeof name !== "string" || !name.startsWith(SECRET_NAME_PREFIX) || urlProblem(url) !== null)
191
+ /** Whether `name` is the `secret_credential` the 0.5.x SDK filled in for `url`'s host, for any agent. */
192
+ export function isLegacyCredentialName(name, url) {
193
+ if (typeof name !== "string" || !name.startsWith(LEGACY_PREFIX) || urlProblem(url) !== null)
214
194
  return false;
215
- const rest = name.slice(SECRET_NAME_PREFIX.length);
195
+ const rest = name.slice(LEGACY_PREFIX.length);
216
196
  const at = rest.lastIndexOf(":");
217
197
  if (at <= 0)
218
198
  return false;
@@ -221,3 +201,26 @@ export function isSdkCredentialName(name, url) {
221
201
  const host = webhookHost(url);
222
202
  return !agentId.includes(":") && (tail === host || tail === hashedHost(host));
223
203
  }
204
+ /** `settings` with the `secret_credential` the 0.5.x SDK filled in removed from each webhook. */
205
+ export function withoutLegacyCredentials(settings) {
206
+ const hooks = settings["webhooks"];
207
+ if (!Array.isArray(hooks))
208
+ return settings;
209
+ const legacy = (h) => {
210
+ if (typeof h !== "object" || h === null)
211
+ return false;
212
+ const { url, secret_credential: name } = h;
213
+ return typeof url === "string" && isLegacyCredentialName(name, url);
214
+ };
215
+ if (!hooks.some(legacy))
216
+ return settings;
217
+ return {
218
+ ...settings,
219
+ webhooks: hooks.map((h) => {
220
+ if (!legacy(h))
221
+ return h;
222
+ const { secret_credential: _dropped, ...rest } = h;
223
+ return rest;
224
+ }),
225
+ };
226
+ }
@@ -1,64 +1,94 @@
1
1
  /**
2
- * `client.webhooks`: set, rotate, check and delete an agent webhook's signing secret (as Python's
3
- * `sarvam_agents.compose.webhook_secrets`).
2
+ * `client.webhooks`: list an agent's webhooks, and create, view, rotate, set and delete each one's signing secret (as
3
+ * Python's `sarvam_agents.compose.webhook_secrets`).
4
4
  *
5
- * The public surface is `WebhookSecrets`. Where the secret lives is behind `SecretBackend`, one small interface with
6
- * one implementation today, `CustomApiBackend`: the secret is a bearer Custom API the SDK creates, owns and binds to
7
- * the agent, always with `enabledForChats: false` (`CustomApiCreate` defaults it to true, which would let the agent's
8
- * sandbox be handed the secret on requests to the webhook's host). When the server ships dedicated secret endpoints
9
- * (SARC-2597: PUT/DELETE secret, rotate-secret, secretStatus), a second backend replaces this one in `secretBackend`
10
- * and nothing else changes.
5
+ * Built on the owner-only routes of the server's webhook secret store (panja #1857, SARC-2597):
6
+ * `GET /v1/agents/{id}/webhooks` and `POST`/`GET`/`PUT`/`DELETE .../webhooks/{webhookKey}/secret` and
7
+ * `POST .../rotate-secret`. The `webhookKey` is always read from the list, by the webhook's exact URL; it is never
8
+ * computed here.
11
9
  *
12
10
  * No secret is logged, kept on an object or put in an error message.
13
11
  */
14
- import { CustomAPIsApi } from "../apis/CustomAPIsApi.js";
12
+ import { AgentsApi } from "../apis/AgentsApi.js";
13
+ import type { AgentWebhookView } from "../models/AgentWebhookView.js";
15
14
  import type { Configuration } from "../runtime.js";
16
15
  import type { Webhook } from "./webhook.js";
16
+ /** `"set"`: deliveries are signed with the webhook's secret. `"missing"`: it has none, so nothing is sent to it. */
17
17
  export type SecretStatus = "set" | "missing";
18
- /** Every Custom API the SDK creates for a webhook secret carries this description (and its name). */
19
- export declare const SECRET_DESCRIPTION = "Webhook signing secret managed by the Sarvam Agents SDK (client.webhooks). Do not edit.";
20
- /** The description of the random secret `deploy` stores when none is set yet: `secretStatus` reads it as
21
- * `"missing"`, and `setSecret`/`rotateSecret` overwrite it with `SECRET_DESCRIPTION`. */
22
- export declare const PLACEHOLDER_DESCRIPTION = "Webhook signing secret managed by the Sarvam Agents SDK (client.webhooks). Placeholder: call client.webhooks.set_secret";
23
- /** Where webhook secrets live. Swap the implementation in `secretBackend`, nowhere else. */
24
- export interface SecretBackend {
25
- /** Store `secret` for `url` on the agent, replacing any current one. */
26
- put(agentId: string, url: string, secret: string): Promise<void>;
27
- /** `"set"` only for a secret stored by `put`; a placeholder from `ensure` is `"missing"`. */
28
- status(agentId: string, url: string): Promise<SecretStatus>;
29
- /** Remove the secret; nothing to remove is not an error. */
30
- delete(agentId: string, url: string): Promise<void>;
31
- /** For `deploy`: make sure the agent has a secret for `url` (a random placeholder one if none) and return the
32
- * credential name for agent.json `secret_credential` and `status` (`"missing"` while it is a placeholder). */
33
- ensure(agentId: string, url: string): Promise<{
34
- name: string;
35
- status: SecretStatus;
36
- }>;
37
- }
38
- /** The one place that picks where secrets live. */
39
- export declare function secretBackend(api: {
40
- config?: Configuration;
41
- customApis?: CustomAPIsApi;
42
- }): SecretBackend;
18
+ /** How long a replaced secret keeps signing after `rotateSecret` or `setSecret` (fixed by the server). */
19
+ export declare const PREVIOUS_SECRET_SECONDS = 86400;
20
+ /** The fine-grained reason of a chat_service error (`details[0].code` or `.reason`), else undefined. */
21
+ export declare function errorCode(err: unknown): Promise<string | undefined>;
43
22
  /**
44
- * `client.webhooks`: the signing secret of each agent.json webhook.
23
+ * `client.webhooks`: an agent's agent.json webhooks and each one's signing secret.
24
+ *
25
+ * `url` is the webhook's URL exactly as in agent.json (or a webhook object). Its `webhookKey` is read from `list` by
26
+ * exact URL match, so the agent must have the webhook (`deploy` it first). Secrets are `whsec_` plus base64 of 24 to
27
+ * 64 bytes. Only the agent's owner can call these.
45
28
  *
46
- * `webhook` is the webhook's URL (or a webhook object); the secret covers the URL's host. Secrets are `whsec_` plus
47
- * base64 of 24 to 64 bytes.
29
+ * `deploy` already creates the secret of each webhook it adds and returns it once (`Deployment.webhookSecrets`).
30
+ * Nothing is delivered to a webhook without a secret.
48
31
  */
49
32
  export declare class WebhookSecrets {
50
33
  #private;
34
+ /** The generated API these helpers call. */
35
+ readonly api: AgentsApi;
51
36
  constructor(config: Configuration);
52
- /** Store `secret` (a new generated one when left out) as the webhook's signing secret and return it. A malformed
53
- * secret throws `SecretFormatError` before anything is sent. */
54
- setSecret(agentId: string, webhook: string | Webhook, secret?: string): Promise<string>;
55
- /** Replace the webhook's signing secret with a new generated one and return it. Have your receiver accept the old
56
- * and the new secret for a few minutes: a delivery still retrying is signed with the new one. */
57
- rotateSecret(agentId: string, webhook: string | Webhook): Promise<string>;
58
- /** `"set"` when the agent has a signing secret stored by `setSecret` or `rotateSecret` for the webhook; `"missing"`
59
- * otherwise, including while it holds the placeholder a deploy stored. */
60
- secretStatus(agentId: string, webhook: string | Webhook): Promise<SecretStatus>;
61
- /** Remove the webhook's signing secret. Only what the SDK stored is removed; a Custom API you made yourself is
62
- * never touched. Deliveries to the webhook fail until a new secret is set or the webhook is removed. */
63
- deleteSecret(agentId: string, webhook: string | Webhook): Promise<void>;
37
+ /**
38
+ * The agent's webhooks, each with `webhookKey`, `url`, `events`, `inAgentJson`, `secretStatus` (`"set"` or
39
+ * `"missing"`), `secretUpdatedAt` and, during the 24 hours after a rotation, `previousExpiresAt`.
40
+ *
41
+ * After them come orphans: a secret whose webhook was removed from agent.json is kept (the same URL added back signs
42
+ * with it again) and listed with `inAgentJson: false` and `url: null` (the server keeps only the key). Remove one
43
+ * with `deleteSecret(agentId, { webhookKey })`.
44
+ */
45
+ list(agentId: string): Promise<AgentWebhookView[]>;
46
+ /** `"set"` or `"missing"` (nothing is sent to a webhook without a secret). */
47
+ secretStatus(agentId: string, url: string | Webhook): Promise<SecretStatus>;
48
+ /** The webhook's current signing secret, to view again at any time (never the previous one during a rotation).
49
+ * Throws `UserError` when it has none. If it leaked, rotate it. */
50
+ getSecret(agentId: string, url: string | Webhook): Promise<string>;
51
+ /** Create the webhook's first signing secret (or a new one after a delete) and return it. Give it to your receiver.
52
+ * Throws `SecretExistsError` when the webhook already has one: rotate it instead. */
53
+ createSecret(agentId: string, url: string | Webhook): Promise<string>;
54
+ /**
55
+ * Replace the webhook's signing secret with a new one the server generates, and return it.
56
+ *
57
+ * The old secret keeps signing for 24 hours (fixed), so every delivery meanwhile carries both signatures: switch
58
+ * your receiver to the new secret within that time. There is one previous slot: rotating again within the 24 hours
59
+ * drops the first old secret at once. After a leak, cut over at once instead: `deleteSecret`, then `createSecret`.
60
+ * Throws `UserError` when the webhook has no secret: create one first.
61
+ */
62
+ rotateSecret(agentId: string, url: string | Webhook): Promise<string>;
63
+ /**
64
+ * Use `secret`, one you made, as the webhook's signing secret (bring your own). A secret it replaces keeps signing
65
+ * for 24 hours. The server never echoes it. A malformed secret throws `SecretFormatError` before anything is sent.
66
+ *
67
+ * Called without `secret` (the 0.5 form, deprecated) it generates one here, sets it and returns it, with a warning.
68
+ */
69
+ setSecret(agentId: string, url: string | Webhook, secret: string): Promise<void>;
70
+ /** @deprecated The 0.5 form: generates a secret, sets it and returns it. Call `createSecret` (no secret yet) or
71
+ * `rotateSecret` (replace it) instead. */
72
+ setSecret(agentId: string, url: string | Webhook): Promise<string>;
73
+ /**
74
+ * Remove the webhook's signing secret (the current one and any previous one). Nothing is sent to the webhook until
75
+ * it gets a new one (`createSecret` or `setSecret`), even if it is removed from agent.json and added back. Nothing
76
+ * to remove is not an error.
77
+ *
78
+ * Pass the webhook's `url`, or `{ webhookKey }` (from `list`) for an orphan: a secret whose webhook was removed from
79
+ * agent.json has no URL.
80
+ */
81
+ deleteSecret(agentId: string, url: string | Webhook | {
82
+ webhookKey: string;
83
+ }): Promise<void>;
64
84
  }
85
+ /**
86
+ * For `deploy`: create the secret of each of `urls` that is in `added` (the webhooks the deploy added) and whose
87
+ * `secretStatus` is `missing`. Returns the new secrets by URL and the URLs still without a secret: a failed create, a
88
+ * webhook not listed, and a webhook deployed before whose secret is missing (never recreated here). Never rotates or
89
+ * overwrites a secret. A failed create is reported as missing, never thrown; a failed list throws.
90
+ */
91
+ export declare function createMissingSecrets(api: AgentsApi, agentId: string, urls: readonly string[], added: ReadonlySet<string>): Promise<{
92
+ created: Record<string, string>;
93
+ missing: string[];
94
+ }>;