@nexface/agent 0.1.15-alpha.0 → 0.1.15-alpha.2
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/dist/agent.d.ts +1 -2
- package/dist/agent.js +918 -333
- package/dist/browser-policy/gpt.js +36 -12
- package/dist/browser-policy/jev.js +21 -9
- package/dist/browser-policy/response-error.js +4 -2
- package/dist/browser-policy/shared.js +49 -21
- package/dist/browser-prompt.generated.js +0 -1
- package/dist/browser-prompt.js +0 -1
- package/dist/errors.d.ts +2 -2
- package/dist/errors.js +3 -4
- package/dist/history-compaction.js +47 -26
- package/dist/history-version.js +11 -4
- package/dist/index.js +0 -1
- package/dist/model/binding.js +0 -1
- package/dist/model/error.js +0 -1
- package/dist/model/internal-adapter.js +1 -2
- package/dist/model/types.js +0 -1
- package/dist/models/3.js +5553 -0
- package/dist/models/3e.js +4 -0
- package/dist/models/6.js +506 -0
- package/dist/models/anthropic-messages.js +5 -20
- package/dist/models/anthropic-messages~1.js +5629 -0
- package/dist/models/deferred-tools.js +28 -0
- package/dist/models/error-body.js +64 -0
- package/dist/models/google-generative-ai.js +4 -19
- package/dist/models/google-generative-ai~1.js +18305 -0
- package/dist/models/google-generative-ai~1.js.LICENSE.txt +5 -0
- package/dist/models/{39.js → k.js} +168 -336
- package/dist/models/openai-completions.js +3 -10
- package/dist/models/openai-completions~1.js +987 -0
- package/dist/models/openai-responses.js +3 -10
- package/dist/models/openai-responses~1.js +848 -0
- package/dist/models/rslib-runtime.js +32 -56
- package/dist/models/v.js +346 -0
- package/dist/page-decision.js +197 -59
- package/dist/page-decisions/gpt.js +0 -1
- package/dist/page-decisions/jev.js +0 -1
- package/dist/page-decisions/shared.js +26 -9
- package/dist/page-diagnostics.js +8 -3
- package/dist/page-observation.js +11 -6
- package/dist/request.js +169 -41
- package/dist/shared/definition.js +2 -3
- package/dist/shared/errors.d.ts +1 -1
- package/dist/shared/errors.js +0 -1
- package/dist/shared/page-protocol.js +0 -1
- package/dist/shared/page-tools.js +0 -1
- package/dist/shared/runtime-controller.d.ts +1 -0
- package/dist/shared/runtime-controller.js +0 -1
- package/dist/shared/runtime-execution.js +0 -1
- package/dist/shared/schema.js +45 -19
- package/dist/tool-catalog.js +23 -25
- package/dist/tool-result.js +7 -3
- package/dist/types.js +0 -1
- package/package.json +6 -2
- package/dist/agent.js.map +0 -1
- package/dist/browser-policy/gpt.js.map +0 -1
- package/dist/browser-policy/jev.js.map +0 -1
- package/dist/browser-policy/response-error.js.map +0 -1
- package/dist/browser-policy/shared.js.map +0 -1
- package/dist/browser-prompt.generated.js.map +0 -1
- package/dist/browser-prompt.js.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/history-compaction.js.map +0 -1
- package/dist/history-version.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/model/binding.js.map +0 -1
- package/dist/model/error.js.map +0 -1
- package/dist/model/internal-adapter.js.map +0 -1
- package/dist/model/types.js.map +0 -1
- package/dist/models/851.js +0 -10
- package/dist/models/_chunks/360-7e580bb2.js +0 -1189
- package/dist/models/_chunks/474-e1813138.js +0 -8304
- package/dist/models/_chunks/86-c0c5ac98.js +0 -453
- package/dist/models/_chunks/anthropic-messages~1-d35e3e7d.js +0 -8057
- package/dist/models/_chunks/deferred-tools-90f3c977.js +0 -37
- package/dist/models/_chunks/error-body-8bee35c2.js +0 -134
- package/dist/models/_chunks/google-generative-ai~1-2ba71457.js +0 -22104
- package/dist/models/_chunks/openai-completions~1-b340f0e0.js +0 -1285
- package/dist/models/_chunks/openai-responses~1-b53c65c2.js +0 -958
- package/dist/page-decision.js.map +0 -1
- package/dist/page-decisions/gpt.js.map +0 -1
- package/dist/page-decisions/jev.js.map +0 -1
- package/dist/page-decisions/shared.js.map +0 -1
- package/dist/page-diagnostics.js.map +0 -1
- package/dist/page-observation.js.map +0 -1
- package/dist/request.js.map +0 -1
- package/dist/shared/definition.js.map +0 -1
- package/dist/shared/errors.js.map +0 -1
- package/dist/shared/page-protocol.js.map +0 -1
- package/dist/shared/page-tools.js.map +0 -1
- package/dist/shared/runtime-controller.js.map +0 -1
- package/dist/shared/runtime-execution.js.map +0 -1
- package/dist/shared/schema.js.map +0 -1
- package/dist/shared/tool-registry.d.ts +0 -6
- package/dist/shared/tool-registry.js +0 -10
- package/dist/shared/tool-registry.js.map +0 -1
- package/dist/tool-catalog.js.map +0 -1
- package/dist/tool-result.js.map +0 -1
- package/dist/types.js.map +0 -1
|
@@ -1,59 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return
|
|
1
|
+
var modules = {};
|
|
2
|
+
var moduleCache = {};
|
|
3
|
+
function rspackRequire(moduleId) {
|
|
4
|
+
var cachedModule = moduleCache[moduleId];
|
|
5
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
6
|
+
var module = moduleCache[moduleId] = {
|
|
7
|
+
exports: {}
|
|
8
|
+
};
|
|
9
|
+
modules[moduleId].call(module.exports, module, module.exports, rspackRequire);
|
|
10
|
+
return module.exports;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// webpack/runtime/define_property_getters
|
|
26
|
-
(() => {
|
|
27
|
-
__webpack_require__.d = (exports, getters, values) => {
|
|
28
|
-
var define = (defs, kind) => {
|
|
29
|
-
for(var key in defs) {
|
|
30
|
-
if(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {
|
|
31
|
-
Object.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
define(getters, "get");
|
|
36
|
-
define(values, "value");
|
|
12
|
+
var moduleFactories = modules;
|
|
13
|
+
var definePropertyGetters = (exports, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (hasOwnProperty(defs, key) && !hasOwnProperty(exports, key)) Object.defineProperty(exports, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
22
|
+
};
|
|
23
|
+
moduleFactories.add = function(modules) {
|
|
24
|
+
Object.assign(moduleFactories, modules);
|
|
37
25
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
47
|
-
})();
|
|
48
|
-
// webpack/runtime/make_namespace_object
|
|
49
|
-
(() => {
|
|
50
|
-
// define __esModule on exports
|
|
51
|
-
__webpack_require__.r = (exports) => {
|
|
52
|
-
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
53
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
54
|
-
}
|
|
55
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
26
|
+
var hasOwnProperty = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
27
|
+
var makeNamespaceObject = (exports)=>{
|
|
28
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports, Symbol.toStringTag, {
|
|
29
|
+
value: 'Module'
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, '__esModule', {
|
|
32
|
+
value: true
|
|
33
|
+
});
|
|
56
34
|
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export { __webpack_require__ };
|
|
35
|
+
export { rspackRequire, moduleFactories, definePropertyGetters, makeNamespaceObject };
|
package/dist/models/v.js
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { rspackRequire, moduleFactories } from "./rslib-runtime.js";
|
|
2
|
+
moduleFactories.add({
|
|
3
|
+
J7 (__unused_rspack_module, exports) {
|
|
4
|
+
var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
5
|
+
if (void 0 === k2) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function() {
|
|
10
|
+
return m[k];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
} : function(o, m, k, k2) {
|
|
15
|
+
if (void 0 === k2) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
});
|
|
18
|
+
var __exportStar = this && this.__exportStar || function(m, exports) {
|
|
19
|
+
for(var p in m)if ("default" !== p && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", {
|
|
22
|
+
value: true
|
|
23
|
+
});
|
|
24
|
+
exports.Allow = exports.MalformedJSON = exports.PartialJSON = exports.parseJSON = exports.parse = void 0;
|
|
25
|
+
const options_1 = rspackRequire("Uo");
|
|
26
|
+
Object.defineProperty(exports, "Allow", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function() {
|
|
29
|
+
return options_1.Allow;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
__exportStar(rspackRequire("Uo"), exports);
|
|
33
|
+
class PartialJSON extends Error {
|
|
34
|
+
}
|
|
35
|
+
exports.PartialJSON = PartialJSON;
|
|
36
|
+
class MalformedJSON extends Error {
|
|
37
|
+
}
|
|
38
|
+
exports.MalformedJSON = MalformedJSON;
|
|
39
|
+
function parseJSON(jsonString, allowPartial = options_1.Allow.ALL) {
|
|
40
|
+
if ("string" != typeof jsonString) throw new TypeError(`expecting str, got ${typeof jsonString}`);
|
|
41
|
+
if (!jsonString.trim()) throw new Error(`${jsonString} is empty`);
|
|
42
|
+
return _parseJSON(jsonString.trim(), allowPartial);
|
|
43
|
+
}
|
|
44
|
+
exports.parseJSON = parseJSON;
|
|
45
|
+
const _parseJSON = (jsonString, allow)=>{
|
|
46
|
+
const length = jsonString.length;
|
|
47
|
+
let index = 0;
|
|
48
|
+
const markPartialJSON = (msg)=>{
|
|
49
|
+
throw new PartialJSON(`${msg} at position ${index}`);
|
|
50
|
+
};
|
|
51
|
+
const throwMalformedError = (msg)=>{
|
|
52
|
+
throw new MalformedJSON(`${msg} at position ${index}`);
|
|
53
|
+
};
|
|
54
|
+
const parseAny = ()=>{
|
|
55
|
+
skipBlank();
|
|
56
|
+
if (index >= length) markPartialJSON("Unexpected end of input");
|
|
57
|
+
if ('"' === jsonString[index]) return parseStr();
|
|
58
|
+
if ("{" === jsonString[index]) return parseObj();
|
|
59
|
+
if ("[" === jsonString[index]) return parseArr();
|
|
60
|
+
if ("null" === jsonString.substring(index, index + 4) || options_1.Allow.NULL & allow && length - index < 4 && "null".startsWith(jsonString.substring(index))) {
|
|
61
|
+
index += 4;
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
if ("true" === jsonString.substring(index, index + 4) || options_1.Allow.BOOL & allow && length - index < 4 && "true".startsWith(jsonString.substring(index))) {
|
|
65
|
+
index += 4;
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
if ("false" === jsonString.substring(index, index + 5) || options_1.Allow.BOOL & allow && length - index < 5 && "false".startsWith(jsonString.substring(index))) {
|
|
69
|
+
index += 5;
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
if ("Infinity" === jsonString.substring(index, index + 8) || options_1.Allow.INFINITY & allow && length - index < 8 && "Infinity".startsWith(jsonString.substring(index))) {
|
|
73
|
+
index += 8;
|
|
74
|
+
return 1 / 0;
|
|
75
|
+
}
|
|
76
|
+
if ("-Infinity" === jsonString.substring(index, index + 9) || options_1.Allow._INFINITY & allow && 1 < length - index && length - index < 9 && "-Infinity".startsWith(jsonString.substring(index))) {
|
|
77
|
+
index += 9;
|
|
78
|
+
return -1 / 0;
|
|
79
|
+
}
|
|
80
|
+
if ("NaN" === jsonString.substring(index, index + 3) || options_1.Allow.NAN & allow && length - index < 3 && "NaN".startsWith(jsonString.substring(index))) {
|
|
81
|
+
index += 3;
|
|
82
|
+
return 0 / 0;
|
|
83
|
+
}
|
|
84
|
+
return parseNum();
|
|
85
|
+
};
|
|
86
|
+
const parseStr = ()=>{
|
|
87
|
+
const start = index;
|
|
88
|
+
let escape = false;
|
|
89
|
+
index++;
|
|
90
|
+
while(index < length && ('"' !== jsonString[index] || escape && "\\" === jsonString[index - 1])){
|
|
91
|
+
escape = "\\" === jsonString[index] ? !escape : false;
|
|
92
|
+
index++;
|
|
93
|
+
}
|
|
94
|
+
if ('"' == jsonString.charAt(index)) try {
|
|
95
|
+
return JSON.parse(jsonString.substring(start, ++index - Number(escape)));
|
|
96
|
+
} catch (e) {
|
|
97
|
+
throwMalformedError(String(e));
|
|
98
|
+
}
|
|
99
|
+
else if (options_1.Allow.STR & allow) try {
|
|
100
|
+
return JSON.parse(jsonString.substring(start, index - Number(escape)) + '"');
|
|
101
|
+
} catch (e) {
|
|
102
|
+
return JSON.parse(jsonString.substring(start, jsonString.lastIndexOf("\\")) + '"');
|
|
103
|
+
}
|
|
104
|
+
markPartialJSON("Unterminated string literal");
|
|
105
|
+
};
|
|
106
|
+
const parseObj = ()=>{
|
|
107
|
+
index++;
|
|
108
|
+
skipBlank();
|
|
109
|
+
const obj = {};
|
|
110
|
+
try {
|
|
111
|
+
while("}" !== jsonString[index]){
|
|
112
|
+
skipBlank();
|
|
113
|
+
if (index >= length && options_1.Allow.OBJ & allow) return obj;
|
|
114
|
+
const key = parseStr();
|
|
115
|
+
skipBlank();
|
|
116
|
+
index++;
|
|
117
|
+
try {
|
|
118
|
+
const value = parseAny();
|
|
119
|
+
obj[key] = value;
|
|
120
|
+
} catch (e) {
|
|
121
|
+
if (options_1.Allow.OBJ & allow) return obj;
|
|
122
|
+
else throw e;
|
|
123
|
+
}
|
|
124
|
+
skipBlank();
|
|
125
|
+
if ("," === jsonString[index]) index++;
|
|
126
|
+
}
|
|
127
|
+
} catch (e) {
|
|
128
|
+
if (options_1.Allow.OBJ & allow) return obj;
|
|
129
|
+
else markPartialJSON("Expected '}' at end of object");
|
|
130
|
+
}
|
|
131
|
+
index++;
|
|
132
|
+
return obj;
|
|
133
|
+
};
|
|
134
|
+
const parseArr = ()=>{
|
|
135
|
+
index++;
|
|
136
|
+
const arr = [];
|
|
137
|
+
try {
|
|
138
|
+
while("]" !== jsonString[index]){
|
|
139
|
+
arr.push(parseAny());
|
|
140
|
+
skipBlank();
|
|
141
|
+
if ("," === jsonString[index]) index++;
|
|
142
|
+
}
|
|
143
|
+
} catch (e) {
|
|
144
|
+
if (options_1.Allow.ARR & allow) return arr;
|
|
145
|
+
markPartialJSON("Expected ']' at end of array");
|
|
146
|
+
}
|
|
147
|
+
index++;
|
|
148
|
+
return arr;
|
|
149
|
+
};
|
|
150
|
+
const parseNum = ()=>{
|
|
151
|
+
if (0 === index) {
|
|
152
|
+
if ("-" === jsonString) throwMalformedError("Not sure what '-' is");
|
|
153
|
+
try {
|
|
154
|
+
return JSON.parse(jsonString);
|
|
155
|
+
} catch (e) {
|
|
156
|
+
if (options_1.Allow.NUM & allow) try {
|
|
157
|
+
return JSON.parse(jsonString.substring(0, jsonString.lastIndexOf("e")));
|
|
158
|
+
} catch (e) {}
|
|
159
|
+
throwMalformedError(String(e));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const start = index;
|
|
163
|
+
if ("-" === jsonString[index]) index++;
|
|
164
|
+
while(jsonString[index] && -1 === ",]}".indexOf(jsonString[index]))index++;
|
|
165
|
+
if (index == length && !(options_1.Allow.NUM & allow)) markPartialJSON("Unterminated number literal");
|
|
166
|
+
try {
|
|
167
|
+
return JSON.parse(jsonString.substring(start, index));
|
|
168
|
+
} catch (e) {
|
|
169
|
+
if ("-" === jsonString.substring(start, index)) markPartialJSON("Not sure what '-' is");
|
|
170
|
+
try {
|
|
171
|
+
return JSON.parse(jsonString.substring(start, jsonString.lastIndexOf("e")));
|
|
172
|
+
} catch (e) {
|
|
173
|
+
throwMalformedError(String(e));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
const skipBlank = ()=>{
|
|
178
|
+
while(index < length && " \n\r\t".includes(jsonString[index]))index++;
|
|
179
|
+
};
|
|
180
|
+
return parseAny();
|
|
181
|
+
};
|
|
182
|
+
const parse = parseJSON;
|
|
183
|
+
exports.parse = parse;
|
|
184
|
+
},
|
|
185
|
+
Uo (__unused_rspack_module, exports) {
|
|
186
|
+
Object.defineProperty(exports, "__esModule", {
|
|
187
|
+
value: true
|
|
188
|
+
});
|
|
189
|
+
exports.Allow = exports.ALL = exports.COLLECTION = exports.ATOM = exports.SPECIAL = exports.INF = exports._INFINITY = exports.INFINITY = exports.NAN = exports.BOOL = exports.NULL = exports.OBJ = exports.ARR = exports.NUM = exports.STR = void 0;
|
|
190
|
+
exports.STR = 0b000000001;
|
|
191
|
+
exports.NUM = 0b000000010;
|
|
192
|
+
exports.ARR = 0b000000100;
|
|
193
|
+
exports.OBJ = 0b000001000;
|
|
194
|
+
exports.NULL = 0b000010000;
|
|
195
|
+
exports.BOOL = 0b000100000;
|
|
196
|
+
exports.NAN = 0b001000000;
|
|
197
|
+
exports.INFINITY = 0b010000000;
|
|
198
|
+
exports._INFINITY = 0b100000000;
|
|
199
|
+
exports.INF = exports.INFINITY | exports._INFINITY;
|
|
200
|
+
exports.SPECIAL = exports.NULL | exports.BOOL | exports.INF | exports.NAN;
|
|
201
|
+
exports.ATOM = exports.STR | exports.NUM | exports.SPECIAL;
|
|
202
|
+
exports.COLLECTION = exports.ARR | exports.OBJ;
|
|
203
|
+
exports.ALL = exports.ATOM | exports.COLLECTION;
|
|
204
|
+
exports.Allow = {
|
|
205
|
+
STR: exports.STR,
|
|
206
|
+
NUM: exports.NUM,
|
|
207
|
+
ARR: exports.ARR,
|
|
208
|
+
OBJ: exports.OBJ,
|
|
209
|
+
NULL: exports.NULL,
|
|
210
|
+
BOOL: exports.BOOL,
|
|
211
|
+
NAN: exports.NAN,
|
|
212
|
+
INFINITY: exports.INFINITY,
|
|
213
|
+
_INFINITY: exports._INFINITY,
|
|
214
|
+
INF: exports.INF,
|
|
215
|
+
SPECIAL: exports.SPECIAL,
|
|
216
|
+
ATOM: exports.ATOM,
|
|
217
|
+
COLLECTION: exports.COLLECTION,
|
|
218
|
+
ALL: exports.ALL
|
|
219
|
+
};
|
|
220
|
+
exports["default"] = exports.Allow;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
const dist = rspackRequire("J7");
|
|
224
|
+
const VALID_JSON_ESCAPES = new Set([
|
|
225
|
+
'"',
|
|
226
|
+
"\\",
|
|
227
|
+
"/",
|
|
228
|
+
"b",
|
|
229
|
+
"f",
|
|
230
|
+
"n",
|
|
231
|
+
"r",
|
|
232
|
+
"t",
|
|
233
|
+
"u"
|
|
234
|
+
]);
|
|
235
|
+
function isControlCharacter(char) {
|
|
236
|
+
const codePoint = char.codePointAt(0);
|
|
237
|
+
return void 0 !== codePoint && codePoint >= 0x00 && codePoint <= 0x1f;
|
|
238
|
+
}
|
|
239
|
+
function escapeControlCharacter(char) {
|
|
240
|
+
switch(char){
|
|
241
|
+
case "\b":
|
|
242
|
+
return "\\b";
|
|
243
|
+
case "\f":
|
|
244
|
+
return "\\f";
|
|
245
|
+
case "\n":
|
|
246
|
+
return "\\n";
|
|
247
|
+
case "\r":
|
|
248
|
+
return "\\r";
|
|
249
|
+
case "\t":
|
|
250
|
+
return "\\t";
|
|
251
|
+
default:
|
|
252
|
+
return `\\u${char.codePointAt(0)?.toString(16).padStart(4, "0") ?? "0000"}`;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function repairJson(json) {
|
|
256
|
+
let repaired = "";
|
|
257
|
+
let inString = false;
|
|
258
|
+
for(let index = 0; index < json.length; index++){
|
|
259
|
+
const char = json[index];
|
|
260
|
+
if (!inString) {
|
|
261
|
+
repaired += char;
|
|
262
|
+
if ('"' === char) inString = true;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
if ('"' === char) {
|
|
266
|
+
repaired += char;
|
|
267
|
+
inString = false;
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
if ("\\" === char) {
|
|
271
|
+
const nextChar = json[index + 1];
|
|
272
|
+
if (void 0 === nextChar) {
|
|
273
|
+
repaired += "\\\\";
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if ("u" === nextChar) {
|
|
277
|
+
const unicodeDigits = json.slice(index + 2, index + 6);
|
|
278
|
+
if (/^[0-9a-fA-F]{4}$/.test(unicodeDigits)) {
|
|
279
|
+
repaired += `\\u${unicodeDigits}`;
|
|
280
|
+
index += 5;
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (VALID_JSON_ESCAPES.has(nextChar)) {
|
|
285
|
+
repaired += `\\${nextChar}`;
|
|
286
|
+
index += 1;
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
repaired += "\\\\";
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
repaired += isControlCharacter(char) ? escapeControlCharacter(char) : char;
|
|
293
|
+
}
|
|
294
|
+
return repaired;
|
|
295
|
+
}
|
|
296
|
+
function parseJsonWithRepair(json) {
|
|
297
|
+
try {
|
|
298
|
+
return JSON.parse(json);
|
|
299
|
+
} catch (error) {
|
|
300
|
+
const repairedJson = repairJson(json);
|
|
301
|
+
if (repairedJson !== json) return JSON.parse(repairedJson);
|
|
302
|
+
throw error;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function parseStreamingJson(partialJson) {
|
|
306
|
+
if (!partialJson || "" === partialJson.trim()) return {};
|
|
307
|
+
try {
|
|
308
|
+
return parseJsonWithRepair(partialJson);
|
|
309
|
+
} catch {
|
|
310
|
+
try {
|
|
311
|
+
const result = (0, dist.parse)(partialJson);
|
|
312
|
+
return result ?? {};
|
|
313
|
+
} catch {
|
|
314
|
+
try {
|
|
315
|
+
const result = (0, dist.parse)(repairJson(partialJson));
|
|
316
|
+
return result ?? {};
|
|
317
|
+
} catch {
|
|
318
|
+
return {};
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function getProviderEnvValue(name, env) {
|
|
324
|
+
const value = env?.[name];
|
|
325
|
+
return "string" == typeof value && value.trim() ? value : void 0;
|
|
326
|
+
}
|
|
327
|
+
function inferCopilotInitiator(messages) {
|
|
328
|
+
const last = messages[messages.length - 1];
|
|
329
|
+
return last && "user" !== last.role ? "agent" : "user";
|
|
330
|
+
}
|
|
331
|
+
function hasCopilotVisionInput(messages) {
|
|
332
|
+
return messages.some((msg)=>{
|
|
333
|
+
if ("user" === msg.role && Array.isArray(msg.content)) return msg.content.some((c)=>"image" === c.type);
|
|
334
|
+
if ("toolResult" === msg.role && Array.isArray(msg.content)) return msg.content.some((c)=>"image" === c.type);
|
|
335
|
+
return false;
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
function buildCopilotDynamicHeaders(params) {
|
|
339
|
+
const headers = {
|
|
340
|
+
"X-Initiator": inferCopilotInitiator(params.messages),
|
|
341
|
+
"Openai-Intent": "conversation-edits"
|
|
342
|
+
};
|
|
343
|
+
if (params.hasImages) headers["Copilot-Vision-Request"] = "true";
|
|
344
|
+
return headers;
|
|
345
|
+
}
|
|
346
|
+
export { buildCopilotDynamicHeaders, getProviderEnvValue, hasCopilotVisionInput, parseJsonWithRepair, parseStreamingJson };
|