@burdenoff/microfe-healthybowl 2026.629.1 → 2026.629.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.
- package/dist/components/assistant/AIAssistantPanel.js +6 -6
- package/dist/components/assistant/AssistantApiCallsConsentDialog.js +4 -4
- package/dist/components/assistant/AssistantChatArea.js +45 -45
- package/dist/components/assistant/AssistantMessageItem.js +5 -5
- package/dist/config/assistantUsecases.js +4 -4
- package/dist/config/assistantUsecases.js.map +1 -1
- package/dist/healthybowl/components/GetHelpButton.js +20 -0
- package/dist/healthybowl/components/GetHelpButton.js.map +1 -0
- package/dist/healthybowl/components/PageLayout.js +31 -30
- package/dist/healthybowl/components/PageLayout.js.map +1 -1
- package/dist/hooks/useAssistantApiAccess.js +19 -18
- package/dist/hooks/useAssistantApiAccess.js.map +1 -1
- package/dist/index.js +5 -5
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useAssistantStore as e } from "../../store/assistantStore.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { useTr as t } from "../../shared/hooks/useTr.js";
|
|
3
|
+
import { useAssistantKeyboardShortcuts as n } from "../../hooks/useAssistantKeyboardShortcuts.js";
|
|
4
|
+
import { useAssistantHeartbeat as r } from "../../hooks/useAssistantHeartbeat.js";
|
|
5
5
|
import { AssistantChatArea as i } from "./AssistantChatArea.js";
|
|
6
6
|
import { AssistantConversationList as a } from "./AssistantConversationList.js";
|
|
7
7
|
import { AssistantExportMenu as o } from "./AssistantExportMenu.js";
|
|
@@ -10,10 +10,10 @@ import { Eraser as c, MessageSquare as l, X as u } from "lucide-react";
|
|
|
10
10
|
import { jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
11
11
|
//#region src/components/assistant/AIAssistantPanel.tsx
|
|
12
12
|
var p = ({ onClose: p, visible: m }) => {
|
|
13
|
-
let h =
|
|
14
|
-
|
|
13
|
+
let h = t(), g = s(null), { conversations: _, activeConversationId: v, conversationListOpen: y, toggleConversationList: b, clearConversation: x } = e(), S = _.find((e) => e.id === v);
|
|
14
|
+
r(S?.backendSessionId ?? null, S?.mode ?? null, m ?? !0);
|
|
15
15
|
let C = (S?.messages.length ?? 0) > 0;
|
|
16
|
-
return
|
|
16
|
+
return n({
|
|
17
17
|
panelRef: g,
|
|
18
18
|
onClose: p
|
|
19
19
|
}), /* @__PURE__ */ f("div", {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useTr as e } from "../../shared/hooks/useTr.js";
|
|
2
|
+
import { Modal as t } from "../../healthybowl/components/Modal.js";
|
|
3
3
|
import { Fragment as n, jsx as r, jsxs as i } from "react/jsx-runtime";
|
|
4
4
|
import { Button as a } from "@burdenoff/fe-libs/ui";
|
|
5
5
|
//#region src/components/assistant/AssistantApiCallsConsentDialog.tsx
|
|
6
6
|
var o = ({ open: o, onConfirm: s, onCancel: c }) => {
|
|
7
|
-
let l =
|
|
8
|
-
return /* @__PURE__ */ r(
|
|
7
|
+
let l = e();
|
|
8
|
+
return /* @__PURE__ */ r(t, {
|
|
9
9
|
open: o,
|
|
10
10
|
onClose: c,
|
|
11
11
|
size: "sm",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useAssistantStore as e } from "../../store/assistantStore.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { useTr as t } from "../../shared/hooks/useTr.js";
|
|
3
|
+
import { checkAssistantAiCredits as n, createAssistantSandbox as r, createAssistantSession as i, extendAssistantSandboxTTL as a, findExistingSandbox as o, getAssistantArtifacts as s, getAssistantMessages as c, getAssistantSession as l, reportAssistantAiTokenUsage as u, sendAssistantPromptAsync as d, waitForAssistantServiceReady as f, waitForSandboxReady as p } from "../../services/assistantApi.js";
|
|
4
4
|
import { AssistantChatInput as m } from "./AssistantChatInput.js";
|
|
5
5
|
import { AssistantMessageList as h } from "./AssistantMessageList.js";
|
|
6
6
|
import { ASSISTANT_MODES as g } from "../../types/assistant.js";
|
|
@@ -95,7 +95,7 @@ function ye(e) {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
var O = () => {
|
|
98
|
-
let w =
|
|
98
|
+
let w = t(), T = ue("workspace"), { getAccessToken: E, getWorkspaceToken: D, userId: O } = de(), { conversations: k, activeConversationId: A, mode: j, processingByConversationId: M, setMode: N, setConversationMode: P, setActiveConversation: F, createConversation: I, addMessage: L, updateMessage: R, patchMessage: z, setConversationProcessing: B, clearConversationProcessing: be, setBackendSessionId: V, clearBackendSessionId: H, setSandbox: U, clearSandbox: W, acknowledgeApiCalls: xe } = e(), Se = k.find((e) => e.id === A)?.messages ?? [], G = A ? M[A] : void 0, Ce = G?.messageId ?? null, we = G?.status === "provisioning" || G?.status === "connecting" || G?.status === "streaming", { canUseApiCalls: K, loading: Te } = te(he()), Ee = se(() => g.filter((e) => !e.requiresAdmin || K), [K]), [q, J] = le(null);
|
|
99
99
|
b(() => {
|
|
100
100
|
if (Te) return;
|
|
101
101
|
let e = g.find((e) => e.id === j);
|
|
@@ -108,27 +108,27 @@ var O = () => {
|
|
|
108
108
|
]);
|
|
109
109
|
let Y = y((e, t, n, r) => {
|
|
110
110
|
B(e, n, t, null), r ? R(e, t, r) : R(e, t, ye(n));
|
|
111
|
-
}, [B, R]), X = y(async (t,
|
|
112
|
-
let u = e.getState().sandboxesByMode[
|
|
111
|
+
}, [B, R]), X = y(async (t, n, a, s, c) => {
|
|
112
|
+
let u = e.getState().sandboxesByMode[a]?.sandboxId ?? null;
|
|
113
113
|
if (!u) {
|
|
114
|
-
Y(t,
|
|
115
|
-
let e = await
|
|
116
|
-
if (e) u = e, U(
|
|
114
|
+
Y(t, n, "provisioning", "Looking for existing environment...");
|
|
115
|
+
let e = await o(T, s, a, c);
|
|
116
|
+
if (e) u = e, U(a, u, "provisioning"), Y(t, n, "provisioning", "Reusing assistant environment..."), await p(T, u, s, c, 3e5, (e) => Y(t, n, "provisioning", e)), await f(T, u, s, c, 9e4, (e) => Y(t, n, "connecting", e)), U(a, u, "running");
|
|
117
117
|
else {
|
|
118
|
-
if (
|
|
119
|
-
Y(t,
|
|
118
|
+
if (a === "api-calls" && !E()) throw Error("API Calls mode requires an authenticated session. Please sign in again.");
|
|
119
|
+
Y(t, n, "provisioning", "Starting assistant environment..."), U(a, null, "provisioning"), u = await r(T, a, s, c), U(a, u, "provisioning"), await p(T, u, s, c, 3e5, (e) => Y(t, n, "provisioning", e)), await f(T, u, s, c, 9e4, (e) => Y(t, n, "connecting", e)), U(a, u, "running");
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
let
|
|
123
|
-
if (
|
|
124
|
-
let e = await
|
|
125
|
-
if (e.mode !==
|
|
122
|
+
let d = e.getState().conversations.find((e) => e.id === t)?.backendSessionId ?? null;
|
|
123
|
+
if (d) try {
|
|
124
|
+
let e = await l(T, u, s, d, c);
|
|
125
|
+
if (e.mode !== a) throw Error(`Session mode mismatch: expected ${a}, received ${e.mode}`);
|
|
126
126
|
} catch {
|
|
127
|
-
H(t),
|
|
127
|
+
H(t), d = null;
|
|
128
128
|
}
|
|
129
|
-
return
|
|
129
|
+
return d || (Y(t, n, "connecting", "Preparing session..."), d = (await i(T, u, s, a, c)).sessionId, V(t, d)), {
|
|
130
130
|
sandboxId: u,
|
|
131
|
-
sessionId:
|
|
131
|
+
sessionId: d
|
|
132
132
|
};
|
|
133
133
|
}, [
|
|
134
134
|
T,
|
|
@@ -137,14 +137,14 @@ var O = () => {
|
|
|
137
137
|
V,
|
|
138
138
|
U,
|
|
139
139
|
Y
|
|
140
|
-
]), Z = y(async (
|
|
140
|
+
]), Z = y(async (t) => {
|
|
141
141
|
if (A) {
|
|
142
142
|
let e = M[A]?.status;
|
|
143
143
|
if (e === "provisioning" || e === "connecting" || e === "streaming") return;
|
|
144
144
|
}
|
|
145
|
-
let r = e.getState().mode,
|
|
146
|
-
if (
|
|
147
|
-
let
|
|
145
|
+
let r = e.getState().mode, i = A, o = i ? e.getState().conversations.find((e) => e.id === i) : void 0;
|
|
146
|
+
if (i ? o && o.mode !== r && (o.messages.length > 0 || o.backendSessionId) ? i = I(void 0, r) : o && o.mode !== r && P(i, r) : i = I(void 0, r), !i) return;
|
|
147
|
+
let l = me(), f = {
|
|
148
148
|
accessToken: E(),
|
|
149
149
|
workspaceToken: D(),
|
|
150
150
|
userId: O,
|
|
@@ -152,71 +152,71 @@ var O = () => {
|
|
|
152
152
|
}, p = {
|
|
153
153
|
id: C(),
|
|
154
154
|
role: "user",
|
|
155
|
-
content:
|
|
155
|
+
content: t,
|
|
156
156
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
157
157
|
};
|
|
158
|
-
L(
|
|
158
|
+
L(i, p);
|
|
159
159
|
let m = C();
|
|
160
|
-
L(
|
|
160
|
+
L(i, {
|
|
161
161
|
id: m,
|
|
162
162
|
role: "assistant",
|
|
163
163
|
content: "",
|
|
164
164
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
165
165
|
});
|
|
166
|
-
let h = (e, t, n,
|
|
167
|
-
z(
|
|
166
|
+
let h = (e, t, n, a) => {
|
|
167
|
+
z(i, m, {
|
|
168
168
|
content: _e(e),
|
|
169
|
-
metadata: t?.length || n ||
|
|
169
|
+
metadata: t?.length || n || a ? {
|
|
170
170
|
artifacts: t,
|
|
171
171
|
mode: r,
|
|
172
172
|
sessionId: n,
|
|
173
|
-
sandboxId:
|
|
173
|
+
sandboxId: a
|
|
174
174
|
} : void 0
|
|
175
175
|
});
|
|
176
176
|
}, g = async (e = 1) => {
|
|
177
177
|
try {
|
|
178
|
-
await
|
|
178
|
+
await n(T, l, f);
|
|
179
179
|
} catch (e) {
|
|
180
180
|
if (re(e)) {
|
|
181
|
-
ie("ai-credits"), h("You've run out of AI credits for this billing cycle. Upgrade your plan to keep chatting."), B(
|
|
181
|
+
ie("ai-credits"), h("You've run out of AI credits for this billing cycle. Upgrade your plan to keep chatting."), B(i, "error", m, null);
|
|
182
182
|
return;
|
|
183
183
|
}
|
|
184
184
|
console.warn("[assistant] AI-credit pre-flight check failed with a non-quota error; proceeding — gateway @usage(checkQuota) still enforces the real budget downstream", e);
|
|
185
185
|
}
|
|
186
186
|
try {
|
|
187
|
-
let { sandboxId: e, sessionId:
|
|
188
|
-
Y(
|
|
189
|
-
let
|
|
190
|
-
await
|
|
191
|
-
let p = ve([],
|
|
192
|
-
for (; Date.now() < g && (p = ve(await
|
|
187
|
+
let { sandboxId: e, sessionId: n } = await X(i, m, r, l, f);
|
|
188
|
+
Y(i, m, "streaming", "Thinking...");
|
|
189
|
+
let o = Date.now();
|
|
190
|
+
await d(T, e, l, n, oe(r, t), r, ne(), f);
|
|
191
|
+
let p = ve([], o), g = Date.now() + (fe[r] ?? pe), _ = Date.now();
|
|
192
|
+
for (; Date.now() < g && (p = ve(await c(T, e, l, n, f, 50), o), z(i, m, { content: _e(p.content) }), !p.done);) Date.now() - _ > 3e4 && (await a(T, e, l, 600, f).catch(() => void 0), _ = Date.now()), await new Promise((e) => setTimeout(e, 1500));
|
|
193
193
|
if (!p.done && r !== "vibe-plugins") throw Error("Assistant response timed out while streaming progress");
|
|
194
|
-
let v = r === "vibe-plugins" ? await
|
|
194
|
+
let v = r === "vibe-plugins" ? await s(T, e, l, n, f).catch(() => []) : void 0;
|
|
195
195
|
if (p.done || (p = {
|
|
196
196
|
...p,
|
|
197
197
|
content: `${p.content}\n\n_Still building in the background — any artifacts below will finish shortly. Re-open this conversation to pick up the completed plugin._`
|
|
198
|
-
}), h(p.content, v,
|
|
199
|
-
z(
|
|
198
|
+
}), h(p.content, v, n, e), p.tokens) {
|
|
199
|
+
z(i, m, { tokens: p.tokens });
|
|
200
200
|
try {
|
|
201
|
-
await
|
|
201
|
+
await u(T, l, n, p.tokens, f), ae();
|
|
202
202
|
} catch {}
|
|
203
203
|
}
|
|
204
|
-
B(
|
|
204
|
+
B(i, "complete", m, null);
|
|
205
205
|
} catch (t) {
|
|
206
|
-
if (e === 1 && ge(t)) return H(
|
|
206
|
+
if (e === 1 && ge(t)) return H(i), W(r), g(2);
|
|
207
207
|
throw t;
|
|
208
208
|
}
|
|
209
209
|
};
|
|
210
210
|
try {
|
|
211
|
-
if (!
|
|
211
|
+
if (!l) throw Error("Assistant backend is unavailable without an active workspace context.");
|
|
212
212
|
await g();
|
|
213
213
|
} catch (e) {
|
|
214
214
|
if (re(e)) {
|
|
215
|
-
ie("sandbox"), h("You've reached your sandbox limit on the current plan. Upgrade to start the AI assistant."), B(
|
|
215
|
+
ie("sandbox"), h("You've reached your sandbox limit on the current plan. Upgrade to start the AI assistant."), B(i, "error", m, null);
|
|
216
216
|
return;
|
|
217
217
|
}
|
|
218
218
|
let t = e instanceof Error ? e.message : "Something went wrong";
|
|
219
|
-
B(
|
|
219
|
+
B(i, "error", m, t), R(i, m, `Sorry, an error occurred: ${t}. Please try again.`);
|
|
220
220
|
}
|
|
221
221
|
}, [
|
|
222
222
|
A,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useTr as e } from "../../shared/hooks/useTr.js";
|
|
2
|
+
import { downloadAssistantArtifact as t } from "../../services/assistantApi.js";
|
|
3
3
|
import { AssistantMarkdownRenderer as n } from "./AssistantMarkdownRenderer.js";
|
|
4
4
|
import { useMemo as r, useState as i } from "react";
|
|
5
5
|
import { Bot as a, User as o } from "lucide-react";
|
|
@@ -24,13 +24,13 @@ function h(e, t, n) {
|
|
|
24
24
|
s.href = o, s.download = t, document.body.appendChild(s), s.click(), document.body.removeChild(s), URL.revokeObjectURL(o);
|
|
25
25
|
}
|
|
26
26
|
var g = ({ message: m, isStreaming: g }) => {
|
|
27
|
-
let _ =
|
|
27
|
+
let _ = e(), v = u("workspace"), { getAccessToken: y, getWorkspaceToken: b } = d(), [x, S] = i(null), C = m.role === "user", w = r(() => f(m), [m]), T = r(() => p(w), [w]), E = async (e) => {
|
|
28
28
|
if (!w?.sandboxId || !w.sessionId) return;
|
|
29
29
|
let n = new URLSearchParams(window.location.search).get("workspace") ?? "";
|
|
30
30
|
if (n) {
|
|
31
|
-
S(
|
|
31
|
+
S(e.path);
|
|
32
32
|
try {
|
|
33
|
-
let r = await
|
|
33
|
+
let r = await t(v, w.sandboxId, n, w.sessionId, e.path, {
|
|
34
34
|
accessToken: y(),
|
|
35
35
|
workspaceToken: b()
|
|
36
36
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e =
|
|
1
|
+
var e = typeof window < "u" && window.location.hostname !== "app.gethealthybowl.com", t = {
|
|
2
2
|
id: "general",
|
|
3
3
|
label: "General",
|
|
4
4
|
description: "General help with HealthyBowl — crops, livestock, the marketplace, and farm operations",
|
|
@@ -8,7 +8,7 @@ var e = [{
|
|
|
8
8
|
"How does the marketplace work?",
|
|
9
9
|
"What government schemes can I apply for?"
|
|
10
10
|
]
|
|
11
|
-
}, {
|
|
11
|
+
}, n = e ? [t, {
|
|
12
12
|
id: "api-calls",
|
|
13
13
|
label: "Actions",
|
|
14
14
|
description: "Let the assistant take actions for you — add crops, log harvests, update records. It describes what it will do and asks before changing anything.",
|
|
@@ -20,8 +20,8 @@ var e = [{
|
|
|
20
20
|
],
|
|
21
21
|
requiresAdmin: !0,
|
|
22
22
|
writeCapable: !0
|
|
23
|
-
}];
|
|
23
|
+
}] : [t];
|
|
24
24
|
//#endregion
|
|
25
|
-
export { e as ASSISTANT_USECASE_CONFIG };
|
|
25
|
+
export { e as API_CALLS_MODE_ENABLED, n as ASSISTANT_USECASE_CONFIG };
|
|
26
26
|
|
|
27
27
|
//# sourceMappingURL=assistantUsecases.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assistantUsecases.js","names":[],"sources":["../../src/config/assistantUsecases.ts"],"sourcesContent":["/**\n * HealthyBowl AI Assistant usecases.\n *\n * `AssistantUsecaseId` is the full set of modes the transport/runtime\n * understands — it drives the image/resource switches in `services/assistantApi`.\n * `ASSISTANT_USECASE_CONFIG` is the set of modes the panel KNOWS about; the mode\n * selector further filters them at runtime by the user's role (see\n * `useAssistantApiAccess`) so a write-capable mode only appears for org admins.\n * - `general` — docs Q&A (proxy-token auth, available to everyone).\n * - `api-calls` — WRITE-CAPABLE: the agent executes GraphQL on the user's\n * behalf (app-client-credentials auth). Minting its per-sandbox OAuth app\n * requires a global Owner/Admin actor, so it is gated to admins, guarded by a\n * confirm-before-mutate dialog + a soft agent preamble, and master-flagged.\n * - `vibe-plugins` — a VibeControls-only concept HealthyBowl never exposes.\n */\n\n// Full set of runtime-understood modes. Keep in sync with the image/resource\n// switches in `services/assistantApi.ts`.\nexport type AssistantUsecaseId = 'general' | 'api-calls' | 'vibe-plugins';\n\nexport interface AssistantUsecase {\n id: AssistantUsecaseId;\n label: string;\n description: string;\n suggestions: readonly string[];\n /** Only offered to a global Owner/Admin (minting the OAuth app needs admin). */\n requiresAdmin?: boolean;\n /** Executes mutations on live data → triggers the confirm-before-mutate guard. */\n writeCapable?: boolean;\n}\n\n/**\n * Master switch for the write-capable `api-calls` mode. It is admin-gated, shows\n * a one-time confirm dialog, and prepends a describe-and-confirm instruction —\n * but the in-sandbox agent still auto-executes (there is no hard server-side\n * confirmation yet, per the ai-assistant agent).
|
|
1
|
+
{"version":3,"file":"assistantUsecases.js","names":[],"sources":["../../src/config/assistantUsecases.ts"],"sourcesContent":["/**\n * HealthyBowl AI Assistant usecases.\n *\n * `AssistantUsecaseId` is the full set of modes the transport/runtime\n * understands — it drives the image/resource switches in `services/assistantApi`.\n * `ASSISTANT_USECASE_CONFIG` is the set of modes the panel KNOWS about; the mode\n * selector further filters them at runtime by the user's role (see\n * `useAssistantApiAccess`) so a write-capable mode only appears for org admins.\n * - `general` — docs Q&A (proxy-token auth, available to everyone).\n * - `api-calls` — WRITE-CAPABLE: the agent executes GraphQL on the user's\n * behalf (app-client-credentials auth). Minting its per-sandbox OAuth app\n * requires a global Owner/Admin actor, so it is gated to admins, guarded by a\n * confirm-before-mutate dialog + a soft agent preamble, and master-flagged.\n * - `vibe-plugins` — a VibeControls-only concept HealthyBowl never exposes.\n */\n\n// Full set of runtime-understood modes. Keep in sync with the image/resource\n// switches in `services/assistantApi.ts`.\nexport type AssistantUsecaseId = 'general' | 'api-calls' | 'vibe-plugins';\n\nexport interface AssistantUsecase {\n id: AssistantUsecaseId;\n label: string;\n description: string;\n suggestions: readonly string[];\n /** Only offered to a global Owner/Admin (minting the OAuth app needs admin). */\n requiresAdmin?: boolean;\n /** Executes mutations on live data → triggers the confirm-before-mutate guard. */\n writeCapable?: boolean;\n}\n\n/**\n * Master switch for the write-capable `api-calls` mode. It is admin-gated, shows\n * a one-time confirm dialog, and prepends a describe-and-confirm instruction —\n * but the in-sandbox agent still auto-executes (there is no hard server-side\n * confirmation yet, per the ai-assistant agent). So it is held OFF on the\n * PRODUCTION app (`app.gethealthybowl.com`) and stays ON for alpha\n * (`alphaapp.gethealthybowl.com`) + local dev, until the agent-side hard confirm\n * lands. Flipping it does not touch the transport, which already supports the mode.\n *\n * Why a RUNTIME hostname check and not `import.meta.env.VITE_*`: this microfe\n * ships a PREBUILT dist (the app bundles dist/index.js, not src), so Vite bakes\n * any `import.meta.env` at MICROFE build time — where the env is never 'prod' —\n * making a build-time env flag unable to distinguish prod from alpha. The\n * runtime `window.location.hostname` is the reliable signal in the browser.\n */\nconst PROD_APP_HOST = 'app.gethealthybowl.com';\nexport const API_CALLS_MODE_ENABLED = typeof window !== 'undefined' && window.location.hostname !== PROD_APP_HOST;\n\nconst GENERAL: AssistantUsecase = {\n id: 'general',\n label: 'General',\n description: 'General help with HealthyBowl — crops, livestock, the marketplace, and farm operations',\n suggestions: [\n 'How do I add a new crop?',\n 'Explain the livestock health tracker',\n 'How does the marketplace work?',\n 'What government schemes can I apply for?',\n ],\n};\n\nconst API_CALLS: AssistantUsecase = {\n id: 'api-calls',\n label: 'Actions',\n description:\n 'Let the assistant take actions for you — add crops, log harvests, update records. It describes what it will do and asks before changing anything.',\n suggestions: [\n 'Add a new crop',\n 'Log a harvest for one of my fields',\n 'List all my livestock',\n \"Update a crop's status\",\n ],\n requiresAdmin: true,\n writeCapable: true,\n};\n\n// Modes the panel knows about. Phase 1 = general; phase 2 adds api-calls (admin-\n// gated + guarded). The mode selector filters this further by role at runtime.\nexport const ASSISTANT_USECASE_CONFIG: readonly AssistantUsecase[] = API_CALLS_MODE_ENABLED\n ? [GENERAL, API_CALLS]\n : [GENERAL];\n"],"mappings":"AA+CA,IAAa,IAAyB,OAAO,SAAW,OAAe,OAAO,SAAS,aADjE,0BAGhB,IAA4B;CAChC,IAAI;CACJ,OAAO;CACP,aAAa;CACb,aAAa;EACX;EACA;EACA;EACA;EACD;CACF,EAmBY,IAAwD,IACjE,CAAC,GAlB+B;CAClC,IAAI;CACJ,OAAO;CACP,aACE;CACF,aAAa;EACX;EACA;EACA;EACA;EACD;CACD,eAAe;CACf,cAAc;CACf,CAKuB,GACpB,CAAC,EAAQ"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useOpenAssistantHelp as e } from "../../hooks/useOpenAssistantHelp.js";
|
|
2
|
+
import { useTr as t } from "../../shared/hooks/useTr.js";
|
|
3
|
+
import { HelpCircle as n } from "lucide-react";
|
|
4
|
+
import { jsx as r, jsxs as i } from "react/jsx-runtime";
|
|
5
|
+
//#region src/healthybowl/components/GetHelpButton.tsx
|
|
6
|
+
function a({ prompt: a, label: o, variant: s = "ghost", className: c = "" }) {
|
|
7
|
+
let l = t(), u = o ?? l("healthybowl.shared.getHelpButton.label", "Get Help"), d = e();
|
|
8
|
+
return /* @__PURE__ */ i("button", {
|
|
9
|
+
type: "button",
|
|
10
|
+
onClick: () => d(a),
|
|
11
|
+
className: `${s === "ghost" ? "inline-flex items-center gap-1.5 px-3 py-1.5 text-sm border border-border-default text-text-secondary hover:text-text-primary hover:bg-bg-sunken rounded-md transition-colors" : "inline-flex items-center gap-1.5 text-sm text-action-primary-bg hover:underline"} ${c}`.trim(),
|
|
12
|
+
title: l("healthybowl.shared.getHelpButton.tooltip", "Ask the assistant about this page"),
|
|
13
|
+
"data-testid": "get-help-button",
|
|
14
|
+
children: [/* @__PURE__ */ r(n, { className: "size-4" }), u]
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { a as GetHelpButton };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=GetHelpButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GetHelpButton.js","names":[],"sources":["../../../src/healthybowl/components/GetHelpButton.tsx"],"sourcesContent":["import { HelpCircle } from 'lucide-react';\nimport { useOpenAssistantHelp } from '@/hooks/useOpenAssistantHelp';\nimport { useTr } from '../../shared/hooks/useTr';\n\ninterface GetHelpButtonProps {\n /** The prompt auto-sent to the assistant (general mode) when clicked. */\n prompt: string;\n /** Optional label override. Defaults to \"Get Help\". */\n label?: string;\n /** `ghost` (default) is a subtle outlined button; `link` is text-only. */\n variant?: 'ghost' | 'link';\n /** Additional CSS class names. */\n className?: string;\n}\n\n/**\n * Shared \"Get Help\" button — a contextual help affordance that opens the AI\n * assistant and auto-asks about the current screen, so a user can get help\n * without leaving the page or typing. Rendered by `PageLayout` on every page\n * (prompt derived from the page title), and usable standalone next to \"Add X\"\n * empty states. Mirrors the VibeControls pattern; HB semantic tokens only.\n *\n * Clicking it: switches the assistant to `general` mode, opens the shell panel\n * (`hb:toggle-ai-assistant` { open: true }), and queues `prompt` — the\n * AssistantChatArea auto-sends it. See `useOpenAssistantHelp`.\n */\nexport function GetHelpButton({ prompt, label, variant = 'ghost', className = '' }: GetHelpButtonProps) {\n const tr = useTr();\n const resolvedLabel = label ?? tr('healthybowl.shared.getHelpButton.label', 'Get Help');\n const openHelp = useOpenAssistantHelp();\n\n const baseClass =\n variant === 'ghost'\n ? 'inline-flex items-center gap-1.5 px-3 py-1.5 text-sm border border-border-default text-text-secondary hover:text-text-primary hover:bg-bg-sunken rounded-md transition-colors'\n : 'inline-flex items-center gap-1.5 text-sm text-action-primary-bg hover:underline';\n\n return (\n <button\n type=\"button\"\n onClick={() => openHelp(prompt)}\n className={`${baseClass} ${className}`.trim()}\n title={tr('healthybowl.shared.getHelpButton.tooltip', 'Ask the assistant about this page')}\n data-testid=\"get-help-button\"\n >\n <HelpCircle className=\"size-4\" />\n {resolvedLabel}\n </button>\n );\n}\n"],"mappings":";;;;;AA0BA,SAAgB,EAAc,EAAE,WAAQ,UAAO,aAAU,SAAS,eAAY,MAA0B;CACtG,IAAM,IAAK,GAAO,EACZ,IAAgB,KAAS,EAAG,0CAA0C,WAAW,EACjF,IAAW,GAAsB;AAOvC,QACE,kBAAC,UAAD;EACE,MAAK;EACL,eAAe,EAAS,EAAO;EAC/B,WAAW,GARb,MAAY,UACR,kLACA,kFAMsB,GAAG,IAAY,MAAM;EAC7C,OAAO,EAAG,4CAA4C,oCAAoC;EAC1F,eAAY;YALd,CAOE,kBAAC,GAAD,EAAY,WAAU,UAAW,CAAA,EAChC,EACM"}
|
|
@@ -1,46 +1,47 @@
|
|
|
1
1
|
import { cn as e } from "../utils/helpers.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { GetHelpButton as t } from "./GetHelpButton.js";
|
|
3
|
+
import { Fragment as n, jsx as r, jsxs as i } from "react/jsx-runtime";
|
|
4
|
+
import { AuroraBackground as a, GradientText as o, NextSteps as s, PageContainer as c, PagePurpose as l } from "@burdenoff/fe-libs/ui";
|
|
5
|
+
import { PageHeader as u } from "@burdenoff/fe-libs/chrome";
|
|
5
6
|
//#region src/healthybowl/components/PageLayout.tsx
|
|
6
|
-
var
|
|
7
|
-
if (!
|
|
8
|
-
let
|
|
9
|
-
return
|
|
10
|
-
e.slice(0,
|
|
11
|
-
/* @__PURE__ */
|
|
12
|
-
e.slice(
|
|
7
|
+
var d = (e, t) => {
|
|
8
|
+
if (!t) return e;
|
|
9
|
+
let a = e.indexOf(t);
|
|
10
|
+
return a === -1 ? e : /* @__PURE__ */ i(n, { children: [
|
|
11
|
+
e.slice(0, a),
|
|
12
|
+
/* @__PURE__ */ r(o, { children: t }),
|
|
13
|
+
e.slice(a + t.length)
|
|
13
14
|
] });
|
|
14
|
-
},
|
|
15
|
-
let
|
|
16
|
-
title:
|
|
17
|
-
description:
|
|
18
|
-
actions:
|
|
15
|
+
}, f = ({ title: o, description: f, actions: p, children: m, hero: h = !1, titleAccent: g, purpose: _, purposeIcon: v, nextSteps: y, nextStepsKey: b, nextStepsTitle: x, helpPrompt: S, hideHelp: C = !1, className: w }) => {
|
|
16
|
+
let T = C ? null : /* @__PURE__ */ r(t, { prompt: S ?? `What is the ${o} page for, and how do I use it?` }), E = T || p ? /* @__PURE__ */ i(n, { children: [T, p] }) : void 0, D = /* @__PURE__ */ r(u, {
|
|
17
|
+
title: d(o, g),
|
|
18
|
+
description: f,
|
|
19
|
+
actions: E
|
|
19
20
|
});
|
|
20
|
-
return /* @__PURE__ */
|
|
21
|
-
className: e("space-y-6",
|
|
21
|
+
return /* @__PURE__ */ i(c, {
|
|
22
|
+
className: e("space-y-6", w),
|
|
22
23
|
children: [
|
|
23
|
-
|
|
24
|
+
h ? /* @__PURE__ */ i("div", {
|
|
24
25
|
className: "relative overflow-hidden rounded-2xl border border-border-seam bg-hero-mesh px-6 py-5 shadow-pop",
|
|
25
|
-
children: [/* @__PURE__ */
|
|
26
|
+
children: [/* @__PURE__ */ r(a, { intensity: "subtle" }), /* @__PURE__ */ r("div", {
|
|
26
27
|
className: "relative z-10",
|
|
27
|
-
children:
|
|
28
|
+
children: D
|
|
28
29
|
})]
|
|
29
|
-
}) :
|
|
30
|
-
|
|
31
|
-
icon:
|
|
32
|
-
children:
|
|
30
|
+
}) : D,
|
|
31
|
+
_ && /* @__PURE__ */ r(l, {
|
|
32
|
+
icon: v,
|
|
33
|
+
children: _
|
|
33
34
|
}),
|
|
34
|
-
|
|
35
|
-
steps:
|
|
36
|
-
storageKey:
|
|
37
|
-
title:
|
|
35
|
+
y && y.length > 0 && b && /* @__PURE__ */ r(s, {
|
|
36
|
+
steps: y,
|
|
37
|
+
storageKey: b,
|
|
38
|
+
title: x
|
|
38
39
|
}),
|
|
39
|
-
|
|
40
|
+
m
|
|
40
41
|
]
|
|
41
42
|
});
|
|
42
43
|
};
|
|
43
44
|
//#endregion
|
|
44
|
-
export {
|
|
45
|
+
export { f as PageLayout };
|
|
45
46
|
|
|
46
47
|
//# sourceMappingURL=PageLayout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PageLayout.js","names":[],"sources":["../../../src/healthybowl/components/PageLayout.tsx"],"sourcesContent":["import type { FC, ReactNode } from 'react';\nimport { PageContainer, AuroraBackground, GradientText, PagePurpose, NextSteps } from '@burdenoff/fe-libs/ui';\nimport type { NextStep } from '@burdenoff/fe-libs/ui';\nimport { PageHeader } from '@burdenoff/fe-libs/chrome';\nimport { cn } from '../utils/helpers';\n\ninterface PageLayoutProps {\n title: string;\n description?: string;\n actions?: ReactNode;\n children: ReactNode;\n /**\n * Boff UI 2.0 hero header — wraps the page header in a glass card with a subtle\n * living AuroraBackground backdrop. Use on the MFE's PRIMARY page only (one\n * aurora per MFE). The backdrop sits behind the content (-z-10), never shifts\n * layout, and goes static under reduced-motion.\n */\n hero?: boolean;\n /**\n * Key noun of the title to render with GradientText (the one hero heading per\n * page). Must be a substring of `title`; the surrounding text stays plain.\n */\n titleAccent?: string;\n /**\n * Boff UI 2.0 page \"story\" — a concise, plain-language explanation of WHAT this\n * page is for and the use-case, rendered as a `PagePurpose` directly under the\n * header so every page is self-explanatory for a new user. Renders before any\n * loading/empty/content branch in `children`, so it is always visible.\n */\n purpose?: ReactNode;\n /** Optional icon for the page purpose. */\n purposeIcon?: ReactNode;\n /**\n * Boff UI 2.0 next-step guidance for COMPLEX pages (detail/dashboard/multi-tab):\n * a dismissable, reopenable `NextSteps` card recommending 2-4 concrete actions\n * wired to real handlers/links so new users aren't overwhelmed. Skip on trivial\n * single-action pages. Requires `nextStepsKey` to persist the dismissed state.\n */\n nextSteps?: NextStep[];\n /** localStorage key suffix for the NextSteps dismissed state (e.g. \"healthybowl-crops\"). */\n nextStepsKey?: string;\n /** Optional title for the NextSteps card. */\n nextStepsTitle?: string;\n className?: string;\n}\n\n/** Renders the title, highlighting `accent` (if present) with GradientText. */\nconst renderTitle = (title: string, accent?: string): ReactNode => {\n if (!accent) return title;\n const idx = title.indexOf(accent);\n if (idx === -1) return title;\n return (\n <>\n {title.slice(0, idx)}\n <GradientText>{accent}</GradientText>\n {title.slice(idx + accent.length)}\n </>\n );\n};\n\n/**\n * Standard page scaffold. Wraps the Boff `PageContainer` (background + padding)\n * and `PageHeader` (title/description/actions) so every page is theme-compliant.\n * With `hero`, the header is wrapped in a glassy mesh card with a living aurora\n * backdrop (Boff UI 2.0) for the MFE's primary page; `titleAccent` clips the key\n * noun into a brand gradient. `PageContainer` supplies the default page padding;\n * we re-add the inter-section vertical gap so header→content spacing is preserved.\n */\nexport const PageLayout: FC<PageLayoutProps> = ({\n title,\n description,\n actions,\n children,\n hero = false,\n titleAccent,\n purpose,\n purposeIcon,\n nextSteps,\n nextStepsKey,\n nextStepsTitle,\n className,\n}) => {\n const header = <PageHeader title={renderTitle(title, titleAccent)} description={description} actions={
|
|
1
|
+
{"version":3,"file":"PageLayout.js","names":[],"sources":["../../../src/healthybowl/components/PageLayout.tsx"],"sourcesContent":["import type { FC, ReactNode } from 'react';\nimport { PageContainer, AuroraBackground, GradientText, PagePurpose, NextSteps } from '@burdenoff/fe-libs/ui';\nimport type { NextStep } from '@burdenoff/fe-libs/ui';\nimport { PageHeader } from '@burdenoff/fe-libs/chrome';\nimport { cn } from '../utils/helpers';\nimport { GetHelpButton } from './GetHelpButton';\n\ninterface PageLayoutProps {\n title: string;\n description?: string;\n actions?: ReactNode;\n children: ReactNode;\n /**\n * Contextual prompt for the always-present \"Get Help\" button in the header —\n * clicking it opens the AI assistant and asks about THIS page. Defaults to a\n * title-based question. Set `hideHelp` to drop the button where it doesn't fit.\n */\n helpPrompt?: string;\n /** Hide the header \"Get Help\" button (shown by default on every page). */\n hideHelp?: boolean;\n /**\n * Boff UI 2.0 hero header — wraps the page header in a glass card with a subtle\n * living AuroraBackground backdrop. Use on the MFE's PRIMARY page only (one\n * aurora per MFE). The backdrop sits behind the content (-z-10), never shifts\n * layout, and goes static under reduced-motion.\n */\n hero?: boolean;\n /**\n * Key noun of the title to render with GradientText (the one hero heading per\n * page). Must be a substring of `title`; the surrounding text stays plain.\n */\n titleAccent?: string;\n /**\n * Boff UI 2.0 page \"story\" — a concise, plain-language explanation of WHAT this\n * page is for and the use-case, rendered as a `PagePurpose` directly under the\n * header so every page is self-explanatory for a new user. Renders before any\n * loading/empty/content branch in `children`, so it is always visible.\n */\n purpose?: ReactNode;\n /** Optional icon for the page purpose. */\n purposeIcon?: ReactNode;\n /**\n * Boff UI 2.0 next-step guidance for COMPLEX pages (detail/dashboard/multi-tab):\n * a dismissable, reopenable `NextSteps` card recommending 2-4 concrete actions\n * wired to real handlers/links so new users aren't overwhelmed. Skip on trivial\n * single-action pages. Requires `nextStepsKey` to persist the dismissed state.\n */\n nextSteps?: NextStep[];\n /** localStorage key suffix for the NextSteps dismissed state (e.g. \"healthybowl-crops\"). */\n nextStepsKey?: string;\n /** Optional title for the NextSteps card. */\n nextStepsTitle?: string;\n className?: string;\n}\n\n/** Renders the title, highlighting `accent` (if present) with GradientText. */\nconst renderTitle = (title: string, accent?: string): ReactNode => {\n if (!accent) return title;\n const idx = title.indexOf(accent);\n if (idx === -1) return title;\n return (\n <>\n {title.slice(0, idx)}\n <GradientText>{accent}</GradientText>\n {title.slice(idx + accent.length)}\n </>\n );\n};\n\n/**\n * Standard page scaffold. Wraps the Boff `PageContainer` (background + padding)\n * and `PageHeader` (title/description/actions) so every page is theme-compliant.\n * With `hero`, the header is wrapped in a glassy mesh card with a living aurora\n * backdrop (Boff UI 2.0) for the MFE's primary page; `titleAccent` clips the key\n * noun into a brand gradient. `PageContainer` supplies the default page padding;\n * we re-add the inter-section vertical gap so header→content spacing is preserved.\n */\nexport const PageLayout: FC<PageLayoutProps> = ({\n title,\n description,\n actions,\n children,\n hero = false,\n titleAccent,\n purpose,\n purposeIcon,\n nextSteps,\n nextStepsKey,\n nextStepsTitle,\n helpPrompt,\n hideHelp = false,\n className,\n}) => {\n // Always-present contextual help button (general-mode assistant, asks about\n // this page). Rendered before any page-specific actions; opt out via hideHelp.\n const helpButton = hideHelp ? null : (\n <GetHelpButton prompt={helpPrompt ?? `What is the ${title} page for, and how do I use it?`} />\n );\n const headerActions =\n helpButton || actions ? (\n <>\n {helpButton}\n {actions}\n </>\n ) : undefined;\n const header = (\n <PageHeader title={renderTitle(title, titleAccent)} description={description} actions={headerActions} />\n );\n\n return (\n <PageContainer className={cn('space-y-6', className)}>\n {hero ? (\n <div className=\"relative overflow-hidden rounded-2xl border border-border-seam bg-hero-mesh px-6 py-5 shadow-pop\">\n <AuroraBackground intensity=\"subtle\" />\n <div className=\"relative z-10\">{header}</div>\n </div>\n ) : (\n header\n )}\n {purpose && <PagePurpose icon={purposeIcon}>{purpose}</PagePurpose>}\n {nextSteps && nextSteps.length > 0 && nextStepsKey && (\n <NextSteps steps={nextSteps} storageKey={nextStepsKey} title={nextStepsTitle} />\n )}\n {children}\n </PageContainer>\n );\n};\n"],"mappings":";;;;;;AAwDA,IAAM,KAAe,GAAe,MAA+B;AACjE,KAAI,CAAC,EAAQ,QAAO;CACpB,IAAM,IAAM,EAAM,QAAQ,EAAO;AAEjC,QADI,MAAQ,KAAW,IAErB,kBAAA,GAAA,EAAA,UAAA;EACG,EAAM,MAAM,GAAG,EAAI;EACpB,kBAAC,GAAD,EAAA,UAAe,GAAsB,CAAA;EACpC,EAAM,MAAM,IAAM,EAAO,OAAO;EAChC,EAAA,CAAA;GAYM,KAAmC,EAC9C,UACA,gBACA,YACA,aACA,UAAO,IACP,gBACA,YACA,gBACA,cACA,iBACA,mBACA,eACA,cAAW,IACX,mBACI;CAGJ,IAAM,IAAa,IAAW,OAC5B,kBAAC,GAAD,EAAe,QAAQ,KAAc,eAAe,EAAM,kCAAoC,CAAA,EAE1F,IACJ,KAAc,IACZ,kBAAA,GAAA,EAAA,UAAA,CACG,GACA,EACA,EAAA,CAAA,GACD,KAAA,GACA,IACJ,kBAAC,GAAD;EAAY,OAAO,EAAY,GAAO,EAAY;EAAe;EAAa,SAAS;EAAiB,CAAA;AAG1G,QACE,kBAAC,GAAD;EAAe,WAAW,EAAG,aAAa,EAAU;YAApD;GACG,IACC,kBAAC,OAAD;IAAK,WAAU;cAAf,CACE,kBAAC,GAAD,EAAkB,WAAU,UAAW,CAAA,EACvC,kBAAC,OAAD;KAAK,WAAU;eAAiB;KAAa,CAAA,CACzC;QAEN;GAED,KAAW,kBAAC,GAAD;IAAa,MAAM;cAAc;IAAsB,CAAA;GAClE,KAAa,EAAU,SAAS,KAAK,KACpC,kBAAC,GAAD;IAAW,OAAO;IAAW,YAAY;IAAc,OAAO;IAAkB,CAAA;GAEjF;GACa"}
|
|
@@ -1,37 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { API_CALLS_MODE_ENABLED as e } from "../config/assistantUsecases.js";
|
|
2
|
+
import { useEffect as t, useState as n } from "react";
|
|
3
|
+
import { graphqlFetch as r } from "@burdenoff/fe-libs/shared/graphql";
|
|
3
4
|
//#region src/hooks/useAssistantApiAccess.ts
|
|
4
|
-
var
|
|
5
|
-
function
|
|
6
|
-
let
|
|
7
|
-
return
|
|
8
|
-
if (!
|
|
9
|
-
|
|
5
|
+
var i = "query AssistantMyRoles($scopeId: String!) {\n myRoles(scopeId: $scopeId) {\n isAdmin\n isOwner\n }\n}";
|
|
6
|
+
function a(a) {
|
|
7
|
+
let o = e && !!a, [s, c] = n(!1), [l, u] = n(o);
|
|
8
|
+
return t(() => {
|
|
9
|
+
if (!o) {
|
|
10
|
+
c(!1), u(!1);
|
|
10
11
|
return;
|
|
11
12
|
}
|
|
12
13
|
let e = !1;
|
|
13
|
-
return
|
|
14
|
+
return u(!0), r({
|
|
14
15
|
gateway: "global",
|
|
15
|
-
query:
|
|
16
|
-
variables: { scopeId:
|
|
16
|
+
query: i,
|
|
17
|
+
variables: { scopeId: a },
|
|
17
18
|
suppressGlobalErrorEvent: !0
|
|
18
19
|
}).then((t) => {
|
|
19
20
|
if (e) return;
|
|
20
21
|
let n = t.data?.myRoles;
|
|
21
|
-
|
|
22
|
+
c(!!(n?.isOwner || n?.isAdmin));
|
|
22
23
|
}).catch(() => {
|
|
23
|
-
e ||
|
|
24
|
+
e || c(!1);
|
|
24
25
|
}).finally(() => {
|
|
25
|
-
e ||
|
|
26
|
+
e || u(!1);
|
|
26
27
|
}), () => {
|
|
27
28
|
e = !0;
|
|
28
29
|
};
|
|
29
|
-
}, [
|
|
30
|
-
canUseApiCalls:
|
|
31
|
-
loading:
|
|
30
|
+
}, [o, a]), {
|
|
31
|
+
canUseApiCalls: s,
|
|
32
|
+
loading: l
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
35
|
//#endregion
|
|
35
|
-
export {
|
|
36
|
+
export { a as useAssistantApiAccess };
|
|
36
37
|
|
|
37
38
|
//# sourceMappingURL=useAssistantApiAccess.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAssistantApiAccess.js","names":[],"sources":["../../src/hooks/useAssistantApiAccess.ts"],"sourcesContent":["/**\n * Resolves whether the current user may use the write-capable `api-calls`\n * assistant mode.\n *\n * That mode mints a per-sandbox OAuth app under the caller's identity\n * (createApp/createApplication in wspace-sandbox-svc), which is RBAC-gated to a\n * global Owner/Admin — a non-admin would only discover this as a FORBIDDEN at\n * provision time. So we gate the UI on the same signal up front, via the global\n * gateway's `myRoles(scopeId)` query (`@rbac(public: true)`, auth-only, returns\n * `isAdmin`/`isOwner` directly — no extra provider wiring needed).\n *\n * Fails CLOSED: an error, an empty org scope, or the master flag being off all\n * resolve to `canUseApiCalls = false`, so the mode stays hidden unless the user\n * is provably an org admin.\n */\n\nimport { useEffect, useState } from 'react';\nimport { graphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\nimport { API_CALLS_MODE_ENABLED } from '@/config/assistantUsecases';\n\nconst MY_ROLES_QUERY = `query AssistantMyRoles($scopeId: String!) {\n myRoles(scopeId: $scopeId) {\n isAdmin\n isOwner\n }\n}`;\n\ninterface MyRolesData {\n myRoles: { isAdmin: boolean; isOwner: boolean };\n}\n\nexport interface AssistantApiAccess {\n /** True only for a confirmed global Owner/Admin (and when the mode is enabled). */\n canUseApiCalls: boolean;\n /** True while the role check is in flight. */\n loading: boolean;\n}\n\nexport function useAssistantApiAccess(scopeId: string): AssistantApiAccess {\n const enabled = API_CALLS_MODE_ENABLED && Boolean(scopeId);\n const [canUseApiCalls, setCanUseApiCalls] = useState(false);\n const [loading, setLoading] = useState(enabled);\n\n useEffect(() => {\n if (!enabled) {\n setCanUseApiCalls(false);\n setLoading(false);\n return;\n }\n\n let cancelled = false;\n setLoading(true);\n\n graphqlFetch<MyRolesData>({\n gateway: 'global',\n query: MY_ROLES_QUERY,\n variables: { scopeId },\n // The gate fails closed on its own; don't surface a global error toast.\n suppressGlobalErrorEvent: true,\n })\n .then((result) => {\n if (cancelled) return;\n const roles = result.data?.myRoles;\n setCanUseApiCalls(Boolean(roles?.isOwner || roles?.isAdmin));\n })\n .catch(() => {\n if (!cancelled) setCanUseApiCalls(false);\n })\n .finally(() => {\n if (!cancelled) setLoading(false);\n });\n\n return () => {\n cancelled = true;\n };\n }, [enabled, scopeId]);\n\n return { canUseApiCalls, loading };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useAssistantApiAccess.js","names":[],"sources":["../../src/hooks/useAssistantApiAccess.ts"],"sourcesContent":["/**\n * Resolves whether the current user may use the write-capable `api-calls`\n * assistant mode.\n *\n * That mode mints a per-sandbox OAuth app under the caller's identity\n * (createApp/createApplication in wspace-sandbox-svc), which is RBAC-gated to a\n * global Owner/Admin — a non-admin would only discover this as a FORBIDDEN at\n * provision time. So we gate the UI on the same signal up front, via the global\n * gateway's `myRoles(scopeId)` query (`@rbac(public: true)`, auth-only, returns\n * `isAdmin`/`isOwner` directly — no extra provider wiring needed).\n *\n * Fails CLOSED: an error, an empty org scope, or the master flag being off all\n * resolve to `canUseApiCalls = false`, so the mode stays hidden unless the user\n * is provably an org admin.\n */\n\nimport { useEffect, useState } from 'react';\nimport { graphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\nimport { API_CALLS_MODE_ENABLED } from '@/config/assistantUsecases';\n\nconst MY_ROLES_QUERY = `query AssistantMyRoles($scopeId: String!) {\n myRoles(scopeId: $scopeId) {\n isAdmin\n isOwner\n }\n}`;\n\ninterface MyRolesData {\n myRoles: { isAdmin: boolean; isOwner: boolean };\n}\n\nexport interface AssistantApiAccess {\n /** True only for a confirmed global Owner/Admin (and when the mode is enabled). */\n canUseApiCalls: boolean;\n /** True while the role check is in flight. */\n loading: boolean;\n}\n\nexport function useAssistantApiAccess(scopeId: string): AssistantApiAccess {\n const enabled = API_CALLS_MODE_ENABLED && Boolean(scopeId);\n const [canUseApiCalls, setCanUseApiCalls] = useState(false);\n const [loading, setLoading] = useState(enabled);\n\n useEffect(() => {\n if (!enabled) {\n setCanUseApiCalls(false);\n setLoading(false);\n return;\n }\n\n let cancelled = false;\n setLoading(true);\n\n graphqlFetch<MyRolesData>({\n gateway: 'global',\n query: MY_ROLES_QUERY,\n variables: { scopeId },\n // The gate fails closed on its own; don't surface a global error toast.\n suppressGlobalErrorEvent: true,\n })\n .then((result) => {\n if (cancelled) return;\n const roles = result.data?.myRoles;\n setCanUseApiCalls(Boolean(roles?.isOwner || roles?.isAdmin));\n })\n .catch(() => {\n if (!cancelled) setCanUseApiCalls(false);\n })\n .finally(() => {\n if (!cancelled) setLoading(false);\n });\n\n return () => {\n cancelled = true;\n };\n }, [enabled, scopeId]);\n\n return { canUseApiCalls, loading };\n}\n"],"mappings":";;;;AAoBA,IAAM,IAAiB;AAkBvB,SAAgB,EAAsB,GAAqC;CACzE,IAAM,IAAU,KAA0B,EAAQ,GAC5C,CAAC,GAAgB,KAAqB,EAAS,GAAM,EACrD,CAAC,GAAS,KAAc,EAAS,EAAQ;AAoC/C,QAlCA,QAAgB;AACd,MAAI,CAAC,GAAS;AAEZ,GADA,EAAkB,GAAM,EACxB,EAAW,GAAM;AACjB;;EAGF,IAAI,IAAY;AAsBhB,SArBA,EAAW,GAAK,EAEhB,EAA0B;GACxB,SAAS;GACT,OAAO;GACP,WAAW,EAAE,YAAS;GAEtB,0BAA0B;GAC3B,CAAC,CACC,MAAM,MAAW;AAChB,OAAI,EAAW;GACf,IAAM,IAAQ,EAAO,MAAM;AAC3B,KAAkB,GAAQ,GAAO,WAAW,GAAO,SAAS;IAC5D,CACD,YAAY;AACX,GAAK,KAAW,EAAkB,GAAM;IACxC,CACD,cAAc;AACb,GAAK,KAAW,EAAW,GAAM;IACjC,QAES;AACX,OAAY;;IAEb,CAAC,GAAS,EAAQ,CAAC,EAEf;EAAE;EAAgB;EAAS"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useHealthyBowl as e } from "./healthybowl/context/HealthyBowlContext.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { useOpenAssistantHelp as t } from "./hooks/useOpenAssistantHelp.js";
|
|
3
|
+
import { HealthyBowlRoot as n } from "./healthybowl/HealthyBowlRoot.js";
|
|
4
|
+
import { useHealthyBowlStore as r } from "./healthybowl/store/healthybowlStore.js";
|
|
4
5
|
import "./healthybowl/index.js";
|
|
5
|
-
import { AIAssistantPanel as
|
|
6
|
+
import { AIAssistantPanel as i } from "./components/assistant/AIAssistantPanel.js";
|
|
6
7
|
import "./components/assistant/index.js";
|
|
7
|
-
|
|
8
|
-
export { r as AIAssistantPanel, t as HealthyBowlRoot, e as useHealthyBowl, n as useHealthyBowlStore, i as useOpenAssistantHelp };
|
|
8
|
+
export { i as AIAssistantPanel, n as HealthyBowlRoot, e as useHealthyBowl, r as useHealthyBowlStore, t as useOpenAssistantHelp };
|
package/package.json
CHANGED