sarvam-agents-client 0.3.1 → 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 (152) hide show
  1. package/README.md +82 -0
  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/compose/agent.d.ts +4 -0
  11. package/dist/compose/agent.js +8 -0
  12. package/dist/compose/deploy.d.ts +33 -7
  13. package/dist/compose/deploy.js +97 -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 +2 -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 +17 -0
  21. package/dist/compose/settingsTransport.js +176 -12
  22. package/dist/compose/transport.d.ts +11 -0
  23. package/dist/compose/transport.js +3 -0
  24. package/dist/compose/webhook.d.ts +19 -0
  25. package/dist/compose/webhook.js +184 -0
  26. package/dist/esm/apis/AgentConversationsApi.d.ts +2 -2
  27. package/dist/esm/apis/AgentConversationsApi.js +2 -2
  28. package/dist/esm/apis/AgentsApi.d.ts +195 -5
  29. package/dist/esm/apis/AgentsApi.js +478 -5
  30. package/dist/esm/apis/ArtifactsApi.d.ts +8 -4
  31. package/dist/esm/apis/ArtifactsApi.js +8 -4
  32. package/dist/esm/apis/ConversationsApi.d.ts +2 -0
  33. package/dist/esm/apis/ConversationsApi.js +6 -0
  34. package/dist/esm/compose/agent.d.ts +4 -0
  35. package/dist/esm/compose/agent.js +8 -0
  36. package/dist/esm/compose/deploy.d.ts +33 -7
  37. package/dist/esm/compose/deploy.js +97 -20
  38. package/dist/esm/compose/errors.d.ts +1 -1
  39. package/dist/esm/compose/errors.js +1 -1
  40. package/dist/esm/compose/index.d.ts +2 -1
  41. package/dist/esm/compose/index.js +1 -1
  42. package/dist/esm/compose/run.d.ts +5 -1
  43. package/dist/esm/compose/run.js +9 -9
  44. package/dist/esm/compose/settingsTransport.d.ts +17 -0
  45. package/dist/esm/compose/settingsTransport.js +176 -12
  46. package/dist/esm/compose/transport.d.ts +11 -0
  47. package/dist/esm/compose/transport.js +2 -1
  48. package/dist/esm/compose/webhook.d.ts +19 -0
  49. package/dist/esm/compose/webhook.js +177 -0
  50. package/dist/esm/models/AgentAttachmentDiff.d.ts +50 -0
  51. package/dist/esm/models/AgentAttachmentDiff.js +55 -0
  52. package/dist/esm/models/AgentContentsResource.d.ts +71 -0
  53. package/dist/esm/models/AgentContentsResource.js +70 -0
  54. package/dist/esm/models/AgentDeploy.d.ts +33 -0
  55. package/dist/esm/models/AgentDeploy.js +41 -0
  56. package/dist/esm/models/AgentDraftResource.d.ts +51 -0
  57. package/dist/esm/models/AgentDraftResource.js +52 -0
  58. package/dist/esm/models/AgentFileContent.d.ts +38 -0
  59. package/dist/esm/models/AgentFileContent.js +47 -0
  60. package/dist/esm/models/AgentHistoryResource.d.ts +71 -0
  61. package/dist/esm/models/AgentHistoryResource.js +66 -0
  62. package/dist/esm/models/AgentResource.d.ts +21 -0
  63. package/dist/esm/models/AgentResource.js +12 -0
  64. package/dist/esm/models/AgentSkillFilePin.d.ts +44 -0
  65. package/dist/esm/models/AgentSkillFilePin.js +51 -0
  66. package/dist/esm/models/AgentSubagentEntry.d.ts +38 -0
  67. package/dist/esm/models/AgentSubagentEntry.js +47 -0
  68. package/dist/esm/models/AgentVersionCreate.d.ts +32 -0
  69. package/dist/esm/models/AgentVersionCreate.js +41 -0
  70. package/dist/esm/models/AgentVersionDiffResource.d.ts +87 -0
  71. package/dist/esm/models/AgentVersionDiffResource.js +78 -0
  72. package/dist/esm/models/AgentVersionPick.d.ts +32 -0
  73. package/dist/esm/models/AgentVersionPick.js +43 -0
  74. package/dist/esm/models/AgentVersionResource.d.ts +56 -0
  75. package/dist/esm/models/AgentVersionResource.js +57 -0
  76. package/dist/esm/models/AppResource.d.ts +12 -0
  77. package/dist/esm/models/AppResource.js +4 -0
  78. package/dist/esm/models/ResponseInput.d.ts +6 -0
  79. package/dist/esm/models/ResponseInput.js +2 -0
  80. package/dist/esm/models/SkillUpdateResource.d.ts +38 -0
  81. package/dist/esm/models/SkillUpdateResource.js +47 -0
  82. package/dist/esm/models/index.d.ts +13 -0
  83. package/dist/esm/models/index.js +13 -0
  84. package/dist/esm/webhooks.d.ts +203 -0
  85. package/dist/esm/webhooks.js +215 -0
  86. package/dist/models/AgentAttachmentDiff.d.ts +50 -0
  87. package/dist/models/AgentAttachmentDiff.js +62 -0
  88. package/dist/models/AgentContentsResource.d.ts +71 -0
  89. package/dist/models/AgentContentsResource.js +77 -0
  90. package/dist/models/AgentDeploy.d.ts +33 -0
  91. package/dist/models/AgentDeploy.js +48 -0
  92. package/dist/models/AgentDraftResource.d.ts +51 -0
  93. package/dist/models/AgentDraftResource.js +59 -0
  94. package/dist/models/AgentFileContent.d.ts +38 -0
  95. package/dist/models/AgentFileContent.js +54 -0
  96. package/dist/models/AgentHistoryResource.d.ts +71 -0
  97. package/dist/models/AgentHistoryResource.js +74 -0
  98. package/dist/models/AgentResource.d.ts +21 -0
  99. package/dist/models/AgentResource.js +13 -1
  100. package/dist/models/AgentSkillFilePin.d.ts +44 -0
  101. package/dist/models/AgentSkillFilePin.js +58 -0
  102. package/dist/models/AgentSubagentEntry.d.ts +38 -0
  103. package/dist/models/AgentSubagentEntry.js +54 -0
  104. package/dist/models/AgentVersionCreate.d.ts +32 -0
  105. package/dist/models/AgentVersionCreate.js +48 -0
  106. package/dist/models/AgentVersionDiffResource.d.ts +87 -0
  107. package/dist/models/AgentVersionDiffResource.js +85 -0
  108. package/dist/models/AgentVersionPick.d.ts +32 -0
  109. package/dist/models/AgentVersionPick.js +50 -0
  110. package/dist/models/AgentVersionResource.d.ts +56 -0
  111. package/dist/models/AgentVersionResource.js +64 -0
  112. package/dist/models/AppResource.d.ts +12 -0
  113. package/dist/models/AppResource.js +4 -0
  114. package/dist/models/ResponseInput.d.ts +6 -0
  115. package/dist/models/ResponseInput.js +2 -0
  116. package/dist/models/SkillUpdateResource.d.ts +38 -0
  117. package/dist/models/SkillUpdateResource.js +54 -0
  118. package/dist/models/index.d.ts +13 -0
  119. package/dist/models/index.js +13 -0
  120. package/dist/webhooks.d.ts +203 -0
  121. package/dist/webhooks.js +224 -0
  122. package/package.json +9 -1
  123. package/src/apis/AgentConversationsApi.ts +2 -2
  124. package/src/apis/AgentsApi.ts +737 -6
  125. package/src/apis/ArtifactsApi.ts +8 -4
  126. package/src/apis/ConversationsApi.ts +10 -0
  127. package/src/compose/agent.ts +9 -0
  128. package/src/compose/deploy.ts +113 -20
  129. package/src/compose/errors.ts +1 -1
  130. package/src/compose/index.ts +2 -1
  131. package/src/compose/run.ts +6 -2
  132. package/src/compose/settingsTransport.ts +167 -10
  133. package/src/compose/transport.ts +12 -0
  134. package/src/compose/webhook.ts +181 -0
  135. package/src/models/AgentAttachmentDiff.ts +93 -0
  136. package/src/models/AgentContentsResource.ts +142 -0
  137. package/src/models/AgentDeploy.ts +66 -0
  138. package/src/models/AgentDraftResource.ts +99 -0
  139. package/src/models/AgentFileContent.ts +75 -0
  140. package/src/models/AgentHistoryResource.ts +121 -0
  141. package/src/models/AgentResource.ts +26 -0
  142. package/src/models/AgentSkillFilePin.ts +84 -0
  143. package/src/models/AgentSubagentEntry.ts +75 -0
  144. package/src/models/AgentVersionCreate.ts +65 -0
  145. package/src/models/AgentVersionDiffResource.ts +154 -0
  146. package/src/models/AgentVersionPick.ts +66 -0
  147. package/src/models/AgentVersionResource.ts +101 -0
  148. package/src/models/AppResource.ts +16 -0
  149. package/src/models/ResponseInput.ts +8 -0
  150. package/src/models/SkillUpdateResource.ts +75 -0
  151. package/src/models/index.ts +13 -0
  152. package/src/webhooks.ts +390 -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,6 +1,7 @@
1
1
  import { BuiltinTool } from "./tools.js";
2
2
  import type { FunctionTool } from "./functionTool.js";
3
3
  import type { OutputType } from "./output.js";
4
+ import type { Webhook } from "./webhook.js";
4
5
  export interface ModelSettings {
5
6
  temperature?: number;
6
7
  topP?: number;
@@ -34,6 +35,8 @@ export interface AgentOptions<TOutput extends OutputType | undefined = undefined
34
35
  metadata?: Record<string, string>;
35
36
  /** The shape of the final answer: `{ type: "json_schema", schema }` or a zod schema. `finalOutput` follows it. */
36
37
  outputType?: TOutput;
38
+ /** Endpoints that receive the turn's events (agent.json `webhooks`); at most 5. */
39
+ webhooks?: Webhook[];
37
40
  }
38
41
  /** An agent with any output type: use it for helpers that accept every agent (plain `Agent` means a text agent). */
39
42
  export type AnyAgent = Agent<OutputType | undefined>;
@@ -49,6 +52,7 @@ export declare class Agent<TOutput extends OutputType | undefined = undefined> {
49
52
  readonly functionTimeoutSeconds?: number;
50
53
  readonly limits?: Limits;
51
54
  readonly metadata?: Record<string, string>;
55
+ readonly webhooks?: readonly Webhook[];
52
56
  /** Kept by reference and not frozen: a zod schema must stay usable. Non-enumerable, so deepFreeze skips it. */
53
57
  readonly outputType: TOutput;
54
58
  constructor(rawOpts: AgentOptions<TOutput>);
@@ -6,6 +6,7 @@ const fingerprint_js_1 = require("./fingerprint.js");
6
6
  const builtins_js_1 = require("./builtins.js");
7
7
  const functionTool_js_1 = require("./functionTool.js");
8
8
  const output_js_1 = require("./output.js");
9
+ const webhook_js_1 = require("./webhook.js");
9
10
  const SLUG = /^[a-z0-9][a-z0-9-]{0,63}$/;
10
11
  const REASONING = ["off", "none", "low", "medium", "high", "xhigh", "max"];
11
12
  const TOOL_CHOICES = ["auto", "none"];
@@ -112,8 +113,11 @@ class Agent {
112
113
  this.functionTimeoutSeconds = opts.functionTimeoutSeconds;
113
114
  this.limits = clone(opts.limits);
114
115
  this.metadata = clone(opts.metadata);
116
+ this.webhooks = clone(opts.webhooks);
115
117
  Object.defineProperty(this, "outputType", { value: opts.outputType, enumerable: false, writable: false });
116
118
  this.check();
119
+ if (this.webhooks !== undefined)
120
+ this.webhooks = (0, webhook_js_1.copyWebhooks)(this.webhooks);
117
121
  deepFreeze(this);
118
122
  }
119
123
  check() {
@@ -184,6 +188,8 @@ class Agent {
184
188
  if (names.indexOf("code_mode") !== -1 && names.indexOf("sandbox") === -1) {
185
189
  throw new errors_js_1.UserError("tools: codeMode needs sandbox; add sandbox() to tools");
186
190
  }
191
+ if (this.webhooks !== undefined)
192
+ (0, webhook_js_1.checkWebhooks)(this.webhooks);
187
193
  this.checkFunctions();
188
194
  }
189
195
  checkFunctions() {
@@ -278,6 +284,8 @@ class Agent {
278
284
  }
279
285
  if (this.functionTimeoutSeconds !== undefined)
280
286
  out["function_timeout_seconds"] = this.functionTimeoutSeconds;
287
+ if (this.webhooks !== undefined && this.webhooks.length > 0)
288
+ out["webhooks"] = (0, webhook_js_1.webhooksJson)(this.webhooks);
281
289
  if (this.outputType !== undefined)
282
290
  out["output_schema"] = (0, output_js_1.outputSchema)(this.outputType);
283
291
  return out;
@@ -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;
@@ -4,11 +4,12 @@ export * from "./tools.js";
4
4
  export * from "./agent.js";
5
5
  export { tool } from "./functionTool.js";
6
6
  export type { FunctionCallDetails, FunctionTool, FunctionToolArgs, FunctionToolOptions } from "./functionTool.js";
7
+ export type { Webhook } from "./webhook.js";
7
8
  export type { Event, ClarifyQuestion, FunctionCallRequest, OutputCitation } from "./events.js";
8
9
  export { SettingsTransport } from "./settingsTransport.js";
9
10
  export type { PendingFunctionCalls, RemoteAgent, SettingsWarning, TurnStream, Transport } from "./transport.js";
10
11
  export type { FunctionResult } from "./functionTool.js";
11
- export { deploy, undeploy, setDefaultClient } from "./deploy.js";
12
+ export { deploy, remove, undeploy, setDefaultClient } from "./deploy.js";
12
13
  export type { Deployment } from "./deploy.js";
13
14
  export { run, RunResult, StreamedRunResult } from "./run.js";
14
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 ---------------------------------------------------------------------------------------------------
@@ -17,11 +17,28 @@ export declare class SettingsTransport implements Transport {
17
17
  private readonly agents;
18
18
  private readonly conversations;
19
19
  private readonly responses;
20
+ private readonly customApis;
20
21
  constructor(config: Configuration);
21
22
  findAgents(sdkName: string): Promise<RemoteAgent[]>;
22
23
  readAgent(agentId: string): Promise<RemoteAgent>;
23
24
  createAgent(agent: Agent<OutputType | undefined>): Promise<RemoteAgent>;
25
+ /** The caller's Custom APIs the webhooks name, to bind to a new agent: one entry per name that matches exactly
26
+ * one, and a sentence per name that matches none or several (left to the server, which refuses it only when it
27
+ * checks credentials). */
28
+ private webhookCredentials;
29
+ /** The ids of the caller's own Custom APIs named exactly `name` (`q` also matches substrings and hosts). */
30
+ private customApiIds;
31
+ private bind;
24
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>;
25
42
  deleteAgent(agentId: string): Promise<void>;
26
43
  startTurn(agentId: string, conversationId: string | null, text: string, signal?: AbortSignal): Promise<TurnStream>;
27
44
  answerClarify(conversationId: string, requestId: string, answers: Record<string, unknown>, signal?: AbortSignal): Promise<TurnStream>;