@agent-api/cli 0.0.3 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/runtime/index.d.ts +1 -1
  2. package/dist/runtime/index.js +1 -1
  3. package/dist/tui/chat.d.ts +1 -6
  4. package/dist/tui/chat.js +1 -1292
  5. package/dist/tui/ink/app.d.ts +5 -0
  6. package/dist/tui/ink/app.js +308 -0
  7. package/dist/tui/ink/components.d.ts +10 -0
  8. package/dist/tui/ink/components.js +20 -0
  9. package/dist/tui/workbench.d.ts +22 -0
  10. package/dist/tui/workbench.js +51 -0
  11. package/dist/workbench/auth-controller.d.ts +43 -0
  12. package/dist/workbench/auth-controller.js +84 -0
  13. package/dist/workbench/auth-gate-controller.d.ts +62 -0
  14. package/dist/workbench/auth-gate-controller.js +231 -0
  15. package/dist/workbench/command-controller.d.ts +29 -0
  16. package/dist/workbench/command-controller.js +371 -0
  17. package/dist/workbench/conversation-controller.d.ts +32 -0
  18. package/dist/workbench/conversation-controller.js +53 -0
  19. package/dist/workbench/engine.d.ts +66 -0
  20. package/dist/workbench/engine.js +291 -0
  21. package/dist/workbench/input-controller.d.ts +44 -0
  22. package/dist/workbench/input-controller.js +71 -0
  23. package/dist/workbench/lifecycle-controller.d.ts +29 -0
  24. package/dist/workbench/lifecycle-controller.js +75 -0
  25. package/dist/workbench/local-controller.d.ts +19 -0
  26. package/dist/workbench/local-controller.js +89 -0
  27. package/dist/workbench/render-model.d.ts +46 -0
  28. package/dist/workbench/render-model.js +61 -0
  29. package/dist/workbench/runtime-controller.d.ts +12 -0
  30. package/dist/workbench/runtime-controller.js +57 -0
  31. package/dist/workbench/session.d.ts +27 -0
  32. package/dist/workbench/session.js +40 -0
  33. package/dist/workbench/settings-controller.d.ts +52 -0
  34. package/dist/workbench/settings-controller.js +120 -0
  35. package/dist/workbench/turn-controller.d.ts +25 -0
  36. package/dist/workbench/turn-controller.js +162 -0
  37. package/dist/workbench/view-model.d.ts +34 -0
  38. package/dist/workbench/view-model.js +121 -0
  39. package/package.json +1 -1
@@ -0,0 +1,121 @@
1
+ export function buildTranscriptViewModel(input) {
2
+ const lines = buildTranscriptLines(input.messages, {
3
+ activeAssistantMessageId: input.activeAssistantMessageId,
4
+ busy: input.busy,
5
+ renderMode: input.renderMode,
6
+ spinnerFrame: input.spinnerFrame,
7
+ width: input.width,
8
+ });
9
+ const maxOffset = Math.max(0, lines.length - input.viewportHeight);
10
+ const offset = Math.min(input.offset, maxOffset);
11
+ const start = Math.max(0, lines.length - input.viewportHeight - offset);
12
+ return {
13
+ lines,
14
+ visibleLines: lines.slice(start, start + input.viewportHeight),
15
+ maxOffset,
16
+ offset,
17
+ viewportHeight: input.viewportHeight,
18
+ };
19
+ }
20
+ export function buildTranscriptLines(messages, options) {
21
+ const lines = [];
22
+ for (const message of messages) {
23
+ const waiting = message.role === "assistant" && options.busy && message.id === options.activeAssistantMessageId && !message.text;
24
+ lines.push({
25
+ id: `${message.id}:role`,
26
+ text: roleLabel(message.role),
27
+ color: roleColor(message.role),
28
+ });
29
+ const content = message.text || (waiting ? `${spinnerGlyph(options.spinnerFrame)} thinking ${elapsedDots(options.spinnerFrame)}` : "");
30
+ const rendered = options.renderMode === "raw"
31
+ ? rawTranscriptLines(content, options.width)
32
+ : markdownTranscriptLines(content, options.width);
33
+ rendered.forEach((line, index) => {
34
+ lines.push({
35
+ ...line,
36
+ id: `${message.id}:line:${index}`,
37
+ });
38
+ });
39
+ if (message.role !== "system") {
40
+ lines.push({ id: `${message.id}:space`, text: "" });
41
+ }
42
+ }
43
+ return lines;
44
+ }
45
+ export function spinnerGlyph(frame) {
46
+ return ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"][frame % 10];
47
+ }
48
+ export function elapsedDots(frame) {
49
+ return ".".repeat((Math.floor(frame / 4) % 3) + 1);
50
+ }
51
+ function rawTranscriptLines(text, width) {
52
+ const source = text ? text.split(/\r?\n/) : [""];
53
+ return source.flatMap((line) => wrapTranscriptText(line, width).map((text) => ({ text })));
54
+ }
55
+ function markdownTranscriptLines(text, width) {
56
+ const source = text ? text.split(/\r?\n/) : [""];
57
+ const lines = [];
58
+ let inCode = false;
59
+ for (const sourceLine of source) {
60
+ if (/^\s*```/.test(sourceLine)) {
61
+ inCode = !inCode;
62
+ lines.push(...wrapTranscriptText(sourceLine, width).map((line) => ({ text: line, color: "gray" })));
63
+ continue;
64
+ }
65
+ lines.push(...markdownTranscriptLine(sourceLine, { code: inCode, width }));
66
+ }
67
+ return lines;
68
+ }
69
+ function markdownTranscriptLine(line, options) {
70
+ if (line === "")
71
+ return [{ text: "" }];
72
+ if (options.code)
73
+ return wrapTranscriptText(line, options.width).map((text) => ({ text, color: "gray" }));
74
+ const heading = /^(#{1,6})\s+(.+)$/.exec(line);
75
+ if (heading) {
76
+ const color = heading[1].length <= 2 ? "cyan" : "blue";
77
+ return wrapTranscriptText(heading[2], options.width).map((text) => ({ text, bold: true, color }));
78
+ }
79
+ if (/^\s*---+\s*$/.test(line))
80
+ return [{ text: "─".repeat(Math.min(48, options.width)), color: "gray" }];
81
+ const bullet = /^(\s*)[-*]\s+(.+)$/.exec(line);
82
+ if (bullet)
83
+ return wrapTranscriptText(`${bullet[1]}• ${bullet[2]}`, options.width).map((text) => ({ text }));
84
+ const numbered = /^(\s*)(\d+\.)\s+(.+)$/.exec(line);
85
+ if (numbered)
86
+ return wrapTranscriptText(`${numbered[1]}${numbered[2]} ${numbered[3]}`, options.width).map((text) => ({ text }));
87
+ const quote = /^\s*>\s?(.+)$/.exec(line);
88
+ if (quote)
89
+ return wrapTranscriptText(`│ ${quote[1]}`, options.width).map((text) => ({ text, color: "gray" }));
90
+ return wrapTranscriptText(line, options.width).map((text) => ({ text }));
91
+ }
92
+ function wrapTranscriptText(text, width) {
93
+ const max = Math.max(12, width);
94
+ if (text.length === 0)
95
+ return [""];
96
+ const lines = [];
97
+ let rest = text;
98
+ while (rest.length > max) {
99
+ const hard = rest.slice(0, max);
100
+ const softBreak = Math.max(hard.lastIndexOf(" "), hard.lastIndexOf("\t"));
101
+ const index = softBreak > Math.floor(max * 0.45) ? softBreak : max;
102
+ lines.push(rest.slice(0, index).trimEnd());
103
+ rest = rest.slice(index).trimStart();
104
+ }
105
+ lines.push(rest);
106
+ return lines;
107
+ }
108
+ function roleLabel(role) {
109
+ if (role === "user")
110
+ return "You";
111
+ if (role === "assistant")
112
+ return "Agent";
113
+ return "System";
114
+ }
115
+ function roleColor(role) {
116
+ if (role === "user")
117
+ return "green";
118
+ if (role === "assistant")
119
+ return "cyan";
120
+ return "gray";
121
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-api/cli",
3
- "version": "0.0.3",
3
+ "version": "0.1.0",
4
4
  "description": "First-class command line interface for Agent API",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/scalebox-dev/agent-tui#readme",