@promptbook/cli 0.113.0-4 → 0.113.0-8
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/apps/agents-server/src/app/admin/update/AdvancedOriginRepositoryPanel.tsx +76 -0
- package/apps/agents-server/src/app/admin/update/CurrentDeploymentCard.tsx +160 -0
- package/apps/agents-server/src/app/admin/update/PendingCommitsCard.tsx +86 -0
- package/apps/agents-server/src/app/admin/update/TargetEnvironmentCard.tsx +331 -0
- package/apps/agents-server/src/app/admin/update/UpdateClient.tsx +20 -873
- package/apps/agents-server/src/app/admin/update/UpdateJobCard.tsx +329 -0
- package/apps/agents-server/src/app/admin/update/UpdateOverview.ts +74 -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/useUpdateClientState.ts +441 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +13 -1
- 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/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/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/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/search/createDefaultServerSearchProviders/loadLocalOrganizationSearchDataset.ts +12 -1
- package/apps/agents-server/src/tools/send_email.ts +1 -2
- 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/createLocalAgentSourceImporter.ts +159 -0
- package/apps/agents-server/src/utils/createMissingImportedAgentFallback.ts +60 -0
- package/apps/agents-server/src/utils/customDomainRouting.ts +157 -12
- package/apps/agents-server/src/utils/externalChatRunner/processExternalUserChatJob.ts +1 -1
- 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 +1 -1
- 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/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/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/userChat/userChatMessageLifecycle.ts +39 -9
- package/apps/agents-server/tests/e2e/support/ChatHistoryNavigationSupport.ts +5 -0
- package/esm/index.es.js +875 -60
- 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-codex-prompts/common/resolveCoderAgent.d.ts +20 -0
- package/esm/scripts/run-codex-prompts/ui/CoderRunUiState.d.ts +5 -0
- package/esm/scripts/run-codex-prompts/ui/buildCoderRunAgentVisual.d.ts +29 -0
- package/esm/scripts/run-codex-prompts/ui/buildCoderRunUiFrame.d.ts +4 -0
- package/esm/src/avatars/renderAvatarVisualAsciiArt.d.ts +75 -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/cli/cli-commands/common/createPositiveIntegerOptionParser.d.ts +10 -0
- 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/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/avatars/avatarAnimationScheduler.ts +2 -1
- package/src/avatars/renderAvatarVisualAsciiArt.ts +138 -0
- package/src/avatars/visuals/octopus3d3AvatarVisual.ts +6 -2
- package/src/avatars/visuals/octopus3d4AvatarVisual.ts +14 -18
- 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/useChatInputAreaDictation.ts +133 -26
- package/src/cli/cli-commands/agents-server/buildAgentsServer.ts +3 -1
- 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/initializeCoderProjectConfiguration.ts +1 -4
- package/src/cli/cli-commands/coder/run.ts +3 -27
- package/src/cli/cli-commands/common/createPositiveIntegerOptionParser.ts +31 -0
- package/src/commitments/TEAM/TEAM.ts +5 -5
- package/src/other/templates/getTemplatesPipelineCollection.ts +770 -1169
- package/src/utils/ascii-art/$detectTerminalAnsiColorDepth.ts +45 -0
- package/src/utils/ascii-art/convertImageDataToAsciiArt.ts +396 -0
- package/src/version.ts +2 -2
- package/src/versions.txt +2 -0
- package/umd/index.umd.js +875 -60
- 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-codex-prompts/common/resolveCoderAgent.d.ts +20 -0
- package/umd/scripts/run-codex-prompts/ui/CoderRunUiState.d.ts +5 -0
- package/umd/scripts/run-codex-prompts/ui/buildCoderRunAgentVisual.d.ts +29 -0
- package/umd/scripts/run-codex-prompts/ui/buildCoderRunUiFrame.d.ts +4 -0
- package/umd/src/avatars/renderAvatarVisualAsciiArt.d.ts +75 -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/cli/cli-commands/common/createPositiveIntegerOptionParser.d.ts +10 -0
- 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/version.d.ts +1 -1
- package/esm/scripts/run-codex-prompts/common/resolveAgentSystemMessage.d.ts +0 -6
- package/umd/scripts/run-codex-prompts/common/resolveAgentSystemMessage.d.ts +0 -6
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import type { LocalSqliteUpsertOptions } from './localSqliteTypes';
|
|
2
|
+
import { uniqueStrings } from './localSqliteSql';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Read index definition for hot SQLite queries.
|
|
6
|
+
*
|
|
7
|
+
* @private type of `$provideLocalSqliteSupabase`
|
|
8
|
+
*/
|
|
9
|
+
export type LocalSqliteReadIndex = {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly columns: ReadonlyArray<string>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Columns whose values are persisted as JSON text in local SQLite.
|
|
16
|
+
*
|
|
17
|
+
* @private constant of `$provideLocalSqliteSupabase`
|
|
18
|
+
*/
|
|
19
|
+
const JSON_COLUMNS_BY_TABLE = new Map<string, ReadonlySet<string>>([
|
|
20
|
+
['Agent', new Set(['agentProfile', 'usage', 'preparedModelRequirements', 'preparedExternals'])],
|
|
21
|
+
['AgentHistory', new Set([])],
|
|
22
|
+
['ChatHistory', new Set(['message', 'usage'])],
|
|
23
|
+
['LlmCache', new Set(['value'])],
|
|
24
|
+
['VectorStoreKnowledgeSourceHashes', new Set([])],
|
|
25
|
+
['Image', new Set([])],
|
|
26
|
+
['File', new Set(['securityResult'])],
|
|
27
|
+
['Message', new Set(['sender', 'recipients', 'metadata'])],
|
|
28
|
+
['MessageSendAttempt', new Set(['raw'])],
|
|
29
|
+
['UserChat', new Set(['messages'])],
|
|
30
|
+
['UserChatJob', new Set(['parameters'])],
|
|
31
|
+
['UserChatTimeout', new Set(['parameters'])],
|
|
32
|
+
['UserData', new Set(['value'])],
|
|
33
|
+
['Wallet', new Set(['jsonSchema'])],
|
|
34
|
+
['ShareTargetPayload', new Set(['attachments'])],
|
|
35
|
+
['CalendarConnection', new Set(['scopes'])],
|
|
36
|
+
['CalendarActivity', new Set(['details'])],
|
|
37
|
+
['ShibbolethUserIdentity', new Set(['rawAttributes'])],
|
|
38
|
+
['ShibbolethAuthenticationAttempt', new Set(['rawAttributes'])],
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Columns that must always be surfaced as strings even when an older SQLite
|
|
43
|
+
* table was created with numeric affinity.
|
|
44
|
+
*
|
|
45
|
+
* @private constant of `$provideLocalSqliteSupabase`
|
|
46
|
+
*/
|
|
47
|
+
const TEXT_COLUMNS_BY_TABLE = new Map<string, ReadonlySet<string>>([['Metadata', new Set(['key', 'value', 'note'])]]);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Table-specific integer columns whose names would otherwise be ambiguous.
|
|
51
|
+
*
|
|
52
|
+
* @private constant of `$provideLocalSqliteSupabase`
|
|
53
|
+
*/
|
|
54
|
+
const INTEGER_COLUMNS_BY_TABLE = new Map<string, ReadonlySet<string>>([['ServerLimit', new Set(['value'])]]);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Boolean columns stored as integers by SQLite and restored as booleans.
|
|
58
|
+
*
|
|
59
|
+
* @private constant of `$provideLocalSqliteSupabase`
|
|
60
|
+
*/
|
|
61
|
+
const BOOLEAN_COLUMNS = new Set(['isAdmin', 'isRevoked', 'isGlobal', 'isUserScoped', 'isSuccessful', 'isChatFocused']);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Tables whose primary key is provided as text rather than generated numerically.
|
|
65
|
+
*
|
|
66
|
+
* @private constant of `$provideLocalSqliteSupabase`
|
|
67
|
+
*/
|
|
68
|
+
const TEXT_PRIMARY_KEY_TABLES = new Set([
|
|
69
|
+
'UserChat',
|
|
70
|
+
'UserChatJob',
|
|
71
|
+
'UserChatTimeout',
|
|
72
|
+
'UserPushSubscription',
|
|
73
|
+
'ShareTargetPayload',
|
|
74
|
+
]);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Unique constraints required by common Supabase upsert and duplicate-detection flows.
|
|
78
|
+
*
|
|
79
|
+
* @private constant of `$provideLocalSqliteSupabase`
|
|
80
|
+
*/
|
|
81
|
+
const UNIQUE_INDEX_COLUMNS_BY_TABLE = new Map<string, ReadonlyArray<ReadonlyArray<string>>>([
|
|
82
|
+
['_Server', [['name'], ['domain']]],
|
|
83
|
+
['Metadata', [['key']]],
|
|
84
|
+
['ServerLimit', [['key']]],
|
|
85
|
+
['Agent', [['permanentId']]],
|
|
86
|
+
['AgentExternals', [['type', 'hash']]],
|
|
87
|
+
['VectorStoreKnowledgeSourceHashes', [['source']]],
|
|
88
|
+
['User', [['username']]],
|
|
89
|
+
['ShibbolethUserIdentity', [['userId'], ['email'], ['nameId']]],
|
|
90
|
+
['UserChatJob', [['chatId', 'clientMessageId']]],
|
|
91
|
+
['LlmCache', [['hash']]],
|
|
92
|
+
['OpenAiAssistantCache', [['agentHash']]],
|
|
93
|
+
['ApiTokens', [['token']]],
|
|
94
|
+
['GenerationLock', [['lockKey']]],
|
|
95
|
+
['CustomStylesheet', [['scope']]],
|
|
96
|
+
['CustomJavascript', [['scope']]],
|
|
97
|
+
['Wallet', [['userId', 'agentPermanentId', 'service', 'key']]],
|
|
98
|
+
['UserData', [['userId', 'key']]],
|
|
99
|
+
['UserPushSubscription', [['endpoint']]],
|
|
100
|
+
]);
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Non-unique indexes for frequent standalone VPS reads.
|
|
104
|
+
*
|
|
105
|
+
* @private constant of `$provideLocalSqliteSupabase`
|
|
106
|
+
*/
|
|
107
|
+
const READ_INDEXES_BY_TABLE = new Map<string, ReadonlyArray<LocalSqliteReadIndex>>([
|
|
108
|
+
[
|
|
109
|
+
'Agent',
|
|
110
|
+
[
|
|
111
|
+
{ name: 'agentName_lookup', columns: ['agentName'] },
|
|
112
|
+
{ name: 'active_directory', columns: ['deletedAt', 'sortOrder', 'agentName'] },
|
|
113
|
+
{ name: 'public_active_directory', columns: ['visibility', 'deletedAt', 'sortOrder', 'agentName'] },
|
|
114
|
+
],
|
|
115
|
+
],
|
|
116
|
+
[
|
|
117
|
+
'AgentFolder',
|
|
118
|
+
[{ name: 'active_directory', columns: ['deletedAt', 'parentId', 'sortOrder', 'name'] }],
|
|
119
|
+
],
|
|
120
|
+
[
|
|
121
|
+
'UserChat',
|
|
122
|
+
[
|
|
123
|
+
{ name: 'user_agent_source_createdAt', columns: ['userId', 'agentPermanentId', 'source', 'createdAt'] },
|
|
124
|
+
{ name: 'agent_source_user_createdAt', columns: ['agentPermanentId', 'source', 'userId', 'createdAt'] },
|
|
125
|
+
],
|
|
126
|
+
],
|
|
127
|
+
[
|
|
128
|
+
'UserChatJob',
|
|
129
|
+
[
|
|
130
|
+
{ name: 'ready_queue', columns: ['status', 'cancelRequestedAt', 'queuedAt', 'createdAt'] },
|
|
131
|
+
{ name: 'active_chat_scope', columns: ['chatId', 'userId', 'agentPermanentId', 'status', 'createdAt'] },
|
|
132
|
+
{ name: 'agent_chat_status', columns: ['agentPermanentId', 'chatId', 'status'] },
|
|
133
|
+
{ name: 'running_lease', columns: ['status', 'leaseExpiresAt'] },
|
|
134
|
+
],
|
|
135
|
+
],
|
|
136
|
+
[
|
|
137
|
+
'UserChatTimeout',
|
|
138
|
+
[
|
|
139
|
+
{ name: 'ready_due', columns: ['status', 'cancelRequestedAt', 'pausedAt', 'dueAt', 'createdAt'] },
|
|
140
|
+
{
|
|
141
|
+
name: 'active_chat_scope',
|
|
142
|
+
columns: ['chatId', 'userId', 'agentPermanentId', 'status', 'pausedAt', 'dueAt', 'createdAt'],
|
|
143
|
+
},
|
|
144
|
+
{ name: 'running_lease', columns: ['status', 'leaseExpiresAt'] },
|
|
145
|
+
],
|
|
146
|
+
],
|
|
147
|
+
]);
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Known unique conflict columns used when `.upsert` omits `onConflict`.
|
|
151
|
+
*
|
|
152
|
+
* @private constant of `$provideLocalSqliteSupabase`
|
|
153
|
+
*/
|
|
154
|
+
const DEFAULT_UPSERT_CONFLICT_COLUMNS_BY_TABLE = new Map<string, ReadonlyArray<string>>([
|
|
155
|
+
['AgentExternals', ['type', 'hash']],
|
|
156
|
+
['LlmCache', ['hash']],
|
|
157
|
+
['VectorStoreKnowledgeSourceHashes', ['source']],
|
|
158
|
+
['Metadata', ['key']],
|
|
159
|
+
['ServerLimit', ['key']],
|
|
160
|
+
]);
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Resolves a table base name from the actual prefixed table name.
|
|
164
|
+
*
|
|
165
|
+
* @private function of `$provideLocalSqliteSupabase`
|
|
166
|
+
*/
|
|
167
|
+
export function resolveTableBaseName(tableName: string): string {
|
|
168
|
+
const knownTableNames = uniqueStrings([
|
|
169
|
+
'_Server',
|
|
170
|
+
...Array.from(JSON_COLUMNS_BY_TABLE.keys()),
|
|
171
|
+
...Array.from(UNIQUE_INDEX_COLUMNS_BY_TABLE.keys()),
|
|
172
|
+
...Array.from(TEXT_PRIMARY_KEY_TABLES),
|
|
173
|
+
'AgentFolder',
|
|
174
|
+
'CustomStylesheet',
|
|
175
|
+
'CustomJavascript',
|
|
176
|
+
'CalendarActivity',
|
|
177
|
+
]).sort((left, right) => right.length - left.length);
|
|
178
|
+
|
|
179
|
+
return knownTableNames.find((knownTableName) => tableName.endsWith(knownTableName)) || tableName;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Resolves columns participating in known unique indexes.
|
|
184
|
+
*
|
|
185
|
+
* @private function of `$provideLocalSqliteSupabase`
|
|
186
|
+
*/
|
|
187
|
+
export function resolveUniqueIndexColumns(tableBaseName: string): Array<string> {
|
|
188
|
+
return resolveUniqueIndexes(tableBaseName).flatMap((columns) => [...columns]);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Resolves columns participating in known read indexes.
|
|
193
|
+
*
|
|
194
|
+
* @private function of `$provideLocalSqliteSupabase`
|
|
195
|
+
*/
|
|
196
|
+
export function resolveReadIndexColumns(tableBaseName: string): Array<string> {
|
|
197
|
+
return resolveReadIndexes(tableBaseName).flatMap((readIndex) => [...readIndex.columns]);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Resolves upsert conflict columns.
|
|
202
|
+
*
|
|
203
|
+
* @private function of `$provideLocalSqliteSupabase`
|
|
204
|
+
*/
|
|
205
|
+
export function resolveUpsertConflictColumns(
|
|
206
|
+
tableBaseName: string,
|
|
207
|
+
options: LocalSqliteUpsertOptions,
|
|
208
|
+
): ReadonlyArray<string> {
|
|
209
|
+
if (options.onConflict) {
|
|
210
|
+
return options.onConflict
|
|
211
|
+
.split(',')
|
|
212
|
+
.map((column) => column.trim())
|
|
213
|
+
.filter(Boolean);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return DEFAULT_UPSERT_CONFLICT_COLUMNS_BY_TABLE.get(tableBaseName) || [];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Resolves the unique index definitions declared for a table base name.
|
|
221
|
+
*
|
|
222
|
+
* @private function of `$provideLocalSqliteSupabase`
|
|
223
|
+
*/
|
|
224
|
+
export function resolveUniqueIndexes(tableBaseName: string): ReadonlyArray<ReadonlyArray<string>> {
|
|
225
|
+
return UNIQUE_INDEX_COLUMNS_BY_TABLE.get(tableBaseName) || [];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Resolves the read index definitions declared for a table base name.
|
|
230
|
+
*
|
|
231
|
+
* @private function of `$provideLocalSqliteSupabase`
|
|
232
|
+
*/
|
|
233
|
+
export function resolveReadIndexes(tableBaseName: string): ReadonlyArray<LocalSqliteReadIndex> {
|
|
234
|
+
return READ_INDEXES_BY_TABLE.get(tableBaseName) || [];
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Resolves whether a column is JSON for a specific table.
|
|
239
|
+
*
|
|
240
|
+
* @private function of `$provideLocalSqliteSupabase`
|
|
241
|
+
*/
|
|
242
|
+
export function isJsonColumn(tableName: string, column: string): boolean {
|
|
243
|
+
return isJsonColumnForTableBaseName(resolveTableBaseName(tableName), column);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Resolves whether a column should be forced to a string for a specific table.
|
|
248
|
+
*
|
|
249
|
+
* @private function of `$provideLocalSqliteSupabase`
|
|
250
|
+
*/
|
|
251
|
+
export function isTextColumn(tableName: string, column: string): boolean {
|
|
252
|
+
return isTextColumnForTableBaseName(resolveTableBaseName(tableName), column);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Resolves whether a column is a boolean stored as an integer.
|
|
257
|
+
*
|
|
258
|
+
* @private function of `$provideLocalSqliteSupabase`
|
|
259
|
+
*/
|
|
260
|
+
export function isBooleanColumn(column: string): boolean {
|
|
261
|
+
return BOOLEAN_COLUMNS.has(column);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Resolves whether a table base name uses a text primary key.
|
|
266
|
+
*
|
|
267
|
+
* @private function of `$provideLocalSqliteSupabase`
|
|
268
|
+
*/
|
|
269
|
+
export function isTextPrimaryKeyTable(tableBaseName: string): boolean {
|
|
270
|
+
return TEXT_PRIMARY_KEY_TABLES.has(tableBaseName);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Resolves SQLite column affinity for dynamically added columns.
|
|
275
|
+
*
|
|
276
|
+
* @private function of `$provideLocalSqliteSupabase`
|
|
277
|
+
*/
|
|
278
|
+
export function resolveSqliteColumnType(tableBaseName: string, column: string): string {
|
|
279
|
+
if (isTextColumnForTableBaseName(tableBaseName, column) || isJsonColumnForTableBaseName(tableBaseName, column)) {
|
|
280
|
+
return 'TEXT';
|
|
281
|
+
}
|
|
282
|
+
if (BOOLEAN_COLUMNS.has(column)) {
|
|
283
|
+
return 'INTEGER';
|
|
284
|
+
}
|
|
285
|
+
if (isIntegerColumnForTableBaseName(tableBaseName, column)) {
|
|
286
|
+
return 'INTEGER';
|
|
287
|
+
}
|
|
288
|
+
if (
|
|
289
|
+
column === 'id' ||
|
|
290
|
+
column.endsWith('Id') ||
|
|
291
|
+
column.endsWith('Count') ||
|
|
292
|
+
column.endsWith('Ms') ||
|
|
293
|
+
column.endsWith('Bytes') ||
|
|
294
|
+
column === 'sortOrder' ||
|
|
295
|
+
column === 'attemptCount' ||
|
|
296
|
+
column === 'runCount'
|
|
297
|
+
) {
|
|
298
|
+
return 'INTEGER';
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return 'TEXT';
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Resolves whether a column is JSON for a specific table base name.
|
|
306
|
+
*
|
|
307
|
+
* @private function of `$provideLocalSqliteSupabase`
|
|
308
|
+
*/
|
|
309
|
+
function isJsonColumnForTableBaseName(tableBaseName: string, column: string): boolean {
|
|
310
|
+
return JSON_COLUMNS_BY_TABLE.get(tableBaseName)?.has(column) || false;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Resolves whether a column should be forced to a string for a specific table base name.
|
|
315
|
+
*
|
|
316
|
+
* @private function of `$provideLocalSqliteSupabase`
|
|
317
|
+
*/
|
|
318
|
+
function isTextColumnForTableBaseName(tableBaseName: string, column: string): boolean {
|
|
319
|
+
return TEXT_COLUMNS_BY_TABLE.get(tableBaseName)?.has(column) || false;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Resolves whether a column is known to be numeric for a specific table base name.
|
|
324
|
+
*
|
|
325
|
+
* @private function of `$provideLocalSqliteSupabase`
|
|
326
|
+
*/
|
|
327
|
+
function isIntegerColumnForTableBaseName(tableBaseName: string, column: string): boolean {
|
|
328
|
+
return INTEGER_COLUMNS_BY_TABLE.get(tableBaseName)?.has(column) || false;
|
|
329
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { TODO_any } from '@promptbook-local/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Minimal query result shape consumed by Agents Server Supabase call sites.
|
|
5
|
+
*
|
|
6
|
+
* @private type of `$provideLocalSqliteSupabase`
|
|
7
|
+
*/
|
|
8
|
+
export type LocalSqliteQueryResult<TData = TODO_any> = {
|
|
9
|
+
readonly data: TData | null;
|
|
10
|
+
readonly error: LocalSqliteError | null;
|
|
11
|
+
readonly count?: number | null;
|
|
12
|
+
readonly status?: number;
|
|
13
|
+
readonly statusText?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Supabase-like error shape returned by the local SQLite adapter.
|
|
18
|
+
*
|
|
19
|
+
* @private type of `$provideLocalSqliteSupabase`
|
|
20
|
+
*/
|
|
21
|
+
export type LocalSqliteError = {
|
|
22
|
+
readonly code?: string;
|
|
23
|
+
readonly message: string;
|
|
24
|
+
readonly details?: string;
|
|
25
|
+
readonly hint?: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Supported query operation kinds.
|
|
30
|
+
*
|
|
31
|
+
* @private type of `$provideLocalSqliteSupabase`
|
|
32
|
+
*/
|
|
33
|
+
export type LocalSqliteOperation = 'select' | 'insert' | 'update' | 'delete' | 'upsert';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Query filter captured from Supabase-like fluent calls.
|
|
37
|
+
*
|
|
38
|
+
* @private type of `$provideLocalSqliteSupabase`
|
|
39
|
+
*/
|
|
40
|
+
export type LocalSqliteFilter = {
|
|
41
|
+
readonly column: string;
|
|
42
|
+
readonly operator: 'eq' | 'neq' | 'is' | 'not-is' | 'in' | 'lt' | 'lte' | 'gt' | 'gte' | 'like' | 'ilike';
|
|
43
|
+
readonly value: unknown;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Query order captured from Supabase-like fluent calls.
|
|
48
|
+
*
|
|
49
|
+
* @private type of `$provideLocalSqliteSupabase`
|
|
50
|
+
*/
|
|
51
|
+
export type LocalSqliteOrder = {
|
|
52
|
+
readonly column: string;
|
|
53
|
+
readonly ascending: boolean;
|
|
54
|
+
readonly nullsFirst?: boolean;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Select options supported by Supabase and used by this app.
|
|
59
|
+
*
|
|
60
|
+
* @private type of `$provideLocalSqliteSupabase`
|
|
61
|
+
*/
|
|
62
|
+
export type LocalSqliteSelectOptions = {
|
|
63
|
+
readonly count?: 'exact';
|
|
64
|
+
readonly head?: boolean;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Upsert options supported by Supabase and used by this app.
|
|
69
|
+
*
|
|
70
|
+
* @private type of `$provideLocalSqliteSupabase`
|
|
71
|
+
*/
|
|
72
|
+
export type LocalSqliteUpsertOptions = {
|
|
73
|
+
readonly onConflict?: string;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* SQL clause fragment paired with its positional bind values.
|
|
78
|
+
*
|
|
79
|
+
* @private type of `$provideLocalSqliteSupabase`
|
|
80
|
+
*/
|
|
81
|
+
export type LocalSqliteSqlFragment = {
|
|
82
|
+
readonly sql: string;
|
|
83
|
+
readonly values: ReadonlyArray<unknown>;
|
|
84
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { isBooleanColumn, isJsonColumn, isTextColumn } from './localSqliteTableSchema';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Serializes one value for SQLite storage.
|
|
5
|
+
*
|
|
6
|
+
* @private function of `$provideLocalSqliteSupabase`
|
|
7
|
+
*/
|
|
8
|
+
export function serializeValue(tableName: string, column: string, value: unknown): unknown {
|
|
9
|
+
if (value === undefined) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
if (value === null) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
if (isTextColumn(tableName, column)) {
|
|
16
|
+
return String(value);
|
|
17
|
+
}
|
|
18
|
+
if (isJsonColumn(tableName, column)) {
|
|
19
|
+
return typeof value === 'string' ? value : JSON.stringify(value);
|
|
20
|
+
}
|
|
21
|
+
if (isBooleanColumn(column)) {
|
|
22
|
+
return value ? 1 : 0;
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Deserializes one SQLite row into Supabase-like row values.
|
|
29
|
+
*
|
|
30
|
+
* @private function of `$provideLocalSqliteSupabase`
|
|
31
|
+
*/
|
|
32
|
+
export function deserializeRow(tableName: string, row: Record<string, unknown>): Record<string, unknown> {
|
|
33
|
+
const result: Record<string, unknown> = {};
|
|
34
|
+
|
|
35
|
+
for (const [column, value] of Object.entries(row)) {
|
|
36
|
+
if (value === null || value === undefined) {
|
|
37
|
+
result[column] = null;
|
|
38
|
+
} else if (isTextColumn(tableName, column)) {
|
|
39
|
+
result[column] = String(value);
|
|
40
|
+
} else if (isJsonColumn(tableName, column) && typeof value === 'string') {
|
|
41
|
+
result[column] = parseJsonValue(value);
|
|
42
|
+
} else if (isBooleanColumn(column)) {
|
|
43
|
+
result[column] = Boolean(value);
|
|
44
|
+
} else {
|
|
45
|
+
result[column] = value;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Parses JSON while preserving invalid strings.
|
|
54
|
+
*
|
|
55
|
+
* @private function of `deserializeRow`
|
|
56
|
+
*/
|
|
57
|
+
function parseJsonValue(value: string): unknown {
|
|
58
|
+
try {
|
|
59
|
+
return JSON.parse(value);
|
|
60
|
+
} catch {
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { LocalSqliteError } from './localSqliteTypes';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts SQLite errors into Supabase-like errors.
|
|
5
|
+
*
|
|
6
|
+
* @private function of `$provideLocalSqliteSupabase`
|
|
7
|
+
*/
|
|
8
|
+
export function normalizeSqliteError(error: unknown): LocalSqliteError {
|
|
9
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
10
|
+
const sqliteCode =
|
|
11
|
+
typeof error === 'object' && error !== null && typeof (error as { code?: unknown }).code === 'string'
|
|
12
|
+
? (error as { code: string }).code
|
|
13
|
+
: undefined;
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
code:
|
|
17
|
+
sqliteCode === 'SQLITE_CONSTRAINT_UNIQUE' || sqliteCode === 'SQLITE_CONSTRAINT_PRIMARYKEY'
|
|
18
|
+
? '23505'
|
|
19
|
+
: sqliteCode,
|
|
20
|
+
message,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -2,7 +2,9 @@ import { $getTableName } from '../../database/$getTableName';
|
|
|
2
2
|
import { $provideSupabaseForServer } from '../../database/$provideSupabaseForServer';
|
|
3
3
|
import type { AgentsServerDatabase } from '../../database/schema';
|
|
4
4
|
import type { AgentBasicInformation } from '../../../../../src/book-2.0/agent-source/AgentBasicInformation';
|
|
5
|
+
import { $provideAgentCollectionForServer } from '../../tools/$provideAgentCollectionForServer';
|
|
5
6
|
import { $provideAgentReferenceResolver } from '../../utils/agentReferenceResolver/$provideAgentReferenceResolver';
|
|
7
|
+
import { createLocalAgentSourceImporter } from '../../utils/createLocalAgentSourceImporter';
|
|
6
8
|
import { getWellKnownAgentUrl } from '../../utils/getWellKnownAgentUrl';
|
|
7
9
|
import { resolveCurrentOrInternalServerOrigin } from '../../utils/resolveCurrentOrInternalServerOrigin';
|
|
8
10
|
import { resolveStoredAgentStates } from '../../utils/resolveStoredAgentState';
|
|
@@ -85,12 +87,21 @@ export async function loadLocalOrganizationSearchDataset(options: {
|
|
|
85
87
|
const folders = (folderResult.data || []) as AgentFolderSearchRow[];
|
|
86
88
|
const localServerUrl = await resolveCurrentOrInternalServerOrigin();
|
|
87
89
|
const agentReferenceResolver = await $provideAgentReferenceResolver();
|
|
90
|
+
const adamAgentUrl = await getWellKnownAgentUrl('ADAM');
|
|
91
|
+
const agentSourceImporter = createLocalAgentSourceImporter({
|
|
92
|
+
collection: await $provideAgentCollectionForServer(),
|
|
93
|
+
localServerUrls: [localServerUrl],
|
|
94
|
+
localAgentUrls: [adamAgentUrl],
|
|
95
|
+
adamAgentUrl,
|
|
96
|
+
fallbackResolver: agentReferenceResolver,
|
|
97
|
+
});
|
|
88
98
|
const resolvedAgents = await resolveStoredAgentStates(
|
|
89
99
|
(agentResult.data || []) as Array<Pick<AgentSearchRow, 'id' | 'agentName' | 'permanentId' | 'agentSource' | 'folderId' | 'visibility'>>,
|
|
90
100
|
{
|
|
91
101
|
localServerUrl,
|
|
92
|
-
adamAgentUrl
|
|
102
|
+
adamAgentUrl,
|
|
93
103
|
agentReferenceResolver,
|
|
104
|
+
agentSourceImporter,
|
|
94
105
|
},
|
|
95
106
|
);
|
|
96
107
|
const agents = resolvedAgents.map((agent) => ({
|
|
@@ -4,7 +4,6 @@ import type { Message } from '../../../../src/types/Message';
|
|
|
4
4
|
import type { OutboundEmail } from '../message-providers/email/_common/Email';
|
|
5
5
|
import { parseEmailAddresses } from '../message-providers/email/_common/utils/parseEmailAddresses';
|
|
6
6
|
import { SmtpMessageProvider } from '../message-providers/email/smtp/SmtpMessageProvider';
|
|
7
|
-
import { humanizeOutboundEmail } from '../utils/messages/humanizeOutboundEmail';
|
|
8
7
|
import { parseUseEmailSmtpCredential } from '../utils/messages/parseUseEmailSmtpCredential';
|
|
9
8
|
import { isSendMessageDeliveryError, sendMessage, type SendMessageResult } from '../utils/messages/sendMessage';
|
|
10
9
|
import {
|
|
@@ -82,7 +81,7 @@ export async function send_email(args: SendEmailToolArgs): Promise<string> {
|
|
|
82
81
|
}
|
|
83
82
|
|
|
84
83
|
const smtpCredential = parseUseEmailSmtpCredential(smtpCredentialRaw);
|
|
85
|
-
const email =
|
|
84
|
+
const email = normalizeSendEmailPayload(args, smtpCredential.fromAddress || defaultFromAddress);
|
|
86
85
|
const smtpProvider = new SmtpMessageProvider({
|
|
87
86
|
host: smtpCredential.host,
|
|
88
87
|
port: smtpCredential.port,
|
|
@@ -2,7 +2,9 @@ import type { AgentBasicInformation } from '../../../../../src/book-2.0/agent-so
|
|
|
2
2
|
import { $getTableName } from '../../database/$getTableName';
|
|
3
3
|
import { $provideSupabaseForServer } from '../../database/$provideSupabaseForServer';
|
|
4
4
|
import type { AgentsServerDatabase } from '../../database/schema';
|
|
5
|
+
import { $provideAgentCollectionForServer } from '../../tools/$provideAgentCollectionForServer';
|
|
5
6
|
import { $provideAgentReferenceResolver } from '../agentReferenceResolver/$provideAgentReferenceResolver';
|
|
7
|
+
import { createLocalAgentSourceImporter } from '../createLocalAgentSourceImporter';
|
|
6
8
|
import { getCurrentUser } from '../getCurrentUser';
|
|
7
9
|
import { getWellKnownAgentUrl } from '../getWellKnownAgentUrl';
|
|
8
10
|
import { resolveCurrentOrInternalServerOrigin } from '../resolveCurrentOrInternalServerOrigin';
|
|
@@ -187,14 +189,24 @@ async function loadResolvedOrganizationSnapshot(options: {
|
|
|
187
189
|
|
|
188
190
|
const localServerUrl = await resolveCurrentOrInternalServerOrigin();
|
|
189
191
|
const agentReferenceResolver = await $provideAgentReferenceResolver();
|
|
192
|
+
const adamAgentUrl = await getWellKnownAgentUrl('ADAM');
|
|
193
|
+
const collection = await $provideAgentCollectionForServer();
|
|
194
|
+
const agentSourceImporter = createLocalAgentSourceImporter({
|
|
195
|
+
collection,
|
|
196
|
+
localServerUrls: [localServerUrl],
|
|
197
|
+
localAgentUrls: [adamAgentUrl],
|
|
198
|
+
adamAgentUrl,
|
|
199
|
+
fallbackResolver: agentReferenceResolver,
|
|
200
|
+
});
|
|
190
201
|
const resolvedAgents = await resolveStoredAgentStates(
|
|
191
202
|
(agentResult.data || []) as Array<
|
|
192
203
|
Pick<AgentRow, 'agentName' | 'agentSource' | 'permanentId' | 'visibility' | 'folderId' | 'sortOrder'>
|
|
193
204
|
>,
|
|
194
205
|
{
|
|
195
206
|
localServerUrl,
|
|
196
|
-
adamAgentUrl
|
|
207
|
+
adamAgentUrl,
|
|
197
208
|
agentReferenceResolver,
|
|
209
|
+
agentSourceImporter,
|
|
198
210
|
},
|
|
199
211
|
);
|
|
200
212
|
const agents = resolvedAgents.map((agent) =>
|