@dudousxd/nestjs-agent-core 0.26.0 → 0.28.0

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.cjs CHANGED
@@ -67,6 +67,7 @@ __export(src_exports, {
67
67
  DefaultRolesPolicy: () => DefaultRolesPolicy,
68
68
  ELICITATION_INPUT_TYPES: () => ELICITATION_INPUT_TYPES,
69
69
  GLOBAL_SCOPE: () => GLOBAL_SCOPE,
70
+ InMemoryAgentStore: () => InMemoryAgentStore,
70
71
  MAX_ASK_QUESTIONS: () => MAX_ASK_QUESTIONS,
71
72
  OutputRejectedError: () => OutputRejectedError,
72
73
  ProcessorFailedError: () => ProcessorFailedError,
@@ -2680,13 +2681,12 @@ var DefaultRolesPolicy = class {
2680
2681
  __name(this, "DefaultRolesPolicy");
2681
2682
  }
2682
2683
  defaultRoles;
2683
- constructor(defaultRoles = [
2684
- "ADMIN"
2685
- ]) {
2684
+ constructor(defaultRoles = []) {
2686
2685
  this.defaultRoles = defaultRoles;
2687
2686
  }
2688
2687
  can(actor, tool) {
2689
2688
  const allowed = tool.roles ?? this.defaultRoles;
2689
+ if (allowed.length === 0) return true;
2690
2690
  return (actor.roles ?? []).some((role) => allowed.includes(role));
2691
2691
  }
2692
2692
  };
@@ -4833,6 +4833,682 @@ ${block}`;
4833
4833
  };
4834
4834
  }
4835
4835
  __name(runAgentLoop, "runAgentLoop");
4836
+
4837
+ // src/in-memory-store.ts
4838
+ var InMemoryAgentStore = class {
4839
+ static {
4840
+ __name(this, "InMemoryAgentStore");
4841
+ }
4842
+ threads = /* @__PURE__ */ new Map();
4843
+ toolCalls = /* @__PURE__ */ new Map();
4844
+ usage = [];
4845
+ runs = /* @__PURE__ */ new Map();
4846
+ now() {
4847
+ return (/* @__PURE__ */ new Date()).toISOString();
4848
+ }
4849
+ async createThread(input) {
4850
+ const id = crypto.randomUUID();
4851
+ const ts = this.now();
4852
+ const row = {
4853
+ id,
4854
+ actorRef: input.actor.id,
4855
+ title: input.title ?? "New chat",
4856
+ transient: input.transient ?? false,
4857
+ createdAt: ts,
4858
+ updatedAt: ts,
4859
+ messages: []
4860
+ };
4861
+ this.threads.set(id, row);
4862
+ return this.toSummary(row);
4863
+ }
4864
+ async getThread(threadId) {
4865
+ const row = this.threads.get(threadId);
4866
+ if (row === void 0) {
4867
+ return null;
4868
+ }
4869
+ return {
4870
+ ...this.toSummary(row),
4871
+ messages: row.messages.map((message) => this.withApprovals(message)),
4872
+ // The run streaming right now — the one field the read-model reports it under.
4873
+ ...row.activeStreamId !== void 0 ? {
4874
+ activeRunId: row.activeStreamId
4875
+ } : {}
4876
+ };
4877
+ }
4878
+ /** A message with the approval record of every call on it that was put to a person. */
4879
+ withApprovals(message) {
4880
+ const approvals = [];
4881
+ for (const call of this.toolCalls.values()) {
4882
+ if (call.messageId !== message.id) {
4883
+ continue;
4884
+ }
4885
+ const approval = toolCallApprovalFromRow({
4886
+ toolCallId: call.toolCallId,
4887
+ status: call.status,
4888
+ approver: call.approver,
4889
+ expiresAt: call.expiresAt,
4890
+ remember: call.remember,
4891
+ executedByRef: call.executedByRef,
4892
+ decidedVia: call.decidedVia,
4893
+ error: call.error
4894
+ });
4895
+ if (approval !== null) {
4896
+ approvals.push(approval);
4897
+ }
4898
+ }
4899
+ return approvals.length > 0 ? {
4900
+ ...message,
4901
+ approvals
4902
+ } : message;
4903
+ }
4904
+ async rememberedApprovals(threadId) {
4905
+ const names = /* @__PURE__ */ new Set();
4906
+ for (const call of this.toolCalls.values()) {
4907
+ if (call.threadId === threadId && call.remember === true) {
4908
+ names.add(call.toolName);
4909
+ }
4910
+ }
4911
+ return [
4912
+ ...names
4913
+ ];
4914
+ }
4915
+ async toolCallInput(toolCallId) {
4916
+ return this.toolCalls.get(toolCallId)?.input ?? null;
4917
+ }
4918
+ async toolCallApproval(toolCallId) {
4919
+ const call = this.toolCalls.get(toolCallId);
4920
+ if (call === void 0) {
4921
+ return null;
4922
+ }
4923
+ return {
4924
+ status: call.status,
4925
+ approver: call.approver ?? null,
4926
+ expiresAt: call.expiresAt ?? null
4927
+ };
4928
+ }
4929
+ async listThreads(actorRef, limit = 50) {
4930
+ return [
4931
+ ...this.threads.values()
4932
+ ].filter((row) => row.actorRef === actorRef && !row.transient).sort((a, b) => b.updatedAt.localeCompare(a.updatedAt)).slice(0, limit).map((row) => this.toSummary(row));
4933
+ }
4934
+ async softDeleteThread(threadId) {
4935
+ this.threads.delete(threadId);
4936
+ }
4937
+ async forkThread(threadId, fromMessageId) {
4938
+ const source = this.threads.get(threadId);
4939
+ if (source === void 0) {
4940
+ throw new Error(`thread ${threadId} not found`);
4941
+ }
4942
+ const cutoff = source.messages.findIndex((message) => message.id === fromMessageId);
4943
+ const kept = cutoff >= 0 ? source.messages.slice(0, cutoff + 1) : [
4944
+ ...source.messages
4945
+ ];
4946
+ const id = crypto.randomUUID();
4947
+ const ts = this.now();
4948
+ const row = {
4949
+ id,
4950
+ actorRef: source.actorRef,
4951
+ title: source.title,
4952
+ transient: false,
4953
+ createdAt: ts,
4954
+ updatedAt: ts,
4955
+ // Feedback rates a message in ITS thread; a fork starts unrated.
4956
+ messages: kept.map(({ feedback: _feedback, ...message }) => ({
4957
+ ...message
4958
+ })),
4959
+ ...source.defaultAgent != null ? {
4960
+ defaultAgent: source.defaultAgent
4961
+ } : {},
4962
+ ...source.model != null ? {
4963
+ model: source.model
4964
+ } : {}
4965
+ };
4966
+ this.threads.set(id, row);
4967
+ return this.toSummary(row);
4968
+ }
4969
+ async ownerOfThread(threadId) {
4970
+ return this.threads.get(threadId)?.actorRef ?? null;
4971
+ }
4972
+ async ownerOfToolCall(toolCallId) {
4973
+ const call = this.toolCalls.get(toolCallId);
4974
+ if (call === void 0) {
4975
+ return null;
4976
+ }
4977
+ return this.threads.get(call.threadId)?.actorRef ?? null;
4978
+ }
4979
+ async runForToolCall(toolCallId) {
4980
+ const call = this.toolCalls.get(toolCallId);
4981
+ if (call === void 0) {
4982
+ return null;
4983
+ }
4984
+ return call.runId ?? this.threads.get(call.threadId)?.activeStreamId ?? null;
4985
+ }
4986
+ async ownerOfActiveStream(runId) {
4987
+ for (const row of this.threads.values()) {
4988
+ if (row.activeStreamId === runId) {
4989
+ return row.actorRef;
4990
+ }
4991
+ }
4992
+ return null;
4993
+ }
4994
+ async setTitle(threadId, title) {
4995
+ const row = this.threads.get(threadId);
4996
+ if (row !== void 0) {
4997
+ row.title = title;
4998
+ row.updatedAt = this.now();
4999
+ }
5000
+ }
5001
+ async updateThread(threadId, patch) {
5002
+ const row = this.threads.get(threadId);
5003
+ if (row === void 0) {
5004
+ return;
5005
+ }
5006
+ if (patch.title !== void 0) {
5007
+ row.title = patch.title;
5008
+ }
5009
+ if (patch.defaultAgent !== void 0) {
5010
+ row.defaultAgent = patch.defaultAgent;
5011
+ }
5012
+ if (patch.model !== void 0) {
5013
+ row.model = patch.model;
5014
+ }
5015
+ row.updatedAt = this.now();
5016
+ }
5017
+ async activeRunForThread(threadId) {
5018
+ return this.threads.get(threadId)?.activeStreamId ?? null;
5019
+ }
5020
+ /**
5021
+ * The thread's default agent, projected. A map lookup here, but the SQL adapters answer this with
5022
+ * a one-column read instead of materializing the whole transcript — so the caller that only needs
5023
+ * this scalar has a method to ask for it.
5024
+ */
5025
+ async defaultAgentForThread(threadId) {
5026
+ return this.threads.get(threadId)?.defaultAgent ?? null;
5027
+ }
5028
+ /** The thread's pinned model, projected like {@link defaultAgentForThread}. */
5029
+ async modelForThread(threadId) {
5030
+ return this.threads.get(threadId)?.model ?? null;
5031
+ }
5032
+ /**
5033
+ * Persist the start of a run (turn). Replay-safe: called under a durable localStep.
5034
+ *
5035
+ * Takes the SPI's own {@link RecordRunStartInput} rather than a hand-copied shape: a field added
5036
+ * to the input is otherwise accepted and dropped, silently, by every adapter that re-declares it.
5037
+ */
5038
+ async recordRunStart(run) {
5039
+ this.runs.set(run.runId, {
5040
+ runId: run.runId,
5041
+ threadId: run.threadId,
5042
+ actorRef: run.actorRef,
5043
+ status: "running",
5044
+ retries: 0,
5045
+ startedAt: this.now(),
5046
+ ...run.agentName !== void 0 ? {
5047
+ agentName: run.agentName
5048
+ } : {},
5049
+ ...run.parentRunId !== void 0 ? {
5050
+ parentRunId: run.parentRunId
5051
+ } : {},
5052
+ ...run.promptHash !== void 0 ? {
5053
+ promptHash: run.promptHash
5054
+ } : {}
5055
+ });
5056
+ }
5057
+ /** Settle a run's outcome. A no-op when the run is unknown (mirrors `setTitle`/`updateThread`). */
5058
+ async recordRunEnd(end) {
5059
+ const row = this.runs.get(end.runId);
5060
+ if (row === void 0) {
5061
+ return;
5062
+ }
5063
+ row.status = end.status;
5064
+ row.settledAt = this.now();
5065
+ if (end.durationMs !== void 0) {
5066
+ row.durationMs = end.durationMs;
5067
+ }
5068
+ if (end.errorCode !== void 0) {
5069
+ row.errorCode = end.errorCode;
5070
+ }
5071
+ if (end.errorMessage !== void 0) {
5072
+ row.errorMessage = end.errorMessage;
5073
+ }
5074
+ }
5075
+ /** Bump the run's llm-step retry counter. */
5076
+ async bumpRunRetries(runId) {
5077
+ const row = this.runs.get(runId);
5078
+ if (row !== void 0) {
5079
+ row.retries += 1;
5080
+ }
5081
+ }
5082
+ async promoteThread(threadId) {
5083
+ const row = this.threads.get(threadId);
5084
+ if (row?.transient) {
5085
+ row.transient = false;
5086
+ row.updatedAt = this.now();
5087
+ }
5088
+ }
5089
+ async setActiveStream(threadId, runId) {
5090
+ const row = this.threads.get(threadId);
5091
+ if (row !== void 0) {
5092
+ if (runId === null) {
5093
+ delete row.activeStreamId;
5094
+ } else {
5095
+ row.activeStreamId = runId;
5096
+ }
5097
+ }
5098
+ }
5099
+ async appendMessage(input) {
5100
+ const row = this.threads.get(input.threadId);
5101
+ if (row === void 0) {
5102
+ throw new Error(`thread ${input.threadId} not found`);
5103
+ }
5104
+ const message = {
5105
+ id: crypto.randomUUID(),
5106
+ role: input.role,
5107
+ content: input.content,
5108
+ createdAt: this.now(),
5109
+ ...input.toolCalls !== void 0 ? {
5110
+ toolCalls: input.toolCalls
5111
+ } : {},
5112
+ ...input.toolResults !== void 0 ? {
5113
+ toolResults: input.toolResults
5114
+ } : {},
5115
+ ...input.attachments !== void 0 ? {
5116
+ attachments: input.attachments
5117
+ } : {},
5118
+ ...input.followUps !== void 0 ? {
5119
+ followUps: input.followUps
5120
+ } : {},
5121
+ ...input.usage !== void 0 ? {
5122
+ usage: input.usage
5123
+ } : {},
5124
+ ...input.agentName !== void 0 ? {
5125
+ agentName: input.agentName
5126
+ } : {},
5127
+ ...input.runId !== void 0 ? {
5128
+ runId: input.runId
5129
+ } : {},
5130
+ ...input.reasoning !== void 0 ? {
5131
+ reasoning: input.reasoning
5132
+ } : {},
5133
+ ...input.reasoningMs !== void 0 ? {
5134
+ reasoningMs: input.reasoningMs
5135
+ } : {},
5136
+ ...input.ui !== void 0 ? {
5137
+ ui: input.ui
5138
+ } : {}
5139
+ };
5140
+ row.messages.push(message);
5141
+ row.updatedAt = message.createdAt;
5142
+ return message;
5143
+ }
5144
+ async setMessageToolResults(messageId, results) {
5145
+ for (const row of this.threads.values()) {
5146
+ const message = row.messages.find((candidate) => candidate.id === messageId);
5147
+ if (message !== void 0) {
5148
+ message.toolResults = results;
5149
+ return;
5150
+ }
5151
+ }
5152
+ }
5153
+ async setMessageUi(messageId, ui) {
5154
+ for (const row of this.threads.values()) {
5155
+ const index = row.messages.findIndex((candidate) => candidate.id === messageId);
5156
+ const message = row.messages[index];
5157
+ if (message !== void 0) {
5158
+ const { ui: _previous, ...rest } = message;
5159
+ row.messages[index] = ui.length > 0 ? {
5160
+ ...rest,
5161
+ ui
5162
+ } : rest;
5163
+ return;
5164
+ }
5165
+ }
5166
+ }
5167
+ async threadOfMessage(messageId) {
5168
+ return this.threadIdForMessage(messageId) ?? null;
5169
+ }
5170
+ async setMessageFeedback(messageId, feedback) {
5171
+ for (const row of this.threads.values()) {
5172
+ const index = row.messages.findIndex((candidate) => candidate.id === messageId);
5173
+ const message = row.messages[index];
5174
+ if (message !== void 0) {
5175
+ const { feedback: _previous, ...rest } = message;
5176
+ row.messages[index] = feedback !== null ? {
5177
+ ...rest,
5178
+ feedback
5179
+ } : rest;
5180
+ return;
5181
+ }
5182
+ }
5183
+ }
5184
+ async truncateFrom(threadId, messageId) {
5185
+ const row = this.threads.get(threadId);
5186
+ if (row === void 0) {
5187
+ return;
5188
+ }
5189
+ const cutoff = row.messages.findIndex((message) => message.id === messageId);
5190
+ if (cutoff >= 0) {
5191
+ row.messages = row.messages.slice(0, cutoff);
5192
+ }
5193
+ }
5194
+ /**
5195
+ * Of `mediaIds`, the ones a surviving message in one of this actor's threads still carries.
5196
+ * Re-derived from the messages each call, so a media whose message was truncated away reads as
5197
+ * unreferenced again.
5198
+ */
5199
+ async referencedMediaIds(actorRef, mediaIds) {
5200
+ if (mediaIds.length === 0) {
5201
+ return [];
5202
+ }
5203
+ const wanted = new Set(mediaIds);
5204
+ const found = /* @__PURE__ */ new Set();
5205
+ for (const thread of this.threads.values()) {
5206
+ if (thread.actorRef !== actorRef) {
5207
+ continue;
5208
+ }
5209
+ for (const message of thread.messages) {
5210
+ for (const attachment of message.attachments ?? []) {
5211
+ if (wanted.has(attachment.mediaId)) {
5212
+ found.add(attachment.mediaId);
5213
+ }
5214
+ }
5215
+ }
5216
+ }
5217
+ return [
5218
+ ...wanted
5219
+ ].filter((mediaId) => found.has(mediaId));
5220
+ }
5221
+ async recordToolCall(input) {
5222
+ this.toolCalls.set(input.toolCallId, {
5223
+ toolCallId: input.toolCallId,
5224
+ messageId: input.messageId,
5225
+ threadId: this.threadIdForMessage(input.messageId) ?? "",
5226
+ toolName: input.toolName,
5227
+ toolType: input.toolType,
5228
+ input: input.input,
5229
+ status: input.status,
5230
+ createdAt: this.now(),
5231
+ ...input.runId !== void 0 ? {
5232
+ runId: input.runId
5233
+ } : {},
5234
+ ...input.approver !== void 0 ? {
5235
+ approver: input.approver
5236
+ } : {},
5237
+ ...input.expiresAt !== void 0 ? {
5238
+ expiresAt: input.expiresAt
5239
+ } : {}
5240
+ });
5241
+ }
5242
+ async updateToolCall(input) {
5243
+ const row = this.toolCalls.get(input.toolCallId);
5244
+ if (row === void 0) {
5245
+ return;
5246
+ }
5247
+ row.status = input.status;
5248
+ if (input.output !== void 0) {
5249
+ row.output = input.output;
5250
+ }
5251
+ if (input.error !== void 0) {
5252
+ row.error = input.error;
5253
+ }
5254
+ if (input.executionMs !== void 0) {
5255
+ row.executionMs = input.executionMs;
5256
+ }
5257
+ if (input.executedByRef !== void 0) {
5258
+ row.executedByRef = input.executedByRef;
5259
+ }
5260
+ if (input.remember !== void 0) {
5261
+ row.remember = input.remember;
5262
+ }
5263
+ if (input.decidedVia !== void 0) {
5264
+ row.decidedVia = input.decidedVia;
5265
+ }
5266
+ }
5267
+ async recordUsage(input) {
5268
+ const createdAt = this.now();
5269
+ this.usage.push({
5270
+ actorRef: input.actorRef,
5271
+ threadId: input.threadId,
5272
+ modelId: input.modelId,
5273
+ inputTokens: input.usage.inputTokens,
5274
+ outputTokens: input.usage.outputTokens,
5275
+ day: createdAt.slice(0, 10),
5276
+ createdAt,
5277
+ ...input.usage.cacheWriteTokens !== void 0 ? {
5278
+ cacheWriteTokens: input.usage.cacheWriteTokens
5279
+ } : {},
5280
+ ...input.usage.cacheReadTokens !== void 0 ? {
5281
+ cacheReadTokens: input.usage.cacheReadTokens
5282
+ } : {},
5283
+ ...input.costUsd !== void 0 ? {
5284
+ costUsd: input.costUsd
5285
+ } : {}
5286
+ });
5287
+ }
5288
+ async quotaToday(actorRef, day) {
5289
+ return this.usageBetween(actorRef, day, day);
5290
+ }
5291
+ async usageBetween(actorRef, fromDay, toDay) {
5292
+ const rows = this.usage.filter((row) => row.actorRef === actorRef && row.day >= fromDay && row.day <= toDay);
5293
+ const usedTokens = rows.reduce((sum, row) => sum + row.inputTokens + row.outputTokens, 0);
5294
+ const costUsd = rows.reduce((sum, row) => sum + (row.costUsd ?? 0), 0);
5295
+ return {
5296
+ usedTokens,
5297
+ costUsd
5298
+ };
5299
+ }
5300
+ /** Test helper: read the recorded usage rows (modelId + token totals). */
5301
+ usageRows() {
5302
+ return this.usage.map((row) => ({
5303
+ actorRef: row.actorRef,
5304
+ tokens: row.inputTokens + row.outputTokens,
5305
+ modelId: row.modelId
5306
+ }));
5307
+ }
5308
+ /** Governance read-model feed: recorded usage rows with the input/output split + thread/day. */
5309
+ governanceUsage() {
5310
+ return this.usage.map((row) => ({
5311
+ actorRef: row.actorRef,
5312
+ threadId: row.threadId,
5313
+ modelId: row.modelId,
5314
+ inputTokens: row.inputTokens,
5315
+ outputTokens: row.outputTokens,
5316
+ day: row.day,
5317
+ createdAt: row.createdAt,
5318
+ ...row.cacheWriteTokens !== void 0 ? {
5319
+ cacheWriteTokens: row.cacheWriteTokens
5320
+ } : {},
5321
+ ...row.cacheReadTokens !== void 0 ? {
5322
+ cacheReadTokens: row.cacheReadTokens
5323
+ } : {},
5324
+ ...row.costUsd !== void 0 ? {
5325
+ costUsd: row.costUsd
5326
+ } : {}
5327
+ }));
5328
+ }
5329
+ /** Governance read-model feed: recorded tool calls with the resolved thread + timestamp. */
5330
+ governanceToolCalls() {
5331
+ return [
5332
+ ...this.toolCalls.values()
5333
+ ].map((row) => ({
5334
+ toolCallId: row.toolCallId,
5335
+ toolName: row.toolName,
5336
+ toolType: row.toolType,
5337
+ status: row.status,
5338
+ threadId: row.threadId,
5339
+ messageId: row.messageId,
5340
+ createdAt: row.createdAt,
5341
+ ...row.executionMs !== void 0 ? {
5342
+ executionMs: row.executionMs
5343
+ } : {},
5344
+ ...row.error !== void 0 ? {
5345
+ error: row.error
5346
+ } : {},
5347
+ ...row.runId !== void 0 ? {
5348
+ runId: row.runId
5349
+ } : {}
5350
+ }));
5351
+ }
5352
+ /** Governance read-model feed: every stored message, thread-resolved, for the thread drill-down. */
5353
+ governanceMessages() {
5354
+ const rows = [];
5355
+ for (const thread of this.threads.values()) {
5356
+ for (const message of thread.messages) {
5357
+ rows.push({
5358
+ messageId: message.id,
5359
+ threadId: thread.id,
5360
+ role: message.role,
5361
+ content: message.content,
5362
+ createdAt: message.createdAt,
5363
+ ...message.agentName !== void 0 ? {
5364
+ agentName: message.agentName
5365
+ } : {}
5366
+ });
5367
+ }
5368
+ }
5369
+ return rows;
5370
+ }
5371
+ /**
5372
+ * Governance read-model feed: tool calls sitting `pending_approval`, joined to their thread
5373
+ * (title/actorRef) and the message that requested them (`agentName`, when the message has one).
5374
+ */
5375
+ governancePendingApprovals() {
5376
+ const rows = [];
5377
+ for (const call of this.toolCalls.values()) {
5378
+ if (call.status !== "pending_approval") {
5379
+ continue;
5380
+ }
5381
+ const thread = this.threads.get(call.threadId);
5382
+ if (thread === void 0) {
5383
+ continue;
5384
+ }
5385
+ const message = thread.messages.find((candidate) => candidate.id === call.messageId);
5386
+ rows.push({
5387
+ toolCallId: call.toolCallId,
5388
+ toolName: call.toolName,
5389
+ input: call.input,
5390
+ threadId: call.threadId,
5391
+ threadTitle: thread.title,
5392
+ actorRef: thread.actorRef,
5393
+ requestedAt: call.createdAt,
5394
+ ...message?.agentName !== void 0 ? {
5395
+ agentName: message.agentName
5396
+ } : {},
5397
+ ...call.runId !== void 0 ? {
5398
+ runId: call.runId
5399
+ } : {}
5400
+ });
5401
+ }
5402
+ return rows;
5403
+ }
5404
+ /** Governance read-model feed: thread metadata (title/actor/message count/last activity). */
5405
+ governanceThreads() {
5406
+ return [
5407
+ ...this.threads.values()
5408
+ ].map((row) => ({
5409
+ threadId: row.id,
5410
+ title: row.title,
5411
+ actorRef: row.actorRef,
5412
+ messageCount: row.messages.length,
5413
+ updatedAt: row.updatedAt
5414
+ }));
5415
+ }
5416
+ /** Governance read-model feed: recorded run outcomes (the reliability surfaces). */
5417
+ governanceRuns() {
5418
+ return [
5419
+ ...this.runs.values()
5420
+ ].map((row) => ({
5421
+ runId: row.runId,
5422
+ threadId: row.threadId,
5423
+ actorRef: row.actorRef,
5424
+ status: row.status,
5425
+ retries: row.retries,
5426
+ startedAt: row.startedAt,
5427
+ ...row.agentName !== void 0 ? {
5428
+ agentName: row.agentName
5429
+ } : {},
5430
+ ...row.parentRunId !== void 0 ? {
5431
+ parentRunId: row.parentRunId
5432
+ } : {},
5433
+ ...row.durationMs !== void 0 ? {
5434
+ durationMs: row.durationMs
5435
+ } : {},
5436
+ ...row.errorCode !== void 0 ? {
5437
+ errorCode: row.errorCode
5438
+ } : {},
5439
+ ...row.errorMessage !== void 0 ? {
5440
+ errorMessage: row.errorMessage
5441
+ } : {},
5442
+ ...row.settledAt !== void 0 ? {
5443
+ settledAt: row.settledAt
5444
+ } : {},
5445
+ ...row.promptHash !== void 0 ? {
5446
+ promptHash: row.promptHash
5447
+ } : {}
5448
+ }));
5449
+ }
5450
+ threadIdForMessage(messageId) {
5451
+ for (const [threadId, row] of this.threads) {
5452
+ if (row.messages.some((message) => message.id === messageId)) {
5453
+ return threadId;
5454
+ }
5455
+ }
5456
+ return void 0;
5457
+ }
5458
+ /** Test helper: read the recorded tool-call rows. */
5459
+ toolCallRows() {
5460
+ return [
5461
+ ...this.toolCalls.values()
5462
+ ].map((row) => ({
5463
+ toolCallId: row.toolCallId,
5464
+ toolName: row.toolName,
5465
+ toolType: row.toolType,
5466
+ status: row.status,
5467
+ input: row.input,
5468
+ ...row.output !== void 0 ? {
5469
+ output: row.output
5470
+ } : {},
5471
+ ...row.error !== void 0 ? {
5472
+ error: row.error
5473
+ } : {},
5474
+ ...row.runId !== void 0 ? {
5475
+ runId: row.runId
5476
+ } : {},
5477
+ ...row.executedByRef !== void 0 ? {
5478
+ executedByRef: row.executedByRef
5479
+ } : {},
5480
+ ...row.approver !== void 0 ? {
5481
+ approver: row.approver
5482
+ } : {},
5483
+ ...row.expiresAt !== void 0 ? {
5484
+ expiresAt: row.expiresAt
5485
+ } : {},
5486
+ ...row.remember !== void 0 ? {
5487
+ remember: row.remember
5488
+ } : {},
5489
+ ...row.decidedVia !== void 0 ? {
5490
+ decidedVia: row.decidedVia
5491
+ } : {}
5492
+ }));
5493
+ }
5494
+ toSummary(row) {
5495
+ const last = row.messages[row.messages.length - 1];
5496
+ return {
5497
+ id: row.id,
5498
+ title: row.title,
5499
+ transient: row.transient,
5500
+ createdAt: row.createdAt,
5501
+ updatedAt: row.updatedAt,
5502
+ ...last !== void 0 ? {
5503
+ lastMessagePreview: last.content.slice(0, 120)
5504
+ } : {},
5505
+ defaultAgent: row.defaultAgent ?? null,
5506
+ ...row.model != null ? {
5507
+ model: row.model
5508
+ } : {}
5509
+ };
5510
+ }
5511
+ };
4836
5512
  // Annotate the CommonJS export names for ESM import in node:
4837
5513
  0 && (module.exports = {
4838
5514
  AGENT_ACTOR_DIRECTORY,
@@ -4881,6 +5557,7 @@ __name(runAgentLoop, "runAgentLoop");
4881
5557
  DefaultRolesPolicy,
4882
5558
  ELICITATION_INPUT_TYPES,
4883
5559
  GLOBAL_SCOPE,
5560
+ InMemoryAgentStore,
4884
5561
  MAX_ASK_QUESTIONS,
4885
5562
  OutputRejectedError,
4886
5563
  ProcessorFailedError,