refactor(coding-agent): optimized module exports and configuration

- Refactor deep imports by targeting specific sub-modules in `@oh-my-pi/pi-ai` to reduce barrel file overhead.
- Utilize jitless ArkType scopes in schema definitions to reduce startup JIT codegen costs by approximately 65%.
- Reorganize internal `auth-storage` exports to maintain clean boundaries between core and broker-specific functionality.
This commit is contained in:
can1357
2026-06-18 19:33:48 +02:00
parent 021d82ac1f
commit 2a92ff8a98
14 changed files with 42 additions and 54 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
export { type Type, type } from "arktype";
export { type ZodType, z } from "zod/v4";
export * from "./api-registry";
export * from "./auth-broker";
export { type AuthGatewayBootOptions, type ModelResolver, startAuthGateway } from "./auth-gateway/server";
export type * from "./auth-broker";
export type { AuthGatewayBootOptions, ModelResolver } from "./auth-gateway/server";
export * from "./auth-gateway/types";
export * from "./auth-retry";
export * from "./auth-storage";
@@ -2,16 +2,13 @@ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { AuthStorage, type OAuthCredential, REMOTE_REFRESH_SENTINEL, SqliteAuthCredentialStore } from "@oh-my-pi/pi-ai";
import {
AuthBrokerClient,
type AuthBrokerServerHandle,
AuthStorage,
type OAuthCredential,
REMOTE_REFRESH_SENTINEL,
RemoteAuthCredentialStore,
SqliteAuthCredentialStore,
startAuthBroker,
} from "@oh-my-pi/pi-ai";
} from "@oh-my-pi/pi-ai/auth-broker";
// MCP OAuth credentials extend the base OAuthCredential with refresh material
// (tokenUrl/clientId/clientSecret/resource) embedded so token refresh works for
@@ -2,7 +2,8 @@ import { afterEach, beforeEach, describe, expect, test, vi } from "bun:test";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { AuthBrokerRefresher, AuthStorage, SqliteAuthCredentialStore } from "@oh-my-pi/pi-ai";
import { AuthStorage, SqliteAuthCredentialStore } from "@oh-my-pi/pi-ai";
import { AuthBrokerRefresher } from "@oh-my-pi/pi-ai/auth-broker";
import * as oauthUtils from "@oh-my-pi/pi-ai/registry/oauth";
const ANTHROPIC_ENV = ["ANTHROPIC_API_KEY", "ANTHROPIC_OAUTH_TOKEN"] as const;
@@ -2,16 +2,14 @@ import { afterEach, beforeEach, describe, expect, test, vi } from "bun:test";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { AuthStorage, REMOTE_REFRESH_SENTINEL, SqliteAuthCredentialStore } from "@oh-my-pi/pi-ai";
import {
AuthBrokerClient,
type AuthBrokerServerHandle,
AuthStorage,
REMOTE_REFRESH_SENTINEL,
RemoteAuthCredentialStore,
type SnapshotResponse,
SqliteAuthCredentialStore,
startAuthBroker,
} from "@oh-my-pi/pi-ai";
} from "@oh-my-pi/pi-ai/auth-broker";
const ANTHROPIC_ENV = ["ANTHROPIC_API_KEY", "ANTHROPIC_OAUTH_TOKEN"] as const;
const savedEnv: Partial<Record<(typeof ANTHROPIC_ENV)[number], string | undefined>> = {};
@@ -2,7 +2,11 @@ import { describe, expect, test } from "bun:test";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { readAuthBrokerSnapshotCache, type SnapshotResponse, writeAuthBrokerSnapshotCache } from "@oh-my-pi/pi-ai";
import {
readAuthBrokerSnapshotCache,
type SnapshotResponse,
writeAuthBrokerSnapshotCache,
} from "@oh-my-pi/pi-ai/auth-broker";
const TOKEN = "broker-cache-token";
const URL = "http://127.0.0.1:8765";
+2 -4
View File
@@ -2,16 +2,14 @@ import { afterEach, beforeEach, describe, expect, test, vi } from "bun:test";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { AuthStorage, REMOTE_REFRESH_SENTINEL, SqliteAuthCredentialStore } from "@oh-my-pi/pi-ai";
import {
AuthBrokerClient,
type AuthBrokerServerHandle,
AuthBrokerStreamUnsupportedError,
AuthStorage,
REMOTE_REFRESH_SENTINEL,
type SnapshotStreamEvent,
SqliteAuthCredentialStore,
startAuthBroker,
} from "@oh-my-pi/pi-ai";
} from "@oh-my-pi/pi-ai/auth-broker";
import * as oauthUtils from "@oh-my-pi/pi-ai/registry/oauth";
const ANTHROPIC_ENV = ["ANTHROPIC_API_KEY", "ANTHROPIC_OAUTH_TOKEN"] as const;
+2 -4
View File
@@ -2,15 +2,13 @@ import { afterEach, beforeEach, describe, expect, test, vi } from "bun:test";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { AuthStorage, REMOTE_REFRESH_SENTINEL, SqliteAuthCredentialStore } from "@oh-my-pi/pi-ai";
import {
AuthBrokerClient,
type AuthBrokerServerHandle,
AuthStorage,
REMOTE_REFRESH_SENTINEL,
RemoteAuthCredentialStore,
SqliteAuthCredentialStore,
startAuthBroker,
} from "@oh-my-pi/pi-ai";
} from "@oh-my-pi/pi-ai/auth-broker";
import * as oauthUtils from "@oh-my-pi/pi-ai/registry/oauth";
const ANTHROPIC_ENV = ["ANTHROPIC_API_KEY", "ANTHROPIC_OAUTH_TOKEN"] as const;
@@ -19,11 +19,9 @@ import * as os from "node:os";
import * as path from "node:path";
import * as readline from "node:readline";
import {
AuthBrokerClient,
type AuthCredential,
AuthStorage,
type CredentialDisabledEvent,
DEFAULT_AUTH_BROKER_BIND,
getEnvApiKey,
getOAuthProviders,
listProvidersWithEnvKey,
@@ -32,8 +30,8 @@ import {
type OAuthProviderInfo,
PROVIDER_REGISTRY,
SqliteAuthCredentialStore,
startAuthBroker,
} from "@oh-my-pi/pi-ai";
import { AuthBrokerClient, DEFAULT_AUTH_BROKER_BIND, startAuthBroker } from "@oh-my-pi/pi-ai/auth-broker";
import { $which, APP_NAME, getAgentDbPath, getConfigRootDir, isEnoent, logger, VERSION } from "@oh-my-pi/pi-utils";
import { setTransports as setLoggerTransports } from "@oh-my-pi/pi-utils/logger";
import { $ } from "bun";
@@ -17,18 +17,15 @@ import * as fs from "node:fs/promises";
import * as path from "node:path";
import {
type Api,
AuthBrokerClient,
AuthStorage,
type CompletionProbe,
type CompletionProbeInput,
type CredentialCompletionResult,
completeSimple,
DEFAULT_AUTH_GATEWAY_BIND,
type Model,
RemoteAuthCredentialStore,
type SnapshotResponse,
startAuthGateway,
} from "@oh-my-pi/pi-ai";
import { AuthBrokerClient, RemoteAuthCredentialStore, type SnapshotResponse } from "@oh-my-pi/pi-ai/auth-broker";
import { DEFAULT_AUTH_GATEWAY_BIND, startAuthGateway } from "@oh-my-pi/pi-ai/auth-gateway";
import { type GeneratedProvider, getBundledModels, getBundledProviders } from "@oh-my-pi/pi-catalog/models";
import { getConfigRootDir, isEnoent, VERSION } from "@oh-my-pi/pi-utils";
import chalk from "chalk";
@@ -1,4 +1,11 @@
import { type } from "arktype";
import { scope } from "arktype";
// Config schemas validate at most a handful of times per process (on config
// load), so the eager JIT codegen ArkType runs at definition time is pure
// startup tax. A local jitless scope skips that codegen and falls back to
// interpreted traversal — ~65% cheaper to construct, validation correctness
// unchanged. (No `name`: duplicate module instances would collide.)
const { type } = scope({}, { jitless: true });
const OpenRouterRoutingSchema = type({
"only?": "string[]",
+5 -9
View File
@@ -56,6 +56,10 @@ import { loadPromptTemplates as loadPromptTemplatesInternal, type PromptTemplate
import { Settings, type SkillsSettings } from "./config/settings";
import { CursorExecHandlers } from "./cursor";
import "./discovery";
import { AuthBrokerClient } from "@oh-my-pi/pi-ai/auth-broker/client";
import { RemoteAuthCredentialStore } from "@oh-my-pi/pi-ai/auth-broker/remote-store";
import { readAuthBrokerSnapshotCache, writeAuthBrokerSnapshotCache } from "@oh-my-pi/pi-ai/auth-broker/snapshot-cache";
import { DEFAULT_SNAPSHOT_CACHE_TTL_MS, type SnapshotResponse } from "@oh-my-pi/pi-ai/auth-broker/types";
import { resolveConfigValue } from "./config/resolve-config-value";
import { initializeWithSettings } from "./discovery";
import { disposeAllKernelSessions, disposeKernelSessionsByOwner } from "./eval/py/executor";
@@ -116,15 +120,7 @@ import {
} from "./secrets";
import { AgentSession } from "./session/agent-session";
import { resolveAuthBrokerConfig } from "./session/auth-broker-config";
import {
AuthBrokerClient,
AuthStorage,
DEFAULT_SNAPSHOT_CACHE_TTL_MS,
RemoteAuthCredentialStore,
readAuthBrokerSnapshotCache,
type SnapshotResponse,
writeAuthBrokerSnapshotCache,
} from "./session/auth-storage";
import { AuthStorage } from "./session/auth-storage";
import {
type CustomMessage,
convertToLlm,
@@ -18,16 +18,7 @@ export type {
ResetCreditRedeemOutcome,
ResetCreditTarget,
SerializedAuthStorage,
SnapshotResponse,
StoredAuthCredential,
} from "@oh-my-pi/pi-ai";
export {
AuthBrokerClient,
AuthStorage,
DEFAULT_SNAPSHOT_CACHE_TTL_MS,
REMOTE_REFRESH_SENTINEL,
RemoteAuthCredentialStore,
readAuthBrokerSnapshotCache,
SqliteAuthCredentialStore,
writeAuthBrokerSnapshotCache,
} from "@oh-my-pi/pi-ai";
export { AuthStorage, REMOTE_REFRESH_SENTINEL, SqliteAuthCredentialStore } from "@oh-my-pi/pi-ai";
export type { SnapshotResponse } from "@oh-my-pi/pi-ai/auth-broker/types";
@@ -2,7 +2,8 @@ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { type AuthBrokerServerHandle, AuthStorage, SqliteAuthCredentialStore, startAuthBroker } from "@oh-my-pi/pi-ai";
import { AuthStorage, SqliteAuthCredentialStore } from "@oh-my-pi/pi-ai";
import { type AuthBrokerServerHandle, startAuthBroker } from "@oh-my-pi/pi-ai/auth-broker";
import { runAuthBrokerCommand } from "@oh-my-pi/pi-coding-agent/cli/auth-broker-cli";
import { getAgentDbPath, setAgentDir } from "@oh-my-pi/pi-utils";
@@ -2,13 +2,15 @@ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { type AuthBrokerServerHandle, AuthStorage, SqliteAuthCredentialStore, startAuthBroker } from "@oh-my-pi/pi-ai";
import { discoverAuthStorage } from "@oh-my-pi/pi-coding-agent/sdk";
import { AuthStorage, SqliteAuthCredentialStore } from "@oh-my-pi/pi-ai";
import {
type AuthBrokerServerHandle,
readAuthBrokerSnapshotCache,
type SnapshotResponse,
startAuthBroker,
writeAuthBrokerSnapshotCache,
} from "@oh-my-pi/pi-coding-agent/session/auth-storage";
} from "@oh-my-pi/pi-ai/auth-broker";
import { discoverAuthStorage } from "@oh-my-pi/pi-coding-agent/sdk";
const ENV_KEYS = [
"OMP_AUTH_BROKER_URL",