@prbe.ai/electron-sdk 0.1.4 → 0.1.6
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/dist/index.d.mts +332 -0
- package/dist/index.d.ts +331 -15
- package/dist/index.js +2471 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2402 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types-DHT-JxMT.d.mts +401 -0
- package/dist/types-DHT-JxMT.d.ts +401 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.d.ts +2 -14
- package/dist/types.js +160 -30
- package/dist/types.js.map +1 -1
- package/dist/types.mjs +125 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +22 -8
- package/dist/agent.d.ts +0 -106
- package/dist/agent.d.ts.map +0 -1
- package/dist/agent.js +0 -878
- package/dist/agent.js.map +0 -1
- package/dist/assets/index.d.ts +0 -6
- package/dist/assets/index.d.ts.map +0 -1
- package/dist/assets/index.js +0 -13
- package/dist/assets/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/interactions.d.ts +0 -63
- package/dist/interactions.d.ts.map +0 -1
- package/dist/interactions.js +0 -27
- package/dist/interactions.js.map +0 -1
- package/dist/models.d.ts +0 -218
- package/dist/models.d.ts.map +0 -1
- package/dist/models.js +0 -121
- package/dist/models.js.map +0 -1
- package/dist/serialization.d.ts +0 -51
- package/dist/serialization.d.ts.map +0 -1
- package/dist/serialization.js +0 -72
- package/dist/serialization.js.map +0 -1
- package/dist/state.d.ts +0 -70
- package/dist/state.d.ts.map +0 -1
- package/dist/state.js +0 -303
- package/dist/state.js.map +0 -1
- package/dist/tools/bash.d.ts +0 -30
- package/dist/tools/bash.d.ts.map +0 -1
- package/dist/tools/bash.js +0 -248
- package/dist/tools/bash.js.map +0 -1
- package/dist/tools/filesystem.d.ts +0 -63
- package/dist/tools/filesystem.d.ts.map +0 -1
- package/dist/tools/filesystem.js +0 -573
- package/dist/tools/filesystem.js.map +0 -1
- package/dist/tools/index.d.ts +0 -46
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js +0 -171
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/interactive.d.ts +0 -15
- package/dist/tools/interactive.d.ts.map +0 -1
- package/dist/tools/interactive.js +0 -58
- package/dist/tools/interactive.js.map +0 -1
- package/dist/tools/logs.d.ts +0 -72
- package/dist/tools/logs.d.ts.map +0 -1
- package/dist/tools/logs.js +0 -366
- package/dist/tools/logs.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { P as PRBEToolDeclaration, a as PRBEToolParameter, b as PRBEInteractionRequester, F as FlaggedFileIn, c as PRBEAgentState, d as PRBEAgentConfig, I as InvestigationSource, e as InteractionPayload, f as InteractionResponse, g as PollResponse, T as TicketInfoOut } from './types-DHT-JxMT.mjs';
|
|
2
|
+
export { A as API_URL, h as AskQuestionPayload, i as AskQuestionResponse, C as ContextRequestOut, D as DEFAULT_PRBE_STATE, j as InteractionType, k as InvestigationResult, M as MIDDLEWARE_URL, l as PRBEAgentConfigKey, m as PRBEAgentError, n as PRBEAgentErrorType, o as PRBEAgentStatus, p as PRBEAgentStatusType, q as PRBECRInvestigation, r as PRBECompletedInvestigation, s as PRBEInteractionHandler, t as PRBESerializedCR, u as PRBESerializedCompletedInvestigation, v as PRBESerializedState, w as PRBESerializedTicket, x as PRBEStateEvent, y as PRBEStatusEvent, z as PollRequest, R as RequestPathAccessPayload, B as RequestPathAccessResponse, E as RequestPermissionPayload, G as RequestPermissionResponse, H as ResolvedInteraction, J as TicketInfoRequest, K as TicketInfoResponse, L as TicketStatusOut, N as ToolName, O as ToolParamType, W as WSMessage, Q as WSMessageType, S as redactPII, U as serializePRBEState } from './types-DHT-JxMT.mjs';
|
|
3
|
+
import 'events';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* tools/index.ts — Tool interface, registry, and closure tool
|
|
7
|
+
*
|
|
8
|
+
* Mirrors PRBEAgentTools.swift tool protocol + registry pattern.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
interface PRBETool {
|
|
12
|
+
readonly declaration: PRBEToolDeclaration;
|
|
13
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
14
|
+
}
|
|
15
|
+
declare class PRBEToolRegistry {
|
|
16
|
+
private tools;
|
|
17
|
+
register(tool: PRBETool): void;
|
|
18
|
+
allDeclarations(): PRBEToolDeclaration[];
|
|
19
|
+
execute(name: string, args: Record<string, unknown>): Promise<string>;
|
|
20
|
+
}
|
|
21
|
+
declare class PRBEClosureTool implements PRBETool {
|
|
22
|
+
readonly declaration: PRBEToolDeclaration;
|
|
23
|
+
private readonly handler;
|
|
24
|
+
constructor(name: string, description: string, parameters: PRBEToolParameter[], handler: (args: Record<string, unknown>) => Promise<string>);
|
|
25
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Resolve a path string and validate it against auto-approved directories.
|
|
29
|
+
* Returns the resolved absolute path or null if outside auto-approved directories.
|
|
30
|
+
*/
|
|
31
|
+
declare function resolveAndValidate(pathStr: string, autoApprovedDirs: string[]): string | null;
|
|
32
|
+
/** Result of resolveWithAccessRequest — resolved path, null (silently denied), or error string for the agent */
|
|
33
|
+
type PathResolution = {
|
|
34
|
+
path: string;
|
|
35
|
+
} | {
|
|
36
|
+
error: string;
|
|
37
|
+
} | null;
|
|
38
|
+
/**
|
|
39
|
+
* Resolve a path, requesting user access if outside auto-approved directories.
|
|
40
|
+
* When a requester is available and the path fails validation, prompts
|
|
41
|
+
* the user for permission and caches the grant in `grantedPaths`.
|
|
42
|
+
*
|
|
43
|
+
* Returns { path } on success, { error } with a message for the agent, or null.
|
|
44
|
+
*/
|
|
45
|
+
declare function resolveWithAccessRequest(pathStr: string, autoApprovedDirs: string[], grantedPaths: Set<string>, requester?: PRBEInteractionRequester): Promise<PathResolution>;
|
|
46
|
+
/**
|
|
47
|
+
* Format byte sizes for human-readable output.
|
|
48
|
+
*/
|
|
49
|
+
declare function humanReadableSize(bytes: number): string;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* tools/logs.ts — Log capture + built-in log tools
|
|
53
|
+
*
|
|
54
|
+
* Implements: client_read_app_logs, client_search_app_logs,
|
|
55
|
+
* client_clear_app_logs, client_flag_app_logs
|
|
56
|
+
*
|
|
57
|
+
* Mirrors PRBELogCapture.swift + log tool implementations from PRBEAgentTools.swift.
|
|
58
|
+
* Log capture works by monkey-patching console.log/warn/error in the Electron main process.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
interface LogEntry {
|
|
62
|
+
timestamp: Date;
|
|
63
|
+
level: string;
|
|
64
|
+
category: string;
|
|
65
|
+
message: string;
|
|
66
|
+
}
|
|
67
|
+
declare class PRBELogCapture {
|
|
68
|
+
private entries;
|
|
69
|
+
private readonly maxEntries;
|
|
70
|
+
private isCapturing;
|
|
71
|
+
private originalLog?;
|
|
72
|
+
private originalWarn?;
|
|
73
|
+
private originalError?;
|
|
74
|
+
private originalDebug?;
|
|
75
|
+
private originalInfo?;
|
|
76
|
+
constructor(maxEntries?: number);
|
|
77
|
+
log(message: string, level?: string, category?: string): void;
|
|
78
|
+
get count(): number;
|
|
79
|
+
getEntries(options?: {
|
|
80
|
+
offset?: number;
|
|
81
|
+
limit?: number;
|
|
82
|
+
level?: string;
|
|
83
|
+
from?: Date;
|
|
84
|
+
to?: Date;
|
|
85
|
+
}): LogEntry[];
|
|
86
|
+
search(pattern: string, contextLines?: number, maxResults?: number): Array<{
|
|
87
|
+
index: number;
|
|
88
|
+
entry: LogEntry;
|
|
89
|
+
}>;
|
|
90
|
+
clearLogs(): number;
|
|
91
|
+
startCapturing(): void;
|
|
92
|
+
stopCapturing(): void;
|
|
93
|
+
getAllEntries(): LogEntry[];
|
|
94
|
+
private append;
|
|
95
|
+
}
|
|
96
|
+
declare class ReadAppLogsTool implements PRBETool {
|
|
97
|
+
private readonly logCapture;
|
|
98
|
+
constructor(logCapture: PRBELogCapture);
|
|
99
|
+
get declaration(): PRBEToolDeclaration;
|
|
100
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
101
|
+
}
|
|
102
|
+
declare class SearchAppLogsTool implements PRBETool {
|
|
103
|
+
private readonly logCapture;
|
|
104
|
+
constructor(logCapture: PRBELogCapture);
|
|
105
|
+
get declaration(): PRBEToolDeclaration;
|
|
106
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
107
|
+
}
|
|
108
|
+
declare class ClearAppLogsTool implements PRBETool {
|
|
109
|
+
private readonly logCapture;
|
|
110
|
+
constructor(logCapture: PRBELogCapture);
|
|
111
|
+
get declaration(): PRBEToolDeclaration;
|
|
112
|
+
execute(_args: Record<string, unknown>): Promise<string>;
|
|
113
|
+
}
|
|
114
|
+
declare class FlagAppLogsTool implements PRBETool {
|
|
115
|
+
private readonly logCapture;
|
|
116
|
+
private readonly onFlag;
|
|
117
|
+
constructor(logCapture: PRBELogCapture, onFlag: (file: FlaggedFileIn) => void);
|
|
118
|
+
get declaration(): PRBEToolDeclaration;
|
|
119
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* agent.ts — PRBEAgent class
|
|
124
|
+
*
|
|
125
|
+
* Main entry point for the PRBE debug agent SDK.
|
|
126
|
+
* Handles WebSocket connection to middleware, investigation lifecycle,
|
|
127
|
+
* background polling for context requests, file uploads, and persistence.
|
|
128
|
+
*
|
|
129
|
+
* Mirrors PRBEAgent.swift behavior.
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
declare class PRBEAgent implements PRBEInteractionRequester {
|
|
133
|
+
readonly state: PRBEAgentState;
|
|
134
|
+
readonly logCapture: PRBELogCapture;
|
|
135
|
+
private readonly config;
|
|
136
|
+
private readonly appDataPath?;
|
|
137
|
+
private readonly interactionHandler?;
|
|
138
|
+
private readonly registry;
|
|
139
|
+
private readonly grantedPaths;
|
|
140
|
+
private userCancelled;
|
|
141
|
+
private activeWS;
|
|
142
|
+
private pollingTimer;
|
|
143
|
+
private persistedData;
|
|
144
|
+
private fetchAbortController;
|
|
145
|
+
private currentInvestigationSource;
|
|
146
|
+
private currentCRId;
|
|
147
|
+
/** Files flagged during the current tool call — uploaded immediately after the tool returns. */
|
|
148
|
+
private pendingFlaggedFiles;
|
|
149
|
+
private get agentID();
|
|
150
|
+
private get trackedTicketIDs();
|
|
151
|
+
private set trackedTicketIDs(value);
|
|
152
|
+
private get respondedCRIDs();
|
|
153
|
+
private set respondedCRIDs(value);
|
|
154
|
+
private syncPolling;
|
|
155
|
+
private addTrackedTicket;
|
|
156
|
+
constructor(config: PRBEAgentConfig);
|
|
157
|
+
private hookElectronLog;
|
|
158
|
+
private hookRendererLogs;
|
|
159
|
+
private static mapElectronLogLevel;
|
|
160
|
+
get investigationSource(): InvestigationSource;
|
|
161
|
+
requestUserInteraction(payload: InteractionPayload): Promise<InteractionResponse>;
|
|
162
|
+
/**
|
|
163
|
+
* Add an additional root directory to the runtime allowed roots.
|
|
164
|
+
*/
|
|
165
|
+
addAutoApprovedDir(rootPath: string): void;
|
|
166
|
+
/**
|
|
167
|
+
* Register a custom tool that the middleware can invoke during investigations.
|
|
168
|
+
*/
|
|
169
|
+
registerTool(name: string, description: string, parameters: PRBEToolParameter[], handler: (args: Record<string, unknown>) => Promise<string>): void;
|
|
170
|
+
/**
|
|
171
|
+
* User-initiated investigation. Updates `state` events/report directly.
|
|
172
|
+
*/
|
|
173
|
+
investigate(query: string, contextRequestID?: string): Promise<void>;
|
|
174
|
+
/**
|
|
175
|
+
* Cancel user-initiated investigation only (does not cancel background CRs).
|
|
176
|
+
*/
|
|
177
|
+
cancelInvestigation(): void;
|
|
178
|
+
/**
|
|
179
|
+
* Cancel everything — user investigation and polling.
|
|
180
|
+
*/
|
|
181
|
+
cancel(): void;
|
|
182
|
+
/**
|
|
183
|
+
* Poll the backend for context requests on tracked tickets.
|
|
184
|
+
*/
|
|
185
|
+
poll(): Promise<PollResponse | null>;
|
|
186
|
+
/**
|
|
187
|
+
* Fetch ticket display info for all tracked tickets.
|
|
188
|
+
*/
|
|
189
|
+
fetchTicketInfo(): Promise<TicketInfoOut[]>;
|
|
190
|
+
stopPolling(): void;
|
|
191
|
+
resumePolling(): void;
|
|
192
|
+
/**
|
|
193
|
+
* Destroy the agent — stops polling, stops console capture, closes WS.
|
|
194
|
+
*/
|
|
195
|
+
destroy(): void;
|
|
196
|
+
/**
|
|
197
|
+
* Reset all persisted data (agent ID, tracked tickets, responded CRs).
|
|
198
|
+
* Also clears in-memory state.
|
|
199
|
+
*/
|
|
200
|
+
resetPersistedData(): void;
|
|
201
|
+
/**
|
|
202
|
+
* Delete the persisted data file. Can be called without an agent instance.
|
|
203
|
+
*/
|
|
204
|
+
static clearPersistedData(): void;
|
|
205
|
+
private investigateForCR;
|
|
206
|
+
private connectToProxy;
|
|
207
|
+
private sendCancel;
|
|
208
|
+
private extractArgs;
|
|
209
|
+
private extractUploadPrefix;
|
|
210
|
+
private static backgroundUpload;
|
|
211
|
+
private startPolling;
|
|
212
|
+
/**
|
|
213
|
+
* Abort all in-flight fetch requests to prevent orphaned DNS lookups
|
|
214
|
+
* that can crash the c-ares resolver during process shutdown.
|
|
215
|
+
*/
|
|
216
|
+
private abortInFlightRequests;
|
|
217
|
+
/**
|
|
218
|
+
* Get an AbortSignal for fetch requests. Creates a new controller if needed.
|
|
219
|
+
*/
|
|
220
|
+
private getFetchSignal;
|
|
221
|
+
private post;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* tools/filesystem.ts — Built-in filesystem tools
|
|
226
|
+
*
|
|
227
|
+
* Implements: client_list_directory, client_read_file, client_search_content,
|
|
228
|
+
* client_find_files, client_flag_file
|
|
229
|
+
*
|
|
230
|
+
* Mirrors PRBEAgentTools.swift filesystem tool implementations.
|
|
231
|
+
*/
|
|
232
|
+
|
|
233
|
+
declare class ListDirectoryTool implements PRBETool {
|
|
234
|
+
private readonly autoApprovedDirs;
|
|
235
|
+
private readonly requester?;
|
|
236
|
+
private readonly grantedPaths?;
|
|
237
|
+
constructor(autoApprovedDirs: string[], requester?: PRBEInteractionRequester, grantedPaths?: Set<string>);
|
|
238
|
+
get declaration(): PRBEToolDeclaration;
|
|
239
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
240
|
+
private static readonly MAX_ENTRIES;
|
|
241
|
+
private listDir;
|
|
242
|
+
}
|
|
243
|
+
declare class ReadFileTool implements PRBETool {
|
|
244
|
+
private readonly autoApprovedDirs;
|
|
245
|
+
private readonly requester?;
|
|
246
|
+
private readonly grantedPaths?;
|
|
247
|
+
constructor(autoApprovedDirs: string[], requester?: PRBEInteractionRequester, grantedPaths?: Set<string>);
|
|
248
|
+
get declaration(): PRBEToolDeclaration;
|
|
249
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
250
|
+
}
|
|
251
|
+
declare class SearchContentTool implements PRBETool {
|
|
252
|
+
private readonly autoApprovedDirs;
|
|
253
|
+
private readonly requester?;
|
|
254
|
+
private readonly grantedPaths?;
|
|
255
|
+
constructor(autoApprovedDirs: string[], requester?: PRBEInteractionRequester, grantedPaths?: Set<string>);
|
|
256
|
+
get declaration(): PRBEToolDeclaration;
|
|
257
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
258
|
+
private collectFiles;
|
|
259
|
+
}
|
|
260
|
+
declare class FindFilesTool implements PRBETool {
|
|
261
|
+
private readonly autoApprovedDirs;
|
|
262
|
+
private readonly requester?;
|
|
263
|
+
private readonly grantedPaths?;
|
|
264
|
+
constructor(autoApprovedDirs: string[], requester?: PRBEInteractionRequester, grantedPaths?: Set<string>);
|
|
265
|
+
get declaration(): PRBEToolDeclaration;
|
|
266
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
267
|
+
private walkAndMatch;
|
|
268
|
+
/**
|
|
269
|
+
* Simple glob matching: supports *, ?, and character classes [...].
|
|
270
|
+
* Converts glob to regex and tests against the filename.
|
|
271
|
+
*/
|
|
272
|
+
private globMatch;
|
|
273
|
+
}
|
|
274
|
+
declare class FlagFileTool implements PRBETool {
|
|
275
|
+
private readonly autoApprovedDirs;
|
|
276
|
+
private readonly onFlag;
|
|
277
|
+
private readonly requester?;
|
|
278
|
+
private readonly grantedPaths?;
|
|
279
|
+
private static readonly MAX_BINARY_SIZE;
|
|
280
|
+
constructor(autoApprovedDirs: string[], onFlag: (file: FlaggedFileIn) => void, requester?: PRBEInteractionRequester, grantedPaths?: Set<string>);
|
|
281
|
+
get declaration(): PRBEToolDeclaration;
|
|
282
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* tools/interactive.ts — AskUserTool
|
|
287
|
+
*
|
|
288
|
+
* Allows the agent to ask the user a question during an investigation.
|
|
289
|
+
*/
|
|
290
|
+
|
|
291
|
+
declare class AskUserTool implements PRBETool {
|
|
292
|
+
private readonly requester;
|
|
293
|
+
constructor(requester: PRBEInteractionRequester);
|
|
294
|
+
get declaration(): PRBEToolDeclaration;
|
|
295
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* tools/bash.ts — BashExecuteTool
|
|
300
|
+
*
|
|
301
|
+
* Allows the agent to execute shell commands during investigations.
|
|
302
|
+
* Uses a whitelist-only safety model: commands on the whitelist run without
|
|
303
|
+
* permission; everything else requires user approval.
|
|
304
|
+
*
|
|
305
|
+
* Platform-aware: uses separate whitelists for Unix and Windows, and
|
|
306
|
+
* runs commands via PowerShell on Windows for consistent behavior.
|
|
307
|
+
*/
|
|
308
|
+
|
|
309
|
+
declare class BashExecuteTool implements PRBETool {
|
|
310
|
+
private readonly requester;
|
|
311
|
+
private readonly autoApprovedDirs;
|
|
312
|
+
private readonly grantedPaths;
|
|
313
|
+
constructor(requester: PRBEInteractionRequester, autoApprovedDirs: string[], grantedPaths: Set<string>);
|
|
314
|
+
get declaration(): PRBEToolDeclaration;
|
|
315
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
316
|
+
/**
|
|
317
|
+
* Check if a command is on the safe whitelist.
|
|
318
|
+
*/
|
|
319
|
+
private isCommandSafe;
|
|
320
|
+
/**
|
|
321
|
+
* For piped commands, check that every segment uses a safe command.
|
|
322
|
+
*/
|
|
323
|
+
private areAllPipeSegmentsSafe;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Probe brand mark SVG (transparent background, dark mark).
|
|
328
|
+
* Exported as a string so host apps can use it inline without bundler plugins.
|
|
329
|
+
*/
|
|
330
|
+
declare const PROBE_MARK_SVG = "<svg width=\"256\" height=\"256\" viewBox=\"0 0 256 256\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M50 112 L114 148 L50 184 Z\" fill=\"#111111\" opacity=\"0.07\"/>\n <path d=\"M70 86 L148 134 L70 182 Z\" fill=\"#111111\" opacity=\"0.18\"/>\n <path d=\"M92 56 L192 118 L92 180 Z\" fill=\"#111111\"/>\n</svg>";
|
|
331
|
+
|
|
332
|
+
export { AskUserTool, BashExecuteTool, ClearAppLogsTool, FindFilesTool, FlagAppLogsTool, FlagFileTool, FlaggedFileIn, InteractionPayload, InteractionResponse, InvestigationSource, ListDirectoryTool, type LogEntry, PRBEAgent, PRBEAgentConfig, PRBEAgentState, PRBEClosureTool, PRBEInteractionRequester, PRBELogCapture, type PRBETool, PRBEToolDeclaration, PRBEToolParameter, PRBEToolRegistry, PROBE_MARK_SVG, PollResponse, ReadAppLogsTool, ReadFileTool, SearchAppLogsTool, SearchContentTool, TicketInfoOut, humanReadableSize, resolveAndValidate, resolveWithAccessRequest };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,332 @@
|
|
|
1
|
+
import { P as PRBEToolDeclaration, a as PRBEToolParameter, b as PRBEInteractionRequester, F as FlaggedFileIn, c as PRBEAgentState, d as PRBEAgentConfig, I as InvestigationSource, e as InteractionPayload, f as InteractionResponse, g as PollResponse, T as TicketInfoOut } from './types-DHT-JxMT.js';
|
|
2
|
+
export { A as API_URL, h as AskQuestionPayload, i as AskQuestionResponse, C as ContextRequestOut, D as DEFAULT_PRBE_STATE, j as InteractionType, k as InvestigationResult, M as MIDDLEWARE_URL, l as PRBEAgentConfigKey, m as PRBEAgentError, n as PRBEAgentErrorType, o as PRBEAgentStatus, p as PRBEAgentStatusType, q as PRBECRInvestigation, r as PRBECompletedInvestigation, s as PRBEInteractionHandler, t as PRBESerializedCR, u as PRBESerializedCompletedInvestigation, v as PRBESerializedState, w as PRBESerializedTicket, x as PRBEStateEvent, y as PRBEStatusEvent, z as PollRequest, R as RequestPathAccessPayload, B as RequestPathAccessResponse, E as RequestPermissionPayload, G as RequestPermissionResponse, H as ResolvedInteraction, J as TicketInfoRequest, K as TicketInfoResponse, L as TicketStatusOut, N as ToolName, O as ToolParamType, W as WSMessage, Q as WSMessageType, S as redactPII, U as serializePRBEState } from './types-DHT-JxMT.js';
|
|
3
|
+
import 'events';
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
|
-
* index.ts —
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
* tools/index.ts — Tool interface, registry, and closure tool
|
|
7
|
+
*
|
|
8
|
+
* Mirrors PRBEAgentTools.swift tool protocol + registry pattern.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
interface PRBETool {
|
|
12
|
+
readonly declaration: PRBEToolDeclaration;
|
|
13
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
14
|
+
}
|
|
15
|
+
declare class PRBEToolRegistry {
|
|
16
|
+
private tools;
|
|
17
|
+
register(tool: PRBETool): void;
|
|
18
|
+
allDeclarations(): PRBEToolDeclaration[];
|
|
19
|
+
execute(name: string, args: Record<string, unknown>): Promise<string>;
|
|
20
|
+
}
|
|
21
|
+
declare class PRBEClosureTool implements PRBETool {
|
|
22
|
+
readonly declaration: PRBEToolDeclaration;
|
|
23
|
+
private readonly handler;
|
|
24
|
+
constructor(name: string, description: string, parameters: PRBEToolParameter[], handler: (args: Record<string, unknown>) => Promise<string>);
|
|
25
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Resolve a path string and validate it against auto-approved directories.
|
|
29
|
+
* Returns the resolved absolute path or null if outside auto-approved directories.
|
|
30
|
+
*/
|
|
31
|
+
declare function resolveAndValidate(pathStr: string, autoApprovedDirs: string[]): string | null;
|
|
32
|
+
/** Result of resolveWithAccessRequest — resolved path, null (silently denied), or error string for the agent */
|
|
33
|
+
type PathResolution = {
|
|
34
|
+
path: string;
|
|
35
|
+
} | {
|
|
36
|
+
error: string;
|
|
37
|
+
} | null;
|
|
38
|
+
/**
|
|
39
|
+
* Resolve a path, requesting user access if outside auto-approved directories.
|
|
40
|
+
* When a requester is available and the path fails validation, prompts
|
|
41
|
+
* the user for permission and caches the grant in `grantedPaths`.
|
|
42
|
+
*
|
|
43
|
+
* Returns { path } on success, { error } with a message for the agent, or null.
|
|
44
|
+
*/
|
|
45
|
+
declare function resolveWithAccessRequest(pathStr: string, autoApprovedDirs: string[], grantedPaths: Set<string>, requester?: PRBEInteractionRequester): Promise<PathResolution>;
|
|
46
|
+
/**
|
|
47
|
+
* Format byte sizes for human-readable output.
|
|
48
|
+
*/
|
|
49
|
+
declare function humanReadableSize(bytes: number): string;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* tools/logs.ts — Log capture + built-in log tools
|
|
53
|
+
*
|
|
54
|
+
* Implements: client_read_app_logs, client_search_app_logs,
|
|
55
|
+
* client_clear_app_logs, client_flag_app_logs
|
|
56
|
+
*
|
|
57
|
+
* Mirrors PRBELogCapture.swift + log tool implementations from PRBEAgentTools.swift.
|
|
58
|
+
* Log capture works by monkey-patching console.log/warn/error in the Electron main process.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
interface LogEntry {
|
|
62
|
+
timestamp: Date;
|
|
63
|
+
level: string;
|
|
64
|
+
category: string;
|
|
65
|
+
message: string;
|
|
66
|
+
}
|
|
67
|
+
declare class PRBELogCapture {
|
|
68
|
+
private entries;
|
|
69
|
+
private readonly maxEntries;
|
|
70
|
+
private isCapturing;
|
|
71
|
+
private originalLog?;
|
|
72
|
+
private originalWarn?;
|
|
73
|
+
private originalError?;
|
|
74
|
+
private originalDebug?;
|
|
75
|
+
private originalInfo?;
|
|
76
|
+
constructor(maxEntries?: number);
|
|
77
|
+
log(message: string, level?: string, category?: string): void;
|
|
78
|
+
get count(): number;
|
|
79
|
+
getEntries(options?: {
|
|
80
|
+
offset?: number;
|
|
81
|
+
limit?: number;
|
|
82
|
+
level?: string;
|
|
83
|
+
from?: Date;
|
|
84
|
+
to?: Date;
|
|
85
|
+
}): LogEntry[];
|
|
86
|
+
search(pattern: string, contextLines?: number, maxResults?: number): Array<{
|
|
87
|
+
index: number;
|
|
88
|
+
entry: LogEntry;
|
|
89
|
+
}>;
|
|
90
|
+
clearLogs(): number;
|
|
91
|
+
startCapturing(): void;
|
|
92
|
+
stopCapturing(): void;
|
|
93
|
+
getAllEntries(): LogEntry[];
|
|
94
|
+
private append;
|
|
95
|
+
}
|
|
96
|
+
declare class ReadAppLogsTool implements PRBETool {
|
|
97
|
+
private readonly logCapture;
|
|
98
|
+
constructor(logCapture: PRBELogCapture);
|
|
99
|
+
get declaration(): PRBEToolDeclaration;
|
|
100
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
101
|
+
}
|
|
102
|
+
declare class SearchAppLogsTool implements PRBETool {
|
|
103
|
+
private readonly logCapture;
|
|
104
|
+
constructor(logCapture: PRBELogCapture);
|
|
105
|
+
get declaration(): PRBEToolDeclaration;
|
|
106
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
107
|
+
}
|
|
108
|
+
declare class ClearAppLogsTool implements PRBETool {
|
|
109
|
+
private readonly logCapture;
|
|
110
|
+
constructor(logCapture: PRBELogCapture);
|
|
111
|
+
get declaration(): PRBEToolDeclaration;
|
|
112
|
+
execute(_args: Record<string, unknown>): Promise<string>;
|
|
113
|
+
}
|
|
114
|
+
declare class FlagAppLogsTool implements PRBETool {
|
|
115
|
+
private readonly logCapture;
|
|
116
|
+
private readonly onFlag;
|
|
117
|
+
constructor(logCapture: PRBELogCapture, onFlag: (file: FlaggedFileIn) => void);
|
|
118
|
+
get declaration(): PRBEToolDeclaration;
|
|
119
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* agent.ts — PRBEAgent class
|
|
124
|
+
*
|
|
125
|
+
* Main entry point for the PRBE debug agent SDK.
|
|
126
|
+
* Handles WebSocket connection to middleware, investigation lifecycle,
|
|
127
|
+
* background polling for context requests, file uploads, and persistence.
|
|
128
|
+
*
|
|
129
|
+
* Mirrors PRBEAgent.swift behavior.
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
declare class PRBEAgent implements PRBEInteractionRequester {
|
|
133
|
+
readonly state: PRBEAgentState;
|
|
134
|
+
readonly logCapture: PRBELogCapture;
|
|
135
|
+
private readonly config;
|
|
136
|
+
private readonly appDataPath?;
|
|
137
|
+
private readonly interactionHandler?;
|
|
138
|
+
private readonly registry;
|
|
139
|
+
private readonly grantedPaths;
|
|
140
|
+
private userCancelled;
|
|
141
|
+
private activeWS;
|
|
142
|
+
private pollingTimer;
|
|
143
|
+
private persistedData;
|
|
144
|
+
private fetchAbortController;
|
|
145
|
+
private currentInvestigationSource;
|
|
146
|
+
private currentCRId;
|
|
147
|
+
/** Files flagged during the current tool call — uploaded immediately after the tool returns. */
|
|
148
|
+
private pendingFlaggedFiles;
|
|
149
|
+
private get agentID();
|
|
150
|
+
private get trackedTicketIDs();
|
|
151
|
+
private set trackedTicketIDs(value);
|
|
152
|
+
private get respondedCRIDs();
|
|
153
|
+
private set respondedCRIDs(value);
|
|
154
|
+
private syncPolling;
|
|
155
|
+
private addTrackedTicket;
|
|
156
|
+
constructor(config: PRBEAgentConfig);
|
|
157
|
+
private hookElectronLog;
|
|
158
|
+
private hookRendererLogs;
|
|
159
|
+
private static mapElectronLogLevel;
|
|
160
|
+
get investigationSource(): InvestigationSource;
|
|
161
|
+
requestUserInteraction(payload: InteractionPayload): Promise<InteractionResponse>;
|
|
162
|
+
/**
|
|
163
|
+
* Add an additional root directory to the runtime allowed roots.
|
|
164
|
+
*/
|
|
165
|
+
addAutoApprovedDir(rootPath: string): void;
|
|
166
|
+
/**
|
|
167
|
+
* Register a custom tool that the middleware can invoke during investigations.
|
|
168
|
+
*/
|
|
169
|
+
registerTool(name: string, description: string, parameters: PRBEToolParameter[], handler: (args: Record<string, unknown>) => Promise<string>): void;
|
|
170
|
+
/**
|
|
171
|
+
* User-initiated investigation. Updates `state` events/report directly.
|
|
172
|
+
*/
|
|
173
|
+
investigate(query: string, contextRequestID?: string): Promise<void>;
|
|
174
|
+
/**
|
|
175
|
+
* Cancel user-initiated investigation only (does not cancel background CRs).
|
|
176
|
+
*/
|
|
177
|
+
cancelInvestigation(): void;
|
|
178
|
+
/**
|
|
179
|
+
* Cancel everything — user investigation and polling.
|
|
180
|
+
*/
|
|
181
|
+
cancel(): void;
|
|
182
|
+
/**
|
|
183
|
+
* Poll the backend for context requests on tracked tickets.
|
|
184
|
+
*/
|
|
185
|
+
poll(): Promise<PollResponse | null>;
|
|
186
|
+
/**
|
|
187
|
+
* Fetch ticket display info for all tracked tickets.
|
|
188
|
+
*/
|
|
189
|
+
fetchTicketInfo(): Promise<TicketInfoOut[]>;
|
|
190
|
+
stopPolling(): void;
|
|
191
|
+
resumePolling(): void;
|
|
192
|
+
/**
|
|
193
|
+
* Destroy the agent — stops polling, stops console capture, closes WS.
|
|
194
|
+
*/
|
|
195
|
+
destroy(): void;
|
|
196
|
+
/**
|
|
197
|
+
* Reset all persisted data (agent ID, tracked tickets, responded CRs).
|
|
198
|
+
* Also clears in-memory state.
|
|
199
|
+
*/
|
|
200
|
+
resetPersistedData(): void;
|
|
201
|
+
/**
|
|
202
|
+
* Delete the persisted data file. Can be called without an agent instance.
|
|
203
|
+
*/
|
|
204
|
+
static clearPersistedData(): void;
|
|
205
|
+
private investigateForCR;
|
|
206
|
+
private connectToProxy;
|
|
207
|
+
private sendCancel;
|
|
208
|
+
private extractArgs;
|
|
209
|
+
private extractUploadPrefix;
|
|
210
|
+
private static backgroundUpload;
|
|
211
|
+
private startPolling;
|
|
212
|
+
/**
|
|
213
|
+
* Abort all in-flight fetch requests to prevent orphaned DNS lookups
|
|
214
|
+
* that can crash the c-ares resolver during process shutdown.
|
|
215
|
+
*/
|
|
216
|
+
private abortInFlightRequests;
|
|
217
|
+
/**
|
|
218
|
+
* Get an AbortSignal for fetch requests. Creates a new controller if needed.
|
|
219
|
+
*/
|
|
220
|
+
private getFetchSignal;
|
|
221
|
+
private post;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* tools/filesystem.ts — Built-in filesystem tools
|
|
226
|
+
*
|
|
227
|
+
* Implements: client_list_directory, client_read_file, client_search_content,
|
|
228
|
+
* client_find_files, client_flag_file
|
|
229
|
+
*
|
|
230
|
+
* Mirrors PRBEAgentTools.swift filesystem tool implementations.
|
|
231
|
+
*/
|
|
232
|
+
|
|
233
|
+
declare class ListDirectoryTool implements PRBETool {
|
|
234
|
+
private readonly autoApprovedDirs;
|
|
235
|
+
private readonly requester?;
|
|
236
|
+
private readonly grantedPaths?;
|
|
237
|
+
constructor(autoApprovedDirs: string[], requester?: PRBEInteractionRequester, grantedPaths?: Set<string>);
|
|
238
|
+
get declaration(): PRBEToolDeclaration;
|
|
239
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
240
|
+
private static readonly MAX_ENTRIES;
|
|
241
|
+
private listDir;
|
|
242
|
+
}
|
|
243
|
+
declare class ReadFileTool implements PRBETool {
|
|
244
|
+
private readonly autoApprovedDirs;
|
|
245
|
+
private readonly requester?;
|
|
246
|
+
private readonly grantedPaths?;
|
|
247
|
+
constructor(autoApprovedDirs: string[], requester?: PRBEInteractionRequester, grantedPaths?: Set<string>);
|
|
248
|
+
get declaration(): PRBEToolDeclaration;
|
|
249
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
250
|
+
}
|
|
251
|
+
declare class SearchContentTool implements PRBETool {
|
|
252
|
+
private readonly autoApprovedDirs;
|
|
253
|
+
private readonly requester?;
|
|
254
|
+
private readonly grantedPaths?;
|
|
255
|
+
constructor(autoApprovedDirs: string[], requester?: PRBEInteractionRequester, grantedPaths?: Set<string>);
|
|
256
|
+
get declaration(): PRBEToolDeclaration;
|
|
257
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
258
|
+
private collectFiles;
|
|
259
|
+
}
|
|
260
|
+
declare class FindFilesTool implements PRBETool {
|
|
261
|
+
private readonly autoApprovedDirs;
|
|
262
|
+
private readonly requester?;
|
|
263
|
+
private readonly grantedPaths?;
|
|
264
|
+
constructor(autoApprovedDirs: string[], requester?: PRBEInteractionRequester, grantedPaths?: Set<string>);
|
|
265
|
+
get declaration(): PRBEToolDeclaration;
|
|
266
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
267
|
+
private walkAndMatch;
|
|
268
|
+
/**
|
|
269
|
+
* Simple glob matching: supports *, ?, and character classes [...].
|
|
270
|
+
* Converts glob to regex and tests against the filename.
|
|
271
|
+
*/
|
|
272
|
+
private globMatch;
|
|
273
|
+
}
|
|
274
|
+
declare class FlagFileTool implements PRBETool {
|
|
275
|
+
private readonly autoApprovedDirs;
|
|
276
|
+
private readonly onFlag;
|
|
277
|
+
private readonly requester?;
|
|
278
|
+
private readonly grantedPaths?;
|
|
279
|
+
private static readonly MAX_BINARY_SIZE;
|
|
280
|
+
constructor(autoApprovedDirs: string[], onFlag: (file: FlaggedFileIn) => void, requester?: PRBEInteractionRequester, grantedPaths?: Set<string>);
|
|
281
|
+
get declaration(): PRBEToolDeclaration;
|
|
282
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* tools/interactive.ts — AskUserTool
|
|
287
|
+
*
|
|
288
|
+
* Allows the agent to ask the user a question during an investigation.
|
|
289
|
+
*/
|
|
290
|
+
|
|
291
|
+
declare class AskUserTool implements PRBETool {
|
|
292
|
+
private readonly requester;
|
|
293
|
+
constructor(requester: PRBEInteractionRequester);
|
|
294
|
+
get declaration(): PRBEToolDeclaration;
|
|
295
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* tools/bash.ts — BashExecuteTool
|
|
300
|
+
*
|
|
301
|
+
* Allows the agent to execute shell commands during investigations.
|
|
302
|
+
* Uses a whitelist-only safety model: commands on the whitelist run without
|
|
303
|
+
* permission; everything else requires user approval.
|
|
304
|
+
*
|
|
305
|
+
* Platform-aware: uses separate whitelists for Unix and Windows, and
|
|
306
|
+
* runs commands via PowerShell on Windows for consistent behavior.
|
|
307
|
+
*/
|
|
308
|
+
|
|
309
|
+
declare class BashExecuteTool implements PRBETool {
|
|
310
|
+
private readonly requester;
|
|
311
|
+
private readonly autoApprovedDirs;
|
|
312
|
+
private readonly grantedPaths;
|
|
313
|
+
constructor(requester: PRBEInteractionRequester, autoApprovedDirs: string[], grantedPaths: Set<string>);
|
|
314
|
+
get declaration(): PRBEToolDeclaration;
|
|
315
|
+
execute(args: Record<string, unknown>): Promise<string>;
|
|
316
|
+
/**
|
|
317
|
+
* Check if a command is on the safe whitelist.
|
|
318
|
+
*/
|
|
319
|
+
private isCommandSafe;
|
|
320
|
+
/**
|
|
321
|
+
* For piped commands, check that every segment uses a safe command.
|
|
322
|
+
*/
|
|
323
|
+
private areAllPipeSegmentsSafe;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Probe brand mark SVG (transparent background, dark mark).
|
|
328
|
+
* Exported as a string so host apps can use it inline without bundler plugins.
|
|
329
|
+
*/
|
|
330
|
+
declare const PROBE_MARK_SVG = "<svg width=\"256\" height=\"256\" viewBox=\"0 0 256 256\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M50 112 L114 148 L50 184 Z\" fill=\"#111111\" opacity=\"0.07\"/>\n <path d=\"M70 86 L148 134 L70 182 Z\" fill=\"#111111\" opacity=\"0.18\"/>\n <path d=\"M92 56 L192 118 L92 180 Z\" fill=\"#111111\"/>\n</svg>";
|
|
331
|
+
|
|
332
|
+
export { AskUserTool, BashExecuteTool, ClearAppLogsTool, FindFilesTool, FlagAppLogsTool, FlagFileTool, FlaggedFileIn, InteractionPayload, InteractionResponse, InvestigationSource, ListDirectoryTool, type LogEntry, PRBEAgent, PRBEAgentConfig, PRBEAgentState, PRBEClosureTool, PRBEInteractionRequester, PRBELogCapture, type PRBETool, PRBEToolDeclaration, PRBEToolParameter, PRBEToolRegistry, PROBE_MARK_SVG, PollResponse, ReadAppLogsTool, ReadFileTool, SearchAppLogsTool, SearchContentTool, TicketInfoOut, humanReadableSize, resolveAndValidate, resolveWithAccessRequest };
|