@vymalo/opencode-devtools 0.12.0 → 0.14.1

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/dist/tools.js CHANGED
@@ -4,88 +4,95 @@ import { selectTools } from "./catalog.js";
4
4
  const z = tool.schema;
5
5
  /** Build the full execution context, applying DI overrides. */
6
6
  export function buildContext(options, overrides) {
7
- return {
8
- options,
9
- now: overrides?.now ?? (() => new Date()),
10
- randomBytes: overrides?.randomBytes ?? ((size) => nodeRandomBytes(size)),
11
- fetchImpl: overrides?.fetchImpl ?? ((...a) => fetch(...a))
12
- };
7
+ return {
8
+ options,
9
+ now: overrides?.now ?? (() => new Date()),
10
+ randomBytes: overrides?.randomBytes ?? ((size) => nodeRandomBytes(size)),
11
+ fetchImpl: overrides?.fetchImpl ?? ((...a) => fetch(...a))
12
+ };
13
13
  }
14
14
  function fieldToZod(field) {
15
- let schema;
16
- switch (field.type) {
17
- case "string":
18
- schema = (field.enum
19
- ? z.enum(field.enum)
20
- : z.string());
21
- break;
22
- case "number":
23
- schema = z.number();
24
- break;
25
- case "boolean":
26
- schema = z.boolean();
27
- break;
28
- case "array":
29
- schema = z.array(fieldToZod(field.items));
30
- break;
31
- case "object":
32
- schema = z.object(buildShape(field.properties));
33
- break;
34
- case "record":
35
- schema = z.record(z.string(), field.valueType === "any" ? z.any() : z.string());
36
- break;
37
- }
38
- if (field.description) {
39
- schema = schema.describe(field.description);
40
- }
41
- if (field.optional) {
42
- schema = schema.optional();
43
- }
44
- return schema;
15
+ let schema;
16
+ switch (field.type) {
17
+ case "string":
18
+ schema = field.enum ? z.enum(field.enum) : z.string();
19
+ break;
20
+ case "number":
21
+ schema = z.number();
22
+ break;
23
+ case "boolean":
24
+ schema = z.boolean();
25
+ break;
26
+ case "array":
27
+ schema = z.array(fieldToZod(field.items));
28
+ break;
29
+ case "object":
30
+ schema = z.object(buildShape(field.properties));
31
+ break;
32
+ case "record":
33
+ schema = z.record(z.string(), field.valueType === "any" ? z.any() : z.string());
34
+ break;
35
+ }
36
+ if (field.description) {
37
+ schema = schema.describe(field.description);
38
+ }
39
+ if (field.optional) {
40
+ schema = schema.optional();
41
+ }
42
+ return schema;
45
43
  }
46
44
  function buildShape(input) {
47
- const shape = {};
48
- for (const [key, field] of Object.entries(input)) {
49
- shape[key] = fieldToZod(field);
50
- }
51
- return shape;
45
+ const shape = {};
46
+ for (const [key, field] of Object.entries(input)) {
47
+ shape[key] = fieldToZod(field);
48
+ }
49
+ return shape;
52
50
  }
53
51
  /** Render an adapter-neutral result into OpenCode's text-only ToolResult. */
54
52
  function renderOpenCode(result) {
55
- if (result.kind === "text") {
56
- return result.text;
57
- }
58
- const metadata = typeof result.data === "object" && result.data !== null ? result.data : { value: result.data };
59
- return { output: result.text, metadata };
53
+ if (result.kind === "text") {
54
+ return result.text;
55
+ }
56
+ const metadata = typeof result.data === "object" && result.data !== null ? result.data : { value: result.data };
57
+ return {
58
+ output: result.text,
59
+ metadata
60
+ };
60
61
  }
61
62
  /**
62
- * Build the devtools tool map registered under `Hooks.tool`, filtered to the
63
- * enabled groups. Each tool is a thin adapter over the shared catalog: validate
64
- * args (zod), run the handler with the execution context, render the result.
65
- */
63
+ * Build the devtools tool map registered under `Hooks.tool`, filtered to the
64
+ * enabled groups. Each tool is a thin adapter over the shared catalog: validate
65
+ * args (zod), run the handler with the execution context, render the result.
66
+ */
66
67
  export function createDevtoolsTools(deps) {
67
- const ctx = buildContext(deps.options, deps.context);
68
- const tools = {};
69
- for (const spec of selectTools(deps.options.groups)) {
70
- const definition = {
71
- description: spec.description,
72
- args: buildShape(spec.input),
73
- async execute(args) {
74
- deps.logger.trace("devtools_tool_invoked", { tool: spec.name, group: spec.group });
75
- try {
76
- const result = await spec.handler(args, ctx);
77
- deps.logger.trace("devtools_tool_completed", { tool: spec.name });
78
- return renderOpenCode(result);
79
- }
80
- catch (err) {
81
- const message = err instanceof Error ? err.message : String(err);
82
- deps.logger.warn("devtools_tool_failed", { tool: spec.name, error: message });
83
- throw err;
84
- }
85
- }
86
- };
87
- tools[spec.name] = definition;
88
- }
89
- return tools;
68
+ const ctx = buildContext(deps.options, deps.context);
69
+ const tools = {};
70
+ for (const spec of selectTools(deps.options.groups)) {
71
+ const definition = {
72
+ description: spec.description,
73
+ args: buildShape(spec.input),
74
+ async execute(args) {
75
+ deps.logger.trace("devtools_tool_invoked", {
76
+ tool: spec.name,
77
+ group: spec.group
78
+ });
79
+ try {
80
+ const result = await spec.handler(args, ctx);
81
+ deps.logger.trace("devtools_tool_completed", { tool: spec.name });
82
+ return renderOpenCode(result);
83
+ } catch (err) {
84
+ const message = err instanceof Error ? err.message : String(err);
85
+ deps.logger.warn("devtools_tool_failed", {
86
+ tool: spec.name,
87
+ error: message
88
+ });
89
+ throw err;
90
+ }
91
+ }
92
+ };
93
+ tools[spec.name] = definition;
94
+ }
95
+ return tools;
90
96
  }
97
+
91
98
  //# sourceMappingURL=tools.js.map
package/dist/tools.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAuB,MAAM,qBAAqB,CAAC;AAEhE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAM3C,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;AAStB,+DAA+D;AAC/D,MAAM,UAAU,YAAY,CAC1B,OAAgC,EAChC,SAAiD;IAEjD,OAAO;QACL,OAAO;QACP,GAAG,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC;QACzC,WAAW,EAAE,SAAS,EAAE,WAAW,IAAI,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAChF,SAAS,EAAE,SAAS,EAAE,SAAS,IA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O,MAAM,yBAAyB;KAAE,MAAM,KAAK;KAAM,OAAO,KAAK;IAAM,CAAC;IACjF,IAAI;KACF,MAAM,SAAS,MAAM,KAAK,QAAQ,MAAM,GAAG;KAC3C,KAAK,OAAO,MAAM,2BAA2B,EAAE,MAAM,KAAK,KAAK,CAAC;KAChE,OAAO,eAAe,MAAM;IAC9B,SAAS,KAAK;KACZ,MAAM,UAAU,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;KAC/D,KAAK,OAAO,KAAK,wBAAwB;MAAE,MAAM,KAAK;MAAM,OAAO;KAAQ,CAAC;KAC5E,MAAM;IACR;GACF;EACF;EACA,MAAM,KAAK,QAAQ;CACrB;CAEA,OAAO;AACT","names":[],"sources":["../src/tools.ts"],"version":3,"file":"tools.js","sourceRoot":""}
package/dist/types.d.ts CHANGED
@@ -2,37 +2,37 @@ import type { ToolGroup } from "./schema.js";
2
2
  export type LogLevel = "trace" | "debug" | "info" | "warn" | "error";
3
3
  export type { ToolGroup } from "./schema.js";
4
4
  /**
5
- * Per-plugin configuration, supplied as the second argument to the plugin
6
- * factory by OpenCode (the `[name, options]` tuple form in `plugin`). All
7
- * fields are optional; see DEFAULTS in opencode.ts for the resolved values.
8
- */
5
+ * Per-plugin configuration, supplied as the second argument to the plugin
6
+ * factory by OpenCode (the `[name, options]` tuple form in `plugin`). All
7
+ * fields are optional; see DEFAULTS in opencode.ts for the resolved values.
8
+ */
9
9
  export interface DevtoolsPluginOptions {
10
- /** Master switch. When false no tools are registered. */
11
- enabled?: boolean;
12
- /**
13
- * Which tool groups to register. The five deterministic, offline groups
14
- * (`math`, `codec`, `crypto`, `datetime`, `convert`) are on by default;
15
- * `http` performs network egress and is **opt-in** — add it explicitly to
16
- * enable it. Per-agent control is also possible via OpenCode's tool
17
- * allow/deny on the `math_* / codec_* / …` names.
18
- */
19
- groups?: ToolGroup[];
20
- /** Options for the opt-in `http` group. */
21
- http?: HttpOptions;
10
+ /** Master switch. When false no tools are registered. */
11
+ enabled?: boolean;
12
+ /**
13
+ * Which tool groups to register. The five deterministic, offline groups
14
+ * (`math`, `codec`, `crypto`, `datetime`, `convert`) are on by default;
15
+ * `http` performs network egress and is **opt-in** — add it explicitly to
16
+ * enable it. Per-agent control is also possible via OpenCode's tool
17
+ * allow/deny on the `math_* / codec_* / …` names.
18
+ */
19
+ groups?: ToolGroup[];
20
+ /** Options for the opt-in `http` group. */
21
+ http?: HttpOptions;
22
22
  }
23
23
  export interface HttpOptions {
24
- /**
25
- * Allow requests to loopback / private / link-local hosts (incl. the cloud
26
- * metadata IP `169.254.169.254`). Default `false` — the SSRF guard rejects
27
- * them. Turn on only when you intend the model to reach internal services.
28
- */
29
- allowPrivateNetwork?: boolean;
30
- /** Per-request timeout in ms before the call aborts. Default 30000. */
31
- timeoutMs?: number;
24
+ /**
25
+ * Allow requests to loopback / private / link-local hosts (incl. the cloud
26
+ * metadata IP `169.254.169.254`). Default `false` — the SSRF guard rejects
27
+ * them. Turn on only when you intend the model to reach internal services.
28
+ */
29
+ allowPrivateNetwork?: boolean;
30
+ /** Per-request timeout in ms before the call aborts. Default 30000. */
31
+ timeoutMs?: number;
32
32
  }
33
33
  /** Fully-resolved options with defaults applied. */
34
34
  export interface ResolvedDevtoolsOptions {
35
- enabled: boolean;
36
- groups: ToolGroup[];
37
- http: Required<HttpOptions>;
35
+ enabled: boolean;
36
+ groups: ToolGroup[];
37
+ http: Required<HttpOptions>;
38
38
  }
package/dist/types.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export {};
2
+
2
3
  //# sourceMappingURL=types.js.map
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
1
+ {"mappings":"","names":[],"sources":["../src/types.ts"],"version":3,"file":"types.js","sourceRoot":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vymalo/opencode-devtools",
3
- "version": "0.12.0",
3
+ "version": "0.14.1",
4
4
  "description": "OpenCode plugin of everyday developer utilities the model can call locally: math (precise arithmetic, unit & base conversion, stats), codec (base64/hex/url, JWT decode, gzip), crypto (hash/hmac, uuid/ulid, random, keypairs), datetime (parse/format/diff, timezones, cron explain), convert (JSON/YAML/TOML/CSV + JSONPath), and an opt-in http client. Deterministic, zero-auth, no server — tools gated into named groups.",
5
5
  "license": "MIT",
6
6
  "author": "vymalo contributors",
@@ -66,11 +66,11 @@
66
66
  "devDependencies": {
67
67
  "@types/luxon": "^3.7.1",
68
68
  "@types/papaparse": "^5.5.2",
69
- "vite": "^8.0.14",
69
+ "vite": "^8.2.1",
70
70
  "vitest": "^4.1.7"
71
71
  },
72
72
  "scripts": {
73
- "build": "tsc -p tsconfig.json",
73
+ "build": "node ../../scripts/build-package.mjs",
74
74
  "lint": "biome lint .",
75
75
  "typecheck": "tsc -p tsconfig.json --noEmit",
76
76
  "test": "vitest run",