cloudaxe-opencode/packages/opencode/src/tool/tool.ts

35 lines
761 B
TypeScript
Raw Normal View History

2025-05-31 21:12:16 +00:00
import type { StandardSchemaV1 } from "@standard-schema/spec"
2025-05-19 23:29:38 +00:00
2025-05-20 15:11:06 +00:00
export namespace Tool {
2025-06-11 16:44:17 +00:00
interface Metadata {
title: string
[key: string]: any
}
2025-06-02 23:51:26 +00:00
export type Context = {
sessionID: string
2025-06-10 21:56:05 +00:00
abort: AbortSignal
2025-06-02 23:51:26 +00:00
}
2025-05-31 21:12:16 +00:00
export interface Info<
Parameters extends StandardSchemaV1 = StandardSchemaV1,
2025-06-11 16:44:17 +00:00
M extends Metadata = Metadata,
2025-05-21 14:30:39 +00:00
> {
2025-05-31 21:12:16 +00:00
id: string
description: string
parameters: Parameters
2025-06-02 23:51:26 +00:00
execute(
args: StandardSchemaV1.InferOutput<Parameters>,
ctx: Context,
): Promise<{
2025-06-11 16:44:17 +00:00
metadata: M
2025-05-31 21:12:16 +00:00
output: string
}>
2025-05-31 20:05:12 +00:00
}
2025-05-21 14:30:39 +00:00
export function define<
2025-05-31 21:12:16 +00:00
Parameters extends StandardSchemaV1,
2025-06-11 16:44:17 +00:00
Result extends Metadata,
2025-05-31 21:12:16 +00:00
>(input: Info<Parameters, Result>): Info<Parameters, Result> {
return input
2025-05-20 15:11:06 +00:00
}
2025-05-19 23:29:38 +00:00
}