@getpochi/cli 0.5.22 → 0.5.24

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/cli.js +481 -90
  2. package/package.json +2 -1
package/dist/cli.js CHANGED
@@ -62,6 +62,337 @@ var __export = (target, all) => {
62
62
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
63
63
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
64
64
 
65
+ // ../../node_modules/minimal-polyfills/Map.js
66
+ var require_Map = __commonJS((exports) => {
67
+ exports.__esModule = true;
68
+ exports.Polyfill = exports.LightMapImpl = undefined;
69
+ var LightMapImpl = function() {
70
+ function LightMapImpl2() {
71
+ this.record = [];
72
+ }
73
+ LightMapImpl2.prototype.has = function(key) {
74
+ return this.record.map(function(_a) {
75
+ var _key = _a[0];
76
+ return _key;
77
+ }).indexOf(key) >= 0;
78
+ };
79
+ LightMapImpl2.prototype.get = function(key) {
80
+ var entry = this.record.filter(function(_a) {
81
+ var _key = _a[0];
82
+ return _key === key;
83
+ })[0];
84
+ if (entry === undefined) {
85
+ return;
86
+ }
87
+ return entry[1];
88
+ };
89
+ LightMapImpl2.prototype.set = function(key, value2) {
90
+ var entry = this.record.filter(function(_a) {
91
+ var _key = _a[0];
92
+ return _key === key;
93
+ })[0];
94
+ if (entry === undefined) {
95
+ this.record.push([key, value2]);
96
+ } else {
97
+ entry[1] = value2;
98
+ }
99
+ return this;
100
+ };
101
+ LightMapImpl2.prototype["delete"] = function(key) {
102
+ var index = this.record.map(function(_a) {
103
+ var key2 = _a[0];
104
+ return key2;
105
+ }).indexOf(key);
106
+ if (index < 0) {
107
+ return false;
108
+ }
109
+ this.record.splice(index, 1);
110
+ return true;
111
+ };
112
+ LightMapImpl2.prototype.keys = function() {
113
+ return this.record.map(function(_a) {
114
+ var key = _a[0];
115
+ return key;
116
+ });
117
+ };
118
+ return LightMapImpl2;
119
+ }();
120
+ exports.LightMapImpl = LightMapImpl;
121
+ exports.Polyfill = typeof Map !== "undefined" ? Map : LightMapImpl;
122
+ });
123
+
124
+ // ../../node_modules/minimal-polyfills/WeakMap.js
125
+ var require_WeakMap = __commonJS((exports) => {
126
+ exports.__esModule = true;
127
+ exports.Polyfill = undefined;
128
+ var Map_1 = require_Map();
129
+ exports.Polyfill = typeof WeakMap !== "undefined" ? WeakMap : Map_1.Polyfill;
130
+ });
131
+
132
+ // ../../node_modules/run-exclusive/lib/runExclusive.js
133
+ var require_runExclusive = __commonJS((exports) => {
134
+ var __spreadArrays = exports && exports.__spreadArrays || function() {
135
+ for (var s = 0, i = 0, il = arguments.length;i < il; i++)
136
+ s += arguments[i].length;
137
+ for (var r = Array(s), k = 0, i = 0;i < il; i++)
138
+ for (var a = arguments[i], j = 0, jl = a.length;j < jl; j++, k++)
139
+ r[k] = a[j];
140
+ return r;
141
+ };
142
+ exports.__esModule = true;
143
+ exports.buildMethodCb = exports.buildCb = exports.getPrComplete = exports.isRunning = exports.cancelAllQueuedCalls = exports.getQueuedCallCount = exports.buildMethod = exports.build = exports.createGroupRef = undefined;
144
+ var WeakMap_1 = require_WeakMap();
145
+ var ExecQueue = function() {
146
+ function ExecQueue2() {
147
+ this.queuedCalls = [];
148
+ this.isRunning = false;
149
+ this.prComplete = Promise.resolve();
150
+ }
151
+ ExecQueue2.prototype.cancelAllQueuedCalls = function() {
152
+ var n;
153
+ this.queuedCalls.splice(0, n = this.queuedCalls.length);
154
+ return n;
155
+ };
156
+ return ExecQueue2;
157
+ }();
158
+ var globalContext = {};
159
+ var clusters = new WeakMap_1.Polyfill;
160
+ function getOrCreateExecQueue(context, groupRef) {
161
+ var execQueueByGroup = clusters.get(context);
162
+ if (!execQueueByGroup) {
163
+ execQueueByGroup = new WeakMap_1.Polyfill;
164
+ clusters.set(context, execQueueByGroup);
165
+ }
166
+ var execQueue = execQueueByGroup.get(groupRef);
167
+ if (!execQueue) {
168
+ execQueue = new ExecQueue;
169
+ execQueueByGroup.set(groupRef, execQueue);
170
+ }
171
+ return execQueue;
172
+ }
173
+ function createGroupRef() {
174
+ return new Array(0);
175
+ }
176
+ exports.createGroupRef = createGroupRef;
177
+ function build() {
178
+ var inputs = [];
179
+ for (var _i = 0;_i < arguments.length; _i++) {
180
+ inputs[_i] = arguments[_i];
181
+ }
182
+ switch (inputs.length) {
183
+ case 1:
184
+ return buildFnPromise(true, createGroupRef(), inputs[0]);
185
+ case 2:
186
+ return buildFnPromise(true, inputs[0], inputs[1]);
187
+ }
188
+ }
189
+ exports.build = build;
190
+ function buildMethod() {
191
+ var inputs = [];
192
+ for (var _i = 0;_i < arguments.length; _i++) {
193
+ inputs[_i] = arguments[_i];
194
+ }
195
+ switch (inputs.length) {
196
+ case 1:
197
+ return buildFnPromise(false, createGroupRef(), inputs[0]);
198
+ case 2:
199
+ return buildFnPromise(false, inputs[0], inputs[1]);
200
+ }
201
+ }
202
+ exports.buildMethod = buildMethod;
203
+ function getQueuedCallCount(runExclusiveFunction, classInstanceObject) {
204
+ var execQueue = getExecQueueByFunctionAndContext(runExclusiveFunction, classInstanceObject);
205
+ return execQueue ? execQueue.queuedCalls.length : 0;
206
+ }
207
+ exports.getQueuedCallCount = getQueuedCallCount;
208
+ function cancelAllQueuedCalls(runExclusiveFunction, classInstanceObject) {
209
+ var execQueue = getExecQueueByFunctionAndContext(runExclusiveFunction, classInstanceObject);
210
+ return execQueue ? execQueue.cancelAllQueuedCalls() : 0;
211
+ }
212
+ exports.cancelAllQueuedCalls = cancelAllQueuedCalls;
213
+ function isRunning(runExclusiveFunction, classInstanceObject) {
214
+ var execQueue = getExecQueueByFunctionAndContext(runExclusiveFunction, classInstanceObject);
215
+ return execQueue ? execQueue.isRunning : false;
216
+ }
217
+ exports.isRunning = isRunning;
218
+ function getPrComplete(runExclusiveFunction, classInstanceObject) {
219
+ var execQueue = getExecQueueByFunctionAndContext(runExclusiveFunction, classInstanceObject);
220
+ return execQueue ? execQueue.prComplete : Promise.resolve();
221
+ }
222
+ exports.getPrComplete = getPrComplete;
223
+ var groupByRunExclusiveFunction = new WeakMap_1.Polyfill;
224
+ function getExecQueueByFunctionAndContext(runExclusiveFunction, context) {
225
+ if (context === undefined) {
226
+ context = globalContext;
227
+ }
228
+ var groupRef = groupByRunExclusiveFunction.get(runExclusiveFunction);
229
+ if (!groupRef) {
230
+ throw Error("Not a run exclusiveFunction");
231
+ }
232
+ var execQueueByGroup = clusters.get(context);
233
+ if (!execQueueByGroup) {
234
+ return;
235
+ }
236
+ return execQueueByGroup.get(groupRef);
237
+ }
238
+ function buildFnPromise(isGlobal, groupRef, fun) {
239
+ var execQueue;
240
+ var runExclusiveFunction = function() {
241
+ var _this = this;
242
+ var inputs = [];
243
+ for (var _i = 0;_i < arguments.length; _i++) {
244
+ inputs[_i] = arguments[_i];
245
+ }
246
+ if (!isGlobal) {
247
+ if (!(this instanceof Object)) {
248
+ throw new Error("Run exclusive, <this> should be an object");
249
+ }
250
+ execQueue = getOrCreateExecQueue(this, groupRef);
251
+ }
252
+ return new Promise(function(resolve, reject) {
253
+ var onPrCompleteResolve;
254
+ execQueue.prComplete = new Promise(function(resolve2) {
255
+ return onPrCompleteResolve = function() {
256
+ return resolve2();
257
+ };
258
+ });
259
+ var onComplete = function(result2) {
260
+ onPrCompleteResolve();
261
+ execQueue.isRunning = false;
262
+ if (execQueue.queuedCalls.length) {
263
+ execQueue.queuedCalls.shift()();
264
+ }
265
+ if ("data" in result2) {
266
+ resolve(result2.data);
267
+ } else {
268
+ reject(result2.reason);
269
+ }
270
+ };
271
+ (function callee() {
272
+ var _this2 = this;
273
+ var inputs2 = [];
274
+ for (var _i2 = 0;_i2 < arguments.length; _i2++) {
275
+ inputs2[_i2] = arguments[_i2];
276
+ }
277
+ if (execQueue.isRunning) {
278
+ execQueue.queuedCalls.push(function() {
279
+ return callee.apply(_this2, inputs2);
280
+ });
281
+ return;
282
+ }
283
+ execQueue.isRunning = true;
284
+ try {
285
+ fun.apply(this, inputs2).then(function(data) {
286
+ return onComplete({ data });
287
+ })["catch"](function(reason) {
288
+ return onComplete({ reason });
289
+ });
290
+ } catch (error40) {
291
+ onComplete({ reason: error40 });
292
+ }
293
+ }).apply(_this, inputs);
294
+ });
295
+ };
296
+ if (isGlobal) {
297
+ execQueue = getOrCreateExecQueue(globalContext, groupRef);
298
+ }
299
+ groupByRunExclusiveFunction.set(runExclusiveFunction, groupRef);
300
+ return runExclusiveFunction;
301
+ }
302
+ function buildCb() {
303
+ var inputs = [];
304
+ for (var _i = 0;_i < arguments.length; _i++) {
305
+ inputs[_i] = arguments[_i];
306
+ }
307
+ switch (inputs.length) {
308
+ case 1:
309
+ return buildFnCallback(true, createGroupRef(), inputs[0]);
310
+ case 2:
311
+ return buildFnCallback(true, inputs[0], inputs[1]);
312
+ }
313
+ }
314
+ exports.buildCb = buildCb;
315
+ function buildMethodCb() {
316
+ var inputs = [];
317
+ for (var _i = 0;_i < arguments.length; _i++) {
318
+ inputs[_i] = arguments[_i];
319
+ }
320
+ switch (inputs.length) {
321
+ case 1:
322
+ return buildFnCallback(false, createGroupRef(), inputs[0]);
323
+ case 2:
324
+ return buildFnCallback(false, inputs[0], inputs[1]);
325
+ }
326
+ }
327
+ exports.buildMethodCb = buildMethodCb;
328
+ function buildFnCallback(isGlobal, groupRef, fun) {
329
+ var execQueue;
330
+ var runExclusiveFunction = function() {
331
+ var _this = this;
332
+ var inputs = [];
333
+ for (var _i = 0;_i < arguments.length; _i++) {
334
+ inputs[_i] = arguments[_i];
335
+ }
336
+ if (!isGlobal) {
337
+ if (!(this instanceof Object)) {
338
+ throw new Error("Run exclusive, <this> should be an object");
339
+ }
340
+ execQueue = getOrCreateExecQueue(this, groupRef);
341
+ }
342
+ var callback = undefined;
343
+ if (inputs.length && typeof inputs[inputs.length - 1] === "function") {
344
+ callback = inputs.pop();
345
+ }
346
+ var onPrCompleteResolve;
347
+ execQueue.prComplete = new Promise(function(resolve) {
348
+ return onPrCompleteResolve = function() {
349
+ return resolve();
350
+ };
351
+ });
352
+ var onComplete = function() {
353
+ var inputs2 = [];
354
+ for (var _i2 = 0;_i2 < arguments.length; _i2++) {
355
+ inputs2[_i2] = arguments[_i2];
356
+ }
357
+ onPrCompleteResolve();
358
+ execQueue.isRunning = false;
359
+ if (execQueue.queuedCalls.length) {
360
+ execQueue.queuedCalls.shift()();
361
+ }
362
+ if (callback) {
363
+ callback.apply(_this, inputs2);
364
+ }
365
+ };
366
+ onComplete.hasCallback = !!callback;
367
+ (function callee() {
368
+ var _this2 = this;
369
+ var inputs2 = [];
370
+ for (var _i2 = 0;_i2 < arguments.length; _i2++) {
371
+ inputs2[_i2] = arguments[_i2];
372
+ }
373
+ if (execQueue.isRunning) {
374
+ execQueue.queuedCalls.push(function() {
375
+ return callee.apply(_this2, inputs2);
376
+ });
377
+ return;
378
+ }
379
+ execQueue.isRunning = true;
380
+ try {
381
+ fun.apply(this, __spreadArrays(inputs2, [onComplete]));
382
+ } catch (error40) {
383
+ error40.message += " ( This exception should not have been thrown, miss use of run-exclusive buildCb )";
384
+ throw error40;
385
+ }
386
+ }).apply(this, inputs);
387
+ };
388
+ if (isGlobal) {
389
+ execQueue = getOrCreateExecQueue(globalContext, groupRef);
390
+ }
391
+ groupByRunExclusiveFunction.set(runExclusiveFunction, groupRef);
392
+ return runExclusiveFunction;
393
+ }
394
+ });
395
+
65
396
  // ../../node_modules/node-machine-id/dist/index.js
66
397
  var require_dist = __commonJS((exports, module) => {
67
398
  (function(t2, n2) {
@@ -74201,10 +74532,10 @@ var init_debug_info = __esm(() => {
74201
74532
  MutableDebugInfo = exports_Schema2.mutable(DebugInfo);
74202
74533
  });
74203
74534
 
74204
- // ../../node_modules/@livestore/utils/node_modules/nanoid/url-alphabet/index.js
74535
+ // ../../node_modules/nanoid/url-alphabet/index.js
74205
74536
  var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
74206
74537
 
74207
- // ../../node_modules/@livestore/utils/node_modules/nanoid/index.js
74538
+ // ../../node_modules/nanoid/index.js
74208
74539
  import { webcrypto as crypto4 } from "node:crypto";
74209
74540
  function fillPool(bytes) {
74210
74541
  if (!pool || pool.length < bytes) {
@@ -270967,7 +271298,7 @@ var require_document = __commonJS((exports, module) => {
270967
271298
  Document.default = Document;
270968
271299
  });
270969
271300
 
270970
- // ../../node_modules/nanoid/non-secure/index.cjs
271301
+ // ../../node_modules/postcss/node_modules/nanoid/non-secure/index.cjs
270971
271302
  var require_non_secure = __commonJS((exports, module) => {
270972
271303
  var urlAlphabet2 = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
270973
271304
  var customAlphabet = (alphabet, defaultSize = 21) => {
@@ -327368,6 +327699,9 @@ var ModelOptions = v4_default.object({
327368
327699
  contextWindow: v4_default.number().optional(),
327369
327700
  useToolCallMiddleware: v4_default.boolean().optional()
327370
327701
  });
327702
+ // ../common/src/vendor/base.ts
327703
+ var runExclusive = __toESM(require_runExclusive(), 1);
327704
+
327371
327705
  // ../common/src/configuration/config-manager.ts
327372
327706
  import * as fs from "node:fs";
327373
327707
  import * as fsPromise from "node:fs/promises";
@@ -345084,18 +345418,20 @@ class VendorBase {
345084
345418
  vendorId;
345085
345419
  constructor(vendorId) {
345086
345420
  this.vendorId = vendorId;
345421
+ this.getCredentials = this.getCredentials.bind(this);
345422
+ this.getUserInfo = this.getUserInfo.bind(this);
345087
345423
  }
345088
- getCredentials = async () => {
345424
+ getCredentials = runExclusive.buildMethod(async () => {
345089
345425
  const { credentials } = this.getVendorConfig();
345090
345426
  const newCredentials = await this.renewCredentials(credentials);
345091
345427
  if (credentials !== newCredentials) {
345092
- updateVendorConfig(this.vendorId, {
345428
+ await updateVendorConfig(this.vendorId, {
345093
345429
  credentials: newCredentials
345094
345430
  });
345095
345431
  }
345096
345432
  return newCredentials;
345097
- };
345098
- async getUserInfo() {
345433
+ });
345434
+ getUserInfo = runExclusive.buildMethod(async () => {
345099
345435
  const { user } = this.getVendorConfig();
345100
345436
  if (user)
345101
345437
  return user;
@@ -345106,7 +345442,7 @@ class VendorBase {
345106
345442
  credentials
345107
345443
  });
345108
345444
  return newUser;
345109
- }
345445
+ });
345110
345446
  logout() {
345111
345447
  return updateVendorConfig(this.vendorId, null);
345112
345448
  }
@@ -346898,7 +347234,7 @@ var buildCustomFetchImpl = () => {
346898
347234
  var authClient = createAuthClient2();
346899
347235
  function isJWTExpiring(jwt2) {
346900
347236
  const { exp } = decodeJwt(jwt2);
346901
- return exp ? Date.now() >= (exp - 120) * 1000 : true;
347237
+ return exp ? Date.now() >= (exp - 5 * 60) * 1000 : true;
346902
347238
  }
346903
347239
 
346904
347240
  // ../vendor-pochi/src/node.ts
@@ -351974,7 +352310,7 @@ var {
351974
352310
  // package.json
351975
352311
  var package_default = {
351976
352312
  name: "@getpochi/cli",
351977
- version: "0.5.22",
352313
+ version: "0.5.24",
351978
352314
  type: "module",
351979
352315
  bin: {
351980
352316
  pochi: "src/cli.ts"
@@ -352000,6 +352336,7 @@ var package_default = {
352000
352336
  "@getpochi/vendor-pochi": "workspace:*",
352001
352337
  "@livestore/adapter-node": "catalog:",
352002
352338
  "@livestore/livestore": "catalog:",
352339
+ "@livestore/utils": "catalog:",
352003
352340
  "@livestore/wa-sqlite": "catalog:",
352004
352341
  "@livestore/sync-cf": "catalog:",
352005
352342
  "@preact/signals-core": "^1.6.2",
@@ -365354,7 +365691,7 @@ var createStorePromise = async ({ signal, otelOptions, ...options4 }) => exports
365354
365691
  return yield* createStore2({ ...options4 }).pipe(exports_Scope.extend(scope5));
365355
365692
  }).pipe(exports_Effect2.withSpan("createStore", {
365356
365693
  attributes: { storeId: options4.storeId, disableDevtools: options4.disableDevtools }
365357
- }), provideOtel(omitUndefineds({ parentSpanContext: otelOptions?.rootSpanContext, otelTracer: otelOptions?.tracer })), exports_Effect2.tapCauseLogPretty, exports_Effect2.annotateLogs({ thread: "window" }), exports_Effect2.provide(exports_Logger2.prettyWithThread("window")), exports_Logger2.withMinimumLogLevel(exports_LogLevel.Debug), exports_Effect2.runPromise);
365694
+ }), provideOtel(omitUndefineds({ parentSpanContext: otelOptions?.rootSpanContext, otelTracer: otelOptions?.tracer })), exports_Effect2.tapCauseLogPretty, exports_Effect2.annotateLogs({ thread: "window" }), exports_Effect2.provide(exports_Logger2.prettyWithThread("window")), exports_Logger2.withMinimumLogLevel(exports_LogLevel.Error), exports_Effect2.runPromise);
365358
365695
  var createStore2 = ({ schema: schema5, adapter: adapter4, storeId, context: context15 = {}, boot, batchUpdates, disableDevtools, onBootStatus, shutdownDeferred, params: params2, debug: debug3, confirmUnsavedChanges = true, syncPayload }) => exports_Effect2.gen(function* () {
365359
365696
  const lifetimeScope = yield* exports_Scope.make();
365360
365697
  yield* validateStoreId(storeId);
@@ -386962,7 +387299,7 @@ ${followUpText}`,
386962
387299
  if (part.type === "tool-attemptCompletion") {
386963
387300
  const { result: result2 = "" } = part.input || {};
386964
387301
  const text12 = `${source_default2.bold(source_default2.green("\uD83C\uDF89 Task Completed"))}
386965
- ${source_default2.dim("└─")} ${result2}`;
387302
+ ${result2}`;
386966
387303
  return {
386967
387304
  text: text12,
386968
387305
  stop: "stopAndPersist",
@@ -387064,6 +387401,9 @@ function renderSubtaskMessages(messages2) {
387064
387401
  return output2;
387065
387402
  }
387066
387403
 
387404
+ // src/task/cmd.ts
387405
+ init_effect();
387406
+
387067
387407
  // src/livekit/store.ts
387068
387408
  import os10 from "node:os";
387069
387409
  import path21 from "node:path";
@@ -387099,10 +387439,70 @@ async function getPochiCredentials3() {
387099
387439
  const credentials = await pochi.getCredentials().catch(() => null);
387100
387440
  return credentials;
387101
387441
  }
387442
+ // src/livekit/chat.node.ts
387443
+ class NodeChatState {
387444
+ signal = {
387445
+ status: d("ready"),
387446
+ error: d(undefined),
387447
+ messages: d([])
387448
+ };
387449
+ get status() {
387450
+ return this.signal.status.value;
387451
+ }
387452
+ set status(chatStatus) {
387453
+ this.signal.status.value = chatStatus;
387454
+ }
387455
+ get error() {
387456
+ return this.signal.error.value;
387457
+ }
387458
+ set error(error44) {
387459
+ this.signal.error.value = error44;
387460
+ }
387461
+ get messages() {
387462
+ return this.signal.messages.value;
387463
+ }
387464
+ set messages(messages2) {
387465
+ this.signal.messages.value = messages2;
387466
+ }
387467
+ constructor(initialMessages = []) {
387468
+ this.messages = initialMessages;
387469
+ }
387470
+ pushMessage = (message) => {
387471
+ this.messages = this.messages.concat(message);
387472
+ };
387473
+ popMessage = () => {
387474
+ this.messages = this.messages.slice(0, -1);
387475
+ };
387476
+ replaceMessage = (index3, message) => {
387477
+ this.messages = [
387478
+ ...this.messages.slice(0, index3),
387479
+ this.snapshot(message),
387480
+ ...this.messages.slice(index3 + 1)
387481
+ ];
387482
+ };
387483
+ snapshot = (value9) => structuredClone(value9);
387484
+ }
387102
387485
 
387486
+ class Chat extends AbstractChat {
387487
+ constructor({ messages: messages2, ...init4 }) {
387488
+ const state2 = new NodeChatState(messages2);
387489
+ super({ ...init4, state: state2 });
387490
+ }
387491
+ appendOrReplaceMessage(message) {
387492
+ const index3 = this.state.messages.findIndex((m13) => m13.id === message.id);
387493
+ if (index3 === -1) {
387494
+ this.state.pushMessage(message);
387495
+ } else {
387496
+ this.state.replaceMessage(index3, message);
387497
+ }
387498
+ }
387499
+ getState() {
387500
+ return this.state;
387501
+ }
387502
+ }
387103
387503
  // src/task/list.ts
387104
387504
  function registerTaskListCommand(taskCommand) {
387105
- taskCommand.command("list", { isDefault: true }).description("List all recent tasks, showing their status and IDs.").option("-n, --limit <number>", "The maximum number of tasks to display.", "10").action(async (options4) => {
387505
+ taskCommand.command("list", { isDefault: true }).description("List all recent tasks, showing their status and IDs.").option("-n, --limit <number>", "The maximum number of tasks to display.", "100").action(async (options4) => {
387106
387506
  const limit = Number.parseInt(options4.limit, 10);
387107
387507
  if (Number.isNaN(limit) || limit <= 0) {
387108
387508
  return taskCommand.error("Limit must be a positive number");
@@ -387119,28 +387519,59 @@ function registerTaskListCommand(taskCommand) {
387119
387519
  console.log(source_default2.white(` pochi -p "<your task description>"`));
387120
387520
  return;
387121
387521
  }
387122
- console.log(source_default2.bold(`
387123
- Recent Tasks (${tasks.length}):`));
387124
- console.log();
387125
- for (const task of tasks) {
387126
- const statusColor = getStatusColor(task.status);
387127
- const title = task.title || task.id.substring(0, 8);
387128
- const timeAgo = getTimeAgo(task.updatedAt);
387129
- const shareInfo = task.shareId ? source_default2.blue(` [${task.shareId.substring(0, 8)}]`) : "";
387130
- console.log(`${statusColor(getStatusIcon(task.status))} ${source_default2.bold(title)}${shareInfo} ${source_default2.gray(`(${timeAgo})`)}`);
387131
- console.log(source_default2.gray(` ID: ${task.id}`));
387132
- if (task.shareId) {
387133
- console.log(source_default2.gray(` Share: https://app.getpochi.com/share/${task.shareId}`));
387522
+ const taskId = await esm_default3({
387523
+ message: `Showing the last ${source_default2.bold(limit)} tasks:`,
387524
+ choices: tasks.map((task2) => ({
387525
+ name: formatTaskForSelect(task2),
387526
+ short: task2.id,
387527
+ value: task2.id,
387528
+ description: formatTaskDescription(task2),
387529
+ disabled: !task2.shareId
387530
+ })),
387531
+ pageSize: 10,
387532
+ theme: {
387533
+ style: {
387534
+ description: (text12) => text12
387535
+ },
387536
+ helpMode: "never",
387537
+ indexMode: "number"
387134
387538
  }
387135
- console.log();
387539
+ });
387540
+ const task = tasks.find((t8) => t8.id === taskId);
387541
+ if (task) {
387542
+ console.log(`
387543
+ ${formatTaskForSelect(task)}
387544
+ ${formatTaskDescription(task, false)}`);
387136
387545
  }
387137
387546
  } catch (error44) {
387138
- return taskCommand.error(`Failed to list tasks: ${error44 instanceof Error ? error44.message : "Unknown error"}`);
387547
+ if (error44 instanceof Error && error44.message.includes("SIGINT")) {} else {
387548
+ return taskCommand.error(`Failed to list tasks: ${error44 instanceof Error ? error44.message : "Unknown error"}`);
387549
+ }
387139
387550
  } finally {
387140
387551
  await store.shutdown();
387141
387552
  }
387142
387553
  });
387143
387554
  }
387555
+ function formatTaskForSelect(task) {
387556
+ const statusColor = getStatusColor(task.status);
387557
+ const title = clipTitle(task.title || task.id.substring(0, 8), 75);
387558
+ return `${statusColor(getStatusIcon(task.status))} ${source_default2.bold(title)}`;
387559
+ }
387560
+ function formatTaskDescription(task, includeID = true) {
387561
+ const timeAgo = getTimeAgo(task.updatedAt);
387562
+ let description = "";
387563
+ if (includeID) {
387564
+ description += `
387565
+ ID: ${source_default2.cyan(task.id)}`;
387566
+ }
387567
+ description += `
387568
+ Last Updated: ${source_default2.gray(timeAgo)}`;
387569
+ if (task.shareId) {
387570
+ description += `
387571
+ Share URL: ${source_default2.underline(`https://app.getpochi.com/share/${task.shareId}`)}`;
387572
+ }
387573
+ return description;
387574
+ }
387144
387575
  function getStatusColor(status3) {
387145
387576
  switch (status3) {
387146
387577
  case "completed":
@@ -387185,29 +387616,48 @@ function getTimeAgo(date8) {
387185
387616
  return `${diffDays}d ago`;
387186
387617
  return date8.toLocaleDateString();
387187
387618
  }
387619
+ function clipTitle(title, maxLength2) {
387620
+ if (title.length <= maxLength2)
387621
+ return title;
387622
+ return `${title.substring(0, maxLength2 - 3)}...`;
387623
+ }
387188
387624
 
387189
387625
  // src/task/share.ts
387190
387626
  function registerTaskShareCommand(taskCommand) {
387191
387627
  taskCommand.command("get-share-url").description("Get the shareable URL for a specific task by its ID.").argument("<task-id>", "The ID of the task to get the share URL for.").action(async (taskId) => {
387192
387628
  const store = await createStore4(process.cwd());
387193
- const shareId = store.query(exports_livestore.queries.makeTaskQuery(taskId))?.shareId;
387629
+ const { shareId } = store.query(exports_livestore.queries.makeTaskQuery(taskId)) || {};
387194
387630
  if (shareId) {
387195
387631
  const shareUrl = `https://app.getpochi.com/share/${shareId}`;
387196
387632
  console.log(`${source_default2.bold("\uD83D\uDCCE Share URL:")} ${source_default2.underline(shareUrl)}`);
387197
387633
  } else {
387198
387634
  console.log(source_default2.red("❌ No share URL found for this task"));
387199
387635
  }
387200
- store.shutdown();
387636
+ await store.shutdown();
387201
387637
  });
387202
387638
  }
387203
387639
 
387204
387640
  // src/task/cmd.ts
387205
387641
  function registerTaskCommand(program5) {
387206
387642
  const taskCommand = program5.command("task").description("Manage and interact with tasks.").addHelpCommand(true);
387643
+ taskCommand.hook("preAction", waitForSync);
387207
387644
  registerTaskListCommand(taskCommand);
387208
387645
  registerTaskShareCommand(taskCommand);
387209
387646
  return taskCommand;
387210
387647
  }
387648
+ async function waitForSync() {
387649
+ const store = await createStore4(process.cwd());
387650
+ await exports_Effect2.gen(function* (_8) {
387651
+ while (true) {
387652
+ const nextChange = store.syncProcessor.syncState.changes.pipe(exports_Stream2.take(1), exports_Stream2.runCollect, exports_Effect2.as(false));
387653
+ const timeout5 = exports_Effect2.sleep("1 second").pipe(exports_Effect2.as(true));
387654
+ if (yield* exports_Effect2.raceFirst(nextChange, timeout5)) {
387655
+ break;
387656
+ }
387657
+ }
387658
+ }).pipe(exports_Effect2.runPromise);
387659
+ await store.shutdown();
387660
+ }
387211
387661
  // ../livekit/src/task.ts
387212
387662
  function toTaskStatus(message, finishReason) {
387213
387663
  let lastStepStart = -1;
@@ -389860,67 +390310,7 @@ class StepCount {
389860
390310
  return stepToString(this);
389861
390311
  }
389862
390312
  }
389863
- // src/livekit/chat.node.ts
389864
- class NodeChatState {
389865
- signal = {
389866
- status: d("ready"),
389867
- error: d(undefined),
389868
- messages: d([])
389869
- };
389870
- get status() {
389871
- return this.signal.status.value;
389872
- }
389873
- set status(chatStatus) {
389874
- this.signal.status.value = chatStatus;
389875
- }
389876
- get error() {
389877
- return this.signal.error.value;
389878
- }
389879
- set error(error44) {
389880
- this.signal.error.value = error44;
389881
- }
389882
- get messages() {
389883
- return this.signal.messages.value;
389884
- }
389885
- set messages(messages2) {
389886
- this.signal.messages.value = messages2;
389887
- }
389888
- constructor(initialMessages = []) {
389889
- this.messages = initialMessages;
389890
- }
389891
- pushMessage = (message) => {
389892
- this.messages = this.messages.concat(message);
389893
- };
389894
- popMessage = () => {
389895
- this.messages = this.messages.slice(0, -1);
389896
- };
389897
- replaceMessage = (index3, message) => {
389898
- this.messages = [
389899
- ...this.messages.slice(0, index3),
389900
- this.snapshot(message),
389901
- ...this.messages.slice(index3 + 1)
389902
- ];
389903
- };
389904
- snapshot = (value9) => structuredClone(value9);
389905
- }
389906
390313
 
389907
- class Chat extends AbstractChat {
389908
- constructor({ messages: messages2, ...init4 }) {
389909
- const state2 = new NodeChatState(messages2);
389910
- super({ ...init4, state: state2 });
389911
- }
389912
- appendOrReplaceMessage(message) {
389913
- const index3 = this.state.messages.findIndex((m13) => m13.id === message.id);
389914
- if (index3 === -1) {
389915
- this.state.pushMessage(message);
389916
- } else {
389917
- this.state.replaceMessage(index3, message);
389918
- }
389919
- }
389920
- getState() {
389921
- return this.state;
389922
- }
389923
- }
389924
390314
  // src/tools/apply-diff.ts
389925
390315
  import * as fs11 from "node:fs/promises";
389926
390316
  import * as nodePath from "node:path";
@@ -390596,7 +390986,7 @@ function toError2(e11) {
390596
390986
  // package.json
390597
390987
  var package_default2 = {
390598
390988
  name: "@getpochi/cli",
390599
- version: "0.5.22",
390989
+ version: "0.5.24",
390600
390990
  type: "module",
390601
390991
  bin: {
390602
390992
  pochi: "src/cli.ts"
@@ -390622,6 +391012,7 @@ var package_default2 = {
390622
391012
  "@getpochi/vendor-pochi": "workspace:*",
390623
391013
  "@livestore/adapter-node": "catalog:",
390624
391014
  "@livestore/livestore": "catalog:",
391015
+ "@livestore/utils": "catalog:",
390625
391016
  "@livestore/wa-sqlite": "catalog:",
390626
391017
  "@livestore/sync-cf": "catalog:",
390627
391018
  "@preact/signals-core": "^1.6.2",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getpochi/cli",
3
- "version": "0.5.22",
3
+ "version": "0.5.24",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "pochi": "src/cli.ts"
@@ -26,6 +26,7 @@
26
26
  "@getpochi/vendor-pochi": "0.0.1",
27
27
  "@livestore/adapter-node": "0.4.0-dev.7",
28
28
  "@livestore/livestore": "0.4.0-dev.7",
29
+ "@livestore/utils": "0.4.0-dev.7",
29
30
  "@livestore/wa-sqlite": "0.4.0-dev.7",
30
31
  "@livestore/sync-cf": "0.4.0-dev.7",
31
32
  "@preact/signals-core": "^1.6.2",