@memberjunction/ai-agents 6.2.0 → 6.3.0-edge.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.
Files changed (96) hide show
  1. package/README.md +21 -1
  2. package/dist/AgentContextAssembler.d.ts +127 -0
  3. package/dist/AgentContextAssembler.d.ts.map +1 -0
  4. package/dist/AgentContextAssembler.js +482 -0
  5. package/dist/AgentContextAssembler.js.map +1 -0
  6. package/dist/AgentDataPreloader.d.ts +5 -1
  7. package/dist/AgentDataPreloader.d.ts.map +1 -1
  8. package/dist/AgentDataPreloader.js +13 -7
  9. package/dist/AgentDataPreloader.js.map +1 -1
  10. package/dist/AgentFeedbackCoordinator.d.ts +169 -0
  11. package/dist/AgentFeedbackCoordinator.d.ts.map +1 -0
  12. package/dist/AgentFeedbackCoordinator.js +593 -0
  13. package/dist/AgentFeedbackCoordinator.js.map +1 -0
  14. package/dist/AgentStepDispatcher.d.ts +211 -0
  15. package/dist/AgentStepDispatcher.d.ts.map +1 -0
  16. package/dist/AgentStepDispatcher.js +729 -0
  17. package/dist/AgentStepDispatcher.js.map +1 -0
  18. package/dist/AgentTreeBudgetTracker.d.ts +163 -0
  19. package/dist/AgentTreeBudgetTracker.d.ts.map +1 -0
  20. package/dist/AgentTreeBudgetTracker.js +415 -0
  21. package/dist/AgentTreeBudgetTracker.js.map +1 -0
  22. package/dist/AgentWakeTriggerService.d.ts +41 -1
  23. package/dist/AgentWakeTriggerService.d.ts.map +1 -1
  24. package/dist/AgentWakeTriggerService.js +154 -8
  25. package/dist/AgentWakeTriggerService.js.map +1 -1
  26. package/dist/MJAIAgentRequestEntityServer.d.ts +32 -1
  27. package/dist/MJAIAgentRequestEntityServer.d.ts.map +1 -1
  28. package/dist/MJAIAgentRequestEntityServer.js +105 -3
  29. package/dist/MJAIAgentRequestEntityServer.js.map +1 -1
  30. package/dist/PayloadManager.d.ts.map +1 -1
  31. package/dist/PayloadManager.js +14 -1
  32. package/dist/PayloadManager.js.map +1 -1
  33. package/dist/SkillMarkdownConverter.d.ts +1 -1
  34. package/dist/SkillMarkdownConverter.d.ts.map +1 -1
  35. package/dist/SkillMarkdownConverter.js +4 -4
  36. package/dist/SkillMarkdownConverter.js.map +1 -1
  37. package/dist/agent-pre-execution-rag.d.ts +5 -0
  38. package/dist/agent-pre-execution-rag.d.ts.map +1 -1
  39. package/dist/agent-pre-execution-rag.js +5 -0
  40. package/dist/agent-pre-execution-rag.js.map +1 -1
  41. package/dist/agent-types/base-agent-type.d.ts.map +1 -1
  42. package/dist/agent-types/base-agent-type.js +8 -1
  43. package/dist/agent-types/base-agent-type.js.map +1 -1
  44. package/dist/agent-types/loop-agent-prompt-params.d.ts +18 -0
  45. package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
  46. package/dist/agent-types/loop-agent-prompt-params.js +2 -0
  47. package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
  48. package/dist/base-agent.d.ts +105 -133
  49. package/dist/base-agent.d.ts.map +1 -1
  50. package/dist/base-agent.js +395 -1472
  51. package/dist/base-agent.js.map +1 -1
  52. package/dist/catalog-narrowing.d.ts +112 -5
  53. package/dist/catalog-narrowing.d.ts.map +1 -1
  54. package/dist/catalog-narrowing.js +181 -6
  55. package/dist/catalog-narrowing.js.map +1 -1
  56. package/dist/index.d.ts +6 -1
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +6 -1
  59. package/dist/index.js.map +1 -1
  60. package/dist/pipeline/operators.d.ts.map +1 -1
  61. package/dist/pipeline/operators.js +1 -1
  62. package/dist/pipeline/operators.js.map +1 -1
  63. package/dist/pipeline/pipeline-executor.d.ts +29 -1
  64. package/dist/pipeline/pipeline-executor.d.ts.map +1 -1
  65. package/dist/pipeline/pipeline-executor.js +159 -2
  66. package/dist/pipeline/pipeline-executor.js.map +1 -1
  67. package/dist/pipeline/pipeline.types.d.ts +19 -1
  68. package/dist/pipeline/pipeline.types.d.ts.map +1 -1
  69. package/dist/pipeline/template.d.ts +11 -0
  70. package/dist/pipeline/template.d.ts.map +1 -1
  71. package/dist/pipeline/template.js +56 -6
  72. package/dist/pipeline/template.js.map +1 -1
  73. package/dist/realtime/bridge-room-transcript-sink.d.ts.map +1 -1
  74. package/dist/realtime/bridge-room-transcript-sink.js +28 -1
  75. package/dist/realtime/bridge-room-transcript-sink.js.map +1 -1
  76. package/dist/realtime/media-channel-server.js +1 -1
  77. package/dist/realtime/media-channel-server.js.map +1 -1
  78. package/dist/realtime/realtime-client-session-service.d.ts +122 -2
  79. package/dist/realtime/realtime-client-session-service.d.ts.map +1 -1
  80. package/dist/realtime/realtime-client-session-service.js +413 -4
  81. package/dist/realtime/realtime-client-session-service.js.map +1 -1
  82. package/dist/realtime/realtime-coagent-config.d.ts +4 -2
  83. package/dist/realtime/realtime-coagent-config.d.ts.map +1 -1
  84. package/dist/realtime/realtime-coagent-config.js +27 -38
  85. package/dist/realtime/realtime-coagent-config.js.map +1 -1
  86. package/dist/realtime/realtime-delegation-narrator.js +1 -1
  87. package/dist/realtime/realtime-delegation-narrator.js.map +1 -1
  88. package/dist/realtime/realtime-session-runner.d.ts +2 -0
  89. package/dist/realtime/realtime-session-runner.d.ts.map +1 -1
  90. package/dist/realtime/realtime-session-runner.js +24 -3
  91. package/dist/realtime/realtime-session-runner.js.map +1 -1
  92. package/dist/unsafe-object-keys.d.ts +20 -0
  93. package/dist/unsafe-object-keys.d.ts.map +1 -0
  94. package/dist/unsafe-object-keys.js +42 -0
  95. package/dist/unsafe-object-keys.js.map +1 -0
  96. package/package.json +20 -20
@@ -0,0 +1,593 @@
1
+ /**
2
+ * @fileoverview Human-in-the-loop (HITL) feedback request coordination and assignee resolution
3
+ * for MemberJunction AI Agents.
4
+ *
5
+ * Extracted from `BaseAgent` (`WS-4.5a`) to encapsulate `MJ: AI Agent Requests` creation,
6
+ * response-form request-type detection, assignment strategy hierarchy resolution
7
+ * (invocation -> agent type -> category tree -> request type), and full `List`
8
+ * assignment strategies (`RoundRobin`, `LeastBusy`, `Random`).
9
+ *
10
+ * @module @memberjunction/ai-agents
11
+ */
12
+ import { randomInt } from 'node:crypto';
13
+ import { LogError, LogStatus, RunView, } from '@memberjunction/core';
14
+ import { ParseAssignmentStrategy, } from '@memberjunction/ai-core-plus';
15
+ import { AIEngine } from '@memberjunction/aiengine';
16
+ import { UserCache } from '@memberjunction/generic-database-provider';
17
+ import { EscapeSQLString, GroupByUUID, IndexByUUID, UUIDMap, UUIDSet, UUIDsEqual } from '@memberjunction/global';
18
+ /**
19
+ * `MJ: List Details` statuses that disqualify a row from list membership.
20
+ * Standard rows created with the SQL default (`Status = 'Pending'`), as well as
21
+ * `'Active'`, `'Complete'`, `'Other'`, or `null`, remain eligible candidates.
22
+ */
23
+ const EXCLUDED_LIST_DETAIL_STATUSES = ['Disabled', 'Error', 'Rejected'];
24
+ const EXCLUDED_LIST_DETAIL_SQL_LIST = EXCLUDED_LIST_DETAIL_STATUSES.map((status) => `'${EscapeSQLString(status)}'`).join(', ');
25
+ /**
26
+ * The sole open status on `MJ: AI Agent Requests` (`MJAIAgentRequestEntity['Status']`).
27
+ */
28
+ const OPEN_AGENT_REQUEST_STATUS = 'Requested';
29
+ /** How many of the list members' newest assignments LeastBusy reads to break a tie on open-request count. */
30
+ const LEAST_BUSY_RECENT_ASSIGNMENT_ROWS = 500;
31
+ /**
32
+ * Coordinates creation of persistent `MJ: AI Agent Requests` rows, response-form
33
+ * classification, hierarchical assignment strategy resolution, and `List`-based
34
+ * (`RoundRobin`, `LeastBusy`, `Random`) user assignment.
35
+ */
36
+ export class AgentFeedbackCoordinator {
37
+ constructor(options) {
38
+ this.randomIntFn = options?.RandomInt ?? ((maxExclusive) => randomInt(0, maxExclusive));
39
+ this.onLogStatus = options?.OnLogStatus;
40
+ }
41
+ /**
42
+ * Builds the standard editable plan-approval {@link AgentResponseForm} for Plan Mode.
43
+ */
44
+ BuildPlanApprovalForm(planText) {
45
+ return {
46
+ title: 'Review Plan',
47
+ description: 'Review the proposed plan below. Edit it if needed, then approve to proceed — or reject (with a note on what to change) and the agent will re-plan.',
48
+ submitLabel: 'Submit',
49
+ questions: [
50
+ {
51
+ id: 'plan',
52
+ label: 'Plan',
53
+ // markdown: agents author plans in Markdown (see the plan-mode prompt
54
+ // instructions); the UI renders a formatted preview with an Edit toggle.
55
+ type: { type: 'textarea', markdown: true },
56
+ defaultValue: planText,
57
+ required: true,
58
+ },
59
+ {
60
+ id: 'reason',
61
+ label: 'Feedback',
62
+ type: {
63
+ type: 'textarea',
64
+ placeholder: 'Optional — if rejecting, tell the agent what to change and it will re-plan.',
65
+ },
66
+ required: false,
67
+ },
68
+ {
69
+ id: 'decision',
70
+ label: 'Decision',
71
+ type: {
72
+ type: 'buttongroup',
73
+ options: [
74
+ { value: 'approve', label: 'Approve' },
75
+ { value: 'reject', label: 'Reject' },
76
+ ],
77
+ },
78
+ required: true,
79
+ },
80
+ ],
81
+ };
82
+ }
83
+ /**
84
+ * Inspects an {@link AgentResponseForm} to determine the request type name.
85
+ * Returns `'Approval'` when the form is a single two-option approve/reject question,
86
+ * otherwise `'Information'`.
87
+ */
88
+ DetectRequestTypeName(form) {
89
+ const q = form.questions?.[0];
90
+ if (!q || form.questions.length !== 1) {
91
+ return 'Information';
92
+ }
93
+ const qType = q.type;
94
+ if ((qType.type === 'buttongroup' || qType.type === 'radio') && 'options' in qType) {
95
+ const opts = qType.options;
96
+ if (opts.length === 2) {
97
+ const labels = opts.map((o) => o.label.toLowerCase());
98
+ const hasPositive = labels.some((l) => l.includes('approv') || l.includes('yes') || l.includes('accept'));
99
+ const hasNegative = labels.some((l) => l.includes('reject') || l.includes('no') || l.includes('deny'));
100
+ if (hasPositive && hasNegative) {
101
+ return 'Approval';
102
+ }
103
+ }
104
+ }
105
+ return 'Information';
106
+ }
107
+ /**
108
+ * Resolves the `MJ: AI Agent Request Types` ID for a Chat or Plan step decision:
109
+ * - If the responseForm has only approve/reject-style buttons, uses `"Approval"`
110
+ * - If there's a responseForm with fields, uses `"Information"`
111
+ * - Otherwise defaults to `"Information"`
112
+ *
113
+ * Request types come from the AI engine's cached `MJ: AI Agent Request Types` rows
114
+ * (`AIEngineBase.ResolveAgentRequestTypeID`), the same source the agent actions use.
115
+ */
116
+ async ResolveRequestTypeID(previousDecision, contextUser) {
117
+ try {
118
+ let typeName = 'Information';
119
+ if (previousDecision.responseForm) {
120
+ typeName = this.DetectRequestTypeName(previousDecision.responseForm);
121
+ }
122
+ return await AIEngine.Instance.ResolveAgentRequestTypeID(typeName, contextUser);
123
+ }
124
+ catch (error) {
125
+ const message = error instanceof Error ? error.message : String(error);
126
+ LogError(`Error resolving request type: ${message}`);
127
+ return null;
128
+ }
129
+ }
130
+ /**
131
+ * Walks the assignment strategy resolution chain (bottom-up, first-non-null wins):
132
+ * 1. `ExecuteAgentParams.assignmentStrategy` (per-invocation override)
133
+ * 2. Agent Type's `AssignmentStrategy`
134
+ * 3. Agent's Category `AssignmentStrategy` (walks up `ParentID` tree)
135
+ * 4. Request Type's `DefaultAssignmentStrategy`
136
+ * 5. `null`
137
+ */
138
+ async ResolveAssignmentStrategy(params, requestTypeId) {
139
+ if (params.assignmentStrategy) {
140
+ return params.assignmentStrategy;
141
+ }
142
+ const agentType = AIEngine.Instance.AgentTypes.find((at) => UUIDsEqual(at.ID, params.agent.TypeID));
143
+ const typeStrategy = ParseAssignmentStrategy(agentType?.AssignmentStrategy ?? null);
144
+ if (typeStrategy) {
145
+ return typeStrategy;
146
+ }
147
+ const categoryStrategy = await this.ResolveCategoryAssignmentStrategy(params);
148
+ if (categoryStrategy) {
149
+ return categoryStrategy;
150
+ }
151
+ if (requestTypeId) {
152
+ const requestType = AIEngine.Instance.AgentRequestTypes.find((t) => UUIDsEqual(t.ID, requestTypeId));
153
+ if (requestType) {
154
+ const rtStrategy = ParseAssignmentStrategy(requestType.DefaultAssignmentStrategy);
155
+ if (rtStrategy) {
156
+ return rtStrategy;
157
+ }
158
+ }
159
+ }
160
+ return null;
161
+ }
162
+ /**
163
+ * Walks up the agent's category hierarchy looking for a configured `AssignmentStrategy`.
164
+ */
165
+ async ResolveCategoryAssignmentStrategy(params) {
166
+ const categoryId = params.agent.CategoryID;
167
+ if (!categoryId) {
168
+ return null;
169
+ }
170
+ try {
171
+ const categoriesByID = IndexByUUID(AIEngine.Instance.AgentCategories);
172
+ let currentId = categoryId;
173
+ const visited = new UUIDSet();
174
+ while (currentId && !visited.Has(currentId)) {
175
+ visited.Add(currentId);
176
+ const cat = categoriesByID.Get(currentId);
177
+ if (!cat) {
178
+ break;
179
+ }
180
+ const strategy = ParseAssignmentStrategy(cat.AssignmentStrategy);
181
+ if (strategy) {
182
+ return strategy;
183
+ }
184
+ currentId = cat.ParentID;
185
+ }
186
+ }
187
+ catch (error) {
188
+ const message = error instanceof Error ? error.message : String(error);
189
+ LogError(`Error resolving category assignment strategy: ${message}`);
190
+ }
191
+ return null;
192
+ }
193
+ /**
194
+ * Synchronously resolves non-`List` assignment strategies (`RunUser`, `AgentOwner`,
195
+ * `SpecificUser`, `SharedInbox`, or `null` fallback).
196
+ */
197
+ ResolveStaticAssigneeUserID(strategy, params, agentRun) {
198
+ if (!strategy) {
199
+ if (params.contextUser?.ID) {
200
+ LogStatus(`⚠️ No assignment strategy configured for agent ${params.agent.Name}; defaulting to context user`);
201
+ return params.contextUser.ID;
202
+ }
203
+ LogStatus(`⚠️ No assignment strategy and no context user for agent ${params.agent.Name}; request will be unassigned`);
204
+ return null;
205
+ }
206
+ switch (strategy.type) {
207
+ case 'RunUser':
208
+ return params.contextUser?.ID ?? agentRun?.UserID ?? null;
209
+ case 'AgentOwner':
210
+ return params.agent.OwnerUserID ?? null;
211
+ case 'SpecificUser':
212
+ return strategy.userID ?? null;
213
+ case 'SharedInbox':
214
+ return null;
215
+ case 'List':
216
+ return params.contextUser?.ID ?? null;
217
+ default:
218
+ return params.contextUser?.ID ?? null;
219
+ }
220
+ }
221
+ /**
222
+ * Resolves the assignee user ID for a feedback request, including async `List`
223
+ * strategies (`RoundRobin`, `LeastBusy`, `Random`).
224
+ */
225
+ async ResolveAssigneeUserID(strategy, params, agentRun, provider) {
226
+ if (!strategy || strategy.type !== 'List') {
227
+ return this.ResolveStaticAssigneeUserID(strategy, params, agentRun);
228
+ }
229
+ return this.resolveListAssigneeUserID(strategy, params, provider);
230
+ }
231
+ /**
232
+ * Creates and saves a persistent `MJ: AI Agent Requests` row for a Chat or Plan step,
233
+ * returning the new request's `ID` when saved or `null` on failure.
234
+ *
235
+ * **Who saves the row.** `MJAIAgentRequestEntityServer.Validate` keeps requests private: a
236
+ * non-Owner-type user may save a request only for themselves, and Owner-type users (the
237
+ * scheduler's system user among them) are exempt. That rule guards direct saves, such as a
238
+ * GraphQL create where the caller types in `RequestForUserID`, and this method leaves it
239
+ * untouched. The assignee here comes from one of two places, held to different standards:
240
+ * - **Metadata** (agent type, agent category, request type): an administrator configured the
241
+ * strategy and the caller cannot change it. When it picks someone other than a non-Owner
242
+ * caller, the row is saved as the system user, the cross-user path the rule exempts (the
243
+ * same way `AgentWakeTriggerService` saves a wake routine for another user). Saving it as
244
+ * the caller would fail validation and lose the request: no inbox row, no resume.
245
+ * - **The caller** (`ExecuteAgentParams.assignmentStrategy`): held to the rule a direct save
246
+ * meets. A non-Owner caller who names someone else gets the request assigned to themselves
247
+ * (logged), and the row is saved as the caller, so the entity rule still backs this up.
248
+ * The reads that choose the assignee (list members, open counts) run as the caller either way.
249
+ */
250
+ async CreateFeedbackRequest(input) {
251
+ const { Params: params, StepEntity: stepEntity, Decision: previousDecision, AgentRun: agentRun, Provider: provider, NowMs: nowMs = Date.now(), } = input;
252
+ try {
253
+ const requestTypeId = await this.ResolveRequestTypeID(previousDecision, params.contextUser);
254
+ const resolvedStrategy = await this.ResolveAssignmentStrategy(params, requestTypeId);
255
+ const resolvedAssigneeUserId = await this.ResolveAssigneeUserID(resolvedStrategy, params, agentRun, provider);
256
+ const { AssigneeUserID: requestForUserId, SaveUser: saveUser } = this.placeRequest(resolvedAssigneeUserId, params);
257
+ const priority = resolvedStrategy?.priority ?? 50;
258
+ const expirationMinutes = resolvedStrategy?.expirationMinutes;
259
+ const request = await provider.GetEntityObject('MJ: AI Agent Requests', saveUser);
260
+ request.NewRecord();
261
+ request.AgentID = params.agent.ID;
262
+ request.RequestedAt = new Date(nowMs);
263
+ request.RequestForUserID = requestForUserId;
264
+ request.Status = 'Requested';
265
+ request.Request = previousDecision.message || 'Agent needs user input';
266
+ request.RequestTypeID = requestTypeId;
267
+ request.ResponseSchema = previousDecision.responseForm
268
+ ? JSON.stringify(previousDecision.responseForm)
269
+ : null;
270
+ request.Priority = priority;
271
+ request.OriginatingAgentRunID = agentRun?.ID || null;
272
+ request.OriginatingAgentRunStepID = stepEntity.ID;
273
+ if (expirationMinutes != null && expirationMinutes > 0) {
274
+ request.ExpiresAt = new Date(nowMs + expirationMinutes * 60_000);
275
+ }
276
+ const saved = await request.Save();
277
+ if (saved) {
278
+ this.onLogStatus?.(`📋 Created feedback request ${request.ID} for user ${requestForUserId || '(system)'}`, true, params);
279
+ return request.ID;
280
+ }
281
+ LogError(`Failed to save AIAgentRequest for agent ${params.agent.Name}: ${request.LatestResult?.CompleteMessage ?? 'unknown error'}`);
282
+ return null;
283
+ }
284
+ catch (error) {
285
+ const message = error instanceof Error ? error.message : String(error);
286
+ LogError(`Error creating feedback request: ${message}`);
287
+ return null;
288
+ }
289
+ }
290
+ /**
291
+ * Applies the ownership rule described on {@link CreateFeedbackRequest} to a resolved assignee.
292
+ * A request for the caller, for nobody (a shared inbox), with no caller, or from an Owner-type
293
+ * caller is saved as the caller unchanged.
294
+ */
295
+ placeRequest(assigneeUserID, params) {
296
+ const caller = params.contextUser;
297
+ if (!caller || !assigneeUserID || UUIDsEqual(assigneeUserID, caller.ID) || this.isOwnerType(caller)) {
298
+ return { AssigneeUserID: assigneeUserID, SaveUser: caller };
299
+ }
300
+ if (params.assignmentStrategy) {
301
+ LogStatus(`⚠️ Agent ${params.agent.Name}: the run's assignmentStrategy picked user ${assigneeUserID}, but a non-Owner caller may only assign a request to themselves; assigning it to the caller`);
302
+ return { AssigneeUserID: caller.ID, SaveUser: caller };
303
+ }
304
+ const systemUser = UserCache.Instance.GetSystemUser();
305
+ if (!systemUser) {
306
+ LogStatus(`⚠️ Agent ${params.agent.Name}: no system user in UserCache to save a request for user ${assigneeUserID}; assigning it to the caller`);
307
+ return { AssigneeUserID: caller.ID, SaveUser: caller };
308
+ }
309
+ return { AssigneeUserID: assigneeUserID, SaveUser: systemUser };
310
+ }
311
+ /** The Owner-type test `MJAIAgentRequestEntityServer.validateOwnership` applies. */
312
+ isOwnerType(user) {
313
+ return user.Type?.trim().toLowerCase() === 'owner';
314
+ }
315
+ describeListFallbackTarget(params) {
316
+ return params.contextUser?.ID
317
+ ? 'falling back to context user'
318
+ : 'falling back to unassigned (no context user)';
319
+ }
320
+ async resolveListAssigneeUserID(strategy, params, provider) {
321
+ const listId = strategy.listID?.trim();
322
+ if (!listId) {
323
+ LogStatus(`⚠️ List assignment strategy on agent ${params.agent.Name} is missing listID; ${this.describeListFallbackTarget(params)}`);
324
+ return params.contextUser?.ID ?? null;
325
+ }
326
+ try {
327
+ const effectiveProvider = provider ?? params.provider;
328
+ // global-provider-ok: Falls back to default RunView only when caller did not supply a provider
329
+ const rv = effectiveProvider ? RunView.FromMetadataProvider(effectiveProvider) : new RunView();
330
+ const candidateUserIDs = await this.loadListCandidateUserIDs(rv, listId, params, effectiveProvider);
331
+ if (!candidateUserIDs) {
332
+ return params.contextUser?.ID ?? null;
333
+ }
334
+ const mode = strategy.listStrategy ?? 'RoundRobin';
335
+ return await this.selectFromActiveListMembers(rv, mode, listId, candidateUserIDs, params);
336
+ }
337
+ catch (error) {
338
+ const message = error instanceof Error ? error.message : String(error);
339
+ LogError(`Error resolving List assignment strategy for list ${listId}: ${message}`);
340
+ return params.contextUser?.ID ?? null;
341
+ }
342
+ }
343
+ /**
344
+ * Reads the list and its member rows in one batch and returns the member user IDs in list order,
345
+ * or `null` (logged) when the list cannot be read, does not target `MJ: Users`, or has no members.
346
+ */
347
+ async loadListCandidateUserIDs(rv, listId, params, provider) {
348
+ const [listResult, detailsResult] = await rv.RunViews(this.buildListViews(listId), params.contextUser);
349
+ if (!listResult?.Success || !detailsResult?.Success) {
350
+ LogError(`Failed to load list ${listId} for assignment: ${listResult?.ErrorMessage || detailsResult?.ErrorMessage || 'unknown error'}`);
351
+ return null;
352
+ }
353
+ const listRow = (listResult.Results ?? [])[0];
354
+ if (!listRow || !this.isUsersList(listRow, provider)) {
355
+ LogStatus(`⚠️ List ${listId} does not exist or does not target 'MJ: Users'; ${this.describeListFallbackTarget(params)}`);
356
+ return null;
357
+ }
358
+ const candidateUserIDs = this.extractOrderedCandidateUserIDs(detailsResult.Results ?? []);
359
+ if (candidateUserIDs.length === 0) {
360
+ LogStatus(`ℹ️ List ${listId} has no active member rows; ${this.describeListFallbackTarget(params)}`);
361
+ return null;
362
+ }
363
+ return candidateUserIDs;
364
+ }
365
+ isUsersList(listRow, provider) {
366
+ if (listRow.Entity) {
367
+ const normalized = listRow.Entity.trim().toLowerCase();
368
+ return normalized === 'mj: users' || normalized === 'users';
369
+ }
370
+ if (listRow.EntityID && provider?.Entities) {
371
+ const entityInfo = provider.Entities.find((e) => UUIDsEqual(e.ID, listRow.EntityID));
372
+ if (entityInfo) {
373
+ const normalized = entityInfo.Name.trim().toLowerCase();
374
+ return normalized === 'mj: users' || normalized === 'users';
375
+ }
376
+ }
377
+ return false;
378
+ }
379
+ isMemberListDetailStatus(status) {
380
+ if (status == null) {
381
+ return true;
382
+ }
383
+ return !EXCLUDED_LIST_DETAIL_STATUSES.includes(status);
384
+ }
385
+ extractOrderedCandidateUserIDs(detailRows) {
386
+ const activeRows = detailRows.filter((row) => this.isMemberListDetailStatus(row.Status) &&
387
+ typeof row.RecordID === 'string' &&
388
+ row.RecordID.trim().length > 0);
389
+ const sortedRows = [...activeRows].sort((a, b) => {
390
+ const seqDiff = (a.Sequence ?? 0) - (b.Sequence ?? 0);
391
+ if (seqDiff !== 0) {
392
+ return seqDiff;
393
+ }
394
+ return String(a.ID ?? '').localeCompare(String(b.ID ?? ''));
395
+ });
396
+ const seen = new UUIDSet();
397
+ const orderedUserIDs = [];
398
+ for (const row of sortedRows) {
399
+ const userId = row.RecordID.trim();
400
+ if (!seen.Has(userId)) {
401
+ seen.Add(userId);
402
+ orderedUserIDs.push(userId);
403
+ }
404
+ }
405
+ return orderedUserIDs;
406
+ }
407
+ /**
408
+ * Reads which candidates are active users, together with the request rows the mode needs, in one
409
+ * batch, then picks among the active members. `LeastBusy` also counts each candidate's open
410
+ * requests, in a second batch run alongside the first. A failed user read falls back to the caller;
411
+ * a failed request read or count falls back to the first active member, so the request still lands
412
+ * on the list.
413
+ */
414
+ async selectFromActiveListMembers(rv, mode, listId, candidateUserIDs, params) {
415
+ const modeViews = this.buildListModeViews(mode, candidateUserIDs, params);
416
+ const countViews = mode === 'LeastBusy' ? this.buildOpenCountViews(candidateUserIDs) : [];
417
+ // The counts are a batch of their own: a RunViews batch made only of count_only views runs as ONE
418
+ // COUNT statement (GenericDatabaseProvider coalesces it); mixed into the selection batch, each
419
+ // count would run as its own query.
420
+ const [[usersResult, ...modeResults], countResults] = await Promise.all([
421
+ rv.RunViews([this.buildActiveUsersView(candidateUserIDs), ...modeViews], params.contextUser),
422
+ countViews.length > 0 ? rv.RunViews(countViews, params.contextUser) : Promise.resolve([]),
423
+ ]);
424
+ if (!usersResult?.Success) {
425
+ LogError(`Failed to load active users for list ${listId}: ${usersResult?.ErrorMessage || 'unknown error'}`);
426
+ return params.contextUser?.ID ?? null;
427
+ }
428
+ const activeUserIDs = this.filterActiveUserIDs(candidateUserIDs, usersResult.Results ?? []);
429
+ if (activeUserIDs.length === 0) {
430
+ LogStatus(`ℹ️ List ${listId} has zero active users; ${this.describeListFallbackTarget(params)}`);
431
+ return params.contextUser?.ID ?? null;
432
+ }
433
+ const failedRead = this.findFailedRead(modeViews.length, modeResults) ?? this.findFailedRead(countViews.length, countResults);
434
+ if (failedRead !== null) {
435
+ LogError(`Failed to load agent requests for list ${listId} (${mode}): ${failedRead}; falling back to first active list member`);
436
+ return activeUserIDs[0];
437
+ }
438
+ const openCounts = new UUIDMap(candidateUserIDs.map((id, i) => [id, countResults[i]?.TotalRowCount ?? 0]));
439
+ return this.pickListMember(mode, activeUserIDs, modeResults, openCounts);
440
+ }
441
+ /** The list row and its member rows (members in a disqualifying status are left out). */
442
+ buildListViews(listId) {
443
+ const escapedListId = EscapeSQLString(listId);
444
+ return [
445
+ {
446
+ EntityName: 'MJ: Lists',
447
+ ExtraFilter: `ID = '${escapedListId}'`,
448
+ Fields: ['ID', 'EntityID', 'Entity'],
449
+ ResultType: 'simple',
450
+ },
451
+ {
452
+ EntityName: 'MJ: List Details',
453
+ ExtraFilter: `ListID = '${escapedListId}' AND (Status IS NULL OR Status NOT IN (${EXCLUDED_LIST_DETAIL_SQL_LIST}))`,
454
+ OrderBy: 'Sequence ASC, ID ASC',
455
+ Fields: ['ID', 'ListID', 'RecordID', 'Sequence', 'Status'],
456
+ ResultType: 'simple',
457
+ },
458
+ ];
459
+ }
460
+ /** IDs as a SQL `IN (...)` list body, each value escaped. */
461
+ toSqlIdList(ids) {
462
+ return ids.map((id) => `'${EscapeSQLString(id)}'`).join(', ');
463
+ }
464
+ buildActiveUsersView(candidateUserIDs) {
465
+ return {
466
+ EntityName: 'MJ: Users',
467
+ ExtraFilter: `ID IN (${this.toSqlIdList(candidateUserIDs)}) AND IsActive = 1`,
468
+ Fields: ['ID', 'IsActive'],
469
+ ResultType: 'simple',
470
+ };
471
+ }
472
+ /**
473
+ * The `MJ: AI Agent Requests` rows a mode needs: none for `Random`; the agent's latest assignment to a
474
+ * member for `RoundRobin` (also used for an unrecognised mode); the members' newest assignments for the
475
+ * `LeastBusy` tie-break (its open-request counts come from {@link buildOpenCountViews}).
476
+ */
477
+ buildListModeViews(mode, candidateUserIDs, params) {
478
+ const userInListClause = this.toSqlIdList(candidateUserIDs);
479
+ if (mode === 'Random') {
480
+ return [];
481
+ }
482
+ if (mode === 'LeastBusy') {
483
+ // Tie-break: each member's latest assignment of any status. The cap is safe here: a member
484
+ // with no row among the newest assignments was last assigned before all of them, so they
485
+ // already rank as the oldest assignment; only their order among themselves falls back to
486
+ // list sequence.
487
+ return [
488
+ {
489
+ EntityName: 'MJ: AI Agent Requests',
490
+ ExtraFilter: `RequestForUserID IN (${userInListClause})`,
491
+ OrderBy: 'RequestedAt DESC, ID DESC',
492
+ MaxRows: LEAST_BUSY_RECENT_ASSIGNMENT_ROWS,
493
+ Fields: ['ID', 'RequestForUserID', 'RequestedAt'],
494
+ ResultType: 'simple',
495
+ },
496
+ ];
497
+ }
498
+ const agentFilter = params.agent?.ID ? `AgentID = '${EscapeSQLString(params.agent.ID)}' AND ` : '';
499
+ return [
500
+ {
501
+ EntityName: 'MJ: AI Agent Requests',
502
+ ExtraFilter: `${agentFilter}RequestForUserID IN (${userInListClause})`,
503
+ OrderBy: 'RequestedAt DESC, ID DESC',
504
+ MaxRows: 1,
505
+ Fields: ['ID', 'AgentID', 'RequestForUserID', 'RequestedAt'],
506
+ ResultType: 'simple',
507
+ },
508
+ ];
509
+ }
510
+ /**
511
+ * One `count_only` view per candidate: how many open (`'Requested'`) requests each one holds. A count
512
+ * returns no rows, so a long history of open requests costs nothing to read.
513
+ */
514
+ buildOpenCountViews(candidateUserIDs) {
515
+ return candidateUserIDs.map((id) => ({
516
+ EntityName: 'MJ: AI Agent Requests',
517
+ ExtraFilter: `RequestForUserID = '${EscapeSQLString(id)}' AND Status = '${OPEN_AGENT_REQUEST_STATUS}'`,
518
+ ResultType: 'count_only',
519
+ }));
520
+ }
521
+ /** The candidates the user read returned as active, in list order. */
522
+ filterActiveUserIDs(candidateUserIDs, activeUserRows) {
523
+ const activeUserSet = new UUIDSet(activeUserRows.filter((u) => u.IsActive !== false).map((u) => u.ID));
524
+ return candidateUserIDs.filter((id) => activeUserSet.Has(id));
525
+ }
526
+ /** The error of the first of `expected` results that is missing or failed, or `null` when all succeeded. */
527
+ findFailedRead(expected, results) {
528
+ for (let i = 0; i < expected; i++) {
529
+ const result = results[i];
530
+ if (!result?.Success) {
531
+ return result?.ErrorMessage || 'unknown error';
532
+ }
533
+ }
534
+ return null;
535
+ }
536
+ pickListMember(mode, activeUserIDs, modeResults, openCounts) {
537
+ const rowsOf = (result) => result?.Results ?? [];
538
+ if (mode === 'Random') {
539
+ const index = this.randomIntFn(activeUserIDs.length);
540
+ return activeUserIDs[Math.max(0, Math.min(activeUserIDs.length - 1, index))];
541
+ }
542
+ if (mode === 'LeastBusy') {
543
+ return this.pickLeastBusyMember(activeUserIDs, openCounts, rowsOf(modeResults[0]));
544
+ }
545
+ return this.pickRoundRobinMember(activeUserIDs, rowsOf(modeResults[0]));
546
+ }
547
+ // ponytail: Concurrent RoundRobin selections read the same latest `MaxRows: 1` request row
548
+ // before either caller inserts its new `MJ: AI Agent Requests` record, so simultaneous
549
+ // creations can collide and pick the same next user. The WS-4.5b spec intentionally uses a
550
+ // stateless query cursor rather than a schema lock; the upgrade path when strict
551
+ // non-colliding rotation is required is a persisted cursor/reservation column (or dedicated
552
+ // cursor table) updated atomically via `UPDATE ... OUTPUT` / `UPDLOCK, HOLDLOCK`.
553
+ pickRoundRobinMember(activeUserIDs, recentRequests) {
554
+ const lastAssignedUserID = recentRequests[0]?.RequestForUserID;
555
+ if (!lastAssignedUserID) {
556
+ return activeUserIDs[0];
557
+ }
558
+ const lastIndex = activeUserIDs.findIndex((id) => UUIDsEqual(id, lastAssignedUserID));
559
+ if (lastIndex === -1) {
560
+ return activeUserIDs[0];
561
+ }
562
+ return activeUserIDs[(lastIndex + 1) % activeUserIDs.length];
563
+ }
564
+ /**
565
+ * The member with the fewest open requests; a tie goes to the member whose latest assignment (of
566
+ * any status) is oldest, then to list sequence.
567
+ */
568
+ pickLeastBusyMember(activeUserIDs, openCounts, recentAssignmentRows) {
569
+ const recentByUser = GroupByUUID(recentAssignmentRows, (req) => req.RequestForUserID);
570
+ let bestUserID = activeUserIDs[0];
571
+ let bestOpenCount = Number.POSITIVE_INFINITY;
572
+ let bestLastAssignedMs = Number.POSITIVE_INFINITY;
573
+ for (const candidateUserID of activeUserIDs) {
574
+ const openCount = openCounts.Get(candidateUserID) ?? 0;
575
+ let lastAssignedMs = Number.NEGATIVE_INFINITY;
576
+ for (const req of recentByUser.Get(candidateUserID) ?? []) {
577
+ const ts = req.RequestedAt ? new Date(req.RequestedAt).getTime() : Number.NaN;
578
+ if (!Number.isNaN(ts) && ts > lastAssignedMs) {
579
+ lastAssignedMs = ts;
580
+ }
581
+ }
582
+ const isBetter = openCount < bestOpenCount ||
583
+ (openCount === bestOpenCount && lastAssignedMs < bestLastAssignedMs);
584
+ if (isBetter) {
585
+ bestUserID = candidateUserID;
586
+ bestOpenCount = openCount;
587
+ bestLastAssignedMs = lastAssignedMs;
588
+ }
589
+ }
590
+ return bestUserID;
591
+ }
592
+ }
593
+ //# sourceMappingURL=AgentFeedbackCoordinator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentFeedbackCoordinator.js","sourceRoot":"","sources":["../src/AgentFeedbackCoordinator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAEH,QAAQ,EACR,SAAS,EACT,OAAO,GAIV,MAAM,sBAAsB,CAAC;AAO9B,OAAO,EAQH,uBAAuB,GAC1B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAoDjH;;;;GAIG;AACH,MAAM,6BAA6B,GAAgC,CAAC,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;AACr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