Skip to content

Commit

Permalink
chore: Update customAuthToken semantics (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjcsmith authored Dec 11, 2024
1 parent 642c3bc commit e447392
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
12 changes: 6 additions & 6 deletions sdk-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

Expand All @@ -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
});

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions sdk-react/demo/TestPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions sdk-react/src/hooks/useRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
}));

Expand Down

0 comments on commit e447392

Please sign in to comment.