opencode-m365-copilot 2.1.0 → 2.1.1

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
- import { C as SECRETS_FILE, S as CONFIG_DIR, _ as createLogger, c as AUTHORITY, f as REDIRECT_URI, h as createCachePlugin, m as authCodeFromUrl, o as object, p as SYDNEY_SCOPES, s as string, u as CLIENT_ID, v as ensurePrivateDir } from "./server-CRfZjKho.mjs";
1
+ import { C as SECRETS_FILE, S as CONFIG_DIR, _ as createLogger, c as AUTHORITY, f as REDIRECT_URI, h as createCachePlugin, m as authCodeFromUrl, o as object, p as SYDNEY_SCOPES, s as string, u as CLIENT_ID, v as ensurePrivateDir } from "./server-MaGKSmnd.mjs";
2
2
  import { join } from "node:path";
3
3
  import { chmodSync, existsSync, readFileSync, statSync } from "node:fs";
4
4
  // src/login.ts
@@ -79,7 +79,7 @@ function normaliseTotpSecret(raw) {
79
79
  }
80
80
  /** Current 6-digit code for a base32 seed. */
81
81
  async function totpCode(secret) {
82
- const { TOTP, Secret } = await import("./otpauth.node-DaSYf7YH.mjs");
82
+ const { TOTP, Secret } = await import("./otpauth.node-Cz2NJJEI.mjs");
83
83
  return new TOTP({
84
84
  secret: Secret.fromBase32(normaliseTotpSecret(secret)),
85
85
  digits: 6,
@@ -96,7 +96,7 @@ async function login(options = {}) {
96
96
  const secrets = loadSecrets(options.secretsFile);
97
97
  const interactive = options.interactive ?? !secrets?.mfaSecret;
98
98
  if (!interactive && !secrets) throw new Error(`No credentials at ${options.secretsFile ?? SECRETS_FILE}. Create it with { "email", "password", "mfaSecret" }, or sign in interactively with --interactive.`);
99
- const { PublicClientApplication, CryptoProvider } = await import("./dist-DnyIX7Da.mjs");
99
+ const { PublicClientApplication, CryptoProvider } = await import("./dist-DoXU8l_x.mjs");
100
100
  const app = new PublicClientApplication({
101
101
  auth: {
102
102
  clientId: CLIENT_ID,
@@ -201,7 +201,7 @@ import * as crypto from "node:crypto";
201
201
  * Returns random bytes.
202
202
  * @param {number} size Size.
203
203
  * @returns {Uint8Array} Random bytes.
204
- */ const randomBytes$1 = (size) => {
204
+ */ const randomBytes = (size) => {
205
205
  if (crypto?.randomBytes) return crypto.randomBytes(size);
206
206
  else if (globalScope.crypto?.getRandomValues) return globalScope.crypto.getRandomValues(new Uint8Array(size));
207
207
  else throw new Error("Cryptography API not available");
@@ -302,7 +302,7 @@ import * as crypto from "node:crypto";
302
302
  * Secret key.
303
303
  * @type {Uint8Array}
304
304
  * @readonly
305
- */ this.bytes = typeof buffer === "undefined" ? randomBytes$1(size) : new Uint8Array(buffer);
305
+ */ this.bytes = typeof buffer === "undefined" ? randomBytes(size) : new Uint8Array(buffer);
306
306
  Object.defineProperty(this, "bytes", {
307
307
  enumerable: true,
308
308
  writable: false,
@@ -316,7 +316,7 @@ import * as crypto from "node:crypto";
316
316
  * @param {string} a String a.
317
317
  * @param {string} b String b.
318
318
  * @returns {boolean} Equality result.
319
- */ const timingSafeEqual$1 = (a, b) => {
319
+ */ const timingSafeEqual = (a, b) => {
320
320
  if (crypto?.timingSafeEqual) return crypto.timingSafeEqual(globalScope.Buffer.from(a), globalScope.Buffer.from(b));
321
321
  else {
322
322
  if (a.length !== b.length) throw new TypeError("Input strings must have the same length");
@@ -407,7 +407,7 @@ import * as crypto from "node:crypto";
407
407
  counter: i,
408
408
  hmac
409
409
  });
410
- if (timingSafeEqual$1(token, generatedToken)) delta = i - counter;
410
+ if (timingSafeEqual(token, generatedToken)) delta = i - counter;
411
411
  };
412
412
  check(counter);
413
413
  for (let i = 1; i <= window && delta === null; ++i) {
package/dist/plugin.d.mts CHANGED
@@ -1,3 +1,23 @@
1
+ /**
2
+ * The plugin entry: one default export, the opencode 2 plugin.
3
+ *
4
+ * opencode 2 imports the package's root entry and validates its default export as
5
+ * `{ id, setup }`. A shape it does not accept is not an error — the plugin simply
6
+ * never loads — so `plugin-entry.test.ts` checks the built artefact.
7
+ *
8
+ * Two rules outlive opencode 1 support, and both are pinned there too:
9
+ *
10
+ * - **Exactly one export.** A loader that walks every export and finds a second
11
+ * plugin-shaped value starts the proxy twice; a non-plugin one can fail the load.
12
+ * - **No `./server` export subpath in package.json.** That name is opencode's for a
13
+ * plugin's server entry. Ours once pointed it at the HTTP proxy, and that was #26.
14
+ *
15
+ * The definition is annotated as `Plugin.Plugin` rather than built with
16
+ * `Plugin.define(...)`: that helper is the identity function, and calling it would
17
+ * mean importing `@opencode/plugin` at runtime. A type-only import keeps the
18
+ * published package free of it, which is also what keeps the dts bundler from
19
+ * inlining effect (see `tsdown.config.ts`).
20
+ */
1
21
  import { Plugin } from "@opencode/plugin";
2
22
  declare const definition: Plugin.Plugin;
3
23
  export { definition as default };
package/dist/plugin.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { A as DEFAULT_MODEL, D as buildProviderInfo, E as buildModelInfos, M as isLocalModel, T as PROVIDER_ID, _ as createLogger, a as startServer, g as createTokenClient, k as resolveOptions, r as SESSION_ID_HEADER, t as AUX_REQUEST_KIND_HEADER, w as PLUGIN_ID } from "./server-CRfZjKho.mjs";
2
- import { t as getOrCreateAgent } from "./agent-C76uuF-q.mjs";
1
+ import { A as DEFAULT_MODEL, D as buildProviderInfo, E as buildModelInfos, M as isLocalModel, T as PROVIDER_ID, _ as createLogger, a as startServer, g as createTokenClient, k as resolveOptions, r as SESSION_ID_HEADER, t as AUX_REQUEST_KIND_HEADER, w as PLUGIN_ID } from "./server-MaGKSmnd.mjs";
2
+ import { t as getOrCreateAgent } from "./agent-Do_zx7Ev.mjs";
3
3
  // src/runtime.ts
4
4
  /**
5
5
  * What the plugin stands on: the OpenAI-compatible proxy, started in-process (or an
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { homedir } from "node:os";
3
- import { dirname, join, parse, resolve, sep } from "node:path";
3
+ import { dirname, join, parse as parse$1, resolve, sep } from "node:path";
4
4
  import { appendFileSync, chmodSync, closeSync, constants, mkdirSync, openSync, readFileSync, realpathSync, writeFileSync, writeSync } from "node:fs";
5
5
  import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
6
6
  import { createServer } from "node:http";
@@ -776,7 +776,7 @@ function canonical(path) {
776
776
  */
777
777
  function isHomeOrAbove(dir) {
778
778
  const target = canonical(dir);
779
- if (target === parse(target).root) return true;
779
+ if (target === parse$1(target).root) return true;
780
780
  const home = canonical(homedir());
781
781
  return home === target || home.startsWith(target.endsWith(sep) ? target : `${target}${sep}`);
782
782
  }
@@ -949,7 +949,7 @@ function createTokenClient(options = {}) {
949
949
  const cache = /* @__PURE__ */ new Map();
950
950
  async function client() {
951
951
  if (app) return app;
952
- const { PublicClientApplication } = await import("./dist-DnyIX7Da.mjs");
952
+ const { PublicClientApplication } = await import("./dist-DoXU8l_x.mjs");
953
953
  app = new PublicClientApplication({
954
954
  auth: {
955
955
  clientId: CLIENT_ID,
@@ -2022,6 +2022,7 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2022
2022
  data = this.consume(this._payloadLength);
2023
2023
  if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) unmask(data, this._mask);
2024
2024
  }
2025
+ this._mask = void 0;
2025
2026
  if (this._opcode > 7) {
2026
2027
  this.controlMessage(data, cb);
2027
2028
  return;
@@ -3063,6 +3064,7 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3063
3064
  const https = __require("https");
3064
3065
  const http = __require("http");
3065
3066
  const net = __require("net");
3067
+ const querystring = __require("querystring");
3066
3068
  const tls = __require("tls");
3067
3069
  const { randomBytes, createHash } = __require("crypto");
3068
3070
  const { Duplex, Readable } = __require("stream");
@@ -3621,8 +3623,10 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3621
3623
  } catch {
3622
3624
  throw new SyntaxError(`Invalid URL: ${address}`);
3623
3625
  }
3624
- if (parsedUrl.protocol === "http:") parsedUrl.protocol = "ws:";
3625
- else if (parsedUrl.protocol === "https:") parsedUrl.protocol = "wss:";
3626
+ if (parsedUrl.protocol === "http:" || parsedUrl.protocol === "https:") {
3627
+ parsedUrl = new URL(parsedUrl);
3628
+ parsedUrl.protocol = parsedUrl.protocol === "http:" ? "ws:" : "wss:";
3629
+ }
3626
3630
  websocket._url = parsedUrl.href;
3627
3631
  const isSecure = parsedUrl.protocol === "wss:";
3628
3632
  const isIpcUrl = parsedUrl.protocol === "ws+unix:";
@@ -3675,7 +3679,7 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3675
3679
  if (opts.protocolVersion < 13) opts.headers["Sec-WebSocket-Origin"] = opts.origin;
3676
3680
  else opts.headers.Origin = opts.origin;
3677
3681
  }
3678
- if (parsedUrl.username || parsedUrl.password) opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
3682
+ if (parsedUrl.username || parsedUrl.password) opts.auth = `${querystring.unescape(parsedUrl.username)}:${querystring.unescape(parsedUrl.password)}`;
3679
3683
  if (isIpcUrl) {
3680
3684
  const i = opts.path.indexOf(":");
3681
3685
  if (i === -1) {
@@ -3891,8 +3895,12 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3891
3895
  function receiverOnConclude(code, reason) {
3892
3896
  const websocket = this[kWebSocket];
3893
3897
  websocket._closeFrameReceived = true;
3894
- websocket._closeMessage = reason;
3895
3898
  websocket._closeCode = code;
3899
+ if (reason.length === 0) websocket._closeMessage = EMPTY_BUFFER;
3900
+ else {
3901
+ websocket._closeMessage = Buffer.allocUnsafeSlow(reason.length);
3902
+ websocket._closeMessage.set(reason);
3903
+ }
3896
3904
  if (websocket._socket[kWebSocket] === void 0) return;
3897
3905
  websocket._socket.removeListener("data", socketOnData);
3898
3906
  process.nextTick(resume, websocket._socket);
@@ -9560,7 +9568,7 @@ const initializer = (inst, issues) => {
9560
9568
  };
9561
9569
  const ZodRealError = /*@__PURE__*/ $constructor("ZodError", initializer, void 0, { Parent: Error });
9562
9570
  // node_modules/zod/v4/classic/parse.js
9563
- const parse$1 = /* @__PURE__ */ _parse(ZodRealError);
9571
+ const parse = /* @__PURE__ */ _parse(ZodRealError);
9564
9572
  const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
9565
9573
  const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
9566
9574
  const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
@@ -9691,7 +9699,7 @@ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
9691
9699
  own(this, "~standard", value);
9692
9700
  },
9693
9701
  parse: function _parse(data, params) {
9694
- return parse$1(this, data, params, { callee: _parse });
9702
+ return parse(this, data, params, { callee: _parse });
9695
9703
  },
9696
9704
  parseAsync: async function _parseAsync(data, params) {
9697
9705
  return await parseAsync(this, data, params, { callee: _parseAsync });
package/dist/server.d.mts CHANGED
@@ -1,3 +1,14 @@
1
+ /**
2
+ * The OpenAI-compatible HTTP surface.
3
+ *
4
+ * Small on purpose: `node:http` rather than a framework, because this runs inside
5
+ * opencode's own process and every dependency here is one opencode has to install.
6
+ * It binds loopback only, and loopback is not a trust boundary: every browser tab on
7
+ * the machine can reach it too. So every request must also carry a per-launch secret
8
+ * (`Authorization: Bearer <apiKey>`), must name a loopback `Host` (DNS rebinding), and
9
+ * must not come from a browser `Origin` the caller did not allow. No CORS headers are
10
+ * ever sent — opencode is a server-side client and needs none.
11
+ */
1
12
  /**
2
13
  * Default when a request carries no model.
3
14
  *
package/dist/server.mjs CHANGED
@@ -1 +1 @@
1
- export { t as AUX_REQUEST_KIND_HEADER, n as DEFAULT_MAX_BODY_BYTES, A as DEFAULT_MODEL, r as SESSION_ID_HEADER, i as generateApiKey, a as startServer } from "./server-CRfZjKho.mjs";
1
+ export { t as AUX_REQUEST_KIND_HEADER, n as DEFAULT_MAX_BODY_BYTES, A as DEFAULT_MODEL, r as SESSION_ID_HEADER, i as generateApiKey, a as startServer } from "./server-MaGKSmnd.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-m365-copilot",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "Use your org's Microsoft 365 Copilot as the model backend for opencode",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -32,19 +32,19 @@
32
32
  "typecheck": "tsc --noEmit"
33
33
  },
34
34
  "dependencies": {
35
- "@azure/msal-node": "^7.0.0",
36
- "otpauth": "^9.5.0",
37
- "ws": "^8.20.0",
38
- "zod": "^4.3.6"
35
+ "@azure/msal-node": "^7.2.1",
36
+ "otpauth": "^9.6.0",
37
+ "ws": "^8.22.2",
38
+ "zod": "^4.6.7"
39
39
  },
40
40
  "devDependencies": {
41
- "@opencode/plugin": "^2.2.5",
42
- "@types/node": "^26.2.0",
43
- "@types/ws": "^8.18.1",
44
- "playwright": "^1.62.1",
45
- "tsdown": "^0.23.4",
41
+ "@opencode/plugin": "^2.2.6",
42
+ "@types/node": "^26.6.6",
43
+ "@types/ws": "^8.18.2",
44
+ "playwright": "^1.65.0",
45
+ "tsdown": "^0.23.7",
46
46
  "typescript": "^7.0.2",
47
- "vitest": "^5.0.0"
47
+ "vitest": "^5.1.0"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"