@schlessera/brain-ui-server 0.13.1 → 0.14.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 +51 -12
- package/dist/agent/backend.d.ts +163 -37
- package/dist/agent/backend.d.ts.map +1 -1
- package/dist/agent/backend.js +281 -286
- package/dist/agent/backend.js.map +1 -1
- package/dist/app.d.ts +46 -5
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +94 -35
- package/dist/app.js.map +1 -1
- package/dist/brain/client.d.ts +41 -30
- package/dist/brain/client.d.ts.map +1 -1
- package/dist/brain/client.js +138 -132
- package/dist/brain/client.js.map +1 -1
- package/dist/config/env.d.ts +104 -0
- package/dist/config/env.d.ts.map +1 -0
- package/dist/config/env.js +296 -0
- package/dist/config/env.js.map +1 -0
- package/dist/cron/scheduler.d.ts +16 -8
- package/dist/cron/scheduler.d.ts.map +1 -1
- package/dist/cron/scheduler.js +54 -53
- package/dist/cron/scheduler.js.map +1 -1
- package/dist/db/brain-db.d.ts +50 -0
- package/dist/db/brain-db.d.ts.map +1 -0
- package/dist/db/brain-db.js +75 -0
- package/dist/db/brain-db.js.map +1 -0
- package/dist/db/client.d.ts +8 -6
- package/dist/db/client.d.ts.map +1 -1
- package/dist/db/client.js +12 -25
- package/dist/db/client.js.map +1 -1
- package/dist/db/settings.d.ts +5 -4
- package/dist/db/settings.d.ts.map +1 -1
- package/dist/db/settings.js +9 -12
- package/dist/db/settings.js.map +1 -1
- package/dist/files/walker.d.ts +6 -7
- package/dist/files/walker.d.ts.map +1 -1
- package/dist/files/walker.js +6 -9
- package/dist/files/walker.js.map +1 -1
- package/dist/graph/reader.d.ts +6 -6
- package/dist/graph/reader.d.ts.map +1 -1
- package/dist/graph/reader.js +22 -12
- package/dist/graph/reader.js.map +1 -1
- package/dist/index.d.ts +15 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -10
- package/dist/index.js.map +1 -1
- package/dist/middleware/auth.d.ts +17 -6
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +34 -43
- package/dist/middleware/auth.js.map +1 -1
- package/dist/middleware/origin.d.ts +1 -2
- package/dist/middleware/origin.d.ts.map +1 -1
- package/dist/middleware/origin.js +1 -7
- package/dist/middleware/origin.js.map +1 -1
- package/dist/middleware/passkeys.d.ts +29 -5
- package/dist/middleware/passkeys.d.ts.map +1 -1
- package/dist/middleware/passkeys.js +47 -76
- package/dist/middleware/passkeys.js.map +1 -1
- package/dist/middleware/tailscale.d.ts +14 -11
- package/dist/middleware/tailscale.d.ts.map +1 -1
- package/dist/middleware/tailscale.js +11 -10
- package/dist/middleware/tailscale.js.map +1 -1
- package/dist/routes/brain.d.ts +9 -154
- package/dist/routes/brain.d.ts.map +1 -1
- package/dist/routes/brain.js +187 -188
- package/dist/routes/brain.js.map +1 -1
- package/dist/routes/files.d.ts +4 -88
- package/dist/routes/files.d.ts.map +1 -1
- package/dist/routes/files.js +74 -71
- package/dist/routes/files.js.map +1 -1
- package/dist/routes/graph.d.ts +4 -255
- package/dist/routes/graph.d.ts.map +1 -1
- package/dist/routes/graph.js +67 -64
- package/dist/routes/graph.js.map +1 -1
- package/dist/routes/health.d.ts +8 -22
- package/dist/routes/health.d.ts.map +1 -1
- package/dist/routes/health.js +10 -10
- package/dist/routes/health.js.map +1 -1
- package/dist/routes/models.d.ts +7 -90
- package/dist/routes/models.d.ts.map +1 -1
- package/dist/routes/models.js +53 -51
- package/dist/routes/models.js.map +1 -1
- package/dist/routes/providers.d.ts +5 -34
- package/dist/routes/providers.d.ts.map +1 -1
- package/dist/routes/providers.js +13 -11
- package/dist/routes/providers.js.map +1 -1
- package/dist/routes/sessions.d.ts +7 -78
- package/dist/routes/sessions.d.ts.map +1 -1
- package/dist/routes/sessions.js +35 -34
- package/dist/routes/sessions.js.map +1 -1
- package/dist/routes/share.d.ts +7 -60
- package/dist/routes/share.d.ts.map +1 -1
- package/dist/routes/share.js +80 -77
- package/dist/routes/share.js.map +1 -1
- package/dist/routes/voice.d.ts +8 -91
- package/dist/routes/voice.d.ts.map +1 -1
- package/dist/routes/voice.js +62 -59
- package/dist/routes/voice.js.map +1 -1
- package/dist/share/staging.d.ts +4 -4
- package/dist/share/staging.d.ts.map +1 -1
- package/dist/share/staging.js +7 -8
- package/dist/share/staging.js.map +1 -1
- package/dist/voice/deepgram-token.d.ts +1 -1
- package/dist/voice/deepgram-token.d.ts.map +1 -1
- package/dist/voice/deepgram-token.js +1 -2
- package/dist/voice/deepgram-token.js.map +1 -1
- package/dist/voice/keyterm-builder.d.ts +23 -8
- package/dist/voice/keyterm-builder.d.ts.map +1 -1
- package/dist/voice/keyterm-builder.js +67 -43
- package/dist/voice/keyterm-builder.js.map +1 -1
- package/dist/voice/speech-providers.d.ts +6 -4
- package/dist/voice/speech-providers.d.ts.map +1 -1
- package/dist/voice/speech-providers.js +28 -25
- package/dist/voice/speech-providers.js.map +1 -1
- package/dist/ws/bridge.d.ts.map +1 -1
- package/dist/ws/bridge.js +2 -3
- package/dist/ws/bridge.js.map +1 -1
- package/dist/ws/clients.d.ts +18 -10
- package/dist/ws/clients.d.ts.map +1 -1
- package/dist/ws/clients.js +35 -37
- package/dist/ws/clients.js.map +1 -1
- package/dist/ws/connection.d.ts.map +1 -1
- package/dist/ws/connection.js +5 -7
- package/dist/ws/connection.js.map +1 -1
- package/dist/ws/dispatch.d.ts.map +1 -1
- package/dist/ws/dispatch.js +1 -2
- package/dist/ws/dispatch.js.map +1 -1
- package/dist/ws/host.d.ts +16 -12
- package/dist/ws/host.d.ts.map +1 -1
- package/dist/ws/host.js +14 -23
- package/dist/ws/host.js.map +1 -1
- package/dist/ws/routing.d.ts +2 -1
- package/dist/ws/routing.d.ts.map +1 -1
- package/dist/ws/routing.js +5 -6
- package/dist/ws/routing.js.map +1 -1
- package/dist/ws/run-session.js +1 -1
- package/dist/ws/run-session.js.map +1 -1
- package/dist/ws/session-catalog.d.ts +2 -2
- package/dist/ws/session-catalog.d.ts.map +1 -1
- package/dist/ws/session-catalog.js +2 -3
- package/dist/ws/session-catalog.js.map +1 -1
- package/package.json +8 -5
- package/src/agent/backend.ts +509 -340
- package/src/app.ts +157 -36
- package/src/brain/client.ts +166 -143
- package/src/config/env.ts +401 -0
- package/src/cron/scheduler.ts +77 -59
- package/src/db/brain-db.ts +104 -0
- package/src/db/client.ts +12 -31
- package/src/db/settings.ts +12 -14
- package/src/files/walker.ts +6 -10
- package/src/graph/reader.ts +26 -15
- package/src/index.ts +56 -17
- package/src/middleware/auth.ts +51 -45
- package/src/middleware/origin.ts +1 -8
- package/src/middleware/passkeys.ts +72 -68
- package/src/middleware/tailscale.ts +22 -17
- package/src/routes/brain.ts +31 -30
- package/src/routes/files.ts +10 -7
- package/src/routes/graph.ts +9 -6
- package/src/routes/health.ts +17 -10
- package/src/routes/models.ts +19 -15
- package/src/routes/providers.ts +14 -15
- package/src/routes/sessions.ts +18 -11
- package/src/routes/share.ts +35 -24
- package/src/routes/voice.ts +78 -68
- package/src/share/staging.ts +10 -8
- package/src/voice/deepgram-token.ts +4 -2
- package/src/voice/keyterm-builder.ts +90 -56
- package/src/voice/speech-providers.ts +28 -24
- package/src/ws/bridge.ts +2 -3
- package/src/ws/clients.ts +38 -41
- package/src/ws/connection.ts +5 -7
- package/src/ws/dispatch.ts +1 -2
- package/src/ws/host.ts +24 -27
- package/src/ws/routing.ts +6 -10
- package/src/ws/run-session.ts +1 -1
- package/src/ws/session-catalog.ts +2 -3
- package/dist/ws/handler.d.ts +0 -34
- package/dist/ws/handler.d.ts.map +0 -1
- package/dist/ws/handler.js +0 -33
- package/dist/ws/handler.js.map +0 -1
- package/src/ws/handler.ts +0 -50
package/README.md
CHANGED
|
@@ -11,13 +11,14 @@ pieces through `createApp()`.
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
-
import { createApp
|
|
14
|
+
import { createApp } from "@schlessera/brain-ui-server";
|
|
15
15
|
|
|
16
16
|
const app = createApp({
|
|
17
17
|
staticRoot: "./client/dist", // optional: serve a built SPA + fallback
|
|
18
18
|
renderer, // optional: { renderPng, renderPdf }
|
|
19
19
|
appName: "Brain UI", // branding in status copy
|
|
20
|
-
|
|
20
|
+
// config: resolveServerConfig(env) // optional: explicit configuration;
|
|
21
|
+
// // omitted = resolved from process.env once
|
|
21
22
|
});
|
|
22
23
|
|
|
23
24
|
export default {
|
|
@@ -27,9 +28,12 @@ export default {
|
|
|
27
28
|
};
|
|
28
29
|
```
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
coordinator, SQLite handle
|
|
32
|
-
|
|
31
|
+
Apps are self-contained: each `createApp()` call builds its own WebSocket
|
|
32
|
+
coordinator, SQLite handle and backend registry from its (resolved or
|
|
33
|
+
injected) configuration, so two differently-configured apps coexist in one
|
|
34
|
+
process. The returned handle carries `config`, `db`, `wsHost`,
|
|
35
|
+
`isTurnActive()`, `cancelActiveTurns()` and `close()` for the deployment
|
|
36
|
+
shell's lifecycle wiring.
|
|
33
37
|
|
|
34
38
|
## What it owns
|
|
35
39
|
|
|
@@ -58,13 +62,48 @@ different options reconfigures the first app rather than creating a second.
|
|
|
58
62
|
|
|
59
63
|
## Environment
|
|
60
64
|
|
|
61
|
-
|
|
62
|
-
`
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
Every variable this package reads, and what happens when it is unset.
|
|
66
|
+
`createApp()` configuration wins over the environment where both exist.
|
|
67
|
+
|
|
68
|
+
<!-- env:begin -->
|
|
69
|
+
|
|
70
|
+
| Variable | What it controls | Unset |
|
|
71
|
+
| --- | --- | --- |
|
|
72
|
+
| `AGENT_BACKEND` | Primary agent backend: "claude" (default) or "pi". | claude |
|
|
73
|
+
| `ALLOWED_ORIGINS` | Comma-separated cross-origin allowlist for a split client/API topology; empty means same-origin only. | (empty) |
|
|
74
|
+
| `AUTH_MODE` | Authentication mode: password \| tailscale \| proxy \| none. Unset auto-detects (password when a hash is set, else tailscale). | (auto-detect) |
|
|
75
|
+
| `BRAIN_PATH` | Path to the brain repo the server operates on. | $HOME/brain |
|
|
76
|
+
| `BRAIN_UI_ALLOW_LOOPBACK_ORIGIN` | Set "1" to accept loopback Origins for WebAuthn regardless of Host (dev-only, for the vite proxy). | 0 |
|
|
77
|
+
| `BRAIN_UI_ALLOW_PASSWORD` | Set "1" to keep password login enabled after a passkey exists for the RP (break-glass recovery). | 0 |
|
|
78
|
+
| `BRAIN_UI_CLAUDE_DEFAULT_MODEL` | Model the built-in default Claude profile is pinned to. | claude-sonnet-4-6 |
|
|
79
|
+
| `BRAIN_UI_CLAUDE_PROFILES` | JSON array of extra Anthropic-compatible inference profiles ({id,label,model?,baseUrl?,authTokenEnv?,apiKeyEnv?,modelAliases?}). | (none) |
|
|
80
|
+
| `BRAIN_UI_DANGEROUSLY_DISABLE_AUTH` | Set "1" to allow AUTH_MODE=none on a non-loopback host. Every network peer gets full agent access. | 0 |
|
|
81
|
+
| `BRAIN_UI_MODEL_DISCOVERY` | Model discovery against the Anthropic Models API; "0"/"off"/"false" disables. Defaults ON, except under a test runner (NODE_ENV=test) where it defaults OFF. | on (off under NODE_ENV=test) |
|
|
82
|
+
| `BRAIN_UI_MODEL_TTL_HOURS` | How long a model-discovery result stays fresh, in hours. | 24 |
|
|
83
|
+
| `BRAIN_UI_PASSWORD_HASH` | Bun.password argon2id hash of the shared password. | **required** — AUTH_MODE=password |
|
|
84
|
+
| `CLAUDE_CODE_PATH` | Path to the Claude Code native binary handed to the Agent SDK. | /usr/local/bin/claude |
|
|
85
|
+
| `COOKIE_SECRET` | Secret signing the session cookie. | **required** — AUTH_MODE=password |
|
|
86
|
+
| `DB_PATH` | SQLite file for the UI's own database (sessions, passkeys, settings). | ./brain-ui.db |
|
|
87
|
+
| `DEEPGRAM_API_KEY` | Deepgram API key for streaming ASR (short-lived tokens are minted from it). | **required** — VOICE_PROVIDER=deepgram (or any voice use without VOICE_PROVIDER=webspeech) |
|
|
88
|
+
| `HOME` | Fallback anchor for the BRAIN_PATH default only. | /root |
|
|
89
|
+
| `HOST` | Bind host; consulted by the auth validation to decide whether AUTH_MODE=none is loopback-safe. | (empty) |
|
|
90
|
+
| `MAX_CONCURRENT_SESSIONS` | Cap on concurrently RUNNING agent sessions. | 3 |
|
|
91
|
+
| `NODE_ENV` | Only consulted for test-runner detection: flips the model-discovery default to off under bun test. Never gates any security behavior. | (unset) |
|
|
92
|
+
| `PROXY_AUTH_HEADER` | Header a fronting auth proxy sets for AUTH_MODE=proxy. | x-forwarded-user |
|
|
93
|
+
| `SOURCE_COMMIT` | Git SHA reported by /api/status (baked at image build time). | dev |
|
|
94
|
+
| `TRUST_PROXY` | Set "1" to trust x-forwarded-for/x-real-ip and the proxy auth header; only safe behind a trusted reverse proxy. | **required** — AUTH_MODE=proxy |
|
|
95
|
+
| `TRUST_PROXY_HOPS` | How many trusted proxies front the app (x-forwarded-for parse depth). | 1 |
|
|
96
|
+
| `VOICE_CACHE_DIR` | Directory holding the keyterm cache JSON. | $BRAIN_PATH/.brain-ui |
|
|
97
|
+
| `VOICE_KEYTERM_LIMIT` | Maximum custom-vocabulary terms built from the brain database. | 500 |
|
|
98
|
+
| `VOICE_PROVIDER` | Speech provider: "deepgram" or "webspeech" (opt-in only — Chromium streams audio to Google). Unset auto-detects deepgram when its key is present. | (auto-detect) |
|
|
99
|
+
| `WEBAUTHN_ORIGINS` | Comma-separated extra origins allowed for WebAuthn ceremonies. | (empty) |
|
|
100
|
+
| `WEBAUTHN_RP_ID` | Relying-party id override for proxies that rewrite Host. | (derived from the request origin) |
|
|
101
|
+
| `WEBAUTHN_RP_NAME` | Relying-party display name shown by authenticators. | Brain UI |
|
|
102
|
+
| `WEBAUTHN_USER_ID` | Stable WebAuthn user handle (wire contract — burned into every resident credential; max 64 bytes; never change it after the first passkey). | brain-ui-owner |
|
|
103
|
+
| `WEBAUTHN_USER_NAME` | WebAuthn user name shown by authenticators. | owner |
|
|
104
|
+
|
|
105
|
+
Generated from `packages/ui-server/src/config/env.ts` by `bun run env-docs`. Edit the descriptor, not this table.
|
|
106
|
+
<!-- env:end -->
|
|
68
107
|
|
|
69
108
|
Model discovery is on by default and needs no configuration beyond the Claude
|
|
70
109
|
credential the agent already uses (`CLAUDE_CODE_OAUTH_TOKEN` or
|
package/dist/agent/backend.d.ts
CHANGED
|
@@ -1,45 +1,171 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AgentConfig } from "../config/env.js";
|
|
2
2
|
import type { ProviderInfo } from "@schlessera/brain-ui-sdk";
|
|
3
3
|
import type { AgentBackend, BackendCapabilities } from "@schlessera/brain-ui-sdk/server";
|
|
4
|
-
/** Drop the memo so the next read reflects a refresh or a settings change. */
|
|
5
|
-
export declare function invalidateProfiles(): void;
|
|
6
4
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* Backend registry for one app instance. Built by `createApp()` from the
|
|
6
|
+
* resolved configuration — no ambient environment and no module-level state,
|
|
7
|
+
* so two apps with different backend configuration coexist in one process and
|
|
8
|
+
* tests install fakes by constructing a registry, not by mutating a module.
|
|
9
|
+
*
|
|
10
|
+
* BOTH backend packages are optional peers loaded lazily (the same
|
|
11
|
+
* `createRequire` path): a deployment installs the one its AGENT_BACKEND
|
|
12
|
+
* names, and the other never has to be present — at runtime AND at
|
|
13
|
+
* type-check time (see the structural mirrors below).
|
|
14
|
+
*
|
|
15
|
+
* The old five hardcoded personal inference profiles are gone: the Claude
|
|
16
|
+
* backend ships the single "claude" default, and additional Anthropic-compatible
|
|
17
|
+
* endpoints are declared via the BRAIN_UI_CLAUDE_PROFILES env var (documented in
|
|
18
|
+
* .env.example) rather than in code.
|
|
9
19
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
|
|
20
|
+
/** Mirror of the Claude package's `InferenceProfileInput` (declarative shape). */
|
|
21
|
+
export interface ClaudeProfileInput {
|
|
22
|
+
id: string;
|
|
23
|
+
label: string;
|
|
24
|
+
vendor?: string;
|
|
25
|
+
/** Model id. Undefined = the SDK/CLI default model. */
|
|
26
|
+
model?: string;
|
|
27
|
+
/** Anthropic-compatible endpoint. */
|
|
28
|
+
baseUrl?: string;
|
|
29
|
+
/** Name of the env var holding a bearer token. */
|
|
30
|
+
authTokenEnv?: string;
|
|
31
|
+
/** Name of the env var holding an x-api-key. */
|
|
32
|
+
apiKeyEnv?: string;
|
|
33
|
+
/** Remap the CLI's model-alias envs to `model`. Requires `model`. */
|
|
34
|
+
modelAliases?: boolean;
|
|
35
|
+
allowedTools?: string[];
|
|
36
|
+
/** Context window in tokens, when known. Presentation only. */
|
|
37
|
+
contextWindow?: number;
|
|
38
|
+
/** Where this profile came from. Presentation only. */
|
|
39
|
+
source?: "builtin" | "declared" | "discovered";
|
|
40
|
+
}
|
|
41
|
+
/** Mirror of the Claude package's resolved `InferenceProfile`. */
|
|
42
|
+
export interface ClaudeProfile {
|
|
43
|
+
id: string;
|
|
44
|
+
label: string;
|
|
45
|
+
vendor?: string;
|
|
46
|
+
model?: string;
|
|
47
|
+
allowedTools?: string[];
|
|
48
|
+
contextWindow?: number;
|
|
49
|
+
source?: "builtin" | "declared" | "discovered";
|
|
50
|
+
/** Env vars that must be present (non-empty) for this profile to be usable. */
|
|
51
|
+
requiredEnvKeys: string[];
|
|
52
|
+
/** Environment overrides merged over the host environment. */
|
|
53
|
+
buildEnv: () => Record<string, string>;
|
|
54
|
+
}
|
|
23
55
|
/**
|
|
24
|
-
*
|
|
56
|
+
* The slice of the lazily-required Claude module this registry drives. The
|
|
57
|
+
* real module carries more (and looser-optional) options; assignability is
|
|
58
|
+
* asserted in tests/declaration-surface.test.ts.
|
|
59
|
+
*/
|
|
60
|
+
export interface ClaudeBackendModule {
|
|
61
|
+
createClaudeBackend: (options: {
|
|
62
|
+
brainPath: string;
|
|
63
|
+
claudeCodePath?: string;
|
|
64
|
+
profiles?: ClaudeProfile[] | (() => ClaudeProfile[]);
|
|
65
|
+
}) => AgentBackend;
|
|
66
|
+
createModelSource: (options: {
|
|
67
|
+
brainPath: string;
|
|
68
|
+
ttlMs?: number;
|
|
69
|
+
enabled?: boolean;
|
|
70
|
+
}) => ClaudeModelSource;
|
|
71
|
+
defineProfiles: (inputs: ClaudeProfileInput[]) => ClaudeProfile[];
|
|
72
|
+
}
|
|
73
|
+
/** Discovery source as the registry internals see it: the public slice + list(). */
|
|
74
|
+
export interface ClaudeModelSource extends ModelDiscoverySource {
|
|
75
|
+
list: () => ClaudeProfileInput[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Discovery freshness, as exposed on the public registry surface.
|
|
25
79
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
80
|
+
* `list()` is omitted on purpose — it returns Claude profile inputs, only the
|
|
81
|
+
* registry internals consume it (see {@link ClaudeModelSource}), and exposing
|
|
82
|
+
* it would put those types on every consumer's plate for no reader.
|
|
28
83
|
*/
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
|
|
84
|
+
export interface ModelDiscoveryState {
|
|
85
|
+
enabled: boolean;
|
|
86
|
+
/** When discovery last succeeded; null when it never has. */
|
|
87
|
+
refreshedAt: number | null;
|
|
88
|
+
/** The cached result is older than the TTL (or absent). */
|
|
89
|
+
stale: boolean;
|
|
90
|
+
/** Last discovery failure, if the current list is served despite one. */
|
|
91
|
+
error?: string;
|
|
92
|
+
}
|
|
93
|
+
/** The slice of the Claude backend's discovery source the routes consume. */
|
|
94
|
+
export interface ModelDiscoverySource {
|
|
95
|
+
state(): ModelDiscoveryState;
|
|
96
|
+
/** Refresh if stale. Awaits only when there is nothing cached to serve. */
|
|
97
|
+
ensureFresh(): Promise<void>;
|
|
98
|
+
/** Force a refresh regardless of TTL. Rejects on failure. */
|
|
99
|
+
refresh(): Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
export interface BackendRegistryOptions {
|
|
102
|
+
/** Where the brain repo lives (handed to every backend). */
|
|
103
|
+
brainPath: string;
|
|
104
|
+
/** Resolved agent configuration (AGENT_BACKEND, profiles, discovery...). */
|
|
105
|
+
agent: AgentConfig;
|
|
106
|
+
/**
|
|
107
|
+
* Profile ids the user keeps out of the model picker (from the app's
|
|
108
|
+
* settings table). Presentation only — a hidden profile still resolves for
|
|
109
|
+
* sessions pinned to it. Defaults to "nothing hidden".
|
|
110
|
+
*/
|
|
111
|
+
getHiddenModelIds?: () => string[];
|
|
112
|
+
}
|
|
113
|
+
export interface BackendRegistry {
|
|
114
|
+
/** All configured backends, with the default backend first. */
|
|
115
|
+
getBackends(): Promise<AgentBackend[]>;
|
|
116
|
+
/** Find a configured backend by its stable id. */
|
|
117
|
+
getBackendById(id: string): Promise<AgentBackend | undefined>;
|
|
118
|
+
/** The default backend used for new and legacy sessions. */
|
|
119
|
+
getDefaultBackend(): Promise<AgentBackend>;
|
|
120
|
+
/** The stable id of the default backend. */
|
|
121
|
+
getDefaultBackendId(): Promise<string>;
|
|
122
|
+
/** Resolve the backend that owns a globally unique profile id. */
|
|
123
|
+
getBackendForProfile(profileId: string): Promise<AgentBackend | undefined>;
|
|
124
|
+
/** Resolve a persisted backend id, falling back for legacy/unknown sessions. */
|
|
125
|
+
getBackendForSession(backendId: string | null | undefined): Promise<AgentBackend>;
|
|
126
|
+
/**
|
|
127
|
+
* Every available profile, tagged with its owning backend id. Hidden
|
|
128
|
+
* profiles are omitted by default (this feeds the picker); the settings
|
|
129
|
+
* screen passes `includeHidden` to render the full catalog.
|
|
130
|
+
*/
|
|
131
|
+
listAllProviders(options?: {
|
|
132
|
+
includeHidden?: boolean;
|
|
133
|
+
}): Promise<ProviderInfo[]>;
|
|
134
|
+
/** Per-backend capability metadata exposed by the providers route. */
|
|
135
|
+
getBackendsInfo(): Promise<Record<string, {
|
|
136
|
+
id: string;
|
|
137
|
+
capabilities: BackendCapabilities;
|
|
138
|
+
}>>;
|
|
139
|
+
/**
|
|
140
|
+
* The Claude backend's discovery source, once the registry is built. Null
|
|
141
|
+
* when discovery is disabled or the deployment runs a different backend.
|
|
142
|
+
*/
|
|
143
|
+
getModelSource(): Promise<ModelDiscoverySource | null>;
|
|
144
|
+
/** Drop the profile memo so the next read reflects a refresh or settings change. */
|
|
145
|
+
invalidateProfiles(): void;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Boot-time guard: the SELECTED backend's package must at least RESOLVE, so a
|
|
149
|
+
* broken install refuses to start instead of reporting healthy and failing
|
|
150
|
+
* every agent turn (the guarantee the old static import gave, restored without
|
|
151
|
+
* giving up the lazy load — `require.resolve` never executes the module, so
|
|
152
|
+
* the Agent SDK still loads on first use only). Called by `createApp()` next
|
|
153
|
+
* to the auth assertions; skipped when an explicit registry is injected.
|
|
154
|
+
*
|
|
155
|
+
* An unrecognized AGENT_BACKEND fails here too, for the same reason.
|
|
156
|
+
*
|
|
157
|
+
* The `resolve` parameter exists for tests (simulating an absent package);
|
|
158
|
+
* production callers pass nothing.
|
|
159
|
+
*/
|
|
160
|
+
export declare function assertBackendResolvable(agent: AgentConfig, resolve?: (specifier: string) => void): void;
|
|
161
|
+
export declare function createBackendRegistry(options: BackendRegistryOptions): BackendRegistry;
|
|
162
|
+
/**
|
|
163
|
+
* A registry over an explicit backend list — the seam tests (and embedders
|
|
164
|
+
* with their own backend wiring) use instead of mutating module state. Takes
|
|
165
|
+
* the same optional hidden-ids reader so visibility behavior matches
|
|
166
|
+
* production.
|
|
167
|
+
*/
|
|
168
|
+
export declare function createStaticBackendRegistry(backends: AgentBackend[], defaultBackendId?: string, options?: {
|
|
169
|
+
getHiddenModelIds?: () => string[];
|
|
170
|
+
}): BackendRegistry;
|
|
45
171
|
//# sourceMappingURL=backend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../src/agent/backend.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../src/agent/backend.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACpB,MAAM,iCAAiC,CAAC;AAEzC;;;;;;;;;;;;;;;GAeG;AA0BH,kFAAkF;AAClF,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,+DAA+D;IAC/D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,uDAAuD;IACvD,MAAM,CAAC,EAAE,SAAS,GAAG,UAAU,GAAG,YAAY,CAAC;CAChD;AAED,kEAAkE;AAClE,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,EAA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