@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 +98 -15
- package/dist/cli.js.map +3 -3
- package/dist/index.js +97 -14
- package/dist/index.js.map +3 -3
- package/dist/native-sessions/codex-history.d.ts.map +1 -1
- package/dist/native-sessions/codex-history.js +96 -11
- package/dist/native-sessions/codex-history.js.map +1 -1
- package/dist/runtime.js +97 -14
- package/dist/runtime.js.map +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -39000,6 +39000,69 @@ function errorMessage(value) {
|
|
|
39000
39000
|
function messageSize(message) {
|
|
39001
39001
|
return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
|
|
39002
39002
|
}
|
|
39003
|
+
var SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT = Math.floor(SESSION_HISTORY_CHARACTER_LIMIT / 2);
|
|
39004
|
+
function fitActivity(activity2, maximumCharacters) {
|
|
39005
|
+
const truncate5 = (limit) => ({
|
|
39006
|
+
...activity2,
|
|
39007
|
+
input: bounded(activity2.input, limit),
|
|
39008
|
+
locations: activity2.locations.map((location) => bounded(location, Math.max(1, limit))),
|
|
39009
|
+
name: bounded(activity2.name, limit),
|
|
39010
|
+
output: bounded(activity2.output, limit),
|
|
39011
|
+
title: bounded(activity2.title, limit),
|
|
39012
|
+
toolKind: bounded(activity2.toolKind, limit)
|
|
39013
|
+
});
|
|
39014
|
+
let minimum = 1;
|
|
39015
|
+
let maximum = 1e5;
|
|
39016
|
+
let fitted = truncate5(0);
|
|
39017
|
+
while (minimum <= maximum) {
|
|
39018
|
+
const limit = Math.floor((minimum + maximum) / 2);
|
|
39019
|
+
const candidate = truncate5(limit);
|
|
39020
|
+
if (JSON.stringify(candidate).length <= maximumCharacters) {
|
|
39021
|
+
fitted = candidate;
|
|
39022
|
+
minimum = limit + 1;
|
|
39023
|
+
} else {
|
|
39024
|
+
maximum = limit - 1;
|
|
39025
|
+
}
|
|
39026
|
+
}
|
|
39027
|
+
return fitted;
|
|
39028
|
+
}
|
|
39029
|
+
function fitActivities(activities, maximumCharacters) {
|
|
39030
|
+
if (activities.length === 0) {
|
|
39031
|
+
return activities;
|
|
39032
|
+
}
|
|
39033
|
+
const arrayCharacters = 2 + activities.length - 1;
|
|
39034
|
+
const maximumActivityCharacters = Math.floor(Math.max(0, maximumCharacters - arrayCharacters) / activities.length);
|
|
39035
|
+
return activities.map((activity2) => fitActivity(activity2, maximumActivityCharacters));
|
|
39036
|
+
}
|
|
39037
|
+
function fitHistoryMessage(message) {
|
|
39038
|
+
const text2 = message.text.slice(-SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT);
|
|
39039
|
+
if (message.role === "user") {
|
|
39040
|
+
return {
|
|
39041
|
+
message: { ...message, text: text2 },
|
|
39042
|
+
truncated: text2.length < message.text.length
|
|
39043
|
+
};
|
|
39044
|
+
}
|
|
39045
|
+
let activities = message.activities;
|
|
39046
|
+
const content = message.content;
|
|
39047
|
+
let fitted = { ...message, activities, content, text: text2 };
|
|
39048
|
+
if (messageSize(fitted) > SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT && activities.length > 0) {
|
|
39049
|
+
const maximumCharacters = SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT - text2.length - JSON.stringify(content).length;
|
|
39050
|
+
activities = fitActivities(activities, maximumCharacters);
|
|
39051
|
+
fitted = { ...fitted, activities };
|
|
39052
|
+
}
|
|
39053
|
+
const excess = Math.max(0, messageSize(fitted) - SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT);
|
|
39054
|
+
if (excess > 0) {
|
|
39055
|
+
const maximumTextLength = Math.max(0, fitted.text.length - excess);
|
|
39056
|
+
fitted = {
|
|
39057
|
+
...fitted,
|
|
39058
|
+
text: maximumTextLength === 0 ? "" : fitted.text.slice(-maximumTextLength)
|
|
39059
|
+
};
|
|
39060
|
+
}
|
|
39061
|
+
return {
|
|
39062
|
+
message: fitted,
|
|
39063
|
+
truncated: fitted.text.length < message.text.length || JSON.stringify(activities).length < JSON.stringify(message.activities).length
|
|
39064
|
+
};
|
|
39065
|
+
}
|
|
39003
39066
|
function turnOutcome(status) {
|
|
39004
39067
|
switch (status) {
|
|
39005
39068
|
case "completed":
|
|
@@ -39026,14 +39089,20 @@ function decodeHistory(thread, value, options) {
|
|
|
39026
39089
|
for (const turn of page.data.toReversed()) {
|
|
39027
39090
|
const outcome = turnOutcome(turn.status);
|
|
39028
39091
|
const activities = [];
|
|
39092
|
+
let assignedActivityCount = 0;
|
|
39029
39093
|
let sequence = 0;
|
|
39030
39094
|
let assistantMessageIndex = null;
|
|
39095
|
+
const activitySlice = () => {
|
|
39096
|
+
const assigned = activities.slice(assignedActivityCount).slice(-100);
|
|
39097
|
+
assignedActivityCount = activities.length;
|
|
39098
|
+
return assigned;
|
|
39099
|
+
};
|
|
39031
39100
|
for (const item of turn.items) {
|
|
39032
39101
|
const { type } = itemTypeSchema.parse(item);
|
|
39033
39102
|
let message;
|
|
39034
39103
|
if (type === "userMessage") {
|
|
39035
39104
|
const { content } = userMessageSchema.parse(item);
|
|
39036
|
-
const
|
|
39105
|
+
const text2 = content.map((block) => {
|
|
39037
39106
|
const { type: type2 } = itemTypeSchema.parse(block);
|
|
39038
39107
|
if (type2 === "text") {
|
|
39039
39108
|
return textSchema.parse(block).text;
|
|
@@ -39045,7 +39114,7 @@ function decodeHistory(thread, value, options) {
|
|
|
39045
39114
|
}).join("");
|
|
39046
39115
|
message = {
|
|
39047
39116
|
role: "user",
|
|
39048
|
-
text:
|
|
39117
|
+
text: text2
|
|
39049
39118
|
};
|
|
39050
39119
|
} else if (type === "agentMessage") {
|
|
39051
39120
|
const agent = agentMessageSchema.parse(item);
|
|
@@ -39066,7 +39135,7 @@ function decodeHistory(thread, value, options) {
|
|
|
39066
39135
|
}
|
|
39067
39136
|
continue;
|
|
39068
39137
|
}
|
|
39069
|
-
message = { activities:
|
|
39138
|
+
message = { activities: activitySlice(), content: [], role: "assistant", text: agent.text };
|
|
39070
39139
|
} else if (type === "reasoning" && options.detail === "rich") {
|
|
39071
39140
|
const reasoning = reasoningSchema.parse(item);
|
|
39072
39141
|
const output2 = (reasoning.summary.length > 0 ? reasoning.summary : reasoning.content).join("\n\n");
|
|
@@ -39107,16 +39176,16 @@ function decodeHistory(thread, value, options) {
|
|
|
39107
39176
|
} else {
|
|
39108
39177
|
continue;
|
|
39109
39178
|
}
|
|
39110
|
-
const
|
|
39111
|
-
if (
|
|
39179
|
+
const fitted = fitHistoryMessage(message);
|
|
39180
|
+
if (fitted.message.text.length === 0 && (fitted.message.images?.length ?? 0) === 0) {
|
|
39112
39181
|
continue;
|
|
39113
39182
|
}
|
|
39114
|
-
truncated ||=
|
|
39115
|
-
messages.push(
|
|
39183
|
+
truncated ||= fitted.truncated;
|
|
39184
|
+
messages.push(fitted.message);
|
|
39116
39185
|
if (message.role === "assistant") {
|
|
39117
39186
|
assistantMessageIndex = messages.length - 1;
|
|
39118
39187
|
}
|
|
39119
|
-
characters += messageSize(
|
|
39188
|
+
characters += messageSize(fitted.message);
|
|
39120
39189
|
}
|
|
39121
39190
|
if (options.detail === "rich" && turn.error != null) {
|
|
39122
39191
|
activities.push(
|
|
@@ -39131,17 +39200,29 @@ function decodeHistory(thread, value, options) {
|
|
|
39131
39200
|
})
|
|
39132
39201
|
);
|
|
39133
39202
|
}
|
|
39203
|
+
if (options.detail === "rich" && activities.length > assignedActivityCount) {
|
|
39204
|
+
const message = {
|
|
39205
|
+
activities: activitySlice(),
|
|
39206
|
+
content: [],
|
|
39207
|
+
role: "assistant",
|
|
39208
|
+
text: ""
|
|
39209
|
+
};
|
|
39210
|
+
messages.push(message);
|
|
39211
|
+
assistantMessageIndex = messages.length - 1;
|
|
39212
|
+
characters += messageSize(message);
|
|
39213
|
+
}
|
|
39134
39214
|
if (assistantMessageIndex !== null) {
|
|
39135
39215
|
const assistant = messages[assistantMessageIndex];
|
|
39136
39216
|
if (assistant?.role === "assistant") {
|
|
39137
39217
|
characters -= messageSize(assistant);
|
|
39138
39218
|
const updated = {
|
|
39139
39219
|
...assistant,
|
|
39140
|
-
...outcome === void 0 ? {} : { outcome }
|
|
39141
|
-
activities: activities.slice(-100)
|
|
39220
|
+
...outcome === void 0 ? {} : { outcome }
|
|
39142
39221
|
};
|
|
39143
|
-
|
|
39144
|
-
|
|
39222
|
+
const fitted = fitHistoryMessage(updated);
|
|
39223
|
+
truncated ||= fitted.truncated;
|
|
39224
|
+
messages[assistantMessageIndex] = fitted.message;
|
|
39225
|
+
characters += messageSize(fitted.message);
|
|
39145
39226
|
}
|
|
39146
39227
|
} else if (activities.length > 0 || outcome !== void 0) {
|
|
39147
39228
|
const message = {
|
|
@@ -39151,8 +39232,10 @@ function decodeHistory(thread, value, options) {
|
|
|
39151
39232
|
...outcome === void 0 ? {} : { outcome },
|
|
39152
39233
|
text: ""
|
|
39153
39234
|
};
|
|
39154
|
-
|
|
39155
|
-
|
|
39235
|
+
const fitted = fitHistoryMessage(message);
|
|
39236
|
+
truncated ||= fitted.truncated;
|
|
39237
|
+
messages.push(fitted.message);
|
|
39238
|
+
characters += messageSize(fitted.message);
|
|
39156
39239
|
}
|
|
39157
39240
|
while (messages.length > (options.detail === "rich" ? SESSION_HISTORY_MESSAGE_LIMIT : SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT) || characters > SESSION_HISTORY_CHARACTER_LIMIT) {
|
|
39158
39241
|
const removed = messages.shift();
|