1- export * as Tool from "./tool.js"
2-
3- import { Tool } from "../effect/tool.js"
1+ import type { Tool } from "../effect/tool.js"
42import type { Agent } from "@opencode-ai/schema/agent"
53import type { Session } from "@opencode-ai/schema/session"
64import type { SessionMessage } from "@opencode-ai/schema/session-message"
7- import { Effect , type JsonSchema , type Schema } from "effect"
5+ import type { JsonSchema , Schema } from "effect"
86import type { Hooks , Transform } from "./registration.js"
97
108export type Context = Tool . Context
119export type SchemaType < A > = Tool . SchemaType < A >
12- export type Definition < Input extends SchemaType < any > , Output extends SchemaType < any > > = Tool . Definition < Input , Output >
13- export type AnyTool = Tool . AnyTool
14- export const Failure = Tool . Failure
15- export type Failure = Tool . Failure
16- export const RegistrationError = Tool . RegistrationError
17- export type RegistrationError = Tool . RegistrationError
1810export type Content = Tool . Content
1911export type DynamicOutput = Tool . DynamicOutput
2012
21- type Config <
13+ export type Definition <
2214 Input extends SchemaType < any > ,
2315 Output extends SchemaType < any > ,
2416 Structured extends SchemaType < any > = Output ,
@@ -41,32 +33,14 @@ type Config<
4133 } ) => ReadonlyArray < Content >
4234}
4335
44- type DynamicConfig = {
36+ export type DynamicDefinition = {
4537 readonly description : string
4638 readonly jsonSchema : JsonSchema . JsonSchema
4739 readonly outputSchema ?: JsonSchema . JsonSchema
4840 readonly execute : ( input : unknown , context : Context ) => Promise < DynamicOutput >
4941}
5042
51- export function make <
52- Input extends SchemaType < any > ,
53- Output extends SchemaType < any > ,
54- Structured extends SchemaType < any > = Output ,
55- > ( config : Config < Input , Output , Structured > ) : Definition < Input , Structured >
56- export function make ( config : DynamicConfig ) : AnyTool
57- export function make ( config : Config < any , any , any > | DynamicConfig ) : AnyTool {
58- if ( "jsonSchema" in config )
59- return Tool . make ( {
60- ...config ,
61- execute : ( input , context ) => Effect . promise ( ( ) => config . execute ( input , context ) ) ,
62- } )
63- return Tool . make ( {
64- ...config ,
65- execute : ( input , context ) => Effect . promise ( ( ) => config . execute ( input , context ) ) ,
66- } )
67- }
68-
69- export const withPermission = Tool . withPermission
43+ export type AnyTool = Definition < any , any , any > | DynamicDefinition
7044
7145export interface ToolExecuteBeforeEvent {
7246 readonly tool : string
@@ -95,7 +69,12 @@ export interface RegisterOptions {
9569}
9670
9771export interface ToolDraft {
98- add ( name : string , tool : AnyTool , options ?: RegisterOptions ) : void
72+ add <
73+ Input extends SchemaType < any > ,
74+ Output extends SchemaType < any > ,
75+ Structured extends SchemaType < any > = Output ,
76+ > ( name : string , tool : Definition < Input , Output , Structured > , options ?: RegisterOptions ) : void
77+ add ( name : string , tool : DynamicDefinition , options ?: RegisterOptions ) : void
9978}
10079
10180export interface ToolHooks {
0 commit comments