Skip to content

Commit ccee173

Browse files
Merge pull request #85 from upstash/improve-agents-researcher
DX-1601: Further Improvements
2 parents df081c2 + 275c9e1 commit ccee173

File tree

5 files changed

+647
-506
lines changed

5 files changed

+647
-506
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Suspense } from 'react';
2+
import { AgentUI } from '../components/agent-ui';
3+
4+
export default async function Page({
5+
params,
6+
}: {
7+
params: Promise<{ session: string }>
8+
}) {
9+
const { session } = await params
10+
return (
11+
<Suspense fallback={<div>Loading...</div>}>
12+
<AgentUI session={session} />
13+
</Suspense>
14+
);
15+
}

examples/agents-researcher/app/components/agent-info.tsx

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1-
import { useState } from 'react';
2-
import cx from '../utils/cx';
3-
import CodeBlock from './code-block';
4-
import { IconCaretDownFilled } from '../icons/caret-dropdown';
5-
import { AgentName, StepRecord } from '../types';
6-
import Markdown from 'markdown-to-jsx';
1+
import { useState } from "react";
2+
import cx from "../utils/cx";
3+
import CodeBlock from "./code-block";
4+
import { IconCaretDownFilled } from "../icons/caret-dropdown";
5+
import { AgentName, StepRecord } from "../types";
6+
import Markdown from "markdown-to-jsx";
77

88
const CollapsibleText = ({
99
title,
1010
text,
11-
maxLength = 300
11+
maxLength = 300,
1212
}: {
1313
title: string;
1414
text: string;
1515
maxLength?: number;
1616
}) => {
1717
const [isExpanded, setIsExpanded] = useState(false);
1818

19+
// Ensure text starts on a new line by adding a newline if it doesn't already have one
20+
const formattedText = text && !text.startsWith('\n') ? `\n${text}` : text;
21+
1922
if (!text || text.length <= maxLength)
2023
return (
2124
<div className="border-gray-300 border-2 p-3 rounded-xl text-md font-mono break-words">
22-
{' '}
25+
{" "}
2326
<label className="text-base font-semibold text-purple-500">
2427
{title}
2528
</label>
@@ -32,16 +35,16 @@ const CollapsibleText = ({
3235
),
3336
ul: ({ children }) => (
3437
<ol className="list-disc list-inside">{children}</ol>
35-
)
36-
}
38+
),
39+
},
3740
}}
3841
>
39-
{text}
42+
{formattedText}
4043
</Markdown>
4144
</div>
4245
);
4346

44-
const displayText = isExpanded ? text : text.slice(0, maxLength) + '...';
47+
const displayText = isExpanded ? formattedText : formattedText.slice(0, maxLength) + "...";
4548

4649
return (
4750
<div className="border-gray-300 border-2 p-3 rounded-xl text-md font-mono break-words">
@@ -55,8 +58,8 @@ const CollapsibleText = ({
5558
),
5659
ul: ({ children }) => (
5760
<ol className="list-disc list-inside">{children}</ol>
58-
)
59-
}
61+
),
62+
},
6063
}}
6164
>
6265
{displayText}
@@ -65,7 +68,7 @@ const CollapsibleText = ({
6568
onClick={() => setIsExpanded(!isExpanded)}
6669
className="text-purple-500 hover:text-purple-600 font-medium text-sm font-mono mt-2"
6770
>
68-
{isExpanded ? 'Read Less' : 'Read More'}
71+
{isExpanded ? "Read Less" : "Read More"}
6972
</button>
7073
</div>
7174
);
@@ -74,14 +77,16 @@ const CollapsibleText = ({
7477
export const AgentInfo = ({
7578
name,
7679
code,
77-
state
80+
state,
7881
}: {
7982
name: AgentName;
8083
code: string;
81-
state: false | 'loading' | StepRecord[];
84+
state: false | "loading" | StepRecord[];
8285
}) => {
8386
const [displayCode, setDisplayCode] = useState(false);
84-
const [displayOutput, setDisplayOutput] = useState(false);
87+
const [displayOutput, setDisplayOutput] = useState(
88+
name === "Cross Reference"
89+
);
8590
return (
8691
<div className="flex flex-col gap-4">
8792
<div className="flex flex-col gap-2 w-full">
@@ -91,8 +96,8 @@ export const AgentInfo = ({
9196
>
9297
<IconCaretDownFilled
9398
className={cx(
94-
'transform transition-transform',
95-
displayCode && 'rotate-180'
99+
"transform transition-transform",
100+
displayCode && "rotate-180"
96101
)}
97102
/>
98103
<label className="">{name} Agent Code</label>
@@ -104,31 +109,31 @@ export const AgentInfo = ({
104109
<div className="flex flex-col gap-4 w-full">
105110
<button
106111
id={
107-
name === 'Cross Reference'
108-
? 'cross-reference-output'
109-
: 'intermediate-output'
112+
name === "Cross Reference"
113+
? "cross-reference-output"
114+
: "intermediate-output"
110115
}
111116
className={cx(
112-
'flex gap-1 w-full px-2 py-2 rounded-xl items-center',
113-
state && state !== 'loading'
114-
? 'bg-purple-500/10 text-purple-500'
115-
: 'bg-gray-100 text-gray-400'
117+
"flex gap-1 w-full px-2 py-2 rounded-xl items-center",
118+
state && state !== "loading"
119+
? "bg-purple-500/10 text-purple-500"
120+
: "bg-gray-100 text-gray-400"
116121
)}
117122
onClick={() => {
118-
if (state && state !== 'loading') setDisplayOutput(!displayOutput);
123+
if (state && state !== "loading") setDisplayOutput(!displayOutput);
119124
}}
120125
>
121126
<IconCaretDownFilled
122127
className={cx(
123-
'transform transition-transform',
124-
displayOutput && 'rotate-180'
128+
"transform transition-transform",
129+
displayOutput && "rotate-180"
125130
)}
126131
/>
127-
<label className={''}>{name} Agent Output</label>
132+
<label className={""}>{name} Agent Output</label>
128133
</button>
129134
{displayOutput &&
130135
state &&
131-
state !== 'loading' &&
136+
state !== "loading" &&
132137
state.map((s, i) => (
133138
<div key={i}>
134139
<CollapsibleText title={s.stepName} text={s.stepOut} />

0 commit comments

Comments
 (0)