@stigmer/react 3.1.7 → 3.1.8

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 (195) hide show
  1. package/agent/AgentDetailView.d.ts +9 -1
  2. package/agent/AgentDetailView.d.ts.map +1 -1
  3. package/agent/AgentDetailView.js +15 -4
  4. package/agent/AgentDetailView.js.map +1 -1
  5. package/environment/EnvironmentListPanel.d.ts.map +1 -1
  6. package/environment/EnvironmentListPanel.js +11 -3
  7. package/environment/EnvironmentListPanel.js.map +1 -1
  8. package/environment/EnvironmentVariableEditor.d.ts.map +1 -1
  9. package/environment/EnvironmentVariableEditor.js +9 -3
  10. package/environment/EnvironmentVariableEditor.js.map +1 -1
  11. package/environment/index.d.ts +1 -0
  12. package/environment/index.d.ts.map +1 -1
  13. package/environment/index.js +1 -0
  14. package/environment/index.js.map +1 -1
  15. package/environment/shareRestriction.d.ts +13 -0
  16. package/environment/shareRestriction.d.ts.map +1 -0
  17. package/environment/shareRestriction.js +15 -0
  18. package/environment/shareRestriction.js.map +1 -0
  19. package/execution/ToolCallItem.d.ts.map +1 -1
  20. package/execution/ToolCallItem.js +12 -0
  21. package/execution/ToolCallItem.js.map +1 -1
  22. package/execution/ToolRunGroup.js +4 -0
  23. package/execution/ToolRunGroup.js.map +1 -1
  24. package/execution/WriteBackCard.d.ts +14 -5
  25. package/execution/WriteBackCard.d.ts.map +1 -1
  26. package/execution/WriteBackCard.js +103 -32
  27. package/execution/WriteBackCard.js.map +1 -1
  28. package/execution/WriteBacksWidget.d.ts +1 -1
  29. package/execution/WriteBacksWidget.js +2 -2
  30. package/execution/WriteBacksWidget.js.map +1 -1
  31. package/execution/index.d.ts +2 -0
  32. package/execution/index.d.ts.map +1 -1
  33. package/execution/index.js +1 -0
  34. package/execution/index.js.map +1 -1
  35. package/execution/write-back-utils.d.ts +57 -0
  36. package/execution/write-back-utils.d.ts.map +1 -0
  37. package/execution/write-back-utils.js +81 -0
  38. package/execution/write-back-utils.js.map +1 -0
  39. package/index.d.ts +6 -2
  40. package/index.d.ts.map +1 -1
  41. package/index.js +6 -1
  42. package/index.js.map +1 -1
  43. package/internal/dev/dom-counter.d.ts.map +1 -1
  44. package/internal/dev/dom-counter.js +2 -2
  45. package/internal/dev/dom-counter.js.map +1 -1
  46. package/internal/dev/enabled.d.ts +7 -0
  47. package/internal/dev/enabled.d.ts.map +1 -0
  48. package/internal/dev/enabled.js +38 -0
  49. package/internal/dev/enabled.js.map +1 -0
  50. package/internal/dev/profiler-wrapper.d.ts +3 -3
  51. package/internal/dev/profiler-wrapper.d.ts.map +1 -1
  52. package/internal/dev/profiler-wrapper.js +5 -5
  53. package/internal/dev/profiler-wrapper.js.map +1 -1
  54. package/internal/dev/use-key-stability.d.ts.map +1 -1
  55. package/internal/dev/use-key-stability.js +2 -2
  56. package/internal/dev/use-key-stability.js.map +1 -1
  57. package/internal/dev/use-render-tracer.d.ts +2 -2
  58. package/internal/dev/use-render-tracer.d.ts.map +1 -1
  59. package/internal/dev/use-render-tracer.js +4 -4
  60. package/internal/dev/use-render-tracer.js.map +1 -1
  61. package/internal/dev/use-stream-rate.d.ts +2 -1
  62. package/internal/dev/use-stream-rate.d.ts.map +1 -1
  63. package/internal/dev/use-stream-rate.js +4 -3
  64. package/internal/dev/use-stream-rate.js.map +1 -1
  65. package/library/ResourceVisibilityControl.d.ts +3 -0
  66. package/library/ResourceVisibilityControl.d.ts.map +1 -1
  67. package/library/ResourceVisibilityControl.js +22 -8
  68. package/library/ResourceVisibilityControl.js.map +1 -1
  69. package/library/useUpdateVisibility.d.ts +5 -3
  70. package/library/useUpdateVisibility.d.ts.map +1 -1
  71. package/library/useUpdateVisibility.js +7 -2
  72. package/library/useUpdateVisibility.js.map +1 -1
  73. package/library/visibilityLevels.d.ts +17 -0
  74. package/library/visibilityLevels.d.ts.map +1 -1
  75. package/library/visibilityLevels.js +32 -0
  76. package/library/visibilityLevels.js.map +1 -1
  77. package/package.json +4 -4
  78. package/session/NewSessionViewer.d.ts +11 -1
  79. package/session/NewSessionViewer.d.ts.map +1 -1
  80. package/session/NewSessionViewer.js +28 -8
  81. package/session/NewSessionViewer.js.map +1 -1
  82. package/session/SessionViewer.d.ts +9 -2
  83. package/session/SessionViewer.d.ts.map +1 -1
  84. package/session/SessionViewer.js +26 -12
  85. package/session/SessionViewer.js.map +1 -1
  86. package/session/audience.d.ts +12 -4
  87. package/session/audience.d.ts.map +1 -1
  88. package/session/facets/ChangesTab.d.ts.map +1 -1
  89. package/session/facets/ChangesTab.js +3 -1
  90. package/session/facets/ChangesTab.js.map +1 -1
  91. package/session/useNewSessionFlow.d.ts +12 -0
  92. package/session/useNewSessionFlow.d.ts.map +1 -1
  93. package/session/useNewSessionFlow.js +13 -1
  94. package/session/useNewSessionFlow.js.map +1 -1
  95. package/session/useSessionPageFlow.d.ts +13 -0
  96. package/session/useSessionPageFlow.d.ts.map +1 -1
  97. package/session/useSessionPageFlow.js +7 -2
  98. package/session/useSessionPageFlow.js.map +1 -1
  99. package/sharing/ShareAgentDialog.d.ts +55 -0
  100. package/sharing/ShareAgentDialog.d.ts.map +1 -0
  101. package/sharing/ShareAgentDialog.js +393 -0
  102. package/sharing/ShareAgentDialog.js.map +1 -0
  103. package/sharing/SharedAgentChat.d.ts +84 -0
  104. package/sharing/SharedAgentChat.d.ts.map +1 -0
  105. package/sharing/SharedAgentChat.js +80 -0
  106. package/sharing/SharedAgentChat.js.map +1 -0
  107. package/sharing/index.d.ts +16 -0
  108. package/sharing/index.d.ts.map +1 -0
  109. package/sharing/index.js +11 -0
  110. package/sharing/index.js.map +1 -0
  111. package/sharing/useRotateShareLink.d.ts +42 -0
  112. package/sharing/useRotateShareLink.d.ts.map +1 -0
  113. package/sharing/useRotateShareLink.js +55 -0
  114. package/sharing/useRotateShareLink.js.map +1 -0
  115. package/sharing/useShareAgent.d.ts +68 -0
  116. package/sharing/useShareAgent.d.ts.map +1 -0
  117. package/sharing/useShareAgent.js +41 -0
  118. package/sharing/useShareAgent.js.map +1 -0
  119. package/sharing/useShareToolReadiness.d.ts +48 -0
  120. package/sharing/useShareToolReadiness.d.ts.map +1 -0
  121. package/sharing/useShareToolReadiness.js +93 -0
  122. package/sharing/useShareToolReadiness.js.map +1 -0
  123. package/sharing/useSharedAgentProfile.d.ts +84 -0
  124. package/sharing/useSharedAgentProfile.d.ts.map +1 -0
  125. package/sharing/useSharedAgentProfile.js +72 -0
  126. package/sharing/useSharedAgentProfile.js.map +1 -0
  127. package/sharing/useUpdateAgentSharing.d.ts +86 -0
  128. package/sharing/useUpdateAgentSharing.d.ts.map +1 -0
  129. package/sharing/useUpdateAgentSharing.js +81 -0
  130. package/sharing/useUpdateAgentSharing.js.map +1 -0
  131. package/src/agent/AgentDetailView.tsx +28 -3
  132. package/src/environment/EnvironmentListPanel.tsx +47 -18
  133. package/src/environment/EnvironmentVariableEditor.tsx +27 -17
  134. package/src/environment/__tests__/shareRestriction.test.ts +35 -0
  135. package/src/environment/index.ts +5 -0
  136. package/src/environment/shareRestriction.ts +22 -0
  137. package/src/execution/ToolCallItem.tsx +19 -1
  138. package/src/execution/ToolRunGroup.tsx +4 -0
  139. package/src/execution/WriteBackCard.tsx +285 -88
  140. package/src/execution/WriteBacksWidget.tsx +5 -5
  141. package/src/execution/__tests__/ToolCallItem.test.tsx +51 -0
  142. package/src/execution/__tests__/ToolRunGroup.test.tsx +22 -0
  143. package/src/execution/__tests__/WriteBackCard.test.tsx +64 -10
  144. package/src/execution/__tests__/write-back-utils.test.ts +135 -0
  145. package/src/execution/index.ts +7 -0
  146. package/src/execution/write-back-utils.ts +107 -0
  147. package/src/index.ts +34 -0
  148. package/src/internal/dev/__tests__/use-key-stability.test.ts +4 -0
  149. package/src/internal/dev/__tests__/use-render-tracer.test.ts +4 -0
  150. package/src/internal/dev/dom-counter.ts +2 -3
  151. package/src/internal/dev/enabled.ts +39 -0
  152. package/src/internal/dev/profiler-wrapper.tsx +5 -6
  153. package/src/internal/dev/use-key-stability.ts +2 -3
  154. package/src/internal/dev/use-render-tracer.ts +4 -5
  155. package/src/internal/dev/use-stream-rate.ts +4 -4
  156. package/src/library/ResourceVisibilityControl.tsx +23 -7
  157. package/src/library/__tests__/visibilityLevels.test.ts +33 -0
  158. package/src/library/useUpdateVisibility.ts +9 -3
  159. package/src/library/visibilityLevels.ts +36 -0
  160. package/src/session/NewSessionViewer.tsx +67 -31
  161. package/src/session/SessionViewer.tsx +67 -36
  162. package/src/session/__tests__/audienceWiring.test.tsx +99 -0
  163. package/src/session/__tests__/useNewSessionFlow.test.tsx +75 -1
  164. package/src/session/__tests__/useSessionPageFlow.guest.test.tsx +112 -0
  165. package/src/session/audience.ts +12 -4
  166. package/src/session/facets/ChangesTab.tsx +6 -4
  167. package/src/session/useNewSessionFlow.ts +26 -1
  168. package/src/session/useSessionPageFlow.ts +24 -2
  169. package/src/sharing/ShareAgentDialog.tsx +1255 -0
  170. package/src/sharing/SharedAgentChat.tsx +283 -0
  171. package/src/sharing/__tests__/ShareAgentDialog.test.tsx +745 -0
  172. package/src/sharing/__tests__/SharedAgentChat.test.tsx +222 -0
  173. package/src/sharing/__tests__/useRotateShareLink.test.tsx +96 -0
  174. package/src/sharing/__tests__/useShareAgent.test.tsx +127 -0
  175. package/src/sharing/__tests__/useShareToolReadiness.test.tsx +182 -0
  176. package/src/sharing/__tests__/useSharedAgentProfile.test.tsx +201 -0
  177. package/src/sharing/__tests__/useUpdateAgentSharing.test.tsx +200 -0
  178. package/src/sharing/index.ts +30 -0
  179. package/src/sharing/useRotateShareLink.ts +76 -0
  180. package/src/sharing/useShareAgent.tsx +106 -0
  181. package/src/sharing/useShareToolReadiness.ts +129 -0
  182. package/src/sharing/useSharedAgentProfile.ts +131 -0
  183. package/src/sharing/useUpdateAgentSharing.ts +151 -0
  184. package/src/switch/Switch.tsx +92 -0
  185. package/src/switch/__tests__/Switch.test.tsx +88 -0
  186. package/src/switch/index.ts +2 -0
  187. package/styles.css +1 -1
  188. package/switch/Switch.d.ts +47 -0
  189. package/switch/Switch.d.ts.map +1 -0
  190. package/switch/Switch.js +36 -0
  191. package/switch/Switch.js.map +1 -0
  192. package/switch/index.d.ts +3 -0
  193. package/switch/index.d.ts.map +1 -0
  194. package/switch/index.js +2 -0
  195. package/switch/index.js.map +1 -0
@@ -0,0 +1,393 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useCallback, useMemo, useRef, useState } from "react";
4
+ import { cn } from "@stigmer/theme";
5
+ import { MAX_ALLOWED_ORIGINS, appendLinkToken, buildEmbedSnippet, chatPath, getUserMessage, validateOrigin, } from "@stigmer/sdk";
6
+ import { Switch } from "../switch/Switch.js";
7
+ import { Tabs } from "../tabs/Tabs.js";
8
+ import { toast } from "../feedback/toast.js";
9
+ import { useCopyResource } from "../resource-detail/useCopyResource.js";
10
+ import { useDeploymentMode } from "../deployment-mode.js";
11
+ import { useBillingAccount } from "../billing/useBillingAccount.js";
12
+ import { formatCreditBalance } from "../billing/format.js";
13
+ import { sharingAudienceFromProto, useUpdateAgentSharing, } from "./useUpdateAgentSharing.js";
14
+ import { useRotateShareLink } from "./useRotateShareLink.js";
15
+ import { useShareToolReadiness } from "./useShareToolReadiness.js";
16
+ /** Maximum length of each visitor message (proto: `string.max_len = 300`). */
17
+ const MAX_MESSAGE_LENGTH = 300;
18
+ const SHARE_TABS = [
19
+ { id: "link", label: "Link" },
20
+ { id: "embed", label: "Embed" },
21
+ { id: "developer", label: "Developer" },
22
+ ];
23
+ const PLATFORM_CLIENT_DOCS_URL = "https://docs.stigmer.ai/guides/authentication/platform-client/overview";
24
+ /**
25
+ * The Share dialog for an agent: toggle public sharing, copy the hosted
26
+ * chat link, copy an embeddable iframe snippet, manage allowed embed
27
+ * origins, customize visitor refusal messages, and discover the
28
+ * PlatformClient SDK path.
29
+ *
30
+ * Sharing is a distinct consent from marketplace visibility: visibility
31
+ * governs who can *read* the blueprint; sharing governs who can *chat*
32
+ * with the running agent — billed to the owning org. The dialog states
33
+ * who pays next to the toggle so enabling sharing never surprises.
34
+ *
35
+ * Every save sends the complete sharing configuration (the RPC replaces
36
+ * `spec.sharing` wholesale — see {@link AgentSharingDraft}), and the
37
+ * local draft is refreshed from the RPC's returned agent, so the dialog
38
+ * never drifts from the server.
39
+ *
40
+ * Built on the native `<dialog>` element for focus trapping and escape
41
+ * handling, matching the SDK's modal convention ({@link ManageAccessDialog}).
42
+ * All visual properties flow through `--stgm-*` design tokens.
43
+ *
44
+ * Most hosts mount it via {@link useShareAgent} (a kebab-menu action).
45
+ * Render it directly only when you own the open-state.
46
+ */
47
+ export function ShareAgentDialog({ open, onOpenChange, agent, buildShareUrl, onSharingChanged, modal = true, }) {
48
+ const dialogRef = useRef(null);
49
+ const handleClose = useCallback(() => {
50
+ dialogRef.current?.close();
51
+ onOpenChange(false);
52
+ }, [onOpenChange]);
53
+ // Sync native dialog open state (matches the SDK dialog convention).
54
+ // Non-modal hosts pass `open` as a plain attribute instead — the dialog
55
+ // renders in-flow with no top layer to manage.
56
+ const prevOpenRef = useRef(false);
57
+ if (modal && open !== prevOpenRef.current) {
58
+ prevOpenRef.current = open;
59
+ if (open) {
60
+ requestAnimationFrame(() => {
61
+ if (dialogRef.current && !dialogRef.current.open) {
62
+ dialogRef.current.showModal();
63
+ }
64
+ });
65
+ }
66
+ else if (dialogRef.current?.open) {
67
+ dialogRef.current.close();
68
+ }
69
+ }
70
+ return (_jsx("dialog", { ref: dialogRef, open: modal ? undefined : open, onClose: handleClose, className: cn("w-full max-w-lg rounded-xl border border-border bg-popover p-0 shadow-xl", modal ? "fixed inset-0 m-auto backdrop:bg-black/50" : "relative"), "aria-labelledby": "share-agent-title", children: open && (_jsx(ShareAgentDialogBody, { agent: agent, buildShareUrl: buildShareUrl, onSharingChanged: onSharingChanged, onClose: handleClose })) }));
71
+ }
72
+ // ---------------------------------------------------------------------------
73
+ // Dialog body — owns the sharing draft for the session
74
+ // ---------------------------------------------------------------------------
75
+ function draftFromAgent(agent) {
76
+ const sharing = agent.spec?.sharing;
77
+ return {
78
+ enabled: sharing?.enabled ?? false,
79
+ audience: sharingAudienceFromProto(sharing?.audience),
80
+ allowedOrigins: sharing?.allowedOrigins ?? [],
81
+ messages: {
82
+ rateLimited: sharing?.messages?.rateLimited ?? "",
83
+ unavailable: sharing?.messages?.unavailable ?? "",
84
+ conversationEnded: sharing?.messages?.conversationEnded ?? "",
85
+ },
86
+ };
87
+ }
88
+ function ShareAgentDialogBody({ agent, buildShareUrl, onSharingChanged, onClose, }) {
89
+ const org = agent.metadata?.org ?? "";
90
+ const slug = agent.metadata?.slug ?? "";
91
+ const agentName = agent.metadata?.name || slug;
92
+ const [draft, setDraft] = useState(() => draftFromAgent(agent));
93
+ // The share-link token is server-owned status (never part of the sharing
94
+ // draft — rotateShareLink is its sole writer); track it separately and
95
+ // adopt it from every returned agent so the shown link never goes stale.
96
+ const [linkToken, setLinkToken] = useState(() => agent.status?.shareLinkToken ?? "");
97
+ const [activeTab, setActiveTab] = useState("link");
98
+ const { updateSharing, isPending } = useUpdateAgentSharing(agent.metadata?.id ?? null);
99
+ const { rotateShareLink, isPending: isRotating } = useRotateShareLink(agent.metadata?.id ?? null);
100
+ // Single commit path: send the complete draft, adopt the server's
101
+ // returned agent as the new baseline, notify the host.
102
+ const commit = useCallback(async (next, successMessage) => {
103
+ try {
104
+ const updated = await updateSharing(next);
105
+ setDraft(updated ? draftFromAgent(updated) : next);
106
+ if (updated) {
107
+ setLinkToken(updated.status?.shareLinkToken ?? "");
108
+ }
109
+ toast.success(successMessage);
110
+ onSharingChanged?.();
111
+ return true;
112
+ }
113
+ catch (err) {
114
+ toast.error(getUserMessage(err));
115
+ return false;
116
+ }
117
+ }, [updateSharing, onSharingChanged]);
118
+ const handleRotateLink = useCallback(async () => {
119
+ try {
120
+ const updated = await rotateShareLink();
121
+ if (updated) {
122
+ setLinkToken(updated.status?.shareLinkToken ?? "");
123
+ }
124
+ toast.success("Link reset — the old link no longer works");
125
+ onSharingChanged?.();
126
+ }
127
+ catch (err) {
128
+ toast.error(getUserMessage(err));
129
+ }
130
+ }, [rotateShareLink, onSharingChanged]);
131
+ const handleToggle = useCallback((enabled) => {
132
+ void commit({ ...draft, enabled }, enabled ? "Sharing enabled" : "Sharing disabled");
133
+ }, [commit, draft]);
134
+ const handleAudienceChange = useCallback((audience) => {
135
+ if (audience === draft.audience)
136
+ return;
137
+ void commit({ ...draft, audience }, audience === "org"
138
+ ? "Only organization members can chat now"
139
+ : "Anyone with the link can chat now");
140
+ }, [commit, draft]);
141
+ const isOrgAudience = draft.audience === "org";
142
+ // Hosts build the base URL; the token rides it only on public shares
143
+ // (org-audience access is gated by membership, not the link token).
144
+ const baseShareUrl = buildShareUrl
145
+ ? buildShareUrl(org, slug)
146
+ : chatPath(org, slug);
147
+ const shareUrl = isOrgAudience
148
+ ? baseShareUrl
149
+ : appendLinkToken(baseShareUrl, linkToken);
150
+ return (_jsxs("div", { className: "flex flex-col", children: [_jsxs("div", { className: "flex items-start justify-between border-b border-border px-6 py-4", children: [_jsxs("div", { className: "min-w-0", children: [_jsx("h2", { id: "share-agent-title", className: "text-base font-semibold text-foreground", children: "Share" }), _jsx("p", { className: "mt-0.5 truncate text-xs text-muted-foreground", children: agentName })] }), _jsx("button", { type: "button", onClick: onClose, "aria-label": "Close", className: cn("rounded-md p-1 text-muted-foreground", "hover:text-foreground hover:bg-accent-hover", "focus:outline-none focus:ring-2 focus:ring-ring"), children: _jsx(CloseIcon, {}) })] }), _jsxs("div", { className: "border-b border-border px-6 py-4", children: [_jsxs("div", { className: "flex items-start justify-between gap-4", children: [_jsxs("div", { className: "min-w-0", children: [_jsx("span", { id: "share-enabled-label", className: "text-sm font-medium text-foreground", children: isOrgAudience
151
+ ? "Organization members can chat"
152
+ : "Anyone with the link can chat" }), _jsx(WhoPaysLine, { org: org, audience: draft.audience })] }), _jsx(Switch, { checked: draft.enabled, onCheckedChange: handleToggle, disabled: isPending, "aria-labelledby": "share-enabled-label" })] }), _jsx(AudienceSelector, { audience: draft.audience, onChange: handleAudienceChange, disabled: isPending }), _jsx(ToolReadinessHint, { agent: agent, enabled: draft.enabled })] }), _jsx("div", { className: "px-6 pb-2 pt-3", children: _jsx(Tabs, { tabs: SHARE_TABS, activeTab: activeTab, onTabChange: setActiveTab, "aria-label": "Sharing options", children: _jsxs("div", { className: "pt-4", children: [activeTab === "link" && (_jsx(LinkTab, { shareUrl: shareUrl, org: org, enabled: draft.enabled, draft: draft, isPending: isPending, commit: commit, hasLinkToken: linkToken !== "", isRotating: isRotating, onResetLink: handleRotateLink })), activeTab === "embed" && (_jsx(EmbedTab, { shareUrl: shareUrl, org: org, slug: slug, agentName: agentName, linkToken: linkToken, enabled: draft.enabled, draft: draft, isPending: isPending, commit: commit })), activeTab === "developer" && _jsx(DeveloperTab, { org: org, slug: slug })] }) }) }), _jsx("div", { className: "flex items-center justify-end border-t border-border px-6 py-3", children: _jsx("button", { type: "button", onClick: onClose, className: cn("rounded-md px-3 py-1.5 text-sm font-medium", "bg-primary text-primary-foreground hover:bg-primary-hover", "focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2"), children: "Done" }) })] }));
153
+ }
154
+ // ---------------------------------------------------------------------------
155
+ // Tool readiness — private credentials block visitors' tool use
156
+ // ---------------------------------------------------------------------------
157
+ /**
158
+ * Pre-flight hint for tool-using agents: visitors' chats can only use
159
+ * environments shared with the organization. Renders nothing unless the
160
+ * check finds bound environments that are still private — sharing stays
161
+ * one toggle; this only catches the misconfiguration at share time
162
+ * instead of at the visitor's first message.
163
+ */
164
+ function ToolReadinessHint({ agent, enabled, }) {
165
+ const readiness = useShareToolReadiness(agent, enabled);
166
+ if (readiness.status !== "blocked") {
167
+ return null;
168
+ }
169
+ const envList = readiness.privateEnvironments.join(", ");
170
+ const plural = readiness.privateEnvironments.length > 1;
171
+ return (_jsxs("p", { className: "mt-2 text-xs text-warning", role: "status", children: ["Visitors' chats can't use this agent's tools yet: the environment", plural ? "s" : "", " ", _jsx("span", { className: "font-medium", children: envList }), " ", plural ? "are" : "is", " private. Share ", plural ? "them" : "it", " with your organization (Settings \u2192 Environments) so visitor and teammate runs can use the credentials. Secret values stay hidden either way."] }));
172
+ }
173
+ // ---------------------------------------------------------------------------
174
+ // Audience — who can chat over the hosted link
175
+ // ---------------------------------------------------------------------------
176
+ const AUDIENCE_OPTIONS = [
177
+ { value: "public", label: "Public link" },
178
+ { value: "org", label: "Org members" },
179
+ ];
180
+ /**
181
+ * Segmented control choosing between the two sharing audiences. Mutually
182
+ * exclusive by nature, so a radio group (not toggles); the master switch
183
+ * above stays the single on/off.
184
+ */
185
+ function AudienceSelector({ audience, onChange, disabled, }) {
186
+ return (_jsx("div", { role: "radiogroup", "aria-label": "Who can chat", className: "mt-3 inline-flex rounded-md border border-border p-0.5", children: AUDIENCE_OPTIONS.map(({ value, label }) => {
187
+ const selected = audience === value;
188
+ return (_jsx("button", { type: "button", role: "radio", "aria-checked": selected, onClick: () => onChange(value), disabled: disabled, className: cn("rounded px-2.5 py-1 text-xs font-medium", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", "disabled:pointer-events-none disabled:opacity-50", selected
189
+ ? "bg-primary text-primary-foreground"
190
+ : "text-muted-foreground hover:text-foreground"), children: label }, value));
191
+ }) }));
192
+ }
193
+ // ---------------------------------------------------------------------------
194
+ // Who pays — cost attribution is always the org in the share URL
195
+ // ---------------------------------------------------------------------------
196
+ function WhoPaysLine({ org, audience, }) {
197
+ const mode = useDeploymentMode();
198
+ // An Organization's id equals its slug (see ApiResourceMetadata.id), so
199
+ // the agent's org reference is directly usable as the billing org id.
200
+ // Cloud-only: local mode has no billing accounts.
201
+ const { account } = useBillingAccount(mode === "cloud" ? org : null);
202
+ const balance = account?.balance !== undefined
203
+ ? formatCreditBalance(account.balance?.availableMicros)
204
+ : null;
205
+ return (_jsxs("p", { className: "mt-0.5 text-xs text-muted-foreground", children: [audience === "org" ? "Members" : "Visitors", " chat on", " ", _jsx("span", { className: "font-medium", children: org }), "'s credits", balance !== null && _jsxs(_Fragment, { children: [" (", balance, " available)"] }), "."] }));
206
+ }
207
+ // ---------------------------------------------------------------------------
208
+ // Link tab
209
+ // ---------------------------------------------------------------------------
210
+ function LinkTab({ shareUrl, org, enabled, draft, isPending, commit, hasLinkToken, isRotating, onResetLink, }) {
211
+ const isOrgAudience = draft.audience === "org";
212
+ return (_jsxs("div", { className: "flex flex-col gap-4", children: [_jsx(CopyField, { label: isOrgAudience ? "Member chat link" : "Public chat link", value: shareUrl, copyLabel: "Link", disabled: !enabled, openHref: enabled ? shareUrl : undefined }), isOrgAudience ? (_jsxs("p", { className: "text-xs text-muted-foreground", children: ["Only signed-in members of ", _jsx("span", { className: "font-medium", children: org }), " ", "can chat. Access is checked on every message, so it ends the moment someone leaves the organization. The link is safe to forward \u2014 it shows nothing to anyone else."] })) : (_jsx("p", { className: "text-xs text-warning", children: "Public links can be forwarded and indexed by search engines. Don't share agents that know internal or confidential information \u2014 or switch the audience to org members." })), !isOrgAudience && (_jsx(ResetLinkControl, { enabled: enabled, hasLinkToken: hasLinkToken, isRotating: isRotating, onResetLink: onResetLink })), _jsx(MessagesEditor, { draft: draft, isPending: isPending, commit: commit })] }));
213
+ }
214
+ /**
215
+ * The "kill a leaked link" lever: rotating generates a fresh `?k=` token
216
+ * so the old URL stops working immediately — sharing stays on, the agent
217
+ * keeps its name. Public audience only; org shares revoke via membership.
218
+ */
219
+ function ResetLinkControl({ enabled, hasLinkToken, isRotating, onResetLink, }) {
220
+ return (_jsx("section", { className: cn(!enabled && "opacity-50"), children: _jsxs("div", { className: "flex items-start justify-between gap-4", children: [_jsxs("div", { className: "min-w-0", children: [_jsx("h3", { className: "text-xs font-medium text-muted-foreground", children: "Reset link" }), _jsx("p", { className: "mt-0.5 text-[0.65rem] text-muted-foreground", children: hasLinkToken
221
+ ? "Generates a new link and kills the current one immediately — even mid-conversation. Re-share the new link with the people who should keep access."
222
+ : "Got forwarded further than you wanted? Resetting locks the link behind a secret and kills the plain address immediately." })] }), _jsx("button", { type: "button", onClick: onResetLink, disabled: !enabled || isRotating, className: cn("shrink-0 rounded-md px-2.5 py-1.5 text-xs font-medium", "border border-border text-foreground hover:bg-accent-hover", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", "disabled:pointer-events-none disabled:opacity-50"), children: isRotating ? "Resetting…" : "Reset link" })] }) }));
223
+ }
224
+ // ---------------------------------------------------------------------------
225
+ // Embed tab
226
+ // ---------------------------------------------------------------------------
227
+ /**
228
+ * The app origin the loader is served from — derived from the share URL
229
+ * the host built. Empty when the host never wired `buildShareUrl` (a
230
+ * relative share URL), which degrades {@link buildEmbedSnippet} to a
231
+ * relative `/embed.js` — same degradation as the relative link itself.
232
+ */
233
+ function appOriginFrom(shareUrl) {
234
+ try {
235
+ return new URL(shareUrl).origin;
236
+ }
237
+ catch {
238
+ return "";
239
+ }
240
+ }
241
+ /** The no-JavaScript alternative: a plain iframe onto the hosted page. */
242
+ function buildIframeSnippet(shareUrl, agentName) {
243
+ return [
244
+ `<iframe`,
245
+ ` src="${shareUrl}"`,
246
+ ` title="${agentName}"`,
247
+ ` width="400"`,
248
+ ` height="600"`,
249
+ ` style="border: 0; border-radius: 12px;"`,
250
+ `></iframe>`,
251
+ ].join("\n");
252
+ }
253
+ function EmbedTab({ shareUrl, org, slug, agentName, linkToken, enabled, draft, isPending, commit, }) {
254
+ const scriptSnippet = useMemo(() => buildEmbedSnippet(appOriginFrom(shareUrl), org, slug, linkToken || undefined), [shareUrl, org, slug, linkToken]);
255
+ // Embedding serves anonymous visitors via guest tokens, which an
256
+ // org-audience share refuses by design — a sign-in flow inside a
257
+ // third-party iframe is its own project. Say so instead of showing
258
+ // snippets that would render nothing.
259
+ if (draft.audience === "org") {
260
+ return (_jsxs("p", { className: "text-xs text-muted-foreground", role: "status", children: ["Embedding isn't available for org-members-only sharing: embeds serve anonymous visitors, and this agent requires a signed-in organization member. Switch the audience to", " ", _jsx("span", { className: "font-medium", children: "Public link" }), " to embed it on a site."] }));
261
+ }
262
+ return (_jsxs("div", { className: "flex flex-col gap-4", children: [_jsx(CopyField, { label: "Embed on your site", value: scriptSnippet, copyLabel: "Embed code", disabled: !enabled, multiline: true }), _jsx("p", { className: "text-xs text-muted-foreground", children: "The widget hides itself on sites that aren't allowed to embed this agent. Free embeds show a \"Powered by Stigmer\" badge." }), _jsx(OriginsEditor, { draft: draft, isPending: isPending, commit: commit }), _jsx(IframeAlternative, { shareUrl: shareUrl, agentName: agentName, enabled: enabled })] }));
263
+ }
264
+ /**
265
+ * Collapsible fallback for hosts that cannot run scripts (locked-down CMSes,
266
+ * strict sanitizers). Same widget, same origin enforcement — minus the
267
+ * hide-on-refusal behavior the loader provides.
268
+ */
269
+ function IframeAlternative({ shareUrl, agentName, enabled, }) {
270
+ const [expanded, setExpanded] = useState(false);
271
+ const snippet = useMemo(() => buildIframeSnippet(shareUrl, agentName), [shareUrl, agentName]);
272
+ return (_jsxs("section", { children: [_jsxs("button", { type: "button", onClick: () => setExpanded((v) => !v), "aria-expanded": expanded, className: cn("inline-flex items-center gap-1 text-xs font-medium text-muted-foreground", "hover:text-foreground", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded"), children: [_jsx(ChevronIcon, { className: cn("size-3 transition-transform", expanded && "rotate-90") }), "No-JavaScript alternative"] }), expanded && (_jsxs("div", { className: "mt-2 flex flex-col gap-2", children: [_jsx("p", { className: "text-[0.65rem] text-muted-foreground", children: "For sites that can't run scripts. A blocked embed shows an empty frame instead of hiding." }), _jsx(CopyField, { label: "Iframe embed", value: snippet, copyLabel: "Iframe code", disabled: !enabled, multiline: true })] }))] }));
273
+ }
274
+ // ---------------------------------------------------------------------------
275
+ // Allowed origins editor
276
+ // ---------------------------------------------------------------------------
277
+ function OriginsEditor({ draft, isPending, commit, }) {
278
+ const [newOrigin, setNewOrigin] = useState("");
279
+ const [inputError, setInputError] = useState(null);
280
+ const handleAdd = useCallback(async () => {
281
+ const value = newOrigin.trim();
282
+ const validationError = validateOrigin(value);
283
+ if (validationError) {
284
+ setInputError(validationError);
285
+ return;
286
+ }
287
+ if (draft.allowedOrigins.includes(value)) {
288
+ setInputError("That origin is already in the list");
289
+ return;
290
+ }
291
+ if (draft.allowedOrigins.length >= MAX_ALLOWED_ORIGINS) {
292
+ setInputError(`At most ${MAX_ALLOWED_ORIGINS} origins are allowed`);
293
+ return;
294
+ }
295
+ setInputError(null);
296
+ const ok = await commit({ ...draft, allowedOrigins: [...draft.allowedOrigins, value] }, "Origin added");
297
+ if (ok)
298
+ setNewOrigin("");
299
+ }, [newOrigin, draft, commit]);
300
+ const handleRemove = useCallback((origin) => {
301
+ void commit({
302
+ ...draft,
303
+ allowedOrigins: draft.allowedOrigins.filter((o) => o !== origin),
304
+ }, "Origin removed");
305
+ }, [draft, commit]);
306
+ return (_jsxs("section", { children: [_jsx("h3", { className: "text-xs font-medium text-muted-foreground", children: "Allowed embed origins" }), _jsx("p", { className: "mt-0.5 text-[0.65rem] text-muted-foreground", children: "Sites allowed to embed this agent. An empty list allows any site; adding origins restricts embedding to those sites. The hosted link works either way." }), draft.allowedOrigins.length > 0 && (_jsx("ul", { className: "mt-2 flex flex-col divide-y divide-border rounded-md border border-border", children: draft.allowedOrigins.map((origin) => (_jsxs("li", { className: "flex items-center justify-between gap-2 px-2.5 py-1.5", children: [_jsx("code", { className: "truncate font-mono text-xs text-foreground", children: origin }), _jsx("button", { type: "button", onClick: () => handleRemove(origin), disabled: isPending, "aria-label": `Remove ${origin}`, className: cn("inline-flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground", "hover:bg-destructive-subtle hover:text-destructive", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", "disabled:pointer-events-none disabled:opacity-50"), children: _jsx(RemoveIcon, {}) })] }, origin))) })), _jsxs("div", { className: "mt-2 flex items-start gap-1.5", children: [_jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("input", { type: "text", value: newOrigin, onChange: (e) => {
307
+ setNewOrigin(e.target.value);
308
+ if (inputError)
309
+ setInputError(null);
310
+ }, onKeyDown: (e) => {
311
+ if (e.key === "Enter") {
312
+ e.preventDefault();
313
+ void handleAdd();
314
+ }
315
+ }, placeholder: "https://example.com", "aria-label": "Add allowed origin", "aria-invalid": inputError != null, className: cn("w-full rounded-md border border-border bg-input-bg px-2 py-1.5 font-mono text-xs text-foreground", "focus:outline-none focus:ring-2 focus:ring-ring") }), inputError && (_jsx("p", { role: "alert", className: "mt-1 text-xs text-destructive", children: inputError }))] }), _jsx("button", { type: "button", onClick: () => void handleAdd(), disabled: isPending || !newOrigin.trim(), className: cn("shrink-0 rounded-md px-2.5 py-1.5 text-xs font-medium", "border border-border text-foreground hover:bg-accent-hover", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", "disabled:pointer-events-none disabled:opacity-50"), children: "Add" })] })] }));
316
+ }
317
+ // ---------------------------------------------------------------------------
318
+ // Visitor messages editor (collapsible)
319
+ // ---------------------------------------------------------------------------
320
+ const MESSAGE_FIELDS = [
321
+ {
322
+ key: "rateLimited",
323
+ label: "Rate limited",
324
+ placeholder: "Shown when a visitor sends messages too quickly",
325
+ },
326
+ {
327
+ key: "unavailable",
328
+ label: "Unavailable",
329
+ placeholder: "Shown when the agent is temporarily unavailable",
330
+ },
331
+ {
332
+ key: "conversationEnded",
333
+ label: "Conversation ended",
334
+ placeholder: "Shown when a conversation reaches its limit",
335
+ },
336
+ ];
337
+ function MessagesEditor({ draft, isPending, commit, }) {
338
+ const [expanded, setExpanded] = useState(false);
339
+ const [localMessages, setLocalMessages] = useState(draft.messages);
340
+ const isDirty = localMessages.rateLimited !== draft.messages.rateLimited ||
341
+ localMessages.unavailable !== draft.messages.unavailable ||
342
+ localMessages.conversationEnded !== draft.messages.conversationEnded;
343
+ const handleSave = useCallback(() => {
344
+ void commit({ ...draft, messages: localMessages }, "Messages saved");
345
+ }, [commit, draft, localMessages]);
346
+ return (_jsxs("section", { children: [_jsxs("button", { type: "button", onClick: () => setExpanded((v) => !v), "aria-expanded": expanded, className: cn("inline-flex items-center gap-1 text-xs font-medium text-muted-foreground", "hover:text-foreground", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded"), children: [_jsx(ChevronIcon, { className: cn("size-3 transition-transform", expanded && "rotate-90") }), "Customize visitor messages"] }), expanded && (_jsxs("div", { className: "mt-2 flex flex-col gap-3", children: [_jsx("p", { className: "text-[0.65rem] text-muted-foreground", children: "Shown to visitors when a limit is reached. Leave empty to use the platform defaults." }), MESSAGE_FIELDS.map(({ key, label, placeholder }) => (_jsx(MessageField, { label: label, placeholder: placeholder, value: localMessages[key], onChange: (value) => setLocalMessages((prev) => ({ ...prev, [key]: value })) }, key))), isDirty && (_jsxs("div", { className: "flex items-center justify-end gap-1.5", children: [_jsx("button", { type: "button", onClick: () => setLocalMessages(draft.messages), disabled: isPending, className: cn("rounded-md px-2.5 py-1 text-xs font-medium", "border border-border text-foreground hover:bg-accent-hover", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"), children: "Reset" }), _jsx("button", { type: "button", onClick: handleSave, disabled: isPending, className: cn("rounded-md px-2.5 py-1 text-xs font-medium", "bg-primary text-primary-foreground hover:bg-primary-hover", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", "disabled:pointer-events-none disabled:opacity-50"), children: "Save messages" })] }))] }))] }));
347
+ }
348
+ function MessageField({ label, placeholder, value, onChange, }) {
349
+ return (_jsxs("label", { className: "flex flex-col gap-1", children: [_jsxs("span", { className: "flex items-center justify-between text-xs font-medium text-muted-foreground", children: [label, _jsxs("span", { className: "tabular-nums text-[0.65rem]", children: [value.length, "/", MAX_MESSAGE_LENGTH] })] }), _jsx("textarea", { value: value, onChange: (e) => onChange(e.target.value.slice(0, MAX_MESSAGE_LENGTH)), placeholder: placeholder, rows: 2, maxLength: MAX_MESSAGE_LENGTH, className: cn("w-full resize-y rounded-md border border-border bg-input-bg px-2 py-1.5 text-xs text-foreground", "focus:outline-none focus:ring-2 focus:ring-ring") })] }));
350
+ }
351
+ // ---------------------------------------------------------------------------
352
+ // Developer tab — the graduation ladder to the full SDK
353
+ // ---------------------------------------------------------------------------
354
+ function buildDeveloperSnippet(org, slug) {
355
+ return [
356
+ `import { createPlatformClientAuth } from "@stigmer/sdk/node";`,
357
+ ``,
358
+ `const auth = createPlatformClientAuth({`,
359
+ ` baseUrl: "https://api.stigmer.ai",`,
360
+ ` clientId: process.env.STIGMER_CLIENT_ID,`,
361
+ ` clientSecret: process.env.STIGMER_CLIENT_SECRET,`,
362
+ `});`,
363
+ ``,
364
+ `// Mint tokens for your own users, then chat with ${org}/${slug}`,
365
+ `const { accessToken } = await auth.mintUserToken({`,
366
+ ` userId: "user-123",`,
367
+ `});`,
368
+ ].join("\n");
369
+ }
370
+ function DeveloperTab({ org, slug, }) {
371
+ const snippet = useMemo(() => buildDeveloperSnippet(org, slug), [org, slug]);
372
+ return (_jsxs("div", { className: "flex flex-col gap-3", children: [_jsx("p", { className: "text-xs text-muted-foreground", children: "Need your own auth, branding, or UI? Create a platform client and integrate this agent with the Stigmer SDK \u2014 the same runtime, full control." }), _jsx(CopyField, { label: "Platform client integration", value: snippet, copyLabel: "Code", multiline: true }), _jsx("a", { href: PLATFORM_CLIENT_DOCS_URL, target: "_blank", rel: "noreferrer", className: cn("text-xs font-medium text-primary hover:text-primary-muted", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded"), children: "Read the platform client guide \u2192" })] }));
373
+ }
374
+ // ---------------------------------------------------------------------------
375
+ // Copy field — labeled value with copy (and optional open) affordances
376
+ // ---------------------------------------------------------------------------
377
+ function CopyField({ label, value, copyLabel, disabled, multiline, openHref, }) {
378
+ const { copy } = useCopyResource();
379
+ return (_jsxs("section", { className: cn(disabled && "opacity-50"), children: [_jsx("h3", { className: "text-xs font-medium text-muted-foreground", children: label }), _jsxs("div", { className: "mt-1.5 flex items-start gap-1.5", children: [multiline ? (_jsx("pre", { className: cn("min-w-0 flex-1 overflow-x-auto rounded-md border border-border bg-muted-subtle px-2.5 py-2", "font-mono text-xs leading-relaxed text-foreground"), children: value })) : (_jsx("code", { className: cn("min-w-0 flex-1 truncate rounded-md border border-border bg-muted-subtle px-2.5 py-1.5", "font-mono text-xs text-foreground"), title: value, children: value })), _jsxs("div", { className: "flex shrink-0 flex-col gap-1.5", children: [_jsx("button", { type: "button", onClick: () => void copy(value, copyLabel), disabled: disabled, className: cn("rounded-md px-2.5 py-1.5 text-xs font-medium", "border border-border text-foreground hover:bg-accent-hover", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", "disabled:pointer-events-none disabled:opacity-50"), children: "Copy" }), openHref && (_jsx("a", { href: openHref, target: "_blank", rel: "noreferrer", className: cn("rounded-md px-2.5 py-1.5 text-center text-xs font-medium", "border border-border text-foreground hover:bg-accent-hover", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"), children: "Open" }))] })] })] }));
380
+ }
381
+ // ---------------------------------------------------------------------------
382
+ // Icons — inline SVGs following the SDK pattern (no icon library dependency)
383
+ // ---------------------------------------------------------------------------
384
+ function CloseIcon() {
385
+ return (_jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M4 4l8 8M12 4l-8 8", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" }) }));
386
+ }
387
+ function RemoveIcon() {
388
+ return (_jsx("svg", { width: "12", height: "12", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", "aria-hidden": "true", children: _jsx("path", { d: "m4 4 8 8M12 4l-8 8" }) }));
389
+ }
390
+ function ChevronIcon({ className }) {
391
+ return (_jsx("svg", { className: className, viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m6 3 5 5-5 5" }) }));
392
+ }
393
+ //# sourceMappingURL=ShareAgentDialog.js.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,GAAG,GAC3B,CACP,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,EAAE,SAAS,EAAmC;IACjE,OAAO,CACL,cACE,SAAS,EAAE,SAAS,EACpB,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,iBACV,MAAM,YAElB,eAAM,CAAC,EAAC,cAAc,GAAG,GACrB,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,84 @@
1
+ import type { SharingAudience } from "./useUpdateAgentSharing.js";
2
+ /** Props for {@link SharedAgentChat}. */
3
+ export interface SharedAgentChatProps {
4
+ /** Organization slug from the share URL. */
5
+ readonly org: string;
6
+ /** Agent slug from the share URL. */
7
+ readonly slug: string;
8
+ /**
9
+ * Heading above the composer before the first message.
10
+ * Defaults to a prompt built from the agent's name.
11
+ */
12
+ readonly heading?: string;
13
+ /** Placeholder for the composer textarea. */
14
+ readonly placeholder?: string;
15
+ /**
16
+ * Render the "Powered by Stigmer" footer.
17
+ *
18
+ * @default true
19
+ */
20
+ readonly showPoweredBy?: boolean;
21
+ /**
22
+ * Called after the visitor's session and first execution are
23
+ * created — e.g. to reflect the session in the host page's URL.
24
+ */
25
+ readonly onSessionCreated?: (sessionId: string) => void;
26
+ /**
27
+ * Which sharing audience this surface serves. Selects the profile
28
+ * resolution path: `"public"` uses the anonymous `getSharedProfile`
29
+ * RPC (pair with `createGuestAuth`); `"org"` uses the authenticated
30
+ * `getSharedProfileForMember` RPC and requires a `StigmerProvider`
31
+ * whose client carries a signed-in org member's token. The chat
32
+ * presentation is identical either way.
33
+ *
34
+ * @default "public"
35
+ */
36
+ readonly sharingAudience?: SharingAudience;
37
+ /**
38
+ * Share-link token from the URL's `?k=` parameter (public audience
39
+ * only). Required when the share link has been locked with a
40
+ * rotatable token; harmless on plain links. Pair it with the same
41
+ * `linkToken` on `createGuestAuth` so profile resolution and token
42
+ * minting present the same credentialing.
43
+ */
44
+ readonly linkToken?: string;
45
+ /** Additional CSS class names for the root container. */
46
+ readonly className?: string;
47
+ }
48
+ /**
49
+ * The complete shared-agent chat experience for anonymous visitors —
50
+ * the organism behind a shared agent's hosted page and embeds.
51
+ *
52
+ * Resolves the agent's public profile (name, description, icon, and
53
+ * the pinned deployment) via {@link useSharedAgentProfile}, then
54
+ * renders the session organisms with `audience="guest"`: a pure chat
55
+ * surface with no configuration pickers, pinned to the shared agent's
56
+ * default instance so the session binds synchronously on mount.
57
+ *
58
+ * Handles all states: loading, unavailable (the agent does not exist
59
+ * or is not shared — indistinguishable by design), transient errors
60
+ * (with retry), and the live chat.
61
+ *
62
+ * **Auth contract:** requires a `StigmerProvider` whose client can
63
+ * chat with this agent. For public shares (the default), pair with
64
+ * `createGuestAuth({ baseUrl, org, slug })` from `@stigmer/sdk` —
65
+ * the profile fetch is public and sessions use the guest token the
66
+ * provider mints on demand. For org-members-only shares, pass
67
+ * `sharingAudience="org"` and a client carrying the signed-in
68
+ * member's own token; the presentation stays the same pure chat.
69
+ *
70
+ * @example
71
+ * ```tsx
72
+ * const guestAuth = createGuestAuth({ baseUrl, org, slug });
73
+ * const client = useMemo(
74
+ * () => new Stigmer({ baseUrl, getAccessToken: guestAuth.getAccessToken }),
75
+ * [guestAuth],
76
+ * );
77
+ *
78
+ * <StigmerProvider client={client} colorMode="system">
79
+ * <SharedAgentChat org={org} slug={slug} />
80
+ * </StigmerProvider>
81
+ * ```
82
+ */
83
+ export declare function SharedAgentChat({ org, slug, heading, placeholder, showPoweredBy, onSessionCreated, sharingAudience, linkToken, className, }: SharedAgentChatProps): import("react/jsx-runtime").JSX.Element;
84
+ //# sourceMappingURL=SharedAgentChat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SharedAgentChat.d.ts","sourceRoot":"","sources":["../../src/sharing/SharedAgentChat.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAMlE,yCAAyC;AACzC,MAAM,WAAW,oBAAoB;IACnC,4CAA4C;IAC5C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,qCAAqC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,6CAA6C;IAC7C,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IACjC;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACxD;;;;;;;;;OASG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,eAAe,CAAC;IAC3C;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,yDAAyD;IACzD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,eAAe,CAAC,EAC9B,GAAG,EACH,IAAI,EACJ,OAAO,EACP,WAAW,EACX,aAAoB,EACpB,gBAAgB,EAChB,eAA0B,EAC1B,SAAS,EACT,SAAS,GACV,EAAE,oBAAoB,2CAoItB"}
@@ -0,0 +1,80 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useCallback, useState } from "react";
4
+ import { cn } from "@stigmer/theme";
5
+ import { getUserMessage } from "@stigmer/sdk";
6
+ import { NewSessionViewer } from "../session/NewSessionViewer.js";
7
+ import { SessionViewer } from "../session/SessionViewer.js";
8
+ import { useSharedAgentProfile } from "./useSharedAgentProfile.js";
9
+ /**
10
+ * The complete shared-agent chat experience for anonymous visitors —
11
+ * the organism behind a shared agent's hosted page and embeds.
12
+ *
13
+ * Resolves the agent's public profile (name, description, icon, and
14
+ * the pinned deployment) via {@link useSharedAgentProfile}, then
15
+ * renders the session organisms with `audience="guest"`: a pure chat
16
+ * surface with no configuration pickers, pinned to the shared agent's
17
+ * default instance so the session binds synchronously on mount.
18
+ *
19
+ * Handles all states: loading, unavailable (the agent does not exist
20
+ * or is not shared — indistinguishable by design), transient errors
21
+ * (with retry), and the live chat.
22
+ *
23
+ * **Auth contract:** requires a `StigmerProvider` whose client can
24
+ * chat with this agent. For public shares (the default), pair with
25
+ * `createGuestAuth({ baseUrl, org, slug })` from `@stigmer/sdk` —
26
+ * the profile fetch is public and sessions use the guest token the
27
+ * provider mints on demand. For org-members-only shares, pass
28
+ * `sharingAudience="org"` and a client carrying the signed-in
29
+ * member's own token; the presentation stays the same pure chat.
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * const guestAuth = createGuestAuth({ baseUrl, org, slug });
34
+ * const client = useMemo(
35
+ * () => new Stigmer({ baseUrl, getAccessToken: guestAuth.getAccessToken }),
36
+ * [guestAuth],
37
+ * );
38
+ *
39
+ * <StigmerProvider client={client} colorMode="system">
40
+ * <SharedAgentChat org={org} slug={slug} />
41
+ * </StigmerProvider>
42
+ * ```
43
+ */
44
+ export function SharedAgentChat({ org, slug, heading, placeholder, showPoweredBy = true, onSessionCreated, sharingAudience = "public", linkToken, className, }) {
45
+ const { profile, isLoading, error, refetch } = useSharedAgentProfile(org, slug, {
46
+ audience: sharingAudience,
47
+ linkToken,
48
+ });
49
+ const [sessionId, setSessionId] = useState(null);
50
+ const [submitError, setSubmitError] = useState(null);
51
+ const handleSessionCreated = useCallback((id) => {
52
+ setSubmitError(null);
53
+ setSessionId(id);
54
+ onSessionCreated?.(id);
55
+ }, [onSessionCreated]);
56
+ if (isLoading) {
57
+ return (_jsx("div", { className: cn("flex h-full w-full items-center justify-center", className), "aria-busy": "true", "aria-label": "Loading agent", children: _jsx(LoadingSkeleton, {}) }));
58
+ }
59
+ if (error) {
60
+ return (_jsx("div", { className: cn("flex h-full w-full items-center justify-center", className), children: _jsx(StateCard, { title: "Something went wrong", message: getUserMessage(error), onRetry: refetch }) }));
61
+ }
62
+ // NOT_FOUND covers both "no such agent" and "sharing disabled" — the
63
+ // server keeps them indistinguishable so a revoked link leaks nothing.
64
+ // A profile without a default instance is equally unusable: there is
65
+ // no deployment to chat with, so it presents as the same state.
66
+ if (!profile || !profile.defaultInstanceId) {
67
+ return (_jsx("div", { className: cn("flex h-full w-full items-center justify-center", className), children: _jsx(StateCard, { title: "This agent isn't available", message: "The link may be incorrect, or sharing may have been turned off." }) }));
68
+ }
69
+ return (_jsxs("div", { className: cn("flex h-full w-full flex-col", className), children: [_jsxs("header", { className: "flex items-center gap-3 border-b border-border px-4 py-3", children: [profile.iconUrl ? (_jsx("img", { src: profile.iconUrl, alt: "", className: "size-8 rounded-md object-cover" })) : (_jsx("div", { "aria-hidden": "true", className: "flex size-8 items-center justify-center rounded-md bg-muted text-sm font-semibold text-muted-foreground", children: (profile.name || slug).charAt(0).toUpperCase() })), _jsxs("div", { className: "min-w-0", children: [_jsx("h1", { className: "truncate text-sm font-semibold text-foreground", children: profile.name || slug }), profile.description && (_jsx("p", { className: "truncate text-xs text-muted-foreground", children: profile.description }))] })] }), _jsx("div", { className: "min-h-0 flex-1", children: sessionId ? (_jsx(SessionViewer, { sessionId: sessionId, org: org, audience: "guest", enableGitHub: false })) : (_jsx(NewSessionViewer, { org: org, audience: "guest", initialAgentRef: { org, slug }, initialInstanceId: profile.defaultInstanceId, enableGitHub: false, heading: heading ?? `Chat with ${profile.name || slug}`, placeholder: placeholder ?? "Ask anything\u2026", onSessionCreated: handleSessionCreated, onError: setSubmitError, footerContent: submitError ? (_jsx("p", { role: "alert", className: "text-center text-xs text-destructive", children: submitError })) : undefined })) }), showPoweredBy && (_jsx("footer", { className: "border-t border-border px-4 py-2 text-center", children: _jsx("a", { href: "https://stigmer.ai", target: "_blank", rel: "noopener noreferrer", className: "text-[0.65rem] text-muted-foreground hover:text-foreground transition-colors", children: "Powered by Stigmer" }) }))] }));
70
+ }
71
+ // ---------------------------------------------------------------------------
72
+ // State presentation
73
+ // ---------------------------------------------------------------------------
74
+ function LoadingSkeleton() {
75
+ return (_jsxs("div", { className: "w-full max-w-sm space-y-3 px-6", children: [_jsx("div", { className: "mx-auto h-8 w-8 animate-pulse rounded-md bg-muted" }), _jsx("div", { className: "mx-auto h-4 w-2/3 animate-pulse rounded bg-muted" }), _jsx("div", { className: "mx-auto h-3 w-1/2 animate-pulse rounded bg-muted" })] }));
76
+ }
77
+ function StateCard({ title, message, onRetry, }) {
78
+ return (_jsxs("div", { className: "mx-6 w-full max-w-sm rounded-lg border border-border bg-card p-6 text-center shadow-sm", children: [_jsx("h2", { className: "text-base font-semibold text-foreground", children: title }), _jsx("p", { className: "mt-1 text-sm text-muted-foreground", children: message }), onRetry && (_jsx("button", { type: "button", onClick: onRetry, className: cn("mt-4 inline-flex items-center justify-center rounded-md px-4 py-2 text-sm font-medium", "bg-primary text-primary-foreground hover:bg-primary-hover", "transition-colors"), children: "Try again" }))] }));
79
+ }
80
+ //# sourceMappingURL=SharedAgentChat.js.map