@mxf-dev/core 3.0.0 → 3.2.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/dist/config/ConfigManager.d.ts +64 -0
  2. package/dist/config/ConfigManager.d.ts.map +1 -1
  3. package/dist/config/ConfigManager.js +68 -1
  4. package/dist/config/ConfigManager.js.map +1 -1
  5. package/dist/config/MeilisearchIngressLimits.d.ts +57 -0
  6. package/dist/config/MeilisearchIngressLimits.d.ts.map +1 -0
  7. package/dist/config/MeilisearchIngressLimits.js +57 -0
  8. package/dist/config/MeilisearchIngressLimits.js.map +1 -0
  9. package/dist/database/adapters/mongodb/MongoChannelRepository.d.ts.map +1 -1
  10. package/dist/database/adapters/mongodb/MongoChannelRepository.js +2 -1
  11. package/dist/database/adapters/mongodb/MongoChannelRepository.js.map +1 -1
  12. package/dist/events/EventNames.d.ts +2 -0
  13. package/dist/events/EventNames.d.ts.map +1 -1
  14. package/dist/events/event-definitions/ConfigEvents.d.ts +6 -0
  15. package/dist/events/event-definitions/ConfigEvents.d.ts.map +1 -1
  16. package/dist/events/event-definitions/ConfigEvents.js +0 -5
  17. package/dist/events/event-definitions/ConfigEvents.js.map +1 -1
  18. package/dist/events/event-definitions/MeilisearchEvents.d.ts +3 -1
  19. package/dist/events/event-definitions/MeilisearchEvents.d.ts.map +1 -1
  20. package/dist/events/event-definitions/MeilisearchEvents.js +4 -0
  21. package/dist/events/event-definitions/MeilisearchEvents.js.map +1 -1
  22. package/dist/events/event-definitions/SystemEvents.d.ts +16 -0
  23. package/dist/events/event-definitions/SystemEvents.d.ts.map +1 -1
  24. package/dist/events/event-definitions/SystemEvents.js +2 -0
  25. package/dist/events/event-definitions/SystemEvents.js.map +1 -1
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +1 -0
  29. package/dist/index.js.map +1 -1
  30. package/dist/interfaces/Channel.d.ts +3 -0
  31. package/dist/interfaces/Channel.d.ts.map +1 -1
  32. package/dist/interfaces/ChannelConfig.d.ts +2 -0
  33. package/dist/interfaces/ChannelConfig.d.ts.map +1 -1
  34. package/dist/interfaces/ConversationMessage.d.ts +1 -1
  35. package/dist/interfaces/ConversationMessage.d.ts.map +1 -1
  36. package/dist/models/channel.d.ts +2 -0
  37. package/dist/models/channel.d.ts.map +1 -1
  38. package/dist/models/channel.js +8 -0
  39. package/dist/models/channel.js.map +1 -1
  40. package/dist/models/task.d.ts.map +1 -1
  41. package/dist/models/task.js.map +1 -1
  42. package/dist/prompts/MxfAgentSystemPrompt.d.ts.map +1 -1
  43. package/dist/prompts/MxfAgentSystemPrompt.js +9 -1
  44. package/dist/prompts/MxfAgentSystemPrompt.js.map +1 -1
  45. package/dist/prompts/SystemLlmStanceGuidance.d.ts +37 -0
  46. package/dist/prompts/SystemLlmStanceGuidance.d.ts.map +1 -0
  47. package/dist/prompts/SystemLlmStanceGuidance.js +48 -0
  48. package/dist/prompts/SystemLlmStanceGuidance.js.map +1 -0
  49. package/dist/repositories/interfaces/IChannelRepository.d.ts +2 -0
  50. package/dist/repositories/interfaces/IChannelRepository.d.ts.map +1 -1
  51. package/dist/schemas/EventPayloadSchema.d.ts +14 -1
  52. package/dist/schemas/EventPayloadSchema.d.ts.map +1 -1
  53. package/dist/schemas/EventPayloadSchema.js +27 -0
  54. package/dist/schemas/EventPayloadSchema.js.map +1 -1
  55. package/dist/services/BackgroundTaskManager.d.ts +6 -0
  56. package/dist/services/BackgroundTaskManager.d.ts.map +1 -1
  57. package/dist/services/BackgroundTaskManager.js +35 -4
  58. package/dist/services/BackgroundTaskManager.js.map +1 -1
  59. package/dist/services/MxfMeilisearchService.d.ts +19 -3
  60. package/dist/services/MxfMeilisearchService.d.ts.map +1 -1
  61. package/dist/services/MxfMeilisearchService.js +46 -34
  62. package/dist/services/MxfMeilisearchService.js.map +1 -1
  63. package/dist/types/SystemLlmStanceTypes.d.ts +123 -0
  64. package/dist/types/SystemLlmStanceTypes.d.ts.map +1 -0
  65. package/dist/types/SystemLlmStanceTypes.js +101 -0
  66. package/dist/types/SystemLlmStanceTypes.js.map +1 -0
  67. package/dist/types/TaskTypes.d.ts +29 -0
  68. package/dist/types/TaskTypes.d.ts.map +1 -1
  69. package/dist/types/TaskTypes.js +41 -1
  70. package/dist/types/TaskTypes.js.map +1 -1
  71. package/dist/utils/PromptTemplateReplacer.d.ts +5 -0
  72. package/dist/utils/PromptTemplateReplacer.d.ts.map +1 -1
  73. package/dist/utils/PromptTemplateReplacer.js +13 -0
  74. package/dist/utils/PromptTemplateReplacer.js.map +1 -1
  75. package/package.json +1 -1
  76. package/src/config/ConfigManager.ts +126 -1
  77. package/src/config/MeilisearchIngressLimits.ts +63 -0
  78. package/src/database/adapters/mongodb/MongoChannelRepository.ts +2 -1
  79. package/src/events/event-definitions/ConfigEvents.ts +8 -0
  80. package/src/events/event-definitions/MeilisearchEvents.ts +7 -1
  81. package/src/events/event-definitions/SystemEvents.ts +24 -0
  82. package/src/index.ts +7 -0
  83. package/src/interfaces/Channel.ts +4 -0
  84. package/src/interfaces/ChannelConfig.ts +6 -0
  85. package/src/interfaces/ConversationMessage.ts +1 -0
  86. package/src/models/channel.ts +10 -0
  87. package/src/models/task.ts +5 -1
  88. package/src/prompts/MxfAgentSystemPrompt.ts +9 -1
  89. package/src/prompts/SystemLlmStanceGuidance.ts +67 -0
  90. package/src/repositories/interfaces/IChannelRepository.ts +2 -0
  91. package/src/schemas/EventPayloadSchema.ts +44 -1
  92. package/src/services/BackgroundTaskManager.ts +35 -4
  93. package/src/services/MxfMeilisearchService.ts +55 -43
  94. package/src/types/SystemLlmStanceTypes.ts +162 -0
  95. package/src/types/TaskTypes.ts +69 -2
  96. package/src/utils/PromptTemplateReplacer.ts +17 -0
@@ -109,7 +109,11 @@ export interface ChannelTask {
109
109
  dependsOn?: string[]; // Task IDs this task depends on
110
110
  blockedBy?: string[]; // Task IDs that block this task
111
111
 
112
- // Results and outcomes
112
+ // Results and outcomes. `output` is whatever the caller passed to
113
+ // completeTask() or the REST completion route, or a TaskCompletionOutput
114
+ // when an agent completed the task by calling task_complete. There is no
115
+ // `result.summary` — use getTaskCompletionOutput() to read the summary
116
+ // safely regardless of which completion path produced this task.
113
117
  result?: {
114
118
  success?: boolean;
115
119
  output?: any;
@@ -117,10 +121,73 @@ export interface ChannelTask {
117
121
  completedAt?: number;
118
122
  completedBy?: string;
119
123
  };
120
-
124
+
121
125
  assignmentStrategy: AssignmentStrategy;
122
126
  }
123
127
 
128
+ /**
129
+ * What `task_complete` stores in `ChannelTask.result.output`.
130
+ *
131
+ * This is the shape TaskService.handleTaskCompletion writes when an agent
132
+ * completes a task through the task_complete tool. It is not the only shape
133
+ * `result.output` can hold: a caller can also set `result.output` directly
134
+ * through completeTask() or the REST completion route, so this type is a
135
+ * guard to check against, not a blanket narrowing of `output`.
136
+ */
137
+ export interface TaskCompletionOutput {
138
+ agentId: string;
139
+ summary: string;
140
+ details?: Record<string, unknown>;
141
+ nextSteps?: string;
142
+ reportedSuccess: boolean;
143
+ requestId: string;
144
+ }
145
+
146
+ /**
147
+ * Checks whether a value matches the TaskCompletionOutput shape.
148
+ * Used to read `result.output` from a task without assuming which
149
+ * completion path (task_complete vs. completeTask()/REST) produced it.
150
+ */
151
+ export function isTaskCompletionOutput(value: unknown): value is TaskCompletionOutput {
152
+ if (typeof value !== 'object' || value === null) {
153
+ return false;
154
+ }
155
+ const candidate = value as Record<string, unknown>;
156
+ if (typeof candidate.agentId !== 'string' || candidate.agentId.length === 0) {
157
+ return false;
158
+ }
159
+ if (typeof candidate.summary !== 'string') {
160
+ return false;
161
+ }
162
+ if (typeof candidate.reportedSuccess !== 'boolean') {
163
+ return false;
164
+ }
165
+ if (typeof candidate.requestId !== 'string' || candidate.requestId.length === 0) {
166
+ return false;
167
+ }
168
+ if (candidate.details !== undefined) {
169
+ if (typeof candidate.details !== 'object' || candidate.details === null || Array.isArray(candidate.details)) {
170
+ return false;
171
+ }
172
+ }
173
+ if (candidate.nextSteps !== undefined && typeof candidate.nextSteps !== 'string') {
174
+ return false;
175
+ }
176
+ return true;
177
+ }
178
+
179
+ /**
180
+ * Reads `task.result.output` as a TaskCompletionOutput, or returns undefined
181
+ * when the task has no result, no output, or an output that does not match
182
+ * (e.g. a value a caller passed directly to completeTask()/REST).
183
+ */
184
+ export function getTaskCompletionOutput(
185
+ task: Pick<ChannelTask, 'result'> | null | undefined
186
+ ): TaskCompletionOutput | undefined {
187
+ const output = task?.result?.output;
188
+ return isTaskCompletionOutput(output) ? output : undefined;
189
+ }
190
+
124
191
  /**
125
192
  * Task creation request
126
193
  */
@@ -31,8 +31,12 @@
31
31
  * - {{ISO_TIMESTAMP}}: Current ISO 8601 timestamp
32
32
  * - {{AGENT_ID}}: Agent ID (context-based)
33
33
  * - {{CHANNEL_ID}}: Channel ID (context-based)
34
+ * - {{SYSTEM_LLM_STANCE}} / {{SYSTEM_LLM_STANCE_GUIDANCE}}: the channel's SystemLLM stance and what it means for the agent
34
35
  */
35
36
 
37
+ import { DEFAULT_SYSTEMLLM_STANCE, type SystemLlmStance } from '../types/SystemLlmStanceTypes.js';
38
+ import { buildSystemLlmStanceGuidance } from '../prompts/SystemLlmStanceGuidance.js';
39
+
36
40
  /**
37
41
  * Available prompt templates as constants
38
42
  * Export these for use in prompt builders
@@ -60,6 +64,8 @@ export const PROMPT_TEMPLATES = {
60
64
  LLM_PROVIDER: '{{LLM_PROVIDER}}',
61
65
  LLM_MODEL: '{{LLM_MODEL}}',
62
66
  SYSTEM_LLM_STATUS: '{{SYSTEM_LLM_STATUS}}',
67
+ SYSTEM_LLM_STANCE: '{{SYSTEM_LLM_STANCE}}',
68
+ SYSTEM_LLM_STANCE_GUIDANCE: '{{SYSTEM_LLM_STANCE_GUIDANCE}}',
63
69
  OS_PLATFORM: '{{OS_PLATFORM}}',
64
70
 
65
71
  // Control loop state
@@ -92,6 +98,8 @@ export interface TemplateContext {
92
98
 
93
99
  // System status
94
100
  systemLlmEnabled?: boolean;
101
+ // SystemLLM stance of the channel; unset is treated as supportive
102
+ systemLlmStance?: SystemLlmStance;
95
103
 
96
104
  // Control loop state
97
105
  currentOrparPhase?: 'Observe' | 'Reason' | 'Plan' | 'Act' | 'Reflect' | null;
@@ -224,6 +232,15 @@ export class PromptTemplateReplacer {
224
232
  const statusStr = context.systemLlmEnabled ? 'Enabled' : 'Disabled';
225
233
  result = result.replace(/\{\{SYSTEM_LLM_STATUS\}\}/g, statusStr);
226
234
  }
235
+
236
+ // Replace the SystemLLM stance and its guidance. Always replaced: an
237
+ // agent that does not know the stance is told the supportive one, which
238
+ // is the stance a server that never sends one is running.
239
+ const stance = context.systemLlmStance ?? DEFAULT_SYSTEMLLM_STANCE;
240
+ const stanceGuidance = buildSystemLlmStanceGuidance(stance);
241
+ result = result.replace(/\{\{SYSTEM_LLM_STANCE\}\}/g, stance);
242
+ // Function replacer: the guidance is prose and must not be parsed for `$` patterns.
243
+ result = result.replace(/\{\{SYSTEM_LLM_STANCE_GUIDANCE\}\}/g, () => stanceGuidance);
227
244
 
228
245
  // Replace ORPAR phase - always replace to avoid leftover template markers
229
246
  // When phase is null, show "(Not in active cycle)" to indicate ORPAR is available but not running