Archived
Broadcast submitted user prompts
This commit is contained in:
@@ -4,6 +4,7 @@ import { appendShellChunk, finalizeShellMessage, shellStartMessage } from "./she
|
|||||||
import type { SessionUiEvent } from "./sessionSocket";
|
import type { SessionUiEvent } from "./sessionSocket";
|
||||||
|
|
||||||
export function applyTranscriptEvent(messages: ChatLine[], event: SessionUiEvent): ChatLine[] | undefined {
|
export function applyTranscriptEvent(messages: ChatLine[], event: SessionUiEvent): ChatLine[] | undefined {
|
||||||
|
if (event.type === "message.append") return appendNormalized(messages, event.message);
|
||||||
if (event.type === "assistant.delta") return appendText(messages, "assistant", event.text);
|
if (event.type === "assistant.delta") return appendText(messages, "assistant", event.text);
|
||||||
if (event.type === "tool.start") return appendNormalized(messages, { role: "assistant", content: [{ type: "toolCall", name: event.toolName, arguments: event.args }] });
|
if (event.type === "tool.start") return appendNormalized(messages, { role: "assistant", content: [{ type: "toolCall", name: event.toolName, arguments: event.args }] });
|
||||||
if (event.type === "tool.end") return appendNormalized(messages, { role: "toolResult", toolName: event.toolName, content: event.content ?? [{ type: "text", text: event.text }], isError: event.isError });
|
if (event.type === "tool.end") return appendNormalized(messages, { role: "toolResult", toolName: event.toolName, content: event.content ?? [{ type: "text", text: event.text }], isError: event.isError });
|
||||||
|
|||||||
@@ -110,7 +110,6 @@ export class SessionController {
|
|||||||
if (isShellInput(text)) return this.runShell(text);
|
if (isShellInput(text)) return this.runShell(text);
|
||||||
const session = this.getState().selectedSession;
|
const session = this.getState().selectedSession;
|
||||||
if (!session || session.archived === true) return;
|
if (!session || session.archived === true) return;
|
||||||
this.setState({ messages: [...this.getState().messages, textMessage("user", text)] });
|
|
||||||
try {
|
try {
|
||||||
await api.prompt(session.id, text, streamingBehavior);
|
await api.prompt(session.id, text, streamingBehavior);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ export class GlobalSessionSocket {
|
|||||||
|
|
||||||
function isSessionUiEvent(event: unknown): event is SessionUiEvent {
|
function isSessionUiEvent(event: unknown): event is SessionUiEvent {
|
||||||
const type = eventType(event);
|
const type = eventType(event);
|
||||||
return ["assistant.delta", "tool.start", "tool.end", "shell.start", "shell.chunk", "shell.end", "agent.start", "agent.end", "message.end", "status.update", "activity.update", "command.output", "session.error", "session.name", "pi.event"].includes(type);
|
return ["message.append", "assistant.delta", "tool.start", "tool.end", "shell.start", "shell.chunk", "shell.end", "agent.start", "agent.end", "message.end", "status.update", "activity.update", "command.output", "session.error", "session.name", "pi.event"].includes(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isGlobalSessionEvent(event: unknown): event is GlobalSessionEvent {
|
function isGlobalSessionEvent(event: unknown): event is GlobalSessionEvent {
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ export class PiSessionService {
|
|||||||
this.maybeGenerateSessionName(session, text);
|
this.maybeGenerateSessionName(session, text);
|
||||||
const behavior = session.isStreaming || session.isCompacting ? streamingBehavior ?? "followUp" : undefined;
|
const behavior = session.isStreaming || session.isCompacting ? streamingBehavior ?? "followUp" : undefined;
|
||||||
this.publishActivity(session, session.isCompacting ? "message queued during compaction" : behavior === "steer" ? "steering queued" : behavior === "followUp" ? "message queued" : "prompt accepted", "active");
|
this.publishActivity(session, session.isCompacting ? "message queued during compaction" : behavior === "steer" ? "steering queued" : behavior === "followUp" ? "message queued" : "prompt accepted", "active");
|
||||||
|
this.events.publish(sessionId, { type: "message.append", message: userTextMessage(text) });
|
||||||
void session.prompt(text, behavior === undefined ? undefined : { streamingBehavior: behavior }).catch((error: unknown) => {
|
void session.prompt(text, behavior === undefined ? undefined : { streamingBehavior: behavior }).catch((error: unknown) => {
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
this.publishActivity(session, "error", "error", message);
|
this.publishActivity(session, "error", "error", message);
|
||||||
@@ -403,6 +404,10 @@ export class PiSessionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function userTextMessage(text: string): { role: "user"; content: string } {
|
||||||
|
return { role: "user", content: text };
|
||||||
|
}
|
||||||
|
|
||||||
function historyMessages(session: AgentSession): unknown[] {
|
function historyMessages(session: AgentSession): unknown[] {
|
||||||
const messages: unknown[] = [];
|
const messages: unknown[] = [];
|
||||||
for (const entry of session.sessionManager.getBranch()) {
|
for (const entry of session.sessionManager.getBranch()) {
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ export type CommandResult =
|
|||||||
| { type: "unsupported"; message: string };
|
| { type: "unsupported"; message: string };
|
||||||
|
|
||||||
export type SessionUiEvent =
|
export type SessionUiEvent =
|
||||||
|
| { type: "message.append"; message: unknown }
|
||||||
| { type: "assistant.delta"; text: string }
|
| { type: "assistant.delta"; text: string }
|
||||||
| { type: "tool.start"; toolName: string; toolCallId: string; summary: string; args?: unknown }
|
| { type: "tool.start"; toolName: string; toolCallId: string; summary: string; args?: unknown }
|
||||||
| { type: "tool.end"; toolName: string; toolCallId: string; text: string; isError: boolean; content?: unknown }
|
| { type: "tool.end"; toolName: string; toolCallId: string; text: string; isError: boolean; content?: unknown }
|
||||||
|
|||||||
Reference in New Issue
Block a user