fix: Async Model End Events, Await Tool Call and Dispatch Handling (#10552)

This commit is contained in:
Danny Avila 2025-11-17 16:37:40 -05:00 committed by GitHub
parent 49c57b27fd
commit bdc47dbe47
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -39,9 +39,9 @@ class ModelEndHandler {
* @param {ModelEndData | undefined} data * @param {ModelEndData | undefined} data
* @param {Record<string, unknown> | undefined} metadata * @param {Record<string, unknown> | undefined} metadata
* @param {StandardGraph} graph * @param {StandardGraph} graph
* @returns * @returns {Promise<void>}
*/ */
handle(event, data, metadata, graph) { async handle(event, data, metadata, graph) {
if (!graph || !metadata) { if (!graph || !metadata) {
console.warn(`Graph or metadata not found in ${event} event`); console.warn(`Graph or metadata not found in ${event} event`);
return; return;
@ -79,7 +79,7 @@ class ModelEndHandler {
} }
} }
if (isGoogle || streamingDisabled || hasUnprocessedToolCalls) { if (isGoogle || streamingDisabled || hasUnprocessedToolCalls) {
handleToolCalls(toolCalls, metadata, graph); await handleToolCalls(toolCalls, metadata, graph);
} }
const usage = data?.output?.usage_metadata; const usage = data?.output?.usage_metadata;
@ -101,7 +101,7 @@ class ModelEndHandler {
const stepKey = graph.getStepKey(metadata); const stepKey = graph.getStepKey(metadata);
const message_id = getMessageId(stepKey, graph) ?? ''; const message_id = getMessageId(stepKey, graph) ?? '';
if (message_id) { if (message_id) {
graph.dispatchRunStep(stepKey, { await graph.dispatchRunStep(stepKey, {
type: StepTypes.MESSAGE_CREATION, type: StepTypes.MESSAGE_CREATION,
message_creation: { message_creation: {
message_id, message_id,
@ -111,7 +111,7 @@ class ModelEndHandler {
const stepId = graph.getStepIdByKey(stepKey); const stepId = graph.getStepIdByKey(stepKey);
const content = data.output.content; const content = data.output.content;
if (typeof content === 'string') { if (typeof content === 'string') {
graph.dispatchMessageDelta(stepId, { await graph.dispatchMessageDelta(stepId, {
content: [ content: [
{ {
type: 'text', type: 'text',
@ -120,7 +120,7 @@ class ModelEndHandler {
], ],
}); });
} else if (content.every((c) => c.type?.startsWith('text'))) { } else if (content.every((c) => c.type?.startsWith('text'))) {
graph.dispatchMessageDelta(stepId, { await graph.dispatchMessageDelta(stepId, {
content, content,
}); });
} }