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,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 {};
|