@alexleekt/pi-ask-user-glimpse 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +2 -2
- package/README.md +27 -5
- package/dist/index.html +13 -13
- package/fallback/terminal-prompt.ts +174 -152
- package/index.ts +492 -377
- package/package.json +78 -75
- package/shared/ask-user.ts +19 -19
- package/tool/ask-user.ts +436 -172
- package/tool/response-formatter.ts +104 -77
- package/types/glimpseui.d.ts +56 -53
|
@@ -1,102 +1,129 @@
|
|
|
1
1
|
import type { AgentToolResult } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
|
|
3
3
|
export interface AskResponse {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
kind: "selection" | "freeform" | "questionnaire";
|
|
5
|
+
selections?: string[];
|
|
6
|
+
comment?: string;
|
|
7
|
+
text?: string;
|
|
8
|
+
questionnaireDetails?: {
|
|
9
|
+
question: string;
|
|
10
|
+
answer: string;
|
|
11
|
+
kind: "selection" | "freeform";
|
|
12
|
+
comment?: string;
|
|
13
|
+
}[];
|
|
9
14
|
}
|
|
10
15
|
|
|
11
16
|
export interface AskToolDetails {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
question: string;
|
|
18
|
+
context?: string;
|
|
19
|
+
options: { title: string; description?: string }[];
|
|
20
|
+
response: AskResponse | null;
|
|
21
|
+
cancelled: boolean;
|
|
22
|
+
error?: string;
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
function normalizeKind(raw: unknown): AskResponse["kind"] {
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
if (raw === "freeform" || raw === "questionnaire") return raw;
|
|
27
|
+
return "selection";
|
|
23
28
|
}
|
|
24
29
|
|
|
25
|
-
function buildResponse(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
function buildResponse(
|
|
31
|
+
result: Record<string, unknown>,
|
|
32
|
+
kind: AskResponse["kind"],
|
|
33
|
+
): AskResponse {
|
|
34
|
+
if (kind === "freeform") {
|
|
35
|
+
return { kind, text: String(result.text ?? "").trim() };
|
|
36
|
+
}
|
|
29
37
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
if (kind === "questionnaire") {
|
|
39
|
+
return {
|
|
40
|
+
kind,
|
|
41
|
+
selections: Array.isArray(result.selections)
|
|
42
|
+
? result.selections.map(String)
|
|
43
|
+
: [],
|
|
44
|
+
questionnaireDetails: Array.isArray(result.questionnaireDetails)
|
|
45
|
+
? result.questionnaireDetails.map((d: unknown) => {
|
|
46
|
+
const entry = d as Record<string, unknown>;
|
|
47
|
+
return {
|
|
48
|
+
question: String(entry.question ?? ""),
|
|
49
|
+
answer: String(entry.answer ?? ""),
|
|
50
|
+
kind:
|
|
51
|
+
entry.kind === "freeform"
|
|
52
|
+
? "freeform"
|
|
53
|
+
: "selection",
|
|
54
|
+
comment: entry.comment
|
|
55
|
+
? String(entry.comment)
|
|
56
|
+
: undefined,
|
|
57
|
+
};
|
|
58
|
+
})
|
|
59
|
+
: [],
|
|
60
|
+
};
|
|
61
|
+
}
|
|
47
62
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
63
|
+
const selections = Array.isArray(result.selections)
|
|
64
|
+
? result.selections.map(String)
|
|
65
|
+
: result.selection
|
|
66
|
+
? [String(result.selection)]
|
|
67
|
+
: [];
|
|
53
68
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
69
|
+
return {
|
|
70
|
+
kind,
|
|
71
|
+
selections,
|
|
72
|
+
comment: result.comment ? String(result.comment) : undefined,
|
|
73
|
+
};
|
|
59
74
|
}
|
|
60
75
|
|
|
61
76
|
function responseToText(response: AskResponse): string {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
77
|
+
if (response.kind === "freeform") {
|
|
78
|
+
return response.text ?? "";
|
|
79
|
+
}
|
|
80
|
+
const selections = response.selections ?? [];
|
|
81
|
+
let text = selections.join(", ");
|
|
82
|
+
if (response.comment) {
|
|
83
|
+
text += `\n\nComment: ${response.comment}`;
|
|
84
|
+
}
|
|
85
|
+
return text;
|
|
71
86
|
}
|
|
72
87
|
|
|
73
88
|
export function formatResponse(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
89
|
+
question: string,
|
|
90
|
+
options: { title: string; description?: string }[],
|
|
91
|
+
result: Record<string, unknown> | null,
|
|
92
|
+
cancelled: boolean,
|
|
93
|
+
error?: string,
|
|
79
94
|
): AgentToolResult<AskToolDetails> {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
95
|
+
if (cancelled) {
|
|
96
|
+
return {
|
|
97
|
+
content: [{ type: "text", text: "Cancelled" }],
|
|
98
|
+
details: {
|
|
99
|
+
question,
|
|
100
|
+
options,
|
|
101
|
+
response: null,
|
|
102
|
+
cancelled: true,
|
|
103
|
+
error,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
86
107
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
108
|
+
if (!result) {
|
|
109
|
+
return {
|
|
110
|
+
content: [{ type: "text", text: "No response" }],
|
|
111
|
+
details: {
|
|
112
|
+
question,
|
|
113
|
+
options,
|
|
114
|
+
response: null,
|
|
115
|
+
cancelled: false,
|
|
116
|
+
error,
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
93
120
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
121
|
+
const kind = normalizeKind(result.kind);
|
|
122
|
+
const response = buildResponse(result, kind);
|
|
123
|
+
const text = responseToText(response);
|
|
97
124
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
125
|
+
return {
|
|
126
|
+
content: [{ type: "text", text }],
|
|
127
|
+
details: { question, options, response, cancelled: false, error },
|
|
128
|
+
};
|
|
102
129
|
}
|
package/types/glimpseui.d.ts
CHANGED
|
@@ -1,57 +1,60 @@
|
|
|
1
1
|
declare module "glimpseui" {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
export interface GlimpseWindowOptions {
|
|
3
|
+
width?: number;
|
|
4
|
+
height?: number;
|
|
5
|
+
title?: string;
|
|
6
|
+
frameless?: boolean;
|
|
7
|
+
floating?: boolean;
|
|
8
|
+
transparent?: boolean;
|
|
9
|
+
clickThrough?: boolean;
|
|
10
|
+
noDock?: boolean;
|
|
11
|
+
hidden?: boolean;
|
|
12
|
+
autoClose?: boolean;
|
|
13
|
+
openLinks?: boolean;
|
|
14
|
+
openLinksApp?: string;
|
|
15
|
+
followCursor?: boolean;
|
|
16
|
+
x?: number;
|
|
17
|
+
y?: number;
|
|
18
|
+
cursorOffset?: { x?: number; y?: number };
|
|
19
|
+
cursorAnchor?: string;
|
|
20
|
+
followMode?: "snap" | "spring";
|
|
21
|
+
timeout?: number;
|
|
22
|
+
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
export interface GlimpseWindow {
|
|
25
|
+
on(event: "message", handler: (data: unknown) => void): void;
|
|
26
|
+
on(event: "closed", handler: () => void): void;
|
|
27
|
+
on(event: "error", handler: (err: Error) => void): void;
|
|
28
|
+
send(js: string): void;
|
|
29
|
+
setHTML(html: string): void;
|
|
30
|
+
show(options?: { title?: string }): void;
|
|
31
|
+
close(): void;
|
|
32
|
+
loadFile(path: string): void;
|
|
33
|
+
getInfo(): unknown;
|
|
34
|
+
followCursor(enabled: boolean, anchor?: string, mode?: string): void;
|
|
35
|
+
readonly info: unknown;
|
|
36
|
+
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
38
|
+
export function open(
|
|
39
|
+
html: string,
|
|
40
|
+
options?: GlimpseWindowOptions,
|
|
41
|
+
): GlimpseWindow;
|
|
42
|
+
export function prompt(
|
|
43
|
+
html: string,
|
|
44
|
+
options?: GlimpseWindowOptions,
|
|
45
|
+
): Promise<unknown | null>;
|
|
46
|
+
export function statusItem(
|
|
47
|
+
html: string,
|
|
48
|
+
options?: GlimpseWindowOptions,
|
|
49
|
+
): GlimpseWindow;
|
|
50
|
+
export function getNativeHostInfo(): {
|
|
51
|
+
path: string;
|
|
52
|
+
platform: string;
|
|
53
|
+
buildHint: string;
|
|
54
|
+
};
|
|
55
|
+
export function supportsFollowCursor(): boolean;
|
|
56
|
+
export function getFollowCursorSupport(): {
|
|
57
|
+
supported: boolean;
|
|
58
|
+
reason?: string;
|
|
59
|
+
};
|
|
57
60
|
}
|