CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
DualOutputBridge.d.ts86 linesDownload Raw Back to dualOutput
1/**2 * @license3 * Copyright 2025 Qwen Team4 * SPDX-License-Identifier: Apache-2.05 */6import type { Config, ServerGeminiStreamEvent, ToolCallRequestInfo, ToolCallResponseInfo } from '@qwen-code/qwen-code-core';7import type { Part } from '@google/genai';8/**9 * Structured-event kinds this bridge version is known to emit. Exposed to10 * consumers in `session_start.data.supported_events` so they can11 * feature-detect rather than sniffing the stream or hard-coding a minimum12 * CLI version.13 *14 * When adding a new event kind, append it here and bump the handshake15 * `protocol_version` below so consumers can gate on the combination.16 */17export declare const SUPPORTED_EVENTS: readonly ["system", "user", "assistant", "stream_event", "result", "control_request", "control_response"];18/**19 * Monotonically-increasing integer bumped whenever the wire protocol20 * changes in a way consumers might care about (new event types,21 * new payload fields that are not purely additive, etc.).22 *23 * History:24 *   1 — initial release (session_start, session_end, full stream-json).25 */26export declare const DUAL_OUTPUT_PROTOCOL_VERSION = 1;27/**28 * Optional metadata wired into the `session_start` capability handshake.29 */30export interface DualOutputBridgeOptions {31    /** CLI version string (e.g. "0.14.5"). Surfaced in session_start. */32    version?: string;33}34/**35 * Bridges TUI-mode events to a sidecar StreamJsonOutputAdapter that writes36 * structured JSON events to a secondary output channel (fd or file).37 *38 * This enables "dual output" mode: the TUI renders normally on stdout while39 * a parallel JSON event stream is emitted on a separate channel for40 * programmatic consumption by IDE extensions, web frontends, CI pipelines, etc.41 *42 * Usage:43 *   qwen --json-fd 3        # JSON events written to fd 344 *   qwen --json-file /path  # JSON events written to file/FIFO45 */46export declare class DualOutputBridge {47    private readonly adapter;48    private readonly stream;49    private readonly sessionId;50    private active;51    private shutdownPromise;52    constructor(config: Config, target: {53        fd: number;54    } | {55        filePath: string;56    }, options?: DualOutputBridgeOptions);57    processEvent(event: ServerGeminiStreamEvent): void;58    startAssistantMessage(): void;59    finalizeAssistantMessage(): void;60    emitUserMessage(parts: Part[]): void;61    emitToolResult(request: ToolCallRequestInfo, response: ToolCallResponseInfo): void;62    /** Whether the underlying stream is still writable. */63    get isConnected(): boolean;64    private disableIfBufferOverflowed;65    /**66     * Emits a `can_use_tool` permission request so an external consumer can67     * approve or deny the tool call. Pairs with {@link emitControlResponse}.68     */69    emitPermissionRequest(requestId: string, toolName: string, toolUseId: string, input: unknown, blockedPath?: string | null): void;70    /**71     * Emits the result of a permission decision (made either in the TUI or by72     * the external consumer) so all observers stay in sync.73     */74    emitControlResponse(requestId: string, allowed: boolean): void;75    /**76     * Emits a `control_response` with subtype `error` — used when an external77     * `confirmation_response` cannot be satisfied (unknown request_id, the78     * tool call already resolved, stream already closed, etc.). Lets79     * consumers retry or surface the error instead of silently hanging.80     */81    emitControlError(requestId: string, message: string): void;82    /** General-purpose system event escape hatch. */83    emitSystemMessage(subtype: string, data?: unknown): void;84    shutdown(): Promise<void>;85}86 
basant307/AI_Governance_Project · CoolFace