@dexto/core 1.8.12 → 1.9.1

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 (124) hide show
  1. package/dist/approval/manager.cjs +37 -325
  2. package/dist/approval/manager.d.ts +10 -109
  3. package/dist/approval/manager.d.ts.map +1 -1
  4. package/dist/approval/manager.js +37 -316
  5. package/dist/approval/schemas.cjs +8 -51
  6. package/dist/approval/schemas.d.ts +5 -179
  7. package/dist/approval/schemas.d.ts.map +1 -1
  8. package/dist/approval/schemas.js +8 -47
  9. package/dist/approval/types.cjs +0 -6
  10. package/dist/approval/types.d.ts +2 -27
  11. package/dist/approval/types.d.ts.map +1 -1
  12. package/dist/approval/types.js +0 -6
  13. package/dist/context/compaction/strategies/reactive-overflow-compaction.cjs +2 -0
  14. package/dist/context/compaction/strategies/reactive-overflow-compaction.d.ts.map +1 -1
  15. package/dist/context/compaction/strategies/reactive-overflow-compaction.js +2 -0
  16. package/dist/context/content-clone.cjs +55 -10
  17. package/dist/context/content-clone.d.ts +1 -0
  18. package/dist/context/content-clone.d.ts.map +1 -1
  19. package/dist/context/content-clone.js +53 -9
  20. package/dist/context/manager.cjs +25 -4
  21. package/dist/context/manager.d.ts +4 -2
  22. package/dist/context/manager.d.ts.map +1 -1
  23. package/dist/context/manager.js +25 -4
  24. package/dist/context/schemas.cjs +15 -1
  25. package/dist/context/schemas.d.ts.map +1 -1
  26. package/dist/context/schemas.js +15 -1
  27. package/dist/context/types.d.ts +11 -0
  28. package/dist/context/types.d.ts.map +1 -1
  29. package/dist/errors/DextoRuntimeError.cjs +3 -1
  30. package/dist/errors/DextoRuntimeError.d.ts +5 -3
  31. package/dist/errors/DextoRuntimeError.d.ts.map +1 -1
  32. package/dist/errors/DextoRuntimeError.js +3 -1
  33. package/dist/errors/index.d.ts +1 -1
  34. package/dist/errors/index.d.ts.map +1 -1
  35. package/dist/errors/types.d.ts +1 -0
  36. package/dist/errors/types.d.ts.map +1 -1
  37. package/dist/events/index.d.ts +2 -2
  38. package/dist/events/index.d.ts.map +1 -1
  39. package/dist/llm/executor/provider-error.cjs +25 -4
  40. package/dist/llm/executor/provider-error.d.ts.map +1 -1
  41. package/dist/llm/executor/provider-error.js +25 -4
  42. package/dist/llm/executor/stream-processor.cjs +98 -7
  43. package/dist/llm/executor/stream-processor.d.ts.map +1 -1
  44. package/dist/llm/executor/stream-processor.js +98 -7
  45. package/dist/llm/executor/turn-executor.cjs +96 -28
  46. package/dist/llm/executor/turn-executor.d.ts +2 -0
  47. package/dist/llm/executor/turn-executor.d.ts.map +1 -1
  48. package/dist/llm/executor/turn-executor.js +96 -28
  49. package/dist/llm/providers/local/schemas.d.ts +2 -2
  50. package/dist/llm/services/factory.cjs +3 -2
  51. package/dist/llm/services/factory.d.ts.map +1 -1
  52. package/dist/llm/services/factory.js +3 -2
  53. package/dist/llm/services/types.d.ts +8 -0
  54. package/dist/llm/services/types.d.ts.map +1 -1
  55. package/dist/llm/services/vercel.cjs +6 -1
  56. package/dist/llm/services/vercel.d.ts +3 -2
  57. package/dist/llm/services/vercel.d.ts.map +1 -1
  58. package/dist/llm/services/vercel.js +6 -1
  59. package/dist/session/chat-session.cjs +4 -0
  60. package/dist/session/chat-session.d.ts +2 -1
  61. package/dist/session/chat-session.d.ts.map +1 -1
  62. package/dist/session/chat-session.js +4 -0
  63. package/dist/session/message-queue.cjs +48 -75
  64. package/dist/session/message-queue.d.ts +1 -2
  65. package/dist/session/message-queue.d.ts.map +1 -1
  66. package/dist/session/message-queue.js +48 -75
  67. package/dist/session/session-manager.cjs +14 -32
  68. package/dist/session/session-manager.d.ts +5 -2
  69. package/dist/session/session-manager.d.ts.map +1 -1
  70. package/dist/session/session-manager.js +14 -32
  71. package/dist/storage/approvals/types.cjs +2 -9
  72. package/dist/storage/approvals/types.d.ts +4 -16
  73. package/dist/storage/approvals/types.d.ts.map +1 -1
  74. package/dist/storage/approvals/types.js +2 -8
  75. package/dist/storage/database/types.d.ts +5 -0
  76. package/dist/storage/database/types.d.ts.map +1 -1
  77. package/dist/storage/index.cjs +0 -2
  78. package/dist/storage/index.d.ts +2 -2
  79. package/dist/storage/index.d.ts.map +1 -1
  80. package/dist/storage/index.js +1 -2
  81. package/dist/storage/message-queue/types.d.ts +14 -6
  82. package/dist/storage/message-queue/types.d.ts.map +1 -1
  83. package/dist/storage/stores/backend.cjs +68 -32
  84. package/dist/storage/stores/backend.d.ts +17 -8
  85. package/dist/storage/stores/backend.d.ts.map +1 -1
  86. package/dist/storage/stores/backend.js +69 -33
  87. package/dist/storage/stores/in-memory.cjs +26 -11
  88. package/dist/storage/stores/in-memory.d.ts.map +1 -1
  89. package/dist/storage/stores/in-memory.js +27 -12
  90. package/dist/test-utils/in-memory-storage.cjs +11 -0
  91. package/dist/test-utils/in-memory-storage.js +11 -0
  92. package/dist/test-utils/session-state-stores.cjs +25 -9
  93. package/dist/test-utils/session-state-stores.js +26 -10
  94. package/dist/tools/approval/tool-approval-policy.cjs +87 -0
  95. package/dist/tools/approval/tool-approval-policy.d.ts +34 -0
  96. package/dist/tools/approval/tool-approval-policy.d.ts.map +1 -0
  97. package/dist/tools/approval/tool-approval-policy.js +64 -0
  98. package/dist/tools/error-codes.cjs +0 -1
  99. package/dist/tools/error-codes.d.ts +0 -1
  100. package/dist/tools/error-codes.d.ts.map +1 -1
  101. package/dist/tools/error-codes.js +0 -1
  102. package/dist/tools/errors.cjs +0 -15
  103. package/dist/tools/errors.d.ts +0 -9
  104. package/dist/tools/errors.d.ts.map +1 -1
  105. package/dist/tools/errors.js +0 -15
  106. package/dist/tools/index.cjs +2 -0
  107. package/dist/tools/index.d.ts +1 -1
  108. package/dist/tools/index.d.ts.map +1 -1
  109. package/dist/tools/index.js +5 -1
  110. package/dist/tools/tool-manager.cjs +94 -312
  111. package/dist/tools/tool-manager.d.ts +4 -19
  112. package/dist/tools/tool-manager.d.ts.map +1 -1
  113. package/dist/tools/tool-manager.js +95 -316
  114. package/dist/tools/types.d.ts +10 -9
  115. package/dist/tools/types.d.ts.map +1 -1
  116. package/dist/utils/service-initializer.cjs +3 -0
  117. package/dist/utils/service-initializer.d.ts +2 -1
  118. package/dist/utils/service-initializer.d.ts.map +1 -1
  119. package/dist/utils/service-initializer.js +3 -0
  120. package/package.json +2 -2
  121. package/dist/tools/pattern-utils.cjs +0 -33
  122. package/dist/tools/pattern-utils.d.ts +0 -20
  123. package/dist/tools/pattern-utils.d.ts.map +0 -1
  124. package/dist/tools/pattern-utils.js +0 -10
@@ -1 +1 @@
1
- {"version":3,"file":"vercel.d.ts","sourceRoot":"","sources":["../../../src/llm/services/vercel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAqB,MAAM,IAAI,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,KAAK,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAI1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGxD,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAIhE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE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ClC,YAAY,CAAC,EAAE,MAAM,EACrB,gBAAgB,CAAC,EAAE,mBAAmB,EACtC,kBAAkB,CAAC,EAAE,OAAO,mCAAmC,EAAE,kBAAkB,GAAG,IAAI;IAyC9F,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAI/B,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IAM7B,gBAAgB,CAAC,OAAO,GAAE,uBAA4B,GAAG,OAAO,CAAC,UAAU,CAAC;IAsClF;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAkC1B;;OAEG;IACH,OAAc,YAAY,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAE7C;;;;;;;OAOG;IACG,MAAM,CACR,OAAO,EAAE,YAAY,EACrB,OAAO,CAAC,EAAE;QACN,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,UAAU,CAAC,EAAE,eAAe,CAAC;KAChC,GACF,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IA+D5B;;;OAGG;IACH,SAAS,IAAI,gBAAgB;IA+B7B;;OAEG;IACH,iBAAiB,IAAI,cAAc,CAAC,OAAO,CAAC;IAI5C;;OAEG;IACH,aAAa,IAAI,mBAAmB;IAIpC,gBAAgB,IAAI,mBAAmB;IAIvC;;OAEG;IACH,qBAAqB,IAAI,OAAO,mCAAmC,EAAE,kBAAkB,GAAG,IAAI;IAI9F,gBAAgB,IAAI,aAAa;CAGpC"}
@@ -48,13 +48,14 @@ class VercelLLMService {
48
48
  compactionStrategy;
49
49
  modelLimits;
50
50
  usageScopeId;
51
+ executionControl;
51
52
  /**
52
53
  * Helper to extract model ID from LanguageModel union type (string | LanguageModelV2)
53
54
  */
54
55
  getModelId() {
55
56
  return typeof this.model === "string" ? this.model : this.model.modelId;
56
57
  }
57
- constructor(toolManager, model, systemPromptManager, conversationStore, sessionEventBus, config, sessionId, resourceManager, logger, steerQueue, followUpQueue, usageScopeId, compactionStrategy) {
58
+ constructor(toolManager, model, systemPromptManager, conversationStore, sessionEventBus, config, sessionId, resourceManager, logger, steerQueue, followUpQueue, usageScopeId, executionControl, compactionStrategy) {
58
59
  this.logger = logger.createChild(DextoLogComponent.LLM);
59
60
  this.model = model;
60
61
  this.config = config;
@@ -63,6 +64,7 @@ class VercelLLMService {
63
64
  this.sessionId = sessionId;
64
65
  this.resourceManager = resourceManager;
65
66
  this.usageScopeId = usageScopeId;
67
+ this.executionControl = executionControl;
66
68
  this.compactionStrategy = compactionStrategy ?? null;
67
69
  this.steerQueue = steerQueue;
68
70
  this.followUpQueue = followUpQueue;
@@ -143,6 +145,9 @@ class VercelLLMService {
143
145
  temperature: this.config.temperature,
144
146
  baseURL: this.config.baseURL,
145
147
  usageScopeId: this.usageScopeId,
148
+ ...this.executionControl !== void 0 && {
149
+ executionControl: this.executionControl
150
+ },
146
151
  // Provider-specific options
147
152
  reasoning: this.config.reasoning
148
153
  },
@@ -188,6 +188,9 @@ class ChatSession {
188
188
  const options = {
189
189
  usageScopeId,
190
190
  compactionStrategy: this.services.compactionStrategy,
191
+ ...this.services.executionControl !== void 0 && {
192
+ executionControl: this.services.executionControl
193
+ },
191
194
  ...workspace?.path !== void 0 && { cwd: workspace.path },
192
195
  steerQueue: this.steerQueue,
193
196
  followUpQueue: this.followUpQueue,
@@ -230,6 +233,7 @@ class ChatSession {
230
233
  const assistantMessage = {
231
234
  id: assistantMessageId,
232
235
  role: "assistant",
236
+ assistantOutput: { status: "complete" },
233
237
  timestamp: timestamp + 1,
234
238
  content: [{ type: "text", text: errorContent }]
235
239
  };
@@ -1,5 +1,5 @@
1
1
  import type { ContextManager } from '../context/index.js';
2
- import type { LanguageModelFactory } from '../llm/services/types.js';
2
+ import type { LLMExecutionControl, LanguageModelFactory } from '../llm/services/types.js';
3
3
  import type { LlmAuthResolver } from '../llm/auth/index.js';
4
4
  import type { SystemPromptManager } from '../systemPrompt/manager.js';
5
5
  import type { ToolManager } from '../tools/tool-manager.js';
@@ -148,6 +148,7 @@ export declare class ChatSession {
148
148
  authResolver?: LlmAuthResolver | null;
149
149
  workspaceManager?: import('../workspace/manager.js').WorkspaceManager;
150
150
  compactionStrategy: CompactionStrategy | null;
151
+ executionControl?: LLMExecutionControl | undefined;
151
152
  }, id: string, logger: Logger);
152
153
  /**
153
154
  * Initialize the session services asynchronously.
@@ -1 +1 @@
1
- {"version":3,"file":"chat-session.d.ts","sourceRoot":"","sources":["../../src/session/chat-session.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAK1D,OAAO,KAAK,EAA2B,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAC9F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EACH,eAAe,EACf,aAAa,EAGhB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAIpD,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,qBAAqB,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAuB,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AACl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AC,MAAM,CAAC;IAO/C;;;OAGG;IACU,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAOlD;;;OAGG;IACU,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IAQjD;;;OAGG;IACI,MAAM,IAAI,OAAO;CAa3B"}
@@ -176,6 +176,9 @@ class ChatSession {
176
176
  const options = {
177
177
  usageScopeId,
178
178
  compactionStrategy: this.services.compactionStrategy,
179
+ ...this.services.executionControl !== void 0 && {
180
+ executionControl: this.services.executionControl
181
+ },
179
182
  ...workspace?.path !== void 0 && { cwd: workspace.path },
180
183
  steerQueue: this.steerQueue,
181
184
  followUpQueue: this.followUpQueue,
@@ -218,6 +221,7 @@ class ChatSession {
218
221
  const assistantMessage = {
219
222
  id: assistantMessageId,
220
223
  role: "assistant",
224
+ assistantOutput: { status: "complete" },
221
225
  timestamp: timestamp + 1,
222
226
  content: [{ type: "text", text: errorContent }]
223
227
  };
@@ -23,18 +23,31 @@ __export(message_queue_exports, {
23
23
  module.exports = __toCommonJS(message_queue_exports);
24
24
  var import_queue_clone = require("./queue-clone.js");
25
25
  class EphemeralMessageQueueStore {
26
- async listSessionIds() {
27
- return [];
28
- }
29
- async load(input) {
26
+ queue = [];
27
+ async list(input) {
30
28
  void input;
31
- return [];
29
+ return (0, import_queue_clone.cloneQueuedMessages)(this.queue);
32
30
  }
33
- async save(input) {
34
- void input;
31
+ async append(input) {
32
+ void input.sessionId;
33
+ this.queue = [...this.queue, (0, import_queue_clone.cloneQueuedMessage)(input.message)];
34
+ return { position: this.queue.length };
35
35
  }
36
- async delete(input) {
37
- void input;
36
+ async takeAll(input) {
37
+ void input.sessionId;
38
+ const messages = (0, import_queue_clone.cloneQueuedMessages)(this.queue);
39
+ this.queue = [];
40
+ return messages;
41
+ }
42
+ async remove(input) {
43
+ void input.sessionId;
44
+ const previousLength = this.queue.length;
45
+ this.queue = this.queue.filter((message) => message.id !== input.id);
46
+ return this.queue.length !== previousLength;
47
+ }
48
+ async clear(input) {
49
+ void input.sessionId;
50
+ this.queue = [];
38
51
  }
39
52
  }
40
53
  function generateId() {
@@ -48,7 +61,7 @@ class MessageQueueService {
48
61
  this.store = store;
49
62
  this.queueKind = queueKind;
50
63
  }
51
- queue = [];
64
+ queueSnapshot = [];
52
65
  mutationLock = Promise.resolve();
53
66
  initialized = false;
54
67
  initializationPromise = null;
@@ -66,10 +79,10 @@ class MessageQueueService {
66
79
  if (this.initialized) {
67
80
  return;
68
81
  }
69
- this.queue = await this.store.load({ sessionId: this.sessionId });
70
- if (this.queue.length > 0) {
82
+ this.queueSnapshot = await this.store.list({ sessionId: this.sessionId });
83
+ if (this.queueSnapshot.length > 0) {
71
84
  this.logger.debug(
72
- `Restored ${this.queue.length} queued message(s) for session ${this.sessionId}`
85
+ `Restored ${this.queueSnapshot.length} queued message(s) for session ${this.sessionId}`
73
86
  );
74
87
  }
75
88
  this.initialized = true;
@@ -79,22 +92,8 @@ class MessageQueueService {
79
92
  });
80
93
  await this.initializationPromise;
81
94
  }
82
- async persistQueue() {
83
- await this.store.save({ sessionId: this.sessionId, queue: this.queue });
84
- }
85
95
  async refreshFromStore() {
86
- const storedQueue = await this.store.load({ sessionId: this.sessionId });
87
- const existingIds = new Set(this.queue.map((message) => message.id));
88
- const externalMessages = storedQueue.filter((message) => !existingIds.has(message.id));
89
- if (externalMessages.length === 0) {
90
- return;
91
- }
92
- this.queue = [...this.queue, ...(0, import_queue_clone.cloneQueuedMessages)(externalMessages)].sort(
93
- (left, right) => left.queuedAt - right.queuedAt
94
- );
95
- this.logger.debug(
96
- `Loaded ${externalMessages.length} externally queued message(s) for session ${this.sessionId}`
97
- );
96
+ this.queueSnapshot = await this.store.list({ sessionId: this.sessionId });
98
97
  }
99
98
  runWithMutationLock(fn) {
100
99
  const currentResult = this.mutationLock.catch(() => {
@@ -124,22 +123,20 @@ class MessageQueueService {
124
123
  ...message.kind !== void 0 && { kind: message.kind }
125
124
  };
126
125
  const copiedQueuedMsg = (0, import_queue_clone.cloneQueuedMessage)(queuedMsg);
127
- this.queue.push(copiedQueuedMsg);
128
- try {
129
- await this.persistQueue();
130
- } catch (error) {
131
- this.queue.pop();
132
- throw error;
133
- }
134
- this.logger.debug(`Message queued: ${queuedMsg.id}, position: ${this.queue.length}`);
126
+ const { position } = await this.store.append({
127
+ sessionId: this.sessionId,
128
+ message: copiedQueuedMsg
129
+ });
130
+ await this.refreshFromStore();
131
+ this.logger.debug(`Message queued: ${queuedMsg.id}, position: ${position}`);
135
132
  this.eventBus.emit("message:queued", {
136
- position: this.queue.length,
133
+ position,
137
134
  id: queuedMsg.id,
138
135
  queue: this.queueKind
139
136
  });
140
137
  return {
141
138
  queued: true,
142
- position: this.queue.length,
139
+ position,
143
140
  id: queuedMsg.id
144
141
  };
145
142
  });
@@ -167,16 +164,9 @@ class MessageQueueService {
167
164
  */
168
165
  async dequeueAll() {
169
166
  return await this.runWithMutationLock(async () => {
170
- await this.refreshFromStore();
171
- if (this.queue.length === 0) return null;
172
- const messages = (0, import_queue_clone.cloneQueuedMessages)(this.queue);
173
- this.queue = [];
174
- try {
175
- await this.persistQueue();
176
- } catch (error) {
177
- this.queue = messages;
178
- throw error;
179
- }
167
+ const messages = await this.store.takeAll({ sessionId: this.sessionId });
168
+ this.queueSnapshot = [];
169
+ if (messages.length === 0) return null;
180
170
  const combined = this.coalesce(messages);
181
171
  this.logger.debug(
182
172
  `Dequeued ${messages.length} message(s): ${messages.map((m) => m.id).join(", ")}`
@@ -272,7 +262,7 @@ ${prefixText}`;
272
262
  * Check if there are pending messages in the queue.
273
263
  */
274
264
  hasPending() {
275
- return this.queue.length > 0;
265
+ return this.queueSnapshot.length > 0;
276
266
  }
277
267
  async refresh() {
278
268
  await this.runWithMutationLock(async () => {
@@ -283,7 +273,7 @@ ${prefixText}`;
283
273
  * Get the number of pending messages.
284
274
  */
285
275
  pendingCount() {
286
- return this.queue.length;
276
+ return this.queueSnapshot.length;
287
277
  }
288
278
  /**
289
279
  * Clear all pending messages without processing.
@@ -291,17 +281,8 @@ ${prefixText}`;
291
281
  */
292
282
  async clear() {
293
283
  await this.runWithMutationLock(async () => {
294
- if (this.queue.length === 0) {
295
- return;
296
- }
297
- const previousQueue = [...this.queue];
298
- this.queue = [];
299
- try {
300
- await this.persistQueue();
301
- } catch (error) {
302
- this.queue = previousQueue;
303
- throw error;
304
- }
284
+ await this.store.clear({ sessionId: this.sessionId });
285
+ this.queueSnapshot = [];
305
286
  });
306
287
  }
307
288
  /**
@@ -309,13 +290,13 @@ ${prefixText}`;
309
290
  * Returns defensive copies to prevent external mutation.
310
291
  */
311
292
  getAll() {
312
- return (0, import_queue_clone.cloneQueuedMessages)(this.queue);
293
+ return (0, import_queue_clone.cloneQueuedMessages)(this.queueSnapshot);
313
294
  }
314
295
  /**
315
296
  * Get a single queued message by ID.
316
297
  */
317
298
  get(id) {
318
- const message = this.queue.find((m) => m.id === id);
299
+ const message = this.queueSnapshot.find((m) => m.id === id);
319
300
  return message ? (0, import_queue_clone.cloneQueuedMessage)(message) : void 0;
320
301
  }
321
302
  /**
@@ -324,21 +305,13 @@ ${prefixText}`;
324
305
  */
325
306
  async remove(id) {
326
307
  return await this.runWithMutationLock(async () => {
327
- const index = this.queue.findIndex((m) => m.id === id);
328
- if (index === -1) {
308
+ const removed = await this.store.remove({ sessionId: this.sessionId, id });
309
+ if (!removed) {
329
310
  this.logger.debug(`Remove failed: message ${id} not found in queue`);
330
311
  return false;
331
312
  }
332
- const [removed] = this.queue.splice(index, 1);
333
- try {
334
- await this.persistQueue();
335
- } catch (error) {
336
- if (removed) {
337
- this.queue.splice(index, 0, removed);
338
- }
339
- throw error;
340
- }
341
- this.logger.debug(`Message removed: ${id}, remaining: ${this.queue.length}`);
313
+ await this.refreshFromStore();
314
+ this.logger.debug(`Message removed: ${id}, remaining: ${this.queueSnapshot.length}`);
342
315
  this.eventBus.emit("message:removed", { id, queue: this.queueKind });
343
316
  return true;
344
317
  });
@@ -51,14 +51,13 @@ export declare class MessageQueueService {
51
51
  private sessionId;
52
52
  private store;
53
53
  private queueKind;
54
- private queue;
54
+ private queueSnapshot;
55
55
  private mutationLock;
56
56
  private initialized;
57
57
  private initializationPromise;
58
58
  static createEphemeral(eventBus: SessionEventBus, logger: Logger, sessionId: string, queueKind?: 'steer' | 'follow-up'): MessageQueueService;
59
59
  constructor(eventBus: SessionEventBus, logger: Logger, sessionId: string, store: MessageQueueBackingStore, queueKind?: 'steer' | 'follow-up');
60
60
  initialize(): Promise<void>;
61
- private persistQueue;
62
61
  private refreshFromStore;
63
62
  private runWithMutationLock;
64
63
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"message-queue.d.ts","sourceRoot":"","sources":["../../src/session/message-queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAElF,KAAK,wBAAwB,GAAG,wBAAwB,CAAC;AA4BzD;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC7B,2DAA2D;IAC3D,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,sCAAsC;IACtC,IAAI,CAAC,EAAE,SAAS,GAAG,YAAY,CAAC;CACnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,mBAAmB;IAsBxB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,SAAS;IAzBrB,OAAO,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AAqB;IAGhD,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;YAsBnB,gBAAgB;IAI9B,OAAO,CAAC,mBAAmB;IAS3B;;;;;;OAMG;IACG,OAAO,CACT,OAAO,EAAE,gBAAgB,GAC1B,OAAO,CAAC;QAAE,MAAM,EAAE,IAAI,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAmC1D;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,UAAU,IAAI,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAyBpD;;;OAGG;IACH,OAAO,CAAC,QAAQ;IAoFhB;;OAEG;IACH,UAAU,IAAI,OAAO;IAIf,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAM9B;;OAEG;IACH,YAAY,IAAI,MAAM;IAItB;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B;;;OAGG;IACH,MAAM,IAAI,aAAa,EAAE;IAIzB;;OAEG;IACH,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAK1C;;;OAGG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAe7C"}
@@ -1,18 +1,31 @@
1
1
  import "../chunk-C6A6W6XS.js";
2
2
  import { cloneCoalescedMessage, cloneQueuedMessage, cloneQueuedMessages } from "./queue-clone.js";
3
3
  class EphemeralMessageQueueStore {
4
- async listSessionIds() {
5
- return [];
6
- }
7
- async load(input) {
4
+ queue = [];
5
+ async list(input) {
8
6
  void input;
9
- return [];
7
+ return cloneQueuedMessages(this.queue);
10
8
  }
11
- async save(input) {
12
- void input;
9
+ async append(input) {
10
+ void input.sessionId;
11
+ this.queue = [...this.queue, cloneQueuedMessage(input.message)];
12
+ return { position: this.queue.length };
13
13
  }
14
- async delete(input) {
15
- void input;
14
+ async takeAll(input) {
15
+ void input.sessionId;
16
+ const messages = cloneQueuedMessages(this.queue);
17
+ this.queue = [];
18
+ return messages;
19
+ }
20
+ async remove(input) {
21
+ void input.sessionId;
22
+ const previousLength = this.queue.length;
23
+ this.queue = this.queue.filter((message) => message.id !== input.id);
24
+ return this.queue.length !== previousLength;
25
+ }
26
+ async clear(input) {
27
+ void input.sessionId;
28
+ this.queue = [];
16
29
  }
17
30
  }
18
31
  function generateId() {
@@ -26,7 +39,7 @@ class MessageQueueService {
26
39
  this.store = store;
27
40
  this.queueKind = queueKind;
28
41
  }
29
- queue = [];
42
+ queueSnapshot = [];
30
43
  mutationLock = Promise.resolve();
31
44
  initialized = false;
32
45
  initializationPromise = null;
@@ -44,10 +57,10 @@ class MessageQueueService {
44
57
  if (this.initialized) {
45
58
  return;
46
59
  }
47
- this.queue = await this.store.load({ sessionId: this.sessionId });
48
- if (this.queue.length > 0) {
60
+ this.queueSnapshot = await this.store.list({ sessionId: this.sessionId });
61
+ if (this.queueSnapshot.length > 0) {
49
62
  this.logger.debug(
50
- `Restored ${this.queue.length} queued message(s) for session ${this.sessionId}`
63
+ `Restored ${this.queueSnapshot.length} queued message(s) for session ${this.sessionId}`
51
64
  );
52
65
  }
53
66
  this.initialized = true;
@@ -57,22 +70,8 @@ class MessageQueueService {
57
70
  });
58
71
  await this.initializationPromise;
59
72
  }
60
- async persistQueue() {
61
- await this.store.save({ sessionId: this.sessionId, queue: this.queue });
62
- }
63
73
  async refreshFromStore() {
64
- const storedQueue = await this.store.load({ sessionId: this.sessionId });
65
- const existingIds = new Set(this.queue.map((message) => message.id));
66
- const externalMessages = storedQueue.filter((message) => !existingIds.has(message.id));
67
- if (externalMessages.length === 0) {
68
- return;
69
- }
70
- this.queue = [...this.queue, ...cloneQueuedMessages(externalMessages)].sort(
71
- (left, right) => left.queuedAt - right.queuedAt
72
- );
73
- this.logger.debug(
74
- `Loaded ${externalMessages.length} externally queued message(s) for session ${this.sessionId}`
75
- );
74
+ this.queueSnapshot = await this.store.list({ sessionId: this.sessionId });
76
75
  }
77
76
  runWithMutationLock(fn) {
78
77
  const currentResult = this.mutationLock.catch(() => {
@@ -102,22 +101,20 @@ class MessageQueueService {
102
101
  ...message.kind !== void 0 && { kind: message.kind }
103
102
  };
104
103
  const copiedQueuedMsg = cloneQueuedMessage(queuedMsg);
105
- this.queue.push(copiedQueuedMsg);
106
- try {
107
- await this.persistQueue();
108
- } catch (error) {
109
- this.queue.pop();
110
- throw error;
111
- }
112
- this.logger.debug(`Message queued: ${queuedMsg.id}, position: ${this.queue.length}`);
104
+ const { position } = await this.store.append({
105
+ sessionId: this.sessionId,
106
+ message: copiedQueuedMsg
107
+ });
108
+ await this.refreshFromStore();
109
+ this.logger.debug(`Message queued: ${queuedMsg.id}, position: ${position}`);
113
110
  this.eventBus.emit("message:queued", {
114
- position: this.queue.length,
111
+ position,
115
112
  id: queuedMsg.id,
116
113
  queue: this.queueKind
117
114
  });
118
115
  return {
119
116
  queued: true,
120
- position: this.queue.length,
117
+ position,
121
118
  id: queuedMsg.id
122
119
  };
123
120
  });
@@ -145,16 +142,9 @@ class MessageQueueService {
145
142
  */
146
143
  async dequeueAll() {
147
144
  return await this.runWithMutationLock(async () => {
148
- await this.refreshFromStore();
149
- if (this.queue.length === 0) return null;
150
- const messages = cloneQueuedMessages(this.queue);
151
- this.queue = [];
152
- try {
153
- await this.persistQueue();
154
- } catch (error) {
155
- this.queue = messages;
156
- throw error;
157
- }
145
+ const messages = await this.store.takeAll({ sessionId: this.sessionId });
146
+ this.queueSnapshot = [];
147
+ if (messages.length === 0) return null;
158
148
  const combined = this.coalesce(messages);
159
149
  this.logger.debug(
160
150
  `Dequeued ${messages.length} message(s): ${messages.map((m) => m.id).join(", ")}`
@@ -250,7 +240,7 @@ ${prefixText}`;
250
240
  * Check if there are pending messages in the queue.
251
241
  */
252
242
  hasPending() {
253
- return this.queue.length > 0;
243
+ return this.queueSnapshot.length > 0;
254
244
  }
255
245
  async refresh() {
256
246
  await this.runWithMutationLock(async () => {
@@ -261,7 +251,7 @@ ${prefixText}`;
261
251
  * Get the number of pending messages.
262
252
  */
263
253
  pendingCount() {
264
- return this.queue.length;
254
+ return this.queueSnapshot.length;
265
255
  }
266
256
  /**
267
257
  * Clear all pending messages without processing.
@@ -269,17 +259,8 @@ ${prefixText}`;
269
259
  */
270
260
  async clear() {
271
261
  await this.runWithMutationLock(async () => {
272
- if (this.queue.length === 0) {
273
- return;
274
- }
275
- const previousQueue = [...this.queue];
276
- this.queue = [];
277
- try {
278
- await this.persistQueue();
279
- } catch (error) {
280
- this.queue = previousQueue;
281
- throw error;
282
- }
262
+ await this.store.clear({ sessionId: this.sessionId });
263
+ this.queueSnapshot = [];
283
264
  });
284
265
  }
285
266
  /**
@@ -287,13 +268,13 @@ ${prefixText}`;
287
268
  * Returns defensive copies to prevent external mutation.
288
269
  */
289
270
  getAll() {
290
- return cloneQueuedMessages(this.queue);
271
+ return cloneQueuedMessages(this.queueSnapshot);
291
272
  }
292
273
  /**
293
274
  * Get a single queued message by ID.
294
275
  */
295
276
  get(id) {
296
- const message = this.queue.find((m) => m.id === id);
277
+ const message = this.queueSnapshot.find((m) => m.id === id);
297
278
  return message ? cloneQueuedMessage(message) : void 0;
298
279
  }
299
280
  /**
@@ -302,21 +283,13 @@ ${prefixText}`;
302
283
  */
303
284
  async remove(id) {
304
285
  return await this.runWithMutationLock(async () => {
305
- const index = this.queue.findIndex((m) => m.id === id);
306
- if (index === -1) {
286
+ const removed = await this.store.remove({ sessionId: this.sessionId, id });
287
+ if (!removed) {
307
288
  this.logger.debug(`Remove failed: message ${id} not found in queue`);
308
289
  return false;
309
290
  }
310
- const [removed] = this.queue.splice(index, 1);
311
- try {
312
- await this.persistQueue();
313
- } catch (error) {
314
- if (removed) {
315
- this.queue.splice(index, 0, removed);
316
- }
317
- throw error;
318
- }
319
- this.logger.debug(`Message removed: ${id}, remaining: ${this.queue.length}`);
291
+ await this.refreshFromStore();
292
+ this.logger.debug(`Message removed: ${id}, remaining: ${this.queueSnapshot.length}`);
320
293
  this.eventBus.emit("message:removed", { id, queue: this.queueKind });
321
294
  return true;
322
295
  });