@bastani/atomic 0.9.55-alpha.1 → 0.9.56-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/dist/builtin/intercom/CHANGELOG.md +12 -0
- package/dist/builtin/intercom/index.bundle.mjs +2 -1
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +4 -3
- package/dist/cli/args.js.map +1 -1
- package/dist/config-self-update.d.ts +1 -0
- package/dist/config-self-update.d.ts.map +1 -1
- package/dist/config-self-update.js +7 -7
- package/dist/config-self-update.js.map +1 -1
- package/dist/config.d.ts +13 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +23 -1
- package/dist/config.js.map +1 -1
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js +3 -0
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/message-types.d.ts +3 -2
- package/dist/core/extensions/message-types.d.ts.map +1 -1
- package/dist/core/extensions/message-types.js.map +1 -1
- package/dist/core/extensions/tool-types.d.ts +2 -1
- package/dist/core/extensions/tool-types.d.ts.map +1 -1
- package/dist/core/extensions/tool-types.js.map +1 -1
- package/dist/core/extensions/ui-types.d.ts +12 -1
- package/dist/core/extensions/ui-types.d.ts.map +1 -1
- package/dist/core/extensions/ui-types.js.map +1 -1
- package/dist/core/settings-schema.d.ts +1 -0
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +4 -0
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/slash-commands.js +1 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/extensions/mcp/cli.d.ts.map +1 -1
- package/dist/extensions/mcp/cli.js +27 -8
- package/dist/extensions/mcp/cli.js.map +1 -1
- package/dist/extensions/tool-search/tool.d.ts +21 -3
- package/dist/extensions/tool-search/tool.d.ts.map +1 -1
- package/dist/extensions/tool-search/tool.js +88 -35
- package/dist/extensions/tool-search/tool.js.map +1 -1
- package/dist/index-extensions.d.ts +1 -1
- package/dist/index-extensions.d.ts.map +1 -1
- package/dist/index-extensions.js.map +1 -1
- package/dist/modes/interactive/chat-input-actions.d.ts +2 -0
- package/dist/modes/interactive/chat-input-actions.d.ts.map +1 -1
- package/dist/modes/interactive/chat-input-actions.js +4 -1
- package/dist/modes/interactive/chat-input-actions.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-editor.js +1 -0
- package/dist/modes/interactive/components/chat-session-host-editor.js.map +1 -1
- package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-entry.js +2 -1
- package/dist/modes/interactive/components/custom-entry.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +2 -1
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/extension-editor.d.ts +2 -0
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +4 -0
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +3 -1
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts +1 -0
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +15 -5
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/interactive-editor-actions.js +1 -0
- package/dist/modes/interactive/interactive-editor-actions.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +46 -2
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +2 -0
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +10 -0
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/open-browser.d.ts.map +1 -1
- package/dist/utils/open-browser.js +3 -1
- package/dist/utils/open-browser.js.map +1 -1
- package/docs/environment-variables.md +1 -0
- package/docs/extensions/authoring.md +10 -11
- package/docs/extensions/ui.md +2 -0
- package/docs/mcp-servers.md +3 -3
- package/docs/reference/cli.md +15 -3
- package/docs/sessions.md +10 -0
- package/docs/settings.md +1 -0
- package/examples/extensions/debug-provider.ts +2 -2
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
- package/schemas/settings.schema.json +8 -0
|
@@ -2,6 +2,7 @@ import { Type } from "typebox";
|
|
|
2
2
|
import { createMcpToolName } from "../mcp/tools.js";
|
|
3
3
|
export const TOOL_SEARCH_TOOL_NAME = "tool_search";
|
|
4
4
|
export const DEFAULT_TOOL_SEARCH_LIMIT = 8;
|
|
5
|
+
const wordSegmenter = new Intl.Segmenter(undefined, { granularity: "word" });
|
|
5
6
|
const STOP_WORDS = new Set([
|
|
6
7
|
"a",
|
|
7
8
|
"an",
|
|
@@ -34,14 +35,22 @@ function stem(term) {
|
|
|
34
35
|
return term.slice(0, -1);
|
|
35
36
|
return term;
|
|
36
37
|
}
|
|
38
|
+
/** Unicode word segmentation with identifier boundaries and English stop words and singular forms. */
|
|
37
39
|
export function tokenize(text) {
|
|
38
|
-
|
|
40
|
+
const normalized = text
|
|
41
|
+
.normalize("NFC")
|
|
39
42
|
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
40
43
|
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2")
|
|
41
44
|
.toLowerCase()
|
|
42
|
-
.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
.replace(/[^\p{L}\p{M}\p{N}]+/gu, " ");
|
|
46
|
+
// The segmenter costs about 15 times a split. Plain ASCII splits into the same words at spaces, so only other
|
|
47
|
+
// text, such as Chinese written without spaces, goes through it.
|
|
48
|
+
const words = /^[a-z0-9 ]*$/.test(normalized)
|
|
49
|
+
? normalized.split(" ")
|
|
50
|
+
: Array.from(wordSegmenter.segment(normalized), (segment) => (segment.isWordLike ? segment.segment : ""));
|
|
51
|
+
return words
|
|
52
|
+
.filter((word) => word.length > 0 && !STOP_WORDS.has(word))
|
|
53
|
+
.map((word) => (/^[a-z0-9]+$/.test(word) ? stem(word) : word));
|
|
45
54
|
}
|
|
46
55
|
function isObject(value) {
|
|
47
56
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -62,12 +71,17 @@ function schemaText(schema, parts) {
|
|
|
62
71
|
for (const variant of schema[key])
|
|
63
72
|
schemaText(variant, parts);
|
|
64
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Search text of a tool: the description and the schema descriptions and property names, and
|
|
76
|
+
* separately the namespace name, description, and instructions. The ranker reads the name from `name`.
|
|
77
|
+
*/
|
|
65
78
|
export function createToolSearchDocument(tool, namespace) {
|
|
66
|
-
const parts = [tool.
|
|
79
|
+
const parts = [tool.description];
|
|
67
80
|
schemaText(tool.parameters, parts);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
81
|
+
const namespaceText = namespace
|
|
82
|
+
? [namespace.name, namespace.description ?? "", namespace.instructions ?? ""].join(" ")
|
|
83
|
+
: "";
|
|
84
|
+
return { name: tool.name, text: parts.filter((part) => part.trim()).join(" "), namespaceText };
|
|
71
85
|
}
|
|
72
86
|
/** Lowercase with characters invalid in script identifiers as `_`, so `dev-radius` matches `dev_radius`. */
|
|
73
87
|
function normalizeName(name) {
|
|
@@ -120,10 +134,44 @@ export function resolveToolNames(query, names) {
|
|
|
120
134
|
const full = names.filter((name) => forms.has(normalizeName(name)));
|
|
121
135
|
return full.length ? full : names.filter((name) => isNameQuery(query, name));
|
|
122
136
|
}
|
|
137
|
+
function indexDocument(document) {
|
|
138
|
+
const textCounts = new Map();
|
|
139
|
+
for (const term of tokenize(document.text))
|
|
140
|
+
textCounts.set(term, (textCounts.get(term) ?? 0) + 1);
|
|
141
|
+
const segments = document.name.split("__");
|
|
142
|
+
return {
|
|
143
|
+
name: document.name,
|
|
144
|
+
nameTerms: new Set(tokenize(document.name)),
|
|
145
|
+
localNameTerms: [...new Set(tokenize(segments[segments.length - 1]))],
|
|
146
|
+
textCounts,
|
|
147
|
+
textLength: [...textCounts.values()].reduce((sum, count) => sum + count, 0),
|
|
148
|
+
namespaceTerms: new Set(tokenize(document.namespaceText ?? "")),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
123
151
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
152
|
+
* A query term in the name counts this many times its IDF. The text part of a term is at most
|
|
153
|
+
* `k1 + 1` (2.2) times its IDF and about 1 for a single mention, so a name match beats any number of
|
|
154
|
+
* mentions in the description.
|
|
155
|
+
*/
|
|
156
|
+
const NAME_WEIGHT = 3;
|
|
157
|
+
/**
|
|
158
|
+
* A query term in the namespace name, description, or instructions counts this many times its IDF. They
|
|
159
|
+
* are shared by every tool of the server, so they help find the server but not the tool in it.
|
|
160
|
+
*/
|
|
161
|
+
const NAMESPACE_WEIGHT = 0.5;
|
|
162
|
+
/**
|
|
163
|
+
* Okapi BM25 over the description, with the name and the namespace as separate fields:
|
|
164
|
+
* - a query that names a tool (see {@link isNameQuery}) ranks that tool first, before coverage;
|
|
165
|
+
* - a tool that matches more of the query's terms, in any field, ranks above one that matches
|
|
166
|
+
* fewer, whatever their scores: for `screenshot window`, a tool whose description has both words
|
|
167
|
+
* beats `window`, whose name has one;
|
|
168
|
+
* - a query term in the name scores more than any number of mentions in the description;
|
|
169
|
+
* - a tool whose whole local name is in the query (`app` in `peekaboo app` for
|
|
170
|
+
* `mcp__peekaboo__app`) gets a bonus worth one more match of every query term, so among tools
|
|
171
|
+
* matching as many terms it mostly wins over tools that only mention the words.
|
|
172
|
+
*
|
|
173
|
+
* The description alone is length-normalized, so a long name or long namespace instructions do
|
|
174
|
+
* not lower a tool's score. Ties keep document order.
|
|
127
175
|
*/
|
|
128
176
|
export class Bm25Ranker {
|
|
129
177
|
k1;
|
|
@@ -135,42 +183,47 @@ export class Bm25Ranker {
|
|
|
135
183
|
rank(query, documents, limit) {
|
|
136
184
|
if (!documents.length || limit <= 0)
|
|
137
185
|
return [];
|
|
138
|
-
const
|
|
186
|
+
const queryTerms = new Set(tokenize(query));
|
|
139
187
|
// A query made only of stop words has no BM25 terms, but can still name a tool exactly (`is`).
|
|
140
|
-
if (
|
|
188
|
+
if (queryTerms.size === 0) {
|
|
141
189
|
return documents
|
|
142
190
|
.filter((document) => isNameQuery(query, document.name))
|
|
143
191
|
.slice(0, limit)
|
|
144
192
|
.map((document) => ({ name: document.name, score: 0 }));
|
|
145
193
|
}
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return
|
|
151
|
-
});
|
|
152
|
-
const lengths = counts.map((count) => [...count.values()].reduce((sum, value) => sum + value, 0));
|
|
153
|
-
const average = lengths.reduce((sum, value) => sum + value, 0) / documents.length || 1;
|
|
154
|
-
const idf = new Map(terms.map((term) => {
|
|
155
|
-
const frequency = counts.filter((count) => count.has(term)).length;
|
|
156
|
-
return [term, Math.log(1 + (documents.length - frequency + 0.5) / (frequency + 0.5))];
|
|
194
|
+
const indexed = documents.map(indexDocument);
|
|
195
|
+
const averageLength = indexed.reduce((sum, document) => sum + document.textLength, 0) / indexed.length || 1;
|
|
196
|
+
const idf = new Map([...queryTerms].map((term) => {
|
|
197
|
+
const frequency = indexed.filter((document) => document.nameTerms.has(term) || document.textCounts.has(term) || document.namespaceTerms.has(term)).length;
|
|
198
|
+
return [term, Math.log(1 + (indexed.length - frequency + 0.5) / (frequency + 0.5))];
|
|
157
199
|
}));
|
|
158
|
-
|
|
159
|
-
|
|
200
|
+
const fullNameBonus = [...idf.values()].reduce((sum, value) => sum + value, 0);
|
|
201
|
+
const matches = [];
|
|
202
|
+
for (const document of indexed) {
|
|
203
|
+
const norm = this.k1 * (1 - this.b + (this.b * document.textLength) / averageLength);
|
|
160
204
|
let score = 0;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
205
|
+
let covered = 0;
|
|
206
|
+
for (const term of queryTerms) {
|
|
207
|
+
const count = document.textCounts.get(term) ?? 0;
|
|
208
|
+
const weight = (document.nameTerms.has(term) ? NAME_WEIGHT : 0) +
|
|
209
|
+
(document.namespaceTerms.has(term) ? NAMESPACE_WEIGHT : 0) +
|
|
210
|
+
(count * (this.k1 + 1)) / (count + norm);
|
|
211
|
+
if (weight > 0)
|
|
212
|
+
covered++;
|
|
213
|
+
score += (idf.get(term) ?? 0) * weight;
|
|
167
214
|
}
|
|
168
215
|
// A query naming the tool keeps it even when tokenization shares no term with it (`readthread`
|
|
169
216
|
// for `readThread`).
|
|
170
217
|
const named = isNameQuery(query, document.name);
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
218
|
+
if (score === 0 && !named)
|
|
219
|
+
continue;
|
|
220
|
+
const local = document.localNameTerms;
|
|
221
|
+
if (score > 0 && local.length > 0 && local.every((term) => queryTerms.has(term)))
|
|
222
|
+
score += fullNameBonus;
|
|
223
|
+
matches.push({ name: document.name, score, covered, named });
|
|
224
|
+
}
|
|
225
|
+
return matches
|
|
226
|
+
.sort((a, b) => Number(b.named) - Number(a.named) || b.covered - a.covered || b.score - a.score)
|
|
174
227
|
.slice(0, limit)
|
|
175
228
|
.map(({ name, score }) => ({ name, score }));
|
|
176
229
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../src/extens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AAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACtG,OAAO;gBACN,OAAO,EAAE;oBACR;wBACC,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,OAAO,CAAC,MAAM;4BACnB,CAAC,CAAC,qCAAqC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,EAAE,WAAW,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;4BACxK,CAAC,CAAC,0BAA0B;qBAC7B;iBACD;gBACD,OAAO,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;aACvD,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { ExtensionAPI, ToolDefinition, ToolInfo, ToolNamespace } from \"../../core/extensions/types.ts\";\nimport { createMcpToolName } from \"../mcp/tools.ts\";\n\nexport const TOOL_SEARCH_TOOL_NAME = \"tool_search\";\nexport const DEFAULT_TOOL_SEARCH_LIMIT = 8;\nexport interface ToolSearchDocument {\n\tname: string;\n\ttext: string;\n}\nexport interface ToolSearchMatch {\n\tname: string;\n\tscore: number;\n}\nexport interface ToolRanker {\n\trank(query: string, documents: readonly ToolSearchDocument[], limit: number): ToolSearchMatch[];\n}\nconst STOP_WORDS = new Set([\n\t\"a\",\n\t\"an\",\n\t\"and\",\n\t\"are\",\n\t\"as\",\n\t\"at\",\n\t\"be\",\n\t\"by\",\n\t\"for\",\n\t\"from\",\n\t\"in\",\n\t\"is\",\n\t\"it\",\n\t\"of\",\n\t\"on\",\n\t\"or\",\n\t\"that\",\n\t\"the\",\n\t\"this\",\n\t\"to\",\n\t\"with\",\n]);\nfunction stem(term: string): string {\n\tif (term.length > 4 && term.endsWith(\"ies\")) return `${term.slice(0, -3)}y`;\n\tif (term.length > 4 && /(ches|shes|sses|xes|zes)$/.test(term)) return term.slice(0, -2);\n\tif (term.length > 3 && term.endsWith(\"s\") && !term.endsWith(\"ss\")) return term.slice(0, -1);\n\treturn term;\n}\nexport function tokenize(text: string): string[] {\n\treturn text\n\t\t.replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n\t\t.replace(/([A-Z]+)([A-Z][a-z])/g, \"$1 $2\")\n\t\t.toLowerCase()\n\t\t.split(/[^a-z0-9]+/)\n\t\t.filter((term) => term.length > 0 && !STOP_WORDS.has(term))\n\t\t.map(stem);\n}\nfunction isObject(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\nfunction schemaText(schema: unknown, parts: string[]): void {\n\tif (!isObject(schema)) return;\n\tif (typeof schema.description === \"string\") parts.push(schema.description);\n\tif (isObject(schema.properties))\n\t\tfor (const [name, property] of Object.entries(schema.properties)) {\n\t\t\tparts.push(name);\n\t\t\tschemaText(property, parts);\n\t\t}\n\tschemaText(schema.items, parts);\n\tfor (const key of [\"anyOf\", \"oneOf\", \"allOf\"])\n\t\tif (Array.isArray(schema[key])) for (const variant of schema[key]) schemaText(variant, parts);\n}\nexport function createToolSearchDocument(\n\ttool: Pick<ToolInfo, \"name\" | \"description\" | \"parameters\">,\n\tnamespace?: ToolNamespace,\n): ToolSearchDocument {\n\tconst parts = [tool.name, tool.name.replaceAll(\"_\", \" \"), tool.description];\n\tschemaText(tool.parameters, parts);\n\tif (namespace) parts.push(namespace.name, namespace.description ?? \"\", namespace.instructions ?? \"\");\n\treturn { name: tool.name, text: parts.filter((part) => part.trim()).join(\" \") };\n}\n/** Lowercase with characters invalid in script identifiers as `_`, so `dev-radius` matches `dev_radius`. */\nfunction normalizeName(name: string): string {\n\treturn name\n\t\t.trim()\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9_$]/g, \"_\");\n}\n/**\n * The normalized forms `query` can take for one tool name. MCP tools are registered as\n * `mcp__<server>__<tool>` with `-` and `.` sanitized to `_`, but skills and models also write the\n * dotted `mcp.<server>.<tool>` and the raw `mcp__alteryx-local__…` forms (#4065). In the dotted form\n * only the first two dots separate server and tool. The rest is a raw tool name, either as written\n * (`mcp.srv.get.item/v2` for the tool `get.item/v2`) or with its dots standing for `__`\n * (`mcp.alteryx-local.alteryx_local.get_server_info` for `alteryx_local__get_server_info`); each is\n * named the way registration names it, with `createMcpToolName`.\n */\nfunction nameQueryForms(query: string): Set<string> {\n\tconst trimmed = query.trim();\n\tconst dotted = /^mcp\\.([^.]+)\\.(.+)$/i.exec(trimmed);\n\tif (!dotted) return new Set([normalizeName(trimmed), normalizeName(trimmed.replaceAll(\".\", \"__\"))]);\n\tconst [, server, tool] = dotted;\n\treturn new Set([\n\t\tnormalizeName(trimmed),\n\t\tnormalizeName(createMcpToolName(server, tool)),\n\t\tnormalizeName(createMcpToolName(server, tool.replaceAll(\".\", \"__\"))),\n\t]);\n}\n/**\n * Whether `query` names the tool: its full name or a suffix after a `__` separator, so `thread_read`\n * and `app__thread_read` both name `mcp__app__thread_read`, and `mcp.app.thread_read` does too.\n */\nfunction isNameQuery(query: string, name: string): boolean {\n\tconst normalized = normalizeName(name);\n\tfor (const form of nameQueryForms(query)) if (normalized === form || normalized.endsWith(`__${form}`)) return true;\n\treturn false;\n}\n/**\n * The tool names `query` names, as {@link isNameQuery} matches them: the exact name when it is\n * registered, else every full-name match, else every `__` suffix match. More than one result is\n * ambiguous; callers must not pick one.\n */\nexport function resolveToolNames(query: string, names: readonly string[]): string[] {\n\tif (names.includes(query)) return [query];\n\tconst forms = nameQueryForms(query);\n\tconst full = names.filter((name) => forms.has(normalizeName(name)));\n\treturn full.length ? full : names.filter((name) => isNameQuery(query, name));\n}\n/**\n * Okapi BM25 with the usual parameters. A query that names a tool ranks that tool first, because\n * length normalization can otherwise rank a short description sharing the name's words above it.\n * Ties keep document order.\n */\nexport class Bm25Ranker implements ToolRanker {\n\tprivate readonly k1: number;\n\tprivate readonly b: number;\n\tconstructor(options: { k1?: number; b?: number } = {}) {\n\t\tthis.k1 = options.k1 ?? 1.2;\n\t\tthis.b = options.b ?? 0.75;\n\t}\n\trank(query: string, documents: readonly ToolSearchDocument[], limit: number): ToolSearchMatch[] {\n\t\tif (!documents.length || limit <= 0) return [];\n\t\tconst terms = [...new Set(tokenize(query))];\n\t\t// A query made only of stop words has no BM25 terms, but can still name a tool exactly (`is`).\n\t\tif (!terms.length) {\n\t\t\treturn documents\n\t\t\t\t.filter((document) => isNameQuery(query, document.name))\n\t\t\t\t.slice(0, limit)\n\t\t\t\t.map((document) => ({ name: document.name, score: 0 }));\n\t\t}\n\t\tconst counts = documents.map((document) => {\n\t\t\tconst result = new Map<string, number>();\n\t\t\tfor (const term of tokenize(document.text)) result.set(term, (result.get(term) ?? 0) + 1);\n\t\t\treturn result;\n\t\t});\n\t\tconst lengths = counts.map((count) => [...count.values()].reduce((sum, value) => sum + value, 0));\n\t\tconst average = lengths.reduce((sum, value) => sum + value, 0) / documents.length || 1;\n\t\tconst idf = new Map(\n\t\t\tterms.map((term) => {\n\t\t\t\tconst frequency = counts.filter((count) => count.has(term)).length;\n\t\t\t\treturn [term, Math.log(1 + (documents.length - frequency + 0.5) / (frequency + 0.5))];\n\t\t\t}),\n\t\t);\n\t\treturn documents\n\t\t\t.flatMap((document, index) => {\n\t\t\t\tlet score = 0;\n\t\t\t\tfor (const term of terms) {\n\t\t\t\t\tconst count = counts[index].get(term);\n\t\t\t\t\tif (!count) continue;\n\t\t\t\t\tconst norm = this.k1 * (1 - this.b + (this.b * lengths[index]) / average);\n\t\t\t\t\tscore += ((idf.get(term) ?? 0) * count * (this.k1 + 1)) / (count + norm);\n\t\t\t\t}\n\t\t\t\t// A query naming the tool keeps it even when tokenization shares no term with it (`readthread`\n\t\t\t\t// for `readThread`).\n\t\t\t\tconst named = isNameQuery(query, document.name);\n\t\t\t\treturn score > 0 || named ? [{ name: document.name, score, named }] : [];\n\t\t\t})\n\t\t\t.sort((a, b) => Number(b.named) - Number(a.named) || b.score - a.score)\n\t\t\t.slice(0, limit)\n\t\t\t.map(({ name, score }) => ({ name, score }));\n\t}\n}\nexport const toolSearchSchema = Type.Object({ query: Type.String(), limit: Type.Optional(Type.Number()) });\nexport type ToolSearchInput = Static<typeof toolSearchSchema>;\nexport interface ToolSearchToolDetails {\n\tloaded: string[];\n}\nexport interface ToolSearchToolOptions {\n\ttools?: Pick<ExtensionAPI, \"getAllTools\" | \"getActiveTools\" | \"setActiveTools\">;\n}\nexport function isToolSearchTool(tool: Pick<ToolInfo, \"name\" | \"parameters\">): boolean {\n\treturn tool.name === TOOL_SEARCH_TOOL_NAME && tool.parameters === toolSearchSchema;\n}\nexport function createToolSearchDescription(_sources: readonly ToolNamespace[] = []): string {\n\treturn \"Search deferred tool metadata with BM25 and load matching tools for the next model call. Some tools may not have been provided upfront; use tool_search to discover currently registered tools.\";\n}\nexport function createToolSearchToolDefinition(\n\toptions: ToolSearchToolOptions = {},\n): ToolDefinition<typeof toolSearchSchema, ToolSearchToolDetails> {\n\treturn {\n\t\tname: TOOL_SEARCH_TOOL_NAME,\n\t\tlabel: TOOL_SEARCH_TOOL_NAME,\n\t\tdescription: createToolSearchDescription(),\n\t\tparameters: toolSearchSchema,\n\t\texposure: \"model-only\",\n\t\tdefaultActive: false,\n\t\texecute: async (_id, { query, limit = DEFAULT_TOOL_SEARCH_LIMIT }) => {\n\t\t\tif (!query.trim()) throw new Error(\"query must not be empty\");\n\t\t\tif (!Number.isInteger(limit) || limit <= 0) throw new Error(\"limit must be a positive integer\");\n\t\t\tconst active = options.tools?.getActiveTools() ?? [];\n\t\t\tconst candidates =\n\t\t\t\toptions.tools\n\t\t\t\t\t?.getAllTools()\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t(tool) =>\n\t\t\t\t\t\t\t(tool.exposure === \"codemode\" || tool.exposure === \"deferred\") && !active.includes(tool.name),\n\t\t\t\t\t) ?? [];\n\t\t\tconst matches = new Bm25Ranker().rank(\n\t\t\t\tquery,\n\t\t\t\tcandidates.map((tool) => createToolSearchDocument(tool, tool.namespace)),\n\t\t\t\tlimit,\n\t\t\t);\n\t\t\tif (matches.length) options.tools?.setActiveTools([...active, ...matches.map((match) => match.name)]);\n\t\t\treturn {\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext: matches.length\n\t\t\t\t\t\t\t? `Loaded tools for your next call:\\n${matches.map((match) => `- ${match.name}: ${candidates.find((tool) => tool.name === match.name)?.description ?? \"\"}`).join(\"\\n\")}`\n\t\t\t\t\t\t\t: \"No matching tools found.\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdetails: { loaded: matches.map((match) => match.name) },\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../src/extensions/tool-search/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC;AACnD,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAgB3C,MAAM,aAAa,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;AAC7E,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IAC1B,GAAG;IACH,IAAI;IACJ,KAAK;IACL,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,MAAM;IACN,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,MA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AE,CAAC;YACV,MAAM,OAAO,GAAG,IAAI,UAAU,EAAE,CAAC,IAAI,CACpC,KAAK,EACL,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,wBAAwB,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EACxE,KAAK,CACL,CAAC;YACF,IAAI,OAAO,CAAC,MAAM;gBAAE,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACtG,OAAO;gBACN,OAAO,EAAE;oBACR;wBACC,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,OAAO,CAAC,MAAM;4BACnB,CAAC,CAAC,qCAAqC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,EAAE,WAAW,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;4BACxK,CAAC,CAAC,0BAA0B;qBAC7B;iBACD;gBACD,OAAO,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;aACvD,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { ExtensionAPI, ToolDefinition, ToolInfo, ToolNamespace } from \"../../core/extensions/types.ts\";\nimport { createMcpToolName } from \"../mcp/tools.ts\";\n\nexport const TOOL_SEARCH_TOOL_NAME = \"tool_search\";\nexport const DEFAULT_TOOL_SEARCH_LIMIT = 8;\n/** A tool as the ranker sees it: its name and the texts built by {@link createToolSearchDocument}. */\nexport interface ToolSearchDocument {\n\tname: string;\n\t/** Description, schema descriptions, and property names. */\n\ttext: string;\n\t/** Name, description, and instructions of the tool's namespace. */\n\tnamespaceText?: string;\n}\nexport interface ToolSearchMatch {\n\tname: string;\n\tscore: number;\n}\nexport interface ToolRanker {\n\trank(query: string, documents: readonly ToolSearchDocument[], limit: number): ToolSearchMatch[];\n}\nconst wordSegmenter = new Intl.Segmenter(undefined, { granularity: \"word\" });\nconst STOP_WORDS = new Set([\n\t\"a\",\n\t\"an\",\n\t\"and\",\n\t\"are\",\n\t\"as\",\n\t\"at\",\n\t\"be\",\n\t\"by\",\n\t\"for\",\n\t\"from\",\n\t\"in\",\n\t\"is\",\n\t\"it\",\n\t\"of\",\n\t\"on\",\n\t\"or\",\n\t\"that\",\n\t\"the\",\n\t\"this\",\n\t\"to\",\n\t\"with\",\n]);\nfunction stem(term: string): string {\n\tif (term.length > 4 && term.endsWith(\"ies\")) return `${term.slice(0, -3)}y`;\n\tif (term.length > 4 && /(ches|shes|sses|xes|zes)$/.test(term)) return term.slice(0, -2);\n\tif (term.length > 3 && term.endsWith(\"s\") && !term.endsWith(\"ss\")) return term.slice(0, -1);\n\treturn term;\n}\n/** Unicode word segmentation with identifier boundaries and English stop words and singular forms. */\nexport function tokenize(text: string): string[] {\n\tconst normalized = text\n\t\t.normalize(\"NFC\")\n\t\t.replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n\t\t.replace(/([A-Z]+)([A-Z][a-z])/g, \"$1 $2\")\n\t\t.toLowerCase()\n\t\t.replace(/[^\\p{L}\\p{M}\\p{N}]+/gu, \" \");\n\t// The segmenter costs about 15 times a split. Plain ASCII splits into the same words at spaces, so only other\n\t// text, such as Chinese written without spaces, goes through it.\n\tconst words = /^[a-z0-9 ]*$/.test(normalized)\n\t\t? normalized.split(\" \")\n\t\t: Array.from(wordSegmenter.segment(normalized), (segment) => (segment.isWordLike ? segment.segment : \"\"));\n\treturn words\n\t\t.filter((word) => word.length > 0 && !STOP_WORDS.has(word))\n\t\t.map((word) => (/^[a-z0-9]+$/.test(word) ? stem(word) : word));\n}\nfunction isObject(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\nfunction schemaText(schema: unknown, parts: string[]): void {\n\tif (!isObject(schema)) return;\n\tif (typeof schema.description === \"string\") parts.push(schema.description);\n\tif (isObject(schema.properties))\n\t\tfor (const [name, property] of Object.entries(schema.properties)) {\n\t\t\tparts.push(name);\n\t\t\tschemaText(property, parts);\n\t\t}\n\tschemaText(schema.items, parts);\n\tfor (const key of [\"anyOf\", \"oneOf\", \"allOf\"])\n\t\tif (Array.isArray(schema[key])) for (const variant of schema[key]) schemaText(variant, parts);\n}\n/**\n * Search text of a tool: the description and the schema descriptions and property names, and\n * separately the namespace name, description, and instructions. The ranker reads the name from `name`.\n */\nexport function createToolSearchDocument(\n\ttool: Pick<ToolInfo, \"name\" | \"description\" | \"parameters\">,\n\tnamespace?: ToolNamespace,\n): ToolSearchDocument {\n\tconst parts = [tool.description];\n\tschemaText(tool.parameters, parts);\n\tconst namespaceText = namespace\n\t\t? [namespace.name, namespace.description ?? \"\", namespace.instructions ?? \"\"].join(\" \")\n\t\t: \"\";\n\treturn { name: tool.name, text: parts.filter((part) => part.trim()).join(\" \"), namespaceText };\n}\n/** Lowercase with characters invalid in script identifiers as `_`, so `dev-radius` matches `dev_radius`. */\nfunction normalizeName(name: string): string {\n\treturn name\n\t\t.trim()\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9_$]/g, \"_\");\n}\n/**\n * The normalized forms `query` can take for one tool name. MCP tools are registered as\n * `mcp__<server>__<tool>` with `-` and `.` sanitized to `_`, but skills and models also write the\n * dotted `mcp.<server>.<tool>` and the raw `mcp__alteryx-local__…` forms (#4065). In the dotted form\n * only the first two dots separate server and tool. The rest is a raw tool name, either as written\n * (`mcp.srv.get.item/v2` for the tool `get.item/v2`) or with its dots standing for `__`\n * (`mcp.alteryx-local.alteryx_local.get_server_info` for `alteryx_local__get_server_info`); each is\n * named the way registration names it, with `createMcpToolName`.\n */\nfunction nameQueryForms(query: string): Set<string> {\n\tconst trimmed = query.trim();\n\tconst dotted = /^mcp\\.([^.]+)\\.(.+)$/i.exec(trimmed);\n\tif (!dotted) return new Set([normalizeName(trimmed), normalizeName(trimmed.replaceAll(\".\", \"__\"))]);\n\tconst [, server, tool] = dotted;\n\treturn new Set([\n\t\tnormalizeName(trimmed),\n\t\tnormalizeName(createMcpToolName(server, tool)),\n\t\tnormalizeName(createMcpToolName(server, tool.replaceAll(\".\", \"__\"))),\n\t]);\n}\n/**\n * Whether `query` names the tool: its full name or a suffix after a `__` separator, so `thread_read`\n * and `app__thread_read` both name `mcp__app__thread_read`, and `mcp.app.thread_read` does too.\n */\nfunction isNameQuery(query: string, name: string): boolean {\n\tconst normalized = normalizeName(name);\n\tfor (const form of nameQueryForms(query)) if (normalized === form || normalized.endsWith(`__${form}`)) return true;\n\treturn false;\n}\n/**\n * The tool names `query` names, as {@link isNameQuery} matches them: the exact name when it is\n * registered, else every full-name match, else every `__` suffix match. More than one result is\n * ambiguous; callers must not pick one.\n */\nexport function resolveToolNames(query: string, names: readonly string[]): string[] {\n\tif (names.includes(query)) return [query];\n\tconst forms = nameQueryForms(query);\n\tconst full = names.filter((name) => forms.has(normalizeName(name)));\n\treturn full.length ? full : names.filter((name) => isNameQuery(query, name));\n}\n/** A document split into the fields the ranker weighs differently. */\ninterface IndexedDocument {\n\tname: string;\n\t/** Terms of the name, for example `mcp`, `app`, `thread`, `read` for `mcp__app__thread_read`. */\n\tnameTerms: ReadonlySet<string>;\n\t/** Terms of the last `__` segment of the name, the part models say: `thread`, `read`. */\n\tlocalNameTerms: readonly string[];\n\ttextCounts: ReadonlyMap<string, number>;\n\ttextLength: number;\n\tnamespaceTerms: ReadonlySet<string>;\n}\n\nfunction indexDocument(document: ToolSearchDocument): IndexedDocument {\n\tconst textCounts = new Map<string, number>();\n\tfor (const term of tokenize(document.text)) textCounts.set(term, (textCounts.get(term) ?? 0) + 1);\n\tconst segments = document.name.split(\"__\");\n\treturn {\n\t\tname: document.name,\n\t\tnameTerms: new Set(tokenize(document.name)),\n\t\tlocalNameTerms: [...new Set(tokenize(segments[segments.length - 1]))],\n\t\ttextCounts,\n\t\ttextLength: [...textCounts.values()].reduce((sum, count) => sum + count, 0),\n\t\tnamespaceTerms: new Set(tokenize(document.namespaceText ?? \"\")),\n\t};\n}\n\n/**\n * A query term in the name counts this many times its IDF. The text part of a term is at most\n * `k1 + 1` (2.2) times its IDF and about 1 for a single mention, so a name match beats any number of\n * mentions in the description.\n */\nconst NAME_WEIGHT = 3;\n\n/**\n * A query term in the namespace name, description, or instructions counts this many times its IDF. They\n * are shared by every tool of the server, so they help find the server but not the tool in it.\n */\nconst NAMESPACE_WEIGHT = 0.5;\n\n/**\n * Okapi BM25 over the description, with the name and the namespace as separate fields:\n * - a query that names a tool (see {@link isNameQuery}) ranks that tool first, before coverage;\n * - a tool that matches more of the query's terms, in any field, ranks above one that matches\n * fewer, whatever their scores: for `screenshot window`, a tool whose description has both words\n * beats `window`, whose name has one;\n * - a query term in the name scores more than any number of mentions in the description;\n * - a tool whose whole local name is in the query (`app` in `peekaboo app` for\n * `mcp__peekaboo__app`) gets a bonus worth one more match of every query term, so among tools\n * matching as many terms it mostly wins over tools that only mention the words.\n *\n * The description alone is length-normalized, so a long name or long namespace instructions do\n * not lower a tool's score. Ties keep document order.\n */\nexport class Bm25Ranker implements ToolRanker {\n\tprivate readonly k1: number;\n\tprivate readonly b: number;\n\tconstructor(options: { k1?: number; b?: number } = {}) {\n\t\tthis.k1 = options.k1 ?? 1.2;\n\t\tthis.b = options.b ?? 0.75;\n\t}\n\trank(query: string, documents: readonly ToolSearchDocument[], limit: number): ToolSearchMatch[] {\n\t\tif (!documents.length || limit <= 0) return [];\n\t\tconst queryTerms = new Set(tokenize(query));\n\t\t// A query made only of stop words has no BM25 terms, but can still name a tool exactly (`is`).\n\t\tif (queryTerms.size === 0) {\n\t\t\treturn documents\n\t\t\t\t.filter((document) => isNameQuery(query, document.name))\n\t\t\t\t.slice(0, limit)\n\t\t\t\t.map((document) => ({ name: document.name, score: 0 }));\n\t\t}\n\t\tconst indexed = documents.map(indexDocument);\n\t\tconst averageLength = indexed.reduce((sum, document) => sum + document.textLength, 0) / indexed.length || 1;\n\t\tconst idf = new Map(\n\t\t\t[...queryTerms].map((term) => {\n\t\t\t\tconst frequency = indexed.filter(\n\t\t\t\t\t(document) =>\n\t\t\t\t\t\tdocument.nameTerms.has(term) || document.textCounts.has(term) || document.namespaceTerms.has(term),\n\t\t\t\t).length;\n\t\t\t\treturn [term, Math.log(1 + (indexed.length - frequency + 0.5) / (frequency + 0.5))] as const;\n\t\t\t}),\n\t\t);\n\t\tconst fullNameBonus = [...idf.values()].reduce((sum, value) => sum + value, 0);\n\t\tconst matches: (ToolSearchMatch & { covered: number; named: boolean })[] = [];\n\t\tfor (const document of indexed) {\n\t\t\tconst norm = this.k1 * (1 - this.b + (this.b * document.textLength) / averageLength);\n\t\t\tlet score = 0;\n\t\t\tlet covered = 0;\n\t\t\tfor (const term of queryTerms) {\n\t\t\t\tconst count = document.textCounts.get(term) ?? 0;\n\t\t\t\tconst weight =\n\t\t\t\t\t(document.nameTerms.has(term) ? NAME_WEIGHT : 0) +\n\t\t\t\t\t(document.namespaceTerms.has(term) ? NAMESPACE_WEIGHT : 0) +\n\t\t\t\t\t(count * (this.k1 + 1)) / (count + norm);\n\t\t\t\tif (weight > 0) covered++;\n\t\t\t\tscore += (idf.get(term) ?? 0) * weight;\n\t\t\t}\n\t\t\t// A query naming the tool keeps it even when tokenization shares no term with it (`readthread`\n\t\t\t// for `readThread`).\n\t\t\tconst named = isNameQuery(query, document.name);\n\t\t\tif (score === 0 && !named) continue;\n\t\t\tconst local = document.localNameTerms;\n\t\t\tif (score > 0 && local.length > 0 && local.every((term) => queryTerms.has(term))) score += fullNameBonus;\n\t\t\tmatches.push({ name: document.name, score, covered, named });\n\t\t}\n\t\treturn matches\n\t\t\t.sort((a, b) => Number(b.named) - Number(a.named) || b.covered - a.covered || b.score - a.score)\n\t\t\t.slice(0, limit)\n\t\t\t.map(({ name, score }) => ({ name, score }));\n\t}\n}\nexport const toolSearchSchema = Type.Object({ query: Type.String(), limit: Type.Optional(Type.Number()) });\nexport type ToolSearchInput = Static<typeof toolSearchSchema>;\nexport interface ToolSearchToolDetails {\n\tloaded: string[];\n}\nexport interface ToolSearchToolOptions {\n\ttools?: Pick<ExtensionAPI, \"getAllTools\" | \"getActiveTools\" | \"setActiveTools\">;\n}\nexport function isToolSearchTool(tool: Pick<ToolInfo, \"name\" | \"parameters\">): boolean {\n\treturn tool.name === TOOL_SEARCH_TOOL_NAME && tool.parameters === toolSearchSchema;\n}\nexport function createToolSearchDescription(_sources: readonly ToolNamespace[] = []): string {\n\treturn \"Search deferred tool metadata with BM25 and load matching tools for the next model call. Some tools may not have been provided upfront; use tool_search to discover currently registered tools.\";\n}\nexport function createToolSearchToolDefinition(\n\toptions: ToolSearchToolOptions = {},\n): ToolDefinition<typeof toolSearchSchema, ToolSearchToolDetails> {\n\treturn {\n\t\tname: TOOL_SEARCH_TOOL_NAME,\n\t\tlabel: TOOL_SEARCH_TOOL_NAME,\n\t\tdescription: createToolSearchDescription(),\n\t\tparameters: toolSearchSchema,\n\t\texposure: \"model-only\",\n\t\tdefaultActive: false,\n\t\texecute: async (_id, { query, limit = DEFAULT_TOOL_SEARCH_LIMIT }) => {\n\t\t\tif (!query.trim()) throw new Error(\"query must not be empty\");\n\t\t\tif (!Number.isInteger(limit) || limit <= 0) throw new Error(\"limit must be a positive integer\");\n\t\t\tconst active = options.tools?.getActiveTools() ?? [];\n\t\t\tconst candidates =\n\t\t\t\toptions.tools\n\t\t\t\t\t?.getAllTools()\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t(tool) =>\n\t\t\t\t\t\t\t(tool.exposure === \"codemode\" || tool.exposure === \"deferred\") && !active.includes(tool.name),\n\t\t\t\t\t) ?? [];\n\t\t\tconst matches = new Bm25Ranker().rank(\n\t\t\t\tquery,\n\t\t\t\tcandidates.map((tool) => createToolSearchDocument(tool, tool.namespace)),\n\t\t\t\tlimit,\n\t\t\t);\n\t\t\tif (matches.length) options.tools?.setActiveTools([...active, ...matches.map((match) => match.name)]);\n\t\t\treturn {\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext: matches.length\n\t\t\t\t\t\t\t? `Loaded tools for your next call:\\n${matches.map((match) => `- ${match.name}: ${candidates.find((tool) => tool.name === match.name)?.description ?? \"\"}`).join(\"\\n\")}`\n\t\t\t\t\t\t\t: \"No matching tools found.\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdetails: { loaded: matches.map((match) => match.name) },\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { isOAuthRefreshRejectedError, OAuthRefreshRejectedError } from "@bastani/pi-ai";
|
|
2
|
-
export type { AfterProviderResponseEvent, AgentActivityOutcome, AgentBeforeSettleEvent, AgentBeforeSettleEventResult, AgentEndEvent, AgentSettledEvent, AgentStartEvent, AgentToolResult, AgentToolUpdateCallback, AppKeybinding, AtomicProviderCompat, AutocompleteProviderFactory, BashToolCallEvent, BeforeAgentStartCustomEvent, BeforeAgentStartEvent, BeforeAgentStartEventResult, BeforeAgentStartUserEvent, BeforeProviderHeadersEvent, BeforeProviderRequestEvent, BeforeProviderRequestEventResult, BoundaryContextPreview, BoundaryResult, BoundaryState, BuildSystemPromptOptions, CompactionEntryDraft, CompactOptions, ConstrainedSamplingConfig, ContextEditEntryDraft, ContextEvent, ContextEventResult, ContextUsage, ContextWithSystemEvent, CustomEntryDraft, CustomMessageEntryDraft, CustomToolCallEvent, EditToolCallEvent, EntryRenderer, EntryRenderOptions, ExecOptions, ExecResult, Extension, ExtensionActions, ExtensionAPI, ExtensionCommandContext, ExtensionCommandContextActions, ExtensionContext, ExtensionContextActions, ExtensionCustomComponent, ExtensionError, ExtensionEvent, ExtensionFactory, ExtensionFlag, ExtensionHandler, ExtensionRuntime, ExtensionScopedModels, ExtensionShortcut, ExtensionUIContext, ExtensionUIDialogOptions, ExtensionWidgetOptions, FindToolCallEvent, HostInputFormField, HostInputFormFieldType, HostInputFormRequest, HostSessionPickerHandle, HostSessionPickerRequest, HostSessionPickerRow, InlineExtension, InputEvent, InputEventResult, InputSource, InstallReactiveWidgetOptions, KeybindingsManager, LoadExtensionsResult, LsToolCallEvent, MarkdownTransformContext, MarkdownTransformer, MessageEndEventResult, MessageRenderer, MessageRenderOptions, ModelSelectEvent, ModelSelectSource, OrchestrationContext, PendingRecoveryDelivery, PowerShellToolCallEvent, ProjectTrustContext, ProjectTrustEvent, ProjectTrustEventDecision, ProjectTrustEventResult, ProjectTrustHandler, ProviderAliasConfig, ProviderConfig, ProviderModelConfig, ProviderStreamEvent, ReactiveWidgetAction, ReactiveWidgetComponent, ReactiveWidgetController, ReactiveWidgetFactory, ReactiveWidgetRefreshReason, ReactiveWidgetRenderContext, ReactiveWidgetRenderState, ReactiveWidgetScheduler, ReactiveWidgetTimerApi, ReactiveWidgetTimerHandle, ReactiveWidgetUi, ReadToolCallEvent, RegisteredCommand, RegisteredTool, ResolvedCommand, ResourcesDiscoverEvent, ResourcesDiscoverResult, ScopedModel, ScrollableWidgetComponent, SessionBeforeCompactEvent, SessionBeforeCompactResult, SessionBeforeForkEvent, SessionBeforeForkResult, SessionBeforeSwitchEvent, SessionBeforeSwitchResult, SessionBeforeTreeEvent, SessionBeforeTreeResult, SessionBoundaryDraft, SessionCompactEvent, SessionCompactFailedEvent, SessionInfoChangedEvent, SessionRecoveryReason, SessionRecoveryReplayDecision, SessionRecoveryReplayEvent, SessionRecoveryReplayResult, SessionRecoveryRestoreEvent, SessionRecoveryRestoreResult, SessionShutdownEvent, SessionStartEvent, SessionTreeEvent, SlashCommandInfo, SlashCommandSource, SourceInfo, SubagentChildPolicy, SubagentIntercomIdentity, TerminalInputHandler, ThinkingLevelSelectEvent, ToolCallEvent, ToolCallEventResult, ToolDefinition, ToolExecutionEndEvent, ToolExecutionMode, ToolExecutionStartEvent, ToolInfo, ToolRenderResultOptions, ToolResultEvent, ToolResultEventResult, TurnEndEvent, TurnEndEventResult, TurnStartEvent, UIPromptEndEvent, UIPromptKind, UIPromptStartEvent, UserBashEvent, UserBashEventResult, WidgetPlacement, WidgetScrollRequest, WidgetScrollState, WorkflowPendingStageDelivery, WorkflowStageOrchestrationContext, WorkingIndicatorOptions, WriteToolCallEvent, } from "./core/extensions/index.js";
|
|
2
|
+
export type { AfterProviderResponseEvent, AgentActivityOutcome, AgentBeforeSettleEvent, AgentBeforeSettleEventResult, AgentEndEvent, AgentSettledEvent, AgentStartEvent, AgentToolResult, AgentToolUpdateCallback, AppKeybinding, AtomicProviderCompat, AutocompleteProviderFactory, BashToolCallEvent, BeforeAgentStartCustomEvent, BeforeAgentStartEvent, BeforeAgentStartEventResult, BeforeAgentStartUserEvent, BeforeProviderHeadersEvent, BeforeProviderRequestEvent, BeforeProviderRequestEventResult, BoundaryContextPreview, BoundaryResult, BoundaryState, BuildSystemPromptOptions, CompactionEntryDraft, CompactOptions, ConstrainedSamplingConfig, ContextEditEntryDraft, ContextEvent, ContextEventResult, ContextUsage, ContextWithSystemEvent, CustomEntryDraft, CustomMessageEntryDraft, CustomToolCallEvent, EditToolCallEvent, EntryRenderer, EntryRenderOptions, ExecOptions, ExecResult, Extension, ExtensionActions, ExtensionAPI, ExtensionCommandContext, ExtensionCommandContextActions, ExtensionContext, ExtensionContextActions, ExtensionCustomComponent, ExtensionError, ExtensionEvent, ExtensionFactory, ExtensionFlag, ExtensionHandler, ExtensionRuntime, ExtensionScopedModels, ExtensionShortcut, ExtensionUIContext, ExtensionUIDialogOptions, ExtensionWidgetOptions, FindToolCallEvent, HostInputFormField, HostInputFormFieldType, HostInputFormRequest, HostSessionPickerHandle, HostSessionPickerRequest, HostSessionPickerRow, InlineExtension, InputEvent, InputEventResult, InputSource, InstallReactiveWidgetOptions, KeybindingHints, KeybindingsManager, LoadExtensionsResult, LsToolCallEvent, MarkdownTransformContext, MarkdownTransformer, MessageEndEventResult, MessageRenderer, MessageRenderOptions, ModelSelectEvent, ModelSelectSource, OrchestrationContext, PendingRecoveryDelivery, PowerShellToolCallEvent, ProjectTrustContext, ProjectTrustEvent, ProjectTrustEventDecision, ProjectTrustEventResult, ProjectTrustHandler, ProviderAliasConfig, ProviderConfig, ProviderModelConfig, ProviderStreamEvent, ReactiveWidgetAction, ReactiveWidgetComponent, ReactiveWidgetController, ReactiveWidgetFactory, ReactiveWidgetRefreshReason, ReactiveWidgetRenderContext, ReactiveWidgetRenderState, ReactiveWidgetScheduler, ReactiveWidgetTimerApi, ReactiveWidgetTimerHandle, ReactiveWidgetUi, ReadToolCallEvent, RegisteredCommand, RegisteredTool, ResolvedCommand, ResourcesDiscoverEvent, ResourcesDiscoverResult, ScopedModel, ScrollableWidgetComponent, SessionBeforeCompactEvent, SessionBeforeCompactResult, SessionBeforeForkEvent, SessionBeforeForkResult, SessionBeforeSwitchEvent, SessionBeforeSwitchResult, SessionBeforeTreeEvent, SessionBeforeTreeResult, SessionBoundaryDraft, SessionCompactEvent, SessionCompactFailedEvent, SessionInfoChangedEvent, SessionRecoveryReason, SessionRecoveryReplayDecision, SessionRecoveryReplayEvent, SessionRecoveryReplayResult, SessionRecoveryRestoreEvent, SessionRecoveryRestoreResult, SessionShutdownEvent, SessionStartEvent, SessionTreeEvent, SlashCommandInfo, SlashCommandSource, SourceInfo, SubagentChildPolicy, SubagentIntercomIdentity, TerminalInputHandler, ThinkingLevelSelectEvent, ToolCallEvent, ToolCallEventResult, ToolDefinition, ToolExecutionEndEvent, ToolExecutionMode, ToolExecutionStartEvent, ToolInfo, ToolRenderResultOptions, ToolResultEvent, ToolResultEventResult, TurnEndEvent, TurnEndEventResult, TurnStartEvent, UIPromptEndEvent, UIPromptKind, UIPromptStartEvent, UserBashEvent, UserBashEventResult, WidgetPlacement, WidgetScrollRequest, WidgetScrollState, WorkflowPendingStageDelivery, WorkflowStageOrchestrationContext, WorkingIndicatorOptions, WriteToolCallEvent, } from "./core/extensions/index.js";
|
|
3
3
|
export { createExtensionRuntime, decideReactiveWidgetAction, defineTool, discoverAndLoadExtensions, ExtensionRunner, installReactiveWidget, isBashToolResult, isEditToolResult, isFindToolResult, isLsToolResult, isPowerShellToolResult, isReadToolResult, isStaleExtensionContextError, isToolCallEventType, isWriteToolResult, OVERLAY_ACTIVE_ROW_MARKER, STALE_EXTENSION_CONTEXT_MARKER, WorkflowRunControlError, WorkflowRunControlUnavailableError, WorkflowRunNotFoundError, WorkflowRunNotResumableError, WorkflowRunOwnershipError, WorkflowRunStorageError, WorkflowStageAmbiguousError, WorkflowStageNotFoundError, WorkflowStageResumeUnsupportedError, wrapRegisteredTool, wrapRegisteredTools, } from "./core/extensions/index.js";
|
|
4
4
|
export type * from "./core/extensions/workflow-events.js";
|
|
5
5
|
export type * from "./core/extensions/workflow-run-control.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-extensions.d.ts","sourceRoot":"","sources":["../src/index-extensions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AACxF,YAAY,EACX,0BAA0B,EAC1B,oBAAoB,EACpB,sBAAsB,EACtB,4BAA4B,EAC5B,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,oBAAoB,EACpB,2BAA2B,EAC3B,iBAAiB,EACjB,2BAA2B,EAC3B,qBAAqB,EACrB,2BAA2B,EAC3B,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,gCAAgC,EAChC,sBAAsB,EACtB,cAAc,EACd,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,yBAAyB,EAC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.ts","sourceRoot":"","sources":["../src/index-extensions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AACxF,YAAY,EACX,0BAA0B,EAC1B,oBAAoB,EACpB,sBAAsB,EACtB,4BAA4B,EAC5B,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,oBAAoB,EACpB,2BAA2B,EAC3B,iBAAiB,EACjB,2BAA2B,EAC3B,qBAAqB,EACrB,2BAA2B,EAC3B,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,gCAAgC,EAChC,sBAAsB,EACtB,cAAc,EACd,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,yBAAyB,EACzB,qBAAqB,EACrB,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,sBAAsB,EACtB,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,YAAY,EACZ,uBAAuB,EACvB,8BAA8B,EAC9B,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACxB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EACpB,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,4BAA4B,EAC5B,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EACh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BAAsB,EACtB,0BAA0B,EAC1B,UAAU,EACV,yBAAyB,EACzB,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,gBAAgB,EAChB,4BAA4B,EAC5B,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,EACzB,8BAA8B,EAC9B,uBAAuB,EACvB,kCAAkC,EAClC,wBAAwB,EACxB,4BAA4B,EAC5B,yBAAyB,EACzB,uBAAuB,EACvB,2BAA2B,EAC3B,0BAA0B,EAC1B,mCAAmC,EACnC,kBAAkB,EAClB,mBAAmB,GACnB,MAAM,4BAA4B,CAAC;AACpC,mBAAmB,sCAAsC,CAAC;AAC1D,mBAAmB,2CAA2C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-extensions.js","sourceRoot":"","sources":["../src/index-extensions.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,sHAAsH;AACtH,OAAO,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index-extensions.js","sourceRoot":"","sources":["../src/index-extensions.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,sHAAsH;AACtH,OAAO,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAyKxF,OAAO,EACN,sBAAsB,EACtB,0BAA0B,EAC1B,UAAU,EACV,yBAAyB,EACzB,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,gBAAgB,EAChB,4BAA4B,EAC5B,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,EACzB,8BAA8B,EAC9B,uBAAuB,EACvB,kCAAkC,EAClC,wBAAwB,EACxB,4BAA4B,EAC5B,yBAAyB,EACzB,uBAAuB,EACvB,2BAA2B,EAC3B,0BAA0B,EAC1B,mCAAmC,EACnC,kBAAkB,EAClB,mBAAmB,GACnB,MAAM,4BAA4B,CAAC","sourcesContent":["// Extension system\n// Extension OAuth providers throw OAuthRefreshRejectedError from `refreshToken` when the provider rejected the login.\nexport { isOAuthRefreshRejectedError, OAuthRefreshRejectedError } from \"@bastani/pi-ai\";\nexport type {\n\tAfterProviderResponseEvent,\n\tAgentActivityOutcome,\n\tAgentBeforeSettleEvent,\n\tAgentBeforeSettleEventResult,\n\tAgentEndEvent,\n\tAgentSettledEvent,\n\tAgentStartEvent,\n\tAgentToolResult,\n\tAgentToolUpdateCallback,\n\tAppKeybinding,\n\tAtomicProviderCompat,\n\tAutocompleteProviderFactory,\n\tBashToolCallEvent,\n\tBeforeAgentStartCustomEvent,\n\tBeforeAgentStartEvent,\n\tBeforeAgentStartEventResult,\n\tBeforeAgentStartUserEvent,\n\tBeforeProviderHeadersEvent,\n\tBeforeProviderRequestEvent,\n\tBeforeProviderRequestEventResult,\n\tBoundaryContextPreview,\n\tBoundaryResult,\n\tBoundaryState,\n\tBuildSystemPromptOptions,\n\tCompactionEntryDraft,\n\tCompactOptions,\n\tConstrainedSamplingConfig,\n\tContextEditEntryDraft,\n\tContextEvent,\n\tContextEventResult,\n\tContextUsage,\n\tContextWithSystemEvent,\n\tCustomEntryDraft,\n\tCustomMessageEntryDraft,\n\tCustomToolCallEvent,\n\tEditToolCallEvent,\n\tEntryRenderer,\n\tEntryRenderOptions,\n\tExecOptions,\n\tExecResult,\n\tExtension,\n\tExtensionActions,\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionCommandContextActions,\n\tExtensionContext,\n\tExtensionContextActions,\n\tExtensionCustomComponent,\n\tExtensionError,\n\tExtensionEvent,\n\tExtensionFactory,\n\tExtensionFlag,\n\tExtensionHandler,\n\tExtensionRuntime,\n\tExtensionScopedModels,\n\tExtensionShortcut,\n\tExtensionUIContext,\n\tExtensionUIDialogOptions,\n\tExtensionWidgetOptions,\n\tFindToolCallEvent,\n\tHostInputFormField,\n\tHostInputFormFieldType,\n\tHostInputFormRequest,\n\tHostSessionPickerHandle,\n\tHostSessionPickerRequest,\n\tHostSessionPickerRow,\n\tInlineExtension,\n\tInputEvent,\n\tInputEventResult,\n\tInputSource,\n\tInstallReactiveWidgetOptions,\n\tKeybindingHints,\n\tKeybindingsManager,\n\tLoadExtensionsResult,\n\tLsToolCallEvent,\n\tMarkdownTransformContext,\n\tMarkdownTransformer,\n\tMessageEndEventResult,\n\tMessageRenderer,\n\tMessageRenderOptions,\n\tModelSelectEvent,\n\tModelSelectSource,\n\tOrchestrationContext,\n\tPendingRecoveryDelivery,\n\tPowerShellToolCallEvent,\n\tProjectTrustContext,\n\tProjectTrustEvent,\n\tProjectTrustEventDecision,\n\tProjectTrustEventResult,\n\tProjectTrustHandler,\n\tProviderAliasConfig,\n\tProviderConfig,\n\tProviderModelConfig,\n\tProviderStreamEvent,\n\tReactiveWidgetAction,\n\tReactiveWidgetComponent,\n\tReactiveWidgetController,\n\tReactiveWidgetFactory,\n\tReactiveWidgetRefreshReason,\n\tReactiveWidgetRenderContext,\n\tReactiveWidgetRenderState,\n\tReactiveWidgetScheduler,\n\tReactiveWidgetTimerApi,\n\tReactiveWidgetTimerHandle,\n\tReactiveWidgetUi,\n\tReadToolCallEvent,\n\tRegisteredCommand,\n\tRegisteredTool,\n\tResolvedCommand,\n\tResourcesDiscoverEvent,\n\tResourcesDiscoverResult,\n\tScopedModel,\n\tScrollableWidgetComponent,\n\tSessionBeforeCompactEvent,\n\tSessionBeforeCompactResult,\n\tSessionBeforeForkEvent,\n\tSessionBeforeForkResult,\n\tSessionBeforeSwitchEvent,\n\tSessionBeforeSwitchResult,\n\tSessionBeforeTreeEvent,\n\tSessionBeforeTreeResult,\n\tSessionBoundaryDraft,\n\tSessionCompactEvent,\n\tSessionCompactFailedEvent,\n\tSessionInfoChangedEvent,\n\tSessionRecoveryReason,\n\tSessionRecoveryReplayDecision,\n\tSessionRecoveryReplayEvent,\n\tSessionRecoveryReplayResult,\n\tSessionRecoveryRestoreEvent,\n\tSessionRecoveryRestoreResult,\n\tSessionShutdownEvent,\n\tSessionStartEvent,\n\tSessionTreeEvent,\n\tSlashCommandInfo,\n\tSlashCommandSource,\n\tSourceInfo,\n\tSubagentChildPolicy,\n\tSubagentIntercomIdentity,\n\tTerminalInputHandler,\n\tThinkingLevelSelectEvent,\n\tToolCallEvent,\n\tToolCallEventResult,\n\tToolDefinition,\n\tToolExecutionEndEvent,\n\tToolExecutionMode,\n\tToolExecutionStartEvent,\n\tToolInfo,\n\tToolRenderResultOptions,\n\tToolResultEvent,\n\tToolResultEventResult,\n\tTurnEndEvent,\n\tTurnEndEventResult,\n\tTurnStartEvent,\n\tUIPromptEndEvent,\n\tUIPromptKind,\n\tUIPromptStartEvent,\n\tUserBashEvent,\n\tUserBashEventResult,\n\tWidgetPlacement,\n\tWidgetScrollRequest,\n\tWidgetScrollState,\n\tWorkflowPendingStageDelivery,\n\tWorkflowStageOrchestrationContext,\n\tWorkingIndicatorOptions,\n\tWriteToolCallEvent,\n} from \"./core/extensions/index.js\";\nexport {\n\tcreateExtensionRuntime,\n\tdecideReactiveWidgetAction,\n\tdefineTool,\n\tdiscoverAndLoadExtensions,\n\tExtensionRunner,\n\tinstallReactiveWidget,\n\tisBashToolResult,\n\tisEditToolResult,\n\tisFindToolResult,\n\tisLsToolResult,\n\tisPowerShellToolResult,\n\tisReadToolResult,\n\tisStaleExtensionContextError,\n\tisToolCallEventType,\n\tisWriteToolResult,\n\tOVERLAY_ACTIVE_ROW_MARKER,\n\tSTALE_EXTENSION_CONTEXT_MARKER,\n\tWorkflowRunControlError,\n\tWorkflowRunControlUnavailableError,\n\tWorkflowRunNotFoundError,\n\tWorkflowRunNotResumableError,\n\tWorkflowRunOwnershipError,\n\tWorkflowRunStorageError,\n\tWorkflowStageAmbiguousError,\n\tWorkflowStageNotFoundError,\n\tWorkflowStageResumeUnsupportedError,\n\twrapRegisteredTool,\n\twrapRegisteredTools,\n} from \"./core/extensions/index.js\";\nexport type * from \"./core/extensions/workflow-events.js\";\nexport type * from \"./core/extensions/workflow-run-control.js\";\n"]}
|
|
@@ -7,6 +7,8 @@ export interface ExternalEditorHost {
|
|
|
7
7
|
export interface ExternalEditorOptions {
|
|
8
8
|
editorCommand?: string;
|
|
9
9
|
showWarning?: (message: string) => void;
|
|
10
|
+
/** Reports an editor that failed to launch or exited unsuccessfully, which leaves the text unchanged. */
|
|
11
|
+
showStatus?: (message: string) => void;
|
|
10
12
|
}
|
|
11
13
|
export interface ClipboardImageEditorOptions {
|
|
12
14
|
showWarning?: (message: string) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-input-actions.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/chat-input-actions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAMlD,MAAM,WAAW,kBAAkB;IAClC,IAAI,IAAI,IAAI,CAAC;IACb,KAAK,IAAI,IAAI,CAAC;IACd,aAAa,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CACrC;AAED,MAAM,WAAW,qBAAqB;IACrC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"chat-input-actions.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/chat-input-actions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAMlD,MAAM,WAAW,kBAAkB;IAClC,IAAI,IAAI,IAAI,CAAC;IACb,KAAK,IAAI,IAAI,CAAC;IACd,aAAa,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CACrC;AAED,MAAM,WAAW,qBAAqB;IACrC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE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,OAAO,GAAG,eAAe,CAAC,GAAG,kBAAkB,EACxE,OAAO,GAAE,qBAA0B,GACjC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAkB7B"}
|
|
@@ -131,7 +131,10 @@ export async function openExternalEditorForText(text, host, options = {}) {
|
|
|
131
131
|
command: editorCommand,
|
|
132
132
|
content: text,
|
|
133
133
|
});
|
|
134
|
-
|
|
134
|
+
if (result.status === "complete")
|
|
135
|
+
return result.content;
|
|
136
|
+
options.showStatus?.(result.message);
|
|
137
|
+
return undefined;
|
|
135
138
|
}
|
|
136
139
|
catch (error) {
|
|
137
140
|
options.showWarning?.(`Failed to open editor: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-input-actions.js","sourceRoot":"","sources":["../../../src/modes/interactive/chat-input-actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAC/F,OAAO,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAoB1F,MAAM,0BAA0B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAClD,MAAM,sBAAsB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEnD,SAAS,aAAa,CAAC,IAAY;IAClC,OAAO,GAAG,QAAQ,IAAI,IAAI,GAAG,CAAC;AAC/B,CAAC;AAED,SAAS,uBAAuB,CAAC,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,aAAa,CAAC,CAAC;IAC1D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,WAAW,EAAE,CACpB,mCAAmC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAC3F,CAAC;QACF,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC9C,IAAY,EACZ,IAAwE,EACxE,OAAO,GAA0B,EAAE;IAEnC,MAAM,aAAa,GAAG,4BAA4B,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC1E,IAAI,CAAC,IAAI,EAAE,CAAC;IACZ,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC;YACzC,OAAO,EAAE,aAAa;YACtB,OAAO,EAAE,IAAI;SACb,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IAClE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,WAAW,EAAE,CAAC,0BAA0B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC1G,OAAO,SAAS,CAAC;IAClB,CAAC;YAAS,CAAC;QACV,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;AACF,CAAC","sourcesContent":["import * as crypto from \"node:crypto\";\nimport * as fs from \"node:fs\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport type { TUI } from \"@earendil-works/pi-tui\";\nimport { APP_NAME } from \"../../config.js\";\nimport { readClipboardFilePaths, readClipboardText } from \"../../utils/clipboard.js\";\nimport { extensionForImageMimeType, readClipboardImage } from \"../../utils/clipboard-image.ts\";\nimport { editInExternalEditor, resolveExternalEditorCommand } from \"./external-editor.ts\";\n\nexport interface ExternalEditorHost {\n\tstop(): void;\n\tstart(): void;\n\trequestRender(force?: boolean): void;\n}\n\nexport interface ExternalEditorOptions {\n\teditorCommand?: string;\n\tshowWarning?: (message: string) => void;\n}\n\nexport interface ClipboardImageEditorOptions {\n\tshowWarning?: (message: string) => void;\n\tcleanupDelayMs?: number;\n\t/** Bash mode shell-quotes pasted file paths and separates them as arguments. */\n\tisBashMode?: boolean;\n}\n\nconst CLIPBOARD_CLEANUP_DELAY_MS = 60 * 60 * 1000;\nconst CLIPBOARD_STALE_AGE_MS = 24 * 60 * 60 * 1000;\n\nfunction appTempPrefix(kind: string): string {\n\treturn `${APP_NAME}-${kind}-`;\n}\n\nfunction scheduleTempFileCleanup(filePath: string, delayMs: number): void {\n\tconst timer = setTimeout(() => {\n\t\ttry {\n\t\t\tfs.unlinkSync(filePath);\n\t\t} catch {\n\t\t\t// Ignore best-effort cleanup failures.\n\t\t}\n\t}, delayMs);\n\ttimer.unref?.();\n}\n\nexport function cleanupStaleClipboardFiles(now = Date.now()): void {\n\tconst prefix = appTempPrefix(\"clipboard\");\n\tlet entries: string[];\n\ttry {\n\t\tentries = fs.readdirSync(os.tmpdir());\n\t} catch {\n\t\treturn;\n\t}\n\tfor (const entry of entries) {\n\t\tif (!entry.startsWith(prefix)) continue;\n\t\tconst filePath = path.join(os.tmpdir(), entry);\n\t\ttry {\n\t\t\tconst stat = fs.statSync(filePath);\n\t\t\tif (stat.isFile() && now - stat.mtimeMs >= CLIPBOARD_STALE_AGE_MS) fs.unlinkSync(filePath);\n\t\t} catch {\n\t\t\t// Ignore best-effort cleanup failures.\n\t\t}\n\t}\n}\n\nexport function combineQueuedMessagesForEditor(queuedMessages: readonly string[], currentText: string): string {\n\treturn [...queuedMessages, ...(currentText.trim() ? [currentText] : [])].join(\"\\n\\n\");\n}\n\n/**\n * Quote an argument for the shell a person pastes a command into on `platform`: double quotes on\n * Windows, where cmd.exe passes single quotes through as part of the argument, and POSIX single\n * quotes elsewhere. A Windows path needs no quotes unless it has a space or another special\n * character.\n */\nexport function quoteForShell(value: string, platform: NodeJS.Platform = process.platform): string {\n\tif (platform !== \"win32\") return quoteIfNeeded(value);\n\tif (value.length > 0 && !/[^a-zA-Z0-9_\\-./\\\\~:@]/.test(value)) return value;\n\treturn `\"${value.replace(/\"/g, '\"\"')}\"`;\n}\n\n/** Quote a shell argument unless it only contains characters that need no quoting. */\nexport function quoteIfNeeded(value: string): string {\n\tif (value.length > 0 && !/[^a-zA-Z0-9_\\-./~:@]/.test(value)) {\n\t\treturn value;\n\t}\n\treturn `'${value.replace(/'/g, `'\\\\''`)}'`;\n}\n\nexport interface ClipboardImageEditorTarget {\n\tinsertTextAtCursor?: (text: string) => void;\n\tgetText?: () => string;\n\tsetText?: (text: string) => void;\n\tgetCursor?: () => { line: number; col: number };\n}\n\nfunction insertIntoEditor(editor: ClipboardImageEditorTarget, text: string, requestRender?: () => void): boolean {\n\tif (editor.insertTextAtCursor) editor.insertTextAtCursor(text);\n\telse if (editor.getText && editor.setText) editor.setText(`${editor.getText()}${text}`);\n\telse return false;\n\trequestRender?.();\n\treturn true;\n}\n\n/** Copied file paths, separated from adjacent text on the cursor's line. */\nfunction formatClipboardFilePaths(\n\teditor: ClipboardImageEditorTarget,\n\tfilePaths: readonly string[],\n\tisBashMode: boolean,\n): string {\n\tif (filePaths.some((filePath) => /\\p{Cc}/u.test(filePath))) {\n\t\tthrow new Error(\"Clipboard file path contains control characters\");\n\t}\n\tconst paths = isBashMode ? filePaths.map(quoteIfNeeded).join(\" \") : filePaths.join(\"\\n\");\n\tconst cursor = editor.getCursor?.();\n\tconst currentLine = cursor ? (editor.getText?.().split(\"\\n\")[cursor.line] ?? \"\") : \"\";\n\tconst characterBeforeCursor = cursor && cursor.col > 0 ? currentLine[cursor.col - 1] : \"\";\n\tconst characterAfterCursor = cursor ? currentLine[cursor.col] : \"\";\n\tconst leadingSpace = characterBeforeCursor && !/\\s/.test(characterBeforeCursor) ? \" \" : \"\";\n\tconst trailingSpace = characterAfterCursor && !/\\s/.test(characterAfterCursor) ? \" \" : \"\";\n\treturn `${leadingSpace}${paths}${trailingSpace}`;\n}\n\n/**\n * Paste from the clipboard: copied files by their original paths (macOS), images via temporary\n * files, and plain text as the final fallback.\n */\nexport async function pasteClipboardImageToEditor(\n\teditor: ClipboardImageEditorTarget,\n\trequestRender?: () => void,\n\toptions: ClipboardImageEditorOptions = {},\n): Promise<boolean> {\n\ttry {\n\t\tcleanupStaleClipboardFiles();\n\t\t// Finder copies also carry the file icon as an image; the paths are what the user copied.\n\t\tconst filePaths = await readClipboardFilePaths();\n\t\tif (filePaths) {\n\t\t\treturn insertIntoEditor(\n\t\t\t\teditor,\n\t\t\t\tformatClipboardFilePaths(editor, filePaths, options.isBashMode ?? false),\n\t\t\t\trequestRender,\n\t\t\t);\n\t\t}\n\n\t\tconst image = await readClipboardImage();\n\t\tif (!image) {\n\t\t\tconst text = await readClipboardText();\n\t\t\tif (!text) return false;\n\t\t\treturn insertIntoEditor(editor, text, requestRender);\n\t\t}\n\n\t\tconst ext = extensionForImageMimeType(image.mimeType) ?? \"png\";\n\t\tconst fileName = `${appTempPrefix(\"clipboard\")}${crypto.randomUUID()}.${ext}`;\n\t\tconst filePath = path.join(os.tmpdir(), fileName);\n\t\tfs.writeFileSync(filePath, Buffer.from(image.bytes), { flag: \"wx\", mode: 0o600 });\n\t\tscheduleTempFileCleanup(filePath, options.cleanupDelayMs ?? CLIPBOARD_CLEANUP_DELAY_MS);\n\n\t\treturn insertIntoEditor(editor, filePath, requestRender);\n\t} catch (error) {\n\t\toptions.showWarning?.(\n\t\t\t`Failed to paste from clipboard: ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t\treturn false;\n\t}\n}\n\nexport async function openExternalEditorForText(\n\ttext: string,\n\thost: Pick<TUI, \"stop\" | \"start\" | \"requestRender\"> | ExternalEditorHost,\n\toptions: ExternalEditorOptions = {},\n): Promise<string | undefined> {\n\tconst editorCommand = resolveExternalEditorCommand(options.editorCommand);\n\thost.stop();\n\ttry {\n\t\tconst result = await editInExternalEditor({\n\t\t\tcommand: editorCommand,\n\t\t\tcontent: text,\n\t\t});\n\t\treturn result.status === \"complete\" ? result.content : undefined;\n\t} catch (error) {\n\t\toptions.showWarning?.(`Failed to open editor: ${error instanceof Error ? error.message : String(error)}`);\n\t\treturn undefined;\n\t} finally {\n\t\thost.start();\n\t\thost.requestRender(true);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"chat-input-actions.js","sourceRoot":"","sources":["../../../src/modes/interactive/chat-input-actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAC/F,OAAO,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAsB1F,MAAM,0BAA0B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAClD,MAAM,sBAAsB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEnD,SAAS,aAAa,CAAC,IAAY;IAClC,OAAO,GAAG,QAAQ,IAAI,IAAI,GAAG,CAAC;AAC/B,CAAC;AAED,SAAS,uBAAuB,CAAC,QAAgB,EAAE,OAAe;IACjE,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAA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ChB,OAAO,CAAC,WAAW,EAAE,CACpB,mCAAmC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAC3F,CAAC;QACF,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC9C,IAAY,EACZ,IAAwE,EACxE,OAAO,GAA0B,EAAE;IAEnC,MAAM,aAAa,GAAG,4BAA4B,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC1E,IAAI,CAAC,IAAI,EAAE,CAAC;IACZ,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC;YACzC,OAAO,EAAE,aAAa;YACtB,OAAO,EAAE,IAAI;SACb,CAAC,CAAC;QACH,IAAI,MAAM,CAAC,MAAM,KAAK,UAAU;YAAE,OAAO,MAAM,CAAC,OAAO,CAAC;QACxD,OAAO,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACrC,OAAO,SAAS,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,WAAW,EAAE,CAAC,0BAA0B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC1G,OAAO,SAAS,CAAC;IAClB,CAAC;YAAS,CAAC;QACV,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;AACF,CAAC","sourcesContent":["import * as crypto from \"node:crypto\";\nimport * as fs from \"node:fs\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport type { TUI } from \"@earendil-works/pi-tui\";\nimport { APP_NAME } from \"../../config.js\";\nimport { readClipboardFilePaths, readClipboardText } from \"../../utils/clipboard.js\";\nimport { extensionForImageMimeType, readClipboardImage } from \"../../utils/clipboard-image.ts\";\nimport { editInExternalEditor, resolveExternalEditorCommand } from \"./external-editor.ts\";\n\nexport interface ExternalEditorHost {\n\tstop(): void;\n\tstart(): void;\n\trequestRender(force?: boolean): void;\n}\n\nexport interface ExternalEditorOptions {\n\teditorCommand?: string;\n\tshowWarning?: (message: string) => void;\n\t/** Reports an editor that failed to launch or exited unsuccessfully, which leaves the text unchanged. */\n\tshowStatus?: (message: string) => void;\n}\n\nexport interface ClipboardImageEditorOptions {\n\tshowWarning?: (message: string) => void;\n\tcleanupDelayMs?: number;\n\t/** Bash mode shell-quotes pasted file paths and separates them as arguments. */\n\tisBashMode?: boolean;\n}\n\nconst CLIPBOARD_CLEANUP_DELAY_MS = 60 * 60 * 1000;\nconst CLIPBOARD_STALE_AGE_MS = 24 * 60 * 60 * 1000;\n\nfunction appTempPrefix(kind: string): string {\n\treturn `${APP_NAME}-${kind}-`;\n}\n\nfunction scheduleTempFileCleanup(filePath: string, delayMs: number): void {\n\tconst timer = setTimeout(() => {\n\t\ttry {\n\t\t\tfs.unlinkSync(filePath);\n\t\t} catch {\n\t\t\t// Ignore best-effort cleanup failures.\n\t\t}\n\t}, delayMs);\n\ttimer.unref?.();\n}\n\nexport function cleanupStaleClipboardFiles(now = Date.now()): void {\n\tconst prefix = appTempPrefix(\"clipboard\");\n\tlet entries: string[];\n\ttry {\n\t\tentries = fs.readdirSync(os.tmpdir());\n\t} catch {\n\t\treturn;\n\t}\n\tfor (const entry of entries) {\n\t\tif (!entry.startsWith(prefix)) continue;\n\t\tconst filePath = path.join(os.tmpdir(), entry);\n\t\ttry {\n\t\t\tconst stat = fs.statSync(filePath);\n\t\t\tif (stat.isFile() && now - stat.mtimeMs >= CLIPBOARD_STALE_AGE_MS) fs.unlinkSync(filePath);\n\t\t} catch {\n\t\t\t// Ignore best-effort cleanup failures.\n\t\t}\n\t}\n}\n\nexport function combineQueuedMessagesForEditor(queuedMessages: readonly string[], currentText: string): string {\n\treturn [...queuedMessages, ...(currentText.trim() ? [currentText] : [])].join(\"\\n\\n\");\n}\n\n/**\n * Quote an argument for the shell a person pastes a command into on `platform`: double quotes on\n * Windows, where cmd.exe passes single quotes through as part of the argument, and POSIX single\n * quotes elsewhere. A Windows path needs no quotes unless it has a space or another special\n * character.\n */\nexport function quoteForShell(value: string, platform: NodeJS.Platform = process.platform): string {\n\tif (platform !== \"win32\") return quoteIfNeeded(value);\n\tif (value.length > 0 && !/[^a-zA-Z0-9_\\-./\\\\~:@]/.test(value)) return value;\n\treturn `\"${value.replace(/\"/g, '\"\"')}\"`;\n}\n\n/** Quote a shell argument unless it only contains characters that need no quoting. */\nexport function quoteIfNeeded(value: string): string {\n\tif (value.length > 0 && !/[^a-zA-Z0-9_\\-./~:@]/.test(value)) {\n\t\treturn value;\n\t}\n\treturn `'${value.replace(/'/g, `'\\\\''`)}'`;\n}\n\nexport interface ClipboardImageEditorTarget {\n\tinsertTextAtCursor?: (text: string) => void;\n\tgetText?: () => string;\n\tsetText?: (text: string) => void;\n\tgetCursor?: () => { line: number; col: number };\n}\n\nfunction insertIntoEditor(editor: ClipboardImageEditorTarget, text: string, requestRender?: () => void): boolean {\n\tif (editor.insertTextAtCursor) editor.insertTextAtCursor(text);\n\telse if (editor.getText && editor.setText) editor.setText(`${editor.getText()}${text}`);\n\telse return false;\n\trequestRender?.();\n\treturn true;\n}\n\n/** Copied file paths, separated from adjacent text on the cursor's line. */\nfunction formatClipboardFilePaths(\n\teditor: ClipboardImageEditorTarget,\n\tfilePaths: readonly string[],\n\tisBashMode: boolean,\n): string {\n\tif (filePaths.some((filePath) => /\\p{Cc}/u.test(filePath))) {\n\t\tthrow new Error(\"Clipboard file path contains control characters\");\n\t}\n\tconst paths = isBashMode ? filePaths.map(quoteIfNeeded).join(\" \") : filePaths.join(\"\\n\");\n\tconst cursor = editor.getCursor?.();\n\tconst currentLine = cursor ? (editor.getText?.().split(\"\\n\")[cursor.line] ?? \"\") : \"\";\n\tconst characterBeforeCursor = cursor && cursor.col > 0 ? currentLine[cursor.col - 1] : \"\";\n\tconst characterAfterCursor = cursor ? currentLine[cursor.col] : \"\";\n\tconst leadingSpace = characterBeforeCursor && !/\\s/.test(characterBeforeCursor) ? \" \" : \"\";\n\tconst trailingSpace = characterAfterCursor && !/\\s/.test(characterAfterCursor) ? \" \" : \"\";\n\treturn `${leadingSpace}${paths}${trailingSpace}`;\n}\n\n/**\n * Paste from the clipboard: copied files by their original paths (macOS), images via temporary\n * files, and plain text as the final fallback.\n */\nexport async function pasteClipboardImageToEditor(\n\teditor: ClipboardImageEditorTarget,\n\trequestRender?: () => void,\n\toptions: ClipboardImageEditorOptions = {},\n): Promise<boolean> {\n\ttry {\n\t\tcleanupStaleClipboardFiles();\n\t\t// Finder copies also carry the file icon as an image; the paths are what the user copied.\n\t\tconst filePaths = await readClipboardFilePaths();\n\t\tif (filePaths) {\n\t\t\treturn insertIntoEditor(\n\t\t\t\teditor,\n\t\t\t\tformatClipboardFilePaths(editor, filePaths, options.isBashMode ?? false),\n\t\t\t\trequestRender,\n\t\t\t);\n\t\t}\n\n\t\tconst image = await readClipboardImage();\n\t\tif (!image) {\n\t\t\tconst text = await readClipboardText();\n\t\t\tif (!text) return false;\n\t\t\treturn insertIntoEditor(editor, text, requestRender);\n\t\t}\n\n\t\tconst ext = extensionForImageMimeType(image.mimeType) ?? \"png\";\n\t\tconst fileName = `${appTempPrefix(\"clipboard\")}${crypto.randomUUID()}.${ext}`;\n\t\tconst filePath = path.join(os.tmpdir(), fileName);\n\t\tfs.writeFileSync(filePath, Buffer.from(image.bytes), { flag: \"wx\", mode: 0o600 });\n\t\tscheduleTempFileCleanup(filePath, options.cleanupDelayMs ?? CLIPBOARD_CLEANUP_DELAY_MS);\n\n\t\treturn insertIntoEditor(editor, filePath, requestRender);\n\t} catch (error) {\n\t\toptions.showWarning?.(\n\t\t\t`Failed to paste from clipboard: ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t\treturn false;\n\t}\n}\n\nexport async function openExternalEditorForText(\n\ttext: string,\n\thost: Pick<TUI, \"stop\" | \"start\" | \"requestRender\"> | ExternalEditorHost,\n\toptions: ExternalEditorOptions = {},\n): Promise<string | undefined> {\n\tconst editorCommand = resolveExternalEditorCommand(options.editorCommand);\n\thost.stop();\n\ttry {\n\t\tconst result = await editInExternalEditor({\n\t\t\tcommand: editorCommand,\n\t\t\tcontent: text,\n\t\t});\n\t\tif (result.status === \"complete\") return result.content;\n\t\toptions.showStatus?.(result.message);\n\t\treturn undefined;\n\t} catch (error) {\n\t\toptions.showWarning?.(`Failed to open editor: ${error instanceof Error ? error.message : String(error)}`);\n\t\treturn undefined;\n\t} finally {\n\t\thost.start();\n\t\thost.requestRender(true);\n\t}\n}\n"]}
|
|
@@ -169,6 +169,7 @@ async function openChatSessionExternalEditor(state) {
|
|
|
169
169
|
const currentText = state.editor.getExpandedText?.() ?? state.editor.getText();
|
|
170
170
|
const updated = await openExternalEditorForText(currentText, host, {
|
|
171
171
|
showWarning: (message) => notifyChatSessionWarning(state, message),
|
|
172
|
+
showStatus: (message) => notifyChatSessionStatus(state, message),
|
|
172
173
|
});
|
|
173
174
|
if (updated !== undefined)
|
|
174
175
|
setChatSessionEditorText(state, updated);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-session-host-editor.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/chat-session-host-editor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAClG,OAAO,EACN,wBAAwB,EACxB,sBAAsB,EACtB,uBAAuB,EACvB,wBAAwB,GACxB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAUlD,MAAM,UAAU,uBAAuB,CACtC,KAAwC,EACxC,GAAoB,EACpB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AAS,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACrE,CAAC;AACH,CAAC;AAED,KAAK,UAAU,6BAA6B,CAC3C,KAAwC;IAExC,IAAI,CAAC,KAAK,CAAC,MAAM;QAAE,OAAO;IAC1B,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC;IACvB,IAAI,CAAC,IAAI;QAAE,OAAO;IAClB,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAC/E,MAAM,OAAO,GAAG,MAAM,yBAAyB,CAAC,WAAW,EAAE,IAAI,EAAE;QAClE,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,wBAAwB,CAAC,KAAK,EAAE,OAAO,CAAC;KAClE,CAAC,CAAC;IACH,IAAI,OAAO,KAAK,SAAS;QAAE,wBAAwB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import type { EditorComponent, EditorTheme, Focusable, TUI } from \"@earendil-works/pi-tui\";\nimport { openExternalEditorForText, pasteClipboardImageToEditor } from \"../chat-input-actions.ts\";\nimport {\n\tisChatSessionBashRunning,\n\tisChatSessionStreaming,\n\tnotifyChatSessionStatus,\n\tnotifyChatSessionWarning,\n} from \"./chat-session-host-runtime.ts\";\nimport type { ChatSessionHostState } from \"./chat-session-host-state.ts\";\nimport type { ChatSessionHostOpts, ChatSessionSubmitMode } from \"./chat-session-host-types.ts\";\nimport { matchesKey } from \"./chat-session-host-utils.ts\";\nimport type { ChatTranscriptEntryLike } from \"./chat-transcript.js\";\nimport { CustomEditor } from \"./custom-editor.ts\";\n\nexport interface ChatSessionEditorCallbacks {\n\tsubmit: (mode: ChatSessionSubmitMode, submittedText?: string) => void | Promise<void>;\n\trestoreQueuedMessagesToEditor: () => boolean;\n\tabortCompaction: () => void | Promise<void>;\n\tinterrupt: (options?: { restoreQueuedMessages?: boolean }) => void | Promise<void>;\n\tabortBash: () => void | Promise<void>;\n}\n\nexport function createChatSessionEditor<TExtraEntry extends ChatTranscriptEntryLike>(\n\tstate: ChatSessionHostState<TExtraEntry>,\n\ttui: TUI | undefined,\n\tkeybindings: unknown,\n\teditorTheme: EditorTheme,\n\teditorFactory: ChatSessionHostOpts<TExtraEntry>[\"editorFactory\"],\n\tcallbacks: ChatSessionEditorCallbacks,\n): EditorComponent | undefined {\n\tif (!tui || !keybindings) return undefined;\n\tconst editor =\n\t\tcreateInheritedEditor(tui, editorTheme, keybindings, editorFactory) ??\n\t\tnew CustomEditor(tui, editorTheme, keybindings as ConstructorParameters<typeof CustomEditor>[2], {\n\t\t\tpaddingX: 0,\n\t\t\tautocompleteMaxVisible: 5,\n\t\t});\n\teditor.onChange = (text) => {\n\t\tstate.inputBuffer = text;\n\t\tstate.isBashMode = text.trimStart().startsWith(\"!\");\n\t};\n\teditor.onSubmit = (text) => {\n\t\tvoid callbacks.submit(\"auto\", text);\n\t};\n\tconst actionEditor = editor as EditorComponent & {\n\t\tonAction?: (action: string, handler: () => void) => void;\n\t\tonEscape?: () => void;\n\t\tonPasteImage?: () => void;\n\t};\n\tactionEditor.onAction?.(\"app.message.followUp\", () => {\n\t\tvoid callbacks.submit(\"followUp\");\n\t});\n\tactionEditor.onAction?.(\"app.message.dequeue\", () => {\n\t\tcallbacks.restoreQueuedMessagesToEditor();\n\t});\n\tactionEditor.onAction?.(\"app.editor.external\", () => {\n\t\tvoid openChatSessionExternalEditor(state);\n\t});\n\tif (state.actions) {\n\t\tfor (const [action, handler] of Object.entries(state.actions)) {\n\t\t\tactionEditor.onAction?.(action, () => {\n\t\t\t\tvoid handler();\n\t\t\t});\n\t\t}\n\t}\n\tconst previousPasteImage = actionEditor.onPasteImage;\n\tactionEditor.onPasteImage = () => {\n\t\tpreviousPasteImage?.();\n\t\tvoid pasteClipboardImageToEditor(chatSessionEditorAccess(state), () => state.requestRender?.(), {\n\t\t\tshowWarning: (message) => notifyChatSessionWarning(state, message),\n\t\t\tisBashMode: state.isBashMode,\n\t\t});\n\t};\n\tconst previousEscape = actionEditor.onEscape;\n\tactionEditor.onEscape = () => {\n\t\tif (state.compacting) {\n\t\t\tvoid callbacks.abortCompaction();\n\t\t\treturn;\n\t\t}\n\t\tif (isChatSessionStreaming(state)) {\n\t\t\tvoid callbacks.interrupt({ restoreQueuedMessages: true });\n\t\t\treturn;\n\t\t}\n\t\tif (isChatSessionBashRunning(state)) {\n\t\t\tvoid callbacks.abortBash();\n\t\t\treturn;\n\t\t}\n\t\tif (state.isBashMode) {\n\t\t\tsetChatSessionEditorText(state, \"\");\n\t\t\tnotifyChatSessionStatus(state, \"Bash mode cleared\");\n\t\t\treturn;\n\t\t}\n\t\tpreviousEscape?.();\n\t};\n\treturn editor;\n}\n\nexport function handleChatSessionInput<TExtraEntry extends ChatTranscriptEntryLike>(\n\tstate: ChatSessionHostState<TExtraEntry>,\n\tdata: string,\n\tcallbacks: ChatSessionEditorCallbacks,\n): boolean {\n\tif (state.bodyViewport.handleInput(data)) return true;\n\tif (matchesKey(data, \"alt+up\")) {\n\t\tcallbacks.restoreQueuedMessagesToEditor();\n\t\treturn true;\n\t}\n\tif (matchesKey(data, \"ctrl+f\")) {\n\t\tvoid callbacks.submit(\"followUp\");\n\t\treturn true;\n\t}\n\tif (matchesKey(data, \"escape\")) {\n\t\tif (state.compacting) {\n\t\t\tvoid callbacks.abortCompaction();\n\t\t\treturn true;\n\t\t}\n\t\tif (isChatSessionStreaming(state)) {\n\t\t\tvoid callbacks.interrupt({ restoreQueuedMessages: true });\n\t\t\treturn true;\n\t\t}\n\t\tif (isChatSessionBashRunning(state)) {\n\t\t\tvoid callbacks.abortBash();\n\t\t\treturn true;\n\t\t}\n\t\tif (state.isBashMode) {\n\t\t\tsetChatSessionEditorText(state, \"\");\n\t\t\tnotifyChatSessionStatus(state, \"Bash mode cleared\");\n\t\t\treturn true;\n\t\t}\n\t}\n\tif (state.editor) {\n\t\tstate.editor.handleInput(data);\n\t\treturn true;\n\t}\n\tif (matchesKey(data, \"enter\")) {\n\t\tvoid callbacks.submit(\"auto\");\n\t\treturn true;\n\t}\n\tif (matchesKey(data, \"backspace\")) {\n\t\tsetChatSessionEditorText(state, state.inputBuffer.slice(0, -1));\n\t\treturn true;\n\t}\n\tif (data.length === 1 && data >= \" \" && data <= \"~\") {\n\t\tsetChatSessionEditorText(state, `${state.inputBuffer}${data}`);\n\t\treturn true;\n\t}\n\treturn false;\n}\n\nexport function setChatSessionEditorText<TExtraEntry extends ChatTranscriptEntryLike>(\n\tstate: ChatSessionHostState<TExtraEntry>,\n\ttext: string,\n): void {\n\tstate.inputBuffer = text;\n\tstate.isBashMode = text.trimStart().startsWith(\"!\");\n\tstate.editor?.setText(text);\n}\n\nexport function setEditorPlaceholder(editor: EditorComponent, placeholder: string | undefined): void {\n\tconst candidate = editor as EditorComponent & {\n\t\tsetPlaceholder?: (value: string | undefined) => void;\n\t};\n\tcandidate.setPlaceholder?.(placeholder);\n}\n\nexport function setEditorBorderColor(editor: EditorComponent, borderColor: (text: string) => string): void {\n\tconst candidate = editor as EditorComponent & {\n\t\tborderColor?: (text: string) => string;\n\t};\n\tif (candidate.borderColor !== undefined) candidate.borderColor = borderColor;\n}\n\nexport function setEditorFocused(editor: EditorComponent, focused: boolean): void {\n\tconst candidate = editor as EditorComponent & Partial<Focusable>;\n\tif (\"focused\" in candidate) candidate.focused = focused;\n}\n\nfunction createInheritedEditor<TExtraEntry extends ChatTranscriptEntryLike>(\n\ttui: TUI,\n\teditorTheme: EditorTheme,\n\tkeybindings: unknown,\n\teditorFactory: ChatSessionHostOpts<TExtraEntry>[\"editorFactory\"],\n): EditorComponent | undefined {\n\tif (!editorFactory) return undefined;\n\ttry {\n\t\treturn editorFactory(tui, editorTheme, keybindings);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\ntype EditorCursor = { line: number; col: number };\ntype CursorAwareEditor = EditorComponent & { getCursor(): EditorCursor };\n\nfunction hasCursor(editor: EditorComponent | undefined): editor is CursorAwareEditor {\n\treturn typeof (editor as Partial<CursorAwareEditor> | undefined)?.getCursor === \"function\";\n}\n\nexport function chatSessionEditorAccess<TExtraEntry extends ChatTranscriptEntryLike>(\n\tstate: ChatSessionHostState<TExtraEntry>,\n): {\n\tinsertTextAtCursor: (text: string) => void;\n\tgetText: () => string;\n\tsetText: (text: string) => void;\n\tgetCursor?: () => EditorCursor;\n} {\n\tconst editor = state.editor;\n\treturn {\n\t\tinsertTextAtCursor: (text: string) => {\n\t\t\tif (state.editor?.insertTextAtCursor) {\n\t\t\t\tstate.editor.insertTextAtCursor(text);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetChatSessionEditorText(state, `${state.inputBuffer}${text}`);\n\t\t},\n\t\tgetText: () => state.inputBuffer,\n\t\tsetText: (text: string) => setChatSessionEditorText(state, text),\n\t\t...(hasCursor(editor) ? { getCursor: () => editor.getCursor() } : {}),\n\t};\n}\n\nasync function openChatSessionExternalEditor<TExtraEntry extends ChatTranscriptEntryLike>(\n\tstate: ChatSessionHostState<TExtraEntry>,\n): Promise<void> {\n\tif (!state.editor) return;\n\tconst host = state.tui;\n\tif (!host) return;\n\tconst currentText = state.editor.getExpandedText?.() ?? state.editor.getText();\n\tconst updated = await openExternalEditorForText(currentText, host, {\n\t\tshowWarning: (message) => notifyChatSessionWarning(state, message),\n\t});\n\tif (updated !== undefined) setChatSessionEditorText(state, updated);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"chat-session-host-editor.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/chat-session-host-editor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAClG,OAAO,EACN,wBAAwB,EACxB,sBAAsB,EACtB,uBAAuB,EACvB,wBAAwB,GACxB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE1D,OAAO,EAAE,YA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AS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACrE,CAAC;AACH,CAAC;AAED,KAAK,UAAU,6BAA6B,CAC3C,KAAwC;IAExC,IAAI,CAAC,KAAK,CAAC,MAAM;QAAE,OAAO;IAC1B,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC;IACvB,IAAI,CAAC,IAAI;QAAE,OAAO;IAClB,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAC/E,MAAM,OAAO,GAAG,MAAM,yBAAyB,CAAC,WAAW,EAAE,IAAI,EAAE;QAClE,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,wBAAwB,CAAC,KAAK,EAAE,OAAO,CAAC;QAClE,UAAU,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,uBAAuB,CAAC,KAAK,EAAE,OAAO,CAAC;KAChE,CAAC,CAAC;IACH,IAAI,OAAO,KAAK,SAAS;QAAE,wBAAwB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import type { EditorComponent, EditorTheme, Focusable, TUI } from \"@earendil-works/pi-tui\";\nimport { openExternalEditorForText, pasteClipboardImageToEditor } from \"../chat-input-actions.ts\";\nimport {\n\tisChatSessionBashRunning,\n\tisChatSessionStreaming,\n\tnotifyChatSessionStatus,\n\tnotifyChatSessionWarning,\n} from \"./chat-session-host-runtime.ts\";\nimport type { ChatSessionHostState } from \"./chat-session-host-state.ts\";\nimport type { ChatSessionHostOpts, ChatSessionSubmitMode } from \"./chat-session-host-types.ts\";\nimport { matchesKey } from \"./chat-session-host-utils.ts\";\nimport type { ChatTranscriptEntryLike } from \"./chat-transcript.js\";\nimport { CustomEditor } from \"./custom-editor.ts\";\n\nexport interface ChatSessionEditorCallbacks {\n\tsubmit: (mode: ChatSessionSubmitMode, submittedText?: string) => void | Promise<void>;\n\trestoreQueuedMessagesToEditor: () => boolean;\n\tabortCompaction: () => void | Promise<void>;\n\tinterrupt: (options?: { restoreQueuedMessages?: boolean }) => void | Promise<void>;\n\tabortBash: () => void | Promise<void>;\n}\n\nexport function createChatSessionEditor<TExtraEntry extends ChatTranscriptEntryLike>(\n\tstate: ChatSessionHostState<TExtraEntry>,\n\ttui: TUI | undefined,\n\tkeybindings: unknown,\n\teditorTheme: EditorTheme,\n\teditorFactory: ChatSessionHostOpts<TExtraEntry>[\"editorFactory\"],\n\tcallbacks: ChatSessionEditorCallbacks,\n): EditorComponent | undefined {\n\tif (!tui || !keybindings) return undefined;\n\tconst editor =\n\t\tcreateInheritedEditor(tui, editorTheme, keybindings, editorFactory) ??\n\t\tnew CustomEditor(tui, editorTheme, keybindings as ConstructorParameters<typeof CustomEditor>[2], {\n\t\t\tpaddingX: 0,\n\t\t\tautocompleteMaxVisible: 5,\n\t\t});\n\teditor.onChange = (text) => {\n\t\tstate.inputBuffer = text;\n\t\tstate.isBashMode = text.trimStart().startsWith(\"!\");\n\t};\n\teditor.onSubmit = (text) => {\n\t\tvoid callbacks.submit(\"auto\", text);\n\t};\n\tconst actionEditor = editor as EditorComponent & {\n\t\tonAction?: (action: string, handler: () => void) => void;\n\t\tonEscape?: () => void;\n\t\tonPasteImage?: () => void;\n\t};\n\tactionEditor.onAction?.(\"app.message.followUp\", () => {\n\t\tvoid callbacks.submit(\"followUp\");\n\t});\n\tactionEditor.onAction?.(\"app.message.dequeue\", () => {\n\t\tcallbacks.restoreQueuedMessagesToEditor();\n\t});\n\tactionEditor.onAction?.(\"app.editor.external\", () => {\n\t\tvoid openChatSessionExternalEditor(state);\n\t});\n\tif (state.actions) {\n\t\tfor (const [action, handler] of Object.entries(state.actions)) {\n\t\t\tactionEditor.onAction?.(action, () => {\n\t\t\t\tvoid handler();\n\t\t\t});\n\t\t}\n\t}\n\tconst previousPasteImage = actionEditor.onPasteImage;\n\tactionEditor.onPasteImage = () => {\n\t\tpreviousPasteImage?.();\n\t\tvoid pasteClipboardImageToEditor(chatSessionEditorAccess(state), () => state.requestRender?.(), {\n\t\t\tshowWarning: (message) => notifyChatSessionWarning(state, message),\n\t\t\tisBashMode: state.isBashMode,\n\t\t});\n\t};\n\tconst previousEscape = actionEditor.onEscape;\n\tactionEditor.onEscape = () => {\n\t\tif (state.compacting) {\n\t\t\tvoid callbacks.abortCompaction();\n\t\t\treturn;\n\t\t}\n\t\tif (isChatSessionStreaming(state)) {\n\t\t\tvoid callbacks.interrupt({ restoreQueuedMessages: true });\n\t\t\treturn;\n\t\t}\n\t\tif (isChatSessionBashRunning(state)) {\n\t\t\tvoid callbacks.abortBash();\n\t\t\treturn;\n\t\t}\n\t\tif (state.isBashMode) {\n\t\t\tsetChatSessionEditorText(state, \"\");\n\t\t\tnotifyChatSessionStatus(state, \"Bash mode cleared\");\n\t\t\treturn;\n\t\t}\n\t\tpreviousEscape?.();\n\t};\n\treturn editor;\n}\n\nexport function handleChatSessionInput<TExtraEntry extends ChatTranscriptEntryLike>(\n\tstate: ChatSessionHostState<TExtraEntry>,\n\tdata: string,\n\tcallbacks: ChatSessionEditorCallbacks,\n): boolean {\n\tif (state.bodyViewport.handleInput(data)) return true;\n\tif (matchesKey(data, \"alt+up\")) {\n\t\tcallbacks.restoreQueuedMessagesToEditor();\n\t\treturn true;\n\t}\n\tif (matchesKey(data, \"ctrl+f\")) {\n\t\tvoid callbacks.submit(\"followUp\");\n\t\treturn true;\n\t}\n\tif (matchesKey(data, \"escape\")) {\n\t\tif (state.compacting) {\n\t\t\tvoid callbacks.abortCompaction();\n\t\t\treturn true;\n\t\t}\n\t\tif (isChatSessionStreaming(state)) {\n\t\t\tvoid callbacks.interrupt({ restoreQueuedMessages: true });\n\t\t\treturn true;\n\t\t}\n\t\tif (isChatSessionBashRunning(state)) {\n\t\t\tvoid callbacks.abortBash();\n\t\t\treturn true;\n\t\t}\n\t\tif (state.isBashMode) {\n\t\t\tsetChatSessionEditorText(state, \"\");\n\t\t\tnotifyChatSessionStatus(state, \"Bash mode cleared\");\n\t\t\treturn true;\n\t\t}\n\t}\n\tif (state.editor) {\n\t\tstate.editor.handleInput(data);\n\t\treturn true;\n\t}\n\tif (matchesKey(data, \"enter\")) {\n\t\tvoid callbacks.submit(\"auto\");\n\t\treturn true;\n\t}\n\tif (matchesKey(data, \"backspace\")) {\n\t\tsetChatSessionEditorText(state, state.inputBuffer.slice(0, -1));\n\t\treturn true;\n\t}\n\tif (data.length === 1 && data >= \" \" && data <= \"~\") {\n\t\tsetChatSessionEditorText(state, `${state.inputBuffer}${data}`);\n\t\treturn true;\n\t}\n\treturn false;\n}\n\nexport function setChatSessionEditorText<TExtraEntry extends ChatTranscriptEntryLike>(\n\tstate: ChatSessionHostState<TExtraEntry>,\n\ttext: string,\n): void {\n\tstate.inputBuffer = text;\n\tstate.isBashMode = text.trimStart().startsWith(\"!\");\n\tstate.editor?.setText(text);\n}\n\nexport function setEditorPlaceholder(editor: EditorComponent, placeholder: string | undefined): void {\n\tconst candidate = editor as EditorComponent & {\n\t\tsetPlaceholder?: (value: string | undefined) => void;\n\t};\n\tcandidate.setPlaceholder?.(placeholder);\n}\n\nexport function setEditorBorderColor(editor: EditorComponent, borderColor: (text: string) => string): void {\n\tconst candidate = editor as EditorComponent & {\n\t\tborderColor?: (text: string) => string;\n\t};\n\tif (candidate.borderColor !== undefined) candidate.borderColor = borderColor;\n}\n\nexport function setEditorFocused(editor: EditorComponent, focused: boolean): void {\n\tconst candidate = editor as EditorComponent & Partial<Focusable>;\n\tif (\"focused\" in candidate) candidate.focused = focused;\n}\n\nfunction createInheritedEditor<TExtraEntry extends ChatTranscriptEntryLike>(\n\ttui: TUI,\n\teditorTheme: EditorTheme,\n\tkeybindings: unknown,\n\teditorFactory: ChatSessionHostOpts<TExtraEntry>[\"editorFactory\"],\n): EditorComponent | undefined {\n\tif (!editorFactory) return undefined;\n\ttry {\n\t\treturn editorFactory(tui, editorTheme, keybindings);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\ntype EditorCursor = { line: number; col: number };\ntype CursorAwareEditor = EditorComponent & { getCursor(): EditorCursor };\n\nfunction hasCursor(editor: EditorComponent | undefined): editor is CursorAwareEditor {\n\treturn typeof (editor as Partial<CursorAwareEditor> | undefined)?.getCursor === \"function\";\n}\n\nexport function chatSessionEditorAccess<TExtraEntry extends ChatTranscriptEntryLike>(\n\tstate: ChatSessionHostState<TExtraEntry>,\n): {\n\tinsertTextAtCursor: (text: string) => void;\n\tgetText: () => string;\n\tsetText: (text: string) => void;\n\tgetCursor?: () => EditorCursor;\n} {\n\tconst editor = state.editor;\n\treturn {\n\t\tinsertTextAtCursor: (text: string) => {\n\t\t\tif (state.editor?.insertTextAtCursor) {\n\t\t\t\tstate.editor.insertTextAtCursor(text);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetChatSessionEditorText(state, `${state.inputBuffer}${text}`);\n\t\t},\n\t\tgetText: () => state.inputBuffer,\n\t\tsetText: (text: string) => setChatSessionEditorText(state, text),\n\t\t...(hasCursor(editor) ? { getCursor: () => editor.getCursor() } : {}),\n\t};\n}\n\nasync function openChatSessionExternalEditor<TExtraEntry extends ChatTranscriptEntryLike>(\n\tstate: ChatSessionHostState<TExtraEntry>,\n): Promise<void> {\n\tif (!state.editor) return;\n\tconst host = state.tui;\n\tif (!host) return;\n\tconst currentText = state.editor.getExpandedText?.() ?? state.editor.getText();\n\tconst updated = await openExternalEditorForText(currentText, host, {\n\t\tshowWarning: (message) => notifyChatSessionWarning(state, message),\n\t\tshowStatus: (message) => notifyChatSessionStatus(state, message),\n\t});\n\tif (updated !== undefined) setChatSessionEditorText(state, updated);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-entry.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/custom-entry.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,SAAS,EAAgB,MAAM,wBAAwB,CAAC;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"custom-entry.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/custom-entry.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,SAAS,EAAgB,MAAM,wBAAwB,CAAC;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAIpE,2DAA2D;AAC3D,qBAAa,oBAAqB,SAAQ,SAAS;IAClD,OAAO,CAAC,eAAe,CAAC,CAAY;IACpC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAS;IAE1B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuB;IAC7C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;IAEzC,YAAY,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,SAAI,EAM9E;IAED,UAAU,IAAI,OAAO,CAEpB;IAED,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAInC;IAED,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAGpC;IAEQ,UAAU,IAAI,IAAI,CAG1B;IAED,OAAO,CAAC,OAAO;CAiBf"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Box, Container, Spacer, Text } from "@earendil-works/pi-tui";
|
|
2
2
|
import { theme } from "../theme/theme.js";
|
|
3
|
+
import { keyHint, keyText } from "./keybinding-hints.js";
|
|
3
4
|
/** Renders an extension-owned persistent session entry. */
|
|
4
5
|
export class CustomEntryComponent extends Container {
|
|
5
6
|
customComponent;
|
|
@@ -36,7 +37,7 @@ export class CustomEntryComponent extends Container {
|
|
|
36
37
|
this.customComponent = undefined;
|
|
37
38
|
let component;
|
|
38
39
|
try {
|
|
39
|
-
component = this.renderer(this.entry, { expanded: this.expanded }, theme);
|
|
40
|
+
component = this.renderer(this.entry, { expanded: this.expanded, keyText, keyHint }, theme);
|
|
40
41
|
}
|
|
41
42
|
catch (error) {
|
|
42
43
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-entry.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/custom-entry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAGtE,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"custom-entry.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/custom-entry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAGtE,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEzD,2DAA2D;AAC3D,MAAM,OAAO,oBAAqB,SAAQ,SAAS;IAC1C,eAAe,CAAa;IAC5B,QAAQ,GAAG,KAAK,CAAC;IACjB,SAAS,CAAS;IAET,KAAK,CAAuB;IAC5B,QAAQ,CAAgB;IAEzC,YAAY,KAA2B,EAAE,QAAuB,EAAE,SAAS,GAAG,CAAC;QAC9E,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,EAAE,CAAC;IAChB,CAAC;IAED,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C,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAC1G,SAAS,GAAG,GAAG,CAAC;QACjB,CAAC;QACD,IAAI,CAAC,SAAS;YAAE,OAAO;QACvB,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QACjC,IAAI,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC1B,CAAC;CACD","sourcesContent":["import type { Component } from \"@earendil-works/pi-tui\";\nimport { Box, Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport type { EntryRenderer } from \"../../../core/extensions/types.ts\";\nimport type { CustomEntry } from \"../../../core/session-manager.ts\";\nimport { theme } from \"../theme/theme.js\";\nimport { keyHint, keyText } from \"./keybinding-hints.js\";\n\n/** Renders an extension-owned persistent session entry. */\nexport class CustomEntryComponent extends Container {\n\tprivate customComponent?: Component;\n\tprivate expanded = false;\n\tprivate outputPad: number;\n\n\tprivate readonly entry: CustomEntry<unknown>;\n\tprivate readonly renderer: EntryRenderer;\n\n\tconstructor(entry: CustomEntry<unknown>, renderer: EntryRenderer, outputPad = 1) {\n\t\tsuper();\n\t\tthis.entry = entry;\n\t\tthis.renderer = renderer;\n\t\tthis.outputPad = outputPad;\n\t\tthis.rebuild();\n\t}\n\n\thasContent(): boolean {\n\t\treturn this.customComponent !== undefined;\n\t}\n\n\tsetExpanded(expanded: boolean): void {\n\t\tif (this.expanded === expanded) return;\n\t\tthis.expanded = expanded;\n\t\tthis.rebuild();\n\t}\n\n\tsetOutputPad(outputPad: number): void {\n\t\tthis.outputPad = outputPad;\n\t\tthis.rebuild();\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tthis.rebuild();\n\t}\n\n\tprivate rebuild(): void {\n\t\tthis.clear();\n\t\tthis.customComponent = undefined;\n\t\tlet component: Component | undefined;\n\t\ttry {\n\t\t\tcomponent = this.renderer(this.entry, { expanded: this.expanded, keyText, keyHint }, theme);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tconst box = new Box(this.outputPad, 1, (text) => theme.bg(\"customMessageBg\", text));\n\t\t\tbox.addChild(new Text(theme.fg(\"error\", `[${this.entry.customType}] renderer failed: ${message}`), 0, 0));\n\t\t\tcomponent = box;\n\t\t}\n\t\tif (!component) return;\n\t\tthis.customComponent = component;\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(component);\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-message.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/custom-message.ts"],"names":[],"mappings":"AAEA,OAAO,EAAO,SAAS,EAAY,KAAK,aAAa,EAAgB,MAAM,wBAAwB,CAAC;AACpG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"custom-message.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/custom-message.ts"],"names":[],"mappings":"AAEA,OAAO,EAAO,SAAS,EAAY,KAAK,aAAa,EAAgB,MAAM,wBAAwB,CAAC;AACpG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAiB/D;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,SAAS;IACpD,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,cAAc,CAAC,CAAkB;IACzC,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,eAAe,CAAC,CAAY;IACpC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,WAAW,CAAU;IAE7B,YACC,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,EAC/B,cAAc,CAAC,EAAE,eAAe,EAChC,aAAa,GAAE,aAAkC,EACjD,SAAS,SAAI,EACb,WAAW,UAAO,EAelB;IAED,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAKnC;IAED,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAIpC;IAEQ,UAAU,IAAI,IAAI,CAG1B;IAED,OAAO,CAAC,OAAO;CA0Ff"}
|