diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 69dd6180..c96e1b36 100644 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: 8b6cd71c-ea04-44da-af45-e43968b5928d management: - docChecksum: 459a4007b7391a38a6e9c7249c84c3bf + docChecksum: bcccd1abd05f6654a822386f2eefbd8a docVersion: 1.0.0 - speakeasyVersion: 1.658.2 + speakeasyVersion: 1.659.0 generationVersion: 2.755.9 releaseVersion: 0.1.17 - configChecksum: 1aa68a2fafd67f1deb74a05868fefaac + configChecksum: 981848e5179cd35dc81cd362029ee736 repoURL: https://github.com/OpenRouterTeam/typescript-sdk.git installationURL: https://github.com/OpenRouterTeam/typescript-sdk published: true @@ -26,13 +26,13 @@ features: globalSecurityCallbacks: 0.1.0 globalSecurityFlattening: 0.1.0 globalServerURLs: 2.83.0 + globals: 2.82.2 groups: 2.81.3 methodArguments: 0.1.2 methodSecurity: 2.82.6 nameOverrides: 2.81.2 nullables: 0.1.1 openEnums: 0.1.1 - reactQueryHooks: 0.2.3 responseFormat: 0.2.3 retries: 2.83.0 sdkHooks: 0.3.0 @@ -46,7 +46,6 @@ generatedFiles: - .devcontainer/setup.sh - .gitattributes - FUNCTIONS.md - - REACT_QUERY.md - RUNTIMES.md - USAGE.md - docs/lib/utils/retryconfig.md @@ -773,33 +772,6 @@ generatedFiles: - src/models/videourl.ts - src/models/websearchpreviewtooluserlocation.ts - src/models/websearchstatus.ts - - src/react-query/_context.tsx - - src/react-query/_types.ts - - src/react-query/analyticsGetUserActivity.ts - - src/react-query/apiKeysCreate.ts - - src/react-query/apiKeysDelete.ts - - src/react-query/apiKeysGet.ts - - src/react-query/apiKeysGetCurrentKeyMetadata.ts - - src/react-query/apiKeysList.ts - - src/react-query/apiKeysUpdate.ts - - src/react-query/betaResponsesSend.ts - - src/react-query/chatSend.ts - - src/react-query/completionsGenerate.ts - - src/react-query/creditsCreateCoinbaseCharge.ts - - src/react-query/creditsGetCredits.ts - - src/react-query/embeddingsGenerate.ts - - src/react-query/embeddingsListModels.ts - - src/react-query/endpointsList.ts - - src/react-query/endpointsListZdrEndpoints.ts - - src/react-query/generationsGetGeneration.ts - - src/react-query/index.ts - - src/react-query/modelsCount.ts - - src/react-query/modelsList.ts - - src/react-query/modelsListForUser.ts - - src/react-query/oAuthCreateAuthCode.ts - - src/react-query/oAuthExchangeAuthCodeForAPIKey.ts - - src/react-query/parametersGetParameters.ts - - src/react-query/providersList.ts - src/sdk/analytics.ts - src/sdk/apikeys.ts - src/sdk/beta.ts diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index 7afc9d9b..9222e3e3 100644 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -65,7 +65,7 @@ typescript: defaultErrorName: OpenRouterDefaultError enableCustomCodeRegions: true enableMCPServer: false - enableReactQuery: true + enableReactQuery: false enumFormat: union envVarPrefix: OPENROUTER exportZodModelNamespace: false diff --git a/.speakeasy/out.openapi.yaml b/.speakeasy/out.openapi.yaml index d218d946..d99089ff 100644 --- a/.speakeasy/out.openapi.yaml +++ b/.speakeasy/out.openapi.yaml @@ -5650,7 +5650,7 @@ components: - model - choices additionalProperties: false - parameters: {} + parameters: {AppIdentifier: {name: HTTP-Referer, in: header, schema: {type: string}, description: "The app identifier should be your app's URL and is used as the primary identifier for rankings.\nThis is used to track API usage per application.\n"}, AppDisplayName: {name: X-Title, in: header, schema: {type: string}, description: "The app display name allows you to customize how your app appears in OpenRouter's dashboard.\n"}} securitySchemes: apiKey: type: http @@ -8409,3 +8409,7 @@ x-retry-strategy: initialDelay: 500 maxDelay: 60000 maxAttempts: 3 +x-speakeasy-globals: + parameters: + - $ref: "#/components/parameters/AppIdentifier" + - $ref: "#/components/parameters/AppDisplayName" diff --git a/.speakeasy/overlays/add-headers.overlay.yaml b/.speakeasy/overlays/add-headers.overlay.yaml new file mode 100644 index 00000000..60a22323 --- /dev/null +++ b/.speakeasy/overlays/add-headers.overlay.yaml @@ -0,0 +1,35 @@ +overlay: 1.0.0 +x-speakeasy-jsonpath: rfc9535 +info: + title: Add HTTP-Referer and X-Title as global parameters + version: 0.0.0 +actions: + # Add global parameters for app identification + - target: $ + description: Add x-speakeasy-globals for HTTP-Referer and X-Title headers + update: + x-speakeasy-globals: + parameters: + - $ref: "#/components/parameters/AppIdentifier" + - $ref: "#/components/parameters/AppDisplayName" + + # Add component parameters + - target: $.components + description: Add parameters for app identification headers + update: + parameters: + AppIdentifier: + name: HTTP-Referer + in: header + schema: + type: string + description: | + The app identifier should be your app's URL and is used as the primary identifier for rankings. + This is used to track API usage per application. + AppDisplayName: + name: X-Title + in: header + schema: + type: string + description: | + The app display name allows you to customize how your app appears in OpenRouter's dashboard. diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index df1aedb5..43f09e2f 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -1,21 +1,20 @@ -speakeasyVersion: 1.658.2 +speakeasyVersion: 1.659.0 sources: OpenRouter API: sourceNamespace: open-router-chat-completions-api - sourceRevisionDigest: sha256:f1b59b9b643de5e20d6e3299a8274783d8c0854615876f5d7f6f081814842695 - sourceBlobDigest: sha256:ee1f2422281b3ed5b38951c74636ad192c9bb160f216069c1f7931ccc4e52553 + sourceRevisionDigest: sha256:ffe0e925561a55a1b403667fe33bb3158e05892ef1e66f56211544c9a890b301 + sourceBlobDigest: sha256:18aa7b22686c2f559af1062fea408a9f80146231027ed1fd62b68df38c71f65d tags: - latest - - feat-update-sdk-models-and-spec - 1.0.0 targets: openrouter: source: OpenRouter API sourceNamespace: open-router-chat-completions-api - sourceRevisionDigest: sha256:f1b59b9b643de5e20d6e3299a8274783d8c0854615876f5d7f6f081814842695 - sourceBlobDigest: sha256:ee1f2422281b3ed5b38951c74636ad192c9bb160f216069c1f7931ccc4e52553 + sourceRevisionDigest: sha256:ffe0e925561a55a1b403667fe33bb3158e05892ef1e66f56211544c9a890b301 + sourceBlobDigest: sha256:18aa7b22686c2f559af1062fea408a9f80146231027ed1fd62b68df38c71f65d codeSamplesNamespace: open-router-chat-completions-api-typescript-code-samples - codeSamplesRevisionDigest: sha256:84b8958b8bfb3e2b25461ca49c1cf10e07bd3821337dec96333acd9a2829c701 + codeSamplesRevisionDigest: sha256:4206cfd1ad4a613178d55c5c1b1da20bcfd21bbaf1b63b8c80beec4bf16dd4b7 workflow: workflowVersion: 1.0.0 speakeasyVersion: latest @@ -26,6 +25,7 @@ workflow: overlays: - location: .speakeasy/overlays/open-enums.overlay.yaml - location: .speakeasy/overlays/remove-rss-responses.overlay.yaml + - location: .speakeasy/overlays/add-headers.overlay.yaml output: .speakeasy/out.openapi.yaml registry: location: registry.speakeasyapi.dev/openrouter/sdk/open-router-chat-completions-api diff --git a/.speakeasy/workflow.yaml b/.speakeasy/workflow.yaml index f042c503..0d55eb8a 100644 --- a/.speakeasy/workflow.yaml +++ b/.speakeasy/workflow.yaml @@ -7,6 +7,7 @@ sources: overlays: - location: .speakeasy/overlays/open-enums.overlay.yaml - location: .speakeasy/overlays/remove-rss-responses.overlay.yaml + - location: .speakeasy/overlays/add-headers.overlay.yaml output: .speakeasy/out.openapi.yaml registry: location: registry.speakeasyapi.dev/openrouter/sdk/open-router-chat-completions-api diff --git a/REACT_QUERY.md b/REACT_QUERY.md deleted file mode 100644 index 4dc5b539..00000000 --- a/REACT_QUERY.md +++ /dev/null @@ -1,296 +0,0 @@ -# React hooks - -This SDK provides React hooks and utilies for making queries and mutations that -can take the pain out of building front-end applications for the web or React -Native. - -They are built as a thin wrapper around [TanStack Query for React v5][rq], a -powerful, asynchronous state management library. A good understanding of that -library will be very helpful while using them. In addition to hooks, there are -several helper functions that can be used for cache management and data fetching -during server-rendering and in React Server Components. - -## Getting started - -To get started using React hooks, you will need to inject TanStack query and an -SDK instance into your application. Typically, this will be done high up in -your React app at the root or layout component. For example: - -```tsx -import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; -import { OpenRouterCore } from "@openrouter/sdk"; -import { OpenRouterProvider } from "@openrouter/sdk/react-query"; - -const queryClient = new QueryClient(); -const openRouter = new OpenRouterCore({ - apiKey: process.env["OPENROUTER_API_KEY"] ?? "", -}); - -// Retries are handled by the underlying SDK. -queryClient.setQueryDefaults(["@openrouter/sdk"], { retry: false }); -queryClient.setMutationDefaults(["@openrouter/sdk"], { retry: false }); - -export function App() { - return ( - - - {/* Your app logic starts here */} - - - ); -} -``` - -## Queries - -Query hooks are the basic building block for fetching data. In addition to -request data, they take the same options as the [`useQuery` hook][use-query] -from TanStack Query. - -[use-query]: https://tanstack.com/query/v5/docs/framework/react/reference/useQuery - -```tsx -import { useAnalyticsGetUserActivity } from "@openrouter/sdk/react-query/analyticsGetUserActivity.js"; - -export function Example() { - const { data, error, status } = useAnalyticsGetUserActivity(); - - // Render the UI here... -} -``` - -### Query timeouts and retries - -Since the underlying SDK handles request timeouts and retries, there are a few -more options provided by the query hooks to control these behaviors. - -```tsx -import { useState } from "react"; -import { useAnalyticsGetUserActivity } from "@openrouter/sdk/react-query/analyticsGetUserActivity.js"; - -export function ExampleWithOptions() { - const [enabled, setEnabled] = useState(true); - const { data, error, status } = useAnalyticsGetUserActivity( - { - // TanStack Query options: - enabled, - staleTime: 60 * 1000, // 1 minute - gcTime: 5 * 60 * 1000, // 5 minutes - - // Request options for the underlying API call: - timeoutMs: 1000, - retryCodes: ["5XX"], - retries: { - strategy: "backoff", - backoff: { - initialInterval: 500, - maxInterval: 10 * 1000, // 10 seconds - exponent: 1.5, - maxElapsedTime: 60 * 1000, // 1 minute - }, - }, - } - ); - - // Render the UI here... -} -``` - - -## Mutations - -Operations that can have side-effects in this SDK are exposed as mutation hooks. -These can be integrated into HTML forms to submit data to the API. They also -take the same options as the [`useMutation` hook][use-mutation] from TanStack -Query. - -[use-mutation]: https://tanstack.com/query/v5/docs/framework/react/reference/useMutation - -```tsx -import { useBetaResponsesSendMutation } from "@openrouter/sdk/react-query/betaResponsesSend.js"; - -export function Example() { - const { mutate, status } = useBetaResponsesSendMutation(); - - return ( -
{ - e.preventDefault(); - - // Read form data here... - - mutate({}); - }} - > - {/* Form fields go here... */} - -
- ); -} -``` - -### Mutation timeouts and retries - -Since the underlying SDK handles request timeouts and retries, there are a few -more options provided by the mutation hooks to control these behaviors. - -```tsx -import { useBetaResponsesSendMutation } from "@openrouter/sdk/react-query/betaResponsesSend.js"; - -export function ExampleWithOptions() { - const { mutate, status } = useBetaResponsesSendMutation({ - // TanStack Query options: - networkMode: "online", - gcTime: 5 * 60 * 1000, // 5 minutes - - // Request options for the underlying API call: - timeoutMs: 1000, - retryCodes: ["5XX"], - retries: { - strategy: "backoff", - backoff: { - initialInterval: 500, - maxInterval: 10 * 1000, // 10 seconds - exponent: 1.5, - maxElapsedTime: 60 * 1000, // 1 minute - }, - }, - }); - - // Render the UI here... -} -``` - - -## Cache invalidation - -In many instances, triggering a mutation hook requires invalidating specific -query data currently residing in the TanStack Query's cache. Alongside every -query hook there are two functions that help invalidate cached data: - -```tsx -import { useQueryClient } from "@tanstack/react-query"; -import { invalidateAnalyticsGetUserActivity, invalidateAllAnalyticsGetUserActivity } from "@openrouter/sdk/react-query/analyticsGetUserActivity.js"; -// Replace this with a real mutation -import { useExampleMutation } from "@openrouter/sdk/react-query/example.js"; - -export function Example() { - const { queryClient } = useQueryClient(); - const { mutate, status } = useExampleMutation(); - - return ( -
{ - e.preventDefault(); - - const formData = new FormData(e.target); - - mutate(formData, { - onSuccess: () => { - // Invalidate a single cache entry: - invalidateAnalyticsGetUserActivity(queryClient, /* ... arguments ... */); - // OR, invalidate all cache entries for the query targets: - invalidateAllAnalyticsGetUserActivity(queryClient); - }, - }); - }} - > - {/* Form fields go here... */} - - -
- ); -} -``` - - -## Integration with React Suspense - -TanStack Query predates React Suspense and out of the box it does a great job at -exposing the lifecycle of asynchronous tasks. However, if you are already using -Suspense in your app, the default hooks will not trigger suspense boundaries. -This is why the library and, by extension, this SDK also provide equivalent -hooks that integrate neatly with React Suspense. - -```tsx -import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; -import { ErrorBoundary } from "react-error-boundary"; - -import { OpenRouterCore } from "@openrouter/sdk"; -import { OpenRouterProvider } from "@openrouter/sdk/react-query"; -import { useAnalyticsGetUserActivitySuspense } from "@openrouter/sdk/react-query/analyticsGetUserActivity.js"; - -const queryClient = new QueryClient(); -const openRouter = new OpenRouterCore({ - apiKey: process.env["OPENROUTER_API_KEY"] ?? "", -}); - -export function App() { - return ( - - - - {({ reset }) => ( - ( -
- There was an error!{' '} - -
{error.message}
-
- )} - onReset={reset} - > - Loading...}> - - -
- )} -
-
-
- ); -} - -function Example() { - const { data } = useAnalyticsGetUserActivitySuspense(); - - // Render the UI here... -} -``` - - -## Server-rendering and React Server Components - -Query hooks are also side-loaded with prefetch helper functions. These functions -can be used to fetch data from the API during server-rendering and in React -Server Components so that it can be available immediately on page load to any -components that use the corresponding hooks: -```tsx -import { - dehydrate, - HydrationBoundary, - QueryClient, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "@openrouter/sdk"; -import { prefetchAnalyticsGetUserActivity } from "@openrouter/sdk/react-query/analyticsGetUserActivity.js"; - -export default async function Page() { - const queryClient = new QueryClient(); - const openRouter = new OpenRouterCore({ - apiKey: process.env["OPENROUTER_API_KEY"] ?? "", - }); - - await prefetchAnalyticsGetUserActivity(openRouter); - - return ( - // HydrationBoundary is a Client Component, so hydration will happen there. - - {/* Client components under this point will also have data on page load. */} - - ); -} -``` - - -[rq]: https://tanstack.com/query/v5/docs/framework/react/overview \ No newline at end of file diff --git a/README.md b/README.md index a1693a8e..bc324a7d 100644 --- a/README.md +++ b/README.md @@ -19,32 +19,24 @@ The SDK can be installed with either [npm](https://www.npmjs.com/), [pnpm](https ```bash npm add @openrouter/sdk -# Install optional peer dependencies if you plan to use React hooks -npm add @tanstack/react-query react react-dom ``` ### PNPM ```bash pnpm add @openrouter/sdk -# Install optional peer dependencies if you plan to use React hooks -pnpm add @tanstack/react-query react react-dom ``` ### Bun ```bash bun add @openrouter/sdk -# Install optional peer dependencies if you plan to use React hooks -bun add @tanstack/react-query react react-dom ``` ### Yarn ```bash yarn add @openrouter/sdk -# Install optional peer dependencies if you plan to use React hooks -yarn add @tanstack/react-query react react-dom ``` > [!NOTE] diff --git a/docs/sdks/analytics/README.md b/docs/sdks/analytics/README.md index 065239ee..f4a6853d 100644 --- a/docs/sdks/analytics/README.md +++ b/docs/sdks/analytics/README.md @@ -59,34 +59,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Query hooks for fetching data. - useAnalyticsGetUserActivity, - useAnalyticsGetUserActivitySuspense, - - // Utility for prefetching data during server-side rendering and in React - // Server Components that will be immediately available to client components - // using the hooks. - prefetchAnalyticsGetUserActivity, - - // Utilities to invalidate the query cache for this query in response to - // mutations and other user actions. - invalidateAnalyticsGetUserActivity, - invalidateAllAnalyticsGetUserActivity, -} from "@openrouter/sdk/react-query/analyticsGetUserActivity.js"; -``` - ### Parameters | Parameter | Type | Required | Description | diff --git a/docs/sdks/apikeys/README.md b/docs/sdks/apikeys/README.md index fa48e2cf..745a01c2 100644 --- a/docs/sdks/apikeys/README.md +++ b/docs/sdks/apikeys/README.md @@ -64,34 +64,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Query hooks for fetching data. - useApiKeysList, - useApiKeysListSuspense, - - // Utility for prefetching data during server-side rendering and in React - // Server Components that will be immediately available to client components - // using the hooks. - prefetchApiKeysList, - - // Utilities to invalidate the query cache for this query in response to - // mutations and other user actions. - invalidateApiKeysList, - invalidateAllApiKeysList, -} from "@openrouter/sdk/react-query/apiKeysList.js"; -``` - ### Parameters | Parameter | Type | Required | Description | @@ -168,23 +140,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Mutation hook for triggering the API call. - useApiKeysCreateMutation -} from "@openrouter/sdk/react-query/apiKeysCreate.js"; -``` - ### Parameters | Parameter | Type | Required | Description | @@ -264,23 +219,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Mutation hook for triggering the API call. - useApiKeysUpdateMutation -} from "@openrouter/sdk/react-query/apiKeysUpdate.js"; -``` - ### Parameters | Parameter | Type | Required | Description | @@ -359,23 +297,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Mutation hook for triggering the API call. - useApiKeysDeleteMutation -} from "@openrouter/sdk/react-query/apiKeysDelete.js"; -``` - ### Parameters | Parameter | Type | Required | Description | @@ -453,34 +374,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Query hooks for fetching data. - useApiKeysGet, - useApiKeysGetSuspense, - - // Utility for prefetching data during server-side rendering and in React - // Server Components that will be immediately available to client components - // using the hooks. - prefetchApiKeysGet, - - // Utilities to invalidate the query cache for this query in response to - // mutations and other user actions. - invalidateApiKeysGet, - invalidateAllApiKeysGet, -} from "@openrouter/sdk/react-query/apiKeysGet.js"; -``` - ### Parameters | Parameter | Type | Required | Description | @@ -554,33 +447,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Query hooks for fetching data. - useApiKeysGetCurrentKeyMetadata, - useApiKeysGetCurrentKeyMetadataSuspense, - - // Utility for prefetching data during server-side rendering and in React - // Server Components that will be immediately available to client components - // using the hooks. - prefetchApiKeysGetCurrentKeyMetadata, - - // Utility to invalidate the query cache for this query in response to - // mutations and other user actions. - invalidateAllApiKeysGetCurrentKeyMetadata, -} from "@openrouter/sdk/react-query/apiKeysGetCurrentKeyMetadata.js"; -``` - ### Parameters | Parameter | Type | Required | Description | diff --git a/docs/sdks/chat/README.md b/docs/sdks/chat/README.md index 7a14c18d..6d0f3c07 100644 --- a/docs/sdks/chat/README.md +++ b/docs/sdks/chat/README.md @@ -61,23 +61,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Mutation hook for triggering the API call. - useChatSendMutation -} from "@openrouter/sdk/react-query/chatSend.js"; -``` - ### Parameters | Parameter | Type | Required | Description | diff --git a/docs/sdks/completions/README.md b/docs/sdks/completions/README.md index c90ef4a8..780bee6f 100644 --- a/docs/sdks/completions/README.md +++ b/docs/sdks/completions/README.md @@ -61,23 +61,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Mutation hook for triggering the API call. - useCompletionsGenerateMutation -} from "@openrouter/sdk/react-query/completionsGenerate.js"; -``` - ### Parameters | Parameter | Type | Required | Description | diff --git a/docs/sdks/credits/README.md b/docs/sdks/credits/README.md index 58e80057..f3d5e730 100644 --- a/docs/sdks/credits/README.md +++ b/docs/sdks/credits/README.md @@ -60,33 +60,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Query hooks for fetching data. - useCreditsGetCredits, - useCreditsGetCreditsSuspense, - - // Utility for prefetching data during server-side rendering and in React - // Server Components that will be immediately available to client components - // using the hooks. - prefetchCreditsGetCredits, - - // Utility to invalidate the query cache for this query in response to - // mutations and other user actions. - invalidateAllCreditsGetCredits, -} from "@openrouter/sdk/react-query/creditsGetCredits.js"; -``` - ### Parameters | Parameter | Type | Required | Description | @@ -166,23 +139,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Mutation hook for triggering the API call. - useCreditsCreateCoinbaseChargeMutation -} from "@openrouter/sdk/react-query/creditsCreateCoinbaseCharge.js"; -``` - ### Parameters | Parameter | Type | Required | Description | diff --git a/docs/sdks/embeddings/README.md b/docs/sdks/embeddings/README.md index a0476504..9b549440 100644 --- a/docs/sdks/embeddings/README.md +++ b/docs/sdks/embeddings/README.md @@ -66,23 +66,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Mutation hook for triggering the API call. - useEmbeddingsGenerateMutation -} from "@openrouter/sdk/react-query/embeddingsGenerate.js"; -``` - ### Parameters | Parameter | Type | Required | Description | @@ -162,33 +145,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Query hooks for fetching data. - useEmbeddingsListModels, - useEmbeddingsListModelsSuspense, - - // Utility for prefetching data during server-side rendering and in React - // Server Components that will be immediately available to client components - // using the hooks. - prefetchEmbeddingsListModels, - - // Utility to invalidate the query cache for this query in response to - // mutations and other user actions. - invalidateAllEmbeddingsListModels, -} from "@openrouter/sdk/react-query/embeddingsListModels.js"; -``` - ### Parameters | Parameter | Type | Required | Description | diff --git a/docs/sdks/endpoints/README.md b/docs/sdks/endpoints/README.md index 3c674b9a..d8eb3244 100644 --- a/docs/sdks/endpoints/README.md +++ b/docs/sdks/endpoints/README.md @@ -66,34 +66,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Query hooks for fetching data. - useEndpointsList, - useEndpointsListSuspense, - - // Utility for prefetching data during server-side rendering and in React - // Server Components that will be immediately available to client components - // using the hooks. - prefetchEndpointsList, - - // Utilities to invalidate the query cache for this query in response to - // mutations and other user actions. - invalidateEndpointsList, - invalidateAllEndpointsList, -} from "@openrouter/sdk/react-query/endpointsList.js"; -``` - ### Parameters | Parameter | Type | Required | Description | @@ -165,33 +137,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Query hooks for fetching data. - useEndpointsListZdrEndpoints, - useEndpointsListZdrEndpointsSuspense, - - // Utility for prefetching data during server-side rendering and in React - // Server Components that will be immediately available to client components - // using the hooks. - prefetchEndpointsListZdrEndpoints, - - // Utility to invalidate the query cache for this query in response to - // mutations and other user actions. - invalidateAllEndpointsListZdrEndpoints, -} from "@openrouter/sdk/react-query/endpointsListZdrEndpoints.js"; -``` - ### Parameters | Parameter | Type | Required | Description | diff --git a/docs/sdks/generations/README.md b/docs/sdks/generations/README.md index c6e998f6..fb741c6b 100644 --- a/docs/sdks/generations/README.md +++ b/docs/sdks/generations/README.md @@ -63,34 +63,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Query hooks for fetching data. - useGenerationsGetGeneration, - useGenerationsGetGenerationSuspense, - - // Utility for prefetching data during server-side rendering and in React - // Server Components that will be immediately available to client components - // using the hooks. - prefetchGenerationsGetGeneration, - - // Utilities to invalidate the query cache for this query in response to - // mutations and other user actions. - invalidateGenerationsGetGeneration, - invalidateAllGenerationsGetGeneration, -} from "@openrouter/sdk/react-query/generationsGetGeneration.js"; -``` - ### Parameters | Parameter | Type | Required | Description | diff --git a/docs/sdks/models/README.md b/docs/sdks/models/README.md index 39fe2982..dbd5dcc6 100644 --- a/docs/sdks/models/README.md +++ b/docs/sdks/models/README.md @@ -61,33 +61,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Query hooks for fetching data. - useModelsCount, - useModelsCountSuspense, - - // Utility for prefetching data during server-side rendering and in React - // Server Components that will be immediately available to client components - // using the hooks. - prefetchModelsCount, - - // Utility to invalidate the query cache for this query in response to - // mutations and other user actions. - invalidateAllModelsCount, -} from "@openrouter/sdk/react-query/modelsCount.js"; -``` - ### Parameters | Parameter | Type | Required | Description | @@ -157,34 +130,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Query hooks for fetching data. - useModelsList, - useModelsListSuspense, - - // Utility for prefetching data during server-side rendering and in React - // Server Components that will be immediately available to client components - // using the hooks. - prefetchModelsList, - - // Utilities to invalidate the query cache for this query in response to - // mutations and other user actions. - invalidateModelsList, - invalidateAllModelsList, -} from "@openrouter/sdk/react-query/modelsList.js"; -``` - ### Parameters | Parameter | Type | Required | Description | @@ -256,33 +201,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Query hooks for fetching data. - useModelsListForUser, - useModelsListForUserSuspense, - - // Utility for prefetching data during server-side rendering and in React - // Server Components that will be immediately available to client components - // using the hooks. - prefetchModelsListForUser, - - // Utility to invalidate the query cache for this query in response to - // mutations and other user actions. - invalidateAllModelsListForUser, -} from "@openrouter/sdk/react-query/modelsListForUser.js"; -``` - ### Parameters | Parameter | Type | Required | Description | diff --git a/docs/sdks/oauth/README.md b/docs/sdks/oauth/README.md index 582dfee8..8b01f235 100644 --- a/docs/sdks/oauth/README.md +++ b/docs/sdks/oauth/README.md @@ -64,23 +64,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Mutation hook for triggering the API call. - useOAuthExchangeAuthCodeForAPIKeyMutation -} from "@openrouter/sdk/react-query/oAuthExchangeAuthCodeForAPIKey.js"; -``` - ### Parameters | Parameter | Type | Required | Description | @@ -157,23 +140,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Mutation hook for triggering the API call. - useOAuthCreateAuthCodeMutation -} from "@openrouter/sdk/react-query/oAuthCreateAuthCode.js"; -``` - ### Parameters | Parameter | Type | Required | Description | diff --git a/docs/sdks/parameters/README.md b/docs/sdks/parameters/README.md index ece36cbc..c41f0f1c 100644 --- a/docs/sdks/parameters/README.md +++ b/docs/sdks/parameters/README.md @@ -67,34 +67,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Query hooks for fetching data. - useParametersGetParameters, - useParametersGetParametersSuspense, - - // Utility for prefetching data during server-side rendering and in React - // Server Components that will be immediately available to client components - // using the hooks. - prefetchParametersGetParameters, - - // Utilities to invalidate the query cache for this query in response to - // mutations and other user actions. - invalidateParametersGetParameters, - invalidateAllParametersGetParameters, -} from "@openrouter/sdk/react-query/parametersGetParameters.js"; -``` - ### Parameters | Parameter | Type | Required | Description | diff --git a/docs/sdks/providers/README.md b/docs/sdks/providers/README.md index 9bfdfd7e..afeb58b5 100644 --- a/docs/sdks/providers/README.md +++ b/docs/sdks/providers/README.md @@ -59,33 +59,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Query hooks for fetching data. - useProvidersList, - useProvidersListSuspense, - - // Utility for prefetching data during server-side rendering and in React - // Server Components that will be immediately available to client components - // using the hooks. - prefetchProvidersList, - - // Utility to invalidate the query cache for this query in response to - // mutations and other user actions. - invalidateAllProvidersList, -} from "@openrouter/sdk/react-query/providersList.js"; -``` - ### Parameters | Parameter | Type | Required | Description | diff --git a/docs/sdks/responses/README.md b/docs/sdks/responses/README.md index 92a7fb36..9734d465 100644 --- a/docs/sdks/responses/README.md +++ b/docs/sdks/responses/README.md @@ -59,23 +59,6 @@ async function run() { run(); ``` -### React hooks and utilities - -This method can be used in React components through the following hooks and -associated utilities. - -> Check out [this guide][hook-guide] for information about each of the utilities -> below and how to get started using React hooks. - -[hook-guide]: ../../../REACT_QUERY.md - -```tsx -import { - // Mutation hook for triggering the API call. - useBetaResponsesSendMutation -} from "@openrouter/sdk/react-query/betaResponsesSend.js"; -``` - ### Parameters | Parameter | Type | Required | Description | diff --git a/package-lock.json b/package-lock.json index 431b4e76..aa5d748e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,31 +13,13 @@ }, "devDependencies": { "@eslint/js": "^9.19.0", - "@tanstack/react-query": "^5.61.4", "@types/node": "^22.13.12", - "@types/react": "^18.3.12", "dotenv": "^16.4.7", "eslint": "^9.19.0", "globals": "^15.14.0", "typescript": "~5.8.3", "typescript-eslint": "^8.26.0", "vitest": "^3.2.4" - }, - "peerDependencies": { - "@tanstack/react-query": "^5", - "react": "^18 || ^19", - "react-dom": "^18 || ^19" - }, - "peerDependenciesMeta": { - "@tanstack/react-query": { - "optional": true - }, - "react": { - "optional": true - }, - "react-dom": { - "optional": true - } } }, "node_modules/@esbuild/aix-ppc64": { @@ -1055,34 +1037,6 @@ "win32" ] }, - "node_modules/@tanstack/query-core": { - "version": "5.90.2", - "resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.90.2.tgz", - "integrity": "sha512-k/TcR3YalnzibscALLwxeiLUub6jN5EDLwKDiO7q5f4ICEoptJ+n9+7vcEFy5/x/i6Q+Lb/tXrsKCggf5uQJXQ==", - "dev": true, - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/tannerlinsley" - } - }, - "node_modules/@tanstack/react-query": { - "version": "5.90.2", - "resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.90.2.tgz", - "integrity": "sha512-CLABiR+h5PYfOWr/z+vWFt5VsOA2ekQeRQBFSKlcoW6Ndx/f8rfyVmq4LbgOM4GG2qtxAxjLYLOpCNTYm4uKzw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@tanstack/query-core": "5.90.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/tannerlinsley" - }, - "peerDependencies": { - "react": "^18 || ^19" - } - }, "node_modules/@types/chai": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.2.tgz", @@ -1124,24 +1078,6 @@ "undici-types": "~6.21.0" } }, - "node_modules/@types/prop-types": { - "version": "15.7.15", - "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.15.tgz", - "integrity": "sha512-F6bEyamV9jKGAFBEmlQnesRPGOQqS2+Uwi0Em15xenOxHaf2hv6L8YCVn3rPdPJOiJfPiCnLIRyvwVaqMY3MIw==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/react": { - "version": "18.3.24", - "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.24.tgz", - "integrity": "sha512-0dLEBsA1kI3OezMBF8nSsb7Nk19ZnsyE1LLhB8r27KbgU5H4pvuqZLdtE+aUkJVoXgTVuA+iLIwmZ0TuK4tx6A==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/prop-types": "*", - "csstype": "^3.0.2" - } - }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "8.40.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.40.0.tgz", @@ -1725,13 +1661,6 @@ "node": ">= 8" } }, - "node_modules/csstype": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", - "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==", - "dev": true, - "license": "MIT" - }, "node_modules/debug": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz", @@ -2642,17 +2571,6 @@ ], "license": "MIT" }, - "node_modules/react": { - "version": "19.1.1", - "resolved": "https://registry.npmjs.org/react/-/react-19.1.1.tgz", - "integrity": "sha512-w8nqGImo45dmMIfljjMwOGtbmC/mk4CMYhWIicdSflH91J9TyCyczcPFXJzrZ/ZXcgGRFeP6BU0BEJTw6tZdfQ==", - "devOptional": true, - "license": "MIT", - "peer": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/resolve-from": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", diff --git a/package.json b/package.json index 1397993a..08a6282d 100644 --- a/package.json +++ b/package.json @@ -48,11 +48,6 @@ "types": "./esm/models/operations/index.d.ts", "default": "./esm/models/operations/index.js" }, - "./react-query": { - "source": "./src/react-query/index.ts", - "types": "./esm/react-query/index.d.ts", - "default": "./esm/react-query/index.js" - }, "./*.js": { "source": "./src/*.ts", "types": "./esm/*.d.ts", @@ -75,20 +70,11 @@ "prepublishOnly": "npm run build" }, "peerDependencies": { - "@tanstack/react-query": "^5", - "react": "^18 || ^19", - "react-dom": "^18 || ^19" - }, - "peerDependenciesMeta": { - "@tanstack/react-query": {"optional":true}, - "react": {"optional":true}, - "react-dom": {"optional":true} + }, "devDependencies": { "@eslint/js": "^9.19.0", - "@tanstack/react-query": "^5.61.4", "@types/node": "^22.13.12", - "@types/react": "^18.3.12", "dotenv": "^16.4.7", "eslint": "^9.19.0", "globals": "^15.14.0", diff --git a/src/lib/config.ts b/src/lib/config.ts index d3cdfee5..c73da5f3 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -21,6 +21,16 @@ export const ServerList = { export type SDKOptions = { apiKey?: string | (() => Promise) | undefined; + /** + * Allows setting the httpReferer parameter for all supported operations + */ + httpReferer?: string | undefined; + + /** + * Allows setting the xTitle parameter for all supported operations + */ + xTitle?: string | undefined; + httpClient?: HTTPClient; /** * Allows overriding the default server used by the SDK diff --git a/src/lib/env.ts b/src/lib/env.ts index 0e742487..3d87d568 100644 --- a/src/lib/env.ts +++ b/src/lib/env.ts @@ -3,17 +3,31 @@ */ import * as z from "zod/v4"; +import { SDKOptions } from "./config.js"; import { dlv } from "./dlv.js"; export interface Env { OPENROUTER_API_KEY?: string | undefined; + /** + * Sets the httpReferer parameter for all supported operations + */ + OPENROUTER_HTTP_REFERER?: string | undefined; + + /** + * Sets the xTitle parameter for all supported operations + */ + OPENROUTER_X_TITLE?: string | undefined; + OPENROUTER_DEBUG?: boolean | undefined; } export const envSchema: z.ZodType = z.object({ OPENROUTER_API_KEY: z.string().optional(), + OPENROUTER_HTTP_REFERER: z.string().optional(), + OPENROUTER_X_TITLE: z.string().optional(), + OPENROUTER_DEBUG: z.coerce.boolean().optional(), }); @@ -55,3 +69,21 @@ export function env(): Env { export function resetEnv() { envMemo = undefined; } + +/** + * Populates global parameters with environment variables. + */ +export function fillGlobals(options: SDKOptions): SDKOptions { + const clone = { ...options }; + + const envVars = env(); + + if (typeof envVars.OPENROUTER_HTTP_REFERER !== "undefined") { + clone.httpReferer ??= envVars.OPENROUTER_HTTP_REFERER; + } + if (typeof envVars.OPENROUTER_X_TITLE !== "undefined") { + clone.xTitle ??= envVars.OPENROUTER_X_TITLE; + } + + return clone; +} diff --git a/src/lib/sdks.ts b/src/lib/sdks.ts index 46cad593..08b7e41b 100644 --- a/src/lib/sdks.ts +++ b/src/lib/sdks.ts @@ -15,7 +15,7 @@ import { ERR, OK, Result } from "../types/fp.js"; import { stringToBase64 } from "./base64.js"; import { SDK_METADATA, SDKOptions, serverURLFromOptions } from "./config.js"; import { encodeForm } from "./encodings.js"; -import { env } from "./env.js"; +import { env, fillGlobals } from "./env.js"; import { HTTPClient, isAbortError, @@ -108,7 +108,7 @@ export class ClientSDK { this._baseURL = url; this.#httpClient = options.httpClient || defaultHttpClient; - this._options = { ...options, hooks: this.#hooks }; + this._options = { ...fillGlobals(options), hooks: this.#hooks }; this.#logger = this._options.debugLogger; if (!this.#logger && env().OPENROUTER_DEBUG) { diff --git a/src/react-query/_context.tsx b/src/react-query/_context.tsx deleted file mode 100644 index 0e01a4a3..00000000 --- a/src/react-query/_context.tsx +++ /dev/null @@ -1,22 +0,0 @@ - -import React from "react"; - -import { OpenRouterCore } from "../core.js"; - -const OpenRouterContext = React.createContext(null); - -export function OpenRouterProvider(props: { client: OpenRouterCore, children: React.ReactNode }): React.ReactNode { - return ( - - {props.children} - - ); -} - -export function useOpenRouterContext(): OpenRouterCore { - const value = React.useContext(OpenRouterContext); - if (value === null) { - throw new Error("SDK not initialized. Create an instance of OpenRouterCore and pass it to ."); - } - return value; -} diff --git a/src/react-query/_types.ts b/src/react-query/_types.ts deleted file mode 100644 index 41460014..00000000 --- a/src/react-query/_types.ts +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { RequestOptions } from "../lib/sdks.js"; -import { PageIterator } from "../types/operations.js"; - -import type { - DefaultError, - InfiniteData, - InfiniteQueryPageParamsOptions, - OmitKeyof, - QueryKey, - QueryObserverOptions, - SkipToken, - UseMutationOptions, - UseQueryOptions, - UseSuspenseQueryOptions, -} from "@tanstack/react-query"; - -// Reaction to breaking change in 5.80.0 https://github.com/TanStack/query/pull/9224#issuecomment-2934835936 -interface UseInfiniteQueryOptions< - TQueryFnData = unknown, - TError = DefaultError, - TData = TQueryFnData, - TQueryKey extends QueryKey = QueryKey, - TPageParam = unknown, -> extends - OmitKeyof< - InfiniteQueryObserverOptions< - TQueryFnData, - TError, - TData, - TQueryKey, - TPageParam - >, - "suspense" - > -{ - /** - * Set this to `false` to unsubscribe this observer from updates to the query cache. - * Defaults to `true`. - */ - subscribed?: boolean; -} - -// Reaction to breaking change in 5.80.0 https://github.com/TanStack/query/pull/9224#issuecomment-2934835936 -interface InfiniteQueryObserverOptions< - TQueryFnData = unknown, - TError = DefaultError, - TData = TQueryFnData, - TQueryKey extends QueryKey = QueryKey, - TPageParam = unknown, -> extends - QueryObserverOptions< - TQueryFnData, - TError, - TData, - InfiniteData, - TQueryKey, - TPageParam - >, - InfiniteQueryPageParamsOptions -{ -} - -// Reaction to breaking change in 5.80.0 https://github.com/TanStack/query/pull/9224#issuecomment-2934835936 -interface UseSuspenseInfiniteQueryOptions< - TQueryFnData = unknown, - TError = DefaultError, - TData = TQueryFnData, - TQueryKey extends QueryKey = QueryKey, - TPageParam = unknown, -> extends - OmitKeyof< - UseInfiniteQueryOptions, - "queryFn" | "enabled" | "throwOnError" | "placeholderData" - > -{ - queryFn?: Exclude< - UseInfiniteQueryOptions< - TQueryFnData, - TError, - TData, - TQueryKey, - TPageParam - >["queryFn"], - SkipToken - >; -} -export type TupleToPrefixes = T extends [...infer Prefix, any] - ? TupleToPrefixes | T - : never; - -export type QueryHookOptions = - & Omit< - UseQueryOptions, - "queryKey" | "queryFn" | "select" | keyof RequestOptions - > - & RequestOptions; - -export type SuspenseQueryHookOptions = - & Omit< - UseSuspenseQueryOptions, - "queryKey" | "queryFn" | "select" | keyof RequestOptions - > - & RequestOptions; - -export type InfiniteQueryHookOptions< - Data extends PageIterator, -> = - & Omit< - UseInfiniteQueryOptions< - Data, - Error, - InfiniteData, - QueryKey, - Data["~next"] - >, - | "queryKey" - | "queryFn" - | "select" - | "getNextPageParam" - | "getPreviousPageParam" - | "initialPageParam" - | keyof RequestOptions - > - & RequestOptions - & { initialPageParam?: Data["~next"] }; - -export type SuspenseInfiniteQueryHookOptions< - Data extends PageIterator, -> = - & Omit< - UseSuspenseInfiniteQueryOptions< - Data, - Error, - InfiniteData, - QueryKey, - Data["~next"] - >, - | "queryKey" - | "queryFn" - | "select" - | "getNextPageParam" - | "getPreviousPageParam" - | "initialPageParam" - | keyof RequestOptions - > - & RequestOptions - & { initialPageParam?: Data["~next"] }; - -export type MutationHookOptions< - Data = unknown, - Err = Error, - Variables = unknown, -> = - & Omit< - UseMutationOptions, - "mutationKey" | "mutationFn" | keyof RequestOptions - > - & RequestOptions; diff --git a/src/react-query/analyticsGetUserActivity.ts b/src/react-query/analyticsGetUserActivity.ts deleted file mode 100644 index f36ff1a6..00000000 --- a/src/react-query/analyticsGetUserActivity.ts +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - InvalidateQueryFilters, - QueryClient, - QueryFunctionContext, - QueryKey, - useQuery, - UseQueryResult, - useSuspenseQuery, - UseSuspenseQueryResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { analyticsGetUserActivity } from "../funcs/analyticsGetUserActivity.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { - QueryHookOptions, - SuspenseQueryHookOptions, - TupleToPrefixes, -} from "./_types.js"; - -export type AnalyticsGetUserActivityQueryData = - operations.GetUserActivityResponse; - -/** - * Get user activity grouped by endpoint - * - * @remarks - * Returns user activity data grouped by endpoint for the last 30 (completed) UTC days - */ -export function useAnalyticsGetUserActivity( - request?: operations.GetUserActivityRequest | undefined, - options?: QueryHookOptions, -): UseQueryResult { - const client = useOpenRouterContext(); - return useQuery({ - ...buildAnalyticsGetUserActivityQuery( - client, - request, - options, - ), - ...options, - }); -} - -/** - * Get user activity grouped by endpoint - * - * @remarks - * Returns user activity data grouped by endpoint for the last 30 (completed) UTC days - */ -export function useAnalyticsGetUserActivitySuspense( - request?: operations.GetUserActivityRequest | undefined, - options?: SuspenseQueryHookOptions, -): UseSuspenseQueryResult { - const client = useOpenRouterContext(); - return useSuspenseQuery({ - ...buildAnalyticsGetUserActivityQuery( - client, - request, - options, - ), - ...options, - }); -} - -export function prefetchAnalyticsGetUserActivity( - queryClient: QueryClient, - client$: OpenRouterCore, - request?: operations.GetUserActivityRequest | undefined, -): Promise { - return queryClient.prefetchQuery({ - ...buildAnalyticsGetUserActivityQuery( - client$, - request, - ), - }); -} - -export function setAnalyticsGetUserActivityData( - client: QueryClient, - queryKeyBase: [parameters: { date?: string | undefined }], - data: AnalyticsGetUserActivityQueryData, -): AnalyticsGetUserActivityQueryData | undefined { - const key = queryKeyAnalyticsGetUserActivity(...queryKeyBase); - - return client.setQueryData(key, data); -} - -export function invalidateAnalyticsGetUserActivity( - client: QueryClient, - queryKeyBase: TupleToPrefixes<[parameters: { date?: string | undefined }]>, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: [ - "@openrouter/sdk", - "Analytics", - "getUserActivity", - ...queryKeyBase, - ], - }); -} - -export function invalidateAllAnalyticsGetUserActivity( - client: QueryClient, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: ["@openrouter/sdk", "Analytics", "getUserActivity"], - }); -} - -export function buildAnalyticsGetUserActivityQuery( - client$: OpenRouterCore, - request?: operations.GetUserActivityRequest | undefined, - options?: RequestOptions, -): { - queryKey: QueryKey; - queryFn: ( - context: QueryFunctionContext, - ) => Promise; -} { - return { - queryKey: queryKeyAnalyticsGetUserActivity({ date: request?.date }), - queryFn: async function analyticsGetUserActivityQueryFn( - ctx, - ): Promise { - const sig = combineSignals(ctx.signal, options?.fetchOptions?.signal); - const mergedOptions = { - ...options, - fetchOptions: { ...options?.fetchOptions, signal: sig }, - }; - - return unwrapAsync(analyticsGetUserActivity( - client$, - request, - mergedOptions, - )); - }, - }; -} - -export function queryKeyAnalyticsGetUserActivity( - parameters: { date?: string | undefined }, -): QueryKey { - return ["@openrouter/sdk", "Analytics", "getUserActivity", parameters]; -} diff --git a/src/react-query/apiKeysCreate.ts b/src/react-query/apiKeysCreate.ts deleted file mode 100644 index a511039a..00000000 --- a/src/react-query/apiKeysCreate.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - MutationKey, - useMutation, - UseMutationResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { apiKeysCreate } from "../funcs/apiKeysCreate.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { MutationHookOptions } from "./_types.js"; - -export type ApiKeysCreateMutationVariables = { - request: operations.CreateKeysRequest; - options?: RequestOptions; -}; - -export type ApiKeysCreateMutationData = operations.CreateKeysResponse; - -/** - * Create a new API key - */ -export function useApiKeysCreateMutation( - options?: MutationHookOptions< - ApiKeysCreateMutationData, - Error, - ApiKeysCreateMutationVariables - >, -): UseMutationResult< - ApiKeysCreateMutationData, - Error, - ApiKeysCreateMutationVariables -> { - const client = useOpenRouterContext(); - return useMutation({ - ...buildApiKeysCreateMutation(client, options), - ...options, - }); -} - -export function mutationKeyApiKeysCreate(): MutationKey { - return ["@openrouter/sdk", "API Keys", "create"]; -} - -export function buildApiKeysCreateMutation( - client$: OpenRouterCore, - hookOptions?: RequestOptions, -): { - mutationKey: MutationKey; - mutationFn: ( - variables: ApiKeysCreateMutationVariables, - ) => Promise; -} { - return { - mutationKey: mutationKeyApiKeysCreate(), - mutationFn: function apiKeysCreateMutationFn({ - request, - options, - }): Promise { - const mergedOptions = { - ...hookOptions, - ...options, - fetchOptions: { - ...hookOptions?.fetchOptions, - ...options?.fetchOptions, - signal: combineSignals( - hookOptions?.fetchOptions?.signal, - options?.fetchOptions?.signal, - ), - }, - }; - return unwrapAsync(apiKeysCreate( - client$, - request, - mergedOptions, - )); - }, - }; -} diff --git a/src/react-query/apiKeysDelete.ts b/src/react-query/apiKeysDelete.ts deleted file mode 100644 index e8d83973..00000000 --- a/src/react-query/apiKeysDelete.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - MutationKey, - useMutation, - UseMutationResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { apiKeysDelete } from "../funcs/apiKeysDelete.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { MutationHookOptions } from "./_types.js"; - -export type ApiKeysDeleteMutationVariables = { - request: operations.DeleteKeysRequest; - options?: RequestOptions; -}; - -export type ApiKeysDeleteMutationData = operations.DeleteKeysResponse; - -/** - * Delete an API key - */ -export function useApiKeysDeleteMutation( - options?: MutationHookOptions< - ApiKeysDeleteMutationData, - Error, - ApiKeysDeleteMutationVariables - >, -): UseMutationResult< - ApiKeysDeleteMutationData, - Error, - ApiKeysDeleteMutationVariables -> { - const client = useOpenRouterContext(); - return useMutation({ - ...buildApiKeysDeleteMutation(client, options), - ...options, - }); -} - -export function mutationKeyApiKeysDelete(): MutationKey { - return ["@openrouter/sdk", "API Keys", "delete"]; -} - -export function buildApiKeysDeleteMutation( - client$: OpenRouterCore, - hookOptions?: RequestOptions, -): { - mutationKey: MutationKey; - mutationFn: ( - variables: ApiKeysDeleteMutationVariables, - ) => Promise; -} { - return { - mutationKey: mutationKeyApiKeysDelete(), - mutationFn: function apiKeysDeleteMutationFn({ - request, - options, - }): Promise { - const mergedOptions = { - ...hookOptions, - ...options, - fetchOptions: { - ...hookOptions?.fetchOptions, - ...options?.fetchOptions, - signal: combineSignals( - hookOptions?.fetchOptions?.signal, - options?.fetchOptions?.signal, - ), - }, - }; - return unwrapAsync(apiKeysDelete( - client$, - request, - mergedOptions, - )); - }, - }; -} diff --git a/src/react-query/apiKeysGet.ts b/src/react-query/apiKeysGet.ts deleted file mode 100644 index 894e6d86..00000000 --- a/src/react-query/apiKeysGet.ts +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - InvalidateQueryFilters, - QueryClient, - QueryFunctionContext, - QueryKey, - useQuery, - UseQueryResult, - useSuspenseQuery, - UseSuspenseQueryResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { apiKeysGet } from "../funcs/apiKeysGet.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { - QueryHookOptions, - SuspenseQueryHookOptions, - TupleToPrefixes, -} from "./_types.js"; - -export type ApiKeysGetQueryData = operations.GetKeyResponse; - -/** - * Get a single API key - */ -export function useApiKeysGet( - request: operations.GetKeyRequest, - options?: QueryHookOptions, -): UseQueryResult { - const client = useOpenRouterContext(); - return useQuery({ - ...buildApiKeysGetQuery( - client, - request, - options, - ), - ...options, - }); -} - -/** - * Get a single API key - */ -export function useApiKeysGetSuspense( - request: operations.GetKeyRequest, - options?: SuspenseQueryHookOptions, -): UseSuspenseQueryResult { - const client = useOpenRouterContext(); - return useSuspenseQuery({ - ...buildApiKeysGetQuery( - client, - request, - options, - ), - ...options, - }); -} - -export function prefetchApiKeysGet( - queryClient: QueryClient, - client$: OpenRouterCore, - request: operations.GetKeyRequest, -): Promise { - return queryClient.prefetchQuery({ - ...buildApiKeysGetQuery( - client$, - request, - ), - }); -} - -export function setApiKeysGetData( - client: QueryClient, - queryKeyBase: [hash: string], - data: ApiKeysGetQueryData, -): ApiKeysGetQueryData | undefined { - const key = queryKeyApiKeysGet(...queryKeyBase); - - return client.setQueryData(key, data); -} - -export function invalidateApiKeysGet( - client: QueryClient, - queryKeyBase: TupleToPrefixes<[hash: string]>, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: ["@openrouter/sdk", "API Keys", "get", ...queryKeyBase], - }); -} - -export function invalidateAllApiKeysGet( - client: QueryClient, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: ["@openrouter/sdk", "API Keys", "get"], - }); -} - -export function buildApiKeysGetQuery( - client$: OpenRouterCore, - request: operations.GetKeyRequest, - options?: RequestOptions, -): { - queryKey: QueryKey; - queryFn: (context: QueryFunctionContext) => Promise; -} { - return { - queryKey: queryKeyApiKeysGet(request.hash), - queryFn: async function apiKeysGetQueryFn( - ctx, - ): Promise { - const sig = combineSignals(ctx.signal, options?.fetchOptions?.signal); - const mergedOptions = { - ...options, - fetchOptions: { ...options?.fetchOptions, signal: sig }, - }; - - return unwrapAsync(apiKeysGet( - client$, - request, - mergedOptions, - )); - }, - }; -} - -export function queryKeyApiKeysGet(hash: string): QueryKey { - return ["@openrouter/sdk", "API Keys", "get", hash]; -} diff --git a/src/react-query/apiKeysGetCurrentKeyMetadata.ts b/src/react-query/apiKeysGetCurrentKeyMetadata.ts deleted file mode 100644 index 1d74ea8d..00000000 --- a/src/react-query/apiKeysGetCurrentKeyMetadata.ts +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - InvalidateQueryFilters, - QueryClient, - QueryFunctionContext, - QueryKey, - useQuery, - UseQueryResult, - useSuspenseQuery, - UseSuspenseQueryResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { apiKeysGetCurrentKeyMetadata } from "../funcs/apiKeysGetCurrentKeyMetadata.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { QueryHookOptions, SuspenseQueryHookOptions } from "./_types.js"; - -export type ApiKeysGetCurrentKeyMetadataQueryData = - operations.GetCurrentKeyResponse; - -/** - * Get current API key - * - * @remarks - * Get information on the API key associated with the current authentication session - */ -export function useApiKeysGetCurrentKeyMetadata( - options?: QueryHookOptions, -): UseQueryResult { - const client = useOpenRouterContext(); - return useQuery({ - ...buildApiKeysGetCurrentKeyMetadataQuery( - client, - options, - ), - ...options, - }); -} - -/** - * Get current API key - * - * @remarks - * Get information on the API key associated with the current authentication session - */ -export function useApiKeysGetCurrentKeyMetadataSuspense( - options?: SuspenseQueryHookOptions, -): UseSuspenseQueryResult { - const client = useOpenRouterContext(); - return useSuspenseQuery({ - ...buildApiKeysGetCurrentKeyMetadataQuery( - client, - options, - ), - ...options, - }); -} - -export function prefetchApiKeysGetCurrentKeyMetadata( - queryClient: QueryClient, - client$: OpenRouterCore, -): Promise { - return queryClient.prefetchQuery({ - ...buildApiKeysGetCurrentKeyMetadataQuery( - client$, - ), - }); -} - -export function setApiKeysGetCurrentKeyMetadataData( - client: QueryClient, - data: ApiKeysGetCurrentKeyMetadataQueryData, -): ApiKeysGetCurrentKeyMetadataQueryData | undefined { - const key = queryKeyApiKeysGetCurrentKeyMetadata(); - - return client.setQueryData(key, data); -} - -export function invalidateAllApiKeysGetCurrentKeyMetadata( - client: QueryClient, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: ["@openrouter/sdk", "API Keys", "getCurrentKeyMetadata"], - }); -} - -export function buildApiKeysGetCurrentKeyMetadataQuery( - client$: OpenRouterCore, - options?: RequestOptions, -): { - queryKey: QueryKey; - queryFn: ( - context: QueryFunctionContext, - ) => Promise; -} { - return { - queryKey: queryKeyApiKeysGetCurrentKeyMetadata(), - queryFn: async function apiKeysGetCurrentKeyMetadataQueryFn( - ctx, - ): Promise { - const sig = combineSignals(ctx.signal, options?.fetchOptions?.signal); - const mergedOptions = { - ...options, - fetchOptions: { ...options?.fetchOptions, signal: sig }, - }; - - return unwrapAsync(apiKeysGetCurrentKeyMetadata( - client$, - mergedOptions, - )); - }, - }; -} - -export function queryKeyApiKeysGetCurrentKeyMetadata(): QueryKey { - return ["@openrouter/sdk", "API Keys", "getCurrentKeyMetadata"]; -} diff --git a/src/react-query/apiKeysList.ts b/src/react-query/apiKeysList.ts deleted file mode 100644 index 933ec8c8..00000000 --- a/src/react-query/apiKeysList.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - InvalidateQueryFilters, - QueryClient, - QueryFunctionContext, - QueryKey, - useQuery, - UseQueryResult, - useSuspenseQuery, - UseSuspenseQueryResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { apiKeysList } from "../funcs/apiKeysList.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { - QueryHookOptions, - SuspenseQueryHookOptions, - TupleToPrefixes, -} from "./_types.js"; - -export type ApiKeysListQueryData = operations.ListResponse; - -/** - * List API keys - */ -export function useApiKeysList( - request?: operations.ListRequest | undefined, - options?: QueryHookOptions, -): UseQueryResult { - const client = useOpenRouterContext(); - return useQuery({ - ...buildApiKeysListQuery( - client, - request, - options, - ), - ...options, - }); -} - -/** - * List API keys - */ -export function useApiKeysListSuspense( - request?: operations.ListRequest | undefined, - options?: SuspenseQueryHookOptions, -): UseSuspenseQueryResult { - const client = useOpenRouterContext(); - return useSuspenseQuery({ - ...buildApiKeysListQuery( - client, - request, - options, - ), - ...options, - }); -} - -export function prefetchApiKeysList( - queryClient: QueryClient, - client$: OpenRouterCore, - request?: operations.ListRequest | undefined, -): Promise { - return queryClient.prefetchQuery({ - ...buildApiKeysListQuery( - client$, - request, - ), - }); -} - -export function setApiKeysListData( - client: QueryClient, - queryKeyBase: [ - parameters: { - includeDisabled?: string | undefined; - offset?: string | undefined; - }, - ], - data: ApiKeysListQueryData, -): ApiKeysListQueryData | undefined { - const key = queryKeyApiKeysList(...queryKeyBase); - - return client.setQueryData(key, data); -} - -export function invalidateApiKeysList( - client: QueryClient, - queryKeyBase: TupleToPrefixes< - [parameters: { - includeDisabled?: string | undefined; - offset?: string | undefined; - }] - >, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: ["@openrouter/sdk", "API Keys", "list", ...queryKeyBase], - }); -} - -export function invalidateAllApiKeysList( - client: QueryClient, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: ["@openrouter/sdk", "API Keys", "list"], - }); -} - -export function buildApiKeysListQuery( - client$: OpenRouterCore, - request?: operations.ListRequest | undefined, - options?: RequestOptions, -): { - queryKey: QueryKey; - queryFn: (context: QueryFunctionContext) => Promise; -} { - return { - queryKey: queryKeyApiKeysList({ - includeDisabled: request?.includeDisabled, - offset: request?.offset, - }), - queryFn: async function apiKeysListQueryFn( - ctx, - ): Promise { - const sig = combineSignals(ctx.signal, options?.fetchOptions?.signal); - const mergedOptions = { - ...options, - fetchOptions: { ...options?.fetchOptions, signal: sig }, - }; - - return unwrapAsync(apiKeysList( - client$, - request, - mergedOptions, - )); - }, - }; -} - -export function queryKeyApiKeysList( - parameters: { - includeDisabled?: string | undefined; - offset?: string | undefined; - }, -): QueryKey { - return ["@openrouter/sdk", "API Keys", "list", parameters]; -} diff --git a/src/react-query/apiKeysUpdate.ts b/src/react-query/apiKeysUpdate.ts deleted file mode 100644 index b34dd683..00000000 --- a/src/react-query/apiKeysUpdate.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - MutationKey, - useMutation, - UseMutationResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { apiKeysUpdate } from "../funcs/apiKeysUpdate.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { MutationHookOptions } from "./_types.js"; - -export type ApiKeysUpdateMutationVariables = { - request: operations.UpdateKeysRequest; - options?: RequestOptions; -}; - -export type ApiKeysUpdateMutationData = operations.UpdateKeysResponse; - -/** - * Update an API key - */ -export function useApiKeysUpdateMutation( - options?: MutationHookOptions< - ApiKeysUpdateMutationData, - Error, - ApiKeysUpdateMutationVariables - >, -): UseMutationResult< - ApiKeysUpdateMutationData, - Error, - ApiKeysUpdateMutationVariables -> { - const client = useOpenRouterContext(); - return useMutation({ - ...buildApiKeysUpdateMutation(client, options), - ...options, - }); -} - -export function mutationKeyApiKeysUpdate(): MutationKey { - return ["@openrouter/sdk", "API Keys", "update"]; -} - -export function buildApiKeysUpdateMutation( - client$: OpenRouterCore, - hookOptions?: RequestOptions, -): { - mutationKey: MutationKey; - mutationFn: ( - variables: ApiKeysUpdateMutationVariables, - ) => Promise; -} { - return { - mutationKey: mutationKeyApiKeysUpdate(), - mutationFn: function apiKeysUpdateMutationFn({ - request, - options, - }): Promise { - const mergedOptions = { - ...hookOptions, - ...options, - fetchOptions: { - ...hookOptions?.fetchOptions, - ...options?.fetchOptions, - signal: combineSignals( - hookOptions?.fetchOptions?.signal, - options?.fetchOptions?.signal, - ), - }, - }; - return unwrapAsync(apiKeysUpdate( - client$, - request, - mergedOptions, - )); - }, - }; -} diff --git a/src/react-query/betaResponsesSend.ts b/src/react-query/betaResponsesSend.ts deleted file mode 100644 index b8e153c2..00000000 --- a/src/react-query/betaResponsesSend.ts +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - MutationKey, - useMutation, - UseMutationResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { betaResponsesSend } from "../funcs/betaResponsesSend.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as models from "../models/index.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { MutationHookOptions } from "./_types.js"; - -export type BetaResponsesSendMutationVariables = { - request: models.OpenResponsesRequest; - options?: RequestOptions; -}; - -export type BetaResponsesSendMutationData = operations.CreateResponsesResponse; - -/** - * Create a response - * - * @remarks - * Creates a streaming or non-streaming response using OpenResponses API format - */ -export function useBetaResponsesSendMutation( - options?: MutationHookOptions< - BetaResponsesSendMutationData, - Error, - BetaResponsesSendMutationVariables - >, -): UseMutationResult< - BetaResponsesSendMutationData, - Error, - BetaResponsesSendMutationVariables -> { - const client = useOpenRouterContext(); - return useMutation({ - ...buildBetaResponsesSendMutation(client, options), - ...options, - }); -} - -export function mutationKeyBetaResponsesSend(): MutationKey { - return ["@openrouter/sdk", "responses", "send"]; -} - -export function buildBetaResponsesSendMutation( - client$: OpenRouterCore, - hookOptions?: RequestOptions, -): { - mutationKey: MutationKey; - mutationFn: ( - variables: BetaResponsesSendMutationVariables, - ) => Promise; -} { - return { - mutationKey: mutationKeyBetaResponsesSend(), - mutationFn: function betaResponsesSendMutationFn({ - request, - options, - }): Promise { - const mergedOptions = { - ...hookOptions, - ...options, - fetchOptions: { - ...hookOptions?.fetchOptions, - ...options?.fetchOptions, - signal: combineSignals( - hookOptions?.fetchOptions?.signal, - options?.fetchOptions?.signal, - ), - }, - }; - return unwrapAsync(betaResponsesSend( - client$, - request, - mergedOptions, - )); - }, - }; -} diff --git a/src/react-query/chatSend.ts b/src/react-query/chatSend.ts deleted file mode 100644 index 383f35f3..00000000 --- a/src/react-query/chatSend.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - MutationKey, - useMutation, - UseMutationResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { chatSend } from "../funcs/chatSend.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as models from "../models/index.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { MutationHookOptions } from "./_types.js"; - -export type ChatSendMutationVariables = { - request: models.ChatGenerationParams; - options?: RequestOptions; -}; - -export type ChatSendMutationData = operations.SendChatCompletionRequestResponse; - -/** - * Create a chat completion - * - * @remarks - * Sends a request for a model response for the given chat conversation. Supports both streaming and non-streaming modes. - */ -export function useChatSendMutation( - options?: MutationHookOptions< - ChatSendMutationData, - Error, - ChatSendMutationVariables - >, -): UseMutationResult { - const client = useOpenRouterContext(); - return useMutation({ - ...buildChatSendMutation(client, options), - ...options, - }); -} - -export function mutationKeyChatSend(): MutationKey { - return ["@openrouter/sdk", "chat", "send"]; -} - -export function buildChatSendMutation( - client$: OpenRouterCore, - hookOptions?: RequestOptions, -): { - mutationKey: MutationKey; - mutationFn: ( - variables: ChatSendMutationVariables, - ) => Promise; -} { - return { - mutationKey: mutationKeyChatSend(), - mutationFn: function chatSendMutationFn({ - request, - options, - }): Promise { - const mergedOptions = { - ...hookOptions, - ...options, - fetchOptions: { - ...hookOptions?.fetchOptions, - ...options?.fetchOptions, - signal: combineSignals( - hookOptions?.fetchOptions?.signal, - options?.fetchOptions?.signal, - ), - }, - }; - return unwrapAsync(chatSend( - client$, - request, - mergedOptions, - )); - }, - }; -} diff --git a/src/react-query/completionsGenerate.ts b/src/react-query/completionsGenerate.ts deleted file mode 100644 index 7b081e8b..00000000 --- a/src/react-query/completionsGenerate.ts +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - MutationKey, - useMutation, - UseMutationResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { completionsGenerate } from "../funcs/completionsGenerate.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as models from "../models/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { MutationHookOptions } from "./_types.js"; - -export type CompletionsGenerateMutationVariables = { - request: models.CompletionCreateParams; - options?: RequestOptions; -}; - -export type CompletionsGenerateMutationData = models.CompletionResponse; - -/** - * Create a completion - * - * @remarks - * Creates a completion for the provided prompt and parameters. Supports both streaming and non-streaming modes. - */ -export function useCompletionsGenerateMutation( - options?: MutationHookOptions< - CompletionsGenerateMutationData, - Error, - CompletionsGenerateMutationVariables - >, -): UseMutationResult< - CompletionsGenerateMutationData, - Error, - CompletionsGenerateMutationVariables -> { - const client = useOpenRouterContext(); - return useMutation({ - ...buildCompletionsGenerateMutation(client, options), - ...options, - }); -} - -export function mutationKeyCompletionsGenerate(): MutationKey { - return ["@openrouter/sdk", "completions", "generate"]; -} - -export function buildCompletionsGenerateMutation( - client$: OpenRouterCore, - hookOptions?: RequestOptions, -): { - mutationKey: MutationKey; - mutationFn: ( - variables: CompletionsGenerateMutationVariables, - ) => Promise; -} { - return { - mutationKey: mutationKeyCompletionsGenerate(), - mutationFn: function completionsGenerateMutationFn({ - request, - options, - }): Promise { - const mergedOptions = { - ...hookOptions, - ...options, - fetchOptions: { - ...hookOptions?.fetchOptions, - ...options?.fetchOptions, - signal: combineSignals( - hookOptions?.fetchOptions?.signal, - options?.fetchOptions?.signal, - ), - }, - }; - return unwrapAsync(completionsGenerate( - client$, - request, - mergedOptions, - )); - }, - }; -} diff --git a/src/react-query/creditsCreateCoinbaseCharge.ts b/src/react-query/creditsCreateCoinbaseCharge.ts deleted file mode 100644 index 78769cad..00000000 --- a/src/react-query/creditsCreateCoinbaseCharge.ts +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - MutationKey, - useMutation, - UseMutationResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { creditsCreateCoinbaseCharge } from "../funcs/creditsCreateCoinbaseCharge.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as models from "../models/index.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { MutationHookOptions } from "./_types.js"; - -export type CreditsCreateCoinbaseChargeMutationVariables = { - security: operations.CreateCoinbaseChargeSecurity; - request: models.CreateChargeRequest; - options?: RequestOptions; -}; - -export type CreditsCreateCoinbaseChargeMutationData = - operations.CreateCoinbaseChargeResponse; - -/** - * Create a Coinbase charge for crypto payment - * - * @remarks - * Create a Coinbase charge for crypto payment - */ -export function useCreditsCreateCoinbaseChargeMutation( - options?: MutationHookOptions< - CreditsCreateCoinbaseChargeMutationData, - Error, - CreditsCreateCoinbaseChargeMutationVariables - >, -): UseMutationResult< - CreditsCreateCoinbaseChargeMutationData, - Error, - CreditsCreateCoinbaseChargeMutationVariables -> { - const client = useOpenRouterContext(); - return useMutation({ - ...buildCreditsCreateCoinbaseChargeMutation(client, options), - ...options, - }); -} - -export function mutationKeyCreditsCreateCoinbaseCharge(): MutationKey { - return ["@openrouter/sdk", "Credits", "createCoinbaseCharge"]; -} - -export function buildCreditsCreateCoinbaseChargeMutation( - client$: OpenRouterCore, - hookOptions?: RequestOptions, -): { - mutationKey: MutationKey; - mutationFn: ( - variables: CreditsCreateCoinbaseChargeMutationVariables, - ) => Promise; -} { - return { - mutationKey: mutationKeyCreditsCreateCoinbaseCharge(), - mutationFn: function creditsCreateCoinbaseChargeMutationFn({ - security, - request, - options, - }): Promise { - const mergedOptions = { - ...hookOptions, - ...options, - fetchOptions: { - ...hookOptions?.fetchOptions, - ...options?.fetchOptions, - signal: combineSignals( - hookOptions?.fetchOptions?.signal, - options?.fetchOptions?.signal, - ), - }, - }; - return unwrapAsync(creditsCreateCoinbaseCharge( - client$, - security, - request, - mergedOptions, - )); - }, - }; -} diff --git a/src/react-query/creditsGetCredits.ts b/src/react-query/creditsGetCredits.ts deleted file mode 100644 index a04ad0d8..00000000 --- a/src/react-query/creditsGetCredits.ts +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - InvalidateQueryFilters, - QueryClient, - QueryFunctionContext, - QueryKey, - useQuery, - UseQueryResult, - useSuspenseQuery, - UseSuspenseQueryResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { creditsGetCredits } from "../funcs/creditsGetCredits.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { QueryHookOptions, SuspenseQueryHookOptions } from "./_types.js"; - -export type CreditsGetCreditsQueryData = operations.GetCreditsResponse; - -/** - * Get remaining credits - * - * @remarks - * Get total credits purchased and used for the authenticated user - */ -export function useCreditsGetCredits( - options?: QueryHookOptions, -): UseQueryResult { - const client = useOpenRouterContext(); - return useQuery({ - ...buildCreditsGetCreditsQuery( - client, - options, - ), - ...options, - }); -} - -/** - * Get remaining credits - * - * @remarks - * Get total credits purchased and used for the authenticated user - */ -export function useCreditsGetCreditsSuspense( - options?: SuspenseQueryHookOptions, -): UseSuspenseQueryResult { - const client = useOpenRouterContext(); - return useSuspenseQuery({ - ...buildCreditsGetCreditsQuery( - client, - options, - ), - ...options, - }); -} - -export function prefetchCreditsGetCredits( - queryClient: QueryClient, - client$: OpenRouterCore, -): Promise { - return queryClient.prefetchQuery({ - ...buildCreditsGetCreditsQuery( - client$, - ), - }); -} - -export function setCreditsGetCreditsData( - client: QueryClient, - data: CreditsGetCreditsQueryData, -): CreditsGetCreditsQueryData | undefined { - const key = queryKeyCreditsGetCredits(); - - return client.setQueryData(key, data); -} - -export function invalidateAllCreditsGetCredits( - client: QueryClient, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: ["@openrouter/sdk", "Credits", "getCredits"], - }); -} - -export function buildCreditsGetCreditsQuery( - client$: OpenRouterCore, - options?: RequestOptions, -): { - queryKey: QueryKey; - queryFn: ( - context: QueryFunctionContext, - ) => Promise; -} { - return { - queryKey: queryKeyCreditsGetCredits(), - queryFn: async function creditsGetCreditsQueryFn( - ctx, - ): Promise { - const sig = combineSignals(ctx.signal, options?.fetchOptions?.signal); - const mergedOptions = { - ...options, - fetchOptions: { ...options?.fetchOptions, signal: sig }, - }; - - return unwrapAsync(creditsGetCredits( - client$, - mergedOptions, - )); - }, - }; -} - -export function queryKeyCreditsGetCredits(): QueryKey { - return ["@openrouter/sdk", "Credits", "getCredits"]; -} diff --git a/src/react-query/embeddingsGenerate.ts b/src/react-query/embeddingsGenerate.ts deleted file mode 100644 index 864b425b..00000000 --- a/src/react-query/embeddingsGenerate.ts +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - MutationKey, - useMutation, - UseMutationResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { embeddingsGenerate } from "../funcs/embeddingsGenerate.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { MutationHookOptions } from "./_types.js"; - -export type EmbeddingsGenerateMutationVariables = { - request: operations.CreateEmbeddingsRequest; - options?: RequestOptions; -}; - -export type EmbeddingsGenerateMutationData = - operations.CreateEmbeddingsResponse; - -/** - * Submit an embedding request - * - * @remarks - * Submits an embedding request to the embeddings router - */ -export function useEmbeddingsGenerateMutation( - options?: MutationHookOptions< - EmbeddingsGenerateMutationData, - Error, - EmbeddingsGenerateMutationVariables - >, -): UseMutationResult< - EmbeddingsGenerateMutationData, - Error, - EmbeddingsGenerateMutationVariables -> { - const client = useOpenRouterContext(); - return useMutation({ - ...buildEmbeddingsGenerateMutation(client, options), - ...options, - }); -} - -export function mutationKeyEmbeddingsGenerate(): MutationKey { - return ["@openrouter/sdk", "Embeddings", "generate"]; -} - -export function buildEmbeddingsGenerateMutation( - client$: OpenRouterCore, - hookOptions?: RequestOptions, -): { - mutationKey: MutationKey; - mutationFn: ( - variables: EmbeddingsGenerateMutationVariables, - ) => Promise; -} { - return { - mutationKey: mutationKeyEmbeddingsGenerate(), - mutationFn: function embeddingsGenerateMutationFn({ - request, - options, - }): Promise { - const mergedOptions = { - ...hookOptions, - ...options, - fetchOptions: { - ...hookOptions?.fetchOptions, - ...options?.fetchOptions, - signal: combineSignals( - hookOptions?.fetchOptions?.signal, - options?.fetchOptions?.signal, - ), - }, - }; - return unwrapAsync(embeddingsGenerate( - client$, - request, - mergedOptions, - )); - }, - }; -} diff --git a/src/react-query/embeddingsListModels.ts b/src/react-query/embeddingsListModels.ts deleted file mode 100644 index b0d6bd93..00000000 --- a/src/react-query/embeddingsListModels.ts +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - InvalidateQueryFilters, - QueryClient, - QueryFunctionContext, - QueryKey, - useQuery, - UseQueryResult, - useSuspenseQuery, - UseSuspenseQueryResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { embeddingsListModels } from "../funcs/embeddingsListModels.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as models from "../models/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { QueryHookOptions, SuspenseQueryHookOptions } from "./_types.js"; - -export type EmbeddingsListModelsQueryData = models.ModelsListResponse; - -/** - * List all embeddings models - * - * @remarks - * Returns a list of all available embeddings models and their properties - */ -export function useEmbeddingsListModels( - options?: QueryHookOptions, -): UseQueryResult { - const client = useOpenRouterContext(); - return useQuery({ - ...buildEmbeddingsListModelsQuery( - client, - options, - ), - ...options, - }); -} - -/** - * List all embeddings models - * - * @remarks - * Returns a list of all available embeddings models and their properties - */ -export function useEmbeddingsListModelsSuspense( - options?: SuspenseQueryHookOptions, -): UseSuspenseQueryResult { - const client = useOpenRouterContext(); - return useSuspenseQuery({ - ...buildEmbeddingsListModelsQuery( - client, - options, - ), - ...options, - }); -} - -export function prefetchEmbeddingsListModels( - queryClient: QueryClient, - client$: OpenRouterCore, -): Promise { - return queryClient.prefetchQuery({ - ...buildEmbeddingsListModelsQuery( - client$, - ), - }); -} - -export function setEmbeddingsListModelsData( - client: QueryClient, - data: EmbeddingsListModelsQueryData, -): EmbeddingsListModelsQueryData | undefined { - const key = queryKeyEmbeddingsListModels(); - - return client.setQueryData(key, data); -} - -export function invalidateAllEmbeddingsListModels( - client: QueryClient, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: ["@openrouter/sdk", "Embeddings", "listModels"], - }); -} - -export function buildEmbeddingsListModelsQuery( - client$: OpenRouterCore, - options?: RequestOptions, -): { - queryKey: QueryKey; - queryFn: ( - context: QueryFunctionContext, - ) => Promise; -} { - return { - queryKey: queryKeyEmbeddingsListModels(), - queryFn: async function embeddingsListModelsQueryFn( - ctx, - ): Promise { - const sig = combineSignals(ctx.signal, options?.fetchOptions?.signal); - const mergedOptions = { - ...options, - fetchOptions: { ...options?.fetchOptions, signal: sig }, - }; - - return unwrapAsync(embeddingsListModels( - client$, - mergedOptions, - )); - }, - }; -} - -export function queryKeyEmbeddingsListModels(): QueryKey { - return ["@openrouter/sdk", "Embeddings", "listModels"]; -} diff --git a/src/react-query/endpointsList.ts b/src/react-query/endpointsList.ts deleted file mode 100644 index bd20108e..00000000 --- a/src/react-query/endpointsList.ts +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - InvalidateQueryFilters, - QueryClient, - QueryFunctionContext, - QueryKey, - useQuery, - UseQueryResult, - useSuspenseQuery, - UseSuspenseQueryResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { endpointsList } from "../funcs/endpointsList.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { - QueryHookOptions, - SuspenseQueryHookOptions, - TupleToPrefixes, -} from "./_types.js"; - -export type EndpointsListQueryData = operations.ListEndpointsResponse; - -/** - * List all endpoints for a model - */ -export function useEndpointsList( - request: operations.ListEndpointsRequest, - options?: QueryHookOptions, -): UseQueryResult { - const client = useOpenRouterContext(); - return useQuery({ - ...buildEndpointsListQuery( - client, - request, - options, - ), - ...options, - }); -} - -/** - * List all endpoints for a model - */ -export function useEndpointsListSuspense( - request: operations.ListEndpointsRequest, - options?: SuspenseQueryHookOptions, -): UseSuspenseQueryResult { - const client = useOpenRouterContext(); - return useSuspenseQuery({ - ...buildEndpointsListQuery( - client, - request, - options, - ), - ...options, - }); -} - -export function prefetchEndpointsList( - queryClient: QueryClient, - client$: OpenRouterCore, - request: operations.ListEndpointsRequest, -): Promise { - return queryClient.prefetchQuery({ - ...buildEndpointsListQuery( - client$, - request, - ), - }); -} - -export function setEndpointsListData( - client: QueryClient, - queryKeyBase: [author: string, slug: string], - data: EndpointsListQueryData, -): EndpointsListQueryData | undefined { - const key = queryKeyEndpointsList(...queryKeyBase); - - return client.setQueryData(key, data); -} - -export function invalidateEndpointsList( - client: QueryClient, - queryKeyBase: TupleToPrefixes<[author: string, slug: string]>, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: ["@openrouter/sdk", "Endpoints", "list", ...queryKeyBase], - }); -} - -export function invalidateAllEndpointsList( - client: QueryClient, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: ["@openrouter/sdk", "Endpoints", "list"], - }); -} - -export function buildEndpointsListQuery( - client$: OpenRouterCore, - request: operations.ListEndpointsRequest, - options?: RequestOptions, -): { - queryKey: QueryKey; - queryFn: (context: QueryFunctionContext) => Promise; -} { - return { - queryKey: queryKeyEndpointsList(request.author, request.slug), - queryFn: async function endpointsListQueryFn( - ctx, - ): Promise { - const sig = combineSignals(ctx.signal, options?.fetchOptions?.signal); - const mergedOptions = { - ...options, - fetchOptions: { ...options?.fetchOptions, signal: sig }, - }; - - return unwrapAsync(endpointsList( - client$, - request, - mergedOptions, - )); - }, - }; -} - -export function queryKeyEndpointsList(author: string, slug: string): QueryKey { - return ["@openrouter/sdk", "Endpoints", "list", author, slug]; -} diff --git a/src/react-query/endpointsListZdrEndpoints.ts b/src/react-query/endpointsListZdrEndpoints.ts deleted file mode 100644 index d3fd8895..00000000 --- a/src/react-query/endpointsListZdrEndpoints.ts +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - InvalidateQueryFilters, - QueryClient, - QueryFunctionContext, - QueryKey, - useQuery, - UseQueryResult, - useSuspenseQuery, - UseSuspenseQueryResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { endpointsListZdrEndpoints } from "../funcs/endpointsListZdrEndpoints.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { QueryHookOptions, SuspenseQueryHookOptions } from "./_types.js"; - -export type EndpointsListZdrEndpointsQueryData = - operations.ListEndpointsZdrResponse; - -/** - * Preview the impact of ZDR on the available endpoints - */ -export function useEndpointsListZdrEndpoints( - options?: QueryHookOptions, -): UseQueryResult { - const client = useOpenRouterContext(); - return useQuery({ - ...buildEndpointsListZdrEndpointsQuery( - client, - options, - ), - ...options, - }); -} - -/** - * Preview the impact of ZDR on the available endpoints - */ -export function useEndpointsListZdrEndpointsSuspense( - options?: SuspenseQueryHookOptions, -): UseSuspenseQueryResult { - const client = useOpenRouterContext(); - return useSuspenseQuery({ - ...buildEndpointsListZdrEndpointsQuery( - client, - options, - ), - ...options, - }); -} - -export function prefetchEndpointsListZdrEndpoints( - queryClient: QueryClient, - client$: OpenRouterCore, -): Promise { - return queryClient.prefetchQuery({ - ...buildEndpointsListZdrEndpointsQuery( - client$, - ), - }); -} - -export function setEndpointsListZdrEndpointsData( - client: QueryClient, - data: EndpointsListZdrEndpointsQueryData, -): EndpointsListZdrEndpointsQueryData | undefined { - const key = queryKeyEndpointsListZdrEndpoints(); - - return client.setQueryData(key, data); -} - -export function invalidateAllEndpointsListZdrEndpoints( - client: QueryClient, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: ["@openrouter/sdk", "Endpoints", "listZdrEndpoints"], - }); -} - -export function buildEndpointsListZdrEndpointsQuery( - client$: OpenRouterCore, - options?: RequestOptions, -): { - queryKey: QueryKey; - queryFn: ( - context: QueryFunctionContext, - ) => Promise; -} { - return { - queryKey: queryKeyEndpointsListZdrEndpoints(), - queryFn: async function endpointsListZdrEndpointsQueryFn( - ctx, - ): Promise { - const sig = combineSignals(ctx.signal, options?.fetchOptions?.signal); - const mergedOptions = { - ...options, - fetchOptions: { ...options?.fetchOptions, signal: sig }, - }; - - return unwrapAsync(endpointsListZdrEndpoints( - client$, - mergedOptions, - )); - }, - }; -} - -export function queryKeyEndpointsListZdrEndpoints(): QueryKey { - return ["@openrouter/sdk", "Endpoints", "listZdrEndpoints"]; -} diff --git a/src/react-query/generationsGetGeneration.ts b/src/react-query/generationsGetGeneration.ts deleted file mode 100644 index 16dcd467..00000000 --- a/src/react-query/generationsGetGeneration.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - InvalidateQueryFilters, - QueryClient, - QueryFunctionContext, - QueryKey, - useQuery, - UseQueryResult, - useSuspenseQuery, - UseSuspenseQueryResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { generationsGetGeneration } from "../funcs/generationsGetGeneration.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { - QueryHookOptions, - SuspenseQueryHookOptions, - TupleToPrefixes, -} from "./_types.js"; - -export type GenerationsGetGenerationQueryData = - operations.GetGenerationResponse; - -/** - * Get request & usage metadata for a generation - */ -export function useGenerationsGetGeneration( - request: operations.GetGenerationRequest, - options?: QueryHookOptions, -): UseQueryResult { - const client = useOpenRouterContext(); - return useQuery({ - ...buildGenerationsGetGenerationQuery( - client, - request, - options, - ), - ...options, - }); -} - -/** - * Get request & usage metadata for a generation - */ -export function useGenerationsGetGenerationSuspense( - request: operations.GetGenerationRequest, - options?: SuspenseQueryHookOptions, -): UseSuspenseQueryResult { - const client = useOpenRouterContext(); - return useSuspenseQuery({ - ...buildGenerationsGetGenerationQuery( - client, - request, - options, - ), - ...options, - }); -} - -export function prefetchGenerationsGetGeneration( - queryClient: QueryClient, - client$: OpenRouterCore, - request: operations.GetGenerationRequest, -): Promise { - return queryClient.prefetchQuery({ - ...buildGenerationsGetGenerationQuery( - client$, - request, - ), - }); -} - -export function setGenerationsGetGenerationData( - client: QueryClient, - queryKeyBase: [parameters: { id: string }], - data: GenerationsGetGenerationQueryData, -): GenerationsGetGenerationQueryData | undefined { - const key = queryKeyGenerationsGetGeneration(...queryKeyBase); - - return client.setQueryData(key, data); -} - -export function invalidateGenerationsGetGeneration( - client: QueryClient, - queryKeyBase: TupleToPrefixes<[parameters: { id: string }]>, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: [ - "@openrouter/sdk", - "Generations", - "getGeneration", - ...queryKeyBase, - ], - }); -} - -export function invalidateAllGenerationsGetGeneration( - client: QueryClient, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: ["@openrouter/sdk", "Generations", "getGeneration"], - }); -} - -export function buildGenerationsGetGenerationQuery( - client$: OpenRouterCore, - request: operations.GetGenerationRequest, - options?: RequestOptions, -): { - queryKey: QueryKey; - queryFn: ( - context: QueryFunctionContext, - ) => Promise; -} { - return { - queryKey: queryKeyGenerationsGetGeneration({ id: request.id }), - queryFn: async function generationsGetGenerationQueryFn( - ctx, - ): Promise { - const sig = combineSignals(ctx.signal, options?.fetchOptions?.signal); - const mergedOptions = { - ...options, - fetchOptions: { ...options?.fetchOptions, signal: sig }, - }; - - return unwrapAsync(generationsGetGeneration( - client$, - request, - mergedOptions, - )); - }, - }; -} - -export function queryKeyGenerationsGetGeneration( - parameters: { id: string }, -): QueryKey { - return ["@openrouter/sdk", "Generations", "getGeneration", parameters]; -} diff --git a/src/react-query/index.ts b/src/react-query/index.ts deleted file mode 100644 index ab2bb325..00000000 --- a/src/react-query/index.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -export { OpenRouterProvider, useOpenRouterContext } from "./_context.js"; -export * from "./_types.js"; - -export * from "./analyticsGetUserActivity.js"; -export * from "./apiKeysCreate.js"; -export * from "./apiKeysDelete.js"; -export * from "./apiKeysGet.js"; -export * from "./apiKeysGetCurrentKeyMetadata.js"; -export * from "./apiKeysList.js"; -export * from "./apiKeysUpdate.js"; -export * from "./betaResponsesSend.js"; -export * from "./chatSend.js"; -export * from "./completionsGenerate.js"; -export * from "./creditsCreateCoinbaseCharge.js"; -export * from "./creditsGetCredits.js"; -export * from "./embeddingsGenerate.js"; -export * from "./embeddingsListModels.js"; -export * from "./endpointsList.js"; -export * from "./endpointsListZdrEndpoints.js"; -export * from "./generationsGetGeneration.js"; -export * from "./modelsCount.js"; -export * from "./modelsList.js"; -export * from "./modelsListForUser.js"; -export * from "./oAuthCreateAuthCode.js"; -export * from "./oAuthExchangeAuthCodeForAPIKey.js"; -export * from "./parametersGetParameters.js"; -export * from "./providersList.js"; diff --git a/src/react-query/modelsCount.ts b/src/react-query/modelsCount.ts deleted file mode 100644 index 16de60d1..00000000 --- a/src/react-query/modelsCount.ts +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - InvalidateQueryFilters, - QueryClient, - QueryFunctionContext, - QueryKey, - useQuery, - UseQueryResult, - useSuspenseQuery, - UseSuspenseQueryResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { modelsCount } from "../funcs/modelsCount.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as models from "../models/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { QueryHookOptions, SuspenseQueryHookOptions } from "./_types.js"; - -export type ModelsCountQueryData = models.ModelsCountResponse; - -/** - * Get total count of available models - */ -export function useModelsCount( - options?: QueryHookOptions, -): UseQueryResult { - const client = useOpenRouterContext(); - return useQuery({ - ...buildModelsCountQuery( - client, - options, - ), - ...options, - }); -} - -/** - * Get total count of available models - */ -export function useModelsCountSuspense( - options?: SuspenseQueryHookOptions, -): UseSuspenseQueryResult { - const client = useOpenRouterContext(); - return useSuspenseQuery({ - ...buildModelsCountQuery( - client, - options, - ), - ...options, - }); -} - -export function prefetchModelsCount( - queryClient: QueryClient, - client$: OpenRouterCore, -): Promise { - return queryClient.prefetchQuery({ - ...buildModelsCountQuery( - client$, - ), - }); -} - -export function setModelsCountData( - client: QueryClient, - data: ModelsCountQueryData, -): ModelsCountQueryData | undefined { - const key = queryKeyModelsCount(); - - return client.setQueryData(key, data); -} - -export function invalidateAllModelsCount( - client: QueryClient, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: ["@openrouter/sdk", "Models", "count"], - }); -} - -export function buildModelsCountQuery( - client$: OpenRouterCore, - options?: RequestOptions, -): { - queryKey: QueryKey; - queryFn: (context: QueryFunctionContext) => Promise; -} { - return { - queryKey: queryKeyModelsCount(), - queryFn: async function modelsCountQueryFn( - ctx, - ): Promise { - const sig = combineSignals(ctx.signal, options?.fetchOptions?.signal); - const mergedOptions = { - ...options, - fetchOptions: { ...options?.fetchOptions, signal: sig }, - }; - - return unwrapAsync(modelsCount( - client$, - mergedOptions, - )); - }, - }; -} - -export function queryKeyModelsCount(): QueryKey { - return ["@openrouter/sdk", "Models", "count"]; -} diff --git a/src/react-query/modelsList.ts b/src/react-query/modelsList.ts deleted file mode 100644 index 98b423e3..00000000 --- a/src/react-query/modelsList.ts +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - InvalidateQueryFilters, - QueryClient, - QueryFunctionContext, - QueryKey, - useQuery, - UseQueryResult, - useSuspenseQuery, - UseSuspenseQueryResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { modelsList } from "../funcs/modelsList.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as models from "../models/index.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { - QueryHookOptions, - SuspenseQueryHookOptions, - TupleToPrefixes, -} from "./_types.js"; - -export type ModelsListQueryData = models.ModelsListResponse; - -/** - * List all models and their properties - */ -export function useModelsList( - request?: operations.GetModelsRequest | undefined, - options?: QueryHookOptions, -): UseQueryResult { - const client = useOpenRouterContext(); - return useQuery({ - ...buildModelsListQuery( - client, - request, - options, - ), - ...options, - }); -} - -/** - * List all models and their properties - */ -export function useModelsListSuspense( - request?: operations.GetModelsRequest | undefined, - options?: SuspenseQueryHookOptions, -): UseSuspenseQueryResult { - const client = useOpenRouterContext(); - return useSuspenseQuery({ - ...buildModelsListQuery( - client, - request, - options, - ), - ...options, - }); -} - -export function prefetchModelsList( - queryClient: QueryClient, - client$: OpenRouterCore, - request?: operations.GetModelsRequest | undefined, -): Promise { - return queryClient.prefetchQuery({ - ...buildModelsListQuery( - client$, - request, - ), - }); -} - -export function setModelsListData( - client: QueryClient, - queryKeyBase: [ - parameters: { - category?: string | undefined; - supportedParameters?: string | undefined; - }, - ], - data: ModelsListQueryData, -): ModelsListQueryData | undefined { - const key = queryKeyModelsList(...queryKeyBase); - - return client.setQueryData(key, data); -} - -export function invalidateModelsList( - client: QueryClient, - queryKeyBase: TupleToPrefixes< - [parameters: { - category?: string | undefined; - supportedParameters?: string | undefined; - }] - >, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: ["@openrouter/sdk", "Models", "list", ...queryKeyBase], - }); -} - -export function invalidateAllModelsList( - client: QueryClient, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: ["@openrouter/sdk", "Models", "list"], - }); -} - -export function buildModelsListQuery( - client$: OpenRouterCore, - request?: operations.GetModelsRequest | undefined, - options?: RequestOptions, -): { - queryKey: QueryKey; - queryFn: (context: QueryFunctionContext) => Promise; -} { - return { - queryKey: queryKeyModelsList({ - category: request?.category, - supportedParameters: request?.supportedParameters, - }), - queryFn: async function modelsListQueryFn( - ctx, - ): Promise { - const sig = combineSignals(ctx.signal, options?.fetchOptions?.signal); - const mergedOptions = { - ...options, - fetchOptions: { ...options?.fetchOptions, signal: sig }, - }; - - return unwrapAsync(modelsList( - client$, - request, - mergedOptions, - )); - }, - }; -} - -export function queryKeyModelsList( - parameters: { - category?: string | undefined; - supportedParameters?: string | undefined; - }, -): QueryKey { - return ["@openrouter/sdk", "Models", "list", parameters]; -} diff --git a/src/react-query/modelsListForUser.ts b/src/react-query/modelsListForUser.ts deleted file mode 100644 index 51a4d7e5..00000000 --- a/src/react-query/modelsListForUser.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - InvalidateQueryFilters, - QueryClient, - QueryFunctionContext, - QueryKey, - useQuery, - UseQueryResult, - useSuspenseQuery, - UseSuspenseQueryResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { modelsListForUser } from "../funcs/modelsListForUser.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as models from "../models/index.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { QueryHookOptions, SuspenseQueryHookOptions } from "./_types.js"; - -export type ModelsListForUserQueryData = models.ModelsListResponse; - -/** - * List models filtered by user provider preferences - */ -export function useModelsListForUser( - security: operations.ListModelsUserSecurity, - options?: QueryHookOptions, -): UseQueryResult { - const client = useOpenRouterContext(); - return useQuery({ - ...buildModelsListForUserQuery( - client, - security, - options, - ), - ...options, - }); -} - -/** - * List models filtered by user provider preferences - */ -export function useModelsListForUserSuspense( - security: operations.ListModelsUserSecurity, - options?: SuspenseQueryHookOptions, -): UseSuspenseQueryResult { - const client = useOpenRouterContext(); - return useSuspenseQuery({ - ...buildModelsListForUserQuery( - client, - security, - options, - ), - ...options, - }); -} - -export function prefetchModelsListForUser( - queryClient: QueryClient, - client$: OpenRouterCore, - security: operations.ListModelsUserSecurity, -): Promise { - return queryClient.prefetchQuery({ - ...buildModelsListForUserQuery( - client$, - security, - ), - }); -} - -export function setModelsListForUserData( - client: QueryClient, - data: ModelsListForUserQueryData, -): ModelsListForUserQueryData | undefined { - const key = queryKeyModelsListForUser(); - - return client.setQueryData(key, data); -} - -export function invalidateAllModelsListForUser( - client: QueryClient, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: ["@openrouter/sdk", "Models", "listForUser"], - }); -} - -export function buildModelsListForUserQuery( - client$: OpenRouterCore, - security: operations.ListModelsUserSecurity, - options?: RequestOptions, -): { - queryKey: QueryKey; - queryFn: ( - context: QueryFunctionContext, - ) => Promise; -} { - return { - queryKey: queryKeyModelsListForUser(), - queryFn: async function modelsListForUserQueryFn( - ctx, - ): Promise { - const sig = combineSignals(ctx.signal, options?.fetchOptions?.signal); - const mergedOptions = { - ...options, - fetchOptions: { ...options?.fetchOptions, signal: sig }, - }; - - return unwrapAsync(modelsListForUser( - client$, - security, - mergedOptions, - )); - }, - }; -} - -export function queryKeyModelsListForUser(): QueryKey { - return ["@openrouter/sdk", "Models", "listForUser"]; -} diff --git a/src/react-query/oAuthCreateAuthCode.ts b/src/react-query/oAuthCreateAuthCode.ts deleted file mode 100644 index 8af94bce..00000000 --- a/src/react-query/oAuthCreateAuthCode.ts +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - MutationKey, - useMutation, - UseMutationResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { oAuthCreateAuthCode } from "../funcs/oAuthCreateAuthCode.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { MutationHookOptions } from "./_types.js"; - -export type OAuthCreateAuthCodeMutationVariables = { - request: operations.CreateAuthKeysCodeRequest; - options?: RequestOptions; -}; - -export type OAuthCreateAuthCodeMutationData = - operations.CreateAuthKeysCodeResponse; - -/** - * Create authorization code - * - * @remarks - * Create an authorization code for the PKCE flow to generate a user-controlled API key - */ -export function useOAuthCreateAuthCodeMutation( - options?: MutationHookOptions< - OAuthCreateAuthCodeMutationData, - Error, - OAuthCreateAuthCodeMutationVariables - >, -): UseMutationResult< - OAuthCreateAuthCodeMutationData, - Error, - OAuthCreateAuthCodeMutationVariables -> { - const client = useOpenRouterContext(); - return useMutation({ - ...buildOAuthCreateAuthCodeMutation(client, options), - ...options, - }); -} - -export function mutationKeyOAuthCreateAuthCode(): MutationKey { - return ["@openrouter/sdk", "OAuth", "createAuthCode"]; -} - -export function buildOAuthCreateAuthCodeMutation( - client$: OpenRouterCore, - hookOptions?: RequestOptions, -): { - mutationKey: MutationKey; - mutationFn: ( - variables: OAuthCreateAuthCodeMutationVariables, - ) => Promise; -} { - return { - mutationKey: mutationKeyOAuthCreateAuthCode(), - mutationFn: function oAuthCreateAuthCodeMutationFn({ - request, - options, - }): Promise { - const mergedOptions = { - ...hookOptions, - ...options, - fetchOptions: { - ...hookOptions?.fetchOptions, - ...options?.fetchOptions, - signal: combineSignals( - hookOptions?.fetchOptions?.signal, - options?.fetchOptions?.signal, - ), - }, - }; - return unwrapAsync(oAuthCreateAuthCode( - client$, - request, - mergedOptions, - )); - }, - }; -} diff --git a/src/react-query/oAuthExchangeAuthCodeForAPIKey.ts b/src/react-query/oAuthExchangeAuthCodeForAPIKey.ts deleted file mode 100644 index b974c1bc..00000000 --- a/src/react-query/oAuthExchangeAuthCodeForAPIKey.ts +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - MutationKey, - useMutation, - UseMutationResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { oAuthExchangeAuthCodeForAPIKey } from "../funcs/oAuthExchangeAuthCodeForAPIKey.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { MutationHookOptions } from "./_types.js"; - -export type OAuthExchangeAuthCodeForAPIKeyMutationVariables = { - request: operations.ExchangeAuthCodeForAPIKeyRequest; - options?: RequestOptions; -}; - -export type OAuthExchangeAuthCodeForAPIKeyMutationData = - operations.ExchangeAuthCodeForAPIKeyResponse; - -/** - * Exchange authorization code for API key - * - * @remarks - * Exchange an authorization code from the PKCE flow for a user-controlled API key - */ -export function useOAuthExchangeAuthCodeForAPIKeyMutation( - options?: MutationHookOptions< - OAuthExchangeAuthCodeForAPIKeyMutationData, - Error, - OAuthExchangeAuthCodeForAPIKeyMutationVariables - >, -): UseMutationResult< - OAuthExchangeAuthCodeForAPIKeyMutationData, - Error, - OAuthExchangeAuthCodeForAPIKeyMutationVariables -> { - const client = useOpenRouterContext(); - return useMutation({ - ...buildOAuthExchangeAuthCodeForAPIKeyMutation(client, options), - ...options, - }); -} - -export function mutationKeyOAuthExchangeAuthCodeForAPIKey(): MutationKey { - return ["@openrouter/sdk", "OAuth", "exchangeAuthCodeForAPIKey"]; -} - -export function buildOAuthExchangeAuthCodeForAPIKeyMutation( - client$: OpenRouterCore, - hookOptions?: RequestOptions, -): { - mutationKey: MutationKey; - mutationFn: ( - variables: OAuthExchangeAuthCodeForAPIKeyMutationVariables, - ) => Promise; -} { - return { - mutationKey: mutationKeyOAuthExchangeAuthCodeForAPIKey(), - mutationFn: function oAuthExchangeAuthCodeForAPIKeyMutationFn({ - request, - options, - }): Promise { - const mergedOptions = { - ...hookOptions, - ...options, - fetchOptions: { - ...hookOptions?.fetchOptions, - ...options?.fetchOptions, - signal: combineSignals( - hookOptions?.fetchOptions?.signal, - options?.fetchOptions?.signal, - ), - }, - }; - return unwrapAsync(oAuthExchangeAuthCodeForAPIKey( - client$, - request, - mergedOptions, - )); - }, - }; -} diff --git a/src/react-query/parametersGetParameters.ts b/src/react-query/parametersGetParameters.ts deleted file mode 100644 index c0dd28c2..00000000 --- a/src/react-query/parametersGetParameters.ts +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - InvalidateQueryFilters, - QueryClient, - QueryFunctionContext, - QueryKey, - useQuery, - UseQueryResult, - useSuspenseQuery, - UseSuspenseQueryResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { parametersGetParameters } from "../funcs/parametersGetParameters.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { - QueryHookOptions, - SuspenseQueryHookOptions, - TupleToPrefixes, -} from "./_types.js"; - -export type ParametersGetParametersQueryData = operations.GetParametersResponse; - -/** - * Get a model's supported parameters and data about which are most popular - */ -export function useParametersGetParameters( - security: operations.GetParametersSecurity, - request: operations.GetParametersRequest, - options?: QueryHookOptions, -): UseQueryResult { - const client = useOpenRouterContext(); - return useQuery({ - ...buildParametersGetParametersQuery( - client, - security, - request, - options, - ), - ...options, - }); -} - -/** - * Get a model's supported parameters and data about which are most popular - */ -export function useParametersGetParametersSuspense( - security: operations.GetParametersSecurity, - request: operations.GetParametersRequest, - options?: SuspenseQueryHookOptions, -): UseSuspenseQueryResult { - const client = useOpenRouterContext(); - return useSuspenseQuery({ - ...buildParametersGetParametersQuery( - client, - security, - request, - options, - ), - ...options, - }); -} - -export function prefetchParametersGetParameters( - queryClient: QueryClient, - client$: OpenRouterCore, - security: operations.GetParametersSecurity, - request: operations.GetParametersRequest, -): Promise { - return queryClient.prefetchQuery({ - ...buildParametersGetParametersQuery( - client$, - security, - request, - ), - }); -} - -export function setParametersGetParametersData( - client: QueryClient, - queryKeyBase: [ - author: string, - slug: string, - parameters: { provider?: operations.GetParametersProvider | undefined }, - ], - data: ParametersGetParametersQueryData, -): ParametersGetParametersQueryData | undefined { - const key = queryKeyParametersGetParameters(...queryKeyBase); - - return client.setQueryData(key, data); -} - -export function invalidateParametersGetParameters( - client: QueryClient, - queryKeyBase: TupleToPrefixes< - [ - author: string, - slug: string, - parameters: { provider?: operations.GetParametersProvider | undefined }, - ] - >, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: [ - "@openrouter/sdk", - "Parameters", - "getParameters", - ...queryKeyBase, - ], - }); -} - -export function invalidateAllParametersGetParameters( - client: QueryClient, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: ["@openrouter/sdk", "Parameters", "getParameters"], - }); -} - -export function buildParametersGetParametersQuery( - client$: OpenRouterCore, - security: operations.GetParametersSecurity, - request: operations.GetParametersRequest, - options?: RequestOptions, -): { - queryKey: QueryKey; - queryFn: ( - context: QueryFunctionContext, - ) => Promise; -} { - return { - queryKey: queryKeyParametersGetParameters(request.author, request.slug, { - provider: request.provider, - }), - queryFn: async function parametersGetParametersQueryFn( - ctx, - ): Promise { - const sig = combineSignals(ctx.signal, options?.fetchOptions?.signal); - const mergedOptions = { - ...options, - fetchOptions: { ...options?.fetchOptions, signal: sig }, - }; - - return unwrapAsync(parametersGetParameters( - client$, - security, - request, - mergedOptions, - )); - }, - }; -} - -export function queryKeyParametersGetParameters( - author: string, - slug: string, - parameters: { provider?: operations.GetParametersProvider | undefined }, -): QueryKey { - return [ - "@openrouter/sdk", - "Parameters", - "getParameters", - author, - slug, - parameters, - ]; -} diff --git a/src/react-query/providersList.ts b/src/react-query/providersList.ts deleted file mode 100644 index a495e66a..00000000 --- a/src/react-query/providersList.ts +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - */ - -import { - InvalidateQueryFilters, - QueryClient, - QueryFunctionContext, - QueryKey, - useQuery, - UseQueryResult, - useSuspenseQuery, - UseSuspenseQueryResult, -} from "@tanstack/react-query"; -import { OpenRouterCore } from "../core.js"; -import { providersList } from "../funcs/providersList.js"; -import { combineSignals } from "../lib/primitives.js"; -import { RequestOptions } from "../lib/sdks.js"; -import * as operations from "../models/operations/index.js"; -import { unwrapAsync } from "../types/fp.js"; -import { useOpenRouterContext } from "./_context.js"; -import { QueryHookOptions, SuspenseQueryHookOptions } from "./_types.js"; - -export type ProvidersListQueryData = operations.ListProvidersResponse; - -/** - * List all providers - */ -export function useProvidersList( - options?: QueryHookOptions, -): UseQueryResult { - const client = useOpenRouterContext(); - return useQuery({ - ...buildProvidersListQuery( - client, - options, - ), - ...options, - }); -} - -/** - * List all providers - */ -export function useProvidersListSuspense( - options?: SuspenseQueryHookOptions, -): UseSuspenseQueryResult { - const client = useOpenRouterContext(); - return useSuspenseQuery({ - ...buildProvidersListQuery( - client, - options, - ), - ...options, - }); -} - -export function prefetchProvidersList( - queryClient: QueryClient, - client$: OpenRouterCore, -): Promise { - return queryClient.prefetchQuery({ - ...buildProvidersListQuery( - client$, - ), - }); -} - -export function setProvidersListData( - client: QueryClient, - data: ProvidersListQueryData, -): ProvidersListQueryData | undefined { - const key = queryKeyProvidersList(); - - return client.setQueryData(key, data); -} - -export function invalidateAllProvidersList( - client: QueryClient, - filters?: Omit, -): Promise { - return client.invalidateQueries({ - ...filters, - queryKey: ["@openrouter/sdk", "Providers", "list"], - }); -} - -export function buildProvidersListQuery( - client$: OpenRouterCore, - options?: RequestOptions, -): { - queryKey: QueryKey; - queryFn: (context: QueryFunctionContext) => Promise; -} { - return { - queryKey: queryKeyProvidersList(), - queryFn: async function providersListQueryFn( - ctx, - ): Promise { - const sig = combineSignals(ctx.signal, options?.fetchOptions?.signal); - const mergedOptions = { - ...options, - fetchOptions: { ...options?.fetchOptions, signal: sig }, - }; - - return unwrapAsync(providersList( - client$, - mergedOptions, - )); - }, - }; -} - -export function queryKeyProvidersList(): QueryKey { - return ["@openrouter/sdk", "Providers", "list"]; -}