From 051beb0cecc01ebefd13b5364fdbc02fbfc00bfa Mon Sep 17 00:00:00 2001 From: John Smith Date: Mon, 9 Dec 2024 19:19:58 +1030 Subject: [PATCH 1/5] feat: Move initialPrompt from useRun to start --- sdk-react/README.md | 36 +-- .../{src/test-page => demo}/TestPage.tsx | 6 +- sdk-react/{src/test-page => demo}/index.html | 0 sdk-react/{src/test-page => demo}/main.jsx | 0 sdk-react/src/contract.ts | 294 ++++++++++++------ sdk-react/src/createClient.ts | 28 +- sdk-react/src/hooks/useRun.ts | 116 ++++--- sdk-react/vite.config.ts | 5 +- 8 files changed, 293 insertions(+), 192 deletions(-) rename sdk-react/{src/test-page => demo}/TestPage.tsx (94%) rename sdk-react/{src/test-page => demo}/index.html (100%) rename sdk-react/{src/test-page => demo}/main.jsx (100%) diff --git a/sdk-react/README.md b/sdk-react/README.md index 857496a2..14869299 100644 --- a/sdk-react/README.md +++ b/sdk-react/README.md @@ -49,41 +49,34 @@ 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', - customerProvidedSecret: 'your-customer-provided-secret', - runId: 'your-run-id', + apiSecret: 'your-api-secret', + authType: 'customer', // or 'cluster' // pollInterval: 1000, // Optional: defaults to 1000ms }); + +start({ + runId: 'your-run-id', +}) ``` #### New Runs -It can be used to create a new run by specifying a `configId`: +It can be used to create a new run by specifying an `initialPrompt`: ```typescript const { messages, run, createMessage, start } = useRun({ clusterId: 'your-cluster-id', - customerProvidedSecret: 'your-customer-provided-secret', - initialMessage: 'Hello!', - configId: 'your-run-config-id', - // configInput: {} // Optional: if the config has an inputSchema + apiSecret: 'your-api-secret', + authType: 'customer', // or 'cluster' // pollInterval: 1000, // Optional: defaults to 1000ms }); -``` - -#### Start -Once the hook is initialized, you can start the run by calling the `start` function: - -```typescript -start() - -// Access messages and run state -console.log(messages); // Array of messages in the run -console.log(run); // Current run status and metadata +start({ + initialPrompt: 'Hello!', +}) ``` - #### Adding Messages You can add messages to the run by calling the `createMessage` function: @@ -103,7 +96,8 @@ You can handle errors by providing an `onError` callback: ```typescript const { messages, run, createMessage } = useRun({ clusterId: 'your-cluster-id', - customerProvidedSecret: 'your-secret', + apiSecret: 'your-api-secret', + authType: 'customer', // or 'cluster' configId: 'your-config-id', onError: (error) => { console.error('Run error:', error); @@ -124,7 +118,7 @@ const { messages } = useRun({ ## Local Development -There is development server included in the repository at `./test-page`. +There is development server included in the repository at `./demo`. 1. Start the development server: ```bash diff --git a/sdk-react/src/test-page/TestPage.tsx b/sdk-react/demo/TestPage.tsx similarity index 94% rename from sdk-react/src/test-page/TestPage.tsx rename to sdk-react/demo/TestPage.tsx index 723fae7f..1baacb79 100644 --- a/sdk-react/src/test-page/TestPage.tsx +++ b/sdk-react/demo/TestPage.tsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { useRun } from '../hooks/useRun'; +import { useRun } from '../src'; type TestPageProps = { baseUrl?: string; @@ -33,7 +33,9 @@ export function TestPage(props: TestPageProps) {