Skip to content

Commit 1308812

Browse files
committed
fix: remove the disable server environment variable
Now, when the GPTSCRIPT_URL is passed, the SDK will use it and not start its own server. Additionally, the SDK will pass this server URL to child SDK calls. Signed-off-by: Donnie Adams <[email protected]>
1 parent a2753a6 commit 1308812

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/gptscript.ts

+24-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,21 @@ export class GPTScript {
8383
this.ready = false
8484
GPTScript.instanceCount++
8585
if (!GPTScript.serverURL) {
86-
GPTScript.serverURL = "http://" + (process.env.GPTSCRIPT_URL || "127.0.0.1:0")
86+
GPTScript.serverURL = process.env.GPTSCRIPT_URL ?? "http://127.0.0.1:0"
87+
if (!GPTScript.serverURL.startsWith("http://") && !GPTScript.serverURL.startsWith("https://")) {
88+
GPTScript.serverURL = "http://" + GPTScript.serverURL
89+
}
90+
}
91+
92+
if (process.env.GPTSCRIPT_URL) {
93+
if (!this.opts.Env) {
94+
this.opts.Env = []
95+
}
96+
this.opts.Env.push("GPTSCRIPT_URL=" + GPTScript.serverURL)
97+
return
8798
}
88-
if (GPTScript.instanceCount === 1 && process.env.GPTSCRIPT_DISABLE_SERVER !== "true") {
99+
100+
if (GPTScript.instanceCount === 1) {
89101
let env = process.env
90102
if (this.opts.Env) {
91103
env = {
@@ -121,16 +133,25 @@ export class GPTScript {
121133
}
122134

123135
GPTScript.serverURL = `http://${url}`
136+
if (!this.opts.Env) {
137+
this.opts.Env = []
138+
}
139+
this.opts.Env.push(`GPTSCRIPT_URL=${GPTScript.serverURL}`)
124140

125141
GPTScript.serverProcess.stderr?.removeAllListeners()
126142
})
143+
} else {
144+
if (!this.opts.Env) {
145+
this.opts.Env = []
146+
}
147+
this.opts.Env.push("GPTSCRIPT_URL=" + GPTScript.serverURL)
127148
}
128149
}
129150

130151
close(): void {
131152
GPTScript.instanceCount--
132153
if (GPTScript.instanceCount === 0 && GPTScript.serverProcess) {
133-
GPTScript.serverURL = "http://" + (process.env.GPTSCRIPT_URL || "127.0.0.1:0")
154+
GPTScript.serverURL = process.env.GPTSCRIPT_URL ?? "http://127.0.0.1:0"
134155
GPTScript.serverProcess.kill("SIGTERM")
135156
GPTScript.serverProcess.stdin?.end()
136157
}

0 commit comments

Comments
 (0)