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
@@ -127,6 +127,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
127
127
  await this.deleteArtifactRaw(requestParameters, initOverrides);
128
128
  }
129
129
  /**
130
+ * 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.
130
131
  * Download Url Route
131
132
  */
132
133
  async downloadUrlRaw(requestParameters, initOverrides) {
@@ -160,6 +161,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
160
161
  return new runtime.JSONApiResponse(response, (jsonValue) => DownloadUrlResponseFromJSON(jsonValue));
161
162
  }
162
163
  /**
164
+ * 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.
163
165
  * Download Url Route
164
166
  */
165
167
  async downloadUrl(requestParameters, initOverrides) {
@@ -167,7 +169,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
167
169
  return await response.value();
168
170
  }
169
171
  /**
170
- * Render an HTML deck to PPTX or PDF and return a download link (sync).
172
+ * 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.
171
173
  * Export Artifact Route
172
174
  */
173
175
  async exportArtifactRaw(requestParameters, initOverrides) {
@@ -200,7 +202,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
200
202
  return new runtime.JSONApiResponse(response, (jsonValue) => ExportResponseFromJSON(jsonValue));
201
203
  }
202
204
  /**
203
- * Render an HTML deck to PPTX or PDF and return a download link (sync).
205
+ * 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.
204
206
  * Export Artifact Route
205
207
  */
206
208
  async exportArtifact(requestParameters, initOverrides) {
@@ -241,6 +243,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
241
243
  return await response.value();
242
244
  }
243
245
  /**
246
+ * 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``.
244
247
  * Mint Upload Url Route
245
248
  */
246
249
  async mintUploadUrlRaw(requestParameters, initOverrides) {
@@ -267,6 +270,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
267
270
  return new runtime.JSONApiResponse(response, (jsonValue) => UploadUrlResponseFromJSON(jsonValue));
268
271
  }
269
272
  /**
273
+ * 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``.
270
274
  * Mint Upload Url Route
271
275
  */
272
276
  async mintUploadUrl(requestParameters, initOverrides) {
@@ -274,7 +278,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
274
278
  return await response.value();
275
279
  }
276
280
  /**
277
- * 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).
281
+ * 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.
278
282
  * Mint Version Upload Url Route
279
283
  */
280
284
  async mintVersionUploadUrlRaw(requestParameters, initOverrides) {
@@ -307,7 +311,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
307
311
  return new runtime.JSONApiResponse(response, (jsonValue) => UploadUrlResponseFromJSON(jsonValue));
308
312
  }
309
313
  /**
310
- * 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).
314
+ * 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.
311
315
  * Mint Version Upload Url Route
312
316
  */
313
317
  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;
@@ -97,6 +97,12 @@ export class ConversationsApi extends runtime.BaseAPI {
97
97
  }
98
98
  const queryParameters = {};
99
99
  const headerParameters = {};
100
+ if (requestParameters['xClientPlatform'] != null) {
101
+ headerParameters['X-Client-Platform'] = String(requestParameters['xClientPlatform']);
102
+ }
103
+ if (requestParameters['xClientVersion'] != null) {
104
+ headerParameters['X-Client-Version'] = String(requestParameters['xClientVersion']);
105
+ }
100
106
  if (this.configuration && this.configuration.accessToken) {
101
107
  const token = this.configuration.accessToken;
102
108
  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
+ }
@@ -0,0 +1,17 @@
1
+ import { WebhookSecrets } from "./compose/webhookSecrets.js";
2
+ /**
3
+ * Groups the hand-written helpers over one `Configuration`.
4
+ *
5
+ * ```ts
6
+ * const client = new Client(config);
7
+ * const secret = await client.webhooks.setSecret(agentId, "https://hooks.acme.com/panja");
8
+ * ```
9
+ */
10
+ export class Client {
11
+ constructor(config) {
12
+ this.config = config;
13
+ if (config === undefined || config === null)
14
+ throw new TypeError("new Client(config): pass a Configuration");
15
+ this.webhooks = new WebhookSecrets(config);
16
+ }
17
+ }
@@ -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>;
@@ -1,8 +1,9 @@
1
- import { DriftError, DuplicateAgentsError, UserError } from "./errors.js";
1
+ import { DriftError, DuplicateAgentsError, NotDeployedError, UserError } from "./errors.js";
2
2
  import { canonicalJson, fingerprintBody, settingsFingerprint } from "./fingerprint.js";
3
3
  import { SettingsTransport } from "./settingsTransport.js";
4
+ import { VERSION_NOTE } from "./transport.js";
4
5
  let defaultClient = null;
5
- /** Set (or clear, with null) the client used when deploy/undeploy/run get no client. */
6
+ /** Set (or clear, with null) the client used when deploy/remove/run get no client. */
6
7
  export function setDefaultClient(config) {
7
8
  defaultClient = config;
8
9
  }
@@ -49,10 +50,38 @@ async function update(transport, remote, agent, strict) {
49
50
  console.warn(`agent "${agent.name}" (${remote.agentId}) was edited outside the SDK; overwriting fields: ${changed.join(", ")}`);
50
51
  }
51
52
  else if (stored === agent.specHash()) {
52
- return { agentId: remote.agentId, action: "unchanged" };
53
+ return settle(transport, remote, agent);
53
54
  }
54
- await transport.updateAgent(remote.agentId, agent);
55
- return { agentId: remote.agentId, action: "updated" };
55
+ const updated = await transport.updateAgent(remote.agentId, agent);
56
+ return deployment(remote.agentId, "updated", liveVersion(updated), missingSecrets(updated));
57
+ }
58
+ function deployment(agentId, action, version, webhooksMissingSecret = []) {
59
+ const out = version === undefined ? { agentId, action } : { agentId, action, version };
60
+ if (webhooksMissingSecret.length > 0)
61
+ out.webhooksMissingSecret = webhooksMissingSecret;
62
+ return out;
63
+ }
64
+ function missingSecrets(remote) {
65
+ const missing = remote === null || remote === void 0 ? void 0 : remote.webhooksMissingSecret;
66
+ return Array.isArray(missing) ? [...missing] : [];
67
+ }
68
+ // Optional chaining: a custom transport written for 0.3 may resolve anything from updateAgent/createAgent.
69
+ function liveVersion(remote) {
70
+ var _a;
71
+ return (_a = remote === null || remote === void 0 ? void 0 : remote.liveVersion) !== null && _a !== void 0 ? _a : undefined;
72
+ }
73
+ /**
74
+ * The stored definition already is this one, so nothing is written to a live or paused agent. What the owner does in
75
+ * the dashboard stays: unsaved draft edits, a version saved to try out, a rollback and a pause. The code's definition
76
+ * goes live again with the next deploy of a changed definition. Only an agent with no live version that was never
77
+ * paused (created, but its first deploy did not finish) is published here.
78
+ */
79
+ async function settle(transport, remote, agent) {
80
+ const state = remote.versionState;
81
+ if (state === undefined || state === "live" || state === "paused" || !transport.publish) {
82
+ return deployment(remote.agentId, "unchanged", remote.liveVersion);
83
+ }
84
+ return deployment(remote.agentId, "updated", await transport.publish(remote.agentId, VERSION_NOTE));
56
85
  }
57
86
  async function deployWith(agent, transport, strict, adopt) {
58
87
  const found = await transport.findAgents(agent.name);
@@ -67,21 +96,57 @@ async function deployWith(agent, transport, strict, adopt) {
67
96
  if (others.length) {
68
97
  throw new UserError(`cannot adopt ${adopt}: agent "${agent.name}" is already deployed as ${others.join(", ")}`);
69
98
  }
70
- await transport.updateAgent(adopt, agent);
71
- return { agentId: adopt, action: "updated" };
99
+ const adopted = await transport.updateAgent(adopt, agent);
100
+ return deployment(adopt, "updated", liveVersion(adopted), missingSecrets(adopted));
72
101
  }
73
102
  if (found.length > 1)
74
103
  throw new DuplicateAgentsError(found.map((r) => r.agentId));
75
- if (found.length === 0)
76
- return { agentId: (await transport.createAgent(agent)).agentId, action: "created" };
104
+ if (found.length === 0) {
105
+ const created = await transport.createAgent(agent);
106
+ return deployment(created.agentId, "created", liveVersion(created), missingSecrets(created));
107
+ }
77
108
  return update(transport, found[0], agent, strict);
78
109
  }
110
+ /**
111
+ * The id of the deployed agent named `agent.name`, for a run with `deploy: false`: reads only, writes nothing. The run
112
+ * gets the live version, whatever definition it holds; a definition that differs from the one last deployed from the
113
+ * SDK is warned about, since only `deploy(agent)` publishes it.
114
+ */
115
+ async function findDeployed(agent, transport) {
116
+ const found = await transport.findAgents(agent.name);
117
+ if (found.length > 1)
118
+ throw new DuplicateAgentsError(found.map((r) => r.agentId));
119
+ if (found.length === 0) {
120
+ throw new NotDeployedError(`agent "${agent.name}" is not deployed. Deploy it first with deploy(agent), or run it with deploy: true`);
121
+ }
122
+ const remote = found[0];
123
+ if (storedHash(remote) !== agent.specHash()) {
124
+ console.warn(`agent "${agent.name}" (${remote.agentId}) was deployed from a different definition; this run uses ` +
125
+ "the live version. Call deploy(agent) to publish your definition");
126
+ }
127
+ return remote.agentId;
128
+ }
129
+ /**
130
+ * Create or update the hosted agent named `agent.name` so end users get this definition.
131
+ *
132
+ * A new or changed definition is saved as the next version and made live (`created` / `updated`). An unchanged one
133
+ * writes nothing (`unchanged`): dashboard edits, a rollback and a pause stay as they are. A changed definition also
134
+ * saves any edits the owner left in the draft, so check the draft first. `strict: true` throws `DriftError` instead of
135
+ * overwriting fields edited outside the SDK. `adopt: agentId` takes over an agent made elsewhere. `version` is the live
136
+ * version (the paused one while paused).
137
+ */
79
138
  export async function deploy(agent, opts = {}) {
80
139
  const transport = resolveTransport(opts.client, opts.transport);
81
140
  forget(agent.name); // this deploy may replace what cached runs of the name point at
82
141
  return serialized(agent.name, () => { var _a; return deployWith(agent, transport, (_a = opts.strict) !== null && _a !== void 0 ? _a : false, opts.adopt); });
83
142
  }
84
- export async function undeploy(name, opts = {}) {
143
+ /**
144
+ * Delete the agent named `name` and all its versions; resolves true if one was deleted. It cannot be undone.
145
+ *
146
+ * To take an agent offline and bring it back later, pause it instead: `new AgentsApi(config).undeployAgent({ agentId })`,
147
+ * then `resumeAgent({ agentId })`.
148
+ */
149
+ export async function remove(name, opts = {}) {
85
150
  const transport = resolveTransport(opts.client, opts.transport);
86
151
  forget(name);
87
152
  return serialized(name, async () => {
@@ -91,7 +156,19 @@ export async function undeploy(name, opts = {}) {
91
156
  return found.length > 0;
92
157
  });
93
158
  }
94
- // Per-name tail: every deploy/undeploy of a name (cached or direct) queues behind the previous one, so they never
159
+ let undeployWarned = false;
160
+ /**
161
+ * @deprecated Renamed {@link remove}: it deletes the agent. The API's `undeploy` route (`AgentsApi.undeployAgent`)
162
+ * pauses an agent instead, so the old name read as a pause.
163
+ */
164
+ export async function undeploy(name, opts = {}) {
165
+ if (!undeployWarned) {
166
+ undeployWarned = true;
167
+ console.warn("undeploy() deletes the agent and is renamed remove(); to pause an agent instead, use AgentsApi.undeployAgent");
168
+ }
169
+ return remove(name, opts);
170
+ }
171
+ // Per-name tail: every deploy/remove of a name (cached or direct) queues behind the previous one, so they never
95
172
  // overlap. forget() does not touch it.
96
173
  const tails = new Map();
97
174
  function serialized(name, fn) {
@@ -106,26 +183,34 @@ function serialized(name, fn) {
106
183
  return p;
107
184
  }
108
185
  const cache = new Map();
109
- /** Drop cached deployments of agent `name` (any owner); called by deploy() and undeploy(). */
186
+ /** Drop cached deployments and lookups of agent `name` (any owner); called by deploy() and remove(). */
110
187
  export function forget(name) {
111
- cache.delete(name);
188
+ cache.delete(cacheKey(name, true));
189
+ cache.delete(cacheKey(name, false));
190
+ }
191
+ // With deploy: false the agent is only looked up, cached apart so a lookup never stands in for a deploy.
192
+ function cacheKey(name, deploy) {
193
+ return `${deploy ? "deploy" : "lookup"}:${name}`;
112
194
  }
113
195
  /**
114
- * The server id for `agent`, deploying it first unless this owner already deployed this exact definition.
115
- * Keyed by name, as the server is: a variant with the same name redeploys, chained after any in-flight deploy so
116
- * deploys of one name never overlap.
196
+ * The server id for `agent`, deploying it first unless this owner already deployed this exact definition; with
197
+ * `deploy` false, the deployed agent's id, looked up without writing. Keyed by name, as the server is: a variant with
198
+ * the same name redeploys, chained after any in-flight deploy so deploys of one name never overlap.
117
199
  */
118
- export function agentIdFor(agent, transport, owner) {
200
+ export function agentIdFor(agent, transport, owner, deploy = true) {
119
201
  const hash = agent.specHash();
120
- let owners = cache.get(agent.name);
202
+ const key = cacheKey(agent.name, deploy);
203
+ let owners = cache.get(key);
121
204
  if (!owners) {
122
205
  owners = new WeakMap();
123
- cache.set(agent.name, owners);
206
+ cache.set(key, owners);
124
207
  }
125
208
  const prev = owners.get(owner);
126
209
  if (prev && prev.hash === hash)
127
210
  return prev.id;
128
- const id = serialized(agent.name, () => deployWith(agent, transport, false)).then((d) => d.agentId);
211
+ const id = deploy
212
+ ? serialized(agent.name, () => deployWith(agent, transport, false)).then((d) => d.agentId)
213
+ : serialized(agent.name, () => findDeployed(agent, transport));
129
214
  const entry = { hash, id };
130
215
  owners.set(owner, entry);
131
216
  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. */
@@ -38,7 +38,7 @@ export class MaxTokensExceededError extends AgentsError {
38
38
  }
39
39
  export class MaxToolCallsExceededError extends AgentsError {
40
40
  }
41
- /** The agent has not been deployed. */
41
+ /** No agent is deployed under this name (thrown by a run with `deploy: false`). */
42
42
  export class NotDeployedError extends AgentsError {
43
43
  }
44
44
  /** A feature the SDK does not support yet. */
@@ -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";
@@ -4,6 +4,6 @@ export * from "./tools.js";
4
4
  export * from "./agent.js";
5
5
  export { tool } from "./functionTool.js";
6
6
  export { SettingsTransport } from "./settingsTransport.js";
7
- export { deploy, undeploy, setDefaultClient } from "./deploy.js";
7
+ export { deploy, remove, undeploy, setDefaultClient } from "./deploy.js";
8
8
  export { run, RunResult, StreamedRunResult } from "./run.js";
9
9
  export { RunState } from "./runState.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;
@@ -480,7 +480,7 @@ function structuredOutput(outputType, event) {
480
480
  return undefined;
481
481
  }
482
482
  async function execute(p, controller, emit) {
483
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
483
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
484
484
  const signal = controller.signal;
485
485
  const unlink = link(p.opts.signal, controller);
486
486
  const stopper = new Stopper(p.transport, signal);
@@ -498,8 +498,8 @@ async function execute(p, controller, emit) {
498
498
  interruptions = await loop.answerPending(p.input);
499
499
  }
500
500
  else {
501
- const agentId = await raceAbort(agentIdFor(p.agent, p.transport, p.owner), signal);
502
- const stream = await loop.start(agentId, (_b = p.opts.conversationId) !== null && _b !== void 0 ? _b : null, p.input);
501
+ const agentId = await raceAbort(agentIdFor(p.agent, p.transport, p.owner, (_b = p.opts.deploy) !== null && _b !== void 0 ? _b : true), signal);
502
+ const stream = await loop.start(agentId, (_c = p.opts.conversationId) !== null && _c !== void 0 ? _c : null, p.input);
503
503
  const interruption = await loop.drive(stream);
504
504
  interruptions = interruption ? [interruption] : [];
505
505
  }
@@ -527,7 +527,7 @@ async function execute(p, controller, emit) {
527
527
  }
528
528
  catch (err) {
529
529
  if (err instanceof ModelBehaviorError)
530
- err.conversationId = (_c = loop.conversationId) !== null && _c !== void 0 ? _c : fallbackConversation;
530
+ err.conversationId = (_d = loop.conversationId) !== null && _d !== void 0 ? _d : fallbackConversation;
531
531
  throw err;
532
532
  }
533
533
  }
@@ -539,12 +539,12 @@ async function execute(p, controller, emit) {
539
539
  newItems: loop.items,
540
540
  interruptions,
541
541
  stopReason: loop.stopReason,
542
- conversationId: (_d = loop.conversationId) !== null && _d !== void 0 ? _d : fallbackConversation,
542
+ conversationId: (_e = loop.conversationId) !== null && _e !== void 0 ? _e : fallbackConversation,
543
543
  cancelled,
544
- outputCitations: ((_e = loop.output) === null || _e === void 0 ? void 0 : _e.kind) === "output" ? ((_f = loop.output.citations) !== null && _f !== void 0 ? _f : []).slice() : [],
545
- outputNote: (_g = loop.output) === null || _g === void 0 ? void 0 : _g.note,
546
- outputSkipped: ((_h = loop.output) === null || _h === void 0 ? void 0 : _h.kind) === "output" ? loop.output.skipped : undefined,
547
- outputMode: ((_j = loop.output) === null || _j === void 0 ? void 0 : _j.kind) === "output" ? loop.output.mode : undefined,
544
+ outputCitations: ((_f = loop.output) === null || _f === void 0 ? void 0 : _f.kind) === "output" ? ((_g = loop.output.citations) !== null && _g !== void 0 ? _g : []).slice() : [],
545
+ outputNote: (_h = loop.output) === null || _h === void 0 ? void 0 : _h.note,
546
+ outputSkipped: ((_j = loop.output) === null || _j === void 0 ? void 0 : _j.kind) === "output" ? loop.output.skipped : undefined,
547
+ outputMode: ((_k = loop.output) === null || _k === void 0 ? void 0 : _k.kind) === "output" ? loop.output.mode : undefined,
548
548
  };
549
549
  }
550
550
  // -- 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>;