Skip to content

Commit 915f23f

Browse files
committed
Add a test GET call to the agent endpoint
1 parent 19b9831 commit 915f23f

File tree

9 files changed

+212
-6
lines changed

9 files changed

+212
-6
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ yarn-error.log*
3131

3232
# turbo
3333
.turbo
34+
35+
tsconfig.tsbuildinfo

apps/example-client/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"scripts": {
66
"build": "next build",
77
"clean": "rm -rf .turbo && rm -rf .next && rm -rf node_modules",
8+
"compile": "tsc -b",
89
"dev": "next dev --port 3000",
910
"lint": "TIMING=1 eslint \"src/**/*.ts*\"",
1011
"start": "next start"

apps/example-client/pages/index.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { InteractionView } from '@proficient/react-sdk';
22

3+
const proficientApiKey = 'pk_USjnILHKBxXeJtiJ5WtAquoRb4IXjQTz1ScvRWTV6XduKxQ4at0YYxRpY28Ce0Qug6fkhm5R';
4+
const agentId = 'ag_T2SW501k1RGk8ZUv2Kaz11Kh';
5+
const userExternalId = 'user123';
6+
37
export default function ExampleClient() {
48
return (
59
<div>
610
<h1>Example Client</h1>
7-
<InteractionView apiKey="abc" userId="user123" />
11+
<InteractionView apiKey={proficientApiKey} agentId={agentId} userExternalId={userExternalId} />
812
</div>
913
);
1014
}

package-lock.json

+153
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
],
99
"scripts": {
1010
"build": "turbo run build",
11+
"compile:example-client": "turbo run compile --filter=example-client",
1112
"dev": "turbo run dev --parallel",
1213
"dev:example-client": "turbo run dev --filter=example-client",
1314
"lint": "turbo run lint",

packages/react-sdk/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"dependencies": {
2525
"@proficient/util": "^0.2.2",
26+
"axios": "^1.3.2",
2627
"lorem-ipsum": "^2.0.8",
2728
"react-infinite-scroll-component": "^6.1.0",
2829
"react-textarea-autosize": "^8.4.0",

packages/react-sdk/src/components/InteractionView/InteractionView.tsx

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import axios from 'axios';
12
import * as React from 'react';
23
import InfiniteScroll from 'react-infinite-scroll-component';
34
import TextareaAutosize from 'react-textarea-autosize';
@@ -9,7 +10,9 @@ import type { InteractionViewProps } from './types';
910

1011
export function InteractionView({
1112
apiKey,
12-
userId,
13+
agentId,
14+
userExternalId,
15+
userHmac,
1316
inputPlaceholder = 'Type something...',
1417
contentMaxLength = 500,
1518
}: InteractionViewProps) {
@@ -18,6 +21,40 @@ export function InteractionView({
1821
const [messageMap, setMessageMap] = React.useState<Record<string, Message>>({});
1922
const [hasMore, setHasMore] = React.useState(true);
2023

24+
const axiosInstance = axios.create({
25+
baseURL: 'http://localhost:8080/client', // TODO: Update
26+
headers: {
27+
'Content-Type': 'application/json',
28+
'X-PROFICIENT-API-KEY': apiKey,
29+
'X-PROFICIENT-USER-EXTERNAL-ID': userExternalId,
30+
'X-PROFICIENT-USER-HMAC': userHmac,
31+
},
32+
});
33+
34+
React.useEffect(() => {
35+
(async () => {
36+
console.log(`Fetching Agent: ${agentId}`);
37+
// TODO: Should import from api package
38+
interface Agent {
39+
[key: string]: any;
40+
41+
id: string;
42+
object: 'agent';
43+
active: boolean;
44+
name: string | null;
45+
description: string;
46+
created_at: number;
47+
updated_at: number;
48+
}
49+
try {
50+
const { data: agent } = await axiosInstance.get<Agent>(`/agents/${agentId}`);
51+
console.log('SUCCESS:', agent);
52+
} catch (err: any) {
53+
console.log('ERROR:', err?.response?.data);
54+
}
55+
})();
56+
}, [axiosInstance, agentId]);
57+
2158
const loadNextBatch = React.useCallback(async () => {
2259
const { messages: receivedMessages, hasMore: hasMoreNext } = await db.getMessages(20, oldestMessageId.current);
2360
setMessageMap((prev) => {
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export interface InteractionViewProps {
22
apiKey: string;
3-
userId: string;
3+
agentId: string;
4+
userExternalId: string;
5+
userHmac?: string;
46
inputPlaceholder?: string;
57
contentMaxLength?: number;
68
}

turbo.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
"dependsOn": ["^build"],
66
"outputs": ["dist/**", ".next/**"]
77
},
8-
"lint": {
9-
"outputs": []
8+
"compile": {
9+
"dependsOn": ["^build"]
1010
},
1111
"dev": {
12-
"cache": false
12+
"cache": false,
13+
"persistent": true,
14+
"dependsOn": ["^build"]
15+
},
16+
"lint": {
17+
"outputs": []
1318
}
1419
}
1520
}

0 commit comments

Comments
 (0)