/** * Daemon-side Prime Agent channel plumbing. * * Deliberately parallel to `hermes.ts`, and it REUSES the OpenClaw stream and * attachment helpers rather than forking them — `hermes.ts` does exactly the * same, and three copies of an SSE pump is three places for backpressure bugs * to hide. * * The one structural difference from Hermes: there is no single, statically * configured bridge URL. Prime Agent loads extensions per session into the * worker that owns that session, so each live session publishes its own * loopback bridge into a discovery directory. Target resolution therefore reads * that directory instead of reading config. */ import { type PrimeAgentSessionDescriptor as AdapterPrimeAgentSessionDescriptor } from '@origintrail-official/dkg-adapter-prime-agent'; export declare const PRIME_AGENT_CHANNEL_RESPONSE_TIMEOUT_MS: number; /** * Absolute backstop for the /send and /stream fetches, deliberately far above * the bridge's activity-based idle timeout (which equals the response-timeout * constant above). The bridge is the authority on turn liveness — its 504 * preserves partial output — so the daemon-side abort exists only to reap a * hung transport that will never deliver that 504. An abort at or below the * bridge's window would race it, kill actively-streaming long turns mid-flight, * and make the 504-propagation branch unreachable. */ export declare const PRIME_AGENT_CHANNEL_HARD_TIMEOUT_MS: number; export declare const PRIME_AGENT_HEALTH_TIMEOUT_MS = 5000; export declare const PRIME_AGENT_PRE_SEND_TIMEOUT_MS = 3000; export declare const PRIME_AGENT_TRANSPORT_KIND = "prime-agent-channel"; export declare const PRIME_AGENT_DKG_SESSION_PREFIX = "prime-agent:dkg-ui:"; export type PrimeAgentSessionDescriptor = AdapterPrimeAgentSessionDescriptor; export type PrimeAgentChannelSession = PrimeAgentSessionDescriptor & { /** Prime-owned id used only when targeting its loopback bridge. */ rawSessionId: string; /** DKG-owned id used for durable chat history. */ memorySessionId: string; }; export interface PrimeAgentChannelTarget { sessionId: string; inboundUrl: string; streamUrl: string; healthUrl: string; } export interface PrimeAgentChannelHealthReport { ok: boolean; sessionCount: number; sessions: PrimeAgentChannelSession[]; target?: string; targetMemorySessionId?: string; busy?: boolean; turnState?: 'queued' | 'running'; clientConnected?: boolean; clientDisconnectedAt?: string; error?: string; } /** * Loopback-only. A descriptor file is written by another process, so it is * untrusted input: the daemon must never be talked into POSTing a user's chat * to an off-box address by a malicious or corrupted descriptor. */ export declare function isPrimeAgentLoopbackUrl(value: string | undefined): boolean; export declare function primeAgentSessionsDir(agentDir?: string): string; /** * Live sessions, most recently active first (`lastActiveAt`, stamped per turn, * falling back to `startedAt`) — a session resumed by Prime Agent's daemon can * have a newer descriptor than the one the operator is actually using. The * adapter owns descriptor validation, liveness and ordering so setup/verify * and daemon routing cannot drift apart. */ export declare function readPrimeAgentSessions(sessionsDir?: string): PrimeAgentSessionDescriptor[]; export declare function targetFromDescriptor(d: PrimeAgentSessionDescriptor): PrimeAgentChannelTarget; /** * Ordered target list, most recently active first. An explicit session id * selects exactly one target and a miss yields none — a silent fallback to * "some other session" would deliver a user's message to a conversation they * were not looking at. */ export declare function getPrimeAgentChannelTargets(opts?: { sessionsDir?: string; sessionId?: string; enabled?: boolean; }): PrimeAgentChannelTarget[]; /** Bridge token is route-scoped and only ever sent to a loopback bridge. */ export declare function buildPrimeAgentChannelHeaders(target: PrimeAgentChannelTarget, bridgeAuthToken: string | undefined, baseHeaders?: Record, requestUrl?: string): Record; export declare function probePrimeAgentChannelHealth(bridgeAuthToken: string | undefined, opts?: { sessionsDir?: string; timeoutMs?: number; }): Promise; /** Pre-send gate, mirroring ensureHermesBridgeAvailable. */ export declare function ensurePrimeAgentBridgeAvailable(target: PrimeAgentChannelTarget, bridgeAuthToken: string | undefined): Promise<{ ok: boolean; status?: number; details?: string; offline?: boolean; }>; export interface PrimeAgentChatPayload { text: string; correlationId: string; sessionId?: string; contextGraphId?: string; identity?: string; persistUserMessage?: boolean; metadata?: Record; } export type PrimeAgentTurnPersistenceState = 'stored' | 'failed' | 'pending'; export interface PrimeAgentPersistTurnPayload { sessionId: string; userMessage: string; assistantReply: string; correlationId?: string; turnId?: string; persistenceState: PrimeAgentTurnPersistenceState; failureReason?: string; toolCalls?: Array<{ name: string; args: Record; result: unknown; }>; metadata?: Record; } export declare function primeAgentDkgSessionId(sessionId: string): string; export declare function primeAgentRawSessionId(sessionId: string): string; export declare function normalizePrimeAgentChatPayload(raw: unknown): PrimeAgentChatPayload | { error: string; }; export declare function normalizePrimeAgentPersistTurnPayload(raw: unknown): PrimeAgentPersistTurnPayload | { error: string; }; /** * Transport patch for the persisted integration record. Reverse-maps a live * target back to config shape, stripping the route suffix the same way * `transportPatchFromHermesTarget` does. */ export declare function transportPatchFromPrimeAgentTarget(target: PrimeAgentChannelTarget | undefined): { kind: string; bridgeUrl?: string; healthUrl?: string; } | undefined; //# sourceMappingURL=prime-agent.d.ts.map