@ai-sdk/harness 1.0.133 → 1.0.134

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.
@@ -1,36 +1,37 @@
1
- import { ToolResultPart } from '@ai-sdk/provider-utils';
2
-
1
+ import { ToolResultPart } from "@ai-sdk/provider-utils";
2
+ //#region src/bridge/harness-bridge-capability-unsupported-error.d.ts
3
3
  /**
4
4
  * Signals an unsupported capability discovered inside a sandbox bridge.
5
5
  * `isInstance` also recognizes the serialized error shape received by the
6
6
  * host, where it can be translated to `HarnessCapabilityUnsupportedError`.
7
7
  */
8
- declare class HarnessBridgeCapabilityUnsupportedError extends Error {
9
- readonly harnessId?: string;
10
- readonly cause?: unknown;
11
- constructor({ message, harnessId, cause, }: {
12
- message: string;
13
- harnessId?: string;
14
- cause?: unknown;
15
- });
16
- static isInstance(error: unknown): error is HarnessBridgeCapabilityUnsupportedError;
8
+ export declare class HarnessBridgeCapabilityUnsupportedError extends Error {
9
+ readonly harnessId?: string;
10
+ readonly cause?: unknown;
11
+ constructor({ message, harnessId, cause }: {
12
+ message: string;
13
+ harnessId?: string;
14
+ cause?: unknown;
15
+ });
16
+ static isInstance(error: unknown): error is HarnessBridgeCapabilityUnsupportedError;
17
17
  }
18
-
18
+ //#endregion
19
+ //#region src/bridge/index.d.ts
19
20
  type BridgeState = 'init' | 'waiting' | 'running' | 'draining' | 'done';
20
21
  /** Outbound turn event the adapter emits. `seq` is added by the runtime. */
21
22
  type BridgeEvent = Record<string, unknown> & {
22
- type: string;
23
+ type: string;
23
24
  };
24
25
  type BridgeDebugLevel = 'error' | 'warn' | 'info' | 'debug' | 'trace';
25
26
  interface Experimental_BridgeUserMessage {
26
- readonly messageId: string;
27
- readonly text: string;
28
- accept(): void;
29
- reject(error: unknown): void;
27
+ readonly messageId: string;
28
+ readonly text: string;
29
+ accept(): void;
30
+ reject(error: unknown): void;
30
31
  }
31
32
  interface Experimental_BridgeUserMessageQueue extends AsyncIterable<Experimental_BridgeUserMessage> {
32
- readonly pendingCount: number;
33
- close(error?: unknown): void;
33
+ readonly pendingCount: number;
34
+ close(error?: unknown): void;
34
35
  }
35
36
  /**
36
37
  * Per-session diagnostics config. The host resolves it from settings +
@@ -39,127 +40,127 @@ interface Experimental_BridgeUserMessageQueue extends AsyncIterable<Experimental
39
40
  * emitted and no `seq` is consumed.
40
41
  */
41
42
  interface BridgeDebugConfig {
42
- enabled?: boolean;
43
- level?: BridgeDebugLevel;
44
- subsystems?: string[];
43
+ enabled?: boolean;
44
+ level?: BridgeDebugLevel;
45
+ subsystems?: string[];
45
46
  }
46
47
  /**
47
48
  * Per-turn surface handed to {@link RunBridgeOptions.onStart}. The adapter
48
49
  * drives its runtime against these primitives; the runtime owns the transport.
49
50
  */
50
51
  interface BridgeTurn {
51
- /**
52
- * Emit a turn event to the host. Stamps a monotonic `seq`, appends to the
53
- * in-memory replay log, and sends to the live socket (best-effort — if the
54
- * host is mid-reconnect the event waits in the log and is replayed on
55
- * resume).
56
- */
57
- emit(event: BridgeEvent): void;
58
- /**
59
- * Register interest in a host-executed tool result and resolve when the
60
- * matching `tool-result` arrives. The adapter emits the `tool-call` event
61
- * itself (via {@link emit}) using the same `toolCallId`.
62
- */
63
- requestToolResult(input: string | {
64
- toolCallId: string;
65
- matches?: (result: {
66
- output: unknown;
67
- isError?: boolean;
68
- toolResult?: ToolResultPart;
69
- }) => boolean;
70
- }): Promise<{
71
- output: unknown;
72
- isError?: boolean;
73
- toolResult?: ToolResultPart;
74
- }>;
75
- /**
76
- * Register interest in a host approval decision and resolve when the matching
77
- * `tool-approval-response` arrives. The adapter emits the
78
- * `tool-approval-request` event itself using the same `approvalId`.
79
- */
80
- requestToolApproval(approvalId: string): Promise<{
81
- approved: boolean;
82
- reason?: string;
83
- }>;
84
- readonly experimental_userMessages: Experimental_BridgeUserMessageQueue;
85
- /** Aborts when the host sends `abort`. */
86
- readonly abortSignal: AbortSignal;
87
- /** True for the first turn since this bridge process started. */
88
- readonly firstTurn: boolean;
89
- /**
90
- * Emit a structured diagnostic. Gated by the session's debug level +
91
- * subsystem filter; a no-op when diagnostics are disabled. Adapters use this
92
- * for runtime-level instrumentation; raw `console.*` output is captured and
93
- * forwarded automatically.
94
- */
95
- bridgeLog(input: {
96
- level?: BridgeDebugLevel;
97
- subsystem: string;
98
- message: string;
99
- attrs?: Record<string, unknown>;
100
- error?: unknown;
101
- }): void;
102
- /**
103
- * Emit a non-fatal bridge warning to stderr using the runtime's harness
104
- * prefix. This is diagnostic-only: it does not emit a stream event, does not
105
- * consume a `seq`, and does not fail the turn.
106
- */
107
- emitWarning(input: {
108
- message: string;
109
- }): void;
110
- emitError(input: {
111
- error: unknown;
112
- message?: string;
113
- }): void;
52
+ /**
53
+ * Emit a turn event to the host. Stamps a monotonic `seq`, appends to the
54
+ * in-memory replay log, and sends to the live socket (best-effort — if the
55
+ * host is mid-reconnect the event waits in the log and is replayed on
56
+ * resume).
57
+ */
58
+ emit(event: BridgeEvent): void;
59
+ /**
60
+ * Register interest in a host-executed tool result and resolve when the
61
+ * matching `tool-result` arrives. The adapter emits the `tool-call` event
62
+ * itself (via {@link emit}) using the same `toolCallId`.
63
+ */
64
+ requestToolResult(input: string | {
65
+ toolCallId: string;
66
+ matches?: (result: {
67
+ output: unknown;
68
+ isError?: boolean;
69
+ toolResult?: ToolResultPart;
70
+ }) => boolean;
71
+ }): Promise<{
72
+ output: unknown;
73
+ isError?: boolean;
74
+ toolResult?: ToolResultPart;
75
+ }>;
76
+ /**
77
+ * Register interest in a host approval decision and resolve when the matching
78
+ * `tool-approval-response` arrives. The adapter emits the
79
+ * `tool-approval-request` event itself using the same `approvalId`.
80
+ */
81
+ requestToolApproval(approvalId: string): Promise<{
82
+ approved: boolean;
83
+ reason?: string;
84
+ }>;
85
+ readonly experimental_userMessages: Experimental_BridgeUserMessageQueue;
86
+ /** Aborts when the host sends `abort`. */
87
+ readonly abortSignal: AbortSignal;
88
+ /** True for the first turn since this bridge process started. */
89
+ readonly firstTurn: boolean;
90
+ /**
91
+ * Emit a structured diagnostic. Gated by the session's debug level +
92
+ * subsystem filter; a no-op when diagnostics are disabled. Adapters use this
93
+ * for runtime-level instrumentation; raw `console.*` output is captured and
94
+ * forwarded automatically.
95
+ */
96
+ bridgeLog(input: {
97
+ level?: BridgeDebugLevel;
98
+ subsystem: string;
99
+ message: string;
100
+ attrs?: Record<string, unknown>;
101
+ error?: unknown;
102
+ }): void;
103
+ /**
104
+ * Emit a non-fatal bridge warning to stderr using the runtime's harness
105
+ * prefix. This is diagnostic-only: it does not emit a stream event, does not
106
+ * consume a `seq`, and does not fail the turn.
107
+ */
108
+ emitWarning(input: {
109
+ message: string;
110
+ }): void;
111
+ emitError(input: {
112
+ error: unknown;
113
+ message?: string;
114
+ }): void;
114
115
  }
115
116
  interface RunBridgeOptions<TStart extends {
116
- type: 'start';
117
+ type: 'start';
117
118
  }> {
118
- /** Identifier written into `bridge-meta.json` (`'claude-code'` / `'codex'`). */
119
- bridgeType: string;
120
- /** Directory for `bridge-meta.json` / `start-config.json`. Created if absent. */
121
- bridgeStateDir: string;
122
- /**
123
- * Drive one prompt turn. Rejections surface to the host as an `error`
124
- * event.
125
- *
126
- * Contract: once `turn.abortSignal` fires, wind down promptly — turns are
127
- * serialized, and a replacement `start` waits up to
128
- * {@link turnTeardownGraceMs} for this promise to settle before it
129
- * proceeds anyway.
130
- */
131
- onStart(start: TStart, turn: BridgeTurn): Promise<void>;
132
- /**
133
- * How long a replacement `start` waits for the previous turn's teardown
134
- * after aborting it, in milliseconds. Turns are serialized so an aborted
135
- * turn cannot emit into its replacement's event log or overlap its runtime
136
- * process — but only within this bound: an adapter that does not settle
137
- * `onStart` after its abort signal fires forfeits the protection for that
138
- * boundary, and the new turn proceeds anyway rather than blocking forever.
139
- * The default of ten seconds exceeds the Claude bridge's five-second
140
- * hard-abort fallback.
141
- */
142
- turnTeardownGraceMs?: number;
143
- /**
144
- * Produce the adapter-defined runtime resume data for `stop`. Defaults to
145
- * `{}`.
146
- */
147
- onStop?(): unknown | Promise<unknown>;
148
- /**
149
- * Perform adapter-defined destruction before the bridge exits.
150
- */
151
- onDestroy?(): void | Promise<void>;
152
- /** WS port. Defaults to `BRIDGE_WS_PORT` env (0 = OS-assigned). */
153
- port?: number;
154
- /** Auth token. Defaults to `BRIDGE_CHANNEL_TOKEN` env. */
155
- token?: string;
156
- /** Called with the bound port once the server is listening. */
157
- onListening?(port: number): void;
158
- /**
159
- * Tear the process down after `stop` / `destroy`. Defaults to closing
160
- * the server and calling `process.exit(0)`. Overridable for tests.
161
- */
162
- onExit?(): void;
119
+ /** Identifier written into `bridge-meta.json` (`'claude-code'` / `'codex'`). */
120
+ bridgeType: string;
121
+ /** Directory for `bridge-meta.json` / `start-config.json`. Created if absent. */
122
+ bridgeStateDir: string;
123
+ /**
124
+ * Drive one prompt turn. Rejections surface to the host as an `error`
125
+ * event.
126
+ *
127
+ * Contract: once `turn.abortSignal` fires, wind down promptly — turns are
128
+ * serialized, and a replacement `start` waits up to
129
+ * {@link turnTeardownGraceMs} for this promise to settle before it
130
+ * proceeds anyway.
131
+ */
132
+ onStart(start: TStart, turn: BridgeTurn): Promise<void>;
133
+ /**
134
+ * How long a replacement `start` waits for the previous turn's teardown
135
+ * after aborting it, in milliseconds. Turns are serialized so an aborted
136
+ * turn cannot emit into its replacement's event log or overlap its runtime
137
+ * process — but only within this bound: an adapter that does not settle
138
+ * `onStart` after its abort signal fires forfeits the protection for that
139
+ * boundary, and the new turn proceeds anyway rather than blocking forever.
140
+ * The default of ten seconds exceeds the Claude bridge's five-second
141
+ * hard-abort fallback.
142
+ */
143
+ turnTeardownGraceMs?: number;
144
+ /**
145
+ * Produce the adapter-defined runtime resume data for `stop`. Defaults to
146
+ * `{}`.
147
+ */
148
+ onStop?(): unknown | Promise<unknown>;
149
+ /**
150
+ * Perform adapter-defined destruction before the bridge exits.
151
+ */
152
+ onDestroy?(): void | Promise<void>;
153
+ /** WS port. Defaults to `BRIDGE_WS_PORT` env (0 = OS-assigned). */
154
+ port?: number;
155
+ /** Auth token. Defaults to `BRIDGE_CHANNEL_TOKEN` env. */
156
+ token?: string;
157
+ /** Called with the bound port once the server is listening. */
158
+ onListening?(port: number): void;
159
+ /**
160
+ * Tear the process down after `stop` / `destroy`. Defaults to closing
161
+ * the server and calling `process.exit(0)`. Overridable for tests.
162
+ */
163
+ onExit?(): void;
163
164
  }
164
165
  /**
165
166
  * Boot the bridge: bind the WebSocket server, announce `bridge-ready`, and
@@ -168,13 +169,14 @@ interface RunBridgeOptions<TStart extends {
168
169
  * `stop` / `destroy` exits it.
169
170
  */
170
171
  interface BridgeHandle {
171
- /** The port the WebSocket server bound to. */
172
- readonly port: number;
173
- /** Close the WebSocket server. Does not call `process.exit`. */
174
- close(): Promise<void>;
172
+ /** The port the WebSocket server bound to. */
173
+ readonly port: number;
174
+ /** Close the WebSocket server. Does not call `process.exit`. */
175
+ close(): Promise<void>;
175
176
  }
176
- declare function runBridge<TStart extends {
177
- type: 'start';
177
+ export declare function runBridge<TStart extends {
178
+ type: 'start';
178
179
  }>(options: RunBridgeOptions<TStart>): Promise<BridgeHandle>;
179
-
180
- export { type BridgeDebugConfig, type BridgeDebugLevel, type BridgeEvent, type BridgeHandle, type BridgeState, type BridgeTurn, type Experimental_BridgeUserMessage, type Experimental_BridgeUserMessageQueue, HarnessBridgeCapabilityUnsupportedError, type RunBridgeOptions, runBridge };
180
+ //#endregion
181
+ export type { BridgeDebugConfig, BridgeDebugLevel, BridgeEvent, BridgeHandle, BridgeState, BridgeTurn, Experimental_BridgeUserMessage, Experimental_BridgeUserMessageQueue, RunBridgeOptions };
182
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/bridge/harness-bridge-capability-unsupported-error.ts","../../src/bridge/index.ts"],"mappings":";;;;;;;qBAOa,gDAAgD;WAClD;WACA;EAEG,cACV,SACA,WACA;IAEA;IACA;IACA;;SAQK,WACL,iBACC,SAAS;;;;KCVF;;KAGA,cAAc;EAA4B;;KAE1C;UAEK;WACN;WACA;EACT;EACA,OAAO;;UAGQ,4CAA4C,cAAc;WAChE;EACT,MAAM;;;;;;;;UAoBS;EACf;EACA,QAAQ;EACR;;;;;;UA+Ke;;;;;;;EAOf,KAAK,OAAO;;;;;;EAOZ,kBACE;IAGM;IACA,WAAW;MACT;MACA;MACA,aAAa;;MAGpB;IACD;IACA;IACA,aAAa;;;;;;;EAQf,oBACE,qBACC;IAAU;IAAmB;;WAEvB,2BAA2B;;WAG3B,aAAa;;WAGb;;;;;;;EAQT,UAAU;IACR,QAAQ;IACR;IACA;IACA,QAAQ;IACR;;;;;;;EAQF,YAAY;IAAS;;EAErB,UAAU;IAAS;IAAgB;;;UAGpB,iBAAiB;EAAiB;;;EAEjD;;EAEA;;;;;;;;;;EAUA,QAAQ,OAAO,QAAQ,MAAM,aAAa;;;;;;;;;;;EAW1C;;;;;EAKA,qBAAqB;;;;EAIrB,qBAAqB;;EAErB;;EAEA;;EAEA,aAAa;;;;;EAKb;;;;;;;;UA+Be;;WAEN;;EAET,SAAS;;wBAGW,UAAU;EAAiB;GAC/C,SAAS,iBAAiB,UACzB,QAAQ"}