Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Main node entrypoint, async nits, global tools #26

Merged
merged 9 commits into from
May 6, 2024

Conversation

vincent99
Copy link
Contributor

  • Changed main entrypoint js in package.json to be where it is now.

  • If you know something is defined but TS doesn't, you can use the "damnit" flag, ! instead of eslint ignore comments. this.promise = new Promise(() => { .... this.process!.on( 'exit', ...)

  • async function foo(): Promise<x> { return await bar() } is functionally the same as just saying function foo(): Promise<x> { return bar() } but makes debugging harder. By marking the function async and awaiting you're creating an extra promise that does nothing but immediately resolve after bar's does. You don't have to declare your function as async in order for the consumer to be able to await it. The consumer just needs a function that returns a Promise (which bar() already returns). On your side you only have to say async if you want to use await for something in the body (other than just immediately returning it).

  • Similarly text() and json() have that + a 2nd layer of extra promises. throw is the same as reject() and throws 'cascade' up so all json() needs to be is return JSON.parse(await this.text()). Also the returned JSON isn't necessarily an object, it could be an array or a random scalar so it should just return any.

  • Changed default for a text block to just plain 'text' format, markdown will be a separate option (that the parser doesn't need to know about)

  • Parameters (or ToolDef) should support globalTools and toolDefToString serializing them.

vincent99 and others added 9 commits May 1, 2024 17:22
- Changed main entrypoint js in package.json to be where it is now.

- If you know something is defined but TS doesn't, you can use the damnit flag, `!` instead of eslint ignore comments. `this.promise = new Promise(() => { .... this.process!.on('exit', ...)`

- `async function foo(): Promise<x> { return await bar() }` is redundant.  This is functionally the same as just saying `function foo(): Promise<x> { return bar() }` but makes debugging harder.  By marking the function async and awaiting you're creating an extra promise that does nothing but immediately resolve after bar's does.  You don't have to declare your function as async in order for the consumer to be able to await it.  The consumer just needs a function that returns a Promise (which bar() already returns).  On your side you only have to say `async` if you want to use `await` for something in the body (other than just immediately returning it)

- Similarly text() and json() have that + a 2nd layer of extra promises. `throw` is the same as reject() and throws 'cascade' up so all json() needs to be is `return JSON.parse(await this.text())`.  Also the returned JSON isn't necessarily an object, it could be an array or a random scalar so it should just return `any`.

- Changed default for a text block to just plain 'text' format, markdown will be a separate option (that the parser doesn't need to know about)

- Parameters (or ToolDef) should support globalTools and toolDefToString serializing them.
Signed-off-by: Donnie Adams <[email protected]>
Signed-off-by: Donnie Adams <[email protected]>
Signed-off-by: Donnie Adams <[email protected]>
@thedadams thedadams merged commit fd623c3 into gptscript-ai:main May 6, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants