@hop-top/kit 0.4.0-alpha.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/CHANGELOG.md +86 -0
- package/LICENSE +25 -0
- package/README.md +189 -0
- package/dist/aim.d.ts +116 -0
- package/dist/aim.js +417 -0
- package/dist/alias.d.ts +73 -0
- package/dist/alias.js +207 -0
- package/dist/api.d.ts +62 -0
- package/dist/api.js +165 -0
- package/dist/auth.d.ts +26 -0
- package/dist/auth.js +41 -0
- package/dist/cli.d.ts +309 -0
- package/dist/cli.js +885 -0
- package/dist/config.d.ts +97 -0
- package/dist/config.js +79 -0
- package/dist/errcorrect.d.ts +37 -0
- package/dist/errcorrect.js +69 -0
- package/dist/llm.d.ts +188 -0
- package/dist/llm.js +356 -0
- package/dist/output.d.ts +213 -0
- package/dist/output.js +447 -0
- package/dist/progress.d.ts +30 -0
- package/dist/progress.js +56 -0
- package/dist/provenance.d.ts +24 -0
- package/dist/provenance.js +32 -0
- package/dist/routellm.d.ts +64 -0
- package/dist/routellm.js +258 -0
- package/dist/rpc.d.ts +25 -0
- package/dist/rpc.js +101 -0
- package/dist/safety.d.ts +24 -0
- package/dist/safety.js +44 -0
- package/dist/scope.d.ts +121 -0
- package/dist/scope.js +380 -0
- package/dist/sqlstore.d.ts +84 -0
- package/dist/sqlstore.js +85 -0
- package/dist/stream.d.ts +35 -0
- package/dist/stream.js +52 -0
- package/dist/tui/index.d.ts +300 -0
- package/dist/tui/index.js +332 -0
- package/dist/upgrade.d.ts +95 -0
- package/dist/upgrade.js +115 -0
- package/dist/xdg.d.ts +169 -0
- package/dist/xdg.js +129 -0
- package/eslint.config.mjs +17 -0
- package/package.json +133 -0
- package/src/README.md +3 -0
- package/src/aim.test.ts +331 -0
- package/src/aim.ts +388 -0
- package/src/alias.test.ts +423 -0
- package/src/alias.ts +256 -0
- package/src/api.test.ts +190 -0
- package/src/api.ts +214 -0
- package/src/auth.test.ts +24 -0
- package/src/auth.ts +37 -0
- package/src/bus.test.ts +178 -0
- package/src/bus.ts +114 -0
- package/src/cli.test.ts +690 -0
- package/src/cli.ts +741 -0
- package/src/completion-values.test.ts +202 -0
- package/src/completion-values.ts +173 -0
- package/src/completion.test.ts +212 -0
- package/src/completion.ts +158 -0
- package/src/compliance.test.ts +134 -0
- package/src/compliance.ts +669 -0
- package/src/config.test.ts +110 -0
- package/src/config.ts +164 -0
- package/src/errcorrect.test.ts +134 -0
- package/src/errcorrect.ts +84 -0
- package/src/flagregister.test.ts +103 -0
- package/src/flagregister.ts +78 -0
- package/src/gen/crud_connect.ts +76 -0
- package/src/gen/crud_pb.ts +269 -0
- package/src/hint.test.ts +315 -0
- package/src/hint.ts +178 -0
- package/src/llm.test.ts +612 -0
- package/src/llm.ts +577 -0
- package/src/log.test.ts +145 -0
- package/src/log.ts +155 -0
- package/src/output/builtins.ts +34 -0
- package/src/output/dispatch.ts +195 -0
- package/src/output/flags.ts +151 -0
- package/src/output/format_help.ts +80 -0
- package/src/output/formatter.ts +167 -0
- package/src/output/formatters/csv.ts +72 -0
- package/src/output/formatters/json.ts +44 -0
- package/src/output/formatters/table.ts +44 -0
- package/src/output/formatters/text.ts +109 -0
- package/src/output/formatters/yaml.ts +47 -0
- package/src/output/projection.ts +126 -0
- package/src/output/registry.ts +88 -0
- package/src/output/template.ts +63 -0
- package/src/output.test.ts +117 -0
- package/src/output.ts +90 -0
- package/src/progress.test.ts +93 -0
- package/src/progress.ts +58 -0
- package/src/provenance.test.ts +59 -0
- package/src/provenance.ts +26 -0
- package/src/routellm.test.ts +179 -0
- package/src/routellm.ts +365 -0
- package/src/router/bert.test.ts +180 -0
- package/src/router/bert.ts +145 -0
- package/src/router/controller.test.ts +183 -0
- package/src/router/controller.ts +165 -0
- package/src/router/integration.test.ts +309 -0
- package/src/router/intent.test.ts +187 -0
- package/src/router/intent.ts +208 -0
- package/src/router/mf.test.ts +66 -0
- package/src/router/mf.ts +52 -0
- package/src/router/random.test.ts +23 -0
- package/src/router/random.ts +13 -0
- package/src/router/router.test.ts +31 -0
- package/src/router/router.ts +62 -0
- package/src/router/server.test.ts +193 -0
- package/src/router/server.ts +134 -0
- package/src/router/sw.test.ts +199 -0
- package/src/router/sw.ts +232 -0
- package/src/rpc.test.ts +47 -0
- package/src/rpc.ts +91 -0
- package/src/safety.test.ts +53 -0
- package/src/safety.ts +42 -0
- package/src/scope-defaults.json +72 -0
- package/src/scope.test.ts +177 -0
- package/src/scope.ts +382 -0
- package/src/setflag.test.ts +110 -0
- package/src/setflag.ts +102 -0
- package/src/sqlstore.test.ts +110 -0
- package/src/sqlstore.ts +144 -0
- package/src/stream.test.ts +69 -0
- package/src/stream.ts +47 -0
- package/src/textflag.test.ts +105 -0
- package/src/textflag.ts +68 -0
- package/src/toolspec.test.ts +187 -0
- package/src/toolspec.ts +279 -0
- package/src/triton/client.test.ts +205 -0
- package/src/triton/client.ts +261 -0
- package/src/tui/anim.test.ts +146 -0
- package/src/tui/anim.ts +134 -0
- package/src/tui/badge.test.ts +41 -0
- package/src/tui/badge.ts +55 -0
- package/src/tui/confirm.test.ts +68 -0
- package/src/tui/confirm.ts +49 -0
- package/src/tui/index.ts +29 -0
- package/src/tui/list.test.ts +84 -0
- package/src/tui/list.ts +72 -0
- package/src/tui/parity.ts +41 -0
- package/src/tui/pills.test.ts +40 -0
- package/src/tui/pills.ts +43 -0
- package/src/tui/progress.test.ts +164 -0
- package/src/tui/progress.ts +120 -0
- package/src/tui/spinner.test.ts +111 -0
- package/src/tui/spinner.ts +96 -0
- package/src/tui/status.test.ts +68 -0
- package/src/tui/status.ts +66 -0
- package/src/upgrade.test.ts +298 -0
- package/src/upgrade.ts +205 -0
- package/src/uri.ts +199 -0
- package/src/wizard.test.ts +441 -0
- package/src/wizard.ts +662 -0
- package/src/xdg.test.ts +202 -0
- package/src/xdg.ts +280 -0
- package/test/output/cols.test.ts +148 -0
- package/test/output/csv.test.ts +129 -0
- package/test/output/dispatch.test.ts +194 -0
- package/test/output/format_help.test.ts +131 -0
- package/test/output/formatter.test.ts +137 -0
- package/test/output/output_flag.test.ts +124 -0
- package/test/output/registry.test.ts +127 -0
- package/test/output/smoke-capture.ts +83 -0
- package/test/output/smoke.test.ts +142 -0
- package/test/output/template.test.ts +95 -0
- package/test/output/text.test.ts +75 -0
- package/test/testdata/api-fixture.json +115 -0
- package/test/testdata/query-vectors.json +187 -0
- package/tsconfig.json +12 -0
package/dist/output.js
ADDED
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/output.ts
|
|
31
|
+
var output_exports = {};
|
|
32
|
+
__export(output_exports, {
|
|
33
|
+
CSV_FORMAT: () => CSV_FORMAT,
|
|
34
|
+
JSON_FORMAT: () => JSON_FORMAT,
|
|
35
|
+
Registry: () => Registry,
|
|
36
|
+
TABLE_FORMAT: () => TABLE_FORMAT,
|
|
37
|
+
TEXT_FORMAT: () => TEXT_FORMAT,
|
|
38
|
+
YAML_FORMAT: () => YAML_FORMAT,
|
|
39
|
+
defaultRegistry: () => defaultRegistry,
|
|
40
|
+
jsonFormatter: () => jsonFormatter,
|
|
41
|
+
newRegistry: () => newRegistry,
|
|
42
|
+
optionTypeName: () => optionTypeName,
|
|
43
|
+
parseOptions: () => parseOptions,
|
|
44
|
+
render: () => render,
|
|
45
|
+
tableFormatter: () => tableFormatter,
|
|
46
|
+
yamlFormatter: () => yamlFormatter
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(output_exports);
|
|
49
|
+
|
|
50
|
+
// src/output/formatter.ts
|
|
51
|
+
function parseOptions(pairs, specs) {
|
|
52
|
+
const specByName = /* @__PURE__ */ new Map();
|
|
53
|
+
for (const s of specs) {
|
|
54
|
+
specByName.set(s.name, s);
|
|
55
|
+
}
|
|
56
|
+
const out = {};
|
|
57
|
+
for (const raw of pairs) {
|
|
58
|
+
const eq = raw.indexOf("=");
|
|
59
|
+
const hasEq = eq !== -1;
|
|
60
|
+
const key = (hasEq ? raw.slice(0, eq) : raw).trim();
|
|
61
|
+
const val = hasEq ? raw.slice(eq + 1) : "";
|
|
62
|
+
if (key === "") {
|
|
63
|
+
throw new Error(`empty option key in "${raw}"`);
|
|
64
|
+
}
|
|
65
|
+
const spec = specByName.get(key);
|
|
66
|
+
if (!spec) {
|
|
67
|
+
const valid = specs.map((s) => s.name).join(", ");
|
|
68
|
+
throw new Error(`unknown option "${key}" (valid: ${valid})`);
|
|
69
|
+
}
|
|
70
|
+
if (!hasEq) {
|
|
71
|
+
if (spec.type !== "bool") {
|
|
72
|
+
throw new Error(`option "${key}" requires a value (e.g. ${key}=...)`);
|
|
73
|
+
}
|
|
74
|
+
out[key] = true;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
out[key] = coerce(spec, val);
|
|
78
|
+
}
|
|
79
|
+
for (const s of specs) {
|
|
80
|
+
if (Object.prototype.hasOwnProperty.call(out, s.name)) continue;
|
|
81
|
+
if (s.default !== void 0) {
|
|
82
|
+
out[s.name] = s.default;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
function coerce(spec, val) {
|
|
88
|
+
switch (spec.type) {
|
|
89
|
+
case "string":
|
|
90
|
+
return val;
|
|
91
|
+
case "int": {
|
|
92
|
+
if (!/^-?\d+$/.test(val)) {
|
|
93
|
+
throw new Error(`option "${spec.name}": "${val}" is not an int`);
|
|
94
|
+
}
|
|
95
|
+
const n = Number(val);
|
|
96
|
+
if (!Number.isSafeInteger(n)) {
|
|
97
|
+
throw new Error(`option "${spec.name}": "${val}" is not an int`);
|
|
98
|
+
}
|
|
99
|
+
return n;
|
|
100
|
+
}
|
|
101
|
+
case "bool": {
|
|
102
|
+
const truthy = /* @__PURE__ */ new Set(["1", "t", "T", "TRUE", "true", "True"]);
|
|
103
|
+
const falsy = /* @__PURE__ */ new Set(["0", "f", "F", "FALSE", "false", "False"]);
|
|
104
|
+
if (truthy.has(val)) return true;
|
|
105
|
+
if (falsy.has(val)) return false;
|
|
106
|
+
throw new Error(`option "${spec.name}": "${val}" is not a bool`);
|
|
107
|
+
}
|
|
108
|
+
case "enum": {
|
|
109
|
+
const allowed = spec.enum ?? [];
|
|
110
|
+
if (allowed.includes(val)) return val;
|
|
111
|
+
throw new Error(
|
|
112
|
+
`option "${spec.name}": "${val}" not in {${allowed.join(", ")}}`
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function optionTypeName(t) {
|
|
118
|
+
return t;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/output/registry.ts
|
|
122
|
+
var Registry = class {
|
|
123
|
+
constructor() {
|
|
124
|
+
this.byKey = /* @__PURE__ */ new Map();
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Adds f to the registry. Throws Error on duplicate key or empty key.
|
|
128
|
+
* Use `override` to intentionally replace.
|
|
129
|
+
*/
|
|
130
|
+
register(f) {
|
|
131
|
+
if (f.key === "") {
|
|
132
|
+
throw new Error("output: formatter key is empty");
|
|
133
|
+
}
|
|
134
|
+
if (this.byKey.has(f.key)) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
`output: formatter "${f.key}" already registered (use override to replace)`
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
this.byKey.set(f.key, f);
|
|
140
|
+
}
|
|
141
|
+
/** Replaces (or registers) the formatter for f.key. */
|
|
142
|
+
override(f) {
|
|
143
|
+
if (f.key === "") {
|
|
144
|
+
throw new Error("output: formatter key is empty");
|
|
145
|
+
}
|
|
146
|
+
this.byKey.set(f.key, f);
|
|
147
|
+
}
|
|
148
|
+
/** Returns the formatter registered under key, if any. */
|
|
149
|
+
lookup(key) {
|
|
150
|
+
return this.byKey.get(key);
|
|
151
|
+
}
|
|
152
|
+
/** Returns all registered format keys, sorted alphabetically. */
|
|
153
|
+
keys() {
|
|
154
|
+
return [...this.byKey.keys()].sort();
|
|
155
|
+
}
|
|
156
|
+
/** Returns all registered formatters in key order. */
|
|
157
|
+
formatters() {
|
|
158
|
+
return this.keys().map((k) => this.byKey.get(k));
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Returns extension→key mappings (e.g. ".csv" → "csv") across all
|
|
162
|
+
* registered formatters. Later registrations win on collision; iteration
|
|
163
|
+
* is in sorted-key order so resolution is deterministic.
|
|
164
|
+
*/
|
|
165
|
+
extensionMap() {
|
|
166
|
+
const out = /* @__PURE__ */ new Map();
|
|
167
|
+
for (const k of this.keys()) {
|
|
168
|
+
const f = this.byKey.get(k);
|
|
169
|
+
if (!f) continue;
|
|
170
|
+
for (const ext of f.extensions) {
|
|
171
|
+
out.set(ext.toLowerCase(), k);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
var defaultRegistry = new Registry();
|
|
178
|
+
function newRegistry() {
|
|
179
|
+
return new Registry();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// src/output/formatters/json.ts
|
|
183
|
+
var jsonFormatter = {
|
|
184
|
+
key: "json",
|
|
185
|
+
extensions: [".json"],
|
|
186
|
+
options: [
|
|
187
|
+
{ name: "indent", type: "int", default: 2, usage: "spaces per indent level" }
|
|
188
|
+
],
|
|
189
|
+
render(out, data, opts, cols) {
|
|
190
|
+
const indent = opts["indent"] ?? 2;
|
|
191
|
+
const value = projectForJson(data, cols);
|
|
192
|
+
out.write(JSON.stringify(value, null, indent) + "\n");
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
function projectForJson(data, cols) {
|
|
196
|
+
if (cols.length === 0) return data;
|
|
197
|
+
if (Array.isArray(data)) {
|
|
198
|
+
return data.map((row) => projectRow(row, cols));
|
|
199
|
+
}
|
|
200
|
+
return projectRow(data, cols);
|
|
201
|
+
}
|
|
202
|
+
function projectRow(row, cols) {
|
|
203
|
+
if (row === null || typeof row !== "object") return row;
|
|
204
|
+
const r = row;
|
|
205
|
+
const out = {};
|
|
206
|
+
for (const c of cols) out[c] = r[c];
|
|
207
|
+
return out;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// src/output/formatters/yaml.ts
|
|
211
|
+
var yaml = __toESM(require("js-yaml"));
|
|
212
|
+
var yamlFormatter = {
|
|
213
|
+
key: "yaml",
|
|
214
|
+
extensions: [".yaml", ".yml"],
|
|
215
|
+
options: [
|
|
216
|
+
{
|
|
217
|
+
name: "flow-level",
|
|
218
|
+
type: "int",
|
|
219
|
+
default: -1,
|
|
220
|
+
usage: "level at which to switch from block to flow style"
|
|
221
|
+
}
|
|
222
|
+
],
|
|
223
|
+
render(out, data, opts, cols) {
|
|
224
|
+
const flowLevel = opts["flow-level"] ?? -1;
|
|
225
|
+
const value = projectForYaml(data, cols);
|
|
226
|
+
out.write(yaml.dump(value, { flowLevel }));
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
function projectForYaml(data, cols) {
|
|
230
|
+
if (cols.length === 0) return data;
|
|
231
|
+
if (Array.isArray(data)) {
|
|
232
|
+
return data.map((row) => projectRow2(row, cols));
|
|
233
|
+
}
|
|
234
|
+
return projectRow2(data, cols);
|
|
235
|
+
}
|
|
236
|
+
function projectRow2(row, cols) {
|
|
237
|
+
if (row === null || typeof row !== "object") return row;
|
|
238
|
+
const r = row;
|
|
239
|
+
const out = {};
|
|
240
|
+
for (const c of cols) out[c] = r[c];
|
|
241
|
+
return out;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// src/output/formatters/table.ts
|
|
245
|
+
var tableFormatter = {
|
|
246
|
+
key: "table",
|
|
247
|
+
extensions: [],
|
|
248
|
+
options: [],
|
|
249
|
+
render(out, data, _opts, cols) {
|
|
250
|
+
const rows = normalise(data);
|
|
251
|
+
if (rows.length === 0) return;
|
|
252
|
+
const allHeaders = Object.keys(rows[0] ?? {});
|
|
253
|
+
const headers = cols.length > 0 ? cols.filter((c) => allHeaders.includes(c)) : allHeaders;
|
|
254
|
+
if (headers.length === 0) return;
|
|
255
|
+
const cells = rows.map(
|
|
256
|
+
(row) => headers.map((h) => String(row[h] ?? ""))
|
|
257
|
+
);
|
|
258
|
+
const widths = headers.map(
|
|
259
|
+
(h, ci) => Math.max(h.length, ...cells.map((r) => r[ci].length))
|
|
260
|
+
);
|
|
261
|
+
const pad = (s, w) => s + " ".repeat(w - s.length);
|
|
262
|
+
const line = (parts) => parts.map((c, i) => pad(c, widths[i])).join(" ");
|
|
263
|
+
out.write(line(headers) + "\n");
|
|
264
|
+
for (const row of cells) {
|
|
265
|
+
out.write(line(row) + "\n");
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
function normalise(v) {
|
|
270
|
+
if (Array.isArray(v)) return v;
|
|
271
|
+
return [v];
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// src/output/formatters/csv.ts
|
|
275
|
+
var import_sync = require("csv-stringify/sync");
|
|
276
|
+
var csvFormatter = {
|
|
277
|
+
key: "csv",
|
|
278
|
+
extensions: [".csv"],
|
|
279
|
+
options: [
|
|
280
|
+
{ name: "delimiter", type: "string", default: ",", usage: "field delimiter" },
|
|
281
|
+
{ name: "no-header", type: "bool", default: false, usage: "omit header row" },
|
|
282
|
+
{
|
|
283
|
+
name: "quote-all",
|
|
284
|
+
type: "bool",
|
|
285
|
+
default: false,
|
|
286
|
+
usage: "quote every field, not just those needing it"
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
name: "crlf",
|
|
290
|
+
type: "bool",
|
|
291
|
+
default: false,
|
|
292
|
+
usage: "use CRLF line endings (default LF)"
|
|
293
|
+
}
|
|
294
|
+
],
|
|
295
|
+
render(out, data, opts, cols) {
|
|
296
|
+
const rows = normalise2(data);
|
|
297
|
+
if (rows.length === 0) return;
|
|
298
|
+
const allHeaders = Object.keys(rows[0] ?? {});
|
|
299
|
+
const headers = cols.length > 0 ? cols.filter((c) => allHeaders.includes(c)) : allHeaders;
|
|
300
|
+
if (headers.length === 0) return;
|
|
301
|
+
const delimiter = opts["delimiter"] ?? ",";
|
|
302
|
+
const noHeader = opts["no-header"] ?? false;
|
|
303
|
+
const quoteAll = opts["quote-all"] ?? false;
|
|
304
|
+
const crlf = opts["crlf"] ?? false;
|
|
305
|
+
if (delimiter.length !== 1) {
|
|
306
|
+
throw new Error(`option "delimiter": delimiter must be exactly one character`);
|
|
307
|
+
}
|
|
308
|
+
const records = rows.map((r) => headers.map((h) => stringify_cell(r[h])));
|
|
309
|
+
const csvRows = noHeader ? records : [headers, ...records];
|
|
310
|
+
const text = (0, import_sync.stringify)(csvRows, {
|
|
311
|
+
delimiter,
|
|
312
|
+
record_delimiter: crlf ? "windows" : "unix",
|
|
313
|
+
quoted: quoteAll
|
|
314
|
+
// No `header: true` — we already prepend headers ourselves to keep
|
|
315
|
+
// row layout uniform with csv format and to make `no-header` toggle
|
|
316
|
+
// a single decision point.
|
|
317
|
+
});
|
|
318
|
+
out.write(text);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
function normalise2(v) {
|
|
322
|
+
if (Array.isArray(v)) return v;
|
|
323
|
+
return [v];
|
|
324
|
+
}
|
|
325
|
+
function stringify_cell(v) {
|
|
326
|
+
if (v === null || v === void 0) return "";
|
|
327
|
+
return String(v);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// src/output/formatters/text.ts
|
|
331
|
+
var STYLE_KV = "kv";
|
|
332
|
+
var STYLE_LINES = "lines";
|
|
333
|
+
var STYLE_PARAGRAPH = "paragraph";
|
|
334
|
+
var textFormatter = {
|
|
335
|
+
key: "text",
|
|
336
|
+
extensions: [".txt"],
|
|
337
|
+
options: [
|
|
338
|
+
{
|
|
339
|
+
name: "style",
|
|
340
|
+
type: "enum",
|
|
341
|
+
default: STYLE_KV,
|
|
342
|
+
enum: [STYLE_KV, STYLE_LINES, STYLE_PARAGRAPH],
|
|
343
|
+
usage: "output style"
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
name: "separator",
|
|
347
|
+
type: "string",
|
|
348
|
+
default: "=",
|
|
349
|
+
usage: "kv separator (kv style only)"
|
|
350
|
+
}
|
|
351
|
+
],
|
|
352
|
+
render(out, data, opts, cols) {
|
|
353
|
+
const rows = normalise3(data);
|
|
354
|
+
if (rows.length === 0) return;
|
|
355
|
+
const allHeaders = Object.keys(rows[0] ?? {});
|
|
356
|
+
const headers = cols.length > 0 ? cols.filter((c) => allHeaders.includes(c)) : allHeaders;
|
|
357
|
+
if (headers.length === 0) return;
|
|
358
|
+
const style = opts["style"] || STYLE_KV;
|
|
359
|
+
const sep = opts["separator"] || "=";
|
|
360
|
+
switch (style) {
|
|
361
|
+
case STYLE_KV:
|
|
362
|
+
return renderKV(out, rows, headers, sep);
|
|
363
|
+
case STYLE_LINES:
|
|
364
|
+
return renderLines(out, rows, headers);
|
|
365
|
+
case STYLE_PARAGRAPH:
|
|
366
|
+
return renderParagraph(out, rows, headers);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
function normalise3(v) {
|
|
371
|
+
if (Array.isArray(v)) return v;
|
|
372
|
+
return [v];
|
|
373
|
+
}
|
|
374
|
+
function fmt(v) {
|
|
375
|
+
if (v === null || v === void 0) return "";
|
|
376
|
+
return String(v);
|
|
377
|
+
}
|
|
378
|
+
function renderKV(out, rows, headers, sep) {
|
|
379
|
+
rows.forEach((r, i) => {
|
|
380
|
+
if (i > 0) out.write("\n");
|
|
381
|
+
for (const h of headers) {
|
|
382
|
+
out.write(`${h}${sep}${fmt(r[h])}
|
|
383
|
+
`);
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
function renderLines(out, rows, headers) {
|
|
388
|
+
for (const r of rows) {
|
|
389
|
+
out.write(headers.map((h) => fmt(r[h])).join(" ") + "\n");
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
function renderParagraph(out, rows, headers) {
|
|
393
|
+
rows.forEach((r, i) => {
|
|
394
|
+
if (i > 0) out.write("\n");
|
|
395
|
+
out.write(`Record ${i + 1}:
|
|
396
|
+
`);
|
|
397
|
+
for (const h of headers) {
|
|
398
|
+
out.write(` ${h}: ${fmt(r[h])}
|
|
399
|
+
`);
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// src/output/builtins.ts
|
|
405
|
+
var registered = false;
|
|
406
|
+
function registerBuiltins() {
|
|
407
|
+
if (registered) return;
|
|
408
|
+
defaultRegistry.register(jsonFormatter);
|
|
409
|
+
defaultRegistry.register(yamlFormatter);
|
|
410
|
+
defaultRegistry.register(tableFormatter);
|
|
411
|
+
defaultRegistry.register(csvFormatter);
|
|
412
|
+
defaultRegistry.register(textFormatter);
|
|
413
|
+
registered = true;
|
|
414
|
+
}
|
|
415
|
+
registerBuiltins();
|
|
416
|
+
|
|
417
|
+
// src/output.ts
|
|
418
|
+
var JSON_FORMAT = "json";
|
|
419
|
+
var YAML_FORMAT = "yaml";
|
|
420
|
+
var TABLE_FORMAT = "table";
|
|
421
|
+
var CSV_FORMAT = "csv";
|
|
422
|
+
var TEXT_FORMAT = "text";
|
|
423
|
+
function render(w, format, v) {
|
|
424
|
+
const f = defaultRegistry.lookup(format);
|
|
425
|
+
if (!f) {
|
|
426
|
+
const valid = defaultRegistry.keys().join(", ");
|
|
427
|
+
throw new Error(`unknown output format "${format}" (valid: ${valid})`);
|
|
428
|
+
}
|
|
429
|
+
void f.render(w, v, {}, []);
|
|
430
|
+
}
|
|
431
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
432
|
+
0 && (module.exports = {
|
|
433
|
+
CSV_FORMAT,
|
|
434
|
+
JSON_FORMAT,
|
|
435
|
+
Registry,
|
|
436
|
+
TABLE_FORMAT,
|
|
437
|
+
TEXT_FORMAT,
|
|
438
|
+
YAML_FORMAT,
|
|
439
|
+
defaultRegistry,
|
|
440
|
+
jsonFormatter,
|
|
441
|
+
newRegistry,
|
|
442
|
+
optionTypeName,
|
|
443
|
+
parseOptions,
|
|
444
|
+
render,
|
|
445
|
+
tableFormatter,
|
|
446
|
+
yamlFormatter
|
|
447
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module progress
|
|
3
|
+
* @package @hop-top/kit
|
|
4
|
+
*
|
|
5
|
+
* Factor 9 — Observable Long-Running Operations.
|
|
6
|
+
*
|
|
7
|
+
* Emits structured progress events (JSON in non-TTY,
|
|
8
|
+
* human-readable in TTY).
|
|
9
|
+
*/
|
|
10
|
+
interface ProgressEvent {
|
|
11
|
+
phase: string;
|
|
12
|
+
step: string;
|
|
13
|
+
current: number;
|
|
14
|
+
total: number;
|
|
15
|
+
percent: number;
|
|
16
|
+
message?: string;
|
|
17
|
+
}
|
|
18
|
+
interface JobHandle {
|
|
19
|
+
id: string;
|
|
20
|
+
status: 'running' | 'completed' | 'failed' | 'cancelled';
|
|
21
|
+
}
|
|
22
|
+
declare class ProgressReporter {
|
|
23
|
+
private w;
|
|
24
|
+
private tty;
|
|
25
|
+
constructor(w: NodeJS.WritableStream, isTTY: boolean);
|
|
26
|
+
emit(event: ProgressEvent): void;
|
|
27
|
+
done(message: string): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { type JobHandle, type ProgressEvent, ProgressReporter };
|
package/dist/progress.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/progress.ts
|
|
21
|
+
var progress_exports = {};
|
|
22
|
+
__export(progress_exports, {
|
|
23
|
+
ProgressReporter: () => ProgressReporter
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(progress_exports);
|
|
26
|
+
var ProgressReporter = class {
|
|
27
|
+
constructor(w, isTTY) {
|
|
28
|
+
this.w = w;
|
|
29
|
+
this.tty = isTTY;
|
|
30
|
+
}
|
|
31
|
+
emit(event) {
|
|
32
|
+
if (this.tty) {
|
|
33
|
+
const msg = event.message ? ` ${event.message}` : "";
|
|
34
|
+
this.w.write(
|
|
35
|
+
`[${event.phase}] ${event.step} ${event.current}/${event.total} (${event.percent}%)${msg}
|
|
36
|
+
`
|
|
37
|
+
);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
this.w.write(JSON.stringify(event) + "\n");
|
|
41
|
+
}
|
|
42
|
+
done(message) {
|
|
43
|
+
if (this.tty) {
|
|
44
|
+
this.w.write(`done: ${message}
|
|
45
|
+
`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
this.w.write(
|
|
49
|
+
JSON.stringify({ done: true, message }) + "\n"
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
ProgressReporter
|
|
56
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module provenance
|
|
3
|
+
* @package @hop-top/kit
|
|
4
|
+
*
|
|
5
|
+
* Factor 11 — Provenance.
|
|
6
|
+
*
|
|
7
|
+
* Attaches origin metadata to any data payload for JSON output,
|
|
8
|
+
* enabling consumers to verify source, timing, and method.
|
|
9
|
+
*/
|
|
10
|
+
interface Provenance {
|
|
11
|
+
source: string;
|
|
12
|
+
/** ISO 8601 timestamp */
|
|
13
|
+
timestamp: string;
|
|
14
|
+
method: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Wraps `data` with provenance metadata under `_meta`.
|
|
18
|
+
*/
|
|
19
|
+
declare function withProvenance<T>(data: T, p: Provenance): {
|
|
20
|
+
data: T;
|
|
21
|
+
_meta: Provenance;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { type Provenance, withProvenance };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/provenance.ts
|
|
21
|
+
var provenance_exports = {};
|
|
22
|
+
__export(provenance_exports, {
|
|
23
|
+
withProvenance: () => withProvenance
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(provenance_exports);
|
|
26
|
+
function withProvenance(data, p) {
|
|
27
|
+
return { data, _meta: p };
|
|
28
|
+
}
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
withProvenance
|
|
32
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Completer, Streamer, ResolvedConfig, Request, Response, Token } from './llm.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*
|
|
6
|
+
* RouteLLM adapter — registers the `routellm` URI scheme.
|
|
7
|
+
*
|
|
8
|
+
* URI format: `routellm://router_name:threshold` (e.g. `routellm://mf:0.7`).
|
|
9
|
+
*
|
|
10
|
+
* Delegates HTTP completions to an OpenAI-compatible endpoint on the
|
|
11
|
+
* RouteLLM server, translating the model field into the server's
|
|
12
|
+
* expected `router-[name]-[threshold]` format.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
interface EvaConfig {
|
|
16
|
+
contracts: string[];
|
|
17
|
+
enforce: boolean;
|
|
18
|
+
}
|
|
19
|
+
interface RouterConfig {
|
|
20
|
+
baseUrl: string;
|
|
21
|
+
grpcPort: number;
|
|
22
|
+
strongModel: string;
|
|
23
|
+
weakModel: string;
|
|
24
|
+
routers: string[];
|
|
25
|
+
routerConfig: Record<string, unknown>;
|
|
26
|
+
eva: EvaConfig;
|
|
27
|
+
autostart: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Extract and validate RouteLLM configuration from provider extras.
|
|
31
|
+
* Environment variables override all other sources.
|
|
32
|
+
*/
|
|
33
|
+
declare function parseRouterConfig(extras?: Record<string, unknown>): RouterConfig;
|
|
34
|
+
interface ParsedModel {
|
|
35
|
+
routerName: string;
|
|
36
|
+
threshold: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Split a model string of the form `router_name:threshold` into its
|
|
40
|
+
* components.
|
|
41
|
+
*/
|
|
42
|
+
declare function parseModelField(model: string): ParsedModel;
|
|
43
|
+
/**
|
|
44
|
+
* RouteLLM adapter implementing Completer and Streamer.
|
|
45
|
+
*
|
|
46
|
+
* Delegates to an OpenAI-compatible HTTP endpoint on the RouteLLM
|
|
47
|
+
* server using the standard fetch API.
|
|
48
|
+
*/
|
|
49
|
+
declare class RouteLLMAdapter implements Completer, Streamer {
|
|
50
|
+
readonly config: RouterConfig;
|
|
51
|
+
readonly routerName: string;
|
|
52
|
+
readonly threshold: number;
|
|
53
|
+
private readonly _baseUrl;
|
|
54
|
+
private readonly _serverModel;
|
|
55
|
+
private readonly _apiKey;
|
|
56
|
+
constructor(cfg: ResolvedConfig);
|
|
57
|
+
complete(req: Request): Promise<Response>;
|
|
58
|
+
stream(req: Request): AsyncGenerator<Token>;
|
|
59
|
+
close(): void;
|
|
60
|
+
private _buildBody;
|
|
61
|
+
private _post;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { type EvaConfig, type ParsedModel, RouteLLMAdapter, type RouterConfig, parseModelField, parseRouterConfig };
|