···11+---
22+"@clack/prompts": minor
33+---
44+55+Adds `stream` API which provides the same methods as `log`, but for iterable (even async) message streams. This is particularly useful for AI responses which are dynamically generated by LLMs.
66+77+```ts
88+import * as p from '@clack/prompts';
99+1010+await p.stream.step((async function* () {
1111+ yield* generateLLMResponse(question);
1212+})())
1313+```
···11+import { setTimeout } from 'node:timers/promises';
22+import * as p from '@clack/prompts';
33+import color from 'picocolors';
44+55+async function main() {
66+ console.clear();
77+88+ await setTimeout(1000);
99+1010+ p.intro(`${color.bgCyan(color.black(' create-app '))}`);
1111+1212+ await p.stream.step((async function* () {
1313+ for (const line of lorem) {
1414+ for (const word of line.split(' ')) {
1515+ yield word;
1616+ yield ' ';
1717+ await setTimeout(200);
1818+ }
1919+ yield '\n';
2020+ if (line !== lorem.at(-1)) {
2121+ await setTimeout(1000);
2222+ }
2323+ }
2424+ })())
2525+2626+ p.outro(`Problems? ${color.underline(color.cyan('https://example.com/issues'))}`);
2727+}
2828+2929+const lorem = [
3030+ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
3131+ 'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
3232+]
3333+3434+main().catch(console.error);
+16
packages/prompts/README.md
···188188log.message('Hello, World', { symbol: color.cyan('~') });
189189```
190190191191+192192+### Stream
193193+194194+When interacting with dynamic LLMs or other streaming message providers, use the `stream` APIs to log messages from an iterable, even an async one.
195195+196196+```js
197197+import { stream } from '@clack/prompts';
198198+199199+stream.info((function *() { yield 'Info!'; })());
200200+stream.success((function *() { yield 'Success!'; })());
201201+stream.step((function *() { yield 'Step!'; })());
202202+stream.warn((function *() { yield 'Warn!'; })());
203203+stream.error((function *() { yield 'Error!'; })());
204204+stream.message((function *() { yield 'Hello'; yield ", World" })(), { symbol: color.cyan('~') });
205205+```
206206+191207[clack-log-prompts](https://github.com/natemoo-re/clack/blob/main/.github/assets/clack-logs.png)