@adeildo/pi-look 6.0.0 → 6.0.1
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.
- package/assets/preview.png +0 -0
- package/package.json +2 -2
- package/src/ui/tool-frame.ts +25 -9
package/assets/preview.png
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adeildo/pi-look",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "Pi's start screen, a framed editor and the footer, redrawn around the data that matters and painted only with the theme's colours.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@adeildo/pi-kit": "6.0.
|
|
41
|
+
"@adeildo/pi-kit": "6.0.1",
|
|
42
42
|
"diff": "8.0.4"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
package/src/ui/tool-frame.ts
CHANGED
|
@@ -24,13 +24,14 @@ import { editBody } from "../render/diff.ts";
|
|
|
24
24
|
import { tabs } from "../render/format.ts";
|
|
25
25
|
import { type IconSet, glyphsOf } from "../render/glyphs.ts";
|
|
26
26
|
import { pathLine, type Stream, STREAMERS } from "../render/streaming.ts";
|
|
27
|
-
import { stateMark, toolIcon, toolLabel } from "../render/tools.ts";
|
|
27
|
+
import { type CallPhase, stateMark, toolIcon, toolLabel } from "../render/tools.ts";
|
|
28
28
|
import { icons } from "../settings.ts";
|
|
29
29
|
|
|
30
|
-
type Phase =
|
|
30
|
+
type Phase = CallPhase | "interrupted";
|
|
31
31
|
|
|
32
32
|
const PHASE_COLORS = {
|
|
33
33
|
writing: "muted",
|
|
34
|
+
interrupted: "muted",
|
|
34
35
|
waiting: "accent",
|
|
35
36
|
running: "accent",
|
|
36
37
|
done: "success",
|
|
@@ -43,6 +44,7 @@ const RESULT_PREVIEW_LINES = 10;
|
|
|
43
44
|
export function registerToolFrames(scope: FeatureScope): void {
|
|
44
45
|
const redraws = new Map<string, () => void>();
|
|
45
46
|
const written = new Map<string, number>();
|
|
47
|
+
const streamed = new Set<string>();
|
|
46
48
|
// Asked for on every drawing, and it changes only with the setting.
|
|
47
49
|
const set = glyphsOf(() => icons.get(scope));
|
|
48
50
|
CALLS_FRAMED.provide(scope, () => true);
|
|
@@ -51,7 +53,11 @@ export function registerToolFrames(scope: FeatureScope): void {
|
|
|
51
53
|
scope.on("message_update", (event) => {
|
|
52
54
|
const update = event.assistantMessageEvent;
|
|
53
55
|
if (update.type === "toolcall_end") written.set(update.toolCall.id, Date.now());
|
|
56
|
+
if (event.message.role !== "assistant") return;
|
|
57
|
+
for (const block of event.message.content)
|
|
58
|
+
if (block.type === "toolCall") streamed.add(block.id);
|
|
54
59
|
});
|
|
60
|
+
scope.on("message_end", () => streamed.clear());
|
|
55
61
|
|
|
56
62
|
scope.registerToolRenderer((toolName, next) =>
|
|
57
63
|
framed(scope, next(), {
|
|
@@ -59,6 +65,7 @@ export function registerToolFrames(scope: FeatureScope): void {
|
|
|
59
65
|
set: () => set().set,
|
|
60
66
|
redraws,
|
|
61
67
|
written,
|
|
68
|
+
streamed,
|
|
62
69
|
}),
|
|
63
70
|
);
|
|
64
71
|
}
|
|
@@ -68,6 +75,7 @@ interface FrameContext {
|
|
|
68
75
|
set: () => IconSet;
|
|
69
76
|
redraws: Map<string, () => void>;
|
|
70
77
|
written: Map<string, number>;
|
|
78
|
+
streamed: ReadonlySet<string>;
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
function framed(
|
|
@@ -100,10 +108,12 @@ function framed(
|
|
|
100
108
|
context.argsComplete ||
|
|
101
109
|
context.executionStarted ||
|
|
102
110
|
!context.isPartial;
|
|
103
|
-
if
|
|
104
|
-
|
|
111
|
+
// Pi replays a call that has no result as if the model were still writing it.
|
|
112
|
+
const interrupted = !done && !frame.streamed.has(context.toolCallId);
|
|
113
|
+
if (done) clock.writtenAt ??= ended ?? now;
|
|
114
|
+
else if (!interrupted) clock.writingAt ??= now;
|
|
105
115
|
if (context.executionStarted) clock.startedAt ??= now;
|
|
106
|
-
const writing = clock.writtenAt === undefined;
|
|
116
|
+
const writing = !interrupted && clock.writtenAt === undefined;
|
|
107
117
|
const ruling = RULING.current(scope, context.toolCallId);
|
|
108
118
|
|
|
109
119
|
// Pi hands every call its arguments again on each piece the model writes, so an unchanged call keeps its frame.
|
|
@@ -112,6 +122,7 @@ function framed(
|
|
|
112
122
|
theme,
|
|
113
123
|
ruling,
|
|
114
124
|
writing,
|
|
125
|
+
interrupted,
|
|
115
126
|
context.expanded,
|
|
116
127
|
context.isPartial,
|
|
117
128
|
context.executionStarted,
|
|
@@ -151,7 +162,7 @@ function framed(
|
|
|
151
162
|
body,
|
|
152
163
|
ruling,
|
|
153
164
|
expanded: context.expanded,
|
|
154
|
-
phase: phaseOf(context, writing),
|
|
165
|
+
phase: interrupted ? "interrupted" : phaseOf(context, writing),
|
|
155
166
|
mark: stateMark,
|
|
156
167
|
set: frame.set,
|
|
157
168
|
progress: writing ? stream?.progress : undefined,
|
|
@@ -300,7 +311,7 @@ class CallFrame implements Component {
|
|
|
300
311
|
const phase = this.parts.phase ?? (running ? "running" : undefined);
|
|
301
312
|
// Read on every drawing, so the time goes on while nothing new arrives.
|
|
302
313
|
const time = clock === undefined || phase === undefined ? undefined : timeOf(phase, clock);
|
|
303
|
-
const mark = phase === undefined ? undefined : this.parts.mark(phase, this.parts.set());
|
|
314
|
+
const mark = phase === undefined ? undefined : this.parts.mark(markOf(phase), this.parts.set());
|
|
304
315
|
const body = this.parts.body.render(room(width));
|
|
305
316
|
const progress = this.parts.progress?.join("\u0000");
|
|
306
317
|
const drawn = { width, body, rest: [ruling, expanded, phase, time, progress, mark] };
|
|
@@ -328,7 +339,7 @@ interface CallParts {
|
|
|
328
339
|
ruling?: CallRuling;
|
|
329
340
|
expanded: boolean;
|
|
330
341
|
phase?: Phase;
|
|
331
|
-
mark: (phase:
|
|
342
|
+
mark: (phase: CallPhase, set: IconSet) => string;
|
|
332
343
|
set: () => IconSet;
|
|
333
344
|
progress?: readonly string[];
|
|
334
345
|
clock?: Clock;
|
|
@@ -367,7 +378,7 @@ class ResultFrame implements Component {
|
|
|
367
378
|
render(width: number): string[] {
|
|
368
379
|
const { theme, phase, wrote, quiet, images } = this.parts;
|
|
369
380
|
const time = this.parts.elapsed;
|
|
370
|
-
const mark = stateMark(phase, this.parts.set());
|
|
381
|
+
const mark = stateMark(markOf(phase), this.parts.set());
|
|
371
382
|
const body = this.parts.body.render(room(width));
|
|
372
383
|
const drawn = { width, body, rest: [phase, mark, time, wrote, images, quiet] };
|
|
373
384
|
if (unchanged(this.#drawn, drawn)) return this.#drawn.lines;
|
|
@@ -520,7 +531,12 @@ function ranFor(clock: Clock, running: boolean): string | undefined {
|
|
|
520
531
|
return end === undefined ? undefined : elapsed(end - clock.startedAt);
|
|
521
532
|
}
|
|
522
533
|
|
|
534
|
+
function markOf(phase: Phase): CallPhase {
|
|
535
|
+
return phase === "interrupted" ? "failed" : phase;
|
|
536
|
+
}
|
|
537
|
+
|
|
523
538
|
function timeOf(phase: Phase, clock: Clock): string | undefined {
|
|
539
|
+
if (phase === "interrupted") return undefined;
|
|
524
540
|
if (phase === "running") return ranFor(clock, true);
|
|
525
541
|
const from = phase === "waiting" ? clock.writtenAt : clock.writingAt;
|
|
526
542
|
return from === undefined ? undefined : elapsed(Date.now() - from);
|