@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/index.js CHANGED
@@ -39029,15 +39029,21 @@ var turnsSchema = external_exports.object({
39029
39029
  });
39030
39030
  var itemTypeSchema = external_exports.object({ type: external_exports.string().min(1).max(80) });
39031
39031
  var userMessageSchema = external_exports.object({
39032
- content: external_exports.array(external_exports.unknown()).max(1e4)
39032
+ content: external_exports.array(external_exports.unknown()).max(1e4),
39033
+ type: external_exports.literal("userMessage")
39033
39034
  });
39034
39035
  var textSchema = external_exports.object({ text: external_exports.string() });
39035
39036
  var imageSchema = external_exports.object({ url: external_exports.string() });
39036
- var agentMessageSchema = textSchema.extend({ phase: external_exports.string().nullish() });
39037
+ var agentMessageSchema = textSchema.extend({
39038
+ id: external_exports.string().optional(),
39039
+ phase: external_exports.string().nullish(),
39040
+ type: external_exports.literal("agentMessage")
39041
+ });
39037
39042
  var reasoningSchema = external_exports.object({
39038
39043
  id: external_exports.string(),
39039
39044
  summary: external_exports.array(external_exports.string()).max(1e4),
39040
- content: external_exports.array(external_exports.string()).max(1e4)
39045
+ content: external_exports.array(external_exports.string()).max(1e4),
39046
+ type: external_exports.literal("reasoning")
39041
39047
  });
39042
39048
  var commandExecutionSchema = external_exports.object({
39043
39049
  id: external_exports.string(),
@@ -39046,8 +39052,45 @@ var commandExecutionSchema = external_exports.object({
39046
39052
  status: external_exports.string(),
39047
39053
  commandActions: external_exports.array(external_exports.object({ type: external_exports.string() }).passthrough()).max(100),
39048
39054
  aggregatedOutput: external_exports.string().nullish(),
39049
- exitCode: external_exports.number().int().nullish()
39055
+ exitCode: external_exports.number().int().nullish(),
39056
+ type: external_exports.literal("commandExecution")
39057
+ });
39058
+ var fileChangeSchema = external_exports.object({
39059
+ changes: external_exports.array(external_exports.object({ diff: external_exports.string(), path: external_exports.string() })).max(1e4),
39060
+ id: external_exports.string(),
39061
+ status: external_exports.string(),
39062
+ type: external_exports.literal("fileChange")
39063
+ });
39064
+ var mcpToolCallSchema = external_exports.object({
39065
+ arguments: external_exports.unknown().optional(),
39066
+ error: external_exports.unknown().nullish(),
39067
+ id: external_exports.string(),
39068
+ result: external_exports.unknown().nullish(),
39069
+ server: external_exports.string(),
39070
+ status: external_exports.string(),
39071
+ tool: external_exports.string(),
39072
+ type: external_exports.literal("mcpToolCall")
39050
39073
  });
39074
+ var dynamicToolCallSchema = external_exports.object({
39075
+ arguments: external_exports.unknown().optional(),
39076
+ contentItems: external_exports.array(external_exports.unknown()).max(1e4).nullish(),
39077
+ id: external_exports.string(),
39078
+ namespace: external_exports.string().nullish(),
39079
+ status: external_exports.string(),
39080
+ tool: external_exports.string(),
39081
+ type: external_exports.literal("dynamicToolCall")
39082
+ });
39083
+ var planSchema = external_exports.object({ id: external_exports.string(), text: external_exports.string(), type: external_exports.literal("plan") });
39084
+ var historyItemSchema = external_exports.discriminatedUnion("type", [
39085
+ userMessageSchema,
39086
+ agentMessageSchema,
39087
+ reasoningSchema,
39088
+ commandExecutionSchema,
39089
+ fileChangeSchema,
39090
+ mcpToolCallSchema,
39091
+ dynamicToolCallSchema,
39092
+ planSchema
39093
+ ]);
39051
39094
  function bounded(value, maximum) {
39052
39095
  return value.slice(0, maximum);
39053
39096
  }
@@ -39078,6 +39121,33 @@ function errorMessage(value) {
39078
39121
  }
39079
39122
  return JSON.stringify(value) ?? "Codex stopped before completing this turn.";
39080
39123
  }
39124
+ function formatted(value) {
39125
+ if (value === void 0) {
39126
+ return "";
39127
+ }
39128
+ if (typeof value === "string") {
39129
+ return value;
39130
+ }
39131
+ return JSON.stringify(value) ?? "";
39132
+ }
39133
+ function toolStatus(status) {
39134
+ return status === "inProgress" ? "running" : status === "completed" ? "completed" : "failed";
39135
+ }
39136
+ function diffDisplayContent(path2, newText) {
39137
+ return {
39138
+ artifactId: "",
39139
+ data: "",
39140
+ mimeType: "",
39141
+ name: "",
39142
+ newText,
39143
+ oldText: "",
39144
+ path: path2,
39145
+ terminalId: "",
39146
+ text: "",
39147
+ type: "diff",
39148
+ uri: ""
39149
+ };
39150
+ }
39081
39151
  function messageSize(message) {
39082
39152
  return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
39083
39153
  }
@@ -39115,8 +39185,8 @@ function fitActivities(activities, maximumCharacters) {
39115
39185
  const maximumActivityCharacters = Math.floor(Math.max(0, maximumCharacters - arrayCharacters) / activities.length);
39116
39186
  return activities.map((activity2) => fitActivity(activity2, maximumActivityCharacters));
39117
39187
  }
39118
- function fitHistoryMessage(message) {
39119
- const text2 = message.text.slice(-SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT);
39188
+ function fitHistoryMessage(message, maximumCharacters = SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT) {
39189
+ const text2 = message.text.slice(-maximumCharacters);
39120
39190
  if (message.role === "user") {
39121
39191
  return {
39122
39192
  message: { ...message, text: text2 },
@@ -39126,12 +39196,12 @@ function fitHistoryMessage(message) {
39126
39196
  let activities = message.activities;
39127
39197
  const content = message.content;
39128
39198
  let fitted = { ...message, activities, content, text: text2 };
39129
- if (messageSize(fitted) > SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT && activities.length > 0) {
39130
- const maximumCharacters = SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT - text2.length - JSON.stringify(content).length;
39131
- activities = fitActivities(activities, maximumCharacters);
39199
+ if (messageSize(fitted) > maximumCharacters && activities.length > 0) {
39200
+ const maximumActivityCharacters = maximumCharacters - text2.length - JSON.stringify(content).length;
39201
+ activities = fitActivities(activities, maximumActivityCharacters);
39132
39202
  fitted = { ...fitted, activities };
39133
39203
  }
39134
- const excess = Math.max(0, messageSize(fitted) - SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT);
39204
+ const excess = Math.max(0, messageSize(fitted) - maximumCharacters);
39135
39205
  if (excess > 0) {
39136
39206
  const maximumTextLength = Math.max(0, fitted.text.length - excess);
39137
39207
  fitted = {
@@ -39169,128 +39239,209 @@ function decodeHistory(thread, value, options) {
39169
39239
  let truncated = page.nextCursor != null;
39170
39240
  for (const turn of page.data.toReversed()) {
39171
39241
  const outcome = turnOutcome(turn.status);
39172
- const activities = [];
39173
- let assignedActivityCount = 0;
39242
+ const turnMessageCharacterLimit = Math.max(
39243
+ 1,
39244
+ Math.floor(SESSION_HISTORY_CHARACTER_LIMIT / Math.max(1, turn.items.length + (turn.error == null ? 0 : 1)))
39245
+ );
39174
39246
  let sequence = 0;
39175
39247
  let assistantMessageIndex = null;
39176
- const activitySlice = () => {
39177
- const assigned = activities.slice(assignedActivityCount).slice(-100);
39178
- assignedActivityCount = activities.length;
39179
- return assigned;
39248
+ const append = (message) => {
39249
+ const fitted = fitHistoryMessage(message, turnMessageCharacterLimit);
39250
+ 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)) {
39251
+ return;
39252
+ }
39253
+ truncated ||= fitted.truncated;
39254
+ messages.push(fitted.message);
39255
+ if (fitted.message.role === "assistant") {
39256
+ assistantMessageIndex = messages.length - 1;
39257
+ }
39258
+ characters += messageSize(fitted.message);
39180
39259
  };
39181
39260
  for (const item of turn.items) {
39182
- const { type } = itemTypeSchema.parse(item);
39183
- let message;
39184
- if (type === "userMessage") {
39185
- const { content } = userMessageSchema.parse(item);
39186
- const text2 = content.map((block) => {
39187
- const { type: type2 } = itemTypeSchema.parse(block);
39188
- if (type2 === "text") {
39261
+ const decoded = historyItemSchema.safeParse(item);
39262
+ if (!decoded.success) {
39263
+ continue;
39264
+ }
39265
+ const historyItem = decoded.data;
39266
+ if (historyItem.type === "userMessage") {
39267
+ const text2 = historyItem.content.map((block) => {
39268
+ const { type } = itemTypeSchema.parse(block);
39269
+ if (type === "text") {
39189
39270
  return textSchema.parse(block).text;
39190
39271
  }
39191
- if (type2 === "image") {
39272
+ if (type === "image") {
39192
39273
  return `[@image](${imageSchema.parse(block).url})`;
39193
39274
  }
39194
39275
  return "[Attachment]";
39195
39276
  }).join("");
39196
- message = {
39277
+ append({
39197
39278
  role: "user",
39198
39279
  text: text2
39199
- };
39200
- } else if (type === "agentMessage") {
39201
- const agent = agentMessageSchema.parse(item);
39202
- if (agent.phase === "commentary") {
39203
- if (options.detail === "rich" && agent.text.length > 0) {
39204
- activities.push(
39205
- activity(`progress-${sequence.toString()}`, "progress", sequence, {
39280
+ });
39281
+ } else if (historyItem.type === "agentMessage") {
39282
+ if (historyItem.phase === "commentary") {
39283
+ if (options.detail === "rich" && historyItem.text.length > 0) {
39284
+ append({
39285
+ activities: [
39286
+ activity(historyItem.id ?? `progress-${sequence.toString()}`, "progress", sequence, {
39287
+ input: "",
39288
+ locations: [],
39289
+ name: "",
39290
+ output: historyItem.text,
39291
+ status: "completed",
39292
+ title: "Progress",
39293
+ toolKind: ""
39294
+ })
39295
+ ],
39296
+ content: [],
39297
+ role: "assistant",
39298
+ text: ""
39299
+ });
39300
+ sequence += 1;
39301
+ }
39302
+ continue;
39303
+ }
39304
+ append({ activities: [], content: [], role: "assistant", text: historyItem.text });
39305
+ } else if (historyItem.type === "reasoning" && options.detail === "rich") {
39306
+ const output2 = (historyItem.summary.length > 0 ? historyItem.summary : historyItem.content).join(
39307
+ "\n\n"
39308
+ );
39309
+ if (output2.length > 0) {
39310
+ append({
39311
+ activities: [
39312
+ activity(historyItem.id, "reasoning", sequence, {
39206
39313
  input: "",
39207
39314
  locations: [],
39208
39315
  name: "",
39209
- output: agent.text,
39316
+ output: output2,
39210
39317
  status: "completed",
39211
- title: "Progress",
39318
+ title: "Reasoning",
39212
39319
  toolKind: ""
39213
39320
  })
39214
- );
39215
- sequence += 1;
39216
- }
39217
- continue;
39321
+ ],
39322
+ content: [],
39323
+ role: "assistant",
39324
+ text: ""
39325
+ });
39326
+ sequence += 1;
39218
39327
  }
39219
- message = { activities: activitySlice(), content: [], role: "assistant", text: agent.text };
39220
- } else if (type === "reasoning" && options.detail === "rich") {
39221
- const reasoning = reasoningSchema.parse(item);
39222
- const output2 = (reasoning.summary.length > 0 ? reasoning.summary : reasoning.content).join("\n\n");
39223
- if (output2.length > 0) {
39224
- activities.push(
39225
- activity(reasoning.id, "reasoning", sequence, {
39328
+ } else if (historyItem.type === "commandExecution" && options.detail === "rich") {
39329
+ const action = historyItem.commandActions[0]?.type ?? "execute";
39330
+ append({
39331
+ activities: [
39332
+ activity(historyItem.id, "tool", sequence, {
39333
+ input: JSON.stringify({ command: historyItem.command, cwd: historyItem.cwd }),
39334
+ locations: [historyItem.cwd],
39335
+ name: "",
39336
+ output: JSON.stringify({
39337
+ formatted_output: historyItem.aggregatedOutput ?? "",
39338
+ ...historyItem.exitCode == null ? {} : { exit_code: historyItem.exitCode }
39339
+ }),
39340
+ status: toolStatus(historyItem.status),
39341
+ title: historyItem.command,
39342
+ toolKind: action
39343
+ })
39344
+ ],
39345
+ content: [],
39346
+ role: "assistant",
39347
+ text: ""
39348
+ });
39349
+ sequence += 1;
39350
+ } else if (historyItem.type === "fileChange" && options.detail === "rich") {
39351
+ const paths = historyItem.changes.map((change) => change.path);
39352
+ const content = historyItem.changes.map(
39353
+ (change) => diffDisplayContent(change.path, change.diff)
39354
+ );
39355
+ append({
39356
+ activities: [
39357
+ activity(historyItem.id, "tool", sequence, {
39358
+ input: JSON.stringify({ changes: paths }),
39359
+ locations: paths,
39360
+ name: "",
39361
+ output: "",
39362
+ status: toolStatus(historyItem.status),
39363
+ title: paths.join(", "),
39364
+ toolKind: "edit"
39365
+ })
39366
+ ].map((entry) => ({ ...entry, content })),
39367
+ content: [],
39368
+ role: "assistant",
39369
+ text: ""
39370
+ });
39371
+ sequence += 1;
39372
+ } else if (historyItem.type === "mcpToolCall" && options.detail === "rich") {
39373
+ append({
39374
+ activities: [
39375
+ activity(historyItem.id, "tool", sequence, {
39376
+ input: formatted(historyItem.arguments),
39377
+ locations: [],
39378
+ name: historyItem.tool,
39379
+ output: formatted(historyItem.error ?? historyItem.result),
39380
+ status: toolStatus(historyItem.status),
39381
+ title: `${historyItem.server}/${historyItem.tool}`,
39382
+ toolKind: "other"
39383
+ })
39384
+ ],
39385
+ content: [],
39386
+ role: "assistant",
39387
+ text: ""
39388
+ });
39389
+ sequence += 1;
39390
+ } else if (historyItem.type === "dynamicToolCall" && options.detail === "rich") {
39391
+ append({
39392
+ activities: [
39393
+ activity(historyItem.id, "tool", sequence, {
39394
+ input: formatted(historyItem.arguments),
39395
+ locations: [],
39396
+ name: historyItem.tool,
39397
+ output: formatted(historyItem.contentItems),
39398
+ status: toolStatus(historyItem.status),
39399
+ title: historyItem.namespace == null ? historyItem.tool : `${historyItem.namespace}/${historyItem.tool}`,
39400
+ toolKind: "other"
39401
+ })
39402
+ ],
39403
+ content: [],
39404
+ role: "assistant",
39405
+ text: ""
39406
+ });
39407
+ sequence += 1;
39408
+ } else if (historyItem.type === "plan" && options.detail === "rich") {
39409
+ append({
39410
+ activities: [
39411
+ activity(historyItem.id, "plan", sequence, {
39226
39412
  input: "",
39227
39413
  locations: [],
39228
39414
  name: "",
39229
- output: output2,
39415
+ output: historyItem.text,
39230
39416
  status: "completed",
39231
- title: "Reasoning",
39417
+ title: "Plan",
39232
39418
  toolKind: ""
39233
39419
  })
39234
- );
39235
- sequence += 1;
39236
- }
39237
- continue;
39238
- } else if (type === "commandExecution" && options.detail === "rich") {
39239
- const command = commandExecutionSchema.parse(item);
39240
- const action = command.commandActions[0]?.type ?? "execute";
39241
- activities.push(
39242
- activity(command.id, "tool", sequence, {
39243
- input: JSON.stringify({ command: command.command, cwd: command.cwd }),
39244
- locations: [command.cwd],
39245
- name: "",
39246
- output: JSON.stringify({
39247
- formatted_output: command.aggregatedOutput ?? "",
39248
- ...command.exitCode == null ? {} : { exit_code: command.exitCode }
39249
- }),
39250
- status: command.status === "completed" ? "completed" : "failed",
39251
- title: command.command,
39252
- toolKind: action
39253
- })
39254
- );
39420
+ ],
39421
+ content: [],
39422
+ role: "assistant",
39423
+ text: ""
39424
+ });
39255
39425
  sequence += 1;
39256
- continue;
39257
- } else {
39258
- continue;
39259
- }
39260
- const fitted = fitHistoryMessage(message);
39261
- if (fitted.message.text.length === 0 && (fitted.message.images?.length ?? 0) === 0) {
39262
- continue;
39263
39426
  }
39264
- truncated ||= fitted.truncated;
39265
- messages.push(fitted.message);
39266
- if (message.role === "assistant") {
39267
- assistantMessageIndex = messages.length - 1;
39268
- }
39269
- characters += messageSize(fitted.message);
39270
39427
  }
39271
39428
  if (options.detail === "rich" && turn.error != null) {
39272
- activities.push(
39273
- activity(`agent-error-${sequence.toString()}`, "tool", sequence, {
39274
- input: "",
39275
- locations: [],
39276
- name: "",
39277
- output: errorMessage(turn.error),
39278
- status: "failed",
39279
- title: "Agent error",
39280
- toolKind: "other"
39281
- })
39282
- );
39283
- }
39284
- if (options.detail === "rich" && activities.length > assignedActivityCount) {
39285
- const message = {
39286
- activities: activitySlice(),
39429
+ append({
39430
+ activities: [
39431
+ activity(`agent-error-${sequence.toString()}`, "tool", sequence, {
39432
+ input: "",
39433
+ locations: [],
39434
+ name: "",
39435
+ output: errorMessage(turn.error),
39436
+ status: "failed",
39437
+ title: "Agent error",
39438
+ toolKind: "other"
39439
+ })
39440
+ ],
39287
39441
  content: [],
39288
39442
  role: "assistant",
39289
39443
  text: ""
39290
- };
39291
- messages.push(message);
39292
- assistantMessageIndex = messages.length - 1;
39293
- characters += messageSize(message);
39444
+ });
39294
39445
  }
39295
39446
  if (assistantMessageIndex !== null) {
39296
39447
  const assistant = messages[assistantMessageIndex];
@@ -39300,20 +39451,20 @@ function decodeHistory(thread, value, options) {
39300
39451
  ...assistant,
39301
39452
  ...outcome === void 0 ? {} : { outcome }
39302
39453
  };
39303
- const fitted = fitHistoryMessage(updated);
39454
+ const fitted = fitHistoryMessage(updated, turnMessageCharacterLimit);
39304
39455
  truncated ||= fitted.truncated;
39305
39456
  messages[assistantMessageIndex] = fitted.message;
39306
39457
  characters += messageSize(fitted.message);
39307
39458
  }
39308
- } else if (activities.length > 0 || outcome !== void 0) {
39459
+ } else if (outcome !== void 0) {
39309
39460
  const message = {
39310
- activities: activities.slice(-100),
39461
+ activities: [],
39311
39462
  content: [],
39312
39463
  role: "assistant",
39313
39464
  ...outcome === void 0 ? {} : { outcome },
39314
39465
  text: ""
39315
39466
  };
39316
- const fitted = fitHistoryMessage(message);
39467
+ const fitted = fitHistoryMessage(message, turnMessageCharacterLimit);
39317
39468
  truncated ||= fitted.truncated;
39318
39469
  messages.push(fitted.message);
39319
39470
  characters += messageSize(fitted.message);