opencode-m365-copilot 2.1.0 → 2.1.2

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-Dhpnsh1N.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-CN4xwvMF.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-Dhpnsh1N.mjs";
2
+ import { t as getOrCreateAgent } from "./agent-DDZ4B7E6.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";
@@ -60,8 +60,8 @@ const LOCAL_TITLE_MODEL = "local-title";
60
60
  */
61
61
  const DEFAULT_MODEL = "gpt-5.5-think-deeper";
62
62
  const MODELS = [
63
- m("work", "M365 Copilot (Work — reads your mailbox)", "magic", false, true),
64
- m("work-think", "M365 Copilot (Work, Think Deeper)", "Gpt_5_5_Reasoning", true, true),
63
+ m("work", "Ask your mail, Teams & files", "magic", false, true),
64
+ m("work-think", "Ask your mail, Teams & files (Think Deeper)", "Gpt_5_5_Reasoning", true, true),
65
65
  m("gpt-5.6-think-deeper", "GPT-5.6 (Think Deeper)", "Gpt_5_6_Reasoning", true),
66
66
  m("gpt-5.5-think-deeper", "GPT-5.5 (Think Deeper)", "Gpt_5_5_Reasoning", true),
67
67
  m("gpt-5.5", "GPT-5.5", "Gpt_5_5_Chat", false),
@@ -87,7 +87,7 @@ const MODELS = [
87
87
  function m(id, name, tone, reasoning, grounded = false) {
88
88
  return {
89
89
  id,
90
- name,
90
+ name: pickerName(name, tone, grounded),
91
91
  tone,
92
92
  reasoning,
93
93
  grounded,
@@ -97,6 +97,15 @@ function m(id, name, tone, reasoning, grounded = false) {
97
97
  }
98
98
  };
99
99
  }
100
+ /**
101
+ * Lead with what the model is for. opencode 2's `Model.Info` has no description, so
102
+ * the name is the only thing that separates reading your account from writing code.
103
+ * The local titler is neither.
104
+ */
105
+ function pickerName(name, tone, grounded) {
106
+ if (tone === null) return name;
107
+ return `${grounded ? "Work" : "Code"} · ${name}`;
108
+ }
100
109
  const BY_ID = new Map(MODELS.map((model) => [model.id, model]));
101
110
  /**
102
111
  * Look up a model, falling back to the default for anything we do not know.
@@ -776,7 +785,7 @@ function canonical(path) {
776
785
  */
777
786
  function isHomeOrAbove(dir) {
778
787
  const target = canonical(dir);
779
- if (target === parse(target).root) return true;
788
+ if (target === parse$1(target).root) return true;
780
789
  const home = canonical(homedir());
781
790
  return home === target || home.startsWith(target.endsWith(sep) ? target : `${target}${sep}`);
782
791
  }
@@ -949,7 +958,7 @@ function createTokenClient(options = {}) {
949
958
  const cache = /* @__PURE__ */ new Map();
950
959
  async function client() {
951
960
  if (app) return app;
952
- const { PublicClientApplication } = await import("./dist-DnyIX7Da.mjs");
961
+ const { PublicClientApplication } = await import("./dist-CN4xwvMF.mjs");
953
962
  app = new PublicClientApplication({
954
963
  auth: {
955
964
  clientId: CLIENT_ID,
@@ -2022,6 +2031,7 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2022
2031
  data = this.consume(this._payloadLength);
2023
2032
  if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) unmask(data, this._mask);
2024
2033
  }
2034
+ this._mask = void 0;
2025
2035
  if (this._opcode > 7) {
2026
2036
  this.controlMessage(data, cb);
2027
2037
  return;
@@ -3063,6 +3073,7 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3063
3073
  const https = __require("https");
3064
3074
  const http = __require("http");
3065
3075
  const net = __require("net");
3076
+ const querystring = __require("querystring");
3066
3077
  const tls = __require("tls");
3067
3078
  const { randomBytes, createHash } = __require("crypto");
3068
3079
  const { Duplex, Readable } = __require("stream");
@@ -3621,8 +3632,10 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3621
3632
  } catch {
3622
3633
  throw new SyntaxError(`Invalid URL: ${address}`);
3623
3634
  }
3624
- if (parsedUrl.protocol === "http:") parsedUrl.protocol = "ws:";
3625
- else if (parsedUrl.protocol === "https:") parsedUrl.protocol = "wss:";
3635
+ if (parsedUrl.protocol === "http:" || parsedUrl.protocol === "https:") {
3636
+ parsedUrl = new URL(parsedUrl);
3637
+ parsedUrl.protocol = parsedUrl.protocol === "http:" ? "ws:" : "wss:";
3638
+ }
3626
3639
  websocket._url = parsedUrl.href;
3627
3640
  const isSecure = parsedUrl.protocol === "wss:";
3628
3641
  const isIpcUrl = parsedUrl.protocol === "ws+unix:";
@@ -3675,7 +3688,7 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3675
3688
  if (opts.protocolVersion < 13) opts.headers["Sec-WebSocket-Origin"] = opts.origin;
3676
3689
  else opts.headers.Origin = opts.origin;
3677
3690
  }
3678
- if (parsedUrl.username || parsedUrl.password) opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
3691
+ if (parsedUrl.username || parsedUrl.password) opts.auth = `${querystring.unescape(parsedUrl.username)}:${querystring.unescape(parsedUrl.password)}`;
3679
3692
  if (isIpcUrl) {
3680
3693
  const i = opts.path.indexOf(":");
3681
3694
  if (i === -1) {
@@ -3891,8 +3904,12 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3891
3904
  function receiverOnConclude(code, reason) {
3892
3905
  const websocket = this[kWebSocket];
3893
3906
  websocket._closeFrameReceived = true;
3894
- websocket._closeMessage = reason;
3895
3907
  websocket._closeCode = code;
3908
+ if (reason.length === 0) websocket._closeMessage = EMPTY_BUFFER;
3909
+ else {
3910
+ websocket._closeMessage = Buffer.allocUnsafeSlow(reason.length);
3911
+ websocket._closeMessage.set(reason);
3912
+ }
3896
3913
  if (websocket._socket[kWebSocket] === void 0) return;
3897
3914
  websocket._socket.removeListener("data", socketOnData);
3898
3915
  process.nextTick(resume, websocket._socket);
@@ -9560,7 +9577,7 @@ const initializer = (inst, issues) => {
9560
9577
  };
9561
9578
  const ZodRealError = /*@__PURE__*/ $constructor("ZodError", initializer, void 0, { Parent: Error });
9562
9579
  // node_modules/zod/v4/classic/parse.js
9563
- const parse$1 = /* @__PURE__ */ _parse(ZodRealError);
9580
+ const parse = /* @__PURE__ */ _parse(ZodRealError);
9564
9581
  const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
9565
9582
  const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
9566
9583
  const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
@@ -9691,7 +9708,7 @@ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
9691
9708
  own(this, "~standard", value);
9692
9709
  },
9693
9710
  parse: function _parse(data, params) {
9694
- return parse$1(this, data, params, { callee: _parse });
9711
+ return parse(this, data, params, { callee: _parse });
9695
9712
  },
9696
9713
  parseAsync: async function _parseAsync(data, params) {
9697
9714
  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-Dhpnsh1N.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.2",
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"