@celljs/ta-agents 4.17.0 → 4.19.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.
- package/extension/index.mjs +299 -14
- package/host/index.mjs +6 -0
- package/package.json +4 -4
- package/web/index.js +2 -1
package/extension/index.mjs
CHANGED
|
@@ -261,6 +261,12 @@ var AgentPrompt;
|
|
|
261
261
|
return messages.filter((message) => message.role === "user" && at.includes(message.timestamp ?? -1));
|
|
262
262
|
}
|
|
263
263
|
AgentPrompt.written = written;
|
|
264
|
+
function toolsNote(server) {
|
|
265
|
+
return `<ta-tools>
|
|
266
|
+
The tools of Ta named in these notes and in your role are those of the MCP server "${server}" you have (mcp__${server}__<name>): call them as your own.
|
|
267
|
+
</ta-tools>`;
|
|
268
|
+
}
|
|
269
|
+
AgentPrompt.toolsNote = toolsNote;
|
|
264
270
|
function resume(error) {
|
|
265
271
|
return `Your last turn stopped with an error before it finished: ${error}
|
|
266
272
|
Continue where you left off.`;
|
|
@@ -313,14 +319,14 @@ ${kept}
|
|
|
313
319
|
}
|
|
314
320
|
AgentPrompt.transcript = transcript;
|
|
315
321
|
function noteTitle(title) {
|
|
316
|
-
return /^<(?:ta-[\w-]+|skills|earlier_conversation|context)>/.test(title.trim());
|
|
322
|
+
return /^<(?:ta-[\w-]+|skills|addendum|earlier_conversation|context)>/.test(title.trim());
|
|
317
323
|
}
|
|
318
324
|
AgentPrompt.noteTitle = noteTitle;
|
|
319
325
|
function notes(messages) {
|
|
320
326
|
const system = messages.filter((message) => message.role === "system").map((message) => [text(message), ...sections(message)].join(`
|
|
321
327
|
`)).join(`
|
|
322
328
|
`);
|
|
323
|
-
return [...system.matchAll(/^<(ta-[\w-]+|skills)>[\s\S]*?<\/\1>$/gm)].map((match) => match[0]);
|
|
329
|
+
return [...system.matchAll(/^<(ta-[\w-]+|skills|addendum)>[\s\S]*?<\/\1>$/gm)].map((match) => match[0]);
|
|
324
330
|
}
|
|
325
331
|
AgentPrompt.notes = notes;
|
|
326
332
|
function sections(message) {
|
|
@@ -1174,6 +1180,12 @@ var TEXTS = {
|
|
|
1174
1180
|
"zh-TW": (agent) => `${agent} 只能在這台電腦上的目錄裡工作,暫不支援遠端目錄。`,
|
|
1175
1181
|
"ja-JP": (agent) => `${agent} はこのコンピュータのディレクトリでのみ動作します。リモートディレクトリはまだサポートしていません。`
|
|
1176
1182
|
},
|
|
1183
|
+
narrowed: {
|
|
1184
|
+
"en-US": (agent) => `${agent} works with its own tools (files, commands), and this conversation may use only some of Ta's: pick a model of Ta for it.`,
|
|
1185
|
+
"zh-CN": (agent) => `${agent} 用自己的工具读写文件、跑命令,这个对话只能用 Ta 给的几样工具,所以用不了它:请给它换一个 Ta 的模型。`,
|
|
1186
|
+
"zh-TW": (agent) => `${agent} 用自己的工具讀寫檔案、執行命令,這個對話只能用 Ta 給的幾樣工具,所以用不了它:請給它換一個 Ta 的模型。`,
|
|
1187
|
+
"ja-JP": (agent) => `${agent} は自分のツールでファイルやコマンドを扱います。この会話は Ta のツールの一部しか使えないため、${agent} は使えません。Ta のモデルに切り替えてください。`
|
|
1188
|
+
},
|
|
1177
1189
|
signIn: {
|
|
1178
1190
|
"en-US": (agent, command) => `${agent} is not signed in. Run \`${command}\` in a terminal to sign in, then try again.`,
|
|
1179
1191
|
"zh-CN": (agent, command) => `${agent} 还没有登录。请在终端里运行 \`${command}\` 登录后再试。`,
|
|
@@ -1352,15 +1364,15 @@ class AcpAgent {
|
|
|
1352
1364
|
this.starting.catch(() => this.starting = undefined);
|
|
1353
1365
|
return this.starting;
|
|
1354
1366
|
}
|
|
1355
|
-
async newSession(cwd, signal) {
|
|
1356
|
-
await this.start();
|
|
1357
|
-
const setup = await this.request("session/new", { cwd, mcpServers:
|
|
1367
|
+
async newSession(cwd, signal, servers = []) {
|
|
1368
|
+
const init = await this.start();
|
|
1369
|
+
const setup = await this.request("session/new", { cwd, mcpServers: AcpAgent.reachable(init, servers) }, signal);
|
|
1358
1370
|
if (!setup?.sessionId) {
|
|
1359
1371
|
throw new Error(`${this.name} did not open a session`);
|
|
1360
1372
|
}
|
|
1361
1373
|
return this.add(setup.sessionId, setup);
|
|
1362
1374
|
}
|
|
1363
|
-
async loadSession(id, cwd, signal) {
|
|
1375
|
+
async loadSession(id, cwd, signal, servers = []) {
|
|
1364
1376
|
const known = this.sessions.get(id);
|
|
1365
1377
|
if (known) {
|
|
1366
1378
|
return known;
|
|
@@ -1370,7 +1382,7 @@ class AcpAgent {
|
|
|
1370
1382
|
return;
|
|
1371
1383
|
}
|
|
1372
1384
|
try {
|
|
1373
|
-
const setup = await this.request("session/load", { sessionId: id, cwd, mcpServers:
|
|
1385
|
+
const setup = await this.request("session/load", { sessionId: id, cwd, mcpServers: AcpAgent.reachable(init, servers) }, signal);
|
|
1374
1386
|
return this.add(id, setup ?? {});
|
|
1375
1387
|
} catch (error) {
|
|
1376
1388
|
if (error instanceof JsonRpcError && error.code !== Acp.AUTH_REQUIRED) {
|
|
@@ -1379,6 +1391,9 @@ class AcpAgent {
|
|
|
1379
1391
|
throw error;
|
|
1380
1392
|
}
|
|
1381
1393
|
}
|
|
1394
|
+
static reachable(init, servers) {
|
|
1395
|
+
return init?.agentCapabilities?.mcpCapabilities?.http ? servers : [];
|
|
1396
|
+
}
|
|
1382
1397
|
async authenticate(methodId, page, signal) {
|
|
1383
1398
|
await this.start();
|
|
1384
1399
|
this.signInPage = page;
|
|
@@ -1579,6 +1594,7 @@ class AgentBindings {
|
|
|
1579
1594
|
release;
|
|
1580
1595
|
cwd = process.cwd();
|
|
1581
1596
|
owner;
|
|
1597
|
+
servers = async () => [];
|
|
1582
1598
|
ids = new Map;
|
|
1583
1599
|
waiting = new Map;
|
|
1584
1600
|
opened = new Map;
|
|
@@ -1647,10 +1663,11 @@ class AgentBindings {
|
|
|
1647
1663
|
throw new Error(text("remote", config.name));
|
|
1648
1664
|
}
|
|
1649
1665
|
const known = this.ids.get(config.id);
|
|
1650
|
-
|
|
1666
|
+
const servers = await this.servers();
|
|
1667
|
+
let session = known ? await agent.loadSession(known, this.cwd, signal, servers) : undefined;
|
|
1651
1668
|
const fresh = !session;
|
|
1652
1669
|
if (!session) {
|
|
1653
|
-
session = await agent.newSession(this.cwd, signal);
|
|
1670
|
+
session = await agent.newSession(this.cwd, signal, servers);
|
|
1654
1671
|
for (const [option, value] of Object.entries(config.options ?? {})) {
|
|
1655
1672
|
await session.select(option, value, signal).catch(() => {
|
|
1656
1673
|
return;
|
|
@@ -1732,6 +1749,136 @@ function isFile(path) {
|
|
|
1732
1749
|
}
|
|
1733
1750
|
}
|
|
1734
1751
|
|
|
1752
|
+
// src/agent-mcp.ts
|
|
1753
|
+
import { randomBytes } from "node:crypto";
|
|
1754
|
+
import { createServer } from "node:http";
|
|
1755
|
+
var MAX_BODY = 1 << 20;
|
|
1756
|
+
var PROTOCOL = "2025-06-18";
|
|
1757
|
+
|
|
1758
|
+
class AgentMcp {
|
|
1759
|
+
static NAME = "ta";
|
|
1760
|
+
server;
|
|
1761
|
+
listening;
|
|
1762
|
+
sessions = new Map;
|
|
1763
|
+
async add(tools) {
|
|
1764
|
+
const port = await this.listen();
|
|
1765
|
+
const token = randomBytes(24).toString("base64url");
|
|
1766
|
+
this.sessions.set(token, tools);
|
|
1767
|
+
return {
|
|
1768
|
+
server: { type: "http", name: AgentMcp.NAME, url: `http://127.0.0.1:${port}/mcp/${token}`, headers: [] },
|
|
1769
|
+
remove: () => this.sessions.delete(token)
|
|
1770
|
+
};
|
|
1771
|
+
}
|
|
1772
|
+
close() {
|
|
1773
|
+
this.server?.closeAllConnections();
|
|
1774
|
+
this.server?.close();
|
|
1775
|
+
this.server = undefined;
|
|
1776
|
+
this.listening = undefined;
|
|
1777
|
+
}
|
|
1778
|
+
listen() {
|
|
1779
|
+
if (!this.listening) {
|
|
1780
|
+
this.listening = new Promise((resolve, reject) => {
|
|
1781
|
+
const server = createServer((request, response) => void this.handle(request, response));
|
|
1782
|
+
server.once("error", reject);
|
|
1783
|
+
server.listen(0, "127.0.0.1", () => resolve(server.address().port));
|
|
1784
|
+
server.unref();
|
|
1785
|
+
this.server = server;
|
|
1786
|
+
});
|
|
1787
|
+
this.listening.catch(() => this.listening = undefined);
|
|
1788
|
+
}
|
|
1789
|
+
return this.listening;
|
|
1790
|
+
}
|
|
1791
|
+
async handle(request, response) {
|
|
1792
|
+
const tools = this.sessions.get(AgentMcp.token(request.url));
|
|
1793
|
+
const port = this.server?.address()?.port;
|
|
1794
|
+
if (!tools || request.headers.origin !== undefined || request.headers.host !== `127.0.0.1:${port}`) {
|
|
1795
|
+
response.writeHead(404).end();
|
|
1796
|
+
return;
|
|
1797
|
+
}
|
|
1798
|
+
if (request.method !== "POST") {
|
|
1799
|
+
response.writeHead(405, { allow: "POST" }).end();
|
|
1800
|
+
return;
|
|
1801
|
+
}
|
|
1802
|
+
let message;
|
|
1803
|
+
try {
|
|
1804
|
+
message = JSON.parse(await AgentMcp.body(request));
|
|
1805
|
+
} catch {
|
|
1806
|
+
AgentMcp.reply(response, { jsonrpc: "2.0", id: null, error: { code: -32700, message: "Parse error" } });
|
|
1807
|
+
return;
|
|
1808
|
+
}
|
|
1809
|
+
if (message.id === undefined) {
|
|
1810
|
+
response.writeHead(202).end();
|
|
1811
|
+
return;
|
|
1812
|
+
}
|
|
1813
|
+
const answer = (result) => AgentMcp.reply(response, { jsonrpc: "2.0", id: message.id, result });
|
|
1814
|
+
const fail = (code, text2) => AgentMcp.reply(response, { jsonrpc: "2.0", id: message.id, error: { code, message: text2 } });
|
|
1815
|
+
switch (message.method) {
|
|
1816
|
+
case "initialize": {
|
|
1817
|
+
const asked = message.params?.protocolVersion;
|
|
1818
|
+
answer({
|
|
1819
|
+
protocolVersion: typeof asked === "string" ? asked : PROTOCOL,
|
|
1820
|
+
capabilities: { tools: {} },
|
|
1821
|
+
serverInfo: { name: "Ta", version: "1" }
|
|
1822
|
+
});
|
|
1823
|
+
return;
|
|
1824
|
+
}
|
|
1825
|
+
case "ping":
|
|
1826
|
+
answer({});
|
|
1827
|
+
return;
|
|
1828
|
+
case "tools/list":
|
|
1829
|
+
answer({ tools: tools.list() });
|
|
1830
|
+
return;
|
|
1831
|
+
case "tools/call": {
|
|
1832
|
+
const name = message.params?.name;
|
|
1833
|
+
const args = message.params?.arguments;
|
|
1834
|
+
if (typeof name !== "string" || !tools.list().some((tool) => tool.name === name)) {
|
|
1835
|
+
fail(-32602, `Unknown tool: ${String(name)}`);
|
|
1836
|
+
return;
|
|
1837
|
+
}
|
|
1838
|
+
const aborted = new AbortController;
|
|
1839
|
+
const stop = () => aborted.abort();
|
|
1840
|
+
response.once("close", stop);
|
|
1841
|
+
try {
|
|
1842
|
+
answer(await tools.call(name, args && typeof args === "object" ? args : {}, aborted.signal));
|
|
1843
|
+
} catch (error) {
|
|
1844
|
+
answer({ content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }], isError: true });
|
|
1845
|
+
} finally {
|
|
1846
|
+
response.off("close", stop);
|
|
1847
|
+
}
|
|
1848
|
+
return;
|
|
1849
|
+
}
|
|
1850
|
+
default:
|
|
1851
|
+
fail(-32601, `Method not found: ${String(message.method)}`);
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
static token(url) {
|
|
1855
|
+
const match = /^\/mcp\/([\w-]+)$/.exec((url ?? "").split("?")[0]);
|
|
1856
|
+
return match?.[1] ?? "";
|
|
1857
|
+
}
|
|
1858
|
+
static body(request) {
|
|
1859
|
+
return new Promise((resolve, reject) => {
|
|
1860
|
+
const chunks = [];
|
|
1861
|
+
let size = 0;
|
|
1862
|
+
request.on("data", (chunk) => {
|
|
1863
|
+
size += chunk.length;
|
|
1864
|
+
if (size > MAX_BODY) {
|
|
1865
|
+
reject(new Error("Too large"));
|
|
1866
|
+
request.destroy();
|
|
1867
|
+
return;
|
|
1868
|
+
}
|
|
1869
|
+
chunks.push(chunk);
|
|
1870
|
+
});
|
|
1871
|
+
request.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
|
|
1872
|
+
request.on("error", reject);
|
|
1873
|
+
});
|
|
1874
|
+
}
|
|
1875
|
+
static reply(response, body) {
|
|
1876
|
+
if (!response.writableEnded && !response.destroyed) {
|
|
1877
|
+
response.writeHead(200, { "content-type": "application/json", connection: "close" }).end(JSON.stringify(body));
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1735
1882
|
// src/agent-refresh.ts
|
|
1736
1883
|
var REFRESH = Symbol.for("ta-agents.refresh");
|
|
1737
1884
|
var AgentRefresh;
|
|
@@ -1871,7 +2018,7 @@ var AgentTool;
|
|
|
1871
2018
|
return result;
|
|
1872
2019
|
}
|
|
1873
2020
|
AgentTool.input = input;
|
|
1874
|
-
function definition(calls) {
|
|
2021
|
+
function definition(calls, tools) {
|
|
1875
2022
|
return {
|
|
1876
2023
|
name: AgentTool.NAME,
|
|
1877
2024
|
label: "Agent tool",
|
|
@@ -1888,12 +2035,17 @@ var AgentTool;
|
|
|
1888
2035
|
exposure: "direct",
|
|
1889
2036
|
defaultActive: false,
|
|
1890
2037
|
annotations: { readOnlyHint: true },
|
|
1891
|
-
async execute(toolCallId, _params, signal) {
|
|
2038
|
+
async execute(toolCallId, _params, signal, _update, ctx) {
|
|
1892
2039
|
const call = calls.get(toolCallId);
|
|
1893
2040
|
if (!call) {
|
|
1894
2041
|
return { content: [{ type: "text", text: "This call ran in an earlier run of the agent." }], details: {} };
|
|
1895
2042
|
}
|
|
1896
|
-
const
|
|
2043
|
+
const waited = call.turn.waitTool(toolCallId, signal);
|
|
2044
|
+
const execute = ctx?.executeTool;
|
|
2045
|
+
if (tools && execute) {
|
|
2046
|
+
await tools.serve((name, args2, aborted) => execute.call(ctx, name, args2, { signal: aborted }), waited, signal);
|
|
2047
|
+
}
|
|
2048
|
+
const run = await waited;
|
|
1897
2049
|
if (signal?.aborted) {
|
|
1898
2050
|
call.session.abandon(call.turn);
|
|
1899
2051
|
calls.delete(toolCallId);
|
|
@@ -2073,6 +2225,9 @@ class AgentStreamer {
|
|
|
2073
2225
|
}
|
|
2074
2226
|
async run(config, model, context, options, builder) {
|
|
2075
2227
|
const signal = options?.signal;
|
|
2228
|
+
if (this.host.narrowed?.()) {
|
|
2229
|
+
throw new Error(text("narrowed", config.name));
|
|
2230
|
+
}
|
|
2076
2231
|
let signedIn = false;
|
|
2077
2232
|
const signIn = async (error) => {
|
|
2078
2233
|
if (signedIn || !AgentSignIn.required(error) || !await this.host.signIn?.(config, signal)) {
|
|
@@ -2121,7 +2276,7 @@ class AgentStreamer {
|
|
|
2121
2276
|
if (earlier) {
|
|
2122
2277
|
prompt = [{ type: "text", text: earlier }, ...prompt];
|
|
2123
2278
|
}
|
|
2124
|
-
const notes = AgentPrompt.notes(context.messages).filter((note) => !session.told.has(note));
|
|
2279
|
+
const notes = [...AgentPrompt.notes(context.messages), ...this.host.notes?.() ?? []].filter((note) => !session.told.has(note));
|
|
2125
2280
|
if (notes.length) {
|
|
2126
2281
|
for (const note of notes) {
|
|
2127
2282
|
session.told.add(note);
|
|
@@ -2236,12 +2391,127 @@ class AgentStreamer {
|
|
|
2236
2391
|
}
|
|
2237
2392
|
}
|
|
2238
2393
|
|
|
2394
|
+
// src/agent-tool-calls.ts
|
|
2395
|
+
var UNTAKEN_MS = 60000;
|
|
2396
|
+
|
|
2397
|
+
class AgentToolCalls {
|
|
2398
|
+
tools;
|
|
2399
|
+
active;
|
|
2400
|
+
waiting = [];
|
|
2401
|
+
wakers = new Set;
|
|
2402
|
+
constructor(tools, active) {
|
|
2403
|
+
this.tools = tools;
|
|
2404
|
+
this.active = active;
|
|
2405
|
+
}
|
|
2406
|
+
list() {
|
|
2407
|
+
const active = new Set(this.active());
|
|
2408
|
+
return this.tools().filter((tool) => AgentToolCalls.offered(tool, active)).map((tool) => ({
|
|
2409
|
+
name: tool.name,
|
|
2410
|
+
description: tool.description ?? "",
|
|
2411
|
+
inputSchema: AgentToolCalls.schema(tool.parameters)
|
|
2412
|
+
}));
|
|
2413
|
+
}
|
|
2414
|
+
call(name, args, signal) {
|
|
2415
|
+
return new Promise((resolve) => {
|
|
2416
|
+
const timer = setTimeout(() => settle({ content: [{ type: "text", text: `Ta could not run ${name} now: no turn of Ta is waiting for you.` }], isError: true }), UNTAKEN_MS);
|
|
2417
|
+
timer.unref?.();
|
|
2418
|
+
const waiting = { name, args, signal, resolve: (result) => settle(result) };
|
|
2419
|
+
const settle = (result) => {
|
|
2420
|
+
clearTimeout(timer);
|
|
2421
|
+
const index = this.waiting.indexOf(waiting);
|
|
2422
|
+
if (index >= 0) {
|
|
2423
|
+
this.waiting.splice(index, 1);
|
|
2424
|
+
}
|
|
2425
|
+
resolve(result);
|
|
2426
|
+
};
|
|
2427
|
+
signal.addEventListener("abort", () => settle({ content: [{ type: "text", text: "Cancelled" }], isError: true }), { once: true });
|
|
2428
|
+
this.waiting.push(waiting);
|
|
2429
|
+
for (const wake of this.wakers) {
|
|
2430
|
+
wake();
|
|
2431
|
+
}
|
|
2432
|
+
});
|
|
2433
|
+
}
|
|
2434
|
+
get pending() {
|
|
2435
|
+
return this.waiting.length > 0;
|
|
2436
|
+
}
|
|
2437
|
+
async serve(run, until, signal) {
|
|
2438
|
+
let done = false;
|
|
2439
|
+
until.finally(() => done = true).catch(() => {
|
|
2440
|
+
return;
|
|
2441
|
+
});
|
|
2442
|
+
const taken = [];
|
|
2443
|
+
while (!done && !signal?.aborted) {
|
|
2444
|
+
const next = this.waiting.shift();
|
|
2445
|
+
if (next) {
|
|
2446
|
+
taken.push(this.runOne(run, next));
|
|
2447
|
+
continue;
|
|
2448
|
+
}
|
|
2449
|
+
let wake = () => {
|
|
2450
|
+
return;
|
|
2451
|
+
};
|
|
2452
|
+
const woken = new Promise((resolve) => {
|
|
2453
|
+
wake = resolve;
|
|
2454
|
+
});
|
|
2455
|
+
this.wakers.add(wake);
|
|
2456
|
+
try {
|
|
2457
|
+
await Promise.race([
|
|
2458
|
+
until.then(() => {
|
|
2459
|
+
return;
|
|
2460
|
+
}, () => {
|
|
2461
|
+
return;
|
|
2462
|
+
}),
|
|
2463
|
+
woken
|
|
2464
|
+
]);
|
|
2465
|
+
} finally {
|
|
2466
|
+
this.wakers.delete(wake);
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
await Promise.all(taken);
|
|
2470
|
+
}
|
|
2471
|
+
async runOne(run, call) {
|
|
2472
|
+
if (call.signal.aborted) {
|
|
2473
|
+
return;
|
|
2474
|
+
}
|
|
2475
|
+
try {
|
|
2476
|
+
const outcome = await run(call.name, call.args, call.signal);
|
|
2477
|
+
const content = (outcome.result?.content ?? []).filter((part) => part.type === "text" || part.type === "image");
|
|
2478
|
+
call.resolve({ content: content.length ? content : [{ type: "text", text: "(no output)" }], ...outcome.isError ? { isError: true } : {} });
|
|
2479
|
+
} catch (error) {
|
|
2480
|
+
call.resolve({ content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }], isError: true });
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
static offered(tool, active) {
|
|
2484
|
+
if (tool.name === AgentTool.NAME || tool.sourceInfo?.source === "builtin") {
|
|
2485
|
+
return false;
|
|
2486
|
+
}
|
|
2487
|
+
switch (tool.exposure ?? "direct") {
|
|
2488
|
+
case "direct":
|
|
2489
|
+
return active.has(tool.name);
|
|
2490
|
+
case "codemode":
|
|
2491
|
+
case "deferred":
|
|
2492
|
+
return true;
|
|
2493
|
+
default:
|
|
2494
|
+
return false;
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
static schema(parameters) {
|
|
2498
|
+
const schema = parameters && typeof parameters === "object" ? JSON.parse(JSON.stringify(parameters)) : {};
|
|
2499
|
+
return schema.type === "object" ? schema : { type: "object", properties: {} };
|
|
2500
|
+
}
|
|
2501
|
+
}
|
|
2502
|
+
|
|
2239
2503
|
// src/extension.ts
|
|
2240
2504
|
var TA_FILE_WRITE_EVENT = "ta:file-write";
|
|
2241
2505
|
var ACTIVITY_ENTRY = "ta-agents.activity";
|
|
2242
2506
|
var CONTEXT_WINDOW = 200000;
|
|
2243
2507
|
var MAX_TOKENS = 32000;
|
|
2244
2508
|
var INSTANCES = Symbol.for("ta-agents.instances");
|
|
2509
|
+
var MCP = Symbol.for("ta-agents.mcp");
|
|
2510
|
+
function mcp() {
|
|
2511
|
+
const global = globalThis;
|
|
2512
|
+
global[MCP] ??= new AgentMcp;
|
|
2513
|
+
return global[MCP];
|
|
2514
|
+
}
|
|
2245
2515
|
var Sessions;
|
|
2246
2516
|
((Sessions) => {
|
|
2247
2517
|
function all() {
|
|
@@ -2393,6 +2663,8 @@ function activate(pi, options = {}) {
|
|
|
2393
2663
|
const ui = context?.hasUI ? context.ui : undefined;
|
|
2394
2664
|
return ui ? new AgentSignIn(config, bindings.agent(config), ui).run(signal) : Promise.resolve(false);
|
|
2395
2665
|
},
|
|
2666
|
+
narrowed: () => !pi.getActiveTools().includes(AgentTool.NAME),
|
|
2667
|
+
notes: () => served && tools.list().length ? [AgentPrompt.toolsNote(AgentMcp.NAME)] : [],
|
|
2396
2668
|
ended: (config, session) => {
|
|
2397
2669
|
if (session.title && !pi.getSessionName()) {
|
|
2398
2670
|
pi.setSessionName(session.title);
|
|
@@ -2405,7 +2677,19 @@ function activate(pi, options = {}) {
|
|
|
2405
2677
|
});
|
|
2406
2678
|
const self = { configs: () => configs, streamer };
|
|
2407
2679
|
let sessionId;
|
|
2408
|
-
pi.
|
|
2680
|
+
const tools = new AgentToolCalls(() => pi.getAllTools(), () => pi.getActiveTools());
|
|
2681
|
+
let served;
|
|
2682
|
+
bindings.servers = async () => {
|
|
2683
|
+
served ??= (options.mcp ?? mcp()).add(tools);
|
|
2684
|
+
return [(await served).server];
|
|
2685
|
+
};
|
|
2686
|
+
const unserve = () => {
|
|
2687
|
+
served?.then(({ remove }) => remove()).catch(() => {
|
|
2688
|
+
return;
|
|
2689
|
+
});
|
|
2690
|
+
served = undefined;
|
|
2691
|
+
};
|
|
2692
|
+
pi.registerTool(AgentTool.definition(calls, tools));
|
|
2409
2693
|
const offerAll = () => offer(AgentCatalog.agents(settings(), find, options.local));
|
|
2410
2694
|
offerAll();
|
|
2411
2695
|
const stopRefresh = AgentRefresh.add(offerAll);
|
|
@@ -2444,6 +2728,7 @@ function activate(pi, options = {}) {
|
|
|
2444
2728
|
pi.on("session_shutdown", () => {
|
|
2445
2729
|
stopRefresh();
|
|
2446
2730
|
bindings.close();
|
|
2731
|
+
unserve();
|
|
2447
2732
|
context = undefined;
|
|
2448
2733
|
if (sessionId) {
|
|
2449
2734
|
Sessions.remove(sessionId, self);
|
package/host/index.mjs
CHANGED
|
@@ -233,6 +233,12 @@ var TEXTS = {
|
|
|
233
233
|
"zh-TW": (agent) => `${agent} 只能在這台電腦上的目錄裡工作,暫不支援遠端目錄。`,
|
|
234
234
|
"ja-JP": (agent) => `${agent} はこのコンピュータのディレクトリでのみ動作します。リモートディレクトリはまだサポートしていません。`
|
|
235
235
|
},
|
|
236
|
+
narrowed: {
|
|
237
|
+
"en-US": (agent) => `${agent} works with its own tools (files, commands), and this conversation may use only some of Ta's: pick a model of Ta for it.`,
|
|
238
|
+
"zh-CN": (agent) => `${agent} 用自己的工具读写文件、跑命令,这个对话只能用 Ta 给的几样工具,所以用不了它:请给它换一个 Ta 的模型。`,
|
|
239
|
+
"zh-TW": (agent) => `${agent} 用自己的工具讀寫檔案、執行命令,這個對話只能用 Ta 給的幾樣工具,所以用不了它:請給它換一個 Ta 的模型。`,
|
|
240
|
+
"ja-JP": (agent) => `${agent} は自分のツールでファイルやコマンドを扱います。この会話は Ta のツールの一部しか使えないため、${agent} は使えません。Ta のモデルに切り替えてください。`
|
|
241
|
+
},
|
|
236
242
|
signIn: {
|
|
237
243
|
"en-US": (agent, command) => `${agent} is not signed in. Run \`${command}\` in a terminal to sign in, then try again.`,
|
|
238
244
|
"zh-CN": (agent, command) => `${agent} 还没有登录。请在终端里运行 \`${command}\` 登录后再试。`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-agents",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.19.0",
|
|
4
4
|
"description": "A pi package for Ta: other coding agents (CodeBuddy Code, Claude Code, Codex and any agent that speaks ACP) as models to pick, each running a conversation on its own harness",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@celljs/ta-exec": "4.
|
|
32
|
-
"@celljs/ta-protocol": "4.
|
|
33
|
-
"@celljs/ta-web": "4.
|
|
31
|
+
"@celljs/ta-exec": "4.19.0",
|
|
32
|
+
"@celljs/ta-protocol": "4.19.0",
|
|
33
|
+
"@celljs/ta-web": "4.19.0",
|
|
34
34
|
"@earendil-works/pi-ai": "^1.5.2",
|
|
35
35
|
"@earendil-works/pi-coding-agent": "^1.5.2",
|
|
36
36
|
"@types/react": "^19.3.0"
|
package/web/index.js
CHANGED
|
@@ -287,10 +287,11 @@ ${data}`);
|
|
|
287
287
|
}), /* @__PURE__ */ React.createElement("p", null, words.signInHint)));
|
|
288
288
|
}
|
|
289
289
|
function AgentsPanel({ pi }) {
|
|
290
|
+
const Loading = pi.ui.Loading ?? pi.ui.Skeleton;
|
|
290
291
|
const words = AgentsWords.of(pi.ui.language);
|
|
291
292
|
const [state, setState] = useAgents(pi);
|
|
292
293
|
if (!state) {
|
|
293
|
-
return /* @__PURE__ */ React.createElement(
|
|
294
|
+
return /* @__PURE__ */ React.createElement(Loading, null);
|
|
294
295
|
}
|
|
295
296
|
const missing = state.agents.some((agent) => agent.state === "missing");
|
|
296
297
|
const signIn = (agent) => pi.ui.custom(({ close }) => /* @__PURE__ */ React.createElement(SignInDialog, {
|