mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 23:34:31 +00:00
refactor: split inbound and reload pipelines into staged modules
This commit is contained in:
40
src/agents/session-tool-result-state.ts
Normal file
40
src/agents/session-tool-result-state.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
export type PendingToolCall = { id: string; name?: string };
|
||||
|
||||
export type PendingToolCallState = {
|
||||
size: () => number;
|
||||
entries: () => IterableIterator<[string, string | undefined]>;
|
||||
getToolName: (id: string) => string | undefined;
|
||||
delete: (id: string) => void;
|
||||
clear: () => void;
|
||||
trackToolCalls: (calls: PendingToolCall[]) => void;
|
||||
getPendingIds: () => string[];
|
||||
shouldFlushForSanitizedDrop: () => boolean;
|
||||
shouldFlushBeforeNonToolResult: (nextRole: unknown, toolCallCount: number) => boolean;
|
||||
shouldFlushBeforeNewToolCalls: (toolCallCount: number) => boolean;
|
||||
};
|
||||
|
||||
export function createPendingToolCallState(): PendingToolCallState {
|
||||
const pending = new Map<string, string | undefined>();
|
||||
|
||||
return {
|
||||
size: () => pending.size,
|
||||
entries: () => pending.entries(),
|
||||
getToolName: (id: string) => pending.get(id),
|
||||
delete: (id: string) => {
|
||||
pending.delete(id);
|
||||
},
|
||||
clear: () => {
|
||||
pending.clear();
|
||||
},
|
||||
trackToolCalls: (calls: PendingToolCall[]) => {
|
||||
for (const call of calls) {
|
||||
pending.set(call.id, call.name);
|
||||
}
|
||||
},
|
||||
getPendingIds: () => Array.from(pending.keys()),
|
||||
shouldFlushForSanitizedDrop: () => pending.size > 0,
|
||||
shouldFlushBeforeNonToolResult: (nextRole: unknown, toolCallCount: number) =>
|
||||
pending.size > 0 && (toolCallCount === 0 || nextRole !== "assistant"),
|
||||
shouldFlushBeforeNewToolCalls: (toolCallCount: number) => pending.size > 0 && toolCallCount > 0,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user