@fungi.computer/parakeet 0.17.2 → 0.17.4
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/commands/interactions.d.ts +14 -1
- package/dist/commands/interactions.js +20 -0
- package/dist/components/ChatComposer.js +1 -1
- package/dist/components/ClientRows.js +1 -1
- package/dist/core/awaiting-answer.d.ts +19 -1
- package/dist/core/awaiting-answer.js +74 -1
- package/dist/headless.d.ts +1 -1
- package/dist/headless.js +1 -1
- package/dist/styles.css +32 -4
- package/dist/use-approval-awaiting.js +23 -2
- package/dist/use-decision.js +29 -6
- package/docs/api/headless.md +78 -9
- package/package.json +4 -4
- package/src/composer-shell.css +31 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { WhistleInteractionEnd, WhistleRuntime } from "@fungi.computer/whistle";
|
|
2
2
|
import { type WhistleInteractionHost } from "@fungi.computer/whistle/interaction";
|
|
3
|
-
import type
|
|
3
|
+
import { DecisionDraft, type AwaitingItem } from "../core/awaiting-answer.js";
|
|
4
4
|
/** One interaction a renderer should draw as a dialog or panel. */
|
|
5
5
|
export type ParakeetOpenInteraction = Readonly<{
|
|
6
6
|
/** Changes whenever a different interaction opens. */
|
|
@@ -95,6 +95,19 @@ export type ParakeetInteractions = Readonly<{
|
|
|
95
95
|
/** Bring back the earliest postponed decision, even over a draft. */
|
|
96
96
|
focus: () => void;
|
|
97
97
|
}>;
|
|
98
|
+
/**
|
|
99
|
+
* Unfinished approval choices, in memory for this session only. They outlive
|
|
100
|
+
* the card that drew them, so a card that is hidden and drawn again resumes
|
|
101
|
+
* the person's choice instead of starting on the first row.
|
|
102
|
+
*/
|
|
103
|
+
drafts: Readonly<{
|
|
104
|
+
/** The draft for one record revision, created on first use. */
|
|
105
|
+
claim: (key: string) => DecisionDraft;
|
|
106
|
+
/** Forget one draft: its record was answered or postponed for good. */
|
|
107
|
+
release: (key: string) => void;
|
|
108
|
+
/** Forget every draft whose key starts with the prefix but is not `keep`. */
|
|
109
|
+
supersede: (prefix: string, keep: string) => void;
|
|
110
|
+
}>;
|
|
98
111
|
}>;
|
|
99
112
|
/**
|
|
100
113
|
* Own how commands talk to the human. An interaction opens only when it asks
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createWhistleInteractionHost, } from "@fungi.computer/whistle/interaction";
|
|
2
|
+
import { DecisionDraft } from "../core/awaiting-answer.js";
|
|
2
3
|
/**
|
|
3
4
|
* Own how commands talk to the human. An interaction opens only when it asks
|
|
4
5
|
* a question, hands off to a URL or shows progress; a command that just
|
|
@@ -15,6 +16,7 @@ export function createParakeetInteractions() {
|
|
|
15
16
|
};
|
|
16
17
|
let sequence = 0;
|
|
17
18
|
let lastEnd;
|
|
19
|
+
const drafts = new Map();
|
|
18
20
|
const listeners = new Set();
|
|
19
21
|
const toastListeners = new Set();
|
|
20
22
|
const toast = (next) => {
|
|
@@ -168,6 +170,24 @@ export function createParakeetInteractions() {
|
|
|
168
170
|
toastListeners.delete(listener);
|
|
169
171
|
};
|
|
170
172
|
},
|
|
173
|
+
drafts: {
|
|
174
|
+
claim: (key) => {
|
|
175
|
+
const held = drafts.get(key);
|
|
176
|
+
if (held !== undefined)
|
|
177
|
+
return held;
|
|
178
|
+
const created = new DecisionDraft();
|
|
179
|
+
drafts.set(key, created);
|
|
180
|
+
return created;
|
|
181
|
+
},
|
|
182
|
+
release: (key) => {
|
|
183
|
+
drafts.delete(key);
|
|
184
|
+
},
|
|
185
|
+
supersede: (prefix, keep) => {
|
|
186
|
+
for (const key of drafts.keys())
|
|
187
|
+
if (key !== keep && key.startsWith(prefix))
|
|
188
|
+
drafts.delete(key);
|
|
189
|
+
},
|
|
190
|
+
},
|
|
171
191
|
attach: (present) => present(presenter),
|
|
172
192
|
lastEnd: () => lastEnd,
|
|
173
193
|
awaiting: {
|
|
@@ -285,7 +285,7 @@ function useComposerRow({ showFooter, statusChips, model, status, viewState, wai
|
|
|
285
285
|
: [
|
|
286
286
|
{
|
|
287
287
|
id: "settings",
|
|
288
|
-
label: (_jsxs("span", { className: "composer-settings-chip", children: [_jsx(SlidersHorizontal, { "aria-hidden": "true" }), "Settings"] })),
|
|
288
|
+
label: (_jsxs("span", { className: "composer-settings-chip", children: [_jsx(SlidersHorizontal, { "aria-hidden": "true" }), _jsx("span", { className: "composer-settings-label", children: "Settings" })] })),
|
|
289
289
|
accessibleLabel: "Session settings",
|
|
290
290
|
title: "Settings",
|
|
291
291
|
content: (_jsxs(StatusTrayList, { className: "composer-settings", children: [modelName === undefined ? null : (_jsx(StatusTrayRow, { primary: "Model", secondary: modelName, actions: canPickModel ? (_jsx(Button, { size: "xs", variant: "ghost", onClick: () => {
|
|
@@ -32,7 +32,7 @@ export function ClientRows({ entryId, rows, actions, onOpen, }) {
|
|
|
32
32
|
void actions.execute(entryId, decision);
|
|
33
33
|
}, children: [_jsx("span", { "aria-hidden": "true", "data-client-row-dot": "", className: `w-3 shrink-0 text-center ${row.tone === undefined ? "" : rowColors[row.tone]}`, children: row.tone === undefined ? "" : "●" }), _jsxs("span", { className: `min-w-0 flex-1 truncate text-start ${row.tone === undefined ? "" : rowColors[row.tone]}`, children: [row.title, row.detail === undefined ? null : (_jsxs("span", { className: "text-dim", children: [" \u00B7 ", row.detail] }))] }), _jsx("span", { className: "shrink-0 text-dim", "data-client-row-action": "", children: decision.label })] }) }, row.id));
|
|
34
34
|
}
|
|
35
|
-
return (_jsxs("div", { "data-client-row": row.id, className: "py-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { "aria-hidden": "true", "data-client-row-dot": "", className: `w-3 shrink-0 text-center leading-4 ${row.tone === undefined ? "" : rowColors[row.tone]}`, children: row.tone === undefined ? "" : "●" }), _jsxs("details", { className: "min-w-0 flex-1", children: [_jsxs("summary", { title: row.title, className: `cursor-pointer truncate leading-4 ${row.tone === undefined ? "" : rowColors[row.tone]}`, children: [row.title, row.inspection === undefined || row.detail === undefined
|
|
35
|
+
return (_jsxs("div", { "data-client-row": row.id, className: "py-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { "aria-hidden": "true", "data-client-row-dot": "", className: `w-3 shrink-0 text-center leading-4 ${row.tone === undefined ? "" : rowColors[row.tone]}`, children: row.tone === undefined ? "" : "●" }), _jsxs("details", { className: "min-w-0 flex-1", children: [_jsxs("summary", { title: row.title, className: `cursor-pointer truncate leading-4 ${row.tone === undefined ? "" : `list-none [&::-webkit-details-marker]:hidden ${rowColors[row.tone]}`}`, children: [row.title, row.inspection === undefined || row.detail === undefined
|
|
36
36
|
? null
|
|
37
37
|
: ` · ${row.detail}`] }), row.detail === undefined ? null : (_jsx("p", { className: "max-h-32 overflow-y-auto overscroll-contain whitespace-pre-wrap break-words pb-2", children: row.detail }))] }), row.open === undefined ? null : (_jsx(Button, { size: "xs", variant: "outline", className: "shrink-0", disabled: onOpen === undefined, onClick: () => {
|
|
38
38
|
if (row.open !== undefined)
|
|
@@ -16,6 +16,8 @@ export type AwaitingItem = Readonly<{
|
|
|
16
16
|
arrivedAt: number;
|
|
17
17
|
/** The conversation to draw and answer. */
|
|
18
18
|
host: WhistleInteractionHost;
|
|
19
|
+
/** A draft owned by the pending record, retained while its host reconnects. */
|
|
20
|
+
draft?: DecisionDraft;
|
|
19
21
|
}>;
|
|
20
22
|
/** Which item the composer shows and where it stands among all of them. */
|
|
21
23
|
export type AwaitingQueue = Readonly<{
|
|
@@ -46,7 +48,7 @@ export type DecisionPrompt = WhistlePromptOf<"decision">;
|
|
|
46
48
|
export type DecisionPhase = "choose" | "other" | "confirm" | "sending" | "refused";
|
|
47
49
|
/** Everything the reducer remembers about one decision prompt. */
|
|
48
50
|
export type DecisionState = Readonly<{
|
|
49
|
-
/** Highlighted row
|
|
51
|
+
/** Highlighted row, or -1 when a retained choice is no longer available. */
|
|
50
52
|
highlight: number;
|
|
51
53
|
/** Option values toggled so far (multiple decisions only). */
|
|
52
54
|
toggled: ReadonlySet<string>;
|
|
@@ -122,6 +124,22 @@ export type DecisionOutcome = Readonly<{
|
|
|
122
124
|
}>;
|
|
123
125
|
/** The state a decision starts in. */
|
|
124
126
|
export declare function initialDecisionState(): DecisionState;
|
|
127
|
+
/** The state of an approval: nothing selected, so Send and Enter wait for a pick. */
|
|
128
|
+
export declare function unselectedDecisionState(): DecisionState;
|
|
129
|
+
/** One pending choice, retaining no display metadata or answering authority. */
|
|
130
|
+
export declare class DecisionDraft {
|
|
131
|
+
#private;
|
|
132
|
+
/** Start without a remembered choice. */
|
|
133
|
+
constructor();
|
|
134
|
+
/** Remember option values, which policy rows may move, and unfinished text. */
|
|
135
|
+
remember(state: DecisionState, prompt: DecisionPrompt): void;
|
|
136
|
+
/**
|
|
137
|
+
* Redraw a compatible choice without replaying any submitted answer. With
|
|
138
|
+
* nothing remembered, an approval has nothing selected: the person may have
|
|
139
|
+
* chosen something this draft lost, and Send must not guess for them.
|
|
140
|
+
*/
|
|
141
|
+
restore(prompt: DecisionPrompt): DecisionState;
|
|
142
|
+
}
|
|
125
143
|
/**
|
|
126
144
|
* The one set of rules both renderers follow. Number keys only move the
|
|
127
145
|
* highlight, Enter is the only way to answer, and Esc steps back one level
|
|
@@ -32,6 +32,71 @@ export function initialDecisionState() {
|
|
|
32
32
|
details: false,
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
+
/** The state of an approval: nothing selected, so Send and Enter wait for a pick. */
|
|
36
|
+
export function unselectedDecisionState() {
|
|
37
|
+
return { ...initialDecisionState(), highlight: -1 };
|
|
38
|
+
}
|
|
39
|
+
/** One pending choice, retaining no display metadata or answering authority. */
|
|
40
|
+
export class DecisionDraft {
|
|
41
|
+
#current;
|
|
42
|
+
/** Start without a remembered choice. */
|
|
43
|
+
constructor() {
|
|
44
|
+
this.#current = undefined;
|
|
45
|
+
}
|
|
46
|
+
/** Remember option values, which policy rows may move, and unfinished text. */
|
|
47
|
+
remember(state, prompt) {
|
|
48
|
+
const option = prompt.options[state.highlight];
|
|
49
|
+
if (option === undefined &&
|
|
50
|
+
(state.highlight !== prompt.options.length || prompt.other === undefined))
|
|
51
|
+
return;
|
|
52
|
+
this.#current = {
|
|
53
|
+
multiple: prompt.multiple === true,
|
|
54
|
+
escape: prompt.escape,
|
|
55
|
+
other: prompt.other === undefined ? undefined : { blank: prompt.other.blank },
|
|
56
|
+
choice: option === undefined
|
|
57
|
+
? { kind: "other" }
|
|
58
|
+
: { kind: "option", value: option.value },
|
|
59
|
+
toggled: [...state.toggled],
|
|
60
|
+
text: state.other,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Redraw a compatible choice without replaying any submitted answer. With
|
|
65
|
+
* nothing remembered, an approval has nothing selected: the person may have
|
|
66
|
+
* chosen something this draft lost, and Send must not guess for them.
|
|
67
|
+
*/
|
|
68
|
+
restore(prompt) {
|
|
69
|
+
const initial = unselectedDecisionState();
|
|
70
|
+
const draft = this.#current;
|
|
71
|
+
if (draft === undefined)
|
|
72
|
+
return initial;
|
|
73
|
+
const choice = draft.choice;
|
|
74
|
+
const highlight = choice.kind === "other"
|
|
75
|
+
? prompt.other === undefined
|
|
76
|
+
? -1
|
|
77
|
+
: prompt.options.length
|
|
78
|
+
: prompt.options.findIndex((option) => option.value === choice.value);
|
|
79
|
+
if (draft.multiple !== (prompt.multiple === true) ||
|
|
80
|
+
draft.escape !== prompt.escape ||
|
|
81
|
+
(draft.other === undefined) !== (prompt.other === undefined) ||
|
|
82
|
+
draft.other?.blank !== prompt.other?.blank ||
|
|
83
|
+
highlight < 0 ||
|
|
84
|
+
draft.toggled.some((value) => !prompt.options.some((option) => option.value === value)))
|
|
85
|
+
return {
|
|
86
|
+
...initial,
|
|
87
|
+
highlight: -1,
|
|
88
|
+
phase: "refused",
|
|
89
|
+
refusal: "This choice changed. Choose again before sending.",
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
...initial,
|
|
93
|
+
highlight,
|
|
94
|
+
phase: highlight === prompt.options.length ? "other" : "choose",
|
|
95
|
+
toggled: new Set(draft.toggled),
|
|
96
|
+
other: draft.text,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
35
100
|
const unchanged = (state) => ({ state });
|
|
36
101
|
function onRow(state, prompt, highlight) {
|
|
37
102
|
return {
|
|
@@ -61,7 +126,11 @@ export function reduceDecision(state, intent, prompt) {
|
|
|
61
126
|
switch (intent.type) {
|
|
62
127
|
case "move":
|
|
63
128
|
return {
|
|
64
|
-
state: onRow(state, prompt,
|
|
129
|
+
state: onRow(state, prompt, state.highlight < 0
|
|
130
|
+
? intent.delta === 1
|
|
131
|
+
? 0
|
|
132
|
+
: rows - 1
|
|
133
|
+
: (state.highlight + intent.delta + rows) % rows),
|
|
65
134
|
};
|
|
66
135
|
case "pick":
|
|
67
136
|
return intent.number >= 1 && intent.number <= rows
|
|
@@ -96,6 +165,8 @@ export function reduceDecision(state, intent, prompt) {
|
|
|
96
165
|
case "details":
|
|
97
166
|
return { state: { ...state, details: !state.details } };
|
|
98
167
|
case "enter": {
|
|
168
|
+
if (state.highlight < 0 || state.highlight >= rows)
|
|
169
|
+
return unchanged(state);
|
|
99
170
|
const text = state.other.trim();
|
|
100
171
|
const answerText = text === "" ? {} : { text };
|
|
101
172
|
if (prompt.multiple === true) {
|
|
@@ -269,6 +340,8 @@ export function decisionView(state, prompt, context) {
|
|
|
269
340
|
phase: state.phase,
|
|
270
341
|
canSend: !sending &&
|
|
271
342
|
!state.details &&
|
|
343
|
+
state.highlight >= 0 &&
|
|
344
|
+
state.highlight < rows.length &&
|
|
272
345
|
(multiple
|
|
273
346
|
? state.toggled.size > 0 || otherText !== ""
|
|
274
347
|
: state.highlight < optionCount ||
|
package/dist/headless.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export { formatToolDuration, toolCallView, toolKindSigils, toolLiveLines, toolSt
|
|
|
28
28
|
export { assistantMessageVisible } from "./core/assistant-visibility.js";
|
|
29
29
|
export { disclosureOpen, initialToolDisclosure, toggleAllDisclosure, toggleDisclosure, toolCallDefaultOpen, toolGroupDefaultOpen, visibleToolCalls, type ToolDisclosureState, } from "./core/tool-groups.js";
|
|
30
30
|
export { useClientActions } from "./client-contributions.js";
|
|
31
|
-
export { awaitingQueue, awaitingTakeover, decisionView, decisionViewText, initialDecisionState, reduceDecision, type AwaitingItem, type AwaitingKind, type AwaitingQueue, type DecisionEffect, type DecisionIntent, type DecisionOutcome, type DecisionPhase, type DecisionPrompt, type DecisionRowView, type DecisionState, type DecisionView, } from "./core/awaiting-answer.js";
|
|
31
|
+
export { awaitingQueue, awaitingTakeover, decisionView, decisionViewText, initialDecisionState, reduceDecision, type AwaitingItem, type AwaitingKind, type AwaitingQueue, type DecisionEffect, type DecisionIntent, type DecisionOutcome, type DecisionPhase, type DecisionPrompt, type DecisionRowView, type DecisionState, DecisionDraft, type DecisionView, } from "./core/awaiting-answer.js";
|
|
32
32
|
export { useDecision, type DecisionController } from "./use-decision.js";
|
|
33
33
|
export { useApprovalAwaiting } from "./use-approval-awaiting.js";
|
|
34
34
|
export { approvalCardCopy, approvalRefusal, askApproval, type ApprovalAbandoned, type ApprovalAnswered, type ApprovalAnswerInput, type ApprovalAnswerResult, type ApprovalCard, type ApprovalContent, type ApprovalDecision, type ApprovalEntry, type ApprovalFacts, type ApprovalOutcome, type ApprovalRefused, type ApprovalReview, type ApprovalSource, } from "./core/approval-decision.js";
|
package/dist/headless.js
CHANGED
|
@@ -23,7 +23,7 @@ export { formatToolDuration, toolCallView, toolKindSigils, toolLiveLines, toolSt
|
|
|
23
23
|
export { assistantMessageVisible } from "./core/assistant-visibility.js";
|
|
24
24
|
export { disclosureOpen, initialToolDisclosure, toggleAllDisclosure, toggleDisclosure, toolCallDefaultOpen, toolGroupDefaultOpen, visibleToolCalls, } from "./core/tool-groups.js";
|
|
25
25
|
export { useClientActions } from "./client-contributions.js";
|
|
26
|
-
export { awaitingQueue, awaitingTakeover, decisionView, decisionViewText, initialDecisionState, reduceDecision, } from "./core/awaiting-answer.js";
|
|
26
|
+
export { awaitingQueue, awaitingTakeover, decisionView, decisionViewText, initialDecisionState, reduceDecision, DecisionDraft, } from "./core/awaiting-answer.js";
|
|
27
27
|
export { useDecision } from "./use-decision.js";
|
|
28
28
|
export { useApprovalAwaiting } from "./use-approval-awaiting.js";
|
|
29
29
|
export { approvalCardCopy, approvalRefusal, askApproval, } from "./core/approval-decision.js";
|
package/dist/styles.css
CHANGED
|
@@ -6599,6 +6599,9 @@
|
|
|
6599
6599
|
.resize {
|
|
6600
6600
|
resize: both;
|
|
6601
6601
|
}
|
|
6602
|
+
.list-none {
|
|
6603
|
+
list-style-type: none;
|
|
6604
|
+
}
|
|
6602
6605
|
.grid-cols-2 {
|
|
6603
6606
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
6604
6607
|
}
|
|
@@ -7859,6 +7862,11 @@
|
|
|
7859
7862
|
height: calc(var(--spacing) * 7);
|
|
7860
7863
|
}
|
|
7861
7864
|
}
|
|
7865
|
+
.\[\&\:\:-webkit-details-marker\]\:hidden {
|
|
7866
|
+
&::-webkit-details-marker {
|
|
7867
|
+
display: none;
|
|
7868
|
+
}
|
|
7869
|
+
}
|
|
7862
7870
|
.\[\&\>\*\]\:join-item {
|
|
7863
7871
|
&>* {
|
|
7864
7872
|
@layer daisyui.l1.l2.l3.l4 {
|
|
@@ -14599,7 +14607,8 @@
|
|
|
14599
14607
|
position: relative;
|
|
14600
14608
|
display: inline-grid;
|
|
14601
14609
|
justify-self: start;
|
|
14602
|
-
|
|
14610
|
+
--caps-code-slot: calc(var(--size-field, 0.25rem) * 10);
|
|
14611
|
+
width: min( 100%, calc( var(--caps-code-length) * var(--caps-code-slot) + (var(--caps-code-length) - 1) * var(--spacing-xs) ) );
|
|
14603
14612
|
}
|
|
14604
14613
|
.caps-code-field {
|
|
14605
14614
|
position: absolute;
|
|
@@ -14617,13 +14626,13 @@
|
|
|
14617
14626
|
}
|
|
14618
14627
|
.caps-code-slots {
|
|
14619
14628
|
display: grid;
|
|
14620
|
-
grid-
|
|
14621
|
-
grid-auto-flow: column;
|
|
14629
|
+
grid-template-columns: repeat(var(--caps-code-length), minmax(0, 1fr));
|
|
14622
14630
|
gap: var(--spacing-xs);
|
|
14623
14631
|
}
|
|
14624
14632
|
.caps-code-slot {
|
|
14625
14633
|
position: relative;
|
|
14626
|
-
width:
|
|
14634
|
+
width: 100%;
|
|
14635
|
+
min-width: 0;
|
|
14627
14636
|
justify-content: center;
|
|
14628
14637
|
padding-inline: 0;
|
|
14629
14638
|
font-family: var(--font-numeric, var(--font-mono));
|
|
@@ -19630,6 +19639,25 @@
|
|
|
19630
19639
|
max-width: none;
|
|
19631
19640
|
}
|
|
19632
19641
|
}
|
|
19642
|
+
@container (max-width: 16rem) {
|
|
19643
|
+
.parakeet-composer-row:has(.composer-settings-chip) .parakeet-composer-model-key {
|
|
19644
|
+
--caps-keycap-justify: center;
|
|
19645
|
+
--caps-keycap-padding: var(--spacing-xs);
|
|
19646
|
+
flex: none;
|
|
19647
|
+
width: var(--caps-status-tray-key-height);
|
|
19648
|
+
min-width: var(--caps-status-tray-key-height);
|
|
19649
|
+
}
|
|
19650
|
+
.parakeet-composer-row:has(.composer-settings-chip) .parakeet-composer-model-key .caps-keycap-button-label, .parakeet-composer-row .composer-settings-label {
|
|
19651
|
+
display: none;
|
|
19652
|
+
}
|
|
19653
|
+
}
|
|
19654
|
+
@media (pointer: coarse) {
|
|
19655
|
+
@container (max-width: 16rem) {
|
|
19656
|
+
.parakeet-composer-row:has(.composer-settings-chip) .parakeet-composer-model-key {
|
|
19657
|
+
display: none;
|
|
19658
|
+
}
|
|
19659
|
+
}
|
|
19660
|
+
}
|
|
19633
19661
|
.boot-curtain {
|
|
19634
19662
|
position: fixed;
|
|
19635
19663
|
inset: 0;
|
|
@@ -31,12 +31,30 @@ export function useApprovalAwaiting(options) {
|
|
|
31
31
|
view.record.revision,
|
|
32
32
|
view.canAnswer,
|
|
33
33
|
]);
|
|
34
|
+
// One record revision owns its draft in the session's store, through any
|
|
35
|
+
// loss of capability metadata and any unmount of this hook. A different
|
|
36
|
+
// revision starts a new choice; rights stay live in source.
|
|
37
|
+
const draftOwner = view === undefined
|
|
38
|
+
? undefined
|
|
39
|
+
: `${JSON.stringify(["approval", view.record.recordId]).slice(0, -1)},`;
|
|
40
|
+
const draftKey = view === undefined || draftOwner === undefined
|
|
41
|
+
? undefined
|
|
42
|
+
: JSON.stringify([
|
|
43
|
+
"approval",
|
|
44
|
+
view.record.recordId,
|
|
45
|
+
view.record.revision,
|
|
46
|
+
]);
|
|
34
47
|
useEffect(() => {
|
|
35
48
|
const view = shown.current;
|
|
36
49
|
if (!enabled || source === undefined || view === undefined)
|
|
37
50
|
return;
|
|
38
|
-
if (!view.canAnswer ||
|
|
51
|
+
if (!view.canAnswer ||
|
|
52
|
+
key === undefined ||
|
|
53
|
+
draftOwner === undefined ||
|
|
54
|
+
draftKey === undefined)
|
|
39
55
|
return;
|
|
56
|
+
store.drafts.supersede(draftOwner, draftKey);
|
|
57
|
+
const retained = store.drafts.claim(draftKey);
|
|
40
58
|
const { home, width, noteLimit } = layout.current;
|
|
41
59
|
const host = createWhistleInteractionHost({ title: "Approval" });
|
|
42
60
|
const session = host.begin();
|
|
@@ -52,6 +70,7 @@ export function useApprovalAwaiting(options) {
|
|
|
52
70
|
kind: "approval",
|
|
53
71
|
arrivedAt: Date.now(),
|
|
54
72
|
host,
|
|
73
|
+
draft: retained,
|
|
55
74
|
});
|
|
56
75
|
void askApproval(session.interaction, {
|
|
57
76
|
view,
|
|
@@ -73,6 +92,8 @@ export function useApprovalAwaiting(options) {
|
|
|
73
92
|
session.settle({ status: "failed", message: outcome.message });
|
|
74
93
|
else {
|
|
75
94
|
leave();
|
|
95
|
+
if (outcome.kind === "answered")
|
|
96
|
+
store.drafts.release(draftKey);
|
|
76
97
|
session.settle(outcome.kind === "answered"
|
|
77
98
|
? { status: "handled" }
|
|
78
99
|
: { status: "cancelled" });
|
|
@@ -82,5 +103,5 @@ export function useApprovalAwaiting(options) {
|
|
|
82
103
|
leave();
|
|
83
104
|
host.cancel();
|
|
84
105
|
};
|
|
85
|
-
}, [source, key, enabled, store]);
|
|
106
|
+
}, [source, key, draftOwner, draftKey, enabled, store]);
|
|
86
107
|
}
|
package/dist/use-decision.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useRef, useState, useSyncExternalStore } from "react";
|
|
2
|
-
import { decisionView, initialDecisionState, reduceDecision, } from "./core/awaiting-answer.js";
|
|
2
|
+
import { decisionView, initialDecisionState, unselectedDecisionState, reduceDecision, } from "./core/awaiting-answer.js";
|
|
3
3
|
/** The state as the person sees it: the reducer's, over what the host reports. */
|
|
4
4
|
function visibleState(held, snapshot) {
|
|
5
5
|
if (snapshot.prompt !== undefined)
|
|
@@ -22,20 +22,40 @@ export function useDecision(item, context) {
|
|
|
22
22
|
const { host } = item;
|
|
23
23
|
const snapshot = useSyncExternalStore(host.subscribe, host.snapshot);
|
|
24
24
|
const shown = useRef();
|
|
25
|
+
if (shown.current?.host !== host)
|
|
26
|
+
shown.current = undefined;
|
|
25
27
|
const pending = snapshot.prompt;
|
|
26
28
|
if (pending?.request.type === "decision")
|
|
27
|
-
shown.current = {
|
|
29
|
+
shown.current = {
|
|
30
|
+
host,
|
|
31
|
+
sequence: pending.sequence,
|
|
32
|
+
prompt: pending.request,
|
|
33
|
+
};
|
|
28
34
|
const [, setHeld] = useState();
|
|
29
35
|
// Several keys can arrive before React renders; each must see the last one.
|
|
30
36
|
const latest = useRef();
|
|
31
37
|
const prompt = shown.current;
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
// An approval never preselects a choice, however it came to be drawn.
|
|
39
|
+
const start = () => item.kind === "approval"
|
|
40
|
+
? unselectedDecisionState()
|
|
34
41
|
: initialDecisionState();
|
|
42
|
+
const held = () => {
|
|
43
|
+
if (prompt === undefined)
|
|
44
|
+
return start();
|
|
45
|
+
if (latest.current?.host !== host ||
|
|
46
|
+
latest.current.sequence !== prompt.sequence) {
|
|
47
|
+
const state = latest.current?.host === host
|
|
48
|
+
? start()
|
|
49
|
+
: (item.draft?.restore(prompt.prompt) ?? start());
|
|
50
|
+
latest.current = { host, sequence: prompt.sequence, state };
|
|
51
|
+
}
|
|
52
|
+
return latest.current.state;
|
|
53
|
+
};
|
|
35
54
|
const remember = (next) => {
|
|
36
55
|
if (prompt === undefined)
|
|
37
56
|
return;
|
|
38
|
-
latest.current = { sequence: prompt.sequence, state: next };
|
|
57
|
+
latest.current = { host, sequence: prompt.sequence, state: next };
|
|
58
|
+
item.draft?.remember(next, prompt.prompt);
|
|
39
59
|
setHeld(latest.current);
|
|
40
60
|
};
|
|
41
61
|
return {
|
|
@@ -60,8 +80,11 @@ export function useDecision(item, context) {
|
|
|
60
80
|
return;
|
|
61
81
|
}
|
|
62
82
|
const outcome = reduceDecision(visibleState(held(), now), intent, prompt.prompt);
|
|
63
|
-
remember(outcome.state);
|
|
64
83
|
const effect = outcome.effect;
|
|
84
|
+
// Backing out of a second question returns to nothing selected.
|
|
85
|
+
remember(item.kind === "approval" && effect?.type === "back"
|
|
86
|
+
? { ...outcome.state, highlight: -1 }
|
|
87
|
+
: outcome.state);
|
|
65
88
|
if (effect?.type === "later")
|
|
66
89
|
context.later();
|
|
67
90
|
else if (effect?.type === "answer") {
|
package/docs/api/headless.md
CHANGED
|
@@ -8,6 +8,67 @@
|
|
|
8
8
|
|
|
9
9
|
# headless
|
|
10
10
|
|
|
11
|
+
## Classes
|
|
12
|
+
|
|
13
|
+
### DecisionDraft
|
|
14
|
+
|
|
15
|
+
One pending choice, retaining no display metadata or answering authority.
|
|
16
|
+
|
|
17
|
+
#### Constructors
|
|
18
|
+
|
|
19
|
+
##### Constructor
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
new DecisionDraft(): DecisionDraft;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Start without a remembered choice.
|
|
26
|
+
|
|
27
|
+
###### Returns
|
|
28
|
+
|
|
29
|
+
[`DecisionDraft`](#decisiondraft)
|
|
30
|
+
|
|
31
|
+
#### Methods
|
|
32
|
+
|
|
33
|
+
##### remember()
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
remember(state, prompt): void;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Remember option values, which policy rows may move, and unfinished text.
|
|
40
|
+
|
|
41
|
+
###### Parameters
|
|
42
|
+
|
|
43
|
+
| Parameter | Type |
|
|
44
|
+
| --------- | --------------------------------- |
|
|
45
|
+
| `state` | [`DecisionState`](#decisionstate) |
|
|
46
|
+
| `prompt` | `object` & `object` |
|
|
47
|
+
|
|
48
|
+
###### Returns
|
|
49
|
+
|
|
50
|
+
`void`
|
|
51
|
+
|
|
52
|
+
##### restore()
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
restore(prompt): DecisionState;
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Redraw a compatible choice without replaying any submitted answer. With nothing
|
|
59
|
+
remembered, an approval has nothing selected: the person may have chosen
|
|
60
|
+
something this draft lost, and Send must not guess for them.
|
|
61
|
+
|
|
62
|
+
###### Parameters
|
|
63
|
+
|
|
64
|
+
| Parameter | Type |
|
|
65
|
+
| --------- | ------------------- |
|
|
66
|
+
| `prompt` | `object` & `object` |
|
|
67
|
+
|
|
68
|
+
###### Returns
|
|
69
|
+
|
|
70
|
+
[`DecisionState`](#decisionstate)
|
|
71
|
+
|
|
11
72
|
## Type Aliases
|
|
12
73
|
|
|
13
74
|
### LoginMethodKind
|
|
@@ -335,6 +396,11 @@ type ParakeetInteractions = Readonly<{
|
|
|
335
396
|
later: (key) => void;
|
|
336
397
|
focus: () => void;
|
|
337
398
|
}>;
|
|
399
|
+
drafts: Readonly<{
|
|
400
|
+
claim: (key) => DecisionDraft;
|
|
401
|
+
release: (key) => void;
|
|
402
|
+
supersede: (prefix, keep) => void;
|
|
403
|
+
}>;
|
|
338
404
|
}>;
|
|
339
405
|
```
|
|
340
406
|
|
|
@@ -699,6 +765,7 @@ type AwaitingItem = Readonly<{
|
|
|
699
765
|
kind: AwaitingKind;
|
|
700
766
|
arrivedAt: number;
|
|
701
767
|
host: WhistleInteractionHost;
|
|
768
|
+
draft?: DecisionDraft;
|
|
702
769
|
}>;
|
|
703
770
|
```
|
|
704
771
|
|
|
@@ -1952,10 +2019,10 @@ leaves the composer but stays counted: it is the footer row.
|
|
|
1952
2019
|
|
|
1953
2020
|
#### Parameters
|
|
1954
2021
|
|
|
1955
|
-
| Parameter | Type
|
|
1956
|
-
| --------- |
|
|
1957
|
-
| `items` | readonly `Readonly`\<\{ `key`: `string`; `kind`: [`AwaitingKind`](#awaitingkind); `arrivedAt`: `number`; `host`: `WhistleInteractionHost`; \}\>[] |
|
|
1958
|
-
| `later` | `ReadonlySet`\<`string`\>
|
|
2022
|
+
| Parameter | Type |
|
|
2023
|
+
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
2024
|
+
| `items` | readonly `Readonly`\<\{ `key`: `string`; `kind`: [`AwaitingKind`](#awaitingkind); `arrivedAt`: `number`; `host`: `WhistleInteractionHost`; `draft?`: [`DecisionDraft`](#decisiondraft); \}\>[] |
|
|
2025
|
+
| `later` | `ReadonlySet`\<`string`\> |
|
|
1959
2026
|
|
|
1960
2027
|
#### Returns
|
|
1961
2028
|
|
|
@@ -1975,6 +2042,7 @@ function awaitingTakeover(
|
|
|
1975
2042
|
kind: AwaitingKind;
|
|
1976
2043
|
arrivedAt: number;
|
|
1977
2044
|
host: WhistleInteractionHost;
|
|
2045
|
+
draft?: DecisionDraft;
|
|
1978
2046
|
}>
|
|
1979
2047
|
| undefined;
|
|
1980
2048
|
```
|
|
@@ -1984,15 +2052,16 @@ with text is never, unless the person asked for the decision.
|
|
|
1984
2052
|
|
|
1985
2053
|
#### Parameters
|
|
1986
2054
|
|
|
1987
|
-
| Parameter | Type
|
|
1988
|
-
| ---------- |
|
|
1989
|
-
| `awaiting` | `Readonly`\<\{ `items`: readonly `Readonly`\<\{ `key`: `string`; `kind`: [`AwaitingKind`](#awaitingkind); `arrivedAt`: `number`; `host`: `WhistleInteractionHost`; \}\>[]; `current?`: `Readonly`\<\{ `key`: `string`; `kind`: [`AwaitingKind`](#awaitingkind); `arrivedAt`: `number`; `host`: `WhistleInteractionHost`; \}\>; `position`: `number`; `total`: `number`; \}\> & `Readonly`\<\{ `forced`: `boolean`; \}\> |
|
|
1990
|
-
| `draft` | `string`
|
|
2055
|
+
| Parameter | Type |
|
|
2056
|
+
| ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
2057
|
+
| `awaiting` | `Readonly`\<\{ `items`: readonly `Readonly`\<\{ `key`: `string`; `kind`: [`AwaitingKind`](#awaitingkind); `arrivedAt`: `number`; `host`: `WhistleInteractionHost`; `draft?`: [`DecisionDraft`](#decisiondraft); \}\>[]; `current?`: `Readonly`\<\{ `key`: `string`; `kind`: [`AwaitingKind`](#awaitingkind); `arrivedAt`: `number`; `host`: `WhistleInteractionHost`; `draft?`: [`DecisionDraft`](#decisiondraft); \}\>; `position`: `number`; `total`: `number`; \}\> & `Readonly`\<\{ `forced`: `boolean`; \}\> |
|
|
2058
|
+
| `draft` | `string` |
|
|
1991
2059
|
|
|
1992
2060
|
#### Returns
|
|
1993
2061
|
|
|
1994
2062
|
\| `Readonly`\<\{ `key`: `string`; `kind`: [`AwaitingKind`](#awaitingkind);
|
|
1995
|
-
`arrivedAt`: `number`; `host`: `WhistleInteractionHost`;
|
|
2063
|
+
`arrivedAt`: `number`; `host`: `WhistleInteractionHost`; `draft?`:
|
|
2064
|
+
[`DecisionDraft`](#decisiondraft); \}\> \| `undefined`
|
|
1996
2065
|
|
|
1997
2066
|
---
|
|
1998
2067
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/parakeet",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.4",
|
|
4
4
|
"author": "Levi <levi@technomancy.dev>",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Standalone React composer for a typed Shiitake Session",
|
|
@@ -68,14 +68,14 @@
|
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"@earendil-works/pi-ai": "1.5.2",
|
|
71
|
-
"@fungi.computer/agar": "0.
|
|
71
|
+
"@fungi.computer/agar": "0.28.0",
|
|
72
72
|
"@fungi.computer/bird-dog": "0.3.8",
|
|
73
73
|
"@fungi.computer/cairn": "0.1.0",
|
|
74
|
-
"@fungi.computer/caps": "0.
|
|
74
|
+
"@fungi.computer/caps": "0.13.0",
|
|
75
75
|
"@fungi.computer/gills": "0.4.0",
|
|
76
76
|
"@fungi.computer/knapsack": "0.4.27",
|
|
77
77
|
"@fungi.computer/mule": "0.3.0",
|
|
78
|
-
"@fungi.computer/shiitake": "0.22.
|
|
78
|
+
"@fungi.computer/shiitake": "0.22.6",
|
|
79
79
|
"@fungi.computer/sigils": "0.3.2",
|
|
80
80
|
"@fungi.computer/sprite": "0.2.2",
|
|
81
81
|
"@fungi.computer/sprite-zdog": "0.3.2",
|
package/src/composer-shell.css
CHANGED
|
@@ -132,3 +132,34 @@
|
|
|
132
132
|
max-width: none;
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
|
+
|
|
136
|
+
/* A split phone pane has room for the model menu key, not a partial name.
|
|
137
|
+
Keep its accessible model label and the ordinary picker action. */
|
|
138
|
+
@container (max-width: 16rem) {
|
|
139
|
+
.parakeet-composer-row:has(.composer-settings-chip)
|
|
140
|
+
.parakeet-composer-model-key {
|
|
141
|
+
--caps-keycap-justify: center;
|
|
142
|
+
--caps-keycap-padding: var(--spacing-xs);
|
|
143
|
+
flex: none;
|
|
144
|
+
width: var(--caps-status-tray-key-height);
|
|
145
|
+
min-width: var(--caps-status-tray-key-height);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.parakeet-composer-row:has(.composer-settings-chip)
|
|
149
|
+
.parakeet-composer-model-key
|
|
150
|
+
.caps-keycap-button-label,
|
|
151
|
+
.parakeet-composer-row .composer-settings-label {
|
|
152
|
+
display: none;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/* Touch keys need more room in a phone's beside pane. Settings already
|
|
157
|
+
contains the same model picker, so keep that route instead of a fourth key. */
|
|
158
|
+
@media (pointer: coarse) {
|
|
159
|
+
@container (max-width: 16rem) {
|
|
160
|
+
.parakeet-composer-row:has(.composer-settings-chip)
|
|
161
|
+
.parakeet-composer-model-key {
|
|
162
|
+
display: none;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|