@bastani/atomic 0.9.3-alpha.1 → 0.9.3-alpha.2

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 (172) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/builtin/cursor/CHANGELOG.md +15 -0
  3. package/dist/builtin/cursor/README.md +2 -1
  4. package/dist/builtin/cursor/package.json +2 -2
  5. package/dist/builtin/cursor/src/cursor-models-raw.json +2 -9
  6. package/dist/builtin/cursor/src/model-mapper.ts +14 -3
  7. package/dist/builtin/cursor/src/proto/protobuf-codec-base64.ts +22 -0
  8. package/dist/builtin/cursor/src/proto/protobuf-codec-request.ts +53 -13
  9. package/dist/builtin/cursor/src/proto/protobuf-codec-wire.ts +24 -7
  10. package/dist/builtin/cursor/src/proto/protobuf-codec.ts +3 -2
  11. package/dist/builtin/cursor/src/stream.ts +5 -11
  12. package/dist/builtin/cursor/src/transport-types.ts +3 -0
  13. package/dist/builtin/cursor/src/transport.ts +1 -0
  14. package/dist/builtin/intercom/package.json +1 -1
  15. package/dist/builtin/mcp/package.json +1 -1
  16. package/dist/builtin/subagents/CHANGELOG.md +9 -0
  17. package/dist/builtin/subagents/package.json +1 -1
  18. package/dist/builtin/subagents/src/extension/fanout-child.ts +1 -0
  19. package/dist/builtin/subagents/src/extension/index.ts +6 -3
  20. package/dist/builtin/subagents/src/extension/schemas.ts +0 -5
  21. package/dist/builtin/subagents/src/runs/background/async-job-tracker.ts +1 -4
  22. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-single.ts +15 -1
  23. package/dist/builtin/subagents/src/runs/foreground/subagent-executor.ts +35 -1
  24. package/dist/builtin/subagents/src/runs/shared/subagent-prompt-runtime.ts +4 -2
  25. package/dist/builtin/subagents/src/shared/types-async.ts +1 -0
  26. package/dist/builtin/subagents/src/slash/prompt-template-bridge.ts +27 -5
  27. package/dist/builtin/subagents/src/tui/render-layout.ts +27 -4
  28. package/dist/builtin/subagents/src/tui/render-result-animation.ts +22 -31
  29. package/dist/builtin/subagents/src/tui/render-result-compact.ts +6 -6
  30. package/dist/builtin/subagents/src/tui/render-result.ts +20 -19
  31. package/dist/builtin/subagents/src/tui/render-status-progress.ts +3 -3
  32. package/dist/builtin/subagents/src/tui/render-widget.ts +46 -7
  33. package/dist/builtin/subagents/src/tui/render.ts +2 -2
  34. package/dist/builtin/web-access/package.json +1 -1
  35. package/dist/builtin/workflows/CHANGELOG.md +43 -0
  36. package/dist/builtin/workflows/README.md +1 -1
  37. package/dist/builtin/workflows/package.json +1 -1
  38. package/dist/builtin/workflows/src/authoring.d.ts +1 -1
  39. package/dist/builtin/workflows/src/durable/backend.ts +343 -0
  40. package/dist/builtin/workflows/src/durable/child-primitive.ts +79 -0
  41. package/dist/builtin/workflows/src/durable/dbos-backend.ts +421 -0
  42. package/dist/builtin/workflows/src/durable/dbos-envelope.ts +171 -0
  43. package/dist/builtin/workflows/src/durable/factory.ts +96 -0
  44. package/dist/builtin/workflows/src/durable/file-backend.ts +433 -0
  45. package/dist/builtin/workflows/src/durable/index.ts +73 -0
  46. package/dist/builtin/workflows/src/durable/resume-catalog.ts +217 -0
  47. package/dist/builtin/workflows/src/durable/resume-runtime.ts +299 -0
  48. package/dist/builtin/workflows/src/durable/scoped-backend.ts +171 -0
  49. package/dist/builtin/workflows/src/durable/stage-primitive.ts +284 -0
  50. package/dist/builtin/workflows/src/durable/tool-primitive.ts +180 -0
  51. package/dist/builtin/workflows/src/durable/types.ts +168 -0
  52. package/dist/builtin/workflows/src/durable/ui-primitive.ts +96 -0
  53. package/dist/builtin/workflows/src/engine/options.ts +3 -0
  54. package/dist/builtin/workflows/src/engine/primitives/parallel.ts +2 -2
  55. package/dist/builtin/workflows/src/engine/primitives/task.ts +4 -4
  56. package/dist/builtin/workflows/src/engine/primitives/ui.ts +22 -8
  57. package/dist/builtin/workflows/src/engine/primitives/workflow.ts +8 -0
  58. package/dist/builtin/workflows/src/engine/run-durable-finalize.ts +69 -0
  59. package/dist/builtin/workflows/src/engine/run-durable-stage-session.ts +31 -0
  60. package/dist/builtin/workflows/src/engine/run.ts +148 -6
  61. package/dist/builtin/workflows/src/engine/runtime.ts +8 -2
  62. package/dist/builtin/workflows/src/extension/extension-factory.ts +6 -12
  63. package/dist/builtin/workflows/src/extension/extension-lifecycle.ts +5 -1
  64. package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +3 -0
  65. package/dist/builtin/workflows/src/extension/runtime.ts +48 -9
  66. package/dist/builtin/workflows/src/extension/workflow-run-control-command.ts +143 -4
  67. package/dist/builtin/workflows/src/runs/background/quit.ts +61 -0
  68. package/dist/builtin/workflows/src/runs/background/status.ts +1 -0
  69. package/dist/builtin/workflows/src/runs/foreground/executor-direct-helpers.ts +5 -5
  70. package/dist/builtin/workflows/src/runs/foreground/executor-stage-call.ts +74 -33
  71. package/dist/builtin/workflows/src/runs/foreground/executor-stage-context.ts +20 -1
  72. package/dist/builtin/workflows/src/runs/foreground/executor-stage-factory.ts +8 -7
  73. package/dist/builtin/workflows/src/runs/foreground/executor-stage-replay.ts +1 -0
  74. package/dist/builtin/workflows/src/runs/foreground/executor-stage-types.ts +1 -1
  75. package/dist/builtin/workflows/src/runs/foreground/executor-types.ts +19 -2
  76. package/dist/builtin/workflows/src/runs/foreground/stage-runner-context.ts +4 -0
  77. package/dist/builtin/workflows/src/runs/foreground/stage-runner-controller.ts +10 -10
  78. package/dist/builtin/workflows/src/runs/foreground/stage-runner-options.ts +5 -1
  79. package/dist/builtin/workflows/src/runs/foreground/stage-runner-send-user-message.ts +25 -0
  80. package/dist/builtin/workflows/src/runs/foreground/stage-runner-types.ts +3 -0
  81. package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +16 -0
  82. package/dist/builtin/workflows/src/shared/authoring-contract-stage.ts +20 -0
  83. package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +23 -1
  84. package/dist/builtin/workflows/src/shared/authoring-contract-ui.ts +30 -1
  85. package/dist/builtin/workflows/src/shared/store-public-types.ts +6 -2
  86. package/dist/builtin/workflows/src/shared/store-run-methods.ts +12 -6
  87. package/dist/builtin/workflows/src/shared/types.ts +55 -0
  88. package/dist/builtin/workflows/src/tui/graph-view-constants.ts +1 -1
  89. package/dist/builtin/workflows/src/tui/graph-view-graph-render.ts +41 -0
  90. package/dist/builtin/workflows/src/tui/graph-view-input.ts +82 -24
  91. package/dist/builtin/workflows/src/tui/graph-view-render.ts +7 -0
  92. package/dist/builtin/workflows/src/tui/graph-view-state.ts +22 -2
  93. package/dist/builtin/workflows/src/tui/graph-view-types.ts +4 -5
  94. package/dist/builtin/workflows/src/tui/overlay-adapter.ts +9 -11
  95. package/dist/builtin/workflows/src/tui/stage-chat-view-footer-status.ts +9 -3
  96. package/dist/builtin/workflows/src/tui/stage-chat-view-input.ts +11 -2
  97. package/dist/builtin/workflows/src/tui/stage-chat-view-live-events.ts +35 -0
  98. package/dist/builtin/workflows/src/tui/stage-chat-view-state.ts +51 -17
  99. package/dist/builtin/workflows/src/tui/stage-chat-view-status.ts +36 -0
  100. package/dist/builtin/workflows/src/tui/stage-chat-view-types.ts +5 -1
  101. package/dist/builtin/workflows/src/tui/stage-chat-view.ts +3 -1
  102. package/dist/builtin/workflows/src/tui/status-list.ts +14 -2
  103. package/dist/builtin/workflows/src/tui/widget.ts +23 -8
  104. package/dist/builtin/workflows/src/tui/workflow-attach-pane-types.ts +5 -4
  105. package/dist/builtin/workflows/src/tui/workflow-attach-pane.ts +8 -8
  106. package/dist/builtin/workflows/src/tui/workflow-resume-selector.ts +151 -0
  107. package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
  108. package/dist/core/extensions/loader-virtual-modules.js +47 -30
  109. package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
  110. package/dist/core/messages.d.ts +1 -0
  111. package/dist/core/messages.d.ts.map +1 -1
  112. package/dist/core/messages.js +46 -1
  113. package/dist/core/messages.js.map +1 -1
  114. package/dist/core/sdk.d.ts.map +1 -1
  115. package/dist/core/sdk.js +12 -0
  116. package/dist/core/sdk.js.map +1 -1
  117. package/dist/core/session-manager-core.d.ts +15 -7
  118. package/dist/core/session-manager-core.d.ts.map +1 -1
  119. package/dist/core/session-manager-core.js +20 -9
  120. package/dist/core/session-manager-core.js.map +1 -1
  121. package/dist/core/session-manager-entries.d.ts +2 -2
  122. package/dist/core/session-manager-entries.d.ts.map +1 -1
  123. package/dist/core/session-manager-entries.js +9 -3
  124. package/dist/core/session-manager-entries.js.map +1 -1
  125. package/dist/core/session-manager-history.d.ts.map +1 -1
  126. package/dist/core/session-manager-history.js +2 -1
  127. package/dist/core/session-manager-history.js.map +1 -1
  128. package/dist/core/session-manager-list.d.ts +3 -3
  129. package/dist/core/session-manager-list.d.ts.map +1 -1
  130. package/dist/core/session-manager-list.js +27 -8
  131. package/dist/core/session-manager-list.js.map +1 -1
  132. package/dist/core/session-manager-storage.d.ts +3 -1
  133. package/dist/core/session-manager-storage.d.ts.map +1 -1
  134. package/dist/core/session-manager-storage.js +55 -12
  135. package/dist/core/session-manager-storage.js.map +1 -1
  136. package/dist/core/session-manager-tool-dependencies.d.ts +10 -0
  137. package/dist/core/session-manager-tool-dependencies.d.ts.map +1 -0
  138. package/dist/core/session-manager-tool-dependencies.js +133 -0
  139. package/dist/core/session-manager-tool-dependencies.js.map +1 -0
  140. package/dist/core/session-manager-types.d.ts +22 -0
  141. package/dist/core/session-manager-types.d.ts.map +1 -1
  142. package/dist/core/session-manager-types.js.map +1 -1
  143. package/dist/core/session-manager.d.ts +2 -2
  144. package/dist/core/session-manager.d.ts.map +1 -1
  145. package/dist/core/session-manager.js +1 -1
  146. package/dist/core/session-manager.js.map +1 -1
  147. package/dist/modes/interactive/components/chat-session-host-runtime.d.ts +1 -0
  148. package/dist/modes/interactive/components/chat-session-host-runtime.d.ts.map +1 -1
  149. package/dist/modes/interactive/components/chat-session-host-runtime.js +12 -0
  150. package/dist/modes/interactive/components/chat-session-host-runtime.js.map +1 -1
  151. package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.d.ts +4 -0
  152. package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.d.ts.map +1 -0
  153. package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.js +131 -0
  154. package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.js.map +1 -0
  155. package/dist/modes/interactive/components/chat-session-host.d.ts +2 -0
  156. package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
  157. package/dist/modes/interactive/components/chat-session-host.js +7 -1
  158. package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
  159. package/dist/modes/interactive/components/chat-transcript.d.ts.map +1 -1
  160. package/dist/modes/interactive/components/chat-transcript.js +15 -4
  161. package/dist/modes/interactive/components/chat-transcript.js.map +1 -1
  162. package/dist/modes/interactive/components/tool-execution.d.ts +3 -0
  163. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  164. package/dist/modes/interactive/components/tool-execution.js +26 -0
  165. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  166. package/docs/compaction.md +2 -0
  167. package/docs/models.md +1 -1
  168. package/docs/providers.md +2 -1
  169. package/docs/session-format.md +6 -0
  170. package/docs/sessions.md +6 -0
  171. package/docs/workflows.md +105 -3
  172. package/package.json +4 -3
@@ -0,0 +1,131 @@
1
+ export function finalizeTerminalWorkflowToolEntries(entries) {
2
+ let changed = false;
3
+ for (let i = 0; i < entries.length; i++) {
4
+ const entry = entries[i];
5
+ if (!isToolEntry(entry))
6
+ continue;
7
+ const finalized = finalizeToolEntry(entry);
8
+ if (finalized !== entry) {
9
+ entries[i] = finalized;
10
+ changed = true;
11
+ }
12
+ }
13
+ return changed;
14
+ }
15
+ function finalizeToolEntry(entry) {
16
+ const result = entry.result ? finalizeToolResult(entry.result) : undefined;
17
+ const resultChanged = result !== entry.result;
18
+ if (entry.isPartial === false && !resultChanged)
19
+ return entry;
20
+ return {
21
+ ...entry,
22
+ ...(result ? { result } : {}),
23
+ isPartial: false,
24
+ };
25
+ }
26
+ function finalizeToolResult(result) {
27
+ const details = finalizeDetails(result.details);
28
+ if (details === result.details)
29
+ return result;
30
+ return { ...result, details };
31
+ }
32
+ function finalizeDetails(details) {
33
+ if (!isRecord(details))
34
+ return details;
35
+ let changed = false;
36
+ const next = { ...details };
37
+ const progress = finalizeProgressArray(next.progress);
38
+ if (progress !== next.progress) {
39
+ next.progress = progress;
40
+ changed = true;
41
+ }
42
+ if (Array.isArray(next.results)) {
43
+ const results = next.results.map((item) => finalizeResultEntry(item));
44
+ if (results.some((item, index) => item !== next.results[index])) {
45
+ next.results = results;
46
+ changed = true;
47
+ }
48
+ }
49
+ const workflowGraph = finalizeWorkflowGraph(next.workflowGraph);
50
+ if (workflowGraph !== next.workflowGraph) {
51
+ next.workflowGraph = workflowGraph;
52
+ changed = true;
53
+ }
54
+ return changed ? next : details;
55
+ }
56
+ function finalizeResultEntry(entry) {
57
+ if (!isRecord(entry))
58
+ return entry;
59
+ const progress = finalizeProgress(entry.progress);
60
+ if (progress === entry.progress)
61
+ return entry;
62
+ return { ...entry, progress };
63
+ }
64
+ function finalizeProgressArray(progress) {
65
+ if (!Array.isArray(progress))
66
+ return progress;
67
+ let changed = false;
68
+ const next = progress.map((entry) => {
69
+ const finalized = finalizeProgress(entry);
70
+ if (finalized !== entry)
71
+ changed = true;
72
+ return finalized;
73
+ });
74
+ return changed ? next : progress;
75
+ }
76
+ function finalizeProgress(progress) {
77
+ if (!isRecord(progress) || progress.status !== "running")
78
+ return progress;
79
+ return {
80
+ ...progress,
81
+ status: "detached",
82
+ activityState: undefined,
83
+ currentTool: undefined,
84
+ currentToolArgs: undefined,
85
+ currentToolStartedAt: undefined,
86
+ };
87
+ }
88
+ function finalizeWorkflowGraph(graph) {
89
+ if (!isRecord(graph))
90
+ return graph;
91
+ const nodes = finalizeWorkflowGraphNodes(graph.nodes);
92
+ const shouldClearCurrent = graph.currentNodeId !== undefined;
93
+ if (nodes === graph.nodes && !shouldClearCurrent)
94
+ return graph;
95
+ return { ...graph, nodes, currentNodeId: undefined };
96
+ }
97
+ function finalizeWorkflowGraphNodes(nodes) {
98
+ if (!Array.isArray(nodes))
99
+ return nodes;
100
+ let changed = false;
101
+ const next = nodes.map((node) => {
102
+ const finalized = finalizeWorkflowGraphNode(node);
103
+ if (finalized !== node)
104
+ changed = true;
105
+ return finalized;
106
+ });
107
+ return changed ? next : nodes;
108
+ }
109
+ function finalizeWorkflowGraphNode(node) {
110
+ if (!isRecord(node))
111
+ return node;
112
+ let changed = false;
113
+ const next = { ...node };
114
+ if (next.status === "running") {
115
+ next.status = "detached";
116
+ changed = true;
117
+ }
118
+ const children = finalizeWorkflowGraphNodes(next.children);
119
+ if (children !== next.children) {
120
+ next.children = children;
121
+ changed = true;
122
+ }
123
+ return changed ? next : node;
124
+ }
125
+ function isToolEntry(entry) {
126
+ return entry.role === "tool" && "kind" in entry && entry.kind === "tool";
127
+ }
128
+ function isRecord(value) {
129
+ return value !== null && typeof value === "object" && !Array.isArray(value);
130
+ }
131
+ //# sourceMappingURL=chat-session-host-terminal-cleanup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-session-host-terminal-cleanup.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/chat-session-host-terminal-cleanup.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,mCAAmC,CAEjD,OAA4C;IAC5C,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QACzB,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;YAAE,SAAS;QAClC,MAAM,SAAS,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAC3C,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;YACxB,OAAO,CAAC,CAAC,CAAC,GAAG,SAA8C,CAAC;YAC5D,OAAO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ts\";\n\ntype ToolEntry = Extract<ChatSessionHostEntry<ChatTranscriptEntryLike>, { kind: \"tool\" }>;\ntype ToolResult = NonNullable<ToolEntry[\"result\"]>;\ntype ObjectRecord = Record<string, unknown>;\n\nexport function finalizeTerminalWorkflowToolEntries<\n TExtraEntry extends ChatTranscriptEntryLike,\n>(entries: ChatSessionHostEntry<TExtraEntry>[]): boolean {\n let changed = false;\n for (let i = 0; i < entries.length; i++) {\n const entry = entries[i];\n if (!isToolEntry(entry)) continue;\n const finalized = finalizeToolEntry(entry);\n if (finalized !== entry) {\n entries[i] = finalized as ChatSessionHostEntry<TExtraEntry>;\n changed = true;\n }\n }\n return changed;\n}\n\nfunction finalizeToolEntry(entry: ToolEntry): ToolEntry {\n const result = entry.result ? finalizeToolResult(entry.result) : undefined;\n const resultChanged = result !== entry.result;\n if (entry.isPartial === false && !resultChanged) return entry;\n return {\n ...entry,\n ...(result ? { result } : {}),\n isPartial: false,\n };\n}\n\nfunction finalizeToolResult(result: ToolResult): ToolResult {\n const details = finalizeDetails(result.details);\n if (details === result.details) return result;\n return { ...result, details };\n}\n\nfunction finalizeDetails(details: unknown): unknown {\n if (!isRecord(details)) return details;\n let changed = false;\n const next: ObjectRecord = { ...details };\n const progress = finalizeProgressArray(next.progress);\n if (progress !== next.progress) {\n next.progress = progress;\n changed = true;\n }\n if (Array.isArray(next.results)) {\n const results = next.results.map((item) => finalizeResultEntry(item));\n if (results.some((item, index) => item !== (next.results as unknown[])[index])) {\n next.results = results;\n changed = true;\n }\n }\n const workflowGraph = finalizeWorkflowGraph(next.workflowGraph);\n if (workflowGraph !== next.workflowGraph) {\n next.workflowGraph = workflowGraph;\n changed = true;\n }\n return changed ? next : details;\n}\n\nfunction finalizeResultEntry(entry: unknown): unknown {\n if (!isRecord(entry)) return entry;\n const progress = finalizeProgress(entry.progress);\n if (progress === entry.progress) return entry;\n return { ...entry, progress };\n}\n\nfunction finalizeProgressArray(progress: unknown): unknown {\n if (!Array.isArray(progress)) return progress;\n let changed = false;\n const next = progress.map((entry) => {\n const finalized = finalizeProgress(entry);\n if (finalized !== entry) changed = true;\n return finalized;\n });\n return changed ? next : progress;\n}\n\nfunction finalizeProgress(progress: unknown): unknown {\n if (!isRecord(progress) || progress.status !== \"running\") return progress;\n return {\n ...progress,\n status: \"detached\",\n activityState: undefined,\n currentTool: undefined,\n currentToolArgs: undefined,\n currentToolStartedAt: undefined,\n };\n}\n\nfunction finalizeWorkflowGraph(graph: unknown): unknown {\n if (!isRecord(graph)) return graph;\n const nodes = finalizeWorkflowGraphNodes(graph.nodes);\n const shouldClearCurrent = graph.currentNodeId !== undefined;\n if (nodes === graph.nodes && !shouldClearCurrent) return graph;\n return { ...graph, nodes, currentNodeId: undefined };\n}\n\nfunction finalizeWorkflowGraphNodes(nodes: unknown): unknown {\n if (!Array.isArray(nodes)) return nodes;\n let changed = false;\n const next = nodes.map((node) => {\n const finalized = finalizeWorkflowGraphNode(node);\n if (finalized !== node) changed = true;\n return finalized;\n });\n return changed ? next : nodes;\n}\n\nfunction finalizeWorkflowGraphNode(node: unknown): unknown {\n if (!isRecord(node)) return node;\n let changed = false;\n const next: ObjectRecord = { ...node };\n if (next.status === \"running\") {\n next.status = \"detached\";\n changed = true;\n }\n const children = finalizeWorkflowGraphNodes(next.children);\n if (children !== next.children) {\n next.children = children;\n changed = true;\n }\n return changed ? next : node;\n}\n\nfunction isToolEntry(entry: ChatSessionHostEntry<ChatTranscriptEntryLike>): entry is ToolEntry {\n return entry.role === \"tool\" && \"kind\" in entry && entry.kind === \"tool\";\n}\n\nfunction isRecord(value: unknown): value is ObjectRecord {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n"]}
@@ -27,6 +27,7 @@ export declare class ChatSessionHost<TExtraEntry extends ChatTranscriptEntryLike
27
27
  isStreaming(): boolean;
28
28
  isBashRunning(): boolean;
29
29
  isEditingBashCommand(): boolean;
30
+ isCompacting(): boolean;
30
31
  hasInputText(): boolean;
31
32
  hasAnimationTick(): boolean;
32
33
  bodyScrollFromBottom(): number;
@@ -35,6 +36,7 @@ export declare class ChatSessionHost<TExtraEntry extends ChatTranscriptEntryLike
35
36
  statusText(): string;
36
37
  scrollToBottom(): void;
37
38
  syncAnimationTick(): void;
39
+ clearBusyForTerminalWorkflowStage(): void;
38
40
  dispose(): void;
39
41
  restoreQueuedMessagesToEditor(): boolean;
40
42
  private editorCallbacks;
@@ -1 +1 @@
1
- {"version":3,"file":"chat-session-host.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/chat-session-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AA8BpE,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,8BAA8B,CAAC;AAEtC,YAAY,EACV,0BAA0B,EAC1B,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,8BAA8B,CAAC;AAEtC,qBAAa,eAAe,CAAC,WAAW,SAAS,uBAAuB,GAAG,KAAK,CAC9E,YAAW,SAAS,EAAE,SAAS;IAE/B,OAAO,UAAQ;IAEf,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAoC;IAE1D,YAAY,IAAI,EAAE,mBAAmB,CAAC,WAAW,CAAC,EAcjD;IAED,cAAc,CAAC,QAAQ,EAAE,SAAS,oBAAoB,EAAE,GAAG,IAAI,CAE9D;IAED,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAUrD;IAED,gBAAgB,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAEzC;IAED,OAAO,IAAI,SAAS,oBAAoB,CAAC,WAAW,CAAC,EAAE,CAEtD;IAED,eAAe,CAAC,KA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AgentSessionEvent } from \"../../../core/agent-session.ts\";\nimport { type Component, type Focusable } from \"@earendil-works/pi-tui\";\nimport { SessionManager } from \"../../../core/session-manager.ts\";\nimport type { ChatTranscriptEntryLike } from \"./chat-transcript.ts\";\nimport {\n abortChatSessionBash,\n abortChatSessionCompaction,\n interruptChatSession,\n restoreQueuedMessagesToEditor,\n submitChatSession,\n} from \"./chat-session-host-actions.ts\";\nimport {\n createChatSessionEditor,\n handleChatSessionInput,\n} from \"./chat-session-host-editor.ts\";\nimport { applyChatSessionAgentEvent } from \"./chat-session-host-events.ts\";\nimport {\n renderChatSessionBody,\n renderChatSessionEditor,\n renderChatSessionEntry,\n renderChatSessionFooter,\n renderChatSessionPendingMessages,\n renderChatSessionUsage,\n renderChatSessionWorkingStatus,\n transcriptCacheKey,\n} from \"./chat-session-host-rendering.ts\";\nimport {\n disposeChatSession,\n isChatSessionBashRunning,\n isChatSessionStreaming,\n syncChatSessionAnimationTick,\n} from \"./chat-session-host-runtime.ts\";\nimport { ChatSessionHostState } from \"./chat-session-host-state.ts\";\nimport type {\n AgentSnapshotMessage,\n ChatSessionHostEntry,\n ChatSessionHostOpts,\n} from \"./chat-session-host-types.ts\";\n\nexport type {\n ChatSessionHostBashRequest,\n ChatSessionHostCommands,\n ChatSessionHostEntry,\n ChatSessionHostOpts,\n ChatSessionHostStyle,\n} from \"./chat-session-host-types.ts\";\n\nexport class ChatSessionHost<TExtraEntry extends ChatTranscriptEntryLike = never>\n implements Component, Focusable\n{\n focused = true;\n\n private readonly state: ChatSessionHostState<TExtraEntry>;\n\n constructor(opts: ChatSessionHostOpts<TExtraEntry>) {\n this.state = new ChatSessionHostState(opts, {\n renderEntry: (state, entry) => renderChatSessionEntry(state, entry),\n transcriptCacheKey: (state, entry, index) => transcriptCacheKey(state, entry, index),\n });\n this.state.editor = createChatSessionEditor(\n this.state,\n opts.tui,\n opts.keybindings,\n opts.editorTheme,\n opts.editorFactory,\n this.editorCallbacks(),\n );\n this.syncAnimationTick();\n }\n\n appendMessages(messages: readonly AgentSnapshotMessage[]): void {\n this.state.liveChat.appendMessages(messages);\n }\n\n loadSessionFile(sessionFile: string | undefined): void {\n if (this.state.transcript.length > 0 || sessionFile === undefined) return;\n let messages: readonly AgentSnapshotMessage[];\n try {\n messages = SessionManager.open(sessionFile).buildSessionContext()\n .messages as readonly AgentSnapshotMessage[];\n } catch {\n return;\n }\n this.state.liveChat.appendMessages(messages);\n }\n\n appendExtraEntry(entry: TExtraEntry): void {\n this.state.transcript.push(entry);\n }\n\n entries(): readonly ChatSessionHostEntry<TExtraEntry>[] {\n return this.state.transcript;\n }\n\n applyAgentEvent(event: AgentSessionEvent): boolean {\n return applyChatSessionAgentEvent(this.state, event);\n }\n\n render(width: number): string[] {\n return this.renderBody(width, 1);\n }\n\n invalidate(): void {\n this.state.transcriptComponent.invalidate();\n this.state.bodyViewport.invalidate();\n this.state.editor?.invalidate();\n }\n\n renderBody(width: number, budget: number): string[] {\n return renderChatSessionBody(this.state, width, budget);\n }\n\n renderPendingMessages(width: number): string[] {\n return renderChatSessionPendingMessages(this.state, width);\n }\n\n renderWorkingStatus(width: number): string[] {\n return renderChatSessionWorkingStatus(this.state, width);\n }\n\n renderUsage(width: number): string[] {\n return renderChatSessionUsage(this.state, width);\n }\n\n renderEditor(width: number): string[] {\n return renderChatSessionEditor(this.state, width, this.focused);\n }\n\n renderFooter(width: number): string[] {\n return renderChatSessionFooter(this.state, width);\n }\n\n handleScrollInput(data: string): boolean {\n return this.state.bodyViewport.handleInput(data);\n }\n\n handleInput(data: string): boolean {\n return handleChatSessionInput(this.state, data, this.editorCallbacks());\n }\n\n async interrupt(): Promise<void> {\n await interruptChatSession(this.state);\n }\n\n async submit(mode: \"auto\" | \"followUp\" = \"auto\", submittedText?: string): Promise<void> {\n await submitChatSession(this.state, mode, submittedText);\n }\n\n isStreaming(): boolean {\n return isChatSessionStreaming(this.state);\n }\n\n isBashRunning(): boolean {\n return isChatSessionBashRunning(this.state);\n }\n\n isEditingBashCommand(): boolean {\n return this.state.isBashMode;\n }\n\n hasInputText(): boolean {\n return this.state.inputBuffer.length > 0;\n }\n\n hasAnimationTick(): boolean {\n return this.state.animationTimer !== undefined;\n }\n\n bodyScrollFromBottom(): number {\n return this.state.bodyViewport.getScrollFromBottom();\n }\n\n bodyMaxScroll(): number {\n return this.state.bodyViewport.getMaxScroll();\n }\n\n inputText(): string {\n return this.state.inputBuffer;\n }\n\n statusText(): string {\n return this.state.statusMessage;\n }\n\n scrollToBottom(): void {\n this.state.bodyViewport.scrollToBottom();\n }\n\n syncAnimationTick(): void {\n syncChatSessionAnimationTick(this.state);\n }\n\n dispose(): void {\n disposeChatSession(this.state);\n }\n\n restoreQueuedMessagesToEditor(): boolean {\n return restoreQueuedMessagesToEditor(this.state);\n }\n\n private editorCallbacks(): {\n submit: (mode: \"auto\" | \"followUp\", submittedText?: string) => void | Promise<void>;\n restoreQueuedMessagesToEditor: () => boolean;\n abortCompaction: () => void | Promise<void>;\n interrupt: () => void | Promise<void>;\n abortBash: () => void | Promise<void>;\n } {\n return {\n submit: (mode, submittedText) => this.submit(mode, submittedText),\n restoreQueuedMessagesToEditor: () => this.restoreQueuedMessagesToEditor(),\n abortCompaction: () => abortChatSessionCompaction(this.state),\n interrupt: () => this.interrupt(),\n abortBash: () => abortChatSessionBash(this.state),\n };\n }\n}\n"]}
1
+ {"version":3,"file":"chat-session-host.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/chat-session-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AA+BpE,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,8BAA8B,CAAC;AAEtC,YAAY,EACV,0B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AAC,IAAI,CAAC,CAE/B;IAEK,MAAM,CAAC,IAAI,GAAE,MAAM,GAAG,UAAmB,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEtF;IAED,WAAW,IAAI,OAAO,CAErB;IAED,aAAa,IAAI,OAAO,CAEvB;IAED,oBAAoB,IAAI,OAAO,CAE9B;IAED,YAAY,IAAI,OAAO,CAEtB;IAED,YAAY,IAAI,OAAO,CAEtB;IAED,gBAAgB,IAAI,OAAO,CAE1B;IAED,oBAAoB,IAAI,MAAM,CAE7B;IAED,aAAa,IAAI,MAAM,CAEtB;IAED,SAAS,IAAI,MAAM,CAElB;IAED,UAAU,IAAI,MAAM,CAEnB;IAED,cAAc,IAAI,IAAI,CAErB;IAED,iBAAiB,IAAI,IAAI,CAExB;IAED,iCAAiC,IAAI,IAAI,CAExC;IAED,OAAO,IAAI,IAAI,CAEd;IAED,6BAA6B,IAAI,OAAO,CAEvC;IAED,OAAO,CAAC,eAAe;CAexB","sourcesContent":["import type { AgentSessionEvent } from \"../../../core/agent-session.ts\";\nimport { type Component, type Focusable } from \"@earendil-works/pi-tui\";\nimport { SessionManager } from \"../../../core/session-manager.ts\";\nimport type { ChatTranscriptEntryLike } from \"./chat-transcript.ts\";\nimport {\n abortChatSessionBash,\n abortChatSessionCompaction,\n interruptChatSession,\n restoreQueuedMessagesToEditor,\n submitChatSession,\n} from \"./chat-session-host-actions.ts\";\nimport {\n createChatSessionEditor,\n handleChatSessionInput,\n} from \"./chat-session-host-editor.ts\";\nimport { applyChatSessionAgentEvent } from \"./chat-session-host-events.ts\";\nimport {\n renderChatSessionBody,\n renderChatSessionEditor,\n renderChatSessionEntry,\n renderChatSessionFooter,\n renderChatSessionPendingMessages,\n renderChatSessionUsage,\n renderChatSessionWorkingStatus,\n transcriptCacheKey,\n} from \"./chat-session-host-rendering.ts\";\nimport {\n clearChatSessionBusyForTerminalWorkflowStage,\n disposeChatSession,\n isChatSessionBashRunning,\n isChatSessionStreaming,\n syncChatSessionAnimationTick,\n} from \"./chat-session-host-runtime.ts\";\nimport { ChatSessionHostState } from \"./chat-session-host-state.ts\";\nimport type {\n AgentSnapshotMessage,\n ChatSessionHostEntry,\n ChatSessionHostOpts,\n} from \"./chat-session-host-types.ts\";\n\nexport type {\n ChatSessionHostBashRequest,\n ChatSessionHostCommands,\n ChatSessionHostEntry,\n ChatSessionHostOpts,\n ChatSessionHostStyle,\n} from \"./chat-session-host-types.ts\";\n\nexport class ChatSessionHost<TExtraEntry extends ChatTranscriptEntryLike = never>\n implements Component, Focusable\n{\n focused = true;\n\n private readonly state: ChatSessionHostState<TExtraEntry>;\n\n constructor(opts: ChatSessionHostOpts<TExtraEntry>) {\n this.state = new ChatSessionHostState(opts, {\n renderEntry: (state, entry) => renderChatSessionEntry(state, entry),\n transcriptCacheKey: (state, entry, index) => transcriptCacheKey(state, entry, index),\n });\n this.state.editor = createChatSessionEditor(\n this.state,\n opts.tui,\n opts.keybindings,\n opts.editorTheme,\n opts.editorFactory,\n this.editorCallbacks(),\n );\n this.syncAnimationTick();\n }\n\n appendMessages(messages: readonly AgentSnapshotMessage[]): void {\n this.state.liveChat.appendMessages(messages);\n }\n\n loadSessionFile(sessionFile: string | undefined): void {\n if (this.state.transcript.length > 0 || sessionFile === undefined) return;\n let messages: readonly AgentSnapshotMessage[];\n try {\n messages = SessionManager.open(sessionFile).buildSessionContext()\n .messages as readonly AgentSnapshotMessage[];\n } catch {\n return;\n }\n this.state.liveChat.appendMessages(messages);\n }\n\n appendExtraEntry(entry: TExtraEntry): void {\n this.state.transcript.push(entry);\n }\n\n entries(): readonly ChatSessionHostEntry<TExtraEntry>[] {\n return this.state.transcript;\n }\n\n applyAgentEvent(event: AgentSessionEvent): boolean {\n return applyChatSessionAgentEvent(this.state, event);\n }\n\n render(width: number): string[] {\n return this.renderBody(width, 1);\n }\n\n invalidate(): void {\n this.state.transcriptComponent.invalidate();\n this.state.bodyViewport.invalidate();\n this.state.editor?.invalidate();\n }\n\n renderBody(width: number, budget: number): string[] {\n return renderChatSessionBody(this.state, width, budget);\n }\n\n renderPendingMessages(width: number): string[] {\n return renderChatSessionPendingMessages(this.state, width);\n }\n\n renderWorkingStatus(width: number): string[] {\n return renderChatSessionWorkingStatus(this.state, width);\n }\n\n renderUsage(width: number): string[] {\n return renderChatSessionUsage(this.state, width);\n }\n\n renderEditor(width: number): string[] {\n return renderChatSessionEditor(this.state, width, this.focused);\n }\n\n renderFooter(width: number): string[] {\n return renderChatSessionFooter(this.state, width);\n }\n\n handleScrollInput(data: string): boolean {\n return this.state.bodyViewport.handleInput(data);\n }\n\n handleInput(data: string): boolean {\n return handleChatSessionInput(this.state, data, this.editorCallbacks());\n }\n\n async interrupt(): Promise<void> {\n await interruptChatSession(this.state);\n }\n\n async submit(mode: \"auto\" | \"followUp\" = \"auto\", submittedText?: string): Promise<void> {\n await submitChatSession(this.state, mode, submittedText);\n }\n\n isStreaming(): boolean {\n return isChatSessionStreaming(this.state);\n }\n\n isBashRunning(): boolean {\n return isChatSessionBashRunning(this.state);\n }\n\n isEditingBashCommand(): boolean {\n return this.state.isBashMode;\n }\n\n isCompacting(): boolean {\n return this.state.compacting;\n }\n\n hasInputText(): boolean {\n return this.state.inputBuffer.length > 0;\n }\n\n hasAnimationTick(): boolean {\n return this.state.animationTimer !== undefined;\n }\n\n bodyScrollFromBottom(): number {\n return this.state.bodyViewport.getScrollFromBottom();\n }\n\n bodyMaxScroll(): number {\n return this.state.bodyViewport.getMaxScroll();\n }\n\n inputText(): string {\n return this.state.inputBuffer;\n }\n\n statusText(): string {\n return this.state.statusMessage;\n }\n\n scrollToBottom(): void {\n this.state.bodyViewport.scrollToBottom();\n }\n\n syncAnimationTick(): void {\n syncChatSessionAnimationTick(this.state);\n }\n\n clearBusyForTerminalWorkflowStage(): void {\n clearChatSessionBusyForTerminalWorkflowStage(this.state);\n }\n\n dispose(): void {\n disposeChatSession(this.state);\n }\n\n restoreQueuedMessagesToEditor(): boolean {\n return restoreQueuedMessagesToEditor(this.state);\n }\n\n private editorCallbacks(): {\n submit: (mode: \"auto\" | \"followUp\", submittedText?: string) => void | Promise<void>;\n restoreQueuedMessagesToEditor: () => boolean;\n abortCompaction: () => void | Promise<void>;\n interrupt: () => void | Promise<void>;\n abortBash: () => void | Promise<void>;\n } {\n return {\n submit: (mode, submittedText) => this.submit(mode, submittedText),\n restoreQueuedMessagesToEditor: () => this.restoreQueuedMessagesToEditor(),\n abortCompaction: () => abortChatSessionCompaction(this.state),\n interrupt: () => this.interrupt(),\n abortBash: () => abortChatSessionBash(this.state),\n };\n }\n}\n"]}
@@ -3,7 +3,7 @@ import { abortChatSessionBash, abortChatSessionCompaction, interruptChatSession,
3
3
  import { createChatSessionEditor, handleChatSessionInput, } from "./chat-session-host-editor.js";
4
4
  import { applyChatSessionAgentEvent } from "./chat-session-host-events.js";
5
5
  import { renderChatSessionBody, renderChatSessionEditor, renderChatSessionEntry, renderChatSessionFooter, renderChatSessionPendingMessages, renderChatSessionUsage, renderChatSessionWorkingStatus, transcriptCacheKey, } from "./chat-session-host-rendering.js";
6
- import { disposeChatSession, isChatSessionBashRunning, isChatSessionStreaming, syncChatSessionAnimationTick, } from "./chat-session-host-runtime.js";
6
+ import { clearChatSessionBusyForTerminalWorkflowStage, disposeChatSession, isChatSessionBashRunning, isChatSessionStreaming, syncChatSessionAnimationTick, } from "./chat-session-host-runtime.js";
7
7
  import { ChatSessionHostState } from "./chat-session-host-state.js";
8
8
  export class ChatSessionHost {
9
9
  constructor(opts) {
@@ -87,6 +87,9 @@ export class ChatSessionHost {
87
87
  isEditingBashCommand() {
88
88
  return this.state.isBashMode;
89
89
  }
90
+ isCompacting() {
91
+ return this.state.compacting;
92
+ }
90
93
  hasInputText() {
91
94
  return this.state.inputBuffer.length > 0;
92
95
  }
@@ -111,6 +114,9 @@ export class ChatSessionHost {
111
114
  syncAnimationTick() {
112
115
  syncChatSessionAnimationTick(this.state);
113
116
  }
117
+ clearBusyForTerminalWorkflowStage() {
118
+ clearChatSessionBusyForTerminalWorkflowStage(this.state);
119
+ }
114
120
  dispose() {
115
121
  disposeChatSession(this.state);
116
122
  }
@@ -1 +1 @@
1
- {"version":3,"file":"chat-session-host.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/chat-session-host.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAElE,OAAO,EACL,oBAAoB,EACpB,0BAA0B,EAC1B,oBAAoB,EACpB,6BAA6B,EAC7B,iBAAiB,GAClB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,gCAAgC,EAChC,sBAAsB,EACtB,8BAA8B,EAC9B,kBAAkB,GACnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAepE,MAAM,OAAO,eAAe;IAO1B,YAAY,IAAsC;QAJlD,YAAO,GAAG,IAAI,CAAC;QAKb,IAAI,CAAC,KAAK,GAAG,IAAI,oBAAoB,CAAC,IAAI,EAAE;YAC1C,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,sBAAsB,CAAC,KAAK,EAAE,KAAK,CAAC;YACnE,kBAAkB,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC;SACrF,CAAC,CAAC;QACH,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,uBAAuB,CACzC,IAAI,CAAC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CAAC,IAAI,CAAC,6BAA6B,EAAE;YACzE,eAAe,EAAE,GAAG,EAAE,CAAC,0BAA0B,CAAC,IAAI,CAAC,KAAK,CAAC;YAC7D,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE;YACjC,SAAS,EAAE,GAAG,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC;SAClD,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { AgentSessionEvent } from \"../../../core/agent-session.ts\";\nimport { type Component, type Focusable } from \"@earendil-works/pi-tui\";\nimport { SessionManager } from \"../../../core/session-manager.ts\";\nimport type { ChatTranscriptEntryLike } from \"./chat-transcript.ts\";\nimport {\n abortChatSessionBash,\n abortChatSessionCompaction,\n interruptChatSession,\n restoreQueuedMessagesToEditor,\n submitChatSession,\n} from \"./chat-session-host-actions.ts\";\nimport {\n createChatSessionEditor,\n handleChatSessionInput,\n} from \"./chat-session-host-editor.ts\";\nimport { applyChatSessionAgentEvent } from \"./chat-session-host-events.ts\";\nimport {\n renderChatSessionBody,\n renderChatSessionEditor,\n renderChatSessionEntry,\n renderChatSessionFooter,\n renderChatSessionPendingMessages,\n renderChatSessionUsage,\n renderChatSessionWorkingStatus,\n transcriptCacheKey,\n} from \"./chat-session-host-rendering.ts\";\nimport {\n disposeChatSession,\n isChatSessionBashRunning,\n isChatSessionStreaming,\n syncChatSessionAnimationTick,\n} from \"./chat-session-host-runtime.ts\";\nimport { ChatSessionHostState } from \"./chat-session-host-state.ts\";\nimport type {\n AgentSnapshotMessage,\n ChatSessionHostEntry,\n ChatSessionHostOpts,\n} from \"./chat-session-host-types.ts\";\n\nexport type {\n ChatSessionHostBashRequest,\n ChatSessionHostCommands,\n ChatSessionHostEntry,\n ChatSessionHostOpts,\n ChatSessionHostStyle,\n} from \"./chat-session-host-types.ts\";\n\nexport class ChatSessionHost<TExtraEntry extends ChatTranscriptEntryLike = never>\n implements Component, Focusable\n{\n focused = true;\n\n private readonly state: ChatSessionHostState<TExtraEntry>;\n\n constructor(opts: ChatSessionHostOpts<TExtraEntry>) {\n this.state = new ChatSessionHostState(opts, {\n renderEntry: (state, entry) => renderChatSessionEntry(state, entry),\n transcriptCacheKey: (state, entry, index) => transcriptCacheKey(state, entry, index),\n });\n this.state.editor = createChatSessionEditor(\n this.state,\n opts.tui,\n opts.keybindings,\n opts.editorTheme,\n opts.editorFactory,\n this.editorCallbacks(),\n );\n this.syncAnimationTick();\n }\n\n appendMessages(messages: readonly AgentSnapshotMessage[]): void {\n this.state.liveChat.appendMessages(messages);\n }\n\n loadSessionFile(sessionFile: string | undefined): void {\n if (this.state.transcript.length > 0 || sessionFile === undefined) return;\n let messages: readonly AgentSnapshotMessage[];\n try {\n messages = SessionManager.open(sessionFile).buildSessionContext()\n .messages as readonly AgentSnapshotMessage[];\n } catch {\n return;\n }\n this.state.liveChat.appendMessages(messages);\n }\n\n appendExtraEntry(entry: TExtraEntry): void {\n this.state.transcript.push(entry);\n }\n\n entries(): readonly ChatSessionHostEntry<TExtraEntry>[] {\n return this.state.transcript;\n }\n\n applyAgentEvent(event: AgentSessionEvent): boolean {\n return applyChatSessionAgentEvent(this.state, event);\n }\n\n render(width: number): string[] {\n return this.renderBody(width, 1);\n }\n\n invalidate(): void {\n this.state.transcriptComponent.invalidate();\n this.state.bodyViewport.invalidate();\n this.state.editor?.invalidate();\n }\n\n renderBody(width: number, budget: number): string[] {\n return renderChatSessionBody(this.state, width, budget);\n }\n\n renderPendingMessages(width: number): string[] {\n return renderChatSessionPendingMessages(this.state, width);\n }\n\n renderWorkingStatus(width: number): string[] {\n return renderChatSessionWorkingStatus(this.state, width);\n }\n\n renderUsage(width: number): string[] {\n return renderChatSessionUsage(this.state, width);\n }\n\n renderEditor(width: number): string[] {\n return renderChatSessionEditor(this.state, width, this.focused);\n }\n\n renderFooter(width: number): string[] {\n return renderChatSessionFooter(this.state, width);\n }\n\n handleScrollInput(data: string): boolean {\n return this.state.bodyViewport.handleInput(data);\n }\n\n handleInput(data: string): boolean {\n return handleChatSessionInput(this.state, data, this.editorCallbacks());\n }\n\n async interrupt(): Promise<void> {\n await interruptChatSession(this.state);\n }\n\n async submit(mode: \"auto\" | \"followUp\" = \"auto\", submittedText?: string): Promise<void> {\n await submitChatSession(this.state, mode, submittedText);\n }\n\n isStreaming(): boolean {\n return isChatSessionStreaming(this.state);\n }\n\n isBashRunning(): boolean {\n return isChatSessionBashRunning(this.state);\n }\n\n isEditingBashCommand(): boolean {\n return this.state.isBashMode;\n }\n\n hasInputText(): boolean {\n return this.state.inputBuffer.length > 0;\n }\n\n hasAnimationTick(): boolean {\n return this.state.animationTimer !== undefined;\n }\n\n bodyScrollFromBottom(): number {\n return this.state.bodyViewport.getScrollFromBottom();\n }\n\n bodyMaxScroll(): number {\n return this.state.bodyViewport.getMaxScroll();\n }\n\n inputText(): string {\n return this.state.inputBuffer;\n }\n\n statusText(): string {\n return this.state.statusMessage;\n }\n\n scrollToBottom(): void {\n this.state.bodyViewport.scrollToBottom();\n }\n\n syncAnimationTick(): void {\n syncChatSessionAnimationTick(this.state);\n }\n\n dispose(): void {\n disposeChatSession(this.state);\n }\n\n restoreQueuedMessagesToEditor(): boolean {\n return restoreQueuedMessagesToEditor(this.state);\n }\n\n private editorCallbacks(): {\n submit: (mode: \"auto\" | \"followUp\", submittedText?: string) => void | Promise<void>;\n restoreQueuedMessagesToEditor: () => boolean;\n abortCompaction: () => void | Promise<void>;\n interrupt: () => void | Promise<void>;\n abortBash: () => void | Promise<void>;\n } {\n return {\n submit: (mode, submittedText) => this.submit(mode, submittedText),\n restoreQueuedMessagesToEditor: () => this.restoreQueuedMessagesToEditor(),\n abortCompaction: () => abortChatSessionCompaction(this.state),\n interrupt: () => this.interrupt(),\n abortBash: () => abortChatSessionBash(this.state),\n };\n }\n}\n"]}
1
+ {"version":3,"file":"chat-session-host.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/chat-session-host.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cA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AG,EAAE,CAAC,0BAA0B,CAAC,IAAI,CAAC,KAAK,CAAC;YAC7D,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE;YACjC,SAAS,EAAE,GAAG,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC;SAClD,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { AgentSessionEvent } from \"../../../core/agent-session.ts\";\nimport { type Component, type Focusable } from \"@earendil-works/pi-tui\";\nimport { SessionManager } from \"../../../core/session-manager.ts\";\nimport type { ChatTranscriptEntryLike } from \"./chat-transcript.ts\";\nimport {\n abortChatSessionBash,\n abortChatSessionCompaction,\n interruptChatSession,\n restoreQueuedMessagesToEditor,\n submitChatSession,\n} from \"./chat-session-host-actions.ts\";\nimport {\n createChatSessionEditor,\n handleChatSessionInput,\n} from \"./chat-session-host-editor.ts\";\nimport { applyChatSessionAgentEvent } from \"./chat-session-host-events.ts\";\nimport {\n renderChatSessionBody,\n renderChatSessionEditor,\n renderChatSessionEntry,\n renderChatSessionFooter,\n renderChatSessionPendingMessages,\n renderChatSessionUsage,\n renderChatSessionWorkingStatus,\n transcriptCacheKey,\n} from \"./chat-session-host-rendering.ts\";\nimport {\n clearChatSessionBusyForTerminalWorkflowStage,\n disposeChatSession,\n isChatSessionBashRunning,\n isChatSessionStreaming,\n syncChatSessionAnimationTick,\n} from \"./chat-session-host-runtime.ts\";\nimport { ChatSessionHostState } from \"./chat-session-host-state.ts\";\nimport type {\n AgentSnapshotMessage,\n ChatSessionHostEntry,\n ChatSessionHostOpts,\n} from \"./chat-session-host-types.ts\";\n\nexport type {\n ChatSessionHostBashRequest,\n ChatSessionHostCommands,\n ChatSessionHostEntry,\n ChatSessionHostOpts,\n ChatSessionHostStyle,\n} from \"./chat-session-host-types.ts\";\n\nexport class ChatSessionHost<TExtraEntry extends ChatTranscriptEntryLike = never>\n implements Component, Focusable\n{\n focused = true;\n\n private readonly state: ChatSessionHostState<TExtraEntry>;\n\n constructor(opts: ChatSessionHostOpts<TExtraEntry>) {\n this.state = new ChatSessionHostState(opts, {\n renderEntry: (state, entry) => renderChatSessionEntry(state, entry),\n transcriptCacheKey: (state, entry, index) => transcriptCacheKey(state, entry, index),\n });\n this.state.editor = createChatSessionEditor(\n this.state,\n opts.tui,\n opts.keybindings,\n opts.editorTheme,\n opts.editorFactory,\n this.editorCallbacks(),\n );\n this.syncAnimationTick();\n }\n\n appendMessages(messages: readonly AgentSnapshotMessage[]): void {\n this.state.liveChat.appendMessages(messages);\n }\n\n loadSessionFile(sessionFile: string | undefined): void {\n if (this.state.transcript.length > 0 || sessionFile === undefined) return;\n let messages: readonly AgentSnapshotMessage[];\n try {\n messages = SessionManager.open(sessionFile).buildSessionContext()\n .messages as readonly AgentSnapshotMessage[];\n } catch {\n return;\n }\n this.state.liveChat.appendMessages(messages);\n }\n\n appendExtraEntry(entry: TExtraEntry): void {\n this.state.transcript.push(entry);\n }\n\n entries(): readonly ChatSessionHostEntry<TExtraEntry>[] {\n return this.state.transcript;\n }\n\n applyAgentEvent(event: AgentSessionEvent): boolean {\n return applyChatSessionAgentEvent(this.state, event);\n }\n\n render(width: number): string[] {\n return this.renderBody(width, 1);\n }\n\n invalidate(): void {\n this.state.transcriptComponent.invalidate();\n this.state.bodyViewport.invalidate();\n this.state.editor?.invalidate();\n }\n\n renderBody(width: number, budget: number): string[] {\n return renderChatSessionBody(this.state, width, budget);\n }\n\n renderPendingMessages(width: number): string[] {\n return renderChatSessionPendingMessages(this.state, width);\n }\n\n renderWorkingStatus(width: number): string[] {\n return renderChatSessionWorkingStatus(this.state, width);\n }\n\n renderUsage(width: number): string[] {\n return renderChatSessionUsage(this.state, width);\n }\n\n renderEditor(width: number): string[] {\n return renderChatSessionEditor(this.state, width, this.focused);\n }\n\n renderFooter(width: number): string[] {\n return renderChatSessionFooter(this.state, width);\n }\n\n handleScrollInput(data: string): boolean {\n return this.state.bodyViewport.handleInput(data);\n }\n\n handleInput(data: string): boolean {\n return handleChatSessionInput(this.state, data, this.editorCallbacks());\n }\n\n async interrupt(): Promise<void> {\n await interruptChatSession(this.state);\n }\n\n async submit(mode: \"auto\" | \"followUp\" = \"auto\", submittedText?: string): Promise<void> {\n await submitChatSession(this.state, mode, submittedText);\n }\n\n isStreaming(): boolean {\n return isChatSessionStreaming(this.state);\n }\n\n isBashRunning(): boolean {\n return isChatSessionBashRunning(this.state);\n }\n\n isEditingBashCommand(): boolean {\n return this.state.isBashMode;\n }\n\n isCompacting(): boolean {\n return this.state.compacting;\n }\n\n hasInputText(): boolean {\n return this.state.inputBuffer.length > 0;\n }\n\n hasAnimationTick(): boolean {\n return this.state.animationTimer !== undefined;\n }\n\n bodyScrollFromBottom(): number {\n return this.state.bodyViewport.getScrollFromBottom();\n }\n\n bodyMaxScroll(): number {\n return this.state.bodyViewport.getMaxScroll();\n }\n\n inputText(): string {\n return this.state.inputBuffer;\n }\n\n statusText(): string {\n return this.state.statusMessage;\n }\n\n scrollToBottom(): void {\n this.state.bodyViewport.scrollToBottom();\n }\n\n syncAnimationTick(): void {\n syncChatSessionAnimationTick(this.state);\n }\n\n clearBusyForTerminalWorkflowStage(): void {\n clearChatSessionBusyForTerminalWorkflowStage(this.state);\n }\n\n dispose(): void {\n disposeChatSession(this.state);\n }\n\n restoreQueuedMessagesToEditor(): boolean {\n return restoreQueuedMessagesToEditor(this.state);\n }\n\n private editorCallbacks(): {\n submit: (mode: \"auto\" | \"followUp\", submittedText?: string) => void | Promise<void>;\n restoreQueuedMessagesToEditor: () => boolean;\n abortCompaction: () => void | Promise<void>;\n interrupt: () => void | Promise<void>;\n abortBash: () => void | Promise<void>;\n } {\n return {\n submit: (mode, submittedText) => this.submit(mode, submittedText),\n restoreQueuedMessagesToEditor: () => this.restoreQueuedMessagesToEditor(),\n abortCompaction: () => abortChatSessionCompaction(this.state),\n interrupt: () => this.interrupt(),\n abortBash: () => abortChatSessionBash(this.state),\n };\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file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,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,WAAW,EAAE,sBAAsB,CAAC,MAAM,CAAC,EAI5C;IAED,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEjC;IAED,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjC;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAE9B;IAED,UAAU,IAAI,IAAI,CAEjB;IAED,mBAAmB,IAAI,MAAM,CAE5B;IAED,YAAY,IAAI,MAAM,CAErB;IAED,cAAc,IAAI,IAAI,CAErB;CACF","sourcesContent":["import {\n matchesKey,\n type Component,\n Container,\n Spacer,\n} from \"@earendil-works/pi-tui\";\n\n/**\n * Roles that participate in pi's chat spacing contract.\n *\n * Assistant turns own their leading whitespace internally, and tool rows attach\n * directly under the assistant/tool-call row they belong to. User-like rows get\n * one blank line when they are not the first row in the transcript.\n */\nexport type ChatTranscriptRole =\n | \"assistant\"\n | \"thinking\"\n | \"tool\"\n | \"user\"\n | \"custom\"\n | \"notice\"\n | \"system\"\n | \"summary\";\n\nexport interface ChatTranscriptEntryLike {\n readonly role: ChatTranscriptRole;\n}\n\nexport type ChatTranscriptRenderer<TEntry extends ChatTranscriptEntryLike> = (\n entry: TEntry,\n) => Component;\n\nexport type ChatTranscriptCacheKey<TEntry extends ChatTranscriptEntryLike> = (\n entry: TEntry,\n index: number,\n) => string;\n\ninterface CachedChatTranscriptBlock<TEntry extends ChatTranscriptEntryLike> {\n readonly entry: TEntry;\n readonly key: string;\n readonly width: number;\n readonly lines: readonly string[];\n}\n\ninterface RowWindowComponent extends Component {\n readonly supportsRowWindow: true;\n rowCount(width: number): number;\n renderRows(width: number, startRow: number, endRow: number): string[];\n}\n\ninterface WindowedComponentRows {\n readonly kind: \"windowed\";\n readonly component: RowWindowComponent;\n readonly rowCount: number;\n}\n\ninterface StaticComponentRows {\n readonly kind: \"static\";\n readonly lines: readonly string[];\n readonly rowCount: number;\n}\n\ntype ComponentRows = WindowedComponentRows | StaticComponentRows;\n\nexport function addChatTranscriptEntry(\n container: Container,\n component: Component,\n role: ChatTranscriptRole,\n): void {\n if (needsLeadingSpacer(role) && container.children.length > 0) {\n container.addChild(new Spacer(1));\n }\n container.addChild(component);\n}\n\nfunction needsLeadingSpacer(role: ChatTranscriptRole): boolean {\n return (\n role === \"user\" ||\n role === \"custom\" ||\n role === \"notice\" ||\n role === \"system\" ||\n role === \"summary\"\n );\n}\n\n/**\n * Reusable pi chat transcript scaffold for extension surfaces.\n *\n * This intentionally mirrors InteractiveMode.addMessageToChat spacing without\n * coupling consumers to a full AgentSession. Extension UIs can bring their own\n * message model while still rendering inside the same Container/Spacer rhythm\n * as the main chat.\n */\nexport class ChatTranscriptComponent<TEntry extends ChatTranscriptEntryLike>\n implements Component\n{\n private readonly entries: readonly TEntry[];\n private readonly renderEntry: ChatTranscriptRenderer<TEntry>;\n readonly supportsRowWindow: boolean;\n\n private readonly cacheKey: ChatTranscriptCacheKey<TEntry> | undefined;\n private blockCache: Array<CachedChatTranscriptBlock<TEntry> | undefined> = [];\n\n constructor(\n entries: readonly TEntry[],\n renderEntry: ChatTranscriptRenderer<TEntry>,\n cacheKey?: ChatTranscriptCacheKey<TEntry>,\n ) {\n this.entries = entries;\n this.renderEntry = renderEntry;\n this.cacheKey = cacheKey;\n this.supportsRowWindow = cacheKey !== undefined;\n }\n\n render(width: number): string[] {\n if (!this.supportsRowWindow) return this.renderAllRows(width);\n return this.renderRows(width, 0, this.rowCount(width));\n }\n\n rowCount(width: number): number {\n if (!this.supportsRowWindow) return this.renderAllRows(width).length;\n this.ensureBlockCache(width);\n let count = 0;\n for (const block of this.blockCache) {\n if (block !== undefined) count += block.lines.length;\n }\n return count;\n }\n\n renderRows(width: number, startRow: number, endRow: number): string[] {\n const start = Math.max(0, Math.floor(startRow));\n const end = Math.max(start, Math.floor(endRow));\n if (end <= start) return [];\n if (!this.supportsRowWindow) return this.renderAllRows(width).slice(start, end);\n\n this.ensureBlockCache(width);\n const lines: string[] = [];\n let cursor = 0;\n for (let index = 0; index < this.entries.length; index += 1) {\n const block = this.blockCache[index];\n if (block === undefined) continue;\n const blockStart = cursor;\n const blockEnd = blockStart + block.lines.length;\n if (blockEnd > start && blockStart < end) {\n const localStart = Math.max(0, start - blockStart);\n const localEnd = Math.min(block.lines.length, end - blockStart);\n lines.push(...block.lines.slice(localStart, localEnd));\n }\n cursor = blockEnd;\n if (cursor >= end) break;\n }\n return lines;\n }\n\n invalidate(): void {\n this.blockCache = [];\n }\n\n private ensureBlockCache(width: number): void {\n if (this.blockCache.length > this.entries.length) {\n this.blockCache.length = this.entries.length;\n }\n for (let index = 0; index < this.entries.length; index += 1) {\n const entry = this.entries[index];\n if (entry === undefined) continue;\n const key = this.cacheKey?.(entry, index) ?? `${index}:${entry.role}`;\n const cached = this.blockCache[index];\n if (\n cached !== undefined &&\n cached.entry === entry &&\n cached.key === key &&\n cached.width === width\n ) {\n continue;\n }\n this.blockCache[index] = {\n entry,\n key,\n width,\n lines: this.renderEntryBlock(entry, index, width),\n };\n }\n }\n\n private renderAllRows(width: number): string[] {\n const lines: string[] = [];\n for (let index = 0; index < this.entries.length; index += 1) {\n const entry = this.entries[index];\n if (entry !== undefined) lines.push(...this.renderEntryBlock(entry, index, width));\n }\n return lines;\n }\n\n private renderEntryBlock(entry: TEntry, index: number, width: number): string[] {\n const lines: string[] = [];\n if (index > 0 && needsLeadingSpacer(entry.role)) lines.push(\"\");\n lines.push(...this.renderEntry(entry).render(width));\n return lines;\n }\n}\n\nconst DEFAULT_SCROLL_STEP_ROWS = 4;\n\n/**\n * Sticky-bottom, scrollable viewport for chat-like component stacks.\n *\n * Pi's main interactive chat gets terminal scrollback for free. Extension\n * overlays render into a fixed rectangle, so they need an explicit viewport\n * with the same sticky-bottom default plus keyboard and mouse history controls.\n */\nexport class ScrollableComponentViewport implements Component {\n private components: readonly Component[] = [];\n private visibleRows = 1;\n private scrollFromBottom = 0;\n private lastLineCount = 0;\n private lastWidth = 0;\n private maxScroll = 0;\n\n setComponents(components: readonly Component[]): void {\n this.components = components;\n }\n\n setVisibleRows(rows: number): void {\n this.visibleRows = Math.max(1, Math.floor(rows));\n this.clampScroll();\n }\n\n getScrollFromBottom(): number {\n return this.scrollFromBottom;\n }\n\n getMaxScroll(): number {\n return this.maxScroll;\n }\n\n scrollToBottom(): void {\n this.scrollFromBottom = 0;\n }\n\n scrollToTop(): void {\n this.scrollFromBottom = this.maxScroll;\n }\n\n scrollBy(deltaRows: number): void {\n // Positive deltas move toward newer content; negative deltas move up\n // into older history. Store the offset from the sticky bottom so new\n // streaming output can keep following when the offset is zero.\n this.scrollFromBottom -= deltaRows;\n this.clampScroll();\n }\n\n handleInput(data: string): boolean {\n const wheelDeltaRows = mouseWheelDeltaRows(data);\n if (wheelDeltaRows !== 0) {\n this.scrollBy(wheelDeltaRows);\n return true;\n }\n if (isMouseSequence(data)) return true;\n if (matchesKey(data, \"pageUp\")) {\n this.scrollBy(-this.pageSize());\n return true;\n }\n if (matchesKey(data, \"pageDown\")) {\n this.scrollBy(this.pageSize());\n return true;\n }\n if (matchesKey(data, \"home\")) {\n this.scrollToTop();\n return true;\n }\n if (matchesKey(data, \"end\")) {\n this.scrollToBottom();\n return true;\n }\n return false;\n }\n\n render(width: number): string[] {\n const componentRows = this.measureComponentRows(width);\n const lineCount = componentRows.reduce((sum, rows) => sum + rows.rowCount, 0);\n const maxScroll = Math.max(0, lineCount - this.visibleRows);\n if (this.scrollFromBottom > 0 && this.lastWidth === width && lineCount > this.lastLineCount) {\n this.scrollFromBottom += lineCount - this.lastLineCount;\n }\n this.lastLineCount = lineCount;\n this.lastWidth = width;\n this.maxScroll = maxScroll;\n this.clampScroll();\n\n const start = Math.max(0, maxScroll - this.scrollFromBottom);\n const visible = this.renderVisibleRows(\n componentRows,\n width,\n start,\n start + this.visibleRows,\n );\n while (visible.length < this.visibleRows) visible.push(\" \".repeat(width));\n return visible;\n }\n\n invalidate(): void {\n for (const component of this.components) component.invalidate();\n }\n\n private measureComponentRows(width: number): ComponentRows[] {\n return this.components.map((component) => {\n if (isRowWindowComponent(component)) {\n return {\n kind: \"windowed\",\n component,\n rowCount: component.rowCount(width),\n };\n }\n const lines = component.render(width);\n return {\n kind: \"static\",\n lines,\n rowCount: lines.length,\n };\n });\n }\n\n private renderVisibleRows(\n componentRows: readonly ComponentRows[],\n width: number,\n startRow: number,\n endRow: number,\n ): string[] {\n const lines: string[] = [];\n let cursor = 0;\n for (const rows of componentRows) {\n const componentStart = cursor;\n const componentEnd = componentStart + rows.rowCount;\n if (componentEnd > startRow && componentStart < endRow) {\n const localStart = Math.max(0, startRow - componentStart);\n const localEnd = Math.min(rows.rowCount, endRow - componentStart);\n if (rows.kind === \"windowed\") {\n lines.push(...rows.component.renderRows(width, localStart, localEnd));\n } else {\n lines.push(...rows.lines.slice(localStart, localEnd));\n }\n }\n cursor = componentEnd;\n if (cursor >= endRow) break;\n }\n return lines;\n }\n\n private pageSize(): number {\n return Math.max(4, this.visibleRows - 2);\n }\n\n private clampScroll(): void {\n this.scrollFromBottom = Math.max(0, Math.min(this.maxScroll, this.scrollFromBottom));\n }\n}\n\nfunction isRowWindowComponent(component: Component): component is RowWindowComponent {\n const candidate = component as Partial<RowWindowComponent>;\n return candidate.supportsRowWindow === true &&\n typeof candidate.rowCount === \"function\" &&\n typeof candidate.renderRows === \"function\";\n}\n\nexport class ScrollableChatTranscriptComponent<TEntry extends ChatTranscriptEntryLike>\n implements Component\n{\n private readonly viewport = new ScrollableComponentViewport();\n private readonly transcript: ChatTranscriptComponent<TEntry>;\n\n constructor(\n entries: readonly TEntry[],\n renderEntry: ChatTranscriptRenderer<TEntry>,\n ) {\n this.transcript = new ChatTranscriptComponent(entries, renderEntry);\n this.viewport.setComponents([this.transcript]);\n }\n\n setVisibleRows(rows: number): void {\n this.viewport.setVisibleRows(rows);\n }\n\n handleInput(data: string): boolean {\n return this.viewport.handleInput(data);\n }\n\n render(width: number): string[] {\n return this.viewport.render(width);\n }\n\n invalidate(): void {\n this.viewport.invalidate();\n }\n\n getScrollFromBottom(): number {\n return this.viewport.getScrollFromBottom();\n }\n\n getMaxScroll(): number {\n return this.viewport.getMaxScroll();\n }\n\n scrollToBottom(): void {\n this.viewport.scrollToBottom();\n }\n}\n\nfunction mouseWheelDeltaRows(data: string): number {\n const sgr = data.match(/^\\x1b\\[<(\\d+);\\d+;\\d+M$/);\n if (sgr) return wheelDeltaForButtonCode(Number.parseInt(sgr[1]!, 10));\n if (data.startsWith(\"\\x1b[M\") && data.length >= 6) {\n return wheelDeltaForButtonCode(data.charCodeAt(3) - 32);\n }\n return 0;\n}\n\nfunction wheelDeltaForButtonCode(code: number): number {\n if ((code & 64) === 0) return 0;\n const direction = code & 3;\n if (direction === 0) return -DEFAULT_SCROLL_STEP_ROWS;\n if (direction === 1) return DEFAULT_SCROLL_STEP_ROWS;\n return 0;\n}\n\nfunction isMouseSequence(data: string): boolean {\n return /^\\x1b\\[<\\d+;\\d+;\\d+[mM]$/.test(data) || data.startsWith(\"\\x1b[M\");\n}\n"]}
1
+ {"version":3,"file":"chat-transcript.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/chat-transcript.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EACd,SAAS,EAEV,MAAM,wBAAwB,CAAC;AAEhC;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAC1B,WAAW,GACX,UAAU,GACV,MAAM,GACN,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,SAAS,CAAC;AAEd,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;CACnC;AAED,MAAM,MAAM,sBAAsB,CAAC,MAAM,SAAS,uBAAuB,IAAI,CAC3E,KAAK,EAAE,MAAM,KACV,SAAS,CAAC;AAEf,MAAM,MAAM,sBAAsB,CAAC,MAAM,SAAS,uBAAuB,IAAI,CAC3E,KAAK,EAAE,MAAM,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EAAE,GAAG,IAAI,CAEpD;IAED,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAGjC;IAED,mBAAmB,IAAI,MAAM,CAE5B;IAED,YAAY,IAAI,MAAM,CAErB;IAED,cAAc,IAAI,IAAI,CAErB;IAED,WAAW,IAAI,IAAI,CAElB;IAED,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAMhC;IAED,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAwBjC;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAqB9B;IAED,UAAU,IAAI,IAAI,CAEjB;IAED,OAAO,CAAC,oBAAoB;IAkB5B,OAAO,CAAC,iBAAiB;IA0BzB,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,WAAW;CAGpB;AASD,qBAAa,iCAAiC,CAAC,MAAM,SAAS,uBAAuB,CACnF,YAAW,SAAS;IAEpB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqC;IAC9D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkC;IAE7D,YACE,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,WAAW,EAAE,sBAAsB,CAAC,MAAM,CAAC,EAI5C;IAED,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEjC;IAED,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjC;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAE9B;IAED,UAAU,IAAI,IAAI,CAEjB;IAED,mBAAmB,IAAI,MAAM,CAE5B;IAED,YAAY,IAAI,MAAM,CAErB;IAED,cAAc,IAAI,IAAI,CAErB;CACF","sourcesContent":["import {\n matchesKey,\n type Component,\n Container,\n Spacer,\n} from \"@earendil-works/pi-tui\";\n\n/**\n * Roles that participate in pi's chat spacing contract.\n *\n * Assistant turns own their leading whitespace internally, and tool rows attach\n * directly under the assistant/tool-call row they belong to. User-like rows get\n * one blank line when they are not the first row in the transcript.\n */\nexport type ChatTranscriptRole =\n | \"assistant\"\n | \"thinking\"\n | \"tool\"\n | \"user\"\n | \"custom\"\n | \"notice\"\n | \"system\"\n | \"summary\";\n\nexport interface ChatTranscriptEntryLike {\n readonly role: ChatTranscriptRole;\n}\n\nexport type ChatTranscriptRenderer<TEntry extends ChatTranscriptEntryLike> = (\n entry: TEntry,\n) => Component;\n\nexport type ChatTranscriptCacheKey<TEntry extends ChatTranscriptEntryLike> = (\n entry: TEntry,\n index: number,\n) => string;\n\ninterface CachedChatTranscriptBlock<TEntry extends ChatTranscriptEntryLike> {\n readonly entry: TEntry;\n readonly key: string;\n readonly width: number;\n readonly component: Component;\n readonly lines: readonly string[];\n}\n\ntype DisposableComponent = Component & { dispose?: () => void };\n\ninterface RowWindowComponent extends Component {\n readonly supportsRowWindow: true;\n rowCount(width: number): number;\n renderRows(width: number, startRow: number, endRow: number): string[];\n}\n\ninterface WindowedComponentRows {\n readonly kind: \"windowed\";\n readonly component: RowWindowComponent;\n readonly rowCount: number;\n}\n\ninterface StaticComponentRows {\n readonly kind: \"static\";\n readonly lines: readonly string[];\n readonly rowCount: number;\n}\n\ntype ComponentRows = WindowedComponentRows | StaticComponentRows;\n\nexport function addChatTranscriptEntry(\n container: Container,\n component: Component,\n role: ChatTranscriptRole,\n): void {\n if (needsLeadingSpacer(role) && container.children.length > 0) {\n container.addChild(new Spacer(1));\n }\n container.addChild(component);\n}\n\nfunction needsLeadingSpacer(role: ChatTranscriptRole): boolean {\n return (\n role === \"user\" ||\n role === \"custom\" ||\n role === \"notice\" ||\n role === \"system\" ||\n role === \"summary\"\n );\n}\n\n/**\n * Reusable pi chat transcript scaffold for extension surfaces.\n *\n * This intentionally mirrors InteractiveMode.addMessageToChat spacing without\n * coupling consumers to a full AgentSession. Extension UIs can bring their own\n * message model while still rendering inside the same Container/Spacer rhythm\n * as the main chat.\n */\nexport class ChatTranscriptComponent<TEntry extends ChatTranscriptEntryLike>\n implements Component\n{\n private readonly entries: readonly TEntry[];\n private readonly renderEntry: ChatTranscriptRenderer<TEntry>;\n readonly supportsRowWindow: boolean;\n\n private readonly cacheKey: ChatTranscriptCacheKey<TEntry> | undefined;\n private blockCache: Array<CachedChatTranscriptBlock<TEntry> | undefined> = [];\n\n constructor(\n entries: readonly TEntry[],\n renderEntry: ChatTranscriptRenderer<TEntry>,\n cacheKey?: ChatTranscriptCacheKey<TEntry>,\n ) {\n this.entries = entries;\n this.renderEntry = renderEntry;\n this.cacheKey = cacheKey;\n this.supportsRowWindow = cacheKey !== undefined;\n }\n\n render(width: number): string[] {\n if (!this.supportsRowWindow) return this.renderAllRows(width);\n return this.renderRows(width, 0, this.rowCount(width));\n }\n\n rowCount(width: number): number {\n if (!this.supportsRowWindow) return this.renderAllRows(width).length;\n this.ensureBlockCache(width);\n let count = 0;\n for (const block of this.blockCache) {\n if (block !== undefined) count += block.lines.length;\n }\n return count;\n }\n\n renderRows(width: number, startRow: number, endRow: number): string[] {\n const start = Math.max(0, Math.floor(startRow));\n const end = Math.max(start, Math.floor(endRow));\n if (end <= start) return [];\n if (!this.supportsRowWindow) return this.renderAllRows(width).slice(start, end);\n\n this.ensureBlockCache(width);\n const lines: string[] = [];\n let cursor = 0;\n for (let index = 0; index < this.entries.length; index += 1) {\n const block = this.blockCache[index];\n if (block === undefined) continue;\n const blockStart = cursor;\n const blockEnd = blockStart + block.lines.length;\n if (blockEnd > start && blockStart < end) {\n const localStart = Math.max(0, start - blockStart);\n const localEnd = Math.min(block.lines.length, end - blockStart);\n lines.push(...block.lines.slice(localStart, localEnd));\n }\n cursor = blockEnd;\n if (cursor >= end) break;\n }\n return lines;\n }\n\n invalidate(): void {\n for (const block of this.blockCache) disposeComponent(block?.component);\n this.blockCache = [];\n }\n\n private ensureBlockCache(width: number): void {\n if (this.blockCache.length > this.entries.length) {\n for (let index = this.entries.length; index < this.blockCache.length; index += 1) {\n disposeComponent(this.blockCache[index]?.component);\n }\n this.blockCache.length = this.entries.length;\n }\n for (let index = 0; index < this.entries.length; index += 1) {\n const entry = this.entries[index];\n if (entry === undefined) continue;\n const key = this.cacheKey?.(entry, index) ?? `${index}:${entry.role}`;\n const cached = this.blockCache[index];\n if (\n cached !== undefined &&\n cached.entry === entry &&\n cached.key === key &&\n cached.width === width\n ) {\n continue;\n }\n disposeComponent(cached?.component);\n const component = this.renderEntry(entry);\n this.blockCache[index] = {\n entry,\n key,\n width,\n component,\n lines: this.renderEntryBlock(component, entry, index, width),\n };\n }\n }\n\n private renderAllRows(width: number): string[] {\n const lines: string[] = [];\n for (let index = 0; index < this.entries.length; index += 1) {\n const entry = this.entries[index];\n if (entry !== undefined) lines.push(...this.renderEntryBlock(this.renderEntry(entry), entry, index, width));\n }\n return lines;\n }\n\n private renderEntryBlock(\n component: Component,\n entry: TEntry,\n index: number,\n width: number,\n ): string[] {\n const lines: string[] = [];\n if (index > 0 && needsLeadingSpacer(entry.role)) lines.push(\"\");\n lines.push(...component.render(width));\n return lines;\n }\n}\n\nfunction disposeComponent(component: Component | undefined): void {\n (component as DisposableComponent | undefined)?.dispose?.();\n}\n\nconst DEFAULT_SCROLL_STEP_ROWS = 4;\n\n/**\n * Sticky-bottom, scrollable viewport for chat-like component stacks.\n *\n * Pi's main interactive chat gets terminal scrollback for free. Extension\n * overlays render into a fixed rectangle, so they need an explicit viewport\n * with the same sticky-bottom default plus keyboard and mouse history controls.\n */\nexport class ScrollableComponentViewport implements Component {\n private components: readonly Component[] = [];\n private visibleRows = 1;\n private scrollFromBottom = 0;\n private lastLineCount = 0;\n private lastWidth = 0;\n private maxScroll = 0;\n\n setComponents(components: readonly Component[]): void {\n this.components = components;\n }\n\n setVisibleRows(rows: number): void {\n this.visibleRows = Math.max(1, Math.floor(rows));\n this.clampScroll();\n }\n\n getScrollFromBottom(): number {\n return this.scrollFromBottom;\n }\n\n getMaxScroll(): number {\n return this.maxScroll;\n }\n\n scrollToBottom(): void {\n this.scrollFromBottom = 0;\n }\n\n scrollToTop(): void {\n this.scrollFromBottom = this.maxScroll;\n }\n\n scrollBy(deltaRows: number): void {\n // Positive deltas move toward newer content; negative deltas move up\n // into older history. Store the offset from the sticky bottom so new\n // streaming output can keep following when the offset is zero.\n this.scrollFromBottom -= deltaRows;\n this.clampScroll();\n }\n\n handleInput(data: string): boolean {\n const wheelDeltaRows = mouseWheelDeltaRows(data);\n if (wheelDeltaRows !== 0) {\n this.scrollBy(wheelDeltaRows);\n return true;\n }\n if (isMouseSequence(data)) return true;\n if (matchesKey(data, \"pageUp\")) {\n this.scrollBy(-this.pageSize());\n return true;\n }\n if (matchesKey(data, \"pageDown\")) {\n this.scrollBy(this.pageSize());\n return true;\n }\n if (matchesKey(data, \"home\")) {\n this.scrollToTop();\n return true;\n }\n if (matchesKey(data, \"end\")) {\n this.scrollToBottom();\n return true;\n }\n return false;\n }\n\n render(width: number): string[] {\n const componentRows = this.measureComponentRows(width);\n const lineCount = componentRows.reduce((sum, rows) => sum + rows.rowCount, 0);\n const maxScroll = Math.max(0, lineCount - this.visibleRows);\n if (this.scrollFromBottom > 0 && this.lastWidth === width && lineCount > this.lastLineCount) {\n this.scrollFromBottom += lineCount - this.lastLineCount;\n }\n this.lastLineCount = lineCount;\n this.lastWidth = width;\n this.maxScroll = maxScroll;\n this.clampScroll();\n\n const start = Math.max(0, maxScroll - this.scrollFromBottom);\n const visible = this.renderVisibleRows(\n componentRows,\n width,\n start,\n start + this.visibleRows,\n );\n while (visible.length < this.visibleRows) visible.push(\" \".repeat(width));\n return visible;\n }\n\n invalidate(): void {\n for (const component of this.components) component.invalidate();\n }\n\n private measureComponentRows(width: number): ComponentRows[] {\n return this.components.map((component) => {\n if (isRowWindowComponent(component)) {\n return {\n kind: \"windowed\",\n component,\n rowCount: component.rowCount(width),\n };\n }\n const lines = component.render(width);\n return {\n kind: \"static\",\n lines,\n rowCount: lines.length,\n };\n });\n }\n\n private renderVisibleRows(\n componentRows: readonly ComponentRows[],\n width: number,\n startRow: number,\n endRow: number,\n ): string[] {\n const lines: string[] = [];\n let cursor = 0;\n for (const rows of componentRows) {\n const componentStart = cursor;\n const componentEnd = componentStart + rows.rowCount;\n if (componentEnd > startRow && componentStart < endRow) {\n const localStart = Math.max(0, startRow - componentStart);\n const localEnd = Math.min(rows.rowCount, endRow - componentStart);\n if (rows.kind === \"windowed\") {\n lines.push(...rows.component.renderRows(width, localStart, localEnd));\n } else {\n lines.push(...rows.lines.slice(localStart, localEnd));\n }\n }\n cursor = componentEnd;\n if (cursor >= endRow) break;\n }\n return lines;\n }\n\n private pageSize(): number {\n return Math.max(4, this.visibleRows - 2);\n }\n\n private clampScroll(): void {\n this.scrollFromBottom = Math.max(0, Math.min(this.maxScroll, this.scrollFromBottom));\n }\n}\n\nfunction isRowWindowComponent(component: Component): component is RowWindowComponent {\n const candidate = component as Partial<RowWindowComponent>;\n return candidate.supportsRowWindow === true &&\n typeof candidate.rowCount === \"function\" &&\n typeof candidate.renderRows === \"function\";\n}\n\nexport class ScrollableChatTranscriptComponent<TEntry extends ChatTranscriptEntryLike>\n implements Component\n{\n private readonly viewport = new ScrollableComponentViewport();\n private readonly transcript: ChatTranscriptComponent<TEntry>;\n\n constructor(\n entries: readonly TEntry[],\n renderEntry: ChatTranscriptRenderer<TEntry>,\n ) {\n this.transcript = new ChatTranscriptComponent(entries, renderEntry);\n this.viewport.setComponents([this.transcript]);\n }\n\n setVisibleRows(rows: number): void {\n this.viewport.setVisibleRows(rows);\n }\n\n handleInput(data: string): boolean {\n return this.viewport.handleInput(data);\n }\n\n render(width: number): string[] {\n return this.viewport.render(width);\n }\n\n invalidate(): void {\n this.viewport.invalidate();\n }\n\n getScrollFromBottom(): number {\n return this.viewport.getScrollFromBottom();\n }\n\n getMaxScroll(): number {\n return this.viewport.getMaxScroll();\n }\n\n scrollToBottom(): void {\n this.viewport.scrollToBottom();\n }\n}\n\nfunction mouseWheelDeltaRows(data: string): number {\n const sgr = data.match(/^\\x1b\\[<(\\d+);\\d+;\\d+M$/);\n if (sgr) return wheelDeltaForButtonCode(Number.parseInt(sgr[1]!, 10));\n if (data.startsWith(\"\\x1b[M\") && data.length >= 6) {\n return wheelDeltaForButtonCode(data.charCodeAt(3) - 32);\n }\n return 0;\n}\n\nfunction wheelDeltaForButtonCode(code: number): number {\n if ((code & 64) === 0) return 0;\n const direction = code & 3;\n if (direction === 0) return -DEFAULT_SCROLL_STEP_ROWS;\n if (direction === 1) return DEFAULT_SCROLL_STEP_ROWS;\n return 0;\n}\n\nfunction isMouseSequence(data: string): boolean {\n return /^\\x1b\\[<\\d+;\\d+;\\d+[mM]$/.test(data) || data.startsWith(\"\\x1b[M\");\n}\n"]}
@@ -72,10 +72,15 @@ export class ChatTranscriptComponent {
72
72
  return lines;
73
73
  }
74
74
  invalidate() {
75
+ for (const block of this.blockCache)
76
+ disposeComponent(block?.component);
75
77
  this.blockCache = [];
76
78
  }
77
79
  ensureBlockCache(width) {
78
80
  if (this.blockCache.length > this.entries.length) {
81
+ for (let index = this.entries.length; index < this.blockCache.length; index += 1) {
82
+ disposeComponent(this.blockCache[index]?.component);
83
+ }
79
84
  this.blockCache.length = this.entries.length;
80
85
  }
81
86
  for (let index = 0; index < this.entries.length; index += 1) {
@@ -90,11 +95,14 @@ export class ChatTranscriptComponent {
90
95
  cached.width === width) {
91
96
  continue;
92
97
  }
98
+ disposeComponent(cached?.component);
99
+ const component = this.renderEntry(entry);
93
100
  this.blockCache[index] = {
94
101
  entry,
95
102
  key,
96
103
  width,
97
- lines: this.renderEntryBlock(entry, index, width),
104
+ component,
105
+ lines: this.renderEntryBlock(component, entry, index, width),
98
106
  };
99
107
  }
100
108
  }
@@ -103,18 +111,21 @@ export class ChatTranscriptComponent {
103
111
  for (let index = 0; index < this.entries.length; index += 1) {
104
112
  const entry = this.entries[index];
105
113
  if (entry !== undefined)
106
- lines.push(...this.renderEntryBlock(entry, index, width));
114
+ lines.push(...this.renderEntryBlock(this.renderEntry(entry), entry, index, width));
107
115
  }
108
116
  return lines;
109
117
  }
110
- renderEntryBlock(entry, index, width) {
118
+ renderEntryBlock(component, entry, index, width) {
111
119
  const lines = [];
112
120
  if (index > 0 && needsLeadingSpacer(entry.role))
113
121
  lines.push("");
114
- lines.push(...this.renderEntry(entry).render(width));
122
+ lines.push(...component.render(width));
115
123
  return lines;
116
124
  }
117
125
  }
126
+ function disposeComponent(component) {
127
+ component?.dispose?.();
128
+ }
118
129
  const DEFAULT_SCROLL_STEP_ROWS = 4;
119
130
  /**
120
131
  * Sticky-bottom, scrollable viewport for chat-like component stacks.
@@ -1 +1 @@
1
- {"version":3,"file":"chat-transcript.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/chat-transcript.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAGV,MAAM,GACP,MAAM,wBAAwB,CAAC;AA2DhC,MAAM,UAAU,sBAAsB,CACpC,SAAoB,EACpB,SAAoB,EACpB,IAAwB;IAExB,IAAI,kBAAkB,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9D,SAAS,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,CAAC;IACD,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAwB;IAClD,OAAO,CACL,IAAI,KAAK,MAAM;QACf,IAAI,KAAK,QAAQ;QACjB,IAAI,KAAK,QAAQ;QACjB,IAAI,KAAK,QAAQ;QACjB,IAAI,KAAK,SAAS,CACnB,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,uBAAuB;IAUlC,YACE,OAA0B,EAC1B,WAA2C,EAC3C,QAAyC;QALnC,eAAU,GAAyD,EAAE,CAAC;QAO5E,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,QAAQ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AQ,CAAC,mBAAmB,EAAE,CAAC;IAC7C,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC;IACtC,CAAC;IAED,cAAc;QACZ,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;IACjC,CAAC;CACF;AAED,SAAS,mBAAmB,CAAC,IAAY;IACvC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAClD,IAAI,GAAG;QAAE,OAAO,uBAAuB,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IACtE,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;QAClD,OAAO,uBAAuB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,uBAAuB,CAAC,IAAY;IAC3C,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAChC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC;IAC3B,IAAI,SAAS,KAAK,CAAC;QAAE,OAAO,CAAC,wBAAwB,CAAC;IACtD,IAAI,SAAS,KAAK,CAAC;QAAE,OAAO,wBAAwB,CAAC;IACrD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,eAAe,CAAC,IAAY;IACnC,OAAO,0BAA0B,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["import {\n matchesKey,\n type Component,\n Container,\n Spacer,\n} from \"@earendil-works/pi-tui\";\n\n/**\n * Roles that participate in pi's chat spacing contract.\n *\n * Assistant turns own their leading whitespace internally, and tool rows attach\n * directly under the assistant/tool-call row they belong to. User-like rows get\n * one blank line when they are not the first row in the transcript.\n */\nexport type ChatTranscriptRole =\n | \"assistant\"\n | \"thinking\"\n | \"tool\"\n | \"user\"\n | \"custom\"\n | \"notice\"\n | \"system\"\n | \"summary\";\n\nexport interface ChatTranscriptEntryLike {\n readonly role: ChatTranscriptRole;\n}\n\nexport type ChatTranscriptRenderer<TEntry extends ChatTranscriptEntryLike> = (\n entry: TEntry,\n) => Component;\n\nexport type ChatTranscriptCacheKey<TEntry extends ChatTranscriptEntryLike> = (\n entry: TEntry,\n index: number,\n) => string;\n\ninterface CachedChatTranscriptBlock<TEntry extends ChatTranscriptEntryLike> {\n readonly entry: TEntry;\n readonly key: string;\n readonly width: number;\n readonly lines: readonly string[];\n}\n\ninterface RowWindowComponent extends Component {\n readonly supportsRowWindow: true;\n rowCount(width: number): number;\n renderRows(width: number, startRow: number, endRow: number): string[];\n}\n\ninterface WindowedComponentRows {\n readonly kind: \"windowed\";\n readonly component: RowWindowComponent;\n readonly rowCount: number;\n}\n\ninterface StaticComponentRows {\n readonly kind: \"static\";\n readonly lines: readonly string[];\n readonly rowCount: number;\n}\n\ntype ComponentRows = WindowedComponentRows | StaticComponentRows;\n\nexport function addChatTranscriptEntry(\n container: Container,\n component: Component,\n role: ChatTranscriptRole,\n): void {\n if (needsLeadingSpacer(role) && container.children.length > 0) {\n container.addChild(new Spacer(1));\n }\n container.addChild(component);\n}\n\nfunction needsLeadingSpacer(role: ChatTranscriptRole): boolean {\n return (\n role === \"user\" ||\n role === \"custom\" ||\n role === \"notice\" ||\n role === \"system\" ||\n role === \"summary\"\n );\n}\n\n/**\n * Reusable pi chat transcript scaffold for extension surfaces.\n *\n * This intentionally mirrors InteractiveMode.addMessageToChat spacing without\n * coupling consumers to a full AgentSession. Extension UIs can bring their own\n * message model while still rendering inside the same Container/Spacer rhythm\n * as the main chat.\n */\nexport class ChatTranscriptComponent<TEntry extends ChatTranscriptEntryLike>\n implements Component\n{\n private readonly entries: readonly TEntry[];\n private readonly renderEntry: ChatTranscriptRenderer<TEntry>;\n readonly supportsRowWindow: boolean;\n\n private readonly cacheKey: ChatTranscriptCacheKey<TEntry> | undefined;\n private blockCache: Array<CachedChatTranscriptBlock<TEntry> | undefined> = [];\n\n constructor(\n entries: readonly TEntry[],\n renderEntry: ChatTranscriptRenderer<TEntry>,\n cacheKey?: ChatTranscriptCacheKey<TEntry>,\n ) {\n this.entries = entries;\n this.renderEntry = renderEntry;\n this.cacheKey = cacheKey;\n this.supportsRowWindow = cacheKey !== undefined;\n }\n\n render(width: number): string[] {\n if (!this.supportsRowWindow) return this.renderAllRows(width);\n return this.renderRows(width, 0, this.rowCount(width));\n }\n\n rowCount(width: number): number {\n if (!this.supportsRowWindow) return this.renderAllRows(width).length;\n this.ensureBlockCache(width);\n let count = 0;\n for (const block of this.blockCache) {\n if (block !== undefined) count += block.lines.length;\n }\n return count;\n }\n\n renderRows(width: number, startRow: number, endRow: number): string[] {\n const start = Math.max(0, Math.floor(startRow));\n const end = Math.max(start, Math.floor(endRow));\n if (end <= start) return [];\n if (!this.supportsRowWindow) return this.renderAllRows(width).slice(start, end);\n\n this.ensureBlockCache(width);\n const lines: string[] = [];\n let cursor = 0;\n for (let index = 0; index < this.entries.length; index += 1) {\n const block = this.blockCache[index];\n if (block === undefined) continue;\n const blockStart = cursor;\n const blockEnd = blockStart + block.lines.length;\n if (blockEnd > start && blockStart < end) {\n const localStart = Math.max(0, start - blockStart);\n const localEnd = Math.min(block.lines.length, end - blockStart);\n lines.push(...block.lines.slice(localStart, localEnd));\n }\n cursor = blockEnd;\n if (cursor >= end) break;\n }\n return lines;\n }\n\n invalidate(): void {\n this.blockCache = [];\n }\n\n private ensureBlockCache(width: number): void {\n if (this.blockCache.length > this.entries.length) {\n this.blockCache.length = this.entries.length;\n }\n for (let index = 0; index < this.entries.length; index += 1) {\n const entry = this.entries[index];\n if (entry === undefined) continue;\n const key = this.cacheKey?.(entry, index) ?? `${index}:${entry.role}`;\n const cached = this.blockCache[index];\n if (\n cached !== undefined &&\n cached.entry === entry &&\n cached.key === key &&\n cached.width === width\n ) {\n continue;\n }\n this.blockCache[index] = {\n entry,\n key,\n width,\n lines: this.renderEntryBlock(entry, index, width),\n };\n }\n }\n\n private renderAllRows(width: number): string[] {\n const lines: string[] = [];\n for (let index = 0; index < this.entries.length; index += 1) {\n const entry = this.entries[index];\n if (entry !== undefined) lines.push(...this.renderEntryBlock(entry, index, width));\n }\n return lines;\n }\n\n private renderEntryBlock(entry: TEntry, index: number, width: number): string[] {\n const lines: string[] = [];\n if (index > 0 && needsLeadingSpacer(entry.role)) lines.push(\"\");\n lines.push(...this.renderEntry(entry).render(width));\n return lines;\n }\n}\n\nconst DEFAULT_SCROLL_STEP_ROWS = 4;\n\n/**\n * Sticky-bottom, scrollable viewport for chat-like component stacks.\n *\n * Pi's main interactive chat gets terminal scrollback for free. Extension\n * overlays render into a fixed rectangle, so they need an explicit viewport\n * with the same sticky-bottom default plus keyboard and mouse history controls.\n */\nexport class ScrollableComponentViewport implements Component {\n private components: readonly Component[] = [];\n private visibleRows = 1;\n private scrollFromBottom = 0;\n private lastLineCount = 0;\n private lastWidth = 0;\n private maxScroll = 0;\n\n setComponents(components: readonly Component[]): void {\n this.components = components;\n }\n\n setVisibleRows(rows: number): void {\n this.visibleRows = Math.max(1, Math.floor(rows));\n this.clampScroll();\n }\n\n getScrollFromBottom(): number {\n return this.scrollFromBottom;\n }\n\n getMaxScroll(): number {\n return this.maxScroll;\n }\n\n scrollToBottom(): void {\n this.scrollFromBottom = 0;\n }\n\n scrollToTop(): void {\n this.scrollFromBottom = this.maxScroll;\n }\n\n scrollBy(deltaRows: number): void {\n // Positive deltas move toward newer content; negative deltas move up\n // into older history. Store the offset from the sticky bottom so new\n // streaming output can keep following when the offset is zero.\n this.scrollFromBottom -= deltaRows;\n this.clampScroll();\n }\n\n handleInput(data: string): boolean {\n const wheelDeltaRows = mouseWheelDeltaRows(data);\n if (wheelDeltaRows !== 0) {\n this.scrollBy(wheelDeltaRows);\n return true;\n }\n if (isMouseSequence(data)) return true;\n if (matchesKey(data, \"pageUp\")) {\n this.scrollBy(-this.pageSize());\n return true;\n }\n if (matchesKey(data, \"pageDown\")) {\n this.scrollBy(this.pageSize());\n return true;\n }\n if (matchesKey(data, \"home\")) {\n this.scrollToTop();\n return true;\n }\n if (matchesKey(data, \"end\")) {\n this.scrollToBottom();\n return true;\n }\n return false;\n }\n\n render(width: number): string[] {\n const componentRows = this.measureComponentRows(width);\n const lineCount = componentRows.reduce((sum, rows) => sum + rows.rowCount, 0);\n const maxScroll = Math.max(0, lineCount - this.visibleRows);\n if (this.scrollFromBottom > 0 && this.lastWidth === width && lineCount > this.lastLineCount) {\n this.scrollFromBottom += lineCount - this.lastLineCount;\n }\n this.lastLineCount = lineCount;\n this.lastWidth = width;\n this.maxScroll = maxScroll;\n this.clampScroll();\n\n const start = Math.max(0, maxScroll - this.scrollFromBottom);\n const visible = this.renderVisibleRows(\n componentRows,\n width,\n start,\n start + this.visibleRows,\n );\n while (visible.length < this.visibleRows) visible.push(\" \".repeat(width));\n return visible;\n }\n\n invalidate(): void {\n for (const component of this.components) component.invalidate();\n }\n\n private measureComponentRows(width: number): ComponentRows[] {\n return this.components.map((component) => {\n if (isRowWindowComponent(component)) {\n return {\n kind: \"windowed\",\n component,\n rowCount: component.rowCount(width),\n };\n }\n const lines = component.render(width);\n return {\n kind: \"static\",\n lines,\n rowCount: lines.length,\n };\n });\n }\n\n private renderVisibleRows(\n componentRows: readonly ComponentRows[],\n width: number,\n startRow: number,\n endRow: number,\n ): string[] {\n const lines: string[] = [];\n let cursor = 0;\n for (const rows of componentRows) {\n const componentStart = cursor;\n const componentEnd = componentStart + rows.rowCount;\n if (componentEnd > startRow && componentStart < endRow) {\n const localStart = Math.max(0, startRow - componentStart);\n const localEnd = Math.min(rows.rowCount, endRow - componentStart);\n if (rows.kind === \"windowed\") {\n lines.push(...rows.component.renderRows(width, localStart, localEnd));\n } else {\n lines.push(...rows.lines.slice(localStart, localEnd));\n }\n }\n cursor = componentEnd;\n if (cursor >= endRow) break;\n }\n return lines;\n }\n\n private pageSize(): number {\n return Math.max(4, this.visibleRows - 2);\n }\n\n private clampScroll(): void {\n this.scrollFromBottom = Math.max(0, Math.min(this.maxScroll, this.scrollFromBottom));\n }\n}\n\nfunction isRowWindowComponent(component: Component): component is RowWindowComponent {\n const candidate = component as Partial<RowWindowComponent>;\n return candidate.supportsRowWindow === true &&\n typeof candidate.rowCount === \"function\" &&\n typeof candidate.renderRows === \"function\";\n}\n\nexport class ScrollableChatTranscriptComponent<TEntry extends ChatTranscriptEntryLike>\n implements Component\n{\n private readonly viewport = new ScrollableComponentViewport();\n private readonly transcript: ChatTranscriptComponent<TEntry>;\n\n constructor(\n entries: readonly TEntry[],\n renderEntry: ChatTranscriptRenderer<TEntry>,\n ) {\n this.transcript = new ChatTranscriptComponent(entries, renderEntry);\n this.viewport.setComponents([this.transcript]);\n }\n\n setVisibleRows(rows: number): void {\n this.viewport.setVisibleRows(rows);\n }\n\n handleInput(data: string): boolean {\n return this.viewport.handleInput(data);\n }\n\n render(width: number): string[] {\n return this.viewport.render(width);\n }\n\n invalidate(): void {\n this.viewport.invalidate();\n }\n\n getScrollFromBottom(): number {\n return this.viewport.getScrollFromBottom();\n }\n\n getMaxScroll(): number {\n return this.viewport.getMaxScroll();\n }\n\n scrollToBottom(): void {\n this.viewport.scrollToBottom();\n }\n}\n\nfunction mouseWheelDeltaRows(data: string): number {\n const sgr = data.match(/^\\x1b\\[<(\\d+);\\d+;\\d+M$/);\n if (sgr) return wheelDeltaForButtonCode(Number.parseInt(sgr[1]!, 10));\n if (data.startsWith(\"\\x1b[M\") && data.length >= 6) {\n return wheelDeltaForButtonCode(data.charCodeAt(3) - 32);\n }\n return 0;\n}\n\nfunction wheelDeltaForButtonCode(code: number): number {\n if ((code & 64) === 0) return 0;\n const direction = code & 3;\n if (direction === 0) return -DEFAULT_SCROLL_STEP_ROWS;\n if (direction === 1) return DEFAULT_SCROLL_STEP_ROWS;\n return 0;\n}\n\nfunction isMouseSequence(data: string): boolean {\n return /^\\x1b\\[<\\d+;\\d+;\\d+[mM]$/.test(data) || data.startsWith(\"\\x1b[M\");\n}\n"]}
1
+ {"version":3,"file":"chat-transcript.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/chat-transcript.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAGV,MAAM,GACP,MAAM,wBAAwB,CAAC;AA8DhC,MAAM,UAAU,sBAAsB,CACpC,SAAoB,EACpB,SAAoB,EACpB,IAAwB;IAExB,IAAI,kBAAkB,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9D,SAAS,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,CAAC;IACD,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAwB;IAClD,OAAO,CACL,IAAI,KAAK,MAAM;QACf,IAAI,KAAK,QAAQ;QACjB,IAAI,KAAK,QAAQ;QACjB,IAAI,KAAK,QAAQ;QACjB,IAAI,KAAK,SAAS,CACnB,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,uBAAuB;IAUlC,YACE,OAA0B,EAC1B,WAA2C,EAC3C,QAAyC;QALnC,eAAU,GAAyD,EAAE,CAAC;QAO5E,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,iBAAiB,GAAG,QAAQ,KAAK,SAAS,CAAC;IAClD,CAAC;IAED,MAAM,CAAC,KAAa;QAClB,IAAI,CAAC,IAAI,CAAC,iBAAiB;YAAE,OAAO,IAAI,CAAC,aA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,CAAC;IAC3B,IAAI,SAAS,KAAK,CAAC;QAAE,OAAO,CAAC,wBAAwB,CAAC;IACtD,IAAI,SAAS,KAAK,CAAC;QAAE,OAAO,wBAAwB,CAAC;IACrD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,eAAe,CAAC,IAAY;IACnC,OAAO,0BAA0B,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["import {\n matchesKey,\n type Component,\n Container,\n Spacer,\n} from \"@earendil-works/pi-tui\";\n\n/**\n * Roles that participate in pi's chat spacing contract.\n *\n * Assistant turns own their leading whitespace internally, and tool rows attach\n * directly under the assistant/tool-call row they belong to. User-like rows get\n * one blank line when they are not the first row in the transcript.\n */\nexport type ChatTranscriptRole =\n | \"assistant\"\n | \"thinking\"\n | \"tool\"\n | \"user\"\n | \"custom\"\n | \"notice\"\n | \"system\"\n | \"summary\";\n\nexport interface ChatTranscriptEntryLike {\n readonly role: ChatTranscriptRole;\n}\n\nexport type ChatTranscriptRenderer<TEntry extends ChatTranscriptEntryLike> = (\n entry: TEntry,\n) => Component;\n\nexport type ChatTranscriptCacheKey<TEntry extends ChatTranscriptEntryLike> = (\n entry: TEntry,\n index: number,\n) => string;\n\ninterface CachedChatTranscriptBlock<TEntry extends ChatTranscriptEntryLike> {\n readonly entry: TEntry;\n readonly key: string;\n readonly width: number;\n readonly component: Component;\n readonly lines: readonly string[];\n}\n\ntype DisposableComponent = Component & { dispose?: () => void };\n\ninterface RowWindowComponent extends Component {\n readonly supportsRowWindow: true;\n rowCount(width: number): number;\n renderRows(width: number, startRow: number, endRow: number): string[];\n}\n\ninterface WindowedComponentRows {\n readonly kind: \"windowed\";\n readonly component: RowWindowComponent;\n readonly rowCount: number;\n}\n\ninterface StaticComponentRows {\n readonly kind: \"static\";\n readonly lines: readonly string[];\n readonly rowCount: number;\n}\n\ntype ComponentRows = WindowedComponentRows | StaticComponentRows;\n\nexport function addChatTranscriptEntry(\n container: Container,\n component: Component,\n role: ChatTranscriptRole,\n): void {\n if (needsLeadingSpacer(role) && container.children.length > 0) {\n container.addChild(new Spacer(1));\n }\n container.addChild(component);\n}\n\nfunction needsLeadingSpacer(role: ChatTranscriptRole): boolean {\n return (\n role === \"user\" ||\n role === \"custom\" ||\n role === \"notice\" ||\n role === \"system\" ||\n role === \"summary\"\n );\n}\n\n/**\n * Reusable pi chat transcript scaffold for extension surfaces.\n *\n * This intentionally mirrors InteractiveMode.addMessageToChat spacing without\n * coupling consumers to a full AgentSession. Extension UIs can bring their own\n * message model while still rendering inside the same Container/Spacer rhythm\n * as the main chat.\n */\nexport class ChatTranscriptComponent<TEntry extends ChatTranscriptEntryLike>\n implements Component\n{\n private readonly entries: readonly TEntry[];\n private readonly renderEntry: ChatTranscriptRenderer<TEntry>;\n readonly supportsRowWindow: boolean;\n\n private readonly cacheKey: ChatTranscriptCacheKey<TEntry> | undefined;\n private blockCache: Array<CachedChatTranscriptBlock<TEntry> | undefined> = [];\n\n constructor(\n entries: readonly TEntry[],\n renderEntry: ChatTranscriptRenderer<TEntry>,\n cacheKey?: ChatTranscriptCacheKey<TEntry>,\n ) {\n this.entries = entries;\n this.renderEntry = renderEntry;\n this.cacheKey = cacheKey;\n this.supportsRowWindow = cacheKey !== undefined;\n }\n\n render(width: number): string[] {\n if (!this.supportsRowWindow) return this.renderAllRows(width);\n return this.renderRows(width, 0, this.rowCount(width));\n }\n\n rowCount(width: number): number {\n if (!this.supportsRowWindow) return this.renderAllRows(width).length;\n this.ensureBlockCache(width);\n let count = 0;\n for (const block of this.blockCache) {\n if (block !== undefined) count += block.lines.length;\n }\n return count;\n }\n\n renderRows(width: number, startRow: number, endRow: number): string[] {\n const start = Math.max(0, Math.floor(startRow));\n const end = Math.max(start, Math.floor(endRow));\n if (end <= start) return [];\n if (!this.supportsRowWindow) return this.renderAllRows(width).slice(start, end);\n\n this.ensureBlockCache(width);\n const lines: string[] = [];\n let cursor = 0;\n for (let index = 0; index < this.entries.length; index += 1) {\n const block = this.blockCache[index];\n if (block === undefined) continue;\n const blockStart = cursor;\n const blockEnd = blockStart + block.lines.length;\n if (blockEnd > start && blockStart < end) {\n const localStart = Math.max(0, start - blockStart);\n const localEnd = Math.min(block.lines.length, end - blockStart);\n lines.push(...block.lines.slice(localStart, localEnd));\n }\n cursor = blockEnd;\n if (cursor >= end) break;\n }\n return lines;\n }\n\n invalidate(): void {\n for (const block of this.blockCache) disposeComponent(block?.component);\n this.blockCache = [];\n }\n\n private ensureBlockCache(width: number): void {\n if (this.blockCache.length > this.entries.length) {\n for (let index = this.entries.length; index < this.blockCache.length; index += 1) {\n disposeComponent(this.blockCache[index]?.component);\n }\n this.blockCache.length = this.entries.length;\n }\n for (let index = 0; index < this.entries.length; index += 1) {\n const entry = this.entries[index];\n if (entry === undefined) continue;\n const key = this.cacheKey?.(entry, index) ?? `${index}:${entry.role}`;\n const cached = this.blockCache[index];\n if (\n cached !== undefined &&\n cached.entry === entry &&\n cached.key === key &&\n cached.width === width\n ) {\n continue;\n }\n disposeComponent(cached?.component);\n const component = this.renderEntry(entry);\n this.blockCache[index] = {\n entry,\n key,\n width,\n component,\n lines: this.renderEntryBlock(component, entry, index, width),\n };\n }\n }\n\n private renderAllRows(width: number): string[] {\n const lines: string[] = [];\n for (let index = 0; index < this.entries.length; index += 1) {\n const entry = this.entries[index];\n if (entry !== undefined) lines.push(...this.renderEntryBlock(this.renderEntry(entry), entry, index, width));\n }\n return lines;\n }\n\n private renderEntryBlock(\n component: Component,\n entry: TEntry,\n index: number,\n width: number,\n ): string[] {\n const lines: string[] = [];\n if (index > 0 && needsLeadingSpacer(entry.role)) lines.push(\"\");\n lines.push(...component.render(width));\n return lines;\n }\n}\n\nfunction disposeComponent(component: Component | undefined): void {\n (component as DisposableComponent | undefined)?.dispose?.();\n}\n\nconst DEFAULT_SCROLL_STEP_ROWS = 4;\n\n/**\n * Sticky-bottom, scrollable viewport for chat-like component stacks.\n *\n * Pi's main interactive chat gets terminal scrollback for free. Extension\n * overlays render into a fixed rectangle, so they need an explicit viewport\n * with the same sticky-bottom default plus keyboard and mouse history controls.\n */\nexport class ScrollableComponentViewport implements Component {\n private components: readonly Component[] = [];\n private visibleRows = 1;\n private scrollFromBottom = 0;\n private lastLineCount = 0;\n private lastWidth = 0;\n private maxScroll = 0;\n\n setComponents(components: readonly Component[]): void {\n this.components = components;\n }\n\n setVisibleRows(rows: number): void {\n this.visibleRows = Math.max(1, Math.floor(rows));\n this.clampScroll();\n }\n\n getScrollFromBottom(): number {\n return this.scrollFromBottom;\n }\n\n getMaxScroll(): number {\n return this.maxScroll;\n }\n\n scrollToBottom(): void {\n this.scrollFromBottom = 0;\n }\n\n scrollToTop(): void {\n this.scrollFromBottom = this.maxScroll;\n }\n\n scrollBy(deltaRows: number): void {\n // Positive deltas move toward newer content; negative deltas move up\n // into older history. Store the offset from the sticky bottom so new\n // streaming output can keep following when the offset is zero.\n this.scrollFromBottom -= deltaRows;\n this.clampScroll();\n }\n\n handleInput(data: string): boolean {\n const wheelDeltaRows = mouseWheelDeltaRows(data);\n if (wheelDeltaRows !== 0) {\n this.scrollBy(wheelDeltaRows);\n return true;\n }\n if (isMouseSequence(data)) return true;\n if (matchesKey(data, \"pageUp\")) {\n this.scrollBy(-this.pageSize());\n return true;\n }\n if (matchesKey(data, \"pageDown\")) {\n this.scrollBy(this.pageSize());\n return true;\n }\n if (matchesKey(data, \"home\")) {\n this.scrollToTop();\n return true;\n }\n if (matchesKey(data, \"end\")) {\n this.scrollToBottom();\n return true;\n }\n return false;\n }\n\n render(width: number): string[] {\n const componentRows = this.measureComponentRows(width);\n const lineCount = componentRows.reduce((sum, rows) => sum + rows.rowCount, 0);\n const maxScroll = Math.max(0, lineCount - this.visibleRows);\n if (this.scrollFromBottom > 0 && this.lastWidth === width && lineCount > this.lastLineCount) {\n this.scrollFromBottom += lineCount - this.lastLineCount;\n }\n this.lastLineCount = lineCount;\n this.lastWidth = width;\n this.maxScroll = maxScroll;\n this.clampScroll();\n\n const start = Math.max(0, maxScroll - this.scrollFromBottom);\n const visible = this.renderVisibleRows(\n componentRows,\n width,\n start,\n start + this.visibleRows,\n );\n while (visible.length < this.visibleRows) visible.push(\" \".repeat(width));\n return visible;\n }\n\n invalidate(): void {\n for (const component of this.components) component.invalidate();\n }\n\n private measureComponentRows(width: number): ComponentRows[] {\n return this.components.map((component) => {\n if (isRowWindowComponent(component)) {\n return {\n kind: \"windowed\",\n component,\n rowCount: component.rowCount(width),\n };\n }\n const lines = component.render(width);\n return {\n kind: \"static\",\n lines,\n rowCount: lines.length,\n };\n });\n }\n\n private renderVisibleRows(\n componentRows: readonly ComponentRows[],\n width: number,\n startRow: number,\n endRow: number,\n ): string[] {\n const lines: string[] = [];\n let cursor = 0;\n for (const rows of componentRows) {\n const componentStart = cursor;\n const componentEnd = componentStart + rows.rowCount;\n if (componentEnd > startRow && componentStart < endRow) {\n const localStart = Math.max(0, startRow - componentStart);\n const localEnd = Math.min(rows.rowCount, endRow - componentStart);\n if (rows.kind === \"windowed\") {\n lines.push(...rows.component.renderRows(width, localStart, localEnd));\n } else {\n lines.push(...rows.lines.slice(localStart, localEnd));\n }\n }\n cursor = componentEnd;\n if (cursor >= endRow) break;\n }\n return lines;\n }\n\n private pageSize(): number {\n return Math.max(4, this.visibleRows - 2);\n }\n\n private clampScroll(): void {\n this.scrollFromBottom = Math.max(0, Math.min(this.maxScroll, this.scrollFromBottom));\n }\n}\n\nfunction isRowWindowComponent(component: Component): component is RowWindowComponent {\n const candidate = component as Partial<RowWindowComponent>;\n return candidate.supportsRowWindow === true &&\n typeof candidate.rowCount === \"function\" &&\n typeof candidate.renderRows === \"function\";\n}\n\nexport class ScrollableChatTranscriptComponent<TEntry extends ChatTranscriptEntryLike>\n implements Component\n{\n private readonly viewport = new ScrollableComponentViewport();\n private readonly transcript: ChatTranscriptComponent<TEntry>;\n\n constructor(\n entries: readonly TEntry[],\n renderEntry: ChatTranscriptRenderer<TEntry>,\n ) {\n this.transcript = new ChatTranscriptComponent(entries, renderEntry);\n this.viewport.setComponents([this.transcript]);\n }\n\n setVisibleRows(rows: number): void {\n this.viewport.setVisibleRows(rows);\n }\n\n handleInput(data: string): boolean {\n return this.viewport.handleInput(data);\n }\n\n render(width: number): string[] {\n return this.viewport.render(width);\n }\n\n invalidate(): void {\n this.viewport.invalidate();\n }\n\n getScrollFromBottom(): number {\n return this.viewport.getScrollFromBottom();\n }\n\n getMaxScroll(): number {\n return this.viewport.getMaxScroll();\n }\n\n scrollToBottom(): void {\n this.viewport.scrollToBottom();\n }\n}\n\nfunction mouseWheelDeltaRows(data: string): number {\n const sgr = data.match(/^\\x1b\\[<(\\d+);\\d+;\\d+M$/);\n if (sgr) return wheelDeltaForButtonCode(Number.parseInt(sgr[1]!, 10));\n if (data.startsWith(\"\\x1b[M\") && data.length >= 6) {\n return wheelDeltaForButtonCode(data.charCodeAt(3) - 32);\n }\n return 0;\n}\n\nfunction wheelDeltaForButtonCode(code: number): number {\n if ((code & 64) === 0) return 0;\n const direction = code & 3;\n if (direction === 0) return -DEFAULT_SCROLL_STEP_ROWS;\n if (direction === 1) return DEFAULT_SCROLL_STEP_ROWS;\n return 0;\n}\n\nfunction isMouseSequence(data: string): boolean {\n return /^\\x1b\\[<\\d+;\\d+;\\d+[mM]$/.test(data) || data.startsWith(\"\\x1b[M\");\n}\n"]}
@@ -52,9 +52,12 @@ export declare class ToolExecutionComponent extends Container {
52
52
  setShowImages(show: boolean): void;
53
53
  setImageWidthCells(width: number): void;
54
54
  invalidate(): void;
55
+ dispose(): void;
55
56
  render(width: number): string[];
56
57
  private updateDisplay;
57
58
  private getTextOutput;
59
+ private disposeRendererComponent;
60
+ private clearRendererStateTimer;
58
61
  private formatToolExecution;
59
62
  }
60
63
  export {};