@openlucaskaka/kagent 0.1.7

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 (117) hide show
  1. package/README.md +353 -0
  2. package/npm/bin/kagent-serve.js +6 -0
  3. package/npm/bin/kagent.js +6 -0
  4. package/npm/lib/App.js +524 -0
  5. package/npm/lib/app-state.js +224 -0
  6. package/npm/lib/approval-choice.js +25 -0
  7. package/npm/lib/commands.js +59 -0
  8. package/npm/lib/editor.js +188 -0
  9. package/npm/lib/ink-runner.js +41 -0
  10. package/npm/lib/kagent-home.js +39 -0
  11. package/npm/lib/launcher.js +221 -0
  12. package/npm/lib/protocol.js +33 -0
  13. package/npm/lib/provider-setup.js +139 -0
  14. package/npm/lib/python-runner.js +892 -0
  15. package/npm/lib/runtime-client.js +390 -0
  16. package/npm/lib/terminal-input.js +127 -0
  17. package/npm/lib/terminal-text.js +19 -0
  18. package/npm/lib/terminal-width.js +14 -0
  19. package/npm/lib/transcript.js +227 -0
  20. package/npm/lib/ui-components.js +247 -0
  21. package/npm/lib/update-manager.js +334 -0
  22. package/package.json +39 -0
  23. package/pyproject.toml +55 -0
  24. package/src/kagent/__init__.py +90 -0
  25. package/src/kagent/cli/__init__.py +5 -0
  26. package/src/kagent/cli/__main__.py +6 -0
  27. package/src/kagent/cli/commands.py +112 -0
  28. package/src/kagent/cli/conversation.py +127 -0
  29. package/src/kagent/cli/interactive.py +841 -0
  30. package/src/kagent/cli/main.py +685 -0
  31. package/src/kagent/cli/memory.py +460 -0
  32. package/src/kagent/cli/pending_approval.py +169 -0
  33. package/src/kagent/cli/provider.py +27 -0
  34. package/src/kagent/cli/session_commands.py +401 -0
  35. package/src/kagent/cli/stdio_runtime.py +784 -0
  36. package/src/kagent/cli/trace.py +67 -0
  37. package/src/kagent/cli/ui.py +931 -0
  38. package/src/kagent/core/__init__.py +0 -0
  39. package/src/kagent/core/agent.py +296 -0
  40. package/src/kagent/core/faults.py +11 -0
  41. package/src/kagent/core/invariants.py +47 -0
  42. package/src/kagent/core/normalization.py +81 -0
  43. package/src/kagent/core/planning.py +48 -0
  44. package/src/kagent/core/state.py +73 -0
  45. package/src/kagent/core/summary.py +64 -0
  46. package/src/kagent/core/tools.py +196 -0
  47. package/src/kagent/core/trace.py +57 -0
  48. package/src/kagent/eval/__init__.py +11 -0
  49. package/src/kagent/eval/cases.py +229 -0
  50. package/src/kagent/eval/evaluator.py +216 -0
  51. package/src/kagent/integrations/__init__.py +3 -0
  52. package/src/kagent/integrations/audit.py +95 -0
  53. package/src/kagent/integrations/backends.py +131 -0
  54. package/src/kagent/integrations/memory.py +301 -0
  55. package/src/kagent/ops/__init__.py +0 -0
  56. package/src/kagent/ops/batch.py +156 -0
  57. package/src/kagent/ops/doctor.py +255 -0
  58. package/src/kagent/ops/metrics.py +214 -0
  59. package/src/kagent/ops/release_evidence.py +877 -0
  60. package/src/kagent/ops/release_manifest.py +142 -0
  61. package/src/kagent/ops/trace_replay.py +285 -0
  62. package/src/kagent/providers/__init__.py +7 -0
  63. package/src/kagent/providers/embeddings.py +187 -0
  64. package/src/kagent/providers/llm.py +770 -0
  65. package/src/kagent/py.typed +1 -0
  66. package/src/kagent/runtime/__init__.py +28 -0
  67. package/src/kagent/runtime/action_graph.py +543 -0
  68. package/src/kagent/runtime/agent.py +2089 -0
  69. package/src/kagent/runtime/approval.py +64 -0
  70. package/src/kagent/runtime/cancellation.py +64 -0
  71. package/src/kagent/runtime/checkpoint_state.py +146 -0
  72. package/src/kagent/runtime/checkpoint_storage.py +270 -0
  73. package/src/kagent/runtime/context.py +65 -0
  74. package/src/kagent/runtime/file_transaction.py +195 -0
  75. package/src/kagent/runtime/hooks.py +74 -0
  76. package/src/kagent/runtime/metadata.py +116 -0
  77. package/src/kagent/runtime/patch_checkpoints.py +385 -0
  78. package/src/kagent/runtime/policy.py +50 -0
  79. package/src/kagent/runtime/presentation.py +205 -0
  80. package/src/kagent/runtime/redaction.py +130 -0
  81. package/src/kagent/runtime/sandbox.py +331 -0
  82. package/src/kagent/runtime/skills.py +66 -0
  83. package/src/kagent/runtime/steering.py +56 -0
  84. package/src/kagent/runtime/steps.py +255 -0
  85. package/src/kagent/runtime/task_state.py +40 -0
  86. package/src/kagent/runtime/tools.py +3532 -0
  87. package/src/kagent/runtime/types.py +240 -0
  88. package/src/kagent/runtime/workspace.py +597 -0
  89. package/src/kagent/service/__init__.py +26 -0
  90. package/src/kagent/service/__main__.py +6 -0
  91. package/src/kagent/service/active_runs.py +178 -0
  92. package/src/kagent/service/cli.py +737 -0
  93. package/src/kagent/service/contract.py +2571 -0
  94. package/src/kagent/service/errors.py +71 -0
  95. package/src/kagent/service/idempotency.py +584 -0
  96. package/src/kagent/service/router.py +884 -0
  97. package/src/kagent/service/run.py +150 -0
  98. package/src/kagent/service/runtime.py +1915 -0
  99. package/src/kagent/service/runtime_approval.py +20 -0
  100. package/src/kagent/service/runtime_cancel.py +192 -0
  101. package/src/kagent/service/runtime_lifecycle.py +229 -0
  102. package/src/kagent/service/runtime_metadata.py +21 -0
  103. package/src/kagent/service/runtime_policy.py +115 -0
  104. package/src/kagent/service/runtime_recovery.py +573 -0
  105. package/src/kagent/service/runtime_resume.py +382 -0
  106. package/src/kagent/service/runtime_resume_claim.py +116 -0
  107. package/src/kagent/service/runtime_run.py +350 -0
  108. package/src/kagent/service/runtime_status.py +2007 -0
  109. package/src/kagent/service/safety.py +139 -0
  110. package/src/kagent/service/server.py +114 -0
  111. package/src/kagent/service/status.py +233 -0
  112. package/src/kagent/service/trace_store.py +322 -0
  113. package/src/kagent/service/transport.py +24 -0
  114. package/src/kagent/utils/__init__.py +0 -0
  115. package/src/kagent/utils/config_validation.py +21 -0
  116. package/src/kagent/utils/json_output.py +23 -0
  117. package/src/kagent/utils/paths.py +473 -0
package/npm/lib/App.js ADDED
@@ -0,0 +1,524 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KagentInkApp = KagentInkApp;
4
+ exports.isSessionCommandInput = isSessionCommandInput;
5
+ const approval_choice_1 = require("./approval-choice");
6
+ const app_state_1 = require("./app-state");
7
+ const commands_1 = require("./commands");
8
+ const editor_1 = require("./editor");
9
+ const runtime_client_1 = require("./runtime-client");
10
+ const provider_setup_1 = require("./provider-setup");
11
+ const terminal_input_1 = require("./terminal-input");
12
+ const transcript_1 = require("./transcript");
13
+ const ui_components_1 = require("./ui-components");
14
+ function KagentInkApp({ React, Ink, runtimeSessionFactory = runtime_client_1.createRuntimeSessionClient, }) {
15
+ const { Box, Text } = Ink;
16
+ const app = Ink.useApp();
17
+ const { internal_eventEmitter: inputEvents, setRawMode } = Ink.useStdin();
18
+ const [runtime] = React.useState(() => runtimeSessionFactory());
19
+ const [editor, setEditor] = React.useState(editor_1.createEditorState);
20
+ const [runtimeState, setRuntimeState] = React.useState(app_state_1.createAppRuntimeState);
21
+ const [transcriptOffset, setTranscriptOffset] = React.useState(0);
22
+ const [frame, setFrame] = React.useState(0);
23
+ const [showApprovalDetails, setShowApprovalDetails] = React.useState(false);
24
+ const [selectedCommand, setSelectedCommand] = React.useState(null);
25
+ const [terminalSize, setTerminalSize] = React.useState(() => currentTerminalSize());
26
+ const [activitySeconds, setActivitySeconds] = React.useState(0);
27
+ const [approvalChoice, setApprovalChoice] = React.useState("deny");
28
+ const { transcript, status, statusText, approval, provider, setup, commandCatalog } = runtimeState;
29
+ const commandMenu = (0, commands_1.updateCommandMenu)(commandCatalog, editor.value, selectedCommand);
30
+ const terminalInputHandler = React.useRef(() => undefined);
31
+ const activityStartedAt = React.useRef(Date.now());
32
+ terminalInputHandler.current = handleTerminalInput;
33
+ function dispatchRuntime(action) {
34
+ setRuntimeState((current) => (0, app_state_1.appRuntimeReducer)(current, action));
35
+ }
36
+ React.useEffect(() => {
37
+ const bridge = (0, terminal_input_1.createTerminalInputBridge)((input, key) => {
38
+ terminalInputHandler.current(input, key);
39
+ });
40
+ const handleRawInput = (input) => bridge.write(input);
41
+ inputEvents.on("input", handleRawInput);
42
+ setRawMode(true);
43
+ return () => {
44
+ inputEvents.removeListener("input", handleRawInput);
45
+ bridge.close();
46
+ setRawMode(false);
47
+ };
48
+ }, [React, inputEvents, setRawMode]);
49
+ React.useEffect(() => {
50
+ const unsubscribe = runtime.subscribe(handleLifecycleEvent);
51
+ return () => {
52
+ unsubscribe();
53
+ runtime.close();
54
+ };
55
+ }, [React, runtime]);
56
+ React.useEffect(() => {
57
+ const handleResize = () => setTerminalSize(currentTerminalSize());
58
+ process.stdout.on("resize", handleResize);
59
+ return () => {
60
+ process.stdout.removeListener("resize", handleResize);
61
+ };
62
+ }, [React]);
63
+ React.useEffect(() => {
64
+ setTranscriptOffset(0);
65
+ }, [React, transcript.nextId]);
66
+ React.useEffect(() => {
67
+ if (setup?.stage !== "saving") {
68
+ return;
69
+ }
70
+ runtime.configureProvider((0, provider_setup_1.providerConfiguration)(setup), handleProviderEvent);
71
+ }, [React, runtime, setup]);
72
+ React.useEffect(() => {
73
+ setApprovalChoice("deny");
74
+ setShowApprovalDetails(false);
75
+ }, [React, approval?.action_id]);
76
+ React.useEffect(() => {
77
+ if (status !== "thinking" &&
78
+ status !== "cancelling" &&
79
+ status !== "starting" &&
80
+ setup?.stage !== "saving") {
81
+ return undefined;
82
+ }
83
+ const timer = setInterval(() => {
84
+ setFrame((current) => (current + 1) % ui_components_1.TERMINAL_SPINNER_FRAMES.length);
85
+ }, 90);
86
+ return () => clearInterval(timer);
87
+ }, [React, setup?.stage, status]);
88
+ React.useEffect(() => {
89
+ if (status !== "thinking" &&
90
+ status !== "cancelling" &&
91
+ status !== "starting" &&
92
+ setup?.stage !== "saving") {
93
+ setActivitySeconds(0);
94
+ return undefined;
95
+ }
96
+ activityStartedAt.current = Date.now();
97
+ setActivitySeconds(0);
98
+ const timer = setInterval(() => {
99
+ setActivitySeconds(Math.floor((Date.now() - activityStartedAt.current) / 1000));
100
+ }, 250);
101
+ return () => clearInterval(timer);
102
+ }, [React, setup?.stage, status]);
103
+ function handleTerminalInput(value, key) {
104
+ if (key.ctrl && key.name === "c") {
105
+ if (setup) {
106
+ if (setup.stage === "saving") {
107
+ runtime.cancel();
108
+ dispatchRuntime({ type: "setup_action", action: { type: "back" } });
109
+ return;
110
+ }
111
+ app.exit();
112
+ return;
113
+ }
114
+ if (status === "thinking" || status === "cancelling") {
115
+ runtime.cancel();
116
+ dispatchRuntime({ type: "cancel_requested", label: "Stopping" });
117
+ return;
118
+ }
119
+ if (status === "approval" && approval) {
120
+ dispatchRuntime({ type: "approval_response", approved: false });
121
+ try {
122
+ runtime.respondToApproval(approval.action_id, false);
123
+ }
124
+ catch (error) {
125
+ showError(errorMessage(error));
126
+ }
127
+ return;
128
+ }
129
+ app.exit();
130
+ return;
131
+ }
132
+ if (setup) {
133
+ handleSetupInput(value, key);
134
+ return;
135
+ }
136
+ if (key.ctrl && key.name === "o") {
137
+ dispatchRuntime({
138
+ type: "transcript_action",
139
+ action: { type: "toggle_latest_result" },
140
+ });
141
+ return;
142
+ }
143
+ if (key.name === "pageup" || key.name === "pagedown") {
144
+ const pagingLayout = (0, ui_components_1.createTerminalLayout)(terminalSize.columns, terminalSize.rows, {
145
+ approval: approval !== null,
146
+ commandMenu: status === "idle" && commandMenu ? commandMenu : false,
147
+ prompt: editor.value,
148
+ promptCursor: editor.cursor,
149
+ });
150
+ setTranscriptOffset((current) => (0, transcript_1.moveTranscriptViewport)(transcript.entries, {
151
+ columns: pagingLayout.columns,
152
+ rows: pagingLayout.rows,
153
+ reservedRows: pagingLayout.reservedRows + (current > 0 ? 1 : 0),
154
+ }, current, key.name === "pageup" ? "older" : "newer"));
155
+ return;
156
+ }
157
+ if (status === "approval") {
158
+ handleApprovalInput(value, key);
159
+ return;
160
+ }
161
+ if (status === "cancelling") {
162
+ return;
163
+ }
164
+ if (status === "thinking" && key.name === "escape") {
165
+ runtime.cancel();
166
+ dispatchRuntime({ type: "cancel_requested", label: "Stopping" });
167
+ return;
168
+ }
169
+ if (key.name === "return" || key.name === "enter") {
170
+ if (key.shift || key.meta || key.sequence === "\n") {
171
+ setEditor((current) => (0, editor_1.insertInput)(current, "\n"));
172
+ return;
173
+ }
174
+ if (status === "thinking") {
175
+ submitSteering();
176
+ }
177
+ else if (commandMenu) {
178
+ const completion = (0, commands_1.commandCompletion)(commandMenu);
179
+ if (completion.endsWith(" ")) {
180
+ setEditor((current) => ({
181
+ ...current,
182
+ value: completion,
183
+ cursor: (0, editor_1.splitGraphemes)(completion).length,
184
+ historyIndex: null,
185
+ draft: "",
186
+ }));
187
+ setSelectedCommand(null);
188
+ }
189
+ else {
190
+ submit(completion);
191
+ }
192
+ }
193
+ else {
194
+ submit();
195
+ }
196
+ return;
197
+ }
198
+ if (key.name === "tab" && commandMenu) {
199
+ const completion = (0, commands_1.commandCompletion)(commandMenu);
200
+ setEditor((current) => ({
201
+ ...current,
202
+ value: completion,
203
+ cursor: (0, editor_1.splitGraphemes)(completion).length,
204
+ historyIndex: null,
205
+ draft: "",
206
+ }));
207
+ setSelectedCommand(null);
208
+ return;
209
+ }
210
+ if (key.name === "backspace") {
211
+ setEditor(editor_1.deleteBeforeCursor);
212
+ return;
213
+ }
214
+ if (key.name === "delete") {
215
+ setEditor(editor_1.deleteAtCursor);
216
+ return;
217
+ }
218
+ if (key.name === "left") {
219
+ setEditor((current) => (0, editor_1.moveCursor)(current, -1));
220
+ return;
221
+ }
222
+ if (key.name === "right") {
223
+ setEditor((current) => (0, editor_1.moveCursor)(current, 1));
224
+ return;
225
+ }
226
+ if (key.name === "home" || (key.ctrl && key.name === "a")) {
227
+ setEditor(editor_1.moveCursorToStart);
228
+ return;
229
+ }
230
+ if (key.name === "end" || (key.ctrl && key.name === "e")) {
231
+ setEditor(editor_1.moveCursorToEnd);
232
+ return;
233
+ }
234
+ if (key.name === "up") {
235
+ if (commandMenu) {
236
+ setSelectedCommand((0, commands_1.moveCommandSelection)(commandMenu, -1).selectedCommand);
237
+ return;
238
+ }
239
+ moveEditorVerticalOrHistory(-1);
240
+ return;
241
+ }
242
+ if (key.name === "down") {
243
+ if (commandMenu) {
244
+ setSelectedCommand((0, commands_1.moveCommandSelection)(commandMenu, 1).selectedCommand);
245
+ return;
246
+ }
247
+ moveEditorVerticalOrHistory(1);
248
+ return;
249
+ }
250
+ if (value && !key.ctrl && !key.meta) {
251
+ setEditor((current) => (0, editor_1.insertInput)(current, value));
252
+ }
253
+ }
254
+ function moveEditorVerticalOrHistory(direction) {
255
+ const promptLayout = (0, ui_components_1.createTerminalLayout)(terminalSize.columns, terminalSize.rows, {
256
+ approval: approval !== null,
257
+ commandMenu: false,
258
+ prompt: editor.value,
259
+ promptCursor: editor.cursor,
260
+ });
261
+ if ((0, editor_1.editorVisualLineCount)(editor.value, promptLayout.promptColumns) > 1) {
262
+ setEditor((current) => (0, editor_1.moveCursorVertical)(current, direction, promptLayout.promptColumns));
263
+ return;
264
+ }
265
+ setEditor((current) => (0, editor_1.navigateHistory)(current, direction));
266
+ }
267
+ function handleLifecycleEvent(event) {
268
+ dispatchRuntime({ type: "runtime_event", channel: "lifecycle", event });
269
+ }
270
+ function handleSetupInput(value, key) {
271
+ if (!setup || setup.stage === "saving") {
272
+ return;
273
+ }
274
+ if (key.name === "escape") {
275
+ if (setup.stage === "provider") {
276
+ app.exit();
277
+ }
278
+ else {
279
+ dispatchRuntime({ type: "setup_action", action: { type: "back" } });
280
+ }
281
+ return;
282
+ }
283
+ if (setup.stage === "provider") {
284
+ if (key.name === "up") {
285
+ dispatchRuntime({
286
+ type: "setup_action",
287
+ action: { type: "select", offset: -1 },
288
+ });
289
+ }
290
+ else if (key.name === "down") {
291
+ dispatchRuntime({
292
+ type: "setup_action",
293
+ action: { type: "select", offset: 1 },
294
+ });
295
+ }
296
+ else if (key.name === "return" || key.name === "enter") {
297
+ dispatchRuntime({ type: "setup_action", action: { type: "next" } });
298
+ }
299
+ return;
300
+ }
301
+ if (key.name === "return" || key.name === "enter") {
302
+ dispatchRuntime({ type: "setup_action", action: { type: "next" } });
303
+ return;
304
+ }
305
+ if (key.name === "backspace") {
306
+ updateSetupEditor(editor_1.deleteBeforeCursor);
307
+ return;
308
+ }
309
+ if (key.name === "delete") {
310
+ updateSetupEditor(editor_1.deleteAtCursor);
311
+ return;
312
+ }
313
+ if (key.name === "left") {
314
+ updateSetupEditor((current) => (0, editor_1.moveCursor)(current, -1));
315
+ return;
316
+ }
317
+ if (key.name === "right") {
318
+ updateSetupEditor((current) => (0, editor_1.moveCursor)(current, 1));
319
+ return;
320
+ }
321
+ if (key.name === "home" || (key.ctrl && key.name === "a")) {
322
+ updateSetupEditor(editor_1.moveCursorToStart);
323
+ return;
324
+ }
325
+ if (key.name === "end" || (key.ctrl && key.name === "e")) {
326
+ updateSetupEditor(editor_1.moveCursorToEnd);
327
+ return;
328
+ }
329
+ if (value && !key.ctrl && !key.meta) {
330
+ updateSetupEditor((current) => (0, editor_1.insertInput)(current, value.replace(/\n/g, " ")));
331
+ }
332
+ }
333
+ function updateSetupEditor(update) {
334
+ setRuntimeState((current) => {
335
+ if (!current.setup || !(0, provider_setup_1.isInputStage)(current.setup.stage)) {
336
+ return current;
337
+ }
338
+ return (0, app_state_1.appRuntimeReducer)(current, {
339
+ type: "setup_action",
340
+ action: { type: "edit", editor: update(current.setup.editor) },
341
+ });
342
+ });
343
+ }
344
+ function handleProviderEvent(event) {
345
+ dispatchRuntime({ type: "runtime_event", channel: "provider", event });
346
+ }
347
+ function submit(value = "") {
348
+ const source = value
349
+ ? {
350
+ ...editor,
351
+ value,
352
+ cursor: (0, editor_1.splitGraphemes)(value).length,
353
+ }
354
+ : editor;
355
+ const submission = (0, editor_1.submitInput)(source);
356
+ if (!submission.value) {
357
+ return;
358
+ }
359
+ const goal = submission.value;
360
+ if (["exit", "quit", ":q"].includes(goal.toLowerCase())) {
361
+ app.exit();
362
+ return;
363
+ }
364
+ setEditor(submission.state);
365
+ setSelectedCommand(null);
366
+ const command = isSessionCommandInput(goal);
367
+ dispatchRuntime({ type: "submit", text: goal, command });
368
+ if (command) {
369
+ runtime.command(goal, handleCommandEvent);
370
+ return;
371
+ }
372
+ runtime.run(goal, handleRuntimeEvent);
373
+ }
374
+ function submitSteering() {
375
+ const submission = (0, editor_1.submitInput)(editor);
376
+ if (!submission.value) {
377
+ return;
378
+ }
379
+ setEditor(submission.state);
380
+ setSelectedCommand(null);
381
+ try {
382
+ runtime.steer(submission.value);
383
+ }
384
+ catch (error) {
385
+ showError(errorMessage(error));
386
+ }
387
+ }
388
+ function handleCommandEvent(event) {
389
+ dispatchRuntime({ type: "runtime_event", channel: "command", event });
390
+ }
391
+ function handleApprovalInput(value, key) {
392
+ if (!approval) {
393
+ return;
394
+ }
395
+ const intent = (0, approval_choice_1.resolveApprovalInput)(approvalChoice, value, key.name);
396
+ if (!intent) {
397
+ return;
398
+ }
399
+ if (intent.type === "toggle_details") {
400
+ setShowApprovalDetails((current) => !current);
401
+ return;
402
+ }
403
+ if (intent.type === "select") {
404
+ setApprovalChoice(intent.choice);
405
+ return;
406
+ }
407
+ setShowApprovalDetails(false);
408
+ dispatchRuntime({ type: "approval_response", approved: intent.approved });
409
+ try {
410
+ runtime.respondToApproval(approval.action_id, intent.approved);
411
+ }
412
+ catch (error) {
413
+ showError(errorMessage(error));
414
+ }
415
+ }
416
+ function handleRuntimeEvent(event) {
417
+ dispatchRuntime({ type: "runtime_event", channel: "run", event });
418
+ }
419
+ function showError(message) {
420
+ dispatchRuntime({ type: "error", message });
421
+ }
422
+ if (setup) {
423
+ const layout = (0, ui_components_1.createTerminalLayout)(terminalSize.columns, terminalSize.rows, {
424
+ approval: false,
425
+ commandMenu: false,
426
+ });
427
+ if (layout.tooNarrow) {
428
+ return React.createElement(ui_components_1.NarrowTerminal, { React, Box, Text });
429
+ }
430
+ return React.createElement(Box, { flexDirection: "column", paddingX: layout.horizontalPadding }, React.createElement(ui_components_1.Header, {
431
+ React,
432
+ Box,
433
+ Text,
434
+ compact: layout.compact,
435
+ provider: null,
436
+ setup: true,
437
+ workspace: process.cwd(),
438
+ }), React.createElement(ui_components_1.ProviderSetupPanel, {
439
+ React,
440
+ Box,
441
+ Text,
442
+ frame,
443
+ setup,
444
+ }));
445
+ }
446
+ const layout = (0, ui_components_1.createTerminalLayout)(terminalSize.columns, terminalSize.rows, {
447
+ approval: approval
448
+ ? { ...approval, showDetails: showApprovalDetails }
449
+ : false,
450
+ commandMenu: status === "idle" && commandMenu ? commandMenu : false,
451
+ prompt: editor.value,
452
+ promptCursor: editor.cursor,
453
+ });
454
+ if (layout.tooNarrow) {
455
+ return React.createElement(ui_components_1.NarrowTerminal, { React, Box, Text });
456
+ }
457
+ const visibleTranscript = (0, transcript_1.selectTranscriptViewport)(transcript.entries, {
458
+ columns: layout.columns,
459
+ rows: layout.rows,
460
+ reservedRows: layout.reservedRows + (transcriptOffset > 0 ? 1 : 0),
461
+ }, transcriptOffset);
462
+ return React.createElement(Box, { flexDirection: "column", paddingX: layout.horizontalPadding }, React.createElement(ui_components_1.Header, {
463
+ React,
464
+ Box,
465
+ Text,
466
+ compact: layout.compact,
467
+ provider,
468
+ setup: false,
469
+ workspace: process.cwd(),
470
+ }), React.createElement(ui_components_1.TranscriptPosition, {
471
+ React,
472
+ Text,
473
+ newerCount: transcriptOffset,
474
+ }), React.createElement(ui_components_1.MessageList, { React, Box, Text, messages: visibleTranscript }), approval
475
+ ? React.createElement(ui_components_1.ApprovalPanel, {
476
+ React,
477
+ Box,
478
+ Text,
479
+ approval,
480
+ choice: approvalChoice,
481
+ compact: layout.compact,
482
+ showDetails: showApprovalDetails,
483
+ })
484
+ : null, React.createElement(ui_components_1.StatusLine, {
485
+ React,
486
+ Text,
487
+ elapsedSeconds: activitySeconds,
488
+ frame,
489
+ status,
490
+ statusText,
491
+ }), commandMenu && status === "idle"
492
+ ? React.createElement(ui_components_1.CommandPalette, {
493
+ React,
494
+ Box,
495
+ Text,
496
+ compact: layout.compact,
497
+ limit: layout.commandLimit,
498
+ menu: commandMenu,
499
+ })
500
+ : null, status === "starting"
501
+ ? null
502
+ : React.createElement(ui_components_1.PromptLine, {
503
+ React,
504
+ Box,
505
+ Text,
506
+ cursor: editor.cursor,
507
+ input: editor.value,
508
+ disabled: status === "cancelling" || status === "approval",
509
+ columns: layout.promptColumns,
510
+ maxRows: layout.promptRowLimit,
511
+ }));
512
+ }
513
+ function currentTerminalSize() {
514
+ return {
515
+ columns: process.stdout.columns || 80,
516
+ rows: process.stdout.rows || 24,
517
+ };
518
+ }
519
+ function errorMessage(error) {
520
+ return error instanceof Error ? error.message : String(error);
521
+ }
522
+ function isSessionCommandInput(value) {
523
+ return !value.includes("\n") && value.trimStart().startsWith("/");
524
+ }