Skip to content

Commit 2ef75eb

Browse files
committed
chore: add related resources
1 parent 6a53c06 commit 2ef75eb

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

snippets/ai/src/providers/ai-provider.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,29 @@ export class AiProvider {
310310
});
311311

312312
text = '';
313-
314-
for await (const delta of result.textStream) {
315-
if (this.thinking.isRunning) {
316-
this.thinking.stop();
317-
process.stdout.write(chalk.bold.blue('Response: '));
318-
}
319-
text += delta;
320-
// Output each chunk as it arrives for 'response' mode
321-
if (expectedOutput === 'response') {
322-
process.stdout.write(delta);
313+
const sources: {
314+
title: string;
315+
url: string;
316+
}[] = [];
317+
318+
for await (const delta of result.fullStream) {
319+
if (
320+
delta.type === 'source' &&
321+
delta.sourceType === 'url' &&
322+
delta.title &&
323+
delta.url
324+
) {
325+
sources.push({ title: delta.title, url: delta.url });
326+
} else if (delta.type === 'text-delta') {
327+
if (this.thinking.isRunning && expectedOutput === 'response') {
328+
this.thinking.stop();
329+
process.stdout.write(chalk.bold.blue('Response: '));
330+
}
331+
text += delta.text;
332+
// Output each chunk as it arrives for 'response' mode
333+
if (expectedOutput === 'response') {
334+
process.stdout.write(delta.text);
335+
}
323336
}
324337
}
325338

@@ -328,8 +341,17 @@ export class AiProvider {
328341
content: text,
329342
});
330343

344+
if (sources.length > 0) {
345+
process.stdout.write(
346+
'\n' +
347+
chalk.italic.gray('Related Resources: ') +
348+
sources.map((source) => chalk.gray(`${source.url}`)).join(', '),
349+
);
350+
}
351+
331352
switch (expectedOutput) {
332353
case 'command':
354+
this.thinking.stop();
333355
this.setInput(
334356
this.formatResponse({ response: text, expectedOutput: 'command' }),
335357
);

0 commit comments

Comments
 (0)