mirror of
https://github.com/earendil-works/pi.git
synced 2026-06-18 15:54:04 +08:00
8a0903ebf2
The root barrel is now core-only and side-effect free: types, createModels/createProvider, auth substrate, lazyStream/lazyApi, faux, utils. Generated catalogs, api-registry, env-api-keys, images, global stream functions, and per-API lazy wrappers leave the root. New @earendil-works/pi-ai/compat preserves the old surface verbatim as a strict superset of the root: api-dispatch stream/complete with env key injection, the builtin registration side effect (skip-if-present so it cannot clobber earlier overrides), deprecated getModel/getModels/ getProviders aliases of the new getBuiltin* reads in providers/all, lazy api wrappers + setBedrockProviderModule, and image generation. Compat dies with the coding-agent ModelManager migration. Packaging: exports map gains ./compat, ./providers/*, ./api/*; sideEffects array lists only the effectful modules. Old-global imports across agent/coding-agent/examples and pi-ai tests switch to /compat (path-only; compat is a superset). The coding-agent extension loader resolves the pi-ai ROOT specifier to compat, so existing user extensions using the old global API keep working at runtime until compat is removed. vitest configs alias /compat to src; browser smoke imports old globals from /compat.
78 lines
2.0 KiB
TypeScript
78 lines
2.0 KiB
TypeScript
/**
|
|
* Full Control
|
|
*
|
|
* Replace everything - no discovery, explicit configuration.
|
|
*/
|
|
|
|
import { getModel } from "@earendil-works/pi-ai/compat";
|
|
import {
|
|
AuthStorage,
|
|
createAgentSession,
|
|
createExtensionRuntime,
|
|
ModelRegistry,
|
|
type ResourceLoader,
|
|
SessionManager,
|
|
SettingsManager,
|
|
} from "@earendil-works/pi-coding-agent";
|
|
|
|
// Custom auth storage location
|
|
const authStorage = AuthStorage.create("/tmp/my-agent/auth.json");
|
|
|
|
// Runtime API key override (not persisted)
|
|
if (process.env.MY_ANTHROPIC_KEY) {
|
|
authStorage.setRuntimeApiKey("anthropic", process.env.MY_ANTHROPIC_KEY);
|
|
}
|
|
|
|
// Model registry with no custom models.json
|
|
const modelRegistry = ModelRegistry.inMemory(authStorage);
|
|
|
|
const model = getModel("anthropic", "claude-sonnet-4-20250514");
|
|
if (!model) throw new Error("Model not found");
|
|
|
|
// In-memory settings with overrides
|
|
const settingsManager = SettingsManager.inMemory({
|
|
compaction: { enabled: false },
|
|
retry: { enabled: true, maxRetries: 2 },
|
|
});
|
|
|
|
const cwd = process.cwd();
|
|
|
|
const resourceLoader: ResourceLoader = {
|
|
getExtensions: () => ({ extensions: [], errors: [], runtime: createExtensionRuntime() }),
|
|
getSkills: () => ({ skills: [], diagnostics: [] }),
|
|
getPrompts: () => ({ prompts: [], diagnostics: [] }),
|
|
getThemes: () => ({ themes: [], diagnostics: [] }),
|
|
getAgentsFiles: () => ({ agentsFiles: [] }),
|
|
getSystemPrompt: () => `You are a minimal assistant.
|
|
Available: read, bash. Be concise.`,
|
|
getAppendSystemPrompt: () => [],
|
|
extendResources: () => {},
|
|
reload: async () => {},
|
|
};
|
|
|
|
const { session } = await createAgentSession({
|
|
cwd,
|
|
agentDir: "/tmp/my-agent",
|
|
model,
|
|
thinkingLevel: "off",
|
|
authStorage,
|
|
modelRegistry,
|
|
resourceLoader,
|
|
tools: ["read", "bash"],
|
|
sessionManager: SessionManager.inMemory(cwd),
|
|
settingsManager,
|
|
});
|
|
|
|
try {
|
|
session.subscribe((event) => {
|
|
if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
|
|
process.stdout.write(event.assistantMessageEvent.delta);
|
|
}
|
|
});
|
|
|
|
await session.prompt("List files in the current directory.");
|
|
console.log();
|
|
} finally {
|
|
session.dispose();
|
|
}
|