fix: Main node entrypoint, async nits, global tools #26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 sayingfunction 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 sayasync
if you want to useawait
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 isreturn 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 returnany
.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.