opencode-m365-copilot 0.4.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 +83 -57
- package/dist/{agent-CtiM1nN_.mjs → agent-C76uuF-q.mjs} +2 -2
- package/dist/cli.mjs +7 -6
- package/dist/{dist-Dp9sO-mB.mjs → dist-DnyIX7Da.mjs} +1 -1
- package/dist/{login-CWvKVY0k.mjs → login-j65WhI4A.mjs} +3 -3
- package/dist/plugin.d.mts +2 -8
- package/dist/plugin.mjs +9 -30
- package/dist/{server-Cow8-T6p.mjs → server-CRfZjKho.mjs} +124 -123
- package/dist/server.mjs +1 -1
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -28,11 +28,11 @@ opencode-m365 setup # adds the plugin to ~/.config/opencode/opencode.json
|
|
|
28
28
|
opencode # models appear as m365/*
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
`setup` writes only a plugin reference. The provider, the model list
|
|
32
|
-
|
|
31
|
+
`setup` writes only a plugin reference. The provider, the model list and the default
|
|
32
|
+
model are all registered by the plugin at startup.
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
[opencode
|
|
34
|
+
Needs **opencode 2** — from 2.0.0 the major version tracks it. On opencode 1, stay on
|
|
35
|
+
0.4.x — see [opencode 1](#opencode-1).
|
|
36
36
|
|
|
37
37
|
## The thing you need to know first
|
|
38
38
|
|
|
@@ -66,9 +66,7 @@ work and do not (verified against 1.18.18, and the reason the architecture is wh
|
|
|
66
66
|
array, but the request that reaches the provider still carries the original prompt.
|
|
67
67
|
Setting `agent.<name>.prompt` from the `config` hook is ignored the same way.
|
|
68
68
|
|
|
69
|
-
The proxy sees the final request, so it is the one place the trim reliably lands.
|
|
70
|
-
plugin still sets `config.tools` as a declaration of intent, in case a future version
|
|
71
|
-
honours it.
|
|
69
|
+
The proxy sees the final request, so it is the one place the trim reliably lands.
|
|
72
70
|
|
|
73
71
|
What gets dropped:
|
|
74
72
|
|
|
@@ -116,55 +114,49 @@ warning and carries on.
|
|
|
116
114
|
|
|
117
115
|
## opencode 2
|
|
118
116
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
117
|
+
This is an opencode 2 plugin (`@opencode/cli`, `@opencode/plugin`): its default export
|
|
118
|
+
is `{ id, setup }`. A local checkout is referenced by its **directory** — opencode 2
|
|
119
|
+
drops a file path with `configured plugin path must be a directory`, and since it
|
|
120
|
+
swallows plugin load failures, nothing else tells you. `opencode-m365 setup` writes the
|
|
121
|
+
right reference for you.
|
|
123
122
|
|
|
124
|
-
|
|
123
|
+
Everything in [Where the trimming happens](#where-the-trimming-happens-and-why) still
|
|
124
|
+
lives in the proxy. opencode 2 does offer hooks where opencode 1's were dead
|
|
125
|
+
(`ctx.tool.transform`, `session.hook("context")`); neither has been measured against a
|
|
126
|
+
live tenant, so the proxy stays the enforcement point.
|
|
125
127
|
|
|
126
|
-
|
|
127
|
-
|---|---|---|
|
|
128
|
-
| config key | `plugin` | `plugins` |
|
|
129
|
-
| entry form | `[spec, options]` | `{ package, options }` |
|
|
130
|
-
| local reference | the built entrypoint | **a directory** — 2.0.11 drops a file path with `configured plugin path must be a directory`, and since it swallows plugin load failures, nothing else tells you |
|
|
131
|
-
| provider registration | `config.provider.m365` | `ctx.provider.transform` → `editor.add` |
|
|
132
|
-
| openai-compatible driver | installs `@ai-sdk/openai-compatible` | bundled as `@opencode/ai/providers/openai-compatible` |
|
|
133
|
-
| title generation | `small_model` | no such setting — see below |
|
|
134
|
-
|
|
135
|
-
`opencode-m365 setup` writes **both** keys, with the right reference for each. Each
|
|
136
|
-
version silently drops the key it does not know, so the one file serves either.
|
|
128
|
+
### opencode 1
|
|
137
129
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
130
|
+
opencode 1 is no longer supported. **0.4.x is the last release that loads there** — pin
|
|
131
|
+
it with `npm install -g opencode-m365-copilot@0.4`. 2.0.0 and later under opencode 1
|
|
132
|
+
fail to load with `must default export an object with server()`. Re-running
|
|
133
|
+
`opencode-m365 setup` removes this plugin's entry from opencode 1's `plugin` key, keeping
|
|
134
|
+
any options you set on it, and leaves other plugins' entries alone.
|
|
142
135
|
|
|
143
136
|
### Verified how far
|
|
144
137
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
The opencode 2 path is covered by unit tests against a stand-in context, and its catalog
|
|
153
|
-
records are checked against the real `@opencode/plugin` schema constructors. It has
|
|
154
|
-
**not** yet been exercised against a live opencode 2 end to end.
|
|
138
|
+
Against a real opencode 2.2.5, end to end, with the proxy running against the offline
|
|
139
|
+
stub rather than Microsoft: the plugin loads from a directory, registers all 21 models,
|
|
140
|
+
an attached image is uploaded and attached to the turn, and the session title is
|
|
141
|
+
answered locally — one chat turn reaches the backend, not two. The catalog records are
|
|
142
|
+
also checked against the real `@opencode/plugin` schema constructors in the test suite.
|
|
143
|
+
Nothing here has been run against a live M365 tenant.
|
|
155
144
|
|
|
156
145
|
## Configuration
|
|
157
146
|
|
|
158
147
|
```jsonc
|
|
159
148
|
{
|
|
160
|
-
"
|
|
161
|
-
"
|
|
162
|
-
"
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
149
|
+
"plugins": [{
|
|
150
|
+
"package": "opencode-m365-copilot",
|
|
151
|
+
"options": {
|
|
152
|
+
"lean": true, // trim the toolset (default: true)
|
|
153
|
+
"leanSystemPrompt": false, // replace opencode's prose prompt (default: false)
|
|
154
|
+
"setDefaultModel": true, // set `model` if you have not (default: true)
|
|
155
|
+
"setSmallModel": true, // answer session titles locally (default: true)
|
|
156
|
+
"baseUrl": null, // use an already-running proxy instead of an in-process one
|
|
157
|
+
"apiKey": null // that proxy's secret (or export M365_PROXY_KEY instead)
|
|
158
|
+
}
|
|
159
|
+
}]
|
|
168
160
|
}
|
|
169
161
|
```
|
|
170
162
|
|
|
@@ -173,20 +165,18 @@ hands it to opencode itself. Only a standalone `opencode-m365 serve` proxy needs
|
|
|
173
165
|
`serve` prints its key, or takes a fixed one from `M365_PROXY_KEY`. Either put that key
|
|
174
166
|
in `apiKey`, or export the same `M365_PROXY_KEY` to opencode and leave `apiKey` out.
|
|
175
167
|
|
|
176
|
-
|
|
168
|
+
### Why session titles are answered locally
|
|
177
169
|
|
|
178
|
-
|
|
170
|
+
opencode titles every new session with a model call on your main model, which on M365
|
|
171
|
+
would open a **second conversation** per session. The account-level throttle counts
|
|
172
|
+
conversations started, not messages, so that is the fastest way to get throttled.
|
|
179
173
|
|
|
180
|
-
opencode
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
same guarantee is reached differently: the plugin marks the title request on a header
|
|
187
|
-
(`x-m365-request-kind: title`) and the proxy answers it locally. Compaction and
|
|
188
|
-
generation are left on the real model — they are real work, and only titling opens the
|
|
189
|
-
extra conversation. `setSmallModel` controls both mechanisms.
|
|
174
|
+
opencode 2 has no `small_model` setting, and its title hook exposes the model read-only,
|
|
175
|
+
so the plugin marks the title request on a header (`x-m365-request-kind: title`) and the
|
|
176
|
+
proxy answers it locally, without opening a connection. Compaction and generation stay
|
|
177
|
+
on the real model — they are real work, and only titling opens the extra conversation.
|
|
178
|
+
`setSmallModel` turns this off; the name dates from opencode 1, where it set
|
|
179
|
+
`small_model`. Any OpenAI client can also select `m365/local-title` by id.
|
|
190
180
|
|
|
191
181
|
## Models
|
|
192
182
|
|
|
@@ -205,6 +195,42 @@ A non-default tone (Claude, the reasoning tones) only takes effect when **no** a
|
|
|
205
195
|
attached — with one, M365 silently routes to GPT regardless. The proxy therefore attaches
|
|
206
196
|
the agent only on turns that carry tools, so plain chat reaches the model the tone selects.
|
|
207
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
|
+
|
|
208
234
|
## Authentication
|
|
209
235
|
|
|
210
236
|
Sign-in is a CLI concern, never the plugin's: the plugin only refreshes silently and asks
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ as createLogger, b as AGENT_FILE, d as POWERPLATFORM_SCOPE, l as BAP_SCOPE, y as writePrivateFile } from "./server-
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
1
|
+
import { _ as createLogger, b as AGENT_FILE, d as POWERPLATFORM_SCOPE, l as BAP_SCOPE, y as writePrivateFile } from "./server-CRfZjKho.mjs";
|
|
3
2
|
import { readFileSync } from "node:fs";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
4
|
// src/agent.ts
|
|
5
5
|
/**
|
|
6
6
|
* The Copilot Studio declarative agent.
|
package/dist/cli.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { C as SECRETS_FILE,
|
|
3
|
-
import { t as getOrCreateAgent } from "./agent-
|
|
4
|
-
import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
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";
|
|
5
4
|
import { homedir } from "node:os";
|
|
6
5
|
import { dirname, join, resolve } from "node:path";
|
|
6
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
// src/cli.ts
|
|
9
9
|
/**
|
|
@@ -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-
|
|
49
|
+
const { login } = await import("./login-j65WhI4A.mjs");
|
|
50
50
|
const interactive = args.includes("--interactive");
|
|
51
51
|
try {
|
|
52
52
|
const account = await login({
|
|
@@ -71,7 +71,7 @@ async function doSetup(args) {
|
|
|
71
71
|
const pluginRef = local ? resolve(dist, "plugin.mjs") : "opencode-m365-copilot";
|
|
72
72
|
const pluginDir = local ? resolve(dist, "..") : pluginRef;
|
|
73
73
|
if (local && !existsSync(pluginRef)) {
|
|
74
|
-
console.error(`No build at ${pluginRef}. Run \`
|
|
74
|
+
console.error(`No build at ${pluginRef}. Run \`npm run build\` first.`);
|
|
75
75
|
process.exitCode = 1;
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
@@ -93,7 +93,8 @@ async function doSetup(args) {
|
|
|
93
93
|
const hadConfig = existsSync(OPENCODE_CONFIG);
|
|
94
94
|
if (hadConfig) copyFileSync(OPENCODE_CONFIG, backup);
|
|
95
95
|
writeFileSync(OPENCODE_CONFIG, `${JSON.stringify(merged, null, 2)}\n`);
|
|
96
|
-
console.log(`Added ${
|
|
96
|
+
console.log(`Added ${pluginDir} to ${OPENCODE_CONFIG}`);
|
|
97
|
+
if (existing.plugin !== void 0 && JSON.stringify(existing.plugin) !== JSON.stringify(merged.plugin)) console.log(`(removed this plugin's opencode 1 entry: opencode 1 is no longer supported)`);
|
|
97
98
|
if (hadConfig) console.log(`(previous version saved as ${backup})`);
|
|
98
99
|
console.log(`\nThe plugin registers the provider itself on startup, so there is nothing`);
|
|
99
100
|
console.log(`else to configure. Models appear as ${PROVIDER_ID}/<model>, defaulting to`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as
|
|
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,6 +1,6 @@
|
|
|
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-
|
|
2
|
-
import { chmodSync, existsSync, readFileSync, statSync } from "node:fs";
|
|
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";
|
|
3
2
|
import { join } from "node:path";
|
|
3
|
+
import { chmodSync, existsSync, readFileSync, statSync } from "node:fs";
|
|
4
4
|
// src/login.ts
|
|
5
5
|
/**
|
|
6
6
|
* Interactive / automated sign-in. Loaded only by the CLI, never by the plugin.
|
|
@@ -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-
|
|
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.d.mts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
import { Plugin } from "@opencode/plugin";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare const _default: {
|
|
5
|
-
id: string;
|
|
6
|
-
setup: (context: Plugin.Context) => Promise<Plugin.Cleanup | void> | Plugin.Cleanup | void;
|
|
7
|
-
server: typeof server;
|
|
8
|
-
};
|
|
9
|
-
export { _default as default };
|
|
2
|
+
declare const definition: Plugin.Plugin;
|
|
3
|
+
export { definition as default };
|
package/dist/plugin.mjs
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import { t as getOrCreateAgent } from "./agent-
|
|
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
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* loaded, how it registers a provider — but they agree completely about what this
|
|
9
|
-
* plugin *does*: stand up the OpenAI-compatible proxy, and hand back the URL it is
|
|
10
|
-
* listening on. That is all this module is.
|
|
5
|
+
* What the plugin stands on: the OpenAI-compatible proxy, started in-process (or an
|
|
6
|
+
* external one, when `baseUrl` is set), and the URL and secret it listens with. The
|
|
7
|
+
* opencode-facing half — provider registration, the title hook — is `plugin-v2.ts`.
|
|
11
8
|
*
|
|
12
9
|
* Auth is deliberately not here: the plugin only refreshes silently, and tells the
|
|
13
10
|
* user to run `opencode-m365 login` if it cannot. Launching a browser underneath a
|
|
@@ -77,24 +74,6 @@ async function startRuntime(rawOptions) {
|
|
|
77
74
|
close: () => proxy.close()
|
|
78
75
|
};
|
|
79
76
|
}
|
|
80
|
-
// src/plugin-v1.ts
|
|
81
|
-
async function server(input, rawOptions) {
|
|
82
|
-
const runtime = await startRuntime(rawOptions);
|
|
83
|
-
await input.client.app.log({ body: {
|
|
84
|
-
service: "m365-copilot",
|
|
85
|
-
level: "info",
|
|
86
|
-
message: `Microsoft 365 Copilot ready at ${runtime.baseUrl}`,
|
|
87
|
-
extra: { lean: runtime.options.lean }
|
|
88
|
-
} }).catch(() => {});
|
|
89
|
-
return {
|
|
90
|
-
async config(config) {
|
|
91
|
-
applyPluginConfig(config, runtime, runtime.options);
|
|
92
|
-
},
|
|
93
|
-
async dispose() {
|
|
94
|
-
await runtime.close();
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
77
|
// src/plugin-v2.ts
|
|
99
78
|
const log = createLogger("plugin");
|
|
100
79
|
const setup = async (ctx) => {
|
|
@@ -125,9 +104,9 @@ const setup = async (ctx) => {
|
|
|
125
104
|
log.info(`Microsoft 365 Copilot ready at ${runtime.baseUrl}`);
|
|
126
105
|
return () => runtime.close();
|
|
127
106
|
};
|
|
128
|
-
|
|
107
|
+
// src/plugin.ts
|
|
108
|
+
const definition = {
|
|
129
109
|
id: PLUGIN_ID,
|
|
130
|
-
setup
|
|
131
|
-
server
|
|
110
|
+
setup
|
|
132
111
|
};
|
|
133
|
-
export {
|
|
112
|
+
export { definition as default };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
3
|
-
import { appendFileSync, chmodSync, closeSync, constants, mkdirSync, openSync, readFileSync, realpathSync, writeFileSync, writeSync } from "node:fs";
|
|
4
2
|
import { homedir } from "node:os";
|
|
5
3
|
import { dirname, join, parse, resolve, sep } from "node:path";
|
|
4
|
+
import { appendFileSync, chmodSync, closeSync, constants, mkdirSync, openSync, readFileSync, realpathSync, writeFileSync, writeSync } from "node:fs";
|
|
5
|
+
import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
6
6
|
import { createServer } from "node:http";
|
|
7
7
|
// \0rolldown/runtime.js
|
|
8
8
|
var __create = Object.create;
|
|
@@ -42,10 +42,11 @@ const OUTPUT_TOKENS = 128e3;
|
|
|
42
42
|
* A synthetic model served entirely by our own proxy — it never opens a WebSocket
|
|
43
43
|
* to M365.
|
|
44
44
|
*
|
|
45
|
-
* This exists because
|
|
46
|
-
*
|
|
45
|
+
* This exists because a harness titles each session with a model call, by default on
|
|
46
|
+
* the main model. That would open a *second* M365 conversation for every session,
|
|
47
47
|
* which is precisely the thread-rate throttle signature: the limit tracks
|
|
48
|
-
* conversations started, not messages.
|
|
48
|
+
* conversations started, not messages. Any client can select this model by id; the
|
|
49
|
+
* opencode plugin instead marks its title requests so the proxy answers them here.
|
|
49
50
|
*/
|
|
50
51
|
const LOCAL_TITLE_MODEL = "local-title";
|
|
51
52
|
/**
|
|
@@ -59,6 +60,8 @@ const LOCAL_TITLE_MODEL = "local-title";
|
|
|
59
60
|
*/
|
|
60
61
|
const DEFAULT_MODEL = "gpt-5.5-think-deeper";
|
|
61
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),
|
|
62
65
|
m("gpt-5.6-think-deeper", "GPT-5.6 (Think Deeper)", "Gpt_5_6_Reasoning", true),
|
|
63
66
|
m("gpt-5.5-think-deeper", "GPT-5.5 (Think Deeper)", "Gpt_5_5_Reasoning", true),
|
|
64
67
|
m("gpt-5.5", "GPT-5.5", "Gpt_5_5_Chat", false),
|
|
@@ -81,12 +84,13 @@ const MODELS = [
|
|
|
81
84
|
m("gpt-5.2-think-deeper", "GPT-5.2 (Think Deeper)", "Gpt_5_2_Reasoning", true),
|
|
82
85
|
m(LOCAL_TITLE_MODEL, "Local titler (no M365 call)", null, false)
|
|
83
86
|
];
|
|
84
|
-
function m(id, name, tone, reasoning) {
|
|
87
|
+
function m(id, name, tone, reasoning, grounded = false) {
|
|
85
88
|
return {
|
|
86
89
|
id,
|
|
87
90
|
name,
|
|
88
91
|
tone,
|
|
89
92
|
reasoning,
|
|
93
|
+
grounded,
|
|
90
94
|
limit: {
|
|
91
95
|
context: CONTEXT_TOKENS,
|
|
92
96
|
output: OUTPUT_TOKENS
|
|
@@ -457,10 +461,8 @@ const PROVIDER_ID = "m365";
|
|
|
457
461
|
* The plugin's own id.
|
|
458
462
|
*
|
|
459
463
|
* opencode 2 requires one, scopes the plugin's storage by it, and names the plugin
|
|
460
|
-
* by it in `plugin list` and diagnostics.
|
|
461
|
-
*
|
|
462
|
-
* that they do. Changing it is not cosmetic: it orphans anything stored under the old
|
|
463
|
-
* one.
|
|
464
|
+
* by it in `plugin list` and diagnostics. Changing it is not cosmetic: it orphans
|
|
465
|
+
* anything stored under the old one.
|
|
464
466
|
*/
|
|
465
467
|
const PLUGIN_ID = "m365-copilot";
|
|
466
468
|
/**
|
|
@@ -482,33 +484,13 @@ const LEAN_TOOLS = [
|
|
|
482
484
|
"grep"
|
|
483
485
|
];
|
|
484
486
|
/**
|
|
485
|
-
* opencode built-ins we switch off in lean mode.
|
|
486
|
-
*
|
|
487
|
-
* Each one is a tool block in the injected prompt, and the count is what trips the
|
|
488
|
-
* filter. `glob`/`grep` overlap and `bash` can do both; `webfetch`/`websearch` are
|
|
489
|
-
* rarely load-bearing for a coding turn; `todowrite`/`question`/`skill` are harness
|
|
490
|
-
* ergonomics rather than capability.
|
|
491
|
-
*/
|
|
492
|
-
const DISABLED_TOOLS = [
|
|
493
|
-
"glob",
|
|
494
|
-
"lsp",
|
|
495
|
-
"patch",
|
|
496
|
-
"skill",
|
|
497
|
-
"todowrite",
|
|
498
|
-
"todoread",
|
|
499
|
-
"webfetch",
|
|
500
|
-
"websearch",
|
|
501
|
-
"question",
|
|
502
|
-
"task"
|
|
503
|
-
];
|
|
504
|
-
/**
|
|
505
487
|
* Cut a harness's toolset down to something M365 will engage with.
|
|
506
488
|
*
|
|
507
|
-
* This is the enforcement point
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
* the
|
|
489
|
+
* This is the enforcement point. opencode 1's own `tools` config was resolved into the
|
|
490
|
+
* config but **not applied to the request** (verified against 1.18.18: a config
|
|
491
|
+
* disabling eight tools still produced a request offering all nine). opencode 2's
|
|
492
|
+
* `tool.transform` has not been measured against a live tenant. The proxy sees the
|
|
493
|
+
* final request whatever the harness does, so the trim lives here.
|
|
512
494
|
*
|
|
513
495
|
* Two rules, in order:
|
|
514
496
|
* 1. Keep the tools we recognise as load-bearing for a coding loop.
|
|
@@ -568,47 +550,6 @@ function resolveOptions(raw) {
|
|
|
568
550
|
apiKey: typeof options.apiKey === "string" && options.apiKey !== "" ? options.apiKey : void 0
|
|
569
551
|
};
|
|
570
552
|
}
|
|
571
|
-
/** `{ bash: true, ..., webfetch: false, ... }` — opencode's `tools` config shape. */
|
|
572
|
-
function buildToolProfile() {
|
|
573
|
-
const profile = {};
|
|
574
|
-
for (const tool of LEAN_TOOLS) profile[tool] = true;
|
|
575
|
-
for (const tool of DISABLED_TOOLS) profile[tool] = false;
|
|
576
|
-
return profile;
|
|
577
|
-
}
|
|
578
|
-
/** The `provider.m365` entry pointing opencode at our local OpenAI-compatible proxy. */
|
|
579
|
-
function buildProviderConfig(baseUrl, apiKey) {
|
|
580
|
-
const models = {};
|
|
581
|
-
for (const model of MODELS) {
|
|
582
|
-
const local = isLocalModel(model.id);
|
|
583
|
-
models[model.id] = {
|
|
584
|
-
name: model.name,
|
|
585
|
-
tool_call: !local,
|
|
586
|
-
reasoning: model.reasoning,
|
|
587
|
-
attachment: !local,
|
|
588
|
-
modalities: {
|
|
589
|
-
input: inputModalities(model.id),
|
|
590
|
-
output: ["text"]
|
|
591
|
-
},
|
|
592
|
-
limit: model.limit,
|
|
593
|
-
cost: {
|
|
594
|
-
input: 0,
|
|
595
|
-
output: 0,
|
|
596
|
-
cache_read: 0,
|
|
597
|
-
cache_write: 0
|
|
598
|
-
}
|
|
599
|
-
};
|
|
600
|
-
}
|
|
601
|
-
return {
|
|
602
|
-
npm: "@ai-sdk/openai-compatible",
|
|
603
|
-
name: "Microsoft 365 Copilot",
|
|
604
|
-
options: {
|
|
605
|
-
baseURL: baseUrl,
|
|
606
|
-
apiKey,
|
|
607
|
-
timeout: 9e5
|
|
608
|
-
},
|
|
609
|
-
models
|
|
610
|
-
};
|
|
611
|
-
}
|
|
612
553
|
/** The opencode 2 provider record pointing at our local OpenAI-compatible proxy. */
|
|
613
554
|
function buildProviderInfo(baseUrl, apiKey) {
|
|
614
555
|
return {
|
|
@@ -668,25 +609,6 @@ function buildModelInfos() {
|
|
|
668
609
|
function inputModalities(modelId) {
|
|
669
610
|
return isLocalModel(modelId) ? ["text"] : ["text", "image"];
|
|
670
611
|
}
|
|
671
|
-
/**
|
|
672
|
-
* Mutate opencode's in-memory config during the plugin's `config` hook.
|
|
673
|
-
*
|
|
674
|
-
* Deliberately additive: anything the user set explicitly wins. We are a plugin
|
|
675
|
-
* making someone else's config work, not the owner of it.
|
|
676
|
-
*/
|
|
677
|
-
function applyPluginConfig(config, endpoint, options) {
|
|
678
|
-
config.provider ??= {};
|
|
679
|
-
config.provider[PROVIDER_ID] = buildProviderConfig(endpoint.baseUrl, endpoint.apiKey);
|
|
680
|
-
if (options.setDefaultModel && !config.model) config.model = `${PROVIDER_ID}/${DEFAULT_MODEL}`;
|
|
681
|
-
if (options.setSmallModel && !config.small_model) config.small_model = `${PROVIDER_ID}/${LOCAL_TITLE_MODEL}`;
|
|
682
|
-
if (options.lean && usesOurProvider(config)) config.tools = {
|
|
683
|
-
...buildToolProfile(),
|
|
684
|
-
...config.tools ?? {}
|
|
685
|
-
};
|
|
686
|
-
}
|
|
687
|
-
function usesOurProvider(config) {
|
|
688
|
-
return typeof config.model === "string" && config.model.startsWith(`m365/`);
|
|
689
|
-
}
|
|
690
612
|
/** The npm name this package publishes under — what a checkout's package.json says. */
|
|
691
613
|
const PACKAGE_NAME = "opencode-m365-copilot";
|
|
692
614
|
/** Every option key this plugin reads; anything else belongs to another plugin. */
|
|
@@ -698,17 +620,36 @@ const OUR_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
|
698
620
|
"baseUrl",
|
|
699
621
|
"apiKey"
|
|
700
622
|
]);
|
|
623
|
+
/**
|
|
624
|
+
* Merge our plugin reference into an on-disk `opencode.json`, non-destructively.
|
|
625
|
+
*
|
|
626
|
+
* Writes opencode 2's `plugins` key. For an npm install the reference is the package
|
|
627
|
+
* name. For a local checkout it is `pluginDir`, the checkout directory: opencode 2
|
|
628
|
+
* drops a file path with `configured plugin path must be a directory` (measured
|
|
629
|
+
* against 2.0.11), and since it swallows plugin load failures nothing else says so.
|
|
630
|
+
*
|
|
631
|
+
* `pluginRef` is how older versions of setup referenced us in opencode 1's `plugin`
|
|
632
|
+
* key — the package name, or the built `dist/plugin.mjs`. It is used only to find
|
|
633
|
+
* that entry and take it out: this version no longer loads under opencode 1, which
|
|
634
|
+
* would throw on it. Options on it carry over when the `plugins` entry has none, so
|
|
635
|
+
* a `{ "lean": false }` set for opencode 1 is not lost. Other plugins' entries in
|
|
636
|
+
* `plugin` stay, and the key is removed only if we emptied it.
|
|
637
|
+
*/
|
|
701
638
|
function mergeOpencodeConfig(existing, opts) {
|
|
702
639
|
const merged = { ...existing };
|
|
703
640
|
merged.$schema ??= "https://opencode.ai/config.json";
|
|
704
641
|
const pluginDir = opts.pluginDir ?? opts.pluginRef;
|
|
705
642
|
const inspect = opts.inspect ?? (() => ({ exists: false }));
|
|
706
|
-
const
|
|
707
|
-
const
|
|
708
|
-
|
|
709
|
-
|
|
643
|
+
const legacy = withOurRef(merged.plugin, opts.pluginRef, inspect);
|
|
644
|
+
const current = withOurRef(merged.plugins, pluginDir, inspect, legacy.dropped);
|
|
645
|
+
if (legacy.dropped.length > 0) {
|
|
646
|
+
if (legacy.kept.length > 0) merged.plugin = legacy.kept;
|
|
647
|
+
else delete merged.plugin;
|
|
648
|
+
}
|
|
649
|
+
const options = current.options ?? legacy.options;
|
|
650
|
+
merged.plugins = [...current.kept, options ? {
|
|
710
651
|
package: pluginDir,
|
|
711
|
-
options
|
|
652
|
+
options
|
|
712
653
|
} : pluginDir];
|
|
713
654
|
return merged;
|
|
714
655
|
}
|
|
@@ -739,7 +680,7 @@ function withOurRef(existing, pluginRef, inspect, containing = []) {
|
|
|
739
680
|
...options ? { options } : {}
|
|
740
681
|
};
|
|
741
682
|
}
|
|
742
|
-
/** The options out of any entry form
|
|
683
|
+
/** The options out of any entry form — `[spec, options]` or `{ package, options }`. */
|
|
743
684
|
function optionsOf(entry) {
|
|
744
685
|
const raw = Array.isArray(entry) ? entry[1] : entry && typeof entry === "object" && "options" in entry ? entry.options : void 0;
|
|
745
686
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
|
|
@@ -752,7 +693,7 @@ function isWithin(dir, path) {
|
|
|
752
693
|
const prefix = dir.endsWith("/") ? dir : `${dir}/`;
|
|
753
694
|
return path.startsWith(prefix);
|
|
754
695
|
}
|
|
755
|
-
/** The package-or-path out of any entry form
|
|
696
|
+
/** The package-or-path out of any entry form, including opencode 1's. */
|
|
756
697
|
function specifierOf(entry) {
|
|
757
698
|
if (typeof entry === "string") return entry;
|
|
758
699
|
if (Array.isArray(entry)) return String(entry[0] ?? "");
|
|
@@ -1008,7 +949,7 @@ function createTokenClient(options = {}) {
|
|
|
1008
949
|
const cache = /* @__PURE__ */ new Map();
|
|
1009
950
|
async function client() {
|
|
1010
951
|
if (app) return app;
|
|
1011
|
-
const { PublicClientApplication } = await import("./dist-
|
|
952
|
+
const { PublicClientApplication } = await import("./dist-DnyIX7Da.mjs");
|
|
1012
953
|
app = new PublicClientApplication({
|
|
1013
954
|
auth: {
|
|
1014
955
|
clientId: CLIENT_ID,
|
|
@@ -4793,6 +4734,19 @@ const VARIANTS = [
|
|
|
4793
4734
|
"feature.EnableSydneyClientCompliance",
|
|
4794
4735
|
"feature.EnableStreaming"
|
|
4795
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(",");
|
|
4796
4750
|
/** The message types we tell the server we are able to render. */
|
|
4797
4751
|
const ALLOWED_MESSAGE_TYPES = [
|
|
4798
4752
|
"Chat",
|
|
@@ -4828,6 +4782,24 @@ var DisengagedError = class extends Error {
|
|
|
4828
4782
|
}
|
|
4829
4783
|
};
|
|
4830
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
|
+
/**
|
|
4831
4803
|
* One M365 conversation.
|
|
4832
4804
|
*
|
|
4833
4805
|
* Stateful across turns: the conversation and session ids persist so the server keeps
|
|
@@ -4853,7 +4825,7 @@ var CopilotSession = class {
|
|
|
4853
4825
|
if (turn.signal?.aborted) throw abortError();
|
|
4854
4826
|
const token = await this.options.getToken();
|
|
4855
4827
|
const { oid, tid } = decodeJwt(token);
|
|
4856
|
-
const url = this.buildUrl(token, oid, tid);
|
|
4828
|
+
const url = this.buildUrl(token, oid, tid, turn.grounded ?? false);
|
|
4857
4829
|
const { annotations, note } = await this.uploadImages(token, turn);
|
|
4858
4830
|
const message = {
|
|
4859
4831
|
text: note ? `${text}\n\n${note}` : text,
|
|
@@ -4895,18 +4867,28 @@ var CopilotSession = class {
|
|
|
4895
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.)`
|
|
4896
4868
|
};
|
|
4897
4869
|
}
|
|
4898
|
-
buildUrl(token, oid, tid) {
|
|
4899
|
-
|
|
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({
|
|
4900
4885
|
access_token: token,
|
|
4901
4886
|
ConversationId: this.conversationId,
|
|
4902
4887
|
chatsessionid: this.sessionId,
|
|
4903
4888
|
"X-SessionId": this.sessionId,
|
|
4904
4889
|
clientrequestid: randomUUID(),
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
agentHost: "Bizchat.FullScreen",
|
|
4908
|
-
scenario: "OfficeWebIncludedCopilot",
|
|
4909
|
-
variants: VARIANTS
|
|
4890
|
+
...scenarioParams,
|
|
4891
|
+
variants: grounded ? GROUNDED_VARIANTS : VARIANTS
|
|
4910
4892
|
}).toString()}`;
|
|
4911
4893
|
}
|
|
4912
4894
|
/** Drive one turn to completion. */
|
|
@@ -4925,7 +4907,8 @@ var CopilotSession = class {
|
|
|
4925
4907
|
reject(error);
|
|
4926
4908
|
return;
|
|
4927
4909
|
}
|
|
4928
|
-
|
|
4910
|
+
const raw = deltaText.length >= snapshotText.length ? deltaText : snapshotText;
|
|
4911
|
+
result.text = turn.grounded ? cleanAnswer(raw) : raw;
|
|
4929
4912
|
resolve(result);
|
|
4930
4913
|
};
|
|
4931
4914
|
const onAbort = () => {
|
|
@@ -5013,20 +4996,35 @@ var CopilotSession = class {
|
|
|
5013
4996
|
const argument = {
|
|
5014
4997
|
message,
|
|
5015
4998
|
tone: turn.tone ?? "magic",
|
|
5016
|
-
source: "officeweb",
|
|
4999
|
+
source: turn.grounded ? "owahub" : "officeweb",
|
|
5017
5000
|
streamingMode: "ConciseWithPadding",
|
|
5018
5001
|
isStartOfSession: this.turnIndex === 0,
|
|
5019
5002
|
conversationId: this.conversationId,
|
|
5020
5003
|
allowedMessageTypes: ALLOWED_MESSAGE_TYPES,
|
|
5021
5004
|
optionsSets: [],
|
|
5022
|
-
clientInfo: {
|
|
5005
|
+
clientInfo: turn.grounded ? {
|
|
5006
|
+
clientPlatform: "OwaHub-web",
|
|
5007
|
+
clientAppName: "OwaHub",
|
|
5008
|
+
clientAppType: "Web",
|
|
5009
|
+
productEntryPoint: "Email"
|
|
5010
|
+
} : {
|
|
5023
5011
|
clientPlatform: "mcmcopilot-web",
|
|
5024
5012
|
clientAppName: "Office",
|
|
5025
5013
|
clientAppVersion: "1.0.0"
|
|
5026
5014
|
},
|
|
5027
5015
|
traceId: randomUUID()
|
|
5028
5016
|
};
|
|
5029
|
-
if (turn.
|
|
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) {
|
|
5030
5028
|
argument.threadLevelGptId = {
|
|
5031
5029
|
id: turn.agentId,
|
|
5032
5030
|
source: "MOS3"
|
|
@@ -5063,6 +5061,7 @@ var CopilotSession = class {
|
|
|
5063
5061
|
log$1.info("sending turn", trunc({
|
|
5064
5062
|
tone: argument.tone,
|
|
5065
5063
|
agent: Boolean(turn.agentId),
|
|
5064
|
+
grounded: Boolean(turn.grounded),
|
|
5066
5065
|
images: outgoing.annotations.length,
|
|
5067
5066
|
text
|
|
5068
5067
|
}));
|
|
@@ -10781,7 +10780,7 @@ const TITLE_INSTRUCTION = /generate|summar|title|respond with|in a few words|sho
|
|
|
10781
10780
|
/**
|
|
10782
10781
|
* Name a session without spending an M365 conversation on it.
|
|
10783
10782
|
*
|
|
10784
|
-
*
|
|
10783
|
+
* A harness titles each session on the main model by default, which would open a second
|
|
10785
10784
|
* conversation for every session — and the throttle counts conversations started, not
|
|
10786
10785
|
* messages. This is not as good as a model-written title; it is free, and it keeps
|
|
10787
10786
|
* the account out of the throttle.
|
|
@@ -11000,21 +10999,23 @@ async function runTurn(request, response, context, body, conversation, model, to
|
|
|
11000
10999
|
getToken: context.deps.getToken,
|
|
11001
11000
|
...context.deps.endpoint ? { endpoint: context.deps.endpoint } : {}
|
|
11002
11001
|
});
|
|
11002
|
+
const effectiveTools = model.grounded ? [] : tools;
|
|
11003
11003
|
const images = collectImages(body.messages, conversation.sentMessageCount);
|
|
11004
|
-
const prompt = buildTurnPrompt(body.messages,
|
|
11005
|
-
const agent =
|
|
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;
|
|
11006
11006
|
const abort = new AbortController();
|
|
11007
11007
|
request.on("close", () => {
|
|
11008
11008
|
if (!response.writableEnded) abort.abort();
|
|
11009
11009
|
});
|
|
11010
11010
|
const streaming = body.stream === true;
|
|
11011
11011
|
const streamId = `chatcmpl-${randomUUID()}`;
|
|
11012
|
-
const canStreamText = streaming &&
|
|
11012
|
+
const canStreamText = streaming && effectiveTools.length === 0 && !model.grounded;
|
|
11013
11013
|
if (streaming) startSse(response);
|
|
11014
11014
|
try {
|
|
11015
11015
|
const result = await conversation.session.run(prompt, {
|
|
11016
11016
|
...model.tone ? { tone: model.tone } : {},
|
|
11017
11017
|
agentId: agent,
|
|
11018
|
+
...model.grounded ? { grounded: true } : {},
|
|
11018
11019
|
signal: abort.signal,
|
|
11019
11020
|
...images.length > 0 ? { images } : {},
|
|
11020
11021
|
...canStreamText ? { onDelta: (chunk) => response.write(streamChunk(streamId, model.id, { content: chunk })) } : {}
|
|
@@ -11023,14 +11024,14 @@ async function runTurn(request, response, context, body, conversation, model, to
|
|
|
11023
11024
|
if (!streaming) {
|
|
11024
11025
|
sendJson(response, 200, buildCompletion(result, {
|
|
11025
11026
|
model: model.id,
|
|
11026
|
-
tools,
|
|
11027
|
+
tools: effectiveTools,
|
|
11027
11028
|
allowMultiple: context.deps.allowMultiTool ?? false
|
|
11028
11029
|
}));
|
|
11029
11030
|
return;
|
|
11030
11031
|
}
|
|
11031
|
-
finishStream(response, streamId, model.id, result,
|
|
11032
|
+
finishStream(response, streamId, model.id, result, effectiveTools, canStreamText, context.deps.allowMultiTool ?? false);
|
|
11032
11033
|
} catch (error) {
|
|
11033
|
-
handleTurnFailure(response, error, streaming,
|
|
11034
|
+
handleTurnFailure(response, error, streaming, effectiveTools.length);
|
|
11034
11035
|
}
|
|
11035
11036
|
}
|
|
11036
11037
|
/** Emit the closing frames of a streamed turn. */
|
|
@@ -11137,4 +11138,4 @@ async function readBody(request, limit) {
|
|
|
11137
11138
|
}
|
|
11138
11139
|
return Buffer.concat(chunks).toString("utf8");
|
|
11139
11140
|
}
|
|
11140
|
-
export {
|
|
11141
|
+
export { DEFAULT_MODEL as A, SECRETS_FILE as C, buildProviderInfo as D, buildModelInfos as E, __toESM as F, isLocalModel as M, __commonJSMin as N, mergeOpencodeConfig as O, __require as P, CONFIG_DIR as S, PROVIDER_ID as T, createLogger as _, startServer as a, AGENT_FILE as b, AUTHORITY as c, POWERPLATFORM_SCOPE as d, REDIRECT_URI as f, createTokenClient as g, createCachePlugin as h, generateApiKey as i, LOCAL_TITLE_MODEL as j, resolveOptions as k, BAP_SCOPE as l, authCodeFromUrl as m, DEFAULT_MAX_BODY_BYTES as n, object as o, SYDNEY_SCOPES as p, SESSION_ID_HEADER as r, string as s, AUX_REQUEST_KIND_HEADER as t, CLIENT_ID as u, ensurePrivateDir as v, PLUGIN_ID as w, CACHE_FILE as x, writePrivateFile as y };
|
package/dist/server.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as AUX_REQUEST_KIND_HEADER, n as DEFAULT_MAX_BODY_BYTES,
|
|
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": "
|
|
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",
|
|
@@ -38,7 +38,6 @@
|
|
|
38
38
|
"zod": "^4.3.6"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@opencode-ai/plugin": "^1.18.18",
|
|
42
41
|
"@opencode/plugin": "^2.2.5",
|
|
43
42
|
"@types/node": "^26.2.0",
|
|
44
43
|
"@types/ws": "^8.18.1",
|
|
@@ -64,19 +63,19 @@
|
|
|
64
63
|
"url": "git+https://github.com/chrischall/opencode-copilot-plugin.git"
|
|
65
64
|
},
|
|
66
65
|
"peerDependencies": {
|
|
67
|
-
"@opencode-ai/plugin": ">=1.18.0",
|
|
68
66
|
"@opencode/plugin": ">=2.0.0",
|
|
69
67
|
"playwright": ">=1.50.0"
|
|
70
68
|
},
|
|
71
69
|
"peerDependenciesMeta": {
|
|
72
|
-
"@opencode-ai/plugin": {
|
|
73
|
-
"optional": true
|
|
74
|
-
},
|
|
75
70
|
"@opencode/plugin": {
|
|
76
71
|
"optional": true
|
|
77
72
|
},
|
|
78
73
|
"playwright": {
|
|
79
74
|
"optional": true
|
|
80
75
|
}
|
|
76
|
+
},
|
|
77
|
+
"overrides": {
|
|
78
|
+
"glob": "^14.0.3",
|
|
79
|
+
"minimatch": "^11.0.2"
|
|
81
80
|
}
|
|
82
81
|
}
|