opencode-m365-copilot 0.3.4 → 0.4.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 +19 -4
- package/dist/{agent-Cd7BGDdu.mjs → agent-CtiM1nN_.mjs} +2 -3
- package/dist/cli.mjs +4 -5
- package/dist/{dist-CMVPFMhc.mjs → dist-Dp9sO-mB.mjs} +402 -511
- package/dist/{login-DTenVKcz.mjs → login-CWvKVY0k.mjs} +4 -5
- package/dist/{otpauth.node-CBOz_1IZ.mjs → otpauth.node-DaSYf7YH.mjs} +21 -13
- package/dist/plugin.d.mts +0 -4
- package/dist/plugin.mjs +5 -8
- package/dist/{server-DQW-8ns2.mjs → server-Cow8-T6p.mjs} +289 -147
- package/dist/server.d.mts +1 -5
- package/dist/server.mjs +1 -2
- package/package.json +3 -3
|
@@ -4,14 +4,14 @@ import { appendFileSync, chmodSync, closeSync, constants, mkdirSync, openSync, r
|
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { dirname, join, parse, resolve, sep } from "node:path";
|
|
6
6
|
import { createServer } from "node:http";
|
|
7
|
-
|
|
7
|
+
// \0rolldown/runtime.js
|
|
8
8
|
var __create = Object.create;
|
|
9
9
|
var __defProp = Object.defineProperty;
|
|
10
10
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
11
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
12
12
|
var __getProtoOf = Object.getPrototypeOf;
|
|
13
13
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
-
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
14
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
|
|
15
15
|
var __copyProps = (to, from, except, desc) => {
|
|
16
16
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
17
17
|
key = keys[i];
|
|
@@ -27,8 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
enumerable: true
|
|
28
28
|
}) : target, mod));
|
|
29
29
|
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
30
|
-
|
|
31
|
-
//#region src/models.ts
|
|
30
|
+
// src/models.ts
|
|
32
31
|
/**
|
|
33
32
|
* Advertised context/output limits.
|
|
34
33
|
*
|
|
@@ -119,8 +118,7 @@ function isLocalModel(id) {
|
|
|
119
118
|
function listModelIds() {
|
|
120
119
|
return MODELS.map((model) => model.id);
|
|
121
120
|
}
|
|
122
|
-
|
|
123
|
-
//#region src/fenced.ts
|
|
121
|
+
// src/fenced.ts
|
|
124
122
|
/** Info strings we accept as "this is a shell block", beyond the tool's own name. */
|
|
125
123
|
const SHELL_FENCE_INFOS = /* @__PURE__ */ new Set([
|
|
126
124
|
"bash",
|
|
@@ -445,8 +443,7 @@ function coerce(value, type) {
|
|
|
445
443
|
default: return value;
|
|
446
444
|
}
|
|
447
445
|
}
|
|
448
|
-
|
|
449
|
-
//#region src/config.ts
|
|
446
|
+
// src/config.ts
|
|
450
447
|
/**
|
|
451
448
|
* opencode configuration: the provider entry, and the lean tool profile that makes
|
|
452
449
|
* M365 willing to engage at all.
|
|
@@ -581,19 +578,26 @@ function buildToolProfile() {
|
|
|
581
578
|
/** The `provider.m365` entry pointing opencode at our local OpenAI-compatible proxy. */
|
|
582
579
|
function buildProviderConfig(baseUrl, apiKey) {
|
|
583
580
|
const models = {};
|
|
584
|
-
for (const model of MODELS)
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
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
|
+
}
|
|
597
601
|
return {
|
|
598
602
|
npm: "@ai-sdk/openai-compatible",
|
|
599
603
|
name: "Microsoft 365 Copilot",
|
|
@@ -642,7 +646,7 @@ function buildModelInfos() {
|
|
|
642
646
|
name: model.name,
|
|
643
647
|
capabilities: {
|
|
644
648
|
tools: !isLocalModel(model.id),
|
|
645
|
-
input:
|
|
649
|
+
input: inputModalities(model.id),
|
|
646
650
|
output: ["text"]
|
|
647
651
|
},
|
|
648
652
|
variants: [],
|
|
@@ -660,6 +664,10 @@ function buildModelInfos() {
|
|
|
660
664
|
limit: model.limit
|
|
661
665
|
}));
|
|
662
666
|
}
|
|
667
|
+
/** Image input on every model that reaches M365; the local titler takes text only. */
|
|
668
|
+
function inputModalities(modelId) {
|
|
669
|
+
return isLocalModel(modelId) ? ["text"] : ["text", "image"];
|
|
670
|
+
}
|
|
663
671
|
/**
|
|
664
672
|
* Mutate opencode's in-memory config during the plugin's `config` hook.
|
|
665
673
|
*
|
|
@@ -778,8 +786,7 @@ function tail(ref) {
|
|
|
778
786
|
if (!ref.includes("/")) return "";
|
|
779
787
|
return ref.split("/").slice(-2).join("/");
|
|
780
788
|
}
|
|
781
|
-
|
|
782
|
-
//#region src/paths.ts
|
|
789
|
+
// src/paths.ts
|
|
783
790
|
/**
|
|
784
791
|
* Where we keep auth state.
|
|
785
792
|
*
|
|
@@ -792,8 +799,7 @@ const CACHE_FILE = process.env.M365_CACHE_FILE || join(CONFIG_DIR, "msal-cache.j
|
|
|
792
799
|
const SECRETS_FILE = process.env.M365_SECRETS_FILE || join(CONFIG_DIR, "secrets.json");
|
|
793
800
|
const AGENT_FILE = process.env.M365_AGENT_FILE || join(CONFIG_DIR, "agent-id.json");
|
|
794
801
|
const LOG_FILE = join(CONFIG_DIR, "debug.log");
|
|
795
|
-
|
|
796
|
-
//#region src/private-fs.ts
|
|
802
|
+
// src/private-fs.ts
|
|
797
803
|
/**
|
|
798
804
|
* Owner-only filesystem writes for everything under the config directory.
|
|
799
805
|
*
|
|
@@ -901,8 +907,7 @@ function createPrivateAppender(file) {
|
|
|
901
907
|
ready = true;
|
|
902
908
|
};
|
|
903
909
|
}
|
|
904
|
-
|
|
905
|
-
//#region src/log.ts
|
|
910
|
+
// src/log.ts
|
|
906
911
|
const DEBUG = process.env.M365_DEBUG === "1" || process.env.M365_TRACE === "1";
|
|
907
912
|
const TRACE = process.env.M365_TRACE === "1";
|
|
908
913
|
const TO_STDOUT = process.env.M365_LOG_STDOUT === "1";
|
|
@@ -939,8 +944,7 @@ function createLogger(scope) {
|
|
|
939
944
|
error: (...parts) => write("error", parts)
|
|
940
945
|
};
|
|
941
946
|
}
|
|
942
|
-
|
|
943
|
-
//#region src/auth.ts
|
|
947
|
+
// src/auth.ts
|
|
944
948
|
/**
|
|
945
949
|
* Authentication against the Office web Copilot client.
|
|
946
950
|
*
|
|
@@ -955,7 +959,7 @@ function createLogger(scope) {
|
|
|
955
959
|
* a client secret only Microsoft holds (`AADSTS7000218`). The `nativeclient` redirect
|
|
956
960
|
* is the only door, which is why `login.ts` has to drive a real browser.
|
|
957
961
|
*/
|
|
958
|
-
const log$
|
|
962
|
+
const log$3 = createLogger("auth");
|
|
959
963
|
/** Microsoft's Office web Copilot client. Not ours, and not replaceable. */
|
|
960
964
|
const CLIENT_ID = "c0ab8ce9-e9a0-42e7-b064-33d422df41f1";
|
|
961
965
|
const AUTHORITY = "https://login.microsoftonline.com/common";
|
|
@@ -994,7 +998,7 @@ function createCachePlugin(file = CACHE_FILE) {
|
|
|
994
998
|
try {
|
|
995
999
|
writePrivateFile(file, context.tokenCache.serialize());
|
|
996
1000
|
} catch (error) {
|
|
997
|
-
log$
|
|
1001
|
+
log$3.warn("could not persist the token cache", String(error));
|
|
998
1002
|
}
|
|
999
1003
|
}
|
|
1000
1004
|
};
|
|
@@ -1004,7 +1008,7 @@ function createTokenClient(options = {}) {
|
|
|
1004
1008
|
const cache = /* @__PURE__ */ new Map();
|
|
1005
1009
|
async function client() {
|
|
1006
1010
|
if (app) return app;
|
|
1007
|
-
const { PublicClientApplication } = await import("./dist-
|
|
1011
|
+
const { PublicClientApplication } = await import("./dist-Dp9sO-mB.mjs");
|
|
1008
1012
|
app = new PublicClientApplication({
|
|
1009
1013
|
auth: {
|
|
1010
1014
|
clientId: CLIENT_ID,
|
|
@@ -1028,7 +1032,7 @@ function createTokenClient(options = {}) {
|
|
|
1028
1032
|
scopes
|
|
1029
1033
|
});
|
|
1030
1034
|
} catch (error) {
|
|
1031
|
-
log$
|
|
1035
|
+
log$3.warn("silent token acquisition failed", String(error));
|
|
1032
1036
|
throw new AuthRequiredError("Could not refresh the Microsoft 365 token silently");
|
|
1033
1037
|
}
|
|
1034
1038
|
if (!result?.accessToken) throw new AuthRequiredError("Microsoft 365 returned no access token");
|
|
@@ -1067,8 +1071,7 @@ function authCodeFromUrl(rawUrl) {
|
|
|
1067
1071
|
}
|
|
1068
1072
|
return url.searchParams.get("code") ?? void 0;
|
|
1069
1073
|
}
|
|
1070
|
-
|
|
1071
|
-
//#region node_modules/ws/lib/constants.js
|
|
1074
|
+
// node_modules/ws/lib/constants.js
|
|
1072
1075
|
var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1073
1076
|
const BINARY_TYPES = [
|
|
1074
1077
|
"nodebuffer",
|
|
@@ -1090,9 +1093,9 @@ var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1090
1093
|
NOOP: () => {}
|
|
1091
1094
|
};
|
|
1092
1095
|
}));
|
|
1093
|
-
|
|
1094
|
-
//#region node_modules/ws/lib/buffer-util.js
|
|
1096
|
+
// node_modules/ws/lib/buffer-util.js
|
|
1095
1097
|
var require_buffer_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1098
|
+
const { websocketMask, websocketUnmask } = __require("http");
|
|
1096
1099
|
const { EMPTY_BUFFER } = require_constants();
|
|
1097
1100
|
const FastBuffer = Buffer[Symbol.species];
|
|
1098
1101
|
/**
|
|
@@ -1177,8 +1180,16 @@ var require_buffer_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1177
1180
|
toBuffer,
|
|
1178
1181
|
unmask: _unmask
|
|
1179
1182
|
};
|
|
1180
|
-
|
|
1181
|
-
|
|
1183
|
+
if (websocketMask) {
|
|
1184
|
+
module.exports.mask = function(source, mask, output, offset, length) {
|
|
1185
|
+
if (length < 24) _mask(source, mask, output, offset, length);
|
|
1186
|
+
else websocketMask(source, mask, output, offset, length);
|
|
1187
|
+
};
|
|
1188
|
+
module.exports.unmask = function(buffer, mask) {
|
|
1189
|
+
if (buffer.length < 24) _unmask(buffer, mask);
|
|
1190
|
+
else websocketUnmask(buffer, mask);
|
|
1191
|
+
};
|
|
1192
|
+
} else if (!process.env.WS_NO_BUFFER_UTIL) try {
|
|
1182
1193
|
const bufferUtil = __require("bufferutil");
|
|
1183
1194
|
module.exports.mask = function(source, mask, output, offset, length) {
|
|
1184
1195
|
if (length < 48) _mask(source, mask, output, offset, length);
|
|
@@ -1190,8 +1201,7 @@ var require_buffer_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1190
1201
|
};
|
|
1191
1202
|
} catch (e) {}
|
|
1192
1203
|
}));
|
|
1193
|
-
|
|
1194
|
-
//#region node_modules/ws/lib/limiter.js
|
|
1204
|
+
// node_modules/ws/lib/limiter.js
|
|
1195
1205
|
var require_limiter = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1196
1206
|
const kDone = Symbol("kDone");
|
|
1197
1207
|
const kRun = Symbol("kRun");
|
|
@@ -1241,8 +1251,7 @@ var require_limiter = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1241
1251
|
};
|
|
1242
1252
|
module.exports = Limiter;
|
|
1243
1253
|
}));
|
|
1244
|
-
|
|
1245
|
-
//#region node_modules/ws/lib/permessage-deflate.js
|
|
1254
|
+
// node_modules/ws/lib/permessage-deflate.js
|
|
1246
1255
|
var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1247
1256
|
const zlib = __require("zlib");
|
|
1248
1257
|
const bufferUtil = require_buffer_util();
|
|
@@ -1577,8 +1586,7 @@ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
1577
1586
|
this[kCallback](err);
|
|
1578
1587
|
}
|
|
1579
1588
|
}));
|
|
1580
|
-
|
|
1581
|
-
//#region node_modules/ws/lib/validation.js
|
|
1589
|
+
// node_modules/ws/lib/validation.js
|
|
1582
1590
|
var require_validation = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1583
1591
|
const { isUtf8 } = __require("buffer");
|
|
1584
1592
|
const { hasBlob } = require_constants();
|
|
@@ -1773,8 +1781,7 @@ var require_validation = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1773
1781
|
};
|
|
1774
1782
|
} catch (e) {}
|
|
1775
1783
|
}));
|
|
1776
|
-
|
|
1777
|
-
//#region node_modules/ws/lib/receiver.js
|
|
1784
|
+
// node_modules/ws/lib/receiver.js
|
|
1778
1785
|
var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1779
1786
|
const { Writable } = __require("stream");
|
|
1780
1787
|
const PerMessageDeflate = require_permessage_deflate();
|
|
@@ -2236,10 +2243,9 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2236
2243
|
};
|
|
2237
2244
|
module.exports = Receiver;
|
|
2238
2245
|
}));
|
|
2239
|
-
|
|
2240
|
-
//#region node_modules/ws/lib/sender.js
|
|
2246
|
+
// node_modules/ws/lib/sender.js
|
|
2241
2247
|
var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2242
|
-
const { Duplex
|
|
2248
|
+
const { Duplex } = __require("stream");
|
|
2243
2249
|
const { randomFillSync } = __require("crypto");
|
|
2244
2250
|
const { types: { isUint8Array } } = __require("util");
|
|
2245
2251
|
const PerMessageDeflate = require_permessage_deflate();
|
|
@@ -2350,12 +2356,13 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2350
2356
|
target[2] = target[3] = 0;
|
|
2351
2357
|
target.writeUIntBE(dataLength, 4, 6);
|
|
2352
2358
|
}
|
|
2353
|
-
if (!options.mask) return [target, data];
|
|
2359
|
+
if (!options.mask) return dataLength ? [target, data] : [target];
|
|
2354
2360
|
target[1] |= 128;
|
|
2355
2361
|
target[offset - 4] = mask[0];
|
|
2356
2362
|
target[offset - 3] = mask[1];
|
|
2357
2363
|
target[offset - 2] = mask[2];
|
|
2358
2364
|
target[offset - 1] = mask[3];
|
|
2365
|
+
if (!dataLength) return [target];
|
|
2359
2366
|
if (skipMasking) return [target, data];
|
|
2360
2367
|
if (merge) {
|
|
2361
2368
|
applyMask(data, mask, target, offset, dataLength);
|
|
@@ -2734,8 +2741,7 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2734
2741
|
sender.onerror(err);
|
|
2735
2742
|
}
|
|
2736
2743
|
}));
|
|
2737
|
-
|
|
2738
|
-
//#region node_modules/ws/lib/event-target.js
|
|
2744
|
+
// node_modules/ws/lib/event-target.js
|
|
2739
2745
|
var require_event_target = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2740
2746
|
const { kForOnEventAttribute, kListener } = require_constants();
|
|
2741
2747
|
const kCode = Symbol("kCode");
|
|
@@ -2965,8 +2971,7 @@ var require_event_target = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2965
2971
|
else listener.call(thisArg, event);
|
|
2966
2972
|
}
|
|
2967
2973
|
}));
|
|
2968
|
-
|
|
2969
|
-
//#region node_modules/ws/lib/extension.js
|
|
2974
|
+
// node_modules/ws/lib/extension.js
|
|
2970
2975
|
var require_extension = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2971
2976
|
const { tokenChars } = require_validation();
|
|
2972
2977
|
/**
|
|
@@ -3111,17 +3116,16 @@ var require_extension = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3111
3116
|
parse
|
|
3112
3117
|
};
|
|
3113
3118
|
}));
|
|
3114
|
-
|
|
3115
|
-
//#region node_modules/ws/lib/websocket.js
|
|
3119
|
+
// node_modules/ws/lib/websocket.js
|
|
3116
3120
|
var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3117
|
-
const EventEmitter
|
|
3121
|
+
const EventEmitter = __require("events");
|
|
3118
3122
|
const https = __require("https");
|
|
3119
|
-
const http
|
|
3123
|
+
const http = __require("http");
|
|
3120
3124
|
const net = __require("net");
|
|
3121
3125
|
const tls = __require("tls");
|
|
3122
|
-
const { randomBytes
|
|
3123
|
-
const { Duplex
|
|
3124
|
-
const { URL
|
|
3126
|
+
const { randomBytes, createHash } = __require("crypto");
|
|
3127
|
+
const { Duplex, Readable } = __require("stream");
|
|
3128
|
+
const { URL } = __require("url");
|
|
3125
3129
|
const PerMessageDeflate = require_permessage_deflate();
|
|
3126
3130
|
const Receiver = require_receiver();
|
|
3127
3131
|
const Sender = require_sender();
|
|
@@ -3144,7 +3148,7 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3144
3148
|
*
|
|
3145
3149
|
* @extends EventEmitter
|
|
3146
3150
|
*/
|
|
3147
|
-
var WebSocket = class WebSocket extends EventEmitter
|
|
3151
|
+
var WebSocket = class WebSocket extends EventEmitter {
|
|
3148
3152
|
/**
|
|
3149
3153
|
* Create a new `WebSocket`.
|
|
3150
3154
|
*
|
|
@@ -3670,9 +3674,9 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3670
3674
|
websocket._closeTimeout = opts.closeTimeout;
|
|
3671
3675
|
if (!protocolVersions.includes(opts.protocolVersion)) throw new RangeError(`Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(", ")})`);
|
|
3672
3676
|
let parsedUrl;
|
|
3673
|
-
if (address instanceof URL
|
|
3677
|
+
if (address instanceof URL) parsedUrl = address;
|
|
3674
3678
|
else try {
|
|
3675
|
-
parsedUrl = new URL
|
|
3679
|
+
parsedUrl = new URL(address);
|
|
3676
3680
|
} catch {
|
|
3677
3681
|
throw new SyntaxError(`Invalid URL: ${address}`);
|
|
3678
3682
|
}
|
|
@@ -3694,8 +3698,8 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3694
3698
|
}
|
|
3695
3699
|
}
|
|
3696
3700
|
const defaultPort = isSecure ? 443 : 80;
|
|
3697
|
-
const key = randomBytes
|
|
3698
|
-
const request = isSecure ? https.request : http
|
|
3701
|
+
const key = randomBytes(16).toString("base64");
|
|
3702
|
+
const request = isSecure ? https.request : http.request;
|
|
3699
3703
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
3700
3704
|
let perMessageDeflate;
|
|
3701
3705
|
opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
|
|
@@ -3732,9 +3736,14 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3732
3736
|
}
|
|
3733
3737
|
if (parsedUrl.username || parsedUrl.password) opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
|
|
3734
3738
|
if (isIpcUrl) {
|
|
3735
|
-
const
|
|
3736
|
-
|
|
3737
|
-
|
|
3739
|
+
const i = opts.path.indexOf(":");
|
|
3740
|
+
if (i === -1) {
|
|
3741
|
+
opts.socketPath = opts.path;
|
|
3742
|
+
opts.path = "";
|
|
3743
|
+
} else {
|
|
3744
|
+
opts.socketPath = opts.path.slice(0, i);
|
|
3745
|
+
opts.path = opts.path.slice(i + 1);
|
|
3746
|
+
}
|
|
3738
3747
|
}
|
|
3739
3748
|
let req;
|
|
3740
3749
|
if (opts.followRedirects) {
|
|
@@ -3780,7 +3789,7 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3780
3789
|
req.abort();
|
|
3781
3790
|
let addr;
|
|
3782
3791
|
try {
|
|
3783
|
-
addr = new URL
|
|
3792
|
+
addr = new URL(location, address);
|
|
3784
3793
|
} catch (e) {
|
|
3785
3794
|
emitErrorAndClose(websocket, /* @__PURE__ */ new SyntaxError(`Invalid URL: ${location}`));
|
|
3786
3795
|
return;
|
|
@@ -3797,7 +3806,7 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3797
3806
|
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
3798
3807
|
return;
|
|
3799
3808
|
}
|
|
3800
|
-
const digest = createHash
|
|
3809
|
+
const digest = createHash("sha1").update(key + GUID).digest("base64");
|
|
3801
3810
|
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
3802
3811
|
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
3803
3812
|
return;
|
|
@@ -4110,11 +4119,10 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4110
4119
|
}
|
|
4111
4120
|
}
|
|
4112
4121
|
}));
|
|
4113
|
-
|
|
4114
|
-
//#region node_modules/ws/lib/stream.js
|
|
4122
|
+
// node_modules/ws/lib/stream.js
|
|
4115
4123
|
var require_stream = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4116
4124
|
require_websocket();
|
|
4117
|
-
const { Duplex
|
|
4125
|
+
const { Duplex } = __require("stream");
|
|
4118
4126
|
/**
|
|
4119
4127
|
* Emits the `'close'` event on a stream.
|
|
4120
4128
|
*
|
|
@@ -4153,7 +4161,7 @@ var require_stream = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4153
4161
|
*/
|
|
4154
4162
|
function createWebSocketStream(ws, options) {
|
|
4155
4163
|
let terminateOnDestroy = true;
|
|
4156
|
-
const duplex = new Duplex
|
|
4164
|
+
const duplex = new Duplex({
|
|
4157
4165
|
...options,
|
|
4158
4166
|
autoDestroy: false,
|
|
4159
4167
|
emitClose: false,
|
|
@@ -4226,8 +4234,7 @@ var require_stream = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4226
4234
|
}
|
|
4227
4235
|
module.exports = createWebSocketStream;
|
|
4228
4236
|
}));
|
|
4229
|
-
|
|
4230
|
-
//#region node_modules/ws/lib/subprotocol.js
|
|
4237
|
+
// node_modules/ws/lib/subprotocol.js
|
|
4231
4238
|
var require_subprotocol = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4232
4239
|
const { tokenChars } = require_validation();
|
|
4233
4240
|
/**
|
|
@@ -4265,13 +4272,12 @@ var require_subprotocol = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4265
4272
|
}
|
|
4266
4273
|
module.exports = { parse };
|
|
4267
4274
|
}));
|
|
4268
|
-
|
|
4269
|
-
//#region node_modules/ws/lib/websocket-server.js
|
|
4275
|
+
// node_modules/ws/lib/websocket-server.js
|
|
4270
4276
|
var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4271
4277
|
const EventEmitter = __require("events");
|
|
4272
4278
|
const http = __require("http");
|
|
4273
4279
|
const { Duplex } = __require("stream");
|
|
4274
|
-
const { createHash
|
|
4280
|
+
const { createHash } = __require("crypto");
|
|
4275
4281
|
const extension = require_extension();
|
|
4276
4282
|
const PerMessageDeflate = require_permessage_deflate();
|
|
4277
4283
|
const subprotocol = require_subprotocol();
|
|
@@ -4541,7 +4547,7 @@ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module)
|
|
|
4541
4547
|
"HTTP/1.1 101 Switching Protocols",
|
|
4542
4548
|
"Upgrade: websocket",
|
|
4543
4549
|
"Connection: Upgrade",
|
|
4544
|
-
`Sec-WebSocket-Accept: ${createHash
|
|
4550
|
+
`Sec-WebSocket-Accept: ${createHash("sha1").update(key + GUID).digest("base64")}`
|
|
4545
4551
|
];
|
|
4546
4552
|
const ws = new this.options.WebSocket(null, void 0, this.options);
|
|
4547
4553
|
if (protocols.size) {
|
|
@@ -4660,8 +4666,91 @@ require_sender();
|
|
|
4660
4666
|
require_subprotocol();
|
|
4661
4667
|
var import_websocket = /* @__PURE__ */ __toESM(require_websocket(), 1);
|
|
4662
4668
|
require_websocket_server();
|
|
4663
|
-
|
|
4664
|
-
|
|
4669
|
+
// src/image.ts
|
|
4670
|
+
/**
|
|
4671
|
+
* Image input: getting a pasted image in front of the model.
|
|
4672
|
+
*
|
|
4673
|
+
* M365 does not take image bytes on the chat socket. The web client uploads the
|
|
4674
|
+
* image over HTTP first, gets a `docId` back, and the chat frame points at it with an
|
|
4675
|
+
* `ImageFile` message annotation. That flow is measured to work with the plain chat
|
|
4676
|
+
* token, with or without the declarative agent, and without any GPT-V `optionsSets`
|
|
4677
|
+
* on the turn itself (cramt/m365-copilot-proxy, hypotheses §33 F86).
|
|
4678
|
+
*/
|
|
4679
|
+
const log$2 = createLogger("image");
|
|
4680
|
+
/**
|
|
4681
|
+
* The image URLs in the messages from `fromIndex` on.
|
|
4682
|
+
*
|
|
4683
|
+
* Only what the turn carries: M365 keeps its own context, so an image from an earlier
|
|
4684
|
+
* turn is already there, and uploading it again would show it to the model twice.
|
|
4685
|
+
*/
|
|
4686
|
+
function collectImages(messages, fromIndex) {
|
|
4687
|
+
const urls = [];
|
|
4688
|
+
for (const message of messages.slice(fromIndex)) {
|
|
4689
|
+
if (message.role === "system" || message.role === "developer") continue;
|
|
4690
|
+
if (!Array.isArray(message.content)) continue;
|
|
4691
|
+
for (const part of message.content) {
|
|
4692
|
+
if (part.type !== "image_url") continue;
|
|
4693
|
+
const raw = part.image_url;
|
|
4694
|
+
const url = typeof raw === "string" ? raw : raw?.url;
|
|
4695
|
+
if (typeof url === "string" && url !== "") urls.push(url);
|
|
4696
|
+
}
|
|
4697
|
+
}
|
|
4698
|
+
return urls;
|
|
4699
|
+
}
|
|
4700
|
+
/** `png`, `jpg`, `svg`… for a base64 image data URL; null for anything else. */
|
|
4701
|
+
function imageFileType(url) {
|
|
4702
|
+
const match = /^data:image\/([a-z0-9.+-]+);base64,/i.exec(url);
|
|
4703
|
+
if (!match) return null;
|
|
4704
|
+
const subtype = match[1].toLowerCase().replace(/\+.*$/, "");
|
|
4705
|
+
return subtype === "jpeg" ? "jpg" : subtype;
|
|
4706
|
+
}
|
|
4707
|
+
/** Upload one image and return the annotation that points a chat turn at it. */
|
|
4708
|
+
async function uploadImage(dataUrl, options) {
|
|
4709
|
+
const fileType = imageFileType(dataUrl);
|
|
4710
|
+
if (!fileType) throw new Error("only base64 image data URLs can be uploaded");
|
|
4711
|
+
const form = new URLSearchParams();
|
|
4712
|
+
form.append("scenario", "UploadImage");
|
|
4713
|
+
form.append("conversationId", options.conversationId);
|
|
4714
|
+
form.append("FileBase64", dataUrl);
|
|
4715
|
+
form.append("optionsSets", "cwcgptvsan");
|
|
4716
|
+
form.append("optionsSets", "flux_v3_gptv_enable_upload_multi_image_in_turn_wo_ch");
|
|
4717
|
+
const response = await fetch(`${options.origin}/m365Copilot/UploadFile`, {
|
|
4718
|
+
method: "POST",
|
|
4719
|
+
headers: {
|
|
4720
|
+
Authorization: `Bearer ${options.token}`,
|
|
4721
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
4722
|
+
"X-Scenario": "OfficeWebIncludedCopilot",
|
|
4723
|
+
"X-Variants": "feature.EnableImageSupportInUploadFile",
|
|
4724
|
+
Origin: "https://m365.cloud.microsoft",
|
|
4725
|
+
Referer: "https://m365.cloud.microsoft/"
|
|
4726
|
+
},
|
|
4727
|
+
body: form.toString(),
|
|
4728
|
+
...options.signal ? { signal: options.signal } : {}
|
|
4729
|
+
});
|
|
4730
|
+
const body = await response.text();
|
|
4731
|
+
if (!response.ok) throw new Error(`image upload failed: HTTP ${response.status}`);
|
|
4732
|
+
let docId;
|
|
4733
|
+
try {
|
|
4734
|
+
docId = JSON.parse(body)?.docId;
|
|
4735
|
+
} catch {}
|
|
4736
|
+
if (typeof docId !== "string" || docId === "") throw new Error("image upload returned no docId");
|
|
4737
|
+
log$2.info("uploaded image", {
|
|
4738
|
+
fileType,
|
|
4739
|
+
chars: dataUrl.length,
|
|
4740
|
+
docId
|
|
4741
|
+
});
|
|
4742
|
+
return {
|
|
4743
|
+
id: docId,
|
|
4744
|
+
messageAnnotationType: "ImageFile",
|
|
4745
|
+
messageAnnotationMetadata: {
|
|
4746
|
+
"@type": "File",
|
|
4747
|
+
annotationType: "File",
|
|
4748
|
+
fileType,
|
|
4749
|
+
fileName: `image-${randomUUID().slice(0, 8)}.${fileType}`
|
|
4750
|
+
}
|
|
4751
|
+
};
|
|
4752
|
+
}
|
|
4753
|
+
// src/session.ts
|
|
4665
4754
|
/**
|
|
4666
4755
|
* The M365 Copilot transport: SignalR over WebSocket.
|
|
4667
4756
|
*
|
|
@@ -4765,15 +4854,47 @@ var CopilotSession = class {
|
|
|
4765
4854
|
const token = await this.options.getToken();
|
|
4766
4855
|
const { oid, tid } = decodeJwt(token);
|
|
4767
4856
|
const url = this.buildUrl(token, oid, tid);
|
|
4857
|
+
const { annotations, note } = await this.uploadImages(token, turn);
|
|
4858
|
+
const message = {
|
|
4859
|
+
text: note ? `${text}\n\n${note}` : text,
|
|
4860
|
+
annotations
|
|
4861
|
+
};
|
|
4768
4862
|
const socket = new import_websocket.default(url, { headers: BROWSER_HEADERS });
|
|
4769
4863
|
try {
|
|
4770
|
-
const result = await this.pump(socket,
|
|
4864
|
+
const result = await this.pump(socket, message, turn);
|
|
4771
4865
|
this.turnIndex += 1;
|
|
4772
4866
|
return result;
|
|
4773
4867
|
} finally {
|
|
4774
4868
|
closeSocket(socket);
|
|
4775
4869
|
}
|
|
4776
4870
|
}
|
|
4871
|
+
/**
|
|
4872
|
+
* Upload the turn's images. A failure costs that image, not the turn: the model is
|
|
4873
|
+
* told what did not arrive, so it says so instead of describing a picture it never
|
|
4874
|
+
* received.
|
|
4875
|
+
*/
|
|
4876
|
+
async uploadImages(token, turn) {
|
|
4877
|
+
const images = turn.images ?? [];
|
|
4878
|
+
const annotations = [];
|
|
4879
|
+
const origin = (this.options.endpoint ?? DEFAULT_ENDPOINT).replace(/^ws/, "http");
|
|
4880
|
+
for (const image of images) try {
|
|
4881
|
+
annotations.push(await uploadImage(image, {
|
|
4882
|
+
token,
|
|
4883
|
+
conversationId: this.conversationId,
|
|
4884
|
+
origin,
|
|
4885
|
+
...turn.signal ? { signal: turn.signal } : {}
|
|
4886
|
+
}));
|
|
4887
|
+
} catch (error) {
|
|
4888
|
+
if (turn.signal?.aborted) throw abortError();
|
|
4889
|
+
log$1.warn("image not attached", error instanceof Error ? error.message : String(error));
|
|
4890
|
+
}
|
|
4891
|
+
const missing = images.length - annotations.length;
|
|
4892
|
+
if (missing === 0) return { annotations };
|
|
4893
|
+
return {
|
|
4894
|
+
annotations,
|
|
4895
|
+
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
|
+
};
|
|
4897
|
+
}
|
|
4777
4898
|
buildUrl(token, oid, tid) {
|
|
4778
4899
|
return `${this.options.endpoint ?? DEFAULT_ENDPOINT}/m365Copilot/Chathub/${oid}@${tid}?${new URLSearchParams({
|
|
4779
4900
|
access_token: token,
|
|
@@ -4789,7 +4910,7 @@ var CopilotSession = class {
|
|
|
4789
4910
|
}).toString()}`;
|
|
4790
4911
|
}
|
|
4791
4912
|
/** Drive one turn to completion. */
|
|
4792
|
-
pump(socket,
|
|
4913
|
+
pump(socket, outgoing, turn) {
|
|
4793
4914
|
return new Promise((resolve, reject) => {
|
|
4794
4915
|
let deltaText = "";
|
|
4795
4916
|
let snapshotText = "";
|
|
@@ -4834,7 +4955,7 @@ var CopilotSession = class {
|
|
|
4834
4955
|
for (const frame of splitFrames(raw.toString())) {
|
|
4835
4956
|
if (!handshakeDone) {
|
|
4836
4957
|
handshakeDone = true;
|
|
4837
|
-
this.sendChat(socket,
|
|
4958
|
+
this.sendChat(socket, outgoing, turn);
|
|
4838
4959
|
if (Object.keys(frame).length === 0) continue;
|
|
4839
4960
|
}
|
|
4840
4961
|
switch (frame.type) {
|
|
@@ -4876,18 +4997,21 @@ var CopilotSession = class {
|
|
|
4876
4997
|
});
|
|
4877
4998
|
}
|
|
4878
4999
|
/** The chat invocation and its mandatory Metrics companion, in one send. */
|
|
4879
|
-
sendChat(socket,
|
|
5000
|
+
sendChat(socket, outgoing, turn) {
|
|
4880
5001
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
5002
|
+
const { text } = outgoing;
|
|
5003
|
+
const message = {
|
|
5004
|
+
text,
|
|
5005
|
+
author: "user",
|
|
5006
|
+
inputMethod: "Keyboard",
|
|
5007
|
+
messageType: "Chat",
|
|
5008
|
+
locale: "en-US",
|
|
5009
|
+
timestamp: now,
|
|
5010
|
+
messageId: randomUUID()
|
|
5011
|
+
};
|
|
5012
|
+
if (outgoing.annotations.length > 0) message.messageAnnotations = outgoing.annotations;
|
|
4881
5013
|
const argument = {
|
|
4882
|
-
message
|
|
4883
|
-
text,
|
|
4884
|
-
author: "user",
|
|
4885
|
-
inputMethod: "Keyboard",
|
|
4886
|
-
messageType: "Chat",
|
|
4887
|
-
locale: "en-US",
|
|
4888
|
-
timestamp: now,
|
|
4889
|
-
messageId: randomUUID()
|
|
4890
|
-
},
|
|
5014
|
+
message,
|
|
4891
5015
|
tone: turn.tone ?? "magic",
|
|
4892
5016
|
source: "officeweb",
|
|
4893
5017
|
streamingMode: "ConciseWithPadding",
|
|
@@ -4939,6 +5063,7 @@ var CopilotSession = class {
|
|
|
4939
5063
|
log$1.info("sending turn", trunc({
|
|
4940
5064
|
tone: argument.tone,
|
|
4941
5065
|
agent: Boolean(turn.agentId),
|
|
5066
|
+
images: outgoing.annotations.length,
|
|
4942
5067
|
text
|
|
4943
5068
|
}));
|
|
4944
5069
|
socket.send(`${JSON.stringify(chat)}${RS}${JSON.stringify(metrics)}${RS}`);
|
|
@@ -5027,8 +5152,7 @@ function abortError() {
|
|
|
5027
5152
|
error.name = "AbortError";
|
|
5028
5153
|
return error;
|
|
5029
5154
|
}
|
|
5030
|
-
|
|
5031
|
-
//#region node_modules/zod/v4/core/util.js
|
|
5155
|
+
// node_modules/zod/v4/core/util.js
|
|
5032
5156
|
function getEnumValues(entries) {
|
|
5033
5157
|
const numericValues = Object.values(entries).filter((v) => typeof v === "number");
|
|
5034
5158
|
return Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
|
|
@@ -5335,6 +5459,17 @@ function prefixIssues(path, issues) {
|
|
|
5335
5459
|
function unwrapMessage(message) {
|
|
5336
5460
|
return typeof message === "string" ? message : message?.message;
|
|
5337
5461
|
}
|
|
5462
|
+
/** The leading size checks of `defChecks` that set an upper bound, each paired with it. */
|
|
5463
|
+
function sizeCaps(defChecks) {
|
|
5464
|
+
const caps = [];
|
|
5465
|
+
for (const ch of defChecks ?? []) {
|
|
5466
|
+
const d = ch._zod.def;
|
|
5467
|
+
if (!/_(length|size)$|_equals$/.test(d.check)) break;
|
|
5468
|
+
const max = d.maximum ?? d.length ?? d.size;
|
|
5469
|
+
if (max >= 0) caps.push([max, ch]);
|
|
5470
|
+
}
|
|
5471
|
+
return caps;
|
|
5472
|
+
}
|
|
5338
5473
|
function attachSchema(issues, start, inst) {
|
|
5339
5474
|
var _a;
|
|
5340
5475
|
for (let i = start; i < issues.length; i++) (_a = issues[i]).schema ?? (_a.schema = inst);
|
|
@@ -5427,6 +5562,7 @@ function hide(inst, key, value) {
|
|
|
5427
5562
|
return own(inst, key, value, false);
|
|
5428
5563
|
}
|
|
5429
5564
|
/** Adds members a table derives from the instance: each builds on first read and shadows as own data, and assignment shadows the same way, as when these were own properties. */
|
|
5565
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
5430
5566
|
function derived(computes, table) {
|
|
5431
5567
|
for (const key in computes) {
|
|
5432
5568
|
const compute = computes[key];
|
|
@@ -5550,8 +5686,7 @@ function constantCatch(value) {
|
|
|
5550
5686
|
fn[CONSTANT_CATCH] = true;
|
|
5551
5687
|
return fn;
|
|
5552
5688
|
}
|
|
5553
|
-
|
|
5554
|
-
//#region node_modules/zod/v4/core/core.js
|
|
5689
|
+
// node_modules/zod/v4/core/core.js
|
|
5555
5690
|
var _a$1;
|
|
5556
5691
|
const _zodDesc = {
|
|
5557
5692
|
value: void 0,
|
|
@@ -5578,6 +5713,7 @@ function newError(Definition) {
|
|
|
5578
5713
|
}
|
|
5579
5714
|
return new Definition();
|
|
5580
5715
|
}
|
|
5716
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
5581
5717
|
function $constructor(name, initializer, proto, params) {
|
|
5582
5718
|
const zodProto = {};
|
|
5583
5719
|
function Internals(def) {
|
|
@@ -5656,8 +5792,7 @@ function config(newConfig) {
|
|
|
5656
5792
|
if (newConfig) Object.assign(globalConfig, newConfig);
|
|
5657
5793
|
return globalConfig;
|
|
5658
5794
|
}
|
|
5659
|
-
|
|
5660
|
-
//#region node_modules/zod/v4/core/errors.js
|
|
5795
|
+
// node_modules/zod/v4/core/errors.js
|
|
5661
5796
|
function _getMessage() {
|
|
5662
5797
|
const internals = this._zod;
|
|
5663
5798
|
internals.message ?? (internals.message = JSON.stringify(internals.def, jsonStringifyReplacer, 2));
|
|
@@ -5708,8 +5843,7 @@ const initializer$1 = (inst, def) => {
|
|
|
5708
5843
|
});
|
|
5709
5844
|
}
|
|
5710
5845
|
};
|
|
5711
|
-
const $ZodError = $constructor("$ZodError", initializer$1);
|
|
5712
|
-
$constructor("$ZodError", initializer$1, void 0, { Parent: Error });
|
|
5846
|
+
const $ZodError = /* @__PURE__ */ $constructor("$ZodError", initializer$1);
|
|
5713
5847
|
/** Get-or-create `obj[key]` as an own data property. A path segment naming an inherited member
|
|
5714
5848
|
* ("toString", "constructor") would otherwise read through to the prototype, and assigning
|
|
5715
5849
|
* "__proto__" would hit the setter instead of creating a key. */
|
|
@@ -5772,8 +5906,7 @@ function formatError(error, mapper = (issue) => issue.message) {
|
|
|
5772
5906
|
processError(error);
|
|
5773
5907
|
return fieldErrors;
|
|
5774
5908
|
}
|
|
5775
|
-
|
|
5776
|
-
//#region node_modules/zod/v4/core/parse.js
|
|
5909
|
+
// node_modules/zod/v4/core/parse.js
|
|
5777
5910
|
function finalizeParams(callee, params) {
|
|
5778
5911
|
return {
|
|
5779
5912
|
callee: params?.callee ?? callee,
|
|
@@ -5975,8 +6108,7 @@ const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
|
5975
6108
|
const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
5976
6109
|
return _safeParseAsync(_Err)(schema, value, _ctx);
|
|
5977
6110
|
};
|
|
5978
|
-
|
|
5979
|
-
//#region node_modules/zod/v4/core/regexes.js
|
|
6111
|
+
// node_modules/zod/v4/core/regexes.js
|
|
5980
6112
|
/**
|
|
5981
6113
|
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
5982
6114
|
* (timestamps embedded in the id). Use {@link cuid2} instead.
|
|
@@ -6047,8 +6179,7 @@ const boolean$1 = /^(?:true|false)$/i;
|
|
|
6047
6179
|
const _null$2 = /^null$/i;
|
|
6048
6180
|
const lowercase = /^[^A-Z]*$/;
|
|
6049
6181
|
const uppercase = /^[^a-z]*$/;
|
|
6050
|
-
|
|
6051
|
-
//#region node_modules/zod/v4/core/checks.js
|
|
6182
|
+
// node_modules/zod/v4/core/checks.js
|
|
6052
6183
|
const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def) => {
|
|
6053
6184
|
var _a;
|
|
6054
6185
|
inst._zod ?? (inst._zod = {});
|
|
@@ -6343,8 +6474,7 @@ const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (ins
|
|
|
6343
6474
|
payload.value = def.tx(payload.value);
|
|
6344
6475
|
};
|
|
6345
6476
|
});
|
|
6346
|
-
|
|
6347
|
-
//#region node_modules/zod/v4/core/doc.js
|
|
6477
|
+
// node_modules/zod/v4/core/doc.js
|
|
6348
6478
|
var Doc = class {
|
|
6349
6479
|
constructor(args = [], closed = {}) {
|
|
6350
6480
|
this.content = [];
|
|
@@ -6377,15 +6507,13 @@ var Doc = class {
|
|
|
6377
6507
|
return new F(...Object.keys(this.closed), `return function (${this.args.join(", ")}) {\n${content.join("\n")}\n};`)(...Object.values(this.closed));
|
|
6378
6508
|
}
|
|
6379
6509
|
};
|
|
6380
|
-
|
|
6381
|
-
//#region node_modules/zod/v4/core/versions.js
|
|
6510
|
+
// node_modules/zod/v4/core/versions.js
|
|
6382
6511
|
const version = {
|
|
6383
6512
|
major: 4,
|
|
6384
6513
|
minor: 6,
|
|
6385
|
-
patch:
|
|
6514
|
+
patch: 7
|
|
6386
6515
|
};
|
|
6387
|
-
|
|
6388
|
-
//#region node_modules/zod/v4/core/schemas.js
|
|
6516
|
+
// node_modules/zod/v4/core/schemas.js
|
|
6389
6517
|
const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
|
|
6390
6518
|
var _a;
|
|
6391
6519
|
inst ?? (inst = {});
|
|
@@ -6902,6 +7030,26 @@ const $ZodNever = /*@__PURE__*/ $constructor("$ZodNever", (inst, def) => {
|
|
|
6902
7030
|
return payload;
|
|
6903
7031
|
};
|
|
6904
7032
|
});
|
|
7033
|
+
function capSize(inst, size) {
|
|
7034
|
+
const caps = sizeCaps(inst._zod.def.checks);
|
|
7035
|
+
if (!caps.length) return;
|
|
7036
|
+
const cap = Math.min(...caps.map((c) => c[0]));
|
|
7037
|
+
const parse = inst._zod.parse;
|
|
7038
|
+
inst._zod.parse = (payload, ctx) => {
|
|
7039
|
+
const n = size(payload.value);
|
|
7040
|
+
if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
|
|
7041
|
+
for (const [max, ch] of sizeCaps(inst._zod.def.checks)) if (n > max && ch._zod.def.when(payload)) {
|
|
7042
|
+
const start = payload.issues.length;
|
|
7043
|
+
ch._zod.check(payload);
|
|
7044
|
+
payload.issues[start].continue = false;
|
|
7045
|
+
attachSchema(payload.issues, start, inst);
|
|
7046
|
+
return payload;
|
|
7047
|
+
}
|
|
7048
|
+
}
|
|
7049
|
+
return parse(payload, ctx);
|
|
7050
|
+
};
|
|
7051
|
+
}
|
|
7052
|
+
const arraySize = (input) => Array.isArray(input) ? input.length : -1;
|
|
6905
7053
|
function handleArrayResult(result, final, index) {
|
|
6906
7054
|
if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
|
|
6907
7055
|
final.value[index] = result.value;
|
|
@@ -6939,6 +7087,7 @@ const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
|
|
|
6939
7087
|
if (proms.length) return Promise.all(proms).then(() => payload);
|
|
6940
7088
|
return payload;
|
|
6941
7089
|
};
|
|
7090
|
+
capSize(inst, arraySize);
|
|
6942
7091
|
});
|
|
6943
7092
|
function handlePropertyResult(result, final, key, input, optin, optout) {
|
|
6944
7093
|
const isPresent = key in input;
|
|
@@ -7047,7 +7196,7 @@ const $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def) => {
|
|
|
7047
7196
|
}
|
|
7048
7197
|
return propValues;
|
|
7049
7198
|
});
|
|
7050
|
-
const isObject$
|
|
7199
|
+
const isObject$1 = isObject;
|
|
7051
7200
|
const catchall = def.catchall;
|
|
7052
7201
|
let value;
|
|
7053
7202
|
const memo = globalConfig.memoizer;
|
|
@@ -7055,7 +7204,7 @@ const $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def) => {
|
|
|
7055
7204
|
inst._zod.parse = (payload, ctx) => {
|
|
7056
7205
|
value ?? (value = _normalized.value);
|
|
7057
7206
|
const input = payload.value;
|
|
7058
|
-
if (!isObject$
|
|
7207
|
+
if (!isObject$1(input)) {
|
|
7059
7208
|
payload.issues.push({
|
|
7060
7209
|
expected: "object",
|
|
7061
7210
|
code: "invalid_type",
|
|
@@ -7185,7 +7334,7 @@ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
7185
7334
|
return doc.compile();
|
|
7186
7335
|
};
|
|
7187
7336
|
let fastpass;
|
|
7188
|
-
const isObject$
|
|
7337
|
+
const isObject$2 = isObject;
|
|
7189
7338
|
const jit = !globalConfig.jitless;
|
|
7190
7339
|
const fastEnabled = jit && allowsEval.value;
|
|
7191
7340
|
const catchall = def.catchall;
|
|
@@ -7193,7 +7342,7 @@ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
7193
7342
|
inst._zod.parse = (payload, ctx) => {
|
|
7194
7343
|
value ?? (value = _normalized.value);
|
|
7195
7344
|
const input = payload.value;
|
|
7196
|
-
if (!isObject$
|
|
7345
|
+
if (!isObject$2(input)) {
|
|
7197
7346
|
payload.issues.push({
|
|
7198
7347
|
expected: "object",
|
|
7199
7348
|
code: "invalid_type",
|
|
@@ -7642,8 +7791,7 @@ function handleRefineResult(result, payload, input, inst) {
|
|
|
7642
7791
|
payload.issues.push(issue(_iss));
|
|
7643
7792
|
}
|
|
7644
7793
|
}
|
|
7645
|
-
|
|
7646
|
-
//#region node_modules/zod/v4/core/memoizer.js
|
|
7794
|
+
// node_modules/zod/v4/core/memoizer.js
|
|
7647
7795
|
var $ZodCyclicError = class extends Error {
|
|
7648
7796
|
constructor() {
|
|
7649
7797
|
super(`Cannot parse a reference cycle that closes through a transform`);
|
|
@@ -7895,8 +8043,7 @@ function isBackEdge(ctx, value) {
|
|
|
7895
8043
|
const backEdges = ctx[STATE]?.backEdges;
|
|
7896
8044
|
return backEdges !== void 0 && isRef(value) && backEdges.has(value);
|
|
7897
8045
|
}
|
|
7898
|
-
|
|
7899
|
-
//#region node_modules/zod/v4/locales/en.js
|
|
8046
|
+
// node_modules/zod/v4/locales/en.js
|
|
7900
8047
|
const error = () => {
|
|
7901
8048
|
const Sizable = {
|
|
7902
8049
|
string: {
|
|
@@ -8003,8 +8150,7 @@ const error = () => {
|
|
|
8003
8150
|
function en_default() {
|
|
8004
8151
|
return { localeError: error() };
|
|
8005
8152
|
}
|
|
8006
|
-
|
|
8007
|
-
//#region node_modules/zod/v4/core/registries.js
|
|
8153
|
+
// node_modules/zod/v4/core/registries.js
|
|
8008
8154
|
var _a;
|
|
8009
8155
|
var $ZodRegistry = class {
|
|
8010
8156
|
constructor() {
|
|
@@ -8050,8 +8196,7 @@ function registry() {
|
|
|
8050
8196
|
}
|
|
8051
8197
|
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
|
8052
8198
|
const globalRegistry = globalThis.__zod_globalRegistry;
|
|
8053
|
-
|
|
8054
|
-
//#region node_modules/zod/v4/core/api.js
|
|
8199
|
+
// node_modules/zod/v4/core/api.js
|
|
8055
8200
|
function snapshotChecks(def) {
|
|
8056
8201
|
if (def.checks) def.checks = [...def.checks];
|
|
8057
8202
|
return def;
|
|
@@ -8570,8 +8715,7 @@ function _check(fn, params) {
|
|
|
8570
8715
|
ch._zod.check = fn;
|
|
8571
8716
|
return ch;
|
|
8572
8717
|
}
|
|
8573
|
-
|
|
8574
|
-
//#region node_modules/zod/v4/core/to-json-schema.js
|
|
8718
|
+
// node_modules/zod/v4/core/to-json-schema.js
|
|
8575
8719
|
function assignProps(target, ...sources) {
|
|
8576
8720
|
for (const source of sources) for (const key of Reflect.ownKeys(source)) if (Object.prototype.propertyIsEnumerable.call(source, key)) assignProp(target, key, source[key]);
|
|
8577
8721
|
return target;
|
|
@@ -9014,8 +9158,7 @@ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params)
|
|
|
9014
9158
|
extractDefs(ctx, schema);
|
|
9015
9159
|
return finalize(ctx, schema);
|
|
9016
9160
|
};
|
|
9017
|
-
|
|
9018
|
-
//#region node_modules/zod/v4/core/json-schema-processors.js
|
|
9161
|
+
// node_modules/zod/v4/core/json-schema-processors.js
|
|
9019
9162
|
const narrowMin = (agg, key, value) => {
|
|
9020
9163
|
if (agg[key] === void 0 || value > agg[key]) agg[key] = value;
|
|
9021
9164
|
};
|
|
@@ -9368,8 +9511,7 @@ const optionalProcessor = (schema, ctx, _json, params) => {
|
|
|
9368
9511
|
const seen = ctx.seen.get(schema);
|
|
9369
9512
|
seen.ref = def.innerType;
|
|
9370
9513
|
};
|
|
9371
|
-
|
|
9372
|
-
//#region node_modules/zod/v4/classic/errors.js
|
|
9514
|
+
// node_modules/zod/v4/classic/errors.js
|
|
9373
9515
|
const _installedErrorProtos = /* @__PURE__ */ new WeakSet([Object.prototype, Error.prototype]);
|
|
9374
9516
|
function _lazyMethod(proto, key, make) {
|
|
9375
9517
|
Object.defineProperty(proto, key, {
|
|
@@ -9418,8 +9560,7 @@ const initializer = (inst, issues) => {
|
|
|
9418
9560
|
});
|
|
9419
9561
|
};
|
|
9420
9562
|
const ZodRealError = /*@__PURE__*/ $constructor("ZodError", initializer, void 0, { Parent: Error });
|
|
9421
|
-
|
|
9422
|
-
//#region node_modules/zod/v4/classic/parse.js
|
|
9563
|
+
// node_modules/zod/v4/classic/parse.js
|
|
9423
9564
|
const parse$1 = /* @__PURE__ */ _parse(ZodRealError);
|
|
9424
9565
|
const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
|
|
9425
9566
|
const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
|
|
@@ -9432,8 +9573,7 @@ const safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
|
|
|
9432
9573
|
const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
|
|
9433
9574
|
const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
|
|
9434
9575
|
const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
|
|
9435
|
-
|
|
9436
|
-
//#region node_modules/zod/v4/classic/schemas.js
|
|
9576
|
+
// node_modules/zod/v4/classic/schemas.js
|
|
9437
9577
|
function _ensureDefaultLocale() {
|
|
9438
9578
|
if (!globalConfig.localeError) config(en_default());
|
|
9439
9579
|
}
|
|
@@ -10296,8 +10436,7 @@ function refine(fn, _params = {}) {
|
|
|
10296
10436
|
function superRefine(fn, params) {
|
|
10297
10437
|
return /* @__PURE__ */ _superRefine(fn, params);
|
|
10298
10438
|
}
|
|
10299
|
-
|
|
10300
|
-
//#region src/translate.ts
|
|
10439
|
+
// src/translate.ts
|
|
10301
10440
|
/**
|
|
10302
10441
|
* OpenAI ⇄ M365 translation.
|
|
10303
10442
|
*
|
|
@@ -10404,6 +10543,9 @@ function contentOf(message) {
|
|
|
10404
10543
|
if (Array.isArray(content)) return content.map((part) => typeof part.text === "string" ? part.text : "").filter(Boolean).join("\n");
|
|
10405
10544
|
return "";
|
|
10406
10545
|
}
|
|
10546
|
+
function hasImagePart(message) {
|
|
10547
|
+
return Array.isArray(message.content) && message.content.some((part) => part.type === "image_url");
|
|
10548
|
+
}
|
|
10407
10549
|
/**
|
|
10408
10550
|
* Capability catalogues a harness injects into its system prompt, and the tool each
|
|
10409
10551
|
* one needs in order to be actionable.
|
|
@@ -10517,7 +10659,7 @@ function buildTurnPrompt(messages, tools, sentMessageCount, options = {}) {
|
|
|
10517
10659
|
if (text) parts.push(text);
|
|
10518
10660
|
continue;
|
|
10519
10661
|
}
|
|
10520
|
-
const text = contentOf(message);
|
|
10662
|
+
const text = contentOf(message) || (hasImagePart(message) ? "(See the attached image.)" : "");
|
|
10521
10663
|
if (text) parts.push(text);
|
|
10522
10664
|
}
|
|
10523
10665
|
return parts.filter(Boolean).join("\n\n");
|
|
@@ -10654,8 +10796,7 @@ function generateTitle(messages) {
|
|
|
10654
10796
|
function firstLine(text) {
|
|
10655
10797
|
return text.split("\n", 1)[0] ?? "";
|
|
10656
10798
|
}
|
|
10657
|
-
|
|
10658
|
-
//#region src/server.ts
|
|
10799
|
+
// src/server.ts
|
|
10659
10800
|
/**
|
|
10660
10801
|
* The OpenAI-compatible HTTP surface.
|
|
10661
10802
|
*
|
|
@@ -10859,6 +11000,7 @@ async function runTurn(request, response, context, body, conversation, model, to
|
|
|
10859
11000
|
getToken: context.deps.getToken,
|
|
10860
11001
|
...context.deps.endpoint ? { endpoint: context.deps.endpoint } : {}
|
|
10861
11002
|
});
|
|
11003
|
+
const images = collectImages(body.messages, conversation.sentMessageCount);
|
|
10862
11004
|
const prompt = buildTurnPrompt(body.messages, tools, conversation.sentMessageCount, { ...context.deps.leanSystemPrompt !== void 0 ? { leanSystemPrompt: context.deps.leanSystemPrompt } : {} });
|
|
10863
11005
|
const agent = tools.length > 0 ? await context.agentId() : null;
|
|
10864
11006
|
const abort = new AbortController();
|
|
@@ -10874,6 +11016,7 @@ async function runTurn(request, response, context, body, conversation, model, to
|
|
|
10874
11016
|
...model.tone ? { tone: model.tone } : {},
|
|
10875
11017
|
agentId: agent,
|
|
10876
11018
|
signal: abort.signal,
|
|
11019
|
+
...images.length > 0 ? { images } : {},
|
|
10877
11020
|
...canStreamText ? { onDelta: (chunk) => response.write(streamChunk(streamId, model.id, { content: chunk })) } : {}
|
|
10878
11021
|
});
|
|
10879
11022
|
conversation.sentMessageCount = body.messages.length + 1;
|
|
@@ -10994,5 +11137,4 @@ async function readBody(request, limit) {
|
|
|
10994
11137
|
}
|
|
10995
11138
|
return Buffer.concat(chunks).toString("utf8");
|
|
10996
11139
|
}
|
|
10997
|
-
//#endregion
|
|
10998
11140
|
export { resolveOptions as A, SECRETS_FILE as C, buildModelInfos as D, applyPluginConfig as E, __require as F, __toESM as I, LOCAL_TITLE_MODEL as M, isLocalModel as N, buildProviderInfo as O, __commonJSMin 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, DEFAULT_MODEL as j, mergeOpencodeConfig 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 };
|