@tangle-network/agent-runtime 0.43.0 → 0.45.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.
Files changed (89) hide show
  1. package/README.md +96 -202
  2. package/dist/agent.d.ts +5 -4
  3. package/dist/agent.js +5 -7
  4. package/dist/agent.js.map +1 -1
  5. package/dist/analyst-loop.d.ts +65 -4
  6. package/dist/analyst-loop.js +6 -1
  7. package/dist/audit.d.ts +93 -0
  8. package/dist/audit.js +312 -0
  9. package/dist/audit.js.map +1 -0
  10. package/dist/chunk-4B6U4CVQ.js +15 -0
  11. package/dist/chunk-4B6U4CVQ.js.map +1 -0
  12. package/dist/chunk-FK53TXOP.js +603 -0
  13. package/dist/chunk-FK53TXOP.js.map +1 -0
  14. package/dist/{chunk-MJDGCRAT.js → chunk-IJ6FGOPO.js} +5 -5
  15. package/dist/chunk-IJ6FGOPO.js.map +1 -0
  16. package/dist/{chunk-HVYOHJHK.js → chunk-IJGS6J7X.js} +2 -2
  17. package/dist/chunk-IJGS6J7X.js.map +1 -0
  18. package/dist/chunk-KEWO4KI6.js +3599 -0
  19. package/dist/chunk-KEWO4KI6.js.map +1 -0
  20. package/dist/{chunk-NRZOXCJK.js → chunk-KSMX62JF.js} +2 -2
  21. package/dist/{chunk-C5HMTTNY.js → chunk-NYN5RTLP.js} +13 -12
  22. package/dist/chunk-NYN5RTLP.js.map +1 -0
  23. package/dist/chunk-PRX45WE2.js +264 -0
  24. package/dist/chunk-PRX45WE2.js.map +1 -0
  25. package/dist/{chunk-3HMHSN22.js → chunk-QR4UUC5P.js} +6 -6
  26. package/dist/chunk-QR4UUC5P.js.map +1 -0
  27. package/dist/chunk-WIR4HOOJ.js +27 -0
  28. package/dist/chunk-WIR4HOOJ.js.map +1 -0
  29. package/dist/{chunk-MNCB4SJ5.js → chunk-Z2QXVBA6.js} +296 -8
  30. package/dist/chunk-Z2QXVBA6.js.map +1 -0
  31. package/dist/coder-CczgMqFx.d.ts +114 -0
  32. package/dist/dynamic-BvllHV6M.d.ts +221 -0
  33. package/dist/{improvement-adapter-BC4HhuAR.d.ts → improvement-adapter-CWegd3vw.d.ts} +1 -1
  34. package/dist/improvement.d.ts +2 -3
  35. package/dist/improvement.js +0 -5
  36. package/dist/improvement.js.map +1 -1
  37. package/dist/index.d.ts +123 -10
  38. package/dist/index.js +407 -19
  39. package/dist/index.js.map +1 -1
  40. package/dist/{kb-gate-DTBum3vH.d.ts → kb-gate-D9GBocLN.d.ts} +82 -5
  41. package/dist/{loop-runner-bin-CVoCBmYk.d.ts → loop-runner-bin-CPrCoKqC.d.ts} +14 -10
  42. package/dist/loop-runner-bin.d.ts +9 -7
  43. package/dist/loop-runner-bin.js +6 -8
  44. package/dist/loops.d.ts +7 -371
  45. package/dist/loops.js +96 -19
  46. package/dist/mcp/bin.js +7 -7
  47. package/dist/mcp/bin.js.map +1 -1
  48. package/dist/mcp/index.d.ts +284 -11
  49. package/dist/mcp/index.js +341 -9
  50. package/dist/mcp/index.js.map +1 -1
  51. package/dist/{otel-export-BzvF1Ela.d.ts → otel-export-Dy2DyUCU.d.ts} +1 -1
  52. package/dist/profiles.d.ts +385 -86
  53. package/dist/profiles.js +549 -4
  54. package/dist/profiles.js.map +1 -1
  55. package/dist/run-loop--hSoIknW.d.ts +112 -0
  56. package/dist/runtime-hooks-C7JwKb9E.d.ts +70 -0
  57. package/dist/runtime.d.ts +1860 -0
  58. package/dist/runtime.js +114 -0
  59. package/dist/runtime.js.map +1 -0
  60. package/dist/substrate-CUgk7F7s.d.ts +77 -0
  61. package/dist/topology.d.ts +73 -0
  62. package/dist/topology.js +111 -0
  63. package/dist/topology.js.map +1 -0
  64. package/dist/types-1HbsFa7H.d.ts +438 -0
  65. package/dist/{types-p8dWBIXL.d.ts → types-BtRLF2U3.d.ts} +1 -1
  66. package/dist/{types-Bcp071Jg.d.ts → types-DdzkffAm.d.ts} +95 -1
  67. package/dist/workflow.d.ts +551 -0
  68. package/dist/workflow.js +1778 -0
  69. package/dist/workflow.js.map +1 -0
  70. package/package.json +53 -16
  71. package/skills/agent-runtime-adoption/SKILL.md +29 -26
  72. package/dist/chunk-3HMHSN22.js.map +0 -1
  73. package/dist/chunk-C5HMTTNY.js.map +0 -1
  74. package/dist/chunk-EKBSQYZE.js +0 -813
  75. package/dist/chunk-EKBSQYZE.js.map +0 -1
  76. package/dist/chunk-HVYOHJHK.js.map +0 -1
  77. package/dist/chunk-MJDGCRAT.js.map +0 -1
  78. package/dist/chunk-MNCB4SJ5.js.map +0 -1
  79. package/dist/chunk-PY6NMZYX.js +0 -52
  80. package/dist/chunk-PY6NMZYX.js.map +0 -1
  81. package/dist/chunk-SQSCRJ7U.js +0 -65
  82. package/dist/chunk-SQSCRJ7U.js.map +0 -1
  83. package/dist/chunk-VOX6Z3II.js +0 -90
  84. package/dist/chunk-VOX6Z3II.js.map +0 -1
  85. package/dist/chunk-XBUG326M.js +0 -261
  86. package/dist/chunk-XBUG326M.js.map +0 -1
  87. package/dist/dynamic-B_7GgCwu.d.ts +0 -108
  88. package/dist/optimize-prompt-D-urF2wW.d.ts +0 -129
  89. /package/dist/{chunk-NRZOXCJK.js.map → chunk-KSMX62JF.js.map} +0 -0
package/dist/index.js CHANGED
@@ -1,3 +1,14 @@
1
+ import {
2
+ mcpToolsForRuntimeMcp,
3
+ mcpToolsForRuntimeMcpSubset
4
+ } from "./chunk-KSMX62JF.js";
5
+ import {
6
+ INTELLIGENCE_WIRE_VERSION,
7
+ buildLoopOtelSpans,
8
+ createOtelExporter,
9
+ exportEvalRuns,
10
+ loopEventToOtelSpan
11
+ } from "./chunk-IJGS6J7X.js";
1
12
  import {
2
13
  DELEGATED_LOOP_MODES,
3
14
  auditLoopRunner,
@@ -10,25 +21,17 @@ import {
10
21
  runDelegatedLoop,
11
22
  runLoopRunnerCli,
12
23
  selfImproveLoopRunner
13
- } from "./chunk-C5HMTTNY.js";
14
- import "./chunk-XBUG326M.js";
15
- import "./chunk-VOX6Z3II.js";
16
- import {
17
- mcpToolsForRuntimeMcp,
18
- mcpToolsForRuntimeMcpSubset
19
- } from "./chunk-NRZOXCJK.js";
20
- import {
21
- INTELLIGENCE_WIRE_VERSION,
22
- buildLoopOtelSpans,
23
- createOtelExporter,
24
- exportEvalRuns,
25
- loopEventToOtelSpan
26
- } from "./chunk-HVYOHJHK.js";
24
+ } from "./chunk-NYN5RTLP.js";
27
25
  import "./chunk-FNMGYYSS.js";
28
- import "./chunk-MJDGCRAT.js";
29
- import "./chunk-EKBSQYZE.js";
30
- import "./chunk-3HMHSN22.js";
31
- import "./chunk-PY6NMZYX.js";
26
+ import "./chunk-IJ6FGOPO.js";
27
+ import "./chunk-QR4UUC5P.js";
28
+ import "./chunk-FK53TXOP.js";
29
+ import {
30
+ composeRuntimeHooks,
31
+ defineRuntimeHooks,
32
+ notifyRuntimeDecisionPoint,
33
+ notifyRuntimeHookEvent
34
+ } from "./chunk-KEWO4KI6.js";
32
35
  import {
33
36
  AgentEvalError,
34
37
  BackendTransportError,
@@ -39,7 +42,7 @@ import {
39
42
  RuntimeRunStateError,
40
43
  SessionMismatchError,
41
44
  ValidationError
42
- } from "./chunk-SQSCRJ7U.js";
45
+ } from "./chunk-PRX45WE2.js";
43
46
  import "./chunk-DGUM43GV.js";
44
47
 
45
48
  // src/sessions.ts
@@ -2729,6 +2732,385 @@ function runtimeStreamServerSentEvent(event, options = {}) {
2729
2732
  function stripNewlines(value) {
2730
2733
  return value.replace(/[\r\n]/g, " ");
2731
2734
  }
2735
+
2736
+ // src/tool-loop.ts
2737
+ var DEFAULT_MAX_TOOL_TURNS = 8;
2738
+ var DEFAULT_DECISION_CONTEXT_CHARS = 12e3;
2739
+ var FAILURE_RECOVERY_ACTIONS = ["retry", "verify", "continue", "stop"];
2740
+ function defaultRender(label, outcome) {
2741
+ if (outcome.ok) return `- ${label} \u2192 ok: ${JSON.stringify(outcome.result)}`;
2742
+ return `- ${label} \u2192 failed (${outcome.code}): ${outcome.message}`;
2743
+ }
2744
+ async function runToolLoop(opts) {
2745
+ const maxTurns = opts.maxToolTurns ?? DEFAULT_MAX_TOOL_TURNS;
2746
+ const render = opts.renderResult ?? defaultRender;
2747
+ const labelFor = opts.labelFor ?? ((c) => c.toolName);
2748
+ const runId = opts.runId ?? `agent-run-${randomSuffix2()}`;
2749
+ const messages = [
2750
+ { role: "system", content: opts.systemPrompt },
2751
+ ...opts.priorMessages ?? [],
2752
+ { role: "user", content: opts.userMessage }
2753
+ ];
2754
+ const observer = createToolLoopObserver(opts.hooks, runId, opts.scenarioId);
2755
+ const toolResults = [];
2756
+ let finalText = "";
2757
+ let turns = 0;
2758
+ observer.loopBefore(maxTurns, messages.length);
2759
+ for (let toolTurn = 0; ; toolTurn++) {
2760
+ turns++;
2761
+ let turnText = "";
2762
+ const pending = [];
2763
+ const turnEventId = observer.turnBefore(toolTurn, messages.length);
2764
+ for await (const ev of opts.streamTurn([...messages])) {
2765
+ if (ev.type === "text") {
2766
+ turnText += ev.text;
2767
+ finalText += ev.text;
2768
+ } else if (ev.type === "tool_call" && opts.isExecutableTool(ev.call.toolName)) {
2769
+ pending.push(ev.call);
2770
+ }
2771
+ }
2772
+ if (pending.length === 0) {
2773
+ observer.turnAfter(toolTurn, turnEventId, {
2774
+ pendingToolCalls: 0,
2775
+ finalTextChars: finalText.length
2776
+ });
2777
+ break;
2778
+ }
2779
+ if (toolTurn >= maxTurns) {
2780
+ observer.turnAfter(toolTurn, turnEventId, {
2781
+ pendingToolCalls: pending.length,
2782
+ cappedOut: true
2783
+ });
2784
+ observer.loopAfter({ turns, toolResults: toolResults.length, cappedOut: true });
2785
+ return { finalText, toolResults, turns, cappedOut: true };
2786
+ }
2787
+ if (turnText.trim()) messages.push({ role: "assistant", content: turnText });
2788
+ const lines = [];
2789
+ const outcomes = [];
2790
+ for (const [callIndex, call] of pending.entries()) {
2791
+ const callEventId = observer.toolCallBefore(toolTurn, turnEventId, callIndex, call);
2792
+ let outcome;
2793
+ try {
2794
+ outcome = await opts.executeToolCall(call);
2795
+ } catch (err) {
2796
+ outcome = {
2797
+ ok: false,
2798
+ code: "executor_error",
2799
+ message: err instanceof Error ? err.message : String(err)
2800
+ };
2801
+ }
2802
+ const label = labelFor(call);
2803
+ const rendered = render(label, outcome);
2804
+ toolResults.push({ call, label, outcome });
2805
+ lines.push(rendered);
2806
+ outcomes.push({ call, label, outcome, rendered });
2807
+ observer.toolCallAfter(toolTurn, callEventId, call, outcome);
2808
+ }
2809
+ observer.failureRecovery({
2810
+ toolTurn,
2811
+ messages,
2812
+ turnText,
2813
+ outcomes
2814
+ });
2815
+ observer.turnAfter(toolTurn, turnEventId, {
2816
+ pendingToolCalls: pending.length,
2817
+ toolResults: outcomes.map((item) => ({
2818
+ toolName: item.call.toolName,
2819
+ toolCallId: item.call.toolCallId,
2820
+ ok: item.outcome.ok
2821
+ })),
2822
+ failedToolCalls: outcomes.filter((item) => !item.outcome.ok).length
2823
+ });
2824
+ messages.push({ role: "user", content: `Tool results:
2825
+ ${lines.join("\n")}` });
2826
+ }
2827
+ observer.loopAfter({ turns, toolResults: toolResults.length, cappedOut: false });
2828
+ return { finalText, toolResults, turns, cappedOut: false };
2829
+ }
2830
+ async function* streamToolLoop(opts) {
2831
+ const maxTurns = opts.maxToolTurns ?? DEFAULT_MAX_TOOL_TURNS;
2832
+ const render = opts.renderResult ?? defaultRender;
2833
+ const labelFor = opts.labelFor ?? ((c) => c.toolName);
2834
+ const runId = opts.runId ?? `agent-run-${randomSuffix2()}`;
2835
+ const messages = [
2836
+ { role: "system", content: opts.systemPrompt },
2837
+ ...opts.priorMessages ?? [],
2838
+ { role: "user", content: opts.userMessage }
2839
+ ];
2840
+ const observer = createToolLoopObserver(opts.hooks, runId, opts.scenarioId);
2841
+ observer.loopBefore(maxTurns, messages.length);
2842
+ for (let toolTurn = 0; ; toolTurn++) {
2843
+ let turnText = "";
2844
+ const pending = [];
2845
+ const turnEventId = observer.turnBefore(toolTurn, messages.length);
2846
+ for await (const event of opts.streamTurn([...messages])) {
2847
+ yield { kind: "event", event };
2848
+ turnText += opts.extractText(event);
2849
+ const call = opts.extractToolCall(event);
2850
+ if (call && opts.isExecutableTool(call.toolName)) pending.push(call);
2851
+ }
2852
+ if (pending.length === 0) {
2853
+ observer.turnAfter(toolTurn, turnEventId, { pendingToolCalls: 0 });
2854
+ observer.loopAfter({ turns: toolTurn + 1, cappedOut: false });
2855
+ return;
2856
+ }
2857
+ if (toolTurn >= maxTurns) {
2858
+ observer.turnAfter(toolTurn, turnEventId, {
2859
+ pendingToolCalls: pending.length,
2860
+ cappedOut: true
2861
+ });
2862
+ observer.loopAfter({ turns: toolTurn + 1, cappedOut: true });
2863
+ yield { kind: "capped", pending: pending.length };
2864
+ return;
2865
+ }
2866
+ if (turnText.trim()) messages.push({ role: "assistant", content: turnText });
2867
+ const lines = [];
2868
+ const outcomes = [];
2869
+ for (const [callIndex, call] of pending.entries()) {
2870
+ const callEventId = observer.toolCallBefore(toolTurn, turnEventId, callIndex, call);
2871
+ let outcome;
2872
+ try {
2873
+ outcome = await opts.executeToolCall(call);
2874
+ } catch (err) {
2875
+ outcome = {
2876
+ ok: false,
2877
+ code: "executor_error",
2878
+ message: err instanceof Error ? err.message : String(err)
2879
+ };
2880
+ }
2881
+ const label = labelFor(call);
2882
+ yield {
2883
+ kind: "tool_result",
2884
+ toolName: call.toolName,
2885
+ toolCallId: call.toolCallId,
2886
+ label,
2887
+ outcome
2888
+ };
2889
+ const rendered = render(label, outcome);
2890
+ lines.push(rendered);
2891
+ outcomes.push({ call, label, outcome, rendered });
2892
+ observer.toolCallAfter(toolTurn, callEventId, call, outcome);
2893
+ }
2894
+ observer.failureRecovery({
2895
+ toolTurn,
2896
+ messages,
2897
+ turnText,
2898
+ outcomes
2899
+ });
2900
+ observer.turnAfter(toolTurn, turnEventId, {
2901
+ pendingToolCalls: pending.length,
2902
+ toolResults: outcomes.map((item) => ({
2903
+ toolName: item.call.toolName,
2904
+ toolCallId: item.call.toolCallId,
2905
+ ok: item.outcome.ok
2906
+ })),
2907
+ failedToolCalls: outcomes.filter((item) => !item.outcome.ok).length
2908
+ });
2909
+ messages.push({ role: "user", content: `Tool results:
2910
+ ${lines.join("\n")}` });
2911
+ }
2912
+ }
2913
+ function createToolLoopObserver(hooks, runId, scenarioId) {
2914
+ const loopEventId = `${runId}:agent.run`;
2915
+ return {
2916
+ loopBefore: (maxToolTurns, messageCount) => {
2917
+ notifyToolLoopEvent({
2918
+ hooks,
2919
+ runId,
2920
+ scenarioId,
2921
+ target: "agent.run",
2922
+ phase: "before",
2923
+ id: `${loopEventId}:before`,
2924
+ payload: { maxToolTurns, messageCount }
2925
+ });
2926
+ },
2927
+ loopAfter: (payload) => {
2928
+ notifyToolLoopEvent({
2929
+ hooks,
2930
+ runId,
2931
+ scenarioId,
2932
+ target: "agent.run",
2933
+ phase: "after",
2934
+ id: `${loopEventId}:after`,
2935
+ payload
2936
+ });
2937
+ },
2938
+ turnBefore: (toolTurn, messageCount) => {
2939
+ const turnEventId = `${loopEventId}:${toolTurn}`;
2940
+ notifyToolLoopEvent({
2941
+ hooks,
2942
+ runId,
2943
+ scenarioId,
2944
+ target: "agent.turn",
2945
+ phase: "before",
2946
+ id: turnEventId,
2947
+ stepIndex: toolTurn,
2948
+ parentId: loopEventId,
2949
+ payload: { messageCount }
2950
+ });
2951
+ return turnEventId;
2952
+ },
2953
+ turnAfter: (toolTurn, turnEventId, payload) => {
2954
+ notifyToolLoopEvent({
2955
+ hooks,
2956
+ runId,
2957
+ scenarioId,
2958
+ target: "agent.turn",
2959
+ phase: "after",
2960
+ id: `${turnEventId}:after`,
2961
+ stepIndex: toolTurn,
2962
+ parentId: turnEventId,
2963
+ payload
2964
+ });
2965
+ },
2966
+ toolCallBefore: (toolTurn, turnEventId, callIndex, call) => {
2967
+ const callEventId = `${turnEventId}:tool-call:${callIndex}`;
2968
+ notifyToolLoopEvent({
2969
+ hooks,
2970
+ runId,
2971
+ scenarioId,
2972
+ target: "agent.tool_call",
2973
+ phase: "before",
2974
+ id: callEventId,
2975
+ stepIndex: toolTurn,
2976
+ parentId: turnEventId,
2977
+ payload: toolCallPayload(call)
2978
+ });
2979
+ return callEventId;
2980
+ },
2981
+ toolCallAfter: (toolTurn, callEventId, call, outcome) => {
2982
+ notifyToolLoopEvent({
2983
+ hooks,
2984
+ runId,
2985
+ scenarioId,
2986
+ target: "agent.tool_call",
2987
+ phase: "after",
2988
+ id: `${callEventId}:after`,
2989
+ stepIndex: toolTurn,
2990
+ parentId: callEventId,
2991
+ payload: { ...toolCallPayload(call), outcome: outcomePayload(outcome) }
2992
+ });
2993
+ },
2994
+ failureRecovery: (options) => {
2995
+ notifyToolFailureRecovery({
2996
+ hooks,
2997
+ runId,
2998
+ scenarioId,
2999
+ stepIndex: options.toolTurn,
3000
+ messages: options.messages,
3001
+ turnText: options.turnText,
3002
+ outcomes: options.outcomes
3003
+ });
3004
+ }
3005
+ };
3006
+ }
3007
+ function notifyToolLoopEvent(options) {
3008
+ notifyRuntimeHookEvent(options.hooks, {
3009
+ id: options.id ?? `${options.runId}:${options.target}:${options.phase}`,
3010
+ runId: options.runId,
3011
+ scenarioId: options.scenarioId,
3012
+ target: options.target,
3013
+ phase: options.phase,
3014
+ timestamp: Date.now(),
3015
+ stepIndex: options.stepIndex,
3016
+ parentId: options.parentId,
3017
+ payload: options.payload,
3018
+ metadata: { producer: "tool-loop", ...options.metadata }
3019
+ });
3020
+ }
3021
+ function notifyToolFailureRecovery(options) {
3022
+ const failed = options.outcomes.filter((item) => !item.outcome.ok);
3023
+ if (failed.length === 0) return;
3024
+ const evidence = [];
3025
+ for (const item of failed) {
3026
+ const id = item.call.toolCallId ?? `${options.stepIndex}:${item.label}`;
3027
+ evidence.push({
3028
+ source: "tool_call",
3029
+ id,
3030
+ detail: `${item.call.toolName} ${stringifySafe(item.call.args, 2e3)}`,
3031
+ metadata: { toolName: item.call.toolName, label: item.label }
3032
+ });
3033
+ evidence.push({
3034
+ source: "tool_result",
3035
+ id: `${id}:result`,
3036
+ detail: item.rendered,
3037
+ metadata: failureMetadata(item.outcome)
3038
+ });
3039
+ }
3040
+ notifyRuntimeDecisionPoint(options.hooks, {
3041
+ id: `${options.runId}:agent.turn:${options.stepIndex}:failure-recovery`,
3042
+ runId: options.runId,
3043
+ scenarioId: options.scenarioId,
3044
+ stepIndex: options.stepIndex,
3045
+ kind: "retry",
3046
+ candidateActions: [...FAILURE_RECOVERY_ACTIONS],
3047
+ context: renderDecisionContext(options.messages, options.turnText, options.outcomes),
3048
+ evidence,
3049
+ metadata: {
3050
+ target: "failure-recovery",
3051
+ source: "agent.turn",
3052
+ failedToolCount: failed.length,
3053
+ toolNames: failed.map((item) => item.call.toolName)
3054
+ }
3055
+ });
3056
+ }
3057
+ function toolCallPayload(call) {
3058
+ return {
3059
+ toolName: call.toolName,
3060
+ toolCallId: call.toolCallId,
3061
+ argsPreview: stringifySafe(call.args, 2e3)
3062
+ };
3063
+ }
3064
+ function outcomePayload(outcome) {
3065
+ if (!outcome.ok) {
3066
+ return {
3067
+ ok: false,
3068
+ code: outcome.code,
3069
+ message: trimText(outcome.message, 2e3),
3070
+ status: outcome.status
3071
+ };
3072
+ }
3073
+ return {
3074
+ ok: true,
3075
+ resultPreview: stringifySafe(outcome.result, 2e3)
3076
+ };
3077
+ }
3078
+ function failureMetadata(outcome) {
3079
+ if (outcome.ok) return void 0;
3080
+ return {
3081
+ code: outcome.code,
3082
+ message: outcome.message,
3083
+ status: outcome.status
3084
+ };
3085
+ }
3086
+ function renderDecisionContext(messages, turnText, outcomes) {
3087
+ const recent = messages.slice(-6).map((message) => `[${message.role}]
3088
+ ${message.content}`);
3089
+ const assistant = turnText.trim() ? [`[assistant]
3090
+ ${turnText}`] : [];
3091
+ const toolResults = [`[tool results]
3092
+ ${outcomes.map((item) => item.rendered).join("\n")}`];
3093
+ return trimText(
3094
+ [...recent, ...assistant, ...toolResults].join("\n\n"),
3095
+ DEFAULT_DECISION_CONTEXT_CHARS
3096
+ );
3097
+ }
3098
+ function stringifySafe(value, max) {
3099
+ let text;
3100
+ try {
3101
+ text = JSON.stringify(value) ?? String(value);
3102
+ } catch {
3103
+ text = String(value);
3104
+ }
3105
+ return trimText(text, max);
3106
+ }
3107
+ function trimText(text, max) {
3108
+ if (text.length <= max) return text;
3109
+ return `${text.slice(0, max)}\u2026`;
3110
+ }
3111
+ function randomSuffix2(len = 8) {
3112
+ return Math.random().toString(36).slice(2, 2 + len);
3113
+ }
2732
3114
  export {
2733
3115
  AgentEvalError,
2734
3116
  BackendTransportError,
@@ -2756,6 +3138,7 @@ export {
2756
3138
  buildLoopOtelSpans,
2757
3139
  cleanModelId,
2758
3140
  coderLoopRunner,
3141
+ composeRuntimeHooks,
2759
3142
  computeBackoff,
2760
3143
  createConversationBackend,
2761
3144
  createIterableBackend,
@@ -2768,6 +3151,7 @@ export {
2768
3151
  decideKnowledgeReadiness,
2769
3152
  defaultIsRetryable,
2770
3153
  defineConversation,
3154
+ defineRuntimeHooks,
2771
3155
  deriveExecutionId,
2772
3156
  dynamicLoopRunner,
2773
3157
  exportEvalRuns,
@@ -2779,6 +3163,8 @@ export {
2779
3163
  makePerAttemptSignal,
2780
3164
  mcpToolsForRuntimeMcp,
2781
3165
  mcpToolsForRuntimeMcpSubset,
3166
+ notifyRuntimeDecisionPoint,
3167
+ notifyRuntimeHookEvent,
2782
3168
  parseLoopRunnerArgv,
2783
3169
  readDepth,
2784
3170
  readinessServerSentEvent,
@@ -2792,6 +3178,7 @@ export {
2792
3178
  runConversationStream,
2793
3179
  runDelegatedLoop,
2794
3180
  runLoopRunnerCli,
3181
+ runToolLoop,
2795
3182
  runtimeStreamServerSentEvent,
2796
3183
  sanitizeAgentRuntimeEvent,
2797
3184
  sanitizeKnowledgeReadinessReport,
@@ -2800,6 +3187,7 @@ export {
2800
3187
  sleep2 as sleep,
2801
3188
  slugifySpeaker,
2802
3189
  startRuntimeRun,
3190
+ streamToolLoop,
2803
3191
  turnId,
2804
3192
  validateChatModelId
2805
3193
  };