@qoder-ai/qoder-agent-sdk 1.0.26 → 1.0.28

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.
package/README.md CHANGED
@@ -448,13 +448,37 @@ the main session.
448
448
 
449
449
  `sessionStoreFlush: "batched"` is the default. `"eager"` starts each append
450
450
  without waiting for the result boundary. Final append failures are emitted as
451
- non-fatal `system/mirror_error` messages. `loadTimeoutMs` defaults to 60,000 ms.
451
+ non-fatal `system/mirror_error` messages. Each append batch is submitted once:
452
+ the SDK does not retry a mutation whose commit outcome may be unknown.
453
+ `loadTimeoutMs` defaults to 60,000 ms.
452
454
  Session storage cannot be combined with `persistSession: false`, file
453
455
  checkpointing, custom transports, or the Cloud Agent runtime. Session storage
454
456
  supports the built-in Process and Worker transports. Use
455
457
  `importSessionToStore(sessionId, store, options)` to copy an existing local main
456
458
  transcript, child-agent transcripts, and metadata into a store.
457
459
 
460
+ For a shared daemon, implement `DaemonSessionStore`, which adds
461
+ `listAllSessions()`, and bind it once at daemon startup:
462
+
463
+ ```ts
464
+ const daemon = await startDaemon({
465
+ auth: qodercliAuth(),
466
+ capacity: 4,
467
+ sessionStore,
468
+ });
469
+
470
+ const running = query({
471
+ prompt,
472
+ options: { daemon, cwd: "/path/to/project" },
473
+ });
474
+ ```
475
+
476
+ `listAllSessions()` returns only main Sessions owned by that Host Store. Each
477
+ summary contains the exact stored `key`, a non-empty title, an ISO timestamp,
478
+ and the canonical working directory. Daemon-bound Queries reuse this one Store
479
+ and cannot override it per Query. Registration sends summaries only; transcript
480
+ entries are loaded lazily when a Worker needs to resume the Session.
481
+
458
482
  ### Production stores
459
483
 
460
484
  The SDK exports the `SessionStore` interface but does not ship a
@@ -0,0 +1,16 @@
1
+ import { Transform, type TransformCallback } from 'node:stream';
2
+ export declare const DEFAULT_MAX_JSONL_FRAME_BYTES: number;
3
+ export declare class FrameTooLargeError extends Error {
4
+ readonly direction: string;
5
+ readonly limit: number;
6
+ readonly code = "DAEMON_FRAME_TOO_LARGE";
7
+ constructor(direction: string, limit: number);
8
+ }
9
+ export declare class BoundedLineTransform extends Transform {
10
+ private readonly maxLineBytes;
11
+ private readonly direction;
12
+ private bytesSinceNewline;
13
+ constructor(maxLineBytes?: number, direction?: string);
14
+ _transform(chunk: Buffer | string, encoding: BufferEncoding, callback: TransformCallback): void;
15
+ }
16
+ export declare function assertBoundedSerializedFrame(serializedFrame: string, maxFrameBytes?: number, direction?: string): void;
@@ -17,6 +17,7 @@ import type { McpServerConfigForProcessTransport, McpServerToolPolicy } from '..
17
17
  import type { InternalAuthOptions } from '../types/auth.js';
18
18
  import type { SecurityScanOptions, SpawnedProcess, SpawnOptions, SettingSource } from '../types/options.js';
19
19
  import type { DiagnosticsSink } from './sdk-diagnostics.js';
20
+ import type { SessionExtra } from '../daemon/session-metadata.js';
20
21
  export declare class QoderCliProcessError extends Error {
21
22
  readonly code: "QODER_CLI_PROCESS_ERROR";
22
23
  readonly exitCode?: number | null;
@@ -46,6 +47,8 @@ export interface ProcessTransportOptions {
46
47
  cwd?: string;
47
48
  /** Custom environment variables (defaults to process.env) */
48
49
  env?: Record<string, string | undefined>;
50
+ /** SDK-internal: config root created by SessionStore materialization. */
51
+ materializedSessionConfigDir?: string;
49
52
  proxy?: string;
50
53
  /**
51
54
  * VPC private-deployment endpoint (CN deployments only). Written to the
@@ -71,6 +74,8 @@ export interface ProcessTransportOptions {
71
74
  /** SDK-internal diagnostics sink. This is not forwarded to qodercli. */
72
75
  diagnostics?: DiagnosticsSink;
73
76
  agent?: string;
77
+ /** SDK-internal Session metadata consumed by the shared daemon. */
78
+ extra?: SessionExtra;
74
79
  sessionId?: string;
75
80
  continue?: boolean;
76
81
  resume?: string;
@@ -0,0 +1,9 @@
1
+ import type { InternalAuthOptions } from '../types/auth.js';
2
+ import { type DaemonRequestHandler } from './daemon-connection.js';
3
+ export declare function createDaemonAuthRequestHandler(auth: InternalAuthOptions, callbackTimeoutMs?: number): DaemonRequestHandler;
4
+ export declare function createDaemonRequestHandler(options: {
5
+ auth: InternalAuthOptions;
6
+ sessionStoreHandler?: DaemonRequestHandler;
7
+ remoteSessionLaunchHandler?: DaemonRequestHandler;
8
+ callbackTimeoutMs?: number;
9
+ }): DaemonRequestHandler;
@@ -0,0 +1,98 @@
1
+ import type { Readable, Writable } from "node:stream";
2
+ import { type DaemonControlRequestFrame, type DaemonEventFrame, type DaemonWireSessionMessage, type JsonObject, type JsonValue, type EnableRemoteControlParams, type EnableRemoteControlResult, type OpenSessionParams, type RenameSessionResult, type SubscribeSessionResult, type UpdateSessionMetadataResult } from "./protocol.js";
3
+ import { DaemonSessionTransport, type DaemonSessionTransportOptions } from "./daemon-session-transport.js";
4
+ export interface DaemonConnectionOptions {
5
+ input: Writable;
6
+ output: Readable;
7
+ requestHandler?: DaemonRequestHandler;
8
+ maxFrameBytes?: number;
9
+ }
10
+ export type DaemonRequestHandler = (request: DaemonControlRequestFrame) => Promise<JsonValue>;
11
+ export type RemoteControlFailure = {
12
+ environmentId: string;
13
+ error: DaemonRpcError;
14
+ };
15
+ export declare class DaemonRpcError extends Error {
16
+ readonly code: string;
17
+ readonly retryable: boolean;
18
+ constructor(options: {
19
+ code: string;
20
+ message: string;
21
+ retryable: boolean;
22
+ });
23
+ }
24
+ export declare class DaemonRequestError extends Error {
25
+ readonly code: string;
26
+ readonly retryable: boolean;
27
+ readonly details: JsonObject | undefined;
28
+ constructor(options: {
29
+ code: string;
30
+ message: string;
31
+ retryable: boolean;
32
+ details?: JsonObject;
33
+ });
34
+ }
35
+ export declare class DaemonConnection {
36
+ private readonly input;
37
+ private readonly requestHandler;
38
+ private readonly pendingRequests;
39
+ private readonly timedOutRequestIds;
40
+ private readonly activeInboundRequestIds;
41
+ private readonly sessions;
42
+ private readonly closedSessionIds;
43
+ private readonly pendingSessionMessages;
44
+ private readonly pendingSessionMessageBytes;
45
+ private pendingSessionMessageFrameCount;
46
+ private pendingSessionMessageByteCount;
47
+ private readonly maxFrameBytes;
48
+ private readonly readTask;
49
+ private writeChain;
50
+ private nextRequestId;
51
+ private initializing;
52
+ private initialized;
53
+ private readonly capabilities;
54
+ private stopping;
55
+ private failure;
56
+ private remoteControlFailureListener;
57
+ private readonly daemonEventListeners;
58
+ private readonly failureListeners;
59
+ constructor(options: DaemonConnectionOptions);
60
+ initialize(sdkVersion: string, optionalCapabilitiesOrTimeout?: readonly string[] | number, timeoutMs?: number): Promise<void>;
61
+ createSessionTransport(options: DaemonSessionTransportOptions): DaemonSessionTransport;
62
+ createAttachedSessionTransport(remoteSessionId: string): DaemonSessionTransport;
63
+ onRemoteControlFailure(listener: (failure: RemoteControlFailure) => void): void;
64
+ onDaemonEvent(listener: (event: DaemonEventFrame) => void): () => void;
65
+ onFailure(listener: (error: Error) => void): () => void;
66
+ openSession(params: OpenSessionParams, transport: DaemonSessionTransport): Promise<string>;
67
+ subscribeSession(remoteSessionId: string, transport: DaemonSessionTransport): Promise<SubscribeSessionResult>;
68
+ enableRemoteControl(params: EnableRemoteControlParams): Promise<EnableRemoteControlResult>;
69
+ listSessions(): Promise<import("./protocol.js").DaemonSessionInfo[]>;
70
+ renameSession(sessionId: string, title: string): Promise<RenameSessionResult>;
71
+ disableRemoteControl(): Promise<void>;
72
+ syncSessionRegistrations(localSessionIds: string[]): Promise<void>;
73
+ updateSessionMetadata(sessionId: string, extra: JsonObject): Promise<UpdateSessionMetadataResult>;
74
+ sendSessionMessage(message: DaemonWireSessionMessage): Promise<void>;
75
+ closeSession(sessionId: string): Promise<void>;
76
+ deleteSession(localSessionId: string): Promise<void>;
77
+ unsubscribeSession(sessionId: string): Promise<void>;
78
+ shutdown(timeoutMs?: number): Promise<void>;
79
+ fail(error: unknown, notifyListeners?: boolean): void;
80
+ private request;
81
+ private readOutput;
82
+ private acceptFrame;
83
+ private rememberTimedOutRequestId;
84
+ private routeSessionMessage;
85
+ private acceptControlResponse;
86
+ private hasPendingSessionRequest;
87
+ private failIfSessionMessagesAreOrphaned;
88
+ private bufferPendingSessionMessage;
89
+ private takePendingSessionMessages;
90
+ private deletePendingSessionMessages;
91
+ private clearPendingSessionMessages;
92
+ private rejectLegacyInitialize;
93
+ private acceptRequest;
94
+ private writeInboundError;
95
+ private acceptEvent;
96
+ private acceptRemoteControlEvent;
97
+ private writeFrame;
98
+ }
@@ -0,0 +1,60 @@
1
+ import type { Transport } from '../core/transport.js';
2
+ import type { StdoutMessage } from '../types/control.js';
3
+ import type { DaemonWireSessionMessage, JsonObject } from './protocol.js';
4
+ import type { DaemonConnection } from './daemon-connection.js';
5
+ import type { SessionExtra } from './session-metadata.js';
6
+ export type DaemonSessionTransportOptions = {
7
+ workerArgs: string[];
8
+ cwd?: string;
9
+ configDir?: string;
10
+ extra?: SessionExtra;
11
+ cleanup?: () => void;
12
+ remoteSessionId?: never;
13
+ } | {
14
+ remoteSessionId: string;
15
+ workerArgs?: never;
16
+ cwd?: never;
17
+ configDir?: never;
18
+ extra?: never;
19
+ cleanup?: never;
20
+ };
21
+ export declare class DaemonSessionTransport implements Transport {
22
+ private readonly connection;
23
+ private readonly options;
24
+ private readonly messages;
25
+ private readonly pendingMessages;
26
+ private initializePromise;
27
+ private sessionId;
28
+ private flushingPendingMessages;
29
+ private inputEnded;
30
+ private resultReceived;
31
+ private commandLifecycleSupported;
32
+ private readonly pendingCommandUuids;
33
+ private closed;
34
+ private cleaned;
35
+ private releasePromise;
36
+ private subscribeResult;
37
+ private readonly remoteSessionId;
38
+ constructor(connection: DaemonConnection, options: DaemonSessionTransportOptions);
39
+ initialize(): Promise<void>;
40
+ initializationResult(): Promise<JsonObject>;
41
+ write(data: string): void;
42
+ readMessages(): AsyncGenerator<StdoutMessage, void, unknown>;
43
+ endInput(): void;
44
+ close(): void;
45
+ isReady(): boolean;
46
+ acceptOutput(message: DaemonWireSessionMessage): void;
47
+ fail(error: unknown): void;
48
+ private open;
49
+ private failAndRelease;
50
+ private startRelease;
51
+ private releaseSessionOnce;
52
+ private releaseSession;
53
+ private trackOutboundCommand;
54
+ private observeCapabilities;
55
+ private updateCommandLifecycleCapability;
56
+ private observeCommandLifecycle;
57
+ private maybeCloseAfterResult;
58
+ private closeAfterResult;
59
+ private cleanup;
60
+ }
@@ -0,0 +1,171 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export declare const DAEMON_PROTOCOL_VERSION: 2;
7
+ export type JsonPrimitive = string | number | boolean | null;
8
+ export type JsonValue = JsonPrimitive | JsonValue[] | {
9
+ [key: string]: JsonValue;
10
+ };
11
+ export type JsonObject = {
12
+ [key: string]: JsonValue;
13
+ };
14
+ export interface DaemonControlRequestFrame<Method extends string = string, Params extends JsonObject = JsonObject> {
15
+ type: "control_request";
16
+ request_id: string;
17
+ session_id?: string;
18
+ request: {
19
+ type: `daemon.${Method}`;
20
+ } & Params;
21
+ }
22
+ export interface DaemonSuccessResponseFrame<Result extends JsonObject = JsonObject> {
23
+ type: "control_response";
24
+ session_id?: string;
25
+ response: {
26
+ subtype: "success";
27
+ request_id: string;
28
+ response?: Result;
29
+ };
30
+ }
31
+ export interface DaemonErrorResponseFrame {
32
+ type: "control_response";
33
+ session_id?: string;
34
+ response: {
35
+ subtype: "error";
36
+ request_id: string;
37
+ error: string;
38
+ code?: string;
39
+ retryable?: boolean;
40
+ details?: JsonObject;
41
+ };
42
+ }
43
+ export type DaemonControlResponseFrame = DaemonSuccessResponseFrame | DaemonErrorResponseFrame;
44
+ export interface DaemonEventFrame {
45
+ type: "event";
46
+ event: string;
47
+ session_id?: string;
48
+ data: JsonObject;
49
+ }
50
+ export interface KeepAliveFrame {
51
+ type: "keep_alive";
52
+ }
53
+ /** A raw Query message carrying a daemon-local Session route. */
54
+ export type DaemonWireSessionMessage = JsonObject & {
55
+ type: string;
56
+ session_id?: string;
57
+ };
58
+ export type DaemonProtocolFrame = DaemonControlRequestFrame | DaemonControlResponseFrame | DaemonEventFrame | KeepAliveFrame | DaemonWireSessionMessage;
59
+ export type InitializeDaemonParams = {
60
+ daemon_protocol_version: typeof DAEMON_PROTOCOL_VERSION;
61
+ sdk_version: string;
62
+ capabilities: string[];
63
+ };
64
+ export type InitializeDaemonResult = {
65
+ daemon_protocol_version: typeof DAEMON_PROTOCOL_VERSION;
66
+ daemon_version: string;
67
+ capabilities: string[];
68
+ };
69
+ export type OpenSessionParams = {
70
+ worker_args: string[];
71
+ cwd?: string;
72
+ config_dir?: string;
73
+ extra?: JsonObject;
74
+ };
75
+ export type OpenSessionResult = {
76
+ session_id: string;
77
+ };
78
+ export type SubscribeSessionParams = {
79
+ remote_session_id: string;
80
+ };
81
+ export type SubscribeSessionResult = {
82
+ session_id: string;
83
+ initialization_result: JsonObject;
84
+ };
85
+ export type UnsubscribeSessionParams = Record<string, never>;
86
+ export type SessionRuntimeState = "pending" | "ready" | "inactive" | "failed";
87
+ export type DaemonSessionInfo = {
88
+ local_session_id: string;
89
+ remote_session_id?: string;
90
+ environment_id?: string;
91
+ title: string;
92
+ cwd?: string;
93
+ extra?: JsonObject;
94
+ state: SessionRuntimeState;
95
+ created_at: string;
96
+ updated_at: string;
97
+ };
98
+ export type ListSessionsParams = Record<string, never>;
99
+ export type ListSessionsResult = {
100
+ sessions: DaemonSessionInfo[];
101
+ };
102
+ export type RenameSessionParams = {
103
+ title: string;
104
+ };
105
+ export type RenameSessionResult = {
106
+ session: DaemonSessionInfo;
107
+ };
108
+ export type EnableRemoteControlParams = {
109
+ external_id: string;
110
+ environment_type: string;
111
+ name?: string;
112
+ metadata?: JsonObject;
113
+ };
114
+ export type EnableRemoteControlResult = {
115
+ environment_id: string;
116
+ };
117
+ export type DisableRemoteControlParams = Record<string, never>;
118
+ export type SyncSessionRegistrationsParams = {
119
+ local_session_ids: string[];
120
+ };
121
+ export type UpdateSessionMetadataParams = {
122
+ extra: JsonObject;
123
+ };
124
+ export type UpdateSessionMetadataResult = {
125
+ session: DaemonSessionInfo;
126
+ };
127
+ export type CloseSessionParams = Record<string, never>;
128
+ export type DeleteSessionParams = {
129
+ local_session_id: string;
130
+ };
131
+ export type ShutdownParams = Record<string, never>;
132
+ export type DaemonCommandMethod = "initialize" | "open_session" | "list_sessions" | "rename_session" | "subscribe_session" | "unsubscribe_session" | "enable_remote_control" | "sync_session_registrations" | "update_session_metadata" | "disable_remote_control" | "close_session" | "delete_session" | "shutdown";
133
+ export interface DaemonCommandParamsMap {
134
+ initialize: InitializeDaemonParams;
135
+ open_session: OpenSessionParams;
136
+ list_sessions: ListSessionsParams;
137
+ rename_session: RenameSessionParams;
138
+ subscribe_session: SubscribeSessionParams;
139
+ unsubscribe_session: UnsubscribeSessionParams;
140
+ enable_remote_control: EnableRemoteControlParams;
141
+ sync_session_registrations: SyncSessionRegistrationsParams;
142
+ update_session_metadata: UpdateSessionMetadataParams;
143
+ disable_remote_control: DisableRemoteControlParams;
144
+ close_session: CloseSessionParams;
145
+ delete_session: DeleteSessionParams;
146
+ shutdown: ShutdownParams;
147
+ }
148
+ export type DaemonCommandRequest = DaemonControlRequestFrame<"initialize", InitializeDaemonParams> | DaemonControlRequestFrame<"open_session", OpenSessionParams> | DaemonControlRequestFrame<"list_sessions", ListSessionsParams> | DaemonControlRequestFrame<"rename_session", RenameSessionParams> | DaemonControlRequestFrame<"subscribe_session", SubscribeSessionParams> | DaemonControlRequestFrame<"unsubscribe_session", UnsubscribeSessionParams> | DaemonControlRequestFrame<"enable_remote_control", EnableRemoteControlParams> | DaemonControlRequestFrame<"sync_session_registrations", SyncSessionRegistrationsParams> | DaemonControlRequestFrame<"update_session_metadata", UpdateSessionMetadataParams> | DaemonControlRequestFrame<"disable_remote_control", DisableRemoteControlParams> | DaemonControlRequestFrame<"close_session", CloseSessionParams> | DaemonControlRequestFrame<"delete_session", DeleteSessionParams> | DaemonControlRequestFrame<"shutdown", ShutdownParams>;
149
+ export interface DaemonCommandResultMap {
150
+ initialize: InitializeDaemonResult;
151
+ open_session: OpenSessionResult;
152
+ list_sessions: ListSessionsResult;
153
+ rename_session: RenameSessionResult;
154
+ subscribe_session: SubscribeSessionResult;
155
+ unsubscribe_session: null;
156
+ enable_remote_control: EnableRemoteControlResult;
157
+ sync_session_registrations: null;
158
+ update_session_metadata: UpdateSessionMetadataResult;
159
+ disable_remote_control: null;
160
+ close_session: null;
161
+ delete_session: null;
162
+ shutdown: null;
163
+ }
164
+ export declare class DaemonProtocolError extends Error {
165
+ readonly code: "DAEMON_PROTOCOL_ERROR";
166
+ constructor(message: string);
167
+ }
168
+ export declare function parseDaemonProtocolLine(line: string): DaemonProtocolFrame;
169
+ export declare function serializeDaemonProtocolFrame(frame: DaemonProtocolFrame): string;
170
+ export declare function parseDaemonCommandRequest(frame: DaemonProtocolFrame): DaemonCommandRequest;
171
+ export declare function parseDaemonCommandResult<Method extends DaemonCommandMethod>(method: Method, frame: DaemonSuccessResponseFrame): DaemonCommandResultMap[Method];
@@ -0,0 +1,3 @@
1
+ import { type DaemonRequestHandler } from './daemon-connection.js';
2
+ import { type ResolveRemoteSessionLaunch } from './session-metadata.js';
3
+ export declare function createRemoteSessionLaunchRequestHandler(resolveLaunch: ResolveRemoteSessionLaunch, callbackTimeoutMs?: number): DaemonRequestHandler;
@@ -0,0 +1,19 @@
1
+ export type SessionExtraValue = string | number | boolean | null | readonly SessionExtraValue[] | {
2
+ readonly [key: string]: SessionExtraValue;
3
+ };
4
+ /** Opaque, JSON-safe metadata owned by the Host application. */
5
+ export type SessionExtra = Readonly<Record<string, SessionExtraValue>>;
6
+ /** Replaces the complete metadata snapshot for one Session. */
7
+ export interface SessionMetadataUpdate {
8
+ extra: SessionExtra;
9
+ }
10
+ export interface RemoteSessionLaunchRequest {
11
+ remoteSessionId: string;
12
+ extra?: SessionExtra;
13
+ }
14
+ export interface RemoteSessionLaunch {
15
+ cwd: string;
16
+ additionalDirectories?: readonly string[];
17
+ }
18
+ export type ResolveRemoteSessionLaunch = (request: RemoteSessionLaunchRequest) => Promise<RemoteSessionLaunch>;
19
+ export declare function normalizeSessionExtra(value: SessionExtra, path?: string): SessionExtra;
@@ -0,0 +1,10 @@
1
+ import type { DaemonSessionStore } from "./session-store-rpc.js";
2
+ export interface SessionRegistrationStore {
3
+ readonly store: DaemonSessionStore;
4
+ flush(): Promise<void>;
5
+ dispose(): void;
6
+ }
7
+ export declare function createSessionRegistrationStore(store: DaemonSessionStore, options: {
8
+ sync: (localSessionIds: string[]) => Promise<void>;
9
+ retryDelaysMs?: readonly number[];
10
+ }): SessionRegistrationStore;
@@ -0,0 +1,37 @@
1
+ import type { SessionKey, SessionStore } from "../session/session-store.js";
2
+ import { DaemonRequestError, type DaemonRequestHandler } from "./daemon-connection.js";
3
+ import { type SessionExtra, type SessionMetadataUpdate } from "./session-metadata.js";
4
+ export interface DaemonSessionStore extends SessionStore {
5
+ listAllSessions(): Promise<readonly DaemonSessionSummary[]>;
6
+ /**
7
+ * Persists a complete replacement of one Session's metadata. Implementations
8
+ * must use upsert semantics: the daemon may call this before the first
9
+ * transcript entry exists, and listAllSessions() must later return the same
10
+ * extra snapshot.
11
+ */
12
+ updateSessionMetadata?(key: Omit<SessionKey, "subpath">, update: SessionMetadataUpdate): Promise<void>;
13
+ }
14
+ export interface DaemonSessionSummary {
15
+ key: SessionKey;
16
+ title: string;
17
+ lastActiveAt: string;
18
+ cwd: string;
19
+ extra?: SessionExtra;
20
+ }
21
+ export interface DaemonSessionStoreRpcOptions {
22
+ callbackTimeoutMs?: number;
23
+ maxEntriesPerPage?: number;
24
+ maxPayloadBytes?: number;
25
+ }
26
+ export type DaemonSessionStoreRequestHandler = DaemonRequestHandler & {
27
+ dispose(): Promise<void>;
28
+ };
29
+ export declare class DaemonSessionStoreRpcError extends DaemonRequestError {
30
+ constructor(options: {
31
+ code: string;
32
+ message: string;
33
+ retryable?: boolean;
34
+ operation?: string;
35
+ });
36
+ }
37
+ export declare function createDaemonSessionStoreRequestHandler(store: DaemonSessionStore, options?: DaemonSessionStoreRpcOptions): DaemonSessionStoreRequestHandler;
@@ -0,0 +1,95 @@
1
+ import type { InternalAuthOptions } from '../types/auth.js';
2
+ import type { Query, OnElicitation } from '../types/options.js';
3
+ import type { CanUseTool } from '../types/permissions.js';
4
+ import type { ProcessTransportOptions } from '../core/process-transport.js';
5
+ import type { QueryTransportProvider } from '../core/transport.js';
6
+ import { type DaemonSessionStore } from './session-store-rpc.js';
7
+ import { type ResolveRemoteSessionLaunch, type SessionExtra, type SessionMetadataUpdate } from './session-metadata.js';
8
+ export type DaemonState = 'ready' | 'stopping' | 'stopped' | 'failed';
9
+ export type RemoteControlState = 'ready' | 'stopping' | 'stopped' | 'failed';
10
+ export interface EnableRemoteControlOptions {
11
+ externalId: string;
12
+ /**
13
+ * Remote Manager-registered push-family Environment type for this Host.
14
+ * The value is an Environment identity component and must remain stable.
15
+ */
16
+ environmentType: string;
17
+ name?: string;
18
+ metadata?: Record<string, unknown>;
19
+ }
20
+ export interface RemoteControl {
21
+ readonly environmentId: string;
22
+ readonly state: RemoteControlState;
23
+ disable(): Promise<void>;
24
+ }
25
+ export interface AttachSessionOptions {
26
+ canUseTool?: CanUseTool;
27
+ onElicitation?: OnElicitation;
28
+ }
29
+ export type SessionRuntimeState = 'pending' | 'ready' | 'inactive' | 'failed';
30
+ export interface DaemonSessionInfo {
31
+ localSessionId: string;
32
+ remoteSessionId?: string;
33
+ environmentId?: string;
34
+ title: string;
35
+ cwd?: string;
36
+ extra?: SessionExtra;
37
+ state: SessionRuntimeState;
38
+ createdAt: string;
39
+ updatedAt: string;
40
+ }
41
+ export interface StartDaemonOptions {
42
+ auth: InternalAuthOptions;
43
+ capacity: number;
44
+ /** Idle Worker timeout in milliseconds. Set to 0 to disable reclamation. */
45
+ workerIdleTimeoutMs?: number;
46
+ cwd?: string;
47
+ pathToQoderCLIExecutable?: string;
48
+ proxy?: string;
49
+ env?: Record<string, string | undefined>;
50
+ sessionStore?: DaemonSessionStore;
51
+ /** Resolves a remotely-created Session to trusted local launch paths. */
52
+ resolveRemoteSessionLaunch?: ResolveRemoteSessionLaunch;
53
+ }
54
+ export type DaemonEvent = {
55
+ type: 'daemonStateChanged';
56
+ previousState: DaemonState;
57
+ state: DaemonState;
58
+ error?: Error;
59
+ } | {
60
+ type: 'remoteControlStateChanged';
61
+ environmentId?: string;
62
+ previousState: RemoteControlState;
63
+ state: RemoteControlState;
64
+ error?: Error;
65
+ } | {
66
+ type: 'sessionDiscovered';
67
+ session: DaemonSessionInfo;
68
+ } | {
69
+ type: 'sessionUpdated';
70
+ session: DaemonSessionInfo;
71
+ previousState?: SessionRuntimeState;
72
+ } | {
73
+ type: 'sessionDeleted';
74
+ localSessionId: string;
75
+ };
76
+ export type DaemonEventCallback = (event: DaemonEvent) => void;
77
+ export interface Daemon {
78
+ readonly state: DaemonState;
79
+ listSessions(): Promise<DaemonSessionInfo[]>;
80
+ onEvent(callback: DaemonEventCallback): () => void;
81
+ renameSession(localSessionId: string, title: string): Promise<DaemonSessionInfo>;
82
+ updateSessionMetadata(localSessionId: string, update: SessionMetadataUpdate): Promise<DaemonSessionInfo>;
83
+ deleteSession(localSessionId: string): Promise<void>;
84
+ enableRemoteControl(options: EnableRemoteControlOptions): Promise<RemoteControl>;
85
+ attachSession(remoteSessionId: string, options?: AttachSessionOptions): Promise<Query>;
86
+ stop(): Promise<void>;
87
+ }
88
+ interface InternalDaemonRuntime {
89
+ readonly auth: InternalAuthOptions;
90
+ readonly transportProvider: QueryTransportProvider<ProcessTransportOptions>;
91
+ readonly sessionStore?: DaemonSessionStore;
92
+ }
93
+ export declare function getDaemonRuntime(daemon: Daemon): InternalDaemonRuntime | undefined;
94
+ export declare function startDaemon(options: StartDaemonOptions): Promise<Daemon>;
95
+ export {};
package/dist/index.d.ts CHANGED
@@ -55,6 +55,10 @@ export { query } from './query/query.js';
55
55
  export { startup } from './query/startup.js';
56
56
  export type { StartupParams, WarmQuery } from './query/startup.js';
57
57
  export { resolveSettings } from './settings/resolve-settings.js';
58
+ export { startDaemon } from './daemon/start-daemon.js';
59
+ export type { Daemon, DaemonEvent, DaemonEventCallback, DaemonState, AttachSessionOptions, DaemonSessionInfo, SessionRuntimeState, EnableRemoteControlOptions, RemoteControl, RemoteControlState, StartDaemonOptions, } from './daemon/start-daemon.js';
60
+ export type { RemoteSessionLaunch, RemoteSessionLaunchRequest, ResolveRemoteSessionLaunch, SessionExtra, SessionExtraValue, SessionMetadataUpdate, } from './daemon/session-metadata.js';
61
+ export type { DaemonSessionStore, DaemonSessionSummary, } from './daemon/session-store-rpc.js';
58
62
  export { DEFAULT_RUNTIME_TRANSPORT, } from './core/default-runtime.js';
59
63
  export { ProcessTransport, QoderCliProcessError, } from './core/process-transport.js';
60
64
  export { hasResolvableQoderWorkerRuntime, QoderWorkerRuntimeError, WorkerTransport, resolveQoderWorkerRuntimePath, } from './core/worker-transport.js';
@@ -86,7 +90,7 @@ export type { AccessTokenInput, AuthOptions, FetchServiceAccountToken, ServiceAc
86
90
  */
87
91
  export type { FetchJobToken, JobTokenAuthOptions, JobTokenRequest, JobTokenResult, } from './types/auth.js';
88
92
  export type { AccountInfo, UsageAddOnQuotaBucket, UsageInfo, UsageOrgResourcePackage, UsageQuotaBucket, SessionCreditsUsage, ApiKeySource, ExitReason, FastModeState, ConfigScope, SettingSource, SDKAssistantMessageError, SDKStatus, EffortLevel, ThinkingAdaptive, ThinkingEnabled, ThinkingDisabled, ThinkingConfig, ModelInfo, ModelSource, ServerModelJson, ServerModelJsonValue, ModelStrategy, ModelPromotion, LocalizedModelText, ModelContextConfig, ModelContextWindowEntry, ModelEffortEntry, ModelThinkingConfig, ModelThinkingDisabled, ModelThinkingEnabled, ModelUsage, NonNullableUsage, SlashCommand, ToolConfig, SdkPluginConfig, } from './types/common.js';
89
- export type { SDKMessage, SDKAssistantMessage, SDKToolNonExecutionKind, SDKToolResultMeta, SDKUserMessage, SDKUserMessageReplay, SDKResultMessage, SDKResultSuccess, SDKResultError, SDKSystemMessage, SDKSystemInitMessage, SDKSystemMessageSubtype, SDKSystemMessageBySubtype, SDKPartialAssistantMessage, SDKCompactBoundaryMessage, SDKStatusMessage, SDKAPIRetryMessage, SDKModelQueueStatusMessage, SDKControlRequestProgressMessage, SDKHookStartedMessage, SDKHookProgressMessage, SDKHookResponseMessage, SDKPermissionDeniedMessage, SDKMirrorErrorMessage, SDKTaskNotificationMessage, SDKTaskStartedMessage, SDKTaskProgressMessage, SDKTaskUpdatedMessage, SDKBackgroundTasksChangedMessage, SDKSessionStateChangedMessage, SDKPlanModeChangedMessage, SDKSessionTitleChangedMessage, SDKFilesPersistedEvent, SDKElicitationCompleteMessage, SDKPromptSuggestionMessage, SDKCloudAgentEventMessage, SDKMemoryGenerationMessage, SDKMemoryConsumptionMessage, SDKSkillEvolutionMessage, SDKPermissionDenial, } from './types/messages.js';
93
+ export type { SDKMessage, SDKAssistantMessage, SDKToolNonExecutionKind, SDKToolResultMeta, SDKArtifactInfo, SDKArtifactUpdateMessage, SDKAvailableModelsUpdateMessage, SDKUserMessage, SDKUserMessageReplay, SDKResultMessage, SDKResultSuccess, SDKResultError, SDKSystemMessage, SDKSystemInitMessage, SDKSystemMessageSubtype, SDKSystemMessageBySubtype, SDKPartialAssistantMessage, SDKCompactBoundaryMessage, SDKStatusMessage, SDKAPIRetryMessage, SDKModelQueueStatusMessage, SDKControlRequestProgressMessage, SDKCommandLifecycleMessage, SDKHookStartedMessage, SDKHookProgressMessage, SDKHookResponseMessage, SDKPermissionDeniedMessage, SDKMirrorErrorMessage, SDKTaskNotificationMessage, SDKTaskStartedMessage, SDKTaskProgressMessage, SDKTaskUpdatedMessage, SDKBackgroundTasksChangedMessage, SDKSessionStateChangedMessage, SDKPlanModeChangedMessage, SDKSessionTitleChangedMessage, SDKFilesPersistedEvent, SDKElicitationCompleteMessage, SDKPromptSuggestionMessage, SDKCloudAgentEventMessage, SDKMemoryGenerationMessage, SDKMemoryConsumptionMessage, SDKSkillEvolutionMessage, SDKPermissionDenial, } from './types/messages.js';
90
94
  export type { DefaultRuntimeTransport, } from './core/default-runtime.js';
91
95
  export type { QueryTransportCreateOptions, QueryTransportProviderOption, } from './core/query-transport.js';
92
96
  export type { ProcessTransportOptions } from './core/process-transport.js';