botinabox 2.9.1 → 2.9.2
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/README.md +2 -1
- package/dist/channels/discord/adapter.d.ts +32 -0
- package/dist/channels/discord/inbound.d.ts +25 -0
- package/dist/channels/discord/index.d.ts +8 -84
- package/dist/channels/discord/models.d.ts +8 -0
- package/dist/channels/discord/outbound.d.ts +14 -0
- package/dist/channels/slack/adapter.d.ts +33 -0
- package/dist/channels/slack/bolt-adapter.d.ts +31 -0
- package/dist/channels/slack/enrichers/enrich.d.ts +12 -0
- package/dist/channels/slack/enrichers/image-enricher.d.ts +10 -0
- package/dist/channels/slack/enrichers/index.d.ts +4 -0
- package/dist/channels/slack/enrichers/pdf-enricher.d.ts +8 -0
- package/dist/channels/slack/enrichers/types.d.ts +33 -0
- package/dist/channels/slack/inbound.d.ts +59 -0
- package/dist/channels/slack/index.d.ts +13 -252
- package/dist/channels/slack/media-type.d.ts +14 -0
- package/dist/channels/slack/models.d.ts +9 -0
- package/dist/channels/slack/outbound.d.ts +12 -0
- package/dist/channels/slack/transcribe.d.ts +41 -0
- package/dist/channels/webhook/adapter.d.ts +23 -0
- package/dist/channels/webhook/hmac.d.ts +13 -0
- package/dist/channels/webhook/index.d.ts +7 -70
- package/dist/channels/webhook/models.d.ts +9 -0
- package/dist/channels/webhook/server.d.ts +20 -0
- package/dist/cli/templates/config.yml.d.ts +7 -0
- package/dist/cli/templates/env.d.ts +1 -0
- package/dist/cli/templates/index.ts.d.ts +2 -0
- package/dist/cli/templates/package.json.d.ts +5 -0
- package/dist/cli.d.ts +1 -3
- package/dist/connectors/google/calendar-connector.d.ts +40 -0
- package/dist/connectors/google/drive-connector.d.ts +43 -0
- package/dist/connectors/google/drive-read.d.ts +81 -0
- package/dist/connectors/google/gmail-connector.d.ts +42 -0
- package/dist/connectors/google/index.d.ts +10 -369
- package/dist/connectors/google/oauth.d.ts +48 -0
- package/dist/connectors/google/types.d.ts +110 -0
- package/dist/core/chat/auto-discovery.d.ts +16 -0
- package/dist/core/chat/channel-registry.d.ts +45 -0
- package/dist/core/chat/chat-pipeline-v2.d.ts +138 -0
- package/dist/core/chat/chat-pipeline.d.ts +116 -0
- package/dist/core/chat/chat-responder.d.ts +94 -0
- package/dist/core/chat/formatter.d.ts +11 -0
- package/dist/core/chat/index.d.ts +26 -0
- package/dist/core/chat/message-interpreter.d.ts +91 -0
- package/dist/core/chat/message-store.d.ts +71 -0
- package/dist/core/chat/notification-queue.d.ts +34 -0
- package/dist/core/chat/pipeline.d.ts +38 -0
- package/dist/core/chat/policies.d.ts +16 -0
- package/dist/core/chat/routing.d.ts +17 -0
- package/dist/core/chat/session-key.d.ts +30 -0
- package/dist/core/chat/session-manager.d.ts +17 -0
- package/dist/core/chat/text-chunker.d.ts +9 -0
- package/dist/core/chat/triage-router.d.ts +75 -0
- package/dist/core/chat/types.d.ts +5 -0
- package/dist/core/config/defaults.d.ts +2 -0
- package/dist/core/config/index.d.ts +6 -0
- package/dist/core/config/interpolate.d.ts +5 -0
- package/dist/core/config/loader.d.ts +24 -0
- package/dist/core/config/schema.d.ts +5 -0
- package/dist/core/data/context-builder.d.ts +27 -0
- package/dist/core/data/core-entity-contexts.d.ts +14 -0
- package/dist/core/data/core-migrations.d.ts +5 -0
- package/dist/core/data/core-schema.d.ts +6 -0
- package/dist/core/data/data-store.d.ts +67 -0
- package/dist/core/data/domain-entity-contexts.d.ts +35 -0
- package/dist/core/data/domain-schema.d.ts +36 -0
- package/dist/core/data/index.d.ts +8 -0
- package/dist/core/data/types.d.ts +111 -0
- package/dist/core/hooks/hook-bus.d.ts +24 -0
- package/dist/core/hooks/index.d.ts +2 -0
- package/dist/core/hooks/types.d.ts +19 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/llm/auto-discovery.d.ts +11 -0
- package/dist/core/llm/cost-tracker.d.ts +6 -0
- package/dist/core/llm/default-llm-call.d.ts +35 -0
- package/dist/core/llm/index.d.ts +6 -0
- package/dist/core/llm/model-router.d.ts +25 -0
- package/dist/core/llm/provider-registry.d.ts +9 -0
- package/dist/core/llm/types.d.ts +2 -0
- package/dist/core/orchestrator/adapters/api-adapter.d.ts +34 -0
- package/dist/core/orchestrator/adapters/cli-adapter.d.ts +62 -0
- package/dist/core/orchestrator/adapters/deterministic-adapter.d.ts +35 -0
- package/dist/core/orchestrator/adapters/env-whitelist.d.ts +4 -0
- package/dist/core/orchestrator/adapters/output-extractor.d.ts +11 -0
- package/dist/core/orchestrator/adapters/process-manager.d.ts +15 -0
- package/dist/core/orchestrator/adapters/tool-loop.d.ts +22 -0
- package/dist/core/orchestrator/agent-registry.d.ts +31 -0
- package/dist/core/orchestrator/budget-controller.d.ts +19 -0
- package/dist/core/orchestrator/chain-guard.d.ts +14 -0
- package/dist/core/orchestrator/circuit-breaker.d.ts +65 -0
- package/dist/core/orchestrator/claude-stream-parser.d.ts +31 -0
- package/dist/core/orchestrator/config-revisions.d.ts +6 -0
- package/dist/core/orchestrator/dependency-resolver.d.ts +20 -0
- package/dist/core/orchestrator/execution-engine.d.ts +99 -0
- package/dist/core/orchestrator/governance-gate.d.ts +110 -0
- package/dist/core/orchestrator/learning-pipeline.d.ts +112 -0
- package/dist/core/orchestrator/loop-detector.d.ts +51 -0
- package/dist/core/orchestrator/ndjson-logger.d.ts +6 -0
- package/dist/core/orchestrator/permission-relay.d.ts +72 -0
- package/dist/core/orchestrator/run-manager.d.ts +31 -0
- package/dist/core/orchestrator/scheduler.d.ts +74 -0
- package/dist/core/orchestrator/secret-store.d.ts +57 -0
- package/dist/core/orchestrator/session-manager.d.ts +13 -0
- package/dist/core/orchestrator/task-queue.d.ts +34 -0
- package/dist/core/orchestrator/template-interpolate.d.ts +5 -0
- package/dist/core/orchestrator/tools/file-ops.d.ts +12 -0
- package/dist/core/orchestrator/tools/index.d.ts +47 -0
- package/dist/core/orchestrator/tools/management.d.ts +12 -0
- package/dist/core/orchestrator/tools/messaging.d.ts +21 -0
- package/dist/core/orchestrator/tools/read-file.d.ts +5 -0
- package/dist/core/orchestrator/tools/resolve-agent.d.ts +9 -0
- package/dist/core/orchestrator/tools/roster.d.ts +16 -0
- package/dist/core/orchestrator/tools/send-file.d.ts +5 -0
- package/dist/core/orchestrator/tools/status.d.ts +20 -0
- package/dist/core/orchestrator/tools/task-ops.d.ts +13 -0
- package/dist/core/orchestrator/user-registry.d.ts +47 -0
- package/dist/core/orchestrator/wakeup-queue.d.ts +9 -0
- package/dist/core/orchestrator/workflow-engine.d.ts +47 -0
- package/dist/core/security/audit.d.ts +20 -0
- package/dist/core/security/column-validator.d.ts +20 -0
- package/dist/core/security/index.d.ts +5 -0
- package/dist/core/security/process-env.d.ts +13 -0
- package/dist/core/security/sanitizer.d.ts +11 -0
- package/dist/core/security/types.d.ts +11 -0
- package/dist/core/update/auto-update.d.ts +21 -0
- package/dist/core/update/backup-manager.d.ts +7 -0
- package/dist/core/update/index.d.ts +8 -0
- package/dist/core/update/migration-hooks.d.ts +11 -0
- package/dist/core/update/types.d.ts +11 -0
- package/dist/core/update/update-checker.d.ts +11 -0
- package/dist/core/update/update-manager.d.ts +25 -0
- package/dist/core/update/version-utils.d.ts +6 -0
- package/dist/index.d.ts +38 -2366
- package/dist/index.js +112 -5
- package/dist/providers/anthropic/index.d.ts +5 -20
- package/dist/providers/anthropic/models.d.ts +2 -0
- package/dist/providers/anthropic/provider.d.ts +13 -0
- package/dist/providers/anthropic/tool-converter.d.ts +10 -0
- package/dist/providers/ollama/index.d.ts +4 -22
- package/dist/providers/ollama/provider.d.ts +17 -0
- package/dist/providers/openai/index.d.ts +5 -20
- package/dist/providers/openai/models.d.ts +2 -0
- package/dist/providers/openai/provider.d.ts +13 -0
- package/dist/providers/openai/tool-converter.d.ts +10 -0
- package/dist/shared/constants.d.ts +50 -0
- package/dist/shared/index.d.ts +14 -0
- package/dist/shared/types/agent.d.ts +36 -0
- package/dist/shared/types/channel.d.ts +78 -0
- package/dist/shared/types/config.d.ts +160 -0
- package/dist/shared/types/connector.d.ts +77 -0
- package/dist/shared/types/execution.d.ts +29 -0
- package/dist/shared/types/provider.d.ts +87 -0
- package/dist/shared/types/task.d.ts +47 -0
- package/dist/shared/types/workflow.d.ts +39 -0
- package/dist/shared/utils.d.ts +6 -0
- package/dist/update-check.d.ts +5 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,2367 +1,39 @@
|
|
|
1
|
-
import { C as ChannelAdapter, H as HealthStatus, I as InboundMessage } from './channel-CVm1AWUF.js';
|
|
2
|
-
export { A as Attachment, a as AttachmentMediaType, b as ChannelCapabilities, c as ChannelConfig, d as ChannelMeta, e as ChatType, F as FormattingMode, O as OutboundPayload, S as SendResult } from './channel-CVm1AWUF.js';
|
|
3
|
-
import { T as TokenUsage, L as LLMProvider, M as ModelInfo, R as ResolvedModel, C as ChatMessage } from './provider-BHkqkSdq.js';
|
|
4
|
-
export { a as ChatParams, b as ChatResult, c as ContentBlock, d as ToolUse } from './provider-BHkqkSdq.js';
|
|
5
|
-
import { C as ConnectorConfig } from './connector-B4Mj0P1b.js';
|
|
6
|
-
export { A as AuthResult, a as Connector, b as ConnectorMeta, P as PushResult, S as SyncOptions, c as SyncResult } from './connector-B4Mj0P1b.js';
|
|
7
|
-
import { C as ChatResponderConfig, D as DataStore, H as HookBus, M as MessageStore, a as ChatResponder, b as MessageInterpreter, E as Extractor } from './chat-pipeline-aBSj7a4E.js';
|
|
8
|
-
export { c as ChatPipeline, d as ChatPipelineConfig, e as DataStoreError, f as EntityContextDef, g as EntityFileSpec, h as EntitySource, i as ExtractedFile, j as ExtractedMemory, k as ExtractedTask, l as ExtractedUserContext, F as Filter, m as HookHandler, n as HookOptions, o as HookRegistration, I as InterpretationResult, L as LLMCallFn, p as MessageInterpreterConfig, P as PkLookup, Q as QueryOptions, R as RelationDef, q as RoutingDecision, r as RoutingRule, s as Row, S as SeedItem, t as SqliteAdapter, u as StoreResult, v as StoredAttachment, T as TableDefinition, w as TableInfoRow, x as TriageRouter, y as TriageRouterConfig, U as Unsubscribe } from './chat-pipeline-aBSj7a4E.js';
|
|
9
|
-
import 'better-sqlite3';
|
|
10
|
-
|
|
11
|
-
/** Execution adapter types — Story 1.5 / 3.4 / 3.5 */
|
|
12
|
-
type RunStatus = "queued" | "running" | "succeeded" | "failed" | "cancelled";
|
|
13
|
-
interface RunContext {
|
|
14
|
-
runId: string;
|
|
15
|
-
agentId: string;
|
|
16
|
-
agentSlug: string;
|
|
17
|
-
taskId?: string;
|
|
18
|
-
taskTitle?: string;
|
|
19
|
-
taskDescription?: string;
|
|
20
|
-
model: string;
|
|
21
|
-
workdir: string;
|
|
22
|
-
sessionParams?: unknown;
|
|
23
|
-
abortSignal?: AbortSignal;
|
|
24
|
-
onLog?: (line: string) => void;
|
|
25
|
-
}
|
|
26
|
-
interface RunResult {
|
|
27
|
-
status: "succeeded" | "failed";
|
|
28
|
-
output?: string;
|
|
29
|
-
error?: string;
|
|
30
|
-
usage?: TokenUsage;
|
|
31
|
-
costCents?: number;
|
|
32
|
-
sessionParams?: unknown;
|
|
33
|
-
clearSession?: boolean;
|
|
34
|
-
durationMs: number;
|
|
35
|
-
}
|
|
36
|
-
interface ExecutionAdapter {
|
|
37
|
-
id: string;
|
|
38
|
-
execute(ctx: RunContext): Promise<RunResult>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Agent types — Story 1.5 / 3.1 */
|
|
42
|
-
type AgentStatus = "idle" | "running" | "paused" | "terminated" | "error";
|
|
43
|
-
interface AgentDefinition {
|
|
44
|
-
slug: string;
|
|
45
|
-
name: string;
|
|
46
|
-
role?: string;
|
|
47
|
-
adapter: string;
|
|
48
|
-
model?: string;
|
|
49
|
-
workdir?: string;
|
|
50
|
-
instructionsFile?: string;
|
|
51
|
-
maxConcurrentRuns?: number;
|
|
52
|
-
budgetMonthlyCents?: number;
|
|
53
|
-
canCreateAgents?: boolean;
|
|
54
|
-
skipPermissions?: boolean;
|
|
55
|
-
config?: Record<string, unknown>;
|
|
56
|
-
}
|
|
57
|
-
interface AgentRecord extends AgentDefinition {
|
|
58
|
-
id: string;
|
|
59
|
-
status: AgentStatus;
|
|
60
|
-
spentMonthlyCents: number;
|
|
61
|
-
createdAt: string;
|
|
62
|
-
updatedAt: string;
|
|
63
|
-
deletedAt?: string;
|
|
64
|
-
}
|
|
65
|
-
interface AgentFilter {
|
|
66
|
-
status?: AgentStatus | AgentStatus[];
|
|
67
|
-
role?: string;
|
|
68
|
-
adapter?: string;
|
|
69
|
-
}
|
|
70
|
-
interface BudgetCheck {
|
|
71
|
-
allowed: boolean;
|
|
72
|
-
status: "ok" | "warning" | "hard_stop";
|
|
73
|
-
spentCents: number;
|
|
74
|
-
limitCents?: number;
|
|
75
|
-
message?: string;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Task types — Story 1.5 / 3.2 */
|
|
79
|
-
type TaskStatus = "backlog" | "todo" | "in_progress" | "in_review" | "done" | "blocked" | "cancelled";
|
|
80
|
-
interface RetryPolicy {
|
|
81
|
-
maxRetries: number;
|
|
82
|
-
backoffMs: number;
|
|
83
|
-
backoffMultiplier: number;
|
|
84
|
-
maxBackoffMs: number;
|
|
85
|
-
}
|
|
86
|
-
interface TaskDefinition {
|
|
87
|
-
title: string;
|
|
88
|
-
description?: string;
|
|
89
|
-
assigneeId?: string;
|
|
90
|
-
priority?: number;
|
|
91
|
-
parentId?: string;
|
|
92
|
-
dependsOn?: string[];
|
|
93
|
-
followupAgentId?: string;
|
|
94
|
-
followupTemplate?: string;
|
|
95
|
-
chainOriginId?: string;
|
|
96
|
-
chainDepth?: number;
|
|
97
|
-
retryPolicy?: RetryPolicy;
|
|
98
|
-
metadata?: Record<string, unknown>;
|
|
99
|
-
}
|
|
100
|
-
interface TaskRecord extends Required<Pick<TaskDefinition, "title" | "priority">> {
|
|
101
|
-
id: string;
|
|
102
|
-
description: string;
|
|
103
|
-
assigneeId?: string;
|
|
104
|
-
status: TaskStatus;
|
|
105
|
-
priority: number;
|
|
106
|
-
parentId?: string;
|
|
107
|
-
dependsOn: string[];
|
|
108
|
-
followupAgentId?: string;
|
|
109
|
-
followupTemplate?: string;
|
|
110
|
-
chainOriginId?: string;
|
|
111
|
-
chainDepth: number;
|
|
112
|
-
retryPolicy?: RetryPolicy;
|
|
113
|
-
retryCount: number;
|
|
114
|
-
maxRetries: number;
|
|
115
|
-
nextRetryAt?: string;
|
|
116
|
-
executionRunId?: string;
|
|
117
|
-
result?: string;
|
|
118
|
-
completedOutput?: string;
|
|
119
|
-
metadata?: Record<string, unknown>;
|
|
120
|
-
createdAt: string;
|
|
121
|
-
updatedAt: string;
|
|
122
|
-
completedAt?: string;
|
|
123
|
-
deletedAt?: string;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/** Bot configuration types — Story 1.2 / 1.5 */
|
|
127
|
-
interface DataConfig {
|
|
128
|
-
path: string;
|
|
129
|
-
walMode: boolean;
|
|
130
|
-
backupDir?: string;
|
|
131
|
-
}
|
|
132
|
-
interface ModelConfig {
|
|
133
|
-
aliases: Record<string, string>;
|
|
134
|
-
default: string;
|
|
135
|
-
routing: Record<string, string>;
|
|
136
|
-
fallbackChain: string[];
|
|
137
|
-
costLimit?: {
|
|
138
|
-
perRunCents?: number;
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
interface SecurityConfig {
|
|
142
|
-
fieldLengthLimits?: Record<string, number>;
|
|
143
|
-
allowedFilePrefixes?: string[];
|
|
144
|
-
}
|
|
145
|
-
interface RenderConfig {
|
|
146
|
-
outputDir: string;
|
|
147
|
-
watchIntervalMs: number;
|
|
148
|
-
}
|
|
149
|
-
interface UpdateConfig {
|
|
150
|
-
policy: "auto-all" | "auto-compatible" | "auto-patch" | "notify" | "manual";
|
|
151
|
-
checkIntervalMs: number;
|
|
152
|
-
maintenanceWindow?: {
|
|
153
|
-
utcHourStart: number;
|
|
154
|
-
utcHourEnd: number;
|
|
155
|
-
days?: Array<"mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun">;
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
interface BudgetConfig {
|
|
159
|
-
globalMonthlyCents?: number;
|
|
160
|
-
warnPercent: number;
|
|
161
|
-
}
|
|
162
|
-
interface EntityColumnDef {
|
|
163
|
-
type: "uuid" | "text" | "integer" | "boolean" | "datetime" | "real";
|
|
164
|
-
required?: boolean;
|
|
165
|
-
default?: string | number | boolean;
|
|
166
|
-
references?: string;
|
|
167
|
-
}
|
|
168
|
-
interface EntityConfig {
|
|
169
|
-
columns: Record<string, EntityColumnDef>;
|
|
170
|
-
relations?: Array<{
|
|
171
|
-
type: "hasMany" | "manyToMany" | "belongsTo";
|
|
172
|
-
table: string;
|
|
173
|
-
through?: string;
|
|
174
|
-
localKey?: string;
|
|
175
|
-
remoteKey?: string;
|
|
176
|
-
}>;
|
|
177
|
-
}
|
|
178
|
-
interface AgentConfig {
|
|
179
|
-
slug: string;
|
|
180
|
-
name: string;
|
|
181
|
-
role?: string;
|
|
182
|
-
adapter: string;
|
|
183
|
-
model?: string;
|
|
184
|
-
workdir?: string;
|
|
185
|
-
instructionsFile?: string;
|
|
186
|
-
maxConcurrentRuns?: number;
|
|
187
|
-
budgetMonthlyCents?: number;
|
|
188
|
-
canCreateAgents?: boolean;
|
|
189
|
-
skipPermissions?: boolean;
|
|
190
|
-
config?: Record<string, unknown>;
|
|
191
|
-
}
|
|
192
|
-
interface ExecutionConfig {
|
|
193
|
-
/** Model for task execution. Default: models.routing.task_execution */
|
|
194
|
-
model?: string;
|
|
195
|
-
/** Max tool loop iterations per task. Default: 5 */
|
|
196
|
-
maxIterations?: number;
|
|
197
|
-
/** Max tokens per LLM call. Default: 4096 */
|
|
198
|
-
maxTokens?: number;
|
|
199
|
-
/** Additional system prompt text appended to agent prompt */
|
|
200
|
-
systemPromptSuffix?: string;
|
|
201
|
-
}
|
|
202
|
-
interface ChatConfig {
|
|
203
|
-
/** System prompt for the conversational responder */
|
|
204
|
-
systemPrompt?: string;
|
|
205
|
-
/** Max tokens for context window. Default: 4000 */
|
|
206
|
-
contextWindowTokens?: number;
|
|
207
|
-
/** Max recent outbound messages for redundancy check. Default: 10 */
|
|
208
|
-
redundancyWindow?: number;
|
|
209
|
-
/** Message dedup window in ms. Default: 300000 (5 min) */
|
|
210
|
-
dedupWindowMs?: number;
|
|
211
|
-
/** Max tokens for ack responses. Default: 500 */
|
|
212
|
-
responseMaxTokens?: number;
|
|
213
|
-
}
|
|
214
|
-
interface RoutingConfig {
|
|
215
|
-
/** Routing rules for message triage */
|
|
216
|
-
rules: Array<{
|
|
217
|
-
agentSlug: string;
|
|
218
|
-
keywords?: string[];
|
|
219
|
-
patterns?: string[];
|
|
220
|
-
priority?: number;
|
|
221
|
-
}>;
|
|
222
|
-
/** Default agent when no rule matches */
|
|
223
|
-
fallbackAgent: string;
|
|
224
|
-
/** Use LLM for ambiguous messages. Default: false */
|
|
225
|
-
llmFallback?: boolean;
|
|
226
|
-
}
|
|
227
|
-
interface SafetyConfig {
|
|
228
|
-
/** Circuit breaker failure threshold. Default: 3 */
|
|
229
|
-
circuitBreakerThreshold?: number;
|
|
230
|
-
/** Circuit breaker reset timeout ms. Default: 300000 (5 min) */
|
|
231
|
-
circuitBreakerResetMs?: number;
|
|
232
|
-
/** Max agent followup chain depth. Default: 5 */
|
|
233
|
-
maxChainDepth?: number;
|
|
234
|
-
/** Stale run detection threshold ms. Default: 1800000 (30 min) */
|
|
235
|
-
staleRunThresholdMs?: number;
|
|
236
|
-
}
|
|
237
|
-
interface BotConfig {
|
|
238
|
-
data: DataConfig;
|
|
239
|
-
channels: Record<string, {
|
|
240
|
-
enabled: boolean;
|
|
241
|
-
accounts?: Record<string, unknown>;
|
|
242
|
-
} & Record<string, unknown>>;
|
|
243
|
-
connectors?: Record<string, {
|
|
244
|
-
enabled: boolean;
|
|
245
|
-
provider: string;
|
|
246
|
-
accounts?: Record<string, ConnectorConfig>;
|
|
247
|
-
} & Record<string, unknown>>;
|
|
248
|
-
agents: AgentConfig[];
|
|
249
|
-
providers: Record<string, {
|
|
250
|
-
enabled: boolean;
|
|
251
|
-
} & Record<string, unknown>>;
|
|
252
|
-
models: ModelConfig;
|
|
253
|
-
entities: Record<string, EntityConfig>;
|
|
254
|
-
security: SecurityConfig;
|
|
255
|
-
render: RenderConfig;
|
|
256
|
-
updates: UpdateConfig;
|
|
257
|
-
budget: BudgetConfig;
|
|
258
|
-
execution?: ExecutionConfig;
|
|
259
|
-
chat?: ChatConfig;
|
|
260
|
-
routing?: RoutingConfig;
|
|
261
|
-
safety?: SafetyConfig;
|
|
262
|
-
workflows?: Record<string, WorkflowConfigEntry>;
|
|
263
|
-
}
|
|
264
|
-
interface WorkflowConfigEntry {
|
|
265
|
-
name: string;
|
|
266
|
-
description?: string;
|
|
267
|
-
steps: WorkflowStepConfig[];
|
|
268
|
-
trigger?: {
|
|
269
|
-
type: "task_completed" | "event" | "schedule" | "manual";
|
|
270
|
-
filter?: Record<string, unknown>;
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
interface WorkflowStepConfig {
|
|
274
|
-
id: string;
|
|
275
|
-
name: string;
|
|
276
|
-
agentSlug?: string;
|
|
277
|
-
taskTemplate: {
|
|
278
|
-
title: string;
|
|
279
|
-
description: string;
|
|
280
|
-
};
|
|
281
|
-
dependsOn?: string[];
|
|
282
|
-
onComplete?: "next" | "parallel" | "end";
|
|
283
|
-
onFail?: "abort" | "skip" | "retry";
|
|
284
|
-
retryPolicy?: RetryPolicy;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/** Workflow types — Story 1.5 / 5.1 */
|
|
288
|
-
type WorkflowRunStatus = "running" | "completed" | "failed" | "cancelled";
|
|
289
|
-
interface WorkflowStep$1 {
|
|
290
|
-
id: string;
|
|
291
|
-
name: string;
|
|
292
|
-
agentSlug?: string;
|
|
293
|
-
agentResolver?: string;
|
|
294
|
-
taskTemplate: {
|
|
295
|
-
title: string;
|
|
296
|
-
description: string;
|
|
297
|
-
};
|
|
298
|
-
dependsOn?: string[];
|
|
299
|
-
onComplete?: "next" | "parallel" | "end";
|
|
300
|
-
onFail?: "abort" | "skip" | "retry";
|
|
301
|
-
retryPolicy?: RetryPolicy;
|
|
302
|
-
condition?: string;
|
|
303
|
-
}
|
|
304
|
-
interface WorkflowDefinition$1 {
|
|
305
|
-
slug: string;
|
|
306
|
-
name: string;
|
|
307
|
-
description?: string;
|
|
308
|
-
steps: WorkflowStep$1[];
|
|
309
|
-
trigger?: WorkflowTrigger;
|
|
310
|
-
}
|
|
311
|
-
interface WorkflowTrigger {
|
|
312
|
-
type: "task_completed" | "event" | "schedule" | "manual";
|
|
313
|
-
filter?: Record<string, unknown>;
|
|
314
|
-
}
|
|
315
|
-
interface WorkflowRunRecord {
|
|
316
|
-
id: string;
|
|
317
|
-
workflowId: string;
|
|
318
|
-
status: WorkflowRunStatus;
|
|
319
|
-
currentStep: number;
|
|
320
|
-
context: Record<string, unknown>;
|
|
321
|
-
originTaskId?: string;
|
|
322
|
-
startedAt: string;
|
|
323
|
-
finishedAt?: string;
|
|
324
|
-
error?: string;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/** Shared constants — event names, default values, status enums */
|
|
328
|
-
/** Hook/event name constants */
|
|
329
|
-
declare const EVENTS: {
|
|
330
|
-
readonly COST_RECORDED: "cost.recorded";
|
|
331
|
-
readonly AGENT_CREATED: "agent.created";
|
|
332
|
-
readonly AGENT_STATUS_CHANGED: "agent.status_changed";
|
|
333
|
-
readonly BUDGET_EXCEEDED: "budget.exceeded";
|
|
334
|
-
readonly TASK_CREATED: "task.created";
|
|
335
|
-
readonly TASK_COMPLETED: "task.completed";
|
|
336
|
-
readonly TASK_FAILED: "task.failed";
|
|
337
|
-
readonly TASK_CANCELLED: "task.cancelled";
|
|
338
|
-
readonly RUN_STARTED: "run.started";
|
|
339
|
-
readonly RUN_COMPLETED: "run.completed";
|
|
340
|
-
readonly RUN_FAILED: "run.failed";
|
|
341
|
-
readonly MESSAGE_INBOUND: "message.inbound";
|
|
342
|
-
readonly MESSAGE_ROUTED: "message.routed";
|
|
343
|
-
readonly MESSAGE_PROCESSED: "message.processed";
|
|
344
|
-
readonly MESSAGE_OUTBOUND: "message.outbound";
|
|
345
|
-
readonly MESSAGE_SENT: "message.sent";
|
|
346
|
-
readonly UPDATE_AVAILABLE: "update.available";
|
|
347
|
-
readonly UPDATE_STARTED: "update.started";
|
|
348
|
-
readonly UPDATE_COMPLETED: "update.completed";
|
|
349
|
-
readonly UPDATE_FAILED: "update.failed";
|
|
350
|
-
readonly WORKFLOW_STARTED: "workflow.started";
|
|
351
|
-
readonly WORKFLOW_STEP_COMPLETED: "workflow.step_completed";
|
|
352
|
-
readonly WORKFLOW_COMPLETED: "workflow.completed";
|
|
353
|
-
readonly WORKFLOW_FAILED: "workflow.failed";
|
|
354
|
-
};
|
|
355
|
-
/** Default config values */
|
|
356
|
-
declare const DEFAULTS: {
|
|
357
|
-
readonly TASK_POLL_INTERVAL_MS: 30000;
|
|
358
|
-
readonly NOTIFICATION_POLL_INTERVAL_MS: 5000;
|
|
359
|
-
readonly ORPHAN_REAP_INTERVAL_MS: 300000;
|
|
360
|
-
readonly STALE_RUN_THRESHOLD_MS: 1800000;
|
|
361
|
-
readonly STALE_TASK_AGE_MS: 7200000;
|
|
362
|
-
readonly MAX_CHAIN_DEPTH: 5;
|
|
363
|
-
readonly MAX_NOTIFICATION_RETRIES: 3;
|
|
364
|
-
readonly UPDATE_CHECK_INTERVAL_MS: 86400000;
|
|
365
|
-
readonly RENDER_WATCH_INTERVAL_MS: 30000;
|
|
366
|
-
readonly DATA_PATH: "./data/bot.db";
|
|
367
|
-
readonly RENDER_OUTPUT_DIR: "./context";
|
|
368
|
-
readonly LOG_PATH_TEMPLATE: "./data/runs/{runId}.ndjson";
|
|
369
|
-
readonly BUDGET_WARN_PERCENT: 80;
|
|
370
|
-
};
|
|
371
|
-
/** Task status values */
|
|
372
|
-
declare const TASK_STATUSES: readonly ["backlog", "todo", "in_progress", "in_review", "done", "blocked", "cancelled"];
|
|
373
|
-
/** Agent status values */
|
|
374
|
-
declare const AGENT_STATUSES: readonly ["idle", "running", "paused", "terminated", "error"];
|
|
375
|
-
/** Run status values */
|
|
376
|
-
declare const RUN_STATUSES: readonly ["queued", "running", "succeeded", "failed", "cancelled"];
|
|
377
|
-
|
|
378
|
-
/** Shared utility functions. */
|
|
379
1
|
/**
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*/
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
*
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
}
|
|
419
|
-
declare function validateConfig(config: unknown): SchemaError[];
|
|
420
|
-
|
|
421
|
-
declare const DEFAULT_CONFIG: BotConfig;
|
|
422
|
-
|
|
423
|
-
declare class ProviderRegistry {
|
|
424
|
-
private providers;
|
|
425
|
-
register(provider: LLMProvider): void;
|
|
426
|
-
unregister(id: string): void;
|
|
427
|
-
get(id: string): LLMProvider | undefined;
|
|
428
|
-
list(): LLMProvider[];
|
|
429
|
-
listModels(): ModelInfo[];
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
declare class ModelRouter {
|
|
433
|
-
private readonly registry;
|
|
434
|
-
private readonly config;
|
|
435
|
-
constructor(registry: ProviderRegistry, config: ModelConfig);
|
|
436
|
-
/**
|
|
437
|
-
* Resolve a model ID or alias to a ResolvedModel.
|
|
438
|
-
* 1. Look up alias in config.aliases (or use as-is)
|
|
439
|
-
* 2. Search all registered providers for a model with that id
|
|
440
|
-
*/
|
|
441
|
-
resolve(modelIdOrAlias: string): ResolvedModel | undefined;
|
|
442
|
-
/**
|
|
443
|
-
* Try primary model, then each in config.fallbackChain.
|
|
444
|
-
* Throws if none found.
|
|
445
|
-
*/
|
|
446
|
-
resolveWithFallback(modelIdOrAlias: string): ResolvedModel;
|
|
447
|
-
/**
|
|
448
|
-
* Use config.routing[purpose] ?? config.default, then resolveWithFallback.
|
|
449
|
-
*/
|
|
450
|
-
resolveForPurpose(purpose: string): ResolvedModel;
|
|
451
|
-
/** Returns all models from all registered providers. */
|
|
452
|
-
listAvailable(): ModelInfo[];
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
type Importer$1 = (packageName: string) => Promise<unknown>;
|
|
456
|
-
/**
|
|
457
|
-
* Scans nodeModulesPath/@botinabox/{pkg}/package.json for each package in the scope.
|
|
458
|
-
* If pkg.botinabox?.type === 'provider', dynamically imports the package
|
|
459
|
-
* and returns the discovered LLMProvider instances.
|
|
460
|
-
*
|
|
461
|
-
* The optional importer parameter allows injection for testing.
|
|
462
|
-
*/
|
|
463
|
-
declare function discoverProviders(nodeModulesPath: string, importer?: Importer$1): Promise<LLMProvider[]>;
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
* Default LLM call function — ready-to-use wrapper around the Anthropic SDK.
|
|
467
|
-
*
|
|
468
|
-
* Handles model routing (fast → Haiku, default → Sonnet), message formatting,
|
|
469
|
-
* and response extraction. Apps can use this directly or provide their own.
|
|
470
|
-
*/
|
|
471
|
-
|
|
472
|
-
interface DefaultLLMCallConfig {
|
|
473
|
-
/** Fast model ID (for acks, interpretation). Default: claude-haiku-4-5-20251001 */
|
|
474
|
-
fastModel?: string;
|
|
475
|
-
/** Standard model ID (for execution). Default: claude-sonnet-4-20250514 */
|
|
476
|
-
defaultModel?: string;
|
|
477
|
-
}
|
|
478
|
-
/**
|
|
479
|
-
* Create a default LLM call function using the Anthropic SDK.
|
|
480
|
-
*
|
|
481
|
-
* @param anthropicClient - An initialized Anthropic client instance
|
|
482
|
-
* @param config - Optional model configuration
|
|
483
|
-
*/
|
|
484
|
-
declare function createDefaultLLMCall(anthropicClient: {
|
|
485
|
-
messages: {
|
|
486
|
-
create: (params: Record<string, unknown>) => Promise<{
|
|
487
|
-
content: Array<{
|
|
488
|
-
type: string;
|
|
489
|
-
text?: string;
|
|
490
|
-
}>;
|
|
491
|
-
model: string;
|
|
492
|
-
stop_reason: string;
|
|
493
|
-
usage: {
|
|
494
|
-
input_tokens: number;
|
|
495
|
-
output_tokens: number;
|
|
496
|
-
};
|
|
497
|
-
}>;
|
|
498
|
-
};
|
|
499
|
-
}, config?: DefaultLLMCallConfig): ChatResponderConfig['llmCall'];
|
|
500
|
-
|
|
501
|
-
/**
|
|
502
|
-
* ChannelRegistry — manages channel adapter lifecycle.
|
|
503
|
-
* Story 4.1
|
|
504
|
-
*/
|
|
505
|
-
|
|
506
|
-
declare class ChannelRegistryError extends Error {
|
|
507
|
-
constructor(message: string);
|
|
508
|
-
}
|
|
509
|
-
declare class ChannelRegistry {
|
|
510
|
-
private readonly adapters;
|
|
511
|
-
private started;
|
|
512
|
-
/**
|
|
513
|
-
* Register a channel adapter.
|
|
514
|
-
* Throws if an adapter with the same id is already registered.
|
|
515
|
-
* If registry is already started, immediately connects the adapter.
|
|
516
|
-
*/
|
|
517
|
-
register(adapter: ChannelAdapter, config?: unknown): void;
|
|
518
|
-
/**
|
|
519
|
-
* Unregister a channel adapter.
|
|
520
|
-
* Disconnects the adapter if it exists.
|
|
521
|
-
*/
|
|
522
|
-
unregister(id: string): Promise<void>;
|
|
523
|
-
/**
|
|
524
|
-
* Reconfigure an adapter: disconnect, update config, reconnect.
|
|
525
|
-
*/
|
|
526
|
-
reconfigure(id: string, config: unknown): Promise<void>;
|
|
527
|
-
/**
|
|
528
|
-
* Run health checks on all registered adapters.
|
|
529
|
-
*/
|
|
530
|
-
healthCheck(): Promise<Record<string, HealthStatus>>;
|
|
531
|
-
/** Check if an adapter is registered. */
|
|
532
|
-
has(id: string): boolean;
|
|
533
|
-
/** Get an adapter by ID. */
|
|
534
|
-
get(id: string): ChannelAdapter | undefined;
|
|
535
|
-
/** List all registered adapters. */
|
|
536
|
-
list(): ChannelAdapter[];
|
|
537
|
-
/**
|
|
538
|
-
* Start: connect all registered adapters and mark registry as started.
|
|
539
|
-
*/
|
|
540
|
-
start(): Promise<void>;
|
|
541
|
-
/**
|
|
542
|
-
* Stop: disconnect all registered adapters.
|
|
543
|
-
*/
|
|
544
|
-
stop(): Promise<void>;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
/**
|
|
548
|
-
* Auto-discovery for channel adapters.
|
|
549
|
-
* Scans @botinabox/* packages for botinabox.type === 'channel'.
|
|
550
|
-
* Story 4.1
|
|
551
|
-
*/
|
|
552
|
-
|
|
553
|
-
type Importer = (packageName: string) => Promise<unknown>;
|
|
554
|
-
/**
|
|
555
|
-
* Scans nodeModulesPath/@botinabox/{pkg}/package.json for each package in the scope.
|
|
556
|
-
* If pkg.botinabox?.type === 'channel', dynamically imports the package
|
|
557
|
-
* and returns the discovered ChannelAdapter instances.
|
|
558
|
-
*
|
|
559
|
-
* The optional importer parameter allows injection for testing.
|
|
560
|
-
*/
|
|
561
|
-
declare function discoverChannels(nodeModulesPath: string, importer?: Importer): Promise<ChannelAdapter[]>;
|
|
562
|
-
|
|
563
|
-
declare class AgentRegistry {
|
|
564
|
-
private db;
|
|
565
|
-
private hooks;
|
|
566
|
-
constructor(db: DataStore, hooks: HookBus);
|
|
567
|
-
register(agent: {
|
|
568
|
-
slug: string;
|
|
569
|
-
name: string;
|
|
570
|
-
adapter: string;
|
|
571
|
-
role?: string;
|
|
572
|
-
[key: string]: unknown;
|
|
573
|
-
}, opts?: {
|
|
574
|
-
actorAgentId?: string;
|
|
575
|
-
}): Promise<string>;
|
|
576
|
-
getById(id: string): Promise<Record<string, unknown> | undefined>;
|
|
577
|
-
getBySlug(slug: string): Promise<Record<string, unknown> | undefined>;
|
|
578
|
-
list(filter?: {
|
|
579
|
-
status?: string;
|
|
580
|
-
role?: string;
|
|
581
|
-
}): Promise<Record<string, unknown>[]>;
|
|
582
|
-
update(id: string, changes: Record<string, unknown>): Promise<void>;
|
|
583
|
-
setStatus(id: string, newStatus: string): Promise<void>;
|
|
584
|
-
terminate(id: string): Promise<void>;
|
|
585
|
-
seedFromConfig(agentConfigs: Array<{
|
|
586
|
-
slug: string;
|
|
587
|
-
name: string;
|
|
588
|
-
adapter: string;
|
|
589
|
-
[key: string]: unknown;
|
|
590
|
-
}>): Promise<void>;
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
declare const MAX_CHAIN_DEPTH = 5;
|
|
594
|
-
/**
|
|
595
|
-
* Throws if depth exceeds the maximum allowed chain depth.
|
|
596
|
-
*/
|
|
597
|
-
declare function checkChainDepth(depth: number, max?: number): void;
|
|
598
|
-
/**
|
|
599
|
-
* Build chain origin metadata for a new child task.
|
|
600
|
-
* If parentTaskId is provided, sets chain_origin_id and increments depth.
|
|
601
|
-
* Otherwise returns depth=0 with no origin.
|
|
602
|
-
*/
|
|
603
|
-
declare function buildChainOrigin(parentTaskId?: string, parentOriginId?: string, parentDepth?: number): {
|
|
604
|
-
chain_origin_id?: string;
|
|
605
|
-
chain_depth: number;
|
|
606
|
-
};
|
|
607
|
-
|
|
608
|
-
declare class TaskQueue {
|
|
609
|
-
private db;
|
|
610
|
-
private hooks;
|
|
611
|
-
private config?;
|
|
612
|
-
private pollTimer;
|
|
613
|
-
private readonly pollIntervalMs;
|
|
614
|
-
private readonly staleThresholdMs;
|
|
615
|
-
constructor(db: DataStore, hooks: HookBus, config?: {
|
|
616
|
-
pollIntervalMs?: number;
|
|
617
|
-
staleThresholdMs?: number;
|
|
618
|
-
} | undefined);
|
|
619
|
-
create(task: {
|
|
620
|
-
title: string;
|
|
621
|
-
description?: string;
|
|
622
|
-
assignee_id?: string;
|
|
623
|
-
priority?: number;
|
|
624
|
-
chain_depth?: number;
|
|
625
|
-
chain_origin_id?: string;
|
|
626
|
-
[key: string]: unknown;
|
|
627
|
-
}): Promise<string>;
|
|
628
|
-
update(id: string, changes: Record<string, unknown>): Promise<void>;
|
|
629
|
-
get(id: string): Promise<Record<string, unknown> | undefined>;
|
|
630
|
-
list(filter?: {
|
|
631
|
-
status?: string;
|
|
632
|
-
assignee_id?: string;
|
|
633
|
-
}): Promise<Record<string, unknown>[]>;
|
|
634
|
-
startPolling(): void;
|
|
635
|
-
stopPolling(): void;
|
|
636
|
-
private poll;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
interface UserInput {
|
|
640
|
-
id?: string;
|
|
641
|
-
org_id?: string;
|
|
642
|
-
name: string;
|
|
643
|
-
email?: string;
|
|
644
|
-
role?: string;
|
|
645
|
-
title?: string;
|
|
646
|
-
external_id?: string;
|
|
647
|
-
channel?: string;
|
|
648
|
-
timezone?: string;
|
|
649
|
-
preferences?: string;
|
|
650
|
-
notes?: string;
|
|
651
|
-
}
|
|
652
|
-
interface User {
|
|
653
|
-
id: string;
|
|
654
|
-
org_id: string | null;
|
|
655
|
-
name: string;
|
|
656
|
-
email: string | null;
|
|
657
|
-
role: string | null;
|
|
658
|
-
title: string | null;
|
|
659
|
-
external_id: string | null;
|
|
660
|
-
channel: string | null;
|
|
661
|
-
timezone: string | null;
|
|
662
|
-
preferences: string;
|
|
663
|
-
notes: string | null;
|
|
664
|
-
created_at: string;
|
|
665
|
-
updated_at: string;
|
|
666
|
-
deleted_at: string | null;
|
|
667
|
-
}
|
|
668
|
-
declare class UserRegistry {
|
|
669
|
-
private readonly db;
|
|
670
|
-
private readonly hooks;
|
|
671
|
-
constructor(db: DataStore, hooks: HookBus);
|
|
672
|
-
register(input: UserInput): Promise<User>;
|
|
673
|
-
getById(id: string): Promise<User | null>;
|
|
674
|
-
getByEmail(email: string): Promise<User | null>;
|
|
675
|
-
resolveByIdentity(channel: string, externalId: string): Promise<User | null>;
|
|
676
|
-
resolveOrCreate(externalId: string, channel: string, defaults?: Partial<UserInput>): Promise<User>;
|
|
677
|
-
list(filter?: {
|
|
678
|
-
role?: string;
|
|
679
|
-
org_id?: string;
|
|
680
|
-
}): Promise<User[]>;
|
|
681
|
-
update(id: string, changes: Partial<UserInput>): Promise<void>;
|
|
682
|
-
addIdentity(userId: string, channel: string, externalId: string, displayName?: string): Promise<void>;
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
/**
|
|
686
|
-
* MessagePipeline — routes inbound messages to the task queue.
|
|
687
|
-
* Story 4.2
|
|
688
|
-
*/
|
|
689
|
-
|
|
690
|
-
declare class MessagePipeline {
|
|
691
|
-
private readonly hooks;
|
|
692
|
-
private readonly agentRegistry;
|
|
693
|
-
private readonly taskQueue;
|
|
694
|
-
private readonly config;
|
|
695
|
-
private readonly agentBindings;
|
|
696
|
-
private readonly userRegistry?;
|
|
697
|
-
constructor(hooks: HookBus, agentRegistry: AgentRegistry, taskQueue: TaskQueue, config: BotConfig, userRegistry?: UserRegistry);
|
|
698
|
-
/**
|
|
699
|
-
* Process an inbound message end-to-end.
|
|
700
|
-
* 1. Emit 'message.inbound'
|
|
701
|
-
* 2. Resolve agent
|
|
702
|
-
* 3. Check policy (allowlist / mention gate)
|
|
703
|
-
* 4. Create task
|
|
704
|
-
* 5. Emit 'message.processed'
|
|
705
|
-
*/
|
|
706
|
-
processInbound(msg: InboundMessage): Promise<void>;
|
|
707
|
-
/**
|
|
708
|
-
* Resolve the best agent for a given inbound message.
|
|
709
|
-
* Returns agentId (slug) or undefined if no match.
|
|
710
|
-
*/
|
|
711
|
-
resolveAgent(msg: InboundMessage): string | undefined;
|
|
712
|
-
/**
|
|
713
|
-
* Evaluate messaging policy for the given agent.
|
|
714
|
-
* Returns false if the message is blocked.
|
|
715
|
-
*/
|
|
716
|
-
evaluatePolicy(msg: InboundMessage, agentId: string): boolean;
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
/**
|
|
720
|
-
* Chat routing — maps channel/scope to agentId.
|
|
721
|
-
* Story 4.2
|
|
722
|
-
*
|
|
723
|
-
* @deprecated Use TriageRouter for content-aware routing with keyword/regex
|
|
724
|
-
* matching and LLM fallback. This static channel→agent binding is kept for
|
|
725
|
-
* backward compatibility only. See `./triage-router.ts`.
|
|
726
|
-
*/
|
|
727
|
-
|
|
728
|
-
/**
|
|
729
|
-
* Build a map from channel identifier to agentId.
|
|
730
|
-
* Each agent may have a config.channel or config.channels binding.
|
|
731
|
-
*
|
|
732
|
-
* @deprecated Use TriageRouter instead — it supports keyword, regex,
|
|
733
|
-
* and LLM-based routing with ownership chain logging.
|
|
734
|
-
*/
|
|
735
|
-
declare function buildAgentBindings(agents: AgentConfig[]): Map<string, string>;
|
|
736
|
-
|
|
737
|
-
/**
|
|
738
|
-
* Chat policy helpers — allowlist and mention gate checks.
|
|
739
|
-
* Story 4.2
|
|
740
|
-
*/
|
|
741
|
-
|
|
742
|
-
/**
|
|
743
|
-
* Returns true if the sender is in the allowlist.
|
|
744
|
-
* If allowFrom is empty, all senders are allowed.
|
|
745
|
-
*/
|
|
746
|
-
declare function checkAllowlist(allowFrom: string[], senderId: string): boolean;
|
|
747
|
-
/**
|
|
748
|
-
* Returns true if the message passes the mention gate.
|
|
749
|
-
* In group/channel contexts, the bot must be mentioned (body contains @botId or similar).
|
|
750
|
-
* In direct contexts, always passes.
|
|
751
|
-
*/
|
|
752
|
-
declare function checkMentionGate(msg: InboundMessage, botId: string): boolean;
|
|
753
|
-
|
|
754
|
-
/**
|
|
755
|
-
* SessionKey — structured key for chat sessions.
|
|
756
|
-
* Story 4.3
|
|
757
|
-
*/
|
|
758
|
-
declare class SessionKey {
|
|
759
|
-
readonly agentId: string;
|
|
760
|
-
readonly channel: string;
|
|
761
|
-
readonly scope: string;
|
|
762
|
-
constructor(agentId: string, channel: string, scope: string);
|
|
763
|
-
toString(): string;
|
|
764
|
-
toJSON(): {
|
|
765
|
-
agentId: string;
|
|
766
|
-
channel: string;
|
|
767
|
-
scope: string;
|
|
768
|
-
};
|
|
769
|
-
static fromString(key: string): SessionKey;
|
|
770
|
-
/**
|
|
771
|
-
* Build a session key from structured parameters.
|
|
772
|
-
*
|
|
773
|
-
* @param agentId - The agent identifier
|
|
774
|
-
* @param channel - The channel identifier
|
|
775
|
-
* @param chatType - 'dm' or 'group'
|
|
776
|
-
* @param peerId - The peer/user ID
|
|
777
|
-
* @param dmScope - DM scoping strategy
|
|
778
|
-
* - 'main' → single session per agent+channel regardless of peer
|
|
779
|
-
* - 'per-peer' → one session per (agent, peer)
|
|
780
|
-
* - 'per-channel-peer' → one session per (agent, channel, peer)
|
|
781
|
-
*/
|
|
782
|
-
static build(agentId: string, channel: string, chatType: "dm" | "group", peerId: string, dmScope: "main" | "per-peer" | "per-channel-peer"): SessionKey;
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
/**
|
|
786
|
-
* ChatSessionManager — wraps orchestrator SessionManager with SessionKey-based lookup.
|
|
787
|
-
* Story 4.3
|
|
788
|
-
*/
|
|
789
|
-
|
|
790
|
-
declare class ChatSessionManager {
|
|
791
|
-
private readonly inner;
|
|
792
|
-
constructor(db: DataStore);
|
|
793
|
-
save(key: SessionKey, params: Record<string, unknown>): Promise<string>;
|
|
794
|
-
load(key: SessionKey): Promise<Record<string, unknown> | undefined>;
|
|
795
|
-
clear(key: SessionKey): Promise<void>;
|
|
796
|
-
shouldClear(session: Record<string, unknown>, opts: {
|
|
797
|
-
maxRuns?: number;
|
|
798
|
-
maxAgeHours?: number;
|
|
799
|
-
}): Promise<boolean>;
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
/**
|
|
803
|
-
* NotificationQueue — persistent outbound notification queue with retry.
|
|
804
|
-
* Story 4.4
|
|
805
|
-
*/
|
|
806
|
-
|
|
807
|
-
interface NotificationQueueOpts {
|
|
808
|
-
maxRetries?: number;
|
|
809
|
-
pollIntervalMs?: number;
|
|
810
|
-
}
|
|
811
|
-
declare class NotificationQueue {
|
|
812
|
-
private readonly db;
|
|
813
|
-
private readonly hooks;
|
|
814
|
-
private readonly channelRegistry;
|
|
815
|
-
private readonly maxRetries;
|
|
816
|
-
private readonly pollIntervalMs;
|
|
817
|
-
private timer;
|
|
818
|
-
constructor(db: DataStore, hooks: HookBus, channelRegistry: ChannelRegistry, opts?: NotificationQueueOpts);
|
|
819
|
-
/**
|
|
820
|
-
* Enqueue a notification for delivery.
|
|
821
|
-
* Returns the notification ID.
|
|
822
|
-
*/
|
|
823
|
-
enqueue(channel: string, recipient: string, payload: {
|
|
824
|
-
text: string;
|
|
825
|
-
threadId?: string;
|
|
826
|
-
[key: string]: unknown;
|
|
827
|
-
}): Promise<string>;
|
|
828
|
-
/** Start the background worker polling for pending notifications. */
|
|
829
|
-
startWorker(): void;
|
|
830
|
-
/** Stop the background worker. */
|
|
831
|
-
stopWorker(): void;
|
|
832
|
-
private processNext;
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
/**
|
|
836
|
-
* CircuitBreaker — prevents runaway agent failures with automatic escalation.
|
|
837
|
-
* Story 6.2
|
|
838
|
-
*
|
|
839
|
-
* States:
|
|
840
|
-
* CLOSED → normal operation, failures counted
|
|
841
|
-
* OPEN → tripped, all executions blocked, escalated to human
|
|
842
|
-
* HALF_OPEN → probe mode, one execution allowed to test recovery
|
|
843
|
-
*
|
|
844
|
-
* Integrates with LoopDetector and RunManager via HookBus events.
|
|
845
|
-
*/
|
|
846
|
-
|
|
847
|
-
declare enum BreakerState {
|
|
848
|
-
CLOSED = "closed",
|
|
849
|
-
OPEN = "open",
|
|
850
|
-
HALF_OPEN = "half_open"
|
|
851
|
-
}
|
|
852
|
-
interface CircuitBreakerConfig {
|
|
853
|
-
/** Failures before tripping. Default: 3 */
|
|
854
|
-
failureThreshold?: number;
|
|
855
|
-
/** Milliseconds to wait before half-open probe. Default: 300_000 (5 min) */
|
|
856
|
-
resetTimeoutMs?: number;
|
|
857
|
-
/** Log events to the database. Default: true */
|
|
858
|
-
persist?: boolean;
|
|
859
|
-
}
|
|
860
|
-
declare class CircuitBreaker {
|
|
861
|
-
private db;
|
|
862
|
-
private hooks;
|
|
863
|
-
private readonly breakers;
|
|
864
|
-
private readonly failureThreshold;
|
|
865
|
-
private readonly resetTimeoutMs;
|
|
866
|
-
private readonly persist;
|
|
867
|
-
constructor(db: DataStore, hooks: HookBus, config?: CircuitBreakerConfig);
|
|
868
|
-
/**
|
|
869
|
-
* Check if an agent is allowed to execute.
|
|
870
|
-
* Returns true if execution is allowed, false if circuit is open.
|
|
871
|
-
*/
|
|
872
|
-
canExecute(agentId: string): boolean;
|
|
873
|
-
/**
|
|
874
|
-
* Record a successful execution. Resets the breaker to CLOSED.
|
|
875
|
-
*/
|
|
876
|
-
recordSuccess(agentId: string): Promise<void>;
|
|
877
|
-
/**
|
|
878
|
-
* Record a failed execution. Increments failure count and may trip breaker.
|
|
879
|
-
*/
|
|
880
|
-
recordFailure(agentId: string, reason?: string): Promise<void>;
|
|
881
|
-
/**
|
|
882
|
-
* Trip the breaker to OPEN state and escalate to human.
|
|
883
|
-
*/
|
|
884
|
-
trip(agentId: string, reason: string): Promise<void>;
|
|
885
|
-
/**
|
|
886
|
-
* Manually reset a breaker (e.g. after human review).
|
|
887
|
-
*/
|
|
888
|
-
reset(agentId: string): Promise<void>;
|
|
889
|
-
/**
|
|
890
|
-
* Get the current state of a breaker.
|
|
891
|
-
*/
|
|
892
|
-
getState(agentId: string): BreakerState;
|
|
893
|
-
/**
|
|
894
|
-
* Get failure count for an agent.
|
|
895
|
-
*/
|
|
896
|
-
getFailureCount(agentId: string): number;
|
|
897
|
-
private logEvent;
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
declare class RunManager {
|
|
901
|
-
private db;
|
|
902
|
-
private hooks;
|
|
903
|
-
private config?;
|
|
904
|
-
private locks;
|
|
905
|
-
private orphanTimer;
|
|
906
|
-
private readonly staleThresholdMs;
|
|
907
|
-
private circuitBreaker?;
|
|
908
|
-
constructor(db: DataStore, hooks: HookBus, config?: {
|
|
909
|
-
staleThresholdMs?: number;
|
|
910
|
-
maxBackoffMs?: number;
|
|
911
|
-
} | undefined);
|
|
912
|
-
/**
|
|
913
|
-
* Attach a CircuitBreaker to prevent retries on broken agents.
|
|
914
|
-
*/
|
|
915
|
-
setCircuitBreaker(cb: CircuitBreaker): void;
|
|
916
|
-
isLocked(agentId: string): boolean;
|
|
917
|
-
startRun(agentId: string, taskId: string, adapter?: string): Promise<string>;
|
|
918
|
-
finishRun(runId: string, result: {
|
|
919
|
-
exitCode: number;
|
|
920
|
-
output?: string;
|
|
921
|
-
costCents?: number;
|
|
922
|
-
usage?: unknown;
|
|
923
|
-
}): Promise<void>;
|
|
924
|
-
reapOrphans(): Promise<void>;
|
|
925
|
-
startOrphanReaper(intervalMs?: number): void;
|
|
926
|
-
stopOrphanReaper(): void;
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
/**
|
|
930
|
-
* ExecutionEngine — generic task executor with pluggable tools and tool loop.
|
|
931
|
-
*
|
|
932
|
-
* Listens for task.created events, picks up tasks, runs them through an LLM
|
|
933
|
-
* with tools, and finishes the run with the result.
|
|
934
|
-
*
|
|
935
|
-
* Apps configure: model, tools, system prompt, max iterations.
|
|
936
|
-
* Framework handles: task pickup, locking, tool loop, cost tracking, result storage.
|
|
937
|
-
*/
|
|
938
|
-
|
|
939
|
-
interface ToolDefinition {
|
|
940
|
-
name: string;
|
|
941
|
-
description: string;
|
|
942
|
-
input_schema: Record<string, unknown>;
|
|
943
|
-
}
|
|
944
|
-
type ToolHandler = (input: Record<string, unknown>, context: ToolContext) => Promise<string>;
|
|
945
|
-
interface ToolContext {
|
|
946
|
-
taskId: string;
|
|
947
|
-
agentId: string;
|
|
948
|
-
hooks: HookBus;
|
|
949
|
-
db: DataStore;
|
|
950
|
-
/** Resolve a relative file path to an absolute path (environment-aware). */
|
|
951
|
-
resolveFilePath?: (path: string) => string;
|
|
952
|
-
}
|
|
953
|
-
interface ContextFile {
|
|
954
|
-
/** Absolute path, used as the `path` attribute in the wrapped XML tag. */
|
|
955
|
-
path: string;
|
|
956
|
-
/** Raw file contents (UTF-8). The engine does not read the filesystem itself. */
|
|
957
|
-
content: string;
|
|
958
|
-
}
|
|
959
|
-
interface ExecutionEngineConfig {
|
|
960
|
-
/** Anthropic client instance */
|
|
961
|
-
client: {
|
|
962
|
-
messages: {
|
|
963
|
-
create: (params: Record<string, unknown>) => Promise<{
|
|
964
|
-
content: Array<{
|
|
965
|
-
type: string;
|
|
966
|
-
text?: string;
|
|
967
|
-
id?: string;
|
|
968
|
-
name?: string;
|
|
969
|
-
input?: unknown;
|
|
970
|
-
}>;
|
|
971
|
-
stop_reason: string;
|
|
972
|
-
usage: {
|
|
973
|
-
input_tokens: number;
|
|
974
|
-
output_tokens: number;
|
|
975
|
-
};
|
|
976
|
-
}>;
|
|
977
|
-
};
|
|
978
|
-
};
|
|
979
|
-
/** Model to use. Default: claude-sonnet-4-20250514 */
|
|
980
|
-
model?: string;
|
|
981
|
-
/** Max tool loop iterations. Default: 5 */
|
|
982
|
-
maxIterations?: number;
|
|
983
|
-
/** Tools available to the agent */
|
|
984
|
-
tools?: Array<{
|
|
985
|
-
definition: ToolDefinition;
|
|
986
|
-
handler: ToolHandler;
|
|
987
|
-
}>;
|
|
988
|
-
/** Additional system prompt text (appended after system context) */
|
|
989
|
-
systemPromptSuffix?: string;
|
|
990
|
-
/** Include system context (users, files, etc). Default: true */
|
|
991
|
-
includeSystemContext?: boolean;
|
|
992
|
-
/** Resolve file paths from DB-relative to absolute (for cross-environment support). */
|
|
993
|
-
resolveFilePath?: (path: string) => string;
|
|
994
|
-
/**
|
|
995
|
-
* Optional per-dispatch context resolver. Called once per task pickup with
|
|
996
|
-
* the resolved agent and task rows. Returned files are wrapped in
|
|
997
|
-
* `<file path="...">...</file>` XML tags and inserted into the system
|
|
998
|
-
* prompt between the static `buildSystemContext` block and the tool
|
|
999
|
-
* listing. Intended for apps that want to inject per-agent or per-project
|
|
1000
|
-
* rendered context (rules, playbooks, agent definitions) that is not
|
|
1001
|
-
* already covered by `buildSystemContext`.
|
|
1002
|
-
*
|
|
1003
|
-
* The resolver owns all filesystem / database lookups — the engine does
|
|
1004
|
-
* not touch the disk. If the resolver throws, the task fails loudly per
|
|
1005
|
-
* Rule-16-style fail-loud semantics; there is no silent fallback.
|
|
1006
|
-
*/
|
|
1007
|
-
resolveContextFiles?: (ctx: {
|
|
1008
|
-
agent: Record<string, unknown>;
|
|
1009
|
-
task: Record<string, unknown>;
|
|
1010
|
-
}) => Promise<ContextFile[]> | ContextFile[];
|
|
1011
|
-
}
|
|
1012
|
-
declare function registerExecutionEngine(opts: {
|
|
1013
|
-
db: DataStore;
|
|
1014
|
-
hooks: HookBus;
|
|
1015
|
-
runs: RunManager;
|
|
1016
|
-
config: ExecutionEngineConfig;
|
|
1017
|
-
}): Promise<void>;
|
|
1018
|
-
|
|
1019
|
-
/**
|
|
1020
|
-
* SystemContextBuilder — loads entity data from the database and formats
|
|
1021
|
-
* it as markdown for injection into LLM system prompts.
|
|
1022
|
-
*
|
|
1023
|
-
* Used by both the ChatPipeline (ack layer) and ExecutionEngine (agent layer)
|
|
1024
|
-
* to give LLMs awareness of the system state.
|
|
1025
|
-
*/
|
|
1026
|
-
|
|
1027
|
-
interface SystemContextOptions {
|
|
1028
|
-
/** Include users. Default: true */
|
|
1029
|
-
users?: boolean;
|
|
1030
|
-
/** Include agents. Default: true */
|
|
1031
|
-
agents?: boolean;
|
|
1032
|
-
/** Include projects. Default: true */
|
|
1033
|
-
projects?: boolean;
|
|
1034
|
-
/** Include clients. Default: true */
|
|
1035
|
-
clients?: boolean;
|
|
1036
|
-
/** Include files. Default: true */
|
|
1037
|
-
files?: boolean;
|
|
1038
|
-
/** Include org. Default: true */
|
|
1039
|
-
org?: boolean;
|
|
1040
|
-
}
|
|
1041
|
-
/**
|
|
1042
|
-
* Build a markdown-formatted system context string from the database.
|
|
1043
|
-
* Queries users, agents, projects, clients, files, and org.
|
|
1044
|
-
*/
|
|
1045
|
-
declare function buildSystemContext(db: DataStore, options?: SystemContextOptions): Promise<string>;
|
|
1046
|
-
|
|
1047
|
-
/**
|
|
1048
|
-
* ChatPipelineV2 — Primary Agent Architecture.
|
|
1049
|
-
*
|
|
1050
|
-
* Replaces the 6-layer "dumb ack + headless execution" pattern with a
|
|
1051
|
-
* 3-phase "conversational brain + tool delegation" pattern:
|
|
1052
|
-
*
|
|
1053
|
-
* Phase 1: RECEIVE — Store message, build history, emit typing indicator
|
|
1054
|
-
* Phase 2: THINK — Call primary agent LLM with history + tools in a loop
|
|
1055
|
-
* Phase 3: RESPOND — Deliver agent's text, run async memory extraction
|
|
1056
|
-
*
|
|
1057
|
-
* The primary agent is the conversational hub. It has full conversation
|
|
1058
|
-
* context and uses tools to answer directly (single-agent) or delegate
|
|
1059
|
-
* work (multi-agent). One response per message — no separate ack.
|
|
1060
|
-
*/
|
|
1061
|
-
|
|
1062
|
-
type ContentBlock = {
|
|
1063
|
-
type: string;
|
|
1064
|
-
text?: string;
|
|
1065
|
-
id?: string;
|
|
1066
|
-
name?: string;
|
|
1067
|
-
input?: unknown;
|
|
1068
|
-
source?: unknown;
|
|
1069
|
-
};
|
|
1070
|
-
type MessageParam = {
|
|
1071
|
-
role: string;
|
|
1072
|
-
content: string | ContentBlock[];
|
|
1073
|
-
};
|
|
1074
|
-
interface ChatPipelineV2Config {
|
|
1075
|
-
/** Primary agent LLM call — supports tool use */
|
|
1076
|
-
llmCall: (params: {
|
|
1077
|
-
model: string;
|
|
1078
|
-
messages: MessageParam[];
|
|
1079
|
-
system?: string;
|
|
1080
|
-
maxTokens?: number;
|
|
1081
|
-
tools?: ToolDefinition[];
|
|
1082
|
-
tool_choice?: {
|
|
1083
|
-
type: string;
|
|
1084
|
-
};
|
|
1085
|
-
}) => Promise<{
|
|
1086
|
-
content: ContentBlock[];
|
|
1087
|
-
stop_reason: string;
|
|
1088
|
-
usage?: {
|
|
1089
|
-
input_tokens: number;
|
|
1090
|
-
output_tokens: number;
|
|
1091
|
-
};
|
|
1092
|
-
}>;
|
|
1093
|
-
/** System prompt for the primary agent */
|
|
1094
|
-
systemPrompt: string;
|
|
1095
|
-
/** Tools available to the primary agent */
|
|
1096
|
-
tools?: Array<{
|
|
1097
|
-
definition: ToolDefinition;
|
|
1098
|
-
handler: ToolHandler;
|
|
1099
|
-
}>;
|
|
1100
|
-
/** Model (default: 'claude-sonnet-4-6') */
|
|
1101
|
-
model?: string;
|
|
1102
|
-
/** Max tool loop iterations (default: 5) */
|
|
1103
|
-
maxIterations?: number;
|
|
1104
|
-
/** Max tokens for response (default: 4096) */
|
|
1105
|
-
maxTokens?: number;
|
|
1106
|
-
/** Optional message filter */
|
|
1107
|
-
messageFilter?: (msg: InboundMessage) => boolean;
|
|
1108
|
-
/** Channel (default: 'slack') */
|
|
1109
|
-
channel?: string;
|
|
1110
|
-
/** Dedup window ms (default: 300_000) */
|
|
1111
|
-
dedupWindowMs?: number;
|
|
1112
|
-
/** Conversation history config */
|
|
1113
|
-
history?: {
|
|
1114
|
-
maxMessages?: number;
|
|
1115
|
-
maxAgeDays?: number;
|
|
1116
|
-
includeAssistant?: boolean;
|
|
1117
|
-
};
|
|
1118
|
-
/** Include system context from DB (default: true) */
|
|
1119
|
-
includeSystemContext?: boolean;
|
|
1120
|
-
/** Options for buildSystemContext */
|
|
1121
|
-
systemContextOptions?: SystemContextOptions;
|
|
1122
|
-
/** TaskQueue for dispatch_task and sub-agent result delivery */
|
|
1123
|
-
tasks: {
|
|
1124
|
-
create(task: Record<string, unknown>): Promise<string>;
|
|
1125
|
-
update(id: string, changes: Record<string, unknown>): Promise<void>;
|
|
1126
|
-
get(id: string): Promise<Record<string, unknown> | undefined>;
|
|
1127
|
-
};
|
|
1128
|
-
/** WakeupQueue for agent wakeup */
|
|
1129
|
-
wakeups: {
|
|
1130
|
-
enqueue(agentId: string, source: string, context?: Record<string, unknown>): Promise<string>;
|
|
1131
|
-
};
|
|
1132
|
-
/** Custom extractors for async memory extraction */
|
|
1133
|
-
extractors?: Extractor[];
|
|
1134
|
-
/** Sub-agent result handling (default: 'passthrough') */
|
|
1135
|
-
subAgentResultMode?: 'passthrough' | 'synthesize';
|
|
1136
|
-
/** Resolve file paths from DB-relative to absolute */
|
|
1137
|
-
resolveFilePath?: (path: string) => string;
|
|
1138
|
-
}
|
|
1139
|
-
declare class ChatPipelineV2 {
|
|
1140
|
-
private db;
|
|
1141
|
-
private hooks;
|
|
1142
|
-
private config;
|
|
1143
|
-
readonly messageStore: MessageStore;
|
|
1144
|
-
readonly responder: ChatResponder;
|
|
1145
|
-
readonly interpreter: MessageInterpreter;
|
|
1146
|
-
private readonly channel;
|
|
1147
|
-
private readonly messageFilter?;
|
|
1148
|
-
private readonly dedupWindowMs;
|
|
1149
|
-
private readonly threadChannelMap;
|
|
1150
|
-
private readonly toolDefs;
|
|
1151
|
-
private readonly toolHandlers;
|
|
1152
|
-
constructor(db: DataStore, hooks: HookBus, config: ChatPipelineV2Config);
|
|
1153
|
-
/**
|
|
1154
|
-
* Resolve the channel ID for a thread (for response delivery).
|
|
1155
|
-
*/
|
|
1156
|
-
resolveChannel(threadId: string, taskId?: string): Promise<string | undefined>;
|
|
1157
|
-
private registerHandlers;
|
|
1158
|
-
/**
|
|
1159
|
-
* Primary agent tool loop — adapted from ExecutionEngine pattern.
|
|
1160
|
-
*/
|
|
1161
|
-
private think;
|
|
1162
|
-
/**
|
|
1163
|
-
* Build conversation history from channel messages.
|
|
1164
|
-
* Includes BOTH user and assistant messages (unlike v1 which excluded bot messages).
|
|
1165
|
-
*/
|
|
1166
|
-
private buildHistory;
|
|
1167
|
-
/**
|
|
1168
|
-
* Dedup check (same as v1).
|
|
1169
|
-
*/
|
|
1170
|
-
private isDuplicate;
|
|
1171
|
-
/**
|
|
1172
|
-
* Async memory extraction (non-blocking, non-fatal).
|
|
1173
|
-
*/
|
|
1174
|
-
private extractAsync;
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
/**
|
|
1178
|
-
* Text chunker — splits long text into chunks at natural boundaries.
|
|
1179
|
-
* Story 4.4
|
|
1180
|
-
*/
|
|
1181
|
-
/**
|
|
1182
|
-
* Split text into chunks of at most maxLen characters.
|
|
1183
|
-
* Splits at paragraph boundaries first, then sentence, then word, then hard-cuts.
|
|
1184
|
-
*/
|
|
1185
|
-
declare function chunkText(text: string, maxLen: number): string[];
|
|
1186
|
-
|
|
1187
|
-
/**
|
|
1188
|
-
* Text formatter — converts markdown to channel-specific formats.
|
|
1189
|
-
* Story 4.4
|
|
1190
|
-
*/
|
|
1191
|
-
/**
|
|
1192
|
-
* Format text for the given mode:
|
|
1193
|
-
* - 'mrkdwn': Slack's mrkdwn format (**bold** → *bold*, _italic_ preserved, `code` preserved)
|
|
1194
|
-
* - 'html': basic markdown → HTML (strong, em, code, pre)
|
|
1195
|
-
* - 'plain': strip markdown markers
|
|
1196
|
-
*/
|
|
1197
|
-
declare function formatText(text: string, mode: "mrkdwn" | "html" | "plain"): string;
|
|
1198
|
-
|
|
1199
|
-
/**
|
|
1200
|
-
* Define all 18 core tables on a DataStore instance.
|
|
1201
|
-
* Call before db.init().
|
|
1202
|
-
*/
|
|
1203
|
-
declare function defineCoreTables(db: DataStore): void;
|
|
1204
|
-
|
|
1205
|
-
/** Initial migration set for core tables */
|
|
1206
|
-
declare const CORE_MIGRATIONS: Array<{
|
|
1207
|
-
version: string;
|
|
1208
|
-
sql: string;
|
|
1209
|
-
}>;
|
|
1210
|
-
|
|
1211
|
-
/**
|
|
1212
|
-
* Define default entity context rendering for botinabox core tables.
|
|
1213
|
-
* Call after defineCoreTables() and before or after init().
|
|
1214
|
-
*
|
|
1215
|
-
* Renders:
|
|
1216
|
-
* - agents/ — per-agent context (AGENT.md, PROJECTS.md if agent_project exists)
|
|
1217
|
-
* - users/ — per-user context (USER.md) — protected
|
|
1218
|
-
* - skills/ — per-skill context (SKILL.md)
|
|
1219
|
-
*
|
|
1220
|
-
* Apps can override by calling db.defineEntityContext() with the same table name
|
|
1221
|
-
* BEFORE calling defineCoreEntityContexts().
|
|
1222
|
-
*/
|
|
1223
|
-
declare function defineCoreEntityContexts(db: DataStore): void;
|
|
1224
|
-
|
|
1225
|
-
/**
|
|
1226
|
-
* Options for domain table generation.
|
|
1227
|
-
* Enable/disable optional tables based on your app's needs.
|
|
1228
|
-
*/
|
|
1229
|
-
interface DomainSchemaOptions {
|
|
1230
|
-
/** Include client + invoice tables (default: true) */
|
|
1231
|
-
clients?: boolean;
|
|
1232
|
-
/** Include repository table (default: true) */
|
|
1233
|
-
repositories?: boolean;
|
|
1234
|
-
/** Include file table (default: true) */
|
|
1235
|
-
files?: boolean;
|
|
1236
|
-
/** Include channel table (default: true) */
|
|
1237
|
-
channels?: boolean;
|
|
1238
|
-
/** Include rule table + junction tables (default: true) */
|
|
1239
|
-
rules?: boolean;
|
|
1240
|
-
/** Include event audit log (default: true) */
|
|
1241
|
-
events?: boolean;
|
|
1242
|
-
/** Include cross-domain junction tables (default: true) */
|
|
1243
|
-
junctions?: boolean;
|
|
1244
|
-
}
|
|
1245
|
-
/**
|
|
1246
|
-
* Define standard domain tables that most multi-agent apps need.
|
|
1247
|
-
* Call after defineCoreTables() and before db.init().
|
|
1248
|
-
*
|
|
1249
|
-
* Provides: org, project, + optional client, invoice, repository,
|
|
1250
|
-
* file, channel, rule, event tables with appropriate junction tables.
|
|
1251
|
-
*
|
|
1252
|
-
* @example
|
|
1253
|
-
* ```ts
|
|
1254
|
-
* defineCoreTables(db);
|
|
1255
|
-
* defineDomainTables(db); // all tables
|
|
1256
|
-
* defineDomainTables(db, { clients: false }); // skip client/invoice
|
|
1257
|
-
* ```
|
|
1258
|
-
*/
|
|
1259
|
-
declare function defineDomainTables(db: DataStore, options?: DomainSchemaOptions): void;
|
|
1260
|
-
|
|
1261
|
-
/**
|
|
1262
|
-
* Options for domain entity context generation.
|
|
1263
|
-
* Match the options used in defineDomainTables().
|
|
1264
|
-
*/
|
|
1265
|
-
interface DomainEntityContextOptions {
|
|
1266
|
-
clients?: boolean;
|
|
1267
|
-
repositories?: boolean;
|
|
1268
|
-
files?: boolean;
|
|
1269
|
-
channels?: boolean;
|
|
1270
|
-
rules?: boolean;
|
|
1271
|
-
/** Column used as directory name for each entity type. Default: 'id'. */
|
|
1272
|
-
orgSlugColumn?: string;
|
|
1273
|
-
projectSlugColumn?: string;
|
|
1274
|
-
clientSlugColumn?: string;
|
|
1275
|
-
fileSlugColumn?: string;
|
|
1276
|
-
channelSlugColumn?: string;
|
|
1277
|
-
}
|
|
1278
|
-
/**
|
|
1279
|
-
* Define entity context rendering for standard domain tables.
|
|
1280
|
-
* Call after defineDomainTables() and defineCoreTables().
|
|
1281
|
-
*
|
|
1282
|
-
* Renders per-entity directories with context files for:
|
|
1283
|
-
* org, project, + optional client, file, channel entities.
|
|
1284
|
-
* Also adds PROJECTS.md, RULES.md, SKILLS.md, REPOS.md to agent context.
|
|
1285
|
-
*
|
|
1286
|
-
* @example
|
|
1287
|
-
* ```ts
|
|
1288
|
-
* defineCoreTables(db);
|
|
1289
|
-
* defineDomainTables(db);
|
|
1290
|
-
* defineCoreEntityContexts(db); // agents, users, skills
|
|
1291
|
-
* defineDomainEntityContexts(db); // org, project, client, file, channel
|
|
1292
|
-
* ```
|
|
1293
|
-
*/
|
|
1294
|
-
declare function defineDomainEntityContexts(db: DataStore, options?: DomainEntityContextOptions): void;
|
|
1295
|
-
|
|
1296
|
-
interface SanitizerOptions {
|
|
1297
|
-
fieldLengthLimits?: Record<string, number>;
|
|
1298
|
-
truncateSuffix?: string;
|
|
1299
|
-
}
|
|
1300
|
-
interface AuditEvent {
|
|
1301
|
-
table: string;
|
|
1302
|
-
operation: 'insert' | 'update' | 'delete';
|
|
1303
|
-
pk: unknown;
|
|
1304
|
-
timestamp: number;
|
|
1305
|
-
changedColumns?: string[];
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
/**
|
|
1309
|
-
* Sanitizes a row object by:
|
|
1310
|
-
* 1. Stripping null bytes from string values
|
|
1311
|
-
* 2. Stripping control characters (preserving \n, \r, \t)
|
|
1312
|
-
* 3. Truncating fields that exceed their byte length limit
|
|
1313
|
-
*
|
|
1314
|
-
* Non-string values pass through unchanged.
|
|
1315
|
-
* Returns a new object — input is never mutated.
|
|
1316
|
-
*/
|
|
1317
|
-
declare function sanitize(row: Record<string, unknown>, opts?: SanitizerOptions): Record<string, unknown>;
|
|
1318
|
-
|
|
1319
|
-
interface ColumnValidator {
|
|
1320
|
-
validateWrite(table: string, row: Record<string, unknown>): Record<string, unknown>;
|
|
1321
|
-
validateRead(table: string, columns: string[]): void;
|
|
1322
|
-
invalidateCache(table: string): void;
|
|
1323
|
-
}
|
|
1324
|
-
/**
|
|
1325
|
-
* Validates column names against the live SQLite schema.
|
|
1326
|
-
*
|
|
1327
|
-
* - validateWrite: strips unknown columns silently
|
|
1328
|
-
* - validateRead: throws on unknown columns
|
|
1329
|
-
*/
|
|
1330
|
-
declare class ColumnValidatorImpl implements ColumnValidator {
|
|
1331
|
-
private readonly db;
|
|
1332
|
-
constructor(db: DataStore);
|
|
1333
|
-
private getValidColumns;
|
|
1334
|
-
validateWrite(table: string, row: Record<string, unknown>): Record<string, unknown>;
|
|
1335
|
-
validateRead(table: string, columns: string[]): void;
|
|
1336
|
-
invalidateCache(_table: string): void;
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
interface AuditEmitterOptions {
|
|
1340
|
-
auditTables?: string[];
|
|
1341
|
-
}
|
|
1342
|
-
/**
|
|
1343
|
-
* Emits audit events via the HookBus for tracked tables.
|
|
1344
|
-
*
|
|
1345
|
-
* - auditTables defaults to [] (nothing audited)
|
|
1346
|
-
* - '*' wildcard audits all tables
|
|
1347
|
-
* - emit is fire-and-forget — errors are swallowed, no awaiting
|
|
1348
|
-
*/
|
|
1349
|
-
declare class AuditEmitter {
|
|
1350
|
-
private readonly hooks;
|
|
1351
|
-
private readonly auditTables;
|
|
1352
|
-
constructor(hooks: HookBus, opts?: AuditEmitterOptions);
|
|
1353
|
-
shouldAudit(table: string): boolean;
|
|
1354
|
-
emit(event: AuditEvent): void;
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
/**
|
|
1358
|
-
* Build a clean environment for spawned subprocesses.
|
|
1359
|
-
* Strips secrets and passes only safe system variables.
|
|
1360
|
-
* Used by the CLI execution adapter when spawning agent processes.
|
|
1361
|
-
*/
|
|
1362
|
-
/**
|
|
1363
|
-
* Build a filtered environment for subprocess execution.
|
|
1364
|
-
* Only passes explicitly allowed variables — all secrets are stripped.
|
|
1365
|
-
*
|
|
1366
|
-
* @param allowedKeys - Additional keys to allow beyond the defaults
|
|
1367
|
-
* @param inject - Extra key-value pairs to inject into the env
|
|
1368
|
-
*/
|
|
1369
|
-
declare function buildProcessEnv(allowedKeys?: string[], inject?: Record<string, string>): Record<string, string>;
|
|
1370
|
-
|
|
1371
|
-
interface PackageUpdate {
|
|
1372
|
-
name: string;
|
|
1373
|
-
installedVersion: string;
|
|
1374
|
-
latestVersion: string;
|
|
1375
|
-
updateType: 'patch' | 'minor' | 'major';
|
|
1376
|
-
}
|
|
1377
|
-
interface UpdateManifest {
|
|
1378
|
-
checkedAt: string;
|
|
1379
|
-
packages: PackageUpdate[];
|
|
1380
|
-
hasUpdates: boolean;
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
/**
|
|
1384
|
-
* Simple semver utilities — no external deps.
|
|
1385
|
-
*/
|
|
1386
|
-
declare function parseVersion(v: string): [number, number, number];
|
|
1387
|
-
declare function compareVersions(a: string, b: string): -1 | 0 | 1;
|
|
1388
|
-
declare function classifyUpdate(from: string, to: string): 'patch' | 'minor' | 'major' | 'none';
|
|
1389
|
-
|
|
1390
|
-
declare class UpdateChecker {
|
|
1391
|
-
private nodeModulesPath;
|
|
1392
|
-
private opts?;
|
|
1393
|
-
private readonly fetchFn;
|
|
1394
|
-
constructor(nodeModulesPath: string, opts?: {
|
|
1395
|
-
fetch?: typeof globalThis.fetch;
|
|
1396
|
-
} | undefined);
|
|
1397
|
-
getInstalledPackages(): string[];
|
|
1398
|
-
check(packageNames?: string[]): Promise<UpdateManifest>;
|
|
1399
|
-
}
|
|
1400
|
-
|
|
1401
|
-
declare class BackupManager {
|
|
1402
|
-
private projectRoot;
|
|
1403
|
-
constructor(projectRoot: string);
|
|
1404
|
-
backup(): Promise<string>;
|
|
1405
|
-
restore(backupPath: string): Promise<void>;
|
|
1406
|
-
cleanup(backupPath: string): Promise<void>;
|
|
1407
|
-
}
|
|
1408
|
-
|
|
1409
|
-
type UpdatePolicy = 'auto-all' | 'auto-compatible' | 'auto-patch' | 'notify' | 'manual';
|
|
1410
|
-
declare class UpdateManager {
|
|
1411
|
-
private checker;
|
|
1412
|
-
private db;
|
|
1413
|
-
private hooks;
|
|
1414
|
-
private opts?;
|
|
1415
|
-
private backupManager;
|
|
1416
|
-
constructor(checker: UpdateChecker, db: DataStore, hooks: HookBus, opts?: {
|
|
1417
|
-
projectRoot?: string;
|
|
1418
|
-
policy?: UpdatePolicy;
|
|
1419
|
-
maintenanceWindow?: {
|
|
1420
|
-
utcHourStart: number;
|
|
1421
|
-
utcHourEnd: number;
|
|
1422
|
-
};
|
|
1423
|
-
} | undefined);
|
|
1424
|
-
checkAndNotify(): Promise<UpdateManifest>;
|
|
1425
|
-
applyUpdates(updates: PackageUpdate[]): Promise<void>;
|
|
1426
|
-
isInMaintenanceWindow(): boolean;
|
|
1427
|
-
filterByPolicy(updates: PackageUpdate[]): PackageUpdate[];
|
|
1428
|
-
}
|
|
1429
|
-
|
|
1430
|
-
interface PackageMigration {
|
|
1431
|
-
version: string;
|
|
1432
|
-
package: string;
|
|
1433
|
-
sql: string;
|
|
1434
|
-
}
|
|
1435
|
-
/**
|
|
1436
|
-
* Runs package migrations using the __lattice_migrations table for tracking.
|
|
1437
|
-
* Each migration is keyed by "{package}:{version}" to ensure idempotency.
|
|
1438
|
-
*/
|
|
1439
|
-
declare function runPackageMigrations(db: DataStore, migrations: PackageMigration[]): Promise<void>;
|
|
1440
|
-
|
|
1441
|
-
interface UpdateResult {
|
|
1442
|
-
updated: boolean;
|
|
1443
|
-
packages: Array<{
|
|
1444
|
-
name: string;
|
|
1445
|
-
from: string;
|
|
1446
|
-
to: string;
|
|
1447
|
-
}>;
|
|
1448
|
-
restartRequired: boolean;
|
|
1449
|
-
}
|
|
1450
|
-
/**
|
|
1451
|
-
* Check npm for newer versions of framework packages and install them.
|
|
1452
|
-
* Returns what was updated. Safe to call on every startup — skips if
|
|
1453
|
-
* already on latest.
|
|
1454
|
-
*
|
|
1455
|
-
* @param packages - Package names to check (default: botinabox + latticesql)
|
|
1456
|
-
* @param opts.quiet - Suppress console output (default: false)
|
|
1457
|
-
*/
|
|
1458
|
-
declare function autoUpdate(packages?: string[], opts?: {
|
|
1459
|
-
quiet?: boolean;
|
|
1460
|
-
}): Promise<UpdateResult>;
|
|
1461
|
-
|
|
1462
|
-
declare class BudgetController {
|
|
1463
|
-
private db;
|
|
1464
|
-
private hooks;
|
|
1465
|
-
constructor(db: DataStore, hooks: HookBus);
|
|
1466
|
-
checkBudget(agentId: string): Promise<{
|
|
1467
|
-
allowed: boolean;
|
|
1468
|
-
reason?: string;
|
|
1469
|
-
currentSpendCents: number;
|
|
1470
|
-
limitCents: number;
|
|
1471
|
-
}>;
|
|
1472
|
-
resetMonthlySpend(agentId: string): Promise<void>;
|
|
1473
|
-
globalCheck(): Promise<{
|
|
1474
|
-
allowed: boolean;
|
|
1475
|
-
totalSpentCents: number;
|
|
1476
|
-
limitCents: number;
|
|
1477
|
-
}>;
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
interface WorkflowStep {
|
|
1481
|
-
id: string;
|
|
1482
|
-
name: string;
|
|
1483
|
-
agentSlug?: string;
|
|
1484
|
-
taskTemplate: {
|
|
1485
|
-
title: string;
|
|
1486
|
-
description: string;
|
|
1487
|
-
};
|
|
1488
|
-
dependsOn?: string[];
|
|
1489
|
-
onComplete?: 'next' | 'parallel' | 'end';
|
|
1490
|
-
onFail?: 'abort' | 'skip' | 'retry';
|
|
1491
|
-
}
|
|
1492
|
-
interface WorkflowDefinition {
|
|
1493
|
-
name: string;
|
|
1494
|
-
description?: string;
|
|
1495
|
-
steps: WorkflowStep[];
|
|
1496
|
-
trigger?: {
|
|
1497
|
-
type: 'task_completed' | 'event' | 'schedule' | 'manual';
|
|
1498
|
-
filter?: Record<string, unknown>;
|
|
1499
|
-
};
|
|
1500
|
-
}
|
|
1501
|
-
declare class WorkflowEngine {
|
|
1502
|
-
private db;
|
|
1503
|
-
private hooks;
|
|
1504
|
-
private taskQueue;
|
|
1505
|
-
constructor(db: DataStore, hooks: HookBus, taskQueue: TaskQueue);
|
|
1506
|
-
/**
|
|
1507
|
-
* Define/register a workflow.
|
|
1508
|
-
*/
|
|
1509
|
-
define(slug: string, def: WorkflowDefinition): Promise<void>;
|
|
1510
|
-
/**
|
|
1511
|
-
* Start a workflow run.
|
|
1512
|
-
*/
|
|
1513
|
-
start(workflowSlug: string, context: Record<string, unknown>): Promise<string>;
|
|
1514
|
-
/**
|
|
1515
|
-
* Called when a task with workflow_run_id completes.
|
|
1516
|
-
*/
|
|
1517
|
-
onStepCompleted(taskId: string, output: string): Promise<void>;
|
|
1518
|
-
/**
|
|
1519
|
-
* Mark a workflow run as failed.
|
|
1520
|
-
*/
|
|
1521
|
-
onStepFailed(taskId: string, error: string): Promise<void>;
|
|
1522
|
-
private _createStepTask;
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
declare class WakeupQueue {
|
|
1526
|
-
private db;
|
|
1527
|
-
constructor(db: DataStore);
|
|
1528
|
-
enqueue(agentId: string, source: string, context?: Record<string, unknown>): Promise<string>;
|
|
1529
|
-
coalesce(agentId: string, context?: Record<string, unknown>): Promise<void>;
|
|
1530
|
-
getNext(agentId: string): Promise<Record<string, unknown> | undefined>;
|
|
1531
|
-
markFired(wakeupId: string, runId: string): Promise<void>;
|
|
1532
|
-
}
|
|
1533
|
-
|
|
1534
|
-
declare class SessionManager {
|
|
1535
|
-
private db;
|
|
1536
|
-
constructor(db: DataStore);
|
|
1537
|
-
save(agentId: string, channelId: string, peerId: string, params: Record<string, unknown>): Promise<string>;
|
|
1538
|
-
load(agentId: string, channelId: string, peerId: string): Promise<Record<string, unknown> | undefined>;
|
|
1539
|
-
clear(agentId: string, channelId: string, peerId: string): Promise<void>;
|
|
1540
|
-
shouldClear(session: Record<string, unknown>, opts: {
|
|
1541
|
-
maxRuns?: number;
|
|
1542
|
-
maxAgeHours?: number;
|
|
1543
|
-
}): Promise<boolean>;
|
|
1544
|
-
private _find;
|
|
1545
|
-
}
|
|
1546
|
-
|
|
1547
|
-
declare class NdjsonLogger {
|
|
1548
|
-
private logPath;
|
|
1549
|
-
constructor(logPath: string);
|
|
1550
|
-
log(stream: 'stdout' | 'stderr', chunk: string): void;
|
|
1551
|
-
close(): void;
|
|
1552
|
-
}
|
|
1553
|
-
|
|
1554
|
-
/**
|
|
1555
|
-
* Scheduler — database-backed job scheduling with cron expressions.
|
|
1556
|
-
*
|
|
1557
|
-
* Supports one-time and recurring schedules. When a schedule fires,
|
|
1558
|
-
* it emits the schedule's `action` as a hook event with the
|
|
1559
|
-
* `action_config` payload. Consumers subscribe to handle the action.
|
|
1560
|
-
*
|
|
1561
|
-
* Supports one-time and recurring use cases.
|
|
1562
|
-
*/
|
|
1563
|
-
|
|
1564
|
-
interface ScheduleDef {
|
|
1565
|
-
name: string;
|
|
1566
|
-
description?: string;
|
|
1567
|
-
/** Cron expression for recurring schedules */
|
|
1568
|
-
cron?: string;
|
|
1569
|
-
/** ISO 8601 datetime for one-time schedules */
|
|
1570
|
-
runAt?: string;
|
|
1571
|
-
/** Hook event name to emit when fired */
|
|
1572
|
-
action: string;
|
|
1573
|
-
/** JSON-serializable payload passed to the hook */
|
|
1574
|
-
actionConfig?: Record<string, unknown>;
|
|
1575
|
-
timezone?: string;
|
|
1576
|
-
}
|
|
1577
|
-
interface Schedule {
|
|
1578
|
-
id: string;
|
|
1579
|
-
name: string;
|
|
1580
|
-
description: string | null;
|
|
1581
|
-
type: "one_time" | "recurring";
|
|
1582
|
-
cron: string | null;
|
|
1583
|
-
run_at: string | null;
|
|
1584
|
-
timezone: string;
|
|
1585
|
-
enabled: number;
|
|
1586
|
-
action: string;
|
|
1587
|
-
action_config: string;
|
|
1588
|
-
last_fired_at: string | null;
|
|
1589
|
-
next_fire_at: string | null;
|
|
1590
|
-
created_at: string;
|
|
1591
|
-
updated_at: string;
|
|
1592
|
-
deleted_at: string | null;
|
|
1593
|
-
}
|
|
1594
|
-
declare class Scheduler {
|
|
1595
|
-
private db;
|
|
1596
|
-
private hooks;
|
|
1597
|
-
private timer;
|
|
1598
|
-
constructor(db: DataStore, hooks: HookBus);
|
|
1599
|
-
/**
|
|
1600
|
-
* Start the scheduler. Computes initial next_fire_at for schedules
|
|
1601
|
-
* that don't have one, then polls for due schedules.
|
|
1602
|
-
*/
|
|
1603
|
-
start(pollIntervalMs?: number): Promise<void>;
|
|
1604
|
-
stop(): void;
|
|
1605
|
-
/** Check for and fire due schedules. */
|
|
1606
|
-
tick(): Promise<void>;
|
|
1607
|
-
/** Register a new schedule. */
|
|
1608
|
-
register(def: ScheduleDef): Promise<string>;
|
|
1609
|
-
/** Update an existing schedule. */
|
|
1610
|
-
update(id: string, changes: Partial<Pick<ScheduleDef, "name" | "cron" | "runAt" | "action" | "actionConfig" | "timezone" | "description">> & {
|
|
1611
|
-
enabled?: boolean;
|
|
1612
|
-
}): Promise<void>;
|
|
1613
|
-
/** Soft-delete a schedule. */
|
|
1614
|
-
unregister(id: string): Promise<void>;
|
|
1615
|
-
/** List schedules, optionally filtered. */
|
|
1616
|
-
list(filter?: {
|
|
1617
|
-
enabled?: boolean;
|
|
1618
|
-
action?: string;
|
|
1619
|
-
}): Promise<Schedule[]>;
|
|
1620
|
-
/** Compute next_fire_at for any enabled schedule missing it. */
|
|
1621
|
-
private initializeNextFireTimes;
|
|
1622
|
-
}
|
|
1623
|
-
|
|
1624
|
-
/**
|
|
1625
|
-
* Creates a config revision record with before/after snapshots.
|
|
1626
|
-
* Note: uses config_revisions table with config_yaml storing JSON of {agentId, before, after}.
|
|
1627
|
-
*/
|
|
1628
|
-
declare function createConfigRevision(db: DataStore, agentId: string, before: Record<string, unknown>, after: Record<string, unknown>): Promise<void>;
|
|
1629
|
-
|
|
1630
|
-
/**
|
|
1631
|
-
* Dependency resolution utilities for workflow steps and task deps.
|
|
1632
|
-
*/
|
|
1633
|
-
interface StepRef {
|
|
1634
|
-
id: string;
|
|
1635
|
-
dependsOn?: string[];
|
|
1636
|
-
}
|
|
1637
|
-
/**
|
|
1638
|
-
* DFS cycle detection — returns true if cycle exists.
|
|
1639
|
-
*/
|
|
1640
|
-
declare function detectCycle(steps: StepRef[]): boolean;
|
|
1641
|
-
/**
|
|
1642
|
-
* Returns step IDs in topological (execution) order.
|
|
1643
|
-
* Throws if a cycle is detected.
|
|
1644
|
-
*/
|
|
1645
|
-
declare function topologicalSort(steps: StepRef[]): string[];
|
|
1646
|
-
/**
|
|
1647
|
-
* Returns true if all dependencies are satisfied (present in completedTaskIds).
|
|
1648
|
-
*/
|
|
1649
|
-
declare function areDependenciesMet(taskDepsJson: string | undefined, completedTaskIds: Set<string>): boolean;
|
|
1650
|
-
|
|
1651
|
-
/**
|
|
1652
|
-
* Simple template interpolation for workflow step templates.
|
|
1653
|
-
* Supports {{key}} and {{steps.stepId.output}} patterns.
|
|
1654
|
-
*/
|
|
1655
|
-
declare function interpolate(template: string, context: Record<string, unknown>): string;
|
|
1656
|
-
|
|
1657
|
-
declare class ApiExecutionAdapter {
|
|
1658
|
-
private modelRouter;
|
|
1659
|
-
readonly type = "api";
|
|
1660
|
-
constructor(modelRouter: ModelRouter);
|
|
1661
|
-
execute(ctx: {
|
|
1662
|
-
agent: {
|
|
1663
|
-
id: string;
|
|
1664
|
-
model?: string;
|
|
1665
|
-
adapter_config?: string;
|
|
1666
|
-
};
|
|
1667
|
-
task: {
|
|
1668
|
-
description?: string;
|
|
1669
|
-
context?: string;
|
|
1670
|
-
};
|
|
1671
|
-
sessionParams?: {
|
|
1672
|
-
history?: ChatMessage[];
|
|
1673
|
-
};
|
|
1674
|
-
contextFiles?: string[];
|
|
1675
|
-
abortSignal?: AbortSignal;
|
|
1676
|
-
onLog?: (stream: 'stdout' | 'stderr', chunk: string) => void;
|
|
1677
|
-
}): Promise<{
|
|
1678
|
-
output: string;
|
|
1679
|
-
exitCode: number;
|
|
1680
|
-
usage: TokenUsage & {
|
|
1681
|
-
provider: string;
|
|
1682
|
-
model: string;
|
|
1683
|
-
};
|
|
1684
|
-
sessionParams: {
|
|
1685
|
-
history: ChatMessage[];
|
|
1686
|
-
};
|
|
1687
|
-
}>;
|
|
1688
|
-
}
|
|
1689
|
-
|
|
1690
|
-
/**
|
|
1691
|
-
* Inputs to the CLI argument builder. Kept as a separate type so the
|
|
1692
|
-
* pure arg-construction function is unit-testable without spawning a process.
|
|
1693
|
-
*/
|
|
1694
|
-
interface CliArgBuildInput {
|
|
1695
|
-
prompt: string;
|
|
1696
|
-
skipPermissions?: boolean;
|
|
1697
|
-
sessionId?: string;
|
|
1698
|
-
settings?: string;
|
|
1699
|
-
appendSystemPrompt?: string;
|
|
1700
|
-
addDirs?: string[];
|
|
1701
|
-
extraArgs?: string[];
|
|
1702
|
-
}
|
|
1703
|
-
/**
|
|
1704
|
-
* Build the argv array passed to the `claude` binary.
|
|
1705
|
-
*
|
|
1706
|
-
* Order matters for the `claude` CLI: flags come first, then `--print` with
|
|
1707
|
-
* the prompt as the final positional argument. This function exists so the
|
|
1708
|
-
* argv shape can be asserted in tests without a real subprocess.
|
|
1709
|
-
*/
|
|
1710
|
-
declare function buildCliArgs(input: CliArgBuildInput): string[];
|
|
1711
|
-
declare class CliExecutionAdapter {
|
|
1712
|
-
readonly type = "cli";
|
|
1713
|
-
execute(ctx: {
|
|
1714
|
-
agent: {
|
|
1715
|
-
id: string;
|
|
1716
|
-
cwd?: string;
|
|
1717
|
-
adapter_config?: string;
|
|
1718
|
-
skip_permissions?: boolean;
|
|
1719
|
-
};
|
|
1720
|
-
task: {
|
|
1721
|
-
title: string;
|
|
1722
|
-
description?: string;
|
|
1723
|
-
context?: string;
|
|
1724
|
-
};
|
|
1725
|
-
/**
|
|
1726
|
-
* Optional Claude Code session UUID. When provided, passed as `--session-id`
|
|
1727
|
-
* so the same UUID on subsequent calls resumes the same conversation.
|
|
1728
|
-
* Callers typically derive this deterministically from a stable conversation
|
|
1729
|
-
* key (e.g. thread identifier) so multi-turn exchanges maintain history.
|
|
1730
|
-
*/
|
|
1731
|
-
sessionId?: string;
|
|
1732
|
-
/**
|
|
1733
|
-
* Value for `--settings`. Accepts a JSON string or a path to a settings
|
|
1734
|
-
* file. Use this to override settings like `autoMemoryDirectory` without
|
|
1735
|
-
* mutating the caller's global config.
|
|
1736
|
-
*/
|
|
1737
|
-
settings?: string;
|
|
1738
|
-
/** Value for `--append-system-prompt`. */
|
|
1739
|
-
appendSystemPrompt?: string;
|
|
1740
|
-
/** Additional directories passed via `--add-dir`. */
|
|
1741
|
-
addDirs?: string[];
|
|
1742
|
-
/** Extra CLI flags appended before the positional prompt. */
|
|
1743
|
-
extraArgs?: string[];
|
|
1744
|
-
logPath?: string;
|
|
1745
|
-
onLog?: (stream: string, chunk: string) => void;
|
|
1746
|
-
abortSignal?: AbortSignal;
|
|
1747
|
-
}): Promise<{
|
|
1748
|
-
output: string;
|
|
1749
|
-
exitCode: number;
|
|
1750
|
-
}>;
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
|
-
/**
|
|
1754
|
-
* DeterministicAdapter — executes scripts without LLM calls.
|
|
1755
|
-
* Story 6.1
|
|
1756
|
-
*
|
|
1757
|
-
* For tasks that don't require reasoning: routing, validation,
|
|
1758
|
-
* data fetching, file transforms. Runs a user-specified command
|
|
1759
|
-
* (Python, Node, bash) as a subprocess with task context on stdin.
|
|
1760
|
-
*/
|
|
1761
|
-
interface DeterministicConfig {
|
|
1762
|
-
command: string;
|
|
1763
|
-
args?: string[];
|
|
1764
|
-
env?: Record<string, string>;
|
|
1765
|
-
timeoutMs?: number;
|
|
1766
|
-
inputMode?: 'stdin' | 'arg';
|
|
1767
|
-
}
|
|
1768
|
-
declare class DeterministicAdapter {
|
|
1769
|
-
readonly type = "deterministic";
|
|
1770
|
-
execute(ctx: {
|
|
1771
|
-
agent: {
|
|
1772
|
-
id: string;
|
|
1773
|
-
cwd?: string;
|
|
1774
|
-
adapter_config?: string;
|
|
1775
|
-
};
|
|
1776
|
-
task: {
|
|
1777
|
-
title: string;
|
|
1778
|
-
description?: string;
|
|
1779
|
-
context?: string;
|
|
1780
|
-
};
|
|
1781
|
-
abortSignal?: AbortSignal;
|
|
1782
|
-
onLog?: (stream: string, chunk: string) => void;
|
|
1783
|
-
}): Promise<{
|
|
1784
|
-
output: string;
|
|
1785
|
-
exitCode: number;
|
|
1786
|
-
}>;
|
|
1787
|
-
}
|
|
1788
|
-
|
|
1789
|
-
/**
|
|
1790
|
-
* LoopDetector — pattern-based loop detection for agent routing.
|
|
1791
|
-
* Story 6.2
|
|
1792
|
-
*
|
|
1793
|
-
* Complements chain-guard's depth limit with active pattern detection:
|
|
1794
|
-
* - Self-loop: agent routes a task back to itself
|
|
1795
|
-
* - Ping-pong: two agents bounce tasks between each other (A→B→A→B)
|
|
1796
|
-
* - Blocked re-entry: a task re-enters the system after being blocked
|
|
1797
|
-
*/
|
|
1798
|
-
|
|
1799
|
-
declare enum LoopType {
|
|
1800
|
-
SELF_LOOP = "self_loop",
|
|
1801
|
-
PING_PONG = "ping_pong",
|
|
1802
|
-
BLOCKED_REENTRY = "blocked_reentry"
|
|
1803
|
-
}
|
|
1804
|
-
interface LoopDetection {
|
|
1805
|
-
type: LoopType;
|
|
1806
|
-
agents: string[];
|
|
1807
|
-
taskId: string;
|
|
1808
|
-
chainOriginId?: string;
|
|
1809
|
-
message: string;
|
|
1810
|
-
}
|
|
1811
|
-
interface LoopDetectorConfig {
|
|
1812
|
-
/** Number of recent followup records to scan. Default: 10 */
|
|
1813
|
-
windowSize?: number;
|
|
1814
|
-
/** Minimum repetitions to confirm ping-pong. Default: 2 */
|
|
1815
|
-
pingPongThreshold?: number;
|
|
1816
|
-
}
|
|
1817
|
-
declare class LoopDetector {
|
|
1818
|
-
private db;
|
|
1819
|
-
private readonly windowSize;
|
|
1820
|
-
private readonly pingPongThreshold;
|
|
1821
|
-
constructor(db: DataStore, config?: LoopDetectorConfig);
|
|
1822
|
-
/**
|
|
1823
|
-
* Check for loops before creating a followup task.
|
|
1824
|
-
* Returns a LoopDetection if a loop pattern is found, undefined otherwise.
|
|
1825
|
-
*/
|
|
1826
|
-
check(sourceAgentId: string, targetAgentId: string, taskId: string, chainOriginId?: string): Promise<LoopDetection | undefined>;
|
|
1827
|
-
/**
|
|
1828
|
-
* Check if an agent is routing to itself.
|
|
1829
|
-
*/
|
|
1830
|
-
private checkSelfLoop;
|
|
1831
|
-
/**
|
|
1832
|
-
* Check if a previously blocked task is being re-entered.
|
|
1833
|
-
*/
|
|
1834
|
-
private checkBlockedReentry;
|
|
1835
|
-
/**
|
|
1836
|
-
* Check for A→B→A→B ping-pong by scanning recent tasks in the chain.
|
|
1837
|
-
*/
|
|
1838
|
-
private checkPingPong;
|
|
1839
|
-
}
|
|
1840
|
-
|
|
1841
|
-
/**
|
|
1842
|
-
* LearningPipeline — turns execution experience into durable knowledge.
|
|
1843
|
-
* Story 6.5
|
|
1844
|
-
*
|
|
1845
|
-
* Promotion ladder:
|
|
1846
|
-
* Execution → Feedback (structured capture)
|
|
1847
|
-
* → 3+ similar → Playbook (generalized rule)
|
|
1848
|
-
* → 3+ projects → Skill (executable behavior)
|
|
1849
|
-
* → Agent-Skill Matrix → Per-Agent Context
|
|
1850
|
-
*
|
|
1851
|
-
* Two-axis evaluation:
|
|
1852
|
-
* - Accuracy: was the output correct?
|
|
1853
|
-
* - Efficiency: how fast / how many tokens?
|
|
1854
|
-
*/
|
|
1855
|
-
|
|
1856
|
-
interface FeedbackEntry {
|
|
1857
|
-
agentId: string;
|
|
1858
|
-
userId?: string;
|
|
1859
|
-
taskId?: string;
|
|
1860
|
-
issue: string;
|
|
1861
|
-
rootCause?: string;
|
|
1862
|
-
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
1863
|
-
repeatable: boolean;
|
|
1864
|
-
accuracyScore?: number;
|
|
1865
|
-
efficiencyScore?: number;
|
|
1866
|
-
tags?: string[];
|
|
1867
|
-
}
|
|
1868
|
-
interface PlaybookEntry {
|
|
1869
|
-
pattern: string;
|
|
1870
|
-
rule: string;
|
|
1871
|
-
feedbackIds: string[];
|
|
1872
|
-
projectScoped: boolean;
|
|
1873
|
-
clientId?: string;
|
|
1874
|
-
agentIds?: string[];
|
|
1875
|
-
}
|
|
1876
|
-
interface SkillEntry {
|
|
1877
|
-
name: string;
|
|
1878
|
-
slug: string;
|
|
1879
|
-
description?: string;
|
|
1880
|
-
behavior: string;
|
|
1881
|
-
sourcePlaybookIds: string[];
|
|
1882
|
-
category?: string;
|
|
1883
|
-
}
|
|
1884
|
-
interface LearningPipelineConfig {
|
|
1885
|
-
/** Feedback count threshold for playbook promotion. Default: 3 */
|
|
1886
|
-
playbookThreshold?: number;
|
|
1887
|
-
/** Project count threshold for skill promotion. Default: 3 */
|
|
1888
|
-
skillThreshold?: number;
|
|
1889
|
-
/** Auto-promote when thresholds are met. Default: false */
|
|
1890
|
-
autoPromote?: boolean;
|
|
1891
|
-
}
|
|
1892
|
-
declare class LearningPipeline {
|
|
1893
|
-
private db;
|
|
1894
|
-
private hooks;
|
|
1895
|
-
private readonly playbookThreshold;
|
|
1896
|
-
private readonly skillThreshold;
|
|
1897
|
-
private readonly autoPromote;
|
|
1898
|
-
constructor(db: DataStore, hooks: HookBus, config?: LearningPipelineConfig);
|
|
1899
|
-
/**
|
|
1900
|
-
* Capture a structured feedback record from an execution.
|
|
1901
|
-
*/
|
|
1902
|
-
captureFeedback(entry: FeedbackEntry): Promise<string>;
|
|
1903
|
-
/**
|
|
1904
|
-
* Get all feedback records, optionally filtered.
|
|
1905
|
-
*/
|
|
1906
|
-
listFeedback(filter?: {
|
|
1907
|
-
agentId?: string;
|
|
1908
|
-
userId?: string;
|
|
1909
|
-
severity?: string;
|
|
1910
|
-
repeatable?: boolean;
|
|
1911
|
-
}): Promise<Array<Record<string, unknown>>>;
|
|
1912
|
-
/**
|
|
1913
|
-
* Check if feedback records with similar issues should be promoted to a playbook.
|
|
1914
|
-
* Groups by issue text similarity (exact match for now).
|
|
1915
|
-
*/
|
|
1916
|
-
checkPlaybookPromotion(issue: string): Promise<string | undefined>;
|
|
1917
|
-
/**
|
|
1918
|
-
* Manually create a playbook from a set of feedback records.
|
|
1919
|
-
*/
|
|
1920
|
-
promoteToPlaybook(entry: PlaybookEntry): Promise<string>;
|
|
1921
|
-
/**
|
|
1922
|
-
* List playbooks, optionally filtered.
|
|
1923
|
-
*/
|
|
1924
|
-
listPlaybooks(filter?: {
|
|
1925
|
-
projectScoped?: boolean;
|
|
1926
|
-
}): Promise<Array<Record<string, unknown>>>;
|
|
1927
|
-
/**
|
|
1928
|
-
* Check if a playbook should be promoted to a skill.
|
|
1929
|
-
* A playbook becomes a skill when it works across multiple projects
|
|
1930
|
-
* (indicated by being referenced by agents in different contexts).
|
|
1931
|
-
*/
|
|
1932
|
-
checkSkillPromotion(playbookId: string): Promise<string | undefined>;
|
|
1933
|
-
/**
|
|
1934
|
-
* Manually promote a playbook to a reusable skill.
|
|
1935
|
-
*/
|
|
1936
|
-
promoteToSkill(entry: SkillEntry): Promise<string>;
|
|
1937
|
-
/**
|
|
1938
|
-
* Assign a skill to an agent.
|
|
1939
|
-
*/
|
|
1940
|
-
assignSkill(agentId: string, skillId: string): Promise<void>;
|
|
1941
|
-
/**
|
|
1942
|
-
* Get learning metrics for an agent.
|
|
1943
|
-
*/
|
|
1944
|
-
getMetrics(agentId: string): Promise<{
|
|
1945
|
-
feedbackCount: number;
|
|
1946
|
-
avgAccuracy: number | null;
|
|
1947
|
-
avgEfficiency: number | null;
|
|
1948
|
-
playbookCount: number;
|
|
1949
|
-
skillCount: number;
|
|
1950
|
-
}>;
|
|
1951
|
-
}
|
|
1952
|
-
|
|
1953
|
-
/**
|
|
1954
|
-
* PermissionRelay — remote approval for unattended agent execution.
|
|
1955
|
-
* Story 6.6
|
|
1956
|
-
*
|
|
1957
|
-
* When an agent needs human approval but the operator is away:
|
|
1958
|
-
* 1. Post the approval prompt to a messaging platform (Slack, Discord, etc.)
|
|
1959
|
-
* 2. Poll for response (approve/deny)
|
|
1960
|
-
* 3. Relay the decision back to the agent
|
|
1961
|
-
*
|
|
1962
|
-
* Dual approval: local terminal + remote messaging. First response wins.
|
|
1963
|
-
* Race condition handled by atomic state transition.
|
|
1964
|
-
*/
|
|
1965
|
-
|
|
1966
|
-
type ApprovalStatus = 'pending' | 'approved' | 'denied' | 'expired';
|
|
1967
|
-
interface PermissionPrompt {
|
|
1968
|
-
id: string;
|
|
1969
|
-
agentId: string;
|
|
1970
|
-
action: string;
|
|
1971
|
-
context?: string;
|
|
1972
|
-
requestedAt: string;
|
|
1973
|
-
expiresAt?: string;
|
|
1974
|
-
}
|
|
1975
|
-
interface ApprovalResponse {
|
|
1976
|
-
promptId: string;
|
|
1977
|
-
status: 'approved' | 'denied';
|
|
1978
|
-
respondedBy: string;
|
|
1979
|
-
respondedAt: string;
|
|
1980
|
-
comment?: string;
|
|
1981
|
-
}
|
|
1982
|
-
/**
|
|
1983
|
-
* Provider interface — implement for each messaging platform.
|
|
1984
|
-
*/
|
|
1985
|
-
interface PermissionProvider {
|
|
1986
|
-
readonly id: string;
|
|
1987
|
-
/** Post an approval request, return a handle for polling. */
|
|
1988
|
-
sendPrompt(prompt: PermissionPrompt): Promise<string>;
|
|
1989
|
-
/** Check for a response. Returns undefined if still pending. */
|
|
1990
|
-
pollResponse(handle: string): Promise<ApprovalResponse | undefined>;
|
|
1991
|
-
/** Cancel a pending prompt (e.g. after local approval). */
|
|
1992
|
-
cancelPrompt(handle: string): Promise<void>;
|
|
1993
|
-
}
|
|
1994
|
-
interface PermissionRelayConfig {
|
|
1995
|
-
/** Registered providers (e.g. Slack, Discord adapters) */
|
|
1996
|
-
providers: PermissionProvider[];
|
|
1997
|
-
/** Poll interval in ms. Default: 5000 */
|
|
1998
|
-
pollIntervalMs?: number;
|
|
1999
|
-
/** Timeout for pending approvals in ms. Default: 300_000 (5 min) */
|
|
2000
|
-
timeoutMs?: number;
|
|
2001
|
-
}
|
|
2002
|
-
declare class PermissionRelay {
|
|
2003
|
-
private hooks;
|
|
2004
|
-
private readonly providers;
|
|
2005
|
-
private readonly pollIntervalMs;
|
|
2006
|
-
private readonly timeoutMs;
|
|
2007
|
-
private readonly pending;
|
|
2008
|
-
constructor(hooks: HookBus, config: PermissionRelayConfig);
|
|
2009
|
-
/**
|
|
2010
|
-
* Request approval from all configured providers.
|
|
2011
|
-
* Returns when the first provider responds (approve or deny).
|
|
2012
|
-
*/
|
|
2013
|
-
requestApproval(prompt: PermissionPrompt): Promise<ApprovalResponse>;
|
|
2014
|
-
/**
|
|
2015
|
-
* Provide a local approval (from terminal).
|
|
2016
|
-
* Resolves the pending request and cancels remote providers.
|
|
2017
|
-
*/
|
|
2018
|
-
approveLocally(promptId: string, approved: boolean): Promise<void>;
|
|
2019
|
-
/**
|
|
2020
|
-
* Get all pending approval requests.
|
|
2021
|
-
*/
|
|
2022
|
-
getPending(): PermissionPrompt[];
|
|
2023
|
-
private cancelOtherProviders;
|
|
2024
|
-
}
|
|
2025
|
-
|
|
2026
|
-
/**
|
|
2027
|
-
* GovernanceGate — independent validation gates for agent output.
|
|
2028
|
-
* Story 6.7
|
|
2029
|
-
*
|
|
2030
|
-
* Key principle: gates report to the HUMAN, not to each other
|
|
2031
|
-
* or to a project manager agent. Structural independence prevents capture.
|
|
2032
|
-
*
|
|
2033
|
-
* Gate dimensions:
|
|
2034
|
-
* QA — data correctness (schema, row counts, format)
|
|
2035
|
-
* Quality — code quality (lint, coverage, patterns)
|
|
2036
|
-
* Drift — architectural drift (unintended dependencies, scope creep)
|
|
2037
|
-
*/
|
|
2038
|
-
|
|
2039
|
-
type GateVerdict = 'pass' | 'fail' | 'warn';
|
|
2040
|
-
interface GateResult {
|
|
2041
|
-
gateId: string;
|
|
2042
|
-
verdict: GateVerdict;
|
|
2043
|
-
findings: GateFinding[];
|
|
2044
|
-
checkedAt: string;
|
|
2045
|
-
durationMs: number;
|
|
2046
|
-
}
|
|
2047
|
-
interface GateFinding {
|
|
2048
|
-
severity: 'info' | 'warning' | 'error' | 'critical';
|
|
2049
|
-
message: string;
|
|
2050
|
-
location?: string;
|
|
2051
|
-
suggestion?: string;
|
|
2052
|
-
}
|
|
2053
|
-
interface GateInput {
|
|
2054
|
-
agentId: string;
|
|
2055
|
-
taskId: string;
|
|
2056
|
-
output: string;
|
|
2057
|
-
metadata?: Record<string, unknown>;
|
|
2058
|
-
}
|
|
2059
|
-
/**
|
|
2060
|
-
* Base class for governance gates. Each gate checks a different dimension.
|
|
2061
|
-
* Gates are structurally independent — they report to the human operator,
|
|
2062
|
-
* not to each other or to any agent.
|
|
2063
|
-
*/
|
|
2064
|
-
declare abstract class GovernanceGate {
|
|
2065
|
-
abstract readonly id: string;
|
|
2066
|
-
abstract readonly name: string;
|
|
2067
|
-
abstract readonly dimension: string;
|
|
2068
|
-
/**
|
|
2069
|
-
* Run the gate check on agent output.
|
|
2070
|
-
* Must return a verdict and any findings.
|
|
2071
|
-
*/
|
|
2072
|
-
abstract check(input: GateInput): Promise<GateResult>;
|
|
2073
|
-
}
|
|
2074
|
-
/**
|
|
2075
|
-
* QA Gate — validates data correctness.
|
|
2076
|
-
* Checks: schema conformance, row counts, format validation.
|
|
2077
|
-
*/
|
|
2078
|
-
declare class QAGate extends GovernanceGate {
|
|
2079
|
-
private validators;
|
|
2080
|
-
readonly id = "qa";
|
|
2081
|
-
readonly name = "Quality Assurance";
|
|
2082
|
-
readonly dimension = "data_correctness";
|
|
2083
|
-
constructor(validators?: Array<{
|
|
2084
|
-
name: string;
|
|
2085
|
-
validate: (output: string, metadata?: Record<string, unknown>) => GateFinding[];
|
|
2086
|
-
}>);
|
|
2087
|
-
check(input: GateInput): Promise<GateResult>;
|
|
2088
|
-
}
|
|
2089
|
-
/**
|
|
2090
|
-
* Quality Gate — validates code quality.
|
|
2091
|
-
* Checks: lint results, test coverage, review patterns.
|
|
2092
|
-
*/
|
|
2093
|
-
declare class QualityGate extends GovernanceGate {
|
|
2094
|
-
private checks;
|
|
2095
|
-
readonly id = "quality";
|
|
2096
|
-
readonly name = "Code Quality";
|
|
2097
|
-
readonly dimension = "code_quality";
|
|
2098
|
-
constructor(checks?: Array<{
|
|
2099
|
-
name: string;
|
|
2100
|
-
check: (output: string, metadata?: Record<string, unknown>) => Promise<GateFinding[]>;
|
|
2101
|
-
}>);
|
|
2102
|
-
check(input: GateInput): Promise<GateResult>;
|
|
2103
|
-
}
|
|
2104
|
-
/**
|
|
2105
|
-
* Drift Gate — detects architectural drift.
|
|
2106
|
-
* Checks: unintended dependencies, scope creep, pattern violations.
|
|
2107
|
-
*/
|
|
2108
|
-
declare class DriftGate extends GovernanceGate {
|
|
2109
|
-
private rules;
|
|
2110
|
-
readonly id = "drift";
|
|
2111
|
-
readonly name = "Architectural Drift";
|
|
2112
|
-
readonly dimension = "architecture";
|
|
2113
|
-
constructor(rules?: Array<{
|
|
2114
|
-
name: string;
|
|
2115
|
-
detect: (output: string, metadata?: Record<string, unknown>) => GateFinding[];
|
|
2116
|
-
}>);
|
|
2117
|
-
check(input: GateInput): Promise<GateResult>;
|
|
2118
|
-
}
|
|
2119
|
-
/**
|
|
2120
|
-
* GateRunner — orchestrates multiple independent gates on agent output.
|
|
2121
|
-
* Each gate runs independently. Results are reported to the human, not to agents.
|
|
2122
|
-
*/
|
|
2123
|
-
declare class GateRunner {
|
|
2124
|
-
private gates;
|
|
2125
|
-
private hooks;
|
|
2126
|
-
constructor(gates: GovernanceGate[], hooks: HookBus);
|
|
2127
|
-
/**
|
|
2128
|
-
* Run all gates on the given input.
|
|
2129
|
-
* Gates run independently — one failure doesn't block others.
|
|
2130
|
-
*/
|
|
2131
|
-
runAll(input: GateInput): Promise<{
|
|
2132
|
-
passed: boolean;
|
|
2133
|
-
results: GateResult[];
|
|
2134
|
-
}>;
|
|
2135
|
-
}
|
|
2136
|
-
|
|
2137
|
-
declare const sendFileTool: {
|
|
2138
|
-
definition: ToolDefinition;
|
|
2139
|
-
handler: ToolHandler;
|
|
2140
|
-
};
|
|
2141
|
-
|
|
2142
|
-
declare const readFileTool: {
|
|
2143
|
-
definition: ToolDefinition;
|
|
2144
|
-
handler: ToolHandler;
|
|
2145
|
-
};
|
|
2146
|
-
|
|
2147
|
-
/**
|
|
2148
|
-
* Built-in tools: File operations — list, register, send, read.
|
|
2149
|
-
*/
|
|
2150
|
-
|
|
2151
|
-
declare const listFilesTool: {
|
|
2152
|
-
definition: ToolDefinition;
|
|
2153
|
-
handler: ToolHandler;
|
|
2154
|
-
};
|
|
2155
|
-
declare const registerFileTool: {
|
|
2156
|
-
definition: ToolDefinition;
|
|
2157
|
-
handler: ToolHandler;
|
|
2158
|
-
};
|
|
2159
|
-
|
|
2160
|
-
declare const dispatchTaskTool: {
|
|
2161
|
-
definition: ToolDefinition;
|
|
2162
|
-
handler: ToolHandler;
|
|
2163
|
-
};
|
|
2164
|
-
declare const cancelTaskTool: {
|
|
2165
|
-
definition: ToolDefinition;
|
|
2166
|
-
handler: ToolHandler;
|
|
2167
|
-
};
|
|
2168
|
-
declare const reassignTaskTool: {
|
|
2169
|
-
definition: ToolDefinition;
|
|
2170
|
-
handler: ToolHandler;
|
|
2171
|
-
};
|
|
2172
|
-
|
|
2173
|
-
/**
|
|
2174
|
-
* Built-in tools: System awareness — task status, agent status, system health.
|
|
2175
|
-
*/
|
|
2176
|
-
|
|
2177
|
-
declare const getTaskStatusTool: {
|
|
2178
|
-
definition: ToolDefinition;
|
|
2179
|
-
handler: ToolHandler;
|
|
2180
|
-
};
|
|
2181
|
-
declare const getAgentStatusTool: {
|
|
2182
|
-
definition: ToolDefinition;
|
|
2183
|
-
handler: ToolHandler;
|
|
2184
|
-
};
|
|
2185
|
-
declare const getSystemStatusTool: {
|
|
2186
|
-
definition: ToolDefinition;
|
|
2187
|
-
handler: ToolHandler;
|
|
2188
|
-
};
|
|
2189
|
-
declare const getActiveTasksTool: {
|
|
2190
|
-
definition: ToolDefinition;
|
|
2191
|
-
handler: ToolHandler;
|
|
2192
|
-
};
|
|
2193
|
-
|
|
2194
|
-
/**
|
|
2195
|
-
* Built-in tools: Entity lookup — agents, projects, details.
|
|
2196
|
-
*/
|
|
2197
|
-
|
|
2198
|
-
declare const listAgentsTool: {
|
|
2199
|
-
definition: ToolDefinition;
|
|
2200
|
-
handler: ToolHandler;
|
|
2201
|
-
};
|
|
2202
|
-
declare const listProjectsTool: {
|
|
2203
|
-
definition: ToolDefinition;
|
|
2204
|
-
handler: ToolHandler;
|
|
2205
|
-
};
|
|
2206
|
-
declare const getAgentDetailTool: {
|
|
2207
|
-
definition: ToolDefinition;
|
|
2208
|
-
handler: ToolHandler;
|
|
2209
|
-
};
|
|
2210
|
-
|
|
2211
|
-
/**
|
|
2212
|
-
* Built-in tools: Communication — send messages, read conversations, search history.
|
|
2213
|
-
* All messaging is channel-agnostic: slack, email, discord, sms — same tools.
|
|
2214
|
-
*/
|
|
2215
|
-
|
|
2216
|
-
declare const sendMessageTool: {
|
|
2217
|
-
definition: ToolDefinition;
|
|
2218
|
-
handler: ToolHandler;
|
|
2219
|
-
};
|
|
2220
|
-
declare const addTaskCommentTool: {
|
|
2221
|
-
definition: ToolDefinition;
|
|
2222
|
-
handler: ToolHandler;
|
|
2223
|
-
};
|
|
2224
|
-
declare const readConversationTool: {
|
|
2225
|
-
definition: ToolDefinition;
|
|
2226
|
-
handler: ToolHandler;
|
|
2227
|
-
};
|
|
2228
|
-
declare const searchConversationTool: {
|
|
2229
|
-
definition: ToolDefinition;
|
|
2230
|
-
handler: ToolHandler;
|
|
2231
|
-
};
|
|
2232
|
-
|
|
2233
|
-
/**
|
|
2234
|
-
* Shared agent resolution: slug → role → name (case-insensitive).
|
|
2235
|
-
*
|
|
2236
|
-
* LLMs see list_agents output like "AgentName (role)" and naturally use
|
|
2237
|
-
* the role as the identifier. All agent-resolving tools must accept
|
|
2238
|
-
* slug, role, OR name — not just slug.
|
|
2239
|
-
*/
|
|
2240
|
-
|
|
2241
|
-
declare function resolveAgent(db: DataStore, ref: string): Promise<Record<string, unknown> | null>;
|
|
2242
|
-
|
|
2243
|
-
/**
|
|
2244
|
-
* Built-in tools: Entity creation — agents, projects.
|
|
2245
|
-
*/
|
|
2246
|
-
|
|
2247
|
-
declare const createAgentTool: {
|
|
2248
|
-
definition: ToolDefinition;
|
|
2249
|
-
handler: ToolHandler;
|
|
2250
|
-
};
|
|
2251
|
-
declare const createProjectTool: {
|
|
2252
|
-
definition: ToolDefinition;
|
|
2253
|
-
handler: ToolHandler;
|
|
2254
|
-
};
|
|
2255
|
-
|
|
2256
|
-
/**
|
|
2257
|
-
* All native tools bundled for convenience.
|
|
2258
|
-
* Apps can pass this directly to ExecutionEngine config:
|
|
2259
|
-
* tools: nativeTools
|
|
2260
|
-
* or spread to add custom tools:
|
|
2261
|
-
* tools: [...nativeTools, myCustomTool]
|
|
2262
|
-
*/
|
|
2263
|
-
declare const nativeTools: {
|
|
2264
|
-
definition: ToolDefinition;
|
|
2265
|
-
handler: ToolHandler;
|
|
2266
|
-
}[];
|
|
2267
|
-
/**
|
|
2268
|
-
* Coordinator tools for multi-agent primary agent.
|
|
2269
|
-
* Orchestration + communication + awareness — no "work" tools.
|
|
2270
|
-
* Use with ChatPipelineV2 in multi-agent mode.
|
|
2271
|
-
*
|
|
2272
|
-
* Single-agent mode should use `nativeTools` instead (all tools).
|
|
2273
|
-
*/
|
|
2274
|
-
declare const coordinatorTools: {
|
|
2275
|
-
definition: ToolDefinition;
|
|
2276
|
-
handler: ToolHandler;
|
|
2277
|
-
}[];
|
|
2278
|
-
|
|
2279
|
-
interface SecretInput {
|
|
2280
|
-
name: string;
|
|
2281
|
-
type?: string;
|
|
2282
|
-
environment?: string;
|
|
2283
|
-
value?: string;
|
|
2284
|
-
location?: string;
|
|
2285
|
-
description?: string;
|
|
2286
|
-
rotation_schedule?: string;
|
|
2287
|
-
expires_at?: string;
|
|
2288
|
-
notes?: string;
|
|
2289
|
-
org_id?: string;
|
|
2290
|
-
}
|
|
2291
|
-
interface SecretMeta {
|
|
2292
|
-
id: string;
|
|
2293
|
-
org_id: string | null;
|
|
2294
|
-
name: string;
|
|
2295
|
-
type: string;
|
|
2296
|
-
environment: string;
|
|
2297
|
-
location: string | null;
|
|
2298
|
-
description: string | null;
|
|
2299
|
-
rotation_schedule: string | null;
|
|
2300
|
-
expires_at: string | null;
|
|
2301
|
-
notes: string | null;
|
|
2302
|
-
created_at: string;
|
|
2303
|
-
updated_at: string;
|
|
2304
|
-
}
|
|
2305
|
-
declare class SecretStore {
|
|
2306
|
-
private readonly db;
|
|
2307
|
-
private readonly hooks;
|
|
2308
|
-
private readonly encKey;
|
|
2309
|
-
/**
|
|
2310
|
-
* @param db - DataStore instance
|
|
2311
|
-
* @param hooks - HookBus instance
|
|
2312
|
-
* @param encryptionKey - Optional master key for encrypting secrets at rest.
|
|
2313
|
-
* When provided, all new secrets are encrypted with AES-256-GCM.
|
|
2314
|
-
* Existing plaintext secrets are read transparently (passthrough on decrypt).
|
|
2315
|
-
*/
|
|
2316
|
-
constructor(db: DataStore, hooks: HookBus, encryptionKey?: string);
|
|
2317
|
-
set(input: SecretInput): Promise<SecretMeta>;
|
|
2318
|
-
get(name: string, environment?: string): Promise<string | null>;
|
|
2319
|
-
getMeta(name: string, environment?: string): Promise<SecretMeta | null>;
|
|
2320
|
-
list(): Promise<SecretMeta[]>;
|
|
2321
|
-
rotate(name: string, newValue: string, environment?: string): Promise<void>;
|
|
2322
|
-
delete(name: string, environment?: string): Promise<void>;
|
|
2323
|
-
/**
|
|
2324
|
-
* Load a sync cursor by key. Returns undefined if not found.
|
|
2325
|
-
* Cursors are stored as secrets with type='sync_cursor'.
|
|
2326
|
-
*/
|
|
2327
|
-
loadCursor(key: string): Promise<string | undefined>;
|
|
2328
|
-
/**
|
|
2329
|
-
* Persist a sync cursor by key. Creates or updates the secret.
|
|
2330
|
-
*/
|
|
2331
|
-
saveCursor(key: string, value: string): Promise<void>;
|
|
2332
|
-
private _toMeta;
|
|
2333
|
-
}
|
|
2334
|
-
|
|
2335
|
-
/**
|
|
2336
|
-
* Parse Claude CLI NDJSON (stream-json) output into structured results.
|
|
2337
|
-
* Used by the CLI execution adapter to extract session info, costs,
|
|
2338
|
-
* token usage, and text output from Claude CLI subprocess output.
|
|
2339
|
-
*/
|
|
2340
|
-
interface ParsedStream {
|
|
2341
|
-
sessionId: string | null;
|
|
2342
|
-
model: string | null;
|
|
2343
|
-
costUsd: number | null;
|
|
2344
|
-
usage: UsageSummary | null;
|
|
2345
|
-
summary: string;
|
|
2346
|
-
isError: boolean;
|
|
2347
|
-
errorMessage: string | null;
|
|
2348
|
-
stopReason: string | null;
|
|
2349
|
-
}
|
|
2350
|
-
interface UsageSummary {
|
|
2351
|
-
inputTokens: number;
|
|
2352
|
-
cachedInputTokens: number;
|
|
2353
|
-
outputTokens: number;
|
|
2354
|
-
}
|
|
2355
|
-
/**
|
|
2356
|
-
* Parse Claude CLI NDJSON output into a structured result.
|
|
2357
|
-
* Handles init, assistant, and result event types.
|
|
2358
|
-
*/
|
|
2359
|
-
declare function parseClaudeStream(stdout: string): ParsedStream;
|
|
2360
|
-
/** Check if the run stopped due to max turns. */
|
|
2361
|
-
declare function isMaxTurns(parsed: ParsedStream): boolean;
|
|
2362
|
-
/** Check if Claude CLI requires login. */
|
|
2363
|
-
declare function isLoginRequired(stdout: string): boolean;
|
|
2364
|
-
/** Rewrite local image paths to prevent CLI auto-embedding as vision content. */
|
|
2365
|
-
declare function deactivateLocalImagePaths(prompt: string): string;
|
|
2366
|
-
|
|
2367
|
-
export { AGENT_STATUSES, type AgentConfig, type AgentDefinition, type AgentFilter, type AgentRecord, AgentRegistry, type AgentStatus, ApiExecutionAdapter, type ApprovalResponse, type ApprovalStatus, AuditEmitter, type AuditEvent, BackupManager, type BotConfig, BreakerState, type BudgetCheck, type BudgetConfig, BudgetController, CORE_MIGRATIONS, ChannelAdapter, ChannelRegistry, ChannelRegistryError, type ChatConfig, ChatMessage, ChatPipelineV2, type ChatPipelineV2Config, ChatResponder, ChatResponderConfig, ChatSessionManager, CircuitBreaker, type CircuitBreakerConfig, type CliArgBuildInput, CliExecutionAdapter, type ColumnValidator, ColumnValidatorImpl, type ConfigLoadError, type ConfigLoadResult, ConnectorConfig, DEFAULTS, DEFAULT_CONFIG, type DataConfig, DataStore, type DefaultLLMCallConfig, DeterministicAdapter, type DeterministicConfig, type DomainEntityContextOptions, type DomainSchemaOptions, DriftGate, EVENTS, type EntityColumnDef, type EntityConfig, type ExecutionAdapter, type ExecutionConfig, type ExecutionEngineConfig, Extractor, type FeedbackEntry, type GateFinding, type GateInput, type GateResult, GateRunner, type GateVerdict, GovernanceGate, HealthStatus, HookBus, InboundMessage, LLMProvider, LearningPipeline, type LearningPipelineConfig, type LoopDetection, LoopDetector, type LoopDetectorConfig, LoopType, MAX_CHAIN_DEPTH, MessageInterpreter, MessagePipeline, MessageStore, type ModelConfig, ModelInfo, ModelRouter, NdjsonLogger, NotificationQueue, type PackageMigration, type PackageUpdate, type ParsedStream, type PermissionPrompt, type PermissionProvider, PermissionRelay, type PermissionRelayConfig, type PlaybookEntry, ProviderRegistry, QAGate, QualityGate, RUN_STATUSES, type RenderConfig, ResolvedModel, type RetryPolicy, type RoutingConfig, type RunContext, RunManager, type RunResult, type RunStatus, type SafetyConfig, type SanitizerOptions, type Schedule, type ScheduleDef, Scheduler, type SchemaError, type SecretInput, type SecretMeta, SecretStore, type SecurityConfig, SessionKey, SessionManager, type SkillEntry, type StepRef, type SystemContextOptions, TASK_STATUSES, type TaskDefinition, TaskQueue, type TaskRecord, type TaskStatus, TokenUsage, type ToolContext, type ToolDefinition, type ToolHandler, UpdateChecker, type UpdateConfig, UpdateManager, type UpdateManifest, type UsageSummary, type User, type UserInput, UserRegistry, WakeupQueue, type WorkflowConfigEntry, type WorkflowDefinition$1 as WorkflowDefinition, WorkflowEngine, type WorkflowRunRecord, type WorkflowRunStatus, type WorkflowStep$1 as WorkflowStep, type WorkflowStepConfig, type WorkflowTrigger, _resetConfig, addTaskCommentTool, areDependenciesMet, autoUpdate, buildAgentBindings, buildChainOrigin, buildCliArgs, buildProcessEnv, buildSystemContext, cancelTaskTool, checkAllowlist, checkChainDepth, checkMentionGate, chunkText, classifyUpdate, compareVersions, coordinatorTools, createAgentTool, createConfigRevision, createDefaultLLMCall, createProjectTool, deactivateLocalImagePaths, defineCoreEntityContexts, defineCoreTables, defineDomainEntityContexts, defineDomainTables, detectCycle, discoverChannels, discoverProviders, dispatchTaskTool, formatText, getActiveTasksTool, getAgentDetailTool, getAgentStatusTool, getConfig, getSystemStatusTool, getTaskStatusTool, initConfig, interpolate, interpolateEnv, isLoginRequired, isMaxTurns, listAgentsTool, listFilesTool, listProjectsTool, loadConfig, nativeTools, parseClaudeStream, parseVersion, readConversationTool, readFileTool, reassignTaskTool, registerExecutionEngine, registerFileTool, resolveAgent, runPackageMigrations, sanitize, searchConversationTool, sendFileTool, sendMessageTool, topologicalSort, truncateAtWord, validateConfig };
|
|
2
|
+
* botinabox — framework for building multi-agent bots.
|
|
3
|
+
* Re-exports everything from shared types and core modules.
|
|
4
|
+
*/
|
|
5
|
+
export * from "./shared/index.js";
|
|
6
|
+
export * from "./core/hooks/index.js";
|
|
7
|
+
export * from "./core/config/index.js";
|
|
8
|
+
export * from "./core/llm/index.js";
|
|
9
|
+
export * from "./core/chat/index.js";
|
|
10
|
+
export * from "./core/data/index.js";
|
|
11
|
+
export * from "./core/security/index.js";
|
|
12
|
+
export * from "./core/update/index.js";
|
|
13
|
+
export * from "./core/orchestrator/agent-registry.js";
|
|
14
|
+
export * from "./core/orchestrator/task-queue.js";
|
|
15
|
+
export * from "./core/orchestrator/run-manager.js";
|
|
16
|
+
export * from "./core/orchestrator/budget-controller.js";
|
|
17
|
+
export { WorkflowEngine } from "./core/orchestrator/workflow-engine.js";
|
|
18
|
+
export * from "./core/orchestrator/wakeup-queue.js";
|
|
19
|
+
export * from "./core/orchestrator/session-manager.js";
|
|
20
|
+
export * from "./core/orchestrator/chain-guard.js";
|
|
21
|
+
export * from "./core/orchestrator/ndjson-logger.js";
|
|
22
|
+
export * from "./core/orchestrator/scheduler.js";
|
|
23
|
+
export * from "./core/orchestrator/config-revisions.js";
|
|
24
|
+
export * from "./core/orchestrator/dependency-resolver.js";
|
|
25
|
+
export * from "./core/orchestrator/template-interpolate.js";
|
|
26
|
+
export * from "./core/orchestrator/adapters/api-adapter.js";
|
|
27
|
+
export * from "./core/orchestrator/adapters/cli-adapter.js";
|
|
28
|
+
export * from "./core/orchestrator/adapters/deterministic-adapter.js";
|
|
29
|
+
export * from "./core/orchestrator/loop-detector.js";
|
|
30
|
+
export * from "./core/orchestrator/circuit-breaker.js";
|
|
31
|
+
export * from "./core/orchestrator/learning-pipeline.js";
|
|
32
|
+
export * from "./core/orchestrator/permission-relay.js";
|
|
33
|
+
export * from "./core/orchestrator/governance-gate.js";
|
|
34
|
+
export { registerExecutionEngine } from "./core/orchestrator/execution-engine.js";
|
|
35
|
+
export type { ExecutionEngineConfig, ToolDefinition, ToolHandler, ToolContext } from "./core/orchestrator/execution-engine.js";
|
|
36
|
+
export * from "./core/orchestrator/tools/index.js";
|
|
37
|
+
export * from "./core/orchestrator/user-registry.js";
|
|
38
|
+
export * from "./core/orchestrator/secret-store.js";
|
|
39
|
+
export * from "./core/orchestrator/claude-stream-parser.js";
|