@skylandnpm/octopus-proxy 0.1.58 → 0.1.61

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