@prbe.ai/electron-sdk 0.1.8 → 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 CHANGED
@@ -1,5 +1,5 @@
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-CwYRJCG0.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-CwYRJCG0.mjs';
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-CeIldtlI.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 ResolveSessionsRequest, J as ResolveSessionsResponse, K as ResolvedInteraction, L as ResolvedTicketOut, N as TicketInfoRequest, O as TicketInfoResponse, Q as TicketStatusOut, S as ToolName, U as ToolParamType, W as WSMessage, V as WSMessageType, X as redactPII, Y as serializePRBEState } from './types-CeIldtlI.mjs';
3
3
  import 'events';
4
4
 
5
5
  /**
@@ -150,12 +150,12 @@ declare class PRBEAgent implements PRBEInteractionRequester {
150
150
  /** Files flagged during the current tool call — uploaded immediately after the tool returns. */
151
151
  private pendingFlaggedFiles;
152
152
  private get agentID();
153
- private get trackedTicketIDs();
154
- private set trackedTicketIDs(value);
153
+ private get trackedSessionIDs();
154
+ private set trackedSessionIDs(value);
155
155
  private get respondedCRIDs();
156
156
  private set respondedCRIDs(value);
157
157
  private syncPolling;
158
- private addTrackedTicket;
158
+ private addTrackedSession;
159
159
  constructor(config: PRBEAgentConfig);
160
160
  private hookElectronLog;
161
161
  private hookRendererLogs;
@@ -186,10 +186,12 @@ declare class PRBEAgent implements PRBEInteractionRequester {
186
186
  cancel(): void;
187
187
  /**
188
188
  * Poll the backend for context requests on tracked tickets.
189
+ * Resolves session IDs → ticket IDs first, then polls with ticket IDs.
189
190
  */
190
191
  poll(): Promise<PollResponse | null>;
191
192
  /**
192
- * Fetch ticket display info for all tracked tickets.
193
+ * Fetch ticket display info for all tracked sessions.
194
+ * Resolves session IDs → ticket IDs first, then fetches ticket info.
193
195
  */
194
196
  fetchTicketInfo(): Promise<TicketInfoOut[]>;
195
197
  stopPolling(): void;
@@ -214,6 +216,7 @@ declare class PRBEAgent implements PRBEInteractionRequester {
214
216
  private extractUploadPrefix;
215
217
  private static backgroundUpload;
216
218
  private startPolling;
219
+ private resolveSessions;
217
220
  /**
218
221
  * Abort all in-flight fetch requests to prevent orphaned DNS lookups
219
222
  * that can crash the c-ares resolver during process shutdown.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
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-CwYRJCG0.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-CwYRJCG0.js';
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-CeIldtlI.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 ResolveSessionsRequest, J as ResolveSessionsResponse, K as ResolvedInteraction, L as ResolvedTicketOut, N as TicketInfoRequest, O as TicketInfoResponse, Q as TicketStatusOut, S as ToolName, U as ToolParamType, W as WSMessage, V as WSMessageType, X as redactPII, Y as serializePRBEState } from './types-CeIldtlI.js';
3
3
  import 'events';
4
4
 
5
5
  /**
@@ -150,12 +150,12 @@ declare class PRBEAgent implements PRBEInteractionRequester {
150
150
  /** Files flagged during the current tool call — uploaded immediately after the tool returns. */
151
151
  private pendingFlaggedFiles;
152
152
  private get agentID();
153
- private get trackedTicketIDs();
154
- private set trackedTicketIDs(value);
153
+ private get trackedSessionIDs();
154
+ private set trackedSessionIDs(value);
155
155
  private get respondedCRIDs();
156
156
  private set respondedCRIDs(value);
157
157
  private syncPolling;
158
- private addTrackedTicket;
158
+ private addTrackedSession;
159
159
  constructor(config: PRBEAgentConfig);
160
160
  private hookElectronLog;
161
161
  private hookRendererLogs;
@@ -186,10 +186,12 @@ declare class PRBEAgent implements PRBEInteractionRequester {
186
186
  cancel(): void;
187
187
  /**
188
188
  * Poll the backend for context requests on tracked tickets.
189
+ * Resolves session IDs → ticket IDs first, then polls with ticket IDs.
189
190
  */
190
191
  poll(): Promise<PollResponse | null>;
191
192
  /**
192
- * Fetch ticket display info for all tracked tickets.
193
+ * Fetch ticket display info for all tracked sessions.
194
+ * Resolves session IDs → ticket IDs first, then fetches ticket info.
193
195
  */
194
196
  fetchTicketInfo(): Promise<TicketInfoOut[]>;
195
197
  stopPolling(): void;
@@ -214,6 +216,7 @@ declare class PRBEAgent implements PRBEInteractionRequester {
214
216
  private extractUploadPrefix;
215
217
  private static backgroundUpload;
216
218
  private startPolling;
219
+ private resolveSessions;
217
220
  /**
218
221
  * Abort all in-flight fetch requests to prevent orphaned DNS lookups
219
222
  * that can crash the c-ares resolver during process shutdown.
package/dist/index.js CHANGED
@@ -192,7 +192,7 @@ var PRBEAgentState = class extends import_events.EventEmitter {
192
192
  activeCRs = /* @__PURE__ */ new Map();
193
193
  completedCRs = [];
194
194
  // Tracked tickets
195
- trackedTicketIDs = [];
195
+ trackedSessionIDs = [];
196
196
  ticketInfo = [];
197
197
  // Computed
198
198
  get hasActiveWork() {
@@ -420,8 +420,8 @@ var PRBEAgentState = class extends import_events.EventEmitter {
420
420
  this.emit("status" /* STATUS */);
421
421
  }
422
422
  // ---------- Tickets ----------
423
- updateTrackedTicketIDs(ids) {
424
- this.trackedTicketIDs = ids;
423
+ updateTrackedSessionIDs(ids) {
424
+ this.trackedSessionIDs = ids;
425
425
  this.emit("tickets-changed" /* TICKETS_CHANGED */, ids);
426
426
  this.emit("status" /* STATUS */);
427
427
  }
@@ -1810,13 +1810,13 @@ var PRBEAgent = class _PRBEAgent {
1810
1810
  savePersistedData(this.persistedData);
1811
1811
  return newID;
1812
1812
  }
1813
- get trackedTicketIDs() {
1814
- return this.persistedData.ticketIds ?? [];
1813
+ get trackedSessionIDs() {
1814
+ return this.persistedData.sessionIds ?? [];
1815
1815
  }
1816
- set trackedTicketIDs(ids) {
1817
- this.persistedData.ticketIds = ids;
1816
+ set trackedSessionIDs(ids) {
1817
+ this.persistedData.sessionIds = ids;
1818
1818
  savePersistedData(this.persistedData);
1819
- this.state.updateTrackedTicketIDs(ids);
1819
+ this.state.updateTrackedSessionIDs(ids);
1820
1820
  this.syncPolling(ids.length > 0);
1821
1821
  }
1822
1822
  get respondedCRIDs() {
@@ -1826,19 +1826,19 @@ var PRBEAgent = class _PRBEAgent {
1826
1826
  this.persistedData.respondedCRIds = Array.from(ids);
1827
1827
  savePersistedData(this.persistedData);
1828
1828
  }
1829
- syncPolling(hasTickets) {
1830
- if (this.config.backgroundPolling && hasTickets) {
1829
+ syncPolling(hasSessions) {
1830
+ if (this.config.backgroundPolling && hasSessions) {
1831
1831
  if (this.pollingTimer === null) {
1832
1832
  this.startPolling();
1833
1833
  }
1834
- } else if (!hasTickets) {
1834
+ } else if (!hasSessions) {
1835
1835
  this.stopPolling();
1836
1836
  }
1837
1837
  }
1838
- addTrackedTicket(id) {
1839
- const ids = this.trackedTicketIDs;
1838
+ addTrackedSession(id) {
1839
+ const ids = this.trackedSessionIDs;
1840
1840
  if (!ids.includes(id)) {
1841
- this.trackedTicketIDs = [...ids, id];
1841
+ this.trackedSessionIDs = [...ids, id];
1842
1842
  }
1843
1843
  }
1844
1844
  // ---------- Constructor ----------
@@ -1896,9 +1896,9 @@ var PRBEAgent = class _PRBEAgent {
1896
1896
  if (config.ipcMain) {
1897
1897
  this.hookRendererLogs(config.ipcMain, config.rendererLogChannel ?? "prbe-renderer-log");
1898
1898
  }
1899
- const existingTickets = this.trackedTicketIDs;
1900
- if (existingTickets.length > 0) {
1901
- this.trackedTicketIDs = existingTickets;
1899
+ const existingSessions = this.trackedSessionIDs;
1900
+ if (existingSessions.length > 0) {
1901
+ this.trackedSessionIDs = existingSessions;
1902
1902
  }
1903
1903
  }
1904
1904
  // ---------- Log integration ----------
@@ -2029,8 +2029,8 @@ var PRBEAgent = class _PRBEAgent {
2029
2029
  );
2030
2030
  this.currentInvestigationSource = "user" /* USER */;
2031
2031
  this.currentCRId = null;
2032
- if (result?.ticketId) {
2033
- this.addTrackedTicket(result.ticketId);
2032
+ if (result?.sessionId) {
2033
+ this.addTrackedSession(result.sessionId);
2034
2034
  } else if (!result) {
2035
2035
  if (this.state.isInvestigating) {
2036
2036
  const message = this.userCancelled ? "Investigation cancelled" : "Investigation ended unexpectedly";
@@ -2062,33 +2062,37 @@ var PRBEAgent = class _PRBEAgent {
2062
2062
  }
2063
2063
  /**
2064
2064
  * Poll the backend for context requests on tracked tickets.
2065
+ * Resolves session IDs → ticket IDs first, then polls with ticket IDs.
2065
2066
  */
2066
2067
  async poll() {
2067
- const ticketIDs = this.trackedTicketIDs;
2068
- if (ticketIDs.length === 0) return null;
2069
- const request = {
2070
- agent_id: this.agentID,
2071
- ticket_ids: ticketIDs
2072
- };
2068
+ const sessionIDs = this.trackedSessionIDs;
2069
+ if (sessionIDs.length === 0) return null;
2073
2070
  try {
2071
+ const resolved = await this.resolveSessions(sessionIDs);
2072
+ const returnedSessionIDs = new Set(
2073
+ resolved.tickets.flatMap((t) => t.session_ids)
2074
+ );
2075
+ const resolvedSessionIDs = new Set(
2076
+ resolved.tickets.filter((t) => t.status === "resolved").flatMap((t) => t.session_ids)
2077
+ );
2078
+ const survivingSessions = sessionIDs.filter(
2079
+ (id) => returnedSessionIDs.has(id) && !resolvedSessionIDs.has(id)
2080
+ );
2081
+ if (survivingSessions.length !== sessionIDs.length) {
2082
+ this.trackedSessionIDs = survivingSessions;
2083
+ }
2084
+ const ticketIDs = resolved.tickets.filter((t) => t.status !== "resolved").map((t) => t.ticket_id);
2085
+ if (ticketIDs.length === 0) return { tickets: [] };
2086
+ const request = {
2087
+ agent_id: this.agentID,
2088
+ ticket_ids: ticketIDs
2089
+ };
2074
2090
  const response = await this.post(
2075
2091
  "/api/agent/poll",
2076
2092
  request
2077
2093
  );
2078
- const returnedIDs = new Set(response.tickets.map((t) => t.ticket_id));
2079
- const orphaned = ticketIDs.filter((id) => !returnedIDs.has(id));
2080
- if (orphaned.length > 0) {
2081
- this.trackedTicketIDs = this.trackedTicketIDs.filter(
2082
- (id) => !orphaned.includes(id)
2083
- );
2084
- }
2085
2094
  const knownCRIDs = /* @__PURE__ */ new Set();
2086
2095
  for (const ticket of response.tickets) {
2087
- if (ticket.status === "resolved") {
2088
- this.trackedTicketIDs = this.trackedTicketIDs.filter(
2089
- (id) => id !== ticket.ticket_id
2090
- );
2091
- }
2092
2096
  for (const cr of ticket.context_requests) {
2093
2097
  knownCRIDs.add(cr.id);
2094
2098
  if (!cr.is_active || this.respondedCRIDs.has(cr.id)) continue;
@@ -2114,13 +2118,17 @@ var PRBEAgent = class _PRBEAgent {
2114
2118
  }
2115
2119
  }
2116
2120
  /**
2117
- * Fetch ticket display info for all tracked tickets.
2121
+ * Fetch ticket display info for all tracked sessions.
2122
+ * Resolves session IDs → ticket IDs first, then fetches ticket info.
2118
2123
  */
2119
2124
  async fetchTicketInfo() {
2120
- const ticketIDs = this.trackedTicketIDs;
2121
- if (ticketIDs.length === 0) return [];
2122
- const request = { ticket_ids: ticketIDs };
2125
+ const sessionIDs = this.trackedSessionIDs;
2126
+ if (sessionIDs.length === 0) return [];
2123
2127
  try {
2128
+ const resolved = await this.resolveSessions(sessionIDs);
2129
+ const ticketIDs = resolved.tickets.map((t) => t.ticket_id);
2130
+ if (ticketIDs.length === 0) return [];
2131
+ const request = { ticket_ids: ticketIDs };
2124
2132
  const response = await this.post(
2125
2133
  "/api/agent/tickets",
2126
2134
  request
@@ -2138,7 +2146,7 @@ var PRBEAgent = class _PRBEAgent {
2138
2146
  }
2139
2147
  }
2140
2148
  resumePolling() {
2141
- if (this.trackedTicketIDs.length === 0) return;
2149
+ if (this.trackedSessionIDs.length === 0) return;
2142
2150
  this.startPolling();
2143
2151
  }
2144
2152
  /**
@@ -2161,7 +2169,7 @@ var PRBEAgent = class _PRBEAgent {
2161
2169
  this.state.completedInvestigations = [];
2162
2170
  this.state.activeCRs.clear();
2163
2171
  this.state.completedCRs = [];
2164
- this.state.trackedTicketIDs = [];
2172
+ this.state.trackedSessionIDs = [];
2165
2173
  this.state.ticketInfo = [];
2166
2174
  this.state.emit("status" /* STATUS */);
2167
2175
  }
@@ -2220,8 +2228,8 @@ var PRBEAgent = class _PRBEAgent {
2220
2228
  );
2221
2229
  this.currentInvestigationSource = "user" /* USER */;
2222
2230
  this.currentCRId = null;
2223
- if (result?.ticketId) {
2224
- this.addTrackedTicket(result.ticketId);
2231
+ if (result?.sessionId) {
2232
+ this.addTrackedSession(result.sessionId);
2225
2233
  }
2226
2234
  }
2227
2235
  // ---------- WebSocket Investigation ----------
@@ -2398,6 +2406,7 @@ var PRBEAgent = class _PRBEAgent {
2398
2406
  const report = msg.content ?? "";
2399
2407
  const userSummary = msg.metadata?.["user_summary"] ?? "";
2400
2408
  const ticketId2 = msg.metadata?.["ticket_id"];
2409
+ const sessionId = msg.metadata?.["session_id"];
2401
2410
  emit({
2402
2411
  type: "completed" /* COMPLETED */,
2403
2412
  report,
@@ -2405,7 +2414,7 @@ var PRBEAgent = class _PRBEAgent {
2405
2414
  ticketId: ticketId2
2406
2415
  });
2407
2416
  ws.close(1e3, "Complete");
2408
- finish({ report, userSummary, ticketId: ticketId2 });
2417
+ finish({ report, userSummary, ticketId: ticketId2, sessionId });
2409
2418
  break;
2410
2419
  }
2411
2420
  case "error" /* ERROR */:
@@ -2516,12 +2525,23 @@ var PRBEAgent = class _PRBEAgent {
2516
2525
  this.stopPolling();
2517
2526
  this.pollingTimer = setInterval(() => {
2518
2527
  void this.poll().then(() => {
2519
- if (this.trackedTicketIDs.length === 0) {
2528
+ if (this.trackedSessionIDs.length === 0) {
2520
2529
  this.stopPolling();
2521
2530
  }
2522
2531
  });
2523
2532
  }, this.config.pollingInterval);
2524
2533
  }
2534
+ // ---------- Session Resolution ----------
2535
+ async resolveSessions(sessionIDs) {
2536
+ const request = {
2537
+ agent_id: this.agentID,
2538
+ session_ids: sessionIDs
2539
+ };
2540
+ return this.post(
2541
+ "/api/agent/resolve-sessions",
2542
+ request
2543
+ );
2544
+ }
2525
2545
  // ---------- Networking ----------
2526
2546
  /**
2527
2547
  * Abort all in-flight fetch requests to prevent orphaned DNS lookups
@@ -2576,7 +2596,7 @@ var DEFAULT_PRBE_STATE = {
2576
2596
  completedInvestigations: [],
2577
2597
  activeCRs: [],
2578
2598
  completedCRs: [],
2579
- trackedTicketIDs: [],
2599
+ trackedSessionIDs: [],
2580
2600
  ticketInfo: [],
2581
2601
  hasActiveWork: false
2582
2602
  };
@@ -2620,7 +2640,7 @@ function serializePRBEState(state) {
2620
2640
  })),
2621
2641
  activeCRs: Array.from(state.activeCRs.values()).map(serializeCR),
2622
2642
  completedCRs: state.completedCRs.map(serializeCR),
2623
- trackedTicketIDs: state.trackedTicketIDs,
2643
+ trackedSessionIDs: state.trackedSessionIDs,
2624
2644
  ticketInfo: state.ticketInfo,
2625
2645
  hasActiveWork: state.hasActiveWork
2626
2646
  };