cencori 1.9.0 → 1.10.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 +88 -0
- package/dist/agents/index.d.mts +433 -0
- package/dist/agents/index.d.ts +433 -0
- package/dist/agents/index.js +897 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/index.mjs +870 -0
- package/dist/agents/index.mjs.map +1 -0
- package/dist/react/index.d.mts +6 -6
- package/dist/react/index.d.ts +6 -6
- package/package.json +11 -3
|
@@ -0,0 +1,897 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __esm = (fn, res) => function __init() {
|
|
7
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
8
|
+
};
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
|
|
23
|
+
// src/agents-sdk/schema.ts
|
|
24
|
+
function isStandard(schema) {
|
|
25
|
+
return typeof schema === "object" && schema !== null && "~standard" in schema && typeof schema["~standard"]?.validate === "function";
|
|
26
|
+
}
|
|
27
|
+
function toJsonSchema(schema) {
|
|
28
|
+
if (!schema) return { type: "object", properties: {}, additionalProperties: false };
|
|
29
|
+
let json;
|
|
30
|
+
if (isStandard(schema)) {
|
|
31
|
+
const std = schema["~standard"];
|
|
32
|
+
if (std.jsonSchema) {
|
|
33
|
+
json = std.jsonSchema.input({ target: "draft-2020-12" });
|
|
34
|
+
} else if (typeof schema.toJSONSchema === "function") {
|
|
35
|
+
json = schema.toJSONSchema();
|
|
36
|
+
} else if (std.vendor === "zod" && schema._def?.typeName) {
|
|
37
|
+
json = zod3ToJsonSchema(schema);
|
|
38
|
+
} else {
|
|
39
|
+
throw new TypeError(
|
|
40
|
+
`This ${std.vendor} schema can't be converted to JSON Schema. Use zod 4, a library that implements Standard JSON Schema, or pass a JSON Schema object.`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
json = schema;
|
|
45
|
+
}
|
|
46
|
+
const { $schema: _ignored, ...rest } = json;
|
|
47
|
+
return rest;
|
|
48
|
+
}
|
|
49
|
+
async function validate(schema, value, what) {
|
|
50
|
+
if (!schema || !isStandard(schema)) return value;
|
|
51
|
+
const result = await schema["~standard"].validate(value);
|
|
52
|
+
if (result.issues) {
|
|
53
|
+
throw new SchemaValidationError(what, result.issues.map((issue) => ({
|
|
54
|
+
message: issue.message,
|
|
55
|
+
path: issue.path?.map((p) => String(typeof p === "object" && p !== null && "key" in p ? p.key : p)).join(".") || void 0
|
|
56
|
+
})));
|
|
57
|
+
}
|
|
58
|
+
return result.value;
|
|
59
|
+
}
|
|
60
|
+
function zod3ToJsonSchema(schema) {
|
|
61
|
+
const def = schema._def;
|
|
62
|
+
const describe = (json) => def.description ? { ...json, description: def.description } : json;
|
|
63
|
+
switch (def.typeName) {
|
|
64
|
+
case "ZodString":
|
|
65
|
+
return describe({ type: "string" });
|
|
66
|
+
case "ZodNumber": {
|
|
67
|
+
const checks = def.checks ?? [];
|
|
68
|
+
return describe({ type: checks.some((c) => c.kind === "int") ? "integer" : "number" });
|
|
69
|
+
}
|
|
70
|
+
case "ZodBigInt":
|
|
71
|
+
return describe({ type: "integer" });
|
|
72
|
+
case "ZodBoolean":
|
|
73
|
+
return describe({ type: "boolean" });
|
|
74
|
+
case "ZodNull":
|
|
75
|
+
return describe({ type: "null" });
|
|
76
|
+
case "ZodDate":
|
|
77
|
+
return describe({ type: "string", format: "date-time" });
|
|
78
|
+
case "ZodAny":
|
|
79
|
+
case "ZodUnknown":
|
|
80
|
+
return describe({});
|
|
81
|
+
case "ZodLiteral":
|
|
82
|
+
return describe({ const: def.value });
|
|
83
|
+
case "ZodEnum":
|
|
84
|
+
return describe({ type: "string", enum: def.values });
|
|
85
|
+
case "ZodNativeEnum":
|
|
86
|
+
return describe({ enum: Object.values(def.values) });
|
|
87
|
+
case "ZodArray":
|
|
88
|
+
return describe({ type: "array", items: zod3ToJsonSchema(def.type) });
|
|
89
|
+
case "ZodTuple":
|
|
90
|
+
return describe({ type: "array", prefixItems: def.items.map(zod3ToJsonSchema) });
|
|
91
|
+
case "ZodRecord":
|
|
92
|
+
return describe({ type: "object", additionalProperties: zod3ToJsonSchema(def.valueType) });
|
|
93
|
+
case "ZodUnion":
|
|
94
|
+
case "ZodDiscriminatedUnion": {
|
|
95
|
+
const options = Array.isArray(def.options) ? def.options : [...def.options.values()];
|
|
96
|
+
return describe({ anyOf: options.map(zod3ToJsonSchema) });
|
|
97
|
+
}
|
|
98
|
+
case "ZodNullable":
|
|
99
|
+
return describe({ anyOf: [zod3ToJsonSchema(def.innerType), { type: "null" }] });
|
|
100
|
+
case "ZodOptional":
|
|
101
|
+
case "ZodDefault":
|
|
102
|
+
case "ZodCatch":
|
|
103
|
+
case "ZodReadonly":
|
|
104
|
+
case "ZodBranded": {
|
|
105
|
+
const inner = zod3ToJsonSchema(def.innerType ?? def.type);
|
|
106
|
+
return def.description ? { ...inner, description: def.description } : inner;
|
|
107
|
+
}
|
|
108
|
+
case "ZodEffects":
|
|
109
|
+
return describe(zod3ToJsonSchema(def.schema));
|
|
110
|
+
case "ZodLazy":
|
|
111
|
+
return describe(zod3ToJsonSchema(def.getter()));
|
|
112
|
+
case "ZodObject": {
|
|
113
|
+
const shape = typeof def.shape === "function" ? def.shape() : def.shape;
|
|
114
|
+
const properties = {};
|
|
115
|
+
const required = [];
|
|
116
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
117
|
+
properties[key] = zod3ToJsonSchema(value);
|
|
118
|
+
const kind = value._def.typeName;
|
|
119
|
+
if (kind !== "ZodOptional" && kind !== "ZodDefault") required.push(key);
|
|
120
|
+
}
|
|
121
|
+
return describe({
|
|
122
|
+
type: "object",
|
|
123
|
+
properties,
|
|
124
|
+
...required.length ? { required } : {},
|
|
125
|
+
additionalProperties: def.unknownKeys === "passthrough"
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
default:
|
|
129
|
+
throw new TypeError(`zod type ${def.typeName} isn't supported in tool parameters. Use zod 4 or pass a JSON Schema object.`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
var SchemaValidationError;
|
|
133
|
+
var init_schema = __esm({
|
|
134
|
+
"src/agents-sdk/schema.ts"() {
|
|
135
|
+
"use strict";
|
|
136
|
+
SchemaValidationError = class extends Error {
|
|
137
|
+
constructor(what, issues) {
|
|
138
|
+
super(`${what}: ${issues.map((i) => i.path ? `${i.path}: ${i.message}` : i.message).join("; ")}`);
|
|
139
|
+
this.name = "SchemaValidationError";
|
|
140
|
+
this.issues = issues;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// src/agents-sdk/tool.ts
|
|
147
|
+
function stringify(value) {
|
|
148
|
+
if (typeof value === "string") return value;
|
|
149
|
+
if (value === void 0) return "";
|
|
150
|
+
try {
|
|
151
|
+
return JSON.stringify(value);
|
|
152
|
+
} catch {
|
|
153
|
+
return String(value);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function tool(options) {
|
|
157
|
+
if (!TOOL_NAME_PATTERN.test(options.name)) {
|
|
158
|
+
throw new TypeError(`Tool name "${options.name}" must be 1-64 letters, digits, _ or -.`);
|
|
159
|
+
}
|
|
160
|
+
const jsonSchema = toJsonSchema(options.parameters);
|
|
161
|
+
const parseArguments = async (rawArguments) => {
|
|
162
|
+
let parsed = {};
|
|
163
|
+
if (rawArguments && rawArguments.trim()) {
|
|
164
|
+
try {
|
|
165
|
+
parsed = JSON.parse(rawArguments);
|
|
166
|
+
} catch {
|
|
167
|
+
throw new SyntaxError(`The arguments for ${options.name} are not valid JSON.`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return validate(options.parameters, parsed, `Invalid arguments for ${options.name}`);
|
|
171
|
+
};
|
|
172
|
+
return {
|
|
173
|
+
type: "function",
|
|
174
|
+
name: options.name,
|
|
175
|
+
description: options.description,
|
|
176
|
+
parameters: jsonSchema,
|
|
177
|
+
needsApproval: options.needsApproval ?? false,
|
|
178
|
+
parseArguments,
|
|
179
|
+
async invoke(runContext, rawArguments, callId) {
|
|
180
|
+
try {
|
|
181
|
+
const args = await parseArguments(rawArguments);
|
|
182
|
+
const out = await options.execute(args, runContext, { callId });
|
|
183
|
+
return stringify(out);
|
|
184
|
+
} catch (error) {
|
|
185
|
+
if (options.errorFunction) return options.errorFunction(error, runContext);
|
|
186
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
187
|
+
return `Error running ${options.name}: ${message}`;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
var TOOL_NAME_PATTERN;
|
|
193
|
+
var init_tool = __esm({
|
|
194
|
+
"src/agents-sdk/tool.ts"() {
|
|
195
|
+
"use strict";
|
|
196
|
+
init_schema();
|
|
197
|
+
TOOL_NAME_PATTERN = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// src/agents-sdk/errors.ts
|
|
202
|
+
var AgentsError, MaxTurnsExceededError, GuardrailTripwireTriggered, CencoriRunError;
|
|
203
|
+
var init_errors = __esm({
|
|
204
|
+
"src/agents-sdk/errors.ts"() {
|
|
205
|
+
"use strict";
|
|
206
|
+
AgentsError = class extends Error {
|
|
207
|
+
constructor(message) {
|
|
208
|
+
super(message);
|
|
209
|
+
this.name = "AgentsError";
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
MaxTurnsExceededError = class extends AgentsError {
|
|
213
|
+
constructor(maxTurns, sessionId) {
|
|
214
|
+
super(`The run exceeded maxTurns (${maxTurns}) without a final answer. Raise maxTurns or check for a tool loop.`);
|
|
215
|
+
this.name = "MaxTurnsExceededError";
|
|
216
|
+
this.sessionId = sessionId;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
GuardrailTripwireTriggered = class extends AgentsError {
|
|
220
|
+
constructor(kind, guardrail, outputInfo) {
|
|
221
|
+
super(`${kind === "input" ? "Input" : "Output"} guardrail "${guardrail}" tripped.`);
|
|
222
|
+
this.name = kind === "input" ? "InputGuardrailTripwireTriggered" : "OutputGuardrailTripwireTriggered";
|
|
223
|
+
this.guardrail = guardrail;
|
|
224
|
+
this.kind = kind;
|
|
225
|
+
this.outputInfo = outputInfo;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
CencoriRunError = class extends AgentsError {
|
|
229
|
+
constructor(message, details = {}) {
|
|
230
|
+
super(message);
|
|
231
|
+
this.name = "CencoriRunError";
|
|
232
|
+
this.status = details.status;
|
|
233
|
+
this.code = details.code;
|
|
234
|
+
this.sessionId = details.sessionId;
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// src/agents-sdk/transport.ts
|
|
241
|
+
function env(name) {
|
|
242
|
+
try {
|
|
243
|
+
return typeof process !== "undefined" ? process.env?.[name] : void 0;
|
|
244
|
+
} catch {
|
|
245
|
+
return void 0;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async function errorFrom(response, sessionId) {
|
|
249
|
+
let message = `Cencori returned ${response.status}`;
|
|
250
|
+
let code;
|
|
251
|
+
try {
|
|
252
|
+
const body = await response.json();
|
|
253
|
+
if (typeof body.error === "string") message = body.error;
|
|
254
|
+
else if (body.error?.message) {
|
|
255
|
+
message = body.error.message;
|
|
256
|
+
code = body.error.code;
|
|
257
|
+
}
|
|
258
|
+
} catch {
|
|
259
|
+
}
|
|
260
|
+
return new CencoriRunError(message, { status: response.status, code, sessionId });
|
|
261
|
+
}
|
|
262
|
+
async function* readSessionEvents(response) {
|
|
263
|
+
if (!response.body) return;
|
|
264
|
+
const reader = response.body.getReader();
|
|
265
|
+
const decoder = new TextDecoder();
|
|
266
|
+
let buffer = "";
|
|
267
|
+
let event = "message";
|
|
268
|
+
let data = [];
|
|
269
|
+
const flush = () => {
|
|
270
|
+
if (data.length === 0) {
|
|
271
|
+
event = "message";
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
const raw = data.join("\n");
|
|
275
|
+
data = [];
|
|
276
|
+
const name = event;
|
|
277
|
+
event = "message";
|
|
278
|
+
try {
|
|
279
|
+
return { event: name, data: JSON.parse(raw) };
|
|
280
|
+
} catch {
|
|
281
|
+
return { event: name, data: { raw } };
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
try {
|
|
285
|
+
while (true) {
|
|
286
|
+
const { done, value } = await reader.read();
|
|
287
|
+
if (done) break;
|
|
288
|
+
buffer += decoder.decode(value, { stream: true });
|
|
289
|
+
let newline;
|
|
290
|
+
while ((newline = buffer.indexOf("\n")) >= 0) {
|
|
291
|
+
const line = buffer.slice(0, newline).replace(/\r$/, "");
|
|
292
|
+
buffer = buffer.slice(newline + 1);
|
|
293
|
+
if (line === "") {
|
|
294
|
+
const parsed = flush();
|
|
295
|
+
if (parsed) yield parsed;
|
|
296
|
+
} else if (line.startsWith("event:")) {
|
|
297
|
+
event = line.slice(6).trim();
|
|
298
|
+
} else if (line.startsWith("data:")) {
|
|
299
|
+
data.push(line.slice(5).replace(/^ /, ""));
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
buffer += decoder.decode();
|
|
304
|
+
if (buffer.trim()) {
|
|
305
|
+
for (const line of buffer.split("\n")) {
|
|
306
|
+
if (line.startsWith("event:")) event = line.slice(6).trim();
|
|
307
|
+
else if (line.startsWith("data:")) data.push(line.slice(5).replace(/^ /, ""));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
const last = flush();
|
|
311
|
+
if (last) yield last;
|
|
312
|
+
} finally {
|
|
313
|
+
reader.releaseLock();
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
var DEFAULT_BASE_URL, Transport;
|
|
317
|
+
var init_transport = __esm({
|
|
318
|
+
"src/agents-sdk/transport.ts"() {
|
|
319
|
+
"use strict";
|
|
320
|
+
init_errors();
|
|
321
|
+
DEFAULT_BASE_URL = "https://cencori.com";
|
|
322
|
+
Transport = class {
|
|
323
|
+
constructor(options = {}) {
|
|
324
|
+
const apiKey = options.apiKey ?? env("CENCORI_API_KEY");
|
|
325
|
+
if (!apiKey) {
|
|
326
|
+
throw new CencoriRunError("No Cencori API key. Pass apiKey or set CENCORI_API_KEY (a secret project key, csk_...).", { code: "missing_api_key" });
|
|
327
|
+
}
|
|
328
|
+
this.apiKey = apiKey;
|
|
329
|
+
this.baseUrl = (options.baseUrl ?? env("CENCORI_BASE_URL") ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
330
|
+
this.fetchImpl = options.fetch ?? fetch;
|
|
331
|
+
this.signal = options.signal;
|
|
332
|
+
}
|
|
333
|
+
async post(path, body, sessionId) {
|
|
334
|
+
const response = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
335
|
+
method: "POST",
|
|
336
|
+
headers: {
|
|
337
|
+
"CENCORI_API_KEY": this.apiKey,
|
|
338
|
+
"Content-Type": "application/json",
|
|
339
|
+
"Accept": "text/event-stream, application/json"
|
|
340
|
+
},
|
|
341
|
+
body: JSON.stringify(body),
|
|
342
|
+
signal: this.signal
|
|
343
|
+
});
|
|
344
|
+
if (!response.ok) throw await errorFrom(response, sessionId);
|
|
345
|
+
return response;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Create a session and run its first turn in one request. Servers that
|
|
349
|
+
* predate this answer with the plain session JSON; the turn then goes in a
|
|
350
|
+
* second request, as before.
|
|
351
|
+
*/
|
|
352
|
+
async createSessionWithTurn(metadata, body) {
|
|
353
|
+
const turn = { ...body, stream: true, pause_on_tool_calls: true };
|
|
354
|
+
const response = await this.fetchImpl(`${this.baseUrl}/v1/sessions`, {
|
|
355
|
+
method: "POST",
|
|
356
|
+
headers: {
|
|
357
|
+
"CENCORI_API_KEY": this.apiKey,
|
|
358
|
+
"Content-Type": "application/json",
|
|
359
|
+
"Accept": "text/event-stream, application/json"
|
|
360
|
+
},
|
|
361
|
+
body: JSON.stringify({ metadata, turn }),
|
|
362
|
+
signal: this.signal
|
|
363
|
+
});
|
|
364
|
+
const headerId = response.headers.get("X-Cencori-Session-Id") ?? void 0;
|
|
365
|
+
if (!response.ok) throw await errorFrom(response, headerId);
|
|
366
|
+
if (headerId) return { sessionId: headerId, response };
|
|
367
|
+
const created = await response.json();
|
|
368
|
+
if (!created.id) throw new CencoriRunError("Cencori did not return a session id.");
|
|
369
|
+
return { sessionId: created.id, response: await this.turn(created.id, body) };
|
|
370
|
+
}
|
|
371
|
+
turn(sessionId, body) {
|
|
372
|
+
return this.post(`/v1/sessions/${encodeURIComponent(sessionId)}/turns`, {
|
|
373
|
+
...body,
|
|
374
|
+
stream: true,
|
|
375
|
+
pause_on_tool_calls: true
|
|
376
|
+
}, sessionId);
|
|
377
|
+
}
|
|
378
|
+
resume(sessionId, actionId, toolResults, next) {
|
|
379
|
+
return this.post(`/v1/sessions/${encodeURIComponent(sessionId)}/approve`, {
|
|
380
|
+
action_id: actionId,
|
|
381
|
+
tool_results: toolResults,
|
|
382
|
+
...next ? { next } : {}
|
|
383
|
+
}, sessionId);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
// src/agents-sdk/run.ts
|
|
390
|
+
var run_exports = {};
|
|
391
|
+
__export(run_exports, {
|
|
392
|
+
RunState: () => RunState,
|
|
393
|
+
run: () => run
|
|
394
|
+
});
|
|
395
|
+
function collectAgents(start) {
|
|
396
|
+
const seen = /* @__PURE__ */ new Map();
|
|
397
|
+
const visit = (agent) => {
|
|
398
|
+
if (seen.has(agent.name)) return;
|
|
399
|
+
seen.set(agent.name, agent);
|
|
400
|
+
agent.handoffs.forEach(visit);
|
|
401
|
+
};
|
|
402
|
+
visit(start);
|
|
403
|
+
return seen;
|
|
404
|
+
}
|
|
405
|
+
function wireTools(agent) {
|
|
406
|
+
const tools = agent.tools.map((t) => ({
|
|
407
|
+
type: "function",
|
|
408
|
+
function: { name: t.name, description: t.description, parameters: t.parameters },
|
|
409
|
+
// Only an unconditional approval is the server's to hold and record; a
|
|
410
|
+
// conditional one is decided here, per call.
|
|
411
|
+
...t.needsApproval === true ? { needsApproval: true } : {}
|
|
412
|
+
}));
|
|
413
|
+
for (const target of agent.handoffs) {
|
|
414
|
+
tools.push({
|
|
415
|
+
type: "function",
|
|
416
|
+
function: {
|
|
417
|
+
name: Agent.handoffToolName(target),
|
|
418
|
+
description: target.handoffDescription ? `Hand the conversation to ${target.name}: ${target.handoffDescription}` : `Hand the conversation to the ${target.name} agent.`,
|
|
419
|
+
parameters: { type: "object", properties: {}, additionalProperties: false }
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
return tools;
|
|
424
|
+
}
|
|
425
|
+
function addUsage(total, usage) {
|
|
426
|
+
const u = usage ?? {};
|
|
427
|
+
return {
|
|
428
|
+
inputTokens: total.inputTokens + (u.input_tokens ?? 0),
|
|
429
|
+
outputTokens: total.outputTokens + (u.output_tokens ?? 0),
|
|
430
|
+
totalTokens: total.totalTokens + (u.total_tokens ?? 0)
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
function completedText(streamed2, data) {
|
|
434
|
+
if (streamed2) return streamed2;
|
|
435
|
+
const out = data.output;
|
|
436
|
+
if (typeof out?.text === "string") return out.text;
|
|
437
|
+
let text = "";
|
|
438
|
+
if (Array.isArray(out?.output)) {
|
|
439
|
+
for (const item of out.output) {
|
|
440
|
+
if (item.type !== "message" || !Array.isArray(item.content)) continue;
|
|
441
|
+
for (const c of item.content) {
|
|
442
|
+
if (c.type === "output_text" && typeof c.text === "string") text += c.text;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return text;
|
|
447
|
+
}
|
|
448
|
+
async function* consumeTurn(response, agentName, sessionId) {
|
|
449
|
+
let text = "";
|
|
450
|
+
for await (const { event, data } of readSessionEvents(response)) {
|
|
451
|
+
switch (event) {
|
|
452
|
+
case "output_text.delta": {
|
|
453
|
+
const delta = typeof data.delta === "string" ? data.delta : "";
|
|
454
|
+
if (delta) {
|
|
455
|
+
text += delta;
|
|
456
|
+
yield { type: "text_delta", delta, agentName };
|
|
457
|
+
}
|
|
458
|
+
break;
|
|
459
|
+
}
|
|
460
|
+
case "turn.paused": {
|
|
461
|
+
const actions = Array.isArray(data.actions) ? data.actions : [{ action_id: String(data.action_id), tool: String(data.tool), arguments: JSON.stringify(data.arguments?.[String(data.tool)] ?? {}) }];
|
|
462
|
+
return { kind: "paused", pause: { actionId: String(data.action_id), actions, text } };
|
|
463
|
+
}
|
|
464
|
+
case "turn.completed":
|
|
465
|
+
return { kind: "completed", text: completedText(text, data), usage: data.usage };
|
|
466
|
+
case "turn.failed": {
|
|
467
|
+
const output = data.output;
|
|
468
|
+
throw new CencoriRunError(output?.error ?? "The turn failed.", { code: "turn_failed", sessionId });
|
|
469
|
+
}
|
|
470
|
+
case "error": {
|
|
471
|
+
const err = data.error ?? data;
|
|
472
|
+
throw new CencoriRunError(err.message ?? "The turn failed.", { code: err.code, sessionId });
|
|
473
|
+
}
|
|
474
|
+
default:
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
throw new CencoriRunError("The turn ended without a result.", { code: "stream_ended", sessionId });
|
|
479
|
+
}
|
|
480
|
+
async function* runLoop(startAgent, input, options) {
|
|
481
|
+
const transport = new Transport(options);
|
|
482
|
+
const agents = collectAgents(startAgent);
|
|
483
|
+
const maxTurns = options.maxTurns ?? DEFAULT_MAX_TURNS;
|
|
484
|
+
const items = [];
|
|
485
|
+
const contextFor = (agent2, sessionId2) => {
|
|
486
|
+
const ctx = {
|
|
487
|
+
context: options.context,
|
|
488
|
+
sessionId: sessionId2,
|
|
489
|
+
agentName: agent2.name,
|
|
490
|
+
signal: options.signal
|
|
491
|
+
};
|
|
492
|
+
Object.defineProperty(ctx, "__runOptions", { value: options, enumerable: false });
|
|
493
|
+
return ctx;
|
|
494
|
+
};
|
|
495
|
+
const nextFor = async (agent2, sessionId2) => ({
|
|
496
|
+
instructions: await agent2.resolveInstructions(contextFor(agent2, sessionId2)) ?? "",
|
|
497
|
+
model: agent2.model,
|
|
498
|
+
tools: wireTools(agent2)
|
|
499
|
+
});
|
|
500
|
+
let agent;
|
|
501
|
+
let sessionId;
|
|
502
|
+
let turnsUsed;
|
|
503
|
+
let usage;
|
|
504
|
+
let response;
|
|
505
|
+
let pending;
|
|
506
|
+
let resumedState;
|
|
507
|
+
if (input instanceof RunState) {
|
|
508
|
+
resumedState = input;
|
|
509
|
+
const found = agents.get(input.agentName);
|
|
510
|
+
if (!found) throw new AgentsError(`The run state belongs to agent "${input.agentName}", which isn't reachable from "${startAgent.name}".`);
|
|
511
|
+
agent = found;
|
|
512
|
+
sessionId = input.sessionId;
|
|
513
|
+
turnsUsed = input.turnsUsed;
|
|
514
|
+
usage = input.usage;
|
|
515
|
+
pending = input.pending;
|
|
516
|
+
} else {
|
|
517
|
+
agent = startAgent;
|
|
518
|
+
turnsUsed = 0;
|
|
519
|
+
usage = { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
|
|
520
|
+
sessionId = options.sessionId ?? "";
|
|
521
|
+
const runContext = contextFor(agent, sessionId);
|
|
522
|
+
for (const guardrail of agent.inputGuardrails) {
|
|
523
|
+
const verdict = await guardrail.execute({ input, agent, runContext });
|
|
524
|
+
if (verdict.tripwireTriggered) throw new GuardrailTripwireTriggered("input", guardrail.name, verdict.outputInfo);
|
|
525
|
+
}
|
|
526
|
+
yield { type: "agent_updated", agent };
|
|
527
|
+
turnsUsed++;
|
|
528
|
+
const firstTools = wireTools(agent);
|
|
529
|
+
const firstTurn = {
|
|
530
|
+
input,
|
|
531
|
+
model: agent.model,
|
|
532
|
+
instructions: await agent.resolveInstructions(runContext),
|
|
533
|
+
tools: firstTools.length ? firstTools : void 0,
|
|
534
|
+
...agent.outputType ? { response_format: { type: "json_schema", json_schema: { name: "final_output", schema: toJsonSchema(agent.outputType) } } } : {},
|
|
535
|
+
...agent.modelSettings.temperature !== void 0 ? { temperature: agent.modelSettings.temperature } : {},
|
|
536
|
+
...agent.modelSettings.maxTokens !== void 0 ? { max_output_tokens: agent.modelSettings.maxTokens } : {},
|
|
537
|
+
...agent.modelSettings.reasoningEffort ? { reasoning_effort: agent.modelSettings.reasoningEffort } : {},
|
|
538
|
+
...options.memory ? { memory: options.memory } : {},
|
|
539
|
+
...options.user ? { user: options.user } : {},
|
|
540
|
+
metadata: { sdk: "cencori/agents", agent: agent.name }
|
|
541
|
+
};
|
|
542
|
+
if (sessionId) {
|
|
543
|
+
response = await transport.turn(sessionId, firstTurn);
|
|
544
|
+
} else {
|
|
545
|
+
const created = await transport.createSessionWithTurn({
|
|
546
|
+
...options.metadata ?? {},
|
|
547
|
+
sdk: "cencori/agents",
|
|
548
|
+
agent: startAgent.name
|
|
549
|
+
}, firstTurn);
|
|
550
|
+
sessionId = created.sessionId;
|
|
551
|
+
response = created.response;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
while (true) {
|
|
555
|
+
if (response) {
|
|
556
|
+
const outcome = yield* consumeTurn(response, agent.name, sessionId);
|
|
557
|
+
response = void 0;
|
|
558
|
+
if (outcome.kind === "completed") {
|
|
559
|
+
usage = addUsage(usage, outcome.usage);
|
|
560
|
+
let finalOutput = outcome.text;
|
|
561
|
+
if (agent.outputType) {
|
|
562
|
+
let parsed;
|
|
563
|
+
try {
|
|
564
|
+
parsed = JSON.parse(outcome.text);
|
|
565
|
+
} catch {
|
|
566
|
+
throw new CencoriRunError(`${agent.name} did not return valid JSON for its outputType.`, { code: "invalid_output", sessionId });
|
|
567
|
+
}
|
|
568
|
+
finalOutput = await validate(agent.outputType, parsed, `${agent.name}'s output`);
|
|
569
|
+
}
|
|
570
|
+
items.push({ type: "message", agentName: agent.name, text: outcome.text });
|
|
571
|
+
const runContext2 = contextFor(agent, sessionId);
|
|
572
|
+
for (const guardrail of agent.outputGuardrails) {
|
|
573
|
+
const verdict = await guardrail.execute({ output: finalOutput, agent, runContext: runContext2 });
|
|
574
|
+
if (verdict.tripwireTriggered) throw new GuardrailTripwireTriggered("output", guardrail.name, verdict.outputInfo);
|
|
575
|
+
}
|
|
576
|
+
return { finalOutput, sessionId, lastAgent: agent, interruptions: [], state: void 0, newItems: items, usage };
|
|
577
|
+
}
|
|
578
|
+
pending = outcome.pause;
|
|
579
|
+
if (outcome.pause.text) items.push({ type: "message", agentName: agent.name, text: outcome.pause.text });
|
|
580
|
+
for (const action of outcome.pause.actions) {
|
|
581
|
+
items.push({ type: "tool_call", agentName: agent.name, callId: action.action_id, toolName: action.tool, arguments: action.arguments });
|
|
582
|
+
yield { type: "tool_call", callId: action.action_id, toolName: action.tool, arguments: action.arguments, agentName: agent.name };
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
if (!pending) throw new AgentsError("Nothing to continue.");
|
|
586
|
+
const runContext = contextFor(agent, sessionId);
|
|
587
|
+
const toolsByName = new Map(agent.tools.map((t) => [t.name, t]));
|
|
588
|
+
const handoffsByName = new Map(agent.handoffs.map((a) => [Agent.handoffToolName(a), a]));
|
|
589
|
+
const interruptions = [];
|
|
590
|
+
for (const action of pending.actions) {
|
|
591
|
+
const t = toolsByName.get(action.tool);
|
|
592
|
+
if (!t || resumedState?.decision(action.action_id)) continue;
|
|
593
|
+
let needs = action.needs_approval === true || t.needsApproval === true;
|
|
594
|
+
if (!needs && typeof t.needsApproval === "function") {
|
|
595
|
+
try {
|
|
596
|
+
needs = await t.needsApproval(runContext, await t.parseArguments(action.arguments), action.action_id);
|
|
597
|
+
} catch {
|
|
598
|
+
needs = false;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
if (needs) {
|
|
602
|
+
interruptions.push({ type: "tool_approval", callId: action.action_id, toolName: action.tool, arguments: action.arguments, agentName: agent.name });
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
if (interruptions.length > 0) {
|
|
606
|
+
const state = new RunState({ sessionId, agentName: agent.name, turnsUsed, usage, pending });
|
|
607
|
+
yield { type: "interruption", interruptions };
|
|
608
|
+
return { finalOutput: void 0, sessionId, lastAgent: agent, interruptions, state, newItems: items, usage };
|
|
609
|
+
}
|
|
610
|
+
if (turnsUsed >= maxTurns) throw new MaxTurnsExceededError(maxTurns, sessionId);
|
|
611
|
+
let handoffTo;
|
|
612
|
+
const results = await Promise.all(pending.actions.map(async (action) => {
|
|
613
|
+
const target = handoffsByName.get(action.tool);
|
|
614
|
+
if (target) {
|
|
615
|
+
if (handoffTo && handoffTo !== target) {
|
|
616
|
+
return { action, output: `Not transferred: the conversation already went to ${handoffTo.name}.` };
|
|
617
|
+
}
|
|
618
|
+
handoffTo = target;
|
|
619
|
+
return { action, output: `Transferred to ${target.name}. You are now ${target.name}; continue the conversation.` };
|
|
620
|
+
}
|
|
621
|
+
const decision = resumedState?.decision(action.action_id);
|
|
622
|
+
if (decision && !decision.approved) {
|
|
623
|
+
return { action, output: `The user rejected this call${decision.message ? `: ${decision.message}` : "."} Don't retry it.` };
|
|
624
|
+
}
|
|
625
|
+
const t = toolsByName.get(action.tool);
|
|
626
|
+
if (!t) return { action, output: `Error: there is no tool named ${action.tool}.` };
|
|
627
|
+
return { action, output: await t.invoke(runContext, action.arguments, action.action_id) };
|
|
628
|
+
}));
|
|
629
|
+
for (const { action, output } of results) {
|
|
630
|
+
if (handoffsByName.has(action.tool)) continue;
|
|
631
|
+
items.push({ type: "tool_output", agentName: agent.name, callId: action.action_id, toolName: action.tool, output });
|
|
632
|
+
yield { type: "tool_output", callId: action.action_id, toolName: action.tool, output, agentName: agent.name };
|
|
633
|
+
}
|
|
634
|
+
let next;
|
|
635
|
+
if (handoffTo) {
|
|
636
|
+
const from = agent.name;
|
|
637
|
+
agent = handoffTo;
|
|
638
|
+
next = await nextFor(agent, sessionId);
|
|
639
|
+
items.push({ type: "handoff", from, to: agent.name });
|
|
640
|
+
yield { type: "handoff", from, to: agent.name };
|
|
641
|
+
yield { type: "agent_updated", agent };
|
|
642
|
+
}
|
|
643
|
+
turnsUsed++;
|
|
644
|
+
resumedState = void 0;
|
|
645
|
+
response = await transport.resume(
|
|
646
|
+
sessionId,
|
|
647
|
+
pending.actionId,
|
|
648
|
+
results.map(({ action, output }) => ({ action_id: action.action_id, output })),
|
|
649
|
+
next
|
|
650
|
+
);
|
|
651
|
+
pending = void 0;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
function run(agent, input, options = {}) {
|
|
655
|
+
if (options.stream) return streamed(agent, input, options);
|
|
656
|
+
return (async () => {
|
|
657
|
+
const loop = runLoop(agent, input, options);
|
|
658
|
+
while (true) {
|
|
659
|
+
const step = await loop.next();
|
|
660
|
+
if (step.done) return step.value;
|
|
661
|
+
}
|
|
662
|
+
})();
|
|
663
|
+
}
|
|
664
|
+
function streamed(agent, input, options) {
|
|
665
|
+
const loop = runLoop(agent, input, options);
|
|
666
|
+
let resolve;
|
|
667
|
+
let reject;
|
|
668
|
+
const completed = new Promise((res, rej) => {
|
|
669
|
+
resolve = res;
|
|
670
|
+
reject = rej;
|
|
671
|
+
});
|
|
672
|
+
completed.catch(() => {
|
|
673
|
+
});
|
|
674
|
+
let started = false;
|
|
675
|
+
const events = async function* () {
|
|
676
|
+
if (started) throw new AgentsError("A streamed run can be iterated once.");
|
|
677
|
+
started = true;
|
|
678
|
+
try {
|
|
679
|
+
while (true) {
|
|
680
|
+
const step = await loop.next();
|
|
681
|
+
if (step.done) {
|
|
682
|
+
resolve(step.value);
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
yield step.value;
|
|
686
|
+
}
|
|
687
|
+
} catch (error) {
|
|
688
|
+
reject(error);
|
|
689
|
+
throw error;
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
let iterator;
|
|
693
|
+
return {
|
|
694
|
+
[Symbol.asyncIterator]() {
|
|
695
|
+
iterator ?? (iterator = events());
|
|
696
|
+
return iterator;
|
|
697
|
+
},
|
|
698
|
+
get completed() {
|
|
699
|
+
if (!started) {
|
|
700
|
+
void (async () => {
|
|
701
|
+
try {
|
|
702
|
+
for await (const _event of this) {
|
|
703
|
+
}
|
|
704
|
+
} catch {
|
|
705
|
+
}
|
|
706
|
+
})();
|
|
707
|
+
}
|
|
708
|
+
return completed;
|
|
709
|
+
},
|
|
710
|
+
async *toTextStream() {
|
|
711
|
+
for await (const event of this) {
|
|
712
|
+
if (event.type === "text_delta") yield event.delta;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
var RunState, DEFAULT_MAX_TURNS;
|
|
718
|
+
var init_run = __esm({
|
|
719
|
+
"src/agents-sdk/run.ts"() {
|
|
720
|
+
"use strict";
|
|
721
|
+
init_agent();
|
|
722
|
+
init_errors();
|
|
723
|
+
init_schema();
|
|
724
|
+
init_transport();
|
|
725
|
+
RunState = class _RunState {
|
|
726
|
+
/** @internal */
|
|
727
|
+
constructor(init) {
|
|
728
|
+
this.sessionId = init.sessionId;
|
|
729
|
+
this.agentName = init.agentName;
|
|
730
|
+
this.turnsUsed = init.turnsUsed;
|
|
731
|
+
this.usage = init.usage;
|
|
732
|
+
this.pending = init.pending;
|
|
733
|
+
this.decisions = new Map(Object.entries(init.decisions ?? {}));
|
|
734
|
+
}
|
|
735
|
+
approve(item) {
|
|
736
|
+
this.decisions.set(typeof item === "string" ? item : item.callId, { approved: true });
|
|
737
|
+
}
|
|
738
|
+
/** The model is told the call was rejected, with your message if given. */
|
|
739
|
+
reject(item, options = {}) {
|
|
740
|
+
this.decisions.set(typeof item === "string" ? item : item.callId, { approved: false, message: options.message });
|
|
741
|
+
}
|
|
742
|
+
/** @internal */
|
|
743
|
+
decision(callId) {
|
|
744
|
+
return this.decisions.get(callId);
|
|
745
|
+
}
|
|
746
|
+
toJSON() {
|
|
747
|
+
return {
|
|
748
|
+
v: 1,
|
|
749
|
+
sessionId: this.sessionId,
|
|
750
|
+
agentName: this.agentName,
|
|
751
|
+
turnsUsed: this.turnsUsed,
|
|
752
|
+
usage: this.usage,
|
|
753
|
+
pending: this.pending,
|
|
754
|
+
decisions: Object.fromEntries(this.decisions)
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
static fromJSON(json) {
|
|
758
|
+
const data = typeof json === "string" ? JSON.parse(json) : json;
|
|
759
|
+
if (data?.v !== 1 || !data.sessionId || !data.pending) throw new AgentsError("Not a cencori/agents run state.");
|
|
760
|
+
return new _RunState(data);
|
|
761
|
+
}
|
|
762
|
+
};
|
|
763
|
+
DEFAULT_MAX_TURNS = 10;
|
|
764
|
+
}
|
|
765
|
+
});
|
|
766
|
+
|
|
767
|
+
// src/agents-sdk/agent.ts
|
|
768
|
+
function toolSafe(name) {
|
|
769
|
+
const safe = name.toLowerCase().replace(/[^a-z0-9_-]+/g, "_").replace(/^_+|_+$/g, "");
|
|
770
|
+
return safe || "agent";
|
|
771
|
+
}
|
|
772
|
+
var DEFAULT_MODEL, Agent;
|
|
773
|
+
var init_agent = __esm({
|
|
774
|
+
"src/agents-sdk/agent.ts"() {
|
|
775
|
+
"use strict";
|
|
776
|
+
init_tool();
|
|
777
|
+
DEFAULT_MODEL = "gpt-oss-120b";
|
|
778
|
+
Agent = class _Agent {
|
|
779
|
+
constructor(options) {
|
|
780
|
+
if (!options.name?.trim()) throw new TypeError("An agent needs a name.");
|
|
781
|
+
if (options.model !== void 0 && !options.model.trim()) throw new TypeError(`Agent "${options.name}" needs a model.`);
|
|
782
|
+
this.name = options.name;
|
|
783
|
+
this.instructions = options.instructions;
|
|
784
|
+
this.model = options.model ?? DEFAULT_MODEL;
|
|
785
|
+
this.tools = options.tools ?? [];
|
|
786
|
+
this.handoffs = options.handoffs ?? [];
|
|
787
|
+
this.handoffDescription = options.handoffDescription;
|
|
788
|
+
this.outputType = options.outputType;
|
|
789
|
+
this.modelSettings = options.modelSettings ?? {};
|
|
790
|
+
this.inputGuardrails = options.inputGuardrails ?? [];
|
|
791
|
+
this.outputGuardrails = options.outputGuardrails ?? [];
|
|
792
|
+
const names = /* @__PURE__ */ new Set();
|
|
793
|
+
for (const t of [...this.tools.map((t2) => t2.name), ...this.handoffs.map((a) => _Agent.handoffToolName(a))]) {
|
|
794
|
+
if (names.has(t)) throw new TypeError(`Agent "${this.name}" has two tools named "${t}".`);
|
|
795
|
+
names.add(t);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
/** A copy with some options changed. */
|
|
799
|
+
clone(overrides) {
|
|
800
|
+
return new _Agent({
|
|
801
|
+
name: this.name,
|
|
802
|
+
instructions: this.instructions,
|
|
803
|
+
model: this.model,
|
|
804
|
+
tools: this.tools,
|
|
805
|
+
handoffs: this.handoffs,
|
|
806
|
+
handoffDescription: this.handoffDescription,
|
|
807
|
+
outputType: this.outputType,
|
|
808
|
+
modelSettings: this.modelSettings,
|
|
809
|
+
inputGuardrails: this.inputGuardrails,
|
|
810
|
+
outputGuardrails: this.outputGuardrails,
|
|
811
|
+
...overrides
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
/** The tool name a handoff to this agent goes by. */
|
|
815
|
+
static handoffToolName(agent) {
|
|
816
|
+
const name = `transfer_to_${toolSafe(agent.name)}`.slice(0, 64);
|
|
817
|
+
if (!TOOL_NAME_PATTERN.test(name)) throw new TypeError(`Can't make a handoff tool name for "${agent.name}".`);
|
|
818
|
+
return name;
|
|
819
|
+
}
|
|
820
|
+
/** Instructions for this run, resolving a function if given. */
|
|
821
|
+
async resolveInstructions(runContext) {
|
|
822
|
+
if (typeof this.instructions === "function") return this.instructions(runContext);
|
|
823
|
+
return this.instructions;
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Use this agent as a tool of another: it runs on its own (in its own
|
|
827
|
+
* session) and returns its final answer, while the calling agent keeps the
|
|
828
|
+
* conversation. Compare handoffs, where this agent would take it over.
|
|
829
|
+
*/
|
|
830
|
+
asTool(options = {}) {
|
|
831
|
+
const agent = this;
|
|
832
|
+
return tool({
|
|
833
|
+
name: options.toolName ?? toolSafe(this.name).slice(0, 64),
|
|
834
|
+
description: options.toolDescription ?? this.handoffDescription ?? `Ask the ${this.name} agent.`,
|
|
835
|
+
parameters: {
|
|
836
|
+
type: "object",
|
|
837
|
+
properties: { input: { type: "string", description: `What to ask ${this.name}.` } },
|
|
838
|
+
required: ["input"],
|
|
839
|
+
additionalProperties: false
|
|
840
|
+
},
|
|
841
|
+
async execute(args, runContext) {
|
|
842
|
+
const { run: run2 } = await Promise.resolve().then(() => (init_run(), run_exports));
|
|
843
|
+
const { input } = args;
|
|
844
|
+
const inherited = runContext.__runOptions;
|
|
845
|
+
const result = await run2(agent, input, {
|
|
846
|
+
// Same transport as the calling run: key, endpoint and any custom fetch.
|
|
847
|
+
apiKey: inherited?.apiKey,
|
|
848
|
+
baseUrl: inherited?.baseUrl,
|
|
849
|
+
fetch: inherited?.fetch,
|
|
850
|
+
user: inherited?.user,
|
|
851
|
+
...options.runOptions,
|
|
852
|
+
context: runContext.context,
|
|
853
|
+
signal: runContext.signal,
|
|
854
|
+
metadata: { parent_session_id: runContext.sessionId, ...inherited?.metadata ?? {} }
|
|
855
|
+
});
|
|
856
|
+
return result.finalOutput;
|
|
857
|
+
}
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
});
|
|
863
|
+
|
|
864
|
+
// src/agents-sdk/index.ts
|
|
865
|
+
var agents_sdk_exports = {};
|
|
866
|
+
__export(agents_sdk_exports, {
|
|
867
|
+
Agent: () => Agent,
|
|
868
|
+
AgentsError: () => AgentsError,
|
|
869
|
+
CencoriRunError: () => CencoriRunError,
|
|
870
|
+
DEFAULT_MODEL: () => DEFAULT_MODEL,
|
|
871
|
+
GuardrailTripwireTriggered: () => GuardrailTripwireTriggered,
|
|
872
|
+
MaxTurnsExceededError: () => MaxTurnsExceededError,
|
|
873
|
+
RunState: () => RunState,
|
|
874
|
+
SchemaValidationError: () => SchemaValidationError,
|
|
875
|
+
run: () => run,
|
|
876
|
+
tool: () => tool
|
|
877
|
+
});
|
|
878
|
+
module.exports = __toCommonJS(agents_sdk_exports);
|
|
879
|
+
init_agent();
|
|
880
|
+
init_tool();
|
|
881
|
+
init_run();
|
|
882
|
+
init_errors();
|
|
883
|
+
init_schema();
|
|
884
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
885
|
+
0 && (module.exports = {
|
|
886
|
+
Agent,
|
|
887
|
+
AgentsError,
|
|
888
|
+
CencoriRunError,
|
|
889
|
+
DEFAULT_MODEL,
|
|
890
|
+
GuardrailTripwireTriggered,
|
|
891
|
+
MaxTurnsExceededError,
|
|
892
|
+
RunState,
|
|
893
|
+
SchemaValidationError,
|
|
894
|
+
run,
|
|
895
|
+
tool
|
|
896
|
+
});
|
|
897
|
+
//# sourceMappingURL=index.js.map
|