@skylandnpm/octopus-proxy 0.1.54 → 0.1.57

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.
@@ -8830,6 +8830,33 @@ var SecureChat = class {
8830
8830
  import { randomUUID as randomUUID8 } from "node:crypto";
8831
8831
  import { execFile as execFile3 } from "node:child_process";
8832
8832
  import { promisify as promisify3 } from "node:util";
8833
+
8834
+ // src/reasoning.ts
8835
+ function reasoningLevels(value) {
8836
+ if (!Array.isArray(value)) return [];
8837
+ return [...new Set(value.flatMap((entry) => {
8838
+ const level = typeof entry === "string" ? entry : entry && typeof entry === "object" ? entry.value ?? entry.reasoningEffort ?? entry.id : void 0;
8839
+ return typeof level === "string" && level.trim() ? [level.trim()] : [];
8840
+ }))];
8841
+ }
8842
+ function defaultReasoningLevel(levels) {
8843
+ if (levels.includes("medium")) return "medium";
8844
+ const order = ["none", "off", "nothink", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"];
8845
+ const active = levels.filter((level) => !["none", "off", "nothink"].includes(level));
8846
+ const choices = (active.length ? active : levels).slice().sort((a, b) => {
8847
+ const left = order.indexOf(a), right = order.indexOf(b);
8848
+ return left < 0 || right < 0 ? 0 : left - right;
8849
+ });
8850
+ return choices[Math.floor((choices.length - 1) / 2)];
8851
+ }
8852
+ function selectedReasoningLevel(payload, parameter) {
8853
+ if (typeof payload.reasoningLevel !== "string" || !payload.reasoningLevel) return void 0;
8854
+ if (payload.reasoningParameter !== void 0 && payload.reasoningParameter !== parameter)
8855
+ throw new Error(`Reasoning parameter must be ${parameter} for this tool; refresh the model configuration`);
8856
+ return payload.reasoningLevel;
8857
+ }
8858
+
8859
+ // src/proxy-snapshot.ts
8833
8860
  var execute2 = promisify3(execFile3);
8834
8861
  function record(value) {
8835
8862
  return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
@@ -8844,7 +8871,8 @@ function publicModels(value) {
8844
8871
  for (const modelValue of Object.values(record(provider.models))) {
8845
8872
  const model = record(modelValue);
8846
8873
  if (typeof model.id !== "string") continue;
8847
- result.push({ id: `${provider.id}/${model.id}`, name: typeof model.name === "string" ? model.name : model.id, isDefault: model.isDefault === true });
8874
+ const levels = reasoningLevels(model.reasoningLevels);
8875
+ result.push({ id: `${provider.id}/${model.id}`, name: typeof model.name === "string" ? model.name : model.id, isDefault: model.isDefault === true, ...Array.isArray(model.reasoningLevels) ? { reasoningLevels: levels } : {}, ...typeof model.reasoningParameter === "string" ? { reasoningParameter: model.reasoningParameter } : {} });
8848
8876
  if (result.length >= 500) return result;
8849
8877
  }
8850
8878
  }
@@ -10764,6 +10792,8 @@ var OpenCodeAdapter = class {
10764
10792
  const input = payload.model;
10765
10793
  model = { providerID: input.providerID, id: input.modelID ?? input.id, ...input.variant ? { variant: input.variant } : {} };
10766
10794
  } else throw new Error("Invalid model identifier");
10795
+ const level = selectedReasoningLevel(payload, "model.variant");
10796
+ if (level) model.variant = level;
10767
10797
  await this.data(project, "POST", `${base}/model`, { model });
10768
10798
  }
10769
10799
  async models(project) {
@@ -10777,7 +10807,7 @@ var OpenCodeAdapter = class {
10777
10807
  const modelId = model.id ?? model.modelID;
10778
10808
  if (typeof model.providerID !== "string" || typeof modelId !== "string") continue;
10779
10809
  const provider = providers.get(model.providerID) ?? { id: model.providerID, models: {} };
10780
- provider.models[modelId] = { ...model, id: modelId, isDefault: configured ? configured === `${model.providerID}/${modelId}` : model.isDefault === true };
10810
+ provider.models[modelId] = { ...model, id: modelId, reasoningParameter: "model.variant", reasoningLevels: reasoningLevels(model.variants), isDefault: configured ? configured === `${model.providerID}/${modelId}` : model.isDefault === true };
10781
10811
  providers.set(model.providerID, provider);
10782
10812
  }
10783
10813
  return redact({ providers: [...providers.values()] });
@@ -12103,7 +12133,7 @@ var CodexAdapter = class {
12103
12133
  const config = await rpc.request("config/read", { cwd: await this.workspace.root(project), includeLayers: false }).catch(() => void 0);
12104
12134
  const configured = typeof config?.config?.model === "string" ? config.config.model.trim() : void 0;
12105
12135
  if (configured && !models.some((entry) => (entry.model ?? entry.id) === configured)) models.push({ id: configured, model: configured, displayName: configured });
12106
- return { providers: [{ id: "codex", models: Object.fromEntries(models.map((entry) => [entry.model ?? entry.id, { id: entry.model ?? entry.id, name: entry.displayName ?? entry.id, isDefault: configured ? (entry.model ?? entry.id) === configured : entry.isDefault === true }])) }] };
12136
+ return { providers: [{ id: "codex", models: Object.fromEntries(models.map((entry) => [entry.model ?? entry.id, { id: entry.model ?? entry.id, name: entry.displayName ?? entry.id, ...entry.supportedReasoningEfforts ? { reasoningParameter: "effort", reasoningLevels: reasoningLevels(entry.supportedReasoningEfforts) } : {}, isDefault: configured ? (entry.model ?? entry.id) === configured : entry.isDefault === true }])) }] };
12107
12137
  }
12108
12138
  if (op === "sessions.list") {
12109
12139
  const index = await this.index(project);
@@ -12164,7 +12194,8 @@ var CodexAdapter = class {
12164
12194
  if (!input.length) throw new Error("Message or attachments required");
12165
12195
  const selectedModel = p.model;
12166
12196
  const model = selectedModel?.providerID === "codex" && typeof selectedModel.modelID === "string" ? selectedModel.modelID : void 0;
12167
- const result = await rpc.request("turn/start", { threadId: id, input, ...model ? { model } : {} });
12197
+ const effort = selectedReasoningLevel(p, "effort");
12198
+ const result = await rpc.request("turn/start", { threadId: id, input, ...model ? { model } : {}, ...effort ? { effort } : {} });
12168
12199
  this.activeTurns.set(id, result.turn.id);
12169
12200
  return result;
12170
12201
  }
@@ -12411,7 +12442,7 @@ var ZcodeAdapter = class {
12411
12442
  const providers = /* @__PURE__ */ new Map();
12412
12443
  for (const entry of model.available) {
12413
12444
  const provider = providers.get(entry.ref.providerId) ?? { id: entry.ref.providerId, name: entry.providerLabel, models: /* @__PURE__ */ Object.create(null) };
12414
- provider.models[entry.ref.modelId] = { id: entry.ref.modelId, name: entry.label, isDefault: entry.ref.providerId === model.current?.providerId && entry.ref.modelId === model.current?.modelId };
12445
+ provider.models[entry.ref.modelId] = { id: entry.ref.modelId, name: entry.label, reasoningParameter: "model.options.reasoningLevel", reasoningLevels: reasoningLevels(entry.reasoning?.levels), isDefault: entry.ref.providerId === model.current?.providerId && entry.ref.modelId === model.current?.modelId };
12415
12446
  providers.set(provider.id, provider);
12416
12447
  }
12417
12448
  return { providers: [...providers.values()] };
@@ -12487,7 +12518,18 @@ var ZcodeAdapter = class {
12487
12518
  }
12488
12519
  if (!lines.length) throw new Error("Message or attachments required");
12489
12520
  const selected = p.model;
12490
- if (selected?.providerID && selected.modelID) await rpc.request("session/setModel", { sessionId: id, model: { providerId: selected.providerID, modelId: selected.modelID } });
12521
+ if (selected?.providerID && selected.modelID) {
12522
+ let level = selectedReasoningLevel(p, "model.options.reasoningLevel");
12523
+ if (!level) {
12524
+ const snapshot = await rpc.request("session/read", { sessionId: id });
12525
+ const entry = snapshot.settings?.model.available.find((entry2) => entry2.ref.providerId === selected.providerID && entry2.ref.modelId === selected.modelID);
12526
+ level = defaultReasoningLevel(reasoningLevels(entry?.reasoning?.levels));
12527
+ }
12528
+ await rpc.request("session/setModel", { sessionId: id, model: { providerId: selected.providerID, modelId: selected.modelID, ...level ? { options: { reasoningLevel: level } } : {} } });
12529
+ } else if (typeof p.reasoningLevel === "string" && p.reasoningLevel) {
12530
+ const level = selectedReasoningLevel(p, "thoughtLevel");
12531
+ await rpc.request("session/setThoughtLevel", { sessionId: id, thoughtLevel: level });
12532
+ }
12491
12533
  return await rpc.request("session/send", { sessionId: id, content: lines.join("\n") });
12492
12534
  }
12493
12535
  if (op === "sessions.abort") {
@@ -12749,7 +12791,8 @@ var PiAdapter = class {
12749
12791
  const providers = /* @__PURE__ */ new Map();
12750
12792
  for (const model of models) {
12751
12793
  const provider = providers.get(model.provider) ?? { id: model.provider, models: /* @__PURE__ */ Object.create(null) };
12752
- provider.models[model.id] = { id: model.id, name: model.name ?? model.id, isDefault: state?.model?.provider === model.provider && state.model.id === model.id };
12794
+ const levels = model.reasoning ? ["off", "minimal", "low", "medium", "high", ...["xhigh", "max"].filter((level) => model.thinkingLevelMap?.[level] != null)].filter((level) => model.thinkingLevelMap?.[level] !== null) : [];
12795
+ provider.models[model.id] = { id: model.id, name: model.name ?? model.id, reasoningParameter: "level", reasoningLevels: reasoningLevels(levels), isDefault: state?.model?.provider === model.provider && state.model.id === model.id };
12753
12796
  providers.set(model.provider, provider);
12754
12797
  }
12755
12798
  return { providers: [...providers.values()] };
@@ -12850,7 +12893,9 @@ var PiAdapter = class {
12850
12893
  }
12851
12894
  if (!lines.length && !images.length) throw new Error("Message or attachments required");
12852
12895
  const model = p.model;
12896
+ const level = selectedReasoningLevel(p, "level");
12853
12897
  if (model && typeof model.providerID === "string" && typeof model.modelID === "string") await rpc.request("set_model", { provider: model.providerID, modelId: model.modelID });
12898
+ if (level) await rpc.request("set_thinking_level", { level });
12854
12899
  const result = await rpc.request("prompt", { message: lines.join("\n"), ...images.length ? { images } : {} });
12855
12900
  session.time.updated = Date.now();
12856
12901
  if (session.title === "\u65B0\u4EFB\u52A1" && typeof p.text === "string" && p.text.trim()) session.title = p.text.trim().slice(0, 100);
package/dist/cli.js CHANGED
@@ -34,7 +34,7 @@ import {
34
34
  supportedPlatform,
35
35
  systemdUnitPath,
36
36
  toolSearchDirs
37
- } from "./chunk-NJNANA6A.js";
37
+ } from "./chunk-YFY544PH.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-NJNANA6A.js";
5
+ } from "./chunk-YFY544PH.js";
6
6
  import "./chunk-XIJKEY4L.js";
7
7
 
8
8
  // src/main.ts
@@ -138,8 +138,16 @@ int main(int argc, const char *argv[]) {
138
138
  if (!display) { dispatch_async(dispatch_get_main_queue(), ^{ fail(@"所选显示器已断开,请刷新显示器列表后重试。" ); }); return; }
139
139
  SCContentFilter *filter = [[SCContentFilter alloc] initWithDisplay:display excludingWindows:@[]];
140
140
  SCStreamConfiguration *configuration = [SCStreamConfiguration new];
141
- configuration.width = CGDisplayPixelsWide(display.displayID);
142
- configuration.height = CGDisplayPixelsHigh(display.displayID);
141
+ if (@available(macOS 14.0, *)) {
142
+ configuration.width = CGDisplayPixelsWide(display.displayID);
143
+ configuration.height = CGDisplayPixelsHigh(display.displayID);
144
+ } else {
145
+ // On macOS 13, re-entering Quartz display queries from the
146
+ // SCShareableContent callback can block indefinitely. The returned
147
+ // SCDisplay already contains the dimensions needed for capture.
148
+ configuration.width = display.width;
149
+ configuration.height = display.height;
150
+ }
143
151
  configuration.pixelFormat = kCVPixelFormatType_32BGRA;
144
152
  configuration.showsCursor = YES;
145
153
  configuration.queueDepth = 3;
@@ -271,6 +271,14 @@ int main(int argc,const char *argv[]) {
271
271
  emit(@{@"capture":@(CGPreflightScreenCaptureAccess()),@"input":@((BOOL)(AXIsProcessTrusted() && CGPreflightPostEventAccess())),@"session":@(sessionPresent()),@"locked":@(screenLocked()),@"lockCapture":@(lockCapture)}); return 0;
272
272
  }
273
273
  if(argc!=6 || strcmp(argv[1],"serve")!=0 || !inputOK() || !CGPreflightScreenCaptureAccess()) return 1;
274
+ if (@available(macOS 14.0, *)) {
275
+ // Keep the current display initialization on modern macOS.
276
+ } else {
277
+ // Initialize AppKit's display connection on the main thread first.
278
+ // Otherwise Quartz display queries can hang on macOS 13 before the
279
+ // capture stream is even created. This does not request permissions.
280
+ (void)NSScreen.screens;
281
+ }
274
282
  displayID=(CGDirectDisplayID)strtoul(argv[2],NULL,10);
275
283
  int w=atoi(argv[3]),h=atoi(argv[4]),fps=atoi(argv[5]);
276
284
  if(!CGDisplayIsOnline(displayID) || w<2 || h<2 || w>3840 || h>2160 || w%2 || h%2 || fps<1 || fps>30) return 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skylandnpm/octopus-proxy",
3
- "version": "0.1.54",
3
+ "version": "0.1.57",
4
4
  "type": "module",
5
5
  "description": "Octopus host proxy: OpenCode, Codex, ZCode and Pi adapters with service installer CLI",
6
6
  "bin": {