@campfire-interactive/ai-chat 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -99,6 +99,10 @@ function createAssistantClient({ hubUrl, getToken, fetch: fetchImpl }) {
|
|
|
99
99
|
});
|
|
100
100
|
return json(res);
|
|
101
101
|
},
|
|
102
|
+
async availability(app) {
|
|
103
|
+
const res = await doFetch(`${base}/availability?app=${encodeURIComponent(app)}`, { headers: await headers() });
|
|
104
|
+
return json(res);
|
|
105
|
+
},
|
|
102
106
|
async listActions(query) {
|
|
103
107
|
const params = new URLSearchParams();
|
|
104
108
|
if (query.sessionId) params.set("session_id", query.sessionId);
|
|
@@ -256,6 +256,15 @@ interface AssistantClient {
|
|
|
256
256
|
listActions(query: ListActionsQuery): Promise<{
|
|
257
257
|
items: AssistantAction[];
|
|
258
258
|
}>;
|
|
259
|
+
/**
|
|
260
|
+
* Whether the hub serves this user the assistant in `app` here: its
|
|
261
|
+
* environment switch, app list, the user's aiFeatures permission and app
|
|
262
|
+
* grant. Optional so a test double can leave it out (meaning yes).
|
|
263
|
+
*/
|
|
264
|
+
availability?(app: string): Promise<{
|
|
265
|
+
available: boolean;
|
|
266
|
+
reason?: string;
|
|
267
|
+
}>;
|
|
259
268
|
}
|
|
260
269
|
interface AssistantClientOptions {
|
|
261
270
|
/** The hub's base URL, without `/api/v1`. */
|
package/dist/host/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { c as AiPageContext, g as AssistantAttachment, a as AiBlock, P as PendingWrite, b as AiLink, f as AssistantAction, i as AssistantClient } from '../client-
|
|
4
|
-
export { A as AssistantEvent, m as createAssistantClient } from '../client-
|
|
3
|
+
import { c as AiPageContext, g as AssistantAttachment, a as AiBlock, P as PendingWrite, b as AiLink, f as AssistantAction, i as AssistantClient } from '../client-Dy-v51FG.js';
|
|
4
|
+
export { A as AssistantEvent, m as createAssistantClient } from '../client-Dy-v51FG.js';
|
|
5
5
|
|
|
6
6
|
/** The page a question was asked on, as its card shows it. */
|
|
7
7
|
type AskedOn = Pick<AiPageContext, 'page' | 'title' | 'breadcrumbs' | 'path'>;
|
package/dist/host/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createAssistantClient
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-SI3LIN2H.js";
|
|
4
4
|
import {
|
|
5
5
|
compareCells,
|
|
6
6
|
formatValue,
|
|
@@ -227,7 +227,7 @@ function ChatProvider({
|
|
|
227
227
|
onChanged,
|
|
228
228
|
client: injected,
|
|
229
229
|
children,
|
|
230
|
-
enabled
|
|
230
|
+
enabled: configured
|
|
231
231
|
}) {
|
|
232
232
|
const onChangedRef = useRef(onChanged);
|
|
233
233
|
onChangedRef.current = onChanged;
|
|
@@ -237,6 +237,23 @@ function ChatProvider({
|
|
|
237
237
|
() => injected ?? createAssistantClient({ hubUrl: hubUrl ?? "", getToken: () => getTokenRef.current() }),
|
|
238
238
|
[injected, hubUrl]
|
|
239
239
|
);
|
|
240
|
+
const [available, setAvailable] = useState(null);
|
|
241
|
+
useEffect(() => {
|
|
242
|
+
if (!configured) {
|
|
243
|
+
setAvailable(null);
|
|
244
|
+
return void 0;
|
|
245
|
+
}
|
|
246
|
+
if (!client.availability) {
|
|
247
|
+
setAvailable(true);
|
|
248
|
+
return void 0;
|
|
249
|
+
}
|
|
250
|
+
let live = true;
|
|
251
|
+
client.availability(app).then((r) => live && setAvailable(r.available === true)).catch(() => live && setAvailable(false));
|
|
252
|
+
return () => {
|
|
253
|
+
live = false;
|
|
254
|
+
};
|
|
255
|
+
}, [configured, client, app]);
|
|
256
|
+
const enabled = configured && available === true;
|
|
240
257
|
const openKey = `cfi.ai-chat.${app}.open`;
|
|
241
258
|
const widthKey = `cfi.ai-chat.${app}.width`;
|
|
242
259
|
const [open, setOpenState] = useState(() => readStored(openKey) === "1");
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as AssistantEvent } from './client-
|
|
2
|
-
export { a as AiBlock, b as AiLink, c as AiPageContext, d as AiTableColumnType, e as AiValueFormat, f as AssistantAction, g as AssistantAttachment, h as AssistantChatRequest, i as AssistantClient, j as AssistantClientOptions, k as AssistantHttpError, C as ConfirmWriteRequest, l as ConfirmWriteResponse, L as ListActionsQuery, P as PendingWrite, m as createAssistantClient } from './client-
|
|
1
|
+
import { A as AssistantEvent } from './client-Dy-v51FG.js';
|
|
2
|
+
export { a as AiBlock, b as AiLink, c as AiPageContext, d as AiTableColumnType, e as AiValueFormat, f as AssistantAction, g as AssistantAttachment, h as AssistantChatRequest, i as AssistantClient, j as AssistantClientOptions, k as AssistantHttpError, C as ConfirmWriteRequest, l as ConfirmWriteResponse, L as ListActionsQuery, P as PendingWrite, m as createAssistantClient } from './client-Dy-v51FG.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Turns the chat stream's bytes into events, one per `data:` line.
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@campfire-interactive/ai-chat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "The platform AI chat panel for Campfire Suite apps: a docked, page-aware assistant opened from the header, answering from every app the user is granted, with typed answer blocks and confirm-to-write cards.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|