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
@@ -18,7 +18,7 @@ import { ConversationDetailFromJSON, ConversationViewFromJSON, CreateConversatio
18
18
  */
19
19
  export class ConversationsApi extends runtime.BaseAPI {
20
20
  /**
21
- * ``origin=managed_agents`` creates the conversation as session type ``api`` (a managed-agent API session, hidden from the default inbox). It requires ``agentId``: a managed-agent session is always about one agent, and the session log lists it by that id. The agent must be visible to the caller (else 404, existence hidden like every other agent read) and a deployed managed agent (else 409 ``AGENT_NOT_DEPLOYED``). Without ``origin`` nothing is checked here — the gateway enforces agent visibility at ingest, as it always has. A conversation created with ``X-Panja-Surface: playground`` (an agent\'s Playground) is saved as session type ``playground``: hidden from the default inbox and listed apart from real chats in the agent\'s session log. Never gated, so drafts work (``services.session_types``).
21
+ * ``origin=managed_agents`` creates the conversation as session type ``api`` (a managed-agent API session, hidden from the default inbox). It requires ``agentId``: a managed-agent session is always about one agent, and the session log lists it by that id. The agent must be visible to the caller (else 404, existence hidden like every other agent read) and a deployed managed agent (else 409 ``AGENT_NOT_DEPLOYED``). Without ``origin``, an ``agentId`` or ``metadata.agent_id`` (how Indus binds a chat) must still name an agent the caller can see (else 404): the binding puts the chat in that agent\'s session log and interaction count. A conversation created with ``X-Panja-Surface: playground`` (an agent\'s Playground) is saved as session type ``playground``: hidden from the default inbox and listed apart from real chats in the agent\'s session log. Never gated, so drafts work (``services.session_types``).
22
22
  * Create Conversation Route
23
23
  */
24
24
  async createConversationRaw(requestParameters, initOverrides) {
@@ -51,7 +51,7 @@ export class ConversationsApi extends runtime.BaseAPI {
51
51
  return new runtime.JSONApiResponse(response, (jsonValue) => ConversationViewFromJSON(jsonValue));
52
52
  }
53
53
  /**
54
- * ``origin=managed_agents`` creates the conversation as session type ``api`` (a managed-agent API session, hidden from the default inbox). It requires ``agentId``: a managed-agent session is always about one agent, and the session log lists it by that id. The agent must be visible to the caller (else 404, existence hidden like every other agent read) and a deployed managed agent (else 409 ``AGENT_NOT_DEPLOYED``). Without ``origin`` nothing is checked here — the gateway enforces agent visibility at ingest, as it always has. A conversation created with ``X-Panja-Surface: playground`` (an agent\'s Playground) is saved as session type ``playground``: hidden from the default inbox and listed apart from real chats in the agent\'s session log. Never gated, so drafts work (``services.session_types``).
54
+ * ``origin=managed_agents`` creates the conversation as session type ``api`` (a managed-agent API session, hidden from the default inbox). It requires ``agentId``: a managed-agent session is always about one agent, and the session log lists it by that id. The agent must be visible to the caller (else 404, existence hidden like every other agent read) and a deployed managed agent (else 409 ``AGENT_NOT_DEPLOYED``). Without ``origin``, an ``agentId`` or ``metadata.agent_id`` (how Indus binds a chat) must still name an agent the caller can see (else 404): the binding puts the chat in that agent\'s session log and interaction count. A conversation created with ``X-Panja-Surface: playground`` (an agent\'s Playground) is saved as session type ``playground``: hidden from the default inbox and listed apart from real chats in the agent\'s session log. Never gated, so drafts work (``services.session_types``).
55
55
  * Create Conversation Route
56
56
  */
57
57
  async createConversation(requestParameters, initOverrides) {
@@ -184,6 +184,9 @@ export class ConversationsApi extends runtime.BaseAPI {
184
184
  if (requestParameters['sessionType'] != null) {
185
185
  queryParameters['sessionType'] = requestParameters['sessionType'];
186
186
  }
187
+ if (requestParameters['agentId'] != null) {
188
+ queryParameters['agentId'] = requestParameters['agentId'];
189
+ }
187
190
  const headerParameters = {};
188
191
  if (this.configuration && this.configuration.accessToken) {
189
192
  const token = this.configuration.accessToken;
@@ -313,6 +316,7 @@ export class ConversationsApi extends runtime.BaseAPI {
313
316
  return await response.value();
314
317
  }
315
318
  /**
319
+ * Rename or replace ``metadata``. A ``metadata.agent_id`` that differs from the stored one must name an agent the caller can see (else 404); an unchanged one is not re-checked, so a chat whose agent was since unshared can still be renamed.
316
320
  * Update Conversation Route
317
321
  */
318
322
  async updateConversationRaw(requestParameters, initOverrides) {
@@ -342,6 +346,7 @@ export class ConversationsApi extends runtime.BaseAPI {
342
346
  return new runtime.JSONApiResponse(response, (jsonValue) => ConversationViewFromJSON(jsonValue));
343
347
  }
344
348
  /**
349
+ * Rename or replace ``metadata``. A ``metadata.agent_id`` that differs from the stored one must name an agent the caller can see (else 404); an unchanged one is not re-checked, so a chat whose agent was since unshared can still be renamed.
345
350
  * Update Conversation Route
346
351
  */
347
352
  async updateConversation(requestParameters, initOverrides) {
@@ -6,13 +6,14 @@ import { WebhookSecrets } from "./compose/webhookSecrets.js";
6
6
  *
7
7
  * ```ts
8
8
  * const client = new Client(config);
9
- * const secret = await client.webhooks.setSecret(agentId, "https://hooks.acme.com/panja");
9
+ * const hooks = await client.webhooks.list(agentId); // each webhook and its secretStatus
10
+ * const secret = await client.webhooks.getSecret(agentId, "https://hooks.acme.com/panja");
10
11
  * const github = await client.triggers.setSecret(agentId, "github_issues"); // a provider trigger's signing secret
11
12
  * ```
12
13
  */
13
14
  export declare class Client {
14
15
  readonly config: Configuration;
15
- /** Set, rotate, check and delete an agent webhook's signing secret. */
16
+ /** List an agent's webhooks; create, view, rotate, set and delete each one's signing secret. */
16
17
  readonly webhooks: WebhookSecrets;
17
18
  /** An agent's inbound triggers: set, rotate, check and delete a trigger's signing secret (or rotate a bearer
18
19
  * trigger's token), and page through its events. */
@@ -5,7 +5,8 @@ import { WebhookSecrets } from "./compose/webhookSecrets.js";
5
5
  *
6
6
  * ```ts
7
7
  * const client = new Client(config);
8
- * const secret = await client.webhooks.setSecret(agentId, "https://hooks.acme.com/panja");
8
+ * const hooks = await client.webhooks.list(agentId); // each webhook and its secretStatus
9
+ * const secret = await client.webhooks.getSecret(agentId, "https://hooks.acme.com/panja");
9
10
  * const github = await client.triggers.setSecret(agentId, "github_issues"); // a provider trigger's signing secret
10
11
  * ```
11
12
  */
@@ -10,13 +10,19 @@ export interface Deployment {
10
10
  /** The live version, or while the agent is paused, the paused version (what `resumeAgent` brings back); undefined
11
11
  * from a server without versions, or when no version was ever live. */
12
12
  version?: number;
13
- /** URLs of the webhooks that still have no signing secret: this deploy stored a placeholder secret nobody holds so
14
- * the server accepts them. Call `client.webhooks.setSecret(agentId, url)` for each before pointing a provider at
15
- * the agent; until then deliveries fail verification. Left out when there are none. */
13
+ /** URLs of the agent's webhooks that have no signing secret after this deploy: one it added whose secret it could
14
+ * not create (it warned why), or one deployed before whose secret is missing (deleted, perhaps on purpose; deploy
15
+ * never recreates it). Nothing is delivered to them: `client.webhooks.createSecret(agentId, url)` gives one. Left
16
+ * out when there are none. */
16
17
  webhooksMissingSecret?: string[];
17
18
  /** The token (and fire URL) of each bearer trigger this deploy created. The server shows a token only once: keep
18
19
  * it now. Left out when nothing was minted; `client.triggers.list(agentId)` lists every trigger's URL. */
19
20
  triggerTokens?: MintedTriggerToken[];
21
+ /** The signing secret this deploy created for each webhook it added (every webhook on a first deploy), by URL. Give each to its receiver
22
+ * now (`client.webhooks.getSecret` shows it again). A webhook that already had a secret keeps it and is not listed.
23
+ * The property is non-enumerable, so logging or serialising the deployment leaves it out. Left out when deploy
24
+ * created none. */
25
+ readonly webhookSecrets?: Readonly<Record<string, string>>;
20
26
  }
21
27
  /** Set (or clear, with null) the client used when deploy/remove/run get no client. */
22
28
  export declare function setDefaultClient(config: Configuration | null): void;
@@ -30,6 +36,11 @@ export declare function resolveTransport(client?: Configuration, transport?: Tra
30
36
  * saves any edits the owner left in the draft, so check the draft first. `strict: true` throws `DriftError` instead of
31
37
  * overwriting fields edited outside the SDK. `adopt: agentId` takes over an agent made elsewhere. `version` is the live
32
38
  * version (the paused one while paused).
39
+ *
40
+ * The deploy then creates the signing secret of each webhook it added (a URL not in the agent.json last deployed;
41
+ * every webhook on a first deploy) and returns it once in `webhookSecrets` (by URL). An existing secret is never
42
+ * rotated or overwritten, and a missing one on a webhook deployed before is never recreated: it is listed in
43
+ * `webhooksMissingSecret`.
33
44
  */
34
45
  export declare function deploy(agent: Agent<OutputType | undefined>, opts?: {
35
46
  client?: Configuration;
@@ -41,7 +41,7 @@ function changedFields(remote, agent) {
41
41
  keys.push("instructions");
42
42
  return keys;
43
43
  }
44
- async function update(transport, remote, agent, strict) {
44
+ async function update(transport, remote, agent, strict, added) {
45
45
  const stored = storedHash(remote);
46
46
  if (stored !== undefined && settingsFingerprint(remote.instructions, remote.settings) !== stored) {
47
47
  const changed = changedFields(remote, agent);
@@ -50,8 +50,9 @@ async function update(transport, remote, agent, strict) {
50
50
  console.warn(`agent "${agent.name}" (${remote.agentId}) was edited outside the SDK; overwriting fields: ${changed.join(", ")}`);
51
51
  }
52
52
  else if (stored === agent.specHash()) {
53
- return settle(transport, remote, agent);
53
+ return settle(transport, remote, agent, added);
54
54
  }
55
+ added.urls = await addedUrls(transport, remote, agent);
55
56
  const updated = await transport.updateAgent(remote.agentId, agent);
56
57
  return deployment(remote.agentId, "updated", liveVersion(updated), missingSecrets(updated), updated === null || updated === void 0 ? void 0 : updated.triggerTokens);
57
58
  }
@@ -63,6 +64,40 @@ function deployment(agentId, action, version, webhooksMissingSecret = [], tokens
63
64
  out.triggerTokens = tokens;
64
65
  return out;
65
66
  }
67
+ /**
68
+ * The URLs of `agent`'s webhooks that this deploy adds: not in the agent.json last deployed (read before the write,
69
+ * with the transport's optional `deployedWebhookUrls`). Nothing deployed yet: every webhook. A read that fails
70
+ * (`null`), or a transport that cannot tell: none, so a secret is never created for a webhook deployed before.
71
+ */
72
+ async function addedUrls(transport, remote, agent) {
73
+ var _a;
74
+ const urls = ((_a = agent.webhooks) !== null && _a !== void 0 ? _a : []).map((h) => h.url);
75
+ if (urls.length === 0 || transport.deployedWebhookUrls === undefined)
76
+ return new Set();
77
+ const previous = await transport.deployedWebhookUrls(remote.agentId, remote.liveVersion, remote.versionState);
78
+ if (previous === null)
79
+ return new Set();
80
+ return new Set(urls.filter((u) => !previous.has(u)));
81
+ }
82
+ /**
83
+ * Create the signing secret of each webhook this deploy added (a URL not in the agent.json last deployed; on a first
84
+ * deploy, every webhook) when it has none. A webhook deployed before is never given a secret here, even when it has
85
+ * none (its owner may have deleted it on purpose): it is listed in `webhooksMissingSecret`, like a webhook whose create
86
+ * failed. Never rotates or overwrites a secret, and a failure never fails the deploy.
87
+ */
88
+ async function withWebhookSecrets(transport, agent, out, added) {
89
+ var _a;
90
+ if (!agent.webhooks || agent.webhooks.length === 0 || transport.createWebhookSecrets === undefined)
91
+ return out;
92
+ const { created, missing } = await transport.createWebhookSecrets(out.agentId, agent, added);
93
+ const allMissing = [...new Set([...((_a = out.webhooksMissingSecret) !== null && _a !== void 0 ? _a : []), ...missing])];
94
+ if (allMissing.length > 0)
95
+ out.webhooksMissingSecret = allMissing;
96
+ if (Object.keys(created).length > 0) {
97
+ Object.defineProperty(out, "webhookSecrets", { value: Object.freeze({ ...created }), enumerable: false });
98
+ }
99
+ return out;
100
+ }
66
101
  function missingSecrets(remote) {
67
102
  const missing = remote === null || remote === void 0 ? void 0 : remote.webhooksMissingSecret;
68
103
  return Array.isArray(missing) ? [...missing] : [];
@@ -92,16 +127,18 @@ function liveVersion(remote) {
92
127
  * goes live again with the next deploy of a changed definition. Only an agent with no live version that was never
93
128
  * paused (created, but its first deploy did not finish) is published here.
94
129
  */
95
- async function settle(transport, remote, agent) {
130
+ async function settle(transport, remote, agent, added) {
96
131
  const state = remote.versionState;
97
132
  if (state === undefined || state === "live" || state === "paused" || !transport.publish) {
98
133
  if (state === "live")
99
134
  await checkTriggers(transport, remote, agent);
100
135
  return deployment(remote.agentId, "unchanged", remote.liveVersion);
101
136
  }
137
+ added.urls = await addedUrls(transport, remote, agent);
102
138
  return published(remote.agentId, await transport.publish(remote.agentId, VERSION_NOTE));
103
139
  }
104
- async function deployWith(agent, transport, strict, adopt) {
140
+ async function deployWith(agent, transport, strict, added, adopt) {
141
+ var _a;
105
142
  const found = await transport.findAgents(agent.name);
106
143
  if (adopt !== undefined) {
107
144
  const target = await transport.readAgent(adopt);
@@ -114,16 +151,18 @@ async function deployWith(agent, transport, strict, adopt) {
114
151
  if (others.length) {
115
152
  throw new UserError(`cannot adopt ${adopt}: agent "${agent.name}" is already deployed as ${others.join(", ")}`);
116
153
  }
154
+ added.urls = await addedUrls(transport, target, agent);
117
155
  const adopted = await transport.updateAgent(adopt, agent);
118
156
  return deployment(adopt, "updated", liveVersion(adopted), missingSecrets(adopted), adopted === null || adopted === void 0 ? void 0 : adopted.triggerTokens);
119
157
  }
120
158
  if (found.length > 1)
121
159
  throw new DuplicateAgentsError(found.map((r) => r.agentId));
122
160
  if (found.length === 0) {
161
+ added.urls = new Set(((_a = agent.webhooks) !== null && _a !== void 0 ? _a : []).map((h) => h.url)); // a new agent: every webhook is new
123
162
  const created = await transport.createAgent(agent);
124
163
  return deployment(created.agentId, "created", liveVersion(created), missingSecrets(created), created.triggerTokens);
125
164
  }
126
- return update(transport, found[0], agent, strict);
165
+ return update(transport, found[0], agent, strict, added);
127
166
  }
128
167
  /**
129
168
  * The id of the deployed agent named `agent.name`, for a run with `deploy: false`: reads only, writes nothing. The run
@@ -152,11 +191,21 @@ async function findDeployed(agent, transport) {
152
191
  * saves any edits the owner left in the draft, so check the draft first. `strict: true` throws `DriftError` instead of
153
192
  * overwriting fields edited outside the SDK. `adopt: agentId` takes over an agent made elsewhere. `version` is the live
154
193
  * version (the paused one while paused).
194
+ *
195
+ * The deploy then creates the signing secret of each webhook it added (a URL not in the agent.json last deployed;
196
+ * every webhook on a first deploy) and returns it once in `webhookSecrets` (by URL). An existing secret is never
197
+ * rotated or overwritten, and a missing one on a webhook deployed before is never recreated: it is listed in
198
+ * `webhooksMissingSecret`.
155
199
  */
156
200
  export async function deploy(agent, opts = {}) {
157
201
  const transport = resolveTransport(opts.client, opts.transport);
158
202
  forget(agent.name); // this deploy may replace what cached runs of the name point at
159
- return serialized(agent.name, () => { var _a; return deployWith(agent, transport, (_a = opts.strict) !== null && _a !== void 0 ? _a : false, opts.adopt); });
203
+ return serialized(agent.name, async () => {
204
+ var _a;
205
+ const added = { urls: new Set() };
206
+ const out = await deployWith(agent, transport, (_a = opts.strict) !== null && _a !== void 0 ? _a : false, added, opts.adopt);
207
+ return withWebhookSecrets(transport, agent, out, added.urls);
208
+ });
160
209
  }
161
210
  /**
162
211
  * Delete the agent named `name` and all its versions; resolves true if one was deleted. It cannot be undone.
@@ -227,7 +276,11 @@ export function agentIdFor(agent, transport, owner, deploy = true) {
227
276
  if (prev && prev.hash === hash)
228
277
  return prev.id;
229
278
  const id = deploy
230
- ? serialized(agent.name, () => deployWith(agent, transport, false)).then((d) => d.agentId)
279
+ ? serialized(agent.name, async () => {
280
+ // As deploy(): the webhooks a run's deploy adds get their secrets (client.webhooks.getSecret shows them).
281
+ const added = { urls: new Set() };
282
+ return withWebhookSecrets(transport, agent, await deployWith(agent, transport, false, added), added.urls);
283
+ }).then((d) => d.agentId)
231
284
  : serialized(agent.name, () => findDeployed(agent, transport));
232
285
  const entry = { hash, id };
233
286
  owners.set(owner, entry);
@@ -16,6 +16,10 @@ export declare class UserError extends AgentsError {
16
16
  message?: string;
17
17
  }>);
18
18
  }
19
+ /** `client.webhooks.createSecret`: the webhook already has a signing secret. Rotate it (`rotateSecret`), view it
20
+ * (`getSecret`), or delete it first. */
21
+ export declare class SecretExistsError extends UserError {
22
+ }
19
23
  /** Where a `ModelBehaviorError` came from: the server's check, or the `outputType`'s own `parse`. */
20
24
  export type ModelBehaviorErrorSource = "server" | "local_parse";
21
25
  /**
@@ -13,6 +13,10 @@ export class UserError extends AgentsError {
13
13
  this.issues = issues;
14
14
  }
15
15
  }
16
+ /** `client.webhooks.createSecret`: the webhook already has a signing secret. Rotate it (`rotateSecret`), view it
17
+ * (`getSecret`), or delete it first. */
18
+ export class SecretExistsError extends UserError {
19
+ }
16
20
  /**
17
21
  * The agent's answer didn't match its `outputType`. `source` says where: `"server"` (no answer matched the schema
18
22
  * after the server's retry; `rawText` is the model's last attempt) or `"local_parse"` (the server accepted the answer
@@ -19,24 +19,29 @@ export declare class SettingsTransport implements Transport {
19
19
  private readonly agents;
20
20
  private readonly conversations;
21
21
  private readonly responses;
22
- private readonly customApis;
23
22
  private readonly triggers;
24
- private readonly secrets;
25
23
  constructor(config: Configuration);
26
24
  findAgents(sdkName: string): Promise<RemoteAgent[]>;
27
25
  readAgent(agentId: string): Promise<RemoteAgent>;
28
26
  createAgent(agent: Agent<OutputType | undefined>): Promise<RemoteAgent>;
29
- /** `settings` with each webhook that names no `secret_credential` given the one `client.webhooks` keeps for the
30
- * agent and host (stored, with a random secret nobody holds, when there is none yet), and the URLs of those
31
- * webhooks still without a secret set by `client.webhooks`. */
32
- private withSecretCredentials;
33
- /** The caller's Custom APIs the webhooks name, to bind to a new agent: one entry per name that matches exactly
34
- * one, and a sentence per name that matches none or several (left to the server, which refuses it only when it
35
- * checks credentials). */
36
- private webhookCredentials;
37
- /** The ids of the caller's own Custom APIs named exactly `name` (`q` also matches substrings and hosts). */
38
- private customApiIds;
39
- private bind;
27
+ /**
28
+ * The webhook URLs of the agent.json last deployed, read before a deploy writes: the live (or paused) version's,
29
+ * `GET /v2/agents/{agentId}/versions/{version}` (its `agent.json` file). Without versions on the server, the
30
+ * agent's settings (`GET /v1/agents/{agentId}/settings`), which are what is deployed there. An empty set when
31
+ * nothing was ever deployed; null, with a warning, when it cannot be read.
32
+ */
33
+ deployedWebhookUrls(agentId: string, liveVersion?: number, versionState?: string): Promise<Set<string> | null>;
34
+ /**
35
+ * Create the signing secret of each webhook in `added` (the URLs this deploy added) whose `secretStatus` is
36
+ * `missing` (`POST .../webhooks/{webhookKey}/secret`); resolves to the new secrets by URL and the URLs of `agent`'s
37
+ * webhooks still without one. A webhook deployed before whose secret is missing is reported, never given one. An
38
+ * existing secret is never rotated or overwritten. Nothing here fails the deploy: a failure is logged (never with a
39
+ * secret) and the webhook reported missing.
40
+ */
41
+ createWebhookSecrets(agentId: string, agent: Agent<OutputType | undefined>, added?: ReadonlySet<string>): Promise<{
42
+ created: Record<string, string>;
43
+ missing: string[];
44
+ }>;
40
45
  updateAgent(agentId: string, agent: Agent<OutputType | undefined>): Promise<RemoteAgent>;
41
46
  /** Make what was just written what end users get. A server without versions (no `versionState`) gets the bodiless
42
47
  * deploy 0.3 sent; otherwise the draft is saved as a version and that version deployed. */