opencode-m365-copilot 2.1.2 → 2.2.1
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 +118 -20
- package/dist/{agent-DDZ4B7E6.mjs → agent-D3anZnuv.mjs} +110 -57
- package/dist/cli.mjs +38 -6
- package/dist/{dist-CN4xwvMF.mjs → dist-CsSmycf9.mjs} +1 -1
- package/dist/{login-DAXgPgtX.mjs → login-Dgv1sbgr.mjs} +2 -2
- package/dist/plugin.mjs +2 -2
- package/dist/{server-Dhpnsh1N.mjs → server-MqggZMCR.mjs} +468 -80
- package/dist/server.d.mts +63 -7
- package/dist/server.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -70,12 +70,20 @@ The proxy sees the final request, so it is the one place the trim reliably lands
|
|
|
70
70
|
|
|
71
71
|
What gets dropped:
|
|
72
72
|
|
|
73
|
-
- **Tools** — keeps
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
- **Tools** — keeps the shell tool under whatever name the harness gives it (`shell`
|
|
74
|
+
in opencode 2, `bash` before), `read`, `grep`, and the editing tools (`edit`/`write`,
|
|
75
|
+
or `apply_patch`). On opencode 2.2.5 that is five of thirteen; `execute`, `glob`,
|
|
76
|
+
`skill`, `subagent`, `webfetch`, `websearch` and `question` are dropped.
|
|
76
77
|
- **Capability catalogues** — `<available_skills>` is removed when no `skill` tool
|
|
77
78
|
survives the trim, because it advertises capabilities nothing can invoke. `<env>` and
|
|
78
79
|
other structured context are kept.
|
|
80
|
+
- **Text about dropped tools** — opencode 2's "Code Mode" section says the listed tools
|
|
81
|
+
only work inside `execute`, which the trim removes, so the model was being told its
|
|
82
|
+
tools were unusable. That section, any line naming `execute`, and the skills
|
|
83
|
+
paragraph go with their tools, as do two harness lines that contradict the
|
|
84
|
+
contract ("prefer parallelizing tool calls", "prefer dedicated tools over shell
|
|
85
|
+
commands"). On opencode 2.2.5 this takes the system prompt from about 8,000
|
|
86
|
+
characters to about 2,000.
|
|
79
87
|
- **The harness's prose system prompt** — replaced with a short one, but **off by
|
|
80
88
|
default**. A long, polished assistant prompt measurably reduces M365's tool
|
|
81
89
|
compliance on another harness's numbers; that is a borrowed result we have not
|
|
@@ -83,7 +91,7 @@ What gets dropped:
|
|
|
83
91
|
never dropped either way: opencode injects `AGENTS.md` and global rules as prose
|
|
84
92
|
inside the system message, and those sections are preserved verbatim.
|
|
85
93
|
|
|
86
|
-
|
|
94
|
+
The shell tool is never dropped. M365's chat-tuned model will not "act as an agent" on request,
|
|
87
95
|
but it *will* reflexively write a ```` ```bash ```` block — routing that block to the
|
|
88
96
|
shell tool is the single lever that makes tool calling work at all.
|
|
89
97
|
|
|
@@ -112,6 +120,50 @@ deleted — another host may be mid-conversation with it.
|
|
|
112
120
|
Without Copilot Studio access the plugin still works, just less reliably; it logs a
|
|
113
121
|
warning and carries on.
|
|
114
122
|
|
|
123
|
+
Four things keep a turn on track:
|
|
124
|
+
|
|
125
|
+
- **A tolerant parser.** M365 writes calls loosely: the command as a `command:` header,
|
|
126
|
+
`filePath:` for `path`, quoted values, a copied `$ ` prompt, prose or an invented
|
|
127
|
+
`<tool_response>` after the block. These are read as the call the model meant.
|
|
128
|
+
- **One nudge after a give-up.** Chat tones sometimes answer a tool turn with "no tool
|
|
129
|
+
is available" without trying. The proxy then asks once more, softly, in the same
|
|
130
|
+
conversation (one extra message, no new conversation), worded differently once
|
|
131
|
+
tools have already run.
|
|
132
|
+
- **A pinned backend.** Every turn's connection carries
|
|
133
|
+
`X-RoutingParameter-SessionKey`, which the reference project found stops long
|
|
134
|
+
sessions running on a forked copy of the conversation.
|
|
135
|
+
- **Telling the model what ran.** Only the first tool block in a reply runs. When a
|
|
136
|
+
reply holds more, or goes on to predict its own result, the next turn starts with
|
|
137
|
+
one line saying so, so the model does not assume the rest ran. opencode's tool
|
|
138
|
+
errors arrive as plain text (`Error: …`) rather than a JSON envelope. In the 237
|
|
139
|
+
`quick` turns measured so far, no reply needed the note.
|
|
140
|
+
|
|
141
|
+
Measured on one tenant on 2026-11-09 (`m365/quick`, opencode 2.2.5, 36 conversations,
|
|
142
|
+
alternating builds), with and without the prompt trimming, nudge and routing header.
|
|
143
|
+
Both builds had the tolerant parser:
|
|
144
|
+
|
|
145
|
+
| Task | Without | With |
|
|
146
|
+
|---|---|---|
|
|
147
|
+
| Fix a bug, then rerun its test | 6/6, 5.3 turns | 6/6, 5.0 turns |
|
|
148
|
+
| Find a value across six files | 6/6, 2.7 turns | 6/6, 2.0 turns |
|
|
149
|
+
| Edit one config value, leave the rest | 6/6, 3.5 turns | 6/6, 4.5 turns (re-read the file to check, 3 of 6) |
|
|
150
|
+
|
|
151
|
+
Every run made its tool call on the first turn, so the nudge never fired. No turn
|
|
152
|
+
disengaged, and none ran on a forked conversation (`turnCount` rose by one each turn).
|
|
153
|
+
|
|
154
|
+
Long sessions (2026-11-10, `m365/quick`, with all three): 4/4 solved, no nudges, no
|
|
155
|
+
forks.
|
|
156
|
+
|
|
157
|
+
| Task | Runs | Turns |
|
|
158
|
+
|---|---|---|
|
|
159
|
+
| Rename a function across ten modules, one edit at a time, then run the test | 2/2 | 37, 25 |
|
|
160
|
+
| Fix a 1,500-line file whose test fails, then fails again on a second bug | 2/2 | 8, 8 |
|
|
161
|
+
|
|
162
|
+
`turnCount` rose by one on every turn of the 37-turn session. Repeated calls were
|
|
163
|
+
progress checks (grep for what was left, re-reading a file after editing it), not loops.
|
|
164
|
+
These runs had the routing header, so they show it causes no harm. They don't show it
|
|
165
|
+
is needed, because no run without it was tried.
|
|
166
|
+
|
|
115
167
|
## opencode 2
|
|
116
168
|
|
|
117
169
|
This is an opencode 2 plugin (`@opencode/cli`, `@opencode/plugin`): its default export
|
|
@@ -140,7 +192,7 @@ stub rather than Microsoft: the plugin loads from a directory, registers all 21
|
|
|
140
192
|
an attached image is uploaded and attached to the turn, and the session title is
|
|
141
193
|
answered locally — one chat turn reaches the backend, not two. The catalog records are
|
|
142
194
|
also checked against the real `@opencode/plugin` schema constructors in the test suite.
|
|
143
|
-
|
|
195
|
+
That stub run says nothing about Microsoft's side; see [Development](#development) for what has been run live.
|
|
144
196
|
|
|
145
197
|
## Configuration
|
|
146
198
|
|
|
@@ -165,6 +217,29 @@ hands it to opencode itself. Only a standalone `opencode-m365 serve` proxy needs
|
|
|
165
217
|
`serve` prints its key, or takes a fixed one from `M365_PROXY_KEY`. Either put that key
|
|
166
218
|
in `apiKey`, or export the same `M365_PROXY_KEY` to opencode and leave `apiKey` out.
|
|
167
219
|
|
|
220
|
+
### Errors and the turn log
|
|
221
|
+
|
|
222
|
+
When M365 refuses a turn, the proxy reports it so that opencode does not retry it.
|
|
223
|
+
Retrying a throttle only extends it, and a refusal like a missing licence never changes.
|
|
224
|
+
opencode streams, so the refusal usually arrives inside a stream that already answered
|
|
225
|
+
200. opencode then decides from the error body alone: it retries an error whose code
|
|
226
|
+
contains "unavailable", whose message says "try again" (M365's own refusals do), or
|
|
227
|
+
which mentions a rate limit. The proxy therefore sends type `invalid_request_error`,
|
|
228
|
+
avoids those words, and uses HTTP 422 when nothing has been streamed yet. In 2.2.0 a
|
|
229
|
+
licence refusal was retried ten times. The error `code` says which refusal it was:
|
|
230
|
+
|
|
231
|
+
| Code | Meaning |
|
|
232
|
+
|---|---|
|
|
233
|
+
| `m365_throttled` | The account is throttled. Wait for a lull. |
|
|
234
|
+
| `m365_not_served` | M365 answered with its own refusal: no credits, a model this licence does not cover, or a dead tone. Called `m365_unavailable` up to 2.2.0 |
|
|
235
|
+
| `m365_turn_rejected` | The server refused the request outright, typically a retired tone |
|
|
236
|
+
| `m365_disengaged` | M365's filter refused to engage with the prompt. A disengaged conversation stays that way, so the proxy drops it: the next request opens a fresh conversation and replays the whole history |
|
|
237
|
+
|
|
238
|
+
Set `M365_TURN_LOG=/path/to/turns.jsonl` before starting opencode to record one line
|
|
239
|
+
per M365 turn: the raw reply, the tool calls parsed from it, and M365's diagnostics
|
|
240
|
+
(`contentOrigin`, `turnCount`, throttle and classifier scores). The file is
|
|
241
|
+
owner-only, and off by default because a reply can quote anything from the workspace.
|
|
242
|
+
|
|
168
243
|
### Why session titles are answered locally
|
|
169
244
|
|
|
170
245
|
opencode titles every new session with a model call on your main model, which on M365
|
|
@@ -180,16 +255,38 @@ on the real model — they are real work, and only titling opens the extra conve
|
|
|
180
255
|
|
|
181
256
|
## Models
|
|
182
257
|
|
|
183
|
-
Models are selected by an M365 *tone*, not a model id. `m365/
|
|
184
|
-
|
|
258
|
+
Models are selected by an M365 *tone*, not a model id. `m365/quick` is the default.
|
|
259
|
+
|
|
260
|
+
Tool-calling on a live tenant (2026-11-09, one non-Premium account, a single file-read
|
|
261
|
+
task per run; small samples):
|
|
262
|
+
|
|
263
|
+
| Model | Made the tool call |
|
|
264
|
+
|---|---|
|
|
265
|
+
| `m365/quick` | 5/5 |
|
|
266
|
+
| `m365/m365-copilot` | 1/1 |
|
|
267
|
+
| `m365/gpt-5.5` (same tone as `quick`) | 0/1 |
|
|
268
|
+
| `m365/gpt-5.6` | 0/1 (the reference project: 7/30), so its picker name says "unreliable tool calls" |
|
|
269
|
+
| `m365/gpt-5.5-think-deeper` | 0/3 — said it had no file tool; 4/4 with the relay framing, below |
|
|
270
|
+
|
|
271
|
+
The reference project's README reports 100% tool compliance for `gpt-5.5-think-deeper`;
|
|
272
|
+
its protocol notes (`m365-copilot-api.md`, quirk #13) say reasoning tones disengage with
|
|
273
|
+
an agent attached. Our runs agree with the notes. Reasoning tones still serve plain chat.
|
|
274
|
+
|
|
275
|
+
The reasoning tones now get a different framing on tool turns. The tool block is
|
|
276
|
+
worded as the user asking to be guided through their own terminal, one command at a
|
|
277
|
+
time, pasting back the real output (the reference project's `relay`). A model that
|
|
278
|
+
doubts it can reach the workspace has nothing to doubt, because the user runs the
|
|
279
|
+
commands. Measured on `gpt-5.5-think-deeper` on 2026-11-10, 16 conversations:
|
|
280
|
+
|
|
281
|
+
| Framing | First reply said the tools were unavailable | Solved |
|
|
282
|
+
|---|---|---|
|
|
283
|
+
| Default, before the give-up nudge | 4/4 | 1/4 |
|
|
284
|
+
| Default, with the nudge | 8/8 | 5/8 |
|
|
285
|
+
| Relay, with the nudge | 0/4 | 4/4, with no nudge needed |
|
|
185
286
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
> opposite — that reasoning tones meta-analyse the injected prompt and disengage, and
|
|
190
|
-
> only `magic`/`*_Quick` work with an agent attached. The README is the newer
|
|
191
|
-
> measurement, so it is the default here; if you see disengagement on tool turns, try
|
|
192
|
-
> `m365/quick` or `m365/m365-copilot`.
|
|
287
|
+
Claude tones stay on the agent, which M365 answers on GPT. The reference project ran
|
|
288
|
+
Claude without the agent and with `relay`, but an account with no Claude licence then
|
|
289
|
+
refuses every tool turn, and that could not be measured on a licensed account here.
|
|
193
290
|
|
|
194
291
|
A non-default tone (Claude, the reasoning tones) only takes effect when **no** agent is
|
|
195
292
|
attached — with one, M365 silently routes to GPT regardless. The proxy therefore attaches
|
|
@@ -269,7 +366,8 @@ opencode-m365 login [--interactive] # sign in
|
|
|
269
366
|
opencode-m365 setup [--local] # register the plugin with opencode
|
|
270
367
|
opencode-m365 serve [--port 4141] # run the proxy standalone, for any OpenAI client
|
|
271
368
|
# (send its key as `Authorization: Bearer`)
|
|
272
|
-
opencode-m365 doctor
|
|
369
|
+
opencode-m365 doctor [--live] # check auth, agent, proxy and opencode wiring
|
|
370
|
+
# (--live sends one short message per model tone)
|
|
273
371
|
```
|
|
274
372
|
|
|
275
373
|
## Images
|
|
@@ -317,12 +415,12 @@ Tests run against a stub SignalR server (`test/stub-copilot.ts`) that speaks the
|
|
|
317
415
|
framing, so a full turn — including the mandatory `Metrics` frame, ping handling,
|
|
318
416
|
Disengaged detection and the stop-on-abort frame — is exercised offline.
|
|
319
417
|
|
|
320
|
-
|
|
321
|
-
opencode
|
|
322
|
-
the protocol notes in
|
|
418
|
+
Chat, tool calling and agent provisioning have been run against one live tenant, through
|
|
419
|
+
opencode 2.2.5. Image upload has not, and file edits, shell commands and multi-step tasks
|
|
420
|
+
have not been exercised there. Other M365 behaviour is implemented from the protocol notes in
|
|
323
421
|
[cramt/m365-copilot-proxy](https://github.com/cramt/m365-copilot-proxy) (MIT), whose
|
|
324
|
-
`docs/` are the source of truth for this surface. Run `opencode-m365 doctor`
|
|
325
|
-
own tenant before trusting it.
|
|
422
|
+
`docs/` are the source of truth for this surface. Run `opencode-m365 doctor --live`
|
|
423
|
+
against your own tenant before trusting it.
|
|
326
424
|
|
|
327
425
|
## Credit
|
|
328
426
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as AGENT_FILE, d as BAP_SCOPE, p as POWERPLATFORM_SCOPE, x as writePrivateFile, y as createLogger } from "./server-MqggZMCR.mjs";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
// src/agent.ts
|
|
@@ -28,6 +28,16 @@ import { createHash } from "node:crypto";
|
|
|
28
28
|
const log = createLogger("agent");
|
|
29
29
|
const BAP_ENVIRONMENT_URL = "https://api.bap.microsoft.com/providers/Microsoft.BusinessAppPlatform/environments/~default?api-version=2023-06-01";
|
|
30
30
|
const COPILOT_STUDIO_API_VERSION = "2022-03-01-preview";
|
|
31
|
+
/** A plain 48×48 square: the portal always sends an icon, so we do too. */
|
|
32
|
+
const BOT_ICON_BASE64 = "iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAAAOklEQVR42u3OQQ0AAAgEoCtjMuNbwhbOBxsBSPW8EiEhISEhISEhISEhISEhISEhISEhISEhISGhOwsQ7wvEcqrbYwAAAABJRU5ErkJggg==";
|
|
33
|
+
const EMPTY_GUID = "00000000-0000-0000-0000-000000000000";
|
|
34
|
+
function studioHeaders(token) {
|
|
35
|
+
return {
|
|
36
|
+
Authorization: `Bearer ${token}`,
|
|
37
|
+
"Content-Type": "application/json",
|
|
38
|
+
"x-ms-user-agent": "PVA-Portal/1.0.0 (Web; ReactNative: false)"
|
|
39
|
+
};
|
|
40
|
+
}
|
|
31
41
|
/**
|
|
32
42
|
* The agent's server-side instructions.
|
|
33
43
|
*
|
|
@@ -52,28 +62,24 @@ function agentInstructions() {
|
|
|
52
62
|
function agentNameFor(instructions) {
|
|
53
63
|
return `m365-tool-agent-${createHash("sha256").update(instructions).digest("hex").slice(0, 8)}`;
|
|
54
64
|
}
|
|
55
|
-
/** The id M365 expects in `threadLevelGptId` / `gpts`. */
|
|
65
|
+
/** The id M365 expects in `threadLevelGptId` / `gpts`. `titleId` arrives already `T_`-prefixed. */
|
|
56
66
|
function buildAgentId(titleId, botId) {
|
|
57
|
-
return
|
|
67
|
+
return `${titleId}.${botId}.gpt.default`;
|
|
58
68
|
}
|
|
59
69
|
/**
|
|
60
|
-
* Power Platform
|
|
70
|
+
* The Power Platform host for this environment.
|
|
61
71
|
*
|
|
62
|
-
* The
|
|
63
|
-
*
|
|
72
|
+
* The id is split across two DNS labels: all but its last two characters, then those
|
|
73
|
+
* two. It looks like a fixed `.df.` on any tenant whose id happens to end in `df`.
|
|
64
74
|
*/
|
|
65
|
-
function
|
|
66
|
-
|
|
67
|
-
return [
|
|
68
|
-
`default${envId}.${suffix}`,
|
|
69
|
-
`default${envId.slice(0, -1)}.${suffix}`,
|
|
70
|
-
`default${envId.slice(0, -2)}.${suffix}`
|
|
71
|
-
];
|
|
75
|
+
function environmentHost(envId) {
|
|
76
|
+
return `default${envId.slice(0, -2)}.${envId.slice(-2)}.environment.api.powerplatform.com`;
|
|
72
77
|
}
|
|
73
|
-
/**
|
|
78
|
+
/** The environment's host, checked in DNS so a wrong one fails with a usable message. */
|
|
74
79
|
async function resolveEnvironmentHost(envId, resolveDns, override) {
|
|
75
80
|
if (override) return override;
|
|
76
|
-
|
|
81
|
+
const host = environmentHost(envId);
|
|
82
|
+
if (await resolveDns(host)) return host;
|
|
77
83
|
throw new Error(`Could not resolve a Power Platform host for environment ${envId}. Set M365_POWERPLATFORM_HOST to override.`);
|
|
78
84
|
}
|
|
79
85
|
/** Default resolver: a DNS lookup, treating any failure as "does not resolve". */
|
|
@@ -89,7 +95,8 @@ const dnsResolver = async (host) => {
|
|
|
89
95
|
/**
|
|
90
96
|
* Resolve the declarative agent id, provisioning one if the tenant has none.
|
|
91
97
|
*
|
|
92
|
-
* Order: local cache → the tenant's existing
|
|
98
|
+
* Order: local cache → the tenant's existing bot, else create → publish (which is also
|
|
99
|
+
* the only way to learn an existing bot's title id).
|
|
93
100
|
*/
|
|
94
101
|
async function getOrCreateAgent(deps) {
|
|
95
102
|
const cacheFile = deps.cacheFile ?? AGENT_FILE;
|
|
@@ -103,17 +110,7 @@ async function getOrCreateAgent(deps) {
|
|
|
103
110
|
const resolveDns = deps.resolveDns ?? dnsResolver;
|
|
104
111
|
const host = await resolveEnvironmentHost(await discoverEnvironmentId(doFetch, deps.getTokenForScope), resolveDns, deps.hostOverride ?? process.env.M365_POWERPLATFORM_HOST);
|
|
105
112
|
const token = await deps.getTokenForScope([POWERPLATFORM_SCOPE]);
|
|
106
|
-
const
|
|
107
|
-
if (existing) {
|
|
108
|
-
const agentId = buildAgentId(existing.titleId, existing.botId);
|
|
109
|
-
writeCache(cacheFile, {
|
|
110
|
-
agentId,
|
|
111
|
-
instructionsHash: wantedName
|
|
112
|
-
});
|
|
113
|
-
log.info("reusing existing agent", agentId);
|
|
114
|
-
return agentId;
|
|
115
|
-
}
|
|
116
|
-
const botId = await createBot(doFetch, host, token, wantedName);
|
|
113
|
+
const botId = await findBot(doFetch, host, token, wantedName) ?? await createBot(doFetch, host, token, wantedName);
|
|
117
114
|
const agentId = buildAgentId(await publishBot(doFetch, host, token, botId), botId);
|
|
118
115
|
writeCache(cacheFile, {
|
|
119
116
|
agentId,
|
|
@@ -136,55 +133,111 @@ async function discoverEnvironmentId(doFetch, getTokenForScope) {
|
|
|
136
133
|
* Find a bot by name.
|
|
137
134
|
*
|
|
138
135
|
* Name lookup is reliable because Copilot Studio reflects the display name we set
|
|
139
|
-
* into `shortBotName` byte for byte — hyphens, length and case all survive.
|
|
136
|
+
* into `shortBotName` byte for byte — hyphens, length and case all survive. The list
|
|
137
|
+
* carries no title id.
|
|
140
138
|
*/
|
|
141
139
|
async function findBot(doFetch, host, token, name) {
|
|
142
|
-
const response = await doFetch(`https://${host}/copilotstudio/minimalBots/api
|
|
140
|
+
const response = await doFetch(`https://${host}/copilotstudio/minimalBots/api?api-version=${COPILOT_STUDIO_API_VERSION}`, { headers: studioHeaders(token) });
|
|
143
141
|
if (!response.ok) throw new AgentHttpError(await describeFailure("listing agents", response), response.status);
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
142
|
+
const bots = await response.json();
|
|
143
|
+
if (!Array.isArray(bots)) throw new Error("Copilot Studio returned an unexpected agent list");
|
|
144
|
+
return bots.find((bot) => bot?.shortBotName === name)?.botId;
|
|
145
|
+
}
|
|
146
|
+
/** The change set the Copilot Studio portal posts to create a GPT-template bot. */
|
|
147
|
+
function createBotBody(name) {
|
|
148
|
+
const noDiagnostics = { diagnostics: [] };
|
|
148
149
|
return {
|
|
149
|
-
|
|
150
|
-
|
|
150
|
+
botComponentChanges: [{
|
|
151
|
+
$kind: "BotComponentInsert",
|
|
152
|
+
component: {
|
|
153
|
+
...noDiagnostics,
|
|
154
|
+
$kind: "GptComponent",
|
|
155
|
+
id: EMPTY_GUID,
|
|
156
|
+
displayName: name,
|
|
157
|
+
description: "Tool-calling format instructions for an OpenAI-compatible bridge.",
|
|
158
|
+
schemaName: `${EMPTY_GUID}.gpt.default`,
|
|
159
|
+
metadata: {
|
|
160
|
+
...noDiagnostics,
|
|
161
|
+
$kind: "GptComponentMetadata",
|
|
162
|
+
tools: [],
|
|
163
|
+
conversationStarters: [],
|
|
164
|
+
instructions: {
|
|
165
|
+
...noDiagnostics,
|
|
166
|
+
$kind: "TemplateLine",
|
|
167
|
+
segments: [{
|
|
168
|
+
...noDiagnostics,
|
|
169
|
+
$kind: "TextSegment",
|
|
170
|
+
value: agentInstructions()
|
|
171
|
+
}]
|
|
172
|
+
},
|
|
173
|
+
knowledgeSources: {
|
|
174
|
+
...noDiagnostics,
|
|
175
|
+
$kind: "SearchAllKnowledgeSources"
|
|
176
|
+
},
|
|
177
|
+
gptCapabilities: {
|
|
178
|
+
...noDiagnostics,
|
|
179
|
+
$kind: "GptCapabilities",
|
|
180
|
+
codeInterpreter: false,
|
|
181
|
+
generateImages: false,
|
|
182
|
+
webBrowsing: false,
|
|
183
|
+
searchOneDriveAndSharePoint: false,
|
|
184
|
+
searchTeams: false,
|
|
185
|
+
searchMeetings: false,
|
|
186
|
+
searchEmails: false,
|
|
187
|
+
searchPeople: false
|
|
188
|
+
},
|
|
189
|
+
aISettings: {
|
|
190
|
+
...noDiagnostics,
|
|
191
|
+
$kind: "AISettings",
|
|
192
|
+
useModelKnowledge: true
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}],
|
|
197
|
+
cloudFlowDefinitionChanges: [],
|
|
198
|
+
connectorDefinitionChanges: [],
|
|
199
|
+
environmentVariableChanges: [],
|
|
200
|
+
connectionReferenceChanges: [],
|
|
201
|
+
aIPluginOperationChanges: [],
|
|
202
|
+
componentCollectionChanges: [],
|
|
203
|
+
dataverseTableSearchChanges: [],
|
|
204
|
+
dataverseTableSearchEntityConfigurationChanges: [],
|
|
205
|
+
dataverseTableSearchGlossaryConfigurationChanges: [],
|
|
206
|
+
dataverseTableSearchEntityColumnSynonymChanges: [],
|
|
207
|
+
aIModelChanges: [],
|
|
208
|
+
connectedAgentDefinitionChanges: [],
|
|
209
|
+
bot: {
|
|
210
|
+
$kind: "BotEntity",
|
|
211
|
+
authorizedSecurityGroupIds: [],
|
|
212
|
+
supportedLanguages: [],
|
|
213
|
+
diagnostics: [],
|
|
214
|
+
displayName: name,
|
|
215
|
+
language: 1033,
|
|
216
|
+
schemaName: EMPTY_GUID,
|
|
217
|
+
template: "gpt-1.1.0",
|
|
218
|
+
iconBase64: BOT_ICON_BASE64
|
|
219
|
+
}
|
|
151
220
|
};
|
|
152
221
|
}
|
|
153
222
|
async function createBot(doFetch, host, token, name) {
|
|
154
223
|
const response = await doFetch(`https://${host}/copilotstudio/minimalBots/api?api-version=${COPILOT_STUDIO_API_VERSION}`, {
|
|
155
224
|
method: "POST",
|
|
156
|
-
headers:
|
|
157
|
-
|
|
158
|
-
"Content-Type": "application/json"
|
|
159
|
-
},
|
|
160
|
-
body: JSON.stringify({
|
|
161
|
-
displayName: name,
|
|
162
|
-
description: "Tool-calling format instructions for an OpenAI-compatible bridge.",
|
|
163
|
-
gptComponent: {
|
|
164
|
-
instructions: agentInstructions(),
|
|
165
|
-
conversationStarters: [],
|
|
166
|
-
aISettings: { useModelKnowledge: true }
|
|
167
|
-
}
|
|
168
|
-
})
|
|
225
|
+
headers: studioHeaders(token),
|
|
226
|
+
body: JSON.stringify(createBotBody(name))
|
|
169
227
|
});
|
|
170
228
|
if (!response.ok) throw new AgentHttpError(await describeFailure("creating the agent", response), response.status);
|
|
171
229
|
const body = await response.json();
|
|
172
|
-
const botId = body?.
|
|
230
|
+
const botId = body?.bot?.schemaName ?? body?.bot?.cdsBotId;
|
|
173
231
|
if (!botId) throw new Error("Copilot Studio created an agent but returned no bot id");
|
|
174
232
|
return botId;
|
|
175
233
|
}
|
|
176
234
|
async function publishBot(doFetch, host, token, botId) {
|
|
177
|
-
const response = await doFetch(`https://${host}/copilotstudio/minimalBots/api/publish?api-version=${COPILOT_STUDIO_API_VERSION}
|
|
235
|
+
const response = await doFetch(`https://${host}/copilotstudio/minimalBots/api/${encodeURIComponent(botId)}/publish?api-version=${COPILOT_STUDIO_API_VERSION}`, {
|
|
178
236
|
method: "POST",
|
|
179
|
-
headers:
|
|
180
|
-
Authorization: `Bearer ${token}`,
|
|
181
|
-
"Content-Type": "application/json"
|
|
182
|
-
},
|
|
183
|
-
body: JSON.stringify({ botId })
|
|
237
|
+
headers: studioHeaders(token)
|
|
184
238
|
});
|
|
185
239
|
if (!response.ok) throw new AgentHttpError(await describeFailure("publishing the agent", response), response.status);
|
|
186
|
-
const
|
|
187
|
-
const titleId = body?.titleId ?? body?.TitleId;
|
|
240
|
+
const titleId = (await response.json())?.TitleId;
|
|
188
241
|
if (!titleId) throw new Error("Copilot Studio published the agent but returned no title id");
|
|
189
242
|
return titleId;
|
|
190
243
|
}
|
package/dist/cli.mjs
CHANGED
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { A as
|
|
3
|
-
import { t as getOrCreateAgent } from "./agent-
|
|
2
|
+
import { A as mergeOpencodeConfig, C as CACHE_FILE, D as PROVIDER_ID, M as DEFAULT_MODEL, N as LOCAL_TITLE_MODEL, P as MODELS, S as AGENT_FILE, T as SECRETS_FILE, l as CopilotSession, o as startServer, v as createTokenClient, w as CONFIG_DIR } from "./server-MqggZMCR.mjs";
|
|
3
|
+
import { t as getOrCreateAgent } from "./agent-D3anZnuv.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";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
|
+
// src/live-check.ts
|
|
9
|
+
function distinctTones(models) {
|
|
10
|
+
return [...new Set(models.flatMap((model) => model.tone ? [model.tone] : []))];
|
|
11
|
+
}
|
|
12
|
+
async function checkTones(session, tones) {
|
|
13
|
+
const results = [];
|
|
14
|
+
for (const tone of tones) try {
|
|
15
|
+
const { text, contentOrigin } = await session.run("Please reply with the word ok.", { tone });
|
|
16
|
+
const ok = text.trim() !== "" && contentOrigin !== "BotConnection";
|
|
17
|
+
results.push({
|
|
18
|
+
tone,
|
|
19
|
+
ok,
|
|
20
|
+
detail: text.trim() === "" ? "empty reply" : contentOrigin ?? "replied"
|
|
21
|
+
});
|
|
22
|
+
} catch (error) {
|
|
23
|
+
results.push({
|
|
24
|
+
tone,
|
|
25
|
+
ok: false,
|
|
26
|
+
detail: error.message
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return results;
|
|
30
|
+
}
|
|
8
31
|
// src/cli.ts
|
|
9
32
|
/**
|
|
10
33
|
* `opencode-m365` — sign in, wire up opencode, and check the plumbing.
|
|
@@ -20,7 +43,7 @@ async function main() {
|
|
|
20
43
|
case "login": return doLogin(rest);
|
|
21
44
|
case "setup": return doSetup(rest);
|
|
22
45
|
case "serve": return doServe(rest);
|
|
23
|
-
case "doctor": return doDoctor();
|
|
46
|
+
case "doctor": return doDoctor(rest);
|
|
24
47
|
case "help":
|
|
25
48
|
case "--help":
|
|
26
49
|
case "-h": return printHelp();
|
|
@@ -37,7 +60,8 @@ function printHelp() {
|
|
|
37
60
|
setup [--local] Add the plugin to ~/.config/opencode/opencode.json
|
|
38
61
|
serve [--port <n>] Run the OpenAI-compatible proxy standalone
|
|
39
62
|
(key from M365_PROXY_KEY, else printed)
|
|
40
|
-
doctor
|
|
63
|
+
doctor [--live] Check auth, the agent, and the proxy
|
|
64
|
+
(--live also sends one short message per model tone)
|
|
41
65
|
|
|
42
66
|
Config lives in ${CONFIG_DIR}
|
|
43
67
|
|
|
@@ -46,7 +70,7 @@ to complete SSO/MFA by hand once — the only option on tenants with push-only
|
|
|
46
70
|
MFA, FIDO2, or a federated IdP.`);
|
|
47
71
|
}
|
|
48
72
|
async function doLogin(args) {
|
|
49
|
-
const { login } = await import("./login-
|
|
73
|
+
const { login } = await import("./login-Dgv1sbgr.mjs");
|
|
50
74
|
const interactive = args.includes("--interactive");
|
|
51
75
|
try {
|
|
52
76
|
const account = await login({
|
|
@@ -145,7 +169,7 @@ async function doServe(args) {
|
|
|
145
169
|
proxy.close().then(() => process.exit(0));
|
|
146
170
|
});
|
|
147
171
|
}
|
|
148
|
-
async function doDoctor() {
|
|
172
|
+
async function doDoctor(args) {
|
|
149
173
|
let failures = 0;
|
|
150
174
|
const check = (label, ok, detail = "") => {
|
|
151
175
|
console.log(` ${ok ? "ok " : "FAIL"} ${label}${detail ? ` — ${detail}` : ""}`);
|
|
@@ -189,6 +213,14 @@ async function doDoctor() {
|
|
|
189
213
|
} catch (error) {
|
|
190
214
|
check("starts", false, error.message);
|
|
191
215
|
}
|
|
216
|
+
if (args.includes("--live")) {
|
|
217
|
+
console.log("\nLive turns (one conversation, one short message per tone)");
|
|
218
|
+
if (!signedIn) console.log(" skip needs a signed-in account");
|
|
219
|
+
else {
|
|
220
|
+
const session = new CopilotSession({ getToken: () => tokens.getToken() });
|
|
221
|
+
for (const { tone, ok, detail } of await checkTones(session, distinctTones(MODELS))) check(tone, ok, detail);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
192
224
|
console.log("\nopencode");
|
|
193
225
|
const configured = existsSync(OPENCODE_CONFIG) && readFileSync(OPENCODE_CONFIG, "utf8").includes("m365");
|
|
194
226
|
check("plugin registered", configured, configured ? OPENCODE_CONFIG : "run `opencode-m365 setup`");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { I as __commonJSMin, L as __require, R as __toESM } from "./server-MqggZMCR.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 {
|
|
1
|
+
import { T as SECRETS_FILE, _ as createCachePlugin, b as ensurePrivateDir, c as string, f as CLIENT_ID, g as authCodeFromUrl, h as SYDNEY_SCOPES, m as REDIRECT_URI, s as object, u as AUTHORITY, w as CONFIG_DIR, y as createLogger } from "./server-MqggZMCR.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-
|
|
99
|
+
const { PublicClientApplication, CryptoProvider } = await import("./dist-CsSmycf9.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 {
|
|
2
|
-
import { t as getOrCreateAgent } from "./agent-
|
|
1
|
+
import { D as PROVIDER_ID, E as PLUGIN_ID, F as isLocalModel, M as DEFAULT_MODEL, O as buildModelInfos, j as resolveOptions, k as buildProviderInfo, o as startServer, r as SESSION_ID_HEADER, t as AUX_REQUEST_KIND_HEADER, v as createTokenClient, y as createLogger } from "./server-MqggZMCR.mjs";
|
|
2
|
+
import { t as getOrCreateAgent } from "./agent-D3anZnuv.mjs";
|
|
3
3
|
// src/runtime.ts
|
|
4
4
|
/**
|
|
5
5
|
* What the plugin stands on: the OpenAI-compatible proxy, started in-process (or an
|