| 6 | } |
| 7 | |
| 8 | export class RedisTerminalStreamAdapter { |
| 9 | private readonly maxEntries: number; |
| 10 | |
| 11 | constructor( |
| 12 | private readonly redis: Redis, |
| 13 | options: TerminalStreamAdapterOptions = {}, |
| 14 | ) { |
| 15 | this.maxEntries = options.maxEntries ?? 5000; |
| 16 | } |
| 17 | |
| 18 | async append(chunk: TerminalChunkInput): Promise<void> { |
| 19 | const key = this.buildKey(chunk); |
| 20 | |
| 21 | const payload = JSON.stringify({ |
| 22 | chunkIndex: chunk.chunkIndex, |
| 23 | payload: chunk.payload, |
| 24 | recordedAt: chunk.recordedAt, |
| 25 | deltaMs: chunk.deltaMs, |
| 26 | origin: chunk.origin, |
| 27 | runnerKind: chunk.runnerKind, |
| 28 | }); |
| 29 | |
| 30 | await this.redis.xadd(key, 'MAXLEN', '~', this.maxEntries, '*', 'data', payload); |
| 31 | } |
| 32 | |
| 33 | private buildKey(chunk: TerminalChunkInput): string { |
| 34 | const safeNode = chunk.nodeRef.replace(/[^a-zA-Z0-9:_.-]/g, '_'); |
| 35 | return `terminal:${chunk.runId}:${safeNode}:${chunk.stream}`; |
| 36 | } |
| 37 | } |
nothing calls this directly
no outgoing calls
no test coverage detected