@qoder-ai/qoder-agent-sdk 1.0.16 → 1.0.19

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
@@ -23,16 +23,10 @@ installed if your application uses SDK tools or MCP integration.
23
23
 
24
24
  ## Runtime Behavior
25
25
 
26
- The standard npm package keeps the existing process runtime behavior:
27
- `query()` launches `qodercli` as a child process by default. During
28
- `npm install`, the postinstall script downloads the platform-specific CLI into
29
- `dist/_bundled`.
30
-
31
- Packages built with the Worker runtime bundle bake that choice into the SDK:
32
- their default `query()` transport is `WorkerTransport.default`, and install
33
- does not download the process CLI unless `QODER_INSTALL_BUNDLED_CLI=1` is set.
34
- Worker runtime assets can either be packaged into the tarball or downloaded by
35
- postinstall, depending on the release pipeline.
26
+ The npm package uses `WorkerTransport.default` for `query()` by default. During
27
+ `npm install`, its postinstall script downloads the Worker runtime selected by
28
+ the package's pinned CLI version into `dist/_worker`. It does not download the
29
+ process CLI unless `QODER_INSTALL_BUNDLED_CLI=1` is set.
36
30
 
37
31
  You can still select a transport explicitly on the same `query()` entry:
38
32
 
@@ -52,17 +46,15 @@ const q = query({
52
46
  });
53
47
  ```
54
48
 
55
- When the package includes `dist/_worker/qoder-worker-runtime.obf.mjs`, the
56
- worker transport uses that embedded runtime; otherwise set
49
+ The worker transport uses the runtime installed at
50
+ `dist/_worker/qoder-worker-runtime.obf.mjs`. You can instead set
57
51
  `QODER_WORKER_RUNTIME_PATH` or pass
58
52
  `new WorkerTransport({ pathToQoderWorkerRuntime })`.
59
53
 
60
- Worker-bundled packages include a `dist/runtime-manifest.json` that records the
61
- default runtime and whether the Worker runtime is packaged or installed by
62
- postinstall. Install-delivered packages can also pin the qodercli Worker runtime
63
- archive URL in that manifest; the SDK package itself does not need to host a
64
- copy of the archive. The presence of `dist/_worker` is used as an integrity
65
- check after installation, not as the mode selector.
54
+ The package includes a `dist/runtime-manifest.json` that records the default
55
+ runtime and pins the qodercli Worker runtime archive URL. The SDK package itself
56
+ does not need to host a copy of the archive. The presence of `dist/_worker` is
57
+ used as an integrity check after installation, not as the mode selector.
66
58
 
67
59
  The packaged Worker runtime is built as a self-contained universal profile by
68
60
  default. Runtime assets such as native keychain bindings, PTY bindings, image
@@ -86,61 +78,73 @@ export QODERCLI_PATH=/absolute/path/to/qodercli
86
78
  export QODER_WORKER_RUNTIME_PATH=/absolute/path/to/qoder-worker-runtime.obf.mjs
87
79
  ```
88
80
 
89
- `query()` is the only query entry point. Standard packages default to process;
90
- Worker-bundled packages default to Worker. Pass `transport: ProcessTransport.default`,
81
+ `query()` is the only query entry point and defaults to Worker. Pass
82
+ `transport: ProcessTransport.default`,
91
83
  `transport: WorkerTransport.default`, or a custom transport provider when a
92
84
  single call needs to override the package default.
93
85
 
86
+ `pathToQoderCLIExecutable` accepts either local runtime form. Native binaries
87
+ and ordinary CLI `.js`/`.mjs` entries use the process transport; recognized
88
+ `qoder-worker-runtime*.mjs` entries use the Worker transport. An explicit
89
+ `transport` provider always takes precedence over automatic path selection.
90
+
94
91
  ## Authentication
95
92
 
96
93
  Every SDK query needs an explicit authentication option.
97
94
 
98
- To reuse the local `qodercli` login state:
95
+ | Authentication method | Identity | Use case |
96
+ | --- | --- | --- |
97
+ | Personal Access Token (PAT) | A Qoder user | Automation that needs the user's permissions and data |
98
+ | Service Account | An organization workload | Services and jobs that should not depend on a personal account |
99
+ | Local `qodercli` session | The signed-in user | Interactive development on a workstation |
100
+
101
+ For a PAT, generate a token at
102
+ [qoder.com/account/integrations](https://qoder.com/account/integrations), store
103
+ it in a secret manager, and expose it through the default environment variable:
104
+
105
+ ```bash
106
+ export QODER_PERSONAL_ACCESS_TOKEN=your-token
107
+ ```
99
108
 
100
109
  ```ts
101
- import { qodercliAuth, query } from "@qoder-ai/qoder-agent-sdk";
110
+ import { accessTokenFromEnv, query } from "@qoder-ai/qoder-agent-sdk";
102
111
 
103
112
  const q = query({
104
113
  prompt: "Summarize this repository.",
105
114
  options: {
106
- auth: qodercliAuth(),
115
+ auth: accessTokenFromEnv(),
107
116
  cwd: process.cwd(),
108
117
  },
109
118
  });
110
119
  ```
111
120
 
112
- To authenticate with a personal access token:
113
-
114
- Generate a Personal Access Token at
115
- [qoder.com/account/integrations](https://qoder.com/account/integrations):
116
-
117
- 1. Sign in to your Qoder account.
118
- 2. Open the integrations page.
119
- 3. Create a new PAT, choosing the expiry and scopes you need.
120
- 4. Copy the token immediately. The value cannot be retrieved again after the
121
- page is closed.
122
-
123
- Use separate tokens for local scripts, CI, and production services when
124
- possible, so each environment can be revoked independently. Do not hard-code
125
- tokens in source code.
126
-
127
- ```bash
128
- export QODER_PERSONAL_ACCESS_TOKEN=your-token
129
- ```
121
+ For a Service Account, read the key from your secret manager and pass it
122
+ directly to the SDK:
130
123
 
131
124
  ```ts
132
- import { accessTokenFromEnv, query } from "@qoder-ai/qoder-agent-sdk";
125
+ import { query, serviceAccount } from "@qoder-ai/qoder-agent-sdk";
126
+
127
+ // Get the Service Account key from the host's secret manager adapter.
128
+ const serviceAccountKey = await readSecret("qoder-service-account-key");
133
129
 
134
130
  const q = query({
135
131
  prompt: "Summarize this repository.",
136
132
  options: {
137
- auth: accessTokenFromEnv(),
133
+ auth: serviceAccount({ serviceAccountKey }),
138
134
  cwd: process.cwd(),
139
135
  },
140
136
  });
141
137
  ```
142
138
 
143
- `accessTokenFromEnv()` reads `QODER_PERSONAL_ACCESS_TOKEN` by default.
139
+ The SDK and CLI obtain and refresh short-lived Service Account tokens for this
140
+ authentication method. A host can retain the Service Account key and use
141
+ `serviceAccount({ fetchServiceAccountToken })` to obtain and refresh
142
+ short-lived SATs for qodercli. See the
143
+ [host callback example](examples/service-account-token-demo/demo.mjs) for a
144
+ complete Token exchange and query. To reuse a signed-in developer
145
+ workstation, use `qodercliAuth()`. See the
146
+ [SDK authentication guide](docs/public/en/cli/sdk/authentication.mdx) for
147
+ complete setup instructions and security guidance.
144
148
 
145
149
  ## Quick Start
146
150
 
package/dist/auth.d.ts CHANGED
@@ -1,6 +1,9 @@
1
- import type { AuthOptions, FetchJobToken, JobTokenAuthOptions } from './types/auth.js';
2
- export declare const DEFAULT_ACCESS_TOKEN_ENV_VAR = "QODER_PERSONAL_ACCESS_TOKEN";
1
+ import type { AuthOptions, FetchJobToken, JobTokenAuthOptions, ServiceAccountAuthOptions, ServiceAccountCredentials } from './types/auth.js';
2
+ export declare const DEFAULT_ACCESS_TOKEN_ENV_VAR: string;
3
+ export declare const DEFAULT_SERVICE_ACCOUNT_ENV_VAR: string;
3
4
  export declare function accessToken(token: string): AuthOptions;
4
5
  export declare function accessTokenFromEnv(envVar?: string): AuthOptions;
5
6
  export declare function qodercliAuth(): AuthOptions;
7
+ export declare function serviceAccount(credentials: ServiceAccountCredentials): ServiceAccountAuthOptions;
8
+ export declare function serviceAccountFromEnv(envVar?: string): ServiceAccountAuthOptions;
6
9
  export declare function jobToken(fetchJobToken: FetchJobToken): JobTokenAuthOptions;
@@ -0,0 +1,22 @@
1
+ export type SdkBrand = 'global' | 'cn';
2
+ export declare const SDK_BRAND: SdkBrand;
3
+ export declare const IS_CN_SDK: boolean;
4
+ export declare const SDK_BRAND_CONFIG: {
5
+ productName: string;
6
+ packageName: string;
7
+ cliCommands: readonly ["qoderclicn", "qodercn"];
8
+ configDirName: string;
9
+ configDirEnv: string;
10
+ cliHomeEnv: string;
11
+ accessTokenEnv: string;
12
+ serviceAccountEnv: string;
13
+ } | {
14
+ productName: string;
15
+ packageName: string;
16
+ cliCommands: readonly ["qodercli", "qoder"];
17
+ configDirName: string;
18
+ configDirEnv: string;
19
+ cliHomeEnv: string;
20
+ accessTokenEnv: string;
21
+ serviceAccountEnv: string;
22
+ };
@@ -21,10 +21,7 @@ export declare const CLOSE_GRACE_MS = 2000;
21
21
  * If the process hasn't exited after SIGTERM within this window, force-kill it.
22
22
  */
23
23
  export declare const KILL_GRACE_MS = 5000;
24
- /**
25
- * Current SDK version, sent to CLI as QODER_AGENT_SDK_VERSION environment variable.
26
- */
27
- export declare const SDK_VERSION = "1.0.16";
24
+ export declare const SDK_VERSION: string;
28
25
  /**
29
26
  * Value for the `--permission-prompt-tool` CLI flag.
30
27
  *
@@ -33,16 +30,29 @@ export declare const SDK_VERSION = "1.0.16";
33
30
  * to resolve them via the `canUseTool` callback.
34
31
  */
35
32
  export declare const PERMISSION_PROMPT_TOOL_STDIO = "stdio";
33
+ /**
34
+ * Exit code the Qoder CLI emits for `FATAL_AUTHENTICATION_ERROR`.
35
+ * See qodercli-next packages/core/src/utils/exitCodes.ts.
36
+ */
37
+ export declare const CLI_EXIT_CODE_AUTH_ERROR = 41;
36
38
  /**
37
39
  * Built-in qodercli tools exposed by SDK sessions when callers do not pass
38
40
  * `options.tools`.
39
41
  *
40
42
  * Keep this list explicit so new qodercli built-ins do not automatically
41
43
  * become SDK-visible. Goal, cron, workflow, plan-mode transition, Bash PTY,
42
- * worktree, tracker, topic, and task-control tools remain opt-in via
44
+ * worktree, topic, and background-task control tools remain opt-in via
43
45
  * `options.tools`.
44
46
  */
45
- export declare const SDK_DEFAULT_TOOLS: readonly ["Agent", "AskUserQuestion", "Bash", "Edit", "Glob", "Grep", "ImageGen", "ImageSearch", "NotebookEdit", "Read", "Skill", "TodoWrite", "WebFetch", "WebSearch", "Write"];
47
+ export declare const SDK_DEFAULT_TOOLS: readonly ["Agent", "AskUserQuestion", "Bash", "Edit", "Glob", "Grep", "ImageGen", "ImageSearch", "NotebookEdit", "Read", "Skill", "TaskCreate", "TaskGet", "TaskUpdate", "TaskList", "WebFetch", "WebSearch", "Write"];
48
+ export declare const SDK_TASK_TOOLS: readonly ["TaskCreate", "TaskGet", "TaskUpdate", "TaskList"];
49
+ /**
50
+ * Resolve the SDK's curated default tool surface against qodercli's Task
51
+ * feature flag. qodercli replaces the persistent Task tools with TodoWrite
52
+ * when QODER_FEATURE_TASKS is explicitly disabled, so the SDK must make the
53
+ * same replacement before it writes its explicit --tools allowlist.
54
+ */
55
+ export declare function resolveSdkDefaultTools(env: Record<string, string | undefined>): string[];
46
56
  /**
47
57
  * Tool names with SDK-side enrichment. Tracked as constants so callers and
48
58
  * the runner agree on the exact string the CLI emits.
@@ -9,6 +9,10 @@ export declare class AuthAccessTokenEnvVarError extends Error {
9
9
  readonly code: "auth_access_token_env_var_not_configured";
10
10
  constructor(envVar: string);
11
11
  }
12
+ export declare class AuthServiceAccountEnvVarError extends Error {
13
+ readonly code: "auth_service_account_env_var_not_configured";
14
+ constructor(envVar: string);
15
+ }
12
16
  type ToolsOption = string[] | {
13
17
  type: 'preset';
14
18
  preset: 'qodercli';
@@ -57,6 +61,7 @@ export interface RuntimeLaunchConfig {
57
61
  }
58
62
  export declare function isScriptFile(filePath: string): boolean;
59
63
  export declare function resolveDefaultCliPath(): string;
64
+ export declare function resolveUserInstalledCliPath(): string | null;
60
65
  export declare class RuntimeLaunchOptionsBuilder {
61
66
  private readonly options;
62
67
  private readonly diagnostics?;
@@ -68,6 +73,7 @@ export declare class RuntimeLaunchOptionsBuilder {
68
73
  cleanupGeneratedSettings(): void;
69
74
  cleanupAuthPayload(): Promise<void>;
70
75
  buildEnv(): Record<string, string>;
76
+ private serviceAccountCredentialEnvVars;
71
77
  buildArgs(): string[];
72
78
  private buildSettingsArg;
73
79
  private applyFileCheckpointingSetting;
@@ -82,6 +88,7 @@ export declare class RuntimeLaunchOptionsBuilder {
82
88
  private writeGeneratedSettingsFile;
83
89
  private createAuthPayloadFile;
84
90
  private buildAuthPayload;
91
+ private resolveServiceAccountKey;
85
92
  private resolveAccessToken;
86
93
  }
87
94
  export {};
@@ -0,0 +1,24 @@
1
+ import type { DefaultRuntimeTransport } from './default-runtime.js';
2
+ export interface ImplicitRuntimeOptions {
3
+ pathToQoderCLIExecutable?: string;
4
+ executable?: string;
5
+ executableArgs?: readonly string[];
6
+ spawnQoderCLIProcess?: unknown;
7
+ }
8
+ export type ImplicitRuntimeSelection = {
9
+ transport: 'process';
10
+ } | {
11
+ transport: 'worker';
12
+ pathToQoderWorkerRuntime?: string;
13
+ };
14
+ /**
15
+ * Distinguish a Qoder Worker entry from a CLI native binary or script entry.
16
+ * Unrecognized JavaScript paths remain process CLI entries for compatibility.
17
+ */
18
+ export declare function isQoderWorkerRuntimePath(candidate: string): boolean;
19
+ /**
20
+ * Select the local runtime when the caller has not supplied an explicit
21
+ * transport provider. Explicit paths and process-only launch options override
22
+ * the transport baked into the SDK package.
23
+ */
24
+ export declare function resolveImplicitRuntimeSelection(options: ImplicitRuntimeOptions, packageDefault: DefaultRuntimeTransport, environment?: NodeJS.ProcessEnv): ImplicitRuntimeSelection;
package/dist/index.d.ts CHANGED
@@ -55,7 +55,7 @@ export { query } from './query/query.js';
55
55
  export { DEFAULT_RUNTIME_TRANSPORT, } from './core/default-runtime.js';
56
56
  export { ProcessTransport, QoderCliProcessError, } from './core/process-transport.js';
57
57
  export { hasResolvableQoderWorkerRuntime, QoderWorkerRuntimeError, WorkerTransport, resolveQoderWorkerRuntimePath, } from './core/worker-transport.js';
58
- export { DEFAULT_ACCESS_TOKEN_ENV_VAR, accessToken, accessTokenFromEnv, jobToken, qodercliAuth, } from './auth.js';
58
+ export { DEFAULT_ACCESS_TOKEN_ENV_VAR, DEFAULT_SERVICE_ACCOUNT_ENV_VAR, accessToken, accessTokenFromEnv, jobToken, qodercliAuth, serviceAccount, serviceAccountFromEnv, } from './auth.js';
59
59
  export { createSdkMcpServer, tool } from './mcp/sdk-mcp-server.js';
60
60
  export type { AnyZodRawShape, InferShape, SdkMcpToolDefinition, ToolExtras, CreateSdkMcpServerOptions, } from './mcp/sdk-mcp-server.js';
61
61
  export type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
@@ -71,17 +71,18 @@ export type { PluginDetails, PluginResources, InstallPluginResult, UninstallPlug
71
71
  export { submitFeedback } from './feedback.js';
72
72
  export type { SubmitFeedbackParams, SubmitFeedbackOptions, IntegrationMode, } from './feedback.js';
73
73
  export { AbortError, ModelPolicyTimeoutError, ProtocolVersionMismatchError, } from './core/errors.js';
74
+ export { AuthAccessTokenEnvVarError, AuthServiceAccountEnvVarError, } from './core/runtime-launch-options.js';
74
75
  export { WIRE_PROTOCOL_VERSION } from './protocol/version.js';
75
76
  export type { ModelPromptPatch, ModelPromptPatches, } from './protocol/model-prompt-patches.js';
76
77
  export { HOOK_EVENTS, EXIT_REASONS } from './core/constants.js';
77
78
  import * as coreTypes from './types/index.js';
78
79
  export { coreTypes };
79
- export type { AccessTokenInput, AuthOptions } from './types/auth.js';
80
+ export type { AccessTokenInput, AuthOptions, FetchServiceAccountToken, ServiceAccountAuthOptions, ServiceAccountCredentials, ServiceAccountKeyInput, ServiceAccountTokenResult, } from './types/auth.js';
80
81
  /**
81
82
  * @internal Internal auth types for first-party host integration, not general public use.
82
83
  */
83
84
  export type { FetchJobToken, JobTokenAuthOptions, JobTokenRequest, JobTokenResult, } from './types/auth.js';
84
- export type { AccountInfo, UsageAddOnQuotaBucket, UsageInfo, UsageOrgResourcePackage, UsageQuotaBucket, 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';
85
+ 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';
85
86
  export type { SDKMessage, SDKAssistantMessage, SDKUserMessage, SDKUserMessageReplay, SDKResultMessage, SDKResultSuccess, SDKResultError, SDKSystemMessage, SDKSystemInitMessage, SDKSystemMessageSubtype, SDKSystemMessageBySubtype, SDKPartialAssistantMessage, SDKCompactBoundaryMessage, SDKStatusMessage, SDKAPIRetryMessage, SDKHookStartedMessage, SDKHookProgressMessage, SDKHookResponseMessage, SDKPermissionDeniedMessage, SDKMirrorErrorMessage, SDKTaskNotificationMessage, SDKTaskStartedMessage, SDKTaskProgressMessage, SDKSessionStateChangedMessage, SDKSessionTitleChangedMessage, SDKFilesPersistedEvent, SDKElicitationCompleteMessage, SDKPromptSuggestionMessage, SDKCloudAgentEventMessage, SDKPermissionDenial, } from './types/messages.js';
86
87
  export type { DefaultRuntimeTransport, } from './core/default-runtime.js';
87
88
  export type { QueryTransportCreateOptions, QueryTransportProviderOption, } from './core/query-transport.js';
@@ -102,5 +103,5 @@ export type { QoderModelPurpose } from './types/control.js';
102
103
  export type { SDKControlRequest, SDKControlResponse, SDKControlInterruptResponse, SDKControlInitializeResponse, SDKControlGetContextUsageResponse, SDKControlGetUsageInfoRequest, SDKControlGetUsageInfoResponse, SDKControlAddDirectoriesResponse, SDKControlReloadPluginsResponse, } from './types/control.js';
103
104
  export type { SDKControlGetModelPolicyRequest, SDKControlGetModelPolicyResponse, SDKCapabilities, ModelPolicyContext, ModelPolicyResult, ModelPolicyProvider, } from './types/model-policy-provider.js';
104
105
  export type { SDKControlGetByokConfigRequest, SDKControlGetByokConfigResponse, SDKControlValidateByokModelRequest, SDKControlValidateByokModelResponse, BYOKModelValidationInput, BYOKProviderInfo, BYOKModelTypeInfo, BYOKModelInfo, CustomModel, } from './types/byok.js';
105
- export type { AgentInput, AgentOutput, BashInput, FileReadInput, FileReadOutput, FileEditInput, FileWriteInput, GlobInput, GrepInput, WebFetchInput, WebSearchInput, AskUserQuestionInput, NotebookEditInput, ExitPlanModeInput, TodoWriteInput, ToolInputSchemas, ToolOutputSchemas, } from './types/tools.js';
106
+ export type { AgentInput, AgentOutput, BashInput, FileReadInput, FileReadOutput, FileEditInput, FileWriteInput, GlobInput, GrepInput, WebFetchInput, WebSearchInput, AskUserQuestionInput, NotebookEditInput, TaskCreateInput, TaskCreateOutput, TaskGetInput, TaskGetOutput, TaskUpdateInput, TaskUpdateOutput, TaskListInput, TaskListOutput, ExitPlanModeInput, TodoWriteInput, ToolInputSchemas, ToolOutputSchemas, } from './types/tools.js';
106
107
  export type { FeedbackResult } from './types/account.js';