@teaflask/assistant 0.11.2 → 0.11.3

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.
@@ -18,6 +18,7 @@ import { useCell } from "./use-store-cell.js";
18
18
  const NO_POLICY = new ObservableCell(null);
19
19
  const NO_GATE_CELL = new ObservableCell(NO_GATE);
20
20
  const COMPOSER_MAX_HEIGHT_PX = 200;
21
+ const WELCOME_ROOM_SHARE = 0.5;
21
22
  export function Composer({ compact = false, surface = "page", }) {
22
23
  const { busy, pendingSend, sendMessage, composerRefocusPending, markComposerRefocusHandled, stopping, stopTurn, composerInput, setDraft, setAttachments, addFiles, noteComposerFocus, takeComposerCaretReturn, } = useConversation();
23
24
  const { draft, attachments } = useCell(composerInput);
@@ -41,6 +42,7 @@ export function Composer({ compact = false, surface = "page", }) {
41
42
  });
42
43
  const { textareaRef, onTextareaFocus, onTextareaBlur } = useComposerFocus({
43
44
  surface,
45
+ compact,
44
46
  draft,
45
47
  busy,
46
48
  composerRefocusPending,
@@ -110,7 +112,7 @@ function useComposerAttachments({ session, policy, addFiles, setAttachments, })
110
112
  const attachmentRoom = policy === null ? 0 : attachmentRoomOf(policy);
111
113
  return { attachmentRoom, addFiles: pickFiles, removeAttachment };
112
114
  }
113
- function useComposerFocus({ surface, draft, busy, composerRefocusPending, markComposerRefocusHandled, noteComposerFocus, takeComposerCaretReturn, }) {
115
+ function useComposerFocus({ surface, compact, draft, busy, composerRefocusPending, markComposerRefocusHandled, noteComposerFocus, takeComposerCaretReturn, }) {
114
116
  const textareaRef = useRef(null);
115
117
  const ownsFocusRef = useRef(false);
116
118
  useEffect(() => {
@@ -137,16 +139,23 @@ function useComposerFocus({ surface, draft, busy, composerRefocusPending, markCo
137
139
  }
138
140
  }, [takeComposerCaretReturn, surface]);
139
141
  useLayoutEffect(() => {
140
- const textarea = textareaRef.current;
141
- if (textarea === null) {
142
- return;
143
- }
144
- textarea.style.height = "auto";
145
- if (textarea.scrollHeight === 0) {
142
+ _fitTheBoxToItsDraft(textareaRef.current, compact);
143
+ }, [draft, compact]);
144
+ useEffect(() => {
145
+ const room = compact
146
+ ? (textareaRef.current?.closest("[data-tf-welcome-room]") ?? null)
147
+ : null;
148
+ if (room === null || typeof ResizeObserver === "undefined") {
146
149
  return;
147
150
  }
148
- textarea.style.height = `${String(Math.min(textarea.scrollHeight, COMPOSER_MAX_HEIGHT_PX))}px`;
149
- }, [draft]);
151
+ const observer = new ResizeObserver(() => {
152
+ _fitTheBoxToItsDraft(textareaRef.current, compact);
153
+ });
154
+ observer.observe(room);
155
+ return () => {
156
+ observer.disconnect();
157
+ };
158
+ }, [compact]);
150
159
  return {
151
160
  textareaRef,
152
161
  onTextareaFocus: () => {
@@ -187,6 +196,22 @@ function ComposerControlsRow({ attachments, policy, busy, pendingSend, stopping,
187
196
  void send.submitDraft();
188
197
  }, disabled: send.sendDisabled, "aria-label": send.sending ? "Sending message" : "Send message", children: _jsx(ArrowUpIcon, {}) }))] })] }));
189
198
  }
199
+ function _fitTheBoxToItsDraft(textarea, compact) {
200
+ if (textarea === null) {
201
+ return;
202
+ }
203
+ textarea.style.height = "auto";
204
+ if (textarea.scrollHeight === 0) {
205
+ return;
206
+ }
207
+ textarea.style.height = `${String(Math.min(textarea.scrollHeight, _heightCapOf(textarea, compact)))}px`;
208
+ }
209
+ function _heightCapOf(textarea, compact) {
210
+ const room = compact ? textarea.closest("[data-tf-welcome-room]") : null;
211
+ return room === null
212
+ ? COMPOSER_MAX_HEIGHT_PX
213
+ : Math.max(COMPOSER_MAX_HEIGHT_PX, room.clientHeight * WELCOME_ROOM_SHARE);
214
+ }
190
215
  function _focusWasDroppedByTheRemount(textarea) {
191
216
  const active = document.activeElement;
192
217
  return (active === null ||
@@ -39,7 +39,7 @@ function EmptyConversation({ surface, suggestions, welcomeTitle = "Where should
39
39
  if (surface === "companion") {
40
40
  return (_jsx(CompanionWelcome, { suggestions: suggestions, welcomeTitle: welcomeTitle, welcomeMark: welcomeMark, pendingRows: pendingRows }));
41
41
  }
42
- return (_jsx("div", { className: "tf:flex tf:min-h-0 tf:flex-1 tf:flex-col " +
42
+ return (_jsx("div", { "data-tf-welcome-room": "", className: "tf:flex tf:min-h-0 tf:flex-1 tf:flex-col " +
43
43
  (pendingEcho === null ? "tf:overflow-y-auto" : ""), children: _jsxs("div", { className: pendingEcho === null
44
44
  ? "tf:my-auto tf:flex tf:w-full tf:flex-col tf:pt-4 tf:pb-16"
45
45
  : "tf:contents", children: [pendingEcho !== null ? (_jsx(SurfaceBoundary, { surface: "message-list", children: _jsx(MessageList, { rows: pendingRows, cards: [], live: true }) })) : (_jsxs("div", { "data-tf-welcome": "", className: "tf:flex tf:items-center tf:justify-center tf:gap-2 tf:px-6 tf:pb-5 tf:text-center", children: [_jsx("span", { "data-tf-host-view": "", className: "tf:contents", children: welcomeMark }), _jsx("h2", { className: "tf:text-3xl tf:font-semibold tf:tracking-[-0.04em] tf:text-balance", children: welcomeTitle })] })), _jsx(SurfaceBoundary, { surface: "composer", children: _jsx(Composer, { compact: pendingEcho === null, surface: surface }) }), pendingEcho === null &&
@@ -181,7 +181,6 @@ export declare const ApiErrorCode: {
181
181
  readonly STEEP_KEY_INVALID: "STEEP_KEY_INVALID";
182
182
  readonly STEEP_TOKEN_EXPIRED: "STEEP_TOKEN_EXPIRED";
183
183
  readonly STEEP_DISABLED: "STEEP_DISABLED";
184
- readonly STEEP_LEARNING_DISABLED: "STEEP_LEARNING_DISABLED";
185
184
  readonly STEEP_LEARNING_OFF: "STEEP_LEARNING_OFF";
186
185
  readonly STEEP_LEARNING_RUN_IN_PROGRESS: "STEEP_LEARNING_RUN_IN_PROGRESS";
187
186
  readonly STEEP_BATCH_INVALID: "STEEP_BATCH_INVALID";
@@ -180,7 +180,6 @@ export const ApiErrorCode = {
180
180
  STEEP_KEY_INVALID: "STEEP_KEY_INVALID",
181
181
  STEEP_TOKEN_EXPIRED: "STEEP_TOKEN_EXPIRED",
182
182
  STEEP_DISABLED: "STEEP_DISABLED",
183
- STEEP_LEARNING_DISABLED: "STEEP_LEARNING_DISABLED",
184
183
  STEEP_LEARNING_OFF: "STEEP_LEARNING_OFF",
185
184
  STEEP_LEARNING_RUN_IN_PROGRESS: "STEEP_LEARNING_RUN_IN_PROGRESS",
186
185
  STEEP_BATCH_INVALID: "STEEP_BATCH_INVALID",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teaflask/assistant",
3
- "version": "0.11.2",
3
+ "version": "0.11.3",
4
4
  "description": "The AI assistant for your product: drop it into your React app or any page with a script tag.",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "author": "Teaflask",