fix(agent): simplify state API and update consumers fixes #2633
This commit is contained in:
@@ -202,10 +202,10 @@ await agent.prompt({ role: 'user-with-attachments', content: 'Check this', attac
|
||||
|
||||
// Control
|
||||
agent.abort();
|
||||
agent.setModel(newModel);
|
||||
agent.setThinkingLevel('medium');
|
||||
agent.setTools([...]);
|
||||
agent.queueMessage(customMessage);
|
||||
agent.state.model = newModel;
|
||||
agent.state.thinkingLevel = 'medium';
|
||||
agent.state.tools = [...];
|
||||
agent.followUp(customMessage);
|
||||
```
|
||||
|
||||
## Message Types
|
||||
@@ -312,7 +312,7 @@ replTool.runtimeProvidersFactory = () => [
|
||||
new ArtifactsRuntimeProvider(artifactsPanel, agent, true), // read-write
|
||||
];
|
||||
|
||||
agent.setTools([replTool]);
|
||||
agent.state.tools = [replTool];
|
||||
```
|
||||
|
||||
### Extract Document
|
||||
@@ -325,7 +325,7 @@ import { createExtractDocumentTool } from '@mariozechner/pi-web-ui';
|
||||
const extractTool = createExtractDocumentTool();
|
||||
extractTool.corsProxyUrl = 'https://corsproxy.io/?';
|
||||
|
||||
agent.setTools([extractTool]);
|
||||
agent.state.tools = [extractTool];
|
||||
```
|
||||
|
||||
### Artifacts Tool
|
||||
@@ -337,7 +337,7 @@ const artifactsPanel = new ArtifactsPanel();
|
||||
artifactsPanel.agent = agent;
|
||||
|
||||
// The tool is available as artifactsPanel.tool
|
||||
agent.setTools([artifactsPanel.tool]);
|
||||
agent.state.tools = [artifactsPanel.tool];
|
||||
```
|
||||
|
||||
### Custom Tool Renderers
|
||||
@@ -551,7 +551,7 @@ const success = await ApiKeyPromptDialog.prompt('anthropic');
|
||||
import { ModelSelector } from '@mariozechner/pi-web-ui';
|
||||
|
||||
ModelSelector.open(currentModel, (selectedModel) => {
|
||||
agent.setModel(selectedModel);
|
||||
agent.state.model = selectedModel;
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ export class ChatPanel extends LitElement {
|
||||
const additionalTools =
|
||||
config?.toolsFactory?.(agent, this.agentInterface, this.artifactsPanel, runtimeProvidersFactory) || [];
|
||||
const tools = [this.artifactsPanel.tool, ...additionalTools];
|
||||
this.agent.setTools(tools);
|
||||
this.agent.state.tools = tools;
|
||||
|
||||
// Reconstruct artifacts from existing messages
|
||||
// Temporarily disable the onArtifactsChange callback to prevent auto-opening on load
|
||||
|
||||
@@ -376,13 +376,15 @@ export class AgentInterface extends LitElement {
|
||||
if (this.onModelSelect) {
|
||||
this.onModelSelect();
|
||||
} else {
|
||||
ModelSelector.open(state.model, (model) => session.setModel(model));
|
||||
ModelSelector.open(state.model, (model) => {
|
||||
session.state.model = model;
|
||||
});
|
||||
}
|
||||
}}
|
||||
.onThinkingChange=${
|
||||
this.enableThinkingSelector
|
||||
? (level: "off" | "minimal" | "low" | "medium" | "high") => {
|
||||
session.setThinkingLevel(level);
|
||||
session.state.thinkingLevel = level;
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { renderMessage } from "./message-renderer-registry.js";
|
||||
export class MessageList extends LitElement {
|
||||
@property({ type: Array }) messages: AgentMessage[] = [];
|
||||
@property({ type: Array }) tools: AgentTool[] = [];
|
||||
@property({ type: Object }) pendingToolCalls?: Set<string>;
|
||||
@property({ type: Object }) pendingToolCalls?: ReadonlySet<string>;
|
||||
@property({ type: Boolean }) isStreaming: boolean = false;
|
||||
@property({ attribute: false }) onCostClick?: () => void;
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ export class UserMessage extends LitElement {
|
||||
export class AssistantMessage extends LitElement {
|
||||
@property({ type: Object }) message!: AssistantMessageType;
|
||||
@property({ type: Array }) tools?: AgentTool<any>[];
|
||||
@property({ type: Object }) pendingToolCalls?: Set<string>;
|
||||
@property({ type: Object }) pendingToolCalls?: ReadonlySet<string>;
|
||||
@property({ type: Boolean }) hideToolCalls = false;
|
||||
@property({ type: Object }) toolResultsById?: Map<string, ToolResultMessageType>;
|
||||
@property({ type: Boolean }) isStreaming: boolean = false;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { property, state } from "lit/decorators.js";
|
||||
export class StreamingMessageContainer extends LitElement {
|
||||
@property({ type: Array }) tools: AgentTool[] = [];
|
||||
@property({ type: Boolean }) isStreaming = false;
|
||||
@property({ type: Object }) pendingToolCalls?: Set<string>;
|
||||
@property({ type: Object }) pendingToolCalls?: ReadonlySet<string>;
|
||||
@property({ type: Object }) toolResultsById?: Map<string, ToolResultMessage>;
|
||||
@property({ attribute: false }) onCostClick?: () => void;
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { AgentMessage } from "@mariozechner/pi-agent-core";
|
||||
import {
|
||||
ARTIFACTS_RUNTIME_PROVIDER_DESCRIPTION_RO,
|
||||
ARTIFACTS_RUNTIME_PROVIDER_DESCRIPTION_RW,
|
||||
@@ -13,7 +14,7 @@ interface ArtifactsPanelLike {
|
||||
}
|
||||
|
||||
interface AgentLike {
|
||||
appendMessage(message: any): void;
|
||||
state: { messages: AgentMessage[] };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,7 +172,7 @@ export class ArtifactsRuntimeProvider implements SandboxRuntimeProvider {
|
||||
filename,
|
||||
content,
|
||||
});
|
||||
this.agent?.appendMessage({
|
||||
this.agent?.state.messages.push({
|
||||
role: "artifact",
|
||||
action,
|
||||
filename,
|
||||
@@ -192,7 +193,7 @@ export class ArtifactsRuntimeProvider implements SandboxRuntimeProvider {
|
||||
command: "delete",
|
||||
filename,
|
||||
});
|
||||
this.agent?.appendMessage({
|
||||
this.agent?.state.messages.push({
|
||||
role: "artifact",
|
||||
action: "delete",
|
||||
filename,
|
||||
|
||||
Reference in New Issue
Block a user