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.
- 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/compose/deploy.d.ts +33 -7
- package/dist/compose/deploy.js +97 -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 +9 -0
- package/dist/compose/settingsTransport.js +82 -8
- package/dist/compose/transport.d.ts +11 -0
- package/dist/compose/transport.js +3 -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/compose/deploy.d.ts +33 -7
- package/dist/esm/compose/deploy.js +97 -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 +9 -0
- package/dist/esm/compose/settingsTransport.js +82 -8
- package/dist/esm/compose/transport.d.ts +11 -0
- package/dist/esm/compose/transport.js +2 -1
- 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/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/compose/deploy.ts +113 -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 +81 -9
- package/src/compose/transport.ts +12 -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
|
@@ -127,6 +127,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
|
|
|
127
127
|
await this.deleteArtifactRaw(requestParameters, initOverrides);
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
130
|
+
* A GET URL for one file: a presigned S3 URL while the file is plaintext. Clients that can follow file-gateway URLs use the v2 route.
|
|
130
131
|
* Download Url Route
|
|
131
132
|
*/
|
|
132
133
|
async downloadUrlRaw(requestParameters, initOverrides) {
|
|
@@ -160,6 +161,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
|
|
|
160
161
|
return new runtime.JSONApiResponse(response, (jsonValue) => DownloadUrlResponseFromJSON(jsonValue));
|
|
161
162
|
}
|
|
162
163
|
/**
|
|
164
|
+
* A GET URL for one file: a presigned S3 URL while the file is plaintext. Clients that can follow file-gateway URLs use the v2 route.
|
|
163
165
|
* Download Url Route
|
|
164
166
|
*/
|
|
165
167
|
async downloadUrl(requestParameters, initOverrides) {
|
|
@@ -167,7 +169,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
|
|
|
167
169
|
return await response.value();
|
|
168
170
|
}
|
|
169
171
|
/**
|
|
170
|
-
* Render an HTML deck to PPTX or PDF and return a download link (sync).
|
|
172
|
+
* Render an HTML deck to PPTX or PDF and return a download link (sync). The link is a presigned S3 URL while the exported file is plaintext; clients that can follow file-gateway URLs use the v2 route.
|
|
171
173
|
* Export Artifact Route
|
|
172
174
|
*/
|
|
173
175
|
async exportArtifactRaw(requestParameters, initOverrides) {
|
|
@@ -200,7 +202,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
|
|
|
200
202
|
return new runtime.JSONApiResponse(response, (jsonValue) => ExportResponseFromJSON(jsonValue));
|
|
201
203
|
}
|
|
202
204
|
/**
|
|
203
|
-
* Render an HTML deck to PPTX or PDF and return a download link (sync).
|
|
205
|
+
* Render an HTML deck to PPTX or PDF and return a download link (sync). The link is a presigned S3 URL while the exported file is plaintext; clients that can follow file-gateway URLs use the v2 route.
|
|
204
206
|
* Export Artifact Route
|
|
205
207
|
*/
|
|
206
208
|
async exportArtifact(requestParameters, initOverrides) {
|
|
@@ -241,6 +243,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
|
|
|
241
243
|
return await response.value();
|
|
242
244
|
}
|
|
243
245
|
/**
|
|
246
|
+
* Mint the PUT URL for an upload: a presigned S3 URL while the file is stored plaintext. Clients that can follow file-gateway URLs use ``POST /v2/artifacts/upload-url``.
|
|
244
247
|
* Mint Upload Url Route
|
|
245
248
|
*/
|
|
246
249
|
async mintUploadUrlRaw(requestParameters, initOverrides) {
|
|
@@ -267,6 +270,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
|
|
|
267
270
|
return new runtime.JSONApiResponse(response, (jsonValue) => UploadUrlResponseFromJSON(jsonValue));
|
|
268
271
|
}
|
|
269
272
|
/**
|
|
273
|
+
* Mint the PUT URL for an upload: a presigned S3 URL while the file is stored plaintext. Clients that can follow file-gateway URLs use ``POST /v2/artifacts/upload-url``.
|
|
270
274
|
* Mint Upload Url Route
|
|
271
275
|
*/
|
|
272
276
|
async mintUploadUrl(requestParameters, initOverrides) {
|
|
@@ -274,7 +278,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
|
|
|
274
278
|
return await response.value();
|
|
275
279
|
}
|
|
276
280
|
/**
|
|
277
|
-
* Presign the PUT for a user\'s edit of ``artifact_id``, saved as its next version. ``artifact_id`` is the version the client edited. 409 ``CHAT_CONFLICT`` (``details[0].latest_artifact_id`` / ``latest_version``) when a newer one has landed; 422 when the artifact has no version chain (uploads, exports).
|
|
281
|
+
* Presign the PUT for a user\'s edit of ``artifact_id``, saved as its next version. ``artifact_id`` is the version the client edited. 409 ``CHAT_CONFLICT`` (``details[0].latest_artifact_id`` / ``latest_version``) when a newer one has landed; 422 when the artifact has no version chain (uploads, exports). The URL is a presigned S3 URL while the edit is stored plaintext; clients that can follow file-gateway URLs use the v2 route.
|
|
278
282
|
* Mint Version Upload Url Route
|
|
279
283
|
*/
|
|
280
284
|
async mintVersionUploadUrlRaw(requestParameters, initOverrides) {
|
|
@@ -307,7 +311,7 @@ export class ArtifactsApi extends runtime.BaseAPI {
|
|
|
307
311
|
return new runtime.JSONApiResponse(response, (jsonValue) => UploadUrlResponseFromJSON(jsonValue));
|
|
308
312
|
}
|
|
309
313
|
/**
|
|
310
|
-
* Presign the PUT for a user\'s edit of ``artifact_id``, saved as its next version. ``artifact_id`` is the version the client edited. 409 ``CHAT_CONFLICT`` (``details[0].latest_artifact_id`` / ``latest_version``) when a newer one has landed; 422 when the artifact has no version chain (uploads, exports).
|
|
314
|
+
* Presign the PUT for a user\'s edit of ``artifact_id``, saved as its next version. ``artifact_id`` is the version the client edited. 409 ``CHAT_CONFLICT`` (``details[0].latest_artifact_id`` / ``latest_version``) when a newer one has landed; 422 when the artifact has no version chain (uploads, exports). The URL is a presigned S3 URL while the edit is stored plaintext; clients that can follow file-gateway URLs use the v2 route.
|
|
311
315
|
* Mint Version Upload Url Route
|
|
312
316
|
*/
|
|
313
317
|
async mintVersionUploadUrl(requestParameters, initOverrides) {
|
|
@@ -21,6 +21,8 @@ export interface DeleteConversationRequest {
|
|
|
21
21
|
}
|
|
22
22
|
export interface GetConversationRequest {
|
|
23
23
|
conversationId: string;
|
|
24
|
+
xClientPlatform?: string | null;
|
|
25
|
+
xClientVersion?: string | null;
|
|
24
26
|
}
|
|
25
27
|
export interface GetResponseRequest {
|
|
26
28
|
conversationId: string;
|
|
@@ -97,6 +97,12 @@ export class ConversationsApi extends runtime.BaseAPI {
|
|
|
97
97
|
}
|
|
98
98
|
const queryParameters = {};
|
|
99
99
|
const headerParameters = {};
|
|
100
|
+
if (requestParameters['xClientPlatform'] != null) {
|
|
101
|
+
headerParameters['X-Client-Platform'] = String(requestParameters['xClientPlatform']);
|
|
102
|
+
}
|
|
103
|
+
if (requestParameters['xClientVersion'] != null) {
|
|
104
|
+
headerParameters['X-Client-Version'] = String(requestParameters['xClientVersion']);
|
|
105
|
+
}
|
|
100
106
|
if (this.configuration && this.configuration.accessToken) {
|
|
101
107
|
const token = this.configuration.accessToken;
|
|
102
108
|
const tokenString = await token("bearerAuth", []);
|
|
@@ -1,4 +1,4 @@
|
|
|
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";
|
|
@@ -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/
|
|
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
|
|
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
|
|
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>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { DriftError, DuplicateAgentsError, UserError } from "./errors.js";
|
|
1
|
+
import { DriftError, DuplicateAgentsError, NotDeployedError, UserError } from "./errors.js";
|
|
2
2
|
import { canonicalJson, fingerprintBody, settingsFingerprint } from "./fingerprint.js";
|
|
3
3
|
import { SettingsTransport } from "./settingsTransport.js";
|
|
4
|
+
import { VERSION_NOTE } from "./transport.js";
|
|
4
5
|
let defaultClient = null;
|
|
5
|
-
/** Set (or clear, with null) the client used when deploy/
|
|
6
|
+
/** Set (or clear, with null) the client used when deploy/remove/run get no client. */
|
|
6
7
|
export function setDefaultClient(config) {
|
|
7
8
|
defaultClient = config;
|
|
8
9
|
}
|
|
@@ -49,10 +50,31 @@ async function update(transport, remote, agent, strict) {
|
|
|
49
50
|
console.warn(`agent "${agent.name}" (${remote.agentId}) was edited outside the SDK; overwriting fields: ${changed.join(", ")}`);
|
|
50
51
|
}
|
|
51
52
|
else if (stored === agent.specHash()) {
|
|
52
|
-
return
|
|
53
|
+
return settle(transport, remote, agent);
|
|
53
54
|
}
|
|
54
|
-
await transport.updateAgent(remote.agentId, agent);
|
|
55
|
-
return
|
|
55
|
+
const updated = await transport.updateAgent(remote.agentId, agent);
|
|
56
|
+
return deployment(remote.agentId, "updated", liveVersion(updated));
|
|
57
|
+
}
|
|
58
|
+
function deployment(agentId, action, version) {
|
|
59
|
+
return version === undefined ? { agentId, action } : { agentId, action, version };
|
|
60
|
+
}
|
|
61
|
+
// Optional chaining: a custom transport written for 0.3 may resolve anything from updateAgent/createAgent.
|
|
62
|
+
function liveVersion(remote) {
|
|
63
|
+
var _a;
|
|
64
|
+
return (_a = remote === null || remote === void 0 ? void 0 : remote.liveVersion) !== null && _a !== void 0 ? _a : undefined;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The stored definition already is this one, so nothing is written to a live or paused agent. What the owner does in
|
|
68
|
+
* the dashboard stays: unsaved draft edits, a version saved to try out, a rollback and a pause. The code's definition
|
|
69
|
+
* goes live again with the next deploy of a changed definition. Only an agent with no live version that was never
|
|
70
|
+
* paused (created, but its first deploy did not finish) is published here.
|
|
71
|
+
*/
|
|
72
|
+
async function settle(transport, remote, agent) {
|
|
73
|
+
const state = remote.versionState;
|
|
74
|
+
if (state === undefined || state === "live" || state === "paused" || !transport.publish) {
|
|
75
|
+
return deployment(remote.agentId, "unchanged", remote.liveVersion);
|
|
76
|
+
}
|
|
77
|
+
return deployment(remote.agentId, "updated", await transport.publish(remote.agentId, VERSION_NOTE));
|
|
56
78
|
}
|
|
57
79
|
async function deployWith(agent, transport, strict, adopt) {
|
|
58
80
|
const found = await transport.findAgents(agent.name);
|
|
@@ -67,21 +89,56 @@ async function deployWith(agent, transport, strict, adopt) {
|
|
|
67
89
|
if (others.length) {
|
|
68
90
|
throw new UserError(`cannot adopt ${adopt}: agent "${agent.name}" is already deployed as ${others.join(", ")}`);
|
|
69
91
|
}
|
|
70
|
-
await transport.updateAgent(adopt, agent);
|
|
71
|
-
return { agentId: adopt, action: "updated" };
|
|
92
|
+
return deployment(adopt, "updated", liveVersion(await transport.updateAgent(adopt, agent)));
|
|
72
93
|
}
|
|
73
94
|
if (found.length > 1)
|
|
74
95
|
throw new DuplicateAgentsError(found.map((r) => r.agentId));
|
|
75
|
-
if (found.length === 0)
|
|
76
|
-
|
|
96
|
+
if (found.length === 0) {
|
|
97
|
+
const created = await transport.createAgent(agent);
|
|
98
|
+
return deployment(created.agentId, "created", liveVersion(created));
|
|
99
|
+
}
|
|
77
100
|
return update(transport, found[0], agent, strict);
|
|
78
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* The id of the deployed agent named `agent.name`, for a run with `deploy: false`: reads only, writes nothing. The run
|
|
104
|
+
* gets the live version, whatever definition it holds; a definition that differs from the one last deployed from the
|
|
105
|
+
* SDK is warned about, since only `deploy(agent)` publishes it.
|
|
106
|
+
*/
|
|
107
|
+
async function findDeployed(agent, transport) {
|
|
108
|
+
const found = await transport.findAgents(agent.name);
|
|
109
|
+
if (found.length > 1)
|
|
110
|
+
throw new DuplicateAgentsError(found.map((r) => r.agentId));
|
|
111
|
+
if (found.length === 0) {
|
|
112
|
+
throw new NotDeployedError(`agent "${agent.name}" is not deployed. Deploy it first with deploy(agent), or run it with deploy: true`);
|
|
113
|
+
}
|
|
114
|
+
const remote = found[0];
|
|
115
|
+
if (storedHash(remote) !== agent.specHash()) {
|
|
116
|
+
console.warn(`agent "${agent.name}" (${remote.agentId}) was deployed from a different definition; this run uses ` +
|
|
117
|
+
"the live version. Call deploy(agent) to publish your definition");
|
|
118
|
+
}
|
|
119
|
+
return remote.agentId;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create or update the hosted agent named `agent.name` so end users get this definition.
|
|
123
|
+
*
|
|
124
|
+
* A new or changed definition is saved as the next version and made live (`created` / `updated`). An unchanged one
|
|
125
|
+
* writes nothing (`unchanged`): dashboard edits, a rollback and a pause stay as they are. A changed definition also
|
|
126
|
+
* saves any edits the owner left in the draft, so check the draft first. `strict: true` throws `DriftError` instead of
|
|
127
|
+
* overwriting fields edited outside the SDK. `adopt: agentId` takes over an agent made elsewhere. `version` is the live
|
|
128
|
+
* version (the paused one while paused).
|
|
129
|
+
*/
|
|
79
130
|
export async function deploy(agent, opts = {}) {
|
|
80
131
|
const transport = resolveTransport(opts.client, opts.transport);
|
|
81
132
|
forget(agent.name); // this deploy may replace what cached runs of the name point at
|
|
82
133
|
return serialized(agent.name, () => { var _a; return deployWith(agent, transport, (_a = opts.strict) !== null && _a !== void 0 ? _a : false, opts.adopt); });
|
|
83
134
|
}
|
|
84
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Delete the agent named `name` and all its versions; resolves true if one was deleted. It cannot be undone.
|
|
137
|
+
*
|
|
138
|
+
* To take an agent offline and bring it back later, pause it instead: `new AgentsApi(config).undeployAgent({ agentId })`,
|
|
139
|
+
* then `resumeAgent({ agentId })`.
|
|
140
|
+
*/
|
|
141
|
+
export async function remove(name, opts = {}) {
|
|
85
142
|
const transport = resolveTransport(opts.client, opts.transport);
|
|
86
143
|
forget(name);
|
|
87
144
|
return serialized(name, async () => {
|
|
@@ -91,7 +148,19 @@ export async function undeploy(name, opts = {}) {
|
|
|
91
148
|
return found.length > 0;
|
|
92
149
|
});
|
|
93
150
|
}
|
|
94
|
-
|
|
151
|
+
let undeployWarned = false;
|
|
152
|
+
/**
|
|
153
|
+
* @deprecated Renamed {@link remove}: it deletes the agent. The API's `undeploy` route (`AgentsApi.undeployAgent`)
|
|
154
|
+
* pauses an agent instead, so the old name read as a pause.
|
|
155
|
+
*/
|
|
156
|
+
export async function undeploy(name, opts = {}) {
|
|
157
|
+
if (!undeployWarned) {
|
|
158
|
+
undeployWarned = true;
|
|
159
|
+
console.warn("undeploy() deletes the agent and is renamed remove(); to pause an agent instead, use AgentsApi.undeployAgent");
|
|
160
|
+
}
|
|
161
|
+
return remove(name, opts);
|
|
162
|
+
}
|
|
163
|
+
// Per-name tail: every deploy/remove of a name (cached or direct) queues behind the previous one, so they never
|
|
95
164
|
// overlap. forget() does not touch it.
|
|
96
165
|
const tails = new Map();
|
|
97
166
|
function serialized(name, fn) {
|
|
@@ -106,26 +175,34 @@ function serialized(name, fn) {
|
|
|
106
175
|
return p;
|
|
107
176
|
}
|
|
108
177
|
const cache = new Map();
|
|
109
|
-
/** Drop cached deployments of agent `name` (any owner); called by deploy() and
|
|
178
|
+
/** Drop cached deployments and lookups of agent `name` (any owner); called by deploy() and remove(). */
|
|
110
179
|
export function forget(name) {
|
|
111
|
-
cache.delete(name);
|
|
180
|
+
cache.delete(cacheKey(name, true));
|
|
181
|
+
cache.delete(cacheKey(name, false));
|
|
182
|
+
}
|
|
183
|
+
// With deploy: false the agent is only looked up, cached apart so a lookup never stands in for a deploy.
|
|
184
|
+
function cacheKey(name, deploy) {
|
|
185
|
+
return `${deploy ? "deploy" : "lookup"}:${name}`;
|
|
112
186
|
}
|
|
113
187
|
/**
|
|
114
|
-
* The server id for `agent`, deploying it first unless this owner already deployed this exact definition
|
|
115
|
-
* Keyed by name, as the server is: a variant with
|
|
116
|
-
* deploys of one name never overlap.
|
|
188
|
+
* The server id for `agent`, deploying it first unless this owner already deployed this exact definition; with
|
|
189
|
+
* `deploy` false, the deployed agent's id, looked up without writing. Keyed by name, as the server is: a variant with
|
|
190
|
+
* the same name redeploys, chained after any in-flight deploy so deploys of one name never overlap.
|
|
117
191
|
*/
|
|
118
|
-
export function agentIdFor(agent, transport, owner) {
|
|
192
|
+
export function agentIdFor(agent, transport, owner, deploy = true) {
|
|
119
193
|
const hash = agent.specHash();
|
|
120
|
-
|
|
194
|
+
const key = cacheKey(agent.name, deploy);
|
|
195
|
+
let owners = cache.get(key);
|
|
121
196
|
if (!owners) {
|
|
122
197
|
owners = new WeakMap();
|
|
123
|
-
cache.set(
|
|
198
|
+
cache.set(key, owners);
|
|
124
199
|
}
|
|
125
200
|
const prev = owners.get(owner);
|
|
126
201
|
if (prev && prev.hash === hash)
|
|
127
202
|
return prev.id;
|
|
128
|
-
const id =
|
|
203
|
+
const id = deploy
|
|
204
|
+
? serialized(agent.name, () => deployWith(agent, transport, false)).then((d) => d.agentId)
|
|
205
|
+
: serialized(agent.name, () => findDeployed(agent, transport));
|
|
129
206
|
const entry = { hash, id };
|
|
130
207
|
owners.set(owner, entry);
|
|
131
208
|
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
|
-
/**
|
|
44
|
+
/** No agent is deployed under this name (thrown by a run with `deploy: false`). */
|
|
45
45
|
export declare class NotDeployedError extends AgentsError {
|
|
46
46
|
}
|
|
47
47
|
/** A feature the SDK does not support yet. */
|
|
@@ -38,7 +38,7 @@ export class MaxTokensExceededError extends AgentsError {
|
|
|
38
38
|
}
|
|
39
39
|
export class MaxToolCallsExceededError extends AgentsError {
|
|
40
40
|
}
|
|
41
|
-
/**
|
|
41
|
+
/** No agent is deployed under this name (thrown by a run with `deploy: false`). */
|
|
42
42
|
export class NotDeployedError extends AgentsError {
|
|
43
43
|
}
|
|
44
44
|
/** A feature the SDK does not support yet. */
|
|
@@ -9,7 +9,7 @@ export type { Event, ClarifyQuestion, FunctionCallRequest, OutputCitation } from
|
|
|
9
9
|
export { SettingsTransport } from "./settingsTransport.js";
|
|
10
10
|
export type { PendingFunctionCalls, RemoteAgent, SettingsWarning, TurnStream, Transport } from "./transport.js";
|
|
11
11
|
export type { FunctionResult } from "./functionTool.js";
|
|
12
|
-
export { deploy, undeploy, setDefaultClient } from "./deploy.js";
|
|
12
|
+
export { deploy, remove, undeploy, setDefaultClient } from "./deploy.js";
|
|
13
13
|
export type { Deployment } from "./deploy.js";
|
|
14
14
|
export { run, RunResult, StreamedRunResult } from "./run.js";
|
|
15
15
|
export type { RunOptions, RunStreamEvent, ClarifyHandler, StopReason } from "./run.js";
|
|
@@ -4,6 +4,6 @@ export * from "./tools.js";
|
|
|
4
4
|
export * from "./agent.js";
|
|
5
5
|
export { tool } from "./functionTool.js";
|
|
6
6
|
export { SettingsTransport } from "./settingsTransport.js";
|
|
7
|
-
export { deploy, undeploy, setDefaultClient } from "./deploy.js";
|
|
7
|
+
export { deploy, remove, undeploy, setDefaultClient } from "./deploy.js";
|
|
8
8
|
export { run, RunResult, StreamedRunResult } from "./run.js";
|
|
9
9
|
export { RunState } from "./runState.js";
|
|
@@ -20,6 +20,10 @@ export interface RunOptions {
|
|
|
20
20
|
/** Throw an error thrown by a function tool's `execute` instead of sending it to the model (for tests). The turn
|
|
21
21
|
* then stays paused on the server; `RunState.fromSession` continues it. */
|
|
22
22
|
raiseErrors?: boolean;
|
|
23
|
+
/** `true` (the default) deploys the agent first unless this process already deployed this definition. `false`
|
|
24
|
+
* never writes: it runs the live version of the deployed agent named `agent.name`, and throws `NotDeployedError`
|
|
25
|
+
* when there is none. Use it on servers, and deploy from CI or a release step. */
|
|
26
|
+
deploy?: boolean;
|
|
23
27
|
/** Not supported: the server caps turns per agent; set `new Agent({ limits: { maxTurns } })`. */
|
|
24
28
|
maxTurns?: never;
|
|
25
29
|
}
|
|
@@ -125,7 +129,7 @@ export declare class StreamedRunResult<T = string> implements AsyncIterable<RunS
|
|
|
125
129
|
}
|
|
126
130
|
/**
|
|
127
131
|
* Run `agent` on `input` (a message, or a RunState holding answers), deploying it first if this owner has not
|
|
128
|
-
* deployed this exact definition. With `stream: true`, resolves at once with a StreamedRunResult.
|
|
132
|
+
* deployed this exact definition (unless `deploy: false`). With `stream: true`, resolves at once with a StreamedRunResult.
|
|
129
133
|
*/
|
|
130
134
|
export declare function run<O extends OutputType | undefined = undefined>(agent: Agent<O>, input: string | RunState, opts: RunOptions & {
|
|
131
135
|
stream: true;
|
package/dist/esm/compose/run.js
CHANGED
|
@@ -480,7 +480,7 @@ function structuredOutput(outputType, event) {
|
|
|
480
480
|
return undefined;
|
|
481
481
|
}
|
|
482
482
|
async function execute(p, controller, emit) {
|
|
483
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
483
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
484
484
|
const signal = controller.signal;
|
|
485
485
|
const unlink = link(p.opts.signal, controller);
|
|
486
486
|
const stopper = new Stopper(p.transport, signal);
|
|
@@ -498,8 +498,8 @@ async function execute(p, controller, emit) {
|
|
|
498
498
|
interruptions = await loop.answerPending(p.input);
|
|
499
499
|
}
|
|
500
500
|
else {
|
|
501
|
-
const agentId = await raceAbort(agentIdFor(p.agent, p.transport, p.owner), signal);
|
|
502
|
-
const stream = await loop.start(agentId, (
|
|
501
|
+
const agentId = await raceAbort(agentIdFor(p.agent, p.transport, p.owner, (_b = p.opts.deploy) !== null && _b !== void 0 ? _b : true), signal);
|
|
502
|
+
const stream = await loop.start(agentId, (_c = p.opts.conversationId) !== null && _c !== void 0 ? _c : null, p.input);
|
|
503
503
|
const interruption = await loop.drive(stream);
|
|
504
504
|
interruptions = interruption ? [interruption] : [];
|
|
505
505
|
}
|
|
@@ -527,7 +527,7 @@ async function execute(p, controller, emit) {
|
|
|
527
527
|
}
|
|
528
528
|
catch (err) {
|
|
529
529
|
if (err instanceof ModelBehaviorError)
|
|
530
|
-
err.conversationId = (
|
|
530
|
+
err.conversationId = (_d = loop.conversationId) !== null && _d !== void 0 ? _d : fallbackConversation;
|
|
531
531
|
throw err;
|
|
532
532
|
}
|
|
533
533
|
}
|
|
@@ -539,12 +539,12 @@ async function execute(p, controller, emit) {
|
|
|
539
539
|
newItems: loop.items,
|
|
540
540
|
interruptions,
|
|
541
541
|
stopReason: loop.stopReason,
|
|
542
|
-
conversationId: (
|
|
542
|
+
conversationId: (_e = loop.conversationId) !== null && _e !== void 0 ? _e : fallbackConversation,
|
|
543
543
|
cancelled,
|
|
544
|
-
outputCitations: ((
|
|
545
|
-
outputNote: (
|
|
546
|
-
outputSkipped: ((
|
|
547
|
-
outputMode: ((
|
|
544
|
+
outputCitations: ((_f = loop.output) === null || _f === void 0 ? void 0 : _f.kind) === "output" ? ((_g = loop.output.citations) !== null && _g !== void 0 ? _g : []).slice() : [],
|
|
545
|
+
outputNote: (_h = loop.output) === null || _h === void 0 ? void 0 : _h.note,
|
|
546
|
+
outputSkipped: ((_j = loop.output) === null || _j === void 0 ? void 0 : _j.kind) === "output" ? loop.output.skipped : undefined,
|
|
547
|
+
outputMode: ((_k = loop.output) === null || _k === void 0 ? void 0 : _k.kind) === "output" ? loop.output.mode : undefined,
|
|
548
548
|
};
|
|
549
549
|
}
|
|
550
550
|
// -- streaming ---------------------------------------------------------------------------------------------------
|
|
@@ -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>;
|
|
@@ -8,6 +8,7 @@ import { FetchError, ResponseError } from "../runtime.js";
|
|
|
8
8
|
import { answerClarify, postToolResults, reconnect, streamResponse } from "../streaming.js";
|
|
9
9
|
import { NotSupportedByServerError, RunError, UserError } from "./errors.js";
|
|
10
10
|
import { chunksFromUiMessage, fromUiChunk } from "./events.js";
|
|
11
|
+
import { VERSION_NOTE } from "./transport.js";
|
|
11
12
|
const PAGE = 100;
|
|
12
13
|
/** A post the server is still delivering (409 in_progress) is retried this many times, Retry-After apart. */
|
|
13
14
|
const IN_PROGRESS_RETRIES = 5;
|
|
@@ -98,6 +99,24 @@ function firstDetail(error) {
|
|
|
98
99
|
const first = Array.isArray(details) ? details[0] : undefined;
|
|
99
100
|
return first !== null && typeof first === "object" && !Array.isArray(first) ? { ...first } : {};
|
|
100
101
|
}
|
|
102
|
+
/** A deploy's 409 MISSING_DEPENDENCIES (the version uses a skill, app, knowledge base or sub-agent that was deleted
|
|
103
|
+
* since) as a UserError naming each one, else null. */
|
|
104
|
+
async function missingDependencies(err, agentId) {
|
|
105
|
+
if ((await reason(err, 409)) !== "MISSING_DEPENDENCIES")
|
|
106
|
+
return null;
|
|
107
|
+
const missing = firstDetail(await chatError(err))["missing"];
|
|
108
|
+
const items = Array.isArray(missing)
|
|
109
|
+
? missing.filter((m) => m !== null && typeof m === "object")
|
|
110
|
+
: [];
|
|
111
|
+
const named = items.map((m) => `${m["kind"]} '${m["name"]}' (${m["id"]})`).join(", ");
|
|
112
|
+
return new UserError(`agent ${agentId}: the new version can't go live because it uses something that was deleted` +
|
|
113
|
+
`${named ? ": " + named : ""}. Remove it from the agent, then deploy again`);
|
|
114
|
+
}
|
|
115
|
+
/** `AgentResource.versionState`; undefined from a server without versions (or an agent that is not managed). */
|
|
116
|
+
function versionStateOf(resource) {
|
|
117
|
+
var _a;
|
|
118
|
+
return (_a = resource.versionState) !== null && _a !== void 0 ? _a : undefined;
|
|
119
|
+
}
|
|
101
120
|
function retryAfterMs(err) {
|
|
102
121
|
var _a;
|
|
103
122
|
const seconds = Number((_a = err.response.headers.get("retry-after")) !== null && _a !== void 0 ? _a : 2);
|
|
@@ -260,6 +279,7 @@ export class SettingsTransport {
|
|
|
260
279
|
}
|
|
261
280
|
let envelope;
|
|
262
281
|
let warnings;
|
|
282
|
+
let live;
|
|
263
283
|
// The create response never echoes settings, so support is read back from the settings route, which 404s
|
|
264
284
|
// when the server has settings switched off (create then silently drops them).
|
|
265
285
|
try {
|
|
@@ -289,7 +309,7 @@ export class SettingsTransport {
|
|
|
289
309
|
for (const sentence of unbound)
|
|
290
310
|
console.warn(`agent ${resource.id}: ${sentence}`);
|
|
291
311
|
checkMetadata(envelope, agent);
|
|
292
|
-
await this.
|
|
312
|
+
live = await this.goLive(resource.id, versionStateOf(resource), agent);
|
|
293
313
|
}
|
|
294
314
|
catch (err) {
|
|
295
315
|
// Don't leave an orphan agent behind; a failing cleanup must not mask the original error.
|
|
@@ -301,13 +321,13 @@ export class SettingsTransport {
|
|
|
301
321
|
}
|
|
302
322
|
throw err;
|
|
303
323
|
}
|
|
304
|
-
return {
|
|
324
|
+
return withVersion({
|
|
305
325
|
agentId: resource.id,
|
|
306
326
|
name: agent.name,
|
|
307
327
|
instructions: agent.instructions,
|
|
308
328
|
settings: { ...((_c = envelope.settings) !== null && _c !== void 0 ? _c : {}) },
|
|
309
329
|
warnings,
|
|
310
|
-
};
|
|
330
|
+
}, live, versionStateOf(resource));
|
|
311
331
|
}
|
|
312
332
|
/** The caller's Custom APIs the webhooks name, to bind to a new agent: one entry per name that matches exactly
|
|
313
333
|
* one, and a sentence per name that matches none or several (left to the server, which refuses it only when it
|
|
@@ -370,7 +390,8 @@ export class SettingsTransport {
|
|
|
370
390
|
var _a, _b;
|
|
371
391
|
const settings = agent.toSettings();
|
|
372
392
|
// findAgents searches by display name, so an adopted (or dashboard-renamed) agent must carry sdk_name.
|
|
373
|
-
|
|
393
|
+
const current = await this.agents.getAgent({ agentId });
|
|
394
|
+
if (current.name !== agent.name) {
|
|
374
395
|
await this.agents.updateAgent({ agentId, agentUpdate: { name: agent.name } });
|
|
375
396
|
}
|
|
376
397
|
// Rejections are only visible after the server stored the settings, so keep what was there to put it back.
|
|
@@ -416,14 +437,51 @@ export class SettingsTransport {
|
|
|
416
437
|
throw err;
|
|
417
438
|
}
|
|
418
439
|
checkMetadata(envelope, agent);
|
|
419
|
-
await this.
|
|
420
|
-
return {
|
|
440
|
+
const live = await this.goLive(agentId, versionStateOf(current), agent);
|
|
441
|
+
return withVersion({
|
|
421
442
|
agentId,
|
|
422
443
|
name: agent.name,
|
|
423
444
|
instructions: agent.instructions,
|
|
424
445
|
settings: { ...((_b = envelope.settings) !== null && _b !== void 0 ? _b : {}) },
|
|
425
446
|
warnings,
|
|
426
|
-
};
|
|
447
|
+
}, live, versionStateOf(current));
|
|
448
|
+
}
|
|
449
|
+
/** Make what was just written what end users get. A server without versions (no `versionState`) gets the bodiless
|
|
450
|
+
* deploy 0.3 sent; otherwise the draft is saved as a version and that version deployed. */
|
|
451
|
+
async goLive(agentId, versionState, agent) {
|
|
452
|
+
if (versionState === undefined) {
|
|
453
|
+
await this.agents.deployAgent({ agentId }); // idempotent; moves an adopted draft to deployed
|
|
454
|
+
return undefined;
|
|
455
|
+
}
|
|
456
|
+
return this.publish(agentId, VERSION_NOTE);
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Save the draft as the next version and make it live. 409 NO_CHANGES means the newest saved version already is the
|
|
460
|
+
* draft, so that version is deployed, by its number (never "the newest", which a save landing in between could
|
|
461
|
+
* change).
|
|
462
|
+
*/
|
|
463
|
+
async publish(agentId, note) {
|
|
464
|
+
var _a, _b;
|
|
465
|
+
let version;
|
|
466
|
+
try {
|
|
467
|
+
version = (await this.agents.saveVersion({ agentId, agentVersionCreate: { note } })).version;
|
|
468
|
+
}
|
|
469
|
+
catch (err) {
|
|
470
|
+
if ((await reason(err, 409)) !== "NO_CHANGES")
|
|
471
|
+
throw err;
|
|
472
|
+
const newest = (await this.agents.getDraft({ agentId })).basedOnVersion;
|
|
473
|
+
if (newest === undefined || newest === null)
|
|
474
|
+
throw err;
|
|
475
|
+
version = newest;
|
|
476
|
+
}
|
|
477
|
+
let resource;
|
|
478
|
+
try {
|
|
479
|
+
resource = await this.agents.deployAgent({ agentId, agentDeploy: { version } });
|
|
480
|
+
}
|
|
481
|
+
catch (err) {
|
|
482
|
+
throw (_a = (await missingDependencies(err, agentId))) !== null && _a !== void 0 ? _a : err;
|
|
483
|
+
}
|
|
484
|
+
return (_b = resource.liveVersion) !== null && _b !== void 0 ? _b : undefined;
|
|
427
485
|
}
|
|
428
486
|
async deleteAgent(agentId) {
|
|
429
487
|
await this.agents.deleteAgent({ agentId });
|
|
@@ -601,9 +659,25 @@ export class SettingsTransport {
|
|
|
601
659
|
}
|
|
602
660
|
remote(resource, instructions) {
|
|
603
661
|
var _a;
|
|
604
|
-
|
|
662
|
+
const remote = {
|
|
663
|
+
agentId: resource.id, name: resource.name, instructions, settings: { ...((_a = resource.settings) !== null && _a !== void 0 ? _a : {}) }, warnings: [],
|
|
664
|
+
};
|
|
665
|
+
// Left out, not set to undefined, when the server has no versions: the shape a 0.3 transport returned.
|
|
666
|
+
if (resource.liveVersion !== undefined && resource.liveVersion !== null)
|
|
667
|
+
remote.liveVersion = resource.liveVersion;
|
|
668
|
+
const state = versionStateOf(resource);
|
|
669
|
+
if (state !== undefined)
|
|
670
|
+
remote.versionState = state;
|
|
671
|
+
return remote;
|
|
605
672
|
}
|
|
606
673
|
}
|
|
674
|
+
/** `remote` with the version fields set when known (left out otherwise, as a server without versions returns it). After a
|
|
675
|
+
* publish the agent is live whatever state it was read in. */
|
|
676
|
+
function withVersion(remote, live, state) {
|
|
677
|
+
if (live !== undefined)
|
|
678
|
+
return { ...remote, liveVersion: live, versionState: "live" };
|
|
679
|
+
return state === undefined ? remote : { ...remote, versionState: state };
|
|
680
|
+
}
|
|
607
681
|
/** The server's 422 CHAT_VALIDATION / invalid_agent_settings rejection as a UserError, else null. */
|
|
608
682
|
async function invalidSettings(err) {
|
|
609
683
|
if (!(err instanceof ResponseError) || err.response.status !== 422)
|
|
@@ -14,7 +14,15 @@ export interface RemoteAgent {
|
|
|
14
14
|
instructions: string;
|
|
15
15
|
settings: Record<string, unknown>;
|
|
16
16
|
warnings: SettingsWarning[];
|
|
17
|
+
/** The version end users get (`AgentResource.liveVersion`); undefined when nothing is live or the server has no
|
|
18
|
+
* versions. */
|
|
19
|
+
liveVersion?: number;
|
|
20
|
+
/** `"live"`, `"paused"` or `"not_live"` (`AgentResource.versionState`); undefined when the server has no versions,
|
|
21
|
+
* in which case deploy() never calls `publish`. */
|
|
22
|
+
versionState?: string;
|
|
17
23
|
}
|
|
24
|
+
/** The note on every version deploy() saves, so the dashboard's version list shows which came from code. */
|
|
25
|
+
export declare const VERSION_NOTE = "Deployed from the SDK";
|
|
18
26
|
/** Async iterable of Events; the ids are filled in as the stream progresses. */
|
|
19
27
|
export interface TurnStream extends AsyncIterable<Event> {
|
|
20
28
|
readonly conversationId: string | null;
|
|
@@ -37,6 +45,9 @@ export interface Transport {
|
|
|
37
45
|
createAgent(agent: Agent<OutputType | undefined>): Promise<RemoteAgent>;
|
|
38
46
|
updateAgent(agentId: string, agent: Agent<OutputType | undefined>): Promise<RemoteAgent>;
|
|
39
47
|
deleteAgent(agentId: string): Promise<void>;
|
|
48
|
+
/** Save the draft as the next version and make that version live; resolves to the live version. Called only for
|
|
49
|
+
* an agent whose `versionState` is set. Optional so a transport written before versions still type-checks. */
|
|
50
|
+
publish?(agentId: string, note: string): Promise<number | undefined>;
|
|
40
51
|
startTurn(agentId: string, conversationId: string | null, text: string, signal?: AbortSignal): Promise<TurnStream>;
|
|
41
52
|
answerClarify(conversationId: string, requestId: string, answers: Record<string, unknown>, signal?: AbortSignal): Promise<TurnStream>;
|
|
42
53
|
resume(conversationId: string, responseId: string, lastEventId: string | null, signal?: AbortSignal): Promise<TurnStream>;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
/** The note on every version deploy() saves, so the dashboard's version list shows which came from code. */
|
|
2
|
+
export const VERSION_NOTE = "Deployed from the SDK";
|