-
Notifications
You must be signed in to change notification settings - Fork 137
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
Add OpenAPI tool #246
base: main
Are you sure you want to change the base?
Add OpenAPI tool #246
Conversation
src/tools/openapi.ts
Outdated
description?: string; | ||
openApiSchema?: any; | ||
apiKey?: string; | ||
http_proxy_url?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use camelCase
src/tools/openapi.ts
Outdated
http_proxy_url?: string; | ||
} | ||
|
||
type ToolRunOptions = BaseToolRunOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed.
src/tools/openapi.ts
Outdated
} | ||
} | ||
|
||
export class OpenAPI extends Tool<StringToolOutput, OpenAPIOptions, ToolRunOptions> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ToolRunOptions
can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to OpenAPITool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response class does not match the reality.
It should be OpenAPIToolOutput
, not StringToolOutput
.
src/tools/openapi.ts
Outdated
//ToolInput<this>, | ||
any, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with Record<string, any>
src/tools/openapi.ts
Outdated
public readonly emitter: ToolEmitter< | ||
//ToolInput<this>, | ||
any, | ||
StringToolOutput, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be OpenAPIToolOutput
this.openApiSchema = parse(openApiSchema); | ||
// TODO: #105 review error codes. Were using APIErrorCode, now ToolError | ||
if (!this.openApiSchema?.paths) { | ||
throw new ValueError("Server is not specified!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the error message more descriptive, please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole constructor can be simplified to
public constructor(options: OpenAPIOptions) {
super(options);
this.openApiSchema = parse(options.openApiSchema);
if (!this.openApiSchema?.paths) {
throw new ValueError("Server is not specified!");
}
}
src/tools/openapi.ts
Outdated
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style | ||
const headers: { [key: string]: string } = { Accept: "application/json" }; | ||
if (this.apiKey) { | ||
headers["Authorization"] = `Bearer this.apiKey`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not work.
You probably wanted to do Bearer ${this.apiKey}
.
src/tools/openapi.ts
Outdated
headers: headers, | ||
signal: AbortSignal.any([AbortSignal.timeout(30_000), run.signal]), | ||
}); | ||
return new StringToolOutput(await response.text()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong response type.
src/tools/openapi.ts
Outdated
body: !isEmpty(input.body) ? input.body : undefined, | ||
method: input.method.toLowerCase(), | ||
headers: headers, | ||
signal: AbortSignal.any([AbortSignal.timeout(30_000), run.signal]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the AbortSignal.timeout()
because a user can specify it via run parameters.
this.openApiSchema = parse(openApiSchema); | ||
// TODO: #105 review error codes. Were using APIErrorCode, now ToolError | ||
if (!this.openApiSchema?.paths) { | ||
throw new ValueError("Server is not specified!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole constructor can be simplified to
public constructor(options: OpenAPIOptions) {
super(options);
this.openApiSchema = parse(options.openApiSchema);
if (!this.openApiSchema?.paths) {
throw new ValueError("Server is not specified!");
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing serialization-related methods.
4118170
to
599387d
Compare
src/tools/openapi.ts
Outdated
} | ||
|
||
protected async _run( | ||
input: any, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the error message?
src/tools/openapi.ts
Outdated
const text = await response.text(); | ||
return new OpenAPIToolOutput(response.status, response.statusText, text); | ||
} catch { | ||
throw new ToolError(`Request to ${url} failed.`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you throw this error without any context, the agent cannot retry. Do this instead.
} catch (err) {
throw new ToolError(`Request to ${url} has failed.`, [err]);
}
5058a23
to
1e85cb1
Compare
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
1e85cb1
to
f718e60
Compare
Which issue(s) does this pull-request address?
Closes: #105
Description
Checklist
yarn lint
oryarn lint:fix
yarn format
oryarn format:fix
yarn test:unit
yarn test:e2e