@chat-js/registry 0.2.0-beta.8 → 0.2.0-beta.9
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/README.md +4 -4
- package/dist/r/ai-titles.json +10 -13
- package/dist/r/attach-workspace-file.json +1 -1
- package/dist/r/attachment-uploads.json +13 -22
- package/dist/r/base/ai-titles.json +10 -13
- package/dist/r/base/attach-workspace-file.json +1 -1
- package/dist/r/base/attachment-uploads.json +13 -22
- package/dist/r/base/credits.json +11 -33
- package/dist/r/base/desktop.json +14 -30
- package/dist/r/base/feedback.json +18 -40
- package/dist/r/base/followup-suggestions.json +18 -40
- package/dist/r/base/guest-chat.json +19 -34
- package/dist/r/base/image-viewer.json +9 -15
- package/dist/r/base/mcp.json +23 -46
- package/dist/r/base/memory-storage.json +2 -2
- package/dist/r/base/model-preferences.json +15 -36
- package/dist/r/base/projects.json +23 -45
- package/dist/r/base/registry.json +137 -366
- package/dist/r/base/search.json +21 -43
- package/dist/r/base/sharing.json +18 -40
- package/dist/r/base/spreadsheet-viewer.json +9 -15
- package/dist/r/base/video-viewer.json +9 -15
- package/dist/r/credits.json +11 -33
- package/dist/r/desktop.json +14 -30
- package/dist/r/feedback.json +18 -40
- package/dist/r/followup-suggestions.json +18 -40
- package/dist/r/guest-chat.json +19 -34
- package/dist/r/image-viewer.json +9 -15
- package/dist/r/mcp.json +23 -46
- package/dist/r/memory-storage.json +2 -2
- package/dist/r/model-preferences.json +15 -36
- package/dist/r/projects.json +23 -45
- package/dist/r/radix/ai-titles.json +10 -13
- package/dist/r/radix/attach-workspace-file.json +1 -1
- package/dist/r/radix/attachment-uploads.json +13 -22
- package/dist/r/radix/credits.json +11 -33
- package/dist/r/radix/desktop.json +14 -30
- package/dist/r/radix/feedback.json +18 -40
- package/dist/r/radix/followup-suggestions.json +18 -40
- package/dist/r/radix/guest-chat.json +19 -34
- package/dist/r/radix/image-viewer.json +9 -15
- package/dist/r/radix/mcp.json +23 -46
- package/dist/r/radix/memory-storage.json +2 -2
- package/dist/r/radix/model-preferences.json +15 -36
- package/dist/r/radix/projects.json +23 -45
- package/dist/r/radix/registry.json +137 -366
- package/dist/r/radix/search.json +21 -43
- package/dist/r/radix/sharing.json +18 -40
- package/dist/r/radix/spreadsheet-viewer.json +9 -15
- package/dist/r/radix/video-viewer.json +9 -15
- package/dist/r/registry.json +137 -366
- package/dist/r/search.json +21 -43
- package/dist/r/sharing.json +18 -40
- package/dist/r/spreadsheet-viewer.json +9 -15
- package/dist/r/video-viewer.json +9 -15
- package/package.json +1 -1
package/dist/r/base/search.json
CHANGED
|
@@ -25,16 +25,16 @@
|
|
|
25
25
|
"target": "~/chatjs/plugins/search/backfill.ts"
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
|
-
"path": "src/plugins/search/src/chat.ts",
|
|
29
|
-
"content": "import { inArray } from \"drizzle-orm\";\nimport type { ChatServerIntegration } from \"@/chatjs/core/chat/contracts\";\nimport { eveSearchText } from \"./search-schema\";\n\
|
|
28
|
+
"path": "src/plugins/search/src/chat-server.ts",
|
|
29
|
+
"content": "import { inArray } from \"drizzle-orm\";\nimport type { ChatServerIntegration } from \"@/chatjs/core/chat/contracts\";\nimport { eveSearchText } from \"./search-schema\";\n\nconst searchChat = {\n afterBranch: async ({ ownerId, branchId, sessionId }) => {\n const { backfillEveSearchConversation } = await import(\"./search-backfill\");\n await backfillEveSearchConversation(ownerId, branchId, sessionId);\n },\n onDeleteConversations: async (tx, { branchIds }) => {\n if (branchIds.length === 0) {\n return;\n }\n await tx\n .delete(eveSearchText)\n .where(inArray(eveSearchText.branchId, [...branchIds]));\n },\n} satisfies ChatServerIntegration;\n\nexport default searchChat;\n",
|
|
30
30
|
"type": "registry:file",
|
|
31
|
-
"target": "~/chatjs/plugins/search/chat.ts"
|
|
31
|
+
"target": "~/chatjs/plugins/search/chat-server.ts"
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
|
-
"path": "src/plugins/search/src/
|
|
35
|
-
"content": "\"use client\";\nimport { definePlugin, slot } from \"@/chatjs/core/ui/slots\";\nimport { SidebarHeaderItems } from \"@/components/chat-slots\";\nimport { SearchSidebarItem } from \"./sidebar-item\";\n\nexport const
|
|
34
|
+
"path": "src/plugins/search/src/chat-ui.ts",
|
|
35
|
+
"content": "\"use client\";\nimport { definePlugin, slot } from \"@/chatjs/core/ui/slots\";\nimport { SidebarHeaderItems } from \"@/components/chat-slots\";\nimport { SearchSidebarItem } from \"./sidebar-item\";\n\nexport const chatUi = definePlugin({\n id: \"search\",\n slots: [slot(SidebarHeaderItems, SearchSidebarItem)],\n});\n",
|
|
36
36
|
"type": "registry:file",
|
|
37
|
-
"target": "~/chatjs/plugins/search/
|
|
37
|
+
"target": "~/chatjs/plugins/search/chat-ui.ts"
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
40
|
"path": "src/plugins/search/src/sidebar-item.tsx",
|
|
@@ -44,19 +44,19 @@
|
|
|
44
44
|
},
|
|
45
45
|
{
|
|
46
46
|
"path": "src/plugins/search/src/router.ts",
|
|
47
|
-
"content": "import { TRPCError } from \"@trpc/server\";\nimport { z } from \"zod\";\nimport { eveOwnedProcedure } from \"@/trpc/eve-owned-procedure\";\nimport { createTRPCRouter } from \"@/trpc/init\";\nimport type { ReadonlyNativeSurface } from \"@/lib/readonly-native-surface\";\nimport { MAX_SEARCH_QUERY_LENGTH } from \"./search-text\";\nimport { searchEveConversations } from \"./search-queries\";\n\nconst MAX_OWNER_SCOPE_LENGTH = 128;\
|
|
47
|
+
"content": "import { TRPCError } from \"@trpc/server\";\nimport { z } from \"zod\";\nimport { eveOwnedProcedure } from \"@/trpc/eve-owned-procedure\";\nimport { createTRPCRouter } from \"@/trpc/init\";\nimport type { ReadonlyNativeSurface } from \"@/lib/readonly-native-surface\";\nimport { MAX_SEARCH_QUERY_LENGTH } from \"./search-text\";\nimport { searchEveConversations } from \"./search-queries\";\n\nconst MAX_OWNER_SCOPE_LENGTH = 128;\nconst searchProcedures = {\n query: eveOwnedProcedure\n .input(\n z.object({\n cursor: z\n .object({\n id: z.uuid(),\n rank: z.number().nonnegative(),\n updatedAt: z.iso.datetime(),\n })\n .nullish(),\n ownerScope: z.string().nonempty().max(MAX_OWNER_SCOPE_LENGTH),\n search: z.string().trim().nonempty().max(MAX_SEARCH_QUERY_LENGTH),\n })\n )\n .query(\n async ({\n ctx,\n input,\n }: {\n readonly ctx: { readonly eveOwnerId: string };\n readonly input: ReadonlyNativeSurface<{\n ownerScope: string;\n search: string;\n cursor?:\n | { id: string; rank: number; updatedAt: string }\n | null\n | undefined;\n }>;\n }) => {\n if (input.ownerScope !== ctx.eveOwnerId) {\n throw new TRPCError({ code: \"FORBIDDEN\" });\n }\n return await searchEveConversations(ctx.eveOwnerId, input);\n }\n ),\n};\n\nexport const router = createTRPCRouter({ search: searchProcedures });\n",
|
|
48
48
|
"type": "registry:file",
|
|
49
49
|
"target": "~/chatjs/plugins/search/router.ts"
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
52
|
"path": "src/plugins/search/src/search-backfill.ts",
|
|
53
|
-
"content": "import { Client } from \"eve/client\";\n\nimport { indexEveSearchText } from \"@/chatjs/plugins/search/search-queries\";\n\nimport { getEveConnectionOptions } from \"@/lib/eve/connection-options\";\nimport type { EveSearchText } from \"./search-text\";\nimport { eveEventSearchText } from \"./search-text\";\n\nconst SEARCH_SNAPSHOT_TIMEOUT_MS = 30_000;\nconst SEARCH_INDEX_BATCH_SIZE = 100;\n\n/**\n * Recover from durable events, including text omitted from the bounded live retry buffer.\n * @param {string} ownerId Owner whose EVE credentials and search index receive the recovered text.\n * @param {string}
|
|
53
|
+
"content": "import { Client } from \"eve/client\";\n\nimport { indexEveSearchText } from \"@/chatjs/plugins/search/search-queries\";\n\nimport { getEveConnectionOptions } from \"@/lib/eve/connection-options\";\nimport type { EveSearchText } from \"./search-text\";\nimport { eveEventSearchText } from \"./search-text\";\n\nconst SEARCH_SNAPSHOT_TIMEOUT_MS = 30_000;\nconst SEARCH_INDEX_BATCH_SIZE = 100;\n\n/**\n * Recover from durable events, including text omitted from the bounded live retry buffer.\n * @param {string} ownerId Owner whose EVE credentials and search index receive the recovered text.\n * @param {string} branchId Conversation receiving idempotent event and seed search entries.\n * @param {string} sessionId Durable EVE session whose snapshot supplies the history.\n * @returns {Promise<void>} Resolves after every batch is indexed; snapshot and index failures reject for a later retry.\n */\nexport const backfillEveSearchConversation = async (\n ownerId: string,\n branchId: string,\n sessionId: string\n): Promise<void> => {\n const client = new Client(getEveConnectionOptions(ownerId));\n const snapshot = await client.sessions\n .attach(sessionId)\n .snapshot({ signal: AbortSignal.timeout(SEARCH_SNAPSHOT_TIMEOUT_MS) });\n let batch: EveSearchText[] = [];\n for (const event of snapshot.events) {\n for (const entry of eveEventSearchText(event)) {\n batch.push(entry);\n if (batch.length === SEARCH_INDEX_BATCH_SIZE) {\n // oxlint-disable-next-line eslint/no-await-in-loop -- Flush SEARCH_INDEX_BATCH_SIZE text entries before continuing the snapshot so a failed batch stops later writes and buffered indexing work stays bounded.\n await indexEveSearchText(ownerId, branchId, batch);\n batch = [];\n }\n }\n }\n await indexEveSearchText(ownerId, branchId, batch);\n};\n",
|
|
54
54
|
"type": "registry:file",
|
|
55
55
|
"target": "~/chatjs/plugins/search/search-backfill.ts"
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
58
|
"path": "src/plugins/search/src/search-chats.tsx",
|
|
59
|
-
"content": "\"use client\";\n\nimport { hasText } from \"@/components/text-value\";\n\nimport { useInfiniteQuery, useQueryClient } from \"@tanstack/react-query\";\nimport { SearchIcon } from \"lucide-react\";\nimport { useRouter } from \"next/navigation\";\nimport React, { useEffect, useState, useSyncExternalStore } from \"react\";\nimport type { JSX as ReactJSX } from \"react\";\n\nimport {\n DialogContent,\n DialogDescription,\n DialogHeader,\n DialogTitle,\n} from \"@/components/ui/dialog\";\nimport { useSidebar } from \"@/components/ui/sidebar\";\nimport { SearchSurface } from \"./search-surface\";\nimport type { ReadonlyNativeSurface } from \"@/lib/readonly-native-surface\";\nimport { useTRPC } from \"@/trpc/react\";\n\nimport { EveSearchResultsView } from \"./search-results-view\";\nimport { useDebouncedSearch } from \"./use-debounced-search\";\n\nconst SearchResults = ({\n onSelect,\n onClose,\n ownerId,\n}: {\n readonly onSelect: (id: string) => void;\n readonly onClose: () => void;\n readonly ownerId: string;\n}): ReactJSX.Element => {\n const trpc = useTRPC();\n const queryClient = useQueryClient();\n const [query, setQuery] = useState(\"\");\n const search = useDebouncedSearch(query);\n const history = useInfiniteQuery(\n trpc.eve.list.infiniteQueryOptions(\n { ownerScope: ownerId },\n {\n enabled: !query.trim(),\n getNextPageParam: (page: {\n readonly nextCursor: {\n readonly isPinned: boolean;\n readonly updatedAt: string;\n readonly id: string;\n } | null;\n }) => page.nextCursor,\n refetchOnWindowFocus: false,\n staleTime: 0,\n }\n )\n );\n const results = useInfiniteQuery(\n trpc.search.query.infiniteQueryOptions(\n { ownerScope: ownerId, search },\n {\n enabled: Boolean(search) && search === query.trim(),\n getNextPageParam: (page: {\n readonly nextCursor: {\n readonly rank: number;\n readonly updatedAt: string;\n readonly id: string;\n } | null;\n }) => page.nextCursor,\n refetchOnWindowFocus: false,\n staleTime: 0,\n trpc: { abortOnUnmount: true },\n }\n )\n );\n const isSearch = Boolean(query.trim());\n const active = isSearch ? results : history;\n const changingQuery = query.trim() !== search;\n const waiting =\n changingQuery ||\n active.isPending ||\n (active.isFetching && !active.isFetchingNextPage);\n const failed = !changingQuery && active.isError;\n const recentItems =\n history.data?.pages\n .flatMap(\n (\n page: ReadonlyNativeSurface<\n NonNullable<typeof history.data>[\"pages\"][number]\n >\n ) => page.items\n )\n .filter(\n (item: {\n readonly state: \"creating\" | \"bound\" | \"uncertain\" | \"deleting\";\n }) => item.state === \"bound\"\n )\n .map(\n (\n item: ReadonlyNativeSurface<\n NonNullable<typeof history.data>[\"pages\"][number][\"items\"][number]\n >\n ) => ({\n ...item,\n
|
|
59
|
+
"content": "\"use client\";\n\nimport { hasText } from \"@/components/text-value\";\n\nimport { useInfiniteQuery, useQueryClient } from \"@tanstack/react-query\";\nimport { SearchIcon } from \"lucide-react\";\nimport { useRouter } from \"next/navigation\";\nimport React, { useEffect, useState, useSyncExternalStore } from \"react\";\nimport type { JSX as ReactJSX } from \"react\";\n\nimport {\n DialogContent,\n DialogDescription,\n DialogHeader,\n DialogTitle,\n} from \"@/components/ui/dialog\";\nimport { useSidebar } from \"@/components/ui/sidebar\";\nimport { SearchSurface } from \"./search-surface\";\nimport type { ReadonlyNativeSurface } from \"@/lib/readonly-native-surface\";\nimport { useTRPC } from \"@/trpc/react\";\n\nimport { EveSearchResultsView } from \"./search-results-view\";\nimport { useDebouncedSearch } from \"./use-debounced-search\";\n\nconst SearchResults = ({\n onSelect,\n onClose,\n ownerId,\n}: {\n readonly onSelect: (id: string) => void;\n readonly onClose: () => void;\n readonly ownerId: string;\n}): ReactJSX.Element => {\n const trpc = useTRPC();\n const queryClient = useQueryClient();\n const [query, setQuery] = useState(\"\");\n const search = useDebouncedSearch(query);\n const history = useInfiniteQuery(\n trpc.eve.list.infiniteQueryOptions(\n { ownerScope: ownerId },\n {\n enabled: !query.trim(),\n getNextPageParam: (page: {\n readonly nextCursor: {\n readonly isPinned: boolean;\n readonly updatedAt: string;\n readonly id: string;\n } | null;\n }) => page.nextCursor,\n refetchOnWindowFocus: false,\n staleTime: 0,\n }\n )\n );\n const results = useInfiniteQuery(\n trpc.search.query.infiniteQueryOptions(\n { ownerScope: ownerId, search },\n {\n enabled: Boolean(search) && search === query.trim(),\n getNextPageParam: (page: {\n readonly nextCursor: {\n readonly rank: number;\n readonly updatedAt: string;\n readonly id: string;\n } | null;\n }) => page.nextCursor,\n refetchOnWindowFocus: false,\n staleTime: 0,\n trpc: { abortOnUnmount: true },\n }\n )\n );\n const isSearch = Boolean(query.trim());\n const active = isSearch ? results : history;\n const changingQuery = query.trim() !== search;\n const waiting =\n changingQuery ||\n active.isPending ||\n (active.isFetching && !active.isFetchingNextPage);\n const failed = !changingQuery && active.isError;\n const recentItems =\n history.data?.pages\n .flatMap(\n (\n page: ReadonlyNativeSurface<\n NonNullable<typeof history.data>[\"pages\"][number]\n >\n ) => page.items\n )\n .filter(\n (item: {\n readonly state: \"creating\" | \"bound\" | \"uncertain\" | \"deleting\";\n }) => item.state === \"bound\"\n )\n .map(\n (\n item: ReadonlyNativeSurface<\n NonNullable<typeof history.data>[\"pages\"][number][\"items\"][number]\n >\n ) => ({\n ...item,\n branchId: item.branchId ?? item.id,\n excerpt: \"\",\n })\n ) ?? [];\n const matchedItems =\n results.data?.pages.flatMap(\n (\n page: ReadonlyNativeSurface<\n NonNullable<typeof results.data>[\"pages\"][number]\n >\n ) => page.items\n ) ?? [];\n const currentItems = isSearch ? matchedItems : recentItems;\n const items = waiting || failed ? [] : currentItems;\n const seen = new Set<string>();\n const distinct = items.filter((item: { readonly id: string }) => {\n if (seen.has(item.id)) {\n return false;\n }\n seen.add(item.id);\n return true;\n });\n return (\n <EveSearchResultsView\n onClose={onClose}\n query={query}\n onQueryChange={(value) => {\n if (value.trim() !== query.trim()) {\n // Cancel immediately, not after the debounce: an old response must\n // never publish while the user is already typing a different query.\n void queryClient.cancelQueries({\n exact: true,\n queryKey: trpc.search.query.infiniteQueryKey({\n ownerScope: ownerId,\n search,\n }),\n });\n }\n setQuery(value);\n }}\n searching={waiting}\n pending={waiting && !failed}\n error={failed}\n items={distinct}\n isSearch={isSearch}\n onSelect={onSelect}\n\n onRetry={() => {\n void active.refetch();\n }}\n hasMore={!waiting && !failed && active.hasNextPage}\n loadingMore={active.isFetchingNextPage}\n\n onLoadMore={() => {\n void active.fetchNextPage();\n }}\n disableLoadMore={active.isFetching || changingQuery}\n />\n );\n};\n\nconst searchShortcut = () => {\n if (navigator.platform.toUpperCase().includes(\"MAC\")) {\n return \"Cmd+K\";\n }\n return \"Ctrl+K\";\n};\n\nconst unsubscribePlatform = (): null => null;\nconst subscribePlatform = () => unsubscribePlatform;\n\nconst serverShortcut = (): string => \"Ctrl+K\";\n\nexport const EveSearchChats = ({\n ownerId,\n onChatSelect,\n}: {\n readonly ownerId?: string;\n readonly onChatSelect?: (id: string) => void;\n}): ReactJSX.Element => {\n const shortcut = useSyncExternalStore(\n subscribePlatform,\n searchShortcut,\n serverShortcut\n );\n const [open, setOpen] = useState(false);\n const router = useRouter();\n const { setOpenMobile } = useSidebar();\n useEffect(() => {\n const down = (\n event: Readonly<\n Pick<KeyboardEvent, \"key\" | \"metaKey\" | \"ctrlKey\" | \"preventDefault\">\n >\n ): void => {\n if (event.key.toLowerCase() === \"k\" && (event.metaKey || event.ctrlKey)) {\n event.preventDefault();\n setOpen((value) => !value);\n }\n };\n document.addEventListener(\"keydown\", down, true);\n return (): void => {\n document.removeEventListener(\"keydown\", down, true);\n };\n }, []);\n return (\n <SearchSurface\n open={open}\n onOpenChange={setOpen}\n trigger={\n <>\n <SearchIcon className=\"size-4\" />\n <span>Search chats</span>\n <span className=\"text-muted-foreground ml-auto text-xs\">\n {shortcut}\n </span>\n </>\n }\n >\n <DialogContent\n className=\"overflow-hidden p-0 max-md:z-[51]\"\n showCloseButton={!hasText(ownerId)}\n >\n <DialogHeader className=\"sr-only\">\n <DialogTitle>Search chats</DialogTitle>\n <DialogDescription>\n Search your conversation history.\n </DialogDescription>\n </DialogHeader>\n {open && !hasText(ownerId) && (\n <p className=\"text-muted-foreground p-4 text-sm\">\n Start a chat to see your conversation history.\n </p>\n )}\n {open && hasText(ownerId) && (\n <SearchResults\n key={ownerId}\n ownerId={ownerId}\n onClose={() => {\n setOpen(false);\n }}\n onSelect={(id) => {\n setOpen(false);\n setOpenMobile(false);\n if (onChatSelect) {\n onChatSelect(id);\n } else {\n router.push(`/chat/${id}`);\n }\n }}\n />\n )}\n </DialogContent>\n </SearchSurface>\n );\n};\n",
|
|
60
60
|
"type": "registry:file",
|
|
61
61
|
"target": "~/chatjs/plugins/search/search-chats.tsx"
|
|
62
62
|
},
|
|
@@ -74,25 +74,25 @@
|
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
76
|
"path": "src/plugins/search/src/search-hook.ts",
|
|
77
|
-
"content": "import { isAccountSession } from \"@/lib/eve/session-identity\";\nimport type { EveSearchText } from \"./search-text\";\nimport type { HookContext } from \"eve/hooks\";\nimport { defineHook } from \"eve/hooks\";\nimport { defineState } from \"eve/context\";\n\nimport { indexEveSearchText } from \"./search-queries\";\nimport { resolveEveConversationScope } from \"@/lib/eve/conversation-scope\";\nimport { backfillEveSearchConversation } from \"./search-backfill\";\nimport { eveEventSearchText } from \"./search-text\";\n\nconst maxPendingEntries = 256;\nconst maxPendingCharacters = 256_000;\n\nconst needsRecovery = defineState(\"chatjs.search-recovery\", () => false);\nconst pending = defineState<EveSearchText[]>(\"chatjs.search-prefix\", () => []);\n\nexport default defineHook({\n events: {\n \"*\": async (\n event: Parameters<typeof eveEventSearchText>[0],\n context: Readonly<{\n session: Readonly<\n Pick<HookContext[\"session\"], \"id\" | \"auth\" | \"parent\">\n >;\n }>\n ) => {\n if (!isAccountSession(context.session)) {\n return;\n }\n if (context.session.parent) {\n return;\n }\n const entries = eveEventSearchText(event);\n if (\n entries.length === 0 &&\n event.type !== \"turn.started\" &&\n event.type !== \"turn.settled\"\n ) {\n return;\n }\n let omitted = 0;\n pending.update((current: readonly EveSearchText[]) => {\n const retained: EveSearchText[] = [];\n const keys = new Set<string>();\n let characters = 0;\n for (const batch of [current, entries]) {\n for (const entry of batch) {\n if (keys.has(entry.key)) {\n continue;\n }\n if (\n retained.length >= maxPendingEntries ||\n characters + entry.text.length > maxPendingCharacters\n ) {\n omitted += 1;\n continue;\n }\n keys.add(entry.key);\n retained.push(entry);\n characters += entry.text.length;\n }\n }\n return retained;\n });\n if (omitted) {\n needsRecovery.update(() => true);\n // Recover from durable EVE events after binding; manual backfill is a fallback.\n console.error(\n \"Search retry buffer overflow; automatic snapshot recovery queued. Run chatjs/plugins/search/backfill.ts if retries keep failing.\",\n {\n omitted,\n sessionId: context.session.id,\n }\n );\n }\n if (pending.get().length === 0 && !needsRecovery.get()) {\n return;\n }\n try {\n const scope = await resolveEveConversationScope(\n context.session.auth.initiator?.principalId,\n context.session.id,\n AbortSignal.timeout(10_000),\n context.session.auth.initiator?.attributes.chatjsReservationId\n );\n if (needsRecovery.get()) {\n // Hook events are already durable, so the snapshot includes the current\n // message as well as any restored history omitted from the retry buffer.\n await backfillEveSearchConversation(\n scope.ownerId,\n scope.
|
|
77
|
+
"content": "import { isAccountSession } from \"@/lib/eve/session-identity\";\nimport type { EveSearchText } from \"./search-text\";\nimport type { HookContext } from \"eve/hooks\";\nimport { defineHook } from \"eve/hooks\";\nimport { defineState } from \"eve/context\";\n\nimport { indexEveSearchText } from \"./search-queries\";\nimport { resolveEveConversationScope } from \"@/lib/eve/conversation-scope\";\nimport { backfillEveSearchConversation } from \"./search-backfill\";\nimport { eveEventSearchText } from \"./search-text\";\n\nconst maxPendingEntries = 256;\nconst maxPendingCharacters = 256_000;\n\nconst needsRecovery = defineState(\"chatjs.search-recovery\", () => false);\nconst pending = defineState<EveSearchText[]>(\"chatjs.search-prefix\", () => []);\n\nexport default defineHook({\n events: {\n \"*\": async (\n event: Parameters<typeof eveEventSearchText>[0],\n context: Readonly<{\n session: Readonly<\n Pick<HookContext[\"session\"], \"id\" | \"auth\" | \"parent\">\n >;\n }>\n ) => {\n if (!isAccountSession(context.session)) {\n return;\n }\n if (context.session.parent) {\n return;\n }\n const entries = eveEventSearchText(event);\n if (\n entries.length === 0 &&\n event.type !== \"turn.started\" &&\n event.type !== \"turn.settled\"\n ) {\n return;\n }\n let omitted = 0;\n pending.update((current: readonly EveSearchText[]) => {\n const retained: EveSearchText[] = [];\n const keys = new Set<string>();\n let characters = 0;\n for (const batch of [current, entries]) {\n for (const entry of batch) {\n if (keys.has(entry.key)) {\n continue;\n }\n if (\n retained.length >= maxPendingEntries ||\n characters + entry.text.length > maxPendingCharacters\n ) {\n omitted += 1;\n continue;\n }\n keys.add(entry.key);\n retained.push(entry);\n characters += entry.text.length;\n }\n }\n return retained;\n });\n if (omitted) {\n needsRecovery.update(() => true);\n // Recover from durable EVE events after binding; manual backfill is a fallback.\n console.error(\n \"Search retry buffer overflow; automatic snapshot recovery queued. Run chatjs/plugins/search/backfill.ts if retries keep failing.\",\n {\n omitted,\n sessionId: context.session.id,\n }\n );\n }\n if (pending.get().length === 0 && !needsRecovery.get()) {\n return;\n }\n try {\n const scope = await resolveEveConversationScope(\n context.session.auth.initiator?.principalId,\n context.session.id,\n AbortSignal.timeout(10_000),\n context.session.auth.initiator?.attributes.chatjsReservationId\n );\n if (needsRecovery.get()) {\n // Hook events are already durable, so the snapshot includes the current\n // message as well as any restored history omitted from the retry buffer.\n await backfillEveSearchConversation(\n scope.ownerId,\n scope.branchId,\n context.session.id\n );\n needsRecovery.update(() => false);\n } else {\n await indexEveSearchText(\n scope.ownerId,\n scope.branchId,\n pending.get()\n );\n }\n pending.update(() => []);\n } catch (error) {\n // Projection failures must not turn a successful chat into turn.failed.\n // Keep the pending text for the next message or turn; backfill also repairs it.\n console.error(\n \"Search indexing failed; will retry on the next chat event.\",\n {\n name: error instanceof Error ? error.name : \"UnknownError\",\n stack:\n error instanceof Error\n ? error.stack?.split(\"\\n\").slice(1).join(\"\\n\")\n : undefined,\n }\n );\n }\n },\n },\n});\n",
|
|
78
78
|
"type": "registry:file",
|
|
79
79
|
"target": "~/chatjs/plugins/search/search-hook.ts"
|
|
80
80
|
},
|
|
81
81
|
{
|
|
82
82
|
"path": "src/plugins/search/src/search-queries.ts",
|
|
83
|
-
"content": "import { isNonEmptyString } from \"@/lib/is-non-empty-string\";\n\nimport { and, eq, sql } from \"drizzle-orm\";\nimport { z } from \"zod\";\n\nimport type { EveSearchText } from \"@/chatjs/plugins/search/search-text\";\nimport { MAX_SEARCH_QUERY_LENGTH } from \"@/chatjs/plugins/search/search-text\";\nimport type { ReadonlyNativeSurface } from \"@/lib/readonly-native-surface\";\n\nimport { db } from \"@/lib/db/client\";\nimport { eveConversation } from \"@/lib/db/schema\";\nimport { eveSearchText } from \"./search-schema\";\n\nconst SEARCH_CHUNK_LENGTH = 8000;\nconst SEARCH_WRITE_BATCH_SIZE = 100;\nconst SEARCH_PAGE_SIZE = 20;\nconst QUOTE_PAIR_SIZE = 2;\nconst UNQUOTED_SEGMENT_REMAINDER = 1;\nconst FIRST_INDEX = 0;\nconst LAST_ITEM_OFFSET = -1;\nconst EMPTY_RESULT_COUNT = 0;\n\ntype SearchTransaction = Readonly<Pick<typeof db, \"select\" | \"insert\">>;\nconst splitSearchChunks = (\n entries: readonly EveSearchText[]\n): EveSearchText[] =>\n entries.flatMap((entry: EveSearchText) => {\n const result: EveSearchText[] = [];\n for (\n let offset = FIRST_INDEX;\n offset < entry.text.length;\n offset += SEARCH_CHUNK_LENGTH\n ) {\n result.push({\n key: `${entry.key}:${offset}`,\n text: entry.text.slice(\n offset,\n offset + SEARCH_CHUNK_LENGTH + MAX_SEARCH_QUERY_LENGTH\n ),\n });\n }\n return result;\n });\n\n/**\n * Writes search chunks only while the owner’s conversation binding is active.\n * The binding lock serializes the write with deletion, and existing keys are\n * updated when their indexed text changes.\n * @param {SearchTransaction} tx Transaction shared with the caller’s conversation update.\n * @param {string} ownerId Owner whose active conversation is being indexed.\n * @param {string} conversationId Bound conversation that owns the chunks.\n * @param {readonly EveSearchText[]} entries Search keys and text chunks to persist.\n */\nconst writeEveSearchText = async (\n tx: SearchTransaction,\n ownerId: string,\n conversationId: string,\n entries: readonly EveSearchText[]\n): Promise<void> => {\n const [conversation] = await tx\n .select({ id: eveConversation.id })\n .from(eveConversation)\n .where(\n and(\n eq(eveConversation.id, conversationId),\n eq(eveConversation.ownerId, ownerId),\n eq(eveConversation.state, \"bound\")\n )\n )\n .for(\"update\");\n const hasConversation = Boolean(conversation);\n if (!hasConversation) {\n return;\n }\n // Bound vectors and insert batches even for unusually large pasted messages.\n const chunks = splitSearchChunks(entries);\n for (\n let index = FIRST_INDEX;\n index < chunks.length;\n index += SEARCH_WRITE_BATCH_SIZE\n ) {\n // oxlint-disable-next-line eslint/no-await-in-loop -- Insert at most SEARCH_WRITE_BATCH_SIZE rows per query on the locked transaction; search-backfill awaits each committed batch before advancing.\n await tx\n .insert(eveSearchText)\n .values(\n chunks\n .slice(index, index + SEARCH_WRITE_BATCH_SIZE)\n .map((entry: EveSearchText) => ({\n ...entry,\n conversationId,\n ownerId,\n }))\n )\n .onConflictDoUpdate({\n set: { text: sql`excluded.text` },\n setWhere: sql`${eveSearchText.text} is distinct from excluded.text`,\n target: [eveSearchText.conversationId, eveSearchText.key],\n });\n }\n};\n\nconst indexEveSearchText = async (\n ownerId: string,\n conversationId: string,\n entries: readonly EveSearchText[]\n): Promise<void> => {\n if (entries.length > EMPTY_RESULT_COUNT) {\n await db.transaction(async (tx: SearchTransaction) => {\n await writeEveSearchText(tx, ownerId, conversationId, entries);\n });\n }\n};\n\nconst eveSearchResult = z.object({\n id: z.string(),\n conversationId: z.string(),\n title: z.string(),\n excerpt: z.string(),\n updatedAt: z.string(),\n rank: z.number(),\n highlightQuery: z.string(),\n highlightWords: z.record(z.string(), z.string()),\n});\ntype EveSearchResult = z.infer<typeof eveSearchResult>;\n\n// Modify only PostgreSQL's normalized final positive operand, never raw query syntax.\n// The leading boundary excludes !'negated' terms; closing groups remain intact.\nconst finalSearchOperand = \"(^|[ (|&])('[^']*(?:''[^']*)*')([)]*)$\";\nconst finalUnquotedWord = /[\\p{L}\\p{N}]$/u;\n\n// Read PostgreSQL's normalized operands so highlighting shares its tokenization,\n// quoting and prefix rules instead of interpreting the user's query again.\nconst queryToken = /!|[()]|'(?<term>(?:[^'\\\\]|\\\\.|'')*)'(?<prefix>:\\*)?/gu;\nconst escapedQueryCharacter = /\\\\(?<character>.)/gu;\nconst markedWord = /⟦(?<word>[^⟧]*)⟧/gu;\n\nconst highlightSearchExcerpt = (\n excerpt: string,\n query: string,\n words: Readonly<Record<string, string>>\n): string => {\n const terms: { prefix: boolean; text: string }[] = [];\n const groups = [false];\n let negateNext = false;\n for (const token of query.matchAll(queryToken)) {\n const negated = (groups.at(LAST_ITEM_OFFSET) ?? false) !== negateNext;\n if (token[FIRST_INDEX] === \"!\") {\n negateNext = !negateNext;\n continue;\n }\n if (token[FIRST_INDEX] === \"(\") {\n groups.push(negated);\n } else if (token[FIRST_INDEX] === \")\") {\n groups.pop();\n } else if (!negated && isNonEmptyString(token.groups?.term)) {\n terms.push({\n prefix: Boolean(token.groups.prefix),\n text: token.groups.term\n .replace(escapedQueryCharacter, \"$1\")\n .replaceAll(\"''\", \"'\"),\n });\n }\n negateNext = false;\n }\n return excerpt.replace(markedWord, (marked, word: string) => {\n const normalized = words[word] ?? word;\n const lengths = terms\n .filter(\n ({ prefix, text }: Readonly<{ prefix: boolean; text: string }>) => {\n if (prefix) {\n return normalized.startsWith(text);\n }\n return normalized === text;\n }\n )\n .map(\n ({ text }: Readonly<{ prefix: boolean; text: string }>) => text.length\n );\n const length = Math.max(EMPTY_RESULT_COUNT, ...lengths);\n\n if (length) {\n return `⟦${word.slice(FIRST_INDEX, length)}⟧${word.slice(length)}`;\n }\n return marked;\n });\n};\n\n/**\n * Searches an owner’s bound conversations and returns one ranked result per chat.\n * The cursor continues after a result using rank, update time, and chat ID.\n * @param {string} ownerId Owner whose private conversation and search text rows are queried.\n * @param {{ search: string; cursor?: { rank: number; updatedAt: string; id: string } | null }} input Search text and optional continuation cursor.\n * @returns {Promise<{ items: Array<Omit<EveSearchResult, \"highlightQuery\" | \"highlightWords\">>; nextCursor: { id: string; rank: number; updatedAt: string } | null }>} A page of highlighted chat results and a cursor when more results exist.\n */\nconst searchEveConversations = async (\n ownerId: string,\n input: {\n readonly search: string;\n readonly cursor?: {\n readonly rank: number;\n readonly updatedAt: string;\n readonly id: string;\n } | null;\n }\n): Promise<{\n items: Omit<EveSearchResult, \"highlightQuery\" | \"highlightWords\">[];\n nextCursor: { id: string; rank: number; updatedAt: string } | null;\n}> => {\n const { cursor } = input;\n const query = input.search.trim();\n const prefixLastWord =\n finalUnquotedWord.test(query) &&\n query.split('\"').length % QUOTE_PAIR_SIZE === UNQUOTED_SEGMENT_REMAINDER;\n const rows = await db.execute(sql`\n with parsed as (select websearch_to_tsquery('simple', ${query}) as terms),\n query as (\n select case when ${prefixLastWord}\n then to_tsquery('simple', regexp_replace(terms::text, ${finalSearchOperand}, ${String.raw`\\1\\2:*\\3`}))\n else terms end as terms\n from parsed\n ),\n matches as (\n select chat.id, branch.id as \"conversationId\", chat.title, chat.\"updatedAt\",\n 2 + ts_rank_cd(to_tsvector('simple', chat.title), query.terms) as rank,\n ''::text as body\n from \"EveChat\" chat cross join query\n join lateral (\n select id from \"EveConversation\"\n where \"chatId\" = chat.id and \"ownerId\" = ${ownerId} and state = 'bound'\n order by (id = chat.\"activeConversationId\") desc, \"createdAt\", id limit 1\n ) branch on true\n where chat.\"ownerId\" = ${ownerId} and to_tsvector('simple', chat.title) @@ query.terms\n union all\n select chat.id, branch.id, chat.title, chat.\"updatedAt\",\n ts_rank_cd(to_tsvector('simple', content.text), query.terms) as rank,\n content.text as body\n from \"EveSearchText\" content cross join query\n join \"EveConversation\" branch on branch.id = content.\"conversationId\" and branch.\"ownerId\" = ${ownerId} and branch.state = 'bound'\n join \"EveChat\" chat on chat.id = branch.\"chatId\" and chat.\"ownerId\" = ${ownerId}\n where content.\"ownerId\" = ${ownerId} and to_tsvector('simple', content.text) @@ query.terms\n ), best as (\n select distinct on (id) *, max(rank) over (partition by id) as \"chatRank\"\n from matches\n order by id, (body <> '') desc, rank desc, \"conversationId\", body\n ), headlines as (\n select id, \"conversationId\", title, query.terms::text as \"highlightQuery\",\n to_char(\"updatedAt\", 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') as \"updatedAt\",\n \"chatRank\"::double precision as rank,\n case when body = '' then '' else ts_headline('simple', body, query.terms,\n 'StartSel=⟦, StopSel=⟧, MaxWords=32, MinWords=12, MaxFragments=1') end as excerpt\n from best cross join query\n where ${\n cursor\n ? sql`\n \"chatRank\" < ${cursor.rank}::double precision\n or (\"chatRank\" = ${cursor.rank}::double precision and \"updatedAt\" < ${cursor.updatedAt}::timestamp)\n or (\"chatRank\" = ${cursor.rank}::double precision and \"updatedAt\" = ${cursor.updatedAt}::timestamp and id > ${cursor.id})\n `\n : sql`true`\n }\n order by \"chatRank\" desc, best.\"updatedAt\" desc, id\n limit 21\n )\n -- Use the same dictionary as the search vector, including its locale rules.\n select headlines.*, (\n select coalesce(jsonb_object_agg(word[1], (ts_lexize('simple', word[1]))[1]), '{}'::jsonb)\n from regexp_matches(excerpt, '⟦([^⟧]*)⟧', 'g') as word\n ) as \"highlightWords\"\n from headlines\n order by rank desc, \"updatedAt\" desc, id\n `);\n const items = z.array(eveSearchResult).parse(rows);\n const page = items\n .slice(FIRST_INDEX, SEARCH_PAGE_SIZE)\n .map(\n ({\n highlightQuery,\n highlightWords,\n ...item\n }: ReadonlyNativeSurface<EveSearchResult>) => ({\n ...item,\n excerpt: highlightSearchExcerpt(\n item.excerpt,\n highlightQuery,\n highlightWords\n ),\n })\n );\n const last = page.at(LAST_ITEM_OFFSET);\n return {\n items: page,\n nextCursor:\n items.length > SEARCH_PAGE_SIZE && last\n ? { id: last.id, rank: last.rank, updatedAt: last.updatedAt }\n : null,\n };\n};\nexport { indexEveSearchText, searchEveConversations, writeEveSearchText };\n",
|
|
83
|
+
"content": "import { isNonEmptyString } from \"@/lib/is-non-empty-string\";\n\nimport { and, eq, sql } from \"drizzle-orm\";\nimport { z } from \"zod\";\n\nimport type { EveSearchText } from \"@/chatjs/plugins/search/search-text\";\nimport { MAX_SEARCH_QUERY_LENGTH } from \"@/chatjs/plugins/search/search-text\";\nimport type { ReadonlyNativeSurface } from \"@/lib/readonly-native-surface\";\n\nimport { db } from \"@/lib/db/client\";\nimport { eveConversation } from \"@/lib/db/schema\";\nimport { eveSearchText } from \"./search-schema\";\n\nconst SEARCH_CHUNK_LENGTH = 8000;\nconst SEARCH_WRITE_BATCH_SIZE = 100;\nconst SEARCH_PAGE_SIZE = 20;\nconst QUOTE_PAIR_SIZE = 2;\nconst UNQUOTED_SEGMENT_REMAINDER = 1;\nconst FIRST_INDEX = 0;\nconst LAST_ITEM_OFFSET = -1;\nconst EMPTY_RESULT_COUNT = 0;\n\ntype SearchTransaction = Readonly<Pick<typeof db, \"select\" | \"insert\">>;\nconst splitSearchChunks = (\n entries: readonly EveSearchText[]\n): EveSearchText[] =>\n entries.flatMap((entry: EveSearchText) => {\n const result: EveSearchText[] = [];\n for (\n let offset = FIRST_INDEX;\n offset < entry.text.length;\n offset += SEARCH_CHUNK_LENGTH\n ) {\n result.push({\n key: `${entry.key}:${offset}`,\n text: entry.text.slice(\n offset,\n offset + SEARCH_CHUNK_LENGTH + MAX_SEARCH_QUERY_LENGTH\n ),\n });\n }\n return result;\n });\n\n/**\n * Writes search chunks only while the owner’s conversation binding is active.\n * The binding lock serializes the write with deletion, and existing keys are\n * updated when their indexed text changes.\n * @param {SearchTransaction} tx Transaction shared with the caller’s conversation update.\n * @param {string} ownerId Owner whose active conversation is being indexed.\n * @param {string} branchId Bound conversation that owns the chunks.\n * @param {readonly EveSearchText[]} entries Search keys and text chunks to persist.\n */\nconst writeEveSearchText = async (\n tx: SearchTransaction,\n ownerId: string,\n branchId: string,\n entries: readonly EveSearchText[]\n): Promise<void> => {\n const [conversation] = await tx\n .select({ id: eveConversation.id })\n .from(eveConversation)\n .where(\n and(\n eq(eveConversation.id, branchId),\n eq(eveConversation.ownerId, ownerId),\n eq(eveConversation.state, \"bound\")\n )\n )\n .for(\"update\");\n const hasConversation = Boolean(conversation);\n if (!hasConversation) {\n return;\n }\n // Bound vectors and insert batches even for unusually large pasted messages.\n const chunks = splitSearchChunks(entries);\n for (\n let index = FIRST_INDEX;\n index < chunks.length;\n index += SEARCH_WRITE_BATCH_SIZE\n ) {\n // oxlint-disable-next-line eslint/no-await-in-loop -- Insert at most SEARCH_WRITE_BATCH_SIZE rows per query on the locked transaction; search-backfill awaits each committed batch before advancing.\n await tx\n .insert(eveSearchText)\n .values(\n chunks\n .slice(index, index + SEARCH_WRITE_BATCH_SIZE)\n .map((entry: EveSearchText) => ({\n ...entry,\n branchId,\n ownerId,\n }))\n )\n .onConflictDoUpdate({\n set: { text: sql`excluded.text` },\n setWhere: sql`${eveSearchText.text} is distinct from excluded.text`,\n target: [eveSearchText.branchId, eveSearchText.key],\n });\n }\n};\n\nconst indexEveSearchText = async (\n ownerId: string,\n branchId: string,\n entries: readonly EveSearchText[]\n): Promise<void> => {\n if (entries.length > EMPTY_RESULT_COUNT) {\n await db.transaction(async (tx: SearchTransaction) => {\n await writeEveSearchText(tx, ownerId, branchId, entries);\n });\n }\n};\n\nconst eveSearchResult = z.object({\n id: z.string(),\n branchId: z.string(),\n title: z.string(),\n excerpt: z.string(),\n updatedAt: z.string(),\n rank: z.number(),\n highlightQuery: z.string(),\n highlightWords: z.record(z.string(), z.string()),\n});\ntype EveSearchResult = z.infer<typeof eveSearchResult>;\n\n// Modify only PostgreSQL's normalized final positive operand, never raw query syntax.\n// The leading boundary excludes !'negated' terms; closing groups remain intact.\nconst finalSearchOperand = \"(^|[ (|&])('[^']*(?:''[^']*)*')([)]*)$\";\nconst finalUnquotedWord = /[\\p{L}\\p{N}]$/u;\n\n// Read PostgreSQL's normalized operands so highlighting shares its tokenization,\n// quoting and prefix rules instead of interpreting the user's query again.\nconst queryToken = /!|[()]|'(?<term>(?:[^'\\\\]|\\\\.|'')*)'(?<prefix>:\\*)?/gu;\nconst escapedQueryCharacter = /\\\\(?<character>.)/gu;\nconst markedWord = /⟦(?<word>[^⟧]*)⟧/gu;\n\nconst highlightSearchExcerpt = (\n excerpt: string,\n query: string,\n words: Readonly<Record<string, string>>\n): string => {\n const terms: { prefix: boolean; text: string }[] = [];\n const groups = [false];\n let negateNext = false;\n for (const token of query.matchAll(queryToken)) {\n const negated = (groups.at(LAST_ITEM_OFFSET) ?? false) !== negateNext;\n if (token[FIRST_INDEX] === \"!\") {\n negateNext = !negateNext;\n continue;\n }\n if (token[FIRST_INDEX] === \"(\") {\n groups.push(negated);\n } else if (token[FIRST_INDEX] === \")\") {\n groups.pop();\n } else if (!negated && isNonEmptyString(token.groups?.term)) {\n terms.push({\n prefix: Boolean(token.groups.prefix),\n text: token.groups.term\n .replace(escapedQueryCharacter, \"$1\")\n .replaceAll(\"''\", \"'\"),\n });\n }\n negateNext = false;\n }\n return excerpt.replace(markedWord, (marked, word: string) => {\n const normalized = words[word] ?? word;\n const lengths = terms\n .filter(\n ({ prefix, text }: Readonly<{ prefix: boolean; text: string }>) => {\n if (prefix) {\n return normalized.startsWith(text);\n }\n return normalized === text;\n }\n )\n .map(\n ({ text }: Readonly<{ prefix: boolean; text: string }>) => text.length\n );\n const length = Math.max(EMPTY_RESULT_COUNT, ...lengths);\n\n if (length) {\n return `⟦${word.slice(FIRST_INDEX, length)}⟧${word.slice(length)}`;\n }\n return marked;\n });\n};\n\n/**\n * Searches an owner’s bound conversations and returns one ranked result per chat.\n * The cursor continues after a result using rank, update time, and chat ID.\n * @param {string} ownerId Owner whose private conversation and search text rows are queried.\n * @param {{ search: string; cursor?: { rank: number; updatedAt: string; id: string } | null }} input Search text and optional continuation cursor.\n * @returns {Promise<{ items: Array<Omit<EveSearchResult, \"highlightQuery\" | \"highlightWords\">>; nextCursor: { id: string; rank: number; updatedAt: string } | null }>} A page of highlighted chat results and a cursor when more results exist.\n */\nconst searchEveConversations = async (\n ownerId: string,\n input: {\n readonly search: string;\n readonly cursor?: {\n readonly rank: number;\n readonly updatedAt: string;\n readonly id: string;\n } | null;\n }\n): Promise<{\n items: Omit<EveSearchResult, \"highlightQuery\" | \"highlightWords\">[];\n nextCursor: { id: string; rank: number; updatedAt: string } | null;\n}> => {\n const { cursor } = input;\n const query = input.search.trim();\n const prefixLastWord =\n finalUnquotedWord.test(query) &&\n query.split('\"').length % QUOTE_PAIR_SIZE === UNQUOTED_SEGMENT_REMAINDER;\n const rows = await db.execute(sql`\n with parsed as (select websearch_to_tsquery('simple', ${query}) as terms),\n query as (\n select case when ${prefixLastWord}\n then to_tsquery('simple', regexp_replace(terms::text, ${finalSearchOperand}, ${String.raw`\\1\\2:*\\3`}))\n else terms end as terms\n from parsed\n ),\n matches as (\n select chat.id, branch.id as \"branchId\", chat.title, chat.\"updatedAt\",\n 2 + ts_rank_cd(to_tsvector('simple', chat.title), query.terms) as rank,\n ''::text as body\n from \"EveChat\" chat cross join query\n join lateral (\n select id from \"EveConversation\"\n where \"chatId\" = chat.id and \"ownerId\" = ${ownerId} and state = 'bound'\n order by (id = chat.\"activeBranchId\") desc, \"createdAt\", id limit 1\n ) branch on true\n where chat.\"ownerId\" = ${ownerId} and to_tsvector('simple', chat.title) @@ query.terms\n union all\n select chat.id, branch.id, chat.title, chat.\"updatedAt\",\n ts_rank_cd(to_tsvector('simple', content.text), query.terms) as rank,\n content.text as body\n from \"EveSearchText\" content cross join query\n join \"EveConversation\" branch on branch.id = content.\"branchId\" and branch.\"ownerId\" = ${ownerId} and branch.state = 'bound'\n join \"EveChat\" chat on chat.id = branch.\"chatId\" and chat.\"ownerId\" = ${ownerId}\n where content.\"ownerId\" = ${ownerId} and to_tsvector('simple', content.text) @@ query.terms\n ), best as (\n select distinct on (id) *, max(rank) over (partition by id) as \"chatRank\"\n from matches\n order by id, (body <> '') desc, rank desc, \"branchId\", body\n ), headlines as (\n select id, \"branchId\", title, query.terms::text as \"highlightQuery\",\n to_char(\"updatedAt\", 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') as \"updatedAt\",\n \"chatRank\"::double precision as rank,\n case when body = '' then '' else ts_headline('simple', body, query.terms,\n 'StartSel=⟦, StopSel=⟧, MaxWords=32, MinWords=12, MaxFragments=1') end as excerpt\n from best cross join query\n where ${\n cursor\n ? sql`\n \"chatRank\" < ${cursor.rank}::double precision\n or (\"chatRank\" = ${cursor.rank}::double precision and \"updatedAt\" < ${cursor.updatedAt}::timestamp)\n or (\"chatRank\" = ${cursor.rank}::double precision and \"updatedAt\" = ${cursor.updatedAt}::timestamp and id > ${cursor.id})\n `\n : sql`true`\n }\n order by \"chatRank\" desc, best.\"updatedAt\" desc, id\n limit 21\n )\n -- Use the same dictionary as the search vector, including its locale rules.\n select headlines.*, (\n select coalesce(jsonb_object_agg(word[1], (ts_lexize('simple', word[1]))[1]), '{}'::jsonb)\n from regexp_matches(excerpt, '⟦([^⟧]*)⟧', 'g') as word\n ) as \"highlightWords\"\n from headlines\n order by rank desc, \"updatedAt\" desc, id\n `);\n const items = z.array(eveSearchResult).parse(rows);\n const page = items\n .slice(FIRST_INDEX, SEARCH_PAGE_SIZE)\n .map(\n ({\n highlightQuery,\n highlightWords,\n ...item\n }: ReadonlyNativeSurface<EveSearchResult>) => ({\n ...item,\n excerpt: highlightSearchExcerpt(\n item.excerpt,\n highlightQuery,\n highlightWords\n ),\n })\n );\n const last = page.at(LAST_ITEM_OFFSET);\n return {\n items: page,\n nextCursor:\n items.length > SEARCH_PAGE_SIZE && last\n ? { id: last.id, rank: last.rank, updatedAt: last.updatedAt }\n : null,\n };\n};\nexport { indexEveSearchText, searchEveConversations, writeEveSearchText };\n",
|
|
84
84
|
"type": "registry:file",
|
|
85
85
|
"target": "~/chatjs/plugins/search/search-queries.ts"
|
|
86
86
|
},
|
|
87
87
|
{
|
|
88
88
|
"path": "src/plugins/search/src/search-results-view.tsx",
|
|
89
|
-
"content": "\"use client\";\n\nimport { LoaderCircle, MessageSquare, X } from \"lucide-react\";\nimport React, { useRef } from \"react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport {\n Command,\n CommandGroup,\n CommandInput,\n CommandItem,\n CommandList,\n} from \"@/components/ui/command\";\nimport { Alert, AlertAction, AlertDescription } from \"@/components/ui/alert\";\nimport { Empty, EmptyDescription } from \"@/components/ui/empty\";\nimport { Skeleton } from \"@/components/ui/skeleton\";\n\nconst highlightedExcerpt = (\n excerpt: string\n): (React.JSX.Element | string)[] => {\n let previousEnd = 0;\n const parts = [...excerpt.matchAll(/⟦[^⟧]*⟧/gu)].flatMap(\n (match: readonly string[] & Readonly<{ index: number }>) => {\n const start = match.index;\n const before = excerpt.slice(previousEnd, start);\n previousEnd = start + match[0].length;\n const mark = (\n <mark\n className=\"text-foreground bg-transparent font-medium\"\n key={start}\n >\n {match[0].slice(1, -1)}\n </mark>\n );\n if (before.length > 0) {\n return [before, mark];\n }\n return [mark];\n }\n );\n if (previousEnd < excerpt.length) {\n parts.push(excerpt.slice(previousEnd));\n }\n return parts;\n};\n\nexport const EveSearchResultsView = ({\n query,\n onQueryChange,\n onClose,\n searching,\n pending,\n error,\n items,\n isSearch,\n onSelect,\n onRetry,\n hasMore,\n loadingMore,\n onLoadMore,\n disableLoadMore,\n}: {\n readonly query: string;\n readonly onQueryChange: (query: string) => void;\n readonly onClose: () => void;\n readonly searching: boolean;\n readonly pending: boolean;\n readonly error: boolean;\n readonly items: readonly {\n readonly id: string;\n readonly
|
|
89
|
+
"content": "\"use client\";\n\nimport { LoaderCircle, MessageSquare, X } from \"lucide-react\";\nimport React, { useRef } from \"react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport {\n Command,\n CommandGroup,\n CommandInput,\n CommandItem,\n CommandList,\n} from \"@/components/ui/command\";\nimport { Alert, AlertAction, AlertDescription } from \"@/components/ui/alert\";\nimport { Empty, EmptyDescription } from \"@/components/ui/empty\";\nimport { Skeleton } from \"@/components/ui/skeleton\";\n\nconst highlightedExcerpt = (\n excerpt: string\n): (React.JSX.Element | string)[] => {\n let previousEnd = 0;\n const parts = [...excerpt.matchAll(/⟦[^⟧]*⟧/gu)].flatMap(\n (match: readonly string[] & Readonly<{ index: number }>) => {\n const start = match.index;\n const before = excerpt.slice(previousEnd, start);\n previousEnd = start + match[0].length;\n const mark = (\n <mark\n className=\"text-foreground bg-transparent font-medium\"\n key={start}\n >\n {match[0].slice(1, -1)}\n </mark>\n );\n if (before.length > 0) {\n return [before, mark];\n }\n return [mark];\n }\n );\n if (previousEnd < excerpt.length) {\n parts.push(excerpt.slice(previousEnd));\n }\n return parts;\n};\n\nexport const EveSearchResultsView = ({\n query,\n onQueryChange,\n onClose,\n searching,\n pending,\n error,\n items,\n isSearch,\n onSelect,\n onRetry,\n hasMore,\n loadingMore,\n onLoadMore,\n disableLoadMore,\n}: {\n readonly query: string;\n readonly onQueryChange: (query: string) => void;\n readonly onClose: () => void;\n readonly searching: boolean;\n readonly pending: boolean;\n readonly error: boolean;\n readonly items: readonly {\n readonly id: string;\n readonly branchId: string;\n readonly title: string;\n readonly excerpt: string;\n }[];\n readonly isSearch: boolean;\n readonly onSelect: (id: string) => void;\n readonly onRetry: () => void;\n readonly hasMore: boolean;\n readonly loadingMore: boolean;\n readonly onLoadMore: () => void;\n readonly disableLoadMore: boolean;\n}): React.JSX.Element => {\n const inputRef = useRef<HTMLInputElement>(null);\n return (\n <Command\n shouldFilter={false}\n className=\"**:data-[slot=command-input-wrapper]:h-12\"\n >\n <div className=\"flex items-center pe-2 *:data-[slot=command-input-wrapper]:min-w-0 *:data-[slot=command-input-wrapper]:flex-1\">\n <CommandInput\n ref={inputRef}\n aria-label=\"Search conversations\"\n className=\"min-w-0\"\n placeholder=\"Search titles and messages…\"\n value={query}\n onValueChange={onQueryChange}\n maxLength={255}\n />\n <div className=\"text-muted-foreground flex shrink-0 items-center gap-1\">\n {searching && (\n <LoaderCircle\n aria-hidden=\"true\"\n className=\"pointer-events-none mx-1 size-4 animate-spin\"\n />\n )}\n {query.length > 0 && (\n <>\n <Button\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => {\n onQueryChange(\"\");\n inputRef.current?.focus();\n }}\n >\n Clear\n </Button>\n <span aria-hidden=\"true\" className=\"bg-border mx-1 h-5 w-px\" />\n </>\n )}\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n aria-label=\"Close search\"\n onClick={onClose}\n >\n <X />\n </Button>\n </div>\n </div>\n <output className=\"sr-only\" aria-live=\"polite\">\n {searching ? \"Searching…\" : \"\"}\n </output>\n <CommandList\n className=\"h-[300px] max-h-[50dvh]\"\n aria-busy={searching || pending}\n >\n {pending && (\n <output aria-label=\"Loading chats\" className=\"block p-1\">\n <div aria-hidden=\"true\">\n <div className=\"flex h-8 items-center px-2\">\n <Skeleton className=\"bg-foreground/10 h-3 w-20\" />\n </div>\n {[\"w-40\", \"w-56\", \"w-32\", \"w-48\", \"w-36\", \"w-44\"].map(\n (width): React.JSX.Element => (\n <div\n className=\"flex h-11 items-center gap-3 px-2\"\n key={width}\n >\n <Skeleton className=\"bg-foreground/10 size-4 shrink-0\" />\n <Skeleton\n className={`bg-foreground/10 h-4 max-w-[75%] ${width}`}\n />\n </div>\n )\n )}\n </div>\n </output>\n )}\n {error && (\n <Alert variant=\"destructive\">\n <AlertDescription>Could not search chats.</AlertDescription>\n <AlertAction>\n <Button variant=\"ghost\" size=\"sm\" onClick={onRetry}>\n Retry\n </Button>\n </AlertAction>\n </Alert>\n )}\n {!pending && !error && !searching && items.length === 0 && (\n <Empty className=\"p-4\">\n <EmptyDescription>\n {isSearch\n ? \"No chats found. Try different words.\"\n : \"Your recent chats will appear here.\"}\n </EmptyDescription>\n </Empty>\n )}\n {items.length > 0 && (\n <CommandGroup heading={isSearch ? \"Best matches\" : \"Recent chats\"}>\n {items.map((item): React.JSX.Element => (\n <CommandItem\n className=\"cursor-pointer items-start gap-3 px-2 py-3\"\n key={item.id}\n value={item.id}\n onSelect={() => {\n onSelect(item.branchId);\n }}\n >\n <MessageSquare className=\"text-muted-foreground mt-0.5 size-4 shrink-0\" />\n <div className=\"flex min-w-0 flex-1 flex-col gap-1\">\n <span className=\"truncate font-medium\">{item.title}</span>\n {item.excerpt && (\n <span className=\"text-muted-foreground line-clamp-2 text-xs leading-relaxed\">\n {highlightedExcerpt(item.excerpt)}\n </span>\n )}\n </div>\n </CommandItem>\n ))}\n </CommandGroup>\n )}\n {hasMore && (\n <Button\n variant=\"ghost\"\n disabled={disableLoadMore}\n onClick={onLoadMore}\n >\n {loadingMore ? \"Loading…\" : \"Load more chats\"}\n </Button>\n )}\n </CommandList>\n </Command>\n );\n};\n",
|
|
90
90
|
"type": "registry:file",
|
|
91
91
|
"target": "~/chatjs/plugins/search/search-results-view.tsx"
|
|
92
92
|
},
|
|
93
93
|
{
|
|
94
94
|
"path": "src/plugins/search/src/search-schema.ts",
|
|
95
|
-
"content": "import { sql } from \"drizzle-orm\";\nimport {\n foreignKey,\n index,\n pgTable,\n primaryKey,\n text,\n uuid,\n} from \"drizzle-orm/pg-core\";\nimport { eveConversation } from \"@/lib/db/schema\";\n\n/** Rebuildable display-text projection; EVE remains the transcript source of truth. */\nexport const eveSearchText = pgTable(\n \"EveSearchText\",\n {\n
|
|
95
|
+
"content": "import { sql } from \"drizzle-orm\";\nimport {\n foreignKey,\n index,\n pgTable,\n primaryKey,\n text,\n uuid,\n} from \"drizzle-orm/pg-core\";\nimport { eveConversation } from \"@/lib/db/schema\";\n\n/** Rebuildable display-text projection; EVE remains the transcript source of truth. */\nexport const eveSearchText = pgTable(\n \"EveSearchText\",\n {\n branchId: uuid(\"branchId\").notNull(),\n key: text(\"key\").notNull(),\n ownerId: text(\"ownerId\").notNull(),\n text: text(\"text\").notNull(),\n },\n (table) => [\n primaryKey({ columns: [table.branchId, table.key] }),\n foreignKey({\n columns: [table.branchId, table.ownerId],\n foreignColumns: [eveConversation.id, eveConversation.ownerId],\n }).onDelete(\"cascade\"),\n index(\"EveSearchText_owner\").on(table.ownerId),\n index(\"EveSearchText_content\").using(\n \"gin\",\n sql`to_tsvector('simple', ${table.text})`\n ),\n ]\n);\n",
|
|
96
96
|
"type": "registry:file",
|
|
97
97
|
"target": "~/chatjs/plugins/search/search-schema.ts"
|
|
98
98
|
},
|
|
@@ -102,12 +102,6 @@
|
|
|
102
102
|
"type": "registry:file",
|
|
103
103
|
"target": "~/chatjs/plugins/search/search-text.ts"
|
|
104
104
|
},
|
|
105
|
-
{
|
|
106
|
-
"path": "src/plugins/search/src/server-plugin.ts",
|
|
107
|
-
"content": "import type { ChatPlugin } from \"@/chatjs/core/installation/plugin\";\nimport { searchRouter } from \"./router\";\n\nexport const search = () =>\n ({ id: \"search\", routers: { search: searchRouter } }) satisfies ChatPlugin;\n",
|
|
108
|
-
"type": "registry:file",
|
|
109
|
-
"target": "~/chatjs/plugins/search/server-plugin.ts"
|
|
110
|
-
},
|
|
111
105
|
{
|
|
112
106
|
"path": "src/plugins/search/src/use-debounced-search.ts",
|
|
113
107
|
"content": "\"use client\";\n\nimport { useEffect, useState } from \"react\";\n// Typing coalesces requests; clearing remains a cancellable asynchronous update.\nconst typingDebounceDelayMs = 250;\nconst clearedSearchDelayMs = 0;\n\nexport const useDebouncedSearch = (value: string): string => {\n const normalized = value.trim();\n const [search, setSearch] = useState(normalized);\n useEffect(() => {\n const timeout = setTimeout(\n () => {\n setSearch(normalized);\n },\n normalized ? typingDebounceDelayMs : clearedSearchDelayMs\n );\n return (): void => {\n clearTimeout(timeout);\n };\n }, [normalized]);\n return search;\n};\n",
|
|
@@ -116,25 +110,27 @@
|
|
|
116
110
|
},
|
|
117
111
|
{
|
|
118
112
|
"path": "src/plugins/search/adapters/agent/hooks/search.ts",
|
|
119
|
-
"content": "// ChatJS source: search. Ownership: chatjs/plugins/search/
|
|
113
|
+
"content": "// ChatJS source: search. Ownership: chatjs/plugins/search/plugin.json.\nexport { default } from \"@/chatjs/plugins/search/search-hook\";\n",
|
|
120
114
|
"type": "registry:file",
|
|
121
115
|
"target": "~/agent/hooks/search.ts"
|
|
122
116
|
},
|
|
123
117
|
{
|
|
124
118
|
"path": "dist/source/search.json",
|
|
125
|
-
"content": "{\n \"id\": \"search\",\n \"kind\": \"plugin\",\n \"files\": [\n \"chatjs/plugins/search/backfill.ts\",\n \"chatjs/plugins/search/chat.ts\",\n \"chatjs/plugins/search/
|
|
119
|
+
"content": "{\n \"contractVersion\": 3,\n \"uiBase\": \"base\",\n \"id\": \"search\",\n \"kind\": \"plugin\",\n \"files\": [\n \"chatjs/plugins/search/backfill.ts\",\n \"chatjs/plugins/search/chat-server.ts\",\n \"chatjs/plugins/search/chat-ui.ts\",\n \"chatjs/plugins/search/sidebar-item.tsx\",\n \"chatjs/plugins/search/router.ts\",\n \"chatjs/plugins/search/search-backfill.ts\",\n \"chatjs/plugins/search/search-chats.tsx\",\n \"chatjs/plugins/search/search-surface.tsx\",\n \"chatjs/plugins/search/search-surface-props.ts\",\n \"chatjs/plugins/search/search-hook.ts\",\n \"chatjs/plugins/search/search-queries.ts\",\n \"chatjs/plugins/search/search-results-view.tsx\",\n \"chatjs/plugins/search/search-schema.ts\",\n \"chatjs/plugins/search/search-text.ts\",\n \"chatjs/plugins/search/use-debounced-search.ts\",\n \"agent/hooks/search.ts\"\n ],\n \"databaseSchemas\": [\"chatjs/plugins/search/search-schema.ts\"]\n}\n",
|
|
126
120
|
"type": "registry:file",
|
|
127
|
-
"target": "~/chatjs/plugins/search/
|
|
121
|
+
"target": "~/chatjs/plugins/search/plugin.json"
|
|
128
122
|
}
|
|
129
123
|
],
|
|
130
124
|
"meta": {
|
|
131
125
|
"chatjs": {
|
|
126
|
+
"contractVersion": 3,
|
|
127
|
+
"uiBase": "base",
|
|
132
128
|
"id": "search",
|
|
133
129
|
"kind": "plugin",
|
|
134
130
|
"files": [
|
|
135
131
|
"chatjs/plugins/search/backfill.ts",
|
|
136
|
-
"chatjs/plugins/search/chat.ts",
|
|
137
|
-
"chatjs/plugins/search/
|
|
132
|
+
"chatjs/plugins/search/chat-server.ts",
|
|
133
|
+
"chatjs/plugins/search/chat-ui.ts",
|
|
138
134
|
"chatjs/plugins/search/sidebar-item.tsx",
|
|
139
135
|
"chatjs/plugins/search/router.ts",
|
|
140
136
|
"chatjs/plugins/search/search-backfill.ts",
|
|
@@ -146,30 +142,12 @@
|
|
|
146
142
|
"chatjs/plugins/search/search-results-view.tsx",
|
|
147
143
|
"chatjs/plugins/search/search-schema.ts",
|
|
148
144
|
"chatjs/plugins/search/search-text.ts",
|
|
149
|
-
"chatjs/plugins/search/server-plugin.ts",
|
|
150
145
|
"chatjs/plugins/search/use-debounced-search.ts",
|
|
151
146
|
"agent/hooks/search.ts"
|
|
152
147
|
],
|
|
153
148
|
"databaseSchemas": [
|
|
154
149
|
"chatjs/plugins/search/search-schema.ts"
|
|
155
|
-
]
|
|
156
|
-
"chat": {
|
|
157
|
-
"export": "searchChat"
|
|
158
|
-
},
|
|
159
|
-
"server": {
|
|
160
|
-
"export": "search",
|
|
161
|
-
"routers": [
|
|
162
|
-
"search"
|
|
163
|
-
]
|
|
164
|
-
},
|
|
165
|
-
"client": {
|
|
166
|
-
"export": "searchClient",
|
|
167
|
-
"composerControls": [],
|
|
168
|
-
"settingsItems": [],
|
|
169
|
-
"chat": true
|
|
170
|
-
},
|
|
171
|
-
"contractVersion": 2,
|
|
172
|
-
"uiBase": "base"
|
|
150
|
+
]
|
|
173
151
|
}
|
|
174
152
|
},
|
|
175
153
|
"type": "registry:item"
|
package/dist/r/base/sharing.json
CHANGED
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
],
|
|
21
21
|
"files": [
|
|
22
22
|
{
|
|
23
|
-
"path": "src/plugins/sharing/src/chat.ts",
|
|
24
|
-
"content": "import { eq } from \"drizzle-orm\";\nimport type { ChatServerIntegration } from \"@/chatjs/core/chat/contracts\";\nimport { eveConversation } from \"@/lib/db/schema\";\n\
|
|
23
|
+
"path": "src/plugins/sharing/src/chat-server.ts",
|
|
24
|
+
"content": "import { eq } from \"drizzle-orm\";\nimport type { ChatServerIntegration } from \"@/chatjs/core/chat/contracts\";\nimport { eveConversation } from \"@/lib/db/schema\";\n\nconst sharingChat = {\n publicReadFilter: () => eq(eveConversation.visibility, \"public\"),\n} satisfies ChatServerIntegration;\n\nexport default sharingChat;\n",
|
|
25
25
|
"type": "registry:file",
|
|
26
|
-
"target": "~/chatjs/plugins/sharing/chat.ts"
|
|
26
|
+
"target": "~/chatjs/plugins/sharing/chat-server.ts"
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
|
-
"path": "src/plugins/sharing/src/
|
|
30
|
-
"content": "\"use client\";\nimport { definePlugin, slot } from \"@/chatjs/core/ui/slots\";\nimport { ChatActions, ChatHeaderActions } from \"@/components/chat-slots\";\nimport { SharingActions, SharingHeaderActions } from \"./ui/chat-contributions\";\n\nexport const
|
|
29
|
+
"path": "src/plugins/sharing/src/chat-ui.ts",
|
|
30
|
+
"content": "\"use client\";\nimport { definePlugin, slot } from \"@/chatjs/core/ui/slots\";\nimport { ChatActions, ChatHeaderActions } from \"@/components/chat-slots\";\nimport { SharingActions, SharingHeaderActions } from \"./ui/chat-contributions\";\n\nexport const chatUi = definePlugin({\n id: \"sharing\",\n slots: [\n slot(ChatActions, SharingActions),\n slot(ChatHeaderActions, SharingHeaderActions),\n ],\n});\n",
|
|
31
31
|
"type": "registry:file",
|
|
32
|
-
"target": "~/chatjs/plugins/sharing/
|
|
32
|
+
"target": "~/chatjs/plugins/sharing/chat-ui.ts"
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
35
|
"path": "src/plugins/sharing/src/public-conversation.ts",
|
|
@@ -45,31 +45,25 @@
|
|
|
45
45
|
},
|
|
46
46
|
{
|
|
47
47
|
"path": "src/plugins/sharing/src/router.ts",
|
|
48
|
-
"content": "import { TRPCError } from \"@trpc/server\";\nimport { z } from \"zod\";\nimport { createTRPCRouter, protectedProcedure } from \"@/trpc/init\";\nimport { getSharing, setSharing } from \"./queries\";\n\
|
|
48
|
+
"content": "import { TRPCError } from \"@trpc/server\";\nimport { z } from \"zod\";\nimport { createTRPCRouter, protectedProcedure } from \"@/trpc/init\";\nimport { getSharing, setSharing } from \"./queries\";\n\nconst sharingProcedures = {\n get: protectedProcedure\n .input(z.object({ id: z.uuid() }))\n .query(async ({ ctx, input }) => {\n const row = await getSharing(ctx.user.id, input.id);\n if (row === undefined) {\n throw new TRPCError({ code: \"NOT_FOUND\" });\n }\n return row;\n }),\n setVisibility: protectedProcedure\n .input(\n z.object({ id: z.uuid(), visibility: z.enum([\"private\", \"public\"]) })\n )\n .mutation(async ({ ctx, input }) => {\n const row = await setSharing(ctx.user.id, input.id, input.visibility);\n if (row === undefined) {\n throw new TRPCError({ code: \"NOT_FOUND\" });\n }\n return row;\n }),\n};\n\nexport const router = createTRPCRouter({ sharing: sharingProcedures });\n",
|
|
49
49
|
"type": "registry:file",
|
|
50
50
|
"target": "~/chatjs/plugins/sharing/router.ts"
|
|
51
51
|
},
|
|
52
|
-
{
|
|
53
|
-
"path": "src/plugins/sharing/src/server-plugin.ts",
|
|
54
|
-
"content": "import type { ChatPlugin } from \"@/chatjs/core/installation/plugin\";\nimport { sharingRouter } from \"./router\";\n\nexport const sharing = () =>\n ({ id: \"sharing\", routers: { sharing: sharingRouter } }) satisfies ChatPlugin;\n",
|
|
55
|
-
"type": "registry:file",
|
|
56
|
-
"target": "~/chatjs/plugins/sharing/server-plugin.ts"
|
|
57
|
-
},
|
|
58
52
|
{
|
|
59
53
|
"path": "src/plugins/sharing/src/ui/chat-contributions.tsx",
|
|
60
|
-
"content": "\"use client\";\nimport React, { useState } from \"react\";\nimport type { ChatActionProps } from \"@/chatjs/core/chat/contracts\";\nimport { EveShareButton, EveShareDialogContent } from \"./share-dialog\";\nimport { ShareDialog } from \"./share-button\";\nimport { ShareMenuItem } from \"./share-menu-item\";\n\nexport const SharingActions = ({\n chat,\n}: ChatActionProps): React.JSX.Element | null => {\n const [open, setOpen] = useState(false);\n const {
|
|
54
|
+
"content": "\"use client\";\nimport React, { useState } from \"react\";\nimport type { ChatActionProps } from \"@/chatjs/core/chat/contracts\";\nimport { EveShareButton, EveShareDialogContent } from \"./share-dialog\";\nimport { ShareDialog } from \"./share-button\";\nimport { ShareMenuItem } from \"./share-menu-item\";\n\nexport const SharingActions = ({\n chat,\n}: ChatActionProps): React.JSX.Element | null => {\n const [open, setOpen] = useState(false);\n const { branchId } = chat;\n if (\n branchId === undefined ||\n branchId === null ||\n branchId === \"\" ||\n chat.state !== \"bound\"\n ) {\n return null;\n }\n return (\n <>\n <ShareMenuItem\n onShare={() => {\n setOpen(true);\n }}\n />\n {open && (\n <ShareDialog\n open={open}\n onOpenChange={setOpen}\n renderContent={(onClose) => (\n <EveShareDialogContent branchId={branchId} onClose={onClose} />\n )}\n />\n )}\n </>\n );\n};\nexport const SharingHeaderActions = ({\n chat,\n}: ChatActionProps): React.JSX.Element | null => {\n if (\n chat.branchId === undefined ||\n chat.branchId === null ||\n chat.branchId === \"\" ||\n chat.state !== \"bound\"\n ) {\n return null;\n }\n return <EveShareButton branchId={chat.branchId} className=\"hidden md:flex\" />;\n};\n",
|
|
61
55
|
"type": "registry:file",
|
|
62
56
|
"target": "~/chatjs/plugins/sharing/ui/chat-contributions.tsx"
|
|
63
57
|
},
|
|
64
58
|
{
|
|
65
59
|
"path": "src/plugins/sharing/src/ui/share-button.tsx",
|
|
66
|
-
"content": "\"use client\";\nimport { DialogButton } from \"@/components/dialog-button\";\nimport { PopoverButton } from \"@/components/popover-button\";\n\nimport { Copy, GlobeIcon, Loader2, LockIcon, Share } from \"lucide-react\";\nimport React, { createContext, useContext, useState } from \"react\";\nimport { toast } from \"sonner\";\n\nimport { Button } from \"@/components/ui/button\";\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogHeader,\n DialogTitle,\n} from \"@/components/ui/dialog\";\nimport { Popover, PopoverContent } from \"@/components/ui/popover\";\nimport type { ReadonlyReactNode } from \"@/lib/readonly-react-node\";\nimport { cn } from \"@/lib/utils\";\nimport { useSession } from \"@/providers/session-provider\";\n\nimport { LoginPrompt } from \"@/components/upgrade-cta/login-prompt\";\n\ntype ShareStep = \"info\" | \"shared\";\n\n/** Runtime-owned link destination; the dialog and visibility controller stay shared. */\nexport const SharingEnvironmentContext = createContext<{\n readonly getUrl: (chatId: string) => string;\n readonly notice?: string;\n}>({ getUrl: (chatId) => `${globalThis.location.origin}/share/${chatId}` });\n\nconst ShareDialogView = ({\n chatId,\n isPublic,\n isPending,\n onClose,\n setVisibility,\n}: {\n readonly chatId: string;\n readonly isPublic: boolean;\n readonly isPending: boolean;\n readonly onClose: () => void;\n readonly setVisibility: (visibility: \"private\" | \"public\") => Promise<void>;\n}): React.JSX.Element => {\n const environment = useContext(SharingEnvironmentContext);\n const [, startEventAction] = React.useTransition();\n const [step, setStep] = useState<ShareStep>(\"info\");\n const handleShare = async (): Promise<void> => {\n try {\n await setVisibility(\"public\");\n setStep(\"shared\");\n } catch (error) {\n toast.error(\n error instanceof Error ? error.message : \"Unable to share chat.\"\n );\n }\n };\n const handleUnshare = async (): Promise<void> => {\n try {\n await setVisibility(\"private\");\n onClose();\n setStep(\"info\");\n } catch (error) {\n toast.error(\n error instanceof Error ? error.message : \"Unable to make chat private.\"\n );\n }\n };\n const handleCopyLink = async (): Promise<void> => {\n const shareUrl = environment.getUrl(chatId);\n try {\n await navigator.clipboard.writeText(shareUrl);\n toast.success(\"Share link copied to clipboard\");\n } catch {\n toast.error(\"Unable to copy share link.\");\n }\n };\n return (\n <>\n {step === \"info\" && (\n <>\n <DialogHeader>\n <DialogTitle>Share chat</DialogTitle>\n <DialogDescription>\n {isPublic\n ? \"This chat is currently public. Anyone with the link can view it.\"\n : \"Make this chat public so you can share it with others.\"}\n </DialogDescription>\n </DialogHeader>\n <div className=\"flex flex-col gap-4\">\n <div className=\"bg-muted/20 flex items-center gap-3 rounded-lg border p-3\">\n {isPublic ? (\n <>\n <div className=\"text-green-600\">\n <GlobeIcon size={20} />\n </div>\n <div className=\"flex-1\">\n <div className=\"text-sm font-medium\">Public</div>\n <div className=\"text-muted-foreground text-xs\">\n Anyone with the link can access this chat\n </div>\n </div>\n </>\n ) : (\n <>\n <div className=\"text-muted-foreground\">\n <LockIcon size={20} />\n </div>\n <div className=\"flex-1\">\n <div className=\"text-sm font-medium\">Private</div>\n <div className=\"text-muted-foreground text-xs\">\n Only you can access this chat\n </div>\n </div>\n </>\n )}\n </div>\n <div className=\"flex gap-2\">\n {isPublic ? (\n <>\n <Button\n className=\"flex-1\"\n disabled={isPending}\n\n onClick={() => {\n startEventAction(handleUnshare);\n }}\n variant=\"outline\"\n >\n {isPending ? (\n <>\n <Loader2 className=\"animate-spin\" size={16} />\n <span className=\"ml-2\">Making Private...</span>\n </>\n ) : (\n <>\n <LockIcon size={16} />\n <span className=\"ml-2\">Make Private</span>\n </>\n )}\n </Button>\n <Button\n className=\"flex-1\"\n disabled={isPending}\n onClick={() => {\n setStep(\"shared\");\n }}\n >\n <GlobeIcon size={16} />\n <span className=\"ml-2\">Get Link</span>\n </Button>\n </>\n ) : (\n <Button\n className=\"w-full\"\n disabled={isPending}\n\n onClick={() => {\n startEventAction(handleShare);\n }}\n >\n {isPending ? (\n <>\n <Loader2 className=\"animate-spin\" size={16} />\n <span className=\"ml-2\">Sharing...</span>\n </>\n ) : (\n <>\n <GlobeIcon size={16} />\n <span className=\"ml-2\">Share Chat</span>\n </>\n )}\n </Button>\n )}\n </div>\n </div>\n </>\n )}\n\n {step === \"shared\" && (\n <>\n <DialogHeader>\n <DialogTitle>Share chat</DialogTitle>\n <DialogDescription>\n Copy the link below to share this chat with others.\n </DialogDescription>\n </DialogHeader>\n <div className=\"flex items-center space-x-2\">\n <div className=\"grid flex-1 gap-2\">\n <label className=\"sr-only\" htmlFor=\"link\">\n Link\n </label>\n <input\n className=\"border-input bg-background ring-offset-background placeholder:text-muted-foreground focus-visible:ring-ring flex h-10 w-full rounded-md border px-3 py-2 text-sm file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:cursor-not-allowed disabled:opacity-50\"\n value={environment.getUrl(chatId)}\n id=\"link\"\n readOnly\n />\n </div>\n <Button\n className=\"px-3\"\n\n onClick={() => {\n startEventAction(handleCopyLink);\n }}\n size=\"sm\"\n type=\"submit\"\n >\n <Copy size={16} />\n <span className=\"sr-only\">Copy</span>\n </Button>\n </div>\n <div className=\"flex items-center justify-between pt-2\">\n <Button\n onClick={() => {\n setStep(\"info\");\n }}\n size=\"sm\"\n variant=\"ghost\"\n >\n ← Back\n </Button>\n <Button\n disabled={isPending}\n\n onClick={() => {\n startEventAction(handleUnshare);\n }}\n size=\"sm\"\n variant=\"outline\"\n >\n {isPending ? (\n <>\n <Loader2 className=\"animate-spin\" size={16} />\n <span className=\"ml-2\">Making Private...</span>\n </>\n ) : (\n <>\n <LockIcon size={16} />\n <span className=\"ml-2\">Make Private</span>\n </>\n )}\n </Button>\n </div>\n </>\n )}\n {typeof environment.notice === \"string\" && environment.notice !== \"\" && (\n <p className=\"text-muted-foreground text-xs\">{environment.notice}</p>\n )}\n </>\n );\n};\n\n// Extracted dialog component that can be controlled externally\nconst ShareDialog = ({\n open,\n onOpenChange,\n children,\n renderContent,\n}: {\n readonly open: boolean;\n readonly onOpenChange: (open: boolean) => void;\n readonly children?: ReadonlyReactNode;\n readonly renderContent: (onClose: () => void) => React.ReactNode;\n}): React.JSX.Element => {\n const handleDialogOpenChange = (isOpen: boolean): void => {\n onOpenChange(isOpen);\n };\n\n return (\n <Dialog onOpenChange={handleDialogOpenChange} open={open}>\n {children}\n <DialogContent className=\"sm:max-w-md\">\n {open &&\n renderContent(() => {\n onOpenChange(false);\n })}\n </DialogContent>\n </Dialog>\n );\n};\n\nconst ShareButton = ({\n className,\n renderContent,\n}: {\n readonly renderContent: (onClose: () => void) => React.ReactNode;\n readonly className?: string;\n} & Omit<\n React.ComponentProps<typeof Button>,\n \"className\"\n>): React.JSX.Element => {\n const [open, setOpen] = useState(false);\n const { data: session } = useSession();\n const isAuthenticated = Boolean(session?.user);\n\n const TriggerButton = isAuthenticated ? DialogButton : PopoverButton;\n const triggerButton = (\n <TriggerButton className={cn(\"\", className)} size=\"sm\" variant=\"outline\">\n <Share size={16} />\n <span className=\"sr-only\">Share chat</span>\n </TriggerButton>\n );\n\n if (!isAuthenticated) {\n return (\n <Popover>\n {triggerButton}\n <PopoverContent align=\"start\" className=\"w-80 p-0\">\n <LoginPrompt\n description=\"Control who can see your conversations and share them with others.\"\n title=\"Sign in to share your chat\"\n />\n </PopoverContent>\n </Popover>\n );\n }\n\n return (\n <ShareDialog\n onOpenChange={setOpen}\n open={open}\n renderContent={renderContent}\n >\n {triggerButton}\n </ShareDialog>\n );\n};\nexport { ShareButton, ShareDialog, ShareDialogView };\n",
|
|
60
|
+
"content": "\"use client\";\nimport { DialogButton } from \"@/components/dialog-button\";\nimport { PopoverButton } from \"@/components/popover-button\";\n\nimport { Copy, GlobeIcon, Loader2, LockIcon, Share } from \"lucide-react\";\nimport React, { createContext, useContext, useState } from \"react\";\nimport { toast } from \"sonner\";\n\nimport { Button } from \"@/components/ui/button\";\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogHeader,\n DialogTitle,\n} from \"@/components/ui/dialog\";\nimport { Popover, PopoverContent } from \"@/components/ui/popover\";\nimport type { ReadonlyReactNode } from \"@/lib/readonly-react-node\";\nimport { cn } from \"@/lib/utils\";\nimport { useSession } from \"@/providers/session-provider\";\n\nimport { LoginPrompt } from \"@/components/upgrade-cta/login-prompt\";\n\ntype ShareStep = \"info\" | \"shared\";\n\n/** Runtime-owned link destination; the dialog and visibility controller stay shared. */\nexport const SharingEnvironmentContext = createContext<{\n readonly getUrl: (branchId: string) => string;\n readonly notice?: string;\n}>({ getUrl: (branchId) => `${globalThis.location.origin}/share/${branchId}` });\n\nconst ShareDialogView = ({\n branchId,\n isPublic,\n isPending,\n onClose,\n setVisibility,\n}: {\n readonly branchId: string;\n readonly isPublic: boolean;\n readonly isPending: boolean;\n readonly onClose: () => void;\n readonly setVisibility: (visibility: \"private\" | \"public\") => Promise<void>;\n}): React.JSX.Element => {\n const environment = useContext(SharingEnvironmentContext);\n const [, startEventAction] = React.useTransition();\n const [step, setStep] = useState<ShareStep>(\"info\");\n const handleShare = async (): Promise<void> => {\n try {\n await setVisibility(\"public\");\n setStep(\"shared\");\n } catch (error) {\n toast.error(\n error instanceof Error ? error.message : \"Unable to share chat.\"\n );\n }\n };\n const handleUnshare = async (): Promise<void> => {\n try {\n await setVisibility(\"private\");\n onClose();\n setStep(\"info\");\n } catch (error) {\n toast.error(\n error instanceof Error ? error.message : \"Unable to make chat private.\"\n );\n }\n };\n const handleCopyLink = async (): Promise<void> => {\n const shareUrl = environment.getUrl(branchId);\n try {\n await navigator.clipboard.writeText(shareUrl);\n toast.success(\"Share link copied to clipboard\");\n } catch {\n toast.error(\"Unable to copy share link.\");\n }\n };\n return (\n <>\n {step === \"info\" && (\n <>\n <DialogHeader>\n <DialogTitle>Share chat</DialogTitle>\n <DialogDescription>\n {isPublic\n ? \"This chat is currently public. Anyone with the link can view it.\"\n : \"Make this chat public so you can share it with others.\"}\n </DialogDescription>\n </DialogHeader>\n <div className=\"flex flex-col gap-4\">\n <div className=\"bg-muted/20 flex items-center gap-3 rounded-lg border p-3\">\n {isPublic ? (\n <>\n <div className=\"text-green-600\">\n <GlobeIcon size={20} />\n </div>\n <div className=\"flex-1\">\n <div className=\"text-sm font-medium\">Public</div>\n <div className=\"text-muted-foreground text-xs\">\n Anyone with the link can access this chat\n </div>\n </div>\n </>\n ) : (\n <>\n <div className=\"text-muted-foreground\">\n <LockIcon size={20} />\n </div>\n <div className=\"flex-1\">\n <div className=\"text-sm font-medium\">Private</div>\n <div className=\"text-muted-foreground text-xs\">\n Only you can access this chat\n </div>\n </div>\n </>\n )}\n </div>\n <div className=\"flex gap-2\">\n {isPublic ? (\n <>\n <Button\n className=\"flex-1\"\n disabled={isPending}\n\n onClick={() => {\n startEventAction(handleUnshare);\n }}\n variant=\"outline\"\n >\n {isPending ? (\n <>\n <Loader2 className=\"animate-spin\" size={16} />\n <span className=\"ml-2\">Making Private...</span>\n </>\n ) : (\n <>\n <LockIcon size={16} />\n <span className=\"ml-2\">Make Private</span>\n </>\n )}\n </Button>\n <Button\n className=\"flex-1\"\n disabled={isPending}\n onClick={() => {\n setStep(\"shared\");\n }}\n >\n <GlobeIcon size={16} />\n <span className=\"ml-2\">Get Link</span>\n </Button>\n </>\n ) : (\n <Button\n className=\"w-full\"\n disabled={isPending}\n\n onClick={() => {\n startEventAction(handleShare);\n }}\n >\n {isPending ? (\n <>\n <Loader2 className=\"animate-spin\" size={16} />\n <span className=\"ml-2\">Sharing...</span>\n </>\n ) : (\n <>\n <GlobeIcon size={16} />\n <span className=\"ml-2\">Share Chat</span>\n </>\n )}\n </Button>\n )}\n </div>\n </div>\n </>\n )}\n\n {step === \"shared\" && (\n <>\n <DialogHeader>\n <DialogTitle>Share chat</DialogTitle>\n <DialogDescription>\n Copy the link below to share this chat with others.\n </DialogDescription>\n </DialogHeader>\n <div className=\"flex items-center space-x-2\">\n <div className=\"grid flex-1 gap-2\">\n <label className=\"sr-only\" htmlFor=\"link\">\n Link\n </label>\n <input\n className=\"border-input bg-background ring-offset-background placeholder:text-muted-foreground focus-visible:ring-ring flex h-10 w-full rounded-md border px-3 py-2 text-sm file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:cursor-not-allowed disabled:opacity-50\"\n value={environment.getUrl(branchId)}\n id=\"link\"\n readOnly\n />\n </div>\n <Button\n className=\"px-3\"\n\n onClick={() => {\n startEventAction(handleCopyLink);\n }}\n size=\"sm\"\n type=\"submit\"\n >\n <Copy size={16} />\n <span className=\"sr-only\">Copy</span>\n </Button>\n </div>\n <div className=\"flex items-center justify-between pt-2\">\n <Button\n onClick={() => {\n setStep(\"info\");\n }}\n size=\"sm\"\n variant=\"ghost\"\n >\n ← Back\n </Button>\n <Button\n disabled={isPending}\n\n onClick={() => {\n startEventAction(handleUnshare);\n }}\n size=\"sm\"\n variant=\"outline\"\n >\n {isPending ? (\n <>\n <Loader2 className=\"animate-spin\" size={16} />\n <span className=\"ml-2\">Making Private...</span>\n </>\n ) : (\n <>\n <LockIcon size={16} />\n <span className=\"ml-2\">Make Private</span>\n </>\n )}\n </Button>\n </div>\n </>\n )}\n {typeof environment.notice === \"string\" && environment.notice !== \"\" && (\n <p className=\"text-muted-foreground text-xs\">{environment.notice}</p>\n )}\n </>\n );\n};\n\n// Extracted dialog component that can be controlled externally\nconst ShareDialog = ({\n open,\n onOpenChange,\n children,\n renderContent,\n}: {\n readonly open: boolean;\n readonly onOpenChange: (open: boolean) => void;\n readonly children?: ReadonlyReactNode;\n readonly renderContent: (onClose: () => void) => React.ReactNode;\n}): React.JSX.Element => {\n const handleDialogOpenChange = (isOpen: boolean): void => {\n onOpenChange(isOpen);\n };\n\n return (\n <Dialog onOpenChange={handleDialogOpenChange} open={open}>\n {children}\n <DialogContent className=\"sm:max-w-md\">\n {open &&\n renderContent(() => {\n onOpenChange(false);\n })}\n </DialogContent>\n </Dialog>\n );\n};\n\nconst ShareButton = ({\n className,\n renderContent,\n}: {\n readonly renderContent: (onClose: () => void) => React.ReactNode;\n readonly className?: string;\n} & Omit<\n React.ComponentProps<typeof Button>,\n \"className\"\n>): React.JSX.Element => {\n const [open, setOpen] = useState(false);\n const { data: session } = useSession();\n const isAuthenticated = Boolean(session?.user);\n\n const TriggerButton = isAuthenticated ? DialogButton : PopoverButton;\n const triggerButton = (\n <TriggerButton className={cn(\"\", className)} size=\"sm\" variant=\"outline\">\n <Share size={16} />\n <span className=\"sr-only\">Share chat</span>\n </TriggerButton>\n );\n\n if (!isAuthenticated) {\n return (\n <Popover>\n {triggerButton}\n <PopoverContent align=\"start\" className=\"w-80 p-0\">\n <LoginPrompt\n description=\"Control who can see your conversations and share them with others.\"\n title=\"Sign in to share your chat\"\n />\n </PopoverContent>\n </Popover>\n );\n }\n\n return (\n <ShareDialog\n onOpenChange={setOpen}\n open={open}\n renderContent={renderContent}\n >\n {triggerButton}\n </ShareDialog>\n );\n};\nexport { ShareButton, ShareDialog, ShareDialogView };\n",
|
|
67
61
|
"type": "registry:file",
|
|
68
62
|
"target": "~/chatjs/plugins/sharing/ui/share-button.tsx"
|
|
69
63
|
},
|
|
70
64
|
{
|
|
71
65
|
"path": "src/plugins/sharing/src/ui/share-dialog.tsx",
|
|
72
|
-
"content": "\"use client\";\n\nimport { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport React from \"react\";\nimport type { JSX as ReactJSX } from \"react\";\n\nimport {\n ShareButton,\n ShareDialogView,\n} from \"@/chatjs/plugins/sharing/ui/share-button\";\nimport { useTRPC } from \"@/trpc/react\";\n\nconst EveShareDialogContent = ({\n
|
|
66
|
+
"content": "\"use client\";\n\nimport { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport React from \"react\";\nimport type { JSX as ReactJSX } from \"react\";\n\nimport {\n ShareButton,\n ShareDialogView,\n} from \"@/chatjs/plugins/sharing/ui/share-button\";\nimport { useTRPC } from \"@/trpc/react\";\n\nconst EveShareDialogContent = ({\n branchId,\n onClose,\n}: {\n readonly branchId: string;\n readonly onClose: () => void;\n}): ReactJSX.Element => {\n const trpc = useTRPC();\n const cache = useQueryClient();\n const query = useQuery(trpc.sharing.get.queryOptions({ id: branchId }));\n const mutation = useMutation(trpc.sharing.setVisibility.mutationOptions());\n return (\n <>\n <ShareDialogView\n branchId={branchId}\n isPending={query.isPending || mutation.isPending || query.isError}\n isPublic={query.data?.visibility === \"public\"}\n onClose={onClose}\n setVisibility={async (visibility) => {\n await mutation.mutateAsync({ id: branchId, visibility });\n await cache.invalidateQueries({\n queryKey: trpc.sharing.get.queryKey({ id: branchId }),\n });\n }}\n />\n {query.error && <p role=\"alert\">{query.error.message}</p>}\n </>\n );\n};\n\nconst EveShareButton = ({\n branchId,\n className,\n}: {\n readonly branchId: string;\n readonly className?: string;\n}): React.JSX.Element => (\n <ShareButton\n className={className}\n renderContent={(onClose): React.JSX.Element => (\n <EveShareDialogContent branchId={branchId} onClose={onClose} />\n )}\n />\n);\nexport { EveShareButton, EveShareDialogContent };\n",
|
|
73
67
|
"type": "registry:file",
|
|
74
68
|
"target": "~/chatjs/plugins/sharing/ui/share-dialog.tsx"
|
|
75
69
|
},
|
|
@@ -105,28 +99,29 @@
|
|
|
105
99
|
},
|
|
106
100
|
{
|
|
107
101
|
"path": "src/plugins/sharing/adapters/app/(chat)/share/[id]/page.tsx",
|
|
108
|
-
"content": "// ChatJS source: sharing. Ownership: chatjs/plugins/sharing/
|
|
102
|
+
"content": "// ChatJS source: sharing. Ownership: chatjs/plugins/sharing/plugin.json.\nimport React, { Suspense } from \"react\";\n\nimport { ChatLoadingShell } from \"@/components/chat-loading-shell\";\nimport { EveSharedPage } from \"@/chatjs/plugins/sharing/ui/shared-page\";\n\nconst SharedChatPageContent = async ({\n params,\n}: {\n readonly params: Readonly<Promise<{ readonly id: string }>>;\n}): Promise<React.JSX.Element> => {\n const { id } = await params;\n return <EveSharedPage id={id} />;\n};\n\nconst SharedChatPageRoute = ({\n params,\n}: {\n readonly params: Readonly<Promise<{ readonly id: string }>>;\n}): React.JSX.Element => (\n <Suspense fallback={<ChatLoadingShell />}>\n <SharedChatPageContent params={params} />\n </Suspense>\n);\nexport default SharedChatPageRoute;\n",
|
|
109
103
|
"type": "registry:file",
|
|
110
104
|
"target": "~/app/(chat)/share/[id]/page.tsx"
|
|
111
105
|
},
|
|
112
106
|
{
|
|
113
107
|
"path": "dist/source/sharing.json",
|
|
114
|
-
"content": "{\n \"id\": \"sharing\",\n \"kind\": \"plugin\",\n \"files\": [\n \"chatjs/plugins/sharing/chat.ts\",\n \"chatjs/plugins/sharing/
|
|
108
|
+
"content": "{\n \"contractVersion\": 3,\n \"uiBase\": \"base\",\n \"id\": \"sharing\",\n \"kind\": \"plugin\",\n \"files\": [\n \"chatjs/plugins/sharing/chat-server.ts\",\n \"chatjs/plugins/sharing/chat-ui.ts\",\n \"chatjs/plugins/sharing/public-conversation.ts\",\n \"chatjs/plugins/sharing/queries.ts\",\n \"chatjs/plugins/sharing/router.ts\",\n \"chatjs/plugins/sharing/ui/chat-contributions.tsx\",\n \"chatjs/plugins/sharing/ui/share-button.tsx\",\n \"chatjs/plugins/sharing/ui/share-dialog.tsx\",\n \"chatjs/plugins/sharing/ui/share-menu-item.tsx\",\n \"chatjs/plugins/sharing/ui/share-menu-surface.tsx\",\n \"chatjs/plugins/sharing/ui/shared-badge.tsx\",\n \"chatjs/plugins/sharing/ui/transcript-messages.tsx\",\n \"chatjs/plugins/sharing/ui/shared-page.tsx\",\n \"app/(chat)/share/[id]/page.tsx\"\n ]\n}\n",
|
|
115
109
|
"type": "registry:file",
|
|
116
|
-
"target": "~/chatjs/plugins/sharing/
|
|
110
|
+
"target": "~/chatjs/plugins/sharing/plugin.json"
|
|
117
111
|
}
|
|
118
112
|
],
|
|
119
113
|
"meta": {
|
|
120
114
|
"chatjs": {
|
|
115
|
+
"contractVersion": 3,
|
|
116
|
+
"uiBase": "base",
|
|
121
117
|
"id": "sharing",
|
|
122
118
|
"kind": "plugin",
|
|
123
119
|
"files": [
|
|
124
|
-
"chatjs/plugins/sharing/chat.ts",
|
|
125
|
-
"chatjs/plugins/sharing/
|
|
120
|
+
"chatjs/plugins/sharing/chat-server.ts",
|
|
121
|
+
"chatjs/plugins/sharing/chat-ui.ts",
|
|
126
122
|
"chatjs/plugins/sharing/public-conversation.ts",
|
|
127
123
|
"chatjs/plugins/sharing/queries.ts",
|
|
128
124
|
"chatjs/plugins/sharing/router.ts",
|
|
129
|
-
"chatjs/plugins/sharing/server-plugin.ts",
|
|
130
125
|
"chatjs/plugins/sharing/ui/chat-contributions.tsx",
|
|
131
126
|
"chatjs/plugins/sharing/ui/share-button.tsx",
|
|
132
127
|
"chatjs/plugins/sharing/ui/share-dialog.tsx",
|
|
@@ -136,24 +131,7 @@
|
|
|
136
131
|
"chatjs/plugins/sharing/ui/transcript-messages.tsx",
|
|
137
132
|
"chatjs/plugins/sharing/ui/shared-page.tsx",
|
|
138
133
|
"app/(chat)/share/[id]/page.tsx"
|
|
139
|
-
]
|
|
140
|
-
"chat": {
|
|
141
|
-
"export": "sharingChat"
|
|
142
|
-
},
|
|
143
|
-
"server": {
|
|
144
|
-
"export": "sharing",
|
|
145
|
-
"routers": [
|
|
146
|
-
"sharing"
|
|
147
|
-
]
|
|
148
|
-
},
|
|
149
|
-
"client": {
|
|
150
|
-
"export": "sharingClient",
|
|
151
|
-
"composerControls": [],
|
|
152
|
-
"settingsItems": [],
|
|
153
|
-
"chat": true
|
|
154
|
-
},
|
|
155
|
-
"contractVersion": 2,
|
|
156
|
-
"uiBase": "base"
|
|
134
|
+
]
|
|
157
135
|
}
|
|
158
136
|
},
|
|
159
137
|
"type": "registry:item"
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
],
|
|
15
15
|
"files": [
|
|
16
16
|
{
|
|
17
|
-
"path": "src/plugins/spreadsheet-viewer/src/
|
|
18
|
-
"content": "\"use client\";\nimport { definePlugin, slot } from \"@/chatjs/core/ui/slots\";\nimport { ArtifactViewerActions } from \"@/components/artifact-actions\";\nimport { SpreadsheetViewerAction } from \"./viewer-action\";\n\nexport const
|
|
17
|
+
"path": "src/plugins/spreadsheet-viewer/src/chat-ui.ts",
|
|
18
|
+
"content": "\"use client\";\nimport { definePlugin, slot } from \"@/chatjs/core/ui/slots\";\nimport { ArtifactViewerActions } from \"@/components/artifact-actions\";\nimport { SpreadsheetViewerAction } from \"./viewer-action\";\n\nexport const chatUi = definePlugin({\n id: \"spreadsheet-viewer\",\n slots: [slot(ArtifactViewerActions, SpreadsheetViewerAction)],\n});\n",
|
|
19
19
|
"type": "registry:file",
|
|
20
|
-
"target": "~/chatjs/plugins/spreadsheet-viewer/
|
|
20
|
+
"target": "~/chatjs/plugins/spreadsheet-viewer/chat-ui.ts"
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
23
|
"path": "src/plugins/spreadsheet-viewer/src/viewer-action.tsx",
|
|
@@ -39,29 +39,23 @@
|
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
41
|
"path": "dist/source/spreadsheet-viewer.json",
|
|
42
|
-
"content": "{\n \"id\": \"spreadsheet-viewer\",\n \"kind\": \"plugin\",\n \"files\": [\n \"chatjs/plugins/spreadsheet-viewer/
|
|
42
|
+
"content": "{\n \"contractVersion\": 3,\n \"uiBase\": \"base\",\n \"id\": \"spreadsheet-viewer\",\n \"kind\": \"plugin\",\n \"files\": [\n \"chatjs/plugins/spreadsheet-viewer/chat-ui.ts\",\n \"chatjs/plugins/spreadsheet-viewer/viewer-action.tsx\",\n \"chatjs/plugins/spreadsheet-viewer/load.ts\",\n \"chatjs/plugins/spreadsheet-viewer/preview.tsx\"\n ]\n}\n",
|
|
43
43
|
"type": "registry:file",
|
|
44
|
-
"target": "~/chatjs/plugins/spreadsheet-viewer/
|
|
44
|
+
"target": "~/chatjs/plugins/spreadsheet-viewer/plugin.json"
|
|
45
45
|
}
|
|
46
46
|
],
|
|
47
47
|
"meta": {
|
|
48
48
|
"chatjs": {
|
|
49
|
+
"contractVersion": 3,
|
|
50
|
+
"uiBase": "base",
|
|
49
51
|
"id": "spreadsheet-viewer",
|
|
50
52
|
"kind": "plugin",
|
|
51
53
|
"files": [
|
|
52
|
-
"chatjs/plugins/spreadsheet-viewer/
|
|
54
|
+
"chatjs/plugins/spreadsheet-viewer/chat-ui.ts",
|
|
53
55
|
"chatjs/plugins/spreadsheet-viewer/viewer-action.tsx",
|
|
54
56
|
"chatjs/plugins/spreadsheet-viewer/load.ts",
|
|
55
57
|
"chatjs/plugins/spreadsheet-viewer/preview.tsx"
|
|
56
|
-
]
|
|
57
|
-
"client": {
|
|
58
|
-
"export": "spreadsheetViewerClient",
|
|
59
|
-
"composerControls": [],
|
|
60
|
-
"settingsItems": [],
|
|
61
|
-
"chat": true
|
|
62
|
-
},
|
|
63
|
-
"contractVersion": 2,
|
|
64
|
-
"uiBase": "base"
|
|
58
|
+
]
|
|
65
59
|
}
|
|
66
60
|
},
|
|
67
61
|
"type": "registry:item"
|