fix(consult): 申报时段计算改为服务端预跑并走同请求缓存(BUG-957)
窗口计算挂在 agent context 缓存上,模型开口前预跑并注入 packet;工具再调用命中同请求缓存,成功次数仍为 1。
This commit is contained in:
@@ -61,7 +61,9 @@ type EventOptions = {
|
||||
state?: ConsultationRuntimeState;
|
||||
};
|
||||
|
||||
function activity(value: unknown): ConsultationAgentPublicEvent | null {
|
||||
export function consultationPublicActivityEvent(
|
||||
value: unknown,
|
||||
): Extract<ConsultationAgentPublicEvent, { type: "activity" }> | null {
|
||||
if (!value || typeof value !== "object") return null;
|
||||
const data = value as { phase?: unknown; label?: unknown };
|
||||
const phase = publicActivityPhaseSchema.safeParse(data.phase);
|
||||
@@ -224,7 +226,7 @@ function mapChunk(
|
||||
): ConsultationAgentPublicEvent[] {
|
||||
const payload = chunk.payload ?? {};
|
||||
if (chunk.type === "data-jyotish-activity") {
|
||||
const event = activity(chunk.data);
|
||||
const event = consultationPublicActivityEvent(chunk.data);
|
||||
return event ? [event] : [];
|
||||
}
|
||||
if (chunk.type === "tool-call") {
|
||||
@@ -311,9 +313,16 @@ export type ThinkFinding = Readonly<{
|
||||
text?: string;
|
||||
}>;
|
||||
|
||||
type AgentStreamSource = ChunkStream | (() => ChunkStream | Promise<ChunkStream>);
|
||||
|
||||
async function resolveAgentStream(stream: AgentStreamSource): Promise<ChunkStream> {
|
||||
return typeof stream === "function" ? await stream() : stream;
|
||||
}
|
||||
|
||||
type StreamAgentResponseOptions = EventOptions & {
|
||||
state: ConsultationRuntimeState;
|
||||
stream: ChunkStream;
|
||||
stream: AgentStreamSource;
|
||||
warmup?: (send: (event: ConsultationAgentPublicEvent) => void) => Promise<void>;
|
||||
transformText?: (text: string) => string;
|
||||
requireTool: boolean;
|
||||
retry?: () => Promise<ChunkStream>;
|
||||
@@ -744,7 +753,11 @@ export function streamAgentResponse(options: StreamAgentResponseOptions) {
|
||||
flushThinkingPlan(controller);
|
||||
try {
|
||||
let deliveredDegraded = false;
|
||||
await consumeAttempt(controller, options.stream, {
|
||||
if (options.warmup) {
|
||||
await options.warmup((event) => send(controller, event));
|
||||
flushThinkingPlan(controller);
|
||||
}
|
||||
await consumeAttempt(controller, await resolveAgentStream(options.stream), {
|
||||
drainSpoken: Boolean(options.composeAnswer),
|
||||
});
|
||||
if (!contractReady(options) && options.retry) {
|
||||
|
||||
Reference in New Issue
Block a user