@codeworksh/plugin 0.0.1-canary.10.1.g65d5c167
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +111 -0
- package/error-ClDISWlT.d.mts +11 -0
- package/event-9PbbjnHJ.d.mts +895 -0
- package/event.d.mts +2 -0
- package/event.mjs +125 -0
- package/event.mjs.map +1 -0
- package/filesystem-Cp-KapCE.d.mts +142 -0
- package/ids-CHjmAdTc.d.mts +43 -0
- package/ids.d.mts +2 -0
- package/ids.mjs +48 -0
- package/ids.mjs.map +1 -0
- package/index.d.mts +3 -0
- package/index.mjs +3 -0
- package/io-BYs7hbiY.d.mts +497 -0
- package/location-D4hAfuXF.d.mts +61 -0
- package/location.d.mts +2 -0
- package/location.mjs +48 -0
- package/location.mjs.map +1 -0
- package/package.json +169 -0
- package/plugin/prompt.d.mts +2 -0
- package/plugin/prompt.mjs +7 -0
- package/plugin/prompt.mjs.map +1 -0
- package/plugin/tool.d.mts +2 -0
- package/plugin/tool.mjs +29 -0
- package/plugin/tool.mjs.map +1 -0
- package/plugin-DHCdfzdO.d.mts +140 -0
- package/plugin-lorpq7Oi.mjs +41 -0
- package/plugin-lorpq7Oi.mjs.map +1 -0
- package/plugin.d.mts +4 -0
- package/plugin.mjs +4 -0
- package/posix.d.mts +6 -0
- package/posix.mjs +8 -0
- package/posix.mjs.map +1 -0
- package/project-CLGsIFD-.d.mts +21 -0
- package/project.d.mts +2 -0
- package/project.mjs +22 -0
- package/project.mjs.map +1 -0
- package/prompt-BcpagjGh.d.mts +10 -0
- package/repo.d.mts +42 -0
- package/repo.mjs +46 -0
- package/repo.mjs.map +1 -0
- package/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/sandbox/driver.d.mts +2 -0
- package/sandbox/driver.mjs +63 -0
- package/sandbox/driver.mjs.map +1 -0
- package/sandbox/errors.d.mts +2 -0
- package/sandbox/errors.mjs +160 -0
- package/sandbox/errors.mjs.map +1 -0
- package/sandbox/filesystem.d.mts +2 -0
- package/sandbox/filesystem.mjs +142 -0
- package/sandbox/filesystem.mjs.map +1 -0
- package/sandbox/instance.d.mts +2 -0
- package/sandbox/instance.mjs +144 -0
- package/sandbox/instance.mjs.map +1 -0
- package/sandbox/io.d.mts +2 -0
- package/sandbox/io.mjs +127 -0
- package/sandbox/io.mjs.map +1 -0
- package/sandbox/resource.d.mts +28 -0
- package/sandbox/resource.mjs +29 -0
- package/sandbox/resource.mjs.map +1 -0
- package/sandbox/shell.d.mts +2 -0
- package/sandbox/shell.mjs +93 -0
- package/sandbox/shell.mjs.map +1 -0
- package/sandbox.d.mts +19 -0
- package/sandbox.mjs +49 -0
- package/sandbox.mjs.map +1 -0
- package/schema.d.mts +93 -0
- package/schema.mjs +107 -0
- package/schema.mjs.map +1 -0
- package/settings-C6RxGd-M.d.mts +557 -0
- package/settings.d.mts +2 -0
- package/settings.mjs +132 -0
- package/settings.mjs.map +1 -0
- package/shell-CZ6Y4lNU.d.mts +109 -0
- package/space-CR-9UxdT.d.mts +25 -0
- package/space.d.mts +2 -0
- package/space.mjs +33 -0
- package/space.mjs.map +1 -0
- package/tool/error.d.mts +2 -0
- package/tool/error.mjs +11 -0
- package/tool/error.mjs.map +1 -0
- package/tool/progress.d.mts +2 -0
- package/tool/progress.mjs +11 -0
- package/tool/progress.mjs.map +1 -0
- package/tool-BoVqkYvL.d.mts +287 -0
- package/tool-DuYBgiJf.d.mts +142 -0
- package/tool.d.mts +2 -0
- package/tool.mjs +71 -0
- package/tool.mjs.map +1 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { t as ToolExecutionError } from "./error-ClDISWlT.mjs";
|
|
2
|
+
import { Message } from "@codeworksh/aikit";
|
|
3
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
4
|
+
//#region src/tool/progress.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* `ToolProgress` — the side-channel a long-running tool (e.g. streaming bash)
|
|
7
|
+
* writes interim output to, instead of an `onUpdate` callback.
|
|
8
|
+
*
|
|
9
|
+
* Most tools never call `report` and keep a clean `Effect<Success, Failure>`
|
|
10
|
+
* signature. Throttling / coalescing lives in the Layer (the live one routes to
|
|
11
|
+
* the run's event PubSub, tagged with the active callID); the handler just
|
|
12
|
+
* reports.
|
|
13
|
+
*/
|
|
14
|
+
/** Mirror of aikit's `Message.ToolRunningPartial` (kept structural to stay decoupled). */
|
|
15
|
+
interface ToolProgressPartial {
|
|
16
|
+
readonly content?: ModelContent;
|
|
17
|
+
readonly details?: unknown;
|
|
18
|
+
}
|
|
19
|
+
interface IToolProgress {
|
|
20
|
+
readonly report: (partial: ToolProgressPartial) => Effect.Effect<void>;
|
|
21
|
+
}
|
|
22
|
+
declare const ToolProgress_base: Context.ServiceClass<ToolProgress, "@codeworksh/plugin/tool/progress/ToolProgress", IToolProgress>;
|
|
23
|
+
declare class ToolProgress extends ToolProgress_base {}
|
|
24
|
+
/** Build a `ToolProgress` Layer from a `report` implementation. */
|
|
25
|
+
declare const make$1: (report: IToolProgress["report"]) => Layer.Layer<ToolProgress>;
|
|
26
|
+
/** Drops every update — the default until the executor wires a live event sink. */
|
|
27
|
+
declare const noop: Layer.Layer<ToolProgress>;
|
|
28
|
+
declare namespace tool_d_exports {
|
|
29
|
+
export { AnyToolDef, AnyToolImpl, Handler, ModelContent, RegisteredTool, ToolCallContext, ToolDef, ToolImpl, define, implement, make, provide, register, toAikitTool, toProviderJsonSchema };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The tool definition + handler model.
|
|
33
|
+
*
|
|
34
|
+
* A tool definition is pure, serializable data: name, description, and Effect
|
|
35
|
+
* Schema for parameters / success / failure. Execution is a separate `Handler`
|
|
36
|
+
* — an `Effect` whose capability dependencies (e.g. `ToolShell`) live in its
|
|
37
|
+
* requirements `R`, provided by a Layer at runtime. Separating the two is the
|
|
38
|
+
* main testing win: assert on the definition as plain data, and run the handler
|
|
39
|
+
* against a stub capability Layer.
|
|
40
|
+
*
|
|
41
|
+
* Effect Schema is the single source of truth. {@link toAikitTool} derives a
|
|
42
|
+
* provider-safe JSON Schema object for the aikit wire view; the harness
|
|
43
|
+
* decode/encodes arguments and results with Effect Schema natively (it does not
|
|
44
|
+
* use aikit's Typebox validators).
|
|
45
|
+
*/
|
|
46
|
+
/** What the model reads next turn (the `content` side of content/details). */
|
|
47
|
+
type ModelContent = ReadonlyArray<Message.TextContent | Message.ImageContent>;
|
|
48
|
+
/** Per-call metadata handed to a handler instead of positional args. */
|
|
49
|
+
declare const ToolCallContext: Schema.Struct<{
|
|
50
|
+
readonly callID: Schema.String;
|
|
51
|
+
readonly toolName: Schema.String;
|
|
52
|
+
readonly rawArgs: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
53
|
+
}>;
|
|
54
|
+
type ToolCallContext = typeof ToolCallContext.Type;
|
|
55
|
+
/**
|
|
56
|
+
* A pure tool definition. Parametrised over the *schema* instances so the
|
|
57
|
+
* decoded parameter/success/failure types can be recovered via `["Type"]`.
|
|
58
|
+
*/
|
|
59
|
+
interface ToolDef<Name extends string = string, Params extends Schema.Top = Schema.Top, Success extends Schema.Top = Schema.Top, Failure extends Schema.Top = Schema.Top> {
|
|
60
|
+
readonly name: Name;
|
|
61
|
+
readonly description: string;
|
|
62
|
+
/** Human-readable display label (kept from the previous `AgentTool`). */
|
|
63
|
+
readonly label?: string;
|
|
64
|
+
/**
|
|
65
|
+
* A short one-line summary for compact tool listings (e.g. a system-prompt tool index),
|
|
66
|
+
* distinct from the fuller `description`.
|
|
67
|
+
*/
|
|
68
|
+
readonly promptSnippet?: string;
|
|
69
|
+
/** Optional guideline bullets appended to the default system prompt Guidelines section when this tool is active. */
|
|
70
|
+
readonly promptGuidelines?: ReadonlyArray<string>;
|
|
71
|
+
readonly parameters: Params;
|
|
72
|
+
readonly success: Success;
|
|
73
|
+
/** Declared, model-visible failures (typed). Omit for tools that cannot fail expectedly. */
|
|
74
|
+
readonly failure?: Failure;
|
|
75
|
+
/** Render success for the model. Omit → executor falls back to JSON text. */
|
|
76
|
+
readonly encodeContent?: (success: Success["Type"]) => ModelContent;
|
|
77
|
+
/** Render an expected failure for the model. Omit → executor falls back to JSON text. */
|
|
78
|
+
readonly encodeFailureContent?: (failure: Failure["Type"]) => ModelContent;
|
|
79
|
+
}
|
|
80
|
+
/** A handler: validated params + context → typed success or typed failure. */
|
|
81
|
+
type Handler<Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top, R = never> = (params: Params["Type"], ctx: ToolCallContext) => Effect.Effect<Success["Type"], Failure["Type"], R>;
|
|
82
|
+
/** A definition paired with its handler (the unit the executor runs). */
|
|
83
|
+
interface ToolImpl<Name extends string = string, Params extends Schema.Top = Schema.Top, Success extends Schema.Top = Schema.Top, Failure extends Schema.Top = Schema.Top, R = never> {
|
|
84
|
+
readonly definition: ToolDef<Name, Params, Success, Failure>;
|
|
85
|
+
readonly handler: Handler<Params, Success, Failure, R>;
|
|
86
|
+
}
|
|
87
|
+
type AnyToolDef = ToolDef<string, any, any, any>;
|
|
88
|
+
type AnyToolImpl<R = never> = ToolImpl<string, any, any, any, R>;
|
|
89
|
+
interface DefineInput<Name extends string, Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top> {
|
|
90
|
+
readonly name: Name;
|
|
91
|
+
readonly description: string;
|
|
92
|
+
readonly label?: string;
|
|
93
|
+
readonly promptSnippet?: string;
|
|
94
|
+
readonly parameters: Params;
|
|
95
|
+
readonly success: Success;
|
|
96
|
+
readonly failure?: Failure;
|
|
97
|
+
readonly encodeContent?: (success: Success["Type"]) => ModelContent;
|
|
98
|
+
readonly encodeFailureContent?: (failure: Failure["Type"]) => ModelContent;
|
|
99
|
+
}
|
|
100
|
+
/** Define a pure tool (handler attached later via {@link implement} or a toolkit). */
|
|
101
|
+
declare const define: <Name extends string, Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top = Schema.Top>(input: DefineInput<Name, Params, Success, Failure>) => ToolDef<Name, Params, Success, Failure>;
|
|
102
|
+
/** Attach a handler to an existing definition (the testable def/exec split). */
|
|
103
|
+
declare const implement: <Name extends string, Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top, R = never>(definition: ToolDef<Name, Params, Success, Failure>, handler: Handler<Params, Success, Failure, R>) => ToolImpl<Name, Params, Success, Failure, R>;
|
|
104
|
+
/** Sugar for the co-located case: a definition with its handler in one object. */
|
|
105
|
+
declare const make: <Name extends string, Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top = Schema.Top, R = never>(input: DefineInput<Name, Params, Success, Failure> & {
|
|
106
|
+
readonly handler: Handler<Params, Success, Failure, R>;
|
|
107
|
+
}) => ToolImpl<Name, Params, Success, Failure, R>;
|
|
108
|
+
/**
|
|
109
|
+
* A tool ready to register: its capability requirements have been discharged, leaving only
|
|
110
|
+
* the executor-provided {@link ToolProgress}. The registry and executor hold `RegisteredTool`s
|
|
111
|
+
* and are non-generic (only `handle` is generic, over a progress sink's `RProgress`), so any
|
|
112
|
+
* number of tools — built-in or
|
|
113
|
+
* third-party/plugin — compose without a shared capability union
|
|
114
|
+
*/
|
|
115
|
+
interface RegisteredTool {
|
|
116
|
+
readonly definition: AnyToolDef;
|
|
117
|
+
readonly handler: (params: unknown, ctx: ToolCallContext) => Effect.Effect<unknown, ToolExecutionError, ToolProgress>;
|
|
118
|
+
}
|
|
119
|
+
/** Register a tool whose only requirement is the executor-provided progress service. */
|
|
120
|
+
declare const register: <Name extends string, Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top>(impl: ToolImpl<Name, Params, Success, Failure, ToolProgress>) => RegisteredTool;
|
|
121
|
+
/**
|
|
122
|
+
* Discharge a tool's capability requirements into a {@link RegisteredTool}, erasing its `R`
|
|
123
|
+
* (the executor still provides `ToolProgress`). This is the registration boundary: a
|
|
124
|
+
* plugin/third-party tool provides its own fully-resolved capability Layer here, so the
|
|
125
|
+
* registry never has to unify anyone's `R`.
|
|
126
|
+
*/
|
|
127
|
+
declare const provide: <Name extends string, Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top, R>(impl: ToolImpl<Name, Params, Success, Failure, R | ToolProgress>, layer: Layer.Layer<R>) => RegisteredTool;
|
|
128
|
+
/**
|
|
129
|
+
* Derive a provider-safe JSON Schema object from an Effect Schema. This is the
|
|
130
|
+
* single boundary that crosses into the provider wire; if a provider rejects a
|
|
131
|
+
* construct, fix it here. Draft-07 inlines the root (no top-level `$ref`).
|
|
132
|
+
*/
|
|
133
|
+
declare const toProviderJsonSchema: (schema: Schema.Top) => Record<string, unknown>;
|
|
134
|
+
/**
|
|
135
|
+
* Build the aikit `Message.Tool` wire view from a definition. The derived JSON
|
|
136
|
+
* Schema object satisfies aikit's `parameters` slot structurally at runtime; the
|
|
137
|
+
* single localized cast keeps aikit untouched (decision 3-A).
|
|
138
|
+
*/
|
|
139
|
+
declare const toAikitTool: (def: AnyToolDef) => Message.Tool;
|
|
140
|
+
//#endregion
|
|
141
|
+
export { IToolProgress as _, RegisteredTool as a, make$1 as b, ToolImpl as c, make as d, provide as f, tool_d_exports as g, toProviderJsonSchema as h, ModelContent as i, define as l, toAikitTool as m, AnyToolImpl as n, ToolCallContext as o, register as p, Handler as r, ToolDef as s, AnyToolDef as t, implement as u, ToolProgress as v, noop as x, ToolProgressPartial as y };
|
|
142
|
+
//# sourceMappingURL=tool-DuYBgiJf.d.mts.map
|
package/tool.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as RegisteredTool, c as ToolImpl, d as make, f as provide, h as toProviderJsonSchema, i as ModelContent, l as define, m as toAikitTool, n as AnyToolImpl, o as ToolCallContext, p as register, r as Handler, s as ToolDef, t as AnyToolDef, u as implement } from "./tool-DuYBgiJf.mjs";
|
|
2
|
+
export { AnyToolDef, AnyToolImpl, Handler, ModelContent, RegisteredTool, ToolCallContext, ToolDef, ToolImpl, define, implement, make, provide, register, toAikitTool, toProviderJsonSchema };
|
package/tool.mjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { ToolExecutionError } from "./tool/error.mjs";
|
|
3
|
+
import { Effect, Schema } from "effect";
|
|
4
|
+
//#region src/tool.ts
|
|
5
|
+
var tool_exports = /* @__PURE__ */ __exportAll({
|
|
6
|
+
ToolCallContext: () => ToolCallContext,
|
|
7
|
+
define: () => define,
|
|
8
|
+
implement: () => implement,
|
|
9
|
+
make: () => make,
|
|
10
|
+
provide: () => provide,
|
|
11
|
+
register: () => register,
|
|
12
|
+
toAikitTool: () => toAikitTool,
|
|
13
|
+
toProviderJsonSchema: () => toProviderJsonSchema
|
|
14
|
+
});
|
|
15
|
+
/** Per-call metadata handed to a handler instead of positional args. */
|
|
16
|
+
const ToolCallContext = Schema.Struct({
|
|
17
|
+
callID: Schema.String,
|
|
18
|
+
toolName: Schema.String,
|
|
19
|
+
rawArgs: Schema.Record(Schema.String, Schema.Unknown)
|
|
20
|
+
});
|
|
21
|
+
/** Define a pure tool (handler attached later via {@link implement} or a toolkit). */
|
|
22
|
+
const define = (input) => ({ ...input });
|
|
23
|
+
/** Attach a handler to an existing definition (the testable def/exec split). */
|
|
24
|
+
const implement = (definition, handler) => ({
|
|
25
|
+
definition,
|
|
26
|
+
handler
|
|
27
|
+
});
|
|
28
|
+
/** Sugar for the co-located case: a definition with its handler in one object. */
|
|
29
|
+
const make = (input) => {
|
|
30
|
+
const { handler, ...rest } = input;
|
|
31
|
+
return {
|
|
32
|
+
definition: define(rest),
|
|
33
|
+
handler
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const toRegistered = (definition, handler) => ({
|
|
37
|
+
definition,
|
|
38
|
+
handler: (params, ctx) => handler(params, ctx).pipe(Effect.mapError((cause) => new ToolExecutionError({
|
|
39
|
+
toolName: definition.name,
|
|
40
|
+
cause
|
|
41
|
+
})))
|
|
42
|
+
});
|
|
43
|
+
/** Register a tool whose only requirement is the executor-provided progress service. */
|
|
44
|
+
const register = (impl) => toRegistered(impl.definition, impl.handler);
|
|
45
|
+
/**
|
|
46
|
+
* Discharge a tool's capability requirements into a {@link RegisteredTool}, erasing its `R`
|
|
47
|
+
* (the executor still provides `ToolProgress`). This is the registration boundary: a
|
|
48
|
+
* plugin/third-party tool provides its own fully-resolved capability Layer here, so the
|
|
49
|
+
* registry never has to unify anyone's `R`.
|
|
50
|
+
*/
|
|
51
|
+
const provide = (impl, layer) => toRegistered(impl.definition, ((params, ctx) => impl.handler(params, ctx).pipe(Effect.provide(layer))));
|
|
52
|
+
/**
|
|
53
|
+
* Derive a provider-safe JSON Schema object from an Effect Schema. This is the
|
|
54
|
+
* single boundary that crosses into the provider wire; if a provider rejects a
|
|
55
|
+
* construct, fix it here. Draft-07 inlines the root (no top-level `$ref`).
|
|
56
|
+
*/
|
|
57
|
+
const toProviderJsonSchema = (schema) => Schema.toStandardJSONSchemaV1(schema)["~standard"].jsonSchema.input({ target: "draft-07" });
|
|
58
|
+
/**
|
|
59
|
+
* Build the aikit `Message.Tool` wire view from a definition. The derived JSON
|
|
60
|
+
* Schema object satisfies aikit's `parameters` slot structurally at runtime; the
|
|
61
|
+
* single localized cast keeps aikit untouched (decision 3-A).
|
|
62
|
+
*/
|
|
63
|
+
const toAikitTool = (def) => ({
|
|
64
|
+
name: def.name,
|
|
65
|
+
description: def.description,
|
|
66
|
+
parameters: toProviderJsonSchema(def.parameters)
|
|
67
|
+
});
|
|
68
|
+
//#endregion
|
|
69
|
+
export { ToolCallContext, define, implement, make, provide, register, tool_exports as t, toAikitTool, toProviderJsonSchema };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=tool.mjs.map
|
package/tool.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.mjs","names":[],"sources":["../../src/tool.ts"],"sourcesContent":["import type { Message } from \"@codeworksh/aikit\";\nimport { Effect, type Layer, Schema } from \"effect\";\nimport type { TSchema } from \"typebox\";\nimport { ToolExecutionError } from \"./tool/error.ts\";\nimport type { ToolProgress } from \"./tool/progress.ts\";\n\n/**\n * The tool definition + handler model.\n *\n * A tool definition is pure, serializable data: name, description, and Effect\n * Schema for parameters / success / failure. Execution is a separate `Handler`\n * — an `Effect` whose capability dependencies (e.g. `ToolShell`) live in its\n * requirements `R`, provided by a Layer at runtime. Separating the two is the\n * main testing win: assert on the definition as plain data, and run the handler\n * against a stub capability Layer.\n *\n * Effect Schema is the single source of truth. {@link toAikitTool} derives a\n * provider-safe JSON Schema object for the aikit wire view; the harness\n * decode/encodes arguments and results with Effect Schema natively (it does not\n * use aikit's Typebox validators).\n */\n\n/** What the model reads next turn (the `content` side of content/details). */\nexport type ModelContent = ReadonlyArray<Message.TextContent | Message.ImageContent>;\n\n/** Per-call metadata handed to a handler instead of positional args. */\nexport const ToolCallContext = Schema.Struct({\n\tcallID: Schema.String,\n\ttoolName: Schema.String,\n\trawArgs: Schema.Record(Schema.String, Schema.Unknown),\n});\nexport type ToolCallContext = typeof ToolCallContext.Type;\n\n/**\n * A pure tool definition. Parametrised over the *schema* instances so the\n * decoded parameter/success/failure types can be recovered via `[\"Type\"]`.\n */\nexport interface ToolDef<\n\tName extends string = string,\n\tParams extends Schema.Top = Schema.Top,\n\tSuccess extends Schema.Top = Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n> {\n\treadonly name: Name;\n\treadonly description: string;\n\t/** Human-readable display label (kept from the previous `AgentTool`). */\n\treadonly label?: string;\n\t/**\n\t * A short one-line summary for compact tool listings (e.g. a system-prompt tool index),\n\t * distinct from the fuller `description`.\n\t */\n\treadonly promptSnippet?: string;\n\t/** Optional guideline bullets appended to the default system prompt Guidelines section when this tool is active. */\n\treadonly promptGuidelines?: ReadonlyArray<string>;\n\treadonly parameters: Params;\n\treadonly success: Success;\n\t/** Declared, model-visible failures (typed). Omit for tools that cannot fail expectedly. */\n\treadonly failure?: Failure;\n\t/** Render success for the model. Omit → executor falls back to JSON text. */\n\treadonly encodeContent?: (success: Success[\"Type\"]) => ModelContent;\n\t/** Render an expected failure for the model. Omit → executor falls back to JSON text. */\n\treadonly encodeFailureContent?: (failure: Failure[\"Type\"]) => ModelContent;\n}\n\n/** A handler: validated params + context → typed success or typed failure. */\nexport type Handler<Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top, R = never> = (\n\tparams: Params[\"Type\"],\n\tctx: ToolCallContext,\n) => Effect.Effect<Success[\"Type\"], Failure[\"Type\"], R>;\n\n/** A definition paired with its handler (the unit the executor runs). */\nexport interface ToolImpl<\n\tName extends string = string,\n\tParams extends Schema.Top = Schema.Top,\n\tSuccess extends Schema.Top = Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n\tR = never,\n> {\n\treadonly definition: ToolDef<Name, Params, Success, Failure>;\n\treadonly handler: Handler<Params, Success, Failure, R>;\n}\n\n// Heterogeneous-collection aliases. `any` for the schema generics keeps handlers\n// of differing parameter types assignable into one array (the precise generics\n// live on the authoring helpers below).\n// biome-ignore lint/suspicious/noExplicitAny: erased schema generics for storage\nexport type AnyToolDef = ToolDef<string, any, any, any>;\n// biome-ignore lint/suspicious/noExplicitAny: erased schema generics for storage\nexport type AnyToolImpl<R = never> = ToolImpl<string, any, any, any, R>;\n\ninterface DefineInput<\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n> {\n\treadonly name: Name;\n\treadonly description: string;\n\treadonly label?: string;\n\treadonly promptSnippet?: string;\n\treadonly parameters: Params;\n\treadonly success: Success;\n\treadonly failure?: Failure;\n\treadonly encodeContent?: (success: Success[\"Type\"]) => ModelContent;\n\treadonly encodeFailureContent?: (failure: Failure[\"Type\"]) => ModelContent;\n}\n\n/** Define a pure tool (handler attached later via {@link implement} or a toolkit). */\nexport const define = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n>(\n\tinput: DefineInput<Name, Params, Success, Failure>,\n): ToolDef<Name, Params, Success, Failure> => ({\n\t...input,\n});\n\n/** Attach a handler to an existing definition (the testable def/exec split). */\nexport const implement = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n\tR = never,\n>(\n\tdefinition: ToolDef<Name, Params, Success, Failure>,\n\thandler: Handler<Params, Success, Failure, R>,\n): ToolImpl<Name, Params, Success, Failure, R> => ({ definition, handler });\n\n/** Sugar for the co-located case: a definition with its handler in one object. */\nexport const make = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n\tR = never,\n>(\n\tinput: DefineInput<Name, Params, Success, Failure> & {\n\t\treadonly handler: Handler<Params, Success, Failure, R>;\n\t},\n): ToolImpl<Name, Params, Success, Failure, R> => {\n\tconst { handler, ...rest } = input;\n\treturn { definition: define(rest), handler };\n};\n\n/**\n * A tool ready to register: its capability requirements have been discharged, leaving only\n * the executor-provided {@link ToolProgress}. The registry and executor hold `RegisteredTool`s\n * and are non-generic (only `handle` is generic, over a progress sink's `RProgress`), so any\n * number of tools — built-in or\n * third-party/plugin — compose without a shared capability union\n */\nexport interface RegisteredTool {\n\treadonly definition: AnyToolDef;\n\treadonly handler: (\n\t\tparams: unknown,\n\t\tctx: ToolCallContext,\n\t) => Effect.Effect<unknown, ToolExecutionError, ToolProgress>;\n}\n\nconst toRegistered = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n>(\n\tdefinition: ToolDef<Name, Params, Success, Failure>,\n\thandler: Handler<Params, Success, Failure, ToolProgress>,\n): RegisteredTool => ({\n\tdefinition,\n\t// The executor decodes with `definition.parameters` before invoking this\n\t// erased handler, so restoring the authored parameter type is safe here.\n\thandler: (params, ctx) =>\n\t\thandler(params as Params[\"Type\"], ctx).pipe(\n\t\t\tEffect.mapError((cause) => new ToolExecutionError({ toolName: definition.name, cause })),\n\t\t),\n});\n\n/** Register a tool whose only requirement is the executor-provided progress service. */\nexport const register = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n>(\n\timpl: ToolImpl<Name, Params, Success, Failure, ToolProgress>,\n): RegisteredTool => toRegistered(impl.definition, impl.handler);\n\n/**\n * Discharge a tool's capability requirements into a {@link RegisteredTool}, erasing its `R`\n * (the executor still provides `ToolProgress`). This is the registration boundary: a\n * plugin/third-party tool provides its own fully-resolved capability Layer here, so the\n * registry never has to unify anyone's `R`.\n */\nexport const provide = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n\tR,\n>(\n\timpl: ToolImpl<Name, Params, Success, Failure, R | ToolProgress>,\n\tlayer: Layer.Layer<R>,\n): RegisteredTool =>\n\t// `Effect.provide` discharges `R`, leaving `ToolProgress`. TS can't simplify\n\t// `Exclude<ToolProgress, R>` for a generic `R`, so localize the cast before\n\t// crossing the registered-tool boundary.\n\ttoRegistered(impl.definition, ((params, ctx) => impl.handler(params, ctx).pipe(Effect.provide(layer))) as Handler<\n\t\tParams,\n\t\tSuccess,\n\t\tFailure,\n\t\tToolProgress\n\t>);\n\n/**\n * Derive a provider-safe JSON Schema object from an Effect Schema. This is the\n * single boundary that crosses into the provider wire; if a provider rejects a\n * construct, fix it here. Draft-07 inlines the root (no top-level `$ref`).\n */\nexport const toProviderJsonSchema = (schema: Schema.Top): Record<string, unknown> =>\n\tSchema.toStandardJSONSchemaV1(schema)[\"~standard\"].jsonSchema.input({ target: \"draft-07\" });\n\n/**\n * Build the aikit `Message.Tool` wire view from a definition. The derived JSON\n * Schema object satisfies aikit's `parameters` slot structurally at runtime; the\n * single localized cast keeps aikit untouched (decision 3-A).\n */\nexport const toAikitTool = (def: AnyToolDef): Message.Tool => ({\n\tname: def.name,\n\tdescription: def.description,\n\tparameters: toProviderJsonSchema(def.parameters) as unknown as TSchema,\n});\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAa,kBAAkB,OAAO,OAAO;CAC5C,QAAQ,OAAO;CACf,UAAU,OAAO;CACjB,SAAS,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO;AACrD,CAAC;;AA8ED,MAAa,UAMZ,WAC8C,EAC9C,GAAG,MACJ;;AAGA,MAAa,aAOZ,YACA,aACkD;CAAE;CAAY;AAAQ;;AAGzE,MAAa,QAOZ,UAGiD;CACjD,MAAM,EAAE,SAAS,GAAG,SAAS;CAC7B,OAAO;EAAE,YAAY,OAAO,IAAI;EAAG;CAAQ;AAC5C;AAiBA,MAAM,gBAML,YACA,aACqB;CACrB;CAGA,UAAU,QAAQ,QACjB,QAAQ,QAA0B,GAAG,CAAC,CAAC,KACtC,OAAO,UAAU,UAAU,IAAI,mBAAmB;EAAE,UAAU,WAAW;EAAM;CAAM,CAAC,CAAC,CACxF;AACF;;AAGA,MAAa,YAMZ,SACoB,aAAa,KAAK,YAAY,KAAK,OAAO;;;;;;;AAQ/D,MAAa,WAOZ,MACA,UAKA,aAAa,KAAK,cAAc,QAAQ,QAAQ,KAAK,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK,OAAO,QAAQ,KAAK,CAAC,EAKnG;;;;;;AAOF,MAAa,wBAAwB,WACpC,OAAO,uBAAuB,MAAM,CAAC,CAAC,YAAY,CAAC,WAAW,MAAM,EAAE,QAAQ,WAAW,CAAC;;;;;;AAO3F,MAAa,eAAe,SAAmC;CAC9D,MAAM,IAAI;CACV,aAAa,IAAI;CACjB,YAAY,qBAAqB,IAAI,UAAU;AAChD"}
|