@shipers-dev/dayline 0.99.1 → 0.100.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +498 -66
  2. package/package.json +8 -1
package/dist/index.js CHANGED
@@ -42823,6 +42823,7 @@ class ChatPeer {
42823
42823
  const msg = {
42824
42824
  id: crypto.randomUUID(),
42825
42825
  author: { kind: "agent", id: authorAgentId, name: authorName },
42826
+ kind: "text",
42826
42827
  text: "",
42827
42828
  ts: Math.floor(Date.now() / 1000),
42828
42829
  mentions: [],
@@ -42882,6 +42883,9 @@ class ChatPeer {
42882
42883
  getDoc() {
42883
42884
  return this.doc;
42884
42885
  }
42886
+ async messages() {
42887
+ return listMessages(this.doc);
42888
+ }
42885
42889
  findMessage(id3) {
42886
42890
  for (const m of listMessages(this.doc))
42887
42891
  if (m.id === id3)
@@ -42994,7 +42998,7 @@ class ChatPeer {
42994
42998
  }
42995
42999
  };
42996
43000
  }
42997
- buildSnapshotGreet() {
43001
+ async buildSnapshotGreet() {
42998
43002
  const snap = exportSnapshot(this.doc);
42999
43003
  const frame = new Uint8Array(1 + snap.byteLength);
43000
43004
  frame[0] = FRAME_LORO;
@@ -43112,6 +43116,418 @@ var init_chat_peer = __esm(() => {
43112
43116
  init_chat_doc();
43113
43117
  });
43114
43118
 
43119
+ // src/_impl/chat-peer-binary.ts
43120
+ import { existsSync as existsSync15, readdirSync as readdirSync4 } from "fs";
43121
+ import { createRequire as createRequire2 } from "module";
43122
+ import { dirname as dirname12, join as join16 } from "path";
43123
+ function packageForHost() {
43124
+ const target = TARGETS[`${process.platform}-${process.arch}`];
43125
+ return target ? `@shipers-dev/dayline-chat-peer-${target}` : null;
43126
+ }
43127
+ function binName() {
43128
+ return process.platform === "win32" ? "dayline-chat-peer.exe" : "dayline-chat-peer";
43129
+ }
43130
+ function candidatesIn(targetDir) {
43131
+ const bin = binName();
43132
+ let triples = [];
43133
+ try {
43134
+ triples = readdirSync4(targetDir, { withFileTypes: true }).filter((e) => e.isDirectory() && e.name.includes("-")).map((e) => e.name);
43135
+ } catch {}
43136
+ const out = [];
43137
+ for (const profile of ["release", "debug"]) {
43138
+ out.push(join16(targetDir, profile, bin));
43139
+ for (const triple of triples)
43140
+ out.push(join16(targetDir, triple, profile, bin));
43141
+ }
43142
+ return out;
43143
+ }
43144
+ function devBuild() {
43145
+ let dir = dirname12(new URL(import.meta.url).pathname);
43146
+ for (let i = 0;i < 6; i++) {
43147
+ for (const candidate of candidatesIn(join16(dir, "target"))) {
43148
+ if (existsSync15(candidate))
43149
+ return candidate;
43150
+ }
43151
+ const parent = dirname12(dir);
43152
+ if (parent === dir)
43153
+ break;
43154
+ dir = parent;
43155
+ }
43156
+ return null;
43157
+ }
43158
+ function resolveChatPeerBinary() {
43159
+ const override = process.env.DAYLINE_CHAT_PEER_BIN;
43160
+ if (override)
43161
+ return existsSync15(override) ? override : null;
43162
+ const pkg = packageForHost();
43163
+ if (pkg) {
43164
+ try {
43165
+ const manifest = require_.resolve(`${pkg}/package.json`);
43166
+ const candidate = join16(dirname12(manifest), "bin", binName());
43167
+ if (existsSync15(candidate))
43168
+ return candidate;
43169
+ } catch {}
43170
+ }
43171
+ return devBuild();
43172
+ }
43173
+ var require_, TARGETS;
43174
+ var init_chat_peer_binary = __esm(() => {
43175
+ require_ = createRequire2(import.meta.url);
43176
+ TARGETS = {
43177
+ "darwin-arm64": "darwin-arm64",
43178
+ "darwin-x64": "darwin-x64",
43179
+ "linux-x64": "linux-x64",
43180
+ "linux-arm64": "linux-arm64",
43181
+ "win32-x64": "win32-x64"
43182
+ };
43183
+ });
43184
+
43185
+ // src/_impl/chat-peer-ipc.ts
43186
+ class ChatPeerSidecar {
43187
+ binary;
43188
+ log;
43189
+ static instance = null;
43190
+ child = null;
43191
+ pending = new Map;
43192
+ chats = new Map;
43193
+ nextId = 1;
43194
+ buf = new Uint8Array(0);
43195
+ spawning = false;
43196
+ constructor(binary, log4) {
43197
+ this.binary = binary;
43198
+ this.log = log4;
43199
+ }
43200
+ static shared(log4) {
43201
+ if (ChatPeerSidecar.instance)
43202
+ return ChatPeerSidecar.instance;
43203
+ const binary = resolveChatPeerBinary();
43204
+ if (!binary)
43205
+ return null;
43206
+ ChatPeerSidecar.instance = new ChatPeerSidecar(binary, log4);
43207
+ return ChatPeerSidecar.instance;
43208
+ }
43209
+ static reset() {
43210
+ try {
43211
+ ChatPeerSidecar.instance?.child?.kill();
43212
+ } catch {}
43213
+ ChatPeerSidecar.instance = null;
43214
+ }
43215
+ registerChat(chatId, handlers) {
43216
+ this.chats.set(chatId, handlers);
43217
+ this.ensureChild();
43218
+ }
43219
+ unregisterChat(chatId) {
43220
+ this.chats.delete(chatId);
43221
+ }
43222
+ notify(method, params, bin) {
43223
+ this.send({ id: null, method, params }, bin);
43224
+ }
43225
+ request(method, params, bin) {
43226
+ const id3 = this.nextId++;
43227
+ return new Promise((resolve2, reject) => {
43228
+ this.pending.set(id3, { resolve: resolve2, reject });
43229
+ this.send({ id: id3, method, params }, bin);
43230
+ });
43231
+ }
43232
+ send(msg, bin) {
43233
+ const child = this.ensureChild();
43234
+ if (!child)
43235
+ return;
43236
+ const json2 = new TextEncoder().encode(JSON.stringify(msg));
43237
+ const body = bin ?? new Uint8Array(0);
43238
+ const frame = new Uint8Array(8 + json2.byteLength + body.byteLength);
43239
+ const view = new DataView(frame.buffer);
43240
+ view.setUint32(0, json2.byteLength, false);
43241
+ view.setUint32(4, body.byteLength, false);
43242
+ frame.set(json2, 8);
43243
+ frame.set(body, 8 + json2.byteLength);
43244
+ try {
43245
+ child.stdin.write(frame);
43246
+ } catch (e) {
43247
+ this.log(`[chat-peer] write failed: ${e.message}`);
43248
+ }
43249
+ }
43250
+ ensureChild() {
43251
+ if (this.child)
43252
+ return this.child;
43253
+ if (this.spawning)
43254
+ return null;
43255
+ this.spawning = true;
43256
+ try {
43257
+ const child = Bun.spawn([this.binary], {
43258
+ stdio: ["pipe", "pipe", "inherit"],
43259
+ env: { ...process.env }
43260
+ });
43261
+ this.child = child;
43262
+ this.log(`[chat-peer] sidecar started (pid ${child.pid})`);
43263
+ this.readLoop(child);
43264
+ child.exited.then((code) => {
43265
+ if (this.child !== child)
43266
+ return;
43267
+ this.child = null;
43268
+ this.log(`[chat-peer] sidecar exited (${code}); reviving ${this.chats.size} chat(s)`);
43269
+ for (const [, p] of this.pending)
43270
+ p.reject(new Error("chat peer sidecar exited"));
43271
+ this.pending.clear();
43272
+ this.spawning = false;
43273
+ for (const [, handlers] of this.chats) {
43274
+ try {
43275
+ handlers.revive();
43276
+ } catch {}
43277
+ }
43278
+ });
43279
+ return child;
43280
+ } catch (e) {
43281
+ this.log(`[chat-peer] spawn failed: ${e.message}`);
43282
+ return null;
43283
+ } finally {
43284
+ this.spawning = false;
43285
+ }
43286
+ }
43287
+ async readLoop(child) {
43288
+ const reader = child.stdout.getReader();
43289
+ try {
43290
+ for (;; ) {
43291
+ const { done: done9, value: value3 } = await reader.read();
43292
+ if (done9)
43293
+ return;
43294
+ if (value3)
43295
+ this.consume(value3);
43296
+ }
43297
+ } catch (e) {
43298
+ this.log(`[chat-peer] read failed: ${e.message}`);
43299
+ }
43300
+ }
43301
+ consume(chunk3) {
43302
+ const merged = new Uint8Array(this.buf.byteLength + chunk3.byteLength);
43303
+ merged.set(this.buf, 0);
43304
+ merged.set(chunk3, this.buf.byteLength);
43305
+ this.buf = merged;
43306
+ for (;; ) {
43307
+ if (this.buf.byteLength < 8)
43308
+ return;
43309
+ const view = new DataView(this.buf.buffer, this.buf.byteOffset, this.buf.byteLength);
43310
+ const jsonLen = view.getUint32(0, false);
43311
+ const binLen = view.getUint32(4, false);
43312
+ const total = 8 + jsonLen + binLen;
43313
+ if (this.buf.byteLength < total)
43314
+ return;
43315
+ const json2 = this.buf.subarray(8, 8 + jsonLen);
43316
+ const bin = this.buf.subarray(8 + jsonLen, total);
43317
+ const binCopy = new Uint8Array(bin);
43318
+ let msg = null;
43319
+ try {
43320
+ msg = JSON.parse(new TextDecoder().decode(json2));
43321
+ } catch {
43322
+ this.log("[chat-peer] unparseable frame from sidecar");
43323
+ }
43324
+ this.buf = this.buf.slice(total);
43325
+ if (msg)
43326
+ this.deliver(msg, binCopy);
43327
+ }
43328
+ }
43329
+ deliver(msg, bin) {
43330
+ if (typeof msg.id === "number") {
43331
+ const p = this.pending.get(msg.id);
43332
+ if (!p)
43333
+ return;
43334
+ this.pending.delete(msg.id);
43335
+ if (msg.ok)
43336
+ p.resolve({ result: msg.result, bin });
43337
+ else
43338
+ p.reject(new Error(String(msg.error ?? "sidecar error")));
43339
+ return;
43340
+ }
43341
+ const handlers = msg.chat_id ? this.chats.get(msg.chat_id) : undefined;
43342
+ switch (msg.event) {
43343
+ case "user_message":
43344
+ if (handlers && msg.message)
43345
+ handlers.onUserMessage(msg.message);
43346
+ return;
43347
+ case "fanout":
43348
+ if (handlers) {
43349
+ handlers.onFanout(bin, typeof msg.except === "number" ? msg.except : null);
43350
+ }
43351
+ return;
43352
+ case "log":
43353
+ this.log(String(msg.line ?? ""));
43354
+ return;
43355
+ case "error":
43356
+ this.log(`[chat-peer] ${String(msg.message ?? "")}`);
43357
+ return;
43358
+ default:
43359
+ return;
43360
+ }
43361
+ }
43362
+ }
43363
+ var init_chat_peer_ipc = __esm(() => {
43364
+ init_chat_peer_binary();
43365
+ });
43366
+
43367
+ // src/_impl/chat-peer-remote.ts
43368
+ class RemoteChatPeer {
43369
+ opts;
43370
+ sidecar;
43371
+ chatId;
43372
+ nextHandle = 1;
43373
+ nextToken = 1;
43374
+ localSubs = new Map;
43375
+ closed = false;
43376
+ constructor(opts, sidecar) {
43377
+ this.opts = opts;
43378
+ this.sidecar = sidecar;
43379
+ this.chatId = opts.chatId;
43380
+ }
43381
+ start() {
43382
+ this.sidecar.registerChat(this.chatId, {
43383
+ onUserMessage: (msg) => {
43384
+ this.opts.onUserMessage?.(msg, this);
43385
+ },
43386
+ onFanout: (frame, except) => this.broadcastLocal(frame, except),
43387
+ revive: () => this.create()
43388
+ });
43389
+ this.create();
43390
+ }
43391
+ create() {
43392
+ if (this.closed)
43393
+ return;
43394
+ this.sidecar.notify("create", {
43395
+ chat_id: this.chatId,
43396
+ api_url: this.opts.apiUrl,
43397
+ auth_token: this.opts.authToken,
43398
+ workspace_id: this.opts.workspaceId,
43399
+ device_id: this.opts.deviceId ?? null,
43400
+ primary_agent_id: this.opts.primaryAgentId,
43401
+ want_user_messages: Boolean(this.opts.onUserMessage)
43402
+ });
43403
+ }
43404
+ close() {
43405
+ this.closed = true;
43406
+ this.sidecar.notify("close", { chat_id: this.chatId });
43407
+ this.sidecar.unregisterChat(this.chatId);
43408
+ }
43409
+ handle() {
43410
+ return `h${this.nextHandle++}`;
43411
+ }
43412
+ appendAndPush(msg) {
43413
+ const handle = this.handle();
43414
+ this.sidecar.notify("append", { chat_id: this.chatId, handle, msg });
43415
+ return handle;
43416
+ }
43417
+ appendStructured(msg) {
43418
+ return this.appendAndPush(msg);
43419
+ }
43420
+ flush() {
43421
+ this.sidecar.notify("flush", { chat_id: this.chatId });
43422
+ }
43423
+ beginPartialAgentMessage(authorAgentId, authorName) {
43424
+ const msg = {
43425
+ id: crypto.randomUUID(),
43426
+ author: { kind: "agent", id: authorAgentId, name: authorName },
43427
+ kind: "text",
43428
+ text: "",
43429
+ ts: Math.floor(Date.now() / 1000),
43430
+ mentions: [],
43431
+ attachments: [],
43432
+ partial: true
43433
+ };
43434
+ return { msgId: msg.id, containerId: this.appendAndPush(msg) };
43435
+ }
43436
+ appendPartialText(containerId, chunk3) {
43437
+ this.sidecar.notify("append_text", { chat_id: this.chatId, handle: containerId, chunk: chunk3 });
43438
+ }
43439
+ finalizePartialMessage(containerId) {
43440
+ this.sidecar.notify("finalize", { chat_id: this.chatId, handle: containerId });
43441
+ }
43442
+ upsertPlan(authorAgentId, authorName, entries2, containerId) {
43443
+ if (containerId) {
43444
+ this.patchMessage(containerId, { plan_entries: entries2 });
43445
+ return containerId;
43446
+ }
43447
+ const msg = {
43448
+ id: crypto.randomUUID(),
43449
+ author: { kind: "agent", id: authorAgentId, name: authorName },
43450
+ kind: "plan",
43451
+ text: "",
43452
+ ts: Math.floor(Date.now() / 1000),
43453
+ mentions: [],
43454
+ attachments: [],
43455
+ partial: false,
43456
+ plan_entries: entries2
43457
+ };
43458
+ return this.appendAndPush(msg);
43459
+ }
43460
+ patchMessage(containerId, patch9) {
43461
+ this.sidecar.notify("patch", { chat_id: this.chatId, handle: containerId, patch: patch9 });
43462
+ }
43463
+ markDelivered(msgId) {
43464
+ this.sidecar.notify("mark_delivered", { chat_id: this.chatId, msg_id: msgId });
43465
+ }
43466
+ async messages() {
43467
+ const { result } = await this.sidecar.request("messages", { chat_id: this.chatId });
43468
+ return result?.messages ?? [];
43469
+ }
43470
+ async awaitMessage(id3, timeoutMs = 5000) {
43471
+ const { result } = await this.sidecar.request("await_message", {
43472
+ chat_id: this.chatId,
43473
+ msg_id: id3,
43474
+ timeout_ms: timeoutMs
43475
+ });
43476
+ return result?.message ?? null;
43477
+ }
43478
+ async buildSnapshotGreet() {
43479
+ const { bin } = await this.sidecar.request("snapshot_greet", { chat_id: this.chatId });
43480
+ return bin;
43481
+ }
43482
+ hasLocalSubscribers() {
43483
+ return this.localSubs.size > 0;
43484
+ }
43485
+ addLocalSubscriber(send) {
43486
+ const token = this.nextToken++;
43487
+ this.localSubs.set(token, send);
43488
+ return { token, close: () => {
43489
+ this.localSubs.delete(token);
43490
+ } };
43491
+ }
43492
+ ingestLocalUpdate(update5, fromToken) {
43493
+ if (typeof fromToken !== "number")
43494
+ return;
43495
+ this.sidecar.notify("ingest_local_update", { chat_id: this.chatId, from_token: fromToken }, update5);
43496
+ }
43497
+ broadcastLocal(frame, except) {
43498
+ for (const [token, send] of this.localSubs) {
43499
+ if (token === except)
43500
+ continue;
43501
+ try {
43502
+ send(frame);
43503
+ } catch {}
43504
+ }
43505
+ }
43506
+ }
43507
+
43508
+ // src/_impl/chat-peer-factory.ts
43509
+ function createChatPeer(opts) {
43510
+ const mode = process.env.DAYLINE_CHAT_PEER ?? "auto";
43511
+ if (mode === "ts")
43512
+ return new ChatPeer(opts);
43513
+ const sidecar = ChatPeerSidecar.shared(opts.log);
43514
+ if (sidecar)
43515
+ return new RemoteChatPeer(opts, sidecar);
43516
+ if (mode === "rust") {
43517
+ throw new Error("DAYLINE_CHAT_PEER=rust but no dayline-chat-peer binary was found for this platform");
43518
+ }
43519
+ if (!warned) {
43520
+ warned = true;
43521
+ opts.log("[chat-peer] no sidecar binary for this platform; using the in-process peer");
43522
+ }
43523
+ return new ChatPeer(opts);
43524
+ }
43525
+ var warned = false;
43526
+ var init_chat_peer_factory = __esm(() => {
43527
+ init_chat_peer();
43528
+ init_chat_peer_ipc();
43529
+ });
43530
+
43115
43531
  // src/_impl/chat-turn.ts
43116
43532
  async function handleChatTurn(opts) {
43117
43533
  const detected = await detectAgents();
@@ -43881,8 +44297,8 @@ var init_chat_plan_actions = __esm(() => {
43881
44297
  });
43882
44298
 
43883
44299
  // src/_impl/chat-attachments.ts
43884
- import { existsSync as existsSync15, mkdirSync as mkdirSync12, writeFileSync as writeFileSync10 } from "fs";
43885
- import { dirname as dirname12, join as join16 } from "path";
44300
+ import { existsSync as existsSync16, mkdirSync as mkdirSync12, writeFileSync as writeFileSync10 } from "fs";
44301
+ import { dirname as dirname13, join as join17 } from "path";
43886
44302
  function safeName(n) {
43887
44303
  return n.replace(/[^A-Za-z0-9._-]+/g, "_").slice(0, 80) || "file";
43888
44304
  }
@@ -43891,18 +44307,18 @@ async function downloadUserAttachments(opts) {
43891
44307
  const atts = message.attachments || [];
43892
44308
  if (atts.length === 0)
43893
44309
  return [];
43894
- const baseRel = join16(".dayline", "attachments", message.id);
43895
- const baseAbs = join16(cwd, baseRel);
43896
- if (!existsSync15(baseAbs))
44310
+ const baseRel = join17(".dayline", "attachments", message.id);
44311
+ const baseAbs = join17(cwd, baseRel);
44312
+ if (!existsSync16(baseAbs))
43897
44313
  mkdirSync12(baseAbs, { recursive: true });
43898
44314
  const out = [];
43899
44315
  for (const a of atts) {
43900
44316
  if (!a.url)
43901
44317
  continue;
43902
44318
  const fname = safeName(a.name);
43903
- const relPath = join16(baseRel, fname);
43904
- const absPath = join16(cwd, relPath);
43905
- if (existsSync15(absPath)) {
44319
+ const relPath = join17(baseRel, fname);
44320
+ const absPath = join17(cwd, relPath);
44321
+ if (existsSync16(absPath)) {
43906
44322
  out.push({ attachment: a, absPath, relPath });
43907
44323
  continue;
43908
44324
  }
@@ -43916,8 +44332,8 @@ async function downloadUserAttachments(opts) {
43916
44332
  continue;
43917
44333
  }
43918
44334
  const buf = new Uint8Array(await res.arrayBuffer());
43919
- if (!existsSync15(dirname12(absPath)))
43920
- mkdirSync12(dirname12(absPath), { recursive: true });
44335
+ if (!existsSync16(dirname13(absPath)))
44336
+ mkdirSync12(dirname13(absPath), { recursive: true });
43921
44337
  writeFileSync10(absPath, buf);
43922
44338
  out.push({ attachment: a, absPath, relPath });
43923
44339
  } catch (e) {
@@ -44521,7 +44937,7 @@ ${agentsBlock}`;
44521
44937
  }
44522
44938
  var issueContextSent;
44523
44939
  var init_chat_supervisor = __esm(() => {
44524
- init_chat_peer();
44940
+ init_chat_peer_factory();
44525
44941
  init_chat_turn();
44526
44942
  init_chat_turn_registry();
44527
44943
  init_chat_plan_actions();
@@ -44570,7 +44986,7 @@ function ensureSession(wsId, chatId, ctx) {
44570
44986
  clearIdle(existing);
44571
44987
  return existing;
44572
44988
  }
44573
- const peer = new ChatPeer({
44989
+ const peer = createChatPeer({
44574
44990
  apiUrl: ctx.apiUrl,
44575
44991
  authToken: ctx.authToken,
44576
44992
  workspaceId: wsId,
@@ -44625,7 +45041,7 @@ async function runTurn(s, k, messageId, ctx, chatId) {
44625
45041
  }
44626
45042
  var DEFAULT_IDLE_TTL_MS, sessions, idleTtlMs, chatSessionRegistry;
44627
45043
  var init_chat_session_registry = __esm(() => {
44628
- init_chat_peer();
45044
+ init_chat_peer_factory();
44629
45045
  init_chat_supervisor();
44630
45046
  DEFAULT_IDLE_TTL_MS = 10 * 60 * 1000;
44631
45047
  sessions = new Map;
@@ -45283,7 +45699,7 @@ import { parseArgs } from "util";
45283
45699
  // package.json
45284
45700
  var package_default = {
45285
45701
  name: "@shipers-dev/dayline",
45286
- version: "0.99.1",
45702
+ version: "0.100.0",
45287
45703
  type: "module",
45288
45704
  bin: {
45289
45705
  dayline: "./dist/index.js"
@@ -45308,6 +45724,13 @@ var package_default = {
45308
45724
  },
45309
45725
  devDependencies: {
45310
45726
  "@multi/lib": "workspace:*"
45727
+ },
45728
+ optionalDependencies: {
45729
+ "@shipers-dev/dayline-chat-peer-darwin-arm64": "0.1.0",
45730
+ "@shipers-dev/dayline-chat-peer-darwin-x64": "0.1.0",
45731
+ "@shipers-dev/dayline-chat-peer-linux-x64": "0.1.0",
45732
+ "@shipers-dev/dayline-chat-peer-linux-arm64": "0.1.0",
45733
+ "@shipers-dev/dayline-chat-peer-win32-x64": "0.1.0"
45311
45734
  }
45312
45735
  };
45313
45736
 
@@ -46455,9 +46878,9 @@ init_client();
46455
46878
  init_detect();
46456
46879
  init_run_task();
46457
46880
  import { Database as Database3 } from "bun:sqlite";
46458
- import { existsSync as existsSync16, mkdirSync as mkdirSync13, writeFileSync as writeFileSync11, unlinkSync as unlinkSync7 } from "fs";
46881
+ import { existsSync as existsSync17, mkdirSync as mkdirSync13, writeFileSync as writeFileSync11, unlinkSync as unlinkSync7 } from "fs";
46459
46882
  import { homedir } from "os";
46460
- import { join as join17 } from "path";
46883
+ import { join as join18 } from "path";
46461
46884
  init_adapter_pidfile();
46462
46885
 
46463
46886
  // src/_impl/runs-projection.ts
@@ -46820,7 +47243,7 @@ init_lib();
46820
47243
  // package.json
46821
47244
  var package_default2 = {
46822
47245
  name: "@shipers-dev/dayline",
46823
- version: "0.99.1",
47246
+ version: "0.100.0",
46824
47247
  type: "module",
46825
47248
  bin: {
46826
47249
  dayline: "./dist/index.js"
@@ -46845,6 +47268,13 @@ var package_default2 = {
46845
47268
  },
46846
47269
  devDependencies: {
46847
47270
  "@multi/lib": "workspace:*"
47271
+ },
47272
+ optionalDependencies: {
47273
+ "@shipers-dev/dayline-chat-peer-darwin-arm64": "0.1.0",
47274
+ "@shipers-dev/dayline-chat-peer-darwin-x64": "0.1.0",
47275
+ "@shipers-dev/dayline-chat-peer-linux-x64": "0.1.0",
47276
+ "@shipers-dev/dayline-chat-peer-linux-arm64": "0.1.0",
47277
+ "@shipers-dev/dayline-chat-peer-win32-x64": "0.1.0"
46848
47278
  }
46849
47279
  };
46850
47280
 
@@ -46853,7 +47283,7 @@ var CLI_VERSION = package_default2.version;
46853
47283
  function findBunBinary() {
46854
47284
  const tryPath = (p) => {
46855
47285
  try {
46856
- return existsSync16(p) ? p : null;
47286
+ return existsSync17(p) ? p : null;
46857
47287
  } catch {
46858
47288
  return null;
46859
47289
  }
@@ -46867,7 +47297,7 @@ function findBunBinary() {
46867
47297
  if (fromWhich)
46868
47298
  return fromWhich;
46869
47299
  const candidates = [
46870
- join17(homedir(), ".bun", "bin", "bun"),
47300
+ join18(homedir(), ".bun", "bin", "bun"),
46871
47301
  "/opt/homebrew/bin/bun",
46872
47302
  "/usr/local/bin/bun",
46873
47303
  "/home/linuxbrew/.linuxbrew/bin/bun"
@@ -46879,12 +47309,12 @@ function findBunBinary() {
46879
47309
  }
46880
47310
  return null;
46881
47311
  }
46882
- var LOCAL_SERVER_PATH = join17(DAYLINE_DIR, "local-server.json");
47312
+ var LOCAL_SERVER_PATH = join18(DAYLINE_DIR, "local-server.json");
46883
47313
  function ensureDirs2() {
46884
- if (!existsSync16(DAYLINE_DIR))
47314
+ if (!existsSync17(DAYLINE_DIR))
46885
47315
  mkdirSync13(DAYLINE_DIR, { recursive: true });
46886
- const logs = join17(DAYLINE_DIR, "logs");
46887
- if (!existsSync16(logs))
47316
+ const logs = join18(DAYLINE_DIR, "logs");
47317
+ if (!existsSync17(logs))
46888
47318
  mkdirSync13(logs, { recursive: true });
46889
47319
  }
46890
47320
  function openTasksDb() {
@@ -47054,7 +47484,7 @@ var daemonProgram = ({ cfg, apiUrl }) => exports_Effect.gen(function* () {
47054
47484
  if (cfg.authToken)
47055
47485
  setAuthToken(cfg.authToken);
47056
47486
  ensureDirs2();
47057
- if (existsSync16(STOP_PATH))
47487
+ if (existsSync17(STOP_PATH))
47058
47488
  unlinkSync7(STOP_PATH);
47059
47489
  const reaped = reapStaleAdapters((m) => log3(m));
47060
47490
  if (reaped > 0)
@@ -47628,7 +48058,7 @@ var daemonProgram = ({ cfg, apiUrl }) => exports_Effect.gen(function* () {
47628
48058
  deviceId: cfg.deviceId,
47629
48059
  log: log3
47630
48060
  });
47631
- const greet = peer.buildSnapshotGreet();
48061
+ const greet = await peer.buildSnapshotGreet();
47632
48062
  return new Response(greet.subarray(1), {
47633
48063
  headers: { "content-type": "application/octet-stream" }
47634
48064
  });
@@ -47653,7 +48083,7 @@ var daemonProgram = ({ cfg, apiUrl }) => exports_Effect.gen(function* () {
47653
48083
  deviceId: cfg.deviceId,
47654
48084
  log: log3
47655
48085
  });
47656
- const messages = listMessages2(peer.getDoc());
48086
+ const messages = await peer.messages();
47657
48087
  return Response.json({ chat_id: chatId, messages });
47658
48088
  } catch (e) {
47659
48089
  const msg = e.message ?? String(e);
@@ -47709,7 +48139,7 @@ var daemonProgram = ({ cfg, apiUrl }) => exports_Effect.gen(function* () {
47709
48139
  }
47710
48140
  };
47711
48141
  const body = new ReadableStream({
47712
- start(controller) {
48142
+ async start(controller) {
47713
48143
  const send = (frame) => {
47714
48144
  try {
47715
48145
  controller.enqueue(encoder.encode(frame));
@@ -47718,28 +48148,30 @@ var daemonProgram = ({ cfg, apiUrl }) => exports_Effect.gen(function* () {
47718
48148
  teardown();
47719
48149
  }
47720
48150
  };
47721
- const reproject = () => {
48151
+ const reproject = async () => {
47722
48152
  try {
47723
- for (const changed of differ3.delta(listMessages2(peer.getDoc()))) {
48153
+ for (const changed of differ3.delta(await peer.messages())) {
47724
48154
  send(encodeSseEvent("message", changed));
47725
48155
  }
47726
48156
  } catch (e) {
47727
48157
  log3(`[chat-stream ${chatId}] reproject failed: ${e.message}`);
47728
48158
  }
47729
48159
  };
48160
+ let seeded = false;
47730
48161
  const scheduleReproject = () => {
47731
- if (done9 || coalesceTimer)
48162
+ if (done9 || !seeded || coalesceTimer)
47732
48163
  return;
47733
48164
  coalesceTimer = setTimeout(() => {
47734
48165
  coalesceTimer = null;
47735
48166
  reproject();
47736
48167
  }, 75);
47737
48168
  };
47738
- const messages = listMessages2(peer.getDoc());
48169
+ subscription = peer.addLocalSubscriber(scheduleReproject);
48170
+ const messages = await peer.messages();
47739
48171
  differ3.delta(messages);
48172
+ seeded = true;
47740
48173
  send(encodeSseEvent("snapshot", { chat_id: chatId, messages }));
47741
- subscription = peer.addLocalSubscriber(scheduleReproject);
47742
- catchupTimer = setTimeout(reproject, 1000);
48174
+ catchupTimer = setTimeout(() => void reproject(), 1000);
47743
48175
  ping = setInterval(() => {
47744
48176
  send(`: ping
47745
48177
 
@@ -47992,8 +48424,8 @@ var daemonProgram = ({ cfg, apiUrl }) => exports_Effect.gen(function* () {
47992
48424
  if (!path || !path.startsWith("/")) {
47993
48425
  return Response.json({ ok: false, code: "bad_path", message: "absolute path required" }, { status: 400 });
47994
48426
  }
47995
- const { existsSync: existsSync17, statSync: statSync3, mkdirSync: mkdirSync14 } = await import("node:fs");
47996
- if (!existsSync17(path) || !statSync3(path).isDirectory()) {
48427
+ const { existsSync: existsSync18, statSync: statSync3, mkdirSync: mkdirSync14 } = await import("node:fs");
48428
+ if (!existsSync18(path) || !statSync3(path).isDirectory()) {
47997
48429
  return Response.json({ ok: false, code: "missing", message: "directory does not exist" }, { status: 404 });
47998
48430
  }
47999
48431
  const { spawn: spawn3 } = await import("node:child_process");
@@ -48088,7 +48520,7 @@ var daemonProgram = ({ cfg, apiUrl }) => exports_Effect.gen(function* () {
48088
48520
  ws.data.peerToken = sub.token;
48089
48521
  ws.data.unsubscribe = sub.close;
48090
48522
  try {
48091
- ws.sendBinary(peer.buildSnapshotGreet());
48523
+ ws.sendBinary(await peer.buildSnapshotGreet());
48092
48524
  } catch {}
48093
48525
  },
48094
48526
  async message(ws, message) {
@@ -48143,7 +48575,7 @@ var daemonProgram = ({ cfg, apiUrl }) => exports_Effect.gen(function* () {
48143
48575
  yield* exports_Effect.forkIn(daemonScope)(exports_Effect.gen(function* () {
48144
48576
  while (true) {
48145
48577
  yield* exports_Effect.sleep(exports_Duration.seconds(150));
48146
- if (existsSync16(STOP_PATH)) {
48578
+ if (existsSync17(STOP_PATH)) {
48147
48579
  yield* exports_Deferred.succeed(stopDeferred, "stop flag");
48148
48580
  return;
48149
48581
  }
@@ -48156,7 +48588,7 @@ var daemonProgram = ({ cfg, apiUrl }) => exports_Effect.gen(function* () {
48156
48588
  }
48157
48589
  }).pipe(exports_Effect.catchAllCause((c) => exports_Effect.sync(() => log3(`funnel liveness crash: ${exports_Cause.pretty(c)}`)))));
48158
48590
  try {
48159
- if (!existsSync16(DAYLINE_DIR))
48591
+ if (!existsSync17(DAYLINE_DIR))
48160
48592
  mkdirSync13(DAYLINE_DIR, { recursive: true });
48161
48593
  writeFileSync11(LOCAL_SERVER_PATH, JSON.stringify({
48162
48594
  url: `http://127.0.0.1:${port}`,
@@ -48187,7 +48619,7 @@ var daemonProgram = ({ cfg, apiUrl }) => exports_Effect.gen(function* () {
48187
48619
  yield* exports_Effect.forkIn(daemonScope)(exports_Effect.gen(function* () {
48188
48620
  while (true) {
48189
48621
  yield* exports_Effect.sleep(exports_Duration.seconds(5));
48190
- if (existsSync16(STOP_PATH)) {
48622
+ if (existsSync17(STOP_PATH)) {
48191
48623
  yield* exports_Deferred.succeed(stopDeferred, "stop flag");
48192
48624
  return;
48193
48625
  }
@@ -48230,13 +48662,13 @@ var daemonProgram = ({ cfg, apiUrl }) => exports_Effect.gen(function* () {
48230
48662
  log3(`adapter shutdown sweep failed: ${String(e)}`);
48231
48663
  }
48232
48664
  yield* exports_Scope.close(daemonScope, exports_Exit.void).pipe(exports_Effect.catchAll(() => exports_Effect.void));
48233
- if (existsSync16(PID_PATH))
48665
+ if (existsSync17(PID_PATH))
48234
48666
  unlinkSync7(PID_PATH);
48235
- if (existsSync16(STOP_PATH))
48667
+ if (existsSync17(STOP_PATH))
48236
48668
  unlinkSync7(STOP_PATH);
48237
- if (existsSync16(PORT_PATH))
48669
+ if (existsSync17(PORT_PATH))
48238
48670
  unlinkSync7(PORT_PATH);
48239
- if (existsSync16(LOCAL_SERVER_PATH))
48671
+ if (existsSync17(LOCAL_SERVER_PATH))
48240
48672
  unlinkSync7(LOCAL_SERVER_PATH);
48241
48673
  db2.close();
48242
48674
  log3("disconnected");
@@ -48254,14 +48686,14 @@ init_detect();
48254
48686
  init_outbox();
48255
48687
 
48256
48688
  // src/_impl/pair-flow.ts
48257
- import { existsSync as existsSync17, mkdirSync as mkdirSync14, writeFileSync as writeFileSync12 } from "fs";
48258
- import { join as join18 } from "path";
48689
+ import { existsSync as existsSync18, mkdirSync as mkdirSync14, writeFileSync as writeFileSync12 } from "fs";
48690
+ import { join as join19 } from "path";
48259
48691
  init_paths();
48260
48692
  var LOCAL_SERVER_DIR = daylineDir();
48261
- var LOCAL_SERVER_PATH2 = join18(LOCAL_SERVER_DIR, "local-server.json");
48693
+ var LOCAL_SERVER_PATH2 = join19(LOCAL_SERVER_DIR, "local-server.json");
48262
48694
  function writePairingInfo(payload) {
48263
48695
  try {
48264
- if (!existsSync17(LOCAL_SERVER_DIR))
48696
+ if (!existsSync18(LOCAL_SERVER_DIR))
48265
48697
  mkdirSync14(LOCAL_SERVER_DIR, { recursive: true });
48266
48698
  writeFileSync12(LOCAL_SERVER_PATH2, JSON.stringify(payload, null, 2));
48267
48699
  } catch {}
@@ -48397,15 +48829,15 @@ ${err?.stack ?? ""}`);
48397
48829
 
48398
48830
  // src/commands/service.ts
48399
48831
  init_esm();
48400
- import { existsSync as existsSync18, readFileSync as readFileSync13 } from "fs";
48832
+ import { existsSync as existsSync19, readFileSync as readFileSync13 } from "fs";
48401
48833
  import { homedir as homedir2, platform, tmpdir } from "os";
48402
- import { join as join19 } from "path";
48834
+ import { join as join20 } from "path";
48403
48835
  init_errors();
48404
48836
  init_paths();
48405
48837
  var LABEL = "dev.shipers.multi.daemon";
48406
48838
  var HOME4 = homedir2();
48407
- var PLIST_PATH = join19(HOME4, "Library", "LaunchAgents", `${LABEL}.plist`);
48408
- var SYSTEMD_UNIT_PATH = join19(HOME4, ".config", "systemd", "user", "multi-daemon.service");
48839
+ var PLIST_PATH = join20(HOME4, "Library", "LaunchAgents", `${LABEL}.plist`);
48840
+ var SYSTEMD_UNIT_PATH = join20(HOME4, ".config", "systemd", "user", "multi-daemon.service");
48409
48841
  var isMac = () => platform() === "darwin";
48410
48842
  var isLinux = () => platform() === "linux";
48411
48843
  var isRunningPid = (pid) => {
@@ -48418,7 +48850,7 @@ var isRunningPid = (pid) => {
48418
48850
  };
48419
48851
  var readPid = () => {
48420
48852
  try {
48421
- if (!existsSync18(PID_PATH))
48853
+ if (!existsSync19(PID_PATH))
48422
48854
  return null;
48423
48855
  const n = Number(readFileSync13(PID_PATH, "utf8").trim());
48424
48856
  return Number.isFinite(n) && n > 0 ? n : null;
@@ -48446,10 +48878,10 @@ function stableCandidates(fromWhich) {
48446
48878
  const home = homedir2();
48447
48879
  return [
48448
48880
  fromWhich,
48449
- join19(home, ".bun/bin/dayline"),
48881
+ join20(home, ".bun/bin/dayline"),
48450
48882
  "/opt/homebrew/bin/dayline",
48451
48883
  "/usr/local/bin/dayline",
48452
- join19(home, ".npm-global/bin/dayline")
48884
+ join20(home, ".npm-global/bin/dayline")
48453
48885
  ];
48454
48886
  }
48455
48887
  var resolveBinary = exports_Effect.fn("service.resolveBinary")(function* () {
@@ -48457,7 +48889,7 @@ var resolveBinary = exports_Effect.fn("service.resolveBinary")(function* () {
48457
48889
  yield* exports_Effect.promise(() => proc.exited);
48458
48890
  const out = yield* exports_Effect.promise(() => new Response(proc.stdout).text());
48459
48891
  const fromWhich = out.trim();
48460
- const stable = pickStableBinary(stableCandidates(fromWhich), existsSync18);
48892
+ const stable = pickStableBinary(stableCandidates(fromWhich), existsSync19);
48461
48893
  if (stable)
48462
48894
  return stable;
48463
48895
  console.log("Installing @shipers-dev/dayline globally so the service has a stable binary…");
@@ -48469,7 +48901,7 @@ var resolveBinary = exports_Effect.fn("service.resolveBinary")(function* () {
48469
48901
  });
48470
48902
  yield* exports_Effect.promise(() => add6.exited);
48471
48903
  }
48472
- const afterInstall = pickStableBinary(stableCandidates(""), existsSync18);
48904
+ const afterInstall = pickStableBinary(stableCandidates(""), existsSync19);
48473
48905
  if (afterInstall)
48474
48906
  return afterInstall;
48475
48907
  return yield* exports_Effect.fail(new DaemonError({
@@ -48493,7 +48925,7 @@ var buildPlist = (binary, env) => {
48493
48925
  const envEntries = Object.entries(env).map(([k, v]) => ` <key>${k}</key>
48494
48926
  <string>${escapeXml(v)}</string>`).join(`
48495
48927
  `);
48496
- const logDir = join19(DAYLINE_DIR, "logs");
48928
+ const logDir = join20(DAYLINE_DIR, "logs");
48497
48929
  return `<?xml version="1.0" encoding="UTF-8"?>
48498
48930
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
48499
48931
  <plist version="1.0">
@@ -48512,9 +48944,9 @@ var buildPlist = (binary, env) => {
48512
48944
  <key>WorkingDirectory</key>
48513
48945
  <string>${escapeXml(HOME4)}</string>
48514
48946
  <key>StandardOutPath</key>
48515
- <string>${escapeXml(join19(logDir, "launchd.out.log"))}</string>
48947
+ <string>${escapeXml(join20(logDir, "launchd.out.log"))}</string>
48516
48948
  <key>StandardErrorPath</key>
48517
- <string>${escapeXml(join19(logDir, "launchd.err.log"))}</string>
48949
+ <string>${escapeXml(join20(logDir, "launchd.err.log"))}</string>
48518
48950
  <key>EnvironmentVariables</key>
48519
48951
  <dict>
48520
48952
  ${envEntries}
@@ -48572,7 +49004,7 @@ var installMac = exports_Effect.fn("service.installMac")(function* (binary) {
48572
49004
  const fs3 = yield* FileSystem;
48573
49005
  const env = collectServiceEnv();
48574
49006
  const plist = buildPlist(binary, env);
48575
- yield* fs3.mkdirp(join19(DAYLINE_DIR, "logs"));
49007
+ yield* fs3.mkdirp(join20(DAYLINE_DIR, "logs"));
48576
49008
  yield* fs3.writeText(PLIST_PATH, plist);
48577
49009
  yield* run6("launchctl", ["unload", PLIST_PATH]).pipe(exports_Effect.ignore);
48578
49010
  yield* run6("launchctl", ["load", "-w", PLIST_PATH]);
@@ -48583,7 +49015,7 @@ var installLinux = exports_Effect.fn("service.installLinux")(function* (binary)
48583
49015
  const fs3 = yield* FileSystem;
48584
49016
  const env = collectServiceEnv();
48585
49017
  const unit = buildSystemdUnit(binary, env);
48586
- yield* fs3.mkdirp(join19(DAYLINE_DIR, "logs"));
49018
+ yield* fs3.mkdirp(join20(DAYLINE_DIR, "logs"));
48587
49019
  yield* fs3.writeText(SYSTEMD_UNIT_PATH, unit);
48588
49020
  yield* run6("systemctl", ["--user", "daemon-reload"]);
48589
49021
  yield* run6("systemctl", ["--user", "enable", "--now", "multi-daemon.service"]);
@@ -48593,7 +49025,7 @@ var installLinux = exports_Effect.fn("service.installLinux")(function* (binary)
48593
49025
  });
48594
49026
  var uninstallMac = exports_Effect.fn("service.uninstallMac")(function* () {
48595
49027
  const fs3 = yield* FileSystem;
48596
- if (existsSync18(PLIST_PATH)) {
49028
+ if (existsSync19(PLIST_PATH)) {
48597
49029
  yield* run6("launchctl", ["unload", PLIST_PATH]).pipe(exports_Effect.ignore);
48598
49030
  yield* fs3.remove(PLIST_PATH);
48599
49031
  console.log(`\uD83D\uDDD1 Removed ${PLIST_PATH}`);
@@ -48603,7 +49035,7 @@ var uninstallMac = exports_Effect.fn("service.uninstallMac")(function* () {
48603
49035
  });
48604
49036
  var uninstallLinux = exports_Effect.fn("service.uninstallLinux")(function* () {
48605
49037
  const fs3 = yield* FileSystem;
48606
- if (existsSync18(SYSTEMD_UNIT_PATH)) {
49038
+ if (existsSync19(SYSTEMD_UNIT_PATH)) {
48607
49039
  yield* run6("systemctl", ["--user", "disable", "--now", "multi-daemon.service"]).pipe(exports_Effect.ignore);
48608
49040
  yield* fs3.remove(SYSTEMD_UNIT_PATH);
48609
49041
  yield* run6("systemctl", ["--user", "daemon-reload"]).pipe(exports_Effect.ignore);
@@ -48632,7 +49064,7 @@ var serviceCmd = exports_Effect.fn("serviceCmd")(function* (sub) {
48632
49064
  }
48633
49065
  case "start": {
48634
49066
  if (isMac()) {
48635
- if (!existsSync18(PLIST_PATH)) {
49067
+ if (!existsSync19(PLIST_PATH)) {
48636
49068
  return yield* exports_Effect.fail(new DaemonError({
48637
49069
  message: "Not installed. Run: dayline service install"
48638
49070
  }));
@@ -48658,7 +49090,7 @@ var serviceCmd = exports_Effect.fn("serviceCmd")(function* (sub) {
48658
49090
  }
48659
49091
  case "status":
48660
49092
  case undefined: {
48661
- const installed = isMac() ? existsSync18(PLIST_PATH) : existsSync18(SYSTEMD_UNIT_PATH);
49093
+ const installed = isMac() ? existsSync19(PLIST_PATH) : existsSync19(SYSTEMD_UNIT_PATH);
48662
49094
  const pid = readPid();
48663
49095
  const running3 = pid !== null && isRunningPid(pid);
48664
49096
  console.log(`Service: ${isMac() ? "launchd" : "systemd --user"}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipers-dev/dayline",
3
- "version": "0.99.1",
3
+ "version": "0.100.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "dayline": "./dist/index.js"
@@ -25,5 +25,12 @@
25
25
  },
26
26
  "devDependencies": {
27
27
  "@multi/lib": "workspace:*"
28
+ },
29
+ "optionalDependencies": {
30
+ "@shipers-dev/dayline-chat-peer-darwin-arm64": "0.1.0",
31
+ "@shipers-dev/dayline-chat-peer-darwin-x64": "0.1.0",
32
+ "@shipers-dev/dayline-chat-peer-linux-x64": "0.1.0",
33
+ "@shipers-dev/dayline-chat-peer-linux-arm64": "0.1.0",
34
+ "@shipers-dev/dayline-chat-peer-win32-x64": "0.1.0"
28
35
  }
29
36
  }