@agentproto/adapter-mastra-agent 0.6.0 → 0.7.0
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.
|
@@ -336,6 +336,19 @@ function makeWorkspaceTools(opts) {
|
|
|
336
336
|
const cwd = resolve(opts.cwd);
|
|
337
337
|
const allowExec = opts.allowExec ?? true;
|
|
338
338
|
const execTimeoutMs = opts.execTimeoutMs ?? 12e4;
|
|
339
|
+
const additionalReadPaths = new Set(
|
|
340
|
+
(opts.additionalReadPaths ?? []).filter(isAbsolute).map((p) => resolve(p))
|
|
341
|
+
);
|
|
342
|
+
const resolveForWrite = (p) => resolveInCwd(cwd, p);
|
|
343
|
+
const resolveForRead = (p) => {
|
|
344
|
+
try {
|
|
345
|
+
return resolveInCwd(cwd, p);
|
|
346
|
+
} catch (err) {
|
|
347
|
+
const target = isAbsolute(p) ? resolve(p) : resolve(cwd, p);
|
|
348
|
+
if (additionalReadPaths.has(target)) return target;
|
|
349
|
+
throw err;
|
|
350
|
+
}
|
|
351
|
+
};
|
|
339
352
|
const execEnv = { ...process.env, GIT_CEILING_DIRECTORIES: resolve(cwd, "..") };
|
|
340
353
|
const guard = (id, execute) => withTimeoutGuard(id, execTimeoutMs, execute);
|
|
341
354
|
const doListDir = async (input) => {
|
|
@@ -346,11 +359,11 @@ function makeWorkspaceTools(opts) {
|
|
|
346
359
|
};
|
|
347
360
|
};
|
|
348
361
|
const doReadFile = async (input) => {
|
|
349
|
-
const file =
|
|
362
|
+
const file = resolveForRead(input.path);
|
|
350
363
|
return { content: await promises.readFile(file, "utf8") };
|
|
351
364
|
};
|
|
352
365
|
const doWriteFile = async (input) => {
|
|
353
|
-
const file =
|
|
366
|
+
const file = resolveForWrite(input.path);
|
|
354
367
|
await promises.mkdir(resolve(file, ".."), { recursive: true });
|
|
355
368
|
await promises.writeFile(file, input.content, "utf8");
|
|
356
369
|
return { path: input.path, bytes: Buffer.byteLength(input.content, "utf8") };
|
|
@@ -421,7 +434,7 @@ function makeWorkspaceTools(opts) {
|
|
|
421
434
|
}),
|
|
422
435
|
outputSchema: z.object({ path: z.string(), replaced: z.boolean() }),
|
|
423
436
|
execute: guard("edit_file", async (input) => {
|
|
424
|
-
const file =
|
|
437
|
+
const file = resolveForWrite(input.path);
|
|
425
438
|
const current = await promises.readFile(file, "utf8");
|
|
426
439
|
const count = current.split(input.old_string).length - 1;
|
|
427
440
|
if (count === 0) throw new Error(`old_string not found in '${input.path}'.`);
|
|
@@ -447,7 +460,7 @@ function makeWorkspaceTools(opts) {
|
|
|
447
460
|
created: z.string()
|
|
448
461
|
}),
|
|
449
462
|
execute: guard("file_info", async (input) => {
|
|
450
|
-
const abs =
|
|
463
|
+
const abs = resolveForRead(input.path);
|
|
451
464
|
const info = await promises.stat(abs);
|
|
452
465
|
return {
|
|
453
466
|
name: abs.split(sep).pop() ?? input.path,
|
|
@@ -554,7 +567,7 @@ function makeWorkspaceTools(opts) {
|
|
|
554
567
|
outputSchema: z.object({ diff: z.string() }),
|
|
555
568
|
execute: guard("read_diff", async (input) => {
|
|
556
569
|
const relPaths = (input.paths ?? []).map((p) => {
|
|
557
|
-
const abs =
|
|
570
|
+
const abs = resolveForRead(p);
|
|
558
571
|
return relative(cwd, abs) || ".";
|
|
559
572
|
});
|
|
560
573
|
const args = [
|
|
@@ -585,7 +598,7 @@ function makeWorkspaceTools(opts) {
|
|
|
585
598
|
outputSchema: z.object({ applied: z.boolean(), output: z.string() }),
|
|
586
599
|
execute: guard("apply_patch", async (input) => {
|
|
587
600
|
for (const p of extractPatchPaths(input.patch)) {
|
|
588
|
-
|
|
601
|
+
resolveForWrite(p);
|
|
589
602
|
}
|
|
590
603
|
const patchFile = join(tmpdir(), `mastra-agent-patch-${randomUUID()}.diff`);
|
|
591
604
|
await promises.writeFile(patchFile, input.patch, "utf8");
|
|
@@ -1409,6 +1422,18 @@ var DEFAULT_TOOL_IDS = [
|
|
|
1409
1422
|
function envFlag(value) {
|
|
1410
1423
|
return Boolean(value);
|
|
1411
1424
|
}
|
|
1425
|
+
function parseAdditionalReadPathsEnv(env = process.env) {
|
|
1426
|
+
const raw = env.AGENTPROTO_ADDITIONAL_READ_PATHS;
|
|
1427
|
+
if (!raw) return void 0;
|
|
1428
|
+
try {
|
|
1429
|
+
const parsed = JSON.parse(raw);
|
|
1430
|
+
if (!Array.isArray(parsed)) return void 0;
|
|
1431
|
+
const paths = parsed.filter((p) => typeof p === "string" && p.length > 0);
|
|
1432
|
+
return paths.length > 0 ? paths : void 0;
|
|
1433
|
+
} catch {
|
|
1434
|
+
return void 0;
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1412
1437
|
function defaultAgentManifest(model) {
|
|
1413
1438
|
return [
|
|
1414
1439
|
"---",
|
|
@@ -1486,6 +1511,9 @@ function makeAgentFactory(opts = {}) {
|
|
|
1486
1511
|
const workspaceTools = makeWorkspaceTools({
|
|
1487
1512
|
cwd,
|
|
1488
1513
|
allowExec: opts.allowExec,
|
|
1514
|
+
// The daemon's exact-file AGENTS.md read grant (pointer-mode contract)
|
|
1515
|
+
// — explicit option wins, else the driver-set env var.
|
|
1516
|
+
additionalReadPaths: opts.additionalReadPaths ?? parseAdditionalReadPathsEnv(),
|
|
1489
1517
|
extraTools: opts.extraTools
|
|
1490
1518
|
});
|
|
1491
1519
|
const modesEnabled = opts.modes !== false && !envFlag(process.env.AGENTPROTO_MASTRA_NO_MODES);
|
|
@@ -1720,6 +1748,7 @@ var SUSPENSION_OPTIONS = [
|
|
|
1720
1748
|
var META_SUSPEND_PAYLOAD = "mastra-agent/suspendPayload";
|
|
1721
1749
|
var META_RESUME_SCHEMA = "mastra-agent/resumeSchema";
|
|
1722
1750
|
var META_RESUME_DATA = "mastra-agent/resumeData";
|
|
1751
|
+
var META_FEEDBACK = "agentproto/feedback";
|
|
1723
1752
|
function emptySessionState() {
|
|
1724
1753
|
return {
|
|
1725
1754
|
session: null,
|
|
@@ -1873,6 +1902,19 @@ var MastraAcpAgent = class {
|
|
|
1873
1902
|
state.turn = turn;
|
|
1874
1903
|
const { text, files } = promptContent(params);
|
|
1875
1904
|
try {
|
|
1905
|
+
if (!interrupted && state.suspensions.size > 0) {
|
|
1906
|
+
await this.#conn.sessionUpdate({
|
|
1907
|
+
sessionId: params.sessionId,
|
|
1908
|
+
update: {
|
|
1909
|
+
sessionUpdate: "agent_message_chunk",
|
|
1910
|
+
content: {
|
|
1911
|
+
type: "text",
|
|
1912
|
+
text: "\n[mastra-agent] run is suspended awaiting approval \u2014 resolve the pending permission request (or cancel the session) before sending another prompt.\n"
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
});
|
|
1916
|
+
return { stopReason: "refusal" };
|
|
1917
|
+
}
|
|
1876
1918
|
const session = await this.#ensureSession(params.sessionId, state);
|
|
1877
1919
|
const map = createEventMapper();
|
|
1878
1920
|
let endReason;
|
|
@@ -1890,6 +1932,21 @@ var MastraAcpAgent = class {
|
|
|
1890
1932
|
if (event.type === "agent_end") {
|
|
1891
1933
|
endReason = event.reason ?? "complete";
|
|
1892
1934
|
resolveAgentEnd?.();
|
|
1935
|
+
if (event.reason === "suspended") {
|
|
1936
|
+
relay = relay.then(
|
|
1937
|
+
() => this.#conn.sessionUpdate({
|
|
1938
|
+
sessionId: params.sessionId,
|
|
1939
|
+
update: {
|
|
1940
|
+
sessionUpdate: "agent_message_chunk",
|
|
1941
|
+
content: {
|
|
1942
|
+
type: "text",
|
|
1943
|
+
text: "\n[mastra-agent] run suspended \u2014 waiting for approval before continuing.\n"
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
})
|
|
1947
|
+
).catch(() => {
|
|
1948
|
+
});
|
|
1949
|
+
}
|
|
1893
1950
|
return;
|
|
1894
1951
|
}
|
|
1895
1952
|
if (event.type === "tool_approval_required") {
|
|
@@ -2086,7 +2143,11 @@ var MastraAcpAgent = class {
|
|
|
2086
2143
|
if (pending.cancelled) return;
|
|
2087
2144
|
if (outcome.outcome !== "selected") return;
|
|
2088
2145
|
const meta = outcome._meta;
|
|
2089
|
-
const
|
|
2146
|
+
const feedback = meta && typeof meta[META_FEEDBACK] === "string" ? meta[META_FEEDBACK] : void 0;
|
|
2147
|
+
const resumeData = meta && META_RESUME_DATA in meta ? meta[META_RESUME_DATA] : {
|
|
2148
|
+
approved: outcome.optionId === "approve",
|
|
2149
|
+
...feedback ? { feedback } : {}
|
|
2150
|
+
};
|
|
2090
2151
|
await session.respondToToolSuspension({
|
|
2091
2152
|
resumeData,
|
|
2092
2153
|
toolCallId: event.toolCallId
|
|
@@ -2120,6 +2181,12 @@ var MastraAcpAgent = class {
|
|
|
2120
2181
|
threadId: acpSessionId
|
|
2121
2182
|
});
|
|
2122
2183
|
session.subscribe((event) => {
|
|
2184
|
+
if (event.type === "tool_suspension_cancelled") {
|
|
2185
|
+
const pending = state.suspensions.get(event.toolCallId);
|
|
2186
|
+
if (pending) pending.cancelled = true;
|
|
2187
|
+
state.suspensions.delete(event.toolCallId);
|
|
2188
|
+
return;
|
|
2189
|
+
}
|
|
2123
2190
|
if (event.type === "mode_changed") {
|
|
2124
2191
|
void this.#conn.sessionUpdate({
|
|
2125
2192
|
sessionId: acpSessionId,
|
|
@@ -2183,5 +2250,5 @@ function runAcpOverStdio(buildController) {
|
|
|
2183
2250
|
}
|
|
2184
2251
|
|
|
2185
2252
|
export { DEFAULT_MODEL, DEFAULT_MODEL_CATALOG, DEFAULT_TOOL_IDS, DISABLED_BUILTIN_TOOL_IDS, DaemonClient, DaemonHttpError, DaemonNotFoundError, MastraAcpAgent, buildSqliteMemory, buildSqliteStore, createEventMapper, defaultAgentManifest, discoverDaemonEndpoint, makeAgentFactory, makeDaemonTools, makeWorkspaceTools, messageText, modelRefToString, promptContent, promptText, providerOf, resolveInCwd, resolveMastraModel, resolveMemoryDbPath, runAcpOverStdio, toolCallTitle, toolKindFor };
|
|
2186
|
-
//# sourceMappingURL=chunk-
|
|
2187
|
-
//# sourceMappingURL=chunk-
|
|
2253
|
+
//# sourceMappingURL=chunk-2FKFITFT.mjs.map
|
|
2254
|
+
//# sourceMappingURL=chunk-2FKFITFT.mjs.map
|