@alisio/plugin-opencode 0.1.0-alpha.5 → 0.1.0-alpha.6

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/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { definePlugin } from "@alisio/sdk";
2
2
  import { OpenCodeProvider } from "./provider.js";
3
+ import { loadVersion } from "./version.js";
3
4
  const profileString = (request, key) => typeof request.profile[key] === "string" ? String(request.profile[key]) : "";
4
5
  export function createOpenCodePlugin() {
5
6
  return definePlugin({
@@ -7,7 +8,7 @@ export function createOpenCodePlugin() {
7
8
  name: "OpenCode Console (Zen)",
8
9
  description: "OpenCode Console gateway for Responses, Chat, and Messages models",
9
10
  categories: ["model-provider"],
10
- version: "0.1.0-alpha.1",
11
+ version: loadVersion(import.meta.url),
11
12
  apiVersion: 1,
12
13
  setup(api) {
13
14
  api.providers.register({
package/dist/provider.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { loadVersion } from "./version.js";
1
2
  const protocolMap = (groups) => new Map(Object.entries(groups).flatMap(([protocol, models]) => (models ?? []).map((model) => [model, protocol])));
2
3
  const GO_MODELS = protocolMap({
3
4
  responses: [
@@ -133,6 +134,8 @@ export function classifyOpenCodeModel(id) {
133
134
  }
134
135
  const dataUrl = (a) => `data:${a.mimeType};base64,${a.data}`;
135
136
  const modelId = (id) => id.replace(/^opencode(?:-go)?\//, "");
137
+ /** Default user agent derives from the package manifest at runtime; never a hardcoded version. */
138
+ const DEFAULT_USER_AGENT = `alisio/${loadVersion(import.meta.url)}`;
136
139
  async function* sse(response) {
137
140
  if (!response.ok)
138
141
  throw new Error(`OpenCode request failed: HTTP ${response.status}`);
@@ -219,7 +222,7 @@ export class OpenCodeGatewayProvider {
219
222
  this.displayName = config.product === "opencode-go" ? "OpenCode Go" : "OpenCode Console";
220
223
  this.classify = config.classify;
221
224
  this.baseURL = config.baseURL.replace(/\/$/, "");
222
- this.userAgent = config.userAgent ?? "alisio/0.1.0-alpha.1";
225
+ this.userAgent = config.userAgent ?? DEFAULT_USER_AGENT;
223
226
  const url = new URL(this.baseURL);
224
227
  if (url.protocol !== "https:" && url.hostname !== "127.0.0.1" && url.hostname !== "localhost")
225
228
  throw new Error("OpenCode base URL must use HTTPS");
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Reads this plugin package's version at runtime so plugin metadata, user-agent defaults and CLI
3
+ * reports stay in sync with the published package without a build-time constant to update.
4
+ * The manifest is resolved relative to the module (`src/version.ts` → `../package.json` in the
5
+ * source tree; `dist/version.js` → `../package.json` of the installed package). Standalone
6
+ * binaries inject the version at build time via ALISIO_PACKAGE_VERSION (scripts/binary-build.ts).
7
+ */
8
+ export declare function loadVersion(fromHere: string): string;
@@ -0,0 +1,28 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ /**
5
+ * Fallback used when neither the build-time injection nor the package manifest is readable
6
+ * (e.g. an unpackaged embed). Keep it a development marker, never a publish literal, so it
7
+ * cannot silently desync from the published package.
8
+ */
9
+ const FALLBACK = "dev";
10
+ /**
11
+ * Reads this plugin package's version at runtime so plugin metadata, user-agent defaults and CLI
12
+ * reports stay in sync with the published package without a build-time constant to update.
13
+ * The manifest is resolved relative to the module (`src/version.ts` → `../package.json` in the
14
+ * source tree; `dist/version.js` → `../package.json` of the installed package). Standalone
15
+ * binaries inject the version at build time via ALISIO_PACKAGE_VERSION (scripts/binary-build.ts).
16
+ */
17
+ export function loadVersion(fromHere) {
18
+ if (process.env.ALISIO_PACKAGE_VERSION)
19
+ return process.env.ALISIO_PACKAGE_VERSION;
20
+ try {
21
+ const manifest = join(dirname(fileURLToPath(fromHere)), "..", "package.json");
22
+ const parsed = JSON.parse(readFileSync(manifest, "utf8"));
23
+ return typeof parsed.version === "string" && parsed.version ? parsed.version : FALLBACK;
24
+ }
25
+ catch {
26
+ return FALLBACK;
27
+ }
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alisio/plugin-opencode",
3
- "version": "0.1.0-alpha.5",
3
+ "version": "0.1.0-alpha.6",
4
4
  "description": "Built-in OpenCode Console (Zen) model provider for Alisio.",
5
5
  "license": "MIT",
6
6
  "type": "module",