@fevex/core 0.1.0-alpha.0 → 0.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,419 @@
1
+ //#region src/evals/index.ts
2
+ function assertNonEmpty(value, name) {
3
+ if (typeof value !== "string" || !value.trim()) throw new TypeError(`${name} must be non-empty`);
4
+ }
5
+ function errorMessage(error) {
6
+ return error instanceof Error ? error.message : String(error);
7
+ }
8
+ function equalJson(left, right) {
9
+ return serializeCanonical(left) === serializeCanonical(right);
10
+ }
11
+ function addUsage(target, usage) {
12
+ if (!usage) return;
13
+ for (const key of [
14
+ "inputTokens",
15
+ "outputTokens",
16
+ "totalTokens"
17
+ ]) if (usage[key] !== void 0) target[key] = (target[key] ?? 0) + usage[key];
18
+ }
19
+ function usageFromEvent(event) {
20
+ if (event.type !== "run.completed" || !event.payload.usage) return void 0;
21
+ const usage = {};
22
+ for (const key of [
23
+ "inputTokens",
24
+ "outputTokens",
25
+ "totalTokens"
26
+ ]) {
27
+ const value = event.payload.usage[key];
28
+ if (typeof value === "number") usage[key] = value;
29
+ }
30
+ return Object.keys(usage).length ? usage : void 0;
31
+ }
32
+ function validateOptions(options) {
33
+ assertNonEmpty(options.suiteName, "suiteName");
34
+ assertNonEmpty(options.targetVersion, "targetVersion");
35
+ assertNonEmpty(options.agentName, "agentName");
36
+ assertNonEmpty(options.dataset.name, "dataset.name");
37
+ assertNonEmpty(options.dataset.version, "dataset.version");
38
+ if (!Array.isArray(options.dataset.cases) || !options.dataset.cases.length) throw new TypeError("dataset.cases must contain at least one case");
39
+ const caseIds = /* @__PURE__ */ new Set();
40
+ for (const testCase of options.dataset.cases) {
41
+ assertNonEmpty(testCase.id, "case.id");
42
+ if (caseIds.has(testCase.id)) throw new TypeError(`Eval case "${testCase.id}" is duplicated`);
43
+ caseIds.add(testCase.id);
44
+ }
45
+ if (!Array.isArray(options.scorers) || !options.scorers.length) throw new TypeError("scorers must contain at least one scorer");
46
+ const scorerIds = /* @__PURE__ */ new Set();
47
+ for (const scorer of options.scorers) {
48
+ assertNonEmpty(scorer.id, "scorer.id");
49
+ if (typeof scorer.score !== "function") throw new TypeError(`Eval scorer "${scorer.id}" must implement score`);
50
+ if (scorerIds.has(scorer.id)) throw new TypeError(`Eval scorer "${scorer.id}" is duplicated`);
51
+ scorerIds.add(scorer.id);
52
+ }
53
+ if (options.reporters !== void 0 && (!Array.isArray(options.reporters) || options.reporters.some((reporter) => typeof reporter.report !== "function"))) throw new TypeError("reporters must implement report");
54
+ }
55
+ async function evaluateCase(options, testCase) {
56
+ options.signal?.throwIfAborted();
57
+ const startedAt = performance.now();
58
+ const events = [];
59
+ let executionError;
60
+ try {
61
+ for await (const event of options.app.streamAgent(options.agentName, {
62
+ input: testCase.input,
63
+ context: testCase.context,
64
+ signal: options.signal
65
+ })) events.push(event);
66
+ } catch (error) {
67
+ if (options.signal?.aborted) throw error;
68
+ executionError = errorMessage(error);
69
+ }
70
+ const latencyMs = performance.now() - startedAt;
71
+ const completed = events.find((event) => event.type === "run.completed");
72
+ const failed = [...events].reverse().find((event) => event.type === "run.failed" || event.type === "run.cancelled");
73
+ const output = completed?.type === "run.completed" ? completed.payload.output : void 0;
74
+ const usage = completed ? usageFromEvent(completed) : void 0;
75
+ const selectedTools = [];
76
+ const selectedIds = /* @__PURE__ */ new Set();
77
+ for (const event of events) {
78
+ if (event.type !== "tool.started" || selectedIds.has(event.payload.toolCallId)) continue;
79
+ selectedIds.add(event.payload.toolCallId);
80
+ selectedTools.push(event.payload.toolName);
81
+ }
82
+ const cost = options.cost && usage ? options.cost.calculate({
83
+ modelRegistryName: options.cost.modelRegistryName,
84
+ model: options.cost.model,
85
+ usage
86
+ }) : void 0;
87
+ if (cost && (!Number.isFinite(cost.amount) || cost.amount < 0 || !cost.currency.trim())) throw new TypeError("CostCalculator must return a non-negative amount and currency");
88
+ const runError = executionError ?? (failed?.type === "run.failed" ? failed.payload.error : failed?.type === "run.cancelled" ? failed.payload.reason : completed ? void 0 : "Run did not complete");
89
+ const context = {
90
+ testCase,
91
+ output,
92
+ tools: selectedTools,
93
+ events,
94
+ usage,
95
+ cost,
96
+ latencyMs,
97
+ error: runError
98
+ };
99
+ const scores = [];
100
+ for (const scorer of options.scorers) try {
101
+ const result = await scorer.score(context);
102
+ if ("skipped" in result) scores.push({
103
+ scorerId: scorer.id,
104
+ status: "skipped",
105
+ ...result.reason ? { details: result.reason } : {}
106
+ });
107
+ else {
108
+ if (!Number.isFinite(result.score) || result.score < 0 || result.score > 1) throw new TypeError("score must be between 0 and 1");
109
+ scores.push({
110
+ scorerId: scorer.id,
111
+ status: result.passed ? "passed" : "failed",
112
+ score: result.score,
113
+ ...result.details === void 0 ? {} : { details: result.details }
114
+ });
115
+ }
116
+ } catch (error) {
117
+ scores.push({
118
+ scorerId: scorer.id,
119
+ status: "error",
120
+ error: errorMessage(error)
121
+ });
122
+ }
123
+ return {
124
+ caseId: testCase.id,
125
+ status: completed ? "completed" : "failed",
126
+ ...output === void 0 ? {} : { output },
127
+ tools: selectedTools,
128
+ ...usage ? { usage } : {},
129
+ ...cost ? { cost } : {},
130
+ latencyMs,
131
+ scores,
132
+ ...runError ? { error: runError } : {}
133
+ };
134
+ }
135
+ function summarize(cases) {
136
+ const scores = cases.flatMap((testCase) => testCase.scores);
137
+ const numericScores = scores.flatMap((score) => score.score === void 0 ? [] : [score.score]);
138
+ const usage = {};
139
+ for (const testCase of cases) addUsage(usage, testCase.usage);
140
+ const costs = cases.flatMap((testCase) => testCase.cost ? [testCase.cost] : []);
141
+ const currencies = new Set(costs.map(({ currency }) => currency));
142
+ const totalCost = costs.length && currencies.size === 1 ? {
143
+ amount: costs.reduce((sum, cost) => sum + cost.amount, 0),
144
+ currency: costs[0].currency
145
+ } : void 0;
146
+ return {
147
+ caseCount: cases.length,
148
+ completedCount: cases.filter(({ status }) => status === "completed").length,
149
+ failedCount: cases.filter(({ status }) => status === "failed").length,
150
+ passedScoreCount: scores.filter(({ status }) => status === "passed").length,
151
+ failedScoreCount: scores.filter(({ status }) => status === "failed").length,
152
+ skippedScoreCount: scores.filter(({ status }) => status === "skipped").length,
153
+ errorScoreCount: scores.filter(({ status }) => status === "error").length,
154
+ ...numericScores.length ? { averageScore: numericScores.reduce((sum, score) => sum + score, 0) / numericScores.length } : {},
155
+ ...Object.keys(usage).length ? { usage } : {},
156
+ ...totalCost ? { cost: totalCost } : {},
157
+ latencyMs: cases.reduce((sum, testCase) => sum + testCase.latencyMs, 0)
158
+ };
159
+ }
160
+ async function runEvaluation(options) {
161
+ validateOptions(options);
162
+ const cases = [];
163
+ for (const testCase of options.dataset.cases) cases.push(await evaluateCase(options, testCase));
164
+ const report = {
165
+ schemaVersion: "fevex.eval.v1",
166
+ suiteName: options.suiteName,
167
+ targetVersion: options.targetVersion,
168
+ agentName: options.agentName,
169
+ dataset: {
170
+ name: options.dataset.name,
171
+ version: options.dataset.version
172
+ },
173
+ scorerIds: options.scorers.map(({ id }) => id),
174
+ cases,
175
+ summary: summarize(cases)
176
+ };
177
+ for (const reporter of options.reporters ?? []) await reporter.report(report);
178
+ return report;
179
+ }
180
+ function exactOutputScorer(id = "output.exact") {
181
+ return {
182
+ id,
183
+ score({ testCase, output }) {
184
+ if (testCase.expected?.output === void 0) return {
185
+ skipped: true,
186
+ reason: "No expected output"
187
+ };
188
+ const passed = equalJson(output, testCase.expected.output);
189
+ return {
190
+ passed,
191
+ score: passed ? 1 : 0
192
+ };
193
+ }
194
+ };
195
+ }
196
+ function toolSelectionScorer(options = {}) {
197
+ return {
198
+ id: options.id ?? "tools.selected",
199
+ score({ testCase, tools }) {
200
+ const expected = testCase.expected?.tools;
201
+ if (!expected) return {
202
+ skipped: true,
203
+ reason: "No expected tools"
204
+ };
205
+ const passed = options.ordered === false ? [...tools].sort().join("\0") === [...expected].sort().join("\0") : tools.join("\0") === expected.join("\0");
206
+ return {
207
+ passed,
208
+ score: passed ? 1 : 0
209
+ };
210
+ }
211
+ };
212
+ }
213
+ function forbiddenToolsScorer(tools, id = "tools.forbidden") {
214
+ const forbidden = new Set(tools);
215
+ return {
216
+ id,
217
+ score(context) {
218
+ const selected = context.tools.filter((tool) => forbidden.has(tool));
219
+ return {
220
+ passed: selected.length === 0,
221
+ score: selected.length ? 0 : 1,
222
+ ...selected.length ? { details: { selected } } : {}
223
+ };
224
+ }
225
+ };
226
+ }
227
+ function maxLatencyScorer(maxMs, id = "latency.max") {
228
+ if (!Number.isFinite(maxMs) || maxMs < 0) throw new TypeError("maxMs must be non-negative");
229
+ return {
230
+ id,
231
+ score({ latencyMs }) {
232
+ return {
233
+ passed: latencyMs <= maxMs,
234
+ score: latencyMs <= maxMs ? 1 : 0,
235
+ details: {
236
+ actualMs: latencyMs,
237
+ maxMs
238
+ }
239
+ };
240
+ }
241
+ };
242
+ }
243
+ function maxTokensScorer(limits, id = "tokens.max") {
244
+ for (const [name, value] of Object.entries(limits)) if (!Number.isFinite(value) || value < 0) throw new TypeError(`${name} token limit is invalid`);
245
+ return {
246
+ id,
247
+ score({ usage }) {
248
+ if (!usage) return {
249
+ passed: false,
250
+ score: 0,
251
+ details: "Model usage is unavailable"
252
+ };
253
+ const passed = (limits.input === void 0 || (usage.inputTokens ?? Infinity) <= limits.input) && (limits.output === void 0 || (usage.outputTokens ?? Infinity) <= limits.output) && (limits.total === void 0 || (usage.totalTokens ?? Infinity) <= limits.total);
254
+ return {
255
+ passed,
256
+ score: passed ? 1 : 0,
257
+ details: {
258
+ usage: {
259
+ ...usage.inputTokens === void 0 ? {} : { inputTokens: usage.inputTokens },
260
+ ...usage.outputTokens === void 0 ? {} : { outputTokens: usage.outputTokens },
261
+ ...usage.totalTokens === void 0 ? {} : { totalTokens: usage.totalTokens }
262
+ },
263
+ limits: {
264
+ ...limits.input === void 0 ? {} : { input: limits.input },
265
+ ...limits.output === void 0 ? {} : { output: limits.output },
266
+ ...limits.total === void 0 ? {} : { total: limits.total }
267
+ }
268
+ }
269
+ };
270
+ }
271
+ };
272
+ }
273
+ function maxCostScorer(maxAmount, currency, id = "cost.max") {
274
+ if (!Number.isFinite(maxAmount) || maxAmount < 0) throw new TypeError("maxAmount must be non-negative");
275
+ assertNonEmpty(currency, "currency");
276
+ return {
277
+ id,
278
+ score({ cost }) {
279
+ if (!cost) return {
280
+ passed: false,
281
+ score: 0,
282
+ details: "Cost is unavailable"
283
+ };
284
+ const passed = cost.currency === currency && cost.amount <= maxAmount;
285
+ return {
286
+ passed,
287
+ score: passed ? 1 : 0,
288
+ details: {
289
+ actual: {
290
+ amount: cost.amount,
291
+ currency: cost.currency
292
+ },
293
+ maximum: {
294
+ amount: maxAmount,
295
+ currency
296
+ }
297
+ }
298
+ };
299
+ }
300
+ };
301
+ }
302
+ function canonicalize(value) {
303
+ if (Array.isArray(value)) return value.map(canonicalize);
304
+ if (value === null || typeof value !== "object") return value;
305
+ return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => [key, canonicalize(item)]));
306
+ }
307
+ function serializeCanonical(value) {
308
+ return JSON.stringify(canonicalize(value), null, 2);
309
+ }
310
+ function serializeEvalReport(report) {
311
+ return `${serializeCanonical(report)}\n`;
312
+ }
313
+ function parseEvalReport(json) {
314
+ const value = JSON.parse(json);
315
+ if (typeof value !== "object" || value === null || value.schemaVersion !== "fevex.eval.v1" || typeof value.suiteName !== "string" || typeof value.targetVersion !== "string" || typeof value.agentName !== "string" || typeof value.dataset !== "object" || value.dataset === null || typeof value.dataset.name !== "string" || typeof value.dataset.version !== "string" || !Array.isArray(value.cases) || !Array.isArray(value.scorerIds) || !value.scorerIds.every((scorerId) => typeof scorerId === "string" && Boolean(scorerId)) || typeof value.summary !== "object" || value.summary === null) throw new TypeError("Invalid fevex.eval.v1 report");
316
+ const report = value;
317
+ const caseIds = /* @__PURE__ */ new Set();
318
+ for (const testCase of report.cases) {
319
+ if (typeof testCase !== "object" || testCase === null || typeof testCase.caseId !== "string" || !testCase.caseId || caseIds.has(testCase.caseId) || !["completed", "failed"].includes(testCase.status) || !Array.isArray(testCase.tools) || !testCase.tools.every((tool) => typeof tool === "string") || !Number.isFinite(testCase.latencyMs) || testCase.latencyMs < 0 || !Array.isArray(testCase.scores)) throw new TypeError("Invalid fevex.eval.v1 report");
320
+ caseIds.add(testCase.caseId);
321
+ for (const score of testCase.scores) if (typeof score !== "object" || score === null || typeof score.scorerId !== "string" || !report.scorerIds.includes(score.scorerId) || ![
322
+ "passed",
323
+ "failed",
324
+ "skipped",
325
+ "error"
326
+ ].includes(score.status) || score.score !== void 0 && (!Number.isFinite(score.score) || score.score < 0 || score.score > 1)) throw new TypeError("Invalid fevex.eval.v1 report");
327
+ }
328
+ return value;
329
+ }
330
+ function jsonReporter(write) {
331
+ return { report: (report) => write(serializeEvalReport(report)) };
332
+ }
333
+ function textReporter(write) {
334
+ return { report(report) {
335
+ return write(`${[
336
+ `${report.suiteName} (${report.targetVersion})`,
337
+ `dataset ${report.dataset.name}@${report.dataset.version}`,
338
+ ...report.cases.map((testCase) => {
339
+ const passed = testCase.scores.filter(({ status }) => status === "passed").length;
340
+ const failed = testCase.scores.filter(({ status }) => status === "failed" || status === "error").length;
341
+ return `${testCase.caseId}: ${testCase.status}; ${passed} passed, ${failed} failed`;
342
+ }),
343
+ `summary: ${report.summary.completedCount}/${report.summary.caseCount} completed; ${report.summary.failedScoreCount + report.summary.errorScoreCount} failed scores`
344
+ ].join("\n")}\n`);
345
+ } };
346
+ }
347
+ function assertRatio(value, name) {
348
+ if (value !== void 0 && (!Number.isFinite(value) || value < 0)) throw new TypeError(`${name} must be non-negative`);
349
+ }
350
+ function compareEvaluationReports(baseline, current, options = {}) {
351
+ if (baseline.suiteName !== current.suiteName || baseline.dataset.name !== current.dataset.name || baseline.dataset.version !== current.dataset.version) throw new TypeError("Evaluation reports must use the same suite and dataset version");
352
+ assertRatio(options.maxScoreDrop, "maxScoreDrop");
353
+ assertRatio(options.maxLatencyIncreaseRatio, "maxLatencyIncreaseRatio");
354
+ assertRatio(options.maxCostIncreaseRatio, "maxCostIncreaseRatio");
355
+ const maxScoreDrop = options.maxScoreDrop ?? 0;
356
+ const regressions = [];
357
+ const currentCases = new Map(current.cases.map((testCase) => [testCase.caseId, testCase]));
358
+ for (const baselineCase of baseline.cases) {
359
+ const currentCase = currentCases.get(baselineCase.caseId);
360
+ if (!currentCase) {
361
+ regressions.push({
362
+ kind: "case_removed",
363
+ caseId: baselineCase.caseId,
364
+ message: `Case "${baselineCase.caseId}" was removed`
365
+ });
366
+ continue;
367
+ }
368
+ if (baselineCase.status === "completed" && currentCase.status === "failed") regressions.push({
369
+ kind: "case_failed",
370
+ caseId: baselineCase.caseId,
371
+ message: `Case "${baselineCase.caseId}" no longer completes`
372
+ });
373
+ const currentScores = new Map(currentCase.scores.map((score) => [score.scorerId, score]));
374
+ for (const baselineScore of baselineCase.scores) {
375
+ const currentScore = currentScores.get(baselineScore.scorerId);
376
+ if (!currentScore) {
377
+ regressions.push({
378
+ kind: "scorer_removed",
379
+ caseId: baselineCase.caseId,
380
+ scorerId: baselineScore.scorerId,
381
+ message: `Scorer "${baselineScore.scorerId}" was removed from "${baselineCase.caseId}"`
382
+ });
383
+ continue;
384
+ }
385
+ if (baselineScore.status === "passed" && currentScore.status !== "passed") regressions.push({
386
+ kind: "score_failed",
387
+ caseId: baselineCase.caseId,
388
+ scorerId: baselineScore.scorerId,
389
+ message: `Scorer "${baselineScore.scorerId}" changed from pass to fail`
390
+ });
391
+ else if (baselineScore.score !== void 0 && currentScore.score !== void 0 && baselineScore.score - currentScore.score > maxScoreDrop) regressions.push({
392
+ kind: "score_dropped",
393
+ caseId: baselineCase.caseId,
394
+ scorerId: baselineScore.scorerId,
395
+ message: `Scorer "${baselineScore.scorerId}" dropped from ${baselineScore.score} to ${currentScore.score}`
396
+ });
397
+ }
398
+ if (options.maxLatencyIncreaseRatio !== void 0 && baselineCase.latencyMs > 0 && currentCase.latencyMs / baselineCase.latencyMs - 1 > options.maxLatencyIncreaseRatio) regressions.push({
399
+ kind: "latency_increased",
400
+ caseId: baselineCase.caseId,
401
+ message: `Latency increased from ${baselineCase.latencyMs}ms to ${currentCase.latencyMs}ms`
402
+ });
403
+ if (options.maxCostIncreaseRatio !== void 0 && baselineCase.cost && currentCase.cost) {
404
+ if (baselineCase.cost.currency !== currentCase.cost.currency || baselineCase.cost.amount > 0 && currentCase.cost.amount / baselineCase.cost.amount - 1 > options.maxCostIncreaseRatio) regressions.push({
405
+ kind: "cost_increased",
406
+ caseId: baselineCase.caseId,
407
+ message: `Cost changed from ${baselineCase.cost.amount} ${baselineCase.cost.currency} to ${currentCase.cost.amount} ${currentCase.cost.currency}`
408
+ });
409
+ }
410
+ }
411
+ return {
412
+ passed: regressions.length === 0,
413
+ baselineTargetVersion: baseline.targetVersion,
414
+ currentTargetVersion: current.targetVersion,
415
+ regressions
416
+ };
417
+ }
418
+ //#endregion
419
+ export { compareEvaluationReports, exactOutputScorer, forbiddenToolsScorer, jsonReporter, maxCostScorer, maxLatencyScorer, maxTokensScorer, parseEvalReport, runEvaluation, serializeCanonical, serializeEvalReport, textReporter, toolSelectionScorer };
@@ -0,0 +1,32 @@
1
+ import { f as RunId, t as AgentEvent } from "./index-C_Zpr13f.mjs";
2
+ import { ModelGateway } from "./models/index.mjs";
3
+ import { t as AgentDefinition } from "./index-BzxHfyYV.mjs";
4
+ import { _ as RunStore, c as ListEventsOptions, h as RunResult, i as CredentialStore, m as RunRequest, t as AgentRun, u as ResumeRunResolution, v as Session, y as SessionId } from "./index-DGWOGXzc.mjs";
5
+ import { r as ObservabilityOptions } from "./index-ojCY3lwm.mjs";
6
+ import { n as ToolDefinition } from "./index-CZGyhNIQ.mjs";
7
+ import { r as PolicyDefinition } from "./index-QTkd6a7C.mjs";
8
+ //#region src/fevex.d.ts
9
+ interface FevexConfig {
10
+ models: Record<string, ModelGateway>;
11
+ agents: AgentDefinition[];
12
+ tools?: ToolDefinition[];
13
+ runStore?: RunStore;
14
+ credentialStore?: CredentialStore;
15
+ policies?: PolicyDefinition[];
16
+ onEvent?: (event: AgentEvent) => void;
17
+ observability?: ObservabilityOptions;
18
+ }
19
+ interface Fevex {
20
+ startAgent<TInput = unknown, TOutput = unknown>(name: string, request: RunRequest<TInput, TOutput>): Promise<AgentRun<TOutput>>;
21
+ runAgent<TInput = unknown, TOutput = unknown>(name: string, request: RunRequest<TInput, TOutput>): Promise<RunResult<TOutput>>;
22
+ streamAgent<TInput = unknown, TOutput = unknown>(name: string, request: RunRequest<TInput, TOutput>): AsyncIterable<AgentEvent>;
23
+ getRun<TOutput = unknown>(runId: RunId): Promise<AgentRun<TOutput> | undefined>;
24
+ listEvents(runId: RunId, options?: ListEventsOptions): Promise<AgentEvent[]>;
25
+ cancelRun(runId: RunId): Promise<boolean>;
26
+ resumeRun<TOutput = unknown>(runId: RunId, resolution: ResumeRunResolution): Promise<AgentRun<TOutput>>;
27
+ compactSession(sessionId: SessionId, summary: string): Promise<Session>;
28
+ flushObservability(): Promise<void>;
29
+ }
30
+ declare function createFevex(config: FevexConfig): Fevex;
31
+ //#endregion
32
+ export { FevexConfig as n, createFevex as r, Fevex as t };
@@ -0,0 +1,23 @@
1
+ import { t as ExactDefinition } from "./exact-definition-NHBBFlFR.mjs";
2
+ import { ModelRef, ReasoningEffort } from "./models/index.mjs";
3
+ import { StandardSchemaV1 } from "@standard-schema/spec";
4
+ //#region src/agents/index.d.ts
5
+ interface AgentLimits {
6
+ maxSteps?: number;
7
+ maxToolCalls?: number;
8
+ maxInputTokens?: number | false;
9
+ maxOutputTokens?: number | false;
10
+ }
11
+ interface AgentDefinition<TOutput = unknown> {
12
+ name: string;
13
+ instructions: string;
14
+ model?: ModelRef;
15
+ tools?: string[];
16
+ reasoning?: ReasoningEffort;
17
+ modelOptions?: Record<string, unknown>;
18
+ outputSchema?: StandardSchemaV1<unknown, TOutput>;
19
+ limits?: AgentLimits;
20
+ }
21
+ declare function defineAgent<T extends AgentDefinition>(agent: ExactDefinition<T, AgentDefinition>): T;
22
+ //#endregion
23
+ export { AgentLimits as n, defineAgent as r, AgentDefinition as t };
@@ -0,0 +1,47 @@
1
+ import { t as ExactDefinition } from "./exact-definition-NHBBFlFR.mjs";
2
+ import { f as RunId, h as ToolSpec, l as JsonValue, o as ExecutionContext, s as JsonObject } from "./index-C_Zpr13f.mjs";
3
+ import { StandardSchemaV1 } from "@standard-schema/spec";
4
+ //#region src/tools/index.d.ts
5
+ interface ToolExecutionContext {
6
+ runId: RunId;
7
+ toolCallId: string;
8
+ attempt: number;
9
+ idempotencyKey: string;
10
+ getCredential(name: string): Promise<string>;
11
+ context?: ExecutionContext;
12
+ signal?: AbortSignal;
13
+ }
14
+ type ToolRisk = 'read' | 'write' | 'sensitive' | 'destructive';
15
+ type ToolApproval = 'never' | 'required';
16
+ type ToolIdempotency = 'none' | 'keyed';
17
+ interface ToolRetryPolicy {
18
+ maxAttempts: number;
19
+ backoffMs: number;
20
+ maxBackoffMs?: number;
21
+ }
22
+ interface ToolDefinition<TInput = unknown, TOutput = unknown> {
23
+ name: string;
24
+ description?: string;
25
+ inputSchema?: StandardSchemaV1<unknown, TInput>;
26
+ outputSchema?: StandardSchemaV1<unknown, TOutput>;
27
+ risk?: ToolRisk;
28
+ approval?: ToolApproval;
29
+ idempotency?: ToolIdempotency;
30
+ retry?: ToolRetryPolicy;
31
+ credentials?: string[];
32
+ execute(input: TInput, context: ToolExecutionContext): TOutput | Promise<TOutput>;
33
+ }
34
+ type ToolWithSchemas<TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1> = Omit<ToolDefinition<StandardSchemaV1.InferOutput<TInputSchema>, StandardSchemaV1.InferOutput<TOutputSchema>>, 'inputSchema' | 'outputSchema'> & {
35
+ inputSchema: TInputSchema;
36
+ outputSchema: TOutputSchema;
37
+ };
38
+ type ToolWithInputSchema<TInputSchema extends StandardSchemaV1> = Omit<ToolDefinition<StandardSchemaV1.InferOutput<TInputSchema>, unknown>, 'inputSchema'> & {
39
+ inputSchema: TInputSchema;
40
+ };
41
+ declare function defineTool<TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TDefinition extends ToolWithSchemas<TInputSchema, TOutputSchema>>(tool: ToolWithSchemas<TInputSchema, TOutputSchema> & ExactDefinition<TDefinition, ToolWithSchemas<TInputSchema, TOutputSchema>>): TDefinition;
42
+ declare function defineTool<TInputSchema extends StandardSchemaV1, TDefinition extends ToolWithInputSchema<TInputSchema>>(tool: ToolWithInputSchema<TInputSchema> & ExactDefinition<TDefinition, ToolWithInputSchema<TInputSchema>>): TDefinition;
43
+ declare function defineTool<TDefinition extends ToolDefinition>(tool: ToolDefinition & ExactDefinition<TDefinition, ToolDefinition>): TDefinition;
44
+ declare function toToolSpec(tool: ToolDefinition, inputSchema?: JsonObject): ToolSpec;
45
+ type ToolResult = JsonValue;
46
+ //#endregion
47
+ export { ToolResult as a, defineTool as c, ToolIdempotency as i, toToolSpec as l, ToolDefinition as n, ToolRetryPolicy as o, ToolExecutionContext as r, ToolRisk as s, ToolApproval as t };
@@ -0,0 +1,124 @@
1
+ //#region src/core/index.d.ts
2
+ type JsonPrimitive = string | number | boolean | null;
3
+ type JsonObject = {
4
+ [key: string]: JsonValue;
5
+ };
6
+ type JsonValue = JsonPrimitive | JsonValue[] | JsonObject;
7
+ type RunId = string;
8
+ declare const SCHEMA_NOT_TRANSPORTABLE = "SCHEMA_NOT_TRANSPORTABLE";
9
+ declare const PROVIDER_SCHEMA_UNSUPPORTED = "PROVIDER_SCHEMA_UNSUPPORTED";
10
+ declare const PROVIDER_REASONING_UNSUPPORTED = "PROVIDER_REASONING_UNSUPPORTED";
11
+ interface ExecutionContext {
12
+ namespace?: string;
13
+ actor?: {
14
+ id: string;
15
+ type?: string;
16
+ };
17
+ attributes?: JsonObject;
18
+ prompt?: JsonObject;
19
+ }
20
+ type AgentMessageRole = 'system' | 'user' | 'assistant' | 'tool';
21
+ interface AgentMessage {
22
+ role: AgentMessageRole;
23
+ content: string;
24
+ name?: string;
25
+ toolCallId?: string;
26
+ toolCalls?: ToolCall[];
27
+ }
28
+ interface ToolSpec {
29
+ name: string;
30
+ description?: string;
31
+ inputSchema?: JsonObject;
32
+ }
33
+ interface ToolCall {
34
+ id: string;
35
+ name: string;
36
+ input: JsonValue;
37
+ }
38
+ type AgentEventType = 'run.started' | 'run.paused' | 'run.resumed' | 'model.started' | 'model.output.delta' | 'model.completed' | 'tool.started' | 'tool.completed' | 'tool.failed' | 'tool.retrying' | 'tool.execution_unknown' | 'approval.requested' | 'approval.resolved' | 'run.completed' | 'run.failed' | 'run.cancelled';
39
+ interface AgentEventPayloads {
40
+ 'run.started': undefined;
41
+ 'run.paused': {
42
+ reason: 'approval' | 'tool_execution_unknown';
43
+ toolCallId: string;
44
+ };
45
+ 'run.resumed': undefined;
46
+ 'model.started': {
47
+ step: number;
48
+ };
49
+ 'model.output.delta': {
50
+ step: number;
51
+ delta: string;
52
+ };
53
+ 'model.completed': {
54
+ step: number;
55
+ usage?: JsonObject;
56
+ };
57
+ 'tool.started': {
58
+ step: number;
59
+ toolCallId: string;
60
+ toolName: string;
61
+ attempt?: number;
62
+ };
63
+ 'tool.completed': {
64
+ step: number;
65
+ toolCallId: string;
66
+ toolName: string;
67
+ attempt?: number;
68
+ };
69
+ 'tool.failed': {
70
+ step: number;
71
+ toolCallId: string;
72
+ toolName: string;
73
+ error: string;
74
+ };
75
+ 'tool.retrying': {
76
+ step: number;
77
+ toolCallId: string;
78
+ toolName: string;
79
+ attempt: number;
80
+ delayMs: number;
81
+ error: string;
82
+ };
83
+ 'tool.execution_unknown': {
84
+ step: number;
85
+ toolCallId: string;
86
+ toolName: string;
87
+ };
88
+ 'approval.requested': {
89
+ approvalId: string;
90
+ toolCallId: string;
91
+ toolName: string;
92
+ };
93
+ 'approval.resolved': {
94
+ approvalId: string;
95
+ toolCallId: string;
96
+ decision: 'approve' | 'reject';
97
+ actorId: string;
98
+ };
99
+ 'run.completed': {
100
+ output: JsonValue;
101
+ usage?: JsonObject;
102
+ };
103
+ 'run.failed': {
104
+ error: string;
105
+ };
106
+ 'run.cancelled': {
107
+ reason: 'aborted' | 'timeout' | 'approval_rejected';
108
+ };
109
+ }
110
+ interface AgentEventBase {
111
+ id: string;
112
+ sequence: number;
113
+ runId: RunId;
114
+ timestamp: string;
115
+ }
116
+ type AgentEvent<TType extends AgentEventType = AgentEventType> = { [TCurrent in TType]: AgentEventBase & {
117
+ type: TCurrent;
118
+ } & (AgentEventPayloads[TCurrent] extends undefined ? {
119
+ payload?: never;
120
+ } : {
121
+ payload: AgentEventPayloads[TCurrent];
122
+ }); }[TType];
123
+ //#endregion
124
+ export { AgentMessageRole as a, JsonPrimitive as c, PROVIDER_SCHEMA_UNSUPPORTED as d, RunId as f, ToolSpec as h, AgentMessage as i, JsonValue as l, ToolCall as m, AgentEventPayloads as n, ExecutionContext as o, SCHEMA_NOT_TRANSPORTABLE as p, AgentEventType as r, JsonObject as s, AgentEvent as t, PROVIDER_REASONING_UNSUPPORTED as u };