@humain/terminal 0.0.3-beta.2 → 0.0.4-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/cli.js +0 -1
- package/dist/bun/cli.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +7 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +4 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +46 -22
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/tools/index.d.ts +2 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +9 -1
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/subagent.d.ts +82 -0
- package/dist/core/tools/subagent.d.ts.map +1 -0
- package/dist/core/tools/subagent.js +980 -0
- package/dist/core/tools/subagent.js.map +1 -0
- package/dist/humain/bedrock-provider/vendor/index.bundle.d.mts +3 -0
- package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +1509 -0
- package/dist/humain/index.d.ts.map +1 -1
- package/dist/humain/index.js +3 -0
- package/dist/humain/index.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/CHANGELOG.md +36 -0
- package/dist/humain/mcp-adapter/vendor/README.md +47 -5
- package/dist/humain/mcp-adapter/vendor/cli.js +163 -1
- package/dist/humain/mcp-adapter/vendor/commands.ts +128 -22
- package/dist/humain/mcp-adapter/vendor/config.ts +25 -7
- package/dist/humain/mcp-adapter/vendor/direct-tools.ts +5 -4
- package/dist/humain/mcp-adapter/vendor/index.bundle.mjs +1663 -458
- package/dist/humain/mcp-adapter/vendor/index.ts +219 -32
- package/dist/humain/mcp-adapter/vendor/init.ts +36 -4
- package/dist/humain/mcp-adapter/vendor/lifecycle.ts +315 -24
- package/dist/humain/mcp-adapter/vendor/mcp-auth-flow.ts +39 -6
- package/dist/humain/mcp-adapter/vendor/mcp-bearer-store.ts +387 -0
- package/dist/humain/mcp-adapter/vendor/mcp-callback-server.ts +27 -3
- package/dist/humain/mcp-adapter/vendor/mcp-code.ts +4 -0
- package/dist/humain/mcp-adapter/vendor/mcp-panel.ts +42 -13
- package/dist/humain/mcp-adapter/vendor/metadata-cache.ts +32 -21
- package/dist/humain/mcp-adapter/vendor/package-mcp-loader.ts +168 -0
- package/dist/humain/mcp-adapter/vendor/package.json +179 -177
- package/dist/humain/mcp-adapter/vendor/proxy-modes.ts +5 -4
- package/dist/humain/mcp-adapter/vendor/request-headers-command.ts +31 -37
- package/dist/humain/mcp-adapter/vendor/search-ranking.ts +92 -22
- package/dist/humain/mcp-adapter/vendor/server-manager.ts +140 -2
- package/dist/humain/mcp-adapter/vendor/session-recovery.ts +7 -0
- package/dist/humain/mcp-adapter/vendor/tool-approval.ts +15 -2
- package/dist/humain/mcp-adapter/vendor/tool-result-renderer.ts +44 -4
- package/dist/humain/mcp-adapter/vendor/types.ts +2 -0
- package/dist/humain/mcp-adapter/vendor/ui-server.ts +18 -16
- package/dist/humain/mcp-adapter/vendor/utils.ts +70 -0
- package/dist/humain/web-access/vendor/anysearch.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/anysearch.js +3 -2
- package/dist/humain/web-access/vendor/anysearch.js.map +1 -1
- package/dist/humain/web-access/vendor/brave.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/brave.js +14 -4
- package/dist/humain/web-access/vendor/brave.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.d.ts +3 -0
- package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.js +4 -1
- package/dist/humain/web-access/vendor/curator-page.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-server.d.ts +3 -0
- package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-server.js +6 -0
- package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
- package/dist/humain/web-access/vendor/exa.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/exa.js +16 -7
- package/dist/humain/web-access/vendor/exa.js.map +1 -1
- package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/extract.js +31 -3
- package/dist/humain/web-access/vendor/extract.js.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.d.ts +2 -2
- package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.js +25 -4
- package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
- package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/index.js +36 -49
- package/dist/humain/web-access/vendor/index.js.map +1 -1
- package/dist/humain/web-access/vendor/page-query.d.ts +1 -2
- package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/page-query.js +5 -2
- package/dist/humain/web-access/vendor/page-query.js.map +1 -1
- package/dist/humain/web-access/vendor/parallel-mcp.d.ts +10 -0
- package/dist/humain/web-access/vendor/parallel-mcp.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/parallel-mcp.js +224 -0
- package/dist/humain/web-access/vendor/parallel-mcp.js.map +1 -0
- package/dist/humain/web-access/vendor/parallel.d.ts +1 -0
- package/dist/humain/web-access/vendor/parallel.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/parallel.js +2 -2
- package/dist/humain/web-access/vendor/parallel.js.map +1 -1
- package/dist/humain/web-access/vendor/query-rewrite.d.ts +3 -0
- package/dist/humain/web-access/vendor/query-rewrite.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/query-rewrite.js +42 -0
- package/dist/humain/web-access/vendor/query-rewrite.js.map +1 -0
- package/dist/humain/web-access/vendor/serper.d.ts +4 -0
- package/dist/humain/web-access/vendor/serper.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/serper.js +206 -0
- package/dist/humain/web-access/vendor/serper.js.map +1 -0
- package/dist/humain/web-access/vendor/summary-model-scope.d.ts +5 -0
- package/dist/humain/web-access/vendor/summary-model-scope.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/summary-model-scope.js +10 -5
- package/dist/humain/web-access/vendor/summary-model-scope.js.map +1 -1
- package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/summary-review.js +40 -14
- package/dist/humain/web-access/vendor/summary-review.js.map +1 -1
- package/dist/humain/web-access/vendor/tavily.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/tavily.js +14 -4
- package/dist/humain/web-access/vendor/tavily.js.map +1 -1
- package/dist/humain/web-access/vendor/utils.d.ts +10 -0
- package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/utils.js +70 -0
- package/dist/humain/web-access/vendor/utils.js.map +1 -1
- package/dist/humain/web-access/vendor/valyu.d.ts +6 -0
- package/dist/humain/web-access/vendor/valyu.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/valyu.js +194 -0
- package/dist/humain/web-access/vendor/valyu.js.map +1 -0
- package/docs/extensions.md +1 -1
- package/examples/extensions/README.md +1 -1
- package/examples/extensions/subagent/README.md +24 -147
- package/npm-shrinkwrap.json +7 -2
- package/package.json +7 -2
- package/src/humain/mcp-adapter/UPSTREAM.md +1 -1
- package/src/humain/mcp-adapter/upstream.json +3 -3
- package/src/humain/mcp-adapter/vendor/CHANGELOG.md +36 -0
- package/src/humain/web-access/UPSTREAM.md +1 -1
- package/src/humain/web-access/upstream.json +4 -4
- package/dist/bun/register-bedrock.d.ts +0 -2
- package/dist/bun/register-bedrock.d.ts.map +0 -1
- package/dist/bun/register-bedrock.js +0 -4
- package/dist/bun/register-bedrock.js.map +0 -1
- package/examples/extensions/subagent/agents.ts +0 -126
- package/examples/extensions/subagent/index.ts +0 -1015
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
3
|
+
import stripJsonComments from "strip-json-comments";
|
|
4
|
+
import { getAgentDir, getConfigDirName } from "./agent-dir.ts";
|
|
5
|
+
import type { McpConfig, ServerEntry } from "./types.ts";
|
|
6
|
+
|
|
7
|
+
interface PackageSetting {
|
|
8
|
+
source: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface PackageManifest {
|
|
12
|
+
name?: unknown;
|
|
13
|
+
pi?: { mcp?: unknown };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function loadPackageMcpConfigs(cwd = process.cwd()): McpConfig {
|
|
17
|
+
const mcpServers: Record<string, ServerEntry> = {};
|
|
18
|
+
const seen = new Set<string>();
|
|
19
|
+
|
|
20
|
+
for (const packageRoot of getConfiguredPackageRoots(cwd)) {
|
|
21
|
+
const manifest = readPackageManifest(packageRoot);
|
|
22
|
+
if (!manifest || typeof manifest.name !== "string" || !manifest.name) continue;
|
|
23
|
+
const paths = getManifestMcpPaths(manifest.pi?.mcp, manifest.name);
|
|
24
|
+
if (!paths) continue;
|
|
25
|
+
|
|
26
|
+
const packagePrefix = formatPackageName(manifest.name);
|
|
27
|
+
const packageServers = new Set<string>();
|
|
28
|
+
for (const path of paths) {
|
|
29
|
+
const configPath = resolvePackageConfigPath(packageRoot, path);
|
|
30
|
+
if (!configPath) {
|
|
31
|
+
console.warn(`Pi package ${manifest.name} skips MCP config ${path}: file must stay inside the package`);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const config = readMcpConfig(configPath, manifest.name);
|
|
36
|
+
if (!config) continue;
|
|
37
|
+
for (const [serverName, server] of Object.entries(config.mcpServers)) {
|
|
38
|
+
const normalizedName = `${packagePrefix}__${formatServerName(serverName)}`;
|
|
39
|
+
if (packageServers.has(normalizedName) || seen.has(normalizedName)) {
|
|
40
|
+
console.warn(`Pi package ${manifest.name} skips duplicate normalized MCP server ${normalizedName}`);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
packageServers.add(normalizedName);
|
|
44
|
+
seen.add(normalizedName);
|
|
45
|
+
mcpServers[normalizedName] = server;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return { mcpServers };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getConfiguredPackageRoots(cwd: string): string[] {
|
|
54
|
+
const roots: string[] = [];
|
|
55
|
+
for (const [settingsPath, scope] of [
|
|
56
|
+
[join(cwd, getConfigDirName(), "settings.json"), "project"],
|
|
57
|
+
[join(getAgentDir(), "settings.json"), "user"],
|
|
58
|
+
] as const) {
|
|
59
|
+
const settings = readOptionalJson(settingsPath, `${scope} Pi settings`);
|
|
60
|
+
if (settings === undefined) continue;
|
|
61
|
+
if (typeof settings !== "object" || settings === null || Array.isArray(settings)) {
|
|
62
|
+
throw new Error(`${scope} Pi settings ${settingsPath} must be a JSON object`);
|
|
63
|
+
}
|
|
64
|
+
const packages = (settings as { packages?: unknown }).packages;
|
|
65
|
+
if (packages === undefined) continue;
|
|
66
|
+
if (!Array.isArray(packages)) throw new Error(`${scope} Pi settings ${settingsPath} packages must be an array`);
|
|
67
|
+
for (const entry of packages) {
|
|
68
|
+
const source = typeof entry === "string"
|
|
69
|
+
? entry
|
|
70
|
+
: entry && typeof entry === "object" && !Array.isArray(entry) && typeof (entry as PackageSetting).source === "string"
|
|
71
|
+
? (entry as PackageSetting).source
|
|
72
|
+
: undefined;
|
|
73
|
+
if (!source) throw new Error(`${scope} Pi settings ${settingsPath} package entries must be strings or objects with a string source`);
|
|
74
|
+
const root = resolvePackageRoot(source, scope, cwd);
|
|
75
|
+
if (root && !roots.includes(root)) roots.push(root);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return roots;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function resolvePackageRoot(source: string, scope: "user" | "project", cwd: string): string | null {
|
|
82
|
+
const baseDir = scope === "user" ? getAgentDir() : join(cwd, getConfigDirName());
|
|
83
|
+
if (source.startsWith("npm:")) {
|
|
84
|
+
const name = source.slice(4).trim().match(/^(@?[^@]+(?:\/[^@]+)?)/)?.[1];
|
|
85
|
+
return name ? resolveContainedPath(join(baseDir, "npm", "node_modules"), name) : null;
|
|
86
|
+
}
|
|
87
|
+
const gitSource = source.startsWith("git:")
|
|
88
|
+
? source.slice(4).trim()
|
|
89
|
+
: /^(?:(?:https?|ssh):\/\/|git@[^:]+:)/.test(source) ? source : null;
|
|
90
|
+
if (gitSource) {
|
|
91
|
+
const value = gitSource
|
|
92
|
+
.replace(/^ssh:\/\/git@/, "")
|
|
93
|
+
.replace(/^git@([^:]+):/, "$1/")
|
|
94
|
+
.replace(/^[a-z]+:\/\//i, "");
|
|
95
|
+
const path = value.replace(/@[^/]+$/, "").replace(/\.git$/, "");
|
|
96
|
+
return path && !path.startsWith("/") ? resolveContainedPath(join(baseDir, "git"), path) : null;
|
|
97
|
+
}
|
|
98
|
+
return isAbsolute(source) ? resolve(source) : resolve(baseDir, source);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function readPackageManifest(packageRoot: string): PackageManifest | null {
|
|
102
|
+
const manifest = readOptionalJson(join(packageRoot, "package.json"), `Pi package manifest ${packageRoot}`);
|
|
103
|
+
return manifest && typeof manifest === "object" && !Array.isArray(manifest) ? manifest as PackageManifest : null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function getManifestMcpPaths(value: unknown, packageName: string): string[] | null {
|
|
107
|
+
const paths = typeof value === "string" ? [value] : Array.isArray(value) && value.every((path): path is string => typeof path === "string") ? value : null;
|
|
108
|
+
if (value !== undefined && !paths) console.warn(`Pi package ${packageName} ignores invalid pi.mcp manifest entry`);
|
|
109
|
+
return paths;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function readMcpConfig(path: string, packageName: string): McpConfig | null {
|
|
113
|
+
const config = readRequiredJson(path, `Pi package ${packageName} MCP config`);
|
|
114
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) {
|
|
115
|
+
throw new Error(`Pi package ${packageName} MCP config ${path} must be a JSON object`);
|
|
116
|
+
}
|
|
117
|
+
const servers = (config as { mcpServers?: unknown }).mcpServers;
|
|
118
|
+
if (!servers || typeof servers !== "object" || Array.isArray(servers)) {
|
|
119
|
+
throw new Error(`Pi package ${packageName} MCP config ${path} must contain a JSON object mcpServers field`);
|
|
120
|
+
}
|
|
121
|
+
const mcpServers: Record<string, ServerEntry> = {};
|
|
122
|
+
for (const [name, server] of Object.entries(servers)) {
|
|
123
|
+
if (!server || typeof server !== "object" || Array.isArray(server)) {
|
|
124
|
+
throw new Error(`Pi package ${packageName} MCP config ${path} server ${name} must be a JSON object`);
|
|
125
|
+
}
|
|
126
|
+
mcpServers[name] = server as ServerEntry;
|
|
127
|
+
}
|
|
128
|
+
return { mcpServers };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function readRequiredJson(path: string, description: string): unknown {
|
|
132
|
+
try {
|
|
133
|
+
return JSON.parse(stripJsonComments(readFileSync(path, "utf8"), { trailingCommas: true }));
|
|
134
|
+
} catch (error) {
|
|
135
|
+
throw new Error(`${description} ${path} contains invalid JSON: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function readOptionalJson(path: string, description: string): unknown | undefined {
|
|
140
|
+
if (!existsSync(path)) return undefined;
|
|
141
|
+
return readRequiredJson(path, description);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function resolveContainedPath(root: string, path: string): string | null {
|
|
145
|
+
const resolved = resolve(root, path);
|
|
146
|
+
const rel = relative(root, resolved);
|
|
147
|
+
return rel === "" || (!rel.startsWith("..") && !rel.startsWith(sep) && !isAbsolute(rel)) ? resolved : null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function resolvePackageConfigPath(packageRoot: string, path: string): string | null {
|
|
151
|
+
const lexicalPath = resolveContainedPath(packageRoot, path);
|
|
152
|
+
if (!lexicalPath || !existsSync(lexicalPath) || !statSync(lexicalPath).isFile()) return null;
|
|
153
|
+
try {
|
|
154
|
+
const realPackageRoot = realpathSync(packageRoot);
|
|
155
|
+
const realConfigPath = realpathSync(lexicalPath);
|
|
156
|
+
return resolveContainedPath(realPackageRoot, realConfigPath);
|
|
157
|
+
} catch {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function formatPackageName(name: string): string {
|
|
163
|
+
return name.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/^[_-]+|[_-]+$/g, "") || "package";
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function formatServerName(name: string): string {
|
|
167
|
+
return name.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/^[_-]+|[_-]+$/g, "") || "server";
|
|
168
|
+
}
|
|
@@ -1,179 +1,181 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
2
|
+
"name": "pi-mcp-adapter",
|
|
3
|
+
"version": "2.27.0",
|
|
4
|
+
"description": "MCP (Model Context Protocol) adapter extension for Pi coding agent",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "./index.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./index.ts",
|
|
10
|
+
"import": "./index.ts",
|
|
11
|
+
"default": "./index.ts"
|
|
12
|
+
},
|
|
13
|
+
"./types": {
|
|
14
|
+
"types": "./types.ts",
|
|
15
|
+
"import": "./types.ts",
|
|
16
|
+
"default": "./types.ts"
|
|
17
|
+
},
|
|
18
|
+
"./oauth": {
|
|
19
|
+
"types": "./oauth.ts",
|
|
20
|
+
"import": "./oauth.ts",
|
|
21
|
+
"default": "./oauth.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"author": "Nico Bailon",
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=20"
|
|
28
|
+
},
|
|
29
|
+
"bin": {
|
|
30
|
+
"pi-mcp-adapter": "cli.js"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"test:watch": "vitest",
|
|
36
|
+
"test:coverage": "vitest run --coverage",
|
|
37
|
+
"test:oauth": "PI_MCP_ADAPTER_TEST_AUTH_STORE=memory PI_MCP_ADAPTER_DISABLE_AUTH_CACHE=1 node --import tsx --test --test-concurrency=1 oauth-public-api.test.ts mcp-auth.test.ts mcp-auth-flow.test.ts mcp-callback-server.test.ts mcp-oauth-provider.test.ts",
|
|
38
|
+
"test:oauth-provider": "PI_MCP_ADAPTER_TEST_AUTH_STORE=memory PI_MCP_ADAPTER_DISABLE_AUTH_CACHE=1 node --import tsx --test mcp-oauth-provider.test.ts",
|
|
39
|
+
"test:conformance": "bash conformance/run.sh"
|
|
40
|
+
},
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/nicobailon/pi-mcp-adapter.git"
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"pi-package",
|
|
47
|
+
"pi",
|
|
48
|
+
"mcp",
|
|
49
|
+
"model-context-protocol",
|
|
50
|
+
"ai",
|
|
51
|
+
"coding-agent",
|
|
52
|
+
"extension",
|
|
53
|
+
"claude",
|
|
54
|
+
"llm"
|
|
55
|
+
],
|
|
56
|
+
"pi": {
|
|
57
|
+
"extensions": [
|
|
58
|
+
"./index.ts"
|
|
59
|
+
],
|
|
60
|
+
"skills": [
|
|
61
|
+
"./skills"
|
|
62
|
+
],
|
|
63
|
+
"video": "https://github.com/nicobailon/pi-mcp-adapter/raw/refs/heads/main/pi-mcp.mp4"
|
|
64
|
+
},
|
|
65
|
+
"files": [
|
|
66
|
+
"cli.js",
|
|
67
|
+
"agent-dir.ts",
|
|
68
|
+
"index.ts",
|
|
69
|
+
"error-signal.ts",
|
|
70
|
+
"state.ts",
|
|
71
|
+
"utils.ts",
|
|
72
|
+
"abort.ts",
|
|
73
|
+
"runtime-owner.ts",
|
|
74
|
+
"tool-metadata.ts",
|
|
75
|
+
"ts-shape.ts",
|
|
76
|
+
"search-ranking.ts",
|
|
77
|
+
"tool-approval.ts",
|
|
78
|
+
"init.ts",
|
|
79
|
+
"ui-session.ts",
|
|
80
|
+
"proxy-modes.ts",
|
|
81
|
+
"direct-tools.ts",
|
|
82
|
+
"commands.ts",
|
|
83
|
+
"prompts.ts",
|
|
84
|
+
"onboarding-state.ts",
|
|
85
|
+
"mcp-setup-panel.ts",
|
|
86
|
+
"types.ts",
|
|
87
|
+
"ui-stream-types.ts",
|
|
88
|
+
"ui-tool-visibility.ts",
|
|
89
|
+
"ui-app-bridge-helpers.ts",
|
|
90
|
+
"config.ts",
|
|
91
|
+
"package-mcp-loader.ts",
|
|
92
|
+
"server-manager.ts",
|
|
93
|
+
"request-headers-command.ts",
|
|
94
|
+
"unix-socket-transport.ts",
|
|
95
|
+
"json-schema-validator.ts",
|
|
96
|
+
"session-recovery.ts",
|
|
97
|
+
"sampling-handler.ts",
|
|
98
|
+
"elicitation-handler.ts",
|
|
99
|
+
"tool-registrar.ts",
|
|
100
|
+
"tool-result-renderer.ts",
|
|
101
|
+
"mcp-output-guard.ts",
|
|
102
|
+
"mcp-code.ts",
|
|
103
|
+
"mcp-script-worker.mjs",
|
|
104
|
+
"mcp-probe.ts",
|
|
105
|
+
"agent-plugin-loader.ts",
|
|
106
|
+
"resource-tools.ts",
|
|
107
|
+
"lifecycle.ts",
|
|
108
|
+
"mcp-status.ts",
|
|
109
|
+
"metadata-cache.ts",
|
|
110
|
+
"host-html-template.ts",
|
|
111
|
+
"ui-resource-handler.ts",
|
|
112
|
+
"consent-manager.ts",
|
|
113
|
+
"ui-server.ts",
|
|
114
|
+
"glimpse-ui.ts",
|
|
115
|
+
"npx-resolver.ts",
|
|
116
|
+
"oauth-handler.ts",
|
|
117
|
+
"oauth.ts",
|
|
118
|
+
"mcp-auth.ts",
|
|
119
|
+
"mcp-bearer-store.ts",
|
|
120
|
+
"mcp-keyring-helper.cjs",
|
|
121
|
+
"mcp-oauth-provider.ts",
|
|
122
|
+
"mcp-callback-server.ts",
|
|
123
|
+
"mcp-auth-flow.ts",
|
|
124
|
+
"mcp-panel.ts",
|
|
125
|
+
"panel-keys.ts",
|
|
126
|
+
"mcp-trace.ts",
|
|
127
|
+
"logger.ts",
|
|
128
|
+
"errors.ts",
|
|
129
|
+
"app-bridge.bundle.js",
|
|
130
|
+
"banner.png",
|
|
131
|
+
"skills",
|
|
132
|
+
"README.md",
|
|
133
|
+
"CHANGELOG.md",
|
|
134
|
+
"LICENSE"
|
|
135
|
+
],
|
|
136
|
+
"dependencies": {
|
|
137
|
+
"@modelcontextprotocol/client": "2.0.0",
|
|
138
|
+
"@modelcontextprotocol/core": "2.0.0",
|
|
139
|
+
"@modelcontextprotocol/ext-apps": "^1.2.2",
|
|
140
|
+
"@napi-rs/keyring": "^1.3.0",
|
|
141
|
+
"ajv": "^8.17.1",
|
|
142
|
+
"ajv-formats": "^3.0.1",
|
|
143
|
+
"cross-spawn": "^7.0.6",
|
|
144
|
+
"open": "^10.2.0",
|
|
145
|
+
"recheck": "^4.5.0",
|
|
146
|
+
"smol-toml": "^1.6.1",
|
|
147
|
+
"strip-json-comments": "^5.0.3",
|
|
148
|
+
"zod": "^3.25.0 || ^4.0.0"
|
|
149
|
+
},
|
|
150
|
+
"peerDependencies": {
|
|
151
|
+
"@earendil-works/pi-ai": "^0.84.1",
|
|
152
|
+
"@earendil-works/pi-tui": "*",
|
|
153
|
+
"typebox": "*",
|
|
154
|
+
"zod": "^3.25.0 || ^4.0.0"
|
|
155
|
+
},
|
|
156
|
+
"peerDependenciesMeta": {
|
|
157
|
+
"@earendil-works/pi-ai": {
|
|
158
|
+
"optional": true
|
|
159
|
+
},
|
|
160
|
+
"@earendil-works/pi-tui": {
|
|
161
|
+
"optional": true
|
|
162
|
+
},
|
|
163
|
+
"typebox": {
|
|
164
|
+
"optional": true
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
"devDependencies": {
|
|
168
|
+
"@earendil-works/pi-ai": "^0.84.1",
|
|
169
|
+
"@earendil-works/pi-coding-agent": "0.84.1",
|
|
170
|
+
"@earendil-works/pi-tui": "^0.84.1",
|
|
171
|
+
"@modelcontextprotocol/conformance": "0.1.16",
|
|
172
|
+
"@types/bun": "^1.0.0",
|
|
173
|
+
"@types/cross-spawn": "6.0.6",
|
|
174
|
+
"@types/node": "20.19.43",
|
|
175
|
+
"@types/open": "^6.2.1",
|
|
176
|
+
"tsx": "^4.21.0",
|
|
177
|
+
"typebox": "1.3.3",
|
|
178
|
+
"typescript": "5.9.3",
|
|
179
|
+
"vitest": "^3.0.0"
|
|
180
|
+
}
|
|
179
181
|
}
|
|
@@ -13,7 +13,7 @@ import { reconstructPromptMetadata } from "./metadata-cache.ts";
|
|
|
13
13
|
import { resolveMcpResultContent, transformMcpContent, transformMcpResourceContents } from "./tool-registrar.ts";
|
|
14
14
|
import { guardMcpOutput, guardedMcpDetails, resolveMcpOutputGuardOptions } from "./mcp-output-guard.ts";
|
|
15
15
|
import { maybeStartUiSession, summarizeUiSessionResult, type UiSessionRuntime } from "./ui-session.ts";
|
|
16
|
-
import { formatAuthRequiredMessage, formatMcpStatus, resolveServerUrl, truncateAtWord } from "./utils.ts";
|
|
16
|
+
import { formatAuthRequiredMessage, formatMcpStatus, normalizeToolArguments, resolveServerUrl, truncateAtWord } from "./utils.ts";
|
|
17
17
|
import { authenticate, completeAuthFromInput, startAuth, supportsOAuth } from "./mcp-auth-flow.ts";
|
|
18
18
|
import { SessionRecoveryAuthRequiredError, withSessionRecovery } from "./session-recovery.ts";
|
|
19
19
|
import { paginate, rankSuggestions, rankToolMatches, resolveSearchKeywords } from "./search-ranking.ts";
|
|
@@ -1136,11 +1136,12 @@ export async function executeCall(
|
|
|
1136
1136
|
return disabledCallResult(serverName, toolMeta);
|
|
1137
1137
|
}
|
|
1138
1138
|
|
|
1139
|
+
const normalizedArgs = toolMeta.resourceUri ? args ?? {} : normalizeToolArguments(args);
|
|
1139
1140
|
const approval = await ensureToolCallApproved(
|
|
1140
1141
|
state,
|
|
1141
1142
|
serverName,
|
|
1142
1143
|
toolMeta,
|
|
1143
|
-
|
|
1144
|
+
normalizedArgs,
|
|
1144
1145
|
ownedSignal,
|
|
1145
1146
|
origin ?? (toolMeta.resourceUri ? "resource" : "proxy"),
|
|
1146
1147
|
);
|
|
@@ -1217,7 +1218,7 @@ export async function executeCall(
|
|
|
1217
1218
|
? await maybeStartUiSession(state, {
|
|
1218
1219
|
serverName,
|
|
1219
1220
|
toolName: toolMeta.originalName,
|
|
1220
|
-
toolArgs:
|
|
1221
|
+
toolArgs: normalizedArgs,
|
|
1221
1222
|
uiResourceUri: toolMeta.uiResourceUri,
|
|
1222
1223
|
...(toolMeta.uiStreamMode !== undefined ? { streamMode: toolMeta.uiStreamMode } : {}),
|
|
1223
1224
|
...(signal ? { signal } : {}),
|
|
@@ -1235,7 +1236,7 @@ export async function executeCall(
|
|
|
1235
1236
|
serverName,
|
|
1236
1237
|
(conn) => abortable(conn.client.callTool({
|
|
1237
1238
|
name: toolMeta.originalName,
|
|
1238
|
-
arguments:
|
|
1239
|
+
arguments: normalizedArgs,
|
|
1239
1240
|
_meta: uiSession?.requestMeta,
|
|
1240
1241
|
}, requestOptions), ownedSignal),
|
|
1241
1242
|
);
|