@aaac/runtime 0.1.20 → 0.1.21

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 CHANGED
@@ -8,6 +8,22 @@ import {
8
8
  hasBlockingViolation,
9
9
  pluginRegistry
10
10
  } from "./chunk-GZCEEIXQ.js";
11
+ import {
12
+ createExecutionEnvelope,
13
+ emitIterationClose,
14
+ emitIterationMetric,
15
+ emitIterationOpen,
16
+ emitLlmTurnClose,
17
+ emitLlmTurnOpen,
18
+ emitSessionClose,
19
+ emitSessionOpen,
20
+ emitSubagentClose,
21
+ emitSubagentOpen,
22
+ emitToolExecClose,
23
+ emitToolExecOpen,
24
+ emitToolchainClose,
25
+ emitToolchainOpen
26
+ } from "./chunk-FNB3PE74.js";
11
27
  import {
12
28
  buildSdkFunctionTools
13
29
  } from "./chunk-LONLL3K2.js";
@@ -375,221 +391,6 @@ ${fileBlocks.join("\n\n")}`);
375
391
  return sections.join("\n\n");
376
392
  }
377
393
 
378
- // src/lib/observability-bridge.ts
379
- import { generateId } from "@aaac/observability";
380
- function createExecutionEnvelope(params = {}) {
381
- const envelope = {
382
- run_id: generateId(),
383
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
384
- };
385
- if (params.parentRunId !== void 0) envelope.parent_run_id = params.parentRunId;
386
- if (params.componentId !== void 0) envelope.component_id = params.componentId;
387
- if (params.fromAgent !== void 0) envelope.from_agent = params.fromAgent;
388
- if (params.toAgent !== void 0) envelope.to_agent = params.toAgent;
389
- if (params.contractVersion !== void 0) envelope.contract_version = params.contractVersion;
390
- if (params.adapter !== void 0) envelope.adapter = params.adapter;
391
- if (params.model !== void 0) envelope.model = params.model;
392
- if (params.taskInstanceId !== void 0) envelope.task_instance_id = params.taskInstanceId;
393
- return envelope;
394
- }
395
- function attrs(base) {
396
- const out = {};
397
- for (const [k, v] of Object.entries(base)) {
398
- if (v !== void 0 && v !== "") out[k] = v;
399
- }
400
- return out;
401
- }
402
- function tokenAttrs(meta) {
403
- const out = {};
404
- const tu = meta.token_usage;
405
- if (tu && typeof tu === "object") {
406
- const t = tu;
407
- if (typeof t.input_tokens === "number") out["token_usage.input"] = t.input_tokens;
408
- if (typeof t.output_tokens === "number") out["token_usage.output"] = t.output_tokens;
409
- if (typeof t.total_tokens === "number") out["token_usage.total"] = t.total_tokens;
410
- if (typeof t.cache_read_input_tokens === "number") out["token_usage.cache_read"] = t.cache_read_input_tokens;
411
- if (typeof t.cache_creation_input_tokens === "number") out["token_usage.cache_creation"] = t.cache_creation_input_tokens;
412
- }
413
- if (typeof meta.cost_usd === "number") out["cost_usd"] = meta.cost_usd;
414
- return out;
415
- }
416
- function emitSessionOpen(observer, envelope, workflowId) {
417
- if (!observer) return void 0;
418
- const spanId = envelope.run_id;
419
- observer({
420
- source: "aaac-runtime",
421
- eventType: "agent.session",
422
- lifecycle: "open",
423
- spanId,
424
- parentSpanId: envelope.parent_run_id,
425
- attributes: attrs({
426
- axis: "agent",
427
- "agent.session_id": envelope.run_id,
428
- "agent.run_id": envelope.run_id,
429
- "workflow.id": workflowId,
430
- "agent.component_id": envelope.component_id,
431
- "agent.model": envelope.model,
432
- adapter: envelope.adapter,
433
- contract_version: envelope.contract_version
434
- })
435
- });
436
- return spanId;
437
- }
438
- function emitSessionClose(observer, spanId, envelope, durationMs, status, errorMessage) {
439
- if (!observer) return;
440
- const metaAttrs = envelope.execution_metadata ? tokenAttrs(envelope.execution_metadata) : {};
441
- observer({
442
- source: "aaac-runtime",
443
- eventType: "agent.session",
444
- lifecycle: "close",
445
- spanId,
446
- attributes: {
447
- ...attrs({
448
- axis: "agent",
449
- "agent.session_id": envelope.run_id,
450
- "agent.session.duration_ms": durationMs,
451
- "agent.status": status,
452
- "agent.error": errorMessage
453
- }),
454
- ...metaAttrs
455
- }
456
- });
457
- }
458
- function emitSubagentOpen(observer, envelope, parentSpanId, taskId, agentRole) {
459
- if (!observer) return void 0;
460
- const spanId = envelope.run_id;
461
- observer({
462
- source: "aaac-runtime",
463
- eventType: "agent.subagent",
464
- lifecycle: "open",
465
- spanId,
466
- parentSpanId,
467
- attributes: attrs({
468
- axis: "agent",
469
- "agent.role": agentRole,
470
- "agent.kind": "task",
471
- "task.id": taskId,
472
- "agent.run_id": envelope.run_id,
473
- "agent.parent_run_id": envelope.parent_run_id,
474
- "agent.model": envelope.model,
475
- adapter: envelope.adapter,
476
- "agent.component_id": envelope.component_id,
477
- "agent.from_agent": envelope.from_agent,
478
- "agent.to_agent": envelope.to_agent
479
- })
480
- });
481
- return spanId;
482
- }
483
- function emitSubagentClose(observer, spanId, envelope, durationMs, status, agentRole, errorMessage) {
484
- if (!observer) return;
485
- const metaAttrs = envelope.execution_metadata ? tokenAttrs(envelope.execution_metadata) : {};
486
- observer({
487
- source: "aaac-runtime",
488
- eventType: "agent.subagent",
489
- lifecycle: "close",
490
- spanId,
491
- attributes: {
492
- ...attrs({
493
- axis: "agent",
494
- "agent.role": agentRole,
495
- "agent.status": status,
496
- "agent.duration_ms": durationMs,
497
- "agent.error": errorMessage
498
- }),
499
- ...metaAttrs
500
- }
501
- });
502
- }
503
- function emitIterationOpen(observer, parentSpanId, evaluateTaskId, loopTo, iterationNumber, maxIterations) {
504
- if (!observer) return void 0;
505
- const spanId = generateId();
506
- observer({
507
- source: "aaac-runtime",
508
- eventType: "evaluate.iteration",
509
- lifecycle: "open",
510
- spanId,
511
- parentSpanId,
512
- attributes: attrs({
513
- axis: "agent",
514
- "evaluate.task": evaluateTaskId,
515
- "evaluate.loop_to": loopTo,
516
- "evaluate.iteration": iterationNumber,
517
- "evaluate.max_iterations": maxIterations
518
- })
519
- });
520
- return spanId;
521
- }
522
- function emitIterationClose(observer, spanId, evaluateTaskId, iterationNumber, verdict, durationMs, feedbackInjected) {
523
- if (!observer) return;
524
- observer({
525
- source: "aaac-runtime",
526
- eventType: "evaluate.iteration",
527
- lifecycle: "close",
528
- spanId,
529
- attributes: attrs({
530
- axis: "agent",
531
- "evaluate.task": evaluateTaskId,
532
- "evaluate.iteration": iterationNumber,
533
- "evaluate.verdict": verdict,
534
- "evaluate.duration_ms": durationMs,
535
- "evaluate.feedback_injected": feedbackInjected
536
- })
537
- });
538
- }
539
- function emitIterationMetric(observer, parentSpanId, evaluateTaskId, totalIterations, terminalOutcome) {
540
- if (!observer) return;
541
- const spanId = generateId();
542
- observer({
543
- source: "aaac-runtime",
544
- eventType: "evaluate.metric",
545
- lifecycle: "instant",
546
- spanId,
547
- parentSpanId,
548
- attributes: attrs({
549
- axis: "agent",
550
- "evaluate.task": evaluateTaskId,
551
- "evaluate.total_iterations": totalIterations,
552
- "evaluate.terminal_outcome": terminalOutcome
553
- })
554
- });
555
- }
556
- function emitToolchainOpen(observer, parentSpanId, toolchainId, operation, artifactIds, componentId) {
557
- if (!observer) return void 0;
558
- const spanId = generateId();
559
- observer({
560
- source: "aaac-runtime",
561
- eventType: "toolchain.execution",
562
- lifecycle: "open",
563
- spanId,
564
- parentSpanId,
565
- attributes: attrs({
566
- axis: "toolchain",
567
- "toolchain.id": toolchainId,
568
- "toolchain.operation": operation,
569
- "toolchain.artifact_ids": artifactIds.join(","),
570
- "agent.component_id": componentId
571
- })
572
- });
573
- return spanId;
574
- }
575
- function emitToolchainClose(observer, spanId, toolchainId, operation, durationMs, status, errorMessage) {
576
- if (!observer) return;
577
- observer({
578
- source: "aaac-runtime",
579
- eventType: "toolchain.execution",
580
- lifecycle: "close",
581
- spanId,
582
- attributes: attrs({
583
- axis: "toolchain",
584
- "toolchain.id": toolchainId,
585
- "toolchain.operation": operation,
586
- "toolchain.status": status,
587
- "toolchain.duration_ms": durationMs,
588
- ...errorMessage ? { "toolchain.error": errorMessage } : {}
589
- })
590
- });
591
- }
592
-
593
394
  // src/lib/task-runner.ts
594
395
  function getZodChecks(schema) {
595
396
  const def = schema._def;
@@ -1143,10 +944,10 @@ async function runTask(adapter, taskId, context, options) {
1143
944
  memoryRef,
1144
945
  splitPrompt,
1145
946
  agents,
1146
- options: { readonly: isReadonly, onProgress, splitPrompt, agents, allowDynamicWorkflow, libraryTools: options?.libraryTools, maxFollowUps, attempt: 0 }
947
+ options: { readonly: isReadonly, onProgress, splitPrompt, agents, allowDynamicWorkflow, libraryTools: options?.libraryTools, observer: options?.observer, parentSpanId: subagentSpanId, maxFollowUps, attempt: 0 }
1147
948
  });
1148
949
  } else {
1149
- fullOutput = await adapter.send(prompt, { readonly: isReadonly, onProgress, splitPrompt, agents, allowDynamicWorkflow, libraryTools: options?.libraryTools });
950
+ fullOutput = await adapter.send(prompt, { readonly: isReadonly, onProgress, splitPrompt, agents, allowDynamicWorkflow, libraryTools: options?.libraryTools, observer: options?.observer, parentSpanId: subagentSpanId });
1150
951
  }
1151
952
  } catch (err) {
1152
953
  closeStatus = "error";
@@ -1939,8 +1740,8 @@ function emitStepEvent(options, workflowId, stepIndex, step, result) {
1939
1740
  }
1940
1741
 
1941
1742
  // src/lib/process-axis-bridge.ts
1942
- import { generateId as generateId2 } from "@aaac/observability";
1943
- function attrs2(base) {
1743
+ import { generateId } from "@aaac/observability";
1744
+ function attrs(base) {
1944
1745
  const out = {};
1945
1746
  for (const [k, v] of Object.entries(base)) {
1946
1747
  if (v !== void 0 && v !== "") out[k] = v;
@@ -1949,14 +1750,14 @@ function attrs2(base) {
1949
1750
  }
1950
1751
  function emitProcessWorkflowOpen(options) {
1951
1752
  if (!options.observer) return void 0;
1952
- const spanId = generateId2();
1753
+ const spanId = generateId();
1953
1754
  options.observer({
1954
1755
  source: "aaac-runtime",
1955
1756
  eventType: "process.workflow",
1956
1757
  lifecycle: "open",
1957
1758
  spanId,
1958
1759
  parentSpanId: options.parentSpanId,
1959
- attributes: attrs2({
1760
+ attributes: attrs({
1960
1761
  axis: "process",
1961
1762
  "agent.session_id": options.sessionId,
1962
1763
  "workflow.id": options.workflowId
@@ -1971,7 +1772,7 @@ function emitProcessWorkflowClose(spanId, options) {
1971
1772
  eventType: "process.workflow",
1972
1773
  lifecycle: "close",
1973
1774
  spanId,
1974
- attributes: attrs2({
1775
+ attributes: attrs({
1975
1776
  axis: "process",
1976
1777
  "workflow.status": options.status,
1977
1778
  ...options.durationMs !== void 0 ? { "workflow.duration_ms": options.durationMs } : {}
@@ -1980,14 +1781,14 @@ function emitProcessWorkflowClose(spanId, options) {
1980
1781
  }
1981
1782
  function emitProcessTaskOpen(options) {
1982
1783
  if (!options.observer) return void 0;
1983
- const spanId = generateId2();
1784
+ const spanId = generateId();
1984
1785
  options.observer({
1985
1786
  source: "aaac-runtime",
1986
1787
  eventType: "process.task",
1987
1788
  lifecycle: "open",
1988
1789
  spanId,
1989
1790
  parentSpanId: options.parentSpanId,
1990
- attributes: attrs2({
1791
+ attributes: attrs({
1991
1792
  axis: "process",
1992
1793
  "agent.session_id": options.sessionId,
1993
1794
  "task.id": options.taskId,
@@ -2004,7 +1805,7 @@ function emitProcessTaskClose(spanId, options) {
2004
1805
  eventType: "process.task",
2005
1806
  lifecycle: "close",
2006
1807
  spanId,
2007
- attributes: attrs2({
1808
+ attributes: attrs({
2008
1809
  axis: "process",
2009
1810
  "task.status": options.status,
2010
1811
  ...options.durationMs !== void 0 ? { "task.duration_ms": options.durationMs } : {}
@@ -2013,14 +1814,14 @@ function emitProcessTaskClose(spanId, options) {
2013
1814
  }
2014
1815
  function emitProcessEdit(options) {
2015
1816
  if (!options.observer) return void 0;
2016
- const spanId = generateId2();
1817
+ const spanId = generateId();
2017
1818
  options.observer({
2018
1819
  source: "aaac-runtime",
2019
1820
  eventType: "process.edit",
2020
1821
  lifecycle: "instant",
2021
1822
  spanId,
2022
1823
  parentSpanId: options.parentSpanId,
2023
- attributes: attrs2({
1824
+ attributes: attrs({
2024
1825
  axis: "process",
2025
1826
  "agent.session_id": options.sessionId,
2026
1827
  "edit.path": options.filePath,
@@ -3828,6 +3629,8 @@ export {
3828
3629
  emitIterationClose,
3829
3630
  emitIterationMetric,
3830
3631
  emitIterationOpen,
3632
+ emitLlmTurnClose,
3633
+ emitLlmTurnOpen,
3831
3634
  emitProcessEdit,
3832
3635
  emitProcessTaskClose,
3833
3636
  emitProcessTaskOpen,
@@ -3837,6 +3640,8 @@ export {
3837
3640
  emitSessionOpen,
3838
3641
  emitSubagentClose,
3839
3642
  emitSubagentOpen,
3643
+ emitToolExecClose,
3644
+ emitToolExecOpen,
3840
3645
  emitToolchainClose,
3841
3646
  emitToolchainOpen,
3842
3647
  evaluateGuardrail,