@btst/stack 2.3.0 → 2.4.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.
- package/dist/packages/stack/src/client/components/compose.cjs +1 -2
- package/dist/packages/stack/src/client/components/compose.mjs +1 -2
- package/dist/packages/stack/src/plugins/ai-chat/api/page-tools.cjs +71 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/page-tools.mjs +68 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/plugin.cjs +54 -7
- package/dist/packages/stack/src/plugins/ai-chat/api/plugin.mjs +54 -7
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-input.cjs +2 -2
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-input.mjs +2 -2
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-interface.cjs +89 -22
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-interface.mjs +90 -23
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-layout.cjs +110 -33
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-layout.mjs +112 -35
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-sidebar.cjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-sidebar.mjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/schemas.cjs +17 -1
- package/dist/packages/stack/src/plugins/ai-chat/schemas.mjs +17 -1
- package/dist/packages/stack/src/plugins/blog/client/components/forms/post-forms.cjs +15 -2
- package/dist/packages/stack/src/plugins/blog/client/components/forms/post-forms.mjs +16 -3
- package/dist/packages/stack/src/plugins/blog/client/components/pages/edit-post-page.internal.cjs +24 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/edit-post-page.internal.mjs +24 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/fill-blog-form-handler.cjs +26 -0
- package/dist/packages/stack/src/plugins/blog/client/components/pages/fill-blog-form-handler.mjs +24 -0
- package/dist/packages/stack/src/plugins/blog/client/components/pages/new-post-page.internal.cjs +30 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/new-post-page.internal.mjs +30 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/post-page.internal.cjs +18 -0
- package/dist/packages/stack/src/plugins/blog/client/components/pages/post-page.internal.mjs +18 -0
- package/dist/packages/stack/src/plugins/cms/api/mutations.cjs +48 -0
- package/dist/packages/stack/src/plugins/cms/api/mutations.mjs +46 -0
- package/dist/packages/stack/src/plugins/cms/api/plugin.cjs +7 -1
- package/dist/packages/stack/src/plugins/cms/api/plugin.mjs +7 -1
- package/dist/packages/stack/src/plugins/kanban/api/mutations.cjs +91 -0
- package/dist/packages/stack/src/plugins/kanban/api/mutations.mjs +87 -0
- package/dist/packages/stack/src/plugins/kanban/api/plugin.cjs +6 -1
- package/dist/packages/stack/src/plugins/kanban/api/plugin.mjs +6 -1
- package/dist/packages/stack/src/plugins/kanban/client/hooks/kanban-hooks.cjs +7 -3
- package/dist/packages/stack/src/plugins/kanban/client/hooks/kanban-hooks.mjs +7 -3
- package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-builder-page.internal.cjs +89 -0
- package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-builder-page.internal.mjs +89 -0
- package/dist/plugins/ai-chat/api/index.d.cts +1 -1
- package/dist/plugins/ai-chat/api/index.d.mts +1 -1
- package/dist/plugins/ai-chat/api/index.d.ts +1 -1
- package/dist/plugins/ai-chat/client/components/index.d.cts +1 -1
- package/dist/plugins/ai-chat/client/components/index.d.mts +1 -1
- package/dist/plugins/ai-chat/client/components/index.d.ts +1 -1
- package/dist/plugins/ai-chat/client/context/page-ai-context.cjs +92 -0
- package/dist/plugins/ai-chat/client/context/page-ai-context.d.cts +84 -0
- package/dist/plugins/ai-chat/client/context/page-ai-context.d.mts +84 -0
- package/dist/plugins/ai-chat/client/context/page-ai-context.d.ts +84 -0
- package/dist/plugins/ai-chat/client/context/page-ai-context.mjs +88 -0
- package/dist/plugins/ai-chat/client/hooks/index.d.cts +1 -1
- package/dist/plugins/ai-chat/client/hooks/index.d.mts +1 -1
- package/dist/plugins/ai-chat/client/hooks/index.d.ts +1 -1
- package/dist/plugins/ai-chat/client/index.d.cts +2 -2
- package/dist/plugins/ai-chat/client/index.d.mts +2 -2
- package/dist/plugins/ai-chat/client/index.d.ts +2 -2
- package/dist/plugins/ai-chat/query-keys.d.cts +1 -1
- package/dist/plugins/ai-chat/query-keys.d.mts +1 -1
- package/dist/plugins/ai-chat/query-keys.d.ts +1 -1
- package/dist/plugins/blog/api/index.d.cts +2 -2
- package/dist/plugins/blog/api/index.d.mts +2 -2
- package/dist/plugins/blog/api/index.d.ts +2 -2
- package/dist/plugins/blog/client/hooks/index.d.cts +2 -2
- package/dist/plugins/blog/client/hooks/index.d.mts +2 -2
- package/dist/plugins/blog/client/hooks/index.d.ts +2 -2
- package/dist/plugins/blog/client/index.d.cts +1 -1
- package/dist/plugins/blog/client/index.d.mts +1 -1
- package/dist/plugins/blog/client/index.d.ts +1 -1
- package/dist/plugins/blog/query-keys.d.cts +2 -2
- package/dist/plugins/blog/query-keys.d.mts +2 -2
- package/dist/plugins/blog/query-keys.d.ts +2 -2
- package/dist/plugins/cms/api/index.cjs +2 -0
- package/dist/plugins/cms/api/index.d.cts +1 -1
- package/dist/plugins/cms/api/index.d.mts +1 -1
- package/dist/plugins/cms/api/index.d.ts +1 -1
- package/dist/plugins/cms/api/index.mjs +1 -0
- package/dist/plugins/cms/query-keys.d.cts +1 -1
- package/dist/plugins/cms/query-keys.d.mts +1 -1
- package/dist/plugins/cms/query-keys.d.ts +1 -1
- package/dist/plugins/form-builder/api/index.d.cts +1 -1
- package/dist/plugins/form-builder/api/index.d.mts +1 -1
- package/dist/plugins/form-builder/api/index.d.ts +1 -1
- package/dist/plugins/form-builder/query-keys.d.cts +1 -1
- package/dist/plugins/form-builder/query-keys.d.mts +1 -1
- package/dist/plugins/form-builder/query-keys.d.ts +1 -1
- package/dist/plugins/kanban/api/index.cjs +4 -0
- package/dist/plugins/kanban/api/index.d.cts +1 -1
- package/dist/plugins/kanban/api/index.d.mts +1 -1
- package/dist/plugins/kanban/api/index.d.ts +1 -1
- package/dist/plugins/kanban/api/index.mjs +1 -0
- package/dist/plugins/kanban/query-keys.d.cts +1 -1
- package/dist/plugins/kanban/query-keys.d.mts +1 -1
- package/dist/plugins/kanban/query-keys.d.ts +1 -1
- package/dist/shared/{stack.BeSm90va.d.ts → stack.BEn34wW6.d.ts} +60 -2
- package/dist/shared/{stack.IdtKDRka.d.cts → stack.BUkC2EsZ.d.cts} +32 -2
- package/dist/shared/{stack.DaOcgmrM.d.ts → stack.BV9hnvu4.d.cts} +31 -7
- package/dist/shared/{stack.DaOcgmrM.d.cts → stack.BV9hnvu4.d.mts} +31 -7
- package/dist/shared/{stack.DaOcgmrM.d.mts → stack.BV9hnvu4.d.ts} +31 -7
- package/dist/shared/{stack.rTy7-wQU.d.mts → stack.BepFXT3w.d.mts} +70 -15
- package/dist/shared/{stack.BKfolAyK.d.ts → stack.CL8ts1Mu.d.ts} +3 -3
- package/dist/shared/{stack.CP68pFEH.d.mts → stack.CczspVn2.d.mts} +32 -2
- package/dist/shared/{stack.TIBF2AOx.d.ts → stack.CgWzG5jH.d.ts} +70 -15
- package/dist/shared/{stack.BpolpQpf.d.cts → stack.D3GB6wKv.d.cts} +70 -15
- package/dist/shared/{stack.B1EeBt1b.d.ts → stack.DASmUVjX.d.ts} +32 -2
- package/dist/shared/{stack.Dg09R0oB.d.mts → stack.DTDxgFj8.d.mts} +60 -2
- package/dist/shared/{stack.CMh_EdxW.d.cts → stack.DWoCZff7.d.cts} +60 -2
- package/dist/shared/{stack.snB1EDP7.d.cts → stack.Dk5r4W1F.d.mts} +3 -3
- package/dist/shared/{stack.BIXEI6v_.d.mts → stack.heOA9gzA.d.cts} +3 -3
- package/package.json +14 -1
- package/src/client/components/compose.tsx +7 -4
- package/src/plugins/ai-chat/api/page-tools.ts +111 -0
- package/src/plugins/ai-chat/api/plugin.ts +180 -9
- package/src/plugins/ai-chat/client/components/chat-input.tsx +2 -2
- package/src/plugins/ai-chat/client/components/chat-interface.tsx +154 -58
- package/src/plugins/ai-chat/client/components/chat-layout.tsx +166 -32
- package/src/plugins/ai-chat/client/components/chat-sidebar.tsx +1 -1
- package/src/plugins/ai-chat/client/context/page-ai-context.tsx +240 -0
- package/src/plugins/ai-chat/schemas.ts +16 -0
- package/src/plugins/blog/client/components/forms/post-forms.tsx +29 -2
- package/src/plugins/blog/client/components/pages/edit-post-page.internal.tsx +28 -0
- package/src/plugins/blog/client/components/pages/fill-blog-form-handler.ts +38 -0
- package/src/plugins/blog/client/components/pages/new-post-page.internal.tsx +33 -1
- package/src/plugins/blog/client/components/pages/post-page.internal.tsx +20 -0
- package/src/plugins/cms/api/index.ts +4 -0
- package/src/plugins/cms/api/mutations.ts +84 -0
- package/src/plugins/cms/api/plugin.ts +9 -0
- package/src/plugins/kanban/api/index.ts +6 -0
- package/src/plugins/kanban/api/mutations.ts +169 -0
- package/src/plugins/kanban/api/plugin.ts +12 -0
- package/src/plugins/kanban/client/hooks/kanban-hooks.tsx +4 -0
- package/src/plugins/ui-builder/client/components/pages/page-builder-page.internal.tsx +132 -0
- package/dist/shared/{stack.C5dtIncc.d.mts → stack.B7ONvlD_.d.mts} +1 -1
- package/dist/shared/{stack.CBON0dWL.d.cts → stack.BQmuNl5p.d.cts} +2 -2
- package/dist/shared/{stack.CBON0dWL.d.mts → stack.BQmuNl5p.d.mts} +2 -2
- package/dist/shared/{stack.CBON0dWL.d.ts → stack.BQmuNl5p.d.ts} +2 -2
- package/dist/shared/{stack.CIP6QS9l.d.ts → stack.Kq2-QzOC.d.ts} +1 -1
- package/dist/shared/{stack.Dw0Ly2TM.d.cts → stack.kcdnD4gA.d.cts} +1 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
async function createKanbanTask(adapter, input) {
|
|
2
|
+
const existingTasks = await adapter.findMany({
|
|
3
|
+
model: "kanbanTask",
|
|
4
|
+
where: [
|
|
5
|
+
{
|
|
6
|
+
field: "columnId",
|
|
7
|
+
value: input.columnId,
|
|
8
|
+
operator: "eq"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
});
|
|
12
|
+
const nextOrder = existingTasks.length > 0 ? Math.max(...existingTasks.map((t) => t.order)) + 1 : 0;
|
|
13
|
+
return adapter.create({
|
|
14
|
+
model: "kanbanTask",
|
|
15
|
+
data: {
|
|
16
|
+
title: input.title,
|
|
17
|
+
columnId: input.columnId,
|
|
18
|
+
description: input.description,
|
|
19
|
+
priority: input.priority ?? "MEDIUM",
|
|
20
|
+
order: nextOrder,
|
|
21
|
+
assigneeId: input.assigneeId,
|
|
22
|
+
isArchived: false,
|
|
23
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
24
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const _pendingBoardCreations = /* @__PURE__ */ new Map();
|
|
29
|
+
async function findOrCreateKanbanBoard(adapter, slug, name, columnTitles) {
|
|
30
|
+
const existing = await adapter.findOne({
|
|
31
|
+
model: "kanbanBoard",
|
|
32
|
+
where: [{ field: "slug", value: slug, operator: "eq" }]
|
|
33
|
+
});
|
|
34
|
+
if (existing) return existing;
|
|
35
|
+
const inflight = _pendingBoardCreations.get(slug);
|
|
36
|
+
if (inflight) return inflight;
|
|
37
|
+
const creation = (async () => {
|
|
38
|
+
try {
|
|
39
|
+
const board = await adapter.create({
|
|
40
|
+
model: "kanbanBoard",
|
|
41
|
+
data: {
|
|
42
|
+
name,
|
|
43
|
+
slug,
|
|
44
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
45
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
await Promise.all(
|
|
49
|
+
columnTitles.map(
|
|
50
|
+
(title, index) => adapter.create({
|
|
51
|
+
model: "kanbanColumn",
|
|
52
|
+
data: {
|
|
53
|
+
title,
|
|
54
|
+
boardId: board.id,
|
|
55
|
+
order: index,
|
|
56
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
57
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
)
|
|
61
|
+
);
|
|
62
|
+
return board;
|
|
63
|
+
} catch (err) {
|
|
64
|
+
const winner = await adapter.findOne({
|
|
65
|
+
model: "kanbanBoard",
|
|
66
|
+
where: [{ field: "slug", value: slug, operator: "eq" }]
|
|
67
|
+
});
|
|
68
|
+
if (winner) return winner;
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
})();
|
|
72
|
+
_pendingBoardCreations.set(slug, creation);
|
|
73
|
+
try {
|
|
74
|
+
return await creation;
|
|
75
|
+
} finally {
|
|
76
|
+
_pendingBoardCreations.delete(slug);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async function getKanbanColumnsByBoardId(adapter, boardId) {
|
|
80
|
+
return adapter.findMany({
|
|
81
|
+
model: "kanbanColumn",
|
|
82
|
+
where: [{ field: "boardId", value: boardId, operator: "eq" }],
|
|
83
|
+
sortBy: { field: "order", direction: "asc" }
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { createKanbanTask, findOrCreateKanbanBoard, getKanbanColumnsByBoardId };
|
|
@@ -5,6 +5,7 @@ const db = require('../db.cjs');
|
|
|
5
5
|
const utils = require('../utils.cjs');
|
|
6
6
|
const schemas = require('../schemas.cjs');
|
|
7
7
|
const getters = require('./getters.cjs');
|
|
8
|
+
const mutations = require('./mutations.cjs');
|
|
8
9
|
const queryKeyDefs = require('./query-key-defs.cjs');
|
|
9
10
|
const serializers = require('./serializers.cjs');
|
|
10
11
|
|
|
@@ -39,7 +40,11 @@ const kanbanBackendPlugin = (hooks) => api.defineBackendPlugin({
|
|
|
39
40
|
api: (adapter) => ({
|
|
40
41
|
getAllBoards: (params) => getters.getAllBoards(adapter, params),
|
|
41
42
|
getBoardById: (id) => getters.getBoardById(adapter, id),
|
|
42
|
-
prefetchForRoute: createKanbanPrefetchForRoute(adapter)
|
|
43
|
+
prefetchForRoute: createKanbanPrefetchForRoute(adapter),
|
|
44
|
+
// Mutations
|
|
45
|
+
createTask: (input) => mutations.createKanbanTask(adapter, input),
|
|
46
|
+
findOrCreateBoard: (slug, name, columnTitles) => mutations.findOrCreateKanbanBoard(adapter, slug, name, columnTitles),
|
|
47
|
+
getColumnsByBoardId: (boardId) => mutations.getKanbanColumnsByBoardId(adapter, boardId)
|
|
43
48
|
}),
|
|
44
49
|
routes: (adapter) => {
|
|
45
50
|
const listBoards = api.createEndpoint(
|
|
@@ -3,6 +3,7 @@ import { kanbanSchema } from '../db.mjs';
|
|
|
3
3
|
import { slugify } from '../utils.mjs';
|
|
4
4
|
import { BoardListQuerySchema, createBoardSchema, updateBoardSchema, createColumnSchema, updateColumnSchema, reorderColumnsSchema, createTaskSchema, updateTaskSchema, moveTaskSchema, reorderTasksSchema } from '../schemas.mjs';
|
|
5
5
|
import { getBoardById, getAllBoards } from './getters.mjs';
|
|
6
|
+
import { getKanbanColumnsByBoardId, findOrCreateKanbanBoard, createKanbanTask } from './mutations.mjs';
|
|
6
7
|
import { KANBAN_QUERY_KEYS } from './query-key-defs.mjs';
|
|
7
8
|
import { serializeBoard } from './serializers.mjs';
|
|
8
9
|
|
|
@@ -37,7 +38,11 @@ const kanbanBackendPlugin = (hooks) => defineBackendPlugin({
|
|
|
37
38
|
api: (adapter) => ({
|
|
38
39
|
getAllBoards: (params) => getAllBoards(adapter, params),
|
|
39
40
|
getBoardById: (id) => getBoardById(adapter, id),
|
|
40
|
-
prefetchForRoute: createKanbanPrefetchForRoute(adapter)
|
|
41
|
+
prefetchForRoute: createKanbanPrefetchForRoute(adapter),
|
|
42
|
+
// Mutations
|
|
43
|
+
createTask: (input) => createKanbanTask(adapter, input),
|
|
44
|
+
findOrCreateBoard: (slug, name, columnTitles) => findOrCreateKanbanBoard(adapter, slug, name, columnTitles),
|
|
45
|
+
getColumnsByBoardId: (boardId) => getKanbanColumnsByBoardId(adapter, boardId)
|
|
41
46
|
}),
|
|
42
47
|
routes: (adapter) => {
|
|
43
48
|
const listBoards = createEndpoint(
|
|
@@ -35,7 +35,8 @@ function useBoards(params) {
|
|
|
35
35
|
const queries = plugins_kanban_queryKeys.createKanbanQueryKeys(client, headers);
|
|
36
36
|
return reactQuery.useQuery({
|
|
37
37
|
...queries.boards.list(params),
|
|
38
|
-
staleTime: 3e4
|
|
38
|
+
staleTime: 3e4,
|
|
39
|
+
refetchOnWindowFocus: true
|
|
39
40
|
});
|
|
40
41
|
}
|
|
41
42
|
function useSuspenseBoards(params) {
|
|
@@ -43,7 +44,8 @@ function useSuspenseBoards(params) {
|
|
|
43
44
|
const queries = plugins_kanban_queryKeys.createKanbanQueryKeys(client, headers);
|
|
44
45
|
const result = reactQuery.useSuspenseQuery({
|
|
45
46
|
...queries.boards.list(params),
|
|
46
|
-
staleTime: 3e4
|
|
47
|
+
staleTime: 3e4,
|
|
48
|
+
refetchOnWindowFocus: true
|
|
47
49
|
});
|
|
48
50
|
if (result.error && !result.isFetching) {
|
|
49
51
|
throw result.error;
|
|
@@ -56,6 +58,7 @@ function useBoard(boardId) {
|
|
|
56
58
|
return reactQuery.useQuery({
|
|
57
59
|
...queries.boards.detail(boardId),
|
|
58
60
|
staleTime: 3e4,
|
|
61
|
+
refetchOnWindowFocus: true,
|
|
59
62
|
enabled: !!boardId
|
|
60
63
|
});
|
|
61
64
|
}
|
|
@@ -64,7 +67,8 @@ function useSuspenseBoard(boardId) {
|
|
|
64
67
|
const queries = plugins_kanban_queryKeys.createKanbanQueryKeys(client, headers);
|
|
65
68
|
const result = reactQuery.useSuspenseQuery({
|
|
66
69
|
...queries.boards.detail(boardId),
|
|
67
|
-
staleTime: 3e4
|
|
70
|
+
staleTime: 3e4,
|
|
71
|
+
refetchOnWindowFocus: true
|
|
68
72
|
});
|
|
69
73
|
if (result.error && !result.isFetching) {
|
|
70
74
|
throw result.error;
|
|
@@ -33,7 +33,8 @@ function useBoards(params) {
|
|
|
33
33
|
const queries = createKanbanQueryKeys(client, headers);
|
|
34
34
|
return useQuery({
|
|
35
35
|
...queries.boards.list(params),
|
|
36
|
-
staleTime: 3e4
|
|
36
|
+
staleTime: 3e4,
|
|
37
|
+
refetchOnWindowFocus: true
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
40
|
function useSuspenseBoards(params) {
|
|
@@ -41,7 +42,8 @@ function useSuspenseBoards(params) {
|
|
|
41
42
|
const queries = createKanbanQueryKeys(client, headers);
|
|
42
43
|
const result = useSuspenseQuery({
|
|
43
44
|
...queries.boards.list(params),
|
|
44
|
-
staleTime: 3e4
|
|
45
|
+
staleTime: 3e4,
|
|
46
|
+
refetchOnWindowFocus: true
|
|
45
47
|
});
|
|
46
48
|
if (result.error && !result.isFetching) {
|
|
47
49
|
throw result.error;
|
|
@@ -54,6 +56,7 @@ function useBoard(boardId) {
|
|
|
54
56
|
return useQuery({
|
|
55
57
|
...queries.boards.detail(boardId),
|
|
56
58
|
staleTime: 3e4,
|
|
59
|
+
refetchOnWindowFocus: true,
|
|
57
60
|
enabled: !!boardId
|
|
58
61
|
});
|
|
59
62
|
}
|
|
@@ -62,7 +65,8 @@ function useSuspenseBoard(boardId) {
|
|
|
62
65
|
const queries = createKanbanQueryKeys(client, headers);
|
|
63
66
|
const result = useSuspenseQuery({
|
|
64
67
|
...queries.boards.detail(boardId),
|
|
65
|
-
staleTime: 3e4
|
|
68
|
+
staleTime: 3e4,
|
|
69
|
+
refetchOnWindowFocus: true
|
|
66
70
|
});
|
|
67
71
|
if (result.error && !result.isFetching) {
|
|
68
72
|
throw result.error;
|
|
@@ -12,10 +12,73 @@ const label = require('../../../../../../../ui/src/components/label.cjs');
|
|
|
12
12
|
const LucideIcons = require('lucide-react');
|
|
13
13
|
const sonner = require('sonner');
|
|
14
14
|
const index$1 = require('../../../../../../../ui/src/components/ui-builder/index.cjs');
|
|
15
|
+
const layerStore = require('../../../../../../../ui/src/lib/ui-builder/store/layer-store.cjs');
|
|
16
|
+
const context$1 = require('@btst/stack/plugins/ai-chat/client/context');
|
|
15
17
|
const uiBuilderHooks = require('../../hooks/ui-builder-hooks.cjs');
|
|
16
18
|
const index = require('../../localization/index.cjs');
|
|
17
19
|
const registry = require('../../registry.cjs');
|
|
18
20
|
|
|
21
|
+
function buildRegistryDescription(registry) {
|
|
22
|
+
const lines = [];
|
|
23
|
+
for (const [name, entry] of Object.entries(registry)) {
|
|
24
|
+
let propsLine = "";
|
|
25
|
+
try {
|
|
26
|
+
const shape = entry.schema?.shape;
|
|
27
|
+
if (shape) {
|
|
28
|
+
const fields = Object.keys(shape).join(", ");
|
|
29
|
+
propsLine = ` \u2014 props: ${fields}`;
|
|
30
|
+
}
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
lines.push(`- ${name}${propsLine}`);
|
|
34
|
+
}
|
|
35
|
+
return lines.join("\n");
|
|
36
|
+
}
|
|
37
|
+
function buildPageDescription(id, slug, layers, registry) {
|
|
38
|
+
const header = id ? `UI Builder \u2014 editing page (slug: "${slug}")` : "UI Builder \u2014 creating new page";
|
|
39
|
+
const layersJson = JSON.stringify(layers, null, 2);
|
|
40
|
+
const registryDesc = buildRegistryDescription(registry);
|
|
41
|
+
const layerFormat = `Each layer: { id: string, type: string, name: string, props: Record<string,any>, children?: ComponentLayer[] | string }`;
|
|
42
|
+
const full = [
|
|
43
|
+
header,
|
|
44
|
+
"",
|
|
45
|
+
`## Current Layers (${layers.length})`,
|
|
46
|
+
layersJson,
|
|
47
|
+
"",
|
|
48
|
+
`## Available Component Types`,
|
|
49
|
+
registryDesc,
|
|
50
|
+
"",
|
|
51
|
+
`## ComponentLayer format`,
|
|
52
|
+
layerFormat
|
|
53
|
+
].join("\n");
|
|
54
|
+
if (full.length <= 16e3) return full;
|
|
55
|
+
const overhead = [
|
|
56
|
+
header,
|
|
57
|
+
"",
|
|
58
|
+
`## Current Layers (${layers.length})`,
|
|
59
|
+
"",
|
|
60
|
+
"",
|
|
61
|
+
`## Available Component Types`,
|
|
62
|
+
registryDesc,
|
|
63
|
+
"",
|
|
64
|
+
`## ComponentLayer format`,
|
|
65
|
+
layerFormat
|
|
66
|
+
].join("\n").length + 30;
|
|
67
|
+
const budget = Math.max(0, 16e3 - overhead);
|
|
68
|
+
const truncatedLayers = layersJson.length > budget ? layersJson.slice(0, budget) + "\n...(truncated)" : layersJson;
|
|
69
|
+
return [
|
|
70
|
+
header,
|
|
71
|
+
"",
|
|
72
|
+
`## Current Layers (${layers.length})`,
|
|
73
|
+
truncatedLayers,
|
|
74
|
+
"",
|
|
75
|
+
`## Available Component Types`,
|
|
76
|
+
registryDesc,
|
|
77
|
+
"",
|
|
78
|
+
`## ComponentLayer format`,
|
|
79
|
+
layerFormat
|
|
80
|
+
].join("\n");
|
|
81
|
+
}
|
|
19
82
|
function slugify(str) {
|
|
20
83
|
return str.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
21
84
|
}
|
|
@@ -72,6 +135,32 @@ function PageBuilderPageContent({
|
|
|
72
135
|
const [layers, setLayers] = React.useState(existingLayers);
|
|
73
136
|
const [variables, setVariables] = React.useState(existingVariables);
|
|
74
137
|
const [autoSlug, setAutoSlug] = React.useState(!id);
|
|
138
|
+
context$1.useRegisterPageAIContext({
|
|
139
|
+
routeName: id ? "ui-builder-edit-page" : "ui-builder-new-page",
|
|
140
|
+
pageDescription: buildPageDescription(id, slug, layers, componentRegistry),
|
|
141
|
+
suggestions: [
|
|
142
|
+
"Add a hero section",
|
|
143
|
+
"Add a 3-column feature grid",
|
|
144
|
+
"Make the layout full-width",
|
|
145
|
+
"Add a card with a title, description, and button",
|
|
146
|
+
"Replace the layout with a centered single-column design"
|
|
147
|
+
],
|
|
148
|
+
clientTools: {
|
|
149
|
+
updatePageLayers: async ({ layers: newLayers }) => {
|
|
150
|
+
const store = layerStore.useLayerStore.getState();
|
|
151
|
+
store.initialize(
|
|
152
|
+
newLayers,
|
|
153
|
+
store.selectedPageId || newLayers[0]?.id,
|
|
154
|
+
void 0,
|
|
155
|
+
store.variables
|
|
156
|
+
);
|
|
157
|
+
return {
|
|
158
|
+
success: true,
|
|
159
|
+
message: `Applied ${newLayers.length} layer(s) to the page`
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
});
|
|
75
164
|
const handleLayersChange = React.useCallback(
|
|
76
165
|
(newLayers) => {
|
|
77
166
|
setLayers(newLayers);
|
|
@@ -10,10 +10,73 @@ import { Label } from '../../../../../../../ui/src/components/label.mjs';
|
|
|
10
10
|
import { ArrowLeft, Settings2, Save } from 'lucide-react';
|
|
11
11
|
import { toast } from 'sonner';
|
|
12
12
|
import UIBuilder from '../../../../../../../ui/src/components/ui-builder/index.mjs';
|
|
13
|
+
import { useLayerStore } from '../../../../../../../ui/src/lib/ui-builder/store/layer-store.mjs';
|
|
14
|
+
import { useRegisterPageAIContext } from '@btst/stack/plugins/ai-chat/client/context';
|
|
13
15
|
import { useSuspenseUIBuilderPage, useCreateUIBuilderPage, useUpdateUIBuilderPage } from '../../hooks/ui-builder-hooks.mjs';
|
|
14
16
|
import { uiBuilderLocalization } from '../../localization/index.mjs';
|
|
15
17
|
import { defaultComponentRegistry } from '../../registry.mjs';
|
|
16
18
|
|
|
19
|
+
function buildRegistryDescription(registry) {
|
|
20
|
+
const lines = [];
|
|
21
|
+
for (const [name, entry] of Object.entries(registry)) {
|
|
22
|
+
let propsLine = "";
|
|
23
|
+
try {
|
|
24
|
+
const shape = entry.schema?.shape;
|
|
25
|
+
if (shape) {
|
|
26
|
+
const fields = Object.keys(shape).join(", ");
|
|
27
|
+
propsLine = ` \u2014 props: ${fields}`;
|
|
28
|
+
}
|
|
29
|
+
} catch {
|
|
30
|
+
}
|
|
31
|
+
lines.push(`- ${name}${propsLine}`);
|
|
32
|
+
}
|
|
33
|
+
return lines.join("\n");
|
|
34
|
+
}
|
|
35
|
+
function buildPageDescription(id, slug, layers, registry) {
|
|
36
|
+
const header = id ? `UI Builder \u2014 editing page (slug: "${slug}")` : "UI Builder \u2014 creating new page";
|
|
37
|
+
const layersJson = JSON.stringify(layers, null, 2);
|
|
38
|
+
const registryDesc = buildRegistryDescription(registry);
|
|
39
|
+
const layerFormat = `Each layer: { id: string, type: string, name: string, props: Record<string,any>, children?: ComponentLayer[] | string }`;
|
|
40
|
+
const full = [
|
|
41
|
+
header,
|
|
42
|
+
"",
|
|
43
|
+
`## Current Layers (${layers.length})`,
|
|
44
|
+
layersJson,
|
|
45
|
+
"",
|
|
46
|
+
`## Available Component Types`,
|
|
47
|
+
registryDesc,
|
|
48
|
+
"",
|
|
49
|
+
`## ComponentLayer format`,
|
|
50
|
+
layerFormat
|
|
51
|
+
].join("\n");
|
|
52
|
+
if (full.length <= 16e3) return full;
|
|
53
|
+
const overhead = [
|
|
54
|
+
header,
|
|
55
|
+
"",
|
|
56
|
+
`## Current Layers (${layers.length})`,
|
|
57
|
+
"",
|
|
58
|
+
"",
|
|
59
|
+
`## Available Component Types`,
|
|
60
|
+
registryDesc,
|
|
61
|
+
"",
|
|
62
|
+
`## ComponentLayer format`,
|
|
63
|
+
layerFormat
|
|
64
|
+
].join("\n").length + 30;
|
|
65
|
+
const budget = Math.max(0, 16e3 - overhead);
|
|
66
|
+
const truncatedLayers = layersJson.length > budget ? layersJson.slice(0, budget) + "\n...(truncated)" : layersJson;
|
|
67
|
+
return [
|
|
68
|
+
header,
|
|
69
|
+
"",
|
|
70
|
+
`## Current Layers (${layers.length})`,
|
|
71
|
+
truncatedLayers,
|
|
72
|
+
"",
|
|
73
|
+
`## Available Component Types`,
|
|
74
|
+
registryDesc,
|
|
75
|
+
"",
|
|
76
|
+
`## ComponentLayer format`,
|
|
77
|
+
layerFormat
|
|
78
|
+
].join("\n");
|
|
79
|
+
}
|
|
17
80
|
function slugify(str) {
|
|
18
81
|
return str.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
19
82
|
}
|
|
@@ -70,6 +133,32 @@ function PageBuilderPageContent({
|
|
|
70
133
|
const [layers, setLayers] = useState(existingLayers);
|
|
71
134
|
const [variables, setVariables] = useState(existingVariables);
|
|
72
135
|
const [autoSlug, setAutoSlug] = useState(!id);
|
|
136
|
+
useRegisterPageAIContext({
|
|
137
|
+
routeName: id ? "ui-builder-edit-page" : "ui-builder-new-page",
|
|
138
|
+
pageDescription: buildPageDescription(id, slug, layers, componentRegistry),
|
|
139
|
+
suggestions: [
|
|
140
|
+
"Add a hero section",
|
|
141
|
+
"Add a 3-column feature grid",
|
|
142
|
+
"Make the layout full-width",
|
|
143
|
+
"Add a card with a title, description, and button",
|
|
144
|
+
"Replace the layout with a centered single-column design"
|
|
145
|
+
],
|
|
146
|
+
clientTools: {
|
|
147
|
+
updatePageLayers: async ({ layers: newLayers }) => {
|
|
148
|
+
const store = useLayerStore.getState();
|
|
149
|
+
store.initialize(
|
|
150
|
+
newLayers,
|
|
151
|
+
store.selectedPageId || newLayers[0]?.id,
|
|
152
|
+
void 0,
|
|
153
|
+
store.variables
|
|
154
|
+
);
|
|
155
|
+
return {
|
|
156
|
+
success: true,
|
|
157
|
+
message: `Applied ${newLayers.length} layer(s) to the page`
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
});
|
|
73
162
|
const handleLayersChange = useCallback(
|
|
74
163
|
(newLayers) => {
|
|
75
164
|
setLayers(newLayers);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { e as AiChatApiRouter, b as AiChatBackendConfig, A as AiChatBackendHooks, a as AiChatMode, C as ChatApiContext, d as aiChatBackendPlugin, c as createAiChatQueryKeys } from '../../../shared/stack.
|
|
1
|
+
export { e as AiChatApiRouter, b as AiChatBackendConfig, A as AiChatBackendHooks, a as AiChatMode, C as ChatApiContext, d as aiChatBackendPlugin, c as createAiChatQueryKeys } from '../../../shared/stack.DWoCZff7.cjs';
|
|
2
2
|
import { Adapter } from '@btst/db';
|
|
3
3
|
import { C as Conversation, M as Message } from '../../../shared/stack.Be1QIHEn.cjs';
|
|
4
4
|
import '@tanstack/react-query';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { e as AiChatApiRouter, b as AiChatBackendConfig, A as AiChatBackendHooks, a as AiChatMode, C as ChatApiContext, d as aiChatBackendPlugin, c as createAiChatQueryKeys } from '../../../shared/stack.
|
|
1
|
+
export { e as AiChatApiRouter, b as AiChatBackendConfig, A as AiChatBackendHooks, a as AiChatMode, C as ChatApiContext, d as aiChatBackendPlugin, c as createAiChatQueryKeys } from '../../../shared/stack.DTDxgFj8.mjs';
|
|
2
2
|
import { Adapter } from '@btst/db';
|
|
3
3
|
import { C as Conversation, M as Message } from '../../../shared/stack.Be1QIHEn.mjs';
|
|
4
4
|
import '@tanstack/react-query';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { e as AiChatApiRouter, b as AiChatBackendConfig, A as AiChatBackendHooks, a as AiChatMode, C as ChatApiContext, d as aiChatBackendPlugin, c as createAiChatQueryKeys } from '../../../shared/stack.
|
|
1
|
+
export { e as AiChatApiRouter, b as AiChatBackendConfig, A as AiChatBackendHooks, a as AiChatMode, C as ChatApiContext, d as aiChatBackendPlugin, c as createAiChatQueryKeys } from '../../../shared/stack.BEn34wW6.js';
|
|
2
2
|
import { Adapter } from '@btst/db';
|
|
3
3
|
import { C as Conversation, M as Message } from '../../../shared/stack.Be1QIHEn.js';
|
|
4
4
|
import '@tanstack/react-query';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { i as ChatInput, C as ChatInterface, e as ChatLayout, f as ChatLayoutProps, h as ChatMessage, g as ChatSidebar, j as ToolCallDisplay } from '../../../../shared/stack.
|
|
1
|
+
export { i as ChatInput, C as ChatInterface, e as ChatLayout, f as ChatLayoutProps, h as ChatMessage, g as ChatSidebar, j as ToolCallDisplay } from '../../../../shared/stack.BV9hnvu4.cjs';
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
import { FallbackProps } from 'react-error-boundary';
|
|
4
4
|
import 'ai';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { i as ChatInput, C as ChatInterface, e as ChatLayout, f as ChatLayoutProps, h as ChatMessage, g as ChatSidebar, j as ToolCallDisplay } from '../../../../shared/stack.
|
|
1
|
+
export { i as ChatInput, C as ChatInterface, e as ChatLayout, f as ChatLayoutProps, h as ChatMessage, g as ChatSidebar, j as ToolCallDisplay } from '../../../../shared/stack.BV9hnvu4.mjs';
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
import { FallbackProps } from 'react-error-boundary';
|
|
4
4
|
import 'ai';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { i as ChatInput, C as ChatInterface, e as ChatLayout, f as ChatLayoutProps, h as ChatMessage, g as ChatSidebar, j as ToolCallDisplay } from '../../../../shared/stack.
|
|
1
|
+
export { i as ChatInput, C as ChatInterface, e as ChatLayout, f as ChatLayoutProps, h as ChatMessage, g as ChatSidebar, j as ToolCallDisplay } from '../../../../shared/stack.BV9hnvu4.js';
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
import { FallbackProps } from 'react-error-boundary';
|
|
4
4
|
import 'ai';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
const React = require('react');
|
|
6
|
+
|
|
7
|
+
const PageAIAPIContext = React.createContext(null);
|
|
8
|
+
const PageAIVersionContext = React.createContext(0);
|
|
9
|
+
function PageAIContextProvider({
|
|
10
|
+
children
|
|
11
|
+
}) {
|
|
12
|
+
const registrationsRef = React.useRef(/* @__PURE__ */ new Map());
|
|
13
|
+
const insertionOrderRef = React.useRef([]);
|
|
14
|
+
const [version, setVersion] = React.useState(0);
|
|
15
|
+
const bumpVersion = React.useCallback(() => setVersion((v) => v + 1), []);
|
|
16
|
+
const register = React.useCallback(
|
|
17
|
+
(id, config) => {
|
|
18
|
+
registrationsRef.current.set(id, config);
|
|
19
|
+
insertionOrderRef.current = insertionOrderRef.current.filter(
|
|
20
|
+
(k) => k !== id
|
|
21
|
+
);
|
|
22
|
+
insertionOrderRef.current.push(id);
|
|
23
|
+
bumpVersion();
|
|
24
|
+
},
|
|
25
|
+
[bumpVersion]
|
|
26
|
+
);
|
|
27
|
+
const unregister = React.useCallback(
|
|
28
|
+
(id) => {
|
|
29
|
+
registrationsRef.current.delete(id);
|
|
30
|
+
insertionOrderRef.current = insertionOrderRef.current.filter(
|
|
31
|
+
(k) => k !== id
|
|
32
|
+
);
|
|
33
|
+
bumpVersion();
|
|
34
|
+
},
|
|
35
|
+
[bumpVersion]
|
|
36
|
+
);
|
|
37
|
+
const getActive = React.useCallback(() => {
|
|
38
|
+
const order = insertionOrderRef.current;
|
|
39
|
+
if (order.length === 0) return null;
|
|
40
|
+
const lastId = order[order.length - 1];
|
|
41
|
+
if (!lastId) return null;
|
|
42
|
+
return registrationsRef.current.get(lastId) ?? null;
|
|
43
|
+
}, []);
|
|
44
|
+
const api = React.useMemo(
|
|
45
|
+
() => ({ register, unregister, getActive }),
|
|
46
|
+
[register, unregister, getActive]
|
|
47
|
+
);
|
|
48
|
+
return /* @__PURE__ */ jsxRuntime.jsx(PageAIAPIContext.Provider, { value: api, children: /* @__PURE__ */ jsxRuntime.jsx(PageAIVersionContext.Provider, { value: version, children }) });
|
|
49
|
+
}
|
|
50
|
+
function useRegisterPageAIContext(config) {
|
|
51
|
+
const ctx = React.useContext(PageAIAPIContext);
|
|
52
|
+
const id = React.useId();
|
|
53
|
+
const configRef = React.useRef(config);
|
|
54
|
+
configRef.current = config;
|
|
55
|
+
React.useEffect(() => {
|
|
56
|
+
if (!ctx || !configRef.current) return;
|
|
57
|
+
ctx.register(id, {
|
|
58
|
+
get routeName() {
|
|
59
|
+
return configRef.current?.routeName ?? "";
|
|
60
|
+
},
|
|
61
|
+
get pageDescription() {
|
|
62
|
+
return configRef.current?.pageDescription ?? "";
|
|
63
|
+
},
|
|
64
|
+
get suggestions() {
|
|
65
|
+
return configRef.current?.suggestions;
|
|
66
|
+
},
|
|
67
|
+
get clientTools() {
|
|
68
|
+
return configRef.current?.clientTools;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return () => {
|
|
72
|
+
ctx.unregister(id);
|
|
73
|
+
};
|
|
74
|
+
}, [
|
|
75
|
+
ctx,
|
|
76
|
+
id,
|
|
77
|
+
config === null,
|
|
78
|
+
config?.routeName,
|
|
79
|
+
config?.pageDescription,
|
|
80
|
+
JSON.stringify(config?.suggestions)
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
function usePageAIContext() {
|
|
84
|
+
React.useContext(PageAIVersionContext);
|
|
85
|
+
const ctx = React.useContext(PageAIAPIContext);
|
|
86
|
+
if (!ctx) return null;
|
|
87
|
+
return ctx.getActive();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
exports.PageAIContextProvider = PageAIContextProvider;
|
|
91
|
+
exports.usePageAIContext = usePageAIContext;
|
|
92
|
+
exports.useRegisterPageAIContext = useRegisterPageAIContext;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A client-side tool handler — receives the AI's tool call args and returns a result.
|
|
5
|
+
* The result is sent back to the model so it can continue the conversation.
|
|
6
|
+
*/
|
|
7
|
+
type PageAIClientTool = (args: any) => Promise<{
|
|
8
|
+
success: boolean;
|
|
9
|
+
message?: string;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Configuration registered by a page to provide AI context and capabilities.
|
|
13
|
+
* Any component in the tree can call useRegisterPageAIContext with this config.
|
|
14
|
+
*/
|
|
15
|
+
interface PageAIContextConfig {
|
|
16
|
+
/**
|
|
17
|
+
* Identifier for the current route/page (e.g. "blog-post", "ui-builder-edit-page").
|
|
18
|
+
* Shown as a badge in the chat header.
|
|
19
|
+
*/
|
|
20
|
+
routeName: string;
|
|
21
|
+
/**
|
|
22
|
+
* Human-readable description of the current page and its content.
|
|
23
|
+
* Injected into the AI system prompt so it understands what the user is looking at.
|
|
24
|
+
* Capped at 8,000 characters server-side.
|
|
25
|
+
*/
|
|
26
|
+
pageDescription: string;
|
|
27
|
+
/**
|
|
28
|
+
* Optional suggested prompts shown as quick-action chips in the chat empty state.
|
|
29
|
+
* These augment (not replace) any static suggestions configured in plugin overrides.
|
|
30
|
+
*/
|
|
31
|
+
suggestions?: string[];
|
|
32
|
+
/**
|
|
33
|
+
* Client-side tool handlers keyed by tool name.
|
|
34
|
+
* When the AI calls a tool by this name, the handler is invoked with the tool args.
|
|
35
|
+
* The result is sent back to the model via addToolResult.
|
|
36
|
+
*
|
|
37
|
+
* Tool schemas must be registered server-side via enablePageTools + clientToolSchemas
|
|
38
|
+
* in aiChatBackendPlugin (built-in tools like fillBlogForm are pre-registered).
|
|
39
|
+
*/
|
|
40
|
+
clientTools?: Record<string, PageAIClientTool>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Provider that enables route-aware AI context across the app.
|
|
44
|
+
*
|
|
45
|
+
* Place this at the root layout — above all StackProviders — so it spans
|
|
46
|
+
* both your main app tree and any chat modals rendered as parallel/intercept routes.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* // app/layout.tsx
|
|
50
|
+
* import { PageAIContextProvider } from "@btst/stack/plugins/ai-chat/client/context"
|
|
51
|
+
*
|
|
52
|
+
* export default function RootLayout({ children }) {
|
|
53
|
+
* return <PageAIContextProvider>{children}</PageAIContextProvider>
|
|
54
|
+
* }
|
|
55
|
+
*/
|
|
56
|
+
declare function PageAIContextProvider({ children, }: {
|
|
57
|
+
children: React.ReactNode;
|
|
58
|
+
}): react_jsx_runtime.JSX.Element;
|
|
59
|
+
/**
|
|
60
|
+
* Register page AI context from any component.
|
|
61
|
+
* The registration is cleaned up automatically when the component unmounts.
|
|
62
|
+
*
|
|
63
|
+
* Pass `null` to conditionally disable context (e.g. while data is loading).
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* // Blog post page
|
|
67
|
+
* useRegisterPageAIContext(post ? {
|
|
68
|
+
* routeName: "blog-post",
|
|
69
|
+
* pageDescription: `Blog post: "${post.title}"\n\n${post.content?.slice(0, 16000)}`,
|
|
70
|
+
* suggestions: ["Summarize this post", "What are the key takeaways?"],
|
|
71
|
+
* } : null)
|
|
72
|
+
*/
|
|
73
|
+
declare function useRegisterPageAIContext(config: PageAIContextConfig | null): void;
|
|
74
|
+
/**
|
|
75
|
+
* Read the currently active page AI context.
|
|
76
|
+
* Returns null when no page has registered context, or when PageAIContextProvider
|
|
77
|
+
* is not in the tree.
|
|
78
|
+
*
|
|
79
|
+
* Used internally by ChatInterface to inject context into requests.
|
|
80
|
+
*/
|
|
81
|
+
declare function usePageAIContext(): PageAIContextConfig | null;
|
|
82
|
+
|
|
83
|
+
export { PageAIContextProvider, usePageAIContext, useRegisterPageAIContext };
|
|
84
|
+
export type { PageAIClientTool, PageAIContextConfig };
|