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.
- package/README.md +36 -23
- package/dist/apis/AgentConversationsApi.d.ts +2 -2
- package/dist/apis/AgentConversationsApi.js +2 -2
- package/dist/apis/AgentsApi.d.ts +195 -5
- package/dist/apis/AgentsApi.js +478 -5
- package/dist/apis/ArtifactsApi.d.ts +8 -4
- package/dist/apis/ArtifactsApi.js +8 -4
- package/dist/apis/ConversationsApi.d.ts +2 -0
- package/dist/apis/ConversationsApi.js +6 -0
- package/dist/client.d.ts +16 -0
- package/dist/client.js +21 -0
- package/dist/compose/deploy.d.ts +37 -7
- package/dist/compose/deploy.js +105 -19
- package/dist/compose/errors.d.ts +1 -1
- package/dist/compose/errors.js +1 -1
- package/dist/compose/index.d.ts +1 -1
- package/dist/compose/index.js +2 -1
- package/dist/compose/run.d.ts +5 -1
- package/dist/compose/run.js +9 -9
- package/dist/compose/settingsTransport.d.ts +14 -0
- package/dist/compose/settingsTransport.js +151 -14
- package/dist/compose/transport.d.ts +14 -0
- package/dist/compose/transport.js +3 -0
- package/dist/compose/webhook.d.ts +18 -3
- package/dist/compose/webhook.js +59 -10
- package/dist/compose/webhookSecrets.d.ts +64 -0
- package/dist/compose/webhookSecrets.js +255 -0
- package/dist/esm/apis/AgentConversationsApi.d.ts +2 -2
- package/dist/esm/apis/AgentConversationsApi.js +2 -2
- package/dist/esm/apis/AgentsApi.d.ts +195 -5
- package/dist/esm/apis/AgentsApi.js +478 -5
- package/dist/esm/apis/ArtifactsApi.d.ts +8 -4
- package/dist/esm/apis/ArtifactsApi.js +8 -4
- package/dist/esm/apis/ConversationsApi.d.ts +2 -0
- package/dist/esm/apis/ConversationsApi.js +6 -0
- package/dist/esm/client.d.ts +16 -0
- package/dist/esm/client.js +17 -0
- package/dist/esm/compose/deploy.d.ts +37 -7
- package/dist/esm/compose/deploy.js +105 -20
- package/dist/esm/compose/errors.d.ts +1 -1
- package/dist/esm/compose/errors.js +1 -1
- package/dist/esm/compose/index.d.ts +1 -1
- package/dist/esm/compose/index.js +1 -1
- package/dist/esm/compose/run.d.ts +5 -1
- package/dist/esm/compose/run.js +9 -9
- package/dist/esm/compose/settingsTransport.d.ts +14 -0
- package/dist/esm/compose/settingsTransport.js +151 -14
- package/dist/esm/compose/transport.d.ts +14 -0
- package/dist/esm/compose/transport.js +2 -1
- package/dist/esm/compose/webhook.d.ts +18 -3
- package/dist/esm/compose/webhook.js +55 -9
- package/dist/esm/compose/webhookSecrets.d.ts +64 -0
- package/dist/esm/compose/webhookSecrets.js +250 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/models/AgentAttachmentDiff.d.ts +50 -0
- package/dist/esm/models/AgentAttachmentDiff.js +55 -0
- package/dist/esm/models/AgentContentsResource.d.ts +71 -0
- package/dist/esm/models/AgentContentsResource.js +70 -0
- package/dist/esm/models/AgentDeploy.d.ts +33 -0
- package/dist/esm/models/AgentDeploy.js +41 -0
- package/dist/esm/models/AgentDraftResource.d.ts +51 -0
- package/dist/esm/models/AgentDraftResource.js +52 -0
- package/dist/esm/models/AgentFileContent.d.ts +38 -0
- package/dist/esm/models/AgentFileContent.js +47 -0
- package/dist/esm/models/AgentHistoryResource.d.ts +71 -0
- package/dist/esm/models/AgentHistoryResource.js +66 -0
- package/dist/esm/models/AgentResource.d.ts +21 -0
- package/dist/esm/models/AgentResource.js +12 -0
- package/dist/esm/models/AgentSkillFilePin.d.ts +44 -0
- package/dist/esm/models/AgentSkillFilePin.js +51 -0
- package/dist/esm/models/AgentSubagentEntry.d.ts +38 -0
- package/dist/esm/models/AgentSubagentEntry.js +47 -0
- package/dist/esm/models/AgentVersionCreate.d.ts +32 -0
- package/dist/esm/models/AgentVersionCreate.js +41 -0
- package/dist/esm/models/AgentVersionDiffResource.d.ts +87 -0
- package/dist/esm/models/AgentVersionDiffResource.js +78 -0
- package/dist/esm/models/AgentVersionPick.d.ts +32 -0
- package/dist/esm/models/AgentVersionPick.js +43 -0
- package/dist/esm/models/AgentVersionResource.d.ts +56 -0
- package/dist/esm/models/AgentVersionResource.js +57 -0
- package/dist/esm/models/AppResource.d.ts +12 -0
- package/dist/esm/models/AppResource.js +4 -0
- package/dist/esm/models/ResponseInput.d.ts +6 -0
- package/dist/esm/models/ResponseInput.js +2 -0
- package/dist/esm/models/SkillUpdateResource.d.ts +38 -0
- package/dist/esm/models/SkillUpdateResource.js +47 -0
- package/dist/esm/models/index.d.ts +13 -0
- package/dist/esm/models/index.js +13 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -0
- package/dist/models/AgentAttachmentDiff.d.ts +50 -0
- package/dist/models/AgentAttachmentDiff.js +62 -0
- package/dist/models/AgentContentsResource.d.ts +71 -0
- package/dist/models/AgentContentsResource.js +77 -0
- package/dist/models/AgentDeploy.d.ts +33 -0
- package/dist/models/AgentDeploy.js +48 -0
- package/dist/models/AgentDraftResource.d.ts +51 -0
- package/dist/models/AgentDraftResource.js +59 -0
- package/dist/models/AgentFileContent.d.ts +38 -0
- package/dist/models/AgentFileContent.js +54 -0
- package/dist/models/AgentHistoryResource.d.ts +71 -0
- package/dist/models/AgentHistoryResource.js +74 -0
- package/dist/models/AgentResource.d.ts +21 -0
- package/dist/models/AgentResource.js +13 -1
- package/dist/models/AgentSkillFilePin.d.ts +44 -0
- package/dist/models/AgentSkillFilePin.js +58 -0
- package/dist/models/AgentSubagentEntry.d.ts +38 -0
- package/dist/models/AgentSubagentEntry.js +54 -0
- package/dist/models/AgentVersionCreate.d.ts +32 -0
- package/dist/models/AgentVersionCreate.js +48 -0
- package/dist/models/AgentVersionDiffResource.d.ts +87 -0
- package/dist/models/AgentVersionDiffResource.js +85 -0
- package/dist/models/AgentVersionPick.d.ts +32 -0
- package/dist/models/AgentVersionPick.js +50 -0
- package/dist/models/AgentVersionResource.d.ts +56 -0
- package/dist/models/AgentVersionResource.js +64 -0
- package/dist/models/AppResource.d.ts +12 -0
- package/dist/models/AppResource.js +4 -0
- package/dist/models/ResponseInput.d.ts +6 -0
- package/dist/models/ResponseInput.js +2 -0
- package/dist/models/SkillUpdateResource.d.ts +38 -0
- package/dist/models/SkillUpdateResource.js +54 -0
- package/dist/models/index.d.ts +13 -0
- package/dist/models/index.js +13 -0
- package/package.json +1 -1
- package/src/apis/AgentConversationsApi.ts +2 -2
- package/src/apis/AgentsApi.ts +737 -6
- package/src/apis/ArtifactsApi.ts +8 -4
- package/src/apis/ConversationsApi.ts +10 -0
- package/src/client.ts +21 -0
- package/src/compose/deploy.ts +126 -20
- package/src/compose/errors.ts +1 -1
- package/src/compose/index.ts +1 -1
- package/src/compose/run.ts +6 -2
- package/src/compose/settingsTransport.ts +154 -16
- package/src/compose/transport.ts +15 -0
- package/src/compose/webhook.ts +64 -11
- package/src/compose/webhookSecrets.ts +257 -0
- package/src/index.ts +4 -0
- package/src/models/AgentAttachmentDiff.ts +93 -0
- package/src/models/AgentContentsResource.ts +142 -0
- package/src/models/AgentDeploy.ts +66 -0
- package/src/models/AgentDraftResource.ts +99 -0
- package/src/models/AgentFileContent.ts +75 -0
- package/src/models/AgentHistoryResource.ts +121 -0
- package/src/models/AgentResource.ts +26 -0
- package/src/models/AgentSkillFilePin.ts +84 -0
- package/src/models/AgentSubagentEntry.ts +75 -0
- package/src/models/AgentVersionCreate.ts +65 -0
- package/src/models/AgentVersionDiffResource.ts +154 -0
- package/src/models/AgentVersionPick.ts +66 -0
- package/src/models/AgentVersionResource.ts +101 -0
- package/src/models/AppResource.ts +16 -0
- package/src/models/ResponseInput.ts +8 -0
- package/src/models/SkillUpdateResource.ts +75 -0
- package/src/models/index.ts +13 -0
package/src/apis/ArtifactsApi.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/compose/deploy.ts
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
|
-
/** deploy()/
|
|
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/
|
|
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
|
|
74
|
+
return settle(transport, remote, agent);
|
|
67
75
|
}
|
|
68
|
-
await transport.updateAgent(remote.agentId, agent);
|
|
69
|
-
return
|
|
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
|
|
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)
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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 =
|
|
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;
|
package/src/compose/errors.ts
CHANGED
|
@@ -54,7 +54,7 @@ export class MaxTokensExceededError extends AgentsError {}
|
|
|
54
54
|
|
|
55
55
|
export class MaxToolCallsExceededError extends AgentsError {}
|
|
56
56
|
|
|
57
|
-
/**
|
|
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. */
|
package/src/compose/index.ts
CHANGED
|
@@ -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";
|
package/src/compose/run.ts
CHANGED
|
@@ -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 },
|