@qoder-ai/qoder-agent-sdk 1.0.4 → 1.0.6

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.
@@ -0,0 +1,84 @@
1
+ import type { DiagnosticsSink } from './sdk-diagnostics.js';
2
+ import type { SdkPluginConfig, ToolConfig } from '../types/common.js';
3
+ import type { InternalAuthOptions } from '../types/auth.js';
4
+ import type { PermissionMode } from '../types/permissions.js';
5
+ import type { McpServerConfigForProcessTransport, McpServerToolPolicy } from '../types/mcp.js';
6
+ import type { SettingSource } from '../types/options.js';
7
+ export declare class AuthAccessTokenEnvVarError extends Error {
8
+ readonly code: "auth_access_token_env_var_not_configured";
9
+ constructor(envVar: string);
10
+ }
11
+ type ToolsOption = string[] | {
12
+ type: 'preset';
13
+ preset: 'qodercli';
14
+ };
15
+ export interface RuntimeLaunchOptions {
16
+ cwd?: string;
17
+ env?: Record<string, string | undefined>;
18
+ proxy?: string;
19
+ auth?: InternalAuthOptions;
20
+ model?: string;
21
+ debug?: boolean;
22
+ agent?: string;
23
+ sessionId?: string;
24
+ continue?: boolean;
25
+ resume?: string;
26
+ forkSession?: boolean;
27
+ maxTurns?: number;
28
+ permissionMode?: PermissionMode;
29
+ allowDangerouslySkipPermissions?: boolean;
30
+ permissionPromptToolName?: string;
31
+ canUseTool?: boolean;
32
+ includePartialMessages?: boolean;
33
+ includeHookEvents?: boolean;
34
+ allowedTools?: string[];
35
+ disallowedTools?: string[];
36
+ tools?: ToolsOption;
37
+ toolConfig?: ToolConfig;
38
+ extensions?: string[];
39
+ mcpServers?: Record<string, McpServerConfigForProcessTransport>;
40
+ mcpToolPolicies?: Record<string, McpServerToolPolicy[]>;
41
+ allowedMcpServerNames?: string[];
42
+ strictMcpConfig?: boolean;
43
+ settings?: string | Record<string, unknown>;
44
+ settingSources?: SettingSource[];
45
+ additionalDirectories?: string[];
46
+ plugins?: SdkPluginConfig[];
47
+ enableFileCheckpointing?: boolean;
48
+ extraArgs?: Record<string, string | null>;
49
+ }
50
+ export interface RuntimeLaunchConfig {
51
+ args: string[];
52
+ env: Record<string, string>;
53
+ authPayloadPath?: string;
54
+ }
55
+ export declare function isScriptFile(filePath: string): boolean;
56
+ export declare function resolveDefaultCliPath(): string;
57
+ export declare class RuntimeLaunchOptionsBuilder {
58
+ private readonly options;
59
+ private readonly diagnostics?;
60
+ private readonly logPrefix;
61
+ private authPayloadPath;
62
+ private generatedSettingsDir;
63
+ constructor(options: RuntimeLaunchOptions, diagnostics?: DiagnosticsSink, logPrefix?: string);
64
+ prepare(): Promise<RuntimeLaunchConfig>;
65
+ cleanupGeneratedSettings(): void;
66
+ cleanupAuthPayload(): Promise<void>;
67
+ buildEnv(): Record<string, string>;
68
+ buildArgs(): string[];
69
+ private buildSettingsArg;
70
+ private applyFileCheckpointingSetting;
71
+ private applySettingsCompatibility;
72
+ private toQoderDefaultPermissionMode;
73
+ private applyAdditionalDirectories;
74
+ private buildCliMcpServers;
75
+ private collectMcpPolicyPermissionRules;
76
+ private hasMcpPolicyRules;
77
+ private applyMcpPolicyRules;
78
+ private readSettingsFile;
79
+ private writeGeneratedSettingsFile;
80
+ private createAuthPayloadFile;
81
+ private buildAuthPayload;
82
+ private resolveAccessToken;
83
+ }
84
+ export {};
@@ -11,6 +11,10 @@
11
11
  */
12
12
  import type { StdoutMessage } from '../types/control.js';
13
13
  export interface Transport {
14
+ /**
15
+ * Start the underlying runtime and make the transport ready.
16
+ */
17
+ initialize(): Promise<void>;
14
18
  /**
15
19
  * Write a JSON line to the CLI process stdin.
16
20
  * The transport is responsible for appending the newline delimiter.
@@ -44,4 +48,15 @@ export interface Transport {
44
48
  * entire transport — the CLI may still produce output.
45
49
  */
46
50
  endInput(): void;
51
+ }
52
+ /**
53
+ * Provider for creating a fresh transport for each query() session.
54
+ *
55
+ * A transport instance is stateful: it owns stdin/stdout readers, close state,
56
+ * auth payload cleanup, and runtime lifetime. Host integrations should pass a
57
+ * provider rather than a reusable Transport instance so every query gets an
58
+ * isolated connection.
59
+ */
60
+ export interface QueryTransportProvider<TOptions = any> {
61
+ create(options: TOptions): Transport;
47
62
  }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * WorkerTransport — runs qoder-worker-runtime inside a Node worker thread.
3
+ *
4
+ * This transport keeps the existing SDK stream-json protocol but replaces the
5
+ * child-process boundary with worker stdin/stdout/stderr streams. It is meant
6
+ * for hosts that already own a Node runtime, including Node SEA hosts, and want
7
+ * to avoid spawning a second qoder SEA process.
8
+ */
9
+ import type { QueryTransportProvider, Transport } from './transport.js';
10
+ import type { ProcessTransportOptions } from './process-transport.js';
11
+ import type { StdoutMessage } from '../types/control.js';
12
+ import type { DiagnosticsSink } from './sdk-diagnostics.js';
13
+ import { type RuntimeLaunchOptions } from './runtime-launch-options.js';
14
+ export declare class QoderWorkerRuntimeError extends Error {
15
+ readonly code: "QODER_WORKER_RUNTIME_ERROR";
16
+ readonly exitCode?: number;
17
+ readonly stderr?: string;
18
+ constructor(message: string, options?: {
19
+ exitCode?: number;
20
+ stderr?: string;
21
+ cause?: unknown;
22
+ });
23
+ }
24
+ export interface WorkerTransportOptions {
25
+ /** Path to qoder-worker-runtime.obf.mjs or an equivalent worker entry. */
26
+ pathToQoderWorkerRuntime?: string;
27
+ /** Extra Node worker execArgv. Defaults to an empty list to avoid host flags leaking. */
28
+ execArgv?: string[];
29
+ /** Additional workerData merged under the top-level object. */
30
+ workerData?: Record<string, unknown>;
31
+ }
32
+ export interface WorkerRuntimeTransportOptions extends RuntimeLaunchOptions, WorkerTransportOptions {
33
+ /** stderr handling mode */
34
+ stderr?: 'inherit' | 'pipe' | 'ignore';
35
+ /** Optional callback for worker stderr output */
36
+ stderrHandler?: (data: string) => void;
37
+ /** Abort controller */
38
+ abortController?: AbortController;
39
+ /** SDK-internal diagnostics sink. */
40
+ diagnostics?: DiagnosticsSink;
41
+ /** Called once when the worker exits with an auth-related status. */
42
+ onAuthExpired?: () => void;
43
+ }
44
+ export declare class WorkerTransport implements QueryTransportProvider<ProcessTransportOptions> {
45
+ static readonly default: WorkerTransport;
46
+ private readonly options;
47
+ constructor(options?: WorkerTransportOptions);
48
+ create(options: ProcessTransportOptions): Transport;
49
+ }
50
+ export declare class WorkerRuntimeTransport implements Transport {
51
+ private worker;
52
+ private options;
53
+ private ready;
54
+ private closed;
55
+ private initializePromise;
56
+ private authExpiredFired;
57
+ private pendingInput;
58
+ private diagnostics?;
59
+ private workerExitError;
60
+ private stderrTail;
61
+ private observedExitCode;
62
+ private launchOptionsBuilder;
63
+ private closeTimer;
64
+ constructor(options?: WorkerRuntimeTransportOptions);
65
+ initialize(): Promise<void>;
66
+ private _doInitialize;
67
+ write(data: string): void;
68
+ isReady(): boolean;
69
+ endInput(): void;
70
+ readMessages(): AsyncGenerator<StdoutMessage, void, unknown>;
71
+ close(): void;
72
+ get threadId(): number | undefined;
73
+ private writeReadyLine;
74
+ private flushPendingInput;
75
+ private endReadyInput;
76
+ private appendStderr;
77
+ private createWorkerError;
78
+ private createWorkerExitError;
79
+ private getStderrTail;
80
+ private waitForWorkerExit;
81
+ private clearCloseTimer;
82
+ private cleanupAuthPayload;
83
+ private fireAuthExpired;
84
+ }
85
+ export declare function resolveQoderWorkerRuntimePath(explicitPath?: string): string;
86
+ export declare function hasResolvableQoderWorkerRuntime(explicitPath?: string): boolean;
@@ -19,8 +19,10 @@ export declare class DirectConnectTransport implements Transport {
19
19
  private messages;
20
20
  private exitError?;
21
21
  private partialLine;
22
+ private initializePromise;
22
23
  constructor(options: DirectConnectOptions);
23
- private initialize;
24
+ initialize(): Promise<void>;
25
+ private doInitialize;
24
26
  write(data: string): Promise<void>;
25
27
  close(): void;
26
28
  isReady(): boolean;
@@ -0,0 +1,14 @@
1
+ import type { PluginDetails } from '../types/plugins.js';
2
+ export declare function listPlugins(opts?: {
3
+ orgId?: string;
4
+ cliPath?: string;
5
+ env?: Record<string, string>;
6
+ }): Promise<PluginDetails[]>;
7
+ export declare function enablePlugin(id: string, opts?: {
8
+ cliPath?: string;
9
+ env?: Record<string, string>;
10
+ }): Promise<void>;
11
+ export declare function disablePlugin(id: string, opts?: {
12
+ cliPath?: string;
13
+ env?: Record<string, string>;
14
+ }): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -3,8 +3,8 @@
3
3
  *
4
4
  * TypeScript SDK for programmatic access to qodercli capabilities.
5
5
  *
6
- * The SDK works by spawning a qodercli subprocess and communicating
7
- * via a bidirectional JSON line protocol over stdin/stdout.
6
+ * The SDK talks to the configured Qoder runtime transport using a
7
+ * bidirectional JSON line protocol.
8
8
  *
9
9
  * @example Basic usage
10
10
  * ```typescript
@@ -52,7 +52,9 @@
52
52
  * ```
53
53
  */
54
54
  export { query } from './query/query.js';
55
- export { QoderCliProcessError } from './core/process-transport.js';
55
+ export { DEFAULT_RUNTIME_TRANSPORT, } from './core/default-runtime.js';
56
+ export { ProcessTransport, QoderCliProcessError, } from './core/process-transport.js';
57
+ export { hasResolvableQoderWorkerRuntime, QoderWorkerRuntimeError, WorkerTransport, resolveQoderWorkerRuntimePath, } from './core/worker-transport.js';
56
58
  export { DEFAULT_ACCESS_TOKEN_ENV_VAR, accessToken, accessTokenFromEnv, jobToken, qodercliAuth, } from './auth.js';
57
59
  export { createSdkMcpServer, tool } from './mcp/sdk-mcp-server.js';
58
60
  export type { AnyZodRawShape, InferShape, SdkMcpToolDefinition, ToolExtras, CreateSdkMcpServerOptions, } from './mcp/sdk-mcp-server.js';
@@ -60,6 +62,8 @@ export type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
60
62
  export type { ToolAnnotations } from '@modelcontextprotocol/sdk/types.js';
61
63
  export { listSessions, getSessionInfo, getSessionMessages, getSubagentMessages, listSubagents, renameSession, tagSession, } from './session/session-manager.js';
62
64
  export { forkSession } from './session/session-fork.js';
65
+ export { listPlugins, enablePlugin, disablePlugin } from './global/plugins.js';
66
+ export type { PluginDetails, PluginResources } from './types/plugins.js';
63
67
  export { submitFeedback } from './feedback.js';
64
68
  export type { SubmitFeedbackParams, SubmitFeedbackOptions, IntegrationMode, } from './feedback.js';
65
69
  export { AbortError, DirectConnectError, ModelPolicyTimeoutError, ProtocolVersionMismatchError, } from './core/errors.js';
@@ -74,9 +78,14 @@ export type { AccessTokenInput, AuthOptions } from './types/auth.js';
74
78
  * @internal Internal auth types for first-party host integration, not general public use.
75
79
  */
76
80
  export type { FetchJobToken, JobTokenAuthOptions, JobTokenRequest, JobTokenResult, } from './types/auth.js';
77
- export type { AccountInfo, UsageAddOnQuotaBucket, UsageInfo, UsageOrgResourcePackage, UsageQuotaBucket, ApiKeySource, ExitReason, FastModeState, ConfigScope, SettingSource, SDKAssistantMessageError, SDKStatus, EffortLevel, ThinkingAdaptive, ThinkingEnabled, ThinkingDisabled, ThinkingConfig, OutputFormatType, JsonSchemaOutputFormat, OutputFormat, BaseOutputFormat, ModelInfo, ModelSource, ModelStrategy, ModelContextConfig, ModelContextWindowEntry, ModelEffortEntry, ModelThinkingConfig, ModelThinkingDisabled, ModelThinkingEnabled, ModelUsage, NonNullableUsage, SlashCommand, ToolConfig, SdkPluginConfig, } from './types/common.js';
81
+ export type { AccountInfo, UsageAddOnQuotaBucket, UsageInfo, UsageOrgResourcePackage, UsageQuotaBucket, ApiKeySource, ExitReason, FastModeState, ConfigScope, SettingSource, SDKAssistantMessageError, SDKStatus, EffortLevel, ThinkingAdaptive, ThinkingEnabled, ThinkingDisabled, ThinkingConfig, OutputFormatType, JsonSchemaOutputFormat, OutputFormat, BaseOutputFormat, ModelInfo, ModelSource, ServerModelJson, ServerModelJsonValue, ModelStrategy, ModelPromotion, LocalizedModelText, ModelContextConfig, ModelContextWindowEntry, ModelEffortEntry, ModelThinkingConfig, ModelThinkingDisabled, ModelThinkingEnabled, ModelUsage, NonNullableUsage, SlashCommand, ToolConfig, SdkPluginConfig, } from './types/common.js';
78
82
  export type { SDKMessage, SDKAssistantMessage, SDKUserMessage, SDKUserMessageReplay, SDKResultMessage, SDKResultSuccess, SDKResultError, SDKSystemMessage, SDKSystemInitMessage, SDKSystemMessageSubtype, SDKSystemMessageBySubtype, SDKPartialAssistantMessage, SDKCompactBoundaryMessage, SDKStatusMessage, SDKAPIRetryMessage, SDKLocalCommandOutputMessage, SDKHookStartedMessage, SDKHookProgressMessage, SDKHookResponseMessage, SDKPermissionDeniedMessage, SDKTaskNotificationMessage, SDKTaskStartedMessage, SDKTaskProgressMessage, SDKSessionStateChangedMessage, SDKSessionTitleChangedMessage, SDKBridgeStateMessage, SDKFilesPersistedEvent, SDKElicitationCompleteMessage, SDKPromptSuggestionMessage, SDKCloudAgentEventMessage, SDKPermissionDenial, } from './types/messages.js';
79
- export type { Options, Query, SpawnOptions, SpawnedProcess, ElicitationRequest, ElicitationResult, OnElicitation, PromptRequest, PromptRequestOption, PromptResponse, CanUseTool, Transport, } from './types/options.js';
83
+ export type { DefaultRuntimeTransport, } from './core/default-runtime.js';
84
+ export type { QueryTransportCreateOptions, QueryTransportProviderOption, } from './core/query-transport.js';
85
+ export type { ProcessTransportOptions } from './core/process-transport.js';
86
+ export type { WorkerRuntimeTransportOptions, WorkerTransportOptions, } from './core/worker-transport.js';
87
+ export type { QueryTransportProvider, Transport, } from './core/transport.js';
88
+ export type { Options, QueryTransportOptions, Query, SpawnOptions, SpawnedProcess, ElicitationRequest, ElicitationResult, OnElicitation, PromptRequest, PromptRequestOption, PromptResponse, CanUseTool, } from './types/options.js';
80
89
  export type { AgentCreateParams, BetaManagedAgentsAgentToolName, BetaManagedAgentsAgentToolset20260401Params, BetaManagedAgentsCustomSkillParams, BetaManagedAgentsFileResourceParams, BetaManagedAgentsModel, BetaManagedAgentsSkillParams, BetaManagedAgentsURLMCPServerParams, CloudAgentOptions, CloudAgentReference, CloudAgentStreamOptions, CloudSessionResource, CloudSessionCreateParams, CloudSessionCreateReference, CloudSessionExistingReference, CloudSessionReference, SessionCreateParams, } from './types/cloud-agent.js';
81
90
  export type { SettingSource as SettingSourceFromOptions } from './types/options.js';
82
91
  export type { PermissionMode, PermissionBehavior, PermissionDecisionClassification, PermissionUpdateDestination, PermissionRuleValue, PermissionUpdate, PermissionResult, CanUseToolOptions, PermissionDecisionReasonType, ExitPlanModeApprovalDetails, } from './types/permissions.js';