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.
- package/LICENSE +21 -21
- package/README.md +190 -190
- package/bin/botinabox.mjs +2 -2
- package/dist/channels/slack/index.d.ts +1 -1
- package/dist/{chat-pipeline-BWrtVqEP.d.ts → chat-pipeline-DuNX5WoL.d.ts} +3 -0
- package/dist/cli.js +0 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +64 -27
- package/package.json +100 -99
- package/dist/channels/discord/adapter.d.ts +0 -32
- package/dist/channels/discord/adapter.js +0 -70
- package/dist/channels/discord/inbound.d.ts +0 -25
- package/dist/channels/discord/inbound.js +0 -24
- package/dist/channels/discord/models.d.ts +0 -8
- package/dist/channels/discord/models.js +0 -5
- package/dist/channels/discord/outbound.d.ts +0 -14
- package/dist/channels/discord/outbound.js +0 -38
- package/dist/channels/slack/adapter.d.ts +0 -33
- package/dist/channels/slack/adapter.js +0 -74
- package/dist/channels/slack/inbound.d.ts +0 -59
- package/dist/channels/slack/inbound.js +0 -96
- package/dist/channels/slack/models.d.ts +0 -9
- package/dist/channels/slack/models.js +0 -5
- package/dist/channels/slack/outbound.d.ts +0 -12
- package/dist/channels/slack/outbound.js +0 -18
- package/dist/channels/slack/transcribe.d.ts +0 -41
- package/dist/channels/slack/transcribe.js +0 -106
- package/dist/channels/webhook/adapter.d.ts +0 -23
- package/dist/channels/webhook/adapter.js +0 -86
- package/dist/channels/webhook/hmac.d.ts +0 -13
- package/dist/channels/webhook/hmac.js +0 -26
- package/dist/channels/webhook/models.d.ts +0 -9
- package/dist/channels/webhook/models.js +0 -5
- package/dist/channels/webhook/server.d.ts +0 -20
- package/dist/channels/webhook/server.js +0 -91
- package/dist/chat-pipeline-C-XlLGNl.d.ts +0 -648
- package/dist/chat-pipeline-CR1KF6eX.d.ts +0 -652
- package/dist/chat-pipeline-DisuC8SB.d.ts +0 -643
- package/dist/chunk-2LGXQPEA.js +0 -41
- package/dist/chunk-3X3YKI4T.js +0 -357
- package/dist/chunk-D47AIFOD.js +0 -351
- package/dist/chunk-DSNJKNEW.js +0 -328
- package/dist/chunk-GS2JFL6I.js +0 -144
- package/dist/chunk-J6S6QMUY.js +0 -144
- package/dist/chunk-QLA6YOFN.js +0 -22
- package/dist/chunk-UACT2WXX.js +0 -381
- package/dist/cli/templates/config.yml.d.ts +0 -7
- package/dist/cli/templates/config.yml.js +0 -61
- package/dist/cli/templates/env.d.ts +0 -1
- package/dist/cli/templates/env.js +0 -30
- package/dist/cli/templates/index.ts.d.ts +0 -2
- package/dist/cli/templates/index.ts.js +0 -30
- package/dist/cli/templates/package.json.d.ts +0 -5
- package/dist/cli/templates/package.json.js +0 -28
- package/dist/connector-DDahQw-2.d.ts +0 -63
- package/dist/connectors/google/calendar-connector.d.ts +0 -40
- package/dist/connectors/google/calendar-connector.js +0 -243
- package/dist/connectors/google/gmail-connector.d.ts +0 -42
- package/dist/connectors/google/gmail-connector.js +0 -345
- package/dist/connectors/google/oauth.d.ts +0 -48
- package/dist/connectors/google/oauth.js +0 -112
- package/dist/connectors/google/types.d.ts +0 -78
- package/dist/connectors/google/types.js +0 -2
- package/dist/core/chat/auto-discovery.d.ts +0 -16
- package/dist/core/chat/auto-discovery.js +0 -54
- package/dist/core/chat/channel-registry.d.ts +0 -45
- package/dist/core/chat/channel-registry.js +0 -96
- package/dist/core/chat/chat-pipeline.d.ts +0 -113
- package/dist/core/chat/chat-pipeline.js +0 -395
- package/dist/core/chat/chat-responder.d.ts +0 -90
- package/dist/core/chat/chat-responder.js +0 -185
- package/dist/core/chat/formatter.d.ts +0 -11
- package/dist/core/chat/formatter.js +0 -60
- package/dist/core/chat/index.d.ts +0 -24
- package/dist/core/chat/index.js +0 -18
- package/dist/core/chat/message-interpreter.d.ts +0 -91
- package/dist/core/chat/message-interpreter.js +0 -166
- package/dist/core/chat/message-store.d.ts +0 -66
- package/dist/core/chat/message-store.js +0 -131
- package/dist/core/chat/notification-queue.d.ts +0 -34
- package/dist/core/chat/notification-queue.js +0 -111
- package/dist/core/chat/pipeline.d.ts +0 -38
- package/dist/core/chat/pipeline.js +0 -89
- package/dist/core/chat/policies.d.ts +0 -16
- package/dist/core/chat/policies.js +0 -25
- package/dist/core/chat/routing.d.ts +0 -17
- package/dist/core/chat/routing.js +0 -36
- package/dist/core/chat/session-key.d.ts +0 -30
- package/dist/core/chat/session-key.js +0 -65
- package/dist/core/chat/session-manager.d.ts +0 -17
- package/dist/core/chat/session-manager.js +0 -23
- package/dist/core/chat/text-chunker.d.ts +0 -9
- package/dist/core/chat/text-chunker.js +0 -48
- package/dist/core/chat/triage-router.d.ts +0 -75
- package/dist/core/chat/triage-router.js +0 -142
- package/dist/core/chat/types.d.ts +0 -5
- package/dist/core/chat/types.js +0 -5
- package/dist/core/config/defaults.d.ts +0 -2
- package/dist/core/config/defaults.js +0 -38
- package/dist/core/config/index.d.ts +0 -6
- package/dist/core/config/index.js +0 -4
- package/dist/core/config/interpolate.d.ts +0 -5
- package/dist/core/config/interpolate.js +0 -27
- package/dist/core/config/loader.d.ts +0 -24
- package/dist/core/config/loader.js +0 -59
- package/dist/core/config/schema.d.ts +0 -5
- package/dist/core/config/schema.js +0 -119
- package/dist/core/data/core-entity-contexts.d.ts +0 -14
- package/dist/core/data/core-entity-contexts.js +0 -197
- package/dist/core/data/core-migrations.d.ts +0 -5
- package/dist/core/data/core-migrations.js +0 -45
- package/dist/core/data/core-schema.d.ts +0 -6
- package/dist/core/data/core-schema.js +0 -454
- package/dist/core/data/data-store.d.ts +0 -67
- package/dist/core/data/data-store.js +0 -218
- package/dist/core/data/domain-entity-contexts.d.ts +0 -29
- package/dist/core/data/domain-entity-contexts.js +0 -321
- package/dist/core/data/domain-schema.d.ts +0 -36
- package/dist/core/data/domain-schema.js +0 -323
- package/dist/core/data/index.d.ts +0 -7
- package/dist/core/data/index.js +0 -7
- package/dist/core/data/types.d.ts +0 -111
- package/dist/core/data/types.js +0 -1
- package/dist/core/hooks/hook-bus.d.ts +0 -18
- package/dist/core/hooks/hook-bus.js +0 -120
- package/dist/core/hooks/index.d.ts +0 -2
- package/dist/core/hooks/index.js +0 -1
- package/dist/core/hooks/types.d.ts +0 -19
- package/dist/core/hooks/types.js +0 -1
- package/dist/core/index.d.ts +0 -4
- package/dist/core/index.js +0 -4
- package/dist/core/llm/auto-discovery.d.ts +0 -11
- package/dist/core/llm/auto-discovery.js +0 -49
- package/dist/core/llm/cost-tracker.d.ts +0 -6
- package/dist/core/llm/cost-tracker.js +0 -38
- package/dist/core/llm/index.d.ts +0 -4
- package/dist/core/llm/index.js +0 -3
- package/dist/core/llm/model-router.d.ts +0 -25
- package/dist/core/llm/model-router.js +0 -49
- package/dist/core/llm/provider-registry.d.ts +0 -9
- package/dist/core/llm/provider-registry.js +0 -25
- package/dist/core/llm/types.d.ts +0 -2
- package/dist/core/llm/types.js +0 -2
- package/dist/core/orchestrator/adapters/api-adapter.d.ts +0 -34
- package/dist/core/orchestrator/adapters/api-adapter.js +0 -88
- package/dist/core/orchestrator/adapters/cli-adapter.d.ts +0 -22
- package/dist/core/orchestrator/adapters/cli-adapter.js +0 -69
- package/dist/core/orchestrator/adapters/deterministic-adapter.d.ts +0 -35
- package/dist/core/orchestrator/adapters/deterministic-adapter.js +0 -75
- package/dist/core/orchestrator/adapters/env-whitelist.d.ts +0 -4
- package/dist/core/orchestrator/adapters/env-whitelist.js +0 -27
- package/dist/core/orchestrator/adapters/output-extractor.d.ts +0 -11
- package/dist/core/orchestrator/adapters/output-extractor.js +0 -59
- package/dist/core/orchestrator/adapters/process-manager.d.ts +0 -15
- package/dist/core/orchestrator/adapters/process-manager.js +0 -26
- package/dist/core/orchestrator/adapters/tool-loop.d.ts +0 -22
- package/dist/core/orchestrator/adapters/tool-loop.js +0 -66
- package/dist/core/orchestrator/agent-registry.d.ts +0 -31
- package/dist/core/orchestrator/agent-registry.js +0 -135
- package/dist/core/orchestrator/budget-controller.d.ts +0 -19
- package/dist/core/orchestrator/budget-controller.js +0 -73
- package/dist/core/orchestrator/chain-guard.d.ts +0 -14
- package/dist/core/orchestrator/chain-guard.js +0 -23
- package/dist/core/orchestrator/circuit-breaker.d.ts +0 -65
- package/dist/core/orchestrator/circuit-breaker.js +0 -159
- package/dist/core/orchestrator/claude-stream-parser.d.ts +0 -31
- package/dist/core/orchestrator/claude-stream-parser.js +0 -99
- package/dist/core/orchestrator/config-revisions.d.ts +0 -6
- package/dist/core/orchestrator/config-revisions.js +0 -17
- package/dist/core/orchestrator/dependency-resolver.d.ts +0 -20
- package/dist/core/orchestrator/dependency-resolver.js +0 -78
- package/dist/core/orchestrator/governance-gate.d.ts +0 -110
- package/dist/core/orchestrator/governance-gate.js +0 -170
- package/dist/core/orchestrator/learning-pipeline.d.ts +0 -109
- package/dist/core/orchestrator/learning-pipeline.js +0 -249
- package/dist/core/orchestrator/loop-detector.d.ts +0 -51
- package/dist/core/orchestrator/loop-detector.js +0 -133
- package/dist/core/orchestrator/ndjson-logger.d.ts +0 -6
- package/dist/core/orchestrator/ndjson-logger.js +0 -18
- package/dist/core/orchestrator/permission-relay.d.ts +0 -72
- package/dist/core/orchestrator/permission-relay.js +0 -164
- package/dist/core/orchestrator/run-manager.d.ts +0 -31
- package/dist/core/orchestrator/run-manager.js +0 -178
- package/dist/core/orchestrator/scheduler.d.ts +0 -70
- package/dist/core/orchestrator/scheduler.js +0 -198
- package/dist/core/orchestrator/secret-store.d.ts +0 -57
- package/dist/core/orchestrator/secret-store.js +0 -171
- package/dist/core/orchestrator/session-manager.d.ts +0 -13
- package/dist/core/orchestrator/session-manager.js +0 -66
- package/dist/core/orchestrator/task-queue.d.ts +0 -34
- package/dist/core/orchestrator/task-queue.js +0 -83
- package/dist/core/orchestrator/template-interpolate.d.ts +0 -5
- package/dist/core/orchestrator/template-interpolate.js +0 -18
- package/dist/core/orchestrator/user-registry.d.ts +0 -47
- package/dist/core/orchestrator/user-registry.js +0 -76
- package/dist/core/orchestrator/wakeup-queue.d.ts +0 -9
- package/dist/core/orchestrator/wakeup-queue.js +0 -45
- package/dist/core/orchestrator/workflow-engine.d.ts +0 -47
- package/dist/core/orchestrator/workflow-engine.js +0 -204
- package/dist/core/security/audit.d.ts +0 -20
- package/dist/core/security/audit.js +0 -33
- package/dist/core/security/column-validator.d.ts +0 -20
- package/dist/core/security/column-validator.js +0 -37
- package/dist/core/security/index.d.ts +0 -5
- package/dist/core/security/index.js +0 -5
- package/dist/core/security/process-env.d.ts +0 -13
- package/dist/core/security/process-env.js +0 -49
- package/dist/core/security/sanitizer.d.ts +0 -11
- package/dist/core/security/sanitizer.js +0 -39
- package/dist/core/security/types.d.ts +0 -11
- package/dist/core/security/types.js +0 -1
- package/dist/core/update/auto-update.d.ts +0 -21
- package/dist/core/update/auto-update.js +0 -102
- package/dist/core/update/backup-manager.d.ts +0 -7
- package/dist/core/update/backup-manager.js +0 -24
- package/dist/core/update/index.d.ts +0 -8
- package/dist/core/update/index.js +0 -6
- package/dist/core/update/migration-hooks.d.ts +0 -11
- package/dist/core/update/migration-hooks.js +0 -10
- package/dist/core/update/types.d.ts +0 -11
- package/dist/core/update/types.js +0 -1
- package/dist/core/update/update-checker.d.ts +0 -11
- package/dist/core/update/update-checker.js +0 -63
- package/dist/core/update/update-manager.d.ts +0 -25
- package/dist/core/update/update-manager.js +0 -101
- package/dist/core/update/version-utils.d.ts +0 -6
- package/dist/core/update/version-utils.js +0 -34
- package/dist/gmail-connector-2FVYTQJH.js +0 -6
- package/dist/gmail-connector-MNUBRNFM.js +0 -6
- package/dist/gmail-connector-PS2VLGNE.js +0 -6
- package/dist/gmail-connector-ULSMN6X2.js +0 -6
- package/dist/gmail-connector-URRFX6A3.js +0 -6
- package/dist/inbound-AFBUPSPG.js +0 -10
- package/dist/inbound-AFOHYNUY.js +0 -6
- package/dist/inbound-CGIXRXGC.js +0 -8
- package/dist/inbound-MCOLRH6U.js +0 -10
- package/dist/inbound-SNEMBLGA.js +0 -6
- package/dist/inbound-ZJHAYVMF.js +0 -10
- package/dist/provider-qqJYv9nv.d.ts +0 -75
- package/dist/providers/anthropic/models.d.ts +0 -2
- package/dist/providers/anthropic/models.js +0 -29
- package/dist/providers/anthropic/provider.d.ts +0 -13
- package/dist/providers/anthropic/provider.js +0 -119
- package/dist/providers/anthropic/tool-converter.d.ts +0 -10
- package/dist/providers/anthropic/tool-converter.js +0 -7
- package/dist/providers/ollama/provider.d.ts +0 -17
- package/dist/providers/ollama/provider.js +0 -185
- package/dist/providers/openai/models.d.ts +0 -2
- package/dist/providers/openai/models.js +0 -29
- package/dist/providers/openai/provider.d.ts +0 -13
- package/dist/providers/openai/provider.js +0 -163
- package/dist/providers/openai/tool-converter.d.ts +0 -10
- package/dist/providers/openai/tool-converter.js +0 -10
- package/dist/shared/constants.d.ts +0 -50
- package/dist/shared/constants.js +0 -64
- package/dist/shared/index.d.ts +0 -14
- package/dist/shared/index.js +0 -14
- package/dist/shared/types/agent.d.ts +0 -36
- package/dist/shared/types/agent.js +0 -2
- package/dist/shared/types/channel.d.ts +0 -70
- package/dist/shared/types/channel.js +0 -2
- package/dist/shared/types/config.d.ts +0 -111
- package/dist/shared/types/config.js +0 -2
- package/dist/shared/types/connector.d.ts +0 -77
- package/dist/shared/types/connector.js +0 -2
- package/dist/shared/types/execution.d.ts +0 -29
- package/dist/shared/types/execution.js +0 -2
- package/dist/shared/types/provider.d.ts +0 -73
- package/dist/shared/types/provider.js +0 -2
- package/dist/shared/types/task.d.ts +0 -47
- package/dist/shared/types/task.js +0 -2
- package/dist/shared/types/workflow.d.ts +0 -39
- package/dist/shared/types/workflow.js +0 -2
- package/dist/shared/utils.d.ts +0 -6
- package/dist/shared/utils.js +0 -13
- package/dist/update-check.d.ts +0 -5
- 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;
|