@alook/daemon 0.1.71 → 0.1.72

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.
Files changed (3) hide show
  1. package/dist/cli/index.js +685 -432
  2. package/dist/index.js +681 -429
  3. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -13521,13 +13521,13 @@ var require_sourcemap_codec_umd = __commonJS((exports, module) => {
13521
13521
  });
13522
13522
  });
13523
13523
 
13524
- // ../../node_modules/.pnpm/@jridgewell+resolve-uri@3.1.2/node_modules/@jridgewell/resolve-uri/dist/resolve-uri.umd.js
13524
+ // ../../node_modules/.pnpm/@jridgewell+resolve-uri@3.1.3/node_modules/@jridgewell/resolve-uri/dist/resolve-uri.umd.js
13525
13525
  var require_resolve_uri_umd = __commonJS((exports, module) => {
13526
13526
  (function(global, factory) {
13527
13527
  typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, global.resolveURI = factory());
13528
13528
  })(exports, function() {
13529
13529
  const schemeRegex = /^[\w+.-]+:\/\//;
13530
- const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
13530
+ const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?(\[[^\]]+\]|[^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
13531
13531
  const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
13532
13532
  function isAbsoluteUrl(input2) {
13533
13533
  return schemeRegex.test(input2);
@@ -24216,9 +24216,11 @@ function parseNativeExecution(data) {
24216
24216
 
24217
24217
  class NativeExecutionReader {
24218
24218
  readRows;
24219
+ continuations;
24219
24220
  path;
24220
- constructor(home, sessionId, readRows = queryExecutionRows) {
24221
+ constructor(home, sessionId, readRows = queryExecutionRows, continuations = false) {
24221
24222
  this.readRows = readRows;
24223
+ this.continuations = continuations;
24222
24224
  if (!/^[a-zA-Z0-9_-]{1,100}$/.test(sessionId))
24223
24225
  throw new Error("Invalid native execution session identity");
24224
24226
  this.path = join4(home, "antigravity-cli", "conversations", `${sessionId}.db`);
@@ -24234,20 +24236,28 @@ class NativeExecutionReader {
24234
24236
  return { index: row.idx, executionId: execution.executionId, lastStepIndex: execution.lastStepIndex };
24235
24237
  }
24236
24238
  async terminal(checkpoint) {
24237
- const rows = await this.readRows(this.path, checkpoint.index, checkpoint.lastStepIndex);
24238
- if (rows.length !== 1)
24239
+ const max = this.continuations ? 32 : 1;
24240
+ const rows = await this.readRows(this.path, checkpoint.index, checkpoint.lastStepIndex, undefined, max + 1);
24241
+ if (!rows.length || rows.length > max)
24239
24242
  throw new Error("Native execution terminal unavailable or ambiguous");
24240
- const row = this.validate(rows[0]);
24241
- const execution = parseNativeExecution(Buffer.from(row.data, "hex"));
24242
- if (row.has_children !== 0)
24243
- throw new Error("Native executor subtrajectory ownership cannot be verified");
24244
- if (row.idx !== checkpoint.index + 1 || execution.executionId === checkpoint.executionId)
24245
- throw new Error("Native execution terminal does not belong to the new root");
24246
- if (execution.hasError || execution.reason === 1)
24247
- return "failed";
24248
- if (execution.reason === 2)
24249
- return "interrupted";
24250
- return execution.reason === 4 ? "success" : "failed";
24243
+ let lastStep = checkpoint.lastStepIndex;
24244
+ const identities = new Set([checkpoint.executionId]);
24245
+ let outcome = "success";
24246
+ for (let index = 0;index < rows.length; index++) {
24247
+ const row = this.validate(rows[index]);
24248
+ const execution = parseNativeExecution(Buffer.from(row.data, "hex"));
24249
+ if (row.has_children !== 0)
24250
+ throw new Error("Native executor subtrajectory ownership cannot be verified");
24251
+ if (row.idx !== checkpoint.index + index + 1 || identities.has(execution.executionId) || this.continuations && execution.lastStepIndex <= lastStep)
24252
+ throw new Error("Native execution terminal does not belong to the new root");
24253
+ identities.add(execution.executionId);
24254
+ lastStep = execution.lastStepIndex;
24255
+ if (execution.hasError || execution.reason !== 2 && execution.reason !== 4)
24256
+ outcome = "failed";
24257
+ else if (execution.reason === 2 && outcome !== "failed")
24258
+ outcome = "interrupted";
24259
+ }
24260
+ return outcome;
24251
24261
  }
24252
24262
  validate(row) {
24253
24263
  if (!Number.isSafeInteger(row.idx) || row.idx < 0 || !/^(?:[a-f0-9]{2})+$/i.test(row.data) || row.data.length > 2 * 1024 * 1024)
@@ -24269,10 +24279,12 @@ async function openNativeExecutionDatabase(path4, loadBuiltin = async () => {
24269
24279
  }
24270
24280
  return new sqlite.DatabaseSync(path4, { readOnly: true });
24271
24281
  }
24272
- async function queryExecutionRows(path4, after, afterStep = -1, openDatabase = openNativeExecutionDatabase) {
24282
+ async function queryExecutionRows(path4, after, afterStep = -1, openDatabase = openNativeExecutionDatabase, maxRows = 2) {
24273
24283
  if (after !== undefined && (!Number.isSafeInteger(after) || after < -1) || !Number.isSafeInteger(afterStep) || afterStep < -1)
24274
24284
  throw new Error("Invalid native execution cursor");
24275
- const query = `SELECT idx,hex(substr(data,1,1048577)) AS data,${after === undefined ? "(SELECT EXISTS(SELECT 1 FROM steps WHERE idx<0 AND has_subtrajectory=1))" : `(SELECT EXISTS(SELECT 1 FROM steps WHERE idx>${afterStep} AND has_subtrajectory=1))`} AS has_children FROM executor_metadata ${after === undefined ? "ORDER BY idx DESC LIMIT 1" : `WHERE idx>${after} ORDER BY idx LIMIT 2`}`;
24285
+ if (!Number.isSafeInteger(maxRows) || maxRows < 1 || maxRows > 33)
24286
+ throw new Error("Invalid native execution read limit");
24287
+ const query = `SELECT idx,hex(substr(data,1,1048577)) AS data,${after === undefined ? "(SELECT EXISTS(SELECT 1 FROM steps WHERE idx<0 AND has_subtrajectory=1))" : `(SELECT EXISTS(SELECT 1 FROM steps WHERE idx>${afterStep} AND has_subtrajectory=1))`} AS has_children FROM executor_metadata ${after === undefined ? "ORDER BY idx DESC LIMIT 1" : `WHERE idx>${after} ORDER BY idx LIMIT ${maxRows}`}`;
24276
24288
  const db = await openDatabase(path4);
24277
24289
  try {
24278
24290
  return db.prepare(query).all();
@@ -24281,6 +24293,37 @@ async function queryExecutionRows(path4, after, afterStep = -1, openDatabase = o
24281
24293
  }
24282
24294
  }
24283
24295
 
24296
+ class NativeSessionActivityReader {
24297
+ sessionId;
24298
+ version;
24299
+ openDatabase;
24300
+ path;
24301
+ constructor(home, sessionId, version, openDatabase = openNativeExecutionDatabase) {
24302
+ this.sessionId = sessionId;
24303
+ this.version = version;
24304
+ this.openDatabase = openDatabase;
24305
+ if (!/^[a-zA-Z0-9_-]{1,100}$/.test(sessionId))
24306
+ throw new Error("Invalid native activity session identity");
24307
+ this.path = join4(home, "antigravity-cli", "conversation_summaries.db");
24308
+ }
24309
+ async activity() {
24310
+ if (this.version !== "1.5.16")
24311
+ return "unknown";
24312
+ const db = await this.openDatabase(this.path);
24313
+ try {
24314
+ const rows = db.prepare("SELECT status,not_fully_idle FROM conversation_summaries WHERE conversation_id = ? LIMIT 1").all(this.sessionId);
24315
+ const row = rows[0];
24316
+ if (!row || row.not_fully_idle !== 0 && row.not_fully_idle !== 1)
24317
+ return "unknown";
24318
+ if (row.status === "CASCADE_RUN_STATUS_RUNNING")
24319
+ return "running";
24320
+ return row.status === "CASCADE_RUN_STATUS_IDLE" ? row.not_fully_idle ? "running" : "idle" : "unknown";
24321
+ } finally {
24322
+ db.close();
24323
+ }
24324
+ }
24325
+ }
24326
+
24284
24327
  // agent-driver/dist/internal/model-observation.js
24285
24328
  function id(value) {
24286
24329
  if (typeof value !== "string")
@@ -24498,6 +24541,18 @@ class AgyAcpLane {
24498
24541
  events = new EventEmitter;
24499
24542
  pending = new Map;
24500
24543
  toolCalls = new Map;
24544
+ completedTools = new Set;
24545
+ unownedContent = false;
24546
+ activityReader;
24547
+ activityRead;
24548
+ activityTimer;
24549
+ nativeActivity = "unknown";
24550
+ publishedActivity;
24551
+ activityRevision = 0;
24552
+ nativeVersion = "";
24553
+ contentOwner;
24554
+ executionIsolated = true;
24555
+ nativeClose = false;
24501
24556
  process = null;
24502
24557
  requestSequence = 0;
24503
24558
  started = false;
@@ -24573,10 +24628,13 @@ class AgyAcpLane {
24573
24628
  const sessionId = this.sessionId;
24574
24629
  if (!sessionId)
24575
24630
  throw new Error("Agy ACP handshake completed without a session id");
24576
- this.executionReader = this.options.executionReader ?? new NativeExecutionReader(this.stateHome, sessionId);
24631
+ this.executionReader = this.options.executionReader ?? new NativeExecutionReader(this.stateHome, sessionId, undefined, this.nativeVersion === "1.5.16");
24577
24632
  this.processActivated = true;
24578
24633
  this.ready = true;
24579
24634
  this.events.emit("runtime_event", { kind: "session_init", sessionId, acquisition: { status: input.sessionId ? "resumed" : "created", evidence: "native_api" } });
24635
+ this.activityReader = this.options.activityReader ?? new NativeSessionActivityReader(this.stateHome, sessionId, this.nativeVersion);
24636
+ await this.refreshActivity();
24637
+ this.scheduleActivity();
24580
24638
  const admission = await this.admitRoot(input.text, input.inputs);
24581
24639
  if (!admission.ok)
24582
24640
  throw new AgyAcpIncompatibleError(admission.error ?? "Native execution state unavailable");
@@ -24621,6 +24679,8 @@ class AgyAcpLane {
24621
24679
  stop(input = {}) {
24622
24680
  this.requestedStopReason ??= input.reason ?? "requested_stop";
24623
24681
  this.ready = false;
24682
+ if (this.activityTimer)
24683
+ clearTimeout(this.activityTimer);
24624
24684
  this.currentPromptRequestId = null;
24625
24685
  this.terminalOwner = null;
24626
24686
  this.toolCalls.clear();
@@ -24638,20 +24698,29 @@ class AgyAcpLane {
24638
24698
  return this.stopPromise;
24639
24699
  }
24640
24700
  async stopPhysicalOnce(input) {
24701
+ const deadline = Date.now() + (input.forceAfterMs ?? SESSION_STOP_GRACE_MS);
24641
24702
  await this.spawnPromise?.catch(() => {
24642
24703
  return;
24643
24704
  });
24644
24705
  const proc = this.process;
24645
24706
  if (!proc)
24646
24707
  return;
24708
+ let closeAcknowledged = false;
24709
+ if (this.nativeClose && this.sessionId && !this.isClosed() && deadline > Date.now()) {
24710
+ try {
24711
+ await this.request("session/close", { sessionId: this.sessionId }, Math.max(1, deadline - Date.now())).promise;
24712
+ closeAcknowledged = true;
24713
+ } catch {}
24714
+ }
24647
24715
  if (proc.pid) {
24648
- await killProcessTree(proc.pid, { graceMs: input.forceAfterMs ?? SESSION_STOP_GRACE_MS });
24716
+ await killProcessTree(proc.pid, { graceMs: closeAcknowledged ? 0 : Math.max(0, deadline - Date.now()) });
24649
24717
  } else if (!this.isClosed()) {
24650
24718
  proc.kill(input.signal ?? "SIGTERM");
24651
24719
  }
24652
24720
  await this.executionRead?.catch(() => {
24653
24721
  return;
24654
24722
  });
24723
+ await this.activityRead;
24655
24724
  }
24656
24725
  async handshake(ctx) {
24657
24726
  const initialize = record2(await this.call("initialize", {
@@ -24666,6 +24735,7 @@ class AgyAcpLane {
24666
24735
  throw new AgyAcpIncompatibleError("Installed Agy ACP does not support protocol version 1");
24667
24736
  }
24668
24737
  const capabilities = record2(initialize.agentCapabilities);
24738
+ this.nativeClose = record2(record2(capabilities?.sessionCapabilities)?.close) !== null;
24669
24739
  if (capabilities?.loadSession !== true) {
24670
24740
  throw new AgyAcpIncompatibleError("Installed Agy ACP does not support persistent session loading");
24671
24741
  }
@@ -24673,6 +24743,7 @@ class AgyAcpLane {
24673
24743
  throw new AgyAcpIncompatibleError("Expected the native Antigravity CLI ACP server");
24674
24744
  }
24675
24745
  const version = record2(initialize.agentInfo)?.version;
24746
+ this.nativeVersion = typeof version === "string" ? version : "";
24676
24747
  this.usageProfile = version === "1.4.12" ? { inputIncludesCache: true, outputIncludesReasoning: false } : version === "1.5.9" ? { inputIncludesCache: false, outputIncludesReasoning: true } : undefined;
24677
24748
  if (!record2(record2(initialize.agentCapabilities)?.sessionCapabilities)?.resume) {
24678
24749
  throw new AgyAcpIncompatibleError("Antigravity CLI ACP does not support native session resume");
@@ -24879,6 +24950,7 @@ class AgyAcpLane {
24879
24950
  if (!this.ready || this.requestedStopReason || this.isClosed())
24880
24951
  return { ok: false, reason: "closed" };
24881
24952
  this.executionCheckpoint = checkpoint;
24953
+ this.executionIsolated = !this.unownedContent && !this.hasPendingTools();
24882
24954
  return this.admitPrompt(text, "prompt", inputs);
24883
24955
  } catch {
24884
24956
  return { ok: false, reason: "runtime_error", error: "Antigravity CLI native execution state cannot be verified. A readable native conversation database and the packaged SQLite runtime are required." };
@@ -24905,7 +24977,7 @@ class AgyAcpLane {
24905
24977
  this.terminalOwner = prompt.receipt;
24906
24978
  this.currentPromptRequestId = requestId;
24907
24979
  if (delivery === "prompt") {
24908
- this.toolCalls.clear();
24980
+ this.contentOwner = !this.unownedContent && !this.hasPendingTools() ? prompt.receipt : undefined;
24909
24981
  this.promptOutcomes.clear();
24910
24982
  this.observedPrompts.clear();
24911
24983
  this.loopStartedAt = new Date().toISOString();
@@ -24972,13 +25044,22 @@ class AgyAcpLane {
24972
25044
  const read = this.executionReader.terminal(this.executionCheckpoint);
24973
25045
  this.executionRead = read;
24974
25046
  nativeOutcome = await read;
25047
+ if (!this.executionIsolated)
25048
+ nativeOutcome = "unknown";
24975
25049
  } catch {
24976
- verificationError = new Error("Antigravity CLI native execution terminal could not be verified");
25050
+ if (this.executionIsolated)
25051
+ verificationError = new Error("Antigravity CLI native execution terminal could not be verified");
25052
+ else
25053
+ nativeOutcome = "unknown";
24977
25054
  } finally {
24978
25055
  this.executionRead = undefined;
24979
25056
  }
24980
25057
  if (this.terminalOwner !== owner || this.requestedStopReason || this.processTerminal)
24981
25058
  return;
25059
+ if (this.hasPendingTools())
25060
+ this.unownedContent = true;
25061
+ this.observeOutsideWork();
25062
+ this.refreshActivity();
24982
25063
  this.finishing = false;
24983
25064
  const outcomes = [...this.promptOutcomes].sort(([a], [b]) => b - a);
24984
25065
  let latest = outcomes.find(([, outcome]) => outcome.error)?.[1] ?? outcomes[0]?.[1];
@@ -25011,7 +25092,7 @@ class AgyAcpLane {
25011
25092
  this.usage.reset();
25012
25093
  this.currentPromptRequestId = null;
25013
25094
  this.terminalOwner = null;
25014
- this.toolCalls.clear();
25095
+ this.contentOwner = undefined;
25015
25096
  this.promptOutcomes.clear();
25016
25097
  this.observedPrompts.clear();
25017
25098
  if (!latest) {
@@ -25023,7 +25104,7 @@ class AgyAcpLane {
25023
25104
  kind: "turn_end",
25024
25105
  sessionId: this.sessionId ?? undefined,
25025
25106
  turnOwner: terminalOwner,
25026
- outcome: latest?.stopReason === "cancelled" ? "interrupted" : latest?.stopReason === "end_turn" ? "success" : "failed",
25107
+ outcome: latest?.stopReason === "cancelled" ? "interrupted" : latest?.stopReason === "end_turn" ? nativeOutcome === "unknown" ? "unknown" : "success" : "failed",
25027
25108
  stopReason: latest?.stopReason,
25028
25109
  ...latest?.stopReason === "cancelled" ? { pendingContent: "discard" } : {}
25029
25110
  });
@@ -25255,24 +25336,38 @@ class AgyAcpLane {
25255
25336
  this.rememberConfig(configuration, true);
25256
25337
  return;
25257
25338
  }
25258
- if (!this.ready || this.currentPromptRequestId === null) {
25259
- this.diagnostic("warning", "Agy ACP emitted a session update without an active prompt");
25339
+ if (!this.ready || this.requestedStopReason || this.processTerminal)
25260
25340
  return;
25261
- }
25262
25341
  const update = record2(payload.update) ?? {};
25263
25342
  const updateType = update?.sessionUpdate;
25264
25343
  switch (updateType) {
25265
25344
  case "agent_message_chunk": {
25266
25345
  const content = record2(update.content);
25267
25346
  if (content?.type === "text" && typeof content.text === "string") {
25268
- this.events.emit("runtime_event", { kind: "assistant_message_delta", text: content.text });
25347
+ if (!this.contentOwner || this.contentOwner !== this.terminalOwner) {
25348
+ this.unownedContent = true;
25349
+ this.observeOutsideWork();
25350
+ }
25351
+ this.events.emit("runtime_event", {
25352
+ kind: "assistant_message_delta",
25353
+ text: content.text,
25354
+ ...!this.contentOwner || this.contentOwner !== this.terminalOwner ? { attribution: { scope: "session" } } : {}
25355
+ });
25269
25356
  }
25270
25357
  return;
25271
25358
  }
25272
25359
  case "agent_thought_chunk": {
25273
25360
  const content = record2(update.content);
25274
25361
  if (content?.type === "text" && typeof content.text === "string") {
25275
- this.events.emit("runtime_event", { kind: "assistant_reasoning_delta", text: content.text });
25362
+ if (!this.contentOwner || this.contentOwner !== this.terminalOwner) {
25363
+ this.unownedContent = true;
25364
+ this.observeOutsideWork();
25365
+ }
25366
+ this.events.emit("runtime_event", {
25367
+ kind: "assistant_reasoning_delta",
25368
+ text: content.text,
25369
+ ...!this.contentOwner || this.contentOwner !== this.terminalOwner ? { attribution: { scope: "session" } } : {}
25370
+ });
25276
25371
  }
25277
25372
  return;
25278
25373
  }
@@ -25296,56 +25391,67 @@ class AgyAcpLane {
25296
25391
  this.diagnostic("warning", "Agy ACP emitted a malformed tool_call update");
25297
25392
  return;
25298
25393
  }
25299
- if (!this.toolCalls.has(update.toolCallId)) {
25300
- const name = typeof update.name === "string" ? update.name : update.title;
25301
- this.toolCalls.set(update.toolCallId, name);
25394
+ if (this.completedTools.has(update.toolCallId))
25395
+ return;
25396
+ let tool = this.toolCalls.get(update.toolCallId);
25397
+ if (!tool) {
25398
+ tool = {
25399
+ name: typeof update.name === "string" ? update.name : update.title,
25400
+ owner: this.contentOwner
25401
+ };
25402
+ this.toolCalls.set(update.toolCallId, tool);
25302
25403
  this.events.emit("runtime_event", {
25303
25404
  kind: "tool_call",
25304
25405
  callId: update.toolCallId,
25305
- name,
25306
- input: update.rawInput
25307
- });
25308
- }
25309
- if ((update.status === "completed" || update.status === "failed") && this.toolCalls.get(update.toolCallId) !== null) {
25310
- const name = this.toolCalls.get(update.toolCallId) ?? update.title;
25311
- this.toolCalls.set(update.toolCallId, null);
25312
- this.events.emit("runtime_event", {
25313
- kind: "tool_output",
25314
- callId: update.toolCallId,
25315
- name,
25316
- outcome: update.status === "failed" ? "failed" : "success",
25317
- output: update.rawOutput
25406
+ name: tool.name,
25407
+ input: update.rawInput,
25408
+ ...tool.owner && tool.owner === this.terminalOwner ? {} : { attribution: { scope: "session" } }
25318
25409
  });
25319
25410
  }
25411
+ this.observeOutsideWork();
25412
+ if (update.status === "completed" || update.status === "failed")
25413
+ this.finishTool(update, tool);
25320
25414
  return;
25321
25415
  }
25322
25416
  case "tool_call_update": {
25323
- if (typeof update.toolCallId === "string" && (update.status === "completed" || update.status === "failed")) {
25324
- const name = this.toolCalls.get(update.toolCallId);
25325
- if (name === undefined || name === null)
25326
- return;
25327
- this.toolCalls.set(update.toolCallId, null);
25328
- this.events.emit("runtime_event", {
25329
- kind: "tool_output",
25330
- callId: update.toolCallId,
25331
- outcome: update.status === "failed" ? "failed" : "success",
25332
- output: update.rawOutput,
25333
- name
25334
- });
25335
- }
25417
+ if (typeof update.toolCallId !== "string")
25418
+ return;
25419
+ const tool = this.toolCalls.get(update.toolCallId);
25420
+ if (!tool)
25421
+ return;
25422
+ if (update.status === "completed" || update.status === "failed")
25423
+ this.finishTool(update, tool);
25336
25424
  return;
25337
25425
  }
25338
25426
  case "plan":
25339
25427
  this.events.emit("runtime_event", {
25340
25428
  kind: "internal_progress",
25341
25429
  source: "agy.acp",
25342
- itemType: "plan"
25430
+ itemType: "plan",
25431
+ ...!this.contentOwner || this.contentOwner !== this.terminalOwner ? { attribution: { scope: "session" } } : {}
25343
25432
  });
25344
25433
  return;
25345
25434
  default:
25346
25435
  this.diagnostic("warning", `Unsupported Agy ACP session update: ${safeLabel(updateType)}`);
25347
25436
  }
25348
25437
  }
25438
+ finishTool(update, tool) {
25439
+ this.toolCalls.delete(update.toolCallId);
25440
+ this.completedTools.add(update.toolCallId);
25441
+ if (this.completedTools.size > 4096)
25442
+ this.completedTools.delete(this.completedTools.values().next().value);
25443
+ if (!tool.owner || tool.owner !== this.terminalOwner)
25444
+ this.unownedContent = true;
25445
+ this.observeOutsideWork();
25446
+ this.events.emit("runtime_event", {
25447
+ kind: "tool_output",
25448
+ callId: update.toolCallId,
25449
+ name: tool.name,
25450
+ outcome: update.status === "failed" ? "failed" : "success",
25451
+ output: update.rawOutput ?? update.content,
25452
+ ...tool.owner && tool.owner === this.terminalOwner ? {} : { attribution: { scope: "session" } }
25453
+ });
25454
+ }
25349
25455
  diagnostic(severity, message) {
25350
25456
  this.events.emit("runtime_event", {
25351
25457
  kind: "runtime_diagnostic",
@@ -25354,6 +25460,58 @@ class AgyAcpLane {
25354
25460
  message
25355
25461
  });
25356
25462
  }
25463
+ hasPendingTools() {
25464
+ return this.toolCalls.size > 0;
25465
+ }
25466
+ publishActivity() {
25467
+ if (!this.ready || this.requestedStopReason || this.processTerminal)
25468
+ return;
25469
+ const status = this.hasPendingTools() ? "running" : this.nativeActivity;
25470
+ if (status === this.publishedActivity)
25471
+ return;
25472
+ this.publishedActivity = status;
25473
+ this.events.emit("runtime_event", { kind: "session_activity", observation: { status, source: "agy.native" } });
25474
+ }
25475
+ observeOutsideWork() {
25476
+ this.activityRevision += 1;
25477
+ this.nativeActivity = "unknown";
25478
+ this.publishActivity();
25479
+ }
25480
+ refreshActivity() {
25481
+ if (this.activityRead)
25482
+ return this.activityRead;
25483
+ if (!this.ready || !this.activityReader || this.requestedStopReason || this.processTerminal)
25484
+ return Promise.resolve();
25485
+ const revision = this.activityRevision;
25486
+ const reading = (async () => {
25487
+ let status = "unknown";
25488
+ try {
25489
+ status = await this.activityReader.activity();
25490
+ } catch {}
25491
+ if (!this.ready || this.requestedStopReason || this.processTerminal)
25492
+ return;
25493
+ if (revision === this.activityRevision)
25494
+ this.nativeActivity = status;
25495
+ if (status === "running" && this.currentPromptRequestId === null)
25496
+ this.unownedContent = true;
25497
+ this.publishActivity();
25498
+ })();
25499
+ this.activityRead = reading;
25500
+ reading.finally(() => {
25501
+ if (this.activityRead === reading)
25502
+ this.activityRead = undefined;
25503
+ });
25504
+ return reading;
25505
+ }
25506
+ scheduleActivity() {
25507
+ if (!this.ready || this.requestedStopReason || this.processTerminal)
25508
+ return;
25509
+ this.activityTimer = setTimeout(() => {
25510
+ this.activityTimer = undefined;
25511
+ this.refreshActivity().then(() => this.scheduleActivity());
25512
+ }, this.options.activityPollMs ?? 1000);
25513
+ this.activityTimer.unref?.();
25514
+ }
25357
25515
  protocolFailure(message) {
25358
25516
  const error = new Error(message);
25359
25517
  this.rejectAllPending(error);
@@ -35356,6 +35514,10 @@ class LogicalAgentSession {
35356
35514
  events;
35357
35515
  closed;
35358
35516
  state = "new";
35517
+ activity;
35518
+ sessionMessage = emptySemanticAssembler();
35519
+ sessionReasoning = emptySemanticAssembler();
35520
+ sessionContentTimer;
35359
35521
  backendSessionId;
35360
35522
  acquisition;
35361
35523
  configuration;
@@ -35556,11 +35718,12 @@ class LogicalAgentSession {
35556
35718
  }
35557
35719
  snapshot() {
35558
35720
  return {
35721
+ ...this.activity ? { activity: this.activity } : {},
35559
35722
  ...this.acquisition ? { acquisition: this.acquisition } : {},
35560
35723
  ...this.configuration ? { configuration: this.configuration } : {},
35561
35724
  ...this.observedModel ? { observedModel: { ...this.observedModel } } : {},
35562
35725
  sessionInstanceId: this.sessionInstanceId,
35563
- state: this.state,
35726
+ state: this.state === "idle" && this.activity && this.activity.status === "running" ? "working" : this.state,
35564
35727
  backendSessionId: this.backendSessionId,
35565
35728
  activeTurn: this.activeTurn ? { turnId: this.activeTurn.turnId, commandIds: this.activeTurn.commandIds } : undefined,
35566
35729
  queuedCommands: this.queued.map(({ message }) => ({
@@ -35886,6 +36049,13 @@ class LogicalAgentSession {
35886
36049
  return;
35887
36050
  if (this.isClosedPerTurnLaneTail(physicalOwner, generation))
35888
36051
  return;
36052
+ if (event.kind === "session_activity") {
36053
+ if (event.observation.status === "idle")
36054
+ this.flushSessionContent();
36055
+ this.activity = event.observation;
36056
+ this.emit({ type: "session_activity", observation: event.observation });
36057
+ return;
36058
+ }
35889
36059
  const observation = event.kind === "model_observed" ? modelObservation(event.observation.model, event.observation.source, event.observation.provider, event.observation.responseId) : event.kind === "configuration_observed" && event.observation.evidence === "observed" && event.observation.effective === "current" ? modelObservation(event.observation.model, "session") : undefined;
35890
36060
  if (observation)
35891
36061
  this.emit({
@@ -35896,7 +36066,19 @@ class LogicalAgentSession {
35896
36066
  });
35897
36067
  if (event.kind === "model_observed")
35898
36068
  return;
35899
- if (event.attribution?.scope === "child" || event.attribution?.scope === "unknown") {
36069
+ if (event.attribution?.scope === "session" && (event.kind === "assistant_message_delta" || event.kind === "assistant_reasoning_delta")) {
36070
+ appendSemanticFragment(event.kind === "assistant_message_delta" ? this.sessionMessage : this.sessionReasoning, event.text);
36071
+ if (event.text && !this.sessionContentTimer) {
36072
+ this.sessionContentTimer = setTimeout(() => {
36073
+ this.sessionContentTimer = undefined;
36074
+ if (this.state !== "closed" && this.state !== "stopping")
36075
+ this.flushSessionContent();
36076
+ }, 500);
36077
+ this.sessionContentTimer.unref?.();
36078
+ }
36079
+ return;
36080
+ }
36081
+ if (event.attribution?.scope === "child" || event.attribution?.scope === "unknown" || event.attribution?.scope === "session") {
35900
36082
  this.emit({
35901
36083
  type: "activity",
35902
36084
  attribution: event.attribution,
@@ -35904,6 +36086,7 @@ class LogicalAgentSession {
35904
36086
  ..."text" in event ? { text: boundedSemanticCompletion(event.text).text } : {},
35905
36087
  ..."callId" in event ? { callId: event.callId } : {},
35906
36088
  ..."name" in event ? { name: event.name } : {},
36089
+ ..."input" in event ? { input: jsonValue(event.input) } : {},
35907
36090
  ..."outcome" in event ? { outcome: event.outcome } : {},
35908
36091
  ..."output" in event ? { output: jsonValue(event.output) } : {}
35909
36092
  });
@@ -36114,10 +36297,23 @@ class LogicalAgentSession {
36114
36297
  this.emit({ type: "assistant_message_completed", turnId, ...message });
36115
36298
  }
36116
36299
  }
36300
+ this.flushSessionContent();
36117
36301
  this.completeTurn(event.sessionId, physicalOwner, generation, event.turnOwner);
36118
36302
  return;
36119
36303
  }
36120
36304
  }
36305
+ flushSessionContent() {
36306
+ if (this.sessionContentTimer)
36307
+ clearTimeout(this.sessionContentTimer);
36308
+ this.sessionContentTimer = undefined;
36309
+ for (const [kind, buffer] of [["assistant_reasoning_completed", this.sessionReasoning], ["assistant_message_completed", this.sessionMessage]]) {
36310
+ const completion = finishSemanticAssembler(buffer);
36311
+ if (completion.text)
36312
+ this.emit({ type: "activity", attribution: { scope: "session" }, kind, ...completion });
36313
+ }
36314
+ this.sessionMessage = emptySemanticAssembler();
36315
+ this.sessionReasoning = emptySemanticAssembler();
36316
+ }
36121
36317
  isClosedPerTurnLaneTail(physicalOwner, generation) {
36122
36318
  if (this.adapter.execution.lifetime !== "turn" || this.activeTurn)
36123
36319
  return false;
@@ -36645,6 +36841,7 @@ class LogicalAgentSession {
36645
36841
  const cleanup = hostCleanup.status === "failed" || hostCleanup.status === "timed_out" ? hostCleanup : this.laneCleanupFailure ?? hostCleanup;
36646
36842
  const result = buildResult(cleanup);
36647
36843
  this.terminalResult = result;
36844
+ this.flushSessionContent();
36648
36845
  this.state = "closed";
36649
36846
  this.emit({ type: "session_closed", result });
36650
36847
  this.eventQueue.close();
@@ -38508,7 +38705,10 @@ function compactTraceData(data) {
38508
38705
  }
38509
38706
  // src/manager/managerPolicy.ts
38510
38707
  function isActivelyWorking(agent) {
38511
- return agent.status === "running" && (leaseIsWorking(agent.execution.lease) || agent.pendingAdmissions.length > 0 || agent.inbox.length > 0);
38708
+ return agent.status === "running" && (agent.sessionActivity?.status === "running" || leaseIsWorking(agent.execution.lease) || agent.pendingAdmissions.length > 0 || agent.inbox.length > 0);
38709
+ }
38710
+ function sessionBlocksIdleCleanup(agent) {
38711
+ return agent.sessionActivity !== undefined && agent.sessionActivity.status !== "idle";
38512
38712
  }
38513
38713
  var DEFAULT_STALE_THRESHOLD_MS = 120000;
38514
38714
  var DEFAULT_TURN_SILENCE_POLICY = {
@@ -38534,6 +38734,19 @@ function createInitialManagerState(staleThresholdMs = DEFAULT_STALE_THRESHOLD_MS
38534
38734
  }
38535
38735
  function reduceManager(state, event) {
38536
38736
  switch (event.type) {
38737
+ case "session_activity": {
38738
+ const current = state.agents[event.agentId];
38739
+ if (!current || !matchesSession(current, event.sessionInstanceId) || current.status === "stopping")
38740
+ return { state, effects: [] };
38741
+ const agent = clone(current);
38742
+ const changed = agent.sessionActivity?.status !== event.observation.status;
38743
+ agent.sessionActivity = event.observation;
38744
+ if (sessionBlocksIdleCleanup(agent))
38745
+ agent.idleSince = null;
38746
+ else if (changed && !leaseIsWorking(agent.execution.lease) && agent.pendingAdmissions.length === 0 && agent.inbox.length === 0)
38747
+ agent.idleSince = event.nowMs;
38748
+ return commit(state, agent, []);
38749
+ }
38537
38750
  case "register":
38538
38751
  return withAgent(state, event.agentId, (a) => a ?? freshAgent(event.agentId), []);
38539
38752
  case "wake":
@@ -38583,6 +38796,7 @@ function reduceManager(state, event) {
38583
38796
  {
38584
38797
  const a = agent;
38585
38798
  a.execution = { sessionInstanceId: event.sessionInstanceId, lease: { state: "none", lastTerminal: null } };
38799
+ a.sessionActivity = undefined;
38586
38800
  a.turnSilence = event.turnSilence ?? {
38587
38801
  ...DEFAULT_TURN_SILENCE_POLICY,
38588
38802
  nativeIdleTimeoutMs: state.staleThresholdMs,
@@ -38784,6 +38998,7 @@ function reduceManager(state, event) {
38784
38998
  const closing = agent.pendingAdmissions.filter((entry) => entry.sessionInstanceId === event.sessionInstanceId);
38785
38999
  agent.pendingAdmissions = agent.pendingAdmissions.filter((entry) => entry.sessionInstanceId !== event.sessionInstanceId);
38786
39000
  agent.execution = { sessionInstanceId: null, lease: { state: "detached" } };
39001
+ agent.sessionActivity = undefined;
38787
39002
  syncExecutionProjection(agent);
38788
39003
  return commit(state, agent, recoveryEffects(agent, closing));
38789
39004
  }
@@ -38912,7 +39127,7 @@ function onTurnCompleted(state, agentId, sessionInstanceId, nowMs, turnId, endRe
38912
39127
  ...messages.map((queued) => ({ type: "send", agentId, message: queued, mode: "idle" }))
38913
39128
  ]);
38914
39129
  }
38915
- agent.idleSince = agent.status === "running" && !agent.resetting ? nowMs : null;
39130
+ agent.idleSince = agent.status === "running" && !agent.resetting && !sessionBlocksIdleCleanup(agent) ? nowMs : null;
38916
39131
  return commit(state, agent, clearEffects);
38917
39132
  }
38918
39133
  function onTurnToolLifecycle(state, event, lifecycle) {
@@ -39062,13 +39277,13 @@ function onTick(state, nowMs) {
39062
39277
  effects.push({ type: "force_exit", agentId: id2, reason: "stopping_stuck" });
39063
39278
  continue;
39064
39279
  }
39065
- const idleResetEligible = a.idleSince !== null && a.sessionId !== null && a.inbox.length === 0 && a.pendingAdmissions.length === 0 && !a.resetting && state.idleResetTimeoutMs > 0 && Number.isFinite(state.idleResetTimeoutMs) && (a.status === "idle" && lease.state === "detached" || a.status === "running" && lease.state === "none" && lease.lastTerminal !== null);
39280
+ const idleResetEligible = !sessionBlocksIdleCleanup(a) && a.idleSince !== null && a.sessionId !== null && a.inbox.length === 0 && a.pendingAdmissions.length === 0 && !a.resetting && state.idleResetTimeoutMs > 0 && Number.isFinite(state.idleResetTimeoutMs) && (a.status === "idle" && lease.state === "detached" || a.status === "running" && lease.state === "none" && lease.lastTerminal !== null);
39066
39281
  if (idleResetEligible && nowMs - a.idleSince >= state.idleResetTimeoutMs) {
39067
39282
  agents[id2] = { ...a, idleSince: nowMs };
39068
39283
  effects.push({ type: "maintain_idle_memory", agentId: id2, sessionId: a.sessionId });
39069
39284
  continue;
39070
39285
  }
39071
- const idleEligible = a.status === "running" && lease.state === "none" && a.pendingAdmissions.length === 0 && lease.lastTerminal !== null && a.inbox.length === 0 && state.idleTimeoutMs > 0 && Number.isFinite(state.idleTimeoutMs);
39286
+ const idleEligible = !sessionBlocksIdleCleanup(a) && a.status === "running" && lease.state === "none" && a.pendingAdmissions.length === 0 && lease.lastTerminal !== null && a.inbox.length === 0 && state.idleTimeoutMs > 0 && Number.isFinite(state.idleTimeoutMs);
39072
39287
  if (idleEligible && a.idleSince !== null && nowMs - a.idleSince >= state.idleTimeoutMs) {
39073
39288
  agents[id2] = { ...a, status: "stopping", stoppingSince: nowMs };
39074
39289
  effects.push({ type: "stop", agentId: id2, reason: "idle_timeout" });
@@ -39102,6 +39317,8 @@ function freshAgent(agentId) {
39102
39317
  }
39103
39318
  function enterStable(agent, status) {
39104
39319
  agent.status = status;
39320
+ if (status === "idle")
39321
+ agent.sessionActivity = undefined;
39105
39322
  agent.resetting = false;
39106
39323
  agent.resettingSince = null;
39107
39324
  agent.stoppingSince = null;
@@ -59094,7 +59311,7 @@ var AgentModelReportSchema = exports_external.object({
59094
59311
  provider: identity2.optional(),
59095
59312
  source: exports_external.enum(["response", "session"]),
59096
59313
  responseId: identity2.optional(),
59097
- observedAt: exports_external.string().datetime({ offset: true })
59314
+ observedAt: exports_external.iso.datetime({ offset: true })
59098
59315
  });
59099
59316
 
59100
59317
  // ../shared/src/community-decision-card.ts
@@ -59208,7 +59425,8 @@ var DecisionCardEmbedSchema = exports_external.strictObject({
59208
59425
  summary: exports_external.string().trim().min(1).max(DECISION_CARD_SUMMARY_MAX_LENGTH).optional(),
59209
59426
  assignees: exports_external.array(DecisionCardAssigneeSchema).max(DECISION_CARD_MAX_MENTIONS),
59210
59427
  questions: exports_external.array(DecisionCardNormalizedQuestionSchema).min(DECISION_CARD_MIN_QUESTIONS).max(DECISION_CARD_MAX_QUESTIONS),
59211
- respondedUserIds: exports_external.array(exports_external.string().min(1)).optional()
59428
+ respondedUserIds: exports_external.array(exports_external.string().min(1)).optional(),
59429
+ viewerDismissed: exports_external.boolean().optional()
59212
59430
  });
59213
59431
  var DecisionCardAnswerItemSchema = exports_external.strictObject({
59214
59432
  questionId: idFieldSchema,
@@ -59295,8 +59513,8 @@ var QuotaLimitSchema = exports_external.object({
59295
59513
  model: QuotaModelIdentitySchema,
59296
59514
  window: QuotaWindowIdentitySchema
59297
59515
  }).strict(),
59298
- usedPercent: exports_external.number().finite().min(0).max(100),
59299
- resetsAt: exports_external.string().datetime({ offset: true }).optional()
59516
+ usedPercent: exports_external.number().min(0).max(100),
59517
+ resetsAt: exports_external.iso.datetime({ offset: true }).optional()
59300
59518
  }).strict();
59301
59519
  function quotaIdentity(limit) {
59302
59520
  const { product, model, window: window2, limitId } = limit.bucket;
@@ -59819,7 +60037,7 @@ var BotAuditEventKindSchema = exports_external.enum([
59819
60037
  var HostBotAuditEventFrameSchema = exports_external.object({
59820
60038
  type: exports_external.literal("bot_audit_event"),
59821
60039
  eventId: exports_external.string().min(1).max(128).optional(),
59822
- occurredAt: exports_external.string().datetime({ offset: true }).optional(),
60040
+ occurredAt: exports_external.iso.datetime({ offset: true }).optional(),
59823
60041
  agentId: exports_external.string().min(1),
59824
60042
  sessionId: exports_external.string().nullable().optional(),
59825
60043
  launchId: exports_external.string().nullable().optional(),
@@ -60390,7 +60608,7 @@ var AccountAttentionSnapshotSchema = AccountAttentionProjectionSchema.extend({
60390
60608
  var EntitlementValueSchema = exports_external.lazy(() => exports_external.union([
60391
60609
  exports_external.null(),
60392
60610
  exports_external.boolean(),
60393
- exports_external.number().finite(),
60611
+ exports_external.number(),
60394
60612
  exports_external.string(),
60395
60613
  exports_external.array(EntitlementValueSchema),
60396
60614
  exports_external.record(exports_external.string(), EntitlementValueSchema)
@@ -60417,11 +60635,11 @@ var BillingOfferSchema = exports_external.object({
60417
60635
  var BillingSubscriptionSchema = exports_external.object({
60418
60636
  plan: BillingPlanSchema,
60419
60637
  status: exports_external.string().min(1),
60420
- currentPeriodEnd: exports_external.string().datetime().nullable(),
60421
- cancelAt: exports_external.string().datetime().nullable(),
60638
+ currentPeriodEnd: exports_external.iso.datetime().nullable(),
60639
+ cancelAt: exports_external.iso.datetime().nullable(),
60422
60640
  scheduledChange: exports_external.object({
60423
60641
  plan: BillingPlanSchema,
60424
- effectiveAt: exports_external.string().datetime()
60642
+ effectiveAt: exports_external.iso.datetime()
60425
60643
  }).nullable()
60426
60644
  });
60427
60645
  var PublicPricingSchema = exports_external.object({
@@ -60446,7 +60664,7 @@ var BillingPortalRequestSchema = exports_external.strictObject({
60446
60664
  priceId: exports_external.string().min(1).max(255).optional()
60447
60665
  });
60448
60666
  var BillingRedirectResponseSchema = exports_external.object({
60449
- url: exports_external.string().url()
60667
+ url: exports_external.url()
60450
60668
  });
60451
60669
  // ../shared/src/utils/day-key.ts
60452
60670
  function utcDayKey(now) {
@@ -60484,7 +60702,7 @@ function dayKeyInTimeZone(now, timeZone) {
60484
60702
  return `${year}-${month}-${day}`;
60485
60703
  }
60486
60704
 
60487
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/entity.js
60705
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/entity.js
60488
60706
  var entityKind = Symbol.for("drizzle:entityKind");
60489
60707
  var hasOwnEntityKind = Symbol.for("drizzle:hasOwnEntityKind");
60490
60708
  function is(value, type) {
@@ -60509,7 +60727,7 @@ function is(value, type) {
60509
60727
  return false;
60510
60728
  }
60511
60729
 
60512
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/column.js
60730
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/column.js
60513
60731
  class Column {
60514
60732
  constructor(table, config2) {
60515
60733
  this.table = table;
@@ -60559,7 +60777,7 @@ class Column {
60559
60777
  }
60560
60778
  }
60561
60779
 
60562
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/column-builder.js
60780
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/column-builder.js
60563
60781
  class ColumnBuilder {
60564
60782
  static [entityKind] = "ColumnBuilder";
60565
60783
  config;
@@ -60615,20 +60833,20 @@ class ColumnBuilder {
60615
60833
  }
60616
60834
  }
60617
60835
 
60618
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/table.utils.js
60836
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/table.utils.js
60619
60837
  var TableName = Symbol.for("drizzle:Name");
60620
60838
 
60621
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/tracing-utils.js
60839
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/tracing-utils.js
60622
60840
  function iife(fn, ...args) {
60623
60841
  return fn(...args);
60624
60842
  }
60625
60843
 
60626
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/pg-core/unique-constraint.js
60844
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/pg-core/unique-constraint.js
60627
60845
  function uniqueKeyName(table, columns) {
60628
60846
  return `${table[TableName]}_${columns.join("_")}_unique`;
60629
60847
  }
60630
60848
 
60631
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/pg-core/columns/common.js
60849
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/pg-core/columns/common.js
60632
60850
  class PgColumn extends Column {
60633
60851
  constructor(table, config2) {
60634
60852
  if (!config2.uniqueName) {
@@ -60677,7 +60895,7 @@ class ExtraConfigColumn extends PgColumn {
60677
60895
  }
60678
60896
  }
60679
60897
 
60680
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/pg-core/columns/enum.js
60898
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/pg-core/columns/enum.js
60681
60899
  class PgEnumObjectColumn extends PgColumn {
60682
60900
  static [entityKind] = "PgEnumObjectColumn";
60683
60901
  enum;
@@ -60707,7 +60925,7 @@ class PgEnumColumn extends PgColumn {
60707
60925
  }
60708
60926
  }
60709
60927
 
60710
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/subquery.js
60928
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/subquery.js
60711
60929
  class Subquery {
60712
60930
  static [entityKind] = "Subquery";
60713
60931
  constructor(sql, fields2, alias, isWith = false, usedTables = []) {
@@ -60722,10 +60940,10 @@ class Subquery {
60722
60940
  }
60723
60941
  }
60724
60942
 
60725
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/version.js
60943
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/version.js
60726
60944
  var version2 = "0.45.4";
60727
60945
 
60728
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/tracing.js
60946
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/tracing.js
60729
60947
  var otel;
60730
60948
  var rawTracer;
60731
60949
  var tracer = {
@@ -60752,10 +60970,10 @@ var tracer = {
60752
60970
  }
60753
60971
  };
60754
60972
 
60755
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/view-common.js
60973
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/view-common.js
60756
60974
  var ViewBaseConfig = Symbol.for("drizzle:ViewBaseConfig");
60757
60975
 
60758
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/table.js
60976
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/table.js
60759
60977
  var Schema = Symbol.for("drizzle:Schema");
60760
60978
  var Columns = Symbol.for("drizzle:Columns");
60761
60979
  var ExtraConfigColumns = Symbol.for("drizzle:ExtraConfigColumns");
@@ -60793,7 +61011,7 @@ class Table {
60793
61011
  }
60794
61012
  }
60795
61013
 
60796
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/sql/sql.js
61014
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/sql/sql.js
60797
61015
  function isSQLWrapper(value) {
60798
61016
  return value !== null && value !== undefined && typeof value.getSQL === "function";
60799
61017
  }
@@ -61156,7 +61374,7 @@ Subquery.prototype.getSQL = function() {
61156
61374
  return new SQL([this]);
61157
61375
  };
61158
61376
 
61159
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/alias.js
61377
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/alias.js
61160
61378
  class ColumnAliasProxyHandler {
61161
61379
  constructor(table) {
61162
61380
  this.table = table;
@@ -61212,7 +61430,7 @@ class TableAliasProxyHandler {
61212
61430
  }
61213
61431
  }
61214
61432
 
61215
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/utils.js
61433
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/utils.js
61216
61434
  function getColumnNameAndConfig(a, b) {
61217
61435
  return {
61218
61436
  name: typeof a === "string" && a.length > 0 ? a : "",
@@ -61221,7 +61439,7 @@ function getColumnNameAndConfig(a, b) {
61221
61439
  }
61222
61440
  var textDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder;
61223
61441
 
61224
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/sql/expressions/conditions.js
61442
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/sql/expressions/conditions.js
61225
61443
  function bindIfParam(value, column) {
61226
61444
  if (isDriverValueEncoder(column) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column) && !is(value, Table) && !is(value, View)) {
61227
61445
  return new Param(value, column);
@@ -61252,7 +61470,7 @@ function isNotNull(value) {
61252
61470
  return sql`${value} is not null`;
61253
61471
  }
61254
61472
 
61255
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/sql/expressions/select.js
61473
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/sql/expressions/select.js
61256
61474
  function desc(column) {
61257
61475
  return sql`${column} desc`;
61258
61476
  }
@@ -61291,12 +61509,12 @@ __export(exports_community_schema, {
61291
61509
  communityAttachment: () => communityAttachment
61292
61510
  });
61293
61511
 
61294
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/sqlite-core/alias.js
61512
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/sqlite-core/alias.js
61295
61513
  function alias(table, alias2) {
61296
61514
  return new Proxy(table, new TableAliasProxyHandler(alias2, false));
61297
61515
  }
61298
61516
 
61299
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/sqlite-core/checks.js
61517
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/sqlite-core/checks.js
61300
61518
  class CheckBuilder {
61301
61519
  constructor(name, value) {
61302
61520
  this.name = name;
@@ -61323,7 +61541,7 @@ function check2(name, value) {
61323
61541
  return new CheckBuilder(name, value);
61324
61542
  }
61325
61543
 
61326
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/sqlite-core/foreign-keys.js
61544
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/sqlite-core/foreign-keys.js
61327
61545
  class ForeignKeyBuilder {
61328
61546
  static [entityKind] = "SQLiteForeignKeyBuilder";
61329
61547
  reference;
@@ -61377,7 +61595,7 @@ class ForeignKey {
61377
61595
  }
61378
61596
  }
61379
61597
 
61380
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/sqlite-core/unique-constraint.js
61598
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/sqlite-core/unique-constraint.js
61381
61599
  function uniqueKeyName2(table, columns) {
61382
61600
  return `${table[TableName]}_${columns.join("_")}_unique`;
61383
61601
  }
@@ -61422,7 +61640,7 @@ class UniqueConstraint {
61422
61640
  }
61423
61641
  }
61424
61642
 
61425
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/sqlite-core/columns/common.js
61643
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/sqlite-core/columns/common.js
61426
61644
  class SQLiteColumnBuilder extends ColumnBuilder {
61427
61645
  static [entityKind] = "SQLiteColumnBuilder";
61428
61646
  foreignKeyConfigs = [];
@@ -61473,7 +61691,7 @@ class SQLiteColumn extends Column {
61473
61691
  static [entityKind] = "SQLiteColumn";
61474
61692
  }
61475
61693
 
61476
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/sqlite-core/columns/blob.js
61694
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/sqlite-core/columns/blob.js
61477
61695
  class SQLiteBigIntBuilder extends SQLiteColumnBuilder {
61478
61696
  static [entityKind] = "SQLiteBigIntBuilder";
61479
61697
  constructor(name) {
@@ -61561,7 +61779,7 @@ function blob(a, b) {
61561
61779
  return new SQLiteBlobBufferBuilder(name);
61562
61780
  }
61563
61781
 
61564
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/sqlite-core/columns/custom.js
61782
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/sqlite-core/columns/custom.js
61565
61783
  class SQLiteCustomColumnBuilder extends SQLiteColumnBuilder {
61566
61784
  static [entityKind] = "SQLiteCustomColumnBuilder";
61567
61785
  constructor(name, fieldConfig, customTypeParams) {
@@ -61602,7 +61820,7 @@ function customType(customTypeParams) {
61602
61820
  };
61603
61821
  }
61604
61822
 
61605
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/sqlite-core/columns/integer.js
61823
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/sqlite-core/columns/integer.js
61606
61824
  class SQLiteBaseIntegerBuilder extends SQLiteColumnBuilder {
61607
61825
  static [entityKind] = "SQLiteBaseIntegerBuilder";
61608
61826
  constructor(name, dataType, columnType) {
@@ -61704,7 +61922,7 @@ function integer2(a, b) {
61704
61922
  return new SQLiteIntegerBuilder(name);
61705
61923
  }
61706
61924
 
61707
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/sqlite-core/columns/numeric.js
61925
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/sqlite-core/columns/numeric.js
61708
61926
  class SQLiteNumericBuilder extends SQLiteColumnBuilder {
61709
61927
  static [entityKind] = "SQLiteNumericBuilder";
61710
61928
  constructor(name) {
@@ -61774,7 +61992,7 @@ function numeric(a, b) {
61774
61992
  return mode === "number" ? new SQLiteNumericNumberBuilder(name) : mode === "bigint" ? new SQLiteNumericBigIntBuilder(name) : new SQLiteNumericBuilder(name);
61775
61993
  }
61776
61994
 
61777
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/sqlite-core/columns/real.js
61995
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/sqlite-core/columns/real.js
61778
61996
  class SQLiteRealBuilder extends SQLiteColumnBuilder {
61779
61997
  static [entityKind] = "SQLiteRealBuilder";
61780
61998
  constructor(name) {
@@ -61795,7 +62013,7 @@ function real(name) {
61795
62013
  return new SQLiteRealBuilder(name ?? "");
61796
62014
  }
61797
62015
 
61798
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/sqlite-core/columns/text.js
62016
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/sqlite-core/columns/text.js
61799
62017
  class SQLiteTextBuilder extends SQLiteColumnBuilder {
61800
62018
  static [entityKind] = "SQLiteTextBuilder";
61801
62019
  constructor(name, config2) {
@@ -61850,7 +62068,7 @@ function text2(a, b = {}) {
61850
62068
  return new SQLiteTextBuilder(name, config2);
61851
62069
  }
61852
62070
 
61853
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/sqlite-core/columns/all.js
62071
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/sqlite-core/columns/all.js
61854
62072
  function getSQLiteColumnBuilders() {
61855
62073
  return {
61856
62074
  blob,
@@ -61862,7 +62080,7 @@ function getSQLiteColumnBuilders() {
61862
62080
  };
61863
62081
  }
61864
62082
 
61865
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/sqlite-core/table.js
62083
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/sqlite-core/table.js
61866
62084
  var InlineForeignKeys = Symbol.for("drizzle:SQLiteInlineForeignKeys");
61867
62085
 
61868
62086
  class SQLiteTable extends Table {
@@ -61896,7 +62114,7 @@ var sqliteTable = (name, columns, extraConfig) => {
61896
62114
  return sqliteTableBase(name, columns, extraConfig);
61897
62115
  };
61898
62116
 
61899
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/sqlite-core/indexes.js
62117
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/sqlite-core/indexes.js
61900
62118
  class IndexBuilderOn {
61901
62119
  constructor(name, unique2) {
61902
62120
  this.name = name;
@@ -61942,7 +62160,7 @@ function uniqueIndex(name) {
61942
62160
  return new IndexBuilderOn(name, true);
61943
62161
  }
61944
62162
 
61945
- // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261114.1_@opentelemetry+api@1.10.0_@ty_3390f7c80ab771c33a3e98a1c71b9106/node_modules/drizzle-orm/sqlite-core/primary-keys.js
62163
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261119.1_@opentelemetry+api@1.10.0_@ty_38fec08cb14afcae8326bba90a769ca2/node_modules/drizzle-orm/sqlite-core/primary-keys.js
61946
62164
  function primaryKey(...config2) {
61947
62165
  if (config2[0].columns) {
61948
62166
  return new PrimaryKeyBuilder(config2[0].columns, config2[0].name);
@@ -62630,19 +62848,18 @@ class Logger {
62630
62848
  entry[k] = { message: v.message, stack: v.stack };
62631
62849
  }
62632
62850
  }
62633
- let line;
62634
- if (this.pretty) {
62851
+ const output2 = this.pretty ? (() => {
62635
62852
  const ts = entry.ts.replace("T", " ").replace("Z", "");
62636
62853
  const lvl = entry.level.toUpperCase().padEnd(5);
62637
62854
  const pairs = Object.entries(entry).filter(([k]) => k !== "level" && k !== "msg" && k !== "service" && k !== "ts").map(([k, v]) => `${k}=${typeof v === "object" ? JSON.stringify(v) : v}`).join(" ");
62638
- line = `${ts} ${lvl} [${entry.service}] ${entry.msg}${pairs ? " " + pairs : ""}`;
62639
- } else {
62640
- line = JSON.stringify(entry);
62641
- }
62855
+ return `${ts} ${lvl} [${entry.service}] ${entry.msg}${pairs ? " " + pairs : ""}`;
62856
+ })() : entry;
62642
62857
  if (level === "error") {
62643
- console.error(line);
62858
+ console.error(output2);
62859
+ } else if (level === "warn") {
62860
+ console.warn(output2);
62644
62861
  } else {
62645
- console.log(line);
62862
+ console.log(output2);
62646
62863
  }
62647
62864
  }
62648
62865
  }
@@ -71753,7 +71970,7 @@ function toResult(value) {
71753
71970
  }
71754
71971
  return value === null || value === undefined ? empty : [value];
71755
71972
  }
71756
- // ../../node_modules/.pnpm/mdast-util-find-and-replace@3.0.4/node_modules/mdast-util-find-and-replace/lib/index.js
71973
+ // ../../node_modules/.pnpm/mdast-util-find-and-replace@3.0.5/node_modules/mdast-util-find-and-replace/lib/index.js
71757
71974
  function findAndReplace(tree, list2, options) {
71758
71975
  const settings = options || {};
71759
71976
  const ignored = convert(settings.ignore || []);
@@ -71789,9 +72006,7 @@ function findAndReplace(tree, list2, options) {
71789
72006
  if (typeof value === "string") {
71790
72007
  value = value.length > 0 ? { type: "text", value } : undefined;
71791
72008
  }
71792
- if (value === false) {
71793
- find.lastIndex = position2 + 1;
71794
- } else {
72009
+ if (value !== false) {
71795
72010
  if (start !== position2) {
71796
72011
  add({ type: "text", value: node3.value.slice(start, position2) });
71797
72012
  }
@@ -71804,6 +72019,10 @@ function findAndReplace(tree, list2, options) {
71804
72019
  start = position2 + match[0].length;
71805
72020
  change = true;
71806
72021
  }
72022
+ if (value === false || match[0].length === 0) {
72023
+ const code = node3.value.codePointAt(position2) || 0;
72024
+ find.lastIndex = position2 + (/[uv]/.test(find.flags) && code > 65535 ? 2 : 1);
72025
+ }
71807
72026
  if (!find.global) {
71808
72027
  break;
71809
72028
  }
@@ -71849,7 +72068,7 @@ function toFunction(replace) {
71849
72068
  return replace;
71850
72069
  };
71851
72070
  }
71852
- // ../../node_modules/.pnpm/mdast-util-gfm-autolink-literal@2.0.1/node_modules/mdast-util-gfm-autolink-literal/lib/index.js
72071
+ // ../../node_modules/.pnpm/mdast-util-gfm-autolink-literal@2.1.0/node_modules/mdast-util-gfm-autolink-literal/lib/index.js
71853
72072
  var inConstruct = "phrasing";
71854
72073
  var notInConstruct = ["autolink", "link", "image", "label"];
71855
72074
  function gfmAutolinkLiteralFromMarkdown() {
@@ -71897,7 +72116,7 @@ function gfmAutolinkLiteralToMarkdown() {
71897
72116
  };
71898
72117
  }
71899
72118
  function enterLiteralAutolink(token) {
71900
- this.enter({ type: "link", title: null, url: "", children: [] }, token);
72119
+ this.enter({ type: "link", title: null, url: "", children: [], position: undefined }, token);
71901
72120
  }
71902
72121
  function enterLiteralAutolinkValue(token) {
71903
72122
  this.config.enter.autolinkProtocol.call(this, token);
@@ -71919,62 +72138,107 @@ function exitLiteralAutolink(token) {
71919
72138
  }
71920
72139
  function transformGfmAutolinkLiterals(tree) {
71921
72140
  findAndReplace(tree, [
71922
- [/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi, findUrl],
71923
- [/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu, findEmail]
72141
+ [
72142
+ /(?<![\da-z])(https?:\/\/|www(?=\.))([\w-]*\.[\w\-.]*)([^\t\n\r ]*)/gi,
72143
+ findUrl
72144
+ ],
72145
+ [
72146
+ /(?<![\w+\-.@])xmpp:([\w+\-.]+)@([\w-]+(?:\.[\w-]+)+)(\/(?:[\w\-/]|\.(?=[\dA-Za-z]))*)?/g,
72147
+ findXmpp
72148
+ ],
72149
+ [/(?<![\w+\-.@])mailto:([\w+\-.]+)@([\w-]+(?:\.[\w-]+)+)/g, findMailto],
72150
+ [
72151
+ /(?<![\w+\-.]|(?:^|[^\d@A-Za-z])(?:mailto|xmpp):)([\w+\-.]+)@([\w-]+(?:\.[\w-]+)+)/g,
72152
+ findEmail
72153
+ ]
71924
72154
  ], { ignore: ["link", "linkReference"] });
71925
72155
  }
71926
72156
  function findUrl(_, protocol, domain2, path13, match) {
71927
- let prefix = "";
71928
72157
  if (!previous2(match)) {
71929
72158
  return false;
71930
72159
  }
72160
+ let prefix = "";
71931
72161
  if (/^w/i.test(protocol)) {
71932
72162
  domain2 = protocol + domain2;
71933
72163
  protocol = "";
71934
72164
  prefix = "http://";
71935
72165
  }
71936
- if (!isCorrectDomain(domain2)) {
72166
+ if (unicodePunctuation(domain2.charCodeAt(0)) || !isCorrectDomain(domain2)) {
71937
72167
  return false;
71938
72168
  }
71939
72169
  const parts = splitUrl(domain2 + path13);
71940
- if (!parts[0])
71941
- return false;
71942
72170
  const result = {
71943
72171
  type: "link",
71944
72172
  title: null,
71945
72173
  url: prefix + protocol + parts[0],
71946
- children: [{ type: "text", value: protocol + parts[0] }]
72174
+ children: [{ type: "text", value: protocol + parts[0], position: undefined }],
72175
+ position: undefined
71947
72176
  };
71948
72177
  if (parts[1]) {
71949
- return [result, { type: "text", value: parts[1] }];
72178
+ return [result, { type: "text", value: parts[1], position: undefined }];
71950
72179
  }
71951
72180
  return result;
71952
72181
  }
71953
- function findEmail(_, atext, label2, match) {
71954
- if (!previous2(match, true) || /[-\d_]$/.test(label2)) {
72182
+ function findEmail(_, atext, label2) {
72183
+ if (/[\d\-_]$/.test(label2)) {
71955
72184
  return false;
71956
72185
  }
71957
72186
  return {
71958
72187
  type: "link",
71959
72188
  title: null,
71960
72189
  url: "mailto:" + atext + "@" + label2,
71961
- children: [{ type: "text", value: atext + "@" + label2 }]
72190
+ children: [{ type: "text", value: atext + "@" + label2, position: undefined }],
72191
+ position: undefined
72192
+ };
72193
+ }
72194
+ function findMailto(_, atext, label2) {
72195
+ if (/[\d\-_]$/.test(label2)) {
72196
+ return false;
72197
+ }
72198
+ const value = "mailto:" + atext + "@" + label2;
72199
+ return {
72200
+ type: "link",
72201
+ title: null,
72202
+ url: value,
72203
+ children: [{ type: "text", value, position: undefined }],
72204
+ position: undefined
72205
+ };
72206
+ }
72207
+ function findXmpp(matchValue, atext, label2, resource, match) {
72208
+ if (/[\d\-_]$/.test(label2) || resource && (!/[A-Za-z]$/.test(resource) || match.input.charAt(match.index + matchValue.length) === "@")) {
72209
+ return false;
72210
+ }
72211
+ const value = "xmpp:" + atext + "@" + label2 + (resource || "");
72212
+ return {
72213
+ type: "link",
72214
+ title: null,
72215
+ url: value,
72216
+ children: [{ type: "text", value, position: undefined }],
72217
+ position: undefined
71962
72218
  };
71963
72219
  }
71964
72220
  function isCorrectDomain(domain2) {
71965
72221
  const parts = domain2.split(".");
71966
- if (parts.length < 2 || parts[parts.length - 1] && (/_/.test(parts[parts.length - 1]) || !/[a-zA-Z\d]/.test(parts[parts.length - 1])) || parts[parts.length - 2] && (/_/.test(parts[parts.length - 2]) || !/[a-zA-Z\d]/.test(parts[parts.length - 2]))) {
72222
+ if (parts.length < 2 || parts[parts.length - 1] && (/_/.test(parts[parts.length - 1]) || !/[\dA-Za-z]/.test(parts[parts.length - 1])) || parts[parts.length - 2] && (/_/.test(parts[parts.length - 2]) || !/[\dA-Za-z]/.test(parts[parts.length - 2]))) {
71967
72223
  return false;
71968
72224
  }
71969
72225
  return true;
71970
72226
  }
71971
72227
  function splitUrl(url2) {
71972
- const trailExec = /[!"&'),.:;<>?\]}]+$/.exec(url2);
71973
- if (!trailExec) {
72228
+ let index3 = url2.length;
72229
+ while (index3 > 0) {
72230
+ const code = url2.charCodeAt(index3 - 1);
72231
+ if (code === 33 || code === 34 || code === 38 || code === 39 || code === 41 || code === 44 || code === 46 || code === 58 || code === 59 || code === 60 || code === 62 || code === 63 || code === 93 || code === 125) {
72232
+ index3--;
72233
+ } else {
72234
+ break;
72235
+ }
72236
+ }
72237
+ if (index3 === url2.length) {
71974
72238
  return [url2, undefined];
71975
72239
  }
71976
- url2 = url2.slice(0, trailExec.index);
71977
- let trail = trailExec[0];
72240
+ let trail = url2.slice(index3);
72241
+ url2 = url2.slice(0, index3);
71978
72242
  let closingParenIndex = trail.indexOf(")");
71979
72243
  const openingParens = ccount(url2, "(");
71980
72244
  let closingParens = ccount(url2, ")");
@@ -71986,9 +72250,9 @@ function splitUrl(url2) {
71986
72250
  }
71987
72251
  return [url2, trail];
71988
72252
  }
71989
- function previous2(match, email3) {
72253
+ function previous2(match) {
71990
72254
  const code = match.input.charCodeAt(match.index - 1);
71991
- return (match.index === 0 || unicodeWhitespace(code) || unicodePunctuation(code)) && (!email3 || code !== 47);
72255
+ return match.index === 0 || unicodeWhitespace(code) || unicodePunctuation(code);
71992
72256
  }
71993
72257
  // ../../node_modules/.pnpm/mdast-util-gfm-footnote@2.1.0/node_modules/mdast-util-gfm-footnote/lib/index.js
71994
72258
  footnoteReference.peek = footnoteReferencePeek;
@@ -72521,25 +72785,37 @@ function emphasisPeek(_, _1, state) {
72521
72785
  return state.options.emphasis || "*";
72522
72786
  }
72523
72787
 
72524
- // ../../node_modules/.pnpm/unist-util-visit@5.1.0/node_modules/unist-util-visit/lib/index.js
72525
- function visit2(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
72788
+ // ../../node_modules/.pnpm/unist-util-visit@5.2.0/node_modules/unist-util-visit/lib/index.js
72789
+ function visit2(tree, testOrEnterOrVisitors, enterOrVisitorsOrReverse, maybeReverse) {
72790
+ let check3;
72791
+ let visitors;
72526
72792
  let reverse;
72527
- let test;
72528
- let visitor;
72529
- if (typeof testOrVisitor === "function" && typeof visitorOrReverse !== "function") {
72530
- test = undefined;
72531
- visitor = testOrVisitor;
72532
- reverse = visitorOrReverse;
72533
- } else {
72534
- test = testOrVisitor;
72535
- visitor = visitorOrReverse;
72793
+ if (typeof enterOrVisitorsOrReverse === "function" || enterOrVisitorsOrReverse && typeof enterOrVisitorsOrReverse === "object") {
72794
+ check3 = testOrEnterOrVisitors;
72795
+ visitors = enterOrVisitorsOrReverse;
72536
72796
  reverse = maybeReverse;
72797
+ } else {
72798
+ visitors = testOrEnterOrVisitors;
72799
+ reverse = enterOrVisitorsOrReverse;
72537
72800
  }
72538
- visitParents(tree, test, overload, reverse);
72539
- function overload(node3, parents) {
72540
- const parent = parents[parents.length - 1];
72541
- const index3 = parent ? parent.children.indexOf(node3) : undefined;
72542
- return visitor(node3, index3, parent);
72801
+ if (typeof visitors === "function") {
72802
+ visitParents(tree, check3, wrap2(visitors), reverse);
72803
+ } else {
72804
+ visitParents(tree, check3, wrapVisitors(visitors), reverse);
72805
+ }
72806
+ }
72807
+ function wrapVisitors(visitors) {
72808
+ if (!visitors || typeof visitors !== "object")
72809
+ return visitors;
72810
+ return {
72811
+ enter: typeof visitors.enter === "function" ? wrap2(visitors.enter) : visitors.enter,
72812
+ exit: typeof visitors.exit === "function" ? wrap2(visitors.exit) : visitors.exit
72813
+ };
72814
+ }
72815
+ function wrap2(visitor) {
72816
+ return overload;
72817
+ function overload(node3, parents, index3) {
72818
+ return visitor(node3, index3, parents[parents.length - 1]);
72543
72819
  }
72544
72820
  }
72545
72821
  // ../../node_modules/.pnpm/mdast-util-to-markdown@2.1.2/node_modules/mdast-util-to-markdown/lib/util/format-heading-as-setext.js
@@ -75616,43 +75892,10 @@ function peek(_, _1, state) {
75616
75892
  return state.options.emphasis || "*";
75617
75893
  }
75618
75894
 
75619
- // ../../node_modules/.pnpm/unist-util-visit@5.2.0/node_modules/unist-util-visit/lib/index.js
75620
- function visit3(tree, testOrEnterOrVisitors, enterOrVisitorsOrReverse, maybeReverse) {
75621
- let check4;
75622
- let visitors;
75623
- let reverse;
75624
- if (typeof enterOrVisitorsOrReverse === "function" || enterOrVisitorsOrReverse && typeof enterOrVisitorsOrReverse === "object") {
75625
- check4 = testOrEnterOrVisitors;
75626
- visitors = enterOrVisitorsOrReverse;
75627
- reverse = maybeReverse;
75628
- } else {
75629
- visitors = testOrEnterOrVisitors;
75630
- reverse = enterOrVisitorsOrReverse;
75631
- }
75632
- if (typeof visitors === "function") {
75633
- visitParents(tree, check4, wrap2(visitors), reverse);
75634
- } else {
75635
- visitParents(tree, check4, wrapVisitors(visitors), reverse);
75636
- }
75637
- }
75638
- function wrapVisitors(visitors) {
75639
- if (!visitors || typeof visitors !== "object")
75640
- return visitors;
75641
- return {
75642
- enter: typeof visitors.enter === "function" ? wrap2(visitors.enter) : visitors.enter,
75643
- exit: typeof visitors.exit === "function" ? wrap2(visitors.exit) : visitors.exit
75644
- };
75645
- }
75646
- function wrap2(visitor) {
75647
- return overload;
75648
- function overload(node3, parents, index3) {
75649
- return visitor(node3, index3, parents[parents.length - 1]);
75650
- }
75651
- }
75652
75895
  // ../../node_modules/.pnpm/mdast-util-to-markdown@2.2.3/node_modules/mdast-util-to-markdown/lib/util/format-heading-as-setext.js
75653
75896
  function formatHeadingAsSetext2(node3, state) {
75654
75897
  let literalWithBreak = false;
75655
- visit3(node3, function(node4) {
75898
+ visit2(node3, function(node4) {
75656
75899
  if ("value" in node4 && /\r?\n|\r/.test(node4.value) || node4.type === "break") {
75657
75900
  literalWithBreak = true;
75658
75901
  return EXIT;
@@ -78043,7 +78286,11 @@ function messagingSection() {
78043
78286
  "",
78044
78287
  "#### Ask for a decision",
78045
78288
  "",
78046
- `Alook users cannot see native question prompts. When you need someone to choose from options, use \`${CLI} message send --ask\` with JSON on stdin (max 8 KiB).`,
78289
+ `Whenever you would use your native Ask Question tool, use Alook’s \`${CLI} message send --ask --remind-after 5m\` in the current conversation instead. People on Alook can only see the question you send there.`,
78290
+ "",
78291
+ "When you ask a question and can offer options, use a decision card. " + "Use a normal Alook message for updates and questions without options.",
78292
+ "",
78293
+ "Pass JSON on stdin (max 8 KiB).",
78047
78294
  "Include a required non-empty `summary` (1–240 chars). Recommend at least one option per question to help the user decide. Use `recommended: true`. Use `mentions` to name respondents, and short `header` values for multi-question tabs. Answers arrive in your inbox as replies to the original question.",
78048
78295
  "",
78049
78296
  "```json",
@@ -79999,6 +80246,9 @@ ${this.opts.wakePromptFooter}` : text8;
79999
80246
  return;
80000
80247
  }
80001
80248
  const sessionSuperseded = owner.superseded;
80249
+ if (event.type === "session_activity" && !sessionSuperseded) {
80250
+ this.dispatch({ type: "session_activity", agentId, sessionInstanceId: event.sessionInstanceId, observation: event.observation, nowMs: this.now() }, owner);
80251
+ }
80002
80252
  const runtimeError = event.type === "session_failed" ? event.error : event.type === "turn_completed" && event.result.outcome === "failed" ? event.result.error : undefined;
80003
80253
  if (runtimeError !== undefined && !sessionSuperseded) {
80004
80254
  this.emitErrorAudit(agentId, "runtime", runtimeError.code, runtimeError.message);
@@ -80015,12 +80265,12 @@ ${this.opts.wakePromptFooter}` : text8;
80015
80265
  }
80016
80266
  }
80017
80267
  if (this.opts.onBotAuditEvent) {
80018
- if (event.type === "assistant_message_completed" && event.text.length > 0) {
80268
+ if ((event.type === "assistant_message_completed" || event.type === "activity" && event.kind === "assistant_message_completed") && event.text && event.text.length > 0) {
80019
80269
  const { text: text8, truncated, chars } = truncateAuditText(event.text);
80020
80270
  try {
80021
80271
  this.opts.onBotAuditEvent(agentId, {
80022
80272
  kind: "text",
80023
- payload: { text: text8, truncated: truncated || event.truncated, chars }
80273
+ payload: { text: text8, truncated: truncated || event.truncated === true, chars }
80024
80274
  }, {
80025
80275
  sessionId: this.liveSessions.get(agentId) ?? null,
80026
80276
  launchId: this.launchIds.get(agentId) ?? null
@@ -81598,212 +81848,233 @@ async function startCredentialProxy(broker, options = {}) {
81598
81848
  return;
81599
81849
  }
81600
81850
  };
81601
- const server = http.createServer(async (req, res) => {
81602
- const requestUrl = new URL2(req.url ?? "/", "http://placeholder");
81603
- const pathname = requestUrl.pathname;
81604
- if (pathname === LOCAL_MEMORY_COMMIT_PATH) {
81605
- if (req.method !== "POST" || req.url !== LOCAL_MEMORY_COMMIT_PATH) {
81606
- writeJson(res, 405, { error: "method not allowed" });
81607
- req.resume();
81851
+ const server = http.createServer((req, res) => {
81852
+ (async () => {
81853
+ const requestUrl = new URL2(req.url ?? "/", "http://placeholder");
81854
+ const pathname = requestUrl.pathname;
81855
+ if (pathname === LOCAL_MEMORY_COMMIT_PATH) {
81856
+ if (req.method !== "POST" || req.url !== LOCAL_MEMORY_COMMIT_PATH) {
81857
+ writeJson(res, 405, { error: "method not allowed" });
81858
+ req.resume();
81859
+ return;
81860
+ }
81861
+ const verdict2 = broker.check(req.headers["authorization"], "send");
81862
+ if (!verdict2.ok) {
81863
+ writeJson(res, verdict2.status, { error: verdict2.error, code: verdict2.code });
81864
+ req.resume();
81865
+ return;
81866
+ }
81867
+ await handleLocalMemoryCommit(req, res, verdict2.reg, options.onMemoryCommit, options.onMemoryCommitResetError);
81608
81868
  return;
81609
81869
  }
81610
- const verdict2 = broker.check(req.headers["authorization"], "send");
81611
- if (!verdict2.ok) {
81612
- writeJson(res, verdict2.status, { error: verdict2.error, code: verdict2.code });
81613
- req.resume();
81870
+ if (pathname === LOCAL_PII_PATH && (req.method === "GET" || req.method === "POST")) {
81871
+ const localVerdict = broker.check(req.headers["authorization"], req.method === "GET" ? "read" : "send");
81872
+ if (!localVerdict.ok) {
81873
+ writeJson(res, localVerdict.status, { error: localVerdict.error, code: localVerdict.code });
81874
+ req.resume();
81875
+ return;
81876
+ }
81877
+ await handleLocalPii(req, res, localVerdict.reg.agentId, options.pii);
81614
81878
  return;
81615
81879
  }
81616
- await handleLocalMemoryCommit(req, res, verdict2.reg, options.onMemoryCommit, options.onMemoryCommitResetError);
81617
- return;
81618
- }
81619
- if (pathname === LOCAL_PII_PATH && (req.method === "GET" || req.method === "POST")) {
81620
- const localVerdict = broker.check(req.headers["authorization"], req.method === "GET" ? "read" : "send");
81621
- if (!localVerdict.ok) {
81622
- writeJson(res, localVerdict.status, { error: localVerdict.error, code: localVerdict.code });
81623
- req.resume();
81880
+ if (pathname.startsWith("/__alook/local/")) {
81881
+ if (req.url !== LOCAL_MESSAGE_REMINDER_PATH) {
81882
+ writeJson(res, 404, { error: "unknown local route", code: "not_found" });
81883
+ req.resume();
81884
+ return;
81885
+ }
81886
+ if (req.method !== "PUT") {
81887
+ writeJson(res, 405, { error: "method not allowed", code: "method_not_allowed" });
81888
+ req.resume();
81889
+ return;
81890
+ }
81891
+ const localVerdict = broker.check(req.headers["authorization"], "send");
81892
+ if (!localVerdict.ok) {
81893
+ writeJson(res, localVerdict.status, { error: localVerdict.error, code: localVerdict.code });
81894
+ req.resume();
81895
+ return;
81896
+ }
81897
+ handleLocalMessageReminder(req, res, localVerdict.reg.agentId, options.onMessageReminderArm);
81624
81898
  return;
81625
81899
  }
81626
- await handleLocalPii(req, res, localVerdict.reg.agentId, options.pii);
81627
- return;
81628
- }
81629
- if (pathname.startsWith("/__alook/local/")) {
81630
- if (req.url !== LOCAL_MESSAGE_REMINDER_PATH) {
81631
- writeJson(res, 404, { error: "unknown local route", code: "not_found" });
81900
+ const route = resolveProxyRoute(pathname, req.method ?? "GET", req.url ?? pathname);
81901
+ const requiredCap = resolveCap ? resolveCap(req.method ?? "GET", pathname) : route.capability;
81902
+ const verdict = broker.check(req.headers["authorization"], requiredCap);
81903
+ if (!verdict.ok) {
81904
+ res.writeHead(verdict.status, { "content-type": "application/json" });
81905
+ res.end(JSON.stringify({ error: verdict.error, code: verdict.code }));
81632
81906
  req.resume();
81633
81907
  return;
81634
81908
  }
81635
- if (req.method !== "PUT") {
81636
- writeJson(res, 405, { error: "method not allowed", code: "method_not_allowed" });
81637
- req.resume();
81909
+ if (pathname.startsWith("/api/community/machines") && !(req.method === "GET" && /^\/api\/community\/machines(?:\/[^/]+(?:\/models)?)?$/.test(pathname) || req.method === "POST" && /^\/api\/community\/machines\/[^/]+\/discover-models$/.test(pathname))) {
81910
+ writeJson(res, 403, { error: "Machine management is not available to bots", code: "forbidden" });
81638
81911
  return;
81639
81912
  }
81640
- const localVerdict = broker.check(req.headers["authorization"], "send");
81641
- if (!localVerdict.ok) {
81642
- writeJson(res, localVerdict.status, { error: localVerdict.error, code: localVerdict.code });
81913
+ const canonicalCommunityDoor = pathname === "/api/community/platform/feedback" || /^\/api\/community\/(channels|messages|servers|invites|friends|users|bots|machines)(\/|$)/.test(pathname);
81914
+ if (pathname === "/api" || pathname.startsWith("/api/") && !canonicalCommunityDoor) {
81915
+ res.writeHead(404, { "content-type": "application/json" });
81916
+ res.end(JSON.stringify({ error: "unknown API route", code: "not_found" }));
81643
81917
  req.resume();
81644
81918
  return;
81645
81919
  }
81646
- handleLocalMessageReminder(req, res, localVerdict.reg.agentId, options.onMessageReminderArm);
81647
- return;
81648
- }
81649
- const route = resolveProxyRoute(pathname, req.method ?? "GET", req.url ?? pathname);
81650
- const requiredCap = resolveCap ? resolveCap(req.method ?? "GET", pathname) : route.capability;
81651
- const verdict = broker.check(req.headers["authorization"], requiredCap);
81652
- if (!verdict.ok) {
81653
- res.writeHead(verdict.status, { "content-type": "application/json" });
81654
- res.end(JSON.stringify({ error: verdict.error, code: verdict.code }));
81655
- req.resume();
81656
- return;
81657
- }
81658
- if (pathname.startsWith("/api/community/machines") && !(req.method === "GET" && /^\/api\/community\/machines(?:\/[^/]+(?:\/models)?)?$/.test(pathname) || req.method === "POST" && /^\/api\/community\/machines\/[^/]+\/discover-models$/.test(pathname))) {
81659
- writeJson(res, 403, { error: "Machine management is not available to bots", code: "forbidden" });
81660
- return;
81661
- }
81662
- const canonicalCommunityDoor = pathname === "/api/community/platform/feedback" || /^\/api\/community\/(channels|messages|servers|invites|friends|users|bots|machines)(\/|$)/.test(pathname);
81663
- if (pathname === "/api" || pathname.startsWith("/api/") && !canonicalCommunityDoor) {
81664
- res.writeHead(404, { "content-type": "application/json" });
81665
- res.end(JSON.stringify({ error: "unknown API route", code: "not_found" }));
81666
- req.resume();
81667
- return;
81668
- }
81669
- if (/^\/api\/community\/bots\/me\/nap(?:\/|$)/.test(pathname)) {
81670
- writeJson(res, 410, { error: "nap was removed; use local commit to record a memory review", code: "command_removed" });
81671
- req.resume();
81672
- return;
81673
- }
81674
- const reg = verdict.reg;
81675
- if (/^\/api\/community\/bots\/[^/]+\/pii\/?$/.test(pathname)) {
81676
- writeJson(res, 403, { error: "PII management requires a human owner session", code: "forbidden" });
81677
- req.resume();
81678
- return;
81679
- }
81680
- let filteredBody;
81681
- let piiTriggeredFilters = [];
81682
- if (options.pii && route.filterPiiSend) {
81683
- try {
81684
- const filtered = await filterPiiRequest(req, reg.agentId, options.pii);
81685
- filteredBody = filtered.body;
81686
- piiTriggeredFilters = filtered.triggeredFilters;
81687
- } catch (error62) {
81688
- writePiiError(res, error62);
81920
+ if (/^\/api\/community\/bots\/me\/nap(?:\/|$)/.test(pathname)) {
81921
+ writeJson(res, 410, { error: "nap was removed; use local commit to record a memory review", code: "command_removed" });
81922
+ req.resume();
81689
81923
  return;
81690
81924
  }
81691
- if (res.destroyed)
81925
+ const reg = verdict.reg;
81926
+ if (/^\/api\/community\/bots\/[^/]+\/pii\/?$/.test(pathname)) {
81927
+ writeJson(res, 403, { error: "PII management requires a human owner session", code: "forbidden" });
81928
+ req.resume();
81692
81929
  return;
81693
- }
81694
- const isInboxPull = route.inboxObservation === "pull";
81695
- const isInboxAck = route.inboxObservation === "ack";
81696
- const shouldObserveInboxPull = Boolean(isInboxPull && onPull);
81697
- const shouldObserveInboxAck = Boolean(isInboxAck && onAck);
81698
- let inboxPullObservationToken;
81699
- let inboxAckObservationToken;
81700
- if (shouldObserveInboxPull) {
81701
- try {
81702
- inboxPullObservationToken = options.onInboxPullStart?.(reg.agentId);
81703
- } catch {
81704
- reportInboxPullObservationError({
81705
- agentId: reg.agentId,
81706
- reason: "observer_failed",
81707
- contentEncoding: "identity"
81708
- });
81709
81930
  }
81710
- }
81711
- if (shouldObserveInboxAck) {
81712
- try {
81713
- inboxAckObservationToken = options.onInboxAckStart?.(reg.agentId);
81714
- } catch {
81715
- reportInboxAckObservationError({
81716
- agentId: reg.agentId,
81717
- reason: "observer_failed",
81718
- contentEncoding: "identity"
81719
- });
81931
+ let filteredBody;
81932
+ let piiTriggeredFilters = [];
81933
+ if (options.pii && route.filterPiiSend) {
81934
+ try {
81935
+ const filtered = await filterPiiRequest(req, reg.agentId, options.pii);
81936
+ filteredBody = filtered.body;
81937
+ piiTriggeredFilters = filtered.triggeredFilters;
81938
+ } catch (error62) {
81939
+ writePiiError(res, error62);
81940
+ return;
81941
+ }
81942
+ if (res.destroyed)
81943
+ return;
81720
81944
  }
81721
- }
81722
- if (onProxyRequest) {
81723
- try {
81724
- const method = req.method ?? "GET";
81725
- onProxyRequest(reg.agentId, method, pathname, route.propertyMetadata, route.auditOperation);
81726
- } catch {}
81727
- }
81728
- const outHeaders = { ...req.headers };
81729
- delete outHeaders["authorization"];
81730
- delete outHeaders["host"];
81731
- outHeaders["authorization"] = `Bearer ${reg.runnerKey}`;
81732
- outHeaders[broker.headerNames.agentId.toLowerCase()] = reg.agentId;
81733
- outHeaders[broker.headerNames.client.toLowerCase()] = broker.clientLabel;
81734
- outHeaders[broker.headerNames.capabilities.toLowerCase()] = [...reg.capabilities].join(",");
81735
- if (isInboxPull || isInboxAck)
81736
- outHeaders["accept-encoding"] = "identity";
81737
- if (filteredBody) {
81738
- delete outHeaders["transfer-encoding"];
81739
- outHeaders["content-length"] = filteredBody.byteLength;
81740
- }
81741
- let responded = false;
81742
- if (piiTriggeredFilters.length)
81743
- outHeaders["accept-encoding"] = "identity";
81744
- let upstreamRes;
81745
- const upstreamReq = upstreamClient.request({
81746
- protocol: upstream.protocol,
81747
- hostname: upstream.hostname,
81748
- port: upstream.port || (upstream.protocol === "https:" ? 443 : 80),
81749
- method: req.method,
81750
- path: joinPath(upstream.pathname, req.url ?? "/"),
81751
- headers: outHeaders
81752
- }, (res_) => {
81753
- responded = true;
81754
- upstreamRes = res_;
81755
- const destroyResIfIncomplete = () => {
81756
- if (!res_.complete)
81757
- res.destroy();
81758
- };
81759
- res_.on("error", destroyResIfIncomplete);
81760
- res_.on("close", destroyResIfIncomplete);
81761
- if ((shouldObserveInboxPull || shouldObserveInboxAck) && res_.statusCode !== undefined && res_.statusCode >= 200 && res_.statusCode < 300) {
81762
- const chunks = [];
81763
- res_.on("data", (chunk2) => chunks.push(chunk2));
81764
- res_.on("end", () => {
81765
- const body = Buffer.concat(chunks);
81766
- const contentEncoding = normalizeContentEncoding(res_.headers["content-encoding"]);
81767
- if (contentEncoding !== "identity") {
81768
- if (shouldObserveInboxPull) {
81769
- reportInboxPullObservationError({
81770
- agentId: reg.agentId,
81771
- reason: "unexpected_content_encoding",
81772
- contentEncoding
81773
- });
81774
- } else {
81775
- reportInboxAckObservationError({
81776
- agentId: reg.agentId,
81777
- reason: "unexpected_content_encoding",
81778
- contentEncoding
81779
- });
81780
- }
81781
- } else {
81782
- let parsed;
81783
- try {
81784
- parsed = JSON.parse(body.toString("utf8"));
81785
- } catch {
81945
+ const isInboxPull = route.inboxObservation === "pull";
81946
+ const isInboxAck = route.inboxObservation === "ack";
81947
+ const shouldObserveInboxPull = Boolean(isInboxPull && onPull);
81948
+ const shouldObserveInboxAck = Boolean(isInboxAck && onAck);
81949
+ let inboxPullObservationToken;
81950
+ let inboxAckObservationToken;
81951
+ if (shouldObserveInboxPull) {
81952
+ try {
81953
+ inboxPullObservationToken = options.onInboxPullStart?.(reg.agentId);
81954
+ } catch {
81955
+ reportInboxPullObservationError({
81956
+ agentId: reg.agentId,
81957
+ reason: "observer_failed",
81958
+ contentEncoding: "identity"
81959
+ });
81960
+ }
81961
+ }
81962
+ if (shouldObserveInboxAck) {
81963
+ try {
81964
+ inboxAckObservationToken = options.onInboxAckStart?.(reg.agentId);
81965
+ } catch {
81966
+ reportInboxAckObservationError({
81967
+ agentId: reg.agentId,
81968
+ reason: "observer_failed",
81969
+ contentEncoding: "identity"
81970
+ });
81971
+ }
81972
+ }
81973
+ if (onProxyRequest) {
81974
+ try {
81975
+ const method = req.method ?? "GET";
81976
+ onProxyRequest(reg.agentId, method, pathname, route.propertyMetadata, route.auditOperation);
81977
+ } catch {}
81978
+ }
81979
+ const outHeaders = { ...req.headers };
81980
+ delete outHeaders["authorization"];
81981
+ delete outHeaders["host"];
81982
+ outHeaders["authorization"] = `Bearer ${reg.runnerKey}`;
81983
+ outHeaders[broker.headerNames.agentId.toLowerCase()] = reg.agentId;
81984
+ outHeaders[broker.headerNames.client.toLowerCase()] = broker.clientLabel;
81985
+ outHeaders[broker.headerNames.capabilities.toLowerCase()] = [...reg.capabilities].join(",");
81986
+ if (isInboxPull || isInboxAck)
81987
+ outHeaders["accept-encoding"] = "identity";
81988
+ if (filteredBody) {
81989
+ delete outHeaders["transfer-encoding"];
81990
+ outHeaders["content-length"] = filteredBody.byteLength;
81991
+ }
81992
+ let responded = false;
81993
+ if (piiTriggeredFilters.length)
81994
+ outHeaders["accept-encoding"] = "identity";
81995
+ let upstreamRes;
81996
+ const upstreamReq = upstreamClient.request({
81997
+ protocol: upstream.protocol,
81998
+ hostname: upstream.hostname,
81999
+ port: upstream.port || (upstream.protocol === "https:" ? 443 : 80),
82000
+ method: req.method,
82001
+ path: joinPath(upstream.pathname, req.url ?? "/"),
82002
+ headers: outHeaders
82003
+ }, (res_) => {
82004
+ responded = true;
82005
+ upstreamRes = res_;
82006
+ const destroyResIfIncomplete = () => {
82007
+ if (!res_.complete)
82008
+ res.destroy();
82009
+ };
82010
+ res_.on("error", destroyResIfIncomplete);
82011
+ res_.on("close", destroyResIfIncomplete);
82012
+ if ((shouldObserveInboxPull || shouldObserveInboxAck) && res_.statusCode !== undefined && res_.statusCode >= 200 && res_.statusCode < 300) {
82013
+ const chunks = [];
82014
+ res_.on("data", (chunk2) => chunks.push(chunk2));
82015
+ res_.on("end", () => {
82016
+ const body = Buffer.concat(chunks);
82017
+ const contentEncoding = normalizeContentEncoding(res_.headers["content-encoding"]);
82018
+ if (contentEncoding !== "identity") {
81786
82019
  if (shouldObserveInboxPull) {
81787
- reportInboxPullObservationError({ agentId: reg.agentId, reason: "invalid_json", contentEncoding });
82020
+ reportInboxPullObservationError({
82021
+ agentId: reg.agentId,
82022
+ reason: "unexpected_content_encoding",
82023
+ contentEncoding
82024
+ });
81788
82025
  } else {
81789
- reportInboxAckObservationError({ agentId: reg.agentId, reason: "invalid_json", contentEncoding });
82026
+ reportInboxAckObservationError({
82027
+ agentId: reg.agentId,
82028
+ reason: "unexpected_content_encoding",
82029
+ contentEncoding
82030
+ });
81790
82031
  }
81791
- }
81792
- if (parsed !== undefined) {
81793
- if (shouldObserveInboxPull) {
81794
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed) || !Array.isArray(parsed.messages)) {
81795
- reportInboxPullObservationError({
82032
+ } else {
82033
+ let parsed;
82034
+ try {
82035
+ parsed = JSON.parse(body.toString("utf8"));
82036
+ } catch {
82037
+ if (shouldObserveInboxPull) {
82038
+ reportInboxPullObservationError({ agentId: reg.agentId, reason: "invalid_json", contentEncoding });
82039
+ } else {
82040
+ reportInboxAckObservationError({ agentId: reg.agentId, reason: "invalid_json", contentEncoding });
82041
+ }
82042
+ }
82043
+ if (parsed !== undefined) {
82044
+ if (shouldObserveInboxPull) {
82045
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed) || !Array.isArray(parsed.messages)) {
82046
+ reportInboxPullObservationError({
82047
+ agentId: reg.agentId,
82048
+ reason: "invalid_inbox_shape",
82049
+ contentEncoding
82050
+ });
82051
+ } else {
82052
+ const messages = parsed.messages;
82053
+ if (messages.length > 0) {
82054
+ try {
82055
+ onPull(reg.agentId, messages, inboxPullObservationToken);
82056
+ } catch {
82057
+ reportInboxPullObservationError({
82058
+ agentId: reg.agentId,
82059
+ reason: "observer_failed",
82060
+ contentEncoding
82061
+ });
82062
+ }
82063
+ }
82064
+ }
82065
+ } else if (!parsed || typeof parsed !== "object" || Array.isArray(parsed) || !Array.isArray(parsed.applied) || !parsed.applied.every((cursor) => Boolean(cursor) && typeof cursor === "object" && !Array.isArray(cursor) && typeof cursor.channel === "string" && cursor.channel.length > 0 && typeof cursor.seq === "number" && Number.isSafeInteger(cursor.seq) && cursor.seq > 0)) {
82066
+ reportInboxAckObservationError({
81796
82067
  agentId: reg.agentId,
81797
- reason: "invalid_inbox_shape",
82068
+ reason: "invalid_ack_shape",
81798
82069
  contentEncoding
81799
82070
  });
81800
82071
  } else {
81801
- const messages = parsed.messages;
81802
- if (messages.length > 0) {
82072
+ const applied = parsed.applied;
82073
+ if (applied.length > 0) {
81803
82074
  try {
81804
- onPull(reg.agentId, messages, inboxPullObservationToken);
82075
+ onAck(reg.agentId, applied, inboxAckObservationToken);
81805
82076
  } catch {
81806
- reportInboxPullObservationError({
82077
+ reportInboxAckObservationError({
81807
82078
  agentId: reg.agentId,
81808
82079
  reason: "observer_failed",
81809
82080
  contentEncoding
@@ -81811,66 +82082,47 @@ async function startCredentialProxy(broker, options = {}) {
81811
82082
  }
81812
82083
  }
81813
82084
  }
81814
- } else if (!parsed || typeof parsed !== "object" || Array.isArray(parsed) || !Array.isArray(parsed.applied) || !parsed.applied.every((cursor) => Boolean(cursor) && typeof cursor === "object" && !Array.isArray(cursor) && typeof cursor.channel === "string" && cursor.channel.length > 0 && typeof cursor.seq === "number" && Number.isSafeInteger(cursor.seq) && cursor.seq > 0)) {
81815
- reportInboxAckObservationError({
81816
- agentId: reg.agentId,
81817
- reason: "invalid_ack_shape",
81818
- contentEncoding
81819
- });
81820
- } else {
81821
- const applied = parsed.applied;
81822
- if (applied.length > 0) {
81823
- try {
81824
- onAck(reg.agentId, applied, inboxAckObservationToken);
81825
- } catch {
81826
- reportInboxAckObservationError({
81827
- agentId: reg.agentId,
81828
- reason: "observer_failed",
81829
- contentEncoding
81830
- });
81831
- }
81832
- }
81833
82085
  }
81834
82086
  }
81835
- }
81836
- res.writeHead(res_.statusCode, res_.headers);
81837
- res.end(body);
81838
- });
81839
- } else if (piiTriggeredFilters.length && res_.statusCode !== undefined && res_.statusCode >= 200 && res_.statusCode < 300 && normalizeContentEncoding(res_.headers["content-encoding"]) === "identity") {
81840
- forwardPiiSendResponse(res_, res, piiTriggeredFilters);
81841
- } else {
81842
- res.writeHead(res_.statusCode ?? 502, res_.headers);
81843
- res_.pipe(res);
81844
- }
81845
- });
81846
- upstreamReq.on("error", (err) => {
81847
- if (responded)
81848
- return;
81849
- responded = true;
81850
- res.writeHead(502, { "content-type": "application/json" });
81851
- res.end(JSON.stringify({ error: `upstream error: ${err.message}`, code: "upstream_error" }));
81852
- });
81853
- const waitingForModels = route.modelDiscovery && requestUrl.searchParams.get("wait") === "1";
81854
- const upstreamTimeoutMs = options.upstreamTimeoutMs ?? (waitingForModels ? 55000 : DEFAULT_UPSTREAM_TIMEOUT_MS);
81855
- upstreamReq.setTimeout(upstreamTimeoutMs, () => {
81856
- upstreamReq.destroy();
81857
- upstreamRes?.destroy();
81858
- if (responded) {
81859
- res.destroy();
81860
- return;
81861
- }
81862
- responded = true;
81863
- res.writeHead(504, { "content-type": "application/json" });
81864
- res.end(JSON.stringify({ error: `upstream request timed out after ${upstreamTimeoutMs}ms`, code: "upstream_timeout" }));
81865
- });
81866
- res.on("close", () => {
81867
- upstreamReq.destroy();
81868
- upstreamRes?.destroy();
81869
- });
81870
- if (filteredBody)
81871
- upstreamReq.end(filteredBody);
81872
- else
81873
- req.pipe(upstreamReq);
82087
+ res.writeHead(res_.statusCode, res_.headers);
82088
+ res.end(body);
82089
+ });
82090
+ } else if (piiTriggeredFilters.length && res_.statusCode !== undefined && res_.statusCode >= 200 && res_.statusCode < 300 && normalizeContentEncoding(res_.headers["content-encoding"]) === "identity") {
82091
+ forwardPiiSendResponse(res_, res, piiTriggeredFilters);
82092
+ } else {
82093
+ res.writeHead(res_.statusCode ?? 502, res_.headers);
82094
+ res_.pipe(res);
82095
+ }
82096
+ });
82097
+ upstreamReq.on("error", (err) => {
82098
+ if (responded)
82099
+ return;
82100
+ responded = true;
82101
+ res.writeHead(502, { "content-type": "application/json" });
82102
+ res.end(JSON.stringify({ error: `upstream error: ${err.message}`, code: "upstream_error" }));
82103
+ });
82104
+ const waitingForModels = route.modelDiscovery && requestUrl.searchParams.get("wait") === "1";
82105
+ const upstreamTimeoutMs = options.upstreamTimeoutMs ?? (waitingForModels ? 55000 : DEFAULT_UPSTREAM_TIMEOUT_MS);
82106
+ upstreamReq.setTimeout(upstreamTimeoutMs, () => {
82107
+ upstreamReq.destroy();
82108
+ upstreamRes?.destroy();
82109
+ if (responded) {
82110
+ res.destroy();
82111
+ return;
82112
+ }
82113
+ responded = true;
82114
+ res.writeHead(504, { "content-type": "application/json" });
82115
+ res.end(JSON.stringify({ error: `upstream request timed out after ${upstreamTimeoutMs}ms`, code: "upstream_timeout" }));
82116
+ });
82117
+ res.on("close", () => {
82118
+ upstreamReq.destroy();
82119
+ upstreamRes?.destroy();
82120
+ });
82121
+ if (filteredBody)
82122
+ upstreamReq.end(filteredBody);
82123
+ else
82124
+ req.pipe(upstreamReq);
82125
+ })();
81874
82126
  });
81875
82127
  await new Promise((resolve6, reject) => {
81876
82128
  server.once("error", reject);