@almadar/evaluator 2.36.0 → 2.38.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TraitConfig, AgentContext, LlmContext, WorkspaceContext, SessionContext, MemoryContext, TraceContext, IntegrationContext, SExpr } from '@almadar/core';
|
|
1
|
+
import { UserContext, TraitConfig, AgentContext, LlmContext, WorkspaceContext, SessionContext, MemoryContext, TraceContext, IntegrationContext, SExpr } from '@almadar/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Evaluation Context
|
|
@@ -9,23 +9,6 @@ import { TraitConfig, AgentContext, LlmContext, WorkspaceContext, SessionContext
|
|
|
9
9
|
* @packageDocumentation
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* User context for @user bindings (role-based UI).
|
|
14
|
-
*/
|
|
15
|
-
interface UserContext {
|
|
16
|
-
/** User's unique ID */
|
|
17
|
-
id: string;
|
|
18
|
-
/** User's email */
|
|
19
|
-
email?: string;
|
|
20
|
-
/** User's display name */
|
|
21
|
-
name?: string;
|
|
22
|
-
/** User's role (for RBAC) */
|
|
23
|
-
role?: string;
|
|
24
|
-
/** User's permissions */
|
|
25
|
-
permissions?: string[];
|
|
26
|
-
/** Additional custom profile fields */
|
|
27
|
-
[key: string]: unknown;
|
|
28
|
-
}
|
|
29
12
|
/**
|
|
30
13
|
* Evaluation context for S-expression evaluation.
|
|
31
14
|
* Provides all bindings and effect handlers needed at runtime.
|
|
@@ -456,4 +439,4 @@ declare function evalWatch(args: SExpr[], evaluate: Evaluator, ctx: EvaluationCo
|
|
|
456
439
|
*/
|
|
457
440
|
declare function evalAtomic(args: SExpr[], evaluate: Evaluator, ctx: EvaluationContext): unknown;
|
|
458
441
|
|
|
459
|
-
export {
|
|
442
|
+
export { evalSetDynamic as $, evalGreaterThanOrEqual as A, evalIf as B, evalIncludes as C, evalIncrement as D, type EvaluationContext as E, evalLast as F, evalLessThan as G, evalLessThanOrEqual as H, evalLet as I, evalList as J, evalMap as K, evalMatches as L, evalMax as M, evalMin as N, evalModulo as O, evalMultiply as P, evalNavigate as Q, evalNot as R, evalNotEqual as S, evalNotify as T, evalNth as U, evalOr as V, evalPersist as W, evalRef as X, evalRenderUI as Y, evalRound as Z, evalSet as _, createEffectContext as a, evalSpawn as a0, evalSubtract as a1, evalSum as a2, evalSwap as a3, evalWatch as a4, evalWhen as a5, resolveBinding as a6, createMinimalContext as b, createChildContext as c, evalAdd as d, evalAbs as e, evalAnd as f, evalAtomic as g, evalCallService as h, evalCeil as i, evalClamp as j, evalConcat as k, evalCount as l, evalDecrement as m, evalDeref as n, evalDespawn as o, evalDivide as p, evalDo as q, evalEmit as r, evalEmpty as s, evalEqual as t, evalFilter as u, evalFind as v, evalFirst as w, evalFloor as x, evalFn as y, evalGreaterThan as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SExpr, ListenPayloadEvaluator } from '@almadar/core';
|
|
2
|
-
export { CORE_BINDINGS, CoreBinding, Expression, ExpressionSchema, ParsedBinding, SExpr, SExprAtom, SExprSchema, collectBindings, getArgs, getOperator, isBinding, isSExpr, isSExprAtom, isSExprCall, isValidBinding, parseBinding, sexpr, walkSExpr } from '@almadar/core';
|
|
3
|
-
import { E as EvaluationContext } from './index-
|
|
4
|
-
export {
|
|
2
|
+
export { CORE_BINDINGS, CoreBinding, Expression, ExpressionSchema, ParsedBinding, SExpr, SExprAtom, SExprSchema, UserContext, collectBindings, getArgs, getOperator, isBinding, isSExpr, isSExprAtom, isSExprCall, isValidBinding, parseBinding, sexpr, walkSExpr } from '@almadar/core';
|
|
3
|
+
import { E as EvaluationContext } from './index-dAA7DJ-s.js';
|
|
4
|
+
export { c as createChildContext, a as createEffectContext, b as createMinimalContext, e as evalAbs, d as evalAdd, f as evalAnd, g as evalAtomic, h as evalCallService, i as evalCeil, j as evalClamp, k as evalConcat, l as evalCount, m as evalDecrement, n as evalDeref, o as evalDespawn, p as evalDivide, q as evalDo, r as evalEmit, s as evalEmpty, t as evalEqual, u as evalFilter, v as evalFind, w as evalFirst, x as evalFloor, y as evalFn, z as evalGreaterThan, A as evalGreaterThanOrEqual, B as evalIf, C as evalIncludes, D as evalIncrement, F as evalLast, G as evalLessThan, H as evalLessThanOrEqual, I as evalLet, J as evalList, K as evalMap, L as evalMatches, M as evalMax, N as evalMin, O as evalModulo, P as evalMultiply, Q as evalNavigate, R as evalNot, S as evalNotEqual, T as evalNotify, U as evalNth, V as evalOr, W as evalPersist, X as evalRef, Y as evalRenderUI, Z as evalRound, _ as evalSet, $ as evalSetDynamic, a0 as evalSpawn, a1 as evalSubtract, a2 as evalSum, a3 as evalSwap, a4 as evalWatch, a5 as evalWhen, a6 as resolveBinding } from './index-dAA7DJ-s.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* S-Expression Evaluator
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isSExpr, isBinding, getOperator, getArgs, isFieldValue, isEventPayloadValue, isSessionHistoryEntry, isPlanSnapshot, OrbitalZodSchema, safeParseOrbitalSchema } from '@almadar/core';
|
|
1
|
+
import { isSExpr, isBinding, getOperator, getArgs, isTensorValue, describeTensorMismatch, contractFieldName, validateContract, isFieldValue, isEventPayloadValue, isSessionHistoryEntry, isPlanSnapshot, tensorLastDimSize, mapTensorLastDim, 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
|
import { assertOperatorArity } from '@almadar/std/registry';
|
|
4
4
|
|
|
@@ -2587,95 +2587,21 @@ function evalOsDebounce(args, evaluate2, ctx) {
|
|
|
2587
2587
|
const eventType = evaluate2(args[1], ctx);
|
|
2588
2588
|
registerTrigger(ctx, "debounce", { ms, eventType });
|
|
2589
2589
|
}
|
|
2590
|
-
|
|
2591
|
-
// std/contract.ts
|
|
2592
|
-
function fieldName(f) {
|
|
2593
|
-
return typeof f === "string" ? f : f.name;
|
|
2594
|
-
}
|
|
2595
|
-
function isTensorValue(v) {
|
|
2596
|
-
if (typeof v === "number") return true;
|
|
2597
|
-
return Array.isArray(v) && v.every(isTensorValue);
|
|
2598
|
-
}
|
|
2599
|
-
function describeType(v) {
|
|
2600
|
-
if (v === null) return "null";
|
|
2601
|
-
if (Array.isArray(v)) return "array containing non-numeric values";
|
|
2602
|
-
return typeof v;
|
|
2603
|
-
}
|
|
2604
|
-
function tensorShape(t) {
|
|
2605
|
-
if (typeof t === "number") return [];
|
|
2606
|
-
if (t.length === 0) return [0];
|
|
2607
|
-
const first = t[0];
|
|
2608
|
-
if (typeof first === "number") return [t.length];
|
|
2609
|
-
return [t.length, ...tensorShape(first)];
|
|
2610
|
-
}
|
|
2611
|
-
function lastDimSize(t) {
|
|
2612
|
-
const shape = tensorShape(t);
|
|
2613
|
-
return shape.length === 0 ? 0 : shape[shape.length - 1];
|
|
2614
|
-
}
|
|
2615
|
-
function arraysEqual(a, b) {
|
|
2616
|
-
return a.length === b.length && a.every((v, i) => v === b[i]);
|
|
2617
|
-
}
|
|
2618
|
-
function gatherLastDim(t, dim) {
|
|
2619
|
-
if (typeof t === "number") return [];
|
|
2620
|
-
if (t.length === 0) return [];
|
|
2621
|
-
if (typeof t[0] === "number") return [t[dim]];
|
|
2622
|
-
const out = [];
|
|
2623
|
-
for (const sub of t) out.push(...gatherLastDim(sub, dim));
|
|
2624
|
-
return out;
|
|
2625
|
-
}
|
|
2626
|
-
function mapLastDim(t, dim, fn) {
|
|
2627
|
-
if (typeof t === "number") return t;
|
|
2628
|
-
if (t.length === 0) return t;
|
|
2629
|
-
if (typeof t[0] === "number") {
|
|
2630
|
-
const copy = [...t];
|
|
2631
|
-
copy[dim] = fn(copy[dim]);
|
|
2632
|
-
return copy;
|
|
2633
|
-
}
|
|
2634
|
-
return t.map((sub) => mapLastDim(sub, dim, fn));
|
|
2635
|
-
}
|
|
2636
|
-
function validateContract(tensor, contract) {
|
|
2637
|
-
if (!isTensorValue(tensor)) {
|
|
2638
|
-
return {
|
|
2639
|
-
valid: false,
|
|
2640
|
-
violations: [{ type: "not_a_tensor", actualType: describeType(tensor) }]
|
|
2641
|
-
};
|
|
2642
|
-
}
|
|
2643
|
-
const violations = [];
|
|
2644
|
-
const shape = tensorShape(tensor);
|
|
2645
|
-
if (contract.shape && !arraysEqual(shape, contract.shape)) {
|
|
2646
|
-
violations.push({ type: "shape_mismatch", expected: contract.shape, actual: shape });
|
|
2647
|
-
}
|
|
2648
|
-
const ranges = contract.ranges ?? {};
|
|
2649
|
-
const size = lastDimSize(tensor);
|
|
2650
|
-
for (const [dimStr, bounds] of Object.entries(ranges)) {
|
|
2651
|
-
const dim = Number(dimStr);
|
|
2652
|
-
if (dim >= size) continue;
|
|
2653
|
-
const vals = gatherLastDim(tensor, dim);
|
|
2654
|
-
const min = bounds.min ?? -Infinity;
|
|
2655
|
-
const max = bounds.max ?? Infinity;
|
|
2656
|
-
const actualMin = Math.min(...vals);
|
|
2657
|
-
const actualMax = Math.max(...vals);
|
|
2658
|
-
if (actualMin < min || actualMax > max) {
|
|
2659
|
-
violations.push({ type: "range_violation", dim, min, max, actualMin, actualMax });
|
|
2660
|
-
}
|
|
2661
|
-
}
|
|
2662
|
-
return { valid: violations.length === 0, violations };
|
|
2663
|
-
}
|
|
2664
2590
|
function clampContract(tensor, contract) {
|
|
2665
2591
|
if (!isTensorValue(tensor)) {
|
|
2666
2592
|
throw new Error(
|
|
2667
|
-
`contract/clamp-output: expected a tensor (a number, or nested arrays of numbers), received ${
|
|
2593
|
+
`contract/clamp-output: expected a tensor (a number, or nested arrays of numbers), received ${describeTensorMismatch(tensor)}. Validate with contract/validate-output before clamping.`
|
|
2668
2594
|
);
|
|
2669
2595
|
}
|
|
2670
2596
|
const ranges = contract.ranges ?? {};
|
|
2671
|
-
const size =
|
|
2597
|
+
const size = tensorLastDimSize(tensor);
|
|
2672
2598
|
let result = tensor;
|
|
2673
2599
|
for (const [dimStr, bounds] of Object.entries(ranges)) {
|
|
2674
2600
|
const dim = Number(dimStr);
|
|
2675
2601
|
if (dim >= size) continue;
|
|
2676
2602
|
const min = bounds.min ?? -Infinity;
|
|
2677
2603
|
const max = bounds.max ?? Infinity;
|
|
2678
|
-
result =
|
|
2604
|
+
result = mapTensorLastDim(result, dim, (v) => Math.min(Math.max(v, min), max));
|
|
2679
2605
|
}
|
|
2680
2606
|
return result;
|
|
2681
2607
|
}
|
|
@@ -2702,7 +2628,7 @@ function evalContractEntityToTensor(args, evaluate2, ctx) {
|
|
|
2702
2628
|
const contract = evaluate2(args[1], ctx);
|
|
2703
2629
|
const fields = contract.fields ?? [];
|
|
2704
2630
|
return fields.map((f) => {
|
|
2705
|
-
const val = entity[
|
|
2631
|
+
const val = entity[contractFieldName(f)];
|
|
2706
2632
|
return typeof val === "number" ? val : 0;
|
|
2707
2633
|
});
|
|
2708
2634
|
}
|
|
@@ -2710,7 +2636,7 @@ function evalContractTensorToPayload(args, evaluate2, ctx) {
|
|
|
2710
2636
|
const tensor = evaluate2(args[0], ctx);
|
|
2711
2637
|
if (!isTensorValue(tensor)) {
|
|
2712
2638
|
throw new Error(
|
|
2713
|
-
`contract/tensor-to-payload: expected a tensor (a number, or nested arrays of numbers), received ${
|
|
2639
|
+
`contract/tensor-to-payload: expected a tensor (a number, or nested arrays of numbers), received ${describeTensorMismatch(tensor)}.`
|
|
2714
2640
|
);
|
|
2715
2641
|
}
|
|
2716
2642
|
const contract = evaluate2(args[1], ctx);
|
|
@@ -2718,18 +2644,18 @@ function evalContractTensorToPayload(args, evaluate2, ctx) {
|
|
|
2718
2644
|
const values = Array.isArray(tensor) ? tensor : [tensor];
|
|
2719
2645
|
const result = {};
|
|
2720
2646
|
fields.forEach((f, i) => {
|
|
2721
|
-
if (i < values.length) result[
|
|
2647
|
+
if (i < values.length) result[contractFieldName(f)] = values[i];
|
|
2722
2648
|
});
|
|
2723
2649
|
return result;
|
|
2724
2650
|
}
|
|
2725
2651
|
|
|
2726
2652
|
// std/graph.ts
|
|
2727
|
-
function
|
|
2653
|
+
function tensorShape(t) {
|
|
2728
2654
|
if (typeof t === "number") return [];
|
|
2729
2655
|
if (t.length === 0) return [0];
|
|
2730
2656
|
const first = t[0];
|
|
2731
2657
|
if (typeof first === "number") return [t.length];
|
|
2732
|
-
return [t.length, ...
|
|
2658
|
+
return [t.length, ...tensorShape(first)];
|
|
2733
2659
|
}
|
|
2734
2660
|
function numNodes(g) {
|
|
2735
2661
|
return g.x.length;
|
|
@@ -2789,7 +2715,7 @@ function evalGraphFromAdjacency(args, evaluate2, ctx) {
|
|
|
2789
2715
|
function evalGraphFromEdgeList(args, evaluate2, ctx) {
|
|
2790
2716
|
const edges = evaluate2(args[0], ctx);
|
|
2791
2717
|
const features = evaluate2(args[1], ctx);
|
|
2792
|
-
const shape =
|
|
2718
|
+
const shape = tensorShape(edges);
|
|
2793
2719
|
let edgeIndex;
|
|
2794
2720
|
if (shape.length === 2 && shape[1] === 2) {
|
|
2795
2721
|
const rows = edges;
|
|
@@ -2915,15 +2841,15 @@ function shuffleInPlace(arr, ctx) {
|
|
|
2915
2841
|
arr[j] = tmp;
|
|
2916
2842
|
}
|
|
2917
2843
|
}
|
|
2918
|
-
function
|
|
2844
|
+
function tensorShape2(t) {
|
|
2919
2845
|
if (typeof t === "number") return [];
|
|
2920
2846
|
if (t.length === 0) return [0];
|
|
2921
2847
|
const first = t[0];
|
|
2922
2848
|
if (typeof first === "number") return [t.length];
|
|
2923
|
-
return [t.length, ...
|
|
2849
|
+
return [t.length, ...tensorShape2(first)];
|
|
2924
2850
|
}
|
|
2925
2851
|
function rank(t) {
|
|
2926
|
-
return
|
|
2852
|
+
return tensorShape2(t).length;
|
|
2927
2853
|
}
|
|
2928
2854
|
function sampleMean(vals) {
|
|
2929
2855
|
return vals.reduce((s, v) => s + v, 0) / vals.length;
|
|
@@ -3055,7 +2981,7 @@ function evalDataPad(args, evaluate2, ctx) {
|
|
|
3055
2981
|
const data = evaluate2(args[0], ctx);
|
|
3056
2982
|
const config = evaluate2(args[1], ctx);
|
|
3057
2983
|
const currentLen = (() => {
|
|
3058
|
-
const shape =
|
|
2984
|
+
const shape = tensorShape2(data);
|
|
3059
2985
|
return shape.length === 0 ? 0 : shape[shape.length - 1];
|
|
3060
2986
|
})();
|
|
3061
2987
|
const targetLen = config.length ?? config.targetLength ?? currentLen;
|