Commit graph

108 commits

Author SHA1 Message Date
mom
ebd8e895ce fix: typos in comments (fixes #1016) 2026-01-28 01:56:34 +00:00
Timo Lins
65eb738c90 Rename to vercel-ai-gateway for clarity 2026-01-13 16:42:34 +01:00
Timo Lins
164a69a601 Add Vercel AI Gateway support 2026-01-13 16:42:34 +01:00
Mario Zechner
4d1936d3df AgentInterface sets default streamFn and getApiKey
- Make Agent.streamFn and Agent.getApiKey public
- AgentInterface sets defaults if not already set
- Example no longer needs to configure these
2025-12-30 22:42:21 +01:00
Mario Zechner
92898f486b Allow async streamFn for dynamic proxy settings
- StreamFn type now allows returning Promise
- agent-loop awaits streamFn result
- createStreamFn takes getProxyUrl callback, reads settings on each call
2025-12-30 22:42:21 +01:00
Mario Zechner
e0be2e650d Add createStreamFn for CORS proxy support
- createStreamFn(proxyUrl?) returns a sync streamFn that applies proxy
- Example reads proxy settings once when creating Agent
- Matches old ProviderTransport behavior
2025-12-30 22:42:21 +01:00
Mario Zechner
6972ce4e87 Clear streaming container on agent_end 2025-12-30 22:42:21 +01:00
Mario Zechner
347d4cf729 Fix AgentInterface to requestUpdate on all message lifecycle events
Was only handling message_update, now also handles message_start,
message_end, turn_start, turn_end, agent_start, agent_end.
2025-12-30 22:42:21 +01:00
Mario Zechner
13a1991ec2 Add defaultConvertToLlm to web-ui, simplify example
- web-ui exports: defaultConvertToLlm, convertAttachments, isUserMessageWithAttachments, isArtifactMessage
- defaultConvertToLlm handles UserMessageWithAttachments and filters ArtifactMessage
- Example's customMessageTransformer now extends defaultConvertToLlm
- Removes duplicated attachment conversion logic from example
2025-12-30 22:42:20 +01:00
Mario Zechner
7a39f9eb11 Fix web-ui and example for new agent API
- AgentInterface composes UserMessageWithAttachments for attachments
- Updated example to use convertToLlm instead of transport/messageTransformer
- Fixed declaration merging: target pi-agent-core, add path to example tsconfig
- Fixed typo in CustomAgentMessages key (user-with-attachment -> user-with-attachments)
- customMessageTransformer properly converts UserMessageWithAttachments to content blocks
2025-12-30 22:42:20 +01:00
Mario Zechner
6ddc7418da WIP: Major cleanup - move Attachment to consumers, simplify agent API
- Removed Attachment from agent package (now in web-ui/coding-agent)
- Agent.prompt now takes (text, images?: ImageContent[])
- Removed transports from web-ui (duplicate of agent package)
- Updated coding-agent to use local message types
- Updated mom package for new agent API

Remaining: Fix AgentInterface.ts to compose UserMessageWithAttachments
2025-12-30 22:42:20 +01:00
Kao Félix
a7efe3d4c1 fix: use consistent model comparison including provider 2025-12-25 22:10:08 +01:00
Mario Zechner
d5fd685901 Enable more biome lints and fix things 2025-12-21 22:56:20 +01:00
Ahmed Kamal
1167e84453
Fix expired OAuth tokens in long-running agent loops (#223)
Add getApiKey hook to AgentLoopConfig that resolves API keys dynamically
before each LLM call. This allows short-lived OAuth tokens (e.g. GitHub
Copilot, Anthropic OAuth) to be refreshed between turns when tool
execution takes a long time.

Previously, the API key was resolved once when ProviderTransport.run()
was called and passed as a static string to the agent loop. If the loop
ran for longer than the token lifetime (e.g. 30 minutes for Copilot),
subsequent LLM calls would fail with expired token errors.

Changes:
- Add getApiKey hook to AgentLoopConfig (packages/ai)
- Call getApiKey before each LLM call in streamAssistantResponse
- Update ProviderTransport to pass getApiKey instead of static apiKey
- Update web-ui ProviderTransport with same pattern
2025-12-19 01:36:25 +01:00
Mario Zechner
5a9d844f9a Simplify compaction: remove proactive abort, use Agent.continue() for retry
- Add agentLoopContinue() to pi-ai for resuming from existing context
- Add Agent.continue() method and transport.continue() interface
- Simplify AgentSession compaction to two cases: overflow (auto-retry) and threshold (no retry)
- Remove proactive mid-turn compaction abort
- Merge turn prefix summary into main summary
- Add isCompacting property to AgentSession and RPC state
- Block input during compaction in interactive mode
- Show compaction count on session resume
- Rename RPC.md to rpc.md for consistency

Related to #128
2025-12-09 21:43:49 +01:00
Mario Zechner
86e5a70ec4 Add totalTokens field to Usage type
- Added totalTokens field to Usage interface in pi-ai
- Anthropic: computed as input + output + cacheRead + cacheWrite
- OpenAI/Google: uses native total_tokens/totalTokenCount
- Fixed openai-completions to compute totalTokens when reasoning tokens present
- Updated calculateContextTokens() to use totalTokens field
- Added comprehensive test covering 13 providers

fixes #130
2025-12-06 22:46:02 +01:00
Mario Zechner
3932c5e04c Add lifecycle callbacks to SandboxRuntimeProvider for abort signal support
- Added onExecutionStart(sandboxId, signal) - called when sandbox execution begins
- Added onExecutionEnd(sandboxId) - called when sandbox execution ends
- Integrated callbacks in SandboxedIframe.execute()
- Enables providers to track and cancel async operations (e.g., userScript executions)
2025-11-16 00:56:20 +01:00
Mario Zechner
e533aebacd Fix Lit dependency duplication and update mini-lit to 0.2.0
- Move lit from dependencies to peerDependencies in web-ui to prevent multiple Lit instances being loaded
- Update mini-lit from 0.1.8/0.1.10 to 0.2.0 in root package.json and web-ui/package.json
- Install @tailwindcss/vite in web-ui/example
- Run biome formatting fixes across codebase

This resolves HMR custom element re-registration errors caused by duplicate Lit registries.
2025-11-12 16:03:43 +01:00
Mario Zechner
84dcab219b Add image support in tool results across all providers
Tool results now use content blocks and can include both text and images.
All providers (Anthropic, Google, OpenAI Completions, OpenAI Responses)
correctly pass images from tool results to LLMs.

- Update ToolResultMessage type to use content blocks
- Add placeholder text for image-only tool results in Google/Anthropic
- OpenAI providers send tool result + follow-up user message with images
- Fix Anthropic JSON parsing for empty tool arguments
- Add comprehensive tests for image-only and text+image tool results
- Update README with tool result content blocks API
2025-11-12 10:45:56 +01:00
Mario Zechner
904fc909c9 Fix lints 2025-11-10 21:55:55 +01:00
Mario Zechner
1f9a3a00cc Custom provider WIP 2025-11-10 21:47:21 +01:00
Mario Zechner
389c80d7a8 Improve web-ui message and tool UX
- Add collapsible thinking blocks with shimmer animation during streaming
- Update user messages to use orange gradient pill styling (matching sitegeist)
- Fix cost display to only show for completed messages, not while streaming
- Update tool renderers to use ChevronsUpDown/ChevronUp icons instead of rotating ChevronRight
- Export ThinkingBlock component from public API
2025-10-30 20:42:04 +01:00
Mario Zechner
9e50bb2c37 Fix ProviderKeyInput UX: improve save button state and remove clear button
- Add inputChanged state to track when user modifies input after save
- Remove Clear button and removeKey() method entirely
- Save button now disables after successful save until input changes
- Save button stays enabled on test failure (allows immediate retry)
- Keep input field showing stars (••••) after successful save instead of clearing

This provides clearer feedback and prevents accidental key deletion.
2025-10-29 21:14:19 +01:00
Mario Zechner
1726c1e3af Remove modelId from session metadata. Not needed, we grab it from the last assistantmessage. 2025-10-29 20:37:24 +01:00
Mario Zechner
92f8801864 Fix message editor height adjustment, requires Chrome +123 2025-10-29 16:11:05 +01:00
Mario Zechner
b6b64dff86 Better proxy handling. 2025-10-28 00:21:54 +01:00
Mario Zechner
55dc0b6e08 Add timestamp to messages 2025-10-26 00:43:43 +02:00
Mario Zechner
4ecbc2fe81 Debug tool rendering. 2025-10-18 01:11:31 +02:00
Mario Zechner
2d5054e6c0 Add reload button to HTML artifact header
Adds a reload button with RefreshCw icon to HTML artifact header buttons.
Clicking the button clears logs and re-executes the HTML content, useful
for manually refreshing when developing HTML artifacts or testing changes.

Changes:
- Import Button, icon from mini-lit and RefreshCw from lucide
- Add reload button to getHeaderButtons() that clears logs and calls executeContent()
- Add "Reload HTML" i18n key in English and German translations
2025-10-18 00:13:16 +02:00
Mario Zechner
92ce5a342f Add auto-reload for HTML artifacts when dependencies change
HTML artifacts can read other artifacts via getArtifact() and attachments.
When any artifact is created, updated, rewritten, or deleted, all HTML
artifacts now automatically reload to reflect the latest data.

Changes:
- Add reloadAllHtmlArtifacts() method to ArtifactsPanel
- Call reload after all artifact mutations (create/update/rewrite/delete)
- Make HtmlArtifact.sandboxIframeRef and executeContent() public
- Update runtime providers before re-executing HTML content

This ensures HTML artifacts always display current data from their dependencies.
2025-10-18 00:10:23 +02:00
Mario Zechner
2a7ccf0fcb Updates to prompts 2025-10-17 22:44:03 +02:00
Mario Zechner
ffc9be8867 Agent package + coding agent WIP, refactored web-ui prompts 2025-10-17 11:47:01 +02:00
Mario Zechner
949cd4efd8 Fix console.log duplication bug in ConsoleRuntimeProvider
Issue:
Each browser_javascript execution wrapped console methods, but captured
the current (already wrapped) console as "original". This created a chain
of wrappers that accumulated across executions:
- Execution 1: 1x console.log (wrapper1 → real console)
- Execution 2: 2x console.log (wrapper2 → wrapper1 → real console)
- Execution 3: 3x console.log (wrapper3 → wrapper2 → wrapper1 → real console)
- Execution 4: 4x console.log (and so on...)

Fix:
Store the truly original console methods in window.__originalConsole on
first wrap only. All subsequent executions use these stored original methods
instead of capturing the current console. This prevents wrapper accumulation.

Changes:
- Check if window.__originalConsole exists before wrapping
- Store original console methods with .bind() to preserve context
- Always use window.__originalConsole for local logging
- Now each execution logs exactly 1x regardless of execution count
2025-10-13 00:20:23 +02:00
Mario Zechner
f66d577eb2 Add paste image support to MessageEditor
- Add handlePaste method to detect and process pasted images
- Automatically attach pasted images as attachments
- Support multiple images in single paste
- Prevent default paste behavior for images (text paste still works normally)
- Use same loadAttachment utility as drag-and-drop for consistency
2025-10-12 19:47:38 +02:00
Mario Zechner
4079bced36 Fix TypeScript errors and export UserMessageWithAttachments
- Export UserMessageWithAttachments type from web-ui index
- Remove unused i18n import from extract-document tool
- Update models.generated.ts (model order changes from API)

This fixes type errors when sitegeist uses custom user message renderer
2025-10-12 17:09:14 +02:00
Mario Zechner
f8b98f7dac Add extract_document tool and improve artifacts tab scrolling
- Add extract_document tool for extracting text from PDF/DOCX/XLSX/PPTX from URLs
- CORS proxy support from settings for fetching documents
- Proper error messages guiding users on CORS issues and manual file attachment
- Add scroll-into-view for active artifact tabs
- Export extract_document tool from web-ui package
2025-10-12 16:24:36 +02:00
Mario Zechner
f93e72a805 Committing manually like the monkey I am 2025-10-12 02:59:46 +02:00
Mario Zechner
26b774bb04 Add standalone mode for HTML artifact downloads
When downloading HTML artifacts, the generated HTML now works standalone
without requiring the extension runtime.

Changes:
- Add PrepareHtmlOptions config object to SandboxedIframe.prepareHtmlDocument()
- Add isStandalone flag to skip runtime bridge and navigation interceptor
- When isStandalone=true:
  - window.sendRuntimeMessage is NOT defined
  - Navigation interceptor is NOT injected
  - Artifact runtime providers fall back to embedded data
- HtmlArtifact download button now uses isStandalone: true

This fixes the issue where downloaded HTML artifacts would:
- Try to call window.sendRuntimeMessage (which would fail silently)
- Try to postMessage to non-existent parent window
- Not work when opened via file:// protocol

Now downloaded artifacts work completely standalone with embedded data.
2025-10-12 00:39:26 +02:00
Mario Zechner
63bfe95c18 Fix up context check 2025-10-11 21:41:24 +02:00
Mario Zechner
8a96741441 Revert: Fix extension context detection - original logic was correct
The negated approach broke browser_script which runs in page context.
browser_script injects into web pages (http://, https://) where
chrome.runtime.sendMessage doesn't work. The original whitelist
approach correctly identifies extension contexts only.

The real issue with artifacts in sandbox iframes needs a different fix.
2025-10-11 19:32:33 +02:00
Mario Zechner
372be18657 Fix module script validation and extension context detection
1. Skip JavaScript validation for <script type="module"> tags
   - new Function() cannot validate ES module syntax (import/export)
   - Module scripts now execute without validation errors
   - Fixes issue where HTML artifacts with modules would fail to load

2. Improve __isExtensionContext detection logic
   - Changed from whitelist (chrome-extension://, moz-extension://)
   - To blacklist approach: negate http://, https://, file://
   - More robust - handles all extension protocols (about:srcdoc, etc.)
   - Fixes "offline mode" errors when using browser_script artifacts

Resolves artifacts not working in extension context after document.write()
2025-10-11 19:19:19 +02:00
Mario Zechner
98ea763d64 Intercept iframe navigation and open links externally
- Add navigation interceptor script that prevents all iframe navigation
- Intercept link clicks, form submissions, and window.location changes
- Send open-external-url messages to parent window
- Use chrome.tabs.create() in extension context, window.open() fallback
- Fix font-size workaround to use 'initial' instead of hardcoded 16px
- Document Chrome extension font-size bug with Stack Overflow reference

This prevents HTML artifacts from navigating away when users click links,
which would break the sandbox message system. All links now open in new
Chrome tabs instead.
2025-10-11 19:13:04 +02:00
Mario Zechner
2a67556e5d Fix font-size inheritance in HTML artifact iframes
Set explicit font-size: 16px on the <html> element in sandboxed iframes
to prevent browser default inheritance quirks that can cause unexpected
font sizes (e.g., 75% shown in devtools).

This establishes a consistent base font size while still allowing user
HTML content to override it on body or specific elements as needed.

Fixes the issue where HTML artifacts displayed with inconsistent font
sizes due to iframe inheritance behavior.
2025-10-11 18:46:55 +02:00
Mario Zechner
b5648eaabd Fix extension context detection in runtime providers
Replace window.sendRuntimeMessage existence check with URL-based detection.
The sendRuntimeMessage function exists in both extension and non-extension
contexts (e.g., downloaded HTML artifacts), causing incorrect behavior.

Changes:
- Add window.__isExtensionContext() helper to RuntimeMessageBridge that checks:
  - chrome-extension:// URLs (Chrome)
  - moz-extension:// URLs (Firefox)
  - about:srcdoc (sandbox iframes)
- Update all runtime providers to use __isExtensionContext() instead:
  - FileDownloadRuntimeProvider: Correctly falls back to browser download
  - ConsoleRuntimeProvider: Only sends messages in extension context
  - ArtifactsRuntimeProvider: Properly detects offline/read-only mode

This fixes the issue where downloaded HTML artifacts incorrectly try to
communicate with the extension when opened from disk.
2025-10-11 18:39:45 +02:00
Mario Zechner
46c1da9826 Add getAllFromIndex method for efficient sorted queries
- Add getAllFromIndex to StorageBackend interface for index-based queries
- Implement getAllFromIndex in IndexedDBStorageBackend using cursor API
- Update SessionsStore.getAllMetadata to use lastModified index
- Enables database-native sorting instead of fetching all keys and sorting in JS

Benefits:
- Much faster for large datasets (uses IndexedDB cursor with direction)
- Reduces memory usage (no need to load all keys first)
- Leverages existing indices for optimal performance
2025-10-11 16:21:28 +02:00
Mario Zechner
b129154cc8 Add ToolRenderResult interface for custom tool rendering
- Changed ToolRenderer return type from TemplateResult to ToolRenderResult
- ToolRenderResult = { content: TemplateResult, isCustom: boolean }
- isCustom: true = no card wrapper, false = wrap in card
- Updated all existing tool renderers to return new format
- Updated Messages.ts to handle custom rendering

This enables tools to render without default card chrome when needed.
2025-10-11 04:40:42 +02:00
Mario Zechner
3db2a6fe2c Expose agent, agentInterface, and artifactsPanel as public in ChatPanel
Make these properties public so they can be accessed externally for
test automation and other programmatic control.

Changes:
- Change agent, agentInterface, artifactsPanel from private to public
2025-10-10 11:40:07 +02:00
Mario Zechner
2756f2a974 Refactor JavaScript REPL tool description with consistent pattern
Clean up and restructure JavaScript REPL description following consistent pattern:
- Purpose section
- When to Use section
- Environment section
- Common Libraries section
- Important Notes section
- Example section

Removed buildJavaScriptReplDescription() function - no longer dynamically
injecting runtime provider docs into tool description (will move to system prompt).

Changes:
- Replace JAVASCRIPT_REPL_BASE_DESCRIPTION with JAVASCRIPT_REPL_DESCRIPTION
- Remove JAVASCRIPT_REPL_CHART_EXAMPLE and JAVASCRIPT_REPL_FOOTER
- Remove buildJavaScriptReplDescription() function
- Update javascript-repl tool to use static description
- Simpler, more scannable structure with clear hierarchy
2025-10-10 11:31:11 +02:00
Mario Zechner
3337953b2a Improve artifacts tool description to emphasize update command
Add clear decision tree and anti-patterns to prevent LLMs from using
get + rewrite when they should use update for targeted edits.

Changes:
- Add CRITICAL workflow section at top with decision tree
- Emphasize 'update' as PREFERRED for edits (token efficient)
- Mark 'rewrite' as LAST RESORT only
- Add ANTI-PATTERNS section showing wrong approaches
- Clarify use cases for each command
- Add examples emphasizing surgical modifications
2025-10-10 02:32:19 +02:00
Mario Zechner
ab9137542c Clarify when to use artifacts runtime functions vs artifacts tool
Make it clear that runtime functions are ONLY for programmatically generated
content (by code), not for content the LLM authors directly.

Changes:
- Add WHEN TO USE and DO NOT USE sections to runtime provider description
- Emphasize that createOrUpdateArtifact is for code-generated content
- Point users to artifacts tool for LLM-authored content like summaries
2025-10-10 02:10:36 +02:00