@evandu/super-pi 0.1.216 → 0.1.218
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/client/.super-pi-client-sources.json +6 -6
- package/dist/client/assets/{CodeMirrorEditor-lexoCaIG.js → CodeMirrorEditor-CyESWKhO.js} +2 -2
- package/dist/client/assets/{dist-BnnInFnU.js → dist-1djw1Aua.js} +1 -1
- package/dist/client/assets/{dist-3-Tz7V5x.js → dist-B33BwR-8.js} +1 -1
- package/dist/client/assets/{dist-Bb5oLu1I.js → dist-BQ5yUYGI.js} +1 -1
- package/dist/client/assets/{dist-BK9jBgy4.js → dist-BXMYNRiG.js} +1 -1
- package/dist/client/assets/{dist-BpfM-LP8.js → dist-BXq9HMCd.js} +1 -1
- package/dist/client/assets/{dist-DNfXS-LN.js → dist-BfAB10-T.js} +1 -1
- package/dist/client/assets/{dist-B3rJZwH0.js → dist-BlALlifb.js} +1 -1
- package/dist/client/assets/{dist-CYNCQ0fQ.js → dist-BwQiVXeZ.js} +1 -1
- package/dist/client/assets/{dist-B8hN96MY.js → dist-C6tiomV0.js} +1 -1
- package/dist/client/assets/{dist-BG9UcsbA.js → dist-C7y8W3IU.js} +1 -1
- package/dist/client/assets/{dist-B38kVE3N.js → dist-C9qNY2Kp.js} +1 -1
- package/dist/client/assets/{dist-otNdihLI.js → dist-CWLwzCNI.js} +1 -1
- package/dist/client/assets/{dist-DHLp8Bhu.js → dist-Cgclz1Km.js} +1 -1
- package/dist/client/assets/{dist-BPCH5VZO.js → dist-CkjmcyTq.js} +1 -1
- package/dist/client/assets/{dist-FKpeRDqz.js → dist-DH6F4kKv.js} +1 -1
- package/dist/client/assets/{dist-BmyPZADX.js → dist-DHh4-Br1.js} +1 -1
- package/dist/client/assets/{dist-Bhq8WMen.js → dist-DZGY_CNU.js} +1 -1
- package/dist/client/assets/{dist-B-mRGWa4.js → dist-DtyV497P.js} +1 -1
- package/dist/client/assets/{dist-Bk2EriC1.js → dist-GMozZ-IZ.js} +1 -1
- package/dist/client/assets/{dist-B9VATyNG.js → dist-XNj0UVAT.js} +1 -1
- package/dist/client/assets/{dist-DgZHuTC8.js → dist-Zl8KoipB.js} +1 -1
- package/dist/client/assets/{dist-Da4kKR0w.js → dist-xAE0Sxu_.js} +1 -1
- package/dist/client/assets/{index-Dc62tdic.js → index-2k9h0zMt.js} +20 -20
- package/dist/client/assets/index-CwfAN5Vw.css +1 -0
- package/dist/client/index.html +2 -2
- package/dist/server/application/provider-service.js +50 -7
- package/dist/server/pi-session.d.ts +26 -5
- package/dist/server/pi-session.js +64 -12
- package/dist/server/providers.d.ts +22 -1
- package/dist/server/providers.js +106 -17
- package/dist/server/runtime.js +19 -3
- package/dist/server/thinking-level-discovery.d.ts +38 -0
- package/dist/server/thinking-level-discovery.js +159 -0
- package/dist/server/types.d.ts +25 -0
- package/dist/shared/thinking-levels.d.ts +53 -0
- package/dist/shared/thinking-levels.js +85 -0
- package/package.json +1 -1
- package/dist/client/assets/index-DVt_dk47.css +0 -1
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { PI_THINKING_LEVELS } from "../shared/thinking-levels.js";
|
|
2
|
+
/**
|
|
3
|
+
* THE API THE LEVELS BELONG TO, and the one the form means when it says nothing.
|
|
4
|
+
*
|
|
5
|
+
* The form's API list starts with `openai-completions`, and an empty field is that one - which is
|
|
6
|
+
* why an absent API is read as this one rather than as "unknown".
|
|
7
|
+
*/
|
|
8
|
+
const DEFAULT_API = "openai-completions";
|
|
9
|
+
/**
|
|
10
|
+
* THE EFFORT NAME Pi KNOWS, AND THE Pi LEVEL IT IS.
|
|
11
|
+
*
|
|
12
|
+
* The provider's `reasoning_effort` values and Pi's levels are the same words, with one addition:
|
|
13
|
+
* OpenAI's `none` is Pi's `off` (thinking switched off, sent as `none`). A value that is not in
|
|
14
|
+
* this table is NOT translated - a provider that calls its levels `ultra` or `high_intensity` gets
|
|
15
|
+
* no map at all rather than a map that guesses what `ultra` means.
|
|
16
|
+
*
|
|
17
|
+
* A MAP, NOT AN OBJECT, because the keys come from a provider's answer. An object literal would
|
|
18
|
+
* answer `EFFORT_TO_LEVEL["constructor"]` with `Object.prototype.constructor` - a function, which
|
|
19
|
+
* is truthy - and `__proto__` with the prototype itself, so a provider that published the word
|
|
20
|
+
* "constructor" would have been believed about a level Pi does not have. A Map has no prototype to
|
|
21
|
+
* inherit from, and `has` asks whether the KEY is one of ours.
|
|
22
|
+
*/
|
|
23
|
+
const EFFORT_TO_LEVEL = new Map([
|
|
24
|
+
["none", "off"],
|
|
25
|
+
["minimal", "minimal"],
|
|
26
|
+
["low", "low"],
|
|
27
|
+
["medium", "medium"],
|
|
28
|
+
["high", "high"],
|
|
29
|
+
["xhigh", "xhigh"],
|
|
30
|
+
["max", "max"],
|
|
31
|
+
]);
|
|
32
|
+
/**
|
|
33
|
+
* MiniMax's OFFICIAL OpenAI-compatible endpoint.
|
|
34
|
+
*
|
|
35
|
+
* The reference is MiniMax's own documentation for the OpenAI-compatible text API
|
|
36
|
+
* (https://platform.minimax.io/docs/api-reference/text-openai-api), which publishes the base URL
|
|
37
|
+
* `https://api.minimax.io/v1` and the `reasoning_effort` values of `MiniMax-M3.1-Flash`.
|
|
38
|
+
*
|
|
39
|
+
* EXACTLY THIS ORIGIN. A proxy that serves a model called `MiniMax-M3.1-Flash` is a different
|
|
40
|
+
* endpoint with a different answer, and it does not get these levels. The path is part of the
|
|
41
|
+
* match too, because the same host serves other paths - `/anthropic` is a different API with
|
|
42
|
+
* different parameters.
|
|
43
|
+
*/
|
|
44
|
+
const MINIMAX_ORIGIN = "https://api.minimax.io";
|
|
45
|
+
/**
|
|
46
|
+
* THE PATHS THAT ARE THE OFFICIAL OPENAI-COMPATIBLE TEXT API.
|
|
47
|
+
*
|
|
48
|
+
* `/v1` is the documented base URL, and `/v1/models` is the URL the model list is actually
|
|
49
|
+
* requested from - the discovery is told which URL ANSWERED, and that is the one that ends in
|
|
50
|
+
* `/models`. The bare origin is the same endpoint with the `/v1` left off.
|
|
51
|
+
*/
|
|
52
|
+
const MINIMAX_PATHS = new Set(["", "/v1", "/v1/models"]);
|
|
53
|
+
/** The model MiniMax's documentation names for these levels. */
|
|
54
|
+
const MINIMAX_FLASH_MODEL = "minimax-m3.1-flash";
|
|
55
|
+
/**
|
|
56
|
+
* MiniMax-M3.1-Flash's levels, as its documentation states them: `low`, `medium`, `high`, `xhigh`,
|
|
57
|
+
* `max`, and nothing else. `off` is `null` because the same documentation says `none` is NOT
|
|
58
|
+
* supported and returns 400 - there is no way to switch this model's thinking off.
|
|
59
|
+
*
|
|
60
|
+
* `minimal` is `null` because MiniMax does not publish it. And MiniMax-M3 - the general model -
|
|
61
|
+
* is NOT here: its documentation does not give it these levels, so copying them onto it would be
|
|
62
|
+
* exactly the "copy a same-named model's levels" mistake this file exists to prevent.
|
|
63
|
+
*/
|
|
64
|
+
const MINIMAX_FLASH_LEVELS = {
|
|
65
|
+
off: null,
|
|
66
|
+
minimal: null,
|
|
67
|
+
low: "low",
|
|
68
|
+
medium: "medium",
|
|
69
|
+
high: "high",
|
|
70
|
+
xhigh: "xhigh",
|
|
71
|
+
max: "max",
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* The official endpoint, or undefined.
|
|
75
|
+
*
|
|
76
|
+
* THE URL THAT ANSWERED, NOT THE ONE THAT WAS ASKED FOR. A fetch follows redirects, so the URL
|
|
77
|
+
* that answered can be a different endpoint from the one in the form - and it is the one that
|
|
78
|
+
* published whatever is being read.
|
|
79
|
+
*/
|
|
80
|
+
function officialMinimaxEndpoint(baseUrl) {
|
|
81
|
+
try {
|
|
82
|
+
const parsed = new URL(baseUrl.trim());
|
|
83
|
+
if (parsed.origin !== MINIMAX_ORIGIN)
|
|
84
|
+
return false;
|
|
85
|
+
const path = parsed.pathname.replace(/\/+$/, "");
|
|
86
|
+
return MINIMAX_PATHS.has(path);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The levels a provider DECLARED for a model, when it declared them properly.
|
|
94
|
+
*
|
|
95
|
+
* THE DECLARATION IS A LIST OF LEVEL NAMES - `supported_reasoning_efforts: ["low","medium","high"]`
|
|
96
|
+
* on the model's own entry in the model list. That is the endpoint naming the values its model
|
|
97
|
+
* accepts, in the parameter's own vocabulary.
|
|
98
|
+
*/
|
|
99
|
+
function declaredLevels(entry) {
|
|
100
|
+
const raw = entry.supported_reasoning_efforts;
|
|
101
|
+
if (!Array.isArray(raw))
|
|
102
|
+
return undefined;
|
|
103
|
+
const names = raw
|
|
104
|
+
.filter((value) => typeof value === "string")
|
|
105
|
+
.map((value) => value.trim())
|
|
106
|
+
.filter((value) => value.length > 0);
|
|
107
|
+
// AN EMPTY LIST IS NOT A DECLARATION. It is a field nobody filled in, and reading it as "this
|
|
108
|
+
// model has no levels" would switch off thinking for a model that has it.
|
|
109
|
+
if (!names.length)
|
|
110
|
+
return undefined;
|
|
111
|
+
const found = {};
|
|
112
|
+
for (const name of names) {
|
|
113
|
+
// ONLY THE EXACT NAMES Pi KNOWS. A name that is not one of them is DROPPED, not translated:
|
|
114
|
+
// guessing what a provider means by `ultra` is how a picker ends up offering a level the
|
|
115
|
+
// model does not have.
|
|
116
|
+
const level = EFFORT_TO_LEVEL.get(name);
|
|
117
|
+
if (!level)
|
|
118
|
+
continue;
|
|
119
|
+
found[level] = name;
|
|
120
|
+
}
|
|
121
|
+
if (!Object.keys(found).length)
|
|
122
|
+
return undefined;
|
|
123
|
+
// ALL SEVEN, every one of them. The levels nobody declared are `null`, because Pi enables the
|
|
124
|
+
// ordinary ones when the map is silent about them.
|
|
125
|
+
const map = {};
|
|
126
|
+
for (const level of PI_THINKING_LEVELS)
|
|
127
|
+
map[level] = found[level] ?? null;
|
|
128
|
+
return map;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* THE LEVELS A MODEL OFFERS, or `undefined` when nobody said.
|
|
132
|
+
*
|
|
133
|
+
* `undefined` is not "no levels" - it is "nobody said", and the caller keeps whatever behaviour it
|
|
134
|
+
* had. A model that nobody described keeps Pi's own defaults, exactly as before.
|
|
135
|
+
*/
|
|
136
|
+
export function discoverThinkingLevels(entry, context) {
|
|
137
|
+
// ONLY THE COMPATIBLE API. A level belongs to the API that published it: the same word means
|
|
138
|
+
// different things over different APIs, so an answer about one is never read as an answer about
|
|
139
|
+
// another. The API the form leaves empty is the default one, which is this one.
|
|
140
|
+
const api = (context.api ?? "").trim() || DEFAULT_API;
|
|
141
|
+
if (api !== DEFAULT_API)
|
|
142
|
+
return undefined;
|
|
143
|
+
// A PAYLOAD THAT SAYS THE MODEL DOES NOT THINK, AND ALSO PUBLISHES LEVELS, CONTRADICTS ITSELF.
|
|
144
|
+
// The explicit answer wins: the levels are dropped, because a map on a model that does not
|
|
145
|
+
// reason would offer levels Pi never shows (it offers `off` and nothing else).
|
|
146
|
+
if (entry.reasoning === false)
|
|
147
|
+
return undefined;
|
|
148
|
+
const declared = declaredLevels(entry);
|
|
149
|
+
if (declared)
|
|
150
|
+
return declared;
|
|
151
|
+
// THE OFFICIAL MINIMAX ENDPOINT, AND ONLY THAT ONE - the origin and the path both, because a map
|
|
152
|
+
// is only true of the endpoint it was learned from.
|
|
153
|
+
if (!officialMinimaxEndpoint(context.baseUrl))
|
|
154
|
+
return undefined;
|
|
155
|
+
const id = typeof entry.id === "string" ? entry.id.trim().toLowerCase() : "";
|
|
156
|
+
if (id !== MINIMAX_FLASH_MODEL)
|
|
157
|
+
return undefined;
|
|
158
|
+
return { ...MINIMAX_FLASH_LEVELS };
|
|
159
|
+
}
|
package/dist/server/types.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export type ModelFilterRule = {
|
|
|
6
6
|
};
|
|
7
7
|
import type { WorkflowRun } from "./workflow.js";
|
|
8
8
|
import type { ScheduledTask } from "./scheduled-tasks.js";
|
|
9
|
+
import type { ThinkingLevelMap } from "../shared/thinking-levels.js";
|
|
9
10
|
/**
|
|
10
11
|
* The lifecycle states a `Conversation.status` moves through while a turn is in flight. `waiting` is the
|
|
11
12
|
* gap between "prompt handed to the LLM" and "the first response token arrived" - holding it apart from
|
|
@@ -409,6 +410,14 @@ export type PublicProviderModel = {
|
|
|
409
410
|
imageInput: boolean;
|
|
410
411
|
contextWindow: number;
|
|
411
412
|
maxTokens: number;
|
|
413
|
+
/**
|
|
414
|
+
* The thinking levels this model really offers, and what each one is sent as.
|
|
415
|
+
*
|
|
416
|
+
* ABSENT means "nobody said" - the map was never written, so Pi's own defaults apply. It is not
|
|
417
|
+
* the same as an empty map, because Pi reads a level the map does not mention as "the model has
|
|
418
|
+
* it".
|
|
419
|
+
*/
|
|
420
|
+
thinkingLevelMap?: ThinkingLevelMap;
|
|
412
421
|
};
|
|
413
422
|
export type PublicProvider = {
|
|
414
423
|
id: string;
|
|
@@ -448,6 +457,14 @@ export type DiscoveredModel = {
|
|
|
448
457
|
imageInput: boolean;
|
|
449
458
|
contextWindow: number;
|
|
450
459
|
maxTokens: number;
|
|
460
|
+
/**
|
|
461
|
+
* The thinking levels the provider PUBLISHED for this model, and what each one is sent as.
|
|
462
|
+
*
|
|
463
|
+
* ABSENT when nobody published them, and that is the common case: a provider that lists a model
|
|
464
|
+
* without saying which effort levels it accepts has said nothing, and this must not pretend
|
|
465
|
+
* otherwise. The map names all seven levels, with `null` for the ones the model does not have.
|
|
466
|
+
*/
|
|
467
|
+
thinkingLevelMap?: ThinkingLevelMap;
|
|
451
468
|
};
|
|
452
469
|
export type ModelCatalog = {
|
|
453
470
|
source: "pi" | "unavailable";
|
|
@@ -1417,6 +1434,14 @@ export type ClientCommandBody =
|
|
|
1417
1434
|
maxTokens?: number;
|
|
1418
1435
|
supportsDeveloperRole?: boolean;
|
|
1419
1436
|
supportsReasoningEffort?: boolean;
|
|
1437
|
+
/**
|
|
1438
|
+
* The thinking levels to write for this model.
|
|
1439
|
+
*
|
|
1440
|
+
* THE SAME THREE STATES THE FORM MEANS BY THEM: absent means "the form knows nothing", so
|
|
1441
|
+
* the saved levels stay; `null` means "this model has no levels", so the saved ones go; a
|
|
1442
|
+
* map means "these are the levels", and every one of Pi's seven is named.
|
|
1443
|
+
*/
|
|
1444
|
+
thinkingLevelMap?: ThinkingLevelMap | null;
|
|
1420
1445
|
}[];
|
|
1421
1446
|
};
|
|
1422
1447
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE THINKING LEVELS A MODEL OFFERS, in Pi's own vocabulary.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS IS A SHARED FILE. The seven levels are Pi's, not Super Pi's. Pi decides which levels a
|
|
5
|
+
* model offers by reading the model object (`getSupportedThinkingLevels`), and the thing that
|
|
6
|
+
* decides it is `thinkingLevelMap` in Pi's `models.json`. So the server writes those names and the
|
|
7
|
+
* browser shows them, and a second list of names anywhere else is a second chance to be wrong.
|
|
8
|
+
*
|
|
9
|
+
* WHAT A MAP SAYS. Each key is one of Pi's levels; each value is the string that level is SENT as.
|
|
10
|
+
* `null` means "this model does not have this level at all".
|
|
11
|
+
*
|
|
12
|
+
* WHY THE NULLS ARE THE POINT. Pi ENABLES the ordinary levels - minimal, low, medium, high - when
|
|
13
|
+
* the map says nothing about them, and it offers `xhigh`/`max` only when the map names them. So a
|
|
14
|
+
* map that only says `{"low": "low", "high": "high"}` would still offer medium, and a map that says
|
|
15
|
+
* nothing at all offers everything. A map that means "this model has exactly these levels" has to
|
|
16
|
+
* name all seven, with `null` for the ones that are not there.
|
|
17
|
+
*/
|
|
18
|
+
/** Pi's seven thinking levels, in Pi's own order. */
|
|
19
|
+
export declare const PI_THINKING_LEVELS: readonly ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
20
|
+
/** One of Pi's seven thinking levels. */
|
|
21
|
+
export type ThinkingLevel = (typeof PI_THINKING_LEVELS)[number];
|
|
22
|
+
/**
|
|
23
|
+
* What each level is sent as, per model. `null` marks a level the model does NOT have.
|
|
24
|
+
*
|
|
25
|
+
* A level that is simply ABSENT means "nobody said" - which is not the same thing, because Pi reads
|
|
26
|
+
* an absent level as "the model has it".
|
|
27
|
+
*/
|
|
28
|
+
export type ThinkingLevelMap = Partial<Record<ThinkingLevel, string | null>>;
|
|
29
|
+
/** The same endpoint can be written with or without a trailing slash. */
|
|
30
|
+
export declare function thinkingLevelsEndpoint(baseUrl: string, api: string): string;
|
|
31
|
+
/** TRUE when the name is one of Pi's seven levels. */
|
|
32
|
+
export declare function isThinkingLevel(name: string): name is ThinkingLevel;
|
|
33
|
+
/**
|
|
34
|
+
* Reads a raw object into a map Pi would accept.
|
|
35
|
+
*
|
|
36
|
+
* LENIENT ON PURPOSE, because this is what reads files other people wrote: an entry that is not a
|
|
37
|
+
* level Pi knows, or a value that is neither a string nor `null`, is DROPPED rather than guessed
|
|
38
|
+
* at. The strict version of this check lives in the validator, which is where a form is checked.
|
|
39
|
+
*
|
|
40
|
+
* Returns `undefined` when there is nothing usable in it - "no map" and "an empty map" are
|
|
41
|
+
* different, and only the second one is a statement.
|
|
42
|
+
*/
|
|
43
|
+
export declare function readThinkingLevelMap(raw: unknown): ThinkingLevelMap | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* The levels a map actually offers - the ones that are not `null` - in Pi's order.
|
|
46
|
+
*
|
|
47
|
+
* This is what the panel shows and what the picker offers, so it reads the map the way Pi reads
|
|
48
|
+
* it: a level the map does not mention is NOT offered, because a map that means "exactly these"
|
|
49
|
+
* names all seven.
|
|
50
|
+
*/
|
|
51
|
+
export declare function offeredThinkingLevels(map: ThinkingLevelMap | null | undefined): ThinkingLevel[];
|
|
52
|
+
/** The levels a map offers, in the words a reader uses: 「low / medium / high」. */
|
|
53
|
+
export declare function describeThinkingLevels(map: ThinkingLevelMap | null | undefined): string;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE THINKING LEVELS A MODEL OFFERS, in Pi's own vocabulary.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS IS A SHARED FILE. The seven levels are Pi's, not Super Pi's. Pi decides which levels a
|
|
5
|
+
* model offers by reading the model object (`getSupportedThinkingLevels`), and the thing that
|
|
6
|
+
* decides it is `thinkingLevelMap` in Pi's `models.json`. So the server writes those names and the
|
|
7
|
+
* browser shows them, and a second list of names anywhere else is a second chance to be wrong.
|
|
8
|
+
*
|
|
9
|
+
* WHAT A MAP SAYS. Each key is one of Pi's levels; each value is the string that level is SENT as.
|
|
10
|
+
* `null` means "this model does not have this level at all".
|
|
11
|
+
*
|
|
12
|
+
* WHY THE NULLS ARE THE POINT. Pi ENABLES the ordinary levels - minimal, low, medium, high - when
|
|
13
|
+
* the map says nothing about them, and it offers `xhigh`/`max` only when the map names them. So a
|
|
14
|
+
* map that only says `{"low": "low", "high": "high"}` would still offer medium, and a map that says
|
|
15
|
+
* nothing at all offers everything. A map that means "this model has exactly these levels" has to
|
|
16
|
+
* name all seven, with `null` for the ones that are not there.
|
|
17
|
+
*/
|
|
18
|
+
/** Pi's seven thinking levels, in Pi's own order. */
|
|
19
|
+
export const PI_THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
20
|
+
/** The same endpoint can be written with or without a trailing slash. */
|
|
21
|
+
export function thinkingLevelsEndpoint(baseUrl, api) {
|
|
22
|
+
const trimmed = baseUrl.trim();
|
|
23
|
+
let address = trimmed.replace(/\/+$/, "");
|
|
24
|
+
try {
|
|
25
|
+
const url = new URL(trimmed);
|
|
26
|
+
address = `${url.origin}${url.pathname.replace(/\/+$/, "")}${url.search}`;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// The form may call this while the URL is being entered.
|
|
30
|
+
}
|
|
31
|
+
return `${address}|${api.trim() || "openai-completions"}`;
|
|
32
|
+
}
|
|
33
|
+
/** TRUE when the name is one of Pi's seven levels. */
|
|
34
|
+
export function isThinkingLevel(name) {
|
|
35
|
+
return PI_THINKING_LEVELS.includes(name);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Reads a raw object into a map Pi would accept.
|
|
39
|
+
*
|
|
40
|
+
* LENIENT ON PURPOSE, because this is what reads files other people wrote: an entry that is not a
|
|
41
|
+
* level Pi knows, or a value that is neither a string nor `null`, is DROPPED rather than guessed
|
|
42
|
+
* at. The strict version of this check lives in the validator, which is where a form is checked.
|
|
43
|
+
*
|
|
44
|
+
* Returns `undefined` when there is nothing usable in it - "no map" and "an empty map" are
|
|
45
|
+
* different, and only the second one is a statement.
|
|
46
|
+
*/
|
|
47
|
+
export function readThinkingLevelMap(raw) {
|
|
48
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
49
|
+
return undefined;
|
|
50
|
+
const map = {};
|
|
51
|
+
let found = false;
|
|
52
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
53
|
+
if (!isThinkingLevel(key))
|
|
54
|
+
continue;
|
|
55
|
+
if (value === null) {
|
|
56
|
+
map[key] = null;
|
|
57
|
+
found = true;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (typeof value !== "string" || !value.trim())
|
|
61
|
+
continue;
|
|
62
|
+
map[key] = value;
|
|
63
|
+
found = true;
|
|
64
|
+
}
|
|
65
|
+
return found ? map : undefined;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The levels a map actually offers - the ones that are not `null` - in Pi's order.
|
|
69
|
+
*
|
|
70
|
+
* This is what the panel shows and what the picker offers, so it reads the map the way Pi reads
|
|
71
|
+
* it: a level the map does not mention is NOT offered, because a map that means "exactly these"
|
|
72
|
+
* names all seven.
|
|
73
|
+
*/
|
|
74
|
+
export function offeredThinkingLevels(map) {
|
|
75
|
+
if (!map)
|
|
76
|
+
return [];
|
|
77
|
+
return PI_THINKING_LEVELS.filter((level) => {
|
|
78
|
+
const mapped = map[level];
|
|
79
|
+
return mapped !== null && mapped !== undefined;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** The levels a map offers, in the words a reader uses: 「low / medium / high」. */
|
|
83
|
+
export function describeThinkingLevels(map) {
|
|
84
|
+
return offeredThinkingLevels(map).join(" / ");
|
|
85
|
+
}
|