@4djs/assistant 0.1.1 → 0.1.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/README.md +34 -1
- package/dist/core/create-assistant-store.d.ts +1 -0
- package/dist/core/create-assistant-store.d.ts.map +1 -1
- package/dist/core/index.d.ts +8 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1968 -807
- package/dist/core/interactive-tools/gate.d.ts +14 -0
- package/dist/core/interactive-tools/gate.d.ts.map +1 -0
- package/dist/core/interactive-tools/index.d.ts +1 -0
- package/dist/core/interactive-tools/index.d.ts.map +1 -1
- package/dist/core/llm-chat.d.ts.map +1 -1
- package/dist/core/llm-provider.d.ts.map +1 -1
- package/dist/core/markdown-utils.d.ts +1 -2
- package/dist/core/markdown-utils.d.ts.map +1 -1
- package/dist/core/system-prompt.d.ts +3 -0
- package/dist/core/system-prompt.d.ts.map +1 -0
- package/dist/core/tool-names.d.ts +5 -0
- package/dist/core/tool-names.d.ts.map +1 -0
- package/dist/core/tool-registry.d.ts +28 -0
- package/dist/core/tool-registry.d.ts.map +1 -0
- package/dist/core/types.d.ts +5 -2
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.js +521 -4007
- package/dist/react/Assistant.d.ts.map +1 -1
- package/dist/react/components/HighlightedJsonCode.d.ts.map +1 -1
- package/dist/react/components/MarkdownContent.d.ts.map +1 -1
- package/dist/react/components/chat/ChatActivity.d.ts.map +1 -1
- package/dist/react/components/highlighted-code.d.ts.map +1 -1
- package/dist/react/context.d.ts +2 -2
- package/dist/react/context.d.ts.map +1 -1
- package/dist/react/hooks/use-composer-commands.d.ts +1 -1
- package/dist/react/hooks/use-composer-commands.d.ts.map +1 -1
- package/dist/react/hooks/use-suggested-prompts.d.ts +1 -1
- package/dist/react/hooks/use-suggested-prompts.d.ts.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/types.d.ts +3 -2
- package/dist/react/types.d.ts.map +1 -1
- package/dist/styles.css +80 -0
- package/dist/tools/datastore.d.ts +28 -0
- package/dist/tools/datastore.d.ts.map +1 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +249 -0
- package/package.json +11 -6
package/dist/core/index.js
CHANGED
|
@@ -16,835 +16,1425 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
16
16
|
};
|
|
17
17
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
18
18
|
|
|
19
|
-
// ../../node_modules/.bun/
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
// ../../node_modules/.bun/highlight.js@11.11.1/node_modules/highlight.js/lib/core.js
|
|
20
|
+
var require_core = __commonJS((exports, module) => {
|
|
21
|
+
function deepFreeze(obj) {
|
|
22
|
+
if (obj instanceof Map) {
|
|
23
|
+
obj.clear = obj.delete = obj.set = function() {
|
|
24
|
+
throw new Error("map is read-only");
|
|
25
|
+
};
|
|
26
|
+
} else if (obj instanceof Set) {
|
|
27
|
+
obj.add = obj.clear = obj.delete = function() {
|
|
28
|
+
throw new Error("set is read-only");
|
|
29
|
+
};
|
|
28
30
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
function warnNoop(publicInstance, callerName) {
|
|
36
|
-
publicInstance = (publicInstance = publicInstance.constructor) && (publicInstance.displayName || publicInstance.name) || "ReactClass";
|
|
37
|
-
var warningKey = publicInstance + "." + callerName;
|
|
38
|
-
didWarnStateUpdateForUnmountedComponent[warningKey] || (console.error("Can't call %s on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to `this.state` directly or define a `state = {};` class property with the desired state in the %s component.", callerName, publicInstance), didWarnStateUpdateForUnmountedComponent[warningKey] = true);
|
|
39
|
-
}
|
|
40
|
-
function Component(props, context, updater) {
|
|
41
|
-
this.props = props;
|
|
42
|
-
this.context = context;
|
|
43
|
-
this.refs = emptyObject;
|
|
44
|
-
this.updater = updater || ReactNoopUpdateQueue;
|
|
45
|
-
}
|
|
46
|
-
function ComponentDummy() {}
|
|
47
|
-
function PureComponent(props, context, updater) {
|
|
48
|
-
this.props = props;
|
|
49
|
-
this.context = context;
|
|
50
|
-
this.refs = emptyObject;
|
|
51
|
-
this.updater = updater || ReactNoopUpdateQueue;
|
|
52
|
-
}
|
|
53
|
-
function noop() {}
|
|
54
|
-
function testStringCoercion(value) {
|
|
55
|
-
return "" + value;
|
|
56
|
-
}
|
|
57
|
-
function checkKeyStringCoercion(value) {
|
|
58
|
-
try {
|
|
59
|
-
testStringCoercion(value);
|
|
60
|
-
var JSCompiler_inline_result = false;
|
|
61
|
-
} catch (e) {
|
|
62
|
-
JSCompiler_inline_result = true;
|
|
31
|
+
Object.freeze(obj);
|
|
32
|
+
Object.getOwnPropertyNames(obj).forEach((name) => {
|
|
33
|
+
const prop = obj[name];
|
|
34
|
+
const type = typeof prop;
|
|
35
|
+
if ((type === "object" || type === "function") && !Object.isFrozen(prop)) {
|
|
36
|
+
deepFreeze(prop);
|
|
63
37
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
38
|
+
});
|
|
39
|
+
return obj;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
class Response {
|
|
43
|
+
constructor(mode) {
|
|
44
|
+
if (mode.data === undefined)
|
|
45
|
+
mode.data = {};
|
|
46
|
+
this.data = mode.data;
|
|
47
|
+
this.isMatchIgnored = false;
|
|
48
|
+
}
|
|
49
|
+
ignoreMatch() {
|
|
50
|
+
this.isMatchIgnored = true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function escapeHTML(value) {
|
|
54
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
55
|
+
}
|
|
56
|
+
function inherit$1(original, ...objects) {
|
|
57
|
+
const result = Object.create(null);
|
|
58
|
+
for (const key in original) {
|
|
59
|
+
result[key] = original[key];
|
|
60
|
+
}
|
|
61
|
+
objects.forEach(function(obj) {
|
|
62
|
+
for (const key in obj) {
|
|
63
|
+
result[key] = obj[key];
|
|
70
64
|
}
|
|
65
|
+
});
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
var SPAN_CLOSE = "</span>";
|
|
69
|
+
var emitsWrappingTags = (node) => {
|
|
70
|
+
return !!node.scope;
|
|
71
|
+
};
|
|
72
|
+
var scopeToCSSClass = (name, { prefix }) => {
|
|
73
|
+
if (name.startsWith("language:")) {
|
|
74
|
+
return name.replace("language:", "language-");
|
|
71
75
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return type;
|
|
79
|
-
switch (type) {
|
|
80
|
-
case REACT_FRAGMENT_TYPE:
|
|
81
|
-
return "Fragment";
|
|
82
|
-
case REACT_PROFILER_TYPE:
|
|
83
|
-
return "Profiler";
|
|
84
|
-
case REACT_STRICT_MODE_TYPE:
|
|
85
|
-
return "StrictMode";
|
|
86
|
-
case REACT_SUSPENSE_TYPE:
|
|
87
|
-
return "Suspense";
|
|
88
|
-
case REACT_SUSPENSE_LIST_TYPE:
|
|
89
|
-
return "SuspenseList";
|
|
90
|
-
case REACT_ACTIVITY_TYPE:
|
|
91
|
-
return "Activity";
|
|
92
|
-
}
|
|
93
|
-
if (typeof type === "object")
|
|
94
|
-
switch (typeof type.tag === "number" && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), type.$$typeof) {
|
|
95
|
-
case REACT_PORTAL_TYPE:
|
|
96
|
-
return "Portal";
|
|
97
|
-
case REACT_CONTEXT_TYPE:
|
|
98
|
-
return type.displayName || "Context";
|
|
99
|
-
case REACT_CONSUMER_TYPE:
|
|
100
|
-
return (type._context.displayName || "Context") + ".Consumer";
|
|
101
|
-
case REACT_FORWARD_REF_TYPE:
|
|
102
|
-
var innerType = type.render;
|
|
103
|
-
type = type.displayName;
|
|
104
|
-
type || (type = innerType.displayName || innerType.name || "", type = type !== "" ? "ForwardRef(" + type + ")" : "ForwardRef");
|
|
105
|
-
return type;
|
|
106
|
-
case REACT_MEMO_TYPE:
|
|
107
|
-
return innerType = type.displayName || null, innerType !== null ? innerType : getComponentNameFromType(type.type) || "Memo";
|
|
108
|
-
case REACT_LAZY_TYPE:
|
|
109
|
-
innerType = type._payload;
|
|
110
|
-
type = type._init;
|
|
111
|
-
try {
|
|
112
|
-
return getComponentNameFromType(type(innerType));
|
|
113
|
-
} catch (x) {}
|
|
114
|
-
}
|
|
115
|
-
return null;
|
|
76
|
+
if (name.includes(".")) {
|
|
77
|
+
const pieces = name.split(".");
|
|
78
|
+
return [
|
|
79
|
+
`${prefix}${pieces.shift()}`,
|
|
80
|
+
...pieces.map((x, i) => `${x}${"_".repeat(i + 1)}`)
|
|
81
|
+
].join(" ");
|
|
116
82
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
83
|
+
return `${prefix}${name}`;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
class HTMLRenderer {
|
|
87
|
+
constructor(parseTree, options) {
|
|
88
|
+
this.buffer = "";
|
|
89
|
+
this.classPrefix = options.classPrefix;
|
|
90
|
+
parseTree.walk(this);
|
|
91
|
+
}
|
|
92
|
+
addText(text) {
|
|
93
|
+
this.buffer += escapeHTML(text);
|
|
94
|
+
}
|
|
95
|
+
openNode(node) {
|
|
96
|
+
if (!emitsWrappingTags(node))
|
|
97
|
+
return;
|
|
98
|
+
const className = scopeToCSSClass(node.scope, { prefix: this.classPrefix });
|
|
99
|
+
this.span(className);
|
|
100
|
+
}
|
|
101
|
+
closeNode(node) {
|
|
102
|
+
if (!emitsWrappingTags(node))
|
|
103
|
+
return;
|
|
104
|
+
this.buffer += SPAN_CLOSE;
|
|
105
|
+
}
|
|
106
|
+
value() {
|
|
107
|
+
return this.buffer;
|
|
108
|
+
}
|
|
109
|
+
span(className) {
|
|
110
|
+
this.buffer += `<span class="${className}">`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
var newNode = (opts = {}) => {
|
|
114
|
+
const result = { children: [] };
|
|
115
|
+
Object.assign(result, opts);
|
|
116
|
+
return result;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
class TokenTree {
|
|
120
|
+
constructor() {
|
|
121
|
+
this.rootNode = newNode();
|
|
122
|
+
this.stack = [this.rootNode];
|
|
123
|
+
}
|
|
124
|
+
get top() {
|
|
125
|
+
return this.stack[this.stack.length - 1];
|
|
126
|
+
}
|
|
127
|
+
get root() {
|
|
128
|
+
return this.rootNode;
|
|
129
|
+
}
|
|
130
|
+
add(node) {
|
|
131
|
+
this.top.children.push(node);
|
|
132
|
+
}
|
|
133
|
+
openNode(scope) {
|
|
134
|
+
const node = newNode({ scope });
|
|
135
|
+
this.add(node);
|
|
136
|
+
this.stack.push(node);
|
|
137
|
+
}
|
|
138
|
+
closeNode() {
|
|
139
|
+
if (this.stack.length > 1) {
|
|
140
|
+
return this.stack.pop();
|
|
127
141
|
}
|
|
142
|
+
return;
|
|
128
143
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
144
|
+
closeAllNodes() {
|
|
145
|
+
while (this.closeNode())
|
|
146
|
+
;
|
|
132
147
|
}
|
|
133
|
-
|
|
134
|
-
return
|
|
148
|
+
toJSON() {
|
|
149
|
+
return JSON.stringify(this.rootNode, null, 4);
|
|
135
150
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
151
|
+
walk(builder) {
|
|
152
|
+
return this.constructor._walk(builder, this.rootNode);
|
|
153
|
+
}
|
|
154
|
+
static _walk(builder, node) {
|
|
155
|
+
if (typeof node === "string") {
|
|
156
|
+
builder.addText(node);
|
|
157
|
+
} else if (node.children) {
|
|
158
|
+
builder.openNode(node);
|
|
159
|
+
node.children.forEach((child) => this._walk(builder, child));
|
|
160
|
+
builder.closeNode(node);
|
|
141
161
|
}
|
|
142
|
-
return
|
|
162
|
+
return builder;
|
|
143
163
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
164
|
+
static _collapse(node) {
|
|
165
|
+
if (typeof node === "string")
|
|
166
|
+
return;
|
|
167
|
+
if (!node.children)
|
|
168
|
+
return;
|
|
169
|
+
if (node.children.every((el) => typeof el === "string")) {
|
|
170
|
+
node.children = [node.children.join("")];
|
|
171
|
+
} else {
|
|
172
|
+
node.children.forEach((child) => {
|
|
173
|
+
TokenTree._collapse(child);
|
|
174
|
+
});
|
|
147
175
|
}
|
|
148
|
-
warnAboutAccessingKey.isReactWarning = true;
|
|
149
|
-
Object.defineProperty(props, "key", {
|
|
150
|
-
get: warnAboutAccessingKey,
|
|
151
|
-
configurable: true
|
|
152
|
-
});
|
|
153
176
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
class TokenTreeEmitter extends TokenTree {
|
|
180
|
+
constructor(options) {
|
|
181
|
+
super();
|
|
182
|
+
this.options = options;
|
|
183
|
+
}
|
|
184
|
+
addText(text) {
|
|
185
|
+
if (text === "") {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this.add(text);
|
|
189
|
+
}
|
|
190
|
+
startScope(scope) {
|
|
191
|
+
this.openNode(scope);
|
|
192
|
+
}
|
|
193
|
+
endScope() {
|
|
194
|
+
this.closeNode();
|
|
195
|
+
}
|
|
196
|
+
__addSublanguage(emitter, name) {
|
|
197
|
+
const node = emitter.root;
|
|
198
|
+
if (name)
|
|
199
|
+
node.scope = `language:${name}`;
|
|
200
|
+
this.add(node);
|
|
201
|
+
}
|
|
202
|
+
toHTML() {
|
|
203
|
+
const renderer = new HTMLRenderer(this, this.options);
|
|
204
|
+
return renderer.value();
|
|
205
|
+
}
|
|
206
|
+
finalize() {
|
|
207
|
+
this.closeAllNodes();
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function source(re) {
|
|
212
|
+
if (!re)
|
|
213
|
+
return null;
|
|
214
|
+
if (typeof re === "string")
|
|
215
|
+
return re;
|
|
216
|
+
return re.source;
|
|
217
|
+
}
|
|
218
|
+
function lookahead(re) {
|
|
219
|
+
return concat("(?=", re, ")");
|
|
220
|
+
}
|
|
221
|
+
function anyNumberOfTimes(re) {
|
|
222
|
+
return concat("(?:", re, ")*");
|
|
223
|
+
}
|
|
224
|
+
function optional(re) {
|
|
225
|
+
return concat("(?:", re, ")?");
|
|
226
|
+
}
|
|
227
|
+
function concat(...args) {
|
|
228
|
+
const joined = args.map((x) => source(x)).join("");
|
|
229
|
+
return joined;
|
|
230
|
+
}
|
|
231
|
+
function stripOptionsFromArgs(args) {
|
|
232
|
+
const opts = args[args.length - 1];
|
|
233
|
+
if (typeof opts === "object" && opts.constructor === Object) {
|
|
234
|
+
args.splice(args.length - 1, 1);
|
|
235
|
+
return opts;
|
|
236
|
+
} else {
|
|
237
|
+
return {};
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function either(...args) {
|
|
241
|
+
const opts = stripOptionsFromArgs(args);
|
|
242
|
+
const joined = "(" + (opts.capture ? "" : "?:") + args.map((x) => source(x)).join("|") + ")";
|
|
243
|
+
return joined;
|
|
244
|
+
}
|
|
245
|
+
function countMatchGroups(re) {
|
|
246
|
+
return new RegExp(re.toString() + "|").exec("").length - 1;
|
|
247
|
+
}
|
|
248
|
+
function startsWith(re, lexeme) {
|
|
249
|
+
const match = re && re.exec(lexeme);
|
|
250
|
+
return match && match.index === 0;
|
|
251
|
+
}
|
|
252
|
+
var BACKREF_RE = /\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./;
|
|
253
|
+
function _rewriteBackreferences(regexps, { joinWith }) {
|
|
254
|
+
let numCaptures = 0;
|
|
255
|
+
return regexps.map((regex) => {
|
|
256
|
+
numCaptures += 1;
|
|
257
|
+
const offset = numCaptures;
|
|
258
|
+
let re = source(regex);
|
|
259
|
+
let out = "";
|
|
260
|
+
while (re.length > 0) {
|
|
261
|
+
const match = BACKREF_RE.exec(re);
|
|
262
|
+
if (!match) {
|
|
263
|
+
out += re;
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
out += re.substring(0, match.index);
|
|
267
|
+
re = re.substring(match.index + match[0].length);
|
|
268
|
+
if (match[0][0] === "\\" && match[1]) {
|
|
269
|
+
out += "\\" + String(Number(match[1]) + offset);
|
|
270
|
+
} else {
|
|
271
|
+
out += match[0];
|
|
272
|
+
if (match[0] === "(") {
|
|
273
|
+
numCaptures++;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return out;
|
|
278
|
+
}).map((re) => `(${re})`).join(joinWith);
|
|
279
|
+
}
|
|
280
|
+
var MATCH_NOTHING_RE = /\b\B/;
|
|
281
|
+
var IDENT_RE = "[a-zA-Z]\\w*";
|
|
282
|
+
var UNDERSCORE_IDENT_RE = "[a-zA-Z_]\\w*";
|
|
283
|
+
var NUMBER_RE = "\\b\\d+(\\.\\d+)?";
|
|
284
|
+
var C_NUMBER_RE = "(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)";
|
|
285
|
+
var BINARY_NUMBER_RE = "\\b(0b[01]+)";
|
|
286
|
+
var RE_STARTERS_RE = "!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~";
|
|
287
|
+
var SHEBANG = (opts = {}) => {
|
|
288
|
+
const beginShebang = /^#![ ]*\//;
|
|
289
|
+
if (opts.binary) {
|
|
290
|
+
opts.begin = concat(beginShebang, /.*\b/, opts.binary, /\b.*/);
|
|
291
|
+
}
|
|
292
|
+
return inherit$1({
|
|
293
|
+
scope: "meta",
|
|
294
|
+
begin: beginShebang,
|
|
295
|
+
end: /$/,
|
|
296
|
+
relevance: 0,
|
|
297
|
+
"on:begin": (m, resp) => {
|
|
298
|
+
if (m.index !== 0)
|
|
299
|
+
resp.ignoreMatch();
|
|
300
|
+
}
|
|
301
|
+
}, opts);
|
|
302
|
+
};
|
|
303
|
+
var BACKSLASH_ESCAPE = {
|
|
304
|
+
begin: "\\\\[\\s\\S]",
|
|
305
|
+
relevance: 0
|
|
306
|
+
};
|
|
307
|
+
var APOS_STRING_MODE = {
|
|
308
|
+
scope: "string",
|
|
309
|
+
begin: "'",
|
|
310
|
+
end: "'",
|
|
311
|
+
illegal: "\\n",
|
|
312
|
+
contains: [BACKSLASH_ESCAPE]
|
|
313
|
+
};
|
|
314
|
+
var QUOTE_STRING_MODE = {
|
|
315
|
+
scope: "string",
|
|
316
|
+
begin: '"',
|
|
317
|
+
end: '"',
|
|
318
|
+
illegal: "\\n",
|
|
319
|
+
contains: [BACKSLASH_ESCAPE]
|
|
320
|
+
};
|
|
321
|
+
var PHRASAL_WORDS_MODE = {
|
|
322
|
+
begin: /\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/
|
|
323
|
+
};
|
|
324
|
+
var COMMENT = function(begin, end, modeOptions = {}) {
|
|
325
|
+
const mode = inherit$1({
|
|
326
|
+
scope: "comment",
|
|
327
|
+
begin,
|
|
328
|
+
end,
|
|
329
|
+
contains: []
|
|
330
|
+
}, modeOptions);
|
|
331
|
+
mode.contains.push({
|
|
332
|
+
scope: "doctag",
|
|
333
|
+
begin: "[ ]*(?=(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):)",
|
|
334
|
+
end: /(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):/,
|
|
335
|
+
excludeBegin: true,
|
|
336
|
+
relevance: 0
|
|
337
|
+
});
|
|
338
|
+
const ENGLISH_WORD = either("I", "a", "is", "so", "us", "to", "at", "if", "in", "it", "on", /[A-Za-z]+['](d|ve|re|ll|t|s|n)/, /[A-Za-z]+[-][a-z]+/, /[A-Za-z][a-z]{2,}/);
|
|
339
|
+
mode.contains.push({
|
|
340
|
+
begin: concat(/[ ]+/, "(", ENGLISH_WORD, /[.]?[:]?([.][ ]|[ ])/, "){3}")
|
|
341
|
+
});
|
|
342
|
+
return mode;
|
|
343
|
+
};
|
|
344
|
+
var C_LINE_COMMENT_MODE = COMMENT("//", "$");
|
|
345
|
+
var C_BLOCK_COMMENT_MODE = COMMENT("/\\*", "\\*/");
|
|
346
|
+
var HASH_COMMENT_MODE = COMMENT("#", "$");
|
|
347
|
+
var NUMBER_MODE = {
|
|
348
|
+
scope: "number",
|
|
349
|
+
begin: NUMBER_RE,
|
|
350
|
+
relevance: 0
|
|
351
|
+
};
|
|
352
|
+
var C_NUMBER_MODE = {
|
|
353
|
+
scope: "number",
|
|
354
|
+
begin: C_NUMBER_RE,
|
|
355
|
+
relevance: 0
|
|
356
|
+
};
|
|
357
|
+
var BINARY_NUMBER_MODE = {
|
|
358
|
+
scope: "number",
|
|
359
|
+
begin: BINARY_NUMBER_RE,
|
|
360
|
+
relevance: 0
|
|
361
|
+
};
|
|
362
|
+
var REGEXP_MODE = {
|
|
363
|
+
scope: "regexp",
|
|
364
|
+
begin: /\/(?=[^/\n]*\/)/,
|
|
365
|
+
end: /\/[gimuy]*/,
|
|
366
|
+
contains: [
|
|
367
|
+
BACKSLASH_ESCAPE,
|
|
368
|
+
{
|
|
369
|
+
begin: /\[/,
|
|
370
|
+
end: /\]/,
|
|
371
|
+
relevance: 0,
|
|
372
|
+
contains: [BACKSLASH_ESCAPE]
|
|
373
|
+
}
|
|
374
|
+
]
|
|
375
|
+
};
|
|
376
|
+
var TITLE_MODE = {
|
|
377
|
+
scope: "title",
|
|
378
|
+
begin: IDENT_RE,
|
|
379
|
+
relevance: 0
|
|
380
|
+
};
|
|
381
|
+
var UNDERSCORE_TITLE_MODE = {
|
|
382
|
+
scope: "title",
|
|
383
|
+
begin: UNDERSCORE_IDENT_RE,
|
|
384
|
+
relevance: 0
|
|
385
|
+
};
|
|
386
|
+
var METHOD_GUARD = {
|
|
387
|
+
begin: "\\.\\s*" + UNDERSCORE_IDENT_RE,
|
|
388
|
+
relevance: 0
|
|
389
|
+
};
|
|
390
|
+
var END_SAME_AS_BEGIN = function(mode) {
|
|
391
|
+
return Object.assign(mode, {
|
|
392
|
+
"on:begin": (m, resp) => {
|
|
393
|
+
resp.data._beginMatch = m[1];
|
|
394
|
+
},
|
|
395
|
+
"on:end": (m, resp) => {
|
|
396
|
+
if (resp.data._beginMatch !== m[1])
|
|
397
|
+
resp.ignoreMatch();
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
};
|
|
401
|
+
var MODES = /* @__PURE__ */ Object.freeze({
|
|
402
|
+
__proto__: null,
|
|
403
|
+
APOS_STRING_MODE,
|
|
404
|
+
BACKSLASH_ESCAPE,
|
|
405
|
+
BINARY_NUMBER_MODE,
|
|
406
|
+
BINARY_NUMBER_RE,
|
|
407
|
+
COMMENT,
|
|
408
|
+
C_BLOCK_COMMENT_MODE,
|
|
409
|
+
C_LINE_COMMENT_MODE,
|
|
410
|
+
C_NUMBER_MODE,
|
|
411
|
+
C_NUMBER_RE,
|
|
412
|
+
END_SAME_AS_BEGIN,
|
|
413
|
+
HASH_COMMENT_MODE,
|
|
414
|
+
IDENT_RE,
|
|
415
|
+
MATCH_NOTHING_RE,
|
|
416
|
+
METHOD_GUARD,
|
|
417
|
+
NUMBER_MODE,
|
|
418
|
+
NUMBER_RE,
|
|
419
|
+
PHRASAL_WORDS_MODE,
|
|
420
|
+
QUOTE_STRING_MODE,
|
|
421
|
+
REGEXP_MODE,
|
|
422
|
+
RE_STARTERS_RE,
|
|
423
|
+
SHEBANG,
|
|
424
|
+
TITLE_MODE,
|
|
425
|
+
UNDERSCORE_IDENT_RE,
|
|
426
|
+
UNDERSCORE_TITLE_MODE
|
|
427
|
+
});
|
|
428
|
+
function skipIfHasPrecedingDot(match, response) {
|
|
429
|
+
const before = match.input[match.index - 1];
|
|
430
|
+
if (before === ".") {
|
|
431
|
+
response.ignoreMatch();
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
function scopeClassName(mode, _parent) {
|
|
435
|
+
if (mode.className !== undefined) {
|
|
436
|
+
mode.scope = mode.className;
|
|
437
|
+
delete mode.className;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
function beginKeywords(mode, parent) {
|
|
441
|
+
if (!parent)
|
|
442
|
+
return;
|
|
443
|
+
if (!mode.beginKeywords)
|
|
444
|
+
return;
|
|
445
|
+
mode.begin = "\\b(" + mode.beginKeywords.split(" ").join("|") + ")(?!\\.)(?=\\b|\\s)";
|
|
446
|
+
mode.__beforeBegin = skipIfHasPrecedingDot;
|
|
447
|
+
mode.keywords = mode.keywords || mode.beginKeywords;
|
|
448
|
+
delete mode.beginKeywords;
|
|
449
|
+
if (mode.relevance === undefined)
|
|
450
|
+
mode.relevance = 0;
|
|
451
|
+
}
|
|
452
|
+
function compileIllegal(mode, _parent) {
|
|
453
|
+
if (!Array.isArray(mode.illegal))
|
|
454
|
+
return;
|
|
455
|
+
mode.illegal = either(...mode.illegal);
|
|
456
|
+
}
|
|
457
|
+
function compileMatch(mode, _parent) {
|
|
458
|
+
if (!mode.match)
|
|
459
|
+
return;
|
|
460
|
+
if (mode.begin || mode.end)
|
|
461
|
+
throw new Error("begin & end are not supported with match");
|
|
462
|
+
mode.begin = mode.match;
|
|
463
|
+
delete mode.match;
|
|
464
|
+
}
|
|
465
|
+
function compileRelevance(mode, _parent) {
|
|
466
|
+
if (mode.relevance === undefined)
|
|
467
|
+
mode.relevance = 1;
|
|
468
|
+
}
|
|
469
|
+
var beforeMatchExt = (mode, parent) => {
|
|
470
|
+
if (!mode.beforeMatch)
|
|
471
|
+
return;
|
|
472
|
+
if (mode.starts)
|
|
473
|
+
throw new Error("beforeMatch cannot be used with starts");
|
|
474
|
+
const originalMode = Object.assign({}, mode);
|
|
475
|
+
Object.keys(mode).forEach((key) => {
|
|
476
|
+
delete mode[key];
|
|
477
|
+
});
|
|
478
|
+
mode.keywords = originalMode.keywords;
|
|
479
|
+
mode.begin = concat(originalMode.beforeMatch, lookahead(originalMode.begin));
|
|
480
|
+
mode.starts = {
|
|
481
|
+
relevance: 0,
|
|
482
|
+
contains: [
|
|
483
|
+
Object.assign(originalMode, { endsParent: true })
|
|
484
|
+
]
|
|
485
|
+
};
|
|
486
|
+
mode.relevance = 0;
|
|
487
|
+
delete originalMode.beforeMatch;
|
|
488
|
+
};
|
|
489
|
+
var COMMON_KEYWORDS = [
|
|
490
|
+
"of",
|
|
491
|
+
"and",
|
|
492
|
+
"for",
|
|
493
|
+
"in",
|
|
494
|
+
"not",
|
|
495
|
+
"or",
|
|
496
|
+
"if",
|
|
497
|
+
"then",
|
|
498
|
+
"parent",
|
|
499
|
+
"list",
|
|
500
|
+
"value"
|
|
501
|
+
];
|
|
502
|
+
var DEFAULT_KEYWORD_SCOPE = "keyword";
|
|
503
|
+
function compileKeywords(rawKeywords, caseInsensitive, scopeName = DEFAULT_KEYWORD_SCOPE) {
|
|
504
|
+
const compiledKeywords = Object.create(null);
|
|
505
|
+
if (typeof rawKeywords === "string") {
|
|
506
|
+
compileList(scopeName, rawKeywords.split(" "));
|
|
507
|
+
} else if (Array.isArray(rawKeywords)) {
|
|
508
|
+
compileList(scopeName, rawKeywords);
|
|
509
|
+
} else {
|
|
510
|
+
Object.keys(rawKeywords).forEach(function(scopeName2) {
|
|
511
|
+
Object.assign(compiledKeywords, compileKeywords(rawKeywords[scopeName2], caseInsensitive, scopeName2));
|
|
191
512
|
});
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
513
|
+
}
|
|
514
|
+
return compiledKeywords;
|
|
515
|
+
function compileList(scopeName2, keywordList) {
|
|
516
|
+
if (caseInsensitive) {
|
|
517
|
+
keywordList = keywordList.map((x) => x.toLowerCase());
|
|
518
|
+
}
|
|
519
|
+
keywordList.forEach(function(keyword) {
|
|
520
|
+
const pair = keyword.split("|");
|
|
521
|
+
compiledKeywords[pair[0]] = [scopeName2, scoreForKeyword(pair[0], pair[1])];
|
|
197
522
|
});
|
|
198
|
-
Object.freeze && (Object.freeze(type.props), Object.freeze(type));
|
|
199
|
-
return type;
|
|
200
523
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return
|
|
524
|
+
}
|
|
525
|
+
function scoreForKeyword(keyword, providedScore) {
|
|
526
|
+
if (providedScore) {
|
|
527
|
+
return Number(providedScore);
|
|
528
|
+
}
|
|
529
|
+
return commonKeyword(keyword) ? 0 : 1;
|
|
530
|
+
}
|
|
531
|
+
function commonKeyword(keyword) {
|
|
532
|
+
return COMMON_KEYWORDS.includes(keyword.toLowerCase());
|
|
533
|
+
}
|
|
534
|
+
var seenDeprecations = {};
|
|
535
|
+
var error = (message) => {
|
|
536
|
+
console.error(message);
|
|
537
|
+
};
|
|
538
|
+
var warn = (message, ...args) => {
|
|
539
|
+
console.log(`WARN: ${message}`, ...args);
|
|
540
|
+
};
|
|
541
|
+
var deprecated = (version2, message) => {
|
|
542
|
+
if (seenDeprecations[`${version2}/${message}`])
|
|
543
|
+
return;
|
|
544
|
+
console.log(`Deprecated as of ${version2}. ${message}`);
|
|
545
|
+
seenDeprecations[`${version2}/${message}`] = true;
|
|
546
|
+
};
|
|
547
|
+
var MultiClassError = new Error;
|
|
548
|
+
function remapScopeNames(mode, regexes, { key }) {
|
|
549
|
+
let offset = 0;
|
|
550
|
+
const scopeNames = mode[key];
|
|
551
|
+
const emit = {};
|
|
552
|
+
const positions = {};
|
|
553
|
+
for (let i = 1;i <= regexes.length; i++) {
|
|
554
|
+
positions[i + offset] = scopeNames[i];
|
|
555
|
+
emit[i + offset] = true;
|
|
556
|
+
offset += countMatchGroups(regexes[i - 1]);
|
|
557
|
+
}
|
|
558
|
+
mode[key] = positions;
|
|
559
|
+
mode[key]._emit = emit;
|
|
560
|
+
mode[key]._multi = true;
|
|
561
|
+
}
|
|
562
|
+
function beginMultiClass(mode) {
|
|
563
|
+
if (!Array.isArray(mode.begin))
|
|
564
|
+
return;
|
|
565
|
+
if (mode.skip || mode.excludeBegin || mode.returnBegin) {
|
|
566
|
+
error("skip, excludeBegin, returnBegin not compatible with beginScope: {}");
|
|
567
|
+
throw MultiClassError;
|
|
205
568
|
}
|
|
206
|
-
|
|
207
|
-
|
|
569
|
+
if (typeof mode.beginScope !== "object" || mode.beginScope === null) {
|
|
570
|
+
error("beginScope must be object");
|
|
571
|
+
throw MultiClassError;
|
|
208
572
|
}
|
|
209
|
-
|
|
210
|
-
|
|
573
|
+
remapScopeNames(mode, mode.begin, { key: "beginScope" });
|
|
574
|
+
mode.begin = _rewriteBackreferences(mode.begin, { joinWith: "" });
|
|
575
|
+
}
|
|
576
|
+
function endMultiClass(mode) {
|
|
577
|
+
if (!Array.isArray(mode.end))
|
|
578
|
+
return;
|
|
579
|
+
if (mode.skip || mode.excludeEnd || mode.returnEnd) {
|
|
580
|
+
error("skip, excludeEnd, returnEnd not compatible with endScope: {}");
|
|
581
|
+
throw MultiClassError;
|
|
211
582
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
583
|
+
if (typeof mode.endScope !== "object" || mode.endScope === null) {
|
|
584
|
+
error("endScope must be object");
|
|
585
|
+
throw MultiClassError;
|
|
586
|
+
}
|
|
587
|
+
remapScopeNames(mode, mode.end, { key: "endScope" });
|
|
588
|
+
mode.end = _rewriteBackreferences(mode.end, { joinWith: "" });
|
|
589
|
+
}
|
|
590
|
+
function scopeSugar(mode) {
|
|
591
|
+
if (mode.scope && typeof mode.scope === "object" && mode.scope !== null) {
|
|
592
|
+
mode.beginScope = mode.scope;
|
|
593
|
+
delete mode.scope;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
function MultiClass(mode) {
|
|
597
|
+
scopeSugar(mode);
|
|
598
|
+
if (typeof mode.beginScope === "string") {
|
|
599
|
+
mode.beginScope = { _wrap: mode.beginScope };
|
|
600
|
+
}
|
|
601
|
+
if (typeof mode.endScope === "string") {
|
|
602
|
+
mode.endScope = { _wrap: mode.endScope };
|
|
603
|
+
}
|
|
604
|
+
beginMultiClass(mode);
|
|
605
|
+
endMultiClass(mode);
|
|
606
|
+
}
|
|
607
|
+
function compileLanguage(language) {
|
|
608
|
+
function langRe(value, global) {
|
|
609
|
+
return new RegExp(source(value), "m" + (language.case_insensitive ? "i" : "") + (language.unicodeRegex ? "u" : "") + (global ? "g" : ""));
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
class MultiRegex {
|
|
613
|
+
constructor() {
|
|
614
|
+
this.matchIndexes = {};
|
|
615
|
+
this.regexes = [];
|
|
616
|
+
this.matchAt = 1;
|
|
617
|
+
this.position = 0;
|
|
618
|
+
}
|
|
619
|
+
addRule(re, opts) {
|
|
620
|
+
opts.position = this.position++;
|
|
621
|
+
this.matchIndexes[this.matchAt] = opts;
|
|
622
|
+
this.regexes.push([opts, re]);
|
|
623
|
+
this.matchAt += countMatchGroups(re) + 1;
|
|
624
|
+
}
|
|
625
|
+
compile() {
|
|
626
|
+
if (this.regexes.length === 0) {
|
|
627
|
+
this.exec = () => null;
|
|
628
|
+
}
|
|
629
|
+
const terminators = this.regexes.map((el) => el[1]);
|
|
630
|
+
this.matcherRe = langRe(_rewriteBackreferences(terminators, { joinWith: "|" }), true);
|
|
631
|
+
this.lastIndex = 0;
|
|
632
|
+
}
|
|
633
|
+
exec(s) {
|
|
634
|
+
this.matcherRe.lastIndex = this.lastIndex;
|
|
635
|
+
const match = this.matcherRe.exec(s);
|
|
636
|
+
if (!match) {
|
|
637
|
+
return null;
|
|
638
|
+
}
|
|
639
|
+
const i = match.findIndex((el, i2) => i2 > 0 && el !== undefined);
|
|
640
|
+
const matchData = this.matchIndexes[i];
|
|
641
|
+
match.splice(0, i);
|
|
642
|
+
return Object.assign(match, matchData);
|
|
643
|
+
}
|
|
217
644
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
645
|
+
|
|
646
|
+
class ResumableMultiRegex {
|
|
647
|
+
constructor() {
|
|
648
|
+
this.rules = [];
|
|
649
|
+
this.multiRegexes = [];
|
|
650
|
+
this.count = 0;
|
|
651
|
+
this.lastIndex = 0;
|
|
652
|
+
this.regexIndex = 0;
|
|
653
|
+
}
|
|
654
|
+
getMatcher(index) {
|
|
655
|
+
if (this.multiRegexes[index])
|
|
656
|
+
return this.multiRegexes[index];
|
|
657
|
+
const matcher = new MultiRegex;
|
|
658
|
+
this.rules.slice(index).forEach(([re, opts]) => matcher.addRule(re, opts));
|
|
659
|
+
matcher.compile();
|
|
660
|
+
this.multiRegexes[index] = matcher;
|
|
661
|
+
return matcher;
|
|
662
|
+
}
|
|
663
|
+
resumingScanAtSamePosition() {
|
|
664
|
+
return this.regexIndex !== 0;
|
|
665
|
+
}
|
|
666
|
+
considerAll() {
|
|
667
|
+
this.regexIndex = 0;
|
|
668
|
+
}
|
|
669
|
+
addRule(re, opts) {
|
|
670
|
+
this.rules.push([re, opts]);
|
|
671
|
+
if (opts.type === "begin")
|
|
672
|
+
this.count++;
|
|
673
|
+
}
|
|
674
|
+
exec(s) {
|
|
675
|
+
const m = this.getMatcher(this.regexIndex);
|
|
676
|
+
m.lastIndex = this.lastIndex;
|
|
677
|
+
let result = m.exec(s);
|
|
678
|
+
if (this.resumingScanAtSamePosition()) {
|
|
679
|
+
if (result && result.index === this.lastIndex)
|
|
680
|
+
;
|
|
681
|
+
else {
|
|
682
|
+
const m2 = this.getMatcher(0);
|
|
683
|
+
m2.lastIndex = this.lastIndex + 1;
|
|
684
|
+
result = m2.exec(s);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
if (result) {
|
|
688
|
+
this.regexIndex += result.position + 1;
|
|
689
|
+
if (this.regexIndex === this.count) {
|
|
690
|
+
this.considerAll();
|
|
237
691
|
}
|
|
692
|
+
}
|
|
693
|
+
return result;
|
|
238
694
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
if (
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
if (
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
695
|
+
}
|
|
696
|
+
function buildModeRegex(mode) {
|
|
697
|
+
const mm = new ResumableMultiRegex;
|
|
698
|
+
mode.contains.forEach((term) => mm.addRule(term.begin, { rule: term, type: "begin" }));
|
|
699
|
+
if (mode.terminatorEnd) {
|
|
700
|
+
mm.addRule(mode.terminatorEnd, { type: "end" });
|
|
701
|
+
}
|
|
702
|
+
if (mode.illegal) {
|
|
703
|
+
mm.addRule(mode.illegal, { type: "illegal" });
|
|
704
|
+
}
|
|
705
|
+
return mm;
|
|
706
|
+
}
|
|
707
|
+
function compileMode(mode, parent) {
|
|
708
|
+
const cmode = mode;
|
|
709
|
+
if (mode.isCompiled)
|
|
710
|
+
return cmode;
|
|
711
|
+
[
|
|
712
|
+
scopeClassName,
|
|
713
|
+
compileMatch,
|
|
714
|
+
MultiClass,
|
|
715
|
+
beforeMatchExt
|
|
716
|
+
].forEach((ext) => ext(mode, parent));
|
|
717
|
+
language.compilerExtensions.forEach((ext) => ext(mode, parent));
|
|
718
|
+
mode.__beforeBegin = null;
|
|
719
|
+
[
|
|
720
|
+
beginKeywords,
|
|
721
|
+
compileIllegal,
|
|
722
|
+
compileRelevance
|
|
723
|
+
].forEach((ext) => ext(mode, parent));
|
|
724
|
+
mode.isCompiled = true;
|
|
725
|
+
let keywordPattern = null;
|
|
726
|
+
if (typeof mode.keywords === "object" && mode.keywords.$pattern) {
|
|
727
|
+
mode.keywords = Object.assign({}, mode.keywords);
|
|
728
|
+
keywordPattern = mode.keywords.$pattern;
|
|
729
|
+
delete mode.keywords.$pattern;
|
|
730
|
+
}
|
|
731
|
+
keywordPattern = keywordPattern || /\w+/;
|
|
732
|
+
if (mode.keywords) {
|
|
733
|
+
mode.keywords = compileKeywords(mode.keywords, language.case_insensitive);
|
|
734
|
+
}
|
|
735
|
+
cmode.keywordPatternRe = langRe(keywordPattern, true);
|
|
736
|
+
if (parent) {
|
|
737
|
+
if (!mode.begin)
|
|
738
|
+
mode.begin = /\B|\b/;
|
|
739
|
+
cmode.beginRe = langRe(cmode.begin);
|
|
740
|
+
if (!mode.end && !mode.endsWithParent)
|
|
741
|
+
mode.end = /\B|\b/;
|
|
742
|
+
if (mode.end)
|
|
743
|
+
cmode.endRe = langRe(cmode.end);
|
|
744
|
+
cmode.terminatorEnd = source(cmode.end) || "";
|
|
745
|
+
if (mode.endsWithParent && parent.terminatorEnd) {
|
|
746
|
+
cmode.terminatorEnd += (mode.end ? "|" : "") + parent.terminatorEnd;
|
|
264
747
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
if (
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
748
|
+
}
|
|
749
|
+
if (mode.illegal)
|
|
750
|
+
cmode.illegalRe = langRe(mode.illegal);
|
|
751
|
+
if (!mode.contains)
|
|
752
|
+
mode.contains = [];
|
|
753
|
+
mode.contains = [].concat(...mode.contains.map(function(c) {
|
|
754
|
+
return expandOrCloneMode(c === "self" ? mode : c);
|
|
755
|
+
}));
|
|
756
|
+
mode.contains.forEach(function(c) {
|
|
757
|
+
compileMode(c, cmode);
|
|
758
|
+
});
|
|
759
|
+
if (mode.starts) {
|
|
760
|
+
compileMode(mode.starts, parent);
|
|
761
|
+
}
|
|
762
|
+
cmode.matcher = buildModeRegex(cmode);
|
|
763
|
+
return cmode;
|
|
764
|
+
}
|
|
765
|
+
if (!language.compilerExtensions)
|
|
766
|
+
language.compilerExtensions = [];
|
|
767
|
+
if (language.contains && language.contains.includes("self")) {
|
|
768
|
+
throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");
|
|
769
|
+
}
|
|
770
|
+
language.classNameAliases = inherit$1(language.classNameAliases || {});
|
|
771
|
+
return compileMode(language);
|
|
772
|
+
}
|
|
773
|
+
function dependencyOnParent(mode) {
|
|
774
|
+
if (!mode)
|
|
775
|
+
return false;
|
|
776
|
+
return mode.endsWithParent || dependencyOnParent(mode.starts);
|
|
777
|
+
}
|
|
778
|
+
function expandOrCloneMode(mode) {
|
|
779
|
+
if (mode.variants && !mode.cachedVariants) {
|
|
780
|
+
mode.cachedVariants = mode.variants.map(function(variant) {
|
|
781
|
+
return inherit$1(mode, { variants: null }, variant);
|
|
296
782
|
});
|
|
783
|
+
}
|
|
784
|
+
if (mode.cachedVariants) {
|
|
785
|
+
return mode.cachedVariants;
|
|
786
|
+
}
|
|
787
|
+
if (dependencyOnParent(mode)) {
|
|
788
|
+
return inherit$1(mode, { starts: mode.starts ? inherit$1(mode.starts) : null });
|
|
789
|
+
}
|
|
790
|
+
if (Object.isFrozen(mode)) {
|
|
791
|
+
return inherit$1(mode);
|
|
792
|
+
}
|
|
793
|
+
return mode;
|
|
794
|
+
}
|
|
795
|
+
var version = "11.11.1";
|
|
796
|
+
|
|
797
|
+
class HTMLInjectionError extends Error {
|
|
798
|
+
constructor(reason, html) {
|
|
799
|
+
super(reason);
|
|
800
|
+
this.name = "HTMLInjectionError";
|
|
801
|
+
this.html = html;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
var escape = escapeHTML;
|
|
805
|
+
var inherit = inherit$1;
|
|
806
|
+
var NO_MATCH = Symbol("nomatch");
|
|
807
|
+
var MAX_KEYWORD_HITS = 7;
|
|
808
|
+
var HLJS = function(hljs) {
|
|
809
|
+
const languages = Object.create(null);
|
|
810
|
+
const aliases = Object.create(null);
|
|
811
|
+
const plugins = [];
|
|
812
|
+
let SAFE_MODE = true;
|
|
813
|
+
const LANGUAGE_NOT_FOUND = "Could not find the language '{}', did you forget to load/include a language module?";
|
|
814
|
+
const PLAINTEXT_LANGUAGE = { disableAutodetect: true, name: "Plain text", contains: [] };
|
|
815
|
+
let options = {
|
|
816
|
+
ignoreUnescapedHTML: false,
|
|
817
|
+
throwUnescapedHTML: false,
|
|
818
|
+
noHighlightRe: /^(no-?highlight)$/i,
|
|
819
|
+
languageDetectRe: /\blang(?:uage)?-([\w-]+)\b/i,
|
|
820
|
+
classPrefix: "hljs-",
|
|
821
|
+
cssSelector: "pre code",
|
|
822
|
+
languages: null,
|
|
823
|
+
__emitter: TokenTreeEmitter
|
|
824
|
+
};
|
|
825
|
+
function shouldNotHighlight(languageName) {
|
|
826
|
+
return options.noHighlightRe.test(languageName);
|
|
827
|
+
}
|
|
828
|
+
function blockLanguage(block) {
|
|
829
|
+
let classes = block.className + " ";
|
|
830
|
+
classes += block.parentNode ? block.parentNode.className : "";
|
|
831
|
+
const match = options.languageDetectRe.exec(classes);
|
|
832
|
+
if (match) {
|
|
833
|
+
const language = getLanguage(match[1]);
|
|
834
|
+
if (!language) {
|
|
835
|
+
warn(LANGUAGE_NOT_FOUND.replace("{}", match[1]));
|
|
836
|
+
warn("Falling back to no-highlight mode for this block.", block);
|
|
837
|
+
}
|
|
838
|
+
return language ? match[1] : "no-highlight";
|
|
839
|
+
}
|
|
840
|
+
return classes.split(/\s+/).find((_class) => shouldNotHighlight(_class) || getLanguage(_class));
|
|
841
|
+
}
|
|
842
|
+
function highlight2(codeOrLanguageName, optionsOrCode, ignoreIllegals) {
|
|
843
|
+
let code = "";
|
|
844
|
+
let languageName = "";
|
|
845
|
+
if (typeof optionsOrCode === "object") {
|
|
846
|
+
code = codeOrLanguageName;
|
|
847
|
+
ignoreIllegals = optionsOrCode.ignoreIllegals;
|
|
848
|
+
languageName = optionsOrCode.language;
|
|
849
|
+
} else {
|
|
850
|
+
deprecated("10.7.0", "highlight(lang, code, ...args) has been deprecated.");
|
|
851
|
+
deprecated("10.7.0", `Please use highlight(code, options) instead.
|
|
852
|
+
https://github.com/highlightjs/highlight.js/issues/2277`);
|
|
853
|
+
languageName = codeOrLanguageName;
|
|
854
|
+
code = optionsOrCode;
|
|
855
|
+
}
|
|
856
|
+
if (ignoreIllegals === undefined) {
|
|
857
|
+
ignoreIllegals = true;
|
|
858
|
+
}
|
|
859
|
+
const context = {
|
|
860
|
+
code,
|
|
861
|
+
language: languageName
|
|
862
|
+
};
|
|
863
|
+
fire("before:highlight", context);
|
|
864
|
+
const result = context.result ? context.result : _highlight(context.language, context.code, ignoreIllegals);
|
|
865
|
+
result.code = context.code;
|
|
866
|
+
fire("after:highlight", result);
|
|
297
867
|
return result;
|
|
298
868
|
}
|
|
299
|
-
function
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
869
|
+
function _highlight(languageName, codeToHighlight, ignoreIllegals, continuation) {
|
|
870
|
+
const keywordHits = Object.create(null);
|
|
871
|
+
function keywordData(mode, matchText) {
|
|
872
|
+
return mode.keywords[matchText];
|
|
873
|
+
}
|
|
874
|
+
function processKeywords() {
|
|
875
|
+
if (!top.keywords) {
|
|
876
|
+
emitter.addText(modeBuffer);
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
let lastIndex = 0;
|
|
880
|
+
top.keywordPatternRe.lastIndex = 0;
|
|
881
|
+
let match = top.keywordPatternRe.exec(modeBuffer);
|
|
882
|
+
let buf = "";
|
|
883
|
+
while (match) {
|
|
884
|
+
buf += modeBuffer.substring(lastIndex, match.index);
|
|
885
|
+
const word = language.case_insensitive ? match[0].toLowerCase() : match[0];
|
|
886
|
+
const data = keywordData(top, word);
|
|
887
|
+
if (data) {
|
|
888
|
+
const [kind, keywordRelevance] = data;
|
|
889
|
+
emitter.addText(buf);
|
|
890
|
+
buf = "";
|
|
891
|
+
keywordHits[word] = (keywordHits[word] || 0) + 1;
|
|
892
|
+
if (keywordHits[word] <= MAX_KEYWORD_HITS)
|
|
893
|
+
relevance += keywordRelevance;
|
|
894
|
+
if (kind.startsWith("_")) {
|
|
895
|
+
buf += match[0];
|
|
896
|
+
} else {
|
|
897
|
+
const cssClass = language.classNameAliases[kind] || kind;
|
|
898
|
+
emitKeyword(match[0], cssClass);
|
|
899
|
+
}
|
|
900
|
+
} else {
|
|
901
|
+
buf += match[0];
|
|
312
902
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
903
|
+
lastIndex = top.keywordPatternRe.lastIndex;
|
|
904
|
+
match = top.keywordPatternRe.exec(modeBuffer);
|
|
905
|
+
}
|
|
906
|
+
buf += modeBuffer.substring(lastIndex);
|
|
907
|
+
emitter.addText(buf);
|
|
908
|
+
}
|
|
909
|
+
function processSubLanguage() {
|
|
910
|
+
if (modeBuffer === "")
|
|
911
|
+
return;
|
|
912
|
+
let result2 = null;
|
|
913
|
+
if (typeof top.subLanguage === "string") {
|
|
914
|
+
if (!languages[top.subLanguage]) {
|
|
915
|
+
emitter.addText(modeBuffer);
|
|
916
|
+
return;
|
|
320
917
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
918
|
+
result2 = _highlight(top.subLanguage, modeBuffer, true, continuations[top.subLanguage]);
|
|
919
|
+
continuations[top.subLanguage] = result2._top;
|
|
920
|
+
} else {
|
|
921
|
+
result2 = highlightAuto(modeBuffer, top.subLanguage.length ? top.subLanguage : null);
|
|
922
|
+
}
|
|
923
|
+
if (top.relevance > 0) {
|
|
924
|
+
relevance += result2.relevance;
|
|
327
925
|
}
|
|
328
|
-
|
|
926
|
+
emitter.__addSublanguage(result2._emitter, result2.language);
|
|
329
927
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
Did you accidentally put curly braces around the import?`, ioInfo), "default" in ioInfo || console.error(`lazy: Expected the result of a dynamic import() call. Instead received: %s
|
|
337
|
-
|
|
338
|
-
Your code should look like:
|
|
339
|
-
const MyComponent = lazy(() => import('./MyComponent'))`, ioInfo), ioInfo.default;
|
|
340
|
-
throw payload._result;
|
|
341
|
-
}
|
|
342
|
-
function resolveDispatcher() {
|
|
343
|
-
var dispatcher = ReactSharedInternals.H;
|
|
344
|
-
dispatcher === null && console.error(`Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
|
|
345
|
-
1. You might have mismatching versions of React and the renderer (such as React DOM)
|
|
346
|
-
2. You might be breaking the Rules of Hooks
|
|
347
|
-
3. You might have more than one copy of React in the same app
|
|
348
|
-
See https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem.`);
|
|
349
|
-
return dispatcher;
|
|
350
|
-
}
|
|
351
|
-
function releaseAsyncTransition() {
|
|
352
|
-
ReactSharedInternals.asyncTransitions--;
|
|
353
|
-
}
|
|
354
|
-
function enqueueTask(task) {
|
|
355
|
-
if (enqueueTaskImpl === null)
|
|
356
|
-
try {
|
|
357
|
-
var requireString = ("require" + Math.random()).slice(0, 7);
|
|
358
|
-
enqueueTaskImpl = (module && module[requireString]).call(module, "timers").setImmediate;
|
|
359
|
-
} catch (_err) {
|
|
360
|
-
enqueueTaskImpl = function(callback) {
|
|
361
|
-
didWarnAboutMessageChannel === false && (didWarnAboutMessageChannel = true, typeof MessageChannel === "undefined" && console.error("This browser does not have a MessageChannel implementation, so enqueuing tasks via await act(async () => ...) will fail. Please file an issue at https://github.com/facebook/react/issues if you encounter this warning."));
|
|
362
|
-
var channel = new MessageChannel;
|
|
363
|
-
channel.port1.onmessage = callback;
|
|
364
|
-
channel.port2.postMessage(undefined);
|
|
365
|
-
};
|
|
928
|
+
function processBuffer() {
|
|
929
|
+
if (top.subLanguage != null) {
|
|
930
|
+
processSubLanguage();
|
|
931
|
+
} else {
|
|
932
|
+
processKeywords();
|
|
366
933
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
return recursivelyFlushAsyncActWork(returnValue, resolve, reject);
|
|
384
|
-
});
|
|
385
|
-
return;
|
|
386
|
-
} catch (error) {
|
|
387
|
-
ReactSharedInternals.thrownErrors.push(error);
|
|
934
|
+
modeBuffer = "";
|
|
935
|
+
}
|
|
936
|
+
function emitKeyword(keyword, scope) {
|
|
937
|
+
if (keyword === "")
|
|
938
|
+
return;
|
|
939
|
+
emitter.startScope(scope);
|
|
940
|
+
emitter.addText(keyword);
|
|
941
|
+
emitter.endScope();
|
|
942
|
+
}
|
|
943
|
+
function emitMultiClass(scope, match) {
|
|
944
|
+
let i = 1;
|
|
945
|
+
const max = match.length - 1;
|
|
946
|
+
while (i <= max) {
|
|
947
|
+
if (!scope._emit[i]) {
|
|
948
|
+
i++;
|
|
949
|
+
continue;
|
|
388
950
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
try {
|
|
398
|
-
for (;i < queue.length; i++) {
|
|
399
|
-
var callback = queue[i];
|
|
400
|
-
do {
|
|
401
|
-
ReactSharedInternals.didUsePromise = false;
|
|
402
|
-
var continuation = callback(false);
|
|
403
|
-
if (continuation !== null) {
|
|
404
|
-
if (ReactSharedInternals.didUsePromise) {
|
|
405
|
-
queue[i] = callback;
|
|
406
|
-
queue.splice(0, i);
|
|
407
|
-
return;
|
|
408
|
-
}
|
|
409
|
-
callback = continuation;
|
|
410
|
-
} else
|
|
411
|
-
break;
|
|
412
|
-
} while (1);
|
|
951
|
+
const klass = language.classNameAliases[scope[i]] || scope[i];
|
|
952
|
+
const text = match[i];
|
|
953
|
+
if (klass) {
|
|
954
|
+
emitKeyword(text, klass);
|
|
955
|
+
} else {
|
|
956
|
+
modeBuffer = text;
|
|
957
|
+
processKeywords();
|
|
958
|
+
modeBuffer = "";
|
|
413
959
|
}
|
|
414
|
-
|
|
415
|
-
} catch (error) {
|
|
416
|
-
queue.splice(0, i + 1), ReactSharedInternals.thrownErrors.push(error);
|
|
417
|
-
} finally {
|
|
418
|
-
isFlushing = false;
|
|
960
|
+
i++;
|
|
419
961
|
}
|
|
420
962
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
}, assign = Object.assign, emptyObject = {};
|
|
437
|
-
Object.freeze(emptyObject);
|
|
438
|
-
Component.prototype.isReactComponent = {};
|
|
439
|
-
Component.prototype.setState = function(partialState, callback) {
|
|
440
|
-
if (typeof partialState !== "object" && typeof partialState !== "function" && partialState != null)
|
|
441
|
-
throw Error("takes an object of state variables to update or a function which returns an object of state variables.");
|
|
442
|
-
this.updater.enqueueSetState(this, partialState, callback, "setState");
|
|
443
|
-
};
|
|
444
|
-
Component.prototype.forceUpdate = function(callback) {
|
|
445
|
-
this.updater.enqueueForceUpdate(this, callback, "forceUpdate");
|
|
446
|
-
};
|
|
447
|
-
var deprecatedAPIs = {
|
|
448
|
-
isMounted: [
|
|
449
|
-
"isMounted",
|
|
450
|
-
"Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks."
|
|
451
|
-
],
|
|
452
|
-
replaceState: [
|
|
453
|
-
"replaceState",
|
|
454
|
-
"Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236)."
|
|
455
|
-
]
|
|
456
|
-
};
|
|
457
|
-
for (fnName in deprecatedAPIs)
|
|
458
|
-
deprecatedAPIs.hasOwnProperty(fnName) && defineDeprecationWarning(fnName, deprecatedAPIs[fnName]);
|
|
459
|
-
ComponentDummy.prototype = Component.prototype;
|
|
460
|
-
deprecatedAPIs = PureComponent.prototype = new ComponentDummy;
|
|
461
|
-
deprecatedAPIs.constructor = PureComponent;
|
|
462
|
-
assign(deprecatedAPIs, Component.prototype);
|
|
463
|
-
deprecatedAPIs.isPureReactComponent = true;
|
|
464
|
-
var isArrayImpl = Array.isArray, REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"), ReactSharedInternals = {
|
|
465
|
-
H: null,
|
|
466
|
-
A: null,
|
|
467
|
-
T: null,
|
|
468
|
-
S: null,
|
|
469
|
-
actQueue: null,
|
|
470
|
-
asyncTransitions: 0,
|
|
471
|
-
isBatchingLegacy: false,
|
|
472
|
-
didScheduleLegacyUpdate: false,
|
|
473
|
-
didUsePromise: false,
|
|
474
|
-
thrownErrors: [],
|
|
475
|
-
getCurrentStack: null,
|
|
476
|
-
recentlyCreatedOwnerStacks: 0
|
|
477
|
-
}, hasOwnProperty = Object.prototype.hasOwnProperty, createTask = console.createTask ? console.createTask : function() {
|
|
478
|
-
return null;
|
|
479
|
-
};
|
|
480
|
-
deprecatedAPIs = {
|
|
481
|
-
react_stack_bottom_frame: function(callStackForError) {
|
|
482
|
-
return callStackForError();
|
|
963
|
+
function startNewMode(mode, match) {
|
|
964
|
+
if (mode.scope && typeof mode.scope === "string") {
|
|
965
|
+
emitter.openNode(language.classNameAliases[mode.scope] || mode.scope);
|
|
966
|
+
}
|
|
967
|
+
if (mode.beginScope) {
|
|
968
|
+
if (mode.beginScope._wrap) {
|
|
969
|
+
emitKeyword(modeBuffer, language.classNameAliases[mode.beginScope._wrap] || mode.beginScope._wrap);
|
|
970
|
+
modeBuffer = "";
|
|
971
|
+
} else if (mode.beginScope._multi) {
|
|
972
|
+
emitMultiClass(mode.beginScope, match);
|
|
973
|
+
modeBuffer = "";
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
top = Object.create(mode, { parent: { value: top } });
|
|
977
|
+
return top;
|
|
483
978
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
979
|
+
function endOfMode(mode, match, matchPlusRemainder) {
|
|
980
|
+
let matched = startsWith(mode.endRe, matchPlusRemainder);
|
|
981
|
+
if (matched) {
|
|
982
|
+
if (mode["on:end"]) {
|
|
983
|
+
const resp = new Response(mode);
|
|
984
|
+
mode["on:end"](match, resp);
|
|
985
|
+
if (resp.isMatchIgnored)
|
|
986
|
+
matched = false;
|
|
987
|
+
}
|
|
988
|
+
if (matched) {
|
|
989
|
+
while (mode.endsParent && mode.parent) {
|
|
990
|
+
mode = mode.parent;
|
|
991
|
+
}
|
|
992
|
+
return mode;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
if (mode.endsWithParent) {
|
|
996
|
+
return endOfMode(mode.parent, match, matchPlusRemainder);
|
|
997
|
+
}
|
|
502
998
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
c: function(size) {
|
|
512
|
-
return resolveDispatcher().useMemoCache(size);
|
|
999
|
+
function doIgnore(lexeme) {
|
|
1000
|
+
if (top.matcher.regexIndex === 0) {
|
|
1001
|
+
modeBuffer += lexeme[0];
|
|
1002
|
+
return 1;
|
|
1003
|
+
} else {
|
|
1004
|
+
resumeScanAtSamePosition = true;
|
|
1005
|
+
return 0;
|
|
1006
|
+
}
|
|
513
1007
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
1008
|
+
function doBeginMatch(match) {
|
|
1009
|
+
const lexeme = match[0];
|
|
1010
|
+
const newMode = match.rule;
|
|
1011
|
+
const resp = new Response(newMode);
|
|
1012
|
+
const beforeCallbacks = [newMode.__beforeBegin, newMode["on:begin"]];
|
|
1013
|
+
for (const cb of beforeCallbacks) {
|
|
1014
|
+
if (!cb)
|
|
1015
|
+
continue;
|
|
1016
|
+
cb(match, resp);
|
|
1017
|
+
if (resp.isMatchIgnored)
|
|
1018
|
+
return doIgnore(lexeme);
|
|
1019
|
+
}
|
|
1020
|
+
if (newMode.skip) {
|
|
1021
|
+
modeBuffer += lexeme;
|
|
1022
|
+
} else {
|
|
1023
|
+
if (newMode.excludeBegin) {
|
|
1024
|
+
modeBuffer += lexeme;
|
|
1025
|
+
}
|
|
1026
|
+
processBuffer();
|
|
1027
|
+
if (!newMode.returnBegin && !newMode.excludeBegin) {
|
|
1028
|
+
modeBuffer = lexeme;
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
startNewMode(newMode, match);
|
|
1032
|
+
return newMode.returnBegin ? 0 : lexeme.length;
|
|
538
1033
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
}
|
|
559
|
-
if (0 < ReactSharedInternals.thrownErrors.length)
|
|
560
|
-
throw popActScope(prevActQueue, prevActScopeDepth), callback = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, callback;
|
|
561
|
-
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
|
562
|
-
var thenable = result;
|
|
563
|
-
queueSeveralMicrotasks(function() {
|
|
564
|
-
didAwaitActCall || didWarnNoAwaitAct || (didWarnNoAwaitAct = true, console.error("You called act(async () => ...) without await. This could lead to unexpected testing behaviour, interleaving multiple act calls and mixing their scopes. You should - await act(async () => ...);"));
|
|
565
|
-
});
|
|
566
|
-
return {
|
|
567
|
-
then: function(resolve, reject) {
|
|
568
|
-
didAwaitActCall = true;
|
|
569
|
-
thenable.then(function(returnValue) {
|
|
570
|
-
popActScope(prevActQueue, prevActScopeDepth);
|
|
571
|
-
if (prevActScopeDepth === 0) {
|
|
572
|
-
try {
|
|
573
|
-
flushActQueue(queue), enqueueTask(function() {
|
|
574
|
-
return recursivelyFlushAsyncActWork(returnValue, resolve, reject);
|
|
575
|
-
});
|
|
576
|
-
} catch (error$0) {
|
|
577
|
-
ReactSharedInternals.thrownErrors.push(error$0);
|
|
578
|
-
}
|
|
579
|
-
if (0 < ReactSharedInternals.thrownErrors.length) {
|
|
580
|
-
var _thrownError = aggregateErrors(ReactSharedInternals.thrownErrors);
|
|
581
|
-
ReactSharedInternals.thrownErrors.length = 0;
|
|
582
|
-
reject(_thrownError);
|
|
583
|
-
}
|
|
584
|
-
} else
|
|
585
|
-
resolve(returnValue);
|
|
586
|
-
}, function(error) {
|
|
587
|
-
popActScope(prevActQueue, prevActScopeDepth);
|
|
588
|
-
0 < ReactSharedInternals.thrownErrors.length ? (error = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, reject(error)) : reject(error);
|
|
589
|
-
});
|
|
1034
|
+
function doEndMatch(match) {
|
|
1035
|
+
const lexeme = match[0];
|
|
1036
|
+
const matchPlusRemainder = codeToHighlight.substring(match.index);
|
|
1037
|
+
const endMode = endOfMode(top, match, matchPlusRemainder);
|
|
1038
|
+
if (!endMode) {
|
|
1039
|
+
return NO_MATCH;
|
|
1040
|
+
}
|
|
1041
|
+
const origin = top;
|
|
1042
|
+
if (top.endScope && top.endScope._wrap) {
|
|
1043
|
+
processBuffer();
|
|
1044
|
+
emitKeyword(lexeme, top.endScope._wrap);
|
|
1045
|
+
} else if (top.endScope && top.endScope._multi) {
|
|
1046
|
+
processBuffer();
|
|
1047
|
+
emitMultiClass(top.endScope, match);
|
|
1048
|
+
} else if (origin.skip) {
|
|
1049
|
+
modeBuffer += lexeme;
|
|
1050
|
+
} else {
|
|
1051
|
+
if (!(origin.returnEnd || origin.excludeEnd)) {
|
|
1052
|
+
modeBuffer += lexeme;
|
|
590
1053
|
}
|
|
591
|
-
|
|
1054
|
+
processBuffer();
|
|
1055
|
+
if (origin.excludeEnd) {
|
|
1056
|
+
modeBuffer = lexeme;
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
do {
|
|
1060
|
+
if (top.scope) {
|
|
1061
|
+
emitter.closeNode();
|
|
1062
|
+
}
|
|
1063
|
+
if (!top.skip && !top.subLanguage) {
|
|
1064
|
+
relevance += top.relevance;
|
|
1065
|
+
}
|
|
1066
|
+
top = top.parent;
|
|
1067
|
+
} while (top !== endMode.parent);
|
|
1068
|
+
if (endMode.starts) {
|
|
1069
|
+
startNewMode(endMode.starts, match);
|
|
1070
|
+
}
|
|
1071
|
+
return origin.returnEnd ? 0 : lexeme.length;
|
|
592
1072
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
throw callback = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, callback;
|
|
600
|
-
return {
|
|
601
|
-
then: function(resolve, reject) {
|
|
602
|
-
didAwaitActCall = true;
|
|
603
|
-
prevActScopeDepth === 0 ? (ReactSharedInternals.actQueue = queue, enqueueTask(function() {
|
|
604
|
-
return recursivelyFlushAsyncActWork(returnValue$jscomp$0, resolve, reject);
|
|
605
|
-
})) : resolve(returnValue$jscomp$0);
|
|
1073
|
+
function processContinuations() {
|
|
1074
|
+
const list = [];
|
|
1075
|
+
for (let current = top;current !== language; current = current.parent) {
|
|
1076
|
+
if (current.scope) {
|
|
1077
|
+
list.unshift(current.scope);
|
|
1078
|
+
}
|
|
606
1079
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
var props = assign({}, element.props), key = element.key, owner = element._owner;
|
|
625
|
-
if (config != null) {
|
|
626
|
-
var JSCompiler_inline_result;
|
|
627
|
-
a: {
|
|
628
|
-
if (hasOwnProperty.call(config, "ref") && (JSCompiler_inline_result = Object.getOwnPropertyDescriptor(config, "ref").get) && JSCompiler_inline_result.isReactWarning) {
|
|
629
|
-
JSCompiler_inline_result = false;
|
|
630
|
-
break a;
|
|
1080
|
+
list.forEach((item) => emitter.openNode(item));
|
|
1081
|
+
}
|
|
1082
|
+
let lastMatch = {};
|
|
1083
|
+
function processLexeme(textBeforeMatch, match) {
|
|
1084
|
+
const lexeme = match && match[0];
|
|
1085
|
+
modeBuffer += textBeforeMatch;
|
|
1086
|
+
if (lexeme == null) {
|
|
1087
|
+
processBuffer();
|
|
1088
|
+
return 0;
|
|
1089
|
+
}
|
|
1090
|
+
if (lastMatch.type === "begin" && match.type === "end" && lastMatch.index === match.index && lexeme === "") {
|
|
1091
|
+
modeBuffer += codeToHighlight.slice(match.index, match.index + 1);
|
|
1092
|
+
if (!SAFE_MODE) {
|
|
1093
|
+
const err = new Error(`0 width match regex (${languageName})`);
|
|
1094
|
+
err.languageName = languageName;
|
|
1095
|
+
err.badRule = lastMatch.rule;
|
|
1096
|
+
throw err;
|
|
631
1097
|
}
|
|
632
|
-
|
|
1098
|
+
return 1;
|
|
1099
|
+
}
|
|
1100
|
+
lastMatch = match;
|
|
1101
|
+
if (match.type === "begin") {
|
|
1102
|
+
return doBeginMatch(match);
|
|
1103
|
+
} else if (match.type === "illegal" && !ignoreIllegals) {
|
|
1104
|
+
const err = new Error('Illegal lexeme "' + lexeme + '" for mode "' + (top.scope || "<unnamed>") + '"');
|
|
1105
|
+
err.mode = top;
|
|
1106
|
+
throw err;
|
|
1107
|
+
} else if (match.type === "end") {
|
|
1108
|
+
const processed = doEndMatch(match);
|
|
1109
|
+
if (processed !== NO_MATCH) {
|
|
1110
|
+
return processed;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
if (match.type === "illegal" && lexeme === "") {
|
|
1114
|
+
modeBuffer += `
|
|
1115
|
+
`;
|
|
1116
|
+
return 1;
|
|
1117
|
+
}
|
|
1118
|
+
if (iterations > 1e5 && iterations > match.index * 3) {
|
|
1119
|
+
const err = new Error("potential infinite loop, way more iterations than matches");
|
|
1120
|
+
throw err;
|
|
1121
|
+
}
|
|
1122
|
+
modeBuffer += lexeme;
|
|
1123
|
+
return lexeme.length;
|
|
1124
|
+
}
|
|
1125
|
+
const language = getLanguage(languageName);
|
|
1126
|
+
if (!language) {
|
|
1127
|
+
error(LANGUAGE_NOT_FOUND.replace("{}", languageName));
|
|
1128
|
+
throw new Error('Unknown language: "' + languageName + '"');
|
|
1129
|
+
}
|
|
1130
|
+
const md = compileLanguage(language);
|
|
1131
|
+
let result = "";
|
|
1132
|
+
let top = continuation || md;
|
|
1133
|
+
const continuations = {};
|
|
1134
|
+
const emitter = new options.__emitter(options);
|
|
1135
|
+
processContinuations();
|
|
1136
|
+
let modeBuffer = "";
|
|
1137
|
+
let relevance = 0;
|
|
1138
|
+
let index = 0;
|
|
1139
|
+
let iterations = 0;
|
|
1140
|
+
let resumeScanAtSamePosition = false;
|
|
1141
|
+
try {
|
|
1142
|
+
if (!language.__emitTokens) {
|
|
1143
|
+
top.matcher.considerAll();
|
|
1144
|
+
for (;; ) {
|
|
1145
|
+
iterations++;
|
|
1146
|
+
if (resumeScanAtSamePosition) {
|
|
1147
|
+
resumeScanAtSamePosition = false;
|
|
1148
|
+
} else {
|
|
1149
|
+
top.matcher.considerAll();
|
|
1150
|
+
}
|
|
1151
|
+
top.matcher.lastIndex = index;
|
|
1152
|
+
const match = top.matcher.exec(codeToHighlight);
|
|
1153
|
+
if (!match)
|
|
1154
|
+
break;
|
|
1155
|
+
const beforeMatch = codeToHighlight.substring(index, match.index);
|
|
1156
|
+
const processedCount = processLexeme(beforeMatch, match);
|
|
1157
|
+
index = match.index + processedCount;
|
|
1158
|
+
}
|
|
1159
|
+
processLexeme(codeToHighlight.substring(index));
|
|
1160
|
+
} else {
|
|
1161
|
+
language.__emitTokens(codeToHighlight, emitter);
|
|
1162
|
+
}
|
|
1163
|
+
emitter.finalize();
|
|
1164
|
+
result = emitter.toHTML();
|
|
1165
|
+
return {
|
|
1166
|
+
language: languageName,
|
|
1167
|
+
value: result,
|
|
1168
|
+
relevance,
|
|
1169
|
+
illegal: false,
|
|
1170
|
+
_emitter: emitter,
|
|
1171
|
+
_top: top
|
|
1172
|
+
};
|
|
1173
|
+
} catch (err) {
|
|
1174
|
+
if (err.message && err.message.includes("Illegal")) {
|
|
1175
|
+
return {
|
|
1176
|
+
language: languageName,
|
|
1177
|
+
value: escape(codeToHighlight),
|
|
1178
|
+
illegal: true,
|
|
1179
|
+
relevance: 0,
|
|
1180
|
+
_illegalBy: {
|
|
1181
|
+
message: err.message,
|
|
1182
|
+
index,
|
|
1183
|
+
context: codeToHighlight.slice(index - 100, index + 100),
|
|
1184
|
+
mode: err.mode,
|
|
1185
|
+
resultSoFar: result
|
|
1186
|
+
},
|
|
1187
|
+
_emitter: emitter
|
|
1188
|
+
};
|
|
1189
|
+
} else if (SAFE_MODE) {
|
|
1190
|
+
return {
|
|
1191
|
+
language: languageName,
|
|
1192
|
+
value: escape(codeToHighlight),
|
|
1193
|
+
illegal: false,
|
|
1194
|
+
relevance: 0,
|
|
1195
|
+
errorRaised: err,
|
|
1196
|
+
_emitter: emitter,
|
|
1197
|
+
_top: top
|
|
1198
|
+
};
|
|
1199
|
+
} else {
|
|
1200
|
+
throw err;
|
|
633
1201
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
JSCompiler_inline_result = Array(propName);
|
|
644
|
-
for (var i = 0;i < propName; i++)
|
|
645
|
-
JSCompiler_inline_result[i] = arguments[i + 2];
|
|
646
|
-
props.children = JSCompiler_inline_result;
|
|
647
|
-
}
|
|
648
|
-
props = ReactElement(element.type, key, props, owner, element._debugStack, element._debugTask);
|
|
649
|
-
for (key = 2;key < arguments.length; key++)
|
|
650
|
-
validateChildKeys(arguments[key]);
|
|
651
|
-
return props;
|
|
652
|
-
};
|
|
653
|
-
exports.createContext = function(defaultValue) {
|
|
654
|
-
defaultValue = {
|
|
655
|
-
$$typeof: REACT_CONTEXT_TYPE,
|
|
656
|
-
_currentValue: defaultValue,
|
|
657
|
-
_currentValue2: defaultValue,
|
|
658
|
-
_threadCount: 0,
|
|
659
|
-
Provider: null,
|
|
660
|
-
Consumer: null
|
|
661
|
-
};
|
|
662
|
-
defaultValue.Provider = defaultValue;
|
|
663
|
-
defaultValue.Consumer = {
|
|
664
|
-
$$typeof: REACT_CONSUMER_TYPE,
|
|
665
|
-
_context: defaultValue
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
function justTextHighlightResult(code) {
|
|
1205
|
+
const result = {
|
|
1206
|
+
value: escape(code),
|
|
1207
|
+
illegal: false,
|
|
1208
|
+
relevance: 0,
|
|
1209
|
+
_top: PLAINTEXT_LANGUAGE,
|
|
1210
|
+
_emitter: new options.__emitter(options)
|
|
666
1211
|
};
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
childArray[_i] = arguments[_i + 2];
|
|
685
|
-
Object.freeze && Object.freeze(childArray);
|
|
686
|
-
i.children = childArray;
|
|
687
|
-
}
|
|
688
|
-
if (type && type.defaultProps)
|
|
689
|
-
for (propName in childrenLength = type.defaultProps, childrenLength)
|
|
690
|
-
i[propName] === undefined && (i[propName] = childrenLength[propName]);
|
|
691
|
-
key && defineKeyPropWarningGetter(i, typeof type === "function" ? type.displayName || type.name || "Unknown" : type);
|
|
692
|
-
var propName = 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
|
|
693
|
-
return ReactElement(type, key, i, getOwner(), propName ? Error("react-stack-top-frame") : unknownOwnerDebugStack, propName ? createTask(getTaskName(type)) : unknownOwnerDebugTask);
|
|
694
|
-
};
|
|
695
|
-
exports.createRef = function() {
|
|
696
|
-
var refObject = { current: null };
|
|
697
|
-
Object.seal(refObject);
|
|
698
|
-
return refObject;
|
|
699
|
-
};
|
|
700
|
-
exports.forwardRef = function(render) {
|
|
701
|
-
render != null && render.$$typeof === REACT_MEMO_TYPE ? console.error("forwardRef requires a render function but received a `memo` component. Instead of forwardRef(memo(...)), use memo(forwardRef(...)).") : typeof render !== "function" ? console.error("forwardRef requires a render function but was given %s.", render === null ? "null" : typeof render) : render.length !== 0 && render.length !== 2 && console.error("forwardRef render functions accept exactly two parameters: props and ref. %s", render.length === 1 ? "Did you forget to use the ref parameter?" : "Any additional parameter will be undefined.");
|
|
702
|
-
render != null && render.defaultProps != null && console.error("forwardRef render functions do not support defaultProps. Did you accidentally pass a React component?");
|
|
703
|
-
var elementType = { $$typeof: REACT_FORWARD_REF_TYPE, render }, ownName;
|
|
704
|
-
Object.defineProperty(elementType, "displayName", {
|
|
705
|
-
enumerable: false,
|
|
706
|
-
configurable: true,
|
|
707
|
-
get: function() {
|
|
708
|
-
return ownName;
|
|
709
|
-
},
|
|
710
|
-
set: function(name) {
|
|
711
|
-
ownName = name;
|
|
712
|
-
render.name || render.displayName || (Object.defineProperty(render, "name", { value: name }), render.displayName = name);
|
|
1212
|
+
result._emitter.addText(code);
|
|
1213
|
+
return result;
|
|
1214
|
+
}
|
|
1215
|
+
function highlightAuto(code, languageSubset) {
|
|
1216
|
+
languageSubset = languageSubset || options.languages || Object.keys(languages);
|
|
1217
|
+
const plaintext = justTextHighlightResult(code);
|
|
1218
|
+
const results = languageSubset.filter(getLanguage).filter(autoDetection).map((name) => _highlight(name, code, false));
|
|
1219
|
+
results.unshift(plaintext);
|
|
1220
|
+
const sorted = results.sort((a, b) => {
|
|
1221
|
+
if (a.relevance !== b.relevance)
|
|
1222
|
+
return b.relevance - a.relevance;
|
|
1223
|
+
if (a.language && b.language) {
|
|
1224
|
+
if (getLanguage(a.language).supersetOf === b.language) {
|
|
1225
|
+
return 1;
|
|
1226
|
+
} else if (getLanguage(b.language).supersetOf === a.language) {
|
|
1227
|
+
return -1;
|
|
1228
|
+
}
|
|
713
1229
|
}
|
|
1230
|
+
return 0;
|
|
714
1231
|
});
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
1232
|
+
const [best, secondBest] = sorted;
|
|
1233
|
+
const result = best;
|
|
1234
|
+
result.secondBest = secondBest;
|
|
1235
|
+
return result;
|
|
1236
|
+
}
|
|
1237
|
+
function updateClassName(element, currentLang, resultLang) {
|
|
1238
|
+
const language = currentLang && aliases[currentLang] || resultLang;
|
|
1239
|
+
element.classList.add("hljs");
|
|
1240
|
+
element.classList.add(`language-${language}`);
|
|
1241
|
+
}
|
|
1242
|
+
function highlightElement(element) {
|
|
1243
|
+
let node = null;
|
|
1244
|
+
const language = blockLanguage(element);
|
|
1245
|
+
if (shouldNotHighlight(language))
|
|
1246
|
+
return;
|
|
1247
|
+
fire("before:highlightElement", { el: element, language });
|
|
1248
|
+
if (element.dataset.highlighted) {
|
|
1249
|
+
console.log("Element previously highlighted. To highlight again, first unset `dataset.highlighted`.", element);
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
if (element.children.length > 0) {
|
|
1253
|
+
if (!options.ignoreUnescapedHTML) {
|
|
1254
|
+
console.warn("One of your code blocks includes unescaped HTML. This is a potentially serious security risk.");
|
|
1255
|
+
console.warn("https://github.com/highlightjs/highlight.js/wiki/security");
|
|
1256
|
+
console.warn("The element with unescaped HTML:");
|
|
1257
|
+
console.warn(element);
|
|
1258
|
+
}
|
|
1259
|
+
if (options.throwUnescapedHTML) {
|
|
1260
|
+
const err = new HTMLInjectionError("One of your code blocks includes unescaped HTML.", element.innerHTML);
|
|
1261
|
+
throw err;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
node = element;
|
|
1265
|
+
const text = node.textContent;
|
|
1266
|
+
const result = language ? highlight2(text, { language, ignoreIllegals: true }) : highlightAuto(text);
|
|
1267
|
+
element.innerHTML = result.value;
|
|
1268
|
+
element.dataset.highlighted = "yes";
|
|
1269
|
+
updateClassName(element, language, result.language);
|
|
1270
|
+
element.result = {
|
|
1271
|
+
language: result.language,
|
|
1272
|
+
re: result.relevance,
|
|
1273
|
+
relevance: result.relevance
|
|
732
1274
|
};
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
1275
|
+
if (result.secondBest) {
|
|
1276
|
+
element.secondBest = {
|
|
1277
|
+
language: result.secondBest.language,
|
|
1278
|
+
relevance: result.secondBest.relevance
|
|
1279
|
+
};
|
|
1280
|
+
}
|
|
1281
|
+
fire("after:highlightElement", { el: element, result, text });
|
|
1282
|
+
}
|
|
1283
|
+
function configure(userOptions) {
|
|
1284
|
+
options = inherit(options, userOptions);
|
|
1285
|
+
}
|
|
1286
|
+
const initHighlighting = () => {
|
|
1287
|
+
highlightAll();
|
|
1288
|
+
deprecated("10.6.0", "initHighlighting() deprecated. Use highlightAll() now.");
|
|
736
1289
|
};
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
return ownName;
|
|
750
|
-
},
|
|
751
|
-
set: function(name) {
|
|
752
|
-
ownName = name;
|
|
753
|
-
type.name || type.displayName || (Object.defineProperty(type, "name", { value: name }), type.displayName = name);
|
|
1290
|
+
function initHighlightingOnLoad() {
|
|
1291
|
+
highlightAll();
|
|
1292
|
+
deprecated("10.6.0", "initHighlightingOnLoad() deprecated. Use highlightAll() now.");
|
|
1293
|
+
}
|
|
1294
|
+
let wantsHighlight = false;
|
|
1295
|
+
function highlightAll() {
|
|
1296
|
+
function boot() {
|
|
1297
|
+
highlightAll();
|
|
1298
|
+
}
|
|
1299
|
+
if (document.readyState === "loading") {
|
|
1300
|
+
if (!wantsHighlight) {
|
|
1301
|
+
window.addEventListener("DOMContentLoaded", boot, false);
|
|
754
1302
|
}
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
1303
|
+
wantsHighlight = true;
|
|
1304
|
+
return;
|
|
1305
|
+
}
|
|
1306
|
+
const blocks = document.querySelectorAll(options.cssSelector);
|
|
1307
|
+
blocks.forEach(highlightElement);
|
|
1308
|
+
}
|
|
1309
|
+
function registerLanguage(languageName, languageDefinition) {
|
|
1310
|
+
let lang = null;
|
|
762
1311
|
try {
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
1312
|
+
lang = languageDefinition(hljs);
|
|
1313
|
+
} catch (error$1) {
|
|
1314
|
+
error("Language definition for '{}' could not be registered.".replace("{}", languageName));
|
|
1315
|
+
if (!SAFE_MODE) {
|
|
1316
|
+
throw error$1;
|
|
1317
|
+
} else {
|
|
1318
|
+
error(error$1);
|
|
1319
|
+
}
|
|
1320
|
+
lang = PLAINTEXT_LANGUAGE;
|
|
770
1321
|
}
|
|
1322
|
+
if (!lang.name)
|
|
1323
|
+
lang.name = languageName;
|
|
1324
|
+
languages[languageName] = lang;
|
|
1325
|
+
lang.rawDefinition = languageDefinition.bind(null, hljs);
|
|
1326
|
+
if (lang.aliases) {
|
|
1327
|
+
registerAliases(lang.aliases, { languageName });
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
function unregisterLanguage(languageName) {
|
|
1331
|
+
delete languages[languageName];
|
|
1332
|
+
for (const alias of Object.keys(aliases)) {
|
|
1333
|
+
if (aliases[alias] === languageName) {
|
|
1334
|
+
delete aliases[alias];
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
function listLanguages() {
|
|
1339
|
+
return Object.keys(languages);
|
|
1340
|
+
}
|
|
1341
|
+
function getLanguage(name) {
|
|
1342
|
+
name = (name || "").toLowerCase();
|
|
1343
|
+
return languages[name] || languages[aliases[name]];
|
|
1344
|
+
}
|
|
1345
|
+
function registerAliases(aliasList, { languageName }) {
|
|
1346
|
+
if (typeof aliasList === "string") {
|
|
1347
|
+
aliasList = [aliasList];
|
|
1348
|
+
}
|
|
1349
|
+
aliasList.forEach((alias) => {
|
|
1350
|
+
aliases[alias.toLowerCase()] = languageName;
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
function autoDetection(name) {
|
|
1354
|
+
const lang = getLanguage(name);
|
|
1355
|
+
return lang && !lang.disableAutodetect;
|
|
1356
|
+
}
|
|
1357
|
+
function upgradePluginAPI(plugin) {
|
|
1358
|
+
if (plugin["before:highlightBlock"] && !plugin["before:highlightElement"]) {
|
|
1359
|
+
plugin["before:highlightElement"] = (data) => {
|
|
1360
|
+
plugin["before:highlightBlock"](Object.assign({ block: data.el }, data));
|
|
1361
|
+
};
|
|
1362
|
+
}
|
|
1363
|
+
if (plugin["after:highlightBlock"] && !plugin["after:highlightElement"]) {
|
|
1364
|
+
plugin["after:highlightElement"] = (data) => {
|
|
1365
|
+
plugin["after:highlightBlock"](Object.assign({ block: data.el }, data));
|
|
1366
|
+
};
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
function addPlugin(plugin) {
|
|
1370
|
+
upgradePluginAPI(plugin);
|
|
1371
|
+
plugins.push(plugin);
|
|
1372
|
+
}
|
|
1373
|
+
function removePlugin(plugin) {
|
|
1374
|
+
const index = plugins.indexOf(plugin);
|
|
1375
|
+
if (index !== -1) {
|
|
1376
|
+
plugins.splice(index, 1);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
function fire(event, args) {
|
|
1380
|
+
const cb = event;
|
|
1381
|
+
plugins.forEach(function(plugin) {
|
|
1382
|
+
if (plugin[cb]) {
|
|
1383
|
+
plugin[cb](args);
|
|
1384
|
+
}
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
function deprecateHighlightBlock(el) {
|
|
1388
|
+
deprecated("10.7.0", "highlightBlock will be removed entirely in v12.0");
|
|
1389
|
+
deprecated("10.7.0", "Please use highlightElement now.");
|
|
1390
|
+
return highlightElement(el);
|
|
1391
|
+
}
|
|
1392
|
+
Object.assign(hljs, {
|
|
1393
|
+
highlight: highlight2,
|
|
1394
|
+
highlightAuto,
|
|
1395
|
+
highlightAll,
|
|
1396
|
+
highlightElement,
|
|
1397
|
+
highlightBlock: deprecateHighlightBlock,
|
|
1398
|
+
configure,
|
|
1399
|
+
initHighlighting,
|
|
1400
|
+
initHighlightingOnLoad,
|
|
1401
|
+
registerLanguage,
|
|
1402
|
+
unregisterLanguage,
|
|
1403
|
+
listLanguages,
|
|
1404
|
+
getLanguage,
|
|
1405
|
+
registerAliases,
|
|
1406
|
+
autoDetection,
|
|
1407
|
+
inherit,
|
|
1408
|
+
addPlugin,
|
|
1409
|
+
removePlugin
|
|
1410
|
+
});
|
|
1411
|
+
hljs.debugMode = function() {
|
|
1412
|
+
SAFE_MODE = false;
|
|
771
1413
|
};
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
};
|
|
775
|
-
exports.use = function(usable) {
|
|
776
|
-
return resolveDispatcher().use(usable);
|
|
777
|
-
};
|
|
778
|
-
exports.useActionState = function(action, initialState, permalink) {
|
|
779
|
-
return resolveDispatcher().useActionState(action, initialState, permalink);
|
|
780
|
-
};
|
|
781
|
-
exports.useCallback = function(callback, deps) {
|
|
782
|
-
return resolveDispatcher().useCallback(callback, deps);
|
|
783
|
-
};
|
|
784
|
-
exports.useContext = function(Context) {
|
|
785
|
-
var dispatcher = resolveDispatcher();
|
|
786
|
-
Context.$$typeof === REACT_CONSUMER_TYPE && console.error("Calling useContext(Context.Consumer) is not supported and will cause bugs. Did you mean to call useContext(Context) instead?");
|
|
787
|
-
return dispatcher.useContext(Context);
|
|
788
|
-
};
|
|
789
|
-
exports.useDebugValue = function(value, formatterFn) {
|
|
790
|
-
return resolveDispatcher().useDebugValue(value, formatterFn);
|
|
791
|
-
};
|
|
792
|
-
exports.useDeferredValue = function(value, initialValue) {
|
|
793
|
-
return resolveDispatcher().useDeferredValue(value, initialValue);
|
|
794
|
-
};
|
|
795
|
-
exports.useEffect = function(create, deps) {
|
|
796
|
-
create == null && console.warn("React Hook useEffect requires an effect callback. Did you forget to pass a callback to the hook?");
|
|
797
|
-
return resolveDispatcher().useEffect(create, deps);
|
|
798
|
-
};
|
|
799
|
-
exports.useEffectEvent = function(callback) {
|
|
800
|
-
return resolveDispatcher().useEffectEvent(callback);
|
|
801
|
-
};
|
|
802
|
-
exports.useId = function() {
|
|
803
|
-
return resolveDispatcher().useId();
|
|
804
|
-
};
|
|
805
|
-
exports.useImperativeHandle = function(ref, create, deps) {
|
|
806
|
-
return resolveDispatcher().useImperativeHandle(ref, create, deps);
|
|
807
|
-
};
|
|
808
|
-
exports.useInsertionEffect = function(create, deps) {
|
|
809
|
-
create == null && console.warn("React Hook useInsertionEffect requires an effect callback. Did you forget to pass a callback to the hook?");
|
|
810
|
-
return resolveDispatcher().useInsertionEffect(create, deps);
|
|
811
|
-
};
|
|
812
|
-
exports.useLayoutEffect = function(create, deps) {
|
|
813
|
-
create == null && console.warn("React Hook useLayoutEffect requires an effect callback. Did you forget to pass a callback to the hook?");
|
|
814
|
-
return resolveDispatcher().useLayoutEffect(create, deps);
|
|
815
|
-
};
|
|
816
|
-
exports.useMemo = function(create, deps) {
|
|
817
|
-
return resolveDispatcher().useMemo(create, deps);
|
|
818
|
-
};
|
|
819
|
-
exports.useOptimistic = function(passthrough, reducer) {
|
|
820
|
-
return resolveDispatcher().useOptimistic(passthrough, reducer);
|
|
821
|
-
};
|
|
822
|
-
exports.useReducer = function(reducer, initialArg, init) {
|
|
823
|
-
return resolveDispatcher().useReducer(reducer, initialArg, init);
|
|
824
|
-
};
|
|
825
|
-
exports.useRef = function(initialValue) {
|
|
826
|
-
return resolveDispatcher().useRef(initialValue);
|
|
827
|
-
};
|
|
828
|
-
exports.useState = function(initialState) {
|
|
829
|
-
return resolveDispatcher().useState(initialState);
|
|
830
|
-
};
|
|
831
|
-
exports.useSyncExternalStore = function(subscribe, getSnapshot, getServerSnapshot) {
|
|
832
|
-
return resolveDispatcher().useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
1414
|
+
hljs.safeMode = function() {
|
|
1415
|
+
SAFE_MODE = true;
|
|
833
1416
|
};
|
|
834
|
-
|
|
835
|
-
|
|
1417
|
+
hljs.versionString = version;
|
|
1418
|
+
hljs.regex = {
|
|
1419
|
+
concat,
|
|
1420
|
+
lookahead,
|
|
1421
|
+
either,
|
|
1422
|
+
optional,
|
|
1423
|
+
anyNumberOfTimes
|
|
836
1424
|
};
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
1425
|
+
for (const key in MODES) {
|
|
1426
|
+
if (typeof MODES[key] === "object") {
|
|
1427
|
+
deepFreeze(MODES[key]);
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
Object.assign(hljs, MODES);
|
|
1431
|
+
return hljs;
|
|
1432
|
+
};
|
|
1433
|
+
var highlight = HLJS({});
|
|
1434
|
+
highlight.newInstance = () => HLJS({});
|
|
1435
|
+
module.exports = highlight;
|
|
1436
|
+
highlight.HighlightJS = highlight;
|
|
1437
|
+
highlight.default = highlight;
|
|
848
1438
|
});
|
|
849
1439
|
|
|
850
1440
|
// src/labels.ts
|
|
@@ -1084,6 +1674,9 @@ function shouldShowChatCommandMenu(value, surface, labels) {
|
|
|
1084
1674
|
}
|
|
1085
1675
|
return filterChatCommands(value, surface, labels).length > 0;
|
|
1086
1676
|
}
|
|
1677
|
+
function completionForChatCommand(command) {
|
|
1678
|
+
return `${command.usage} `;
|
|
1679
|
+
}
|
|
1087
1680
|
function listChatCommands(surface, labels) {
|
|
1088
1681
|
const resolved = resolveLabels(labels);
|
|
1089
1682
|
return CHAT_COMMANDS.filter((command) => !surface || command.surfaces.includes(surface)).map(({ name, description }) => ({
|
|
@@ -1138,7 +1731,7 @@ async function runAssistantChatCommand(input, deps) {
|
|
|
1138
1731
|
var REQUEST_CHOICES_TOOL = "request_choices";
|
|
1139
1732
|
var CHOICES_TOOL = {
|
|
1140
1733
|
name: REQUEST_CHOICES_TOOL,
|
|
1141
|
-
description: "
|
|
1734
|
+
description: "Block and wait for the user to pick one action path before you execute. Never use to list, display, summarize, or format information — write that in your text reply instead. Never for opening tabs or navigation. At most once per user request.",
|
|
1142
1735
|
inputSchema: {
|
|
1143
1736
|
type: "object",
|
|
1144
1737
|
properties: {
|
|
@@ -1239,7 +1832,7 @@ function parseChoicesArgs(args) {
|
|
|
1239
1832
|
var REQUEST_CONFIRMATION_TOOL = "request_confirmation";
|
|
1240
1833
|
var CONFIRMATION_TOOL = {
|
|
1241
1834
|
name: REQUEST_CONFIRMATION_TOOL,
|
|
1242
|
-
description: "Ask the user to confirm before
|
|
1835
|
+
description: "Ask the user to confirm ONLY before destructive or irreversible writes (delete, reset, import overwrite, bulk mutations). Never use for navigation, opening tabs, viewing data, or read-only operations. At most once per user request.",
|
|
1243
1836
|
inputSchema: {
|
|
1244
1837
|
type: "object",
|
|
1245
1838
|
properties: {
|
|
@@ -1414,6 +2007,80 @@ async function executeChatInteractiveTool(name, args, callId, signal) {
|
|
|
1414
2007
|
function shouldTerminateTurnAfterTool(name) {
|
|
1415
2008
|
return isPostResponseChatTool(name);
|
|
1416
2009
|
}
|
|
2010
|
+
// src/core/interactive-tools/gate.ts
|
|
2011
|
+
var NAMESPACED_TOOL_PATTERN = /^@[^/]+\/.+/;
|
|
2012
|
+
function createInteractiveAgentGate() {
|
|
2013
|
+
return {
|
|
2014
|
+
confirmationCalls: 0,
|
|
2015
|
+
choicesCalls: 0,
|
|
2016
|
+
registryToolCalls: 0
|
|
2017
|
+
};
|
|
2018
|
+
}
|
|
2019
|
+
function isDisplayChoicesArgs(args) {
|
|
2020
|
+
if (!Array.isArray(args.options) || args.options.length < 2)
|
|
2021
|
+
return false;
|
|
2022
|
+
return args.options.every((entry) => {
|
|
2023
|
+
if (!entry || typeof entry !== "object")
|
|
2024
|
+
return false;
|
|
2025
|
+
const option = entry;
|
|
2026
|
+
const id = String(option.id ?? "").trim();
|
|
2027
|
+
const label = String(option.label ?? "").trim();
|
|
2028
|
+
return NAMESPACED_TOOL_PATTERN.test(id) || NAMESPACED_TOOL_PATTERN.test(label);
|
|
2029
|
+
});
|
|
2030
|
+
}
|
|
2031
|
+
function shouldAutoResolveInteractiveTool(gate, toolName, args) {
|
|
2032
|
+
if (toolName === REQUEST_CHOICES_TOOL && args && isDisplayChoicesArgs(args)) {
|
|
2033
|
+
return true;
|
|
2034
|
+
}
|
|
2035
|
+
if (gate.registryToolCalls > 0)
|
|
2036
|
+
return false;
|
|
2037
|
+
if (toolName === REQUEST_CONFIRMATION_TOOL && gate.confirmationCalls > 0) {
|
|
2038
|
+
return true;
|
|
2039
|
+
}
|
|
2040
|
+
if (toolName === REQUEST_CHOICES_TOOL && gate.choicesCalls > 0) {
|
|
2041
|
+
return true;
|
|
2042
|
+
}
|
|
2043
|
+
return false;
|
|
2044
|
+
}
|
|
2045
|
+
function recordInteractiveToolCall(gate, toolName) {
|
|
2046
|
+
if (toolName === REQUEST_CONFIRMATION_TOOL) {
|
|
2047
|
+
gate.confirmationCalls += 1;
|
|
2048
|
+
return;
|
|
2049
|
+
}
|
|
2050
|
+
if (toolName === REQUEST_CHOICES_TOOL) {
|
|
2051
|
+
gate.choicesCalls += 1;
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
function recordRegistryToolCall(gate) {
|
|
2055
|
+
gate.registryToolCalls += 1;
|
|
2056
|
+
}
|
|
2057
|
+
function shouldInjectActionNudge(gate) {
|
|
2058
|
+
return gate.confirmationCalls + gate.choicesCalls >= 2 && gate.registryToolCalls === 0;
|
|
2059
|
+
}
|
|
2060
|
+
function actionToolNudgeMessage() {
|
|
2061
|
+
return "The user already responded to your prompts. Fulfill their request now " + "with an action tool. Do not call request_confirmation or request_choices again.";
|
|
2062
|
+
}
|
|
2063
|
+
function autoResolvedInteractiveResult(toolName, args) {
|
|
2064
|
+
if (toolName === REQUEST_CHOICES_TOOL && args && isDisplayChoicesArgs(args)) {
|
|
2065
|
+
return JSON.stringify({
|
|
2066
|
+
selected: [],
|
|
2067
|
+
autoResolved: true,
|
|
2068
|
+
message: "Do not present items as a choice menu. Reply in your message with a markdown table or numbered list instead."
|
|
2069
|
+
});
|
|
2070
|
+
}
|
|
2071
|
+
if (toolName === REQUEST_CONFIRMATION_TOOL) {
|
|
2072
|
+
return JSON.stringify({
|
|
2073
|
+
confirmed: true,
|
|
2074
|
+
autoResolved: true,
|
|
2075
|
+
message: "Confirmation was already collected. Call the action tool immediately."
|
|
2076
|
+
});
|
|
2077
|
+
}
|
|
2078
|
+
return JSON.stringify({
|
|
2079
|
+
selected: [],
|
|
2080
|
+
autoResolved: true,
|
|
2081
|
+
message: "A choice was already submitted. Call the action tool immediately."
|
|
2082
|
+
});
|
|
2083
|
+
}
|
|
1417
2084
|
// src/core/chat-history.ts
|
|
1418
2085
|
var DEFAULT_HISTORY_KEY = "assistant-chat-history";
|
|
1419
2086
|
var DEFAULT_MAX_STORED = 100;
|
|
@@ -1486,6 +2153,283 @@ function createChatHistoryHelpers(options) {
|
|
|
1486
2153
|
}
|
|
1487
2154
|
return { getStored, persist, clear, loadInitial };
|
|
1488
2155
|
}
|
|
2156
|
+
// ../../node_modules/.bun/highlight.js@11.11.1/node_modules/highlight.js/es/core.js
|
|
2157
|
+
var import_core = __toESM(require_core(), 1);
|
|
2158
|
+
var core_default = import_core.default;
|
|
2159
|
+
|
|
2160
|
+
// ../../node_modules/.bun/highlight.js@11.11.1/node_modules/highlight.js/es/languages/json.js
|
|
2161
|
+
function json(hljs) {
|
|
2162
|
+
const ATTRIBUTE = {
|
|
2163
|
+
className: "attr",
|
|
2164
|
+
begin: /"(\\.|[^\\"\r\n])*"(?=\s*:)/,
|
|
2165
|
+
relevance: 1.01
|
|
2166
|
+
};
|
|
2167
|
+
const PUNCTUATION = {
|
|
2168
|
+
match: /[{}[\],:]/,
|
|
2169
|
+
className: "punctuation",
|
|
2170
|
+
relevance: 0
|
|
2171
|
+
};
|
|
2172
|
+
const LITERALS = [
|
|
2173
|
+
"true",
|
|
2174
|
+
"false",
|
|
2175
|
+
"null"
|
|
2176
|
+
];
|
|
2177
|
+
const LITERALS_MODE = {
|
|
2178
|
+
scope: "literal",
|
|
2179
|
+
beginKeywords: LITERALS.join(" ")
|
|
2180
|
+
};
|
|
2181
|
+
return {
|
|
2182
|
+
name: "JSON",
|
|
2183
|
+
aliases: ["jsonc"],
|
|
2184
|
+
keywords: {
|
|
2185
|
+
literal: LITERALS
|
|
2186
|
+
},
|
|
2187
|
+
contains: [
|
|
2188
|
+
ATTRIBUTE,
|
|
2189
|
+
PUNCTUATION,
|
|
2190
|
+
hljs.QUOTE_STRING_MODE,
|
|
2191
|
+
LITERALS_MODE,
|
|
2192
|
+
hljs.C_NUMBER_MODE,
|
|
2193
|
+
hljs.C_LINE_COMMENT_MODE,
|
|
2194
|
+
hljs.C_BLOCK_COMMENT_MODE
|
|
2195
|
+
],
|
|
2196
|
+
illegal: "\\S"
|
|
2197
|
+
};
|
|
2198
|
+
}
|
|
2199
|
+
|
|
2200
|
+
// ../../node_modules/.bun/highlight.js@11.11.1/node_modules/highlight.js/es/languages/markdown.js
|
|
2201
|
+
function markdown(hljs) {
|
|
2202
|
+
const regex = hljs.regex;
|
|
2203
|
+
const INLINE_HTML = {
|
|
2204
|
+
begin: /<\/?[A-Za-z_]/,
|
|
2205
|
+
end: ">",
|
|
2206
|
+
subLanguage: "xml",
|
|
2207
|
+
relevance: 0
|
|
2208
|
+
};
|
|
2209
|
+
const HORIZONTAL_RULE = {
|
|
2210
|
+
begin: "^[-\\*]{3,}",
|
|
2211
|
+
end: "$"
|
|
2212
|
+
};
|
|
2213
|
+
const CODE = {
|
|
2214
|
+
className: "code",
|
|
2215
|
+
variants: [
|
|
2216
|
+
{ begin: "(`{3,})[^`](.|\\n)*?\\1`*[ ]*" },
|
|
2217
|
+
{ begin: "(~{3,})[^~](.|\\n)*?\\1~*[ ]*" },
|
|
2218
|
+
{
|
|
2219
|
+
begin: "```",
|
|
2220
|
+
end: "```+[ ]*$"
|
|
2221
|
+
},
|
|
2222
|
+
{
|
|
2223
|
+
begin: "~~~",
|
|
2224
|
+
end: "~~~+[ ]*$"
|
|
2225
|
+
},
|
|
2226
|
+
{ begin: "`.+?`" },
|
|
2227
|
+
{
|
|
2228
|
+
begin: "(?=^( {4}|\\t))",
|
|
2229
|
+
contains: [
|
|
2230
|
+
{
|
|
2231
|
+
begin: "^( {4}|\\t)",
|
|
2232
|
+
end: "(\\n)$"
|
|
2233
|
+
}
|
|
2234
|
+
],
|
|
2235
|
+
relevance: 0
|
|
2236
|
+
}
|
|
2237
|
+
]
|
|
2238
|
+
};
|
|
2239
|
+
const LIST = {
|
|
2240
|
+
className: "bullet",
|
|
2241
|
+
begin: "^[ \t]*([*+-]|(\\d+\\.))(?=\\s+)",
|
|
2242
|
+
end: "\\s+",
|
|
2243
|
+
excludeEnd: true
|
|
2244
|
+
};
|
|
2245
|
+
const LINK_REFERENCE = {
|
|
2246
|
+
begin: /^\[[^\n]+\]:/,
|
|
2247
|
+
returnBegin: true,
|
|
2248
|
+
contains: [
|
|
2249
|
+
{
|
|
2250
|
+
className: "symbol",
|
|
2251
|
+
begin: /\[/,
|
|
2252
|
+
end: /\]/,
|
|
2253
|
+
excludeBegin: true,
|
|
2254
|
+
excludeEnd: true
|
|
2255
|
+
},
|
|
2256
|
+
{
|
|
2257
|
+
className: "link",
|
|
2258
|
+
begin: /:\s*/,
|
|
2259
|
+
end: /$/,
|
|
2260
|
+
excludeBegin: true
|
|
2261
|
+
}
|
|
2262
|
+
]
|
|
2263
|
+
};
|
|
2264
|
+
const URL_SCHEME = /[A-Za-z][A-Za-z0-9+.-]*/;
|
|
2265
|
+
const LINK = {
|
|
2266
|
+
variants: [
|
|
2267
|
+
{
|
|
2268
|
+
begin: /\[.+?\]\[.*?\]/,
|
|
2269
|
+
relevance: 0
|
|
2270
|
+
},
|
|
2271
|
+
{
|
|
2272
|
+
begin: /\[.+?\]\(((data|javascript|mailto):|(?:http|ftp)s?:\/\/).*?\)/,
|
|
2273
|
+
relevance: 2
|
|
2274
|
+
},
|
|
2275
|
+
{
|
|
2276
|
+
begin: regex.concat(/\[.+?\]\(/, URL_SCHEME, /:\/\/.*?\)/),
|
|
2277
|
+
relevance: 2
|
|
2278
|
+
},
|
|
2279
|
+
{
|
|
2280
|
+
begin: /\[.+?\]\([./?&#].*?\)/,
|
|
2281
|
+
relevance: 1
|
|
2282
|
+
},
|
|
2283
|
+
{
|
|
2284
|
+
begin: /\[.*?\]\(.*?\)/,
|
|
2285
|
+
relevance: 0
|
|
2286
|
+
}
|
|
2287
|
+
],
|
|
2288
|
+
returnBegin: true,
|
|
2289
|
+
contains: [
|
|
2290
|
+
{
|
|
2291
|
+
match: /\[(?=\])/
|
|
2292
|
+
},
|
|
2293
|
+
{
|
|
2294
|
+
className: "string",
|
|
2295
|
+
relevance: 0,
|
|
2296
|
+
begin: "\\[",
|
|
2297
|
+
end: "\\]",
|
|
2298
|
+
excludeBegin: true,
|
|
2299
|
+
returnEnd: true
|
|
2300
|
+
},
|
|
2301
|
+
{
|
|
2302
|
+
className: "link",
|
|
2303
|
+
relevance: 0,
|
|
2304
|
+
begin: "\\]\\(",
|
|
2305
|
+
end: "\\)",
|
|
2306
|
+
excludeBegin: true,
|
|
2307
|
+
excludeEnd: true
|
|
2308
|
+
},
|
|
2309
|
+
{
|
|
2310
|
+
className: "symbol",
|
|
2311
|
+
relevance: 0,
|
|
2312
|
+
begin: "\\]\\[",
|
|
2313
|
+
end: "\\]",
|
|
2314
|
+
excludeBegin: true,
|
|
2315
|
+
excludeEnd: true
|
|
2316
|
+
}
|
|
2317
|
+
]
|
|
2318
|
+
};
|
|
2319
|
+
const BOLD = {
|
|
2320
|
+
className: "strong",
|
|
2321
|
+
contains: [],
|
|
2322
|
+
variants: [
|
|
2323
|
+
{
|
|
2324
|
+
begin: /_{2}(?!\s)/,
|
|
2325
|
+
end: /_{2}/
|
|
2326
|
+
},
|
|
2327
|
+
{
|
|
2328
|
+
begin: /\*{2}(?!\s)/,
|
|
2329
|
+
end: /\*{2}/
|
|
2330
|
+
}
|
|
2331
|
+
]
|
|
2332
|
+
};
|
|
2333
|
+
const ITALIC = {
|
|
2334
|
+
className: "emphasis",
|
|
2335
|
+
contains: [],
|
|
2336
|
+
variants: [
|
|
2337
|
+
{
|
|
2338
|
+
begin: /\*(?![*\s])/,
|
|
2339
|
+
end: /\*/
|
|
2340
|
+
},
|
|
2341
|
+
{
|
|
2342
|
+
begin: /_(?![_\s])/,
|
|
2343
|
+
end: /_/,
|
|
2344
|
+
relevance: 0
|
|
2345
|
+
}
|
|
2346
|
+
]
|
|
2347
|
+
};
|
|
2348
|
+
const BOLD_WITHOUT_ITALIC = hljs.inherit(BOLD, { contains: [] });
|
|
2349
|
+
const ITALIC_WITHOUT_BOLD = hljs.inherit(ITALIC, { contains: [] });
|
|
2350
|
+
BOLD.contains.push(ITALIC_WITHOUT_BOLD);
|
|
2351
|
+
ITALIC.contains.push(BOLD_WITHOUT_ITALIC);
|
|
2352
|
+
let CONTAINABLE = [
|
|
2353
|
+
INLINE_HTML,
|
|
2354
|
+
LINK
|
|
2355
|
+
];
|
|
2356
|
+
[
|
|
2357
|
+
BOLD,
|
|
2358
|
+
ITALIC,
|
|
2359
|
+
BOLD_WITHOUT_ITALIC,
|
|
2360
|
+
ITALIC_WITHOUT_BOLD
|
|
2361
|
+
].forEach((m) => {
|
|
2362
|
+
m.contains = m.contains.concat(CONTAINABLE);
|
|
2363
|
+
});
|
|
2364
|
+
CONTAINABLE = CONTAINABLE.concat(BOLD, ITALIC);
|
|
2365
|
+
const HEADER = {
|
|
2366
|
+
className: "section",
|
|
2367
|
+
variants: [
|
|
2368
|
+
{
|
|
2369
|
+
begin: "^#{1,6}",
|
|
2370
|
+
end: "$",
|
|
2371
|
+
contains: CONTAINABLE
|
|
2372
|
+
},
|
|
2373
|
+
{
|
|
2374
|
+
begin: "(?=^.+?\\n[=-]{2,}$)",
|
|
2375
|
+
contains: [
|
|
2376
|
+
{ begin: "^[=-]*$" },
|
|
2377
|
+
{
|
|
2378
|
+
begin: "^",
|
|
2379
|
+
end: "\\n",
|
|
2380
|
+
contains: CONTAINABLE
|
|
2381
|
+
}
|
|
2382
|
+
]
|
|
2383
|
+
}
|
|
2384
|
+
]
|
|
2385
|
+
};
|
|
2386
|
+
const BLOCKQUOTE = {
|
|
2387
|
+
className: "quote",
|
|
2388
|
+
begin: "^>\\s+",
|
|
2389
|
+
contains: CONTAINABLE,
|
|
2390
|
+
end: "$"
|
|
2391
|
+
};
|
|
2392
|
+
const ENTITY = {
|
|
2393
|
+
scope: "literal",
|
|
2394
|
+
match: /&([a-zA-Z0-9]+|#[0-9]{1,7}|#[Xx][0-9a-fA-F]{1,6});/
|
|
2395
|
+
};
|
|
2396
|
+
return {
|
|
2397
|
+
name: "Markdown",
|
|
2398
|
+
aliases: [
|
|
2399
|
+
"md",
|
|
2400
|
+
"mkdown",
|
|
2401
|
+
"mkd"
|
|
2402
|
+
],
|
|
2403
|
+
contains: [
|
|
2404
|
+
HEADER,
|
|
2405
|
+
INLINE_HTML,
|
|
2406
|
+
LIST,
|
|
2407
|
+
BOLD,
|
|
2408
|
+
ITALIC,
|
|
2409
|
+
BLOCKQUOTE,
|
|
2410
|
+
CODE,
|
|
2411
|
+
HORIZONTAL_RULE,
|
|
2412
|
+
LINK,
|
|
2413
|
+
LINK_REFERENCE,
|
|
2414
|
+
ENTITY
|
|
2415
|
+
]
|
|
2416
|
+
};
|
|
2417
|
+
}
|
|
2418
|
+
|
|
2419
|
+
// src/core/code-highlight.ts
|
|
2420
|
+
core_default.registerLanguage("json", json);
|
|
2421
|
+
core_default.registerLanguage("markdown", markdown);
|
|
2422
|
+
function normalizeCodeLineEndings(code) {
|
|
2423
|
+
return code.replace(/\r\n?/g, `
|
|
2424
|
+
`);
|
|
2425
|
+
}
|
|
2426
|
+
function highlightCode(code, language) {
|
|
2427
|
+
const source = normalizeCodeLineEndings(code);
|
|
2428
|
+
if (language && core_default.getLanguage(language)) {
|
|
2429
|
+
return core_default.highlight(source, { language, ignoreIllegals: true }).value;
|
|
2430
|
+
}
|
|
2431
|
+
return core_default.highlightAuto(source).value;
|
|
2432
|
+
}
|
|
1489
2433
|
// ../../node_modules/.bun/zustand@5.0.14+93dbe784b8baa420/node_modules/zustand/esm/vanilla.mjs
|
|
1490
2434
|
var createStoreImpl = (createState) => {
|
|
1491
2435
|
let state;
|
|
@@ -1511,11 +2455,11 @@ var createStoreImpl = (createState) => {
|
|
|
1511
2455
|
var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
|
|
1512
2456
|
|
|
1513
2457
|
// ../../node_modules/.bun/zustand@5.0.14+93dbe784b8baa420/node_modules/zustand/esm/react.mjs
|
|
1514
|
-
|
|
2458
|
+
import React from "react";
|
|
1515
2459
|
var identity = (arg) => arg;
|
|
1516
2460
|
function useStore(api, selector = identity) {
|
|
1517
|
-
const slice =
|
|
1518
|
-
|
|
2461
|
+
const slice = React.useSyncExternalStore(api.subscribe, React.useCallback(() => selector(api.getState()), [api, selector]), React.useCallback(() => selector(api.getInitialState()), [api, selector]));
|
|
2462
|
+
React.useDebugValue(slice);
|
|
1519
2463
|
return slice;
|
|
1520
2464
|
}
|
|
1521
2465
|
var createImpl = (createState) => {
|
|
@@ -1654,7 +2598,20 @@ var DISABLED_SETTINGS = {
|
|
|
1654
2598
|
apiKey: null,
|
|
1655
2599
|
model: DEFAULT_LLM_MODEL
|
|
1656
2600
|
};
|
|
2601
|
+
var GLOBAL_RESOLVER_KEY = Symbol.for("@4djs/assistant/llm-resolver");
|
|
1657
2602
|
var resolveSettings = null;
|
|
2603
|
+
function getGlobalResolver() {
|
|
2604
|
+
return globalThis[GLOBAL_RESOLVER_KEY] ?? null;
|
|
2605
|
+
}
|
|
2606
|
+
function setSharedResolver(resolver) {
|
|
2607
|
+
resolveSettings = resolver;
|
|
2608
|
+
const globalRecord = globalThis;
|
|
2609
|
+
if (resolver) {
|
|
2610
|
+
globalRecord[GLOBAL_RESOLVER_KEY] = resolver;
|
|
2611
|
+
} else {
|
|
2612
|
+
delete globalRecord[GLOBAL_RESOLVER_KEY];
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
1658
2615
|
function normalizeSettings(input) {
|
|
1659
2616
|
return {
|
|
1660
2617
|
enabled: input.enabled,
|
|
@@ -1667,19 +2624,20 @@ function normalizeSettings(input) {
|
|
|
1667
2624
|
}
|
|
1668
2625
|
function configureAssistantLlm(config) {
|
|
1669
2626
|
if (typeof config === "function") {
|
|
1670
|
-
|
|
2627
|
+
setSharedResolver(async () => normalizeSettings(await config()));
|
|
1671
2628
|
return;
|
|
1672
2629
|
}
|
|
1673
2630
|
const settings = normalizeSettings(config);
|
|
1674
|
-
|
|
2631
|
+
setSharedResolver(async () => settings);
|
|
1675
2632
|
}
|
|
1676
2633
|
async function resolveAssistantLlmSettings() {
|
|
1677
|
-
|
|
2634
|
+
const resolver = resolveSettings ?? getGlobalResolver();
|
|
2635
|
+
if (!resolver)
|
|
1678
2636
|
return DISABLED_SETTINGS;
|
|
1679
|
-
return
|
|
2637
|
+
return resolver();
|
|
1680
2638
|
}
|
|
1681
2639
|
function resetAssistantLlm() {
|
|
1682
|
-
|
|
2640
|
+
setSharedResolver(null);
|
|
1683
2641
|
}
|
|
1684
2642
|
async function testLlmConnection(settings) {
|
|
1685
2643
|
if (!settings.apiKey?.trim() && !isLocalLlmBaseUrl(settings.baseUrl)) {
|
|
@@ -1757,15 +2715,15 @@ function createStreamParser() {
|
|
|
1757
2715
|
done: true
|
|
1758
2716
|
};
|
|
1759
2717
|
}
|
|
1760
|
-
let
|
|
2718
|
+
let json2;
|
|
1761
2719
|
try {
|
|
1762
|
-
|
|
2720
|
+
json2 = JSON.parse(data);
|
|
1763
2721
|
} catch {
|
|
1764
2722
|
return null;
|
|
1765
2723
|
}
|
|
1766
|
-
if (typeof
|
|
1767
|
-
model =
|
|
1768
|
-
const choice =
|
|
2724
|
+
if (typeof json2.model === "string")
|
|
2725
|
+
model = json2.model;
|
|
2726
|
+
const choice = json2.choices?.[0];
|
|
1769
2727
|
const delta = choice?.delta;
|
|
1770
2728
|
if (!delta)
|
|
1771
2729
|
return null;
|
|
@@ -1857,6 +2815,48 @@ async function readSseStream(body, onChunk, signal) {
|
|
|
1857
2815
|
return { ...last, done: true };
|
|
1858
2816
|
}
|
|
1859
2817
|
|
|
2818
|
+
// src/core/system-prompt.ts
|
|
2819
|
+
function buildSystemPromptWithTools(basePrompt, tools) {
|
|
2820
|
+
const trimmedBase = basePrompt.trim();
|
|
2821
|
+
if (tools.length === 0) {
|
|
2822
|
+
return `${trimmedBase}
|
|
2823
|
+
|
|
2824
|
+
## Currently enabled tools
|
|
2825
|
+
|
|
2826
|
+
No @namespace action tools are enabled. You cannot call datastore or UI action tools until the user enables them in Settings → AI Assistant Tools.
|
|
2827
|
+
|
|
2828
|
+
When the user asks what tools are available, say none are enabled and point them to settings. Do not invent or list disabled tool names.`;
|
|
2829
|
+
}
|
|
2830
|
+
const toolLines = tools.map((tool, index) => `${index + 1}. \`${tool.name}\` — ${tool.description}`);
|
|
2831
|
+
return `${trimmedBase}
|
|
2832
|
+
|
|
2833
|
+
## Currently enabled tools
|
|
2834
|
+
|
|
2835
|
+
Only the tools below are available in this session. When listing tools, include **only** these entries — never mention disabled or hypothetical tools.
|
|
2836
|
+
|
|
2837
|
+
${toolLines.join(`
|
|
2838
|
+
`)}`;
|
|
2839
|
+
}
|
|
2840
|
+
|
|
2841
|
+
// src/core/tool-names.ts
|
|
2842
|
+
var LLM_TOOL_NAME_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
2843
|
+
function toLlmToolName(name) {
|
|
2844
|
+
if (LLM_TOOL_NAME_PATTERN.test(name))
|
|
2845
|
+
return name;
|
|
2846
|
+
if (name.startsWith("@")) {
|
|
2847
|
+
return name.slice(1).replace(/\//g, "__");
|
|
2848
|
+
}
|
|
2849
|
+
return name.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
2850
|
+
}
|
|
2851
|
+
function fromLlmToolName(llmName, registryNames) {
|
|
2852
|
+
if (registryNames.includes(llmName))
|
|
2853
|
+
return llmName;
|
|
2854
|
+
const decoded = `@${llmName.replace(/__/g, "/")}`;
|
|
2855
|
+
if (registryNames.includes(decoded))
|
|
2856
|
+
return decoded;
|
|
2857
|
+
return llmName;
|
|
2858
|
+
}
|
|
2859
|
+
|
|
1860
2860
|
// src/core/llm-chat.ts
|
|
1861
2861
|
var MAX_AGENT_STEPS = 8;
|
|
1862
2862
|
var DEFAULT_SYSTEM_PROMPT = "You are a helpful assistant with access to tools. Use tools when they help answer the user.";
|
|
@@ -1979,12 +2979,16 @@ async function runLlmAgent(input) {
|
|
|
1979
2979
|
{ role: "user", content: input.userMessage }
|
|
1980
2980
|
];
|
|
1981
2981
|
let lastToolResult;
|
|
2982
|
+
const registryToolNames = input.tools.map((tool) => tool.name);
|
|
2983
|
+
const interactiveGate = createInteractiveAgentGate();
|
|
1982
2984
|
const clientTools = [
|
|
1983
2985
|
...input.tools.map(toClientTool),
|
|
1984
2986
|
...getChatInteractiveTools()
|
|
1985
2987
|
];
|
|
1986
2988
|
let finalContent = "";
|
|
1987
2989
|
let endedWithPostResponseTool = false;
|
|
2990
|
+
const settings = await resolveAssistantLlmSettings();
|
|
2991
|
+
const systemPrompt = buildSystemPromptWithTools(settings.systemPrompt ?? DEFAULT_SYSTEM_PROMPT, input.tools);
|
|
1988
2992
|
for (let step = 0;step < MAX_AGENT_STEPS; step++) {
|
|
1989
2993
|
if (input.signal?.aborted) {
|
|
1990
2994
|
throw new ChatAbortedError;
|
|
@@ -1993,6 +2997,7 @@ async function runLlmAgent(input) {
|
|
|
1993
2997
|
messages: apiMessages,
|
|
1994
2998
|
tools: clientTools,
|
|
1995
2999
|
model: input.model,
|
|
3000
|
+
systemPrompt,
|
|
1996
3001
|
signal: input.signal,
|
|
1997
3002
|
stream: input.stream ? {
|
|
1998
3003
|
turnId: input.stream.turnId,
|
|
@@ -2019,10 +3024,11 @@ async function runLlmAgent(input) {
|
|
|
2019
3024
|
let terminatesTurn = false;
|
|
2020
3025
|
for (const call of completion.toolCalls) {
|
|
2021
3026
|
const args = parseToolArguments(call.function.arguments);
|
|
3027
|
+
const toolName = fromLlmToolName(call.function.name, registryToolNames);
|
|
2022
3028
|
const stepId = crypto.randomUUID();
|
|
2023
3029
|
input.toolHandlers?.onStart({
|
|
2024
3030
|
id: stepId,
|
|
2025
|
-
name:
|
|
3031
|
+
name: toolName,
|
|
2026
3032
|
args,
|
|
2027
3033
|
callId: call.id
|
|
2028
3034
|
});
|
|
@@ -2030,15 +3036,24 @@ async function runLlmAgent(input) {
|
|
|
2030
3036
|
let finishUpdate;
|
|
2031
3037
|
if (isChatUiTool(call.function.name)) {
|
|
2032
3038
|
try {
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
3039
|
+
if (shouldAutoResolveInteractiveTool(interactiveGate, call.function.name, args)) {
|
|
3040
|
+
toolContent = autoResolvedInteractiveResult(call.function.name, args);
|
|
3041
|
+
finishUpdate = {
|
|
3042
|
+
status: "done",
|
|
3043
|
+
result: JSON.parse(toolContent)
|
|
3044
|
+
};
|
|
3045
|
+
} else {
|
|
3046
|
+
recordInteractiveToolCall(interactiveGate, call.function.name);
|
|
3047
|
+
const interactiveResult = await executeChatInteractiveTool(call.function.name, args, call.id, input.signal);
|
|
3048
|
+
toolContent = interactiveResult.content;
|
|
3049
|
+
finishUpdate = {
|
|
3050
|
+
status: interactiveResult.isError ? "error" : "done",
|
|
3051
|
+
result: JSON.parse(interactiveResult.content)
|
|
3052
|
+
};
|
|
3053
|
+
if (interactiveResult.postResponse) {
|
|
3054
|
+
input.onPostResponseTool?.(interactiveResult.postResponse);
|
|
3055
|
+
terminatesTurn = true;
|
|
3056
|
+
}
|
|
2042
3057
|
}
|
|
2043
3058
|
} catch (error) {
|
|
2044
3059
|
if (input.signal?.aborted || error instanceof DOMException && error.name === "AbortError") {
|
|
@@ -2049,7 +3064,8 @@ async function runLlmAgent(input) {
|
|
|
2049
3064
|
finishUpdate = { status: "error", error: message };
|
|
2050
3065
|
}
|
|
2051
3066
|
} else {
|
|
2052
|
-
|
|
3067
|
+
recordRegistryToolCall(interactiveGate);
|
|
3068
|
+
const result = await input.invokeTool(toolName, args);
|
|
2053
3069
|
lastToolResult = result;
|
|
2054
3070
|
toolContent = formatToolResult(result);
|
|
2055
3071
|
finishUpdate = {
|
|
@@ -2074,12 +3090,19 @@ async function runLlmAgent(input) {
|
|
|
2074
3090
|
endedWithPostResponseTool = true;
|
|
2075
3091
|
break;
|
|
2076
3092
|
}
|
|
3093
|
+
if (shouldInjectActionNudge(interactiveGate)) {
|
|
3094
|
+
apiMessages.push({
|
|
3095
|
+
role: "system",
|
|
3096
|
+
content: actionToolNudgeMessage()
|
|
3097
|
+
});
|
|
3098
|
+
}
|
|
2077
3099
|
}
|
|
2078
3100
|
if (!endedWithPostResponseTool && apiMessages.at(-1)?.role === "tool") {
|
|
2079
3101
|
const completion = await requestLlmCompletion({
|
|
2080
3102
|
messages: apiMessages,
|
|
2081
3103
|
tools: clientTools,
|
|
2082
3104
|
model: input.model,
|
|
3105
|
+
systemPrompt,
|
|
2083
3106
|
signal: input.signal,
|
|
2084
3107
|
stream: input.stream ? {
|
|
2085
3108
|
turnId: input.stream.turnId,
|
|
@@ -2171,7 +3194,7 @@ function buildLlmHistory(messages) {
|
|
|
2171
3194
|
id: `call_${baseId}_${index}`,
|
|
2172
3195
|
type: "function",
|
|
2173
3196
|
function: {
|
|
2174
|
-
name: step.name,
|
|
3197
|
+
name: toLlmToolName(step.name),
|
|
2175
3198
|
arguments: JSON.stringify(step.args)
|
|
2176
3199
|
}
|
|
2177
3200
|
}));
|
|
@@ -2199,7 +3222,7 @@ function buildLlmHistory(messages) {
|
|
|
2199
3222
|
id,
|
|
2200
3223
|
type: "function",
|
|
2201
3224
|
function: {
|
|
2202
|
-
name: msg.toolCall.name,
|
|
3225
|
+
name: toLlmToolName(msg.toolCall.name),
|
|
2203
3226
|
arguments: JSON.stringify(msg.toolCall.args)
|
|
2204
3227
|
}
|
|
2205
3228
|
}
|
|
@@ -2262,7 +3285,7 @@ function upstreamError(body, status) {
|
|
|
2262
3285
|
}
|
|
2263
3286
|
function toClientTool(tool) {
|
|
2264
3287
|
return {
|
|
2265
|
-
name: tool.name,
|
|
3288
|
+
name: toLlmToolName(tool.name),
|
|
2266
3289
|
description: tool.description,
|
|
2267
3290
|
inputSchema: tool.inputSchema
|
|
2268
3291
|
};
|
|
@@ -2567,7 +3590,21 @@ function finalizeErroredMessages(messages, errorMessage) {
|
|
|
2567
3590
|
function clearReplySuggestions(messages) {
|
|
2568
3591
|
return messages.map((message) => message.replySuggestions ? { ...message, replySuggestions: undefined } : message);
|
|
2569
3592
|
}
|
|
3593
|
+
function resolveAssistantStoreDependencies(deps) {
|
|
3594
|
+
if (deps.toolRegistry) {
|
|
3595
|
+
return {
|
|
3596
|
+
...deps,
|
|
3597
|
+
listTools: () => deps.toolRegistry.listTools(),
|
|
3598
|
+
invokeTool: (name, args) => deps.toolRegistry.invokeTool(name, args)
|
|
3599
|
+
};
|
|
3600
|
+
}
|
|
3601
|
+
if (!deps.listTools || !deps.invokeTool) {
|
|
3602
|
+
throw new Error("Assistant requires toolRegistry or both listTools and invokeTool");
|
|
3603
|
+
}
|
|
3604
|
+
return deps;
|
|
3605
|
+
}
|
|
2570
3606
|
function createAssistantStore(deps) {
|
|
3607
|
+
const resolvedDeps = resolveAssistantStoreDependencies(deps);
|
|
2571
3608
|
const historyKey = deps.storageKeys?.history ?? "assistant-chat-history";
|
|
2572
3609
|
const llmSettingsKey = deps.storageKeys?.llmSettings ?? "assistant-llm-settings";
|
|
2573
3610
|
const llmSettingsStorage = createLlmSettingsStorage(llmSettingsKey);
|
|
@@ -2601,7 +3638,7 @@ function createAssistantStore(deps) {
|
|
|
2601
3638
|
});
|
|
2602
3639
|
const store = create((set, get) => {
|
|
2603
3640
|
async function runLlmChatTurn(message) {
|
|
2604
|
-
const tools = await
|
|
3641
|
+
const tools = await resolvedDeps.listTools();
|
|
2605
3642
|
const storedMessages = get().messages.filter((m) => m.id !== "welcome");
|
|
2606
3643
|
const priorMessages = storedMessages.at(-1)?.role === "user" ? storedMessages.slice(0, -1) : storedMessages;
|
|
2607
3644
|
const llmHistory = buildLlmHistory(priorMessages);
|
|
@@ -2658,7 +3695,7 @@ function createAssistantStore(deps) {
|
|
|
2658
3695
|
}));
|
|
2659
3696
|
},
|
|
2660
3697
|
invokeTool: async (name, args) => {
|
|
2661
|
-
const result = await
|
|
3698
|
+
const result = await resolvedDeps.invokeTool(name, args);
|
|
2662
3699
|
deps.onToolInvoked?.(result);
|
|
2663
3700
|
return result;
|
|
2664
3701
|
}
|
|
@@ -2941,7 +3978,9 @@ function parseSuggestedPromptsResponse(data) {
|
|
|
2941
3978
|
return prompts.slice(0, 6);
|
|
2942
3979
|
}
|
|
2943
3980
|
// src/core/markdown-utils.ts
|
|
2944
|
-
|
|
3981
|
+
function isReactElement(value) {
|
|
3982
|
+
return typeof value === "object" && value !== null && "props" in value && typeof value.props === "object";
|
|
3983
|
+
}
|
|
2945
3984
|
function childrenToText(children) {
|
|
2946
3985
|
if (typeof children === "string")
|
|
2947
3986
|
return children;
|
|
@@ -2949,13 +3988,125 @@ function childrenToText(children) {
|
|
|
2949
3988
|
return String(children);
|
|
2950
3989
|
if (Array.isArray(children))
|
|
2951
3990
|
return children.map(childrenToText).join("");
|
|
2952
|
-
if (
|
|
3991
|
+
if (isReactElement(children)) {
|
|
2953
3992
|
return childrenToText(children.props.children);
|
|
2954
3993
|
}
|
|
2955
3994
|
return "";
|
|
2956
3995
|
}
|
|
3996
|
+
// src/core/prepare-markdown.ts
|
|
3997
|
+
function prepareMarkdown(message) {
|
|
3998
|
+
let text = convertLatexDisplayMath(message.trimStart());
|
|
3999
|
+
text = convertLatexInlineMath(text);
|
|
4000
|
+
return text.replace(/\n{3,}/g, `
|
|
4001
|
+
|
|
4002
|
+
`).trimEnd();
|
|
4003
|
+
}
|
|
4004
|
+
function convertLatexInlineMath(message) {
|
|
4005
|
+
return message.replace(/\\\(([\s\S]*?)\\\)/g, (_, math) => `$${math.trim()}$`);
|
|
4006
|
+
}
|
|
4007
|
+
function convertLatexDisplayMath(message) {
|
|
4008
|
+
return message.replace(/(^|\n)([ \t]*?)\\\[([\s\S]*?)\\\]/g, (_full, lineStart, indent, rawMath) => {
|
|
4009
|
+
const mathLines = rawMath.split(`
|
|
4010
|
+
`).map((line) => line.trim()).filter((line) => line.length > 0);
|
|
4011
|
+
if (mathLines.length === 0) {
|
|
4012
|
+
return _full;
|
|
4013
|
+
}
|
|
4014
|
+
const pad = indent.length > 0 ? " " : "";
|
|
4015
|
+
const body = mathLines.map((line) => `${pad}${line}`).join(`
|
|
4016
|
+
`);
|
|
4017
|
+
return `${lineStart}${pad}$$
|
|
4018
|
+
${body}
|
|
4019
|
+
${pad}$$`;
|
|
4020
|
+
});
|
|
4021
|
+
}
|
|
4022
|
+
// src/core/tool-registry.ts
|
|
4023
|
+
function toolResultOk(data) {
|
|
4024
|
+
return {
|
|
4025
|
+
content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
|
|
4026
|
+
structuredContent: data
|
|
4027
|
+
};
|
|
4028
|
+
}
|
|
4029
|
+
function toolResultErr(message) {
|
|
4030
|
+
return {
|
|
4031
|
+
content: [{ type: "text", text: message }],
|
|
4032
|
+
isError: true
|
|
4033
|
+
};
|
|
4034
|
+
}
|
|
4035
|
+
|
|
4036
|
+
class AssistantToolRegistryImpl {
|
|
4037
|
+
entries = new Map;
|
|
4038
|
+
register(handler) {
|
|
4039
|
+
const name = handler.definition.name;
|
|
4040
|
+
if (!name.trim()) {
|
|
4041
|
+
throw new Error("Tool definition.name is required");
|
|
4042
|
+
}
|
|
4043
|
+
this.entries.set(name, { handler, active: true });
|
|
4044
|
+
return this;
|
|
4045
|
+
}
|
|
4046
|
+
deactivate(name) {
|
|
4047
|
+
const entry = this.entries.get(name);
|
|
4048
|
+
if (!entry)
|
|
4049
|
+
return false;
|
|
4050
|
+
entry.active = false;
|
|
4051
|
+
return true;
|
|
4052
|
+
}
|
|
4053
|
+
activate(name) {
|
|
4054
|
+
const entry = this.entries.get(name);
|
|
4055
|
+
if (!entry)
|
|
4056
|
+
return false;
|
|
4057
|
+
entry.active = true;
|
|
4058
|
+
return true;
|
|
4059
|
+
}
|
|
4060
|
+
isActive(name) {
|
|
4061
|
+
const entry = this.entries.get(name);
|
|
4062
|
+
return entry?.active ?? false;
|
|
4063
|
+
}
|
|
4064
|
+
has(name) {
|
|
4065
|
+
return this.entries.has(name);
|
|
4066
|
+
}
|
|
4067
|
+
async listTools() {
|
|
4068
|
+
return [...this.entries.values()].filter((entry) => entry.active).map((entry) => entry.handler.definition);
|
|
4069
|
+
}
|
|
4070
|
+
async invokeTool(name, args) {
|
|
4071
|
+
const entry = this.entries.get(name);
|
|
4072
|
+
if (!entry?.active) {
|
|
4073
|
+
return toolResultErr(`Unknown tool: ${name}`);
|
|
4074
|
+
}
|
|
4075
|
+
try {
|
|
4076
|
+
return await entry.handler.invoke(args);
|
|
4077
|
+
} catch (error) {
|
|
4078
|
+
return toolResultErr(error instanceof Error ? error.message : String(error));
|
|
4079
|
+
}
|
|
4080
|
+
}
|
|
4081
|
+
}
|
|
4082
|
+
function createAssistantToolRegistry() {
|
|
4083
|
+
return new AssistantToolRegistryImpl;
|
|
4084
|
+
}
|
|
4085
|
+
function resolveAssistantToolHooks(registry) {
|
|
4086
|
+
return {
|
|
4087
|
+
listTools: () => registry.listTools(),
|
|
4088
|
+
invokeTool: (name, args) => registry.invokeTool(name, args)
|
|
4089
|
+
};
|
|
4090
|
+
}
|
|
4091
|
+
function connectExternalTools(registry, external) {
|
|
4092
|
+
const names = external.listTools().map((definition) => {
|
|
4093
|
+
registry.register({
|
|
4094
|
+
definition,
|
|
4095
|
+
invoke: (args) => external.invokeTool(definition.name, args)
|
|
4096
|
+
});
|
|
4097
|
+
return definition.name;
|
|
4098
|
+
});
|
|
4099
|
+
return () => {
|
|
4100
|
+
for (const name of names) {
|
|
4101
|
+
registry.deactivate(name);
|
|
4102
|
+
}
|
|
4103
|
+
};
|
|
4104
|
+
}
|
|
2957
4105
|
export {
|
|
4106
|
+
toolResultOk,
|
|
4107
|
+
toolResultErr,
|
|
2958
4108
|
toStoredSettings,
|
|
4109
|
+
toLlmToolName,
|
|
2959
4110
|
testLlmConnection,
|
|
2960
4111
|
summarizeActivityResult,
|
|
2961
4112
|
storedToAssistant,
|
|
@@ -2966,11 +4117,14 @@ export {
|
|
|
2966
4117
|
runAssistantChatCommand,
|
|
2967
4118
|
resolveSelectedModel,
|
|
2968
4119
|
resolveInteractiveToolResult,
|
|
4120
|
+
resolveAssistantToolHooks,
|
|
4121
|
+
resolveAssistantStoreDependencies,
|
|
2969
4122
|
resolveAssistantLlmSettings,
|
|
2970
4123
|
resolveAssistantLabels,
|
|
2971
4124
|
resetAssistantLlm,
|
|
2972
4125
|
requestLlmCompletion,
|
|
2973
4126
|
rejectAllInteractiveToolWaiters,
|
|
4127
|
+
prepareMarkdown,
|
|
2974
4128
|
persistStoredModelSelection,
|
|
2975
4129
|
peekStoredModel,
|
|
2976
4130
|
parseSuggestedPromptsResponse,
|
|
@@ -2978,6 +4132,7 @@ export {
|
|
|
2978
4132
|
parseChatCommand,
|
|
2979
4133
|
normalizeStoredSystemPrompt,
|
|
2980
4134
|
normalizeStoredSettings,
|
|
4135
|
+
normalizeCodeLineEndings,
|
|
2981
4136
|
migrateLegacyModelStorage,
|
|
2982
4137
|
mergeLlmSettings,
|
|
2983
4138
|
listChatCommands,
|
|
@@ -2986,8 +4141,10 @@ export {
|
|
|
2986
4141
|
isLlmSettingsFormDirty,
|
|
2987
4142
|
isLlmConfigured,
|
|
2988
4143
|
isChatCommandInput,
|
|
4144
|
+
highlightCode,
|
|
2989
4145
|
getFallbackModels,
|
|
2990
4146
|
getChatCommandSuggestions,
|
|
4147
|
+
fromLlmToolName,
|
|
2991
4148
|
formatModelsText,
|
|
2992
4149
|
formatLabel,
|
|
2993
4150
|
formatJsonIfLarge,
|
|
@@ -2999,11 +4156,15 @@ export {
|
|
|
2999
4156
|
createLlmSettingsFormState,
|
|
3000
4157
|
createDefaultStoredSettings,
|
|
3001
4158
|
createChatHistoryHelpers,
|
|
4159
|
+
createAssistantToolRegistry,
|
|
3002
4160
|
createAssistantStore,
|
|
4161
|
+
connectExternalTools,
|
|
3003
4162
|
configureAssistantLlm,
|
|
4163
|
+
completionForChatCommand,
|
|
3004
4164
|
clearProviderModelCache,
|
|
3005
4165
|
childrenToText,
|
|
3006
4166
|
chatActivityStepLabel,
|
|
4167
|
+
buildSystemPromptWithTools,
|
|
3007
4168
|
buildModelsUrl,
|
|
3008
4169
|
buildLlmRequestHeaders,
|
|
3009
4170
|
buildLlmHistory,
|