@valerypopoff/rivet2-core 2.1.9 → 2.3.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 (188) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/bundle.cjs +5618 -2533
  3. package/dist/cjs/bundle.cjs.map +4 -4
  4. package/dist/cjs/webAppRuntime.cjs +333 -22
  5. package/dist/cjs/webAppRuntime.cjs.map +4 -4
  6. package/dist/esm/api/createProcessor.js +2 -0
  7. package/dist/esm/exports.js +1 -0
  8. package/dist/esm/integrations/CodeRunner.js +2 -7
  9. package/dist/esm/integrations/CodeRunnerOptions.js +7 -0
  10. package/dist/esm/model/AgentResponseTrace.js +558 -0
  11. package/dist/esm/model/ConnectedToolContinuationHost.js +33 -0
  12. package/dist/esm/model/GraphProcessor.js +165 -74
  13. package/dist/esm/model/NodeImpl.js +6 -0
  14. package/dist/esm/model/ProcessContextBuilder.js +3 -1
  15. package/dist/esm/model/RecordingPlayer.js +212 -25
  16. package/dist/esm/model/SplitRunProcessor.js +49 -8
  17. package/dist/esm/model/SubprocessorBridge.js +3 -0
  18. package/dist/esm/model/ToolCallContinuationCoordinator.js +7 -3
  19. package/dist/esm/model/UiGraph.js +21 -0
  20. package/dist/esm/model/UiGraphActionProtocol.js +3 -0
  21. package/dist/esm/model/UiGraphBrowserRuntime.js +133 -4
  22. package/dist/esm/model/UiGraphRendererStyles.js +221 -0
  23. package/dist/esm/model/UiGraphRuntimeModel.js +9 -3
  24. package/dist/esm/model/UiGraphSchema.js +7 -1
  25. package/dist/esm/model/chat/aiSdkTools.js +3 -2
  26. package/dist/esm/model/chat-v2/aiSdkBridge.js +146 -14
  27. package/dist/esm/model/chat-v2/chatV2CallObserver.js +11 -5
  28. package/dist/esm/model/chat-v2/chatV2CredentialNames.js +93 -0
  29. package/dist/esm/model/chat-v2/chatV2EditorCache.js +47 -20
  30. package/dist/esm/model/chat-v2/chatV2Errors.js +7 -19
  31. package/dist/esm/model/chat-v2/chatV2FeatureCompatibility.js +1 -1
  32. package/dist/esm/model/chat-v2/chatV2Outputs.js +48 -108
  33. package/dist/esm/model/chat-v2/chatV2Pipeline.js +101 -149
  34. package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +39 -4
  35. package/dist/esm/model/chat-v2/chatV2ProviderRegistry.js +9 -0
  36. package/dist/esm/model/chat-v2/chatV2RequestPlan.js +2 -3
  37. package/dist/esm/model/chat-v2/chatV2ResponseBodyCapture.js +63 -0
  38. package/dist/esm/model/chat-v2/chatV2ResponseFormat.js +8 -4
  39. package/dist/esm/model/chat-v2/chatV2Retry.js +4 -3
  40. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +7 -7
  41. package/dist/esm/model/chat-v2/chatV2Shared.js +1 -1
  42. package/dist/esm/model/chat-v2/chatV2Types.js +20 -8
  43. package/dist/esm/model/chat-v2/chatV2UsageAccounting.js +78 -0
  44. package/dist/esm/model/chat-v2/customProviderApi.js +40 -0
  45. package/dist/esm/model/chat-v2/index.js +15 -0
  46. package/dist/esm/model/chat-v2/llmChatV2Body.js +289 -0
  47. package/dist/esm/model/chat-v2/llmChatV2CacheBoundary.js +32 -0
  48. package/dist/esm/model/chat-v2/llmChatV2CachePolicy.js +25 -0
  49. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +13 -50
  50. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +117 -24
  51. package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +24 -0
  52. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +150 -199
  53. package/dist/esm/model/chat-v2/llmInvocationCoordinator.js +60 -0
  54. package/dist/esm/model/chat-v2/llmInvocationDecision.js +11 -0
  55. package/dist/esm/model/chat-v2/llmInvocationJournal.js +43 -0
  56. package/dist/esm/model/chat-v2/llmInvocationPlan.js +68 -0
  57. package/dist/esm/model/chat-v2/llmInvocationProjections.js +5 -0
  58. package/dist/esm/model/chat-v2/llmInvocationResultProjector.js +48 -0
  59. package/dist/esm/model/chat-v2/llmModelCandidate.js +79 -0
  60. package/dist/esm/model/chat-v2/llmProfile.js +52 -65
  61. package/dist/esm/model/chat-v2/llmProfileBody.js +193 -0
  62. package/dist/esm/model/chat-v2/llmProfileFallback.js +442 -100
  63. package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +74 -0
  64. package/dist/esm/model/chat-v2/llmProfileHealthStore.js +326 -0
  65. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +55 -33
  66. package/dist/esm/model/chat-v2/llmProfileTypes.js +1 -18
  67. package/dist/esm/model/chat-v2/llmResponseMaterializer.js +42 -0
  68. package/dist/esm/model/chat-v2/modelRegistry.js +54 -4
  69. package/dist/esm/model/chat-v2/parallelToolCalls.js +9 -2
  70. package/dist/esm/model/chat-v2/providerOptions.js +116 -24
  71. package/dist/esm/model/chat-v2/rivetToolRegistry.js +9 -0
  72. package/dist/esm/model/chat-v2/toolCallCodec.js +52 -0
  73. package/dist/esm/model/chat-v2/toolContinuation.js +72 -35
  74. package/dist/esm/model/chat-v2/toolHandlerResolver.js +23 -0
  75. package/dist/esm/model/chat-v2/toolRoundExecutor.js +12 -0
  76. package/dist/esm/model/nodes/ChatNode.js +6 -0
  77. package/dist/esm/model/nodes/ChatNodeBase.js +1 -0
  78. package/dist/esm/model/nodes/CodeNewNode.js +5 -47
  79. package/dist/esm/model/nodes/CodeNode.js +4 -46
  80. package/dist/esm/model/nodes/DelegateFunctionCallNode.js +19 -6
  81. package/dist/esm/model/nodes/ExpressionNode.js +5 -8
  82. package/dist/esm/model/nodes/LLMChatV2Node.js +121 -229
  83. package/dist/esm/model/nodes/LLMProfileNode.js +27 -8
  84. package/dist/esm/model/nodes/MatchNode.js +86 -41
  85. package/dist/esm/model/nodes/PromptNode.js +7 -0
  86. package/dist/esm/model/nodes/ToolNode.js +7 -0
  87. package/dist/esm/model/nodes/toolCallDelegation.js +177 -110
  88. package/dist/esm/plugins/anthropic/anthropic.js +4 -4
  89. package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +7 -0
  90. package/dist/esm/plugins/gentrace/gentraceSdk.js +0 -1
  91. package/dist/esm/plugins/gentrace/index.js +0 -1
  92. package/dist/esm/plugins/gentrace/plugin.js +61 -179
  93. package/dist/esm/plugins/google/google.js +5 -9
  94. package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +4 -1
  95. package/dist/esm/plugins.js +1 -2
  96. package/dist/esm/recording/ExecutionRecorder.js +62 -13
  97. package/dist/esm/utils/emitDetached.js +6 -3
  98. package/dist/esm/utils/openai.js +60 -16
  99. package/dist/esm/utils/serialization/serialization.js +2 -19
  100. package/dist/esm/webAppRuntime.js +3 -2
  101. package/dist/types/api/createProcessor.d.ts +3 -0
  102. package/dist/types/exports.d.ts +1 -0
  103. package/dist/types/integrations/CodeRunner.d.ts +10 -7
  104. package/dist/types/integrations/CodeRunnerOptions.d.ts +15 -0
  105. package/dist/types/model/AgentResponseTrace.d.ts +123 -0
  106. package/dist/types/model/ConnectedToolContinuationHost.d.ts +34 -0
  107. package/dist/types/model/EditorDefinition.d.ts +16 -0
  108. package/dist/types/model/ExecutorProtocol.d.ts +32 -11
  109. package/dist/types/model/GraphProcessor.d.ts +41 -9
  110. package/dist/types/model/NodeBase.d.ts +0 -10
  111. package/dist/types/model/NodeImpl.d.ts +18 -1
  112. package/dist/types/model/Nodes.d.ts +2 -2
  113. package/dist/types/model/ProcessContext.d.ts +99 -0
  114. package/dist/types/model/ProcessContextBuilder.d.ts +3 -1
  115. package/dist/types/model/RecordingPlayer.d.ts +6 -0
  116. package/dist/types/model/SplitRunProcessor.d.ts +10 -3
  117. package/dist/types/model/UiGraph.d.ts +8 -0
  118. package/dist/types/model/UiGraphActionProtocol.d.ts +3 -0
  119. package/dist/types/model/UiGraphBrowserRuntime.d.ts +11 -2
  120. package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
  121. package/dist/types/model/UiGraphRuntimeModel.d.ts +2 -0
  122. package/dist/types/model/UiGraphSchema.d.ts +1 -0
  123. package/dist/types/model/chat-v2/chatV2CallObserver.d.ts +2 -0
  124. package/dist/types/model/chat-v2/chatV2CredentialNames.d.ts +30 -0
  125. package/dist/types/model/chat-v2/chatV2EditorCache.d.ts +2 -3
  126. package/dist/types/model/chat-v2/chatV2Outputs.d.ts +6 -16
  127. package/dist/types/model/chat-v2/chatV2Pipeline.d.ts +13 -17
  128. package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +7 -0
  129. package/dist/types/model/chat-v2/chatV2ProviderRegistry.d.ts +8 -0
  130. package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +2 -2
  131. package/dist/types/model/chat-v2/chatV2ResponseBodyCapture.d.ts +25 -0
  132. package/dist/types/model/chat-v2/chatV2ResponseFormat.d.ts +3 -2
  133. package/dist/types/model/chat-v2/chatV2Retry.d.ts +2 -0
  134. package/dist/types/model/chat-v2/chatV2RuntimeOptions.d.ts +3 -8
  135. package/dist/types/model/chat-v2/chatV2Types.d.ts +44 -10
  136. package/dist/types/model/chat-v2/chatV2UsageAccounting.d.ts +14 -0
  137. package/dist/types/model/chat-v2/customProviderApi.d.ts +22 -0
  138. package/dist/types/model/chat-v2/index.d.ts +15 -0
  139. package/dist/types/model/chat-v2/llmChatV2Body.d.ts +24 -0
  140. package/dist/types/model/chat-v2/llmChatV2CacheBoundary.d.ts +10 -0
  141. package/dist/types/model/chat-v2/llmChatV2CachePolicy.d.ts +13 -0
  142. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +19 -3
  143. package/dist/types/model/chat-v2/llmChatV2NodeMigration.d.ts +8 -0
  144. package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +14 -16
  145. package/dist/types/model/chat-v2/llmInvocationCoordinator.d.ts +16 -0
  146. package/dist/types/model/chat-v2/llmInvocationDecision.d.ts +21 -0
  147. package/dist/types/model/chat-v2/llmInvocationJournal.d.ts +38 -0
  148. package/dist/types/model/chat-v2/llmInvocationPlan.d.ts +41 -0
  149. package/dist/types/model/chat-v2/llmInvocationProjections.d.ts +3 -0
  150. package/dist/types/model/chat-v2/llmInvocationResultProjector.d.ts +26 -0
  151. package/dist/types/model/chat-v2/llmModelCandidate.d.ts +20 -0
  152. package/dist/types/model/chat-v2/llmProfile.d.ts +14 -0
  153. package/dist/types/model/chat-v2/llmProfileBody.d.ts +20 -0
  154. package/dist/types/model/chat-v2/llmProfileFallback.d.ts +36 -49
  155. package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +209 -0
  156. package/dist/types/model/chat-v2/llmProfileHealthStore.d.ts +111 -0
  157. package/dist/types/model/chat-v2/llmProfileNodeRuntime.d.ts +1 -1
  158. package/dist/types/model/chat-v2/llmProfileTypes.d.ts +4 -1
  159. package/dist/types/model/chat-v2/llmResponseMaterializer.d.ts +20 -0
  160. package/dist/types/model/chat-v2/modelRegistry.d.ts +17 -187
  161. package/dist/types/model/chat-v2/parallelToolCalls.d.ts +3 -1
  162. package/dist/types/model/chat-v2/providerOptions.d.ts +12 -0
  163. package/dist/types/model/chat-v2/rivetToolRegistry.d.ts +11 -0
  164. package/dist/types/model/chat-v2/toolCallCodec.d.ts +7 -0
  165. package/dist/types/model/chat-v2/toolContinuation.d.ts +3 -3
  166. package/dist/types/model/chat-v2/toolHandlerResolver.d.ts +25 -0
  167. package/dist/types/model/chat-v2/toolRoundExecutor.d.ts +18 -0
  168. package/dist/types/model/nodes/ChatNode.d.ts +2 -1
  169. package/dist/types/model/nodes/CodeNewNode.d.ts +0 -5
  170. package/dist/types/model/nodes/CodeNode.d.ts +0 -5
  171. package/dist/types/model/nodes/DelegateFunctionCallNode.d.ts +2 -1
  172. package/dist/types/model/nodes/LLMChatV2Node.d.ts +2 -1
  173. package/dist/types/model/nodes/LLMProfileNode.d.ts +2 -1
  174. package/dist/types/model/nodes/MatchNode.d.ts +6 -0
  175. package/dist/types/model/nodes/PromptNode.d.ts +4 -1
  176. package/dist/types/model/nodes/ToolNode.d.ts +2 -1
  177. package/dist/types/model/nodes/toolCallDelegation.d.ts +10 -3
  178. package/dist/types/plugins/anthropic/anthropic.d.ts +1 -0
  179. package/dist/types/plugins/gentrace/gentraceSdk.d.ts +0 -1
  180. package/dist/types/plugins/gentrace/plugin.d.ts +55 -9
  181. package/dist/types/plugins/google/google.d.ts +2 -8
  182. package/dist/types/plugins.d.ts +1 -1
  183. package/dist/types/recording/ExecutionRecorder.d.ts +7 -1
  184. package/dist/types/recording/RecordedEvents.d.ts +6 -0
  185. package/dist/types/utils/emitDetached.d.ts +3 -2
  186. package/dist/types/utils/openai.d.ts +49 -0
  187. package/dist/types/webAppRuntime.d.ts +4 -2
  188. package/package.json +2 -2
@@ -28,6 +28,7 @@ __export(webAppRuntime_exports, {
28
28
  copyUiGraphText: () => copyUiGraphText,
29
29
  createUiGraphActionExecutionController: () => createUiGraphActionExecutionController,
30
30
  createUiGraphChatHistoryFlushStatePatch: () => createUiGraphChatHistoryFlushStatePatch,
31
+ createUiGraphChatMessageRemovalStatePatch: () => createUiGraphChatMessageRemovalStatePatch,
31
32
  createUiGraphChatPinStatePatch: () => createUiGraphChatPinStatePatch,
32
33
  createUiGraphChatSubmissionStatePatch: () => createUiGraphChatSubmissionStatePatch,
33
34
  createUiGraphInteractionController: () => createUiGraphInteractionController,
@@ -45,17 +46,181 @@ __export(webAppRuntime_exports, {
45
46
  getUiGraphWebAppStorageKey: () => getUiGraphWebAppStorageKey,
46
47
  hasUiGraphChatPersistentStateChanged: () => hasUiGraphChatPersistentStateChanged,
47
48
  highlightUiGraphChatSearchMatches: () => highlightUiGraphChatSearchMatches,
49
+ isAgentResponseTrace: () => isAgentResponseTrace,
48
50
  loadUiGraphChatPersistentState: () => loadUiGraphChatPersistentState,
51
+ loadUiGraphResponseTrace: () => loadUiGraphResponseTrace,
49
52
  loadUiGraphWebAppStorage: () => loadUiGraphWebAppStorage,
50
53
  observeUiGraphOutputResizeBounds: () => observeUiGraphOutputResizeBounds,
51
54
  parseRivetWebAppClientMessage: () => parseRivetWebAppClientMessage,
52
55
  parseRivetWebAppServerMessage: () => parseRivetWebAppServerMessage,
56
+ pruneUiGraphResponseTraces: () => pruneUiGraphResponseTraces,
53
57
  revealUiGraphChatElement: () => revealUiGraphChatElement,
54
58
  revealUiGraphChatSearchMatch: () => revealUiGraphChatSearchMatch,
55
- saveUiGraphChatPersistentState: () => saveUiGraphChatPersistentState
59
+ saveUiGraphChatPersistentState: () => saveUiGraphChatPersistentState,
60
+ saveUiGraphResponseTrace: () => saveUiGraphResponseTrace
56
61
  });
57
62
  module.exports = __toCommonJS(webAppRuntime_exports);
58
63
 
64
+ // src/model/AgentResponseTrace.ts
65
+ var AGENT_RESPONSE_TRACE_SCHEMA_VERSION = 1;
66
+ var AGENT_RESPONSE_TRACE_MAX_MODEL_CALLS = 250;
67
+ var AGENT_RESPONSE_TRACE_MAX_PROFILE_ATTEMPTS = 1e3;
68
+ var AGENT_RESPONSE_TRACE_MAX_TOOL_CALLS = 500;
69
+ function isAgentResponseTrace(value) {
70
+ if (!isRecord(value) || value.schemaVersion !== AGENT_RESPONSE_TRACE_SCHEMA_VERSION) return false;
71
+ if (!hasOnlyKeys(value, [
72
+ "schemaVersion",
73
+ "traceId",
74
+ "scope",
75
+ "rootRunId",
76
+ "graphRunId",
77
+ "graphId",
78
+ "nodeId",
79
+ "processId",
80
+ "startedAt",
81
+ "responseReadyAt",
82
+ "finishedAt",
83
+ "durationMs",
84
+ "status",
85
+ "backgroundWorkPending",
86
+ "summary",
87
+ "modelCalls",
88
+ "profileAttempts",
89
+ "toolCalls",
90
+ "omittedModelCallCount",
91
+ "omittedProfileAttemptCount",
92
+ "omittedToolCallCount"
93
+ ]))
94
+ return false;
95
+ if (typeof value.traceId !== "string" || typeof value.rootRunId !== "string") return false;
96
+ if (typeof value.graphRunId !== "string" || typeof value.graphId !== "string") return false;
97
+ if (value.scope !== "response" && value.scope !== "llm-invocation") return false;
98
+ if (!isRecord(value.summary) || !Array.isArray(value.modelCalls) || !Array.isArray(value.toolCalls)) return false;
99
+ if (value.profileAttempts !== void 0 && !Array.isArray(value.profileAttempts)) return false;
100
+ if (value.modelCalls.length > AGENT_RESPONSE_TRACE_MAX_MODEL_CALLS) return false;
101
+ if (Array.isArray(value.profileAttempts) && value.profileAttempts.length > AGENT_RESPONSE_TRACE_MAX_PROFILE_ATTEMPTS)
102
+ return false;
103
+ if (value.toolCalls.length > AGENT_RESPONSE_TRACE_MAX_TOOL_CALLS) return false;
104
+ return isOptionalString(value.nodeId) && isOptionalString(value.processId) && isOptionalNonNegativeFiniteNumber(value.startedAt) && isOptionalNonNegativeFiniteNumber(value.responseReadyAt) && isOptionalNonNegativeFiniteNumber(value.finishedAt) && isOptionalNonNegativeFiniteNumber(value.durationMs) && isOptionalBoolean(value.backgroundWorkPending) && ["running", "response-ready", "completed", "error", "aborted", "unavailable"].includes(String(value.status)) && isNonNegativeInteger(value.omittedModelCallCount) && (value.omittedProfileAttemptCount === void 0 || isNonNegativeInteger(value.omittedProfileAttemptCount)) && isNonNegativeInteger(value.omittedToolCallCount) && isAgentTraceSummary(value.summary) && value.modelCalls.every(isAgentModelCallTrace) && (value.profileAttempts === void 0 || value.profileAttempts.every(isAgentLLMProfileAttemptTrace)) && value.toolCalls.every(isAgentToolCallTrace);
105
+ }
106
+ function isAgentModelCallTrace(value) {
107
+ return isRecord(value) && hasOnlyKeys(value, [
108
+ "callId",
109
+ "nodeId",
110
+ "processId",
111
+ "provider",
112
+ "model",
113
+ "customProviderApi",
114
+ "outcome",
115
+ "attemptIndex",
116
+ "profileIndex",
117
+ "profileHealthKey",
118
+ "profileHealthState",
119
+ "roundIndex",
120
+ "startedAt",
121
+ "durationMs",
122
+ "finishReason",
123
+ "usage",
124
+ "pricing"
125
+ ]) && typeof value.callId === "string" && typeof value.nodeId === "string" && typeof value.processId === "string" && typeof value.provider === "string" && typeof value.model === "string" && (value.customProviderApi === void 0 || value.customProviderApi === "completions" || value.customProviderApi === "responses") && (value.outcome === "success" || value.outcome === "provider-failure" || value.outcome === "aborted") && isNonNegativeInteger(value.attemptIndex) && isOptionalNonNegativeInteger(value.profileIndex) && isOptionalString(value.profileHealthKey) && (value.profileHealthState === void 0 || value.profileHealthState === "closed" || value.profileHealthState === "open" || value.profileHealthState === "half-open") && isOptionalNonNegativeInteger(value.roundIndex) && isOptionalNonNegativeFiniteNumber(value.startedAt) && isOptionalNonNegativeFiniteNumber(value.durationMs) && isOptionalString(value.finishReason) && (value.usage === void 0 || isAgentTraceUsage(value.usage)) && isAgentTracePricing(value.pricing);
126
+ }
127
+ function isAgentLLMProfileAttemptTrace(value) {
128
+ return isRecord(value) && hasOnlyKeys(value, [
129
+ "eventId",
130
+ "roundIndex",
131
+ "profileIndex",
132
+ "nodeId",
133
+ "processId",
134
+ "provider",
135
+ "model",
136
+ "customProviderApi",
137
+ "stage",
138
+ "outcome",
139
+ "attemptIndex",
140
+ "status",
141
+ "error",
142
+ "profileHealthKey",
143
+ "healthState",
144
+ "healthDisposition",
145
+ "healthOutcome",
146
+ "retryAt",
147
+ "timeoutKind"
148
+ ]) && typeof value.eventId === "string" && isNonNegativeInteger(value.roundIndex) && isOptionalNonNegativeInteger(value.profileIndex) && typeof value.nodeId === "string" && typeof value.processId === "string" && typeof value.provider === "string" && typeof value.model === "string" && (value.customProviderApi === void 0 || value.customProviderApi === "completions" || value.customProviderApi === "responses") && ["configuration", "request", "response-validation", "health-gate", "health-update"].includes(
149
+ String(value.stage)
150
+ ) && ["success", "failure", "aborted", "skipped"].includes(String(value.outcome)) && isOptionalNonNegativeInteger(value.attemptIndex) && isOptionalNonNegativeFiniteNumber(value.status) && isOptionalString(value.error) && isOptionalString(value.profileHealthKey) && (value.healthState === void 0 || value.healthState === "closed" || value.healthState === "open" || value.healthState === "half-open") && (value.healthDisposition === void 0 || value.healthDisposition === "allow" || value.healthDisposition === "deny" || value.healthDisposition === "fail-open") && (value.healthOutcome === void 0 || value.healthOutcome === "healthy" || value.healthOutcome === "unhealthy" || value.healthOutcome === "ignored") && isOptionalNonNegativeFiniteNumber(value.retryAt) && (value.timeoutKind === void 0 || value.timeoutKind === "first-output" || value.timeoutKind === "stream-inactivity");
151
+ }
152
+ function isAgentToolCallTrace(value) {
153
+ const hasKnownOutcome = isRecord(value) && (value.outcome === "success" || value.outcome === "passthrough-error" || value.outcome === "failure" || value.outcome === "aborted");
154
+ return isRecord(value) && hasOnlyKeys(value, [
155
+ "toolCallId",
156
+ "toolName",
157
+ "sourceNodeId",
158
+ "sourceProcessId",
159
+ "resultOwner",
160
+ "handlerKind",
161
+ "handlerGraphId",
162
+ "handlerName",
163
+ "outcome",
164
+ "startedAt",
165
+ "durationMs"
166
+ ]) && isOptionalString(value.toolCallId) && typeof value.toolName === "string" && typeof value.sourceNodeId === "string" && typeof value.sourceProcessId === "string" && (value.resultOwner === void 0 || isAgentToolResultOutcome(value.outcome) && isAgentToolResultOwner(value.resultOwner)) && (value.handlerKind === "graph" || value.handlerKind === "external" || value.handlerKind === "unknown") && isOptionalString(value.handlerGraphId) && isOptionalString(value.handlerName) && hasKnownOutcome && isOptionalNonNegativeFiniteNumber(value.startedAt) && isOptionalNonNegativeFiniteNumber(value.durationMs);
167
+ }
168
+ function isAgentToolResultOutcome(value) {
169
+ return value === "success" || value === "passthrough-error";
170
+ }
171
+ function isAgentToolResultOwner(value) {
172
+ return isRecord(value) && hasOnlyKeys(value, ["nodeId", "processId", "outputPortId"]) && typeof value.nodeId === "string" && typeof value.processId === "string" && typeof value.outputPortId === "string";
173
+ }
174
+ function isAgentTraceSummary(value) {
175
+ return hasOnlyKeys(value, [
176
+ "modelCallCount",
177
+ "toolCallCount",
178
+ "retryCount",
179
+ "fallbackCount",
180
+ "promptTokens",
181
+ "completionTokens",
182
+ "totalTokens",
183
+ "cachedTokens",
184
+ "reasoningTokens",
185
+ "knownCostUsd",
186
+ "costStatus"
187
+ ]) && isNonNegativeInteger(value.modelCallCount) && isNonNegativeInteger(value.toolCallCount) && isNonNegativeInteger(value.retryCount) && isNonNegativeInteger(value.fallbackCount) && isOptionalNonNegativeFiniteNumber(value.promptTokens) && isOptionalNonNegativeFiniteNumber(value.completionTokens) && isOptionalNonNegativeFiniteNumber(value.totalTokens) && isOptionalNonNegativeFiniteNumber(value.cachedTokens) && isOptionalNonNegativeFiniteNumber(value.reasoningTokens) && isNonNegativeFiniteNumber(value.knownCostUsd) && (value.costStatus === "known" || value.costStatus === "partial" || value.costStatus === "unknown");
188
+ }
189
+ function isAgentTraceUsage(value) {
190
+ return isRecord(value) && hasOnlyKeys(value, ["promptTokens", "completionTokens", "totalTokens", "cachedTokens", "reasoningTokens"]) && Object.values(value).every(isNonNegativeFiniteNumber);
191
+ }
192
+ function isAgentTracePricing(value) {
193
+ return isRecord(value) && hasOnlyKeys(value, ["status", "costUsd"]) && (value.status === "known" || value.status === "unknown") && isOptionalNonNegativeFiniteNumber(value.costUsd);
194
+ }
195
+ function hasOnlyKeys(value, allowed) {
196
+ const allowedKeys = new Set(allowed);
197
+ return Object.keys(value).every((key) => allowedKeys.has(key));
198
+ }
199
+ function isFiniteNumber(value) {
200
+ return typeof value === "number" && Number.isFinite(value);
201
+ }
202
+ function isNonNegativeFiniteNumber(value) {
203
+ return isFiniteNumber(value) && value >= 0;
204
+ }
205
+ function isOptionalNonNegativeFiniteNumber(value) {
206
+ return value === void 0 || isNonNegativeFiniteNumber(value);
207
+ }
208
+ function isNonNegativeInteger(value) {
209
+ return Number.isInteger(value) && value >= 0;
210
+ }
211
+ function isOptionalNonNegativeInteger(value) {
212
+ return value === void 0 || isNonNegativeInteger(value);
213
+ }
214
+ function isOptionalString(value) {
215
+ return value === void 0 || typeof value === "string";
216
+ }
217
+ function isOptionalBoolean(value) {
218
+ return value === void 0 || typeof value === "boolean";
219
+ }
220
+ function isRecord(value) {
221
+ return typeof value === "object" && value != null && !Array.isArray(value);
222
+ }
223
+
59
224
  // src/utils/newId.ts
60
225
  var import_non_secure = require("nanoid/non-secure");
61
226
 
@@ -124,6 +289,22 @@ function createUiGraphChatPinStatePatch(componentId, state, messageIndex) {
124
289
  [pinsStateKey]: pinnedIndexes.includes(messageIndex) ? pinnedIndexes.filter((index) => index !== messageIndex) : [...pinnedIndexes, messageIndex].sort((left, right) => left - right)
125
290
  };
126
291
  }
292
+ function createUiGraphChatMessageRemovalStatePatch(componentId, state, messageIndex) {
293
+ const messages = getUiGraphChatMessages(componentId, state);
294
+ if (!Number.isSafeInteger(messageIndex) || messageIndex < 0 || messageIndex >= messages.length) {
295
+ return void 0;
296
+ }
297
+ const pinsStateKey = getUiGraphChatPinsStateKey(componentId);
298
+ const pinnedIndexes = getUiGraphChatPins(componentId, state).map((pin) => pin.messageIndex);
299
+ const remainingPinnedIndexes = pinnedIndexes.flatMap((pinnedIndex) => {
300
+ if (pinnedIndex === messageIndex) return [];
301
+ return [pinnedIndex > messageIndex ? pinnedIndex - 1 : pinnedIndex];
302
+ });
303
+ return {
304
+ [getUiGraphChatMessagesStateKey(componentId)]: messages.filter((_message, index) => index !== messageIndex),
305
+ [pinsStateKey]: remainingPinnedIndexes
306
+ };
307
+ }
127
308
  function createUiGraphChatHistoryFlushStatePatch(componentId) {
128
309
  return {
129
310
  [getUiGraphChatMessagesStateKey(componentId)]: [],
@@ -392,7 +573,7 @@ function createUiGraphInteractionController(initialUiGraph, options = {}) {
392
573
  }
393
574
  }
394
575
  };
395
- const stampChatResponseAtBrowserReceipt = (component, statePatch) => {
576
+ const stampChatResponseAtBrowserReceipt = (component, statePatch, responseTrace) => {
396
577
  if (component.type !== "chat" || !statePatch) {
397
578
  return statePatch;
398
579
  }
@@ -409,7 +590,11 @@ function createUiGraphInteractionController(initialUiGraph, options = {}) {
409
590
  ...statePatch,
410
591
  [messagesStateKey]: [
411
592
  ...messages.slice(0, -1),
412
- { ...lastMessage, timestamp: (/* @__PURE__ */ new Date()).toISOString() }
593
+ {
594
+ ...lastMessage,
595
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
596
+ ...component.allowResponseInspection && responseTrace != null ? { responseTraceId: responseTrace.traceId } : {}
597
+ }
413
598
  ]
414
599
  };
415
600
  };
@@ -473,7 +658,7 @@ function createUiGraphInteractionController(initialUiGraph, options = {}) {
473
658
  }
474
659
  const statePatch = actionController.resolveStatePatch(
475
660
  execution,
476
- stampChatResponseAtBrowserReceipt(component, result.statePatch)
661
+ stampChatResponseAtBrowserReceipt(component, result.statePatch, result.responseTrace)
477
662
  );
478
663
  if (statePatch) {
479
664
  const nextState = applyUiGraphStatePatch(state, statePatch);
@@ -791,17 +976,17 @@ function applyUiGraphStatePatch(state, statePatch) {
791
976
  // src/model/UiGraphActionProtocol.ts
792
977
  var RIVET_WEB_APP_ACTION_PROTOCOL_VERSION = 1;
793
978
  function parseRivetWebAppClientMessage(value) {
794
- if (!isRecord(value) || typeof value.type !== "string") return void 0;
979
+ if (!isRecord2(value) || typeof value.type !== "string") return void 0;
795
980
  switch (value.type) {
796
981
  case "client.hello":
797
982
  return value.protocolVersion === RIVET_WEB_APP_ACTION_PROTOCOL_VERSION ? { type: value.type, protocolVersion: value.protocolVersion } : void 0;
798
983
  case "action.start":
799
- return isNonEmptyString(value.requestId) && isNonEmptyString(value.componentId) && isRecord(value.state) && (value.storage == null || isRecord(value.storage)) && (value.revisionKey == null || typeof value.revisionKey === "string") ? {
984
+ return isNonEmptyString(value.requestId) && isNonEmptyString(value.componentId) && isRecord2(value.state) && (value.storage == null || isRecord2(value.storage)) && (value.revisionKey == null || typeof value.revisionKey === "string") ? {
800
985
  type: value.type,
801
986
  requestId: value.requestId,
802
987
  componentId: value.componentId,
803
988
  state: value.state,
804
- ...isRecord(value.storage) ? { storage: value.storage } : {},
989
+ ...isRecord2(value.storage) ? { storage: value.storage } : {},
805
990
  ...typeof value.revisionKey === "string" ? { revisionKey: value.revisionKey } : {}
806
991
  } : void 0;
807
992
  case "action.cancel":
@@ -813,7 +998,7 @@ function parseRivetWebAppClientMessage(value) {
813
998
  }
814
999
  }
815
1000
  function parseRivetWebAppServerMessage(value) {
816
- if (!isRecord(value) || typeof value.type !== "string") return void 0;
1001
+ if (!isRecord2(value) || typeof value.type !== "string") return void 0;
817
1002
  if (value.type === "server.ready") {
818
1003
  return value.protocolVersion === RIVET_WEB_APP_ACTION_PROTOCOL_VERSION ? { type: value.type, protocolVersion: value.protocolVersion } : void 0;
819
1004
  }
@@ -845,7 +1030,7 @@ function parseRivetWebAppServerMessage(value) {
845
1030
  case "action.cancelled":
846
1031
  return { type: value.type, ...base };
847
1032
  case "action.progress": {
848
- if (!isRecord(value.progress)) return void 0;
1033
+ if (!isRecord2(value.progress)) return void 0;
849
1034
  const progress = normalizeGraphProgress({
850
1035
  message: typeof value.progress.message === "string" ? value.progress.message : void 0,
851
1036
  percent: typeof value.progress.percent === "number" ? value.progress.percent : void 0
@@ -853,18 +1038,20 @@ function parseRivetWebAppServerMessage(value) {
853
1038
  return progress ? { type: value.type, ...base, progress } : void 0;
854
1039
  }
855
1040
  case "action.completed":
856
- return isRecord(value.statePatch) && (value.storagePatch == null || isRecord(value.storagePatch)) ? {
1041
+ return isRecord2(value.statePatch) && (value.storagePatch == null || isRecord2(value.storagePatch)) ? {
857
1042
  type: value.type,
858
1043
  ...base,
859
1044
  statePatch: value.statePatch,
860
- ...isRecord(value.storagePatch) ? { storagePatch: value.storagePatch } : {}
1045
+ ...isRecord2(value.storagePatch) ? { storagePatch: value.storagePatch } : {},
1046
+ ...isAgentResponseTrace(value.responseTrace) ? { responseTrace: value.responseTrace } : {}
861
1047
  } : void 0;
862
1048
  case "action.failed":
863
1049
  return isNonEmptyString(value.error) ? {
864
1050
  type: value.type,
865
1051
  ...base,
866
1052
  error: value.error,
867
- ...typeof value.code === "string" ? { code: value.code } : {}
1053
+ ...typeof value.code === "string" ? { code: value.code } : {},
1054
+ ...isAgentResponseTrace(value.responseTrace) ? { responseTrace: value.responseTrace } : {}
868
1055
  } : void 0;
869
1056
  case "action.interrupted":
870
1057
  return isNonEmptyString(value.error) ? { type: value.type, ...base, error: value.error } : void 0;
@@ -875,7 +1062,7 @@ function parseRivetWebAppServerMessage(value) {
875
1062
  function hasRunEventBase(value) {
876
1063
  return isNonEmptyString(value.requestId) && isNonEmptyString(value.runId) && typeof value.sequence === "number" && Number.isSafeInteger(value.sequence) && value.sequence > 0;
877
1064
  }
878
- function isRecord(value) {
1065
+ function isRecord2(value) {
879
1066
  return typeof value === "object" && value != null && !Array.isArray(value);
880
1067
  }
881
1068
  function isNonEmptyString(value) {
@@ -891,6 +1078,10 @@ var CHAT_SEARCH_MATCH_CLASS = "rivet-web-app-chat-search-match";
891
1078
  var CHAT_SEARCH_ACTIVE_MATCH_CLASS = "rivet-web-app-chat-search-match-active";
892
1079
  var UI_GRAPH_CHAT_STORAGE_PREFIX = "rivet-web-app-chat-state:v1";
893
1080
  var UI_GRAPH_APP_STORAGE_PREFIX = "rivet-web-app-storage:v1";
1081
+ var UI_GRAPH_RESPONSE_TRACE_STORAGE_PREFIX = "rivet-web-app-response-traces:v1";
1082
+ var UI_GRAPH_RESPONSE_TRACE_LIMIT = 100;
1083
+ var responseTraceMemoryFallback = /* @__PURE__ */ new Map();
1084
+ var unsyncedResponseTraceKeysByStorage = /* @__PURE__ */ new WeakMap();
894
1085
  var escapeRegularExpression = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
895
1086
  var getPixelValue = (value, fallback) => {
896
1087
  const parsed = Number.parseFloat(value);
@@ -901,7 +1092,7 @@ var setStyleProperty = (element, property, value) => {
901
1092
  element.style.setProperty(property, value);
902
1093
  }
903
1094
  };
904
- var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1095
+ var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
905
1096
  var getDefaultUiGraphBrowserStorage = () => {
906
1097
  var _a;
907
1098
  try {
@@ -945,21 +1136,37 @@ function getUiGraphChatMessagePresentations(messages, options = {}) {
945
1136
  dateKey: dateKeyFormatter.format(timestamp),
946
1137
  dateTime: timestamp.toISOString(),
947
1138
  dateLabel: dateFormatter.format(timestamp),
948
- timeLabel: timeFormatter.format(timestamp)
1139
+ timeLabel: timeFormatter.format(timestamp),
1140
+ timestamp
949
1141
  };
950
1142
  });
951
1143
  const hasMultipleDates = new Set(entries.flatMap((entry) => entry ? [entry.dateKey] : [])).size > 1;
952
1144
  let previousDateKey;
953
- return entries.map((entry) => {
1145
+ let previousUserTimestamp;
1146
+ return entries.map((entry, index) => {
1147
+ const message = messages[index];
1148
+ if (message.role === "user") {
1149
+ previousUserTimestamp = entry == null ? void 0 : entry.timestamp;
1150
+ }
954
1151
  if (!entry) return {};
955
1152
  const dateSeparator = hasMultipleDates && previousDateKey != null && previousDateKey !== entry.dateKey ? { dateTime: entry.dateTime, label: entry.dateLabel } : void 0;
956
1153
  previousDateKey = entry.dateKey;
1154
+ const elapsedSincePreviousUserMessage = message.role === "assistant" && previousUserTimestamp ? formatUiGraphChatElapsedSeconds(entry.timestamp.getTime() - previousUserTimestamp.getTime()) : void 0;
957
1155
  return {
958
1156
  ...dateSeparator ? { dateSeparator } : {},
959
- timestamp: { dateTime: entry.dateTime, label: entry.timeLabel }
1157
+ timestamp: {
1158
+ dateTime: entry.dateTime,
1159
+ ...elapsedSincePreviousUserMessage ? { elapsedSincePreviousUserMessage } : {},
1160
+ label: entry.timeLabel
1161
+ }
960
1162
  };
961
1163
  });
962
1164
  }
1165
+ var formatUiGraphChatElapsedSeconds = (elapsedMilliseconds) => {
1166
+ if (!Number.isFinite(elapsedMilliseconds) || elapsedMilliseconds < 0) return void 0;
1167
+ const seconds = Math.round(elapsedMilliseconds / 1e3 * 10) / 10;
1168
+ return `${Number.isInteger(seconds) ? seconds : seconds.toFixed(1)} seconds after previous user message`;
1169
+ };
963
1170
  var parseUiGraphChatTimestamp = (value) => {
964
1171
  if (typeof value !== "string") return void 0;
965
1172
  const timestamp = new Date(value);
@@ -989,6 +1196,103 @@ function getUiGraphWebAppStorageKey(uiGraph, location = getDefaultUiGraphStorage
989
1196
  encodeURIComponent(uiGraph.id)
990
1197
  ].join(":");
991
1198
  }
1199
+ function getUiGraphResponseTraceStorageKey(uiGraph, componentId, location = getDefaultUiGraphStorageLocation()) {
1200
+ if (!(location == null ? void 0 : location.origin)) return void 0;
1201
+ const pathname = location.pathname.replace(/\/+$/, "") || "/";
1202
+ return [
1203
+ UI_GRAPH_RESPONSE_TRACE_STORAGE_PREFIX,
1204
+ encodeURIComponent(location.origin),
1205
+ encodeURIComponent(pathname),
1206
+ encodeURIComponent(uiGraph.id),
1207
+ encodeURIComponent(componentId)
1208
+ ].join(":");
1209
+ }
1210
+ var isUiGraphResponseInspectionEnabled = (uiGraph, componentId) => uiGraph.components.some(
1211
+ (component) => component.type === "chat" && component.id === componentId && component.allowResponseInspection === true
1212
+ );
1213
+ var removeUiGraphChatResponseTraceIds = (messages) => messages.map((message) => {
1214
+ if (message.responseTraceId == null) return message;
1215
+ const sanitized = { ...message };
1216
+ delete sanitized.responseTraceId;
1217
+ return sanitized;
1218
+ });
1219
+ var purgeDisabledUiGraphResponseTraces = (uiGraph, storage, location) => {
1220
+ for (const component of uiGraph.components) {
1221
+ if (component.type !== "chat" || component.allowResponseInspection === true) continue;
1222
+ const key = getUiGraphResponseTraceStorageKey(uiGraph, component.id, location) ?? `memory:${uiGraph.id}:${component.id}`;
1223
+ persistUiGraphResponseTraces(key, [], storage);
1224
+ }
1225
+ };
1226
+ function saveUiGraphResponseTrace(uiGraph, componentId, trace, storage = getDefaultUiGraphBrowserStorage(), location) {
1227
+ if (!isAgentResponseTrace(trace)) return;
1228
+ if (!isUiGraphResponseInspectionEnabled(uiGraph, componentId)) {
1229
+ const key2 = getUiGraphResponseTraceStorageKey(uiGraph, componentId, location) ?? `memory:${uiGraph.id}:${componentId}`;
1230
+ persistUiGraphResponseTraces(key2, [], storage);
1231
+ return;
1232
+ }
1233
+ const key = getUiGraphResponseTraceStorageKey(uiGraph, componentId, location) ?? `memory:${uiGraph.id}:${componentId}`;
1234
+ const traces = loadUiGraphResponseTraces(uiGraph, componentId, storage, location).filter(
1235
+ (candidate) => candidate.traceId !== trace.traceId
1236
+ );
1237
+ traces.push(trace);
1238
+ const bounded = traces.slice(-UI_GRAPH_RESPONSE_TRACE_LIMIT);
1239
+ persistUiGraphResponseTraces(key, bounded, storage);
1240
+ }
1241
+ function loadUiGraphResponseTrace(uiGraph, componentId, traceId, storage = getDefaultUiGraphBrowserStorage(), location) {
1242
+ if (!isUiGraphResponseInspectionEnabled(uiGraph, componentId)) return void 0;
1243
+ return loadUiGraphResponseTraces(uiGraph, componentId, storage, location).find((trace) => trace.traceId === traceId);
1244
+ }
1245
+ function pruneUiGraphResponseTraces(uiGraph, state, storage = getDefaultUiGraphBrowserStorage(), location) {
1246
+ for (const component of uiGraph.components) {
1247
+ if (component.type !== "chat") continue;
1248
+ const referenced = component.allowResponseInspection === true ? new Set(
1249
+ getUiGraphChatMessages(component.id, state).flatMap(
1250
+ (message) => typeof message.responseTraceId === "string" ? [message.responseTraceId] : []
1251
+ )
1252
+ ) : /* @__PURE__ */ new Set();
1253
+ const key = getUiGraphResponseTraceStorageKey(uiGraph, component.id, location) ?? `memory:${uiGraph.id}:${component.id}`;
1254
+ const retained = loadUiGraphResponseTraces(uiGraph, component.id, storage, location).filter(
1255
+ (trace) => referenced.has(trace.traceId)
1256
+ );
1257
+ persistUiGraphResponseTraces(key, retained, storage);
1258
+ }
1259
+ }
1260
+ function persistUiGraphResponseTraces(key, traces, storage) {
1261
+ var _a;
1262
+ responseTraceMemoryFallback.set(key, traces);
1263
+ if (!storage || key.startsWith("memory:")) return;
1264
+ try {
1265
+ if (traces.length === 0) storage.removeItem(key);
1266
+ else storage.setItem(key, JSON.stringify(traces));
1267
+ (_a = unsyncedResponseTraceKeysByStorage.get(storage)) == null ? void 0 : _a.delete(key);
1268
+ } catch {
1269
+ const unsyncedKeys = unsyncedResponseTraceKeysByStorage.get(storage) ?? /* @__PURE__ */ new Set();
1270
+ unsyncedKeys.add(key);
1271
+ unsyncedResponseTraceKeysByStorage.set(storage, unsyncedKeys);
1272
+ }
1273
+ }
1274
+ function loadUiGraphResponseTraces(uiGraph, componentId, storage, location) {
1275
+ var _a;
1276
+ const key = getUiGraphResponseTraceStorageKey(uiGraph, componentId, location) ?? `memory:${uiGraph.id}:${componentId}`;
1277
+ if (storage && ((_a = unsyncedResponseTraceKeysByStorage.get(storage)) == null ? void 0 : _a.has(key))) {
1278
+ return responseTraceMemoryFallback.get(key) ?? [];
1279
+ }
1280
+ if (storage && !key.startsWith("memory:")) {
1281
+ try {
1282
+ const raw = storage.getItem(key);
1283
+ if (raw) {
1284
+ const parsed = JSON.parse(raw);
1285
+ if (Array.isArray(parsed)) {
1286
+ const traces = parsed.filter(isAgentResponseTrace).slice(-UI_GRAPH_RESPONSE_TRACE_LIMIT);
1287
+ responseTraceMemoryFallback.set(key, traces);
1288
+ return traces;
1289
+ }
1290
+ }
1291
+ } catch {
1292
+ }
1293
+ }
1294
+ return responseTraceMemoryFallback.get(key) ?? [];
1295
+ }
992
1296
  function loadUiGraphWebAppStorage(uiGraph, storage = getDefaultUiGraphBrowserStorage(), location) {
993
1297
  const key = getUiGraphWebAppStorageKey(uiGraph, location);
994
1298
  if (!key || !storage) return {};
@@ -996,7 +1300,7 @@ function loadUiGraphWebAppStorage(uiGraph, storage = getDefaultUiGraphBrowserSto
996
1300
  const serialized = storage.getItem(key);
997
1301
  if (!serialized) return {};
998
1302
  const value = JSON.parse(serialized);
999
- return isRecord2(value) ? value : {};
1303
+ return isRecord3(value) ? value : {};
1000
1304
  } catch {
1001
1305
  return {};
1002
1306
  }
@@ -1037,12 +1341,13 @@ function getUiGraphChatPersistentState(uiGraph, state) {
1037
1341
  const pinsStateKey = getUiGraphChatPinsStateKey(component.id);
1038
1342
  const draft = state[draftStateKey];
1039
1343
  const messages = getUiGraphChatMessages(component.id, state);
1344
+ const persistedMessages = component.allowResponseInspection === true ? messages : removeUiGraphChatResponseTraceIds(messages);
1040
1345
  const pins = getUiGraphChatPins(component.id, state).map((pin) => pin.messageIndex);
1041
1346
  if (typeof draft === "string" && draft) {
1042
1347
  persistentState[draftStateKey] = draft;
1043
1348
  }
1044
- if (messages.length > 0) {
1045
- persistentState[messagesStateKey] = messages;
1349
+ if (persistedMessages.length > 0) {
1350
+ persistentState[messagesStateKey] = persistedMessages;
1046
1351
  }
1047
1352
  if (pins.length > 0) {
1048
1353
  persistentState[pinsStateKey] = pins;
@@ -1067,12 +1372,13 @@ function loadUiGraphChatPersistentState(uiGraph, storage = getDefaultUiGraphBrow
1067
1372
  return {};
1068
1373
  }
1069
1374
  const storedState = JSON.parse(serializedState);
1070
- return isRecord2(storedState) ? getUiGraphChatPersistentState(uiGraph, storedState) : {};
1375
+ return isRecord3(storedState) ? getUiGraphChatPersistentState(uiGraph, storedState) : {};
1071
1376
  } catch {
1072
1377
  return {};
1073
1378
  }
1074
1379
  }
1075
1380
  function saveUiGraphChatPersistentState(uiGraph, state, storage = getDefaultUiGraphBrowserStorage(), location) {
1381
+ purgeDisabledUiGraphResponseTraces(uiGraph, storage, location);
1076
1382
  const key = getUiGraphChatStorageKey(uiGraph, location);
1077
1383
  if (!key || !storage) {
1078
1384
  return;
@@ -1310,6 +1616,7 @@ var revealUiGraphChatSearchMatch = revealUiGraphChatElement;
1310
1616
  copyUiGraphText,
1311
1617
  createUiGraphActionExecutionController,
1312
1618
  createUiGraphChatHistoryFlushStatePatch,
1619
+ createUiGraphChatMessageRemovalStatePatch,
1313
1620
  createUiGraphChatPinStatePatch,
1314
1621
  createUiGraphChatSubmissionStatePatch,
1315
1622
  createUiGraphInteractionController,
@@ -1327,13 +1634,17 @@ var revealUiGraphChatSearchMatch = revealUiGraphChatElement;
1327
1634
  getUiGraphWebAppStorageKey,
1328
1635
  hasUiGraphChatPersistentStateChanged,
1329
1636
  highlightUiGraphChatSearchMatches,
1637
+ isAgentResponseTrace,
1330
1638
  loadUiGraphChatPersistentState,
1639
+ loadUiGraphResponseTrace,
1331
1640
  loadUiGraphWebAppStorage,
1332
1641
  observeUiGraphOutputResizeBounds,
1333
1642
  parseRivetWebAppClientMessage,
1334
1643
  parseRivetWebAppServerMessage,
1644
+ pruneUiGraphResponseTraces,
1335
1645
  revealUiGraphChatElement,
1336
1646
  revealUiGraphChatSearchMatch,
1337
- saveUiGraphChatPersistentState
1647
+ saveUiGraphChatPersistentState,
1648
+ saveUiGraphResponseTrace
1338
1649
  });
1339
1650
  //# sourceMappingURL=webAppRuntime.cjs.map