@4djs/assistant 0.1.0 → 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 +138 -3
- package/dist/core/chat-activity.d.ts +2 -1
- package/dist/core/chat-activity.d.ts.map +1 -1
- package/dist/core/chat-commands.d.ts +6 -4
- package/dist/core/chat-commands.d.ts.map +1 -1
- package/dist/core/chat-history.d.ts.map +1 -1
- package/dist/core/chat-reply-suggestions-parse.d.ts.map +1 -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/fetch-suggested-prompts.d.ts.map +1 -1
- package/dist/core/index.d.ts +10 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2148 -838
- package/dist/core/interactive-tools/choices.d.ts.map +1 -1
- package/dist/core/interactive-tools/confirmation.d.ts.map +1 -1
- package/dist/core/interactive-tools/execute.d.ts.map +1 -1
- 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/interactive-tools/suggestions.d.ts.map +1 -1
- package/dist/core/interactive-tools/waiters.d.ts.map +1 -1
- package/dist/core/llm-chat.d.ts.map +1 -1
- package/dist/core/llm-config.d.ts.map +1 -1
- package/dist/core/llm-models.d.ts.map +1 -1
- package/dist/core/llm-provider.d.ts.map +1 -1
- package/dist/core/llm-settings-storage.d.ts.map +1 -1
- package/dist/core/llm-sse.d.ts.map +1 -1
- package/dist/core/llm-types.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 +875 -4161
- package/dist/labels.d.ts +136 -0
- package/dist/labels.d.ts.map +1 -0
- 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/MarkdownEditor.d.ts.map +1 -1
- package/dist/react/components/MermaidDiagram.d.ts.map +1 -1
- package/dist/react/components/ModelSelector.d.ts.map +1 -1
- package/dist/react/components/chat/AssistantErrorCallout.d.ts +3 -1
- package/dist/react/components/chat/AssistantErrorCallout.d.ts.map +1 -1
- package/dist/react/components/chat/ChatActivity.d.ts.map +1 -1
- package/dist/react/components/chat/ChatComposer.d.ts +3 -1
- package/dist/react/components/chat/ChatComposer.d.ts.map +1 -1
- package/dist/react/components/chat/ChatEmptyState.d.ts.map +1 -1
- package/dist/react/components/chat/ChatInteractivePrompt/choices-prompt.d.ts.map +1 -1
- package/dist/react/components/chat/ChatInteractivePrompt/confirmation-prompt.d.ts.map +1 -1
- package/dist/react/components/chat/ChatInteractivePrompt/index.d.ts.map +1 -1
- package/dist/react/components/chat/ChatInteractivePrompt/shell.d.ts.map +1 -1
- package/dist/react/components/chat/ChatMessage.d.ts.map +1 -1
- package/dist/react/components/chat/ChatMessageScroll.d.ts.map +1 -1
- package/dist/react/components/chat/ChatReplySuggestions.d.ts.map +1 -1
- package/dist/react/components/chat/ComposerCommandMenu.d.ts.map +1 -1
- package/dist/react/components/chat/LlmSettingsStrip.d.ts.map +1 -1
- package/dist/react/components/chat/LlmSetupPrompt.d.ts.map +1 -1
- package/dist/react/components/chat/LlmUnavailableBanner.d.ts.map +1 -1
- package/dist/react/components/chat/SuggestedPromptsList.d.ts.map +1 -1
- package/dist/react/components/chat/SuggestedPromptsStrip.d.ts.map +1 -1
- package/dist/react/components/chat/SystemPromptField.d.ts.map +1 -1
- package/dist/react/components/highlighted-code.d.ts.map +1 -1
- package/dist/react/context.d.ts +4 -2
- package/dist/react/context.d.ts.map +1 -1
- package/dist/react/hooks/use-composer-commands.d.ts +4 -2
- package/dist/react/hooks/use-composer-commands.d.ts.map +1 -1
- package/dist/react/hooks/use-suggested-prompts.d.ts +2 -1
- package/dist/react/hooks/use-suggested-prompts.d.ts.map +1 -1
- package/dist/react/index.d.ts +4 -2
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/lib/parse-assistant-error.d.ts +2 -1
- package/dist/react/lib/parse-assistant-error.d.ts.map +1 -1
- package/dist/react/lib/prompt-icons.d.ts.map +1 -1
- package/dist/react/types.d.ts +7 -2
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/utils/cn.d.ts.map +1 -1
- package/dist/styles.css +1886 -1806
- 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 +55 -50
package/dist/core/index.js
CHANGED
|
@@ -16,837 +16,1563 @@ 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);
|
|
205
528
|
}
|
|
206
|
-
|
|
207
|
-
|
|
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]);
|
|
208
557
|
}
|
|
209
|
-
|
|
210
|
-
|
|
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;
|
|
211
568
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
569
|
+
if (typeof mode.beginScope !== "object" || mode.beginScope === null) {
|
|
570
|
+
error("beginScope must be object");
|
|
571
|
+
throw MultiClassError;
|
|
572
|
+
}
|
|
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;
|
|
582
|
+
}
|
|
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 };
|
|
217
603
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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
|
+
}
|
|
644
|
+
}
|
|
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);
|
|
237
685
|
}
|
|
686
|
+
}
|
|
687
|
+
if (result) {
|
|
688
|
+
this.regexIndex += result.position + 1;
|
|
689
|
+
if (this.regexIndex === this.count) {
|
|
690
|
+
this.considerAll();
|
|
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
|
-
childKey = nameSoFar === "" ? "." : nameSoFar + ":";
|
|
276
|
-
if (isArrayImpl(children))
|
|
277
|
-
for (var i = 0;i < children.length; i++)
|
|
278
|
-
nameSoFar = children[i], type = childKey + getElementKey(nameSoFar, i), invokeCallback += mapIntoArray(nameSoFar, array, escapedPrefix, type, callback);
|
|
279
|
-
else if (i = getIteratorFn(children), typeof i === "function")
|
|
280
|
-
for (i === children.entries && (didWarnAboutMaps || console.warn("Using Maps as children is not supported. Use an array of keyed ReactElements instead."), didWarnAboutMaps = true), children = i.call(children), i = 0;!(nameSoFar = children.next()).done; )
|
|
281
|
-
nameSoFar = nameSoFar.value, type = childKey + getElementKey(nameSoFar, i++), invokeCallback += mapIntoArray(nameSoFar, array, escapedPrefix, type, callback);
|
|
282
|
-
else if (type === "object") {
|
|
283
|
-
if (typeof children.then === "function")
|
|
284
|
-
return mapIntoArray(resolveThenable(children), array, escapedPrefix, nameSoFar, callback);
|
|
285
|
-
array = String(children);
|
|
286
|
-
throw Error("Objects are not valid as a React child (found: " + (array === "[object Object]" ? "object with keys {" + Object.keys(children).join(", ") + "}" : array) + "). If you meant to render a collection of children, use an array instead.");
|
|
287
|
-
}
|
|
288
|
-
return invokeCallback;
|
|
289
|
-
}
|
|
290
|
-
function mapChildren(children, func, context) {
|
|
291
|
-
if (children == null)
|
|
292
|
-
return children;
|
|
293
|
-
var result = [], count = 0;
|
|
294
|
-
mapIntoArray(children, result, "", "", function(child) {
|
|
295
|
-
return func.call(context, child, count++);
|
|
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);
|
|
296
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);
|
|
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
|
-
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
960
|
+
i++;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
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;
|
|
978
|
+
}
|
|
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
|
+
}
|
|
998
|
+
}
|
|
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
|
+
}
|
|
1007
|
+
}
|
|
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;
|
|
1033
|
+
}
|
|
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;
|
|
1053
|
+
}
|
|
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;
|
|
1072
|
+
}
|
|
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
|
+
}
|
|
1079
|
+
}
|
|
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;
|
|
1097
|
+
}
|
|
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;
|
|
419
1201
|
}
|
|
420
1202
|
}
|
|
421
1203
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
react_stack_bottom_frame: function(callStackForError) {
|
|
482
|
-
return callStackForError();
|
|
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)
|
|
1211
|
+
};
|
|
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
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
return 0;
|
|
1231
|
+
});
|
|
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
|
+
}
|
|
483
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
|
|
1274
|
+
};
|
|
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.");
|
|
484
1289
|
};
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
} else if (typeof process === "object" && typeof process.emit === "function") {
|
|
500
|
-
process.emit("uncaughtException", error);
|
|
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);
|
|
1302
|
+
}
|
|
1303
|
+
wantsHighlight = true;
|
|
501
1304
|
return;
|
|
502
1305
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
1306
|
+
const blocks = document.querySelectorAll(options.cssSelector);
|
|
1307
|
+
blocks.forEach(highlightElement);
|
|
1308
|
+
}
|
|
1309
|
+
function registerLanguage(languageName, languageDefinition) {
|
|
1310
|
+
let lang = null;
|
|
1311
|
+
try {
|
|
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;
|
|
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];
|
|
513
1348
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
}
|
|
527
|
-
return n;
|
|
528
|
-
},
|
|
529
|
-
toArray: function(children) {
|
|
530
|
-
return mapChildren(children, function(child) {
|
|
531
|
-
return child;
|
|
532
|
-
}) || [];
|
|
533
|
-
},
|
|
534
|
-
only: function(children) {
|
|
535
|
-
if (!isValidElement(children))
|
|
536
|
-
throw Error("React.Children.only expected to receive a single React element child.");
|
|
537
|
-
return children;
|
|
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
|
+
};
|
|
538
1362
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
exports.Component = Component;
|
|
543
|
-
exports.Fragment = REACT_FRAGMENT_TYPE;
|
|
544
|
-
exports.Profiler = REACT_PROFILER_TYPE;
|
|
545
|
-
exports.PureComponent = PureComponent;
|
|
546
|
-
exports.StrictMode = REACT_STRICT_MODE_TYPE;
|
|
547
|
-
exports.Suspense = REACT_SUSPENSE_TYPE;
|
|
548
|
-
exports.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE = ReactSharedInternals;
|
|
549
|
-
exports.__COMPILER_RUNTIME = deprecatedAPIs;
|
|
550
|
-
exports.act = function(callback) {
|
|
551
|
-
var prevActQueue = ReactSharedInternals.actQueue, prevActScopeDepth = actScopeDepth;
|
|
552
|
-
actScopeDepth++;
|
|
553
|
-
var queue = ReactSharedInternals.actQueue = prevActQueue !== null ? prevActQueue : [], didAwaitActCall = false;
|
|
554
|
-
try {
|
|
555
|
-
var result = callback();
|
|
556
|
-
} catch (error) {
|
|
557
|
-
ReactSharedInternals.thrownErrors.push(error);
|
|
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
|
-
});
|
|
590
|
-
}
|
|
1363
|
+
if (plugin["after:highlightBlock"] && !plugin["after:highlightElement"]) {
|
|
1364
|
+
plugin["after:highlightElement"] = (data) => {
|
|
1365
|
+
plugin["after:highlightBlock"](Object.assign({ block: data.el }, data));
|
|
591
1366
|
};
|
|
592
1367
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
exports.cache = function(fn) {
|
|
610
|
-
return function() {
|
|
611
|
-
return fn.apply(null, arguments);
|
|
612
|
-
};
|
|
613
|
-
};
|
|
614
|
-
exports.cacheSignal = function() {
|
|
615
|
-
return null;
|
|
616
|
-
};
|
|
617
|
-
exports.captureOwnerStack = function() {
|
|
618
|
-
var getCurrentStack = ReactSharedInternals.getCurrentStack;
|
|
619
|
-
return getCurrentStack === null ? null : getCurrentStack();
|
|
620
|
-
};
|
|
621
|
-
exports.cloneElement = function(element, config, children) {
|
|
622
|
-
if (element === null || element === undefined)
|
|
623
|
-
throw Error("The argument must be a React element, but you passed " + element + ".");
|
|
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;
|
|
631
|
-
}
|
|
632
|
-
JSCompiler_inline_result = config.ref !== undefined;
|
|
633
|
-
}
|
|
634
|
-
JSCompiler_inline_result && (owner = getOwner());
|
|
635
|
-
hasValidKey(config) && (checkKeyStringCoercion(config.key), key = "" + config.key);
|
|
636
|
-
for (propName in config)
|
|
637
|
-
!hasOwnProperty.call(config, propName) || propName === "key" || propName === "__self" || propName === "__source" || propName === "ref" && config.ref === undefined || (props[propName] = config[propName]);
|
|
638
|
-
}
|
|
639
|
-
var propName = arguments.length - 2;
|
|
640
|
-
if (propName === 1)
|
|
641
|
-
props.children = children;
|
|
642
|
-
else if (1 < propName) {
|
|
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
|
|
666
|
-
};
|
|
667
|
-
defaultValue._currentRenderer = null;
|
|
668
|
-
defaultValue._currentRenderer2 = null;
|
|
669
|
-
return defaultValue;
|
|
670
|
-
};
|
|
671
|
-
exports.createElement = function(type, config, children) {
|
|
672
|
-
for (var i = 2;i < arguments.length; i++)
|
|
673
|
-
validateChildKeys(arguments[i]);
|
|
674
|
-
i = {};
|
|
675
|
-
var key = null;
|
|
676
|
-
if (config != null)
|
|
677
|
-
for (propName in didWarnAboutOldJSXRuntime || !("__self" in config) || "key" in config || (didWarnAboutOldJSXRuntime = true, console.warn("Your app (or one of its dependencies) is using an outdated JSX transform. Update to the modern JSX transform for faster performance: https://react.dev/link/new-jsx-transform")), hasValidKey(config) && (checkKeyStringCoercion(config.key), key = "" + config.key), config)
|
|
678
|
-
hasOwnProperty.call(config, propName) && propName !== "key" && propName !== "__self" && propName !== "__source" && (i[propName] = config[propName]);
|
|
679
|
-
var childrenLength = arguments.length - 2;
|
|
680
|
-
if (childrenLength === 1)
|
|
681
|
-
i.children = children;
|
|
682
|
-
else if (1 < childrenLength) {
|
|
683
|
-
for (var childArray = Array(childrenLength), _i = 0;_i < childrenLength; _i++)
|
|
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);
|
|
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);
|
|
713
1384
|
}
|
|
714
1385
|
});
|
|
715
|
-
|
|
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;
|
|
716
1413
|
};
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
ctor = { _status: -1, _result: ctor };
|
|
720
|
-
var lazyType = {
|
|
721
|
-
$$typeof: REACT_LAZY_TYPE,
|
|
722
|
-
_payload: ctor,
|
|
723
|
-
_init: lazyInitializer
|
|
724
|
-
}, ioInfo = {
|
|
725
|
-
name: "lazy",
|
|
726
|
-
start: -1,
|
|
727
|
-
end: -1,
|
|
728
|
-
value: null,
|
|
729
|
-
owner: null,
|
|
730
|
-
debugStack: Error("react-stack-top-frame"),
|
|
731
|
-
debugTask: console.createTask ? console.createTask("lazy()") : null
|
|
732
|
-
};
|
|
733
|
-
ctor._ioInfo = ioInfo;
|
|
734
|
-
lazyType._debugInfo = [{ awaited: ioInfo }];
|
|
735
|
-
return lazyType;
|
|
1414
|
+
hljs.safeMode = function() {
|
|
1415
|
+
SAFE_MODE = true;
|
|
736
1416
|
};
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
var ownName;
|
|
745
|
-
Object.defineProperty(compare, "displayName", {
|
|
746
|
-
enumerable: false,
|
|
747
|
-
configurable: true,
|
|
748
|
-
get: function() {
|
|
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);
|
|
754
|
-
}
|
|
755
|
-
});
|
|
756
|
-
return compare;
|
|
1417
|
+
hljs.versionString = version;
|
|
1418
|
+
hljs.regex = {
|
|
1419
|
+
concat,
|
|
1420
|
+
lookahead,
|
|
1421
|
+
either,
|
|
1422
|
+
optional,
|
|
1423
|
+
anyNumberOfTimes
|
|
757
1424
|
};
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
ReactSharedInternals.T = currentTransition;
|
|
762
|
-
try {
|
|
763
|
-
var returnValue = scope(), onStartTransitionFinish = ReactSharedInternals.S;
|
|
764
|
-
onStartTransitionFinish !== null && onStartTransitionFinish(currentTransition, returnValue);
|
|
765
|
-
typeof returnValue === "object" && returnValue !== null && typeof returnValue.then === "function" && (ReactSharedInternals.asyncTransitions++, returnValue.then(releaseAsyncTransition, releaseAsyncTransition), returnValue.then(noop, reportGlobalError));
|
|
766
|
-
} catch (error) {
|
|
767
|
-
reportGlobalError(error);
|
|
768
|
-
} finally {
|
|
769
|
-
prevTransition === null && currentTransition._updatedFibers && (scope = currentTransition._updatedFibers.size, currentTransition._updatedFibers.clear(), 10 < scope && console.warn("Detected a large number of updates inside startTransition. If this is due to a subscription please re-write it to use React provided hooks. Otherwise concurrent mode guarantees are off the table.")), prevTransition !== null && currentTransition.types !== null && (prevTransition.types !== null && prevTransition.types !== currentTransition.types && console.error("We expected inner Transitions to have transferred the outer types set and that you cannot add to the outer Transition while inside the inner.This is a bug in React."), prevTransition.types = currentTransition.types), ReactSharedInternals.T = prevTransition;
|
|
1425
|
+
for (const key in MODES) {
|
|
1426
|
+
if (typeof MODES[key] === "object") {
|
|
1427
|
+
deepFreeze(MODES[key]);
|
|
770
1428
|
}
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
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);
|
|
833
|
-
};
|
|
834
|
-
exports.useTransition = function() {
|
|
835
|
-
return resolveDispatcher().useTransition();
|
|
836
|
-
};
|
|
837
|
-
exports.version = "19.2.7";
|
|
838
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
839
|
-
})();
|
|
840
|
-
});
|
|
841
|
-
|
|
842
|
-
// ../../node_modules/.bun/react@19.2.7/node_modules/react/index.js
|
|
843
|
-
var require_react = __commonJS((exports, module) => {
|
|
844
|
-
var react_development = __toESM(require_react_development());
|
|
845
|
-
if (false) {} else {
|
|
846
|
-
module.exports = react_development;
|
|
847
|
-
}
|
|
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
|
|
|
1440
|
+
// src/labels.ts
|
|
1441
|
+
var DEFAULT_ASSISTANT_LABELS = {
|
|
1442
|
+
"common.cancel": "Cancel",
|
|
1443
|
+
"common.save": "Save",
|
|
1444
|
+
"common.saving": "Saving",
|
|
1445
|
+
"common.dismiss": "Dismiss",
|
|
1446
|
+
"common.loading": "Loading…",
|
|
1447
|
+
"common.error": "Error",
|
|
1448
|
+
"common.result": "Result",
|
|
1449
|
+
"common.edit": "Edit",
|
|
1450
|
+
"common.preview": "Preview",
|
|
1451
|
+
"common.regenerate": "Regenerate",
|
|
1452
|
+
"common.tryAgain": "Try again",
|
|
1453
|
+
"header.title": "Assistant",
|
|
1454
|
+
"message.assistantRole": "Assistant",
|
|
1455
|
+
"message.thinking": "Assistant is thinking",
|
|
1456
|
+
"composer.placeholder": "Ask the assistant…",
|
|
1457
|
+
"composer.placeholderDisabled": "LLM not configured — chat is disabled",
|
|
1458
|
+
"composer.messageAria": "Chat message",
|
|
1459
|
+
"composer.send": "Send",
|
|
1460
|
+
"composer.stop": "Stop",
|
|
1461
|
+
"composer.hint": "Enter to send · Shift+Enter for new line",
|
|
1462
|
+
"composer.llmSettings": "LLM settings",
|
|
1463
|
+
"composer.generateSuggestions": "Generate suggestions",
|
|
1464
|
+
"composer.clearConversation": "Clear conversation",
|
|
1465
|
+
"commandMenu.ariaLabel": "Composer commands",
|
|
1466
|
+
"commandMenu.header": "Commands",
|
|
1467
|
+
"commands.clear.description": "Clear the current conversation",
|
|
1468
|
+
"commands.clear.noArgsError": "The /clear command does not accept arguments.",
|
|
1469
|
+
"commands.clear.waitForFinishError": "Wait for the assistant to finish before clearing.",
|
|
1470
|
+
"commands.unknown": "Unknown command: /{name}",
|
|
1471
|
+
"commands.failed": "Command failed",
|
|
1472
|
+
"llmSetup.notConnected": "LLM not connected.",
|
|
1473
|
+
"llmSetup.addProviderBeforeLink": "Add a cloud or local provider in",
|
|
1474
|
+
"llmSetup.settingsLink": "LLM settings",
|
|
1475
|
+
"llmSetup.connectTitle": "Connect an LLM",
|
|
1476
|
+
"llmSetup.connectDescription": "OpenAI-compatible endpoint — cloud or local",
|
|
1477
|
+
"llmSetup.configure": "Configure",
|
|
1478
|
+
"llmSettings.title": "LLM settings",
|
|
1479
|
+
"llmSettings.ariaLabel": "LLM settings",
|
|
1480
|
+
"llmSettings.testConnection": "Test connection",
|
|
1481
|
+
"llmSettings.resetAllSettings": "Reset all settings",
|
|
1482
|
+
"llmSettings.close": "Close LLM settings",
|
|
1483
|
+
"llmSettings.baseUrl": "Base URL",
|
|
1484
|
+
"llmSettings.apiKey": "API key",
|
|
1485
|
+
"llmSettings.model": "Model",
|
|
1486
|
+
"llmSettings.advanced": "Advanced",
|
|
1487
|
+
"llmSettings.modelList": "Model list",
|
|
1488
|
+
"llmSettings.baseUrlPlaceholder": "https://api.openai.com/v1",
|
|
1489
|
+
"llmSettings.apiKeyPlaceholder": "sk-…",
|
|
1490
|
+
"llmSettings.apiKeyConfiguredPlaceholder": "Configured — leave blank to keep",
|
|
1491
|
+
"llmSettings.modelPlaceholder": "gpt-4o-mini",
|
|
1492
|
+
"llmSettings.modelListPlaceholder": "Optional — comma-separated",
|
|
1493
|
+
"llmSettings.connected": "Connected · {model}",
|
|
1494
|
+
"llmSettings.resetAll": "Reset all",
|
|
1495
|
+
"llmSettings.failedToLoad": "Failed to load LLM settings",
|
|
1496
|
+
"llmSettings.failedToSave": "Failed to save LLM settings",
|
|
1497
|
+
"llmSettings.failedToReset": "Failed to reset LLM settings",
|
|
1498
|
+
"systemPrompt.label": "System prompt",
|
|
1499
|
+
"systemPrompt.defaultTag": "Default",
|
|
1500
|
+
"systemPrompt.viewAria": "System prompt view",
|
|
1501
|
+
"systemPrompt.resetAria": "Reset system prompt",
|
|
1502
|
+
"systemPrompt.resetTitle": "Reset to default",
|
|
1503
|
+
"systemPrompt.placeholder": "Optional — replaces app default",
|
|
1504
|
+
"systemPrompt.editorAria": "System prompt editor",
|
|
1505
|
+
"systemPrompt.previewAria": "System prompt preview",
|
|
1506
|
+
"modelSelector.label": "Model",
|
|
1507
|
+
"modelSelector.modelAria": "LLM model",
|
|
1508
|
+
"modelSelector.loadingModels": "Loading models…",
|
|
1509
|
+
"modelSelector.searchModels": "Search models…",
|
|
1510
|
+
"modelSelector.suggestionsAria": "Model suggestions",
|
|
1511
|
+
"modelSelector.custom": "Custom",
|
|
1512
|
+
"suggestions.ariaLabel": "Suggested prompts",
|
|
1513
|
+
"suggestions.title": "Suggestions",
|
|
1514
|
+
"suggestions.generate": "Generate",
|
|
1515
|
+
"suggestions.close": "Close suggestions",
|
|
1516
|
+
"suggestions.loading": "Loading suggestions",
|
|
1517
|
+
"suggestions.failedToLoad": "Failed to load suggestions",
|
|
1518
|
+
"emptyState.eyebrow": "AI Assistant",
|
|
1519
|
+
"emptyState.generateSuggestions": "Generate suggestions",
|
|
1520
|
+
"emptyState.generateSuggestionsHint": "Tailored prompts based on your live catalog",
|
|
1521
|
+
"emptyState.generating": "Generating suggestions",
|
|
1522
|
+
"emptyState.suggestedForYou": "Suggested for you",
|
|
1523
|
+
"emptyState.quickStarts": "Quick starts",
|
|
1524
|
+
"emptyState.capabilities.catalog": "Catalog",
|
|
1525
|
+
"emptyState.capabilities.query": "Query",
|
|
1526
|
+
"emptyState.capabilities.mutate": "Mutate",
|
|
1527
|
+
"activity.trace": "Trace",
|
|
1528
|
+
"activity.live": "Live",
|
|
1529
|
+
"activity.arguments": "Arguments",
|
|
1530
|
+
"activity.running": "Running…",
|
|
1531
|
+
"activity.steps.waitingConfirmation": "Waiting for confirmation…",
|
|
1532
|
+
"activity.steps.waitingChoice": "Waiting for your choice…",
|
|
1533
|
+
"activity.steps.suggestingReplies": "Suggesting replies…",
|
|
1534
|
+
"activity.steps.running": "Running {name}…",
|
|
1535
|
+
"activity.steps.failed": "{name} failed",
|
|
1536
|
+
"activity.steps.confirmationAnswered": "Confirmation answered",
|
|
1537
|
+
"activity.steps.choiceSubmitted": "Choice submitted",
|
|
1538
|
+
"activity.steps.replySuggestionsShown": "Reply suggestions shown",
|
|
1539
|
+
"activity.steps.ran": "Ran {name}",
|
|
1540
|
+
"interactive.chooseOptions": "Choose options",
|
|
1541
|
+
"interactive.chooseOne": "Choose one",
|
|
1542
|
+
"interactive.choicesKeyboardHint": "1-9 · Enter · Esc",
|
|
1543
|
+
"interactive.confirmationKeyboardHint": "Enter · Esc",
|
|
1544
|
+
"interactive.confirm": "Confirm",
|
|
1545
|
+
"interactive.confirmDeletion": "Confirm deletion",
|
|
1546
|
+
"interactive.invalidArgs": "Invalid interactive tool arguments",
|
|
1547
|
+
"replySuggestions.legend": "Suggested replies",
|
|
1548
|
+
"replySuggestions.pickHint": "to pick · or type below",
|
|
1549
|
+
"replySuggestions.badges.model": "Model",
|
|
1550
|
+
"replySuggestions.badges.status": "Status",
|
|
1551
|
+
"replySuggestions.badges.tools": "Tools",
|
|
1552
|
+
"replySuggestions.badges.dataclass": "Dataclass",
|
|
1553
|
+
"replySuggestions.badges.filter": "Filter",
|
|
1554
|
+
"scroll.toBottom": "Scroll to bottom",
|
|
1555
|
+
"errors.network.title": "Connection lost",
|
|
1556
|
+
"errors.network.hintChat": "Check your network or LLM endpoint, then try again.",
|
|
1557
|
+
"errors.network.hintSuggestions": "Check your connection and LLM settings.",
|
|
1558
|
+
"errors.auth.title": "Authentication failed",
|
|
1559
|
+
"errors.auth.hint": "Verify your API key or credentials in LLM settings.",
|
|
1560
|
+
"errors.timeout.title": "Request timed out",
|
|
1561
|
+
"errors.timeout.hint": "The model took too long to respond. Try again in a moment.",
|
|
1562
|
+
"errors.rateLimit.title": "Rate limit reached",
|
|
1563
|
+
"errors.rateLimit.hint": "Wait a few seconds before sending another request.",
|
|
1564
|
+
"errors.unknown.titleChat": "Something went wrong",
|
|
1565
|
+
"errors.unknown.titleSuggestions": "Couldn't load suggestions",
|
|
1566
|
+
"errors.unknown.hintChat": "Try again, or review your LLM settings.",
|
|
1567
|
+
"errors.unknown.hintSuggestions": "Try regenerating, or check your LLM configuration."
|
|
1568
|
+
};
|
|
1569
|
+
var ASSISTANT_LABEL_KEYS = Object.keys(DEFAULT_ASSISTANT_LABELS);
|
|
1570
|
+
function formatLabel(template, values) {
|
|
1571
|
+
return template.replace(/\{(\w+)\}/g, (_, key) => String(values[key] ?? ""));
|
|
1572
|
+
}
|
|
1573
|
+
function resolveAssistantLabels(overrides) {
|
|
1574
|
+
return { ...DEFAULT_ASSISTANT_LABELS, ...overrides };
|
|
1575
|
+
}
|
|
850
1576
|
// src/core/chat-activity.ts
|
|
851
1577
|
function summarizeActivityResult(result) {
|
|
852
1578
|
if (result === undefined || result === null)
|
|
@@ -862,25 +1588,25 @@ function summarizeActivityResult(result) {
|
|
|
862
1588
|
}
|
|
863
1589
|
return result;
|
|
864
1590
|
}
|
|
865
|
-
function chatActivityStepLabel(step) {
|
|
1591
|
+
function chatActivityStepLabel(step, labels = DEFAULT_ASSISTANT_LABELS) {
|
|
866
1592
|
if (step.status === "active") {
|
|
867
1593
|
if (step.name === "request_confirmation")
|
|
868
|
-
return "
|
|
1594
|
+
return labels["activity.steps.waitingConfirmation"];
|
|
869
1595
|
if (step.name === "request_choices")
|
|
870
|
-
return "
|
|
1596
|
+
return labels["activity.steps.waitingChoice"];
|
|
871
1597
|
if (step.name === "suggest_replies")
|
|
872
|
-
return "
|
|
873
|
-
return
|
|
1598
|
+
return labels["activity.steps.suggestingReplies"];
|
|
1599
|
+
return formatLabel(labels["activity.steps.running"], { name: step.name });
|
|
874
1600
|
}
|
|
875
1601
|
if (step.status === "error")
|
|
876
|
-
return
|
|
1602
|
+
return formatLabel(labels["activity.steps.failed"], { name: step.name });
|
|
877
1603
|
if (step.name === "request_confirmation")
|
|
878
|
-
return "
|
|
1604
|
+
return labels["activity.steps.confirmationAnswered"];
|
|
879
1605
|
if (step.name === "request_choices")
|
|
880
|
-
return "
|
|
1606
|
+
return labels["activity.steps.choiceSubmitted"];
|
|
881
1607
|
if (step.name === "suggest_replies")
|
|
882
|
-
return "
|
|
883
|
-
return
|
|
1608
|
+
return labels["activity.steps.replySuggestionsShown"];
|
|
1609
|
+
return formatLabel(labels["activity.steps.ran"], { name: step.name });
|
|
884
1610
|
}
|
|
885
1611
|
function formatJsonIfLarge(raw) {
|
|
886
1612
|
const trimmed = raw.trim();
|
|
@@ -898,42 +1624,46 @@ function formatJsonIfLarge(raw) {
|
|
|
898
1624
|
var CHAT_COMMANDS = [
|
|
899
1625
|
{
|
|
900
1626
|
name: "clear",
|
|
901
|
-
description: "Clear the current conversation",
|
|
902
1627
|
surfaces: ["assistant"],
|
|
903
|
-
|
|
1628
|
+
description: (labels) => labels["commands.clear.description"],
|
|
1629
|
+
run: async (args, deps, labels) => {
|
|
904
1630
|
if (args) {
|
|
905
|
-
throw new Error("
|
|
1631
|
+
throw new Error(labels["commands.clear.noArgsError"]);
|
|
906
1632
|
}
|
|
907
1633
|
if (deps.streaming) {
|
|
908
|
-
throw new Error("
|
|
1634
|
+
throw new Error(labels["commands.clear.waitForFinishError"]);
|
|
909
1635
|
}
|
|
910
1636
|
deps.clearMessages();
|
|
911
1637
|
deps.setError(null);
|
|
912
1638
|
}
|
|
913
1639
|
}
|
|
914
1640
|
];
|
|
915
|
-
function
|
|
1641
|
+
function resolveLabels(labels) {
|
|
1642
|
+
return labels ?? DEFAULT_ASSISTANT_LABELS;
|
|
1643
|
+
}
|
|
1644
|
+
function getChatCommandSuggestions(surface, labels) {
|
|
1645
|
+
const resolved = resolveLabels(labels);
|
|
916
1646
|
return CHAT_COMMANDS.filter((command) => command.surfaces.includes(surface)).map(({ name, description }) => ({
|
|
917
1647
|
name,
|
|
918
|
-
description,
|
|
1648
|
+
description: description(resolved),
|
|
919
1649
|
usage: `/${name}`
|
|
920
1650
|
}));
|
|
921
1651
|
}
|
|
922
1652
|
function isChatCommandInput(value) {
|
|
923
1653
|
return value.trimStart().startsWith("/");
|
|
924
1654
|
}
|
|
925
|
-
function filterChatCommands(value, surface) {
|
|
1655
|
+
function filterChatCommands(value, surface, labels) {
|
|
926
1656
|
if (!isChatCommandInput(value)) {
|
|
927
1657
|
return [];
|
|
928
1658
|
}
|
|
929
1659
|
const query = value.trimStart().slice(1).toLowerCase();
|
|
930
|
-
const commands = getChatCommandSuggestions(surface);
|
|
1660
|
+
const commands = getChatCommandSuggestions(surface, labels);
|
|
931
1661
|
if (!query) {
|
|
932
1662
|
return commands;
|
|
933
1663
|
}
|
|
934
1664
|
return commands.filter((command) => command.name.startsWith(query) || command.usage.toLowerCase().startsWith(`/${query}`));
|
|
935
1665
|
}
|
|
936
|
-
function shouldShowChatCommandMenu(value, surface) {
|
|
1666
|
+
function shouldShowChatCommandMenu(value, surface, labels) {
|
|
937
1667
|
if (!isChatCommandInput(value) || value.includes(`
|
|
938
1668
|
`)) {
|
|
939
1669
|
return false;
|
|
@@ -942,10 +1672,17 @@ function shouldShowChatCommandMenu(value, surface) {
|
|
|
942
1672
|
if (trimmed.includes(" ")) {
|
|
943
1673
|
return false;
|
|
944
1674
|
}
|
|
945
|
-
return filterChatCommands(value, surface).length > 0;
|
|
1675
|
+
return filterChatCommands(value, surface, labels).length > 0;
|
|
1676
|
+
}
|
|
1677
|
+
function completionForChatCommand(command) {
|
|
1678
|
+
return `${command.usage} `;
|
|
946
1679
|
}
|
|
947
|
-
function listChatCommands(surface) {
|
|
948
|
-
|
|
1680
|
+
function listChatCommands(surface, labels) {
|
|
1681
|
+
const resolved = resolveLabels(labels);
|
|
1682
|
+
return CHAT_COMMANDS.filter((command) => !surface || command.surfaces.includes(surface)).map(({ name, description }) => ({
|
|
1683
|
+
name,
|
|
1684
|
+
description: description(resolved)
|
|
1685
|
+
}));
|
|
949
1686
|
}
|
|
950
1687
|
function parseChatCommand(input) {
|
|
951
1688
|
const trimmed = input.trim();
|
|
@@ -963,22 +1700,23 @@ function parseChatCommand(input) {
|
|
|
963
1700
|
};
|
|
964
1701
|
}
|
|
965
1702
|
async function executeCommand(parsed, deps) {
|
|
1703
|
+
const labels = resolveLabels(deps.labels);
|
|
966
1704
|
const command = CHAT_COMMANDS.find((entry) => entry.name === parsed.name);
|
|
967
1705
|
if (!command?.surfaces.includes("assistant")) {
|
|
968
1706
|
return {
|
|
969
1707
|
handled: true,
|
|
970
1708
|
clearInput: true,
|
|
971
|
-
error:
|
|
1709
|
+
error: formatLabel(labels["commands.unknown"], { name: parsed.name })
|
|
972
1710
|
};
|
|
973
1711
|
}
|
|
974
1712
|
try {
|
|
975
|
-
await command.run(parsed.args, deps);
|
|
1713
|
+
await command.run(parsed.args, deps, labels);
|
|
976
1714
|
return { handled: true, clearInput: true };
|
|
977
1715
|
} catch (error) {
|
|
978
1716
|
return {
|
|
979
1717
|
handled: true,
|
|
980
1718
|
clearInput: true,
|
|
981
|
-
error: error instanceof Error ? error.message : "
|
|
1719
|
+
error: error instanceof Error ? error.message : labels["commands.failed"]
|
|
982
1720
|
};
|
|
983
1721
|
}
|
|
984
1722
|
}
|
|
@@ -993,7 +1731,7 @@ async function runAssistantChatCommand(input, deps) {
|
|
|
993
1731
|
var REQUEST_CHOICES_TOOL = "request_choices";
|
|
994
1732
|
var CHOICES_TOOL = {
|
|
995
1733
|
name: REQUEST_CHOICES_TOOL,
|
|
996
|
-
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.",
|
|
997
1735
|
inputSchema: {
|
|
998
1736
|
type: "object",
|
|
999
1737
|
properties: {
|
|
@@ -1094,7 +1832,7 @@ function parseChoicesArgs(args) {
|
|
|
1094
1832
|
var REQUEST_CONFIRMATION_TOOL = "request_confirmation";
|
|
1095
1833
|
var CONFIRMATION_TOOL = {
|
|
1096
1834
|
name: REQUEST_CONFIRMATION_TOOL,
|
|
1097
|
-
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.",
|
|
1098
1836
|
inputSchema: {
|
|
1099
1837
|
type: "object",
|
|
1100
1838
|
properties: {
|
|
@@ -1269,6 +2007,80 @@ async function executeChatInteractiveTool(name, args, callId, signal) {
|
|
|
1269
2007
|
function shouldTerminateTurnAfterTool(name) {
|
|
1270
2008
|
return isPostResponseChatTool(name);
|
|
1271
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
|
+
}
|
|
1272
2084
|
// src/core/chat-history.ts
|
|
1273
2085
|
var DEFAULT_HISTORY_KEY = "assistant-chat-history";
|
|
1274
2086
|
var DEFAULT_MAX_STORED = 100;
|
|
@@ -1341,6 +2153,283 @@ function createChatHistoryHelpers(options) {
|
|
|
1341
2153
|
}
|
|
1342
2154
|
return { getStored, persist, clear, loadInitial };
|
|
1343
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
|
+
}
|
|
1344
2433
|
// ../../node_modules/.bun/zustand@5.0.14+93dbe784b8baa420/node_modules/zustand/esm/vanilla.mjs
|
|
1345
2434
|
var createStoreImpl = (createState) => {
|
|
1346
2435
|
let state;
|
|
@@ -1366,11 +2455,11 @@ var createStoreImpl = (createState) => {
|
|
|
1366
2455
|
var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
|
|
1367
2456
|
|
|
1368
2457
|
// ../../node_modules/.bun/zustand@5.0.14+93dbe784b8baa420/node_modules/zustand/esm/react.mjs
|
|
1369
|
-
|
|
2458
|
+
import React from "react";
|
|
1370
2459
|
var identity = (arg) => arg;
|
|
1371
2460
|
function useStore(api, selector = identity) {
|
|
1372
|
-
const slice =
|
|
1373
|
-
|
|
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);
|
|
1374
2463
|
return slice;
|
|
1375
2464
|
}
|
|
1376
2465
|
var createImpl = (createState) => {
|
|
@@ -1509,7 +2598,20 @@ var DISABLED_SETTINGS = {
|
|
|
1509
2598
|
apiKey: null,
|
|
1510
2599
|
model: DEFAULT_LLM_MODEL
|
|
1511
2600
|
};
|
|
2601
|
+
var GLOBAL_RESOLVER_KEY = Symbol.for("@4djs/assistant/llm-resolver");
|
|
1512
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
|
+
}
|
|
1513
2615
|
function normalizeSettings(input) {
|
|
1514
2616
|
return {
|
|
1515
2617
|
enabled: input.enabled,
|
|
@@ -1522,19 +2624,20 @@ function normalizeSettings(input) {
|
|
|
1522
2624
|
}
|
|
1523
2625
|
function configureAssistantLlm(config) {
|
|
1524
2626
|
if (typeof config === "function") {
|
|
1525
|
-
|
|
2627
|
+
setSharedResolver(async () => normalizeSettings(await config()));
|
|
1526
2628
|
return;
|
|
1527
2629
|
}
|
|
1528
2630
|
const settings = normalizeSettings(config);
|
|
1529
|
-
|
|
2631
|
+
setSharedResolver(async () => settings);
|
|
1530
2632
|
}
|
|
1531
2633
|
async function resolveAssistantLlmSettings() {
|
|
1532
|
-
|
|
2634
|
+
const resolver = resolveSettings ?? getGlobalResolver();
|
|
2635
|
+
if (!resolver)
|
|
1533
2636
|
return DISABLED_SETTINGS;
|
|
1534
|
-
return
|
|
2637
|
+
return resolver();
|
|
1535
2638
|
}
|
|
1536
2639
|
function resetAssistantLlm() {
|
|
1537
|
-
|
|
2640
|
+
setSharedResolver(null);
|
|
1538
2641
|
}
|
|
1539
2642
|
async function testLlmConnection(settings) {
|
|
1540
2643
|
if (!settings.apiKey?.trim() && !isLocalLlmBaseUrl(settings.baseUrl)) {
|
|
@@ -1612,15 +2715,15 @@ function createStreamParser() {
|
|
|
1612
2715
|
done: true
|
|
1613
2716
|
};
|
|
1614
2717
|
}
|
|
1615
|
-
let
|
|
2718
|
+
let json2;
|
|
1616
2719
|
try {
|
|
1617
|
-
|
|
2720
|
+
json2 = JSON.parse(data);
|
|
1618
2721
|
} catch {
|
|
1619
2722
|
return null;
|
|
1620
2723
|
}
|
|
1621
|
-
if (typeof
|
|
1622
|
-
model =
|
|
1623
|
-
const choice =
|
|
2724
|
+
if (typeof json2.model === "string")
|
|
2725
|
+
model = json2.model;
|
|
2726
|
+
const choice = json2.choices?.[0];
|
|
1624
2727
|
const delta = choice?.delta;
|
|
1625
2728
|
if (!delta)
|
|
1626
2729
|
return null;
|
|
@@ -1712,6 +2815,48 @@ async function readSseStream(body, onChunk, signal) {
|
|
|
1712
2815
|
return { ...last, done: true };
|
|
1713
2816
|
}
|
|
1714
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
|
+
|
|
1715
2860
|
// src/core/llm-chat.ts
|
|
1716
2861
|
var MAX_AGENT_STEPS = 8;
|
|
1717
2862
|
var DEFAULT_SYSTEM_PROMPT = "You are a helpful assistant with access to tools. Use tools when they help answer the user.";
|
|
@@ -1834,12 +2979,16 @@ async function runLlmAgent(input) {
|
|
|
1834
2979
|
{ role: "user", content: input.userMessage }
|
|
1835
2980
|
];
|
|
1836
2981
|
let lastToolResult;
|
|
2982
|
+
const registryToolNames = input.tools.map((tool) => tool.name);
|
|
2983
|
+
const interactiveGate = createInteractiveAgentGate();
|
|
1837
2984
|
const clientTools = [
|
|
1838
2985
|
...input.tools.map(toClientTool),
|
|
1839
2986
|
...getChatInteractiveTools()
|
|
1840
2987
|
];
|
|
1841
2988
|
let finalContent = "";
|
|
1842
2989
|
let endedWithPostResponseTool = false;
|
|
2990
|
+
const settings = await resolveAssistantLlmSettings();
|
|
2991
|
+
const systemPrompt = buildSystemPromptWithTools(settings.systemPrompt ?? DEFAULT_SYSTEM_PROMPT, input.tools);
|
|
1843
2992
|
for (let step = 0;step < MAX_AGENT_STEPS; step++) {
|
|
1844
2993
|
if (input.signal?.aborted) {
|
|
1845
2994
|
throw new ChatAbortedError;
|
|
@@ -1848,6 +2997,7 @@ async function runLlmAgent(input) {
|
|
|
1848
2997
|
messages: apiMessages,
|
|
1849
2998
|
tools: clientTools,
|
|
1850
2999
|
model: input.model,
|
|
3000
|
+
systemPrompt,
|
|
1851
3001
|
signal: input.signal,
|
|
1852
3002
|
stream: input.stream ? {
|
|
1853
3003
|
turnId: input.stream.turnId,
|
|
@@ -1874,10 +3024,11 @@ async function runLlmAgent(input) {
|
|
|
1874
3024
|
let terminatesTurn = false;
|
|
1875
3025
|
for (const call of completion.toolCalls) {
|
|
1876
3026
|
const args = parseToolArguments(call.function.arguments);
|
|
3027
|
+
const toolName = fromLlmToolName(call.function.name, registryToolNames);
|
|
1877
3028
|
const stepId = crypto.randomUUID();
|
|
1878
3029
|
input.toolHandlers?.onStart({
|
|
1879
3030
|
id: stepId,
|
|
1880
|
-
name:
|
|
3031
|
+
name: toolName,
|
|
1881
3032
|
args,
|
|
1882
3033
|
callId: call.id
|
|
1883
3034
|
});
|
|
@@ -1885,15 +3036,24 @@ async function runLlmAgent(input) {
|
|
|
1885
3036
|
let finishUpdate;
|
|
1886
3037
|
if (isChatUiTool(call.function.name)) {
|
|
1887
3038
|
try {
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
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
|
+
}
|
|
1897
3057
|
}
|
|
1898
3058
|
} catch (error) {
|
|
1899
3059
|
if (input.signal?.aborted || error instanceof DOMException && error.name === "AbortError") {
|
|
@@ -1904,7 +3064,8 @@ async function runLlmAgent(input) {
|
|
|
1904
3064
|
finishUpdate = { status: "error", error: message };
|
|
1905
3065
|
}
|
|
1906
3066
|
} else {
|
|
1907
|
-
|
|
3067
|
+
recordRegistryToolCall(interactiveGate);
|
|
3068
|
+
const result = await input.invokeTool(toolName, args);
|
|
1908
3069
|
lastToolResult = result;
|
|
1909
3070
|
toolContent = formatToolResult(result);
|
|
1910
3071
|
finishUpdate = {
|
|
@@ -1929,12 +3090,19 @@ async function runLlmAgent(input) {
|
|
|
1929
3090
|
endedWithPostResponseTool = true;
|
|
1930
3091
|
break;
|
|
1931
3092
|
}
|
|
3093
|
+
if (shouldInjectActionNudge(interactiveGate)) {
|
|
3094
|
+
apiMessages.push({
|
|
3095
|
+
role: "system",
|
|
3096
|
+
content: actionToolNudgeMessage()
|
|
3097
|
+
});
|
|
3098
|
+
}
|
|
1932
3099
|
}
|
|
1933
3100
|
if (!endedWithPostResponseTool && apiMessages.at(-1)?.role === "tool") {
|
|
1934
3101
|
const completion = await requestLlmCompletion({
|
|
1935
3102
|
messages: apiMessages,
|
|
1936
3103
|
tools: clientTools,
|
|
1937
3104
|
model: input.model,
|
|
3105
|
+
systemPrompt,
|
|
1938
3106
|
signal: input.signal,
|
|
1939
3107
|
stream: input.stream ? {
|
|
1940
3108
|
turnId: input.stream.turnId,
|
|
@@ -2026,7 +3194,7 @@ function buildLlmHistory(messages) {
|
|
|
2026
3194
|
id: `call_${baseId}_${index}`,
|
|
2027
3195
|
type: "function",
|
|
2028
3196
|
function: {
|
|
2029
|
-
name: step.name,
|
|
3197
|
+
name: toLlmToolName(step.name),
|
|
2030
3198
|
arguments: JSON.stringify(step.args)
|
|
2031
3199
|
}
|
|
2032
3200
|
}));
|
|
@@ -2054,7 +3222,7 @@ function buildLlmHistory(messages) {
|
|
|
2054
3222
|
id,
|
|
2055
3223
|
type: "function",
|
|
2056
3224
|
function: {
|
|
2057
|
-
name: msg.toolCall.name,
|
|
3225
|
+
name: toLlmToolName(msg.toolCall.name),
|
|
2058
3226
|
arguments: JSON.stringify(msg.toolCall.args)
|
|
2059
3227
|
}
|
|
2060
3228
|
}
|
|
@@ -2117,7 +3285,7 @@ function upstreamError(body, status) {
|
|
|
2117
3285
|
}
|
|
2118
3286
|
function toClientTool(tool) {
|
|
2119
3287
|
return {
|
|
2120
|
-
name: tool.name,
|
|
3288
|
+
name: toLlmToolName(tool.name),
|
|
2121
3289
|
description: tool.description,
|
|
2122
3290
|
inputSchema: tool.inputSchema
|
|
2123
3291
|
};
|
|
@@ -2422,7 +3590,21 @@ function finalizeErroredMessages(messages, errorMessage) {
|
|
|
2422
3590
|
function clearReplySuggestions(messages) {
|
|
2423
3591
|
return messages.map((message) => message.replySuggestions ? { ...message, replySuggestions: undefined } : message);
|
|
2424
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
|
+
}
|
|
2425
3606
|
function createAssistantStore(deps) {
|
|
3607
|
+
const resolvedDeps = resolveAssistantStoreDependencies(deps);
|
|
2426
3608
|
const historyKey = deps.storageKeys?.history ?? "assistant-chat-history";
|
|
2427
3609
|
const llmSettingsKey = deps.storageKeys?.llmSettings ?? "assistant-llm-settings";
|
|
2428
3610
|
const llmSettingsStorage = createLlmSettingsStorage(llmSettingsKey);
|
|
@@ -2456,7 +3638,7 @@ function createAssistantStore(deps) {
|
|
|
2456
3638
|
});
|
|
2457
3639
|
const store = create((set, get) => {
|
|
2458
3640
|
async function runLlmChatTurn(message) {
|
|
2459
|
-
const tools = await
|
|
3641
|
+
const tools = await resolvedDeps.listTools();
|
|
2460
3642
|
const storedMessages = get().messages.filter((m) => m.id !== "welcome");
|
|
2461
3643
|
const priorMessages = storedMessages.at(-1)?.role === "user" ? storedMessages.slice(0, -1) : storedMessages;
|
|
2462
3644
|
const llmHistory = buildLlmHistory(priorMessages);
|
|
@@ -2513,7 +3695,7 @@ function createAssistantStore(deps) {
|
|
|
2513
3695
|
}));
|
|
2514
3696
|
},
|
|
2515
3697
|
invokeTool: async (name, args) => {
|
|
2516
|
-
const result = await
|
|
3698
|
+
const result = await resolvedDeps.invokeTool(name, args);
|
|
2517
3699
|
deps.onToolInvoked?.(result);
|
|
2518
3700
|
return result;
|
|
2519
3701
|
}
|
|
@@ -2796,7 +3978,9 @@ function parseSuggestedPromptsResponse(data) {
|
|
|
2796
3978
|
return prompts.slice(0, 6);
|
|
2797
3979
|
}
|
|
2798
3980
|
// src/core/markdown-utils.ts
|
|
2799
|
-
|
|
3981
|
+
function isReactElement(value) {
|
|
3982
|
+
return typeof value === "object" && value !== null && "props" in value && typeof value.props === "object";
|
|
3983
|
+
}
|
|
2800
3984
|
function childrenToText(children) {
|
|
2801
3985
|
if (typeof children === "string")
|
|
2802
3986
|
return children;
|
|
@@ -2804,13 +3988,125 @@ function childrenToText(children) {
|
|
|
2804
3988
|
return String(children);
|
|
2805
3989
|
if (Array.isArray(children))
|
|
2806
3990
|
return children.map(childrenToText).join("");
|
|
2807
|
-
if (
|
|
3991
|
+
if (isReactElement(children)) {
|
|
2808
3992
|
return childrenToText(children.props.children);
|
|
2809
3993
|
}
|
|
2810
3994
|
return "";
|
|
2811
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
|
+
}
|
|
2812
4105
|
export {
|
|
4106
|
+
toolResultOk,
|
|
4107
|
+
toolResultErr,
|
|
2813
4108
|
toStoredSettings,
|
|
4109
|
+
toLlmToolName,
|
|
2814
4110
|
testLlmConnection,
|
|
2815
4111
|
summarizeActivityResult,
|
|
2816
4112
|
storedToAssistant,
|
|
@@ -2821,10 +4117,14 @@ export {
|
|
|
2821
4117
|
runAssistantChatCommand,
|
|
2822
4118
|
resolveSelectedModel,
|
|
2823
4119
|
resolveInteractiveToolResult,
|
|
4120
|
+
resolveAssistantToolHooks,
|
|
4121
|
+
resolveAssistantStoreDependencies,
|
|
2824
4122
|
resolveAssistantLlmSettings,
|
|
4123
|
+
resolveAssistantLabels,
|
|
2825
4124
|
resetAssistantLlm,
|
|
2826
4125
|
requestLlmCompletion,
|
|
2827
4126
|
rejectAllInteractiveToolWaiters,
|
|
4127
|
+
prepareMarkdown,
|
|
2828
4128
|
persistStoredModelSelection,
|
|
2829
4129
|
peekStoredModel,
|
|
2830
4130
|
parseSuggestedPromptsResponse,
|
|
@@ -2832,6 +4132,7 @@ export {
|
|
|
2832
4132
|
parseChatCommand,
|
|
2833
4133
|
normalizeStoredSystemPrompt,
|
|
2834
4134
|
normalizeStoredSettings,
|
|
4135
|
+
normalizeCodeLineEndings,
|
|
2835
4136
|
migrateLegacyModelStorage,
|
|
2836
4137
|
mergeLlmSettings,
|
|
2837
4138
|
listChatCommands,
|
|
@@ -2840,9 +4141,12 @@ export {
|
|
|
2840
4141
|
isLlmSettingsFormDirty,
|
|
2841
4142
|
isLlmConfigured,
|
|
2842
4143
|
isChatCommandInput,
|
|
4144
|
+
highlightCode,
|
|
2843
4145
|
getFallbackModels,
|
|
2844
4146
|
getChatCommandSuggestions,
|
|
4147
|
+
fromLlmToolName,
|
|
2845
4148
|
formatModelsText,
|
|
4149
|
+
formatLabel,
|
|
2846
4150
|
formatJsonIfLarge,
|
|
2847
4151
|
filterChatCommands,
|
|
2848
4152
|
fetchProviderModels,
|
|
@@ -2852,11 +4156,15 @@ export {
|
|
|
2852
4156
|
createLlmSettingsFormState,
|
|
2853
4157
|
createDefaultStoredSettings,
|
|
2854
4158
|
createChatHistoryHelpers,
|
|
4159
|
+
createAssistantToolRegistry,
|
|
2855
4160
|
createAssistantStore,
|
|
4161
|
+
connectExternalTools,
|
|
2856
4162
|
configureAssistantLlm,
|
|
4163
|
+
completionForChatCommand,
|
|
2857
4164
|
clearProviderModelCache,
|
|
2858
4165
|
childrenToText,
|
|
2859
4166
|
chatActivityStepLabel,
|
|
4167
|
+
buildSystemPromptWithTools,
|
|
2860
4168
|
buildModelsUrl,
|
|
2861
4169
|
buildLlmRequestHeaders,
|
|
2862
4170
|
buildLlmHistory,
|
|
@@ -2870,7 +4178,9 @@ export {
|
|
|
2870
4178
|
DEFAULT_LLM_SETTINGS_STORAGE_KEY,
|
|
2871
4179
|
DEFAULT_LLM_MODEL,
|
|
2872
4180
|
DEFAULT_LLM_BASE_URL,
|
|
4181
|
+
DEFAULT_ASSISTANT_LABELS,
|
|
2873
4182
|
ChatAbortedError,
|
|
2874
4183
|
CONFIRMATION_TOOL,
|
|
2875
|
-
CHOICES_TOOL
|
|
4184
|
+
CHOICES_TOOL,
|
|
4185
|
+
ASSISTANT_LABEL_KEYS
|
|
2876
4186
|
};
|