scoutline 0.1.0 → 0.2.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/README.md +170 -5
- package/bin/scoutline.js +36 -15
- package/dist/capabilities/diagnostics.d.ts +97 -0
- package/dist/capabilities/diagnostics.d.ts.map +1 -0
- package/dist/capabilities/diagnostics.js +88 -0
- package/dist/capabilities/diagnostics.js.map +1 -0
- package/dist/capabilities/quota.d.ts +99 -0
- package/dist/capabilities/quota.d.ts.map +1 -0
- package/dist/capabilities/quota.js +129 -0
- package/dist/capabilities/quota.js.map +1 -0
- package/dist/capabilities/search.d.ts +110 -0
- package/dist/capabilities/search.d.ts.map +1 -0
- package/dist/capabilities/search.js +21 -0
- package/dist/capabilities/search.js.map +1 -0
- package/dist/capabilities/vision.d.ts +156 -0
- package/dist/capabilities/vision.d.ts.map +1 -0
- package/dist/capabilities/vision.js +111 -0
- package/dist/capabilities/vision.js.map +1 -0
- package/dist/command-invocation.d.ts +58 -0
- package/dist/command-invocation.d.ts.map +1 -0
- package/dist/command-invocation.js +95 -0
- package/dist/command-invocation.js.map +1 -0
- package/dist/commands/code.d.ts +11 -4
- package/dist/commands/code.d.ts.map +1 -1
- package/dist/commands/code.js +16 -42
- package/dist/commands/code.js.map +1 -1
- package/dist/commands/doctor.d.ts +58 -3
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +154 -52
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/quota.d.ts +45 -3
- package/dist/commands/quota.d.ts.map +1 -1
- package/dist/commands/quota.js +116 -60
- package/dist/commands/quota.js.map +1 -1
- package/dist/commands/read.d.ts +15 -1
- package/dist/commands/read.d.ts.map +1 -1
- package/dist/commands/read.js +53 -54
- package/dist/commands/read.js.map +1 -1
- package/dist/commands/repo.d.ts +8 -3
- package/dist/commands/repo.d.ts.map +1 -1
- package/dist/commands/repo.js +40 -78
- package/dist/commands/repo.js.map +1 -1
- package/dist/commands/search.d.ts +27 -2
- package/dist/commands/search.d.ts.map +1 -1
- package/dist/commands/search.js +95 -103
- package/dist/commands/search.js.map +1 -1
- package/dist/commands/tools.d.ts +9 -3
- package/dist/commands/tools.d.ts.map +1 -1
- package/dist/commands/tools.js +29 -59
- package/dist/commands/tools.js.map +1 -1
- package/dist/commands/vision.d.ts +35 -9
- package/dist/commands/vision.d.ts.map +1 -1
- package/dist/commands/vision.js +184 -131
- package/dist/commands/vision.js.map +1 -1
- package/dist/index.d.ts +42 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +389 -207
- package/dist/index.js.map +1 -1
- package/dist/lib/cache.d.ts +61 -0
- package/dist/lib/cache.d.ts.map +1 -1
- package/dist/lib/cache.js +74 -11
- package/dist/lib/cache.js.map +1 -1
- package/dist/lib/code-mode.d.ts +13 -0
- package/dist/lib/code-mode.d.ts.map +1 -1
- package/dist/lib/code-mode.js +26 -6
- package/dist/lib/code-mode.js.map +1 -1
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +15 -18
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/errors.d.ts +65 -10
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +135 -19
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/execution.d.ts +76 -0
- package/dist/lib/execution.d.ts.map +1 -0
- package/dist/lib/execution.js +177 -0
- package/dist/lib/execution.js.map +1 -0
- package/dist/lib/index.d.ts +10 -2
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +10 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/mcp-client.d.ts +46 -11
- package/dist/lib/mcp-client.d.ts.map +1 -1
- package/dist/lib/mcp-client.js +92 -27
- package/dist/lib/mcp-client.js.map +1 -1
- package/dist/lib/mcp-config.d.ts +17 -0
- package/dist/lib/mcp-config.d.ts.map +1 -1
- package/dist/lib/mcp-config.js +29 -0
- package/dist/lib/mcp-config.js.map +1 -1
- package/dist/lib/monitor-client.d.ts +17 -3
- package/dist/lib/monitor-client.d.ts.map +1 -1
- package/dist/lib/monitor-client.js +23 -69
- package/dist/lib/monitor-client.js.map +1 -1
- package/dist/lib/output.d.ts +53 -7
- package/dist/lib/output.d.ts.map +1 -1
- package/dist/lib/output.js +126 -39
- package/dist/lib/output.js.map +1 -1
- package/dist/lib/redact.d.ts +62 -3
- package/dist/lib/redact.d.ts.map +1 -1
- package/dist/lib/redact.js +165 -31
- package/dist/lib/redact.js.map +1 -1
- package/dist/lib/tty.d.ts +7 -20
- package/dist/lib/tty.d.ts.map +1 -1
- package/dist/lib/tty.js +51 -30
- package/dist/lib/tty.js.map +1 -1
- package/dist/node-command-invocation-adapter.d.ts +28 -0
- package/dist/node-command-invocation-adapter.d.ts.map +1 -0
- package/dist/node-command-invocation-adapter.js +88 -0
- package/dist/node-command-invocation-adapter.js.map +1 -0
- package/dist/providers/minimax/adapter.d.ts +47 -0
- package/dist/providers/minimax/adapter.d.ts.map +1 -0
- package/dist/providers/minimax/adapter.js +443 -0
- package/dist/providers/minimax/adapter.js.map +1 -0
- package/dist/providers/minimax/config.d.ts +32 -0
- package/dist/providers/minimax/config.d.ts.map +1 -0
- package/dist/providers/minimax/config.js +84 -0
- package/dist/providers/minimax/config.js.map +1 -0
- package/dist/providers/minimax/media.d.ts +34 -0
- package/dist/providers/minimax/media.d.ts.map +1 -0
- package/dist/providers/minimax/media.js +92 -0
- package/dist/providers/minimax/media.js.map +1 -0
- package/dist/providers/minimax/quota-client.d.ts +37 -0
- package/dist/providers/minimax/quota-client.d.ts.map +1 -0
- package/dist/providers/minimax/quota-client.js +78 -0
- package/dist/providers/minimax/quota-client.js.map +1 -0
- package/dist/providers/minimax/quota.d.ts +48 -0
- package/dist/providers/minimax/quota.d.ts.map +1 -0
- package/dist/providers/minimax/quota.js +120 -0
- package/dist/providers/minimax/quota.js.map +1 -0
- package/dist/providers/minimax/sdk-client.d.ts +29 -0
- package/dist/providers/minimax/sdk-client.d.ts.map +1 -0
- package/dist/providers/minimax/sdk-client.js +50 -0
- package/dist/providers/minimax/sdk-client.js.map +1 -0
- package/dist/providers/minimax/vision-attestations.d.ts +29 -0
- package/dist/providers/minimax/vision-attestations.d.ts.map +1 -0
- package/dist/providers/minimax/vision-attestations.js +54 -0
- package/dist/providers/minimax/vision-attestations.js.map +1 -0
- package/dist/providers/minimax/vision-conformance.d.ts +184 -0
- package/dist/providers/minimax/vision-conformance.d.ts.map +1 -0
- package/dist/providers/minimax/vision-conformance.js +369 -0
- package/dist/providers/minimax/vision-conformance.js.map +1 -0
- package/dist/providers/minimax/vision-mappings/chart.d.ts +35 -0
- package/dist/providers/minimax/vision-mappings/chart.d.ts.map +1 -0
- package/dist/providers/minimax/vision-mappings/chart.js +55 -0
- package/dist/providers/minimax/vision-mappings/chart.js.map +1 -0
- package/dist/providers/minimax/vision-mappings/common.d.ts +60 -0
- package/dist/providers/minimax/vision-mappings/common.d.ts.map +1 -0
- package/dist/providers/minimax/vision-mappings/common.js +75 -0
- package/dist/providers/minimax/vision-mappings/common.js.map +1 -0
- package/dist/providers/minimax/vision-mappings/diagnose-error.d.ts +35 -0
- package/dist/providers/minimax/vision-mappings/diagnose-error.d.ts.map +1 -0
- package/dist/providers/minimax/vision-mappings/diagnose-error.js +55 -0
- package/dist/providers/minimax/vision-mappings/diagnose-error.js.map +1 -0
- package/dist/providers/minimax/vision-mappings/diagram.d.ts +35 -0
- package/dist/providers/minimax/vision-mappings/diagram.d.ts.map +1 -0
- package/dist/providers/minimax/vision-mappings/diagram.js +55 -0
- package/dist/providers/minimax/vision-mappings/diagram.js.map +1 -0
- package/dist/providers/minimax/vision-mappings/extract-text.d.ts +35 -0
- package/dist/providers/minimax/vision-mappings/extract-text.d.ts.map +1 -0
- package/dist/providers/minimax/vision-mappings/extract-text.js +55 -0
- package/dist/providers/minimax/vision-mappings/extract-text.js.map +1 -0
- package/dist/providers/minimax/vision-mappings/ui-artifact.d.ts +35 -0
- package/dist/providers/minimax/vision-mappings/ui-artifact.d.ts.map +1 -0
- package/dist/providers/minimax/vision-mappings/ui-artifact.js +69 -0
- package/dist/providers/minimax/vision-mappings/ui-artifact.js.map +1 -0
- package/dist/providers/minimax/vision-mappings.generated.d.ts +29 -0
- package/dist/providers/minimax/vision-mappings.generated.d.ts.map +1 -0
- package/dist/providers/minimax/vision-mappings.generated.js +29 -0
- package/dist/providers/minimax/vision-mappings.generated.js.map +1 -0
- package/dist/providers/minimax/vision-revisions.d.ts +22 -0
- package/dist/providers/minimax/vision-revisions.d.ts.map +1 -0
- package/dist/providers/minimax/vision-revisions.js +27 -0
- package/dist/providers/minimax/vision-revisions.js.map +1 -0
- package/dist/providers/registry.d.ts +36 -0
- package/dist/providers/registry.d.ts.map +1 -0
- package/dist/providers/registry.js +45 -0
- package/dist/providers/registry.js.map +1 -0
- package/dist/providers/selection.d.ts +44 -0
- package/dist/providers/selection.d.ts.map +1 -0
- package/dist/providers/selection.js +85 -0
- package/dist/providers/selection.js.map +1 -0
- package/dist/providers/types.d.ts +247 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +127 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/providers/zai/adapter.d.ts +35 -0
- package/dist/providers/zai/adapter.d.ts.map +1 -0
- package/dist/providers/zai/adapter.js +619 -0
- package/dist/providers/zai/adapter.js.map +1 -0
- package/dist/providers/zai/credentials.d.ts +38 -0
- package/dist/providers/zai/credentials.d.ts.map +1 -0
- package/dist/providers/zai/credentials.js +60 -0
- package/dist/providers/zai/credentials.js.map +1 -0
- package/dist/providers/zai/media.d.ts +38 -0
- package/dist/providers/zai/media.d.ts.map +1 -0
- package/dist/providers/zai/media.js +107 -0
- package/dist/providers/zai/media.js.map +1 -0
- package/dist/providers/zai/monitor-client.d.ts +53 -0
- package/dist/providers/zai/monitor-client.d.ts.map +1 -0
- package/dist/providers/zai/monitor-client.js +117 -0
- package/dist/providers/zai/monitor-client.js.map +1 -0
- package/dist/providers/zai/quota.d.ts +47 -0
- package/dist/providers/zai/quota.d.ts.map +1 -0
- package/dist/providers/zai/quota.js +127 -0
- package/dist/providers/zai/quota.js.map +1 -0
- package/package.json +10 -5
package/dist/lib/output.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Output formatting for Scoutline
|
|
2
|
+
* Output formatting for Scoutline.
|
|
3
|
+
*
|
|
4
|
+
* This Module exposes the pure, invocation-local output contract from
|
|
5
|
+
* DESIGN.md §3: OUTPUT_MODES, OutputMode, isOutputMode,
|
|
6
|
+
* formatSuccessOutput, and formatErrorOutput. The pure `success` and
|
|
7
|
+
* `error` response builders are retained as utility constructors.
|
|
8
|
+
*
|
|
9
|
+
* P1-10 removed the mutable output surface: there is no module-level output
|
|
10
|
+
* mode, no mode setter/getter, no side-effecting success/error writers, no
|
|
11
|
+
* output-mode environment mutation, and no console writes or process
|
|
12
|
+
* termination here. Command presentation and process writes flow through
|
|
13
|
+
* `invokeCommand` and the Node Adapter.
|
|
3
14
|
*/
|
|
15
|
+
export declare const OUTPUT_MODES: readonly ["data", "json", "pretty", "compact", "markdown", "refs", "tty"];
|
|
16
|
+
export type OutputMode = (typeof OUTPUT_MODES)[number];
|
|
4
17
|
export interface SuccessResponse<T = unknown> {
|
|
5
18
|
success: true;
|
|
6
19
|
data: T;
|
|
@@ -13,12 +26,45 @@ export interface ErrorResponse {
|
|
|
13
26
|
help?: string;
|
|
14
27
|
}
|
|
15
28
|
export type Response<T = unknown> = SuccessResponse<T> | ErrorResponse;
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
export declare function isOutputMode(value: unknown): value is OutputMode;
|
|
30
|
+
/**
|
|
31
|
+
* Pure success formatter.
|
|
32
|
+
*
|
|
33
|
+
* - `data` mode emits the raw JSON-encoded data (no success envelope).
|
|
34
|
+
* - `json` / `pretty` modes emit the success envelope with the timestamp
|
|
35
|
+
* taken from the injected `now` (defaults to `Date.now`). `pretty` uses
|
|
36
|
+
* 2-space indentation.
|
|
37
|
+
* - Text-oriented modes (`compact`, `markdown`, `refs`, `tty`) return the
|
|
38
|
+
* explicitly selected command presentation override when `data` carries
|
|
39
|
+
* one (i.e. `data.presentations[mode]` is a string). Otherwise they
|
|
40
|
+
* fall back to the JSON-encoded data.
|
|
41
|
+
*
|
|
42
|
+
* The function performs no I/O and mutates no shared state.
|
|
43
|
+
*/
|
|
44
|
+
export declare function formatSuccessOutput<T>(data: T, mode: OutputMode, now?: () => number): string;
|
|
45
|
+
/**
|
|
46
|
+
* Pure error formatter. Inspects the value through duck typing so this
|
|
47
|
+
* Module does not have to import from `./errors.js` (avoids a circular
|
|
48
|
+
* dependency with the error hierarchy).
|
|
49
|
+
*
|
|
50
|
+
* Recognises a ScoutlineError-shaped object (one carrying `message` and
|
|
51
|
+
* `code`) and surfaces `help` and `statusCode` when present. Plain
|
|
52
|
+
* `Error` instances and unknown values fall through to `UNKNOWN_ERROR`.
|
|
53
|
+
* `pretty` mode indents; all other modes emit compact JSON.
|
|
54
|
+
*
|
|
55
|
+
* The public envelope contains only the documented fields — `success`,
|
|
56
|
+
* `error`, `code`, optional `help`, optional `statusCode` — so stack,
|
|
57
|
+
* cause, raw response body, and any non-envelope property of the input
|
|
58
|
+
* are never serialised. Credential-shaped substrings inside `help` and
|
|
59
|
+
* `error` are redacted.
|
|
60
|
+
*
|
|
61
|
+
* The optional `secrets` argument lets a caller thread the credentials
|
|
62
|
+
* resolved from an injected environment (e.g. `MainDependencies.env`)
|
|
63
|
+
* into redaction, so a secret that exists only in the injected env —
|
|
64
|
+
* and not in ambient `process.env` — is still redacted (Fixup B — B3).
|
|
65
|
+
* When omitted, configured secrets are read from `process.env`.
|
|
66
|
+
*/
|
|
67
|
+
export declare function formatErrorOutput(value: unknown, mode: OutputMode, secrets?: string[]): string;
|
|
19
68
|
export declare function success<T>(data: T): SuccessResponse<T>;
|
|
20
69
|
export declare function error(message: string, code?: string, help?: string): ErrorResponse;
|
|
21
|
-
export declare function output<T>(response: Response<T>): void;
|
|
22
|
-
export declare function outputSuccess<T>(data: T): void;
|
|
23
|
-
export declare function outputError(message: string, code?: string, help?: string): void;
|
|
24
70
|
//# sourceMappingURL=output.d.ts.map
|
package/dist/lib/output.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/lib/output.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/lib/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,eAAO,MAAM,YAAY,YACvB,MAAM,EACN,MAAM,EACN,QAAQ,EACR,SAAS,EACT,UAAU,EACV,MAAM,EACN,KAAK,CACG,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvD,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC1C,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,CAAC;IACR,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,OAAO,IAAI,eAAe,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC;AAEvE,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEhE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,UAAU,EAChB,GAAG,GAAE,MAAM,MAAiB,GAC3B,MAAM,CA2BR;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CA2C9F;AAWD,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAMtD;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,aAAa,CAOlF"}
|
package/dist/lib/output.js
CHANGED
|
@@ -1,14 +1,133 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Output formatting for Scoutline
|
|
2
|
+
* Output formatting for Scoutline.
|
|
3
|
+
*
|
|
4
|
+
* This Module exposes the pure, invocation-local output contract from
|
|
5
|
+
* DESIGN.md §3: OUTPUT_MODES, OutputMode, isOutputMode,
|
|
6
|
+
* formatSuccessOutput, and formatErrorOutput. The pure `success` and
|
|
7
|
+
* `error` response builders are retained as utility constructors.
|
|
8
|
+
*
|
|
9
|
+
* P1-10 removed the mutable output surface: there is no module-level output
|
|
10
|
+
* mode, no mode setter/getter, no side-effecting success/error writers, no
|
|
11
|
+
* output-mode environment mutation, and no console writes or process
|
|
12
|
+
* termination here. Command presentation and process writes flow through
|
|
13
|
+
* `invokeCommand` and the Node Adapter.
|
|
3
14
|
*/
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
15
|
+
import { redactCredentialString, configuredSecrets } from "./redact.js";
|
|
16
|
+
export const OUTPUT_MODES = [
|
|
17
|
+
"data",
|
|
18
|
+
"json",
|
|
19
|
+
"pretty",
|
|
20
|
+
"compact",
|
|
21
|
+
"markdown",
|
|
22
|
+
"refs",
|
|
23
|
+
"tty",
|
|
24
|
+
];
|
|
25
|
+
export function isOutputMode(value) {
|
|
26
|
+
return typeof value === "string" && OUTPUT_MODES.includes(value);
|
|
8
27
|
}
|
|
9
|
-
|
|
10
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Pure success formatter.
|
|
30
|
+
*
|
|
31
|
+
* - `data` mode emits the raw JSON-encoded data (no success envelope).
|
|
32
|
+
* - `json` / `pretty` modes emit the success envelope with the timestamp
|
|
33
|
+
* taken from the injected `now` (defaults to `Date.now`). `pretty` uses
|
|
34
|
+
* 2-space indentation.
|
|
35
|
+
* - Text-oriented modes (`compact`, `markdown`, `refs`, `tty`) return the
|
|
36
|
+
* explicitly selected command presentation override when `data` carries
|
|
37
|
+
* one (i.e. `data.presentations[mode]` is a string). Otherwise they
|
|
38
|
+
* fall back to the JSON-encoded data.
|
|
39
|
+
*
|
|
40
|
+
* The function performs no I/O and mutates no shared state.
|
|
41
|
+
*/
|
|
42
|
+
export function formatSuccessOutput(data, mode, now = Date.now) {
|
|
43
|
+
if (mode === "data") {
|
|
44
|
+
return JSON.stringify(data);
|
|
45
|
+
}
|
|
46
|
+
if (mode === "json" || mode === "pretty") {
|
|
47
|
+
const indent = mode === "pretty" ? 2 : 0;
|
|
48
|
+
return JSON.stringify({ success: true, data, timestamp: now() }, null, indent);
|
|
49
|
+
}
|
|
50
|
+
// Text-oriented modes: prefer an explicitly selected command
|
|
51
|
+
// presentation override carried on `data.presentations`.
|
|
52
|
+
if (data !== null &&
|
|
53
|
+
typeof data === "object" &&
|
|
54
|
+
"presentations" in data &&
|
|
55
|
+
data.presentations !== null &&
|
|
56
|
+
typeof data.presentations === "object") {
|
|
57
|
+
const presentations = data.presentations;
|
|
58
|
+
const override = presentations[mode];
|
|
59
|
+
if (typeof override === "string") {
|
|
60
|
+
return override;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return JSON.stringify(data);
|
|
11
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Pure error formatter. Inspects the value through duck typing so this
|
|
67
|
+
* Module does not have to import from `./errors.js` (avoids a circular
|
|
68
|
+
* dependency with the error hierarchy).
|
|
69
|
+
*
|
|
70
|
+
* Recognises a ScoutlineError-shaped object (one carrying `message` and
|
|
71
|
+
* `code`) and surfaces `help` and `statusCode` when present. Plain
|
|
72
|
+
* `Error` instances and unknown values fall through to `UNKNOWN_ERROR`.
|
|
73
|
+
* `pretty` mode indents; all other modes emit compact JSON.
|
|
74
|
+
*
|
|
75
|
+
* The public envelope contains only the documented fields — `success`,
|
|
76
|
+
* `error`, `code`, optional `help`, optional `statusCode` — so stack,
|
|
77
|
+
* cause, raw response body, and any non-envelope property of the input
|
|
78
|
+
* are never serialised. Credential-shaped substrings inside `help` and
|
|
79
|
+
* `error` are redacted.
|
|
80
|
+
*
|
|
81
|
+
* The optional `secrets` argument lets a caller thread the credentials
|
|
82
|
+
* resolved from an injected environment (e.g. `MainDependencies.env`)
|
|
83
|
+
* into redaction, so a secret that exists only in the injected env —
|
|
84
|
+
* and not in ambient `process.env` — is still redacted (Fixup B — B3).
|
|
85
|
+
* When omitted, configured secrets are read from `process.env`.
|
|
86
|
+
*/
|
|
87
|
+
export function formatErrorOutput(value, mode, secrets) {
|
|
88
|
+
const indent = mode === "pretty" ? 2 : 0;
|
|
89
|
+
const resolvedSecrets = secrets ?? configuredSecrets();
|
|
90
|
+
let payload;
|
|
91
|
+
const isShapedError = value !== null && typeof value === "object" && "message" in value && "code" in value;
|
|
92
|
+
if (isShapedError) {
|
|
93
|
+
const err = value;
|
|
94
|
+
const rawError = typeof err.message === "string" ? err.message : String(err.message);
|
|
95
|
+
payload = {
|
|
96
|
+
success: false,
|
|
97
|
+
error: redactCredentialString(rawError, resolvedSecrets),
|
|
98
|
+
code: typeof err.code === "string" ? err.code : "UNKNOWN_ERROR",
|
|
99
|
+
};
|
|
100
|
+
if (typeof err.help === "string" && err.help.length > 0) {
|
|
101
|
+
payload.help = redactCredentialString(err.help, resolvedSecrets);
|
|
102
|
+
}
|
|
103
|
+
if (typeof err.statusCode === "number") {
|
|
104
|
+
payload.statusCode = err.statusCode;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else if (value instanceof Error) {
|
|
108
|
+
payload = {
|
|
109
|
+
success: false,
|
|
110
|
+
error: redactCredentialString(value.message, resolvedSecrets),
|
|
111
|
+
code: "UNKNOWN_ERROR",
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
payload = {
|
|
116
|
+
success: false,
|
|
117
|
+
error: redactCredentialString(String(value), resolvedSecrets),
|
|
118
|
+
code: "UNKNOWN_ERROR",
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return JSON.stringify(payload, null, indent);
|
|
122
|
+
}
|
|
123
|
+
// ---------------------------------------------------------------------------
|
|
124
|
+
// Pure response builders. These construct plain response objects and perform
|
|
125
|
+
// no I/O. They are retained as utility constructors; the side-effecting
|
|
126
|
+
// mutable output surface (mode setter/getter, the success/error writers, the
|
|
127
|
+
// module-level mode variable, output-mode env mutation, and process
|
|
128
|
+
// termination) was removed in P1-10. Command presentation and process writes
|
|
129
|
+
// now flow exclusively through `invokeCommand` and the Node Adapter.
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
12
131
|
export function success(data) {
|
|
13
132
|
return {
|
|
14
133
|
success: true,
|
|
@@ -24,36 +143,4 @@ export function error(message, code, help) {
|
|
|
24
143
|
...(help && { help }),
|
|
25
144
|
};
|
|
26
145
|
}
|
|
27
|
-
export function output(response) {
|
|
28
|
-
const pretty = outputMode === "pretty";
|
|
29
|
-
console.log(JSON.stringify(response, null, pretty ? 2 : 0));
|
|
30
|
-
}
|
|
31
|
-
export function outputSuccess(data) {
|
|
32
|
-
// Search-specific text formats; data is expected to be a pre-formatted string.
|
|
33
|
-
if (outputMode === "compact" ||
|
|
34
|
-
outputMode === "markdown" ||
|
|
35
|
-
outputMode === "refs" ||
|
|
36
|
-
outputMode === "tty") {
|
|
37
|
-
if (typeof data === "string") {
|
|
38
|
-
console.log(data);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
console.log(JSON.stringify(data, null, 0));
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
if (outputMode === "data") {
|
|
45
|
-
if (typeof data === "string") {
|
|
46
|
-
console.log(data);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
console.log(JSON.stringify(data, null, 0));
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
output(success(data));
|
|
53
|
-
}
|
|
54
|
-
export function outputError(message, code, help) {
|
|
55
|
-
const pretty = outputMode === "pretty";
|
|
56
|
-
console.error(JSON.stringify(error(message, code, help), null, pretty ? 2 : 0));
|
|
57
|
-
process.exit(1);
|
|
58
|
-
}
|
|
59
146
|
//# sourceMappingURL=output.js.map
|
package/dist/lib/output.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/lib/output.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/lib/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAExE,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,UAAU;IACV,MAAM;IACN,KAAK;CACG,CAAC;AAmBX,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAK,YAAkC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC1F,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAO,EACP,IAAgB,EAChB,GAAG,GAAiB,IAAI,CAAC,GAAG;IAE5B,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACzC,MAAM,MAAM,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6E;AAC7E,qEAAqE;AACrE,8EAA8E;AAE9E,MAAM,UAAU,OAAO,CAAI,IAAO;IAChC,OAAO;QACL,OAAO,EAAE,IAAI;QACb,IAAI;QACJ,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACtB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,OAAe,EAAE,IAAa,EAAE,IAAa;IACjE,OAAO;QACL,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,OAAO;QACd,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,CAAC;QACrB,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,CAAC;KACtB,CAAC;AACJ,CAAC"}
|
package/dist/lib/redact.d.ts
CHANGED
|
@@ -1,7 +1,66 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Recursive Provider credential redaction (DESIGN.md §16).
|
|
3
|
+
*
|
|
4
|
+
* This Module is the single source of truth for stripping Provider
|
|
5
|
+
* credentials before any value leaves Scoutline's outward boundaries:
|
|
6
|
+
* formatted errors, cached metadata, quota failures, diagnostics output,
|
|
7
|
+
* and fatal shell errors.
|
|
8
|
+
*
|
|
9
|
+
* Redaction properties (Phase 4 P4-01):
|
|
10
|
+
* - Case-insensitive for the canonical credential-shaped keys.
|
|
11
|
+
* - Recursive through nested arrays and plain objects.
|
|
12
|
+
* - Non-mutating — the original input is never modified.
|
|
13
|
+
* - Secret-aware — every configured secret value is replaced inside
|
|
14
|
+
* any string the value tree reaches, not just the configured key.
|
|
15
|
+
* - Empty-safe — empty strings are never treated as a replacement token.
|
|
16
|
+
*
|
|
17
|
+
* The Module retains the legacy `redactSecrets(value, apiKey?)` and
|
|
18
|
+
* `redactTool(tool)` exports so existing call sites keep compiling.
|
|
19
|
+
* New code should pass an explicit array of secrets so every Provider's
|
|
20
|
+
* credential is covered in one pass.
|
|
3
21
|
*/
|
|
4
22
|
import type { Tool } from "@utcp/sdk";
|
|
5
|
-
|
|
6
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Replace credential-shaped substrings inside a single string. Useful
|
|
25
|
+
* for error messages and load-failure texts where the value is a flat
|
|
26
|
+
* string rather than a structured object.
|
|
27
|
+
*
|
|
28
|
+
* Replaces:
|
|
29
|
+
* - Bearer authorization values (any case).
|
|
30
|
+
* - x-api-key assignments (any case; `=`, `:`, or whitespace as the
|
|
31
|
+
* key/value separator — covers both `x-api-key=value` and
|
|
32
|
+
* `x-api-key value`).
|
|
33
|
+
* - Z_AI_API_KEY, ZAI_API_KEY, MINIMAX_API_KEY assignments.
|
|
34
|
+
* - The literal credentials passed in `extraSecrets` (each value is
|
|
35
|
+
* replaced wherever it appears; empty strings are skipped).
|
|
36
|
+
*/
|
|
37
|
+
export declare function redactCredentialString(input: string, extraSecrets?: string | string[]): string;
|
|
38
|
+
/**
|
|
39
|
+
* Resolve the configured Provider credential values from the current
|
|
40
|
+
* process environment. Returned values are deduplicated and empty
|
|
41
|
+
* entries skipped, so callers can pass the result directly to
|
|
42
|
+
* {@link redactSecrets}.
|
|
43
|
+
*/
|
|
44
|
+
export declare function configuredSecrets(env?: NodeJS.ProcessEnv): string[];
|
|
45
|
+
/**
|
|
46
|
+
* Recursively redact credential values from an arbitrary tree.
|
|
47
|
+
*
|
|
48
|
+
* Accepts either a single string (back-compat overload) or an array of
|
|
49
|
+
* secret values. Returns a NEW value tree; the input is never mutated.
|
|
50
|
+
*
|
|
51
|
+
* Key matching is case-insensitive over {@link CREDENTIAL_KEYS}. Plain
|
|
52
|
+
* objects and arrays are descended into. Other object kinds (Date,
|
|
53
|
+
* typed arrays, class instances) are returned as-is so their internal
|
|
54
|
+
* state is not reflected.
|
|
55
|
+
*/
|
|
56
|
+
export declare function redactSecrets(value: unknown, secrets?: string | string[]): unknown;
|
|
57
|
+
/**
|
|
58
|
+
* Redact credential-shaped fields from a Tool's metadata tree.
|
|
59
|
+
*
|
|
60
|
+
* Back-compat: when called with a single argument the function reads
|
|
61
|
+
* the configured Provider credentials from the current process
|
|
62
|
+
* environment. When called with an explicit secrets argument, the
|
|
63
|
+
* caller's value is used instead.
|
|
64
|
+
*/
|
|
65
|
+
export declare function redactTool(tool: Tool, secrets?: string | string[]): Tool;
|
|
7
66
|
//# sourceMappingURL=redact.d.ts.map
|
package/dist/lib/redact.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redact.d.ts","sourceRoot":"","sources":["../../src/lib/redact.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"redact.d.ts","sourceRoot":"","sources":["../../src/lib/redact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAqBtC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CA0B9F;AAuBD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,EAAE,CAOhF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAiClF;AAQD;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAMxE"}
|
package/dist/lib/redact.js
CHANGED
|
@@ -1,50 +1,184 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Recursive Provider credential redaction (DESIGN.md §16).
|
|
3
|
+
*
|
|
4
|
+
* This Module is the single source of truth for stripping Provider
|
|
5
|
+
* credentials before any value leaves Scoutline's outward boundaries:
|
|
6
|
+
* formatted errors, cached metadata, quota failures, diagnostics output,
|
|
7
|
+
* and fatal shell errors.
|
|
8
|
+
*
|
|
9
|
+
* Redaction properties (Phase 4 P4-01):
|
|
10
|
+
* - Case-insensitive for the canonical credential-shaped keys.
|
|
11
|
+
* - Recursive through nested arrays and plain objects.
|
|
12
|
+
* - Non-mutating — the original input is never modified.
|
|
13
|
+
* - Secret-aware — every configured secret value is replaced inside
|
|
14
|
+
* any string the value tree reaches, not just the configured key.
|
|
15
|
+
* - Empty-safe — empty strings are never treated as a replacement token.
|
|
16
|
+
*
|
|
17
|
+
* The Module retains the legacy `redactSecrets(value, apiKey?)` and
|
|
18
|
+
* `redactTool(tool)` exports so existing call sites keep compiling.
|
|
19
|
+
* New code should pass an explicit array of secrets so every Provider's
|
|
20
|
+
* credential is covered in one pass.
|
|
3
21
|
*/
|
|
4
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Canonical credential-shaped key names. Lowercased so case-insensitive
|
|
24
|
+
* matching is a one-step compare. Covers every name DESIGN.md §16
|
|
25
|
+
* enumerates plus the common HTTP header aliases.
|
|
26
|
+
*/
|
|
27
|
+
const CREDENTIAL_KEYS = new Set([
|
|
5
28
|
"authorization",
|
|
6
|
-
"
|
|
29
|
+
"x-api-key",
|
|
7
30
|
"api_key",
|
|
8
|
-
"
|
|
31
|
+
"apikey",
|
|
9
32
|
"access_token",
|
|
10
33
|
"token",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
34
|
+
"z_ai_api_key",
|
|
35
|
+
"zai_api_key",
|
|
36
|
+
"minimax_api_key",
|
|
13
37
|
]);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
38
|
+
const REDACTED = "[REDACTED]";
|
|
39
|
+
/**
|
|
40
|
+
* Replace credential-shaped substrings inside a single string. Useful
|
|
41
|
+
* for error messages and load-failure texts where the value is a flat
|
|
42
|
+
* string rather than a structured object.
|
|
43
|
+
*
|
|
44
|
+
* Replaces:
|
|
45
|
+
* - Bearer authorization values (any case).
|
|
46
|
+
* - x-api-key assignments (any case; `=`, `:`, or whitespace as the
|
|
47
|
+
* key/value separator — covers both `x-api-key=value` and
|
|
48
|
+
* `x-api-key value`).
|
|
49
|
+
* - Z_AI_API_KEY, ZAI_API_KEY, MINIMAX_API_KEY assignments.
|
|
50
|
+
* - The literal credentials passed in `extraSecrets` (each value is
|
|
51
|
+
* replaced wherever it appears; empty strings are skipped).
|
|
52
|
+
*/
|
|
53
|
+
export function redactCredentialString(input, extraSecrets) {
|
|
54
|
+
if (typeof input !== "string")
|
|
55
|
+
return input;
|
|
56
|
+
let result = input;
|
|
57
|
+
result = result.replace(/Bearer\s+\S+/gi, REDACTED);
|
|
58
|
+
// Fixup C — W3: the class accepts either `=`, `:`, or any whitespace
|
|
59
|
+
// as the key/value separator. The trailing `\S+` consumes the secret
|
|
60
|
+
// value; the entire `key + separator + value` span is replaced with
|
|
61
|
+
// the redaction marker.
|
|
62
|
+
result = result.replace(/x-api-key[\s=:]+[^\s,;"'`]+/gi, REDACTED);
|
|
63
|
+
result = result.replace(/Z_AI_API_KEY\s*=\s*\S+/gi, REDACTED);
|
|
64
|
+
result = result.replace(/ZAI_API_KEY\s*=\s*\S+/gi, REDACTED);
|
|
65
|
+
result = result.replace(/MINIMAX_API_KEY\s*=\s*\S+/gi, REDACTED);
|
|
66
|
+
// Embedded credential substrings inside URLs, e.g.
|
|
67
|
+
// `https://user:secret@host/path`. Catches both `https://` and
|
|
68
|
+
// `http://` schemes and replaces the entire URL with the marker so
|
|
69
|
+
// the user info does not leak.
|
|
70
|
+
result = result.replace(/https?:\/\/[^\s/:]+:[^\s@\/]+@[^\s/]+/gi, REDACTED);
|
|
71
|
+
const secrets = normalizeSecrets(extraSecrets);
|
|
72
|
+
for (const secret of secrets) {
|
|
73
|
+
if (secret.length === 0)
|
|
74
|
+
continue;
|
|
75
|
+
// Escape regex meta characters so a secret containing characters
|
|
76
|
+
// like `.` or `+` does not accidentally broaden the replacement.
|
|
77
|
+
const escaped = secret.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
78
|
+
result = result.replace(new RegExp(escaped, "g"), REDACTED);
|
|
21
79
|
}
|
|
22
80
|
return result;
|
|
23
81
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Normalise the `secrets` argument to a deduplicated array of
|
|
84
|
+
* non-empty strings. A `undefined` argument yields an empty list;
|
|
85
|
+
* a single string yields `[string]`; an array yields the filtered
|
|
86
|
+
* list.
|
|
87
|
+
*/
|
|
88
|
+
function normalizeSecrets(secrets) {
|
|
89
|
+
if (secrets === undefined)
|
|
90
|
+
return [];
|
|
91
|
+
const list = Array.isArray(secrets) ? secrets : [secrets];
|
|
92
|
+
const out = [];
|
|
93
|
+
const seen = new Set();
|
|
94
|
+
for (const item of list) {
|
|
95
|
+
if (typeof item !== "string")
|
|
96
|
+
continue;
|
|
97
|
+
if (item.length === 0)
|
|
98
|
+
continue;
|
|
99
|
+
if (seen.has(item))
|
|
100
|
+
continue;
|
|
101
|
+
seen.add(item);
|
|
102
|
+
out.push(item);
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Resolve the configured Provider credential values from the current
|
|
108
|
+
* process environment. Returned values are deduplicated and empty
|
|
109
|
+
* entries skipped, so callers can pass the result directly to
|
|
110
|
+
* {@link redactSecrets}.
|
|
111
|
+
*/
|
|
112
|
+
export function configuredSecrets(env = process.env) {
|
|
113
|
+
const candidates = [
|
|
114
|
+
env.Z_AI_API_KEY,
|
|
115
|
+
env.ZAI_API_KEY,
|
|
116
|
+
env.MINIMAX_API_KEY,
|
|
117
|
+
];
|
|
118
|
+
return normalizeSecrets(candidates.filter((c) => typeof c === "string"));
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Recursively redact credential values from an arbitrary tree.
|
|
122
|
+
*
|
|
123
|
+
* Accepts either a single string (back-compat overload) or an array of
|
|
124
|
+
* secret values. Returns a NEW value tree; the input is never mutated.
|
|
125
|
+
*
|
|
126
|
+
* Key matching is case-insensitive over {@link CREDENTIAL_KEYS}. Plain
|
|
127
|
+
* objects and arrays are descended into. Other object kinds (Date,
|
|
128
|
+
* typed arrays, class instances) are returned as-is so their internal
|
|
129
|
+
* state is not reflected.
|
|
130
|
+
*/
|
|
131
|
+
export function redactSecrets(value, secrets) {
|
|
132
|
+
const normalized = normalizeSecrets(secrets);
|
|
133
|
+
// Fast path: primitive value or null/undefined.
|
|
134
|
+
if (value === null || value === undefined)
|
|
135
|
+
return value;
|
|
136
|
+
const t = typeof value;
|
|
137
|
+
if (t === "string") {
|
|
138
|
+
return redactCredentialString(value, normalized);
|
|
27
139
|
}
|
|
140
|
+
if (t !== "object")
|
|
141
|
+
return value;
|
|
142
|
+
// Recurse through arrays.
|
|
28
143
|
if (Array.isArray(value)) {
|
|
29
|
-
return value.map((item) => redactSecrets(item,
|
|
144
|
+
return value.map((item) => redactSecrets(item, normalized));
|
|
30
145
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
146
|
+
// Skip exotic non-plain objects: Date, TypedArrays, Map, Set,
|
|
147
|
+
// class instances. Plain objects descend; everything else is left
|
|
148
|
+
// untouched to avoid reflecting internal state.
|
|
149
|
+
if (!isPlainObject(value)) {
|
|
150
|
+
return value;
|
|
151
|
+
}
|
|
152
|
+
const input = value;
|
|
153
|
+
const output = {};
|
|
154
|
+
for (const key of Object.keys(input)) {
|
|
155
|
+
if (CREDENTIAL_KEYS.has(key.toLowerCase())) {
|
|
156
|
+
output[key] = REDACTED;
|
|
157
|
+
continue;
|
|
40
158
|
}
|
|
41
|
-
|
|
159
|
+
output[key] = redactSecrets(input[key], normalized);
|
|
42
160
|
}
|
|
43
|
-
return
|
|
161
|
+
return output;
|
|
162
|
+
}
|
|
163
|
+
function isPlainObject(value) {
|
|
164
|
+
if (value === null || typeof value !== "object")
|
|
165
|
+
return false;
|
|
166
|
+
const proto = Object.getPrototypeOf(value);
|
|
167
|
+
return proto === Object.prototype || proto === null;
|
|
44
168
|
}
|
|
45
|
-
|
|
46
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Redact credential-shaped fields from a Tool's metadata tree.
|
|
171
|
+
*
|
|
172
|
+
* Back-compat: when called with a single argument the function reads
|
|
173
|
+
* the configured Provider credentials from the current process
|
|
174
|
+
* environment. When called with an explicit secrets argument, the
|
|
175
|
+
* caller's value is used instead.
|
|
176
|
+
*/
|
|
177
|
+
export function redactTool(tool, secrets) {
|
|
178
|
+
const resolved = secrets === undefined
|
|
179
|
+
? configuredSecrets()
|
|
180
|
+
: normalizeSecrets(secrets);
|
|
47
181
|
const clone = JSON.parse(JSON.stringify(tool));
|
|
48
|
-
return redactSecrets(clone,
|
|
182
|
+
return redactSecrets(clone, resolved);
|
|
49
183
|
}
|
|
50
184
|
//# sourceMappingURL=redact.js.map
|
package/dist/lib/redact.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redact.js","sourceRoot":"","sources":["../../src/lib/redact.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"redact.js","sourceRoot":"","sources":["../../src/lib/redact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH;;;;GAIG;AACH,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC;IACnD,eAAe;IACf,WAAW;IACX,SAAS;IACT,QAAQ;IACR,cAAc;IACd,OAAO;IACP,cAAc;IACd,aAAa;IACb,iBAAiB;CAClB,CAAC,CAAC;AAEH,MAAM,QAAQ,GAAG,YAAY,CAAC;AAE9B;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAa,EAAE,YAAgC;IACpF,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK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C,OAAO,CAAC,CAAC;IAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAS,CAAC;IACvD,OAAO,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAS,CAAC;AAChD,CAAC"}
|
package/dist/lib/tty.d.ts
CHANGED
|
@@ -36,25 +36,12 @@ interface SearchResultLike {
|
|
|
36
36
|
occurrences?: number;
|
|
37
37
|
}
|
|
38
38
|
export declare function formatSearchResultsPretty(results: SearchResultLike[]): string;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
windowHours?: number;
|
|
47
|
-
resetsIn?: string | null;
|
|
48
|
-
byTool?: Array<{
|
|
49
|
-
modelCode?: string;
|
|
50
|
-
usage?: number;
|
|
51
|
-
}>;
|
|
52
|
-
} | null;
|
|
53
|
-
tokens?: {
|
|
54
|
-
percentage?: number;
|
|
55
|
-
resetsIn?: string | null;
|
|
56
|
-
} | null;
|
|
57
|
-
}
|
|
58
|
-
export declare function formatQuotaPretty(q: QuotaLike): string;
|
|
39
|
+
import type { QuotaDashboard } from "../capabilities/quota.js";
|
|
40
|
+
/**
|
|
41
|
+
* Provider-neutral TTY rendering of a {@link QuotaDashboard}. Each
|
|
42
|
+
* Provider entry is labelled with its Provider id and each category by
|
|
43
|
+
* its normalized name; progress bars represent the REMAINING percentage.
|
|
44
|
+
*/
|
|
45
|
+
export declare function formatQuotaDashboard(dashboard: QuotaDashboard): string;
|
|
59
46
|
export {};
|
|
60
47
|
//# sourceMappingURL=tty.d.ts.map
|
package/dist/lib/tty.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tty.d.ts","sourceRoot":"","sources":["../../src/lib/tty.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,KAAK,OAAO,GAAG,CAAC,CAAC,EAAE,MAAM,KA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