More browser extension work, disable ajv validation in browser extensions, it uses eval/new Function, which is not allowed in manifest v3 extensions

This commit is contained in:
Mario Zechner 2025-10-01 20:30:49 +02:00
parent fc1ef04b6d
commit 0e932a97df
14 changed files with 1151 additions and 11 deletions

View file

@ -4,6 +4,7 @@ import { LitElement } from "lit";
import { customElement, state } from "lit/decorators.js";
import "./AgentInterface.js";
import { AgentSession } from "./state/agent-session.js";
import { browserJavaScriptTool, createJavaScriptReplTool } from "./tools/index.js";
import { getAuthToken } from "./utils/auth-token.js";
@customElement("pi-chat-panel")
@ -23,17 +24,44 @@ export class ChatPanel extends LitElement {
this.style.height = "100%";
this.style.minHeight = "0";
// Create JavaScript REPL tool with attachments provider
const javascriptReplTool = createJavaScriptReplTool();
// Create agent session with default settings
this.session = new AgentSession({
initialState: {
systemPrompt: "You are a helpful AI assistant.",
model: getModel("anthropic", "claude-3-5-haiku-20241022"),
tools: [calculateTool, getCurrentTimeTool],
tools: [calculateTool, getCurrentTimeTool, browserJavaScriptTool, javascriptReplTool],
thinkingLevel: "off",
},
authTokenProvider: async () => getAuthToken(),
transportMode: "direct", // Use direct mode by default (API keys from KeyStore)
});
// Wire up attachments provider for JavaScript REPL tool
// We'll need to get attachments from the AgentInterface
javascriptReplTool.attachmentsProvider = () => {
// Get all attachments from conversation messages
const attachments: any[] = [];
for (const message of this.session.state.messages) {
if (message.role === "user") {
const content = Array.isArray(message.content) ? message.content : [message.content];
for (const block of content) {
if (typeof block !== "string" && block.type === "image") {
attachments.push({
id: `image-${attachments.length}`,
fileName: "image.png",
mimeType: block.mimeType || "image/png",
size: 0,
content: block.data,
});
}
}
}
}
return attachments;
};
}
render() {