From e447392a6a9449b40897aeaf289d5ad50890c344 Mon Sep 17 00:00:00 2001 From: John Smith Date: Wed, 11 Dec 2024 21:10:57 +1030 Subject: [PATCH] chore: Update customAuthToken semantics (#293) --- sdk-react/README.md | 12 ++++++------ sdk-react/demo/TestPage.tsx | 4 ++-- sdk-react/src/hooks/useRun.ts | 11 +++++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/sdk-react/README.md b/sdk-react/README.md index f50e8b6b..51153eef 100644 --- a/sdk-react/README.md +++ b/sdk-react/README.md @@ -52,8 +52,8 @@ It can be used to interact with an existing run by specifying the `runId`: ```typescript const { messages, run, createMessage, start } = useRun({ clusterId: 'your-cluster-id', - apiSecret: 'your-api-secret', - authType: 'custom', // or 'cluster' + customAuthToken: 'your-custom-auth-token', + // apiSecret: 'your-api-secret', // Not recommended // pollInterval: 1000, // Optional: defaults to 1000ms }); @@ -70,8 +70,8 @@ It can be used to create a new run by specifying an `initialPrompt`: ```typescript const { messages, run, createMessage, start } = useRun({ clusterId: 'your-cluster-id', - apiSecret: 'your-api-secret', - authType: 'custom', // or 'cluster' + customAuthToken: 'your-custom-auth-token', + // apiSecret: 'your-api-secret', // Not recommended // pollInterval: 1000, // Optional: defaults to 1000ms }); @@ -99,8 +99,8 @@ You can handle errors by providing an `onError` callback: ```typescript const { messages, run, createMessage } = useRun({ clusterId: 'your-cluster-id', - apiSecret: 'your-api-secret', - authType: 'custom', // or 'cluster' + customAuthToken: 'your-custom-auth-token', + // apiSecret: 'your-api-secret', // Not recommended configId: 'your-config-id', onError: (error) => { console.error('Run error:', error); diff --git a/sdk-react/demo/TestPage.tsx b/sdk-react/demo/TestPage.tsx index 93d2bb6e..d8a55051 100644 --- a/sdk-react/demo/TestPage.tsx +++ b/sdk-react/demo/TestPage.tsx @@ -3,8 +3,8 @@ import { useRun } from '../src'; type TestPageProps = { baseUrl?: string; - apiSecret: string; - authType?: 'custom' | 'cluster'; + apiSecret?: string; + customAuthToken?: string; clusterId: string; configId: string; initialPrompt?: string; diff --git a/sdk-react/src/hooks/useRun.ts b/sdk-react/src/hooks/useRun.ts index f0968060..b5a676b3 100644 --- a/sdk-react/src/hooks/useRun.ts +++ b/sdk-react/src/hooks/useRun.ts @@ -6,8 +6,8 @@ import { ClientInferRequest, ClientInferResponseBody } from '@ts-rest/core'; type UseRunOptions = { clusterId: string; - apiSecret: string; - authType?: 'custom' | 'cluster'; + apiSecret?: string; + customAuthToken?: string; baseUrl?: string; pollInterval?: number; onError?: (error: Error) => void; @@ -32,9 +32,12 @@ interface UseRunReturn { } export function useRun(options: UseRunOptions): UseRunReturn { + const authType = options.customAuthToken ? 'custom' : 'cluster'; + const apiSecret = options.customAuthToken ?? options.apiSecret; + const [client] = useState(() => createApiClient({ - apiSecret: options.apiSecret, - authType: options.authType, + apiSecret, + authType, baseUrl: options.baseUrl }));