@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.
Files changed (47) hide show
  1. package/README.md +770 -52
  2. package/dist/agents/index.d.mts +1 -22
  3. package/dist/agents/index.mjs +1 -1
  4. package/dist/channels/index.d.mts +2 -0
  5. package/dist/channels/index.mjs +150 -0
  6. package/dist/evals/index.d.mts +153 -0
  7. package/dist/evals/index.mjs +422 -0
  8. package/dist/fevex-Ddyi6z6L.d.mts +60 -0
  9. package/dist/http/index.d.mts +90 -0
  10. package/dist/http/index.mjs +470 -0
  11. package/dist/index-B4PIkqOU.d.mts +80 -0
  12. package/dist/index-Bg9rr8Qe.d.mts +50 -0
  13. package/dist/index-Bgcxgy66.d.mts +82 -0
  14. package/dist/index-CTIwrVf9.d.mts +51 -0
  15. package/dist/index-CqOjvtQ9.d.mts +132 -0
  16. package/dist/index-CrOId2px.d.mts +66 -0
  17. package/dist/index-DeXUtyd9.d.mts +70 -0
  18. package/dist/index-DviHtsLo.d.mts +58 -0
  19. package/dist/index-Dx_LotWZ.d.mts +425 -0
  20. package/dist/index-dkFyTNh4.d.mts +21 -0
  21. package/dist/index.d.mts +39 -15
  22. package/dist/index.mjs +3505 -194
  23. package/dist/knowledge/index.d.mts +2 -0
  24. package/dist/knowledge/index.mjs +89 -0
  25. package/dist/model-stream-u2xMsEaf.mjs +251 -0
  26. package/dist/models/index.d.mts +2 -27
  27. package/dist/observability/index.d.mts +2 -0
  28. package/dist/observability/index.mjs +1 -0
  29. package/dist/policies/index.d.mts +2 -0
  30. package/dist/policies/index.mjs +6 -0
  31. package/dist/run-error-Cr17wPGH.mjs +23 -0
  32. package/dist/runtime/index.d.mts +2 -17
  33. package/dist/runtime/index.mjs +141 -1
  34. package/dist/sandbox/index.d.mts +2 -0
  35. package/dist/sandbox/index.mjs +122 -0
  36. package/dist/teams/index.d.mts +2 -0
  37. package/dist/teams/index.mjs +2 -0
  38. package/dist/teams-Ctz676G4.mjs +82 -0
  39. package/dist/testing/index.d.mts +34 -8
  40. package/dist/testing/index.mjs +572 -23
  41. package/dist/tools/index.d.mts +3 -31
  42. package/dist/tools/index.mjs +222 -2
  43. package/dist/types-CuoRx12Q.d.mts +333 -0
  44. package/dist/workflows/index.d.mts +2 -0
  45. package/dist/workflows/index.mjs +6 -0
  46. package/package.json +39 -3
  47. package/dist/index-D_RBJmVt.d.mts +0 -44
@@ -0,0 +1,122 @@
1
+ import { spawn } from "node:child_process";
2
+ import { realpathSync } from "node:fs";
3
+ import { relative, resolve } from "node:path";
4
+ //#region src/sandbox/sandbox.ts
5
+ var SandboxError = class extends Error {
6
+ code;
7
+ safeMessage;
8
+ name = "SandboxError";
9
+ constructor(code, safeMessage, options) {
10
+ super(safeMessage, options);
11
+ this.code = code;
12
+ this.safeMessage = safeMessage;
13
+ }
14
+ };
15
+ function sandboxResultToJson(result) {
16
+ return {
17
+ exitCode: result.exitCode,
18
+ stdout: result.stdout,
19
+ stderr: result.stderr,
20
+ durationMs: result.durationMs,
21
+ timedOut: result.timedOut
22
+ };
23
+ }
24
+ //#endregion
25
+ //#region src/sandbox/local-sandbox.ts
26
+ /** Creates a subprocess sandbox restricted to a root directory and command allowlist. */
27
+ function createLocalSandbox(options) {
28
+ if (!options.rootDir.trim()) throw new SandboxError("SANDBOX_INVALID_CONFIG", "Sandbox rootDir must be non-empty");
29
+ if (!options.commands.length || options.commands.some((command) => !command.trim())) throw new SandboxError("SANDBOX_INVALID_CONFIG", "Sandbox commands allowlist must contain non-empty commands");
30
+ const rootDir = realpathSync(resolve(options.rootDir));
31
+ const allowed = new Set(options.commands);
32
+ const defaultTimeoutMs = options.defaultTimeoutMs ?? 1e4;
33
+ const maxOutputBytes = options.maxOutputBytes ?? 64e3;
34
+ return { async run(request) {
35
+ if (request.capabilities?.network) throw new SandboxError("SANDBOX_NETWORK_UNSUPPORTED", "Local sandbox does not support network access");
36
+ const command = request.command;
37
+ if (!allowed.has(command) || !request.capabilities?.process?.commands?.includes(command)) throw new SandboxError("SANDBOX_COMMAND_DENIED", `Command "${command}" is not allowed`);
38
+ const cwd = resolve(rootDir, request.cwd ?? request.capabilities.filesystem?.cwd ?? ".");
39
+ if (!isInside(rootDir, cwd)) throw new SandboxError("SANDBOX_CWD_DENIED", "Sandbox cwd must stay inside rootDir");
40
+ const timeoutMs = request.timeoutMs ?? request.capabilities.resources?.timeoutMs ?? request.capabilities.process.timeoutMs ?? defaultTimeoutMs;
41
+ const outputLimit = request.maxOutputBytes ?? request.capabilities.resources?.maxOutputBytes ?? maxOutputBytes;
42
+ if (!Number.isInteger(timeoutMs) || timeoutMs < 1) throw new SandboxError("SANDBOX_INVALID_REQUEST", "Sandbox timeoutMs must be positive");
43
+ if (!Number.isInteger(outputLimit) || outputLimit < 1) throw new SandboxError("SANDBOX_INVALID_REQUEST", "Sandbox maxOutputBytes must be positive");
44
+ return runProcess({
45
+ command,
46
+ args: request.args ?? [],
47
+ cwd,
48
+ env: {
49
+ ...options.env ?? {},
50
+ ...request.env ?? {}
51
+ },
52
+ input: request.input,
53
+ timeoutMs,
54
+ maxOutputBytes: outputLimit,
55
+ signal: request.signal
56
+ });
57
+ } };
58
+ }
59
+ async function runProcess(options) {
60
+ const started = Date.now();
61
+ let timedOut = false;
62
+ let stdout = "";
63
+ let stderr = "";
64
+ return await new Promise((resolvePromise, reject) => {
65
+ options.signal?.throwIfAborted();
66
+ const child = spawn(options.command, [...options.args], {
67
+ cwd: options.cwd,
68
+ env: options.env,
69
+ shell: false,
70
+ stdio: [
71
+ "pipe",
72
+ "pipe",
73
+ "pipe"
74
+ ]
75
+ });
76
+ const abort = () => {
77
+ child.kill("SIGTERM");
78
+ reject(options.signal?.reason ?? new DOMException("Sandbox aborted", "AbortError"));
79
+ };
80
+ const timer = setTimeout(() => {
81
+ timedOut = true;
82
+ child.kill("SIGTERM");
83
+ }, options.timeoutMs);
84
+ options.signal?.addEventListener("abort", abort, { once: true });
85
+ child.stdout.setEncoding("utf8");
86
+ child.stderr.setEncoding("utf8");
87
+ child.stdout.on("data", (chunk) => {
88
+ stdout = appendLimited(stdout, String(chunk), options.maxOutputBytes);
89
+ });
90
+ child.stderr.on("data", (chunk) => {
91
+ stderr = appendLimited(stderr, String(chunk), options.maxOutputBytes);
92
+ });
93
+ child.on("error", (error) => {
94
+ clearTimeout(timer);
95
+ options.signal?.removeEventListener("abort", abort);
96
+ reject(new SandboxError("SANDBOX_PROCESS_ERROR", "Sandbox process failed", { cause: error }));
97
+ });
98
+ child.on("close", (exitCode) => {
99
+ clearTimeout(timer);
100
+ options.signal?.removeEventListener("abort", abort);
101
+ resolvePromise({
102
+ exitCode,
103
+ stdout,
104
+ stderr,
105
+ durationMs: Date.now() - started,
106
+ timedOut
107
+ });
108
+ });
109
+ if (options.input !== void 0) child.stdin.end(options.input);
110
+ else child.stdin.end();
111
+ });
112
+ }
113
+ function appendLimited(current, chunk, maxBytes) {
114
+ const next = current + chunk;
115
+ return Buffer.byteLength(next) <= maxBytes ? next : next.slice(0, maxBytes);
116
+ }
117
+ function isInside(rootDir, value) {
118
+ const path = relative(rootDir, value);
119
+ return path === "" || !path.startsWith("..") && !resolve(path).startsWith("..");
120
+ }
121
+ //#endregion
122
+ export { SandboxError, createLocalSandbox, sandboxResultToJson };
@@ -0,0 +1,2 @@
1
+ import { a as TeamMember, c as defineTeam, i as TeamLimits, n as TeamDelegation, o as TeamStep, r as TeamHandoff, s as TeamTaskResult, t as TeamDefinition } from "../index-Bg9rr8Qe.mjs";
2
+ export { type TeamDefinition, type TeamDelegation, type TeamHandoff, type TeamLimits, type TeamMember, type TeamStep, type TeamTaskResult, defineTeam };
@@ -0,0 +1,2 @@
1
+ import { t as defineTeam } from "../teams-Ctz676G4.mjs";
2
+ export { defineTeam };
@@ -0,0 +1,82 @@
1
+ //#region src/teams/team.ts
2
+ function defineTeam(team) {
3
+ return team;
4
+ }
5
+ /** @internal Compiles teams onto the existing durable workflow engine. */
6
+ function teamAsWorkflow(team) {
7
+ const allowed = /* @__PURE__ */ new Set([team.supervisor, ...team.members.map(({ agent }) => agent)]);
8
+ const limits = team.limits && {
9
+ ...team.limits.maxSteps === void 0 ? {} : { maxSteps: team.limits.maxSteps },
10
+ ...team.limits.maxToolCalls === void 0 ? {} : { maxToolCalls: team.limits.maxToolCalls },
11
+ ...team.limits.maxInputTokens === void 0 ? {} : { maxInputTokens: team.limits.maxInputTokens },
12
+ ...team.limits.maxOutputTokens === void 0 ? {} : { maxOutputTokens: team.limits.maxOutputTokens }
13
+ };
14
+ return {
15
+ name: team.name,
16
+ version: team.version ?? "1",
17
+ inputSchema: team.inputSchema,
18
+ outputSchema: team.outputSchema,
19
+ limits,
20
+ async run(step, input) {
21
+ let delegations = 0;
22
+ const countDelegation = () => {
23
+ delegations += 1;
24
+ if (team.limits?.maxDelegations !== void 0 && delegations > team.limits.maxDelegations) throw new Error(`Team "${team.name}" exceeded maxDelegations limit of ${team.limits.maxDelegations}`);
25
+ };
26
+ const runAgent = async (delegationId, delegation, metadata) => {
27
+ if (!delegationId.trim()) throw new Error("Team delegation id cannot be empty");
28
+ if (!allowed.has(delegation.agent)) throw new Error(`Agent "${delegation.agent}" is not a member of team "${team.name}"`);
29
+ if (delegation.expectedOutput !== void 0 && !delegation.expectedOutput.trim()) throw new Error("Team delegation expectedOutput cannot be empty");
30
+ if (delegation.constraints !== void 0 && (!Array.isArray(delegation.constraints) || delegation.constraints.some((constraint) => typeof constraint !== "string" || !constraint.trim()))) throw new Error("Team delegation constraints must be non-empty strings");
31
+ countDelegation();
32
+ const request = {
33
+ input: delegation.task,
34
+ ...delegation.context === void 0 ? {} : { context: delegation.context },
35
+ ...delegation.limits === void 0 ? {} : { limits: delegation.limits }
36
+ };
37
+ return {
38
+ ...await step.agent(delegationId, delegation.agent, request, { metadata }),
39
+ delegationId,
40
+ agentName: delegation.agent
41
+ };
42
+ };
43
+ return team.run({
44
+ delegate(delegationId, delegation) {
45
+ return runAgent(delegationId, delegation, {
46
+ teamAction: "delegate",
47
+ ...delegation.expectedOutput === void 0 ? {} : { expectedOutput: delegation.expectedOutput },
48
+ ...delegation.constraints === void 0 ? {} : { constraints: delegation.constraints }
49
+ });
50
+ },
51
+ handoff(delegationId, handoff) {
52
+ if (!allowed.has(handoff.from)) throw new Error(`Agent "${handoff.from}" is not a member of team "${team.name}"`);
53
+ if (!handoff.reason.trim()) throw new Error("Team handoff reason cannot be empty");
54
+ return runAgent(delegationId, {
55
+ agent: handoff.to,
56
+ task: handoff.task,
57
+ context: handoff.context,
58
+ limits: handoff.limits,
59
+ expectedOutput: handoff.expectedOutput,
60
+ constraints: handoff.constraints
61
+ }, {
62
+ teamAction: "handoff",
63
+ from: handoff.from,
64
+ reason: handoff.reason,
65
+ ...handoff.expectedOutput === void 0 ? {} : { expectedOutput: handoff.expectedOutput },
66
+ ...handoff.constraints === void 0 ? {} : { constraints: handoff.constraints }
67
+ });
68
+ },
69
+ parallel(stepId, tasks) {
70
+ const width = Object.keys(tasks).length;
71
+ if (team.limits?.maxParallel !== void 0 && width > team.limits.maxParallel) throw new Error(`Team "${team.name}" exceeded maxParallel limit of ${team.limits.maxParallel}`);
72
+ return step.parallel(stepId, tasks, { metadata: {
73
+ teamAction: "merge",
74
+ width
75
+ } });
76
+ }
77
+ }, input);
78
+ }
79
+ };
80
+ }
81
+ //#endregion
82
+ export { teamAsWorkflow as n, defineTeam as t };
@@ -1,16 +1,42 @@
1
- import { d as ToolCall } from "../index-D_RBJmVt.mjs";
2
- import { ModelGateway, ModelGenerateInput, ModelGenerateResult } from "../models/index.mjs";
3
- //#region src/testing/index.d.ts
4
- interface FakeModel extends ModelGateway {
5
- readonly calls: readonly ModelGenerateInput[];
6
- }
7
- declare function fakeModel(...responses: ModelGenerateResult[]): FakeModel;
1
+ import { m as ToolCall } from "../types-CuoRx12Q.mjs";
2
+ import { a as ModelResult, n as ModelInput, t as ModelGateway } from "../index-CTIwrVf9.mjs";
3
+ import { p as DurableRunStore } from "../index-Dx_LotWZ.mjs";
4
+ import { s as MemoryStore } from "../index-DeXUtyd9.mjs";
5
+ import { d as ToolProvider } from "../index-CqOjvtQ9.mjs";
6
+ import { c as ChannelMessage, l as ChannelOutput, n as ChannelAdapter } from "../index-Bgcxgy66.mjs";
7
+ //#region src/testing/contracts.d.ts
8
8
  interface ModelGatewayContract {
9
9
  output?: unknown;
10
10
  toolCall?: ToolCall;
11
11
  usage?: boolean;
12
12
  error?: Error;
13
13
  }
14
+ interface ChannelAdapterContract<TInput, TOutput> {
15
+ input: TInput;
16
+ message: ChannelMessage;
17
+ output: ChannelOutput;
18
+ delivered: TOutput;
19
+ ignoredInput?: TInput;
20
+ }
21
+ interface ToolProviderContract {
22
+ allowedTool: string;
23
+ input?: unknown;
24
+ output?: unknown;
25
+ disallowedTool?: string;
26
+ safeError?: boolean;
27
+ timeout?: boolean;
28
+ }
29
+ declare function testMemoryStore(store: MemoryStore): Promise<void>;
30
+ declare function testToolProvider(provider: ToolProvider, contract: ToolProviderContract): Promise<void>;
31
+ declare function testChannelAdapter<TInput, TOutput>(adapter: ChannelAdapter<TInput, TOutput>, contract: ChannelAdapterContract<TInput, TOutput>): Promise<void>;
14
32
  declare function testModelGateway(model: ModelGateway, contract?: ModelGatewayContract): Promise<void>;
33
+ declare function testRunStore(store: DurableRunStore): Promise<void>;
34
+ //#endregion
35
+ //#region src/testing/fake-model.d.ts
36
+ interface FakeModel extends ModelGateway {
37
+ readonly calls: readonly ModelInput[];
38
+ }
39
+ /** Creates a deterministic model gateway for unit tests. */
40
+ declare function fakeModel(...responses: ModelResult[]): FakeModel;
15
41
  //#endregion
16
- export { FakeModel, ModelGatewayContract, fakeModel, testModelGateway };
42
+ export { ChannelAdapterContract, FakeModel, ModelGatewayContract, ToolProviderContract, fakeModel, testChannelAdapter, testMemoryStore, testModelGateway, testRunStore, testToolProvider };