@promptbook/cli 0.113.0-1 → 0.113.0-10
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 +1 -17
- package/agents/default/developer.book +3 -0
- package/apps/agents-server/next.config.ts +6 -3
- package/apps/agents-server/src/app/admin/resource-monitor/page.tsx +456 -0
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerClient.tsx +17 -5
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerTaskLogActions.tsx +150 -0
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerTaskRow.tsx +62 -18
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerTaskTerminalDialog.tsx +125 -0
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerTasksCard.tsx +8 -6
- package/apps/agents-server/src/app/admin/task-manager/page.tsx +3 -2
- package/apps/agents-server/src/app/admin/update/AdvancedOriginRepositoryPanel.tsx +81 -0
- package/apps/agents-server/src/app/admin/update/AutomaticSelfUpdateConfigurationCard.tsx +90 -0
- package/apps/agents-server/src/app/admin/update/CurrentDeploymentCard.tsx +162 -0
- package/apps/agents-server/src/app/admin/update/CustomCommitPicker.tsx +10 -10
- package/apps/agents-server/src/app/admin/update/InstalledVersionsCard.tsx +112 -0
- package/apps/agents-server/src/app/admin/update/PendingCommitsCard.tsx +87 -0
- package/apps/agents-server/src/app/admin/update/TargetEnvironmentCard.tsx +331 -0
- package/apps/agents-server/src/app/admin/update/UpdateClient.tsx +35 -878
- package/apps/agents-server/src/app/admin/update/UpdateDatabaseMigrationsPanel.tsx +305 -0
- package/apps/agents-server/src/app/admin/update/UpdateJobCard.tsx +350 -0
- package/apps/agents-server/src/app/admin/update/UpdateOverview.ts +142 -0
- package/apps/agents-server/src/app/admin/update/buildDeploymentTimeBehindLabel.ts +29 -0
- package/apps/agents-server/src/app/admin/update/formatHumanReadableTimestamp.ts +18 -0
- package/apps/agents-server/src/app/admin/update/getUpdateJobFailureMessage.ts +13 -0
- package/apps/agents-server/src/app/admin/update/getUpdateJobSuccessMessage.ts +13 -0
- package/apps/agents-server/src/app/admin/update/updatePageCardClassName.ts +6 -0
- package/apps/agents-server/src/app/admin/update/useUpdateClientState.ts +675 -0
- package/apps/agents-server/src/app/agents/[agentName]/AgentChatWrapper.tsx +17 -3
- package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +13 -1
- package/apps/agents-server/src/app/agents/[agentName]/chat/CanonicalAgentChatSurface.tsx +6 -2
- package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/AgentCodePageClient.tsx +14 -559
- package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/AgentCodePageHeader.tsx +84 -0
- package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/AgentCodePageSection.tsx +52 -0
- package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/GeneratedCodePreview.tsx +138 -0
- package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/GeneratedHarnessSection.tsx +98 -0
- package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/SourceBookSection.tsx +66 -0
- package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/TranspiledCodeErrorBanner.tsx +30 -0
- package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/TranspiledCodeExportWarningBanner.tsx +62 -0
- package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/Transpiler.ts +9 -0
- package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/useAgentCodeExportState.ts +478 -0
- package/apps/agents-server/src/app/api/admin/chat-tasks/[taskId]/terminal/route.ts +52 -0
- package/apps/agents-server/src/app/api/admin/update/route.ts +55 -8
- package/apps/agents-server/src/app/api/admin/update/versions/route.ts +34 -0
- package/apps/agents-server/src/app/api/auth/shibboleth/acs/route.ts +4 -2
- package/apps/agents-server/src/app/api/auth/shibboleth/login/route.ts +3 -1
- package/apps/agents-server/src/app/api/auth/shibboleth/metadata/route.ts +5 -2
- package/apps/agents-server/src/app/api/auth/shibboleth/status/route.ts +5 -2
- package/apps/agents-server/src/app/api/page-preview/check/route.ts +20 -5
- package/apps/agents-server/src/app/api/page-preview/input/route.ts +161 -0
- package/apps/agents-server/src/app/api/page-preview/screenshot/route.ts +21 -13
- package/apps/agents-server/src/app/api/page-preview/stream/route.ts +81 -0
- package/apps/agents-server/src/app/layout.tsx +39 -25
- package/apps/agents-server/src/app/system/utilities/mocked-chats/cloneMockedChatPreset.ts +17 -0
- package/apps/agents-server/src/app/system/utilities/mocked-chats/confirmDeleteMockedChat.ts +16 -0
- package/apps/agents-server/src/app/system/utilities/mocked-chats/createDraftWithUpdatedMessage.ts +81 -0
- package/apps/agents-server/src/app/system/utilities/mocked-chats/createDraftWithUpdatedParticipant.ts +146 -0
- package/apps/agents-server/src/app/system/utilities/mocked-chats/createDraftWithUpdatedSettings.ts +19 -0
- package/apps/agents-server/src/app/system/utilities/mocked-chats/createDuplicatedDraft.ts +66 -0
- package/apps/agents-server/src/app/system/utilities/mocked-chats/findMockedChatById.ts +51 -0
- package/apps/agents-server/src/app/system/utilities/mocked-chats/persistMockedChats.ts +51 -0
- package/apps/agents-server/src/app/system/utilities/mocked-chats/useMockedChatsEditorState.ts +16 -426
- package/apps/agents-server/src/components/AgentAvatar/AgentAvatar.tsx +1 -1
- package/apps/agents-server/src/components/AgentAvatar/DefaultAgentAvatarVisualProvider.tsx +1 -1
- package/apps/agents-server/src/components/CronJobConfiguration/CronJobConfiguration.tsx +834 -0
- package/apps/agents-server/src/components/Header/Header.tsx +16 -3
- package/apps/agents-server/src/components/Header/HeaderDesktopTopMenuNavigation.tsx +22 -2
- package/apps/agents-server/src/components/Header/HeaderHomepageLink.tsx +1 -1
- package/apps/agents-server/src/components/Header/HeaderMobileDrawer.tsx +22 -2
- package/apps/agents-server/src/components/Header/HeaderTypes.ts +12 -1
- package/apps/agents-server/src/components/Header/buildAgentMenuStructure.tsx +6 -4
- package/apps/agents-server/src/components/Header/buildDocumentationDropdownItems.tsx +198 -3
- package/apps/agents-server/src/components/Header/buildHeaderMenuItems.ts +6 -0
- package/apps/agents-server/src/components/Header/buildHeaderSystemMenuItems.ts +182 -16
- package/apps/agents-server/src/components/Homepage/buildFreeGraphBoxLayout.ts +446 -0
- package/apps/agents-server/src/components/Homepage/buildGraphLayoutNodes.ts +415 -157
- package/apps/agents-server/src/components/Homepage/useAgentsGraphCanvasState.ts +2 -1
- package/apps/agents-server/src/components/Homepage/useAgentsListState.ts +1 -1
- package/apps/agents-server/src/components/LayoutWrapper/LayoutWrapper.tsx +21 -5
- package/apps/agents-server/src/constants/defaultAgentAvatarVisual.ts +4 -3
- package/apps/agents-server/src/database/metadataDefaults.ts +1 -1
- package/apps/agents-server/src/database/migrate.ts +25 -1
- package/apps/agents-server/src/database/migratePrefix.ts +24 -0
- package/apps/agents-server/src/database/runDatabaseMigrations.ts +9 -1
- package/apps/agents-server/src/database/sqlite/$provideLocalSqliteSupabase.ts +3 -1541
- package/apps/agents-server/src/database/sqlite/localSqliteSupabase/LocalSqliteQueryBuilder.ts +623 -0
- package/apps/agents-server/src/database/sqlite/localSqliteSupabase/LocalSqliteSupabaseClient.ts +64 -0
- package/apps/agents-server/src/database/sqlite/localSqliteSupabase/ensureTable.ts +93 -0
- package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteFilters.ts +202 -0
- package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteMutationPayload.ts +131 -0
- package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteRowOperations.ts +102 -0
- package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteSql.ts +59 -0
- package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteTableSchema.ts +329 -0
- package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteTypes.ts +84 -0
- package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteValueCodec.ts +63 -0
- package/apps/agents-server/src/database/sqlite/localSqliteSupabase/normalizeSqliteError.ts +22 -0
- package/apps/agents-server/src/instrumentation-node.ts +15 -0
- package/apps/agents-server/src/languages/ServerTranslationKeys.ts +1 -0
- package/apps/agents-server/src/languages/translations/czech.yaml +1 -0
- package/apps/agents-server/src/languages/translations/english.yaml +1 -0
- package/apps/agents-server/src/search/createDefaultServerSearchProviders/loadLocalOrganizationSearchDataset.ts +12 -1
- package/apps/agents-server/src/tools/send_email.ts +1 -2
- package/apps/agents-server/src/{components/Homepage → utils/agentOrganization}/hiddenFolders.ts +49 -29
- package/apps/agents-server/src/utils/agentOrganization/loadAgentOrganizationState.ts +13 -1
- package/apps/agents-server/src/utils/backup/createServerBackupZipStream.ts +7 -1382
- package/apps/agents-server/src/utils/backup/serverBackup/appendAgentBackupEntriesToZip.ts +27 -0
- package/apps/agents-server/src/utils/backup/serverBackup/appendConversationBackupEntriesToZip.ts +140 -0
- package/apps/agents-server/src/utils/backup/serverBackup/appendFileBackupEntriesToZip.ts +147 -0
- package/apps/agents-server/src/utils/backup/serverBackup/appendMessageBackupEntriesToZip.ts +65 -0
- package/apps/agents-server/src/utils/backup/serverBackup/appendMetadataBackupEntriesToZip.ts +39 -0
- package/apps/agents-server/src/utils/backup/serverBackup/appendSectionEntriesToZip.ts +92 -0
- package/apps/agents-server/src/utils/backup/serverBackup/appendUserBackupEntriesToZip.ts +80 -0
- package/apps/agents-server/src/utils/backup/serverBackup/createRedactedWalletBackupRecord.ts +34 -0
- package/apps/agents-server/src/utils/backup/serverBackup/createServerBackupManifest.ts +82 -0
- package/apps/agents-server/src/utils/backup/serverBackup/downloadBackupBinaryContent.ts +39 -0
- package/apps/agents-server/src/utils/backup/serverBackup/resolveFeedbackThreadMessages.ts +53 -0
- package/apps/agents-server/src/utils/backup/serverBackup/serverBackupAttachments.ts +151 -0
- package/apps/agents-server/src/utils/backup/serverBackup/serverBackupContext.ts +167 -0
- package/apps/agents-server/src/utils/backup/serverBackup/serverBackupFilenames.ts +161 -0
- package/apps/agents-server/src/utils/backup/serverBackup/serverBackupPreviews.ts +97 -0
- package/apps/agents-server/src/utils/backup/serverBackup/serverBackupRowUtilities.ts +158 -0
- package/apps/agents-server/src/utils/backup/serverBackup/serverBackupTypes.ts +59 -0
- package/apps/agents-server/src/utils/chat/createAttachmentAwareCitationLabelResolver.ts +147 -0
- package/apps/agents-server/src/utils/chatTasksAdmin.ts +3 -2
- package/apps/agents-server/src/utils/createLocalAgentSourceImporter.ts +159 -0
- package/apps/agents-server/src/utils/createMissingImportedAgentFallback.ts +60 -0
- package/apps/agents-server/src/utils/createPagePreviewBrowserStream.ts +179 -0
- package/apps/agents-server/src/utils/customDomainRouting.ts +157 -12
- package/apps/agents-server/src/utils/externalChatRunner/processExternalUserChatJob.ts +12 -6
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/GetAdminChatTasksData.ts +12 -0
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/adminChatTaskSqlQuery.ts +264 -0
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/adminChatTaskSqlValues.ts +35 -0
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/adminChatTaskTimeUtilities.ts +30 -0
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/compareAdminChatTasks.ts +135 -0
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/createAdminChatTaskCounters.ts +29 -0
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/filterAdminChatTasks.ts +78 -0
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/getAdminChatTasksViaClientSql.ts +62 -0
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/getAdminChatTasksViaSupabaseQuery.ts +29 -0
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/loadAdminChatTaskFallbackData.ts +193 -0
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/mapAdminChatTaskFallbackRows.ts +99 -0
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks/mapAdminChatTaskSqlRows.ts +94 -0
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/getAdminChatTasks.ts +4 -947
- package/apps/agents-server/src/utils/getAdminChatTasksResponse/mapVpsSelfUpdateJobToAdminChatTask.ts +18 -5
- package/apps/agents-server/src/utils/getAdminChatTasksResponse.ts +103 -41
- package/apps/agents-server/src/utils/importAgentWithFallback.ts +1 -58
- package/apps/agents-server/src/utils/localAgentRouteReferences.ts +167 -0
- package/apps/agents-server/src/utils/localChatRunner/processLocalUserChatJob.ts +21 -6
- package/apps/agents-server/src/utils/managementApi/managementApiAgents.ts +17 -3
- package/apps/agents-server/src/utils/messages/sendMessage.ts +5 -3
- package/apps/agents-server/src/utils/pagePreviewBrowserSessions.ts +246 -0
- package/apps/agents-server/src/utils/resolveAgentStateFromSource.ts +7 -1
- package/apps/agents-server/src/utils/resolveInheritedAgentSource.ts +54 -5
- package/apps/agents-server/src/utils/resolveServerAgentContext.ts +12 -1
- package/apps/agents-server/src/utils/resolveStoredAgentState.ts +2 -1
- package/apps/agents-server/src/utils/resourceMonitor/formatResourceMonitorValue.ts +50 -0
- package/apps/agents-server/src/utils/resourceMonitor/readCpuResourceUsage.ts +75 -0
- package/apps/agents-server/src/utils/resourceMonitor/readDiskResourceUsage.ts +42 -0
- package/apps/agents-server/src/utils/resourceMonitor/readMemoryResourceUsage.ts +28 -0
- package/apps/agents-server/src/utils/resourceMonitor/readNetworkResourceUsage.ts +271 -0
- package/apps/agents-server/src/utils/resourceMonitor/readServerResourceMonitorSnapshot.ts +47 -0
- package/apps/agents-server/src/utils/resourceMonitor/resolveServerResourceWarningStatus.ts +72 -0
- package/apps/agents-server/src/utils/resourceMonitor/resourceMonitorConstants.ts +29 -0
- package/apps/agents-server/src/utils/resourceMonitor/resourceMonitorTypes.ts +155 -0
- package/apps/agents-server/src/utils/resourceMonitor/waitForResourceMonitorSample.ts +11 -0
- package/apps/agents-server/src/utils/shibbolethAuthentication/createShibbolethSamlClient.ts +35 -0
- package/apps/agents-server/src/utils/shibbolethAuthentication/createShibbolethServiceProviderMetadataXml.ts +25 -0
- package/apps/agents-server/src/utils/shibbolethAuthentication/extractShibbolethProfileAttributes.ts +173 -0
- package/apps/agents-server/src/utils/shibbolethAuthentication/fetchIdentityProviderMetadataXml.ts +21 -0
- package/apps/agents-server/src/utils/shibbolethAuthentication/findOrCreateShibbolethUser.ts +323 -0
- package/apps/agents-server/src/utils/shibbolethAuthentication/getShibbolethAuthenticationAttemptTableName.ts +13 -0
- package/apps/agents-server/src/utils/shibbolethAuthentication/getShibbolethRequestDetails.ts +19 -0
- package/apps/agents-server/src/utils/shibbolethAuthentication/getShibbolethUserIdentityTableName.ts +13 -0
- package/apps/agents-server/src/utils/shibbolethAuthentication/parseIdentityProviderMetadataXml.ts +110 -0
- package/apps/agents-server/src/utils/shibbolethAuthentication/recordShibbolethAuthenticationAttempt.ts +57 -0
- package/apps/agents-server/src/utils/shibbolethAuthentication/resolveShibbolethAuthenticationConfiguration.ts +78 -0
- package/apps/agents-server/src/utils/shibbolethAuthentication/resolveShibbolethPublicRequestUrl.ts +101 -0
- package/apps/agents-server/src/utils/shibbolethAuthentication/resolveShibbolethServiceProviderUrls.ts +63 -0
- package/apps/agents-server/src/utils/shibbolethAuthentication/sanitizeShibbolethRelayState.ts +17 -0
- package/apps/agents-server/src/utils/shibbolethAuthentication/shibbolethAuthenticationConstants.ts +62 -0
- package/apps/agents-server/src/utils/shibbolethAuthentication/shibbolethAuthenticationTypes.ts +105 -0
- package/apps/agents-server/src/utils/shibbolethAuthentication.ts +25 -957
- package/apps/agents-server/src/utils/speech-to-text/SpeechToTextFailoverRecognition/SpeechToTextFailoverRecognitionProviderRuntime.ts +0 -1
- package/apps/agents-server/src/utils/speech-to-text/SpeechToTextFailoverRecognition.ts +34 -2
- package/apps/agents-server/src/utils/taskTerminal/resolveAdminTaskTerminalSession.ts +512 -0
- package/apps/agents-server/src/utils/taskTerminal/runWithTaskTerminalCapture.ts +134 -0
- package/apps/agents-server/src/utils/taskTerminal/taskTerminalLog.ts +360 -0
- package/apps/agents-server/src/utils/userChat/finalizeUserChatJob.ts +16 -0
- package/apps/agents-server/src/utils/userChat/userChatMessageLifecycle.ts +39 -9
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/updateUserChatTimeoutTerminalState.ts +3 -0
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutWorker.ts +4 -1
- package/apps/agents-server/src/utils/vpsConfiguration.ts +4 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/deleteVpsSelfUpdateInstalledVersion.ts +81 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/listVpsSelfUpdateCandidateCommits.ts +217 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/readPersistedVpsSelfUpdateJob.ts +310 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/readVpsSelfUpdateOverview.ts +178 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/resolveVpsSelfUpdateJobForOverview.ts +42 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/startVpsSelfUpdate.ts +201 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/vpsSelfUpdateAutomaticConfiguration.ts +152 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/vpsSelfUpdateConfiguration.ts +81 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/vpsSelfUpdateCron.ts +357 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/vpsSelfUpdateEnvironment.ts +120 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/vpsSelfUpdateInstalledVersions.ts +162 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/vpsSelfUpdateJobConstants.ts +15 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/vpsSelfUpdateJobHistory.ts +387 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/vpsSelfUpdateJobIdentity.ts +26 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/vpsSelfUpdateOriginRepository.ts +90 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/vpsSelfUpdateRepository.ts +286 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/vpsSelfUpdateScheduler.ts +191 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/vpsSelfUpdateStateFiles.ts +197 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate/vpsSelfUpdateTypes.ts +452 -0
- package/apps/agents-server/src/utils/vpsSelfUpdate.ts +66 -1547
- package/apps/agents-server/tests/e2e/support/ChatHistoryNavigationSupport.ts +5 -0
- package/esm/apps/agents-server/src/database/migratePrefix.d.ts +19 -0
- package/esm/apps/agents-server/src/database/runDatabaseMigrations.d.ts +4 -0
- package/esm/book/scripts/import-markdown/increaseHeadings.d.ts +8 -0
- package/esm/index.es.js +28592 -27063
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/find-refactor-candidates/find-refactor-candidates.d.ts +7 -0
- package/esm/scripts/find-refactor-candidates/selectMostImportantRefactorCandidates.d.ts +12 -0
- package/esm/scripts/run-agent-messages/main/runMultipleAgentMessages/MultipleAgentAutoPuller.d.ts +27 -0
- package/esm/scripts/run-agent-messages/main/runMultipleAgentMessages/MultipleAgentGithubSynchronizer.d.ts +26 -0
- package/esm/scripts/run-agent-messages/main/runMultipleAgentMessages/MultipleAgentRunUiPresenter.d.ts +66 -0
- package/esm/scripts/run-agent-messages/main/runMultipleAgentMessages/RunMultipleAgentMessageTaskScheduler.d.ts +67 -0
- package/esm/scripts/run-agent-messages/main/runMultipleAgentMessages/formatProjectPath.d.ts +6 -0
- package/esm/scripts/run-agent-messages/main/runMultipleAgentMessages/loadLocalAgentRunnerProjectSummaries.d.ts +11 -0
- package/esm/scripts/run-agent-messages/main/runMultipleAgentMessages/wait.d.ts +6 -0
- package/esm/scripts/run-agent-messages/main/runMultipleAgentMessages.d.ts +1 -1
- package/esm/scripts/run-codex-prompts/common/buildCoderRunProgressSnapshot.d.ts +1 -1
- package/esm/scripts/run-codex-prompts/common/cliProgressDisplay.d.ts +2 -1
- package/esm/scripts/run-codex-prompts/common/resolveCoderAgent.d.ts +20 -0
- package/esm/scripts/run-codex-prompts/runners/claude-code/ClaudeCodeRunner.d.ts +4 -0
- package/esm/scripts/run-codex-prompts/runners/claude-code/ClaudeCodeSessionResurrection.d.ts +37 -0
- package/esm/scripts/run-codex-prompts/runners/claude-code/parseClaudeCodeOutputEvents.d.ts +47 -0
- package/esm/scripts/run-codex-prompts/ui/CoderRunUiState.d.ts +8 -1
- package/esm/scripts/run-codex-prompts/ui/buildCoderRunAgentVisual.d.ts +54 -0
- package/esm/scripts/run-codex-prompts/ui/buildCoderRunUiFrame.d.ts +10 -0
- package/esm/scripts/run-codex-prompts/ui/coderRunUiRefresh.d.ts +2 -2
- package/esm/src/_packages/types.index.d.ts +2 -2
- package/esm/src/avatars/renderAvatarVisualAsciiArt.d.ts +98 -0
- package/esm/src/avatars/visuals/octopus3dAvatarVisualShared.d.ts +1 -1
- package/esm/src/book-components/BookEditor/BookEditorMonacoUploadPanel.d.ts +1 -1
- package/esm/src/book-components/BookEditor/useBookEditorMonacoUploads/bookEditorMonacoUploadTypes.d.ts +120 -0
- package/esm/src/book-components/BookEditor/useBookEditorMonacoUploads/clearScheduledTimer.d.ts +6 -0
- package/esm/src/book-components/BookEditor/useBookEditorMonacoUploads/enqueueFilesForUpload.d.ts +26 -0
- package/esm/src/book-components/BookEditor/useBookEditorMonacoUploads/useBookEditorMonacoUploadEditorSync.d.ts +23 -0
- package/esm/src/book-components/BookEditor/useBookEditorMonacoUploads/useBookEditorMonacoUploadItemsState.d.ts +21 -0
- package/esm/src/book-components/BookEditor/useBookEditorMonacoUploads/useBookEditorMonacoUploadProgressQueue.d.ts +12 -0
- package/esm/src/book-components/BookEditor/useBookEditorMonacoUploads/useBookEditorMonacoUploadQueue.d.ts +27 -0
- package/esm/src/book-components/BookEditor/useBookEditorMonacoUploads/useCompletedUploadsAutoClear.d.ts +12 -0
- package/esm/src/book-components/BookEditor/useBookEditorMonacoUploads.d.ts +5 -58
- package/esm/src/book-components/Chat/Chat/ChatImageAttachmentModal.d.ts +25 -0
- package/esm/src/book-components/Chat/Chat/ChatInputArea.d.ts +3 -0
- package/esm/src/book-components/Chat/Chat/ChatMessageAttachments.d.ts +27 -0
- package/esm/src/book-components/Chat/Chat/ChatMessageItem.d.ts +1 -1
- package/esm/src/book-components/Chat/Chat/ChatMessageList.d.ts +1 -0
- package/esm/src/book-components/Chat/Chat/ChatProps.d.ts +8 -0
- package/esm/src/book-components/Chat/Chat/CitationIframePreview.d.ts +1 -1
- package/esm/src/book-components/Chat/Chat/CitationIframePreview.test.d.ts +2 -0
- package/esm/src/book-components/Chat/Chat/insertDictationChunk.d.ts +1 -1
- package/esm/src/book-components/Chat/Chat/insertDictationChunk.test.d.ts +1 -0
- package/esm/src/book-components/Chat/Chat/learnDictationDictionary.test.d.ts +1 -0
- package/esm/src/book-components/Chat/Chat/refineFinalDictationChunk.test.d.ts +1 -0
- package/esm/src/book-components/Chat/Chat/useChatInputAreaComposer.d.ts +12 -0
- package/esm/src/book-components/Chat/Chat/useChatInputAreaComposer.draftMessage.test.d.ts +2 -0
- package/esm/src/book-components/Chat/utils/isVisibleChatToolCall.d.ts +1 -1
- package/esm/src/book-components/Chat/utils/parseMessageButtons.d.ts +16 -2
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/AGENTS_SERVER_BUILD_CACHE_FILENAME.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/AGENTS_SERVER_BUILD_CACHE_VERSION.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/AGENTS_SERVER_NEXT_BUILD_ID_FILENAME.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/AgentsServerBuildCache.d.ts +10 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/AgentsServerBuildCacheOptions.d.ts +10 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/NODE_MODULES_DIRECTORY_NAME.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/PreparedAgentsServerRuntime.d.ts +18 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerBuildSourceFingerprint.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerRuntimeEnvironment.d.ts +28 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/ensureAgentsServerBuild.d.ts +19 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/getAgentsServerBuildInputRelativePaths.d.ts +11 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/isAgentsServerAppPath.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/isAgentsServerAppPathMaterialized.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/isAgentsServerBuildCacheCurrent.d.ts +7 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/isAgentsServerBuildInputTestFile.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/isExcludedAgentsServerBuildInputDirectoryName.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/isExcludedAgentsServerBuildInputPath.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/isExcludedAgentsServerRuntimeSourcePath.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/isFile.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/isPathInsideNodeModules.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/normalizeAgentsServerBuildInputPath.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/prepareAgentsServerRuntime.d.ts +9 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/readAgentsServerBuildCache.d.ts +8 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/resolveAgentsServerAppPath.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/resolveAgentsServerBuildAppPath.d.ts +9 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/resolveAgentsServerBuildOutputPath.d.ts +7 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/resolveNextCliPath.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/resolveNodeModulesPath.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/runNextBuild.d.ts +12 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/shouldCopyAgentsServerRuntimePath.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/synchronizeMaterializedAgentsServerRuntime.d.ts +11 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/writeAgentsServerBuildCache.d.ts +7 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer.d.ts +8 -109
- package/esm/src/cli/cli-commands/agents-server/ensureAgentsServerEnvFile.d.ts +1 -1
- package/esm/src/cli/cli-commands/agents-server/ensureAgentsServerGitignoreFile.d.ts +1 -1
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer/AgentsServerChildEnvironment.d.ts +16 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer/AgentsServerLogStreams.d.ts +30 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer/AgentsServerRuntimePaths.d.ts +19 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer/AgentsServerSupervisorState.d.ts +37 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer/LocalAgentRunnerLimits.d.ts +9 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer/PreparedAgentsServerLaunch.d.ts +13 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer/StartAgentsServerOptions.d.ts +24 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer/createInternalRouteErrorMessage.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer/createLocalAgentRunOptions.d.ts +9 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer/forwardChildOutput.d.ts +13 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer/loadAgentsServerProjectEnvironment.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer/prepareAgentsServerLaunch.d.ts +18 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer/readInternalRouteErrorDetails.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer/resolveAgentsServerChildHostname.d.ts +7 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer/startNextServer.d.ts +20 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer/startUserChatJobWorkerPump.d.ts +15 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer/stopChildProcess.d.ts +8 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer/waitForLocalAgentRunnerLimits.d.ts +16 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +3 -30
- package/esm/src/cli/cli-commands/common/createPositiveIntegerOptionParser.d.ts +10 -0
- package/esm/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +1 -1
- package/esm/src/collection/agent-collection/CreateAgentInput.d.ts +1 -1
- package/esm/src/collection/agent-collection/constructors/agent-collection-in-supabase/prepareAgentSourceForPersistence.d.ts +1 -1
- package/esm/src/commitments/META/META.d.ts +2 -2
- package/esm/src/commitments/META_AVATAR/META_AVATAR.d.ts +9 -4
- package/esm/src/commitments/index.d.ts +1 -1
- package/esm/src/conversion/validation/validatePipeline/createPipelineValidationContext.d.ts +16 -0
- package/esm/src/conversion/validation/validatePipeline/validatePipelineCollectionsStructure.d.ts +7 -0
- package/esm/src/conversion/validation/validatePipeline/validatePipelineDependencyResolution.d.ts +7 -0
- package/esm/src/conversion/validation/validatePipeline/validatePipelineMetadata.d.ts +7 -0
- package/esm/src/conversion/validation/validatePipeline/validatePipelineParameters.d.ts +7 -0
- package/esm/src/conversion/validation/validatePipeline/validatePipelineTasks.d.ts +7 -0
- package/esm/src/llm-providers/_common/register/$registeredLlmToolsMessage/RegisteredLlmToolsMessageContext.d.ts +46 -0
- package/esm/src/llm-providers/_common/register/$registeredLlmToolsMessage/USED_ENV_FILENAME.d.ts +11 -0
- package/esm/src/llm-providers/_common/register/$registeredLlmToolsMessage/createRegisteredLlmToolConfigurationStatusMessage.d.ts +7 -0
- package/esm/src/llm-providers/_common/register/$registeredLlmToolsMessage/createRegisteredLlmToolEntryKey.d.ts +7 -0
- package/esm/src/llm-providers/_common/register/$registeredLlmToolsMessage/createRegisteredLlmToolInstallationStatusMessage.d.ts +7 -0
- package/esm/src/llm-providers/_common/register/$registeredLlmToolsMessage/createRegisteredLlmToolStatus.d.ts +14 -0
- package/esm/src/llm-providers/_common/register/$registeredLlmToolsMessage/createRegisteredLlmToolsMessageContext.d.ts +7 -0
- package/esm/src/llm-providers/_common/register/$registeredLlmToolsMessage/getAvailableRegisteredLlmToolsEnvironmentVariables.d.ts +7 -0
- package/esm/src/llm-providers/_common/register/$registeredLlmToolsMessage/getRegisteredLlmToolRegisters.d.ts +7 -0
- package/esm/src/llm-providers/_common/register/$registeredLlmToolsMessage/hasRegisteredLlmToolEntry.d.ts +7 -0
- package/esm/src/llm-providers/_common/register/$registeredLlmToolsMessage/listRegisteredLlmToolEntries.d.ts +9 -0
- package/esm/src/llm-providers/_common/register/$registeredLlmToolsMessage/listRegisteredLlmToolStatuses.d.ts +7 -0
- package/esm/src/llm-providers/_common/register/$registeredLlmToolsMessage/renderAvailableRegisteredLlmTools.d.ts +7 -0
- package/esm/src/llm-providers/_common/register/$registeredLlmToolsMessage/renderNoRegisteredLlmToolsMessage.d.ts +7 -0
- package/esm/src/llm-providers/_common/register/$registeredLlmToolsMessage/renderRegisteredLlmToolsMessage.d.ts +8 -0
- package/esm/src/llm-providers/_common/register/$registeredLlmToolsMessage/renderRelevantRegisteredLlmToolsEnvironmentVariables.d.ts +7 -0
- package/esm/src/utils/agent-message-runtime/agentMessageRuntimePaths.d.ts +24 -0
- package/esm/src/utils/agents/resolveAgentAvatarImageUrl.d.ts +2 -2
- package/esm/src/utils/ascii-art/$detectTerminalAnsiColorDepth.d.ts +15 -0
- package/esm/src/utils/ascii-art/convertImageDataToAsciiArt.d.ts +80 -0
- package/esm/src/utils/color/Color.d.ts +1 -1
- package/esm/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/_packages/types.index.ts +2 -2
- package/src/avatars/Avatar.tsx +2 -13
- package/src/avatars/avatarAnimationScheduler.ts +2 -1
- package/src/avatars/renderAvatarVisual.ts +2 -13
- package/src/avatars/renderAvatarVisualAsciiArt.ts +257 -0
- package/src/avatars/visuals/asciiOctopusAvatarVisual.ts +1 -6
- package/src/avatars/visuals/avatarVisualRegistry.ts +1 -1
- package/src/avatars/visuals/minecraft2AvatarVisual.ts +1 -2
- package/src/avatars/visuals/octopus2AvatarVisual.ts +1 -5
- package/src/avatars/visuals/octopus3AvatarVisual.ts +1 -8
- package/src/avatars/visuals/octopus3d2AvatarVisual.ts +4 -13
- package/src/avatars/visuals/octopus3d3AvatarVisual.ts +10 -15
- package/src/avatars/visuals/octopus3d4AvatarVisual.ts +18 -31
- package/src/avatars/visuals/octopus3dAvatarVisual.ts +3 -3
- package/src/avatars/visuals/octopus3dAvatarVisualShared.ts +2 -7
- package/src/book-2.0/agent-source/parseAgentSource/applyMetaCommitment.ts +2 -1
- package/src/book-2.0/book-language-documentation/createStandaloneBookLanguageMarkdown.ts +3 -5
- package/src/book-3.0/CliAgent.ts +1 -7
- package/src/book-3.0/LiteAgent.ts +5 -5
- package/src/book-components/AvatarProfile/AvatarProfile/AvatarProfile.tsx +1 -4
- package/src/book-components/BookEditor/BookEditor.tsx +2 -2
- package/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.tsx +3 -2
- package/src/book-components/BookEditor/BookEditorActionbar.tsx +1 -1
- package/src/book-components/BookEditor/BookEditorMonaco.tsx +2 -2
- package/src/book-components/BookEditor/BookEditorMonacoUploadPanel.tsx +1 -1
- package/src/book-components/BookEditor/useBookEditorMonacoLanguage.ts +1 -1
- package/src/book-components/BookEditor/useBookEditorMonacoStyles.ts +1 -1
- package/src/book-components/BookEditor/useBookEditorMonacoUploads/bookEditorMonacoUploadTypes.ts +147 -0
- package/src/book-components/BookEditor/useBookEditorMonacoUploads/clearScheduledTimer.ts +10 -0
- package/src/book-components/BookEditor/useBookEditorMonacoUploads/enqueueFilesForUpload.ts +209 -0
- package/src/book-components/BookEditor/useBookEditorMonacoUploads/useBookEditorMonacoUploadEditorSync.ts +164 -0
- package/src/book-components/BookEditor/useBookEditorMonacoUploads/useBookEditorMonacoUploadItemsState.ts +121 -0
- package/src/book-components/BookEditor/useBookEditorMonacoUploads/useBookEditorMonacoUploadProgressQueue.ts +81 -0
- package/src/book-components/BookEditor/useBookEditorMonacoUploads/useBookEditorMonacoUploadQueue.ts +360 -0
- package/src/book-components/BookEditor/useBookEditorMonacoUploads/useCompletedUploadsAutoClear.ts +47 -0
- package/src/book-components/BookEditor/useBookEditorMonacoUploads.ts +10 -1067
- package/src/book-components/Chat/Chat/Chat.module.css +199 -12
- package/src/book-components/Chat/Chat/Chat.tsx +16 -1
- package/src/book-components/Chat/Chat/ChatCitationModal.tsx +2 -2
- package/src/book-components/Chat/Chat/ChatImageAttachmentModal.tsx +108 -0
- package/src/book-components/Chat/Chat/ChatInputArea.tsx +43 -27
- package/src/book-components/Chat/Chat/ChatMessageAttachments.tsx +212 -0
- package/src/book-components/Chat/Chat/ChatMessageItem.tsx +32 -18
- package/src/book-components/Chat/Chat/ChatMessageList.tsx +3 -0
- package/src/book-components/Chat/Chat/ChatProps.tsx +9 -0
- package/src/book-components/Chat/Chat/CitationIframePreview.tsx +108 -156
- package/src/book-components/Chat/Chat/createProgressCardChecklistMarkdown.ts +1 -8
- package/src/book-components/Chat/Chat/insertDictationChunk.ts +3 -3
- package/src/book-components/Chat/Chat/learnDictationDictionary.ts +1 -1
- package/src/book-components/Chat/Chat/renderTimeoutToolCallDetails.tsx +1 -5
- package/src/book-components/Chat/Chat/useChatInputAreaComposer.ts +59 -7
- package/src/book-components/Chat/Chat/useChatInputAreaDictation.ts +140 -33
- package/src/book-components/Chat/Chat/useChatToolCallModalState.ts +1 -4
- package/src/book-components/Chat/hooks/useChatRatings.ts +1 -1
- package/src/book-components/Chat/save/html/htmlSaveFormatDefinition.ts +2 -3
- package/src/book-components/Chat/save/markdown/mdSaveFormatDefinition.ts +2 -2
- package/src/book-components/Chat/save/pdf/buildChatPdf.ts +1 -1
- package/src/book-components/Chat/utils/getToolCallChipletInfo.ts +1 -5
- package/src/book-components/Chat/utils/isVisibleChatToolCall.ts +2 -1
- package/src/book-components/Chat/utils/parseMessageButtons.ts +27 -2
- package/src/cli/cli-commands/about.ts +1 -1
- package/src/cli/cli-commands/agent/agentCliOptions.ts +2 -5
- package/src/cli/cli-commands/agent-folder/agentProjectPaths.ts +6 -12
- package/src/cli/cli-commands/agent-folder/init.ts +3 -8
- package/src/cli/cli-commands/agent-folder/initializeAgentProjectConfiguration.ts +2 -11
- package/src/cli/cli-commands/agent-folder/printAgentInitializationSummary.ts +2 -9
- package/src/cli/cli-commands/agents-server/buildAgentsServer/AGENTS_SERVER_BUILD_CACHE_FILENAME.ts +6 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/AGENTS_SERVER_BUILD_CACHE_VERSION.ts +6 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/AGENTS_SERVER_NEXT_BUILD_ID_FILENAME.ts +6 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/AgentsServerBuildCache.ts +11 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/AgentsServerBuildCacheOptions.ts +9 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/NODE_MODULES_DIRECTORY_NAME.ts +6 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/PreparedAgentsServerRuntime.ts +19 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerBuildSourceFingerprint.ts +71 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerRuntimeEnvironment.ts +69 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/ensureAgentsServerBuild.ts +59 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/getAgentsServerBuildInputRelativePaths.ts +23 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/isAgentsServerAppPath.ts +20 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/isAgentsServerAppPathMaterialized.ts +17 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/isAgentsServerBuildCacheCurrent.ts +27 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/isAgentsServerBuildInputTestFile.ts +21 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/isExcludedAgentsServerBuildInputDirectoryName.ts +22 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/isExcludedAgentsServerBuildInputPath.ts +30 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/isExcludedAgentsServerRuntimeSourcePath.ts +41 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/isFile.ts +14 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/isPathInsideNodeModules.ts +10 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/normalizeAgentsServerBuildInputPath.ts +10 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/prepareAgentsServerRuntime.ts +31 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/readAgentsServerBuildCache.ts +35 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/resolveAgentsServerAppPath.ts +33 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/resolveAgentsServerBuildAppPath.ts +30 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/resolveAgentsServerBuildOutputPath.ts +19 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/resolveNextCliPath.ts +21 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/resolveNodeModulesPath.ts +19 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/runNextBuild.ts +184 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/shouldCopyAgentsServerRuntimePath.ts +48 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/synchronizeMaterializedAgentsServerRuntime.ts +179 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer/writeAgentsServerBuildCache.ts +28 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer.ts +22 -1043
- package/src/cli/cli-commands/agents-server/ensureAgentsServerEnvFile.ts +2 -1
- package/src/cli/cli-commands/agents-server/ensureAgentsServerGitignoreFile.ts +2 -1
- package/src/cli/cli-commands/agents-server/run.ts +2 -5
- package/src/cli/cli-commands/agents-server/startAgentsServer/AgentsServerChildEnvironment.ts +67 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer/AgentsServerLogStreams.ts +43 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer/AgentsServerRuntimePaths.ts +44 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer/AgentsServerSupervisorState.ts +59 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer/LocalAgentRunnerLimits.ts +9 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer/PreparedAgentsServerLaunch.ts +14 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer/StartAgentsServerOptions.ts +26 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer/createInternalRouteErrorMessage.ts +15 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer/createLocalAgentRunOptions.ts +29 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer/forwardChildOutput.ts +32 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer/loadAgentsServerProjectEnvironment.ts +18 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer/prepareAgentsServerLaunch.ts +81 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer/readInternalRouteErrorDetails.ts +52 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer/resolveAgentsServerChildHostname.ts +17 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer/startNextServer.ts +97 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer/startUserChatJobWorkerPump.ts +132 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer/stopChildProcess.ts +14 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer/waitForLocalAgentRunnerLimits.ts +132 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer.ts +24 -797
- package/src/cli/cli-commands/agents-server.ts +2 -6
- package/src/cli/cli-commands/coder/agentCodingFile.ts +1 -7
- package/src/cli/cli-commands/coder/boilerplateTemplates.ts +14 -21
- package/src/cli/cli-commands/coder/find-refactor-candidates.ts +9 -2
- package/src/cli/cli-commands/coder/generate-boilerplates.ts +2 -6
- package/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.ts +2 -10
- package/src/cli/cli-commands/coder/run.ts +3 -27
- package/src/cli/cli-commands/coder/server.ts +4 -2
- package/src/cli/cli-commands/common/createPositiveIntegerOptionParser.ts +31 -0
- package/src/cli/cli-commands/common/promptRunnerCliOptions.ts +3 -8
- package/src/cli/cli-commands/make.ts +1 -1
- package/src/cli/cli-commands/run/runCommandAction.ts +1 -1
- package/src/cli/promptbookCli.ts +28 -3
- package/src/collection/agent-collection/CreateAgentInput.ts +2 -5
- package/src/collection/agent-collection/constructors/agent-collection-in-supabase/prepareAgentSourceForPersistence.ts +1 -1
- package/src/commitments/MEMORY/createMemoryToolFunctions.ts +1 -10
- package/src/commitments/MEMORY/getMemoryToolRuntimeAdapterOrDisabledResult.ts +1 -10
- package/src/commitments/MEMORY/parseMemoryToolArgs.ts +1 -6
- package/src/commitments/META/META.ts +4 -4
- package/src/commitments/META_AVATAR/META_AVATAR.ts +16 -10
- package/src/commitments/TEAM/TEAM.ts +5 -5
- package/src/commitments/USE_CALENDAR/createUseCalendarToolFunctions.ts +1 -4
- package/src/commitments/USE_PROJECT/createUseProjectToolFunctions.ts +2 -10
- package/src/commitments/USE_TIMEOUT/createTimeoutToolFunctions.ts +1 -11
- package/src/commitments/USE_TIMEOUT/getTimeoutToolRuntimeAdapterOrDisabledResult.ts +1 -6
- package/src/commitments/USE_TIMEOUT/parseTimeoutToolArgs.ts +1 -6
- package/src/commitments/WALLET/createWalletToolFunctions.ts +2 -11
- package/src/commitments/WALLET/getWalletToolRuntimeAdapterOrDisabledResult.ts +1 -6
- package/src/commitments/WALLET/parseWalletToolArgs.ts +1 -10
- package/src/commitments/index.ts +1 -0
- package/src/conversion/parsePipeline/applyPipelineHead.ts +1 -1
- package/src/conversion/parsePipeline/createUniqueSectionNameResolver.ts +1 -1
- package/src/conversion/parsePipeline/processPipelineSection.ts +1 -1
- package/src/conversion/validation/validatePipeline/createPipelineValidationContext.ts +43 -0
- package/src/conversion/validation/validatePipeline/validatePipelineCollectionsStructure.ts +72 -0
- package/src/conversion/validation/validatePipeline/validatePipelineDependencyResolution.ts +220 -0
- package/src/conversion/validation/validatePipeline/validatePipelineMetadata.ts +66 -0
- package/src/conversion/validation/validatePipeline/validatePipelineParameters.ts +136 -0
- package/src/conversion/validation/validatePipeline/validatePipelineTasks.ts +243 -0
- package/src/conversion/validation/validatePipeline.ts +7 -750
- package/src/execution/LlmExecutionTools.ts +1 -6
- package/src/execution/createPipelineExecutor/getReservedParametersForTask.ts +1 -5
- package/src/llm-providers/_common/register/$registeredLlmToolsMessage/RegisteredLlmToolsMessageContext.ts +51 -0
- package/src/llm-providers/_common/register/$registeredLlmToolsMessage/USED_ENV_FILENAME.ts +30 -0
- package/src/llm-providers/_common/register/$registeredLlmToolsMessage/createRegisteredLlmToolConfigurationStatusMessage.ts +62 -0
- package/src/llm-providers/_common/register/$registeredLlmToolsMessage/createRegisteredLlmToolEntryKey.ts +10 -0
- package/src/llm-providers/_common/register/$registeredLlmToolsMessage/createRegisteredLlmToolInstallationStatusMessage.ts +75 -0
- package/src/llm-providers/_common/register/$registeredLlmToolsMessage/createRegisteredLlmToolStatus.ts +101 -0
- package/src/llm-providers/_common/register/$registeredLlmToolsMessage/createRegisteredLlmToolsMessageContext.ts +24 -0
- package/src/llm-providers/_common/register/$registeredLlmToolsMessage/getAvailableRegisteredLlmToolsEnvironmentVariables.ts +17 -0
- package/src/llm-providers/_common/register/$registeredLlmToolsMessage/getRegisteredLlmToolRegisters.ts +15 -0
- package/src/llm-providers/_common/register/$registeredLlmToolsMessage/hasRegisteredLlmToolEntry.ts +19 -0
- package/src/llm-providers/_common/register/$registeredLlmToolsMessage/listRegisteredLlmToolEntries.ts +44 -0
- package/src/llm-providers/_common/register/$registeredLlmToolsMessage/listRegisteredLlmToolStatuses.ts +21 -0
- package/src/llm-providers/_common/register/$registeredLlmToolsMessage/renderAvailableRegisteredLlmTools.ts +97 -0
- package/src/llm-providers/_common/register/$registeredLlmToolsMessage/renderNoRegisteredLlmToolsMessage.ts +17 -0
- package/src/llm-providers/_common/register/$registeredLlmToolsMessage/renderRegisteredLlmToolsMessage.ts +30 -0
- package/src/llm-providers/_common/register/$registeredLlmToolsMessage/renderRelevantRegisteredLlmToolsEnvironmentVariables.ts +32 -0
- package/src/llm-providers/_common/register/$registeredLlmToolsMessage.ts +5 -568
- package/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.ts +1 -6
- package/src/llm-providers/openai/OpenAiAgentKitExecutionTools.ts +2 -2
- package/src/llm-providers/openai/OpenAiAssistantExecutionTools.ts +1 -1
- package/src/llm-providers/openai/OpenAiAssistantExecutionToolsStreamRunner.ts +2 -2
- package/src/llm-providers/openai/OpenAiAssistantExecutionToolsToolRunner.ts +1 -1
- package/src/llm-providers/openai/OpenAiCompatibleExecutionTools.ts +2 -7
- package/src/llm-providers/openai/utils/OpenAiCompatibleChatPromptBuilder.ts +1 -1
- package/src/llm-providers/openai/utils/OpenAiCompatibleChatToolCaller.ts +2 -2
- package/src/llm-providers/openai/utils/OpenAiCompatibleUnsupportedParameterRetrier.ts +1 -5
- package/src/llm-providers/openai/utils/buildToolInvocationScript.ts +1 -6
- package/src/other/templates/getTemplatesPipelineCollection.ts +871 -769
- package/src/remote-server/startRemoteServer/registerExecutionRoutes.ts +1 -1
- package/src/remote-server/startRemoteServer/registerServerIndexRoute.ts +1 -1
- package/src/scrapers/_common/utils/makeKnowledgeSourceHandler.ts +1 -6
- package/src/speech-recognition/OpenAiSpeechRecognition.ts +1 -6
- package/src/transpilers/_common/prepareSdkTranspilerContext.ts +1 -4
- package/src/types/Prompt.ts +1 -7
- package/src/types/string_host.ts +1 -9
- package/src/types/string_pipeline_url.ts +1 -4
- package/src/utils/agent-message-runtime/agentMessageRuntimePaths.ts +66 -0
- package/src/utils/agents/resolveAgentAvatarImageUrl.ts +2 -2
- package/src/utils/ascii-art/$detectTerminalAnsiColorDepth.ts +45 -0
- package/src/utils/ascii-art/convertImageDataToAsciiArt.ts +396 -0
- package/src/utils/color/Color.ts +2 -2
- package/src/utils/markdown/parseMarkdownSection.ts +1 -5
- package/src/utils/random/$randomFullnameWithColor.ts +1 -6
- package/src/version.ts +2 -2
- package/src/versions.txt +6 -0
- package/umd/apps/agents-server/src/database/migratePrefix.d.ts +19 -0
- package/umd/apps/agents-server/src/database/runDatabaseMigrations.d.ts +4 -0
- package/umd/book/scripts/import-markdown/increaseHeadings.d.ts +8 -0
- package/umd/index.umd.js +28594 -27065
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/find-refactor-candidates/find-refactor-candidates.d.ts +7 -0
- package/umd/scripts/find-refactor-candidates/selectMostImportantRefactorCandidates.d.ts +12 -0
- package/umd/scripts/run-agent-messages/main/runMultipleAgentMessages/MultipleAgentAutoPuller.d.ts +27 -0
- package/umd/scripts/run-agent-messages/main/runMultipleAgentMessages/MultipleAgentGithubSynchronizer.d.ts +26 -0
- package/umd/scripts/run-agent-messages/main/runMultipleAgentMessages/MultipleAgentRunUiPresenter.d.ts +66 -0
- package/umd/scripts/run-agent-messages/main/runMultipleAgentMessages/RunMultipleAgentMessageTaskScheduler.d.ts +67 -0
- package/umd/scripts/run-agent-messages/main/runMultipleAgentMessages/formatProjectPath.d.ts +6 -0
- package/umd/scripts/run-agent-messages/main/runMultipleAgentMessages/loadLocalAgentRunnerProjectSummaries.d.ts +11 -0
- package/umd/scripts/run-agent-messages/main/runMultipleAgentMessages/wait.d.ts +6 -0
- package/umd/scripts/run-agent-messages/main/runMultipleAgentMessages.d.ts +1 -1
- package/umd/scripts/run-codex-prompts/common/buildCoderRunProgressSnapshot.d.ts +1 -1
- package/umd/scripts/run-codex-prompts/common/cliProgressDisplay.d.ts +2 -1
- package/umd/scripts/run-codex-prompts/common/resolveCoderAgent.d.ts +20 -0
- package/umd/scripts/run-codex-prompts/runners/claude-code/ClaudeCodeRunner.d.ts +4 -0
- package/umd/scripts/run-codex-prompts/runners/claude-code/ClaudeCodeSessionResurrection.d.ts +37 -0
- package/umd/scripts/run-codex-prompts/runners/claude-code/parseClaudeCodeOutputEvents.d.ts +47 -0
- package/umd/scripts/run-codex-prompts/ui/CoderRunUiState.d.ts +8 -1
- package/umd/scripts/run-codex-prompts/ui/buildCoderRunAgentVisual.d.ts +54 -0
- package/umd/scripts/run-codex-prompts/ui/buildCoderRunUiFrame.d.ts +10 -0
- package/umd/scripts/run-codex-prompts/ui/coderRunUiRefresh.d.ts +2 -2
- package/umd/src/_packages/types.index.d.ts +2 -2
- package/umd/src/avatars/renderAvatarVisualAsciiArt.d.ts +98 -0
- package/umd/src/avatars/visuals/octopus3dAvatarVisualShared.d.ts +1 -1
- package/umd/src/book-components/BookEditor/BookEditorMonacoUploadPanel.d.ts +1 -1
- package/umd/src/book-components/BookEditor/useBookEditorMonacoUploads/bookEditorMonacoUploadTypes.d.ts +120 -0
- package/umd/src/book-components/BookEditor/useBookEditorMonacoUploads/clearScheduledTimer.d.ts +6 -0
- package/umd/src/book-components/BookEditor/useBookEditorMonacoUploads/enqueueFilesForUpload.d.ts +26 -0
- package/umd/src/book-components/BookEditor/useBookEditorMonacoUploads/useBookEditorMonacoUploadEditorSync.d.ts +23 -0
- package/umd/src/book-components/BookEditor/useBookEditorMonacoUploads/useBookEditorMonacoUploadItemsState.d.ts +21 -0
- package/umd/src/book-components/BookEditor/useBookEditorMonacoUploads/useBookEditorMonacoUploadProgressQueue.d.ts +12 -0
- package/umd/src/book-components/BookEditor/useBookEditorMonacoUploads/useBookEditorMonacoUploadQueue.d.ts +27 -0
- package/umd/src/book-components/BookEditor/useBookEditorMonacoUploads/useCompletedUploadsAutoClear.d.ts +12 -0
- package/umd/src/book-components/BookEditor/useBookEditorMonacoUploads.d.ts +5 -58
- package/umd/src/book-components/Chat/Chat/ChatImageAttachmentModal.d.ts +25 -0
- package/umd/src/book-components/Chat/Chat/ChatInputArea.d.ts +3 -0
- package/umd/src/book-components/Chat/Chat/ChatMessageAttachments.d.ts +27 -0
- package/umd/src/book-components/Chat/Chat/ChatMessageItem.d.ts +1 -1
- package/umd/src/book-components/Chat/Chat/ChatMessageList.d.ts +1 -0
- package/umd/src/book-components/Chat/Chat/ChatProps.d.ts +8 -0
- package/umd/src/book-components/Chat/Chat/CitationIframePreview.d.ts +1 -1
- package/umd/src/book-components/Chat/Chat/CitationIframePreview.test.d.ts +2 -0
- package/umd/src/book-components/Chat/Chat/insertDictationChunk.d.ts +1 -1
- package/umd/src/book-components/Chat/Chat/insertDictationChunk.test.d.ts +1 -0
- package/umd/src/book-components/Chat/Chat/learnDictationDictionary.test.d.ts +1 -0
- package/umd/src/book-components/Chat/Chat/refineFinalDictationChunk.test.d.ts +1 -0
- package/umd/src/book-components/Chat/Chat/useChatInputAreaComposer.d.ts +12 -0
- package/umd/src/book-components/Chat/Chat/useChatInputAreaComposer.draftMessage.test.d.ts +2 -0
- package/umd/src/book-components/Chat/utils/isVisibleChatToolCall.d.ts +1 -1
- package/umd/src/book-components/Chat/utils/parseMessageButtons.d.ts +16 -2
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/AGENTS_SERVER_BUILD_CACHE_FILENAME.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/AGENTS_SERVER_BUILD_CACHE_VERSION.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/AGENTS_SERVER_NEXT_BUILD_ID_FILENAME.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/AgentsServerBuildCache.d.ts +10 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/AgentsServerBuildCacheOptions.d.ts +10 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/NODE_MODULES_DIRECTORY_NAME.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/PreparedAgentsServerRuntime.d.ts +18 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerBuildSourceFingerprint.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerRuntimeEnvironment.d.ts +28 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/ensureAgentsServerBuild.d.ts +19 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/getAgentsServerBuildInputRelativePaths.d.ts +11 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/isAgentsServerAppPath.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/isAgentsServerAppPathMaterialized.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/isAgentsServerBuildCacheCurrent.d.ts +7 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/isAgentsServerBuildInputTestFile.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/isExcludedAgentsServerBuildInputDirectoryName.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/isExcludedAgentsServerBuildInputPath.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/isExcludedAgentsServerRuntimeSourcePath.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/isFile.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/isPathInsideNodeModules.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/normalizeAgentsServerBuildInputPath.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/prepareAgentsServerRuntime.d.ts +9 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/readAgentsServerBuildCache.d.ts +8 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/resolveAgentsServerAppPath.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/resolveAgentsServerBuildAppPath.d.ts +9 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/resolveAgentsServerBuildOutputPath.d.ts +7 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/resolveNextCliPath.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/resolveNodeModulesPath.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/runNextBuild.d.ts +12 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/shouldCopyAgentsServerRuntimePath.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/synchronizeMaterializedAgentsServerRuntime.d.ts +11 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/writeAgentsServerBuildCache.d.ts +7 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer.d.ts +8 -109
- package/umd/src/cli/cli-commands/agents-server/ensureAgentsServerEnvFile.d.ts +1 -1
- package/umd/src/cli/cli-commands/agents-server/ensureAgentsServerGitignoreFile.d.ts +1 -1
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer/AgentsServerChildEnvironment.d.ts +16 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer/AgentsServerLogStreams.d.ts +30 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer/AgentsServerRuntimePaths.d.ts +19 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer/AgentsServerSupervisorState.d.ts +37 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer/LocalAgentRunnerLimits.d.ts +9 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer/PreparedAgentsServerLaunch.d.ts +13 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer/StartAgentsServerOptions.d.ts +24 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer/createInternalRouteErrorMessage.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer/createLocalAgentRunOptions.d.ts +9 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer/forwardChildOutput.d.ts +13 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer/loadAgentsServerProjectEnvironment.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer/prepareAgentsServerLaunch.d.ts +18 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer/readInternalRouteErrorDetails.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer/resolveAgentsServerChildHostname.d.ts +7 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer/startNextServer.d.ts +20 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer/startUserChatJobWorkerPump.d.ts +15 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer/stopChildProcess.d.ts +8 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer/waitForLocalAgentRunnerLimits.d.ts +16 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +3 -30
- package/umd/src/cli/cli-commands/common/createPositiveIntegerOptionParser.d.ts +10 -0
- package/umd/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +1 -1
- package/umd/src/collection/agent-collection/CreateAgentInput.d.ts +1 -1
- package/umd/src/collection/agent-collection/constructors/agent-collection-in-supabase/prepareAgentSourceForPersistence.d.ts +1 -1
- package/umd/src/commitments/META/META.d.ts +2 -2
- package/umd/src/commitments/META_AVATAR/META_AVATAR.d.ts +9 -4
- package/umd/src/commitments/index.d.ts +1 -1
- package/umd/src/conversion/validation/validatePipeline/createPipelineValidationContext.d.ts +16 -0
- package/umd/src/conversion/validation/validatePipeline/validatePipelineCollectionsStructure.d.ts +7 -0
- package/umd/src/conversion/validation/validatePipeline/validatePipelineDependencyResolution.d.ts +7 -0
- package/umd/src/conversion/validation/validatePipeline/validatePipelineMetadata.d.ts +7 -0
- package/umd/src/conversion/validation/validatePipeline/validatePipelineParameters.d.ts +7 -0
- package/umd/src/conversion/validation/validatePipeline/validatePipelineTasks.d.ts +7 -0
- package/umd/src/llm-providers/_common/register/$registeredLlmToolsMessage/RegisteredLlmToolsMessageContext.d.ts +46 -0
- package/umd/src/llm-providers/_common/register/$registeredLlmToolsMessage/USED_ENV_FILENAME.d.ts +11 -0
- package/umd/src/llm-providers/_common/register/$registeredLlmToolsMessage/createRegisteredLlmToolConfigurationStatusMessage.d.ts +7 -0
- package/umd/src/llm-providers/_common/register/$registeredLlmToolsMessage/createRegisteredLlmToolEntryKey.d.ts +7 -0
- package/umd/src/llm-providers/_common/register/$registeredLlmToolsMessage/createRegisteredLlmToolInstallationStatusMessage.d.ts +7 -0
- package/umd/src/llm-providers/_common/register/$registeredLlmToolsMessage/createRegisteredLlmToolStatus.d.ts +14 -0
- package/umd/src/llm-providers/_common/register/$registeredLlmToolsMessage/createRegisteredLlmToolsMessageContext.d.ts +7 -0
- package/umd/src/llm-providers/_common/register/$registeredLlmToolsMessage/getAvailableRegisteredLlmToolsEnvironmentVariables.d.ts +7 -0
- package/umd/src/llm-providers/_common/register/$registeredLlmToolsMessage/getRegisteredLlmToolRegisters.d.ts +7 -0
- package/umd/src/llm-providers/_common/register/$registeredLlmToolsMessage/hasRegisteredLlmToolEntry.d.ts +7 -0
- package/umd/src/llm-providers/_common/register/$registeredLlmToolsMessage/listRegisteredLlmToolEntries.d.ts +9 -0
- package/umd/src/llm-providers/_common/register/$registeredLlmToolsMessage/listRegisteredLlmToolStatuses.d.ts +7 -0
- package/umd/src/llm-providers/_common/register/$registeredLlmToolsMessage/renderAvailableRegisteredLlmTools.d.ts +7 -0
- package/umd/src/llm-providers/_common/register/$registeredLlmToolsMessage/renderNoRegisteredLlmToolsMessage.d.ts +7 -0
- package/umd/src/llm-providers/_common/register/$registeredLlmToolsMessage/renderRegisteredLlmToolsMessage.d.ts +8 -0
- package/umd/src/llm-providers/_common/register/$registeredLlmToolsMessage/renderRelevantRegisteredLlmToolsEnvironmentVariables.d.ts +7 -0
- package/umd/src/utils/agent-message-runtime/agentMessageRuntimePaths.d.ts +24 -0
- package/umd/src/utils/agents/resolveAgentAvatarImageUrl.d.ts +2 -2
- package/umd/src/utils/ascii-art/$detectTerminalAnsiColorDepth.d.ts +15 -0
- package/umd/src/utils/ascii-art/convertImageDataToAsciiArt.d.ts +80 -0
- package/umd/src/utils/color/Color.d.ts +1 -1
- package/umd/src/version.d.ts +1 -1
- package/apps/agents-server/src/app/api/page-preview/interact/route.ts +0 -179
- package/apps/agents-server/src/app/api/page-preview/live/route.ts +0 -67
- package/apps/agents-server/src/utils/pagePreview/livePagePreviewSessions.ts +0 -365
- package/apps/agents-server/src/utils/pagePreview/resolvePagePreviewRequestUrl.ts +0 -74
- package/apps/agents-server/src/utils/userChat/createUserChatRunnerProgressCard.ts +0 -57
- package/esm/scripts/run-codex-prompts/common/resolveAgentSystemMessage.d.ts +0 -6
- package/esm/src/book-components/Chat/utils/livePagePreviewConstants.d.ts +0 -12
- package/src/book-components/Chat/utils/livePagePreviewConstants.ts +0 -17
- package/umd/scripts/run-codex-prompts/common/resolveAgentSystemMessage.d.ts +0 -6
- package/umd/src/book-components/Chat/utils/livePagePreviewConstants.d.ts +0 -12
|
@@ -1,209 +1,11 @@
|
|
|
1
1
|
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
-
import type { TODO_any } from '@promptbook-local/types';
|
|
3
2
|
import {
|
|
4
3
|
$provideAgentsServerSqliteDatabase,
|
|
5
4
|
$resetAgentsServerSqliteDatabaseForTests,
|
|
6
|
-
type AgentsServerSqliteDatabase,
|
|
7
5
|
} from './$provideAgentsServerSqliteDatabase';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
type LocalSqliteQueryResult<TData = TODO_any> = {
|
|
13
|
-
readonly data: TData | null;
|
|
14
|
-
readonly error: LocalSqliteError | null;
|
|
15
|
-
readonly count?: number | null;
|
|
16
|
-
readonly status?: number;
|
|
17
|
-
readonly statusText?: string;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Supabase-like error shape returned by the local SQLite adapter.
|
|
22
|
-
*/
|
|
23
|
-
type LocalSqliteError = {
|
|
24
|
-
readonly code?: string;
|
|
25
|
-
readonly message: string;
|
|
26
|
-
readonly details?: string;
|
|
27
|
-
readonly hint?: string;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Supported query operation kinds.
|
|
32
|
-
*/
|
|
33
|
-
type LocalSqliteOperation = 'select' | 'insert' | 'update' | 'delete' | 'upsert';
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Query filter captured from Supabase-like fluent calls.
|
|
37
|
-
*/
|
|
38
|
-
type LocalSqliteFilter = {
|
|
39
|
-
readonly column: string;
|
|
40
|
-
readonly operator: 'eq' | 'neq' | 'is' | 'not-is' | 'in' | 'lt' | 'lte' | 'gt' | 'gte' | 'like' | 'ilike';
|
|
41
|
-
readonly value: unknown;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Query order captured from Supabase-like fluent calls.
|
|
46
|
-
*/
|
|
47
|
-
type LocalSqliteOrder = {
|
|
48
|
-
readonly column: string;
|
|
49
|
-
readonly ascending: boolean;
|
|
50
|
-
readonly nullsFirst?: boolean;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Select options supported by Supabase and used by this app.
|
|
55
|
-
*/
|
|
56
|
-
type LocalSqliteSelectOptions = {
|
|
57
|
-
readonly count?: 'exact';
|
|
58
|
-
readonly head?: boolean;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Upsert options supported by Supabase and used by this app.
|
|
63
|
-
*/
|
|
64
|
-
type LocalSqliteUpsertOptions = {
|
|
65
|
-
readonly onConflict?: string;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Read index definition for hot SQLite queries.
|
|
70
|
-
*/
|
|
71
|
-
type LocalSqliteReadIndex = {
|
|
72
|
-
readonly name: string;
|
|
73
|
-
readonly columns: ReadonlyArray<string>;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Columns whose values are persisted as JSON text in local SQLite.
|
|
78
|
-
*/
|
|
79
|
-
const JSON_COLUMNS_BY_TABLE = new Map<string, ReadonlySet<string>>([
|
|
80
|
-
['Agent', new Set(['agentProfile', 'usage', 'preparedModelRequirements', 'preparedExternals'])],
|
|
81
|
-
['AgentHistory', new Set([])],
|
|
82
|
-
['ChatHistory', new Set(['message', 'usage'])],
|
|
83
|
-
['LlmCache', new Set(['value'])],
|
|
84
|
-
['VectorStoreKnowledgeSourceHashes', new Set([])],
|
|
85
|
-
['Image', new Set([])],
|
|
86
|
-
['File', new Set(['securityResult'])],
|
|
87
|
-
['Message', new Set(['sender', 'recipients', 'metadata'])],
|
|
88
|
-
['MessageSendAttempt', new Set(['raw'])],
|
|
89
|
-
['UserChat', new Set(['messages'])],
|
|
90
|
-
['UserChatJob', new Set(['parameters'])],
|
|
91
|
-
['UserChatTimeout', new Set(['parameters'])],
|
|
92
|
-
['UserData', new Set(['value'])],
|
|
93
|
-
['Wallet', new Set(['jsonSchema'])],
|
|
94
|
-
['ShareTargetPayload', new Set(['attachments'])],
|
|
95
|
-
['CalendarConnection', new Set(['scopes'])],
|
|
96
|
-
['CalendarActivity', new Set(['details'])],
|
|
97
|
-
['ShibbolethUserIdentity', new Set(['rawAttributes'])],
|
|
98
|
-
['ShibbolethAuthenticationAttempt', new Set(['rawAttributes'])],
|
|
99
|
-
]);
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Columns that must always be surfaced as strings even when an older SQLite
|
|
103
|
-
* table was created with numeric affinity.
|
|
104
|
-
*/
|
|
105
|
-
const TEXT_COLUMNS_BY_TABLE = new Map<string, ReadonlySet<string>>([['Metadata', new Set(['key', 'value', 'note'])]]);
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Table-specific integer columns whose names would otherwise be ambiguous.
|
|
109
|
-
*/
|
|
110
|
-
const INTEGER_COLUMNS_BY_TABLE = new Map<string, ReadonlySet<string>>([['ServerLimit', new Set(['value'])]]);
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Boolean columns stored as integers by SQLite and restored as booleans.
|
|
114
|
-
*/
|
|
115
|
-
const BOOLEAN_COLUMNS = new Set(['isAdmin', 'isRevoked', 'isGlobal', 'isUserScoped', 'isSuccessful', 'isChatFocused']);
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Tables whose primary key is provided as text rather than generated numerically.
|
|
119
|
-
*/
|
|
120
|
-
const TEXT_PRIMARY_KEY_TABLES = new Set([
|
|
121
|
-
'UserChat',
|
|
122
|
-
'UserChatJob',
|
|
123
|
-
'UserChatTimeout',
|
|
124
|
-
'UserPushSubscription',
|
|
125
|
-
'ShareTargetPayload',
|
|
126
|
-
]);
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Unique constraints required by common Supabase upsert and duplicate-detection flows.
|
|
130
|
-
*/
|
|
131
|
-
const UNIQUE_INDEX_COLUMNS_BY_TABLE = new Map<string, ReadonlyArray<ReadonlyArray<string>>>([
|
|
132
|
-
['_Server', [['name'], ['domain']]],
|
|
133
|
-
['Metadata', [['key']]],
|
|
134
|
-
['ServerLimit', [['key']]],
|
|
135
|
-
['Agent', [['permanentId']]],
|
|
136
|
-
['AgentExternals', [['type', 'hash']]],
|
|
137
|
-
['VectorStoreKnowledgeSourceHashes', [['source']]],
|
|
138
|
-
['User', [['username']]],
|
|
139
|
-
['ShibbolethUserIdentity', [['userId'], ['email'], ['nameId']]],
|
|
140
|
-
['UserChatJob', [['chatId', 'clientMessageId']]],
|
|
141
|
-
['LlmCache', [['hash']]],
|
|
142
|
-
['OpenAiAssistantCache', [['agentHash']]],
|
|
143
|
-
['ApiTokens', [['token']]],
|
|
144
|
-
['GenerationLock', [['lockKey']]],
|
|
145
|
-
['CustomStylesheet', [['scope']]],
|
|
146
|
-
['CustomJavascript', [['scope']]],
|
|
147
|
-
['Wallet', [['userId', 'agentPermanentId', 'service', 'key']]],
|
|
148
|
-
['UserData', [['userId', 'key']]],
|
|
149
|
-
['UserPushSubscription', [['endpoint']]],
|
|
150
|
-
]);
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Non-unique indexes for frequent standalone VPS reads.
|
|
154
|
-
*/
|
|
155
|
-
const READ_INDEXES_BY_TABLE = new Map<string, ReadonlyArray<LocalSqliteReadIndex>>([
|
|
156
|
-
[
|
|
157
|
-
'Agent',
|
|
158
|
-
[
|
|
159
|
-
{ name: 'agentName_lookup', columns: ['agentName'] },
|
|
160
|
-
{ name: 'active_directory', columns: ['deletedAt', 'sortOrder', 'agentName'] },
|
|
161
|
-
{ name: 'public_active_directory', columns: ['visibility', 'deletedAt', 'sortOrder', 'agentName'] },
|
|
162
|
-
],
|
|
163
|
-
],
|
|
164
|
-
[
|
|
165
|
-
'AgentFolder',
|
|
166
|
-
[{ name: 'active_directory', columns: ['deletedAt', 'parentId', 'sortOrder', 'name'] }],
|
|
167
|
-
],
|
|
168
|
-
[
|
|
169
|
-
'UserChat',
|
|
170
|
-
[
|
|
171
|
-
{ name: 'user_agent_source_createdAt', columns: ['userId', 'agentPermanentId', 'source', 'createdAt'] },
|
|
172
|
-
{ name: 'agent_source_user_createdAt', columns: ['agentPermanentId', 'source', 'userId', 'createdAt'] },
|
|
173
|
-
],
|
|
174
|
-
],
|
|
175
|
-
[
|
|
176
|
-
'UserChatJob',
|
|
177
|
-
[
|
|
178
|
-
{ name: 'ready_queue', columns: ['status', 'cancelRequestedAt', 'queuedAt', 'createdAt'] },
|
|
179
|
-
{ name: 'active_chat_scope', columns: ['chatId', 'userId', 'agentPermanentId', 'status', 'createdAt'] },
|
|
180
|
-
{ name: 'agent_chat_status', columns: ['agentPermanentId', 'chatId', 'status'] },
|
|
181
|
-
{ name: 'running_lease', columns: ['status', 'leaseExpiresAt'] },
|
|
182
|
-
],
|
|
183
|
-
],
|
|
184
|
-
[
|
|
185
|
-
'UserChatTimeout',
|
|
186
|
-
[
|
|
187
|
-
{ name: 'ready_due', columns: ['status', 'cancelRequestedAt', 'pausedAt', 'dueAt', 'createdAt'] },
|
|
188
|
-
{
|
|
189
|
-
name: 'active_chat_scope',
|
|
190
|
-
columns: ['chatId', 'userId', 'agentPermanentId', 'status', 'pausedAt', 'dueAt', 'createdAt'],
|
|
191
|
-
},
|
|
192
|
-
{ name: 'running_lease', columns: ['status', 'leaseExpiresAt'] },
|
|
193
|
-
],
|
|
194
|
-
],
|
|
195
|
-
]);
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Known unique conflict columns used when `.upsert` omits `onConflict`.
|
|
199
|
-
*/
|
|
200
|
-
const DEFAULT_UPSERT_CONFLICT_COLUMNS_BY_TABLE = new Map<string, ReadonlyArray<string>>([
|
|
201
|
-
['AgentExternals', ['type', 'hash']],
|
|
202
|
-
['LlmCache', ['hash']],
|
|
203
|
-
['VectorStoreKnowledgeSourceHashes', ['source']],
|
|
204
|
-
['Metadata', ['key']],
|
|
205
|
-
['ServerLimit', ['key']],
|
|
206
|
-
]);
|
|
6
|
+
import { ensureTable } from './localSqliteSupabase/ensureTable';
|
|
7
|
+
import { resolveReadIndexColumns, resolveTableBaseName } from './localSqliteSupabase/localSqliteTableSchema';
|
|
8
|
+
import { LocalSqliteSupabaseClient } from './localSqliteSupabase/LocalSqliteSupabaseClient';
|
|
207
9
|
|
|
208
10
|
/**
|
|
209
11
|
* Cached Supabase-shaped local client.
|
|
@@ -245,1343 +47,3 @@ export function ensureLocalSqliteTableReadIndexes(tableName: string): void {
|
|
|
245
47
|
|
|
246
48
|
ensureTable(database, tableName, resolveReadIndexColumns(tableBaseName));
|
|
247
49
|
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Supabase-shaped client with only the table query surface used by Agents Server.
|
|
251
|
-
*/
|
|
252
|
-
class LocalSqliteSupabaseClient {
|
|
253
|
-
public constructor(private readonly database: AgentsServerSqliteDatabase) {}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Starts a query for one SQLite table.
|
|
257
|
-
*/
|
|
258
|
-
public from(tableName: string): LocalSqliteTable {
|
|
259
|
-
return new LocalSqliteTable(this.database, tableName);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Supabase-shaped table entry point. Every operation starts a fresh query builder.
|
|
265
|
-
*/
|
|
266
|
-
class LocalSqliteTable {
|
|
267
|
-
public constructor(private readonly database: AgentsServerSqliteDatabase, private readonly tableName: string) {}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Starts a select query.
|
|
271
|
-
*/
|
|
272
|
-
public select(columns = '*', options?: LocalSqliteSelectOptions): LocalSqliteQueryBuilder {
|
|
273
|
-
return new LocalSqliteQueryBuilder(this.database, this.tableName).select(columns, options);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Starts an insert query.
|
|
278
|
-
*/
|
|
279
|
-
public insert(values: TODO_any): LocalSqliteQueryBuilder {
|
|
280
|
-
return new LocalSqliteQueryBuilder(this.database, this.tableName).insert(values);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Starts an update query.
|
|
285
|
-
*/
|
|
286
|
-
public update(values: Record<string, unknown>): LocalSqliteQueryBuilder {
|
|
287
|
-
return new LocalSqliteQueryBuilder(this.database, this.tableName).update(values);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Starts a delete query.
|
|
292
|
-
*/
|
|
293
|
-
public delete(): LocalSqliteQueryBuilder {
|
|
294
|
-
return new LocalSqliteQueryBuilder(this.database, this.tableName).delete();
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Starts an upsert query.
|
|
299
|
-
*/
|
|
300
|
-
public upsert(values: TODO_any, options?: LocalSqliteUpsertOptions): LocalSqliteQueryBuilder {
|
|
301
|
-
return new LocalSqliteQueryBuilder(this.database, this.tableName).upsert(values, options);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Supabase-shaped thenable query builder executed by `await`.
|
|
307
|
-
*/
|
|
308
|
-
class LocalSqliteQueryBuilder implements PromiseLike<LocalSqliteQueryResult> {
|
|
309
|
-
private operation: LocalSqliteOperation = 'select';
|
|
310
|
-
private selectedColumns = '*';
|
|
311
|
-
private selectOptions: LocalSqliteSelectOptions = {};
|
|
312
|
-
private filters: Array<LocalSqliteFilter> = [];
|
|
313
|
-
private orFilters: Array<string> = [];
|
|
314
|
-
private orders: Array<LocalSqliteOrder> = [];
|
|
315
|
-
private limitCount: number | null = null;
|
|
316
|
-
private offsetCount: number | null = null;
|
|
317
|
-
private singleMode: 'single' | 'maybeSingle' | null = null;
|
|
318
|
-
private mutationRows: Array<Record<string, unknown>> = [];
|
|
319
|
-
private mutationValues: Record<string, unknown> = {};
|
|
320
|
-
private upsertOptions: LocalSqliteUpsertOptions = {};
|
|
321
|
-
private signal: AbortSignal | null = null;
|
|
322
|
-
private isReturningSelection = false;
|
|
323
|
-
|
|
324
|
-
public constructor(private readonly database: AgentsServerSqliteDatabase, private readonly tableName: string) {}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* Configures selected columns or mutation return columns.
|
|
328
|
-
*/
|
|
329
|
-
public select(columns = '*', options: LocalSqliteSelectOptions = {}): this {
|
|
330
|
-
if (this.operation !== 'select') {
|
|
331
|
-
this.isReturningSelection = true;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
this.selectedColumns = columns || '*';
|
|
335
|
-
this.selectOptions = options;
|
|
336
|
-
return this;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* Configures inserted rows.
|
|
341
|
-
*/
|
|
342
|
-
public insert(values: TODO_any): this {
|
|
343
|
-
this.operation = 'insert';
|
|
344
|
-
this.mutationRows = normalizeMutationRows(values);
|
|
345
|
-
return this;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Configures updated values.
|
|
350
|
-
*/
|
|
351
|
-
public update(values: Record<string, unknown>): this {
|
|
352
|
-
this.operation = 'update';
|
|
353
|
-
this.mutationValues = stripUndefinedValues(values);
|
|
354
|
-
return this;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Configures row deletion.
|
|
359
|
-
*/
|
|
360
|
-
public delete(): this {
|
|
361
|
-
this.operation = 'delete';
|
|
362
|
-
return this;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* Configures inserted-or-updated rows.
|
|
367
|
-
*/
|
|
368
|
-
public upsert(values: TODO_any, options: LocalSqliteUpsertOptions = {}): this {
|
|
369
|
-
this.operation = 'upsert';
|
|
370
|
-
this.mutationRows = normalizeMutationRows(values);
|
|
371
|
-
this.upsertOptions = options;
|
|
372
|
-
return this;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Adds equality filter.
|
|
377
|
-
*/
|
|
378
|
-
public eq(column: string, value: unknown): this {
|
|
379
|
-
this.filters.push({ column, operator: 'eq', value });
|
|
380
|
-
return this;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* Adds inequality filter.
|
|
385
|
-
*/
|
|
386
|
-
public neq(column: string, value: unknown): this {
|
|
387
|
-
this.filters.push({ column, operator: 'neq', value });
|
|
388
|
-
return this;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* Adds nullability filter.
|
|
393
|
-
*/
|
|
394
|
-
public is(column: string, value: unknown): this {
|
|
395
|
-
this.filters.push({ column, operator: 'is', value });
|
|
396
|
-
return this;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Adds negative filter for supported operators.
|
|
401
|
-
*/
|
|
402
|
-
public not(column: string, operator: string, value: unknown): this {
|
|
403
|
-
if (operator === 'is') {
|
|
404
|
-
this.filters.push({ column, operator: 'not-is', value });
|
|
405
|
-
} else if (operator === 'eq') {
|
|
406
|
-
this.filters.push({ column, operator: 'neq', value });
|
|
407
|
-
}
|
|
408
|
-
return this;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Adds `IN` filter.
|
|
413
|
-
*/
|
|
414
|
-
public in(column: string, value: ReadonlyArray<unknown>): this {
|
|
415
|
-
this.filters.push({ column, operator: 'in', value });
|
|
416
|
-
return this;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* Adds less-than filter.
|
|
421
|
-
*/
|
|
422
|
-
public lt(column: string, value: unknown): this {
|
|
423
|
-
this.filters.push({ column, operator: 'lt', value });
|
|
424
|
-
return this;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
/**
|
|
428
|
-
* Adds less-than-or-equal filter.
|
|
429
|
-
*/
|
|
430
|
-
public lte(column: string, value: unknown): this {
|
|
431
|
-
this.filters.push({ column, operator: 'lte', value });
|
|
432
|
-
return this;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
/**
|
|
436
|
-
* Adds greater-than filter.
|
|
437
|
-
*/
|
|
438
|
-
public gt(column: string, value: unknown): this {
|
|
439
|
-
this.filters.push({ column, operator: 'gt', value });
|
|
440
|
-
return this;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
/**
|
|
444
|
-
* Adds greater-than-or-equal filter.
|
|
445
|
-
*/
|
|
446
|
-
public gte(column: string, value: unknown): this {
|
|
447
|
-
this.filters.push({ column, operator: 'gte', value });
|
|
448
|
-
return this;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* Adds SQL LIKE filter.
|
|
453
|
-
*/
|
|
454
|
-
public like(column: string, value: string): this {
|
|
455
|
-
this.filters.push({ column, operator: 'like', value });
|
|
456
|
-
return this;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* Adds case-insensitive LIKE filter.
|
|
461
|
-
*/
|
|
462
|
-
public ilike(column: string, value: string): this {
|
|
463
|
-
this.filters.push({ column, operator: 'ilike', value });
|
|
464
|
-
return this;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
/**
|
|
468
|
-
* Adds an OR filter in the PostgREST format used by Supabase.
|
|
469
|
-
*/
|
|
470
|
-
public or(filter: string): this {
|
|
471
|
-
this.orFilters.push(filter);
|
|
472
|
-
return this;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* Adds ordering.
|
|
477
|
-
*/
|
|
478
|
-
public order(column: string, options: { ascending?: boolean; nullsFirst?: boolean } = {}): this {
|
|
479
|
-
this.orders.push({
|
|
480
|
-
column,
|
|
481
|
-
ascending: options.ascending !== false,
|
|
482
|
-
nullsFirst: options.nullsFirst,
|
|
483
|
-
});
|
|
484
|
-
return this;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
/**
|
|
488
|
-
* Adds a limit.
|
|
489
|
-
*/
|
|
490
|
-
public limit(count: number): this {
|
|
491
|
-
this.limitCount = count;
|
|
492
|
-
return this;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* Adds inclusive range pagination.
|
|
497
|
-
*/
|
|
498
|
-
public range(from: number, to: number): this {
|
|
499
|
-
this.offsetCount = from;
|
|
500
|
-
this.limitCount = Math.max(0, to - from + 1);
|
|
501
|
-
return this;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
/**
|
|
505
|
-
* Marks the query as requiring exactly one row.
|
|
506
|
-
*/
|
|
507
|
-
public single(): Promise<LocalSqliteQueryResult> {
|
|
508
|
-
this.singleMode = 'single';
|
|
509
|
-
return this.execute();
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* Marks the query as requiring at most one row.
|
|
514
|
-
*/
|
|
515
|
-
public maybeSingle(): Promise<LocalSqliteQueryResult> {
|
|
516
|
-
this.singleMode = 'maybeSingle';
|
|
517
|
-
return this.execute();
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
/**
|
|
521
|
-
* Accepts an abort signal for API compatibility.
|
|
522
|
-
*/
|
|
523
|
-
public abortSignal(signal: AbortSignal): this {
|
|
524
|
-
this.signal = signal;
|
|
525
|
-
return this;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
/**
|
|
529
|
-
* Makes the query builder awaitable.
|
|
530
|
-
*/
|
|
531
|
-
public then<TResult1 = LocalSqliteQueryResult, TResult2 = never>(
|
|
532
|
-
onfulfilled?: ((value: LocalSqliteQueryResult) => TResult1 | PromiseLike<TResult1>) | null,
|
|
533
|
-
onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null,
|
|
534
|
-
): Promise<TResult1 | TResult2> {
|
|
535
|
-
return this.execute().then(onfulfilled, onrejected);
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
* Executes the configured query.
|
|
540
|
-
*/
|
|
541
|
-
private async execute(): Promise<LocalSqliteQueryResult> {
|
|
542
|
-
try {
|
|
543
|
-
if (this.signal?.aborted) {
|
|
544
|
-
throw new Error('The operation was aborted.');
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
switch (this.operation) {
|
|
548
|
-
case 'insert':
|
|
549
|
-
return this.executeInsert();
|
|
550
|
-
case 'update':
|
|
551
|
-
return this.executeUpdate();
|
|
552
|
-
case 'delete':
|
|
553
|
-
return this.executeDelete();
|
|
554
|
-
case 'upsert':
|
|
555
|
-
return this.executeUpsert();
|
|
556
|
-
case 'select':
|
|
557
|
-
default:
|
|
558
|
-
return this.executeSelect();
|
|
559
|
-
}
|
|
560
|
-
} catch (error) {
|
|
561
|
-
return {
|
|
562
|
-
data: null,
|
|
563
|
-
error: normalizeSqliteError(error),
|
|
564
|
-
status: 400,
|
|
565
|
-
statusText: 'Bad Request',
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
/**
|
|
571
|
-
* Executes a select query.
|
|
572
|
-
*/
|
|
573
|
-
private executeSelect(): LocalSqliteQueryResult {
|
|
574
|
-
const selectedColumns = parseSelectedColumns(this.selectedColumns);
|
|
575
|
-
const requiredColumns = [
|
|
576
|
-
...selectedColumns,
|
|
577
|
-
...this.filters.map((filter) => filter.column),
|
|
578
|
-
...this.orders.map((order) => order.column),
|
|
579
|
-
...this.extractOrFilterColumns(),
|
|
580
|
-
];
|
|
581
|
-
ensureTable(this.database, this.tableName, requiredColumns);
|
|
582
|
-
|
|
583
|
-
const where = this.createWhereClause();
|
|
584
|
-
const orderBy = this.createOrderByClause();
|
|
585
|
-
const limit = this.createLimitClause();
|
|
586
|
-
const count = this.selectOptions.count === 'exact' ? this.executeCount(where) : null;
|
|
587
|
-
|
|
588
|
-
if (this.selectOptions.head) {
|
|
589
|
-
return {
|
|
590
|
-
data: null,
|
|
591
|
-
error: null,
|
|
592
|
-
count,
|
|
593
|
-
status: 200,
|
|
594
|
-
statusText: 'OK',
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
const sql = [
|
|
599
|
-
`SELECT ${createSelectExpression(selectedColumns)} FROM ${quoteIdentifier(this.tableName)}`,
|
|
600
|
-
where.sql,
|
|
601
|
-
orderBy,
|
|
602
|
-
limit.sql,
|
|
603
|
-
]
|
|
604
|
-
.filter(Boolean)
|
|
605
|
-
.join(' ');
|
|
606
|
-
const rows = this.database.prepare(sql).all(...where.values, ...limit.values);
|
|
607
|
-
const data = rows.map((row) => deserializeRow(this.tableName, row));
|
|
608
|
-
|
|
609
|
-
return this.finalizeDataResponse(data, count);
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
/**
|
|
613
|
-
* Executes an insert query.
|
|
614
|
-
*/
|
|
615
|
-
private executeInsert(): LocalSqliteQueryResult {
|
|
616
|
-
const insertedRowids: Array<number | bigint> = [];
|
|
617
|
-
|
|
618
|
-
for (const rawRow of this.mutationRows) {
|
|
619
|
-
const row = withInsertDefaults(resolveTableBaseName(this.tableName), rawRow);
|
|
620
|
-
ensureTable(this.database, this.tableName, Object.keys(row));
|
|
621
|
-
insertedRowids.push(insertRow(this.database, this.tableName, row).lastInsertRowid);
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
return this.createMutationResponse(insertedRowids);
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
/**
|
|
628
|
-
* Executes an update query.
|
|
629
|
-
*/
|
|
630
|
-
private executeUpdate(): LocalSqliteQueryResult {
|
|
631
|
-
const updateColumns = Object.keys(this.mutationValues);
|
|
632
|
-
ensureTable(this.database, this.tableName, [
|
|
633
|
-
...updateColumns,
|
|
634
|
-
...this.filters.map((filter) => filter.column),
|
|
635
|
-
...this.extractOrFilterColumns(),
|
|
636
|
-
]);
|
|
637
|
-
|
|
638
|
-
const rowids = this.selectMatchingRowids();
|
|
639
|
-
|
|
640
|
-
if (rowids.length > 0 && updateColumns.length > 0) {
|
|
641
|
-
const assignments = updateColumns.map((column) => `${quoteIdentifier(column)} = ?`).join(', ');
|
|
642
|
-
const values = updateColumns.map((column) =>
|
|
643
|
-
serializeValue(this.tableName, column, this.mutationValues[column]),
|
|
644
|
-
);
|
|
645
|
-
const rowidPlaceholders = rowids.map(() => '?').join(', ');
|
|
646
|
-
this.database
|
|
647
|
-
.prepare(
|
|
648
|
-
`UPDATE ${quoteIdentifier(
|
|
649
|
-
this.tableName,
|
|
650
|
-
)} SET ${assignments} WHERE rowid IN (${rowidPlaceholders})`,
|
|
651
|
-
)
|
|
652
|
-
.run(...values, ...rowids);
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
return this.createMutationResponse(rowids);
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
/**
|
|
659
|
-
* Executes a delete query.
|
|
660
|
-
*/
|
|
661
|
-
private executeDelete(): LocalSqliteQueryResult {
|
|
662
|
-
ensureTable(this.database, this.tableName, [
|
|
663
|
-
...this.filters.map((filter) => filter.column),
|
|
664
|
-
...this.extractOrFilterColumns(),
|
|
665
|
-
]);
|
|
666
|
-
|
|
667
|
-
const rowids = this.selectMatchingRowids();
|
|
668
|
-
if (rowids.length > 0) {
|
|
669
|
-
const rowidPlaceholders = rowids.map(() => '?').join(', ');
|
|
670
|
-
this.database
|
|
671
|
-
.prepare(`DELETE FROM ${quoteIdentifier(this.tableName)} WHERE rowid IN (${rowidPlaceholders})`)
|
|
672
|
-
.run(...rowids);
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
return this.createMutationResponse([]);
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
/**
|
|
679
|
-
* Executes an upsert query.
|
|
680
|
-
*/
|
|
681
|
-
private executeUpsert(): LocalSqliteQueryResult {
|
|
682
|
-
const affectedRowids: Array<number | bigint> = [];
|
|
683
|
-
const tableBaseName = resolveTableBaseName(this.tableName);
|
|
684
|
-
const conflictColumns = resolveUpsertConflictColumns(tableBaseName, this.upsertOptions);
|
|
685
|
-
|
|
686
|
-
for (const rawRow of this.mutationRows) {
|
|
687
|
-
const row = withInsertDefaults(tableBaseName, rawRow);
|
|
688
|
-
ensureTable(this.database, this.tableName, [...Object.keys(row), ...conflictColumns]);
|
|
689
|
-
const existingRowid =
|
|
690
|
-
conflictColumns.length > 0
|
|
691
|
-
? findConflictRowid(this.database, this.tableName, row, conflictColumns)
|
|
692
|
-
: null;
|
|
693
|
-
|
|
694
|
-
if (existingRowid !== null) {
|
|
695
|
-
updateRowid(this.database, this.tableName, existingRowid, row);
|
|
696
|
-
affectedRowids.push(existingRowid);
|
|
697
|
-
} else {
|
|
698
|
-
affectedRowids.push(insertRow(this.database, this.tableName, row).lastInsertRowid);
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
return this.createMutationResponse(affectedRowids);
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
/**
|
|
706
|
-
* Creates a mutation response, optionally loading selected mutated rows.
|
|
707
|
-
*/
|
|
708
|
-
private createMutationResponse(rowids: ReadonlyArray<number | bigint>): LocalSqliteQueryResult {
|
|
709
|
-
if (!this.isReturningSelection) {
|
|
710
|
-
return {
|
|
711
|
-
data: null,
|
|
712
|
-
error: null,
|
|
713
|
-
status: 201,
|
|
714
|
-
statusText: 'Created',
|
|
715
|
-
};
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
const data = selectRowsByRowids(
|
|
719
|
-
this.database,
|
|
720
|
-
this.tableName,
|
|
721
|
-
rowids,
|
|
722
|
-
parseSelectedColumns(this.selectedColumns),
|
|
723
|
-
);
|
|
724
|
-
return this.finalizeDataResponse(data, null);
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
/**
|
|
728
|
-
* Applies single/maybeSingle response semantics.
|
|
729
|
-
*/
|
|
730
|
-
private finalizeDataResponse(data: Array<Record<string, unknown>>, count: number | null): LocalSqliteQueryResult {
|
|
731
|
-
if (this.singleMode === 'single') {
|
|
732
|
-
if (data.length !== 1) {
|
|
733
|
-
return {
|
|
734
|
-
data: null,
|
|
735
|
-
error: {
|
|
736
|
-
code: 'PGRST116',
|
|
737
|
-
message: `Expected exactly one row, received ${data.length}.`,
|
|
738
|
-
},
|
|
739
|
-
count,
|
|
740
|
-
status: 406,
|
|
741
|
-
statusText: 'Not Acceptable',
|
|
742
|
-
};
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
return { data: data[0], error: null, count, status: 200, statusText: 'OK' };
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
if (this.singleMode === 'maybeSingle') {
|
|
749
|
-
if (data.length > 1) {
|
|
750
|
-
return {
|
|
751
|
-
data: null,
|
|
752
|
-
error: {
|
|
753
|
-
code: 'PGRST116',
|
|
754
|
-
message: `Expected zero or one row, received ${data.length}.`,
|
|
755
|
-
},
|
|
756
|
-
count,
|
|
757
|
-
status: 406,
|
|
758
|
-
statusText: 'Not Acceptable',
|
|
759
|
-
};
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
return { data: data[0] || null, error: null, count, status: 200, statusText: 'OK' };
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
return { data, error: null, count, status: 200, statusText: 'OK' };
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
/**
|
|
769
|
-
* Counts rows matching the current filters.
|
|
770
|
-
*/
|
|
771
|
-
private executeCount(where: { readonly sql: string; readonly values: ReadonlyArray<unknown> }): number {
|
|
772
|
-
const row = this.database
|
|
773
|
-
.prepare(`SELECT COUNT(*) AS "count" FROM ${quoteIdentifier(this.tableName)} ${where.sql}`)
|
|
774
|
-
.get(...where.values);
|
|
775
|
-
|
|
776
|
-
return Number(row?.count || 0);
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
/**
|
|
780
|
-
* Selects matching SQLite rowids before a mutation changes filtered columns.
|
|
781
|
-
*/
|
|
782
|
-
private selectMatchingRowids(): Array<number | bigint> {
|
|
783
|
-
const where = this.createWhereClause();
|
|
784
|
-
const sql = `SELECT rowid AS "__rowid" FROM ${quoteIdentifier(this.tableName)} ${where.sql}`;
|
|
785
|
-
return this.database
|
|
786
|
-
.prepare(sql)
|
|
787
|
-
.all(...where.values)
|
|
788
|
-
.map((row) => row.__rowid as number | bigint);
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
/**
|
|
792
|
-
* Creates the SQL WHERE clause.
|
|
793
|
-
*/
|
|
794
|
-
private createWhereClause(): { readonly sql: string; readonly values: ReadonlyArray<unknown> } {
|
|
795
|
-
const parts: Array<string> = [];
|
|
796
|
-
const values: Array<unknown> = [];
|
|
797
|
-
|
|
798
|
-
for (const filter of this.filters) {
|
|
799
|
-
const condition = createFilterCondition(this.tableName, filter);
|
|
800
|
-
parts.push(condition.sql);
|
|
801
|
-
values.push(...condition.values);
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
for (const filter of this.orFilters) {
|
|
805
|
-
const condition = createOrFilterCondition(this.tableName, filter);
|
|
806
|
-
if (!condition) {
|
|
807
|
-
continue;
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
parts.push(condition.sql);
|
|
811
|
-
values.push(...condition.values);
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
return {
|
|
815
|
-
sql: parts.length > 0 ? `WHERE ${parts.join(' AND ')}` : '',
|
|
816
|
-
values,
|
|
817
|
-
};
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
/**
|
|
821
|
-
* Creates the SQL ORDER BY clause.
|
|
822
|
-
*/
|
|
823
|
-
private createOrderByClause(): string {
|
|
824
|
-
if (this.orders.length === 0) {
|
|
825
|
-
return '';
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
const orderParts: Array<string> = [];
|
|
829
|
-
for (const order of this.orders) {
|
|
830
|
-
const quotedColumn = quoteIdentifier(order.column);
|
|
831
|
-
const direction = order.ascending ? 'ASC' : 'DESC';
|
|
832
|
-
|
|
833
|
-
if (order.nullsFirst === true) {
|
|
834
|
-
orderParts.push(`${quotedColumn} IS NOT NULL ASC`);
|
|
835
|
-
} else if (order.nullsFirst === false) {
|
|
836
|
-
orderParts.push(`${quotedColumn} IS NULL ASC`);
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
orderParts.push(`${quotedColumn} ${direction}`);
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
return `ORDER BY ${orderParts.join(', ')}`;
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
/**
|
|
846
|
-
* Creates the SQL LIMIT/OFFSET clause.
|
|
847
|
-
*/
|
|
848
|
-
private createLimitClause(): { readonly sql: string; readonly values: ReadonlyArray<unknown> } {
|
|
849
|
-
if (this.limitCount === null) {
|
|
850
|
-
return { sql: '', values: [] };
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
if (this.offsetCount === null) {
|
|
854
|
-
return { sql: 'LIMIT ?', values: [this.limitCount] };
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
return { sql: 'LIMIT ? OFFSET ?', values: [this.limitCount, this.offsetCount] };
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
/**
|
|
861
|
-
* Extracts column names referenced in OR filters.
|
|
862
|
-
*/
|
|
863
|
-
private extractOrFilterColumns(): Array<string> {
|
|
864
|
-
return this.orFilters.flatMap((filter) =>
|
|
865
|
-
splitPostgrestOrFilter(filter)
|
|
866
|
-
.map(parsePostgrestFilter)
|
|
867
|
-
.filter((parsedFilter): parsedFilter is ParsedPostgrestFilter => parsedFilter !== null)
|
|
868
|
-
.map((parsedFilter) => parsedFilter.column),
|
|
869
|
-
);
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
/**
|
|
874
|
-
* Parsed PostgREST filter expression.
|
|
875
|
-
*/
|
|
876
|
-
type ParsedPostgrestFilter = {
|
|
877
|
-
readonly column: string;
|
|
878
|
-
readonly operator: string;
|
|
879
|
-
readonly value: string;
|
|
880
|
-
};
|
|
881
|
-
|
|
882
|
-
/**
|
|
883
|
-
* Ensures a table and all required columns exist.
|
|
884
|
-
*/
|
|
885
|
-
function ensureTable(
|
|
886
|
-
database: AgentsServerSqliteDatabase,
|
|
887
|
-
tableName: string,
|
|
888
|
-
requiredColumns: ReadonlyArray<string>,
|
|
889
|
-
): void {
|
|
890
|
-
const tableBaseName = resolveTableBaseName(tableName);
|
|
891
|
-
const primaryKey = TEXT_PRIMARY_KEY_TABLES.has(tableBaseName)
|
|
892
|
-
? '"id" TEXT PRIMARY KEY'
|
|
893
|
-
: '"id" INTEGER PRIMARY KEY AUTOINCREMENT';
|
|
894
|
-
|
|
895
|
-
database.exec(`CREATE TABLE IF NOT EXISTS ${quoteIdentifier(tableName)} (${primaryKey})`);
|
|
896
|
-
|
|
897
|
-
const existingColumns = new Set(
|
|
898
|
-
database
|
|
899
|
-
.prepare(`PRAGMA table_info(${quoteIdentifier(tableName)})`)
|
|
900
|
-
.all()
|
|
901
|
-
.map((row) => String(row.name)),
|
|
902
|
-
);
|
|
903
|
-
const columnsToEnsure = uniqueStrings([...requiredColumns, ...resolveUniqueIndexColumns(tableBaseName)]).filter(
|
|
904
|
-
(column) => column !== '*' && column !== 'id',
|
|
905
|
-
);
|
|
906
|
-
const columnsToEnsureWithIndexes = uniqueStrings([...columnsToEnsure, ...resolveReadIndexColumns(tableBaseName)]);
|
|
907
|
-
|
|
908
|
-
for (const column of columnsToEnsureWithIndexes) {
|
|
909
|
-
if (existingColumns.has(column)) {
|
|
910
|
-
continue;
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
database.exec(
|
|
914
|
-
`ALTER TABLE ${quoteIdentifier(tableName)} ADD COLUMN ${quoteIdentifier(column)} ${resolveSqliteColumnType(
|
|
915
|
-
tableBaseName,
|
|
916
|
-
column,
|
|
917
|
-
)}`,
|
|
918
|
-
);
|
|
919
|
-
existingColumns.add(column);
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
ensureUniqueIndexes(database, tableName, tableBaseName);
|
|
923
|
-
ensureReadIndexes(database, tableName, tableBaseName);
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
/**
|
|
927
|
-
* Creates known unique indexes after required columns exist.
|
|
928
|
-
*/
|
|
929
|
-
function ensureUniqueIndexes(database: AgentsServerSqliteDatabase, tableName: string, tableBaseName: string): void {
|
|
930
|
-
const uniqueIndexes = UNIQUE_INDEX_COLUMNS_BY_TABLE.get(tableBaseName) || [];
|
|
931
|
-
|
|
932
|
-
for (const columns of uniqueIndexes) {
|
|
933
|
-
const indexName = `idx_${sanitizeSqlIdentifier(tableName)}_${columns.join('_')}_unique`;
|
|
934
|
-
const columnSql = columns.map(quoteIdentifier).join(', ');
|
|
935
|
-
database.exec(
|
|
936
|
-
`CREATE UNIQUE INDEX IF NOT EXISTS ${quoteIdentifier(indexName)} ON ${quoteIdentifier(
|
|
937
|
-
tableName,
|
|
938
|
-
)} (${columnSql})`,
|
|
939
|
-
);
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
/**
|
|
944
|
-
* Creates known read indexes after required columns exist.
|
|
945
|
-
*/
|
|
946
|
-
function ensureReadIndexes(database: AgentsServerSqliteDatabase, tableName: string, tableBaseName: string): void {
|
|
947
|
-
const readIndexes = READ_INDEXES_BY_TABLE.get(tableBaseName) || [];
|
|
948
|
-
|
|
949
|
-
for (const readIndex of readIndexes) {
|
|
950
|
-
const indexName = `index_${sanitizeSqlIdentifier(tableName)}_${sanitizeSqlIdentifier(readIndex.name)}`;
|
|
951
|
-
const columnSql = readIndex.columns.map(quoteIdentifier).join(', ');
|
|
952
|
-
database.exec(
|
|
953
|
-
`CREATE INDEX IF NOT EXISTS ${quoteIdentifier(indexName)} ON ${quoteIdentifier(tableName)} (${columnSql})`,
|
|
954
|
-
);
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
/**
|
|
959
|
-
* Inserts one row into the table.
|
|
960
|
-
*/
|
|
961
|
-
function insertRow(
|
|
962
|
-
database: AgentsServerSqliteDatabase,
|
|
963
|
-
tableName: string,
|
|
964
|
-
row: Record<string, unknown>,
|
|
965
|
-
): { readonly lastInsertRowid: number | bigint } {
|
|
966
|
-
const columns = Object.keys(row).filter((column) => row[column] !== undefined);
|
|
967
|
-
|
|
968
|
-
if (columns.length === 0) {
|
|
969
|
-
return database.prepare(`INSERT INTO ${quoteIdentifier(tableName)} DEFAULT VALUES`).run();
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
const placeholders = columns.map(() => '?').join(', ');
|
|
973
|
-
const values = columns.map((column) => serializeValue(tableName, column, row[column]));
|
|
974
|
-
const sql = `INSERT INTO ${quoteIdentifier(tableName)} (${columns
|
|
975
|
-
.map(quoteIdentifier)
|
|
976
|
-
.join(', ')}) VALUES (${placeholders})`;
|
|
977
|
-
|
|
978
|
-
return database.prepare(sql).run(...values);
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
/**
|
|
982
|
-
* Updates one row by SQLite rowid.
|
|
983
|
-
*/
|
|
984
|
-
function updateRowid(
|
|
985
|
-
database: AgentsServerSqliteDatabase,
|
|
986
|
-
tableName: string,
|
|
987
|
-
rowid: number | bigint,
|
|
988
|
-
row: Record<string, unknown>,
|
|
989
|
-
): void {
|
|
990
|
-
const columns = Object.keys(row).filter((column) => column !== 'id' && row[column] !== undefined);
|
|
991
|
-
if (columns.length === 0) {
|
|
992
|
-
return;
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
const assignments = columns.map((column) => `${quoteIdentifier(column)} = ?`).join(', ');
|
|
996
|
-
const values = columns.map((column) => serializeValue(tableName, column, row[column]));
|
|
997
|
-
database.prepare(`UPDATE ${quoteIdentifier(tableName)} SET ${assignments} WHERE rowid = ?`).run(...values, rowid);
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
/**
|
|
1001
|
-
* Finds the rowid matching an upsert conflict target.
|
|
1002
|
-
*/
|
|
1003
|
-
function findConflictRowid(
|
|
1004
|
-
database: AgentsServerSqliteDatabase,
|
|
1005
|
-
tableName: string,
|
|
1006
|
-
row: Record<string, unknown>,
|
|
1007
|
-
conflictColumns: ReadonlyArray<string>,
|
|
1008
|
-
): number | bigint | null {
|
|
1009
|
-
if (conflictColumns.some((column) => row[column] === undefined)) {
|
|
1010
|
-
return null;
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
const conditions = conflictColumns.map((column) => `${quoteIdentifier(column)} = ?`).join(' AND ');
|
|
1014
|
-
const values = conflictColumns.map((column) => serializeValue(tableName, column, row[column]));
|
|
1015
|
-
const result = database
|
|
1016
|
-
.prepare(`SELECT rowid FROM ${quoteIdentifier(tableName)} WHERE ${conditions} LIMIT 1`)
|
|
1017
|
-
.get(...values);
|
|
1018
|
-
|
|
1019
|
-
return result ? (result.rowid as number | bigint) : null;
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
/**
|
|
1023
|
-
* Selects rows by rowids for a mutation returning clause.
|
|
1024
|
-
*/
|
|
1025
|
-
function selectRowsByRowids(
|
|
1026
|
-
database: AgentsServerSqliteDatabase,
|
|
1027
|
-
tableName: string,
|
|
1028
|
-
rowids: ReadonlyArray<number | bigint>,
|
|
1029
|
-
selectedColumns: ReadonlyArray<string>,
|
|
1030
|
-
): Array<Record<string, unknown>> {
|
|
1031
|
-
if (rowids.length === 0) {
|
|
1032
|
-
return [];
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
ensureTable(database, tableName, selectedColumns);
|
|
1036
|
-
const placeholders = rowids.map(() => '?').join(', ');
|
|
1037
|
-
const rows = database
|
|
1038
|
-
.prepare(
|
|
1039
|
-
`SELECT ${createSelectExpression(selectedColumns)} FROM ${quoteIdentifier(
|
|
1040
|
-
tableName,
|
|
1041
|
-
)} WHERE rowid IN (${placeholders})`,
|
|
1042
|
-
)
|
|
1043
|
-
.all(...rowids);
|
|
1044
|
-
|
|
1045
|
-
return rows.map((row) => deserializeRow(tableName, row));
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
/**
|
|
1049
|
-
* Creates SQL for one simple filter.
|
|
1050
|
-
*/
|
|
1051
|
-
function createFilterCondition(
|
|
1052
|
-
tableName: string,
|
|
1053
|
-
filter: LocalSqliteFilter,
|
|
1054
|
-
): { readonly sql: string; readonly values: ReadonlyArray<unknown> } {
|
|
1055
|
-
const column = quoteIdentifier(filter.column);
|
|
1056
|
-
const value = serializeValue(tableName, filter.column, filter.value);
|
|
1057
|
-
|
|
1058
|
-
switch (filter.operator) {
|
|
1059
|
-
case 'eq':
|
|
1060
|
-
return value === null
|
|
1061
|
-
? { sql: `${column} IS NULL`, values: [] }
|
|
1062
|
-
: { sql: `${column} = ?`, values: [value] };
|
|
1063
|
-
case 'neq':
|
|
1064
|
-
return value === null
|
|
1065
|
-
? { sql: `${column} IS NOT NULL`, values: [] }
|
|
1066
|
-
: { sql: `${column} <> ?`, values: [value] };
|
|
1067
|
-
case 'is':
|
|
1068
|
-
return filter.value === null
|
|
1069
|
-
? { sql: `${column} IS NULL`, values: [] }
|
|
1070
|
-
: { sql: `${column} IS ?`, values: [value] };
|
|
1071
|
-
case 'not-is':
|
|
1072
|
-
return filter.value === null
|
|
1073
|
-
? { sql: `${column} IS NOT NULL`, values: [] }
|
|
1074
|
-
: { sql: `${column} IS NOT ?`, values: [value] };
|
|
1075
|
-
case 'in': {
|
|
1076
|
-
const values = Array.isArray(filter.value)
|
|
1077
|
-
? filter.value.map((item) => serializeValue(tableName, filter.column, item))
|
|
1078
|
-
: [];
|
|
1079
|
-
if (values.length === 0) {
|
|
1080
|
-
return { sql: '0 = 1', values: [] };
|
|
1081
|
-
}
|
|
1082
|
-
return { sql: `${column} IN (${values.map(() => '?').join(', ')})`, values };
|
|
1083
|
-
}
|
|
1084
|
-
case 'lt':
|
|
1085
|
-
return { sql: `${column} < ?`, values: [value] };
|
|
1086
|
-
case 'lte':
|
|
1087
|
-
return { sql: `${column} <= ?`, values: [value] };
|
|
1088
|
-
case 'gt':
|
|
1089
|
-
return { sql: `${column} > ?`, values: [value] };
|
|
1090
|
-
case 'gte':
|
|
1091
|
-
return { sql: `${column} >= ?`, values: [value] };
|
|
1092
|
-
case 'like':
|
|
1093
|
-
return { sql: `${column} LIKE ? ESCAPE '\\'`, values: [value] };
|
|
1094
|
-
case 'ilike':
|
|
1095
|
-
return { sql: `LOWER(${column}) LIKE LOWER(?) ESCAPE '\\'`, values: [value] };
|
|
1096
|
-
default:
|
|
1097
|
-
return { sql: '1 = 1', values: [] };
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
/**
|
|
1102
|
-
* Creates SQL for one PostgREST `.or(...)` filter.
|
|
1103
|
-
*/
|
|
1104
|
-
function createOrFilterCondition(
|
|
1105
|
-
tableName: string,
|
|
1106
|
-
filter: string,
|
|
1107
|
-
): { readonly sql: string; readonly values: ReadonlyArray<unknown> } | null {
|
|
1108
|
-
const conditions: Array<string> = [];
|
|
1109
|
-
const values: Array<unknown> = [];
|
|
1110
|
-
|
|
1111
|
-
for (const part of splitPostgrestOrFilter(filter)) {
|
|
1112
|
-
const parsedFilter = parsePostgrestFilter(part);
|
|
1113
|
-
if (!parsedFilter) {
|
|
1114
|
-
continue;
|
|
1115
|
-
}
|
|
1116
|
-
|
|
1117
|
-
if (parsedFilter.operator === 'cs') {
|
|
1118
|
-
conditions.push('0 = 1');
|
|
1119
|
-
continue;
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
const condition = createFilterCondition(tableName, {
|
|
1123
|
-
column: parsedFilter.column,
|
|
1124
|
-
operator: normalizePostgrestOperator(parsedFilter.operator),
|
|
1125
|
-
value: decodePostgrestFilterValue(parsedFilter.value),
|
|
1126
|
-
});
|
|
1127
|
-
conditions.push(condition.sql);
|
|
1128
|
-
values.push(...condition.values);
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1131
|
-
if (conditions.length === 0) {
|
|
1132
|
-
return null;
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
return {
|
|
1136
|
-
sql: `(${conditions.join(' OR ')})`,
|
|
1137
|
-
values,
|
|
1138
|
-
};
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
/**
|
|
1142
|
-
* Splits a PostgREST OR filter while keeping JSON literals intact.
|
|
1143
|
-
*/
|
|
1144
|
-
function splitPostgrestOrFilter(filter: string): Array<string> {
|
|
1145
|
-
const parts: Array<string> = [];
|
|
1146
|
-
let current = '';
|
|
1147
|
-
let depth = 0;
|
|
1148
|
-
let isInsideString = false;
|
|
1149
|
-
|
|
1150
|
-
for (let index = 0; index < filter.length; index++) {
|
|
1151
|
-
const character = filter[index]!;
|
|
1152
|
-
const previousCharacter = filter[index - 1];
|
|
1153
|
-
|
|
1154
|
-
if (character === '"' && previousCharacter !== '\\') {
|
|
1155
|
-
isInsideString = !isInsideString;
|
|
1156
|
-
} else if (!isInsideString && (character === '{' || character === '[')) {
|
|
1157
|
-
depth++;
|
|
1158
|
-
} else if (!isInsideString && (character === '}' || character === ']')) {
|
|
1159
|
-
depth--;
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
|
-
if (character === ',' && depth === 0 && !isInsideString) {
|
|
1163
|
-
parts.push(current);
|
|
1164
|
-
current = '';
|
|
1165
|
-
continue;
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
current += character;
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
|
-
if (current) {
|
|
1172
|
-
parts.push(current);
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
|
-
return parts.map((part) => part.trim()).filter(Boolean);
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
/**
|
|
1179
|
-
* Parses one PostgREST filter expression.
|
|
1180
|
-
*/
|
|
1181
|
-
function parsePostgrestFilter(filter: string): ParsedPostgrestFilter | null {
|
|
1182
|
-
const match = /^([^.]*)\.([a-z]+)\.([\s\S]*)$/iu.exec(filter.trim());
|
|
1183
|
-
if (!match) {
|
|
1184
|
-
return null;
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
|
-
return {
|
|
1188
|
-
column: match[1]!,
|
|
1189
|
-
operator: match[2]!.toLowerCase(),
|
|
1190
|
-
value: match[3]!,
|
|
1191
|
-
};
|
|
1192
|
-
}
|
|
1193
|
-
|
|
1194
|
-
/**
|
|
1195
|
-
* Converts PostgREST operators into internal filter operators.
|
|
1196
|
-
*/
|
|
1197
|
-
function normalizePostgrestOperator(operator: string): LocalSqliteFilter['operator'] {
|
|
1198
|
-
switch (operator) {
|
|
1199
|
-
case 'neq':
|
|
1200
|
-
return 'neq';
|
|
1201
|
-
case 'ilike':
|
|
1202
|
-
return 'ilike';
|
|
1203
|
-
case 'like':
|
|
1204
|
-
return 'like';
|
|
1205
|
-
case 'lt':
|
|
1206
|
-
return 'lt';
|
|
1207
|
-
case 'lte':
|
|
1208
|
-
return 'lte';
|
|
1209
|
-
case 'gt':
|
|
1210
|
-
return 'gt';
|
|
1211
|
-
case 'gte':
|
|
1212
|
-
return 'gte';
|
|
1213
|
-
case 'eq':
|
|
1214
|
-
default:
|
|
1215
|
-
return 'eq';
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
/**
|
|
1220
|
-
* Decodes a PostgREST filter value when URL-encoded by callers.
|
|
1221
|
-
*/
|
|
1222
|
-
function decodePostgrestFilterValue(value: string): string {
|
|
1223
|
-
try {
|
|
1224
|
-
return decodeURIComponent(value);
|
|
1225
|
-
} catch {
|
|
1226
|
-
return value;
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
/**
|
|
1231
|
-
* Creates a select expression from parsed columns.
|
|
1232
|
-
*/
|
|
1233
|
-
function createSelectExpression(columns: ReadonlyArray<string>): string {
|
|
1234
|
-
if (columns.length === 0 || columns.includes('*')) {
|
|
1235
|
-
return '*';
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
return columns.map(quoteIdentifier).join(', ');
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
/**
|
|
1242
|
-
* Parses a simple Supabase select column list.
|
|
1243
|
-
*/
|
|
1244
|
-
function parseSelectedColumns(columns: string): Array<string> {
|
|
1245
|
-
const trimmedColumns = columns.trim();
|
|
1246
|
-
if (!trimmedColumns || trimmedColumns === '*') {
|
|
1247
|
-
return ['*'];
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
return trimmedColumns
|
|
1251
|
-
.split(',')
|
|
1252
|
-
.map((column) => column.trim())
|
|
1253
|
-
.filter(Boolean)
|
|
1254
|
-
.map((column) => column.split(':').pop() || column)
|
|
1255
|
-
.map((column) => column.replace(/\s+/g, ''))
|
|
1256
|
-
.filter((column) => /^[A-Za-z_][A-Za-z0-9_]*$/u.test(column));
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
/**
|
|
1260
|
-
* Converts mutation payloads into a uniform array of records.
|
|
1261
|
-
*/
|
|
1262
|
-
function normalizeMutationRows(values: TODO_any): Array<Record<string, unknown>> {
|
|
1263
|
-
if (Array.isArray(values)) {
|
|
1264
|
-
return values.map((row) => stripUndefinedValues(row || {}));
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
|
-
return [stripUndefinedValues(values || {})];
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
/**
|
|
1271
|
-
* Removes undefined values because Supabase omits them from mutation payloads.
|
|
1272
|
-
*/
|
|
1273
|
-
function stripUndefinedValues(values: Record<string, unknown>): Record<string, unknown> {
|
|
1274
|
-
const result: Record<string, unknown> = {};
|
|
1275
|
-
|
|
1276
|
-
for (const [key, value] of Object.entries(values)) {
|
|
1277
|
-
if (value !== undefined) {
|
|
1278
|
-
result[key] = value;
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
return result;
|
|
1283
|
-
}
|
|
1284
|
-
|
|
1285
|
-
/**
|
|
1286
|
-
* Adds SQLite-side defaults that are normally supplied by PostgreSQL migrations.
|
|
1287
|
-
*/
|
|
1288
|
-
function withInsertDefaults(tableBaseName: string, row: Record<string, unknown>): Record<string, unknown> {
|
|
1289
|
-
const nowIso = new Date().toISOString();
|
|
1290
|
-
const result = { ...row };
|
|
1291
|
-
|
|
1292
|
-
if (result.createdAt === undefined) {
|
|
1293
|
-
result.createdAt = nowIso;
|
|
1294
|
-
}
|
|
1295
|
-
if (result.updatedAt === undefined && tableBaseName !== 'AgentHistory' && tableBaseName !== 'ChatHistory') {
|
|
1296
|
-
result.updatedAt = nowIso;
|
|
1297
|
-
}
|
|
1298
|
-
|
|
1299
|
-
switch (tableBaseName) {
|
|
1300
|
-
case 'Agent':
|
|
1301
|
-
result.visibility ??= 'PRIVATE';
|
|
1302
|
-
result.folderId ??= null;
|
|
1303
|
-
result.sortOrder ??= Date.now();
|
|
1304
|
-
result.deletedAt ??= null;
|
|
1305
|
-
result.preparedModelRequirements ??= null;
|
|
1306
|
-
break;
|
|
1307
|
-
case 'AgentFolder':
|
|
1308
|
-
result.parentId ??= null;
|
|
1309
|
-
result.sortOrder ??= Date.now();
|
|
1310
|
-
result.deletedAt ??= null;
|
|
1311
|
-
result.icon ??= null;
|
|
1312
|
-
result.color ??= null;
|
|
1313
|
-
break;
|
|
1314
|
-
case 'User':
|
|
1315
|
-
result.isAdmin ??= false;
|
|
1316
|
-
result.profileImageUrl ??= null;
|
|
1317
|
-
result.email ??= null;
|
|
1318
|
-
result.displayName ??= null;
|
|
1319
|
-
result.authenticationProvider ??= 'LOCAL';
|
|
1320
|
-
break;
|
|
1321
|
-
case 'ShibbolethUserIdentity':
|
|
1322
|
-
result.displayName ??= null;
|
|
1323
|
-
result.nameId ??= null;
|
|
1324
|
-
result.nameIdFormat ??= null;
|
|
1325
|
-
result.unstructuredName ??= null;
|
|
1326
|
-
result.eduPersonPrincipalName ??= null;
|
|
1327
|
-
result.rawAttributes ??= null;
|
|
1328
|
-
result.lastLoggedInAt ??= null;
|
|
1329
|
-
result.loginCount ??= 0;
|
|
1330
|
-
break;
|
|
1331
|
-
case 'ShibbolethAuthenticationAttempt':
|
|
1332
|
-
result.userId ??= null;
|
|
1333
|
-
result.email ??= null;
|
|
1334
|
-
result.displayName ??= null;
|
|
1335
|
-
result.nameId ??= null;
|
|
1336
|
-
result.relayState ??= null;
|
|
1337
|
-
result.ip ??= null;
|
|
1338
|
-
result.userAgent ??= null;
|
|
1339
|
-
result.errorMessage ??= null;
|
|
1340
|
-
result.rawAttributes ??= null;
|
|
1341
|
-
break;
|
|
1342
|
-
case 'UserChat':
|
|
1343
|
-
result.messages ??= [];
|
|
1344
|
-
result.source ??= 'WEB_UI';
|
|
1345
|
-
result.title ??= null;
|
|
1346
|
-
result.draftMessage ??= null;
|
|
1347
|
-
break;
|
|
1348
|
-
case 'UserChatJob':
|
|
1349
|
-
result.parameters ??= {};
|
|
1350
|
-
result.queuedAt ??= nowIso;
|
|
1351
|
-
result.attemptCount ??= 0;
|
|
1352
|
-
break;
|
|
1353
|
-
case 'UserChatTimeout':
|
|
1354
|
-
result.parameters ??= {};
|
|
1355
|
-
result.queuedAt ??= nowIso;
|
|
1356
|
-
result.attemptCount ??= 0;
|
|
1357
|
-
result.runCount ??= 0;
|
|
1358
|
-
break;
|
|
1359
|
-
case 'ApiTokens':
|
|
1360
|
-
result.isRevoked ??= false;
|
|
1361
|
-
break;
|
|
1362
|
-
case 'Wallet':
|
|
1363
|
-
result.isUserScoped ??= true;
|
|
1364
|
-
result.isGlobal ??= false;
|
|
1365
|
-
result.deletedAt ??= null;
|
|
1366
|
-
break;
|
|
1367
|
-
case 'UserMemory':
|
|
1368
|
-
result.isGlobal ??= false;
|
|
1369
|
-
result.deletedAt ??= null;
|
|
1370
|
-
break;
|
|
1371
|
-
case 'ShareTargetPayload':
|
|
1372
|
-
result.attachments ??= [];
|
|
1373
|
-
result.consumedAt ??= null;
|
|
1374
|
-
break;
|
|
1375
|
-
case 'UserPushSubscription':
|
|
1376
|
-
result.isChatFocused ??= false;
|
|
1377
|
-
break;
|
|
1378
|
-
}
|
|
1379
|
-
|
|
1380
|
-
return result;
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
/**
|
|
1384
|
-
* Serializes one value for SQLite storage.
|
|
1385
|
-
*/
|
|
1386
|
-
function serializeValue(tableName: string, column: string, value: unknown): unknown {
|
|
1387
|
-
if (value === undefined) {
|
|
1388
|
-
return undefined;
|
|
1389
|
-
}
|
|
1390
|
-
if (value === null) {
|
|
1391
|
-
return null;
|
|
1392
|
-
}
|
|
1393
|
-
if (isTextColumn(tableName, column)) {
|
|
1394
|
-
return String(value);
|
|
1395
|
-
}
|
|
1396
|
-
if (isJsonColumn(tableName, column)) {
|
|
1397
|
-
return typeof value === 'string' ? value : JSON.stringify(value);
|
|
1398
|
-
}
|
|
1399
|
-
if (BOOLEAN_COLUMNS.has(column)) {
|
|
1400
|
-
return value ? 1 : 0;
|
|
1401
|
-
}
|
|
1402
|
-
return value;
|
|
1403
|
-
}
|
|
1404
|
-
|
|
1405
|
-
/**
|
|
1406
|
-
* Deserializes one SQLite row into Supabase-like row values.
|
|
1407
|
-
*/
|
|
1408
|
-
function deserializeRow(tableName: string, row: Record<string, unknown>): Record<string, unknown> {
|
|
1409
|
-
const result: Record<string, unknown> = {};
|
|
1410
|
-
|
|
1411
|
-
for (const [column, value] of Object.entries(row)) {
|
|
1412
|
-
if (value === null || value === undefined) {
|
|
1413
|
-
result[column] = null;
|
|
1414
|
-
} else if (isTextColumn(tableName, column)) {
|
|
1415
|
-
result[column] = String(value);
|
|
1416
|
-
} else if (isJsonColumn(tableName, column) && typeof value === 'string') {
|
|
1417
|
-
result[column] = parseJsonValue(value);
|
|
1418
|
-
} else if (BOOLEAN_COLUMNS.has(column)) {
|
|
1419
|
-
result[column] = Boolean(value);
|
|
1420
|
-
} else {
|
|
1421
|
-
result[column] = value;
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1425
|
-
return result;
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
/**
|
|
1429
|
-
* Parses JSON while preserving invalid strings.
|
|
1430
|
-
*/
|
|
1431
|
-
function parseJsonValue(value: string): unknown {
|
|
1432
|
-
try {
|
|
1433
|
-
return JSON.parse(value);
|
|
1434
|
-
} catch {
|
|
1435
|
-
return value;
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
/**
|
|
1440
|
-
* Resolves whether a column is JSON for a specific table.
|
|
1441
|
-
*/
|
|
1442
|
-
function isJsonColumn(tableName: string, column: string): boolean {
|
|
1443
|
-
return isJsonColumnForTableBaseName(resolveTableBaseName(tableName), column);
|
|
1444
|
-
}
|
|
1445
|
-
|
|
1446
|
-
/**
|
|
1447
|
-
* Resolves whether a column is JSON for a specific table base name.
|
|
1448
|
-
*/
|
|
1449
|
-
function isJsonColumnForTableBaseName(tableBaseName: string, column: string): boolean {
|
|
1450
|
-
return JSON_COLUMNS_BY_TABLE.get(tableBaseName)?.has(column) || false;
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
|
-
/**
|
|
1454
|
-
* Resolves whether a column should be forced to a string for a specific table.
|
|
1455
|
-
*/
|
|
1456
|
-
function isTextColumn(tableName: string, column: string): boolean {
|
|
1457
|
-
return isTextColumnForTableBaseName(resolveTableBaseName(tableName), column);
|
|
1458
|
-
}
|
|
1459
|
-
|
|
1460
|
-
/**
|
|
1461
|
-
* Resolves whether a column should be forced to a string for a specific table base name.
|
|
1462
|
-
*/
|
|
1463
|
-
function isTextColumnForTableBaseName(tableBaseName: string, column: string): boolean {
|
|
1464
|
-
return TEXT_COLUMNS_BY_TABLE.get(tableBaseName)?.has(column) || false;
|
|
1465
|
-
}
|
|
1466
|
-
|
|
1467
|
-
/**
|
|
1468
|
-
* Resolves whether a column is known to be numeric for a specific table base name.
|
|
1469
|
-
*/
|
|
1470
|
-
function isIntegerColumnForTableBaseName(tableBaseName: string, column: string): boolean {
|
|
1471
|
-
return INTEGER_COLUMNS_BY_TABLE.get(tableBaseName)?.has(column) || false;
|
|
1472
|
-
}
|
|
1473
|
-
|
|
1474
|
-
/**
|
|
1475
|
-
* Resolves SQLite column affinity for dynamically added columns.
|
|
1476
|
-
*/
|
|
1477
|
-
function resolveSqliteColumnType(tableBaseName: string, column: string): string {
|
|
1478
|
-
if (isTextColumnForTableBaseName(tableBaseName, column) || isJsonColumnForTableBaseName(tableBaseName, column)) {
|
|
1479
|
-
return 'TEXT';
|
|
1480
|
-
}
|
|
1481
|
-
if (BOOLEAN_COLUMNS.has(column)) {
|
|
1482
|
-
return 'INTEGER';
|
|
1483
|
-
}
|
|
1484
|
-
if (isIntegerColumnForTableBaseName(tableBaseName, column)) {
|
|
1485
|
-
return 'INTEGER';
|
|
1486
|
-
}
|
|
1487
|
-
if (
|
|
1488
|
-
column === 'id' ||
|
|
1489
|
-
column.endsWith('Id') ||
|
|
1490
|
-
column.endsWith('Count') ||
|
|
1491
|
-
column.endsWith('Ms') ||
|
|
1492
|
-
column.endsWith('Bytes') ||
|
|
1493
|
-
column === 'sortOrder' ||
|
|
1494
|
-
column === 'attemptCount' ||
|
|
1495
|
-
column === 'runCount'
|
|
1496
|
-
) {
|
|
1497
|
-
return 'INTEGER';
|
|
1498
|
-
}
|
|
1499
|
-
|
|
1500
|
-
return 'TEXT';
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1503
|
-
/**
|
|
1504
|
-
* Resolves a table base name from the actual prefixed table name.
|
|
1505
|
-
*/
|
|
1506
|
-
function resolveTableBaseName(tableName: string): string {
|
|
1507
|
-
const knownTableNames = uniqueStrings([
|
|
1508
|
-
'_Server',
|
|
1509
|
-
...Array.from(JSON_COLUMNS_BY_TABLE.keys()),
|
|
1510
|
-
...Array.from(UNIQUE_INDEX_COLUMNS_BY_TABLE.keys()),
|
|
1511
|
-
...Array.from(TEXT_PRIMARY_KEY_TABLES),
|
|
1512
|
-
'AgentFolder',
|
|
1513
|
-
'CustomStylesheet',
|
|
1514
|
-
'CustomJavascript',
|
|
1515
|
-
'CalendarActivity',
|
|
1516
|
-
]).sort((left, right) => right.length - left.length);
|
|
1517
|
-
|
|
1518
|
-
return knownTableNames.find((knownTableName) => tableName.endsWith(knownTableName)) || tableName;
|
|
1519
|
-
}
|
|
1520
|
-
|
|
1521
|
-
/**
|
|
1522
|
-
* Resolves columns participating in known unique indexes.
|
|
1523
|
-
*/
|
|
1524
|
-
function resolveUniqueIndexColumns(tableBaseName: string): Array<string> {
|
|
1525
|
-
return (UNIQUE_INDEX_COLUMNS_BY_TABLE.get(tableBaseName) || []).flatMap((columns) => [...columns]);
|
|
1526
|
-
}
|
|
1527
|
-
|
|
1528
|
-
/**
|
|
1529
|
-
* Resolves columns participating in known read indexes.
|
|
1530
|
-
*/
|
|
1531
|
-
function resolveReadIndexColumns(tableBaseName: string): Array<string> {
|
|
1532
|
-
return (READ_INDEXES_BY_TABLE.get(tableBaseName) || []).flatMap((readIndex) => [...readIndex.columns]);
|
|
1533
|
-
}
|
|
1534
|
-
|
|
1535
|
-
/**
|
|
1536
|
-
* Resolves upsert conflict columns.
|
|
1537
|
-
*/
|
|
1538
|
-
function resolveUpsertConflictColumns(tableBaseName: string, options: LocalSqliteUpsertOptions): ReadonlyArray<string> {
|
|
1539
|
-
if (options.onConflict) {
|
|
1540
|
-
return options.onConflict
|
|
1541
|
-
.split(',')
|
|
1542
|
-
.map((column) => column.trim())
|
|
1543
|
-
.filter(Boolean);
|
|
1544
|
-
}
|
|
1545
|
-
|
|
1546
|
-
return DEFAULT_UPSERT_CONFLICT_COLUMNS_BY_TABLE.get(tableBaseName) || [];
|
|
1547
|
-
}
|
|
1548
|
-
|
|
1549
|
-
/**
|
|
1550
|
-
* Converts SQLite errors into Supabase-like errors.
|
|
1551
|
-
*/
|
|
1552
|
-
function normalizeSqliteError(error: unknown): LocalSqliteError {
|
|
1553
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
1554
|
-
const sqliteCode =
|
|
1555
|
-
typeof error === 'object' && error !== null && typeof (error as { code?: unknown }).code === 'string'
|
|
1556
|
-
? (error as { code: string }).code
|
|
1557
|
-
: undefined;
|
|
1558
|
-
|
|
1559
|
-
return {
|
|
1560
|
-
code:
|
|
1561
|
-
sqliteCode === 'SQLITE_CONSTRAINT_UNIQUE' || sqliteCode === 'SQLITE_CONSTRAINT_PRIMARYKEY'
|
|
1562
|
-
? '23505'
|
|
1563
|
-
: sqliteCode,
|
|
1564
|
-
message,
|
|
1565
|
-
};
|
|
1566
|
-
}
|
|
1567
|
-
|
|
1568
|
-
/**
|
|
1569
|
-
* Quotes one SQLite identifier.
|
|
1570
|
-
*/
|
|
1571
|
-
function quoteIdentifier(identifier: string): string {
|
|
1572
|
-
return `"${identifier.replace(/"/g, '""')}"`;
|
|
1573
|
-
}
|
|
1574
|
-
|
|
1575
|
-
/**
|
|
1576
|
-
* Creates a safe identifier suffix for generated index names.
|
|
1577
|
-
*/
|
|
1578
|
-
function sanitizeSqlIdentifier(identifier: string): string {
|
|
1579
|
-
return identifier.replace(/[^A-Za-z0-9_]/g, '_');
|
|
1580
|
-
}
|
|
1581
|
-
|
|
1582
|
-
/**
|
|
1583
|
-
* Deduplicates strings while preserving order.
|
|
1584
|
-
*/
|
|
1585
|
-
function uniqueStrings(values: ReadonlyArray<string>): Array<string> {
|
|
1586
|
-
return Array.from(new Set(values.filter(Boolean)));
|
|
1587
|
-
}
|