@skylandnpm/octopus-proxy 0.1.58 → 0.1.60
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/dist/{chunk-AOBRAQCJ.js → chunk-VW545PK2.js} +68 -7
- package/dist/cli.js +1 -1
- package/dist/main.js +1 -1
- package/package.json +1 -1
|
@@ -11270,6 +11270,37 @@ function zcodeEnvironment(command) {
|
|
|
11270
11270
|
return env;
|
|
11271
11271
|
}
|
|
11272
11272
|
|
|
11273
|
+
// src/tools/zcode-standalone.ts
|
|
11274
|
+
import { basename as basename4 } from "node:path";
|
|
11275
|
+
function standaloneZcodeSource(source) {
|
|
11276
|
+
const bootstrap = /\br\(([$\w]+),"runZCodeProtocolAgent"\)/.exec(source)?.[1];
|
|
11277
|
+
const registry = /\br\(([$\w]+),"startProcessProviderRegistryRuntime"\)/.exec(source)?.[1];
|
|
11278
|
+
if (!bootstrap || !registry) throw new Error("Unsupported ZCode bundle: native account bootstrap is unavailable");
|
|
11279
|
+
const start = source.indexOf(`async function ${bootstrap}(`);
|
|
11280
|
+
const end = source.indexOf(`r(${bootstrap},"runZCodeProtocolAgent")`, start);
|
|
11281
|
+
if (start < 0 || end < start) throw new Error("Unsupported ZCode protocol bootstrap");
|
|
11282
|
+
let body = source.slice(start, end);
|
|
11283
|
+
const escapedRegistry = registry.replace(/[$]/g, "\\$&");
|
|
11284
|
+
const registryCall = new RegExp(`\\b${escapedRegistry}\\(([$\\w]+)\\)`, "g");
|
|
11285
|
+
const nativePorts = /([$\w]+)\.runtime\.registryService,\1\.configuredDefaultModelSelection\),/g;
|
|
11286
|
+
if ([...body.matchAll(registryCall)].length !== 1 || [...body.matchAll(nativePorts)].length !== 1) {
|
|
11287
|
+
throw new Error("Unsupported ZCode account bootstrap; native compatibility check failed");
|
|
11288
|
+
}
|
|
11289
|
+
body = body.replace(registryCall, `${registry}($1,{standalone:{}})`).replace(nativePorts, "$&providerRuntimeHeadersPort:$1.providerRuntimeHeadersPort,");
|
|
11290
|
+
return source.slice(0, start) + body + source.slice(end);
|
|
11291
|
+
}
|
|
11292
|
+
function zcodeServerLaunch(command, args) {
|
|
11293
|
+
if (basename4(command) !== "zcode.cjs") return { command, args: [...args] };
|
|
11294
|
+
const shim = `const fs=require('node:fs'),Module=require('node:module'),path=require('node:path');
|
|
11295
|
+
const filename=process.argv[1];
|
|
11296
|
+
try {
|
|
11297
|
+
const source=(${standaloneZcodeSource.toString()})(fs.readFileSync(filename,'utf8'));
|
|
11298
|
+
const entry=new Module(filename);entry.filename=filename;entry.paths=Module._nodeModulePaths(path.dirname(filename));
|
|
11299
|
+
entry._compile(source,filename);
|
|
11300
|
+
} catch(error) { console.error(error.message);process.exitCode=1; }`;
|
|
11301
|
+
return { command: process.execPath, args: ["-e", shim, command, ...args] };
|
|
11302
|
+
}
|
|
11303
|
+
|
|
11273
11304
|
// src/tools/stdio-runtime.ts
|
|
11274
11305
|
import { spawn as spawn3, execFile as execFile4 } from "node:child_process";
|
|
11275
11306
|
import { promisify as promisify4 } from "node:util";
|
|
@@ -11642,8 +11673,9 @@ ${bytes.toString("utf8")}`);
|
|
|
11642
11673
|
await mkdir7(this.config.stateDirectory, { recursive: true, mode: 448 });
|
|
11643
11674
|
const log = await open6(logPath, "a", 384);
|
|
11644
11675
|
let child;
|
|
11676
|
+
const launch = this.kind === "zcode" ? zcodeServerLaunch(this.config.tool.command, this.descriptor.serverArgs) : { command: this.config.tool.command, args: [...this.descriptor.serverArgs] };
|
|
11645
11677
|
try {
|
|
11646
|
-
child = spawn3(
|
|
11678
|
+
child = spawn3(launch.command, launch.args, { cwd: directory, env: this.kind === "zcode" ? zcodeEnvironment(this.config.tool.command) : { ...process.env }, stdio: ["pipe", "pipe", log.fd] });
|
|
11647
11679
|
} catch (error) {
|
|
11648
11680
|
await log.close();
|
|
11649
11681
|
throw error;
|
|
@@ -12297,6 +12329,7 @@ var ZcodeAdapter = class {
|
|
|
12297
12329
|
permissions = /* @__PURE__ */ new Map();
|
|
12298
12330
|
inputs = /* @__PURE__ */ new Map();
|
|
12299
12331
|
subscribed = /* @__PURE__ */ new Set();
|
|
12332
|
+
resuming = /* @__PURE__ */ new Map();
|
|
12300
12333
|
supportedOperations() {
|
|
12301
12334
|
return OPERATIONS2;
|
|
12302
12335
|
}
|
|
@@ -12381,6 +12414,13 @@ var ZcodeAdapter = class {
|
|
|
12381
12414
|
const turns = /* @__PURE__ */ new Map();
|
|
12382
12415
|
let current;
|
|
12383
12416
|
for (const row of rows) {
|
|
12417
|
+
if (row.info && ["user", "assistant"].includes(String(row.info.role)) && Array.isArray(row.parts)) {
|
|
12418
|
+
const semantics = row.info.semantics;
|
|
12419
|
+
if (semantics?.uiVisibility === "hidden" || semantics?.uiVisibility !== "visible" && row.info.visibility === "model-only") continue;
|
|
12420
|
+
messages.push({ info: { ...row.info }, parts: row.parts });
|
|
12421
|
+
current = void 0;
|
|
12422
|
+
continue;
|
|
12423
|
+
}
|
|
12384
12424
|
const data = row.data ?? row;
|
|
12385
12425
|
if (data.kind === "turnHeader") {
|
|
12386
12426
|
turns.set(String(row.turnId ?? data.turnId ?? ""), data);
|
|
@@ -12409,7 +12449,27 @@ var ZcodeAdapter = class {
|
|
|
12409
12449
|
async session(project, id) {
|
|
12410
12450
|
if (!describeTool("zcode").sessionPattern.test(id)) throw new Error("Invalid session id");
|
|
12411
12451
|
const rpc = await this.rpc(project);
|
|
12412
|
-
|
|
12452
|
+
let result;
|
|
12453
|
+
try {
|
|
12454
|
+
result = await rpc.request("session/read", { sessionId: id });
|
|
12455
|
+
} catch (error) {
|
|
12456
|
+
if (!(error instanceof Error) || !/^Session is not active:/i.test(error.message)) throw error;
|
|
12457
|
+
const key = `${project}\0${id}`;
|
|
12458
|
+
let pending = this.resuming.get(key);
|
|
12459
|
+
if (!pending) {
|
|
12460
|
+
pending = (async () => {
|
|
12461
|
+
const list = await rpc.request("session/list", { workspace: await this.workspaceRef(project), sessionIds: [id] });
|
|
12462
|
+
if (!list.sessions?.some((session) => session.sessionId === id)) throw new Error("Session not found in this project");
|
|
12463
|
+
return rpc.request("session/resume", { sessionId: id });
|
|
12464
|
+
})();
|
|
12465
|
+
this.resuming.set(key, pending);
|
|
12466
|
+
}
|
|
12467
|
+
try {
|
|
12468
|
+
result = await pending;
|
|
12469
|
+
} finally {
|
|
12470
|
+
if (this.resuming.get(key) === pending) this.resuming.delete(key);
|
|
12471
|
+
}
|
|
12472
|
+
}
|
|
12413
12473
|
const sessionInfo = result.session;
|
|
12414
12474
|
if (!sessionInfo) throw new Error("Session not found");
|
|
12415
12475
|
const directory = sessionInfo.workspace?.workspacePath;
|
|
@@ -12438,7 +12498,7 @@ var ZcodeAdapter = class {
|
|
|
12438
12498
|
const snapshot = await rpc.request("session/create", { workspace: await this.workspaceRef(project), persistence: "deferred", titleGenerationEnabled: false, toolAllowlist: [] });
|
|
12439
12499
|
try {
|
|
12440
12500
|
const model = snapshot.settings.model;
|
|
12441
|
-
if (op === "auth.status") return { status: model.available.length ? "authenticated" : "unauthenticated", message: model.available.length ? "ZCode \u5DF2\u914D\u7F6E\u53EF\u7528\u6A21\u578B\uFF08\u51ED\u636E\u6709\u6548\u6027\u7531\u5DE5\u5177\u5728\u8C03\u7528\u65F6\u68C0\u67E5\uFF09" : "ZCode \u672A\u914D\u7F6E\u53EF\u7528\u6A21\u578B", methods: [{ id: "zai", label: "Z.AI \u6D4F\u89C8\u5668\u767B\u5F55" }] };
|
|
12501
|
+
if (op === "auth.status") return { status: model.available.length ? "authenticated" : "unauthenticated", message: model.available.length ? "ZCode \u5DF2\u914D\u7F6E\u53EF\u7528\u6A21\u578B\uFF08\u51ED\u636E\u6709\u6548\u6027\u7531\u5DE5\u5177\u5728\u8C03\u7528\u65F6\u68C0\u67E5\uFF09" : "ZCode \u672A\u914D\u7F6E\u53EF\u7528\u6A21\u578B", methods: [{ id: "zai", label: "Z.AI \u6D4F\u89C8\u5668\u767B\u5F55" }, { id: "bigmodel", label: "\u667A\u8C31 BigModel \u6D4F\u89C8\u5668\u767B\u5F55" }] };
|
|
12442
12502
|
const providers = /* @__PURE__ */ new Map();
|
|
12443
12503
|
for (const entry of model.available) {
|
|
12444
12504
|
const provider = providers.get(entry.ref.providerId) ?? { id: entry.ref.providerId, name: entry.providerLabel, models: /* @__PURE__ */ Object.create(null) };
|
|
@@ -12451,20 +12511,21 @@ var ZcodeAdapter = class {
|
|
|
12451
12511
|
}
|
|
12452
12512
|
}
|
|
12453
12513
|
if (op === "auth.login") {
|
|
12454
|
-
if (p.method !== "zai") throw new Error("\u4E0D\u652F\u6301\u7684 ZCode \u767B\u5F55\u65B9\u5F0F");
|
|
12514
|
+
if (p.method !== "zai" && p.method !== "bigmodel") throw new Error("\u4E0D\u652F\u6301\u7684 ZCode \u767B\u5F55\u65B9\u5F0F");
|
|
12515
|
+
const provider = p.method;
|
|
12455
12516
|
let child;
|
|
12456
12517
|
const flow = this.auth.create(project, () => {
|
|
12457
12518
|
child?.kill("SIGTERM");
|
|
12458
12519
|
});
|
|
12459
|
-
child = spawn4(this.runtime.config.tool.command, ["login", "--no-browser", "--json"], { cwd: await this.workspace.root(project), env: zcodeEnvironment(this.runtime.config.tool.command), stdio: ["ignore", "pipe", "pipe"] });
|
|
12520
|
+
child = spawn4(this.runtime.config.tool.command, ["login", provider, "--no-browser", "--json"], { cwd: await this.workspace.root(project), env: zcodeEnvironment(this.runtime.config.tool.command), stdio: ["ignore", "pipe", "pipe"] });
|
|
12460
12521
|
let output = "", diagnostic = "";
|
|
12461
12522
|
child.stdout?.on("data", (data) => {
|
|
12462
12523
|
output = (output + data.toString()).slice(-65536);
|
|
12463
12524
|
});
|
|
12464
12525
|
child.stderr?.on("data", (data) => {
|
|
12465
12526
|
diagnostic = (diagnostic + data.toString()).slice(-8192);
|
|
12466
|
-
const match = /Open this URL to sign in:\s*(https?:\/\/[^\s]+)/.exec(diagnostic);
|
|
12467
|
-
if (match) this.auth.update(project, flow.flowId, { url: match[1], message:
|
|
12527
|
+
const match = /(?:Open this URL to sign in|Fallback URL):\s*(https?:\/\/[^\s]+)/.exec(diagnostic);
|
|
12528
|
+
if (match) this.auth.update(project, flow.flowId, { url: match[1], message: `\u5728\u6D4F\u89C8\u5668\u5B8C\u6210 ${provider === "bigmodel" ? "\u667A\u8C31 BigModel" : "Z.AI"} \u6388\u6743\uFF0CZCode \u5C06\u81EA\u884C\u4FDD\u5B58\u8BA4\u8BC1\u4FE1\u606F` });
|
|
12468
12529
|
});
|
|
12469
12530
|
child.once("error", () => this.auth.update(project, flow.flowId, { status: "failed", message: "\u65E0\u6CD5\u542F\u52A8 ZCode \u539F\u751F\u767B\u5F55" }));
|
|
12470
12531
|
child.once("exit", (code) => {
|
package/dist/cli.js
CHANGED
package/dist/main.js
CHANGED