Skip to content

Commit c06d724

Browse files
committed
fix: use correct path and data when using browser SSE
1 parent a0d5124 commit c06d724

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ async function streamExecFileWithEvents() {
224224
// Wait for the initial run to complete.
225225
await run.text();
226226

227-
while (run.RunState === gptscript.RunState.Continue) {
227+
while (run.state === gptscript.RunState.Continue) {
228228
// ...Get the next input from the user somehow...
229229

230230
run = run.nextChat(inputFromUser)

src/gptscript.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class Client {
8080
* @return {Run} The Run object representing the running tool.
8181
*/
8282
run(toolName: string, opts: RunOpts = {}): Run {
83-
return (new Run("run-file-stream-with-events", toolName, "", opts)).nextChat(opts.input)
83+
return (new Run("run-file-stream-with-events", toolName, "", opts, this.gptscriptBin, this.gptscriptURL)).nextChat(opts.input)
8484
}
8585

8686
/**
@@ -101,7 +101,7 @@ export class Client {
101101
toolString = toolDefToString(tool)
102102
}
103103

104-
return (new Run("run-tool-stream-with-event", "", toolString, opts)).nextChat(opts.input)
104+
return (new Run("run-tool-stream-with-event", "", toolString, opts, this.gptscriptBin, this.gptscriptURL)).nextChat(opts.input)
105105
}
106106

107107
async parse(fileName: string): Promise<Block[]> {
@@ -196,7 +196,7 @@ export class Run {
196196

197197
let run = this
198198
if (run.state !== RunState.Creating) {
199-
run = new (this.constructor as any)(run.requestPath, run.filePath, run.content, run.opts)
199+
run = new (this.constructor as any)(run.requestPath, run.filePath, run.content, run.opts, run.gptscriptURL)
200200
}
201201

202202
run.chatState = this.chatState
@@ -379,9 +379,10 @@ export class Run {
379379
if (typeof window !== "undefined" && typeof window.document !== "undefined") {
380380
// @ts-ignore
381381
const {SSE} = await import("sse.js")
382-
this.sse = new SSE(this.gptscriptURL + "/" + this.filePath, {
382+
this.sse = new SSE(this.gptscriptURL + "/" + this.requestPath, {
383383
headers: {"Content-Type": "application/json"},
384-
payload: postData
384+
payload: tool ? postData : undefined,
385+
method: tool ? "POST" : "GET"
385386
} as any)
386387

387388
this.sse.addEventListener("open", () => {

0 commit comments

Comments
 (0)