@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.js CHANGED
@@ -2482,13 +2482,12 @@ var DefaultRolesPolicy = class {
2482
2482
  __name(this, "DefaultRolesPolicy");
2483
2483
  }
2484
2484
  defaultRoles;
2485
- constructor(defaultRoles = [
2486
- "ADMIN"
2487
- ]) {
2485
+ constructor(defaultRoles = []) {
2488
2486
  this.defaultRoles = defaultRoles;
2489
2487
  }
2490
2488
  can(actor, tool) {
2491
2489
  const allowed = tool.roles ?? this.defaultRoles;
2490
+ if (allowed.length === 0) return true;
2492
2491
  return (actor.roles ?? []).some((role) => allowed.includes(role));
2493
2492
  }
2494
2493
  };
@@ -4635,6 +4634,682 @@ ${block}`;
4635
4634
  };
4636
4635
  }
4637
4636
  __name(runAgentLoop, "runAgentLoop");
4637
+
4638
+ // src/in-memory-store.ts
4639
+ var InMemoryAgentStore = class {
4640
+ static {
4641
+ __name(this, "InMemoryAgentStore");
4642
+ }
4643
+ threads = /* @__PURE__ */ new Map();
4644
+ toolCalls = /* @__PURE__ */ new Map();
4645
+ usage = [];
4646
+ runs = /* @__PURE__ */ new Map();
4647
+ now() {
4648
+ return (/* @__PURE__ */ new Date()).toISOString();
4649
+ }
4650
+ async createThread(input) {
4651
+ const id = crypto.randomUUID();
4652
+ const ts = this.now();
4653
+ const row = {
4654
+ id,
4655
+ actorRef: input.actor.id,
4656
+ title: input.title ?? "New chat",
4657
+ transient: input.transient ?? false,
4658
+ createdAt: ts,
4659
+ updatedAt: ts,
4660
+ messages: []
4661
+ };
4662
+ this.threads.set(id, row);
4663
+ return this.toSummary(row);
4664
+ }
4665
+ async getThread(threadId) {
4666
+ const row = this.threads.get(threadId);
4667
+ if (row === void 0) {
4668
+ return null;
4669
+ }
4670
+ return {
4671
+ ...this.toSummary(row),
4672
+ messages: row.messages.map((message) => this.withApprovals(message)),
4673
+ // The run streaming right now — the one field the read-model reports it under.
4674
+ ...row.activeStreamId !== void 0 ? {
4675
+ activeRunId: row.activeStreamId
4676
+ } : {}
4677
+ };
4678
+ }
4679
+ /** A message with the approval record of every call on it that was put to a person. */
4680
+ withApprovals(message) {
4681
+ const approvals = [];
4682
+ for (const call of this.toolCalls.values()) {
4683
+ if (call.messageId !== message.id) {
4684
+ continue;
4685
+ }
4686
+ const approval = toolCallApprovalFromRow({
4687
+ toolCallId: call.toolCallId,
4688
+ status: call.status,
4689
+ approver: call.approver,
4690
+ expiresAt: call.expiresAt,
4691
+ remember: call.remember,
4692
+ executedByRef: call.executedByRef,
4693
+ decidedVia: call.decidedVia,
4694
+ error: call.error
4695
+ });
4696
+ if (approval !== null) {
4697
+ approvals.push(approval);
4698
+ }
4699
+ }
4700
+ return approvals.length > 0 ? {
4701
+ ...message,
4702
+ approvals
4703
+ } : message;
4704
+ }
4705
+ async rememberedApprovals(threadId) {
4706
+ const names = /* @__PURE__ */ new Set();
4707
+ for (const call of this.toolCalls.values()) {
4708
+ if (call.threadId === threadId && call.remember === true) {
4709
+ names.add(call.toolName);
4710
+ }
4711
+ }
4712
+ return [
4713
+ ...names
4714
+ ];
4715
+ }
4716
+ async toolCallInput(toolCallId) {
4717
+ return this.toolCalls.get(toolCallId)?.input ?? null;
4718
+ }
4719
+ async toolCallApproval(toolCallId) {
4720
+ const call = this.toolCalls.get(toolCallId);
4721
+ if (call === void 0) {
4722
+ return null;
4723
+ }
4724
+ return {
4725
+ status: call.status,
4726
+ approver: call.approver ?? null,
4727
+ expiresAt: call.expiresAt ?? null
4728
+ };
4729
+ }
4730
+ async listThreads(actorRef, limit = 50) {
4731
+ return [
4732
+ ...this.threads.values()
4733
+ ].filter((row) => row.actorRef === actorRef && !row.transient).sort((a, b) => b.updatedAt.localeCompare(a.updatedAt)).slice(0, limit).map((row) => this.toSummary(row));
4734
+ }
4735
+ async softDeleteThread(threadId) {
4736
+ this.threads.delete(threadId);
4737
+ }
4738
+ async forkThread(threadId, fromMessageId) {
4739
+ const source = this.threads.get(threadId);
4740
+ if (source === void 0) {
4741
+ throw new Error(`thread ${threadId} not found`);
4742
+ }
4743
+ const cutoff = source.messages.findIndex((message) => message.id === fromMessageId);
4744
+ const kept = cutoff >= 0 ? source.messages.slice(0, cutoff + 1) : [
4745
+ ...source.messages
4746
+ ];
4747
+ const id = crypto.randomUUID();
4748
+ const ts = this.now();
4749
+ const row = {
4750
+ id,
4751
+ actorRef: source.actorRef,
4752
+ title: source.title,
4753
+ transient: false,
4754
+ createdAt: ts,
4755
+ updatedAt: ts,
4756
+ // Feedback rates a message in ITS thread; a fork starts unrated.
4757
+ messages: kept.map(({ feedback: _feedback, ...message }) => ({
4758
+ ...message
4759
+ })),
4760
+ ...source.defaultAgent != null ? {
4761
+ defaultAgent: source.defaultAgent
4762
+ } : {},
4763
+ ...source.model != null ? {
4764
+ model: source.model
4765
+ } : {}
4766
+ };
4767
+ this.threads.set(id, row);
4768
+ return this.toSummary(row);
4769
+ }
4770
+ async ownerOfThread(threadId) {
4771
+ return this.threads.get(threadId)?.actorRef ?? null;
4772
+ }
4773
+ async ownerOfToolCall(toolCallId) {
4774
+ const call = this.toolCalls.get(toolCallId);
4775
+ if (call === void 0) {
4776
+ return null;
4777
+ }
4778
+ return this.threads.get(call.threadId)?.actorRef ?? null;
4779
+ }
4780
+ async runForToolCall(toolCallId) {
4781
+ const call = this.toolCalls.get(toolCallId);
4782
+ if (call === void 0) {
4783
+ return null;
4784
+ }
4785
+ return call.runId ?? this.threads.get(call.threadId)?.activeStreamId ?? null;
4786
+ }
4787
+ async ownerOfActiveStream(runId) {
4788
+ for (const row of this.threads.values()) {
4789
+ if (row.activeStreamId === runId) {
4790
+ return row.actorRef;
4791
+ }
4792
+ }
4793
+ return null;
4794
+ }
4795
+ async setTitle(threadId, title) {
4796
+ const row = this.threads.get(threadId);
4797
+ if (row !== void 0) {
4798
+ row.title = title;
4799
+ row.updatedAt = this.now();
4800
+ }
4801
+ }
4802
+ async updateThread(threadId, patch) {
4803
+ const row = this.threads.get(threadId);
4804
+ if (row === void 0) {
4805
+ return;
4806
+ }
4807
+ if (patch.title !== void 0) {
4808
+ row.title = patch.title;
4809
+ }
4810
+ if (patch.defaultAgent !== void 0) {
4811
+ row.defaultAgent = patch.defaultAgent;
4812
+ }
4813
+ if (patch.model !== void 0) {
4814
+ row.model = patch.model;
4815
+ }
4816
+ row.updatedAt = this.now();
4817
+ }
4818
+ async activeRunForThread(threadId) {
4819
+ return this.threads.get(threadId)?.activeStreamId ?? null;
4820
+ }
4821
+ /**
4822
+ * The thread's default agent, projected. A map lookup here, but the SQL adapters answer this with
4823
+ * a one-column read instead of materializing the whole transcript — so the caller that only needs
4824
+ * this scalar has a method to ask for it.
4825
+ */
4826
+ async defaultAgentForThread(threadId) {
4827
+ return this.threads.get(threadId)?.defaultAgent ?? null;
4828
+ }
4829
+ /** The thread's pinned model, projected like {@link defaultAgentForThread}. */
4830
+ async modelForThread(threadId) {
4831
+ return this.threads.get(threadId)?.model ?? null;
4832
+ }
4833
+ /**
4834
+ * Persist the start of a run (turn). Replay-safe: called under a durable localStep.
4835
+ *
4836
+ * Takes the SPI's own {@link RecordRunStartInput} rather than a hand-copied shape: a field added
4837
+ * to the input is otherwise accepted and dropped, silently, by every adapter that re-declares it.
4838
+ */
4839
+ async recordRunStart(run) {
4840
+ this.runs.set(run.runId, {
4841
+ runId: run.runId,
4842
+ threadId: run.threadId,
4843
+ actorRef: run.actorRef,
4844
+ status: "running",
4845
+ retries: 0,
4846
+ startedAt: this.now(),
4847
+ ...run.agentName !== void 0 ? {
4848
+ agentName: run.agentName
4849
+ } : {},
4850
+ ...run.parentRunId !== void 0 ? {
4851
+ parentRunId: run.parentRunId
4852
+ } : {},
4853
+ ...run.promptHash !== void 0 ? {
4854
+ promptHash: run.promptHash
4855
+ } : {}
4856
+ });
4857
+ }
4858
+ /** Settle a run's outcome. A no-op when the run is unknown (mirrors `setTitle`/`updateThread`). */
4859
+ async recordRunEnd(end) {
4860
+ const row = this.runs.get(end.runId);
4861
+ if (row === void 0) {
4862
+ return;
4863
+ }
4864
+ row.status = end.status;
4865
+ row.settledAt = this.now();
4866
+ if (end.durationMs !== void 0) {
4867
+ row.durationMs = end.durationMs;
4868
+ }
4869
+ if (end.errorCode !== void 0) {
4870
+ row.errorCode = end.errorCode;
4871
+ }
4872
+ if (end.errorMessage !== void 0) {
4873
+ row.errorMessage = end.errorMessage;
4874
+ }
4875
+ }
4876
+ /** Bump the run's llm-step retry counter. */
4877
+ async bumpRunRetries(runId) {
4878
+ const row = this.runs.get(runId);
4879
+ if (row !== void 0) {
4880
+ row.retries += 1;
4881
+ }
4882
+ }
4883
+ async promoteThread(threadId) {
4884
+ const row = this.threads.get(threadId);
4885
+ if (row?.transient) {
4886
+ row.transient = false;
4887
+ row.updatedAt = this.now();
4888
+ }
4889
+ }
4890
+ async setActiveStream(threadId, runId) {
4891
+ const row = this.threads.get(threadId);
4892
+ if (row !== void 0) {
4893
+ if (runId === null) {
4894
+ delete row.activeStreamId;
4895
+ } else {
4896
+ row.activeStreamId = runId;
4897
+ }
4898
+ }
4899
+ }
4900
+ async appendMessage(input) {
4901
+ const row = this.threads.get(input.threadId);
4902
+ if (row === void 0) {
4903
+ throw new Error(`thread ${input.threadId} not found`);
4904
+ }
4905
+ const message = {
4906
+ id: crypto.randomUUID(),
4907
+ role: input.role,
4908
+ content: input.content,
4909
+ createdAt: this.now(),
4910
+ ...input.toolCalls !== void 0 ? {
4911
+ toolCalls: input.toolCalls
4912
+ } : {},
4913
+ ...input.toolResults !== void 0 ? {
4914
+ toolResults: input.toolResults
4915
+ } : {},
4916
+ ...input.attachments !== void 0 ? {
4917
+ attachments: input.attachments
4918
+ } : {},
4919
+ ...input.followUps !== void 0 ? {
4920
+ followUps: input.followUps
4921
+ } : {},
4922
+ ...input.usage !== void 0 ? {
4923
+ usage: input.usage
4924
+ } : {},
4925
+ ...input.agentName !== void 0 ? {
4926
+ agentName: input.agentName
4927
+ } : {},
4928
+ ...input.runId !== void 0 ? {
4929
+ runId: input.runId
4930
+ } : {},
4931
+ ...input.reasoning !== void 0 ? {
4932
+ reasoning: input.reasoning
4933
+ } : {},
4934
+ ...input.reasoningMs !== void 0 ? {
4935
+ reasoningMs: input.reasoningMs
4936
+ } : {},
4937
+ ...input.ui !== void 0 ? {
4938
+ ui: input.ui
4939
+ } : {}
4940
+ };
4941
+ row.messages.push(message);
4942
+ row.updatedAt = message.createdAt;
4943
+ return message;
4944
+ }
4945
+ async setMessageToolResults(messageId, results) {
4946
+ for (const row of this.threads.values()) {
4947
+ const message = row.messages.find((candidate) => candidate.id === messageId);
4948
+ if (message !== void 0) {
4949
+ message.toolResults = results;
4950
+ return;
4951
+ }
4952
+ }
4953
+ }
4954
+ async setMessageUi(messageId, ui) {
4955
+ for (const row of this.threads.values()) {
4956
+ const index = row.messages.findIndex((candidate) => candidate.id === messageId);
4957
+ const message = row.messages[index];
4958
+ if (message !== void 0) {
4959
+ const { ui: _previous, ...rest } = message;
4960
+ row.messages[index] = ui.length > 0 ? {
4961
+ ...rest,
4962
+ ui
4963
+ } : rest;
4964
+ return;
4965
+ }
4966
+ }
4967
+ }
4968
+ async threadOfMessage(messageId) {
4969
+ return this.threadIdForMessage(messageId) ?? null;
4970
+ }
4971
+ async setMessageFeedback(messageId, feedback) {
4972
+ for (const row of this.threads.values()) {
4973
+ const index = row.messages.findIndex((candidate) => candidate.id === messageId);
4974
+ const message = row.messages[index];
4975
+ if (message !== void 0) {
4976
+ const { feedback: _previous, ...rest } = message;
4977
+ row.messages[index] = feedback !== null ? {
4978
+ ...rest,
4979
+ feedback
4980
+ } : rest;
4981
+ return;
4982
+ }
4983
+ }
4984
+ }
4985
+ async truncateFrom(threadId, messageId) {
4986
+ const row = this.threads.get(threadId);
4987
+ if (row === void 0) {
4988
+ return;
4989
+ }
4990
+ const cutoff = row.messages.findIndex((message) => message.id === messageId);
4991
+ if (cutoff >= 0) {
4992
+ row.messages = row.messages.slice(0, cutoff);
4993
+ }
4994
+ }
4995
+ /**
4996
+ * Of `mediaIds`, the ones a surviving message in one of this actor's threads still carries.
4997
+ * Re-derived from the messages each call, so a media whose message was truncated away reads as
4998
+ * unreferenced again.
4999
+ */
5000
+ async referencedMediaIds(actorRef, mediaIds) {
5001
+ if (mediaIds.length === 0) {
5002
+ return [];
5003
+ }
5004
+ const wanted = new Set(mediaIds);
5005
+ const found = /* @__PURE__ */ new Set();
5006
+ for (const thread of this.threads.values()) {
5007
+ if (thread.actorRef !== actorRef) {
5008
+ continue;
5009
+ }
5010
+ for (const message of thread.messages) {
5011
+ for (const attachment of message.attachments ?? []) {
5012
+ if (wanted.has(attachment.mediaId)) {
5013
+ found.add(attachment.mediaId);
5014
+ }
5015
+ }
5016
+ }
5017
+ }
5018
+ return [
5019
+ ...wanted
5020
+ ].filter((mediaId) => found.has(mediaId));
5021
+ }
5022
+ async recordToolCall(input) {
5023
+ this.toolCalls.set(input.toolCallId, {
5024
+ toolCallId: input.toolCallId,
5025
+ messageId: input.messageId,
5026
+ threadId: this.threadIdForMessage(input.messageId) ?? "",
5027
+ toolName: input.toolName,
5028
+ toolType: input.toolType,
5029
+ input: input.input,
5030
+ status: input.status,
5031
+ createdAt: this.now(),
5032
+ ...input.runId !== void 0 ? {
5033
+ runId: input.runId
5034
+ } : {},
5035
+ ...input.approver !== void 0 ? {
5036
+ approver: input.approver
5037
+ } : {},
5038
+ ...input.expiresAt !== void 0 ? {
5039
+ expiresAt: input.expiresAt
5040
+ } : {}
5041
+ });
5042
+ }
5043
+ async updateToolCall(input) {
5044
+ const row = this.toolCalls.get(input.toolCallId);
5045
+ if (row === void 0) {
5046
+ return;
5047
+ }
5048
+ row.status = input.status;
5049
+ if (input.output !== void 0) {
5050
+ row.output = input.output;
5051
+ }
5052
+ if (input.error !== void 0) {
5053
+ row.error = input.error;
5054
+ }
5055
+ if (input.executionMs !== void 0) {
5056
+ row.executionMs = input.executionMs;
5057
+ }
5058
+ if (input.executedByRef !== void 0) {
5059
+ row.executedByRef = input.executedByRef;
5060
+ }
5061
+ if (input.remember !== void 0) {
5062
+ row.remember = input.remember;
5063
+ }
5064
+ if (input.decidedVia !== void 0) {
5065
+ row.decidedVia = input.decidedVia;
5066
+ }
5067
+ }
5068
+ async recordUsage(input) {
5069
+ const createdAt = this.now();
5070
+ this.usage.push({
5071
+ actorRef: input.actorRef,
5072
+ threadId: input.threadId,
5073
+ modelId: input.modelId,
5074
+ inputTokens: input.usage.inputTokens,
5075
+ outputTokens: input.usage.outputTokens,
5076
+ day: createdAt.slice(0, 10),
5077
+ createdAt,
5078
+ ...input.usage.cacheWriteTokens !== void 0 ? {
5079
+ cacheWriteTokens: input.usage.cacheWriteTokens
5080
+ } : {},
5081
+ ...input.usage.cacheReadTokens !== void 0 ? {
5082
+ cacheReadTokens: input.usage.cacheReadTokens
5083
+ } : {},
5084
+ ...input.costUsd !== void 0 ? {
5085
+ costUsd: input.costUsd
5086
+ } : {}
5087
+ });
5088
+ }
5089
+ async quotaToday(actorRef, day) {
5090
+ return this.usageBetween(actorRef, day, day);
5091
+ }
5092
+ async usageBetween(actorRef, fromDay, toDay) {
5093
+ const rows = this.usage.filter((row) => row.actorRef === actorRef && row.day >= fromDay && row.day <= toDay);
5094
+ const usedTokens = rows.reduce((sum, row) => sum + row.inputTokens + row.outputTokens, 0);
5095
+ const costUsd = rows.reduce((sum, row) => sum + (row.costUsd ?? 0), 0);
5096
+ return {
5097
+ usedTokens,
5098
+ costUsd
5099
+ };
5100
+ }
5101
+ /** Test helper: read the recorded usage rows (modelId + token totals). */
5102
+ usageRows() {
5103
+ return this.usage.map((row) => ({
5104
+ actorRef: row.actorRef,
5105
+ tokens: row.inputTokens + row.outputTokens,
5106
+ modelId: row.modelId
5107
+ }));
5108
+ }
5109
+ /** Governance read-model feed: recorded usage rows with the input/output split + thread/day. */
5110
+ governanceUsage() {
5111
+ return this.usage.map((row) => ({
5112
+ actorRef: row.actorRef,
5113
+ threadId: row.threadId,
5114
+ modelId: row.modelId,
5115
+ inputTokens: row.inputTokens,
5116
+ outputTokens: row.outputTokens,
5117
+ day: row.day,
5118
+ createdAt: row.createdAt,
5119
+ ...row.cacheWriteTokens !== void 0 ? {
5120
+ cacheWriteTokens: row.cacheWriteTokens
5121
+ } : {},
5122
+ ...row.cacheReadTokens !== void 0 ? {
5123
+ cacheReadTokens: row.cacheReadTokens
5124
+ } : {},
5125
+ ...row.costUsd !== void 0 ? {
5126
+ costUsd: row.costUsd
5127
+ } : {}
5128
+ }));
5129
+ }
5130
+ /** Governance read-model feed: recorded tool calls with the resolved thread + timestamp. */
5131
+ governanceToolCalls() {
5132
+ return [
5133
+ ...this.toolCalls.values()
5134
+ ].map((row) => ({
5135
+ toolCallId: row.toolCallId,
5136
+ toolName: row.toolName,
5137
+ toolType: row.toolType,
5138
+ status: row.status,
5139
+ threadId: row.threadId,
5140
+ messageId: row.messageId,
5141
+ createdAt: row.createdAt,
5142
+ ...row.executionMs !== void 0 ? {
5143
+ executionMs: row.executionMs
5144
+ } : {},
5145
+ ...row.error !== void 0 ? {
5146
+ error: row.error
5147
+ } : {},
5148
+ ...row.runId !== void 0 ? {
5149
+ runId: row.runId
5150
+ } : {}
5151
+ }));
5152
+ }
5153
+ /** Governance read-model feed: every stored message, thread-resolved, for the thread drill-down. */
5154
+ governanceMessages() {
5155
+ const rows = [];
5156
+ for (const thread of this.threads.values()) {
5157
+ for (const message of thread.messages) {
5158
+ rows.push({
5159
+ messageId: message.id,
5160
+ threadId: thread.id,
5161
+ role: message.role,
5162
+ content: message.content,
5163
+ createdAt: message.createdAt,
5164
+ ...message.agentName !== void 0 ? {
5165
+ agentName: message.agentName
5166
+ } : {}
5167
+ });
5168
+ }
5169
+ }
5170
+ return rows;
5171
+ }
5172
+ /**
5173
+ * Governance read-model feed: tool calls sitting `pending_approval`, joined to their thread
5174
+ * (title/actorRef) and the message that requested them (`agentName`, when the message has one).
5175
+ */
5176
+ governancePendingApprovals() {
5177
+ const rows = [];
5178
+ for (const call of this.toolCalls.values()) {
5179
+ if (call.status !== "pending_approval") {
5180
+ continue;
5181
+ }
5182
+ const thread = this.threads.get(call.threadId);
5183
+ if (thread === void 0) {
5184
+ continue;
5185
+ }
5186
+ const message = thread.messages.find((candidate) => candidate.id === call.messageId);
5187
+ rows.push({
5188
+ toolCallId: call.toolCallId,
5189
+ toolName: call.toolName,
5190
+ input: call.input,
5191
+ threadId: call.threadId,
5192
+ threadTitle: thread.title,
5193
+ actorRef: thread.actorRef,
5194
+ requestedAt: call.createdAt,
5195
+ ...message?.agentName !== void 0 ? {
5196
+ agentName: message.agentName
5197
+ } : {},
5198
+ ...call.runId !== void 0 ? {
5199
+ runId: call.runId
5200
+ } : {}
5201
+ });
5202
+ }
5203
+ return rows;
5204
+ }
5205
+ /** Governance read-model feed: thread metadata (title/actor/message count/last activity). */
5206
+ governanceThreads() {
5207
+ return [
5208
+ ...this.threads.values()
5209
+ ].map((row) => ({
5210
+ threadId: row.id,
5211
+ title: row.title,
5212
+ actorRef: row.actorRef,
5213
+ messageCount: row.messages.length,
5214
+ updatedAt: row.updatedAt
5215
+ }));
5216
+ }
5217
+ /** Governance read-model feed: recorded run outcomes (the reliability surfaces). */
5218
+ governanceRuns() {
5219
+ return [
5220
+ ...this.runs.values()
5221
+ ].map((row) => ({
5222
+ runId: row.runId,
5223
+ threadId: row.threadId,
5224
+ actorRef: row.actorRef,
5225
+ status: row.status,
5226
+ retries: row.retries,
5227
+ startedAt: row.startedAt,
5228
+ ...row.agentName !== void 0 ? {
5229
+ agentName: row.agentName
5230
+ } : {},
5231
+ ...row.parentRunId !== void 0 ? {
5232
+ parentRunId: row.parentRunId
5233
+ } : {},
5234
+ ...row.durationMs !== void 0 ? {
5235
+ durationMs: row.durationMs
5236
+ } : {},
5237
+ ...row.errorCode !== void 0 ? {
5238
+ errorCode: row.errorCode
5239
+ } : {},
5240
+ ...row.errorMessage !== void 0 ? {
5241
+ errorMessage: row.errorMessage
5242
+ } : {},
5243
+ ...row.settledAt !== void 0 ? {
5244
+ settledAt: row.settledAt
5245
+ } : {},
5246
+ ...row.promptHash !== void 0 ? {
5247
+ promptHash: row.promptHash
5248
+ } : {}
5249
+ }));
5250
+ }
5251
+ threadIdForMessage(messageId) {
5252
+ for (const [threadId, row] of this.threads) {
5253
+ if (row.messages.some((message) => message.id === messageId)) {
5254
+ return threadId;
5255
+ }
5256
+ }
5257
+ return void 0;
5258
+ }
5259
+ /** Test helper: read the recorded tool-call rows. */
5260
+ toolCallRows() {
5261
+ return [
5262
+ ...this.toolCalls.values()
5263
+ ].map((row) => ({
5264
+ toolCallId: row.toolCallId,
5265
+ toolName: row.toolName,
5266
+ toolType: row.toolType,
5267
+ status: row.status,
5268
+ input: row.input,
5269
+ ...row.output !== void 0 ? {
5270
+ output: row.output
5271
+ } : {},
5272
+ ...row.error !== void 0 ? {
5273
+ error: row.error
5274
+ } : {},
5275
+ ...row.runId !== void 0 ? {
5276
+ runId: row.runId
5277
+ } : {},
5278
+ ...row.executedByRef !== void 0 ? {
5279
+ executedByRef: row.executedByRef
5280
+ } : {},
5281
+ ...row.approver !== void 0 ? {
5282
+ approver: row.approver
5283
+ } : {},
5284
+ ...row.expiresAt !== void 0 ? {
5285
+ expiresAt: row.expiresAt
5286
+ } : {},
5287
+ ...row.remember !== void 0 ? {
5288
+ remember: row.remember
5289
+ } : {},
5290
+ ...row.decidedVia !== void 0 ? {
5291
+ decidedVia: row.decidedVia
5292
+ } : {}
5293
+ }));
5294
+ }
5295
+ toSummary(row) {
5296
+ const last = row.messages[row.messages.length - 1];
5297
+ return {
5298
+ id: row.id,
5299
+ title: row.title,
5300
+ transient: row.transient,
5301
+ createdAt: row.createdAt,
5302
+ updatedAt: row.updatedAt,
5303
+ ...last !== void 0 ? {
5304
+ lastMessagePreview: last.content.slice(0, 120)
5305
+ } : {},
5306
+ defaultAgent: row.defaultAgent ?? null,
5307
+ ...row.model != null ? {
5308
+ model: row.model
5309
+ } : {}
5310
+ };
5311
+ }
5312
+ };
4638
5313
  export {
4639
5314
  AGENT_ACTOR_DIRECTORY,
4640
5315
  AGENT_ACTOR_RESOLVER,
@@ -4682,6 +5357,7 @@ export {
4682
5357
  DefaultRolesPolicy,
4683
5358
  ELICITATION_INPUT_TYPES,
4684
5359
  GLOBAL_SCOPE,
5360
+ InMemoryAgentStore,
4685
5361
  MAX_ASK_QUESTIONS,
4686
5362
  OutputRejectedError,
4687
5363
  ProcessorFailedError,