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.
- package/README.md +52 -29
- package/dist/apis/AgentsApi.d.ts +96 -11
- package/dist/apis/AgentsApi.js +229 -9
- package/dist/apis/ConversationsApi.d.ts +5 -2
- package/dist/apis/ConversationsApi.js +7 -2
- package/dist/client.d.ts +3 -2
- package/dist/client.js +2 -1
- package/dist/compat/core/agents.d.ts +6 -1
- package/dist/compat/core/agents.js +237 -27
- package/dist/compat/core/customApis.d.ts +76 -0
- package/dist/compat/core/customApis.js +424 -0
- package/dist/compat/core/data.js +1 -1
- package/dist/compat/openai/client.d.ts +3 -0
- package/dist/compat/openai/client.js +5 -1
- package/dist/compat/openai/index.d.ts +1 -0
- package/dist/compat/openai/index.js +0 -1
- package/dist/compat/openai/resources/agents.js +8 -1
- package/dist/compat/openai/resources/sarvam.d.ts +26 -0
- package/dist/compat/openai/resources/sarvam.js +56 -0
- package/dist/compose/deploy.d.ts +14 -3
- package/dist/compose/deploy.js +60 -7
- package/dist/compose/errors.d.ts +4 -0
- package/dist/compose/errors.js +6 -1
- package/dist/compose/settingsTransport.d.ts +18 -13
- package/dist/compose/settingsTransport.js +78 -130
- package/dist/compose/transport.d.ts +12 -2
- package/dist/compose/webhook.d.ts +10 -13
- package/dist/compose/webhook.js +48 -45
- package/dist/compose/webhookSecrets.d.ts +79 -49
- package/dist/compose/webhookSecrets.js +244 -195
- package/dist/esm/apis/AgentsApi.d.ts +96 -11
- package/dist/esm/apis/AgentsApi.js +230 -10
- package/dist/esm/apis/ConversationsApi.d.ts +5 -2
- package/dist/esm/apis/ConversationsApi.js +7 -2
- package/dist/esm/client.d.ts +3 -2
- package/dist/esm/client.js +2 -1
- package/dist/esm/compat/core/agents.d.ts +6 -1
- package/dist/esm/compat/core/agents.js +237 -27
- package/dist/esm/compat/core/customApis.d.ts +76 -0
- package/dist/esm/compat/core/customApis.js +419 -0
- package/dist/esm/compat/core/data.js +1 -1
- package/dist/esm/compat/openai/client.d.ts +3 -0
- package/dist/esm/compat/openai/client.js +5 -1
- package/dist/esm/compat/openai/index.d.ts +1 -0
- package/dist/esm/compat/openai/index.js +0 -1
- package/dist/esm/compat/openai/resources/agents.js +8 -1
- package/dist/esm/compat/openai/resources/sarvam.d.ts +26 -0
- package/dist/esm/compat/openai/resources/sarvam.js +51 -0
- package/dist/esm/compose/deploy.d.ts +14 -3
- package/dist/esm/compose/deploy.js +60 -7
- package/dist/esm/compose/errors.d.ts +4 -0
- package/dist/esm/compose/errors.js +4 -0
- package/dist/esm/compose/settingsTransport.d.ts +18 -13
- package/dist/esm/compose/settingsTransport.js +80 -132
- package/dist/esm/compose/transport.d.ts +12 -2
- package/dist/esm/compose/webhook.d.ts +10 -13
- package/dist/esm/compose/webhook.js +45 -42
- package/dist/esm/compose/webhookSecrets.d.ts +79 -49
- package/dist/esm/compose/webhookSecrets.js +241 -193
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/models/AgentConversationDetail.d.ts +12 -0
- package/dist/esm/models/AgentConversationDetail.js +4 -0
- package/dist/esm/models/AgentConversationView.d.ts +12 -0
- package/dist/esm/models/AgentConversationView.js +4 -0
- package/dist/esm/models/AgentResource.d.ts +7 -0
- package/dist/esm/models/AgentResource.js +3 -0
- package/dist/esm/models/AgentVersionSavedResource.d.ts +65 -0
- package/dist/esm/models/AgentVersionSavedResource.js +60 -0
- package/dist/esm/models/AgentWebhookList.d.ts +33 -0
- package/dist/esm/models/AgentWebhookList.js +44 -0
- package/dist/esm/models/AgentWebhookView.d.ts +76 -0
- package/dist/esm/models/AgentWebhookView.js +70 -0
- package/dist/esm/models/ConversationDetail.d.ts +6 -0
- package/dist/esm/models/ConversationDetail.js +2 -0
- package/dist/esm/models/ConversationView.d.ts +6 -0
- package/dist/esm/models/ConversationView.js +2 -0
- package/dist/esm/models/ErrorDetailItem.d.ts +3 -0
- package/dist/esm/models/FileNodeView.d.ts +7 -0
- package/dist/esm/models/FileNodeView.js +3 -0
- package/dist/esm/models/QueueMessageInput.d.ts +6 -0
- package/dist/esm/models/QueueMessageInput.js +2 -0
- package/dist/esm/models/RotatedWebhookSecretView.d.ts +58 -0
- package/dist/esm/models/RotatedWebhookSecretView.js +61 -0
- package/dist/esm/models/SaveWarningView.d.ts +44 -0
- package/dist/esm/models/SaveWarningView.js +51 -0
- package/dist/esm/models/ShareSkippedResource.d.ts +41 -0
- package/dist/esm/models/ShareSkippedResource.js +47 -0
- package/dist/esm/models/WebhookSecretPutBody.d.ts +32 -0
- package/dist/esm/models/WebhookSecretPutBody.js +43 -0
- package/dist/esm/models/WebhookSecretStateView.d.ts +52 -0
- package/dist/esm/models/WebhookSecretStateView.js +56 -0
- package/dist/esm/models/WebhookSecretValueView.d.ts +32 -0
- package/dist/esm/models/WebhookSecretValueView.js +44 -0
- package/dist/esm/models/WebhookWarning.d.ts +44 -0
- package/dist/esm/models/WebhookWarning.js +51 -0
- package/dist/esm/models/index.d.ts +10 -0
- package/dist/esm/models/index.js +10 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -1
- package/dist/models/AgentConversationDetail.d.ts +12 -0
- package/dist/models/AgentConversationDetail.js +4 -0
- package/dist/models/AgentConversationView.d.ts +12 -0
- package/dist/models/AgentConversationView.js +4 -0
- package/dist/models/AgentResource.d.ts +7 -0
- package/dist/models/AgentResource.js +3 -0
- package/dist/models/AgentVersionSavedResource.d.ts +65 -0
- package/dist/models/AgentVersionSavedResource.js +67 -0
- package/dist/models/AgentWebhookList.d.ts +33 -0
- package/dist/models/AgentWebhookList.js +51 -0
- package/dist/models/AgentWebhookView.d.ts +76 -0
- package/dist/models/AgentWebhookView.js +78 -0
- package/dist/models/ConversationDetail.d.ts +6 -0
- package/dist/models/ConversationDetail.js +2 -0
- package/dist/models/ConversationView.d.ts +6 -0
- package/dist/models/ConversationView.js +2 -0
- package/dist/models/ErrorDetailItem.d.ts +3 -0
- package/dist/models/FileNodeView.d.ts +7 -0
- package/dist/models/FileNodeView.js +3 -0
- package/dist/models/QueueMessageInput.d.ts +6 -0
- package/dist/models/QueueMessageInput.js +2 -0
- package/dist/models/RotatedWebhookSecretView.d.ts +58 -0
- package/dist/models/RotatedWebhookSecretView.js +69 -0
- package/dist/models/SaveWarningView.d.ts +44 -0
- package/dist/models/SaveWarningView.js +58 -0
- package/dist/models/ShareSkippedResource.d.ts +41 -0
- package/dist/models/ShareSkippedResource.js +54 -0
- package/dist/models/WebhookSecretPutBody.d.ts +32 -0
- package/dist/models/WebhookSecretPutBody.js +50 -0
- package/dist/models/WebhookSecretStateView.d.ts +52 -0
- package/dist/models/WebhookSecretStateView.js +64 -0
- package/dist/models/WebhookSecretValueView.d.ts +32 -0
- package/dist/models/WebhookSecretValueView.js +51 -0
- package/dist/models/WebhookWarning.d.ts +44 -0
- package/dist/models/WebhookWarning.js +58 -0
- package/dist/models/index.d.ts +10 -0
- package/dist/models/index.js +10 -0
- package/package.json +1 -1
- package/src/apis/AgentsApi.ts +366 -11
- package/src/apis/ConversationsApi.ts +9 -2
- package/src/client.ts +3 -2
- package/src/compat/core/agents.ts +265 -36
- package/src/compat/core/customApis.ts +506 -0
- package/src/compat/core/data.ts +1 -1
- package/src/compat/openai/client.ts +7 -1
- package/src/compat/openai/index.ts +9 -0
- package/src/compat/openai/resources/agents.ts +9 -1
- package/src/compat/openai/resources/sarvam.ts +94 -0
- package/src/compose/deploy.ts +71 -10
- package/src/compose/errors.ts +4 -0
- package/src/compose/settingsTransport.ts +78 -131
- package/src/compose/transport.ts +10 -2
- package/src/compose/webhook.ts +49 -45
- package/src/compose/webhookSecrets.ts +227 -179
- package/src/index.ts +2 -1
- package/src/models/AgentConversationDetail.ts +16 -0
- package/src/models/AgentConversationView.ts +16 -0
- package/src/models/AgentResource.ts +15 -0
- package/src/models/AgentVersionSavedResource.ts +119 -0
- package/src/models/AgentWebhookList.ts +74 -0
- package/src/models/AgentWebhookView.ts +129 -0
- package/src/models/ConversationDetail.ts +8 -0
- package/src/models/ConversationView.ts +8 -0
- package/src/models/ErrorDetailItem.ts +3 -0
- package/src/models/FileNodeView.ts +16 -0
- package/src/models/QueueMessageInput.ts +8 -0
- package/src/models/RotatedWebhookSecretView.ts +103 -0
- package/src/models/SaveWarningView.ts +84 -0
- package/src/models/ShareSkippedResource.ts +78 -0
- package/src/models/WebhookSecretPutBody.ts +66 -0
- package/src/models/WebhookSecretStateView.ts +94 -0
- package/src/models/WebhookSecretValueView.ts +66 -0
- package/src/models/WebhookWarning.ts +84 -0
- 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
|
|
5
|
-
*
|
|
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
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
/**
|
|
205
|
-
|
|
206
|
-
|
|
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(
|
|
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`:
|
|
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
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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 {
|
|
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
|
-
/**
|
|
19
|
-
export declare const
|
|
20
|
-
/** The
|
|
21
|
-
|
|
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`:
|
|
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
|
-
* `
|
|
47
|
-
*
|
|
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
|
-
/**
|
|
53
|
-
*
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
|
|
63
|
-
|
|
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
|
+
}>;
|