Files
Mujoco_WASM/web_platform/e2e/fixtures/subscriptionSession.ts
T
chenlin f3a8a38acd
web-platform-ci / Standalone decision service (no cloud credentials) (push) Has been cancelled
web-platform-ci / TypeScript, lint, unit, build (push) Has been cancelled
web-platform-ci / Playwright E2E (push) Has been cancelled
lekiwi-compatibility / cpu-compatibility (push) Has been cancelled
web-platform-ci / Standalone decision service (no cloud credentials) (pull_request) Has been cancelled
web-platform-ci / TypeScript, lint, unit, build (pull_request) Has been cancelled
web-platform-ci / Playwright E2E (pull_request) Has been cancelled
lekiwi-compatibility / cpu-compatibility (pull_request) Has been cancelled
feat: release v1.0.1 CADWorld 网站与 LeKiwi 智能抓放
集成同源 BYOK 会话隔离、精简模型设置、官方订阅入口和 HTTPS 发布运维;保留本地训练/调参与控制能力。同步 npm 版本及 CHANGELOG,记录公网真实 API 验收仍待用户凭据。
2026-09-24 09:57:41 +08:00

44 lines
1.7 KiB
TypeScript

import { createConnection } from 'node:net';
import { readFile } from 'node:fs/promises';
/** Same-user 0600 Unix channel. Never print the connect response or persist its token. */
export async function subscriptionOperation(operation: 'connect' | 'status' | 'limits' | 'stop') {
const pointer = JSON.parse(
await readFile('build/lekiwi-agent/subscription-session.json', 'utf8'),
) as { socket?: string; status: string };
if (!pointer.socket || pointer.status === 'closed')
throw new Error('隔离订阅会话已关闭,请重新发起官方登录');
return new Promise<Record<string, unknown>>((resolve, reject) => {
const channel = createConnection(pointer.socket!);
let buffer = '';
channel.setTimeout(20000);
channel.once('connect', () => channel.write(JSON.stringify(operation) + '\n'));
channel.on('data', (chunk) => {
buffer += String(chunk);
if (buffer.length > 16384) {
channel.destroy();
reject(new Error('订阅管理响应过大'));
return;
}
if (buffer.includes('\n')) {
try {
const result = JSON.parse(buffer.split('\n')[0]) as Record<string, unknown>;
if (result.error) reject(new Error('订阅管理请求失败'));
else resolve(result);
} catch {
reject(new Error('订阅管理响应非法'));
}
channel.end();
}
});
channel.once('timeout', () => {
channel.destroy();
reject(new Error('订阅管理请求超时'));
});
channel.once('error', () => reject(new Error('无法连接隔离订阅会话')));
channel.once('end', () => {
if (!buffer.includes('\n')) reject(new Error('订阅管理连接提前关闭'));
});
});
}