@promptbook/cli 0.113.0-5 → 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 +96 -57
- 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/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/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/avatars/avatarAnimationScheduler.ts +2 -1
- 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 +727 -781
- package/src/utils/ascii-art/convertImageDataToAsciiArt.ts +1 -4
- package/src/version.ts +2 -2
- package/src/versions.txt +1 -0
- package/umd/index.umd.js +96 -57
- 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/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/version.d.ts +1 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createMockedChatParticipantId,
|
|
3
|
+
type MockedChatParticipant,
|
|
4
|
+
type MockedChatPreset,
|
|
5
|
+
type MockedChatScriptedMessage,
|
|
6
|
+
} from '@/src/utils/mockedChatsSchema';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Adds one participant to the current draft.
|
|
10
|
+
*
|
|
11
|
+
* @private function of <MockedChatsEditorClient/>
|
|
12
|
+
*/
|
|
13
|
+
export function createDraftWithAddedParticipant(previousDraft: MockedChatPreset): MockedChatPreset {
|
|
14
|
+
const nextParticipants = [...previousDraft.participants, createDraftParticipant(previousDraft.participants.length)];
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
...previousDraft,
|
|
18
|
+
participants: nextParticipants,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Updates one participant field in the draft.
|
|
24
|
+
*
|
|
25
|
+
* @private function of <MockedChatsEditorClient/>
|
|
26
|
+
*/
|
|
27
|
+
export function createDraftWithUpdatedParticipant<TField extends keyof MockedChatParticipant>(
|
|
28
|
+
previousDraft: MockedChatPreset,
|
|
29
|
+
participantId: string,
|
|
30
|
+
field: TField,
|
|
31
|
+
value: MockedChatParticipant[TField],
|
|
32
|
+
): MockedChatPreset {
|
|
33
|
+
const nextParticipants = updateParticipantsAfterFieldChange(previousDraft.participants, participantId, field, value);
|
|
34
|
+
const fallbackSenderId = nextParticipants[0]?.id || previousDraft.messages[0]?.senderId || 'USER';
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
...previousDraft,
|
|
38
|
+
participants: nextParticipants,
|
|
39
|
+
messages: reconcileMessageSenderIds(previousDraft.messages, nextParticipants, fallbackSenderId),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Removes one participant from the draft.
|
|
45
|
+
*
|
|
46
|
+
* @private function of <MockedChatsEditorClient/>
|
|
47
|
+
*/
|
|
48
|
+
export function createDraftWithRemovedParticipant(previousDraft: MockedChatPreset, participantId: string): MockedChatPreset {
|
|
49
|
+
const remainingParticipants = previousDraft.participants.filter((participant) => participant.id !== participantId);
|
|
50
|
+
if (remainingParticipants.length === 0) {
|
|
51
|
+
return previousDraft;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const nextParticipants = ensureParticipantMarkedAsMe(remainingParticipants);
|
|
55
|
+
const fallbackSenderId = nextParticipants[0]?.id || 'USER';
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
...previousDraft,
|
|
59
|
+
participants: nextParticipants,
|
|
60
|
+
messages: reconcileMessageSenderIds(previousDraft.messages, nextParticipants, fallbackSenderId),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Creates one participant draft with deterministic defaults.
|
|
66
|
+
*
|
|
67
|
+
* @private function of <MockedChatsEditorClient/>
|
|
68
|
+
*/
|
|
69
|
+
function createDraftParticipant(participantCount: number): MockedChatParticipant {
|
|
70
|
+
return {
|
|
71
|
+
id: createMockedChatParticipantId(),
|
|
72
|
+
name: `Participant ${participantCount + 1}`,
|
|
73
|
+
isMe: participantCount === 0,
|
|
74
|
+
bubbleColor: '#2563eb',
|
|
75
|
+
avatarUrl: null,
|
|
76
|
+
typingAvatarUrl: null,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Ensures at least one participant remains marked as `isMe`.
|
|
82
|
+
*
|
|
83
|
+
* @private function of <MockedChatsEditorClient/>
|
|
84
|
+
*/
|
|
85
|
+
function ensureParticipantMarkedAsMe(participants: Array<MockedChatParticipant>): Array<MockedChatParticipant> {
|
|
86
|
+
if (participants.some((participant) => participant.isMe) || participants.length === 0) {
|
|
87
|
+
return participants;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const nextParticipants = [...participants];
|
|
91
|
+
nextParticipants[0] = {
|
|
92
|
+
...nextParticipants[0],
|
|
93
|
+
isMe: true,
|
|
94
|
+
};
|
|
95
|
+
return nextParticipants;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Reconciles message sender ids after participant changes.
|
|
100
|
+
*
|
|
101
|
+
* @private function of <MockedChatsEditorClient/>
|
|
102
|
+
*/
|
|
103
|
+
function reconcileMessageSenderIds(
|
|
104
|
+
messages: ReadonlyArray<MockedChatScriptedMessage>,
|
|
105
|
+
participants: ReadonlyArray<MockedChatParticipant>,
|
|
106
|
+
fallbackSenderId: string,
|
|
107
|
+
): Array<MockedChatScriptedMessage> {
|
|
108
|
+
return messages.map((message) => ({
|
|
109
|
+
...message,
|
|
110
|
+
senderId: participants.some((participant) => participant.id === message.senderId)
|
|
111
|
+
? message.senderId
|
|
112
|
+
: fallbackSenderId,
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Applies one participant field update and keeps the "me" invariant.
|
|
118
|
+
*
|
|
119
|
+
* @private function of <MockedChatsEditorClient/>
|
|
120
|
+
*/
|
|
121
|
+
function updateParticipantsAfterFieldChange<TField extends keyof MockedChatParticipant>(
|
|
122
|
+
participants: ReadonlyArray<MockedChatParticipant>,
|
|
123
|
+
participantId: string,
|
|
124
|
+
field: TField,
|
|
125
|
+
value: MockedChatParticipant[TField],
|
|
126
|
+
): Array<MockedChatParticipant> {
|
|
127
|
+
let nextParticipants = participants.map((participant) => {
|
|
128
|
+
if (participant.id !== participantId) {
|
|
129
|
+
return participant;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
...participant,
|
|
134
|
+
[field]: value,
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
if (field === 'isMe' && value === true) {
|
|
139
|
+
nextParticipants = nextParticipants.map((participant) => ({
|
|
140
|
+
...participant,
|
|
141
|
+
isMe: participant.id === participantId,
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return nextParticipants;
|
|
146
|
+
}
|
package/apps/agents-server/src/app/system/utilities/mocked-chats/createDraftWithUpdatedSettings.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MockedChatPreset, MockedChatSettings } from '@/src/utils/mockedChatsSchema';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Applies one settings patch to the draft.
|
|
5
|
+
*
|
|
6
|
+
* @private function of <MockedChatsEditorClient/>
|
|
7
|
+
*/
|
|
8
|
+
export function createDraftWithUpdatedSettings(
|
|
9
|
+
previousDraft: MockedChatPreset,
|
|
10
|
+
settingsPatch: Partial<MockedChatSettings>,
|
|
11
|
+
): MockedChatPreset {
|
|
12
|
+
return {
|
|
13
|
+
...previousDraft,
|
|
14
|
+
settings: {
|
|
15
|
+
...previousDraft.settings,
|
|
16
|
+
...settingsPatch,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createMockedChatId, type MockedChatPreset } from '@/src/utils/mockedChatsSchema';
|
|
2
|
+
import { cloneMockedChatPreset } from './cloneMockedChatPreset';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a local duplicate draft from the current editor content.
|
|
6
|
+
*
|
|
7
|
+
* @private function of <MockedChatsEditorClient/>
|
|
8
|
+
*/
|
|
9
|
+
export function createDuplicatedDraft(draftChat: MockedChatPreset): MockedChatPreset {
|
|
10
|
+
const duplicatedDraft = cloneMockedChatPreset(draftChat);
|
|
11
|
+
duplicatedDraft.id = createMockedChatId();
|
|
12
|
+
duplicatedDraft.name = buildCopyName(draftChat.name);
|
|
13
|
+
duplicatedDraft.createdAt = new Date().toISOString();
|
|
14
|
+
duplicatedDraft.updatedAt = duplicatedDraft.createdAt;
|
|
15
|
+
return duplicatedDraft;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Normalizes the draft before saving it over its current id.
|
|
20
|
+
*
|
|
21
|
+
* @private function of <MockedChatsEditorClient/>
|
|
22
|
+
*/
|
|
23
|
+
export function createNormalizedDraftForSave(
|
|
24
|
+
draftChat: MockedChatPreset,
|
|
25
|
+
selectedSavedChat: MockedChatPreset | null,
|
|
26
|
+
): MockedChatPreset {
|
|
27
|
+
const nowIso = new Date().toISOString();
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
...cloneMockedChatPreset(draftChat),
|
|
31
|
+
name: draftChat.name.trim() || 'Untitled mocked chat',
|
|
32
|
+
updatedAt: nowIso,
|
|
33
|
+
createdAt: selectedSavedChat?.createdAt || draftChat.createdAt || nowIso,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates the saved-copy payload used by "Save as New".
|
|
39
|
+
*
|
|
40
|
+
* @private function of <MockedChatsEditorClient/>
|
|
41
|
+
*/
|
|
42
|
+
export function createDraftForSaveAsNew(draftChat: MockedChatPreset): MockedChatPreset {
|
|
43
|
+
const nowIso = new Date().toISOString();
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
...cloneMockedChatPreset(draftChat),
|
|
47
|
+
id: createMockedChatId(),
|
|
48
|
+
name: buildCopyName(draftChat.name),
|
|
49
|
+
createdAt: nowIso,
|
|
50
|
+
updatedAt: nowIso,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Builds a user-friendly duplicate name.
|
|
56
|
+
*
|
|
57
|
+
* @private function of <MockedChatsEditorClient/>
|
|
58
|
+
*/
|
|
59
|
+
function buildCopyName(name: string): string {
|
|
60
|
+
const trimmedName = name.trim();
|
|
61
|
+
if (!trimmedName) {
|
|
62
|
+
return 'Untitled mocked chat copy';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return trimmedName.toLowerCase().endsWith('copy') ? trimmedName : `${trimmedName} copy`;
|
|
66
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { MockedChatPreset } from '@/src/utils/mockedChatsSchema';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Finds one mocked chat by id.
|
|
5
|
+
*
|
|
6
|
+
* @private function of <MockedChatsEditorClient/>
|
|
7
|
+
*/
|
|
8
|
+
export function findMockedChatById(
|
|
9
|
+
mockedChats: ReadonlyArray<MockedChatPreset>,
|
|
10
|
+
mockedChatId: string | null,
|
|
11
|
+
): MockedChatPreset | null {
|
|
12
|
+
if (!mockedChatId) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return mockedChats.find((mockedChat) => mockedChat.id === mockedChatId) || null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Checks whether the draft differs from the selected saved chat.
|
|
21
|
+
*
|
|
22
|
+
* @private function of <MockedChatsEditorClient/>
|
|
23
|
+
*/
|
|
24
|
+
export function isMockedChatDraftDirty(selectedSavedChat: MockedChatPreset | null, draftChat: MockedChatPreset): boolean {
|
|
25
|
+
if (!selectedSavedChat) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return JSON.stringify(selectedSavedChat) !== JSON.stringify(draftChat);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Upserts one mocked-chat preset by id while preserving list order by updated date.
|
|
34
|
+
*
|
|
35
|
+
* @private function of <MockedChatsEditorClient/>
|
|
36
|
+
*/
|
|
37
|
+
export function upsertMockedChatPreset(
|
|
38
|
+
presets: ReadonlyArray<MockedChatPreset>,
|
|
39
|
+
incomingPreset: MockedChatPreset,
|
|
40
|
+
): Array<MockedChatPreset> {
|
|
41
|
+
const existingIndex = presets.findIndex((preset) => preset.id === incomingPreset.id);
|
|
42
|
+
const nextPresets = [...presets];
|
|
43
|
+
|
|
44
|
+
if (existingIndex === -1) {
|
|
45
|
+
nextPresets.push(incomingPreset);
|
|
46
|
+
} else {
|
|
47
|
+
nextPresets[existingIndex] = incomingPreset;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return nextPresets.sort((leftPreset, rightPreset) => Date.parse(rightPreset.updatedAt) - Date.parse(leftPreset.updatedAt));
|
|
51
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { MockedChatPreset } from '@/src/utils/mockedChatsSchema';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* API endpoint used by the mocked-chat editor.
|
|
5
|
+
*
|
|
6
|
+
* @private constant of <MockedChatsEditorClient/>
|
|
7
|
+
*/
|
|
8
|
+
const MOCKED_CHATS_API_ENDPOINT = '/api/system/mocked-chats';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* API payload returned by mocked-chat routes.
|
|
12
|
+
*
|
|
13
|
+
* @private type of <MockedChatsEditorClient/>
|
|
14
|
+
*/
|
|
15
|
+
type MockedChatsApiPayload = {
|
|
16
|
+
mockedChats: Array<MockedChatPreset>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Persists one full mocked-chat list and returns server-normalized records.
|
|
21
|
+
*
|
|
22
|
+
* @private function of <MockedChatsEditorClient/>
|
|
23
|
+
*/
|
|
24
|
+
export async function persistMockedChats(nextMockedChats: Array<MockedChatPreset>): Promise<Array<MockedChatPreset>> {
|
|
25
|
+
const response = await fetch(MOCKED_CHATS_API_ENDPOINT, {
|
|
26
|
+
method: 'PUT',
|
|
27
|
+
headers: {
|
|
28
|
+
'Content-Type': 'application/json',
|
|
29
|
+
},
|
|
30
|
+
body: JSON.stringify({ mockedChats: nextMockedChats }),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const payload = (await response.json().catch(() => ({}))) as Partial<MockedChatsApiPayload> & {
|
|
34
|
+
error?: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
if (!response.ok || !Array.isArray(payload.mockedChats)) {
|
|
38
|
+
throw new Error(payload.error || 'Failed to save mocked chats.');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return payload.mockedChats;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Resolves the user-facing error message for one mocked-chat action.
|
|
46
|
+
*
|
|
47
|
+
* @private function of <MockedChatsEditorClient/>
|
|
48
|
+
*/
|
|
49
|
+
export function resolveMockedChatsActionErrorMessage(error: unknown, fallbackMessage: string): string {
|
|
50
|
+
return error instanceof Error ? error.message : fallbackMessage;
|
|
51
|
+
}
|