import { z } from "zod"; import { type ProductProfile } from "./profile.js"; import { SteerDeliveryError } from "./errors.js"; import { type CodexParent, type CodexReceiverRuntime } from "./codex-receiver.js"; import type { ClaudeParent } from "./claude-receiver.js"; import type { WaitProcess } from "./cursor-receive.js"; export type ChannelKind = "codex" | "claude" | "cursor" | "background"; declare const channelSchema: z.ZodObject<{ schema: z.ZodLiteral<"aiterm-steer.channel.v1">; channel_id: z.ZodUUID; kind: z.ZodEnum<{ codex: "codex"; claude: "claude"; cursor: "cursor"; background: "background"; }>; created_at: z.ZodString; codex: z.ZodOptional>; claude: z.ZodOptional>; }, z.core.$strict>; export type Channel = z.infer; export declare class ChannelError extends SteerDeliveryError { } export type ChannelDeliveryState = "queued" | "sending" | "emitted" | "unknown" | "withdrawn"; /** * 親の会話にchannelを開く。parentは単発配送と同じ方法で特定したもの(codexParentFromRequest、claudeParentFromRequest、 * cursorParentFromRequest)。Grok等の特定できない親は null を渡し、背景受信だけのchannelにする。 */ export declare function openChannel(profile: ProductProfile, parent: CodexParent | ClaudeParent | { kind: "cursor"; } | null): Channel; export declare function readChannel(profile: ProductProfile, channelId: string): Channel; export declare function channelClosed(profile: ProductProfile, channelId: string): boolean; /** channelを閉じる。未取得の本文は残し、待機中の受け口は次の確認で終わる。 */ export declare function closeChannel(profile: ProductProfile, channelId: string, reason?: string): void; /** * 確定した本文を送る。Codexは公式キューへ入れて受付IDを返す(state=submitted)。 * それ以外はchannelの受信箱へ保存し(state=queued)、受け口が出力した時点でemittedになる。deliveryIdは送る本文ごとに新しいUUID。 */ export declare function sendToChannel(profile: ProductProfile, channelId: string, deliveryId: string, text: string, runtime?: CodexReceiverRuntime): Promise<{ state: "submitted" | "queued"; queued_submission_id: string | null; }>; /** 送った本文の現在の状態。Codexは公式キューの受付までを表す(submitted)。 */ export declare function channelDeliveryState(profile: ProductProfile, channelId: string, deliveryId: string): ChannelDeliveryState | null; /** * まだどの受け口も取っていない本文を受信箱から取り下げる。取り下げられたらtrue(親へは出ていない)。 * 受け口が先に取っていたらfalse。channelを張り直す時に、未取得の本文を新しいchannelへ送り直すために使う。 */ export declare function withdrawFromChannel(profile: ProductProfile, channelId: string, deliveryId: string): boolean; export declare function runClaudeChannelWaiter(profile: ProductProfile, input: unknown, emit: (text: string) => Promise | void, options?: { wait_ms?: number; poll_ms?: number; owner?: { pid: number; started_identity: string; } | null; owner_check_ms?: number; identity_recheck_ms?: number; runtime?: { exists: (pid: number) => boolean; identity: (pid: number) => string | undefined; }; }): Promise<0 | 2>; /** Claude CodeのSessionEndで、その会話のchannelを閉じる。未取得の本文は残る。 */ export declare function closeClaudeSessionChannels(profile: ProductProfile, input: unknown): void; /** tool結果(structuredContentのsteer_channel.channel_id、または本文の`steer_channel=`行)からchannel IDを読む。 */ export declare function channelIdFromResult(value: unknown, depth?: number): string | null; /** tool結果へ載せる印。CursorのhookはこれでchannelをCursorの実際の会話へ結ぶ。 */ export declare function channelMarker(channel: Channel): { structured: { steer_channel: { channel_id: string; }; }; text: string; }; /** * Cursorの公式hook(afterMCPExecution・postToolUse・postToolUseFailure)から呼ぶ。 * dispatch toolの結果にあるchannelをその会話へ結び、tool返りのhookでは結ばれたchannelの本文を差し込み用に返す。 */ export declare function handleCursorChannelHook(profile: ProductProfile, event: Record, emit: (text: string) => Promise | void): Promise; /** 親の背景process APIへそのまま渡す起動情報。scriptは製品のchannel受信入口の絶対path。 */ export declare function channelReceiveProcess(script: string, channelId: string, executable?: string): WaitProcess; export type ChannelReceiveResult = { outcome: "delivered"; channel_id: string; deliveries: { delivery_id: string; text: string; }[]; } | { outcome: "timeout" | "closed"; channel_id: string; }; /** * 次に届いた本文を受け取って終わる。受け取った本文はこの時点でemittedになる(出力は呼び出し側が行う)。 * hookが先に差し込んだ本文は飛ばして、その次を待つ。 */ export declare function receiveFromChannel(profile: ProductProfile, channelId: string, options?: { wait_ms?: number; poll_ms?: number; emit?: (result: ChannelReceiveResult) => Promise | void; }): Promise; export {};