@almadar/evaluator 2.24.0 → 2.25.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/dist/index.js +62 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isSExpr, isBinding, getOperator, getArgs } from '@almadar/core';
|
|
1
|
+
import { isSExpr, isBinding, getOperator, getArgs, OrbitalZodSchema, safeParseOrbitalSchema } from '@almadar/core';
|
|
2
2
|
export { CORE_BINDINGS, ExpressionSchema, SExprSchema, collectBindings, getArgs, getOperator, isBinding, isSExpr, isSExprAtom, isSExprCall, isValidBinding, parseBinding, sexpr, walkSExpr } from '@almadar/core';
|
|
3
3
|
|
|
4
4
|
// types/expression.ts
|
|
@@ -2563,6 +2563,43 @@ function evalLlmCompact(args, evaluate2, ctx) {
|
|
|
2563
2563
|
const strategy = args.length > 0 ? evaluate2(args[0], ctx) : void 0;
|
|
2564
2564
|
return ctx.llm.compact(strategy);
|
|
2565
2565
|
}
|
|
2566
|
+
function isFieldValue(value) {
|
|
2567
|
+
if (value === null) return true;
|
|
2568
|
+
const kind = typeof value;
|
|
2569
|
+
if (kind === "string" || kind === "number" || kind === "boolean") return true;
|
|
2570
|
+
if (value instanceof Date) return true;
|
|
2571
|
+
if (Array.isArray(value)) return value.every((item) => isFieldValue(item));
|
|
2572
|
+
if (kind === "object" && value !== null && typeof value === "object") {
|
|
2573
|
+
return Object.values(value).every((item) => item === void 0 || isFieldValue(item));
|
|
2574
|
+
}
|
|
2575
|
+
return false;
|
|
2576
|
+
}
|
|
2577
|
+
function isEventPayloadValue(value) {
|
|
2578
|
+
if (value === null || value === void 0) return true;
|
|
2579
|
+
const kind = typeof value;
|
|
2580
|
+
if (kind === "string" || kind === "number" || kind === "boolean") return true;
|
|
2581
|
+
if (value instanceof Date) return true;
|
|
2582
|
+
if (Array.isArray(value)) return value.every((item) => isEventPayloadValue(item));
|
|
2583
|
+
if (kind === "object" && value !== null && typeof value === "object") {
|
|
2584
|
+
return Object.values(value).every((item) => isEventPayloadValue(item));
|
|
2585
|
+
}
|
|
2586
|
+
return false;
|
|
2587
|
+
}
|
|
2588
|
+
function isSessionHistoryEntry(value) {
|
|
2589
|
+
if (typeof value !== "object" || value === null) return false;
|
|
2590
|
+
return "role" in value && typeof value.role === "string" && "content" in value && typeof value.content === "string" && "timestamp" in value && typeof value.timestamp === "number";
|
|
2591
|
+
}
|
|
2592
|
+
function isPlanSnapshot(value) {
|
|
2593
|
+
if (typeof value !== "object" || value === null) return false;
|
|
2594
|
+
const statuses = ["proposed", "confirmed", "built", "failed"];
|
|
2595
|
+
return "schemaVersion" in value && value.schemaVersion === 1 && "status" in value && statuses.some((s) => s === value.status) && "builtAt" in value && typeof value.builtAt === "string" && "orbitals" in value && Array.isArray(value.orbitals) && "renames" in value && Array.isArray(value.renames) && "deletedOrbitals" in value && Array.isArray(value.deletedOrbitals);
|
|
2596
|
+
}
|
|
2597
|
+
function isOrbital(value) {
|
|
2598
|
+
return OrbitalZodSchema.safeParse(value).success;
|
|
2599
|
+
}
|
|
2600
|
+
function isOrbitalSchemaValue(value) {
|
|
2601
|
+
return safeParseOrbitalSchema(value).success;
|
|
2602
|
+
}
|
|
2566
2603
|
|
|
2567
2604
|
// std/workspace.ts
|
|
2568
2605
|
function evalWorkspaceReadOrbital(args, evaluate2, ctx) {
|
|
@@ -2574,6 +2611,9 @@ function evalWorkspaceWriteOrbital(args, evaluate2, ctx) {
|
|
|
2574
2611
|
if (!ctx.workspace) return null;
|
|
2575
2612
|
const name = evaluate2(args[0], ctx);
|
|
2576
2613
|
const content = evaluate2(args[1], ctx);
|
|
2614
|
+
if (!isOrbital(content)) {
|
|
2615
|
+
throw new Error(`workspace/write-orbital value for "${name}" is not a valid orbital definition`);
|
|
2616
|
+
}
|
|
2577
2617
|
return ctx.workspace.writeOrbital(name, content);
|
|
2578
2618
|
}
|
|
2579
2619
|
function evalWorkspaceReadFile(args, evaluate2, ctx) {
|
|
@@ -2603,6 +2643,9 @@ function evalWorkspaceReadSchema(_args, _evaluate, ctx) {
|
|
|
2603
2643
|
function evalWorkspaceWriteSchema(args, evaluate2, ctx) {
|
|
2604
2644
|
if (!ctx.workspace) return null;
|
|
2605
2645
|
const schema = evaluate2(args[0], ctx);
|
|
2646
|
+
if (!isOrbitalSchemaValue(schema)) {
|
|
2647
|
+
throw new Error("workspace/write-schema value is not a valid orbital schema");
|
|
2648
|
+
}
|
|
2606
2649
|
return ctx.workspace.writeSchema(schema);
|
|
2607
2650
|
}
|
|
2608
2651
|
function evalWorkspaceReadPlan(_args, _evaluate, ctx) {
|
|
@@ -2612,6 +2655,9 @@ function evalWorkspaceReadPlan(_args, _evaluate, ctx) {
|
|
|
2612
2655
|
function evalWorkspaceWritePlan(args, evaluate2, ctx) {
|
|
2613
2656
|
if (!ctx.workspace) return null;
|
|
2614
2657
|
const plan = evaluate2(args[0], ctx);
|
|
2658
|
+
if (!isPlanSnapshot(plan)) {
|
|
2659
|
+
throw new Error("workspace/write-plan value is not a valid plan snapshot (schemaVersion 1 envelope)");
|
|
2660
|
+
}
|
|
2615
2661
|
return ctx.workspace.writePlan(plan);
|
|
2616
2662
|
}
|
|
2617
2663
|
function evalWorkspaceArchiveOrbital(args, evaluate2, ctx) {
|
|
@@ -2630,6 +2676,9 @@ function evalSessionWriteSpec(args, evaluate2, ctx) {
|
|
|
2630
2676
|
if (!ctx.session) return null;
|
|
2631
2677
|
const orbitalName = evaluate2(args[0], ctx);
|
|
2632
2678
|
const spec = evaluate2(args[1], ctx);
|
|
2679
|
+
if (!isOrbital(spec)) {
|
|
2680
|
+
throw new Error(`session/write-spec value for "${orbitalName}" is not a valid orbital definition`);
|
|
2681
|
+
}
|
|
2633
2682
|
return ctx.session.writeSpec(orbitalName, spec);
|
|
2634
2683
|
}
|
|
2635
2684
|
function evalSessionReadMemory(args, evaluate2, ctx) {
|
|
@@ -2652,6 +2701,9 @@ function evalSessionAppendHistory(args, evaluate2, ctx) {
|
|
|
2652
2701
|
if (!ctx.session) return null;
|
|
2653
2702
|
const orbitalName = evaluate2(args[0], ctx);
|
|
2654
2703
|
const entry = evaluate2(args[1], ctx);
|
|
2704
|
+
if (!isSessionHistoryEntry(entry)) {
|
|
2705
|
+
throw new Error(`session/append-history entry for "${orbitalName}" must have role/content/timestamp`);
|
|
2706
|
+
}
|
|
2655
2707
|
return ctx.session.appendHistory(orbitalName, entry);
|
|
2656
2708
|
}
|
|
2657
2709
|
function evalSessionReadErrors(args, evaluate2, ctx) {
|
|
@@ -2696,6 +2748,9 @@ function evalTraceEmit(args, evaluate2, ctx) {
|
|
|
2696
2748
|
if (!ctx.trace) return;
|
|
2697
2749
|
const event = evaluate2(args[0], ctx);
|
|
2698
2750
|
const payload = args.length > 1 ? evaluate2(args[1], ctx) : void 0;
|
|
2751
|
+
if (!isEventPayloadValue(payload)) {
|
|
2752
|
+
throw new Error(`trace/emit payload for "${event}" is not an event-payload value (JSON-like)`);
|
|
2753
|
+
}
|
|
2699
2754
|
ctx.trace.emit(event, payload);
|
|
2700
2755
|
}
|
|
2701
2756
|
function evalTraceLog(args, evaluate2, ctx) {
|
|
@@ -2703,6 +2758,9 @@ function evalTraceLog(args, evaluate2, ctx) {
|
|
|
2703
2758
|
const message = evaluate2(args[0], ctx);
|
|
2704
2759
|
const level = args.length > 1 ? evaluate2(args[1], ctx) : void 0;
|
|
2705
2760
|
const data = args.length > 2 ? evaluate2(args[2], ctx) : void 0;
|
|
2761
|
+
if (!isEventPayloadValue(data)) {
|
|
2762
|
+
throw new Error("trace/log data is not an event-payload value (JSON-like)");
|
|
2763
|
+
}
|
|
2706
2764
|
ctx.trace.log(message, level, data);
|
|
2707
2765
|
}
|
|
2708
2766
|
|
|
@@ -2712,6 +2770,9 @@ function evalIntegrationHttp(args, evaluate2, ctx) {
|
|
|
2712
2770
|
const method = evaluate2(args[0], ctx);
|
|
2713
2771
|
const url = evaluate2(args[1], ctx);
|
|
2714
2772
|
const body = args.length > 2 ? evaluate2(args[2], ctx) : void 0;
|
|
2773
|
+
if (body !== void 0 && !isFieldValue(body)) {
|
|
2774
|
+
throw new Error(`integration/http body for ${method} ${url} is not a field value (JSON-like)`);
|
|
2775
|
+
}
|
|
2715
2776
|
const headers = args.length > 3 ? evaluate2(args[3], ctx) : void 0;
|
|
2716
2777
|
return ctx.integration.http(method, url, body, headers);
|
|
2717
2778
|
}
|