@alexleekt/pi-ask-user-glimpse 0.2.1 → 0.3.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.
@@ -1,102 +1,129 @@
1
1
  import type { AgentToolResult } from "@earendil-works/pi-coding-agent";
2
2
 
3
3
  export interface AskResponse {
4
- kind: "selection" | "freeform" | "questionnaire";
5
- selections?: string[];
6
- comment?: string;
7
- text?: string;
8
- questionnaireDetails?: { question: string; answer: string; kind: "selection" | "freeform"; comment?: string }[];
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
- question: string;
13
- context?: string;
14
- options: { title: string; description?: string }[];
15
- response: AskResponse | null;
16
- cancelled: boolean;
17
- error?: string;
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
- if (raw === "freeform" || raw === "questionnaire") return raw;
22
- return "selection";
26
+ if (raw === "freeform" || raw === "questionnaire") return raw;
27
+ return "selection";
23
28
  }
24
29
 
25
- function buildResponse(result: Record<string, unknown>, kind: AskResponse["kind"]): AskResponse {
26
- if (kind === "freeform") {
27
- return { kind, text: String(result.text ?? "").trim() };
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
- if (kind === "questionnaire") {
31
- return {
32
- kind,
33
- selections: Array.isArray(result.selections) ? result.selections.map(String) : [],
34
- questionnaireDetails: Array.isArray(result.questionnaireDetails)
35
- ? result.questionnaireDetails.map((d: unknown) => {
36
- const entry = d as Record<string, unknown>;
37
- return {
38
- question: String(entry.question ?? ""),
39
- answer: String(entry.answer ?? ""),
40
- kind: entry.kind === "freeform" ? "freeform" : "selection",
41
- comment: entry.comment ? String(entry.comment) : undefined,
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
- const selections = Array.isArray(result.selections)
49
- ? result.selections.map(String)
50
- : result.selection
51
- ? [String(result.selection)]
52
- : [];
63
+ const selections = Array.isArray(result.selections)
64
+ ? result.selections.map(String)
65
+ : result.selection
66
+ ? [String(result.selection)]
67
+ : [];
53
68
 
54
- return {
55
- kind,
56
- selections,
57
- comment: result.comment ? String(result.comment) : undefined,
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
- if (response.kind === "freeform") {
63
- return response.text ?? "";
64
- }
65
- const selections = response.selections ?? [];
66
- let text = selections.join(", ");
67
- if (response.comment) {
68
- text += `\n\nComment: ${response.comment}`;
69
- }
70
- return text;
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
- question: string,
75
- options: { title: string; description?: string }[],
76
- result: Record<string, unknown> | null,
77
- cancelled: boolean,
78
- error?: string,
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
- if (cancelled) {
81
- return {
82
- content: [{ type: "text", text: "Cancelled" }],
83
- details: { question, options, response: null, cancelled: true, error },
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
- if (!result) {
88
- return {
89
- content: [{ type: "text", text: "No response" }],
90
- details: { question, options, response: null, cancelled: false, error },
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
- const kind = normalizeKind(result.kind);
95
- const response = buildResponse(result, kind);
96
- const text = responseToText(response);
121
+ const kind = normalizeKind(result.kind);
122
+ const response = buildResponse(result, kind);
123
+ const text = responseToText(response);
97
124
 
98
- return {
99
- content: [{ type: "text", text }],
100
- details: { question, options, response, cancelled: false, error },
101
- };
125
+ return {
126
+ content: [{ type: "text", text }],
127
+ details: { question, options, response, cancelled: false, error },
128
+ };
102
129
  }
@@ -1,57 +1,60 @@
1
1
  declare module "glimpseui" {
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
- }
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
- 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
- }
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
- export function open(html: string, options?: GlimpseWindowOptions): GlimpseWindow;
39
- export function prompt(
40
- html: string,
41
- options?: GlimpseWindowOptions,
42
- ): Promise<unknown | null>;
43
- export function statusItem(
44
- html: string,
45
- options?: GlimpseWindowOptions,
46
- ): GlimpseWindow;
47
- export function getNativeHostInfo(): {
48
- path: string;
49
- platform: string;
50
- buildHint: string;
51
- };
52
- export function supportsFollowCursor(): boolean;
53
- export function getFollowCursorSupport(): {
54
- supported: boolean;
55
- reason?: string;
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
  }