MCPcopy
hub / github.com/xintaofei/codeg / Transport

Interface Transport

src/lib/transport/types.ts:92–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92export interface Transport {
93 /**
94 * Invoke a backend command (replaces Tauri's invoke()).
95 */
96 call<T>(
97 command: string,
98 args?: Record<string, unknown>,
99 options?: CallOptions
100 ): Promise<T>
101
102 /**
103 * Subscribe to a backend event stream (replaces Tauri's listen()).
104 * Returns an unsubscribe function.
105 */
106 subscribe<T>(
107 event: string,
108 handler: (payload: T) => void
109 ): Promise<UnsubscribeFn>
110
111 /**
112 * Whether the app is running in a desktop Tauri environment.
113 */
114 isDesktop(): boolean
115
116 /**
117 * Register a callback invoked after a WebSocket-based transport reconnects
118 * and the server-side broadcaster receiver is re-subscribed. Used by
119 * consumers (e.g. ACP connection store) to recover any events emitted
120 * during the disconnect window — the broadcaster drops events when
121 * `receiver_count == 0`, so anything fired between `onclose` and the next
122 * `__ready__` is lost. Re-fetching backend snapshots is the recovery path.
123 *
124 * Not fired on the initial connect (consumers handle that separately).
125 * Returns an unsubscribe function. Optional — IPC-only transports (e.g.
126 * Tauri) leave this undefined.
127 */
128 onReconnect?(callback: () => void): UnsubscribeFn
129
130 /**
131 * Resolves when the server-side broadcaster receiver is currently
132 * subscribed (i.e. the most recent WS connection has received its
133 * `__ready__` frame). Callers should await this immediately before
134 * invoking HTTP commands that emit events via the WebSocket — without
135 * the await, events fired during a WS reconnect window are silently
136 * dropped by the broadcaster's `receiver_count == 0` guard.
137 *
138 * Bounded by a transport-internal timeout; falls through (resolves)
139 * rather than rejecting to avoid permanent UI hang. Optional — IPC-only
140 * transports leave this undefined (no disconnect window to guard).
141 */
142 waitForReady?(): Promise<void>
143
144 /**
145 * Per-connection event stream (Subscribe-with-Snapshot). Returns
146 * `undefined` for transports that don't yet support the attach protocol —
147 * callers fall back to the legacy `subscribe()` channel. Implementations
148 * are stateful: the same EventStream instance handles re-attach on
149 * reconnect transparently to the caller.

Implementers 3

RemoteDesktopTransportsrc/lib/transport/remote-desktop-trans
WebTransportsrc/lib/transport/web-transport.ts
TauriTransportsrc/lib/transport/tauri-transport.ts

Calls

no outgoing calls

Tested by

no test coverage detected