@pi-unipi/notify 2.2.0 → 2.2.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/package.json +2 -10
- package/permission-prompt-message.ts +95 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-unipi/notify",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Cross-platform notification extension for Pi — native OS, Gotify, and Telegram notifications for agent lifecycle events",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -24,15 +24,7 @@
|
|
|
24
24
|
"typecheck": "tsc --noEmit"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
|
-
"
|
|
28
|
-
"tools.ts",
|
|
29
|
-
"commands.ts",
|
|
30
|
-
"settings.ts",
|
|
31
|
-
"events.ts",
|
|
32
|
-
"ask-user-prompt-message.ts",
|
|
33
|
-
"ntfy-config.ts",
|
|
34
|
-
"summarize.ts",
|
|
35
|
-
"types.ts",
|
|
27
|
+
"*.ts",
|
|
36
28
|
"platforms/*",
|
|
37
29
|
"tui/*",
|
|
38
30
|
"skills/**/*",
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @pi-unipi/notify — Internal helper: build notification message from
|
|
3
|
+
* permission prompt event payloads.
|
|
4
|
+
*
|
|
5
|
+
* Handles the `permissions:ui_prompt` broadcast emitted by
|
|
6
|
+
* `@gotgenes/pi-permission-system` immediately before a human-facing
|
|
7
|
+
* permission prompt is shown.
|
|
8
|
+
*
|
|
9
|
+
* @internal — not part of the public API. Shared by the event listener and tests.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export interface PermissionPromptEventPayload {
|
|
13
|
+
/** Correlation id for the permission request */
|
|
14
|
+
requestId?: string;
|
|
15
|
+
/** Originating subsystem of the request */
|
|
16
|
+
source?: string;
|
|
17
|
+
/** Surface being requested — e.g. "bash", "mcp", "read", "edit" */
|
|
18
|
+
surface?: string | null;
|
|
19
|
+
/** Command / path / tool / skill being requested */
|
|
20
|
+
value?: string | null;
|
|
21
|
+
/** Current or requesting agent, when available */
|
|
22
|
+
agentName?: string | null;
|
|
23
|
+
/** Human-readable permission prompt text */
|
|
24
|
+
message?: string;
|
|
25
|
+
/** Present for forwarded subagent prompts */
|
|
26
|
+
forwarding?: unknown;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
30
|
+
return value !== null && typeof value === "object";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Return a trimmed non-empty string, or `undefined` for anything else. */
|
|
34
|
+
function cleanString(value: unknown): string | undefined {
|
|
35
|
+
if (typeof value !== "string") return undefined;
|
|
36
|
+
const trimmed = value.trim();
|
|
37
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* `forwarding` is documented as "present for forwarded subagent prompts".
|
|
42
|
+
* Treat an explicitly falsy value (false / null / "" / 0) as not forwarded so
|
|
43
|
+
* that publishers which always include the key are handled correctly.
|
|
44
|
+
*/
|
|
45
|
+
function isForwarded(value: unknown): boolean {
|
|
46
|
+
if (value === undefined || value === null) return false;
|
|
47
|
+
if (typeof value === "boolean") return value;
|
|
48
|
+
if (typeof value === "string") return value.trim().length > 0;
|
|
49
|
+
if (typeof value === "number") return value !== 0;
|
|
50
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
51
|
+
if (isRecord(value)) return Object.keys(value).length > 0;
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Build the "what was requested" clause from `agentName` / `surface` / `value`.
|
|
57
|
+
* Returns `undefined` when there is nothing meaningful to say.
|
|
58
|
+
*/
|
|
59
|
+
function buildRequestClause(
|
|
60
|
+
agentName: string | undefined,
|
|
61
|
+
surface: string | undefined,
|
|
62
|
+
value: string | undefined,
|
|
63
|
+
): string | undefined {
|
|
64
|
+
if (!surface && !value) return undefined;
|
|
65
|
+
|
|
66
|
+
const who = agentName ?? "Agent";
|
|
67
|
+
|
|
68
|
+
if (surface && value) return `${who} requested ${surface} '${value}'.`;
|
|
69
|
+
if (surface) return `${who} requested ${surface} access.`;
|
|
70
|
+
return `${who} requested '${value}'.`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Build a human-readable notification message from a permission prompt payload. */
|
|
74
|
+
export function buildPermissionPromptMessage(payload: unknown): string {
|
|
75
|
+
const p = isRecord(payload) ? payload : {};
|
|
76
|
+
|
|
77
|
+
const agentName = cleanString(p.agentName);
|
|
78
|
+
const surface = cleanString(p.surface);
|
|
79
|
+
const value = cleanString(p.value);
|
|
80
|
+
const message = cleanString(p.message);
|
|
81
|
+
|
|
82
|
+
const parts: string[] = [];
|
|
83
|
+
|
|
84
|
+
const requestClause = buildRequestClause(agentName, surface, value);
|
|
85
|
+
if (requestClause) parts.push(requestClause);
|
|
86
|
+
|
|
87
|
+
// Only append the prompt text when it adds information beyond the clause.
|
|
88
|
+
if (message && message !== requestClause) parts.push(message);
|
|
89
|
+
|
|
90
|
+
if (parts.length === 0) parts.push("Pi is waiting for a permission decision.");
|
|
91
|
+
|
|
92
|
+
if (isForwarded(p.forwarding)) parts.push("(forwarded)");
|
|
93
|
+
|
|
94
|
+
return parts.join(" ");
|
|
95
|
+
}
|