@vymalo/opencode-devtools 0.12.0 → 0.14.0
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/catalog.d.ts +7 -7
- package/dist/catalog.js +27 -26
- package/dist/catalog.js.map +1 -1
- package/dist/groups/codec.js +162 -135
- package/dist/groups/codec.js.map +1 -1
- package/dist/groups/convert.js +116 -89
- package/dist/groups/convert.js.map +1 -1
- package/dist/groups/crypto.js +247 -186
- package/dist/groups/crypto.js.map +1 -1
- package/dist/groups/datetime.js +265 -215
- package/dist/groups/datetime.js.map +1 -1
- package/dist/groups/http.d.ts +6 -6
- package/dist/groups/http.js +272 -248
- package/dist/groups/http.js.map +1 -1
- package/dist/groups/math.js +157 -127
- package/dist/groups/math.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib.js +1 -0
- package/dist/lib.js.map +1 -1
- package/dist/logging.d.ts +6 -6
- package/dist/logging.js +59 -62
- package/dist/logging.js.map +1 -1
- package/dist/opencode.d.ts +4 -4
- package/dist/opencode.js +71 -75
- package/dist/opencode.js.map +1 -1
- package/dist/schema.d.ts +41 -41
- package/dist/schema.js +43 -48
- package/dist/schema.js.map +1 -1
- package/dist/tool-spec.d.ts +27 -27
- package/dist/tool-spec.js +24 -16
- package/dist/tool-spec.js.map +1 -1
- package/dist/tools.d.ts +8 -8
- package/dist/tools.js +80 -73
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +27 -27
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/package.json +3 -3
package/dist/groups/math.js
CHANGED
|
@@ -1,139 +1,169 @@
|
|
|
1
1
|
import { all, create } from "mathjs";
|
|
2
2
|
import { json, reqNumber, reqString } from "../tool-spec.js";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const math = create(all, {
|
|
4
|
+
* A hardened mathjs instance. We use BigNumber for precise decimal arithmetic
|
|
5
|
+
* and disable every function that can mutate the evaluator or reach outside the
|
|
6
|
+
* expression sandbox. `evaluate` itself parses mathjs's own expression language
|
|
7
|
+
* (not JavaScript), so with `import` / `createUnit` / function-assignment
|
|
8
|
+
* removed there is no path to arbitrary code execution. See plans/devtools.md
|
|
9
|
+
* and the math-sandbox ADR.
|
|
10
|
+
*/
|
|
11
|
+
const math = create(all, {
|
|
12
|
+
number: "BigNumber",
|
|
13
|
+
precision: 64
|
|
14
|
+
});
|
|
12
15
|
const disabled = () => {
|
|
13
|
-
|
|
16
|
+
throw new Error("disabled for security");
|
|
14
17
|
};
|
|
15
18
|
math.import({
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
import: disabled,
|
|
20
|
+
createUnit: disabled,
|
|
21
|
+
reviver: disabled,
|
|
22
|
+
splitUnit: disabled
|
|
20
23
|
}, { override: true });
|
|
21
|
-
const RADIX_PREFIX = {
|
|
24
|
+
const RADIX_PREFIX = {
|
|
25
|
+
2: "0b",
|
|
26
|
+
8: "0o",
|
|
27
|
+
16: "0x"
|
|
28
|
+
};
|
|
22
29
|
function parseInRadix(value, radix) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return Number.parseInt(trimmed, radix);
|
|
30
|
+
const trimmed = value.trim().replace(/^0[box]/i, "");
|
|
31
|
+
// Number.parseInt stops at the first illegal digit (so "1012" in base 2 would
|
|
32
|
+
// silently parse as 5). Require EVERY digit to be legal for the radix.
|
|
33
|
+
const allLegal = trimmed.length > 0 && [...trimmed.toLowerCase()].every((ch) => {
|
|
34
|
+
const d = Number.parseInt(ch, radix);
|
|
35
|
+
return !Number.isNaN(d) && d < radix;
|
|
36
|
+
});
|
|
37
|
+
if (!allLegal) {
|
|
38
|
+
throw new Error(`"${value}" is not a valid base-${radix} integer`);
|
|
39
|
+
}
|
|
40
|
+
return Number.parseInt(trimmed, radix);
|
|
35
41
|
}
|
|
36
42
|
export const MATH_TOOLS = [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
43
|
+
{
|
|
44
|
+
name: "math_eval",
|
|
45
|
+
group: "math",
|
|
46
|
+
description: "Evaluate a mathematical expression with arbitrary-precision (64-digit) decimals. Supports arithmetic, functions (sqrt, log, sin, …), constants (pi, e), and inline unit math (e.g. \"3 inch to cm\"). Sandboxed: no code execution.",
|
|
47
|
+
input: { expression: {
|
|
48
|
+
type: "string",
|
|
49
|
+
description: "Expression to evaluate, e.g. \"(2 + 3) * 4\" or \"sqrt(2)\" or \"5 km to miles\"."
|
|
50
|
+
} },
|
|
51
|
+
handler: (args) => {
|
|
52
|
+
const expression = reqString(args, "expression");
|
|
53
|
+
const result = math.evaluate(expression);
|
|
54
|
+
const formatted = math.format(result, { precision: 64 });
|
|
55
|
+
return json({
|
|
56
|
+
expression,
|
|
57
|
+
result: formatted
|
|
58
|
+
}, formatted);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: "math_convert_unit",
|
|
63
|
+
group: "math",
|
|
64
|
+
description: "Convert a physical quantity from one unit to another (length, mass, time, temperature, data, energy, …). Returns the converted value.",
|
|
65
|
+
input: {
|
|
66
|
+
value: {
|
|
67
|
+
type: "number",
|
|
68
|
+
description: "Numeric magnitude to convert."
|
|
69
|
+
},
|
|
70
|
+
from: {
|
|
71
|
+
type: "string",
|
|
72
|
+
description: "Source unit, e.g. \"km\", \"kg\", \"celsius\", \"GB\"."
|
|
73
|
+
},
|
|
74
|
+
to: {
|
|
75
|
+
type: "string",
|
|
76
|
+
description: "Target unit, e.g. \"miles\", \"lbs\", \"fahrenheit\", \"MB\"."
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
handler: (args) => {
|
|
80
|
+
const value = reqNumber(args, "value");
|
|
81
|
+
const from = reqString(args, "from");
|
|
82
|
+
const to = reqString(args, "to");
|
|
83
|
+
const converted = math.evaluate(`${value} ${from} to ${to}`);
|
|
84
|
+
const formatted = math.format(converted, { precision: 14 });
|
|
85
|
+
return json({
|
|
86
|
+
value,
|
|
87
|
+
from,
|
|
88
|
+
to,
|
|
89
|
+
result: formatted
|
|
90
|
+
}, `${value} ${from} = ${formatted}`);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: "math_stats",
|
|
95
|
+
group: "math",
|
|
96
|
+
description: "Compute descriptive statistics over a list of numbers: count, sum, min, max, mean, median, mode, variance and standard deviation.",
|
|
97
|
+
input: { values: {
|
|
98
|
+
type: "array",
|
|
99
|
+
items: { type: "number" },
|
|
100
|
+
description: "The numbers to summarize."
|
|
101
|
+
} },
|
|
102
|
+
handler: (args) => {
|
|
103
|
+
const raw = args.values;
|
|
104
|
+
if (!Array.isArray(raw) || raw.length === 0) {
|
|
105
|
+
throw new Error("\"values\" must be a non-empty array of numbers");
|
|
106
|
+
}
|
|
107
|
+
const values = raw.map((v, i) => {
|
|
108
|
+
if (typeof v !== "number" || Number.isNaN(v)) {
|
|
109
|
+
throw new Error(`values[${i}] is not a number`);
|
|
110
|
+
}
|
|
111
|
+
return v;
|
|
112
|
+
});
|
|
113
|
+
const num = (x) => Number(math.format(x, { precision: 14 }));
|
|
114
|
+
const stats = {
|
|
115
|
+
count: values.length,
|
|
116
|
+
sum: num(math.sum(values)),
|
|
117
|
+
min: num(math.min(values)),
|
|
118
|
+
max: num(math.max(values)),
|
|
119
|
+
mean: num(math.mean(values)),
|
|
120
|
+
median: num(math.median(values)),
|
|
121
|
+
mode: math.mode(values).map(num),
|
|
122
|
+
variance: num(math.variance(values)),
|
|
123
|
+
stdev: num(math.std(values))
|
|
124
|
+
};
|
|
125
|
+
return json(stats, `n=${stats.count} mean=${stats.mean} median=${stats.median} stdev=${stats.stdev} min=${stats.min} max=${stats.max}`);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: "math_base",
|
|
130
|
+
group: "math",
|
|
131
|
+
description: "Convert an integer between numeric bases (radix 2–36). Common bases (binary, octal, decimal, hex) are returned alongside the requested target.",
|
|
132
|
+
input: {
|
|
133
|
+
value: {
|
|
134
|
+
type: "string",
|
|
135
|
+
description: "Integer to convert, e.g. \"255\" or \"0xff\" or \"1011\"."
|
|
136
|
+
},
|
|
137
|
+
fromBase: {
|
|
138
|
+
type: "number",
|
|
139
|
+
description: "Base of the input value (2–36)."
|
|
140
|
+
},
|
|
141
|
+
toBase: {
|
|
142
|
+
type: "number",
|
|
143
|
+
description: "Base to convert to (2–36)."
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
handler: (args) => {
|
|
147
|
+
const value = reqString(args, "value");
|
|
148
|
+
const fromBase = reqNumber(args, "fromBase");
|
|
149
|
+
const toBase = reqNumber(args, "toBase");
|
|
150
|
+
for (const [label, b] of [["fromBase", fromBase], ["toBase", toBase]]) {
|
|
151
|
+
if (!Number.isInteger(b) || b < 2 || b > 36) {
|
|
152
|
+
throw new Error(`"${label}" must be an integer in 2–36`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const n = parseInRadix(value, fromBase);
|
|
156
|
+
const out = n.toString(toBase);
|
|
157
|
+
const prefix = RADIX_PREFIX[toBase] ?? "";
|
|
158
|
+
return json({
|
|
159
|
+
decimal: n,
|
|
160
|
+
result: out,
|
|
161
|
+
binary: n.toString(2),
|
|
162
|
+
octal: n.toString(8),
|
|
163
|
+
hex: n.toString(16)
|
|
164
|
+
}, `${value} (base ${fromBase}) = ${prefix}${out} (base ${toBase})`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
138
167
|
];
|
|
168
|
+
|
|
139
169
|
//# sourceMappingURL=math.js.map
|
package/dist/groups/math.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAAA,SAAS,KAAK,cAAc;AAE5B,SAAS,MAAM,WAAW,iBAAgC;;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AC;IACnC,OAAO,IAAI,KAAK,IAAI,MAAM,CAAC;GAC7B;GACA,OAAO,KACL,OACA,KAAK,MAAM,MAAM,QAAQ,MAAM,KAAK,UAAU,MAAM,OAAO,SAAS,MAAM,MAAM,OAAO,MAAM,IAAI,OAAO,MAAM,KAChH;EACF;CACF;CACA;EACE,MAAM;EACN,OAAO;EACP,aACE;EACF,OAAO;GACL,OAAO;IAAE,MAAM;IAAU,aAAa;GAAsD;GAC5F,UAAU;IAAE,MAAM;IAAU,aAAa;GAAkC;GAC3E,QAAQ;IAAE,MAAM;IAAU,aAAa;GAA6B;EACtE;EACA,UAAU,SAAS;GACjB,MAAM,QAAQ,UAAU,MAAM,OAAO;GACrC,MAAM,WAAW,UAAU,MAAM,UAAU;GAC3C,MAAM,SAAS,UAAU,MAAM,QAAQ;GACvC,KAAK,MAAM,CAAC,OAAO,MAAM,CACvB,CAAC,YAAY,QAAQ,GACrB,CAAC,UAAU,MAAM,CACnB,GAAY;IACV,IAAI,CAAC,OAAO,UAAU,CAAC,KAAK,IAAI,KAAK,IAAI,IAAI;KAC3C,MAAM,IAAI,MAAM,IAAI,MAAM,6BAA6B;IACzD;GACF;GACA,MAAM,IAAI,aAAa,OAAO,QAAQ;GACtC,MAAM,MAAM,EAAE,SAAS,MAAM;GAC7B,MAAM,SAAS,aAAa,WAAW;GACvC,OAAO,KACL;IACE,SAAS;IACT,QAAQ;IACR,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,EAAE,SAAS,CAAC;IACnB,KAAK,EAAE,SAAS,EAAE;GACpB,GACA,GAAG,MAAM,SAAS,SAAS,MAAM,SAAS,IAAI,SAAS,OAAO,EAChE;EACF;CACF;AACF","names":[],"sources":["../../src/groups/math.ts"],"version":3,"file":"math.js","sourceRoot":""}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":";;;;AAIA,SAAS,eAAe","names":[],"sources":["../src/index.ts"],"version":3,"file":"index.js","sourceRoot":""}
|
package/dist/lib.js
CHANGED
|
@@ -4,4 +4,5 @@ export { buildContext, createDevtoolsTools } from "./tools.js";
|
|
|
4
4
|
export { toJsonSchema } from "./schema.js";
|
|
5
5
|
export { json, optBool, optString, reqNumber, reqString, text } from "./tool-spec.js";
|
|
6
6
|
export { createJsonConsoleLogger, DEFAULT_LOG_LEVEL, fromOpenCodeLogLevel } from "./logging.js";
|
|
7
|
+
|
|
7
8
|
//# sourceMappingURL=lib.js.map
|
package/dist/lib.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAAA,SACE,sBAEA,wBACA,sBACK;AAEP,SACE,gBACA,gBAEA,aACA,mBAIK;AAEP,SAAS,cAAc,2BAA0C;AAEjE,SAAsD,oBAAoB;AAE1E,SAAS,MAAM,SAAS,WAAW,WAAW,WAAW,YAAY;AAErE,SACE,yBACA,mBACA,4BAIK","names":[],"sources":["../src/lib.ts"],"version":3,"file":"lib.js","sourceRoot":""}
|
package/dist/logging.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ export type { LogLevel } from "./types.js";
|
|
|
3
3
|
export declare const LOG_LEVEL_PRIORITY: Record<LogLevel, number>;
|
|
4
4
|
export declare const DEFAULT_LOG_LEVEL: LogLevel;
|
|
5
5
|
export interface LogFields {
|
|
6
|
-
|
|
6
|
+
[key: string]: unknown;
|
|
7
7
|
}
|
|
8
8
|
export interface Logger {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
trace(event: string, fields?: LogFields): void;
|
|
10
|
+
debug(event: string, fields?: LogFields): void;
|
|
11
|
+
info(event: string, fields?: LogFields): void;
|
|
12
|
+
warn(event: string, fields?: LogFields): void;
|
|
13
|
+
error(event: string, fields?: LogFields): void;
|
|
14
14
|
}
|
|
15
15
|
export declare function createJsonConsoleLogger(minLevel?: LogLevel): Logger;
|
|
16
16
|
export declare function fromOpenCodeLogLevel(value: unknown): LogLevel | undefined;
|
package/dist/logging.js
CHANGED
|
@@ -1,72 +1,69 @@
|
|
|
1
1
|
export const LOG_LEVEL_PRIORITY = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
trace: 5,
|
|
3
|
+
debug: 10,
|
|
4
|
+
info: 20,
|
|
5
|
+
warn: 30,
|
|
6
|
+
error: 40
|
|
7
7
|
};
|
|
8
8
|
export const DEFAULT_LOG_LEVEL = "info";
|
|
9
9
|
function redactFields(fields) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
if (!fields) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const redacted = {};
|
|
14
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
15
|
+
if (/token|secret|password|authorization/i.test(key)) {
|
|
16
|
+
redacted[key] = "[redacted]";
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
redacted[key] = value;
|
|
20
|
+
}
|
|
21
|
+
return redacted;
|
|
22
22
|
}
|
|
23
23
|
export function createJsonConsoleLogger(minLevel = DEFAULT_LOG_LEVEL) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
24
|
+
const minPriority = LOG_LEVEL_PRIORITY[minLevel];
|
|
25
|
+
const write = (level, event, fields) => {
|
|
26
|
+
if (LOG_LEVEL_PRIORITY[level] < minPriority) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const payload = {
|
|
30
|
+
ts: new Date().toISOString(),
|
|
31
|
+
level,
|
|
32
|
+
event,
|
|
33
|
+
...redactFields(fields) ?? {}
|
|
34
|
+
};
|
|
35
|
+
const line = JSON.stringify(payload);
|
|
36
|
+
if (level === "error") {
|
|
37
|
+
console.error(line);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (level === "warn") {
|
|
41
|
+
console.warn(line);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
console.log(line);
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
trace: (event, fields) => write("trace", event, fields),
|
|
48
|
+
debug: (event, fields) => write("debug", event, fields),
|
|
49
|
+
info: (event, fields) => write("info", event, fields),
|
|
50
|
+
warn: (event, fields) => write("warn", event, fields),
|
|
51
|
+
error: (event, fields) => write("error", event, fields)
|
|
52
|
+
};
|
|
53
53
|
}
|
|
54
54
|
export function fromOpenCodeLogLevel(value) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return "error";
|
|
68
|
-
default:
|
|
69
|
-
return undefined;
|
|
70
|
-
}
|
|
55
|
+
if (typeof value !== "string") {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
switch (value.toUpperCase()) {
|
|
59
|
+
case "DEBUG":
|
|
60
|
+
// Host DEBUG unlocks our most-verbose internal tier (trace).
|
|
61
|
+
return "trace";
|
|
62
|
+
case "INFO": return "info";
|
|
63
|
+
case "WARN": return "warn";
|
|
64
|
+
case "ERROR": return "error";
|
|
65
|
+
default: return undefined;
|
|
66
|
+
}
|
|
71
67
|
}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,SAAS,qBAAqB,OAAsC;CACzE,IAAI,OAAO,UAAU,UAAU;EAC7B,OAAO;CACT;CACA,QAAQ,MAAM,YAAY,GAA1B;EACE,KAAK;;EAEH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,SACH,OAAO;EACT,SACE,OAAO;CACX;AACF","names":[],"sources":["../src/logging.ts"],"version":3,"file":"logging.js","sourceRoot":""}
|
package/dist/opencode.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ import { type Logger } from "./logging.js";
|
|
|
3
3
|
import { type ToolDeps } from "./tools.js";
|
|
4
4
|
import type { ResolvedDevtoolsOptions } from "./types.js";
|
|
5
5
|
export interface DevtoolsPluginFactoryOptions {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
/** Inject a logger (defaults to the OpenCode-piped logger). */
|
|
7
|
+
logger?: Logger;
|
|
8
|
+
/** Inject the tool execution context (clock / randomness / fetch) for tests. */
|
|
9
|
+
context?: ToolDeps["context"];
|
|
10
10
|
}
|
|
11
11
|
export declare function resolveOptions(raw: PluginOptions | undefined): ResolvedDevtoolsOptions;
|
|
12
12
|
export declare function createDevtoolsPlugin(factoryOptions?: DevtoolsPluginFactoryOptions): Plugin;
|