@struktoai/mirage-agents 0.0.3 → 0.0.5-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/README.md +4 -3
- package/dist/chunk-IMI7BLEG.js +142 -0
- package/dist/chunk-IMI7BLEG.js.map +1 -0
- package/dist/chunk-XEQB7N3F.js +79 -0
- package/dist/chunk-XEQB7N3F.js.map +1 -0
- package/dist/chunk-Y4G25V5V.js +139 -0
- package/dist/chunk-Y4G25V5V.js.map +1 -0
- package/dist/{chunk-ODKR5YZI.js → chunk-ZPXFVDYT.js} +3 -4
- package/dist/chunk-ZPXFVDYT.js.map +1 -0
- package/dist/claude-agent-sdk/index.d.ts +5 -10
- package/dist/claude-agent-sdk/index.js +20 -111
- package/dist/claude-agent-sdk/index.js.map +1 -1
- package/dist/file-version-Clij-pms.d.ts +22 -0
- package/dist/langchain/index.d.ts +1 -1
- package/dist/langchain/index.js +1 -3
- package/dist/langchain/index.js.map +1 -1
- package/dist/mcp/index.d.ts +14 -0
- package/dist/mcp/index.js +100 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/openai/index.d.ts +14 -3
- package/dist/openai/index.js +82 -2
- package/dist/openai/index.js.map +1 -1
- package/dist/opencode/index.d.ts +8 -18
- package/dist/opencode/index.js +66 -67
- package/dist/opencode/index.js.map +1 -1
- package/dist/pi/index.d.ts +13 -8
- package/dist/pi/index.js +66 -37
- package/dist/pi/index.js.map +1 -1
- package/dist/prompt-B_6pxgjj.d.ts +11 -0
- package/dist/tool-descriptions-7CgIovZc.d.ts +33 -0
- package/dist/vercel/index.d.ts +3 -67
- package/dist/vercel/index.js +28 -102
- package/dist/vercel/index.js.map +1 -1
- package/package.json +32 -25
- package/dist/chunk-ODKR5YZI.js.map +0 -1
- package/dist/prompt-Ca4hc1Ul.d.ts +0 -11
|
@@ -1,115 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EDIT_DESCRIPTION,
|
|
3
|
+
EXECUTE_DESCRIPTION,
|
|
4
|
+
GREP_DESCRIPTION,
|
|
5
|
+
LS_DESCRIPTION,
|
|
6
|
+
MirageToolOperations,
|
|
7
|
+
READ_DESCRIPTION,
|
|
8
|
+
WRITE_DESCRIPTION
|
|
9
|
+
} from "../chunk-Y4G25V5V.js";
|
|
1
10
|
import {
|
|
2
11
|
MIRAGE_SYSTEM_PROMPT,
|
|
3
12
|
buildSystemPrompt
|
|
4
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-ZPXFVDYT.js";
|
|
14
|
+
import "../chunk-XEQB7N3F.js";
|
|
5
15
|
|
|
6
16
|
// src/claude-agent-sdk/server.ts
|
|
7
|
-
import { VERSION
|
|
17
|
+
import { VERSION } from "@struktoai/mirage-core";
|
|
8
18
|
import { createSdkMcpServer, tool } from "@anthropic-ai/claude-agent-sdk";
|
|
9
19
|
import { z } from "zod";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function decode(value) {
|
|
13
|
-
if (value === null || value === void 0) return "";
|
|
14
|
-
return new TextDecoder("utf-8").decode(value);
|
|
15
|
-
}
|
|
16
|
-
function ioToStr(io) {
|
|
17
|
-
const stdout = io.stdoutText;
|
|
18
|
-
const stderr = io.stderrText;
|
|
19
|
-
if (stderr) return stdout ? `${stdout}
|
|
20
|
-
${stderr}` : stderr;
|
|
21
|
-
return stdout;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// src/claude-agent-sdk/descriptions.ts
|
|
25
|
-
var EXECUTE_DESCRIPTION = "Run a shell-style command on the Mirage virtual filesystem. Supports cat, grep, find, head, tail, ls, wc, sort, uniq, tee, pipe, and any other Unix command on mounted resources (S3, disk, RAM, etc.). Also supports reading structured files: cat on .parquet/.orc/.csv returns a table.";
|
|
26
|
-
var READ_DESCRIPTION = "Read the contents of a file on the Mirage virtual filesystem. Returns line-numbered text. Optionally pass 'offset' (default 0) to start at a given line and 'limit' (default 2000) to cap the number of lines returned.";
|
|
27
|
-
var WRITE_DESCRIPTION = "Write content to a new file on the Mirage virtual filesystem. Fails if the file already exists; use edit to modify an existing file.";
|
|
28
|
-
var EDIT_DESCRIPTION = "Replace a string in an existing file on the Mirage virtual filesystem. Fails if old_string is not found or appears more than once. Pass replace_all=true (default false) to replace every occurrence.";
|
|
29
|
-
var LS_DESCRIPTION = "List files and directories at the given path on the Mirage virtual filesystem.";
|
|
30
|
-
var GREP_DESCRIPTION = "Search for a pattern in files on the Mirage virtual filesystem. Supports regex. Searches recursively under path.";
|
|
31
|
-
|
|
32
|
-
// src/claude-agent-sdk/server.ts
|
|
33
|
-
function textResult(text) {
|
|
34
|
-
return { content: [{ type: "text", text }] };
|
|
35
|
-
}
|
|
36
|
-
function errorResult(text) {
|
|
37
|
-
return { content: [{ type: "text", text }], isError: true };
|
|
38
|
-
}
|
|
39
|
-
function ioResult(io) {
|
|
40
|
-
const result = textResult(ioToStr(io));
|
|
41
|
-
if (io.exitCode !== 0) result.isError = true;
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
function shQuote(value) {
|
|
45
|
-
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
46
|
-
}
|
|
47
|
-
async function ensureParents(ws, path) {
|
|
48
|
-
const parent = gnuDirname(path);
|
|
49
|
-
if (parent === "/" || parent === "" || parent === ".") return;
|
|
50
|
-
if (await ws.fs.exists(parent)) return;
|
|
51
|
-
await ensureParents(ws, parent);
|
|
52
|
-
try {
|
|
53
|
-
await ws.fs.mkdir(parent);
|
|
54
|
-
} catch (err) {
|
|
55
|
-
if (!await ws.fs.exists(parent)) throw err;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
async function runExecute(ws, command) {
|
|
59
|
-
return ioResult(await ws.execute(command));
|
|
60
|
-
}
|
|
61
|
-
async function runRead(ws, path, offset = 0, limit = 2e3) {
|
|
62
|
-
let data;
|
|
63
|
-
try {
|
|
64
|
-
data = await ws.fs.readFile(path);
|
|
65
|
-
} catch (err) {
|
|
66
|
-
if (!await ws.fs.exists(path)) {
|
|
67
|
-
return errorResult(`Error: file '${path}' not found`);
|
|
68
|
-
}
|
|
69
|
-
return errorResult(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
|
70
|
-
}
|
|
71
|
-
const text = decode(data);
|
|
72
|
-
const raw = text.length === 0 ? [] : text.split(/(?<=\n)/);
|
|
73
|
-
const lines = raw.length > 0 && raw[raw.length - 1] === "" ? raw.slice(0, -1) : raw;
|
|
74
|
-
const sliced = lines.slice(offset, offset + limit);
|
|
75
|
-
const numbered = sliced.map((line, i) => `${String(i + offset + 1).padStart(6)} ${line}`);
|
|
76
|
-
return textResult(numbered.join(""));
|
|
77
|
-
}
|
|
78
|
-
async function runWrite(ws, path, content) {
|
|
79
|
-
if (await ws.fs.exists(path)) {
|
|
80
|
-
return errorResult(`Error: file '${path}' already exists`);
|
|
81
|
-
}
|
|
82
|
-
await ensureParents(ws, path);
|
|
83
|
-
await ws.fs.writeFile(path, content);
|
|
84
|
-
return textResult(`Written: ${path}`);
|
|
85
|
-
}
|
|
86
|
-
async function runEdit(ws, path, oldString, newString, replaceAll = false) {
|
|
87
|
-
let content;
|
|
88
|
-
try {
|
|
89
|
-
content = await ws.fs.readFileText(path);
|
|
90
|
-
} catch {
|
|
91
|
-
return errorResult(`Error: file '${path}' not found`);
|
|
92
|
-
}
|
|
93
|
-
const count = content.split(oldString).length - 1;
|
|
94
|
-
if (count === 0) {
|
|
95
|
-
return errorResult(`Error: string not found in file: '${oldString}'`);
|
|
96
|
-
}
|
|
97
|
-
if (count > 1 && !replaceAll) {
|
|
98
|
-
return errorResult(`Error: string appears ${String(count)} times. Pass replace_all=true`);
|
|
99
|
-
}
|
|
100
|
-
const newContent = replaceAll ? content.split(oldString).join(newString) : content.replace(oldString, newString);
|
|
101
|
-
await ws.fs.writeFile(path, newContent);
|
|
102
|
-
const occurrences = replaceAll ? count : 1;
|
|
103
|
-
return textResult(`Edited: ${path} (${String(occurrences)} occurrence(s))`);
|
|
104
|
-
}
|
|
105
|
-
async function runLs(ws, path) {
|
|
106
|
-
return ioResult(await ws.execute(`ls ${shQuote(path)}`));
|
|
107
|
-
}
|
|
108
|
-
async function runGrep(ws, pattern, path) {
|
|
109
|
-
const io = await ws.execute(`grep -rn ${shQuote(pattern)} ${shQuote(path)}`);
|
|
110
|
-
return textResult(ioToStr(io));
|
|
111
|
-
}
|
|
112
|
-
function MirageServer(workspace) {
|
|
20
|
+
function MirageServer(workspace, options = {}) {
|
|
21
|
+
const operations = new MirageToolOperations(workspace, options);
|
|
113
22
|
return createSdkMcpServer({
|
|
114
23
|
name: "mirage",
|
|
115
24
|
version: VERSION,
|
|
@@ -119,20 +28,20 @@ function MirageServer(workspace) {
|
|
|
119
28
|
"execute_command",
|
|
120
29
|
EXECUTE_DESCRIPTION,
|
|
121
30
|
{ command: z.string() },
|
|
122
|
-
(args) =>
|
|
31
|
+
(args) => operations.execute(args.command)
|
|
123
32
|
),
|
|
124
33
|
tool(
|
|
125
34
|
"read",
|
|
126
35
|
READ_DESCRIPTION,
|
|
127
36
|
{ path: z.string(), offset: z.number().optional(), limit: z.number().optional() },
|
|
128
|
-
(args) =>
|
|
37
|
+
(args) => operations.read(args.path, args.offset, args.limit),
|
|
129
38
|
{ annotations: { readOnlyHint: true } }
|
|
130
39
|
),
|
|
131
40
|
tool(
|
|
132
41
|
"write",
|
|
133
42
|
WRITE_DESCRIPTION,
|
|
134
43
|
{ path: z.string(), content: z.string() },
|
|
135
|
-
(args) =>
|
|
44
|
+
(args) => operations.write(args.path, args.content)
|
|
136
45
|
),
|
|
137
46
|
tool(
|
|
138
47
|
"edit",
|
|
@@ -143,16 +52,16 @@ function MirageServer(workspace) {
|
|
|
143
52
|
new_string: z.string(),
|
|
144
53
|
replace_all: z.boolean().optional()
|
|
145
54
|
},
|
|
146
|
-
(args) =>
|
|
55
|
+
(args) => operations.edit(args.path, args.old_string, args.new_string, args.replace_all)
|
|
147
56
|
),
|
|
148
|
-
tool("ls", LS_DESCRIPTION, { path: z.string() }, (args) =>
|
|
57
|
+
tool("ls", LS_DESCRIPTION, { path: z.string() }, (args) => operations.ls(args.path), {
|
|
149
58
|
annotations: { readOnlyHint: true }
|
|
150
59
|
}),
|
|
151
60
|
tool(
|
|
152
61
|
"grep",
|
|
153
62
|
GREP_DESCRIPTION,
|
|
154
63
|
{ pattern: z.string(), path: z.string() },
|
|
155
|
-
(args) =>
|
|
64
|
+
(args) => operations.grep(args.pattern, args.path),
|
|
156
65
|
{ annotations: { readOnlyHint: true } }
|
|
157
66
|
)
|
|
158
67
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/claude-agent-sdk/server.ts","../../src/io-text.ts","../../src/claude-agent-sdk/descriptions.ts","../../src/claude-agent-sdk/options.ts"],"sourcesContent":["// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n\nimport type { ExecuteResult, Workspace } from '@struktoai/mirage-core'\nimport { VERSION, gnuDirname } from '@struktoai/mirage-core'\nimport { createSdkMcpServer, tool } from '@anthropic-ai/claude-agent-sdk'\nimport { z } from 'zod'\nimport { decode, ioToStr } from '../io-text.ts'\nimport {\n EDIT_DESCRIPTION,\n EXECUTE_DESCRIPTION,\n GREP_DESCRIPTION,\n LS_DESCRIPTION,\n READ_DESCRIPTION,\n WRITE_DESCRIPTION,\n} from './descriptions.ts'\n\nexport interface ToolResult {\n [key: string]: unknown\n content: { type: 'text'; text: string }[]\n isError?: boolean\n}\n\nfunction textResult(text: string): ToolResult {\n return { content: [{ type: 'text', text }] }\n}\n\nfunction errorResult(text: string): ToolResult {\n return { content: [{ type: 'text', text }], isError: true }\n}\n\nfunction ioResult(io: ExecuteResult): ToolResult {\n const result = textResult(ioToStr(io))\n if (io.exitCode !== 0) result.isError = true\n return result\n}\n\nfunction shQuote(value: string): string {\n return `'${value.replace(/'/g, \"'\\\\''\")}'`\n}\n\nasync function ensureParents(ws: Workspace, path: string): Promise<void> {\n const parent = gnuDirname(path)\n if (parent === '/' || parent === '' || parent === '.') return\n if (await ws.fs.exists(parent)) return\n await ensureParents(ws, parent)\n try {\n await ws.fs.mkdir(parent)\n } catch (err) {\n if (!(await ws.fs.exists(parent))) throw err\n }\n}\n\nexport async function runExecute(ws: Workspace, command: string): Promise<ToolResult> {\n return ioResult(await ws.execute(command))\n}\n\nexport async function runRead(\n ws: Workspace,\n path: string,\n offset = 0,\n limit = 2000,\n): Promise<ToolResult> {\n let data: Uint8Array\n try {\n data = await ws.fs.readFile(path)\n } catch (err) {\n if (!(await ws.fs.exists(path))) {\n return errorResult(`Error: file '${path}' not found`)\n }\n return errorResult(`Error: ${err instanceof Error ? err.message : String(err)}`)\n }\n const text = decode(data)\n const raw = text.length === 0 ? [] : text.split(/(?<=\\n)/)\n const lines = raw.length > 0 && raw[raw.length - 1] === '' ? raw.slice(0, -1) : raw\n const sliced = lines.slice(offset, offset + limit)\n const numbered = sliced.map((line, i) => `${String(i + offset + 1).padStart(6)}\\t${line}`)\n return textResult(numbered.join(''))\n}\n\nexport async function runWrite(ws: Workspace, path: string, content: string): Promise<ToolResult> {\n if (await ws.fs.exists(path)) {\n return errorResult(`Error: file '${path}' already exists`)\n }\n await ensureParents(ws, path)\n await ws.fs.writeFile(path, content)\n return textResult(`Written: ${path}`)\n}\n\nexport async function runEdit(\n ws: Workspace,\n path: string,\n oldString: string,\n newString: string,\n replaceAll = false,\n): Promise<ToolResult> {\n let content: string\n try {\n content = await ws.fs.readFileText(path)\n } catch {\n return errorResult(`Error: file '${path}' not found`)\n }\n const count = content.split(oldString).length - 1\n if (count === 0) {\n return errorResult(`Error: string not found in file: '${oldString}'`)\n }\n if (count > 1 && !replaceAll) {\n return errorResult(`Error: string appears ${String(count)} times. Pass replace_all=true`)\n }\n const newContent = replaceAll\n ? content.split(oldString).join(newString)\n : content.replace(oldString, newString)\n await ws.fs.writeFile(path, newContent)\n const occurrences = replaceAll ? count : 1\n return textResult(`Edited: ${path} (${String(occurrences)} occurrence(s))`)\n}\n\nexport async function runLs(ws: Workspace, path: string): Promise<ToolResult> {\n return ioResult(await ws.execute(`ls ${shQuote(path)}`))\n}\n\nexport async function runGrep(ws: Workspace, pattern: string, path: string): Promise<ToolResult> {\n const io = await ws.execute(`grep -rn ${shQuote(pattern)} ${shQuote(path)}`)\n return textResult(ioToStr(io))\n}\n\nexport function MirageServer(workspace: Workspace) {\n return createSdkMcpServer({\n name: 'mirage',\n version: VERSION,\n alwaysLoad: true,\n tools: [\n tool('execute_command', EXECUTE_DESCRIPTION, { command: z.string() }, (args) =>\n runExecute(workspace, args.command),\n ),\n tool(\n 'read',\n READ_DESCRIPTION,\n { path: z.string(), offset: z.number().optional(), limit: z.number().optional() },\n (args) => runRead(workspace, args.path, args.offset, args.limit),\n { annotations: { readOnlyHint: true } },\n ),\n tool('write', WRITE_DESCRIPTION, { path: z.string(), content: z.string() }, (args) =>\n runWrite(workspace, args.path, args.content),\n ),\n tool(\n 'edit',\n EDIT_DESCRIPTION,\n {\n path: z.string(),\n old_string: z.string(),\n new_string: z.string(),\n replace_all: z.boolean().optional(),\n },\n (args) => runEdit(workspace, args.path, args.old_string, args.new_string, args.replace_all),\n ),\n tool('ls', LS_DESCRIPTION, { path: z.string() }, (args) => runLs(workspace, args.path), {\n annotations: { readOnlyHint: true },\n }),\n tool(\n 'grep',\n GREP_DESCRIPTION,\n { pattern: z.string(), path: z.string() },\n (args) => runGrep(workspace, args.pattern, args.path),\n { annotations: { readOnlyHint: true } },\n ),\n ],\n })\n}\n","// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n\nimport type { ExecuteResult } from '@struktoai/mirage-core'\n\nexport function decode(value: Uint8Array | null | undefined): string {\n if (value === null || value === undefined) return ''\n return new TextDecoder('utf-8').decode(value)\n}\n\nexport function ioToStr(io: ExecuteResult): string {\n const stdout = io.stdoutText\n const stderr = io.stderrText\n if (stderr) return stdout ? `${stdout}\\n${stderr}` : stderr\n return stdout\n}\n","// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n\nexport const EXECUTE_DESCRIPTION =\n 'Run a shell-style command on the Mirage virtual filesystem. ' +\n 'Supports cat, grep, find, head, tail, ls, wc, sort, uniq, tee, pipe, ' +\n 'and any other Unix command on mounted resources (S3, disk, RAM, etc.). ' +\n 'Also supports reading structured files: cat on .parquet/.orc/.csv returns a table.'\n\nexport const READ_DESCRIPTION =\n 'Read the contents of a file on the Mirage virtual filesystem. ' +\n 'Returns line-numbered text. ' +\n \"Optionally pass 'offset' (default 0) to start at a given line \" +\n \"and 'limit' (default 2000) to cap the number of lines returned.\"\n\nexport const WRITE_DESCRIPTION =\n 'Write content to a new file on the Mirage virtual filesystem. ' +\n 'Fails if the file already exists; use edit to modify an existing file.'\n\nexport const EDIT_DESCRIPTION =\n 'Replace a string in an existing file on the Mirage virtual filesystem. ' +\n 'Fails if old_string is not found or appears more than once. ' +\n 'Pass replace_all=true (default false) to replace every occurrence.'\n\nexport const LS_DESCRIPTION =\n 'List files and directories at the given path on the Mirage virtual filesystem.'\n\nexport const GREP_DESCRIPTION =\n 'Search for a pattern in files on the Mirage virtual filesystem. ' +\n 'Supports regex. Searches recursively under path.'\n","// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n\nimport type { Workspace } from '@struktoai/mirage-core'\nimport type { Options } from '@anthropic-ai/claude-agent-sdk'\nimport { buildSystemPrompt } from '../prompt.ts'\nimport { MirageServer } from './server.ts'\n\nexport interface BuildOptionsOptions {\n systemPrompt?: string\n}\n\nexport function buildOptions(workspace: Workspace, opts: BuildOptionsOptions = {}): Options {\n return {\n mcpServers: { mirage: MirageServer(workspace) },\n allowedTools: ['mcp__mirage__*'],\n systemPrompt: opts.systemPrompt ?? buildSystemPrompt({ workspace }),\n }\n}\n"],"mappings":";;;;;;AAeA,SAAS,SAAS,kBAAkB;AACpC,SAAS,oBAAoB,YAAY;AACzC,SAAS,SAAS;;;ACDX,SAAS,OAAO,OAA8C;AACnE,MAAI,UAAU,QAAQ,UAAU,OAAW,QAAO;AAClD,SAAO,IAAI,YAAY,OAAO,EAAE,OAAO,KAAK;AAC9C;AAEO,SAAS,QAAQ,IAA2B;AACjD,QAAM,S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SAAS,WAAW,KAAK,MAAM,KAAK,OAAO;AAAA,MAC7C;AAAA,MACA;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,UACE,MAAM,EAAE,OAAO;AAAA,UACf,YAAY,EAAE,OAAO;AAAA,UACrB,YAAY,EAAE,OAAO;AAAA,UACrB,aAAa,EAAE,QAAQ,EAAE,SAAS;AAAA,QACpC;AAAA,QACA,CAAC,SAAS,QAAQ,WAAW,KAAK,MAAM,KAAK,YAAY,KAAK,YAAY,KAAK,WAAW;AAAA,MAC5F;AAAA,MACA,KAAK,MAAM,gBAAgB,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,SAAS,MAAM,WAAW,KAAK,IAAI,GAAG;AAAA,QACtF,aAAa,EAAE,cAAc,KAAK;AAAA,MACpC,CAAC;AAAA,MACD;AAAA,QACE;AAAA,QACA;AAAA,QACA,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,EAAE,OAAO,EAAE;AAAA,QACxC,CAAC,SAAS,QAAQ,WAAW,KAAK,SAAS,KAAK,IAAI;AAAA,QACpD,EAAE,aAAa,EAAE,cAAc,KAAK,EAAE;AAAA,MACxC;AAAA,IACF;AAAA,EACF,CAAC;AACH;;;AG5JO,SAAS,aAAa,WAAsB,OAA4B,CAAC,GAAY;AAC1F,SAAO;AAAA,IACL,YAAY,EAAE,QAAQ,aAAa,SAAS,EAAE;AAAA,IAC9C,cAAc,CAAC,gBAAgB;AAAA,IAC/B,cAAc,KAAK,gBAAgB,kBAAkB,EAAE,UAAU,CAAC;AAAA,EACpE;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/claude-agent-sdk/server.ts","../../src/claude-agent-sdk/options.ts"],"sourcesContent":["// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n\nimport type { Workspace } from '@struktoai/mirage-core'\nimport { VERSION } from '@struktoai/mirage-core'\nimport { createSdkMcpServer, tool } from '@anthropic-ai/claude-agent-sdk'\nimport { z } from 'zod'\nimport {\n MirageToolOperations,\n type MirageToolOperationsOptions,\n type ToolResult,\n} from '../tool-operations.ts'\nimport {\n EDIT_DESCRIPTION,\n EXECUTE_DESCRIPTION,\n GREP_DESCRIPTION,\n LS_DESCRIPTION,\n READ_DESCRIPTION,\n WRITE_DESCRIPTION,\n} from './descriptions.ts'\n\nexport async function runExecute(ws: Workspace, command: string): Promise<ToolResult> {\n return new MirageToolOperations(ws).execute(command)\n}\n\nexport async function runRead(\n ws: Workspace,\n path: string,\n offset = 0,\n limit = 2000,\n): Promise<ToolResult> {\n return new MirageToolOperations(ws).read(path, offset, limit)\n}\n\nexport async function runWrite(ws: Workspace, path: string, content: string): Promise<ToolResult> {\n return new MirageToolOperations(ws).write(path, content)\n}\n\nexport async function runEdit(\n ws: Workspace,\n path: string,\n oldString: string,\n newString: string,\n replaceAll = false,\n): Promise<ToolResult> {\n return new MirageToolOperations(ws).edit(path, oldString, newString, replaceAll)\n}\n\nexport async function runLs(ws: Workspace, path: string): Promise<ToolResult> {\n return new MirageToolOperations(ws).ls(path)\n}\n\nexport async function runGrep(ws: Workspace, pattern: string, path: string): Promise<ToolResult> {\n return new MirageToolOperations(ws).grep(pattern, path)\n}\n\nexport function MirageServer(workspace: Workspace, options: MirageToolOperationsOptions = {}) {\n const operations = new MirageToolOperations(workspace, options)\n return createSdkMcpServer({\n name: 'mirage',\n version: VERSION,\n alwaysLoad: true,\n tools: [\n tool('execute_command', EXECUTE_DESCRIPTION, { command: z.string() }, (args) =>\n operations.execute(args.command),\n ),\n tool(\n 'read',\n READ_DESCRIPTION,\n { path: z.string(), offset: z.number().optional(), limit: z.number().optional() },\n (args) => operations.read(args.path, args.offset, args.limit),\n { annotations: { readOnlyHint: true } },\n ),\n tool('write', WRITE_DESCRIPTION, { path: z.string(), content: z.string() }, (args) =>\n operations.write(args.path, args.content),\n ),\n tool(\n 'edit',\n EDIT_DESCRIPTION,\n {\n path: z.string(),\n old_string: z.string(),\n new_string: z.string(),\n replace_all: z.boolean().optional(),\n },\n (args) => operations.edit(args.path, args.old_string, args.new_string, args.replace_all),\n ),\n tool('ls', LS_DESCRIPTION, { path: z.string() }, (args) => operations.ls(args.path), {\n annotations: { readOnlyHint: true },\n }),\n tool(\n 'grep',\n GREP_DESCRIPTION,\n { pattern: z.string(), path: z.string() },\n (args) => operations.grep(args.pattern, args.path),\n { annotations: { readOnlyHint: true } },\n ),\n ],\n })\n}\n","// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n\nimport type { Workspace } from '@struktoai/mirage-core'\nimport type { Options } from '@anthropic-ai/claude-agent-sdk'\nimport { buildSystemPrompt } from '../prompt.ts'\nimport { MirageServer } from './server.ts'\n\nexport interface BuildOptionsOptions {\n systemPrompt?: string\n}\n\nexport function buildOptions(workspace: Workspace, opts: BuildOptionsOptions = {}): Options {\n return {\n mcpServers: { mirage: MirageServer(workspace) },\n allowedTools: ['mcp__mirage__*'],\n systemPrompt: opts.systemPrompt ?? buildSystemPrompt({ workspace }),\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,SA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,QACnF,aAAa,EAAE,cAAc,KAAK;AAAA,MACpC,CAAC;AAAA,MACD;AAAA,QACE;AAAA,QACA;AAAA,QACA,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,EAAE,OAAO,EAAE;AAAA,QACxC,CAAC,SAAS,WAAW,KAAK,KAAK,SAAS,KAAK,IAAI;AAAA,QACjD,EAAE,aAAa,EAAE,cAAc,KAAK,EAAE;AAAA,MACxC;AAAA,IACF;AAAA,EACF,CAAC;AACH;;;ACvFO,SAAS,aAAa,WAAsB,OAA4B,CAAC,GAAY;AAC1F,SAAO;AAAA,IACL,YAAY,EAAE,QAAQ,aAAa,SAAS,EAAE;AAAA,IAC9C,cAAc,CAAC,gBAAgB;AAAA,IAC/B,cAAc,KAAK,gBAAgB,kBAAkB,EAAE,UAAU,CAAC;AAAA,EACpE;AACF;","names":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Workspace } from '@struktoai/mirage-core';
|
|
2
|
+
|
|
3
|
+
declare class StaleMirageFileError extends Error {
|
|
4
|
+
readonly path: string;
|
|
5
|
+
constructor(path: string);
|
|
6
|
+
}
|
|
7
|
+
declare class FileVersionTracker {
|
|
8
|
+
private readonly ws;
|
|
9
|
+
private readonly enabled;
|
|
10
|
+
private readonly readVersions;
|
|
11
|
+
private readonly editVersions;
|
|
12
|
+
constructor(ws: Workspace, enabled?: boolean);
|
|
13
|
+
private currentVersion;
|
|
14
|
+
private assertVersion;
|
|
15
|
+
private recordWrite;
|
|
16
|
+
read(path: string): Promise<Buffer>;
|
|
17
|
+
readForEdit(path: string): Promise<Buffer>;
|
|
18
|
+
write(path: string, content: string): Promise<void>;
|
|
19
|
+
writeEdit(path: string, content: string): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { FileVersionTracker as F, StaleMirageFileError as S };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Workspace } from '@struktoai/mirage-node';
|
|
2
2
|
import { SandboxBackendProtocolV2, ExecuteResponse, LsResult, ReadResult, ReadRawResult, WriteResult, EditResult, GrepResult, GlobResult, FileUploadResponse, FileDownloadResponse } from 'deepagents';
|
|
3
|
-
export { B as BuildSystemPromptOptions, M as MIRAGE_SYSTEM_PROMPT, b as buildSystemPrompt } from '../prompt-
|
|
3
|
+
export { B as BuildSystemPromptOptions, M as MIRAGE_SYSTEM_PROMPT, b as buildSystemPrompt } from '../prompt-B_6pxgjj.js';
|
|
4
4
|
import '@struktoai/mirage-core';
|
|
5
5
|
|
|
6
6
|
interface LangchainWorkspaceOptions {
|
package/dist/langchain/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MIRAGE_SYSTEM_PROMPT,
|
|
3
3
|
buildSystemPrompt
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-ZPXFVDYT.js";
|
|
5
5
|
|
|
6
6
|
// src/langchain/convert.ts
|
|
7
7
|
function ioToExecuteResponse(io) {
|
|
@@ -106,7 +106,6 @@ function extOf(path) {
|
|
|
106
106
|
if (dot < 0) return "";
|
|
107
107
|
return path.slice(dot + 1).toLowerCase();
|
|
108
108
|
}
|
|
109
|
-
var MIRAGE_RENDERED_AS_TEXT = /* @__PURE__ */ new Set(["parquet", "h5", "hdf5", "feather"]);
|
|
110
109
|
function mimeFor(path) {
|
|
111
110
|
const ext = extOf(path);
|
|
112
111
|
if (ext === "json" || ext === "jsonl") return "application/json";
|
|
@@ -114,7 +113,6 @@ function mimeFor(path) {
|
|
|
114
113
|
if (ext === "html" || ext === "htm") return "text/html";
|
|
115
114
|
if (ext === "md") return "text/markdown";
|
|
116
115
|
if (TEXT_EXTENSIONS.has(ext)) return "text/plain";
|
|
117
|
-
if (MIRAGE_RENDERED_AS_TEXT.has(ext)) return "text/plain";
|
|
118
116
|
if (ext === "png") return "image/png";
|
|
119
117
|
if (ext === "jpg" || ext === "jpeg") return "image/jpeg";
|
|
120
118
|
if (ext === "pdf") return "application/pdf";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/langchain/convert.ts","../../src/langchain/backend.ts","../../src/langchain/messages.ts"],"sourcesContent":["// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n\nimport type { ExecuteResponse, FileInfo, GrepMatch } from 'deepagents'\n\ninterface IOLike {\n stdoutText: string\n stderrText: string\n exitCode: number | null\n}\n\nexport function ioToExecuteResponse(io: IOLike): ExecuteResponse {\n const stdout = io.stdoutText\n const stderr = io.stderrText\n let output = stdout\n if (stderr.length > 0) {\n output = stdout.length > 0 ? `${stdout}\\n${stderr}` : stderr\n }\n return { output, exitCode: io.exitCode, truncated: false }\n}\n\nexport function ioToGrepMatches(io: IOLike): GrepMatch[] {\n const stdout = io.stdoutText.trim()\n if (stdout.length === 0) return []\n const matches: GrepMatch[] = []\n for (const line of stdout.split('\\n')) {\n const firstColon = line.indexOf(':')\n if (firstColon < 0) continue\n const secondColon = line.indexOf(':', firstColon + 1)\n if (secondColon < 0) continue\n const path = line.slice(0, firstColon)\n const lineNumStr = line.slice(firstColon + 1, secondColon)\n const text = line.slice(secondColon + 1)\n const lineNum = Number.parseInt(lineNumStr, 10)\n if (Number.isNaN(lineNum)) continue\n matches.push({ path, line: lineNum, text })\n }\n return matches\n}\n\nexport function ioToFileInfos(io: IOLike): FileInfo[] {\n const stdout = io.stdoutText.trim()\n if (stdout.length === 0) return []\n const infos: FileInfo[] = []\n for (const raw of stdout.split('\\n')) {\n const entry = raw.trim()\n if (entry.length === 0) continue\n const isDir = entry.endsWith('/')\n infos.push({ path: isDir ? entry.slice(0, -1) : entry, is_dir: isDir })\n }\n return infos\n}\n","// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n\nimport type { Workspace } from '@struktoai/mirage-node'\nimport type {\n EditResult,\n ExecuteResponse,\n FileData,\n FileDownloadResponse,\n FileInfo,\n FileUploadResponse,\n GlobResult,\n GrepResult,\n LsResult,\n ReadRawResult,\n ReadResult,\n SandboxBackendProtocolV2 as SandboxBackendProtocol,\n WriteResult,\n} from 'deepagents'\nimport { ioToExecuteResponse, ioToFileInfos, ioToGrepMatches } from './convert.ts'\nimport { gnuDirname } from '@struktoai/mirage-core'\n\nconst TEXT_EXTENSIONS = new Set([\n 'txt',\n 'md',\n 'json',\n 'jsonl',\n 'yaml',\n 'yml',\n 'csv',\n 'tsv',\n 'xml',\n 'html',\n 'htm',\n 'js',\n 'mjs',\n 'cjs',\n 'ts',\n 'tsx',\n 'jsx',\n 'py',\n 'rb',\n 'rs',\n 'go',\n 'java',\n 'c',\n 'cpp',\n 'h',\n 'hpp',\n 'sh',\n 'bash',\n 'zsh',\n 'fish',\n 'sql',\n 'log',\n 'env',\n 'ini',\n 'toml',\n 'conf',\n 'cfg',\n])\n\nfunction shellQuote(s: string): string {\n if (/^[A-Za-z0-9_./-]+$/.test(s)) return s\n return `'${s.replaceAll(`'`, `'\\\\''`)}'`\n}\n\nasync function ensureParent(ws: Workspace, path: string): Promise<void> {\n const parent = gnuDirname(path)\n if (parent === '/' || parent === '' || parent === '.') return\n if (await ws.fs.exists(parent)) return\n await ensureParent(ws, parent)\n try {\n await ws.fs.mkdir(parent)\n } catch (err) {\n if (!(await ws.fs.exists(parent))) throw err\n }\n}\n\nfunction extOf(path: string): string {\n const dot = path.lastIndexOf('.')\n if (dot < 0) return ''\n return path.slice(dot + 1).toLowerCase()\n}\n\nconst MIRAGE_RENDERED_AS_TEXT = new Set(['parquet', 'h5', 'hdf5', 'feather'])\n\nfunction mimeFor(path: string): string {\n const ext = extOf(path)\n if (ext === 'json' || ext === 'jsonl') return 'application/json'\n if (ext === 'csv') return 'text/csv'\n if (ext === 'html' || ext === 'htm') return 'text/html'\n if (ext === 'md') return 'text/markdown'\n if (TEXT_EXTENSIONS.has(ext)) return 'text/plain'\n if (MIRAGE_RENDERED_AS_TEXT.has(ext)) return 'text/plain'\n if (ext === 'png') return 'image/png'\n if (ext === 'jpg' || ext === 'jpeg') return 'image/jpeg'\n if (ext === 'pdf') return 'application/pdf'\n return 'application/octet-stream'\n}\n\nfunction isTextMime(mimeType: string): boolean {\n return mimeType.startsWith('text/') || mimeType === 'application/json'\n}\n\nconst ANTHROPIC_BINARY_MIMES = new Set([\n 'application/pdf',\n 'image/jpeg',\n 'image/png',\n 'image/gif',\n 'image/webp',\n])\n\nexport interface LangchainWorkspaceOptions {\n sandboxId?: string\n}\n\nexport class LangchainWorkspace implements SandboxBackendProtocol {\n readonly id: string\n private readonly ws: Workspace\n\n constructor(workspace: Workspace, options: LangchainWorkspaceOptions = {}) {\n this.ws = workspace\n this.id = options.sandboxId ?? 'mirage'\n }\n\n async execute(command: string): Promise<ExecuteResponse> {\n const io = await this.ws.execute(command)\n return ioToExecuteResponse(io)\n }\n\n async ls(path: string): Promise<LsResult> {\n let entries: string[]\n try {\n entries = await this.ws.fs.readdir(path)\n } catch (err) {\n return { error: err instanceof Error ? err.message : String(err) }\n }\n const files: FileInfo[] = []\n for (const entry of entries) {\n const isDir = await this.ws.fs.isDir(entry)\n files.push({ path: entry, is_dir: isDir })\n }\n return { files }\n }\n\n async read(filePath: string, offset = 0, limit = 500): Promise<ReadResult> {\n const mimeType = mimeFor(filePath)\n let bytes: Uint8Array\n try {\n bytes = await this.ws.fs.readFile(filePath)\n } catch (err) {\n return { error: err instanceof Error ? err.message : String(err) }\n }\n if (!isTextMime(mimeType)) {\n if (ANTHROPIC_BINARY_MIMES.has(mimeType)) {\n return { content: bytes, mimeType }\n }\n return {\n error: `Binary file '${filePath}' (${mimeType}, ${String(bytes.length)} bytes). Use shell commands (head, file, wc, od) via execute() to inspect.`,\n }\n }\n const text = new TextDecoder('utf-8').decode(bytes)\n const lines = text.split('\\n')\n if (offset >= lines.length) {\n return {\n error: `Line offset ${String(offset)} exceeds file length (${String(lines.length)} lines)`,\n }\n }\n const end = Math.min(offset + limit, lines.length)\n return { content: lines.slice(offset, end).join('\\n'), mimeType }\n }\n\n async readRaw(filePath: string): Promise<ReadRawResult> {\n let stat: Awaited<ReturnType<Workspace['fs']['stat']>>\n let bytes: Uint8Array\n try {\n stat = await this.ws.fs.stat(filePath)\n bytes = await this.ws.fs.readFile(filePath)\n } catch (err) {\n return { error: err instanceof Error ? err.message : String(err) }\n }\n const mimeType = mimeFor(filePath)\n const content: string | Uint8Array = isTextMime(mimeType)\n ? new TextDecoder('utf-8').decode(bytes)\n : bytes\n const modified = stat.modified ?? new Date().toISOString()\n const data: FileData = {\n content,\n mimeType,\n created_at: modified,\n modified_at: modified,\n }\n return { data }\n }\n\n async write(filePath: string, content: string): Promise<WriteResult> {\n if (await this.ws.fs.exists(filePath)) {\n return { error: `Error: file '${filePath}' already exists` }\n }\n await ensureParent(this.ws, filePath)\n await this.ws.fs.writeFile(filePath, content)\n return { path: filePath }\n }\n\n async edit(\n filePath: string,\n oldString: string,\n newString: string,\n replaceAll = false,\n ): Promise<EditResult> {\n let current: string\n try {\n current = await this.ws.fs.readFileText(filePath)\n } catch {\n return { error: `Error: file '${filePath}' not found` }\n }\n const count = current.split(oldString).length - 1\n if (count === 0) {\n return { error: `Error: string not found in file: '${oldString}'` }\n }\n if (count > 1 && !replaceAll) {\n return {\n error: `Error: string '${oldString}' appears ${String(count)} times. Use replaceAll=true`,\n }\n }\n const next = replaceAll\n ? current.split(oldString).join(newString)\n : current.replace(oldString, newString)\n await this.ws.fs.writeFile(filePath, next)\n return { path: filePath, occurrences: replaceAll ? count : 1 }\n }\n\n async grep(pattern: string, path?: string | null, glob?: string | null): Promise<GrepResult> {\n const parts: string[] = ['grep', '-rn']\n if (glob !== undefined && glob !== null && glob.length > 0) {\n parts.push('--include', shellQuote(glob))\n }\n parts.push(shellQuote(pattern))\n parts.push(shellQuote(path ?? '/'))\n const io = await this.ws.execute(parts.join(' '))\n return { matches: ioToGrepMatches(io) }\n }\n\n async glob(pattern: string, path = '/'): Promise<GlobResult> {\n const name = pattern.includes('/') ? (pattern.split('/').pop() ?? pattern) : pattern\n const io = await this.ws.execute(`find ${shellQuote(path)} -name ${shellQuote(name)}`)\n return { files: ioToFileInfos(io) }\n }\n\n async uploadFiles(\n files: readonly (readonly [string, Uint8Array])[],\n ): Promise<FileUploadResponse[]> {\n const results: FileUploadResponse[] = []\n for (const [path, data] of files) {\n await ensureParent(this.ws, path)\n await this.ws.fs.writeFile(path, data)\n results.push({ path, error: null })\n }\n return results\n }\n\n async downloadFiles(paths: readonly string[]): Promise<FileDownloadResponse[]> {\n const results: FileDownloadResponse[] = []\n for (const path of paths) {\n try {\n const content = await this.ws.fs.readFile(path)\n results.push({ path, content, error: null })\n } catch {\n results.push({ path, content: null, error: 'file_not_found' })\n }\n }\n return results\n }\n}\n","// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n\ninterface MessageLike {\n content?: unknown\n}\n\ninterface ContentBlock {\n type?: string\n text?: string\n}\n\nfunction isTextBlock(value: unknown): value is { type: 'text'; text: string } {\n if (typeof value !== 'object' || value === null) return false\n const block = value as ContentBlock\n return block.type === 'text' && typeof block.text === 'string'\n}\n\nexport function extractText(messages: readonly MessageLike[]): string[] {\n const texts: string[] = []\n for (const msg of messages) {\n if (!('content' in msg) || msg.content === undefined || msg.content === null) continue\n const content = msg.content\n if (typeof content === 'string') {\n if (content.trim().length > 0) texts.push(content)\n continue\n }\n if (Array.isArray(content)) {\n for (const block of content) {\n if (isTextBlock(block) && block.text.trim().length > 0) {\n texts.push(block.text)\n }\n }\n }\n }\n return texts\n}\n"],"mappings":";;;;;;AAsBO,SAAS,oBAAoB,IAA6B;AAC/D,QAAM,SAAS,GAAG;AAClB,QAAM,SAAS,GAAG;AAClB,MAAI,SAAS;AACb,MAAI,OAAO,SAAS,GAAG;AACrB,aAAS,OAAO,SAAS,IAAI,GAAG,MAAM;AAAA,EAAK,MAAM,KAAK;AAAA,EACxD;AACA,SAAO,EAAE,QAAQ,UAAU,GAAG,UAAU,WAAW,MAAM;AAC3D;AAEO,SAAS,gBAAgB,IAAyB;AACvD,QAAM,SAAS,GAAG,WAAW,KAAK;AAClC,MAAI,OAAO,WAAW,EAAG,QAAO,CAAC;AACjC,QAAM,UAAuB,CAAC;AAC9B,aAAW,QAAQ,OAAO,MAAM,IAAI,GAAG;AACrC,UAAM,aAAa,KAAK,QAAQ,GAAG;AACnC,QAAI,aAAa,EAAG;AACpB,UAAM,cAAc,KAAK,QAAQ,KAAK,aAAa,CAAC;AACpD,QAAI,cAAc,EAAG;AACrB,UAAM,OAAO,KAAK,MAAM,GAAG,UAAU;AACrC,UAAM,aAAa,KAAK,MAAM,aAAa,GAAG,WAAW;AACzD,UAAM,OAAO,KAAK,MAAM,cAA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langchain/convert.ts","../../src/langchain/backend.ts","../../src/langchain/messages.ts"],"sourcesContent":["// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n\nimport type { ExecuteResponse, FileInfo, GrepMatch } from 'deepagents'\n\ninterface IOLike {\n stdoutText: string\n stderrText: string\n exitCode: number | null\n}\n\nexport function ioToExecuteResponse(io: IOLike): ExecuteResponse {\n const stdout = io.stdoutText\n const stderr = io.stderrText\n let output = stdout\n if (stderr.length > 0) {\n output = stdout.length > 0 ? `${stdout}\\n${stderr}` : stderr\n }\n return { output, exitCode: io.exitCode, truncated: false }\n}\n\nexport function ioToGrepMatches(io: IOLike): GrepMatch[] {\n const stdout = io.stdoutText.trim()\n if (stdout.length === 0) return []\n const matches: GrepMatch[] = []\n for (const line of stdout.split('\\n')) {\n const firstColon = line.indexOf(':')\n if (firstColon < 0) continue\n const secondColon = line.indexOf(':', firstColon + 1)\n if (secondColon < 0) continue\n const path = line.slice(0, firstColon)\n const lineNumStr = line.slice(firstColon + 1, secondColon)\n const text = line.slice(secondColon + 1)\n const lineNum = Number.parseInt(lineNumStr, 10)\n if (Number.isNaN(lineNum)) continue\n matches.push({ path, line: lineNum, text })\n }\n return matches\n}\n\nexport function ioToFileInfos(io: IOLike): FileInfo[] {\n const stdout = io.stdoutText.trim()\n if (stdout.length === 0) return []\n const infos: FileInfo[] = []\n for (const raw of stdout.split('\\n')) {\n const entry = raw.trim()\n if (entry.length === 0) continue\n const isDir = entry.endsWith('/')\n infos.push({ path: isDir ? entry.slice(0, -1) : entry, is_dir: isDir })\n }\n return infos\n}\n","// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n\nimport type { Workspace } from '@struktoai/mirage-node'\nimport type {\n EditResult,\n ExecuteResponse,\n FileData,\n FileDownloadResponse,\n FileInfo,\n FileUploadResponse,\n GlobResult,\n GrepResult,\n LsResult,\n ReadRawResult,\n ReadResult,\n SandboxBackendProtocolV2 as SandboxBackendProtocol,\n WriteResult,\n} from 'deepagents'\nimport { ioToExecuteResponse, ioToFileInfos, ioToGrepMatches } from './convert.ts'\nimport { gnuDirname } from '@struktoai/mirage-core'\n\nconst TEXT_EXTENSIONS = new Set([\n 'txt',\n 'md',\n 'json',\n 'jsonl',\n 'yaml',\n 'yml',\n 'csv',\n 'tsv',\n 'xml',\n 'html',\n 'htm',\n 'js',\n 'mjs',\n 'cjs',\n 'ts',\n 'tsx',\n 'jsx',\n 'py',\n 'rb',\n 'rs',\n 'go',\n 'java',\n 'c',\n 'cpp',\n 'h',\n 'hpp',\n 'sh',\n 'bash',\n 'zsh',\n 'fish',\n 'sql',\n 'log',\n 'env',\n 'ini',\n 'toml',\n 'conf',\n 'cfg',\n])\n\nfunction shellQuote(s: string): string {\n if (/^[A-Za-z0-9_./-]+$/.test(s)) return s\n return `'${s.replaceAll(`'`, `'\\\\''`)}'`\n}\n\nasync function ensureParent(ws: Workspace, path: string): Promise<void> {\n const parent = gnuDirname(path)\n if (parent === '/' || parent === '' || parent === '.') return\n if (await ws.fs.exists(parent)) return\n await ensureParent(ws, parent)\n try {\n await ws.fs.mkdir(parent)\n } catch (err) {\n if (!(await ws.fs.exists(parent))) throw err\n }\n}\n\nfunction extOf(path: string): string {\n const dot = path.lastIndexOf('.')\n if (dot < 0) return ''\n return path.slice(dot + 1).toLowerCase()\n}\n\nfunction mimeFor(path: string): string {\n const ext = extOf(path)\n if (ext === 'json' || ext === 'jsonl') return 'application/json'\n if (ext === 'csv') return 'text/csv'\n if (ext === 'html' || ext === 'htm') return 'text/html'\n if (ext === 'md') return 'text/markdown'\n if (TEXT_EXTENSIONS.has(ext)) return 'text/plain'\n if (ext === 'png') return 'image/png'\n if (ext === 'jpg' || ext === 'jpeg') return 'image/jpeg'\n if (ext === 'pdf') return 'application/pdf'\n return 'application/octet-stream'\n}\n\nfunction isTextMime(mimeType: string): boolean {\n return mimeType.startsWith('text/') || mimeType === 'application/json'\n}\n\nconst ANTHROPIC_BINARY_MIMES = new Set([\n 'application/pdf',\n 'image/jpeg',\n 'image/png',\n 'image/gif',\n 'image/webp',\n])\n\nexport interface LangchainWorkspaceOptions {\n sandboxId?: string\n}\n\nexport class LangchainWorkspace implements SandboxBackendProtocol {\n readonly id: string\n private readonly ws: Workspace\n\n constructor(workspace: Workspace, options: LangchainWorkspaceOptions = {}) {\n this.ws = workspace\n this.id = options.sandboxId ?? 'mirage'\n }\n\n async execute(command: string): Promise<ExecuteResponse> {\n const io = await this.ws.execute(command)\n return ioToExecuteResponse(io)\n }\n\n async ls(path: string): Promise<LsResult> {\n let entries: string[]\n try {\n entries = await this.ws.fs.readdir(path)\n } catch (err) {\n return { error: err instanceof Error ? err.message : String(err) }\n }\n const files: FileInfo[] = []\n for (const entry of entries) {\n const isDir = await this.ws.fs.isDir(entry)\n files.push({ path: entry, is_dir: isDir })\n }\n return { files }\n }\n\n async read(filePath: string, offset = 0, limit = 500): Promise<ReadResult> {\n const mimeType = mimeFor(filePath)\n let bytes: Uint8Array\n try {\n bytes = await this.ws.fs.readFile(filePath)\n } catch (err) {\n return { error: err instanceof Error ? err.message : String(err) }\n }\n if (!isTextMime(mimeType)) {\n if (ANTHROPIC_BINARY_MIMES.has(mimeType)) {\n return { content: bytes, mimeType }\n }\n return {\n error: `Binary file '${filePath}' (${mimeType}, ${String(bytes.length)} bytes). Use shell commands (head, file, wc, od) via execute() to inspect.`,\n }\n }\n const text = new TextDecoder('utf-8').decode(bytes)\n const lines = text.split('\\n')\n if (offset >= lines.length) {\n return {\n error: `Line offset ${String(offset)} exceeds file length (${String(lines.length)} lines)`,\n }\n }\n const end = Math.min(offset + limit, lines.length)\n return { content: lines.slice(offset, end).join('\\n'), mimeType }\n }\n\n async readRaw(filePath: string): Promise<ReadRawResult> {\n let stat: Awaited<ReturnType<Workspace['fs']['stat']>>\n let bytes: Uint8Array\n try {\n stat = await this.ws.fs.stat(filePath)\n bytes = await this.ws.fs.readFile(filePath)\n } catch (err) {\n return { error: err instanceof Error ? err.message : String(err) }\n }\n const mimeType = mimeFor(filePath)\n const content: string | Uint8Array = isTextMime(mimeType)\n ? new TextDecoder('utf-8').decode(bytes)\n : bytes\n const modified = stat.modified ?? new Date().toISOString()\n const data: FileData = {\n content,\n mimeType,\n created_at: modified,\n modified_at: modified,\n }\n return { data }\n }\n\n async write(filePath: string, content: string): Promise<WriteResult> {\n if (await this.ws.fs.exists(filePath)) {\n return { error: `Error: file '${filePath}' already exists` }\n }\n await ensureParent(this.ws, filePath)\n await this.ws.fs.writeFile(filePath, content)\n return { path: filePath }\n }\n\n async edit(\n filePath: string,\n oldString: string,\n newString: string,\n replaceAll = false,\n ): Promise<EditResult> {\n let current: string\n try {\n current = await this.ws.fs.readFileText(filePath)\n } catch {\n return { error: `Error: file '${filePath}' not found` }\n }\n const count = current.split(oldString).length - 1\n if (count === 0) {\n return { error: `Error: string not found in file: '${oldString}'` }\n }\n if (count > 1 && !replaceAll) {\n return {\n error: `Error: string '${oldString}' appears ${String(count)} times. Use replaceAll=true`,\n }\n }\n const next = replaceAll\n ? current.split(oldString).join(newString)\n : current.replace(oldString, newString)\n await this.ws.fs.writeFile(filePath, next)\n return { path: filePath, occurrences: replaceAll ? count : 1 }\n }\n\n async grep(pattern: string, path?: string | null, glob?: string | null): Promise<GrepResult> {\n const parts: string[] = ['grep', '-rn']\n if (glob !== undefined && glob !== null && glob.length > 0) {\n parts.push('--include', shellQuote(glob))\n }\n parts.push(shellQuote(pattern))\n parts.push(shellQuote(path ?? '/'))\n const io = await this.ws.execute(parts.join(' '))\n return { matches: ioToGrepMatches(io) }\n }\n\n async glob(pattern: string, path = '/'): Promise<GlobResult> {\n const name = pattern.includes('/') ? (pattern.split('/').pop() ?? pattern) : pattern\n const io = await this.ws.execute(`find ${shellQuote(path)} -name ${shellQuote(name)}`)\n return { files: ioToFileInfos(io) }\n }\n\n async uploadFiles(\n files: readonly (readonly [string, Uint8Array])[],\n ): Promise<FileUploadResponse[]> {\n const results: FileUploadResponse[] = []\n for (const [path, data] of files) {\n await ensureParent(this.ws, path)\n await this.ws.fs.writeFile(path, data)\n results.push({ path, error: null })\n }\n return results\n }\n\n async downloadFiles(paths: readonly string[]): Promise<FileDownloadResponse[]> {\n const results: FileDownloadResponse[] = []\n for (const path of paths) {\n try {\n const content = await this.ws.fs.readFile(path)\n results.push({ path, content, error: null })\n } catch {\n results.push({ path, content: null, error: 'file_not_found' })\n }\n }\n return results\n }\n}\n","// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n\ninterface MessageLike {\n content?: unknown\n}\n\ninterface ContentBlock {\n type?: string\n text?: string\n}\n\nfunction isTextBlock(value: unknown): value is { type: 'text'; text: string } {\n if (typeof value !== 'object' || value === null) return false\n const block = value as ContentBlock\n return block.type === 'text' && typeof block.text === 'string'\n}\n\nexport function extractText(messages: readonly MessageLike[]): string[] {\n const texts: string[] = []\n for (const msg of messages) {\n if (!('content' in msg) || msg.content === undefined || msg.content === null) continue\n const content = msg.content\n if (typeof content === 'string') {\n if (content.trim().length > 0) texts.push(content)\n continue\n }\n if (Array.isArray(content)) {\n for (const block of content) {\n if (isTextBlock(block) && block.text.trim().length > 0) {\n texts.push(block.text)\n }\n }\n }\n }\n return texts\n}\n"],"mappings":";;;;;;AAsBO,SAAS,oBAAoB,IAA6B;AAC/D,QAAM,SAAS,GAAG;AAClB,QAAM,SAAS,GAAG;AAClB,MAAI,SAAS;AACb,MAAI,OAAO,SAAS,GAAG;AACrB,aAAS,OAAO,SAAS,IAAI,GAAG,MAAM;AAAA,EAAK,MAAM,KAAK;AAAA,EACxD;AACA,SAAO,EAAE,QAAQ,UAAU,GAAG,UAAU,WAAW,MAAM;AAC3D;AAEO,SAAS,gBAAgB,IAAyB;AACvD,QAAM,SAAS,GAAG,WAAW,KAAK;AAClC,MAAI,OAAO,WAAW,EAAG,QAAO,CAAC;AACjC,QAAM,UAAuB,CAAC;AAC9B,aAAW,QAAQ,OAAO,MAAM,IAAI,GAAG;AACrC,UAAM,aAAa,KAAK,QAAQ,GAAG;AACnC,QAAI,aAAa,EAAG;AACpB,UAAM,cAAc,KAAK,QAAQ,KAAK,aAAa,CAAC;AACpD,QAAI,cAAc,EAAG;AACrB,UAAM,OAAO,KAAK,MAAM,GAAG,UAAU;AACrC,UAAM,aAAa,KAAK,MAAM,aAAa,GAAG,WAAW;AACzD,UAAM,OAAO,KAAK,MAAM,cAAc,CAAC;AACvC,UAAM,UAAU,OAAO,SAAS,YAAY,EAAE;AAC9C,QAAI,OAAO,MAAM,OAAO,EAAG;AAC3B,YAAQ,KAAK,EAAE,MAAM,MAAM,SAAS,KAAK,CAAC;AAAA,EAC5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QAAQ,OAAO;AACxB,UAAI;AACF,cAAM,UAAU,MAAM,KAAK,GAAG,GAAG,SAAS,IAAI;AAC9C,gBAAQ,KAAK,EAAE,MAAM,SAAS,OAAO,KAAK,CAAC;AAAA,MAC7C,QAAQ;AACN,gBAAQ,KAAK,EAAE,MAAM,SAAS,MAAM,OAAO,iBAAiB,CAAC;AAAA,MAC/D;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;;;ACnQA,SAAS,YAAY,OAAyD;AAC5E,MAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;AACxD,QAAM,QAAQ;AACd,SAAO,MAAM,SAAS,UAAU,OAAO,MAAM,SAAS;AACxD;AAEO,SAAS,YAAY,UAA4C;AACtE,QAAM,QAAkB,CAAC;AACzB,aAAW,OAAO,UAAU;AAC1B,QAAI,EAAE,aAAa,QAAQ,IAAI,YAAY,UAAa,IAAI,YAAY,KAAM;AAC9E,UAAM,UAAU,IAAI;AACpB,QAAI,OAAO,YAAY,UAAU;AAC/B,UAAI,QAAQ,KAAK,EAAE,SAAS,EAAG,OAAM,KAAK,OAAO;AACjD;AAAA,IACF;AACA,QAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,iBAAW,SAAS,SAAS;AAC3B,YAAI,YAAY,KAAK,KAAK,MAAM,KAAK,KAAK,EAAE,SAAS,GAAG;AACtD,gBAAM,KAAK,MAAM,IAAI;AAAA,QACvB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Workspace } from '@struktoai/mirage-core';
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
import { M as MirageToolOperationsOptions } from '../tool-descriptions-7CgIovZc.js';
|
|
4
|
+
export { E as EDIT_DESCRIPTION, a as EXECUTE_DESCRIPTION, G as GREP_DESCRIPTION, L as LS_DESCRIPTION, b as MirageToolOperations, R as READ_DESCRIPTION, T as ToolResult, W as WRITE_DESCRIPTION } from '../tool-descriptions-7CgIovZc.js';
|
|
5
|
+
export { F as FileVersionTracker, S as StaleMirageFileError } from '../file-version-Clij-pms.js';
|
|
6
|
+
|
|
7
|
+
interface MirageMcpServerOptions extends MirageToolOperationsOptions {
|
|
8
|
+
name?: string;
|
|
9
|
+
version?: string;
|
|
10
|
+
}
|
|
11
|
+
declare function createMirageMcpServer(workspace: Workspace, options?: MirageMcpServerOptions): McpServer;
|
|
12
|
+
declare function serveMirageMcp(workspace: Workspace, options?: MirageMcpServerOptions): Promise<McpServer>;
|
|
13
|
+
|
|
14
|
+
export { type MirageMcpServerOptions, MirageToolOperationsOptions, createMirageMcpServer, serveMirageMcp };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EDIT_DESCRIPTION,
|
|
3
|
+
EXECUTE_DESCRIPTION,
|
|
4
|
+
GREP_DESCRIPTION,
|
|
5
|
+
LS_DESCRIPTION,
|
|
6
|
+
MirageToolOperations,
|
|
7
|
+
READ_DESCRIPTION,
|
|
8
|
+
WRITE_DESCRIPTION
|
|
9
|
+
} from "../chunk-Y4G25V5V.js";
|
|
10
|
+
import {
|
|
11
|
+
FileVersionTracker,
|
|
12
|
+
StaleMirageFileError
|
|
13
|
+
} from "../chunk-XEQB7N3F.js";
|
|
14
|
+
|
|
15
|
+
// src/mcp/server.ts
|
|
16
|
+
import { VERSION } from "@struktoai/mirage-core";
|
|
17
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
18
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
19
|
+
import { z } from "zod";
|
|
20
|
+
function createMirageMcpServer(workspace, options = {}) {
|
|
21
|
+
const operations = new MirageToolOperations(workspace, options);
|
|
22
|
+
const server = new McpServer({
|
|
23
|
+
name: options.name ?? "mirage",
|
|
24
|
+
version: options.version ?? VERSION
|
|
25
|
+
});
|
|
26
|
+
server.registerTool(
|
|
27
|
+
"execute_command",
|
|
28
|
+
{ description: EXECUTE_DESCRIPTION, inputSchema: { command: z.string() } },
|
|
29
|
+
(args) => operations.execute(args.command)
|
|
30
|
+
);
|
|
31
|
+
server.registerTool(
|
|
32
|
+
"read",
|
|
33
|
+
{
|
|
34
|
+
description: READ_DESCRIPTION,
|
|
35
|
+
inputSchema: {
|
|
36
|
+
path: z.string(),
|
|
37
|
+
offset: z.number().int().min(0).optional(),
|
|
38
|
+
limit: z.number().int().min(1).optional()
|
|
39
|
+
},
|
|
40
|
+
annotations: { readOnlyHint: true }
|
|
41
|
+
},
|
|
42
|
+
(args) => operations.read(args.path, args.offset, args.limit)
|
|
43
|
+
);
|
|
44
|
+
server.registerTool(
|
|
45
|
+
"write",
|
|
46
|
+
{ description: WRITE_DESCRIPTION, inputSchema: { path: z.string(), content: z.string() } },
|
|
47
|
+
(args) => operations.write(args.path, args.content)
|
|
48
|
+
);
|
|
49
|
+
server.registerTool(
|
|
50
|
+
"edit",
|
|
51
|
+
{
|
|
52
|
+
description: EDIT_DESCRIPTION,
|
|
53
|
+
inputSchema: {
|
|
54
|
+
path: z.string(),
|
|
55
|
+
old_string: z.string(),
|
|
56
|
+
new_string: z.string(),
|
|
57
|
+
replace_all: z.boolean().optional()
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
(args) => operations.edit(args.path, args.old_string, args.new_string, args.replace_all)
|
|
61
|
+
);
|
|
62
|
+
server.registerTool(
|
|
63
|
+
"ls",
|
|
64
|
+
{
|
|
65
|
+
description: LS_DESCRIPTION,
|
|
66
|
+
inputSchema: { path: z.string() },
|
|
67
|
+
annotations: { readOnlyHint: true }
|
|
68
|
+
},
|
|
69
|
+
(args) => operations.ls(args.path)
|
|
70
|
+
);
|
|
71
|
+
server.registerTool(
|
|
72
|
+
"grep",
|
|
73
|
+
{
|
|
74
|
+
description: GREP_DESCRIPTION,
|
|
75
|
+
inputSchema: { pattern: z.string(), path: z.string() },
|
|
76
|
+
annotations: { readOnlyHint: true }
|
|
77
|
+
},
|
|
78
|
+
(args) => operations.grep(args.pattern, args.path)
|
|
79
|
+
);
|
|
80
|
+
return server;
|
|
81
|
+
}
|
|
82
|
+
async function serveMirageMcp(workspace, options = {}) {
|
|
83
|
+
const server = createMirageMcpServer(workspace, options);
|
|
84
|
+
await server.connect(new StdioServerTransport());
|
|
85
|
+
return server;
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
EDIT_DESCRIPTION,
|
|
89
|
+
EXECUTE_DESCRIPTION,
|
|
90
|
+
FileVersionTracker,
|
|
91
|
+
GREP_DESCRIPTION,
|
|
92
|
+
LS_DESCRIPTION,
|
|
93
|
+
MirageToolOperations,
|
|
94
|
+
READ_DESCRIPTION,
|
|
95
|
+
StaleMirageFileError,
|
|
96
|
+
WRITE_DESCRIPTION,
|
|
97
|
+
createMirageMcpServer,
|
|
98
|
+
serveMirageMcp
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/mcp/server.ts"],"sourcesContent":["// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n\nimport type { Workspace } from '@struktoai/mirage-core'\nimport { VERSION } from '@struktoai/mirage-core'\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'\nimport { z } from 'zod'\nimport {\n EDIT_DESCRIPTION,\n EXECUTE_DESCRIPTION,\n GREP_DESCRIPTION,\n LS_DESCRIPTION,\n READ_DESCRIPTION,\n WRITE_DESCRIPTION,\n} from '../tool-descriptions.ts'\nimport { MirageToolOperations, type MirageToolOperationsOptions } from '../tool-operations.ts'\n\nexport interface MirageMcpServerOptions extends MirageToolOperationsOptions {\n name?: string\n version?: string\n}\n\nexport function createMirageMcpServer(\n workspace: Workspace,\n options: MirageMcpServerOptions = {},\n): McpServer {\n const operations = new MirageToolOperations(workspace, options)\n const server = new McpServer({\n name: options.name ?? 'mirage',\n version: options.version ?? VERSION,\n })\n\n server.registerTool(\n 'execute_command',\n { description: EXECUTE_DESCRIPTION, inputSchema: { command: z.string() } },\n (args) => operations.execute(args.command),\n )\n server.registerTool(\n 'read',\n {\n description: READ_DESCRIPTION,\n inputSchema: {\n path: z.string(),\n offset: z.number().int().min(0).optional(),\n limit: z.number().int().min(1).optional(),\n },\n annotations: { readOnlyHint: true },\n },\n (args) => operations.read(args.path, args.offset, args.limit),\n )\n server.registerTool(\n 'write',\n { description: WRITE_DESCRIPTION, inputSchema: { path: z.string(), content: z.string() } },\n (args) => operations.write(args.path, args.content),\n )\n server.registerTool(\n 'edit',\n {\n description: EDIT_DESCRIPTION,\n inputSchema: {\n path: z.string(),\n old_string: z.string(),\n new_string: z.string(),\n replace_all: z.boolean().optional(),\n },\n },\n (args) => operations.edit(args.path, args.old_string, args.new_string, args.replace_all),\n )\n server.registerTool(\n 'ls',\n {\n description: LS_DESCRIPTION,\n inputSchema: { path: z.string() },\n annotations: { readOnlyHint: true },\n },\n (args) => operations.ls(args.path),\n )\n server.registerTool(\n 'grep',\n {\n description: GREP_DESCRIPTION,\n inputSchema: { pattern: z.string(), path: z.string() },\n annotations: { readOnlyHint: true },\n },\n (args) => operations.grep(args.pattern, args.path),\n )\n\n return server\n}\n\nexport async function serveMirageMcp(\n workspace: Workspace,\n options: MirageMcpServerOptions = {},\n): Promise<McpServer> {\n const server = createMirageMcpServer(workspace, options)\n await server.connect(new StdioServerTransport())\n return server\n}\n"],"mappings":";;;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MACpC;AAAA,IACF;AAAA,IACA,CAAC,SAAS,WAAW,KAAK,KAAK,MAAM,KAAK,YAAY,KAAK,YAAY,KAAK,WAAW;AAAA,EACzF;AACA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE,aAAa;AAAA,MACb,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE;AAAA,MAChC,aAAa,EAAE,cAAc,KAAK;AAAA,IACpC;AAAA,IACA,CAAC,SAAS,WAAW,GAAG,KAAK,IAAI;AAAA,EACnC;AACA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE,aAAa;AAAA,MACb,aAAa,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,EAAE,OAAO,EAAE;AAAA,MACrD,aAAa,EAAE,cAAc,KAAK;AAAA,IACpC;AAAA,IACA,CAAC,SAAS,WAAW,KAAK,KAAK,SAAS,KAAK,IAAI;AAAA,EACnD;AAEA,SAAO;AACT;AAEA,eAAsB,eACpB,WACA,UAAkC,CAAC,GACf;AACpB,QAAM,SAAS,sBAAsB,WAAW,OAAO;AACvD,QAAM,OAAO,QAAQ,IAAI,qBAAqB,CAAC;AAC/C,SAAO;AACT;","names":[]}
|
package/dist/openai/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Workspace } from '@struktoai/mirage-core';
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import * as _openai_agents from '@openai/agents';
|
|
3
|
+
import { Editor, ApplyPatchOperation, ApplyPatchResult, ToolOutputText, ToolOutputImage, ToolOutputFileContent, Shell, ShellAction, ShellResult } from '@openai/agents';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
export { B as BuildSystemPromptOptions, M as MIRAGE_SYSTEM_PROMPT, b as buildSystemPrompt } from '../prompt-B_6pxgjj.js';
|
|
4
6
|
|
|
5
7
|
declare class MirageEditor implements Editor {
|
|
6
8
|
private readonly ws;
|
|
@@ -16,10 +18,19 @@ declare class MirageEditor implements Editor {
|
|
|
16
18
|
}>): Promise<ApplyPatchResult>;
|
|
17
19
|
}
|
|
18
20
|
|
|
21
|
+
declare function mirageExecuteTool(ws: Workspace): _openai_agents.FunctionTool<unknown, z.ZodObject<{
|
|
22
|
+
command: z.ZodString;
|
|
23
|
+
}, z.core.$strip>, string>;
|
|
24
|
+
|
|
25
|
+
type MirageReadFileOutput = ToolOutputText | ToolOutputImage | ToolOutputFileContent;
|
|
26
|
+
declare function mirageReadFileTool(ws: Workspace): _openai_agents.FunctionTool<unknown, z.ZodObject<{
|
|
27
|
+
path: z.ZodString;
|
|
28
|
+
}, z.core.$strip>, string>;
|
|
29
|
+
|
|
19
30
|
declare class MirageShell implements Shell {
|
|
20
31
|
private readonly ws;
|
|
21
32
|
constructor(ws: Workspace);
|
|
22
33
|
run(action: ShellAction): Promise<ShellResult>;
|
|
23
34
|
}
|
|
24
35
|
|
|
25
|
-
export { MirageEditor, MirageShell };
|
|
36
|
+
export { MirageEditor, type MirageReadFileOutput, MirageShell, mirageExecuteTool, mirageReadFileTool };
|