@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,97 @@
|
|
|
1
|
+
import type { AgentRow, BackupAgentPreview, BackupUserPreview, UserRow } from './serverBackupTypes';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Builds the user preview map reused across metadata sidecars.
|
|
5
|
+
*
|
|
6
|
+
* @param users - Full user rows.
|
|
7
|
+
* @returns User preview map keyed by numeric id.
|
|
8
|
+
*
|
|
9
|
+
* @private function of `createServerBackupZipStream`
|
|
10
|
+
*/
|
|
11
|
+
export function createUserPreviewById(users: ReadonlyArray<UserRow>): Map<number, BackupUserPreview> {
|
|
12
|
+
return new Map(
|
|
13
|
+
users.map((user) => [
|
|
14
|
+
user.id,
|
|
15
|
+
{
|
|
16
|
+
id: user.id,
|
|
17
|
+
username: user.username,
|
|
18
|
+
isAdmin: user.isAdmin,
|
|
19
|
+
profileImageUrl: user.profileImageUrl,
|
|
20
|
+
} satisfies BackupUserPreview,
|
|
21
|
+
] as const),
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Builds the agent preview map keyed by numeric id.
|
|
27
|
+
*
|
|
28
|
+
* @param agents - Full agent rows.
|
|
29
|
+
* @returns Agent preview map keyed by numeric id.
|
|
30
|
+
*
|
|
31
|
+
* @private function of `createServerBackupZipStream`
|
|
32
|
+
*/
|
|
33
|
+
export function createAgentPreviewById(agents: ReadonlyArray<AgentRow>): Map<number, BackupAgentPreview> {
|
|
34
|
+
return new Map(
|
|
35
|
+
agents.map((agent) => [
|
|
36
|
+
agent.id,
|
|
37
|
+
{
|
|
38
|
+
id: agent.id,
|
|
39
|
+
agentName: agent.agentName,
|
|
40
|
+
permanentId: agent.permanentId,
|
|
41
|
+
} satisfies BackupAgentPreview,
|
|
42
|
+
] as const),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Builds the agent preview map keyed by permanent id.
|
|
48
|
+
*
|
|
49
|
+
* @param agents - Full agent rows.
|
|
50
|
+
* @returns Agent preview map keyed by permanent id.
|
|
51
|
+
*
|
|
52
|
+
* @private function of `createServerBackupZipStream`
|
|
53
|
+
*/
|
|
54
|
+
export function createAgentPreviewByPermanentId(agents: ReadonlyArray<AgentRow>): Map<string, BackupAgentPreview> {
|
|
55
|
+
return new Map(
|
|
56
|
+
agents.flatMap((agent) =>
|
|
57
|
+
agent.permanentId
|
|
58
|
+
? [
|
|
59
|
+
[
|
|
60
|
+
agent.permanentId,
|
|
61
|
+
{
|
|
62
|
+
id: agent.id,
|
|
63
|
+
agentName: agent.agentName,
|
|
64
|
+
permanentId: agent.permanentId,
|
|
65
|
+
} satisfies BackupAgentPreview,
|
|
66
|
+
] as const,
|
|
67
|
+
]
|
|
68
|
+
: [],
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Builds the first-agent-by-name preview map used by feedback sidecars.
|
|
75
|
+
*
|
|
76
|
+
* @param agents - Full agent rows.
|
|
77
|
+
* @returns Agent preview map keyed by agent name.
|
|
78
|
+
*
|
|
79
|
+
* @private function of `createServerBackupZipStream`
|
|
80
|
+
*/
|
|
81
|
+
export function createAgentPreviewByName(agents: ReadonlyArray<AgentRow>): Map<string, BackupAgentPreview> {
|
|
82
|
+
const agentPreviewByName = new Map<string, BackupAgentPreview>();
|
|
83
|
+
|
|
84
|
+
for (const agent of agents) {
|
|
85
|
+
if (agentPreviewByName.has(agent.agentName)) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
agentPreviewByName.set(agent.agentName, {
|
|
90
|
+
id: agent.id,
|
|
91
|
+
agentName: agent.agentName,
|
|
92
|
+
permanentId: agent.permanentId,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return agentPreviewByName;
|
|
97
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Groups rows by a computed key.
|
|
3
|
+
*
|
|
4
|
+
* @param rows - Rows to group.
|
|
5
|
+
* @param getKey - Key selector.
|
|
6
|
+
* @returns Grouped rows keyed by the computed value.
|
|
7
|
+
*
|
|
8
|
+
* @private function of `createServerBackupZipStream`
|
|
9
|
+
*/
|
|
10
|
+
export function groupRowsBy<Row, Key extends string | number>(
|
|
11
|
+
rows: ReadonlyArray<Row>,
|
|
12
|
+
getKey: (row: Row) => Key,
|
|
13
|
+
): Map<Key, Array<Row>> {
|
|
14
|
+
const rowsByKey = new Map<Key, Array<Row>>();
|
|
15
|
+
|
|
16
|
+
for (const row of rows) {
|
|
17
|
+
const key = getKey(row);
|
|
18
|
+
const groupedRows = rowsByKey.get(key) || [];
|
|
19
|
+
groupedRows.push(row);
|
|
20
|
+
rowsByKey.set(key, groupedRows);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return rowsByKey;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Converts one unknown persisted message array into serializable objects.
|
|
28
|
+
*
|
|
29
|
+
* @param value - Raw message array candidate.
|
|
30
|
+
* @returns Serializable message array.
|
|
31
|
+
*
|
|
32
|
+
* @private function of `createServerBackupZipStream`
|
|
33
|
+
*/
|
|
34
|
+
export function resolveSerializableArray(value: unknown): Array<Record<string, unknown>> {
|
|
35
|
+
if (!Array.isArray(value)) {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return value.filter(isRecord);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Type guard for plain objects used throughout the backup builders.
|
|
44
|
+
*
|
|
45
|
+
* @param value - Unknown value.
|
|
46
|
+
* @returns `true` when the value is a non-array object.
|
|
47
|
+
*
|
|
48
|
+
* @private function of `createServerBackupZipStream`
|
|
49
|
+
*/
|
|
50
|
+
export function isRecord(value: unknown): value is Record<string, unknown> {
|
|
51
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Deduplicates JSON-serializable objects using their serialized representation.
|
|
56
|
+
*
|
|
57
|
+
* @param values - Serializable objects.
|
|
58
|
+
* @returns Deduplicated object list in first-seen order.
|
|
59
|
+
*
|
|
60
|
+
* @private function of `createServerBackupZipStream`
|
|
61
|
+
*/
|
|
62
|
+
export function deduplicateSerializableObjects<Value extends object>(values: ReadonlyArray<Value>): Array<Value> {
|
|
63
|
+
const seenSerializedValues = new Set<string>();
|
|
64
|
+
const deduplicatedValues: Array<Value> = [];
|
|
65
|
+
|
|
66
|
+
for (const value of values) {
|
|
67
|
+
const serializedValue = JSON.stringify(value);
|
|
68
|
+
if (seenSerializedValues.has(serializedValue)) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
seenSerializedValues.add(serializedValue);
|
|
73
|
+
deduplicatedValues.push(value);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return deduplicatedValues;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Normalizes one optional text field to a trimmed string or `null`.
|
|
81
|
+
*
|
|
82
|
+
* @param value - Raw value.
|
|
83
|
+
* @returns Trimmed text or `null`.
|
|
84
|
+
*
|
|
85
|
+
* @private function of `createServerBackupZipStream`
|
|
86
|
+
*/
|
|
87
|
+
export function normalizeOptionalText(value: unknown): string | null {
|
|
88
|
+
if (typeof value !== 'string') {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const normalizedValue = value.trim();
|
|
93
|
+
return normalizedValue.length > 0 ? normalizedValue : null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Sorts exported rows so JSON files remain stable and easier to diff.
|
|
98
|
+
*
|
|
99
|
+
* @param rows - Raw table rows fetched from Supabase.
|
|
100
|
+
* @returns Sorted shallow-cloned row list.
|
|
101
|
+
*
|
|
102
|
+
* @private function of `createServerBackupZipStream`
|
|
103
|
+
*/
|
|
104
|
+
export function sortBackupRows(rows: ReadonlyArray<Record<string, unknown>>): Array<Record<string, unknown>> {
|
|
105
|
+
return [...rows].sort(compareBackupRows);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Compares two generic backup rows using the most common stable identifier fields.
|
|
110
|
+
*
|
|
111
|
+
* @param left - First row.
|
|
112
|
+
* @param right - Second row.
|
|
113
|
+
* @returns Stable ordering for backup JSON output.
|
|
114
|
+
*
|
|
115
|
+
* @private function of `createServerBackupZipStream`
|
|
116
|
+
*/
|
|
117
|
+
function compareBackupRows(left: Record<string, unknown>, right: Record<string, unknown>): number {
|
|
118
|
+
const comparableKeys = ['sortOrder', 'id', 'key', 'username', 'agentName', 'permanentId', 'messageHash', 'createdAt'];
|
|
119
|
+
|
|
120
|
+
for (const comparableKey of comparableKeys) {
|
|
121
|
+
const comparison = compareComparableValues(left[comparableKey], right[comparableKey]);
|
|
122
|
+
|
|
123
|
+
if (comparison !== 0) {
|
|
124
|
+
return comparison;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return JSON.stringify(left).localeCompare(JSON.stringify(right));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Compares one optional pair of identifier values.
|
|
133
|
+
*
|
|
134
|
+
* @param left - First value.
|
|
135
|
+
* @param right - Second value.
|
|
136
|
+
* @returns Comparison result compatible with `Array.sort`.
|
|
137
|
+
*
|
|
138
|
+
* @private function of `createServerBackupZipStream`
|
|
139
|
+
*/
|
|
140
|
+
function compareComparableValues(left: unknown, right: unknown): number {
|
|
141
|
+
if (left === right) {
|
|
142
|
+
return 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (typeof left === 'number' && typeof right === 'number') {
|
|
146
|
+
return left - right;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (left === undefined || left === null) {
|
|
150
|
+
return 1;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (right === undefined || right === null) {
|
|
154
|
+
return -1;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return String(left).localeCompare(String(right));
|
|
158
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { AgentsServerDatabase } from '../../../database/schema';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Typed row alias for `Agent`.
|
|
5
|
+
*
|
|
6
|
+
* @private type of `createServerBackupZipStream`
|
|
7
|
+
*/
|
|
8
|
+
export type AgentRow = AgentsServerDatabase['public']['Tables']['Agent']['Row'];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Typed row alias for `User`.
|
|
12
|
+
*
|
|
13
|
+
* @private type of `createServerBackupZipStream`
|
|
14
|
+
*/
|
|
15
|
+
export type UserRow = AgentsServerDatabase['public']['Tables']['User']['Row'];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Typed row alias for `UserChat`.
|
|
19
|
+
*
|
|
20
|
+
* @private type of `createServerBackupZipStream`
|
|
21
|
+
*/
|
|
22
|
+
export type UserChatRow = AgentsServerDatabase['public']['Tables']['UserChat']['Row'];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Typed row alias for `ChatFeedback`.
|
|
26
|
+
*
|
|
27
|
+
* @private type of `createServerBackupZipStream`
|
|
28
|
+
*/
|
|
29
|
+
export type ChatFeedbackRow = AgentsServerDatabase['public']['Tables']['ChatFeedback']['Row'];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Typed row alias for `Wallet`.
|
|
33
|
+
*
|
|
34
|
+
* @private type of `createServerBackupZipStream`
|
|
35
|
+
*/
|
|
36
|
+
export type WalletRow = AgentsServerDatabase['public']['Tables']['Wallet']['Row'];
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Shared preview persisted for referenced users inside backup metadata files.
|
|
40
|
+
*
|
|
41
|
+
* @private type of `createServerBackupZipStream`
|
|
42
|
+
*/
|
|
43
|
+
export type BackupUserPreview = {
|
|
44
|
+
readonly id: number;
|
|
45
|
+
readonly username: string;
|
|
46
|
+
readonly isAdmin: boolean;
|
|
47
|
+
readonly profileImageUrl: string | null;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Shared preview persisted for referenced agents inside backup metadata files.
|
|
52
|
+
*
|
|
53
|
+
* @private type of `createServerBackupZipStream`
|
|
54
|
+
*/
|
|
55
|
+
export type BackupAgentPreview = {
|
|
56
|
+
readonly id: number;
|
|
57
|
+
readonly agentName: string;
|
|
58
|
+
readonly permanentId: string | null;
|
|
59
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { AgentReferenceResolver } from '../../../../src/book-2.0/agent-source/AgentReferenceResolver';
|
|
2
|
+
import type { AgentCollection } from '../../../../src/collection/agent-collection/AgentCollection';
|
|
3
|
+
import { DEFAULT_MAX_RECURSION } from '../../../../src/config';
|
|
4
|
+
import { NotFoundError } from '../../../../src/errors/NotFoundError';
|
|
5
|
+
import { ParseError } from '../../../../src/errors/ParseError';
|
|
6
|
+
import type { string_agent_url } from '../../../../src/types/typeAliases';
|
|
7
|
+
import { spaceTrim } from '../../../../src/utils/organization/spaceTrim';
|
|
8
|
+
import type { FederatedAgentImportConfiguration } from '../constants/federatedAgentImport';
|
|
9
|
+
import {
|
|
10
|
+
resolveBookScopedAgentContext,
|
|
11
|
+
type ResolvedBookScopedAgentContext,
|
|
12
|
+
} from './agentReferenceResolver/bookScopedAgentReferences';
|
|
13
|
+
import {
|
|
14
|
+
createLocalAgentUrl,
|
|
15
|
+
normalizeLocalAgentUrlReferences,
|
|
16
|
+
normalizeLocalServerUrls,
|
|
17
|
+
resolveLocalAgentRouteReference,
|
|
18
|
+
} from './localAgentRouteReferences';
|
|
19
|
+
import { createMissingImportedAgentFallback } from './createMissingImportedAgentFallback';
|
|
20
|
+
import {
|
|
21
|
+
resolveInheritedAgentSource,
|
|
22
|
+
type AgentSourceImporter,
|
|
23
|
+
} from './resolveInheritedAgentSource';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Dependencies needed for importing same-instance agent sources without HTTP.
|
|
27
|
+
*/
|
|
28
|
+
export type CreateLocalAgentSourceImporterOptions = {
|
|
29
|
+
/**
|
|
30
|
+
* Collection used to load local regular and book-scoped agent sources.
|
|
31
|
+
*/
|
|
32
|
+
readonly collection: Pick<AgentCollection, 'getAgentPermanentId' | 'getAgentSource'>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Server origins that should be treated as this Agents Server instance.
|
|
36
|
+
*/
|
|
37
|
+
readonly localServerUrls: ReadonlyArray<string>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Exact agent URLs that should be treated as local even when their origin is not in `localServerUrls`.
|
|
41
|
+
*/
|
|
42
|
+
readonly localAgentUrls?: ReadonlyArray<string_agent_url>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Adam agent URL used for implicit default inheritance.
|
|
46
|
+
*/
|
|
47
|
+
readonly adamAgentUrl: string_agent_url;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Resolver used for compact references that are not book-scoped.
|
|
51
|
+
*/
|
|
52
|
+
readonly fallbackResolver?: AgentReferenceResolver;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Retry configuration used when nested imports leave the local server.
|
|
56
|
+
*/
|
|
57
|
+
readonly federatedAgentImportConfiguration?: FederatedAgentImportConfiguration;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Creates an importer that loads same-instance agent URLs directly from the collection.
|
|
62
|
+
*
|
|
63
|
+
* @param options - Same-instance import dependencies.
|
|
64
|
+
* @returns Importer suitable for `resolveInheritedAgentSource`.
|
|
65
|
+
*/
|
|
66
|
+
export function createLocalAgentSourceImporter(options: CreateLocalAgentSourceImporterOptions): AgentSourceImporter {
|
|
67
|
+
const localServerUrls = normalizeLocalServerUrls(options.localServerUrls);
|
|
68
|
+
const localAgentUrlReferences = normalizeLocalAgentUrlReferences(options.localAgentUrls || []);
|
|
69
|
+
const localAgentSourceImporter: AgentSourceImporter = async (agentUrl, context) => {
|
|
70
|
+
const localRouteReference = resolveLocalAgentRouteReference(agentUrl, localServerUrls, localAgentUrlReferences);
|
|
71
|
+
|
|
72
|
+
if (!localRouteReference) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const nextRecursionLevel = (context.importAgentOptions.recursionLevel || 0) + 1;
|
|
77
|
+
assertRecursionLevel(nextRecursionLevel, agentUrl);
|
|
78
|
+
|
|
79
|
+
let resolvedAgentContext: ResolvedBookScopedAgentContext;
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
resolvedAgentContext = await resolveBookScopedAgentContext({
|
|
83
|
+
collection: options.collection,
|
|
84
|
+
agentIdentifier: localRouteReference.agentIdentifier,
|
|
85
|
+
localServerUrl: localRouteReference.localServerUrl,
|
|
86
|
+
fallbackResolver: options.fallbackResolver,
|
|
87
|
+
});
|
|
88
|
+
} catch (error) {
|
|
89
|
+
if (error instanceof NotFoundError) {
|
|
90
|
+
return createMissingImportedAgentFallback(agentUrl, 1, error);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return resolveInheritedAgentSource(resolvedAgentContext.unresolvedAgentSource, {
|
|
97
|
+
adamAgentUrl: options.adamAgentUrl,
|
|
98
|
+
recursionLevel: nextRecursionLevel,
|
|
99
|
+
inheritancePath: context.importAgentOptions.inheritancePath,
|
|
100
|
+
currentAgentUrl: resolvedAgentContext.canonicalAgentUrl,
|
|
101
|
+
currentAgentAliases: createCurrentAgentAliases(resolvedAgentContext, localServerUrls),
|
|
102
|
+
agentReferenceResolver: resolvedAgentContext.scopedAgentReferenceResolver,
|
|
103
|
+
federatedAgentImportConfiguration:
|
|
104
|
+
options.federatedAgentImportConfiguration || context.federatedAgentImportConfiguration,
|
|
105
|
+
agentSourceImporter: localAgentSourceImporter,
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
return localAgentSourceImporter;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Throws when direct local importing would exceed the configured recursion limit.
|
|
114
|
+
*
|
|
115
|
+
* @param recursionLevel - Next recursion level.
|
|
116
|
+
* @param agentUrl - Local agent URL being imported.
|
|
117
|
+
*/
|
|
118
|
+
function assertRecursionLevel(recursionLevel: number, agentUrl: string_agent_url): void {
|
|
119
|
+
if (recursionLevel <= DEFAULT_MAX_RECURSION) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
throw new ParseError(
|
|
124
|
+
spaceTrim(
|
|
125
|
+
(block) => `
|
|
126
|
+
Recursion depth ${recursionLevel} exceeds maximum allowed ${DEFAULT_MAX_RECURSION} while importing local agent:
|
|
127
|
+
|
|
128
|
+
${block(agentUrl)}
|
|
129
|
+
`,
|
|
130
|
+
),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Builds cycle-detection aliases for every same-instance origin.
|
|
136
|
+
*
|
|
137
|
+
* @param resolvedAgentContext - Resolved local/book-scoped agent context.
|
|
138
|
+
* @param localServerUrls - Same-instance server origins.
|
|
139
|
+
* @returns Unique local URL aliases for the imported agent.
|
|
140
|
+
*/
|
|
141
|
+
function createCurrentAgentAliases(
|
|
142
|
+
resolvedAgentContext: ResolvedBookScopedAgentContext,
|
|
143
|
+
localServerUrls: ReadonlyArray<string>,
|
|
144
|
+
): Array<string_agent_url> {
|
|
145
|
+
const agentIdentifiers = [
|
|
146
|
+
resolvedAgentContext.canonicalAgentIdentifier,
|
|
147
|
+
resolvedAgentContext.requestedAgentIdentifier,
|
|
148
|
+
resolvedAgentContext.resolvedAgentName,
|
|
149
|
+
].filter((agentIdentifier, index, agentIdentifierList) => agentIdentifierList.indexOf(agentIdentifier) === index);
|
|
150
|
+
const agentAliases = new Set<string>(resolvedAgentContext.currentAgentAliases);
|
|
151
|
+
|
|
152
|
+
for (const localServerUrl of localServerUrls) {
|
|
153
|
+
for (const agentIdentifier of agentIdentifiers) {
|
|
154
|
+
agentAliases.add(createLocalAgentUrl(localServerUrl, agentIdentifier));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return [...agentAliases] as Array<string_agent_url>;
|
|
159
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { padBook } from '../../../../src/book-2.0/agent-source/padBook';
|
|
2
|
+
import { validateBook } from '../../../../src/book-2.0/agent-source/string_book';
|
|
3
|
+
import type { string_agent_url } from '../../../../src/types/typeAliases';
|
|
4
|
+
import type { string_book } from '../../../../src/book-2.0/agent-source/string_book';
|
|
5
|
+
import { spaceTrim } from '../../../../src/utils/organization/spaceTrim';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Collapses one thrown error into a single-line message suitable for `NOTE` commitments.
|
|
9
|
+
*
|
|
10
|
+
* @param agentUrl - Canonical imported agent URL.
|
|
11
|
+
* @param error - Unknown error raised while loading the imported agent.
|
|
12
|
+
* @returns Human-readable single-line failure reason.
|
|
13
|
+
*
|
|
14
|
+
* @private internal helper for imported-agent fallback books
|
|
15
|
+
*/
|
|
16
|
+
function normalizeImportFailureMessage(agentUrl: string_agent_url, error: unknown): string {
|
|
17
|
+
const rawMessage = error instanceof Error ? error.message : String(error);
|
|
18
|
+
const normalizedMessage = rawMessage.replace(/\s+/g, ' ').trim();
|
|
19
|
+
const prefix = `Failed to import agent from "${agentUrl}"`;
|
|
20
|
+
|
|
21
|
+
if (normalizedMessage.startsWith(prefix)) {
|
|
22
|
+
const suffix = normalizedMessage.slice(prefix.length).trim();
|
|
23
|
+
if (suffix.length > 0) {
|
|
24
|
+
return suffix.replace(/^[-:,\s]+/, '').trim() || 'unknown error';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return normalizedMessage || 'unknown error';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Creates the ad-hoc fallback source returned when a referenced agent stays unavailable.
|
|
33
|
+
*
|
|
34
|
+
* @param agentUrl - Canonical imported agent URL.
|
|
35
|
+
* @param attempts - Total number of attempts that were used.
|
|
36
|
+
* @param error - Final error raised by the failed import attempts.
|
|
37
|
+
* @returns Valid fallback book source.
|
|
38
|
+
*
|
|
39
|
+
* @private internal helper for imported-agent fallback books
|
|
40
|
+
*/
|
|
41
|
+
export function createMissingImportedAgentFallback(
|
|
42
|
+
agentUrl: string_agent_url,
|
|
43
|
+
attempts: number,
|
|
44
|
+
error: unknown,
|
|
45
|
+
): string_book {
|
|
46
|
+
const failureMessage = normalizeImportFailureMessage(agentUrl, error);
|
|
47
|
+
|
|
48
|
+
return padBook(
|
|
49
|
+
validateBook(
|
|
50
|
+
spaceTrim(
|
|
51
|
+
`
|
|
52
|
+
Not found agent
|
|
53
|
+
|
|
54
|
+
NOTE This agent was supposed to be imported from ${agentUrl}, but it can not be loaded after ${attempts} attempts because of ${failureMessage}
|
|
55
|
+
CLOSED
|
|
56
|
+
`,
|
|
57
|
+
),
|
|
58
|
+
),
|
|
59
|
+
);
|
|
60
|
+
}
|