indusagi-coding-agent 0.2.3 → 0.2.5
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/CHANGELOG.md +25 -0
- package/LICENSE +661 -0
- package/README.md +95 -1
- package/dist/entry.js +3205 -1585
- package/dist/guardrails.js +47 -515
- package/dist/index.js +3232 -1671
- package/package.json +8 -7
- package/dist/types/addons/addons.test.d.ts +0 -21
- package/dist/types/addons/contract.d.ts +0 -640
- package/dist/types/addons/dispatch/event-dispatcher.d.ts +0 -140
- package/dist/types/addons/dispatch/index.d.ts +0 -23
- package/dist/types/addons/dispatch/tool-interceptor.d.ts +0 -128
- package/dist/types/addons/host.d.ts +0 -246
- package/dist/types/addons/index.d.ts +0 -51
- package/dist/types/addons/manifest.d.ts +0 -56
- package/dist/types/addons/sandbox.d.ts +0 -103
- package/dist/types/addons/surface.d.ts +0 -42
- package/dist/types/boot/auth-vault.d.ts +0 -29
- package/dist/types/boot/boot.d.ts +0 -26
- package/dist/types/boot/boot.test.d.ts +0 -15
- package/dist/types/boot/contract.d.ts +0 -236
- package/dist/types/boot/index.d.ts +0 -20
- package/dist/types/boot/invocation.d.ts +0 -40
- package/dist/types/boot/invocation.test.d.ts +0 -8
- package/dist/types/boot/runners/addon-wiring.d.ts +0 -103
- package/dist/types/boot/runners/addon-wiring.test.d.ts +0 -19
- package/dist/types/boot/runners/checkpoint.d.ts +0 -133
- package/dist/types/boot/runners/checkpoint.test.d.ts +0 -12
- package/dist/types/boot/runners/delegate-runner.d.ts +0 -89
- package/dist/types/boot/runners/delegate-runner.test.d.ts +0 -13
- package/dist/types/boot/runners/index.d.ts +0 -13
- package/dist/types/boot/runners/link-runner.d.ts +0 -20
- package/dist/types/boot/runners/memdir.d.ts +0 -103
- package/dist/types/boot/runners/memdir.test.d.ts +0 -12
- package/dist/types/boot/runners/oneshot-runner.d.ts +0 -19
- package/dist/types/boot/runners/read-state.d.ts +0 -82
- package/dist/types/boot/runners/read-state.test.d.ts +0 -10
- package/dist/types/boot/runners/registry.d.ts +0 -30
- package/dist/types/boot/runners/repl-runner.d.ts +0 -19
- package/dist/types/boot/runners/session-persist.test.d.ts +0 -10
- package/dist/types/boot/runners/session.d.ts +0 -65
- package/dist/types/boot/runners/session.test.d.ts +0 -10
- package/dist/types/boot/stages.d.ts +0 -92
- package/dist/types/boot/upgrade/apply.d.ts +0 -45
- package/dist/types/boot/upgrade/index.d.ts +0 -13
- package/dist/types/boot/upgrade/upgrades.d.ts +0 -126
- package/dist/types/briefing/briefing.test.d.ts +0 -15
- package/dist/types/briefing/compose.d.ts +0 -37
- package/dist/types/briefing/context-docs.d.ts +0 -38
- package/dist/types/briefing/context-docs.test.d.ts +0 -18
- package/dist/types/briefing/contract.d.ts +0 -686
- package/dist/types/briefing/index.d.ts +0 -29
- package/dist/types/briefing/macros.d.ts +0 -206
- package/dist/types/briefing/skills.d.ts +0 -67
- package/dist/types/capability-deck/bridge-ledger/index.d.ts +0 -25
- package/dist/types/capability-deck/bridge-ledger/key.d.ts +0 -65
- package/dist/types/capability-deck/bridge-ledger/ledger.d.ts +0 -129
- package/dist/types/capability-deck/bridge-ledger/network.d.ts +0 -115
- package/dist/types/capability-deck/builtin-bridge.d.ts +0 -114
- package/dist/types/capability-deck/capability-deck.test.d.ts +0 -18
- package/dist/types/capability-deck/cards/bg-process-card.d.ts +0 -99
- package/dist/types/capability-deck/cards/index.d.ts +0 -37
- package/dist/types/capability-deck/cards/memory-card.d.ts +0 -68
- package/dist/types/capability-deck/cards/plan-file.d.ts +0 -56
- package/dist/types/capability-deck/cards/plan-tools.d.ts +0 -97
- package/dist/types/capability-deck/cards/plan-tools.test.d.ts +0 -9
- package/dist/types/capability-deck/cards/saas-card.d.ts +0 -78
- package/dist/types/capability-deck/cards/task-card.d.ts +0 -106
- package/dist/types/capability-deck/cards/todo-card.d.ts +0 -78
- package/dist/types/capability-deck/cards/workflow-card.d.ts +0 -55
- package/dist/types/capability-deck/cards/workflow-card.test.d.ts +0 -12
- package/dist/types/capability-deck/checkpoint.int.test.d.ts +0 -25
- package/dist/types/capability-deck/contract.d.ts +0 -317
- package/dist/types/capability-deck/index.d.ts +0 -46
- package/dist/types/capability-deck/manifest.d.ts +0 -60
- package/dist/types/capability-deck/provision.d.ts +0 -76
- package/dist/types/capability-deck/read-edit-gate.int.test.d.ts +0 -21
- package/dist/types/channels/channels.test.d.ts +0 -15
- package/dist/types/channels/contract.d.ts +0 -489
- package/dist/types/channels/framer.d.ts +0 -49
- package/dist/types/channels/index.d.ts +0 -24
- package/dist/types/channels/link/dialog.d.ts +0 -138
- package/dist/types/channels/link/driver.d.ts +0 -81
- package/dist/types/channels/link/index.d.ts +0 -13
- package/dist/types/channels/link/server.d.ts +0 -70
- package/dist/types/channels/oneshot.d.ts +0 -37
- package/dist/types/channels/ops.d.ts +0 -89
- package/dist/types/channels/session-ops.d.ts +0 -80
- package/dist/types/conductor/bash-guard.d.ts +0 -106
- package/dist/types/conductor/bash-guard.test.d.ts +0 -17
- package/dist/types/conductor/catalog/catalog.d.ts +0 -87
- package/dist/types/conductor/catalog/index.d.ts +0 -14
- package/dist/types/conductor/catalog/matcher.d.ts +0 -47
- package/dist/types/conductor/conductor.d.ts +0 -189
- package/dist/types/conductor/conductor.test.d.ts +0 -10
- package/dist/types/conductor/contract.d.ts +0 -774
- package/dist/types/conductor/diagnostics.d.ts +0 -183
- package/dist/types/conductor/diagnostics.test.d.ts +0 -10
- package/dist/types/conductor/index.d.ts +0 -26
- package/dist/types/conductor/permission-gate.integration.test.d.ts +0 -22
- package/dist/types/conductor/permission-wiring.test.d.ts +0 -14
- package/dist/types/conductor/permissions.d.ts +0 -217
- package/dist/types/conductor/permissions.test.d.ts +0 -12
- package/dist/types/conductor/plan-mode.integration.test.d.ts +0 -23
- package/dist/types/conductor/post-edit-diagnostics.test.d.ts +0 -13
- package/dist/types/conductor/signal-hub/hub.d.ts +0 -83
- package/dist/types/conductor/signal-hub/index.d.ts +0 -19
- package/dist/types/conductor/signal-hub/translate.d.ts +0 -77
- package/dist/types/conductor/skill-parse/index.d.ts +0 -10
- package/dist/types/conductor/skill-parse/parse.d.ts +0 -67
- package/dist/types/conductor/submit.test.d.ts +0 -28
- package/dist/types/conductor/transcript-store/index.d.ts +0 -16
- package/dist/types/conductor/transcript-store/serialize.d.ts +0 -106
- package/dist/types/conductor/transcript-store/serialize.test.d.ts +0 -10
- package/dist/types/conductor/transcript-store/store.d.ts +0 -188
- package/dist/types/console/components/AgentsView.d.ts +0 -41
- package/dist/types/console/components/BackgroundAgents.d.ts +0 -63
- package/dist/types/console/components/BackgroundAgents.test.d.ts +0 -8
- package/dist/types/console/components/Banner.d.ts +0 -110
- package/dist/types/console/components/Composer.d.ts +0 -37
- package/dist/types/console/components/StatusBar.d.ts +0 -42
- package/dist/types/console/components/TerminalConsole.d.ts +0 -32
- package/dist/types/console/components/WorkingIndicator.d.ts +0 -44
- package/dist/types/console/components/WorkingIndicator.test.d.ts +0 -9
- package/dist/types/console/components/banner-sweep.d.ts +0 -55
- package/dist/types/console/components/banner.test.d.ts +0 -9
- package/dist/types/console/components/welcome.d.ts +0 -115
- package/dist/types/console/components/welcome.test.d.ts +0 -9
- package/dist/types/console/console.test.d.ts +0 -19
- package/dist/types/console/contract.d.ts +0 -598
- package/dist/types/console/index.d.ts +0 -34
- package/dist/types/console/input/complete.d.ts +0 -120
- package/dist/types/console/input/dir-reader.d.ts +0 -28
- package/dist/types/console/input/index.d.ts +0 -24
- package/dist/types/console/input/input.test.d.ts +0 -14
- package/dist/types/console/input/keymap.d.ts +0 -193
- package/dist/types/console/input/paste.d.ts +0 -131
- package/dist/types/console/mount.d.ts +0 -53
- package/dist/types/console/overlays/approval-queue.d.ts +0 -71
- package/dist/types/console/overlays/approval.d.ts +0 -104
- package/dist/types/console/overlays/approval.test.d.ts +0 -17
- package/dist/types/console/overlays/auth.d.ts +0 -31
- package/dist/types/console/overlays/boards.d.ts +0 -55
- package/dist/types/console/overlays/host.d.ts +0 -45
- package/dist/types/console/overlays/index.d.ts +0 -15
- package/dist/types/console/overlays/pickers.d.ts +0 -37
- package/dist/types/console/overlays/sessions.d.ts +0 -29
- package/dist/types/console/reducer.d.ts +0 -51
- package/dist/types/console/slash/builtins.d.ts +0 -33
- package/dist/types/console/slash/commands/dynamic.d.ts +0 -57
- package/dist/types/console/slash/commands/dynamic.test.d.ts +0 -9
- package/dist/types/console/slash/commands/integrations.d.ts +0 -28
- package/dist/types/console/slash/commands/integrations.test.d.ts +0 -18
- package/dist/types/console/slash/commands/shared.d.ts +0 -72
- package/dist/types/console/slash/commands/transcript.d.ts +0 -24
- package/dist/types/console/slash/commands/transcript.test.d.ts +0 -10
- package/dist/types/console/slash/commands/workbench.d.ts +0 -21
- package/dist/types/console/slash/commands/workbench.test.d.ts +0 -10
- package/dist/types/console/slash/index.d.ts +0 -34
- package/dist/types/console/slash/registry.d.ts +0 -90
- package/dist/types/console/slash/resolve.d.ts +0 -109
- package/dist/types/console/slash/slash.test.d.ts +0 -18
- package/dist/types/console/startup.d.ts +0 -119
- package/dist/types/console/theme/adapter.d.ts +0 -79
- package/dist/types/console/theme/index.d.ts +0 -18
- package/dist/types/console/theme/palette.d.ts +0 -77
- package/dist/types/console/theme/resolve.d.ts +0 -45
- package/dist/types/console/theme/theme.test.d.ts +0 -16
- package/dist/types/console/theme/tokens.d.ts +0 -62
- package/dist/types/entry.d.ts +0 -17
- package/dist/types/guardrails.d.ts +0 -33
- package/dist/types/index.d.ts +0 -24
- package/dist/types/insight/channel.d.ts +0 -45
- package/dist/types/insight/contract.d.ts +0 -411
- package/dist/types/insight/index.d.ts +0 -26
- package/dist/types/insight/insight.test.d.ts +0 -17
- package/dist/types/insight/recorder.d.ts +0 -63
- package/dist/types/insight/redaction.d.ts +0 -44
- package/dist/types/insight/replay.d.ts +0 -77
- package/dist/types/insight/sampling.d.ts +0 -84
- package/dist/types/insight/serialize.d.ts +0 -54
- package/dist/types/insight/sinks/console.d.ts +0 -36
- package/dist/types/insight/sinks/file.d.ts +0 -37
- package/dist/types/insight/sinks/index.d.ts +0 -16
- package/dist/types/insight/sinks/stream.d.ts +0 -53
- package/dist/types/kit/clipboard-image.d.ts +0 -40
- package/dist/types/kit/external-editor.d.ts +0 -35
- package/dist/types/kit/image.d.ts +0 -102
- package/dist/types/kit/index.d.ts +0 -29
- package/dist/types/kit/kit.test.d.ts +0 -13
- package/dist/types/kit/shell.d.ts +0 -50
- package/dist/types/kit/tool-fetch.d.ts +0 -165
- package/dist/types/launch/catalog.d.ts +0 -51
- package/dist/types/launch/contract.d.ts +0 -387
- package/dist/types/launch/credentials.d.ts +0 -112
- package/dist/types/launch/index.d.ts +0 -28
- package/dist/types/launch/invocation/attachments.d.ts +0 -72
- package/dist/types/launch/invocation/flags.d.ts +0 -59
- package/dist/types/launch/invocation/index.d.ts +0 -23
- package/dist/types/launch/invocation/read.d.ts +0 -52
- package/dist/types/launch/invocation/usage.d.ts +0 -25
- package/dist/types/launch/launch.test.d.ts +0 -20
- package/dist/types/launch/oauth.d.ts +0 -101
- package/dist/types/launch/packages.d.ts +0 -75
- package/dist/types/launch/packages.test.d.ts +0 -15
- package/dist/types/launch/pickers.d.ts +0 -97
- package/dist/types/runtime-bridge/bridges/_drive.d.ts +0 -74
- package/dist/types/runtime-bridge/bridges/builtins.d.ts +0 -77
- package/dist/types/runtime-bridge/bridges/claude-cli.d.ts +0 -37
- package/dist/types/runtime-bridge/bridges/codex-cli.d.ts +0 -27
- package/dist/types/runtime-bridge/bridges/index.d.ts +0 -15
- package/dist/types/runtime-bridge/bridges/indusagi-cli.d.ts +0 -36
- package/dist/types/runtime-bridge/broker.d.ts +0 -182
- package/dist/types/runtime-bridge/contract.d.ts +0 -436
- package/dist/types/runtime-bridge/index.d.ts +0 -21
- package/dist/types/runtime-bridge/runtime-bridge.test.d.ts +0 -17
- package/dist/types/runtime-bridge/sink.d.ts +0 -59
- package/dist/types/sessions/contract.d.ts +0 -79
- package/dist/types/sessions/index.d.ts +0 -11
- package/dist/types/sessions/library.d.ts +0 -95
- package/dist/types/sessions/sessions.test.d.ts +0 -11
- package/dist/types/settings/contract.d.ts +0 -175
- package/dist/types/settings/index.d.ts +0 -13
- package/dist/types/settings/manager.d.ts +0 -109
- package/dist/types/settings/settings.test.d.ts +0 -16
- package/dist/types/transcript-export/index.d.ts +0 -20
- package/dist/types/transcript-export/publish.d.ts +0 -81
- package/dist/types/transcript-export/sgr.d.ts +0 -90
- package/dist/types/transcript-export/template.d.ts +0 -64
- package/dist/types/transcript-export/theme-bridge.d.ts +0 -99
- package/dist/types/transcript-export/transcript-export.test.d.ts +0 -16
- package/dist/types/window-budget/budget/estimate.d.ts +0 -47
- package/dist/types/window-budget/budget/gate.d.ts +0 -37
- package/dist/types/window-budget/budget/index.d.ts +0 -14
- package/dist/types/window-budget/budget/slice.d.ts +0 -38
- package/dist/types/window-budget/condenser.d.ts +0 -73
- package/dist/types/window-budget/contract.d.ts +0 -182
- package/dist/types/window-budget/index.d.ts +0 -17
- package/dist/types/window-budget/microcompact.d.ts +0 -68
- package/dist/types/window-budget/microcompact.test.d.ts +0 -16
- package/dist/types/window-budget/rehydrate.d.ts +0 -56
- package/dist/types/window-budget/summarize/condense.d.ts +0 -70
- package/dist/types/window-budget/summarize/index.d.ts +0 -12
- package/dist/types/window-budget/summarize/prompt.d.ts +0 -56
- package/dist/types/window-budget/window-budget.test.d.ts +0 -18
- package/dist/types/workflow-engine/agent-runner.d.ts +0 -105
- package/dist/types/workflow-engine/agent-runner.test.d.ts +0 -8
- package/dist/types/workflow-engine/display.d.ts +0 -148
- package/dist/types/workflow-engine/display.test.d.ts +0 -1
- package/dist/types/workflow-engine/engine.d.ts +0 -183
- package/dist/types/workflow-engine/engine.test.d.ts +0 -1
- package/dist/types/workflow-engine/index.d.ts +0 -21
- package/dist/types/workflow-engine/parse.d.ts +0 -64
- package/dist/types/workflow-engine/parse.test.d.ts +0 -1
- package/dist/types/workflow-engine/structured-output.d.ts +0 -51
- package/dist/types/workflow-engine/structured-output.test.d.ts +0 -1
- package/dist/types/workspace/brand.d.ts +0 -26
- package/dist/types/workspace/index.d.ts +0 -11
- package/dist/types/workspace/locator.d.ts +0 -50
- package/dist/types/workspace/runtime-detect.d.ts +0 -56
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `indusagi-cli` bridge — drives a peer agent over JSON-RPC.
|
|
3
|
-
*
|
|
4
|
-
* Unlike the CLI bridges, the peer already speaks (a transport-framed form of)
|
|
5
|
-
* the framework event vocabulary, so its messages map onto
|
|
6
|
-
* {@link NormalizedEvent} near-directly. Each inbound {@link ChildMessage.payload}
|
|
7
|
-
* is a JSON-RPC frame:
|
|
8
|
-
* - a **notification** `{ method, params }` streams one turn event:
|
|
9
|
-
* · `stream/text` params `{ delta }` → `text`
|
|
10
|
-
* · `stream/thinking` params `{ delta }` → `thinking`
|
|
11
|
-
* · `stream/toolCall` params `{ id, name, arguments }` → `tool_call`
|
|
12
|
-
* · `session/resume` params `{ resumeToken }` → `resume`
|
|
13
|
-
* · `stream/done` params `{ reason }` → `finish`
|
|
14
|
-
* · `stream/error` params `{ message, aborted }` → `failed`
|
|
15
|
-
* - a **response** `{ id, result | error }` to the opening `runExchange`
|
|
16
|
-
* request: an `error` member fails the exchange; a `result` is treated as a
|
|
17
|
-
* terminal acknowledgement (`finish`) if the stream has not already settled.
|
|
18
|
-
*
|
|
19
|
-
* The opening request is a JSON-RPC `runExchange` call carrying the context,
|
|
20
|
-
* delegate provider, and resume token. The peer is reached only through the
|
|
21
|
-
* injected {@link ChildTransport}; no peer process is spawned here.
|
|
22
|
-
*/
|
|
23
|
-
import type { ExternalRuntimeSpec, RuntimeBridge } from "../contract";
|
|
24
|
-
/**
|
|
25
|
-
* Build the `indusagi-cli` {@link RuntimeBridge}. The bound {@link ExternalRuntimeSpec}
|
|
26
|
-
* is captured so the opening request can forward its `delegate` to the peer; the
|
|
27
|
-
* broker constructs one bridge per spec it routes to.
|
|
28
|
-
*
|
|
29
|
-
* @param spec the runtime annotation whose `delegate` the peer should target
|
|
30
|
-
*/
|
|
31
|
-
export declare function makeIndusagiCliBridge(spec: ExternalRuntimeSpec): RuntimeBridge;
|
|
32
|
-
/**
|
|
33
|
-
* A default `indusagi-cli` bridge bound to a spec with no delegate. Use
|
|
34
|
-
* {@link makeIndusagiCliBridge} when a delegate provider must be forwarded.
|
|
35
|
-
*/
|
|
36
|
-
export declare const indusagiCliBridge: RuntimeBridge;
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RuntimeBroker — the single decision point that routes every turn to either an
|
|
3
|
-
* external runtime (a spawned child coding-agent driven by a {@link RuntimeBridge})
|
|
4
|
-
* or the framework network stream (`streamSimple` over an HTTP provider).
|
|
5
|
-
*
|
|
6
|
-
* The broker is the only component the product asks "how is this turn produced?".
|
|
7
|
-
* It owns three concerns:
|
|
8
|
-
*
|
|
9
|
-
* 1. **Routing.** {@link RuntimeBroker.route} resolves the model's optional
|
|
10
|
-
* {@link ExternalRuntimeSpec} (a `bridge:<adapter>` baseUrl decode) and a
|
|
11
|
-
* matching registered {@link RuntimeBridge}. A model with a spec whose
|
|
12
|
-
* adapter is registered routes `"external"`; everything else routes
|
|
13
|
-
* `"framework"`.
|
|
14
|
-
* 2. **Dispatch.** {@link RuntimeBrokerRuntime.exchange} acts on that decision:
|
|
15
|
-
* for an external route it builds (or is injected) a {@link ChildTransport}
|
|
16
|
-
* and calls {@link RuntimeBridge.runExchange} over it; for a framework route
|
|
17
|
-
* it calls the framework `streamSimple`. Either way it returns the framework
|
|
18
|
-
* {@link AssistantMessageEventStream} the turn streams into — the two paths
|
|
19
|
-
* are indistinguishable to the caller.
|
|
20
|
-
* 3. **Resume persistence.** When a bridge surfaces a `resume` token (a CLI
|
|
21
|
-
* session id / thread id), the broker persists it through an injected
|
|
22
|
-
* {@link RuntimeLinkStore} as a *renamed* custom transcript entry —
|
|
23
|
-
* {@link RUNTIME_LINK_ENTRY} = `"external-runtime-link"`, shape
|
|
24
|
-
* `{ source, bridge, resumeToken, at }` — so a later exchange can reattach
|
|
25
|
-
* the same underlying session. Handle reuse keys on the composite
|
|
26
|
-
* {@link runtimeSourceKey} (`source|model|bridge`), not three separate field
|
|
27
|
-
* comparisons.
|
|
28
|
-
*
|
|
29
|
-
* The {@link ChildTransport} is injectable end to end: a production factory wraps
|
|
30
|
-
* a spawned process, a test factory returns a hand-written fake. The broker never
|
|
31
|
-
* imports `child_process`; nothing here spawns a real `claude`/`codex` binary.
|
|
32
|
-
*/
|
|
33
|
-
import type { Api, AssistantMessageEventStream, ChildTransport, Context, ExchangeOptions, ExternalRuntimeSpec, Model, NormalizedEvent, RuntimeBridge, RuntimeBroker } from "./contract";
|
|
34
|
-
/**
|
|
35
|
-
* The custom transcript-entry tag under which a runtime resume token is logged.
|
|
36
|
-
*
|
|
37
|
-
* The record this build writes is its own `"external-runtime-link"` shape so the
|
|
38
|
-
* persisted log carries no inherited vocabulary. A consumer scanning the active
|
|
39
|
-
* branch backwards for a reattachable session matches on this tag.
|
|
40
|
-
*/
|
|
41
|
-
export declare const RUNTIME_LINK_ENTRY: "external-runtime-link";
|
|
42
|
-
/** The literal type of {@link RUNTIME_LINK_ENTRY}. */
|
|
43
|
-
export type RuntimeLinkEntryTag = typeof RUNTIME_LINK_ENTRY;
|
|
44
|
-
/**
|
|
45
|
-
* The serializable payload persisted under {@link RUNTIME_LINK_ENTRY}.
|
|
46
|
-
*
|
|
47
|
-
* The renamed shape: `{ source, bridge, resumeToken, at }`. `source` is the
|
|
48
|
-
* model's provider slug, `bridge` is the owning {@link RuntimeBridge.adapter},
|
|
49
|
-
* `resumeToken` is the reattachable CLI session id / thread id the child
|
|
50
|
-
* reported, and `at` is the ISO instant it was captured. Reuse keys on
|
|
51
|
-
* {@link runtimeSourceKey}, derived from `source` + model id + `bridge`.
|
|
52
|
-
*/
|
|
53
|
-
export interface RuntimeLink {
|
|
54
|
-
/** The model's provider slug (its `source`). */
|
|
55
|
-
readonly source: string;
|
|
56
|
-
/** The owning bridge adapter id. */
|
|
57
|
-
readonly bridge: string;
|
|
58
|
-
/** The reattachable session id / thread id reported by the child runtime. */
|
|
59
|
-
readonly resumeToken: string;
|
|
60
|
-
/** ISO-8601 instant the token was captured. */
|
|
61
|
-
readonly at: string;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Compose the composite reuse key a broker matches a persisted {@link RuntimeLink}
|
|
65
|
-
* against. A single `source|model|bridge` string rather than three field
|
|
66
|
-
* comparisons — a stored link is reattachable iff its key equals the key of the
|
|
67
|
-
* exchange about to run.
|
|
68
|
-
*
|
|
69
|
-
* @param source the model provider slug
|
|
70
|
-
* @param modelId the model id
|
|
71
|
-
* @param bridge the bridge adapter id
|
|
72
|
-
*/
|
|
73
|
-
export declare function runtimeSourceKey(source: string, modelId: string, bridge: string): string;
|
|
74
|
-
/**
|
|
75
|
-
* Injectable persistence boundary for resume tokens. The conductor's transcript
|
|
76
|
-
* store binds a real implementation (appending a {@link RUNTIME_LINK_ENTRY} custom
|
|
77
|
-
* entry to the active branch and scanning it backwards on lookup); tests pass an
|
|
78
|
-
* in-memory fake. Both methods are async to match a disk-backed transcript.
|
|
79
|
-
*/
|
|
80
|
-
export interface RuntimeLinkStore {
|
|
81
|
-
/**
|
|
82
|
-
* Persist a captured resume token as a renamed custom transcript entry. Called
|
|
83
|
-
* once per `resume` event a bridge surfaces during an exchange.
|
|
84
|
-
*
|
|
85
|
-
* @param link the renamed link record to append
|
|
86
|
-
*/
|
|
87
|
-
save(link: RuntimeLink): Promise<void> | void;
|
|
88
|
-
/**
|
|
89
|
-
* Resolve the most recent reattachable token for a reuse key, or `undefined`
|
|
90
|
-
* when the active branch holds no matching {@link RUNTIME_LINK_ENTRY}. The key
|
|
91
|
-
* is {@link runtimeSourceKey}.
|
|
92
|
-
*
|
|
93
|
-
* @param sourceKey the composite `source|model|bridge` reuse key
|
|
94
|
-
*/
|
|
95
|
-
find(sourceKey: string): Promise<string | undefined> | string | undefined;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* The context handed to a {@link ChildTransportFactory} when the broker needs a
|
|
99
|
-
* transport for an external exchange. Carries everything a production factory
|
|
100
|
-
* needs to launch + wire the child (the resolved spec's binary/args/env, the
|
|
101
|
-
* working directory, a resume token to reattach) without the broker itself
|
|
102
|
-
* touching `child_process`.
|
|
103
|
-
*/
|
|
104
|
-
export interface TransportContext {
|
|
105
|
-
/** The resolved runtime spec (binary, args, env, delegate) for the child. */
|
|
106
|
-
readonly spec: ExternalRuntimeSpec;
|
|
107
|
-
/** The bound model the exchange runs for. */
|
|
108
|
-
readonly model: Model<Api>;
|
|
109
|
-
/** The per-exchange options (session id, cwd, resume, stream opts). */
|
|
110
|
-
readonly opts: ExchangeOptions;
|
|
111
|
-
/** A persisted resume token resolved for this exchange, if any. */
|
|
112
|
-
readonly resume?: string;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Mints a {@link ChildTransport} for an external exchange. The single seam the
|
|
116
|
-
* broker reaches the outside world through: a production factory spawns the
|
|
117
|
-
* process and adapts its stdio/RPC into the transport; a test factory returns a
|
|
118
|
-
* scripted fake. The broker calls it lazily, only on an external route.
|
|
119
|
-
*/
|
|
120
|
-
export type ChildTransportFactory = (ctx: TransportContext) => ChildTransport;
|
|
121
|
-
/** The framework network-stream signature the broker falls through to. */
|
|
122
|
-
export type FrameworkStream = (model: Model<Api>, context: Context, opts: ExchangeOptions) => AssistantMessageEventStream;
|
|
123
|
-
/**
|
|
124
|
-
* Construction-time dependencies for {@link createRuntimeBroker}. All optional —
|
|
125
|
-
* an empty broker registers bridges later, routes everything to the framework
|
|
126
|
-
* until a transport factory is wired, and skips persistence when no store is set.
|
|
127
|
-
*/
|
|
128
|
-
export interface RuntimeBrokerDeps {
|
|
129
|
-
/**
|
|
130
|
-
* The seam that builds a {@link ChildTransport} for an external exchange. When
|
|
131
|
-
* absent, an external route still *decides* `"external"` but {@link
|
|
132
|
-
* RuntimeBrokerRuntime.exchange} cannot drive a child — so it falls through to
|
|
133
|
-
* the framework path. Tests inject a fake-transport factory here.
|
|
134
|
-
*/
|
|
135
|
-
readonly transportFactory?: ChildTransportFactory;
|
|
136
|
-
/** Where resume tokens persist; omitted ⇒ tokens are not persisted. */
|
|
137
|
-
readonly linkStore?: RuntimeLinkStore;
|
|
138
|
-
/**
|
|
139
|
-
* Override for the framework network stream (defaults to `streamSimple`).
|
|
140
|
-
* Injected in tests so the framework path is observable without a network.
|
|
141
|
-
*/
|
|
142
|
-
readonly frameworkStream?: FrameworkStream;
|
|
143
|
-
/** Bridges to pre-register at construction (equivalent to calling `register`). */
|
|
144
|
-
readonly bridges?: readonly RuntimeBridge[];
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* The broker the product drives. Extends the frozen {@link RuntimeBroker} routing
|
|
148
|
-
* surface with {@link exchange}: the dispatch half that acts on a {@link route}
|
|
149
|
-
* decision and returns the framework stream the turn streams into.
|
|
150
|
-
*/
|
|
151
|
-
export interface RuntimeBrokerRuntime extends RuntimeBroker {
|
|
152
|
-
/**
|
|
153
|
-
* Produce the turn for `model`. Routes (via {@link RuntimeBroker.route}); on an
|
|
154
|
-
* `"external"` route with a wired transport factory it drives the bridge's
|
|
155
|
-
* `runExchange` over a freshly-built {@link ChildTransport} (resolving + later
|
|
156
|
-
* persisting the resume token); otherwise it runs the framework stream. Returns
|
|
157
|
-
* the {@link AssistantMessageEventStream} synchronously, like `streamSimple`.
|
|
158
|
-
*
|
|
159
|
-
* @param model the model the turn is bound to
|
|
160
|
-
* @param context the framework conversation context
|
|
161
|
-
* @param opts per-exchange options
|
|
162
|
-
*/
|
|
163
|
-
exchange(model: Model<Api>, context: Context, opts?: ExchangeOptions): AssistantMessageEventStream;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Construct a {@link RuntimeBrokerRuntime}. The single sanctioned way to obtain a
|
|
167
|
-
* broker: build one with optional dependencies (a transport factory, a resume
|
|
168
|
-
* link store, a framework-stream override, pre-registered bridges), then
|
|
169
|
-
* {@link RuntimeBroker.register} further bridges and drive turns through
|
|
170
|
-
* {@link RuntimeBrokerRuntime.exchange} / {@link RuntimeBroker.route}.
|
|
171
|
-
*
|
|
172
|
-
* @param deps optional construction-time dependencies
|
|
173
|
-
*/
|
|
174
|
-
export declare function createRuntimeBroker(deps?: RuntimeBrokerDeps): RuntimeBrokerRuntime;
|
|
175
|
-
/**
|
|
176
|
-
* The normalized resume-event kind a bridge emits — re-exported so a transport
|
|
177
|
-
* tap / consumer can name the same `"resume"` discriminant the sink ignores on
|
|
178
|
-
* the stream but the broker persists out of band.
|
|
179
|
-
*/
|
|
180
|
-
export type ResumeEvent = Extract<NormalizedEvent, {
|
|
181
|
-
kind: "resume";
|
|
182
|
-
}>;
|
|
@@ -1,436 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Runtime-bridge contract — the FROZEN type surface of provider *routing*.
|
|
3
|
-
*
|
|
4
|
-
* This module is the single typed seam that decides, per model, **where a turn
|
|
5
|
-
* is actually produced**: by the framework's own network stream
|
|
6
|
-
* (`streamSimple` over an HTTP provider) or by an *external runtime* — a child
|
|
7
|
-
* coding-agent process driven over its own protocol (an Anthropic-flavoured CLI
|
|
8
|
-
* speaking line-delimited JSON, an OpenAI-flavoured CLI emitting `--json`
|
|
9
|
-
* items, or a peer agent reachable over JSON-RPC). The product never calls a
|
|
10
|
-
* bridge or the framework stream directly; it asks the {@link RuntimeBroker} to
|
|
11
|
-
* route, and the broker picks the path.
|
|
12
|
-
*
|
|
13
|
-
* Design stance:
|
|
14
|
-
* - A model is *annotated*, not re-catalogued. The model catalog/matcher
|
|
15
|
-
* (Phase 2) own the {@link Model} list; this layer only attaches an optional
|
|
16
|
-
* {@link ExternalRuntimeSpec} that says "this model is backed by a spawned
|
|
17
|
-
* CLI / a peer agent, here is how to reach it and authenticate". A model
|
|
18
|
-
* with no spec routes normally.
|
|
19
|
-
* - Every external runtime speaks a *different* wire dialect, but the broker
|
|
20
|
-
* should not care. So each bridge is reduced to a **parser** that yields a
|
|
21
|
-
* provider-neutral {@link NormalizedEvent} stream, and the single
|
|
22
|
-
* {@link BridgeEventSink} translates those events into the framework's
|
|
23
|
-
* {@link AssistantMessageEventStream} push shape. The imperative
|
|
24
|
-
* `pushStart/pushTextDelta/pushDone` idiom lives in exactly one place.
|
|
25
|
-
* - The child process / RPC peer a bridge drives is reached through an
|
|
26
|
-
* **injectable** {@link ChildTransport}, never a hard-coded `spawn`. Tests
|
|
27
|
-
* hand the bridge a fake transport so no real `claude`/`codex` binary is
|
|
28
|
-
* launched.
|
|
29
|
-
* - Authentication policy is data, not control flow:
|
|
30
|
-
* {@link RuntimeBridge.requiresCredential} answers "does this model need a
|
|
31
|
-
* key on disk before it can be offered?" — a spawned-CLI runtime that owns
|
|
32
|
-
* its own auth returns `false`, letting the model appear available with no
|
|
33
|
-
* key.
|
|
34
|
-
*
|
|
35
|
-
* Framework anchors (all from the sibling rebuilt framework, the `indusagi`
|
|
36
|
-
* package) — consumed verbatim, never re-derived:
|
|
37
|
-
* - `Model`, `Context`, `AssistantMessage`, `AssistantMessageEventStream`,
|
|
38
|
-
* `Api`, `StopReason`, `ToolCall`, `Usage`, `SimpleStreamOptions`,
|
|
39
|
-
* `KnownProvider` ← `indusagi/ai`
|
|
40
|
-
* - `streamSimple` is the network fallback the broker routes to.
|
|
41
|
-
*
|
|
42
|
-
* Interface-dictated shapes preserved as-is:
|
|
43
|
-
* - the `bridge:<adapter>` synthetic endpoint convention for runtime-backed
|
|
44
|
-
* models (so a catalog entry has a stable, non-HTTP `baseUrl`);
|
|
45
|
-
* - the external CLI protocol vocabularies (Anthropic stream-json content
|
|
46
|
-
* blocks, OpenAI `--json` items, peer JSON-RPC requests) — surfaced only as
|
|
47
|
-
* the opaque payloads a {@link ChildTransport} carries, never re-expressed.
|
|
48
|
-
*/
|
|
49
|
-
import type { Api, AssistantMessage, AssistantMessageEventStream, Context, KnownProvider, Model, SimpleStreamOptions, StopReason, ToolCall } from "indusagi/ai";
|
|
50
|
-
/** Re-exported framework vocabulary routing consumers routinely compose. */
|
|
51
|
-
export type { Api, AssistantMessage, AssistantMessageEventStream, Context, KnownProvider, Model, SimpleStreamOptions, StopReason, ToolCall, };
|
|
52
|
-
/**
|
|
53
|
-
* The set of bridge adapters this layer ships.
|
|
54
|
-
*
|
|
55
|
-
* Each value names a concrete {@link RuntimeBridge} implementation and the wire
|
|
56
|
-
* dialect it speaks:
|
|
57
|
-
* - `"claude-cli"` — drives an Anthropic-flavoured CLI emitting
|
|
58
|
-
* line-delimited stream-json content blocks.
|
|
59
|
-
* - `"codex-cli"` — drives an OpenAI-flavoured CLI emitting `--json`
|
|
60
|
-
* turn/item events.
|
|
61
|
-
* - `"indusagi-cli"` — drives a peer agent over JSON-RPC; the child already
|
|
62
|
-
* speaks the framework event vocabulary, so its events
|
|
63
|
-
* map onto {@link NormalizedEvent} near-directly.
|
|
64
|
-
*
|
|
65
|
-
* Left open (`(string & {})`) so an extension can register a further adapter
|
|
66
|
-
* without editing this union, while the three shipped ids keep autocompletion.
|
|
67
|
-
*/
|
|
68
|
-
export type RuntimeAdapterId = "claude-cli" | "codex-cli" | "indusagi-cli" | (string & {});
|
|
69
|
-
/**
|
|
70
|
-
* How a model bound to an external runtime authenticates.
|
|
71
|
-
*
|
|
72
|
-
* - `"external-cli"` — the spawned child owns its own auth (its own login /
|
|
73
|
-
* keychain); the product needs **no** key on disk, so the model can be
|
|
74
|
-
* offered as available with an empty vault. This is the policy that makes a
|
|
75
|
-
* CLI-backed model "just work" once the underlying tool is logged in.
|
|
76
|
-
* - `"api-key"` — the runtime still needs an API key resolved from the
|
|
77
|
-
* credential vault, same as a normal HTTP provider; only the *transport*
|
|
78
|
-
* differs.
|
|
79
|
-
*/
|
|
80
|
-
export type RuntimeAuthMode = "external-cli" | "api-key";
|
|
81
|
-
/**
|
|
82
|
-
* The annotation that turns an ordinary {@link Model} into an external-runtime
|
|
83
|
-
* model. Attached alongside a catalog card (it is *additive* metadata — the
|
|
84
|
-
* catalog/matcher are unaware of it) and consulted by the {@link RuntimeBroker}
|
|
85
|
-
* to decide routing.
|
|
86
|
-
*
|
|
87
|
-
* All transport fields are optional: a bridge may have a sensible default
|
|
88
|
-
* binary, take no extra args, inherit the parent environment, and route to its
|
|
89
|
-
* own downstream source. Only {@link adapter} is required, because it selects
|
|
90
|
-
* which {@link RuntimeBridge} owns the exchange.
|
|
91
|
-
*/
|
|
92
|
-
export interface ExternalRuntimeSpec {
|
|
93
|
-
/** Which bridge owns this model's exchange (the {@link RuntimeBridge.adapter}). */
|
|
94
|
-
readonly adapter: RuntimeAdapterId;
|
|
95
|
-
/** Whether the runtime needs a key on disk, or owns its own auth. */
|
|
96
|
-
readonly authMode: RuntimeAuthMode;
|
|
97
|
-
/** Override for the child executable to launch (defaults to the bridge's own). */
|
|
98
|
-
readonly binaryPath?: string;
|
|
99
|
-
/** Extra command-line arguments prepended to the bridge's protocol flags. */
|
|
100
|
-
readonly args?: readonly string[];
|
|
101
|
-
/** Environment overrides merged into the child process environment. */
|
|
102
|
-
readonly env?: Readonly<Record<string, string>>;
|
|
103
|
-
/**
|
|
104
|
-
* For a bridge that fronts another source (e.g. a peer agent that itself
|
|
105
|
-
* talks to a downstream provider), the provider slug the child should target.
|
|
106
|
-
* Ignored by bridges that terminate the exchange themselves.
|
|
107
|
-
*/
|
|
108
|
-
readonly delegate?: string;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* The synthetic endpoint scheme stamped onto a runtime-backed model's
|
|
112
|
-
* `baseUrl`. A model annotated with {@link ExternalRuntimeSpec} carries
|
|
113
|
-
* `baseUrl === "${RUNTIME_ENDPOINT_SCHEME}${adapter}"` so it has a stable,
|
|
114
|
-
* non-HTTP address that never resolves to a network host.
|
|
115
|
-
*/
|
|
116
|
-
export declare const RUNTIME_ENDPOINT_SCHEME: "bridge:";
|
|
117
|
-
/** The literal type of {@link RUNTIME_ENDPOINT_SCHEME}. */
|
|
118
|
-
export type RuntimeEndpointScheme = typeof RUNTIME_ENDPOINT_SCHEME;
|
|
119
|
-
/**
|
|
120
|
-
* Compose the synthetic `bridge:<adapter>` endpoint for a runtime-backed model.
|
|
121
|
-
* Inert string helper; the single sanctioned way to mint the convention so it
|
|
122
|
-
* stays uniform across the catalog annotation and the broker's routing check.
|
|
123
|
-
*
|
|
124
|
-
* @param adapter the {@link RuntimeBridge.adapter} owning the model
|
|
125
|
-
*/
|
|
126
|
-
export declare function runtimeEndpoint(adapter: RuntimeAdapterId): string;
|
|
127
|
-
/**
|
|
128
|
-
* A provider-neutral streamed event — the common currency between a bridge's
|
|
129
|
-
* per-dialect parser and the {@link BridgeEventSink}.
|
|
130
|
-
*
|
|
131
|
-
* Each external runtime emits its own wire vocabulary (Anthropic content
|
|
132
|
-
* blocks, OpenAI items, peer JSON-RPC events). A bridge's only job is to map
|
|
133
|
-
* that vocabulary onto this small, closed union; the sink then translates a
|
|
134
|
-
* {@link NormalizedEvent} into the matching framework
|
|
135
|
-
* {@link AssistantMessageEventStream} push call. This is the seam that removes
|
|
136
|
-
* the per-bridge `stream.push*` duplication.
|
|
137
|
-
*
|
|
138
|
-
* Variants:
|
|
139
|
-
* - `text` — a chunk of assistant answer text.
|
|
140
|
-
* - `thinking` — a chunk of reasoning text (runtimes without a thinking
|
|
141
|
-
* channel simply never emit this).
|
|
142
|
-
* - `tool_call`— a fully-formed tool invocation the child decided on.
|
|
143
|
-
* - `resume` — the child reported a session/thread id the bridge can persist
|
|
144
|
-
* to reattach the underlying CLI session after a restart.
|
|
145
|
-
* - `finish` — the exchange settled successfully with a terminal reason.
|
|
146
|
-
* - `failed` — the exchange ended in error.
|
|
147
|
-
*/
|
|
148
|
-
export type NormalizedEvent = {
|
|
149
|
-
readonly kind: "text";
|
|
150
|
-
readonly delta: string;
|
|
151
|
-
} | {
|
|
152
|
-
readonly kind: "thinking";
|
|
153
|
-
readonly delta: string;
|
|
154
|
-
} | {
|
|
155
|
-
readonly kind: "tool_call";
|
|
156
|
-
readonly call: ToolCall;
|
|
157
|
-
} | {
|
|
158
|
-
readonly kind: "resume";
|
|
159
|
-
readonly resumeToken: string;
|
|
160
|
-
} | {
|
|
161
|
-
readonly kind: "finish";
|
|
162
|
-
readonly reason: FinishReason;
|
|
163
|
-
} | {
|
|
164
|
-
readonly kind: "failed";
|
|
165
|
-
readonly error: BridgeFailure;
|
|
166
|
-
};
|
|
167
|
-
/** The discriminant literals of {@link NormalizedEvent}, for filtering/logging. */
|
|
168
|
-
export type NormalizedEventKind = NormalizedEvent["kind"];
|
|
169
|
-
/** Extract a single member of {@link NormalizedEvent} by its `kind`. */
|
|
170
|
-
export type NormalizedEventOf<K extends NormalizedEventKind> = Extract<NormalizedEvent, {
|
|
171
|
-
kind: K;
|
|
172
|
-
}>;
|
|
173
|
-
/**
|
|
174
|
-
* The terminal reasons an external exchange can settle on. A subset of the
|
|
175
|
-
* framework's {@link StopReason} — the non-error outcomes a bridge reports to
|
|
176
|
-
* the sink, which then emits the framework `done` event.
|
|
177
|
-
*/
|
|
178
|
-
export type FinishReason = Extract<StopReason, "stop" | "length" | "toolUse">;
|
|
179
|
-
/**
|
|
180
|
-
* A typed failure surfaced by a bridge when an external exchange breaks. The
|
|
181
|
-
* `aborted` flag distinguishes a caller-cancelled exchange (the child was
|
|
182
|
-
* interrupted) from a genuine fault, so the sink can emit the matching
|
|
183
|
-
* framework error reason (`aborted` vs `error`).
|
|
184
|
-
*/
|
|
185
|
-
export interface BridgeFailure {
|
|
186
|
-
/** Human-readable, single-line summary of what went wrong. */
|
|
187
|
-
readonly message: string;
|
|
188
|
-
/** True when the exchange was cancelled rather than failing on its own. */
|
|
189
|
-
readonly aborted?: boolean;
|
|
190
|
-
/** Underlying error or structured detail, if any. */
|
|
191
|
-
readonly cause?: unknown;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* The single push-stream helper every bridge writes through.
|
|
195
|
-
*
|
|
196
|
-
* It owns the accumulating {@link AssistantMessage}, the content-block index
|
|
197
|
-
* bookkeeping, and the lazily-started lifecycle (the first emission opens the
|
|
198
|
-
* stream). A bridge never touches {@link AssistantMessageEventStream} directly;
|
|
199
|
-
* it constructs a sink, drives it with normalized events, and returns the
|
|
200
|
-
* sink's {@link stream}. This centralizes the
|
|
201
|
-
* `ensureStarted → push* → finishSuccess/finishError` idiom so the per-bridge
|
|
202
|
-
* code is purely a parser.
|
|
203
|
-
*
|
|
204
|
-
* The convenience methods cover the common path; {@link emit} accepts a raw
|
|
205
|
-
* {@link NormalizedEvent} for parsers that prefer to yield the union directly.
|
|
206
|
-
*/
|
|
207
|
-
export interface BridgeEventSink {
|
|
208
|
-
/**
|
|
209
|
-
* Open the underlying stream and push the framework `start` event, if it has
|
|
210
|
-
* not already started. Idempotent: safe to call before any emission, and a
|
|
211
|
-
* no-op once started. The convenience emitters call it implicitly.
|
|
212
|
-
*/
|
|
213
|
-
start(): void;
|
|
214
|
-
/** Append a chunk of assistant answer text (opens a text block on first call). */
|
|
215
|
-
text(delta: string): void;
|
|
216
|
-
/** Append a chunk of reasoning text (opens a thinking block on first call). */
|
|
217
|
-
thinking(delta: string): void;
|
|
218
|
-
/** Emit a fully-formed tool call as its own content block. */
|
|
219
|
-
toolCall(call: ToolCall): void;
|
|
220
|
-
/**
|
|
221
|
-
* Map one {@link NormalizedEvent} onto the matching push call. The single
|
|
222
|
-
* entry point a parser can drive with the raw union; dispatches to
|
|
223
|
-
* {@link text} / {@link thinking} / {@link toolCall} / {@link finishSuccess} /
|
|
224
|
-
* {@link finishError} by `kind`. A `resume` event is informational and does
|
|
225
|
-
* not touch the stream.
|
|
226
|
-
*/
|
|
227
|
-
emit(event: NormalizedEvent): void;
|
|
228
|
-
/**
|
|
229
|
-
* Settle the exchange successfully: close any open block, finalize the
|
|
230
|
-
* accumulated message, and push the framework `done` event with `reason`.
|
|
231
|
-
* Terminal — no further emissions are valid after this.
|
|
232
|
-
*
|
|
233
|
-
* @param reason the terminal stop reason (defaults to `"stop"`)
|
|
234
|
-
*/
|
|
235
|
-
finishSuccess(reason?: FinishReason): void;
|
|
236
|
-
/**
|
|
237
|
-
* Settle the exchange in error: push the framework `error` event. The
|
|
238
|
-
* {@link BridgeFailure.aborted} flag selects the framework error reason
|
|
239
|
-
* (`aborted` vs `error`). Terminal.
|
|
240
|
-
*
|
|
241
|
-
* @param error the typed bridge failure
|
|
242
|
-
*/
|
|
243
|
-
finishError(error: BridgeFailure): void;
|
|
244
|
-
/**
|
|
245
|
-
* The framework push stream the broker hands back to its caller. Populated
|
|
246
|
-
* asynchronously as the bridge drives the sink; consumers iterate it exactly
|
|
247
|
-
* as they would the stream `streamSimple` returns.
|
|
248
|
-
*/
|
|
249
|
-
readonly stream: AssistantMessageEventStream;
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* A single message exchanged with the child runtime over its {@link ChildTransport}.
|
|
253
|
-
*
|
|
254
|
-
* The `payload` is deliberately opaque: it is whatever the underlying protocol
|
|
255
|
-
* carries — a parsed JSON line from a CLI's NDJSON stdout, a JSON-RPC
|
|
256
|
-
* notification from a peer agent, a raw text chunk. The bridge that owns the
|
|
257
|
-
* transport knows how to interpret it; the contract only fixes the envelope so
|
|
258
|
-
* the transport interface itself is dialect-agnostic and mockable.
|
|
259
|
-
*/
|
|
260
|
-
export interface ChildMessage {
|
|
261
|
-
/** The protocol payload (a parsed JSON value, a text line, an RPC frame). */
|
|
262
|
-
readonly payload: unknown;
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* A request sent *to* the child runtime. The bridge formats the dialect-specific
|
|
266
|
-
* body; the transport only relays it. `body` is opaque for the same reason
|
|
267
|
-
* {@link ChildMessage.payload} is.
|
|
268
|
-
*/
|
|
269
|
-
export interface ChildRequest {
|
|
270
|
-
/** The dialect-specific request body the bridge constructed. */
|
|
271
|
-
readonly body: unknown;
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* The injectable boundary between a bridge and the actual child process / RPC
|
|
275
|
-
* peer it drives.
|
|
276
|
-
*
|
|
277
|
-
* A production transport wraps a spawned process (its stdin/stdout, or a
|
|
278
|
-
* JSON-RPC client over that process); a test transport is a hand-written fake
|
|
279
|
-
* that records `send`s and replays canned {@link ChildMessage}s — so a bridge's
|
|
280
|
-
* parser can be exercised with **no real binary launched**. The bridge depends
|
|
281
|
-
* only on this interface, never on `child_process` directly.
|
|
282
|
-
*/
|
|
283
|
-
export interface ChildTransport {
|
|
284
|
-
/**
|
|
285
|
-
* Relay one {@link ChildRequest} to the child (e.g. write a prompt to stdin or
|
|
286
|
-
* issue a JSON-RPC call). Resolves once the request has been handed off.
|
|
287
|
-
*
|
|
288
|
-
* @param request the dialect-specific request to deliver
|
|
289
|
-
*/
|
|
290
|
-
send(request: ChildRequest): Promise<void>;
|
|
291
|
-
/**
|
|
292
|
-
* Register a listener for inbound {@link ChildMessage}s from the child
|
|
293
|
-
* (stdout lines, RPC notifications). Returns an unsubscribe function.
|
|
294
|
-
*
|
|
295
|
-
* @param listener invoked for each inbound message
|
|
296
|
-
* @returns a disposer that removes the listener
|
|
297
|
-
*/
|
|
298
|
-
onMessage(listener: (message: ChildMessage) => void): () => void;
|
|
299
|
-
/**
|
|
300
|
-
* Terminate the child and release the transport. Idempotent; safe to call on
|
|
301
|
-
* an already-closed transport. After `close`, `send` rejects and no further
|
|
302
|
-
* messages are delivered.
|
|
303
|
-
*/
|
|
304
|
-
close(): Promise<void>;
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Per-exchange options threaded into {@link RuntimeBridge.runExchange} (and the
|
|
308
|
-
* framework `streamSimple` fallback the broker also drives).
|
|
309
|
-
*
|
|
310
|
-
* Extends the framework's {@link SimpleStreamOptions} (so `signal`, `apiKey`,
|
|
311
|
-
* `reasoning`, etc. flow straight through to the network path) with the
|
|
312
|
-
* routing-layer extras a bridge needs:
|
|
313
|
-
* - {@link sessionId} correlates the exchange with a persisted runtime session
|
|
314
|
-
* so the bridge can resume the underlying CLI session.
|
|
315
|
-
* - {@link cwd} is the working directory the child runtime is scoped to.
|
|
316
|
-
* - {@link resume} carries a previously-persisted token (e.g. a CLI session id
|
|
317
|
-
* / thread id) the bridge reattaches to instead of starting fresh.
|
|
318
|
-
*/
|
|
319
|
-
export interface ExchangeOptions extends SimpleStreamOptions {
|
|
320
|
-
/** Stable session id to correlate / persist the runtime session under. */
|
|
321
|
-
readonly sessionId?: string;
|
|
322
|
-
/** Working directory the child runtime is scoped to (defaults to process cwd). */
|
|
323
|
-
readonly cwd?: string;
|
|
324
|
-
/** A resume token from a prior exchange to reattach the underlying session. */
|
|
325
|
-
readonly resume?: string;
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* One external-runtime adapter: the strategy that produces a turn for a model
|
|
329
|
-
* whose {@link ExternalRuntimeSpec} names it.
|
|
330
|
-
*
|
|
331
|
-
* A bridge is the dialect specialist. Given the bound {@link Model}, the
|
|
332
|
-
* {@link Context}, per-exchange {@link ExchangeOptions}, and an **injected**
|
|
333
|
-
* {@link ChildTransport}, it drives the child and returns the framework push
|
|
334
|
-
* stream the turn streams into. The transport is a parameter (not constructed
|
|
335
|
-
* internally) precisely so tests pass a fake and no real CLI is spawned.
|
|
336
|
-
*
|
|
337
|
-
* Bridges hold no per-session state on the contract surface; live session
|
|
338
|
-
* handles and reuse/persistence are the {@link RuntimeBroker}'s concern.
|
|
339
|
-
*/
|
|
340
|
-
export interface RuntimeBridge {
|
|
341
|
-
/** The adapter id this bridge answers to (matched against {@link ExternalRuntimeSpec.adapter}). */
|
|
342
|
-
readonly adapter: RuntimeAdapterId;
|
|
343
|
-
/**
|
|
344
|
-
* Drive one exchange against the external runtime and return the framework
|
|
345
|
-
* push stream it streams into. Returns the stream **synchronously** (the
|
|
346
|
-
* stream is populated asynchronously as the child emits), matching the shape
|
|
347
|
-
* of the framework's own `streamSimple`. The implementation reads inbound
|
|
348
|
-
* {@link ChildMessage}s off `transport`, parses them into
|
|
349
|
-
* {@link NormalizedEvent}s, and feeds a {@link BridgeEventSink}.
|
|
350
|
-
*
|
|
351
|
-
* @param model the bound framework model for this exchange
|
|
352
|
-
* @param context the framework conversation context
|
|
353
|
-
* @param opts per-exchange options (session id, cwd, resume, stream opts)
|
|
354
|
-
* @param transport the injected child boundary to drive
|
|
355
|
-
*/
|
|
356
|
-
runExchange(model: Model<Api>, context: Context, opts: ExchangeOptions, transport: ChildTransport): AssistantMessageEventStream;
|
|
357
|
-
/**
|
|
358
|
-
* Whether a model bound to this bridge needs a credential on disk before it
|
|
359
|
-
* can be offered. Returns `false` for an `"external-cli"` spec whose child
|
|
360
|
-
* owns its own auth (so the model is available with an empty vault), `true`
|
|
361
|
-
* for an `"api-key"` spec. The central auth-routing predicate.
|
|
362
|
-
*
|
|
363
|
-
* @param spec the external-runtime annotation to evaluate
|
|
364
|
-
*/
|
|
365
|
-
requiresCredential(spec: ExternalRuntimeSpec): boolean;
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* The outcome of a routing decision: either an external runtime owns the
|
|
369
|
-
* exchange, or it falls through to the framework network stream.
|
|
370
|
-
*
|
|
371
|
-
* - `"external"` carries the chosen {@link RuntimeBridge} and the resolved
|
|
372
|
-
* {@link ExternalRuntimeSpec} the broker will drive `runExchange` with.
|
|
373
|
-
* - `"framework"` signals the caller to run the framework `streamSimple` path
|
|
374
|
-
* unchanged.
|
|
375
|
-
*/
|
|
376
|
-
export type RuntimeRoute = {
|
|
377
|
-
readonly target: "external";
|
|
378
|
-
readonly bridge: RuntimeBridge;
|
|
379
|
-
readonly spec: ExternalRuntimeSpec;
|
|
380
|
-
} | {
|
|
381
|
-
readonly target: "framework";
|
|
382
|
-
};
|
|
383
|
-
/**
|
|
384
|
-
* The router and registry over {@link RuntimeBridge}s — the single decision
|
|
385
|
-
* point for "external runtime vs framework stream".
|
|
386
|
-
*
|
|
387
|
-
* The broker is asked to {@link route} every turn. If the model carries an
|
|
388
|
-
* {@link ExternalRuntimeSpec} whose adapter resolves to a registered bridge,
|
|
389
|
-
* the broker returns an `"external"` route the caller drives via the bridge's
|
|
390
|
-
* `runExchange`; otherwise it returns a `"framework"` route and the caller runs
|
|
391
|
-
* `streamSimple`. Bridges are {@link register}ed at assembly time and looked up
|
|
392
|
-
* by adapter id.
|
|
393
|
-
*/
|
|
394
|
-
export interface RuntimeBroker {
|
|
395
|
-
/**
|
|
396
|
-
* Add a {@link RuntimeBridge} to the registry, keyed by its
|
|
397
|
-
* {@link RuntimeBridge.adapter}. Registering an adapter id that already exists
|
|
398
|
-
* replaces the prior bridge.
|
|
399
|
-
*
|
|
400
|
-
* @param bridge the bridge to register
|
|
401
|
-
*/
|
|
402
|
-
register(bridge: RuntimeBridge): void;
|
|
403
|
-
/**
|
|
404
|
-
* Decide how to produce a turn for `model`. Resolves the model's
|
|
405
|
-
* {@link ExternalRuntimeSpec} (via {@link resolveSpec}) and a matching
|
|
406
|
-
* registered bridge; returns an `"external"` route when both are present and
|
|
407
|
-
* the bridge's credential requirement is satisfiable, else a `"framework"`
|
|
408
|
-
* route. The framework `context`/`opts` are accepted so an implementation may
|
|
409
|
-
* factor them into routing, even though the base decision keys on the model.
|
|
410
|
-
*
|
|
411
|
-
* @param model the model the turn is bound to
|
|
412
|
-
* @param context the framework conversation context for the turn
|
|
413
|
-
* @param opts per-exchange options
|
|
414
|
-
*/
|
|
415
|
-
route(model: Model<Api>, context: Context, opts: ExchangeOptions): RuntimeRoute;
|
|
416
|
-
/**
|
|
417
|
-
* Resolve the {@link ExternalRuntimeSpec} annotated onto a model, or
|
|
418
|
-
* `undefined` when the model is a plain HTTP-provider model. How the spec is
|
|
419
|
-
* attached (a side-table keyed by canonical id, a field on a catalog card, a
|
|
420
|
-
* `bridge:<adapter>` baseUrl decode) is the implementation's choice; the
|
|
421
|
-
* contract only fixes the lookup.
|
|
422
|
-
*
|
|
423
|
-
* @param model the model to inspect for a runtime annotation
|
|
424
|
-
*/
|
|
425
|
-
resolveSpec(model: Model<Api>): ExternalRuntimeSpec | undefined;
|
|
426
|
-
/**
|
|
427
|
-
* Whether a runtime-annotated model needs a credential on disk before it can
|
|
428
|
-
* be offered as available. Delegates to the owning bridge's
|
|
429
|
-
* {@link RuntimeBridge.requiresCredential}; returns `false` for a model with
|
|
430
|
-
* no spec only when the caller treats "no runtime" as "framework auth applies
|
|
431
|
-
* elsewhere" — so this answers strictly the *runtime* credential question.
|
|
432
|
-
*
|
|
433
|
-
* @param spec the runtime annotation to evaluate
|
|
434
|
-
*/
|
|
435
|
-
requiresCredential(spec: ExternalRuntimeSpec): boolean;
|
|
436
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Runtime-bridge subsystem — public barrel.
|
|
3
|
-
*
|
|
4
|
-
* Re-exports the FROZEN provider-routing contract: the external-runtime
|
|
5
|
-
* annotation ({@link ExternalRuntimeSpec} + the `bridge:<adapter>` endpoint
|
|
6
|
-
* convention), the provider-neutral {@link NormalizedEvent} union, the single
|
|
7
|
-
* {@link BridgeEventSink} push-stream helper, the injectable
|
|
8
|
-
* {@link ChildTransport} boundary, and the routing surface itself
|
|
9
|
-
* ({@link RuntimeBridge}, {@link RuntimeBroker}, {@link RuntimeRoute}).
|
|
10
|
-
*
|
|
11
|
-
* Behavior modules (the concrete bridges under `bridges/`, the sink
|
|
12
|
-
* implementation, the broker) are added to this barrel as they land; consumers
|
|
13
|
-
* import the routing surface from `src/runtime-bridge` rather than reaching into
|
|
14
|
-
* individual modules.
|
|
15
|
-
*/
|
|
16
|
-
export type { RuntimeAdapterId, RuntimeAuthMode, ExternalRuntimeSpec, RuntimeEndpointScheme, NormalizedEvent, NormalizedEventKind, NormalizedEventOf, FinishReason, BridgeFailure, BridgeEventSink, ChildMessage, ChildRequest, ChildTransport, ExchangeOptions, RuntimeBridge, RuntimeBroker, RuntimeRoute, Api, AssistantMessage, AssistantMessageEventStream, Context, KnownProvider, Model, SimpleStreamOptions, StopReason, ToolCall, } from "./contract";
|
|
17
|
-
export { RUNTIME_ENDPOINT_SCHEME, runtimeEndpoint } from "./contract";
|
|
18
|
-
export type { BridgeMessageSeed } from "./sink";
|
|
19
|
-
export { createBridgeSink } from "./sink";
|
|
20
|
-
export { claudeCliBridge, codexCliBridge, indusagiCliBridge, makeIndusagiCliBridge, BUILTIN_RUNTIME_SPECS, BUILTIN_ADAPTERS, builtinRuntimeSpec, annotateCard, withRuntimeEndpoint, specFromModel, type RuntimeAnnotatedModel, driveExchange, seedFromModel, type ChildParser, type ParseStep, } from "./bridges";
|
|
21
|
-
export { createRuntimeBroker, runtimeSourceKey, RUNTIME_LINK_ENTRY, type RuntimeBrokerRuntime, type RuntimeBrokerDeps, type ChildTransportFactory, type TransportContext, type FrameworkStream, type RuntimeLink, type RuntimeLinkStore, type RuntimeLinkEntryTag, type ResumeEvent, } from "./broker";
|