@dyyz1993/pi-coding-agent 0.70.2 → 0.70.4
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 +37 -1
- package/dist/core/agent-session.d.ts +4 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +47 -11
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/mcp/errors.d.ts +16 -0
- package/dist/core/mcp/errors.d.ts.map +1 -0
- package/dist/core/mcp/errors.js +31 -0
- package/dist/core/mcp/errors.js.map +1 -0
- package/dist/core/mcp/logger.d.ts +12 -0
- package/dist/core/mcp/logger.d.ts.map +1 -0
- package/dist/core/mcp/logger.js +31 -0
- package/dist/core/mcp/logger.js.map +1 -0
- package/dist/core/mcp/mcp-manager.d.ts +42 -0
- package/dist/core/mcp/mcp-manager.d.ts.map +1 -0
- package/dist/core/mcp/mcp-manager.js +427 -0
- package/dist/core/mcp/mcp-manager.js.map +1 -0
- package/dist/core/mcp/tool-converter.d.ts +5 -0
- package/dist/core/mcp/tool-converter.d.ts.map +1 -0
- package/dist/core/mcp/tool-converter.js +39 -0
- package/dist/core/mcp/tool-converter.js.map +1 -0
- package/dist/core/mcp/types.d.ts +50 -0
- package/dist/core/mcp/types.d.ts.map +1 -0
- package/dist/core/mcp/types.js +2 -0
- package/dist/core/mcp/types.js.map +1 -0
- package/dist/core/settings-manager.d.ts +3 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/custom-provider-qwen-cli/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/package.json +5 -4
|
@@ -1656,6 +1656,7 @@ export class AgentSession {
|
|
|
1656
1656
|
this._applyExtensionBindings(this._extensionRunner);
|
|
1657
1657
|
await this._extensionRunner.emit(this._sessionStartEvent);
|
|
1658
1658
|
await this.extendResourcesFromExtensions(this._sessionStartEvent.reason === "reload" ? "reload" : "startup");
|
|
1659
|
+
await this._initMcpServers();
|
|
1659
1660
|
}
|
|
1660
1661
|
async extendResourcesFromExtensions(reason) {
|
|
1661
1662
|
if (!this._extensionRunner.hasHandlers("resources_discover")) {
|
|
@@ -1697,6 +1698,48 @@ export class AgentSession {
|
|
|
1697
1698
|
const name = base.replace(/\.(ts|js)$/, "");
|
|
1698
1699
|
return `extension:${name}`;
|
|
1699
1700
|
}
|
|
1701
|
+
_mcpManager;
|
|
1702
|
+
_createMcpToolDef;
|
|
1703
|
+
async _initMcpServers() {
|
|
1704
|
+
const settings = this.settingsManager.getProjectSettings();
|
|
1705
|
+
const servers = settings?.mcp?.servers;
|
|
1706
|
+
if (!servers || Object.keys(servers).length === 0)
|
|
1707
|
+
return;
|
|
1708
|
+
const { McpManager } = await import("./mcp/mcp-manager.js");
|
|
1709
|
+
const { createMcpToolDefinition } = await import("./mcp/tool-converter.js");
|
|
1710
|
+
this._createMcpToolDef = createMcpToolDefinition;
|
|
1711
|
+
const mcpOptions = settings?.mcp?.options;
|
|
1712
|
+
const manager = new McpManager({
|
|
1713
|
+
...mcpOptions,
|
|
1714
|
+
onConnectionChange: () => {
|
|
1715
|
+
this._syncMcpTools();
|
|
1716
|
+
},
|
|
1717
|
+
});
|
|
1718
|
+
this._mcpManager = manager;
|
|
1719
|
+
try {
|
|
1720
|
+
await manager.connectAll(servers);
|
|
1721
|
+
this._syncMcpTools();
|
|
1722
|
+
}
|
|
1723
|
+
catch (e) {
|
|
1724
|
+
console.error("[mcp] Failed to initialize:", e);
|
|
1725
|
+
}
|
|
1726
|
+
this.sessionSignal.addEventListener("abort", () => {
|
|
1727
|
+
this._mcpManager?.dispose().catch(() => { });
|
|
1728
|
+
this._mcpManager = undefined;
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
_syncMcpTools() {
|
|
1732
|
+
this._customTools = this._customTools.filter((t) => !t.name.startsWith("mcp__"));
|
|
1733
|
+
if (!this._createMcpToolDef || !this._mcpManager)
|
|
1734
|
+
return;
|
|
1735
|
+
const tools = this._mcpManager.getAllTools();
|
|
1736
|
+
for (const tool of tools) {
|
|
1737
|
+
this._customTools.push(this._createMcpToolDef(tool, this._mcpManager));
|
|
1738
|
+
}
|
|
1739
|
+
if (tools.length > 0) {
|
|
1740
|
+
this._refreshToolRegistry();
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1700
1743
|
_applyExtensionBindings(runner) {
|
|
1701
1744
|
runner.setUIContext(this._extensionUIContext);
|
|
1702
1745
|
runner.bindCommandContext(this._extensionCommandContextActions);
|
|
@@ -2757,15 +2800,10 @@ export class AgentSession {
|
|
|
2757
2800
|
const contextWindow = model.contextWindow ?? 0;
|
|
2758
2801
|
if (contextWindow <= 0)
|
|
2759
2802
|
return undefined;
|
|
2760
|
-
// After compaction, the last assistant usage reflects pre-compaction context size.
|
|
2761
|
-
// We can only trust usage from an assistant that responded after the latest compaction.
|
|
2762
|
-
// If no such assistant exists, context token count is unknown until the next LLM response.
|
|
2763
2803
|
const branchEntries = this.sessionManager.getBranch();
|
|
2764
2804
|
const latestCompaction = getLatestCompactionEntry(branchEntries);
|
|
2765
2805
|
if (latestCompaction) {
|
|
2766
|
-
// Check if there's a valid assistant usage after the compaction boundary
|
|
2767
2806
|
const compactionIndex = branchEntries.lastIndexOf(latestCompaction);
|
|
2768
|
-
let hasPostCompactionUsage = false;
|
|
2769
2807
|
for (let i = branchEntries.length - 1; i > compactionIndex; i--) {
|
|
2770
2808
|
const entry = branchEntries[i];
|
|
2771
2809
|
if (entry.type === "message" && entry.message.role === "assistant") {
|
|
@@ -2773,18 +2811,16 @@ export class AgentSession {
|
|
|
2773
2811
|
if (assistant.stopReason !== "aborted" && assistant.stopReason !== "error") {
|
|
2774
2812
|
const contextTokens = calculateContextTokens(assistant.usage);
|
|
2775
2813
|
if (contextTokens > 0) {
|
|
2776
|
-
|
|
2814
|
+
const percent = (contextTokens / contextWindow) * 100;
|
|
2815
|
+
return { tokens: contextTokens, contextWindow, percent };
|
|
2777
2816
|
}
|
|
2778
|
-
break;
|
|
2779
2817
|
}
|
|
2818
|
+
break;
|
|
2780
2819
|
}
|
|
2781
2820
|
}
|
|
2782
|
-
if (!hasPostCompactionUsage) {
|
|
2783
|
-
return { tokens: null, contextWindow, percent: null };
|
|
2784
|
-
}
|
|
2785
2821
|
}
|
|
2786
2822
|
const estimate = estimateContextTokens(this.messages);
|
|
2787
|
-
const percent = (estimate.tokens / contextWindow) * 100;
|
|
2823
|
+
const percent = contextWindow > 0 ? (estimate.tokens / contextWindow) * 100 : 0;
|
|
2788
2824
|
return {
|
|
2789
2825
|
tokens: estimate.tokens,
|
|
2790
2826
|
contextWindow,
|