@ngosangns/ns-bridge 0.1.29 → 0.1.31

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.
@@ -1,4 +1,4 @@
1
- // @ngosangns/ns-bridge 0.1.29 — prebuilt host bundle.
1
+ // @ngosangns/ns-bridge 0.1.31 — prebuilt host bundle.
2
2
  import { createRequire as __nsBridgeCreateRequire } from 'node:module';
3
3
  const require = __nsBridgeCreateRequire(import.meta.url);
4
4
  var __defProp = Object.defineProperty;
@@ -13945,6 +13945,7 @@ function loadExports() {
13945
13945
  "model_cache_decrypt",
13946
13946
  "qodercontext_new",
13947
13947
  "qodercontext_prepareInferRequest",
13948
+ "qodercontext_prepareRequest",
13948
13949
  "requestresult_url",
13949
13950
  "requestresult_body",
13950
13951
  "requestresult_headers",
@@ -14094,6 +14095,41 @@ function signQoderInferRequest(endpoint, bodyJson, modelKey, modelSource, identi
14094
14095
  exports.__wbg_qodercontext_free(ctx, 0);
14095
14096
  }
14096
14097
  }
14098
+ function callPrepareRequest(exports, ctx, endpoint, path, method, authType, body) {
14099
+ const retptr = exports.__wbindgen_add_to_stack_pointer(-16);
14100
+ try {
14101
+ const [endpointPtr, endpointLen] = passStringToWasm(exports, endpoint);
14102
+ const [pathPtr, pathLen] = passStringToWasm(exports, path);
14103
+ const [methodPtr, methodLen] = passStringToWasm(exports, method);
14104
+ const [authPtr, authLen] = passStringToWasm(exports, authType);
14105
+ const [bodyPtr, bodyLen] = body === void 0 ? [0, 0] : passStringToWasm(exports, body);
14106
+ exports.qodercontext_prepareRequest(retptr, ctx, endpointPtr, endpointLen, pathPtr, pathLen, methodPtr, methodLen, authPtr, authLen, bodyPtr, bodyLen, 0, 0);
14107
+ const view = new Int32Array(exports.memory.buffer, retptr, 4);
14108
+ if ((view[2] ?? 0) !== 0)
14109
+ throw takeObject(view[1] ?? 0);
14110
+ return (view[0] ?? 0) >>> 0;
14111
+ } finally {
14112
+ exports.__wbindgen_add_to_stack_pointer(16);
14113
+ }
14114
+ }
14115
+ function signQoderRequest(endpoint, path, method, authType, body, identity, cosyVersion) {
14116
+ const exports = loadExports();
14117
+ const ctx = callContextNew(exports, identity, cosyVersion);
14118
+ try {
14119
+ const result = callPrepareRequest(exports, ctx, endpoint, path, method, authType, body);
14120
+ try {
14121
+ const url = wasmResultString(exports, exports.requestresult_url, result);
14122
+ if (!url)
14123
+ throw new Error("qoder request signer returned an empty url");
14124
+ const signedBody = wasmResultString(exports, exports.requestresult_body, result);
14125
+ return { url, headers: signatureHeaders(exports, result), body: signedBody ?? "" };
14126
+ } finally {
14127
+ exports.__wbg_requestresult_free(result, 0);
14128
+ }
14129
+ } finally {
14130
+ exports.__wbg_qodercontext_free(ctx, 0);
14131
+ }
14132
+ }
14097
14133
  function storedString(record, field) {
14098
14134
  const value = record[field];
14099
14135
  return typeof value === "string" && value.length > 0 ? value : void 0;
@@ -14326,71 +14362,9 @@ function qoderModelInfosFromVendorCatalog(raw, scene) {
14326
14362
  // ../qoder-core/dist/models-api.js
14327
14363
  import { readdirSync as readdirSync3, readFileSync as readFileSync11, statSync as statSync3 } from "node:fs";
14328
14364
  import { join as join17 } from "node:path";
14329
- function newestCatalogDirectory(root) {
14330
- try {
14331
- const dirs = readdirSync3(root, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => join17(root, entry.name)).flatMap((dir) => {
14332
- try {
14333
- return [{ dir, mtime: statSync3(dir).mtimeMs }];
14334
- } catch {
14335
- return [];
14336
- }
14337
- });
14338
- dirs.sort((a, b) => b.mtime - a.mtime);
14339
- for (const { dir } of dirs) {
14340
- const file = newestCatalog(dir);
14341
- if (file)
14342
- return { dir, file };
14343
- }
14344
- return void 0;
14345
- } catch {
14346
- return void 0;
14347
- }
14348
- }
14349
- function newestCatalog(dir) {
14350
- try {
14351
- const files = readdirSync3(dir).flatMap((name) => {
14352
- const match = /^catalog-v(\d+)$/.exec(name);
14353
- return match ? [{ file: join17(dir, name), version: Number(match[1]) }] : [];
14354
- }).sort((a, b) => b.version - a.version);
14355
- return files[0]?.file;
14356
- } catch {
14357
- return void 0;
14358
- }
14359
- }
14360
- function qoderVendorCatalogFile(configDir) {
14361
- const root = join17(configDir, ".models");
14362
- let uid;
14363
- let scene;
14364
- try {
14365
- const pointer = JSON.parse(readFileSync11(join17(root, "default"), "utf8"));
14366
- if (typeof pointer.uid === "string" && pointer.uid)
14367
- uid = pointer.uid;
14368
- if (typeof pointer.scene === "string" && pointer.scene)
14369
- scene = pointer.scene;
14370
- } catch {
14371
- }
14372
- let dir = uid ? join17(root, uid) : void 0;
14373
- let file = dir ? newestCatalog(dir) : void 0;
14374
- if (!file) {
14375
- const found = newestCatalogDirectory(root);
14376
- dir = found?.dir;
14377
- file = found?.file;
14378
- }
14379
- if (!dir || !file)
14380
- return void 0;
14381
- return { file, uid: dir.slice(root.length + 1), ...scene ? { scene } : {} };
14382
- }
14383
- async function fetchQoderModels(_options = {}) {
14384
- try {
14385
- const target = qoderVendorCatalogFile(qoderConfigDir());
14386
- if (!target)
14387
- return qoderBootstrapModels();
14388
- const plain = decryptQoderModelCache(readFileSync11(target.file, "utf8"), target.uid);
14389
- return qoderModelsFromModelInfos(qoderModelInfosFromVendorCatalog(plain, target.scene));
14390
- } catch {
14391
- return qoderBootstrapModels();
14392
- }
14393
- }
14365
+
14366
+ // ../qoder-core/dist/stream.js
14367
+ import { randomUUID as randomUUID2 } from "node:crypto";
14394
14368
 
14395
14369
  // ../qoder-core/dist/prompt.js
14396
14370
  function imageDataUrl(data, mimeType) {
@@ -14463,15 +14437,16 @@ function nonNegative3(value) {
14463
14437
  return value;
14464
14438
  }
14465
14439
  function toQoderUsage(wire) {
14466
- const input = nonNegative3(wire.prompt_tokens);
14440
+ const prompt = nonNegative3(wire.prompt_tokens);
14467
14441
  const output = nonNegative3(wire.completion_tokens);
14468
14442
  const hit = nonNegative3(wire.prompt_cache_hit_tokens);
14469
14443
  const cached2 = nonNegative3(wire.prompt_tokens_details?.cached_tokens);
14470
- const cacheRead = hit > 0 ? hit : cached2;
14444
+ const cacheRead = Math.min(hit > 0 ? hit : cached2, prompt);
14445
+ const input = prompt - cacheRead;
14471
14446
  return {
14472
14447
  input,
14473
14448
  output,
14474
- totalTokens: input + output,
14449
+ totalTokens: input + cacheRead + output,
14475
14450
  ...cacheRead > 0 ? { cacheRead } : {},
14476
14451
  cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
14477
14452
  };
@@ -14673,7 +14648,6 @@ function qoderSessionId(raw) {
14673
14648
  }
14674
14649
 
14675
14650
  // ../qoder-core/dist/stream.js
14676
- import { randomUUID as randomUUID2 } from "node:crypto";
14677
14651
  var QODER_WIRE_VERSION = "1.1.83";
14678
14652
  var QODER_INFER_ORIGIN = "https://api2.qoder.sh";
14679
14653
  var ANONYMOUS_SIGNING_IDENTITY = {
@@ -14715,6 +14689,40 @@ function machineOs() {
14715
14689
  const arch = process.arch === "arm64" ? "aarch64" : process.arch;
14716
14690
  return `${arch}_${process.platform}`;
14717
14691
  }
14692
+ function estimateQoderBodyBytes(payload) {
14693
+ try {
14694
+ return Buffer.byteLength(JSON.stringify(payload));
14695
+ } catch {
14696
+ return Number.MAX_SAFE_INTEGER;
14697
+ }
14698
+ }
14699
+ function fitQoderBody(payload) {
14700
+ const messages = payload.messages;
14701
+ if (!Array.isArray(messages) || messages.length <= 1)
14702
+ return payload;
14703
+ if (estimateQoderBodyBytes(payload) <= QODER_WIRE_BODY_LIMIT_BYTES)
14704
+ return payload;
14705
+ const kept = messages.slice();
14706
+ while (kept.length > 1 && estimateQoderBodyBytes({ ...payload, messages: kept }) > QODER_WIRE_BODY_LIMIT_BYTES) {
14707
+ const dropped = kept[0];
14708
+ kept.shift();
14709
+ if (dropped?.role === "assistant" && Array.isArray(dropped.tool_calls) && dropped.tool_calls.length > 0) {
14710
+ const toolCallIds = new Set(dropped.tool_calls.map((tc) => tc && typeof tc === "object" && "id" in tc ? tc.id : void 0).filter((id) => typeof id === "string"));
14711
+ while (kept.length > 1) {
14712
+ const next = kept[0];
14713
+ if (next?.role === "tool" && typeof next.tool_call_id === "string" && toolCallIds.has(next.tool_call_id)) {
14714
+ kept.shift();
14715
+ toolCallIds.delete(next.tool_call_id);
14716
+ if (toolCallIds.size === 0)
14717
+ break;
14718
+ } else {
14719
+ break;
14720
+ }
14721
+ }
14722
+ }
14723
+ }
14724
+ return { ...payload, messages: kept };
14725
+ }
14718
14726
  function toWireTool(tool) {
14719
14727
  return {
14720
14728
  type: "function",
@@ -14944,7 +14952,8 @@ async function* streamQoderResponse(options) {
14944
14952
  if (payload.messages.length === 0)
14945
14953
  throw new QoderApiError("Qoder prompt is empty");
14946
14954
  const fetchImpl = options.fetchImpl ?? fetch;
14947
- const body = JSON.stringify(payload);
14955
+ const fittedPayload = fitQoderBody(payload);
14956
+ const body = JSON.stringify(fittedPayload);
14948
14957
  const bodyBytes = Buffer.byteLength(body);
14949
14958
  if (bodyBytes > QODER_WIRE_BODY_LIMIT_BYTES) {
14950
14959
  throw new QoderApiError(`Qoder prompt is too long for this model's context window (${bodyBytes} bytes > ${QODER_WIRE_BODY_LIMIT_BYTES} bytes)`);
@@ -15001,6 +15010,110 @@ function streamQoder(options) {
15001
15010
  });
15002
15011
  }
15003
15012
 
15013
+ // ../qoder-core/dist/models-api.js
15014
+ var QODER_MODEL_LIST_PATH = "/algo/api/v2/model/list?Encode=1";
15015
+ function newestCatalogDirectory(root) {
15016
+ try {
15017
+ const dirs = readdirSync3(root, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => join17(root, entry.name)).flatMap((dir) => {
15018
+ try {
15019
+ return [{ dir, mtime: statSync3(dir).mtimeMs }];
15020
+ } catch {
15021
+ return [];
15022
+ }
15023
+ });
15024
+ dirs.sort((a, b) => b.mtime - a.mtime);
15025
+ for (const { dir } of dirs) {
15026
+ const file = newestCatalog(dir);
15027
+ if (file)
15028
+ return { dir, file };
15029
+ }
15030
+ return void 0;
15031
+ } catch {
15032
+ return void 0;
15033
+ }
15034
+ }
15035
+ function newestCatalog(dir) {
15036
+ try {
15037
+ const files = readdirSync3(dir).flatMap((name) => {
15038
+ const match = /^catalog-v(\d+)$/.exec(name);
15039
+ return match ? [{ file: join17(dir, name), version: Number(match[1]) }] : [];
15040
+ }).sort((a, b) => b.version - a.version);
15041
+ return files[0]?.file;
15042
+ } catch {
15043
+ return void 0;
15044
+ }
15045
+ }
15046
+ function qoderVendorCatalogFile(configDir) {
15047
+ const root = join17(configDir, ".models");
15048
+ let uid;
15049
+ let scene;
15050
+ try {
15051
+ const pointer = JSON.parse(readFileSync11(join17(root, "default"), "utf8"));
15052
+ if (typeof pointer.uid === "string" && pointer.uid)
15053
+ uid = pointer.uid;
15054
+ if (typeof pointer.scene === "string" && pointer.scene)
15055
+ scene = pointer.scene;
15056
+ } catch {
15057
+ }
15058
+ let dir = uid ? join17(root, uid) : void 0;
15059
+ let file = dir ? newestCatalog(dir) : void 0;
15060
+ if (!file) {
15061
+ const found = newestCatalogDirectory(root);
15062
+ dir = found?.dir;
15063
+ file = found?.file;
15064
+ }
15065
+ if (!dir || !file)
15066
+ return void 0;
15067
+ return { file, uid: dir.slice(root.length + 1), ...scene ? { scene } : {} };
15068
+ }
15069
+ var MODEL_LIST_TIMEOUT_MS = 1e4;
15070
+ async function fetchServerModels(signal) {
15071
+ const identity = readQoderSigningIdentity(qoderConfigDir());
15072
+ if (!identity)
15073
+ throw new QoderAuthError();
15074
+ const signed = signQoderRequest(qoderWireUrl(process.env.QODER_MODEL_SERVER_HOST), QODER_MODEL_LIST_PATH, "GET", "auth", void 0, identity, QODER_WIRE_VERSION);
15075
+ const timeout = AbortSignal.timeout(MODEL_LIST_TIMEOUT_MS);
15076
+ const response = await fetch(signed.url, {
15077
+ method: "GET",
15078
+ headers: signed.headers,
15079
+ signal: signal ? AbortSignal.any([signal, timeout]) : timeout
15080
+ });
15081
+ const text = await response.text();
15082
+ if (response.status === 401 || response.status === 403) {
15083
+ throw new QoderAuthError(`${QODER_LOGIN_MESSAGE} (HTTP ${response.status}: ${text.slice(0, 200)})`);
15084
+ }
15085
+ if (!response.ok)
15086
+ throw new QoderApiError(`models.list failed: HTTP ${response.status}: ${text.slice(0, 200)}`);
15087
+ const infos = qoderModelInfosFromVendorCatalog(text);
15088
+ if (infos.length === 0)
15089
+ throw new QoderApiError("models.list returned no models for the assistant scene");
15090
+ return qoderModelsFromModelInfos(infos);
15091
+ }
15092
+ function readLocalCatalog() {
15093
+ const target = qoderVendorCatalogFile(qoderConfigDir());
15094
+ if (!target)
15095
+ return void 0;
15096
+ const plain = decryptQoderModelCache(readFileSync11(target.file, "utf8"), target.uid);
15097
+ return qoderModelsFromModelInfos(qoderModelInfosFromVendorCatalog(plain, target.scene));
15098
+ }
15099
+ async function fetchQoderModels(options = {}) {
15100
+ let error2;
15101
+ try {
15102
+ return { models: await fetchServerModels(options.signal), source: "server" };
15103
+ } catch (err) {
15104
+ if (options.signal?.aborted)
15105
+ throw err;
15106
+ error2 = err instanceof Error ? err.message : String(err);
15107
+ }
15108
+ try {
15109
+ const models = readLocalCatalog();
15110
+ if (models)
15111
+ return { models, source: "catalog", error: error2 };
15112
+ } catch {
15113
+ }
15114
+ return { models: qoderBootstrapModels(), source: "bootstrap", error: error2 };
15115
+ }
15116
+
15004
15117
  // ../pi-provider/src/qoder/provider.ts
15005
15118
  import {
15006
15119
  createAssistantMessageEventStream as createAssistantMessageEventStream8
@@ -15126,7 +15239,16 @@ async function refreshQoderModels(options = {}) {
15126
15239
  error: "no Qoder auth: run `qodercli login` or set QODER_PERSONAL_ACCESS_TOKEN"
15127
15240
  };
15128
15241
  }
15129
- const catalog = specsToCatalog2(await fetchQoderModels({ auth }));
15242
+ const list = await fetchQoderModels();
15243
+ const catalog = specsToCatalog2(list.models);
15244
+ if (list.source !== "server") {
15245
+ return {
15246
+ models: catalogToProviderModels3(catalog),
15247
+ fromCache: false,
15248
+ source: "fallback",
15249
+ error: `model server unavailable (${list.error ?? "unknown error"}); showing ${list.source} list`
15250
+ };
15251
+ }
15130
15252
  cache.store(QODER_PROVIDER_ID, catalog, { version: "qoder-cli-v1" });
15131
15253
  return { models: catalogToProviderModels3(catalog), fromCache: false, source: "live" };
15132
15254
  } catch (err) {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngosangns/ns-pi-provider",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -0,0 +1,24 @@
1
+ /**
2
+ * `ns-bridge plugin install` command.
3
+ *
4
+ * Installs a DSH plugin bundle into coding agent profiles (Pi, OMP, DSH).
5
+ * The bundle must have a package.json with a name field.
6
+ */
7
+ import { type Host, type HostPaths } from "./hosts.js";
8
+ export interface PluginInstallOptions {
9
+ bundlePath: string;
10
+ host: Host | "all";
11
+ profile?: string;
12
+ apply: boolean;
13
+ log: (line: string) => void;
14
+ err: (line: string) => void;
15
+ hostPaths?: HostPaths;
16
+ desktopRunning?: () => boolean;
17
+ }
18
+ export interface PluginInstallResult {
19
+ code: number;
20
+ }
21
+ /**
22
+ * Install a plugin bundle into one or more hosts.
23
+ */
24
+ export declare function runPluginInstall(options: PluginInstallOptions): Promise<PluginInstallResult>;
package/dist/plugin.js ADDED
@@ -0,0 +1,183 @@
1
+ /**
2
+ * `ns-bridge plugin install` command.
3
+ *
4
+ * Installs a DSH plugin bundle into coding agent profiles (Pi, OMP, DSH).
5
+ * The bundle must have a package.json with a name field.
6
+ */
7
+ import { spawnSync } from "node:child_process";
8
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
9
+ import { dirname, join } from "node:path";
10
+ import { defaultHostPaths, dshDesktopRunning, dshPatchPath, dshProfiles, formatCommand, } from "./hosts.js";
11
+ /**
12
+ * Install a plugin bundle into one or more hosts.
13
+ */
14
+ export async function runPluginInstall(options) {
15
+ const { bundlePath, host, profile, apply, log, err } = options;
16
+ const paths = options.hostPaths ?? defaultHostPaths();
17
+ const desktopRunning = options.desktopRunning ?? dshDesktopRunning;
18
+ // Validate bundle path
19
+ if (!existsSync(bundlePath)) {
20
+ err(`bundle not found: ${bundlePath}`);
21
+ return { code: 1 };
22
+ }
23
+ const packageJsonPath = join(bundlePath, "package.json");
24
+ if (!existsSync(packageJsonPath)) {
25
+ err(`bundle missing package.json: ${packageJsonPath}`);
26
+ return { code: 1 };
27
+ }
28
+ // Read plugin name from package.json
29
+ let pluginName;
30
+ try {
31
+ const pkg = JSON.parse(readFileSync(packageJsonPath, "utf8"));
32
+ pluginName = pkg.name;
33
+ if (!pluginName) {
34
+ err(`package.json missing name field: ${packageJsonPath}`);
35
+ return { code: 1 };
36
+ }
37
+ }
38
+ catch (error) {
39
+ err(`could not read ${packageJsonPath}: ${error instanceof Error ? error.message : String(error)}`);
40
+ return { code: 1 };
41
+ }
42
+ // Determine which hosts to install to
43
+ const hosts = host === "all" ? ["pi", "omp", "dsh"] : [host];
44
+ // Build installation steps
45
+ const steps = [];
46
+ const notes = [];
47
+ for (const targetHost of hosts) {
48
+ if (targetHost === "pi") {
49
+ steps.push({
50
+ host: "pi",
51
+ argv: ["pi", "plugin", "install", bundlePath],
52
+ });
53
+ }
54
+ else if (targetHost === "omp") {
55
+ steps.push({
56
+ host: "omp",
57
+ argv: ["omp", "plugin", "install", bundlePath],
58
+ });
59
+ }
60
+ else if (targetHost === "dsh") {
61
+ // DSH can target a specific profile or all profiles
62
+ const dshHome = paths.env.DSH_HOME ?? join(paths.home, ".dsh");
63
+ const profiles = profile ? [profile] : dshProfiles(dshHome);
64
+ if (profile && profile.toLowerCase() === "desktop" && desktopRunning()) {
65
+ notes.push(`# dsh ${profile} skipped: quit the DeepSeek Harness app to edit it`);
66
+ continue;
67
+ }
68
+ if (profiles.length === 0) {
69
+ notes.push(`# dsh skipped: no DSH profiles found`);
70
+ continue;
71
+ }
72
+ for (const profileName of profiles) {
73
+ if (isDesktop(profileName) && desktopRunning()) {
74
+ notes.push(`# dsh ${profileName} skipped: quit the DeepSeek Harness app to edit it`);
75
+ continue;
76
+ }
77
+ // For desktop profile, we would need to edit package.json dependencies
78
+ // For now, document this as not yet supported
79
+ if (isDesktop(profileName)) {
80
+ notes.push(`# dsh ${profileName}: desktop profile plugin install not yet supported`);
81
+ continue;
82
+ }
83
+ const patchPath = dshPatchPath(paths, profileName);
84
+ steps.push({
85
+ host: "dsh",
86
+ label: `add ${pluginName} to ${patchPath}`,
87
+ apply: () => addPluginToPatch(patchPath, pluginName),
88
+ });
89
+ }
90
+ }
91
+ }
92
+ // Execute or preview
93
+ if (!apply) {
94
+ log("# dry-run (run without --dry-run to apply)");
95
+ for (const step of steps) {
96
+ if (step.argv) {
97
+ log(formatCommand(step.argv));
98
+ }
99
+ else if (step.label) {
100
+ log(step.label);
101
+ }
102
+ }
103
+ for (const note of notes) {
104
+ log(note);
105
+ }
106
+ return { code: 0 };
107
+ }
108
+ // Execute steps
109
+ const runner = (argv) => {
110
+ const result = spawnSync(argv[0], argv.slice(1), { encoding: "utf8" });
111
+ return {
112
+ code: result.status ?? 1,
113
+ stdout: result.stdout ?? "",
114
+ stderr: result.stderr ?? "",
115
+ };
116
+ };
117
+ for (const step of steps) {
118
+ if (step.argv) {
119
+ log(formatCommand(step.argv));
120
+ const result = await runner(step.argv);
121
+ if (result.stdout.trim())
122
+ log(result.stdout.trimEnd());
123
+ if (result.code !== 0) {
124
+ if (step.tolerate) {
125
+ log(`# ignored: ${formatCommand(step.argv)} exited ${result.code}`);
126
+ continue;
127
+ }
128
+ if (result.stderr.trim())
129
+ err(result.stderr.trimEnd());
130
+ err(`${formatCommand(step.argv)} exited ${result.code}`);
131
+ return { code: 2 };
132
+ }
133
+ }
134
+ else if (step.apply) {
135
+ const result = step.apply();
136
+ if (typeof result !== "string") {
137
+ err(result.error);
138
+ return { code: 1 };
139
+ }
140
+ log(result);
141
+ }
142
+ }
143
+ for (const note of notes) {
144
+ log(note);
145
+ }
146
+ return { code: 0 };
147
+ }
148
+ function isDesktop(profile) {
149
+ return profile.toLowerCase() === "desktop";
150
+ }
151
+ function addPluginToPatch(patchPath, pluginName) {
152
+ let raw = "";
153
+ try {
154
+ raw = readFileSync(patchPath, "utf8");
155
+ }
156
+ catch (error) {
157
+ const code = typeof error === "object" && error !== null && "code" in error ? error.code : undefined;
158
+ if (code !== "ENOENT") {
159
+ const message = error instanceof Error ? error.message : String(error);
160
+ return { error: `could not read ${patchPath}: ${message}` };
161
+ }
162
+ }
163
+ // Check if plugin is already present
164
+ if (raw.includes(`name: '${pluginName}'`) || raw.includes(`name: "${pluginName}"`)) {
165
+ return `${patchPath}: ${pluginName} already present`;
166
+ }
167
+ // Add the plugin block
168
+ const block = `- insert:\n - id: ${pluginName.replace(/^ns-dsh-/, "")}\n name: '${pluginName}'`;
169
+ let next;
170
+ if (raw.trim() === "") {
171
+ next = `# ns-bridge plugin\n${block}\n`;
172
+ }
173
+ else if (raw.trim() === "[]") {
174
+ next = `# ns-bridge plugin\n${block}\n`;
175
+ }
176
+ else {
177
+ next = `${raw.replace(/\s+$/, "")}\n\n${block}\n`;
178
+ }
179
+ mkdirSync(dirname(patchPath), { recursive: true });
180
+ writeFileSync(patchPath, next, "utf8");
181
+ return `${patchPath}: added ${pluginName}`;
182
+ }
183
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,aAAa,GAId,MAAM,YAAY,CAAC;AAiBpB;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC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