@caupulican/pi-adaptative 0.80.57 → 0.80.58
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 +8 -0
- package/dist/cli/args.d.ts +2 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +5 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-session.d.ts +59 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +115 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +5 -0
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +1 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +19 -1
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +1 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +11 -3
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/print-mode.d.ts +13 -0
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +18 -1
- package/dist/modes/print-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/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
|
@@ -59,6 +59,8 @@ export function parseSkillBlock(text) {
|
|
|
59
59
|
userMessage: match[4]?.trim() || undefined,
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
+
/** customType for spawned-usage roll-up entries (Cost Aggregation, Model A). */
|
|
63
|
+
export const SPAWNED_USAGE_CUSTOM_TYPE = "spawned_usage";
|
|
62
64
|
// ============================================================================
|
|
63
65
|
// Constants
|
|
64
66
|
// ============================================================================
|
|
@@ -2082,6 +2084,9 @@ export class AgentSession {
|
|
|
2082
2084
|
setThinkingLevel: (level) => this.setThinkingLevel(level),
|
|
2083
2085
|
getExternalResourceRoots: () => this.settingsManager.getEffectiveExternalResourceRoots(),
|
|
2084
2086
|
registerMemoryProvider: (provider) => this.registerMemoryProvider(provider),
|
|
2087
|
+
reportSpawnedUsage: (usage, opts) => {
|
|
2088
|
+
this.addSpawnedUsage(usage, opts);
|
|
2089
|
+
},
|
|
2085
2090
|
}, {
|
|
2086
2091
|
getModel: () => this.model,
|
|
2087
2092
|
isIdle: () => !this.isStreaming,
|
|
@@ -3089,6 +3094,116 @@ export class AgentSession {
|
|
|
3089
3094
|
contextUsage: this.getContextUsage(),
|
|
3090
3095
|
};
|
|
3091
3096
|
}
|
|
3097
|
+
/**
|
|
3098
|
+
* Cumulative usage (full breakdown) for this session's entire spawn subtree: its own
|
|
3099
|
+
* assistant messages PLUS every `spawned_usage` report it has rolled up. Single source of
|
|
3100
|
+
* truth for "how much did this session and everything it spawned spend" — used by print-mode
|
|
3101
|
+
* to emit a child's total so a spawner can roll it up via {@link addSpawnedUsage}.
|
|
3102
|
+
*
|
|
3103
|
+
* Including the `spawned_usage` reports is what keeps the single-hop invariant intact: a child
|
|
3104
|
+
* that itself spawned grandchildren must report own + sub-usage in one number, or the parent
|
|
3105
|
+
* silently under-counts the grandchildren.
|
|
3106
|
+
*/
|
|
3107
|
+
getCumulativeUsage() {
|
|
3108
|
+
let input = 0;
|
|
3109
|
+
let output = 0;
|
|
3110
|
+
let cacheRead = 0;
|
|
3111
|
+
let cacheWrite = 0;
|
|
3112
|
+
let totalTokens = 0;
|
|
3113
|
+
let costInput = 0;
|
|
3114
|
+
let costOutput = 0;
|
|
3115
|
+
let costCacheRead = 0;
|
|
3116
|
+
let costCacheWrite = 0;
|
|
3117
|
+
let costTotal = 0;
|
|
3118
|
+
const add = (usage) => {
|
|
3119
|
+
input += usage.input;
|
|
3120
|
+
output += usage.output;
|
|
3121
|
+
cacheRead += usage.cacheRead;
|
|
3122
|
+
cacheWrite += usage.cacheWrite;
|
|
3123
|
+
totalTokens += usage.totalTokens;
|
|
3124
|
+
costInput += usage.cost.input;
|
|
3125
|
+
costOutput += usage.cost.output;
|
|
3126
|
+
costCacheRead += usage.cost.cacheRead;
|
|
3127
|
+
costCacheWrite += usage.cost.cacheWrite;
|
|
3128
|
+
costTotal += usage.cost.total;
|
|
3129
|
+
};
|
|
3130
|
+
for (const message of this.state.messages) {
|
|
3131
|
+
if (message.role !== "assistant")
|
|
3132
|
+
continue;
|
|
3133
|
+
const usage = message.usage;
|
|
3134
|
+
if (!usage)
|
|
3135
|
+
continue;
|
|
3136
|
+
add(usage);
|
|
3137
|
+
}
|
|
3138
|
+
// Roll up usage this session attributed to its own spawned children (single-hop).
|
|
3139
|
+
for (const entry of this.sessionManager.getEntries()) {
|
|
3140
|
+
if (entry.type !== "custom" || entry.customType !== SPAWNED_USAGE_CUSTOM_TYPE)
|
|
3141
|
+
continue;
|
|
3142
|
+
const data = entry.data;
|
|
3143
|
+
if (data?.usage)
|
|
3144
|
+
add(data.usage);
|
|
3145
|
+
}
|
|
3146
|
+
return {
|
|
3147
|
+
input,
|
|
3148
|
+
output,
|
|
3149
|
+
cacheRead,
|
|
3150
|
+
cacheWrite,
|
|
3151
|
+
totalTokens,
|
|
3152
|
+
cost: {
|
|
3153
|
+
input: costInput,
|
|
3154
|
+
output: costOutput,
|
|
3155
|
+
cacheRead: costCacheRead,
|
|
3156
|
+
cacheWrite: costCacheWrite,
|
|
3157
|
+
total: costTotal,
|
|
3158
|
+
},
|
|
3159
|
+
};
|
|
3160
|
+
}
|
|
3161
|
+
/**
|
|
3162
|
+
* Record usage spent by a spawned/subagent session so the footer can roll it into the
|
|
3163
|
+
* displayed cost. Persisted as a `CustomEntry` (`customType: "spawned_usage"`, Model A) so
|
|
3164
|
+
* it survives reload and is reconstructed exactly like main usage; a new/forked session
|
|
3165
|
+
* starts fresh because it owns a new log file.
|
|
3166
|
+
*
|
|
3167
|
+
* Idempotent on `opts.reportId`: a re-report (retry, duplicate `agent_end`) with a
|
|
3168
|
+
* previously-seen id is ignored, so cost cannot be double-counted. Honors the single-hop
|
|
3169
|
+
* invariant documented on {@link SpawnedUsageReport}.
|
|
3170
|
+
*
|
|
3171
|
+
* @returns the id of the appended entry, or `undefined` if the report was a duplicate.
|
|
3172
|
+
*/
|
|
3173
|
+
addSpawnedUsage(usage, opts) {
|
|
3174
|
+
const reportId = opts?.reportId;
|
|
3175
|
+
if (reportId) {
|
|
3176
|
+
for (const entry of this.sessionManager.getEntries()) {
|
|
3177
|
+
if (entry.type === "custom" &&
|
|
3178
|
+
entry.customType === SPAWNED_USAGE_CUSTOM_TYPE &&
|
|
3179
|
+
entry.data?.reportId === reportId) {
|
|
3180
|
+
return undefined;
|
|
3181
|
+
}
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
const report = {
|
|
3185
|
+
usage,
|
|
3186
|
+
label: opts?.label,
|
|
3187
|
+
sourceSessionId: opts?.sourceSessionId,
|
|
3188
|
+
reportId,
|
|
3189
|
+
};
|
|
3190
|
+
return this.sessionManager.appendCustomEntry(SPAWNED_USAGE_CUSTOM_TYPE, report);
|
|
3191
|
+
}
|
|
3192
|
+
/** Aggregate all recorded spawned-usage reports (see {@link addSpawnedUsage}). */
|
|
3193
|
+
getSpawnedUsage() {
|
|
3194
|
+
let cost = 0;
|
|
3195
|
+
let reports = 0;
|
|
3196
|
+
for (const entry of this.sessionManager.getEntries()) {
|
|
3197
|
+
if (entry.type !== "custom" || entry.customType !== SPAWNED_USAGE_CUSTOM_TYPE)
|
|
3198
|
+
continue;
|
|
3199
|
+
const data = entry.data;
|
|
3200
|
+
if (!data?.usage)
|
|
3201
|
+
continue;
|
|
3202
|
+
cost += data.usage.cost.total;
|
|
3203
|
+
reports += 1;
|
|
3204
|
+
}
|
|
3205
|
+
return { cost, reports };
|
|
3206
|
+
}
|
|
3092
3207
|
getContextUsage() {
|
|
3093
3208
|
const model = this.model;
|
|
3094
3209
|
if (!model)
|