sarvam-agents-client 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/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/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/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
package/src/compose/webhook.ts
CHANGED
|
@@ -1,37 +1,40 @@
|
|
|
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
|
import type { WebhookEventType } from "../webhooks.js";
|
|
16
18
|
|
|
17
|
-
/** Where the agent reports a finished, failed or paused turn (agent.json `webhooks[]`).
|
|
19
|
+
/** Where the agent reports a finished, failed or paused turn (agent.json `webhooks[]`). The deploy that adds it
|
|
20
|
+
* creates its signing secret and returns it once (`Deployment.webhookSecrets[url]`); nothing is delivered to a
|
|
21
|
+
* webhook without a secret. The secret belongs to the exact URL: a changed URL is a new webhook with a new secret. */
|
|
18
22
|
export interface Webhook {
|
|
19
23
|
/** An `https://` URL on port 443 with a DNS host; a query string is allowed. */
|
|
20
24
|
url: string;
|
|
21
25
|
/** 1 to 4 distinct events. `approval.requested` is reserved: accepted, not sent yet. */
|
|
22
26
|
events: WebhookEventType[];
|
|
23
27
|
/**
|
|
24
|
-
*
|
|
25
|
-
* fills in the credential `client.webhooks` keeps, and `client.webhooks.setSecret(agentId, url)` sets the secret.
|
|
28
|
+
* Ignored: never sent to the server, which keeps each webhook's signing secret itself.
|
|
26
29
|
*
|
|
27
|
-
* @deprecated
|
|
30
|
+
* @deprecated Leave it out; `deploy` creates the webhook's secret.
|
|
28
31
|
*/
|
|
29
32
|
secretCredential?: string;
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
export const WEBHOOKS_MAX = 5;
|
|
36
|
+
|
|
33
37
|
const WEBHOOK_URL_MAX = 2048;
|
|
34
|
-
const SECRET_CREDENTIAL_MAX = 256;
|
|
35
38
|
|
|
36
39
|
const LABEL = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
37
40
|
// A last label that is a number (decimal, or 0x hex) makes resolvers read the whole host as an IPv4 address.
|
|
@@ -157,7 +160,8 @@ export function checkWebhooks(webhooks: unknown): void {
|
|
|
157
160
|
throw new UserError(where + "secretCredential: must be a string");
|
|
158
161
|
}
|
|
159
162
|
// Python's Webhook is extra="forbid": a key dropped silently (a misplaced secret) would never verify.
|
|
160
|
-
|
|
163
|
+
// A webhook is identified by its URL: a `name` is refused here, as the server does.
|
|
164
|
+
const extra = Object.keys(hook).find((k) => !["url", "events", "secretCredential"].includes(k));
|
|
161
165
|
if (extra !== undefined) throw new UserError(where + extra + ": Extra inputs are not permitted");
|
|
162
166
|
const problem = urlProblem(url);
|
|
163
167
|
if (problem !== null) throw new UserError(where + "url: " + problem);
|
|
@@ -168,11 +172,6 @@ export function checkWebhooks(webhooks: unknown): void {
|
|
|
168
172
|
throw new UserError(where + `events: events must be from: ${WEBHOOK_EVENTS.join(", ")}.`);
|
|
169
173
|
}
|
|
170
174
|
if (new Set(events).size !== events.length) throw new UserError(where + "events: events must not repeat an event.");
|
|
171
|
-
const n = typeof secretCredential === "string" ? codePoints(secretCredential) : 1;
|
|
172
|
-
if (n < 1 || n > SECRET_CREDENTIAL_MAX) {
|
|
173
|
-
throw new UserError(where + "secret_credential: secret_credential must be the name of a vault credential " +
|
|
174
|
-
`(1 to ${SECRET_CREDENTIAL_MAX} characters).`);
|
|
175
|
-
}
|
|
176
175
|
const key = urlKey(url);
|
|
177
176
|
if (seen.has(key)) {
|
|
178
177
|
throw new UserError(where + "url: webhooks must not list the same url twice; put all its events on one entry.");
|
|
@@ -181,23 +180,13 @@ export function checkWebhooks(webhooks: unknown): void {
|
|
|
181
180
|
});
|
|
182
181
|
}
|
|
183
182
|
|
|
184
|
-
/** Only
|
|
185
|
-
* writes anyway (one spelling keeps one fingerprint). */
|
|
183
|
+
/** Only `url` and `events` (a copy): `secretCredential` is ignored, so it is dropped here. */
|
|
186
184
|
export function copyWebhooks(webhooks: readonly Webhook[]): Webhook[] {
|
|
187
|
-
return webhooks.map((h) => {
|
|
188
|
-
const copy: Webhook = { url: h.url, events: [...h.events] };
|
|
189
|
-
const name = h.secretCredential;
|
|
190
|
-
if (name !== undefined && !isSdkCredentialName(name, h.url)) copy.secretCredential = name;
|
|
191
|
-
return copy;
|
|
192
|
-
});
|
|
185
|
+
return webhooks.map((h) => ({ url: h.url, events: [...h.events] }));
|
|
193
186
|
}
|
|
194
187
|
|
|
195
188
|
export function webhooksJson(webhooks: readonly Webhook[]): Record<string, unknown>[] {
|
|
196
|
-
return webhooks.map((h) => {
|
|
197
|
-
const out: Record<string, unknown> = { url: h.url, events: [...h.events] };
|
|
198
|
-
if (h.secretCredential !== undefined) out["secret_credential"] = h.secretCredential;
|
|
199
|
-
return out;
|
|
200
|
-
});
|
|
189
|
+
return webhooks.map((h) => ({ url: h.url, events: [...h.events] }));
|
|
201
190
|
}
|
|
202
191
|
|
|
203
192
|
/** The host of an allowed webhook URL, lowercased, without a trailing dot or a port. */
|
|
@@ -205,26 +194,21 @@ export function webhookHost(url: string): string {
|
|
|
205
194
|
return stripTrailingDots(hostPort(split(url)[1])[0]);
|
|
206
195
|
}
|
|
207
196
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
197
|
+
// -- 0.5.x compatibility ----------------------------------------------------------------------------------------
|
|
198
|
+
// The 0.5.x SDK filled in `secret_credential` as `webhook-secret:<agentId>:<host>` on every webhook it deployed. An
|
|
199
|
+
// agent it deployed still has that name in agent.json; the deploy reads such a webhook without it, so the stored
|
|
200
|
+
// `sdk_hash` (computed without it) still matches and the agent does not read as edited outside the SDK.
|
|
201
|
+
|
|
202
|
+
const LEGACY_PREFIX = "webhook-secret:";
|
|
211
203
|
|
|
212
204
|
function hashedHost(host: string): string {
|
|
213
205
|
return "sha256-" + createHash("sha256").update(host, "utf8").digest("hex").slice(0, 32);
|
|
214
206
|
}
|
|
215
207
|
|
|
216
|
-
/**
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
const name = `${SECRET_NAME_PREFIX}${agentId}:${host}`;
|
|
221
|
-
return codePoints(name) <= SECRET_NAME_MAX ? name : `${SECRET_NAME_PREFIX}${agentId}:${hashedHost(host)}`;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/** Whether `name` is the SDK's credential name for `url`'s host, for any agent. */
|
|
225
|
-
export function isSdkCredentialName(name: unknown, url: string): boolean {
|
|
226
|
-
if (typeof name !== "string" || !name.startsWith(SECRET_NAME_PREFIX) || urlProblem(url) !== null) return false;
|
|
227
|
-
const rest = name.slice(SECRET_NAME_PREFIX.length);
|
|
208
|
+
/** Whether `name` is the `secret_credential` the 0.5.x SDK filled in for `url`'s host, for any agent. */
|
|
209
|
+
export function isLegacyCredentialName(name: unknown, url: string): boolean {
|
|
210
|
+
if (typeof name !== "string" || !name.startsWith(LEGACY_PREFIX) || urlProblem(url) !== null) return false;
|
|
211
|
+
const rest = name.slice(LEGACY_PREFIX.length);
|
|
228
212
|
const at = rest.lastIndexOf(":");
|
|
229
213
|
if (at <= 0) return false;
|
|
230
214
|
const agentId = rest.slice(0, at);
|
|
@@ -232,3 +216,23 @@ export function isSdkCredentialName(name: unknown, url: string): boolean {
|
|
|
232
216
|
const host = webhookHost(url);
|
|
233
217
|
return !agentId.includes(":") && (tail === host || tail === hashedHost(host));
|
|
234
218
|
}
|
|
219
|
+
|
|
220
|
+
/** `settings` with the `secret_credential` the 0.5.x SDK filled in removed from each webhook. */
|
|
221
|
+
export function withoutLegacyCredentials(settings: Record<string, unknown>): Record<string, unknown> {
|
|
222
|
+
const hooks = settings["webhooks"];
|
|
223
|
+
if (!Array.isArray(hooks)) return settings;
|
|
224
|
+
const legacy = (h: unknown): boolean => {
|
|
225
|
+
if (typeof h !== "object" || h === null) return false;
|
|
226
|
+
const { url, secret_credential: name } = h as Record<string, unknown>;
|
|
227
|
+
return typeof url === "string" && isLegacyCredentialName(name, url);
|
|
228
|
+
};
|
|
229
|
+
if (!hooks.some(legacy)) return settings;
|
|
230
|
+
return {
|
|
231
|
+
...settings,
|
|
232
|
+
webhooks: hooks.map((h) => {
|
|
233
|
+
if (!legacy(h)) return h;
|
|
234
|
+
const { secret_credential: _dropped, ...rest } = h as Record<string, unknown>;
|
|
235
|
+
return rest;
|
|
236
|
+
}),
|
|
237
|
+
};
|
|
238
|
+
}
|