@prbe.ai/electron-sdk 0.1.15 → 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,3 +1,6 @@
1
+ // package.json
2
+ var version = "0.1.17";
3
+
1
4
  // src/agent.ts
2
5
  import * as fs3 from "fs";
3
6
  import * as path5 from "path";
@@ -50,6 +53,11 @@ var ToolName = /* @__PURE__ */ ((ToolName2) => {
50
53
  ToolName2["CLIENT_MESSAGE_USER"] = "client_message_user";
51
54
  return ToolName2;
52
55
  })(ToolName || {});
56
+ var UserIdentifierType = /* @__PURE__ */ ((UserIdentifierType2) => {
57
+ UserIdentifierType2["EMAIL"] = "email";
58
+ UserIdentifierType2["ID"] = "id";
59
+ return UserIdentifierType2;
60
+ })(UserIdentifierType || {});
53
61
  var PRBEAgentConfigKey = /* @__PURE__ */ ((PRBEAgentConfigKey3) => {
54
62
  PRBEAgentConfigKey3["API_KEY"] = "apiKey";
55
63
  PRBEAgentConfigKey3["AUTO_APPROVED_DIRS"] = "autoApprovedDirs";
@@ -1913,6 +1921,9 @@ var PRBEAgent = class _PRBEAgent {
1913
1921
  historyStore;
1914
1922
  /** Files flagged during the current tool call — uploaded immediately after the tool returns. */
1915
1923
  pendingFlaggedFiles = [];
1924
+ // ---------- User Identifier ----------
1925
+ userEmail;
1926
+ userId;
1916
1927
  // ---------- Persistence ----------
1917
1928
  get agentID() {
1918
1929
  if (this.persistedData.agentId) {
@@ -1959,7 +1970,7 @@ var PRBEAgent = class _PRBEAgent {
1959
1970
  };
1960
1971
  this.interactionHandler = config.interactionHandler;
1961
1972
  this.appDataPath = config.appDataPath;
1962
- this.sessionMetadata = config.sessionMetadata ?? {};
1973
+ this.sessionMetadata = { sdk_version: version, ...config.sessionMetadata };
1963
1974
  if (this.appDataPath && !this.config.autoApprovedDirs.includes(this.appDataPath)) {
1964
1975
  this.config.autoApprovedDirs.push(this.appDataPath);
1965
1976
  }
@@ -1967,6 +1978,7 @@ var PRBEAgent = class _PRBEAgent {
1967
1978
  this.logCapture = new PRBELogCapture(this.config.maxLogEntries);
1968
1979
  this.persistedData = loadPersistedData();
1969
1980
  this.historyStore = new HistoryStore(this.config.apiKey);
1981
+ void this.agentID;
1970
1982
  const history = this.historyStore.load();
1971
1983
  this.state.completedInvestigations = history.investigations;
1972
1984
  this.state.completedCRs = history.crs;
@@ -2120,6 +2132,47 @@ var PRBEAgent = class _PRBEAgent {
2120
2132
  updateSessionMetadata(metadata) {
2121
2133
  this.sessionMetadata = { ...this.sessionMetadata, ...metadata };
2122
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
+ }
2123
2176
  /**
2124
2177
  * Register a custom tool that the middleware can invoke during investigations.
2125
2178
  */
@@ -2420,8 +2473,15 @@ var PRBEAgent = class _PRBEAgent {
2420
2473
  if (contextRequestID) startMetadata["context_request_id"] = contextRequestID;
2421
2474
  if (ticketId) startMetadata["ticket_id"] = ticketId;
2422
2475
  if (this.appDataPath) startMetadata["app_data_path"] = this.appDataPath;
2423
- if (Object.keys(this.sessionMetadata).length > 0) {
2424
- 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;
2425
2485
  }
2426
2486
  if (!conn.send({ type: "start" /* START */, content: query, metadata: startMetadata })) {
2427
2487
  emit({ type: "error" /* ERROR */, message: "Failed to send start message" });
@@ -2721,10 +2781,12 @@ export {
2721
2781
  PROBE_MARK_SVG,
2722
2782
  ReadAppLogsTool,
2723
2783
  ReadFileTool,
2784
+ version as SDK_VERSION,
2724
2785
  SearchAppLogsTool,
2725
2786
  SearchContentTool,
2726
2787
  ToolName,
2727
2788
  ToolParamType,
2789
+ UserIdentifierType,
2728
2790
  WSMessageType,
2729
2791
  humanReadableSize,
2730
2792
  redactPII,