diff --git a/README.md b/README.md index 5cc538a..2d570bc 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,17 @@ [![npm version](https://badge.fury.io/js/%40lazydynamics%2Frxinfer-client.svg)](https://badge.fury.io/js/%40lazydynamics%2Frxinfer-client) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) -A TypeScript SDK for interacting with RxInferServer, providing type-safe access to all server endpoints and features. +A TypeScript client for interacting with RxInferServer, providing type-safe access to its API endpoints. + +## About RxInferServer + +RxInferServer is a Julia-based server that provides an API for performing probabilistic inference using the RxInfer.jl package. This client library allows you to interact with RxInferServer from TypeScript/JavaScript applications. + +### Key Features of RxInferServer +- Probabilistic inference using message passing +- Support for various probabilistic models +- RESTful API interface +- Real-time inference capabilities ## Installation @@ -11,20 +21,74 @@ A TypeScript SDK for interacting with RxInferServer, providing type-safe access npm install @lazydynamics/rxinfer-client ``` -## Documentation +## Usage + +```typescript +import { RxInferClient, pingServer } from '@lazydynamics/rxinfer-client'; -For detailed documentation and getting started guide, please visit our [official documentation](https://lazydynamics.github.io/RxInferClient.js/). +// Create a client instance +const client = await RxInferClient.create(); -The documentation includes: -- Getting Started Guide -- API Reference -- Examples and Use Cases -- Best Practices -- Troubleshooting +// Use the client to interact with RxInferServer +const response = await pingServer({ client }); +console.log(response.data); // { status: 'ok' } +``` ## Development -For information about developing this package, please see our [Contributing Guide](CONTRIBUTING.md). +### Prerequisites +- Node.js (LTS version recommended) +- RxInferServer running locally or accessible via network + +### Setting up RxInferServer +1. Clone the RxInferServer repository: + ```bash + git clone https://github.com/lazydynamics/RxInferServer.git + cd RxInferServer + ``` + +2. Build and start the server: + ```bash + make docker + make dev + ``` + + This will start RxInferServer on `http://localhost:8000`. + +### Building the Client +1. Install dependencies: + ```bash + npm install + ``` + +2. Generate TypeScript client from OpenAPI specification: + ```bash + npm run generate + ``` + +3. Build the package: + ```bash + npm run build + ``` + +### Running Tests +```bash +npm test +``` + +Note: Tests require RxInferServer to be running locally. + +## Documentation + +Generate and view documentation: +```bash +npm run docs +npm run docs:serve +``` + +## Contributing + +See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to this project. ## License diff --git a/openapi-ts.config.ts b/openapi-ts.config.ts index 76e2cab..b37209b 100644 --- a/openapi-ts.config.ts +++ b/openapi-ts.config.ts @@ -1,7 +1,16 @@ +import { defaultPlugins } from '@hey-api/openapi-ts'; import { defineConfig } from '@hey-api/openapi-ts'; export default defineConfig({ - input: 'https://raw.githubusercontent.com/lazydynamics/RxInferServer/refs/heads/main/openapi/spec.yaml', - output: 'src/client', - plugins: ['@hey-api/client-fetch'], + input: 'https://raw.githubusercontent.com/lazydynamics/RxInferServer/refs/heads/main/openapi/spec.yaml', + output: 'src/client', + plugins: [ + ...defaultPlugins, + '@hey-api/client-fetch', + 'zod', + { + name: '@hey-api/sdk', + validator: true, + } + ], }); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ece39a9..a704ccb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MIT", "dependencies": { "@hey-api/client-fetch": "^0.10.0", - "axios": "^1.6.7" + "zod": "^3.24.2" }, "devDependencies": { "@hey-api/openapi-ts": "^0.66.4", @@ -1733,23 +1733,6 @@ "dev": true, "license": "MIT" }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "license": "MIT" - }, - "node_modules/axios": { - "version": "1.8.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.8.4.tgz", - "integrity": "sha512-eBSYY4Y68NNlHbHBMdeDmKNtDgXWhQsJcGqzO3iLUM0GraQFSS9cVgPX5I9b3lbdFKyYoAEGAZF1DwhTaljNAw==", - "license": "MIT", - "dependencies": { - "follow-redirects": "^1.15.6", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/babel-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.7.0.tgz", @@ -1987,19 +1970,6 @@ } } }, - "node_modules/call-bind-apply-helpers": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", - "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "function-bind": "^1.1.2" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -2177,18 +2147,6 @@ "dev": true, "license": "MIT" }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "license": "MIT", - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -2304,15 +2262,6 @@ "integrity": "sha512-mEQCMmwJu317oSz8CwdIOdwf3xMif1ttiM8LTufzc3g6kR+9Pe236twL8j3IYT1F7GfRgGcW6MWxzZjLIkuHIg==", "license": "MIT" }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "license": "MIT", - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/destr": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/destr/-/destr-2.0.5.tgz", @@ -2351,20 +2300,6 @@ "url": "https://dotenvx.com" } }, - "node_modules/dunder-proto": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", - "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", - "license": "MIT", - "dependencies": { - "call-bind-apply-helpers": "^1.0.1", - "es-errors": "^1.3.0", - "gopd": "^1.2.0" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/ejs": { "version": "3.1.10", "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.10.tgz", @@ -2431,51 +2366,6 @@ "is-arrayish": "^0.2.1" } }, - "node_modules/es-define-property": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", - "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/es-errors": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", - "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/es-object-atoms": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", - "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/es-set-tostringtag": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", - "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.6", - "has-tostringtag": "^1.0.2", - "hasown": "^2.0.2" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/esbuild": { "version": "0.25.2", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.2.tgz", @@ -2668,41 +2558,6 @@ "node": ">=8" } }, - "node_modules/follow-redirects": { - "version": "1.15.9", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", - "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "license": "MIT", - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, - "node_modules/form-data": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz", - "integrity": "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==", - "license": "MIT", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "es-set-tostringtag": "^2.1.0", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/fs-minipass": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", @@ -2753,6 +2608,7 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "dev": true, "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" @@ -2778,30 +2634,6 @@ "node": "6.* || 8.* || >= 10.*" } }, - "node_modules/get-intrinsic": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", - "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", - "license": "MIT", - "dependencies": { - "call-bind-apply-helpers": "^1.0.2", - "es-define-property": "^1.0.1", - "es-errors": "^1.3.0", - "es-object-atoms": "^1.1.1", - "function-bind": "^1.1.2", - "get-proto": "^1.0.1", - "gopd": "^1.2.0", - "has-symbols": "^1.1.0", - "hasown": "^2.0.2", - "math-intrinsics": "^1.1.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/get-package-type": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz", @@ -2812,19 +2644,6 @@ "node": ">=8.0.0" } }, - "node_modules/get-proto": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", - "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", - "license": "MIT", - "dependencies": { - "dunder-proto": "^1.0.1", - "es-object-atoms": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/get-stream": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", @@ -2918,18 +2737,6 @@ "node": ">=4" } }, - "node_modules/gopd": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", - "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", @@ -2968,37 +2775,11 @@ "node": ">=8" } }, - "node_modules/has-symbols": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", - "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-tostringtag": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", - "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", - "license": "MIT", - "dependencies": { - "has-symbols": "^1.0.3" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/hasown": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "dev": true, "license": "MIT", "dependencies": { "function-bind": "^1.1.2" @@ -4075,15 +3856,6 @@ "markdown-it": "bin/markdown-it.mjs" } }, - "node_modules/math-intrinsics": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", - "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - } - }, "node_modules/mdurl": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.0.0.tgz", @@ -4112,27 +3884,6 @@ "node": ">=8.6" } }, - "node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "license": "MIT", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, "node_modules/mimic-fn": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", @@ -4578,12 +4329,6 @@ "node": ">= 6" } }, - "node_modules/proxy-from-env": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", - "license": "MIT" - }, "node_modules/punycode.js": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz", @@ -5341,6 +5086,15 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/zod": { + "version": "3.24.2", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.24.2.tgz", + "integrity": "sha512-lY7CDW43ECgW9u1TcT3IoXHflywfVqDYze4waEz812jR/bZ8FHDsl7pFQoSZTz5N+2NqRXs8GBwnAwo3ZNxqhQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } } } diff --git a/package.json b/package.json index 077434e..d2ed1ac 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ }, "dependencies": { "@hey-api/client-fetch": "^0.10.0", - "axios": "^1.6.7" + "zod": "^3.24.2" }, "devDependencies": { "@hey-api/openapi-ts": "^0.66.4", diff --git a/scripts/wait-for-server.js b/scripts/wait-for-server.js index 1b9374a..7a2fb41 100644 --- a/scripts/wait-for-server.js +++ b/scripts/wait-for-server.js @@ -1,6 +1,5 @@ #!/usr/bin/env node -const axios = require('axios'); const { setTimeout } = require('timers/promises'); const isRunningInCI = () => { @@ -29,10 +28,13 @@ const waitForServer = async (timeout = null, retryInterval = null) => { while (Date.now() - startTime < timeout * 1000) { try { - const response = await axios.get('http://localhost:8000/v1/ping'); - if (response.data.status === 'ok') { - console.log("RxInferServer is available!"); - return true; + const response = await fetch('http://localhost:8000/v1/ping'); + if (response.ok) { + const data = await response.json(); + if (data.status === 'ok') { + console.log("RxInferServer is available!"); + return true; + } } } catch (error) { // Ignore errors and retry diff --git a/src/client/sdk.gen.ts b/src/client/sdk.gen.ts index 58811dc..69666d8 100644 --- a/src/client/sdk.gen.ts +++ b/src/client/sdk.gen.ts @@ -2,6 +2,7 @@ import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch'; import type { GetServerInfoData, GetServerInfoResponse, GetServerInfoError, PingServerData, PingServerResponse, TokenGenerateData, TokenGenerateResponse2, TokenGenerateError, TokenRolesData, TokenRolesResponse2, TokenRolesError, GetAvailableModelsData, GetAvailableModelsResponse, GetAvailableModelsError, GetAvailableModelData, GetAvailableModelResponse, GetAvailableModelError, CreateModelInstanceData, CreateModelInstanceResponse2, CreateModelInstanceError, GetModelInstancesData, GetModelInstancesResponse, GetModelInstancesError, DeleteModelInstanceData, DeleteModelInstanceResponse, DeleteModelInstanceError, GetModelInstanceData, GetModelInstanceResponse, GetModelInstanceError, GetModelInstanceStateData, GetModelInstanceStateResponse, GetModelInstanceStateError, GetModelInstanceParametersData, GetModelInstanceParametersResponse, GetModelInstanceParametersError, RunInferenceData, RunInferenceResponse, RunInferenceError, RunLearningData, RunLearningResponse, RunLearningError, CreateEpisodeData, CreateEpisodeResponse, CreateEpisodeError, GetEpisodesData, GetEpisodesResponse, GetEpisodesError, DeleteEpisodeData, DeleteEpisodeResponse, DeleteEpisodeError, GetEpisodeInfoData, GetEpisodeInfoResponse, GetEpisodeInfoError, AttachEventsToEpisodeData, AttachEventsToEpisodeResponse, AttachEventsToEpisodeError, WipeEpisodeData, WipeEpisodeResponse, WipeEpisodeError, AttachMetadataToEventData, AttachMetadataToEventResponse, AttachMetadataToEventError } from './types.gen'; +import { zGetServerInfoResponse, zPingServerResponse, zTokenGenerateResponse2, zTokenRolesResponse2, zGetAvailableModelsResponse, zGetAvailableModelResponse, zCreateModelInstanceResponse2, zGetModelInstancesResponse, zDeleteModelInstanceResponse, zGetModelInstanceResponse, zGetModelInstanceStateResponse, zGetModelInstanceParametersResponse, zRunInferenceResponse, zRunLearningResponse, zCreateEpisodeResponse, zGetEpisodesResponse, zDeleteEpisodeResponse, zGetEpisodeInfoResponse, zAttachEventsToEpisodeResponse, zWipeEpisodeResponse, zAttachMetadataToEventResponse } from './zod.gen'; import { client as _heyApiClient } from './client.gen'; export type Options = ClientOptions & { @@ -30,6 +31,9 @@ export const getServerInfo = (options?: Op type: 'http' } ], + responseValidator: async (data) => { + return await zGetServerInfoResponse.parseAsync(data); + }, url: '/info', ...options }); @@ -41,6 +45,9 @@ export const getServerInfo = (options?: Op */ export const pingServer = (options?: Options) => { return (options?.client ?? _heyApiClient).get({ + responseValidator: async (data) => { + return await zPingServerResponse.parseAsync(data); + }, url: '/ping', ...options }); @@ -52,6 +59,9 @@ export const pingServer = (options?: Optio */ export const tokenGenerate = (options?: Options) => { return (options?.client ?? _heyApiClient).post({ + responseValidator: async (data) => { + return await zTokenGenerateResponse2.parseAsync(data); + }, url: '/token/generate', ...options }); @@ -69,6 +79,9 @@ export const tokenRoles = (options?: Optio type: 'http' } ], + responseValidator: async (data) => { + return await zTokenRolesResponse2.parseAsync(data); + }, url: '/token/roles', ...options }); @@ -91,6 +104,9 @@ export const getAvailableModels = (options type: 'http' } ], + responseValidator: async (data) => { + return await zGetAvailableModelsResponse.parseAsync(data); + }, url: '/models/available', ...options }); @@ -108,6 +124,9 @@ export const getAvailableModel = (options: type: 'http' } ], + responseValidator: async (data) => { + return await zGetAvailableModelResponse.parseAsync(data); + }, url: '/models/available/{model_name}', ...options }); @@ -125,6 +144,9 @@ export const createModelInstance = (option type: 'http' } ], + responseValidator: async (data) => { + return await zCreateModelInstanceResponse2.parseAsync(data); + }, url: '/models/create-instance', ...options, headers: { @@ -146,6 +168,9 @@ export const getModelInstances = (options? type: 'http' } ], + responseValidator: async (data) => { + return await zGetModelInstancesResponse.parseAsync(data); + }, url: '/models/instances', ...options }); @@ -163,6 +188,9 @@ export const deleteModelInstance = (option type: 'http' } ], + responseValidator: async (data) => { + return await zDeleteModelInstanceResponse.parseAsync(data); + }, url: '/models/i/{instance_id}', ...options }); @@ -180,6 +208,9 @@ export const getModelInstance = (options: type: 'http' } ], + responseValidator: async (data) => { + return await zGetModelInstanceResponse.parseAsync(data); + }, url: '/models/i/{instance_id}', ...options }); @@ -197,6 +228,9 @@ export const getModelInstanceState = (opti type: 'http' } ], + responseValidator: async (data) => { + return await zGetModelInstanceStateResponse.parseAsync(data); + }, url: '/models/i/{instance_id}/state', ...options }); @@ -214,6 +248,9 @@ export const getModelInstanceParameters = type: 'http' } ], + responseValidator: async (data) => { + return await zGetModelInstanceParametersResponse.parseAsync(data); + }, url: '/models/i/{instance_id}/parameters', ...options }); @@ -231,6 +268,9 @@ export const runInference = (options: Opti type: 'http' } ], + responseValidator: async (data) => { + return await zRunInferenceResponse.parseAsync(data); + }, url: '/models/i/{instance_id}/infer', ...options, headers: { @@ -252,6 +292,9 @@ export const runLearning = (options: Optio type: 'http' } ], + responseValidator: async (data) => { + return await zRunLearningResponse.parseAsync(data); + }, url: '/models/i/{instance_id}/learn', ...options, headers: { @@ -276,6 +319,9 @@ export const createEpisode = (options: Opt type: 'http' } ], + responseValidator: async (data) => { + return await zCreateEpisodeResponse.parseAsync(data); + }, url: '/models/i/{instance_id}/create-episode', ...options, headers: { @@ -297,6 +343,9 @@ export const getEpisodes = (options: Optio type: 'http' } ], + responseValidator: async (data) => { + return await zGetEpisodesResponse.parseAsync(data); + }, url: '/models/i/{instance_id}/episodes', ...options }); @@ -317,6 +366,9 @@ export const deleteEpisode = (options: Opt type: 'http' } ], + responseValidator: async (data) => { + return await zDeleteEpisodeResponse.parseAsync(data); + }, url: '/models/i/{instance_id}/episodes/{episode_name}', ...options }); @@ -334,6 +386,9 @@ export const getEpisodeInfo = (options: Op type: 'http' } ], + responseValidator: async (data) => { + return await zGetEpisodeInfoResponse.parseAsync(data); + }, url: '/models/i/{instance_id}/episodes/{episode_name}', ...options }); @@ -351,6 +406,9 @@ export const attachEventsToEpisode = (opti type: 'http' } ], + responseValidator: async (data) => { + return await zAttachEventsToEpisodeResponse.parseAsync(data); + }, url: '/models/i/{instance_id}/episodes/{episode_name}/attach-events', ...options, headers: { @@ -372,6 +430,9 @@ export const wipeEpisode = (options: Optio type: 'http' } ], + responseValidator: async (data) => { + return await zWipeEpisodeResponse.parseAsync(data); + }, url: '/models/i/{instance_id}/episodes/{episode_name}/wipe', ...options }); @@ -389,6 +450,9 @@ export const attachMetadataToEvent = (opti type: 'http' } ], + responseValidator: async (data) => { + return await zAttachMetadataToEventResponse.parseAsync(data); + }, url: '/models/i/{instance_id}/episodes/{episode_name}/events/{event_id}/attach-metadata', ...options, headers: { diff --git a/src/client/zod.gen.ts b/src/client/zod.gen.ts new file mode 100644 index 0000000..f31f014 --- /dev/null +++ b/src/client/zod.gen.ts @@ -0,0 +1,172 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import { z } from 'zod'; + +export const zSuccessResponse = z.object({ + message: z.string() +}); + +export const zErrorResponse = z.object({ + error: z.string(), + message: z.string().optional() +}); + +export const zNotFoundResponse = z.object({ + error: z.enum([ + 'Not Found' + ]), + message: z.string() +}); + +export const zUnauthorizedResponse = z.object({ + error: z.enum([ + 'Unauthorized' + ]), + message: z.string() +}); + +export const zPingResponse = z.object({ + status: z.string().default('ok') +}); + +export const zServerInfo = z.object({ + rxinfer_version: z.string(), + server_version: z.string(), + server_edition: z.string(), + julia_version: z.string(), + api_version: z.string().default('v1') +}); + +export const zTokenGenerateResponse = z.object({ + token: z.string() +}); + +export const zTokenRolesResponse = z.object({ + roles: z.array(z.string()) +}); + +export const zAvailableModel = z.object({ + details: z.object({ + name: z.string().optional(), + description: z.string().optional(), + author: z.string().optional(), + roles: z.array(z.string()).optional() + }), + config: z.object({}) +}); + +export const zCreateModelInstanceRequest = z.object({ + model_name: z.string(), + arguments: z.object({}).optional(), + description: z.string().max(128).optional() +}); + +export const zCreateModelInstanceResponse = z.object({ + instance_id: z.string().uuid() +}); + +export const zModelInstance = z.object({ + instance_id: z.string().uuid(), + model_name: z.string(), + created_at: z.string().datetime(), + description: z.string(), + arguments: z.object({}), + current_episode: z.string() +}); + +export const zDeleteModelInstanceRequest = z.object({ + instance_id: z.string().uuid() +}); + +export const zModelInstanceState = z.object({ + state: z.object({}) +}); + +export const zModelInstanceParameters = z.object({ + parameters: z.object({}) +}); + +export const zInferRequest = z.object({ + data: z.object({}), + timestamp: z.string().datetime().optional(), + episode_name: z.string().optional().default('default') +}); + +export const zInferResponse = z.object({ + event_id: z.coerce.bigint(), + results: z.object({}), + errors: z.array(zErrorResponse) +}); + +export const zLearnRequest = z.object({ + episodes: z.array(z.string()).default(['default']) +}); + +export const zLearnResponse = z.object({ + learned_parameters: z.object({}) +}); + +export const zCreateEpisodeRequest = z.object({ + name: z.string() +}); + +export const zEpisodeInfo = z.object({ + instance_id: z.string().uuid(), + episode_name: z.string(), + created_at: z.string().datetime(), + events: z.array(z.object({})) +}); + +export const zAttachEventsToEpisodeRequest = z.object({ + events: z.array(z.object({ + timestamp: z.string().datetime().optional(), + data: z.object({}).optional(), + metadata: z.object({}).optional() + })) +}); + +export const zAttachMetadataToEventRequest = z.object({ + metadata: z.object({}) +}); + +export const zGetServerInfoResponse = zServerInfo; + +export const zPingServerResponse = zPingResponse; + +export const zTokenGenerateResponse2 = zTokenGenerateResponse; + +export const zTokenRolesResponse2 = zTokenRolesResponse; + +export const zGetAvailableModelsResponse = z.array(zAvailableModel); + +export const zGetAvailableModelResponse = zAvailableModel; + +export const zCreateModelInstanceResponse2 = zCreateModelInstanceResponse; + +export const zGetModelInstancesResponse = z.array(zModelInstance); + +export const zDeleteModelInstanceResponse = zSuccessResponse; + +export const zGetModelInstanceResponse = zModelInstance; + +export const zGetModelInstanceStateResponse = zModelInstanceState; + +export const zGetModelInstanceParametersResponse = zModelInstanceParameters; + +export const zRunInferenceResponse = zInferResponse; + +export const zRunLearningResponse = zLearnResponse; + +export const zCreateEpisodeResponse = zEpisodeInfo; + +export const zGetEpisodesResponse = z.array(zEpisodeInfo); + +export const zDeleteEpisodeResponse = zSuccessResponse; + +export const zGetEpisodeInfoResponse = zEpisodeInfo; + +export const zAttachEventsToEpisodeResponse = zSuccessResponse; + +export const zWipeEpisodeResponse = zSuccessResponse; + +export const zAttachMetadataToEventResponse = zSuccessResponse; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 07133b1..f2a08f7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,17 +3,32 @@ * @packageDocumentation */ import { Client } from '@hey-api/client-fetch'; -import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from '@hey-api/client-fetch'; +import { createClient } from '@hey-api/client-fetch'; import { tokenGenerate } from './client/sdk.gen'; export * from './client/index'; export { Client } from '@hey-api/client-fetch'; +/** + * RxInferClient provides a factory for creating API clients to interact with the RxInfer service. + * This class cannot be instantiated directly - use the static create() method instead. + */ export class RxInferClient { + /** + * Private constructor to prevent direct instantiation. + * @throws Error Always throws an error directing users to use the create() method. + */ constructor() { throw new Error('Use RxInferClient.create() to create a new client'); } + /** + * Creates a new API client for the RxInfer service. + * @param baseUrl - The base URL of the RxInfer API. Defaults to 'http://localhost:8000/v1'. + * @param apiKey - Optional API key. If not provided, a temporary token will be generated. + * @returns A Promise that resolves to a configured Client instance. + * @throws Error If no API key is provided and token generation fails. + */ static async create(baseUrl: string = 'http://localhost:8000/v1', apiKey: string | undefined = undefined): Promise { let token: string | undefined = apiKey; if (!token) {