refactor(plugin): include name in promise tools
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
export * as PluginPromise from "./promise"
|
export * as PluginPromise from "./promise"
|
||||||
|
|
||||||
import { Plugin } from "@opencode-ai/plugin/v2/effect"
|
import { Plugin } from "@opencode-ai/plugin/v2/effect"
|
||||||
import type { AnyTool, RegisterOptions } from "@opencode-ai/plugin/v2/tool"
|
import type { AnyTool } from "@opencode-ai/plugin/v2/tool"
|
||||||
import { Effect, Scope, Stream } from "effect"
|
import { Effect, Scope, Stream } from "effect"
|
||||||
import { Tool } from "../tool/tool"
|
import { Tool } from "../tool/tool"
|
||||||
|
|
||||||
@@ -114,8 +114,7 @@ export function fromPromise(plugin: PromisePlugin) {
|
|||||||
register(
|
register(
|
||||||
host.tool.transform((draft) =>
|
host.tool.transform((draft) =>
|
||||||
callback({
|
callback({
|
||||||
add: (name: string, tool: AnyTool, options?: RegisterOptions) =>
|
add: (tool: AnyTool) => draft.add(tool.name, fromPromiseTool(tool), tool.options),
|
||||||
draft.add(name, fromPromiseTool(tool), options),
|
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -106,7 +106,8 @@ describe("fromPromise", () => {
|
|||||||
id: "promise-tool",
|
id: "promise-tool",
|
||||||
setup: async (ctx) => {
|
setup: async (ctx) => {
|
||||||
await ctx.tool.transform((tools) => {
|
await ctx.tool.transform((tools) => {
|
||||||
tools.add("hello", {
|
tools.add({
|
||||||
|
name: "hello",
|
||||||
description: "Hello",
|
description: "Hello",
|
||||||
input: Schema.Struct({ name: Schema.String }),
|
input: Schema.Struct({ name: Schema.String }),
|
||||||
output: Schema.String,
|
output: Schema.String,
|
||||||
|
|||||||
@@ -282,7 +282,8 @@ export default Plugin.define({
|
|||||||
id: "acme.greeting",
|
id: "acme.greeting",
|
||||||
setup: async (ctx) => {
|
setup: async (ctx) => {
|
||||||
await ctx.tool.transform((tools) => {
|
await ctx.tool.transform((tools) => {
|
||||||
tools.add("greeting", {
|
tools.add({
|
||||||
|
name: "greeting",
|
||||||
description: "Create a greeting",
|
description: "Create a greeting",
|
||||||
input: Schema.Struct({ name: Schema.String }),
|
input: Schema.Struct({ name: Schema.String }),
|
||||||
output: Schema.String,
|
output: Schema.String,
|
||||||
@@ -295,8 +296,8 @@ export default Plugin.define({
|
|||||||
|
|
||||||
Unsupported characters in tool and group names are normalized to underscores.
|
Unsupported characters in tool and group names are normalized to underscores.
|
||||||
The resulting exposed key must begin with a letter and contain at most 64
|
The resulting exposed key must begin with a letter and contain at most 64
|
||||||
letters, digits, underscores, or hyphens. `tools.add` also accepts
|
letters, digits, underscores, or hyphens. Set `options` on the declaration to
|
||||||
`{ group, deferred }`:
|
configure registration with `{ group, deferred }`:
|
||||||
|
|
||||||
- `group` prefixes and groups the exposed tool name.
|
- `group` prefixes and groups the exposed tool name.
|
||||||
- `deferred: true` makes the tool available through the deferred `execute`
|
- `deferred: true` makes the tool available through the deferred `execute`
|
||||||
|
|||||||
@@ -91,7 +91,8 @@ Promise tools use plain object declarations with async executors:
|
|||||||
import { Schema } from "effect"
|
import { Schema } from "effect"
|
||||||
|
|
||||||
await ctx.tool.transform((tools) => {
|
await ctx.tool.transform((tools) => {
|
||||||
tools.add("echo", {
|
tools.add({
|
||||||
|
name: "echo",
|
||||||
description: "Echo text",
|
description: "Echo text",
|
||||||
input: Schema.Struct({ text: Schema.String }),
|
input: Schema.Struct({ text: Schema.String }),
|
||||||
output: Schema.Struct({ text: Schema.String }),
|
output: Schema.Struct({ text: Schema.String }),
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ export type Definition<
|
|||||||
Output extends SchemaType<any>,
|
Output extends SchemaType<any>,
|
||||||
Structured extends SchemaType<any> = Output,
|
Structured extends SchemaType<any> = Output,
|
||||||
> = {
|
> = {
|
||||||
|
readonly name: string
|
||||||
|
readonly options?: RegisterOptions
|
||||||
readonly description: string
|
readonly description: string
|
||||||
readonly input: Input
|
readonly input: Input
|
||||||
readonly output: Output
|
readonly output: Output
|
||||||
@@ -34,6 +36,8 @@ export type Definition<
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type DynamicDefinition = {
|
export type DynamicDefinition = {
|
||||||
|
readonly name: string
|
||||||
|
readonly options?: RegisterOptions
|
||||||
readonly description: string
|
readonly description: string
|
||||||
readonly jsonSchema: JsonSchema.JsonSchema
|
readonly jsonSchema: JsonSchema.JsonSchema
|
||||||
readonly outputSchema?: JsonSchema.JsonSchema
|
readonly outputSchema?: JsonSchema.JsonSchema
|
||||||
@@ -73,8 +77,8 @@ export interface ToolDraft {
|
|||||||
Input extends SchemaType<any>,
|
Input extends SchemaType<any>,
|
||||||
Output extends SchemaType<any>,
|
Output extends SchemaType<any>,
|
||||||
Structured extends SchemaType<any> = Output,
|
Structured extends SchemaType<any> = Output,
|
||||||
>(name: string, tool: Definition<Input, Output, Structured>, options?: RegisterOptions): void
|
>(tool: Definition<Input, Output, Structured>): void
|
||||||
add(name: string, tool: DynamicDefinition, options?: RegisterOptions): void
|
add(tool: DynamicDefinition): void
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ToolHooks {
|
export interface ToolHooks {
|
||||||
|
|||||||
Reference in New Issue
Block a user