@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,441 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
|
+
import type { CustomCommitPickerCandidate } from './CustomCommitPicker';
|
|
5
|
+
import { getUpdateJobSuccessMessage } from './getUpdateJobSuccessMessage';
|
|
6
|
+
import type { UpdateEnvironmentOption, UpdateOverview } from './UpdateOverview';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Interval (ms) used while polling a running standalone VPS update job.
|
|
10
|
+
*/
|
|
11
|
+
const UPDATE_OVERVIEW_REFRESH_INTERVAL_MS = 4000;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Options for loading the standalone VPS update overview.
|
|
15
|
+
*
|
|
16
|
+
* @private type of `useUpdateClientState`
|
|
17
|
+
*/
|
|
18
|
+
type LoadUpdateOverviewOptions = {
|
|
19
|
+
readonly isSilent?: boolean;
|
|
20
|
+
readonly isRestartExpected?: boolean;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Body sent when starting a standalone VPS self-update.
|
|
25
|
+
*
|
|
26
|
+
* @private type of `useUpdateClientState`
|
|
27
|
+
*/
|
|
28
|
+
type StartUpdateRequestBody = {
|
|
29
|
+
readonly environment: string;
|
|
30
|
+
readonly customRef: string | null;
|
|
31
|
+
readonly originRepositoryUrl: string | null;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Options used to build the start-update request body.
|
|
36
|
+
*
|
|
37
|
+
* @private type of `useUpdateClientState`
|
|
38
|
+
*/
|
|
39
|
+
type CreateStartUpdateRequestBodyOptions = {
|
|
40
|
+
readonly selectedEnvironment: UpdateEnvironmentOption;
|
|
41
|
+
readonly isCustomEnvironmentSelected: boolean;
|
|
42
|
+
readonly customRef: string;
|
|
43
|
+
readonly isOriginRepositoryUrlOverrideChanged: boolean;
|
|
44
|
+
readonly originRepositoryUrlOverride: string;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Options used to build the user-facing start-update success message.
|
|
49
|
+
*
|
|
50
|
+
* @private type of `useUpdateClientState`
|
|
51
|
+
*/
|
|
52
|
+
type CreateStartUpdateSuccessMessageOptions = {
|
|
53
|
+
readonly selectedEnvironment: UpdateEnvironmentOption;
|
|
54
|
+
readonly isCustomEnvironmentSelected: boolean;
|
|
55
|
+
readonly isEnvironmentSwitchRequired: boolean;
|
|
56
|
+
readonly customRef: string;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* State and actions used by the standalone VPS update client page.
|
|
61
|
+
*
|
|
62
|
+
* @private type of `<UpdateClient/>`
|
|
63
|
+
*/
|
|
64
|
+
export type UpdateClientState = {
|
|
65
|
+
readonly overview: UpdateOverview | null;
|
|
66
|
+
readonly selectedEnvironment: UpdateEnvironmentOption | null;
|
|
67
|
+
readonly customRef: string;
|
|
68
|
+
readonly originRepositoryUrlOverride: string;
|
|
69
|
+
readonly isAdvancedExpanded: boolean;
|
|
70
|
+
readonly isLoading: boolean;
|
|
71
|
+
readonly isStartingUpdate: boolean;
|
|
72
|
+
readonly errorMessage: string | null;
|
|
73
|
+
readonly successMessage: string | null;
|
|
74
|
+
readonly isCustomEnvironmentSelected: boolean;
|
|
75
|
+
readonly isEnvironmentSwitchRequired: boolean;
|
|
76
|
+
readonly isUpdateRunning: boolean;
|
|
77
|
+
readonly isCustomRefRelease: boolean;
|
|
78
|
+
readonly isCustomRefMissing: boolean;
|
|
79
|
+
readonly isOriginRepositoryUrlOverrideChanged: boolean;
|
|
80
|
+
readonly updateTerminalId: string;
|
|
81
|
+
readonly updateTerminalEmptyState: string;
|
|
82
|
+
readonly loadOverview: (options?: LoadUpdateOverviewOptions) => Promise<void>;
|
|
83
|
+
readonly startUpdate: () => Promise<void>;
|
|
84
|
+
readonly selectEnvironment: (environmentId: string) => void;
|
|
85
|
+
readonly selectCustomRef: (
|
|
86
|
+
nextRef: string,
|
|
87
|
+
matchedCandidate: CustomCommitPickerCandidate | null,
|
|
88
|
+
) => void;
|
|
89
|
+
readonly changeOriginRepositoryUrlOverride: (nextValue: string) => void;
|
|
90
|
+
readonly toggleAdvanced: () => void;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Collects standalone VPS update page state, polling, and mutation actions behind one focused hook.
|
|
95
|
+
*
|
|
96
|
+
* @returns State and actions needed to render `<UpdateClient/>`.
|
|
97
|
+
*
|
|
98
|
+
* @private hook of `<UpdateClient/>`
|
|
99
|
+
*/
|
|
100
|
+
export function useUpdateClientState(): UpdateClientState {
|
|
101
|
+
const [overview, setOverview] = useState<UpdateOverview | null>(null);
|
|
102
|
+
const [selectedEnvironmentId, setSelectedEnvironmentId] = useState<string>('');
|
|
103
|
+
const [customRef, setCustomRef] = useState<string>('');
|
|
104
|
+
const [customCandidate, setCustomCandidate] = useState<CustomCommitPickerCandidate | null>(null);
|
|
105
|
+
const [originRepositoryUrlOverride, setOriginRepositoryUrlOverride] = useState<string>('');
|
|
106
|
+
const [isAdvancedExpanded, setIsAdvancedExpanded] = useState<boolean>(false);
|
|
107
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
108
|
+
const [isStartingUpdate, setIsStartingUpdate] = useState(false);
|
|
109
|
+
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
|
110
|
+
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
|
111
|
+
|
|
112
|
+
const loadOverview = useCallback(async (options?: LoadUpdateOverviewOptions): Promise<void> => {
|
|
113
|
+
try {
|
|
114
|
+
if (!options?.isSilent) {
|
|
115
|
+
setIsLoading(true);
|
|
116
|
+
}
|
|
117
|
+
setErrorMessage(null);
|
|
118
|
+
|
|
119
|
+
const payload = await fetchUpdateOverview();
|
|
120
|
+
|
|
121
|
+
setOverview(payload);
|
|
122
|
+
setSelectedEnvironmentId(
|
|
123
|
+
(currentSelectedEnvironmentId) => currentSelectedEnvironmentId || payload.currentEnvironment.id,
|
|
124
|
+
);
|
|
125
|
+
setOriginRepositoryUrlOverride((currentValue) => currentValue || payload.originRepositoryUrl);
|
|
126
|
+
if (payload.job.status === 'succeeded') {
|
|
127
|
+
setSuccessMessage(getUpdateJobSuccessMessage(payload.job));
|
|
128
|
+
} else if (payload.job.status === 'failed') {
|
|
129
|
+
setSuccessMessage(null);
|
|
130
|
+
}
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (options?.isRestartExpected) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
setErrorMessage(getErrorMessage(error, 'Failed to load the update overview.'));
|
|
137
|
+
} finally {
|
|
138
|
+
if (!options?.isSilent) {
|
|
139
|
+
setIsLoading(false);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}, []);
|
|
143
|
+
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
void loadOverview();
|
|
146
|
+
}, [loadOverview]);
|
|
147
|
+
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
if (overview?.job.status !== 'running') {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const interval = window.setInterval(() => {
|
|
154
|
+
void loadOverview({ isSilent: true, isRestartExpected: true });
|
|
155
|
+
}, UPDATE_OVERVIEW_REFRESH_INTERVAL_MS);
|
|
156
|
+
|
|
157
|
+
return () => {
|
|
158
|
+
window.clearInterval(interval);
|
|
159
|
+
};
|
|
160
|
+
}, [loadOverview, overview?.job.status]);
|
|
161
|
+
|
|
162
|
+
const selectedEnvironment = useMemo(
|
|
163
|
+
() => getSelectedEnvironment(overview, selectedEnvironmentId),
|
|
164
|
+
[overview, selectedEnvironmentId],
|
|
165
|
+
);
|
|
166
|
+
const isCustomEnvironmentSelected = selectedEnvironment?.isCustom === true;
|
|
167
|
+
const isEnvironmentSwitchRequired = isUpdateEnvironmentSwitchRequired(selectedEnvironment, overview);
|
|
168
|
+
const isUpdateRunning = overview?.job.status === 'running';
|
|
169
|
+
const isCustomRefRelease = isCustomEnvironmentSelected ? customCandidate?.isReleaseTag === true : true;
|
|
170
|
+
const isCustomRefMissing = isCustomEnvironmentSelected && !customRef.trim();
|
|
171
|
+
const isOriginRepositoryUrlOverrideChanged = isOriginRepositoryUrlOverrideChangedForOverview(
|
|
172
|
+
overview,
|
|
173
|
+
originRepositoryUrlOverride,
|
|
174
|
+
);
|
|
175
|
+
const updateTerminalId = buildUpdateTerminalId(overview);
|
|
176
|
+
const updateTerminalEmptyState = getUpdateTerminalEmptyState(isLoading, overview);
|
|
177
|
+
|
|
178
|
+
const startUpdate = useCallback(async (): Promise<void> => {
|
|
179
|
+
if (!selectedEnvironment) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
setIsStartingUpdate(true);
|
|
185
|
+
setErrorMessage(null);
|
|
186
|
+
setSuccessMessage(null);
|
|
187
|
+
|
|
188
|
+
const payload = await startUpdateJob(
|
|
189
|
+
createStartUpdateRequestBody({
|
|
190
|
+
selectedEnvironment,
|
|
191
|
+
isCustomEnvironmentSelected,
|
|
192
|
+
customRef,
|
|
193
|
+
isOriginRepositoryUrlOverrideChanged,
|
|
194
|
+
originRepositoryUrlOverride,
|
|
195
|
+
}),
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
setOverview(payload);
|
|
199
|
+
setSuccessMessage(
|
|
200
|
+
createStartUpdateSuccessMessage({
|
|
201
|
+
selectedEnvironment,
|
|
202
|
+
isCustomEnvironmentSelected,
|
|
203
|
+
isEnvironmentSwitchRequired,
|
|
204
|
+
customRef,
|
|
205
|
+
}),
|
|
206
|
+
);
|
|
207
|
+
} catch (error) {
|
|
208
|
+
setErrorMessage(getErrorMessage(error, 'Failed to start the update.'));
|
|
209
|
+
} finally {
|
|
210
|
+
setIsStartingUpdate(false);
|
|
211
|
+
}
|
|
212
|
+
}, [
|
|
213
|
+
customRef,
|
|
214
|
+
isCustomEnvironmentSelected,
|
|
215
|
+
isEnvironmentSwitchRequired,
|
|
216
|
+
isOriginRepositoryUrlOverrideChanged,
|
|
217
|
+
originRepositoryUrlOverride,
|
|
218
|
+
selectedEnvironment,
|
|
219
|
+
]);
|
|
220
|
+
|
|
221
|
+
const selectEnvironment = useCallback((environmentId: string): void => {
|
|
222
|
+
setSelectedEnvironmentId(environmentId);
|
|
223
|
+
}, []);
|
|
224
|
+
|
|
225
|
+
const selectCustomRef = useCallback(
|
|
226
|
+
(nextRef: string, matchedCandidate: CustomCommitPickerCandidate | null): void => {
|
|
227
|
+
setCustomRef(nextRef);
|
|
228
|
+
setCustomCandidate(matchedCandidate);
|
|
229
|
+
},
|
|
230
|
+
[],
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
const toggleAdvanced = useCallback((): void => {
|
|
234
|
+
setIsAdvancedExpanded((current) => !current);
|
|
235
|
+
}, []);
|
|
236
|
+
|
|
237
|
+
return {
|
|
238
|
+
overview,
|
|
239
|
+
selectedEnvironment,
|
|
240
|
+
customRef,
|
|
241
|
+
originRepositoryUrlOverride,
|
|
242
|
+
isAdvancedExpanded,
|
|
243
|
+
isLoading,
|
|
244
|
+
isStartingUpdate,
|
|
245
|
+
errorMessage,
|
|
246
|
+
successMessage,
|
|
247
|
+
isCustomEnvironmentSelected,
|
|
248
|
+
isEnvironmentSwitchRequired,
|
|
249
|
+
isUpdateRunning,
|
|
250
|
+
isCustomRefRelease,
|
|
251
|
+
isCustomRefMissing,
|
|
252
|
+
isOriginRepositoryUrlOverrideChanged,
|
|
253
|
+
updateTerminalId,
|
|
254
|
+
updateTerminalEmptyState,
|
|
255
|
+
loadOverview,
|
|
256
|
+
startUpdate,
|
|
257
|
+
selectEnvironment,
|
|
258
|
+
selectCustomRef,
|
|
259
|
+
changeOriginRepositoryUrlOverride: setOriginRepositoryUrlOverride,
|
|
260
|
+
toggleAdvanced,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Loads the latest standalone VPS update overview from the admin API.
|
|
266
|
+
*
|
|
267
|
+
* @returns Parsed update overview.
|
|
268
|
+
*
|
|
269
|
+
* @private function of `useUpdateClientState`
|
|
270
|
+
*/
|
|
271
|
+
async function fetchUpdateOverview(): Promise<UpdateOverview> {
|
|
272
|
+
const response = await fetch('/api/admin/update', { cache: 'no-store' });
|
|
273
|
+
const payload = (await response.json()) as UpdateOverview;
|
|
274
|
+
|
|
275
|
+
if (!response.ok) {
|
|
276
|
+
throw new Error(payload.error || 'Failed to load the update overview.');
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return payload;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Starts a standalone VPS update job with the prepared API request body.
|
|
284
|
+
*
|
|
285
|
+
* @param requestBody - Target environment/ref/origin payload.
|
|
286
|
+
* @returns Updated overview snapshot returned by the server.
|
|
287
|
+
*
|
|
288
|
+
* @private function of `useUpdateClientState`
|
|
289
|
+
*/
|
|
290
|
+
async function startUpdateJob(requestBody: StartUpdateRequestBody): Promise<UpdateOverview> {
|
|
291
|
+
const response = await fetch('/api/admin/update', {
|
|
292
|
+
method: 'POST',
|
|
293
|
+
headers: {
|
|
294
|
+
'Content-Type': 'application/json',
|
|
295
|
+
},
|
|
296
|
+
body: JSON.stringify(requestBody),
|
|
297
|
+
});
|
|
298
|
+
const payload = (await response.json()) as UpdateOverview;
|
|
299
|
+
|
|
300
|
+
if (!response.ok) {
|
|
301
|
+
throw new Error(payload.error || 'Failed to start the update.');
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return payload;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Builds the POST body for starting the update without mixing UI state decisions into the network call.
|
|
309
|
+
*
|
|
310
|
+
* @param options - Current target environment, custom ref, and origin override state.
|
|
311
|
+
* @returns Request body accepted by `/api/admin/update`.
|
|
312
|
+
*
|
|
313
|
+
* @private function of `useUpdateClientState`
|
|
314
|
+
*/
|
|
315
|
+
function createStartUpdateRequestBody(options: CreateStartUpdateRequestBodyOptions): StartUpdateRequestBody {
|
|
316
|
+
const {
|
|
317
|
+
customRef,
|
|
318
|
+
isCustomEnvironmentSelected,
|
|
319
|
+
isOriginRepositoryUrlOverrideChanged,
|
|
320
|
+
originRepositoryUrlOverride,
|
|
321
|
+
selectedEnvironment,
|
|
322
|
+
} = options;
|
|
323
|
+
|
|
324
|
+
return {
|
|
325
|
+
environment: selectedEnvironment.id,
|
|
326
|
+
customRef: isCustomEnvironmentSelected ? customRef.trim() : null,
|
|
327
|
+
originRepositoryUrl: isOriginRepositoryUrlOverrideChanged ? originRepositoryUrlOverride.trim() : null,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Resolves the success message shown after the update job is accepted by the server.
|
|
333
|
+
*
|
|
334
|
+
* @param options - Target selection state used to describe the accepted job.
|
|
335
|
+
* @returns Human-readable success message.
|
|
336
|
+
*
|
|
337
|
+
* @private function of `useUpdateClientState`
|
|
338
|
+
*/
|
|
339
|
+
function createStartUpdateSuccessMessage(options: CreateStartUpdateSuccessMessageOptions): string {
|
|
340
|
+
const { customRef, isCustomEnvironmentSelected, isEnvironmentSwitchRequired, selectedEnvironment } = options;
|
|
341
|
+
|
|
342
|
+
if (isCustomEnvironmentSelected) {
|
|
343
|
+
return `Started the standalone VPS update to custom ref ${customRef.trim()}.`;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (isEnvironmentSwitchRequired) {
|
|
347
|
+
return `Switched to ${selectedEnvironment.label} and started the standalone VPS update.`;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
return 'Standalone VPS update started.';
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Selects the target environment from the current overview and selected id.
|
|
355
|
+
*
|
|
356
|
+
* @param overview - Current overview snapshot.
|
|
357
|
+
* @param selectedEnvironmentId - Environment id selected in the UI.
|
|
358
|
+
* @returns Selected environment, current environment fallback, or `null` while loading.
|
|
359
|
+
*
|
|
360
|
+
* @private function of `useUpdateClientState`
|
|
361
|
+
*/
|
|
362
|
+
function getSelectedEnvironment(
|
|
363
|
+
overview: UpdateOverview | null,
|
|
364
|
+
selectedEnvironmentId: string,
|
|
365
|
+
): UpdateEnvironmentOption | null {
|
|
366
|
+
return (
|
|
367
|
+
overview?.environments.find((environment) => environment.id === selectedEnvironmentId) ||
|
|
368
|
+
overview?.currentEnvironment ||
|
|
369
|
+
null
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Resolves whether the selected target differs from the currently tracked environment.
|
|
375
|
+
*
|
|
376
|
+
* @param selectedEnvironment - Environment selected in the UI.
|
|
377
|
+
* @param overview - Current overview snapshot.
|
|
378
|
+
* @returns `true` when updating also switches branches/environments.
|
|
379
|
+
*
|
|
380
|
+
* @private function of `useUpdateClientState`
|
|
381
|
+
*/
|
|
382
|
+
function isUpdateEnvironmentSwitchRequired(
|
|
383
|
+
selectedEnvironment: UpdateEnvironmentOption | null,
|
|
384
|
+
overview: UpdateOverview | null,
|
|
385
|
+
): boolean {
|
|
386
|
+
return Boolean(selectedEnvironment) && selectedEnvironment?.id !== overview?.currentEnvironment.id;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Resolves whether the upstream repository input differs from the persisted origin URL.
|
|
391
|
+
*
|
|
392
|
+
* @param overview - Current overview snapshot.
|
|
393
|
+
* @param originRepositoryUrlOverride - Current upstream repository input value.
|
|
394
|
+
* @returns `true` when the input should be sent with the update request.
|
|
395
|
+
*
|
|
396
|
+
* @private function of `useUpdateClientState`
|
|
397
|
+
*/
|
|
398
|
+
function isOriginRepositoryUrlOverrideChangedForOverview(
|
|
399
|
+
overview: UpdateOverview | null,
|
|
400
|
+
originRepositoryUrlOverride: string,
|
|
401
|
+
): boolean {
|
|
402
|
+
return overview !== null && originRepositoryUrlOverride.trim() !== overview.originRepositoryUrl;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Builds a stable terminal id for the latest visible update job.
|
|
407
|
+
*
|
|
408
|
+
* @param overview - Current overview snapshot.
|
|
409
|
+
* @returns Terminal id used by `<AdminXtermTerminal/>`.
|
|
410
|
+
*
|
|
411
|
+
* @private function of `useUpdateClientState`
|
|
412
|
+
*/
|
|
413
|
+
function buildUpdateTerminalId(overview: UpdateOverview | null): string {
|
|
414
|
+
return `standalone-vps-update:${overview?.job.startedAt || overview?.job.finishedAt || overview?.job.status || 'loading'}`;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Builds the log empty-state text from the current loading state.
|
|
419
|
+
*
|
|
420
|
+
* @param isLoading - Whether the initial overview load is still in progress.
|
|
421
|
+
* @param overview - Current overview snapshot.
|
|
422
|
+
* @returns Empty-state message for the update terminal.
|
|
423
|
+
*
|
|
424
|
+
* @private function of `useUpdateClientState`
|
|
425
|
+
*/
|
|
426
|
+
function getUpdateTerminalEmptyState(isLoading: boolean, overview: UpdateOverview | null): string {
|
|
427
|
+
return isLoading && !overview ? 'Loading update log...' : 'No persisted update log output yet.';
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Extracts a message from unknown caught values while preserving the existing fallback behavior.
|
|
432
|
+
*
|
|
433
|
+
* @param error - Unknown caught value.
|
|
434
|
+
* @param fallbackMessage - Message used when the caught value is not an `Error`.
|
|
435
|
+
* @returns Human-readable error message.
|
|
436
|
+
*
|
|
437
|
+
* @private function of `useUpdateClientState`
|
|
438
|
+
*/
|
|
439
|
+
function getErrorMessage(error: unknown, fallbackMessage: string): string {
|
|
440
|
+
return error instanceof Error ? error.message : fallbackMessage;
|
|
441
|
+
}
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
import { loadFederatedAgentImportConfiguration } from '@/src/utils/federatedAgentImportConfiguration';
|
|
9
9
|
import { getCurrentUser } from '@/src/utils/getCurrentUser';
|
|
10
10
|
import { getWellKnownAgentUrl } from '@/src/utils/getWellKnownAgentUrl';
|
|
11
|
+
import { createLocalAgentSourceImporter } from '@/src/utils/createLocalAgentSourceImporter';
|
|
11
12
|
import { resolveInheritedAgentSource } from '@/src/utils/resolveInheritedAgentSource';
|
|
12
13
|
import { padBook, validateBook } from '@promptbook-local/core';
|
|
13
14
|
import type { string_agent_url } from '@promptbook-local/types';
|
|
@@ -96,13 +97,24 @@ export async function GET(request: Request, { params }: { params: Promise<{ agen
|
|
|
96
97
|
const agentSource = resolvedAgentContext.unresolvedAgentSource;
|
|
97
98
|
const agentReferenceResolver = resolvedAgentContext.scopedAgentReferenceResolver;
|
|
98
99
|
const federatedAgentImportConfiguration = await loadFederatedAgentImportConfiguration();
|
|
100
|
+
const adamAgentUrl = await getWellKnownAgentUrl('ADAM');
|
|
101
|
+
const localServerUrl = new URL(request.url).origin;
|
|
102
|
+
const agentSourceImporter = createLocalAgentSourceImporter({
|
|
103
|
+
collection,
|
|
104
|
+
localServerUrls: [localServerUrl],
|
|
105
|
+
localAgentUrls: [adamAgentUrl],
|
|
106
|
+
adamAgentUrl,
|
|
107
|
+
fallbackResolver: baseAgentReferenceResolver,
|
|
108
|
+
federatedAgentImportConfiguration,
|
|
109
|
+
});
|
|
99
110
|
const effectiveAgentSource = await resolveInheritedAgentSource(agentSource, {
|
|
100
|
-
adamAgentUrl
|
|
111
|
+
adamAgentUrl,
|
|
101
112
|
recursionLevel,
|
|
102
113
|
currentAgentUrl: resolvedAgentContext.canonicalAgentUrl,
|
|
103
114
|
inheritancePath: inheritancePath as Array<string_agent_url>,
|
|
104
115
|
agentReferenceResolver,
|
|
105
116
|
federatedAgentImportConfiguration,
|
|
117
|
+
agentSourceImporter,
|
|
106
118
|
});
|
|
107
119
|
const etag = `W/"${computeHash(effectiveAgentSource)}"`;
|
|
108
120
|
|