From dd7faea5c0e6483b1ae83ab66a50031b2ff44583 Mon Sep 17 00:00:00 2001 From: Wang Tai Date: Tue, 17 Nov 2026 15:28:29 +0800 Subject: [PATCH 1/3] feat(shell): stream pack-route files with HTTP range Preview routes can return a file or raw bytes. The loopback server sends them with range requests so clients no longer base64-encode documents. Signed-off-by: Wang Tai --- .../src/local-backend/pack-backend-routes.ts | 14 +- .../ts/src/local-backend/router.ts | 25 ++- packages/agent-shell/ts/src/scenario/pack.ts | 4 + .../agent-shell/ts/src/server/http-server.ts | 152 +++++++++++++++++- .../ts/tests/local-backend/router.test.ts | 31 ++++ .../ts/tests/server/http-server.test.ts | 95 +++++++++++ .../agent-shell/web/src/lib/host-bridge.ts | 21 +++ .../web/src/lib/http-bridge.test.ts | 42 +++++ .../agent-shell/web/src/lib/http-bridge.ts | 35 ++++ packages/pack-sdk/ts/types/index.d.ts | 33 +++- 10 files changed, 442 insertions(+), 10 deletions(-) diff --git a/packages/agent-shell/ts/src/local-backend/pack-backend-routes.ts b/packages/agent-shell/ts/src/local-backend/pack-backend-routes.ts index 0328bf12f..e3a489b3e 100644 --- a/packages/agent-shell/ts/src/local-backend/pack-backend-routes.ts +++ b/packages/agent-shell/ts/src/local-backend/pack-backend-routes.ts @@ -12,13 +12,25 @@ */ import type { + PackBackendAnyResponse, + PackBackendBinaryBytesResponse, + PackBackendBinaryFileResponse, + PackBackendBinaryResponse, PackBackendRoute, PackBackendRouteRequest, PackBackendRouteResponse, } from '@steerable/pack-sdk'; // 类型单一真源在 @steerable/pack-sdk(阶段 2.2);re-export 兼容既有调用方。 -export type { PackBackendRoute, PackBackendRouteRequest, PackBackendRouteResponse }; +export type { + PackBackendAnyResponse, + PackBackendBinaryBytesResponse, + PackBackendBinaryFileResponse, + PackBackendBinaryResponse, + PackBackendRoute, + PackBackendRouteRequest, + PackBackendRouteResponse, +}; interface RegisteredPackBackendRoute extends PackBackendRoute { readonly packId: string; diff --git a/packages/agent-shell/ts/src/local-backend/router.ts b/packages/agent-shell/ts/src/local-backend/router.ts index efa4875ae..1ceb9de21 100644 --- a/packages/agent-shell/ts/src/local-backend/router.ts +++ b/packages/agent-shell/ts/src/local-backend/router.ts @@ -153,7 +153,7 @@ import { collectPackForcedSkillVars, collectPackWorldState, } from './pack-turn-hooks.js'; -import { matchPackBackendRoute } from './pack-backend-routes.js'; +import { matchPackBackendRoute, type PackBackendBinaryResponse } from './pack-backend-routes.js'; import { invokePackHttpRoute } from '../host/http-routes.js'; import { installProductCli } from '../cli-install.js'; import { collectTurnFiles } from './turn-files.js'; @@ -164,6 +164,8 @@ export interface LocalBackendRequest { method: string; path: string; body?: unknown; + /** 原始请求头(HTTP 模式下透传)。 */ + headers?: Record; /** Authenticated identity supplied by the BS HTTP layer. */ principal?: Principal; } @@ -173,6 +175,10 @@ export interface LocalBackendResponse { data: T; } +export type LocalBackendRawResponse = + | LocalBackendResponse + | PackBackendBinaryResponse; + function stringRecord(value: unknown): Record { if (!value || typeof value !== 'object' || Array.isArray(value)) return {}; return Object.fromEntries( @@ -586,14 +592,26 @@ export class LocalBackendRouter { return this.store; } - handle(request: LocalBackendRequest): Promise { + async handle(request: LocalBackendRequest): Promise { + const response = await this.handleRaw(request); + if ('kind' in response) { + return { + status: 406, + data: { detail: 'binary response requires HTTP transport' }, + }; + } + return response; + } + + /** 与 handle() 相同,但保留包路由返回的二进制流/字节响应供 HTTP 层直接输出。 */ + handleRaw(request: LocalBackendRequest): Promise { return this.storeContext.run( this.resolveStore(request.principal), () => this.handleScoped(request), ); } - private async handleScoped(request: LocalBackendRequest): Promise { + private async handleScoped(request: LocalBackendRequest): Promise { const { method } = request; const url = new URL(request.path, 'http://local.backend'); const pathname = url.pathname; @@ -2670,6 +2688,7 @@ export class LocalBackendRouter { params: packMatch.params, query: url.searchParams, body: request.body, + ...(request.headers ? { headers: request.headers } : {}), }); } diff --git a/packages/agent-shell/ts/src/scenario/pack.ts b/packages/agent-shell/ts/src/scenario/pack.ts index db714abb0..e683d702b 100644 --- a/packages/agent-shell/ts/src/scenario/pack.ts +++ b/packages/agent-shell/ts/src/scenario/pack.ts @@ -33,6 +33,10 @@ export type { CliCommandIO, CliCommandSpec, ScenarioPack, + PackBackendAnyResponse, + PackBackendBinaryBytesResponse, + PackBackendBinaryFileResponse, + PackBackendBinaryResponse, PackBackendRouteResponse, PackBackendRouteRequest, PackBackendRoute, diff --git a/packages/agent-shell/ts/src/server/http-server.ts b/packages/agent-shell/ts/src/server/http-server.ts index d652966d9..371410292 100644 --- a/packages/agent-shell/ts/src/server/http-server.ts +++ b/packages/agent-shell/ts/src/server/http-server.ts @@ -25,11 +25,12 @@ */ import { createServer, type IncomingMessage, type Server, type ServerResponse } from 'node:http'; import { randomBytes } from 'node:crypto'; -import { readFile } from 'node:fs/promises'; -import { existsSync } from 'node:fs'; +import { readFile, stat } from 'node:fs/promises'; +import { createReadStream, existsSync } from 'node:fs'; import path from 'node:path'; import { log } from '../log.js'; import type { LocalBackendRouter } from '../local-backend/router.js'; +import type { PackBackendBinaryResponse } from '../local-backend/pack-backend-routes.js'; import { getActiveCoreLoopStreamId } from '../local-backend/coreloop-stream.js'; import { getSidecarSupervisor } from '../llm/index.js'; import type { ScopedStore } from '../storage/scoped-store.js'; @@ -129,6 +130,140 @@ function sendJson(res: ServerResponse, status: number, data: unknown): void { res.end(body); } +type ParsedByteRange = + | { kind: 'none' } + | { kind: 'invalid' } + | { kind: 'range'; start: number; end: number }; + +function parseByteRange(header: string | string[] | undefined, size: number): ParsedByteRange { + if (header === undefined) return { kind: 'none' }; + const raw = Array.isArray(header) ? header[0] : header; + if (!raw) return { kind: 'none' }; + const match = /^bytes=(\d*)-(\d*)$/i.exec(raw.trim()); + if (!match) return { kind: 'invalid' }; + const [, startText, endText] = match; + if (!startText && !endText) return { kind: 'invalid' }; + if (size <= 0) return { kind: 'invalid' }; + if (!startText) { + const suffix = Number(endText); + if (!Number.isSafeInteger(suffix) || suffix <= 0) return { kind: 'invalid' }; + const start = Math.max(0, size - suffix); + return { kind: 'range', start, end: size - 1 }; + } + const start = Number(startText); + if (!Number.isSafeInteger(start) || start < 0 || start >= size) return { kind: 'invalid' }; + if (!endText) return { kind: 'range', start, end: size - 1 }; + const requestedEnd = Number(endText); + if (!Number.isSafeInteger(requestedEnd) || requestedEnd < start) return { kind: 'invalid' }; + return { kind: 'range', start, end: Math.min(requestedEnd, size - 1) }; +} + +function contentDispositionInline(fileName: string | undefined): string | undefined { + if (!fileName) return undefined; + const ascii = fileName.replace(/[^\x20-\x7E]+/g, '_').replace(/["\\]/g, '_'); + const encoded = encodeURIComponent(fileName); + return `inline; filename="${ascii}"; filename*=UTF-8''${encoded}`; +} + +async function sendBinaryResponse( + req: IncomingMessage, + res: ServerResponse, + response: PackBackendBinaryResponse, +): Promise { + const disposition = contentDispositionInline(response.fileName); + if (response.kind === 'bytes') { + const headers: Record = { + 'Content-Type': response.contentType, + 'Content-Length': response.body.byteLength, + 'Cache-Control': response.cacheControl ?? 'private, no-store', + }; + if (disposition) headers['Content-Disposition'] = disposition; + res.writeHead(response.status, headers); + res.end(req.method === 'HEAD' ? undefined : response.body); + return; + } + + let fileStat; + try { + fileStat = await stat(response.filePath); + } catch { + sendJson(res, 404, { detail: 'file not found' }); + return; + } + if (!fileStat.isFile()) { + sendJson(res, 404, { detail: 'file not found' }); + return; + } + + const size = fileStat.size; + const etag = response.etag ?? `W/"${size}-${Math.round(fileStat.mtimeMs)}"`; + const range = response.status === 200 ? parseByteRange(req.headers.range, size) : { kind: 'none' as const }; + if (range.kind === 'invalid') { + res.writeHead(416, { + 'Content-Range': `bytes */${size}`, + 'Accept-Ranges': 'bytes', + 'Cache-Control': 'no-store', + }); + res.end(); + return; + } + + const headers: Record = { + 'Content-Type': response.contentType, + 'Accept-Ranges': 'bytes', + 'Cache-Control': response.cacheControl ?? 'private, no-cache', + ETag: etag, + }; + if (disposition) headers['Content-Disposition'] = disposition; + + if (range.kind === 'range') { + headers['Content-Range'] = `bytes ${range.start}-${range.end}/${size}`; + headers['Content-Length'] = range.end - range.start + 1; + res.writeHead(206, headers); + } else { + headers['Content-Length'] = size; + res.writeHead(response.status, headers); + } + + if (req.method === 'HEAD' || size === 0) { + res.end(); + return; + } + + const stream = createReadStream( + response.filePath, + range.kind === 'range' ? { start: range.start, end: range.end } : undefined, + ); + const onResClose = () => { + if (!stream.destroyed) stream.destroy(); + }; + res.on('close', onResClose); + await new Promise((resolve, reject) => { + let settled = false; + const done = () => { + if (settled) return; + settled = true; + res.off('close', onResClose); + resolve(); + }; + stream.on('error', (err) => { + if (settled) return; + settled = true; + res.off('close', onResClose); + if (!res.headersSent) { + sendJson(res, 500, { detail: 'failed to read file' }); + resolve(); + return; + } + res.destroy(err); + reject(err); + }); + stream.on('close', done); + res.on('finish', done); + stream.pipe(res); + }); +} + async function readJsonBody(req: IncomingMessage): Promise { const chunks: Buffer[] = []; let size = 0; @@ -215,12 +350,19 @@ export function createBsServer(deps: BsServerDeps): Server { } try { - const response = await localBackendRouter.handle(request); + const response = typeof localBackendRouter.handleRaw === 'function' + ? await localBackendRouter.handleRaw({ ...request, headers: req.headers }) + : await localBackendRouter.handle(request); log.info(`[bs] ${request.method} ${pathname} -> ${response.status}`); - sendJson(res, response.status, response.data); + if ('kind' in response) { + await sendBinaryResponse(req, res, response); + } else { + sendJson(res, response.status, response.data); + } } catch (err) { log.error(`[bs] ${request.method} ${pathname} threw`, err); - sendJson(res, 500, { detail: 'internal error' }); + if (!res.headersSent) sendJson(res, 500, { detail: 'internal error' }); + else res.end(); } } diff --git a/packages/agent-shell/ts/tests/local-backend/router.test.ts b/packages/agent-shell/ts/tests/local-backend/router.test.ts index c40409cf6..ec78c4f10 100644 --- a/packages/agent-shell/ts/tests/local-backend/router.test.ts +++ b/packages/agent-shell/ts/tests/local-backend/router.test.ts @@ -2238,6 +2238,37 @@ describe('占位与 fallback 路由', () => { ); }); + it('二进制包路由:handleRaw 透传 headers 并原样返回 file/bytes;handle 回 406', async () => { + const handler = vi.fn(() => ({ + status: 200, + kind: 'bytes' as const, + body: new Uint8Array([1, 2, 3]), + contentType: 'application/pdf', + })); + h.packRoute = { params: {}, route: { handler } }; + const router = makeRouter(); + const raw = await router.handleRaw({ + method: 'GET', + path: '/api/v2/aroli/file-preview/raw', + headers: { range: 'bytes=0-1' }, + }); + expect(raw).toEqual({ + status: 200, + kind: 'bytes', + body: new Uint8Array([1, 2, 3]), + contentType: 'application/pdf', + }); + expect(handler).toHaveBeenCalledWith( + expect.objectContaining({ headers: { range: 'bytes=0-1' } }), + ); + + const jsonOnly = await router.handle({ + method: 'GET', + path: '/api/v2/aroli/file-preview/raw', + }); + expect(jsonOnly.status).toBe(406); + }); + it('fallback:GET 列表型端点返回空集合形状;其他 GET 返回 {};非 GET 返回 noop', async () => { const router = makeRouter(); const listLike = await router.handle({ method: 'GET', path: '/api/v2/unknowns' }); diff --git a/packages/agent-shell/ts/tests/server/http-server.test.ts b/packages/agent-shell/ts/tests/server/http-server.test.ts index 330d48f5a..9c689fd22 100644 --- a/packages/agent-shell/ts/tests/server/http-server.test.ts +++ b/packages/agent-shell/ts/tests/server/http-server.test.ts @@ -667,4 +667,99 @@ describe('BS HTTP server', () => { expect((await post('/host/local/exec-shell', { command: 'pwd' })).status).toBe(200); }); }); + + describe('二进制流与 Range 206 响应', () => { + const handleRaw = vi.fn(); + + beforeEach(async () => { + handleRaw.mockReset(); + await new Promise((resolve) => server.close(() => resolve())); + const deps = makeDeps(webDistDir); + server = createBsServer({ + ...deps, + localBackendRouter: { + ...deps.localBackendRouter, + handleRaw, + } as unknown as BsServerDeps['localBackendRouter'], + }); + await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve)); + base = `http://127.0.0.1:${(server.address() as AddressInfo).port}`; + }); + + it('kind=bytes 直接输出原始字节并带 Content-Type / Content-Disposition', async () => { + handleRaw.mockResolvedValue({ + status: 200, + kind: 'bytes', + body: new Uint8Array([0x25, 0x50, 0x44, 0x46]), + contentType: 'application/pdf', + fileName: '报告.pdf', + }); + const res = await get('/api/v2/aroli/file-preview/raw'); + expect(res.status).toBe(200); + expect(res.headers.get('content-type')).toBe('application/pdf'); + expect(res.headers.get('content-disposition')).toContain('inline;'); + expect(new Uint8Array(await res.arrayBuffer())).toEqual(new Uint8Array([0x25, 0x50, 0x44, 0x46])); + }); + + it('kind=file 支持全量流、HEAD、Range 206 切片及 416 越界拒绝', async () => { + const filePath = path.join(webDistDir, 'sample.bin'); + writeFileSync(filePath, '0123456789ABCDEF'); + handleRaw.mockResolvedValue({ + status: 200, + kind: 'file', + filePath, + contentType: 'application/pdf', + }); + + const full = await get('/api/v2/aroli/file-preview/raw'); + expect(full.status).toBe(200); + expect(full.headers.get('accept-ranges')).toBe('bytes'); + expect(full.headers.get('content-length')).toBe('16'); + expect(full.headers.get('etag')).toMatch(/^W\/"16-\d+"$/); + expect(await full.text()).toBe('0123456789ABCDEF'); + + const head = await fetch(`${base}/api/v2/aroli/file-preview/raw`, { + method: 'HEAD', + headers: AUTH, + }); + expect(head.status).toBe(200); + expect(head.headers.get('content-length')).toBe('16'); + expect(await head.text()).toBe(''); + + const partial = await fetch(`${base}/api/v2/aroli/file-preview/raw`, { + headers: { ...AUTH, Range: 'bytes=2-6' }, + }); + expect(partial.status).toBe(206); + expect(partial.headers.get('content-range')).toBe('bytes 2-6/16'); + expect(partial.headers.get('content-length')).toBe('5'); + expect(await partial.text()).toBe('23456'); + + const suffix = await fetch(`${base}/api/v2/aroli/file-preview/raw`, { + headers: { ...AUTH, Range: 'bytes=-4' }, + }); + expect(suffix.status).toBe(206); + expect(suffix.headers.get('content-range')).toBe('bytes 12-15/16'); + expect(await suffix.text()).toBe('CDEF'); + + const invalid = await fetch(`${base}/api/v2/aroli/file-preview/raw`, { + headers: { ...AUTH, Range: 'bytes=99-120' }, + }); + expect(invalid.status).toBe(416); + expect(invalid.headers.get('content-range')).toBe('bytes */16'); + }); + + it('未授权请求访问二进制端点仍返回 401,文件不存在返回 404', async () => { + const unauth = await fetch(`${base}/api/v2/aroli/file-preview/raw`); + expect(unauth.status).toBe(401); + + handleRaw.mockResolvedValue({ + status: 200, + kind: 'file', + filePath: path.join(webDistDir, 'missing.pdf'), + contentType: 'application/pdf', + }); + const missing = await get('/api/v2/aroli/file-preview/raw'); + expect(missing.status).toBe(404); + }); + }); }); diff --git a/packages/agent-shell/web/src/lib/host-bridge.ts b/packages/agent-shell/web/src/lib/host-bridge.ts index 833ff46e2..0da987ae5 100644 --- a/packages/agent-shell/web/src/lib/host-bridge.ts +++ b/packages/agent-shell/web/src/lib/host-bridge.ts @@ -16,6 +16,20 @@ export type LocalBackendRequestInput = { body?: unknown; }; +export type LocalBackendBinaryRequestInput = { + method?: 'GET' | 'POST'; + path: string; + body?: unknown; + signal?: AbortSignal; +}; + +export interface LocalBackendBinaryResponse { + status: number; + headers: Headers; + arrayBuffer: () => Promise; + blob: () => Promise; +} + export type LocalBackendStreamEvent = | { type: 'data'; chunk: string; parsed?: SSEEvent } | { type: 'end'; status: number } @@ -180,6 +194,13 @@ export interface HostBridge { }; localBackend: { request: (input: LocalBackendRequestInput) => Promise; + requestBinary?: ( + input: LocalBackendBinaryRequestInput, + ) => Promise; + resolveAuthorizedFetch?: (path: string) => { + url: string; + headers: Record; + }; startStream: ( input: LocalBackendRequestInput, onEvent: (payload: LocalBackendStreamEvent) => void, diff --git a/packages/agent-shell/web/src/lib/http-bridge.test.ts b/packages/agent-shell/web/src/lib/http-bridge.test.ts index 8258b9b14..b9304b4fb 100644 --- a/packages/agent-shell/web/src/lib/http-bridge.test.ts +++ b/packages/agent-shell/web/src/lib/http-bridge.test.ts @@ -336,4 +336,46 @@ describe('浏览器形态的 local.* 降级', () => { expect(bridge.setZoom).toBeUndefined(); expect(bridge.onZoomChanged).toBeUndefined(); }); + + it('requestBinary 透传 AbortSignal 与 Bearer 头并返回原始字节;resolveAuthorizedFetch 带鉴权头', async () => { + vi.stubGlobal('__DEEPPATH_BS__', { platform: 'darwin', flavor: 'test', brandName: 'T', token: 'tok-bin' }); + const bytes = new Uint8Array([7, 8, 9]).buffer; + const fetchMock = stubFetch(() => ({ + ok: true, + status: 200, + headers: new Headers({ 'content-type': 'application/pdf' }), + arrayBuffer: () => Promise.resolve(bytes), + blob: () => Promise.resolve(new Blob([bytes])), + })); + const controller = new AbortController(); + const bridge = createHttpBridge(); + const res = await bridge.localBackend.requestBinary!({ + path: '/api/v2/aroli/file-preview/raw?chatId=c1', + signal: controller.signal, + }); + expect(fetchMock).toHaveBeenCalledWith('/api/v2/aroli/file-preview/raw?chatId=c1', { + method: 'GET', + headers: { Authorization: 'Bearer tok-bin' }, + body: undefined, + signal: controller.signal, + }); + expect(new Uint8Array(await res.arrayBuffer())).toEqual(new Uint8Array([7, 8, 9])); + expect(bridge.localBackend.resolveAuthorizedFetch!('/api/v2/aroli/file-preview/raw')).toEqual({ + url: '/api/v2/aroli/file-preview/raw', + headers: { Authorization: 'Bearer tok-bin' }, + }); + }); + + it('requestBinary 非 2xx 时解析 detail 并抛出带 status 的错误', async () => { + stubFetch(() => ({ + ok: false, + status: 404, + json: () => Promise.resolve({ detail: '找不到这个文件' }), + })); + const bridge = createHttpBridge(); + const err = await bridge.localBackend.requestBinary!({ path: '/missing' }).catch((e: unknown) => e); + expect(err).toBeInstanceOf(Error); + expect((err as Error).message).toBe('找不到这个文件'); + expect((err as Error & { status?: number }).status).toBe(404); + }); }); diff --git a/packages/agent-shell/web/src/lib/http-bridge.ts b/packages/agent-shell/web/src/lib/http-bridge.ts index ad70277f4..683efba9f 100644 --- a/packages/agent-shell/web/src/lib/http-bridge.ts +++ b/packages/agent-shell/web/src/lib/http-bridge.ts @@ -18,6 +18,8 @@ import type { ApprovalPromptRequest, AskUserPromptRequest, HostBridge, + LocalBackendBinaryRequestInput, + LocalBackendBinaryResponse, LocalBackendRequestInput, LocalBackendStreamEvent, TerminalSession, @@ -73,6 +75,34 @@ async function http(method: string, path: string, body?: unknown): Promise return data; } +async function httpBinary( + input: LocalBackendBinaryRequestInput, +): Promise { + const method = input.method ?? 'GET'; + const res = await fetch(input.path, { + method, + headers: { + ...(input.body !== undefined ? { 'Content-Type': 'application/json' } : {}), + ...authHeaders(), + }, + body: input.body !== undefined ? JSON.stringify(input.body) : undefined, + signal: input.signal, + }); + if (!res.ok) { + const data = await res.json().catch(() => null); + const err = new Error(httpErrorMessage(data, res.status)) as Error & { status?: number; data?: unknown }; + err.status = res.status; + err.data = data; + throw err; + } + return { + status: res.status, + headers: res.headers, + arrayBuffer: () => res.arrayBuffer(), + blob: () => res.blob(), + }; +} + // --------------------------------------------------------------------------- // 事件总线:一条 EventSource 承载所有 channel(channel 名与 IPC 通道一致)。 // --------------------------------------------------------------------------- @@ -256,6 +286,11 @@ export function createHttpBridge(): HostBridge { localBackend: { request: (input: LocalBackendRequestInput) => http(input.method, input.path, input.body), + requestBinary: (input: LocalBackendBinaryRequestInput) => httpBinary(input), + resolveAuthorizedFetch: (path: string) => ({ + url: path, + headers: authHeaders(), + }), startStream, cancelStream, steerChat: async (chatId, content, options) => { diff --git a/packages/pack-sdk/ts/types/index.d.ts b/packages/pack-sdk/ts/types/index.d.ts index f4b7257e6..0b41e45e3 100644 --- a/packages/pack-sdk/ts/types/index.d.ts +++ b/packages/pack-sdk/ts/types/index.d.ts @@ -290,19 +290,50 @@ export interface PackBackendRouteResponse { data: T; } +/** 二进制文件流响应:由宿主 HTTP 层按字节流式输出并自动支持 Range 206。 */ +export interface PackBackendBinaryFileResponse { + readonly status: number; + readonly kind: 'file'; + readonly filePath: string; + readonly contentType: string; + readonly fileName?: string; + readonly cacheControl?: string; + readonly etag?: string; +} + +/** 内存二进制响应:由宿主 HTTP 层直接输出字节,不经过 JSON/base64 编码。 */ +export interface PackBackendBinaryBytesResponse { + readonly status: number; + readonly kind: 'bytes'; + readonly body: Uint8Array; + readonly contentType: string; + readonly fileName?: string; + readonly cacheControl?: string; +} + +export type PackBackendBinaryResponse = + | PackBackendBinaryFileResponse + | PackBackendBinaryBytesResponse; + +export type PackBackendAnyResponse = + | PackBackendRouteResponse + | PackBackendBinaryResponse; + /** 包路由请求:段参数 + query + 反序列化后的 body。 */ export interface PackBackendRouteRequest { readonly params: Record; /** URL query(searchParams 原样透传,多值键取逗号拼接语义同 URL 规范)。 */ readonly query: URLSearchParams; readonly body: unknown; + /** 原始请求头(HTTP 模式下透传,便于检查 Range / If-None-Match)。 */ + readonly headers?: Record; } export interface PackBackendRoute { readonly method: 'GET' | 'POST' | 'PUT' | 'DELETE'; /** 路径模式,如 '/api/v2/ppt-preview/edits/:id/cancel'。 */ readonly path: string; - readonly handler: (req: PackBackendRouteRequest) => Promise; + readonly handler: (req: PackBackendRouteRequest) => Promise; } // ─── 回合级钩子契约 ─── From 033791e123667dce90811cccb44fb895b2c46cd5 Mon Sep 17 00:00:00 2001 From: deeppath-release-bot Date: Tue, 17 Nov 2026 07:37:31 +0000 Subject: [PATCH 2/3] chore(release): v0.12.4 Signed-off-by: deeppath-release-bot --- package.json | 2 +- packages/agent-cli/ts/package.json | 2 +- packages/agent-client/ts/package.json | 2 +- packages/agent-harness/py/pyproject.toml | 2 +- packages/agent-harness/ts/package.json | 2 +- packages/agent-protocol/py/pyproject.toml | 2 +- packages/agent-protocol/ts/package.json | 2 +- packages/agent-runtime/py/pyproject.toml | 2 +- packages/agent-runtime/ts/package.json | 2 +- packages/agent-shell/tauri/package.json | 2 +- packages/agent-shell/ts/package.json | 2 +- packages/agent-shell/web/package.json | 2 +- packages/agent-ui/ts/package.json | 2 +- packages/pack-sdk/ts/package.json | 2 +- packages/plugin-sdk/py/pyproject.toml | 2 +- packages/sidecar/py/pyproject.toml | 2 +- uv.lock | 10 +++++----- 17 files changed, 21 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 7c9819e40..101471931 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/monorepo", - "version": "0.12.3", + "version": "0.12.4", "private": true, "type": "module", "packageManager": "pnpm@10.23.0", diff --git a/packages/agent-cli/ts/package.json b/packages/agent-cli/ts/package.json index 8ab894f72..a168f2fd6 100644 --- a/packages/agent-cli/ts/package.json +++ b/packages/agent-cli/ts/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/agent-cli", - "version": "0.12.3", + "version": "0.12.4", "description": "Product-neutral command line for a Steerable host. Products supply the bin name and brand.", "license": "Apache-2.0", "homepage": "https://steerableframework.com/", diff --git a/packages/agent-client/ts/package.json b/packages/agent-client/ts/package.json index 3b79e89a6..a21f29baa 100644 --- a/packages/agent-client/ts/package.json +++ b/packages/agent-client/ts/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/agent-client", - "version": "0.12.3", + "version": "0.12.4", "description": "In-process client for a Steerable host: HTTP-shaped requests, turn streams, and approval replies.", "license": "Apache-2.0", "homepage": "https://steerableframework.com/", diff --git a/packages/agent-harness/py/pyproject.toml b/packages/agent-harness/py/pyproject.toml index e85a037d7..6fd23c302 100644 --- a/packages/agent-harness/py/pyproject.toml +++ b/packages/agent-harness/py/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "steerable-agent-harness" -version = "0.12.3" +version = "0.12.4" description = "Steerable harness helpers for Python" license = { text = "Apache-2.0" } readme = "README.md" diff --git a/packages/agent-harness/ts/package.json b/packages/agent-harness/ts/package.json index ff6d641cd..aa3f16fc9 100644 --- a/packages/agent-harness/ts/package.json +++ b/packages/agent-harness/ts/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/agent-harness", - "version": "0.12.3", + "version": "0.12.4", "description": "Steerable framework Tier 2 \u2014 TypeScript facade over the Python harness (policy, budget, retry, completion, tracing) used for cross-language conformance tests. Production code should depend on the Python harness.", "license": "Apache-2.0", "homepage": "https://steerableframework.com/", diff --git a/packages/agent-protocol/py/pyproject.toml b/packages/agent-protocol/py/pyproject.toml index cb8106249..f9b7d62b1 100644 --- a/packages/agent-protocol/py/pyproject.toml +++ b/packages/agent-protocol/py/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "steerable-agent-protocol" -version = "0.12.3" +version = "0.12.4" description = "Steerable protocol schemas for Python" license = { text = "Apache-2.0" } readme = "README.md" diff --git a/packages/agent-protocol/ts/package.json b/packages/agent-protocol/ts/package.json index a7795aa84..c3dfdc648 100644 --- a/packages/agent-protocol/ts/package.json +++ b/packages/agent-protocol/ts/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/agent-protocol", - "version": "0.12.3", + "version": "0.12.4", "description": "Steerable framework Tier 1 \u2014 wire-format types (SSEEvent, ChatMessage, ToolCall, ToolResult, AgentSession, HarnessTrace, sidecar JSON-RPC) shared by every Steerable client and server.", "license": "Apache-2.0", "homepage": "https://steerableframework.com/", diff --git a/packages/agent-runtime/py/pyproject.toml b/packages/agent-runtime/py/pyproject.toml index c0dfbde61..b188a1579 100644 --- a/packages/agent-runtime/py/pyproject.toml +++ b/packages/agent-runtime/py/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "steerable-agent-runtime" -version = "0.12.3" +version = "0.12.4" description = "Steerable agent runtime: LLM, tool, storage, and transport adapters." license = { text = "Apache-2.0" } readme = "README.md" diff --git a/packages/agent-runtime/ts/package.json b/packages/agent-runtime/ts/package.json index 87523662a..225c06824 100644 --- a/packages/agent-runtime/ts/package.json +++ b/packages/agent-runtime/ts/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/agent-runtime", - "version": "0.12.3", + "version": "0.12.4", "description": "Steerable framework \u2014 official TypeScript production runtime. Owns the embedded Python sidecar lifecycle (spawn / ready handshake / health / bounded auto-restart / graceful drain) and exposes the CoreLoop-level API over the sidecar JSON-RPC surface. There is no TS CoreLoop; this package drives the same Rust CoreLoop the server uses (via the Python sidecar facade), so cross-language conformance holds by construction.", "license": "Apache-2.0", "homepage": "https://steerableframework.com/", diff --git a/packages/agent-shell/tauri/package.json b/packages/agent-shell/tauri/package.json index acce9b7f8..b682b151b 100644 --- a/packages/agent-shell/tauri/package.json +++ b/packages/agent-shell/tauri/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/agent-shell-tauri", - "version": "0.12.3", + "version": "0.12.4", "description": "Reusable Tauri Rust host source for @steerable/agent-shell", "license": "Apache-2.0", "homepage": "https://steerableframework.com/", diff --git a/packages/agent-shell/ts/package.json b/packages/agent-shell/ts/package.json index aeb597fec..cd7dff791 100644 --- a/packages/agent-shell/ts/package.json +++ b/packages/agent-shell/ts/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/agent-shell", - "version": "0.12.3", + "version": "0.12.4", "description": "Steerable framework \u2014 product-neutral Node HostRuntime and headless HTTP server shared by Tauri desktop and browser deployments; scenario packs extend it through @steerable/pack-sdk.", "license": "Apache-2.0", "homepage": "https://steerableframework.com/", diff --git a/packages/agent-shell/web/package.json b/packages/agent-shell/web/package.json index 5cbe13cc0..3123e51b9 100644 --- a/packages/agent-shell/web/package.json +++ b/packages/agent-shell/web/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/agent-shell-web", - "version": "0.12.3", + "version": "0.12.4", "type": "module", "description": "Steerable framework \u2014 product-neutral renderer SPA source for @steerable/agent-shell (React + Vite). Consumed by product web entry points via the `@/` alias (anchored at this package's src/) and the createProductViteConfig factory. Published as a source package (src/), plus the compiled vite.base config factory (vite.base.js + .d.ts) for Node-side config loading.", "license": "Apache-2.0", diff --git a/packages/agent-ui/ts/package.json b/packages/agent-ui/ts/package.json index 28cc2e6de..846c291da 100644 --- a/packages/agent-ui/ts/package.json +++ b/packages/agent-ui/ts/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/agent-ui", - "version": "0.12.3", + "version": "0.12.4", "description": "Steerable framework Tier 4 \u2014 headless React hooks (useAgentSession, useChatStream, useToolCallStatus) and Tailwind-themed components (ChatPanel, MessageList, OrchestrationPlanCard, ToolCallRenderer, SSEStreamView) for embedding Steerable agents in any React app.", "license": "Apache-2.0", "homepage": "https://steerableframework.com/storybook/", diff --git a/packages/pack-sdk/ts/package.json b/packages/pack-sdk/ts/package.json index fb6d35c28..752ad99fc 100644 --- a/packages/pack-sdk/ts/package.json +++ b/packages/pack-sdk/ts/package.json @@ -1,6 +1,6 @@ { "name": "@steerable/pack-sdk", - "version": "0.12.3", + "version": "0.12.4", "type": "module", "description": "Scenario pack contract for @steerable/agent-shell (pure types, zero runtime). A scenario pack declares every extension a vertical scenario needs \u2014 services, tools, tables, skills, agent seeds, HTTP routes, renderer slots, branding \u2014 and the host composes the selected packs at build time.", "license": "Apache-2.0", diff --git a/packages/plugin-sdk/py/pyproject.toml b/packages/plugin-sdk/py/pyproject.toml index 3c773e913..c6ad3a09b 100644 --- a/packages/plugin-sdk/py/pyproject.toml +++ b/packages/plugin-sdk/py/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "steerable-plugin-sdk" -version = "0.12.3" +version = "0.12.4" description = "Pure-Python authoring and RPC SDK for Steerable tool plugins" license = { text = "Apache-2.0" } readme = "README.md" diff --git a/packages/sidecar/py/pyproject.toml b/packages/sidecar/py/pyproject.toml index 6a56c9489..832cd46f4 100644 --- a/packages/sidecar/py/pyproject.toml +++ b/packages/sidecar/py/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "steerable-sidecar" -version = "0.12.3" +version = "0.12.4" description = "Steerable agent runtime sidecar — JSON-RPC over stdio." license = { text = "Apache-2.0" } readme = "README.md" diff --git a/uv.lock b/uv.lock index 7243640bf..6b63972cf 100644 --- a/uv.lock +++ b/uv.lock @@ -1709,7 +1709,7 @@ wheels = [ [[package]] name = "steerable-agent-harness" -version = "0.12.3" +version = "0.12.4" source = { editable = "packages/agent-harness/py" } dependencies = [ { name = "pydantic" }, @@ -1724,7 +1724,7 @@ requires-dist = [ [[package]] name = "steerable-agent-protocol" -version = "0.12.3" +version = "0.12.4" source = { editable = "packages/agent-protocol/py" } dependencies = [ { name = "pydantic" }, @@ -1735,7 +1735,7 @@ requires-dist = [{ name = "pydantic", specifier = ">=2.10.0" }] [[package]] name = "steerable-agent-runtime" -version = "0.12.3" +version = "0.12.4" source = { editable = "packages/agent-runtime/py" } dependencies = [ { name = "httpx", extra = ["socks"] }, @@ -1863,7 +1863,7 @@ dev = [ [[package]] name = "steerable-plugin-sdk" -version = "0.12.3" +version = "0.12.4" source = { editable = "packages/plugin-sdk/py" } dependencies = [ { name = "steerable-agent-harness" }, @@ -1878,7 +1878,7 @@ requires-dist = [ [[package]] name = "steerable-sidecar" -version = "0.12.3" +version = "0.12.4" source = { editable = "packages/sidecar/py" } dependencies = [ { name = "ag-ui-protocol" }, From dd509374b998070820d677b4ef7dc591e9dfd1b5 Mon Sep 17 00:00:00 2001 From: Wang Tai Date: Tue, 17 Nov 2026 15:39:30 +0800 Subject: [PATCH 3/3] fix(shell): keep product names out of pack-route tests The public exposure gate rejects product names in the framework tree. Binary route tests now use a generic preview path. Signed-off-by: Wang Tai --- .../ts/tests/local-backend/router.test.ts | 4 ++-- .../ts/tests/server/http-server.test.ts | 16 ++++++++-------- .../agent-shell/web/src/lib/http-bridge.test.ts | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/agent-shell/ts/tests/local-backend/router.test.ts b/packages/agent-shell/ts/tests/local-backend/router.test.ts index ec78c4f10..24d6fe9c2 100644 --- a/packages/agent-shell/ts/tests/local-backend/router.test.ts +++ b/packages/agent-shell/ts/tests/local-backend/router.test.ts @@ -2249,7 +2249,7 @@ describe('占位与 fallback 路由', () => { const router = makeRouter(); const raw = await router.handleRaw({ method: 'GET', - path: '/api/v2/aroli/file-preview/raw', + path: '/api/v2/files/preview/raw', headers: { range: 'bytes=0-1' }, }); expect(raw).toEqual({ @@ -2264,7 +2264,7 @@ describe('占位与 fallback 路由', () => { const jsonOnly = await router.handle({ method: 'GET', - path: '/api/v2/aroli/file-preview/raw', + path: '/api/v2/files/preview/raw', }); expect(jsonOnly.status).toBe(406); }); diff --git a/packages/agent-shell/ts/tests/server/http-server.test.ts b/packages/agent-shell/ts/tests/server/http-server.test.ts index 9c689fd22..538724ce0 100644 --- a/packages/agent-shell/ts/tests/server/http-server.test.ts +++ b/packages/agent-shell/ts/tests/server/http-server.test.ts @@ -694,7 +694,7 @@ describe('BS HTTP server', () => { contentType: 'application/pdf', fileName: '报告.pdf', }); - const res = await get('/api/v2/aroli/file-preview/raw'); + const res = await get('/api/v2/files/preview/raw'); expect(res.status).toBe(200); expect(res.headers.get('content-type')).toBe('application/pdf'); expect(res.headers.get('content-disposition')).toContain('inline;'); @@ -711,14 +711,14 @@ describe('BS HTTP server', () => { contentType: 'application/pdf', }); - const full = await get('/api/v2/aroli/file-preview/raw'); + const full = await get('/api/v2/files/preview/raw'); expect(full.status).toBe(200); expect(full.headers.get('accept-ranges')).toBe('bytes'); expect(full.headers.get('content-length')).toBe('16'); expect(full.headers.get('etag')).toMatch(/^W\/"16-\d+"$/); expect(await full.text()).toBe('0123456789ABCDEF'); - const head = await fetch(`${base}/api/v2/aroli/file-preview/raw`, { + const head = await fetch(`${base}/api/v2/files/preview/raw`, { method: 'HEAD', headers: AUTH, }); @@ -726,7 +726,7 @@ describe('BS HTTP server', () => { expect(head.headers.get('content-length')).toBe('16'); expect(await head.text()).toBe(''); - const partial = await fetch(`${base}/api/v2/aroli/file-preview/raw`, { + const partial = await fetch(`${base}/api/v2/files/preview/raw`, { headers: { ...AUTH, Range: 'bytes=2-6' }, }); expect(partial.status).toBe(206); @@ -734,14 +734,14 @@ describe('BS HTTP server', () => { expect(partial.headers.get('content-length')).toBe('5'); expect(await partial.text()).toBe('23456'); - const suffix = await fetch(`${base}/api/v2/aroli/file-preview/raw`, { + const suffix = await fetch(`${base}/api/v2/files/preview/raw`, { headers: { ...AUTH, Range: 'bytes=-4' }, }); expect(suffix.status).toBe(206); expect(suffix.headers.get('content-range')).toBe('bytes 12-15/16'); expect(await suffix.text()).toBe('CDEF'); - const invalid = await fetch(`${base}/api/v2/aroli/file-preview/raw`, { + const invalid = await fetch(`${base}/api/v2/files/preview/raw`, { headers: { ...AUTH, Range: 'bytes=99-120' }, }); expect(invalid.status).toBe(416); @@ -749,7 +749,7 @@ describe('BS HTTP server', () => { }); it('未授权请求访问二进制端点仍返回 401,文件不存在返回 404', async () => { - const unauth = await fetch(`${base}/api/v2/aroli/file-preview/raw`); + const unauth = await fetch(`${base}/api/v2/files/preview/raw`); expect(unauth.status).toBe(401); handleRaw.mockResolvedValue({ @@ -758,7 +758,7 @@ describe('BS HTTP server', () => { filePath: path.join(webDistDir, 'missing.pdf'), contentType: 'application/pdf', }); - const missing = await get('/api/v2/aroli/file-preview/raw'); + const missing = await get('/api/v2/files/preview/raw'); expect(missing.status).toBe(404); }); }); diff --git a/packages/agent-shell/web/src/lib/http-bridge.test.ts b/packages/agent-shell/web/src/lib/http-bridge.test.ts index b9304b4fb..1b99703e7 100644 --- a/packages/agent-shell/web/src/lib/http-bridge.test.ts +++ b/packages/agent-shell/web/src/lib/http-bridge.test.ts @@ -350,18 +350,18 @@ describe('浏览器形态的 local.* 降级', () => { const controller = new AbortController(); const bridge = createHttpBridge(); const res = await bridge.localBackend.requestBinary!({ - path: '/api/v2/aroli/file-preview/raw?chatId=c1', + path: '/api/v2/files/preview/raw?chatId=c1', signal: controller.signal, }); - expect(fetchMock).toHaveBeenCalledWith('/api/v2/aroli/file-preview/raw?chatId=c1', { + expect(fetchMock).toHaveBeenCalledWith('/api/v2/files/preview/raw?chatId=c1', { method: 'GET', headers: { Authorization: 'Bearer tok-bin' }, body: undefined, signal: controller.signal, }); expect(new Uint8Array(await res.arrayBuffer())).toEqual(new Uint8Array([7, 8, 9])); - expect(bridge.localBackend.resolveAuthorizedFetch!('/api/v2/aroli/file-preview/raw')).toEqual({ - url: '/api/v2/aroli/file-preview/raw', + expect(bridge.localBackend.resolveAuthorizedFetch!('/api/v2/files/preview/raw')).toEqual({ + url: '/api/v2/files/preview/raw', headers: { Authorization: 'Bearer tok-bin' }, }); });