opencode-m365-copilot 2.0.0 → 2.1.0

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/README.md CHANGED
@@ -195,6 +195,42 @@ A non-default tone (Claude, the reasoning tones) only takes effect when **no** a
195
195
  attached — with one, M365 silently routes to GPT regardless. The proxy therefore attaches
196
196
  the agent only on turns that carry tools, so plain chat reaches the model the tone selects.
197
197
 
198
+ ### Reading your Microsoft 365 work
199
+
200
+ Two models ground the turn on your **own Microsoft 365 account**. Copilot's `WorkSearch`
201
+ runs server-side over the Microsoft Search index, so these span your whole work substrate,
202
+ not just mail:
203
+
204
+ | Model | Use |
205
+ |---|---|
206
+ | `m365/work` | Ask about your work — "what needs my attention first", "summarise the thread with X", "what did Jim message me on Teams", "find my recent sprint docs" |
207
+ | `m365/work-think` | The same, on a reasoning tone |
208
+
209
+ What `WorkSearch` reaches (all verified against a live tenant, except where noted):
210
+
211
+ | Source | Grounded? |
212
+ |---|---|
213
+ | Outlook **mail** and **calendar** | ✅ |
214
+ | **Teams** chats and channel messages | ✅ |
215
+ | **OneDrive** and **SharePoint** files | ✅ |
216
+ | **People** (colleagues, senders, managers) | ✅ |
217
+ | Third-party **Graph connectors** (Jira, ServiceNow, …) | ✅ *if your admin configured them* |
218
+
219
+ Select one in opencode (the model picker, or pin a `work` sub-agent to it) when you want
220
+ this context; every other model stays coding/web-only and never reaches your account. A
221
+ grounded turn switches the request to the Outlook side-pane scenario, sends that surface's
222
+ feature variants, and attaches the built-in agent with the `WorkSearch` capability — the
223
+ combination that actually grounds on the signed-in account — then strips Copilot's inline
224
+ citation markers from the reply. Bias toward one source by saying so ("in Teams, …", "in my
225
+ OneDrive, …").
226
+
227
+ These models are for **reading and synthesis** — ask-your-work Q&A. A grounded turn carries
228
+ **no tools**: the proxy drops opencode's toolset for these models, so the fenced tool
229
+ instructions are never attached and no tool-call parsing runs on the reply — Copilot brings
230
+ its own built-in agent instead. Keep a coding model selected for coding, and switch to
231
+ `m365/work` to ask about your mail, Teams or files. Read-only: Copilot searches and
232
+ summarises, it does not send a message or edit a file.
233
+
198
234
  ## Authentication
199
235
 
200
236
  Sign-in is a CLI concern, never the plugin's: the plugin only refreshes silently and asks
@@ -1,4 +1,4 @@
1
- import { _ as createLogger, b as AGENT_FILE, d as POWERPLATFORM_SCOPE, l as BAP_SCOPE, y as writePrivateFile } from "./server-IXv9y_4x.mjs";
1
+ import { _ as createLogger, b as AGENT_FILE, d as POWERPLATFORM_SCOPE, l as BAP_SCOPE, y as writePrivateFile } from "./server-CRfZjKho.mjs";
2
2
  import { readFileSync } from "node:fs";
3
3
  import { createHash } from "node:crypto";
4
4
  // src/agent.ts
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { A as DEFAULT_MODEL, C as SECRETS_FILE, O as mergeOpencodeConfig, S as CONFIG_DIR, T as PROVIDER_ID, a as startServer, b as AGENT_FILE, g as createTokenClient, j as LOCAL_TITLE_MODEL, x as CACHE_FILE } from "./server-IXv9y_4x.mjs";
3
- import { t as getOrCreateAgent } from "./agent-D4_Eut51.mjs";
2
+ import { A as DEFAULT_MODEL, C as SECRETS_FILE, O as mergeOpencodeConfig, S as CONFIG_DIR, T as PROVIDER_ID, a as startServer, b as AGENT_FILE, g as createTokenClient, j as LOCAL_TITLE_MODEL, x as CACHE_FILE } from "./server-CRfZjKho.mjs";
3
+ import { t as getOrCreateAgent } from "./agent-C76uuF-q.mjs";
4
4
  import { homedir } from "node:os";
5
5
  import { dirname, join, resolve } from "node:path";
6
6
  import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
@@ -46,7 +46,7 @@ to complete SSO/MFA by hand once — the only option on tenants with push-only
46
46
  MFA, FIDO2, or a federated IdP.`);
47
47
  }
48
48
  async function doLogin(args) {
49
- const { login } = await import("./login-DcSFLsOo.mjs");
49
+ const { login } = await import("./login-j65WhI4A.mjs");
50
50
  const interactive = args.includes("--interactive");
51
51
  try {
52
52
  const account = await login({
@@ -1,4 +1,4 @@
1
- import { F as __toESM, N as __commonJSMin, P as __require } from "./server-IXv9y_4x.mjs";
1
+ import { F as __toESM, N as __commonJSMin, P as __require } from "./server-CRfZjKho.mjs";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import http from "http";
4
4
  import crypto, { createHash as createHash$1 } from "crypto";
@@ -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-IXv9y_4x.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-CRfZjKho.mjs";
2
2
  import { join } from "node:path";
3
3
  import { chmodSync, existsSync, readFileSync, statSync } from "node:fs";
4
4
  // src/login.ts
@@ -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-BNzsla4k.mjs");
99
+ const { PublicClientApplication, CryptoProvider } = await import("./dist-DnyIX7Da.mjs");
100
100
  const app = new PublicClientApplication({
101
101
  auth: {
102
102
  clientId: CLIENT_ID,
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-IXv9y_4x.mjs";
2
- import { t as getOrCreateAgent } from "./agent-D4_Eut51.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-CRfZjKho.mjs";
2
+ import { t as getOrCreateAgent } from "./agent-C76uuF-q.mjs";
3
3
  // src/runtime.ts
4
4
  /**
5
5
  * What the plugin stands on: the OpenAI-compatible proxy, started in-process (or an
@@ -60,6 +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
65
  m("gpt-5.6-think-deeper", "GPT-5.6 (Think Deeper)", "Gpt_5_6_Reasoning", true),
64
66
  m("gpt-5.5-think-deeper", "GPT-5.5 (Think Deeper)", "Gpt_5_5_Reasoning", true),
65
67
  m("gpt-5.5", "GPT-5.5", "Gpt_5_5_Chat", false),
@@ -82,12 +84,13 @@ const MODELS = [
82
84
  m("gpt-5.2-think-deeper", "GPT-5.2 (Think Deeper)", "Gpt_5_2_Reasoning", true),
83
85
  m(LOCAL_TITLE_MODEL, "Local titler (no M365 call)", null, false)
84
86
  ];
85
- function m(id, name, tone, reasoning) {
87
+ function m(id, name, tone, reasoning, grounded = false) {
86
88
  return {
87
89
  id,
88
90
  name,
89
91
  tone,
90
92
  reasoning,
93
+ grounded,
91
94
  limit: {
92
95
  context: CONTEXT_TOKENS,
93
96
  output: OUTPUT_TOKENS
@@ -946,7 +949,7 @@ function createTokenClient(options = {}) {
946
949
  const cache = /* @__PURE__ */ new Map();
947
950
  async function client() {
948
951
  if (app) return app;
949
- const { PublicClientApplication } = await import("./dist-BNzsla4k.mjs");
952
+ const { PublicClientApplication } = await import("./dist-DnyIX7Da.mjs");
950
953
  app = new PublicClientApplication({
951
954
  auth: {
952
955
  clientId: CLIENT_ID,
@@ -4731,6 +4734,19 @@ const VARIANTS = [
4731
4734
  "feature.EnableSydneyClientCompliance",
4732
4735
  "feature.EnableStreaming"
4733
4736
  ].join(",");
4737
+ /**
4738
+ * The variants the Outlook side-pane client sends, used only for a grounded
4739
+ * turn. Verified live 2026-11-09: without them the mailbox scenario replies
4740
+ * "you don't have a valid license" (contentOrigin "BotConnection"). Cargo-culted
4741
+ * from a captured first-party side-pane session, exactly as VARIANTS above is.
4742
+ */
4743
+ const GROUNDED_VARIANTS = [
4744
+ "feature.OutlookSidepaneWorkCopilotToHelix",
4745
+ "feature.EnableStarterLicenseCheckBypass",
4746
+ "feature.IsStreamingModeInChatRequestEnabled",
4747
+ "feature.isExternalEmailEnabled",
4748
+ "IncludeSourceAttributionsConcise"
4749
+ ].join(",");
4734
4750
  /** The message types we tell the server we are able to render. */
4735
4751
  const ALLOWED_MESSAGE_TYPES = [
4736
4752
  "Chat",
@@ -4766,6 +4782,24 @@ var DisengagedError = class extends Error {
4766
4782
  }
4767
4783
  };
4768
4784
  /**
4785
+ * Strip Copilot's inline citation control tokens from a GROUNDED answer.
4786
+ *
4787
+ * The web UI renders these as citation chips; over the wire they arrive as
4788
+ * literal noise: private-use-area delimiters (U+E000–U+F8FF) wrapping
4789
+ * `cite…turn1search23…` runs, plus `【2-9c5ade】`-style attribution markers.
4790
+ * Only the side-pane (grounded) surface emits them, which is why the caller runs
4791
+ * this on grounded turns only — a coding answer is passed through untouched, so
4792
+ * its indentation is never altered.
4793
+ *
4794
+ * Even here the whitespace tidy is indentation-safe: it collapses only runs that
4795
+ * FOLLOW a non-space character (the double spaces a removed token leaves mid
4796
+ * line), never leading indentation — a grounded answer can still contain a code
4797
+ * block. Measured against live answers 2026-11-09.
4798
+ */
4799
+ function cleanAnswer(text) {
4800
+ return text.replace(/[\u{E000}-\u{F8FF}\u{F0000}-\u{FFFFD}\u{100000}-\u{10FFFD}]/gu, "").replace(/cite(?:turn\d+[a-z]+\d+)+/gi, "").replace(/【[^】]{1,60}】/g, "").replace(/[ \t]+\n/g, "\n").replace(/(\S)[ \t]{2,}/g, "$1 ").trim();
4801
+ }
4802
+ /**
4769
4803
  * One M365 conversation.
4770
4804
  *
4771
4805
  * Stateful across turns: the conversation and session ids persist so the server keeps
@@ -4791,7 +4825,7 @@ var CopilotSession = class {
4791
4825
  if (turn.signal?.aborted) throw abortError();
4792
4826
  const token = await this.options.getToken();
4793
4827
  const { oid, tid } = decodeJwt(token);
4794
- const url = this.buildUrl(token, oid, tid);
4828
+ const url = this.buildUrl(token, oid, tid, turn.grounded ?? false);
4795
4829
  const { annotations, note } = await this.uploadImages(token, turn);
4796
4830
  const message = {
4797
4831
  text: note ? `${text}\n\n${note}` : text,
@@ -4833,18 +4867,28 @@ var CopilotSession = class {
4833
4867
  note: images.length === 1 ? "(The user attached an image, but it could not be uploaded, so it is not visible to you. If it matters, let them know.)" : `(${missing} of the ${images.length} attached images could not be uploaded, so they are not visible to you. If they matter, let the user know.)`
4834
4868
  };
4835
4869
  }
4836
- buildUrl(token, oid, tid) {
4837
- return `${this.options.endpoint ?? DEFAULT_ENDPOINT}/m365Copilot/Chathub/${oid}@${tid}?${new URLSearchParams({
4870
+ buildUrl(token, oid, tid, grounded) {
4871
+ const origin = this.options.endpoint ?? DEFAULT_ENDPOINT;
4872
+ const scenarioParams = grounded ? {
4873
+ source: "\"owahub\"",
4874
+ product: "OwaHub",
4875
+ agentHost: "Bizchat.Sidepane",
4876
+ scenario: "OutlookSidepaneWorkCopilot",
4877
+ agent: "work"
4878
+ } : {
4879
+ source: "\"officeweb\"",
4880
+ product: "Office",
4881
+ agentHost: "Bizchat.FullScreen",
4882
+ scenario: "OfficeWebIncludedCopilot"
4883
+ };
4884
+ return `${origin}/m365Copilot/Chathub/${oid}@${tid}?${new URLSearchParams({
4838
4885
  access_token: token,
4839
4886
  ConversationId: this.conversationId,
4840
4887
  chatsessionid: this.sessionId,
4841
4888
  "X-SessionId": this.sessionId,
4842
4889
  clientrequestid: randomUUID(),
4843
- source: "\"officeweb\"",
4844
- product: "Office",
4845
- agentHost: "Bizchat.FullScreen",
4846
- scenario: "OfficeWebIncludedCopilot",
4847
- variants: VARIANTS
4890
+ ...scenarioParams,
4891
+ variants: grounded ? GROUNDED_VARIANTS : VARIANTS
4848
4892
  }).toString()}`;
4849
4893
  }
4850
4894
  /** Drive one turn to completion. */
@@ -4863,7 +4907,8 @@ var CopilotSession = class {
4863
4907
  reject(error);
4864
4908
  return;
4865
4909
  }
4866
- result.text = deltaText.length >= snapshotText.length ? deltaText : snapshotText;
4910
+ const raw = deltaText.length >= snapshotText.length ? deltaText : snapshotText;
4911
+ result.text = turn.grounded ? cleanAnswer(raw) : raw;
4867
4912
  resolve(result);
4868
4913
  };
4869
4914
  const onAbort = () => {
@@ -4951,20 +4996,35 @@ var CopilotSession = class {
4951
4996
  const argument = {
4952
4997
  message,
4953
4998
  tone: turn.tone ?? "magic",
4954
- source: "officeweb",
4999
+ source: turn.grounded ? "owahub" : "officeweb",
4955
5000
  streamingMode: "ConciseWithPadding",
4956
5001
  isStartOfSession: this.turnIndex === 0,
4957
5002
  conversationId: this.conversationId,
4958
5003
  allowedMessageTypes: ALLOWED_MESSAGE_TYPES,
4959
5004
  optionsSets: [],
4960
- clientInfo: {
5005
+ clientInfo: turn.grounded ? {
5006
+ clientPlatform: "OwaHub-web",
5007
+ clientAppName: "OwaHub",
5008
+ clientAppType: "Web",
5009
+ productEntryPoint: "Email"
5010
+ } : {
4961
5011
  clientPlatform: "mcmcopilot-web",
4962
5012
  clientAppName: "Office",
4963
5013
  clientAppVersion: "1.0.0"
4964
5014
  },
4965
5015
  traceId: randomUUID()
4966
5016
  };
4967
- if (turn.agentId) {
5017
+ if (turn.grounded) {
5018
+ argument.gpts = [{
5019
+ id: "bizchat-as-gpt-scenario",
5020
+ source: "BuiltInAgents",
5021
+ clientOverrides: { capabilities: [{ name: "WebSearch" }, { name: "WorkSearch" }] }
5022
+ }];
5023
+ argument.plugins = [{
5024
+ Id: "BingWebSearch",
5025
+ Source: "BuiltIn"
5026
+ }];
5027
+ } else if (turn.agentId) {
4968
5028
  argument.threadLevelGptId = {
4969
5029
  id: turn.agentId,
4970
5030
  source: "MOS3"
@@ -5001,6 +5061,7 @@ var CopilotSession = class {
5001
5061
  log$1.info("sending turn", trunc({
5002
5062
  tone: argument.tone,
5003
5063
  agent: Boolean(turn.agentId),
5064
+ grounded: Boolean(turn.grounded),
5004
5065
  images: outgoing.annotations.length,
5005
5066
  text
5006
5067
  }));
@@ -10938,21 +10999,23 @@ async function runTurn(request, response, context, body, conversation, model, to
10938
10999
  getToken: context.deps.getToken,
10939
11000
  ...context.deps.endpoint ? { endpoint: context.deps.endpoint } : {}
10940
11001
  });
11002
+ const effectiveTools = model.grounded ? [] : tools;
10941
11003
  const images = collectImages(body.messages, conversation.sentMessageCount);
10942
- const prompt = buildTurnPrompt(body.messages, tools, conversation.sentMessageCount, { ...context.deps.leanSystemPrompt !== void 0 ? { leanSystemPrompt: context.deps.leanSystemPrompt } : {} });
10943
- const agent = tools.length > 0 ? await context.agentId() : null;
11004
+ const prompt = buildTurnPrompt(body.messages, effectiveTools, conversation.sentMessageCount, { ...context.deps.leanSystemPrompt !== void 0 ? { leanSystemPrompt: context.deps.leanSystemPrompt } : {} });
11005
+ const agent = effectiveTools.length > 0 ? await context.agentId() : null;
10944
11006
  const abort = new AbortController();
10945
11007
  request.on("close", () => {
10946
11008
  if (!response.writableEnded) abort.abort();
10947
11009
  });
10948
11010
  const streaming = body.stream === true;
10949
11011
  const streamId = `chatcmpl-${randomUUID()}`;
10950
- const canStreamText = streaming && tools.length === 0;
11012
+ const canStreamText = streaming && effectiveTools.length === 0 && !model.grounded;
10951
11013
  if (streaming) startSse(response);
10952
11014
  try {
10953
11015
  const result = await conversation.session.run(prompt, {
10954
11016
  ...model.tone ? { tone: model.tone } : {},
10955
11017
  agentId: agent,
11018
+ ...model.grounded ? { grounded: true } : {},
10956
11019
  signal: abort.signal,
10957
11020
  ...images.length > 0 ? { images } : {},
10958
11021
  ...canStreamText ? { onDelta: (chunk) => response.write(streamChunk(streamId, model.id, { content: chunk })) } : {}
@@ -10961,14 +11024,14 @@ async function runTurn(request, response, context, body, conversation, model, to
10961
11024
  if (!streaming) {
10962
11025
  sendJson(response, 200, buildCompletion(result, {
10963
11026
  model: model.id,
10964
- tools,
11027
+ tools: effectiveTools,
10965
11028
  allowMultiple: context.deps.allowMultiTool ?? false
10966
11029
  }));
10967
11030
  return;
10968
11031
  }
10969
- finishStream(response, streamId, model.id, result, tools, canStreamText, context.deps.allowMultiTool ?? false);
11032
+ finishStream(response, streamId, model.id, result, effectiveTools, canStreamText, context.deps.allowMultiTool ?? false);
10970
11033
  } catch (error) {
10971
- handleTurnFailure(response, error, streaming, tools.length);
11034
+ handleTurnFailure(response, error, streaming, effectiveTools.length);
10972
11035
  }
10973
11036
  }
10974
11037
  /** Emit the closing frames of a streamed turn. */
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-IXv9y_4x.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-CRfZjKho.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-m365-copilot",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Use your org's Microsoft 365 Copilot as the model backend for opencode",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -73,5 +73,9 @@
73
73
  "playwright": {
74
74
  "optional": true
75
75
  }
76
+ },
77
+ "overrides": {
78
+ "glob": "^14.0.3",
79
+ "minimatch": "^11.0.2"
76
80
  }
77
81
  }