Skip to content

Commit 62536a9

Browse files
author
tianhaowei
committed
feat: add onReceivedActionContent callback
1 parent cecbc55 commit 62536a9

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

app/lib/runtime/message-parser.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface ParserCallbacks {
2929
onArtifactClose?: ArtifactCallback;
3030
onActionOpen?: ActionCallback;
3131
onActionClose?: ActionCallback;
32+
onReceivedActionContent?: ActionCallback;
3233
}
3334

3435
interface ElementFactoryProps {
@@ -99,6 +100,14 @@ export class StreamingMessageParser {
99100

100101
currentAction.content = content;
101102

103+
104+
this._options.callbacks?.onReceivedActionContent?.({
105+
artifactId: currentArtifact.id,
106+
messageId,
107+
actionId: String(state.actionId - 1),
108+
action: currentAction as BoltAction,
109+
});
110+
102111
this._options.callbacks?.onActionClose?.({
103112
artifactId: currentArtifact.id,
104113
messageId,
@@ -118,6 +127,18 @@ export class StreamingMessageParser {
118127

119128
i = closeIndex + ARTIFACT_ACTION_TAG_CLOSE.length;
120129
} else {
130+
131+
const content = input.slice(i, input.length - ARTIFACT_ACTION_TAG_CLOSE.length);
132+
133+
this._options.callbacks?.onReceivedActionContent?.({
134+
artifactId: currentArtifact.id,
135+
messageId,
136+
actionId: String(state.actionId - 1),
137+
action: {
138+
...currentAction,
139+
content,
140+
} as BoltAction,
141+
});
121142
break;
122143
}
123144
} else {

0 commit comments

Comments
 (0)