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
@@ -265,6 +265,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
265
265
  }
266
266
 
267
267
  /**
268
+ * 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.
268
269
  * Download Url Route
269
270
  */
270
271
  async downloadUrlRaw(requestParameters: DownloadUrlRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<DownloadUrlResponse>> {
@@ -313,6 +314,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
313
314
  }
314
315
 
315
316
  /**
317
+ * 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.
316
318
  * Download Url Route
317
319
  */
318
320
  async downloadUrl(requestParameters: DownloadUrlRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<DownloadUrlResponse> {
@@ -321,7 +323,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
321
323
  }
322
324
 
323
325
  /**
324
- * Render an HTML deck to PPTX or PDF and return a download link (sync).
326
+ * 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.
325
327
  * Export Artifact Route
326
328
  */
327
329
  async exportArtifactRaw(requestParameters: ExportArtifactRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ExportResponse>> {
@@ -372,7 +374,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
372
374
  }
373
375
 
374
376
  /**
375
- * Render an HTML deck to PPTX or PDF and return a download link (sync).
377
+ * 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.
376
378
  * Export Artifact Route
377
379
  */
378
380
  async exportArtifact(requestParameters: ExportArtifactRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ExportResponse> {
@@ -424,6 +426,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
424
426
  }
425
427
 
426
428
  /**
429
+ * 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``.
427
430
  * Mint Upload Url Route
428
431
  */
429
432
  async mintUploadUrlRaw(requestParameters: MintUploadUrlRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<UploadUrlResponse>> {
@@ -460,6 +463,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
460
463
  }
461
464
 
462
465
  /**
466
+ * 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``.
463
467
  * Mint Upload Url Route
464
468
  */
465
469
  async mintUploadUrl(requestParameters: MintUploadUrlRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<UploadUrlResponse> {
@@ -468,7 +472,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
468
472
  }
469
473
 
470
474
  /**
471
- * 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).
475
+ * 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.
472
476
  * Mint Version Upload Url Route
473
477
  */
474
478
  async mintVersionUploadUrlRaw(requestParameters: MintVersionUploadUrlRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<UploadUrlResponse>> {
@@ -519,7 +523,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
519
523
  }
520
524
 
521
525
  /**
522
- * 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).
526
+ * 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.
523
527
  * Mint Version Upload Url Route
524
528
  */
525
529
  async mintVersionUploadUrl(requestParameters: MintVersionUploadUrlRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<UploadUrlResponse> {
@@ -64,6 +64,8 @@ export interface DeleteConversationRequest {
64
64
 
65
65
  export interface GetConversationRequest {
66
66
  conversationId: string;
67
+ xClientPlatform?: string | null;
68
+ xClientVersion?: string | null;
67
69
  }
68
70
 
69
71
  export interface GetResponseRequest {
@@ -211,6 +213,14 @@ export class ConversationsApi extends runtime.BaseAPI {
211
213
 
212
214
  const headerParameters: runtime.HTTPHeaders = {};
213
215
 
216
+ if (requestParameters['xClientPlatform'] != null) {
217
+ headerParameters['X-Client-Platform'] = String(requestParameters['xClientPlatform']);
218
+ }
219
+
220
+ if (requestParameters['xClientVersion'] != null) {
221
+ headerParameters['X-Client-Version'] = String(requestParameters['xClientVersion']);
222
+ }
223
+
214
224
  if (this.configuration && this.configuration.accessToken) {
215
225
  const token = this.configuration.accessToken;
216
226
  const tokenString = await token("bearerAuth", []);
package/src/client.ts ADDED
@@ -0,0 +1,21 @@
1
+ // Hand-written, not generated: the high-level client.
2
+ import type { Configuration } from "./runtime.js";
3
+ import { WebhookSecrets } from "./compose/webhookSecrets.js";
4
+
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
+ export class Client {
14
+ /** Set, rotate, check and delete an agent webhook's signing secret. */
15
+ readonly webhooks: WebhookSecrets;
16
+
17
+ constructor(readonly config: Configuration) {
18
+ if (config === undefined || config === null) throw new TypeError("new Client(config): pass a Configuration");
19
+ this.webhooks = new WebhookSecrets(config);
20
+ }
21
+ }
@@ -1,20 +1,28 @@
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";
5
- import { DriftError, DuplicateAgentsError, UserError } from "./errors.js";
5
+ import { DriftError, DuplicateAgentsError, NotDeployedError, UserError } from "./errors.js";
6
6
  import { canonicalJson, fingerprintBody, settingsFingerprint } from "./fingerprint.js";
7
7
  import { SettingsTransport } from "./settingsTransport.js";
8
+ import { VERSION_NOTE } from "./transport.js";
8
9
  import type { RemoteAgent, Transport } from "./transport.js";
9
10
 
10
11
  export interface Deployment {
11
12
  agentId: string;
12
13
  action: "created" | "updated" | "unchanged";
14
+ /** The live version, or while the agent is paused, the paused version (what `resumeAgent` brings back); undefined
15
+ * from a server without versions, or when no version was ever live. */
16
+ version?: number;
17
+ /** URLs of the webhooks that still have no signing secret: this deploy stored a placeholder secret nobody holds so
18
+ * the server accepts them. Call `client.webhooks.setSecret(agentId, url)` for each before pointing a provider at
19
+ * the agent; until then deliveries fail verification. Left out when there are none. */
20
+ webhooksMissingSecret?: string[];
13
21
  }
14
22
 
15
23
  let defaultClient: Configuration | null = null;
16
24
 
17
- /** Set (or clear, with null) the client used when deploy/undeploy/run get no client. */
25
+ /** Set (or clear, with null) the client used when deploy/remove/run get no client. */
18
26
  export function setDefaultClient(config: Configuration | null): void {
19
27
  defaultClient = config;
20
28
  }
@@ -63,10 +71,41 @@ async function update(transport: Transport, remote: RemoteAgent, agent: Agent<Ou
63
71
  `agent "${agent.name}" (${remote.agentId}) was edited outside the SDK; overwriting fields: ${changed.join(", ")}`,
64
72
  );
65
73
  } else if (stored === agent.specHash()) {
66
- return { agentId: remote.agentId, action: "unchanged" };
74
+ return settle(transport, remote, agent);
67
75
  }
68
- await transport.updateAgent(remote.agentId, agent);
69
- return { agentId: remote.agentId, action: "updated" };
76
+ const updated = await transport.updateAgent(remote.agentId, agent);
77
+ return deployment(remote.agentId, "updated", liveVersion(updated), missingSecrets(updated));
78
+ }
79
+
80
+ function deployment(agentId: string, action: Deployment["action"], version: number | undefined,
81
+ webhooksMissingSecret: string[] = []): Deployment {
82
+ const out: Deployment = version === undefined ? { agentId, action } : { agentId, action, version };
83
+ if (webhooksMissingSecret.length > 0) out.webhooksMissingSecret = webhooksMissingSecret;
84
+ return out;
85
+ }
86
+
87
+ function missingSecrets(remote: RemoteAgent | undefined | null): string[] {
88
+ const missing = remote?.webhooksMissingSecret;
89
+ return Array.isArray(missing) ? [...missing] : [];
90
+ }
91
+
92
+ // Optional chaining: a custom transport written for 0.3 may resolve anything from updateAgent/createAgent.
93
+ function liveVersion(remote: RemoteAgent | undefined | null): number | undefined {
94
+ return remote?.liveVersion ?? undefined;
95
+ }
96
+
97
+ /**
98
+ * The stored definition already is this one, so nothing is written to a live or paused agent. What the owner does in
99
+ * the dashboard stays: unsaved draft edits, a version saved to try out, a rollback and a pause. The code's definition
100
+ * goes live again with the next deploy of a changed definition. Only an agent with no live version that was never
101
+ * paused (created, but its first deploy did not finish) is published here.
102
+ */
103
+ async function settle(transport: Transport, remote: RemoteAgent, agent: Agent<OutputType | undefined>): Promise<Deployment> {
104
+ const state = remote.versionState;
105
+ if (state === undefined || state === "live" || state === "paused" || !transport.publish) {
106
+ return deployment(remote.agentId, "unchanged", remote.liveVersion);
107
+ }
108
+ return deployment(remote.agentId, "updated", await transport.publish(remote.agentId, VERSION_NOTE));
70
109
  }
71
110
 
72
111
  async function deployWith(agent: Agent<OutputType | undefined>, transport: Transport, strict: boolean, adopt?: string): Promise<Deployment> {
@@ -82,14 +121,47 @@ async function deployWith(agent: Agent<OutputType | undefined>, transport: Trans
82
121
  if (others.length) {
83
122
  throw new UserError(`cannot adopt ${adopt}: agent "${agent.name}" is already deployed as ${others.join(", ")}`);
84
123
  }
85
- await transport.updateAgent(adopt, agent);
86
- return { agentId: adopt, action: "updated" };
124
+ const adopted = await transport.updateAgent(adopt, agent);
125
+ return deployment(adopt, "updated", liveVersion(adopted), missingSecrets(adopted));
87
126
  }
88
127
  if (found.length > 1) throw new DuplicateAgentsError(found.map((r) => r.agentId));
89
- if (found.length === 0) return { agentId: (await transport.createAgent(agent)).agentId, action: "created" };
128
+ if (found.length === 0) {
129
+ const created = await transport.createAgent(agent);
130
+ return deployment(created.agentId, "created", liveVersion(created), missingSecrets(created));
131
+ }
90
132
  return update(transport, found[0], agent, strict);
91
133
  }
92
134
 
135
+ /**
136
+ * The id of the deployed agent named `agent.name`, for a run with `deploy: false`: reads only, writes nothing. The run
137
+ * gets the live version, whatever definition it holds; a definition that differs from the one last deployed from the
138
+ * SDK is warned about, since only `deploy(agent)` publishes it.
139
+ */
140
+ async function findDeployed(agent: Agent<OutputType | undefined>, transport: Transport): Promise<string> {
141
+ const found = await transport.findAgents(agent.name);
142
+ if (found.length > 1) throw new DuplicateAgentsError(found.map((r) => r.agentId));
143
+ if (found.length === 0) {
144
+ throw new NotDeployedError(
145
+ `agent "${agent.name}" is not deployed. Deploy it first with deploy(agent), or run it with deploy: true`,
146
+ );
147
+ }
148
+ const remote = found[0];
149
+ if (storedHash(remote) !== agent.specHash()) {
150
+ console.warn(`agent "${agent.name}" (${remote.agentId}) was deployed from a different definition; this run uses ` +
151
+ "the live version. Call deploy(agent) to publish your definition");
152
+ }
153
+ return remote.agentId;
154
+ }
155
+
156
+ /**
157
+ * Create or update the hosted agent named `agent.name` so end users get this definition.
158
+ *
159
+ * A new or changed definition is saved as the next version and made live (`created` / `updated`). An unchanged one
160
+ * writes nothing (`unchanged`): dashboard edits, a rollback and a pause stay as they are. A changed definition also
161
+ * saves any edits the owner left in the draft, so check the draft first. `strict: true` throws `DriftError` instead of
162
+ * overwriting fields edited outside the SDK. `adopt: agentId` takes over an agent made elsewhere. `version` is the live
163
+ * version (the paused one while paused).
164
+ */
93
165
  export async function deploy(
94
166
  agent: Agent<OutputType | undefined>,
95
167
  opts: { client?: Configuration; transport?: Transport; strict?: boolean; adopt?: string } = {},
@@ -99,7 +171,13 @@ export async function deploy(
99
171
  return serialized(agent.name, () => deployWith(agent, transport, opts.strict ?? false, opts.adopt));
100
172
  }
101
173
 
102
- export async function undeploy(
174
+ /**
175
+ * Delete the agent named `name` and all its versions; resolves true if one was deleted. It cannot be undone.
176
+ *
177
+ * To take an agent offline and bring it back later, pause it instead: `new AgentsApi(config).undeployAgent({ agentId })`,
178
+ * then `resumeAgent({ agentId })`.
179
+ */
180
+ export async function remove(
103
181
  name: string,
104
182
  opts: { client?: Configuration; transport?: Transport } = {},
105
183
  ): Promise<boolean> {
@@ -112,7 +190,24 @@ export async function undeploy(
112
190
  });
113
191
  }
114
192
 
115
- // Per-name tail: every deploy/undeploy of a name (cached or direct) queues behind the previous one, so they never
193
+ let undeployWarned = false;
194
+
195
+ /**
196
+ * @deprecated Renamed {@link remove}: it deletes the agent. The API's `undeploy` route (`AgentsApi.undeployAgent`)
197
+ * pauses an agent instead, so the old name read as a pause.
198
+ */
199
+ export async function undeploy(
200
+ name: string,
201
+ opts: { client?: Configuration; transport?: Transport } = {},
202
+ ): Promise<boolean> {
203
+ if (!undeployWarned) {
204
+ undeployWarned = true;
205
+ console.warn("undeploy() deletes the agent and is renamed remove(); to pause an agent instead, use AgentsApi.undeployAgent");
206
+ }
207
+ return remove(name, opts);
208
+ }
209
+
210
+ // Per-name tail: every deploy/remove of a name (cached or direct) queues behind the previous one, so they never
116
211
  // overlap. forget() does not touch it.
117
212
  const tails = new Map<string, Promise<unknown>>();
118
213
 
@@ -139,26 +234,37 @@ interface Entry {
139
234
 
140
235
  const cache = new Map<string, WeakMap<object, Entry>>();
141
236
 
142
- /** Drop cached deployments of agent `name` (any owner); called by deploy() and undeploy(). */
237
+ /** Drop cached deployments and lookups of agent `name` (any owner); called by deploy() and remove(). */
143
238
  export function forget(name: string): void {
144
- cache.delete(name);
239
+ cache.delete(cacheKey(name, true));
240
+ cache.delete(cacheKey(name, false));
241
+ }
242
+
243
+ // With deploy: false the agent is only looked up, cached apart so a lookup never stands in for a deploy.
244
+ function cacheKey(name: string, deploy: boolean): string {
245
+ return `${deploy ? "deploy" : "lookup"}:${name}`;
145
246
  }
146
247
 
147
248
  /**
148
- * The server id for `agent`, deploying it first unless this owner already deployed this exact definition.
149
- * Keyed by name, as the server is: a variant with the same name redeploys, chained after any in-flight deploy so
150
- * deploys of one name never overlap.
249
+ * The server id for `agent`, deploying it first unless this owner already deployed this exact definition; with
250
+ * `deploy` false, the deployed agent's id, looked up without writing. Keyed by name, as the server is: a variant with
251
+ * the same name redeploys, chained after any in-flight deploy so deploys of one name never overlap.
151
252
  */
152
- export function agentIdFor(agent: Agent<OutputType | undefined>, transport: Transport, owner: object): Promise<string> {
253
+ export function agentIdFor(
254
+ agent: Agent<OutputType | undefined>, transport: Transport, owner: object, deploy = true,
255
+ ): Promise<string> {
153
256
  const hash = agent.specHash();
154
- let owners = cache.get(agent.name);
257
+ const key = cacheKey(agent.name, deploy);
258
+ let owners = cache.get(key);
155
259
  if (!owners) {
156
260
  owners = new WeakMap();
157
- cache.set(agent.name, owners);
261
+ cache.set(key, owners);
158
262
  }
159
263
  const prev = owners.get(owner);
160
264
  if (prev && prev.hash === hash) return prev.id;
161
- const id = serialized(agent.name, () => deployWith(agent, transport, false)).then((d) => d.agentId);
265
+ const id = deploy
266
+ ? serialized(agent.name, () => deployWith(agent, transport, false)).then((d) => d.agentId)
267
+ : serialized(agent.name, () => findDeployed(agent, transport));
162
268
  const entry: Entry = { hash, id };
163
269
  owners.set(owner, entry);
164
270
  const slot = owners;
@@ -54,7 +54,7 @@ export class MaxTokensExceededError extends AgentsError {}
54
54
 
55
55
  export class MaxToolCallsExceededError extends AgentsError {}
56
56
 
57
- /** The agent has not been deployed. */
57
+ /** No agent is deployed under this name (thrown by a run with `deploy: false`). */
58
58
  export class NotDeployedError extends AgentsError {}
59
59
 
60
60
  /** 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";
@@ -34,6 +34,10 @@ export interface RunOptions {
34
34
  /** Throw an error thrown by a function tool's `execute` instead of sending it to the model (for tests). The turn
35
35
  * then stays paused on the server; `RunState.fromSession` continues it. */
36
36
  raiseErrors?: boolean;
37
+ /** `true` (the default) deploys the agent first unless this process already deployed this definition. `false`
38
+ * never writes: it runs the live version of the deployed agent named `agent.name`, and throws `NotDeployedError`
39
+ * when there is none. Use it on servers, and deploy from CI or a release step. */
40
+ deploy?: boolean;
37
41
  /** Not supported: the server caps turns per agent; set `new Agent({ limits: { maxTurns } })`. */
38
42
  maxTurns?: never;
39
43
  }
@@ -584,7 +588,7 @@ async function execute(p: Prepared, controller: AbortController, emit: Emit): Pr
584
588
  if (p.input instanceof RunState) {
585
589
  interruptions = await loop.answerPending(p.input);
586
590
  } else {
587
- const agentId = await raceAbort(agentIdFor(p.agent, p.transport, p.owner), signal);
591
+ const agentId = await raceAbort(agentIdFor(p.agent, p.transport, p.owner, p.opts.deploy ?? true), signal);
588
592
  const stream = await loop.start(agentId, p.opts.conversationId ?? null, p.input);
589
593
  const interruption = await loop.drive(stream);
590
594
  interruptions = interruption ? [interruption] : [];
@@ -773,7 +777,7 @@ export class StreamedRunResult<T = string> implements AsyncIterable<RunStreamEve
773
777
 
774
778
  /**
775
779
  * Run `agent` on `input` (a message, or a RunState holding answers), deploying it first if this owner has not
776
- * deployed this exact definition. With `stream: true`, resolves at once with a StreamedRunResult.
780
+ * deployed this exact definition (unless `deploy: false`). With `stream: true`, resolves at once with a StreamedRunResult.
777
781
  */
778
782
  export function run<O extends OutputType | undefined = undefined>(
779
783
  agent: Agent<O>, input: string | RunState, opts: RunOptions & { stream: true },