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.
Files changed (143) 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/compose/deploy.d.ts +14 -3
  9. package/dist/compose/deploy.js +60 -7
  10. package/dist/compose/errors.d.ts +4 -0
  11. package/dist/compose/errors.js +6 -1
  12. package/dist/compose/settingsTransport.d.ts +18 -13
  13. package/dist/compose/settingsTransport.js +78 -130
  14. package/dist/compose/transport.d.ts +12 -2
  15. package/dist/compose/webhook.d.ts +10 -13
  16. package/dist/compose/webhook.js +48 -45
  17. package/dist/compose/webhookSecrets.d.ts +79 -49
  18. package/dist/compose/webhookSecrets.js +244 -195
  19. package/dist/esm/apis/AgentsApi.d.ts +96 -11
  20. package/dist/esm/apis/AgentsApi.js +230 -10
  21. package/dist/esm/apis/ConversationsApi.d.ts +5 -2
  22. package/dist/esm/apis/ConversationsApi.js +7 -2
  23. package/dist/esm/client.d.ts +3 -2
  24. package/dist/esm/client.js +2 -1
  25. package/dist/esm/compose/deploy.d.ts +14 -3
  26. package/dist/esm/compose/deploy.js +60 -7
  27. package/dist/esm/compose/errors.d.ts +4 -0
  28. package/dist/esm/compose/errors.js +4 -0
  29. package/dist/esm/compose/settingsTransport.d.ts +18 -13
  30. package/dist/esm/compose/settingsTransport.js +80 -132
  31. package/dist/esm/compose/transport.d.ts +12 -2
  32. package/dist/esm/compose/webhook.d.ts +10 -13
  33. package/dist/esm/compose/webhook.js +45 -42
  34. package/dist/esm/compose/webhookSecrets.d.ts +79 -49
  35. package/dist/esm/compose/webhookSecrets.js +241 -193
  36. package/dist/esm/index.d.ts +2 -1
  37. package/dist/esm/index.js +2 -1
  38. package/dist/esm/models/AgentConversationDetail.d.ts +12 -0
  39. package/dist/esm/models/AgentConversationDetail.js +4 -0
  40. package/dist/esm/models/AgentConversationView.d.ts +12 -0
  41. package/dist/esm/models/AgentConversationView.js +4 -0
  42. package/dist/esm/models/AgentResource.d.ts +7 -0
  43. package/dist/esm/models/AgentResource.js +3 -0
  44. package/dist/esm/models/AgentVersionSavedResource.d.ts +65 -0
  45. package/dist/esm/models/AgentVersionSavedResource.js +60 -0
  46. package/dist/esm/models/AgentWebhookList.d.ts +33 -0
  47. package/dist/esm/models/AgentWebhookList.js +44 -0
  48. package/dist/esm/models/AgentWebhookView.d.ts +76 -0
  49. package/dist/esm/models/AgentWebhookView.js +70 -0
  50. package/dist/esm/models/ConversationDetail.d.ts +6 -0
  51. package/dist/esm/models/ConversationDetail.js +2 -0
  52. package/dist/esm/models/ConversationView.d.ts +6 -0
  53. package/dist/esm/models/ConversationView.js +2 -0
  54. package/dist/esm/models/ErrorDetailItem.d.ts +3 -0
  55. package/dist/esm/models/FileNodeView.d.ts +7 -0
  56. package/dist/esm/models/FileNodeView.js +3 -0
  57. package/dist/esm/models/QueueMessageInput.d.ts +6 -0
  58. package/dist/esm/models/QueueMessageInput.js +2 -0
  59. package/dist/esm/models/RotatedWebhookSecretView.d.ts +58 -0
  60. package/dist/esm/models/RotatedWebhookSecretView.js +61 -0
  61. package/dist/esm/models/SaveWarningView.d.ts +44 -0
  62. package/dist/esm/models/SaveWarningView.js +51 -0
  63. package/dist/esm/models/ShareSkippedResource.d.ts +41 -0
  64. package/dist/esm/models/ShareSkippedResource.js +47 -0
  65. package/dist/esm/models/WebhookSecretPutBody.d.ts +32 -0
  66. package/dist/esm/models/WebhookSecretPutBody.js +43 -0
  67. package/dist/esm/models/WebhookSecretStateView.d.ts +52 -0
  68. package/dist/esm/models/WebhookSecretStateView.js +56 -0
  69. package/dist/esm/models/WebhookSecretValueView.d.ts +32 -0
  70. package/dist/esm/models/WebhookSecretValueView.js +44 -0
  71. package/dist/esm/models/WebhookWarning.d.ts +44 -0
  72. package/dist/esm/models/WebhookWarning.js +51 -0
  73. package/dist/esm/models/index.d.ts +10 -0
  74. package/dist/esm/models/index.js +10 -0
  75. package/dist/index.d.ts +2 -1
  76. package/dist/index.js +4 -1
  77. package/dist/models/AgentConversationDetail.d.ts +12 -0
  78. package/dist/models/AgentConversationDetail.js +4 -0
  79. package/dist/models/AgentConversationView.d.ts +12 -0
  80. package/dist/models/AgentConversationView.js +4 -0
  81. package/dist/models/AgentResource.d.ts +7 -0
  82. package/dist/models/AgentResource.js +3 -0
  83. package/dist/models/AgentVersionSavedResource.d.ts +65 -0
  84. package/dist/models/AgentVersionSavedResource.js +67 -0
  85. package/dist/models/AgentWebhookList.d.ts +33 -0
  86. package/dist/models/AgentWebhookList.js +51 -0
  87. package/dist/models/AgentWebhookView.d.ts +76 -0
  88. package/dist/models/AgentWebhookView.js +78 -0
  89. package/dist/models/ConversationDetail.d.ts +6 -0
  90. package/dist/models/ConversationDetail.js +2 -0
  91. package/dist/models/ConversationView.d.ts +6 -0
  92. package/dist/models/ConversationView.js +2 -0
  93. package/dist/models/ErrorDetailItem.d.ts +3 -0
  94. package/dist/models/FileNodeView.d.ts +7 -0
  95. package/dist/models/FileNodeView.js +3 -0
  96. package/dist/models/QueueMessageInput.d.ts +6 -0
  97. package/dist/models/QueueMessageInput.js +2 -0
  98. package/dist/models/RotatedWebhookSecretView.d.ts +58 -0
  99. package/dist/models/RotatedWebhookSecretView.js +69 -0
  100. package/dist/models/SaveWarningView.d.ts +44 -0
  101. package/dist/models/SaveWarningView.js +58 -0
  102. package/dist/models/ShareSkippedResource.d.ts +41 -0
  103. package/dist/models/ShareSkippedResource.js +54 -0
  104. package/dist/models/WebhookSecretPutBody.d.ts +32 -0
  105. package/dist/models/WebhookSecretPutBody.js +50 -0
  106. package/dist/models/WebhookSecretStateView.d.ts +52 -0
  107. package/dist/models/WebhookSecretStateView.js +64 -0
  108. package/dist/models/WebhookSecretValueView.d.ts +32 -0
  109. package/dist/models/WebhookSecretValueView.js +51 -0
  110. package/dist/models/WebhookWarning.d.ts +44 -0
  111. package/dist/models/WebhookWarning.js +58 -0
  112. package/dist/models/index.d.ts +10 -0
  113. package/dist/models/index.js +10 -0
  114. package/package.json +1 -1
  115. package/src/apis/AgentsApi.ts +366 -11
  116. package/src/apis/ConversationsApi.ts +9 -2
  117. package/src/client.ts +3 -2
  118. package/src/compose/deploy.ts +71 -10
  119. package/src/compose/errors.ts +4 -0
  120. package/src/compose/settingsTransport.ts +78 -131
  121. package/src/compose/transport.ts +10 -2
  122. package/src/compose/webhook.ts +49 -45
  123. package/src/compose/webhookSecrets.ts +227 -179
  124. package/src/index.ts +2 -1
  125. package/src/models/AgentConversationDetail.ts +16 -0
  126. package/src/models/AgentConversationView.ts +16 -0
  127. package/src/models/AgentResource.ts +15 -0
  128. package/src/models/AgentVersionSavedResource.ts +119 -0
  129. package/src/models/AgentWebhookList.ts +74 -0
  130. package/src/models/AgentWebhookView.ts +129 -0
  131. package/src/models/ConversationDetail.ts +8 -0
  132. package/src/models/ConversationView.ts +8 -0
  133. package/src/models/ErrorDetailItem.ts +3 -0
  134. package/src/models/FileNodeView.ts +16 -0
  135. package/src/models/QueueMessageInput.ts +8 -0
  136. package/src/models/RotatedWebhookSecretView.ts +103 -0
  137. package/src/models/SaveWarningView.ts +84 -0
  138. package/src/models/ShareSkippedResource.ts +78 -0
  139. package/src/models/WebhookSecretPutBody.ts +66 -0
  140. package/src/models/WebhookSecretStateView.ts +94 -0
  141. package/src/models/WebhookSecretValueView.ts +66 -0
  142. package/src/models/WebhookWarning.ts +84 -0
  143. package/src/models/index.ts +10 -0
@@ -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
+ }>;