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.
60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
import { homedir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { getModel } from "@earendil-works/pi-ai/compat";
|
|
import { NodeExecutionEnv } from "../../src/harness/env/nodejs.ts";
|
|
import { InMemorySessionStorage } from "../../src/harness/session/memory-storage.ts";
|
|
import {
|
|
AgentHarness,
|
|
formatSkillsForSystemPrompt,
|
|
loadSourcedPromptTemplates,
|
|
loadSourcedSkills,
|
|
type PromptTemplate,
|
|
Session,
|
|
type Skill,
|
|
} from "../../src/index.ts";
|
|
|
|
type Source = { type: "project" | "user" | "path"; dir: string };
|
|
type SourcedSkill = Skill & { source: Source };
|
|
type SourcedPromptTemplate = PromptTemplate & { source: Source };
|
|
|
|
const env = new NodeExecutionEnv({ cwd: process.cwd() });
|
|
|
|
const source = (type: Source["type"], dir: string) => ({ path: dir, source: { type, dir } });
|
|
const { skills: sourcedSkills } = await loadSourcedSkills<Source, SourcedSkill>(
|
|
env,
|
|
[
|
|
source("project", join(env.cwd, ".pi/skills")),
|
|
source("user", join(homedir(), ".pi/agent/skills")),
|
|
source("path", join(env.cwd, "../../../pi-skills")),
|
|
],
|
|
(skill, source) => ({ ...skill, source }),
|
|
);
|
|
const { promptTemplates: sourcedPromptTemplates } = await loadSourcedPromptTemplates<Source, SourcedPromptTemplate>(
|
|
env,
|
|
[source("project", join(env.cwd, ".pi/prompts")), source("user", join(homedir(), ".pi/agent/prompts"))],
|
|
(promptTemplate, source) => ({ ...promptTemplate, source }),
|
|
);
|
|
|
|
const session = new Session(new InMemorySessionStorage());
|
|
const agent = new AgentHarness({
|
|
env,
|
|
session,
|
|
model: getModel("openai", "gpt-5.5"),
|
|
thinkingLevel: "low",
|
|
systemPrompt: ({ env, resources }) =>
|
|
[
|
|
"You are a helpful assistant.",
|
|
formatSkillsForSystemPrompt(resources.skills ?? []),
|
|
`Current working directory: ${env.cwd}`,
|
|
]
|
|
.filter((part) => part.length > 0)
|
|
.join("\n\n"),
|
|
resources: {
|
|
promptTemplates: sourcedPromptTemplates.map(({ promptTemplate }) => promptTemplate),
|
|
skills: sourcedSkills.map(({ skill }) => skill),
|
|
},
|
|
});
|
|
|
|
const response = await agent.prompt("What skills do you have? Any duplicates?");
|
|
console.log(response);
|