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,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 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
  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
- * The vault credential holding the `whsec_` signing secret (agent.json `secret_credential`). Leave it out: `deploy`
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 Use `client.webhooks.setSecret` instead of creating a Custom API and naming it here.
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
- const extra = Object.keys(hook).find((k) => k !== "url" && k !== "events" && k !== "secretCredential");
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 the three fields (a copy). `secretCredential` is left out when absent, or when it is the name `deploy`
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
- /** Every Custom API the SDK creates for a webhook secret is named `webhook-secret:<agentId>:<host>`. */
209
- export const SECRET_NAME_PREFIX = "webhook-secret:";
210
- const SECRET_NAME_MAX = 256;
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
- /** The credential name the SDK uses for `url`'s signing secret on agent `agentId` (what `deploy` writes as
217
- * `secret_credential` when a webhook leaves it out). A host too long to fit 256 characters is hashed. */
218
- export function secretCredentialName(agentId: string, url: string): string {
219
- const host = webhookHost(url);
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
+ }