@moxt-ai/mobius 0.0.140 → 0.0.141

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -3381,7 +3381,7 @@ var program = new Command();
3381
3381
  // package.json
3382
3382
  var package_default = {
3383
3383
  name: "@moxt-ai/mobius",
3384
- version: "0.0.140",
3384
+ version: "0.0.141",
3385
3385
  description: "Mobius CLI for pairing and running local AI agent services.",
3386
3386
  type: "module",
3387
3387
  bin: {
@@ -42441,6 +42441,69 @@ function errorMessage(value) {
42441
42441
  function messageSize(message) {
42442
42442
  return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
42443
42443
  }
42444
+ var SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT = Math.floor(SESSION_HISTORY_CHARACTER_LIMIT / 2);
42445
+ function fitActivity(activity2, maximumCharacters) {
42446
+ const truncate5 = (limit) => ({
42447
+ ...activity2,
42448
+ input: bounded(activity2.input, limit),
42449
+ locations: activity2.locations.map((location) => bounded(location, Math.max(1, limit))),
42450
+ name: bounded(activity2.name, limit),
42451
+ output: bounded(activity2.output, limit),
42452
+ title: bounded(activity2.title, limit),
42453
+ toolKind: bounded(activity2.toolKind, limit)
42454
+ });
42455
+ let minimum = 1;
42456
+ let maximum = 1e5;
42457
+ let fitted = truncate5(0);
42458
+ while (minimum <= maximum) {
42459
+ const limit = Math.floor((minimum + maximum) / 2);
42460
+ const candidate = truncate5(limit);
42461
+ if (JSON.stringify(candidate).length <= maximumCharacters) {
42462
+ fitted = candidate;
42463
+ minimum = limit + 1;
42464
+ } else {
42465
+ maximum = limit - 1;
42466
+ }
42467
+ }
42468
+ return fitted;
42469
+ }
42470
+ function fitActivities(activities, maximumCharacters) {
42471
+ if (activities.length === 0) {
42472
+ return activities;
42473
+ }
42474
+ const arrayCharacters = 2 + activities.length - 1;
42475
+ const maximumActivityCharacters = Math.floor(Math.max(0, maximumCharacters - arrayCharacters) / activities.length);
42476
+ return activities.map((activity2) => fitActivity(activity2, maximumActivityCharacters));
42477
+ }
42478
+ function fitHistoryMessage(message) {
42479
+ const text2 = message.text.slice(-SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT);
42480
+ if (message.role === "user") {
42481
+ return {
42482
+ message: { ...message, text: text2 },
42483
+ truncated: text2.length < message.text.length
42484
+ };
42485
+ }
42486
+ let activities = message.activities;
42487
+ const content = message.content;
42488
+ let fitted = { ...message, activities, content, text: text2 };
42489
+ if (messageSize(fitted) > SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT && activities.length > 0) {
42490
+ const maximumCharacters = SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT - text2.length - JSON.stringify(content).length;
42491
+ activities = fitActivities(activities, maximumCharacters);
42492
+ fitted = { ...fitted, activities };
42493
+ }
42494
+ const excess = Math.max(0, messageSize(fitted) - SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT);
42495
+ if (excess > 0) {
42496
+ const maximumTextLength = Math.max(0, fitted.text.length - excess);
42497
+ fitted = {
42498
+ ...fitted,
42499
+ text: maximumTextLength === 0 ? "" : fitted.text.slice(-maximumTextLength)
42500
+ };
42501
+ }
42502
+ return {
42503
+ message: fitted,
42504
+ truncated: fitted.text.length < message.text.length || JSON.stringify(activities).length < JSON.stringify(message.activities).length
42505
+ };
42506
+ }
42444
42507
  function turnOutcome(status) {
42445
42508
  switch (status) {
42446
42509
  case "completed":
@@ -42467,14 +42530,20 @@ function decodeHistory(thread, value, options) {
42467
42530
  for (const turn of page.data.toReversed()) {
42468
42531
  const outcome = turnOutcome(turn.status);
42469
42532
  const activities = [];
42533
+ let assignedActivityCount = 0;
42470
42534
  let sequence = 0;
42471
42535
  let assistantMessageIndex = null;
42536
+ const activitySlice = () => {
42537
+ const assigned = activities.slice(assignedActivityCount).slice(-100);
42538
+ assignedActivityCount = activities.length;
42539
+ return assigned;
42540
+ };
42472
42541
  for (const item of turn.items) {
42473
42542
  const { type } = itemTypeSchema.parse(item);
42474
42543
  let message;
42475
42544
  if (type === "userMessage") {
42476
42545
  const { content } = userMessageSchema.parse(item);
42477
- const text3 = content.map((block) => {
42546
+ const text2 = content.map((block) => {
42478
42547
  const { type: type2 } = itemTypeSchema.parse(block);
42479
42548
  if (type2 === "text") {
42480
42549
  return textSchema.parse(block).text;
@@ -42486,7 +42555,7 @@ function decodeHistory(thread, value, options) {
42486
42555
  }).join("");
42487
42556
  message = {
42488
42557
  role: "user",
42489
- text: text3
42558
+ text: text2
42490
42559
  };
42491
42560
  } else if (type === "agentMessage") {
42492
42561
  const agent = agentMessageSchema.parse(item);
@@ -42507,7 +42576,7 @@ function decodeHistory(thread, value, options) {
42507
42576
  }
42508
42577
  continue;
42509
42578
  }
42510
- message = { activities: activities.slice(-100), content: [], role: "assistant", text: agent.text };
42579
+ message = { activities: activitySlice(), content: [], role: "assistant", text: agent.text };
42511
42580
  } else if (type === "reasoning" && options.detail === "rich") {
42512
42581
  const reasoning = reasoningSchema.parse(item);
42513
42582
  const output2 = (reasoning.summary.length > 0 ? reasoning.summary : reasoning.content).join("\n\n");
@@ -42548,16 +42617,16 @@ function decodeHistory(thread, value, options) {
42548
42617
  } else {
42549
42618
  continue;
42550
42619
  }
42551
- const text2 = message.text.slice(-SESSION_HISTORY_CHARACTER_LIMIT);
42552
- if (text2.length === 0 && (message.images?.length ?? 0) === 0) {
42620
+ const fitted = fitHistoryMessage(message);
42621
+ if (fitted.message.text.length === 0 && (fitted.message.images?.length ?? 0) === 0) {
42553
42622
  continue;
42554
42623
  }
42555
- truncated ||= text2.length < message.text.length;
42556
- messages.push({ ...message, text: text2 });
42624
+ truncated ||= fitted.truncated;
42625
+ messages.push(fitted.message);
42557
42626
  if (message.role === "assistant") {
42558
42627
  assistantMessageIndex = messages.length - 1;
42559
42628
  }
42560
- characters += messageSize({ ...message, text: text2 });
42629
+ characters += messageSize(fitted.message);
42561
42630
  }
42562
42631
  if (options.detail === "rich" && turn.error != null) {
42563
42632
  activities.push(
@@ -42572,17 +42641,29 @@ function decodeHistory(thread, value, options) {
42572
42641
  })
42573
42642
  );
42574
42643
  }
42644
+ if (options.detail === "rich" && activities.length > assignedActivityCount) {
42645
+ const message = {
42646
+ activities: activitySlice(),
42647
+ content: [],
42648
+ role: "assistant",
42649
+ text: ""
42650
+ };
42651
+ messages.push(message);
42652
+ assistantMessageIndex = messages.length - 1;
42653
+ characters += messageSize(message);
42654
+ }
42575
42655
  if (assistantMessageIndex !== null) {
42576
42656
  const assistant = messages[assistantMessageIndex];
42577
42657
  if (assistant?.role === "assistant") {
42578
42658
  characters -= messageSize(assistant);
42579
42659
  const updated = {
42580
42660
  ...assistant,
42581
- ...outcome === void 0 ? {} : { outcome },
42582
- activities: activities.slice(-100)
42661
+ ...outcome === void 0 ? {} : { outcome }
42583
42662
  };
42584
- messages[assistantMessageIndex] = updated;
42585
- characters += messageSize(updated);
42663
+ const fitted = fitHistoryMessage(updated);
42664
+ truncated ||= fitted.truncated;
42665
+ messages[assistantMessageIndex] = fitted.message;
42666
+ characters += messageSize(fitted.message);
42586
42667
  }
42587
42668
  } else if (activities.length > 0 || outcome !== void 0) {
42588
42669
  const message = {
@@ -42592,8 +42673,10 @@ function decodeHistory(thread, value, options) {
42592
42673
  ...outcome === void 0 ? {} : { outcome },
42593
42674
  text: ""
42594
42675
  };
42595
- messages.push(message);
42596
- characters += messageSize(message);
42676
+ const fitted = fitHistoryMessage(message);
42677
+ truncated ||= fitted.truncated;
42678
+ messages.push(fitted.message);
42679
+ characters += messageSize(fitted.message);
42597
42680
  }
42598
42681
  while (messages.length > (options.detail === "rich" ? SESSION_HISTORY_MESSAGE_LIMIT : SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT) || characters > SESSION_HISTORY_CHARACTER_LIMIT) {
42599
42682
  const removed = messages.shift();