-
Notifications
You must be signed in to change notification settings - Fork 88
feat(plugin-api): export ToolDefinition for tool-file authoring #31956
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dee77fe
feat(plugin-api): export ToolDefinition for tool-file authoring
d78513e
Consolidate PluginTool into ToolDefinition
6dca9ac
Apply review feedback: ToolDefinition, RiskLevel, simpler LoadedPlugi…
8236f27
Consolidate ToolContext/ToolExecutionResult; simplify LoadedPluginTool
fff69c4
meet-manifest-loader/registries: source ToolDefinition from tools/types
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
assistant/src/__tests__/plugin-api-tool-definition.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /** | ||
| * Shape tests for the public `ToolDefinition` author-facing tool spec. | ||
| * | ||
| * These tests don't exercise runtime behavior — they assert via | ||
| * `satisfies` that representative tool literals line up with the public | ||
| * interface. If a later PR breaks a field name or signature in | ||
| * `assistant/src/plugin-api/types.ts`, this file fails to type-check and | ||
| * the regression is caught at `tsc --noEmit` / `bun test` time. | ||
| */ | ||
|
|
||
| import { describe, expect, test } from "bun:test"; | ||
|
|
||
| import { | ||
| RiskLevel, | ||
| type ToolContext, | ||
| type ToolDefinition, | ||
| type ToolExecutionResult, | ||
| } from "../plugin-api/index.js"; | ||
|
|
||
| describe("ToolDefinition (public author-facing tool spec) ", () => { | ||
| test("a fully-populated literal satisfies the interface", () => { | ||
| const tool = { | ||
| description: "Greet the model in a fixed language.", | ||
| defaultRiskLevel: RiskLevel.Low, | ||
| input_schema: { | ||
| type: "object", | ||
| properties: { | ||
| language: { type: "string" }, | ||
| }, | ||
| required: ["language"], | ||
| additionalProperties: false, | ||
| }, | ||
| async execute( | ||
| input: Record<string, unknown>, | ||
| _ctx: ToolContext, | ||
| ): Promise<ToolExecutionResult> { | ||
| return { | ||
| content: `hello, ${String(input.language)} speaker`, | ||
| isError: false, | ||
| }; | ||
| }, | ||
| } as const satisfies ToolDefinition; | ||
|
|
||
| // `as const` propagates literal types and verifies type compatibility, | ||
| // but the runtime expectations below also smoke-check the structure | ||
| // for anyone reading the test without TS folded in. | ||
| expect(typeof tool.execute).toBe("function"); | ||
| expect(tool.defaultRiskLevel).toBe(RiskLevel.Low); | ||
| }); | ||
|
|
||
| test("every field is optional — empty literal satisfies the interface", () => { | ||
| const tool: ToolDefinition = {}; | ||
| expect(tool).toEqual({}); | ||
| }); | ||
|
|
||
| test("every author-facing risk level is permitted", () => { | ||
| const low: ToolDefinition = { defaultRiskLevel: RiskLevel.Low }; | ||
| const medium: ToolDefinition = { defaultRiskLevel: RiskLevel.Medium }; | ||
| const high: ToolDefinition = { defaultRiskLevel: RiskLevel.High }; | ||
|
|
||
| expect(low.defaultRiskLevel).toBe(RiskLevel.Low); | ||
| expect(medium.defaultRiskLevel).toBe(RiskLevel.Medium); | ||
| expect(high.defaultRiskLevel).toBe(RiskLevel.High); | ||
| }); | ||
|
|
||
| test("execute receives the public ToolContext", async () => { | ||
| // Type-only assertion: the execute signature uses the public | ||
| // ToolContext (narrow base). A daemon-internal field added to the | ||
| // rich ToolContext that doesn't exist on the narrow one must not be | ||
| // accessible here. We can't test this at runtime — the assertion | ||
| // lives in `tsc --noEmit` over this file. | ||
| const tool: ToolDefinition = { | ||
| async execute(_input, ctx) { | ||
| // `ctx` is the public `ToolContext`. Touch | ||
| // commonly-needed fields to make sure they're present. | ||
| const _conversationId = ctx.conversationId; | ||
| const _workingDir = ctx.workingDir; | ||
| const _signal = ctx.signal; | ||
| return { content: "ok", isError: false }; | ||
| }, | ||
| }; | ||
| const result = await tool.execute?.( | ||
| {}, | ||
| { | ||
| conversationId: "conv-abc", | ||
| workingDir: "/tmp", | ||
| signal: new AbortController().signal, | ||
| } as ToolContext, | ||
| ); | ||
| expect(result?.isError).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.