Skip to content

Commit a3aa722

Browse files
committed
feat: add BlockChunk type to chat.{start,append,stop}Stream methods
1 parent 9fa2921 commit a3aa722

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

packages/types/src/chunk.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { URLSourceElement } from './block-kit/block-elements';
2+
import type { AnyBlock } from './block-kit/blocks';
23
/**
34
* Base interface for streaming message chunks.
45
* https://docs.slack.dev/messaging/sending-and-scheduling-messages#text-streaming
@@ -39,7 +40,17 @@ export interface TaskUpdateChunk extends Chunk {
3940
sources?: URLSourceElement[];
4041
}
4142

43+
/**
44+
* Used for passing an array of blocks within a streaming message.
45+
* https://docs.slack.dev/changelog/2026/04/16/block-kit-new-blocks/
46+
*/
47+
export interface BlocksChunk extends Chunk {
48+
type: 'blocks';
49+
/** @description An array of {@link AnyBlock} objects. Maximum of 50 blocks. */
50+
blocks: AnyBlock[];
51+
}
52+
4253
/**
4354
* Union type of all possible chunk types
4455
*/
45-
export type AnyChunk = MarkdownTextChunk | PlanUpdateChunk | TaskUpdateChunk;
56+
export type AnyChunk = MarkdownTextChunk | PlanUpdateChunk | TaskUpdateChunk | BlocksChunk;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { expectAssignable, expectError } from 'tsd';
2+
import type { AnyChunk, BlocksChunk } from '../src/index';
3+
4+
// BlocksChunk
5+
// -- sad path
6+
expectError<BlocksChunk>({});
7+
expectError<BlocksChunk>({ type: 'blocks' });
8+
expectError<BlocksChunk>({ blocks: [] });
9+
10+
// -- happy path
11+
expectAssignable<BlocksChunk>({ type: 'blocks', blocks: [] });
12+
expectAssignable<BlocksChunk>({
13+
type: 'blocks',
14+
blocks: [
15+
{
16+
type: 'section',
17+
text: { type: 'plain_text', text: "Sandra's plan outline" },
18+
},
19+
],
20+
});
21+
expectAssignable<BlocksChunk>({
22+
type: 'blocks',
23+
blocks: [
24+
{ type: 'divider' },
25+
{ type: 'header', text: { type: 'plain_text', text: 'Hello' } },
26+
],
27+
});
28+
// Unknown block types accepted via generic Block interface
29+
expectAssignable<BlocksChunk>({
30+
type: 'blocks',
31+
blocks: [{ type: 'future_block_type' }],
32+
});
33+
34+
// BlocksChunk is assignable to AnyChunk
35+
expectAssignable<AnyChunk>({ type: 'blocks', blocks: [] });

0 commit comments

Comments
 (0)