@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.
Files changed (41) hide show
  1. package/README.md +117 -0
  2. package/package.json +59 -0
  3. package/src/client.ts +57 -0
  4. package/src/error-interceptor.ts +51 -0
  5. package/src/gen/client/client.gen.ts +212 -0
  6. package/src/gen/client/index.ts +25 -0
  7. package/src/gen/client/types.gen.ts +222 -0
  8. package/src/gen/client/utils.gen.ts +287 -0
  9. package/src/gen/client.gen.ts +22 -0
  10. package/src/gen/core/auth.gen.ts +41 -0
  11. package/src/gen/core/bodySerializer.gen.ts +74 -0
  12. package/src/gen/core/params.gen.ts +144 -0
  13. package/src/gen/core/pathSerializer.gen.ts +167 -0
  14. package/src/gen/core/queryKeySerializer.gen.ts +111 -0
  15. package/src/gen/core/serverSentEvents.gen.ts +210 -0
  16. package/src/gen/core/types.gen.ts +91 -0
  17. package/src/gen/core/utils.gen.ts +109 -0
  18. package/src/gen/sdk.gen.ts +1197 -0
  19. package/src/gen/types.gen.ts +3907 -0
  20. package/src/index.ts +21 -0
  21. package/src/process.ts +31 -0
  22. package/src/server.ts +134 -0
  23. package/src/v2/client.ts +93 -0
  24. package/src/v2/data.ts +32 -0
  25. package/src/v2/gen/client/client.gen.ts +285 -0
  26. package/src/v2/gen/client/index.ts +25 -0
  27. package/src/v2/gen/client/types.gen.ts +202 -0
  28. package/src/v2/gen/client/utils.gen.ts +289 -0
  29. package/src/v2/gen/client.gen.ts +18 -0
  30. package/src/v2/gen/core/auth.gen.ts +41 -0
  31. package/src/v2/gen/core/bodySerializer.gen.ts +82 -0
  32. package/src/v2/gen/core/params.gen.ts +169 -0
  33. package/src/v2/gen/core/pathSerializer.gen.ts +167 -0
  34. package/src/v2/gen/core/queryKeySerializer.gen.ts +111 -0
  35. package/src/v2/gen/core/serverSentEvents.gen.ts +239 -0
  36. package/src/v2/gen/core/types.gen.ts +86 -0
  37. package/src/v2/gen/core/utils.gen.ts +137 -0
  38. package/src/v2/gen/sdk.gen.ts +7219 -0
  39. package/src/v2/gen/types.gen.ts +13618 -0
  40. package/src/v2/index.ts +23 -0
  41. package/src/v2/server.ts +134 -0
@@ -0,0 +1,23 @@
1
+ export * from "./client.js"
2
+ export * from "./server.js"
3
+
4
+ import { createZyraxonClient } from "./client.js"
5
+ import { createZyraxonServer } from "./server.js"
6
+ import type { ServerOptions } from "./server.js"
7
+
8
+ export * as data from "./data.js"
9
+
10
+ export async function createZyraxon(options?: ServerOptions) {
11
+ const server = await createZyraxonServer({
12
+ ...options,
13
+ })
14
+
15
+ const client = createZyraxonClient({
16
+ baseUrl: server.url,
17
+ })
18
+
19
+ return {
20
+ client,
21
+ server,
22
+ }
23
+ }
@@ -0,0 +1,134 @@
1
+ import launch from "cross-spawn"
2
+ import { type Config } from "./gen/types.gen.js"
3
+ import { stop, bindAbort } from "../process.js"
4
+
5
+ export type ServerOptions = {
6
+ hostname?: string
7
+ port?: number
8
+ signal?: AbortSignal
9
+ timeout?: number
10
+ config?: Config
11
+ }
12
+
13
+ export type TuiOptions = {
14
+ project?: string
15
+ model?: string
16
+ session?: string
17
+ agent?: string
18
+ signal?: AbortSignal
19
+ config?: Config
20
+ }
21
+
22
+ export async function createZyraxonServer(options?: ServerOptions) {
23
+ options = Object.assign(
24
+ {
25
+ hostname: "127.0.0.1",
26
+ port: 4096,
27
+ timeout: 5000,
28
+ },
29
+ options ?? {},
30
+ )
31
+
32
+ const args = [`serve`, `--hostname=${options.hostname}`, `--port=${options.port}`]
33
+ if (options.config?.logLevel) args.push(`--log-level=${options.config.logLevel}`)
34
+
35
+ const proc = launch(`zyraxon`, args, {
36
+ env: {
37
+ ...process.env,
38
+ ZYRAXON_CONFIG_CONTENT: JSON.stringify(options.config ?? {}),
39
+ },
40
+ })
41
+ let clear = () => {}
42
+
43
+ const url = await new Promise<string>((resolve, reject) => {
44
+ const id = setTimeout(() => {
45
+ clear()
46
+ stop(proc)
47
+ reject(new Error(`Timeout waiting for server to start after ${options.timeout}ms`))
48
+ }, options.timeout)
49
+ let output = ""
50
+ let resolved = false
51
+ proc.stdout?.on("data", (chunk) => {
52
+ if (resolved) return
53
+ output += chunk.toString()
54
+ const lines = output.split("\n")
55
+ for (const line of lines) {
56
+ if (line.startsWith("zyraxon server listening")) {
57
+ const match = line.match(/on\s+(https?:\/\/[^\s]+)/)
58
+ if (!match) {
59
+ clear()
60
+ stop(proc)
61
+ clearTimeout(id)
62
+ reject(new Error(`Failed to parse server url from output: ${line}`))
63
+ return
64
+ }
65
+ clearTimeout(id)
66
+ resolved = true
67
+ resolve(match[1]!)
68
+ return
69
+ }
70
+ }
71
+ })
72
+ proc.stderr?.on("data", (chunk) => {
73
+ output += chunk.toString()
74
+ })
75
+ proc.on("exit", (code) => {
76
+ clearTimeout(id)
77
+ let msg = `Server exited with code ${code}`
78
+ if (output.trim()) {
79
+ msg += `\nServer output: ${output}`
80
+ }
81
+ reject(new Error(msg))
82
+ })
83
+ proc.on("error", (error) => {
84
+ clearTimeout(id)
85
+ reject(error)
86
+ })
87
+ clear = bindAbort(proc, options.signal, () => {
88
+ clearTimeout(id)
89
+ reject(options.signal?.reason)
90
+ })
91
+ })
92
+
93
+ return {
94
+ url,
95
+ close() {
96
+ clear()
97
+ stop(proc)
98
+ },
99
+ }
100
+ }
101
+
102
+ export function createZyraxonTui(options?: TuiOptions) {
103
+ const args = []
104
+
105
+ if (options?.project) {
106
+ args.push(`--project=${options.project}`)
107
+ }
108
+ if (options?.model) {
109
+ args.push(`--model=${options.model}`)
110
+ }
111
+ if (options?.session) {
112
+ args.push(`--session=${options.session}`)
113
+ }
114
+ if (options?.agent) {
115
+ args.push(`--agent=${options.agent}`)
116
+ }
117
+
118
+ const proc = launch(`zyraxon`, args, {
119
+ stdio: "inherit",
120
+ env: {
121
+ ...process.env,
122
+ ZYRAXON_CONFIG_CONTENT: JSON.stringify(options?.config ?? {}),
123
+ },
124
+ })
125
+
126
+ const clear = bindAbort(proc, options?.signal)
127
+
128
+ return {
129
+ close() {
130
+ clear()
131
+ stop(proc)
132
+ },
133
+ }
134
+ }