@moxt-ai/mobius 0.0.78 → 0.0.79

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
@@ -25658,6 +25658,8 @@ var encodeRecordedSessionEvent = (event) => JSON.stringify(decodeRecordedSession
25658
25658
  // ../protocol/src/session-live-history.ts
25659
25659
  var SESSION_LIVE_HISTORY_LOAD_KIND = "session.live-history.load";
25660
25660
  var SESSION_LIVE_HISTORY_LOADED_KIND = "session.live-history.loaded";
25661
+ var SESSION_LIVE_HISTORY_PAGE_LOAD_KIND = "session.live-history.page.load";
25662
+ var SESSION_LIVE_HISTORY_PAGE_LOADED_KIND = "session.live-history.page.loaded";
25661
25663
  var identifier2 = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/);
25662
25664
  var directoryIdentifier = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/);
25663
25665
  var sessionLiveHistoryLoadSchema = external_exports.strictObject({
@@ -25675,6 +25677,23 @@ var sessionLiveHistoryLoadedSchema = external_exports.strictObject({
25675
25677
  requestId: identifier2,
25676
25678
  sessionId: identifier2
25677
25679
  }).readonly();
25680
+ var sessionLiveHistoryPageLoadSchema = external_exports.strictObject({
25681
+ additionalDirectoryIds: external_exports.array(directoryIdentifier).max(16).readonly(),
25682
+ agentId: identifier2,
25683
+ bindingId: identifier2,
25684
+ cursor: external_exports.string().min(1).max(512).nullable(),
25685
+ directoryId: directoryIdentifier,
25686
+ kind: external_exports.literal(SESSION_LIVE_HISTORY_PAGE_LOAD_KIND),
25687
+ limit: external_exports.number().int().min(1).max(100),
25688
+ requestId: identifier2,
25689
+ sessionId: identifier2
25690
+ }).readonly();
25691
+ var sessionLiveHistoryPageLoadedSchema = external_exports.strictObject({
25692
+ kind: external_exports.literal(SESSION_LIVE_HISTORY_PAGE_LOADED_KIND),
25693
+ page: nativeMessagePageSchema,
25694
+ requestId: identifier2,
25695
+ sessionId: identifier2
25696
+ }).readonly();
25678
25697
  function decode6(schema, encoded) {
25679
25698
  try {
25680
25699
  const value = JSON.parse(encoded);
@@ -25687,6 +25706,10 @@ var decodeSessionLiveHistoryLoad = (encoded) => decode6(sessionLiveHistoryLoadSc
25687
25706
  var decodeSessionLiveHistoryLoaded = (encoded) => decode6(sessionLiveHistoryLoadedSchema, encoded);
25688
25707
  var encodeSessionLiveHistoryLoad = (value) => JSON.stringify(sessionLiveHistoryLoadSchema.parse(value));
25689
25708
  var encodeSessionLiveHistoryLoaded = (value) => JSON.stringify(sessionLiveHistoryLoadedSchema.parse(value));
25709
+ var decodeSessionLiveHistoryPageLoad = (encoded) => decode6(sessionLiveHistoryPageLoadSchema, encoded);
25710
+ var decodeSessionLiveHistoryPageLoaded = (encoded) => decode6(sessionLiveHistoryPageLoadedSchema, encoded);
25711
+ var encodeSessionLiveHistoryPageLoad = (value) => JSON.stringify(sessionLiveHistoryPageLoadSchema.parse(value));
25712
+ var encodeSessionLiveHistoryPageLoaded = (value) => JSON.stringify(sessionLiveHistoryPageLoadedSchema.parse(value));
25690
25713
 
25691
25714
  // ../protocol/src/daemon-transport.ts
25692
25715
  function defineMessageSignature(kind, encoder, decoder) {
@@ -25790,6 +25813,11 @@ var serviceToDaemonSignatures = {
25790
25813
  encodeSessionLiveHistoryLoad,
25791
25814
  decodeSessionLiveHistoryLoad
25792
25815
  ),
25816
+ [SESSION_LIVE_HISTORY_PAGE_LOAD_KIND]: defineMessageSignature(
25817
+ SESSION_LIVE_HISTORY_PAGE_LOAD_KIND,
25818
+ encodeSessionLiveHistoryPageLoad,
25819
+ decodeSessionLiveHistoryPageLoad
25820
+ ),
25793
25821
  [SESSION_PERMISSION_RESPOND_KIND]: defineMessageSignature(
25794
25822
  SESSION_PERMISSION_RESPOND_KIND,
25795
25823
  encodeSessionPermissionRespondCommand,
@@ -25900,6 +25928,11 @@ var daemonToServiceSignatures = {
25900
25928
  encodeSessionLiveHistoryLoaded,
25901
25929
  decodeSessionLiveHistoryLoaded
25902
25930
  ),
25931
+ [SESSION_LIVE_HISTORY_PAGE_LOADED_KIND]: defineMessageSignature(
25932
+ SESSION_LIVE_HISTORY_PAGE_LOADED_KIND,
25933
+ encodeSessionLiveHistoryPageLoaded,
25934
+ decodeSessionLiveHistoryPageLoaded
25935
+ ),
25903
25936
  [SESSION_READY_KIND]: defineMessageSignature(SESSION_READY_KIND, encodeSessionReadyEvent, decodeSessionReadyEvent),
25904
25937
  [WORKSPACE_ENTRIES_KIND]: defineMessageSignature(
25905
25938
  WORKSPACE_ENTRIES_KIND,
@@ -34495,6 +34528,29 @@ function sessionConfigProtocolForAgent(agentId) {
34495
34528
  }
34496
34529
 
34497
34530
  // src/acp/session-history.ts
34531
+ var HISTORY_ACTIVITY_FIELD_LIMIT = 1e5;
34532
+ var HISTORY_ACTIVITY_LIMIT = 100;
34533
+ function historyActivity(activity2) {
34534
+ return {
34535
+ activityId: activity2.activityId.slice(0, 128),
34536
+ activityType: activity2.activityType.slice(0, 128),
34537
+ content: activity2.content.slice(0, 100),
34538
+ input: activity2.input.slice(0, HISTORY_ACTIVITY_FIELD_LIMIT),
34539
+ locations: activity2.locations.slice(0, 100).map((location) => location.slice(0, 2048)),
34540
+ name: activity2.name.slice(0, 128),
34541
+ output: activity2.output.slice(0, HISTORY_ACTIVITY_FIELD_LIMIT),
34542
+ sequence: activity2.sequence,
34543
+ status: activity2.status.slice(0, 64),
34544
+ title: activity2.title.slice(0, 500),
34545
+ toolKind: activity2.toolKind.slice(0, 64)
34546
+ };
34547
+ }
34548
+ function historyContentCharacters(messages) {
34549
+ return messages.reduce(
34550
+ (total, message) => total + message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0),
34551
+ 0
34552
+ );
34553
+ }
34498
34554
  var AcpHistoryReplay = class {
34499
34555
  #activities = /* @__PURE__ */ new Map();
34500
34556
  #messages = [];
@@ -34601,33 +34657,45 @@ var AcpHistoryReplay = class {
34601
34657
  };
34602
34658
  snapshot = async () => {
34603
34659
  await this.#activityTracker.finish();
34660
+ const messages = this.#messages.map((message) => {
34661
+ if (message.role === "user") {
34662
+ return message;
34663
+ }
34664
+ const activities = message.activityIds.flatMap((id) => {
34665
+ const activity2 = this.#activities.get(id);
34666
+ return activity2 === void 0 ? [] : [historyActivity(activity2)];
34667
+ });
34668
+ if (activities.length > HISTORY_ACTIVITY_LIMIT) {
34669
+ this.#truncated = true;
34670
+ }
34671
+ return {
34672
+ role: "assistant",
34673
+ text: message.text,
34674
+ content: message.content.slice(0, 100),
34675
+ activities: activities.slice(-HISTORY_ACTIVITY_LIMIT)
34676
+ };
34677
+ });
34678
+ while (historyContentCharacters(messages) > SESSION_HISTORY_CHARACTER_LIMIT) {
34679
+ const richIndex = messages.findIndex(
34680
+ (message) => message.role === "assistant" && (message.activities.length > 0 || message.content.length > 0)
34681
+ );
34682
+ if (richIndex === -1) {
34683
+ messages.shift();
34684
+ } else {
34685
+ const message = messages[richIndex];
34686
+ if (message?.role === "assistant") {
34687
+ messages[richIndex] = {
34688
+ ...message,
34689
+ activities: message.activities.length > 0 ? message.activities.slice(1) : message.activities,
34690
+ content: message.activities.length === 0 && message.content.length > 0 ? message.content.slice(1) : message.content
34691
+ };
34692
+ }
34693
+ }
34694
+ this.#truncated = true;
34695
+ }
34604
34696
  return {
34605
34697
  status: "available",
34606
- messages: this.#messages.map(
34607
- (message) => message.role === "user" ? message : {
34608
- role: "assistant",
34609
- text: message.text,
34610
- content: message.content,
34611
- activities: message.activityIds.flatMap((id) => {
34612
- const activity2 = this.#activities.get(id);
34613
- return activity2 === void 0 ? [] : [
34614
- {
34615
- activityId: activity2.activityId,
34616
- activityType: activity2.activityType,
34617
- content: activity2.content,
34618
- input: activity2.input,
34619
- locations: activity2.locations,
34620
- name: activity2.name,
34621
- output: activity2.output,
34622
- sequence: activity2.sequence,
34623
- status: activity2.status,
34624
- title: activity2.title,
34625
- toolKind: activity2.toolKind
34626
- }
34627
- ];
34628
- })
34629
- }
34630
- ),
34698
+ messages,
34631
34699
  truncated: this.#truncated,
34632
34700
  coveredCommandIds: [],
34633
34701
  coveredMessageIds: []
@@ -42018,6 +42086,70 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
42018
42086
  reportOperationFailure(socket, command.requestId, command.sessionId, error62, metrics.snapshot());
42019
42087
  }
42020
42088
  }
42089
+ function liveHistoryCursor(sessionId, endIndex) {
42090
+ return Buffer.from(JSON.stringify({ endIndex, sessionId }), "utf8").toString("base64url");
42091
+ }
42092
+ function liveHistoryEndIndex(cursor, sessionId) {
42093
+ try {
42094
+ if (!/^[A-Za-z0-9_-]{1,512}$/u.test(cursor)) {
42095
+ throw new Error("Invalid cursor alphabet");
42096
+ }
42097
+ const value = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
42098
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
42099
+ throw new Error("Invalid cursor shape");
42100
+ }
42101
+ const record2 = Object.fromEntries(Object.entries(value));
42102
+ if (Object.keys(record2).sort().join(",") !== "endIndex,sessionId" || record2["sessionId"] !== sessionId || typeof record2["endIndex"] !== "number" || !Number.isSafeInteger(record2["endIndex"]) || record2["endIndex"] < 0) {
42103
+ throw new Error("Invalid cursor target");
42104
+ }
42105
+ return record2["endIndex"];
42106
+ } catch (cause) {
42107
+ throw new AcpExecutionError("The native Session history cursor is invalid", { cause }, "invalid_cursor");
42108
+ }
42109
+ }
42110
+ function liveHistoryCoveredTurnRanges(history) {
42111
+ const ranges = [];
42112
+ let historyIndex = history.messages.length;
42113
+ for (const commandId of history.coveredCommandIds) {
42114
+ let assistantStartIndex = historyIndex;
42115
+ while (assistantStartIndex > 0 && history.messages[assistantStartIndex - 1]?.role === "assistant") {
42116
+ assistantStartIndex -= 1;
42117
+ }
42118
+ const userIndex = assistantStartIndex - 1;
42119
+ if (assistantStartIndex === historyIndex || history.messages[userIndex]?.role !== "user") {
42120
+ break;
42121
+ }
42122
+ ranges.push({ assistantEndIndex: historyIndex, assistantStartIndex, commandId, userIndex });
42123
+ historyIndex = userIndex;
42124
+ }
42125
+ return ranges;
42126
+ }
42127
+ function paginateLiveSessionHistory(history, sessionId, cursor, limit) {
42128
+ if (history.status === "unavailable") {
42129
+ if (cursor !== null) {
42130
+ throw new AcpExecutionError("Unavailable native Session history has no cursor", {}, "invalid_cursor");
42131
+ }
42132
+ return { cause: history.cause, nextCursor: null, status: "unavailable" };
42133
+ }
42134
+ const endIndex = cursor === null ? history.messages.length : liveHistoryEndIndex(cursor, sessionId);
42135
+ if (endIndex > history.messages.length) {
42136
+ throw new AcpExecutionError("The native Session history cursor is invalid", {}, "invalid_cursor");
42137
+ }
42138
+ const startIndex = Math.max(0, endIndex - limit);
42139
+ const coveredMessageIds = new Set(history.coveredMessageIds);
42140
+ const ranges = liveHistoryCoveredTurnRanges(history);
42141
+ return {
42142
+ coveredCommandIds: ranges.filter((range) => range.userIndex >= startIndex && range.assistantEndIndex <= endIndex).map((range) => range.commandId),
42143
+ coveredMessageIds: ranges.flatMap((range) => [
42144
+ ...range.userIndex >= startIndex && range.userIndex < endIndex && coveredMessageIds.has(`${range.commandId}:user`) ? [`${range.commandId}:user`] : [],
42145
+ ...range.assistantStartIndex >= startIndex && range.assistantEndIndex <= endIndex && coveredMessageIds.has(`${range.commandId}:agent`) ? [`${range.commandId}:agent`] : []
42146
+ ]),
42147
+ messages: history.messages.slice(startIndex, endIndex),
42148
+ nextCursor: startIndex > 0 ? liveHistoryCursor(sessionId, startIndex) : null,
42149
+ status: "available",
42150
+ truncated: history.truncated
42151
+ };
42152
+ }
42021
42153
  async function executeSessionLiveHistoryLoad(socket, command, config2, directories, audit, sessions, signal) {
42022
42154
  try {
42023
42155
  const resolved = await resolveSessionDirectories(
@@ -42067,6 +42199,57 @@ async function executeSessionLiveHistoryLoad(socket, command, config2, directori
42067
42199
  });
42068
42200
  }
42069
42201
  }
42202
+ async function executeSessionLiveHistoryPageLoad(socket, command, config2, directories, audit, sessions, signal) {
42203
+ try {
42204
+ const resolved = await resolveSessionDirectories(
42205
+ directories,
42206
+ config2.bindingId,
42207
+ command.directoryId,
42208
+ command.additionalDirectoryIds,
42209
+ signal
42210
+ );
42211
+ const history = await sessions.loadSessionHistory({
42212
+ additionalDirectories: resolved.additionalDirectories,
42213
+ agent: config2.catalog.find(command.agentId),
42214
+ cwd: resolved.cwd,
42215
+ sessionId: command.sessionId,
42216
+ signal
42217
+ });
42218
+ signal.throwIfAborted();
42219
+ const page = paginateLiveSessionHistory(history, command.sessionId, command.cursor, command.limit);
42220
+ audit.record({
42221
+ commandId: command.requestId,
42222
+ event: "session_history_loaded",
42223
+ sessionId: command.sessionId
42224
+ });
42225
+ send(socket, {
42226
+ kind: "session.live-history.page.loaded",
42227
+ page,
42228
+ requestId: command.requestId,
42229
+ sessionId: command.sessionId
42230
+ });
42231
+ } catch (error62) {
42232
+ if (signal.aborted) {
42233
+ return;
42234
+ }
42235
+ audit.record({
42236
+ commandId: command.requestId,
42237
+ details: { code: operationErrorCode(error62) },
42238
+ event: "session_history_unavailable",
42239
+ sessionId: command.sessionId
42240
+ });
42241
+ send(socket, {
42242
+ kind: "session.live-history.page.loaded",
42243
+ page: {
42244
+ status: "unavailable",
42245
+ cause: { code: operationErrorCode(error62), message: operationErrorMessage(error62) },
42246
+ nextCursor: null
42247
+ },
42248
+ requestId: command.requestId,
42249
+ sessionId: command.sessionId
42250
+ });
42251
+ }
42252
+ }
42070
42253
  async function executeSessionConfigure(publisher, socket, command, config2, directories, audit, sessions, signal) {
42071
42254
  try {
42072
42255
  const resolved = await resolveSessionDirectories(
@@ -42926,6 +43109,19 @@ async function runRelayConnection(config2, directories, audit, sessions, install
42926
43109
  );
42927
43110
  return;
42928
43111
  }
43112
+ if (kind === SESSION_LIVE_HISTORY_PAGE_LOAD_KIND) {
43113
+ const command2 = decodeSessionLiveHistoryPageLoad(encoded);
43114
+ void executeSessionLiveHistoryPageLoad(
43115
+ socket,
43116
+ command2,
43117
+ config2,
43118
+ directories,
43119
+ audit,
43120
+ sessions,
43121
+ connectionController.signal
43122
+ );
43123
+ return;
43124
+ }
42929
43125
  if (kind === NATIVE_SESSION_CANCEL_KIND) {
42930
43126
  const command2 = message;
42931
43127
  const pending = nativeRequests.get(command2.requestId);