asgard.message.delta
The asgard.message.delta event streams the content of a message. Each event carries a small piece of text, and the idx field is what keeps them in order.
What it is
- When it fires: as the AI generates content, sending it out in pieces
- What it is for: the live typewriter effect
- How often: a message can produce many delta events
The fields that matter
| Field | What it is |
|---|---|
| messageDelta.message.text | The increment: the new piece of text, which may be a character, a phrase or a sentence |
| messageDelta.message.idx | The position, counting up from 0 |
| messageDelta.message.template | Usually null; it has a value in the complete event |
A full example
The example below shows the typewriter effect for one complete message. Say the AI is about to answer with a sentence: it goes out as several delta events, each a character, a phrase or a sentence.
Delta 1 (idx: 0), the first piece
{
"eventType": "asgard.message.delta",
"requestId": "6939c5a6c590d90c401e3850a1ff44f3",
"namespace": "qa-7e301310-a594-4a7b-aa2a-xxxxxxxxxxxx",
"botProviderName": "bpapi-d97c512f-f8dc-46f6-82f0-xxxxxxxxxxxx",
"customChannelId": "ch-6xxxxxxxxxxxx",
"fact": {
"runInit": null,
"runDone": null,
"runError": null,
"messageStart": null,
"messageDelta": {
"message": {
"messageId": "1834828082242916352",
"replyToCustomMessageId": "",
"text": "目前", // <- only the new text
"payload": null,
"isDebug": false,
"idx": 0, // <- the first piece
"template": null // <- usually null
}
},
"messageComplete": null
}
}
Delta 2 (idx: 1), the second piece
{
"eventType": "asgard.message.delta",
"requestId": "6939c5a6c590d90c401e3850a1ff44f3",
"namespace": "qa-7e301310-a594-4a7b-aa2a-xxxxxxxxxxxx",
"botProviderName": "bpapi-d97c512f-f8dc-46f6-82f0-xxxxxxxxxxxx",
"customChannelId": "ch-6xxxxxxxxxxxx",
"fact": {
"runInit": null,
"runDone": null,
"runError": null,
"messageStart": null,
"messageDelta": {
"message": {
"messageId": "1834828082242916352",
"replyToCustomMessageId": "",
"text": "台", // <- only the new text
"payload": null,
"isDebug": false,
"idx": 1, // <- the second piece
"template": null
}
},
"messageComplete": null
}
}
Delta 3 (idx: 2), the third piece
{
"eventType": "asgard.message.delta",
"requestId": "6939c5a6c590d90c401e3850a1ff44f3",
"namespace": "qa-7e301310-a594-4a7b-aa2a-xxxxxxxxxxxx",
"botProviderName": "bpapi-d97c512f-f8dc-46f6-82f0-xxxxxxxxxxxx",
"customChannelId": "ch-6xxxxxxxxxxxx",
"fact": {
"runInit": null,
"runDone": null,
"runError": null,
"messageStart": null,
"messageDelta": {
"message": {
"messageId": "1834828082242916352",
"replyToCustomMessageId": "",
"text": "北", // <- only the new text
"payload": null,
"isDebug": false,
"idx": 2, // <- the third piece
"template": null
}
},
"messageComplete": null
}
}
Reading the example
What accumulates
As the delta events arrive, the front end accumulates the text like this:
- After delta 1:
"目前"(possibly a phrase) - After delta 2:
"目前台"(still accumulating) - After delta 3:
"目前台北"(still accumulating)
What to notice
- The
messageIdis the same: every delta belongs to the same message idxcounts up: which is what lets you process them in ordertextis an increment: each one carries the new piece, whether a character, a phrase or a sentence
Worth knowing
- Order matters: process them in
idxorder - Accumulate the text: join the text of every delta to produce the typewriter effect
- Watch the cost: the interface updates frequently, so keep an eye on performance