@parall/daemon 1.68.0 → 1.70.0

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.
@@ -602,6 +602,7 @@ var init_clip_connection_endpoints = __esm({
602
602
  "use strict";
603
603
  clipConnectionEndpoints = {
604
604
  ORG_CLIP_MCP_OAUTH_ATTEMPT: (orgId, clipId, attemptId) => `/api/v1/orgs/${orgId}/clip-registry/${clipId}/mcp-oauth-attempts/${attemptId}`,
605
+ CLIP_CONNECTIONS_ALL: (orgId) => `/api/v1/orgs/${orgId}/clip-connections/all`,
605
606
  CLIP_CONNECTIONS: (orgId, clipId) => `/api/v1/orgs/${orgId}/clip-registry/${clipId}/connections`,
606
607
  CLIP_CONNECTION_ACCESS: (orgId, connId) => `/api/v1/orgs/${orgId}/clip-connections/${connId}/access`,
607
608
  CLIP_CONNECTION: (orgId, connId) => `/api/v1/orgs/${orgId}/clip-connections/${connId}`
@@ -1065,6 +1066,7 @@ var init_constants = __esm({
1065
1066
  // Onboarding
1066
1067
  SEED_ONBOARDING_DM: (orgId) => `${API_BASE2}/orgs/${orgId}/seed-onboarding-dm`,
1067
1068
  DISMISS_ONBOARDING: (orgId) => `${API_BASE2}/orgs/${orgId}/dismiss-onboarding`,
1069
+ ORG_ACCENT_THEME: (orgId) => `${API_BASE2}/orgs/${orgId}/accent-theme`,
1068
1070
  // Chats (org-scoped)
1069
1071
  CHATS: (orgId) => `${API_BASE2}/orgs/${orgId}/chats`,
1070
1072
  CHATS_DISCOVERABLE: (orgId) => `${API_BASE2}/orgs/${orgId}/chats/discoverable`,
@@ -1431,6 +1433,7 @@ var init_constants = __esm({
1431
1433
  UNREAD_BY_ORG: `${API_BASE2}/me/unread/orgs`,
1432
1434
  CHAT_READ: (orgId, chatId) => `${API_BASE2}/orgs/${orgId}/chats/${chatId}/read`,
1433
1435
  CHAT_READ_ALL: (orgId, chatId) => `${API_BASE2}/orgs/${orgId}/chats/${chatId}/read-all`,
1436
+ CHAT_UNREAD_THREADS: (orgId, chatId) => `${API_BASE2}/orgs/${orgId}/chats/${chatId}/threads/unread`,
1434
1437
  THREAD_UNREAD: (orgId, chatId, threadRootId) => `${API_BASE2}/orgs/${orgId}/chats/${chatId}/threads/${threadRootId}/unread`,
1435
1438
  THREAD_READ: (orgId, chatId, threadRootId) => `${API_BASE2}/orgs/${orgId}/chats/${chatId}/threads/${threadRootId}/read`,
1436
1439
  // References (org-scoped)
@@ -1589,6 +1592,7 @@ var init_constants = __esm({
1589
1592
  ORG_INVITE_LINK_JOINED: "org.invite_link.joined",
1590
1593
  ORG_MEMBER_REMOVED: "org.member.removed",
1591
1594
  ORG_MEMBER_PROFILE_UPDATED: "org.member.profile.updated",
1595
+ APP_DATA_CHANGED: "app.data.changed",
1592
1596
  AGENT_CONFIG_UPDATE: "agent_config.update",
1593
1597
  PRESENCE_UPDATE: "presence.update",
1594
1598
  WIKI_CHANGESET_CREATED: "wiki.changeset.created",
@@ -2331,6 +2335,9 @@ var init_clip_connection_client = __esm({
2331
2335
  async listClipConnections(orgId, clipId) {
2332
2336
  return this.request("GET", ENDPOINTS.CLIP_CONNECTIONS(orgId, clipId));
2333
2337
  }
2338
+ async listAllClipConnections(orgId) {
2339
+ return this.request("GET", ENDPOINTS.CLIP_CONNECTIONS_ALL(orgId));
2340
+ }
2334
2341
  async createClipConnection(orgId, clipId, input) {
2335
2342
  return this.request("POST", ENDPOINTS.CLIP_CONNECTIONS(orgId, clipId), input);
2336
2343
  }
@@ -2639,6 +2646,22 @@ var init_trigger_judge_client = __esm({
2639
2646
  }
2640
2647
  });
2641
2648
 
2649
+ // ts/sdk/dist/org-accent-client.js
2650
+ var OrgAccentClient;
2651
+ var init_org_accent_client = __esm({
2652
+ "ts/sdk/dist/org-accent-client.js"() {
2653
+ "use strict";
2654
+ init_constants();
2655
+ init_trigger_judge_client();
2656
+ OrgAccentClient = class extends TriggerJudgeClient {
2657
+ /** Set the caller's own color theme for this org. */
2658
+ async setOrgAccentTheme(orgId, accentTheme) {
2659
+ return this.request("PUT", ENDPOINTS.ORG_ACCENT_THEME(orgId), { accent_theme: accentTheme });
2660
+ }
2661
+ };
2662
+ }
2663
+ });
2664
+
2642
2665
  // ts/sdk/dist/wiki-upload.js
2643
2666
  function createWikiUploadFormData(params) {
2644
2667
  const form = new FormData();
@@ -2826,12 +2849,12 @@ var init_client = __esm({
2826
2849
  "ts/sdk/dist/client.js"() {
2827
2850
  "use strict";
2828
2851
  init_browser_viewer();
2829
- init_trigger_judge_client();
2852
+ init_org_accent_client();
2830
2853
  init_wiki_upload();
2831
2854
  init_fetch_cause();
2832
2855
  init_wiki_changeset();
2833
2856
  init_constants();
2834
- ParallClient = class _ParallClient extends TriggerJudgeClient {
2857
+ ParallClient = class _ParallClient extends OrgAccentClient {
2835
2858
  baseUrl;
2836
2859
  wikiBaseUrl;
2837
2860
  token;
@@ -4004,6 +4027,12 @@ var init_client = __esm({
4004
4027
  async markAllRead(orgId, chatId) {
4005
4028
  return this.request("POST", ENDPOINTS.CHAT_READ_ALL(orgId, chatId));
4006
4029
  }
4030
+ /** The caller's watched threads in a chat that have unread replies — the
4031
+ * per-thread breakdown of the chat's `thread_count`, for reaching thread
4032
+ * residue whose root is outside the loaded message window. */
4033
+ async getUnreadThreads(orgId, chatId) {
4034
+ return this.request("GET", ENDPOINTS.CHAT_UNREAD_THREADS(orgId, chatId));
4035
+ }
4007
4036
  async getThreadUnread(orgId, chatId, threadRootId) {
4008
4037
  return this.request("GET", ENDPOINTS.THREAD_UNREAD(orgId, chatId, threadRootId));
4009
4038
  }
@@ -5527,6 +5556,24 @@ var init_mini_app_types = __esm({
5527
5556
  }
5528
5557
  });
5529
5558
 
5559
+ // ts/sdk/dist/org-accent-types.js
5560
+ var ACCENT_THEMES;
5561
+ var init_org_accent_types = __esm({
5562
+ "ts/sdk/dist/org-accent-types.js"() {
5563
+ "use strict";
5564
+ ACCENT_THEMES = [
5565
+ "graphite",
5566
+ "durability",
5567
+ "amber",
5568
+ "lime",
5569
+ "teal",
5570
+ "indigo",
5571
+ "purple",
5572
+ "pink"
5573
+ ];
5574
+ }
5575
+ });
5576
+
5530
5577
  // ts/sdk/dist/org-unread-types.js
5531
5578
  var init_org_unread_types = __esm({
5532
5579
  "ts/sdk/dist/org-unread-types.js"() {
@@ -5951,7 +5998,7 @@ var init_ws = __esm({
5951
5998
  enterAuthInvalid(event) {
5952
5999
  this.clearReconnect();
5953
6000
  this.setState("auth-invalid");
5954
- console.error(`WS auth-invalid: server rejected this credential (status ${event.status}${event.code ? `, code ${event.code}` : ""}) \u2014 ${event.message}. The key is invalid, expired, or revoked; retrying it cannot succeed, so reconnects are stopped. Recover by refreshing credentials (re-login, or issue a new API key), then connect again.`);
6001
+ console.error(`WS auth-invalid: server rejected this credential (status ${event.status}${event.code ? `, code ${event.code}` : ""}) \u2014 ${event.message}. This client stops reconnecting on its own; the owner decides whether to call connect() again later or refresh credentials (re-login, or issue a new API key) first.`);
5955
6002
  for (const listener of this.authInvalidListeners) {
5956
6003
  listener(event);
5957
6004
  }
@@ -6065,6 +6112,7 @@ var init_ws = __esm({
6065
6112
  // ts/sdk/dist/index.js
6066
6113
  var dist_exports = {};
6067
6114
  __export(dist_exports, {
6115
+ ACCENT_THEMES: () => ACCENT_THEMES,
6068
6116
  API_BASE: () => API_BASE2,
6069
6117
  ApiError: () => ApiError,
6070
6118
  BROWSER_USE_ACTIONS: () => BROWSER_USE_ACTIONS,
@@ -6147,6 +6195,7 @@ var init_dist = __esm({
6147
6195
  init_fetch_cause();
6148
6196
  init_llm_provider_types();
6149
6197
  init_mini_app_types();
6198
+ init_org_accent_types();
6150
6199
  init_org_unread_types();
6151
6200
  init_runtime_observation2();
6152
6201
  init_subject();
@@ -59436,6 +59485,8 @@ function resolveClaudeDaemonConfig(env = process.env) {
59436
59485
  restartBackoffMaxMs: parseMs(env.PRLL_DAEMON_RESTART_BACKOFF_MAX_MS, 5 * 6e4),
59437
59486
  bootstrapBackoffMs: parseMsAllowZero(env.PRLL_DAEMON_BOOTSTRAP_BACKOFF_MS, 2e3),
59438
59487
  bootstrapBackoffMaxMs: parseMs(env.PRLL_DAEMON_BOOTSTRAP_BACKOFF_MAX_MS, 6e4),
59488
+ credentialRetryBackoffMs: parseMs(env.PRLL_DAEMON_CREDENTIAL_RETRY_BACKOFF_MS, 6e4),
59489
+ credentialRetryBackoffMaxMs: parseMs(env.PRLL_DAEMON_CREDENTIAL_RETRY_BACKOFF_MAX_MS, 15 * 6e4),
59439
59490
  supervisorRestartBackoffMs: parseMsAllowZero(env.PRLL_DAEMON_SUPERVISOR_RESTART_BACKOFF_MS, 5e3),
59440
59491
  supervisorRestartBackoffMaxMs: parseMs(env.PRLL_DAEMON_SUPERVISOR_RESTART_BACKOFF_MAX_MS, 5 * 6e4),
59441
59492
  updateCdnUrl: env.PRLL_DAEMON_UPDATE_CDN_URL?.trim() || ((env.PRLL_DAEMON_UPDATE_CHANNEL?.trim() ?? "production") === "staging" ? "https://releases.staging.prll.sh/daemon/staging" : "https://releases.parall.com/daemon/production"),
@@ -60232,6 +60283,7 @@ MCowBQYDK2VwAyEAQHQAZThNX7+deJNyHl/5DgiAa1OHx7UQoJotam0JhUk=
60232
60283
  updating = false;
60233
60284
  periodicTimer = null;
60234
60285
  reportOutcome = null;
60286
+ restartHandler = null;
60235
60287
  constructor(bundleDir, cdnBaseUrl, log2, signingEnabled) {
60236
60288
  this.bundleDir = bundleDir;
60237
60289
  this.cdnBaseUrl = cdnBaseUrl;
@@ -60246,6 +60298,15 @@ MCowBQYDK2VwAyEAQHQAZThNX7+deJNyHl/5DgiAa1OHx7UQoJotam0JhUk=
60246
60298
  report(outcome, reason) {
60247
60299
  this.reportOutcome?.(outcome, reason);
60248
60300
  }
60301
+ /**
60302
+ * Restart the daemon onto an update installed after boot (periodic check or
60303
+ * WS push). Installed-but-not-running is not an update: the old process
60304
+ * would keep its bugs, and a later push for the same version is skipped
60305
+ * because the disk is already current.
60306
+ */
60307
+ setRestartHandler(fn) {
60308
+ this.restartHandler = fn;
60309
+ }
60249
60310
  /**
60250
60311
  * Start periodic update checks. Call once after supervisor bootstrap.
60251
60312
  */
@@ -60253,9 +60314,7 @@ MCowBQYDK2VwAyEAQHQAZThNX7+deJNyHl/5DgiAa1OHx7UQoJotam0JhUk=
60253
60314
  if (intervalMs <= 0 || this.periodicTimer)
60254
60315
  return;
60255
60316
  this.periodicTimer = setInterval(() => {
60256
- this.checkAndApply().catch((err) => {
60257
- this.log.warn(`periodic update check failed: ${String(err)}`);
60258
- });
60317
+ void this.applyAndRestart();
60259
60318
  }, intervalMs);
60260
60319
  this.periodicTimer.unref?.();
60261
60320
  }
@@ -60291,7 +60350,13 @@ MCowBQYDK2VwAyEAQHQAZThNX7+deJNyHl/5DgiAa1OHx7UQoJotam0JhUk=
60291
60350
  const jitter = Math.random() * 18e4;
60292
60351
  await new Promise((r) => setTimeout(r, jitter));
60293
60352
  }
60294
- return this.checkAndApply(targetVersion);
60353
+ return this.applyAndRestart(targetVersion);
60354
+ }
60355
+ async applyAndRestart(targetVersion) {
60356
+ const applied = await this.checkAndApply(targetVersion);
60357
+ if (applied)
60358
+ this.restartHandler?.();
60359
+ return applied;
60295
60360
  }
60296
60361
  /**
60297
60362
  * Check if we need to roll back from a failed update.
@@ -67640,8 +67705,7 @@ var init_process = __esm({
67640
67705
  }
67641
67706
  });
67642
67707
 
67643
- // ts/daemon/dist/clip-runtime/hub-client.js
67644
- import * as http22 from "node:http2";
67708
+ // ts/daemon/dist/clip-runtime/connect-envelope.js
67645
67709
  function encodeEnvelope(msg) {
67646
67710
  const json = Buffer.from(JSON.stringify(msg), "utf-8");
67647
67711
  const header = Buffer.alloc(5);
@@ -67649,6 +67713,40 @@ function encodeEnvelope(msg) {
67649
67713
  header.writeUInt32BE(json.length, 1);
67650
67714
  return Buffer.concat([header, json]);
67651
67715
  }
67716
+ var ENVELOPE_FLAG_DATA, ENVELOPE_FLAG_TRAILER, MAX_FRAME_LENGTH, EnvelopeDecoder;
67717
+ var init_connect_envelope = __esm({
67718
+ "ts/daemon/dist/clip-runtime/connect-envelope.js"() {
67719
+ "use strict";
67720
+ ENVELOPE_FLAG_DATA = 0;
67721
+ ENVELOPE_FLAG_TRAILER = 2;
67722
+ MAX_FRAME_LENGTH = 16 * 1024 * 1024;
67723
+ EnvelopeDecoder = class {
67724
+ buf = Buffer.alloc(0);
67725
+ push(chunk) {
67726
+ this.buf = this.buf.length === 0 ? Buffer.from(chunk) : Buffer.concat([this.buf, chunk]);
67727
+ }
67728
+ /** Drain all complete envelopes from the internal buffer. */
67729
+ *flush() {
67730
+ while (this.buf.length >= 5) {
67731
+ const flags = this.buf[0];
67732
+ const length = this.buf.readUInt32BE(1);
67733
+ if (length > MAX_FRAME_LENGTH) {
67734
+ this.buf = Buffer.alloc(0);
67735
+ throw new Error(`envelope frame too large: ${length} bytes`);
67736
+ }
67737
+ if (this.buf.length < 5 + length)
67738
+ break;
67739
+ const payload = this.buf.subarray(5, 5 + length);
67740
+ this.buf = Buffer.from(this.buf.subarray(5 + length));
67741
+ yield { flags, payload };
67742
+ }
67743
+ }
67744
+ };
67745
+ }
67746
+ });
67747
+
67748
+ // ts/daemon/dist/clip-runtime/hub-client.js
67749
+ import * as http22 from "node:http2";
67652
67750
  function connectErrorMessage(text) {
67653
67751
  try {
67654
67752
  const obj = JSON.parse(text);
@@ -67676,35 +67774,12 @@ function parseTrailer(payload) {
67676
67774
  return null;
67677
67775
  }
67678
67776
  }
67679
- var ENVELOPE_FLAG_DATA, ENVELOPE_FLAG_TRAILER, MAX_FRAME_LENGTH, DEFAULT_REQUEST_TIMEOUT_MS, EnvelopeDecoder, HubCommandError, HubClient;
67777
+ var DEFAULT_REQUEST_TIMEOUT_MS, HubCommandError, HubClient;
67680
67778
  var init_hub_client = __esm({
67681
67779
  "ts/daemon/dist/clip-runtime/hub-client.js"() {
67682
67780
  "use strict";
67683
- ENVELOPE_FLAG_DATA = 0;
67684
- ENVELOPE_FLAG_TRAILER = 2;
67685
- MAX_FRAME_LENGTH = 16 * 1024 * 1024;
67781
+ init_connect_envelope();
67686
67782
  DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
67687
- EnvelopeDecoder = class {
67688
- buf = Buffer.alloc(0);
67689
- push(chunk) {
67690
- this.buf = this.buf.length === 0 ? Buffer.from(chunk) : Buffer.concat([this.buf, chunk]);
67691
- }
67692
- *flush() {
67693
- while (this.buf.length >= 5) {
67694
- const flags = this.buf[0];
67695
- const length = this.buf.readUInt32BE(1);
67696
- if (length > MAX_FRAME_LENGTH) {
67697
- this.buf = Buffer.alloc(0);
67698
- throw new Error(`envelope frame too large: ${length} bytes`);
67699
- }
67700
- if (this.buf.length < 5 + length)
67701
- break;
67702
- const payload = this.buf.subarray(5, 5 + length);
67703
- this.buf = Buffer.from(this.buf.subarray(5 + length));
67704
- yield { flags, payload };
67705
- }
67706
- }
67707
- };
67708
67783
  HubCommandError = class extends Error {
67709
67784
  code;
67710
67785
  constructor(message, code) {
@@ -68407,51 +68482,19 @@ var init_viewer_command_deadline = __esm({
68407
68482
 
68408
68483
  // ts/daemon/dist/clip-runtime/clip-provider.js
68409
68484
  import * as http23 from "node:http2";
68410
- function encodeEnvelope2(msg) {
68411
- const json = Buffer.from(JSON.stringify(msg), "utf-8");
68412
- const header = Buffer.alloc(5);
68413
- header[0] = ENVELOPE_FLAG_DATA2;
68414
- header.writeUInt32BE(json.length, 1);
68415
- return Buffer.concat([header, json]);
68416
- }
68417
68485
  function registrationKey(clips) {
68418
68486
  const sorted = [...clips].sort((a, b) => (a.alias ?? "").localeCompare(b.alias ?? ""));
68419
68487
  return JSON.stringify(sorted);
68420
68488
  }
68421
- var ENVELOPE_FLAG_DATA2, ENVELOPE_FLAG_TRAILER2, EnvelopeDecoder2, ClipProvider;
68489
+ var ClipProvider;
68422
68490
  var init_clip_provider = __esm({
68423
68491
  "ts/daemon/dist/clip-runtime/clip-provider.js"() {
68424
68492
  "use strict";
68425
68493
  init_browser_dependency();
68494
+ init_connect_envelope();
68426
68495
  init_process();
68427
68496
  init_viewer_command_deadline();
68428
68497
  init_viewer_command_error();
68429
- ENVELOPE_FLAG_DATA2 = 0;
68430
- ENVELOPE_FLAG_TRAILER2 = 2;
68431
- EnvelopeDecoder2 = class _EnvelopeDecoder {
68432
- buf = Buffer.alloc(0);
68433
- push(chunk) {
68434
- this.buf = this.buf.length === 0 ? Buffer.from(chunk) : Buffer.concat([this.buf, chunk]);
68435
- }
68436
- /** Drain all complete envelopes from the internal buffer. */
68437
- static MAX_FRAME_LENGTH = 16 * 1024 * 1024;
68438
- // 16 MiB
68439
- *flush() {
68440
- while (this.buf.length >= 5) {
68441
- const flags = this.buf[0];
68442
- const length = this.buf.readUInt32BE(1);
68443
- if (length > _EnvelopeDecoder.MAX_FRAME_LENGTH) {
68444
- this.buf = Buffer.alloc(0);
68445
- throw new Error(`envelope frame too large: ${length} bytes`);
68446
- }
68447
- if (this.buf.length < 5 + length)
68448
- break;
68449
- const payload = this.buf.subarray(5, 5 + length);
68450
- this.buf = Buffer.from(this.buf.subarray(5 + length));
68451
- yield { flags, payload };
68452
- }
68453
- }
68454
- };
68455
68498
  ClipProvider = class _ClipProvider {
68456
68499
  opts;
68457
68500
  session = null;
@@ -68459,6 +68502,7 @@ var init_clip_provider = __esm({
68459
68502
  stopped = false;
68460
68503
  connected = false;
68461
68504
  reconnectAttempt = 0;
68505
+ rejectedAttempt = 0;
68462
68506
  reconnectTimer = null;
68463
68507
  heartbeatTimer = null;
68464
68508
  statusUnsubscribe = null;
@@ -68537,11 +68581,11 @@ var init_clip_provider = __esm({
68537
68581
  this.opts.log.warn(`[clip-provider] stream error: ${String(err)}`);
68538
68582
  this.handleDisconnect(gen);
68539
68583
  });
68540
- const decoder = new EnvelopeDecoder2();
68584
+ const decoder = new EnvelopeDecoder();
68541
68585
  this.stream.on("data", (chunk) => {
68542
68586
  decoder.push(chunk);
68543
68587
  for (const envelope of decoder.flush()) {
68544
- if (envelope.flags === ENVELOPE_FLAG_TRAILER2) {
68588
+ if (envelope.flags === ENVELOPE_FLAG_TRAILER) {
68545
68589
  this.opts.log.info("[clip-provider] received end-of-stream trailer");
68546
68590
  continue;
68547
68591
  }
@@ -68577,10 +68621,10 @@ var init_clip_provider = __esm({
68577
68621
  this.clearHeartbeatTimer();
68578
68622
  this.scheduleReconnect();
68579
68623
  }
68580
- scheduleReconnect() {
68624
+ scheduleReconnect(delayMs) {
68581
68625
  if (this.stopped || this.reconnectTimer)
68582
68626
  return;
68583
- const delay = Math.min(_ClipProvider.RECONNECT_BASE_MS * Math.pow(2, this.reconnectAttempt), _ClipProvider.RECONNECT_MAX_MS);
68627
+ const delay = delayMs ?? Math.min(_ClipProvider.RECONNECT_BASE_MS * Math.pow(2, this.reconnectAttempt), _ClipProvider.RECONNECT_MAX_MS);
68584
68628
  this.reconnectAttempt++;
68585
68629
  this.opts.log.info(`[clip-provider] reconnecting in ${delay}ms (attempt ${this.reconnectAttempt})`);
68586
68630
  if (this.reconnectAttempt % _ClipProvider.PERSISTENT_FAILURE_ATTEMPT === 0) {
@@ -68723,11 +68767,19 @@ var init_clip_provider = __esm({
68723
68767
  this.opts.log.info(`[clip-provider] registered with hub (org=${this.opts.orgId})`);
68724
68768
  this.connected = true;
68725
68769
  this.reconnectAttempt = 0;
68770
+ this.rejectedAttempt = 0;
68726
68771
  this.startHeartbeat();
68727
68772
  this.flushReregister();
68728
68773
  } else {
68729
68774
  this.opts.log.error(`[clip-provider] registration rejected: ${reg.message}`);
68730
- this.stopped = true;
68775
+ this.connected = false;
68776
+ const retryDelay = this.opts.rejectedRetryDelayMs?.(this.rejectedAttempt++);
68777
+ if (retryDelay === void 0) {
68778
+ this.stopped = true;
68779
+ } else {
68780
+ this.clearHeartbeatTimer();
68781
+ this.scheduleReconnect(retryDelay);
68782
+ }
68731
68783
  this.closeStream();
68732
68784
  this.closeSession();
68733
68785
  }
@@ -68846,7 +68898,7 @@ var init_clip_provider = __esm({
68846
68898
  if (!this.stream || this.stream.closed || this.stream.destroyed) {
68847
68899
  throw new Error("stream not open");
68848
68900
  }
68849
- const envelope = encodeEnvelope2(msg);
68901
+ const envelope = encodeEnvelope(msg);
68850
68902
  return new Promise((resolve9, reject) => {
68851
68903
  this.stream.write(envelope, (err) => {
68852
68904
  if (err)
@@ -71968,7 +72020,7 @@ function sleepCancellable(ms, signal) {
71968
72020
  signal.addEventListener("abort", onAbort, { once: true });
71969
72021
  });
71970
72022
  }
71971
- var RUNTIME_PACKAGES, WORKSPACE_SETUP_RETRY_DELAY_MS, PARK_KEEPALIVE_MS, AGENT_CONFIG_REFRESH_RETRY_DELAY_MS, CLIP_RECONCILE_INTERVAL_MS, RUNTIME_DETECT_INTERVAL_MS, DaemonSupervisor;
72023
+ var RUNTIME_PACKAGES, WORKSPACE_SETUP_RETRY_DELAY_MS, MACHINE_KEY_RECOVERY, AGENT_CONFIG_REFRESH_RETRY_DELAY_MS, CLIP_RECONCILE_INTERVAL_MS, RUNTIME_DETECT_INTERVAL_MS, DaemonSupervisor;
71972
72024
  var init_supervisor = __esm({
71973
72025
  "ts/daemon/dist/supervisor.js"() {
71974
72026
  "use strict";
@@ -71998,7 +72050,7 @@ var init_supervisor = __esm({
71998
72050
  openclaw: "@parall/openclaw-agent"
71999
72051
  };
72000
72052
  WORKSPACE_SETUP_RETRY_DELAY_MS = 5e3;
72001
- PARK_KEEPALIVE_MS = 6e4;
72053
+ MACHINE_KEY_RECOVERY = 'The daemon keeps retrying and reconnects by itself if the key becomes valid again. If it keeps failing, the key was revoked or rotated, this machine was deleted, or its owner left the org: re-register this machine to get a new key \u2014 Desktop app: "Disable daemon", then "Enable daemon" (this registers a new machine and tries to delete the old one; re-attach its agents); CLI or server: create a machine under Compute in Parall and run `parall-daemon init` with its key \u2014 then restart the daemon. If you left the org or your account was disabled, this machine cannot be registered there again.';
72002
72054
  AGENT_CONFIG_REFRESH_RETRY_DELAY_MS = 5e3;
72003
72055
  CLIP_RECONCILE_INTERVAL_MS = 5 * 6e4;
72004
72056
  RUNTIME_DETECT_INTERVAL_MS = 5 * 6e4;
@@ -72038,6 +72090,9 @@ var init_supervisor = __esm({
72038
72090
  // registration check already keeps the stale state from ever spawning.
72039
72091
  restartingStates = /* @__PURE__ */ new Set();
72040
72092
  ws = null;
72093
+ // Slow re-arm of the machine WS after the server rejected this machine's key.
72094
+ wsAuthRetryTimer = null;
72095
+ wsAuthRetryAttempt = 0;
72041
72096
  running = false;
72042
72097
  machineId = null;
72043
72098
  /**
@@ -72206,17 +72261,7 @@ var init_supervisor = __esm({
72206
72261
  });
72207
72262
  this.ws.on("machine.update", (data) => {
72208
72263
  this.log.info(`WS: daemon update available \u2014 version=${data.new_version} mandatory=${data.mandatory}`);
72209
- if (this.updater) {
72210
- void this.updater.triggerUpdate(data.new_version, data.mandatory).then(async (applied) => {
72211
- if (applied) {
72212
- this.log.info("daemon update applied \u2014 stopping supervisor before restart");
72213
- await this.stop();
72214
- process.exit(42);
72215
- }
72216
- }).catch((err) => {
72217
- this.log.warn(`daemon update failed: ${String(err)}`);
72218
- });
72219
- }
72264
+ void this.updater?.triggerUpdate(data.new_version, data.mandatory);
72220
72265
  });
72221
72266
  this.ws.on("machine.agent.attached", (data) => {
72222
72267
  this.log.info(`WS: agent ${data.agent_id} attached`);
@@ -72274,10 +72319,10 @@ var init_supervisor = __esm({
72274
72319
  if (state === "reconnecting") {
72275
72320
  this.daemonTelemetry?.recordWsReconnect({ cause: detail?.cause, closeCode: detail?.code });
72276
72321
  }
72322
+ if (state === "connected")
72323
+ this.wsAuthRetryAttempt = 0;
72277
72324
  });
72278
- this.ws.onAuthInvalid((event) => {
72279
- this.log.error(`machine WS auth-invalid: the server rejected this machine's key (status ${event.status}${event.code ? `, code ${event.code}` : ""}) \u2014 ${event.message}. Control-plane events (attach/detach, config updates, update signals) are OFFLINE and reconnects are stopped. Re-register or re-authenticate this machine (Desktop app or \`parall-daemon register\`) to install a new machine key, then restart the daemon.`);
72280
- });
72325
+ this.ws.onAuthInvalid((event) => this.handleMachineWsAuthInvalid(event));
72281
72326
  await this.ws.connect();
72282
72327
  await new Promise((resolve9) => {
72283
72328
  this.stopResolve = resolve9;
@@ -72290,6 +72335,10 @@ var init_supervisor = __esm({
72290
72335
  return;
72291
72336
  this.running = false;
72292
72337
  this.healthGate?.onSupervisorEnded();
72338
+ if (this.wsAuthRetryTimer) {
72339
+ clearTimeout(this.wsAuthRetryTimer);
72340
+ this.wsAuthRetryTimer = null;
72341
+ }
72293
72342
  if (this.ws) {
72294
72343
  this.ws.disconnect();
72295
72344
  this.ws = null;
@@ -72344,9 +72393,31 @@ var init_supervisor = __esm({
72344
72393
  this.stopResolve = null;
72345
72394
  }
72346
72395
  }
72396
+ /**
72397
+ * The SDK stops after its small auth budget; re-arm it on the slow credential
72398
+ * schedule (connect() from auth-invalid grants a fresh budget). Running
72399
+ * children keep their own agk_ and are left alone; machine.hello on
72400
+ * reconnect replays whatever was missed.
72401
+ */
72402
+ handleMachineWsAuthInvalid(event) {
72403
+ if (!this.running)
72404
+ return;
72405
+ const delay = this.credentialRetryDelay(this.wsAuthRetryAttempt++);
72406
+ this.log.error(`machine WS auth-invalid: the server rejected this machine's key (status ${event.status}${event.code ? `, code ${event.code}` : ""}) \u2014 ${event.message}. Control-plane events (attach/detach, config updates, update signals) are OFFLINE; retrying in ${Math.round(delay / 1e3)}s. ` + MACHINE_KEY_RECOVERY);
72407
+ this.wsAuthRetryTimer = setTimeout(() => {
72408
+ this.wsAuthRetryTimer = null;
72409
+ if (this.running)
72410
+ void this.ws?.connect();
72411
+ }, delay);
72412
+ }
72347
72413
  // ---- Bootstrap (resilient identity probe) ----
72414
+ /** Slow schedule shared by every machine-key rejection retry (boot, WS, ProviderStream). */
72415
+ credentialRetryDelay(attempt) {
72416
+ return Math.min(this.config.credentialRetryBackoffMs * 2 ** attempt, this.config.credentialRetryBackoffMaxMs);
72417
+ }
72348
72418
  async bootstrapWithRetry(signal) {
72349
72419
  let attempt = 0;
72420
+ let credentialAttempt = 0;
72350
72421
  while (this.running && !signal.aborted) {
72351
72422
  try {
72352
72423
  const machine = await this.client.getMachineSelf();
@@ -72360,21 +72431,11 @@ var init_supervisor = __esm({
72360
72431
  return true;
72361
72432
  } catch (err) {
72362
72433
  if (err instanceof ApiError && err.status === 401) {
72363
- this.log.error(`machine key rejected by the server (status 401${err.code ? `, code ${err.code}` : ""}): ${err.message}. The daemon cannot start with this machine key and no automatic recovery exists \u2014 re-register or re-authenticate this machine (Desktop app or \`parall-daemon register\`) to install a new machine key, then restart the daemon.`);
72364
- const parked = setInterval(() => {
72365
- }, PARK_KEEPALIVE_MS);
72366
- try {
72367
- await new Promise((resolve9) => {
72368
- if (signal.aborted) {
72369
- resolve9();
72370
- return;
72371
- }
72372
- signal.addEventListener("abort", () => resolve9(), { once: true });
72373
- });
72374
- } finally {
72375
- clearInterval(parked);
72376
- }
72377
- return false;
72434
+ const delay2 = this.credentialRetryDelay(credentialAttempt++);
72435
+ this.log.error(`machine key rejected by the server (status 401${err.code ? `, code ${err.code}` : ""}): ${err.message}. Retrying in ${Math.round(delay2 / 1e3)}s. ${MACHINE_KEY_RECOVERY}`);
72436
+ if (!await sleepCancellable(delay2, signal))
72437
+ return false;
72438
+ continue;
72378
72439
  }
72379
72440
  if (this.config.bootstrapBackoffMs === 0) {
72380
72441
  this.log.error(`getMachineSelf failed: ${String(err)} (fail-fast mode)`);
@@ -73144,7 +73205,8 @@ var init_supervisor = __esm({
73144
73205
  // server may have rolled out a (new) clip_provider_url after we booted
73145
73206
  // (our ws-gateway WS never bounced to re-trigger machine.hello). Refetch
73146
73207
  // machine config; applyClipProviderState rebuilds us if the URL moved.
73147
- onPersistentFailure: () => void this.refreshMachineConfig()
73208
+ onPersistentFailure: () => void this.refreshMachineConfig(),
73209
+ rejectedRetryDelayMs: (attempt) => this.credentialRetryDelay(attempt)
73148
73210
  });
73149
73211
  this.clipProvider.connect().catch((err) => this.log.warn(`clip provider connect failed: ${String(err)}`));
73150
73212
  } else if (this.clipProvider) {
@@ -73721,6 +73783,7 @@ async function main(bootstrap2) {
73721
73783
  process.exit(1);
73722
73784
  });
73723
73785
  config.wsUrl = resolveWsUrl(config.apiUrl, config.wsUrl, config.swimlaneName);
73786
+ let restartForUpdate = false;
73724
73787
  if (updater) {
73725
73788
  const applied = await updater.checkAndApply().catch((err) => {
73726
73789
  log.warn(`boot update check failed: ${String(err)}`);
@@ -73732,11 +73795,19 @@ async function main(bootstrap2) {
73732
73795
  await telemetry.shutdown();
73733
73796
  process.exit(UPDATE_EXIT_CODE);
73734
73797
  }
73798
+ updater.setRestartHandler(() => {
73799
+ restartForUpdate = true;
73800
+ abortController.abort();
73801
+ });
73735
73802
  updater.startPeriodicCheck(config.updateIntervalMs);
73736
73803
  }
73737
73804
  await runForever(config, client, log, abortController.signal, updater, healthGate, daemonTelemetry);
73738
73805
  daemonTelemetry.stop();
73739
73806
  await telemetry.shutdown();
73807
+ if (restartForUpdate) {
73808
+ log.info("daemon update applied \u2014 exiting for service manager restart");
73809
+ process.exit(UPDATE_EXIT_CODE);
73810
+ }
73740
73811
  }
73741
73812
  async function runDaemonEntry(bootstrap2, args = process.argv.slice(2)) {
73742
73813
  try {
@@ -8,7 +8,7 @@
8
8
  * Service hub as the "browser" provider for exactly ONE profile.
9
9
  *
10
10
  * It is deliberately NOT the daemon supervisor. The daemon (`index.ts`) is a
11
- * Machine: it authenticates with a 90-day `mck_`, polls `/machines/me/*`, and
11
+ * Machine: it authenticates with a long-lived `mck_`, polls `/machines/me/*`, and
12
12
  * supervises per-agent subprocesses. A hosted browser pod has none of that — it
13
13
  * is platform infrastructure with a short-lived, controller-minted platform
14
14
  * assignment token (`pba_`) scoped to `(org_id, profile_id, pod_id)`, and serves
@@ -8,7 +8,7 @@
8
8
  * Service hub as the "browser" provider for exactly ONE profile.
9
9
  *
10
10
  * It is deliberately NOT the daemon supervisor. The daemon (`index.ts`) is a
11
- * Machine: it authenticates with a 90-day `mck_`, polls `/machines/me/*`, and
11
+ * Machine: it authenticates with a long-lived `mck_`, polls `/machines/me/*`, and
12
12
  * supervises per-agent subprocesses. A hosted browser pod has none of that — it
13
13
  * is platform infrastructure with a short-lived, controller-minted platform
14
14
  * assignment token (`pba_`) scoped to `(org_id, profile_id, pod_id)`, and serves
@@ -39,6 +39,9 @@ export interface ClipProviderOptions {
39
39
  * re-trigger machine.hello. Optional.
40
40
  */
41
41
  onPersistentFailure?: () => void;
42
+ /** Retry delay after the hub rejects registration. BYOC sets it (a rejected mck_ can
43
+ * recover); hosted pods leave it unset and stop (their lease was superseded). */
44
+ rejectedRetryDelayMs?: (attempt: number) => number;
42
45
  /**
43
46
  * Hosted-browser live-viewer handler. Set ONLY for a hosted browser pod
44
47
  * (browser-pod.ts): clip-service relays viewer commands down the
@@ -68,6 +71,7 @@ export declare class ClipProvider {
68
71
  private stopped;
69
72
  private connected;
70
73
  private reconnectAttempt;
74
+ private rejectedAttempt;
71
75
  private reconnectTimer;
72
76
  private heartbeatTimer;
73
77
  private statusUnsubscribe;
@@ -1 +1 @@
1
- {"version":3,"file":"clip-provider.d.ts","sourceRoot":"","sources":["../../src/clip-runtime/clip-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AA6L/D,MAAM,WAAW,mBAAmB;IAClC,sDAAsD;IACtD,UAAU,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,YAAY,EAAE,MAAM,CAAC;IACrB,yDAAyD;IACzD,WAAW,EAAE,kBAAkB,CAAC;IAChC,mBAAmB;IACnB,GAAG,EAAE;QAAE,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAA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