@fevex/core 0.1.0-alpha.0 → 0.1.0-alpha.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/README.md +770 -52
- package/dist/agents/index.d.mts +1 -22
- package/dist/agents/index.mjs +1 -1
- package/dist/channels/index.d.mts +2 -0
- package/dist/channels/index.mjs +150 -0
- package/dist/evals/index.d.mts +153 -0
- package/dist/evals/index.mjs +422 -0
- package/dist/fevex-Ddyi6z6L.d.mts +60 -0
- package/dist/http/index.d.mts +90 -0
- package/dist/http/index.mjs +470 -0
- package/dist/index-B4PIkqOU.d.mts +80 -0
- package/dist/index-Bg9rr8Qe.d.mts +50 -0
- package/dist/index-Bgcxgy66.d.mts +82 -0
- package/dist/index-CTIwrVf9.d.mts +51 -0
- package/dist/index-CqOjvtQ9.d.mts +132 -0
- package/dist/index-CrOId2px.d.mts +66 -0
- package/dist/index-DeXUtyd9.d.mts +70 -0
- package/dist/index-DviHtsLo.d.mts +58 -0
- package/dist/index-Dx_LotWZ.d.mts +425 -0
- package/dist/index-dkFyTNh4.d.mts +21 -0
- package/dist/index.d.mts +39 -15
- package/dist/index.mjs +3505 -194
- package/dist/knowledge/index.d.mts +2 -0
- package/dist/knowledge/index.mjs +89 -0
- package/dist/model-stream-u2xMsEaf.mjs +251 -0
- package/dist/models/index.d.mts +2 -27
- package/dist/observability/index.d.mts +2 -0
- package/dist/observability/index.mjs +1 -0
- package/dist/policies/index.d.mts +2 -0
- package/dist/policies/index.mjs +6 -0
- package/dist/run-error-Cr17wPGH.mjs +23 -0
- package/dist/runtime/index.d.mts +2 -17
- package/dist/runtime/index.mjs +141 -1
- package/dist/sandbox/index.d.mts +2 -0
- package/dist/sandbox/index.mjs +122 -0
- package/dist/teams/index.d.mts +2 -0
- package/dist/teams/index.mjs +2 -0
- package/dist/teams-Ctz676G4.mjs +82 -0
- package/dist/testing/index.d.mts +34 -8
- package/dist/testing/index.mjs +572 -23
- package/dist/tools/index.d.mts +3 -31
- package/dist/tools/index.mjs +222 -2
- package/dist/types-CuoRx12Q.d.mts +333 -0
- package/dist/workflows/index.d.mts +2 -0
- package/dist/workflows/index.mjs +6 -0
- package/package.json +39 -3
- package/dist/index-D_RBJmVt.d.mts +0 -44
package/dist/agents/index.d.mts
CHANGED
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
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
|
|
1
|
+
import { n as AgentLimits, r as defineAgent, t as AgentDefinition } from "../index-Dx_LotWZ.mjs";
|
|
23
2
|
export { AgentDefinition, AgentLimits, defineAgent };
|
package/dist/agents/index.mjs
CHANGED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as ChannelEvent, c as ChannelMessage, d as ChannelRunOptions, f as ChannelRunResult, i as ChannelError, l as ChannelOutput, n as ChannelAdapter, o as ChannelEventType, r as ChannelContext, s as ChannelFailurePhase, t as handleChannelInput, u as ChannelRunEvent } from "../index-Bgcxgy66.mjs";
|
|
2
|
+
export { ChannelAdapter, ChannelContext, ChannelError, ChannelEvent, ChannelEventType, ChannelFailurePhase, ChannelMessage, ChannelOutput, ChannelRunEvent, ChannelRunOptions, ChannelRunResult, handleChannelInput };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
//#region src/channels/channel.ts
|
|
2
|
+
var ChannelError = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
safeMessage;
|
|
5
|
+
name = "ChannelError";
|
|
6
|
+
constructor(code, safeMessage, options) {
|
|
7
|
+
super(safeMessage, options);
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.safeMessage = safeMessage;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/channels/handle-channel-input.ts
|
|
14
|
+
/** Parses one channel input, runs the configured agent, and delivers its output. */
|
|
15
|
+
async function handleChannelInput(input, options) {
|
|
16
|
+
const channelEvents = [];
|
|
17
|
+
const emit = (event) => {
|
|
18
|
+
channelEvents.push(event);
|
|
19
|
+
options.onEvent?.(event);
|
|
20
|
+
};
|
|
21
|
+
let parsed;
|
|
22
|
+
try {
|
|
23
|
+
parsed = await options.adapter.parse(input, { signal: options.signal });
|
|
24
|
+
} catch (cause) {
|
|
25
|
+
const error = channelError("CHANNEL_PARSE_FAILED", "Channel parse failed", cause);
|
|
26
|
+
emit(failed(options.adapter.name, "parse", error));
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
if (parsed === null) return {
|
|
30
|
+
ignored: true,
|
|
31
|
+
events: []
|
|
32
|
+
};
|
|
33
|
+
const message = parsed;
|
|
34
|
+
emit(received(options.adapter.name, message));
|
|
35
|
+
let result;
|
|
36
|
+
try {
|
|
37
|
+
const sessionId = await options.resolveSessionId?.(message);
|
|
38
|
+
result = await options.fevex.runAgent(options.agentName, {
|
|
39
|
+
input: message.content,
|
|
40
|
+
...sessionId ? { sessionId } : {},
|
|
41
|
+
context: channelContext(options.adapter.name, message),
|
|
42
|
+
signal: options.signal
|
|
43
|
+
});
|
|
44
|
+
} catch (cause) {
|
|
45
|
+
const error = channelError("CHANNEL_RUN_FAILED", "Channel run failed", cause);
|
|
46
|
+
emit(failed(options.adapter.name, "run", error, message));
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
const run = await options.fevex.getRun(result.runId);
|
|
50
|
+
if (!run || run.kind === "workflow" || run.kind === "team") {
|
|
51
|
+
const error = channelError("CHANNEL_RUN_FAILED", "Channel run was not found after completion");
|
|
52
|
+
emit(failed(options.adapter.name, "run", error, message));
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
const output = {
|
|
56
|
+
deliveryId: message.deliveryId,
|
|
57
|
+
conversationId: message.conversationId,
|
|
58
|
+
...message.threadId ? { threadId: message.threadId } : {},
|
|
59
|
+
content: stringifyOutput(result.output),
|
|
60
|
+
metadata: {
|
|
61
|
+
runId: result.runId,
|
|
62
|
+
sessionId: result.sessionId
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
let delivery;
|
|
66
|
+
try {
|
|
67
|
+
delivery = await options.adapter.deliver(output, { signal: options.signal });
|
|
68
|
+
} catch (cause) {
|
|
69
|
+
const error = channelError("CHANNEL_DELIVERY_FAILED", "Channel delivery failed", cause);
|
|
70
|
+
emit(failed(options.adapter.name, "deliver", error, message));
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
const deliveredEvent = delivered(options.adapter.name, message);
|
|
74
|
+
emit(deliveredEvent);
|
|
75
|
+
return {
|
|
76
|
+
ignored: false,
|
|
77
|
+
message,
|
|
78
|
+
run,
|
|
79
|
+
output,
|
|
80
|
+
delivery,
|
|
81
|
+
events: [
|
|
82
|
+
channelEvents[0],
|
|
83
|
+
...result.events ?? [],
|
|
84
|
+
deliveredEvent
|
|
85
|
+
]
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function channelContext(adapter, message) {
|
|
89
|
+
return {
|
|
90
|
+
namespace: adapter,
|
|
91
|
+
...message.actor ? { actor: message.actor } : {},
|
|
92
|
+
attributes: {
|
|
93
|
+
...message.metadata ?? {},
|
|
94
|
+
channel: adapter,
|
|
95
|
+
messageId: message.id,
|
|
96
|
+
deliveryId: message.deliveryId,
|
|
97
|
+
conversationId: message.conversationId,
|
|
98
|
+
...message.threadId ? { threadId: message.threadId } : {}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function received(adapter, message) {
|
|
103
|
+
return {
|
|
104
|
+
type: "channel.received",
|
|
105
|
+
id: crypto.randomUUID(),
|
|
106
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
107
|
+
adapter,
|
|
108
|
+
messageId: message.id,
|
|
109
|
+
deliveryId: message.deliveryId,
|
|
110
|
+
conversationId: message.conversationId,
|
|
111
|
+
...message.threadId ? { threadId: message.threadId } : {},
|
|
112
|
+
...message.actor ? { actor: message.actor } : {}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function delivered(adapter, message) {
|
|
116
|
+
return {
|
|
117
|
+
type: "channel.delivered",
|
|
118
|
+
id: crypto.randomUUID(),
|
|
119
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
120
|
+
adapter,
|
|
121
|
+
messageId: message.id,
|
|
122
|
+
deliveryId: message.deliveryId,
|
|
123
|
+
conversationId: message.conversationId,
|
|
124
|
+
...message.threadId ? { threadId: message.threadId } : {}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function failed(adapter, phase, error, message) {
|
|
128
|
+
return {
|
|
129
|
+
type: "channel.failed",
|
|
130
|
+
id: crypto.randomUUID(),
|
|
131
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
132
|
+
adapter,
|
|
133
|
+
phase,
|
|
134
|
+
error: error.safeMessage,
|
|
135
|
+
...message ? {
|
|
136
|
+
messageId: message.id,
|
|
137
|
+
deliveryId: message.deliveryId,
|
|
138
|
+
conversationId: message.conversationId,
|
|
139
|
+
...message.threadId ? { threadId: message.threadId } : {}
|
|
140
|
+
} : {}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function channelError(code, safeMessage, cause) {
|
|
144
|
+
return new ChannelError(code, safeMessage, cause === void 0 ? void 0 : { cause });
|
|
145
|
+
}
|
|
146
|
+
function stringifyOutput(value) {
|
|
147
|
+
return typeof value === "string" ? value : JSON.stringify(value);
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
export { ChannelError, handleChannelInput };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { l as JsonValue, o as ExecutionContext, t as AgentEvent } from "../types-CuoRx12Q.mjs";
|
|
2
|
+
import { r as ModelMetadata, s as ModelUsage } from "../index-CTIwrVf9.mjs";
|
|
3
|
+
import { l as TraceCost, t as CostCalculator } from "../index-B4PIkqOU.mjs";
|
|
4
|
+
import { t as Fevex } from "../fevex-Ddyi6z6L.mjs";
|
|
5
|
+
//#region src/evals/canonical-json.d.ts
|
|
6
|
+
/** Serializes JSON-like data with stable object-key ordering. */
|
|
7
|
+
declare function serializeCanonical(value: unknown): string;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/evals/types.d.ts
|
|
10
|
+
interface EvalExpectation {
|
|
11
|
+
output?: JsonValue;
|
|
12
|
+
tools?: string[];
|
|
13
|
+
}
|
|
14
|
+
interface EvalCase<TInput = unknown> {
|
|
15
|
+
id: string;
|
|
16
|
+
input: TInput;
|
|
17
|
+
expected?: EvalExpectation;
|
|
18
|
+
context?: ExecutionContext;
|
|
19
|
+
}
|
|
20
|
+
interface EvalDataset<TInput = unknown> {
|
|
21
|
+
name: string;
|
|
22
|
+
version: string;
|
|
23
|
+
cases: readonly EvalCase<TInput>[];
|
|
24
|
+
}
|
|
25
|
+
interface EvalScorerContext<TInput = unknown> {
|
|
26
|
+
testCase: EvalCase<TInput>;
|
|
27
|
+
output?: JsonValue;
|
|
28
|
+
tools: readonly string[];
|
|
29
|
+
events: readonly AgentEvent[];
|
|
30
|
+
usage?: ModelUsage;
|
|
31
|
+
cost?: TraceCost;
|
|
32
|
+
latencyMs: number;
|
|
33
|
+
error?: string;
|
|
34
|
+
}
|
|
35
|
+
type EvalScorerResult = {
|
|
36
|
+
passed: boolean;
|
|
37
|
+
score: number;
|
|
38
|
+
details?: JsonValue;
|
|
39
|
+
} | {
|
|
40
|
+
skipped: true;
|
|
41
|
+
reason?: string;
|
|
42
|
+
};
|
|
43
|
+
interface EvalScorer<TInput = unknown> {
|
|
44
|
+
id: string;
|
|
45
|
+
score(context: EvalScorerContext<TInput>): EvalScorerResult | Promise<EvalScorerResult>;
|
|
46
|
+
}
|
|
47
|
+
type EvalScoreStatus = 'passed' | 'failed' | 'skipped' | 'error';
|
|
48
|
+
interface EvalScore {
|
|
49
|
+
scorerId: string;
|
|
50
|
+
status: EvalScoreStatus;
|
|
51
|
+
score?: number;
|
|
52
|
+
details?: JsonValue;
|
|
53
|
+
error?: string;
|
|
54
|
+
}
|
|
55
|
+
interface EvalCaseReport {
|
|
56
|
+
caseId: string;
|
|
57
|
+
status: 'completed' | 'failed';
|
|
58
|
+
output?: JsonValue;
|
|
59
|
+
tools: string[];
|
|
60
|
+
usage?: ModelUsage;
|
|
61
|
+
cost?: TraceCost;
|
|
62
|
+
latencyMs: number;
|
|
63
|
+
scores: EvalScore[];
|
|
64
|
+
error?: string;
|
|
65
|
+
}
|
|
66
|
+
interface EvalSummary {
|
|
67
|
+
caseCount: number;
|
|
68
|
+
completedCount: number;
|
|
69
|
+
failedCount: number;
|
|
70
|
+
passedScoreCount: number;
|
|
71
|
+
failedScoreCount: number;
|
|
72
|
+
skippedScoreCount: number;
|
|
73
|
+
errorScoreCount: number;
|
|
74
|
+
averageScore?: number;
|
|
75
|
+
usage?: ModelUsage;
|
|
76
|
+
cost?: TraceCost;
|
|
77
|
+
latencyMs: number;
|
|
78
|
+
}
|
|
79
|
+
interface EvalReport {
|
|
80
|
+
schemaVersion: 'fevex.eval.v1';
|
|
81
|
+
suiteName: string;
|
|
82
|
+
targetVersion: string;
|
|
83
|
+
agentName: string;
|
|
84
|
+
dataset: {
|
|
85
|
+
name: string;
|
|
86
|
+
version: string;
|
|
87
|
+
};
|
|
88
|
+
scorerIds: string[];
|
|
89
|
+
cases: EvalCaseReport[];
|
|
90
|
+
summary: EvalSummary;
|
|
91
|
+
}
|
|
92
|
+
interface EvalReporter {
|
|
93
|
+
report(report: Readonly<EvalReport>): void | Promise<void>;
|
|
94
|
+
}
|
|
95
|
+
interface EvalCostOptions {
|
|
96
|
+
calculate: CostCalculator;
|
|
97
|
+
modelRegistryName: string;
|
|
98
|
+
model?: ModelMetadata;
|
|
99
|
+
}
|
|
100
|
+
interface RunEvaluationOptions<TInput = unknown> {
|
|
101
|
+
app: Fevex;
|
|
102
|
+
suiteName: string;
|
|
103
|
+
targetVersion: string;
|
|
104
|
+
agentName: string;
|
|
105
|
+
dataset: EvalDataset<TInput>;
|
|
106
|
+
scorers: readonly EvalScorer<TInput>[];
|
|
107
|
+
reporters?: readonly EvalReporter[];
|
|
108
|
+
cost?: EvalCostOptions;
|
|
109
|
+
signal?: AbortSignal;
|
|
110
|
+
}
|
|
111
|
+
interface Regression {
|
|
112
|
+
kind: 'case_removed' | 'case_failed' | 'scorer_removed' | 'score_failed' | 'score_dropped' | 'latency_increased' | 'cost_increased';
|
|
113
|
+
caseId: string;
|
|
114
|
+
scorerId?: string;
|
|
115
|
+
message: string;
|
|
116
|
+
}
|
|
117
|
+
interface RegressionReport {
|
|
118
|
+
passed: boolean;
|
|
119
|
+
baselineTargetVersion: string;
|
|
120
|
+
currentTargetVersion: string;
|
|
121
|
+
regressions: Regression[];
|
|
122
|
+
}
|
|
123
|
+
interface RegressionOptions {
|
|
124
|
+
maxScoreDrop?: number;
|
|
125
|
+
maxLatencyIncreaseRatio?: number;
|
|
126
|
+
maxCostIncreaseRatio?: number;
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/evals/evaluation.d.ts
|
|
130
|
+
/** Runs every case and scorer, producing a deterministic aggregate report. */
|
|
131
|
+
declare function runEvaluation<TInput = unknown>(options: RunEvaluationOptions<TInput>): Promise<EvalReport>;
|
|
132
|
+
declare function serializeEvalReport(report: EvalReport): string;
|
|
133
|
+
declare function parseEvalReport(json: string): EvalReport;
|
|
134
|
+
declare function jsonReporter(write: (output: string) => void | Promise<void>): EvalReporter;
|
|
135
|
+
declare function textReporter(write: (output: string) => void | Promise<void>): EvalReporter;
|
|
136
|
+
declare function compareEvaluationReports(baseline: EvalReport, current: EvalReport, options?: RegressionOptions): RegressionReport;
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/evals/scorers.d.ts
|
|
139
|
+
declare function exactOutputScorer(id?: string): EvalScorer;
|
|
140
|
+
declare function toolSelectionScorer(options?: {
|
|
141
|
+
id?: string;
|
|
142
|
+
ordered?: boolean;
|
|
143
|
+
}): EvalScorer;
|
|
144
|
+
declare function forbiddenToolsScorer(tools: readonly string[], id?: string): EvalScorer;
|
|
145
|
+
declare function maxLatencyScorer(maxMs: number, id?: string): EvalScorer;
|
|
146
|
+
declare function maxTokensScorer(limits: {
|
|
147
|
+
input?: number;
|
|
148
|
+
output?: number;
|
|
149
|
+
total?: number;
|
|
150
|
+
}, id?: string): EvalScorer;
|
|
151
|
+
declare function maxCostScorer(maxAmount: number, currency: string, id?: string): EvalScorer;
|
|
152
|
+
//#endregion
|
|
153
|
+
export { EvalCase, EvalCaseReport, EvalCostOptions, EvalDataset, EvalExpectation, EvalReport, EvalReporter, EvalScore, EvalScoreStatus, EvalScorer, EvalScorerContext, EvalScorerResult, EvalSummary, Regression, RegressionOptions, RegressionReport, RunEvaluationOptions, compareEvaluationReports, exactOutputScorer, forbiddenToolsScorer, jsonReporter, maxCostScorer, maxLatencyScorer, maxTokensScorer, parseEvalReport, runEvaluation, serializeCanonical, serializeEvalReport, textReporter, toolSelectionScorer };
|