opencode-m365-copilot 0.3.5 → 2.0.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 +66 -61
- package/dist/{agent-gllWWI9m.mjs → agent-D4_Eut51.mjs} +3 -4
- package/dist/cli.mjs +8 -8
- package/dist/{dist-CQqDXRJD.mjs → dist-BNzsla4k.mjs} +402 -511
- package/dist/{login-DGT4kHJ1.mjs → login-DcSFLsOo.mjs} +5 -6
- package/dist/{otpauth.node-CBOz_1IZ.mjs → otpauth.node-DaSYf7YH.mjs} +21 -13
- package/dist/plugin.d.mts +2 -12
- package/dist/plugin.mjs +11 -35
- package/dist/{server-CvdPE1oi.mjs → server-IXv9y_4x.mjs} +272 -224
- package/dist/server.d.mts +1 -5
- package/dist/server.mjs +1 -1
- package/package.json +3 -8
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
|
-
|
|
177
|
-
|
|
178
|
-
### Why `small_model` is redirected
|
|
168
|
+
### Why session titles are answered locally
|
|
179
169
|
|
|
180
|
-
opencode
|
|
181
|
-
|
|
182
|
-
conversations started, not messages, so that is the fastest way to get throttled.
|
|
183
|
-
`m365/local-title` model is answered by the proxy itself and never opens a connection.
|
|
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.
|
|
184
173
|
|
|
185
|
-
opencode 2 has no `small_model
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
|
|
@@ -245,6 +235,22 @@ opencode-m365 serve [--port 4141] # run the proxy standalone, for any OpenAI
|
|
|
245
235
|
opencode-m365 doctor # check auth, agent, proxy and opencode wiring
|
|
246
236
|
```
|
|
247
237
|
|
|
238
|
+
## Images
|
|
239
|
+
|
|
240
|
+
Paste an image into opencode (or attach one with `opencode run -f shot.png`) and the
|
|
241
|
+
model sees it. opencode sends it to the proxy as an `image_url` data URL; the proxy
|
|
242
|
+
uploads it to M365 the way the Copilot web client does — `POST /m365Copilot/UploadFile`
|
|
243
|
+
into the same conversation — and the turn points at the upload with an `ImageFile`
|
|
244
|
+
annotation. Only images new to a turn are uploaded: M365 already holds the earlier ones.
|
|
245
|
+
|
|
246
|
+
- If an upload fails, the turn still runs and the model is told the image did not
|
|
247
|
+
arrive, so it says so instead of describing a picture it never saw.
|
|
248
|
+
- Data URLs only. A remote `https://` image URL is not fetched.
|
|
249
|
+
- The local titler model stays text-only; it never reaches M365.
|
|
250
|
+
- The M365 side is implemented from cramt/m365-copilot-proxy's measurement (one model,
|
|
251
|
+
agent attached and not); like the rest of this README's M365 claims, it has not been
|
|
252
|
+
run against a live tenant from here.
|
|
253
|
+
|
|
248
254
|
## Limits
|
|
249
255
|
|
|
250
256
|
- **600 user messages per conversation.** The proxy reuses one conversation per task,
|
|
@@ -265,10 +271,9 @@ opencode-m365 doctor # check auth, agent, proxy and opencode wi
|
|
|
265
271
|
## Development
|
|
266
272
|
|
|
267
273
|
```sh
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
pnpm build
|
|
274
|
+
npm ci
|
|
275
|
+
npm test # typechecks, then runs the suite; no network and no credentials required
|
|
276
|
+
npm run build
|
|
272
277
|
```
|
|
273
278
|
|
|
274
279
|
Tests run against a stub SignalR server (`test/stub-copilot.ts`) that speaks the real
|
|
@@ -1,7 +1,7 @@
|
|
|
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-IXv9y_4x.mjs";
|
|
3
2
|
import { readFileSync } from "node:fs";
|
|
4
|
-
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
// src/agent.ts
|
|
5
5
|
/**
|
|
6
6
|
* The Copilot Studio declarative agent.
|
|
7
7
|
*
|
|
@@ -218,5 +218,4 @@ function writeCache(file, cache) {
|
|
|
218
218
|
log.warn("could not write the agent cache", String(error));
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
|
-
//#endregion
|
|
222
221
|
export { getOrCreateAgent as t };
|
package/dist/cli.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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-IXv9y_4x.mjs";
|
|
3
|
+
import { t as getOrCreateAgent } from "./agent-D4_Eut51.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
|
/**
|
|
10
10
|
* `opencode-m365` — sign in, wire up opencode, and check the plumbing.
|
|
11
11
|
*
|
|
@@ -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-DcSFLsOo.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`);
|
|
@@ -197,5 +198,4 @@ main().catch((error) => {
|
|
|
197
198
|
console.error(error instanceof Error ? error.message : String(error));
|
|
198
199
|
process.exit(1);
|
|
199
200
|
});
|
|
200
|
-
//#endregion
|
|
201
201
|
export {};
|