fix(agent): simplify state API and update consumers fixes #2633

This commit is contained in:
Mario Zechner
2026-03-30 12:43:34 +02:00
parent 5e3852fc9c
commit cbe1a8b732
24 changed files with 829 additions and 1198 deletions

View File

@@ -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
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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,