sarvam-agents-client 0.1.2 → 0.2.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 +15 -0
- package/dist/apis/AgentConversationsApi.d.ts +44 -1
- package/dist/apis/AgentConversationsApi.js +104 -1
- package/dist/apis/AgentsApi.d.ts +77 -5
- package/dist/apis/AgentsApi.js +163 -5
- package/dist/apis/AppsApi.d.ts +43 -1
- package/dist/apis/AppsApi.js +108 -0
- package/dist/apis/ArtifactsApi.d.ts +31 -1
- package/dist/apis/ArtifactsApi.js +82 -0
- package/dist/apis/CustomAPIsApi.d.ts +124 -0
- package/dist/apis/CustomAPIsApi.js +305 -0
- package/dist/apis/ModelsApi.d.ts +26 -0
- package/dist/apis/ModelsApi.js +52 -0
- package/dist/apis/index.d.ts +2 -0
- package/dist/apis/index.js +2 -0
- package/dist/compose/agent.d.ts +44 -0
- package/dist/compose/agent.js +222 -0
- package/dist/compose/builtins.d.ts +4 -0
- package/dist/compose/builtins.js +22 -0
- package/dist/compose/deploy.d.ts +30 -0
- package/dist/compose/deploy.js +146 -0
- package/dist/compose/errors.d.ts +48 -0
- package/dist/compose/errors.js +68 -0
- package/dist/compose/events.d.ts +63 -0
- package/dist/compose/events.js +100 -0
- package/dist/compose/fingerprint.d.ts +6 -0
- package/dist/compose/fingerprint.js +83 -0
- package/dist/compose/index.d.ts +13 -0
- package/dist/compose/index.js +33 -0
- package/dist/compose/run.d.ts +100 -0
- package/dist/compose/run.js +536 -0
- package/dist/compose/runState.d.ts +26 -0
- package/dist/compose/runState.js +79 -0
- package/dist/compose/settingsTransport.d.ts +24 -0
- package/dist/compose/settingsTransport.js +280 -0
- package/dist/compose/tools.d.ts +17 -0
- package/dist/compose/tools.js +44 -0
- package/dist/compose/transport.d.ts +34 -0
- package/dist/compose/transport.js +2 -0
- package/dist/esm/apis/AgentConversationsApi.d.ts +44 -1
- package/dist/esm/apis/AgentConversationsApi.js +104 -1
- package/dist/esm/apis/AgentsApi.d.ts +77 -5
- package/dist/esm/apis/AgentsApi.js +163 -5
- package/dist/esm/apis/AppsApi.d.ts +43 -1
- package/dist/esm/apis/AppsApi.js +109 -1
- package/dist/esm/apis/ArtifactsApi.d.ts +31 -1
- package/dist/esm/apis/ArtifactsApi.js +83 -1
- package/dist/esm/apis/CustomAPIsApi.d.ts +124 -0
- package/dist/esm/apis/CustomAPIsApi.js +301 -0
- package/dist/esm/apis/ModelsApi.d.ts +26 -0
- package/dist/esm/apis/ModelsApi.js +48 -0
- package/dist/esm/apis/index.d.ts +2 -0
- package/dist/esm/apis/index.js +2 -0
- package/dist/esm/compose/agent.d.ts +44 -0
- package/dist/esm/compose/agent.js +218 -0
- package/dist/esm/compose/builtins.d.ts +4 -0
- package/dist/esm/compose/builtins.js +18 -0
- package/dist/esm/compose/deploy.d.ts +30 -0
- package/dist/esm/compose/deploy.js +137 -0
- package/dist/esm/compose/errors.d.ts +48 -0
- package/dist/esm/compose/errors.js +53 -0
- package/dist/esm/compose/events.d.ts +63 -0
- package/dist/esm/compose/events.js +97 -0
- package/dist/esm/compose/fingerprint.d.ts +6 -0
- package/dist/esm/compose/fingerprint.js +78 -0
- package/dist/esm/compose/index.d.ts +13 -0
- package/dist/esm/compose/index.js +8 -0
- package/dist/esm/compose/run.d.ts +100 -0
- package/dist/esm/compose/run.js +530 -0
- package/dist/esm/compose/runState.d.ts +26 -0
- package/dist/esm/compose/runState.js +75 -0
- package/dist/esm/compose/settingsTransport.d.ts +24 -0
- package/dist/esm/compose/settingsTransport.js +276 -0
- package/dist/esm/compose/tools.d.ts +17 -0
- package/dist/esm/compose/tools.js +34 -0
- package/dist/esm/compose/transport.d.ts +34 -0
- package/dist/esm/compose/transport.js +1 -0
- package/dist/esm/models/AgentChannelRef.d.ts +1 -0
- package/dist/esm/models/AgentChannelRef.js +2 -1
- package/dist/esm/models/AgentConversationDetail.d.ts +15 -2
- package/dist/esm/models/AgentConversationDetail.js +6 -4
- package/dist/esm/models/AgentConversationView.d.ts +11 -5
- package/dist/esm/models/AgentConversationView.js +4 -4
- package/dist/esm/models/AgentCreate.d.ts +8 -0
- package/dist/esm/models/AgentCreate.js +2 -0
- package/dist/esm/models/AgentCustomApiList.d.ts +33 -0
- package/dist/esm/models/AgentCustomApiList.js +44 -0
- package/dist/esm/models/AgentResource.d.ts +14 -0
- package/dist/esm/models/AgentResource.js +4 -0
- package/dist/esm/models/AgentSettingsResponse.d.ts +53 -0
- package/dist/esm/models/AgentSettingsResponse.js +52 -0
- package/dist/esm/models/AgentUpdate.d.ts +8 -0
- package/dist/esm/models/AgentUpdate.js +2 -0
- package/dist/esm/models/AppAccountView.d.ts +88 -0
- package/dist/esm/models/AppAccountView.js +79 -0
- package/dist/esm/models/AppAccountsView.d.ts +66 -0
- package/dist/esm/models/AppAccountsView.js +60 -0
- package/dist/esm/models/AppResource.d.ts +36 -0
- package/dist/esm/models/AppResource.js +12 -0
- package/dist/esm/models/AppResourceCheckView.d.ts +74 -0
- package/dist/esm/models/AppResourceCheckView.js +63 -0
- package/dist/esm/models/AppResourceView.d.ts +68 -0
- package/dist/esm/models/AppResourceView.js +67 -0
- package/dist/esm/models/AppResourcesView.d.ts +54 -0
- package/dist/esm/models/AppResourcesView.js +56 -0
- package/dist/esm/models/AppToolsResponse.d.ts +14 -0
- package/dist/esm/models/AppToolsResponse.js +4 -0
- package/dist/esm/models/AppView.d.ts +42 -0
- package/dist/esm/models/AppView.js +14 -0
- package/dist/esm/models/ArtifactVersionResponse.d.ts +94 -0
- package/dist/esm/models/ArtifactVersionResponse.js +80 -0
- package/dist/esm/models/AttachedAgent.d.ts +44 -0
- package/dist/esm/models/AttachedAgent.js +49 -0
- package/dist/esm/models/Auth.d.ts +30 -0
- package/dist/esm/models/Auth.js +52 -0
- package/dist/esm/models/BindCustomApiBody.d.ts +32 -0
- package/dist/esm/models/BindCustomApiBody.js +43 -0
- package/dist/esm/models/ConversationArtifact.d.ts +14 -0
- package/dist/esm/models/ConversationArtifact.js +9 -0
- package/dist/esm/models/CustomApi.d.ts +102 -0
- package/dist/esm/models/CustomApi.js +90 -0
- package/dist/esm/models/CustomApiBasicAuth.d.ts +51 -0
- package/dist/esm/models/CustomApiBasicAuth.js +57 -0
- package/dist/esm/models/CustomApiBearerAuth.d.ts +45 -0
- package/dist/esm/models/CustomApiBearerAuth.js +53 -0
- package/dist/esm/models/CustomApiCreate.d.ts +57 -0
- package/dist/esm/models/CustomApiCreate.js +56 -0
- package/dist/esm/models/CustomApiHeader.d.ts +44 -0
- package/dist/esm/models/CustomApiHeader.js +47 -0
- package/dist/esm/models/CustomApiHeadersAuth.d.ts +46 -0
- package/dist/esm/models/CustomApiHeadersAuth.js +54 -0
- package/dist/esm/models/CustomApiList.d.ts +64 -0
- package/dist/esm/models/CustomApiList.js +64 -0
- package/dist/esm/models/CustomApiName.d.ts +44 -0
- package/dist/esm/models/CustomApiName.js +49 -0
- package/dist/esm/models/CustomApiUpdate.d.ts +58 -0
- package/dist/esm/models/CustomApiUpdate.js +50 -0
- package/dist/esm/models/CustomApiUpdateAuth.d.ts +30 -0
- package/dist/esm/models/CustomApiUpdateAuth.js +52 -0
- package/dist/esm/models/ErrorDetailItem.d.ts +5 -0
- package/dist/esm/models/ListModels403Response.d.ts +23 -0
- package/dist/esm/models/ListModels403Response.js +45 -0
- package/dist/esm/models/ModelEndpointView.d.ts +38 -0
- package/dist/esm/models/ModelEndpointView.js +45 -0
- package/dist/esm/models/ModelView.d.ts +69 -0
- package/dist/esm/models/ModelView.js +56 -0
- package/dist/esm/models/ModelsResponse.d.ts +33 -0
- package/dist/esm/models/ModelsResponse.js +44 -0
- package/dist/esm/models/SettingsIssueView.d.ts +44 -0
- package/dist/esm/models/SettingsIssueView.js +51 -0
- package/dist/esm/models/VersionCommitBody.d.ts +44 -0
- package/dist/esm/models/VersionCommitBody.js +51 -0
- package/dist/esm/models/VersionUploadUrlBody.d.ts +32 -0
- package/dist/esm/models/VersionUploadUrlBody.js +43 -0
- package/dist/esm/models/index.d.ts +28 -0
- package/dist/esm/models/index.js +28 -0
- package/dist/models/AgentChannelRef.d.ts +1 -0
- package/dist/models/AgentChannelRef.js +2 -1
- package/dist/models/AgentConversationDetail.d.ts +15 -2
- package/dist/models/AgentConversationDetail.js +6 -4
- package/dist/models/AgentConversationView.d.ts +11 -5
- package/dist/models/AgentConversationView.js +4 -4
- package/dist/models/AgentCreate.d.ts +8 -0
- package/dist/models/AgentCreate.js +2 -0
- package/dist/models/AgentCustomApiList.d.ts +33 -0
- package/dist/models/AgentCustomApiList.js +51 -0
- package/dist/models/AgentResource.d.ts +14 -0
- package/dist/models/AgentResource.js +4 -0
- package/dist/models/AgentSettingsResponse.d.ts +53 -0
- package/dist/models/AgentSettingsResponse.js +59 -0
- package/dist/models/AgentUpdate.d.ts +8 -0
- package/dist/models/AgentUpdate.js +2 -0
- package/dist/models/AppAccountView.d.ts +88 -0
- package/dist/models/AppAccountView.js +87 -0
- package/dist/models/AppAccountsView.d.ts +66 -0
- package/dist/models/AppAccountsView.js +68 -0
- package/dist/models/AppResource.d.ts +36 -0
- package/dist/models/AppResource.js +12 -0
- package/dist/models/AppResourceCheckView.d.ts +74 -0
- package/dist/models/AppResourceCheckView.js +71 -0
- package/dist/models/AppResourceView.d.ts +68 -0
- package/dist/models/AppResourceView.js +74 -0
- package/dist/models/AppResourcesView.d.ts +54 -0
- package/dist/models/AppResourcesView.js +64 -0
- package/dist/models/AppToolsResponse.d.ts +14 -0
- package/dist/models/AppToolsResponse.js +4 -0
- package/dist/models/AppView.d.ts +42 -0
- package/dist/models/AppView.js +14 -0
- package/dist/models/ArtifactVersionResponse.d.ts +94 -0
- package/dist/models/ArtifactVersionResponse.js +88 -0
- package/dist/models/AttachedAgent.d.ts +44 -0
- package/dist/models/AttachedAgent.js +56 -0
- package/dist/models/Auth.d.ts +30 -0
- package/dist/models/Auth.js +58 -0
- package/dist/models/BindCustomApiBody.d.ts +32 -0
- package/dist/models/BindCustomApiBody.js +50 -0
- package/dist/models/ConversationArtifact.d.ts +14 -0
- package/dist/models/ConversationArtifact.js +10 -0
- package/dist/models/CustomApi.d.ts +102 -0
- package/dist/models/CustomApi.js +98 -0
- package/dist/models/CustomApiBasicAuth.d.ts +51 -0
- package/dist/models/CustomApiBasicAuth.js +65 -0
- package/dist/models/CustomApiBearerAuth.d.ts +45 -0
- package/dist/models/CustomApiBearerAuth.js +61 -0
- package/dist/models/CustomApiCreate.d.ts +57 -0
- package/dist/models/CustomApiCreate.js +63 -0
- package/dist/models/CustomApiHeader.d.ts +44 -0
- package/dist/models/CustomApiHeader.js +54 -0
- package/dist/models/CustomApiHeadersAuth.d.ts +46 -0
- package/dist/models/CustomApiHeadersAuth.js +62 -0
- package/dist/models/CustomApiList.d.ts +64 -0
- package/dist/models/CustomApiList.js +71 -0
- package/dist/models/CustomApiName.d.ts +44 -0
- package/dist/models/CustomApiName.js +56 -0
- package/dist/models/CustomApiUpdate.d.ts +58 -0
- package/dist/models/CustomApiUpdate.js +57 -0
- package/dist/models/CustomApiUpdateAuth.d.ts +30 -0
- package/dist/models/CustomApiUpdateAuth.js +58 -0
- package/dist/models/ErrorDetailItem.d.ts +5 -0
- package/dist/models/ListModels403Response.d.ts +23 -0
- package/dist/models/ListModels403Response.js +51 -0
- package/dist/models/ModelEndpointView.d.ts +38 -0
- package/dist/models/ModelEndpointView.js +52 -0
- package/dist/models/ModelView.d.ts +69 -0
- package/dist/models/ModelView.js +63 -0
- package/dist/models/ModelsResponse.d.ts +33 -0
- package/dist/models/ModelsResponse.js +51 -0
- package/dist/models/SettingsIssueView.d.ts +44 -0
- package/dist/models/SettingsIssueView.js +58 -0
- package/dist/models/VersionCommitBody.d.ts +44 -0
- package/dist/models/VersionCommitBody.js +58 -0
- package/dist/models/VersionUploadUrlBody.d.ts +32 -0
- package/dist/models/VersionUploadUrlBody.js +50 -0
- package/dist/models/index.d.ts +28 -0
- package/dist/models/index.js +28 -0
- package/package.json +15 -2
- package/src/apis/AgentConversationsApi.ts +172 -3
- package/src/apis/AgentsApi.ts +242 -7
- package/src/apis/AppsApi.ts +174 -3
- package/src/apis/ArtifactsApi.ts +144 -0
- package/src/apis/ClarifyApi.ts +3 -3
- package/src/apis/CollectionsApi.ts +3 -3
- package/src/apis/ConversationsApi.ts +3 -3
- package/src/apis/CronsApi.ts +3 -3
- package/src/apis/CustomAPIsApi.ts +471 -0
- package/src/apis/MessagesApi.ts +3 -3
- package/src/apis/ModelsApi.ts +70 -0
- package/src/apis/QueueApi.ts +3 -3
- package/src/apis/ResponsesApi.ts +3 -3
- package/src/apis/SkillsApi.ts +3 -3
- package/src/apis/index.ts +2 -0
- package/src/compose/agent.ts +254 -0
- package/src/compose/builtins.ts +19 -0
- package/src/compose/deploy.ts +168 -0
- package/src/compose/errors.ts +66 -0
- package/src/compose/events.ts +122 -0
- package/src/compose/fingerprint.ts +74 -0
- package/src/compose/index.ts +13 -0
- package/src/compose/run.ts +601 -0
- package/src/compose/runState.ts +95 -0
- package/src/compose/settingsTransport.ts +299 -0
- package/src/compose/tools.ts +42 -0
- package/src/compose/transport.ts +48 -0
- package/src/models/AgentChannelRef.ts +2 -1
- package/src/models/AgentConversationDetail.ts +21 -5
- package/src/models/AgentConversationView.ts +15 -8
- package/src/models/AgentCreate.ts +8 -0
- package/src/models/AgentCustomApiList.ts +74 -0
- package/src/models/AgentResource.ts +16 -0
- package/src/models/AgentSettingsResponse.ts +99 -0
- package/src/models/AgentUpdate.ts +8 -0
- package/src/models/AppAccountView.ts +143 -0
- package/src/models/AppAccountsView.ts +118 -0
- package/src/models/AppResource.ts +48 -0
- package/src/models/AppResourceCheckView.ts +117 -0
- package/src/models/AppResourceView.ts +120 -0
- package/src/models/AppResourcesView.ts +102 -0
- package/src/models/AppToolsResponse.ts +16 -0
- package/src/models/AppView.ts +56 -0
- package/src/models/ArtifactVersionResponse.ts +155 -0
- package/src/models/AttachedAgent.ts +83 -0
- package/src/models/Auth.ts +84 -0
- package/src/models/BindCustomApiBody.ts +66 -0
- package/src/models/ConversationArtifact.ts +19 -0
- package/src/models/CustomApi.ts +175 -0
- package/src/models/CustomApiBasicAuth.ts +94 -0
- package/src/models/CustomApiBearerAuth.ts +85 -0
- package/src/models/CustomApiCreate.ts +108 -0
- package/src/models/CustomApiHeader.ts +82 -0
- package/src/models/CustomApiHeadersAuth.ts +93 -0
- package/src/models/CustomApiList.ts +120 -0
- package/src/models/CustomApiName.ts +83 -0
- package/src/models/CustomApiUpdate.ts +106 -0
- package/src/models/CustomApiUpdateAuth.ts +84 -0
- package/src/models/ErrorDetailItem.ts +5 -0
- package/src/models/ListModels403Response.ts +73 -0
- package/src/models/ModelEndpointView.ts +74 -0
- package/src/models/ModelView.ts +122 -0
- package/src/models/ModelsResponse.ts +74 -0
- package/src/models/SettingsIssueView.ts +84 -0
- package/src/models/VersionCommitBody.ts +84 -0
- package/src/models/VersionUploadUrlBody.ts +66 -0
- package/src/models/index.ts +28 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Internal: built-in tool names and checks shared by tools.ts and agent.ts. Not re-exported from index.ts. */
|
|
2
|
+
import { UserError } from "./errors.js";
|
|
3
|
+
/** The agent.json builtin_tools switches, in schema order. */
|
|
4
|
+
export const BUILTIN_NAMES = ["web_search", "sandbox", "code_mode", "todo", "schedules", "clarify", "subagents"];
|
|
5
|
+
/** The server's web search rules, for options built by hand (`{ name: "web_search", options }`). */
|
|
6
|
+
export function checkWebSearchOptions(options) {
|
|
7
|
+
const keys = Object.keys(options);
|
|
8
|
+
for (const k of keys) {
|
|
9
|
+
if (k !== "allowed_domains" && k !== "blocked_domains")
|
|
10
|
+
throw new UserError(`tools.web_search: unknown option ${JSON.stringify(k)}`);
|
|
11
|
+
const v = options[k];
|
|
12
|
+
if (!Array.isArray(v) || v.length === 0 || v.some((d) => typeof d !== "string")) {
|
|
13
|
+
throw new UserError(`tools.web_search.${k}: must be a non-empty list of domains`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (keys.length > 1)
|
|
17
|
+
throw new UserError("tools.web_search: give allowed_domains or blocked_domains, not both");
|
|
18
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** deploy()/undeploy(): upsert a hosted agent by name, with fingerprint-based drift detection, and the deploy cache. */
|
|
2
|
+
import type { Configuration } from "../runtime.js";
|
|
3
|
+
import type { Agent } from "./agent.js";
|
|
4
|
+
import type { Transport } from "./transport.js";
|
|
5
|
+
export interface Deployment {
|
|
6
|
+
agentId: string;
|
|
7
|
+
action: "created" | "updated" | "unchanged";
|
|
8
|
+
}
|
|
9
|
+
/** Set (or clear, with null) the client used when deploy/undeploy/run get no client. */
|
|
10
|
+
export declare function setDefaultClient(config: Configuration | null): void;
|
|
11
|
+
export declare function getDefaultClient(): Configuration | null;
|
|
12
|
+
export declare function resolveTransport(client?: Configuration, transport?: Transport): Transport;
|
|
13
|
+
export declare function deploy(agent: Agent, opts?: {
|
|
14
|
+
client?: Configuration;
|
|
15
|
+
transport?: Transport;
|
|
16
|
+
strict?: boolean;
|
|
17
|
+
adopt?: string;
|
|
18
|
+
}): Promise<Deployment>;
|
|
19
|
+
export declare function undeploy(name: string, opts?: {
|
|
20
|
+
client?: Configuration;
|
|
21
|
+
transport?: Transport;
|
|
22
|
+
}): Promise<boolean>;
|
|
23
|
+
/** Drop cached deployments of agent `name` (any owner); called by deploy() and undeploy(). */
|
|
24
|
+
export declare function forget(name: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* The server id for `agent`, deploying it first unless this owner already deployed this exact definition.
|
|
27
|
+
* Keyed by name, as the server is: a variant with the same name redeploys, chained after any in-flight deploy so
|
|
28
|
+
* deploys of one name never overlap.
|
|
29
|
+
*/
|
|
30
|
+
export declare function agentIdFor(agent: Agent, transport: Transport, owner: object): Promise<string>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { DriftError, DuplicateAgentsError, UserError } from "./errors.js";
|
|
2
|
+
import { canonicalJson, fingerprintBody, settingsFingerprint } from "./fingerprint.js";
|
|
3
|
+
import { SettingsTransport } from "./settingsTransport.js";
|
|
4
|
+
let defaultClient = null;
|
|
5
|
+
/** Set (or clear, with null) the client used when deploy/undeploy/run get no client. */
|
|
6
|
+
export function setDefaultClient(config) {
|
|
7
|
+
defaultClient = config;
|
|
8
|
+
}
|
|
9
|
+
export function getDefaultClient() {
|
|
10
|
+
return defaultClient;
|
|
11
|
+
}
|
|
12
|
+
export function resolveTransport(client, transport) {
|
|
13
|
+
if (transport)
|
|
14
|
+
return transport;
|
|
15
|
+
const config = client !== null && client !== void 0 ? client : defaultClient;
|
|
16
|
+
if (!config) {
|
|
17
|
+
throw new UserError("no client configured: pass client (or transport) or call setDefaultClient(config)");
|
|
18
|
+
}
|
|
19
|
+
return new SettingsTransport(config);
|
|
20
|
+
}
|
|
21
|
+
function storedHash(remote) {
|
|
22
|
+
const metadata = remote.settings["metadata"];
|
|
23
|
+
const h = metadata ? metadata.sdk_hash : undefined;
|
|
24
|
+
return typeof h === "string" ? h : undefined;
|
|
25
|
+
}
|
|
26
|
+
function changedFields(remote, agent) {
|
|
27
|
+
const want = fingerprintBody(agent.toSettings());
|
|
28
|
+
const have = fingerprintBody(remote.settings);
|
|
29
|
+
const keys = [];
|
|
30
|
+
const all = new Set([...Object.keys(want), ...Object.keys(have)]);
|
|
31
|
+
all.forEach((k) => {
|
|
32
|
+
// like Python's want.get(k) != have.get(k): a missing key equals null
|
|
33
|
+
const a = canonicalJson(want[k] === undefined ? null : want[k]);
|
|
34
|
+
const b = canonicalJson(have[k] === undefined ? null : have[k]);
|
|
35
|
+
if (a !== b)
|
|
36
|
+
keys.push(k);
|
|
37
|
+
});
|
|
38
|
+
keys.sort();
|
|
39
|
+
if (remote.instructions !== agent.instructions)
|
|
40
|
+
keys.push("instructions");
|
|
41
|
+
return keys;
|
|
42
|
+
}
|
|
43
|
+
async function update(transport, remote, agent, strict) {
|
|
44
|
+
const stored = storedHash(remote);
|
|
45
|
+
if (stored !== undefined && settingsFingerprint(remote.instructions, remote.settings) !== stored) {
|
|
46
|
+
const changed = changedFields(remote, agent);
|
|
47
|
+
if (strict)
|
|
48
|
+
throw new DriftError(changed);
|
|
49
|
+
console.warn(`agent "${agent.name}" (${remote.agentId}) was edited outside the SDK; overwriting fields: ${changed.join(", ")}`);
|
|
50
|
+
}
|
|
51
|
+
else if (stored === agent.specHash()) {
|
|
52
|
+
return { agentId: remote.agentId, action: "unchanged" };
|
|
53
|
+
}
|
|
54
|
+
await transport.updateAgent(remote.agentId, agent);
|
|
55
|
+
return { agentId: remote.agentId, action: "updated" };
|
|
56
|
+
}
|
|
57
|
+
async function deployWith(agent, transport, strict, adopt) {
|
|
58
|
+
const found = await transport.findAgents(agent.name);
|
|
59
|
+
if (adopt !== undefined) {
|
|
60
|
+
const target = await transport.readAgent(adopt);
|
|
61
|
+
const metadata = target.settings["metadata"];
|
|
62
|
+
const owner = metadata ? metadata.sdk_name : undefined;
|
|
63
|
+
if (owner !== undefined && owner !== null && owner !== agent.name) {
|
|
64
|
+
throw new UserError(`agent ${adopt} is managed by SDK agent "${owner}", cannot adopt it as "${agent.name}"`);
|
|
65
|
+
}
|
|
66
|
+
const others = found.filter((r) => r.agentId !== adopt).map((r) => r.agentId);
|
|
67
|
+
if (others.length) {
|
|
68
|
+
throw new UserError(`cannot adopt ${adopt}: agent "${agent.name}" is already deployed as ${others.join(", ")}`);
|
|
69
|
+
}
|
|
70
|
+
await transport.updateAgent(adopt, agent);
|
|
71
|
+
return { agentId: adopt, action: "updated" };
|
|
72
|
+
}
|
|
73
|
+
if (found.length > 1)
|
|
74
|
+
throw new DuplicateAgentsError(found.map((r) => r.agentId));
|
|
75
|
+
if (found.length === 0)
|
|
76
|
+
return { agentId: (await transport.createAgent(agent)).agentId, action: "created" };
|
|
77
|
+
return update(transport, found[0], agent, strict);
|
|
78
|
+
}
|
|
79
|
+
export async function deploy(agent, opts = {}) {
|
|
80
|
+
const transport = resolveTransport(opts.client, opts.transport);
|
|
81
|
+
forget(agent.name); // this deploy may replace what cached runs of the name point at
|
|
82
|
+
return serialized(agent.name, () => { var _a; return deployWith(agent, transport, (_a = opts.strict) !== null && _a !== void 0 ? _a : false, opts.adopt); });
|
|
83
|
+
}
|
|
84
|
+
export async function undeploy(name, opts = {}) {
|
|
85
|
+
const transport = resolveTransport(opts.client, opts.transport);
|
|
86
|
+
forget(name);
|
|
87
|
+
return serialized(name, async () => {
|
|
88
|
+
const found = await transport.findAgents(name);
|
|
89
|
+
for (const remote of found)
|
|
90
|
+
await transport.deleteAgent(remote.agentId);
|
|
91
|
+
return found.length > 0;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
// Per-name tail: every deploy/undeploy of a name (cached or direct) queues behind the previous one, so they never
|
|
95
|
+
// overlap. forget() does not touch it.
|
|
96
|
+
const tails = new Map();
|
|
97
|
+
function serialized(name, fn) {
|
|
98
|
+
const prev = tails.get(name);
|
|
99
|
+
const p = prev ? prev.then(fn) : fn();
|
|
100
|
+
const tail = p.then(() => undefined, () => undefined);
|
|
101
|
+
tails.set(name, tail);
|
|
102
|
+
tail.then(() => {
|
|
103
|
+
if (tails.get(name) === tail)
|
|
104
|
+
tails.delete(name);
|
|
105
|
+
});
|
|
106
|
+
return p;
|
|
107
|
+
}
|
|
108
|
+
const cache = new Map();
|
|
109
|
+
/** Drop cached deployments of agent `name` (any owner); called by deploy() and undeploy(). */
|
|
110
|
+
export function forget(name) {
|
|
111
|
+
cache.delete(name);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
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 the same name redeploys, chained after any in-flight deploy so
|
|
116
|
+
* deploys of one name never overlap.
|
|
117
|
+
*/
|
|
118
|
+
export function agentIdFor(agent, transport, owner) {
|
|
119
|
+
const hash = agent.specHash();
|
|
120
|
+
let owners = cache.get(agent.name);
|
|
121
|
+
if (!owners) {
|
|
122
|
+
owners = new WeakMap();
|
|
123
|
+
cache.set(agent.name, owners);
|
|
124
|
+
}
|
|
125
|
+
const prev = owners.get(owner);
|
|
126
|
+
if (prev && prev.hash === hash)
|
|
127
|
+
return prev.id;
|
|
128
|
+
const id = serialized(agent.name, () => deployWith(agent, transport, false)).then((d) => d.agentId);
|
|
129
|
+
const entry = { hash, id };
|
|
130
|
+
owners.set(owner, entry);
|
|
131
|
+
const slot = owners;
|
|
132
|
+
id.catch(() => {
|
|
133
|
+
if (slot.get(owner) === entry)
|
|
134
|
+
slot.delete(owner);
|
|
135
|
+
});
|
|
136
|
+
return id;
|
|
137
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Error hierarchy for the compose layer. */
|
|
2
|
+
export declare class AgentsError extends Error {
|
|
3
|
+
constructor(message?: string);
|
|
4
|
+
}
|
|
5
|
+
/** The caller supplied an invalid value. */
|
|
6
|
+
export declare class UserError extends AgentsError {
|
|
7
|
+
/** The server's `{ code, path, message }` issues when it rejected agent settings. */
|
|
8
|
+
readonly issues: Array<{
|
|
9
|
+
code?: string;
|
|
10
|
+
path?: string;
|
|
11
|
+
message?: string;
|
|
12
|
+
}>;
|
|
13
|
+
constructor(message?: string, issues?: Array<{
|
|
14
|
+
code?: string;
|
|
15
|
+
path?: string;
|
|
16
|
+
message?: string;
|
|
17
|
+
}>);
|
|
18
|
+
}
|
|
19
|
+
export declare class ModelBehaviorError extends AgentsError {
|
|
20
|
+
}
|
|
21
|
+
export declare class MaxTurnsExceededError extends AgentsError {
|
|
22
|
+
}
|
|
23
|
+
export declare class MaxTokensExceededError extends AgentsError {
|
|
24
|
+
}
|
|
25
|
+
export declare class MaxToolCallsExceededError extends AgentsError {
|
|
26
|
+
}
|
|
27
|
+
/** The agent has not been deployed. */
|
|
28
|
+
export declare class NotDeployedError extends AgentsError {
|
|
29
|
+
}
|
|
30
|
+
/** A feature the SDK does not support yet. */
|
|
31
|
+
export declare class NotSupportedError extends AgentsError {
|
|
32
|
+
}
|
|
33
|
+
export declare class RunError extends AgentsError {
|
|
34
|
+
readonly code: string;
|
|
35
|
+
constructor(code: string, message: string);
|
|
36
|
+
}
|
|
37
|
+
export declare class DriftError extends AgentsError {
|
|
38
|
+
readonly changed: string[];
|
|
39
|
+
constructor(changed: string[]);
|
|
40
|
+
}
|
|
41
|
+
export declare class DuplicateAgentsError extends AgentsError {
|
|
42
|
+
readonly agentIds: string[];
|
|
43
|
+
constructor(agentIds: string[]);
|
|
44
|
+
}
|
|
45
|
+
export declare class NotSupportedByServerError extends AgentsError {
|
|
46
|
+
readonly features: string[];
|
|
47
|
+
constructor(features: string[]);
|
|
48
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Error hierarchy for the compose layer. */
|
|
2
|
+
export class AgentsError extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
6
|
+
this.name = new.target.name;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** The caller supplied an invalid value. */
|
|
10
|
+
export class UserError extends AgentsError {
|
|
11
|
+
constructor(message, issues = []) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.issues = issues;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class ModelBehaviorError extends AgentsError {
|
|
17
|
+
}
|
|
18
|
+
export class MaxTurnsExceededError extends AgentsError {
|
|
19
|
+
}
|
|
20
|
+
export class MaxTokensExceededError extends AgentsError {
|
|
21
|
+
}
|
|
22
|
+
export class MaxToolCallsExceededError extends AgentsError {
|
|
23
|
+
}
|
|
24
|
+
/** The agent has not been deployed. */
|
|
25
|
+
export class NotDeployedError extends AgentsError {
|
|
26
|
+
}
|
|
27
|
+
/** A feature the SDK does not support yet. */
|
|
28
|
+
export class NotSupportedError extends AgentsError {
|
|
29
|
+
}
|
|
30
|
+
export class RunError extends AgentsError {
|
|
31
|
+
constructor(code, message) {
|
|
32
|
+
super(`${code}: ${message}`);
|
|
33
|
+
this.code = code;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export class DriftError extends AgentsError {
|
|
37
|
+
constructor(changed) {
|
|
38
|
+
super("deployed agent drifted: " + changed.join(", "));
|
|
39
|
+
this.changed = changed.slice();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export class DuplicateAgentsError extends AgentsError {
|
|
43
|
+
constructor(agentIds) {
|
|
44
|
+
super("duplicate agents: " + agentIds.join(", "));
|
|
45
|
+
this.agentIds = agentIds.slice();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export class NotSupportedByServerError extends AgentsError {
|
|
49
|
+
constructor(features) {
|
|
50
|
+
super("server does not support: " + features.join(", "));
|
|
51
|
+
this.features = features.slice();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** Stream event model for `/v1/responses` UI-message-stream chunks. */
|
|
2
|
+
export interface ClarifyQuestion {
|
|
3
|
+
id: string;
|
|
4
|
+
prompt: string;
|
|
5
|
+
inputType?: string;
|
|
6
|
+
choices?: string[];
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
export interface FunctionCallRequest {
|
|
10
|
+
callId: string;
|
|
11
|
+
name: string;
|
|
12
|
+
arguments: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
export type Event = {
|
|
15
|
+
kind: "text_start";
|
|
16
|
+
id: string;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "text_delta";
|
|
19
|
+
delta: string;
|
|
20
|
+
id?: string;
|
|
21
|
+
} | {
|
|
22
|
+
kind: "text_end";
|
|
23
|
+
id: string;
|
|
24
|
+
} | {
|
|
25
|
+
kind: "reasoning_delta";
|
|
26
|
+
delta: string;
|
|
27
|
+
} | {
|
|
28
|
+
kind: "tool_called";
|
|
29
|
+
callId: string;
|
|
30
|
+
name: string;
|
|
31
|
+
arguments: unknown;
|
|
32
|
+
} | {
|
|
33
|
+
kind: "tool_output";
|
|
34
|
+
callId: string;
|
|
35
|
+
output: unknown;
|
|
36
|
+
} | {
|
|
37
|
+
kind: "clarify_requested";
|
|
38
|
+
requestId: string;
|
|
39
|
+
questions: ClarifyQuestion[];
|
|
40
|
+
} | {
|
|
41
|
+
kind: "function_calls_requested";
|
|
42
|
+
requestId: string;
|
|
43
|
+
calls: FunctionCallRequest[];
|
|
44
|
+
expiresAt?: string;
|
|
45
|
+
} | {
|
|
46
|
+
kind: "stopped";
|
|
47
|
+
reason: string;
|
|
48
|
+
} | {
|
|
49
|
+
kind: "turn_finished";
|
|
50
|
+
reason: string;
|
|
51
|
+
} | {
|
|
52
|
+
kind: "turn_failed";
|
|
53
|
+
code: string;
|
|
54
|
+
message: string;
|
|
55
|
+
} | {
|
|
56
|
+
kind: "unknown";
|
|
57
|
+
chunk: Record<string, unknown>;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Map one stream chunk to an Event; `null` for chunks the runner ignores.
|
|
61
|
+
* Never throws: malformed chunks degrade to `{ kind: "unknown", chunk }`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function fromUiChunk(chunk: unknown): Event | null;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/** Stream event model for `/v1/responses` UI-message-stream chunks. */
|
|
2
|
+
const IGNORED = ["start", "start-step", "finish-step", "tool-input-start", "tool-input-delta"];
|
|
3
|
+
function isObject(v) {
|
|
4
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
5
|
+
}
|
|
6
|
+
function str(v, fallback) {
|
|
7
|
+
return typeof v === "string" && v !== "" ? v : fallback;
|
|
8
|
+
}
|
|
9
|
+
function text(v) {
|
|
10
|
+
return typeof v === "string" ? v : "";
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Map one stream chunk to an Event; `null` for chunks the runner ignores.
|
|
14
|
+
* Never throws: malformed chunks degrade to `{ kind: "unknown", chunk }`.
|
|
15
|
+
*/
|
|
16
|
+
export function fromUiChunk(chunk) {
|
|
17
|
+
if (!isObject(chunk))
|
|
18
|
+
return { kind: "unknown", chunk: chunk };
|
|
19
|
+
try {
|
|
20
|
+
return map(chunk);
|
|
21
|
+
}
|
|
22
|
+
catch (_a) {
|
|
23
|
+
return { kind: "unknown", chunk };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function map(chunk) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
const type = chunk["type"];
|
|
29
|
+
const data = isObject(chunk["data"]) ? chunk["data"] : {};
|
|
30
|
+
if (typeof type === "string" && IGNORED.indexOf(type) !== -1)
|
|
31
|
+
return null;
|
|
32
|
+
switch (type) {
|
|
33
|
+
case "text-start":
|
|
34
|
+
return { kind: "text_start", id: text(chunk["id"]) };
|
|
35
|
+
case "text-delta": {
|
|
36
|
+
const ev = { kind: "text_delta", delta: text(chunk["delta"]) };
|
|
37
|
+
if (typeof chunk["id"] === "string")
|
|
38
|
+
ev.id = chunk["id"];
|
|
39
|
+
return ev;
|
|
40
|
+
}
|
|
41
|
+
case "text-end":
|
|
42
|
+
return { kind: "text_end", id: text(chunk["id"]) };
|
|
43
|
+
case "reasoning-delta":
|
|
44
|
+
return { kind: "reasoning_delta", delta: text(chunk["delta"]) };
|
|
45
|
+
case "tool-input-available":
|
|
46
|
+
return {
|
|
47
|
+
kind: "tool_called",
|
|
48
|
+
callId: text(chunk["toolCallId"]),
|
|
49
|
+
name: text(chunk["toolName"]),
|
|
50
|
+
arguments: chunk["input"],
|
|
51
|
+
};
|
|
52
|
+
case "tool-output-available":
|
|
53
|
+
return { kind: "tool_output", callId: text(chunk["toolCallId"]), output: chunk["output"] };
|
|
54
|
+
case "data-clarify-request": {
|
|
55
|
+
const questions = (_a = data["questions"]) !== null && _a !== void 0 ? _a : [];
|
|
56
|
+
if (!Array.isArray(questions))
|
|
57
|
+
throw new TypeError("questions must be a list");
|
|
58
|
+
return {
|
|
59
|
+
kind: "clarify_requested",
|
|
60
|
+
requestId: str(data["requestId"], text(chunk["id"])),
|
|
61
|
+
questions: questions,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
case "data-function-call-request": {
|
|
65
|
+
const raw = (_b = data["calls"]) !== null && _b !== void 0 ? _b : [];
|
|
66
|
+
if (!Array.isArray(raw))
|
|
67
|
+
throw new TypeError("calls must be a list");
|
|
68
|
+
const calls = raw.map((c) => {
|
|
69
|
+
if (!isObject(c))
|
|
70
|
+
throw new TypeError("call must be an object");
|
|
71
|
+
const args = c["arguments"];
|
|
72
|
+
return {
|
|
73
|
+
callId: text(c["toolCallId"]),
|
|
74
|
+
name: text(c["name"]),
|
|
75
|
+
arguments: isObject(args) ? args : {},
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
const ev = {
|
|
79
|
+
kind: "function_calls_requested",
|
|
80
|
+
requestId: str(data["requestId"], text(chunk["id"])),
|
|
81
|
+
calls,
|
|
82
|
+
};
|
|
83
|
+
if (typeof data["expiresAt"] === "string")
|
|
84
|
+
ev.expiresAt = data["expiresAt"];
|
|
85
|
+
return ev;
|
|
86
|
+
}
|
|
87
|
+
case "data-stopped":
|
|
88
|
+
return { kind: "stopped", reason: str(data["reason"], "stopped") };
|
|
89
|
+
case "error":
|
|
90
|
+
return { kind: "turn_failed", code: str(chunk["code"], "turn_failed"), message: text(chunk["errorText"]) };
|
|
91
|
+
case "finish":
|
|
92
|
+
return { kind: "turn_finished", reason: str(chunk["finishReason"], "stop") };
|
|
93
|
+
default:
|
|
94
|
+
// data-output and data-output-error are unknown until structured output lands.
|
|
95
|
+
return { kind: "unknown", chunk };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Settings as fingerprinted: metadata keeps the user's keys but drops sdk_name/sdk_hash (and goes when empty). */
|
|
2
|
+
export declare function fingerprintBody(settings: Record<string, unknown>): Record<string, unknown>;
|
|
3
|
+
/** Canonical JSON: code-point-sorted keys, no spaces, ASCII-only strings, ECMAScript numbers. */
|
|
4
|
+
export declare function canonicalJson(value: unknown): string;
|
|
5
|
+
/** Hash of instructions + settings (minus metadata.sdk_*); the single source of truth for sdk_hash. */
|
|
6
|
+
export declare function settingsFingerprint(instructions: string, settings: Record<string, unknown>): string;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { UserError } from "./errors.js";
|
|
3
|
+
const SDK_KEYS = ["sdk_name", "sdk_hash"];
|
|
4
|
+
/** Settings as fingerprinted: metadata keeps the user's keys but drops sdk_name/sdk_hash (and goes when empty). */
|
|
5
|
+
export function fingerprintBody(settings) {
|
|
6
|
+
const body = {};
|
|
7
|
+
for (const key of Object.keys(settings)) {
|
|
8
|
+
if (key !== "metadata")
|
|
9
|
+
body[key] = settings[key];
|
|
10
|
+
}
|
|
11
|
+
const metadata = settings["metadata"];
|
|
12
|
+
if (metadata !== null && typeof metadata === "object" && !Array.isArray(metadata)) {
|
|
13
|
+
const user = {};
|
|
14
|
+
let any = false;
|
|
15
|
+
for (const key of Object.keys(metadata)) {
|
|
16
|
+
if (SDK_KEYS.indexOf(key) === -1) {
|
|
17
|
+
user[key] = metadata[key];
|
|
18
|
+
any = true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (any)
|
|
22
|
+
body["metadata"] = user;
|
|
23
|
+
}
|
|
24
|
+
else if (metadata !== undefined && metadata !== null) {
|
|
25
|
+
body["metadata"] = metadata;
|
|
26
|
+
}
|
|
27
|
+
return body;
|
|
28
|
+
}
|
|
29
|
+
function compareCodePoints(a, b) {
|
|
30
|
+
const x = Array.from(a);
|
|
31
|
+
const y = Array.from(b);
|
|
32
|
+
const n = Math.min(x.length, y.length);
|
|
33
|
+
for (let i = 0; i < n; i++) {
|
|
34
|
+
const d = x[i].codePointAt(0) - y[i].codePointAt(0);
|
|
35
|
+
if (d !== 0)
|
|
36
|
+
return d;
|
|
37
|
+
}
|
|
38
|
+
return x.length - y.length;
|
|
39
|
+
}
|
|
40
|
+
/** A string as Python's json.dumps(ensure_ascii=True) writes it. */
|
|
41
|
+
function quote(s) {
|
|
42
|
+
const json = JSON.stringify(s); // short escapes for control characters, \uXXXX (lowercase) for lone surrogates
|
|
43
|
+
let out = "";
|
|
44
|
+
for (let i = 0; i < json.length; i++) {
|
|
45
|
+
const c = json.charCodeAt(i);
|
|
46
|
+
out += c > 0x7e ? "\\u" + c.toString(16).padStart(4, "0") : json[i];
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
/** Canonical JSON: code-point-sorted keys, no spaces, ASCII-only strings, ECMAScript numbers. */
|
|
51
|
+
export function canonicalJson(value) {
|
|
52
|
+
if (value === null)
|
|
53
|
+
return "null";
|
|
54
|
+
if (value === true)
|
|
55
|
+
return "true";
|
|
56
|
+
if (value === false)
|
|
57
|
+
return "false";
|
|
58
|
+
if (typeof value === "number") {
|
|
59
|
+
if (!Number.isFinite(value))
|
|
60
|
+
throw new UserError("NaN and Infinity cannot be fingerprinted");
|
|
61
|
+
return Number.isInteger(value) ? BigInt(value).toString() : JSON.stringify(value);
|
|
62
|
+
}
|
|
63
|
+
if (typeof value === "string")
|
|
64
|
+
return quote(value);
|
|
65
|
+
if (Array.isArray(value))
|
|
66
|
+
return "[" + value.map((v) => canonicalJson(v)).join(",") + "]";
|
|
67
|
+
if (typeof value === "object" && value !== undefined) {
|
|
68
|
+
const obj = value;
|
|
69
|
+
const keys = Object.keys(obj).filter((k) => obj[k] !== undefined).sort(compareCodePoints);
|
|
70
|
+
return "{" + keys.map((k) => quote(k) + ":" + canonicalJson(obj[k])).join(",") + "}";
|
|
71
|
+
}
|
|
72
|
+
throw new UserError(`cannot fingerprint ${typeof value}`);
|
|
73
|
+
}
|
|
74
|
+
/** Hash of instructions + settings (minus metadata.sdk_*); the single source of truth for sdk_hash. */
|
|
75
|
+
export function settingsFingerprint(instructions, settings) {
|
|
76
|
+
const raw = canonicalJson({ instructions, settings: fingerprintBody(settings) });
|
|
77
|
+
return createHash("sha256").update(raw, "utf8").digest("hex");
|
|
78
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./errors.js";
|
|
2
|
+
export * from "./fingerprint.js";
|
|
3
|
+
export * from "./tools.js";
|
|
4
|
+
export * from "./agent.js";
|
|
5
|
+
export type { Event, ClarifyQuestion, FunctionCallRequest } from "./events.js";
|
|
6
|
+
export { SettingsTransport } from "./settingsTransport.js";
|
|
7
|
+
export type { RemoteAgent, SettingsWarning, TurnStream, Transport } from "./transport.js";
|
|
8
|
+
export { deploy, undeploy, setDefaultClient } from "./deploy.js";
|
|
9
|
+
export type { Deployment } from "./deploy.js";
|
|
10
|
+
export { run, RunResult, StreamedRunResult } from "./run.js";
|
|
11
|
+
export type { RunOptions, RunStreamEvent, ClarifyHandler } from "./run.js";
|
|
12
|
+
export { RunState } from "./runState.js";
|
|
13
|
+
export type { Interruption } from "./runState.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./errors.js";
|
|
2
|
+
export * from "./fingerprint.js";
|
|
3
|
+
export * from "./tools.js";
|
|
4
|
+
export * from "./agent.js";
|
|
5
|
+
export { SettingsTransport } from "./settingsTransport.js";
|
|
6
|
+
export { deploy, undeploy, setDefaultClient } from "./deploy.js";
|
|
7
|
+
export { run, RunResult, StreamedRunResult } from "./run.js";
|
|
8
|
+
export { RunState } from "./runState.js";
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/** run(): deploy the agent, drive one turn through a Transport, handle clarify questions, dropped streams and cancel. */
|
|
2
|
+
import type { Configuration } from "../runtime.js";
|
|
3
|
+
import type { Agent } from "./agent.js";
|
|
4
|
+
import type { ClarifyQuestion, Event } from "./events.js";
|
|
5
|
+
import { RunState } from "./runState.js";
|
|
6
|
+
import type { Interruption } from "./runState.js";
|
|
7
|
+
import type { Transport } from "./transport.js";
|
|
8
|
+
export type ClarifyHandler = (questions: ClarifyQuestion[]) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
9
|
+
export interface RunOptions {
|
|
10
|
+
client?: Configuration;
|
|
11
|
+
transport?: Transport;
|
|
12
|
+
/** Continue this conversation (a previous `result.conversationId`). */
|
|
13
|
+
conversationId?: string;
|
|
14
|
+
/** Aborting stops reading, tells the server to stop the turn, and resolves with `finalOutput` undefined. */
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
/** Answers clarify questions; without it a question ends the run with an interruption. */
|
|
17
|
+
onClarify?: ClarifyHandler;
|
|
18
|
+
/** Not supported: the server caps turns per agent; set `new Agent({ limits: { maxTurns } })`. */
|
|
19
|
+
maxTurns?: never;
|
|
20
|
+
}
|
|
21
|
+
export type RunStreamEvent = {
|
|
22
|
+
type: "raw_model_stream_event";
|
|
23
|
+
data: {
|
|
24
|
+
type: "output_text_delta" | "reasoning_delta";
|
|
25
|
+
delta: string;
|
|
26
|
+
};
|
|
27
|
+
} | {
|
|
28
|
+
type: "run_item_stream_event";
|
|
29
|
+
name: "tool_called" | "tool_output" | "message_output_created";
|
|
30
|
+
item: unknown;
|
|
31
|
+
};
|
|
32
|
+
interface Outcome {
|
|
33
|
+
finalOutput: string | undefined;
|
|
34
|
+
outputText: string;
|
|
35
|
+
newItems: Event[];
|
|
36
|
+
interruptions: Interruption[];
|
|
37
|
+
conversationId: string | undefined;
|
|
38
|
+
cancelled: boolean;
|
|
39
|
+
}
|
|
40
|
+
export declare class RunResult {
|
|
41
|
+
readonly finalOutput: string | undefined;
|
|
42
|
+
readonly outputText: string;
|
|
43
|
+
readonly newItems: Event[];
|
|
44
|
+
readonly interruptions: Interruption[];
|
|
45
|
+
readonly conversationId: string | undefined;
|
|
46
|
+
/** @internal */
|
|
47
|
+
constructor(outcome: Outcome);
|
|
48
|
+
/** A RunState to answer the interruptions and continue; throws UserError when the run has no conversation. */
|
|
49
|
+
get state(): RunState;
|
|
50
|
+
}
|
|
51
|
+
interface Prepared {
|
|
52
|
+
agent: Agent;
|
|
53
|
+
input: string | RunState;
|
|
54
|
+
opts: RunOptions;
|
|
55
|
+
transport: Transport;
|
|
56
|
+
owner: object;
|
|
57
|
+
}
|
|
58
|
+
/** Returned by `run(..., { stream: true })`. Iterate it once (or use `toTextStream()`); leaving early cancels. */
|
|
59
|
+
export declare class StreamedRunResult implements AsyncIterable<RunStreamEvent> {
|
|
60
|
+
/** Settles when the run ends; rejects with the run's error. */
|
|
61
|
+
readonly completed: Promise<void>;
|
|
62
|
+
finalOutput: string | undefined;
|
|
63
|
+
outputText: string;
|
|
64
|
+
newItems: Event[];
|
|
65
|
+
interruptions: Interruption[];
|
|
66
|
+
conversationId: string | undefined;
|
|
67
|
+
cancelled: boolean;
|
|
68
|
+
private readonly queue;
|
|
69
|
+
private waiters;
|
|
70
|
+
private done;
|
|
71
|
+
private failure;
|
|
72
|
+
private consumed;
|
|
73
|
+
private readonly controller;
|
|
74
|
+
/** @internal */
|
|
75
|
+
constructor(prepared: Prepared);
|
|
76
|
+
get state(): RunState;
|
|
77
|
+
private push;
|
|
78
|
+
private end;
|
|
79
|
+
private notify;
|
|
80
|
+
private claim;
|
|
81
|
+
/**
|
|
82
|
+
* The event iterator. Hand-written rather than an async generator: a generator's return() queues behind a pending
|
|
83
|
+
* next(), so leaving while the server is quiet would neither settle nor cancel the run until another event came.
|
|
84
|
+
*/
|
|
85
|
+
private events;
|
|
86
|
+
[Symbol.asyncIterator](): AsyncIterator<RunStreamEvent>;
|
|
87
|
+
/** The output text deltas as a ReadableStream; consumes this result's events. */
|
|
88
|
+
toTextStream(): ReadableStream<string>;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Run `agent` on `input` (a message, or a RunState holding answers), deploying it first if this owner has not
|
|
92
|
+
* deployed this exact definition. With `stream: true`, resolves at once with a StreamedRunResult.
|
|
93
|
+
*/
|
|
94
|
+
export declare function run(agent: Agent, input: string | RunState, opts: RunOptions & {
|
|
95
|
+
stream: true;
|
|
96
|
+
}): Promise<StreamedRunResult>;
|
|
97
|
+
export declare function run(agent: Agent, input: string | RunState, opts?: RunOptions & {
|
|
98
|
+
stream?: false;
|
|
99
|
+
}): Promise<RunResult>;
|
|
100
|
+
export {};
|