sarvam-agents-client 0.3.2 → 0.4.0

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 (136) hide show
  1. package/dist/apis/AgentConversationsApi.d.ts +2 -2
  2. package/dist/apis/AgentConversationsApi.js +2 -2
  3. package/dist/apis/AgentsApi.d.ts +195 -5
  4. package/dist/apis/AgentsApi.js +478 -5
  5. package/dist/apis/ArtifactsApi.d.ts +8 -4
  6. package/dist/apis/ArtifactsApi.js +8 -4
  7. package/dist/apis/ConversationsApi.d.ts +2 -0
  8. package/dist/apis/ConversationsApi.js +6 -0
  9. package/dist/compose/deploy.d.ts +33 -7
  10. package/dist/compose/deploy.js +97 -19
  11. package/dist/compose/errors.d.ts +1 -1
  12. package/dist/compose/errors.js +1 -1
  13. package/dist/compose/index.d.ts +1 -1
  14. package/dist/compose/index.js +2 -1
  15. package/dist/compose/run.d.ts +5 -1
  16. package/dist/compose/run.js +9 -9
  17. package/dist/compose/settingsTransport.d.ts +9 -0
  18. package/dist/compose/settingsTransport.js +82 -8
  19. package/dist/compose/transport.d.ts +11 -0
  20. package/dist/compose/transport.js +3 -0
  21. package/dist/esm/apis/AgentConversationsApi.d.ts +2 -2
  22. package/dist/esm/apis/AgentConversationsApi.js +2 -2
  23. package/dist/esm/apis/AgentsApi.d.ts +195 -5
  24. package/dist/esm/apis/AgentsApi.js +478 -5
  25. package/dist/esm/apis/ArtifactsApi.d.ts +8 -4
  26. package/dist/esm/apis/ArtifactsApi.js +8 -4
  27. package/dist/esm/apis/ConversationsApi.d.ts +2 -0
  28. package/dist/esm/apis/ConversationsApi.js +6 -0
  29. package/dist/esm/compose/deploy.d.ts +33 -7
  30. package/dist/esm/compose/deploy.js +97 -20
  31. package/dist/esm/compose/errors.d.ts +1 -1
  32. package/dist/esm/compose/errors.js +1 -1
  33. package/dist/esm/compose/index.d.ts +1 -1
  34. package/dist/esm/compose/index.js +1 -1
  35. package/dist/esm/compose/run.d.ts +5 -1
  36. package/dist/esm/compose/run.js +9 -9
  37. package/dist/esm/compose/settingsTransport.d.ts +9 -0
  38. package/dist/esm/compose/settingsTransport.js +82 -8
  39. package/dist/esm/compose/transport.d.ts +11 -0
  40. package/dist/esm/compose/transport.js +2 -1
  41. package/dist/esm/models/AgentAttachmentDiff.d.ts +50 -0
  42. package/dist/esm/models/AgentAttachmentDiff.js +55 -0
  43. package/dist/esm/models/AgentContentsResource.d.ts +71 -0
  44. package/dist/esm/models/AgentContentsResource.js +70 -0
  45. package/dist/esm/models/AgentDeploy.d.ts +33 -0
  46. package/dist/esm/models/AgentDeploy.js +41 -0
  47. package/dist/esm/models/AgentDraftResource.d.ts +51 -0
  48. package/dist/esm/models/AgentDraftResource.js +52 -0
  49. package/dist/esm/models/AgentFileContent.d.ts +38 -0
  50. package/dist/esm/models/AgentFileContent.js +47 -0
  51. package/dist/esm/models/AgentHistoryResource.d.ts +71 -0
  52. package/dist/esm/models/AgentHistoryResource.js +66 -0
  53. package/dist/esm/models/AgentResource.d.ts +21 -0
  54. package/dist/esm/models/AgentResource.js +12 -0
  55. package/dist/esm/models/AgentSkillFilePin.d.ts +44 -0
  56. package/dist/esm/models/AgentSkillFilePin.js +51 -0
  57. package/dist/esm/models/AgentSubagentEntry.d.ts +38 -0
  58. package/dist/esm/models/AgentSubagentEntry.js +47 -0
  59. package/dist/esm/models/AgentVersionCreate.d.ts +32 -0
  60. package/dist/esm/models/AgentVersionCreate.js +41 -0
  61. package/dist/esm/models/AgentVersionDiffResource.d.ts +87 -0
  62. package/dist/esm/models/AgentVersionDiffResource.js +78 -0
  63. package/dist/esm/models/AgentVersionPick.d.ts +32 -0
  64. package/dist/esm/models/AgentVersionPick.js +43 -0
  65. package/dist/esm/models/AgentVersionResource.d.ts +56 -0
  66. package/dist/esm/models/AgentVersionResource.js +57 -0
  67. package/dist/esm/models/AppResource.d.ts +12 -0
  68. package/dist/esm/models/AppResource.js +4 -0
  69. package/dist/esm/models/ResponseInput.d.ts +6 -0
  70. package/dist/esm/models/ResponseInput.js +2 -0
  71. package/dist/esm/models/SkillUpdateResource.d.ts +38 -0
  72. package/dist/esm/models/SkillUpdateResource.js +47 -0
  73. package/dist/esm/models/index.d.ts +13 -0
  74. package/dist/esm/models/index.js +13 -0
  75. package/dist/models/AgentAttachmentDiff.d.ts +50 -0
  76. package/dist/models/AgentAttachmentDiff.js +62 -0
  77. package/dist/models/AgentContentsResource.d.ts +71 -0
  78. package/dist/models/AgentContentsResource.js +77 -0
  79. package/dist/models/AgentDeploy.d.ts +33 -0
  80. package/dist/models/AgentDeploy.js +48 -0
  81. package/dist/models/AgentDraftResource.d.ts +51 -0
  82. package/dist/models/AgentDraftResource.js +59 -0
  83. package/dist/models/AgentFileContent.d.ts +38 -0
  84. package/dist/models/AgentFileContent.js +54 -0
  85. package/dist/models/AgentHistoryResource.d.ts +71 -0
  86. package/dist/models/AgentHistoryResource.js +74 -0
  87. package/dist/models/AgentResource.d.ts +21 -0
  88. package/dist/models/AgentResource.js +13 -1
  89. package/dist/models/AgentSkillFilePin.d.ts +44 -0
  90. package/dist/models/AgentSkillFilePin.js +58 -0
  91. package/dist/models/AgentSubagentEntry.d.ts +38 -0
  92. package/dist/models/AgentSubagentEntry.js +54 -0
  93. package/dist/models/AgentVersionCreate.d.ts +32 -0
  94. package/dist/models/AgentVersionCreate.js +48 -0
  95. package/dist/models/AgentVersionDiffResource.d.ts +87 -0
  96. package/dist/models/AgentVersionDiffResource.js +85 -0
  97. package/dist/models/AgentVersionPick.d.ts +32 -0
  98. package/dist/models/AgentVersionPick.js +50 -0
  99. package/dist/models/AgentVersionResource.d.ts +56 -0
  100. package/dist/models/AgentVersionResource.js +64 -0
  101. package/dist/models/AppResource.d.ts +12 -0
  102. package/dist/models/AppResource.js +4 -0
  103. package/dist/models/ResponseInput.d.ts +6 -0
  104. package/dist/models/ResponseInput.js +2 -0
  105. package/dist/models/SkillUpdateResource.d.ts +38 -0
  106. package/dist/models/SkillUpdateResource.js +54 -0
  107. package/dist/models/index.d.ts +13 -0
  108. package/dist/models/index.js +13 -0
  109. package/package.json +1 -1
  110. package/src/apis/AgentConversationsApi.ts +2 -2
  111. package/src/apis/AgentsApi.ts +737 -6
  112. package/src/apis/ArtifactsApi.ts +8 -4
  113. package/src/apis/ConversationsApi.ts +10 -0
  114. package/src/compose/deploy.ts +113 -20
  115. package/src/compose/errors.ts +1 -1
  116. package/src/compose/index.ts +1 -1
  117. package/src/compose/run.ts +6 -2
  118. package/src/compose/settingsTransport.ts +81 -9
  119. package/src/compose/transport.ts +12 -0
  120. package/src/models/AgentAttachmentDiff.ts +93 -0
  121. package/src/models/AgentContentsResource.ts +142 -0
  122. package/src/models/AgentDeploy.ts +66 -0
  123. package/src/models/AgentDraftResource.ts +99 -0
  124. package/src/models/AgentFileContent.ts +75 -0
  125. package/src/models/AgentHistoryResource.ts +121 -0
  126. package/src/models/AgentResource.ts +26 -0
  127. package/src/models/AgentSkillFilePin.ts +84 -0
  128. package/src/models/AgentSubagentEntry.ts +75 -0
  129. package/src/models/AgentVersionCreate.ts +65 -0
  130. package/src/models/AgentVersionDiffResource.ts +154 -0
  131. package/src/models/AgentVersionPick.ts +66 -0
  132. package/src/models/AgentVersionResource.ts +101 -0
  133. package/src/models/AppResource.ts +16 -0
  134. package/src/models/ResponseInput.ts +8 -0
  135. package/src/models/SkillUpdateResource.ts +75 -0
  136. 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", []);
@@ -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,52 @@ 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;
9
12
  }
10
- /** Set (or clear, with null) the client used when deploy/undeploy/run get no client. */
13
+ /** Set (or clear, with null) the client used when deploy/remove/run get no client. */
11
14
  export declare function setDefaultClient(config: Configuration | null): void;
12
15
  export declare function getDefaultClient(): Configuration | null;
13
16
  export declare function resolveTransport(client?: Configuration, transport?: Transport): Transport;
17
+ /**
18
+ * Create or update the hosted agent named `agent.name` so end users get this definition.
19
+ *
20
+ * A new or changed definition is saved as the next version and made live (`created` / `updated`). An unchanged one
21
+ * writes nothing (`unchanged`): dashboard edits, a rollback and a pause stay as they are. A changed definition also
22
+ * saves any edits the owner left in the draft, so check the draft first. `strict: true` throws `DriftError` instead of
23
+ * overwriting fields edited outside the SDK. `adopt: agentId` takes over an agent made elsewhere. `version` is the live
24
+ * version (the paused one while paused).
25
+ */
14
26
  export declare function deploy(agent: Agent<OutputType | undefined>, opts?: {
15
27
  client?: Configuration;
16
28
  transport?: Transport;
17
29
  strict?: boolean;
18
30
  adopt?: string;
19
31
  }): Promise<Deployment>;
32
+ /**
33
+ * Delete the agent named `name` and all its versions; resolves true if one was deleted. It cannot be undone.
34
+ *
35
+ * To take an agent offline and bring it back later, pause it instead: `new AgentsApi(config).undeployAgent({ agentId })`,
36
+ * then `resumeAgent({ agentId })`.
37
+ */
38
+ export declare function remove(name: string, opts?: {
39
+ client?: Configuration;
40
+ transport?: Transport;
41
+ }): Promise<boolean>;
42
+ /**
43
+ * @deprecated Renamed {@link remove}: it deletes the agent. The API's `undeploy` route (`AgentsApi.undeployAgent`)
44
+ * pauses an agent instead, so the old name read as a pause.
45
+ */
20
46
  export declare function undeploy(name: string, opts?: {
21
47
  client?: Configuration;
22
48
  transport?: Transport;
23
49
  }): Promise<boolean>;
24
- /** Drop cached deployments of agent `name` (any owner); called by deploy() and undeploy(). */
50
+ /** Drop cached deployments and lookups of agent `name` (any owner); called by deploy() and remove(). */
25
51
  export declare function forget(name: string): void;
26
52
  /**
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.
53
+ * The server id for `agent`, deploying it first unless this owner already deployed this exact definition; with
54
+ * `deploy` false, the deployed agent's id, looked up without writing. Keyed by name, as the server is: a variant with
55
+ * the same name redeploys, chained after any in-flight deploy so deploys of one name never overlap.
30
56
  */
31
- export declare function agentIdFor(agent: Agent<OutputType | undefined>, transport: Transport, owner: object): Promise<string>;
57
+ 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,31 @@ 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));
67
+ }
68
+ function deployment(agentId, action, version) {
69
+ return version === undefined ? { agentId, action } : { agentId, action, version };
70
+ }
71
+ // Optional chaining: a custom transport written for 0.3 may resolve anything from updateAgent/createAgent.
72
+ function liveVersion(remote) {
73
+ var _a;
74
+ return (_a = remote === null || remote === void 0 ? void 0 : remote.liveVersion) !== null && _a !== void 0 ? _a : undefined;
75
+ }
76
+ /**
77
+ * The stored definition already is this one, so nothing is written to a live or paused agent. What the owner does in
78
+ * the dashboard stays: unsaved draft edits, a version saved to try out, a rollback and a pause. The code's definition
79
+ * goes live again with the next deploy of a changed definition. Only an agent with no live version that was never
80
+ * paused (created, but its first deploy did not finish) is published here.
81
+ */
82
+ async function settle(transport, remote, agent) {
83
+ const state = remote.versionState;
84
+ if (state === undefined || state === "live" || state === "paused" || !transport.publish) {
85
+ return deployment(remote.agentId, "unchanged", remote.liveVersion);
86
+ }
87
+ return deployment(remote.agentId, "updated", await transport.publish(remote.agentId, transport_js_1.VERSION_NOTE));
65
88
  }
66
89
  async function deployWith(agent, transport, strict, adopt) {
67
90
  const found = await transport.findAgents(agent.name);
@@ -76,21 +99,56 @@ async function deployWith(agent, transport, strict, adopt) {
76
99
  if (others.length) {
77
100
  throw new errors_js_1.UserError(`cannot adopt ${adopt}: agent "${agent.name}" is already deployed as ${others.join(", ")}`);
78
101
  }
79
- await transport.updateAgent(adopt, agent);
80
- return { agentId: adopt, action: "updated" };
102
+ return deployment(adopt, "updated", liveVersion(await transport.updateAgent(adopt, agent)));
81
103
  }
82
104
  if (found.length > 1)
83
105
  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" };
106
+ if (found.length === 0) {
107
+ const created = await transport.createAgent(agent);
108
+ return deployment(created.agentId, "created", liveVersion(created));
109
+ }
86
110
  return update(transport, found[0], agent, strict);
87
111
  }
112
+ /**
113
+ * The id of the deployed agent named `agent.name`, for a run with `deploy: false`: reads only, writes nothing. The run
114
+ * gets the live version, whatever definition it holds; a definition that differs from the one last deployed from the
115
+ * SDK is warned about, since only `deploy(agent)` publishes it.
116
+ */
117
+ async function findDeployed(agent, transport) {
118
+ const found = await transport.findAgents(agent.name);
119
+ if (found.length > 1)
120
+ throw new errors_js_1.DuplicateAgentsError(found.map((r) => r.agentId));
121
+ if (found.length === 0) {
122
+ throw new errors_js_1.NotDeployedError(`agent "${agent.name}" is not deployed. Deploy it first with deploy(agent), or run it with deploy: true`);
123
+ }
124
+ const remote = found[0];
125
+ if (storedHash(remote) !== agent.specHash()) {
126
+ console.warn(`agent "${agent.name}" (${remote.agentId}) was deployed from a different definition; this run uses ` +
127
+ "the live version. Call deploy(agent) to publish your definition");
128
+ }
129
+ return remote.agentId;
130
+ }
131
+ /**
132
+ * Create or update the hosted agent named `agent.name` so end users get this definition.
133
+ *
134
+ * A new or changed definition is saved as the next version and made live (`created` / `updated`). An unchanged one
135
+ * writes nothing (`unchanged`): dashboard edits, a rollback and a pause stay as they are. A changed definition also
136
+ * saves any edits the owner left in the draft, so check the draft first. `strict: true` throws `DriftError` instead of
137
+ * overwriting fields edited outside the SDK. `adopt: agentId` takes over an agent made elsewhere. `version` is the live
138
+ * version (the paused one while paused).
139
+ */
88
140
  async function deploy(agent, opts = {}) {
89
141
  const transport = resolveTransport(opts.client, opts.transport);
90
142
  forget(agent.name); // this deploy may replace what cached runs of the name point at
91
143
  return serialized(agent.name, () => { var _a; return deployWith(agent, transport, (_a = opts.strict) !== null && _a !== void 0 ? _a : false, opts.adopt); });
92
144
  }
93
- async function undeploy(name, opts = {}) {
145
+ /**
146
+ * Delete the agent named `name` and all its versions; resolves true if one was deleted. It cannot be undone.
147
+ *
148
+ * To take an agent offline and bring it back later, pause it instead: `new AgentsApi(config).undeployAgent({ agentId })`,
149
+ * then `resumeAgent({ agentId })`.
150
+ */
151
+ async function remove(name, opts = {}) {
94
152
  const transport = resolveTransport(opts.client, opts.transport);
95
153
  forget(name);
96
154
  return serialized(name, async () => {
@@ -100,7 +158,19 @@ async function undeploy(name, opts = {}) {
100
158
  return found.length > 0;
101
159
  });
102
160
  }
103
- // Per-name tail: every deploy/undeploy of a name (cached or direct) queues behind the previous one, so they never
161
+ let undeployWarned = false;
162
+ /**
163
+ * @deprecated Renamed {@link remove}: it deletes the agent. The API's `undeploy` route (`AgentsApi.undeployAgent`)
164
+ * pauses an agent instead, so the old name read as a pause.
165
+ */
166
+ async function undeploy(name, opts = {}) {
167
+ if (!undeployWarned) {
168
+ undeployWarned = true;
169
+ console.warn("undeploy() deletes the agent and is renamed remove(); to pause an agent instead, use AgentsApi.undeployAgent");
170
+ }
171
+ return remove(name, opts);
172
+ }
173
+ // Per-name tail: every deploy/remove of a name (cached or direct) queues behind the previous one, so they never
104
174
  // overlap. forget() does not touch it.
105
175
  const tails = new Map();
106
176
  function serialized(name, fn) {
@@ -115,26 +185,34 @@ function serialized(name, fn) {
115
185
  return p;
116
186
  }
117
187
  const cache = new Map();
118
- /** Drop cached deployments of agent `name` (any owner); called by deploy() and undeploy(). */
188
+ /** Drop cached deployments and lookups of agent `name` (any owner); called by deploy() and remove(). */
119
189
  function forget(name) {
120
- cache.delete(name);
190
+ cache.delete(cacheKey(name, true));
191
+ cache.delete(cacheKey(name, false));
192
+ }
193
+ // With deploy: false the agent is only looked up, cached apart so a lookup never stands in for a deploy.
194
+ function cacheKey(name, deploy) {
195
+ return `${deploy ? "deploy" : "lookup"}:${name}`;
121
196
  }
122
197
  /**
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.
198
+ * The server id for `agent`, deploying it first unless this owner already deployed this exact definition; with
199
+ * `deploy` false, the deployed agent's id, looked up without writing. Keyed by name, as the server is: a variant with
200
+ * the same name redeploys, chained after any in-flight deploy so deploys of one name never overlap.
126
201
  */
127
- function agentIdFor(agent, transport, owner) {
202
+ function agentIdFor(agent, transport, owner, deploy = true) {
128
203
  const hash = agent.specHash();
129
- let owners = cache.get(agent.name);
204
+ const key = cacheKey(agent.name, deploy);
205
+ let owners = cache.get(key);
130
206
  if (!owners) {
131
207
  owners = new WeakMap();
132
- cache.set(agent.name, owners);
208
+ cache.set(key, owners);
133
209
  }
134
210
  const prev = owners.get(owner);
135
211
  if (prev && prev.hash === hash)
136
212
  return prev.id;
137
- const id = serialized(agent.name, () => deployWith(agent, transport, false)).then((d) => d.agentId);
213
+ const id = deploy
214
+ ? serialized(agent.name, () => deployWith(agent, transport, false)).then((d) => d.agentId)
215
+ : serialized(agent.name, () => findDeployed(agent, transport));
138
216
  const entry = { hash, id };
139
217
  owners.set(owner, entry);
140
218
  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 ---------------------------------------------------------------------------------------------------
@@ -30,6 +30,15 @@ export declare class SettingsTransport implements Transport {
30
30
  private customApiIds;
31
31
  private bind;
32
32
  updateAgent(agentId: string, agent: Agent<OutputType | undefined>): Promise<RemoteAgent>;
33
+ /** Make what was just written what end users get. A server without versions (no `versionState`) gets the bodiless
34
+ * deploy 0.3 sent; otherwise the draft is saved as a version and that version deployed. */
35
+ private goLive;
36
+ /**
37
+ * Save the draft as the next version and make it live. 409 NO_CHANGES means the newest saved version already is the
38
+ * draft, so that version is deployed, by its number (never "the newest", which a save landing in between could
39
+ * change).
40
+ */
41
+ publish(agentId: string, note: string): Promise<number | undefined>;
33
42
  deleteAgent(agentId: string): Promise<void>;
34
43
  startTurn(agentId: string, conversationId: string | null, text: string, signal?: AbortSignal): Promise<TurnStream>;
35
44
  answerClarify(conversationId: string, requestId: string, answers: Record<string, unknown>, signal?: AbortSignal): Promise<TurnStream>;
@@ -12,6 +12,7 @@ const runtime_js_1 = require("../runtime.js");
12
12
  const streaming_js_1 = require("../streaming.js");
13
13
  const errors_js_1 = require("./errors.js");
14
14
  const events_js_1 = require("./events.js");
15
+ const transport_js_1 = require("./transport.js");
15
16
  const PAGE = 100;
16
17
  /** A post the server is still delivering (409 in_progress) is retried this many times, Retry-After apart. */
17
18
  const IN_PROGRESS_RETRIES = 5;
@@ -102,6 +103,24 @@ function firstDetail(error) {
102
103
  const first = Array.isArray(details) ? details[0] : undefined;
103
104
  return first !== null && typeof first === "object" && !Array.isArray(first) ? { ...first } : {};
104
105
  }
106
+ /** A deploy's 409 MISSING_DEPENDENCIES (the version uses a skill, app, knowledge base or sub-agent that was deleted
107
+ * since) as a UserError naming each one, else null. */
108
+ async function missingDependencies(err, agentId) {
109
+ if ((await reason(err, 409)) !== "MISSING_DEPENDENCIES")
110
+ return null;
111
+ const missing = firstDetail(await chatError(err))["missing"];
112
+ const items = Array.isArray(missing)
113
+ ? missing.filter((m) => m !== null && typeof m === "object")
114
+ : [];
115
+ const named = items.map((m) => `${m["kind"]} '${m["name"]}' (${m["id"]})`).join(", ");
116
+ return new errors_js_1.UserError(`agent ${agentId}: the new version can't go live because it uses something that was deleted` +
117
+ `${named ? ": " + named : ""}. Remove it from the agent, then deploy again`);
118
+ }
119
+ /** `AgentResource.versionState`; undefined from a server without versions (or an agent that is not managed). */
120
+ function versionStateOf(resource) {
121
+ var _a;
122
+ return (_a = resource.versionState) !== null && _a !== void 0 ? _a : undefined;
123
+ }
105
124
  function retryAfterMs(err) {
106
125
  var _a;
107
126
  const seconds = Number((_a = err.response.headers.get("retry-after")) !== null && _a !== void 0 ? _a : 2);
@@ -264,6 +283,7 @@ class SettingsTransport {
264
283
  }
265
284
  let envelope;
266
285
  let warnings;
286
+ let live;
267
287
  // The create response never echoes settings, so support is read back from the settings route, which 404s
268
288
  // when the server has settings switched off (create then silently drops them).
269
289
  try {
@@ -293,7 +313,7 @@ class SettingsTransport {
293
313
  for (const sentence of unbound)
294
314
  console.warn(`agent ${resource.id}: ${sentence}`);
295
315
  checkMetadata(envelope, agent);
296
- await this.agents.deployAgent({ agentId: resource.id });
316
+ live = await this.goLive(resource.id, versionStateOf(resource), agent);
297
317
  }
298
318
  catch (err) {
299
319
  // Don't leave an orphan agent behind; a failing cleanup must not mask the original error.
@@ -305,13 +325,13 @@ class SettingsTransport {
305
325
  }
306
326
  throw err;
307
327
  }
308
- return {
328
+ return withVersion({
309
329
  agentId: resource.id,
310
330
  name: agent.name,
311
331
  instructions: agent.instructions,
312
332
  settings: { ...((_c = envelope.settings) !== null && _c !== void 0 ? _c : {}) },
313
333
  warnings,
314
- };
334
+ }, live, versionStateOf(resource));
315
335
  }
316
336
  /** The caller's Custom APIs the webhooks name, to bind to a new agent: one entry per name that matches exactly
317
337
  * one, and a sentence per name that matches none or several (left to the server, which refuses it only when it
@@ -374,7 +394,8 @@ class SettingsTransport {
374
394
  var _a, _b;
375
395
  const settings = agent.toSettings();
376
396
  // findAgents searches by display name, so an adopted (or dashboard-renamed) agent must carry sdk_name.
377
- if ((await this.agents.getAgent({ agentId })).name !== agent.name) {
397
+ const current = await this.agents.getAgent({ agentId });
398
+ if (current.name !== agent.name) {
378
399
  await this.agents.updateAgent({ agentId, agentUpdate: { name: agent.name } });
379
400
  }
380
401
  // Rejections are only visible after the server stored the settings, so keep what was there to put it back.
@@ -420,14 +441,51 @@ class SettingsTransport {
420
441
  throw err;
421
442
  }
422
443
  checkMetadata(envelope, agent);
423
- await this.agents.deployAgent({ agentId }); // idempotent; moves an adopted draft to deployed
424
- return {
444
+ const live = await this.goLive(agentId, versionStateOf(current), agent);
445
+ return withVersion({
425
446
  agentId,
426
447
  name: agent.name,
427
448
  instructions: agent.instructions,
428
449
  settings: { ...((_b = envelope.settings) !== null && _b !== void 0 ? _b : {}) },
429
450
  warnings,
430
- };
451
+ }, live, versionStateOf(current));
452
+ }
453
+ /** Make what was just written what end users get. A server without versions (no `versionState`) gets the bodiless
454
+ * deploy 0.3 sent; otherwise the draft is saved as a version and that version deployed. */
455
+ async goLive(agentId, versionState, agent) {
456
+ if (versionState === undefined) {
457
+ await this.agents.deployAgent({ agentId }); // idempotent; moves an adopted draft to deployed
458
+ return undefined;
459
+ }
460
+ return this.publish(agentId, transport_js_1.VERSION_NOTE);
461
+ }
462
+ /**
463
+ * Save the draft as the next version and make it live. 409 NO_CHANGES means the newest saved version already is the
464
+ * draft, so that version is deployed, by its number (never "the newest", which a save landing in between could
465
+ * change).
466
+ */
467
+ async publish(agentId, note) {
468
+ var _a, _b;
469
+ let version;
470
+ try {
471
+ version = (await this.agents.saveVersion({ agentId, agentVersionCreate: { note } })).version;
472
+ }
473
+ catch (err) {
474
+ if ((await reason(err, 409)) !== "NO_CHANGES")
475
+ throw err;
476
+ const newest = (await this.agents.getDraft({ agentId })).basedOnVersion;
477
+ if (newest === undefined || newest === null)
478
+ throw err;
479
+ version = newest;
480
+ }
481
+ let resource;
482
+ try {
483
+ resource = await this.agents.deployAgent({ agentId, agentDeploy: { version } });
484
+ }
485
+ catch (err) {
486
+ throw (_a = (await missingDependencies(err, agentId))) !== null && _a !== void 0 ? _a : err;
487
+ }
488
+ return (_b = resource.liveVersion) !== null && _b !== void 0 ? _b : undefined;
431
489
  }
432
490
  async deleteAgent(agentId) {
433
491
  await this.agents.deleteAgent({ agentId });
@@ -605,10 +663,26 @@ class SettingsTransport {
605
663
  }
606
664
  remote(resource, instructions) {
607
665
  var _a;
608
- return { agentId: resource.id, name: resource.name, instructions, settings: { ...((_a = resource.settings) !== null && _a !== void 0 ? _a : {}) }, warnings: [] };
666
+ const remote = {
667
+ agentId: resource.id, name: resource.name, instructions, settings: { ...((_a = resource.settings) !== null && _a !== void 0 ? _a : {}) }, warnings: [],
668
+ };
669
+ // Left out, not set to undefined, when the server has no versions: the shape a 0.3 transport returned.
670
+ if (resource.liveVersion !== undefined && resource.liveVersion !== null)
671
+ remote.liveVersion = resource.liveVersion;
672
+ const state = versionStateOf(resource);
673
+ if (state !== undefined)
674
+ remote.versionState = state;
675
+ return remote;
609
676
  }
610
677
  }
611
678
  exports.SettingsTransport = SettingsTransport;
679
+ /** `remote` with the version fields set when known (left out otherwise, as a server without versions returns it). After a
680
+ * publish the agent is live whatever state it was read in. */
681
+ function withVersion(remote, live, state) {
682
+ if (live !== undefined)
683
+ return { ...remote, liveVersion: live, versionState: "live" };
684
+ return state === undefined ? remote : { ...remote, versionState: state };
685
+ }
612
686
  /** The server's 422 CHAT_VALIDATION / invalid_agent_settings rejection as a UserError, else null. */
613
687
  async function invalidSettings(err) {
614
688
  if (!(err instanceof runtime_js_1.ResponseError) || err.response.status !== 422)