Merge model-registry into main
This commit is contained in:
@@ -6,6 +6,11 @@
|
||||
|
||||
- Added `Ctrl+J` as a default newline keybinding alongside `Shift+Enter`.
|
||||
- Renamed the displayed `zai` provider label to ZAI Coding Plan (Global) for clarity ([#5965](https://github.com/earendil-works/pi/issues/5965)).
|
||||
- pi-ai's old global API (`stream`/`complete`/`completeSimple`, `getModel`/`getModels`/`getProviders`, `registerApiProvider`, `getEnvApiKey`, ...) moved off the `@earendil-works/pi-ai` root entrypoint to `@earendil-works/pi-ai/compat`. Extensions are not affected at runtime: the extension loader resolves the pi-ai root to the compat entrypoint (a strict superset), so existing extensions keep working unchanged. Extension sources that typecheck against pi-ai's published types should switch those imports to `@earendil-works/pi-ai/compat` (or migrate to the new `createModels()`/provider-factory API). The compat entrypoint and the loader alias will be removed in a future release with a migration guide.
|
||||
|
||||
### Added
|
||||
|
||||
- Added an experimental first-time setup flow behind `PI_EXPERIMENTAL=1` that asks for a dark/light theme choice (preselecting the detected appearance) and opt-in analytics data sharing on first launch with the default agent directory; opting in stores a `trackingId` in `settings.json`.
|
||||
|
||||
## [0.79.10] - 2026-06-22
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* pi --extension examples/extensions/custom-compaction.ts
|
||||
*/
|
||||
|
||||
import { complete } from "@earendil-works/pi-ai";
|
||||
import { complete } from "@earendil-works/pi-ai/compat";
|
||||
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
||||
import { convertToLlm, serializeConversation } from "@earendil-works/pi-coding-agent";
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ async function refreshAnthropicToken(credentials: OAuthCredentials): Promise<OAu
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Streaming Implementation (simplified from packages/ai/src/providers/anthropic.ts)
|
||||
// Streaming Implementation (simplified from packages/ai/src/api/anthropic-messages.ts)
|
||||
// =============================================================================
|
||||
|
||||
// Claude Code tool names for OAuth stealth mode
|
||||
|
||||
@@ -12,16 +12,16 @@
|
||||
import {
|
||||
type Api,
|
||||
type AssistantMessageEventStream,
|
||||
anthropicMessagesApi,
|
||||
type Context,
|
||||
createAssistantMessageEventStream,
|
||||
type Model,
|
||||
type OAuthCredentials,
|
||||
type OAuthLoginCallbacks,
|
||||
openAIResponsesApi,
|
||||
type SimpleStreamOptions,
|
||||
streamSimpleAnthropic,
|
||||
streamSimpleOpenAIResponses,
|
||||
type ThinkingLevelMap,
|
||||
} from "@earendil-works/pi-ai";
|
||||
} from "@earendil-works/pi-ai/compat";
|
||||
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
||||
|
||||
// =============================================================================
|
||||
@@ -325,7 +325,7 @@ export function streamGitLabDuo(
|
||||
|
||||
const innerStream =
|
||||
cfg.backend === "anthropic"
|
||||
? streamSimpleAnthropic(
|
||||
? anthropicMessagesApi().streamSimple(
|
||||
{
|
||||
...(modelWithBaseUrl as Model<"anthropic-messages">),
|
||||
compat: {
|
||||
@@ -336,7 +336,11 @@ export function streamGitLabDuo(
|
||||
context,
|
||||
streamOptions,
|
||||
)
|
||||
: streamSimpleOpenAIResponses(modelWithBaseUrl as Model<"openai-responses">, context, streamOptions);
|
||||
: openAIResponsesApi().streamSimple(
|
||||
modelWithBaseUrl as Model<"openai-responses">,
|
||||
context,
|
||||
streamOptions,
|
||||
);
|
||||
|
||||
for await (const event of innerStream) stream.push(event);
|
||||
stream.end();
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* npx tsx test.ts claude-sonnet-4-5-20250929 --thinking
|
||||
*/
|
||||
|
||||
import { type Api, type Context, type Model, registerApiProvider, streamSimple } from "@earendil-works/pi-ai";
|
||||
import { type Api, type Context, type Model, registerApiProvider, streamSimple } from "@earendil-works/pi-ai/compat";
|
||||
import { readFileSync } from "fs";
|
||||
import { getAgentDir } from "packages/coding-agent/src/config.js";
|
||||
import { join } from "path";
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
*/
|
||||
|
||||
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
||||
import { complete, type Message } from "@earendil-works/pi-ai";
|
||||
import { complete, type Message } from "@earendil-works/pi-ai/compat";
|
||||
import type { ExtensionAPI, SessionEntry } from "@earendil-works/pi-coding-agent";
|
||||
import { BorderedLoader, convertToLlm, serializeConversation } from "@earendil-works/pi-coding-agent";
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* 3. Loads the result into the editor for user to fill in answers
|
||||
*/
|
||||
|
||||
import { complete, type UserMessage } from "@earendil-works/pi-ai";
|
||||
import { complete, type UserMessage } from "@earendil-works/pi-ai/compat";
|
||||
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
||||
import { BorderedLoader } from "@earendil-works/pi-coding-agent";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { complete, getModel } from "@earendil-works/pi-ai";
|
||||
import { complete, getModel } from "@earendil-works/pi-ai/compat";
|
||||
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
||||
import { DynamicBorder, getMarkdownTheme } from "@earendil-works/pi-coding-agent";
|
||||
import { Container, Markdown, matchesKey, Text } from "@earendil-works/pi-tui";
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Shows how to select a specific model and thinking level.
|
||||
*/
|
||||
|
||||
import { getModel } from "@earendil-works/pi-ai";
|
||||
import { getModel } from "@earendil-works/pi-ai/compat";
|
||||
import { AuthStorage, createAgentSession, ModelRegistry } from "@earendil-works/pi-coding-agent";
|
||||
|
||||
// Set up auth storage and model registry
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Replace everything - no discovery, explicit configuration.
|
||||
*/
|
||||
|
||||
import { getModel } from "@earendil-works/pi-ai";
|
||||
import { getModel } from "@earendil-works/pi-ai/compat";
|
||||
import {
|
||||
AuthStorage,
|
||||
createAgentSession,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { setBedrockProviderModule } from "@earendil-works/pi-ai";
|
||||
import { bedrockProviderModule } from "@earendil-works/pi-ai/bedrock-provider";
|
||||
import { setBedrockProviderModule } from "@earendil-works/pi-ai/compat";
|
||||
|
||||
setBedrockProviderModule(bedrockProviderModule);
|
||||
|
||||
@@ -23,7 +23,7 @@ import type {
|
||||
AgentTool,
|
||||
ThinkingLevel,
|
||||
} from "@earendil-works/pi-agent-core";
|
||||
import type { AssistantMessage, ImageContent, Message, Model, TextContent } from "@earendil-works/pi-ai";
|
||||
import type { AssistantMessage, ImageContent, Message, Model, TextContent } from "@earendil-works/pi-ai/compat";
|
||||
import {
|
||||
clampThinkingLevel,
|
||||
cleanupSessionResources,
|
||||
@@ -32,7 +32,7 @@ import {
|
||||
modelsAreEqual,
|
||||
resetApiProviders,
|
||||
streamSimple,
|
||||
} from "@earendil-works/pi-ai";
|
||||
} from "@earendil-works/pi-ai/compat";
|
||||
import { getThemeByName, theme } from "../modes/interactive/theme/theme.ts";
|
||||
import { stripFrontmatter } from "../utils/frontmatter.ts";
|
||||
import { resolvePath } from "../utils/paths.ts";
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
type OAuthCredentials,
|
||||
type OAuthLoginCallbacks,
|
||||
type OAuthProviderId,
|
||||
} from "@earendil-works/pi-ai";
|
||||
} from "@earendil-works/pi-ai/compat";
|
||||
import { getOAuthApiKey, getOAuthProvider, getOAuthProviders } from "@earendil-works/pi-ai/oauth";
|
||||
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
||||
import { dirname, join } from "path";
|
||||
@@ -41,6 +41,10 @@ export type AuthStatus = {
|
||||
label?: string;
|
||||
};
|
||||
|
||||
export interface GetApiKeyOptions {
|
||||
includeFallback?: boolean;
|
||||
}
|
||||
|
||||
type LockResult<T> = {
|
||||
result: T;
|
||||
next?: string;
|
||||
@@ -199,7 +203,6 @@ export class InMemoryAuthStorageBackend implements AuthStorageBackend {
|
||||
export class AuthStorage {
|
||||
private data: AuthStorageData = {};
|
||||
private runtimeOverrides: Map<string, string> = new Map();
|
||||
private fallbackResolver?: (provider: string) => string | undefined;
|
||||
private loadError: Error | null = null;
|
||||
private errors: Error[] = [];
|
||||
private storage: AuthStorageBackend;
|
||||
@@ -238,14 +241,6 @@ export class AuthStorage {
|
||||
this.runtimeOverrides.delete(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a fallback resolver for API keys not found in auth.json or env vars.
|
||||
* Used for custom provider keys from models.json.
|
||||
*/
|
||||
setFallbackResolver(resolver: (provider: string) => string | undefined): void {
|
||||
this.fallbackResolver = resolver;
|
||||
}
|
||||
|
||||
private recordError(error: unknown): void {
|
||||
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
||||
this.errors.push(normalizedError);
|
||||
@@ -350,7 +345,6 @@ export class AuthStorage {
|
||||
if (this.runtimeOverrides.has(provider)) return true;
|
||||
if (this.data[provider]) return true;
|
||||
if (getEnvApiKey(provider)) return true;
|
||||
if (this.fallbackResolver?.(provider)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -371,10 +365,6 @@ export class AuthStorage {
|
||||
return { configured: false, source: "environment", label: envKeys[0] };
|
||||
}
|
||||
|
||||
if (this.fallbackResolver?.(provider)) {
|
||||
return { configured: false, source: "fallback", label: "custom provider config" };
|
||||
}
|
||||
|
||||
return { configured: false };
|
||||
}
|
||||
|
||||
@@ -468,9 +458,8 @@ export class AuthStorage {
|
||||
* 2. API key from auth.json
|
||||
* 3. OAuth token from auth.json (auto-refreshed with locking)
|
||||
* 4. Environment variable
|
||||
* 5. Fallback resolver (models.json custom providers)
|
||||
*/
|
||||
async getApiKey(providerId: string, options?: { includeFallback?: boolean }): Promise<string | undefined> {
|
||||
async getApiKey(providerId: string, options: GetApiKeyOptions = {}): Promise<string | undefined> {
|
||||
// Runtime override takes highest priority
|
||||
const runtimeKey = this.runtimeOverrides.get(providerId);
|
||||
if (runtimeKey) {
|
||||
@@ -521,15 +510,12 @@ export class AuthStorage {
|
||||
}
|
||||
}
|
||||
|
||||
if (options.includeFallback === false) return undefined;
|
||||
|
||||
// Fall back to environment variable
|
||||
const envKey = getEnvApiKey(providerId);
|
||||
if (envKey) return envKey;
|
||||
|
||||
// Fall back to custom resolver (e.g., models.json custom providers)
|
||||
if (options?.includeFallback !== false) {
|
||||
return this.fallbackResolver?.(providerId) ?? undefined;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
*/
|
||||
|
||||
import type { AgentMessage, StreamFn } from "@earendil-works/pi-agent-core";
|
||||
import type { Model, SimpleStreamOptions } from "@earendil-works/pi-ai";
|
||||
import { completeSimple } from "@earendil-works/pi-ai";
|
||||
import type { Model, SimpleStreamOptions } from "@earendil-works/pi-ai/compat";
|
||||
import { completeSimple } from "@earendil-works/pi-ai/compat";
|
||||
import {
|
||||
convertToLlm,
|
||||
createBranchSummaryMessage,
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
*/
|
||||
|
||||
import type { AgentMessage, StreamFn, ThinkingLevel } from "@earendil-works/pi-agent-core";
|
||||
import type { AssistantMessage, Context, Model, SimpleStreamOptions, Usage } from "@earendil-works/pi-ai";
|
||||
import { completeSimple } from "@earendil-works/pi-ai";
|
||||
import type { AssistantMessage, Context, Model, SimpleStreamOptions, Usage } from "@earendil-works/pi-ai/compat";
|
||||
import { completeSimple } from "@earendil-works/pi-ai/compat";
|
||||
import {
|
||||
convertToLlm,
|
||||
createBranchSummaryMessage,
|
||||
|
||||
@@ -8,7 +8,7 @@ import { createRequire } from "node:module";
|
||||
import * as path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import * as _bundledPiAgentCore from "@earendil-works/pi-agent-core";
|
||||
import * as _bundledPiAi from "@earendil-works/pi-ai";
|
||||
import * as _bundledPiAiCompat from "@earendil-works/pi-ai/compat";
|
||||
import * as _bundledPiAiOauth from "@earendil-works/pi-ai/oauth";
|
||||
import type { KeyId } from "@earendil-works/pi-tui";
|
||||
import * as _bundledPiTui from "@earendil-works/pi-tui";
|
||||
@@ -50,12 +50,17 @@ const VIRTUAL_MODULES: Record<string, unknown> = {
|
||||
"@sinclair/typebox/value": _bundledTypeboxValue,
|
||||
"@earendil-works/pi-agent-core": _bundledPiAgentCore,
|
||||
"@earendil-works/pi-tui": _bundledPiTui,
|
||||
"@earendil-works/pi-ai": _bundledPiAi,
|
||||
// Extensions resolve the pi-ai root to the compat entrypoint (a strict
|
||||
// superset of the core entrypoint): existing extensions using the old
|
||||
// global API keep working at runtime until compat is removed.
|
||||
"@earendil-works/pi-ai": _bundledPiAiCompat,
|
||||
"@earendil-works/pi-ai/compat": _bundledPiAiCompat,
|
||||
"@earendil-works/pi-ai/oauth": _bundledPiAiOauth,
|
||||
"@earendil-works/pi-coding-agent": _bundledPiCodingAgent,
|
||||
"@mariozechner/pi-agent-core": _bundledPiAgentCore,
|
||||
"@mariozechner/pi-tui": _bundledPiTui,
|
||||
"@mariozechner/pi-ai": _bundledPiAi,
|
||||
"@mariozechner/pi-ai": _bundledPiAiCompat,
|
||||
"@mariozechner/pi-ai/compat": _bundledPiAiCompat,
|
||||
"@mariozechner/pi-ai/oauth": _bundledPiAiOauth,
|
||||
"@mariozechner/pi-coding-agent": _bundledPiCodingAgent,
|
||||
};
|
||||
@@ -90,19 +95,24 @@ function getAliases(): Record<string, string> {
|
||||
const piCodingAgentEntry = packageIndex;
|
||||
const piAgentCoreEntry = resolveWorkspaceOrImport("agent/dist/index.js", "@earendil-works/pi-agent-core");
|
||||
const piTuiEntry = resolveWorkspaceOrImport("tui/dist/index.js", "@earendil-works/pi-tui");
|
||||
const piAiEntry = resolveWorkspaceOrImport("ai/dist/index.js", "@earendil-works/pi-ai");
|
||||
// Extensions resolve the pi-ai root to the compat entrypoint (a strict
|
||||
// superset of the core entrypoint): existing extensions using the old
|
||||
// global API keep working at runtime until compat is removed.
|
||||
const piAiCompatEntry = resolveWorkspaceOrImport("ai/dist/compat.js", "@earendil-works/pi-ai/compat");
|
||||
const piAiOauthEntry = resolveWorkspaceOrImport("ai/dist/oauth.js", "@earendil-works/pi-ai/oauth");
|
||||
|
||||
_aliases = {
|
||||
"@earendil-works/pi-coding-agent": piCodingAgentEntry,
|
||||
"@earendil-works/pi-agent-core": piAgentCoreEntry,
|
||||
"@earendil-works/pi-tui": piTuiEntry,
|
||||
"@earendil-works/pi-ai": piAiEntry,
|
||||
"@earendil-works/pi-ai": piAiCompatEntry,
|
||||
"@earendil-works/pi-ai/compat": piAiCompatEntry,
|
||||
"@earendil-works/pi-ai/oauth": piAiOauthEntry,
|
||||
"@mariozechner/pi-coding-agent": piCodingAgentEntry,
|
||||
"@mariozechner/pi-agent-core": piAgentCoreEntry,
|
||||
"@mariozechner/pi-tui": piTuiEntry,
|
||||
"@mariozechner/pi-ai": piAiEntry,
|
||||
"@mariozechner/pi-ai": piAiCompatEntry,
|
||||
"@mariozechner/pi-ai/compat": piAiCompatEntry,
|
||||
"@mariozechner/pi-ai/oauth": piAiOauthEntry,
|
||||
typebox: typeboxEntry,
|
||||
"typebox/compile": typeboxCompileEntry,
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
registerApiProvider,
|
||||
resetApiProviders,
|
||||
type SimpleStreamOptions,
|
||||
} from "@earendil-works/pi-ai";
|
||||
} from "@earendil-works/pi-ai/compat";
|
||||
import { registerOAuthProvider, resetOAuthProviders } from "@earendil-works/pi-ai/oauth";
|
||||
import { existsSync, readFileSync } from "fs";
|
||||
import { join } from "path";
|
||||
@@ -801,7 +801,7 @@ export class ModelRegistry {
|
||||
* Get API key for a provider.
|
||||
*/
|
||||
async getApiKeyForProvider(provider: string): Promise<string | undefined> {
|
||||
const apiKey = await this.authStorage.getApiKey(provider, { includeFallback: false });
|
||||
const apiKey = await this.authStorage.getApiKey(provider);
|
||||
if (apiKey !== undefined) {
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { join } from "node:path";
|
||||
import { Agent, type AgentMessage, type ThinkingLevel } from "@earendil-works/pi-agent-core";
|
||||
import { clampThinkingLevel, type Message, type Model, streamSimple } from "@earendil-works/pi-ai";
|
||||
import { clampThinkingLevel, type Message, type Model, streamSimple } from "@earendil-works/pi-ai/compat";
|
||||
import { getAgentDir } from "../config.ts";
|
||||
import { resolvePath } from "../utils/paths.ts";
|
||||
import { AgentSession } from "./agent-session.ts";
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
type Model,
|
||||
type OAuthProviderId,
|
||||
type OAuthSelectPrompt,
|
||||
} from "@earendil-works/pi-ai";
|
||||
} from "@earendil-works/pi-ai/compat";
|
||||
import type {
|
||||
AutocompleteItem,
|
||||
AutocompleteProvider,
|
||||
|
||||
@@ -2,12 +2,8 @@ import { existsSync, mkdirSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { Agent } from "@earendil-works/pi-agent-core";
|
||||
import {
|
||||
type AssistantMessage,
|
||||
createAssistantMessageEventStream,
|
||||
fauxAssistantMessage,
|
||||
getModel,
|
||||
} from "@earendil-works/pi-ai";
|
||||
import { type AssistantMessage, createAssistantMessageEventStream, fauxAssistantMessage } from "@earendil-works/pi-ai";
|
||||
import { getModel } from "@earendil-works/pi-ai/compat";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { AgentSession } from "../src/core/agent-session.ts";
|
||||
import { AuthStorage } from "../src/core/auth-storage.ts";
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
import { existsSync, mkdirSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { getModel } from "@earendil-works/pi-ai";
|
||||
import { getModel } from "@earendil-works/pi-ai/compat";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import type { AgentSession } from "../src/core/agent-session.ts";
|
||||
import {
|
||||
|
||||
@@ -11,7 +11,7 @@ import { existsSync, mkdirSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { Agent } from "@earendil-works/pi-agent-core";
|
||||
import { getModel } from "@earendil-works/pi-ai";
|
||||
import { getModel } from "@earendil-works/pi-ai/compat";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { AgentSession, type AgentSessionEvent } from "../src/core/agent-session.ts";
|
||||
import { AuthStorage } from "../src/core/auth-storage.ts";
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
getModel,
|
||||
type ImageContent,
|
||||
type TextContent,
|
||||
} from "@earendil-works/pi-ai";
|
||||
} from "@earendil-works/pi-ai/compat";
|
||||
import { Type } from "typebox";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { AgentSession } from "../src/core/agent-session.ts";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { existsSync, mkdirSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { getModel } from "@earendil-works/pi-ai";
|
||||
import { getModel } from "@earendil-works/pi-ai/compat";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { AuthStorage } from "../src/core/auth-storage.ts";
|
||||
import { DefaultResourceLoader } from "../src/core/resource-loader.ts";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { existsSync, mkdirSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { getModel } from "@earendil-works/pi-ai";
|
||||
import { getModel } from "@earendil-works/pi-ai/compat";
|
||||
import { Type } from "typebox";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { DefaultResourceLoader } from "../src/core/resource-loader.ts";
|
||||
|
||||
@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { Agent, type AgentEvent, type AgentTool } from "@earendil-works/pi-agent-core";
|
||||
import { type AssistantMessage, type AssistantMessageEvent, EventStream, getModel } from "@earendil-works/pi-ai";
|
||||
import { type AssistantMessage, type AssistantMessageEvent, EventStream, getModel } from "@earendil-works/pi-ai/compat";
|
||||
import { Type } from "typebox";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { AgentSession } from "../src/core/agent-session.ts";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Agent } from "@earendil-works/pi-agent-core";
|
||||
import { type AssistantMessage, getModel, type Usage } from "@earendil-works/pi-ai";
|
||||
import { type AssistantMessage, getModel, type Usage } from "@earendil-works/pi-ai/compat";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { AgentSession } from "../src/core/agent-session.ts";
|
||||
import { AuthStorage } from "../src/core/auth-storage.ts";
|
||||
|
||||
@@ -6,7 +6,7 @@ import { existsSync, mkdirSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { Agent } from "@earendil-works/pi-agent-core";
|
||||
import { getModel } from "@earendil-works/pi-ai";
|
||||
import { getModel } from "@earendil-works/pi-ai/compat";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { AgentSession } from "../src/core/agent-session.ts";
|
||||
import { AuthStorage } from "../src/core/auth-storage.ts";
|
||||
|
||||
@@ -7,8 +7,8 @@ const { completeSimpleMock } = vi.hoisted(() => ({
|
||||
completeSimpleMock: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@earendil-works/pi-ai", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("@earendil-works/pi-ai")>();
|
||||
vi.mock("@earendil-works/pi-ai/compat", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("@earendil-works/pi-ai/compat")>();
|
||||
return {
|
||||
...actual,
|
||||
completeSimple: completeSimpleMock,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
||||
import type { AssistantMessage, Usage } from "@earendil-works/pi-ai";
|
||||
import { getModel } from "@earendil-works/pi-ai";
|
||||
import type { AssistantMessage, Usage } from "@earendil-works/pi-ai/compat";
|
||||
import { getModel } from "@earendil-works/pi-ai/compat";
|
||||
import { readFileSync } from "fs";
|
||||
import { join } from "path";
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import type { AnthropicMessagesCompat, Api, Context, Model, OpenAICompletionsCompat } from "@earendil-works/pi-ai";
|
||||
import { getApiProvider } from "@earendil-works/pi-ai";
|
||||
import type {
|
||||
AnthropicMessagesCompat,
|
||||
Api,
|
||||
Context,
|
||||
Model,
|
||||
OpenAICompletionsCompat,
|
||||
} from "@earendil-works/pi-ai/compat";
|
||||
import { getApiProvider } from "@earendil-works/pi-ai/compat";
|
||||
import { getOAuthProvider } from "@earendil-works/pi-ai/oauth";
|
||||
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
||||
import { AuthStorage } from "../src/core/auth-storage.ts";
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
EventStream,
|
||||
getModel,
|
||||
type Model,
|
||||
} from "@earendil-works/pi-ai";
|
||||
} from "@earendil-works/pi-ai/compat";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { AgentSession } from "../src/core/agent-session.ts";
|
||||
import type { AgentSessionRuntime } from "../src/core/agent-session-runtime.ts";
|
||||
|
||||
@@ -20,11 +20,11 @@ import {
|
||||
type Model,
|
||||
type SimpleStreamOptions,
|
||||
Type,
|
||||
} from "@earendil-works/pi-ai";
|
||||
} from "@earendil-works/pi-ai/compat";
|
||||
import {
|
||||
getOpenAICodexWebSocketDebugStats,
|
||||
streamSimpleOpenAICodexResponses,
|
||||
} from "../../ai/src/providers/openai-codex-responses.ts";
|
||||
streamSimple as streamSimpleOpenAICodexResponses,
|
||||
} from "../../ai/src/api/openai-codex-responses.ts";
|
||||
import { AuthStorage } from "../src/core/auth-storage.ts";
|
||||
import { createExtensionRuntime } from "../src/core/extensions/loader.ts";
|
||||
import type { ToolDefinition } from "../src/core/extensions/types.ts";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { existsSync, mkdirSync, realpathSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { getModel } from "@earendil-works/pi-ai";
|
||||
import { getModel } from "@earendil-works/pi-ai/compat";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { createAgentSession } from "../src/core/sdk.ts";
|
||||
import { SessionManager } from "../src/core/session-manager.ts";
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import {
|
||||
existsSync,
|
||||
mkdirSync,
|
||||
mkdtempSync,
|
||||
readdirSync,
|
||||
readFileSync,
|
||||
realpathSync,
|
||||
rmSync,
|
||||
writeFileSync,
|
||||
} from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join, resolve } from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
@@ -15,7 +24,10 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
function createTempDir(): string {
|
||||
const dir = mkdtempSync(join(tmpdir(), "pi-session-id-readonly-"));
|
||||
// realpath: on macOS tmpdir() is a symlink (/var -> /private/var), but the
|
||||
// spawned CLI sees the physical path via process.cwd(). Session cwd
|
||||
// filtering compares paths textually, so the fixture must use physical paths.
|
||||
const dir = realpathSync(mkdtempSync(join(tmpdir(), "pi-session-id-readonly-")));
|
||||
tempDirs.push(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import { existsSync, mkdirSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { getModel } from "@earendil-works/pi-ai";
|
||||
import { getModel } from "@earendil-works/pi-ai/compat";
|
||||
import { Type } from "typebox";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { DefaultResourceLoader } from "../../../src/core/resource-loader.ts";
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import { existsSync, mkdirSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { getModel } from "@earendil-works/pi-ai";
|
||||
import { getModel } from "@earendil-works/pi-ai/compat";
|
||||
import { Type } from "typebox";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync }
|
||||
import { homedir, tmpdir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { Agent } from "@earendil-works/pi-agent-core";
|
||||
import { getModel, type OAuthCredentials, type OAuthProvider } from "@earendil-works/pi-ai";
|
||||
import { getModel, type OAuthCredentials, type OAuthProvider } from "@earendil-works/pi-ai/compat";
|
||||
import { getOAuthApiKey } from "@earendil-works/pi-ai/oauth";
|
||||
import { AgentSession } from "../src/core/agent-session.ts";
|
||||
import { AuthStorage } from "../src/core/auth-storage.ts";
|
||||
|
||||
@@ -2,6 +2,7 @@ import { fileURLToPath } from "node:url";
|
||||
import { defineConfig } from "vitest/config";
|
||||
|
||||
const aiSrcIndex = fileURLToPath(new URL("../ai/src/index.ts", import.meta.url));
|
||||
const aiSrcCompat = fileURLToPath(new URL("../ai/src/compat.ts", import.meta.url));
|
||||
const aiSrcOAuth = fileURLToPath(new URL("../ai/src/oauth.ts", import.meta.url));
|
||||
const agentSrcIndex = fileURLToPath(new URL("../agent/src/index.ts", import.meta.url));
|
||||
const tuiSrcIndex = fileURLToPath(new URL("../tui/src/index.ts", import.meta.url));
|
||||
@@ -20,6 +21,7 @@ export default defineConfig({
|
||||
resolve: {
|
||||
alias: [
|
||||
{ find: /^@earendil-works\/pi-ai$/, replacement: aiSrcIndex },
|
||||
{ find: /^@earendil-works\/pi-ai\/compat$/, replacement: aiSrcCompat },
|
||||
{ find: /^@earendil-works\/pi-ai\/oauth$/, replacement: aiSrcOAuth },
|
||||
{ find: /^@earendil-works\/pi-agent-core$/, replacement: agentSrcIndex },
|
||||
{ find: /^@earendil-works\/pi-tui$/, replacement: tuiSrcIndex },
|
||||
|
||||
Reference in New Issue
Block a user