@zyraxon-ai/sdk 19.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -0
- package/package.json +59 -0
- package/src/client.ts +57 -0
- package/src/error-interceptor.ts +51 -0
- package/src/gen/client/client.gen.ts +212 -0
- package/src/gen/client/index.ts +25 -0
- package/src/gen/client/types.gen.ts +222 -0
- package/src/gen/client/utils.gen.ts +287 -0
- package/src/gen/client.gen.ts +22 -0
- package/src/gen/core/auth.gen.ts +41 -0
- package/src/gen/core/bodySerializer.gen.ts +74 -0
- package/src/gen/core/params.gen.ts +144 -0
- package/src/gen/core/pathSerializer.gen.ts +167 -0
- package/src/gen/core/queryKeySerializer.gen.ts +111 -0
- package/src/gen/core/serverSentEvents.gen.ts +210 -0
- package/src/gen/core/types.gen.ts +91 -0
- package/src/gen/core/utils.gen.ts +109 -0
- package/src/gen/sdk.gen.ts +1197 -0
- package/src/gen/types.gen.ts +3907 -0
- package/src/index.ts +21 -0
- package/src/process.ts +31 -0
- package/src/server.ts +134 -0
- package/src/v2/client.ts +93 -0
- package/src/v2/data.ts +32 -0
- package/src/v2/gen/client/client.gen.ts +285 -0
- package/src/v2/gen/client/index.ts +25 -0
- package/src/v2/gen/client/types.gen.ts +202 -0
- package/src/v2/gen/client/utils.gen.ts +289 -0
- package/src/v2/gen/client.gen.ts +18 -0
- package/src/v2/gen/core/auth.gen.ts +41 -0
- package/src/v2/gen/core/bodySerializer.gen.ts +82 -0
- package/src/v2/gen/core/params.gen.ts +169 -0
- package/src/v2/gen/core/pathSerializer.gen.ts +167 -0
- package/src/v2/gen/core/queryKeySerializer.gen.ts +111 -0
- package/src/v2/gen/core/serverSentEvents.gen.ts +239 -0
- package/src/v2/gen/core/types.gen.ts +86 -0
- package/src/v2/gen/core/utils.gen.ts +137 -0
- package/src/v2/gen/sdk.gen.ts +7219 -0
- package/src/v2/gen/types.gen.ts +13618 -0
- package/src/v2/index.ts +23 -0
- package/src/v2/server.ts +134 -0
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# ZYRAXON AI SDK
|
|
2
|
+
|
|
3
|
+
> The official JavaScript/TypeScript SDK for ZYRAXON AI
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
The ZYRAXON AI SDK provides a comprehensive set of tools and APIs for developers who want to integrate ZYRAXON's powerful AI capabilities into their own applications. Build chatbots, code editors, voice assistants, and more with ease.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @zyraxon-ai/sdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { createZyraxonClient } from '@zyraxon-ai/sdk'
|
|
21
|
+
|
|
22
|
+
const client = createZyraxonClient({
|
|
23
|
+
baseUrl: 'http://localhost:3000',
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const response = await client.chat({
|
|
27
|
+
message: 'Hello ZYRAXON!',
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
console.log(response.text)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Documentation
|
|
36
|
+
|
|
37
|
+
- **[Full SDK Documentation](../../../SDK.md)** — Complete API reference, examples, and guides
|
|
38
|
+
- **[Quick Start Guide](./QUICKSTART.md)** — Get up and running in minutes
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
| Feature | Description |
|
|
45
|
+
|---------|-------------|
|
|
46
|
+
| **AI Chat** | Send messages and receive responses from 25+ LLM providers |
|
|
47
|
+
| **Streaming** | Real-time streaming responses for better UX |
|
|
48
|
+
| **File Operations** | Read and write files on the server |
|
|
49
|
+
| **Session Management** | Maintain conversation context across messages |
|
|
50
|
+
| **Memory** | Store and retrieve key-value pairs |
|
|
51
|
+
| **TypeScript** | Full TypeScript support with type definitions |
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Examples
|
|
56
|
+
|
|
57
|
+
### Basic Chat
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { createZyraxonClient } from '@zyraxon-ai/sdk'
|
|
61
|
+
|
|
62
|
+
const client = createZyraxonClient({
|
|
63
|
+
baseUrl: 'http://localhost:3000',
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
async function chat() {
|
|
67
|
+
const response = await client.chat({
|
|
68
|
+
message: 'Write a Python function to sort a list',
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
console.log(response.text)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
chat()
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Streaming Response
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
const stream = await client.chatStream({
|
|
81
|
+
message: 'Explain quantum computing',
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
for await (const chunk of stream) {
|
|
85
|
+
process.stdout.write(chunk.text)
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### File Operations
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
// Read a file
|
|
93
|
+
const file = await client.readFile({ path: 'README.md' })
|
|
94
|
+
console.log(file.content)
|
|
95
|
+
|
|
96
|
+
// Write a file
|
|
97
|
+
await client.writeFile({
|
|
98
|
+
path: 'output.txt',
|
|
99
|
+
content: 'Hello from ZYRAXON SDK!',
|
|
100
|
+
})
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Contributing
|
|
106
|
+
|
|
107
|
+
Contributions are welcome! Please read our [Contributing Guide](../../../CONTRIBUTING.md) before submitting a Pull Request.
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
This project is licensed under the **Zyraxon Sovereign License — X Edition (ZSL-X)**.
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
*Created by OMG / Lx Sayidi — [GitHub](https://github.com/onelpawarai-X)*
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
+
"name": "@zyraxon-ai/sdk",
|
|
4
|
+
"version": "19.0.2",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
7
|
+
"description": "Official JavaScript/TypeScript SDK for ZYRAXON AI — Build AI-powered applications with ease",
|
|
8
|
+
"homepage": "https://zyraxonai.lovable.app",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/onelpawarai-X/ZYRAXON-AI.git",
|
|
12
|
+
"directory": "packages/sdk/js"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/onelpawarai-X/ZYRAXON-AI/issues"
|
|
16
|
+
},
|
|
17
|
+
"author": "OMG / Lx Sayidi <sayidilx@gmail.com>",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "bun test",
|
|
20
|
+
"typecheck": "tsgo --noEmit",
|
|
21
|
+
"build": "bun ./script/build.ts",
|
|
22
|
+
"prepublishOnly": "bun run build"
|
|
23
|
+
},
|
|
24
|
+
"exports": {
|
|
25
|
+
".": "./src/index.ts",
|
|
26
|
+
"./client": "./src/client.ts",
|
|
27
|
+
"./server": "./src/server.ts",
|
|
28
|
+
"./v2": "./src/v2/index.ts",
|
|
29
|
+
"./v2/client": "./src/v2/client.ts",
|
|
30
|
+
"./v2/gen/client": "./src/v2/gen/client/index.ts",
|
|
31
|
+
"./v2/server": "./src/v2/server.ts",
|
|
32
|
+
"./v2/types": "./src/v2/gen/types.gen.ts"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"src"
|
|
37
|
+
],
|
|
38
|
+
"keywords": [
|
|
39
|
+
"zyraxon",
|
|
40
|
+
"ai",
|
|
41
|
+
"sdk",
|
|
42
|
+
"llm",
|
|
43
|
+
"chatbot",
|
|
44
|
+
"artificial-intelligence",
|
|
45
|
+
"typescript",
|
|
46
|
+
"javascript"
|
|
47
|
+
],
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@hey-api/openapi-ts": "0.90.10",
|
|
50
|
+
"@tsconfig/node22": "catalog:",
|
|
51
|
+
"@types/cross-spawn": "catalog:",
|
|
52
|
+
"@types/node": "catalog:",
|
|
53
|
+
"@typescript/native-preview": "catalog:",
|
|
54
|
+
"typescript": "catalog:"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"cross-spawn": "catalog:"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export * from "./gen/types.gen.js"
|
|
2
|
+
|
|
3
|
+
import { createClient } from "./gen/client/client.gen.js"
|
|
4
|
+
import { type Config } from "./gen/client/types.gen.js"
|
|
5
|
+
import { ZyraxonClient } from "./gen/sdk.gen.js"
|
|
6
|
+
import { wrapClientError } from "./error-interceptor.js"
|
|
7
|
+
export { type Config as ZyraxonClientConfig, ZyraxonClient }
|
|
8
|
+
|
|
9
|
+
function pick(value: string | null, fallback?: string) {
|
|
10
|
+
if (!value) return
|
|
11
|
+
if (!fallback) return value
|
|
12
|
+
if (value === fallback) return fallback
|
|
13
|
+
if (value === encodeURIComponent(fallback)) return fallback
|
|
14
|
+
return value
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function rewrite(request: Request, directory?: string) {
|
|
18
|
+
if (request.method !== "GET" && request.method !== "HEAD") return request
|
|
19
|
+
|
|
20
|
+
const value = pick(request.headers.get("x-zyraxon-directory"), directory)
|
|
21
|
+
if (!value) return request
|
|
22
|
+
|
|
23
|
+
const url = new URL(request.url)
|
|
24
|
+
if (!url.searchParams.has("directory")) {
|
|
25
|
+
url.searchParams.set("directory", value)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const next = new Request(url, request)
|
|
29
|
+
next.headers.delete("x-zyraxon-directory")
|
|
30
|
+
return next
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function createZyraxonClient(config?: Config & { directory?: string }) {
|
|
34
|
+
if (!config?.fetch) {
|
|
35
|
+
const customFetch: any = (req: any) => {
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
req.timeout = false
|
|
38
|
+
return fetch(req)
|
|
39
|
+
}
|
|
40
|
+
config = {
|
|
41
|
+
...config,
|
|
42
|
+
fetch: customFetch,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (config?.directory) {
|
|
47
|
+
config.headers = {
|
|
48
|
+
...config.headers,
|
|
49
|
+
"x-zyraxon-directory": encodeURIComponent(config.directory),
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const client = createClient(config)
|
|
54
|
+
client.interceptors.request.use((request) => rewrite(request, config?.directory))
|
|
55
|
+
client.interceptors.error.use(wrapClientError)
|
|
56
|
+
return new ZyraxonClient({ client })
|
|
57
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wrap whatever the generated client decoded from a non-2xx error body
|
|
3
|
+
* into a real `Error` so downstream formatters (TUI, plugins) get a
|
|
4
|
+
* useful `.message` instead of `[object Object]` or blank. The original
|
|
5
|
+
* parsed body and status live under `.cause` for callers that need
|
|
6
|
+
* structured fields.
|
|
7
|
+
*
|
|
8
|
+
* Only fires when the caller used `{ throwOnError: true }`. Callers that
|
|
9
|
+
* read `result.error` directly (the result-tuple path) get the parsed
|
|
10
|
+
* body unchanged so existing field-level reads (`.error.name`,
|
|
11
|
+
* `JSON.stringify(error)`, etc.) are byte-for-byte identical to before.
|
|
12
|
+
*/
|
|
13
|
+
export function wrapClientError(
|
|
14
|
+
error: unknown,
|
|
15
|
+
response: Response | undefined,
|
|
16
|
+
request: Request | undefined,
|
|
17
|
+
opts: { throwOnError?: boolean } | undefined,
|
|
18
|
+
): unknown {
|
|
19
|
+
if (!opts?.throwOnError) return error
|
|
20
|
+
if (error instanceof Error) return error
|
|
21
|
+
|
|
22
|
+
// NamedError-shaped responses (the common case for zyraxon 4xx) come
|
|
23
|
+
// through as POJOs — extract a useful message first, then wrap.
|
|
24
|
+
if (typeof error === "object" && error !== null && Object.keys(error).length > 0) {
|
|
25
|
+
const obj = error as { data?: { message?: unknown }; message?: unknown; name?: unknown }
|
|
26
|
+
const message =
|
|
27
|
+
(typeof obj.data?.message === "string" && obj.data.message) ||
|
|
28
|
+
(typeof obj.message === "string" && obj.message) ||
|
|
29
|
+
(typeof obj.name === "string" && obj.name) ||
|
|
30
|
+
describe(request, response)
|
|
31
|
+
return new Error(message, { cause: { body: error, status: response?.status } })
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (typeof error === "string" && error.length > 0) {
|
|
35
|
+
return new Error(error, { cause: { body: error, status: response?.status } })
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Empty body / network failure / undefined / null / empty object.
|
|
39
|
+
const reason = response ? "(empty response body)" : "network error (no response)"
|
|
40
|
+
return new Error(`zyraxon server ${describe(request, response)}: ${reason}`, {
|
|
41
|
+
cause: { body: error, status: response?.status },
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function describe(request: Request | undefined, response: Response | undefined) {
|
|
46
|
+
const method = request?.method ?? "?"
|
|
47
|
+
const url = request?.url ?? "?"
|
|
48
|
+
const status = response?.status
|
|
49
|
+
const statusText = response?.statusText
|
|
50
|
+
return `${method} ${url}${status ? " → " + status : ""}${statusText ? " " + statusText : ""}`
|
|
51
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import { createSseClient } from "../core/serverSentEvents.gen.js"
|
|
4
|
+
import type { Client, Config, RequestOptions, ResolvedRequestOptions } from "./types.gen.js"
|
|
5
|
+
import {
|
|
6
|
+
buildUrl,
|
|
7
|
+
createConfig,
|
|
8
|
+
createInterceptors,
|
|
9
|
+
getParseAs,
|
|
10
|
+
mergeConfigs,
|
|
11
|
+
mergeHeaders,
|
|
12
|
+
setAuthParams,
|
|
13
|
+
} from "./utils.gen.js"
|
|
14
|
+
|
|
15
|
+
type ReqInit = Omit<RequestInit, "body" | "headers"> & {
|
|
16
|
+
body?: any
|
|
17
|
+
headers: ReturnType<typeof mergeHeaders>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const createClient = (config: Config = {}): Client => {
|
|
21
|
+
let _config = mergeConfigs(createConfig(), config)
|
|
22
|
+
|
|
23
|
+
const getConfig = (): Config => ({ ..._config })
|
|
24
|
+
|
|
25
|
+
const setConfig = (config: Config): Config => {
|
|
26
|
+
_config = mergeConfigs(_config, config)
|
|
27
|
+
return getConfig()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>()
|
|
31
|
+
|
|
32
|
+
const beforeRequest = async (options: RequestOptions) => {
|
|
33
|
+
const opts = {
|
|
34
|
+
..._config,
|
|
35
|
+
...options,
|
|
36
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
37
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
38
|
+
serializedBody: undefined,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (opts.security) {
|
|
42
|
+
await setAuthParams({
|
|
43
|
+
...opts,
|
|
44
|
+
security: opts.security,
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (opts.requestValidator) {
|
|
49
|
+
await opts.requestValidator(opts)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (opts.body && opts.bodySerializer) {
|
|
53
|
+
opts.serializedBody = opts.bodySerializer(opts.body)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
57
|
+
if (opts.serializedBody === undefined || opts.serializedBody === "") {
|
|
58
|
+
opts.headers.delete("Content-Type")
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const url = buildUrl(opts)
|
|
62
|
+
|
|
63
|
+
return { opts, url }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const request: Client["request"] = async (options) => {
|
|
67
|
+
// @ts-expect-error
|
|
68
|
+
const { opts, url } = await beforeRequest(options)
|
|
69
|
+
const requestInit: ReqInit = {
|
|
70
|
+
redirect: "follow",
|
|
71
|
+
...opts,
|
|
72
|
+
body: opts.serializedBody,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let request = new Request(url, requestInit)
|
|
76
|
+
|
|
77
|
+
for (const fn of interceptors.request._fns) {
|
|
78
|
+
if (fn) {
|
|
79
|
+
request = await fn(request, opts)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// fetch must be assigned here, otherwise it would throw the error:
|
|
84
|
+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
85
|
+
const _fetch = opts.fetch!
|
|
86
|
+
let response = await _fetch(request)
|
|
87
|
+
|
|
88
|
+
for (const fn of interceptors.response._fns) {
|
|
89
|
+
if (fn) {
|
|
90
|
+
response = await fn(response, request, opts)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const result = {
|
|
95
|
+
request,
|
|
96
|
+
response,
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (response.ok) {
|
|
100
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
101
|
+
return opts.responseStyle === "data"
|
|
102
|
+
? {}
|
|
103
|
+
: {
|
|
104
|
+
data: {},
|
|
105
|
+
...result,
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const parseAs =
|
|
110
|
+
(opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json"
|
|
111
|
+
|
|
112
|
+
let data: any
|
|
113
|
+
switch (parseAs) {
|
|
114
|
+
case "arrayBuffer":
|
|
115
|
+
case "blob":
|
|
116
|
+
case "formData":
|
|
117
|
+
case "json":
|
|
118
|
+
case "text":
|
|
119
|
+
data = await response[parseAs]()
|
|
120
|
+
break
|
|
121
|
+
case "stream":
|
|
122
|
+
return opts.responseStyle === "data"
|
|
123
|
+
? response.body
|
|
124
|
+
: {
|
|
125
|
+
data: response.body,
|
|
126
|
+
...result,
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (parseAs === "json") {
|
|
131
|
+
if (opts.responseValidator) {
|
|
132
|
+
await opts.responseValidator(data)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (opts.responseTransformer) {
|
|
136
|
+
data = await opts.responseTransformer(data)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return opts.responseStyle === "data"
|
|
141
|
+
? data
|
|
142
|
+
: {
|
|
143
|
+
data,
|
|
144
|
+
...result,
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const textError = await response.text()
|
|
149
|
+
let jsonError: unknown
|
|
150
|
+
|
|
151
|
+
try {
|
|
152
|
+
jsonError = JSON.parse(textError)
|
|
153
|
+
} catch {
|
|
154
|
+
// noop
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const error = jsonError ?? textError
|
|
158
|
+
let finalError = error
|
|
159
|
+
|
|
160
|
+
for (const fn of interceptors.error._fns) {
|
|
161
|
+
if (fn) {
|
|
162
|
+
finalError = (await fn(error, response, request, opts)) as string
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
finalError = finalError || ({} as string)
|
|
167
|
+
|
|
168
|
+
if (opts.throwOnError) {
|
|
169
|
+
throw finalError
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// TODO: we probably want to return error and improve types
|
|
173
|
+
return opts.responseStyle === "data"
|
|
174
|
+
? undefined
|
|
175
|
+
: {
|
|
176
|
+
error: finalError,
|
|
177
|
+
...result,
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const makeMethod = (method: Required<Config>["method"]) => {
|
|
182
|
+
const fn = (options: RequestOptions) => request({ ...options, method })
|
|
183
|
+
fn.sse = async (options: RequestOptions) => {
|
|
184
|
+
const { opts, url } = await beforeRequest(options)
|
|
185
|
+
return createSseClient({
|
|
186
|
+
...opts,
|
|
187
|
+
body: opts.body as BodyInit | null | undefined,
|
|
188
|
+
headers: opts.headers as unknown as Record<string, string>,
|
|
189
|
+
method,
|
|
190
|
+
url,
|
|
191
|
+
})
|
|
192
|
+
}
|
|
193
|
+
return fn
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
buildUrl,
|
|
198
|
+
connect: makeMethod("CONNECT"),
|
|
199
|
+
delete: makeMethod("DELETE"),
|
|
200
|
+
get: makeMethod("GET"),
|
|
201
|
+
getConfig,
|
|
202
|
+
head: makeMethod("HEAD"),
|
|
203
|
+
interceptors,
|
|
204
|
+
options: makeMethod("OPTIONS"),
|
|
205
|
+
patch: makeMethod("PATCH"),
|
|
206
|
+
post: makeMethod("POST"),
|
|
207
|
+
put: makeMethod("PUT"),
|
|
208
|
+
request,
|
|
209
|
+
setConfig,
|
|
210
|
+
trace: makeMethod("TRACE"),
|
|
211
|
+
} as Client
|
|
212
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
export type { Auth } from "../core/auth.gen.js"
|
|
4
|
+
export type { QuerySerializerOptions } from "../core/bodySerializer.gen.js"
|
|
5
|
+
export {
|
|
6
|
+
formDataBodySerializer,
|
|
7
|
+
jsonBodySerializer,
|
|
8
|
+
urlSearchParamsBodySerializer,
|
|
9
|
+
} from "../core/bodySerializer.gen.js"
|
|
10
|
+
export { buildClientParams } from "../core/params.gen.js"
|
|
11
|
+
export { createClient } from "./client.gen.js"
|
|
12
|
+
export type {
|
|
13
|
+
Client,
|
|
14
|
+
ClientOptions,
|
|
15
|
+
Config,
|
|
16
|
+
CreateClientConfig,
|
|
17
|
+
Options,
|
|
18
|
+
OptionsLegacyParser,
|
|
19
|
+
RequestOptions,
|
|
20
|
+
RequestResult,
|
|
21
|
+
ResolvedRequestOptions,
|
|
22
|
+
ResponseStyle,
|
|
23
|
+
TDataShape,
|
|
24
|
+
} from "./types.gen.js"
|
|
25
|
+
export { createConfig, mergeHeaders } from "./utils.gen.js"
|