@brainbox-labs/sdk 0.0.0-stage → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +346 -2
- package/dist/athena-R67AV2DO.js +13 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +57 -0
- package/dist/chunk-43LDD7YT.js +139 -0
- package/dist/chunk-4J77FNJJ.js +192 -0
- package/dist/chunk-AJR44IFE.js +47 -0
- package/dist/chunk-GVWDS5TG.js +112 -0
- package/dist/chunk-MF3BADT7.js +544 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-VEXUCOXR.js +387 -0
- package/dist/chunk-XFLBPF4A.js +169 -0
- package/dist/chunk-YRH35U57.js +178 -0
- package/dist/column-profiler-FJCAQQAS.js +23 -0
- package/dist/docs-loader-B2l0cO36.d.ts +25 -0
- package/dist/docs-loader-VA4KBG6Y.js +11 -0
- package/dist/index-qV0gq2eJ.d.ts +148 -0
- package/dist/index.d.ts +476 -0
- package/dist/index.js +523 -0
- package/dist/ingest/public.d.ts +178 -0
- package/dist/ingest/public.js +63 -0
- package/dist/ingest-DICRS7WW.js +13 -0
- package/dist/introspect-KQOOQEZM.js +11 -0
- package/dist/schema-reader-4ZVTUZIX.js +150 -0
- package/dist/serve/index.d.ts +2 -0
- package/dist/serve/index.js +8 -0
- package/dist/sql-parser-TB26PFXS.js +198 -0
- package/dist/sync-MXG4WALD.js +260 -0
- package/dist/trino-TUQ7CIRM.js +13 -0
- package/package.json +79 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
import { AnalysisDepth, GrepWikiArgs, GrepWikiResult, McpToolDefinition, GetIndexArgs, GetIndexResult, ListLearningsResult, ListPersonalPagesArgs, ListPersonalPagesResult, GetRecentChangesArgs, GetRecentChangesResult, RecallDomainArgs, ListTracesArgs, ListTracesResult, RecallTracesArgs, ListWikiPagesArgs, ListWikiPagesResult, RecallWikiArgs, CheckContextDraftArgs, CheckContextDraftResult, GetTraceArgs, GetWikiPageArgs, ResearchTaskArgs, ResearchTaskResult, ListSkillsResult, GetSkillArgs, GetSkillResult, CreateLearningArgs, CreateLearningResult, RetireLearningArgs, RetireLearningResult, ReportContextGapArgs, ReportContextGapResult, SaveDomainArgs, SaveDomainResult, ProcessEventArgs, CreateSkillArgs, CreateSkillResult, ArchiveWikiPageArgs, ArchiveResult, ArchiveTraceArgs, SaveWikiPageArgs, AppendWikiPageResult, SaveWikiPageResult, SavePersonalPageArgs, SavePersonalPageResult, AppendWikiPageArgs, FlagPersonalPageForReviewArgs, Project } from '@brainbox-labs/types';
|
|
2
|
+
import { D as DocEntry } from './docs-loader-B2l0cO36.js';
|
|
3
|
+
import { M as MCPOptions, a as MCP } from './index-qV0gq2eJ.js';
|
|
4
|
+
export { i as serve } from './index-qV0gq2eJ.js';
|
|
5
|
+
|
|
6
|
+
interface IngestPostgresOptions {
|
|
7
|
+
connectionString: string;
|
|
8
|
+
/** Restrict introspection to these table names. */
|
|
9
|
+
tables?: string[];
|
|
10
|
+
/** Dialect tag passed to the server (defaults to 'postgres'). */
|
|
11
|
+
dialect?: string;
|
|
12
|
+
}
|
|
13
|
+
interface IngestTrinoOptions {
|
|
14
|
+
/** trino://user[:password]@host[:port]/catalog[/schema] connection URL. */
|
|
15
|
+
connectionString: string;
|
|
16
|
+
/** Restrict introspection to these table names. */
|
|
17
|
+
tables?: string[];
|
|
18
|
+
/** Dialect tag passed to the server (defaults to 'trino'). */
|
|
19
|
+
dialect?: string;
|
|
20
|
+
}
|
|
21
|
+
interface IngestAthenaOptions {
|
|
22
|
+
/** athena://region/database[?catalog=AwsDataCatalog&workgroup=primary&output=s3://bucket/prefix] connection URL.
|
|
23
|
+
* AWS credentials come from the standard AWS SDK credential chain, not the URL. */
|
|
24
|
+
connectionString: string;
|
|
25
|
+
/** Restrict introspection to these table names. */
|
|
26
|
+
tables?: string[];
|
|
27
|
+
/** Dialect tag passed to the server (defaults to 'athena'). */
|
|
28
|
+
dialect?: string;
|
|
29
|
+
}
|
|
30
|
+
interface IngestSkillOptions {
|
|
31
|
+
/** Skill name — shown in the agent's skill list. */
|
|
32
|
+
name: string;
|
|
33
|
+
/** Skill description — used for skill discovery/routing. */
|
|
34
|
+
description: string;
|
|
35
|
+
/** Glob patterns matching source files to merge into the skill (md, txt, html, pdf, docx). */
|
|
36
|
+
sources: string[];
|
|
37
|
+
}
|
|
38
|
+
interface IngestProfileOptions {
|
|
39
|
+
/**
|
|
40
|
+
* 'cardinality': distinctCount + nullRate + numeric/string stats only.
|
|
41
|
+
* 'full': also collects enum values (for low-cardinality columns) and JSON key shapes.
|
|
42
|
+
*/
|
|
43
|
+
mode: 'cardinality' | 'full';
|
|
44
|
+
/** Max rows to sample per table for sample-based stats (default: 10 000). */
|
|
45
|
+
sampleRows?: number;
|
|
46
|
+
/** "tablename.columnname" pairs to exclude from profiling. */
|
|
47
|
+
skipColumns?: string[];
|
|
48
|
+
}
|
|
49
|
+
interface IngestOptions {
|
|
50
|
+
postgres?: IngestPostgresOptions;
|
|
51
|
+
/** Trino source — mutually exclusive with `postgres` and `athena`. Introspection covers tables
|
|
52
|
+
* and columns only; Trino has no enforced PKs, FKs, or indexes. */
|
|
53
|
+
trino?: IngestTrinoOptions;
|
|
54
|
+
/** Athena source — mutually exclusive with `postgres` and `trino`. Introspection covers tables
|
|
55
|
+
* and columns only; like Trino, Athena has no enforced PKs, FKs, or indexes. */
|
|
56
|
+
athena?: IngestAthenaOptions;
|
|
57
|
+
/** SQL files or directories to parse and submit alongside the schema. */
|
|
58
|
+
sql?: string[];
|
|
59
|
+
/**
|
|
60
|
+
* Glob patterns matching doc files (md, txt, html, pdf, docx).
|
|
61
|
+
* PDF and DOCX are auto-converted to markdown; html is passed as-is.
|
|
62
|
+
* An entry may instead be an object `{ path | content, sourceKey, sourceVersion, namespace, metadata }`
|
|
63
|
+
* to give the doc a stable identity: re-ingesting the same `sourceKey` updates the same page, and an
|
|
64
|
+
* unchanged key + version is skipped server-side (reported in `IngestStageResult.unchanged`).
|
|
65
|
+
*/
|
|
66
|
+
docs?: Array<string | DocEntry>;
|
|
67
|
+
/**
|
|
68
|
+
* Directory where converted markdown files (from PDF and DOCX sources) are written.
|
|
69
|
+
* Created automatically if it does not exist. Only applies when `docs` is set.
|
|
70
|
+
*/
|
|
71
|
+
convertedOutputDir?: string;
|
|
72
|
+
/** Free-form text to attach as an inline document. */
|
|
73
|
+
text?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Merge one or more source files into a single Agent Skill. Resolves synchronously —
|
|
76
|
+
* unlike the other source kinds, there is no context generate/poll/activate step.
|
|
77
|
+
*/
|
|
78
|
+
skill?: IngestSkillOptions;
|
|
79
|
+
/**
|
|
80
|
+
* How deeply to analyse `docs`/`text` sources. Applied to every source in this
|
|
81
|
+
* ingest that doesn't set its own depth; the server falls back to 'shallow' when unset.
|
|
82
|
+
*/
|
|
83
|
+
analysisDepth?: AnalysisDepth;
|
|
84
|
+
/**
|
|
85
|
+
* Profile column data from the database. Only applies when `postgres`, `trino`, or `athena` is set.
|
|
86
|
+
* Supports Postgres, MySQL, SQLite, DuckDB, Trino, and Athena via the connection string dialect.
|
|
87
|
+
*/
|
|
88
|
+
profile?: IngestProfileOptions;
|
|
89
|
+
/** Free-form description of this ingest. Not sent to the server today; reserved for
|
|
90
|
+
* future use (e.g. a commit-message-style field on the connector draft). */
|
|
91
|
+
message?: string;
|
|
92
|
+
/** Per-stage poll timeout in ms. Defaults to 300_000 (5 min). */
|
|
93
|
+
timeoutMs?: number;
|
|
94
|
+
/** Stop after the context is `ready` — skip activation so a reviewer can curate first. */
|
|
95
|
+
reviewOnly?: boolean;
|
|
96
|
+
/** Re-process the last connector draft instead of uploading sources again. */
|
|
97
|
+
force?: boolean;
|
|
98
|
+
/** Send `force: true` on the docs connector so the server does not skip keyed sources it considers
|
|
99
|
+
* unchanged (workaround for a failed extraction that left the page looking current, context-layer #469). */
|
|
100
|
+
forceDocs?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Stop after creating the connector draft — do not create a context or activate a version.
|
|
103
|
+
* Useful for inspecting what would be submitted before committing to a full ingest.
|
|
104
|
+
*/
|
|
105
|
+
dryRun?: boolean;
|
|
106
|
+
}
|
|
107
|
+
interface IngestStageResult {
|
|
108
|
+
kind: 'sql' | 'docs' | 'skill';
|
|
109
|
+
/** Absent when the server skipped every keyed source as unchanged (no connector was created). */
|
|
110
|
+
connectorDraftId?: string;
|
|
111
|
+
/** Docs stage: sourceKeys the server skipped as unchanged. */
|
|
112
|
+
unchanged?: string[];
|
|
113
|
+
/** Absent when `dryRun: true`. */
|
|
114
|
+
contextId?: string;
|
|
115
|
+
/** Present unless `reviewOnly: true` or `dryRun: true`. */
|
|
116
|
+
version?: number;
|
|
117
|
+
/** Present unless `reviewOnly: true` or `dryRun: true`. */
|
|
118
|
+
layerId?: string;
|
|
119
|
+
/** Non-fatal issues collected during this stage (e.g. SQL files that failed to parse). */
|
|
120
|
+
warnings?: string[];
|
|
121
|
+
}
|
|
122
|
+
interface IngestResult {
|
|
123
|
+
stages: IngestStageResult[];
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Thrown when a later stage fails after an earlier stage already activated a new
|
|
127
|
+
* version. `completed` carries the stages that did succeed so callers can decide
|
|
128
|
+
* whether to compensate (e.g. roll back, alert, retry just the failed stage).
|
|
129
|
+
*/
|
|
130
|
+
declare class IngestPartialFailureError extends Error {
|
|
131
|
+
readonly completed: IngestStageResult[];
|
|
132
|
+
readonly failedKind: IngestStageResult['kind'];
|
|
133
|
+
readonly cause: unknown;
|
|
134
|
+
constructor(failedKind: IngestStageResult['kind'], completed: IngestStageResult[], cause: unknown);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
declare function isTenantKey(apiKey: string): boolean;
|
|
138
|
+
interface ProjectView {
|
|
139
|
+
projectId: string;
|
|
140
|
+
name?: string;
|
|
141
|
+
role: 'overlay' | 'base' | 'project';
|
|
142
|
+
/** One-line description of what the brain covers, when the project has one. */
|
|
143
|
+
description?: string;
|
|
144
|
+
/** Alternate names / domain terms for the brain. */
|
|
145
|
+
aliases?: string[];
|
|
146
|
+
}
|
|
147
|
+
interface TenantView {
|
|
148
|
+
overlay: ProjectView;
|
|
149
|
+
bases: ProjectView[];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
interface BrainExecutorCallOptions {
|
|
153
|
+
/**
|
|
154
|
+
* Target a specific project by ID for this call. Only meaningful for
|
|
155
|
+
* tenant-key handles — routes a read to one of the tenant's readable base
|
|
156
|
+
* projects instead of the default (overlay). Write tools ignore this and
|
|
157
|
+
* always target the overlay. Single-project (non-tenant) executors throw
|
|
158
|
+
* if a projectId other than their bound project is requested.
|
|
159
|
+
*/
|
|
160
|
+
projectId?: string;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* A non-2xx brain dispatch response. `message` keeps the legacy
|
|
164
|
+
* `Brain dispatch <status> (<tool>): <body>` text so existing regex checks still match.
|
|
165
|
+
* `code` is the server's error code when the body carries one (e.g. 'VERSION_CONFLICT' from
|
|
166
|
+
* save_wiki_page with a stale baseVersion), else 'CONFLICT' for 409 and `HTTP_<status>` otherwise.
|
|
167
|
+
*/
|
|
168
|
+
declare class BrainDispatchError extends Error {
|
|
169
|
+
readonly status: number;
|
|
170
|
+
readonly toolName: string;
|
|
171
|
+
readonly body: string;
|
|
172
|
+
readonly code: string;
|
|
173
|
+
/** The JSON error body, when there is one (e.g. `currentVersion` on a VERSION_CONFLICT). */
|
|
174
|
+
readonly details?: Record<string, unknown>;
|
|
175
|
+
/**
|
|
176
|
+
* True when the same call can succeed later: 429, 502, 503, 504, and the process_event 409
|
|
177
|
+
* for a source.externalId that is still being processed. Other 409s (VERSION_CONFLICT, an
|
|
178
|
+
* archived skill) need the caller to change something first, so they are not retryable.
|
|
179
|
+
*/
|
|
180
|
+
readonly retryable: boolean;
|
|
181
|
+
/** Seconds from the Retry-After header, when the server sent one. */
|
|
182
|
+
readonly retryAfter?: number;
|
|
183
|
+
constructor(status: number, toolName: string, body: string, opts?: {
|
|
184
|
+
message?: string;
|
|
185
|
+
retryAfter?: number;
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
interface SyncOptions {
|
|
190
|
+
/** Directory of docs to sync (md, txt, html, pdf, docx). Dot-directories and node_modules are skipped. */
|
|
191
|
+
dir?: string;
|
|
192
|
+
/** In-memory / explicit sources, alone or on top of `dir`. Without a `sourceKey` the key is derived from `name` (or the file name). */
|
|
193
|
+
sources?: DocEntry[];
|
|
194
|
+
/**
|
|
195
|
+
* Namespace the pages live in; part of every derived key. Defaults to the basename of `dir`
|
|
196
|
+
* (`docs/kb` -> `kb`); required when syncing `sources` without a `dir`. A namespace is owned by
|
|
197
|
+
* ONE sync root: deletes are computed against every keyed raw-source page in exactly this
|
|
198
|
+
* namespace, so pages written there by anything else (brain.ingest with a sourceKey, another
|
|
199
|
+
* folder's sync) show up as pending deletes. Synced-in namespaces are read-only locally.
|
|
200
|
+
*/
|
|
201
|
+
namespace?: string;
|
|
202
|
+
/** Transform script: a name under `.brainbox/transforms/` in the current working directory, or a path relative to it. Its content hash is folded into sourceVersion. */
|
|
203
|
+
transform?: string;
|
|
204
|
+
/** Pre-approve archiving docs that no longer exist locally. Default false: they come back as `pendingDeletes`. */
|
|
205
|
+
prune?: boolean;
|
|
206
|
+
/** Send every doc and tell the server not to skip unchanged ones (workaround for context-layer #469). */
|
|
207
|
+
force?: boolean;
|
|
208
|
+
/** Diff only: no ingest, no archive, and nothing is created (a missing project just reports every doc as added). */
|
|
209
|
+
dryRun?: boolean;
|
|
210
|
+
analysisDepth?: AnalysisDepth;
|
|
211
|
+
timeoutMs?: number;
|
|
212
|
+
/** Stop before activating the new version so a reviewer can curate first. */
|
|
213
|
+
reviewOnly?: boolean;
|
|
214
|
+
}
|
|
215
|
+
interface SyncEntry {
|
|
216
|
+
sourceKey: string;
|
|
217
|
+
name: string;
|
|
218
|
+
}
|
|
219
|
+
interface PendingDelete {
|
|
220
|
+
sourceKey: string;
|
|
221
|
+
title: string;
|
|
222
|
+
}
|
|
223
|
+
interface SyncResult {
|
|
224
|
+
dryRun: boolean;
|
|
225
|
+
/** The namespace this sync owns (default: the synced dir's basename). */
|
|
226
|
+
namespace: string;
|
|
227
|
+
/** Dry run only: the project doesn't exist yet, so everything is reported as added. */
|
|
228
|
+
projectMissing?: boolean;
|
|
229
|
+
/** The server may have cut the listing short, so deletes were not computed (nothing is reported or archived). */
|
|
230
|
+
listingTruncated?: boolean;
|
|
231
|
+
added: SyncEntry[];
|
|
232
|
+
changed: SyncEntry[];
|
|
233
|
+
/** Same key + version + namespace as the Brain. Not sent unless `force`. */
|
|
234
|
+
unchanged: SyncEntry[];
|
|
235
|
+
/** In the Brain but no longer present locally. */
|
|
236
|
+
deleted: PendingDelete[];
|
|
237
|
+
/** `deleted` minus what was archived: nothing is archived without `prune` (or `brain.prune`). */
|
|
238
|
+
pendingDeletes: PendingDelete[];
|
|
239
|
+
archived: string[];
|
|
240
|
+
/** Keys the server itself reported as unchanged. */
|
|
241
|
+
skippedByServer: string[];
|
|
242
|
+
/** Files a transform dropped (returned null). */
|
|
243
|
+
skippedByTransform: string[];
|
|
244
|
+
/** Absent for a dry run or when nothing needed ingesting. */
|
|
245
|
+
ingest?: IngestResult;
|
|
246
|
+
}
|
|
247
|
+
interface PruneResult {
|
|
248
|
+
archived: string[];
|
|
249
|
+
notFound: string[];
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
interface LocalGrepWikiArgs extends GrepWikiArgs {
|
|
253
|
+
/** Narrow to this namespace and everything under it. Mutually exclusive with `tag`. */
|
|
254
|
+
namespace?: string;
|
|
255
|
+
}
|
|
256
|
+
interface LocalGrepWikiResult extends GrepWikiResult {
|
|
257
|
+
/**
|
|
258
|
+
* True when older pages of some kind may not have been searched: the kind has
|
|
259
|
+
* at least ~1000 pages (the deepest the server's list cursor goes), or the
|
|
260
|
+
* server can't page at all (before context-layer #409) and returned a full
|
|
261
|
+
* first page. Narrow with `tag`, `namespace` or `kind` to cover such a wiki.
|
|
262
|
+
*/
|
|
263
|
+
pagesTruncated: boolean;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* One callable verb on a brain namespace (e.g. `brain.recall.get_index`).
|
|
268
|
+
* Args are optional — tools with no `required` parameters can be called with `()`.
|
|
269
|
+
* `callOpts` is only meaningful for tenant-key handles: pass `{ projectId }`
|
|
270
|
+
* to target a specific readable base project instead of the default overlay.
|
|
271
|
+
*/
|
|
272
|
+
type VerbHandler<Args extends object = Record<string, unknown>, Result = unknown> = (args?: Args, callOpts?: BrainExecutorCallOptions) => Promise<Result>;
|
|
273
|
+
/**
|
|
274
|
+
* A tool catalog entry as exposed by `.asTools()`. Carries the MCP-format
|
|
275
|
+
* schema plus a bound `execute` so a single array drops straight into an
|
|
276
|
+
* agent loop without a per-tool dispatch table.
|
|
277
|
+
*
|
|
278
|
+
* for (const block of response.content) {
|
|
279
|
+
* if (block.type === 'tool_use') {
|
|
280
|
+
* const tool = tools.find(t => t.name === block.name);
|
|
281
|
+
* const result = await tool.execute(block.input);
|
|
282
|
+
* }
|
|
283
|
+
* }
|
|
284
|
+
*
|
|
285
|
+
* Anthropic/OpenAI tool params accept extra fields structurally, so this
|
|
286
|
+
* still works as-is when spread into `tools: [...]`.
|
|
287
|
+
*/
|
|
288
|
+
interface VerbTool extends McpToolDefinition {
|
|
289
|
+
execute: VerbHandler;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
type BrainRecall = {
|
|
293
|
+
get_index: VerbHandler<GetIndexArgs, GetIndexResult>;
|
|
294
|
+
list_learnings: VerbHandler<Record<string, never>, ListLearningsResult>;
|
|
295
|
+
list_personal_pages: VerbHandler<ListPersonalPagesArgs, ListPersonalPagesResult>;
|
|
296
|
+
get_recent_changes: VerbHandler<GetRecentChangesArgs, GetRecentChangesResult>;
|
|
297
|
+
recall_domain: VerbHandler<RecallDomainArgs, unknown>;
|
|
298
|
+
list_traces: VerbHandler<ListTracesArgs, ListTracesResult>;
|
|
299
|
+
recall_traces: VerbHandler<RecallTracesArgs, unknown>;
|
|
300
|
+
list_wiki_pages: VerbHandler<ListWikiPagesArgs, ListWikiPagesResult>;
|
|
301
|
+
recall_wiki: VerbHandler<RecallWikiArgs, unknown>;
|
|
302
|
+
/** Client-side: lists + fetches pages and greps locally. Result adds `pagesTruncated`. */
|
|
303
|
+
grep_wiki: VerbHandler<LocalGrepWikiArgs, LocalGrepWikiResult>;
|
|
304
|
+
check_context_draft: VerbHandler<CheckContextDraftArgs, CheckContextDraftResult>;
|
|
305
|
+
get_trace: VerbHandler<GetTraceArgs, unknown>;
|
|
306
|
+
get_wiki_page: VerbHandler<GetWikiPageArgs, unknown>;
|
|
307
|
+
research_task: VerbHandler<ResearchTaskArgs, ResearchTaskResult>;
|
|
308
|
+
list_skills: VerbHandler<Record<string, never>, ListSkillsResult>;
|
|
309
|
+
get_skill: VerbHandler<GetSkillArgs, GetSkillResult>;
|
|
310
|
+
asTools(): VerbTool[];
|
|
311
|
+
/** Like {@link asTools} minus tools this org has switched off (server-reported). Local verbs such as grep_wiki are always kept. */
|
|
312
|
+
asEnabledTools(): Promise<VerbTool[]>;
|
|
313
|
+
};
|
|
314
|
+
type BrainUpdate = {
|
|
315
|
+
create_learning: VerbHandler<CreateLearningArgs, CreateLearningResult>;
|
|
316
|
+
retire_learning: VerbHandler<RetireLearningArgs, RetireLearningResult>;
|
|
317
|
+
report_context_gap: VerbHandler<ReportContextGapArgs, ReportContextGapResult>;
|
|
318
|
+
save_domain: VerbHandler<SaveDomainArgs, SaveDomainResult>;
|
|
319
|
+
/**
|
|
320
|
+
* `source.externalId` is the idempotency key: a retry with the same externalId returns the
|
|
321
|
+
* existing trace instead of writing a second one. A concurrent duplicate that is still being
|
|
322
|
+
* processed is rejected with a 409, surfaced as `BrainDispatchError` (`code: 'CONFLICT'`,
|
|
323
|
+
* `retryable: true`); retry after a short backoff and you get the winner's trace.
|
|
324
|
+
*/
|
|
325
|
+
process_event: VerbHandler<ProcessEventArgs, unknown>;
|
|
326
|
+
/**
|
|
327
|
+
* `onConflict: 'update'` replaces an existing same-named skill's body as a new version instead
|
|
328
|
+
* of failing; the result's `outcome` is 'created' or 'updated' and `version` is the new version.
|
|
329
|
+
* Refused if the skill is archived or has a pending proposed revision.
|
|
330
|
+
*/
|
|
331
|
+
create_skill: VerbHandler<CreateSkillArgs, CreateSkillResult>;
|
|
332
|
+
/**
|
|
333
|
+
* Moves a synthesis wiki page into pending deletion (hidden from every read at once, purged
|
|
334
|
+
* after 7 days unless a person restores it). Hidden unless the org enables `agentArchiveTools`,
|
|
335
|
+
* so asEnabledTools() leaves it out by default.
|
|
336
|
+
*/
|
|
337
|
+
archive_wiki_page: VerbHandler<ArchiveWikiPageArgs, ArchiveResult>;
|
|
338
|
+
/** Same as {@link archive_wiki_page} for a trace. Also gated by `agentArchiveTools`. */
|
|
339
|
+
archive_trace: VerbHandler<ArchiveTraceArgs, ArchiveResult>;
|
|
340
|
+
/** With `mode: 'append'` adds `body` to the end of page `id` and returns {@link AppendWikiPageResult}. */
|
|
341
|
+
save_wiki_page: {
|
|
342
|
+
(args: SaveWikiPageArgs & {
|
|
343
|
+
mode: 'append';
|
|
344
|
+
}, callOpts?: BrainExecutorCallOptions): Promise<AppendWikiPageResult>;
|
|
345
|
+
(args?: SaveWikiPageArgs, callOpts?: BrainExecutorCallOptions): Promise<SaveWikiPageResult>;
|
|
346
|
+
};
|
|
347
|
+
/** With `id` + `flagForReview: true` and no title/body, flags the page without changing it. */
|
|
348
|
+
save_personal_page: VerbHandler<SavePersonalPageArgs, SavePersonalPageResult>;
|
|
349
|
+
/** @deprecated Use `save_wiki_page({ mode: 'append', id, body })`. Not listed by asTools(). */
|
|
350
|
+
append_wiki_page: VerbHandler<AppendWikiPageArgs, AppendWikiPageResult>;
|
|
351
|
+
/** @deprecated Use `save_personal_page({ id, flagForReview: true })`. Not listed by asTools(). */
|
|
352
|
+
flag_personal_page_for_review: VerbHandler<FlagPersonalPageForReviewArgs, SavePersonalPageResult & {
|
|
353
|
+
flagged: true;
|
|
354
|
+
}>;
|
|
355
|
+
asTools(): VerbTool[];
|
|
356
|
+
asEnabledTools(): Promise<VerbTool[]>;
|
|
357
|
+
};
|
|
358
|
+
/**
|
|
359
|
+
* `brain.projects.*` — org-level project discovery and creation. Needs no
|
|
360
|
+
* `project` on the handle. `create` requires a write-scoped org/project key (tenant
|
|
361
|
+
* keys are refused); renaming/deleting projects and all tenant management are
|
|
362
|
+
* admin-tier and not reachable with an API key.
|
|
363
|
+
*/
|
|
364
|
+
type BrainProjects = {
|
|
365
|
+
/** Projects this key can address, role-tagged, with description/aliases. Works for every key type. */
|
|
366
|
+
list(): Promise<ProjectView[]>;
|
|
367
|
+
create(name: string): Promise<Project>;
|
|
368
|
+
};
|
|
369
|
+
interface BrainBoxOptions {
|
|
370
|
+
/** BrainBox API key (bb_...). */
|
|
371
|
+
apiKey: string;
|
|
372
|
+
/** Organization slug. The API key is org-scoped; this is asserted on resolve. */
|
|
373
|
+
org: string;
|
|
374
|
+
/** Project (brain) slug. Omit to address the org-level default brain. */
|
|
375
|
+
project?: string;
|
|
376
|
+
/** BrainBox base URL (no /api suffix). Defaults to https://ctx.brainbox-ai.app. */
|
|
377
|
+
apiUrl?: string;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Root handle to a BrainBox brain. Holds credentials and addressing for the
|
|
381
|
+
* server-builder (`brain.serve`), read verbs (`brain.recall.*`), and write
|
|
382
|
+
* verbs (`brain.update.*`).
|
|
383
|
+
*
|
|
384
|
+
* Project ID resolution is lazy — the first `recall`/`update` call resolves
|
|
385
|
+
* the project slug; a successful resolve is cached, a failed resolve is
|
|
386
|
+
* cleared so the next call retries instead of replaying the rejection.
|
|
387
|
+
*/
|
|
388
|
+
declare class BrainBox {
|
|
389
|
+
readonly options: BrainBoxOptions;
|
|
390
|
+
readonly serve: BrainBoxServe;
|
|
391
|
+
readonly recall: BrainRecall;
|
|
392
|
+
readonly update: BrainUpdate;
|
|
393
|
+
readonly projects: BrainProjects;
|
|
394
|
+
private projectIdPromise?;
|
|
395
|
+
private tenantViewPromise?;
|
|
396
|
+
private discoveryPromise?;
|
|
397
|
+
private executor?;
|
|
398
|
+
constructor(options: BrainBoxOptions);
|
|
399
|
+
/**
|
|
400
|
+
* GET /api/projects for any key type: the addressable projects plus the tools
|
|
401
|
+
* this org has switched off. A successful fetch is cached; a failed one is
|
|
402
|
+
* cleared so the next call retries.
|
|
403
|
+
*/
|
|
404
|
+
private getDiscovery;
|
|
405
|
+
/** Tenant-key agents call this first to find the base Brains they can pass as `projectId`. */
|
|
406
|
+
private listProjectsTool;
|
|
407
|
+
/** Best-effort: discovery failing must never hide tools, so an error means "nothing disabled". */
|
|
408
|
+
private getDisabledTools;
|
|
409
|
+
/** Drops tools this org has switched off. Local verbs (grep_wiki) never hit the gated server tool, so they stay. */
|
|
410
|
+
private enabledTools;
|
|
411
|
+
/**
|
|
412
|
+
* A gated tool fails with a bare dispatch 403. Only on that failure, look up
|
|
413
|
+
* the org's disabled set (no extra request on the happy path) and replace the
|
|
414
|
+
* error with a clear one if the tool is in it.
|
|
415
|
+
*/
|
|
416
|
+
private explainDisabledTool;
|
|
417
|
+
private client;
|
|
418
|
+
/** Tenant keys see projects through the overlay/base view, and POST /projects returns their existing overlay instead of creating. */
|
|
419
|
+
private assertNotTenantKey;
|
|
420
|
+
/**
|
|
421
|
+
* Ingest sources into this brain — equivalent to running `brainbox meta ingest`
|
|
422
|
+
* + `repo push` + `repo meta create` + `repo meta approve`. Blocks until each
|
|
423
|
+
* stage's context is activated and a new version is published.
|
|
424
|
+
*
|
|
425
|
+
* For tenant keys, always targets the tenant's overlay project — `project`
|
|
426
|
+
* on the parent {@link BrainBox} handle is ignored, since base projects are
|
|
427
|
+
* shared, read-only brains that a tenant must never write into. For
|
|
428
|
+
* project/org keys, requires `project` on the parent handle.
|
|
429
|
+
*/
|
|
430
|
+
ingest(opts: IngestOptions): Promise<IngestResult>;
|
|
431
|
+
/**
|
|
432
|
+
* Sync a folder (or explicit sources) with this brain by stable `sourceKey`: list what the
|
|
433
|
+
* brain holds, ingest new and changed docs in one batch, and report docs deleted locally as
|
|
434
|
+
* `pendingDeletes`. Nothing is archived unless `prune: true`; apply a user's decision later
|
|
435
|
+
* with {@link BrainBox.prune}. Targets the handle's `project` like {@link BrainBox.ingest};
|
|
436
|
+
* tenant keys are not supported yet.
|
|
437
|
+
*
|
|
438
|
+
* `namespace` defaults to the synced dir's basename and is owned by this one sync root: deletes
|
|
439
|
+
* are computed against every keyed raw-source page in exactly that namespace, so other writers
|
|
440
|
+
* into it show up as pending deletes.
|
|
441
|
+
*/
|
|
442
|
+
sync(opts: SyncOptions): Promise<SyncResult>;
|
|
443
|
+
/** Archive the synced pages for these `sourceKey`s (soft, reversible server-side). Unknown keys come back in `notFound`. */
|
|
444
|
+
prune(sourceKeys: string[]): Promise<PruneResult>;
|
|
445
|
+
/** Target for write-side calls: a tenant key's overlay project, else the handle's `project`. */
|
|
446
|
+
private ingestContext;
|
|
447
|
+
private getExecutor;
|
|
448
|
+
/** Best-effort scope label from the key prefix alone — logged before any network call. */
|
|
449
|
+
private logDeclaredScope;
|
|
450
|
+
/** Backend-confirmed scope, logged once a resolving call (tenant view / project lookup) succeeds. */
|
|
451
|
+
private logConfirmedScope;
|
|
452
|
+
/**
|
|
453
|
+
* Resolves a tenant key's view (overlay + readable bases) from the cached GET /api/projects.
|
|
454
|
+
* A successful resolve is cached; a failed resolve is cleared so the next call
|
|
455
|
+
* retries instead of replaying the rejection.
|
|
456
|
+
*/
|
|
457
|
+
private getTenantView;
|
|
458
|
+
private resolveProjectId;
|
|
459
|
+
}
|
|
460
|
+
/** `brain.serve.*` — server-builder factories scoped to a brain handle. */
|
|
461
|
+
declare class BrainBoxServe {
|
|
462
|
+
private readonly handle;
|
|
463
|
+
constructor(handle: BrainBoxOptions);
|
|
464
|
+
/**
|
|
465
|
+
* Build an MCP server bound to this brain. Returns an unstarted MCP
|
|
466
|
+
* instance — call `.start({ port })` to begin serving.
|
|
467
|
+
*
|
|
468
|
+
* A `project` is required on the parent {@link BrainBox} handle until
|
|
469
|
+
* org-level default brains are supported by the server runtime — except
|
|
470
|
+
* for tenant keys, which discover their overlay + base projects at
|
|
471
|
+
* `start()` time via GET /api/projects instead.
|
|
472
|
+
*/
|
|
473
|
+
mcp(opts?: Omit<MCPOptions, 'apiKey' | 'project' | 'apiUrl'>): MCP;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
export { BrainBox, type BrainBoxOptions, BrainBoxServe, BrainDispatchError, type BrainProjects, DocEntry, type IngestOptions, IngestPartialFailureError, type IngestPostgresOptions, type IngestResult, type IngestStageResult, type LocalGrepWikiArgs, type LocalGrepWikiResult, type PendingDelete, type ProjectView, type PruneResult, type SyncEntry, type SyncOptions, type SyncResult, type TenantView, isTenantKey };
|