sarvam-agents-client 0.1.2 → 0.2.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 +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 +40 -0
- package/dist/compose/agent.js +191 -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 +29 -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 +40 -0
- package/dist/esm/compose/agent.js +187 -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 +19 -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 +223 -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 +27 -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,48 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Sarvam Agents API
|
|
5
|
+
* Chat with a Sarvam agent, exchange files with it, and set it up (instructions, skills, knowledge bases, connectors, deploy) from your own code. Authenticate with a service token sent as a Bearer token, and send the header X-Panja-Origin: managed_agents on every request.
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 0.1.0
|
|
8
|
+
* Contact: support@sarvam.ai
|
|
9
|
+
*
|
|
10
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
11
|
+
* https://openapi-generator.tech
|
|
12
|
+
* Do not edit the class manually.
|
|
13
|
+
*/
|
|
14
|
+
import * as runtime from '../runtime.js';
|
|
15
|
+
import { ModelsResponseFromJSON, } from '../models/index.js';
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
export class ModelsApi extends runtime.BaseAPI {
|
|
20
|
+
/**
|
|
21
|
+
* List Models
|
|
22
|
+
*/
|
|
23
|
+
async listModelsRaw(initOverrides) {
|
|
24
|
+
const queryParameters = {};
|
|
25
|
+
const headerParameters = {};
|
|
26
|
+
if (this.configuration && this.configuration.accessToken) {
|
|
27
|
+
const token = this.configuration.accessToken;
|
|
28
|
+
const tokenString = await token("bearerAuth", []);
|
|
29
|
+
if (tokenString) {
|
|
30
|
+
headerParameters["Authorization"] = `Bearer ${tokenString}`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const response = await this.request({
|
|
34
|
+
path: `/v1/models`,
|
|
35
|
+
method: 'GET',
|
|
36
|
+
headers: headerParameters,
|
|
37
|
+
query: queryParameters,
|
|
38
|
+
}, initOverrides);
|
|
39
|
+
return new runtime.JSONApiResponse(response, (jsonValue) => ModelsResponseFromJSON(jsonValue));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* List Models
|
|
43
|
+
*/
|
|
44
|
+
async listModels(initOverrides) {
|
|
45
|
+
const response = await this.listModelsRaw(initOverrides);
|
|
46
|
+
return await response.value();
|
|
47
|
+
}
|
|
48
|
+
}
|
package/dist/esm/apis/index.d.ts
CHANGED
|
@@ -6,7 +6,9 @@ export * from './ClarifyApi.js';
|
|
|
6
6
|
export * from './CollectionsApi.js';
|
|
7
7
|
export * from './ConversationsApi.js';
|
|
8
8
|
export * from './CronsApi.js';
|
|
9
|
+
export * from './CustomAPIsApi.js';
|
|
9
10
|
export * from './MessagesApi.js';
|
|
11
|
+
export * from './ModelsApi.js';
|
|
10
12
|
export * from './QueueApi.js';
|
|
11
13
|
export * from './ResponsesApi.js';
|
|
12
14
|
export * from './SkillsApi.js';
|
package/dist/esm/apis/index.js
CHANGED
|
@@ -8,7 +8,9 @@ export * from './ClarifyApi.js';
|
|
|
8
8
|
export * from './CollectionsApi.js';
|
|
9
9
|
export * from './ConversationsApi.js';
|
|
10
10
|
export * from './CronsApi.js';
|
|
11
|
+
export * from './CustomAPIsApi.js';
|
|
11
12
|
export * from './MessagesApi.js';
|
|
13
|
+
export * from './ModelsApi.js';
|
|
12
14
|
export * from './QueueApi.js';
|
|
13
15
|
export * from './ResponsesApi.js';
|
|
14
16
|
export * from './SkillsApi.js';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BuiltinTool } from "./tools.js";
|
|
2
|
+
export interface ModelSettings {
|
|
3
|
+
temperature?: number;
|
|
4
|
+
topP?: number;
|
|
5
|
+
maxTokens?: number;
|
|
6
|
+
toolChoice?: "auto" | "none";
|
|
7
|
+
reasoning?: {
|
|
8
|
+
effort: "off" | "none" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface Limits {
|
|
12
|
+
maxTurns?: number;
|
|
13
|
+
maxToolCallsPerTurn?: number;
|
|
14
|
+
maxTokensPerTurn?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface AgentOptions {
|
|
17
|
+
name: string;
|
|
18
|
+
instructions?: string;
|
|
19
|
+
model?: string;
|
|
20
|
+
modelSettings?: ModelSettings;
|
|
21
|
+
fallbackModels?: string[];
|
|
22
|
+
tools?: BuiltinTool[];
|
|
23
|
+
limits?: Limits;
|
|
24
|
+
metadata?: Record<string, string>;
|
|
25
|
+
}
|
|
26
|
+
export declare class Agent {
|
|
27
|
+
readonly name: string;
|
|
28
|
+
readonly instructions: string;
|
|
29
|
+
readonly model?: string;
|
|
30
|
+
readonly modelSettings?: ModelSettings;
|
|
31
|
+
readonly fallbackModels?: string[];
|
|
32
|
+
readonly tools: readonly BuiltinTool[];
|
|
33
|
+
readonly limits?: Limits;
|
|
34
|
+
readonly metadata?: Record<string, string>;
|
|
35
|
+
constructor(rawOpts: AgentOptions);
|
|
36
|
+
private check;
|
|
37
|
+
private baseSettings;
|
|
38
|
+
specHash(): string;
|
|
39
|
+
toSettings(): Record<string, unknown>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { NotSupportedError, UserError } from "./errors.js";
|
|
2
|
+
import { settingsFingerprint } from "./fingerprint.js";
|
|
3
|
+
const SLUG = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
4
|
+
const REASONING = ["off", "none", "low", "medium", "high", "xhigh", "max"];
|
|
5
|
+
const TOOL_CHOICES = ["auto", "none"];
|
|
6
|
+
function deepFreeze(value) {
|
|
7
|
+
if (value !== null && typeof value === "object" && !Object.isFrozen(value)) {
|
|
8
|
+
Object.freeze(value);
|
|
9
|
+
for (const key of Object.keys(value))
|
|
10
|
+
deepFreeze(value[key]);
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
function clone(value) {
|
|
15
|
+
return value === undefined ? value : JSON.parse(JSON.stringify(value));
|
|
16
|
+
}
|
|
17
|
+
function isPositiveInt(n) {
|
|
18
|
+
return typeof n === "number" && Number.isInteger(n) && n >= 1;
|
|
19
|
+
}
|
|
20
|
+
function isFiniteNumber(n) {
|
|
21
|
+
return typeof n === "number" && Number.isFinite(n);
|
|
22
|
+
}
|
|
23
|
+
/** Runs on the raw options, before the JSON clone turns NaN/Infinity into null. */
|
|
24
|
+
function checkNumbers(opts) {
|
|
25
|
+
const ms = opts.modelSettings;
|
|
26
|
+
if (ms !== undefined && ms !== null) {
|
|
27
|
+
if (ms.temperature !== undefined && !(isFiniteNumber(ms.temperature) && ms.temperature >= 0 && ms.temperature <= 2)) {
|
|
28
|
+
throw new UserError("modelSettings.temperature: must be a number between 0 and 2");
|
|
29
|
+
}
|
|
30
|
+
if (ms.topP !== undefined && !(isFiniteNumber(ms.topP) && ms.topP > 0 && ms.topP <= 1)) {
|
|
31
|
+
throw new UserError("modelSettings.topP: must be a number > 0 and <= 1");
|
|
32
|
+
}
|
|
33
|
+
if (ms.maxTokens !== undefined && !isPositiveInt(ms.maxTokens)) {
|
|
34
|
+
throw new UserError("modelSettings.maxTokens: must be an integer >= 1");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const limits = opts.limits;
|
|
38
|
+
if (limits !== undefined && limits !== null) {
|
|
39
|
+
for (const key of ["maxTurns", "maxToolCallsPerTurn", "maxTokensPerTurn"]) {
|
|
40
|
+
if (limits[key] !== undefined && !isPositiveInt(limits[key])) {
|
|
41
|
+
throw new UserError(`limits.${key}: must be an integer >= 1`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Drops null-valued own keys (shallow copy); a non-object (null/undefined) becomes undefined. */
|
|
47
|
+
function dropNulls(value) {
|
|
48
|
+
if (value === null || value === undefined || typeof value !== "object")
|
|
49
|
+
return undefined;
|
|
50
|
+
const out = {};
|
|
51
|
+
for (const key of Object.keys(value)) {
|
|
52
|
+
const v = value[key];
|
|
53
|
+
if (v !== null && v !== undefined)
|
|
54
|
+
out[key] = v;
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
/** JS callers spreading JSON configs pass null for unset fields; null means unset everywhere (like Python's None). */
|
|
59
|
+
function normalize(raw) {
|
|
60
|
+
const opts = dropNulls(raw);
|
|
61
|
+
if (opts.modelSettings !== undefined)
|
|
62
|
+
opts.modelSettings = dropNulls(opts.modelSettings);
|
|
63
|
+
if (opts.limits !== undefined)
|
|
64
|
+
opts.limits = dropNulls(opts.limits);
|
|
65
|
+
return opts;
|
|
66
|
+
}
|
|
67
|
+
const LIMIT_KEYS = [
|
|
68
|
+
["maxTurns", "max_turns"],
|
|
69
|
+
["maxToolCallsPerTurn", "max_tool_calls_per_turn"],
|
|
70
|
+
["maxTokensPerTurn", "max_tokens_per_turn"],
|
|
71
|
+
];
|
|
72
|
+
export class Agent {
|
|
73
|
+
constructor(rawOpts) {
|
|
74
|
+
var _a, _b, _c;
|
|
75
|
+
const opts = normalize(rawOpts);
|
|
76
|
+
for (const tool of (_a = opts.tools) !== null && _a !== void 0 ? _a : []) {
|
|
77
|
+
if (tool instanceof Agent) {
|
|
78
|
+
throw new NotSupportedError("sub-agents in tools are not supported yet (field: tools)");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
checkNumbers(opts);
|
|
82
|
+
this.name = opts.name;
|
|
83
|
+
this.instructions = (_b = opts.instructions) !== null && _b !== void 0 ? _b : "";
|
|
84
|
+
this.model = opts.model;
|
|
85
|
+
this.modelSettings = clone(opts.modelSettings);
|
|
86
|
+
this.fallbackModels = clone(opts.fallbackModels);
|
|
87
|
+
this.tools = clone((_c = opts.tools) !== null && _c !== void 0 ? _c : []);
|
|
88
|
+
this.limits = clone(opts.limits);
|
|
89
|
+
this.metadata = clone(opts.metadata);
|
|
90
|
+
this.check();
|
|
91
|
+
deepFreeze(this);
|
|
92
|
+
}
|
|
93
|
+
check() {
|
|
94
|
+
if (typeof this.name !== "string" || !SLUG.test(this.name)) {
|
|
95
|
+
throw new UserError(`name: ${JSON.stringify(this.name)} must match ${SLUG.source}`);
|
|
96
|
+
}
|
|
97
|
+
const ms = this.modelSettings;
|
|
98
|
+
if (ms !== undefined) {
|
|
99
|
+
if (ms.reasoning !== undefined && REASONING.indexOf(ms.reasoning.effort) === -1) {
|
|
100
|
+
throw new UserError(`modelSettings.reasoning: ${JSON.stringify(ms.reasoning.effort)} must be one of ${REASONING.join(", ")}`);
|
|
101
|
+
}
|
|
102
|
+
if (ms.toolChoice !== undefined && TOOL_CHOICES.indexOf(ms.toolChoice) === -1) {
|
|
103
|
+
throw new UserError(`modelSettings.toolChoice: ${JSON.stringify(ms.toolChoice)} must be one of ${TOOL_CHOICES.join(", ")}`);
|
|
104
|
+
}
|
|
105
|
+
if (ms.temperature !== undefined && !(ms.temperature >= 0 && ms.temperature <= 2)) {
|
|
106
|
+
throw new UserError("modelSettings.temperature: must be between 0 and 2");
|
|
107
|
+
}
|
|
108
|
+
if (ms.topP !== undefined && !(ms.topP > 0 && ms.topP <= 1)) {
|
|
109
|
+
throw new UserError("modelSettings.topP: must be > 0 and <= 1");
|
|
110
|
+
}
|
|
111
|
+
if (ms.maxTokens !== undefined && !isPositiveInt(ms.maxTokens)) {
|
|
112
|
+
throw new UserError("modelSettings.maxTokens: must be an integer >= 1");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (this.limits !== undefined) {
|
|
116
|
+
for (const [key] of LIMIT_KEYS) {
|
|
117
|
+
const value = this.limits[key];
|
|
118
|
+
if (value !== undefined && !isPositiveInt(value)) {
|
|
119
|
+
throw new UserError(`limits.${key}: must be an integer >= 1`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (this.metadata !== undefined) {
|
|
124
|
+
const bad = Object.keys(this.metadata).filter((k) => k.indexOf("sdk_") === 0).sort();
|
|
125
|
+
if (bad.length > 0) {
|
|
126
|
+
throw new UserError(`metadata: keys starting with 'sdk_' are reserved (${bad.join(", ")})`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const names = this.tools.map((t) => t.name);
|
|
130
|
+
const dupes = Array.from(new Set(names.filter((n, i) => names.indexOf(n) !== i))).sort();
|
|
131
|
+
if (dupes.length > 0) {
|
|
132
|
+
throw new UserError(`tools: duplicate built-in tool(s): ${dupes.join(", ")}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
baseSettings() {
|
|
136
|
+
const out = { version: 1 };
|
|
137
|
+
if (this.model !== undefined)
|
|
138
|
+
out["model"] = this.model;
|
|
139
|
+
const ms = this.modelSettings;
|
|
140
|
+
if (ms !== undefined) {
|
|
141
|
+
if (ms.reasoning !== undefined)
|
|
142
|
+
out["reasoning"] = ms.reasoning.effort;
|
|
143
|
+
if (ms.temperature !== undefined)
|
|
144
|
+
out["temperature"] = ms.temperature;
|
|
145
|
+
if (ms.topP !== undefined)
|
|
146
|
+
out["top_p"] = ms.topP;
|
|
147
|
+
if (ms.maxTokens !== undefined)
|
|
148
|
+
out["max_output_tokens"] = ms.maxTokens;
|
|
149
|
+
if (ms.toolChoice !== undefined)
|
|
150
|
+
out["tool_choice"] = ms.toolChoice;
|
|
151
|
+
}
|
|
152
|
+
if (this.fallbackModels !== undefined && this.fallbackModels.length > 0) {
|
|
153
|
+
out["fallback"] = clone(this.fallbackModels);
|
|
154
|
+
}
|
|
155
|
+
if (this.limits !== undefined) {
|
|
156
|
+
const limits = {};
|
|
157
|
+
for (const [key, wire] of LIMIT_KEYS) {
|
|
158
|
+
const value = this.limits[key];
|
|
159
|
+
if (value !== undefined)
|
|
160
|
+
limits[wire] = value;
|
|
161
|
+
}
|
|
162
|
+
if (Object.keys(limits).length > 0)
|
|
163
|
+
out["limits"] = limits;
|
|
164
|
+
}
|
|
165
|
+
if (this.tools.length > 0) {
|
|
166
|
+
const tools = {};
|
|
167
|
+
for (const t of this.tools) {
|
|
168
|
+
tools[t.name] = t.options !== undefined && Object.keys(t.options).length > 0 ? clone(t.options) : true;
|
|
169
|
+
}
|
|
170
|
+
out["builtin_tools"] = tools;
|
|
171
|
+
}
|
|
172
|
+
return out;
|
|
173
|
+
}
|
|
174
|
+
specHash() {
|
|
175
|
+
const settings = this.baseSettings();
|
|
176
|
+
if (this.metadata !== undefined && Object.keys(this.metadata).length > 0) {
|
|
177
|
+
settings["metadata"] = { ...this.metadata };
|
|
178
|
+
}
|
|
179
|
+
return settingsFingerprint(this.instructions, settings);
|
|
180
|
+
}
|
|
181
|
+
toSettings() {
|
|
182
|
+
var _a;
|
|
183
|
+
const out = this.baseSettings();
|
|
184
|
+
out["metadata"] = { ...((_a = this.metadata) !== null && _a !== void 0 ? _a : {}), sdk_name: this.name, sdk_hash: this.specHash() };
|
|
185
|
+
return out;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -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;
|