@moxt-ai/mobius 0.0.411 → 0.0.412

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.
Files changed (26) hide show
  1. package/dist/{chunk-6BQX2L5A.js → chunk-7ER5P6H5.js} +68 -38
  2. package/dist/{chunk-6BQX2L5A.js.map → chunk-7ER5P6H5.js.map} +3 -3
  3. package/dist/{chunk-EX66DFKM.js → chunk-PMJDO7PC.js} +2 -2
  4. package/dist/{chunk-EX66DFKM.js.map → chunk-PMJDO7PC.js.map} +1 -1
  5. package/dist/{cli-4QU22MGP.js → cli-KGI5XDXC.js} +3 -3
  6. package/dist/cli.js +2 -2
  7. package/dist/engine/runtime/command/registry/interactions.d.ts.map +1 -1
  8. package/dist/engine/runtime/command/registry/interactions.js +7 -2
  9. package/dist/engine/runtime/command/registry/interactions.js.map +1 -1
  10. package/dist/engine/runtime/command/registry/prompt.d.ts.map +1 -1
  11. package/dist/engine/runtime/command/registry/prompt.js +8 -7
  12. package/dist/engine/runtime/command/registry/prompt.js.map +1 -1
  13. package/dist/engine/session/api/session-layer.d.ts.map +1 -1
  14. package/dist/engine/session/api/session-layer.js +1 -1
  15. package/dist/engine/session/api/session-layer.js.map +1 -1
  16. package/dist/engine/session/prompt/prompt-lifecycle.d.ts +7 -2
  17. package/dist/engine/session/prompt/prompt-lifecycle.d.ts.map +1 -1
  18. package/dist/engine/session/prompt/prompt-lifecycle.js +32 -9
  19. package/dist/engine/session/prompt/prompt-lifecycle.js.map +1 -1
  20. package/dist/engine/session/turn/execution-receipts.d.ts +16 -3
  21. package/dist/engine/session/turn/execution-receipts.d.ts.map +1 -1
  22. package/dist/engine/session/turn/execution-receipts.js +17 -14
  23. package/dist/engine/session/turn/execution-receipts.js.map +1 -1
  24. package/dist/engine.js +2 -2
  25. package/package.json +2 -2
  26. /package/dist/{cli-4QU22MGP.js.map → cli-KGI5XDXC.js.map} +0 -0
@@ -3,7 +3,7 @@ import {
3
3
  __export,
4
4
  __using,
5
5
  package_default
6
- } from "./chunk-EX66DFKM.js";
6
+ } from "./chunk-PMJDO7PC.js";
7
7
 
8
8
  // src/engine/runtime/relay/runtime-revocation.ts
9
9
  var runtimeRevocationCloseCode = 1008;
@@ -20804,9 +20804,10 @@ var sessionEventPayloadSchema = external_exports.discriminatedUnion("type", [
20804
20804
  external_exports.object({ payload: lifecycleMetadataSchema, type: external_exports.literal("lifecycle-metadata") }).readonly()
20805
20805
  ]);
20806
20806
  var positionSchema = external_exports.string().regex(/^(0|[1-9][0-9]*)$/);
20807
+ var mobiusMetadataFields = { omitted: external_exports.literal(true).optional(), restated: external_exports.literal(true).optional() };
20807
20808
  var sharedSessionEventFields = {
20808
20809
  eventId: identifierStringSchema,
20809
- mobiusMetadata: external_exports.object({ omitted: external_exports.literal(true).optional() }).readonly().optional(),
20810
+ mobiusMetadata: external_exports.object(mobiusMetadataFields).readonly().optional(),
20810
20811
  recordedAt: external_exports.iso.datetime({ offset: true }),
20811
20812
  sessionGenerationId: identifierStringSchema,
20812
20813
  sessionId: identifierStringSchema
@@ -20829,7 +20830,7 @@ var wireLifecyclePayloadSchema = external_exports.object({
20829
20830
  }).passthrough().readonly();
20830
20831
  var wireEventFields = {
20831
20832
  ...sessionLiveEventFields,
20832
- mobiusMetadata: external_exports.object({ omitted: external_exports.literal(true).optional() }).passthrough().readonly().optional()
20833
+ mobiusMetadata: external_exports.object(mobiusMetadataFields).passthrough().readonly().optional()
20833
20834
  };
20834
20835
  var sessionWireEventSchema = external_exports.union([
20835
20836
  external_exports.object({
@@ -88606,8 +88607,10 @@ var PromptLifecycle = class {
88606
88607
  #recordActiveTurn;
88607
88608
  #executions;
88608
88609
  #recordLifecycle;
88609
- constructor(sink, recordLifecycle, recordActiveTurn, executions) {
88610
+ #append;
88611
+ constructor(sink, recordLifecycle, append, recordActiveTurn, executions) {
88610
88612
  this.#recordLifecycle = recordLifecycle;
88613
+ this.#append = append;
88611
88614
  this.#recordActiveTurn = recordActiveTurn;
88612
88615
  this.#executions = executions;
88613
88616
  this.#sink = sink;
@@ -88646,16 +88649,20 @@ var PromptLifecycle = class {
88646
88649
  const sessionId = recorded.sessionId;
88647
88650
  if (recorded.type === "lifecycle-metadata" && isPromptTerminal(recorded.payload)) {
88648
88651
  this.#terminal.set(recorded.payload.commandId, recorded);
88649
- const pending2 = this.#publications.get(sessionId) ?? [];
88650
- pending2.push(recorded);
88651
- this.#publications.set(sessionId, pending2);
88652
+ const pending = this.#publications.get(sessionId) ?? [];
88653
+ pending.push(recorded);
88654
+ this.#publications.set(sessionId, pending);
88652
88655
  return;
88653
88656
  }
88654
- const pending = this.#publications.get(sessionId);
88657
+ this.#publishInOrder(recorded);
88658
+ };
88659
+ /** Publishes after the Session's held terminal events, so clients receive its events in order. */
88660
+ #publishInOrder = (event) => {
88661
+ const pending = this.#publications.get(event.sessionId);
88655
88662
  if (pending !== void 0) {
88656
- pending.push(recorded);
88663
+ pending.push(event);
88657
88664
  } else {
88658
- this.#sink.publish(recorded);
88665
+ this.#sink.publish(event);
88659
88666
  }
88660
88667
  };
88661
88668
  publishTerminal = (sessionId, commandId) => {
@@ -88680,13 +88687,24 @@ var PromptLifecycle = class {
88680
88687
  }
88681
88688
  this.#queued.delete(commandId);
88682
88689
  };
88683
- replayOutcome = async (sessionId, event) => {
88690
+ recordOutcome = async (sessionId, event) => {
88684
88691
  if (event.type !== "lifecycle-metadata" || !("commandId" in event.payload)) {
88685
88692
  return;
88686
88693
  }
88687
88694
  await this.#recordLifecycle(sessionId, event);
88688
88695
  this.publishTerminal(sessionId, event.payload.commandId);
88689
88696
  };
88697
+ /**
88698
+ * Answers a retried request about a command with the outcome its receipt already holds. The restatement is marked,
88699
+ * so Recording and status notifications do not take it for a new outcome, and it does not settle the receipt again.
88700
+ */
88701
+ restateOutcome = (sessionId, event) => {
88702
+ if (event.type !== "lifecycle-metadata" || !("commandId" in event.payload)) {
88703
+ return;
88704
+ }
88705
+ const restated = this.#append(sessionId, event);
88706
+ this.#publishInOrder({ ...restated, mobiusMetadata: { ...restated.mobiusMetadata, restated: true } });
88707
+ };
88690
88708
  queueChanged = async (sessionId, commandId) => {
88691
88709
  await this.#recordLifecycle(sessionId, {
88692
88710
  type: "lifecycle-metadata",
@@ -88745,10 +88763,16 @@ var PromptLifecycle = class {
88745
88763
  });
88746
88764
  };
88747
88765
  async function settleAbandonedTurn(projection, operations, cancellation) {
88748
- const outcome = operations.recordCancellationBeforeAdmission(cancellation.commandId, cancellation.sessionId);
88749
- if (outcome !== void 0) {
88750
- await projection.replayOutcome(cancellation.sessionId, outcome);
88751
- return;
88766
+ const cancelled = operations.recordCancellationBeforeAdmission(cancellation.commandId, cancellation.sessionId);
88767
+ switch (cancelled.kind) {
88768
+ case "recorded":
88769
+ await projection.recordOutcome(cancellation.sessionId, cancelled.outcome);
88770
+ return;
88771
+ case "restated":
88772
+ projection.restateOutcome(cancellation.sessionId, cancelled.outcome);
88773
+ return;
88774
+ case "unavailable":
88775
+ break;
88752
88776
  }
88753
88777
  const attemptId = operations.findUnsettledAttemptId(cancellation.commandId, cancellation.sessionId);
88754
88778
  if (attemptId === null) {
@@ -88840,7 +88864,6 @@ var unexpectedStanding = (standing) => {
88840
88864
  };
88841
88865
  var ExecutionReceipts = class {
88842
88866
  #executions = /* @__PURE__ */ new Map();
88843
- #recoveredCommands = /* @__PURE__ */ new Set();
88844
88867
  #table;
88845
88868
  #cancellations;
88846
88869
  #closing = false;
@@ -88860,7 +88883,6 @@ var ExecutionReceipts = class {
88860
88883
  if (cancelledBeforeStart(state)) {
88861
88884
  retained.push({ commandId, sessionId: identity2.sessionId });
88862
88885
  }
88863
- this.#recoveredCommands.add(commandId);
88864
88886
  }
88865
88887
  cancellations.retain(retained);
88866
88888
  }
@@ -88881,7 +88903,6 @@ var ExecutionReceipts = class {
88881
88903
  this.#executions.set(commandId, receipt);
88882
88904
  for (const evictedCommandId of evicted) {
88883
88905
  this.#executions.delete(evictedCommandId);
88884
- this.#recoveredCommands.delete(evictedCommandId);
88885
88906
  }
88886
88907
  let activeCount = 0;
88887
88908
  for (const entry of this.#executions.values()) {
@@ -89014,22 +89035,30 @@ var ExecutionReceipts = class {
89014
89035
  return unexpectedStanding(standing);
89015
89036
  }
89016
89037
  };
89017
- /** Reserves an unseen command for cancellation before a delayed prompt can claim its identity. */
89038
+ /**
89039
+ * Reserves an unseen command for cancellation before a delayed prompt can claim its identity. A command that
89040
+ * already has an outcome keeps it, and the outcome is restated rather than recorded again.
89041
+ */
89018
89042
  recordCancellationBeforeAdmission = (commandId, sessionId) => {
89019
89043
  const standing = this.#standing(commandId, sessionId);
89020
89044
  switch (standing.kind) {
89021
89045
  case "foreign":
89022
- return void 0;
89046
+ return { kind: "unavailable" };
89023
89047
  case "retryable":
89024
- case "retained":
89025
- return this.outcome(commandId);
89048
+ case "retained": {
89049
+ const outcome2 = this.outcome(commandId);
89050
+ return outcome2 === void 0 ? { kind: "unavailable" } : { kind: "restated", outcome: outcome2 };
89051
+ }
89026
89052
  case "expired":
89027
89053
  return {
89028
- type: "lifecycle-metadata",
89029
- payload: { kind: "prompt.completed", commandId, stopReason: "cancelled" }
89054
+ kind: "restated",
89055
+ outcome: {
89056
+ type: "lifecycle-metadata",
89057
+ payload: { kind: "prompt.completed", commandId, stopReason: "cancelled" }
89058
+ }
89030
89059
  };
89031
89060
  case "cancelled":
89032
- return cancelledBeforeStartOutcome(commandId);
89061
+ return { kind: "restated", outcome: cancelledBeforeStartOutcome(commandId) };
89033
89062
  case "unseen":
89034
89063
  break;
89035
89064
  default:
@@ -89053,7 +89082,7 @@ var ExecutionReceipts = class {
89053
89082
  outcome: JSON.stringify({ ...outcome, recordedAt: (/* @__PURE__ */ new Date()).toISOString() })
89054
89083
  }
89055
89084
  });
89056
- return outcome;
89085
+ return { kind: "recorded", outcome };
89057
89086
  };
89058
89087
  /**
89059
89088
  * Receipts follow their command's recorded lifecycle. `prompt.started` is recorded where the command is handed
@@ -89136,14 +89165,13 @@ var ExecutionReceipts = class {
89136
89165
  attemptId: standing.receipt.attemptId,
89137
89166
  commandId,
89138
89167
  kind: "duplicate",
89139
- outcome: this.#recoveredCommands.has(commandId) ? this.outcome(commandId) : void 0
89168
+ state: executionOutcome(standing.receipt.state) === null ? "unsettled" : "settled"
89140
89169
  };
89141
89170
  case "expired":
89142
89171
  return standing.commandHash === commandHash ? { kind: "expired" } : { kind: "conflict" };
89143
89172
  case "retryable":
89144
89173
  this.#table.remove(commandId);
89145
89174
  this.#executions.delete(commandId);
89146
- this.#recoveredCommands.delete(commandId);
89147
89175
  return this.claimExecution(commandId, sessionId, commandJson);
89148
89176
  case "unseen":
89149
89177
  break;
@@ -89171,7 +89199,6 @@ var ExecutionReceipts = class {
89171
89199
  };
89172
89200
  close = () => {
89173
89201
  this.#executions.clear();
89174
- this.#recoveredCommands.clear();
89175
89202
  this.#cancellations.close();
89176
89203
  };
89177
89204
  };
@@ -89833,6 +89860,7 @@ function buildSessionLayer(options) {
89833
89860
  eventProjection.record(recorded);
89834
89861
  return true;
89835
89862
  },
89863
+ (sessionId, event) => events.append(sessionId, event),
89836
89864
  activeSessions.recordSessionEvent,
89837
89865
  operations
89838
89866
  );
@@ -91713,9 +91741,14 @@ var sessionCancelBeforeStartCommand = {
91713
91741
  }
91714
91742
  const turn = sessionTurns.get(message.commandId, message.sessionId);
91715
91743
  if (turn === void 0) {
91716
- const outcome = operations.recordCancellationBeforeAdmission(message.commandId, message.sessionId);
91744
+ const cancelled = operations.recordCancellationBeforeAdmission(message.commandId, message.sessionId);
91745
+ const outcome = cancelled.kind === "unavailable" ? void 0 : cancelled.outcome;
91717
91746
  if (outcome?.type === "lifecycle-metadata" && outcome.payload.kind === "prompt.completed" && promptCompletion(outcome.payload).kind === "cancelled") {
91718
- void eventProjection.replayOutcome(message.sessionId, outcome).catch((error62) => {
91747
+ if (cancelled.kind === "restated") {
91748
+ eventProjection.restateOutcome(message.sessionId, outcome);
91749
+ return;
91750
+ }
91751
+ void eventProjection.recordOutcome(message.sessionId, outcome).catch((error62) => {
91719
91752
  reportOperationFailure(socket, message.commandId, message.sessionId, error62);
91720
91753
  });
91721
91754
  return;
@@ -92278,18 +92311,15 @@ var sessionPromptCommand = {
92278
92311
  return;
92279
92312
  }
92280
92313
  if (receipt.kind === "duplicate") {
92281
- const outcome = receipt.outcome;
92282
- const original = context.sessionTurns.get(message.commandId, message.sessionId);
92283
92314
  send(context.socket, {
92284
92315
  kind: "session.prompt.accepted",
92285
92316
  requestId: message.commandId,
92286
92317
  sessionId: message.sessionId,
92287
- state: outcome !== void 0 ? "settled" : original?.isQueued() === true ? "queued" : "running"
92318
+ state: receipt.state === "settled" ? "settled" : context.sessionTurns.get(message.commandId, message.sessionId)?.isQueued() === true ? "queued" : "running"
92288
92319
  });
92320
+ const outcome = receipt.state === "settled" ? context.operations.outcome(message.commandId) : void 0;
92289
92321
  if (outcome !== void 0) {
92290
- void context.eventProjection.replayOutcome(message.sessionId, outcome).catch((cause) => {
92291
- console.error("Could not replay the persisted execution outcome", cause);
92292
- });
92322
+ context.eventProjection.restateOutcome(message.sessionId, outcome);
92293
92323
  }
92294
92324
  return;
92295
92325
  }
@@ -94010,4 +94040,4 @@ export {
94010
94040
  * MIT Licensed
94011
94041
  *)
94012
94042
  */
94013
- //# sourceMappingURL=chunk-6BQX2L5A.js.map
94043
+ //# sourceMappingURL=chunk-7ER5P6H5.js.map