* docs(serve): v0.16-alpha known limits + SDK QWEN_SERVER_TOKEN env fallback (PR 27) First PR in the F5 release chain (PR 27 → 28 → 30a → 31) per the 2026-05-24 v0.16-alpha scope freeze in #4175 (text-only chat / coding + local-only deployment). ## SDK ergonomic micro-change (~50 LOC + 4 tests) `DaemonClient` constructor falls back to `QWEN_SERVER_TOKEN` env var when `opts.token` is absent — closes the asymmetry where the daemon side already honors this var (--token CLI flag fallback, already in main since PR 15) but the SDK forced clients to thread it through every construction. Properties: - Browser-safe via `globalThis.process` indirection (the SDK is imported by @qwen-code/webui; literal process.env access would explode at module load on browser bundles) - Whitespace stripped (matches daemon-side trim — handy for `export QWEN_SERVER_TOKEN=\"\$(cat token.txt)\"` where cat adds a trailing newline) - Empty / whitespace-only treated as unset (a stale `export QWEN_SERVER_TOKEN=\"\"` won't accidentally send Authorization: Bearer with no token) - Resolved at construction, not lazily per-request (later process.env mutations don't affect already-built clients) - Explicit opts.token wins over env Tests: 4 new in DaemonClient.test.ts `bearer auth` describe covering env fallback / explicit-wins / empty-treated-unset / whitespace-stripped. Plus a defensive snapshot/restore on the existing 'omits Authorization when no token' test so an inherited test-runner export of QWEN_SERVER_TOKEN doesn't turn that assertion into a false positive. This SDK fallback is the entire ergonomic replacement for PR 29's SDK env/file fallback. PR 29's other features (auto-gen daemon token, instance-path keying, stale cleanup) remain deferred to v0.16.x — all are DX improvements over the boot-time security gate already shipped in PR 15. ## v0.16-alpha docs (~120 LOC markdown) - docs/users/qwen-serve.md: new "v0.16-alpha known limits" section enumerating product surface (text-only ✅, multimodal ❌), deployment surface (local launchers ✅, containerized ❌, multi- daemon ❌, BYO-token ✅), and hardening posture (boot security gate ✅, mutation gate ✅, MCP guardrails ✅, prompt absolute deadline ⏸️, rate limiting ⏸️, --max-body-size ⏸️). Adds an alpha banner at the top of the file. - docs/developers/examples/daemon-client-quickstart.md: documents the SDK env fallback in both the Hello-daemon intro and the Authentication section, with the "export + no-token-arg" recommended path called out for local dev. Verification: 125/125 DaemonClient.test.ts pass (121 existing + 4 new); 4/4 daemon-public-surface.test.ts pass (constructor signature unchanged); tsc clean on packages/sdk-typescript; eslint --max-warnings 0 clean on touched .ts files. Part of #4175. * fix(sdk): #4473 round 1 fold-in — 2 copilot doc threads adopted T1 [copilot DaemonClient.ts:144 — stale line refs in readTokenFromEnv JSDoc]: removed `runQwenServe.ts:175` (token resolution actually lives at line 302-318 today, would drift again on next refactor) and `docs/users/qwen-serve.md:173`. Replaced with stable symbol/section references ("runQwenServe token-resolution path"; "qwen-serve user guide CLI flags section"). T2 [copilot daemon-client-quickstart.md:33 — `~/.qwen/server-token` implies built-in path that doesn't exist]: PR 27 explicitly defers token auto-generation + file-store fallback (PR 29 deferred features). The example incorrectly suggested a standard file location. Replaced with two explicit user-managed alternatives: - `openssl rand -hex 32` one-shot - `cat ./my-token-file` user-managed file Both threads were accurate suggestions caught at the right time (zero behavior change; pure docstring/example accuracy). Verification: 125/125 DaemonClient tests pass; tsc + eslint clean on touched files.
116 lines
4.0 KiB
JavaScript
116 lines
4.0 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright 2025 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import { execSync } from 'node:child_process';
|
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
import { resolve } from 'node:path';
|
|
|
|
// A script to handle versioning and ensure all related changes are in a single, atomic commit.
|
|
|
|
function run(command) {
|
|
console.log(`> ${command}`);
|
|
execSync(command, { stdio: 'inherit' });
|
|
}
|
|
|
|
function readJson(filePath) {
|
|
return JSON.parse(readFileSync(filePath, 'utf-8'));
|
|
}
|
|
|
|
function writeJson(filePath, data) {
|
|
writeFileSync(filePath, JSON.stringify(data, null, 2) + '\n');
|
|
}
|
|
|
|
// 1. Get the version from the command line arguments.
|
|
const versionType = process.argv[2];
|
|
if (!versionType) {
|
|
console.error('Error: No version specified.');
|
|
console.error(
|
|
'Usage: npm run version <version> (e.g., 1.2.3 or patch|minor|major|prerelease)',
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
// 2. Bump the version in the root and all workspace package.json files.
|
|
run(`npm version ${versionType} --no-git-tag-version --allow-same-version`);
|
|
|
|
// 3. Get all workspaces and filter out the one we don't want to version.
|
|
// We intend to maintain sdk version independently.
|
|
const workspacesToExclude = ['@qwen-code/sdk'];
|
|
let lsOutput;
|
|
try {
|
|
lsOutput = JSON.parse(
|
|
execSync('npm ls --workspaces --json --depth=0').toString(),
|
|
);
|
|
} catch (e) {
|
|
// `npm ls` can exit with a non-zero status code if there are issues
|
|
// with dependencies, but it will still produce the JSON output we need.
|
|
// We'll try to parse the stdout from the error object.
|
|
if (e.stdout) {
|
|
console.warn(
|
|
'Warning: `npm ls` exited with a non-zero status code. Attempting to proceed with the output.',
|
|
);
|
|
try {
|
|
lsOutput = JSON.parse(e.stdout.toString());
|
|
} catch (parseError) {
|
|
console.error(
|
|
'Error: Failed to parse JSON from `npm ls` output even after `npm ls` failed.',
|
|
);
|
|
console.error('npm ls stderr:', e.stderr.toString());
|
|
console.error('Parse error:', parseError);
|
|
process.exit(1);
|
|
}
|
|
} else {
|
|
console.error('Error: `npm ls` failed with no output.');
|
|
console.error(e.stderr?.toString() || e);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
const allWorkspaces = Object.keys(lsOutput.dependencies || {});
|
|
const workspacesToVersion = allWorkspaces.filter(
|
|
(wsName) => !workspacesToExclude.includes(wsName),
|
|
);
|
|
|
|
for (const workspaceName of workspacesToVersion) {
|
|
run(
|
|
`npm version ${versionType} --workspace ${workspaceName} --no-git-tag-version --allow-same-version`,
|
|
);
|
|
}
|
|
|
|
// 4. Get the new version number from the root package.json
|
|
const rootPackageJsonPath = resolve(process.cwd(), 'package.json');
|
|
const newVersion = readJson(rootPackageJsonPath).version;
|
|
|
|
// 5. Update the sandboxImageUri in the root package.json
|
|
const rootPackageJson = readJson(rootPackageJsonPath);
|
|
if (rootPackageJson.config?.sandboxImageUri) {
|
|
rootPackageJson.config.sandboxImageUri =
|
|
rootPackageJson.config.sandboxImageUri.replace(/:.*$/, `:${newVersion}`);
|
|
console.log(`Updated sandboxImageUri in root to use version ${newVersion}`);
|
|
writeJson(rootPackageJsonPath, rootPackageJson);
|
|
}
|
|
|
|
// 6. Update the sandboxImageUri in the cli package.json
|
|
const cliPackageJsonPath = resolve(process.cwd(), 'packages/cli/package.json');
|
|
const cliPackageJson = readJson(cliPackageJsonPath);
|
|
if (cliPackageJson.config?.sandboxImageUri) {
|
|
cliPackageJson.config.sandboxImageUri =
|
|
cliPackageJson.config.sandboxImageUri.replace(/:.*$/, `:${newVersion}`);
|
|
console.log(
|
|
`Updated sandboxImageUri in cli package to use version ${newVersion}`,
|
|
);
|
|
writeJson(cliPackageJsonPath, cliPackageJson);
|
|
}
|
|
|
|
// 7. Run `npm install` to update package-lock.json.
|
|
// --ignore-scripts prevents the root `prepare` lifecycle from triggering a
|
|
// redundant full build that fails with TS5055 when dist/ already exists from
|
|
// the initial `npm ci` install.
|
|
run(
|
|
'npm install --workspace packages/cli --workspace packages/core --workspace packages/channels/base --workspace packages/channels/plugin-example --package-lock-only --ignore-scripts',
|
|
);
|
|
|
|
console.log(`Successfully bumped versions to v${newVersion}.`);
|