Skip to content

Commit

Permalink
feat: add onReceivedActionContent callback
Browse files Browse the repository at this point in the history
  • Loading branch information
tianhaowei committed Dec 8, 2024
1 parent cecbc55 commit 62536a9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/lib/runtime/message-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface ParserCallbacks {
onArtifactClose?: ArtifactCallback;
onActionOpen?: ActionCallback;
onActionClose?: ActionCallback;
onReceivedActionContent?: ActionCallback;
}

interface ElementFactoryProps {
Expand Down Expand Up @@ -99,6 +100,14 @@ export class StreamingMessageParser {

currentAction.content = content;


this._options.callbacks?.onReceivedActionContent?.({
artifactId: currentArtifact.id,
messageId,
actionId: String(state.actionId - 1),
action: currentAction as BoltAction,
});

this._options.callbacks?.onActionClose?.({
artifactId: currentArtifact.id,
messageId,
Expand All @@ -118,6 +127,18 @@ export class StreamingMessageParser {

i = closeIndex + ARTIFACT_ACTION_TAG_CLOSE.length;
} else {

const content = input.slice(i, input.length - ARTIFACT_ACTION_TAG_CLOSE.length);

this._options.callbacks?.onReceivedActionContent?.({
artifactId: currentArtifact.id,
messageId,
actionId: String(state.actionId - 1),
action: {
...currentAction,
content,
} as BoltAction,
});
break;
}
} else {
Expand Down

0 comments on commit 62536a9

Please sign in to comment.