botinabox 1.8.2 → 1.8.3
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/dist/channels/discord/adapter.d.ts +32 -0
- package/dist/channels/discord/adapter.js +70 -0
- package/dist/channels/discord/inbound.d.ts +25 -0
- package/dist/channels/discord/inbound.js +24 -0
- package/dist/channels/discord/models.d.ts +8 -0
- package/dist/channels/discord/models.js +5 -0
- package/dist/channels/discord/outbound.d.ts +14 -0
- package/dist/channels/discord/outbound.js +38 -0
- package/dist/channels/slack/adapter.d.ts +33 -0
- package/dist/channels/slack/adapter.js +74 -0
- package/dist/channels/slack/inbound.d.ts +59 -0
- package/dist/channels/slack/inbound.js +96 -0
- package/dist/channels/slack/models.d.ts +9 -0
- package/dist/channels/slack/models.js +5 -0
- package/dist/channels/slack/outbound.d.ts +12 -0
- package/dist/channels/slack/outbound.js +18 -0
- package/dist/channels/slack/transcribe.d.ts +41 -0
- package/dist/channels/slack/transcribe.js +106 -0
- package/dist/channels/webhook/adapter.d.ts +23 -0
- package/dist/channels/webhook/adapter.js +86 -0
- package/dist/channels/webhook/hmac.d.ts +13 -0
- package/dist/channels/webhook/hmac.js +26 -0
- package/dist/channels/webhook/models.d.ts +9 -0
- package/dist/channels/webhook/models.js +5 -0
- package/dist/channels/webhook/server.d.ts +20 -0
- package/dist/channels/webhook/server.js +91 -0
- package/dist/cli/templates/config.yml.d.ts +7 -0
- package/dist/cli/templates/config.yml.js +61 -0
- package/dist/cli/templates/env.d.ts +1 -0
- package/dist/cli/templates/env.js +30 -0
- package/dist/cli/templates/index.ts.d.ts +2 -0
- package/dist/cli/templates/index.ts.js +30 -0
- package/dist/cli/templates/package.json.d.ts +5 -0
- package/dist/cli/templates/package.json.js +28 -0
- package/dist/connectors/google/calendar-connector.d.ts +40 -0
- package/dist/connectors/google/calendar-connector.js +243 -0
- package/dist/connectors/google/gmail-connector.d.ts +42 -0
- package/dist/connectors/google/gmail-connector.js +345 -0
- package/dist/connectors/google/oauth.d.ts +48 -0
- package/dist/connectors/google/oauth.js +112 -0
- package/dist/connectors/google/types.d.ts +78 -0
- package/dist/connectors/google/types.js +2 -0
- package/dist/core/chat/auto-discovery.d.ts +16 -0
- package/dist/core/chat/auto-discovery.js +54 -0
- package/dist/core/chat/channel-registry.d.ts +45 -0
- package/dist/core/chat/channel-registry.js +96 -0
- package/dist/core/chat/chat-pipeline.d.ts +104 -0
- package/dist/core/chat/chat-pipeline.js +282 -0
- package/dist/core/chat/chat-responder.d.ts +90 -0
- package/dist/core/chat/chat-responder.js +185 -0
- package/dist/core/chat/formatter.d.ts +11 -0
- package/dist/core/chat/formatter.js +60 -0
- package/dist/core/chat/index.d.ts +24 -0
- package/dist/core/chat/index.js +18 -0
- package/dist/core/chat/message-interpreter.d.ts +91 -0
- package/dist/core/chat/message-interpreter.js +164 -0
- package/dist/core/chat/message-store.d.ts +66 -0
- package/dist/core/chat/message-store.js +131 -0
- package/dist/core/chat/notification-queue.d.ts +34 -0
- package/dist/core/chat/notification-queue.js +111 -0
- package/dist/core/chat/pipeline.d.ts +38 -0
- package/dist/core/chat/pipeline.js +89 -0
- package/dist/core/chat/policies.d.ts +16 -0
- package/dist/core/chat/policies.js +25 -0
- package/dist/core/chat/routing.d.ts +17 -0
- package/dist/core/chat/routing.js +36 -0
- package/dist/core/chat/session-key.d.ts +30 -0
- package/dist/core/chat/session-key.js +65 -0
- package/dist/core/chat/session-manager.d.ts +17 -0
- package/dist/core/chat/session-manager.js +23 -0
- package/dist/core/chat/text-chunker.d.ts +9 -0
- package/dist/core/chat/text-chunker.js +48 -0
- package/dist/core/chat/triage-router.d.ts +75 -0
- package/dist/core/chat/triage-router.js +142 -0
- package/dist/core/chat/types.d.ts +5 -0
- package/dist/core/chat/types.js +5 -0
- package/dist/core/config/defaults.d.ts +2 -0
- package/dist/core/config/defaults.js +38 -0
- package/dist/core/config/index.d.ts +6 -0
- package/dist/core/config/index.js +4 -0
- package/dist/core/config/interpolate.d.ts +5 -0
- package/dist/core/config/interpolate.js +27 -0
- package/dist/core/config/loader.d.ts +24 -0
- package/dist/core/config/loader.js +59 -0
- package/dist/core/config/schema.d.ts +5 -0
- package/dist/core/config/schema.js +119 -0
- package/dist/core/data/core-entity-contexts.d.ts +14 -0
- package/dist/core/data/core-entity-contexts.js +197 -0
- package/dist/core/data/core-migrations.d.ts +5 -0
- package/dist/core/data/core-migrations.js +45 -0
- package/dist/core/data/core-schema.d.ts +6 -0
- package/dist/core/data/core-schema.js +454 -0
- package/dist/core/data/data-store.d.ts +67 -0
- package/dist/core/data/data-store.js +218 -0
- package/dist/core/data/domain-entity-contexts.d.ts +29 -0
- package/dist/core/data/domain-entity-contexts.js +321 -0
- package/dist/core/data/domain-schema.d.ts +36 -0
- package/dist/core/data/domain-schema.js +323 -0
- package/dist/core/data/index.d.ts +7 -0
- package/dist/core/data/index.js +7 -0
- package/dist/core/data/types.d.ts +111 -0
- package/dist/core/data/types.js +1 -0
- package/dist/core/hooks/hook-bus.d.ts +18 -0
- package/dist/core/hooks/hook-bus.js +120 -0
- package/dist/core/hooks/index.d.ts +2 -0
- package/dist/core/hooks/index.js +1 -0
- package/dist/core/hooks/types.d.ts +19 -0
- package/dist/core/hooks/types.js +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +4 -0
- package/dist/core/llm/auto-discovery.d.ts +11 -0
- package/dist/core/llm/auto-discovery.js +49 -0
- package/dist/core/llm/cost-tracker.d.ts +6 -0
- package/dist/core/llm/cost-tracker.js +38 -0
- package/dist/core/llm/index.d.ts +4 -0
- package/dist/core/llm/index.js +3 -0
- package/dist/core/llm/model-router.d.ts +25 -0
- package/dist/core/llm/model-router.js +49 -0
- package/dist/core/llm/provider-registry.d.ts +9 -0
- package/dist/core/llm/provider-registry.js +25 -0
- package/dist/core/llm/types.d.ts +2 -0
- package/dist/core/llm/types.js +2 -0
- package/dist/core/orchestrator/adapters/api-adapter.d.ts +34 -0
- package/dist/core/orchestrator/adapters/api-adapter.js +88 -0
- package/dist/core/orchestrator/adapters/cli-adapter.d.ts +22 -0
- package/dist/core/orchestrator/adapters/cli-adapter.js +69 -0
- package/dist/core/orchestrator/adapters/deterministic-adapter.d.ts +35 -0
- package/dist/core/orchestrator/adapters/deterministic-adapter.js +75 -0
- package/dist/core/orchestrator/adapters/env-whitelist.d.ts +4 -0
- package/dist/core/orchestrator/adapters/env-whitelist.js +27 -0
- package/dist/core/orchestrator/adapters/output-extractor.d.ts +11 -0
- package/dist/core/orchestrator/adapters/output-extractor.js +59 -0
- package/dist/core/orchestrator/adapters/process-manager.d.ts +15 -0
- package/dist/core/orchestrator/adapters/process-manager.js +26 -0
- package/dist/core/orchestrator/adapters/tool-loop.d.ts +22 -0
- package/dist/core/orchestrator/adapters/tool-loop.js +66 -0
- package/dist/core/orchestrator/agent-registry.d.ts +31 -0
- package/dist/core/orchestrator/agent-registry.js +135 -0
- package/dist/core/orchestrator/budget-controller.d.ts +19 -0
- package/dist/core/orchestrator/budget-controller.js +73 -0
- package/dist/core/orchestrator/chain-guard.d.ts +14 -0
- package/dist/core/orchestrator/chain-guard.js +23 -0
- package/dist/core/orchestrator/circuit-breaker.d.ts +65 -0
- package/dist/core/orchestrator/circuit-breaker.js +159 -0
- package/dist/core/orchestrator/claude-stream-parser.d.ts +31 -0
- package/dist/core/orchestrator/claude-stream-parser.js +99 -0
- package/dist/core/orchestrator/config-revisions.d.ts +6 -0
- package/dist/core/orchestrator/config-revisions.js +17 -0
- package/dist/core/orchestrator/dependency-resolver.d.ts +20 -0
- package/dist/core/orchestrator/dependency-resolver.js +78 -0
- package/dist/core/orchestrator/governance-gate.d.ts +110 -0
- package/dist/core/orchestrator/governance-gate.js +170 -0
- package/dist/core/orchestrator/learning-pipeline.d.ts +109 -0
- package/dist/core/orchestrator/learning-pipeline.js +249 -0
- package/dist/core/orchestrator/loop-detector.d.ts +51 -0
- package/dist/core/orchestrator/loop-detector.js +133 -0
- package/dist/core/orchestrator/ndjson-logger.d.ts +6 -0
- package/dist/core/orchestrator/ndjson-logger.js +18 -0
- package/dist/core/orchestrator/permission-relay.d.ts +72 -0
- package/dist/core/orchestrator/permission-relay.js +164 -0
- package/dist/core/orchestrator/run-manager.d.ts +31 -0
- package/dist/core/orchestrator/run-manager.js +178 -0
- package/dist/core/orchestrator/scheduler.d.ts +70 -0
- package/dist/core/orchestrator/scheduler.js +198 -0
- package/dist/core/orchestrator/secret-store.d.ts +57 -0
- package/dist/core/orchestrator/secret-store.js +171 -0
- package/dist/core/orchestrator/session-manager.d.ts +13 -0
- package/dist/core/orchestrator/session-manager.js +66 -0
- package/dist/core/orchestrator/task-queue.d.ts +34 -0
- package/dist/core/orchestrator/task-queue.js +83 -0
- package/dist/core/orchestrator/template-interpolate.d.ts +5 -0
- package/dist/core/orchestrator/template-interpolate.js +18 -0
- package/dist/core/orchestrator/user-registry.d.ts +47 -0
- package/dist/core/orchestrator/user-registry.js +76 -0
- package/dist/core/orchestrator/wakeup-queue.d.ts +9 -0
- package/dist/core/orchestrator/wakeup-queue.js +45 -0
- package/dist/core/orchestrator/workflow-engine.d.ts +47 -0
- package/dist/core/orchestrator/workflow-engine.js +204 -0
- package/dist/core/security/audit.d.ts +20 -0
- package/dist/core/security/audit.js +33 -0
- package/dist/core/security/column-validator.d.ts +20 -0
- package/dist/core/security/column-validator.js +37 -0
- package/dist/core/security/index.d.ts +5 -0
- package/dist/core/security/index.js +5 -0
- package/dist/core/security/process-env.d.ts +13 -0
- package/dist/core/security/process-env.js +49 -0
- package/dist/core/security/sanitizer.d.ts +11 -0
- package/dist/core/security/sanitizer.js +39 -0
- package/dist/core/security/types.d.ts +11 -0
- package/dist/core/security/types.js +1 -0
- package/dist/core/update/auto-update.d.ts +21 -0
- package/dist/core/update/auto-update.js +102 -0
- package/dist/core/update/backup-manager.d.ts +7 -0
- package/dist/core/update/backup-manager.js +24 -0
- package/dist/core/update/index.d.ts +8 -0
- package/dist/core/update/index.js +6 -0
- package/dist/core/update/migration-hooks.d.ts +11 -0
- package/dist/core/update/migration-hooks.js +10 -0
- package/dist/core/update/types.d.ts +11 -0
- package/dist/core/update/types.js +1 -0
- package/dist/core/update/update-checker.d.ts +11 -0
- package/dist/core/update/update-checker.js +63 -0
- package/dist/core/update/update-manager.d.ts +25 -0
- package/dist/core/update/update-manager.js +101 -0
- package/dist/core/update/version-utils.d.ts +6 -0
- package/dist/core/update/version-utils.js +34 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +20 -13
- package/dist/providers/anthropic/models.d.ts +2 -0
- package/dist/providers/anthropic/models.js +29 -0
- package/dist/providers/anthropic/provider.d.ts +13 -0
- package/dist/providers/anthropic/provider.js +119 -0
- package/dist/providers/anthropic/tool-converter.d.ts +10 -0
- package/dist/providers/anthropic/tool-converter.js +7 -0
- package/dist/providers/ollama/provider.d.ts +17 -0
- package/dist/providers/ollama/provider.js +185 -0
- package/dist/providers/openai/models.d.ts +2 -0
- package/dist/providers/openai/models.js +29 -0
- package/dist/providers/openai/provider.d.ts +13 -0
- package/dist/providers/openai/provider.js +163 -0
- package/dist/providers/openai/tool-converter.d.ts +10 -0
- package/dist/providers/openai/tool-converter.js +10 -0
- package/dist/shared/constants.d.ts +50 -0
- package/dist/shared/constants.js +64 -0
- package/dist/shared/index.d.ts +14 -0
- package/dist/shared/index.js +14 -0
- package/dist/shared/types/agent.d.ts +36 -0
- package/dist/shared/types/agent.js +2 -0
- package/dist/shared/types/channel.d.ts +70 -0
- package/dist/shared/types/channel.js +2 -0
- package/dist/shared/types/config.d.ts +111 -0
- package/dist/shared/types/config.js +2 -0
- package/dist/shared/types/connector.d.ts +77 -0
- package/dist/shared/types/connector.js +2 -0
- package/dist/shared/types/execution.d.ts +29 -0
- package/dist/shared/types/execution.js +2 -0
- package/dist/shared/types/provider.d.ts +73 -0
- package/dist/shared/types/provider.js +2 -0
- package/dist/shared/types/task.d.ts +47 -0
- package/dist/shared/types/task.js +2 -0
- package/dist/shared/types/workflow.d.ts +39 -0
- package/dist/shared/types/workflow.js +2 -0
- package/dist/shared/utils.d.ts +6 -0
- package/dist/shared/utils.js +13 -0
- package/dist/update-check.d.ts +5 -0
- package/dist/update-check.js +56 -0
- package/package.json +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interpolate ${ENV_VAR} references in YAML string values.
|
|
3
|
+
* Recursively walks objects and arrays.
|
|
4
|
+
*/
|
|
5
|
+
export function interpolateEnv(value, env = process.env) {
|
|
6
|
+
if (typeof value === "string") {
|
|
7
|
+
return value.replace(/\$\{([^}]+)\}/g, (_, name) => {
|
|
8
|
+
const envVal = env[name];
|
|
9
|
+
if (envVal === undefined) {
|
|
10
|
+
// Leave the placeholder if env var is not set (don't silently swallow)
|
|
11
|
+
return `\${${name}}`;
|
|
12
|
+
}
|
|
13
|
+
return envVal;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
return value.map(item => interpolateEnv(item, env));
|
|
18
|
+
}
|
|
19
|
+
if (value !== null && typeof value === "object") {
|
|
20
|
+
const result = {};
|
|
21
|
+
for (const [k, v] of Object.entries(value)) {
|
|
22
|
+
result[k] = interpolateEnv(v, env);
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { BotConfig } from "../../shared/index.js";
|
|
2
|
+
export interface ConfigLoadError {
|
|
3
|
+
field: string;
|
|
4
|
+
message: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ConfigLoadResult {
|
|
7
|
+
config: BotConfig;
|
|
8
|
+
errors: ConfigLoadError[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Load and merge config from file, with env var interpolation and runtime overrides.
|
|
12
|
+
* Merge order: defaults < config file < runtime overrides
|
|
13
|
+
*/
|
|
14
|
+
export declare function loadConfig(opts?: {
|
|
15
|
+
configPath?: string;
|
|
16
|
+
overrides?: Partial<BotConfig>;
|
|
17
|
+
env?: Record<string, string | undefined>;
|
|
18
|
+
}): ConfigLoadResult;
|
|
19
|
+
/** Get the loaded config singleton. Call loadConfig() first. */
|
|
20
|
+
export declare function getConfig(): BotConfig;
|
|
21
|
+
/** Initialize the config singleton. Returns errors if any. */
|
|
22
|
+
export declare function initConfig(opts?: Parameters<typeof loadConfig>[0]): ConfigLoadError[];
|
|
23
|
+
/** Reset the singleton (for testing) */
|
|
24
|
+
export declare function _resetConfig(): void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
2
|
+
import { parse as parseYaml } from "yaml";
|
|
3
|
+
import { DEFAULT_CONFIG } from "./defaults.js";
|
|
4
|
+
import { interpolateEnv } from "./interpolate.js";
|
|
5
|
+
function deepMerge(base, override) {
|
|
6
|
+
if (override === undefined || override === null)
|
|
7
|
+
return base;
|
|
8
|
+
if (base === undefined || base === null)
|
|
9
|
+
return override;
|
|
10
|
+
if (typeof base !== "object" || typeof override !== "object")
|
|
11
|
+
return override;
|
|
12
|
+
if (Array.isArray(override))
|
|
13
|
+
return override;
|
|
14
|
+
const result = { ...base };
|
|
15
|
+
for (const [k, v] of Object.entries(override)) {
|
|
16
|
+
if (v !== undefined) {
|
|
17
|
+
result[k] = deepMerge(result[k], v);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Load and merge config from file, with env var interpolation and runtime overrides.
|
|
24
|
+
* Merge order: defaults < config file < runtime overrides
|
|
25
|
+
*/
|
|
26
|
+
export function loadConfig(opts) {
|
|
27
|
+
const configPath = opts?.configPath ?? "botinabox.config.yml";
|
|
28
|
+
const errors = [];
|
|
29
|
+
let fileConfig = {};
|
|
30
|
+
if (existsSync(configPath)) {
|
|
31
|
+
try {
|
|
32
|
+
const raw = readFileSync(configPath, "utf-8");
|
|
33
|
+
const parsed = parseYaml(raw);
|
|
34
|
+
fileConfig = interpolateEnv(parsed, opts?.env ?? process.env);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
errors.push({ field: "configPath", message: `Failed to parse ${configPath}: ${String(err)}` });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const merged = deepMerge(deepMerge(DEFAULT_CONFIG, fileConfig), opts?.overrides ?? {});
|
|
41
|
+
return { config: Object.freeze(merged), errors };
|
|
42
|
+
}
|
|
43
|
+
let _config = null;
|
|
44
|
+
/** Get the loaded config singleton. Call loadConfig() first. */
|
|
45
|
+
export function getConfig() {
|
|
46
|
+
if (!_config)
|
|
47
|
+
throw new Error("Config not loaded — call loadConfig() first");
|
|
48
|
+
return _config;
|
|
49
|
+
}
|
|
50
|
+
/** Initialize the config singleton. Returns errors if any. */
|
|
51
|
+
export function initConfig(opts) {
|
|
52
|
+
const { config, errors } = loadConfig(opts);
|
|
53
|
+
_config = config;
|
|
54
|
+
return errors;
|
|
55
|
+
}
|
|
56
|
+
/** Reset the singleton (for testing) */
|
|
57
|
+
export function _resetConfig() {
|
|
58
|
+
_config = null;
|
|
59
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import Ajv from "ajv";
|
|
2
|
+
const ajv = new Ajv({ allErrors: true, coerceTypes: false });
|
|
3
|
+
const BOT_CONFIG_SCHEMA = {
|
|
4
|
+
type: "object",
|
|
5
|
+
additionalProperties: true,
|
|
6
|
+
properties: {
|
|
7
|
+
data: {
|
|
8
|
+
type: "object",
|
|
9
|
+
required: ["path", "walMode"],
|
|
10
|
+
properties: {
|
|
11
|
+
path: { type: "string", minLength: 1 },
|
|
12
|
+
walMode: { type: "boolean" },
|
|
13
|
+
backupDir: { type: "string" },
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
models: {
|
|
17
|
+
type: "object",
|
|
18
|
+
required: ["aliases", "default", "routing", "fallbackChain"],
|
|
19
|
+
properties: {
|
|
20
|
+
aliases: { type: "object", additionalProperties: { type: "string" } },
|
|
21
|
+
default: { type: "string", minLength: 1 },
|
|
22
|
+
routing: { type: "object", additionalProperties: { type: "string" } },
|
|
23
|
+
fallbackChain: { type: "array", items: { type: "string" } },
|
|
24
|
+
costLimit: {
|
|
25
|
+
type: "object",
|
|
26
|
+
properties: {
|
|
27
|
+
perRunCents: { type: "number", minimum: 0 },
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
security: {
|
|
33
|
+
type: "object",
|
|
34
|
+
properties: {
|
|
35
|
+
fieldLengthLimits: { type: "object", additionalProperties: { type: "number" } },
|
|
36
|
+
allowedFilePrefixes: { type: "array", items: { type: "string" } },
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
render: {
|
|
40
|
+
type: "object",
|
|
41
|
+
required: ["outputDir", "watchIntervalMs"],
|
|
42
|
+
properties: {
|
|
43
|
+
outputDir: { type: "string", minLength: 1 },
|
|
44
|
+
watchIntervalMs: { type: "number", minimum: 1000 },
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
updates: {
|
|
48
|
+
type: "object",
|
|
49
|
+
required: ["policy", "checkIntervalMs"],
|
|
50
|
+
properties: {
|
|
51
|
+
policy: { type: "string", enum: ["auto-all", "auto-compatible", "auto-patch", "notify", "manual"] },
|
|
52
|
+
checkIntervalMs: { type: "number", minimum: 60_000 },
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
budget: {
|
|
56
|
+
type: "object",
|
|
57
|
+
required: ["warnPercent"],
|
|
58
|
+
properties: {
|
|
59
|
+
warnPercent: { type: "number", minimum: 1, maximum: 100 },
|
|
60
|
+
globalMonthlyCents: { type: "number", minimum: 0 },
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
agents: {
|
|
64
|
+
type: "array",
|
|
65
|
+
items: {
|
|
66
|
+
type: "object",
|
|
67
|
+
required: ["slug", "name", "adapter"],
|
|
68
|
+
properties: {
|
|
69
|
+
slug: { type: "string", minLength: 1, pattern: "^[a-z0-9-]+$" },
|
|
70
|
+
name: { type: "string", minLength: 1 },
|
|
71
|
+
adapter: { type: "string", minLength: 1 },
|
|
72
|
+
model: { type: "string" },
|
|
73
|
+
workdir: { type: "string" },
|
|
74
|
+
maxConcurrentRuns: { type: "number", minimum: 1 },
|
|
75
|
+
budgetMonthlyCents: { type: "number", minimum: 0 },
|
|
76
|
+
canCreateAgents: { type: "boolean" },
|
|
77
|
+
skipPermissions: { type: "boolean" },
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
channels: {
|
|
82
|
+
type: "object",
|
|
83
|
+
additionalProperties: {
|
|
84
|
+
type: "object",
|
|
85
|
+
required: ["enabled"],
|
|
86
|
+
properties: {
|
|
87
|
+
enabled: { type: "boolean" },
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
providers: {
|
|
92
|
+
type: "object",
|
|
93
|
+
additionalProperties: {
|
|
94
|
+
type: "object",
|
|
95
|
+
required: ["enabled"],
|
|
96
|
+
properties: {
|
|
97
|
+
enabled: { type: "boolean" },
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
let _validate = null;
|
|
104
|
+
function getValidator() {
|
|
105
|
+
if (!_validate) {
|
|
106
|
+
_validate = ajv.compile(BOT_CONFIG_SCHEMA);
|
|
107
|
+
}
|
|
108
|
+
return _validate;
|
|
109
|
+
}
|
|
110
|
+
export function validateConfig(config) {
|
|
111
|
+
const validate = getValidator();
|
|
112
|
+
const valid = validate(config);
|
|
113
|
+
if (valid)
|
|
114
|
+
return [];
|
|
115
|
+
return (validate.errors ?? []).map(err => ({
|
|
116
|
+
path: err.instancePath || "/",
|
|
117
|
+
message: err.message ?? "invalid",
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DataStore } from "./data-store.js";
|
|
2
|
+
/**
|
|
3
|
+
* Define default entity context rendering for botinabox core tables.
|
|
4
|
+
* Call after defineCoreTables() and before or after init().
|
|
5
|
+
*
|
|
6
|
+
* Renders:
|
|
7
|
+
* - agents/ — per-agent context (AGENT.md, PROJECTS.md if agent_project exists)
|
|
8
|
+
* - users/ — per-user context (USER.md) — protected
|
|
9
|
+
* - skills/ — per-skill context (SKILL.md)
|
|
10
|
+
*
|
|
11
|
+
* Apps can override by calling db.defineEntityContext() with the same table name
|
|
12
|
+
* BEFORE calling defineCoreEntityContexts().
|
|
13
|
+
*/
|
|
14
|
+
export declare function defineCoreEntityContexts(db: DataStore): void;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { truncateAtWord } from "../../shared/utils.js";
|
|
2
|
+
/**
|
|
3
|
+
* Define default entity context rendering for botinabox core tables.
|
|
4
|
+
* Call after defineCoreTables() and before or after init().
|
|
5
|
+
*
|
|
6
|
+
* Renders:
|
|
7
|
+
* - agents/ — per-agent context (AGENT.md, PROJECTS.md if agent_project exists)
|
|
8
|
+
* - users/ — per-user context (USER.md) — protected
|
|
9
|
+
* - skills/ — per-skill context (SKILL.md)
|
|
10
|
+
*
|
|
11
|
+
* Apps can override by calling db.defineEntityContext() with the same table name
|
|
12
|
+
* BEFORE calling defineCoreEntityContexts().
|
|
13
|
+
*/
|
|
14
|
+
export function defineCoreEntityContexts(db) {
|
|
15
|
+
// --- Agents ---
|
|
16
|
+
db.defineEntityContext("agents", {
|
|
17
|
+
table: "agents",
|
|
18
|
+
directory: "agents",
|
|
19
|
+
slugColumn: "slug",
|
|
20
|
+
indexFile: "agents/AGENTS.md",
|
|
21
|
+
files: {
|
|
22
|
+
"AGENT.md": {
|
|
23
|
+
source: { type: "self" },
|
|
24
|
+
render: (rows) => {
|
|
25
|
+
const a = rows[0];
|
|
26
|
+
if (!a)
|
|
27
|
+
return "";
|
|
28
|
+
return [
|
|
29
|
+
`# ${a.name}`,
|
|
30
|
+
"",
|
|
31
|
+
a.role ? `**Role:** ${a.role}` : null,
|
|
32
|
+
a.adapter ? `**Adapter:** ${a.adapter}` : null,
|
|
33
|
+
a.status ? `**Status:** ${a.status}` : null,
|
|
34
|
+
a.cwd ? `**Working Directory:** ${a.cwd}` : null,
|
|
35
|
+
a.reports_to ? `**Reports To:** ${a.reports_to}` : null,
|
|
36
|
+
"",
|
|
37
|
+
]
|
|
38
|
+
.filter(Boolean)
|
|
39
|
+
.join("\n");
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
"SKILLS.md": {
|
|
43
|
+
source: {
|
|
44
|
+
type: "manyToMany",
|
|
45
|
+
junctionTable: "agent_skills",
|
|
46
|
+
localKey: "agent_id",
|
|
47
|
+
remoteKey: "skill_id",
|
|
48
|
+
remoteTable: "skills",
|
|
49
|
+
},
|
|
50
|
+
omitIfEmpty: true,
|
|
51
|
+
render: (rows) => {
|
|
52
|
+
if (!rows.length)
|
|
53
|
+
return "";
|
|
54
|
+
const lines = [`# Skills (${rows.length})`, ""];
|
|
55
|
+
for (const s of rows) {
|
|
56
|
+
lines.push(`## ${s.name}`);
|
|
57
|
+
if (s.category)
|
|
58
|
+
lines.push(`**Category:** ${s.category}`);
|
|
59
|
+
if (s.description)
|
|
60
|
+
lines.push("", s.description);
|
|
61
|
+
if (s.definition)
|
|
62
|
+
lines.push("", "```", s.definition, "```");
|
|
63
|
+
lines.push("");
|
|
64
|
+
}
|
|
65
|
+
return lines.join("\n");
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
"PLAYBOOKS.md": {
|
|
69
|
+
source: {
|
|
70
|
+
type: "manyToMany",
|
|
71
|
+
junctionTable: "agent_playbooks",
|
|
72
|
+
localKey: "agent_id",
|
|
73
|
+
remoteKey: "playbook_id",
|
|
74
|
+
remoteTable: "playbooks",
|
|
75
|
+
},
|
|
76
|
+
omitIfEmpty: true,
|
|
77
|
+
render: (rows) => {
|
|
78
|
+
if (!rows.length)
|
|
79
|
+
return "";
|
|
80
|
+
const lines = [`# Playbooks (${rows.length})`, ""];
|
|
81
|
+
for (const pb of rows) {
|
|
82
|
+
lines.push(`## ${pb.pattern ?? pb.name ?? "Unnamed"}`);
|
|
83
|
+
if (pb.rule)
|
|
84
|
+
lines.push("", pb.rule);
|
|
85
|
+
lines.push("");
|
|
86
|
+
}
|
|
87
|
+
return lines.join("\n");
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
// --- Users (protected) ---
|
|
93
|
+
db.defineEntityContext("users", {
|
|
94
|
+
table: "users",
|
|
95
|
+
directory: "users",
|
|
96
|
+
slugColumn: "id",
|
|
97
|
+
protected: true,
|
|
98
|
+
indexFile: "users/USERS.md",
|
|
99
|
+
files: {
|
|
100
|
+
"USER.md": {
|
|
101
|
+
source: { type: "self" },
|
|
102
|
+
render: (rows) => {
|
|
103
|
+
const u = rows[0];
|
|
104
|
+
if (!u)
|
|
105
|
+
return "";
|
|
106
|
+
return [
|
|
107
|
+
`# ${u.name}`,
|
|
108
|
+
"",
|
|
109
|
+
u.role ? `**Role:** ${u.role}` : null,
|
|
110
|
+
u.title ? `**Title:** ${u.title}` : null,
|
|
111
|
+
u.email ? `**Email:** ${u.email}` : null,
|
|
112
|
+
u.timezone ? `**Timezone:** ${u.timezone}` : null,
|
|
113
|
+
"",
|
|
114
|
+
]
|
|
115
|
+
.filter(Boolean)
|
|
116
|
+
.join("\n");
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
// --- Skills ---
|
|
122
|
+
db.defineEntityContext("skills", {
|
|
123
|
+
table: "skills",
|
|
124
|
+
directory: "skills",
|
|
125
|
+
slugColumn: "slug",
|
|
126
|
+
indexFile: "skills/SKILLS.md",
|
|
127
|
+
files: {
|
|
128
|
+
"SKILL.md": {
|
|
129
|
+
source: { type: "self" },
|
|
130
|
+
render: (rows) => {
|
|
131
|
+
const s = rows[0];
|
|
132
|
+
if (!s)
|
|
133
|
+
return "";
|
|
134
|
+
return [
|
|
135
|
+
`# ${s.name}`,
|
|
136
|
+
"",
|
|
137
|
+
s.category ? `**Category:** ${s.category}` : null,
|
|
138
|
+
s.description ? `\n${s.description}` : null,
|
|
139
|
+
s.definition ? `\n## Definition\n\n${s.definition}` : null,
|
|
140
|
+
"",
|
|
141
|
+
]
|
|
142
|
+
.filter(Boolean)
|
|
143
|
+
.join("\n");
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
// --- Messages ---
|
|
149
|
+
db.defineEntityContext("messages", {
|
|
150
|
+
table: "messages",
|
|
151
|
+
directory: "messages",
|
|
152
|
+
slugColumn: "id",
|
|
153
|
+
indexFile: "messages/MESSAGES.md",
|
|
154
|
+
indexRender: (rows) => {
|
|
155
|
+
const active = rows.filter((r) => r.deleted_at == null);
|
|
156
|
+
if (!active.length)
|
|
157
|
+
return "# Messages\n\nNo messages.\n";
|
|
158
|
+
const recent = active.slice(-100);
|
|
159
|
+
const lines = recent.map((r) => {
|
|
160
|
+
const dir = r.direction === "outbound" ? "→" : "←";
|
|
161
|
+
const who = r.from_agent ?? r.from_user ?? "unknown";
|
|
162
|
+
const time = (r.created_at ?? "").slice(0, 16);
|
|
163
|
+
const preview = truncateAtWord(r.body ?? "", 80);
|
|
164
|
+
return `- ${dir} **${who}** (${time}): ${preview}`;
|
|
165
|
+
});
|
|
166
|
+
return `# Messages\n\nLast ${lines.length} messages:\n\n${lines.join("\n")}\n`;
|
|
167
|
+
},
|
|
168
|
+
files: {
|
|
169
|
+
"MESSAGE.md": {
|
|
170
|
+
source: { type: "self" },
|
|
171
|
+
render: (rows) => {
|
|
172
|
+
const m = rows[0];
|
|
173
|
+
if (!m)
|
|
174
|
+
return "";
|
|
175
|
+
return [
|
|
176
|
+
"# Message",
|
|
177
|
+
"",
|
|
178
|
+
`**Direction:** ${m.direction}`,
|
|
179
|
+
m.from_user ? `**From User:** ${m.from_user}` : null,
|
|
180
|
+
m.from_agent ? `**From Agent:** ${m.from_agent}` : null,
|
|
181
|
+
`**Channel:** ${m.channel}`,
|
|
182
|
+
m.thread_id ? `**Thread:** ${m.thread_id}` : null,
|
|
183
|
+
m.task_id ? `**Task:** ${m.task_id}` : null,
|
|
184
|
+
`**Time:** ${m.created_at}`,
|
|
185
|
+
"",
|
|
186
|
+
"---",
|
|
187
|
+
"",
|
|
188
|
+
m.body,
|
|
189
|
+
"",
|
|
190
|
+
]
|
|
191
|
+
.filter(Boolean)
|
|
192
|
+
.join("\n");
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Initial migration set for core tables */
|
|
2
|
+
export const CORE_MIGRATIONS = [
|
|
3
|
+
{
|
|
4
|
+
version: "001_initial_schema",
|
|
5
|
+
sql: `-- Initial schema is applied via DataStore.define() + init().
|
|
6
|
+
-- This migration is a no-op placeholder for version tracking.
|
|
7
|
+
SELECT 1;`,
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
version: "002_activity_log_indexes",
|
|
11
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_activity_log_type ON activity_log(event_type, recorded_at);`,
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
version: "003_runs_cost_index",
|
|
15
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_runs_cost ON runs(agent_id, completed_at) WHERE cost_cents > 0;`,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
version: "004_schedules_table",
|
|
19
|
+
sql: `CREATE TABLE IF NOT EXISTS schedules (
|
|
20
|
+
id TEXT PRIMARY KEY,
|
|
21
|
+
name TEXT NOT NULL,
|
|
22
|
+
description TEXT,
|
|
23
|
+
type TEXT NOT NULL DEFAULT 'recurring',
|
|
24
|
+
cron TEXT,
|
|
25
|
+
run_at TEXT,
|
|
26
|
+
timezone TEXT DEFAULT 'UTC',
|
|
27
|
+
enabled INTEGER NOT NULL DEFAULT 1,
|
|
28
|
+
action TEXT NOT NULL,
|
|
29
|
+
action_config TEXT DEFAULT '{}',
|
|
30
|
+
last_fired_at TEXT,
|
|
31
|
+
next_fire_at TEXT,
|
|
32
|
+
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
33
|
+
updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
34
|
+
deleted_at TEXT
|
|
35
|
+
)`,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
version: "005_schedules_name_index",
|
|
39
|
+
sql: `CREATE UNIQUE INDEX IF NOT EXISTS idx_schedules_name ON schedules(name) WHERE deleted_at IS NULL`,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
version: "006_schedules_next_index",
|
|
43
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_schedules_next ON schedules(enabled, next_fire_at) WHERE deleted_at IS NULL`,
|
|
44
|
+
},
|
|
45
|
+
];
|