sarvam-agents-client 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compat/core/agents.d.ts +53 -0
- package/dist/compat/core/agents.js +338 -0
- package/dist/compat/core/data.d.ts +10 -0
- package/dist/compat/core/data.js +275 -0
- package/dist/compat/core/errors.d.ts +37 -0
- package/dist/compat/core/errors.js +155 -0
- package/dist/compat/core/events.d.ts +107 -0
- package/dist/compat/core/events.js +160 -0
- package/dist/compat/core/files.d.ts +65 -0
- package/dist/compat/core/files.js +851 -0
- package/dist/compat/core/history.d.ts +9 -0
- package/dist/compat/core/history.js +112 -0
- package/dist/compat/core/http.d.ts +112 -0
- package/dist/compat/core/http.js +753 -0
- package/dist/compat/core/ids.d.ts +4 -0
- package/dist/compat/core/ids.js +36 -0
- package/dist/compat/core/index.d.ts +14 -0
- package/dist/compat/core/index.js +30 -0
- package/dist/compat/core/models.d.ts +20 -0
- package/dist/compat/core/models.js +75 -0
- package/dist/compat/core/paging.d.ts +14 -0
- package/dist/compat/core/paging.js +124 -0
- package/dist/compat/core/refusals.d.ts +9 -0
- package/dist/compat/core/refusals.js +25 -0
- package/dist/compat/core/sessions.d.ts +65 -0
- package/dist/compat/core/sessions.js +317 -0
- package/dist/compat/core/toolResults.d.ts +43 -0
- package/dist/compat/core/toolResults.js +208 -0
- package/dist/compat/core/turns.d.ts +104 -0
- package/dist/compat/core/turns.js +504 -0
- package/dist/compat/core/warnings.d.ts +6 -0
- package/dist/compat/core/warnings.js +26 -0
- package/dist/compat/index.d.ts +3 -0
- package/dist/compat/index.js +9 -0
- package/dist/compat/openai/client.d.ts +62 -0
- package/dist/compat/openai/client.js +108 -0
- package/dist/compat/openai/errors.d.ts +72 -0
- package/dist/compat/openai/errors.js +150 -0
- package/dist/compat/openai/index.d.ts +14 -0
- package/dist/compat/openai/index.js +42 -0
- package/dist/compat/openai/pages.d.ts +19 -0
- package/dist/compat/openai/pages.js +39 -0
- package/dist/compat/openai/resources/agents.d.ts +36 -0
- package/dist/compat/openai/resources/agents.js +549 -0
- package/dist/compat/openai/resources/events.d.ts +23 -0
- package/dist/compat/openai/resources/events.js +485 -0
- package/dist/compat/openai/resources/sessions.d.ts +33 -0
- package/dist/compat/openai/resources/sessions.js +283 -0
- package/dist/compat/openai/stream.d.ts +40 -0
- package/dist/compat/openai/stream.js +585 -0
- package/dist/compat/openai/types.d.ts +125 -0
- package/dist/compat/openai/types.js +98 -0
- package/dist/compose/agent.d.ts +2 -0
- package/dist/compose/agent.js +27 -0
- package/dist/compose/functionTool.d.ts +2 -0
- package/dist/compose/functionTool.js +46 -0
- package/dist/compose/output.d.ts +2 -0
- package/dist/compose/output.js +15 -7
- package/dist/esm/compat/core/agents.d.ts +53 -0
- package/dist/esm/compat/core/agents.js +334 -0
- package/dist/esm/compat/core/data.d.ts +10 -0
- package/dist/esm/compat/core/data.js +272 -0
- package/dist/esm/compat/core/errors.d.ts +37 -0
- package/dist/esm/compat/core/errors.js +146 -0
- package/dist/esm/compat/core/events.d.ts +107 -0
- package/dist/esm/compat/core/events.js +156 -0
- package/dist/esm/compat/core/files.d.ts +65 -0
- package/dist/esm/compat/core/files.js +829 -0
- package/dist/esm/compat/core/history.d.ts +9 -0
- package/dist/esm/compat/core/history.js +109 -0
- package/dist/esm/compat/core/http.d.ts +112 -0
- package/dist/esm/compat/core/http.js +746 -0
- package/dist/esm/compat/core/ids.d.ts +4 -0
- package/dist/esm/compat/core/ids.js +30 -0
- package/dist/esm/compat/core/index.d.ts +14 -0
- package/dist/esm/compat/core/index.js +14 -0
- package/dist/esm/compat/core/models.d.ts +20 -0
- package/dist/esm/compat/core/models.js +71 -0
- package/dist/esm/compat/core/paging.d.ts +14 -0
- package/dist/esm/compat/core/paging.js +118 -0
- package/dist/esm/compat/core/refusals.d.ts +9 -0
- package/dist/esm/compat/core/refusals.js +21 -0
- package/dist/esm/compat/core/sessions.d.ts +65 -0
- package/dist/esm/compat/core/sessions.js +312 -0
- package/dist/esm/compat/core/toolResults.d.ts +43 -0
- package/dist/esm/compat/core/toolResults.js +203 -0
- package/dist/esm/compat/core/turns.d.ts +104 -0
- package/dist/esm/compat/core/turns.js +497 -0
- package/dist/esm/compat/core/warnings.d.ts +6 -0
- package/dist/esm/compat/core/warnings.js +20 -0
- package/dist/esm/compat/index.d.ts +3 -0
- package/dist/esm/compat/index.js +3 -0
- package/dist/esm/compat/openai/client.d.ts +62 -0
- package/dist/esm/compat/openai/client.js +104 -0
- package/dist/esm/compat/openai/errors.d.ts +72 -0
- package/dist/esm/compat/openai/errors.js +130 -0
- package/dist/esm/compat/openai/index.d.ts +14 -0
- package/dist/esm/compat/openai/index.js +17 -0
- package/dist/esm/compat/openai/pages.d.ts +19 -0
- package/dist/esm/compat/openai/pages.js +35 -0
- package/dist/esm/compat/openai/resources/agents.d.ts +36 -0
- package/dist/esm/compat/openai/resources/agents.js +540 -0
- package/dist/esm/compat/openai/resources/events.d.ts +23 -0
- package/dist/esm/compat/openai/resources/events.js +479 -0
- package/dist/esm/compat/openai/resources/sessions.d.ts +33 -0
- package/dist/esm/compat/openai/resources/sessions.js +278 -0
- package/dist/esm/compat/openai/stream.d.ts +40 -0
- package/dist/esm/compat/openai/stream.js +579 -0
- package/dist/esm/compat/openai/types.d.ts +125 -0
- package/dist/esm/compat/openai/types.js +91 -0
- package/dist/esm/compose/agent.d.ts +2 -0
- package/dist/esm/compose/agent.js +28 -2
- package/dist/esm/compose/functionTool.d.ts +2 -0
- package/dist/esm/compose/functionTool.js +45 -0
- package/dist/esm/compose/output.d.ts +2 -0
- package/dist/esm/compose/output.js +14 -7
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -1
- package/package.json +53 -11
- package/src/compat/core/agents.ts +437 -0
- package/src/compat/core/data.ts +283 -0
- package/src/compat/core/errors.ts +162 -0
- package/src/compat/core/events.ts +198 -0
- package/src/compat/core/files.ts +913 -0
- package/src/compat/core/history.ts +116 -0
- package/src/compat/core/http.ts +827 -0
- package/src/compat/core/ids.ts +35 -0
- package/src/compat/core/index.ts +14 -0
- package/src/compat/core/models.ts +85 -0
- package/src/compat/core/paging.ts +119 -0
- package/src/compat/core/refusals.ts +31 -0
- package/src/compat/core/sessions.ts +358 -0
- package/src/compat/core/toolResults.ts +235 -0
- package/src/compat/core/turns.ts +622 -0
- package/src/compat/core/warnings.ts +23 -0
- package/src/compat/index.ts +3 -0
- package/src/compat/openai/client.ts +177 -0
- package/src/compat/openai/errors.ts +165 -0
- package/src/compat/openai/index.ts +65 -0
- package/src/compat/openai/pages.ts +55 -0
- package/src/compat/openai/resources/agents.ts +603 -0
- package/src/compat/openai/resources/events.ts +523 -0
- package/src/compat/openai/resources/sessions.ts +369 -0
- package/src/compat/openai/stream.ts +599 -0
- package/src/compat/openai/types.ts +217 -0
- package/src/compose/agent.ts +30 -3
- package/src/compose/functionTool.ts +44 -0
- package/src/compose/output.ts +14 -8
- package/src/index.ts +3 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Http } from "./http.js";
|
|
2
|
+
import { ModelResolver } from "./models.js";
|
|
3
|
+
export interface AgentSpec {
|
|
4
|
+
name: string;
|
|
5
|
+
instructions: string;
|
|
6
|
+
model?: string | null;
|
|
7
|
+
reasoningEffort?: string | null;
|
|
8
|
+
reasoningSummary?: string | null;
|
|
9
|
+
toolChoice?: string | null;
|
|
10
|
+
builtins?: Record<string, unknown> | null;
|
|
11
|
+
functions: Record<string, unknown>[];
|
|
12
|
+
outputSchema?: Record<string, unknown> | null;
|
|
13
|
+
outputSchemaName?: string | null;
|
|
14
|
+
metadata: Record<string, string>;
|
|
15
|
+
description?: string | null;
|
|
16
|
+
sarvam: Record<string, unknown>;
|
|
17
|
+
provider: string;
|
|
18
|
+
requestedModel?: string | null;
|
|
19
|
+
multiAgentEnabled?: boolean | null;
|
|
20
|
+
archived?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface AgentRecord {
|
|
23
|
+
id: string;
|
|
24
|
+
spec: AgentSpec;
|
|
25
|
+
version: number | null;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
archived: boolean;
|
|
28
|
+
sarvamModel: string | null;
|
|
29
|
+
rawSettings: Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
export declare class Agents {
|
|
32
|
+
private readonly http;
|
|
33
|
+
private readonly models;
|
|
34
|
+
private readonly transport;
|
|
35
|
+
private readonly api;
|
|
36
|
+
private readonly inlineInflight;
|
|
37
|
+
constructor(http: Http, models: ModelResolver);
|
|
38
|
+
private buildRaw;
|
|
39
|
+
create(spec: AgentSpec, opts?: {
|
|
40
|
+
pathOf?: (field: string) => string;
|
|
41
|
+
}): Promise<AgentRecord>;
|
|
42
|
+
retrieve(agentId: string): Promise<AgentRecord>;
|
|
43
|
+
update(agentId: string, change: (spec: AgentSpec) => AgentSpec, opts?: {
|
|
44
|
+
expectedVersion?: number;
|
|
45
|
+
pathOf?: (field: string) => string;
|
|
46
|
+
}): Promise<AgentRecord>;
|
|
47
|
+
list(offset?: number, limit?: number): Promise<[AgentRecord[], boolean]>;
|
|
48
|
+
delete(agentId: string): Promise<void>;
|
|
49
|
+
private findInlineByName;
|
|
50
|
+
ensureInline(spec: AgentSpec, opts?: {
|
|
51
|
+
pathOf?: (field: string) => string;
|
|
52
|
+
}): Promise<AgentRecord>;
|
|
53
|
+
}
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Agents = void 0;
|
|
4
|
+
/** Core Agents service: neutral AgentSpec <-> Panja agent.json, AGENT.md, and versions. */
|
|
5
|
+
const AgentsApi_js_1 = require("../../apis/AgentsApi.js");
|
|
6
|
+
const agent_js_1 = require("../../compose/agent.js");
|
|
7
|
+
const errors_js_1 = require("../../compose/errors.js");
|
|
8
|
+
const fingerprint_js_1 = require("../../compose/fingerprint.js");
|
|
9
|
+
const settingsTransport_js_1 = require("../../compose/settingsTransport.js");
|
|
10
|
+
const errors_js_2 = require("./errors.js");
|
|
11
|
+
const ids_js_1 = require("./ids.js");
|
|
12
|
+
const refusals_js_1 = require("./refusals.js");
|
|
13
|
+
const warnings_js_1 = require("./warnings.js");
|
|
14
|
+
const ALLOWED_SARVAM_KEYS = new Set([
|
|
15
|
+
"limits",
|
|
16
|
+
"webhooks",
|
|
17
|
+
"triggers",
|
|
18
|
+
"fallback",
|
|
19
|
+
"endpoint",
|
|
20
|
+
"temperature",
|
|
21
|
+
"top_p",
|
|
22
|
+
"max_output_tokens",
|
|
23
|
+
"function_timeout_seconds",
|
|
24
|
+
"output_schema",
|
|
25
|
+
"builtin_tools",
|
|
26
|
+
"skills",
|
|
27
|
+
"knowledge_bases",
|
|
28
|
+
"clarify",
|
|
29
|
+
"apps",
|
|
30
|
+
]);
|
|
31
|
+
function isObj(v) {
|
|
32
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
33
|
+
}
|
|
34
|
+
function clone(v) {
|
|
35
|
+
return JSON.parse(JSON.stringify(v));
|
|
36
|
+
}
|
|
37
|
+
function iso(v) {
|
|
38
|
+
if (v instanceof Date)
|
|
39
|
+
return v.toISOString();
|
|
40
|
+
if (typeof v === "string" && v)
|
|
41
|
+
return v;
|
|
42
|
+
return new Date().toISOString();
|
|
43
|
+
}
|
|
44
|
+
function mapUserError(err, pathOf) {
|
|
45
|
+
const msg = err.message;
|
|
46
|
+
const colon = msg.indexOf(":");
|
|
47
|
+
const prefix = colon !== -1 ? msg.slice(0, colon).trim() : "";
|
|
48
|
+
const param = prefix ? (pathOf ? pathOf(prefix) : prefix) : null;
|
|
49
|
+
return new errors_js_2.CoreAPIError(msg, { status: 400, code: "invalid_request_error", param });
|
|
50
|
+
}
|
|
51
|
+
function validateSarvamKeys(sarvam, provider) {
|
|
52
|
+
for (const k of Object.keys(sarvam)) {
|
|
53
|
+
if (!ALLOWED_SARVAM_KEYS.has(k)) {
|
|
54
|
+
(0, refusals_js_1.refuse)(provider, `sarvam_config.${k}`, {
|
|
55
|
+
reason: `unknown Sarvam extension key ${JSON.stringify(k)}`,
|
|
56
|
+
param: `sarvam_config.${k}`,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function specToSettings(spec, sarvamModel, baseSettings) {
|
|
62
|
+
var _a, _b, _c;
|
|
63
|
+
validateSarvamKeys((_a = spec.sarvam) !== null && _a !== void 0 ? _a : {}, spec.provider);
|
|
64
|
+
// Preserve unmapped settings & non-sdk_compat metadata from baseSettings.
|
|
65
|
+
const out = baseSettings ? clone(baseSettings) : {};
|
|
66
|
+
if (!("version" in out))
|
|
67
|
+
out["version"] = 1;
|
|
68
|
+
if (sarvamModel !== null)
|
|
69
|
+
out["model"] = sarvamModel;
|
|
70
|
+
else
|
|
71
|
+
delete out["model"];
|
|
72
|
+
if (spec.reasoningEffort !== undefined && spec.reasoningEffort !== null)
|
|
73
|
+
out["reasoning"] = spec.reasoningEffort;
|
|
74
|
+
else
|
|
75
|
+
delete out["reasoning"];
|
|
76
|
+
if (spec.toolChoice !== undefined && spec.toolChoice !== null)
|
|
77
|
+
out["tool_choice"] = spec.toolChoice;
|
|
78
|
+
else
|
|
79
|
+
delete out["tool_choice"];
|
|
80
|
+
if (spec.builtins !== undefined && spec.builtins !== null) {
|
|
81
|
+
const b = clone(spec.builtins);
|
|
82
|
+
if (spec.multiAgentEnabled !== undefined && spec.multiAgentEnabled !== null) {
|
|
83
|
+
b["subagents"] = spec.multiAgentEnabled;
|
|
84
|
+
}
|
|
85
|
+
out["builtin_tools"] = b;
|
|
86
|
+
}
|
|
87
|
+
else if (spec.multiAgentEnabled !== undefined && spec.multiAgentEnabled !== null) {
|
|
88
|
+
const existingB = isObj(out["builtin_tools"]) ? clone(out["builtin_tools"]) : {};
|
|
89
|
+
existingB["subagents"] = spec.multiAgentEnabled;
|
|
90
|
+
out["builtin_tools"] = existingB;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
delete out["builtin_tools"];
|
|
94
|
+
}
|
|
95
|
+
if (spec.functions.length > 0)
|
|
96
|
+
out["functions"] = clone(spec.functions);
|
|
97
|
+
else
|
|
98
|
+
delete out["functions"];
|
|
99
|
+
if (spec.outputSchema !== undefined && spec.outputSchema !== null)
|
|
100
|
+
out["output_schema"] = clone(spec.outputSchema);
|
|
101
|
+
else
|
|
102
|
+
delete out["output_schema"];
|
|
103
|
+
for (const [k, v] of Object.entries((_b = spec.sarvam) !== null && _b !== void 0 ? _b : {})) {
|
|
104
|
+
if (v === undefined)
|
|
105
|
+
continue;
|
|
106
|
+
if (v === null) {
|
|
107
|
+
delete out[k];
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (k === "builtin_tools" && isObj(v)) {
|
|
111
|
+
const existing = isObj(out["builtin_tools"]) ? clone(out["builtin_tools"]) : {};
|
|
112
|
+
Object.assign(existing, clone(v));
|
|
113
|
+
out["builtin_tools"] = existing;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
out[k] = clone(v);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const compatMeta = {
|
|
120
|
+
provider: spec.provider,
|
|
121
|
+
metadata: { ...((_c = spec.metadata) !== null && _c !== void 0 ? _c : {}) },
|
|
122
|
+
archived: Boolean(spec.archived),
|
|
123
|
+
};
|
|
124
|
+
if (spec.description !== undefined && spec.description !== null)
|
|
125
|
+
compatMeta["description"] = spec.description;
|
|
126
|
+
if (spec.requestedModel !== undefined && spec.requestedModel !== null)
|
|
127
|
+
compatMeta["requested_model"] = spec.requestedModel;
|
|
128
|
+
if (spec.reasoningSummary !== undefined && spec.reasoningSummary !== null)
|
|
129
|
+
compatMeta["reasoning_summary"] = spec.reasoningSummary;
|
|
130
|
+
if (spec.outputSchemaName !== undefined && spec.outputSchemaName !== null)
|
|
131
|
+
compatMeta["output_schema_name"] = spec.outputSchemaName;
|
|
132
|
+
const existingMeta = isObj(out["metadata"]) ? clone(out["metadata"]) : {};
|
|
133
|
+
delete existingMeta["sdk_name"];
|
|
134
|
+
delete existingMeta["sdk_hash"];
|
|
135
|
+
existingMeta["sdk_compat"] = compatMeta;
|
|
136
|
+
out["metadata"] = existingMeta;
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
function settingsToRecord(id, name, instructions, settings, version, createdAt) {
|
|
140
|
+
const rawMeta = isObj(settings["metadata"]) ? settings["metadata"] : {};
|
|
141
|
+
const compat = isObj(rawMeta["sdk_compat"]) ? rawMeta["sdk_compat"] : {};
|
|
142
|
+
const userMetaRaw = isObj(compat["metadata"]) ? compat["metadata"] : {};
|
|
143
|
+
const userMeta = {};
|
|
144
|
+
for (const [k, v] of Object.entries(userMetaRaw))
|
|
145
|
+
userMeta[k] = String(v);
|
|
146
|
+
const sarvamModel = typeof settings["model"] === "string" ? settings["model"] : null;
|
|
147
|
+
const requestedModel = typeof compat["requested_model"] === "string" ? compat["requested_model"] : sarvamModel;
|
|
148
|
+
const builtins = isObj(settings["builtin_tools"]) ? clone(settings["builtin_tools"]) : null;
|
|
149
|
+
const multiAgentEnabled = builtins && "subagents" in builtins ? Boolean(builtins["subagents"]) : null;
|
|
150
|
+
const archived = Boolean(compat["archived"]);
|
|
151
|
+
const spec = {
|
|
152
|
+
name,
|
|
153
|
+
instructions,
|
|
154
|
+
model: requestedModel,
|
|
155
|
+
reasoningEffort: typeof settings["reasoning"] === "string" ? settings["reasoning"] : null,
|
|
156
|
+
reasoningSummary: typeof compat["reasoning_summary"] === "string" ? compat["reasoning_summary"] : null,
|
|
157
|
+
toolChoice: typeof settings["tool_choice"] === "string" ? settings["tool_choice"] : null,
|
|
158
|
+
builtins,
|
|
159
|
+
functions: Array.isArray(settings["functions"]) ? clone(settings["functions"]) : [],
|
|
160
|
+
outputSchema: isObj(settings["output_schema"]) ? clone(settings["output_schema"]) : null,
|
|
161
|
+
outputSchemaName: typeof compat["output_schema_name"] === "string" ? compat["output_schema_name"] : null,
|
|
162
|
+
metadata: userMeta,
|
|
163
|
+
description: typeof compat["description"] === "string" ? compat["description"] : null,
|
|
164
|
+
sarvam: {},
|
|
165
|
+
provider: typeof compat["provider"] === "string" ? compat["provider"] : "openai",
|
|
166
|
+
requestedModel,
|
|
167
|
+
multiAgentEnabled,
|
|
168
|
+
archived,
|
|
169
|
+
};
|
|
170
|
+
return { id, spec, version, createdAt, archived, sarvamModel, rawSettings: clone(settings) };
|
|
171
|
+
}
|
|
172
|
+
class Agents {
|
|
173
|
+
constructor(http, models) {
|
|
174
|
+
this.http = http;
|
|
175
|
+
this.models = models;
|
|
176
|
+
this.inlineInflight = new Map();
|
|
177
|
+
this.transport = new settingsTransport_js_1.SettingsTransport(http.sdkConfig);
|
|
178
|
+
this.api = new AgentsApi_js_1.AgentsApi(http.sdkConfig);
|
|
179
|
+
}
|
|
180
|
+
async buildRaw(spec, pathOf, baseSettings) {
|
|
181
|
+
const resolved = await this.models.resolve(spec.model);
|
|
182
|
+
const effective = clone(spec);
|
|
183
|
+
if (!effective.requestedModel)
|
|
184
|
+
effective.requestedModel = resolved.requested;
|
|
185
|
+
const settings = specToSettings(effective, resolved.sarvamId, baseSettings);
|
|
186
|
+
try {
|
|
187
|
+
return { agent: (0, agent_js_1.rawAgent)(effective.name, effective.instructions, settings), sarvamModel: resolved.sarvamId };
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
if (err instanceof errors_js_1.UserError)
|
|
191
|
+
throw mapUserError(err, pathOf);
|
|
192
|
+
throw err;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async create(spec, opts = {}) {
|
|
196
|
+
var _a;
|
|
197
|
+
const { agent } = await this.buildRaw(spec, opts.pathOf);
|
|
198
|
+
try {
|
|
199
|
+
const remote = await this.http.call(() => this.transport.createAgent(agent), { idempotent: false });
|
|
200
|
+
return settingsToRecord(remote.agentId, remote.name, remote.instructions, remote.settings, (_a = remote.liveVersion) !== null && _a !== void 0 ? _a : null, iso(remote.createdAt));
|
|
201
|
+
}
|
|
202
|
+
catch (err) {
|
|
203
|
+
if (err instanceof errors_js_1.UserError)
|
|
204
|
+
throw mapUserError(err, opts.pathOf);
|
|
205
|
+
if (err instanceof errors_js_1.NotSupportedByServerError) {
|
|
206
|
+
throw new errors_js_2.CoreAPIError(err.message, { status: 400, code: "unsupported_by_sarvam" });
|
|
207
|
+
}
|
|
208
|
+
throw err;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async retrieve(agentId) {
|
|
212
|
+
var _a;
|
|
213
|
+
const [resource, instr] = await Promise.all([
|
|
214
|
+
this.http.call(() => this.api.getAgent({ agentId }), { idempotent: true }),
|
|
215
|
+
this.http.call(() => this.api.getInstructions({ agentId }), { idempotent: true }),
|
|
216
|
+
]);
|
|
217
|
+
let settings = isObj(resource.settings) ? { ...resource.settings } : {};
|
|
218
|
+
if (Object.keys(settings).length === 0) {
|
|
219
|
+
try {
|
|
220
|
+
const env = await this.http.call(() => this.api.getAgentSettings({ agentId }), { idempotent: true });
|
|
221
|
+
settings = isObj(env.settings) ? { ...env.settings } : {};
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
if (!(err instanceof errors_js_2.CoreAPIError && err.status === 404))
|
|
225
|
+
throw err;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return settingsToRecord(resource.id, resource.name, instr.data, settings, (_a = resource.liveVersion) !== null && _a !== void 0 ? _a : null, iso(resource.createdAt));
|
|
229
|
+
}
|
|
230
|
+
async update(agentId, change, opts = {}) {
|
|
231
|
+
var _a;
|
|
232
|
+
const current = await this.retrieve(agentId);
|
|
233
|
+
if (current.archived) {
|
|
234
|
+
throw new errors_js_2.CoreAPIError(`Cannot update archived agent ${agentId}.`, {
|
|
235
|
+
status: 409,
|
|
236
|
+
code: "agent_archived",
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
if (opts.expectedVersion !== undefined) {
|
|
240
|
+
(0, warnings_js_1.warnOnce)("version_check_not_atomic", "Expected-version check on agent update is not atomic on Sarvam yet; concurrent writers are last-write-wins.");
|
|
241
|
+
if (current.version !== opts.expectedVersion) {
|
|
242
|
+
throw new errors_js_2.CoreAPIError(`Agent ${agentId} is at version ${current.version}, expected ${opts.expectedVersion}`, { status: 409, code: "version_conflict" });
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const updatedSpec = change(clone(current.spec));
|
|
246
|
+
const { agent } = await this.buildRaw(updatedSpec, opts.pathOf, current.rawSettings);
|
|
247
|
+
const currentHash = (0, fingerprint_js_1.settingsFingerprint)(current.spec.instructions, current.rawSettings);
|
|
248
|
+
if (updatedSpec.name === current.spec.name && agent.specHash() === currentHash) {
|
|
249
|
+
return current;
|
|
250
|
+
}
|
|
251
|
+
try {
|
|
252
|
+
const remote = await this.http.call(() => this.transport.updateAgent(agentId, agent), { idempotent: false });
|
|
253
|
+
return settingsToRecord(remote.agentId, remote.name, remote.instructions, remote.settings, (_a = remote.liveVersion) !== null && _a !== void 0 ? _a : null, current.createdAt);
|
|
254
|
+
}
|
|
255
|
+
catch (err) {
|
|
256
|
+
if (err instanceof errors_js_1.UserError)
|
|
257
|
+
throw mapUserError(err, opts.pathOf);
|
|
258
|
+
if (err instanceof errors_js_1.NotSupportedByServerError) {
|
|
259
|
+
throw new errors_js_2.CoreAPIError(err.message, { status: 400, code: "unsupported_by_sarvam" });
|
|
260
|
+
}
|
|
261
|
+
throw err;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
async list(offset = 0, limit = 20) {
|
|
265
|
+
var _a;
|
|
266
|
+
const resp = await this.http.call(() => this.api.listAgents({ limit, offset }), { idempotent: true });
|
|
267
|
+
const records = ((_a = resp.data) !== null && _a !== void 0 ? _a : []).map((item) => {
|
|
268
|
+
var _a;
|
|
269
|
+
const instrRaw = item["instructions"];
|
|
270
|
+
return settingsToRecord(item.id, item.name, typeof instrRaw === "string" ? instrRaw : "", isObj(item.settings) ? { ...item.settings } : {}, (_a = item.liveVersion) !== null && _a !== void 0 ? _a : null, iso(item.createdAt));
|
|
271
|
+
});
|
|
272
|
+
return [records, Boolean(resp.hasMore)];
|
|
273
|
+
}
|
|
274
|
+
async delete(agentId) {
|
|
275
|
+
await this.http.call(() => this.transport.deleteAgent(agentId), { idempotent: true });
|
|
276
|
+
}
|
|
277
|
+
async findInlineByName(name) {
|
|
278
|
+
var _a, _b;
|
|
279
|
+
const matches = [];
|
|
280
|
+
let offset = 0;
|
|
281
|
+
for (;;) {
|
|
282
|
+
const off = offset;
|
|
283
|
+
const page = await this.http.call(() => this.api.listAgents({ limit: 100, offset: off }), { idempotent: true });
|
|
284
|
+
const items = (_a = page.data) !== null && _a !== void 0 ? _a : [];
|
|
285
|
+
for (const item of items) {
|
|
286
|
+
const settings = isObj(item.settings) ? { ...item.settings } : {};
|
|
287
|
+
const meta = isObj(settings["metadata"]) ? settings["metadata"] : {};
|
|
288
|
+
const sdkName = typeof meta["sdk_name"] === "string" ? meta["sdk_name"] : null;
|
|
289
|
+
if (item.name === name || sdkName === name) {
|
|
290
|
+
const instrRaw = item["instructions"];
|
|
291
|
+
matches.push({
|
|
292
|
+
id: item.id,
|
|
293
|
+
name: item.name,
|
|
294
|
+
instructions: typeof instrRaw === "string" ? instrRaw : "",
|
|
295
|
+
settings,
|
|
296
|
+
version: (_b = item.liveVersion) !== null && _b !== void 0 ? _b : null,
|
|
297
|
+
createdAt: iso(item.createdAt),
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (items.length === 0 || !page.hasMore)
|
|
302
|
+
break;
|
|
303
|
+
offset += items.length;
|
|
304
|
+
}
|
|
305
|
+
if (matches.length === 0)
|
|
306
|
+
return null;
|
|
307
|
+
matches.sort((a, b) => a.id.localeCompare(b.id));
|
|
308
|
+
const chosen = matches[0];
|
|
309
|
+
return settingsToRecord(chosen.id, chosen.name, chosen.instructions, chosen.settings, chosen.version, chosen.createdAt);
|
|
310
|
+
}
|
|
311
|
+
async ensureInline(spec, opts = {}) {
|
|
312
|
+
const resolved = await this.models.resolve(spec.model);
|
|
313
|
+
const temp = clone(spec);
|
|
314
|
+
if (!temp.requestedModel)
|
|
315
|
+
temp.requestedModel = resolved.requested;
|
|
316
|
+
const tempSettings = specToSettings(temp, resolved.sarvamId);
|
|
317
|
+
const fp = (0, fingerprint_js_1.settingsFingerprint)(temp.instructions, tempSettings);
|
|
318
|
+
temp.name = (0, ids_js_1.inlineAgentName)(fp);
|
|
319
|
+
const key = temp.name;
|
|
320
|
+
const inflight = this.inlineInflight.get(key);
|
|
321
|
+
if (inflight)
|
|
322
|
+
return inflight;
|
|
323
|
+
const promise = (async () => {
|
|
324
|
+
const existing = await this.findInlineByName(key);
|
|
325
|
+
if (existing)
|
|
326
|
+
return existing;
|
|
327
|
+
return this.create(temp, opts);
|
|
328
|
+
})();
|
|
329
|
+
this.inlineInflight.set(key, promise);
|
|
330
|
+
try {
|
|
331
|
+
return await promise;
|
|
332
|
+
}
|
|
333
|
+
finally {
|
|
334
|
+
this.inlineInflight.delete(key);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
exports.Agents = Agents;
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REFUSALS = void 0;
|
|
4
|
+
exports.REFUSALS = [
|
|
5
|
+
{
|
|
6
|
+
"provider": "openai",
|
|
7
|
+
"path": "environment.type=self_hosted",
|
|
8
|
+
"param": "environment.type",
|
|
9
|
+
"reason": "Sarvam runs agents in a managed sandbox only",
|
|
10
|
+
"hint": "Use environment={'type': 'openai_hosted'} (sandbox on) or {'type': 'none'} (sandbox off).",
|
|
11
|
+
"needs": null,
|
|
12
|
+
"feature": "openai.environment.self_hosted"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"provider": "openai",
|
|
16
|
+
"path": "environment.vault_ids",
|
|
17
|
+
"param": "environment.vault_ids",
|
|
18
|
+
"reason": "OpenAI vaults are not supported",
|
|
19
|
+
"hint": "Configure agent apps or custom APIs via sarvam_config={'apps': [...]}.",
|
|
20
|
+
"needs": null,
|
|
21
|
+
"feature": "openai.environment.vault_ids"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"provider": "openai",
|
|
25
|
+
"path": "environment.spend_control",
|
|
26
|
+
"param": "environment.spend_control",
|
|
27
|
+
"reason": "spend_control is not supported",
|
|
28
|
+
"hint": "Use sarvam_config={'limits': {'max_turns': ..., 'max_tokens_per_turn': ...}} instead.",
|
|
29
|
+
"needs": null,
|
|
30
|
+
"feature": "openai.environment.spend_control"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"provider": "openai",
|
|
34
|
+
"path": "environment.contradicts_agent",
|
|
35
|
+
"param": "environment.type",
|
|
36
|
+
"reason": "sandbox setting is configured per agent on Sarvam and contradicts the existing agent",
|
|
37
|
+
"hint": "Match the agent's sandbox setting or update the agent first.",
|
|
38
|
+
"needs": null,
|
|
39
|
+
"feature": "openai.environment.contradicts_agent"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"provider": "openai",
|
|
43
|
+
"path": "tools[type=mcp]",
|
|
44
|
+
"param": "tools",
|
|
45
|
+
"reason": "ad-hoc MCP servers by URL are not supported yet",
|
|
46
|
+
"hint": "Bind installed apps via sarvam_config={'apps': [...]} instead.",
|
|
47
|
+
"needs": "panja: MCP by URL (harness phase 4)",
|
|
48
|
+
"feature": "openai.tools.mcp"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"provider": "openai",
|
|
52
|
+
"path": "tools[type=computer_use]",
|
|
53
|
+
"param": "tools",
|
|
54
|
+
"reason": "computer use is not supported",
|
|
55
|
+
"hint": "",
|
|
56
|
+
"needs": null,
|
|
57
|
+
"feature": "openai.tools.computer_use"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"provider": "openai",
|
|
61
|
+
"path": "tools[type=web_search].options",
|
|
62
|
+
"param": "tools",
|
|
63
|
+
"reason": "only domain filters (allowed_domains or blocked_domains) are supported on web_search",
|
|
64
|
+
"hint": "Pass filters={'allowed_domains': [...]} without extra web_search options.",
|
|
65
|
+
"needs": null,
|
|
66
|
+
"feature": "openai.tools.web_search.options"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"provider": "openai",
|
|
70
|
+
"path": "tools[type=programmatic_tool_calling].no_sandbox",
|
|
71
|
+
"param": "tools",
|
|
72
|
+
"reason": "programmatic_tool_calling requires the managed sandbox",
|
|
73
|
+
"hint": "Use environment={'type': 'openai_hosted'} when programmatic_tool_calling is enabled.",
|
|
74
|
+
"needs": null,
|
|
75
|
+
"feature": "openai.tools.programmatic_tool_calling.no_sandbox"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"provider": "openai",
|
|
79
|
+
"path": "multi_agent.max_concurrent_subagents",
|
|
80
|
+
"param": "multi_agent.max_concurrent_subagents",
|
|
81
|
+
"reason": "sub-agent concurrency cap is not configurable yet",
|
|
82
|
+
"hint": "Omit max_concurrent_subagents to use the platform default.",
|
|
83
|
+
"needs": "panja: sub-agent concurrency (harness phase 9)",
|
|
84
|
+
"feature": "openai.multi_agent.max_concurrent_subagents"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"provider": "openai",
|
|
88
|
+
"path": "text.verbosity",
|
|
89
|
+
"param": "text.verbosity",
|
|
90
|
+
"reason": "text verbosity is not configurable",
|
|
91
|
+
"hint": "Omit text.verbosity to use the default.",
|
|
92
|
+
"needs": null,
|
|
93
|
+
"feature": "openai.text.verbosity"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"provider": "openai",
|
|
97
|
+
"path": "service_tier",
|
|
98
|
+
"param": "service_tier",
|
|
99
|
+
"reason": "service_tier is not supported",
|
|
100
|
+
"hint": "Omit service_tier to use the default.",
|
|
101
|
+
"needs": null,
|
|
102
|
+
"feature": "openai.service_tier"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"provider": "openai",
|
|
106
|
+
"path": "experimental",
|
|
107
|
+
"param": "experimental",
|
|
108
|
+
"reason": "experimental provider flags are not supported",
|
|
109
|
+
"hint": "",
|
|
110
|
+
"needs": null,
|
|
111
|
+
"feature": "openai.experimental"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"provider": "openai",
|
|
115
|
+
"path": "compaction",
|
|
116
|
+
"param": "compaction",
|
|
117
|
+
"reason": "compaction is automatic and cannot be customized",
|
|
118
|
+
"hint": "Omit compaction to use automatic compaction.",
|
|
119
|
+
"needs": null,
|
|
120
|
+
"feature": "openai.compaction"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"provider": "openai",
|
|
124
|
+
"path": "tool_choice",
|
|
125
|
+
"param": "tool_choice",
|
|
126
|
+
"reason": "only 'auto' and 'none' are supported for tool_choice",
|
|
127
|
+
"hint": "Use tool_choice='auto' or tool_choice='none'.",
|
|
128
|
+
"needs": null,
|
|
129
|
+
"feature": "openai.tool_choice"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"provider": "openai",
|
|
133
|
+
"path": "model",
|
|
134
|
+
"param": "model",
|
|
135
|
+
"reason": "unknown model is not in the Sarvam model catalog",
|
|
136
|
+
"hint": "Pass a Sarvam model ID, configure model_map / SARVAM_MODEL_MAP, or disable strict_models.",
|
|
137
|
+
"needs": null,
|
|
138
|
+
"feature": "openai.model.unknown"
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"provider": "openai",
|
|
142
|
+
"path": "sessions.update.model",
|
|
143
|
+
"param": "model",
|
|
144
|
+
"reason": "per-session model overrides are not supported yet",
|
|
145
|
+
"hint": "Update the agent instead.",
|
|
146
|
+
"needs": "panja: per-conversation overrides (harness phase 11)",
|
|
147
|
+
"feature": "openai.sessions.update.overrides"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"provider": "openai",
|
|
151
|
+
"path": "sessions.update.reasoning",
|
|
152
|
+
"param": "reasoning",
|
|
153
|
+
"reason": "per-session reasoning overrides are not supported yet",
|
|
154
|
+
"hint": "Update the agent instead.",
|
|
155
|
+
"needs": "panja: per-conversation overrides (harness phase 11)",
|
|
156
|
+
"feature": "openai.sessions.update.overrides"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"provider": "openai",
|
|
160
|
+
"path": "sessions.update.tools",
|
|
161
|
+
"param": "tools",
|
|
162
|
+
"reason": "per-session tool overrides are not supported yet",
|
|
163
|
+
"hint": "Update the agent instead.",
|
|
164
|
+
"needs": "panja: per-conversation overrides (harness phase 11)",
|
|
165
|
+
"feature": "openai.sessions.update.overrides"
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"provider": "openai",
|
|
169
|
+
"path": "sessions.update.agent",
|
|
170
|
+
"param": "agent",
|
|
171
|
+
"reason": "per-session agent overrides are not supported yet",
|
|
172
|
+
"hint": "Update the agent instead.",
|
|
173
|
+
"needs": "panja: per-conversation overrides (harness phase 11)",
|
|
174
|
+
"feature": "openai.sessions.update.overrides"
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
"provider": "openai",
|
|
178
|
+
"path": "sessions.create.pin_agent_version",
|
|
179
|
+
"param": "pin_agent_version",
|
|
180
|
+
"reason": "pinning a session to an agent configuration snapshot is not supported yet",
|
|
181
|
+
"hint": "",
|
|
182
|
+
"needs": "panja: session version pinning",
|
|
183
|
+
"feature": "openai.sessions.pin_version"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
"provider": "openai",
|
|
187
|
+
"path": "sessions.create.idempotency_key",
|
|
188
|
+
"param": "idempotency_key",
|
|
189
|
+
"reason": "idempotent session creation is not supported by Panja yet",
|
|
190
|
+
"hint": "Omit idempotencyKey / Idempotency-Key on sessions.create; Panja does not deduplicate POST /v1/conversations yet.",
|
|
191
|
+
"needs": "panja: Idempotency-Key on POST /v1/conversations",
|
|
192
|
+
"feature": "openai.sessions.create.idempotency_key"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"provider": "openai",
|
|
196
|
+
"path": "agents.create.idempotency_key",
|
|
197
|
+
"param": "idempotency_key",
|
|
198
|
+
"reason": "idempotent agent creation is not supported by Panja yet",
|
|
199
|
+
"hint": "Omit idempotencyKey / Idempotency-Key on agents.create; Panja does not deduplicate POST /v2/agents yet.",
|
|
200
|
+
"needs": "panja: Idempotency-Key on POST /v2/agents",
|
|
201
|
+
"feature": "openai.agents.create.idempotency_key"
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"provider": "openai",
|
|
205
|
+
"path": "input.input_image.detail",
|
|
206
|
+
"param": "input",
|
|
207
|
+
"reason": "input_image.detail is not supported on agent sessions",
|
|
208
|
+
"hint": "Omit detail on input_image blocks; Sarvam ignores image detail tiers.",
|
|
209
|
+
"needs": null,
|
|
210
|
+
"feature": "openai.input.image.detail"
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"provider": "openai",
|
|
214
|
+
"path": "beta.agents.environments",
|
|
215
|
+
"param": "beta.agents.environments",
|
|
216
|
+
"reason": "managed environments resource is not supported",
|
|
217
|
+
"hint": "Pass environment={'type': 'openai_hosted'} or {'type': 'none'} to sessions.create.",
|
|
218
|
+
"needs": null,
|
|
219
|
+
"feature": "openai.resource.environments"
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"provider": "openai",
|
|
223
|
+
"path": "beta.agents.templates",
|
|
224
|
+
"param": "beta.agents.templates",
|
|
225
|
+
"reason": "environment templates are not supported",
|
|
226
|
+
"hint": "",
|
|
227
|
+
"needs": null,
|
|
228
|
+
"feature": "openai.resource.templates"
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
"provider": "openai",
|
|
232
|
+
"path": "beta.agents.files",
|
|
233
|
+
"param": "beta.agents.files",
|
|
234
|
+
"reason": "agent files resource is not supported",
|
|
235
|
+
"hint": "",
|
|
236
|
+
"needs": null,
|
|
237
|
+
"feature": "openai.resource.files"
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
"provider": "openai",
|
|
241
|
+
"path": "beta.agents.vaults",
|
|
242
|
+
"param": "beta.agents.vaults",
|
|
243
|
+
"reason": "vaults are not supported",
|
|
244
|
+
"hint": "",
|
|
245
|
+
"needs": null,
|
|
246
|
+
"feature": "openai.resource.vaults"
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
"provider": "openai",
|
|
250
|
+
"path": "beta.agents.credentials",
|
|
251
|
+
"param": "beta.agents.credentials",
|
|
252
|
+
"reason": "credentials resource is not supported",
|
|
253
|
+
"hint": "",
|
|
254
|
+
"needs": null,
|
|
255
|
+
"feature": "openai.resource.credentials"
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
"provider": "openai",
|
|
259
|
+
"path": "beta.agents.sessions.traces",
|
|
260
|
+
"param": "beta.agents.sessions.traces",
|
|
261
|
+
"reason": "session traces resource is not supported",
|
|
262
|
+
"hint": "",
|
|
263
|
+
"needs": null,
|
|
264
|
+
"feature": "openai.resource.traces"
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
"provider": "openai",
|
|
268
|
+
"path": "extra_body",
|
|
269
|
+
"param": "extra_body",
|
|
270
|
+
"reason": "extra_body keys other than 'sarvam_config' are not supported",
|
|
271
|
+
"hint": "Pass Sarvam extensions under sarvam_config={...} or extra_body={'sarvam_config': {...}}.",
|
|
272
|
+
"needs": null,
|
|
273
|
+
"feature": "openai.extra_body"
|
|
274
|
+
}
|
|
275
|
+
];
|