@juicesharp/rpiv-web-tools 2.6.0 → 2.6.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/docs/configuration.md +6 -5
- package/package.json +3 -2
- package/providers/config.ts +74 -11
package/docs/configuration.md
CHANGED
|
@@ -50,13 +50,14 @@ rewritten to drop fields it does not recognise.
|
|
|
50
50
|
## Failure behaviour
|
|
51
51
|
|
|
52
52
|
The whole file degrades to an empty config rather than crashing the session when
|
|
53
|
-
it is missing, is not valid JSON, is a directory
|
|
54
|
-
|
|
53
|
+
it is missing, is not valid JSON, or is a directory. A schema violation degrades
|
|
54
|
+
per field: only the offending paths are dropped for the session (an empty config
|
|
55
|
+
remains the floor when nothing salvageable is left).
|
|
55
56
|
|
|
56
57
|
Guidance validation is independently fail-soft: an empty string, a wrong type,
|
|
57
|
-
or an empty array in any `promptSnippet` / `promptGuidelines`
|
|
58
|
-
falls back to the built-in default for that field alone. The
|
|
59
|
-
unaffected.
|
|
58
|
+
or an empty array in any `promptSnippet` / `promptGuidelines` / `description`
|
|
59
|
+
field silently falls back to the built-in default for that field alone. The
|
|
60
|
+
other fields are unaffected.
|
|
60
61
|
|
|
61
62
|
## Executor guidance overrides
|
|
62
63
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-web-tools",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"description": "Pi extension. Web search and fetch for the model with pluggable providers (Brave, Tavily, Serper, Exa, You.com, Jina, Firecrawl, Perplexity, SearXNG, Ollama).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -59,12 +59,13 @@
|
|
|
59
59
|
"!**/*.test.ts"
|
|
60
60
|
],
|
|
61
61
|
"pi": {
|
|
62
|
+
"image": "https://raw.githubusercontent.com/juicesharp/rpiv-mono/main/packages/rpiv-web-tools/docs/cover.png",
|
|
62
63
|
"extensions": [
|
|
63
64
|
"./index.ts"
|
|
64
65
|
]
|
|
65
66
|
},
|
|
66
67
|
"dependencies": {
|
|
67
|
-
"@juicesharp/rpiv-config": "^2.6.
|
|
68
|
+
"@juicesharp/rpiv-config": "^2.6.1",
|
|
68
69
|
"typebox": "^1.1.24"
|
|
69
70
|
},
|
|
70
71
|
"peerDependencies": {
|
package/providers/config.ts
CHANGED
|
@@ -8,9 +8,10 @@
|
|
|
8
8
|
* legacy-apiKey migration depends on.
|
|
9
9
|
*
|
|
10
10
|
* Validation is fail-soft (matching `loadJsonConfig` and `validateConfig` in
|
|
11
|
-
* rpiv-config): malformed JSON
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* rpiv-config): malformed JSON and EISDIR degrade to `{}`; a schema violation
|
|
12
|
+
* degrades per field — only the offending paths are dropped, `{}` remains the
|
|
13
|
+
* floor when nothing salvageable is left. The orchestrator never has to
|
|
14
|
+
* handle "config blew up at startup."
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
17
|
import {
|
|
@@ -75,17 +76,79 @@ export function getConfigPath(): string {
|
|
|
75
76
|
return CONFIG_PATH;
|
|
76
77
|
}
|
|
77
78
|
|
|
79
|
+
/** JSON-pointer segments of a `Value.Errors` `instancePath` (`~1` ⇒ `/`, `~0` ⇒ `~`). */
|
|
80
|
+
const pointerSegments = (instancePath: string): string[] =>
|
|
81
|
+
instancePath === ""
|
|
82
|
+
? []
|
|
83
|
+
: instancePath
|
|
84
|
+
.split("/")
|
|
85
|
+
.slice(1)
|
|
86
|
+
.map((s) => s.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Delete the value at `segs` from `root`, widening to the nearest containing
|
|
90
|
+
* FIELD when the path descends into an array (deleting one element would leave
|
|
91
|
+
* a sparse hole that still fails validation — the whole array field falls back
|
|
92
|
+
* instead). Returns false when the path is already gone (a prior deletion took
|
|
93
|
+
* an ancestor).
|
|
94
|
+
*/
|
|
95
|
+
const deleteAtPointer = (root: Record<string, unknown>, segs: string[]): boolean => {
|
|
96
|
+
let parent: Record<string, unknown> = root;
|
|
97
|
+
for (let i = 0; i < segs.length - 1; i++) {
|
|
98
|
+
const next = parent[segs[i] as string];
|
|
99
|
+
if (next === null || typeof next !== "object") return false;
|
|
100
|
+
if (Array.isArray(next)) {
|
|
101
|
+
delete parent[segs[i] as string];
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
parent = next as Record<string, unknown>;
|
|
105
|
+
}
|
|
106
|
+
const leaf = segs[segs.length - 1] as string;
|
|
107
|
+
if (!(leaf in parent)) return false;
|
|
108
|
+
delete parent[leaf];
|
|
109
|
+
return true;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Per-field salvage of a config that fails the whole-schema check: drop
|
|
114
|
+
* exactly the offending paths `Value.Errors` reports and keep everything else,
|
|
115
|
+
* so one wrong-typed leaf (e.g. `guidance.web_search.description: 123`) costs
|
|
116
|
+
* that field alone — not provider, apiKeys, baseUrls, interceptors and both
|
|
117
|
+
* guidance subtrees for the session, with the `/web-tools` save path then
|
|
118
|
+
* persisting the wipe. Unknown keys are untouched (`additionalProperties:
|
|
119
|
+
* true` reports no errors for them), preserving the `otherField` pass-through
|
|
120
|
+
* contract. Deletions are schema-driven, so a future shared-`GuidanceFields`
|
|
121
|
+
* field addition cannot re-open the whole-file cliff. The pass loop is belt
|
|
122
|
+
* and braces for cascading reports (e.g. a union error at the field alongside
|
|
123
|
+
* its nested cause); a round that deletes nothing, or a config still failing
|
|
124
|
+
* after the bounded passes, degrades to `{}` exactly as before.
|
|
125
|
+
*/
|
|
126
|
+
const salvageConfig = (raw: object): WebToolsConfig | undefined => {
|
|
127
|
+
const cfg = structuredClone(raw) as Record<string, unknown>;
|
|
128
|
+
for (let pass = 0; pass < 5; pass++) {
|
|
129
|
+
const errors = [...Value.Errors(WebToolsConfigSchema, cfg)];
|
|
130
|
+
if (errors.length === 0) return cfg as WebToolsConfig;
|
|
131
|
+
let deleted = false;
|
|
132
|
+
for (const e of errors) {
|
|
133
|
+
const segs = pointerSegments(e.instancePath);
|
|
134
|
+
if (segs.length === 0) return undefined; // root itself invalid — unsalvageable
|
|
135
|
+
if (deleteAtPointer(cfg, segs)) deleted = true;
|
|
136
|
+
}
|
|
137
|
+
if (!deleted) return undefined;
|
|
138
|
+
}
|
|
139
|
+
return Value.Check(WebToolsConfigSchema, cfg) ? (cfg as WebToolsConfig) : undefined;
|
|
140
|
+
};
|
|
141
|
+
|
|
78
142
|
// Tolerant read: loadJsonConfig already swallows JSON parse failures + EISDIR
|
|
79
|
-
// into `{}`;
|
|
80
|
-
//
|
|
81
|
-
// `Value.
|
|
82
|
-
// pass-through contract).
|
|
143
|
+
// into `{}`; a schema violation then degrades PER FIELD via `salvageConfig`
|
|
144
|
+
// (whole-file `{}` only when nothing salvageable remains). Validation uses
|
|
145
|
+
// `Value.Check`/`Value.Errors` (no mutation) rather than `Value.Clean` (would
|
|
146
|
+
// strip unknown fields like the released `otherField` pass-through contract).
|
|
83
147
|
export function readConfig(): WebToolsConfig {
|
|
84
148
|
const raw = loadJsonConfigWithLegacyFallback<unknown>("rpiv-web-tools");
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
return raw as WebToolsConfig;
|
|
149
|
+
if (Value.Check(WebToolsConfigSchema, raw)) return raw as WebToolsConfig;
|
|
150
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return {} as WebToolsConfig;
|
|
151
|
+
return salvageConfig(raw) ?? ({} as WebToolsConfig);
|
|
89
152
|
}
|
|
90
153
|
|
|
91
154
|
export function writeConfig(c: WebToolsConfig): boolean {
|