aimeat 1.7.0 → 1.9.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 (261) hide show
  1. package/dist/.env.example +4 -1
  2. package/dist/locales/en.json +573 -10
  3. package/dist/locales/fi.json +572 -9
  4. package/dist/public/css/views/admin-agent-integration.css +304 -0
  5. package/dist/public/css/views/agents-detail.css +1697 -120
  6. package/dist/public/css/views/profile.css +22 -2
  7. package/dist/public/css/views/public-knowledge-viewer.css +479 -0
  8. package/dist/public/js/i18n.js +9 -3
  9. package/dist/public/js/services/admin-agent-integration.js +52 -0
  10. package/dist/public/js/services/agent-integration.js +80 -0
  11. package/dist/public/js/services/agent-messages.js +3 -1
  12. package/dist/public/js/services/generator-spec-validate.js +23 -0
  13. package/dist/public/js/services/memory.js +39 -0
  14. package/dist/public/lib/live-updates.js +9 -4
  15. package/dist/public/llms-template.txt +106 -0
  16. package/dist/public/spa.html +7 -2
  17. package/dist/public/views/admin/agent-integration-tab.js +390 -0
  18. package/dist/public/views/admin/federation-tab.js +5 -5
  19. package/dist/public/views/admin/prompts-tab.js +9 -10
  20. package/dist/public/views/admin.js +2 -0
  21. package/dist/public/views/profile/access-tab.js +18 -0
  22. package/dist/public/views/profile/agents/agent-card.js +396 -0
  23. package/dist/public/views/profile/agents/shared-board.js +97 -0
  24. package/dist/public/views/profile/agents/state-detector.js +62 -0
  25. package/dist/public/views/profile/agents/tab-activity.js +232 -0
  26. package/dist/public/views/profile/agents/tab-agent-config.js +199 -0
  27. package/dist/public/views/profile/agents/tab-data-access.js +304 -0
  28. package/dist/public/views/profile/agents/tab-directives.js +178 -0
  29. package/dist/public/views/profile/agents/tab-integration.js +505 -0
  30. package/dist/public/views/profile/agents/tab-messages.js +278 -0
  31. package/dist/public/views/profile/agents/tab-services.js +17 -0
  32. package/dist/public/views/profile/agents/tab-tasks.js +17 -0
  33. package/dist/public/views/profile/agents-messages-subtab.js +12 -10
  34. package/dist/public/views/profile/agents-services-subtab.js +17 -11
  35. package/dist/public/views/profile/agents-tab.js +159 -255
  36. package/dist/public/views/profile/agents-task-builder.js +403 -0
  37. package/dist/public/views/profile/agents-tasks-subtab.js +186 -140
  38. package/dist/public/views/profile/generator-detail.js +8 -1
  39. package/dist/public/views/profile/memory-tab.js +371 -7
  40. package/dist/public/views/profile/wallet-tab.js +14 -0
  41. package/dist/public/views/public-knowledge-viewer.js +650 -0
  42. package/dist/src/auth/middleware.d.ts.map +1 -1
  43. package/dist/src/auth/middleware.js +17 -0
  44. package/dist/src/auth/middleware.js.map +1 -1
  45. package/dist/src/config.d.ts +1 -0
  46. package/dist/src/config.d.ts.map +1 -1
  47. package/dist/src/config.js +1 -0
  48. package/dist/src/config.js.map +1 -1
  49. package/dist/src/middleware/readiness-gate.d.ts +18 -0
  50. package/dist/src/middleware/readiness-gate.d.ts.map +1 -0
  51. package/dist/src/middleware/readiness-gate.js +50 -0
  52. package/dist/src/middleware/readiness-gate.js.map +1 -0
  53. package/dist/src/models/agent-capabilities-schemas.d.ts +3 -0
  54. package/dist/src/models/agent-capabilities-schemas.d.ts.map +1 -1
  55. package/dist/src/models/agent-capabilities-schemas.js +3 -0
  56. package/dist/src/models/agent-capabilities-schemas.js.map +1 -1
  57. package/dist/src/models/agent-directives-schemas.d.ts +12 -0
  58. package/dist/src/models/agent-directives-schemas.d.ts.map +1 -1
  59. package/dist/src/models/agent-directives-schemas.js +7 -0
  60. package/dist/src/models/agent-directives-schemas.js.map +1 -1
  61. package/dist/src/models/agent-onboarding-schemas.d.ts +45 -0
  62. package/dist/src/models/agent-onboarding-schemas.d.ts.map +1 -0
  63. package/dist/src/models/agent-onboarding-schemas.js +91 -0
  64. package/dist/src/models/agent-onboarding-schemas.js.map +1 -0
  65. package/dist/src/models/webhook-schemas.d.ts +266 -0
  66. package/dist/src/models/webhook-schemas.d.ts.map +1 -0
  67. package/dist/src/models/webhook-schemas.js +137 -0
  68. package/dist/src/models/webhook-schemas.js.map +1 -0
  69. package/dist/src/routes/admin-agent-integration.d.ts +24 -0
  70. package/dist/src/routes/admin-agent-integration.d.ts.map +1 -0
  71. package/dist/src/routes/admin-agent-integration.js +186 -0
  72. package/dist/src/routes/admin-agent-integration.js.map +1 -0
  73. package/dist/src/routes/admin-monitoring.js +12 -7
  74. package/dist/src/routes/admin-monitoring.js.map +1 -1
  75. package/dist/src/routes/agent-activity.d.ts.map +1 -1
  76. package/dist/src/routes/agent-activity.js +17 -0
  77. package/dist/src/routes/agent-activity.js.map +1 -1
  78. package/dist/src/routes/agent-capabilities.d.ts +1 -0
  79. package/dist/src/routes/agent-capabilities.d.ts.map +1 -1
  80. package/dist/src/routes/agent-capabilities.js +9 -0
  81. package/dist/src/routes/agent-capabilities.js.map +1 -1
  82. package/dist/src/routes/agent-directives.d.ts +5 -1
  83. package/dist/src/routes/agent-directives.d.ts.map +1 -1
  84. package/dist/src/routes/agent-directives.js +74 -20
  85. package/dist/src/routes/agent-directives.js.map +1 -1
  86. package/dist/src/routes/agent-integration.d.ts +1 -0
  87. package/dist/src/routes/agent-integration.d.ts.map +1 -1
  88. package/dist/src/routes/agent-integration.js +128 -11
  89. package/dist/src/routes/agent-integration.js.map +1 -1
  90. package/dist/src/routes/agent-messages.d.ts +5 -1
  91. package/dist/src/routes/agent-messages.d.ts.map +1 -1
  92. package/dist/src/routes/agent-messages.js +20 -1
  93. package/dist/src/routes/agent-messages.js.map +1 -1
  94. package/dist/src/routes/agent-onboarding.d.ts +23 -0
  95. package/dist/src/routes/agent-onboarding.d.ts.map +1 -0
  96. package/dist/src/routes/agent-onboarding.js +374 -0
  97. package/dist/src/routes/agent-onboarding.js.map +1 -0
  98. package/dist/src/routes/agent-skill-bundle.d.ts +16 -0
  99. package/dist/src/routes/agent-skill-bundle.d.ts.map +1 -0
  100. package/dist/src/routes/agent-skill-bundle.js +133 -0
  101. package/dist/src/routes/agent-skill-bundle.js.map +1 -0
  102. package/dist/src/routes/agent-tasks.d.ts +8 -1
  103. package/dist/src/routes/agent-tasks.d.ts.map +1 -1
  104. package/dist/src/routes/agent-tasks.js +192 -14
  105. package/dist/src/routes/agent-tasks.js.map +1 -1
  106. package/dist/src/routes/agent-telemetry.d.ts +15 -0
  107. package/dist/src/routes/agent-telemetry.d.ts.map +1 -0
  108. package/dist/src/routes/agent-telemetry.js +99 -0
  109. package/dist/src/routes/agent-telemetry.js.map +1 -0
  110. package/dist/src/routes/agent-webhook.d.ts +18 -0
  111. package/dist/src/routes/agent-webhook.d.ts.map +1 -0
  112. package/dist/src/routes/agent-webhook.js +243 -0
  113. package/dist/src/routes/agent-webhook.js.map +1 -0
  114. package/dist/src/routes/agents.d.ts.map +1 -1
  115. package/dist/src/routes/agents.js +203 -4
  116. package/dist/src/routes/agents.js.map +1 -1
  117. package/dist/src/routes/auth.d.ts.map +1 -1
  118. package/dist/src/routes/auth.js +45 -2
  119. package/dist/src/routes/auth.js.map +1 -1
  120. package/dist/src/routes/federation-auth.d.ts.map +1 -1
  121. package/dist/src/routes/federation-auth.js +3 -1
  122. package/dist/src/routes/federation-auth.js.map +1 -1
  123. package/dist/src/routes/federation-peer.d.ts.map +1 -1
  124. package/dist/src/routes/federation-peer.js +11 -2
  125. package/dist/src/routes/federation-peer.js.map +1 -1
  126. package/dist/src/routes/federation-sync.d.ts +1 -0
  127. package/dist/src/routes/federation-sync.d.ts.map +1 -1
  128. package/dist/src/routes/federation-sync.js +29 -0
  129. package/dist/src/routes/federation-sync.js.map +1 -1
  130. package/dist/src/routes/ghii.d.ts.map +1 -1
  131. package/dist/src/routes/ghii.js +42 -5
  132. package/dist/src/routes/ghii.js.map +1 -1
  133. package/dist/src/routes/knowledge.d.ts.map +1 -1
  134. package/dist/src/routes/knowledge.js +19 -7
  135. package/dist/src/routes/knowledge.js.map +1 -1
  136. package/dist/src/routes/memory.d.ts +9 -0
  137. package/dist/src/routes/memory.d.ts.map +1 -1
  138. package/dist/src/routes/memory.js +307 -12
  139. package/dist/src/routes/memory.js.map +1 -1
  140. package/dist/src/routes/portal.d.ts.map +1 -1
  141. package/dist/src/routes/portal.js +1 -0
  142. package/dist/src/routes/portal.js.map +1 -1
  143. package/dist/src/routes/prompts.d.ts +1 -0
  144. package/dist/src/routes/prompts.d.ts.map +1 -1
  145. package/dist/src/routes/prompts.js +40 -1
  146. package/dist/src/routes/prompts.js.map +1 -1
  147. package/dist/src/routes/sharing-groups.d.ts.map +1 -1
  148. package/dist/src/routes/sharing-groups.js +8 -2
  149. package/dist/src/routes/sharing-groups.js.map +1 -1
  150. package/dist/src/routes/wallet.d.ts.map +1 -1
  151. package/dist/src/routes/wallet.js +2 -0
  152. package/dist/src/routes/wallet.js.map +1 -1
  153. package/dist/src/server-bootstrap/routes-loader.d.ts.map +1 -1
  154. package/dist/src/server-bootstrap/routes-loader.js +47 -3
  155. package/dist/src/server-bootstrap/routes-loader.js.map +1 -1
  156. package/dist/src/services/config-schema.d.ts.map +1 -1
  157. package/dist/src/services/config-schema.js +2 -1
  158. package/dist/src/services/config-schema.js.map +1 -1
  159. package/dist/src/services/core-jobs.d.ts.map +1 -1
  160. package/dist/src/services/core-jobs.js +3 -2
  161. package/dist/src/services/core-jobs.js.map +1 -1
  162. package/dist/src/services/federation-helpers.d.ts +1 -0
  163. package/dist/src/services/federation-helpers.d.ts.map +1 -1
  164. package/dist/src/services/federation-helpers.js +1 -1
  165. package/dist/src/services/federation-helpers.js.map +1 -1
  166. package/dist/src/services/generator-autopilot.d.ts.map +1 -1
  167. package/dist/src/services/generator-autopilot.js +125 -26
  168. package/dist/src/services/generator-autopilot.js.map +1 -1
  169. package/dist/src/services/generator-prompts/index.d.ts +1 -1
  170. package/dist/src/services/generator-prompts/index.d.ts.map +1 -1
  171. package/dist/src/services/generator-prompts/index.js +1 -1
  172. package/dist/src/services/generator-prompts/index.js.map +1 -1
  173. package/dist/src/services/generator-prompts/spec-validate.d.ts +1 -0
  174. package/dist/src/services/generator-prompts/spec-validate.d.ts.map +1 -1
  175. package/dist/src/services/generator-prompts/spec-validate.js +20 -0
  176. package/dist/src/services/generator-prompts/spec-validate.js.map +1 -1
  177. package/dist/src/services/generator-prompts/validate.d.ts +7 -1
  178. package/dist/src/services/generator-prompts/validate.d.ts.map +1 -1
  179. package/dist/src/services/generator-prompts/validate.js +70 -0
  180. package/dist/src/services/generator-prompts/validate.js.map +1 -1
  181. package/dist/src/services/onboarding-validator.d.ts +22 -0
  182. package/dist/src/services/onboarding-validator.d.ts.map +1 -0
  183. package/dist/src/services/onboarding-validator.js +202 -0
  184. package/dist/src/services/onboarding-validator.js.map +1 -0
  185. package/dist/src/services/platform-detector.d.ts +27 -0
  186. package/dist/src/services/platform-detector.d.ts.map +1 -0
  187. package/dist/src/services/platform-detector.js +73 -0
  188. package/dist/src/services/platform-detector.js.map +1 -0
  189. package/dist/src/services/prompt-defaults.d.ts +1 -0
  190. package/dist/src/services/prompt-defaults.d.ts.map +1 -1
  191. package/dist/src/services/prompt-defaults.js +875 -47
  192. package/dist/src/services/prompt-defaults.js.map +1 -1
  193. package/dist/src/services/prompt-seeder.js +1 -1
  194. package/dist/src/services/prompt-seeder.js.map +1 -1
  195. package/dist/src/services/readiness-scorer.d.ts +34 -0
  196. package/dist/src/services/readiness-scorer.d.ts.map +1 -0
  197. package/dist/src/services/readiness-scorer.js +87 -0
  198. package/dist/src/services/readiness-scorer.js.map +1 -0
  199. package/dist/src/services/skill-bundle/generator.d.ts +17 -0
  200. package/dist/src/services/skill-bundle/generator.d.ts.map +1 -0
  201. package/dist/src/services/skill-bundle/generator.js +387 -0
  202. package/dist/src/services/skill-bundle/generator.js.map +1 -0
  203. package/dist/src/services/skill-bundle/generic-adapter.d.ts +16 -0
  204. package/dist/src/services/skill-bundle/generic-adapter.d.ts.map +1 -0
  205. package/dist/src/services/skill-bundle/generic-adapter.js +96 -0
  206. package/dist/src/services/skill-bundle/generic-adapter.js.map +1 -0
  207. package/dist/src/services/skill-bundle/hermes-adapter.d.ts +25 -0
  208. package/dist/src/services/skill-bundle/hermes-adapter.d.ts.map +1 -0
  209. package/dist/src/services/skill-bundle/hermes-adapter.js +302 -0
  210. package/dist/src/services/skill-bundle/hermes-adapter.js.map +1 -0
  211. package/dist/src/services/skill-bundle/types.d.ts +54 -0
  212. package/dist/src/services/skill-bundle/types.d.ts.map +1 -0
  213. package/dist/src/services/skill-bundle/types.js +8 -0
  214. package/dist/src/services/skill-bundle/types.js.map +1 -0
  215. package/dist/src/services/task-stall-detector.d.ts +10 -2
  216. package/dist/src/services/task-stall-detector.d.ts.map +1 -1
  217. package/dist/src/services/task-stall-detector.js +34 -5
  218. package/dist/src/services/task-stall-detector.js.map +1 -1
  219. package/dist/src/services/webhook-dispatcher.d.ts +71 -0
  220. package/dist/src/services/webhook-dispatcher.d.ts.map +1 -0
  221. package/dist/src/services/webhook-dispatcher.js +259 -0
  222. package/dist/src/services/webhook-dispatcher.js.map +1 -0
  223. package/dist/src/storage/interface.d.ts +82 -2
  224. package/dist/src/storage/interface.d.ts.map +1 -1
  225. package/dist/src/storage/providers/mongodb/index.d.ts +20 -1
  226. package/dist/src/storage/providers/mongodb/index.d.ts.map +1 -1
  227. package/dist/src/storage/providers/mongodb/index.js +254 -3
  228. package/dist/src/storage/providers/mongodb/index.js.map +1 -1
  229. package/dist/src/storage/providers/sqlite/index.d.ts +18 -1
  230. package/dist/src/storage/providers/sqlite/index.d.ts.map +1 -1
  231. package/dist/src/storage/providers/sqlite/index.js +173 -4
  232. package/dist/src/storage/providers/sqlite/index.js.map +1 -1
  233. package/dist/src/storage/providers/sqlite/repos/agent-directives.d.ts.map +1 -1
  234. package/dist/src/storage/providers/sqlite/repos/agent-directives.js +8 -4
  235. package/dist/src/storage/providers/sqlite/repos/agent-directives.js.map +1 -1
  236. package/dist/src/storage/providers/sqlite/repos/agent.d.ts.map +1 -1
  237. package/dist/src/storage/providers/sqlite/repos/agent.js +25 -4
  238. package/dist/src/storage/providers/sqlite/repos/agent.js.map +1 -1
  239. package/dist/src/storage/providers/sqlite/schema.d.ts.map +1 -1
  240. package/dist/src/storage/providers/sqlite/schema.js +73 -1
  241. package/dist/src/storage/providers/sqlite/schema.js.map +1 -1
  242. package/dist/src/storage/repositories/agent-onboarding.repository.d.ts +16 -0
  243. package/dist/src/storage/repositories/agent-onboarding.repository.d.ts.map +1 -0
  244. package/dist/src/storage/repositories/agent-onboarding.repository.js +8 -0
  245. package/dist/src/storage/repositories/agent-onboarding.repository.js.map +1 -0
  246. package/dist/src/storage/repositories/agent-webhook.repository.d.ts +21 -0
  247. package/dist/src/storage/repositories/agent-webhook.repository.d.ts.map +1 -0
  248. package/dist/src/storage/repositories/agent-webhook.repository.js +2 -0
  249. package/dist/src/storage/repositories/agent-webhook.repository.js.map +1 -0
  250. package/dist/src/storage/repositories/agent.repository.d.ts +1 -0
  251. package/dist/src/storage/repositories/agent.repository.d.ts.map +1 -1
  252. package/dist/src/storage/repositories/index.d.ts +2 -0
  253. package/dist/src/storage/repositories/index.d.ts.map +1 -1
  254. package/dist/src/utils/env-config.d.ts.map +1 -1
  255. package/dist/src/utils/env-config.js +7 -1
  256. package/dist/src/utils/env-config.js.map +1 -1
  257. package/dist/src/utils/url-validator.d.ts.map +1 -1
  258. package/dist/src/utils/url-validator.js +3 -0
  259. package/dist/src/utils/url-validator.js.map +1 -1
  260. package/package.json +1 -1
  261. package/prisma/schema.prisma +67 -7
@@ -186,6 +186,18 @@ export class MongoStorage {
186
186
  technicalCapabilities: agent.technicalCapabilities ?? null,
187
187
  domainCapabilities: agent.domainCapabilities ?? null,
188
188
  activityStats: agent.activityStats ?? null,
189
+ modulesLoaded: agent.modulesLoaded ?? null,
190
+ agentLimitations: agent.agentLimitations ?? null,
191
+ webhookUrl: agent.webhookUrl ?? null,
192
+ webhookSecret: agent.webhookSecret ?? null,
193
+ webhookEnabled: agent.webhookEnabled ?? false,
194
+ webhookLastSuccess: agent.webhookLastSuccess ? new Date(agent.webhookLastSuccess) : null,
195
+ webhookLastFailure: agent.webhookLastFailure ? new Date(agent.webhookLastFailure) : null,
196
+ webhookFailCount: agent.webhookFailCount ?? 0,
197
+ platform: agent.platform ?? null,
198
+ platformVersion: agent.platformVersion ?? null,
199
+ platformDetectedBy: agent.platformDetectedBy ?? null,
200
+ tags: agent.tags ?? [],
189
201
  createdAt: new Date(agent.createdAt),
190
202
  lastSeen: new Date(agent.lastSeen),
191
203
  },
@@ -197,6 +209,11 @@ export class MongoStorage {
197
209
  const row = await this.prisma.agent.findUnique({ where: { gaii } });
198
210
  return row ? this.toAgentRecord(row) : null;
199
211
  }
212
+ async getAgentByName(name, nodeId) {
213
+ this.ensureReady();
214
+ const row = await this.prisma.agent.findFirst({ where: { name } });
215
+ return row ? this.toAgentRecord(row) : null;
216
+ }
200
217
  async getAgentsByOwner(owner) {
201
218
  this.ensureReady();
202
219
  const rows = await this.prisma.agent.findMany({ where: { owner } });
@@ -208,7 +225,8 @@ export class MongoStorage {
208
225
  const row = await this.prisma.agent.update({ where: { gaii }, data: updates });
209
226
  return this.toAgentRecord(row);
210
227
  }
211
- catch {
228
+ catch (err) {
229
+ logger.warn('updateAgent failed for %s: %s', gaii, err.message);
212
230
  return null;
213
231
  }
214
232
  }
@@ -294,6 +312,19 @@ export class MongoStorage {
294
312
  catch { /* not found */ }
295
313
  // Agent activity
296
314
  await this.prisma.agentActivity.deleteMany({ where: { agentGaii: gaii } });
315
+ // Agent messages
316
+ await this.prisma.agentMessage.deleteMany({ where: { agentGaii: gaii } });
317
+ // Telemetry events
318
+ await this.prisma.telemetryEvent.deleteMany({ where: { agentGaii: gaii } });
319
+ // Webhook delivery logs
320
+ await this.prisma.webhookDeliveryLog.deleteMany({ where: { agentGaii: gaii } });
321
+ // Onboarding record
322
+ try {
323
+ await this.prisma.agentOnboarding.delete({ where: { agentGaii: gaii } });
324
+ }
325
+ catch { /* not found */ }
326
+ // Sharing groups
327
+ await this.prisma.sharingGroup.deleteMany({ where: { ownerGaii: gaii } });
297
328
  }
298
329
  async listAgents() {
299
330
  this.ensureReady();
@@ -1380,7 +1411,7 @@ export class MongoStorage {
1380
1411
  return { name: row.name, displayName: row.displayName ?? undefined, publicKey: row.publicKey, roles: row.roles, createdAt: row.createdAt.toISOString() };
1381
1412
  }
1382
1413
  toAgentRecord(row) {
1383
- return { name: row.name, owner: row.owner, gaii: row.gaii, displayName: row.displayName ?? undefined, description: row.description ?? undefined, capabilities: row.capabilities, publicKey: row.publicKey, trustScore: row.trustScore, morselBalance: row.morselBalance, defaultScopes: row.defaultScopes?.length ? row.defaultScopes : undefined, allowedOrigins: row.allowedOrigins?.length ? row.allowedOrigins : undefined, federate: row.federate ?? false, technicalCapabilities: row.technicalCapabilities ?? undefined, domainCapabilities: row.domainCapabilities ?? undefined, activityStats: row.activityStats ?? undefined, createdAt: row.createdAt.toISOString(), lastSeen: row.lastSeen.toISOString() };
1414
+ return { name: row.name, owner: row.owner, gaii: row.gaii, displayName: row.displayName ?? undefined, description: row.description ?? undefined, capabilities: row.capabilities, publicKey: row.publicKey, trustScore: row.trustScore, morselBalance: row.morselBalance, defaultScopes: row.defaultScopes?.length ? row.defaultScopes : undefined, allowedOrigins: row.allowedOrigins?.length ? row.allowedOrigins : undefined, federate: row.federate ?? false, technicalCapabilities: row.technicalCapabilities ?? undefined, domainCapabilities: row.domainCapabilities ?? undefined, activityStats: row.activityStats ?? undefined, modulesLoaded: row.modulesLoaded ?? undefined, agentLimitations: row.agentLimitations ?? undefined, webhookUrl: row.webhookUrl ?? undefined, webhookSecret: row.webhookSecret ?? undefined, webhookEnabled: row.webhookEnabled ?? false, webhookLastSuccess: row.webhookLastSuccess ? row.webhookLastSuccess.toISOString() : undefined, webhookLastFailure: row.webhookLastFailure ? row.webhookLastFailure.toISOString() : undefined, webhookFailCount: row.webhookFailCount ?? 0, platform: row.platform ?? undefined, platformVersion: row.platformVersion ?? undefined, platformDetectedBy: row.platformDetectedBy ?? undefined, tags: row.tags?.length ? row.tags : undefined, createdAt: row.createdAt.toISOString(), lastSeen: row.lastSeen.toISOString() };
1384
1415
  }
1385
1416
  toMemoryRecord(row) {
1386
1417
  return { key: row.key, ownerGaii: row.ownerGaii, value: row.value, visibility: row.visibility, groupId: row.groupId ?? undefined, tags: row.tags, ttlHours: row.ttlHours, version: row.version, createdAt: row.createdAt.toISOString(), updatedAt: row.updatedAt.toISOString(), flagCount: row.flagCount ?? undefined, allowedOrigins: row.allowedOrigins?.length ? row.allowedOrigins : undefined };
@@ -5690,7 +5721,7 @@ export class MongoStorage {
5690
5721
  }
5691
5722
  // ── Agent Directives ──
5692
5723
  toDirectivesRecord(row) {
5693
- return {
5724
+ const record = {
5694
5725
  agentGaii: row.agentGaii,
5695
5726
  purpose: row.purpose,
5696
5727
  rules: row.rules,
@@ -5698,6 +5729,9 @@ export class MongoStorage {
5698
5729
  resources: row.resources,
5699
5730
  updatedAt: row.updatedAt instanceof Date ? row.updatedAt.toISOString() : row.updatedAt,
5700
5731
  };
5732
+ if (row.budgetLimits)
5733
+ record.budgetLimits = row.budgetLimits;
5734
+ return record;
5701
5735
  }
5702
5736
  toOwnerDefaultsRecord(row) {
5703
5737
  const record = {
@@ -5727,12 +5761,14 @@ export class MongoStorage {
5727
5761
  rules: record.rules,
5728
5762
  memoryAreas: record.memoryAreas,
5729
5763
  resources: record.resources,
5764
+ budgetLimits: record.budgetLimits ?? null,
5730
5765
  },
5731
5766
  update: {
5732
5767
  purpose: record.purpose,
5733
5768
  rules: record.rules,
5734
5769
  memoryAreas: record.memoryAreas,
5735
5770
  resources: record.resources,
5771
+ budgetLimits: record.budgetLimits ?? null,
5736
5772
  },
5737
5773
  });
5738
5774
  return this.toDirectivesRecord(row);
@@ -5947,6 +5983,221 @@ export class MongoStorage {
5947
5983
  results.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
5948
5984
  return results;
5949
5985
  }
5986
+ // ══════════════════════════════════════════════════════════
5987
+ // ── Agent Onboarding ──
5988
+ // ══════════════════════════════════════════════════════════
5989
+ toOnboardingRecord(row) {
5990
+ return {
5991
+ agentGaii: row.agentGaii,
5992
+ status: row.status,
5993
+ startedAt: row.startedAt instanceof Date ? row.startedAt.toISOString() : row.startedAt,
5994
+ completedAt: row.completedAt instanceof Date ? row.completedAt.toISOString() : row.completedAt ?? undefined,
5995
+ steps: row.steps,
5996
+ readinessScore: row.readinessScore ?? undefined,
5997
+ readinessLevel: row.readinessLevel ?? undefined,
5998
+ detectedPlatform: row.detectedPlatform ?? undefined,
5999
+ installedRuntime: row.installedRuntime ?? undefined,
6000
+ onboardingBaseline: row.onboardingBaseline ?? undefined,
6001
+ operationalHealth: row.operationalHealth ?? undefined,
6002
+ healthComponents: row.healthComponents ?? undefined,
6003
+ healthRecalculatedAt: row.healthRecalculatedAt instanceof Date ? row.healthRecalculatedAt.toISOString() : row.healthRecalculatedAt ?? undefined,
6004
+ readinessOverride: row.readinessOverride ?? undefined,
6005
+ };
6006
+ }
6007
+ async createOnboarding(record) {
6008
+ this.ensureReady();
6009
+ const row = await this.prisma.agentOnboarding.create({
6010
+ data: {
6011
+ agentGaii: record.agentGaii,
6012
+ status: record.status,
6013
+ startedAt: new Date(record.startedAt),
6014
+ completedAt: record.completedAt ? new Date(record.completedAt) : null,
6015
+ steps: record.steps,
6016
+ readinessScore: record.readinessScore ?? null,
6017
+ readinessLevel: record.readinessLevel ?? null,
6018
+ detectedPlatform: record.detectedPlatform ?? null,
6019
+ installedRuntime: record.installedRuntime ?? null,
6020
+ onboardingBaseline: record.onboardingBaseline ?? null,
6021
+ operationalHealth: record.operationalHealth ?? null,
6022
+ healthComponents: record.healthComponents ?? null,
6023
+ healthRecalculatedAt: record.healthRecalculatedAt ? new Date(record.healthRecalculatedAt) : null,
6024
+ readinessOverride: record.readinessOverride ?? null,
6025
+ },
6026
+ });
6027
+ return this.toOnboardingRecord(row);
6028
+ }
6029
+ async getOnboarding(agentGaii) {
6030
+ this.ensureReady();
6031
+ try {
6032
+ const row = await this.prisma.agentOnboarding.findUnique({ where: { agentGaii } });
6033
+ return row ? this.toOnboardingRecord(row) : null;
6034
+ }
6035
+ catch {
6036
+ return null;
6037
+ }
6038
+ }
6039
+ async updateOnboarding(agentGaii, updates) {
6040
+ this.ensureReady();
6041
+ try {
6042
+ const data = {};
6043
+ if (updates.status !== undefined)
6044
+ data.status = updates.status;
6045
+ if (updates.startedAt !== undefined)
6046
+ data.startedAt = new Date(updates.startedAt);
6047
+ if (updates.completedAt !== undefined)
6048
+ data.completedAt = updates.completedAt ? new Date(updates.completedAt) : null;
6049
+ if (updates.steps !== undefined)
6050
+ data.steps = updates.steps;
6051
+ if (updates.readinessScore !== undefined)
6052
+ data.readinessScore = updates.readinessScore ?? null;
6053
+ if (updates.readinessLevel !== undefined)
6054
+ data.readinessLevel = updates.readinessLevel ?? null;
6055
+ if (updates.detectedPlatform !== undefined)
6056
+ data.detectedPlatform = updates.detectedPlatform ?? null;
6057
+ if (updates.installedRuntime !== undefined)
6058
+ data.installedRuntime = updates.installedRuntime ?? null;
6059
+ if (updates.onboardingBaseline !== undefined)
6060
+ data.onboardingBaseline = updates.onboardingBaseline ?? null;
6061
+ if (updates.operationalHealth !== undefined)
6062
+ data.operationalHealth = updates.operationalHealth ?? null;
6063
+ if (updates.healthComponents !== undefined)
6064
+ data.healthComponents = updates.healthComponents ?? null;
6065
+ if (updates.healthRecalculatedAt !== undefined)
6066
+ data.healthRecalculatedAt = updates.healthRecalculatedAt ? new Date(updates.healthRecalculatedAt) : null;
6067
+ if (updates.readinessOverride !== undefined)
6068
+ data.readinessOverride = updates.readinessOverride ?? null;
6069
+ const row = await this.prisma.agentOnboarding.update({ where: { agentGaii }, data });
6070
+ return this.toOnboardingRecord(row);
6071
+ }
6072
+ catch {
6073
+ return null;
6074
+ }
6075
+ }
6076
+ async deleteOnboarding(agentGaii) {
6077
+ this.ensureReady();
6078
+ try {
6079
+ await this.prisma.agentOnboarding.delete({ where: { agentGaii } });
6080
+ return true;
6081
+ }
6082
+ catch {
6083
+ return false;
6084
+ }
6085
+ }
6086
+ async listOnboardingByOwner(owner) {
6087
+ this.ensureReady();
6088
+ const rows = await this.prisma.agentOnboarding.findMany({
6089
+ where: { agentGaii: { contains: `#${owner}@` } },
6090
+ orderBy: { startedAt: 'desc' },
6091
+ });
6092
+ return rows.map((r) => this.toOnboardingRecord(r));
6093
+ }
6094
+ async listOnboardingByStatus(status) {
6095
+ this.ensureReady();
6096
+ const rows = await this.prisma.agentOnboarding.findMany({
6097
+ where: { status },
6098
+ orderBy: { startedAt: 'desc' },
6099
+ });
6100
+ return rows.map((r) => this.toOnboardingRecord(r));
6101
+ }
6102
+ // ── Agent Telemetry ──
6103
+ toTelemetryEvent(row) {
6104
+ return {
6105
+ id: row.id,
6106
+ agentGaii: row.agentGaii,
6107
+ type: row.type,
6108
+ data: row.data,
6109
+ sessionId: row.sessionId ?? undefined,
6110
+ taskId: row.taskId ?? undefined,
6111
+ createdAt: row.createdAt.toISOString(),
6112
+ };
6113
+ }
6114
+ async appendTelemetry(event) {
6115
+ this.ensureReady();
6116
+ await this.prisma.telemetryEvent.create({
6117
+ data: {
6118
+ id: event.id,
6119
+ agentGaii: event.agentGaii,
6120
+ type: event.type,
6121
+ data: event.data,
6122
+ sessionId: event.sessionId ?? null,
6123
+ taskId: event.taskId ?? null,
6124
+ createdAt: new Date(event.createdAt),
6125
+ },
6126
+ });
6127
+ }
6128
+ async listTelemetry(agentGaii, opts) {
6129
+ this.ensureReady();
6130
+ const where = { agentGaii };
6131
+ if (opts.type)
6132
+ where.type = opts.type;
6133
+ if (opts.since)
6134
+ where.createdAt = { gt: new Date(opts.since) };
6135
+ const rows = await this.prisma.telemetryEvent.findMany({
6136
+ where,
6137
+ orderBy: { createdAt: 'desc' },
6138
+ take: opts.limit ?? 50,
6139
+ });
6140
+ return rows.map((r) => this.toTelemetryEvent(r));
6141
+ }
6142
+ // ── Webhook Delivery Log ──
6143
+ toDeliveryLog(row) {
6144
+ return {
6145
+ id: row.id,
6146
+ agentGaii: row.agentGaii,
6147
+ event: row.event,
6148
+ payload: row.payload,
6149
+ status: row.status,
6150
+ httpStatus: row.httpStatus ?? undefined,
6151
+ errorMessage: row.errorMessage ?? undefined,
6152
+ attemptCount: row.attemptCount,
6153
+ latencyMs: row.latencyMs,
6154
+ createdAt: row.createdAt.toISOString(),
6155
+ };
6156
+ }
6157
+ async appendDeliveryLog(log) {
6158
+ this.ensureReady();
6159
+ await this.prisma.webhookDeliveryLog.create({
6160
+ data: {
6161
+ id: log.id,
6162
+ agentGaii: log.agentGaii,
6163
+ event: log.event,
6164
+ payload: log.payload,
6165
+ status: log.status,
6166
+ httpStatus: log.httpStatus ?? null,
6167
+ errorMessage: log.errorMessage ?? null,
6168
+ attemptCount: log.attemptCount,
6169
+ latencyMs: log.latencyMs,
6170
+ createdAt: new Date(log.createdAt),
6171
+ },
6172
+ });
6173
+ }
6174
+ async listDeliveryLog(agentGaii, limit) {
6175
+ this.ensureReady();
6176
+ const rows = await this.prisma.webhookDeliveryLog.findMany({
6177
+ where: { agentGaii },
6178
+ orderBy: { createdAt: 'desc' },
6179
+ take: limit ?? 50,
6180
+ });
6181
+ return rows.map((r) => this.toDeliveryLog(r));
6182
+ }
6183
+ async pruneDeliveryLog(agentGaii, keepCount) {
6184
+ this.ensureReady();
6185
+ // Find the cutoff: the keepCount-th newest record's createdAt
6186
+ const cutoffRows = await this.prisma.webhookDeliveryLog.findMany({
6187
+ where: { agentGaii },
6188
+ orderBy: { createdAt: 'desc' },
6189
+ skip: keepCount,
6190
+ take: 1,
6191
+ select: { createdAt: true },
6192
+ });
6193
+ if (cutoffRows.length === 0)
6194
+ return 0;
6195
+ const cutoff = cutoffRows[0].createdAt;
6196
+ const result = await this.prisma.webhookDeliveryLog.deleteMany({
6197
+ where: { agentGaii, createdAt: { lte: cutoff } },
6198
+ });
6199
+ return result.count;
6200
+ }
5950
6201
  }
5951
6202
  /**
5952
6203
  * Wildcard pattern matching: supports '*' (one segment) and '**' (multiple segments)