Files
pi/scripts/browser-smoke-entry.ts
Mario Zechner 8a0903ebf2 feat(ai): compat entrypoint, core-only root barrel (phase 5)
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.
2026-06-10 21:17:12 +02:00

62 lines
2.0 KiB
TypeScript

import { createAssistantMessageEventStream, Type } from "@earendil-works/pi-ai";
import { complete, getModel, getProviders } from "@earendil-works/pi-ai/compat";
import {
Agent,
bashExecutionToText,
convertToLlm,
createCustomMessage,
FileError,
formatPromptTemplateInvocation,
formatSkillInvocation,
formatSkillsForSystemPrompt,
getOrThrow,
InMemorySessionRepo,
ok,
parseCommandArgs,
streamProxy,
toError,
truncateHead,
} from "@earendil-works/pi-agent-core";
// Keep this entry browser-safe. It is bundled by scripts/check-browser-smoke.mjs
// to catch accidental Node-only runtime imports in browser-facing package exports.
const model = getModel("google", "gemini-2.5-flash");
const schema = Type.Object({ prompt: Type.String() });
const stream = createAssistantMessageEventStream();
const agent = new Agent({ initialState: { model } });
agent.steer({ role: "user", content: [{ type: "text", text: "queued" }], timestamp: 0 });
const repo = new InMemorySessionRepo();
const result = getOrThrow(ok({ value: 1 }));
const customMessage = createCustomMessage("note", "hello", true, undefined, "2026-01-01T00:00:00.000Z");
const llmMessages = convertToLlm([customMessage]);
const skill = { name: "browser-safe", description: "Smoke test", content: "Use browser APIs.", filePath: "/skills/browser-safe/SKILL.md" };
console.log(
model.id,
getProviders().length,
typeof complete,
schema.type,
typeof stream.push,
agent.hasQueuedMessages(),
typeof repo.create,
result.value,
llmMessages.length,
bashExecutionToText({
role: "bashExecution",
command: "echo ok",
output: "ok",
exitCode: 0,
cancelled: false,
truncated: false,
timestamp: 0,
}),
formatSkillsForSystemPrompt([skill]).length,
formatSkillInvocation(skill).length,
formatPromptTemplateInvocation({ name: "example", content: "$1 $@" }, parseCommandArgs('one "two three"')),
truncateHead("a\nb", { maxLines: 1 }).content,
new FileError("not_found", "missing").code,
toError("boom").message,
typeof streamProxy,
);