@codeworksh/plugin 0.0.1-dev.20260922103030
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-rIZpnOTo.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 +200 -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-DbJEpY3M.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/error.d.mts +7 -0
- package/sandbox/error.mjs +15 -0
- package/sandbox/error.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 +17 -0
- package/sandbox.mjs +39 -0
- package/sandbox.mjs.map +1 -0
- package/schema.d.mts +91 -0
- package/schema.mjs +105 -0
- package/schema.mjs.map +1 -0
- package/settings-CYL6yyDD.d.mts +193 -0
- package/settings.d.mts +2 -0
- package/settings.mjs +102 -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
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"}
|