botinabox 2.4.2 → 2.5.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 (277) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +190 -190
  3. package/bin/botinabox.mjs +2 -2
  4. package/dist/channels/slack/index.d.ts +1 -1
  5. package/dist/{chat-pipeline-BWrtVqEP.d.ts → chat-pipeline-DuNX5WoL.d.ts} +3 -0
  6. package/dist/cli.js +0 -0
  7. package/dist/index.d.ts +11 -2
  8. package/dist/index.js +64 -27
  9. package/package.json +100 -99
  10. package/dist/channels/discord/adapter.d.ts +0 -32
  11. package/dist/channels/discord/adapter.js +0 -70
  12. package/dist/channels/discord/inbound.d.ts +0 -25
  13. package/dist/channels/discord/inbound.js +0 -24
  14. package/dist/channels/discord/models.d.ts +0 -8
  15. package/dist/channels/discord/models.js +0 -5
  16. package/dist/channels/discord/outbound.d.ts +0 -14
  17. package/dist/channels/discord/outbound.js +0 -38
  18. package/dist/channels/slack/adapter.d.ts +0 -33
  19. package/dist/channels/slack/adapter.js +0 -74
  20. package/dist/channels/slack/inbound.d.ts +0 -59
  21. package/dist/channels/slack/inbound.js +0 -96
  22. package/dist/channels/slack/models.d.ts +0 -9
  23. package/dist/channels/slack/models.js +0 -5
  24. package/dist/channels/slack/outbound.d.ts +0 -12
  25. package/dist/channels/slack/outbound.js +0 -18
  26. package/dist/channels/slack/transcribe.d.ts +0 -41
  27. package/dist/channels/slack/transcribe.js +0 -106
  28. package/dist/channels/webhook/adapter.d.ts +0 -23
  29. package/dist/channels/webhook/adapter.js +0 -86
  30. package/dist/channels/webhook/hmac.d.ts +0 -13
  31. package/dist/channels/webhook/hmac.js +0 -26
  32. package/dist/channels/webhook/models.d.ts +0 -9
  33. package/dist/channels/webhook/models.js +0 -5
  34. package/dist/channels/webhook/server.d.ts +0 -20
  35. package/dist/channels/webhook/server.js +0 -91
  36. package/dist/chat-pipeline-C-XlLGNl.d.ts +0 -648
  37. package/dist/chat-pipeline-CR1KF6eX.d.ts +0 -652
  38. package/dist/chat-pipeline-DisuC8SB.d.ts +0 -643
  39. package/dist/chunk-2LGXQPEA.js +0 -41
  40. package/dist/chunk-3X3YKI4T.js +0 -357
  41. package/dist/chunk-D47AIFOD.js +0 -351
  42. package/dist/chunk-DSNJKNEW.js +0 -328
  43. package/dist/chunk-GS2JFL6I.js +0 -144
  44. package/dist/chunk-J6S6QMUY.js +0 -144
  45. package/dist/chunk-QLA6YOFN.js +0 -22
  46. package/dist/chunk-UACT2WXX.js +0 -381
  47. package/dist/cli/templates/config.yml.d.ts +0 -7
  48. package/dist/cli/templates/config.yml.js +0 -61
  49. package/dist/cli/templates/env.d.ts +0 -1
  50. package/dist/cli/templates/env.js +0 -30
  51. package/dist/cli/templates/index.ts.d.ts +0 -2
  52. package/dist/cli/templates/index.ts.js +0 -30
  53. package/dist/cli/templates/package.json.d.ts +0 -5
  54. package/dist/cli/templates/package.json.js +0 -28
  55. package/dist/connector-DDahQw-2.d.ts +0 -63
  56. package/dist/connectors/google/calendar-connector.d.ts +0 -40
  57. package/dist/connectors/google/calendar-connector.js +0 -243
  58. package/dist/connectors/google/gmail-connector.d.ts +0 -42
  59. package/dist/connectors/google/gmail-connector.js +0 -345
  60. package/dist/connectors/google/oauth.d.ts +0 -48
  61. package/dist/connectors/google/oauth.js +0 -112
  62. package/dist/connectors/google/types.d.ts +0 -78
  63. package/dist/connectors/google/types.js +0 -2
  64. package/dist/core/chat/auto-discovery.d.ts +0 -16
  65. package/dist/core/chat/auto-discovery.js +0 -54
  66. package/dist/core/chat/channel-registry.d.ts +0 -45
  67. package/dist/core/chat/channel-registry.js +0 -96
  68. package/dist/core/chat/chat-pipeline.d.ts +0 -113
  69. package/dist/core/chat/chat-pipeline.js +0 -395
  70. package/dist/core/chat/chat-responder.d.ts +0 -90
  71. package/dist/core/chat/chat-responder.js +0 -185
  72. package/dist/core/chat/formatter.d.ts +0 -11
  73. package/dist/core/chat/formatter.js +0 -60
  74. package/dist/core/chat/index.d.ts +0 -24
  75. package/dist/core/chat/index.js +0 -18
  76. package/dist/core/chat/message-interpreter.d.ts +0 -91
  77. package/dist/core/chat/message-interpreter.js +0 -166
  78. package/dist/core/chat/message-store.d.ts +0 -66
  79. package/dist/core/chat/message-store.js +0 -131
  80. package/dist/core/chat/notification-queue.d.ts +0 -34
  81. package/dist/core/chat/notification-queue.js +0 -111
  82. package/dist/core/chat/pipeline.d.ts +0 -38
  83. package/dist/core/chat/pipeline.js +0 -89
  84. package/dist/core/chat/policies.d.ts +0 -16
  85. package/dist/core/chat/policies.js +0 -25
  86. package/dist/core/chat/routing.d.ts +0 -17
  87. package/dist/core/chat/routing.js +0 -36
  88. package/dist/core/chat/session-key.d.ts +0 -30
  89. package/dist/core/chat/session-key.js +0 -65
  90. package/dist/core/chat/session-manager.d.ts +0 -17
  91. package/dist/core/chat/session-manager.js +0 -23
  92. package/dist/core/chat/text-chunker.d.ts +0 -9
  93. package/dist/core/chat/text-chunker.js +0 -48
  94. package/dist/core/chat/triage-router.d.ts +0 -75
  95. package/dist/core/chat/triage-router.js +0 -142
  96. package/dist/core/chat/types.d.ts +0 -5
  97. package/dist/core/chat/types.js +0 -5
  98. package/dist/core/config/defaults.d.ts +0 -2
  99. package/dist/core/config/defaults.js +0 -38
  100. package/dist/core/config/index.d.ts +0 -6
  101. package/dist/core/config/index.js +0 -4
  102. package/dist/core/config/interpolate.d.ts +0 -5
  103. package/dist/core/config/interpolate.js +0 -27
  104. package/dist/core/config/loader.d.ts +0 -24
  105. package/dist/core/config/loader.js +0 -59
  106. package/dist/core/config/schema.d.ts +0 -5
  107. package/dist/core/config/schema.js +0 -119
  108. package/dist/core/data/core-entity-contexts.d.ts +0 -14
  109. package/dist/core/data/core-entity-contexts.js +0 -197
  110. package/dist/core/data/core-migrations.d.ts +0 -5
  111. package/dist/core/data/core-migrations.js +0 -45
  112. package/dist/core/data/core-schema.d.ts +0 -6
  113. package/dist/core/data/core-schema.js +0 -454
  114. package/dist/core/data/data-store.d.ts +0 -67
  115. package/dist/core/data/data-store.js +0 -218
  116. package/dist/core/data/domain-entity-contexts.d.ts +0 -29
  117. package/dist/core/data/domain-entity-contexts.js +0 -321
  118. package/dist/core/data/domain-schema.d.ts +0 -36
  119. package/dist/core/data/domain-schema.js +0 -323
  120. package/dist/core/data/index.d.ts +0 -7
  121. package/dist/core/data/index.js +0 -7
  122. package/dist/core/data/types.d.ts +0 -111
  123. package/dist/core/data/types.js +0 -1
  124. package/dist/core/hooks/hook-bus.d.ts +0 -18
  125. package/dist/core/hooks/hook-bus.js +0 -120
  126. package/dist/core/hooks/index.d.ts +0 -2
  127. package/dist/core/hooks/index.js +0 -1
  128. package/dist/core/hooks/types.d.ts +0 -19
  129. package/dist/core/hooks/types.js +0 -1
  130. package/dist/core/index.d.ts +0 -4
  131. package/dist/core/index.js +0 -4
  132. package/dist/core/llm/auto-discovery.d.ts +0 -11
  133. package/dist/core/llm/auto-discovery.js +0 -49
  134. package/dist/core/llm/cost-tracker.d.ts +0 -6
  135. package/dist/core/llm/cost-tracker.js +0 -38
  136. package/dist/core/llm/index.d.ts +0 -4
  137. package/dist/core/llm/index.js +0 -3
  138. package/dist/core/llm/model-router.d.ts +0 -25
  139. package/dist/core/llm/model-router.js +0 -49
  140. package/dist/core/llm/provider-registry.d.ts +0 -9
  141. package/dist/core/llm/provider-registry.js +0 -25
  142. package/dist/core/llm/types.d.ts +0 -2
  143. package/dist/core/llm/types.js +0 -2
  144. package/dist/core/orchestrator/adapters/api-adapter.d.ts +0 -34
  145. package/dist/core/orchestrator/adapters/api-adapter.js +0 -88
  146. package/dist/core/orchestrator/adapters/cli-adapter.d.ts +0 -22
  147. package/dist/core/orchestrator/adapters/cli-adapter.js +0 -69
  148. package/dist/core/orchestrator/adapters/deterministic-adapter.d.ts +0 -35
  149. package/dist/core/orchestrator/adapters/deterministic-adapter.js +0 -75
  150. package/dist/core/orchestrator/adapters/env-whitelist.d.ts +0 -4
  151. package/dist/core/orchestrator/adapters/env-whitelist.js +0 -27
  152. package/dist/core/orchestrator/adapters/output-extractor.d.ts +0 -11
  153. package/dist/core/orchestrator/adapters/output-extractor.js +0 -59
  154. package/dist/core/orchestrator/adapters/process-manager.d.ts +0 -15
  155. package/dist/core/orchestrator/adapters/process-manager.js +0 -26
  156. package/dist/core/orchestrator/adapters/tool-loop.d.ts +0 -22
  157. package/dist/core/orchestrator/adapters/tool-loop.js +0 -66
  158. package/dist/core/orchestrator/agent-registry.d.ts +0 -31
  159. package/dist/core/orchestrator/agent-registry.js +0 -135
  160. package/dist/core/orchestrator/budget-controller.d.ts +0 -19
  161. package/dist/core/orchestrator/budget-controller.js +0 -73
  162. package/dist/core/orchestrator/chain-guard.d.ts +0 -14
  163. package/dist/core/orchestrator/chain-guard.js +0 -23
  164. package/dist/core/orchestrator/circuit-breaker.d.ts +0 -65
  165. package/dist/core/orchestrator/circuit-breaker.js +0 -159
  166. package/dist/core/orchestrator/claude-stream-parser.d.ts +0 -31
  167. package/dist/core/orchestrator/claude-stream-parser.js +0 -99
  168. package/dist/core/orchestrator/config-revisions.d.ts +0 -6
  169. package/dist/core/orchestrator/config-revisions.js +0 -17
  170. package/dist/core/orchestrator/dependency-resolver.d.ts +0 -20
  171. package/dist/core/orchestrator/dependency-resolver.js +0 -78
  172. package/dist/core/orchestrator/governance-gate.d.ts +0 -110
  173. package/dist/core/orchestrator/governance-gate.js +0 -170
  174. package/dist/core/orchestrator/learning-pipeline.d.ts +0 -109
  175. package/dist/core/orchestrator/learning-pipeline.js +0 -249
  176. package/dist/core/orchestrator/loop-detector.d.ts +0 -51
  177. package/dist/core/orchestrator/loop-detector.js +0 -133
  178. package/dist/core/orchestrator/ndjson-logger.d.ts +0 -6
  179. package/dist/core/orchestrator/ndjson-logger.js +0 -18
  180. package/dist/core/orchestrator/permission-relay.d.ts +0 -72
  181. package/dist/core/orchestrator/permission-relay.js +0 -164
  182. package/dist/core/orchestrator/run-manager.d.ts +0 -31
  183. package/dist/core/orchestrator/run-manager.js +0 -178
  184. package/dist/core/orchestrator/scheduler.d.ts +0 -70
  185. package/dist/core/orchestrator/scheduler.js +0 -198
  186. package/dist/core/orchestrator/secret-store.d.ts +0 -57
  187. package/dist/core/orchestrator/secret-store.js +0 -171
  188. package/dist/core/orchestrator/session-manager.d.ts +0 -13
  189. package/dist/core/orchestrator/session-manager.js +0 -66
  190. package/dist/core/orchestrator/task-queue.d.ts +0 -34
  191. package/dist/core/orchestrator/task-queue.js +0 -83
  192. package/dist/core/orchestrator/template-interpolate.d.ts +0 -5
  193. package/dist/core/orchestrator/template-interpolate.js +0 -18
  194. package/dist/core/orchestrator/user-registry.d.ts +0 -47
  195. package/dist/core/orchestrator/user-registry.js +0 -76
  196. package/dist/core/orchestrator/wakeup-queue.d.ts +0 -9
  197. package/dist/core/orchestrator/wakeup-queue.js +0 -45
  198. package/dist/core/orchestrator/workflow-engine.d.ts +0 -47
  199. package/dist/core/orchestrator/workflow-engine.js +0 -204
  200. package/dist/core/security/audit.d.ts +0 -20
  201. package/dist/core/security/audit.js +0 -33
  202. package/dist/core/security/column-validator.d.ts +0 -20
  203. package/dist/core/security/column-validator.js +0 -37
  204. package/dist/core/security/index.d.ts +0 -5
  205. package/dist/core/security/index.js +0 -5
  206. package/dist/core/security/process-env.d.ts +0 -13
  207. package/dist/core/security/process-env.js +0 -49
  208. package/dist/core/security/sanitizer.d.ts +0 -11
  209. package/dist/core/security/sanitizer.js +0 -39
  210. package/dist/core/security/types.d.ts +0 -11
  211. package/dist/core/security/types.js +0 -1
  212. package/dist/core/update/auto-update.d.ts +0 -21
  213. package/dist/core/update/auto-update.js +0 -102
  214. package/dist/core/update/backup-manager.d.ts +0 -7
  215. package/dist/core/update/backup-manager.js +0 -24
  216. package/dist/core/update/index.d.ts +0 -8
  217. package/dist/core/update/index.js +0 -6
  218. package/dist/core/update/migration-hooks.d.ts +0 -11
  219. package/dist/core/update/migration-hooks.js +0 -10
  220. package/dist/core/update/types.d.ts +0 -11
  221. package/dist/core/update/types.js +0 -1
  222. package/dist/core/update/update-checker.d.ts +0 -11
  223. package/dist/core/update/update-checker.js +0 -63
  224. package/dist/core/update/update-manager.d.ts +0 -25
  225. package/dist/core/update/update-manager.js +0 -101
  226. package/dist/core/update/version-utils.d.ts +0 -6
  227. package/dist/core/update/version-utils.js +0 -34
  228. package/dist/gmail-connector-2FVYTQJH.js +0 -6
  229. package/dist/gmail-connector-MNUBRNFM.js +0 -6
  230. package/dist/gmail-connector-PS2VLGNE.js +0 -6
  231. package/dist/gmail-connector-ULSMN6X2.js +0 -6
  232. package/dist/gmail-connector-URRFX6A3.js +0 -6
  233. package/dist/inbound-AFBUPSPG.js +0 -10
  234. package/dist/inbound-AFOHYNUY.js +0 -6
  235. package/dist/inbound-CGIXRXGC.js +0 -8
  236. package/dist/inbound-MCOLRH6U.js +0 -10
  237. package/dist/inbound-SNEMBLGA.js +0 -6
  238. package/dist/inbound-ZJHAYVMF.js +0 -10
  239. package/dist/provider-qqJYv9nv.d.ts +0 -75
  240. package/dist/providers/anthropic/models.d.ts +0 -2
  241. package/dist/providers/anthropic/models.js +0 -29
  242. package/dist/providers/anthropic/provider.d.ts +0 -13
  243. package/dist/providers/anthropic/provider.js +0 -119
  244. package/dist/providers/anthropic/tool-converter.d.ts +0 -10
  245. package/dist/providers/anthropic/tool-converter.js +0 -7
  246. package/dist/providers/ollama/provider.d.ts +0 -17
  247. package/dist/providers/ollama/provider.js +0 -185
  248. package/dist/providers/openai/models.d.ts +0 -2
  249. package/dist/providers/openai/models.js +0 -29
  250. package/dist/providers/openai/provider.d.ts +0 -13
  251. package/dist/providers/openai/provider.js +0 -163
  252. package/dist/providers/openai/tool-converter.d.ts +0 -10
  253. package/dist/providers/openai/tool-converter.js +0 -10
  254. package/dist/shared/constants.d.ts +0 -50
  255. package/dist/shared/constants.js +0 -64
  256. package/dist/shared/index.d.ts +0 -14
  257. package/dist/shared/index.js +0 -14
  258. package/dist/shared/types/agent.d.ts +0 -36
  259. package/dist/shared/types/agent.js +0 -2
  260. package/dist/shared/types/channel.d.ts +0 -70
  261. package/dist/shared/types/channel.js +0 -2
  262. package/dist/shared/types/config.d.ts +0 -111
  263. package/dist/shared/types/config.js +0 -2
  264. package/dist/shared/types/connector.d.ts +0 -77
  265. package/dist/shared/types/connector.js +0 -2
  266. package/dist/shared/types/execution.d.ts +0 -29
  267. package/dist/shared/types/execution.js +0 -2
  268. package/dist/shared/types/provider.d.ts +0 -73
  269. package/dist/shared/types/provider.js +0 -2
  270. package/dist/shared/types/task.d.ts +0 -47
  271. package/dist/shared/types/task.js +0 -2
  272. package/dist/shared/types/workflow.d.ts +0 -39
  273. package/dist/shared/types/workflow.js +0 -2
  274. package/dist/shared/utils.d.ts +0 -6
  275. package/dist/shared/utils.js +0 -13
  276. package/dist/update-check.d.ts +0 -5
  277. package/dist/update-check.js +0 -56
@@ -1,218 +0,0 @@
1
- import { Lattice } from 'latticesql';
2
- export class DataStoreError extends Error {
3
- constructor(message) {
4
- super(message);
5
- this.name = 'DataStoreError';
6
- }
7
- }
8
- /**
9
- * Thin wrapper around Lattice that provides the botinabox DataStore API.
10
- *
11
- * Delegates all data operations to the latticesql package. Application-level
12
- * events (task.created, run.completed, etc.) remain on the HookBus — they are
13
- * emitted by orchestrator modules, not the data layer.
14
- */
15
- export class DataStore {
16
- lattice;
17
- hooks;
18
- outputDir;
19
- _initialized = false;
20
- deferredStatements = [];
21
- constructor(opts) {
22
- this.lattice = new Lattice(opts.dbPath, {
23
- wal: opts.wal ?? true,
24
- });
25
- this.outputDir = opts.outputDir;
26
- this.hooks = opts.hooks;
27
- }
28
- /**
29
- * Register a table definition. Must be called before init().
30
- *
31
- * tableConstraints may contain both inline constraints (FOREIGN KEY, UNIQUE)
32
- * and standalone SQL statements (CREATE INDEX). Standalone statements are
33
- * deferred and executed after init() creates the tables.
34
- */
35
- define(name, def) {
36
- if (this._initialized) {
37
- throw new DataStoreError('Cannot define tables after init()');
38
- }
39
- const inlineConstraints = [];
40
- for (const stmt of def.tableConstraints ?? []) {
41
- const upper = stmt.trimStart().toUpperCase();
42
- if (upper.startsWith('CREATE ') || upper.startsWith('DROP ') || upper.startsWith('ALTER ')) {
43
- // Prevent multi-statement injection via semicolons
44
- if (stmt.includes(';')) {
45
- throw new DataStoreError(`Deferred DDL statement must not contain semicolons: ${stmt}`);
46
- }
47
- this.deferredStatements.push(stmt);
48
- }
49
- else {
50
- inlineConstraints.push(stmt);
51
- }
52
- }
53
- this.lattice.define(name, {
54
- columns: def.columns,
55
- primaryKey: def.primaryKey,
56
- tableConstraints: inlineConstraints.length ? inlineConstraints : undefined,
57
- relations: def.relations,
58
- filter: def.filter,
59
- render: def.render,
60
- outputFile: def.outputFile,
61
- });
62
- }
63
- /**
64
- * Register an entity context definition for per-entity file rendering.
65
- */
66
- defineEntityContext(name, def) {
67
- this.lattice.defineEntityContext(name, {
68
- slug: (row) => {
69
- const val = row[def.slugColumn];
70
- const raw = val == null ? String(row.id ?? row.name ?? 'unknown') : String(val);
71
- // Validate: no path traversal characters
72
- if (raw.includes('/') || raw.includes('\\') || raw.includes('..')) {
73
- throw new Error(`Invalid slug "${raw}": contains path traversal characters`);
74
- }
75
- return raw;
76
- },
77
- directoryRoot: def.directory,
78
- files: def.files,
79
- protectedFiles: def.protectedFiles,
80
- protected: def.protected,
81
- encrypted: def.encrypted,
82
- // Note: sourceDefaults.softDelete NOT set here because junction tables
83
- // (agent_project, rule_agent, etc.) don't have deleted_at columns.
84
- // Entity context render functions should add softDelete per-source when targeting
85
- // tables that support it.
86
- index: def.indexFile
87
- ? {
88
- outputFile: def.indexFile,
89
- render: def.indexRender ?? ((rows) => {
90
- const active = rows.filter((r) => r.deleted_at == null);
91
- const dir = def.directory;
92
- const title = dir.charAt(0).toUpperCase() + dir.slice(1);
93
- if (!active.length)
94
- return `# ${title}\n\nNone.\n`;
95
- const lines = active.map((r) => {
96
- const slug = String(r[def.slugColumn] ?? r.name ?? r.id ?? 'unknown');
97
- const name = String(r.name ?? slug);
98
- const status = r.status ? ` (${r.status})` : '';
99
- return `- [${name}](${dir}/${slug}/)${status}`;
100
- });
101
- return `# ${title}\n\n${lines.join('\n')}\n`;
102
- }),
103
- }
104
- : undefined,
105
- });
106
- }
107
- async init(opts) {
108
- await this.lattice.init({ migrations: opts?.migrations });
109
- // Run deferred statements (CREATE INDEX, etc.) after tables exist
110
- for (const stmt of this.deferredStatements) {
111
- this.lattice.db.exec(stmt);
112
- }
113
- this._initialized = true;
114
- }
115
- assertInitialized() {
116
- if (!this._initialized) {
117
- throw new DataStoreError('DataStore not initialized — call init() first');
118
- }
119
- }
120
- // --- CRUD -----------------------------------------------------------
121
- async insert(table, row) {
122
- this.assertInitialized();
123
- return this.lattice.insertReturning(table, row);
124
- }
125
- async upsert(table, row) {
126
- this.assertInitialized();
127
- const id = await this.lattice.upsert(table, row);
128
- const result = await this.lattice.get(table, id);
129
- return result ?? { ...row, id };
130
- }
131
- async update(table, pk, changes) {
132
- this.assertInitialized();
133
- return this.lattice.updateReturning(table, pk, changes);
134
- }
135
- async delete(table, pk) {
136
- this.assertInitialized();
137
- await this.lattice.delete(table, pk);
138
- }
139
- /**
140
- * Get a single row by primary key.
141
- * Returns undefined if not found (Lattice returns null).
142
- */
143
- async get(table, pk) {
144
- this.assertInitialized();
145
- const result = await this.lattice.get(table, pk);
146
- return result ?? undefined;
147
- }
148
- async query(table, opts) {
149
- this.assertInitialized();
150
- return this.lattice.query(table, opts);
151
- }
152
- async count(table, opts) {
153
- this.assertInitialized();
154
- return this.lattice.count(table, opts);
155
- }
156
- // --- Junctions ------------------------------------------------------
157
- async link(junctionTable, row) {
158
- this.assertInitialized();
159
- await this.lattice.link(junctionTable, row);
160
- }
161
- async unlink(junctionTable, row) {
162
- this.assertInitialized();
163
- await this.lattice.unlink(junctionTable, row);
164
- }
165
- // --- Migrations -----------------------------------------------------
166
- async migrate(migrations) {
167
- this.assertInitialized();
168
- await this.lattice.migrate(migrations);
169
- }
170
- // --- Seed -----------------------------------------------------------
171
- async seed(items) {
172
- this.assertInitialized();
173
- for (const item of items) {
174
- const naturalKey = Array.isArray(item.naturalKey)
175
- ? item.naturalKey[0]
176
- : (item.naturalKey ?? 'id');
177
- await this.lattice.seed({
178
- table: item.table,
179
- data: item.rows,
180
- naturalKey,
181
- softDeleteMissing: item.softDeleteMissing,
182
- });
183
- if (item.junctions) {
184
- for (const junc of item.junctions) {
185
- for (const linkRow of junc.items) {
186
- await this.lattice.link(junc.table, linkRow);
187
- }
188
- }
189
- }
190
- }
191
- }
192
- // --- Rendering ------------------------------------------------------
193
- async render() {
194
- this.assertInitialized();
195
- if (this.outputDir) {
196
- await this.lattice.render(this.outputDir);
197
- }
198
- }
199
- async reconcile() {
200
- this.assertInitialized();
201
- if (this.outputDir) {
202
- await this.lattice.reconcile(this.outputDir);
203
- }
204
- }
205
- // --- Schema introspection ------------------------------------------
206
- tableInfo(table) {
207
- this.assertInitialized();
208
- return this.lattice.db.pragma(`table_info(${table})`);
209
- }
210
- // --- Lifecycle ------------------------------------------------------
211
- close() {
212
- this.lattice.close();
213
- this._initialized = false;
214
- }
215
- on(event, handler) {
216
- this.hooks?.register(event, handler);
217
- }
218
- }
@@ -1,29 +0,0 @@
1
- import type { DataStore } from "./data-store.js";
2
- /**
3
- * Options for domain entity context generation.
4
- * Match the options used in defineDomainTables().
5
- */
6
- export interface DomainEntityContextOptions {
7
- clients?: boolean;
8
- repositories?: boolean;
9
- files?: boolean;
10
- channels?: boolean;
11
- rules?: boolean;
12
- }
13
- /**
14
- * Define entity context rendering for standard domain tables.
15
- * Call after defineDomainTables() and defineCoreTables().
16
- *
17
- * Renders per-entity directories with context files for:
18
- * org, project, + optional client, file, channel entities.
19
- * Also adds PROJECTS.md, RULES.md, SKILLS.md, REPOS.md to agent context.
20
- *
21
- * @example
22
- * ```ts
23
- * defineCoreTables(db);
24
- * defineDomainTables(db);
25
- * defineCoreEntityContexts(db); // agents, users, skills
26
- * defineDomainEntityContexts(db); // org, project, client, file, channel
27
- * ```
28
- */
29
- export declare function defineDomainEntityContexts(db: DataStore, options?: DomainEntityContextOptions): void;
@@ -1,321 +0,0 @@
1
- import { truncateAtWord } from "../../shared/utils.js";
2
- /**
3
- * Define entity context rendering for standard domain tables.
4
- * Call after defineDomainTables() and defineCoreTables().
5
- *
6
- * Renders per-entity directories with context files for:
7
- * org, project, + optional client, file, channel entities.
8
- * Also adds PROJECTS.md, RULES.md, SKILLS.md, REPOS.md to agent context.
9
- *
10
- * @example
11
- * ```ts
12
- * defineCoreTables(db);
13
- * defineDomainTables(db);
14
- * defineCoreEntityContexts(db); // agents, users, skills
15
- * defineDomainEntityContexts(db); // org, project, client, file, channel
16
- * ```
17
- */
18
- export function defineDomainEntityContexts(db, options = {}) {
19
- const opts = {
20
- clients: true,
21
- repositories: true,
22
- files: true,
23
- channels: true,
24
- rules: true,
25
- ...options,
26
- };
27
- // --- Extend agent context with project/rule/skill connections ---
28
- // NOTE: This must be called BEFORE defineCoreEntityContexts() or the agent
29
- // context will already be registered. Apps should call this first, then core.
30
- // Actually, botinabox registers agents in defineCoreEntityContexts() already.
31
- // So we skip re-defining agents here — apps add PROJECTS.md etc. themselves.
32
- // --- Org context ---
33
- db.defineEntityContext("org", {
34
- table: "org",
35
- directory: "orgs",
36
- slugColumn: "id",
37
- indexFile: "orgs/ORGS.md",
38
- files: {
39
- "ORG.md": {
40
- source: { type: "self" },
41
- render: (rows) => {
42
- const o = rows[0];
43
- if (!o)
44
- return "";
45
- return [
46
- `# ${o.name}`,
47
- "",
48
- o.type ? `**Type:** ${o.type}` : null,
49
- o.description ? `\n${o.description}` : null,
50
- o.mission ? `\n**Mission:** ${o.mission}` : null,
51
- o.website ? `**Website:** ${o.website}` : null,
52
- "",
53
- ]
54
- .filter(Boolean)
55
- .join("\n");
56
- },
57
- },
58
- },
59
- });
60
- // --- Project context ---
61
- // PROJECT.md auto-combines with all connected context (latticesql 1.2.0+).
62
- db.defineEntityContext("project", {
63
- table: "project",
64
- directory: "projects",
65
- slugColumn: "id",
66
- indexFile: "projects/PROJECTS.md",
67
- files: {
68
- "PROJECT.md": {
69
- source: { type: "self" },
70
- render: (rows) => {
71
- const p = rows[0];
72
- if (!p)
73
- return "";
74
- return [
75
- `# ${p.name}`,
76
- "",
77
- p.status ? `**Status:** ${p.status}` : null,
78
- p.description ? `\n${p.description}` : null,
79
- p.tech_stack ? `\n**Tech Stack:** ${p.tech_stack}` : null,
80
- p.production_url ? `**URL:** ${p.production_url}` : null,
81
- p.github_repo ? `**GitHub:** ${p.github_repo}` : null,
82
- p.deploy_target ? `**Deploy:** ${p.deploy_target}` : null,
83
- p.branch_strategy
84
- ? `**Branch Strategy:** ${p.branch_strategy}`
85
- : null,
86
- p.notes ? `\n**Notes:**\n${p.notes}` : null,
87
- "",
88
- ]
89
- .filter(Boolean)
90
- .join("\n");
91
- },
92
- },
93
- ...(opts.repositories
94
- ? {
95
- "REPOS.md": {
96
- source: {
97
- type: "hasMany",
98
- table: "repository",
99
- foreignKey: "project_id",
100
- },
101
- render: (rows) => {
102
- if (!rows.length)
103
- return "";
104
- const lines = rows.map((r) => `- **${r.name}** — ${r.url ?? ""}`);
105
- return `# Repositories\n\n${lines.join("\n")}\n`;
106
- },
107
- omitIfEmpty: true,
108
- },
109
- }
110
- : {}),
111
- ...(opts.rules
112
- ? {
113
- "RULES.md": {
114
- source: {
115
- type: "manyToMany",
116
- junctionTable: "rule_project",
117
- localKey: "project_id",
118
- remoteKey: "rule_id",
119
- remoteTable: "rule",
120
- softDelete: true,
121
- orderBy: "priority",
122
- },
123
- render: (rows) => {
124
- if (!rows.length)
125
- return "";
126
- const lines = rows.map((r) => `### ${r.title}\n${r.rule_text}`);
127
- return `# Project Rules\n\n${lines.join("\n\n")}\n`;
128
- },
129
- omitIfEmpty: true,
130
- },
131
- }
132
- : {}),
133
- ...(opts.files
134
- ? {
135
- "FILES.md": {
136
- source: {
137
- type: "hasMany",
138
- table: "file",
139
- foreignKey: "project_id",
140
- },
141
- render: (rows) => {
142
- if (!rows.length)
143
- return "";
144
- const lines = rows.map((r) => `- [${r.name}](files/${r.name}/)${r.mime_type ? ` (${r.mime_type})` : ""}`);
145
- return `# Files\n\n${lines.join("\n")}\n`;
146
- },
147
- omitIfEmpty: true,
148
- },
149
- }
150
- : {}),
151
- "MESSAGES.md": {
152
- source: {
153
- type: "hasMany",
154
- table: "messages",
155
- foreignKey: "project_id",
156
- orderBy: "created_at",
157
- limit: 100,
158
- },
159
- render: (rows) => {
160
- if (!rows.length)
161
- return "# Messages\n\nNo messages.\n";
162
- const lines = rows.map((r) => {
163
- const dir = r.direction === "inbound" ? "\u2192" : "\u2190";
164
- const ts = (r.created_at ?? "").slice(0, 16);
165
- const agent = r.from_agent ? ` [${r.from_agent}]` : "";
166
- const body = r.body ?? "";
167
- const preview = truncateAtWord(body, 150);
168
- const link = `[${ts}](messages/${r.id}/)`;
169
- return `- ${dir} **${link}**${agent} ${preview}`;
170
- });
171
- return `# Messages\n\n${lines.join("\n")}\n`;
172
- },
173
- omitIfEmpty: false,
174
- },
175
- },
176
- });
177
- // --- Client context ---
178
- // CLIENT.md auto-combines with all connected context (latticesql 1.2.0+).
179
- if (opts.clients) {
180
- db.defineEntityContext("client", {
181
- table: "client",
182
- directory: "clients",
183
- slugColumn: "id",
184
- indexFile: "clients/CLIENTS.md",
185
- files: {
186
- "CLIENT.md": {
187
- source: { type: "self" },
188
- render: (rows) => {
189
- const c = rows[0];
190
- if (!c)
191
- return "";
192
- return [
193
- `# ${c.name}`,
194
- "",
195
- c.contact_name ? `**Contact:** ${c.contact_name}` : null,
196
- c.contact_email ? `**Email:** ${c.contact_email}` : null,
197
- c.phone ? `**Phone:** ${c.phone}` : null,
198
- c.status ? `**Status:** ${c.status}` : null,
199
- c.notes ? `\n${c.notes}` : null,
200
- "",
201
- ]
202
- .filter(Boolean)
203
- .join("\n");
204
- },
205
- },
206
- ...(opts.repositories
207
- ? {
208
- "REPOS.md": {
209
- source: {
210
- type: "hasMany",
211
- table: "repository",
212
- foreignKey: "client_id",
213
- },
214
- render: (rows) => {
215
- if (!rows.length)
216
- return "";
217
- const lines = rows.map((r) => `- **${r.name}** — ${r.url ?? ""}`);
218
- return `# Repositories\n\n${lines.join("\n")}\n`;
219
- },
220
- omitIfEmpty: true,
221
- },
222
- }
223
- : {}),
224
- AGENTS: {
225
- source: {
226
- type: "manyToMany",
227
- junctionTable: "agent_client",
228
- localKey: "client_id",
229
- remoteKey: "agent_id",
230
- remoteTable: "agents",
231
- },
232
- render: (rows) => {
233
- if (!rows.length)
234
- return "";
235
- const lines = rows.map((r) => `- **${r.name}** (${r.role ?? "agent"})`);
236
- return `# Assigned Agents\n\n${lines.join("\n")}\n`;
237
- },
238
- omitIfEmpty: true,
239
- },
240
- "INVOICES.md": {
241
- source: {
242
- type: "hasMany",
243
- table: "invoice",
244
- foreignKey: "client_id",
245
- },
246
- render: (rows) => {
247
- if (!rows.length)
248
- return "";
249
- const lines = rows.map((r) => {
250
- const amt = r.amount_cents
251
- ? `$${(r.amount_cents / 100).toFixed(2)}`
252
- : "TBD";
253
- return `- **${r.number ?? "Draft"}** — ${amt} (${r.status})${r.description ? ": " + r.description : ""}`;
254
- });
255
- return `# Invoices\n\n${lines.join("\n")}\n`;
256
- },
257
- omitIfEmpty: true,
258
- },
259
- },
260
- });
261
- }
262
- // --- File context ---
263
- if (opts.files) {
264
- db.defineEntityContext("file", {
265
- table: "file",
266
- directory: "files",
267
- slugColumn: "id",
268
- indexFile: "files/FILES.md",
269
- files: {
270
- "FILE.md": {
271
- source: { type: "self" },
272
- render: (rows) => {
273
- const f = rows[0];
274
- if (!f)
275
- return "";
276
- return [
277
- `# ${f.name}`,
278
- "",
279
- f.mime_type ? `**Type:** ${f.mime_type}` : null,
280
- f.access_level ? `**Access:** ${f.access_level}` : null,
281
- f.file_path ? `**Path:** ${f.file_path}` : null,
282
- f.description ? `\n${f.description}` : null,
283
- "",
284
- ]
285
- .filter(Boolean)
286
- .join("\n");
287
- },
288
- },
289
- },
290
- });
291
- }
292
- // --- Channel context ---
293
- if (opts.channels) {
294
- db.defineEntityContext("channel", {
295
- table: "channel",
296
- directory: "channels",
297
- slugColumn: "id",
298
- indexFile: "channels/CHANNELS.md",
299
- files: {
300
- "CHANNEL.md": {
301
- source: { type: "self" },
302
- render: (rows) => {
303
- const c = rows[0];
304
- if (!c)
305
- return "";
306
- return [
307
- `# ${c.name}`,
308
- "",
309
- c.platform ? `**Platform:** ${c.platform}` : null,
310
- c.type ? `**Type:** ${c.type}` : null,
311
- c.instructions ? `\n${c.instructions}` : null,
312
- "",
313
- ]
314
- .filter(Boolean)
315
- .join("\n");
316
- },
317
- },
318
- },
319
- });
320
- }
321
- }
@@ -1,36 +0,0 @@
1
- import type { DataStore } from "./data-store.js";
2
- /**
3
- * Options for domain table generation.
4
- * Enable/disable optional tables based on your app's needs.
5
- */
6
- export interface DomainSchemaOptions {
7
- /** Include client + invoice tables (default: true) */
8
- clients?: boolean;
9
- /** Include repository table (default: true) */
10
- repositories?: boolean;
11
- /** Include file table (default: true) */
12
- files?: boolean;
13
- /** Include channel table (default: true) */
14
- channels?: boolean;
15
- /** Include rule table + junction tables (default: true) */
16
- rules?: boolean;
17
- /** Include event audit log (default: true) */
18
- events?: boolean;
19
- /** Include cross-domain junction tables (default: true) */
20
- junctions?: boolean;
21
- }
22
- /**
23
- * Define standard domain tables that most multi-agent apps need.
24
- * Call after defineCoreTables() and before db.init().
25
- *
26
- * Provides: org, project, + optional client, invoice, repository,
27
- * file, channel, rule, event tables with appropriate junction tables.
28
- *
29
- * @example
30
- * ```ts
31
- * defineCoreTables(db);
32
- * defineDomainTables(db); // all tables
33
- * defineDomainTables(db, { clients: false }); // skip client/invoice
34
- * ```
35
- */
36
- export declare function defineDomainTables(db: DataStore, options?: DomainSchemaOptions): void;