@dyyz1993/pi-coding-agent 0.70.4 → 0.70.5
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 +7 -0
- 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 +56 -3
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +1 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/defaults.d.ts +1 -0
- package/dist/core/defaults.d.ts.map +1 -1
- package/dist/core/defaults.js +5 -0
- package/dist/core/defaults.js.map +1 -1
- package/dist/core/extensions/types.d.ts +4 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/model-resolver.d.ts +4 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +51 -7
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/settings-manager.d.ts +2 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +4 -0
- 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 +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +17 -2
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +14 -1
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +17 -2
- package/dist/modes/rpc/rpc-mode.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 +4 -4
|
@@ -24,13 +24,14 @@ import { theme } from "../modes/interactive/theme/theme.js";
|
|
|
24
24
|
import { stripFrontmatter } from "../utils/frontmatter.js";
|
|
25
25
|
import { sleep } from "../utils/sleep.js";
|
|
26
26
|
import { executeBashWithOperations } from "./bash-executor.js";
|
|
27
|
-
import { calculateContextTokens, collectEntriesForBranchSummary, compact, estimateContextTokens, generateBranchSummary, prepareCompaction, shouldCompact, } from "./compaction/index.js";
|
|
27
|
+
import { calculateContextTokens, collectEntriesForBranchSummary, compact, estimateContextTokens, estimateTokens, generateBranchSummary, prepareCompaction, shouldCompact, } from "./compaction/index.js";
|
|
28
28
|
import { DEFAULT_THINKING_LEVEL } from "./defaults.js";
|
|
29
29
|
import { exportSessionToHtml } from "./export-html/index.js";
|
|
30
30
|
import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
|
|
31
31
|
import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
|
|
32
32
|
import { emitSessionShutdownEvent } from "./extensions/runner.js";
|
|
33
33
|
import { handleLargeInput } from "./large-input.js";
|
|
34
|
+
import { resolveModelAlias } from "./model-resolver.js";
|
|
34
35
|
import { expandPromptTemplate } from "./prompt-templates.js";
|
|
35
36
|
import { CURRENT_SESSION_VERSION, getLatestCompactionEntry } from "./session-manager.js";
|
|
36
37
|
import { createSyntheticSourceInfo } from "./source-info.js";
|
|
@@ -116,6 +117,7 @@ export class AgentSession {
|
|
|
116
117
|
_backgroundTasks = new Set();
|
|
117
118
|
// Model registry for API key resolution
|
|
118
119
|
_modelRegistry;
|
|
120
|
+
_tierModels = {};
|
|
119
121
|
// Tool registry for extension getTools/setTools
|
|
120
122
|
_toolRegistry = new Map();
|
|
121
123
|
_toolDefinitions = new Map();
|
|
@@ -523,6 +525,12 @@ export class AgentSession {
|
|
|
523
525
|
get model() {
|
|
524
526
|
return this.agent.state.model;
|
|
525
527
|
}
|
|
528
|
+
getTierModels() {
|
|
529
|
+
return this._tierModels;
|
|
530
|
+
}
|
|
531
|
+
setTierModels(mapping) {
|
|
532
|
+
this._tierModels = { ...mapping };
|
|
533
|
+
}
|
|
526
534
|
/** Current thinking level */
|
|
527
535
|
get thinkingLevel() {
|
|
528
536
|
return this.agent.state.thinkingLevel;
|
|
@@ -1589,6 +1597,11 @@ export class AgentSession {
|
|
|
1589
1597
|
tokensBefore,
|
|
1590
1598
|
details,
|
|
1591
1599
|
};
|
|
1600
|
+
let tokensAfter = 0;
|
|
1601
|
+
for (const msg of sessionContext.messages) {
|
|
1602
|
+
tokensAfter += estimateTokens(msg);
|
|
1603
|
+
}
|
|
1604
|
+
result.tokensAfter = tokensAfter;
|
|
1592
1605
|
this._emit({ type: "compaction_end", reason, result, aborted: false, willRetry });
|
|
1593
1606
|
if (willRetry) {
|
|
1594
1607
|
const messages = this.agent.state.messages;
|
|
@@ -1884,8 +1897,36 @@ export class AgentSession {
|
|
|
1884
1897
|
},
|
|
1885
1898
|
});
|
|
1886
1899
|
}
|
|
1900
|
+
async _resolveOptionalModel(modelSpec) {
|
|
1901
|
+
if (!modelSpec)
|
|
1902
|
+
return this.model;
|
|
1903
|
+
const aliasResolved = resolveModelAlias(modelSpec, this._tierModels);
|
|
1904
|
+
const candidate = aliasResolved ?? modelSpec;
|
|
1905
|
+
let provider;
|
|
1906
|
+
let modelId;
|
|
1907
|
+
if (candidate.includes("/")) {
|
|
1908
|
+
const slashIdx = candidate.indexOf("/");
|
|
1909
|
+
provider = candidate.substring(0, slashIdx);
|
|
1910
|
+
modelId = candidate.substring(slashIdx + 1);
|
|
1911
|
+
}
|
|
1912
|
+
else {
|
|
1913
|
+
modelId = candidate;
|
|
1914
|
+
}
|
|
1915
|
+
let resolved;
|
|
1916
|
+
if (provider) {
|
|
1917
|
+
resolved = this._modelRegistry.find(provider, modelId);
|
|
1918
|
+
}
|
|
1919
|
+
if (!resolved) {
|
|
1920
|
+
const available = this._modelRegistry.getAvailable();
|
|
1921
|
+
resolved = available.find((m) => m.id === modelId);
|
|
1922
|
+
}
|
|
1923
|
+
if (resolved && this._modelRegistry.hasConfiguredAuth(resolved)) {
|
|
1924
|
+
return resolved;
|
|
1925
|
+
}
|
|
1926
|
+
return this.model;
|
|
1927
|
+
}
|
|
1887
1928
|
async callLLM(options) {
|
|
1888
|
-
const model = this.model;
|
|
1929
|
+
const model = await this._resolveOptionalModel(options.model);
|
|
1889
1930
|
if (!model)
|
|
1890
1931
|
throw new Error("No model selected");
|
|
1891
1932
|
const auth = await this._modelRegistry.getApiKeyAndHeaders(model);
|
|
@@ -2052,7 +2093,7 @@ export class AgentSession {
|
|
|
2052
2093
|
throw lastError ?? new Error("callLLMStructured failed");
|
|
2053
2094
|
}
|
|
2054
2095
|
async forkAgent(promptText, options) {
|
|
2055
|
-
const model = this.model;
|
|
2096
|
+
const model = await this._resolveOptionalModel(options?.model);
|
|
2056
2097
|
if (!model)
|
|
2057
2098
|
throw new Error("No model selected");
|
|
2058
2099
|
const auth = await this._modelRegistry.getApiKeyAndHeaders(model);
|
|
@@ -2820,6 +2861,18 @@ export class AgentSession {
|
|
|
2820
2861
|
}
|
|
2821
2862
|
}
|
|
2822
2863
|
const estimate = estimateContextTokens(this.messages);
|
|
2864
|
+
if (latestCompaction && estimate.lastUsageIndex !== null) {
|
|
2865
|
+
const usageMsg = this.messages[estimate.lastUsageIndex];
|
|
2866
|
+
if (usageMsg?.role === "assistant" &&
|
|
2867
|
+
usageMsg.timestamp <= new Date(latestCompaction.timestamp).getTime()) {
|
|
2868
|
+
let estimated = 0;
|
|
2869
|
+
for (const message of this.messages) {
|
|
2870
|
+
estimated += estimateTokens(message);
|
|
2871
|
+
}
|
|
2872
|
+
const fallbackPercent = contextWindow > 0 ? (estimated / contextWindow) * 100 : 0;
|
|
2873
|
+
return { tokens: estimated, contextWindow, percent: fallbackPercent };
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2823
2876
|
const percent = contextWindow > 0 ? (estimate.tokens / contextWindow) * 100 : 0;
|
|
2824
2877
|
return {
|
|
2825
2878
|
tokens: estimate.tokens,
|