@averyyy/pi-coding-agent 0.80.7-piclient.1 → 0.80.10-piclient.2
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 +77 -0
- package/README.md +6 -6
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/cli.js +2 -0
- package/dist/bun/cli.js.map +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +1 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/list-models.d.ts +2 -2
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +3 -3
- package/dist/cli/list-models.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +3 -0
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +3 -6
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +10 -9
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +5 -6
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +57 -30
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +15 -99
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +46 -259
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/cache-stats.d.ts +2 -2
- package/dist/core/cache-stats.d.ts.map +1 -1
- package/dist/core/cache-stats.js +1 -1
- package/dist/core/cache-stats.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +8 -2
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +1 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +3 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +9 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/model-config.d.ts +512 -0
- package/dist/core/model-config.d.ts.map +1 -0
- package/dist/core/model-config.js +243 -0
- package/dist/core/model-config.js.map +1 -0
- package/dist/core/model-registry.d.ts +13 -123
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +44 -747
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +6 -6
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +18 -18
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +77 -0
- package/dist/core/model-runtime.d.ts.map +1 -0
- package/dist/core/model-runtime.js +418 -0
- package/dist/core/model-runtime.js.map +1 -0
- package/dist/core/models-store.d.ts +17 -0
- package/dist/core/models-store.d.ts.map +1 -0
- package/dist/core/models-store.js +45 -0
- package/dist/core/models-store.js.map +1 -0
- package/dist/core/provider-composer.d.ts +55 -0
- package/dist/core/provider-composer.d.ts.map +1 -0
- package/dist/core/provider-composer.js +375 -0
- package/dist/core/provider-composer.js.map +1 -0
- package/dist/core/radius.d.ts +0 -19
- package/dist/core/radius.d.ts.map +1 -1
- package/dist/core/radius.js +0 -28
- package/dist/core/radius.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts +5 -0
- package/dist/core/remote-catalog-provider.d.ts.map +1 -0
- package/dist/core/remote-catalog-provider.js +83 -0
- package/dist/core/remote-catalog-provider.js.map +1 -0
- package/dist/core/runtime-credentials.d.ts +15 -0
- package/dist/core/runtime-credentials.d.ts.map +1 -0
- package/dist/core/runtime-credentials.js +36 -0
- package/dist/core/runtime-credentials.js.map +1 -0
- package/dist/core/sdk.d.ts +3 -6
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +37 -33
- package/dist/core/sdk.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +11 -13
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +22 -10
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +1 -1
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +4 -8
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +14 -12
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +11 -4
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +72 -41
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +4 -4
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +14 -27
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +6 -3
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +157 -143
- 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 +2 -2
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +67 -5
- package/dist/package-manager-cli.js.map +1 -1
- package/docs/custom-provider.md +6 -11
- package/docs/extensions.md +22 -1
- package/docs/models.md +2 -0
- package/docs/packages.md +1 -0
- package/docs/providers.md +13 -1
- package/docs/sdk.md +40 -50
- package/docs/usage.md +1 -0
- package/examples/extensions/README.md +1 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +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/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/kimi-deferred-tools.ts +61 -0
- 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/examples/sdk/02-custom-model.ts +5 -8
- package/examples/sdk/09-api-keys-and-oauth.ts +13 -31
- package/examples/sdk/12-full-control.ts +7 -12
- package/examples/sdk/README.md +14 -18
- package/package.json +4 -4
- package/dist/core/provider-display-names.d.ts +0 -2
- package/dist/core/provider-display-names.d.ts.map +0 -1
- package/dist/core/provider-display-names.js +0 -37
- package/dist/core/provider-display-names.js.map +0 -1
|
@@ -27,6 +27,7 @@ import { exportSessionToHtml } from "./export-html/index.js";
|
|
|
27
27
|
import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
|
|
28
28
|
import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
|
|
29
29
|
import { emitSessionShutdownEvent } from "./extensions/runner.js";
|
|
30
|
+
import { ModelRegistry } from "./model-registry.js";
|
|
30
31
|
import { compactPiServer, syncPiServerTree, } from "./pi-server-client.js";
|
|
31
32
|
import { expandPromptTemplate } from "./prompt-templates.js";
|
|
32
33
|
import { CURRENT_SESSION_VERSION, getLatestCompactionEntry } from "./session-manager.js";
|
|
@@ -50,6 +51,14 @@ export function parseSkillBlock(text) {
|
|
|
50
51
|
userMessage: match[4]?.trim() || undefined,
|
|
51
52
|
};
|
|
52
53
|
}
|
|
54
|
+
// ============================================================================
|
|
55
|
+
// Types
|
|
56
|
+
// ============================================================================
|
|
57
|
+
function withoutDeletedHeaders(headers) {
|
|
58
|
+
return headers
|
|
59
|
+
? Object.fromEntries(Object.entries(headers).filter((entry) => entry[1] !== null))
|
|
60
|
+
: undefined;
|
|
61
|
+
}
|
|
53
62
|
function estimateMessagesTokens(messages) {
|
|
54
63
|
let tokens = 0;
|
|
55
64
|
for (const message of messages) {
|
|
@@ -197,8 +206,7 @@ export class AgentSession {
|
|
|
197
206
|
_extensionErrorUnsubscriber;
|
|
198
207
|
_autoSessionNameEnabled;
|
|
199
208
|
_autoSessionNameAttempted = false;
|
|
200
|
-
|
|
201
|
-
_modelRegistry;
|
|
209
|
+
_modelRuntime;
|
|
202
210
|
// Tool registry for extension getTools/setTools
|
|
203
211
|
_toolRegistry = new Map();
|
|
204
212
|
_toolDefinitions = new Map();
|
|
@@ -216,7 +224,7 @@ export class AgentSession {
|
|
|
216
224
|
this._resourceLoader = config.resourceLoader;
|
|
217
225
|
this._customTools = config.customTools ?? [];
|
|
218
226
|
this._cwd = config.cwd;
|
|
219
|
-
this.
|
|
227
|
+
this._modelRuntime = config.modelRuntime;
|
|
220
228
|
this._extensionRunnerRef = config.extensionRunnerRef;
|
|
221
229
|
this._initialActiveToolNames = config.initialActiveToolNames;
|
|
222
230
|
this._allowedToolNames = config.allowedToolNames ? new Set(config.allowedToolNames) : undefined;
|
|
@@ -237,9 +245,8 @@ export class AgentSession {
|
|
|
237
245
|
includeAllExtensionTools: true,
|
|
238
246
|
});
|
|
239
247
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
return this._modelRegistry;
|
|
248
|
+
get modelRuntime() {
|
|
249
|
+
return this._modelRuntime;
|
|
243
250
|
}
|
|
244
251
|
reconcilePiServerHistory(snapshot) {
|
|
245
252
|
this.sessionManager.replaceTree(snapshot.entries, snapshot.leafId);
|
|
@@ -252,17 +259,25 @@ export class AgentSession {
|
|
|
252
259
|
});
|
|
253
260
|
}
|
|
254
261
|
async _getRequiredRequestAuth(model) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
262
|
+
let result;
|
|
263
|
+
try {
|
|
264
|
+
result = await this._modelRuntime.getAuth(model);
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
const cause = error instanceof Error ? error.cause : undefined;
|
|
268
|
+
if (cause instanceof Error && cause.message === "authHeader requires a resolved API key") {
|
|
258
269
|
throw new Error(formatNoApiKeyFoundMessage(model.provider));
|
|
259
270
|
}
|
|
260
|
-
throw
|
|
271
|
+
throw error;
|
|
261
272
|
}
|
|
262
|
-
if (result.apiKey) {
|
|
263
|
-
return {
|
|
273
|
+
if (result?.auth.apiKey) {
|
|
274
|
+
return {
|
|
275
|
+
apiKey: result.auth.apiKey,
|
|
276
|
+
headers: withoutDeletedHeaders(result.auth.headers),
|
|
277
|
+
env: result.env,
|
|
278
|
+
};
|
|
264
279
|
}
|
|
265
|
-
const isOAuth = this.
|
|
280
|
+
const isOAuth = this._modelRuntime.isUsingOAuth(model.provider);
|
|
266
281
|
if (isOAuth) {
|
|
267
282
|
throw new Error(`Authentication failed for "${model.provider}". ` +
|
|
268
283
|
`Credentials may have expired or network is unavailable. ` +
|
|
@@ -274,8 +289,15 @@ export class AgentSession {
|
|
|
274
289
|
if (this.agent.streamFn === streamSimple) {
|
|
275
290
|
return this._getRequiredRequestAuth(model);
|
|
276
291
|
}
|
|
277
|
-
|
|
278
|
-
|
|
292
|
+
try {
|
|
293
|
+
const result = await this._modelRuntime.getAuth(model);
|
|
294
|
+
return result
|
|
295
|
+
? { apiKey: result.auth.apiKey, headers: withoutDeletedHeaders(result.auth.headers), env: result.env }
|
|
296
|
+
: {};
|
|
297
|
+
}
|
|
298
|
+
catch {
|
|
299
|
+
return {};
|
|
300
|
+
}
|
|
279
301
|
}
|
|
280
302
|
_resetValidationHintState() {
|
|
281
303
|
this._validationModifiedFiles.clear();
|
|
@@ -1144,8 +1166,10 @@ export class AgentSession {
|
|
|
1144
1166
|
if (!this.model) {
|
|
1145
1167
|
throw new Error(formatNoModelSelectedMessage());
|
|
1146
1168
|
}
|
|
1147
|
-
|
|
1148
|
-
|
|
1169
|
+
const hasConfiguredAuth = this._modelRuntime.hasConfiguredAuth(this.model.provider) ||
|
|
1170
|
+
(await this._modelRuntime.checkAuth(this.model.provider)) !== undefined;
|
|
1171
|
+
if (!hasConfiguredAuth) {
|
|
1172
|
+
const isOAuth = this._modelRuntime.isUsingOAuth(this.model.provider);
|
|
1149
1173
|
if (isOAuth) {
|
|
1150
1174
|
throw new Error(`Authentication failed for "${this.model.provider}". ` +
|
|
1151
1175
|
`Credentials may have expired or network is unavailable. ` +
|
|
@@ -1493,7 +1517,7 @@ export class AgentSession {
|
|
|
1493
1517
|
* @throws Error if no auth is configured for the model
|
|
1494
1518
|
*/
|
|
1495
1519
|
async setModel(model) {
|
|
1496
|
-
if (!this.
|
|
1520
|
+
if (!(await this._modelRuntime.checkAuth(model.provider))) {
|
|
1497
1521
|
throw new Error(`No API key for ${model.provider}/${model.id}`);
|
|
1498
1522
|
}
|
|
1499
1523
|
if (this.isStreaming) {
|
|
@@ -1521,7 +1545,11 @@ export class AgentSession {
|
|
|
1521
1545
|
return this._cycleAvailableModel(direction);
|
|
1522
1546
|
}
|
|
1523
1547
|
async _cycleScopedModel(direction) {
|
|
1524
|
-
const
|
|
1548
|
+
const checks = await Promise.all(this._scopedModels.map(async (scoped) => ({
|
|
1549
|
+
scoped,
|
|
1550
|
+
auth: await this._modelRuntime.checkAuth(scoped.model.provider),
|
|
1551
|
+
})));
|
|
1552
|
+
const scopedModels = checks.filter(({ auth }) => auth !== undefined).map(({ scoped }) => scoped);
|
|
1525
1553
|
if (scopedModels.length <= 1)
|
|
1526
1554
|
return undefined;
|
|
1527
1555
|
const currentModel = this.model;
|
|
@@ -1545,7 +1573,7 @@ export class AgentSession {
|
|
|
1545
1573
|
return { model: next.model, thinkingLevel: this.thinkingLevel, isScoped: true };
|
|
1546
1574
|
}
|
|
1547
1575
|
async _cycleAvailableModel(direction) {
|
|
1548
|
-
const availableModels = await this.
|
|
1576
|
+
const availableModels = await this._modelRuntime.getAvailable();
|
|
1549
1577
|
if (availableModels.length <= 1)
|
|
1550
1578
|
return undefined;
|
|
1551
1579
|
const currentModel = this.model;
|
|
@@ -1953,12 +1981,11 @@ export class AgentSession {
|
|
|
1953
1981
|
let headers;
|
|
1954
1982
|
let env;
|
|
1955
1983
|
if (this.agent.streamFn === streamSimple) {
|
|
1956
|
-
const authResult = await this.
|
|
1957
|
-
if (!authResult.
|
|
1984
|
+
const authResult = await this._modelRuntime.getAuth(this.model);
|
|
1985
|
+
if (!authResult?.auth.apiKey)
|
|
1958
1986
|
return false;
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
headers = authResult.headers;
|
|
1987
|
+
apiKey = authResult.auth.apiKey;
|
|
1988
|
+
headers = withoutDeletedHeaders(authResult.auth.headers);
|
|
1962
1989
|
env = authResult.env;
|
|
1963
1990
|
}
|
|
1964
1991
|
else {
|
|
@@ -2249,7 +2276,7 @@ export class AgentSession {
|
|
|
2249
2276
|
if (!currentModel) {
|
|
2250
2277
|
return;
|
|
2251
2278
|
}
|
|
2252
|
-
const refreshedModel = this.
|
|
2279
|
+
const refreshedModel = this._modelRuntime.getModel(currentModel.provider, currentModel.id);
|
|
2253
2280
|
if (!refreshedModel || refreshedModel === currentModel) {
|
|
2254
2281
|
return;
|
|
2255
2282
|
}
|
|
@@ -2318,7 +2345,7 @@ export class AgentSession {
|
|
|
2318
2345
|
refreshTools: () => this._refreshToolRegistry(),
|
|
2319
2346
|
getCommands,
|
|
2320
2347
|
setModel: async (model) => {
|
|
2321
|
-
if (!this.
|
|
2348
|
+
if (!this._modelRuntime.hasConfiguredAuth(model.provider))
|
|
2322
2349
|
return false;
|
|
2323
2350
|
await this.setModel(model);
|
|
2324
2351
|
return true;
|
|
@@ -2358,11 +2385,11 @@ export class AgentSession {
|
|
|
2358
2385
|
getSystemPromptOptions: () => this._baseSystemPromptOptions,
|
|
2359
2386
|
}, {
|
|
2360
2387
|
registerProvider: (name, config) => {
|
|
2361
|
-
this.
|
|
2388
|
+
this._modelRuntime.registerProvider(name, config);
|
|
2362
2389
|
this._refreshCurrentModelFromRegistry();
|
|
2363
2390
|
},
|
|
2364
2391
|
unregisterProvider: (name) => {
|
|
2365
|
-
this.
|
|
2392
|
+
this._modelRuntime.unregisterProvider(name);
|
|
2366
2393
|
this._refreshCurrentModelFromRegistry();
|
|
2367
2394
|
},
|
|
2368
2395
|
});
|
|
@@ -2464,7 +2491,7 @@ export class AgentSession {
|
|
|
2464
2491
|
extensionsResult.runtime.flagValues.set(name, value);
|
|
2465
2492
|
}
|
|
2466
2493
|
}
|
|
2467
|
-
this._extensionRunner = new ExtensionRunner(extensionsResult.extensions, extensionsResult.runtime, this._cwd, this.sessionManager, this.
|
|
2494
|
+
this._extensionRunner = new ExtensionRunner(extensionsResult.extensions, extensionsResult.runtime, this._cwd, this.sessionManager, new ModelRegistry(this._modelRuntime));
|
|
2468
2495
|
if (this._extensionRunnerRef) {
|
|
2469
2496
|
this._extensionRunnerRef.current = this._extensionRunner;
|
|
2470
2497
|
}
|