@blocksdiy/react-common 1.63.1 → 1.64.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.
@@ -10,8 +10,10 @@ export interface FloatingAgentChatHandle {
10
10
  /** What to open: a conversation (`{ chatThreadId }`; a deprecated `chatId` on it is ignored), or the new chat. */
11
11
  export type FloatingAgentChatTarget = AgentConversationRef | "new";
12
12
  /**
13
- * How the open session shows: the floating prompt — the new chat as a one-line composer, until
14
- * its first send — or the panel with the conversation. One engine underneath either way.
13
+ * How the open session shows: the panel with the conversation. `prompt` — the new chat as a
14
+ * one-line composer until its first send — is retired: the controller never opens it. The type
15
+ * keeps it for the registry item's faces and the reducers until the item drops the prompt parts
16
+ * (the agent-chat item's RETIRED-PROMPT note says when).
15
17
  */
16
18
  export type FloatingAgentChatFace = "prompt" | "panel";
17
19
  /**
@@ -33,7 +35,7 @@ export interface FloatingAgentChatOpenOptions<Handle extends FloatingAgentChatHa
33
35
  newChatHref?: string;
34
36
  /** Extra context handed to the agent on every turn (like `AgentChat`'s `chatContext`). */
35
37
  chatContext?: unknown;
36
- /** The face to open with — the panel by default; the prompt always opens the new chat. */
38
+ /** Ignored: the controller opens the panel. `prompt` is retired. */
37
39
  face?: FloatingAgentChatFace;
38
40
  }
39
41
  /** The open options with the ids resolved from the handle. */
@@ -1 +1 @@
1
- {"version":3,"file":"floating-agent-chat.d.ts","sourceRoot":"","sources":["../../src/hooks/floating-agent-chat.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAErE,8FAA8F;AAC9F,MAAM,WAAW,uBAAuB;IACtC,0BAA0B,IAAI;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CAC1F;AAED,kHAAkH;AAClH,MAAM,MAAM,uBAAuB,GAAG,oBAAoB,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
1
  // The floating agent chat's state, headless: what the open session shows (which agent, which
2
- // conversation), the face it wears (the floating prompt until a new chat's first send, the panel
3
- // after), the draft the new chat is until that send, and the opener that gets focus back on
4
- // close. The agent-chat registry item renders it. Mirrors the conversation selection rules of
5
- // useAgentConversationSelection: a new chat is a draft minted here and listed nowhere until the
6
- // first send; "New chat" on an untouched draft keeps it; a thread opened beside it leaves it
7
- // standing by. The reducers are pure and tested; the hook is the thin React shell.
2
+ // conversation), the face it wears (the panel; see FloatingAgentChatFace), the draft the new
3
+ // chat is until that send, and the opener that gets focus back on close. The agent-chat registry
4
+ // item renders it. Mirrors the conversation selection rules of useAgentConversationSelection: a
5
+ // new chat is a draft minted here and listed nowhere until the first send; "New chat" on an
6
+ // untouched draft keeps it; a thread opened beside it leaves it standing by. The reducers are
7
+ // pure and tested; the hook is the thin React shell.
8
8
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
9
9
  /** The panel shows the new chat, nothing sent on it yet. */
10
10
  export const isFloatingAgentChatDraft = (state) => state.conversation.chatThreadId === state.draftThreadId && !state.draftSent;
@@ -82,7 +82,7 @@ export const useFloatingAgentChatController = () => {
82
82
  agentChat: options.agentChat,
83
83
  agentChatId,
84
84
  target: options.target ?? "new",
85
- face: options.face ?? "panel",
85
+ face: "panel",
86
86
  expandHref: options.expandHref,
87
87
  newChatHref: options.newChatHref,
88
88
  chatContext: options.chatContext,
@@ -1,10 +1,10 @@
1
- // The platform's door to an app's floating agent prompt. The platform asks through the iframe
2
- // bridge; app-render, which answers the bridge, posts the request here; the app's
3
- // FloatingAgentChatProvider, which renders the prompt, subscribes. Both run in the iframe on
4
- // this one module (`@blocksdiy/react-common/agent-threads` is a UMD external the bundle takes
5
- // from app-render), so no window global is needed. A request posted before the provider mounts
6
- // (the bundle is still loading) waits for it; one nothing claims in time is dropped and the
7
- // platform told — an app built without the prompt.
1
+ // The platform's door to an app's floating agent chat: a new chat with one of its agents, in
2
+ // the panel. The platform asks through the iframe bridge; app-render, which answers the bridge,
3
+ // posts the request here; the app's FloatingAgentChatProvider, which renders the chat,
4
+ // subscribes. Both run in the iframe on this one module (`@blocksdiy/react-common/agent-threads`
5
+ // is a UMD external the bundle takes from app-render), so no window global is needed. A request
6
+ // posted before the provider mounts (the bundle is still loading) waits for it; one nothing
7
+ // claims in time is dropped and the platform told — an app built without the floating chat.
8
8
  /** How long a request waits for a subscriber before it is withdrawn. */
9
9
  export const FLOATING_AGENT_PROMPT_CLAIM_TIMEOUT_MS = 5000;
10
10
  // Read at call time, so a test's fake timers apply.
@@ -1,17 +1,26 @@
1
- import type { FloatingAgentChatExpandHref, FloatingAgentChatHandle, UseFloatingAgentChatControllerResult } from "./floating-agent-chat.js";
1
+ import type { FloatingAgentChatExpandHref, FloatingAgentChatHandle, FloatingAgentChatOpenOptions, UseFloatingAgentChatControllerResult } from "./floating-agent-chat.js";
2
2
  /**
3
- * One agent the prompt can open, as the app resolved it: its id (the agent block's name — what
4
- * the platform asks for), the agent's own chat the session opens, and where the panel's expand
5
- * goes for a conversation started here.
3
+ * One agent on offer, as the app resolved it: its id (the agent block's name — what the
4
+ * platform asks for), the agent's own chat the session opens, and where the panel's expand
5
+ * goes for a conversation started here — and for the new chat, nothing sent on it yet.
6
6
  */
7
7
  export interface FloatingAgentPromptAgentEntry<Handle extends FloatingAgentChatHandle = FloatingAgentChatHandle> {
8
8
  id: string;
9
9
  agentChatId: string;
10
10
  handle: Handle;
11
11
  expandHref?: FloatingAgentChatExpandHref;
12
+ /** The agent's full-page new chat (its mini-app's `/new`); without it the new chat has no expand. */
13
+ newChatHref?: string;
12
14
  }
13
15
  /** The entry for an id, or the first entry when none is named; null for an id not on offer, or without entries. */
14
16
  export declare const resolveFloatingAgentPromptAgent: <Handle extends FloatingAgentChatHandle>(agents: readonly FloatingAgentPromptAgentEntry<Handle>[], agentId?: string) => FloatingAgentPromptAgentEntry<Handle> | null;
17
+ /**
18
+ * The open for one of the agents on offer: a new chat with it, which expands to the agent's
19
+ * new-chat page, and to the thread's page once sent. Null when there is nothing to open — no
20
+ * agents, the agent asked for not among them, an anonymous visitor — so the platform falls back
21
+ * to the agent's own new-chat page.
22
+ */
23
+ export declare const floatingAgentPromptOpen: <Handle extends FloatingAgentChatHandle>(agents: readonly FloatingAgentPromptAgentEntry<Handle>[], agentId: string | undefined, canOpen: boolean, chatContext?: unknown) => FloatingAgentChatOpenOptions<Handle> | null;
15
24
  /** What the open agent's chat lends the prompt, which renders outside it (it shows while the chat loads). */
16
25
  export interface FloatingAgentPromptChat {
17
26
  canSend: boolean;
@@ -24,34 +33,33 @@ export interface FloatingAgentPromptOpenOptions {
24
33
  chatContext?: unknown;
25
34
  }
26
35
  export interface UseFloatingAgentPromptControllerOptions<Handle extends FloatingAgentChatHandle = FloatingAgentChatHandle> {
27
- /** The session the prompt opens: one controller per app. */
36
+ /** The session the doors open: one controller per app. */
28
37
  session: UseFloatingAgentChatControllerResult<Handle>;
29
38
  agents: readonly FloatingAgentPromptAgentEntry<Handle>[];
30
39
  /** False for an anonymous visitor: nothing opens, and the platform's requests go unclaimed. */
31
40
  canOpen: boolean;
32
41
  }
33
42
  export interface UseFloatingAgentPromptControllerResult {
34
- /** The session wears the prompt face. */
43
+ /** The session wears the prompt face: never. */
35
44
  isOpen: boolean;
36
45
  /** The open session's agent, as an entry id; null while nothing is open or for an agent not on offer. */
37
46
  agentId: string | null;
38
- /** True once the prompt opened; false without agents, for an agent not on offer, or for an anonymous visitor. */
47
+ /**
48
+ * Opens a new chat with the agent in the floating chat panel ({@link floatingAgentPromptOpen}).
49
+ * True once it opened; false without agents, for an agent not on offer, or for an anonymous visitor.
50
+ */
39
51
  openPrompt: (options?: FloatingAgentPromptOpenOptions) => boolean;
52
+ /** The prompt's text: always empty. */
40
53
  text: string;
41
54
  setText: (text: string) => void;
42
- /** Counts the opens, re-points included — the message takes focus on each. */
55
+ /** The prompt's opens: always zero. */
43
56
  openCount: number;
44
- /** The open agent's chat is up and free. */
57
+ /** The prompt can send: never. */
45
58
  canSend: boolean;
46
- /** Sends through the open agent's chat; its first send turns the prompt into the panel. */
59
+ /** No-op, like `setText` and `setChat`. */
47
60
  send: (content: string) => void;
48
- /** The open agent's chat lends itself here once it is up, and takes itself back when it goes. */
49
61
  setChat: (chat: FloatingAgentPromptChat | null) => void;
50
62
  }
51
- /**
52
- * The prompt's state and transitions, for the one provider at the app's root. A fresh prompt
53
- * starts empty; re-pointing it at another agent keeps the text; a sent message is the chat's
54
- * (the pill is gone), a refused one stays where it was.
55
- */
63
+ /** The doors, for the one provider at the app's root, with the prompt's fixed state. */
56
64
  export declare const useFloatingAgentPromptController: <Handle extends FloatingAgentChatHandle = FloatingAgentChatHandle>({ session, agents, canOpen, }: UseFloatingAgentPromptControllerOptions<Handle>) => UseFloatingAgentPromptControllerResult;
57
65
  //# sourceMappingURL=floating-agent-prompt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"floating-agent-prompt.d.ts","sourceRoot":"","sources":["../../src/hooks/floating-agent-prompt.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,2BAA2B,EAC3B,uBAAuB,EACvB,oCAAoC,EACrC,MAAM,uBAAuB,CAAC;AAG/B;;;;GAIG;AACH,MAAM,WAAW,6BAA6B,CAAC,MAAM,SAAS,uBAAuB,GAAG,uBAAuB;IAC7G,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,2BAA2B,CAAC;CAC1C;AAED,mHAAmH;AACnH,eAAO,MAAM,+BAA+B,GAAI,MAAM,SAAS,uBAAuB,EACpF,QAAQ,SAAS,6BAA6B,CAAC,MAAM,CAAC,EAAE,EACxD,UAAU,MAAM,KACf,6BAA6B,CAAC,MAAM,CAAC,GAAG,IACiD,CAAC;AAE7F,6GAA6G;AAC7G,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,CAAC,OAAO,EAAE,MAA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AAC;IACzD,+FAA+F;IAC/F,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,sCAAsC;IACrD,gDAAgD;IAChD,MAAM,EAAE,OAAO,CAAC;IAChB,yGAAyG;IACzG,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB;;;OAGG;IACH,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE,8BAA8B,KAAK,OAAO,CAAC;IAClE,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,kCAAkC;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,2CAA2C;IAC3C,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,OAAO,EAAE,CAAC,IAAI,EAAE,uBAAuB,GAAG,IAAI,KAAK,IAAI,CAAC;CACzD;AAID,wFAAwF;AACxF,eAAO,MAAM,gCAAgC,GAAI,MAAM,SAAS,uBAAuB,GAAG,uBAAuB,EAAE,+BAIhH,uCAAuC,CAAC,MAAM,CAAC,KAAG,sCAqDpD,CAAC"}
@@ -1,42 +1,42 @@
1
- // The floating agent prompt's state, headless: which of the app's agents it is for, the text
2
- // typed, the opens (the message takes focus on each), what the open agent's chat lends it (can it
3
- // send, the send), and the platform's requests for it (the rail's chat bubble, through
4
- // app-render's mailbox). The session it opens is useFloatingAgentChatController's; the
5
- // agent-chat registry item resolves the agents and renders the prompt.
6
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
1
+ // The floating agent chat's doors for the app's agents, headless: a page's `openPrompt` and the
2
+ // platform's requests for one of the agents (the rail's chat bubble, through app-render's
3
+ // mailbox) open a new chat with the agent in the floating chat panel. The one-line prompt face
4
+ // is retired — the session never wears it — so its state below is fixed; it stays for the
5
+ // agent-chat registry item's prompt parts. The session is useFloatingAgentChatController's; the
6
+ // registry item resolves the agents.
7
+ import { useCallback, useEffect, useMemo, useRef } from "react";
7
8
  import { subscribeFloatingAgentPromptRequests } from "./floating-agent-prompt-requests.js";
8
9
  /** The entry for an id, or the first entry when none is named; null for an id not on offer, or without entries. */
9
10
  export const resolveFloatingAgentPromptAgent = (agents, agentId) => (agentId === undefined ? agents[0] : agents.find((entry) => entry.id === agentId)) ?? null;
10
11
  /**
11
- * The prompt's state and transitions, for the one provider at the app's root. A fresh prompt
12
- * starts empty; re-pointing it at another agent keeps the text; a sent message is the chat's
13
- * (the pill is gone), a refused one stays where it was.
12
+ * The open for one of the agents on offer: a new chat with it, which expands to the agent's
13
+ * new-chat page, and to the thread's page once sent. Null when there is nothing to open — no
14
+ * agents, the agent asked for not among them, an anonymous visitor — so the platform falls back
15
+ * to the agent's own new-chat page.
14
16
  */
17
+ export const floatingAgentPromptOpen = (agents, agentId, canOpen, chatContext) => {
18
+ const entry = resolveFloatingAgentPromptAgent(agents, agentId);
19
+ if (!entry || !canOpen) {
20
+ return null;
21
+ }
22
+ return { agentChat: entry.handle, expandHref: entry.expandHref, newChatHref: entry.newChatHref, chatContext };
23
+ };
24
+ const noop = () => { };
25
+ /** The doors, for the one provider at the app's root, with the prompt's fixed state. */
15
26
  export const useFloatingAgentPromptController = ({ session, agents, canOpen, }) => {
16
27
  const { state, open } = session;
17
- const isOpen = state !== null && state.face === "prompt";
18
- const [text, setText] = useState("");
19
- const [openCount, setOpenCount] = useState(0);
20
- const [chat, setChat] = useState(null);
21
- // Opens the prompt for an agent; false when there is nothing to open — no agents, the agent
22
- // asked for not among them, an anonymous visitor.
28
+ // Opens the agent's new chat; false when there is nothing to open.
23
29
  const openFor = useCallback((agentId, chatContext) => {
24
- const entry = resolveFloatingAgentPromptAgent(agents, agentId);
25
- if (!entry || !canOpen) {
26
- return false;
27
- }
28
- if (!isOpen) {
29
- setText("");
30
+ const openOptions = floatingAgentPromptOpen(agents, agentId, canOpen, chatContext);
31
+ if (openOptions) {
32
+ open(openOptions);
30
33
  }
31
- setOpenCount((count) => count + 1);
32
- // No `newChatHref`: the prompt has no header, and its first send makes the new chat a thread.
33
- open({ agentChat: entry.handle, face: "prompt", expandHref: entry.expandHref, chatContext });
34
- return true;
35
- }, [agents, canOpen, isOpen, open]);
34
+ return openOptions !== null;
35
+ }, [agents, canOpen, open]);
36
36
  const openPrompt = useCallback((options) => {
37
37
  const opened = openFor(options?.agent, options?.chatContext);
38
38
  if (!opened) {
39
- console.warn("Floating agent prompt: nothing to open — it needs agents on offer (the one asked for among them) and a signed-in user.");
39
+ console.warn("Floating agent chat: nothing to open — it needs agents on offer (the one asked for among them) and a signed-in user.");
40
40
  }
41
41
  return opened;
42
42
  }, [openFor]);
@@ -50,7 +50,15 @@ export const useFloatingAgentPromptController = ({ session, agents, canOpen, })
50
50
  }, [openFor]);
51
51
  useEffect(() => subscribeFloatingAgentPromptRequests((request) => openForRef.current(request.agent)), []);
52
52
  const agentId = state === null ? null : (agents.find((entry) => entry.agentChatId === state.agentChatId)?.id ?? null);
53
- const canSend = chat?.canSend ?? false;
54
- const send = useCallback((content) => chat?.send(content), [chat]);
55
- return useMemo(() => ({ isOpen, agentId, openPrompt, text, setText, openCount, canSend, send, setChat }), [isOpen, agentId, openPrompt, text, openCount, canSend, send]);
53
+ return useMemo(() => ({
54
+ isOpen: false,
55
+ agentId,
56
+ openPrompt,
57
+ text: "",
58
+ setText: noop,
59
+ openCount: 0,
60
+ canSend: false,
61
+ send: noop,
62
+ setChat: noop,
63
+ }), [agentId, openPrompt]);
56
64
  };
@@ -120,9 +120,9 @@ export interface IframeApi extends Methods {
120
120
  */
121
121
  onLockChatComponentFocus: (isLocked: boolean) => Promise<void>;
122
122
  /**
123
- * Opens the app's floating agent prompt for one of its agents (`agent` is the agent's block
124
- * name). Resolves `false` when nothing in the app took the request — an app built without the
125
- * prompt — so the platform can fall back to the agent's own new-chat page.
123
+ * Opens a new chat with one of the app's agents in its floating agent chat panel (`agent` is
124
+ * the agent's block name). Resolves `false` when nothing in the app took the request — an app
125
+ * built without the floating chat — so the platform can fall back to the agent's own new-chat page.
126
126
  */
127
127
  onOpenAgentPrompt: (args: {
128
128
  agent: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocksdiy/react-common",
3
- "version": "1.63.1",
3
+ "version": "1.64.0",
4
4
  "type": "module",
5
5
  "description": "React common",
6
6
  "keywords": [],