trusted-user-agent 0.0.0-stage → 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/LICENSE +21 -0
- package/dist/acp/agent.js +601 -0
- package/dist/acp/backend.js +2 -0
- package/dist/acp/config-options.js +26 -0
- package/dist/acp/mock-backend.js +277 -0
- package/dist/acp/sdk-backend.js +495 -0
- package/dist/browser/mcp-acp-client.js +81 -0
- package/dist/browser/provider.js +1045 -0
- package/dist/browser/schemas.js +221 -0
- package/dist/capability-registry.js +92 -0
- package/dist/client-heartbeat.js +118 -0
- package/dist/compose/schemas.js +90 -0
- package/dist/contacts/schemas.js +26 -0
- package/dist/installer/cli.js +70 -0
- package/dist/installer/common.js +93 -0
- package/dist/installer/index.js +341 -0
- package/dist/installer/mcp-clients.js +555 -0
- package/dist/installer/mcp.js +166 -0
- package/dist/installer/platforms.js +277 -0
- package/dist/logger.js +54 -0
- package/dist/mail/schemas.js +98 -0
- package/dist/mutation/schemas.js +31 -0
- package/dist/native-host/broker-ipc.js +344 -0
- package/dist/native-host/framing.js +76 -0
- package/dist/native-host/main.js +520 -0
- package/dist/native-host/mcp-server.js +322 -0
- package/dist/native-host/mcp-stdio-bridge.js +179 -0
- package/dist/native-host/mcp-stdio-main.js +13 -0
- package/dist/native-host/relay.js +84 -0
- package/dist/native-host/skills-startup.js +167 -0
- package/dist/native-host/transport.js +248 -0
- package/dist/permission-store.js +207 -0
- package/dist/repl/fs-sandbox.js +187 -0
- package/dist/repl/provider.js +252 -0
- package/dist/repl/runtime.js +436 -0
- package/dist/repl/types.js +10 -0
- package/dist/repl/worker.js +731 -0
- package/dist/skills/extension.js +99 -0
- package/dist/skills/grants-file.js +145 -0
- package/dist/skills/isolated-runner.js +259 -0
- package/dist/skills/mock-session-factory.js +49 -0
- package/dist/skills/package-roots.js +25 -0
- package/dist/skills/pi-bridge.js +8 -0
- package/dist/skills/pi-integration.js +110 -0
- package/dist/skills/planner.js +128 -0
- package/dist/skills/registry.js +104 -0
- package/dist/skills/skills-protocol.js +253 -0
- package/dist/skills/skills-service.js +195 -0
- package/dist/tool-bridge.js +8 -0
- package/dist/workspace.js +70 -0
- package/extensions/pi-browser-tools.ts +65 -0
- package/extensions/pi-browser.ts +60 -0
- package/extensions/pi-skills.ts +14 -0
- package/native/pi-agent-host +2 -0
- package/native/pi-browser-host +5 -0
- package/native/pi-browser-host.cmd +3 -0
- package/node_modules/@pi-browser/protocol/.bundled-by-trusted-user-agent +0 -0
- package/node_modules/@pi-browser/protocol/dist/acp.d.ts +10 -0
- package/node_modules/@pi-browser/protocol/dist/acp.js +9 -0
- package/node_modules/@pi-browser/protocol/dist/browser-tools.d.ts +33 -0
- package/node_modules/@pi-browser/protocol/dist/browser-tools.js +478 -0
- package/node_modules/@pi-browser/protocol/dist/callers.d.ts +108 -0
- package/node_modules/@pi-browser/protocol/dist/callers.js +56 -0
- package/node_modules/@pi-browser/protocol/dist/compose-tools.d.ts +30 -0
- package/node_modules/@pi-browser/protocol/dist/compose-tools.js +175 -0
- package/node_modules/@pi-browser/protocol/dist/contacts-tools.d.ts +23 -0
- package/node_modules/@pi-browser/protocol/dist/contacts-tools.js +63 -0
- package/node_modules/@pi-browser/protocol/dist/control-tools.d.ts +32 -0
- package/node_modules/@pi-browser/protocol/dist/control-tools.js +201 -0
- package/node_modules/@pi-browser/protocol/dist/errors.d.ts +63 -0
- package/node_modules/@pi-browser/protocol/dist/errors.js +109 -0
- package/node_modules/@pi-browser/protocol/dist/index.d.ts +16 -0
- package/node_modules/@pi-browser/protocol/dist/index.js +16 -0
- package/node_modules/@pi-browser/protocol/dist/integration.d.ts +409 -0
- package/node_modules/@pi-browser/protocol/dist/integration.js +260 -0
- package/node_modules/@pi-browser/protocol/dist/jsonrpc.d.ts +33 -0
- package/node_modules/@pi-browser/protocol/dist/jsonrpc.js +31 -0
- package/node_modules/@pi-browser/protocol/dist/mail-mutation-tools.d.ts +27 -0
- package/node_modules/@pi-browser/protocol/dist/mail-mutation-tools.js +88 -0
- package/node_modules/@pi-browser/protocol/dist/mail-tools.d.ts +133 -0
- package/node_modules/@pi-browser/protocol/dist/mail-tools.js +245 -0
- package/node_modules/@pi-browser/protocol/dist/permission.d.ts +113 -0
- package/node_modules/@pi-browser/protocol/dist/permission.js +257 -0
- package/node_modules/@pi-browser/protocol/dist/skills.d.ts +304 -0
- package/node_modules/@pi-browser/protocol/dist/skills.js +473 -0
- package/node_modules/@pi-browser/protocol/dist/tool-capabilities.d.ts +18 -0
- package/node_modules/@pi-browser/protocol/dist/tool-capabilities.js +52 -0
- package/node_modules/@pi-browser/protocol/dist/transport.d.ts +17 -0
- package/node_modules/@pi-browser/protocol/dist/transport.js +17 -0
- package/node_modules/@pi-browser/protocol/package.json +14 -0
- package/package.json +71 -6
- package/skills/browser-walk/SKILL.md +98 -0
- package/README.md +0 -3
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeBox parameter schemas for the browser tools.
|
|
3
|
+
*
|
|
4
|
+
* These MUST stay in sync with the JSON Schemas in
|
|
5
|
+
* @pi-browser/protocol (browser-tools.ts) — the JSON is what the Firefox
|
|
6
|
+
* side serves over MCP, the TypeBox schemas are what Pi validates against.
|
|
7
|
+
* test/tool-schemas.test.ts enforces the sync.
|
|
8
|
+
*/
|
|
9
|
+
import { Type } from "typebox";
|
|
10
|
+
import { BROWSER_FRAME_DESCRIPTION, BROWSER_TOOLS, CONTROL_TOOLS, REPL_TOOLS } from "@pi-browser/protocol";
|
|
11
|
+
const empty = () => Type.Object({}, { additionalProperties: false });
|
|
12
|
+
/**
|
|
13
|
+
* Shared `frame` parameter for the content-frame tools. MUST stay in sync
|
|
14
|
+
* with FRAME_PROPERTY in @pi-browser/protocol (enforced by
|
|
15
|
+
* test/tool-schemas.test.ts — the description is imported, not duplicated).
|
|
16
|
+
*/
|
|
17
|
+
const frame = () => Type.Union([Type.Number(), Type.String()], { description: BROWSER_FRAME_DESCRIPTION });
|
|
18
|
+
const SCHEMAS = {
|
|
19
|
+
browser_get_page: empty(),
|
|
20
|
+
browser_get_selection: Type.Object({
|
|
21
|
+
frame: Type.Optional(frame()),
|
|
22
|
+
}, { additionalProperties: false }),
|
|
23
|
+
browser_get_dom: Type.Object({
|
|
24
|
+
maxElements: Type.Optional(Type.Number({
|
|
25
|
+
description: "Maximum number of elements to return (default 600, hard cap 2000).",
|
|
26
|
+
})),
|
|
27
|
+
frame: Type.Optional(frame()),
|
|
28
|
+
}, { additionalProperties: false }),
|
|
29
|
+
browser_screenshot: Type.Object({
|
|
30
|
+
format: Type.Optional(Type.Union([Type.Literal("png"), Type.Literal("jpeg")], {
|
|
31
|
+
description: "Image format (default png).",
|
|
32
|
+
})),
|
|
33
|
+
quality: Type.Optional(Type.Number({ description: "JPEG quality 1-100 (jpeg only, default 80)." })),
|
|
34
|
+
}, { additionalProperties: false }),
|
|
35
|
+
browser_reload: empty(),
|
|
36
|
+
browser_click: Type.Object({
|
|
37
|
+
ref: Type.String({ description: "Element reference, e.g. el-183 (from browser_get_dom)." }),
|
|
38
|
+
frame: Type.Optional(frame()),
|
|
39
|
+
}, { additionalProperties: false, required: ["ref"] }),
|
|
40
|
+
browser_type: Type.Object({
|
|
41
|
+
ref: Type.String({ description: "Element reference, e.g. el-183 (from browser_get_dom)." }),
|
|
42
|
+
text: Type.String({ description: "Text to type." }),
|
|
43
|
+
submit: Type.Optional(Type.Boolean({ description: "Submit the element's form after typing (default false)." })),
|
|
44
|
+
frame: Type.Optional(frame()),
|
|
45
|
+
}, { additionalProperties: false, required: ["ref", "text"] }),
|
|
46
|
+
browser_wait_for: Type.Object({
|
|
47
|
+
selector: Type.String({ description: "CSS selector to wait for." }),
|
|
48
|
+
state: Type.Optional(Type.Union([Type.Literal("visible"), Type.Literal("hidden")], {
|
|
49
|
+
description: "Wait until the element is visible (default) or hidden.",
|
|
50
|
+
})),
|
|
51
|
+
timeoutMs: Type.Optional(Type.Number({ description: "Maximum wait in milliseconds (default 10000, max 60000)." })),
|
|
52
|
+
frame: Type.Optional(frame()),
|
|
53
|
+
}, { additionalProperties: false, required: ["selector"] }),
|
|
54
|
+
browser_evaluate: Type.Object({
|
|
55
|
+
expression: Type.String({
|
|
56
|
+
description: "JavaScript expression or function, e.g. \"document.title\" or \"(sel) => document.querySelector(sel)?.value\".",
|
|
57
|
+
}),
|
|
58
|
+
arg: Type.Optional(Type.Any({
|
|
59
|
+
description: "Optional JSON value passed as the single argument when the expression is a function.",
|
|
60
|
+
})),
|
|
61
|
+
frame: Type.Optional(frame()),
|
|
62
|
+
}, { additionalProperties: false, required: ["expression"] }),
|
|
63
|
+
browser_get_accessibility_tree: Type.Object({
|
|
64
|
+
format: Type.Optional(Type.Union([Type.Literal("text"), Type.Literal("tree"), Type.Literal("nodes")], {
|
|
65
|
+
description: '"text" (default) = the indented outline; "tree" = nested node objects ({role, name, children[]}); "nodes" = flat structured node list with refs and rects.',
|
|
66
|
+
})),
|
|
67
|
+
maxNodes: Type.Optional(Type.Number({
|
|
68
|
+
description: "Maximum outline nodes to return (default 300, hard cap 2000).",
|
|
69
|
+
})),
|
|
70
|
+
maxDepth: Type.Optional(Type.Number({
|
|
71
|
+
description: "Maximum outline depth (default 60, hard cap 80).",
|
|
72
|
+
})),
|
|
73
|
+
frame: Type.Optional(frame()),
|
|
74
|
+
}, { additionalProperties: false }),
|
|
75
|
+
browser_get_console: Type.Object({
|
|
76
|
+
level: Type.Optional(Type.Union([
|
|
77
|
+
Type.Literal("all"),
|
|
78
|
+
Type.Literal("error"),
|
|
79
|
+
Type.Literal("warn"),
|
|
80
|
+
Type.Literal("log"),
|
|
81
|
+
Type.Literal("info"),
|
|
82
|
+
Type.Literal("debug"),
|
|
83
|
+
], {
|
|
84
|
+
description: 'Only messages at this level (default "all"); "error" includes window errors and unhandled rejections.',
|
|
85
|
+
})),
|
|
86
|
+
limit: Type.Optional(Type.Number({ description: "Maximum messages to return, newest first (default 50, max 200)." })),
|
|
87
|
+
since: Type.Optional(Type.Number({ description: "Only messages captured at or after this Unix timestamp (ms)." })),
|
|
88
|
+
clear: Type.Optional(Type.Boolean({ description: "Clear the captured buffer after reading (default false)." })),
|
|
89
|
+
frame: Type.Optional(frame()),
|
|
90
|
+
}, { additionalProperties: false }),
|
|
91
|
+
browser_get_network: Type.Object({
|
|
92
|
+
filter: Type.Optional(Type.String({ description: "Only requests whose URL contains this substring (case-insensitive)." })),
|
|
93
|
+
method: Type.Optional(Type.String({ description: 'Only requests with this HTTP method, e.g. "POST".' })),
|
|
94
|
+
errorsOnly: Type.Optional(Type.Boolean({
|
|
95
|
+
description: "Only failed requests or responses with status >= 400 (default false).",
|
|
96
|
+
})),
|
|
97
|
+
limit: Type.Optional(Type.Number({ description: "Maximum requests to return, newest first (default 50, max 200)." })),
|
|
98
|
+
}, { additionalProperties: false }),
|
|
99
|
+
browser_element_at: Type.Object({
|
|
100
|
+
x: Type.Number({ description: "X coordinate in CSS pixels from the viewport's left edge." }),
|
|
101
|
+
y: Type.Number({ description: "Y coordinate in CSS pixels from the viewport's top edge." }),
|
|
102
|
+
frame: Type.Optional(frame()),
|
|
103
|
+
}, { additionalProperties: false, required: ["x", "y"] }),
|
|
104
|
+
browser_navigate: Type.Object({
|
|
105
|
+
url: Type.String({ description: 'Absolute URL to navigate to, e.g. "http://localhost:5173/login".' }),
|
|
106
|
+
timeoutMs: Type.Optional(Type.Number({
|
|
107
|
+
description: "Max milliseconds to wait for the load to settle (default 30000, cap 120000).",
|
|
108
|
+
})),
|
|
109
|
+
}, { additionalProperties: false, required: ["url"] }),
|
|
110
|
+
browser_download: Type.Object({
|
|
111
|
+
url: Type.String({
|
|
112
|
+
description: 'Absolute http(s) URL to download, e.g. the src of an image on the current page.',
|
|
113
|
+
}),
|
|
114
|
+
maxBytes: Type.Optional(Type.Number({
|
|
115
|
+
description: "Maximum bytes to download (default 10485760, cap 52428800). Larger files are rejected, not truncated.",
|
|
116
|
+
})),
|
|
117
|
+
}, { additionalProperties: false, required: ["url"] }),
|
|
118
|
+
browser_click_at: Type.Object({
|
|
119
|
+
x: Type.Number({ description: "X coordinate in CSS pixels from the viewport's left edge." }),
|
|
120
|
+
y: Type.Number({ description: "Y coordinate in CSS pixels from the viewport's top edge." }),
|
|
121
|
+
frame: Type.Optional(frame()),
|
|
122
|
+
}, { additionalProperties: false, required: ["x", "y"] }),
|
|
123
|
+
browser_focus: Type.Object({
|
|
124
|
+
ref: Type.String({ description: "Element reference, e.g. el-183." }),
|
|
125
|
+
frame: Type.Optional(frame()),
|
|
126
|
+
}, { additionalProperties: false, required: ["ref"] }),
|
|
127
|
+
browser_scroll: Type.Object({
|
|
128
|
+
ref: Type.String({ description: "Element reference, e.g. el-183." }),
|
|
129
|
+
frame: Type.Optional(frame()),
|
|
130
|
+
}, { additionalProperties: false, required: ["ref"] }),
|
|
131
|
+
browser_type_focused: Type.Object({
|
|
132
|
+
text: Type.String({ description: "Text to type into the focused element." }),
|
|
133
|
+
frame: Type.Optional(frame()),
|
|
134
|
+
}, { additionalProperties: false, required: ["text"] }),
|
|
135
|
+
browser_open_tab: Type.Object({
|
|
136
|
+
url: Type.String({ description: 'URL for the new tab (default about:blank), e.g. "https://example.com".' }),
|
|
137
|
+
timeoutMs: Type.Optional(Type.Number({
|
|
138
|
+
description: "Max milliseconds to wait for the load to settle (default 30000, cap 120000).",
|
|
139
|
+
})),
|
|
140
|
+
}, { additionalProperties: false, required: ["url"] }),
|
|
141
|
+
browser_close_tab: Type.Object({
|
|
142
|
+
tabId: Type.Number({ description: "Firefox tab id (from browser_list_tabs / browser_open_tab)." }),
|
|
143
|
+
}, { additionalProperties: false, required: ["tabId"] }),
|
|
144
|
+
browser_list_tabs: empty(),
|
|
145
|
+
browser_bind_tab: Type.Object({
|
|
146
|
+
tabId: Type.Number({ description: "Firefox tab id (from browser_list_tabs)." }),
|
|
147
|
+
}, { additionalProperties: false, required: ["tabId"] }),
|
|
148
|
+
browser_unbind_tab: empty(),
|
|
149
|
+
};
|
|
150
|
+
/** One entry per protocol browser tool, with its TypeBox parameter schema. */
|
|
151
|
+
export const BROWSER_TOOL_SCHEMAS = BROWSER_TOOLS.map((def) => {
|
|
152
|
+
const parameters = SCHEMAS[def.name];
|
|
153
|
+
if (!parameters)
|
|
154
|
+
throw new Error(`missing TypeBox schema for tool ${def.name}`);
|
|
155
|
+
return { name: def.name, description: def.description, parameters, readOnly: def.readOnly };
|
|
156
|
+
});
|
|
157
|
+
// ---------------------------------------------------------------------------
|
|
158
|
+
// Host-side REPL tools (executed by the native host, never the add-on)
|
|
159
|
+
// ---------------------------------------------------------------------------
|
|
160
|
+
const REPL_SCHEMAS = {
|
|
161
|
+
javascript: Type.Object({
|
|
162
|
+
code: Type.String({
|
|
163
|
+
description: "JavaScript to run as one REPL cell. Top-level await allowed. Example: " +
|
|
164
|
+
"`const s = await page.snapshot(); await page.click(s.tree.children.find(n => n.name === 'Go')?.ref)`",
|
|
165
|
+
}),
|
|
166
|
+
timeoutMs: Type.Optional(Type.Number({
|
|
167
|
+
description: "Kill the cell after this many milliseconds (default 30000, max 120000).",
|
|
168
|
+
})),
|
|
169
|
+
}, { additionalProperties: false, required: ["code"] }),
|
|
170
|
+
};
|
|
171
|
+
/** One entry per protocol REPL tool, with its TypeBox parameter schema. */
|
|
172
|
+
export const REPL_TOOL_SCHEMAS = REPL_TOOLS.map((def) => {
|
|
173
|
+
const parameters = REPL_SCHEMAS[def.name];
|
|
174
|
+
if (!parameters)
|
|
175
|
+
throw new Error(`missing TypeBox schema for repl tool ${def.name}`);
|
|
176
|
+
return { name: def.name, description: def.description, parameters, readOnly: def.readOnly };
|
|
177
|
+
});
|
|
178
|
+
// ---------------------------------------------------------------------------
|
|
179
|
+
// Control tools (pi_*)
|
|
180
|
+
// ---------------------------------------------------------------------------
|
|
181
|
+
const sessionId = Type.String({ description: "ACP session id (e.g. from pi_get_state)." });
|
|
182
|
+
const CONTROL_SCHEMAS = {
|
|
183
|
+
pi_get_state: empty(),
|
|
184
|
+
pi_new_session: Type.Object({
|
|
185
|
+
cwd: Type.String({ description: "Working directory for the new session (absolute path)." }),
|
|
186
|
+
}, { additionalProperties: false, required: ["cwd"] }),
|
|
187
|
+
pi_select_session: Type.Object({ sessionId }, { additionalProperties: false, required: ["sessionId"] }),
|
|
188
|
+
pi_prompt: Type.Object({
|
|
189
|
+
sessionId,
|
|
190
|
+
text: Type.String({ description: "Prompt text." }),
|
|
191
|
+
}, { additionalProperties: false, required: ["sessionId", "text"] }),
|
|
192
|
+
pi_cancel: Type.Object({ sessionId }, { additionalProperties: false, required: ["sessionId"] }),
|
|
193
|
+
pi_close_session: Type.Object({ sessionId }, { additionalProperties: false, required: ["sessionId"] }),
|
|
194
|
+
pi_set_config_option: Type.Object({
|
|
195
|
+
sessionId,
|
|
196
|
+
configId: Type.String({ description: "Config option id, e.g. \"model\" or \"thinking\"." }),
|
|
197
|
+
value: Type.Union([Type.String(), Type.Boolean()], {
|
|
198
|
+
description: "Value id (string) or flag (boolean) for the option.",
|
|
199
|
+
}),
|
|
200
|
+
}, { additionalProperties: false, required: ["sessionId", "configId", "value"] }),
|
|
201
|
+
pi_bind_current_tab: Type.Object({ sessionId }, { additionalProperties: false, required: ["sessionId"] }),
|
|
202
|
+
pi_bind_tab: Type.Object({
|
|
203
|
+
sessionId,
|
|
204
|
+
tabId: Type.Number({ description: "Firefox tab id (from pi_list_tabs)." }),
|
|
205
|
+
}, { additionalProperties: false, required: ["sessionId", "tabId"] }),
|
|
206
|
+
pi_open_tab: Type.Object({
|
|
207
|
+
sessionId,
|
|
208
|
+
url: Type.String({ description: 'URL for the new tab, e.g. "https://example.com".' }),
|
|
209
|
+
}, { additionalProperties: false, required: ["sessionId", "url"] }),
|
|
210
|
+
pi_list_tabs: Type.Object({ sessionId }, { additionalProperties: false, required: ["sessionId"] }),
|
|
211
|
+
pi_unbind_tab: Type.Object({ sessionId }, { additionalProperties: false, required: ["sessionId"] }),
|
|
212
|
+
pi_open_bound_tab: Type.Object({ sessionId }, { additionalProperties: false, required: ["sessionId"] }),
|
|
213
|
+
};
|
|
214
|
+
/** One entry per protocol control tool, with its TypeBox parameter schema. */
|
|
215
|
+
export const CONTROL_TOOL_SCHEMAS = CONTROL_TOOLS.map((def) => {
|
|
216
|
+
const parameters = CONTROL_SCHEMAS[def.name];
|
|
217
|
+
if (!parameters)
|
|
218
|
+
throw new Error(`missing TypeBox schema for tool ${def.name}`);
|
|
219
|
+
return { name: def.name, description: def.description, parameters, readOnly: def.readOnly };
|
|
220
|
+
});
|
|
221
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability provider registry (THUNDERBIRD-PLAN.md §28).
|
|
3
|
+
*
|
|
4
|
+
* The broker maintains one entry per attached application connection
|
|
5
|
+
* (Firefox / Thunderbird), identified by the pi.agent.hello handshake
|
|
6
|
+
* (application + capabilities). Tool routing (plan §29) resolves each tool
|
|
7
|
+
* call to the connected client that provides it, so a Pi session can use
|
|
8
|
+
* both apps' tools in one turn.
|
|
9
|
+
*/
|
|
10
|
+
import { AGENT_CAPABILITIES, PI_BROWSER_ERROR, PiBrowserProtocolError, capabilitiesProvideTool, } from "@pi-browser/protocol";
|
|
11
|
+
export class CapabilityRegistry {
|
|
12
|
+
log;
|
|
13
|
+
clients = new Map();
|
|
14
|
+
/**
|
|
15
|
+
* Broker hook: fired with the new union after any register/remove that
|
|
16
|
+
* changes the client set, so the host can push
|
|
17
|
+
* x-pi-browser/capabilities_changed to every connected client (their UIs
|
|
18
|
+
* update the "capabilities:" line in near-real-time).
|
|
19
|
+
*/
|
|
20
|
+
onChange;
|
|
21
|
+
constructor(log) {
|
|
22
|
+
this.log = log;
|
|
23
|
+
}
|
|
24
|
+
emitChange() {
|
|
25
|
+
if (!this.onChange)
|
|
26
|
+
return;
|
|
27
|
+
try {
|
|
28
|
+
this.onChange(this.allCapabilities());
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// Notification plumbing must never break registration/disconnection.
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Register (or re-register) a client. Returns the previous entry, if any. */
|
|
35
|
+
register(client) {
|
|
36
|
+
const previous = this.clients.get(client.clientId);
|
|
37
|
+
this.clients.set(client.clientId, client);
|
|
38
|
+
this.log.info(`registry: ${client.clientId} ${client.application} capabilities=[${client.capabilities.join(",")}]` +
|
|
39
|
+
(previous ? " (re-registered)" : "") +
|
|
40
|
+
` — connected: ${this.clients.size}`);
|
|
41
|
+
this.emitChange();
|
|
42
|
+
return previous;
|
|
43
|
+
}
|
|
44
|
+
/** Remove a disconnected client. Returns it if it was registered. */
|
|
45
|
+
remove(clientId) {
|
|
46
|
+
const client = this.clients.get(clientId);
|
|
47
|
+
if (!client)
|
|
48
|
+
return undefined;
|
|
49
|
+
this.clients.delete(clientId);
|
|
50
|
+
this.log.info(`registry: ${clientId} removed — connected: ${this.clients.size}`);
|
|
51
|
+
this.emitChange();
|
|
52
|
+
return client;
|
|
53
|
+
}
|
|
54
|
+
get(clientId) {
|
|
55
|
+
return this.clients.get(clientId);
|
|
56
|
+
}
|
|
57
|
+
list() {
|
|
58
|
+
return [...this.clients.values()];
|
|
59
|
+
}
|
|
60
|
+
get size() {
|
|
61
|
+
return this.clients.size;
|
|
62
|
+
}
|
|
63
|
+
/** Union of all connected clients' capabilities (canonical order). */
|
|
64
|
+
allCapabilities() {
|
|
65
|
+
const set = new Set();
|
|
66
|
+
for (const c of this.clients.values()) {
|
|
67
|
+
for (const cap of c.capabilities)
|
|
68
|
+
set.add(cap);
|
|
69
|
+
}
|
|
70
|
+
return AGENT_CAPABILITIES.filter((c) => set.has(c));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Client that should execute `toolName` for a session owned by
|
|
74
|
+
* `ownerClientId` (plan §29): the owner when it provides the tool,
|
|
75
|
+
* otherwise the first other connected client that does (cross-app
|
|
76
|
+
* routing). Throws a structured error when no connected client provides
|
|
77
|
+
* the tool.
|
|
78
|
+
*/
|
|
79
|
+
resolveTarget(ownerClientId, toolName) {
|
|
80
|
+
const owner = ownerClientId ? this.clients.get(ownerClientId) : undefined;
|
|
81
|
+
if (owner && capabilitiesProvideTool(owner.capabilities, toolName))
|
|
82
|
+
return owner;
|
|
83
|
+
for (const client of this.clients.values()) {
|
|
84
|
+
if (owner && client.clientId === owner.clientId)
|
|
85
|
+
continue;
|
|
86
|
+
if (capabilitiesProvideTool(client.capabilities, toolName))
|
|
87
|
+
return client;
|
|
88
|
+
}
|
|
89
|
+
throw new PiBrowserProtocolError(PI_BROWSER_ERROR.MCP_UNAVAILABLE, `no connected client provides tool: ${toolName}`, { tool: toolName });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=capability-registry.js.map
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client (add-on) heartbeat: the host-side presence signal for onboarding
|
|
3
|
+
* (PRODUCT.md §8, onboarding/auto-detection).
|
|
4
|
+
*
|
|
5
|
+
* The add-on holds the Native Messaging port, so the host cannot enumerate
|
|
6
|
+
* add-ons; instead the host records when the add-on connects (ACP
|
|
7
|
+
* initialize) and on every keepalive ping. The installer CLI
|
|
8
|
+
* (/pi-browser status|doctor) reads the file to report whether the add-on
|
|
9
|
+
* side of the onboarding is complete, in either install order:
|
|
10
|
+
*
|
|
11
|
+
* - plugin first: doctor shows "add-on: not detected" until it is loaded
|
|
12
|
+
* - add-on first: the add-on auto-detects the installed host; once it
|
|
13
|
+
* connects, the heartbeat appears and status flips to "detected"
|
|
14
|
+
*
|
|
15
|
+
* The file is best-effort: a filesystem hiccup must never break the protocol
|
|
16
|
+
* path. Contents are non-sensitive (timestamp, client identity, pid).
|
|
17
|
+
*/
|
|
18
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
19
|
+
import os from "node:os";
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
/**
|
|
22
|
+
* Client names the add-ons send in ACP `initialize` (acp-client.ts).
|
|
23
|
+
* The host records a heartbeat for any recognized client so the installer
|
|
24
|
+
* can report per-app add-on presence (plan §23: both apps share the host).
|
|
25
|
+
*/
|
|
26
|
+
export const ADDON_CLIENT_NAMES = [
|
|
27
|
+
"pi-browser-firefox",
|
|
28
|
+
"pi-firefox",
|
|
29
|
+
"pi-thunderbird",
|
|
30
|
+
];
|
|
31
|
+
/** Legacy single-client constant (kept for tests/references). */
|
|
32
|
+
export const ADDON_CLIENT_NAME = "pi-browser-firefox";
|
|
33
|
+
export function isKnownAddonClient(name) {
|
|
34
|
+
return typeof name === "string" && ADDON_CLIENT_NAMES.includes(name);
|
|
35
|
+
}
|
|
36
|
+
/** A heartbeat younger than this counts as "add-on connected" (3x the 10s ping). */
|
|
37
|
+
export const ADDON_HEARTBEAT_FRESH_MS = 90_000;
|
|
38
|
+
/** Application a client name belongs to (for per-app heartbeat files). */
|
|
39
|
+
export function applicationForClient(name) {
|
|
40
|
+
if (name === "pi-thunderbird")
|
|
41
|
+
return "thunderbird";
|
|
42
|
+
if (name === "pi-browser-firefox" || name === "pi-firefox")
|
|
43
|
+
return "firefox";
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Heartbeat file locations (env override for tests; default under $HOME).
|
|
48
|
+
* Legacy single file (latest client) + per-app files so status/doctor can
|
|
49
|
+
* report both applications independently (plan §23, cross-app broker).
|
|
50
|
+
*/
|
|
51
|
+
export function heartbeatPathForHome(homeDir) {
|
|
52
|
+
return process.env.PI_BROWSER_HEARTBEAT_FILE || path.join(homeDir, ".pi-browser", "client.heartbeat");
|
|
53
|
+
}
|
|
54
|
+
export function heartbeatPath() {
|
|
55
|
+
return heartbeatPathForHome(os.homedir());
|
|
56
|
+
}
|
|
57
|
+
/** Per-app heartbeat file (e.g. client.heartbeat.thunderbird). */
|
|
58
|
+
export function appHeartbeatPath(homeDir, application) {
|
|
59
|
+
const dir = process.env.PI_BROWSER_HEARTBEAT_FILE
|
|
60
|
+
? path.dirname(process.env.PI_BROWSER_HEARTBEAT_FILE)
|
|
61
|
+
: path.join(homeDir, ".pi-browser");
|
|
62
|
+
return path.join(dir, `client.heartbeat.${application}`);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Record add-on presence. No-op for non-add-on clients (e.g. test harnesses).
|
|
66
|
+
* Writes the legacy single file (latest client) AND the per-app file so
|
|
67
|
+
* /pi-browser status|doctor can report both applications (plan §23).
|
|
68
|
+
* Best-effort: never throws.
|
|
69
|
+
*/
|
|
70
|
+
export function touchClientHeartbeat(clientName, clientVersion, application) {
|
|
71
|
+
try {
|
|
72
|
+
if (!isKnownAddonClient(clientName))
|
|
73
|
+
return;
|
|
74
|
+
const file = heartbeatPath();
|
|
75
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
76
|
+
const hb = {
|
|
77
|
+
ts: Date.now(),
|
|
78
|
+
client: clientName,
|
|
79
|
+
...(clientVersion ? { version: clientVersion } : {}),
|
|
80
|
+
pid: process.pid,
|
|
81
|
+
};
|
|
82
|
+
writeFileSync(file, JSON.stringify(hb));
|
|
83
|
+
const app = application ?? applicationForClient(clientName);
|
|
84
|
+
if (app) {
|
|
85
|
+
writeFileSync(appHeartbeatPath(os.homedir(), app), JSON.stringify(hb));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// best-effort only — the protocol path must never break on this
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Read the add-on heartbeat, or undefined when absent/unreadable.
|
|
94
|
+
* With `application`, reads the per-app file (falling back to the legacy
|
|
95
|
+
* file when its client belongs to that application).
|
|
96
|
+
*/
|
|
97
|
+
export function readClientHeartbeat(homeDir, application) {
|
|
98
|
+
const files = application
|
|
99
|
+
? [appHeartbeatPath(homeDir, application), heartbeatPathForHome(homeDir)]
|
|
100
|
+
: [heartbeatPathForHome(homeDir)];
|
|
101
|
+
for (const file of files) {
|
|
102
|
+
try {
|
|
103
|
+
if (!existsSync(file))
|
|
104
|
+
continue;
|
|
105
|
+
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
106
|
+
if (typeof raw.ts !== "number" || !isKnownAddonClient(raw.client))
|
|
107
|
+
continue;
|
|
108
|
+
if (application && applicationForClient(raw.client) !== application)
|
|
109
|
+
continue;
|
|
110
|
+
return { ...raw, ageMs: Date.now() - raw.ts };
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// try the next file
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=client-heartbeat.js.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeBox parameter schemas for the draft-first Thunderbird compose tools.
|
|
3
|
+
*
|
|
4
|
+
* These MUST stay in sync with the JSON Schemas in @pi-browser/protocol
|
|
5
|
+
* (compose-tools.ts) — the JSON is the transport-neutral contract, the TypeBox
|
|
6
|
+
* schemas are what Pi validates against and hands to the model.
|
|
7
|
+
* test/tool-schemas.test.ts enforces the sync.
|
|
8
|
+
*/
|
|
9
|
+
import { Type } from "typebox";
|
|
10
|
+
import { COMPOSE_TOOLS } from "@pi-browser/protocol";
|
|
11
|
+
const composeTabId = Type.Number({
|
|
12
|
+
description: "Compose window tab id, returned by the compose_prepare_* tools; identifies the window to read or update.",
|
|
13
|
+
});
|
|
14
|
+
const messageId = Type.Number({
|
|
15
|
+
description: "Thunderbird numeric message id of the message to reply/forward (from the current context or a search result). Transient: valid only within the current session.",
|
|
16
|
+
});
|
|
17
|
+
const to = Type.String({
|
|
18
|
+
description: 'Recipients in mailbox format ("Name <a@example.com>" or just "a@example.com"); separate several with commas.',
|
|
19
|
+
});
|
|
20
|
+
const cc = Type.String({
|
|
21
|
+
description: 'CC recipients in mailbox format ("Name <a@example.com>"), comma-separated.',
|
|
22
|
+
});
|
|
23
|
+
const bcc = Type.String({
|
|
24
|
+
description: 'BCC recipients in mailbox format ("Name <a@example.com>"), comma-separated.',
|
|
25
|
+
});
|
|
26
|
+
const subject = Type.String({ description: "The message subject line." });
|
|
27
|
+
const body = Type.String({ description: "The message body (HTML)." });
|
|
28
|
+
const contentType = Type.Union([Type.Literal("text/html"), Type.Literal("text/plain")], { description: "Body MIME type (default text/html)." });
|
|
29
|
+
const replyType = Type.Union([Type.Literal("replyToSender"), Type.Literal("replyToList"), Type.Literal("replyToAll")], { description: "Who the reply is addressed to (default replyToSender)." });
|
|
30
|
+
const forwardType = Type.Union([Type.Literal("forwardInline"), Type.Literal("forwardAsAttachment")], { description: "How the message is forwarded (default forwardInline)." });
|
|
31
|
+
const attachmentName = Type.String({
|
|
32
|
+
description: 'The attachment filename, e.g. "report.pdf".',
|
|
33
|
+
});
|
|
34
|
+
const attachmentContent = Type.String({
|
|
35
|
+
description: "The file content, base64-encoded.",
|
|
36
|
+
});
|
|
37
|
+
const attachmentContentType = Type.String({
|
|
38
|
+
description: 'The MIME type, e.g. "application/pdf" (default application/octet-stream).',
|
|
39
|
+
});
|
|
40
|
+
const SCHEMAS = {
|
|
41
|
+
compose_prepare_new: Type.Object({
|
|
42
|
+
to: Type.Optional(to),
|
|
43
|
+
cc: Type.Optional(cc),
|
|
44
|
+
bcc: Type.Optional(bcc),
|
|
45
|
+
subject: Type.Optional(subject),
|
|
46
|
+
body: Type.Optional(body),
|
|
47
|
+
contentType: Type.Optional(contentType),
|
|
48
|
+
}, { additionalProperties: false }),
|
|
49
|
+
compose_prepare_reply: Type.Object({
|
|
50
|
+
messageId,
|
|
51
|
+
replyType: Type.Optional(replyType),
|
|
52
|
+
cc: Type.Optional(cc),
|
|
53
|
+
bcc: Type.Optional(bcc),
|
|
54
|
+
subject: Type.Optional(subject),
|
|
55
|
+
body: Type.Optional(body),
|
|
56
|
+
}, { additionalProperties: false, required: ["messageId"] }),
|
|
57
|
+
compose_prepare_forward: Type.Object({
|
|
58
|
+
messageId,
|
|
59
|
+
forwardType: Type.Optional(forwardType),
|
|
60
|
+
to: Type.Optional(to),
|
|
61
|
+
cc: Type.Optional(cc),
|
|
62
|
+
bcc: Type.Optional(bcc),
|
|
63
|
+
subject: Type.Optional(subject),
|
|
64
|
+
body: Type.Optional(body),
|
|
65
|
+
}, { additionalProperties: false, required: ["messageId"] }),
|
|
66
|
+
compose_get: Type.Object({ tabId: composeTabId }, { additionalProperties: false, required: ["tabId"] }),
|
|
67
|
+
compose_update: Type.Object({
|
|
68
|
+
tabId: composeTabId,
|
|
69
|
+
to: Type.Optional(to),
|
|
70
|
+
cc: Type.Optional(cc),
|
|
71
|
+
bcc: Type.Optional(bcc),
|
|
72
|
+
subject: Type.Optional(subject),
|
|
73
|
+
body: Type.Optional(body),
|
|
74
|
+
contentType: Type.Optional(contentType),
|
|
75
|
+
}, { additionalProperties: false, required: ["tabId"] }),
|
|
76
|
+
compose_add_attachment: Type.Object({
|
|
77
|
+
tabId: composeTabId,
|
|
78
|
+
name: attachmentName,
|
|
79
|
+
content: attachmentContent,
|
|
80
|
+
contentType: Type.Optional(attachmentContentType),
|
|
81
|
+
}, { additionalProperties: false, required: ["tabId", "name", "content"] }),
|
|
82
|
+
};
|
|
83
|
+
/** One entry per protocol compose tool, with its TypeBox parameter schema. */
|
|
84
|
+
export const COMPOSE_TOOL_SCHEMAS = COMPOSE_TOOLS.map((def) => {
|
|
85
|
+
const parameters = SCHEMAS[def.name];
|
|
86
|
+
if (!parameters)
|
|
87
|
+
throw new Error(`missing TypeBox schema for tool ${def.name}`);
|
|
88
|
+
return { name: def.name, description: def.description, parameters, readOnly: def.readOnly };
|
|
89
|
+
});
|
|
90
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeBox parameter schemas for the Thunderbird contacts (T6) tools.
|
|
3
|
+
* MUST stay in sync with the JSON Schemas in @pi-browser/protocol
|
|
4
|
+
* (contacts-tools.ts) — enforced by test/tool-schemas.test.ts.
|
|
5
|
+
*/
|
|
6
|
+
import { Type } from "typebox";
|
|
7
|
+
import { CONTACTS_TOOLS } from "@pi-browser/protocol";
|
|
8
|
+
const query = Type.String({ description: "One or more space-separated search terms." });
|
|
9
|
+
const limit = Type.Number({ description: "Maximum number of results to return (default 10)." });
|
|
10
|
+
const contactId = Type.String({ description: "The contact id (cardKey) from a contacts_search result." });
|
|
11
|
+
const SCHEMAS = {
|
|
12
|
+
contacts_search: Type.Object({ query, limit: Type.Optional(limit) }, { additionalProperties: false, required: ["query"] }),
|
|
13
|
+
contacts_list: Type.Object({
|
|
14
|
+
filter: Type.Optional(Type.String({ description: "Only contacts whose name, email, or organization contains this (case-insensitive)." })),
|
|
15
|
+
limit: Type.Optional(Type.Number({ description: "Maximum contacts per page (default 10, max 50)." })),
|
|
16
|
+
cursor: Type.Optional(Type.Number({ description: "Offset into the full (filtered) list for pagination; pass the previous nextCursor." })),
|
|
17
|
+
}, { additionalProperties: false }),
|
|
18
|
+
contacts_get: Type.Object({ contactId }, { additionalProperties: false, required: ["contactId"] }),
|
|
19
|
+
};
|
|
20
|
+
export const CONTACTS_TOOL_SCHEMAS = CONTACTS_TOOLS.map((def) => {
|
|
21
|
+
const parameters = SCHEMAS[def.name];
|
|
22
|
+
if (!parameters)
|
|
23
|
+
throw new Error(`missing TypeBox schema for tool ${def.name}`);
|
|
24
|
+
return { name: def.name, description: def.description, parameters, readOnly: def.readOnly };
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Installer CLI — `trusted-ua` when installed from npm (`npm i -g trusted-user-agent`),
|
|
4
|
+
* or `node dist/installer/cli.js` from a checkout:
|
|
5
|
+
*
|
|
6
|
+
* trusted-ua [install|status|doctor|uninstall] [firefox|thunderbird|mozilla]
|
|
7
|
+
* trusted-ua mcp [install|status|uninstall] [pi|claude|codex|cursor|gemini|vscode|all]
|
|
8
|
+
*
|
|
9
|
+
* The app target selects which Mozilla applications the shared `com.matbee.agent`
|
|
10
|
+
* host is registered for (plan §23). Default: `mozilla` (both).
|
|
11
|
+
* The mcp client selects which MCP client configs get the `pi-browser` stdio
|
|
12
|
+
* bridge entry. Default: `pi`.
|
|
13
|
+
*
|
|
14
|
+
* `--allow-temporary` lets install run from a temporary package root (npx
|
|
15
|
+
* cache, temp dir); only tests need it.
|
|
16
|
+
*
|
|
17
|
+
* This is a normal CLI process (not the native host), so stdout is free for
|
|
18
|
+
* report output. The native host keeps stdout protocol-only.
|
|
19
|
+
*/
|
|
20
|
+
import { runCommand } from "./index.js";
|
|
21
|
+
import { MCP_CLIENTS, isMcpClientTarget } from "./mcp-clients.js";
|
|
22
|
+
const USAGE = [
|
|
23
|
+
"usage: trusted-ua [install|status|doctor|uninstall] [firefox|thunderbird|mozilla]",
|
|
24
|
+
` trusted-ua mcp [install|status|uninstall] [${[...MCP_CLIENTS, "all"].join("|")}]`,
|
|
25
|
+
].join("\n");
|
|
26
|
+
const commands = new Set(["install", "status", "doctor", "uninstall", "mcp"]);
|
|
27
|
+
const appTargets = new Set(["firefox", "thunderbird", "mozilla"]);
|
|
28
|
+
const mcpSubs = new Set(["install", "status", "uninstall"]);
|
|
29
|
+
const argv = process.argv.slice(2);
|
|
30
|
+
const allowTemporary = argv.includes("--allow-temporary");
|
|
31
|
+
const positional = argv.filter((a) => !a.startsWith("--"));
|
|
32
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
33
|
+
process.stdout.write(`${USAGE}\n`);
|
|
34
|
+
process.exit(0);
|
|
35
|
+
}
|
|
36
|
+
const command = (positional[0] ?? "status").trim();
|
|
37
|
+
if (!commands.has(command)) {
|
|
38
|
+
process.stderr.write(`${USAGE}\n`);
|
|
39
|
+
process.exit(2);
|
|
40
|
+
}
|
|
41
|
+
let sub = "install";
|
|
42
|
+
let mcpClient = "pi";
|
|
43
|
+
let appArg = "mozilla";
|
|
44
|
+
if (command === "mcp") {
|
|
45
|
+
const s = (positional[1] ?? "install").trim();
|
|
46
|
+
const c = (positional[2] ?? "pi").trim();
|
|
47
|
+
if (!mcpSubs.has(s) || !isMcpClientTarget(c)) {
|
|
48
|
+
process.stderr.write(`${USAGE}\n`);
|
|
49
|
+
process.exit(2);
|
|
50
|
+
}
|
|
51
|
+
sub = s;
|
|
52
|
+
mcpClient = c;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
appArg = (positional[1] ?? "mozilla").trim();
|
|
56
|
+
if (!appTargets.has(appArg)) {
|
|
57
|
+
process.stderr.write(`${USAGE}\n`);
|
|
58
|
+
process.exit(2);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const result = await runCommand(command, { apps: appArg, mcpClient, ...(allowTemporary ? { allowTemporary } : {}) }, sub);
|
|
63
|
+
process.stdout.write(result.lines.join("\n") + "\n");
|
|
64
|
+
process.exit(result.ok ? 0 : 1);
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
process.stderr.write(`error: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=cli.js.map
|