@prbe.ai/electron-sdk 0.1.16 → 0.1.17

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.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.1.16";
2
+ var version = "0.1.17";
3
3
 
4
4
  // src/agent.ts
5
5
  import * as fs3 from "fs";
@@ -53,6 +53,11 @@ var ToolName = /* @__PURE__ */ ((ToolName2) => {
53
53
  ToolName2["CLIENT_MESSAGE_USER"] = "client_message_user";
54
54
  return ToolName2;
55
55
  })(ToolName || {});
56
+ var UserIdentifierType = /* @__PURE__ */ ((UserIdentifierType2) => {
57
+ UserIdentifierType2["EMAIL"] = "email";
58
+ UserIdentifierType2["ID"] = "id";
59
+ return UserIdentifierType2;
60
+ })(UserIdentifierType || {});
56
61
  var PRBEAgentConfigKey = /* @__PURE__ */ ((PRBEAgentConfigKey3) => {
57
62
  PRBEAgentConfigKey3["API_KEY"] = "apiKey";
58
63
  PRBEAgentConfigKey3["AUTO_APPROVED_DIRS"] = "autoApprovedDirs";
@@ -1916,6 +1921,9 @@ var PRBEAgent = class _PRBEAgent {
1916
1921
  historyStore;
1917
1922
  /** Files flagged during the current tool call — uploaded immediately after the tool returns. */
1918
1923
  pendingFlaggedFiles = [];
1924
+ // ---------- User Identifier ----------
1925
+ userEmail;
1926
+ userId;
1919
1927
  // ---------- Persistence ----------
1920
1928
  get agentID() {
1921
1929
  if (this.persistedData.agentId) {
@@ -1970,6 +1978,7 @@ var PRBEAgent = class _PRBEAgent {
1970
1978
  this.logCapture = new PRBELogCapture(this.config.maxLogEntries);
1971
1979
  this.persistedData = loadPersistedData();
1972
1980
  this.historyStore = new HistoryStore(this.config.apiKey);
1981
+ void this.agentID;
1973
1982
  const history = this.historyStore.load();
1974
1983
  this.state.completedInvestigations = history.investigations;
1975
1984
  this.state.completedCRs = history.crs;
@@ -2123,6 +2132,47 @@ var PRBEAgent = class _PRBEAgent {
2123
2132
  updateSessionMetadata(metadata) {
2124
2133
  this.sessionMetadata = { ...this.sessionMetadata, ...metadata };
2125
2134
  }
2135
+ /**
2136
+ * Set a user identifier for this agent. Persists to the backend agents table.
2137
+ * Can be called multiple times with different types to set both email and ID.
2138
+ * Also auto-injects user_email and/or user_id into session metadata for investigations.
2139
+ */
2140
+ setUserIdentifier(type, value) {
2141
+ if (type === "email" /* EMAIL */) {
2142
+ this.userEmail = value;
2143
+ } else {
2144
+ this.userId = value;
2145
+ }
2146
+ this.syncUserIdentifierToBackend(type, value);
2147
+ }
2148
+ /**
2149
+ * Clear user identifier(s) for this agent.
2150
+ * Pass a specific type to clear only that identifier, or omit to clear both email and ID.
2151
+ */
2152
+ clearUserIdentifier(type) {
2153
+ if (type) {
2154
+ if (type === "email" /* EMAIL */) {
2155
+ this.userEmail = void 0;
2156
+ } else {
2157
+ this.userId = void 0;
2158
+ }
2159
+ this.syncUserIdentifierToBackend(type, null);
2160
+ } else {
2161
+ this.userEmail = void 0;
2162
+ this.userId = void 0;
2163
+ this.syncUserIdentifierToBackend("email" /* EMAIL */, null);
2164
+ this.syncUserIdentifierToBackend("id" /* ID */, null);
2165
+ }
2166
+ }
2167
+ syncUserIdentifierToBackend(type, value) {
2168
+ void this.post("/api/agent/update-user", {
2169
+ agent_id: this.agentID,
2170
+ identifier_type: type,
2171
+ identifier_value: value
2172
+ }).catch((err) => {
2173
+ console.error(`[PRBEAgent] Failed to sync user identifier: ${err}`);
2174
+ });
2175
+ }
2126
2176
  /**
2127
2177
  * Register a custom tool that the middleware can invoke during investigations.
2128
2178
  */
@@ -2423,8 +2473,15 @@ var PRBEAgent = class _PRBEAgent {
2423
2473
  if (contextRequestID) startMetadata["context_request_id"] = contextRequestID;
2424
2474
  if (ticketId) startMetadata["ticket_id"] = ticketId;
2425
2475
  if (this.appDataPath) startMetadata["app_data_path"] = this.appDataPath;
2426
- if (Object.keys(this.sessionMetadata).length > 0) {
2427
- startMetadata["session_metadata"] = this.sessionMetadata;
2476
+ const enrichedMetadata = { ...this.sessionMetadata };
2477
+ if (this.userEmail) {
2478
+ enrichedMetadata["user_email"] = this.userEmail;
2479
+ }
2480
+ if (this.userId) {
2481
+ enrichedMetadata["user_id"] = this.userId;
2482
+ }
2483
+ if (Object.keys(enrichedMetadata).length > 0) {
2484
+ startMetadata["session_metadata"] = enrichedMetadata;
2428
2485
  }
2429
2486
  if (!conn.send({ type: "start" /* START */, content: query, metadata: startMetadata })) {
2430
2487
  emit({ type: "error" /* ERROR */, message: "Failed to send start message" });
@@ -2729,6 +2786,7 @@ export {
2729
2786
  SearchContentTool,
2730
2787
  ToolName,
2731
2788
  ToolParamType,
2789
+ UserIdentifierType,
2732
2790
  WSMessageType,
2733
2791
  humanReadableSize,
2734
2792
  redactPII,