sarvam-agents-client 0.3.2 → 0.4.1

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 (157) hide show
  1. package/README.md +36 -23
  2. package/dist/apis/AgentConversationsApi.d.ts +2 -2
  3. package/dist/apis/AgentConversationsApi.js +2 -2
  4. package/dist/apis/AgentsApi.d.ts +195 -5
  5. package/dist/apis/AgentsApi.js +478 -5
  6. package/dist/apis/ArtifactsApi.d.ts +8 -4
  7. package/dist/apis/ArtifactsApi.js +8 -4
  8. package/dist/apis/ConversationsApi.d.ts +2 -0
  9. package/dist/apis/ConversationsApi.js +6 -0
  10. package/dist/client.d.ts +16 -0
  11. package/dist/client.js +21 -0
  12. package/dist/compose/deploy.d.ts +37 -7
  13. package/dist/compose/deploy.js +105 -19
  14. package/dist/compose/errors.d.ts +1 -1
  15. package/dist/compose/errors.js +1 -1
  16. package/dist/compose/index.d.ts +1 -1
  17. package/dist/compose/index.js +2 -1
  18. package/dist/compose/run.d.ts +5 -1
  19. package/dist/compose/run.js +9 -9
  20. package/dist/compose/settingsTransport.d.ts +14 -0
  21. package/dist/compose/settingsTransport.js +151 -14
  22. package/dist/compose/transport.d.ts +14 -0
  23. package/dist/compose/transport.js +3 -0
  24. package/dist/compose/webhook.d.ts +18 -3
  25. package/dist/compose/webhook.js +59 -10
  26. package/dist/compose/webhookSecrets.d.ts +64 -0
  27. package/dist/compose/webhookSecrets.js +255 -0
  28. package/dist/esm/apis/AgentConversationsApi.d.ts +2 -2
  29. package/dist/esm/apis/AgentConversationsApi.js +2 -2
  30. package/dist/esm/apis/AgentsApi.d.ts +195 -5
  31. package/dist/esm/apis/AgentsApi.js +478 -5
  32. package/dist/esm/apis/ArtifactsApi.d.ts +8 -4
  33. package/dist/esm/apis/ArtifactsApi.js +8 -4
  34. package/dist/esm/apis/ConversationsApi.d.ts +2 -0
  35. package/dist/esm/apis/ConversationsApi.js +6 -0
  36. package/dist/esm/client.d.ts +16 -0
  37. package/dist/esm/client.js +17 -0
  38. package/dist/esm/compose/deploy.d.ts +37 -7
  39. package/dist/esm/compose/deploy.js +105 -20
  40. package/dist/esm/compose/errors.d.ts +1 -1
  41. package/dist/esm/compose/errors.js +1 -1
  42. package/dist/esm/compose/index.d.ts +1 -1
  43. package/dist/esm/compose/index.js +1 -1
  44. package/dist/esm/compose/run.d.ts +5 -1
  45. package/dist/esm/compose/run.js +9 -9
  46. package/dist/esm/compose/settingsTransport.d.ts +14 -0
  47. package/dist/esm/compose/settingsTransport.js +151 -14
  48. package/dist/esm/compose/transport.d.ts +14 -0
  49. package/dist/esm/compose/transport.js +2 -1
  50. package/dist/esm/compose/webhook.d.ts +18 -3
  51. package/dist/esm/compose/webhook.js +55 -9
  52. package/dist/esm/compose/webhookSecrets.d.ts +64 -0
  53. package/dist/esm/compose/webhookSecrets.js +250 -0
  54. package/dist/esm/index.d.ts +3 -0
  55. package/dist/esm/index.js +3 -0
  56. package/dist/esm/models/AgentAttachmentDiff.d.ts +50 -0
  57. package/dist/esm/models/AgentAttachmentDiff.js +55 -0
  58. package/dist/esm/models/AgentContentsResource.d.ts +71 -0
  59. package/dist/esm/models/AgentContentsResource.js +70 -0
  60. package/dist/esm/models/AgentDeploy.d.ts +33 -0
  61. package/dist/esm/models/AgentDeploy.js +41 -0
  62. package/dist/esm/models/AgentDraftResource.d.ts +51 -0
  63. package/dist/esm/models/AgentDraftResource.js +52 -0
  64. package/dist/esm/models/AgentFileContent.d.ts +38 -0
  65. package/dist/esm/models/AgentFileContent.js +47 -0
  66. package/dist/esm/models/AgentHistoryResource.d.ts +71 -0
  67. package/dist/esm/models/AgentHistoryResource.js +66 -0
  68. package/dist/esm/models/AgentResource.d.ts +21 -0
  69. package/dist/esm/models/AgentResource.js +12 -0
  70. package/dist/esm/models/AgentSkillFilePin.d.ts +44 -0
  71. package/dist/esm/models/AgentSkillFilePin.js +51 -0
  72. package/dist/esm/models/AgentSubagentEntry.d.ts +38 -0
  73. package/dist/esm/models/AgentSubagentEntry.js +47 -0
  74. package/dist/esm/models/AgentVersionCreate.d.ts +32 -0
  75. package/dist/esm/models/AgentVersionCreate.js +41 -0
  76. package/dist/esm/models/AgentVersionDiffResource.d.ts +87 -0
  77. package/dist/esm/models/AgentVersionDiffResource.js +78 -0
  78. package/dist/esm/models/AgentVersionPick.d.ts +32 -0
  79. package/dist/esm/models/AgentVersionPick.js +43 -0
  80. package/dist/esm/models/AgentVersionResource.d.ts +56 -0
  81. package/dist/esm/models/AgentVersionResource.js +57 -0
  82. package/dist/esm/models/AppResource.d.ts +12 -0
  83. package/dist/esm/models/AppResource.js +4 -0
  84. package/dist/esm/models/ResponseInput.d.ts +6 -0
  85. package/dist/esm/models/ResponseInput.js +2 -0
  86. package/dist/esm/models/SkillUpdateResource.d.ts +38 -0
  87. package/dist/esm/models/SkillUpdateResource.js +47 -0
  88. package/dist/esm/models/index.d.ts +13 -0
  89. package/dist/esm/models/index.js +13 -0
  90. package/dist/index.d.ts +3 -0
  91. package/dist/index.js +6 -0
  92. package/dist/models/AgentAttachmentDiff.d.ts +50 -0
  93. package/dist/models/AgentAttachmentDiff.js +62 -0
  94. package/dist/models/AgentContentsResource.d.ts +71 -0
  95. package/dist/models/AgentContentsResource.js +77 -0
  96. package/dist/models/AgentDeploy.d.ts +33 -0
  97. package/dist/models/AgentDeploy.js +48 -0
  98. package/dist/models/AgentDraftResource.d.ts +51 -0
  99. package/dist/models/AgentDraftResource.js +59 -0
  100. package/dist/models/AgentFileContent.d.ts +38 -0
  101. package/dist/models/AgentFileContent.js +54 -0
  102. package/dist/models/AgentHistoryResource.d.ts +71 -0
  103. package/dist/models/AgentHistoryResource.js +74 -0
  104. package/dist/models/AgentResource.d.ts +21 -0
  105. package/dist/models/AgentResource.js +13 -1
  106. package/dist/models/AgentSkillFilePin.d.ts +44 -0
  107. package/dist/models/AgentSkillFilePin.js +58 -0
  108. package/dist/models/AgentSubagentEntry.d.ts +38 -0
  109. package/dist/models/AgentSubagentEntry.js +54 -0
  110. package/dist/models/AgentVersionCreate.d.ts +32 -0
  111. package/dist/models/AgentVersionCreate.js +48 -0
  112. package/dist/models/AgentVersionDiffResource.d.ts +87 -0
  113. package/dist/models/AgentVersionDiffResource.js +85 -0
  114. package/dist/models/AgentVersionPick.d.ts +32 -0
  115. package/dist/models/AgentVersionPick.js +50 -0
  116. package/dist/models/AgentVersionResource.d.ts +56 -0
  117. package/dist/models/AgentVersionResource.js +64 -0
  118. package/dist/models/AppResource.d.ts +12 -0
  119. package/dist/models/AppResource.js +4 -0
  120. package/dist/models/ResponseInput.d.ts +6 -0
  121. package/dist/models/ResponseInput.js +2 -0
  122. package/dist/models/SkillUpdateResource.d.ts +38 -0
  123. package/dist/models/SkillUpdateResource.js +54 -0
  124. package/dist/models/index.d.ts +13 -0
  125. package/dist/models/index.js +13 -0
  126. package/package.json +1 -1
  127. package/src/apis/AgentConversationsApi.ts +2 -2
  128. package/src/apis/AgentsApi.ts +737 -6
  129. package/src/apis/ArtifactsApi.ts +8 -4
  130. package/src/apis/ConversationsApi.ts +10 -0
  131. package/src/client.ts +21 -0
  132. package/src/compose/deploy.ts +126 -20
  133. package/src/compose/errors.ts +1 -1
  134. package/src/compose/index.ts +1 -1
  135. package/src/compose/run.ts +6 -2
  136. package/src/compose/settingsTransport.ts +154 -16
  137. package/src/compose/transport.ts +15 -0
  138. package/src/compose/webhook.ts +64 -11
  139. package/src/compose/webhookSecrets.ts +257 -0
  140. package/src/index.ts +4 -0
  141. package/src/models/AgentAttachmentDiff.ts +93 -0
  142. package/src/models/AgentContentsResource.ts +142 -0
  143. package/src/models/AgentDeploy.ts +66 -0
  144. package/src/models/AgentDraftResource.ts +99 -0
  145. package/src/models/AgentFileContent.ts +75 -0
  146. package/src/models/AgentHistoryResource.ts +121 -0
  147. package/src/models/AgentResource.ts +26 -0
  148. package/src/models/AgentSkillFilePin.ts +84 -0
  149. package/src/models/AgentSubagentEntry.ts +75 -0
  150. package/src/models/AgentVersionCreate.ts +65 -0
  151. package/src/models/AgentVersionDiffResource.ts +154 -0
  152. package/src/models/AgentVersionPick.ts +66 -0
  153. package/src/models/AgentVersionResource.ts +101 -0
  154. package/src/models/AppResource.ts +16 -0
  155. package/src/models/ResponseInput.ts +8 -0
  156. package/src/models/SkillUpdateResource.ts +75 -0
  157. package/src/models/index.ts +13 -0
@@ -130,6 +130,7 @@ class ArtifactsApi extends runtime.BaseAPI {
130
130
  await this.deleteArtifactRaw(requestParameters, initOverrides);
131
131
  }
132
132
  /**
133
+ * A GET URL for one file: a presigned S3 URL while the file is plaintext. Clients that can follow file-gateway URLs use the v2 route.
133
134
  * Download Url Route
134
135
  */
135
136
  async downloadUrlRaw(requestParameters, initOverrides) {
@@ -163,6 +164,7 @@ class ArtifactsApi extends runtime.BaseAPI {
163
164
  return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_js_1.DownloadUrlResponseFromJSON)(jsonValue));
164
165
  }
165
166
  /**
167
+ * A GET URL for one file: a presigned S3 URL while the file is plaintext. Clients that can follow file-gateway URLs use the v2 route.
166
168
  * Download Url Route
167
169
  */
168
170
  async downloadUrl(requestParameters, initOverrides) {
@@ -170,7 +172,7 @@ class ArtifactsApi extends runtime.BaseAPI {
170
172
  return await response.value();
171
173
  }
172
174
  /**
173
- * Render an HTML deck to PPTX or PDF and return a download link (sync).
175
+ * Render an HTML deck to PPTX or PDF and return a download link (sync). The link is a presigned S3 URL while the exported file is plaintext; clients that can follow file-gateway URLs use the v2 route.
174
176
  * Export Artifact Route
175
177
  */
176
178
  async exportArtifactRaw(requestParameters, initOverrides) {
@@ -203,7 +205,7 @@ class ArtifactsApi extends runtime.BaseAPI {
203
205
  return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_js_1.ExportResponseFromJSON)(jsonValue));
204
206
  }
205
207
  /**
206
- * Render an HTML deck to PPTX or PDF and return a download link (sync).
208
+ * Render an HTML deck to PPTX or PDF and return a download link (sync). The link is a presigned S3 URL while the exported file is plaintext; clients that can follow file-gateway URLs use the v2 route.
207
209
  * Export Artifact Route
208
210
  */
209
211
  async exportArtifact(requestParameters, initOverrides) {
@@ -244,6 +246,7 @@ class ArtifactsApi extends runtime.BaseAPI {
244
246
  return await response.value();
245
247
  }
246
248
  /**
249
+ * Mint the PUT URL for an upload: a presigned S3 URL while the file is stored plaintext. Clients that can follow file-gateway URLs use ``POST /v2/artifacts/upload-url``.
247
250
  * Mint Upload Url Route
248
251
  */
249
252
  async mintUploadUrlRaw(requestParameters, initOverrides) {
@@ -270,6 +273,7 @@ class ArtifactsApi extends runtime.BaseAPI {
270
273
  return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_js_1.UploadUrlResponseFromJSON)(jsonValue));
271
274
  }
272
275
  /**
276
+ * Mint the PUT URL for an upload: a presigned S3 URL while the file is stored plaintext. Clients that can follow file-gateway URLs use ``POST /v2/artifacts/upload-url``.
273
277
  * Mint Upload Url Route
274
278
  */
275
279
  async mintUploadUrl(requestParameters, initOverrides) {
@@ -277,7 +281,7 @@ class ArtifactsApi extends runtime.BaseAPI {
277
281
  return await response.value();
278
282
  }
279
283
  /**
280
- * Presign the PUT for a user\'s edit of ``artifact_id``, saved as its next version. ``artifact_id`` is the version the client edited. 409 ``CHAT_CONFLICT`` (``details[0].latest_artifact_id`` / ``latest_version``) when a newer one has landed; 422 when the artifact has no version chain (uploads, exports).
284
+ * Presign the PUT for a user\'s edit of ``artifact_id``, saved as its next version. ``artifact_id`` is the version the client edited. 409 ``CHAT_CONFLICT`` (``details[0].latest_artifact_id`` / ``latest_version``) when a newer one has landed; 422 when the artifact has no version chain (uploads, exports). The URL is a presigned S3 URL while the edit is stored plaintext; clients that can follow file-gateway URLs use the v2 route.
281
285
  * Mint Version Upload Url Route
282
286
  */
283
287
  async mintVersionUploadUrlRaw(requestParameters, initOverrides) {
@@ -310,7 +314,7 @@ class ArtifactsApi extends runtime.BaseAPI {
310
314
  return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_js_1.UploadUrlResponseFromJSON)(jsonValue));
311
315
  }
312
316
  /**
313
- * Presign the PUT for a user\'s edit of ``artifact_id``, saved as its next version. ``artifact_id`` is the version the client edited. 409 ``CHAT_CONFLICT`` (``details[0].latest_artifact_id`` / ``latest_version``) when a newer one has landed; 422 when the artifact has no version chain (uploads, exports).
317
+ * Presign the PUT for a user\'s edit of ``artifact_id``, saved as its next version. ``artifact_id`` is the version the client edited. 409 ``CHAT_CONFLICT`` (``details[0].latest_artifact_id`` / ``latest_version``) when a newer one has landed; 422 when the artifact has no version chain (uploads, exports). The URL is a presigned S3 URL while the edit is stored plaintext; clients that can follow file-gateway URLs use the v2 route.
314
318
  * Mint Version Upload Url Route
315
319
  */
316
320
  async mintVersionUploadUrl(requestParameters, initOverrides) {
@@ -21,6 +21,8 @@ export interface DeleteConversationRequest {
21
21
  }
22
22
  export interface GetConversationRequest {
23
23
  conversationId: string;
24
+ xClientPlatform?: string | null;
25
+ xClientVersion?: string | null;
24
26
  }
25
27
  export interface GetResponseRequest {
26
28
  conversationId: string;
@@ -100,6 +100,12 @@ class ConversationsApi extends runtime.BaseAPI {
100
100
  }
101
101
  const queryParameters = {};
102
102
  const headerParameters = {};
103
+ if (requestParameters['xClientPlatform'] != null) {
104
+ headerParameters['X-Client-Platform'] = String(requestParameters['xClientPlatform']);
105
+ }
106
+ if (requestParameters['xClientVersion'] != null) {
107
+ headerParameters['X-Client-Version'] = String(requestParameters['xClientVersion']);
108
+ }
103
109
  if (this.configuration && this.configuration.accessToken) {
104
110
  const token = this.configuration.accessToken;
105
111
  const tokenString = await token("bearerAuth", []);
@@ -0,0 +1,16 @@
1
+ import type { Configuration } from "./runtime.js";
2
+ import { WebhookSecrets } from "./compose/webhookSecrets.js";
3
+ /**
4
+ * Groups the hand-written helpers over one `Configuration`.
5
+ *
6
+ * ```ts
7
+ * const client = new Client(config);
8
+ * const secret = await client.webhooks.setSecret(agentId, "https://hooks.acme.com/panja");
9
+ * ```
10
+ */
11
+ export declare class Client {
12
+ readonly config: Configuration;
13
+ /** Set, rotate, check and delete an agent webhook's signing secret. */
14
+ readonly webhooks: WebhookSecrets;
15
+ constructor(config: Configuration);
16
+ }
package/dist/client.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Client = void 0;
4
+ const webhookSecrets_js_1 = require("./compose/webhookSecrets.js");
5
+ /**
6
+ * Groups the hand-written helpers over one `Configuration`.
7
+ *
8
+ * ```ts
9
+ * const client = new Client(config);
10
+ * const secret = await client.webhooks.setSecret(agentId, "https://hooks.acme.com/panja");
11
+ * ```
12
+ */
13
+ class Client {
14
+ constructor(config) {
15
+ this.config = config;
16
+ if (config === undefined || config === null)
17
+ throw new TypeError("new Client(config): pass a Configuration");
18
+ this.webhooks = new webhookSecrets_js_1.WebhookSecrets(config);
19
+ }
20
+ }
21
+ exports.Client = Client;
@@ -1,4 +1,4 @@
1
- /** deploy()/undeploy(): upsert a hosted agent by name, with fingerprint-based drift detection, and the deploy cache. */
1
+ /** deploy()/remove(): upsert a hosted agent by name, with fingerprint-based drift detection, and the deploy cache. */
2
2
  import type { Configuration } from "../runtime.js";
3
3
  import type { Agent } from "./agent.js";
4
4
  import type { OutputType } from "./output.js";
@@ -6,26 +6,56 @@ import type { Transport } from "./transport.js";
6
6
  export interface Deployment {
7
7
  agentId: string;
8
8
  action: "created" | "updated" | "unchanged";
9
+ /** The live version, or while the agent is paused, the paused version (what `resumeAgent` brings back); undefined
10
+ * from a server without versions, or when no version was ever live. */
11
+ version?: number;
12
+ /** URLs of the webhooks that still have no signing secret: this deploy stored a placeholder secret nobody holds so
13
+ * the server accepts them. Call `client.webhooks.setSecret(agentId, url)` for each before pointing a provider at
14
+ * the agent; until then deliveries fail verification. Left out when there are none. */
15
+ webhooksMissingSecret?: string[];
9
16
  }
10
- /** Set (or clear, with null) the client used when deploy/undeploy/run get no client. */
17
+ /** Set (or clear, with null) the client used when deploy/remove/run get no client. */
11
18
  export declare function setDefaultClient(config: Configuration | null): void;
12
19
  export declare function getDefaultClient(): Configuration | null;
13
20
  export declare function resolveTransport(client?: Configuration, transport?: Transport): Transport;
21
+ /**
22
+ * Create or update the hosted agent named `agent.name` so end users get this definition.
23
+ *
24
+ * A new or changed definition is saved as the next version and made live (`created` / `updated`). An unchanged one
25
+ * writes nothing (`unchanged`): dashboard edits, a rollback and a pause stay as they are. A changed definition also
26
+ * saves any edits the owner left in the draft, so check the draft first. `strict: true` throws `DriftError` instead of
27
+ * overwriting fields edited outside the SDK. `adopt: agentId` takes over an agent made elsewhere. `version` is the live
28
+ * version (the paused one while paused).
29
+ */
14
30
  export declare function deploy(agent: Agent<OutputType | undefined>, opts?: {
15
31
  client?: Configuration;
16
32
  transport?: Transport;
17
33
  strict?: boolean;
18
34
  adopt?: string;
19
35
  }): Promise<Deployment>;
36
+ /**
37
+ * Delete the agent named `name` and all its versions; resolves true if one was deleted. It cannot be undone.
38
+ *
39
+ * To take an agent offline and bring it back later, pause it instead: `new AgentsApi(config).undeployAgent({ agentId })`,
40
+ * then `resumeAgent({ agentId })`.
41
+ */
42
+ export declare function remove(name: string, opts?: {
43
+ client?: Configuration;
44
+ transport?: Transport;
45
+ }): Promise<boolean>;
46
+ /**
47
+ * @deprecated Renamed {@link remove}: it deletes the agent. The API's `undeploy` route (`AgentsApi.undeployAgent`)
48
+ * pauses an agent instead, so the old name read as a pause.
49
+ */
20
50
  export declare function undeploy(name: string, opts?: {
21
51
  client?: Configuration;
22
52
  transport?: Transport;
23
53
  }): Promise<boolean>;
24
- /** Drop cached deployments of agent `name` (any owner); called by deploy() and undeploy(). */
54
+ /** Drop cached deployments and lookups of agent `name` (any owner); called by deploy() and remove(). */
25
55
  export declare function forget(name: string): void;
26
56
  /**
27
- * The server id for `agent`, deploying it first unless this owner already deployed this exact definition.
28
- * Keyed by name, as the server is: a variant with the same name redeploys, chained after any in-flight deploy so
29
- * deploys of one name never overlap.
57
+ * The server id for `agent`, deploying it first unless this owner already deployed this exact definition; with
58
+ * `deploy` false, the deployed agent's id, looked up without writing. Keyed by name, as the server is: a variant with
59
+ * the same name redeploys, chained after any in-flight deploy so deploys of one name never overlap.
30
60
  */
31
- export declare function agentIdFor(agent: Agent<OutputType | undefined>, transport: Transport, owner: object): Promise<string>;
61
+ export declare function agentIdFor(agent: Agent<OutputType | undefined>, transport: Transport, owner: object, deploy?: boolean): Promise<string>;
@@ -4,14 +4,16 @@ exports.setDefaultClient = setDefaultClient;
4
4
  exports.getDefaultClient = getDefaultClient;
5
5
  exports.resolveTransport = resolveTransport;
6
6
  exports.deploy = deploy;
7
+ exports.remove = remove;
7
8
  exports.undeploy = undeploy;
8
9
  exports.forget = forget;
9
10
  exports.agentIdFor = agentIdFor;
10
11
  const errors_js_1 = require("./errors.js");
11
12
  const fingerprint_js_1 = require("./fingerprint.js");
12
13
  const settingsTransport_js_1 = require("./settingsTransport.js");
14
+ const transport_js_1 = require("./transport.js");
13
15
  let defaultClient = null;
14
- /** Set (or clear, with null) the client used when deploy/undeploy/run get no client. */
16
+ /** Set (or clear, with null) the client used when deploy/remove/run get no client. */
15
17
  function setDefaultClient(config) {
16
18
  defaultClient = config;
17
19
  }
@@ -58,10 +60,38 @@ async function update(transport, remote, agent, strict) {
58
60
  console.warn(`agent "${agent.name}" (${remote.agentId}) was edited outside the SDK; overwriting fields: ${changed.join(", ")}`);
59
61
  }
60
62
  else if (stored === agent.specHash()) {
61
- return { agentId: remote.agentId, action: "unchanged" };
63
+ return settle(transport, remote, agent);
62
64
  }
63
- await transport.updateAgent(remote.agentId, agent);
64
- return { agentId: remote.agentId, action: "updated" };
65
+ const updated = await transport.updateAgent(remote.agentId, agent);
66
+ return deployment(remote.agentId, "updated", liveVersion(updated), missingSecrets(updated));
67
+ }
68
+ function deployment(agentId, action, version, webhooksMissingSecret = []) {
69
+ const out = version === undefined ? { agentId, action } : { agentId, action, version };
70
+ if (webhooksMissingSecret.length > 0)
71
+ out.webhooksMissingSecret = webhooksMissingSecret;
72
+ return out;
73
+ }
74
+ function missingSecrets(remote) {
75
+ const missing = remote === null || remote === void 0 ? void 0 : remote.webhooksMissingSecret;
76
+ return Array.isArray(missing) ? [...missing] : [];
77
+ }
78
+ // Optional chaining: a custom transport written for 0.3 may resolve anything from updateAgent/createAgent.
79
+ function liveVersion(remote) {
80
+ var _a;
81
+ return (_a = remote === null || remote === void 0 ? void 0 : remote.liveVersion) !== null && _a !== void 0 ? _a : undefined;
82
+ }
83
+ /**
84
+ * The stored definition already is this one, so nothing is written to a live or paused agent. What the owner does in
85
+ * the dashboard stays: unsaved draft edits, a version saved to try out, a rollback and a pause. The code's definition
86
+ * goes live again with the next deploy of a changed definition. Only an agent with no live version that was never
87
+ * paused (created, but its first deploy did not finish) is published here.
88
+ */
89
+ async function settle(transport, remote, agent) {
90
+ const state = remote.versionState;
91
+ if (state === undefined || state === "live" || state === "paused" || !transport.publish) {
92
+ return deployment(remote.agentId, "unchanged", remote.liveVersion);
93
+ }
94
+ return deployment(remote.agentId, "updated", await transport.publish(remote.agentId, transport_js_1.VERSION_NOTE));
65
95
  }
66
96
  async function deployWith(agent, transport, strict, adopt) {
67
97
  const found = await transport.findAgents(agent.name);
@@ -76,21 +106,57 @@ async function deployWith(agent, transport, strict, adopt) {
76
106
  if (others.length) {
77
107
  throw new errors_js_1.UserError(`cannot adopt ${adopt}: agent "${agent.name}" is already deployed as ${others.join(", ")}`);
78
108
  }
79
- await transport.updateAgent(adopt, agent);
80
- return { agentId: adopt, action: "updated" };
109
+ const adopted = await transport.updateAgent(adopt, agent);
110
+ return deployment(adopt, "updated", liveVersion(adopted), missingSecrets(adopted));
81
111
  }
82
112
  if (found.length > 1)
83
113
  throw new errors_js_1.DuplicateAgentsError(found.map((r) => r.agentId));
84
- if (found.length === 0)
85
- return { agentId: (await transport.createAgent(agent)).agentId, action: "created" };
114
+ if (found.length === 0) {
115
+ const created = await transport.createAgent(agent);
116
+ return deployment(created.agentId, "created", liveVersion(created), missingSecrets(created));
117
+ }
86
118
  return update(transport, found[0], agent, strict);
87
119
  }
120
+ /**
121
+ * The id of the deployed agent named `agent.name`, for a run with `deploy: false`: reads only, writes nothing. The run
122
+ * gets the live version, whatever definition it holds; a definition that differs from the one last deployed from the
123
+ * SDK is warned about, since only `deploy(agent)` publishes it.
124
+ */
125
+ async function findDeployed(agent, transport) {
126
+ const found = await transport.findAgents(agent.name);
127
+ if (found.length > 1)
128
+ throw new errors_js_1.DuplicateAgentsError(found.map((r) => r.agentId));
129
+ if (found.length === 0) {
130
+ throw new errors_js_1.NotDeployedError(`agent "${agent.name}" is not deployed. Deploy it first with deploy(agent), or run it with deploy: true`);
131
+ }
132
+ const remote = found[0];
133
+ if (storedHash(remote) !== agent.specHash()) {
134
+ console.warn(`agent "${agent.name}" (${remote.agentId}) was deployed from a different definition; this run uses ` +
135
+ "the live version. Call deploy(agent) to publish your definition");
136
+ }
137
+ return remote.agentId;
138
+ }
139
+ /**
140
+ * Create or update the hosted agent named `agent.name` so end users get this definition.
141
+ *
142
+ * A new or changed definition is saved as the next version and made live (`created` / `updated`). An unchanged one
143
+ * writes nothing (`unchanged`): dashboard edits, a rollback and a pause stay as they are. A changed definition also
144
+ * saves any edits the owner left in the draft, so check the draft first. `strict: true` throws `DriftError` instead of
145
+ * overwriting fields edited outside the SDK. `adopt: agentId` takes over an agent made elsewhere. `version` is the live
146
+ * version (the paused one while paused).
147
+ */
88
148
  async function deploy(agent, opts = {}) {
89
149
  const transport = resolveTransport(opts.client, opts.transport);
90
150
  forget(agent.name); // this deploy may replace what cached runs of the name point at
91
151
  return serialized(agent.name, () => { var _a; return deployWith(agent, transport, (_a = opts.strict) !== null && _a !== void 0 ? _a : false, opts.adopt); });
92
152
  }
93
- async function undeploy(name, opts = {}) {
153
+ /**
154
+ * Delete the agent named `name` and all its versions; resolves true if one was deleted. It cannot be undone.
155
+ *
156
+ * To take an agent offline and bring it back later, pause it instead: `new AgentsApi(config).undeployAgent({ agentId })`,
157
+ * then `resumeAgent({ agentId })`.
158
+ */
159
+ async function remove(name, opts = {}) {
94
160
  const transport = resolveTransport(opts.client, opts.transport);
95
161
  forget(name);
96
162
  return serialized(name, async () => {
@@ -100,7 +166,19 @@ async function undeploy(name, opts = {}) {
100
166
  return found.length > 0;
101
167
  });
102
168
  }
103
- // Per-name tail: every deploy/undeploy of a name (cached or direct) queues behind the previous one, so they never
169
+ let undeployWarned = false;
170
+ /**
171
+ * @deprecated Renamed {@link remove}: it deletes the agent. The API's `undeploy` route (`AgentsApi.undeployAgent`)
172
+ * pauses an agent instead, so the old name read as a pause.
173
+ */
174
+ async function undeploy(name, opts = {}) {
175
+ if (!undeployWarned) {
176
+ undeployWarned = true;
177
+ console.warn("undeploy() deletes the agent and is renamed remove(); to pause an agent instead, use AgentsApi.undeployAgent");
178
+ }
179
+ return remove(name, opts);
180
+ }
181
+ // Per-name tail: every deploy/remove of a name (cached or direct) queues behind the previous one, so they never
104
182
  // overlap. forget() does not touch it.
105
183
  const tails = new Map();
106
184
  function serialized(name, fn) {
@@ -115,26 +193,34 @@ function serialized(name, fn) {
115
193
  return p;
116
194
  }
117
195
  const cache = new Map();
118
- /** Drop cached deployments of agent `name` (any owner); called by deploy() and undeploy(). */
196
+ /** Drop cached deployments and lookups of agent `name` (any owner); called by deploy() and remove(). */
119
197
  function forget(name) {
120
- cache.delete(name);
198
+ cache.delete(cacheKey(name, true));
199
+ cache.delete(cacheKey(name, false));
200
+ }
201
+ // With deploy: false the agent is only looked up, cached apart so a lookup never stands in for a deploy.
202
+ function cacheKey(name, deploy) {
203
+ return `${deploy ? "deploy" : "lookup"}:${name}`;
121
204
  }
122
205
  /**
123
- * The server id for `agent`, deploying it first unless this owner already deployed this exact definition.
124
- * Keyed by name, as the server is: a variant with the same name redeploys, chained after any in-flight deploy so
125
- * deploys of one name never overlap.
206
+ * The server id for `agent`, deploying it first unless this owner already deployed this exact definition; with
207
+ * `deploy` false, the deployed agent's id, looked up without writing. Keyed by name, as the server is: a variant with
208
+ * the same name redeploys, chained after any in-flight deploy so deploys of one name never overlap.
126
209
  */
127
- function agentIdFor(agent, transport, owner) {
210
+ function agentIdFor(agent, transport, owner, deploy = true) {
128
211
  const hash = agent.specHash();
129
- let owners = cache.get(agent.name);
212
+ const key = cacheKey(agent.name, deploy);
213
+ let owners = cache.get(key);
130
214
  if (!owners) {
131
215
  owners = new WeakMap();
132
- cache.set(agent.name, owners);
216
+ cache.set(key, owners);
133
217
  }
134
218
  const prev = owners.get(owner);
135
219
  if (prev && prev.hash === hash)
136
220
  return prev.id;
137
- const id = serialized(agent.name, () => deployWith(agent, transport, false)).then((d) => d.agentId);
221
+ const id = deploy
222
+ ? serialized(agent.name, () => deployWith(agent, transport, false)).then((d) => d.agentId)
223
+ : serialized(agent.name, () => findDeployed(agent, transport));
138
224
  const entry = { hash, id };
139
225
  owners.set(owner, entry);
140
226
  const slot = owners;
@@ -41,7 +41,7 @@ export declare class MaxTokensExceededError extends AgentsError {
41
41
  }
42
42
  export declare class MaxToolCallsExceededError extends AgentsError {
43
43
  }
44
- /** The agent has not been deployed. */
44
+ /** No agent is deployed under this name (thrown by a run with `deploy: false`). */
45
45
  export declare class NotDeployedError extends AgentsError {
46
46
  }
47
47
  /** A feature the SDK does not support yet. */
@@ -47,7 +47,7 @@ exports.MaxTokensExceededError = MaxTokensExceededError;
47
47
  class MaxToolCallsExceededError extends AgentsError {
48
48
  }
49
49
  exports.MaxToolCallsExceededError = MaxToolCallsExceededError;
50
- /** The agent has not been deployed. */
50
+ /** No agent is deployed under this name (thrown by a run with `deploy: false`). */
51
51
  class NotDeployedError extends AgentsError {
52
52
  }
53
53
  exports.NotDeployedError = NotDeployedError;
@@ -9,7 +9,7 @@ export type { Event, ClarifyQuestion, FunctionCallRequest, OutputCitation } from
9
9
  export { SettingsTransport } from "./settingsTransport.js";
10
10
  export type { PendingFunctionCalls, RemoteAgent, SettingsWarning, TurnStream, Transport } from "./transport.js";
11
11
  export type { FunctionResult } from "./functionTool.js";
12
- export { deploy, undeploy, setDefaultClient } from "./deploy.js";
12
+ export { deploy, remove, undeploy, setDefaultClient } from "./deploy.js";
13
13
  export type { Deployment } from "./deploy.js";
14
14
  export { run, RunResult, StreamedRunResult } from "./run.js";
15
15
  export type { RunOptions, RunStreamEvent, ClarifyHandler, StopReason } from "./run.js";
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.RunState = exports.StreamedRunResult = exports.RunResult = exports.run = exports.setDefaultClient = exports.undeploy = exports.deploy = exports.SettingsTransport = exports.tool = void 0;
17
+ exports.RunState = exports.StreamedRunResult = exports.RunResult = exports.run = exports.setDefaultClient = exports.undeploy = exports.remove = exports.deploy = exports.SettingsTransport = exports.tool = void 0;
18
18
  __exportStar(require("./errors.js"), exports);
19
19
  __exportStar(require("./fingerprint.js"), exports);
20
20
  __exportStar(require("./tools.js"), exports);
@@ -25,6 +25,7 @@ var settingsTransport_js_1 = require("./settingsTransport.js");
25
25
  Object.defineProperty(exports, "SettingsTransport", { enumerable: true, get: function () { return settingsTransport_js_1.SettingsTransport; } });
26
26
  var deploy_js_1 = require("./deploy.js");
27
27
  Object.defineProperty(exports, "deploy", { enumerable: true, get: function () { return deploy_js_1.deploy; } });
28
+ Object.defineProperty(exports, "remove", { enumerable: true, get: function () { return deploy_js_1.remove; } });
28
29
  Object.defineProperty(exports, "undeploy", { enumerable: true, get: function () { return deploy_js_1.undeploy; } });
29
30
  Object.defineProperty(exports, "setDefaultClient", { enumerable: true, get: function () { return deploy_js_1.setDefaultClient; } });
30
31
  var run_js_1 = require("./run.js");
@@ -20,6 +20,10 @@ export interface RunOptions {
20
20
  /** Throw an error thrown by a function tool's `execute` instead of sending it to the model (for tests). The turn
21
21
  * then stays paused on the server; `RunState.fromSession` continues it. */
22
22
  raiseErrors?: boolean;
23
+ /** `true` (the default) deploys the agent first unless this process already deployed this definition. `false`
24
+ * never writes: it runs the live version of the deployed agent named `agent.name`, and throws `NotDeployedError`
25
+ * when there is none. Use it on servers, and deploy from CI or a release step. */
26
+ deploy?: boolean;
23
27
  /** Not supported: the server caps turns per agent; set `new Agent({ limits: { maxTurns } })`. */
24
28
  maxTurns?: never;
25
29
  }
@@ -125,7 +129,7 @@ export declare class StreamedRunResult<T = string> implements AsyncIterable<RunS
125
129
  }
126
130
  /**
127
131
  * Run `agent` on `input` (a message, or a RunState holding answers), deploying it first if this owner has not
128
- * deployed this exact definition. With `stream: true`, resolves at once with a StreamedRunResult.
132
+ * deployed this exact definition (unless `deploy: false`). With `stream: true`, resolves at once with a StreamedRunResult.
129
133
  */
130
134
  export declare function run<O extends OutputType | undefined = undefined>(agent: Agent<O>, input: string | RunState, opts: RunOptions & {
131
135
  stream: true;
@@ -485,7 +485,7 @@ function structuredOutput(outputType, event) {
485
485
  return undefined;
486
486
  }
487
487
  async function execute(p, controller, emit) {
488
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
488
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
489
489
  const signal = controller.signal;
490
490
  const unlink = link(p.opts.signal, controller);
491
491
  const stopper = new Stopper(p.transport, signal);
@@ -503,8 +503,8 @@ async function execute(p, controller, emit) {
503
503
  interruptions = await loop.answerPending(p.input);
504
504
  }
505
505
  else {
506
- const agentId = await raceAbort((0, deploy_js_1.agentIdFor)(p.agent, p.transport, p.owner), signal);
507
- const stream = await loop.start(agentId, (_b = p.opts.conversationId) !== null && _b !== void 0 ? _b : null, p.input);
506
+ const agentId = await raceAbort((0, deploy_js_1.agentIdFor)(p.agent, p.transport, p.owner, (_b = p.opts.deploy) !== null && _b !== void 0 ? _b : true), signal);
507
+ const stream = await loop.start(agentId, (_c = p.opts.conversationId) !== null && _c !== void 0 ? _c : null, p.input);
508
508
  const interruption = await loop.drive(stream);
509
509
  interruptions = interruption ? [interruption] : [];
510
510
  }
@@ -532,7 +532,7 @@ async function execute(p, controller, emit) {
532
532
  }
533
533
  catch (err) {
534
534
  if (err instanceof errors_js_1.ModelBehaviorError)
535
- err.conversationId = (_c = loop.conversationId) !== null && _c !== void 0 ? _c : fallbackConversation;
535
+ err.conversationId = (_d = loop.conversationId) !== null && _d !== void 0 ? _d : fallbackConversation;
536
536
  throw err;
537
537
  }
538
538
  }
@@ -544,12 +544,12 @@ async function execute(p, controller, emit) {
544
544
  newItems: loop.items,
545
545
  interruptions,
546
546
  stopReason: loop.stopReason,
547
- conversationId: (_d = loop.conversationId) !== null && _d !== void 0 ? _d : fallbackConversation,
547
+ conversationId: (_e = loop.conversationId) !== null && _e !== void 0 ? _e : fallbackConversation,
548
548
  cancelled,
549
- outputCitations: ((_e = loop.output) === null || _e === void 0 ? void 0 : _e.kind) === "output" ? ((_f = loop.output.citations) !== null && _f !== void 0 ? _f : []).slice() : [],
550
- outputNote: (_g = loop.output) === null || _g === void 0 ? void 0 : _g.note,
551
- outputSkipped: ((_h = loop.output) === null || _h === void 0 ? void 0 : _h.kind) === "output" ? loop.output.skipped : undefined,
552
- outputMode: ((_j = loop.output) === null || _j === void 0 ? void 0 : _j.kind) === "output" ? loop.output.mode : undefined,
549
+ outputCitations: ((_f = loop.output) === null || _f === void 0 ? void 0 : _f.kind) === "output" ? ((_g = loop.output.citations) !== null && _g !== void 0 ? _g : []).slice() : [],
550
+ outputNote: (_h = loop.output) === null || _h === void 0 ? void 0 : _h.note,
551
+ outputSkipped: ((_j = loop.output) === null || _j === void 0 ? void 0 : _j.kind) === "output" ? loop.output.skipped : undefined,
552
+ outputMode: ((_k = loop.output) === null || _k === void 0 ? void 0 : _k.kind) === "output" ? loop.output.mode : undefined,
553
553
  };
554
554
  }
555
555
  // -- streaming ---------------------------------------------------------------------------------------------------
@@ -18,10 +18,15 @@ export declare class SettingsTransport implements Transport {
18
18
  private readonly conversations;
19
19
  private readonly responses;
20
20
  private readonly customApis;
21
+ private readonly secrets;
21
22
  constructor(config: Configuration);
22
23
  findAgents(sdkName: string): Promise<RemoteAgent[]>;
23
24
  readAgent(agentId: string): Promise<RemoteAgent>;
24
25
  createAgent(agent: Agent<OutputType | undefined>): Promise<RemoteAgent>;
26
+ /** `settings` with each webhook that names no `secret_credential` given the one `client.webhooks` keeps for the
27
+ * agent and host (stored, with a random secret nobody holds, when there is none yet), and the URLs of those
28
+ * webhooks still without a secret set by `client.webhooks`. */
29
+ private withSecretCredentials;
25
30
  /** The caller's Custom APIs the webhooks name, to bind to a new agent: one entry per name that matches exactly
26
31
  * one, and a sentence per name that matches none or several (left to the server, which refuses it only when it
27
32
  * checks credentials). */
@@ -30,6 +35,15 @@ export declare class SettingsTransport implements Transport {
30
35
  private customApiIds;
31
36
  private bind;
32
37
  updateAgent(agentId: string, agent: Agent<OutputType | undefined>): Promise<RemoteAgent>;
38
+ /** Make what was just written what end users get. A server without versions (no `versionState`) gets the bodiless
39
+ * deploy 0.3 sent; otherwise the draft is saved as a version and that version deployed. */
40
+ private goLive;
41
+ /**
42
+ * Save the draft as the next version and make it live. 409 NO_CHANGES means the newest saved version already is the
43
+ * draft, so that version is deployed, by its number (never "the newest", which a save landing in between could
44
+ * change).
45
+ */
46
+ publish(agentId: string, note: string): Promise<number | undefined>;
33
47
  deleteAgent(agentId: string): Promise<void>;
34
48
  startTurn(agentId: string, conversationId: string | null, text: string, signal?: AbortSignal): Promise<TurnStream>;
35
49
  answerClarify(conversationId: string, requestId: string, answers: Record<string, unknown>, signal?: AbortSignal): Promise<TurnStream>;