@almadar/evaluator 2.6.0 → 2.7.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 { SExpr } from '@almadar/core';
1
+ import { AgentContext, SExpr } from '@almadar/core';
2
2
 
3
3
  /**
4
4
  * Evaluation Context
@@ -8,6 +8,7 @@ import { SExpr } from '@almadar/core';
8
8
  *
9
9
  * @packageDocumentation
10
10
  */
11
+
11
12
  /**
12
13
  * User context for @user bindings (role-based UI).
13
14
  */
@@ -62,6 +63,8 @@ interface EvaluationContext {
62
63
  _probSeed?: {
63
64
  state: number;
64
65
  };
66
+ /** Agent context for agent/* operators (memory, LLM, tools, session) */
67
+ agent?: AgentContext;
65
68
  /** Mutate entity fields */
66
69
  mutateEntity?: (changes: Record<string, unknown>) => void;
67
70
  /** Emit an event */
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { SExpr } from '@almadar/core';
2
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-Cf4WAVBs.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 evalMap, K as evalMatches, L as evalMax, M as evalMin, N as evalModulo, O as evalMultiply, P as evalNavigate, Q as evalNot, R as evalNotEqual, S as evalNotify, T as evalNth, U as evalOr, V as evalPersist, W as evalRef, X as evalRenderUI, Y as evalRound, Z as evalSet, _ as evalSetDynamic, $ as evalSpawn, a0 as evalSubtract, a1 as evalSum, a2 as evalSwap, a3 as evalWatch, a4 as evalWhen, a5 as resolveBinding } from './index-Cf4WAVBs.js';
3
+ import { E as EvaluationContext } from './index-CvAGW0K_.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 evalMap, K as evalMatches, L as evalMax, M as evalMin, N as evalModulo, O as evalMultiply, P as evalNavigate, Q as evalNot, R as evalNotEqual, S as evalNotify, T as evalNth, U as evalOr, V as evalPersist, W as evalRef, X as evalRenderUI, Y as evalRound, Z as evalSet, _ as evalSetDynamic, $ as evalSpawn, a0 as evalSubtract, a1 as evalSum, a2 as evalSwap, a3 as evalWatch, a4 as evalWhen, a5 as resolveBinding } from './index-CvAGW0K_.js';
5
5
 
6
6
  /**
7
7
  * S-Expression Evaluator
package/dist/index.js CHANGED
@@ -2436,6 +2436,120 @@ function evalOsDebounce(args, evaluate2, ctx) {
2436
2436
  registerTrigger(ctx, "debounce", { ms, eventType });
2437
2437
  }
2438
2438
 
2439
+ // std/agent.ts
2440
+ function evalAgentRecall(args, evaluate2, ctx) {
2441
+ if (!ctx.agent) return [];
2442
+ const query = evaluate2(args[0], ctx);
2443
+ const limit = args.length > 1 ? evaluate2(args[1], ctx) : void 0;
2444
+ return ctx.agent.recall(query, limit);
2445
+ }
2446
+ function evalAgentMemories(args, evaluate2, ctx) {
2447
+ if (!ctx.agent) return [];
2448
+ const category = args.length > 0 ? evaluate2(args[0], ctx) : void 0;
2449
+ return ctx.agent.memories(category);
2450
+ }
2451
+ function evalAgentMemoryStrength(args, evaluate2, ctx) {
2452
+ if (!ctx.agent) return 0;
2453
+ const id = evaluate2(args[0], ctx);
2454
+ return ctx.agent.memoryStrength(id);
2455
+ }
2456
+ function evalAgentIsPinned(args, evaluate2, ctx) {
2457
+ if (!ctx.agent) return false;
2458
+ const id = evaluate2(args[0], ctx);
2459
+ return ctx.agent.isPinned(id);
2460
+ }
2461
+ function evalAgentProvider(_args, _evaluate, ctx) {
2462
+ if (!ctx.agent) return "";
2463
+ return ctx.agent.provider();
2464
+ }
2465
+ function evalAgentModel(_args, _evaluate, ctx) {
2466
+ if (!ctx.agent) return "";
2467
+ return ctx.agent.model();
2468
+ }
2469
+ function evalAgentTools(_args, _evaluate, ctx) {
2470
+ if (!ctx.agent) return [];
2471
+ return ctx.agent.tools();
2472
+ }
2473
+ function evalAgentTokenCount(_args, _evaluate, ctx) {
2474
+ if (!ctx.agent) return 0;
2475
+ return ctx.agent.tokenCount();
2476
+ }
2477
+ function evalAgentContextUsage(_args, _evaluate, ctx) {
2478
+ if (!ctx.agent) return 0;
2479
+ return ctx.agent.contextUsage();
2480
+ }
2481
+ function evalAgentSessionId(_args, _evaluate, ctx) {
2482
+ if (!ctx.agent) return "";
2483
+ return ctx.agent.sessionId();
2484
+ }
2485
+ function evalAgentMemorize(args, evaluate2, ctx) {
2486
+ if (!ctx.agent) return null;
2487
+ const content = evaluate2(args[0], ctx);
2488
+ const category = evaluate2(args[1], ctx);
2489
+ const scope = args.length > 2 ? evaluate2(args[2], ctx) : void 0;
2490
+ return ctx.agent.memorize(content, category, scope);
2491
+ }
2492
+ function evalAgentForget(args, evaluate2, ctx) {
2493
+ if (!ctx.agent) return null;
2494
+ const id = evaluate2(args[0], ctx);
2495
+ return ctx.agent.forget(id);
2496
+ }
2497
+ function evalAgentPin(args, evaluate2, ctx) {
2498
+ if (!ctx.agent) return null;
2499
+ const id = evaluate2(args[0], ctx);
2500
+ return ctx.agent.pin(id);
2501
+ }
2502
+ function evalAgentReinforce(args, evaluate2, ctx) {
2503
+ if (!ctx.agent) return null;
2504
+ const id = evaluate2(args[0], ctx);
2505
+ return ctx.agent.reinforce(id);
2506
+ }
2507
+ function evalAgentDecay(_args, _evaluate, ctx) {
2508
+ if (!ctx.agent) return null;
2509
+ return ctx.agent.decay();
2510
+ }
2511
+ function evalAgentGenerate(args, evaluate2, ctx) {
2512
+ if (!ctx.agent) return null;
2513
+ const prompt = evaluate2(args[0], ctx);
2514
+ const options = args.length > 1 ? evaluate2(args[1], ctx) : void 0;
2515
+ return ctx.agent.generate(prompt, options);
2516
+ }
2517
+ function evalAgentSwitchProvider(args, evaluate2, ctx) {
2518
+ if (!ctx.agent) return null;
2519
+ const provider = evaluate2(args[0], ctx);
2520
+ const model = args.length > 1 ? evaluate2(args[1], ctx) : void 0;
2521
+ ctx.agent.switchProvider(provider, model);
2522
+ return null;
2523
+ }
2524
+ function evalAgentInvoke(args, evaluate2, ctx) {
2525
+ if (!ctx.agent) return null;
2526
+ const toolName = evaluate2(args[0], ctx);
2527
+ const toolArgs = evaluate2(args[1], ctx);
2528
+ return ctx.agent.invoke(toolName, toolArgs);
2529
+ }
2530
+ function evalAgentCompact(args, evaluate2, ctx) {
2531
+ if (!ctx.agent) return null;
2532
+ const strategy = args.length > 0 ? evaluate2(args[0], ctx) : void 0;
2533
+ return ctx.agent.compact(strategy);
2534
+ }
2535
+ function evalAgentFork(args, evaluate2, ctx) {
2536
+ if (!ctx.agent) return null;
2537
+ const label = args.length > 0 ? evaluate2(args[0], ctx) : void 0;
2538
+ return ctx.agent.fork(label);
2539
+ }
2540
+ function evalAgentLabel(args, evaluate2, ctx) {
2541
+ if (!ctx.agent) return null;
2542
+ const text = evaluate2(args[0], ctx);
2543
+ ctx.agent.label(text);
2544
+ return null;
2545
+ }
2546
+ function evalAgentSearchCode(args, evaluate2, ctx) {
2547
+ if (!ctx.agent) return null;
2548
+ const query = evaluate2(args[0], ctx);
2549
+ const language = args.length > 1 ? evaluate2(args[1], ctx) : void 0;
2550
+ return ctx.agent.searchCode(query, language);
2551
+ }
2552
+
2439
2553
  // SExpressionEvaluator.ts
2440
2554
  var jitCache = /* @__PURE__ */ new Map();
2441
2555
  var MAX_JIT_CACHE_SIZE = 1e3;
@@ -3082,6 +3196,64 @@ var SExpressionEvaluator = class {
3082
3196
  case "os/debounce":
3083
3197
  evalOsDebounce(args, evaluate2, ctx);
3084
3198
  return void 0;
3199
+ // ===============================
3200
+ // Standard Library: agent/*
3201
+ // ===============================
3202
+ // Pure (memory)
3203
+ case "agent/recall":
3204
+ return evalAgentRecall(args, evaluate2, ctx);
3205
+ case "agent/memories":
3206
+ return evalAgentMemories(args, evaluate2, ctx);
3207
+ case "agent/memory-strength":
3208
+ return evalAgentMemoryStrength(args, evaluate2, ctx);
3209
+ case "agent/is-pinned":
3210
+ return evalAgentIsPinned(args, evaluate2, ctx);
3211
+ // Pure (LLM)
3212
+ case "agent/provider":
3213
+ return evalAgentProvider(args, evaluate2, ctx);
3214
+ case "agent/model":
3215
+ return evalAgentModel(args, evaluate2, ctx);
3216
+ // Pure (tools)
3217
+ case "agent/tools":
3218
+ return evalAgentTools(args, evaluate2, ctx);
3219
+ // Pure (context)
3220
+ case "agent/token-count":
3221
+ return evalAgentTokenCount(args, evaluate2, ctx);
3222
+ case "agent/context-usage":
3223
+ return evalAgentContextUsage(args, evaluate2, ctx);
3224
+ // Pure (session)
3225
+ case "agent/session-id":
3226
+ return evalAgentSessionId(args, evaluate2, ctx);
3227
+ // Effects (memory)
3228
+ case "agent/memorize":
3229
+ return evalAgentMemorize(args, evaluate2, ctx);
3230
+ case "agent/forget":
3231
+ return evalAgentForget(args, evaluate2, ctx);
3232
+ case "agent/pin":
3233
+ return evalAgentPin(args, evaluate2, ctx);
3234
+ case "agent/reinforce":
3235
+ return evalAgentReinforce(args, evaluate2, ctx);
3236
+ case "agent/decay":
3237
+ return evalAgentDecay(args, evaluate2, ctx);
3238
+ // Effects (LLM)
3239
+ case "agent/generate":
3240
+ return evalAgentGenerate(args, evaluate2, ctx);
3241
+ case "agent/switch-provider":
3242
+ return evalAgentSwitchProvider(args, evaluate2, ctx);
3243
+ // Effects (tools)
3244
+ case "agent/invoke":
3245
+ return evalAgentInvoke(args, evaluate2, ctx);
3246
+ // Effects (context)
3247
+ case "agent/compact":
3248
+ return evalAgentCompact(args, evaluate2, ctx);
3249
+ // Effects (session)
3250
+ case "agent/fork":
3251
+ return evalAgentFork(args, evaluate2, ctx);
3252
+ case "agent/label":
3253
+ return evalAgentLabel(args, evaluate2, ctx);
3254
+ // Effects (search)
3255
+ case "agent/search-code":
3256
+ return evalAgentSearchCode(args, evaluate2, ctx);
3085
3257
  default:
3086
3258
  console.warn(`Unknown operator: ${op}`);
3087
3259
  return void 0;