aaea0f4600
Major changes: - Migrate browser-extension to use web-ui package (85% code reduction) - Add JailJS content script with ES6+ transform support - Expose DOM constructors (Event, KeyboardEvent, etc.) to JailJS - Support top-level await by wrapping code in async IIFE - Add returnFile() support in JailJS execution - Refactor KeyStore into pluggable storage-adapter pattern - Make ChatPanel configurable with sandboxUrlProvider and additionalTools - Update jailjs to 0.1.1 Files deleted (33 duplicate files): - All browser-extension components, dialogs, state, tools, utils - Now using web-ui versions via @mariozechner/pi-web-ui Files added: - packages/browser-extension/src/content.ts (JailJS content script) - packages/web-ui/src/state/storage-adapter.ts - packages/web-ui/src/state/key-store.ts Browser extension now has only 5 source files (down from 38).
33 lines
978 B
TypeScript
33 lines
978 B
TypeScript
import { type AgentContext, agentLoop, type Message, type PromptConfig, type UserMessage } from "@mariozechner/pi-ai";
|
|
import { getKeyStore } from "../key-store.js";
|
|
import type { AgentRunConfig, AgentTransport } from "./types.js";
|
|
|
|
export class DirectTransport implements AgentTransport {
|
|
constructor(private readonly getMessages: () => Promise<Message[]>) {}
|
|
|
|
async *run(userMessage: Message, cfg: AgentRunConfig, signal?: AbortSignal) {
|
|
// Get API key from KeyStore
|
|
const apiKey = await getKeyStore().getKey(cfg.model.provider);
|
|
if (!apiKey) {
|
|
throw new Error("no-api-key");
|
|
}
|
|
|
|
const context: AgentContext = {
|
|
systemPrompt: cfg.systemPrompt,
|
|
messages: await this.getMessages(),
|
|
tools: cfg.tools,
|
|
};
|
|
|
|
const pc: PromptConfig = {
|
|
model: cfg.model,
|
|
reasoning: cfg.reasoning,
|
|
apiKey,
|
|
};
|
|
|
|
// Yield events from agentLoop
|
|
for await (const ev of agentLoop(userMessage as unknown as UserMessage, context, pc, signal)) {
|
|
yield ev;
|
|
}
|
|
}
|
|
}
|