pi-pocket 0.28.2 → 0.29.0-beta.2
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/architecture.md +4 -3
- package/docs/customizing.md +1 -1
- package/docs/extensions/linked-sessions.md +2 -0
- package/docs/extensions/policies/api-stability.md +1 -1
- package/docs/extensions/reference/api-versions.md +3 -0
- package/docs/extensions/reference/host.md +18 -4
- package/docs/extensions/reference/pocket.md +12 -1
- package/docs/extensions/reference/types.md +19 -1
- package/docs/extensions/tools.md +18 -0
- package/docs/features.md +5 -5
- package/docs/map.md +6 -4
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/src/server/app.ts +2 -7
- package/src/server/browser/cdp.ts +6 -0
- package/src/server/browser/identity.ts +55 -0
- package/src/server/browser/page.ts +12 -1
- package/src/server/browser.ts +1 -0
- package/src/server/commands.ts +26 -5
- package/src/server/config.ts +10 -0
- package/src/server/custom-providers.ts +304 -23
- package/src/server/docs.ts +10 -3
- package/src/server/extensions/agent-teams.ts +9 -1
- package/src/server/extensions/subagents.ts +51 -3
- package/src/server/host.ts +13 -4
- package/src/server/http/assets.ts +26 -3
- package/src/server/http/io.ts +11 -1
- package/src/server/http/link-routes.ts +4 -1
- package/src/server/http.ts +29 -3
- package/src/server/linked-sessions.ts +92 -9
- package/src/server/project-model.ts +17 -1
- package/types/pocket.d.ts +40 -6
- package/web/app.js +3 -2
- package/web/back.js +27 -6
- package/web/browser-panel.js +23 -12
- package/web/browser-paste.js +13 -0
- package/web/composer.js +7 -3
- package/web/extension-ui.js +17 -2
- package/web/index.html +2 -0
- package/web/pip.js +65 -0
- package/web/running-board.js +38 -36
- package/web/sheets/custom-providers.js +420 -21
- package/web/sheets/memory.js +76 -40
- package/web/store.js +117 -22
- package/web/style.css +176 -13
- package/web/transcript.js +57 -11
|
@@ -1,10 +1,289 @@
|
|
|
1
1
|
// OpenAI-compatible endpoints in the Providers sheet: the "OpenAI Compatible" row adds one with a
|
|
2
2
|
// URL and a key, its models picked from what the endpoint lists (GET /models) or typed by hand;
|
|
3
|
-
// each endpoint's own row edits or removes it.
|
|
4
|
-
//
|
|
3
|
+
// each endpoint's own row edits or removes it. Each chosen model says whether it sees images, the
|
|
4
|
+
// thinking levels it has, its context window and maximum output, and its price. The server keeps
|
|
5
|
+
// each in Pi's models.json, and its key in Pi's sign-ins.
|
|
5
6
|
import { useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";
|
|
6
7
|
import { api, attempt, notify, store } from "../store.js";
|
|
7
|
-
import { html, Icon, MODEL_SEARCH_AT } from "../ui.js";
|
|
8
|
+
import { formatTokens, html, Icon, MODEL_SEARCH_AT } from "../ui.js";
|
|
9
|
+
|
|
10
|
+
/** Pi's thinking levels, in order, with their names in the app. */
|
|
11
|
+
const LEVELS = [
|
|
12
|
+
["off", "Off"],
|
|
13
|
+
["minimal", "Minimal"],
|
|
14
|
+
["low", "Low"],
|
|
15
|
+
["medium", "Medium"],
|
|
16
|
+
["high", "High"],
|
|
17
|
+
["xhigh", "Extra high"],
|
|
18
|
+
["max", "Max"],
|
|
19
|
+
];
|
|
20
|
+
const LEVEL_NAMES = new Map(LEVELS);
|
|
21
|
+
/** The levels Pi offers a reasoning model with no map: off to high, each sending its own name; off sends nothing. */
|
|
22
|
+
const DEFAULT_TIERS = ["off", "minimal", "low", "medium", "high"].map((level) => ({
|
|
23
|
+
level,
|
|
24
|
+
value: level === "off" ? "" : level,
|
|
25
|
+
}));
|
|
26
|
+
const order = (tiers) => LEVELS.flatMap(([level]) => tiers.filter((tier) => tier.level === level));
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The level Add level adds: the next one above the model's highest, so it goes below the last row; when the highest is
|
|
30
|
+
* Max, the nearest free one under it. Undefined when every level is used.
|
|
31
|
+
*/
|
|
32
|
+
function nextLevel(thinking) {
|
|
33
|
+
const used = new Set(thinking.map((tier) => tier.level));
|
|
34
|
+
const last = LEVELS.findIndex(([level]) => level === thinking.at(-1)?.level);
|
|
35
|
+
const free = ([level]) => !used.has(level);
|
|
36
|
+
|
|
37
|
+
return (LEVELS.slice(last + 1).find(free) ?? LEVELS.slice(0, last).findLast(free))?.[0];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** What a model's Thinking button says: off, or its levels from first to last. */
|
|
41
|
+
function tierSummary(thinking) {
|
|
42
|
+
if (!Array.isArray(thinking) || thinking.length === 0) {
|
|
43
|
+
return "No thinking";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const first = LEVEL_NAMES.get(thinking[0]?.level);
|
|
47
|
+
const last = LEVEL_NAMES.get(thinking.at(-1)?.level);
|
|
48
|
+
|
|
49
|
+
return thinking.length === 1 ? `Thinking: ${first}` : `Thinking: ${first} to ${last}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A model's thinking levels: each is one of Pi's levels and the value sent to the endpoint for it (its
|
|
54
|
+
* `reasoning_effort`), which a model may name its own way. Levels can be added, removed, and changed.
|
|
55
|
+
*/
|
|
56
|
+
function ThinkingLevels({ id, thinking, onChange }) {
|
|
57
|
+
const used = new Set((thinking ?? []).map((tier) => tier.level));
|
|
58
|
+
const next = nextLevel(thinking ?? []);
|
|
59
|
+
const set = (index, patch) =>
|
|
60
|
+
onChange(order(thinking.map((tier, at) => (at === index ? { ...tier, ...patch } : tier))));
|
|
61
|
+
|
|
62
|
+
return html`<div class="model-thinking" role="group" aria-label=${`Thinking levels of ${id}`}>
|
|
63
|
+
<label class="check model-thinking-on">
|
|
64
|
+
<input
|
|
65
|
+
type="checkbox"
|
|
66
|
+
checked=${thinking !== null}
|
|
67
|
+
onChange=${(event) => onChange(event.currentTarget.checked ? DEFAULT_TIERS : null)}
|
|
68
|
+
/>
|
|
69
|
+
It thinks (reasoning)
|
|
70
|
+
</label>
|
|
71
|
+
${
|
|
72
|
+
thinking !== null &&
|
|
73
|
+
html`<p class="muted small">
|
|
74
|
+
Each level in the model menu, and the value it sends the endpoint as its
|
|
75
|
+
reasoning effort.
|
|
76
|
+
</p>
|
|
77
|
+
<div class="model-tiers">
|
|
78
|
+
${thinking.map(
|
|
79
|
+
(tier, index) => html`<div class="model-tier" key=${tier.level}>
|
|
80
|
+
<select
|
|
81
|
+
aria-label="Level"
|
|
82
|
+
value=${tier.level}
|
|
83
|
+
onChange=${(event) =>
|
|
84
|
+
set(index, { level: event.currentTarget.value })}
|
|
85
|
+
>
|
|
86
|
+
${LEVELS.filter(
|
|
87
|
+
([level]) => level === tier.level || !used.has(level),
|
|
88
|
+
).map(
|
|
89
|
+
([level, name]) =>
|
|
90
|
+
html`<option value=${level}>${name}</option>`,
|
|
91
|
+
)}
|
|
92
|
+
</select>
|
|
93
|
+
<input
|
|
94
|
+
class="mono"
|
|
95
|
+
aria-label=${`Value sent for ${LEVEL_NAMES.get(tier.level)}`}
|
|
96
|
+
value=${tier.value}
|
|
97
|
+
maxlength="64"
|
|
98
|
+
autocomplete="off"
|
|
99
|
+
placeholder=${tier.level === "off" ? "Nothing" : tier.level}
|
|
100
|
+
onInput=${(event) => set(index, { value: event.currentTarget.value })}
|
|
101
|
+
/>
|
|
102
|
+
<button
|
|
103
|
+
class="icon-button"
|
|
104
|
+
aria-label=${`Remove ${LEVEL_NAMES.get(tier.level)}`}
|
|
105
|
+
disabled=${thinking.length === 1}
|
|
106
|
+
onClick=${() => onChange(thinking.filter((_, at) => at !== index))}
|
|
107
|
+
>
|
|
108
|
+
<${Icon} name="close" size=${14} />
|
|
109
|
+
</button>
|
|
110
|
+
</div>`,
|
|
111
|
+
)}
|
|
112
|
+
</div>
|
|
113
|
+
<div class="row model-tier-buttons">
|
|
114
|
+
<button
|
|
115
|
+
class="button small"
|
|
116
|
+
disabled=${next === undefined}
|
|
117
|
+
onClick=${() =>
|
|
118
|
+
onChange(
|
|
119
|
+
order([
|
|
120
|
+
...thinking,
|
|
121
|
+
{ level: next, value: next === "off" ? "" : next },
|
|
122
|
+
]),
|
|
123
|
+
)}
|
|
124
|
+
>
|
|
125
|
+
<${Icon} name="plus" size=${14} />
|
|
126
|
+
Add level
|
|
127
|
+
</button>
|
|
128
|
+
<button class="button small ghost" onClick=${() => onChange(DEFAULT_TIERS)}>
|
|
129
|
+
Defaults
|
|
130
|
+
</button>
|
|
131
|
+
</div>`
|
|
132
|
+
}
|
|
133
|
+
</div>`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** A model's tiers are ready to save: each level but off sends something. */
|
|
137
|
+
const tiersReady = (thinking) =>
|
|
138
|
+
thinking === null || thinking.every((tier) => tier.level === "off" || tier.value.trim() !== "");
|
|
139
|
+
|
|
140
|
+
/** The parts of a model's price, in dollars per million tokens, with their names in the form. */
|
|
141
|
+
const PRICES = [
|
|
142
|
+
["input", "Input"],
|
|
143
|
+
["output", "Output"],
|
|
144
|
+
["cacheRead", "Cache read"],
|
|
145
|
+
["cacheWrite", "Cache write"],
|
|
146
|
+
];
|
|
147
|
+
/** The most tokens and dollars the server takes. */
|
|
148
|
+
const MAX_TOKENS = 1_000_000_000;
|
|
149
|
+
const MAX_PRICE = 1_000_000;
|
|
150
|
+
|
|
151
|
+
/** A number as its field shows it, every digit and no exponent (0.0000003, not 3e-7): empty when there is none. */
|
|
152
|
+
const shown = (value) =>
|
|
153
|
+
typeof value === "number"
|
|
154
|
+
? value.toLocaleString("en-US", { useGrouping: false, maximumFractionDigits: 20 })
|
|
155
|
+
: "";
|
|
156
|
+
|
|
157
|
+
/** What a model's fields start with: its context window, maximum output, and price, as text. */
|
|
158
|
+
const limitsText = (model) => ({
|
|
159
|
+
contextWindow: shown(model?.contextWindow),
|
|
160
|
+
maxTokens: shown(model?.maxTokens),
|
|
161
|
+
cost: Object.fromEntries(PRICES.map(([part]) => [part, shown(model?.cost?.[part])])),
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
/** A count of tokens from its field: null when empty (Pi's default), NaN when it is not one. */
|
|
165
|
+
function tokensFrom(text) {
|
|
166
|
+
const trimmed = text.trim();
|
|
167
|
+
|
|
168
|
+
if (trimmed === "") {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const value = /^\d+$/.test(trimmed) ? Number(trimmed) : Number.NaN;
|
|
173
|
+
|
|
174
|
+
return value >= 1 && value <= MAX_TOKENS ? value : Number.NaN;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Dollars from a price field: a plain number (3, 0.15, .5), NaN when it is not one. */
|
|
178
|
+
const amountFrom = (text) =>
|
|
179
|
+
/^(\d+(\.\d*)?|\.\d+)$/.test(text.trim()) ? Number(text.trim()) : Number.NaN;
|
|
180
|
+
|
|
181
|
+
/** A price from its fields: null when all are empty (the model costs nothing); a cache part left empty is 0. */
|
|
182
|
+
const priceFrom = (cost) =>
|
|
183
|
+
PRICES.every(([part]) => cost[part].trim() === "")
|
|
184
|
+
? null
|
|
185
|
+
: Object.fromEntries(
|
|
186
|
+
PRICES.map(([part]) => [part, cost[part].trim() === "" ? 0 : amountFrom(cost[part])]),
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
/** What is wrong with a model's context window, maximum output, or price; empty when nothing is. */
|
|
190
|
+
function limitsProblem({ contextWindow, maxTokens, cost }) {
|
|
191
|
+
if (Number.isNaN(tokensFrom(contextWindow))) {
|
|
192
|
+
return "The context window is a whole number of tokens.";
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (Number.isNaN(tokensFrom(maxTokens))) {
|
|
196
|
+
return "The maximum output is a whole number of tokens.";
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const price = priceFrom(cost);
|
|
200
|
+
|
|
201
|
+
if (price === null) {
|
|
202
|
+
return "";
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (cost.input.trim() === "" || cost.output.trim() === "") {
|
|
206
|
+
return "A price needs its input and output dollars.";
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return Object.values(price).every((each) => each >= 0 && each <= MAX_PRICE)
|
|
210
|
+
? ""
|
|
211
|
+
: "A price is a plain number of dollars per million tokens, like 0.15.";
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** A price as its button shows it: 3, 0.15, 0.075, 0.0003. */
|
|
215
|
+
const dollars = (value) => shown(Number(value < 0.1 ? value.toPrecision(2) : value.toFixed(2)));
|
|
216
|
+
|
|
217
|
+
/** Whether any of a model's context, output, or price fields has something in it. */
|
|
218
|
+
const limitsSet = ({ contextWindow, maxTokens, cost }) =>
|
|
219
|
+
[contextWindow, maxTokens, ...Object.values(cost)].some((each) => each.trim() !== "");
|
|
220
|
+
|
|
221
|
+
/** What a model's Context and price button says: what is set, or that nothing is. */
|
|
222
|
+
function limitsSummary(limits) {
|
|
223
|
+
const window = tokensFrom(limits.contextWindow);
|
|
224
|
+
const price = limitsProblem(limits) === "" ? priceFrom(limits.cost) : null;
|
|
225
|
+
const parts = [
|
|
226
|
+
...(window > 0 ? [`${formatTokens(window)} context`] : []),
|
|
227
|
+
...(price === null ? [] : [`$${dollars(price.input)}/$${dollars(price.output)}`]),
|
|
228
|
+
];
|
|
229
|
+
|
|
230
|
+
return parts.length === 0 ? "Context & price" : parts.join(" · ");
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* A model's context window and maximum output, in tokens, and its price, in dollars per million tokens. An empty token
|
|
235
|
+
* field is Pi's default; an empty price is no price, so the model costs nothing.
|
|
236
|
+
*/
|
|
237
|
+
function ModelLimits({ id, limits, onChange }) {
|
|
238
|
+
const problem = limitsProblem(limits);
|
|
239
|
+
const tokens = (field, label, fallback) => html`<label class="field">
|
|
240
|
+
<span class="label">${label}</span>
|
|
241
|
+
<input
|
|
242
|
+
inputmode="numeric"
|
|
243
|
+
autocomplete="off"
|
|
244
|
+
spellcheck="false"
|
|
245
|
+
value=${limits[field]}
|
|
246
|
+
placeholder=${fallback}
|
|
247
|
+
onInput=${(event) => onChange({ [field]: event.currentTarget.value })}
|
|
248
|
+
/>
|
|
249
|
+
</label>`;
|
|
250
|
+
|
|
251
|
+
return html`<div class="model-limits" role="group" aria-label=${`Context and price of ${id}`}>
|
|
252
|
+
<div class="model-limits-grid">
|
|
253
|
+
${tokens("contextWindow", "Context window", "128000")}
|
|
254
|
+
${tokens("maxTokens", "Max output", "16384")}
|
|
255
|
+
</div>
|
|
256
|
+
<p class="muted small">
|
|
257
|
+
In tokens. Empty uses Pi's default (128k and 16k). The context meter and compaction go by
|
|
258
|
+
the context window. Each request asks for up to the max output, so keep it at or below
|
|
259
|
+
what the endpoint allows.
|
|
260
|
+
</p>
|
|
261
|
+
<span class="label">Price in dollars per million tokens</span>
|
|
262
|
+
<div class="model-limits-grid">
|
|
263
|
+
${PRICES.map(
|
|
264
|
+
([part, label]) => html`<label class="field" key=${part}>
|
|
265
|
+
<span class="label">${label}</span>
|
|
266
|
+
<input
|
|
267
|
+
inputmode="decimal"
|
|
268
|
+
autocomplete="off"
|
|
269
|
+
spellcheck="false"
|
|
270
|
+
value=${limits.cost[part]}
|
|
271
|
+
placeholder=${part === "input" || part === "output" ? "" : "0"}
|
|
272
|
+
onInput=${(event) =>
|
|
273
|
+
onChange({
|
|
274
|
+
cost: { ...limits.cost, [part]: event.currentTarget.value },
|
|
275
|
+
})}
|
|
276
|
+
/>
|
|
277
|
+
</label>`,
|
|
278
|
+
)}
|
|
279
|
+
</div>
|
|
280
|
+
<p class="muted small">
|
|
281
|
+
Pi counts what each message costs, and spend limits use it. Empty: the model costs
|
|
282
|
+
nothing.
|
|
283
|
+
</p>
|
|
284
|
+
${problem && html`<p class="warn small" role="alert">${problem}</p>`}
|
|
285
|
+
</div>`;
|
|
286
|
+
}
|
|
8
287
|
|
|
9
288
|
/** The form that adds an endpoint (`editing` undefined) or changes one. */
|
|
10
289
|
export function EndpointForm({ editing, onDone, onCancel }) {
|
|
@@ -12,8 +291,32 @@ export function EndpointForm({ editing, onDone, onCancel }) {
|
|
|
12
291
|
const [baseUrl, setBaseUrl] = useState(editing?.baseUrl ?? "");
|
|
13
292
|
const [apiKey, setApiKey] = useState("");
|
|
14
293
|
const [noKey, setNoKey] = useState(editing?.key === "none");
|
|
15
|
-
// The models chosen, in order, and what the endpoint listed (with
|
|
16
|
-
|
|
294
|
+
// The models chosen, in order, and what the endpoint listed (with a vLLM server's context
|
|
295
|
+
// windows).
|
|
296
|
+
// A server from before these fields sends each model as its id alone.
|
|
297
|
+
const known = (editing?.models ?? []).map((model) =>
|
|
298
|
+
typeof model === "string" ? { id: model } : model,
|
|
299
|
+
);
|
|
300
|
+
const [chosen, setChosen] = useState(known.map((model) => model.id));
|
|
301
|
+
// What each model is, by id: it sees images, its thinking levels (null: it does not think), and
|
|
302
|
+
// its context window, maximum output, and price, as their fields' text.
|
|
303
|
+
const [caps, setCaps] = useState(
|
|
304
|
+
() =>
|
|
305
|
+
new Map(
|
|
306
|
+
known.map((model) => [
|
|
307
|
+
model.id,
|
|
308
|
+
// A model with none of these fields: no images, no thinking, Pi's defaults, no
|
|
309
|
+
// price.
|
|
310
|
+
{
|
|
311
|
+
images: model.images === true,
|
|
312
|
+
thinking: Array.isArray(model.thinking) ? model.thinking : null,
|
|
313
|
+
...limitsText(model),
|
|
314
|
+
},
|
|
315
|
+
]),
|
|
316
|
+
),
|
|
317
|
+
);
|
|
318
|
+
// The panel open under a model: its thinking levels, or its context and price.
|
|
319
|
+
const [open, setOpen] = useState(null);
|
|
17
320
|
const [listed, setListed] = useState(null);
|
|
18
321
|
const [typed, setTyped] = useState("");
|
|
19
322
|
const [query, setQuery] = useState("");
|
|
@@ -29,7 +332,19 @@ export function EndpointForm({ editing, onDone, onCancel }) {
|
|
|
29
332
|
?.scrollIntoView({ block: "start", behavior: "smooth" });
|
|
30
333
|
}, []);
|
|
31
334
|
|
|
32
|
-
|
|
335
|
+
// A new model starts with no images, no thinking, no price, and Pi's default output; its
|
|
336
|
+
// context window too, unless a vLLM server listed it. The owner sets the rest.
|
|
337
|
+
const capsOf = (id) =>
|
|
338
|
+
caps.get(id) ?? {
|
|
339
|
+
images: false,
|
|
340
|
+
thinking: null,
|
|
341
|
+
...limitsText((listed ?? []).find((model) => model.id === id)),
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
const toggleOpen = (panel) => setOpen(open === panel ? null : panel);
|
|
345
|
+
|
|
346
|
+
const setCap = (id, patch) =>
|
|
347
|
+
setCaps((was) => new Map(was).set(id, { ...capsOf(id), ...patch }));
|
|
33
348
|
const toggle = (id, on) =>
|
|
34
349
|
setChosen((was) =>
|
|
35
350
|
on ? [...was.filter((each) => each !== id), id] : was.filter((each) => each !== id),
|
|
@@ -75,9 +390,21 @@ export function EndpointForm({ editing, onDone, onCancel }) {
|
|
|
75
390
|
setBusy("save");
|
|
76
391
|
setProblem("");
|
|
77
392
|
|
|
78
|
-
const models = chosen.map((id) =>
|
|
79
|
-
|
|
80
|
-
|
|
393
|
+
const models = chosen.map((id) => {
|
|
394
|
+
const { images, thinking, contextWindow, maxTokens, cost } = capsOf(id);
|
|
395
|
+
|
|
396
|
+
return {
|
|
397
|
+
id,
|
|
398
|
+
images,
|
|
399
|
+
thinking:
|
|
400
|
+
thinking === null
|
|
401
|
+
? null
|
|
402
|
+
: thinking.map((tier) => ({ ...tier, value: tier.value.trim() })),
|
|
403
|
+
contextWindow: tokensFrom(contextWindow),
|
|
404
|
+
maxTokens: tokensFrom(maxTokens),
|
|
405
|
+
cost: priceFrom(cost),
|
|
406
|
+
};
|
|
407
|
+
});
|
|
81
408
|
const body = {
|
|
82
409
|
name,
|
|
83
410
|
baseUrl,
|
|
@@ -107,11 +434,12 @@ export function EndpointForm({ editing, onDone, onCancel }) {
|
|
|
107
434
|
...(listed ?? []).map((model) => model.id),
|
|
108
435
|
...chosen.filter((id) => !(listed ?? []).some((model) => model.id === id)),
|
|
109
436
|
];
|
|
110
|
-
const
|
|
437
|
+
const matching = rows.filter((id) => needle === "" || id.toLowerCase().includes(needle));
|
|
111
438
|
const ready =
|
|
112
439
|
name.trim() !== "" &&
|
|
113
440
|
baseUrl.trim() !== "" &&
|
|
114
441
|
(noKey || apiKey.trim() !== "" || editing !== undefined) &&
|
|
442
|
+
chosen.every((id) => tiersReady(capsOf(id).thinking) && limitsProblem(capsOf(id)) === "") &&
|
|
115
443
|
busy === "";
|
|
116
444
|
const keepsKey = editing && editing.key !== "none" && editing.key !== "missing";
|
|
117
445
|
const findLabel =
|
|
@@ -201,17 +529,88 @@ export function EndpointForm({ editing, onDone, onCancel }) {
|
|
|
201
529
|
role="group"
|
|
202
530
|
aria-label="Models to add"
|
|
203
531
|
>
|
|
204
|
-
${
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
532
|
+
${matching.map((id) => {
|
|
533
|
+
const on = chosen.includes(id);
|
|
534
|
+
const model = capsOf(id);
|
|
535
|
+
const { images, thinking } = model;
|
|
536
|
+
const thinkingPanel = `thinking ${id}`;
|
|
537
|
+
const limitsPanel = `limits ${id}`;
|
|
538
|
+
const limitsBad = limitsProblem(model) !== "";
|
|
539
|
+
|
|
540
|
+
return html`<div
|
|
541
|
+
class=${`custom-endpoint-model ${on ? "chosen" : ""}`}
|
|
542
|
+
key=${id}
|
|
543
|
+
>
|
|
544
|
+
<div class="custom-endpoint-model-row">
|
|
545
|
+
<label class="check custom-endpoint-model-name">
|
|
546
|
+
<input
|
|
547
|
+
type="checkbox"
|
|
548
|
+
checked=${on}
|
|
549
|
+
onChange=${(event) =>
|
|
550
|
+
toggle(id, event.currentTarget.checked)}
|
|
551
|
+
/>
|
|
552
|
+
<span class="mono">${id}</span>
|
|
553
|
+
</label>
|
|
554
|
+
${
|
|
555
|
+
on &&
|
|
556
|
+
html`<div class="custom-endpoint-model-caps">
|
|
557
|
+
<label class="check">
|
|
558
|
+
<input
|
|
559
|
+
type="checkbox"
|
|
560
|
+
checked=${images}
|
|
561
|
+
onChange=${(event) =>
|
|
562
|
+
setCap(id, {
|
|
563
|
+
images: event.currentTarget.checked,
|
|
564
|
+
})}
|
|
565
|
+
/>
|
|
566
|
+
Images
|
|
567
|
+
</label>
|
|
568
|
+
<button
|
|
569
|
+
class=${`button small model-thinking-button ${thinking === null ? "" : "on"}`}
|
|
570
|
+
aria-expanded=${open === thinkingPanel ? "true" : "false"}
|
|
571
|
+
onClick=${() => toggleOpen(thinkingPanel)}
|
|
572
|
+
>
|
|
573
|
+
${tierSummary(thinking)}
|
|
574
|
+
<${Icon}
|
|
575
|
+
name=${open === thinkingPanel ? "up" : "down"}
|
|
576
|
+
size=${14}
|
|
577
|
+
/>
|
|
578
|
+
</button>
|
|
579
|
+
<button
|
|
580
|
+
class=${`button small model-thinking-button ${limitsBad ? "bad" : limitsSet(model) ? "on" : ""}`}
|
|
581
|
+
aria-expanded=${open === limitsPanel ? "true" : "false"}
|
|
582
|
+
onClick=${() => toggleOpen(limitsPanel)}
|
|
583
|
+
>
|
|
584
|
+
${limitsSummary(model)}
|
|
585
|
+
<${Icon}
|
|
586
|
+
name=${open === limitsPanel ? "up" : "down"}
|
|
587
|
+
size=${14}
|
|
588
|
+
/>
|
|
589
|
+
</button>
|
|
590
|
+
</div>`
|
|
591
|
+
}
|
|
592
|
+
</div>
|
|
593
|
+
${
|
|
594
|
+
on &&
|
|
595
|
+
open === thinkingPanel &&
|
|
596
|
+
html`<${ThinkingLevels}
|
|
597
|
+
id=${id}
|
|
598
|
+
thinking=${thinking}
|
|
599
|
+
onChange=${(next) => setCap(id, { thinking: next })}
|
|
600
|
+
/>`
|
|
601
|
+
}
|
|
602
|
+
${
|
|
603
|
+
on &&
|
|
604
|
+
open === limitsPanel &&
|
|
605
|
+
html`<${ModelLimits}
|
|
606
|
+
id=${id}
|
|
607
|
+
limits=${model}
|
|
608
|
+
onChange=${(patch) => setCap(id, patch)}
|
|
609
|
+
/>`
|
|
610
|
+
}
|
|
611
|
+
</div>`;
|
|
612
|
+
})}
|
|
613
|
+
${matching.length === 0 && html`<p class="muted small">No model matches.</p>`}
|
|
215
614
|
</div>`
|
|
216
615
|
}
|
|
217
616
|
<div class="row">
|
package/web/sheets/memory.js
CHANGED
|
@@ -343,7 +343,41 @@ function Group({ title, lessons, data, empty, conversationId, pendingOnly = fals
|
|
|
343
343
|
</div>`;
|
|
344
344
|
}
|
|
345
345
|
|
|
346
|
-
/**
|
|
346
|
+
/**
|
|
347
|
+
* The sheet's scope: which lessons it lists, and where one added by hand goes. Each shows how many it holds, and for the
|
|
348
|
+
* owner how many of them wait for approval, so none hides behind the other.
|
|
349
|
+
*/
|
|
350
|
+
function ScopeSwitch({ scope, setScope, lessons, waiting }) {
|
|
351
|
+
const option = (which, label) => {
|
|
352
|
+
const count = lessons.filter(
|
|
353
|
+
(lesson) => lesson.scope === which && !waiting.includes(lesson),
|
|
354
|
+
).length;
|
|
355
|
+
const pending = waiting.filter((lesson) => lesson.scope === which).length;
|
|
356
|
+
const said = `${label}: ${count} ${count === 1 ? "lesson" : "lessons"}${pending > 0 ? `, ${pending} to approve` : ""}`;
|
|
357
|
+
|
|
358
|
+
return html`<button
|
|
359
|
+
role="radio"
|
|
360
|
+
aria-checked=${scope === which ? "true" : "false"}
|
|
361
|
+
aria-label=${said}
|
|
362
|
+
class=${scope === which ? "on" : ""}
|
|
363
|
+
onClick=${() => setScope(which)}
|
|
364
|
+
>
|
|
365
|
+
<span>${label}</span>
|
|
366
|
+
<span class="memory-scope-count">${count}</span>
|
|
367
|
+
${pending > 0 && html`<span class="tab-count">${pending}</span>`}
|
|
368
|
+
</button>`;
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
return html`<div class="segmented memory-scope" role="radiogroup" aria-label="Lessons for">
|
|
372
|
+
${option("project", "This project")}
|
|
373
|
+
${option("everywhere", "Everywhere")}
|
|
374
|
+
</div>`;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* The lessons Pi keeps: what waits for approval, this project's, and everywhere's; and one added by hand. The scope
|
|
379
|
+
* switch picks which of the two it lists, and where a new one goes.
|
|
380
|
+
*/
|
|
347
381
|
export function MemorySheet({ draft: initial = "", conversationId, pendingOnly = false }) {
|
|
348
382
|
const id = conversationId ?? store.state.conversationId;
|
|
349
383
|
const data = useMemory(id, pendingOnly);
|
|
@@ -354,19 +388,19 @@ export function MemorySheet({ draft: initial = "", conversationId, pendingOnly =
|
|
|
354
388
|
const title = pendingOnly ? "Pending memories" : "Memory";
|
|
355
389
|
|
|
356
390
|
if (pendingOnly && store.state.me?.role !== "owner") {
|
|
357
|
-
return html`<${Sheet} title=${title} onClose=${closeSheet}>
|
|
391
|
+
return html`<${Sheet} title=${title} onClose=${closeSheet} wide=${true}>
|
|
358
392
|
<p class="muted">Only the owner can review pending memories.</p>
|
|
359
393
|
<//>`;
|
|
360
394
|
}
|
|
361
395
|
|
|
362
396
|
if (!data) {
|
|
363
|
-
return html`<${Sheet} title=${title} onClose=${closeSheet}>
|
|
397
|
+
return html`<${Sheet} title=${title} onClose=${closeSheet} wide=${true}>
|
|
364
398
|
<p class="muted">Loading…</p>
|
|
365
399
|
<//>`;
|
|
366
400
|
}
|
|
367
401
|
|
|
368
402
|
if (pendingOnly && data.restartRequired) {
|
|
369
|
-
return html`<${Sheet} title=${title} onClose=${closeSheet}>
|
|
403
|
+
return html`<${Sheet} title=${title} onClose=${closeSheet} wide=${true}>
|
|
370
404
|
<p class="muted">
|
|
371
405
|
Restart the server from Menu → Restart server to review pending memories across projects.
|
|
372
406
|
</p>
|
|
@@ -378,7 +412,10 @@ export function MemorySheet({ draft: initial = "", conversationId, pendingOnly =
|
|
|
378
412
|
const waiting = data.owner
|
|
379
413
|
? data.lessons.filter((lesson) => lesson.pending || lesson.proposal)
|
|
380
414
|
: [];
|
|
381
|
-
const shown = data.lessons.filter(
|
|
415
|
+
const shown = data.lessons.filter(
|
|
416
|
+
(lesson) => lesson.scope === chosen && !waiting.includes(lesson),
|
|
417
|
+
);
|
|
418
|
+
const waitingHere = waiting.filter((lesson) => lesson.scope === chosen);
|
|
382
419
|
|
|
383
420
|
const add = () => {
|
|
384
421
|
if (busy || text.trim() === "") {
|
|
@@ -400,7 +437,12 @@ export function MemorySheet({ draft: initial = "", conversationId, pendingOnly =
|
|
|
400
437
|
};
|
|
401
438
|
|
|
402
439
|
if (pendingOnly) {
|
|
403
|
-
return html`<${Sheet}
|
|
440
|
+
return html`<${Sheet}
|
|
441
|
+
title=${title}
|
|
442
|
+
onClose=${closeSheet}
|
|
443
|
+
wide=${true}
|
|
444
|
+
className="pending-memories"
|
|
445
|
+
>
|
|
404
446
|
<p class="muted small">
|
|
405
447
|
Memories waiting for your approval, across every project and everywhere.
|
|
406
448
|
Approve only what you want Pi to keep; until then Pi goes on as before.
|
|
@@ -416,10 +458,19 @@ export function MemorySheet({ draft: initial = "", conversationId, pendingOnly =
|
|
|
416
458
|
<//>`;
|
|
417
459
|
}
|
|
418
460
|
|
|
419
|
-
return html`<${Sheet} title=${title} onClose=${closeSheet}>
|
|
461
|
+
return html`<${Sheet} title=${title} onClose=${closeSheet} wide=${true}>
|
|
420
462
|
<p class="muted small">
|
|
421
463
|
Short lessons Pi keeps across sessions: how to build and test, gotchas, conventions, preferences. ${project ? html`Those for <b>${project.name}</b> go to every session in it, worktrees too; the rest go everywhere.` : "PiP keeps lessons for everywhere."} Pi proposes one only when asked, or when sure it will help in many later sessions, and the owner approves; yours count at once.
|
|
422
464
|
</p>
|
|
465
|
+
${
|
|
466
|
+
project &&
|
|
467
|
+
html`<${ScopeSwitch}
|
|
468
|
+
scope=${chosen}
|
|
469
|
+
setScope=${setScope}
|
|
470
|
+
lessons=${data.lessons}
|
|
471
|
+
waiting=${waiting}
|
|
472
|
+
/>`
|
|
473
|
+
}
|
|
423
474
|
${
|
|
424
475
|
data.canWrite &&
|
|
425
476
|
html`<div class="lesson-add">
|
|
@@ -437,27 +488,9 @@ export function MemorySheet({ draft: initial = "", conversationId, pendingOnly =
|
|
|
437
488
|
}}
|
|
438
489
|
></textarea>
|
|
439
490
|
<div class="row">
|
|
440
|
-
|
|
441
|
-
project
|
|
442
|
-
|
|
443
|
-
<button
|
|
444
|
-
role="radio"
|
|
445
|
-
aria-checked=${chosen === "project" ? "true" : "false"}
|
|
446
|
-
class=${chosen === "project" ? "on" : ""}
|
|
447
|
-
onClick=${() => setScope("project")}
|
|
448
|
-
>
|
|
449
|
-
This project
|
|
450
|
-
</button>
|
|
451
|
-
<button
|
|
452
|
-
role="radio"
|
|
453
|
-
aria-checked=${chosen === "everywhere" ? "true" : "false"}
|
|
454
|
-
class=${chosen === "everywhere" ? "on" : ""}
|
|
455
|
-
onClick=${() => setScope("everywhere")}
|
|
456
|
-
>
|
|
457
|
-
Everywhere
|
|
458
|
-
</button>
|
|
459
|
-
</div>`
|
|
460
|
-
}
|
|
491
|
+
<span class="muted small lesson-add-for">
|
|
492
|
+
${chosen === "project" ? `For ${project.name}` : "For every session and PiP"}
|
|
493
|
+
</span>
|
|
461
494
|
<button
|
|
462
495
|
class="button primary"
|
|
463
496
|
disabled=${busy || text.trim() === ""}
|
|
@@ -469,31 +502,34 @@ export function MemorySheet({ draft: initial = "", conversationId, pendingOnly =
|
|
|
469
502
|
</div>`
|
|
470
503
|
}
|
|
471
504
|
${
|
|
472
|
-
|
|
505
|
+
waitingHere.length > 0 &&
|
|
473
506
|
html`<${Group}
|
|
474
|
-
title=${`To approve · ${
|
|
475
|
-
lessons=${
|
|
507
|
+
title=${`To approve · ${waitingHere.length}`}
|
|
508
|
+
lessons=${waitingHere}
|
|
476
509
|
data=${data}
|
|
477
510
|
conversationId=${id}
|
|
478
511
|
/>`
|
|
479
512
|
}
|
|
480
513
|
${
|
|
481
|
-
project &&
|
|
514
|
+
chosen === "project" &&
|
|
482
515
|
html`<${Group}
|
|
483
516
|
title=${`This project: ${project.name}`}
|
|
484
|
-
lessons=${shown
|
|
517
|
+
lessons=${shown}
|
|
518
|
+
data=${data}
|
|
519
|
+
conversationId=${id}
|
|
520
|
+
empty="Nothing yet."
|
|
521
|
+
/>`
|
|
522
|
+
}
|
|
523
|
+
${
|
|
524
|
+
chosen === "everywhere" &&
|
|
525
|
+
html`<${Group}
|
|
526
|
+
title="Everywhere"
|
|
527
|
+
lessons=${shown}
|
|
485
528
|
data=${data}
|
|
486
529
|
conversationId=${id}
|
|
487
530
|
empty="Nothing yet."
|
|
488
531
|
/>`
|
|
489
532
|
}
|
|
490
|
-
<${Group}
|
|
491
|
-
title="Everywhere"
|
|
492
|
-
lessons=${shown.filter((lesson) => lesson.scope === "everywhere")}
|
|
493
|
-
data=${data}
|
|
494
|
-
conversationId=${id}
|
|
495
|
-
empty="Nothing yet."
|
|
496
|
-
/>
|
|
497
533
|
<//>`;
|
|
498
534
|
}
|
|
499
535
|
|