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.
- package/README.md +82 -0
- 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/agent.d.ts +4 -0
- package/dist/compose/agent.js +8 -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 +2 -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 +17 -0
- package/dist/compose/settingsTransport.js +176 -12
- package/dist/compose/transport.d.ts +11 -0
- package/dist/compose/transport.js +3 -0
- package/dist/compose/webhook.d.ts +19 -0
- package/dist/compose/webhook.js +184 -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/agent.d.ts +4 -0
- package/dist/esm/compose/agent.js +8 -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 +2 -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 +17 -0
- package/dist/esm/compose/settingsTransport.js +176 -12
- package/dist/esm/compose/transport.d.ts +11 -0
- package/dist/esm/compose/transport.js +2 -1
- package/dist/esm/compose/webhook.d.ts +19 -0
- package/dist/esm/compose/webhook.js +177 -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/esm/webhooks.d.ts +203 -0
- package/dist/esm/webhooks.js +215 -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/dist/webhooks.d.ts +203 -0
- package/dist/webhooks.js +224 -0
- package/package.json +9 -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/agent.ts +9 -0
- package/src/compose/deploy.ts +113 -20
- package/src/compose/errors.ts +1 -1
- package/src/compose/index.ts +2 -1
- package/src/compose/run.ts +6 -2
- package/src/compose/settingsTransport.ts +167 -10
- package/src/compose/transport.ts +12 -0
- package/src/compose/webhook.ts +181 -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/webhooks.ts +390 -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,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>);
|
|
@@ -3,6 +3,7 @@ import { settingsFingerprint } from "./fingerprint.js";
|
|
|
3
3
|
import { BUILTIN_NAMES, checkWebSearchOptions } from "./builtins.js";
|
|
4
4
|
import { DEFAULT_FUNCTION_TIMEOUT_SECONDS, FUNCTION_TIMEOUT_RANGE, FUNCTIONS_MAX, FUNCTIONS_TOTAL_MAX_BYTES, compactBytes, functionToolSettings, isBuiltFunctionTool, isFunctionTool, tool, } from "./functionTool.js";
|
|
5
5
|
import { checkOutputType, outputSchema } from "./output.js";
|
|
6
|
+
import { checkWebhooks, copyWebhooks, webhooksJson } from "./webhook.js";
|
|
6
7
|
const SLUG = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
7
8
|
const REASONING = ["off", "none", "low", "medium", "high", "xhigh", "max"];
|
|
8
9
|
const TOOL_CHOICES = ["auto", "none"];
|
|
@@ -109,8 +110,11 @@ export class Agent {
|
|
|
109
110
|
this.functionTimeoutSeconds = opts.functionTimeoutSeconds;
|
|
110
111
|
this.limits = clone(opts.limits);
|
|
111
112
|
this.metadata = clone(opts.metadata);
|
|
113
|
+
this.webhooks = clone(opts.webhooks);
|
|
112
114
|
Object.defineProperty(this, "outputType", { value: opts.outputType, enumerable: false, writable: false });
|
|
113
115
|
this.check();
|
|
116
|
+
if (this.webhooks !== undefined)
|
|
117
|
+
this.webhooks = copyWebhooks(this.webhooks);
|
|
114
118
|
deepFreeze(this);
|
|
115
119
|
}
|
|
116
120
|
check() {
|
|
@@ -181,6 +185,8 @@ export class Agent {
|
|
|
181
185
|
if (names.indexOf("code_mode") !== -1 && names.indexOf("sandbox") === -1) {
|
|
182
186
|
throw new UserError("tools: codeMode needs sandbox; add sandbox() to tools");
|
|
183
187
|
}
|
|
188
|
+
if (this.webhooks !== undefined)
|
|
189
|
+
checkWebhooks(this.webhooks);
|
|
184
190
|
this.checkFunctions();
|
|
185
191
|
}
|
|
186
192
|
checkFunctions() {
|
|
@@ -275,6 +281,8 @@ export class Agent {
|
|
|
275
281
|
}
|
|
276
282
|
if (this.functionTimeoutSeconds !== undefined)
|
|
277
283
|
out["function_timeout_seconds"] = this.functionTimeoutSeconds;
|
|
284
|
+
if (this.webhooks !== undefined && this.webhooks.length > 0)
|
|
285
|
+
out["webhooks"] = webhooksJson(this.webhooks);
|
|
278
286
|
if (this.outputType !== undefined)
|
|
279
287
|
out["output_schema"] = outputSchema(this.outputType);
|
|
280
288
|
return out;
|
|
@@ -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. */
|
|
@@ -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";
|
|
@@ -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 ---------------------------------------------------------------------------------------------------
|
|
@@ -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>;
|