@moxt-ai/mobius 0.0.143 → 0.0.144

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/runtime.js CHANGED
@@ -38151,15 +38151,21 @@ var turnsSchema = external_exports.object({
38151
38151
  });
38152
38152
  var itemTypeSchema = external_exports.object({ type: external_exports.string().min(1).max(80) });
38153
38153
  var userMessageSchema = external_exports.object({
38154
- content: external_exports.array(external_exports.unknown()).max(1e4)
38154
+ content: external_exports.array(external_exports.unknown()).max(1e4),
38155
+ type: external_exports.literal("userMessage")
38155
38156
  });
38156
38157
  var textSchema = external_exports.object({ text: external_exports.string() });
38157
38158
  var imageSchema = external_exports.object({ url: external_exports.string() });
38158
- var agentMessageSchema = textSchema.extend({ phase: external_exports.string().nullish() });
38159
+ var agentMessageSchema = textSchema.extend({
38160
+ id: external_exports.string().optional(),
38161
+ phase: external_exports.string().nullish(),
38162
+ type: external_exports.literal("agentMessage")
38163
+ });
38159
38164
  var reasoningSchema = external_exports.object({
38160
38165
  id: external_exports.string(),
38161
38166
  summary: external_exports.array(external_exports.string()).max(1e4),
38162
- content: external_exports.array(external_exports.string()).max(1e4)
38167
+ content: external_exports.array(external_exports.string()).max(1e4),
38168
+ type: external_exports.literal("reasoning")
38163
38169
  });
38164
38170
  var commandExecutionSchema = external_exports.object({
38165
38171
  id: external_exports.string(),
@@ -38168,8 +38174,45 @@ var commandExecutionSchema = external_exports.object({
38168
38174
  status: external_exports.string(),
38169
38175
  commandActions: external_exports.array(external_exports.object({ type: external_exports.string() }).passthrough()).max(100),
38170
38176
  aggregatedOutput: external_exports.string().nullish(),
38171
- exitCode: external_exports.number().int().nullish()
38177
+ exitCode: external_exports.number().int().nullish(),
38178
+ type: external_exports.literal("commandExecution")
38179
+ });
38180
+ var fileChangeSchema = external_exports.object({
38181
+ changes: external_exports.array(external_exports.object({ diff: external_exports.string(), path: external_exports.string() })).max(1e4),
38182
+ id: external_exports.string(),
38183
+ status: external_exports.string(),
38184
+ type: external_exports.literal("fileChange")
38185
+ });
38186
+ var mcpToolCallSchema = external_exports.object({
38187
+ arguments: external_exports.unknown().optional(),
38188
+ error: external_exports.unknown().nullish(),
38189
+ id: external_exports.string(),
38190
+ result: external_exports.unknown().nullish(),
38191
+ server: external_exports.string(),
38192
+ status: external_exports.string(),
38193
+ tool: external_exports.string(),
38194
+ type: external_exports.literal("mcpToolCall")
38172
38195
  });
38196
+ var dynamicToolCallSchema = external_exports.object({
38197
+ arguments: external_exports.unknown().optional(),
38198
+ contentItems: external_exports.array(external_exports.unknown()).max(1e4).nullish(),
38199
+ id: external_exports.string(),
38200
+ namespace: external_exports.string().nullish(),
38201
+ status: external_exports.string(),
38202
+ tool: external_exports.string(),
38203
+ type: external_exports.literal("dynamicToolCall")
38204
+ });
38205
+ var planSchema = external_exports.object({ id: external_exports.string(), text: external_exports.string(), type: external_exports.literal("plan") });
38206
+ var historyItemSchema = external_exports.discriminatedUnion("type", [
38207
+ userMessageSchema,
38208
+ agentMessageSchema,
38209
+ reasoningSchema,
38210
+ commandExecutionSchema,
38211
+ fileChangeSchema,
38212
+ mcpToolCallSchema,
38213
+ dynamicToolCallSchema,
38214
+ planSchema
38215
+ ]);
38173
38216
  function bounded(value, maximum) {
38174
38217
  return value.slice(0, maximum);
38175
38218
  }
@@ -38200,6 +38243,33 @@ function errorMessage(value) {
38200
38243
  }
38201
38244
  return JSON.stringify(value) ?? "Codex stopped before completing this turn.";
38202
38245
  }
38246
+ function formatted(value) {
38247
+ if (value === void 0) {
38248
+ return "";
38249
+ }
38250
+ if (typeof value === "string") {
38251
+ return value;
38252
+ }
38253
+ return JSON.stringify(value) ?? "";
38254
+ }
38255
+ function toolStatus(status) {
38256
+ return status === "inProgress" ? "running" : status === "completed" ? "completed" : "failed";
38257
+ }
38258
+ function diffDisplayContent(path2, newText) {
38259
+ return {
38260
+ artifactId: "",
38261
+ data: "",
38262
+ mimeType: "",
38263
+ name: "",
38264
+ newText,
38265
+ oldText: "",
38266
+ path: path2,
38267
+ terminalId: "",
38268
+ text: "",
38269
+ type: "diff",
38270
+ uri: ""
38271
+ };
38272
+ }
38203
38273
  function messageSize(message) {
38204
38274
  return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
38205
38275
  }
@@ -38237,8 +38307,8 @@ function fitActivities(activities, maximumCharacters) {
38237
38307
  const maximumActivityCharacters = Math.floor(Math.max(0, maximumCharacters - arrayCharacters) / activities.length);
38238
38308
  return activities.map((activity2) => fitActivity(activity2, maximumActivityCharacters));
38239
38309
  }
38240
- function fitHistoryMessage(message) {
38241
- const text2 = message.text.slice(-SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT);
38310
+ function fitHistoryMessage(message, maximumCharacters = SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT) {
38311
+ const text2 = message.text.slice(-maximumCharacters);
38242
38312
  if (message.role === "user") {
38243
38313
  return {
38244
38314
  message: { ...message, text: text2 },
@@ -38248,12 +38318,12 @@ function fitHistoryMessage(message) {
38248
38318
  let activities = message.activities;
38249
38319
  const content = message.content;
38250
38320
  let fitted = { ...message, activities, content, text: text2 };
38251
- if (messageSize(fitted) > SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT && activities.length > 0) {
38252
- const maximumCharacters = SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT - text2.length - JSON.stringify(content).length;
38253
- activities = fitActivities(activities, maximumCharacters);
38321
+ if (messageSize(fitted) > maximumCharacters && activities.length > 0) {
38322
+ const maximumActivityCharacters = maximumCharacters - text2.length - JSON.stringify(content).length;
38323
+ activities = fitActivities(activities, maximumActivityCharacters);
38254
38324
  fitted = { ...fitted, activities };
38255
38325
  }
38256
- const excess = Math.max(0, messageSize(fitted) - SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT);
38326
+ const excess = Math.max(0, messageSize(fitted) - maximumCharacters);
38257
38327
  if (excess > 0) {
38258
38328
  const maximumTextLength = Math.max(0, fitted.text.length - excess);
38259
38329
  fitted = {
@@ -38291,128 +38361,209 @@ function decodeHistory(thread, value, options) {
38291
38361
  let truncated = page.nextCursor != null;
38292
38362
  for (const turn of page.data.toReversed()) {
38293
38363
  const outcome = turnOutcome(turn.status);
38294
- const activities = [];
38295
- let assignedActivityCount = 0;
38364
+ const turnMessageCharacterLimit = Math.max(
38365
+ 1,
38366
+ Math.floor(SESSION_HISTORY_CHARACTER_LIMIT / Math.max(1, turn.items.length + (turn.error == null ? 0 : 1)))
38367
+ );
38296
38368
  let sequence = 0;
38297
38369
  let assistantMessageIndex = null;
38298
- const activitySlice = () => {
38299
- const assigned = activities.slice(assignedActivityCount).slice(-100);
38300
- assignedActivityCount = activities.length;
38301
- return assigned;
38370
+ const append = (message) => {
38371
+ const fitted = fitHistoryMessage(message, turnMessageCharacterLimit);
38372
+ if (fitted.message.text.length === 0 && (fitted.message.images?.length ?? 0) === 0 && (fitted.message.role === "user" || fitted.message.activities.length === 0 && fitted.message.content.length === 0)) {
38373
+ return;
38374
+ }
38375
+ truncated ||= fitted.truncated;
38376
+ messages.push(fitted.message);
38377
+ if (fitted.message.role === "assistant") {
38378
+ assistantMessageIndex = messages.length - 1;
38379
+ }
38380
+ characters += messageSize(fitted.message);
38302
38381
  };
38303
38382
  for (const item of turn.items) {
38304
- const { type } = itemTypeSchema.parse(item);
38305
- let message;
38306
- if (type === "userMessage") {
38307
- const { content } = userMessageSchema.parse(item);
38308
- const text2 = content.map((block) => {
38309
- const { type: type2 } = itemTypeSchema.parse(block);
38310
- if (type2 === "text") {
38383
+ const decoded = historyItemSchema.safeParse(item);
38384
+ if (!decoded.success) {
38385
+ continue;
38386
+ }
38387
+ const historyItem = decoded.data;
38388
+ if (historyItem.type === "userMessage") {
38389
+ const text2 = historyItem.content.map((block) => {
38390
+ const { type } = itemTypeSchema.parse(block);
38391
+ if (type === "text") {
38311
38392
  return textSchema.parse(block).text;
38312
38393
  }
38313
- if (type2 === "image") {
38394
+ if (type === "image") {
38314
38395
  return `[@image](${imageSchema.parse(block).url})`;
38315
38396
  }
38316
38397
  return "[Attachment]";
38317
38398
  }).join("");
38318
- message = {
38399
+ append({
38319
38400
  role: "user",
38320
38401
  text: text2
38321
- };
38322
- } else if (type === "agentMessage") {
38323
- const agent = agentMessageSchema.parse(item);
38324
- if (agent.phase === "commentary") {
38325
- if (options.detail === "rich" && agent.text.length > 0) {
38326
- activities.push(
38327
- activity(`progress-${sequence.toString()}`, "progress", sequence, {
38402
+ });
38403
+ } else if (historyItem.type === "agentMessage") {
38404
+ if (historyItem.phase === "commentary") {
38405
+ if (options.detail === "rich" && historyItem.text.length > 0) {
38406
+ append({
38407
+ activities: [
38408
+ activity(historyItem.id ?? `progress-${sequence.toString()}`, "progress", sequence, {
38409
+ input: "",
38410
+ locations: [],
38411
+ name: "",
38412
+ output: historyItem.text,
38413
+ status: "completed",
38414
+ title: "Progress",
38415
+ toolKind: ""
38416
+ })
38417
+ ],
38418
+ content: [],
38419
+ role: "assistant",
38420
+ text: ""
38421
+ });
38422
+ sequence += 1;
38423
+ }
38424
+ continue;
38425
+ }
38426
+ append({ activities: [], content: [], role: "assistant", text: historyItem.text });
38427
+ } else if (historyItem.type === "reasoning" && options.detail === "rich") {
38428
+ const output2 = (historyItem.summary.length > 0 ? historyItem.summary : historyItem.content).join(
38429
+ "\n\n"
38430
+ );
38431
+ if (output2.length > 0) {
38432
+ append({
38433
+ activities: [
38434
+ activity(historyItem.id, "reasoning", sequence, {
38328
38435
  input: "",
38329
38436
  locations: [],
38330
38437
  name: "",
38331
- output: agent.text,
38438
+ output: output2,
38332
38439
  status: "completed",
38333
- title: "Progress",
38440
+ title: "Reasoning",
38334
38441
  toolKind: ""
38335
38442
  })
38336
- );
38337
- sequence += 1;
38338
- }
38339
- continue;
38443
+ ],
38444
+ content: [],
38445
+ role: "assistant",
38446
+ text: ""
38447
+ });
38448
+ sequence += 1;
38340
38449
  }
38341
- message = { activities: activitySlice(), content: [], role: "assistant", text: agent.text };
38342
- } else if (type === "reasoning" && options.detail === "rich") {
38343
- const reasoning = reasoningSchema.parse(item);
38344
- const output2 = (reasoning.summary.length > 0 ? reasoning.summary : reasoning.content).join("\n\n");
38345
- if (output2.length > 0) {
38346
- activities.push(
38347
- activity(reasoning.id, "reasoning", sequence, {
38450
+ } else if (historyItem.type === "commandExecution" && options.detail === "rich") {
38451
+ const action = historyItem.commandActions[0]?.type ?? "execute";
38452
+ append({
38453
+ activities: [
38454
+ activity(historyItem.id, "tool", sequence, {
38455
+ input: JSON.stringify({ command: historyItem.command, cwd: historyItem.cwd }),
38456
+ locations: [historyItem.cwd],
38457
+ name: "",
38458
+ output: JSON.stringify({
38459
+ formatted_output: historyItem.aggregatedOutput ?? "",
38460
+ ...historyItem.exitCode == null ? {} : { exit_code: historyItem.exitCode }
38461
+ }),
38462
+ status: toolStatus(historyItem.status),
38463
+ title: historyItem.command,
38464
+ toolKind: action
38465
+ })
38466
+ ],
38467
+ content: [],
38468
+ role: "assistant",
38469
+ text: ""
38470
+ });
38471
+ sequence += 1;
38472
+ } else if (historyItem.type === "fileChange" && options.detail === "rich") {
38473
+ const paths = historyItem.changes.map((change) => change.path);
38474
+ const content = historyItem.changes.map(
38475
+ (change) => diffDisplayContent(change.path, change.diff)
38476
+ );
38477
+ append({
38478
+ activities: [
38479
+ activity(historyItem.id, "tool", sequence, {
38480
+ input: JSON.stringify({ changes: paths }),
38481
+ locations: paths,
38482
+ name: "",
38483
+ output: "",
38484
+ status: toolStatus(historyItem.status),
38485
+ title: paths.join(", "),
38486
+ toolKind: "edit"
38487
+ })
38488
+ ].map((entry) => ({ ...entry, content })),
38489
+ content: [],
38490
+ role: "assistant",
38491
+ text: ""
38492
+ });
38493
+ sequence += 1;
38494
+ } else if (historyItem.type === "mcpToolCall" && options.detail === "rich") {
38495
+ append({
38496
+ activities: [
38497
+ activity(historyItem.id, "tool", sequence, {
38498
+ input: formatted(historyItem.arguments),
38499
+ locations: [],
38500
+ name: historyItem.tool,
38501
+ output: formatted(historyItem.error ?? historyItem.result),
38502
+ status: toolStatus(historyItem.status),
38503
+ title: `${historyItem.server}/${historyItem.tool}`,
38504
+ toolKind: "other"
38505
+ })
38506
+ ],
38507
+ content: [],
38508
+ role: "assistant",
38509
+ text: ""
38510
+ });
38511
+ sequence += 1;
38512
+ } else if (historyItem.type === "dynamicToolCall" && options.detail === "rich") {
38513
+ append({
38514
+ activities: [
38515
+ activity(historyItem.id, "tool", sequence, {
38516
+ input: formatted(historyItem.arguments),
38517
+ locations: [],
38518
+ name: historyItem.tool,
38519
+ output: formatted(historyItem.contentItems),
38520
+ status: toolStatus(historyItem.status),
38521
+ title: historyItem.namespace == null ? historyItem.tool : `${historyItem.namespace}/${historyItem.tool}`,
38522
+ toolKind: "other"
38523
+ })
38524
+ ],
38525
+ content: [],
38526
+ role: "assistant",
38527
+ text: ""
38528
+ });
38529
+ sequence += 1;
38530
+ } else if (historyItem.type === "plan" && options.detail === "rich") {
38531
+ append({
38532
+ activities: [
38533
+ activity(historyItem.id, "plan", sequence, {
38348
38534
  input: "",
38349
38535
  locations: [],
38350
38536
  name: "",
38351
- output: output2,
38537
+ output: historyItem.text,
38352
38538
  status: "completed",
38353
- title: "Reasoning",
38539
+ title: "Plan",
38354
38540
  toolKind: ""
38355
38541
  })
38356
- );
38357
- sequence += 1;
38358
- }
38359
- continue;
38360
- } else if (type === "commandExecution" && options.detail === "rich") {
38361
- const command = commandExecutionSchema.parse(item);
38362
- const action = command.commandActions[0]?.type ?? "execute";
38363
- activities.push(
38364
- activity(command.id, "tool", sequence, {
38365
- input: JSON.stringify({ command: command.command, cwd: command.cwd }),
38366
- locations: [command.cwd],
38367
- name: "",
38368
- output: JSON.stringify({
38369
- formatted_output: command.aggregatedOutput ?? "",
38370
- ...command.exitCode == null ? {} : { exit_code: command.exitCode }
38371
- }),
38372
- status: command.status === "completed" ? "completed" : "failed",
38373
- title: command.command,
38374
- toolKind: action
38375
- })
38376
- );
38542
+ ],
38543
+ content: [],
38544
+ role: "assistant",
38545
+ text: ""
38546
+ });
38377
38547
  sequence += 1;
38378
- continue;
38379
- } else {
38380
- continue;
38381
- }
38382
- const fitted = fitHistoryMessage(message);
38383
- if (fitted.message.text.length === 0 && (fitted.message.images?.length ?? 0) === 0) {
38384
- continue;
38385
38548
  }
38386
- truncated ||= fitted.truncated;
38387
- messages.push(fitted.message);
38388
- if (message.role === "assistant") {
38389
- assistantMessageIndex = messages.length - 1;
38390
- }
38391
- characters += messageSize(fitted.message);
38392
38549
  }
38393
38550
  if (options.detail === "rich" && turn.error != null) {
38394
- activities.push(
38395
- activity(`agent-error-${sequence.toString()}`, "tool", sequence, {
38396
- input: "",
38397
- locations: [],
38398
- name: "",
38399
- output: errorMessage(turn.error),
38400
- status: "failed",
38401
- title: "Agent error",
38402
- toolKind: "other"
38403
- })
38404
- );
38405
- }
38406
- if (options.detail === "rich" && activities.length > assignedActivityCount) {
38407
- const message = {
38408
- activities: activitySlice(),
38551
+ append({
38552
+ activities: [
38553
+ activity(`agent-error-${sequence.toString()}`, "tool", sequence, {
38554
+ input: "",
38555
+ locations: [],
38556
+ name: "",
38557
+ output: errorMessage(turn.error),
38558
+ status: "failed",
38559
+ title: "Agent error",
38560
+ toolKind: "other"
38561
+ })
38562
+ ],
38409
38563
  content: [],
38410
38564
  role: "assistant",
38411
38565
  text: ""
38412
- };
38413
- messages.push(message);
38414
- assistantMessageIndex = messages.length - 1;
38415
- characters += messageSize(message);
38566
+ });
38416
38567
  }
38417
38568
  if (assistantMessageIndex !== null) {
38418
38569
  const assistant = messages[assistantMessageIndex];
@@ -38422,20 +38573,20 @@ function decodeHistory(thread, value, options) {
38422
38573
  ...assistant,
38423
38574
  ...outcome === void 0 ? {} : { outcome }
38424
38575
  };
38425
- const fitted = fitHistoryMessage(updated);
38576
+ const fitted = fitHistoryMessage(updated, turnMessageCharacterLimit);
38426
38577
  truncated ||= fitted.truncated;
38427
38578
  messages[assistantMessageIndex] = fitted.message;
38428
38579
  characters += messageSize(fitted.message);
38429
38580
  }
38430
- } else if (activities.length > 0 || outcome !== void 0) {
38581
+ } else if (outcome !== void 0) {
38431
38582
  const message = {
38432
- activities: activities.slice(-100),
38583
+ activities: [],
38433
38584
  content: [],
38434
38585
  role: "assistant",
38435
38586
  ...outcome === void 0 ? {} : { outcome },
38436
38587
  text: ""
38437
38588
  };
38438
- const fitted = fitHistoryMessage(message);
38589
+ const fitted = fitHistoryMessage(message, turnMessageCharacterLimit);
38439
38590
  truncated ||= fitted.truncated;
38440
38591
  messages.push(fitted.message);
38441
38592
  characters += messageSize(fitted.message);