opencode-openai-session-router 0.0.0-stage → 0.1.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.
Files changed (45) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +217 -2
  3. package/dist/accounts.d.ts +31 -0
  4. package/dist/bun.lock.txt +671 -0
  5. package/dist/chunks/index-85yd61pa.js +29 -0
  6. package/dist/chunks/index-n7sr1hee.js +803 -0
  7. package/dist/index.d.ts +4 -0
  8. package/dist/index.js +1842 -0
  9. package/dist/network.d.ts +8 -0
  10. package/dist/panel-contract.d.ts +14 -0
  11. package/dist/persistence.d.ts +40 -0
  12. package/dist/relay-protocol.d.ts +86 -0
  13. package/dist/relay.d.ts +50 -0
  14. package/dist/retry-control.d.ts +41 -0
  15. package/dist/router.d.ts +55 -0
  16. package/dist/rpc.d.ts +98 -0
  17. package/dist/rpc.js +7 -0
  18. package/dist/runtime.d.ts +94 -0
  19. package/dist/settings.d.ts +32 -0
  20. package/dist/sidebar-colors.d.ts +10 -0
  21. package/dist/sidebar-model.d.ts +82 -0
  22. package/dist/sidebar.d.ts +33 -0
  23. package/dist/sidebar.js +12 -0
  24. package/dist/tui.d.ts +3 -0
  25. package/dist/tui.js +25 -0
  26. package/package.json +52 -4
  27. package/scripts/build.ts +39 -0
  28. package/src/accounts.ts +130 -0
  29. package/src/index.ts +203 -0
  30. package/src/network.ts +25 -0
  31. package/src/panel-contract.ts +15 -0
  32. package/src/persistence.ts +96 -0
  33. package/src/relay-protocol.ts +157 -0
  34. package/src/relay.ts +593 -0
  35. package/src/retry-control.ts +92 -0
  36. package/src/router.ts +156 -0
  37. package/src/rpc.ts +28 -0
  38. package/src/runtime.ts +319 -0
  39. package/src/settings.ts +68 -0
  40. package/src/sidebar-colors.ts +132 -0
  41. package/src/sidebar-model.ts +257 -0
  42. package/src/sidebar.tsx +438 -0
  43. package/src/tui.tsx +12 -0
  44. package/tsconfig.build.json +12 -0
  45. package/tsconfig.json +16 -0
@@ -0,0 +1,8 @@
1
+ type Environment = Readonly<Record<string, string | undefined>>;
2
+ /**
3
+ * Source-aligned with v2.4.4 core/effect/websocket-constructor/options.ts.
4
+ * Public server-owned policy projection, no private import or global env edits.
5
+ * This specifies intended selection, NOT a claim about Bun implicit proxy IO.
6
+ */
7
+ export declare function webSocketProxy(input: string, environment?: Environment): string | undefined;
8
+ export {};
@@ -0,0 +1,14 @@
1
+ /** Public, non-secret UI state. Account indices follow native OpenAI list order. */
2
+ export interface SessionAccountView {
3
+ readonly sessionID: string;
4
+ /** The sticky assignment, not an unconfirmed failover candidate. */
5
+ readonly accountIndex: number | null;
6
+ }
7
+ export interface RouterSnapshot {
8
+ /** OFF delegates new requests to native OpenCode; assignments remain history. */
9
+ readonly enabled: boolean;
10
+ /** Distinguishes runtime reloads, whose revision counters restart at zero. */
11
+ readonly instanceID: string;
12
+ readonly revision: number;
13
+ readonly assignments: readonly SessionAccountView[];
14
+ }
@@ -0,0 +1,40 @@
1
+ import type { RoutingState } from "./router";
2
+ /** Only nonsecret identity/primary metadata and the round-robin cursor persist. */
3
+ export interface DurableRouting {
4
+ readonly version: 1;
5
+ readonly sessions: readonly {
6
+ readonly sessionID: string;
7
+ readonly accountID: string | null;
8
+ readonly primary: boolean | null;
9
+ }[];
10
+ readonly cursor: RoutingState["cursor"];
11
+ }
12
+ export interface RoutingStorage {
13
+ get(key: string): Promise<unknown>;
14
+ set(key: string, value: DurableRouting): Promise<void>;
15
+ }
16
+ export declare function routingStorageKey(location: {
17
+ directory: string;
18
+ workspaceID?: string;
19
+ }): string;
20
+ export declare function decodeRouting(value: unknown): DurableRouting;
21
+ /**
22
+ * One atomic KV document, serialized writes per Location activation. Native
23
+ * v2.4.4 loader awaits old scope close before loading its replacement. close()
24
+ * drains BEFORE runtime disposal; no late write survives that handoff.
25
+ * Public storage has no CAS: independent processes for the SAME Location are
26
+ * not fenced. Different Locations have different keys, not a global history.
27
+ */
28
+ export declare class RoutingPersistence {
29
+ private readonly storage;
30
+ private readonly key;
31
+ private tail;
32
+ private saved;
33
+ private closed;
34
+ private hydrated;
35
+ private failed;
36
+ constructor(storage: RoutingStorage, key: string);
37
+ hydrate(): Promise<DurableRouting | undefined>;
38
+ save(state: DurableRouting): void;
39
+ close(): Promise<void>;
40
+ }
@@ -0,0 +1,86 @@
1
+ declare const decode: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => {
2
+ readonly [x: string]: unknown;
3
+ readonly type: string;
4
+ readonly delta?: string | undefined;
5
+ readonly arguments?: string | undefined;
6
+ readonly text?: string | undefined;
7
+ readonly item_id?: string | undefined;
8
+ readonly output_index?: number | undefined;
9
+ readonly summary_index?: number | undefined;
10
+ readonly item?: {
11
+ readonly [x: string]: unknown;
12
+ readonly type: string;
13
+ readonly id?: string | undefined;
14
+ readonly call_id?: string | undefined;
15
+ readonly name?: string | undefined;
16
+ readonly namespace?: string | undefined;
17
+ readonly arguments?: string | undefined;
18
+ readonly encrypted_content?: string | null | undefined;
19
+ } | null | undefined;
20
+ readonly response?: {
21
+ readonly [x: string]: unknown;
22
+ readonly id?: string | undefined;
23
+ readonly service_tier?: string | null | undefined;
24
+ readonly incomplete_details?: {
25
+ readonly reason?: string | undefined;
26
+ } | null | undefined;
27
+ readonly output?: readonly {
28
+ readonly [x: string]: unknown;
29
+ readonly type: string;
30
+ readonly id?: string | undefined;
31
+ readonly call_id?: string | undefined;
32
+ readonly name?: string | undefined;
33
+ readonly namespace?: string | undefined;
34
+ readonly arguments?: string | undefined;
35
+ readonly encrypted_content?: string | null | undefined;
36
+ }[] | undefined;
37
+ readonly usage?: {
38
+ readonly [x: string]: unknown;
39
+ readonly input_tokens?: number | undefined;
40
+ readonly input_tokens_details?: {
41
+ readonly [x: string]: unknown;
42
+ readonly cached_tokens?: number | undefined;
43
+ readonly cache_write_tokens?: number | undefined;
44
+ } | null | undefined;
45
+ readonly output_tokens?: number | undefined;
46
+ readonly output_tokens_details?: {
47
+ readonly [x: string]: unknown;
48
+ readonly reasoning_tokens?: number | undefined;
49
+ } | null | undefined;
50
+ readonly total_tokens?: number | undefined;
51
+ } | null | undefined;
52
+ readonly error?: unknown;
53
+ } | undefined;
54
+ readonly code?: unknown;
55
+ readonly message?: unknown;
56
+ readonly error?: unknown;
57
+ readonly status?: unknown;
58
+ readonly status_code?: unknown;
59
+ };
60
+ type NativeEvent = ReturnType<typeof decode>;
61
+ export declare function wireEvent(raw: string): NativeEvent;
62
+ export declare const terminal: (event: Record<string, any>) => boolean;
63
+ /** Admission uses ONLY numeric wire status429, never wording/code-derived guesses. */
64
+ export declare function wire429(event: Record<string, any>): boolean;
65
+ /**
66
+ * WS may omit numeric status. Use ONLY these exact affirmative native codes at
67
+ * published errorDetail precedence. No wording, substring or HTTP400 admission.
68
+ * Official Responses schemas permit absent status; actual Codex incidence is
69
+ * unverified. Conflicting/malformed evidence closes the exchange, not guesses.
70
+ */
71
+ export declare function wsLimit(event: Record<string, any>): boolean;
72
+ /** Conservative native lifecycle observer. Host still performs authoritative parsing. */
73
+ export declare class ResponseLifecycle {
74
+ private id?;
75
+ private ended;
76
+ private invalid;
77
+ visible: boolean;
78
+ success: boolean;
79
+ private parser;
80
+ observe(event: NativeEvent): void;
81
+ }
82
+ export declare function compactSuccess(raw: string, signal?: AbortSignal): Promise<boolean>;
83
+ export declare const sseFrame: (raw: string) => string;
84
+ /** SSE framing only; protocol payloads use the native codec. UTF8/chunk-safe. */
85
+ export declare function sseData(body: ReadableStream<Uint8Array>, signal: AbortSignal, maxFrame?: number): AsyncGenerator<string>;
86
+ export {};
@@ -0,0 +1,50 @@
1
+ import { type OAuthFamily } from "./accounts";
2
+ import { RouterRuntime, type LogicalCall } from "./runtime";
3
+ interface Binding {
4
+ readonly call: LogicalCall;
5
+ readonly family: OAuthFamily;
6
+ }
7
+ export interface RelayDependencies {
8
+ headers(id: string, family: OAuthFamily, source: Headers, signal?: AbortSignal): Promise<Headers>;
9
+ /** Dependency injection is server-only, never a plugin/user proxy setting. */
10
+ fetch?: (input: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) => Promise<Response>;
11
+ connect?: (url: string, headers: Headers) => WebSocket;
12
+ }
13
+ /** Owns only loopback transport; the host retains the bundled provider/model/parser. */
14
+ export declare class SessionRelay {
15
+ readonly runtime: RouterRuntime;
16
+ private readonly dependencies;
17
+ private readonly auth;
18
+ private readonly owned;
19
+ private readonly sockets;
20
+ private readonly server;
21
+ private closed;
22
+ private readonly sendHTTP;
23
+ private readonly connect;
24
+ constructor(runtime: RouterRuntime, dependencies: RelayDependencies);
25
+ get origin(): string;
26
+ bind(call: LogicalCall, selected: OAuthFamily): string;
27
+ localHeaders(headers: Headers): Headers;
28
+ /** Resolve transport metadata without interpreting model names or HTTP content. */
29
+ binding(url: string, sessionID: string, model: {
30
+ providerID: string;
31
+ id: string;
32
+ variant?: string;
33
+ }, kind: string): Binding | undefined;
34
+ private prune;
35
+ private authenticated;
36
+ private target;
37
+ private open;
38
+ private accept;
39
+ /** Same authenticated HTTP handler for listener and public hook in-process dispatch. */
40
+ respondHTTP(request: Request, invocationSignal?: AbortSignal): Promise<Response>;
41
+ private start;
42
+ private seal;
43
+ private cached;
44
+ private failure;
45
+ private httpExchange;
46
+ private wsExchange;
47
+ private wsAttempt;
48
+ close(): void;
49
+ }
50
+ export {};
@@ -0,0 +1,41 @@
1
+ export interface ModelRef {
2
+ readonly providerID: string;
3
+ readonly id: string;
4
+ readonly variant?: string;
5
+ }
6
+ export interface ManagedFailure {
7
+ readonly sessionID: string;
8
+ readonly model: ModelRef;
9
+ readonly kind: "primary" | "compaction" | "generate" | "title";
10
+ readonly handle: string;
11
+ }
12
+ export interface RetryContext {
13
+ readonly sessionID: string;
14
+ readonly model: ModelRef;
15
+ readonly error: {
16
+ readonly response?: {
17
+ readonly body: string;
18
+ };
19
+ };
20
+ }
21
+ export declare const CONTROL = "_opencode_local_router";
22
+ export declare const ORIGINAL = "_opencode_local_original";
23
+ export declare const record: (value: unknown) => value is Record<string, any>;
24
+ /**
25
+ * LOCAL wire diagnostics, inserted only on confirmed native limit termination
26
+ * (HTTP/wire429 or the exact WS-only affirmative code admission predicate).
27
+ * HOST's bundled provider constructs/parses its own errors. No SDK AIError
28
+ * instance or model implementation crosses the host module-identity boundary.
29
+ */
30
+ export declare class RetryControl {
31
+ #private;
32
+ private readonly runtimeID;
33
+ constructor(runtimeID: string);
34
+ private mac;
35
+ seal(original: string, failure: ManagedFailure, requestURL: string): string;
36
+ verify(context: RetryContext): {
37
+ originalBody: string;
38
+ failure: ManagedFailure;
39
+ } | undefined;
40
+ dispose(): void;
41
+ }
@@ -0,0 +1,55 @@
1
+ /** API-independent routing core for opencode-openai-session-router. */
2
+ export declare class NoAccountsError extends Error {
3
+ constructor();
4
+ }
5
+ export interface RoutingRequest {
6
+ readonly sessionId: string;
7
+ readonly revision: number;
8
+ readonly candidates: readonly string[];
9
+ }
10
+ export interface RoutingState {
11
+ readonly assignments: readonly (readonly [string, string])[];
12
+ readonly cursor: {
13
+ readonly nextAccountID: string | null;
14
+ readonly order: readonly string[];
15
+ };
16
+ }
17
+ export declare class SessionRouter {
18
+ private accounts;
19
+ private nextAccountId;
20
+ private cursorOrder;
21
+ private readonly assignments;
22
+ private readonly revisions;
23
+ private revision;
24
+ constructor(accountIds: readonly string[]);
25
+ /**
26
+ * Account IDs must be stable identities, not positions in an external list.
27
+ * Retain the next round-robin account if possible; otherwise use its next
28
+ * surviving successor in the old order, or the first new account.
29
+ * Historical assignments survive pool changes; unavailable accounts allocate
30
+ * again only on the next request, never merely on metadata refresh.
31
+ */
32
+ setAccounts(accountIds: readonly string[]): void;
33
+ state(): RoutingState;
34
+ /** Startup only: no calls/capabilities or CAS revisions survive a generation. */
35
+ restore(state: RoutingState): void;
36
+ getAssignedAccount(sessionId: string): string | undefined;
37
+ entries(): readonly (readonly [string, string])[];
38
+ removeSession(sessionId: string): void;
39
+ begin(sessionId: string): RoutingRequest;
40
+ /** An accepted completion invalidates every older overlapping request. */
41
+ commit(request: RoutingRequest, accountId: string): boolean;
42
+ /** A fresh logical request gets a fresh, bounded candidate snapshot. */
43
+ getCandidates(sessionId: string): readonly string[];
44
+ /**
45
+ * The adapter classifies rate-limit errors (e.g. HTTP 429); all other errors
46
+ * stop immediately. Exhaustion throws the last rate-limit error unchanged.
47
+ * No clocks, cooldowns, or cross-request failure state are maintained.
48
+ *
49
+ * Changes during an attempt: new accounts wait until the next request;
50
+ * removed accounts are skipped and cannot become assigned on success.
51
+ * Concurrent requests are independent; stale completions cannot overwrite
52
+ * an assignment accepted since their request began.
53
+ */
54
+ run<T>(sessionId: string, attempt: (accountId: string) => T | Promise<T>, isRateLimit: (error: unknown) => boolean): Promise<T>;
55
+ }
package/dist/rpc.d.ts ADDED
@@ -0,0 +1,98 @@
1
+ import { Schema } from "effect";
2
+ /** Public payloads deliberately contain no native connection IDs or labels. */
3
+ export declare const RouterRpc: {
4
+ readonly id: "opencode-openai-session-router";
5
+ readonly methods: {
6
+ readonly snapshot: {
7
+ readonly input: import("effect/StandardSchema").StandardSchemaV1<{}, {}> & Schema.Struct<{}>;
8
+ readonly output: import("effect/StandardSchema").StandardSchemaV1<{
9
+ readonly enabled: boolean;
10
+ readonly instanceID: string;
11
+ readonly revision: number;
12
+ readonly assignments: readonly {
13
+ readonly sessionID: string;
14
+ readonly accountIndex: number | null;
15
+ }[];
16
+ }, {
17
+ readonly enabled: boolean;
18
+ readonly instanceID: string;
19
+ readonly revision: number;
20
+ readonly assignments: readonly {
21
+ readonly sessionID: string;
22
+ readonly accountIndex: number | null;
23
+ }[];
24
+ }> & Schema.Struct<{
25
+ readonly enabled: Schema.Boolean;
26
+ readonly instanceID: Schema.String;
27
+ readonly revision: Schema.Number;
28
+ readonly assignments: Schema.$Array<Schema.Struct<{
29
+ readonly sessionID: Schema.String;
30
+ readonly accountIndex: Schema.NullOr<Schema.Number>;
31
+ }>>;
32
+ }>;
33
+ };
34
+ readonly setEnabled: {
35
+ readonly input: import("effect/StandardSchema").StandardSchemaV1<{
36
+ readonly enabled: boolean;
37
+ }, {
38
+ readonly enabled: boolean;
39
+ }> & Schema.Struct<{
40
+ readonly enabled: Schema.Boolean;
41
+ }>;
42
+ readonly output: import("effect/StandardSchema").StandardSchemaV1<{
43
+ readonly enabled: boolean;
44
+ readonly instanceID: string;
45
+ readonly revision: number;
46
+ readonly assignments: readonly {
47
+ readonly sessionID: string;
48
+ readonly accountIndex: number | null;
49
+ }[];
50
+ }, {
51
+ readonly enabled: boolean;
52
+ readonly instanceID: string;
53
+ readonly revision: number;
54
+ readonly assignments: readonly {
55
+ readonly sessionID: string;
56
+ readonly accountIndex: number | null;
57
+ }[];
58
+ }> & Schema.Struct<{
59
+ readonly enabled: Schema.Boolean;
60
+ readonly instanceID: Schema.String;
61
+ readonly revision: Schema.Number;
62
+ readonly assignments: Schema.$Array<Schema.Struct<{
63
+ readonly sessionID: Schema.String;
64
+ readonly accountIndex: Schema.NullOr<Schema.Number>;
65
+ }>>;
66
+ }>;
67
+ };
68
+ };
69
+ readonly events: {
70
+ readonly changed: {
71
+ readonly schema: import("effect/StandardSchema").StandardSchemaV1<{
72
+ readonly enabled: boolean;
73
+ readonly instanceID: string;
74
+ readonly revision: number;
75
+ readonly assignments: readonly {
76
+ readonly sessionID: string;
77
+ readonly accountIndex: number | null;
78
+ }[];
79
+ }, {
80
+ readonly enabled: boolean;
81
+ readonly instanceID: string;
82
+ readonly revision: number;
83
+ readonly assignments: readonly {
84
+ readonly sessionID: string;
85
+ readonly accountIndex: number | null;
86
+ }[];
87
+ }> & Schema.Struct<{
88
+ readonly enabled: Schema.Boolean;
89
+ readonly instanceID: Schema.String;
90
+ readonly revision: Schema.Number;
91
+ readonly assignments: Schema.$Array<Schema.Struct<{
92
+ readonly sessionID: Schema.String;
93
+ readonly accountIndex: Schema.NullOr<Schema.Number>;
94
+ }>>;
95
+ }>;
96
+ };
97
+ };
98
+ };
package/dist/rpc.js ADDED
@@ -0,0 +1,7 @@
1
+ // @bun
2
+ import {
3
+ RouterRpc
4
+ } from "./chunks/index-85yd61pa.js";
5
+ export {
6
+ RouterRpc
7
+ };
@@ -0,0 +1,94 @@
1
+ import { SessionRouter, type RoutingRequest } from "./router";
2
+ import type { RouterSnapshot } from "./panel-contract";
3
+ import { RetryControl, type ModelRef } from "./retry-control";
4
+ import type { DurableRouting } from "./persistence";
5
+ /** Only pre-verified compatible IDs enter this store; never credentials. */
6
+ export interface AccountView {
7
+ readonly id: string;
8
+ /** Position in the FULL native credential order, not the compatible pool. */
9
+ readonly index: number;
10
+ }
11
+ export interface LogicalCall {
12
+ readonly handle: string;
13
+ readonly sessionID: string;
14
+ readonly kind: "primary" | "compaction" | "title" | "generate";
15
+ readonly model?: ModelRef;
16
+ routing: RoutingRequest;
17
+ tried: Set<string>;
18
+ limited: Set<string>;
19
+ inFlight: number;
20
+ outcome: "new" | "success" | "failure";
21
+ recency: number;
22
+ cancelled?: boolean;
23
+ sentWebSocket?: boolean;
24
+ readonly aborts: Set<AbortController>;
25
+ /** Retained until explicit host lifecycle cleanup, including native re-entry. */
26
+ exhaustion?: {
27
+ readonly error: unknown;
28
+ };
29
+ }
30
+ export interface RoutingOperation {
31
+ readonly call: LogicalCall;
32
+ readonly routing: RoutingRequest;
33
+ readonly tried: Set<string>;
34
+ readonly limited: Set<string>;
35
+ readonly retainedError?: unknown;
36
+ terminalError?: unknown;
37
+ succeeded: boolean;
38
+ }
39
+ /**
40
+ * Only executing entries are protected. Eviction never recreates an operation:
41
+ * an evicted handle fails locally before provider traffic. Success is retained
42
+ * for native compaction's same-prepared-request nudge; that nudge is a NEW bounded
43
+ * operation, starting at the current sticky assignment and CAS revision.
44
+ */
45
+ export declare class RouterRuntime {
46
+ private readonly capacity;
47
+ readonly router: SessionRouter;
48
+ private accounts;
49
+ private nativeOrder;
50
+ private readonly calls;
51
+ private readonly primary;
52
+ private readonly listeners;
53
+ private readonly durableListeners;
54
+ private durableText;
55
+ private current;
56
+ private enabledValue;
57
+ private disposed;
58
+ private sequence;
59
+ readonly retryControl: RetryControl;
60
+ constructor(capacity?: number);
61
+ get enabled(): boolean;
62
+ /** Admission policy only: never cancel calls, reset the cursor or erase history. */
63
+ setEnabled(enabled: boolean): RouterSnapshot;
64
+ setAccounts(accounts: readonly AccountView[], nativeOrder?: readonly AccountView[]): void;
65
+ private validateOrder;
66
+ /** Metadata-only display refresh; never resolve OAuth just to show history. */
67
+ setNativeOrder(nativeOrder: readonly AccountView[]): void;
68
+ restore(state: DurableRouting): void;
69
+ durableSnapshot(): DurableRouting;
70
+ subscribeDurable(listener: (state: DurableRouting) => void): () => void;
71
+ /** Auxiliary requests do not change which account the primary UI displays. */
72
+ setPrimaryProvider(sessionID: string, nativeOpenAI: boolean): void;
73
+ begin(sessionID: string, kind: LogicalCall["kind"], model?: ModelRef): LogicalCall;
74
+ lookup(handle: string): LogicalCall | undefined;
75
+ contains(call: LogicalCall): boolean;
76
+ enter(call: LogicalCall): RoutingOperation;
77
+ complete(operation: RoutingOperation, accountID: string): void;
78
+ retain(operation: RoutingOperation, error: unknown): void;
79
+ end(operation: RoutingOperation): void;
80
+ available(accountID: string): boolean;
81
+ commit(call: LogicalCall, accountID: string): boolean;
82
+ release(handle: string): void;
83
+ releaseSessionCalls(sessionID: string, primaryOnly?: boolean): void;
84
+ removeSession(sessionID: string): void;
85
+ snapshot(): RouterSnapshot;
86
+ subscribe(listener: (snapshot: RouterSnapshot) => void): () => void;
87
+ /** Stop admission/completions without destroying values still being saved. */
88
+ stop(): void;
89
+ dispose(): void;
90
+ cancel(call: LogicalCall): void;
91
+ cancelPrimary(sessionID: string): void;
92
+ private assertOpen;
93
+ private publish;
94
+ }
@@ -0,0 +1,32 @@
1
+ export interface RoutingSettings {
2
+ readonly version: 1;
3
+ readonly enabled: boolean;
4
+ }
5
+ export interface SettingsStorage {
6
+ get(key: string): Promise<unknown>;
7
+ set(key: string, value: RoutingSettings): Promise<void>;
8
+ }
9
+ /** Separate document: existing strict routing/v1 mapping bytes/schema stay valid. */
10
+ export declare const settingsStorageKey: (location: {
11
+ directory: string;
12
+ workspaceID?: string;
13
+ }) => string;
14
+ /**
15
+ * Same Location/native-loader boundary as RoutingPersistence: one atomic KV
16
+ * value, ordered writes, drained close before replacement hydration. No public
17
+ * storage CAS exists; independent same-Location processes are not fenced.
18
+ */
19
+ export declare class SettingsPersistence {
20
+ private readonly storage;
21
+ private readonly key;
22
+ private hydrated;
23
+ private closed;
24
+ private desired;
25
+ private failed;
26
+ private tail;
27
+ private lastWrite;
28
+ constructor(storage: SettingsStorage, key: string);
29
+ hydrate(): Promise<boolean>;
30
+ save(enabled: boolean): Promise<void>;
31
+ close(): Promise<void>;
32
+ }
@@ -0,0 +1,10 @@
1
+ import { RGBA } from "@opentui/core";
2
+ import type { SidebarAgent } from "./sidebar-model";
3
+ export type SidebarColor = string | RGBA;
4
+ /** Reproduces the public theme's categorical-400 palette used for agent colors. */
5
+ export declare function categoricalAgentPalette(categorical: unknown): SidebarColor[];
6
+ export declare function configuredAgentColor(value: string | undefined): value is string;
7
+ /** Mirrors OMO-Slim's explicit-color, roster-index, then muted fallback order. */
8
+ export declare function resolveAgentColor(agentID: string | undefined, roster: readonly SidebarAgent[], palette: readonly SidebarColor[], muted: SidebarColor): SidebarColor;
9
+ export declare function themeColor(theme: unknown, paths: readonly (readonly (string | number)[])[], fallback: SidebarColor): SidebarColor;
10
+ export declare function resolveHoverBackground(theme: unknown): SidebarColor;
@@ -0,0 +1,82 @@
1
+ export interface SidebarSession {
2
+ readonly id: string;
3
+ readonly parentID?: string;
4
+ readonly agent?: string;
5
+ readonly title?: string;
6
+ readonly time: {
7
+ readonly updated: number;
8
+ readonly busy?: number;
9
+ readonly idle?: number;
10
+ };
11
+ }
12
+ export interface SidebarRow {
13
+ readonly sessionID: string;
14
+ readonly agent: string;
15
+ readonly accountIndex: number | null;
16
+ readonly orchestrator: boolean;
17
+ readonly title: string;
18
+ }
19
+ export declare const BASELINE_SESSIONS = 10;
20
+ export declare const BASELINE_CHILDREN: number;
21
+ export declare const PAGE_SIZE = 10;
22
+ export interface SidebarAgent {
23
+ readonly id: string;
24
+ readonly name: string;
25
+ readonly color?: string;
26
+ readonly hidden?: boolean;
27
+ }
28
+ export interface RouterSnapshotLike {
29
+ readonly enabled: boolean;
30
+ readonly instanceID: string;
31
+ readonly revision: number;
32
+ readonly assignments: readonly {
33
+ readonly sessionID: string;
34
+ readonly accountIndex: number | null;
35
+ }[];
36
+ }
37
+ export interface SnapshotEpochState {
38
+ readonly snapshot?: RouterSnapshotLike;
39
+ readonly requestToken: number;
40
+ readonly requestBaseInstanceID?: string;
41
+ readonly requestBaseRevision?: number;
42
+ readonly retiredInstanceIDs: ReadonlySet<string>;
43
+ }
44
+ export declare function initialSnapshotEpochState(): SnapshotEpochState;
45
+ export declare function beginSnapshotRequest(state: SnapshotEpochState): SnapshotEpochState;
46
+ export declare function snapshotRequestIsAuthoritative(state: SnapshotEpochState, requestToken: number, baseInstanceID?: string, baseRevision?: number): boolean;
47
+ export declare function acceptSnapshotEvent(state: SnapshotEpochState, incoming: RouterSnapshotLike): SnapshotEpochState;
48
+ export declare function acceptSnapshotFetch(state: SnapshotEpochState, incoming: RouterSnapshotLike, requestToken: number): SnapshotEpochState;
49
+ export declare function navigateSidebarRow(sessionID: string, navigate: (sessionID: string) => void): void;
50
+ export declare function moreCount(totalChildren: number, visibleChildren: number): number;
51
+ export declare function nextVisibleChildren(visibleChildren: number, totalChildren: number): number;
52
+ export declare function toggleSidebarCollapsed(collapsed: boolean): boolean;
53
+ export interface PrimaryPointerEvent {
54
+ readonly button: number;
55
+ readonly x: number;
56
+ readonly y: number;
57
+ readonly isDragging?: boolean;
58
+ readonly stopPropagation: () => void;
59
+ readonly preventDefault: () => void;
60
+ }
61
+ export declare function createPrimaryClickHandler(activate: (target: string) => void): {
62
+ down(target: string, event: PrimaryPointerEvent): void;
63
+ up(target: string, event: PrimaryPointerEvent): boolean;
64
+ cancel(target: string, event: PrimaryPointerEvent): void;
65
+ cancelAll(event: PrimaryPointerEvent): void;
66
+ invalidate(target: string): void;
67
+ };
68
+ export interface RoutingToggleOptions {
69
+ readonly snapshot?: RouterSnapshotLike;
70
+ readonly directory?: string;
71
+ readonly isPending: () => boolean;
72
+ readonly setPending: (pending: boolean) => void;
73
+ readonly isCurrent: () => boolean;
74
+ readonly setEnabled: (enabled: boolean, directory: string) => Promise<RouterSnapshotLike>;
75
+ readonly accept: (snapshot: RouterSnapshotLike) => void;
76
+ readonly fail: () => void;
77
+ }
78
+ export declare function requestRoutingToggle(options: RoutingToggleOptions): Promise<void>;
79
+ export declare function projectSidebar(rootID: string, sessions: readonly SidebarSession[], accountBySession: ReadonlyMap<string, number | null>, visibleChildren?: number, agents?: readonly SidebarAgent[]): {
80
+ rows: SidebarRow[];
81
+ totalChildren: number;
82
+ };
@@ -0,0 +1,33 @@
1
+ import type { SidebarRow } from "./sidebar-model";
2
+ import type { SidebarColor } from "./sidebar-colors";
3
+ export declare function pointerWithinRenderable(currentTarget: {
4
+ readonly screenX: number;
5
+ readonly screenY: number;
6
+ readonly width: number;
7
+ readonly height: number;
8
+ } | null, x: number, y: number): boolean;
9
+ export declare function SessionSidebar(props: {
10
+ sessionID: string;
11
+ }): import("solid-js").JSX.Element;
12
+ interface SidebarViewProps {
13
+ readonly getRows: () => readonly SidebarRow[];
14
+ readonly totalChildren: number;
15
+ readonly visibleChildren: number;
16
+ readonly collapsed: boolean;
17
+ readonly enabled?: boolean;
18
+ readonly togglePending: boolean;
19
+ readonly treeError: boolean;
20
+ readonly rpcError: boolean;
21
+ readonly toggleError: boolean;
22
+ readonly accent: SidebarColor;
23
+ readonly muted: SidebarColor;
24
+ readonly hoverBackground: SidebarColor;
25
+ readonly rowColor: (row: SidebarRow) => SidebarColor;
26
+ readonly onCollapse: () => void;
27
+ readonly onToggle: () => void;
28
+ readonly onNavigate: (sessionID: string) => void;
29
+ readonly onMore: () => void;
30
+ readonly onLess: () => void;
31
+ }
32
+ export declare function SidebarView(props: SidebarViewProps): import("solid-js").JSX.Element;
33
+ export {};
@@ -0,0 +1,12 @@
1
+ // @bun
2
+ import {
3
+ SessionSidebar,
4
+ SidebarView,
5
+ pointerWithinRenderable
6
+ } from "./chunks/index-n7sr1hee.js";
7
+ import"./chunks/index-85yd61pa.js";
8
+ export {
9
+ pointerWithinRenderable,
10
+ SidebarView,
11
+ SessionSidebar
12
+ };