@tangle-network/agent-runtime 0.88.0 → 0.89.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/agent.js CHANGED
@@ -1,7 +1,7 @@
1
- import "./chunk-22HPUH77.js";
1
+ import "./chunk-PIPPLSOF.js";
2
2
  import {
3
3
  createSandboxForSpec
4
- } from "./chunk-LRNRPJAV.js";
4
+ } from "./chunk-N7EJV7N3.js";
5
5
  import "./chunk-UD4BHQMI.js";
6
6
  import "./chunk-BZF3KQ6G.js";
7
7
  import {
@@ -8,7 +8,7 @@ import {
8
8
  DELEGATION_STATUS_DESCRIPTION,
9
9
  DELEGATION_STATUS_INPUT_SCHEMA,
10
10
  DELEGATION_STATUS_TOOL_NAME
11
- } from "./chunk-LRNRPJAV.js";
11
+ } from "./chunk-N7EJV7N3.js";
12
12
 
13
13
  // src/mcp/openai-tools.ts
14
14
  function buildTool(name, description, parameters) {
@@ -45,4 +45,4 @@ export {
45
45
  mcpToolsForRuntimeMcp,
46
46
  mcpToolsForRuntimeMcpSubset
47
47
  };
48
- //# sourceMappingURL=chunk-JHULWWQD.js.map
48
+ //# sourceMappingURL=chunk-5AVV7KAH.js.map
@@ -5,10 +5,10 @@ import {
5
5
  definePersona,
6
6
  runPersonified,
7
7
  worktreeFanout
8
- } from "./chunk-22HPUH77.js";
8
+ } from "./chunk-PIPPLSOF.js";
9
9
  import {
10
10
  createExecutorRegistry
11
- } from "./chunk-LRNRPJAV.js";
11
+ } from "./chunk-N7EJV7N3.js";
12
12
  import {
13
13
  runAnalystLoop
14
14
  } from "./chunk-ZQZX77MM.js";
@@ -196,4 +196,4 @@ export {
196
196
  runLoopRunnerCli,
197
197
  parseLoopRunnerArgv
198
198
  };
199
- //# sourceMappingURL=chunk-HBE77SWV.js.map
199
+ //# sourceMappingURL=chunk-BQPFZE2C.js.map
@@ -5259,243 +5259,6 @@ function canonicalize(value) {
5259
5259
  return out;
5260
5260
  }
5261
5261
 
5262
- // src/runtime/supervise/loop-executor.ts
5263
- var loopRuntime = "loop";
5264
- var loopRole = "loop";
5265
- function defineLoop(name, spec) {
5266
- if (!name) throw new ValidationError("defineLoop: a loop needs a name");
5267
- if (!Number.isInteger(spec.maxRounds) || spec.maxRounds < 1) {
5268
- throw new ValidationError(`defineLoop: "${name}" needs an integer maxRounds >= 1`);
5269
- }
5270
- const hasRound = typeof spec.round === "function";
5271
- const hasAgents = Array.isArray(spec.agents) && spec.agents.length > 0;
5272
- if (hasRound === hasAgents) {
5273
- throw new ValidationError(
5274
- `defineLoop: "${name}" needs exactly one of round(ctx) or a non-empty agents[]`
5275
- );
5276
- }
5277
- const round = hasRound ? spec.round : agentPipelineRound(name, spec.agents ?? []);
5278
- return {
5279
- name,
5280
- maxRounds: spec.maxRounds,
5281
- round,
5282
- ...spec.check ? { check: spec.check } : {},
5283
- ...spec.describe ? { describe: spec.describe } : {}
5284
- };
5285
- }
5286
- function agentPipelineRound(name, agents) {
5287
- for (const agent of agents) {
5288
- if (!agent || typeof agent.run !== "function" || !agent.name) {
5289
- throw new ValidationError(`defineLoop: "${name}" has an agent missing a name or run()`);
5290
- }
5291
- }
5292
- return async (ctx) => {
5293
- let out = ctx.task;
5294
- for (const agent of agents) {
5295
- out = await agent.run(ctx, out);
5296
- }
5297
- return { out };
5298
- };
5299
- }
5300
- function loopChild(loop, journal) {
5301
- const spec = {
5302
- profile: { name: loop.name, metadata: { role: loopRole } },
5303
- harness: null,
5304
- loop,
5305
- journal
5306
- };
5307
- return {
5308
- name: loop.name,
5309
- executorSpec: spec,
5310
- act() {
5311
- throw new ValidationError(
5312
- `loopChild: "${loop.name}" was run directly; a loop child runs through its nested-scope executor`
5313
- );
5314
- }
5315
- };
5316
- }
5317
- function isLoopSpec(spec) {
5318
- const role = spec.profile.metadata?.role;
5319
- if (role !== loopRole) return false;
5320
- const loop = spec.loop;
5321
- if (!isLoopDef(loop)) {
5322
- throw new ValidationError(
5323
- "loopExecutor: a loop-role spec must carry a `loop` LoopDef to run inside its nested scope"
5324
- );
5325
- }
5326
- return true;
5327
- }
5328
- var loopExecutorFactory = (spec, ctx) => {
5329
- if (!isLoopSpec(spec)) {
5330
- throw new ValidationError(
5331
- 'loopExecutorFactory: spec is not a loop child (no role:"loop" marker)'
5332
- );
5333
- }
5334
- const loop = spec.loop;
5335
- const journal = spec.journal;
5336
- const seam = readNestedScopeSeam(ctx);
5337
- const inbox = createInbox();
5338
- let artifact;
5339
- let meteredSpend;
5340
- return {
5341
- runtime: loopRuntime,
5342
- // The steer seam: `steer_agent` → `Scope.send` → here. Never throws (inbox contract).
5343
- deliver(msg) {
5344
- inbox.deliver(msg);
5345
- },
5346
- async execute(task, signal) {
5347
- const nestedRoot = nestedTreeKey(seam, journal);
5348
- await journal.beginTree(nestedRoot, (/* @__PURE__ */ new Date(0)).toISOString());
5349
- const nestedScope = seam.mount(nestedRoot, signal);
5350
- let out;
5351
- let delivered = false;
5352
- try {
5353
- for (let round = 1; round <= loop.maxRounds; round++) {
5354
- if (signal.aborted || nestedScope.signal.aborted) break;
5355
- const steer = drainSteer(inbox);
5356
- const roundInterrupt = inbox.freshInterrupt();
5357
- const roundSignal = AbortSignal.any([signal, nestedScope.signal, roundInterrupt]);
5358
- const result = await loop.round({
5359
- task,
5360
- scope: nestedScope,
5361
- round,
5362
- maxRounds: loop.maxRounds,
5363
- steer,
5364
- budget: nestedScope.budget,
5365
- signal: roundSignal
5366
- });
5367
- out = result.out;
5368
- if (loop.check && await runCheck(loop.check, out)) {
5369
- delivered = true;
5370
- break;
5371
- }
5372
- if (result.done) break;
5373
- }
5374
- const events = await loadTreeEvents(journal, nestedRoot);
5375
- const settled = events.filter(isSettled);
5376
- meteredSpend = nonZeroOrUndef(sumMetered(events));
5377
- const valid = loop.check ? await runCheck(loop.check, out) : delivered;
5378
- const verdict = { valid, score: valid ? 1 : 0 };
5379
- artifact = {
5380
- outRef: `${loopRuntime}:${nestedRoot}`,
5381
- out,
5382
- spent: sumSpend(settled),
5383
- verdict
5384
- };
5385
- return artifact;
5386
- } catch (err) {
5387
- meteredSpend = await safeSumMetered(journal, nestedRoot);
5388
- throw err;
5389
- }
5390
- },
5391
- metered() {
5392
- return meteredSpend;
5393
- },
5394
- teardown() {
5395
- return Promise.resolve({ destroyed: true });
5396
- },
5397
- resultArtifact() {
5398
- if (!artifact)
5399
- throw new ValidationError("loopExecutor: resultArtifact() read before execute()");
5400
- return artifact;
5401
- }
5402
- };
5403
- };
5404
- function withLoopExecutor(base) {
5405
- return {
5406
- register: base.register.bind(base),
5407
- resolve(spec) {
5408
- const role = spec.profile.metadata?.role;
5409
- if (role === loopRole && !spec.executor) {
5410
- return { succeeded: true, value: loopExecutorFactory };
5411
- }
5412
- return base.resolve(spec);
5413
- }
5414
- };
5415
- }
5416
- function drainSteer(inbox) {
5417
- return inbox.drain().map((m) => m.text);
5418
- }
5419
- async function runCheck(check, out) {
5420
- try {
5421
- return await check(out) === true;
5422
- } catch {
5423
- return false;
5424
- }
5425
- }
5426
- function nestedTreeKey(seam, journal) {
5427
- return `${seam.journalRoot}/l${nextNestOrdinal(journal)}`;
5428
- }
5429
- var nestCounters = /* @__PURE__ */ new WeakMap();
5430
- function nextNestOrdinal(journal) {
5431
- let c = nestCounters.get(journal);
5432
- if (!c) {
5433
- c = { n: 0 };
5434
- nestCounters.set(journal, c);
5435
- }
5436
- return c.n++;
5437
- }
5438
- async function loadTreeEvents(journal, nestedRoot) {
5439
- const events = await journal.loadTree(nestedRoot);
5440
- if (events === void 0) {
5441
- throw new ValidationError(
5442
- `loopExecutor: nested tree '${nestedRoot}' missing from the journal after run (corrupted log)`
5443
- );
5444
- }
5445
- return events;
5446
- }
5447
- function isSettled(ev) {
5448
- return ev.kind === "settled";
5449
- }
5450
- function sumSpend(settled) {
5451
- const total = { iterations: 0, tokens: { input: 0, output: 0 }, usd: 0, ms: 0 };
5452
- for (const ev of settled) {
5453
- total.iterations += ev.spent.iterations;
5454
- total.tokens.input += ev.spent.tokens.input;
5455
- total.tokens.output += ev.spent.tokens.output;
5456
- total.usd += ev.spent.usd;
5457
- total.ms += ev.spent.ms;
5458
- }
5459
- return total;
5460
- }
5461
- function sumMetered(events) {
5462
- const total = { iterations: 0, tokens: { input: 0, output: 0 }, usd: 0, ms: 0 };
5463
- for (const ev of events) {
5464
- if (ev.kind !== "metered") continue;
5465
- total.iterations += ev.spend.iterations;
5466
- total.tokens.input += ev.spend.tokens.input;
5467
- total.tokens.output += ev.spend.tokens.output;
5468
- total.usd += ev.spend.usd;
5469
- total.ms += ev.spend.ms;
5470
- }
5471
- return total;
5472
- }
5473
- function isNonZeroSpend(s) {
5474
- return s.iterations > 0 || s.tokens.input > 0 || s.tokens.output > 0 || s.usd > 0 || s.ms > 0;
5475
- }
5476
- function nonZeroOrUndef(s) {
5477
- return isNonZeroSpend(s) ? s : void 0;
5478
- }
5479
- async function safeSumMetered(journal, nestedRoot) {
5480
- try {
5481
- return nonZeroOrUndef(sumMetered(await loadTreeEvents(journal, nestedRoot)));
5482
- } catch {
5483
- return void 0;
5484
- }
5485
- }
5486
- function readNestedScopeSeam(ctx) {
5487
- const seam = ctx.seams[nestedScopeSeamKey];
5488
- if (!seam || typeof seam.mount !== "function") {
5489
- throw new ValidationError(
5490
- `loopExecutor: missing required seam "${nestedScopeSeamKey}" \u2014 a loop child must be spawned through a Scope that seeds it (the keystone scope does)`
5491
- );
5492
- }
5493
- return seam;
5494
- }
5495
- function isLoopDef(value) {
5496
- return typeof value === "object" && value !== null && typeof value.round === "function" && typeof value.name === "string" && Number.isInteger(value.maxRounds);
5497
- }
5498
-
5499
5262
  // src/runtime/supervise/driver-executor.ts
5500
5263
  var driverRuntime = "driver";
5501
5264
  var driverRole = "driver";
@@ -5518,30 +5281,30 @@ var driverExecutorFactory = (spec, ctx) => {
5518
5281
  }
5519
5282
  const driver = spec.driver;
5520
5283
  const journal = spec.journal;
5521
- const seam = readNestedScopeSeam2(ctx);
5284
+ const seam = readNestedScopeSeam(ctx);
5522
5285
  let artifact;
5523
5286
  let meteredSpend;
5524
5287
  return {
5525
5288
  runtime: driverRuntime,
5526
5289
  async execute(task, signal) {
5527
- const nestedRoot = nestedTreeKey2(seam, journal);
5290
+ const nestedRoot = nestedTreeKey(seam, journal);
5528
5291
  await journal.beginTree(nestedRoot, (/* @__PURE__ */ new Date(0)).toISOString());
5529
5292
  const nestedScope = seam.mount(nestedRoot, signal);
5530
5293
  try {
5531
5294
  const out = await driver.act(task, nestedScope);
5532
- const events = await loadTreeEvents2(journal, nestedRoot);
5533
- const settled = events.filter(isSettled2);
5534
- meteredSpend = nonZeroOrUndef2(sumMetered2(events));
5295
+ const events = await loadTreeEvents(journal, nestedRoot);
5296
+ const settled = events.filter(isSettled);
5297
+ meteredSpend = nonZeroOrUndef(sumMetered(events));
5535
5298
  const verdict = deriveDeliveryVerdict(settled);
5536
5299
  artifact = {
5537
5300
  outRef: `${driverRuntime}:${nestedRoot}`,
5538
5301
  out,
5539
- spent: sumSpend2(settled),
5302
+ spent: sumSpend(settled),
5540
5303
  ...verdict ? { verdict } : {}
5541
5304
  };
5542
5305
  return artifact;
5543
5306
  } catch (err) {
5544
- meteredSpend = await safeSumMetered2(journal, nestedRoot);
5307
+ meteredSpend = await safeSumMetered(journal, nestedRoot);
5545
5308
  throw err;
5546
5309
  }
5547
5310
  },
@@ -5571,19 +5334,19 @@ function withDriverExecutor(base) {
5571
5334
  }
5572
5335
  };
5573
5336
  }
5574
- function nestedTreeKey2(seam, journal) {
5575
- return `${seam.journalRoot}/d${nextNestOrdinal2(journal)}`;
5337
+ function nestedTreeKey(seam, journal) {
5338
+ return `${seam.journalRoot}/d${nextNestOrdinal(journal)}`;
5576
5339
  }
5577
- var nestCounters2 = /* @__PURE__ */ new WeakMap();
5578
- function nextNestOrdinal2(journal) {
5579
- let c = nestCounters2.get(journal);
5340
+ var nestCounters = /* @__PURE__ */ new WeakMap();
5341
+ function nextNestOrdinal(journal) {
5342
+ let c = nestCounters.get(journal);
5580
5343
  if (!c) {
5581
5344
  c = { n: 0 };
5582
- nestCounters2.set(journal, c);
5345
+ nestCounters.set(journal, c);
5583
5346
  }
5584
5347
  return c.n++;
5585
5348
  }
5586
- async function loadTreeEvents2(journal, nestedRoot) {
5349
+ async function loadTreeEvents(journal, nestedRoot) {
5587
5350
  const events = await journal.loadTree(nestedRoot);
5588
5351
  if (events === void 0) {
5589
5352
  throw new ValidationError(
@@ -5592,10 +5355,10 @@ async function loadTreeEvents2(journal, nestedRoot) {
5592
5355
  }
5593
5356
  return events;
5594
5357
  }
5595
- function isSettled2(ev) {
5358
+ function isSettled(ev) {
5596
5359
  return ev.kind === "settled";
5597
5360
  }
5598
- function sumSpend2(settled) {
5361
+ function sumSpend(settled) {
5599
5362
  const total = { iterations: 0, tokens: { input: 0, output: 0 }, usd: 0, ms: 0 };
5600
5363
  for (const ev of settled) {
5601
5364
  total.iterations += ev.spent.iterations;
@@ -5606,7 +5369,7 @@ function sumSpend2(settled) {
5606
5369
  }
5607
5370
  return total;
5608
5371
  }
5609
- function sumMetered2(events) {
5372
+ function sumMetered(events) {
5610
5373
  const total = { iterations: 0, tokens: { input: 0, output: 0 }, usd: 0, ms: 0 };
5611
5374
  for (const ev of events) {
5612
5375
  if (ev.kind !== "metered") continue;
@@ -5618,15 +5381,15 @@ function sumMetered2(events) {
5618
5381
  }
5619
5382
  return total;
5620
5383
  }
5621
- function isNonZeroSpend2(s) {
5384
+ function isNonZeroSpend(s) {
5622
5385
  return s.iterations > 0 || s.tokens.input > 0 || s.tokens.output > 0 || s.usd > 0 || s.ms > 0;
5623
5386
  }
5624
- function nonZeroOrUndef2(s) {
5625
- return isNonZeroSpend2(s) ? s : void 0;
5387
+ function nonZeroOrUndef(s) {
5388
+ return isNonZeroSpend(s) ? s : void 0;
5626
5389
  }
5627
- async function safeSumMetered2(journal, nestedRoot) {
5390
+ async function safeSumMetered(journal, nestedRoot) {
5628
5391
  try {
5629
- return nonZeroOrUndef2(sumMetered2(await loadTreeEvents2(journal, nestedRoot)));
5392
+ return nonZeroOrUndef(sumMetered(await loadTreeEvents(journal, nestedRoot)));
5630
5393
  } catch {
5631
5394
  return void 0;
5632
5395
  }
@@ -5656,7 +5419,7 @@ function deriveDeliveryVerdict(settled) {
5656
5419
  score: anyValid ? bestValidScore ?? 1 : bestDoneScore ?? 0
5657
5420
  };
5658
5421
  }
5659
- function readNestedScopeSeam2(ctx) {
5422
+ function readNestedScopeSeam(ctx) {
5660
5423
  const seam = ctx.seams[nestedScopeSeamKey];
5661
5424
  if (!seam || typeof seam.mount !== "function") {
5662
5425
  throw new ValidationError(
@@ -5672,13 +5435,10 @@ function isAgent(value) {
5672
5435
  // src/runtime/supervise/run-context.ts
5673
5436
  function createInMemoryRunContext(opts = {}) {
5674
5437
  const base = createExecutorRegistry();
5675
- let executors = base;
5676
- if (opts.withDriver) executors = withDriverExecutor(executors);
5677
- if (opts.withLoop) executors = withLoopExecutor(executors);
5678
5438
  return {
5679
5439
  journal: new InMemorySpawnJournal(),
5680
5440
  blobs: new InMemoryResultBlobStore(),
5681
- executors
5441
+ executors: opts.withDriver ? withDriverExecutor(base) : base
5682
5442
  };
5683
5443
  }
5684
5444
 
@@ -6819,10 +6579,6 @@ export {
6819
6579
  composeLoopTraceEmitters,
6820
6580
  DelegationTaskQueue,
6821
6581
  hashIdempotencyInput,
6822
- loopRuntime,
6823
- defineLoop,
6824
- loopChild,
6825
- withLoopExecutor,
6826
6582
  createInMemoryRunContext,
6827
6583
  supervisorAgent,
6828
6584
  workerFromBackend,
@@ -6858,4 +6614,4 @@ export {
6858
6614
  createInProcessTransport,
6859
6615
  serveCoordinationMcp
6860
6616
  };
6861
- //# sourceMappingURL=chunk-LRNRPJAV.js.map
6617
+ //# sourceMappingURL=chunk-N7EJV7N3.js.map