opencode-m365-copilot 0.4.0 → 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 +47 -57
- package/dist/{agent-CtiM1nN_.mjs → agent-D4_Eut51.mjs} +2 -2
- package/dist/cli.mjs +7 -6
- package/dist/{dist-Dp9sO-mB.mjs → dist-BNzsla4k.mjs} +1 -1
- package/dist/{login-CWvKVY0k.mjs → login-DcSFLsOo.mjs} +3 -3
- package/dist/plugin.d.mts +2 -8
- package/dist/plugin.mjs +9 -30
- package/dist/{server-Cow8-T6p.mjs → server-IXv9y_4x.mjs} +42 -104
- package/dist/server.mjs +1 -1
- package/package.json +1 -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
|
-
|
|
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
|
|
|
@@ -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-IXv9y_4x.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-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
|
/**
|
|
@@ -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`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as
|
|
1
|
+
import { F as __toESM, N as __commonJSMin, P as __require } from "./server-IXv9y_4x.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-IXv9y_4x.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-BNzsla4k.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-IXv9y_4x.mjs";
|
|
2
|
+
import { t as getOrCreateAgent } from "./agent-D4_Eut51.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
|
/**
|
|
@@ -457,10 +458,8 @@ const PROVIDER_ID = "m365";
|
|
|
457
458
|
* The plugin's own id.
|
|
458
459
|
*
|
|
459
460
|
* 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.
|
|
461
|
+
* by it in `plugin list` and diagnostics. Changing it is not cosmetic: it orphans
|
|
462
|
+
* anything stored under the old one.
|
|
464
463
|
*/
|
|
465
464
|
const PLUGIN_ID = "m365-copilot";
|
|
466
465
|
/**
|
|
@@ -482,33 +481,13 @@ const LEAN_TOOLS = [
|
|
|
482
481
|
"grep"
|
|
483
482
|
];
|
|
484
483
|
/**
|
|
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
484
|
* Cut a harness's toolset down to something M365 will engage with.
|
|
506
485
|
*
|
|
507
|
-
* This is the enforcement point
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
* the
|
|
486
|
+
* This is the enforcement point. opencode 1's own `tools` config was resolved into the
|
|
487
|
+
* config but **not applied to the request** (verified against 1.18.18: a config
|
|
488
|
+
* disabling eight tools still produced a request offering all nine). opencode 2's
|
|
489
|
+
* `tool.transform` has not been measured against a live tenant. The proxy sees the
|
|
490
|
+
* final request whatever the harness does, so the trim lives here.
|
|
512
491
|
*
|
|
513
492
|
* Two rules, in order:
|
|
514
493
|
* 1. Keep the tools we recognise as load-bearing for a coding loop.
|
|
@@ -568,47 +547,6 @@ function resolveOptions(raw) {
|
|
|
568
547
|
apiKey: typeof options.apiKey === "string" && options.apiKey !== "" ? options.apiKey : void 0
|
|
569
548
|
};
|
|
570
549
|
}
|
|
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
550
|
/** The opencode 2 provider record pointing at our local OpenAI-compatible proxy. */
|
|
613
551
|
function buildProviderInfo(baseUrl, apiKey) {
|
|
614
552
|
return {
|
|
@@ -668,25 +606,6 @@ function buildModelInfos() {
|
|
|
668
606
|
function inputModalities(modelId) {
|
|
669
607
|
return isLocalModel(modelId) ? ["text"] : ["text", "image"];
|
|
670
608
|
}
|
|
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
609
|
/** The npm name this package publishes under — what a checkout's package.json says. */
|
|
691
610
|
const PACKAGE_NAME = "opencode-m365-copilot";
|
|
692
611
|
/** Every option key this plugin reads; anything else belongs to another plugin. */
|
|
@@ -698,17 +617,36 @@ const OUR_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
|
698
617
|
"baseUrl",
|
|
699
618
|
"apiKey"
|
|
700
619
|
]);
|
|
620
|
+
/**
|
|
621
|
+
* Merge our plugin reference into an on-disk `opencode.json`, non-destructively.
|
|
622
|
+
*
|
|
623
|
+
* Writes opencode 2's `plugins` key. For an npm install the reference is the package
|
|
624
|
+
* name. For a local checkout it is `pluginDir`, the checkout directory: opencode 2
|
|
625
|
+
* drops a file path with `configured plugin path must be a directory` (measured
|
|
626
|
+
* against 2.0.11), and since it swallows plugin load failures nothing else says so.
|
|
627
|
+
*
|
|
628
|
+
* `pluginRef` is how older versions of setup referenced us in opencode 1's `plugin`
|
|
629
|
+
* key — the package name, or the built `dist/plugin.mjs`. It is used only to find
|
|
630
|
+
* that entry and take it out: this version no longer loads under opencode 1, which
|
|
631
|
+
* would throw on it. Options on it carry over when the `plugins` entry has none, so
|
|
632
|
+
* a `{ "lean": false }` set for opencode 1 is not lost. Other plugins' entries in
|
|
633
|
+
* `plugin` stay, and the key is removed only if we emptied it.
|
|
634
|
+
*/
|
|
701
635
|
function mergeOpencodeConfig(existing, opts) {
|
|
702
636
|
const merged = { ...existing };
|
|
703
637
|
merged.$schema ??= "https://opencode.ai/config.json";
|
|
704
638
|
const pluginDir = opts.pluginDir ?? opts.pluginRef;
|
|
705
639
|
const inspect = opts.inspect ?? (() => ({ exists: false }));
|
|
706
|
-
const
|
|
707
|
-
const
|
|
708
|
-
|
|
709
|
-
|
|
640
|
+
const legacy = withOurRef(merged.plugin, opts.pluginRef, inspect);
|
|
641
|
+
const current = withOurRef(merged.plugins, pluginDir, inspect, legacy.dropped);
|
|
642
|
+
if (legacy.dropped.length > 0) {
|
|
643
|
+
if (legacy.kept.length > 0) merged.plugin = legacy.kept;
|
|
644
|
+
else delete merged.plugin;
|
|
645
|
+
}
|
|
646
|
+
const options = current.options ?? legacy.options;
|
|
647
|
+
merged.plugins = [...current.kept, options ? {
|
|
710
648
|
package: pluginDir,
|
|
711
|
-
options
|
|
649
|
+
options
|
|
712
650
|
} : pluginDir];
|
|
713
651
|
return merged;
|
|
714
652
|
}
|
|
@@ -739,7 +677,7 @@ function withOurRef(existing, pluginRef, inspect, containing = []) {
|
|
|
739
677
|
...options ? { options } : {}
|
|
740
678
|
};
|
|
741
679
|
}
|
|
742
|
-
/** The options out of any entry form
|
|
680
|
+
/** The options out of any entry form — `[spec, options]` or `{ package, options }`. */
|
|
743
681
|
function optionsOf(entry) {
|
|
744
682
|
const raw = Array.isArray(entry) ? entry[1] : entry && typeof entry === "object" && "options" in entry ? entry.options : void 0;
|
|
745
683
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
|
|
@@ -752,7 +690,7 @@ function isWithin(dir, path) {
|
|
|
752
690
|
const prefix = dir.endsWith("/") ? dir : `${dir}/`;
|
|
753
691
|
return path.startsWith(prefix);
|
|
754
692
|
}
|
|
755
|
-
/** The package-or-path out of any entry form
|
|
693
|
+
/** The package-or-path out of any entry form, including opencode 1's. */
|
|
756
694
|
function specifierOf(entry) {
|
|
757
695
|
if (typeof entry === "string") return entry;
|
|
758
696
|
if (Array.isArray(entry)) return String(entry[0] ?? "");
|
|
@@ -1008,7 +946,7 @@ function createTokenClient(options = {}) {
|
|
|
1008
946
|
const cache = /* @__PURE__ */ new Map();
|
|
1009
947
|
async function client() {
|
|
1010
948
|
if (app) return app;
|
|
1011
|
-
const { PublicClientApplication } = await import("./dist-
|
|
949
|
+
const { PublicClientApplication } = await import("./dist-BNzsla4k.mjs");
|
|
1012
950
|
app = new PublicClientApplication({
|
|
1013
951
|
auth: {
|
|
1014
952
|
clientId: CLIENT_ID,
|
|
@@ -10781,7 +10719,7 @@ const TITLE_INSTRUCTION = /generate|summar|title|respond with|in a few words|sho
|
|
|
10781
10719
|
/**
|
|
10782
10720
|
* Name a session without spending an M365 conversation on it.
|
|
10783
10721
|
*
|
|
10784
|
-
*
|
|
10722
|
+
* A harness titles each session on the main model by default, which would open a second
|
|
10785
10723
|
* conversation for every session — and the throttle counts conversations started, not
|
|
10786
10724
|
* messages. This is not as good as a model-written title; it is free, and it keeps
|
|
10787
10725
|
* the account out of the throttle.
|
|
@@ -11137,4 +11075,4 @@ async function readBody(request, limit) {
|
|
|
11137
11075
|
}
|
|
11138
11076
|
return Buffer.concat(chunks).toString("utf8");
|
|
11139
11077
|
}
|
|
11140
|
-
export {
|
|
11078
|
+
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-IXv9y_4x.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-m365-copilot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "2.0.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,14 +63,10 @@
|
|
|
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
|
},
|