@saeeol/sdk 7.3.3 → 7.3.5
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/package.json +6 -3
- package/src/client.ts +64 -0
- package/src/gen/client/client.gen.ts +215 -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 +3905 -0
- package/src/index.ts +21 -0
- package/src/process.ts +31 -0
- package/src/server.ts +165 -0
- package/src/v2/client.ts +97 -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 +6316 -0
- package/src/v2/gen/types.gen.ts +7495 -0
- package/src/v2/index.ts +23 -0
- package/src/v2/server.ts +163 -0
package/src/v2/index.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export * from "./client.js"
|
|
2
|
+
export * from "./server.js"
|
|
3
|
+
|
|
4
|
+
import { createSaeeolClient } from "./client.js"
|
|
5
|
+
import { createSaeeolServer } from "./server.js"
|
|
6
|
+
import type { ServerOptions } from "./server.js"
|
|
7
|
+
|
|
8
|
+
export * as data from "./data.js"
|
|
9
|
+
|
|
10
|
+
export async function createSaeeol(options?: ServerOptions) {
|
|
11
|
+
const server = await createSaeeolServer({
|
|
12
|
+
...options,
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const client = createSaeeolClient({
|
|
16
|
+
baseUrl: server.url,
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
client,
|
|
21
|
+
server,
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/v2/server.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import launch from "cross-spawn"
|
|
2
|
+
import { type Config } from "./gen/types.gen.js"
|
|
3
|
+
import { stop, bindAbort } from "../process.js"
|
|
4
|
+
// This preserves Saeeol-injected modes when spawning nested CLI instances
|
|
5
|
+
function mergeConfig(existing: Config | undefined, incoming: Config | undefined): Config {
|
|
6
|
+
const base = existing ?? {}
|
|
7
|
+
const override = incoming ?? {}
|
|
8
|
+
return {
|
|
9
|
+
...base,
|
|
10
|
+
...override,
|
|
11
|
+
agent: { ...base.agent, ...override.agent },
|
|
12
|
+
command: { ...base.command, ...override.command },
|
|
13
|
+
mcp: { ...base.mcp, ...override.mcp },
|
|
14
|
+
mode: { ...base.mode, ...override.mode },
|
|
15
|
+
plugin: [...(base.plugin ?? []), ...(override.plugin ?? [])],
|
|
16
|
+
instructions: [...(base.instructions ?? []), ...(override.instructions ?? [])],
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function parseExistingConfig(): Config | undefined {
|
|
21
|
+
const content = process.env.SAEEOL_CONFIG_CONTENT
|
|
22
|
+
if (!content) return undefined
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(content)
|
|
25
|
+
} catch {
|
|
26
|
+
return undefined
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function buildConfigEnv(config?: Config): string {
|
|
31
|
+
const merged = mergeConfig(parseExistingConfig(), config)
|
|
32
|
+
return JSON.stringify(merged)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type ServerOptions = {
|
|
36
|
+
hostname?: string
|
|
37
|
+
port?: number
|
|
38
|
+
signal?: AbortSignal
|
|
39
|
+
timeout?: number
|
|
40
|
+
config?: Config
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type TuiOptions = {
|
|
44
|
+
project?: string
|
|
45
|
+
model?: string
|
|
46
|
+
session?: string
|
|
47
|
+
agent?: string
|
|
48
|
+
signal?: AbortSignal
|
|
49
|
+
config?: Config
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function createSaeeolServer(options?: ServerOptions) {
|
|
53
|
+
options = Object.assign(
|
|
54
|
+
{
|
|
55
|
+
hostname: "127.0.0.1",
|
|
56
|
+
port: 4096,
|
|
57
|
+
timeout: 5000,
|
|
58
|
+
},
|
|
59
|
+
options ?? {},
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
const args = [`serve`, `--hostname=${options.hostname}`, `--port=${options.port}`]
|
|
63
|
+
if (options.config?.logLevel) args.push(`--log-level=${options.config.logLevel}`)
|
|
64
|
+
const proc = launch(`saeeol`, args, {
|
|
65
|
+
env: {
|
|
66
|
+
...process.env,
|
|
67
|
+
SAEEOL_CONFIG_CONTENT: buildConfigEnv(options.config),
|
|
68
|
+
},
|
|
69
|
+
})
|
|
70
|
+
let clear = () => {}
|
|
71
|
+
|
|
72
|
+
const url = await new Promise<string>((resolve, reject) => {
|
|
73
|
+
const id = setTimeout(() => {
|
|
74
|
+
clear()
|
|
75
|
+
stop(proc)
|
|
76
|
+
reject(new Error(`Timeout waiting for server to start after ${options.timeout}ms`))
|
|
77
|
+
}, options.timeout)
|
|
78
|
+
let output = ""
|
|
79
|
+
let resolved = false
|
|
80
|
+
proc.stdout?.on("data", (chunk) => {
|
|
81
|
+
if (resolved) return
|
|
82
|
+
output += chunk.toString()
|
|
83
|
+
const lines = output.split("\n")
|
|
84
|
+
for (const line of lines) {
|
|
85
|
+
if (line.startsWith("saeeol server listening")) {
|
|
86
|
+
const match = line.match(/on\s+(https?:\/\/[^\s]+)/)
|
|
87
|
+
if (!match) {
|
|
88
|
+
clear()
|
|
89
|
+
stop(proc)
|
|
90
|
+
clearTimeout(id)
|
|
91
|
+
reject(new Error(`Failed to parse server url from output: ${line}`))
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
clearTimeout(id)
|
|
95
|
+
resolved = true
|
|
96
|
+
resolve(match[1]!)
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
proc.stderr?.on("data", (chunk) => {
|
|
102
|
+
output += chunk.toString()
|
|
103
|
+
})
|
|
104
|
+
proc.on("exit", (code) => {
|
|
105
|
+
clearTimeout(id)
|
|
106
|
+
let msg = `Server exited with code ${code}`
|
|
107
|
+
if (output.trim()) {
|
|
108
|
+
msg += `\nServer output: ${output}`
|
|
109
|
+
}
|
|
110
|
+
reject(new Error(msg))
|
|
111
|
+
})
|
|
112
|
+
proc.on("error", (error) => {
|
|
113
|
+
clearTimeout(id)
|
|
114
|
+
reject(error)
|
|
115
|
+
})
|
|
116
|
+
clear = bindAbort(proc, options.signal, () => {
|
|
117
|
+
clearTimeout(id)
|
|
118
|
+
reject(options.signal?.reason)
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
url,
|
|
124
|
+
close() {
|
|
125
|
+
clear()
|
|
126
|
+
stop(proc)
|
|
127
|
+
},
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function createSaeeolTui(options?: TuiOptions) {
|
|
132
|
+
const args = []
|
|
133
|
+
|
|
134
|
+
if (options?.project) {
|
|
135
|
+
args.push(`--project=${options.project}`)
|
|
136
|
+
}
|
|
137
|
+
if (options?.model) {
|
|
138
|
+
args.push(`--model=${options.model}`)
|
|
139
|
+
}
|
|
140
|
+
if (options?.session) {
|
|
141
|
+
args.push(`--session=${options.session}`)
|
|
142
|
+
}
|
|
143
|
+
if (options?.agent) {
|
|
144
|
+
args.push(`--agent=${options.agent}`)
|
|
145
|
+
}
|
|
146
|
+
const proc = launch(`saeeol`, args, {
|
|
147
|
+
stdio: "inherit",
|
|
148
|
+
windowsHide: true,
|
|
149
|
+
env: {
|
|
150
|
+
...process.env,
|
|
151
|
+
SAEEOL_CONFIG_CONTENT: buildConfigEnv(options?.config),
|
|
152
|
+
},
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
const clear = bindAbort(proc, options?.signal)
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
close() {
|
|
159
|
+
clear()
|
|
160
|
+
stop(proc)
|
|
161
|
+
},
|
|
162
|
+
}
|
|
163
|
+
}
|