rift-ds 1.22.0 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/behaviors/chat-card.css +135 -0
- package/chat/AssistantTurn.js +9 -3
- package/chat/ChatLauncher.js +3 -5
- package/chat/ChatProvider.d.ts +10 -1
- package/chat/ChatProvider.js +3 -2
- package/chat/ChatWidget.css +12 -0
- package/chat/ChatWidget.d.ts +27 -4
- package/chat/ChatWidget.js +73 -37
- package/chat/DemoWelcome.js +2 -2
- package/chat/actions.d.ts +105 -0
- package/chat/actions.js +47 -0
- package/chat/demo-card-components.d.ts +3 -4
- package/chat/demo-script.js +15 -15
- package/chat/generatedStarters.d.ts +19 -0
- package/chat/generatedStarters.js +49 -0
- package/chat/index.d.ts +7 -3
- package/chat/index.js +25 -2
- package/chat/placement.d.ts +9 -0
- package/chat/placement.js +7 -0
- package/chat/queries.d.ts +6 -0
- package/chat/queries.js +25 -0
- package/chat/questions.d.ts +1 -1
- package/chat/questions.js +1 -1
- package/chat/registry.json.d.ts +4 -2
- package/chat/registry.json.js +1 -1
- package/chat/selection.css +8 -0
- package/chat/selection.d.ts +40 -0
- package/chat/selection.js +140 -0
- package/chat/selectionContext.d.ts +70 -0
- package/chat/selectionContext.js +60 -0
- package/chat/server.d.ts +54 -1
- package/chat/server.js +101 -5
- package/chat/suggestions.d.ts +12 -8
- package/chat/suggestions.js +1 -1
- package/chat/types.d.ts +2 -0
- package/chat/useChat.js +5 -3
- package/components/ActionCard/ActionCard.css +147 -0
- package/components/ActionCard/ActionCard.d.ts +54 -0
- package/components/ActionCard/ActionCard.js +75 -0
- package/components/ActionReadout/ActionReadout.css +47 -0
- package/components/ActionReadout/ActionReadout.d.ts +29 -0
- package/components/ActionReadout/ActionReadout.js +22 -0
- package/components/AgentPlan/AgentPlan.css +18 -8
- package/components/AgentPlan/AgentPlan.js +1 -0
- package/components/AppSidebar/AppSidebar.css +11 -5
- package/components/AppSidebar/AppSidebar.d.ts +2 -0
- package/components/AppSidebar/AppSidebar.js +13 -1
- package/components/ArtifactCard/ArtifactCard.css +11 -10
- package/components/ArtifactCard/ArtifactCard.js +3 -1
- package/components/ChatThread/ChatThread.css +6 -3
- package/components/Chip/Chip.css +9 -1
- package/components/CodeBlock/CodeBlock.css +2 -0
- package/components/CodeDiff/CodeDiff.css +18 -8
- package/components/CodeDiff/CodeDiff.js +1 -0
- package/components/Composer/Composer.css +52 -13
- package/components/Composer/Composer.d.ts +9 -1
- package/components/Composer/Composer.js +19 -1
- package/components/DataTable/FilterEditor.js +4 -2
- package/components/DataTable/filterModel.d.ts +8 -0
- package/components/DataTable/filterModel.js +4 -0
- package/components/DataTable/views.js +2 -2
- package/components/DocumentChip/DocumentChip.css +27 -3
- package/components/EntitySwitcher/EntitySwitcher.css +333 -0
- package/components/EntitySwitcher/EntitySwitcher.d.ts +74 -0
- package/components/EntitySwitcher/EntitySwitcher.js +291 -0
- package/components/InterruptCard/InterruptCard.css +96 -34
- package/components/InterruptCard/InterruptCard.d.ts +20 -3
- package/components/InterruptCard/InterruptCard.js +23 -8
- package/components/MessageCard/MessageCard.css +27 -18
- package/components/MessageCard/MessageCard.js +1 -0
- package/components/PromptSuggestions/PromptSuggestions.css +3 -0
- package/components/Prose/Prose.css +2 -0
- package/components/QuestionCard/QuestionCard.css +9 -5
- package/components/QuestionCard/QuestionCard.js +1 -0
- package/components/SourceTrail/SourceTrail.css +33 -11
- package/components/SourceTrail/SourceTrail.js +3 -2
- package/components/TableToolbar/TableToolbar.css +4 -1
- package/components/TableToolbar/TableToolbar.js +1 -1
- package/components/ToolCall/ToolCall.css +89 -22
- package/components/ToolCall/ToolCall.js +2 -1
- package/components/UsageCard/UsageCard.css +29 -2
- package/components/UsageCard/UsageCard.js +1 -0
- package/components/registry.json +24 -0
- package/components/registry.json.d.ts +24 -0
- package/components/registry.json.js +1 -1
- package/fonts/presets/bricolage-grotesque-300-800-latin-ext.woff2 +0 -0
- package/fonts/presets/bricolage-grotesque-300-800-latin.woff2 +0 -0
- package/fonts/presets/figtree-300-800-latin-ext.woff2 +0 -0
- package/fonts/presets/figtree-300-800-latin.woff2 +0 -0
- package/index.d.ts +3 -0
- package/index.js +6 -0
- package/package.json +5 -1
- package/tokens/motion.d.ts +2 -0
- package/tokens/motion.js +2 -0
- package/tokens/presets/plum.css +419 -0
- package/tokens/presets/presets.css +1 -0
- package/tokens/registry.json +2 -0
- package/tokens/registry.json.d.ts +2 -0
- package/tokens/registry.json.js +1 -1
- package/tokens/tokens-dark.css +4 -0
- package/tokens/tokens-light.css +4 -0
- package/tokens/tokens-typography.css +8 -2
- package/tokens/values.json.js +1 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Changes a chat can propose and a reader confirms, defined once.
|
|
3
|
+
*
|
|
4
|
+
* An action says which records it applies to (`skip` gives the reason it
|
|
5
|
+
* leaves one alone, or null), what it writes to each (`apply`), and the words
|
|
6
|
+
* around it: its button and card title (`label`), what a receipt says was
|
|
7
|
+
* done (`done`), the reader's words when they confirm it in the chat
|
|
8
|
+
* (`confirm`), and how a page's own confirmation asks (`verb`, `effect`). The
|
|
9
|
+
* same definition drives a selection bar's button and the chat's proposal, so
|
|
10
|
+
* the two can never do different things to the same records. `planAction` is
|
|
11
|
+
* the dry run both show before anything changes.
|
|
12
|
+
*
|
|
13
|
+
* Pure and framework-free: published on its own as rift-ds/chat/actions, so a
|
|
14
|
+
* shared definitions module pulls in no peer, and re-exported from
|
|
15
|
+
* rift-ds/chat for the page and rift-ds/chat/server for the route that
|
|
16
|
+
* proposes, which plans the same action over the same records. The flow it
|
|
17
|
+
* serves (propose on a card, the reader's Confirm sent as their message, the
|
|
18
|
+
* reply opening with a readout) is design.md's "A chat proposes, the reader
|
|
19
|
+
* confirms".
|
|
20
|
+
*
|
|
21
|
+
* The confirmation mark is what makes that flow safe. The reader's Confirm
|
|
22
|
+
* sends their words as an ordinary message, which they could also type, so
|
|
23
|
+
* the words alone can never be what tells the server a change was made. The
|
|
24
|
+
* page marks the one request its Confirm sends (`createConfirmationMark`),
|
|
25
|
+
* the route rebuilds the mark from the request (`sanitiseConfirmation`), and
|
|
26
|
+
* the model is told whether this message was confirmed on its card
|
|
27
|
+
* (`confirmationLine`). A typed "yes, cancel them" carries no mark.
|
|
28
|
+
*/
|
|
29
|
+
export interface ChatAction<Values, Edit = Partial<Values>> {
|
|
30
|
+
/** A stable id the server and the page share. */
|
|
31
|
+
id: string;
|
|
32
|
+
/** The button's words, and the proposal card's title: "Cancel orders". */
|
|
33
|
+
label: string;
|
|
34
|
+
/** What a receipt says was done, after the count: "cancelled". */
|
|
35
|
+
done: string;
|
|
36
|
+
/** The reader's words when they confirm it in the chat, given "this order" or "these 23 orders". */
|
|
37
|
+
confirm: (these: string) => string;
|
|
38
|
+
/** The verb a confirmation asks with: "Cancel" in "Cancel 3 orders?", and on its confirm button. Defaults to the label. */
|
|
39
|
+
verb?: string;
|
|
40
|
+
/** What the change does to the records, for a confirmation's body, given how many it changes: "Any that were paid are refunded." Worded for the count, so one record reads as one. */
|
|
41
|
+
effect?: (count: number) => string;
|
|
42
|
+
/** A Material Symbol for the card and the button. */
|
|
43
|
+
icon: string;
|
|
44
|
+
/** Drawn as destructive on the card and the bar. */
|
|
45
|
+
destructive?: boolean;
|
|
46
|
+
/** Why a record is left alone ("already shipped"), or null when the action applies to it. */
|
|
47
|
+
skip: (values: Values) => string | null;
|
|
48
|
+
/** What the action writes to a record it applies to. */
|
|
49
|
+
apply: (values: Values) => Edit;
|
|
50
|
+
}
|
|
51
|
+
/** Declares an action, typed by the records it acts on. */
|
|
52
|
+
export declare const defineAction: <Values, Edit = Partial<Values>>(action: ChatAction<Values, Edit>) => ChatAction<Values, Edit>;
|
|
53
|
+
/** What an action would do to some records: the ones it changes, and how many it leaves alone for each reason. */
|
|
54
|
+
export interface ActionPlan {
|
|
55
|
+
action: string;
|
|
56
|
+
ids: string[];
|
|
57
|
+
skipped: Record<string, number>;
|
|
58
|
+
}
|
|
59
|
+
/** The dry run: which of these records the action changes, and why it leaves the rest. Changes nothing. */
|
|
60
|
+
export declare function planAction<Values>(action: ChatAction<Values, unknown>, records: {
|
|
61
|
+
id: string;
|
|
62
|
+
values: Values;
|
|
63
|
+
}[]): ActionPlan;
|
|
64
|
+
/** A change the reader confirmed on its card: which action, how many records it changed, and their ids. */
|
|
65
|
+
export interface ActionConfirmation<Id extends string = string> {
|
|
66
|
+
action: Id;
|
|
67
|
+
count: number;
|
|
68
|
+
ids: string[];
|
|
69
|
+
}
|
|
70
|
+
/** The page's one-shot mark: set on Confirm, read once by the next request, then gone. */
|
|
71
|
+
export interface ConfirmationMark<Id extends string = string> {
|
|
72
|
+
/** Marks the request about to carry the reader's confirmation. */
|
|
73
|
+
mark: (confirmation: ActionConfirmation<Id>) => void;
|
|
74
|
+
/** The mark for this request, cleared as it is read, or null when the message was not a card's Confirm. */
|
|
75
|
+
take: () => ActionConfirmation<Id> | null;
|
|
76
|
+
}
|
|
77
|
+
/** A holder for the confirmation mark. Keep one per chat (a ref or a module value); the transport calls `take` in `getContext`. */
|
|
78
|
+
export declare function createConfirmationMark<Id extends string = string>(): ConfirmationMark<Id>;
|
|
79
|
+
export interface SanitiseConfirmationOptions {
|
|
80
|
+
/** The actions a confirmation may name, by id. */
|
|
81
|
+
actions: Record<string, ChatAction<never, unknown>> | readonly string[];
|
|
82
|
+
/** Whether an id is a real record. Ids that are not are dropped. */
|
|
83
|
+
isId: (id: string) => boolean;
|
|
84
|
+
/** The most records one confirmation can change. */
|
|
85
|
+
maxCount: number;
|
|
86
|
+
/** The most ids kept. Defaults to 50. */
|
|
87
|
+
maxIds?: number;
|
|
88
|
+
}
|
|
89
|
+
/** The confirmation a request claims, rebuilt as untrusted input: a known action, a count in range, real ids only. Null for none. */
|
|
90
|
+
export declare function sanitiseConfirmation(value: unknown, { actions, isId, maxCount, maxIds }: SanitiseConfirmationOptions): ActionConfirmation | null;
|
|
91
|
+
export interface ConfirmationLineOptions {
|
|
92
|
+
/** The actions a confirmation may name, by id, for the words that say what was done. */
|
|
93
|
+
actions: Record<string, Pick<ChatAction<never, unknown>, 'done'>>;
|
|
94
|
+
/** The records' noun for a count: "order" for one, "orders" for more. */
|
|
95
|
+
noun: (count: number) => string;
|
|
96
|
+
/** The locale the count is written in. */
|
|
97
|
+
locale?: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The line that tells the model whether this message was a card's Confirm, so
|
|
101
|
+
* it says a change is made only when it was.
|
|
102
|
+
*/
|
|
103
|
+
export declare function confirmationLine(confirmation: ActionConfirmation | null, { actions, noun, locale }: ConfirmationLineOptions): string;
|
|
104
|
+
/** "2 already shipped, 1 cancelled": the records a plan leaves alone, in words, its counts in `locale`. */
|
|
105
|
+
export declare const skippedText: (skipped: Record<string, number>, locale?: string) => string;
|
package/chat/actions.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { DEFAULT_LOCALE } from "../behaviors/locale.js";
|
|
2
|
+
const defineAction = (action) => action;
|
|
3
|
+
function planAction(action, records) {
|
|
4
|
+
const ids = [];
|
|
5
|
+
const skipped = {};
|
|
6
|
+
for (const record of records) {
|
|
7
|
+
const reason = action.skip(record.values);
|
|
8
|
+
if (reason) skipped[reason] = (skipped[reason] ?? 0) + 1;
|
|
9
|
+
else ids.push(record.id);
|
|
10
|
+
}
|
|
11
|
+
return { action: action.id, ids, skipped };
|
|
12
|
+
}
|
|
13
|
+
function createConfirmationMark() {
|
|
14
|
+
let pending = null;
|
|
15
|
+
return {
|
|
16
|
+
mark: (confirmation) => {
|
|
17
|
+
pending = confirmation;
|
|
18
|
+
},
|
|
19
|
+
take: () => {
|
|
20
|
+
const confirmation = pending;
|
|
21
|
+
pending = null;
|
|
22
|
+
return confirmation;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function sanitiseConfirmation(value, { actions, isId, maxCount, maxIds = 50 }) {
|
|
27
|
+
const { action, count, ids } = value ?? {};
|
|
28
|
+
const known = Array.isArray(actions) ? actions : Object.keys(actions);
|
|
29
|
+
if (typeof action !== "string" || !known.includes(action)) return null;
|
|
30
|
+
if (typeof count !== "number" || !Number.isFinite(count) || count < 1 || count > maxCount) return null;
|
|
31
|
+
const kept = Array.isArray(ids) ? ids.filter((id) => typeof id === "string" && isId(id)) : [];
|
|
32
|
+
return { action, count: Math.floor(count), ids: [...new Set(kept)].slice(0, maxIds) };
|
|
33
|
+
}
|
|
34
|
+
function confirmationLine(confirmation, { actions, noun, locale = DEFAULT_LOCALE }) {
|
|
35
|
+
const action = confirmation ? actions[confirmation.action] : void 0;
|
|
36
|
+
if (!confirmation || !action) return "This message was not confirmed on a card. Nothing it says has changed anything.";
|
|
37
|
+
return `This message was confirmed on its card: ${confirmation.count.toLocaleString(locale)} ${noun(confirmation.count)} ${action.done}. The change is made.`;
|
|
38
|
+
}
|
|
39
|
+
const skippedText = (skipped, locale = DEFAULT_LOCALE) => Object.entries(skipped).map(([reason, count]) => `${count.toLocaleString(locale)} ${reason}`).join(", ");
|
|
40
|
+
export {
|
|
41
|
+
confirmationLine,
|
|
42
|
+
createConfirmationMark,
|
|
43
|
+
defineAction,
|
|
44
|
+
planAction,
|
|
45
|
+
sanitiseConfirmation,
|
|
46
|
+
skippedText
|
|
47
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { InterruptCardOption } from '../components/InterruptCard/InterruptCard';
|
|
1
2
|
import { ChatCardRenderers } from './context';
|
|
2
3
|
import { ChatCard } from './types';
|
|
3
4
|
export interface DemoChartCard {
|
|
@@ -21,11 +22,9 @@ export interface DemoToolCallCard {
|
|
|
21
22
|
export interface DemoInterruptCard {
|
|
22
23
|
title: string;
|
|
23
24
|
description: string;
|
|
24
|
-
options: {
|
|
25
|
-
value: string;
|
|
26
|
-
label: string;
|
|
25
|
+
options: (Pick<InterruptCardOption, 'value' | 'label' | 'answeredLabel' | 'answeredVariant'> & {
|
|
27
26
|
variant: 'primary' | 'secondary';
|
|
28
|
-
}[];
|
|
27
|
+
})[];
|
|
29
28
|
}
|
|
30
29
|
/** Several cards landing as one turn's stack. */
|
|
31
30
|
export interface DemoStackCard {
|
package/chat/demo-script.js
CHANGED
|
@@ -32,7 +32,7 @@ function planFor(answer) {
|
|
|
32
32
|
return {
|
|
33
33
|
steps: [{ status: "Matching the plan", point: "Team size decides the plan; nothing else differs." }],
|
|
34
34
|
text: `For ${answer.trim().replace(/[.!?]$/, "")}, ${plan}.`,
|
|
35
|
-
followups: ["What do the plans include?", "Invite my team
|
|
35
|
+
followups: ["What do the plans include?", "Invite my team", "Set up notifications for me"]
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
const INVITES_SENT = {
|
|
@@ -56,12 +56,12 @@ const PLANS_COMPARED = {
|
|
|
56
56
|
{ status: "Drafting the answer", point: "Name what the Team plan adds over the base." }
|
|
57
57
|
],
|
|
58
58
|
text: "Every plan includes unlimited projects. The Team plan adds shared workspaces, guest seats, and a 90 day version history.",
|
|
59
|
-
followups: ["Which plan fits
|
|
59
|
+
followups: ["Which plan fits five people?", "Help me pick a plan", "Where is that written down?"]
|
|
60
60
|
};
|
|
61
61
|
const DEMO_STARTERS = [
|
|
62
62
|
{ id: "start", label: "How do I get started?" },
|
|
63
63
|
{ id: "plans", label: "What do the plans include?" },
|
|
64
|
-
{ id: "invite", label: "Invite my team
|
|
64
|
+
{ id: "invite", label: "Invite my team" }
|
|
65
65
|
];
|
|
66
66
|
const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
|
|
67
67
|
"Create a workspace from the dashboard, then invite your team from Settings. Everyone you add sees the shared projects the moment they join. If you would rather not click through it, I can set the whole thing up for you.",
|
|
@@ -79,7 +79,7 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
|
|
|
79
79
|
],
|
|
80
80
|
card: card("plan", { steps: PLAN_STEPS }),
|
|
81
81
|
followups: ["Find a time we can all meet", "Take us up to twelve seats", "How is the trial going?"]
|
|
82
|
-
}).user("What do the plans include?").assistant(PLANS_COMPARED.text, PLANS_COMPARED).user("Which plan fits
|
|
82
|
+
}).user("What do the plans include?").assistant(PLANS_COMPARED.text, PLANS_COMPARED).user("Which plan fits five people?").assistant("The Team plan fits what you described: shared workspaces for the whole team, and guest seats stay free. Shall we go with it?", {
|
|
83
83
|
steps: [
|
|
84
84
|
{ status: "Matching plans to the team", point: "The visitor needs shared workspaces and guest seats." },
|
|
85
85
|
{ status: "Drafting the answer", point: "The Team plan covers both; lead with the card." }
|
|
@@ -105,7 +105,7 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
|
|
|
105
105
|
answered: (answer) => answer.toLowerCase().includes("compare") ? PLANS_COMPARED : {
|
|
106
106
|
steps: [{ status: "Switching the plan", point: "Move the workspace to Team from today." }],
|
|
107
107
|
text: "Done. The workspace is on the Team plan from today, billed monthly, and you can step back down any time.",
|
|
108
|
-
followups: ["Invite my team
|
|
108
|
+
followups: ["Invite my team", "Where is that written down?", "How is the trial going?"]
|
|
109
109
|
}
|
|
110
110
|
}).user("Where is that written down?").assistant("Each chip opens the page the answer came from, so nothing here needs taking on trust.", {
|
|
111
111
|
steps: [
|
|
@@ -137,7 +137,7 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
|
|
|
137
137
|
}
|
|
138
138
|
]
|
|
139
139
|
}),
|
|
140
|
-
followups: ["Which plan fits
|
|
140
|
+
followups: ["Which plan fits five people?", "How do I get started?", "How is the trial going?"]
|
|
141
141
|
}).user("How is the trial going?").assistant("Signups have climbed for five of the six weeks since the trial opened, and last week was the strongest yet.", {
|
|
142
142
|
steps: [
|
|
143
143
|
{ status: "Pulling the signup numbers", point: "Six weeks of signup data since the trial opened." },
|
|
@@ -152,8 +152,8 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
|
|
|
152
152
|
yKey: "signups",
|
|
153
153
|
label: "Signups"
|
|
154
154
|
}),
|
|
155
|
-
followups: ["Which plan fits
|
|
156
|
-
}).user("Invite my team
|
|
155
|
+
followups: ["Which plan fits five people?", "Invite my team", "Where is that written down?"]
|
|
156
|
+
}).user("Invite my team").assistant("Happy to. Shall I send invites to the three teammates on your account, all as editors?", {
|
|
157
157
|
steps: [
|
|
158
158
|
{ status: "Checking the account", point: "Three teammates sit on the account, none invited yet." },
|
|
159
159
|
{ status: "Drafting the answer", point: "Confirm before sending anything." }
|
|
@@ -176,7 +176,7 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
|
|
|
176
176
|
text: "Nothing sent. The three are ready to go whenever you are.",
|
|
177
177
|
followups: ["Take us up to twelve seats", "Find a time we can all meet", "How is the trial going?"]
|
|
178
178
|
} : INVITES_SENT
|
|
179
|
-
}).user("
|
|
179
|
+
}).user("Invite the other three").assistant(INVITES_SENT.text, INVITES_SENT).user("Take us up to twelve seats").assistant("Only the seat count moves, from five to twelve. Everything else in the config stays as it was. Apply it?", {
|
|
180
180
|
steps: [
|
|
181
181
|
{ status: "Locating the seat limit", point: "The seat limit lives in workspace.config.ts." },
|
|
182
182
|
{ status: "Preparing the change", point: "One line changes; show the diff." }
|
|
@@ -201,7 +201,7 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
|
|
|
201
201
|
answered: (answer) => answer.toLowerCase().startsWith("not yet") ? {
|
|
202
202
|
steps: [{ status: "Leaving the config", point: "The diff stays a proposal." }],
|
|
203
203
|
text: "Left as it is. The workspace stays at five seats until you say otherwise.",
|
|
204
|
-
followups: ["What do the plans include?", "Invite my team
|
|
204
|
+
followups: ["What do the plans include?", "Invite my team", "How is the trial going?"]
|
|
205
205
|
} : {
|
|
206
206
|
steps: [{ status: "Applying the change", point: "One line in workspace.config.ts." }],
|
|
207
207
|
text: "Applied. The workspace takes twelve seats from now, and the next invoice picks up the difference.",
|
|
@@ -211,7 +211,7 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
|
|
|
211
211
|
status: "success",
|
|
212
212
|
duration: "0.4s"
|
|
213
213
|
}),
|
|
214
|
-
followups: ["Invite my team
|
|
214
|
+
followups: ["Invite my team", "Find a time we can all meet", "How is the trial going?"]
|
|
215
215
|
}
|
|
216
216
|
}).user("Here is the launch plan we are working from.").assistant(
|
|
217
217
|
"Three phases, and most of the budget sits behind launch week itself. The dates line up with the workspace you already set up, so nothing needs to move.",
|
|
@@ -265,7 +265,7 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
|
|
|
265
265
|
answered: (answer) => answer.toLowerCase().startsWith("leave") ? {
|
|
266
266
|
steps: [{ status: "Leaving the sync", point: "Nothing to retry until asked." }],
|
|
267
267
|
text: "Left for now. Nothing else depends on it, and it can run again whenever you like.",
|
|
268
|
-
followups: ["Find a time we can all meet", "Invite my team
|
|
268
|
+
followups: ["Find a time we can all meet", "Invite my team", "How is the trial going?"]
|
|
269
269
|
} : {
|
|
270
270
|
steps: [{ status: "Retrying the sync", point: "Second attempt against the provider." }],
|
|
271
271
|
text: "Second time lucky. The shared calendar is in sync.",
|
|
@@ -299,14 +299,14 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
|
|
|
299
299
|
answered: (answer) => answer.toLowerCase().startsWith("not now") ? {
|
|
300
300
|
steps: [{ status: "Leaving the calendar alone", point: "No access; offer the manual route." }],
|
|
301
301
|
text: "No problem, nothing is connected. You can share a few times that suit you and I will send them round.",
|
|
302
|
-
followups: ["
|
|
302
|
+
followups: ["Invite the other three", "How is the trial going?", "How do I get started?"]
|
|
303
303
|
} : {
|
|
304
304
|
steps: [
|
|
305
305
|
{ status: "Reading the shared calendar", point: "Four calendars, the next ten working days." },
|
|
306
306
|
{ status: "Finding a free slot", point: "Thursday afternoon is clear for everyone." }
|
|
307
307
|
],
|
|
308
308
|
text: answer.toLowerCase().includes("always") ? "Connected for good. Thursday at 2pm is the first slot everyone has free, and I will keep an eye out when plans change." : "Read once and disconnected. Thursday at 2pm is the first slot everyone has free.",
|
|
309
|
-
followups: ["Plan our launch kickoff", "
|
|
309
|
+
followups: ["Plan our launch kickoff", "Invite the other three", "How is the trial going?"]
|
|
310
310
|
}
|
|
311
311
|
}).user("Build me a launch dashboard").assistant(
|
|
312
312
|
"Here is the launch on one board: what is running now, the trial signups, the projects and what is waiting on you. The rows that ask a question will ask it here.",
|
|
@@ -316,7 +316,7 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
|
|
|
316
316
|
{ status: "Laying out the dashboard", point: "Too much for a card; build it as an artifact." }
|
|
317
317
|
],
|
|
318
318
|
card: artifactCard(DEMO_DASHBOARD_ARTIFACT),
|
|
319
|
-
followups: ["Draft the launch page", "How is the trial going?", "Which plan fits
|
|
319
|
+
followups: ["Draft the launch page", "How is the trial going?", "Which plan fits five people?"]
|
|
320
320
|
}
|
|
321
321
|
).user("Draft the launch page").assistant(
|
|
322
322
|
"A first draft of the launch page is up beside the chat: the headline, the three things the Team plan adds, and one call to action. The source is behind the Code view.",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Starter } from './types';
|
|
2
|
+
export interface GeneratedStartersOptions {
|
|
3
|
+
/** The route `createStartersHandler` serves. */
|
|
4
|
+
endpoint: string;
|
|
5
|
+
/** Ask only while this is true: the welcome screen is showing. */
|
|
6
|
+
active: boolean;
|
|
7
|
+
/** The written chips for when nothing comes back, and while the model writes. */
|
|
8
|
+
fallback: Starter[];
|
|
9
|
+
}
|
|
10
|
+
export interface GeneratedStarters {
|
|
11
|
+
/** The chips to show: the model's once written, the fallback until then. Null with no request. */
|
|
12
|
+
starters: Starter[] | null;
|
|
13
|
+
/** Whether the model is still writing them: ChatWidget's `startersPending`. */
|
|
14
|
+
pending: boolean;
|
|
15
|
+
/** A short, stable key for the request: ChatWidget's `startersKey`. */
|
|
16
|
+
key: string | null;
|
|
17
|
+
}
|
|
18
|
+
/** The model's starters for `request`, or null for none (the host shows its own). */
|
|
19
|
+
export declare function useGeneratedStarters(request: string | null, { endpoint, active, fallback }: GeneratedStartersOptions): GeneratedStarters;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState, useRef, useEffect } from "react";
|
|
3
|
+
import { MOTION_SELECTION_SETTLE_MS } from "../tokens/motion.js";
|
|
4
|
+
const written = /* @__PURE__ */ new Map();
|
|
5
|
+
function hashOf(text) {
|
|
6
|
+
let hash = 0;
|
|
7
|
+
for (let index = 0; index < text.length; index += 1) hash = hash * 31 + text.charCodeAt(index) | 0;
|
|
8
|
+
return (hash >>> 0).toString(36);
|
|
9
|
+
}
|
|
10
|
+
function useGeneratedStarters(request, { endpoint, active, fallback }) {
|
|
11
|
+
const cacheKey = request === null ? null : `${endpoint}
|
|
12
|
+
${request}`;
|
|
13
|
+
const [settled, setSettled] = useState(null);
|
|
14
|
+
const fallbackRef = useRef(fallback);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
fallbackRef.current = fallback;
|
|
17
|
+
});
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!active || cacheKey === null || written.has(cacheKey)) return;
|
|
20
|
+
const controller = new AbortController();
|
|
21
|
+
const timer = setTimeout(async () => {
|
|
22
|
+
let suggestions = [];
|
|
23
|
+
try {
|
|
24
|
+
const response = await fetch(endpoint, {
|
|
25
|
+
method: "POST",
|
|
26
|
+
headers: { "content-type": "application/json" },
|
|
27
|
+
body: JSON.stringify({ context: request }),
|
|
28
|
+
signal: controller.signal
|
|
29
|
+
});
|
|
30
|
+
suggestions = response.ok ? (await response.json()).suggestions ?? [] : [];
|
|
31
|
+
} catch {
|
|
32
|
+
if (controller.signal.aborted) return;
|
|
33
|
+
}
|
|
34
|
+
const starters2 = suggestions.length ? suggestions.map((label, index) => ({ id: `generated-${index}`, label })) : fallbackRef.current;
|
|
35
|
+
written.set(cacheKey, starters2);
|
|
36
|
+
setSettled({ cacheKey, starters: starters2 });
|
|
37
|
+
}, MOTION_SELECTION_SETTLE_MS);
|
|
38
|
+
return () => {
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
controller.abort();
|
|
41
|
+
};
|
|
42
|
+
}, [active, cacheKey, endpoint, request]);
|
|
43
|
+
if (cacheKey === null) return { starters: null, pending: false, key: null };
|
|
44
|
+
const starters = written.get(cacheKey) ?? (settled?.cacheKey === cacheKey ? settled.starters : null);
|
|
45
|
+
return { starters: starters ?? fallback, pending: active && !starters, key: `generated-${hashOf(cacheKey)}` };
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
useGeneratedStarters
|
|
49
|
+
};
|
package/chat/index.d.ts
CHANGED
|
@@ -14,7 +14,11 @@
|
|
|
14
14
|
* documentation, and validate-chat-widget.mjs holds the two together).
|
|
15
15
|
*/
|
|
16
16
|
export { ChatProvider, type ChatProviderProps } from './ChatProvider';
|
|
17
|
-
export { ChatWidget, type ChatWidgetProps, type ChatAgentOptions, type RailSlot } from './ChatWidget';
|
|
17
|
+
export { ChatWidget, type ChatWidgetProps, type ChatAgentOptions, type ChatContext, type RailSlot } from './ChatWidget';
|
|
18
|
+
export { useSelectionFocus, useHeldHighlight, readSelection, describeSelection, CHAT_SOURCE_ATTRIBUTE, HELD_HIGHLIGHT_NAME, type SelectedText, type DescribeSelectionOptions } from './selection';
|
|
19
|
+
export { sanitiseSelection, selectionLines, DEFAULT_SELECTION_LIMITS, type ChatSelection, type SelectionKind, type SelectionLimits, type SelectionLinesOptions } from './selectionContext';
|
|
20
|
+
export { useGeneratedStarters, type GeneratedStarters, type GeneratedStartersOptions } from './generatedStarters';
|
|
21
|
+
export { defineAction, planAction, skippedText, createConfirmationMark, sanitiseConfirmation, confirmationLine, type ChatAction, type ActionPlan, type ActionConfirmation, type ConfirmationMark, type SanitiseConfirmationOptions, type ConfirmationLineOptions, } from './actions';
|
|
18
22
|
export { ChatLauncher, CHAT_PANEL_ID, type ChatLauncherProps } from './ChatLauncher';
|
|
19
23
|
export { useChatAgentState } from './agentState';
|
|
20
24
|
export { ChatThreads, type ChatThreadsProps } from './ChatThreads';
|
|
@@ -23,7 +27,7 @@ export { ChatAgentPane, type ChatAgentPaneProps } from './ChatAgentPane';
|
|
|
23
27
|
export { ChatArtifactPane, type ChatArtifactPaneProps } from './ChatArtifactPane';
|
|
24
28
|
export { ChatArtifactCard, type ChatArtifactCardProps } from './ChatArtifactCard';
|
|
25
29
|
export { useChatWidget, isInternalPath, createFeedbackPoster, type ChatView, type ChatArtifactRenderers, type ChatCardRenderers, type ChatLinkRenderer, type ChatWidgetContextValue, type FeedbackSink, } from './context';
|
|
26
|
-
export { DOCK_QUERY, TAKEOVER_QUERY, THREADS_RAIL_MIN_WIDTH, ASIDE_RAIL_MIN_WIDTH, ARTIFACT_MIN_COLUMN_WIDTH, ASIDE_WITH_THREADS_MIN_WIDTH, useTakeoverViewport, } from './queries';
|
|
30
|
+
export { DOCK_QUERY, TAKEOVER_QUERY, THREADS_RAIL_MIN_WIDTH, ASIDE_RAIL_MIN_WIDTH, ARTIFACT_MIN_COLUMN_WIDTH, ASIDE_WITH_THREADS_MIN_WIDTH, useTakeoverViewport, useDockViewport, } from './queries';
|
|
27
31
|
export { useChat, DEFAULT_PLACEHOLDER_COPY, type ChatState, type ChatPlaceholderCopy, } from './useChat';
|
|
28
32
|
export { useThreads, THREAD_NAMING_DELAY_MS, type ThreadsLabels, type ThreadsOptions, type ThreadsState } from './threads';
|
|
29
33
|
export { createFetchTransport, DEFAULT_FETCH_COPY, FIRST_BYTE_TIMEOUT_MS, MAX_TRANSPORT_TURNS, type FetchTransportOptions, type FetchTransportCopy, } from './transport';
|
|
@@ -33,7 +37,7 @@ export { SUGGESTION_MAX_CHARS, fitsChip } from './suggestions';
|
|
|
33
37
|
export { sanitizeQuestionSet, describeAnswers, serializeReply, isBlockingQuestion, ASK_USER_INPUT_SCHEMA, MAX_QUESTIONS, MAX_QUESTION_OPTIONS, MIN_QUESTION_OPTIONS, QUESTION_PROMPT_MAX_CHARS, OPTION_DESCRIPTION_MAX_CHARS, } from './questions';
|
|
34
38
|
export { STARTER_COUNT, pickStarters, namedStarter, hashString, mulberry32, } from './starters';
|
|
35
39
|
export { greetingFor, readGreeting, serverGreeting, subscribeClock, DEFAULT_GREETING_COPY, type GreetingCopy, } from './greeting';
|
|
36
|
-
export { CHAT_PLACEMENTS, chatPlacement, DOCK_MIN_WIDTH, DOCK_MAX_WIDTH, FLOAT_MAX_SCALE, FLOAT_EDGE_GAP, dockWidthFromDrag, isFloatDragStart, clampFloatPosition, type ChatPlacement, type ChatSide, } from './placement';
|
|
40
|
+
export { CHAT_PLACEMENTS, chatPlacement, DOCK_MIN_WIDTH, DOCK_MAX_WIDTH, DOCK_PAGE_MIN_WIDTH, dockFits, FLOAT_MAX_SCALE, FLOAT_EDGE_GAP, dockWidthFromDrag, isFloatDragStart, clampFloatPosition, type ChatPlacement, type ChatSide, } from './placement';
|
|
37
41
|
export { artifactCard, cardArtifact } from './artifacts';
|
|
38
42
|
export { ARTIFACT_CARD_KIND, CHAT_EVENT_KINDS, type ChatArtifact, type ChatCard, type ChatEvent, type ChatQuestion, type ChatQuestionAnswer, type ChatQuestionSet, type ChatReply, type ChatTransport, type ChatTransportMessage, type ChatTurn, type ChatModelOption, type ChatFeedbackVerdict, type LivePhase, type LiveResponse, type Starter, } from './types';
|
|
39
43
|
export { chatWidget, chatWidgetRegistry, WIDGET_COUNT, type ChatWidgetMeta } from './registry';
|
package/chat/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { ChatProvider } from "./ChatProvider.js";
|
|
2
2
|
import { ChatWidget } from "./ChatWidget.js";
|
|
3
|
+
import { CHAT_SOURCE_ATTRIBUTE, HELD_HIGHLIGHT_NAME, describeSelection, readSelection, useHeldHighlight, useSelectionFocus } from "./selection.js";
|
|
4
|
+
import { DEFAULT_SELECTION_LIMITS, sanitiseSelection, selectionLines } from "./selectionContext.js";
|
|
5
|
+
import { useGeneratedStarters } from "./generatedStarters.js";
|
|
6
|
+
import { confirmationLine, createConfirmationMark, defineAction, planAction, sanitiseConfirmation, skippedText } from "./actions.js";
|
|
3
7
|
import { CHAT_PANEL_ID, ChatLauncher } from "./ChatLauncher.js";
|
|
4
8
|
import { useChatAgentState } from "./agentState.js";
|
|
5
9
|
import { ChatThreads } from "./ChatThreads.js";
|
|
@@ -8,7 +12,7 @@ import { ChatAgentPane } from "./ChatAgentPane.js";
|
|
|
8
12
|
import { ChatArtifactPane } from "./ChatArtifactPane.js";
|
|
9
13
|
import { ChatArtifactCard } from "./ChatArtifactCard.js";
|
|
10
14
|
import { createFeedbackPoster, isInternalPath, useChatWidget } from "./context.js";
|
|
11
|
-
import { ARTIFACT_MIN_COLUMN_WIDTH, ASIDE_RAIL_MIN_WIDTH, ASIDE_WITH_THREADS_MIN_WIDTH, DOCK_QUERY, TAKEOVER_QUERY, THREADS_RAIL_MIN_WIDTH, useTakeoverViewport } from "./queries.js";
|
|
15
|
+
import { ARTIFACT_MIN_COLUMN_WIDTH, ASIDE_RAIL_MIN_WIDTH, ASIDE_WITH_THREADS_MIN_WIDTH, DOCK_QUERY, TAKEOVER_QUERY, THREADS_RAIL_MIN_WIDTH, useDockViewport, useTakeoverViewport } from "./queries.js";
|
|
12
16
|
import { DEFAULT_PLACEHOLDER_COPY, useChat } from "./useChat.js";
|
|
13
17
|
import { THREAD_NAMING_DELAY_MS, useThreads } from "./threads.js";
|
|
14
18
|
import { DEFAULT_FETCH_COPY, FIRST_BYTE_TIMEOUT_MS, MAX_TRANSPORT_TURNS, createFetchTransport } from "./transport.js";
|
|
@@ -18,7 +22,7 @@ import { SUGGESTION_MAX_CHARS, fitsChip } from "./suggestions.js";
|
|
|
18
22
|
import { ASK_USER_INPUT_SCHEMA, MAX_QUESTIONS, MAX_QUESTION_OPTIONS, MIN_QUESTION_OPTIONS, OPTION_DESCRIPTION_MAX_CHARS, QUESTION_PROMPT_MAX_CHARS, describeAnswers, isBlockingQuestion, sanitizeQuestionSet, serializeReply } from "./questions.js";
|
|
19
23
|
import { STARTER_COUNT, hashString, mulberry32, namedStarter, pickStarters } from "./starters.js";
|
|
20
24
|
import { DEFAULT_GREETING_COPY, greetingFor, readGreeting, serverGreeting, subscribeClock } from "./greeting.js";
|
|
21
|
-
import { CHAT_PLACEMENTS, DOCK_MAX_WIDTH, DOCK_MIN_WIDTH, FLOAT_EDGE_GAP, FLOAT_MAX_SCALE, chatPlacement, clampFloatPosition, dockWidthFromDrag, isFloatDragStart } from "./placement.js";
|
|
25
|
+
import { CHAT_PLACEMENTS, DOCK_MAX_WIDTH, DOCK_MIN_WIDTH, DOCK_PAGE_MIN_WIDTH, FLOAT_EDGE_GAP, FLOAT_MAX_SCALE, chatPlacement, clampFloatPosition, dockFits, dockWidthFromDrag, isFloatDragStart } from "./placement.js";
|
|
22
26
|
import { artifactCard, cardArtifact } from "./artifacts.js";
|
|
23
27
|
import { ARTIFACT_CARD_KIND, CHAT_EVENT_KINDS } from "./types.js";
|
|
24
28
|
import { WIDGET_COUNT, chatWidget, chatWidgetRegistry } from "./registry.js";
|
|
@@ -31,6 +35,7 @@ export {
|
|
|
31
35
|
CHAT_EVENT_KINDS,
|
|
32
36
|
CHAT_PANEL_ID,
|
|
33
37
|
CHAT_PLACEMENTS,
|
|
38
|
+
CHAT_SOURCE_ATTRIBUTE,
|
|
34
39
|
ChatAgentPane,
|
|
35
40
|
ChatArtifactCard,
|
|
36
41
|
ChatArtifactPane,
|
|
@@ -44,14 +49,17 @@ export {
|
|
|
44
49
|
DEFAULT_FETCH_COPY,
|
|
45
50
|
DEFAULT_GREETING_COPY,
|
|
46
51
|
DEFAULT_PLACEHOLDER_COPY,
|
|
52
|
+
DEFAULT_SELECTION_LIMITS,
|
|
47
53
|
DEFAULT_SIM_TIMING,
|
|
48
54
|
DOCK_MAX_WIDTH,
|
|
49
55
|
DOCK_MIN_WIDTH,
|
|
56
|
+
DOCK_PAGE_MIN_WIDTH,
|
|
50
57
|
DOCK_QUERY,
|
|
51
58
|
FIRST_BYTE_TIMEOUT_MS,
|
|
52
59
|
FLOAT_EDGE_GAP,
|
|
53
60
|
FLOAT_MAX_SCALE,
|
|
54
61
|
FOLLOWUPS_TIMEOUT_MS,
|
|
62
|
+
HELD_HIGHLIGHT_NAME,
|
|
55
63
|
MAX_FOLLOWUPS,
|
|
56
64
|
MAX_QUESTIONS,
|
|
57
65
|
MAX_QUESTION_OPTIONS,
|
|
@@ -71,12 +79,17 @@ export {
|
|
|
71
79
|
chatWidget,
|
|
72
80
|
chatWidgetRegistry,
|
|
73
81
|
clampFloatPosition,
|
|
82
|
+
confirmationLine,
|
|
83
|
+
createConfirmationMark,
|
|
74
84
|
createFeedbackPoster,
|
|
75
85
|
createFetchTransport,
|
|
76
86
|
createFollowupsFetcher,
|
|
77
87
|
createSimTransport,
|
|
78
88
|
defaultFilesReply,
|
|
89
|
+
defineAction,
|
|
79
90
|
describeAnswers,
|
|
91
|
+
describeSelection,
|
|
92
|
+
dockFits,
|
|
80
93
|
dockWidthFromDrag,
|
|
81
94
|
fitsChip,
|
|
82
95
|
followupTarget,
|
|
@@ -89,15 +102,25 @@ export {
|
|
|
89
102
|
namedStarter,
|
|
90
103
|
pickFallbackFollowups,
|
|
91
104
|
pickStarters,
|
|
105
|
+
planAction,
|
|
92
106
|
readGreeting,
|
|
107
|
+
readSelection,
|
|
108
|
+
sanitiseConfirmation,
|
|
109
|
+
sanitiseSelection,
|
|
93
110
|
sanitizeQuestionSet,
|
|
94
111
|
scriptChat,
|
|
112
|
+
selectionLines,
|
|
95
113
|
serializeReply,
|
|
96
114
|
serverGreeting,
|
|
115
|
+
skippedText,
|
|
97
116
|
subscribeClock,
|
|
98
117
|
useChat,
|
|
99
118
|
useChatAgentState,
|
|
100
119
|
useChatWidget,
|
|
120
|
+
useDockViewport,
|
|
121
|
+
useGeneratedStarters,
|
|
122
|
+
useHeldHighlight,
|
|
123
|
+
useSelectionFocus,
|
|
101
124
|
useTakeoverViewport,
|
|
102
125
|
useThreads
|
|
103
126
|
};
|
package/chat/placement.d.ts
CHANGED
|
@@ -25,6 +25,15 @@ export declare const chatPlacement: (id: ChatPlacement) => {
|
|
|
25
25
|
};
|
|
26
26
|
export declare const DOCK_MIN_WIDTH = 420;
|
|
27
27
|
export declare const DOCK_MAX_WIDTH = 655;
|
|
28
|
+
/** The page room the dock threshold promises: the narrowest viewport that
|
|
29
|
+
docks (the step plus the one pixel `mediaAbove` adds) less the panel's
|
|
30
|
+
resting width. */
|
|
31
|
+
export declare const DOCK_PAGE_MIN_WIDTH: number;
|
|
32
|
+
/** Whether a panel of this width docks in a viewport this wide: only while
|
|
33
|
+
the page keeps the room the dock threshold promises. A panel widened, or
|
|
34
|
+
a window narrowed, past it overlays instead, the rule below the dock
|
|
35
|
+
threshold. */
|
|
36
|
+
export declare function dockFits(viewportWidth: number, panelWidth: number): boolean;
|
|
28
37
|
/** A docked panel's width after a grip drag: the inner edge is the one
|
|
29
38
|
that moves, and it faces the other way on the left dock. */
|
|
30
39
|
export declare function dockWidthFromDrag(startWidth: number, pointerDelta: number, side: ChatSide): number;
|
package/chat/placement.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BREAKPOINT_CHAT_DOCK_PX } from "../tokens/breakpoints.js";
|
|
1
2
|
const CHAT_PLACEMENTS = [
|
|
2
3
|
{ id: "right", label: "Dock right", icon: "dock_to_left" },
|
|
3
4
|
{ id: "left", label: "Dock left", icon: "dock_to_right" },
|
|
@@ -6,6 +7,10 @@ const CHAT_PLACEMENTS = [
|
|
|
6
7
|
const chatPlacement = (id) => CHAT_PLACEMENTS.find((placement) => placement.id === id) ?? CHAT_PLACEMENTS[0];
|
|
7
8
|
const DOCK_MIN_WIDTH = 420;
|
|
8
9
|
const DOCK_MAX_WIDTH = 655;
|
|
10
|
+
const DOCK_PAGE_MIN_WIDTH = BREAKPOINT_CHAT_DOCK_PX + 1 - DOCK_MIN_WIDTH;
|
|
11
|
+
function dockFits(viewportWidth, panelWidth) {
|
|
12
|
+
return viewportWidth - panelWidth >= DOCK_PAGE_MIN_WIDTH;
|
|
13
|
+
}
|
|
9
14
|
function dockWidthFromDrag(startWidth, pointerDelta, side) {
|
|
10
15
|
const grown = startWidth + (side === "left" ? pointerDelta : -pointerDelta);
|
|
11
16
|
return Math.round(Math.min(DOCK_MAX_WIDTH, Math.max(DOCK_MIN_WIDTH, grown)));
|
|
@@ -30,10 +35,12 @@ export {
|
|
|
30
35
|
CHAT_PLACEMENTS,
|
|
31
36
|
DOCK_MAX_WIDTH,
|
|
32
37
|
DOCK_MIN_WIDTH,
|
|
38
|
+
DOCK_PAGE_MIN_WIDTH,
|
|
33
39
|
FLOAT_EDGE_GAP,
|
|
34
40
|
FLOAT_MAX_SCALE,
|
|
35
41
|
chatPlacement,
|
|
36
42
|
clampFloatPosition,
|
|
43
|
+
dockFits,
|
|
37
44
|
dockWidthFromDrag,
|
|
38
45
|
isFloatDragStart
|
|
39
46
|
};
|
package/chat/queries.d.ts
CHANGED
|
@@ -16,3 +16,9 @@ export declare const ARTIFACT_MIN_COLUMN_WIDTH = 320;
|
|
|
16
16
|
server and for the first client render. Shared by the launcher and any
|
|
17
17
|
host stage, which both hand the widget its phone layout. */
|
|
18
18
|
export declare function useTakeoverViewport(): boolean;
|
|
19
|
+
/** Whether a chat panel docks beside the page now: above the dock threshold
|
|
20
|
+
and only while the page keeps the room that threshold promises, so a
|
|
21
|
+
panel widened past it overlays instead. False on the server and for the
|
|
22
|
+
first client render. Shared by the launcher and any host that reserves
|
|
23
|
+
the docked panel's room. */
|
|
24
|
+
export declare function useDockViewport(): boolean;
|
package/chat/queries.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useSyncExternalStore } from "react";
|
|
3
3
|
import { mediaAbove, mediaBelow, BREAKPOINT_CHAT_TAKEOVER_PX, BREAKPOINT_CHAT_DOCK_PX } from "../tokens/breakpoints.js";
|
|
4
|
+
import { DOCK_MIN_WIDTH, dockFits } from "./placement.js";
|
|
4
5
|
const DOCK_QUERY = mediaAbove(BREAKPOINT_CHAT_DOCK_PX);
|
|
5
6
|
const TAKEOVER_QUERY = mediaBelow(BREAKPOINT_CHAT_TAKEOVER_PX);
|
|
6
7
|
const THREADS_RAIL_MIN_WIDTH = 720;
|
|
@@ -16,6 +17,29 @@ const readTakeover = () => window.matchMedia(TAKEOVER_QUERY).matches;
|
|
|
16
17
|
function useTakeoverViewport() {
|
|
17
18
|
return useSyncExternalStore(subscribeTakeover, readTakeover, () => false);
|
|
18
19
|
}
|
|
20
|
+
let lastDockFit = false;
|
|
21
|
+
const readDockFit = () => {
|
|
22
|
+
const root = document.documentElement;
|
|
23
|
+
if (root.hasAttribute("data-chat-resizing")) return lastDockFit;
|
|
24
|
+
const width = parseFloat(root.style.getPropertyValue("--ds-chat-width")) || DOCK_MIN_WIDTH;
|
|
25
|
+
lastDockFit = window.matchMedia(DOCK_QUERY).matches && dockFits(window.innerWidth, width);
|
|
26
|
+
return lastDockFit;
|
|
27
|
+
};
|
|
28
|
+
const subscribeDockFit = (onChange) => {
|
|
29
|
+
window.addEventListener("resize", onChange);
|
|
30
|
+
const observer = new MutationObserver(onChange);
|
|
31
|
+
observer.observe(document.documentElement, {
|
|
32
|
+
attributes: true,
|
|
33
|
+
attributeFilter: ["style", "data-chat-resizing"]
|
|
34
|
+
});
|
|
35
|
+
return () => {
|
|
36
|
+
window.removeEventListener("resize", onChange);
|
|
37
|
+
observer.disconnect();
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
function useDockViewport() {
|
|
41
|
+
return useSyncExternalStore(subscribeDockFit, readDockFit, () => false);
|
|
42
|
+
}
|
|
19
43
|
export {
|
|
20
44
|
ARTIFACT_MIN_COLUMN_WIDTH,
|
|
21
45
|
ASIDE_RAIL_MIN_WIDTH,
|
|
@@ -23,5 +47,6 @@ export {
|
|
|
23
47
|
DOCK_QUERY,
|
|
24
48
|
TAKEOVER_QUERY,
|
|
25
49
|
THREADS_RAIL_MIN_WIDTH,
|
|
50
|
+
useDockViewport,
|
|
26
51
|
useTakeoverViewport
|
|
27
52
|
};
|
package/chat/questions.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ export declare const ASK_USER_INPUT_SCHEMA: {
|
|
|
66
66
|
readonly properties: {
|
|
67
67
|
readonly label: {
|
|
68
68
|
readonly type: "string";
|
|
69
|
-
readonly description: "The answer as the person would say it, at most
|
|
69
|
+
readonly description: "The answer as the person would say it, at most 30 characters, a month or weekday written short (\"Oct\").";
|
|
70
70
|
};
|
|
71
71
|
readonly description: {
|
|
72
72
|
readonly type: "string";
|
package/chat/questions.js
CHANGED
|
@@ -103,7 +103,7 @@ const ASK_USER_INPUT_SCHEMA = {
|
|
|
103
103
|
properties: {
|
|
104
104
|
label: {
|
|
105
105
|
type: "string",
|
|
106
|
-
description: `The answer as the person would say it, at most ${SUGGESTION_MAX_CHARS} characters.`
|
|
106
|
+
description: `The answer as the person would say it, at most ${SUGGESTION_MAX_CHARS} characters, a month or weekday written short ("Oct").`
|
|
107
107
|
},
|
|
108
108
|
description: {
|
|
109
109
|
type: "string",
|
package/chat/registry.json.d.ts
CHANGED
|
@@ -9,8 +9,9 @@ declare const _default: {
|
|
|
9
9
|
"description": "The whole AI chat: the panel, the streaming replies, the history, the cards and questions a reply can carry and the server handlers, set up with props.",
|
|
10
10
|
"command": "init chat",
|
|
11
11
|
"subpaths": {
|
|
12
|
-
"./chat": "The widget, the provider, the launcher and the engine under them.",
|
|
13
|
-
"./chat/server": "The streaming chat handler, with an opt-in tool for asking the visitor questions,
|
|
12
|
+
"./chat": "The widget, the provider, the launcher and the engine under them, with the hooks that let it follow the reader and write starters for what they picked.",
|
|
13
|
+
"./chat/server": "The streaming chat handler, with an opt-in tool for asking the visitor questions, its follow-ups, starters and feedback siblings, and the checks for what a reader highlighted, for any web-standard route.",
|
|
14
|
+
"./chat/actions": "The action definitions a page and its route share, their dry run and the mark that says a change was confirmed on its card, with no dependencies.",
|
|
14
15
|
"./chat/upstash": "Rate limits, a daily budget and the exchange log over Upstash Redis, as the handlers' guardrails.",
|
|
15
16
|
"./chat/demo": "A scripted conversation with rich cards and fixtures, for a preview that needs no key.",
|
|
16
17
|
"./chat/chat.css": "The widget's stylesheet."
|
|
@@ -45,6 +46,7 @@ declare const _default: {
|
|
|
45
46
|
"CircularButton",
|
|
46
47
|
"CodeBlock",
|
|
47
48
|
"Composer",
|
|
49
|
+
"DocumentChip",
|
|
48
50
|
"DropdownMenu",
|
|
49
51
|
"EmptyState",
|
|
50
52
|
"Mention",
|