@qoder-ai/qoder-agent-sdk 1.0.56 → 1.0.58
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 +36 -60
- package/dist/core/default-runtime.d.ts +4 -2
- package/dist/core/errors.d.ts +12 -0
- package/dist/core/process-transport.d.ts +11 -117
- package/dist/core/query-transport.d.ts +12 -2
- package/dist/core/worker-transport.d.ts +8 -52
- package/dist/daemon/daemon-connection.d.ts +25 -7
- package/dist/daemon/global-daemon.d.ts +22 -8
- package/dist/daemon/legacy-transport-compat.d.ts +13 -0
- package/dist/daemon/start-daemon.d.ts +15 -2
- package/dist/index.d.ts +6 -6
- package/dist/index.js +35 -39
- package/dist/protocol/index.d.ts +1 -1
- package/dist/protocol/messages.d.ts +24 -1
- package/dist/runtime-manifest.json +5 -5
- package/dist/types/index.d.ts +1 -4
- package/dist/types/messages.d.ts +1 -1
- package/dist/types/options.d.ts +22 -27
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -23,48 +23,38 @@ installed if your application uses SDK tools or MCP integration.
|
|
|
23
23
|
|
|
24
24
|
## Runtime Behavior
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
the current operating system, and the current architecture. It does not fall
|
|
59
|
-
back to the universal artifact. The SDK package itself does not need to host a
|
|
60
|
-
copy of the archive. The presence of `dist/_worker` is used as an integrity
|
|
61
|
-
check after installation, not as the mode selector.
|
|
62
|
-
|
|
63
|
-
The installed Worker runtime is self-contained. Platform packages include the
|
|
64
|
-
matching native keychain, PTY, image-processing, and ripgrep assets. Linux
|
|
65
|
-
packages retain both glibc and musl image-processing bindings. OpenHarmony does
|
|
66
|
-
not have an install-delivered platform artifact and must use an explicitly
|
|
67
|
-
supplied runtime source.
|
|
26
|
+
`query()` always runs through a process-wide qodercli daemon. The first query
|
|
27
|
+
starts that daemon and reuses it for later queries in the same process; pass
|
|
28
|
+
`options.daemon` to bind a query to a daemon you started yourself with
|
|
29
|
+
`startDaemon()`. The daemon owns the CLI process boundary, so the SDK does not
|
|
30
|
+
spawn a separate CLI per query. Call `shutdownDaemon()` before your host
|
|
31
|
+
process exits to stop the shared daemon.
|
|
32
|
+
|
|
33
|
+
During `npm install`, the postinstall script downloads the CLI binary selected
|
|
34
|
+
by the package's pinned CLI version into `dist/_bundled`; worker packages also
|
|
35
|
+
deliver the worker runtime into `dist/_worker`.
|
|
36
|
+
|
|
37
|
+
The daemon launches qodercli either as a native process carrier or as a Node
|
|
38
|
+
worker runtime. `startDaemon()` / `initDaemon()` accept
|
|
39
|
+
`launchMode: 'process' | 'worker'`; without it, the first query's
|
|
40
|
+
`options.transport` (`ProcessTransport` or `WorkerTransport`) selects the
|
|
41
|
+
carrier, otherwise the package's `DEFAULT_RUNTIME_TRANSPORT` applies. Worker
|
|
42
|
+
mode launches the bundled `dist/_worker` runtime, or the runtime passed through
|
|
43
|
+
`pathToQoderWorkerRuntime`; when no worker runtime is available the daemon
|
|
44
|
+
falls back to the process carrier. A later query whose launch mode differs from
|
|
45
|
+
the ready daemon is rejected with `DaemonConfigurationConflictError`.
|
|
46
|
+
|
|
47
|
+
The process carrier uses `pathToQoderCLIExecutable` when provided, then
|
|
48
|
+
`QODERCLI_PATH`, then the bundled CLI, then a locally installed `qodercli`.
|
|
49
|
+
JavaScript CLI entries run through `executable` (or the SDK host's Node binary).
|
|
50
|
+
|
|
51
|
+
`Options.transport`, `ProcessTransport`, and `WorkerTransport` remain
|
|
52
|
+
available: selecting either transport no longer spawns a per-query process or
|
|
53
|
+
worker, it selects the shared daemon's carrier. Query options that configure
|
|
54
|
+
the CLI process, such as `pathToQoderCLIExecutable`, `executable`,
|
|
55
|
+
`executableArgs`, `env`, `proxy`, `vpcEndpoint`, and `auth`, configure the
|
|
56
|
+
shared daemon instead. Because the daemon is shared, every query in one process
|
|
57
|
+
must pass compatible daemon-level options.
|
|
68
58
|
|
|
69
59
|
If your environment blocks install scripts or network downloads, skip postinstall
|
|
70
60
|
runtime downloads:
|
|
@@ -73,27 +63,13 @@ runtime downloads:
|
|
|
73
63
|
QODER_SKIP_DOWNLOAD=1 npm install @qoder-ai/qoder-agent-sdk zod
|
|
74
64
|
```
|
|
75
65
|
|
|
76
|
-
`QODER_SKIP_DOWNLOAD` only affects install-time downloads.
|
|
77
|
-
|
|
78
|
-
`qodercli`:
|
|
66
|
+
`QODER_SKIP_DOWNLOAD` only affects install-time downloads. Point the daemon at
|
|
67
|
+
an existing `qodercli` with:
|
|
79
68
|
|
|
80
69
|
```bash
|
|
81
70
|
export QODERCLI_PATH=/absolute/path/to/qodercli
|
|
82
71
|
```
|
|
83
72
|
|
|
84
|
-
To use an existing Worker runtime, pass its absolute path through
|
|
85
|
-
`new WorkerTransport({ pathToQoderWorkerRuntime })`.
|
|
86
|
-
|
|
87
|
-
`query()` is the only query entry point and defaults to Worker. Pass
|
|
88
|
-
`transport: ProcessTransport.default`,
|
|
89
|
-
`transport: WorkerTransport.default`, or a custom transport provider when a
|
|
90
|
-
single call needs to override the package default.
|
|
91
|
-
|
|
92
|
-
`pathToQoderCLIExecutable` accepts either local runtime form. Native binaries
|
|
93
|
-
and ordinary CLI `.js`/`.mjs` entries use the process transport; recognized
|
|
94
|
-
`qoder-worker-runtime*.mjs` entries use the Worker transport. An explicit
|
|
95
|
-
`transport` provider always takes precedence over automatic path selection.
|
|
96
|
-
|
|
97
73
|
## Authentication
|
|
98
74
|
|
|
99
75
|
Every SDK query needs an explicit authentication option.
|
|
@@ -452,8 +428,8 @@ non-fatal `system/mirror_error` messages. Each append batch is submitted once:
|
|
|
452
428
|
the SDK does not retry a mutation whose commit outcome may be unknown.
|
|
453
429
|
`loadTimeoutMs` defaults to 60,000 ms.
|
|
454
430
|
Session storage cannot be combined with `persistSession: false`, file
|
|
455
|
-
checkpointing,
|
|
456
|
-
|
|
431
|
+
checkpointing, or the Cloud Agent runtime. It works on daemon-backed queries.
|
|
432
|
+
Use
|
|
457
433
|
`importSessionToStore(sessionId, store, options)` to copy an existing local main
|
|
458
434
|
transcript, child-agent transcripts, and metadata into a store.
|
|
459
435
|
|
|
@@ -2,7 +2,9 @@ export type DefaultRuntimeTransport = 'process' | 'worker';
|
|
|
2
2
|
/**
|
|
3
3
|
* The default transport baked into the packaged SDK bundle.
|
|
4
4
|
*
|
|
5
|
-
* Development / plain `tsc` builds default to `process`.
|
|
6
|
-
* `__QODER_DEFAULT_RUNTIME_TRANSPORT__` through esbuild `define
|
|
5
|
+
* Development / plain `tsc` builds default to `process`. Legacy bundles may
|
|
6
|
+
* replace `__QODER_DEFAULT_RUNTIME_TRANSPORT__` through esbuild `define`; the
|
|
7
|
+
* value is retained for integrations that read it, while every Query now
|
|
8
|
+
* executes through the process-wide daemon.
|
|
7
9
|
*/
|
|
8
10
|
export declare const DEFAULT_RUNTIME_TRANSPORT: DefaultRuntimeTransport;
|
package/dist/core/errors.d.ts
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
* Custom error types for the Qoder Agent SDK.
|
|
3
3
|
*/
|
|
4
4
|
import type { SDKResultMessage } from '../protocol/messages.js';
|
|
5
|
+
export declare class QoderCliProcessError extends Error {
|
|
6
|
+
readonly code: "QODER_CLI_PROCESS_ERROR";
|
|
7
|
+
readonly exitCode?: number | null;
|
|
8
|
+
readonly signal?: NodeJS.Signals | null;
|
|
9
|
+
readonly stderr?: string;
|
|
10
|
+
constructor(message: string, options?: {
|
|
11
|
+
exitCode?: number | null;
|
|
12
|
+
signal?: NodeJS.Signals | null;
|
|
13
|
+
stderr?: string;
|
|
14
|
+
cause?: unknown;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
5
17
|
/** JSONL 帧超过传输预算;输入与输出使用不同错误码,避免把执行端输出问题归因于用户输入。 */
|
|
6
18
|
export declare class FrameTooLargeError extends Error {
|
|
7
19
|
readonly direction: 'input' | 'output';
|
|
@@ -1,40 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ProcessTransport
|
|
3
|
-
* manages stdin/stdout communication using JSONL (JSON Lines) format.
|
|
2
|
+
* ProcessTransport compatibility surface.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* 3. Reads stdout line-by-line, parsing each as JSON
|
|
9
|
-
* 4. Writes to stdin as JSON + newline
|
|
10
|
-
* 5. Handles graceful shutdown: close stdin → wait → SIGTERM → wait → SIGKILL
|
|
4
|
+
* The child-process implementation is gone: selecting this transport now runs
|
|
5
|
+
* the Query through the process-wide daemon. The exported types and members
|
|
6
|
+
* stay so existing integrations keep compiling and keep the same behavior.
|
|
11
7
|
*/
|
|
12
8
|
import type { QueryTransportProvider, Transport } from './transport.js';
|
|
13
|
-
import type { StdoutMessage } from '../types/control.js';
|
|
14
9
|
import type { SdkPluginConfig, ToolConfig } from '../types/common.js';
|
|
15
10
|
import type { PermissionMode } from '../types/permissions.js';
|
|
16
11
|
import type { McpServerConfigForProcessTransport, McpServerToolPolicy } from '../types/mcp.js';
|
|
17
12
|
import type { InternalAuthOptions } from '../types/auth.js';
|
|
18
13
|
import type { SecurityScanOptions, SpawnedProcess, SpawnOptions, SettingSource } from '../types/options.js';
|
|
19
14
|
import type { DiagnosticsSink } from './sdk-diagnostics.js';
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
constructor(message: string, options?: {
|
|
26
|
-
exitCode?: number | null;
|
|
27
|
-
signal?: NodeJS.Signals | null;
|
|
28
|
-
stderr?: string;
|
|
29
|
-
cause?: unknown;
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Options for configuring the ProcessTransport.
|
|
34
|
-
*
|
|
35
|
-
* These map 1:1 to the CLI flags and environment variables that the
|
|
36
|
-
* qodercli understands.
|
|
37
|
-
*/
|
|
15
|
+
export { QoderCliProcessError } from './errors.js';
|
|
16
|
+
type ToolsOption = string[] | {
|
|
17
|
+
type: 'preset';
|
|
18
|
+
preset: 'qodercli';
|
|
19
|
+
};
|
|
38
20
|
export interface ProcessTransportOptions {
|
|
39
21
|
/** Path to the Qoder CLI executable (binary or script) */
|
|
40
22
|
pathToQoderCLIExecutable?: string;
|
|
@@ -120,95 +102,7 @@ export interface ProcessTransportOptions {
|
|
|
120
102
|
*/
|
|
121
103
|
onAuthExpired?: () => void;
|
|
122
104
|
}
|
|
123
|
-
|
|
124
|
-
type: 'preset';
|
|
125
|
-
preset: 'qodercli';
|
|
126
|
-
};
|
|
127
|
-
export declare class ProcessTransport implements Transport, QueryTransportProvider<ProcessTransportOptions> {
|
|
105
|
+
export declare class ProcessTransport implements QueryTransportProvider<ProcessTransportOptions> {
|
|
128
106
|
static readonly default: ProcessTransport;
|
|
129
|
-
private process;
|
|
130
|
-
private customHandle;
|
|
131
|
-
private options;
|
|
132
|
-
private ready;
|
|
133
|
-
private closed;
|
|
134
|
-
private shutdownStarted;
|
|
135
|
-
private initializePromise;
|
|
136
|
-
private authExpiredFired;
|
|
137
|
-
private pendingInput;
|
|
138
|
-
private diagnostics?;
|
|
139
|
-
private processExitError;
|
|
140
|
-
private processStopped;
|
|
141
|
-
private closeTimer;
|
|
142
|
-
private killTimer;
|
|
143
|
-
private stderrTail;
|
|
144
|
-
private launchOptionsBuilder;
|
|
145
|
-
constructor(options?: ProcessTransportOptions);
|
|
146
107
|
create(options: ProcessTransportOptions): Transport;
|
|
147
|
-
|
|
148
|
-
* Build CLI arguments, resolve the executable, spawn the process,
|
|
149
|
-
* and mark the transport as ready.
|
|
150
|
-
*/
|
|
151
|
-
initialize(): Promise<void>;
|
|
152
|
-
private _doInitialize;
|
|
153
|
-
/** Write a JSON line to stdin. */
|
|
154
|
-
write(data: string): void;
|
|
155
|
-
private writeReadyLine;
|
|
156
|
-
private flushPendingInput;
|
|
157
|
-
/** Whether the transport is ready to send/receive. */
|
|
158
|
-
isReady(): boolean;
|
|
159
|
-
/** Signal that no more input will be sent (close stdin). */
|
|
160
|
-
endInput(): void;
|
|
161
|
-
private endReadyInput;
|
|
162
|
-
/**
|
|
163
|
-
* Async generator that yields parsed JSON messages from stdout.
|
|
164
|
-
*
|
|
165
|
-
* Uses readline to split stdout into lines. Each non-empty line is
|
|
166
|
-
* expected to be a complete JSON object (JSONL format).
|
|
167
|
-
*
|
|
168
|
-
* The generator completes when:
|
|
169
|
-
* - The readline interface closes (process exited or stdout ended)
|
|
170
|
-
* - The transport is closed
|
|
171
|
-
*/
|
|
172
|
-
readMessages(): AsyncGenerator<StdoutMessage, void, unknown>;
|
|
173
|
-
/**
|
|
174
|
-
* Close the transport with graceful shutdown:
|
|
175
|
-
*
|
|
176
|
-
* 1. Close stdin (signal to CLI that no more input is coming)
|
|
177
|
-
* 2. Wait CLOSE_GRACE_MS for the process to exit on its own
|
|
178
|
-
* 3. Send SIGTERM
|
|
179
|
-
* 4. Wait KILL_GRACE_MS for the process to exit
|
|
180
|
-
* 5. Send SIGKILL if still running
|
|
181
|
-
*/
|
|
182
|
-
close(): void;
|
|
183
|
-
/** 回收进程资源,不改变调用方主动关闭状态;异常仍由读取循环传播。 */
|
|
184
|
-
private shutdownProcess;
|
|
185
|
-
private hasProcessStopped;
|
|
186
|
-
private finishProcess;
|
|
187
|
-
private observeProcess;
|
|
188
|
-
/**
|
|
189
|
-
* Get the underlying process PID, if available.
|
|
190
|
-
*/
|
|
191
|
-
get pid(): number | undefined;
|
|
192
|
-
/**
|
|
193
|
-
* Get the stdout stream from the process or custom handle.
|
|
194
|
-
*/
|
|
195
|
-
private getStdout;
|
|
196
|
-
private appendStderr;
|
|
197
|
-
private createSpawnError;
|
|
198
|
-
private createProcessExitError;
|
|
199
|
-
private getStderrTail;
|
|
200
|
-
private waitForProcessExit;
|
|
201
|
-
/**
|
|
202
|
-
* Resolve the executable command and arguments.
|
|
203
|
-
*
|
|
204
|
-
* If the CLI path is a script file (.js/.mjs/.ts/.tsx/.jsx), we need
|
|
205
|
-
* an interpreter (node/bun/deno). Otherwise the path is a native binary
|
|
206
|
-
* and is used directly as the command.
|
|
207
|
-
*/
|
|
208
|
-
private resolveExecutable;
|
|
209
|
-
/** 清理 runtime 已消费或不再可能消费的启动制品。 */
|
|
210
|
-
private cleanupLaunchArtifacts;
|
|
211
|
-
/** Fire `onAuthExpired` at most once per session. */
|
|
212
|
-
private fireAuthExpired;
|
|
213
|
-
}
|
|
214
|
-
export {};
|
|
108
|
+
}
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ProcessTransportOptions } from './process-transport.js';
|
|
2
|
+
import type { RuntimeLaunchOptions } from './runtime-launch-options.js';
|
|
2
3
|
import type { QueryTransportProvider, Transport } from './transport.js';
|
|
4
|
+
/** SDK-internal options for the daemon session transport provider. */
|
|
5
|
+
export interface DaemonQueryTransportOptions extends RuntimeLaunchOptions {
|
|
6
|
+
/** SDK-internal: config root created by SessionStore materialization. */
|
|
7
|
+
materializedSessionConfigDir?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Options a custom transport provider receives. Kept as the historical
|
|
11
|
+
* `ProcessTransportOptions` shape so existing providers keep compiling.
|
|
12
|
+
*/
|
|
3
13
|
export type QueryTransportCreateOptions = ProcessTransportOptions;
|
|
4
14
|
export type QueryTransportProviderOption = QueryTransportProvider<QueryTransportCreateOptions>;
|
|
5
15
|
export declare function isQueryTransportProvider(value: unknown): value is QueryTransportProviderOption;
|
|
6
|
-
export declare function createQueryTransport(provider:
|
|
16
|
+
export declare function createQueryTransport<T extends object>(provider: QueryTransportProvider<T>, options: T): Transport;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* WorkerTransport
|
|
2
|
+
* WorkerTransport compatibility surface.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* to avoid spawning a second qoder SEA process.
|
|
4
|
+
* The worker-thread implementation is gone: selecting this transport now runs
|
|
5
|
+
* the Query through the process-wide daemon. The exported classes, helpers and
|
|
6
|
+
* option types stay so existing integrations keep compiling and running.
|
|
8
7
|
*/
|
|
9
8
|
import type { QueryTransportProvider, Transport } from './transport.js';
|
|
10
9
|
import type { ProcessTransportOptions } from './process-transport.js';
|
|
11
|
-
import type { StdoutMessage } from '../types/control.js';
|
|
12
10
|
import type { DiagnosticsSink } from './sdk-diagnostics.js';
|
|
13
|
-
import {
|
|
11
|
+
import type { RuntimeLaunchOptions } from './runtime-launch-options.js';
|
|
14
12
|
import { hasResolvableQoderWorkerRuntime, resolveQoderWorkerRuntimePath } from './worker-runtime-path.js';
|
|
15
13
|
export { hasResolvableQoderWorkerRuntime, resolveQoderWorkerRuntimePath };
|
|
16
14
|
export declare class QoderWorkerRuntimeError extends Error {
|
|
@@ -49,52 +47,10 @@ export interface WorkerRuntimeTransportOptions extends RuntimeLaunchOptions, Wor
|
|
|
49
47
|
onAuthExpired?: () => void;
|
|
50
48
|
}
|
|
51
49
|
export declare class WorkerTransport implements QueryTransportProvider<ProcessTransportOptions> {
|
|
52
|
-
static readonly default: WorkerTransport;
|
|
53
50
|
private readonly options;
|
|
51
|
+
static readonly default: WorkerTransport;
|
|
54
52
|
constructor(options?: WorkerTransportOptions);
|
|
53
|
+
/** query() 用它把 worker 选择映射成 daemon 的宿主形态。 */
|
|
54
|
+
getPathToQoderWorkerRuntime(): string | undefined;
|
|
55
55
|
create(options: ProcessTransportOptions): Transport;
|
|
56
|
-
}
|
|
57
|
-
export declare class WorkerRuntimeTransport implements Transport {
|
|
58
|
-
private worker;
|
|
59
|
-
private options;
|
|
60
|
-
private ready;
|
|
61
|
-
private closed;
|
|
62
|
-
private initializePromise;
|
|
63
|
-
private authExpiredFired;
|
|
64
|
-
private pendingInput;
|
|
65
|
-
private diagnostics?;
|
|
66
|
-
private workerExitError;
|
|
67
|
-
private stderrTail;
|
|
68
|
-
private observedExitCode;
|
|
69
|
-
private launchOptionsBuilder;
|
|
70
|
-
private closeTimer;
|
|
71
|
-
private closePromise;
|
|
72
|
-
private abortSignal?;
|
|
73
|
-
private abortListener?;
|
|
74
|
-
constructor(options?: WorkerRuntimeTransportOptions);
|
|
75
|
-
initialize(): Promise<void>;
|
|
76
|
-
private _doInitialize;
|
|
77
|
-
write(data: string): void;
|
|
78
|
-
isReady(): boolean;
|
|
79
|
-
endInput(): void;
|
|
80
|
-
readMessages(): AsyncGenerator<StdoutMessage, void, unknown>;
|
|
81
|
-
close(): Promise<void>;
|
|
82
|
-
private performClose;
|
|
83
|
-
get threadId(): number | undefined;
|
|
84
|
-
private writeReadyLine;
|
|
85
|
-
private flushPendingInput;
|
|
86
|
-
private endReadyInput;
|
|
87
|
-
private destroyWorkerStreams;
|
|
88
|
-
private appendStderr;
|
|
89
|
-
private createWorkerError;
|
|
90
|
-
private createWorkerExitError;
|
|
91
|
-
private getStderrTail;
|
|
92
|
-
private recordWorkerExit;
|
|
93
|
-
private recordSuppressedWorkerExit;
|
|
94
|
-
private formatStderrTailForDiagnostics;
|
|
95
|
-
private waitForWorkerExit;
|
|
96
|
-
private clearCloseTimer;
|
|
97
|
-
private cleanupAbortListener;
|
|
98
|
-
private cleanupLaunchArtifacts;
|
|
99
|
-
private fireAuthExpired;
|
|
100
56
|
}
|
|
@@ -7,12 +7,15 @@ import type { DiagnosticsSink } from "../core/sdk-diagnostics.js";
|
|
|
7
7
|
export declare const SESSION_STORE_FILE_CHECKPOINTING_CAPABILITY = "session_store_file_checkpointing_v1";
|
|
8
8
|
export declare const SESSION_STORE_FORK_BARRIER_CAPABILITY = "session_store_fork_barrier_v1";
|
|
9
9
|
/**
|
|
10
|
-
* 心跳判死阈值:
|
|
11
|
-
* DAEMON_KEEP_ALIVE_INTERVAL_MS(5s 发送周期,本值 =
|
|
10
|
+
* 心跳判死阈值:120s 无任何入站字节即判 daemon 失活。与 CLI 仓
|
|
11
|
+
* DAEMON_KEEP_ALIVE_INTERVAL_MS(5s 发送周期,本值 = 24 周期)镜像;能力常量
|
|
12
12
|
* DAEMON_KEEP_ALIVE_CAPABILITY 同为两仓镜像,靠握手协商门控——组合不匹配时
|
|
13
13
|
* 最多不武装看门狗,不会误判。
|
|
14
|
+
*
|
|
15
|
+
* 阈值取 120s 而不是 30s:daemon 是共享进程,AI 代码统计等可选后台工作可能在
|
|
16
|
+
* 主线程上产生数十秒的计算停顿;30s 会把「忙」误判成「死」,连带终止全部会话。
|
|
14
17
|
*/
|
|
15
|
-
export declare const DAEMON_HEARTBEAT_TIMEOUT_MS =
|
|
18
|
+
export declare const DAEMON_HEARTBEAT_TIMEOUT_MS = 120000;
|
|
16
19
|
export declare const DAEMON_KEEP_ALIVE_CAPABILITY = "daemon_keep_alive_v1";
|
|
17
20
|
/**
|
|
18
21
|
* daemon 会话 close 改成「关信道即回包、后台排干 teardown」的能力位(CLI 仓镜像)。
|
|
@@ -117,7 +120,12 @@ export interface DaemonSessionIdClaim {
|
|
|
117
120
|
export declare class DaemonHeartbeatTimeoutError extends Error {
|
|
118
121
|
readonly code = "DAEMON_HEARTBEAT_TIMEOUT";
|
|
119
122
|
readonly elapsedMs: number;
|
|
120
|
-
|
|
123
|
+
/**
|
|
124
|
+
* 判死时是否正处在一条未收完的帧中间:区分「daemon 完全静默」与「大帧传到一半
|
|
125
|
+
* 停住」。两者都是连接级失败;该字段只用于现场归因,不改变判定与传播路径。
|
|
126
|
+
*/
|
|
127
|
+
readonly partialFrame: boolean;
|
|
128
|
+
constructor(elapsedMs: number, partialFrame?: boolean);
|
|
121
129
|
}
|
|
122
130
|
export declare class DaemonConnection {
|
|
123
131
|
private readonly input;
|
|
@@ -162,11 +170,20 @@ export declare class DaemonConnection {
|
|
|
162
170
|
private readonly describeUnexpectedClose;
|
|
163
171
|
private readonly diagnostics;
|
|
164
172
|
/**
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
173
|
+
* 心跳看门狗:最近一次**入站字节**的单调钟时刻(每个 chunk 都刷新——有正常会话
|
|
174
|
+
* 流量时天然免检,keep_alive 只是空闲期保底节拍)。
|
|
175
|
+
*
|
|
176
|
+
* 不能等整行收完再刷新:一条大帧(单个 tool 结果可达数 MiB)在慢速管道上可能连续
|
|
177
|
+
* 传输超过阈值,期间字节一直在到达、事件循环也正常,只是换行符还没出现。以行为
|
|
178
|
+
* 单位会把它误判成「daemon 失活」,进而 fail() 整条连接、连带杀掉全部会话。
|
|
179
|
+
* 单调钟使机器睡眠/唤醒后差值仍小,不误杀。看门狗定时器与阈值见 armHeartbeatWatchdog。
|
|
168
180
|
*/
|
|
169
181
|
private lastInboundAt;
|
|
182
|
+
/**
|
|
183
|
+
* 是否正处在一条尚未收完的 NDJSON 帧中间。只用于判死时的诊断:区分「daemon 完全
|
|
184
|
+
* 静默」与「大帧传到一半停住」,不参与是否判死的判定(后者只看字节进展)。
|
|
185
|
+
*/
|
|
186
|
+
private inboundFrameInProgress;
|
|
170
187
|
private heartbeatWatchdog;
|
|
171
188
|
private readonly heartbeatTimeoutMs;
|
|
172
189
|
constructor(options: DaemonConnectionOptions);
|
|
@@ -263,6 +280,7 @@ export declare class DaemonConnection {
|
|
|
263
280
|
private readOutput;
|
|
264
281
|
private acceptFrame;
|
|
265
282
|
private rememberTimedOutRequestId;
|
|
283
|
+
private abandonSessionFromLateResponse;
|
|
266
284
|
private routeSessionMessage;
|
|
267
285
|
private acceptControlResponse;
|
|
268
286
|
private hasPendingSessionRequest;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { InternalAuthOptions } from '../types/auth.js';
|
|
2
|
+
import type { QueryTransportProvider } from '../core/transport.js';
|
|
3
|
+
import type { DaemonQueryTransportOptions } from '../core/query-transport.js';
|
|
2
4
|
import { type Daemon } from './start-daemon.js';
|
|
3
5
|
export interface InitDaemonOptions {
|
|
4
6
|
auth: InternalAuthOptions;
|
|
@@ -13,6 +15,10 @@ export interface InitDaemonOptions {
|
|
|
13
15
|
/** 语义同 `StartDaemonOptions.vpcEndpoint`。 */
|
|
14
16
|
vpcEndpoint?: string;
|
|
15
17
|
env?: Record<string, string | undefined>;
|
|
18
|
+
/** 宿主形态:process=spawn CLI 二进制;worker=Node 跑 worker runtime。缺省 process。 */
|
|
19
|
+
launchMode?: 'process' | 'worker';
|
|
20
|
+
/** worker 形态下覆盖 worker runtime 产物路径。 */
|
|
21
|
+
pathToQoderWorkerRuntime?: string;
|
|
16
22
|
/** 语义同 `StartDaemonOptions.stderr`:daemon 子进程 stderr 的实时回调。 */
|
|
17
23
|
stderr?: (data: string) => void;
|
|
18
24
|
/** 语义同 `StartDaemonOptions.debug`。 */
|
|
@@ -20,16 +26,24 @@ export interface InitDaemonOptions {
|
|
|
20
26
|
/** 语义同 `StartDaemonOptions.debugFile`。 */
|
|
21
27
|
debugFile?: string;
|
|
22
28
|
}
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
export interface GlobalDaemonHandle {
|
|
30
|
+
/**
|
|
31
|
+
* A daemon-shaped handle that resolves every call against the initialization
|
|
32
|
+
* started by `acquireGlobalDaemon`. It is usable before the handshake
|
|
33
|
+
* completes; asynchronous members wait for readiness instead of failing.
|
|
34
|
+
*/
|
|
26
35
|
daemon: Daemon;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
reason: DaemonFallbackReason;
|
|
30
|
-
};
|
|
36
|
+
transportProvider: QueryTransportProvider<DaemonQueryTransportOptions>;
|
|
37
|
+
}
|
|
31
38
|
export declare class DaemonConfigurationConflictError extends Error {
|
|
32
39
|
constructor();
|
|
33
40
|
}
|
|
34
|
-
export declare function initDaemon(options: InitDaemonOptions): Promise<
|
|
41
|
+
export declare function initDaemon(options: InitDaemonOptions): Promise<Daemon>;
|
|
42
|
+
/**
|
|
43
|
+
* Start a query handle backed by the process-wide daemon. The daemon starts
|
|
44
|
+
* immediately, and each Query's session transport waits for that same
|
|
45
|
+
* initialization; a failure rejects the Query instead of falling back to a
|
|
46
|
+
* direct CLI transport.
|
|
47
|
+
*/
|
|
48
|
+
export declare function acquireGlobalDaemon(options: InitDaemonOptions): GlobalDaemonHandle;
|
|
35
49
|
export declare function shutdownDaemon(): Promise<void>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ProcessTransportOptions } from '../core/process-transport.js';
|
|
2
|
+
import type { Transport } from '../core/transport.js';
|
|
3
|
+
/**
|
|
4
|
+
* Built-in Process/Worker transport selections keep their public surface but
|
|
5
|
+
* execute through the process-wide daemon. This adapter is used when a caller
|
|
6
|
+
* invokes the legacy provider's `create()` directly; `query()` routes the same
|
|
7
|
+
* selections without reaching the provider.
|
|
8
|
+
*/
|
|
9
|
+
export interface LegacyDaemonLaunch {
|
|
10
|
+
readonly launchMode: 'process' | 'worker';
|
|
11
|
+
readonly pathToQoderWorkerRuntime?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function createLegacyDaemonTransport(options: ProcessTransportOptions, launch: LegacyDaemonLaunch): Transport;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { InternalAuthOptions } from '../types/auth.js';
|
|
2
|
-
import type { ProcessTransportOptions } from '../core/process-transport.js';
|
|
3
2
|
import type { QueryTransportProvider } from '../core/transport.js';
|
|
3
|
+
import type { DaemonQueryTransportOptions } from '../core/query-transport.js';
|
|
4
4
|
import type { DaemonGetModelsParams, DaemonValidateByokModelParams } from './protocol.js';
|
|
5
5
|
import type { BYOKProviderInfo, ByokConfigCheckResult, ByokConfigInfo, ByokConfigReference, CheckByokConfigInput, CreateByokConfigInput, DeleteByokConfigInput, UpdateByokConfigInput } from '../protocol/control.js';
|
|
6
6
|
import type { AccountInfo, ModelInfo, UsageInfo } from '../protocol/common.js';
|
|
@@ -39,7 +39,20 @@ export interface StartDaemonOptions {
|
|
|
39
39
|
* at any later point, whenever something first triggers the landing.
|
|
40
40
|
*/
|
|
41
41
|
initializeTimeoutMs?: number;
|
|
42
|
+
/**
|
|
43
|
+
* 心跳看门狗阈值(ms):超过这段时间没有任何入站字节即判 daemon 失活。
|
|
44
|
+
* 缺省 120s;0 关闭看门狗(逃生口)。只在 CLI 协商出 `daemon_keep_alive_v1` 后生效。
|
|
45
|
+
* 宿主一般不需要调整;测试与受限环境用它缩短判定窗口。
|
|
46
|
+
*/
|
|
47
|
+
heartbeatTimeoutMs?: number;
|
|
42
48
|
pathToQoderCLIExecutable?: string;
|
|
49
|
+
/**
|
|
50
|
+
* 宿主形态:`process` spawn CLI 二进制;`worker` 用 Node 跑 worker runtime
|
|
51
|
+
* (老 Windows 无法运行 Bun 二进制时使用)。缺省 `process`。
|
|
52
|
+
*/
|
|
53
|
+
launchMode?: 'process' | 'worker';
|
|
54
|
+
/** worker 形态下覆盖 worker runtime 产物路径;缺省用随包/已安装产物。 */
|
|
55
|
+
pathToQoderWorkerRuntime?: string;
|
|
43
56
|
/**
|
|
44
57
|
* 运行 CLI 脚本入口的解释器(node/bun/deno 等),语义与 `query()` 的
|
|
45
58
|
* `Options.executable` 一致:只在解析出的 CLI 入口是脚本文件(.js/.mjs/.ts/...)
|
|
@@ -228,7 +241,7 @@ interface InternalDaemonRuntime {
|
|
|
228
241
|
* when unset, or when the CLI does not support bypass updates).
|
|
229
242
|
*/
|
|
230
243
|
noProxy: string | null;
|
|
231
|
-
readonly transportProvider: QueryTransportProvider<
|
|
244
|
+
readonly transportProvider: QueryTransportProvider<DaemonQueryTransportOptions>;
|
|
232
245
|
}
|
|
233
246
|
export declare function getDaemonRuntime(daemon: Daemon): InternalDaemonRuntime | undefined;
|
|
234
247
|
export declare function startDaemon(options: StartDaemonOptions): Promise<Daemon>;
|
package/dist/index.d.ts
CHANGED
|
@@ -56,14 +56,14 @@ 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
58
|
export { initDaemon, shutdownDaemon } from './daemon/global-daemon.js';
|
|
59
|
-
export type {
|
|
59
|
+
export type { InitDaemonOptions } from './daemon/global-daemon.js';
|
|
60
60
|
export { startDaemon } from './daemon/start-daemon.js';
|
|
61
|
+
export { DEFAULT_RUNTIME_TRANSPORT } from './core/default-runtime.js';
|
|
62
|
+
export { ProcessTransport, QoderCliProcessError } from './core/process-transport.js';
|
|
63
|
+
export { hasResolvableQoderWorkerRuntime, QoderWorkerRuntimeError, WorkerTransport, resolveQoderWorkerRuntimePath, } from './core/worker-transport.js';
|
|
61
64
|
export type { Daemon, DaemonState, DaemonSessionInfo, SessionRuntimeState, StartDaemonOptions, } from './daemon/start-daemon.js';
|
|
62
65
|
export type { DaemonGetModelsParams, DaemonValidateByokModelParams, DaemonValidatePluginsParams, DaemonSetProxyParams, } from './daemon/protocol.js';
|
|
63
66
|
export { DAEMON_PROXY_BYPASS_CAPABILITY, DAEMON_PROXY_CAPABILITY, DAEMON_VALIDATE_PLUGINS_CAPABILITY, } from './daemon/protocol.js';
|
|
64
|
-
export { DEFAULT_RUNTIME_TRANSPORT, } from './core/default-runtime.js';
|
|
65
|
-
export { ProcessTransport, QoderCliProcessError, } from './core/process-transport.js';
|
|
66
|
-
export { hasResolvableQoderWorkerRuntime, QoderWorkerRuntimeError, WorkerTransport, resolveQoderWorkerRuntimePath, } from './core/worker-transport.js';
|
|
67
67
|
export { DEFAULT_ACCESS_TOKEN_ENV_VAR, DEFAULT_SERVICE_ACCOUNT_ENV_VAR, accessToken, accessTokenFromEnv, jobToken, qodercliAuth, serviceAccount, serviceAccountFromEnv, } from './auth.js';
|
|
68
68
|
export { createSdkMcpServer, tool } from './mcp/sdk-mcp-server.js';
|
|
69
69
|
export type { AnyZodRawShape, InferShape, SdkMcpToolDefinition, ToolExtras, CreateSdkMcpServerOptions, } from './mcp/sdk-mcp-server.js';
|
|
@@ -96,11 +96,11 @@ export type { AccessTokenInput, AuthOptions, FetchServiceAccountToken, ServiceAc
|
|
|
96
96
|
*/
|
|
97
97
|
export type { FetchJobToken, JobTokenAuthOptions, JobTokenRequest, JobTokenResult, } from './types/auth.js';
|
|
98
98
|
export type { Base64ImageSource, UrlImageSource, URLImageSource, ImageSource, ImageContentBlock, ImageBlockParam, ContentBlock, MessageParam, 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';
|
|
99
|
-
export type { SDKMessage, SDKAssistantMessage, SDKToolNonExecutionKind, SDKToolResultMeta, SDKMessageOrigin, SDKSelectedSkill, SDKArtifactInfo, SDKArtifactUpdateMessage, SDKAvailableModelsUpdateMessage, SDKCommandsChangedMessage, SDKUserMessage, SDKUserMessageReplay, SDKResultMessage, SDKResultSuccess, SDKResultError, SDKSystemMessage, SDKSystemInitMessage, SDKSystemMessageSubtype, SDKSystemMessageBySubtype, SDKPartialAssistantMessage, SDKCompactBoundaryMessage, SDKStatusMessage, SDKAPIRetryMessage, SDKModelQueueStatusMessage, SDKControlRequestProgressMessage, SDKCommandLifecycleMessage, SDKToolProgressMessage, SDKHookStartedMessage, SDKHookProgressMessage, SDKHookResponseMessage, SDKPermissionDeniedMessage, SDKMirrorErrorMessage, SDKTaskNotificationMessage, SDKTaskStartedMessage, SDKTaskProgressMessage, SDKTaskUpdatedMessage, SDKBackgroundTasksChangedMessage, SDKSessionStateChangedMessage, SDKPlanModeChangedMessage, SDKSessionTitleChangedMessage, SDKFilesPersistedEvent, SDKElicitationCompleteMessage, SDKPromptSuggestionMessage, SDKCloudAgentEventMessage, SDKMemoryGenerationMessage, SDKMemoryConsumptionMessage, SDKSkillEvolutionMessage, SDKAgentsMdSizeWarningMessage, SDKPermissionDenial, } from './types/messages.js';
|
|
99
|
+
export type { SDKMessage, SDKAssistantMessage, SDKToolNonExecutionKind, SDKToolResultMeta, SDKMessageOrigin, SDKSelectedSkill, SDKArtifactInfo, SDKArtifactUpdateMessage, SDKAvailableModelsUpdateMessage, SDKCommandsChangedMessage, SDKUserMessage, SDKUserMessageReplay, SDKResultMessage, SDKResultSuccess, SDKResultError, SDKSystemMessage, SDKSystemInitMessage, SDKSystemMessageSubtype, SDKSystemMessageBySubtype, SDKPartialAssistantMessage, SDKCompactBoundaryMessage, SDKStatusMessage, SDKAPIRetryMessage, SDKModelQueueStatusMessage, SDKControlRequestProgressMessage, SDKCommandLifecycleMessage, SDKToolProgressMessage, SDKHookDiagnosticsMessage, SDKHookStartedMessage, SDKHookProgressMessage, SDKHookResponseMessage, SDKPermissionDeniedMessage, SDKMirrorErrorMessage, SDKTaskNotificationMessage, SDKTaskStartedMessage, SDKTaskProgressMessage, SDKTaskUpdatedMessage, SDKBackgroundTasksChangedMessage, SDKSessionStateChangedMessage, SDKPlanModeChangedMessage, SDKSessionTitleChangedMessage, SDKFilesPersistedEvent, SDKElicitationCompleteMessage, SDKPromptSuggestionMessage, SDKCloudAgentEventMessage, SDKMemoryGenerationMessage, SDKMemoryConsumptionMessage, SDKSkillEvolutionMessage, SDKAgentsMdSizeWarningMessage, SDKPermissionDenial, } from './types/messages.js';
|
|
100
100
|
export type { DefaultRuntimeTransport, } from './core/default-runtime.js';
|
|
101
|
-
export type { QueryTransportCreateOptions, QueryTransportProviderOption, } from './core/query-transport.js';
|
|
102
101
|
export type { ProcessTransportOptions } from './core/process-transport.js';
|
|
103
102
|
export type { WorkerRuntimeTransportOptions, WorkerTransportOptions, } from './core/worker-transport.js';
|
|
103
|
+
export type { QueryTransportCreateOptions, QueryTransportProviderOption, } from './core/query-transport.js';
|
|
104
104
|
export type { QueryTransportProvider, Transport, } from './core/transport.js';
|
|
105
105
|
export type { Options, QueryTransportOptions, Query, RemoteProjectionEnableOptions, RemoteProjectionCheckpoint, SpawnOptions, SpawnedProcess, ElicitationRequest, ElicitationResult, OnElicitation, PromptRequest, PromptRequestOption, PromptResponse, CanUseTool, SecurityScanOptions, } from './types/options.js';
|
|
106
106
|
export type { ArtifactGroup, SessionArtifactBase, SessionArtifact, ResolveSessionArtifactsResult, ResolveSessionArtifacts, } from './types/artifacts.js';
|