refactor(agents): split tools + PI subscribe
This commit is contained in:
83
src/agents/pi-embedded-subscribe.handlers.types.ts
Normal file
83
src/agents/pi-embedded-subscribe.handlers.types.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import type { AgentEvent, AgentMessage } from "@mariozechner/pi-agent-core";
|
||||
|
||||
import type { ReasoningLevel } from "../auto-reply/thinking.js";
|
||||
import type { EmbeddedBlockChunker } from "./pi-embedded-block-chunker.js";
|
||||
import type { MessagingToolSend } from "./pi-embedded-messaging.js";
|
||||
import type {
|
||||
BlockReplyChunking,
|
||||
SubscribeEmbeddedPiSessionParams,
|
||||
} from "./pi-embedded-subscribe.types.js";
|
||||
|
||||
export type EmbeddedSubscribeLogger = {
|
||||
debug: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
};
|
||||
|
||||
export type EmbeddedPiSubscribeState = {
|
||||
assistantTexts: string[];
|
||||
toolMetas: Array<{ toolName?: string; meta?: string }>;
|
||||
toolMetaById: Map<string, string | undefined>;
|
||||
toolSummaryById: Set<string>;
|
||||
|
||||
blockReplyBreak: "text_end" | "message_end";
|
||||
reasoningMode: ReasoningLevel;
|
||||
includeReasoning: boolean;
|
||||
shouldEmitPartialReplies: boolean;
|
||||
streamReasoning: boolean;
|
||||
|
||||
deltaBuffer: string;
|
||||
blockBuffer: string;
|
||||
blockState: { thinking: boolean; final: boolean };
|
||||
lastStreamedAssistant?: string;
|
||||
lastStreamedReasoning?: string;
|
||||
lastBlockReplyText?: string;
|
||||
assistantTextBaseline: number;
|
||||
suppressBlockChunks: boolean;
|
||||
lastReasoningSent?: string;
|
||||
|
||||
compactionInFlight: boolean;
|
||||
pendingCompactionRetry: number;
|
||||
compactionRetryResolve?: () => void;
|
||||
compactionRetryPromise: Promise<void> | null;
|
||||
|
||||
messagingToolSentTexts: string[];
|
||||
messagingToolSentTextsNormalized: string[];
|
||||
messagingToolSentTargets: MessagingToolSend[];
|
||||
pendingMessagingTexts: Map<string, string>;
|
||||
pendingMessagingTargets: Map<string, MessagingToolSend>;
|
||||
};
|
||||
|
||||
export type EmbeddedPiSubscribeContext = {
|
||||
params: SubscribeEmbeddedPiSessionParams;
|
||||
state: EmbeddedPiSubscribeState;
|
||||
log: EmbeddedSubscribeLogger;
|
||||
blockChunking?: BlockReplyChunking;
|
||||
blockChunker: EmbeddedBlockChunker | null;
|
||||
|
||||
shouldEmitToolResult: () => boolean;
|
||||
emitToolSummary: (toolName?: string, meta?: string) => void;
|
||||
stripBlockTags: (
|
||||
text: string,
|
||||
state: { thinking: boolean; final: boolean },
|
||||
) => string;
|
||||
emitBlockChunk: (text: string) => void;
|
||||
flushBlockReplyBuffer: () => void;
|
||||
emitReasoningStream: (text: string) => void;
|
||||
resetAssistantMessageState: (nextAssistantTextBaseline: number) => void;
|
||||
resetForCompactionRetry: () => void;
|
||||
finalizeAssistantTexts: (args: {
|
||||
text: string;
|
||||
addedDuringMessage: boolean;
|
||||
chunkerHasBuffered: boolean;
|
||||
}) => void;
|
||||
trimMessagingToolSent: () => void;
|
||||
ensureCompactionPromise: () => void;
|
||||
noteCompactionRetry: () => void;
|
||||
resolveCompactionRetry: () => void;
|
||||
maybeResolveCompactionWait: () => void;
|
||||
};
|
||||
|
||||
export type EmbeddedPiSubscribeEvent =
|
||||
| AgentEvent
|
||||
| { type: string; [k: string]: unknown }
|
||||
| { type: "message_start"; message: AgentMessage };
|
||||
Reference in New Issue
Block a user