@surfaces-ui/chat 0.0.0-stage → 0.2.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.
Files changed (61) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +4 -0
  3. package/README.md +40 -2
  4. package/dist/AnalyticsChat.d.ts +82 -0
  5. package/dist/AnalyticsChat.js +168 -0
  6. package/dist/AnalyticsChat.js.map +1 -0
  7. package/dist/Approval.d.ts +18 -0
  8. package/dist/Approval.js +116 -0
  9. package/dist/Approval.js.map +1 -0
  10. package/dist/Chat.d.ts +112 -0
  11. package/dist/Chat.js +119 -0
  12. package/dist/Chat.js.map +1 -0
  13. package/dist/ChatComposer.d.ts +117 -0
  14. package/dist/ChatComposer.js +186 -0
  15. package/dist/ChatComposer.js.map +1 -0
  16. package/dist/ChatPanels.d.ts +34 -0
  17. package/dist/ChatPanels.js +75 -0
  18. package/dist/ChatPanels.js.map +1 -0
  19. package/dist/DataPanel.d.ts +19 -0
  20. package/dist/DataPanel.js +20 -0
  21. package/dist/DataPanel.js.map +1 -0
  22. package/dist/Menu.d.ts +37 -0
  23. package/dist/Menu.js +85 -0
  24. package/dist/Menu.js.map +1 -0
  25. package/dist/PageStudio.d.ts +103 -0
  26. package/dist/PageStudio.js +166 -0
  27. package/dist/PageStudio.js.map +1 -0
  28. package/dist/SessionList.d.ts +64 -0
  29. package/dist/SessionList.js +225 -0
  30. package/dist/SessionList.js.map +1 -0
  31. package/dist/appComponents.d.ts +6 -0
  32. package/dist/appComponents.js +100 -0
  33. package/dist/appComponents.js.map +1 -0
  34. package/dist/conversation.d.ts +66 -0
  35. package/dist/conversation.js +119 -0
  36. package/dist/conversation.js.map +1 -0
  37. package/dist/icons.d.ts +33 -0
  38. package/dist/icons.js +34 -0
  39. package/dist/icons.js.map +1 -0
  40. package/dist/index.d.ts +18 -0
  41. package/dist/index.js +19 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/selectors.d.ts +106 -0
  44. package/dist/selectors.js +160 -0
  45. package/dist/selectors.js.map +1 -0
  46. package/dist/sessions.d.ts +71 -0
  47. package/dist/sessions.js +194 -0
  48. package/dist/sessions.js.map +1 -0
  49. package/dist/speech.d.ts +43 -0
  50. package/dist/speech.js +89 -0
  51. package/dist/speech.js.map +1 -0
  52. package/dist/thread.d.ts +199 -0
  53. package/dist/thread.js +225 -0
  54. package/dist/thread.js.map +1 -0
  55. package/dist/useChat.d.ts +121 -0
  56. package/dist/useChat.js +293 -0
  57. package/dist/useChat.js.map +1 -0
  58. package/dist/voice.d.ts +41 -0
  59. package/dist/voice.js +128 -0
  60. package/dist/voice.js.map +1 -0
  61. package/package.json +71 -3
@@ -0,0 +1,199 @@
1
+ import type { AgentEvent } from "@surfaces-ui/agent";
2
+ import type { JsonObject } from "@bufbuild/protobuf";
3
+ import { type Catalog, type Surfaces } from "@surfaces-ui/spec";
4
+ import type { DataRef } from "@surfaces-ui/components";
5
+ export interface ChatStep {
6
+ id: string;
7
+ title: string;
8
+ status: "running" | "done" | "failed";
9
+ tool: string;
10
+ /** More to show when opened: the SQL run, an error message. */
11
+ detail: string;
12
+ durationMs: number;
13
+ }
14
+ export interface ChatApproval {
15
+ id: string;
16
+ kind: "permission" | "choice" | "input";
17
+ title: string;
18
+ detail: string;
19
+ /** SQL the agent wants to run, when that is what needs approval. */
20
+ sql: string;
21
+ options: string[];
22
+ /** What exactly is being approved, shown as JSON. */
23
+ subject?: JsonObject;
24
+ /** "sha256:…" of `{ sql, subject }`; the card refuses to offer approval when it does not match. */
25
+ digest: string;
26
+ /** ISO time after which it cannot be approved. Empty for no limit. */
27
+ expiresAt: string;
28
+ risk: "low" | "high" | "irreversible" | "";
29
+ /** The person may change the SQL or subject before approving. */
30
+ editable: boolean;
31
+ reasonRequired: boolean;
32
+ /** Different people who must allow it. */
33
+ approvalsRequired: number;
34
+ /** Decisions already made, when several people must decide. */
35
+ approvals: ChatDecision[];
36
+ /** What the request was based on, for the person to see. */
37
+ basis: string;
38
+ /** Set once the person has answered. */
39
+ answer?: ChatApprovalAnswer;
40
+ }
41
+ /** Who decided, as the host identified them. */
42
+ export interface ChatActor {
43
+ id: string;
44
+ name: string;
45
+ }
46
+ export interface ChatDecision {
47
+ by?: ChatActor;
48
+ /** ISO time. */
49
+ at: string;
50
+ allow: boolean;
51
+ reason: string;
52
+ }
53
+ export interface ChatApprovalAnswer extends ChatDecision {
54
+ /** The chosen option or typed answer. */
55
+ text: string;
56
+ /** "sha256:…" of what was approved, edits included. */
57
+ digest: string;
58
+ editedSql?: string;
59
+ editedSubject?: JsonObject;
60
+ }
61
+ /** One button in an actions part. What a press does is the host's to decide. */
62
+ export interface ChatButton {
63
+ /** Reaches the host with the press; need only be unique within its row. */
64
+ id: string;
65
+ label: string;
66
+ /** "primary" for the one thing most people will do; "danger" for what cannot be taken back. */
67
+ variant?: "primary" | "danger";
68
+ /** Shown but cannot be pressed. It stays reachable by keyboard so its reason can be read. */
69
+ disabled?: boolean;
70
+ /** Why it cannot be pressed (or, when it can, what it does). Its tooltip, and read with it. */
71
+ reason?: string;
72
+ /** A fuller name when the label alone is ambiguous: "Apply “Bold” from the chat". */
73
+ ariaLabel?: string;
74
+ }
75
+ /** One of several alternatives in an actions part, with buttons of its own. */
76
+ export interface ChatChoice {
77
+ id: string;
78
+ title: string;
79
+ detail?: string;
80
+ buttons: ChatButton[];
81
+ }
82
+ /**
83
+ * What a person can do about a reply, drawn under it: one set of buttons
84
+ * ("Show on the page", "Discard", "Apply"), or several alternatives one row
85
+ * each with buttons for the whole set after them ("Discard all"). Presses go
86
+ * to `MessageList`'s `onPartAction`. Once handled, the host sets `outcome`,
87
+ * which replaces every button.
88
+ */
89
+ export interface ChatActions {
90
+ id: string;
91
+ title?: string;
92
+ detail?: string;
93
+ /** Alternatives to choose between, one row each. */
94
+ choices?: ChatChoice[];
95
+ /** Buttons for the whole set, after any choices. */
96
+ buttons?: ChatButton[];
97
+ /** What became of it ("Applied.", "Discarded."). Replaces the buttons. */
98
+ outcome?: string;
99
+ }
100
+ /** One piece of a reply, in the order it arrived. */
101
+ export type ChatPart = {
102
+ kind: "text";
103
+ text: string;
104
+ }
105
+ /** Tables and columns a person attached to their message, by name. */
106
+ | {
107
+ kind: "references";
108
+ references: DataRef[];
109
+ } | {
110
+ kind: "steps";
111
+ steps: ChatStep[];
112
+ }
113
+ /** A component the agent drew. `surfaceId` is the key into `ChatThread.surfaces`. */
114
+ | {
115
+ kind: "surface";
116
+ surfaceId: string;
117
+ } | {
118
+ kind: "approval";
119
+ approval: ChatApproval;
120
+ }
121
+ /** Buttons the host offers under a reply. Added by the host, never by an agent's events. */
122
+ | {
123
+ kind: "actions";
124
+ actions: ChatActions;
125
+ } | {
126
+ kind: "error";
127
+ code: string;
128
+ message: string;
129
+ };
130
+ export interface ChatMessage {
131
+ id: number;
132
+ role: "user" | "assistant";
133
+ parts: ChatPart[];
134
+ /** The model or agent that answered. Always shown. */
135
+ generatedBy: string;
136
+ streaming: boolean;
137
+ }
138
+ export interface ChatUsage {
139
+ inputTokens: number;
140
+ outputTokens: number;
141
+ contextTokens: number;
142
+ contextLimit: number;
143
+ costUsd?: number;
144
+ }
145
+ export interface ChatThread {
146
+ messages: ChatMessage[];
147
+ /** Agent-drawn surfaces, keyed by message and the agent's own surface ID. */
148
+ surfaces: Surfaces;
149
+ /** "waiting" means the agent paused for the person's answer. */
150
+ status: "idle" | "streaming" | "waiting";
151
+ sessionId: string;
152
+ usage?: ChatUsage;
153
+ /** Things the person might say next. */
154
+ suggestions: string[];
155
+ }
156
+ export type ChatAction = {
157
+ type: "user";
158
+ text: string;
159
+ references?: DataRef[];
160
+ }
161
+ /** A turn has started; the reply is added to the latest assistant message when `resume` is set. */
162
+ | {
163
+ type: "begin";
164
+ resume?: boolean;
165
+ } | {
166
+ type: "event";
167
+ event: AgentEvent;
168
+ } | {
169
+ type: "answered";
170
+ id: string;
171
+ answer: ChatApprovalAnswer;
172
+ } | {
173
+ type: "end";
174
+ } | {
175
+ type: "reset";
176
+ }
177
+ /** Replaces the thread with one loaded from storage (checked with `parseThread` first). */
178
+ | {
179
+ type: "restore";
180
+ thread: ChatThread;
181
+ };
182
+ export declare const emptyThread: ChatThread;
183
+ /** The key a message's surface is stored under, so two replies can both use "main". */
184
+ export declare const surfaceKey: (messageId: number, surfaceId: string) => string;
185
+ /** The agent's own ID for a stored surface, to send back with an action. */
186
+ export declare const agentSurfaceId: (key: string) => string;
187
+ /**
188
+ * Folds user input and agent events into a thread. Pure: the same actions
189
+ * always give the same thread, so a conversation can be replayed in tests.
190
+ */
191
+ export declare function reduceThread(thread: ChatThread, action: ChatAction, catalog: Catalog): ChatThread;
192
+ /**
193
+ * Checks a thread loaded from storage before it is used, since anyone with
194
+ * access to the storage can edit it. Returns undefined for anything that is
195
+ * not a thread. A reply that was still streaming when the page closed is
196
+ * marked as cut off; an approval nobody answered is still waiting. Surfaces
197
+ * are checked against the catalog again when they are drawn.
198
+ */
199
+ export declare function parseThread(input: unknown): ChatThread | undefined;
package/dist/thread.js ADDED
@@ -0,0 +1,225 @@
1
+ import { ApprovalKind, ApprovalRisk, StepStatus } from "@surfaces-ui/proto";
2
+ import { applyMessage, isComponentIssue, upgradeMessage, upgradeSurface } from "@surfaces-ui/spec";
3
+ export const emptyThread = { messages: [], surfaces: {}, status: "idle", sessionId: "", suggestions: [] };
4
+ const STEP_STATUS = {
5
+ [StepStatus.RUNNING]: "running",
6
+ [StepStatus.DONE]: "done",
7
+ [StepStatus.FAILED]: "failed",
8
+ };
9
+ const APPROVAL_KIND = {
10
+ [ApprovalKind.PERMISSION]: "permission",
11
+ [ApprovalKind.CHOICE]: "choice",
12
+ [ApprovalKind.INPUT]: "input",
13
+ };
14
+ const APPROVAL_RISK = {
15
+ [ApprovalRisk.LOW]: "low",
16
+ [ApprovalRisk.HIGH]: "high",
17
+ [ApprovalRisk.IRREVERSIBLE]: "irreversible",
18
+ };
19
+ const SCOPE = ":";
20
+ /** The key a message's surface is stored under, so two replies can both use "main". */
21
+ export const surfaceKey = (messageId, surfaceId) => `m${messageId}${SCOPE}${surfaceId}`;
22
+ /** The agent's own ID for a stored surface, to send back with an action. */
23
+ export const agentSurfaceId = (key) => key.slice(key.indexOf(SCOPE) + 1);
24
+ function updateLast(thread, change) {
25
+ const index = thread.messages.findLastIndex((m) => m.role === "assistant");
26
+ if (index < 0)
27
+ return thread;
28
+ return { ...thread, messages: thread.messages.map((m, i) => (i === index ? change(m) : m)) };
29
+ }
30
+ function withPart(message, part) {
31
+ return { ...message, parts: [...message.parts, part] };
32
+ }
33
+ function applySurface(thread, raw, catalog) {
34
+ const message = thread.messages.findLast((m) => m.role === "assistant");
35
+ if (!message)
36
+ return thread;
37
+ const fail = (text) => updateLast(thread, (m) => withPart(m, { kind: "error", code: "INVALID_SURFACE", message: text }));
38
+ // A malformed envelope is refused; a malformed component is applied and reported where it is drawn.
39
+ const fatal = catalog.validateMessage(raw).filter((issue) => !isComponentIssue(issue));
40
+ if (fatal.length > 0)
41
+ return fail(`The agent sent a view this page cannot draw: ${fatal[0].path} ${fatal[0].message}`);
42
+ // What is kept is in the current version, whichever the agent wrote.
43
+ const record = upgradeMessage(raw);
44
+ const kind = ["createSurface", "updateComponents", "updateDataModel", "deleteSurface"].find((k) => record[k]);
45
+ if (!kind)
46
+ return thread;
47
+ const key = surfaceKey(message.id, record[kind].surfaceId);
48
+ const scoped = { ...record, [kind]: { ...record[kind], surfaceId: key } };
49
+ try {
50
+ const surfaces = applyMessage(thread.surfaces, scoped);
51
+ const shown = message.parts.some((p) => p.kind === "surface" && p.surfaceId === key);
52
+ const next = { ...thread, surfaces };
53
+ return kind === "createSurface" && !shown ? updateLast(next, (m) => withPart(m, { kind: "surface", surfaceId: key })) : next;
54
+ }
55
+ catch (error) {
56
+ return fail(error instanceof Error ? error.message : String(error));
57
+ }
58
+ }
59
+ /**
60
+ * Folds user input and agent events into a thread. Pure: the same actions
61
+ * always give the same thread, so a conversation can be replayed in tests.
62
+ */
63
+ export function reduceThread(thread, action, catalog) {
64
+ const nextId = (thread.messages.at(-1)?.id ?? 0) + 1;
65
+ switch (action.type) {
66
+ case "reset":
67
+ return emptyThread;
68
+ case "restore":
69
+ return action.thread;
70
+ case "user":
71
+ return {
72
+ ...thread,
73
+ suggestions: [],
74
+ messages: [
75
+ ...thread.messages,
76
+ { id: nextId, role: "user", parts: [{ kind: "text", text: action.text }, ...(action.references?.length ? [{ kind: "references", references: action.references }] : [])], generatedBy: "", streaming: false },
77
+ ],
78
+ };
79
+ case "begin": {
80
+ const last = thread.messages.at(-1);
81
+ if (action.resume && last?.role === "assistant") {
82
+ return { ...updateLast(thread, (m) => ({ ...m, streaming: true })), status: "streaming", suggestions: [] };
83
+ }
84
+ return {
85
+ ...thread,
86
+ status: "streaming",
87
+ suggestions: [],
88
+ messages: [...thread.messages, { id: nextId, role: "assistant", parts: [], generatedBy: "", streaming: true }],
89
+ };
90
+ }
91
+ case "answered":
92
+ return {
93
+ ...thread,
94
+ messages: thread.messages.map((m) => ({
95
+ ...m,
96
+ parts: m.parts.map((p) => p.kind === "approval" && p.approval.id === action.id ? { ...p, approval: { ...p.approval, answer: action.answer } } : p),
97
+ })),
98
+ };
99
+ case "end": {
100
+ const waiting = thread.messages.at(-1)?.parts.some((p) => p.kind === "approval" && !p.approval.answer) ?? false;
101
+ return { ...updateLast(thread, (m) => ({ ...m, streaming: false })), status: waiting ? "waiting" : "idle" };
102
+ }
103
+ case "event": {
104
+ const event = action.event.event;
105
+ switch (event.case) {
106
+ case "text":
107
+ return updateLast(thread, (m) => {
108
+ const last = m.parts.at(-1);
109
+ if (last?.kind === "text")
110
+ return { ...m, parts: [...m.parts.slice(0, -1), { kind: "text", text: last.text + event.value.delta }] };
111
+ return withPart(m, { kind: "text", text: event.value.delta });
112
+ });
113
+ case "step": {
114
+ const step = {
115
+ id: event.value.id,
116
+ title: event.value.title,
117
+ status: STEP_STATUS[event.value.status] ?? "running",
118
+ tool: event.value.tool,
119
+ detail: event.value.detail,
120
+ durationMs: Number(event.value.durationMs),
121
+ };
122
+ return updateLast(thread, (m) => {
123
+ // An event for a step already shown updates it in place.
124
+ if (m.parts.some((p) => p.kind === "steps" && p.steps.some((s) => s.id === step.id))) {
125
+ return {
126
+ ...m,
127
+ parts: m.parts.map((p) => p.kind === "steps" ? { ...p, steps: p.steps.map((s) => (s.id === step.id ? { ...s, ...step, title: step.title || s.title, detail: step.detail || s.detail } : s)) } : p),
128
+ };
129
+ }
130
+ const last = m.parts.at(-1);
131
+ if (last?.kind === "steps")
132
+ return { ...m, parts: [...m.parts.slice(0, -1), { kind: "steps", steps: [...last.steps, step] }] };
133
+ return withPart(m, { kind: "steps", steps: [step] });
134
+ });
135
+ }
136
+ case "surface":
137
+ return applySurface(thread, event.value, catalog);
138
+ case "approval": {
139
+ const approval = {
140
+ id: event.value.id,
141
+ kind: APPROVAL_KIND[event.value.kind] ?? "permission",
142
+ title: event.value.title,
143
+ detail: event.value.detail,
144
+ sql: event.value.sql,
145
+ options: event.value.options,
146
+ ...(event.value.subject ? { subject: event.value.subject } : {}),
147
+ digest: event.value.digest,
148
+ expiresAt: event.value.expiresAt,
149
+ risk: APPROVAL_RISK[event.value.risk] ?? "",
150
+ editable: event.value.editable,
151
+ reasonRequired: event.value.reasonRequired,
152
+ approvalsRequired: Math.max(1, event.value.approvalsRequired),
153
+ approvals: event.value.approvals.map((r) => ({
154
+ ...(r.decidedBy ? { by: { id: r.decidedBy.id, name: r.decidedBy.name } } : {}),
155
+ at: r.decidedAt,
156
+ allow: r.allow,
157
+ reason: r.reason,
158
+ })),
159
+ basis: event.value.basis,
160
+ };
161
+ return updateLast(thread, (m) => withPart(m, { kind: "approval", approval }));
162
+ }
163
+ case "usage":
164
+ return {
165
+ ...thread,
166
+ usage: {
167
+ inputTokens: Number(event.value.inputTokens),
168
+ outputTokens: Number(event.value.outputTokens),
169
+ contextTokens: Number(event.value.contextTokens),
170
+ contextLimit: Number(event.value.contextLimit),
171
+ costUsd: event.value.costUsd,
172
+ },
173
+ };
174
+ case "suggestions":
175
+ return { ...thread, suggestions: event.value.items };
176
+ case "error":
177
+ return updateLast(thread, (m) => withPart(m, { kind: "error", code: event.value.code, message: event.value.message }));
178
+ case "done":
179
+ return { ...updateLast(thread, (m) => ({ ...m, generatedBy: event.value.generatedBy || m.generatedBy })), sessionId: event.value.sessionId || thread.sessionId };
180
+ default:
181
+ return thread;
182
+ }
183
+ }
184
+ }
185
+ }
186
+ const PART_KINDS = new Set(["text", "references", "steps", "surface", "approval", "actions", "error"]);
187
+ const isRecord = (value) => !!value && typeof value === "object" && !Array.isArray(value);
188
+ /**
189
+ * Checks a thread loaded from storage before it is used, since anyone with
190
+ * access to the storage can edit it. Returns undefined for anything that is
191
+ * not a thread. A reply that was still streaming when the page closed is
192
+ * marked as cut off; an approval nobody answered is still waiting. Surfaces
193
+ * are checked against the catalog again when they are drawn.
194
+ */
195
+ export function parseThread(input) {
196
+ if (!isRecord(input) || !Array.isArray(input.messages) || !isRecord(input.surfaces))
197
+ return undefined;
198
+ const messages = [];
199
+ for (const raw of input.messages) {
200
+ if (!isRecord(raw) || typeof raw.id !== "number" || (raw.role !== "user" && raw.role !== "assistant") || !Array.isArray(raw.parts))
201
+ return undefined;
202
+ if (!raw.parts.every((p) => isRecord(p) && PART_KINDS.has(p.kind)))
203
+ return undefined;
204
+ const parts = raw.parts;
205
+ const cut = raw.streaming === true;
206
+ messages.push({
207
+ id: raw.id,
208
+ role: raw.role,
209
+ parts: cut ? [...parts, { kind: "error", code: "INTERRUPTED", message: "This reply was cut off when the page closed." }] : parts,
210
+ generatedBy: typeof raw.generatedBy === "string" ? raw.generatedBy : "",
211
+ streaming: false,
212
+ });
213
+ }
214
+ const waiting = messages.at(-1)?.parts.some((p) => p.kind === "approval" && !p.approval.answer) ?? false;
215
+ return {
216
+ messages,
217
+ // A thread kept before the move to A2UI v1.0 holds surfaces written for v0.9.
218
+ surfaces: Object.fromEntries(Object.entries(input.surfaces).map(([key, surface]) => [key, isRecord(surface) && isRecord(surface.components) ? upgradeSurface(surface) : surface])),
219
+ status: waiting ? "waiting" : "idle",
220
+ sessionId: typeof input.sessionId === "string" ? input.sessionId : "",
221
+ ...(isRecord(input.usage) ? { usage: input.usage } : {}),
222
+ suggestions: Array.isArray(input.suggestions) ? input.suggestions.filter((s) => typeof s === "string") : [],
223
+ };
224
+ }
225
+ //# sourceMappingURL=thread.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thread.js","sourceRoot":"","sources":["../src/thread.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAoD,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AA+JrJ,MAAM,CAAC,MAAM,WAAW,GAAe,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;AAEtH,MAAM,WAAW,GAAoD;IACnE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,SAAS;IAC/B,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM;IACzB,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,QAAQ;CAC9B,CAAC;AACF,MAAM,aAAa,GAAwD;IACzE,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,YAAY;IACvC,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,QAAQ;IAC/B,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,OAAO;CAC9B,CAAC;AAEF,MAAM,aAAa,GAAwD;IACzE,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,KAAK;IACzB,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,MAAM;IAC3B,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,cAAc;CAC5C,CAAC;AAEF,MAAM,KAAK,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AC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;QACrE,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAA6B,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAChF,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE;KACzH,CAAC;AACJ,CAAC","sourcesContent":["import type { AgentEvent } from \"@surfaces-ui/agent\";\nimport type { JsonObject } from \"@bufbuild/protobuf\";\nimport { ApprovalKind, ApprovalRisk, StepStatus } from \"@surfaces-ui/proto\";\nimport { type Catalog, type SurfaceMessage, type Surfaces, applyMessage, isComponentIssue, upgradeMessage, upgradeSurface } from \"@surfaces-ui/spec\";\nimport type { DataRef } from \"@surfaces-ui/components\";\n\nexport interface ChatStep {\n id: string;\n title: string;\n status: \"running\" | \"done\" | \"failed\";\n tool: string;\n /** More to show when opened: the SQL run, an error message. */\n detail: string;\n durationMs: number;\n}\n\nexport interface ChatApproval {\n id: string;\n kind: \"permission\" | \"choice\" | \"input\";\n title: string;\n detail: string;\n /** SQL the agent wants to run, when that is what needs approval. */\n sql: string;\n options: string[];\n /** What exactly is being approved, shown as JSON. */\n subject?: JsonObject;\n /** \"sha256:…\" of `{ sql, subject }`; the card refuses to offer approval when it does not match. */\n digest: string;\n /** ISO time after which it cannot be approved. Empty for no limit. */\n expiresAt: string;\n risk: \"low\" | \"high\" | \"irreversible\" | \"\";\n /** The person may change the SQL or subject before approving. */\n editable: boolean;\n reasonRequired: boolean;\n /** Different people who must allow it. */\n approvalsRequired: number;\n /** Decisions already made, when several people must decide. */\n approvals: ChatDecision[];\n /** What the request was based on, for the person to see. */\n basis: string;\n /** Set once the person has answered. */\n answer?: ChatApprovalAnswer;\n}\n\n/** Who decided, as the host identified them. */\nexport interface ChatActor {\n id: string;\n name: string;\n}\n\nexport interface ChatDecision {\n by?: ChatActor;\n /** ISO time. */\n at: string;\n allow: boolean;\n reason: string;\n}\n\nexport interface ChatApprovalAnswer extends ChatDecision {\n /** The chosen option or typed answer. */\n text: string;\n /** \"sha256:…\" of what was approved, edits included. */\n digest: string;\n editedSql?: string;\n editedSubject?: JsonObject;\n}\n\n/** One button in an actions part. What a press does is the host's to decide. */\nexport interface ChatButton {\n /** Reaches the host with the press; need only be unique within its row. */\n id: string;\n label: string;\n /** \"primary\" for the one thing most people will do; \"danger\" for what cannot be taken back. */\n variant?: \"primary\" | \"danger\";\n /** Shown but cannot be pressed. It stays reachable by keyboard so its reason can be read. */\n disabled?: boolean;\n /** Why it cannot be pressed (or, when it can, what it does). Its tooltip, and read with it. */\n reason?: string;\n /** A fuller name when the label alone is ambiguous: \"Apply “Bold” from the chat\". */\n ariaLabel?: string;\n}\n\n/** One of several alternatives in an actions part, with buttons of its own. */\nexport interface ChatChoice {\n id: string;\n title: string;\n detail?: string;\n buttons: ChatButton[];\n}\n\n/**\n * What a person can do about a reply, drawn under it: one set of buttons\n * (\"Show on the page\", \"Discard\", \"Apply\"), or several alternatives one row\n * each with buttons for the whole set after them (\"Discard all\"). Presses go\n * to `MessageList`'s `onPartAction`. Once handled, the host sets `outcome`,\n * which replaces every button.\n */\nexport interface ChatActions {\n id: string;\n title?: string;\n detail?: string;\n /** Alternatives to choose between, one row each. */\n choices?: ChatChoice[];\n /** Buttons for the whole set, after any choices. */\n buttons?: ChatButton[];\n /** What became of it (\"Applied.\", \"Discarded.\"). Replaces the buttons. */\n outcome?: string;\n}\n\n/** One piece of a reply, in the order it arrived. */\nexport type ChatPart =\n | { kind: \"text\"; text: string }\n /** Tables and columns a person attached to their message, by name. */\n | { kind: \"references\"; references: DataRef[] }\n | { kind: \"steps\"; steps: ChatStep[] }\n /** A component the agent drew. `surfaceId` is the key into `ChatThread.surfaces`. */\n | { kind: \"surface\"; surfaceId: string }\n | { kind: \"approval\"; approval: ChatApproval }\n /** Buttons the host offers under a reply. Added by the host, never by an agent's events. */\n | { kind: \"actions\"; actions: ChatActions }\n | { kind: \"error\"; code: string; message: string };\n\nexport interface ChatMessage {\n id: number;\n role: \"user\" | \"assistant\";\n parts: ChatPart[];\n /** The model or agent that answered. Always shown. */\n generatedBy: string;\n streaming: boolean;\n}\n\nexport interface ChatUsage {\n inputTokens: number;\n outputTokens: number;\n contextTokens: number;\n contextLimit: number;\n costUsd?: number;\n}\n\nexport interface ChatThread {\n messages: ChatMessage[];\n /** Agent-drawn surfaces, keyed by message and the agent's own surface ID. */\n surfaces: Surfaces;\n /** \"waiting\" means the agent paused for the person's answer. */\n status: \"idle\" | \"streaming\" | \"waiting\";\n sessionId: string;\n usage?: ChatUsage;\n /** Things the person might say next. */\n suggestions: string[];\n}\n\nexport type ChatAction =\n | { type: \"user\"; text: string; references?: DataRef[] }\n /** A turn has started; the reply is added to the latest assistant message when `resume` is set. */\n | { type: \"begin\"; resume?: boolean }\n | { type: \"event\"; event: AgentEvent }\n | { type: \"answered\"; id: string; answer: ChatApprovalAnswer }\n | { type: \"end\" }\n | { type: \"reset\" }\n /** Replaces the thread with one loaded from storage (checked with `parseThread` first). */\n | { type: \"restore\"; thread: ChatThread };\n\nexport const emptyThread: ChatThread = { messages: [], surfaces: {}, status: \"idle\", sessionId: \"\", suggestions: [] };\n\nconst STEP_STATUS: Partial<Record<StepStatus, ChatStep[\"status\"]>> = {\n [StepStatus.RUNNING]: \"running\",\n [StepStatus.DONE]: \"done\",\n [StepStatus.FAILED]: \"failed\",\n};\nconst APPROVAL_KIND: Partial<Record<ApprovalKind, ChatApproval[\"kind\"]>> = {\n [ApprovalKind.PERMISSION]: \"permission\",\n [ApprovalKind.CHOICE]: \"choice\",\n [ApprovalKind.INPUT]: \"input\",\n};\n\nconst APPROVAL_RISK: Partial<Record<ApprovalRisk, ChatApproval[\"risk\"]>> = {\n [ApprovalRisk.LOW]: \"low\",\n [ApprovalRisk.HIGH]: \"high\",\n [ApprovalRisk.IRREVERSIBLE]: \"irreversible\",\n};\n\nconst SCOPE = \":\";\n/** The key a message's surface is stored under, so two replies can both use \"main\". */\nexport const surfaceKey = (messageId: number, surfaceId: string) => `m${messageId}${SCOPE}${surfaceId}`;\n/** The agent's own ID for a stored surface, to send back with an action. */\nexport const agentSurfaceId = (key: string) => key.slice(key.indexOf(SCOPE) + 1);\n\nfunction updateLast(thread: ChatThread, change: (message: ChatMessage) => ChatMessage): ChatThread {\n const index = thread.messages.findLastIndex((m) => m.role === \"assistant\");\n if (index < 0) return thread;\n return { ...thread, messages: thread.messages.map((m, i) => (i === index ? change(m) : m)) };\n}\n\nfunction withPart(message: ChatMessage, part: ChatPart): ChatMessage {\n return { ...message, parts: [...message.parts, part] };\n}\n\nfunction applySurface(thread: ChatThread, raw: unknown, catalog: Catalog): ChatThread {\n const message = thread.messages.findLast((m) => m.role === \"assistant\");\n if (!message) return thread;\n const fail = (text: string) => updateLast(thread, (m) => withPart(m, { kind: \"error\", code: \"INVALID_SURFACE\", message: text }));\n // A malformed envelope is refused; a malformed component is applied and reported where it is drawn.\n const fatal = catalog.validateMessage(raw).filter((issue) => !isComponentIssue(issue));\n if (fatal.length > 0) return fail(`The agent sent a view this page cannot draw: ${fatal[0]!.path} ${fatal[0]!.message}`);\n // What is kept is in the current version, whichever the agent wrote.\n const record = upgradeMessage(raw) as Record<string, { surfaceId: string }>;\n const kind = ([\"createSurface\", \"updateComponents\", \"updateDataModel\", \"deleteSurface\"] as const).find((k) => record[k]);\n if (!kind) return thread;\n const key = surfaceKey(message.id, record[kind]!.surfaceId);\n const scoped = { ...record, [kind]: { ...record[kind], surfaceId: key } } as unknown as SurfaceMessage;\n try {\n const surfaces = applyMessage(thread.surfaces, scoped);\n const shown = message.parts.some((p) => p.kind === \"surface\" && p.surfaceId === key);\n const next = { ...thread, surfaces };\n return kind === \"createSurface\" && !shown ? updateLast(next, (m) => withPart(m, { kind: \"surface\", surfaceId: key })) : next;\n } catch (error) {\n return fail(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Folds user input and agent events into a thread. Pure: the same actions\n * always give the same thread, so a conversation can be replayed in tests.\n */\nexport function reduceThread(thread: ChatThread, action: ChatAction, catalog: Catalog): ChatThread {\n const nextId = (thread.messages.at(-1)?.id ?? 0) + 1;\n switch (action.type) {\n case \"reset\":\n return emptyThread;\n case \"restore\":\n return action.thread;\n case \"user\":\n return {\n ...thread,\n suggestions: [],\n messages: [\n ...thread.messages,\n { id: nextId, role: \"user\", parts: [{ kind: \"text\", text: action.text }, ...(action.references?.length ? [{ kind: \"references\" as const, references: action.references }] : [])], generatedBy: \"\", streaming: false },\n ],\n };\n case \"begin\": {\n const last = thread.messages.at(-1);\n if (action.resume && last?.role === \"assistant\") {\n return { ...updateLast(thread, (m) => ({ ...m, streaming: true })), status: \"streaming\", suggestions: [] };\n }\n return {\n ...thread,\n status: \"streaming\",\n suggestions: [],\n messages: [...thread.messages, { id: nextId, role: \"assistant\", parts: [], generatedBy: \"\", streaming: true }],\n };\n }\n case \"answered\":\n return {\n ...thread,\n messages: thread.messages.map((m) => ({\n ...m,\n parts: m.parts.map((p) =>\n p.kind === \"approval\" && p.approval.id === action.id ? { ...p, approval: { ...p.approval, answer: action.answer } } : p,\n ),\n })),\n };\n case \"end\": {\n const waiting = thread.messages.at(-1)?.parts.some((p) => p.kind === \"approval\" && !p.approval.answer) ?? false;\n return { ...updateLast(thread, (m) => ({ ...m, streaming: false })), status: waiting ? \"waiting\" : \"idle\" };\n }\n case \"event\": {\n const event = action.event.event;\n switch (event.case) {\n case \"text\":\n return updateLast(thread, (m) => {\n const last = m.parts.at(-1);\n if (last?.kind === \"text\") return { ...m, parts: [...m.parts.slice(0, -1), { kind: \"text\", text: last.text + event.value.delta }] };\n return withPart(m, { kind: \"text\", text: event.value.delta });\n });\n case \"step\": {\n const step: ChatStep = {\n id: event.value.id,\n title: event.value.title,\n status: STEP_STATUS[event.value.status] ?? \"running\",\n tool: event.value.tool,\n detail: event.value.detail,\n durationMs: Number(event.value.durationMs),\n };\n return updateLast(thread, (m) => {\n // An event for a step already shown updates it in place.\n if (m.parts.some((p) => p.kind === \"steps\" && p.steps.some((s) => s.id === step.id))) {\n return {\n ...m,\n parts: m.parts.map((p) =>\n p.kind === \"steps\" ? { ...p, steps: p.steps.map((s) => (s.id === step.id ? { ...s, ...step, title: step.title || s.title, detail: step.detail || s.detail } : s)) } : p,\n ),\n };\n }\n const last = m.parts.at(-1);\n if (last?.kind === \"steps\") return { ...m, parts: [...m.parts.slice(0, -1), { kind: \"steps\", steps: [...last.steps, step] }] };\n return withPart(m, { kind: \"steps\", steps: [step] });\n });\n }\n case \"surface\":\n return applySurface(thread, event.value, catalog);\n case \"approval\": {\n const approval: ChatApproval = {\n id: event.value.id,\n kind: APPROVAL_KIND[event.value.kind] ?? \"permission\",\n title: event.value.title,\n detail: event.value.detail,\n sql: event.value.sql,\n options: event.value.options,\n ...(event.value.subject ? { subject: event.value.subject } : {}),\n digest: event.value.digest,\n expiresAt: event.value.expiresAt,\n risk: APPROVAL_RISK[event.value.risk] ?? \"\",\n editable: event.value.editable,\n reasonRequired: event.value.reasonRequired,\n approvalsRequired: Math.max(1, event.value.approvalsRequired),\n approvals: event.value.approvals.map((r) => ({\n ...(r.decidedBy ? { by: { id: r.decidedBy.id, name: r.decidedBy.name } } : {}),\n at: r.decidedAt,\n allow: r.allow,\n reason: r.reason,\n })),\n basis: event.value.basis,\n };\n return updateLast(thread, (m) => withPart(m, { kind: \"approval\", approval }));\n }\n case \"usage\":\n return {\n ...thread,\n usage: {\n inputTokens: Number(event.value.inputTokens),\n outputTokens: Number(event.value.outputTokens),\n contextTokens: Number(event.value.contextTokens),\n contextLimit: Number(event.value.contextLimit),\n costUsd: event.value.costUsd,\n },\n };\n case \"suggestions\":\n return { ...thread, suggestions: event.value.items };\n case \"error\":\n return updateLast(thread, (m) => withPart(m, { kind: \"error\", code: event.value.code, message: event.value.message }));\n case \"done\":\n return { ...updateLast(thread, (m) => ({ ...m, generatedBy: event.value.generatedBy || m.generatedBy })), sessionId: event.value.sessionId || thread.sessionId };\n default:\n return thread;\n }\n }\n }\n}\n\nconst PART_KINDS = new Set([\"text\", \"references\", \"steps\", \"surface\", \"approval\", \"actions\", \"error\"]);\nconst isRecord = (value: unknown): value is Record<string, unknown> => !!value && typeof value === \"object\" && !Array.isArray(value);\n\n/**\n * Checks a thread loaded from storage before it is used, since anyone with\n * access to the storage can edit it. Returns undefined for anything that is\n * not a thread. A reply that was still streaming when the page closed is\n * marked as cut off; an approval nobody answered is still waiting. Surfaces\n * are checked against the catalog again when they are drawn.\n */\nexport function parseThread(input: unknown): ChatThread | undefined {\n if (!isRecord(input) || !Array.isArray(input.messages) || !isRecord(input.surfaces)) return undefined;\n const messages: ChatMessage[] = [];\n for (const raw of input.messages) {\n if (!isRecord(raw) || typeof raw.id !== \"number\" || (raw.role !== \"user\" && raw.role !== \"assistant\") || !Array.isArray(raw.parts)) return undefined;\n if (!raw.parts.every((p) => isRecord(p) && PART_KINDS.has(p.kind as string))) return undefined;\n const parts = raw.parts as ChatPart[];\n const cut = raw.streaming === true;\n messages.push({\n id: raw.id,\n role: raw.role,\n parts: cut ? [...parts, { kind: \"error\", code: \"INTERRUPTED\", message: \"This reply was cut off when the page closed.\" }] : parts,\n generatedBy: typeof raw.generatedBy === \"string\" ? raw.generatedBy : \"\",\n streaming: false,\n });\n }\n const waiting = messages.at(-1)?.parts.some((p) => p.kind === \"approval\" && !p.approval.answer) ?? false;\n return {\n messages,\n // A thread kept before the move to A2UI v1.0 holds surfaces written for v0.9.\n surfaces: Object.fromEntries(Object.entries(input.surfaces as ChatThread[\"surfaces\"]).map(([key, surface]) => [key, isRecord(surface) && isRecord(surface.components) ? upgradeSurface(surface) : surface])),\n status: waiting ? \"waiting\" : \"idle\",\n sessionId: typeof input.sessionId === \"string\" ? input.sessionId : \"\",\n ...(isRecord(input.usage) ? { usage: input.usage as unknown as ChatUsage } : {}),\n suggestions: Array.isArray(input.suggestions) ? input.suggestions.filter((s): s is string => typeof s === \"string\") : [],\n };\n}\n"]}
@@ -0,0 +1,121 @@
1
+ import { type AgentBackend } from "@surfaces-ui/agent";
2
+ import type { JsonObject } from "@bufbuild/protobuf";
3
+ import { type Catalog, type SurfaceAction } from "@surfaces-ui/spec";
4
+ import { type SurfaceNote, type SurfaceProblem } from "@surfaces-ui/spec/react";
5
+ import { type StateStorage } from "@surfaces-ui/state";
6
+ import type { DataRef } from "@surfaces-ui/components";
7
+ /** One thing a person did in a surface, kept until the agent's next turn. */
8
+ export interface ChatActivity {
9
+ componentId: string;
10
+ kind: string;
11
+ summary: string;
12
+ subject?: Record<string, unknown>;
13
+ at: string;
14
+ }
15
+ import { type ChatActor, type ChatThread } from "./thread.js";
16
+ export interface UseChatOptions {
17
+ /** The catalog agent-drawn components are checked against. */
18
+ catalog: Catalog;
19
+ /** Which agent to talk to, when the backend has several. */
20
+ agentId?: string;
21
+ /** Limit the agent to the data in this saved context pack. */
22
+ contextPackId?: string;
23
+ /**
24
+ * Who is using the chat, from the host's own sign-in. Recorded on every
25
+ * approval answer (`decided_by`). A backend must still check it against
26
+ * its own session.
27
+ */
28
+ user?: ChatActor;
29
+ /**
30
+ * Where to keep the conversation so it survives a reload: the thread,
31
+ * where each surface stands, and approvals still waiting. Use
32
+ * `browserStorage()` from `@surfaces-ui/state` for this browser, or your own
33
+ * `StateStorage` over a server so another person can pick up a waiting
34
+ * approval. Nothing is kept without it.
35
+ */
36
+ storage?: StateStorage;
37
+ /** The key the conversation is kept under. Defaults to "surfaces.chat". */
38
+ storageKey?: string;
39
+ /**
40
+ * The thread to open with: a saved conversation (`conversationThread`) or a
41
+ * written one (`scriptThread`). Read once; a kept conversation in `storage`
42
+ * does not replace it.
43
+ */
44
+ initial?: ChatThread;
45
+ /**
46
+ * What the person chose for this conversation: the agent, the model, and
47
+ * the skills and connectors that are on. Sent with every turn; the backend
48
+ * refuses anything it does not offer. Leave it out to use the agent's defaults.
49
+ */
50
+ settings?: ChatSettings;
51
+ }
52
+ /** A person's choices for a conversation, as plain JSON a host or a saved conversation can hold. */
53
+ export interface ChatSettings {
54
+ agentId?: string;
55
+ /** Empty or left out: the agent's default. */
56
+ model?: string;
57
+ /**
58
+ * Where the model runs, when the host offers several (`ChatProvider`): the
59
+ * host turns it into its own backend. Neither it nor the model picked under
60
+ * it is sent with a turn: the host passes the model to that backend.
61
+ */
62
+ provider?: string;
63
+ /** Given: exactly these are on. Left out: each one's default. */
64
+ skillIds?: string[];
65
+ connectorIds?: string[];
66
+ /** The data connection the person browses and attaches from. Not sent: what the agent sees is what they attach. */
67
+ sourceId?: string;
68
+ }
69
+ /** The parts of a turn request that carry a person's choices. */
70
+ export declare function settingsRequest(settings: ChatSettings | undefined, agentId?: string): {
71
+ agentId: string;
72
+ model: string;
73
+ choicesSet?: boolean | undefined;
74
+ skillIds?: string[] | undefined;
75
+ connectorIds?: string[] | undefined;
76
+ };
77
+ /** A person's answer to an approval. */
78
+ export interface ApprovalReply {
79
+ allow: boolean;
80
+ /** The chosen option or typed answer. */
81
+ text?: string;
82
+ /** Why, in their words. */
83
+ reason?: string;
84
+ /** Their version of the SQL, when the request was editable. */
85
+ editedSql?: string;
86
+ /** Their version of the subject, when the request was editable. */
87
+ editedSubject?: JsonObject;
88
+ }
89
+ export interface UseChat {
90
+ thread: ChatThread;
91
+ /** Sends what the person typed, with any tables and columns they attached. */
92
+ send(text: string, references?: DataRef[]): void;
93
+ /** Answers an approval the agent is waiting on, recording who, when and why, and the digest of what was approved. */
94
+ answer(id: string, reply: ApprovalReply): void;
95
+ /** Sends an event from a control on an agent-drawn component. */
96
+ act(action: SurfaceAction): void;
97
+ /**
98
+ * Records where an agent-drawn surface stands: its data model after a
99
+ * person typed, or one component's controls. Nothing is sent now; every
100
+ * later turn carries it (`SendRequest.surfaces`).
101
+ */
102
+ report(surfaceKey: string, state: {
103
+ data?: unknown;
104
+ componentId?: string;
105
+ controls?: Record<string, unknown>;
106
+ note?: SurfaceNote;
107
+ }): void;
108
+ /** Records a problem with an agent-drawn surface, to tell the agent on the next turn (`SendRequest.surface_errors`). */
109
+ problem(surfaceKey: string, problem: SurfaceProblem): void;
110
+ /** Stops the reply in progress. */
111
+ stop(): void;
112
+ /** Starts a new conversation, forgetting the kept one too. */
113
+ reset(): void;
114
+ /** False until a kept conversation has been loaded (always true without `storage`). */
115
+ ready: boolean;
116
+ }
117
+ /**
118
+ * Runs a conversation against any AgentBackend and keeps its thread. One
119
+ * turn streams at a time; starting another stops the one in progress.
120
+ */
121
+ export declare function useChat(given: AgentBackend, options: UseChatOptions): UseChat;