@prbe.ai/electron-sdk 0.1.7 → 0.1.9
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 +15 -8
- package/dist/index.d.ts +15 -8
- package/dist/index.js +78 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -53
- package/dist/index.mjs.map +1 -1
- package/dist/{types-CwYRJCG0.d.mts → types-CeIldtlI.d.mts} +17 -4
- package/dist/{types-CwYRJCG0.d.ts → types-CeIldtlI.d.ts} +17 -4
- package/dist/types.d.mts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/types.mjs +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -122,7 +122,7 @@ var PRBEAgentState = class extends EventEmitter {
|
|
|
122
122
|
activeCRs = /* @__PURE__ */ new Map();
|
|
123
123
|
completedCRs = [];
|
|
124
124
|
// Tracked tickets
|
|
125
|
-
|
|
125
|
+
trackedSessionIDs = [];
|
|
126
126
|
ticketInfo = [];
|
|
127
127
|
// Computed
|
|
128
128
|
get hasActiveWork() {
|
|
@@ -350,8 +350,8 @@ var PRBEAgentState = class extends EventEmitter {
|
|
|
350
350
|
this.emit("status" /* STATUS */);
|
|
351
351
|
}
|
|
352
352
|
// ---------- Tickets ----------
|
|
353
|
-
|
|
354
|
-
this.
|
|
353
|
+
updateTrackedSessionIDs(ids) {
|
|
354
|
+
this.trackedSessionIDs = ids;
|
|
355
355
|
this.emit("tickets-changed" /* TICKETS_CHANGED */, ids);
|
|
356
356
|
this.emit("status" /* STATUS */);
|
|
357
357
|
}
|
|
@@ -399,8 +399,13 @@ var PRBEToolRegistry = class {
|
|
|
399
399
|
var PRBEClosureTool = class {
|
|
400
400
|
declaration;
|
|
401
401
|
handler;
|
|
402
|
-
constructor(name, description, parameters, handler) {
|
|
403
|
-
this.declaration = {
|
|
402
|
+
constructor(name, description, parameters, handler, options) {
|
|
403
|
+
this.declaration = {
|
|
404
|
+
name,
|
|
405
|
+
description,
|
|
406
|
+
parameters,
|
|
407
|
+
...options?.interactive ? { interactive: true } : {}
|
|
408
|
+
};
|
|
404
409
|
this.handler = handler;
|
|
405
410
|
}
|
|
406
411
|
async execute(args) {
|
|
@@ -1735,13 +1740,13 @@ var PRBEAgent = class _PRBEAgent {
|
|
|
1735
1740
|
savePersistedData(this.persistedData);
|
|
1736
1741
|
return newID;
|
|
1737
1742
|
}
|
|
1738
|
-
get
|
|
1739
|
-
return this.persistedData.
|
|
1743
|
+
get trackedSessionIDs() {
|
|
1744
|
+
return this.persistedData.sessionIds ?? [];
|
|
1740
1745
|
}
|
|
1741
|
-
set
|
|
1742
|
-
this.persistedData.
|
|
1746
|
+
set trackedSessionIDs(ids) {
|
|
1747
|
+
this.persistedData.sessionIds = ids;
|
|
1743
1748
|
savePersistedData(this.persistedData);
|
|
1744
|
-
this.state.
|
|
1749
|
+
this.state.updateTrackedSessionIDs(ids);
|
|
1745
1750
|
this.syncPolling(ids.length > 0);
|
|
1746
1751
|
}
|
|
1747
1752
|
get respondedCRIDs() {
|
|
@@ -1751,19 +1756,19 @@ var PRBEAgent = class _PRBEAgent {
|
|
|
1751
1756
|
this.persistedData.respondedCRIds = Array.from(ids);
|
|
1752
1757
|
savePersistedData(this.persistedData);
|
|
1753
1758
|
}
|
|
1754
|
-
syncPolling(
|
|
1755
|
-
if (this.config.backgroundPolling &&
|
|
1759
|
+
syncPolling(hasSessions) {
|
|
1760
|
+
if (this.config.backgroundPolling && hasSessions) {
|
|
1756
1761
|
if (this.pollingTimer === null) {
|
|
1757
1762
|
this.startPolling();
|
|
1758
1763
|
}
|
|
1759
|
-
} else if (!
|
|
1764
|
+
} else if (!hasSessions) {
|
|
1760
1765
|
this.stopPolling();
|
|
1761
1766
|
}
|
|
1762
1767
|
}
|
|
1763
|
-
|
|
1764
|
-
const ids = this.
|
|
1768
|
+
addTrackedSession(id) {
|
|
1769
|
+
const ids = this.trackedSessionIDs;
|
|
1765
1770
|
if (!ids.includes(id)) {
|
|
1766
|
-
this.
|
|
1771
|
+
this.trackedSessionIDs = [...ids, id];
|
|
1767
1772
|
}
|
|
1768
1773
|
}
|
|
1769
1774
|
// ---------- Constructor ----------
|
|
@@ -1821,9 +1826,9 @@ var PRBEAgent = class _PRBEAgent {
|
|
|
1821
1826
|
if (config.ipcMain) {
|
|
1822
1827
|
this.hookRendererLogs(config.ipcMain, config.rendererLogChannel ?? "prbe-renderer-log");
|
|
1823
1828
|
}
|
|
1824
|
-
const
|
|
1825
|
-
if (
|
|
1826
|
-
this.
|
|
1829
|
+
const existingSessions = this.trackedSessionIDs;
|
|
1830
|
+
if (existingSessions.length > 0) {
|
|
1831
|
+
this.trackedSessionIDs = existingSessions;
|
|
1827
1832
|
}
|
|
1828
1833
|
}
|
|
1829
1834
|
// ---------- Log integration ----------
|
|
@@ -1908,9 +1913,9 @@ var PRBEAgent = class _PRBEAgent {
|
|
|
1908
1913
|
/**
|
|
1909
1914
|
* Register a custom tool that the middleware can invoke during investigations.
|
|
1910
1915
|
*/
|
|
1911
|
-
registerTool(name, description, parameters, handler) {
|
|
1916
|
+
registerTool(name, description, parameters, handler, options) {
|
|
1912
1917
|
this.registry.register(
|
|
1913
|
-
new PRBEClosureTool(name, description, parameters, handler)
|
|
1918
|
+
new PRBEClosureTool(name, description, parameters, handler, options)
|
|
1914
1919
|
);
|
|
1915
1920
|
}
|
|
1916
1921
|
/**
|
|
@@ -1954,8 +1959,8 @@ var PRBEAgent = class _PRBEAgent {
|
|
|
1954
1959
|
);
|
|
1955
1960
|
this.currentInvestigationSource = "user" /* USER */;
|
|
1956
1961
|
this.currentCRId = null;
|
|
1957
|
-
if (result?.
|
|
1958
|
-
this.
|
|
1962
|
+
if (result?.sessionId) {
|
|
1963
|
+
this.addTrackedSession(result.sessionId);
|
|
1959
1964
|
} else if (!result) {
|
|
1960
1965
|
if (this.state.isInvestigating) {
|
|
1961
1966
|
const message = this.userCancelled ? "Investigation cancelled" : "Investigation ended unexpectedly";
|
|
@@ -1987,33 +1992,37 @@ var PRBEAgent = class _PRBEAgent {
|
|
|
1987
1992
|
}
|
|
1988
1993
|
/**
|
|
1989
1994
|
* Poll the backend for context requests on tracked tickets.
|
|
1995
|
+
* Resolves session IDs → ticket IDs first, then polls with ticket IDs.
|
|
1990
1996
|
*/
|
|
1991
1997
|
async poll() {
|
|
1992
|
-
const
|
|
1993
|
-
if (
|
|
1994
|
-
const request = {
|
|
1995
|
-
agent_id: this.agentID,
|
|
1996
|
-
ticket_ids: ticketIDs
|
|
1997
|
-
};
|
|
1998
|
+
const sessionIDs = this.trackedSessionIDs;
|
|
1999
|
+
if (sessionIDs.length === 0) return null;
|
|
1998
2000
|
try {
|
|
2001
|
+
const resolved = await this.resolveSessions(sessionIDs);
|
|
2002
|
+
const returnedSessionIDs = new Set(
|
|
2003
|
+
resolved.tickets.flatMap((t) => t.session_ids)
|
|
2004
|
+
);
|
|
2005
|
+
const resolvedSessionIDs = new Set(
|
|
2006
|
+
resolved.tickets.filter((t) => t.status === "resolved").flatMap((t) => t.session_ids)
|
|
2007
|
+
);
|
|
2008
|
+
const survivingSessions = sessionIDs.filter(
|
|
2009
|
+
(id) => returnedSessionIDs.has(id) && !resolvedSessionIDs.has(id)
|
|
2010
|
+
);
|
|
2011
|
+
if (survivingSessions.length !== sessionIDs.length) {
|
|
2012
|
+
this.trackedSessionIDs = survivingSessions;
|
|
2013
|
+
}
|
|
2014
|
+
const ticketIDs = resolved.tickets.filter((t) => t.status !== "resolved").map((t) => t.ticket_id);
|
|
2015
|
+
if (ticketIDs.length === 0) return { tickets: [] };
|
|
2016
|
+
const request = {
|
|
2017
|
+
agent_id: this.agentID,
|
|
2018
|
+
ticket_ids: ticketIDs
|
|
2019
|
+
};
|
|
1999
2020
|
const response = await this.post(
|
|
2000
2021
|
"/api/agent/poll",
|
|
2001
2022
|
request
|
|
2002
2023
|
);
|
|
2003
|
-
const returnedIDs = new Set(response.tickets.map((t) => t.ticket_id));
|
|
2004
|
-
const orphaned = ticketIDs.filter((id) => !returnedIDs.has(id));
|
|
2005
|
-
if (orphaned.length > 0) {
|
|
2006
|
-
this.trackedTicketIDs = this.trackedTicketIDs.filter(
|
|
2007
|
-
(id) => !orphaned.includes(id)
|
|
2008
|
-
);
|
|
2009
|
-
}
|
|
2010
2024
|
const knownCRIDs = /* @__PURE__ */ new Set();
|
|
2011
2025
|
for (const ticket of response.tickets) {
|
|
2012
|
-
if (ticket.status === "resolved") {
|
|
2013
|
-
this.trackedTicketIDs = this.trackedTicketIDs.filter(
|
|
2014
|
-
(id) => id !== ticket.ticket_id
|
|
2015
|
-
);
|
|
2016
|
-
}
|
|
2017
2026
|
for (const cr of ticket.context_requests) {
|
|
2018
2027
|
knownCRIDs.add(cr.id);
|
|
2019
2028
|
if (!cr.is_active || this.respondedCRIDs.has(cr.id)) continue;
|
|
@@ -2039,13 +2048,17 @@ var PRBEAgent = class _PRBEAgent {
|
|
|
2039
2048
|
}
|
|
2040
2049
|
}
|
|
2041
2050
|
/**
|
|
2042
|
-
* Fetch ticket display info for all tracked
|
|
2051
|
+
* Fetch ticket display info for all tracked sessions.
|
|
2052
|
+
* Resolves session IDs → ticket IDs first, then fetches ticket info.
|
|
2043
2053
|
*/
|
|
2044
2054
|
async fetchTicketInfo() {
|
|
2045
|
-
const
|
|
2046
|
-
if (
|
|
2047
|
-
const request = { ticket_ids: ticketIDs };
|
|
2055
|
+
const sessionIDs = this.trackedSessionIDs;
|
|
2056
|
+
if (sessionIDs.length === 0) return [];
|
|
2048
2057
|
try {
|
|
2058
|
+
const resolved = await this.resolveSessions(sessionIDs);
|
|
2059
|
+
const ticketIDs = resolved.tickets.map((t) => t.ticket_id);
|
|
2060
|
+
if (ticketIDs.length === 0) return [];
|
|
2061
|
+
const request = { ticket_ids: ticketIDs };
|
|
2049
2062
|
const response = await this.post(
|
|
2050
2063
|
"/api/agent/tickets",
|
|
2051
2064
|
request
|
|
@@ -2063,7 +2076,7 @@ var PRBEAgent = class _PRBEAgent {
|
|
|
2063
2076
|
}
|
|
2064
2077
|
}
|
|
2065
2078
|
resumePolling() {
|
|
2066
|
-
if (this.
|
|
2079
|
+
if (this.trackedSessionIDs.length === 0) return;
|
|
2067
2080
|
this.startPolling();
|
|
2068
2081
|
}
|
|
2069
2082
|
/**
|
|
@@ -2086,7 +2099,7 @@ var PRBEAgent = class _PRBEAgent {
|
|
|
2086
2099
|
this.state.completedInvestigations = [];
|
|
2087
2100
|
this.state.activeCRs.clear();
|
|
2088
2101
|
this.state.completedCRs = [];
|
|
2089
|
-
this.state.
|
|
2102
|
+
this.state.trackedSessionIDs = [];
|
|
2090
2103
|
this.state.ticketInfo = [];
|
|
2091
2104
|
this.state.emit("status" /* STATUS */);
|
|
2092
2105
|
}
|
|
@@ -2145,8 +2158,8 @@ var PRBEAgent = class _PRBEAgent {
|
|
|
2145
2158
|
);
|
|
2146
2159
|
this.currentInvestigationSource = "user" /* USER */;
|
|
2147
2160
|
this.currentCRId = null;
|
|
2148
|
-
if (result?.
|
|
2149
|
-
this.
|
|
2161
|
+
if (result?.sessionId) {
|
|
2162
|
+
this.addTrackedSession(result.sessionId);
|
|
2150
2163
|
}
|
|
2151
2164
|
}
|
|
2152
2165
|
// ---------- WebSocket Investigation ----------
|
|
@@ -2323,6 +2336,7 @@ var PRBEAgent = class _PRBEAgent {
|
|
|
2323
2336
|
const report = msg.content ?? "";
|
|
2324
2337
|
const userSummary = msg.metadata?.["user_summary"] ?? "";
|
|
2325
2338
|
const ticketId2 = msg.metadata?.["ticket_id"];
|
|
2339
|
+
const sessionId = msg.metadata?.["session_id"];
|
|
2326
2340
|
emit({
|
|
2327
2341
|
type: "completed" /* COMPLETED */,
|
|
2328
2342
|
report,
|
|
@@ -2330,7 +2344,7 @@ var PRBEAgent = class _PRBEAgent {
|
|
|
2330
2344
|
ticketId: ticketId2
|
|
2331
2345
|
});
|
|
2332
2346
|
ws.close(1e3, "Complete");
|
|
2333
|
-
finish({ report, userSummary, ticketId: ticketId2 });
|
|
2347
|
+
finish({ report, userSummary, ticketId: ticketId2, sessionId });
|
|
2334
2348
|
break;
|
|
2335
2349
|
}
|
|
2336
2350
|
case "error" /* ERROR */:
|
|
@@ -2441,12 +2455,23 @@ var PRBEAgent = class _PRBEAgent {
|
|
|
2441
2455
|
this.stopPolling();
|
|
2442
2456
|
this.pollingTimer = setInterval(() => {
|
|
2443
2457
|
void this.poll().then(() => {
|
|
2444
|
-
if (this.
|
|
2458
|
+
if (this.trackedSessionIDs.length === 0) {
|
|
2445
2459
|
this.stopPolling();
|
|
2446
2460
|
}
|
|
2447
2461
|
});
|
|
2448
2462
|
}, this.config.pollingInterval);
|
|
2449
2463
|
}
|
|
2464
|
+
// ---------- Session Resolution ----------
|
|
2465
|
+
async resolveSessions(sessionIDs) {
|
|
2466
|
+
const request = {
|
|
2467
|
+
agent_id: this.agentID,
|
|
2468
|
+
session_ids: sessionIDs
|
|
2469
|
+
};
|
|
2470
|
+
return this.post(
|
|
2471
|
+
"/api/agent/resolve-sessions",
|
|
2472
|
+
request
|
|
2473
|
+
);
|
|
2474
|
+
}
|
|
2450
2475
|
// ---------- Networking ----------
|
|
2451
2476
|
/**
|
|
2452
2477
|
* Abort all in-flight fetch requests to prevent orphaned DNS lookups
|
|
@@ -2501,7 +2526,7 @@ var DEFAULT_PRBE_STATE = {
|
|
|
2501
2526
|
completedInvestigations: [],
|
|
2502
2527
|
activeCRs: [],
|
|
2503
2528
|
completedCRs: [],
|
|
2504
|
-
|
|
2529
|
+
trackedSessionIDs: [],
|
|
2505
2530
|
ticketInfo: [],
|
|
2506
2531
|
hasActiveWork: false
|
|
2507
2532
|
};
|
|
@@ -2545,7 +2570,7 @@ function serializePRBEState(state) {
|
|
|
2545
2570
|
})),
|
|
2546
2571
|
activeCRs: Array.from(state.activeCRs.values()).map(serializeCR),
|
|
2547
2572
|
completedCRs: state.completedCRs.map(serializeCR),
|
|
2548
|
-
|
|
2573
|
+
trackedSessionIDs: state.trackedSessionIDs,
|
|
2549
2574
|
ticketInfo: state.ticketInfo,
|
|
2550
2575
|
hasActiveWork: state.hasActiveWork
|
|
2551
2576
|
};
|