mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 18:00:11 +08:00
- Add assets/releases/ver1-4-0.md covering deltas since v1.4.0-beta (reasoning_effort normalization, tool-schema fallback, restart-safe turn runtime, frontend placeholder hardening, CLI chat REPL config). - Bump deeptutor/__version__ to 1.4.0. - Update README Releases section: v1.4.0 at top, install opt-in note updated for stable. - Fix pre-existing pre-commit failures so the v1.4.0 cut runs clean: bandit B324 (mark _sha1 as non-security), mypy no-redef in document.py / line_doc.py, mypy arg-type/assignment in snapshot/adapters.py, mypy assignment + arg-type in services/memory/settings.py, mypy func-returns-value on set.add idiom in deeptutor_cli/init_wizard.py. - Apply ruff format / prettier sweep across the repo. - Remove stale workspace + i18n env example + playwright captures already cleaned locally; ignore .playwright-cli/ going forward. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
77 lines
2.1 KiB
TypeScript
77 lines
2.1 KiB
TypeScript
import type { StreamEvent } from "./unified-ws";
|
|
|
|
type MessageWithEvents = {
|
|
events?: StreamEvent[];
|
|
};
|
|
|
|
function asRecord(value: unknown): Record<string, unknown> | null {
|
|
return value && typeof value === "object" && !Array.isArray(value)
|
|
? (value as Record<string, unknown>)
|
|
: null;
|
|
}
|
|
|
|
function eventBelongsToTurn(
|
|
event: StreamEvent,
|
|
turnId?: string | null,
|
|
): boolean {
|
|
if (!turnId) return true;
|
|
return !event.turn_id || event.turn_id === turnId;
|
|
}
|
|
|
|
function askUserPayloadFrom(
|
|
event: StreamEvent,
|
|
): Record<string, unknown> | null {
|
|
const meta = asRecord(event.metadata);
|
|
const toolMetadata = asRecord(meta?.tool_metadata);
|
|
return asRecord(toolMetadata?.ask_user) ?? asRecord(meta?.ask_user);
|
|
}
|
|
|
|
function askUserToolCallId(event: StreamEvent): string {
|
|
const meta = asRecord(event.metadata);
|
|
return typeof meta?.tool_call_id === "string" ? meta.tool_call_id.trim() : "";
|
|
}
|
|
|
|
/**
|
|
* Returns true when a stream contains an ask_user card that has not yet
|
|
* emitted the matching ask_user_resolved progress event.
|
|
*/
|
|
export function hasPendingAskUser(
|
|
events: StreamEvent[] | undefined,
|
|
turnId?: string | null,
|
|
): boolean {
|
|
const pending = new Set<string>();
|
|
let anonymousCount = 0;
|
|
|
|
for (const event of events ?? []) {
|
|
if (!eventBelongsToTurn(event, turnId)) continue;
|
|
const meta = asRecord(event.metadata);
|
|
|
|
if (event.type === "tool_result" && askUserPayloadFrom(event)) {
|
|
const toolCallId = askUserToolCallId(event);
|
|
pending.add(toolCallId ? `id:${toolCallId}` : `anon:${anonymousCount++}`);
|
|
continue;
|
|
}
|
|
|
|
if (event.type === "progress" && meta?.ask_user_resolved === true) {
|
|
const resolvedId =
|
|
typeof meta.ask_user_tool_call_id === "string"
|
|
? meta.ask_user_tool_call_id.trim()
|
|
: "";
|
|
if (resolvedId) {
|
|
pending.delete(`id:${resolvedId}`);
|
|
} else {
|
|
pending.clear();
|
|
}
|
|
}
|
|
}
|
|
|
|
return pending.size > 0;
|
|
}
|
|
|
|
export function hasPendingAskUserInMessages(
|
|
messages: MessageWithEvents[],
|
|
turnId?: string | null,
|
|
): boolean {
|
|
return messages.some((message) => hasPendingAskUser(message.events, turnId));
|
|
}
|