@promptbook/cli 0.112.0-104 → 0.112.0-106
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/image-generator-test/ImageAttachmentsEditor.tsx +19 -3
- package/apps/agents-server/src/app/admin/limits/LimitsClient.tsx +11 -12
- package/apps/agents-server/src/app/admin/metadata/MetadataClient.tsx +34 -2
- package/apps/agents-server/src/app/admin/servers/CreateServerDialog.tsx +6 -1
- package/apps/agents-server/src/app/admin/servers/useCreateServerWizard.ts +13 -1
- package/apps/agents-server/src/app/agents/[agentName]/AgentChatWrapper.tsx +11 -2
- package/apps/agents-server/src/app/agents/[agentName]/AgentProfileChat.tsx +11 -1
- package/apps/agents-server/src/app/agents/[agentName]/book/BookEditorWrapper.tsx +7 -1
- package/apps/agents-server/src/app/agents/[agentName]/chat/CanonicalAgentChatSurface.tsx +11 -1
- package/apps/agents-server/src/app/agents/[agentName]/images/default-avatar.png/route.ts +6 -2
- package/apps/agents-server/src/app/api/images/[filename]/route.ts +6 -2
- package/apps/agents-server/src/app/api/internal/agent-runner-limits/route.ts +51 -0
- package/apps/agents-server/src/app/api/upload/route.ts +48 -12
- package/apps/agents-server/src/app/layout.tsx +13 -0
- package/apps/agents-server/src/components/FileUploadAvailability/FileUploadAvailabilityContext.tsx +50 -0
- package/apps/agents-server/src/components/FileUploadAvailability/FileUploadUnavailableNotice.tsx +45 -0
- package/apps/agents-server/src/components/LayoutWrapper/LayoutWrapper.tsx +85 -76
- package/apps/agents-server/src/components/NewAgentDialog/NewAgentDialog.tsx +7 -3
- package/apps/agents-server/src/components/NewAgentDialog/NewAgentWizardKnowledgeStep.tsx +6 -0
- package/apps/agents-server/src/components/NewAgentDialog/useNewAgentWizardKnowledgeState.ts +8 -1
- package/apps/agents-server/src/constants/serverLimits.ts +22 -2
- package/apps/agents-server/src/database/seedDefaultAgents.ts +218 -0
- package/apps/agents-server/src/tools/$provideCdnForServer.ts +72 -8
- package/apps/agents-server/src/utils/defaultAgents/loadDefaultAgentBooks.ts +103 -0
- package/apps/agents-server/src/utils/knowledge/createInlineKnowledgeSourceUploader.ts +24 -5
- package/apps/agents-server/src/utils/serverLimits.ts +26 -1
- package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerDefaultAgents.ts +1 -85
- package/apps/agents-server/src/utils/shareTargetPayloads.ts +20 -2
- package/apps/agents-server/src/utils/upload/fileUploadAvailability.ts +91 -0
- package/apps/agents-server/src/utils/upload/uploadFileToServer.ts +46 -2
- package/esm/apps/agents-server/src/constants/federatedAgentImport.d.ts +42 -0
- package/esm/apps/agents-server/src/constants/serverLimits.d.ts +207 -0
- package/esm/apps/agents-server/src/constants/toolUsageLimits.d.ts +55 -0
- package/esm/index.es.js +602 -39
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/run-agent-messages/main/AgentMessageFailureTracker.d.ts +27 -0
- package/esm/scripts/run-agent-messages/main/handleAgentWatchError.d.ts +4 -0
- package/esm/scripts/run-agent-messages/main/runAgentMessages.d.ts +1 -0
- package/esm/scripts/run-agent-messages/messages/moveAgentMessageToFailed.d.ts +17 -0
- package/esm/src/book-components/BookEditor/BookEditor.d.ts +5 -4
- package/esm/src/book-components/BookEditor/BookEditorTheme.d.ts +24 -0
- package/esm/src/book-components/BookEditor/useBookEditorMonacoLanguage.d.ts +1 -6
- package/esm/src/book-components/BookEditor/useBookEditorMonacoLifecycle.d.ts +1 -4
- package/esm/src/book-components/BookEditor/useBookEditorMonacoStyles.d.ts +2 -1
- package/esm/src/cli/cli-commands/agent-folder/agentProjectPaths.d.ts +6 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/avatars/visuals/octopus3d3AvatarVisual.ts +28 -29
- package/src/book-components/BookEditor/BookEditor.tsx +10 -7
- package/src/book-components/BookEditor/BookEditorMonaco.tsx +3 -1
- package/src/book-components/BookEditor/BookEditorTheme.ts +32 -0
- package/src/book-components/BookEditor/useBookEditorMonacoLanguage.ts +15 -15
- package/src/book-components/BookEditor/useBookEditorMonacoLifecycle.ts +1 -5
- package/src/book-components/BookEditor/useBookEditorMonacoStyles.ts +2 -1
- package/src/cli/cli-commands/agent-folder/agentProjectPaths.ts +7 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer.ts +109 -9
- package/src/cli/cli-commands/agents-server/startAgentsServer.ts +132 -4
- package/src/other/templates/getTemplatesPipelineCollection.ts +874 -760
- package/src/version.ts +2 -2
- package/src/versions.txt +2 -0
- package/umd/apps/agents-server/src/constants/federatedAgentImport.d.ts +42 -0
- package/umd/apps/agents-server/src/constants/serverLimits.d.ts +207 -0
- package/umd/apps/agents-server/src/constants/toolUsageLimits.d.ts +55 -0
- package/umd/index.umd.js +602 -39
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/run-agent-messages/main/AgentMessageFailureTracker.d.ts +27 -0
- package/umd/scripts/run-agent-messages/main/handleAgentWatchError.d.ts +4 -0
- package/umd/scripts/run-agent-messages/main/runAgentMessages.d.ts +1 -0
- package/umd/scripts/run-agent-messages/messages/moveAgentMessageToFailed.d.ts +17 -0
- package/umd/src/book-components/BookEditor/BookEditor.d.ts +5 -4
- package/umd/src/book-components/BookEditor/BookEditorTheme.d.ts +24 -0
- package/umd/src/book-components/BookEditor/useBookEditorMonacoLanguage.d.ts +1 -6
- package/umd/src/book-components/BookEditor/useBookEditorMonacoLifecycle.d.ts +1 -4
- package/umd/src/book-components/BookEditor/useBookEditorMonacoStyles.d.ts +2 -1
- package/umd/src/cli/cli-commands/agent-folder/agentProjectPaths.d.ts +6 -0
- package/umd/src/version.d.ts +1 -1
- package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddress.test.ts.todo +0 -108
- package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddresses.test.ts.todo +0 -117
- package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddress.test.ts.todo +0 -119
- package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddresses.test.ts.todo +0 -74
- package/apps/agents-server/src/utils/defaultAgents/defaultAgents.ts +0 -168
- package/apps/agents-server/src/utils/defaultAgents/installDefaultAgents.ts +0 -139
- package/apps/agents-server/tests/e2e/authentication-and-navigation.spec.ts.todo +0 -178
- package/src/_packages/browser.index.ts +0 -31
- package/src/_packages/browser.readme.md +0 -43
- package/src/book-2.0/agent-source/parseAgentSourceWithCommitments.test.ts.todo +0 -265
- package/src/book-components/BookEditor/BookEditorMonaco.test.tsx.todo +0 -115
- package/src/book-components/Chat/utils/renderMarkdown.test.ts.tmp +0 -199
- package/src/collection/agent-collection/constructors/agent-collection-in-directory/AgentCollectionInDirectory.test.ts.todo +0 -131
- package/src/commands/_common/parseCommand.test.ts.todo +0 -48
- package/src/commitments/META_LINK/META_LINK.test.ts.todo +0 -75
- package/src/conversion/validation/pipelineStringToJson-errors.test.ts.todo +0 -33
- package/src/dialogs/simple-prompt/SimplePromptInterfaceTools.ts +0 -51
- package/src/executables/browsers/locateSafari.test.ts.tmp +0 -15
- package/src/execution/PromptbookFetch.test-type.ts +0 -14
- package/src/execution/createPipelineExecutor/00-createPipelineExecutor.test.ts.todo +0 -0
- package/src/execution/execution-report/executionReportJsonToString.test.ts.todo +0 -83
- package/src/execution/utils/usageToHuman.test.ts.todo +0 -80
- package/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.ts +0 -76
- package/src/llm-providers/_common/utils/assertUniqueModels.ts +0 -27
- package/src/llm-providers/_multiple/playground/playground.ts +0 -141
- package/src/llm-providers/_multiple/playground/tsconfig.json +0 -19
- package/src/llm-providers/agent/playground/playground.ts +0 -190
- package/src/llm-providers/agent/playground/tsconfig.json +0 -19
- package/src/llm-providers/anthropic-claude/playground/playground.ts +0 -99
- package/src/llm-providers/anthropic-claude/playground/tsconfig.json +0 -19
- package/src/llm-providers/azure-openai/playground/playground.ts +0 -101
- package/src/llm-providers/azure-openai/playground/tsconfig.json +0 -19
- package/src/llm-providers/ollama/playground/playground.ts +0 -120
- package/src/llm-providers/ollama/playground/tsconfig.json +0 -19
- package/src/llm-providers/openai/playground/playground.ts +0 -406
- package/src/llm-providers/openai/playground/tsconfig.json +0 -19
- package/src/llm-providers/remote/playground/playground.ts +0 -144
- package/src/llm-providers/remote/playground/tsconfig.json +0 -19
- package/src/llm-providers/vercel/playground/playground.ts +0 -133
- package/src/llm-providers/vercel/playground/tsconfig.json +0 -19
- package/src/personas/preparePersona.test.ts.todo +0 -126
- package/src/playground/backup/_playground-boilerplate.ts.txt +0 -37
- package/src/playground/backup/playground-agent-os.txt +0 -62
- package/src/playground/backup/playground-brj-app.ts.txt +0 -302
- package/src/playground/backup/playground-browser-playwright.txt +0 -110
- package/src/playground/backup/playground-claude-mcp.txt +0 -43
- package/src/playground/backup/playground-document-conversion.txt +0 -84
- package/src/playground/backup/playground-glob.ts.txt +0 -42
- package/src/playground/backup/playground-mcp-server.txt +0 -1
- package/src/playground/backup/playground-openai-agent-kit.txt +0 -73
- package/src/playground/backup/playground-openai-function-calling.txt +0 -131
- package/src/playground/backup/playground-openai-streaming.ts.txt +0 -68
- package/src/playground/backup/playground-scrape-knowledge.txt +0 -65
- package/src/playground/backup/playground-scraperFetch.ts.txt +0 -44
- package/src/playground/backup/playground-using-openai-compatible-route-on-agents-server.ts.txt +0 -49
- package/src/playground/backup/playground-write-pavolhejny-bio.txt +0 -120
- package/src/playground/permanent/_boilerplate.ts +0 -54
- package/src/playground/permanent/agent-with-browser-playground.ts +0 -92
- package/src/playground/permanent/error-handling-playground.ts +0 -103
- package/src/playground/playground.ts +0 -36
- package/src/playground/tsconfig.json +0 -19
- package/src/scrapers/_boilerplate/BoilerplateScraper.test.ts.todo +0 -73
- package/src/scrapers/_boilerplate/playground/boilerplate-scraper-playground.ts +0 -79
- package/src/scrapers/_boilerplate/playground/tsconfig.json +0 -19
- package/src/scrapers/_common/utils/files/blobToDataurl.test.ts.todo +0 -17
- package/src/scrapers/_common/utils/files/dataurlToBlob.test.ts.todo +0 -52
- package/src/scrapers/_common/utils/files/isValidDataurl.test.ts.todo +0 -42
- package/src/scrapers/_common/utils/files/shorten.test.ts.todo +0 -13
- package/src/scrapers/document/playground/document-scraper-playground.ts +0 -80
- package/src/scrapers/document/playground/tsconfig.json +0 -19
- package/src/scrapers/document-legacy/playground/legacy-document-scraper-playground.ts +0 -80
- package/src/scrapers/document-legacy/playground/tsconfig.json +0 -19
- package/src/scrapers/markdown/playground/markdown-scraper-playground.ts +0 -74
- package/src/scrapers/markdown/playground/tsconfig.json +0 -19
- package/src/scrapers/markitdown/MarkitdownScraper.test.ts.todo +0 -132
- package/src/scrapers/markitdown/playground/markitdown-scraper-playground.ts +0 -91
- package/src/scrapers/markitdown/playground/tsconfig.json +0 -19
- package/src/scrapers/pdf/PdfScraper.test.ts.todo +0 -52
- package/src/scrapers/pdf/playground/pdf-scraper-playground.ts +0 -75
- package/src/scrapers/pdf/playground/tsconfig.json +0 -19
- package/src/scrapers/website/playground/tsconfig.json +0 -19
- package/src/scrapers/website/playground/website-scraper-playground.ts +0 -82
- package/src/storage/_common/PromptbookStorage.test-type.ts +0 -14
- package/src/storage/local-storage/getIndexedDbStorage.ts +0 -36
- package/src/storage/local-storage/getLocalStorage.ts +0 -33
- package/src/storage/local-storage/getSessionStorage.ts +0 -33
- package/src/storage/local-storage/utils/IndexedDbStorageOptions.ts +0 -16
- package/src/storage/local-storage/utils/makePromptbookStorageFromIndexedDb.ts +0 -58
- package/src/storage/local-storage/utils/makePromptbookStorageFromWebStorage.ts +0 -45
- package/src/transpilers/formatted-book-in-markdown/FormattedBookInMarkdownTranspiler.test.ts.todo +0 -35
- package/src/transpilers/openai-sdk/playground/playground.ts +0 -85
- package/src/transpilers/openai-sdk/playground/tmp/chatbot-openaisdk-1.js +0 -194
- package/src/transpilers/openai-sdk/playground/tmp/package.json +0 -3
- package/src/transpilers/openai-sdk/playground/tsconfig.json +0 -18
- package/src/utils/editable/utils/findUsableParameters.test.ts.todo +0 -43
- package/src/utils/editable/utils/stringifyPipelineJson.test.ts.todo +0 -38
- package/src/utils/markdown/prettifyMarkdown.test.ts.tmp +0 -42
- package/src/utils/serialization/serializeToPromptbookJavascript.test.ts.todo +0 -116
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import * as dotenv from 'dotenv';
|
|
2
|
+
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
3
|
+
import { AgentCollectionInSupabase } from '../../../../src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase';
|
|
4
|
+
import type { AgentsDatabaseSchema } from '../../../../src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema';
|
|
5
|
+
import { $provideSupabaseForServer } from './$provideSupabaseForServer';
|
|
6
|
+
import { DEFAULT_AGENT_VISIBILITY } from '../utils/agentVisibility';
|
|
7
|
+
import { loadDefaultAgentBooks } from '../utils/defaultAgents/loadDefaultAgentBooks';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Environment variable pointing to the installed Agents Server `.env` file.
|
|
11
|
+
*
|
|
12
|
+
* @private utility of standalone default-agent seeding
|
|
13
|
+
*/
|
|
14
|
+
const AGENTS_SERVER_ENV_FILE_ENV_NAME = 'PTBK_AGENTS_SERVER_ENV_FILE';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Environment variable with an explicit default-agent source directory.
|
|
18
|
+
*
|
|
19
|
+
* @private utility of standalone default-agent seeding
|
|
20
|
+
*/
|
|
21
|
+
const DEFAULT_AGENTS_DIRECTORY_ENV_NAME = 'PTBK_DEFAULT_AGENTS_DIR';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Environment variable carrying the current Agents Server table prefix.
|
|
25
|
+
*
|
|
26
|
+
* @private utility of standalone default-agent seeding
|
|
27
|
+
*/
|
|
28
|
+
const SUPABASE_TABLE_PREFIX_ENV_NAME = 'SUPABASE_TABLE_PREFIX';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Logger surface used by the default-agent seeder.
|
|
32
|
+
*
|
|
33
|
+
* @private utility of standalone default-agent seeding
|
|
34
|
+
*/
|
|
35
|
+
type SeedDefaultAgentsLogger = Pick<Console, 'error' | 'info' | 'warn'>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Options for installing bundled default agents into the current Agents Server database.
|
|
39
|
+
*
|
|
40
|
+
* @private utility of standalone default-agent seeding
|
|
41
|
+
*/
|
|
42
|
+
export type SeedDefaultAgentsOptions = {
|
|
43
|
+
/**
|
|
44
|
+
* Optional explicit directory containing default `*.book` files.
|
|
45
|
+
*/
|
|
46
|
+
readonly defaultAgentDirectory?: string | null;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Optional table prefix for the server namespace being seeded.
|
|
50
|
+
*/
|
|
51
|
+
readonly tablePrefix?: string | null;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Optional logger for installer output.
|
|
55
|
+
*/
|
|
56
|
+
readonly logger?: SeedDefaultAgentsLogger;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Result of one default-agent seed attempt.
|
|
61
|
+
*
|
|
62
|
+
* @private utility of standalone default-agent seeding
|
|
63
|
+
*/
|
|
64
|
+
export type SeedDefaultAgentsResult = {
|
|
65
|
+
/**
|
|
66
|
+
* Number of agents already present before seeding, including soft-deleted agents.
|
|
67
|
+
*/
|
|
68
|
+
readonly existingAgentCount: number;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Number of bundled default books found.
|
|
72
|
+
*/
|
|
73
|
+
readonly sourceCount: number;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Number of default agents created.
|
|
77
|
+
*/
|
|
78
|
+
readonly createdCount: number;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Names of agents created during this run.
|
|
82
|
+
*/
|
|
83
|
+
readonly createdAgentNames: ReadonlyArray<string>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Reason no agents were created.
|
|
87
|
+
*/
|
|
88
|
+
readonly skippedReason: 'existing-agents' | 'no-default-books' | null;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Installs bundled default agents when the current server has no agents yet.
|
|
93
|
+
*
|
|
94
|
+
* @param options - Optional seed controls.
|
|
95
|
+
* @returns Seed summary.
|
|
96
|
+
*
|
|
97
|
+
* @private utility of standalone default-agent seeding
|
|
98
|
+
*/
|
|
99
|
+
export async function seedDefaultAgents(options: SeedDefaultAgentsOptions = {}): Promise<SeedDefaultAgentsResult> {
|
|
100
|
+
const logger = options.logger ?? console;
|
|
101
|
+
const tablePrefix = options.tablePrefix ?? process.env[SUPABASE_TABLE_PREFIX_ENV_NAME] ?? '';
|
|
102
|
+
const collection = new AgentCollectionInSupabase(resolveAgentsDatabaseSupabaseClient(), { tablePrefix });
|
|
103
|
+
const existingAgentCount = await countExistingAgents(collection);
|
|
104
|
+
|
|
105
|
+
if (existingAgentCount > 0) {
|
|
106
|
+
logger.info(
|
|
107
|
+
`Skipping default agents because the server already has ${existingAgentCount} agent${
|
|
108
|
+
existingAgentCount === 1 ? '' : 's'
|
|
109
|
+
}.`,
|
|
110
|
+
);
|
|
111
|
+
return {
|
|
112
|
+
existingAgentCount,
|
|
113
|
+
sourceCount: 0,
|
|
114
|
+
createdCount: 0,
|
|
115
|
+
createdAgentNames: [],
|
|
116
|
+
skippedReason: 'existing-agents',
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const defaultAgentBooks = await loadDefaultAgentBooks({
|
|
121
|
+
defaultAgentDirectory: options.defaultAgentDirectory ?? process.env[DEFAULT_AGENTS_DIRECTORY_ENV_NAME],
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
if (defaultAgentBooks.length === 0) {
|
|
125
|
+
logger.warn('Skipping default agents because no bundled *.book files were found.');
|
|
126
|
+
return {
|
|
127
|
+
existingAgentCount,
|
|
128
|
+
sourceCount: 0,
|
|
129
|
+
createdCount: 0,
|
|
130
|
+
createdAgentNames: [],
|
|
131
|
+
skippedReason: 'no-default-books',
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const createdAgentNames: Array<string> = [];
|
|
136
|
+
|
|
137
|
+
for (const [index, defaultAgentBook] of defaultAgentBooks.entries()) {
|
|
138
|
+
const createdAgent = await collection.createAgent(defaultAgentBook, {
|
|
139
|
+
sortOrder: index,
|
|
140
|
+
visibility: DEFAULT_AGENT_VISIBILITY,
|
|
141
|
+
});
|
|
142
|
+
createdAgentNames.push(createdAgent.agentName);
|
|
143
|
+
logger.info(`Created default agent: ${createdAgent.agentName}`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
existingAgentCount,
|
|
148
|
+
sourceCount: defaultAgentBooks.length,
|
|
149
|
+
createdCount: createdAgentNames.length,
|
|
150
|
+
createdAgentNames,
|
|
151
|
+
skippedReason: null,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Counts active and soft-deleted agents so repeated installer runs do not recreate defaults.
|
|
157
|
+
*
|
|
158
|
+
* @param collection - Agent collection bound to the current table prefix.
|
|
159
|
+
* @returns Number of existing active and deleted agents.
|
|
160
|
+
*
|
|
161
|
+
* @private utility of standalone default-agent seeding
|
|
162
|
+
*/
|
|
163
|
+
async function countExistingAgents(collection: AgentCollectionInSupabase): Promise<number> {
|
|
164
|
+
const activeAgents = await collection.listAgents();
|
|
165
|
+
const deletedAgents = await collection.listDeletedAgents();
|
|
166
|
+
|
|
167
|
+
return activeAgents.length + deletedAgents.length;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Resolves the Supabase-shaped client for the Agent collection subset.
|
|
172
|
+
*
|
|
173
|
+
* @returns Supabase client typed for agent collection persistence.
|
|
174
|
+
*
|
|
175
|
+
* @private utility of standalone default-agent seeding
|
|
176
|
+
*/
|
|
177
|
+
function resolveAgentsDatabaseSupabaseClient(): SupabaseClient<AgentsDatabaseSchema> {
|
|
178
|
+
return $provideSupabaseForServer() as unknown as SupabaseClient<AgentsDatabaseSchema>;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Loads the installed Agents Server environment before seeding.
|
|
183
|
+
*
|
|
184
|
+
* @private utility of standalone default-agent seeding
|
|
185
|
+
*/
|
|
186
|
+
function loadSeedDefaultAgentsEnvironment(): void {
|
|
187
|
+
const explicitEnvFilePath = process.env[AGENTS_SERVER_ENV_FILE_ENV_NAME]?.trim();
|
|
188
|
+
if (explicitEnvFilePath) {
|
|
189
|
+
const explicitLoadResult = dotenv.config({ path: explicitEnvFilePath });
|
|
190
|
+
if (!explicitLoadResult.error) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
dotenv.config();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Runs the standalone default-agent seed command.
|
|
200
|
+
*
|
|
201
|
+
* @private utility of standalone default-agent seeding
|
|
202
|
+
*/
|
|
203
|
+
async function runSeedDefaultAgentsCommand(): Promise<void> {
|
|
204
|
+
loadSeedDefaultAgentsEnvironment();
|
|
205
|
+
const result = await seedDefaultAgents();
|
|
206
|
+
|
|
207
|
+
if (result.createdCount > 0) {
|
|
208
|
+
console.info(`Installed ${result.createdCount} default agent${result.createdCount === 1 ? '' : 's'}.`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (require.main === module) {
|
|
213
|
+
runSeedDefaultAgentsCommand().catch((error) => {
|
|
214
|
+
console.error('Failed to install default agents:');
|
|
215
|
+
console.error(error instanceof Error ? error.message : error);
|
|
216
|
+
process.exit(1);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
@@ -4,6 +4,16 @@ import { TrackedFilesStorage } from '../utils/cdn/classes/TrackedFilesStorage';
|
|
|
4
4
|
import { VercelBlobStorage } from '../utils/cdn/classes/VercelBlobStorage';
|
|
5
5
|
import { IIFilesStorageWithCdn } from '../utils/cdn/interfaces/IFilesStorage';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Options controlling CDN storage construction for the current server request.
|
|
9
|
+
*/
|
|
10
|
+
export type ProvideCdnForServerOptions = {
|
|
11
|
+
/**
|
|
12
|
+
* Public URL used when generating file links.
|
|
13
|
+
*/
|
|
14
|
+
readonly cdnPublicUrl?: URL;
|
|
15
|
+
};
|
|
16
|
+
|
|
7
17
|
/**
|
|
8
18
|
* Region expected by the bundled VersityGW S3-compatible storage.
|
|
9
19
|
*
|
|
@@ -19,20 +29,28 @@ const SELF_CONTAINED_S3_DEFAULT_REGION = 'us-east-1';
|
|
|
19
29
|
const EXTERNAL_S3_DEFAULT_REGION = 'auto';
|
|
20
30
|
|
|
21
31
|
/**
|
|
22
|
-
* Cache of CDN
|
|
32
|
+
* Cache of CDN instances by public URL.
|
|
23
33
|
*
|
|
24
34
|
* @private internal cache for `$provideCdnForServer`
|
|
25
35
|
*/
|
|
26
|
-
|
|
36
|
+
const cdnByPublicUrl = new Map<string, IIFilesStorageWithCdn>();
|
|
27
37
|
|
|
28
38
|
/**
|
|
29
39
|
* Provides a CDN storage interface for server-side file operations, with caching to reuse instances.
|
|
40
|
+
*
|
|
41
|
+
* @param options - Optional request-aware CDN public URL override.
|
|
42
|
+
* @returns CDN storage interface.
|
|
30
43
|
*/
|
|
31
|
-
export function $provideCdnForServer(): IIFilesStorageWithCdn {
|
|
44
|
+
export function $provideCdnForServer(options: ProvideCdnForServerOptions = {}): IIFilesStorageWithCdn {
|
|
45
|
+
const cdnPublicUrl = options.cdnPublicUrl || resolveConfiguredCdnPublicUrl();
|
|
46
|
+
const cdnCacheKey = cdnPublicUrl.href;
|
|
47
|
+
let cdn = cdnByPublicUrl.get(cdnCacheKey);
|
|
48
|
+
|
|
32
49
|
if (!cdn) {
|
|
33
|
-
const inner = createCdnStorageForServer();
|
|
50
|
+
const inner = createCdnStorageForServer(cdnPublicUrl);
|
|
34
51
|
const supabase = $provideSupabaseForServer();
|
|
35
52
|
cdn = new TrackedFilesStorage(inner, supabase);
|
|
53
|
+
cdnByPublicUrl.set(cdnCacheKey, cdn);
|
|
36
54
|
}
|
|
37
55
|
|
|
38
56
|
return cdn;
|
|
@@ -41,9 +59,10 @@ export function $provideCdnForServer(): IIFilesStorageWithCdn {
|
|
|
41
59
|
/**
|
|
42
60
|
* Creates the configured CDN storage implementation for server-side file operations.
|
|
43
61
|
*
|
|
62
|
+
* @param cdnPublicUrl - Public URL used to build deterministic file links.
|
|
44
63
|
* @private helper of `$provideCdnForServer`
|
|
45
64
|
*/
|
|
46
|
-
function createCdnStorageForServer(): IIFilesStorageWithCdn {
|
|
65
|
+
function createCdnStorageForServer(cdnPublicUrl: URL): IIFilesStorageWithCdn {
|
|
47
66
|
if (isS3CompatibleStorageSelected()) {
|
|
48
67
|
return new DigitalOceanSpaces({
|
|
49
68
|
bucket: process.env.CDN_BUCKET!,
|
|
@@ -51,7 +70,7 @@ function createCdnStorageForServer(): IIFilesStorageWithCdn {
|
|
|
51
70
|
endpoint: process.env.CDN_ENDPOINT!,
|
|
52
71
|
accessKeyId: process.env.CDN_ACCESS_KEY_ID!,
|
|
53
72
|
secretAccessKey: process.env.CDN_SECRET_ACCESS_KEY!,
|
|
54
|
-
cdnPublicUrl
|
|
73
|
+
cdnPublicUrl,
|
|
55
74
|
gzip: true,
|
|
56
75
|
forcePathStyle: process.env.CDN_FORCE_PATH_STYLE === 'true',
|
|
57
76
|
region: resolveS3CompatibleStorageRegion(),
|
|
@@ -61,10 +80,46 @@ function createCdnStorageForServer(): IIFilesStorageWithCdn {
|
|
|
61
80
|
return new VercelBlobStorage({
|
|
62
81
|
token: process.env.VERCEL_BLOB_READ_WRITE_TOKEN!,
|
|
63
82
|
pathPrefix: process.env.NEXT_PUBLIC_CDN_PATH_PREFIX || '',
|
|
64
|
-
cdnPublicUrl
|
|
83
|
+
cdnPublicUrl,
|
|
65
84
|
});
|
|
66
85
|
}
|
|
67
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Resolves the CDN public URL from environment configuration.
|
|
89
|
+
*
|
|
90
|
+
* @returns Configured CDN public URL.
|
|
91
|
+
* @private helper of `$provideCdnForServer`
|
|
92
|
+
*/
|
|
93
|
+
function resolveConfiguredCdnPublicUrl(): URL {
|
|
94
|
+
return new URL(process.env.NEXT_PUBLIC_CDN_PUBLIC_URL!);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Resolves the public URL that should be used for CDN links for one server request.
|
|
99
|
+
*
|
|
100
|
+
* Self-contained S3 is proxied through the current server domain. The configured
|
|
101
|
+
* CDN public URL still owns the `/s3/<bucket>` path, but the origin must follow
|
|
102
|
+
* the active server so uploads are not published under the VPS raw IP address.
|
|
103
|
+
*
|
|
104
|
+
* @param serverPublicUrl - Public URL of the active server.
|
|
105
|
+
* @returns Request-aware CDN public URL.
|
|
106
|
+
*/
|
|
107
|
+
export function resolveCdnPublicUrlForServer(serverPublicUrl: URL): URL {
|
|
108
|
+
const configuredCdnPublicUrl = resolveConfiguredCdnPublicUrl();
|
|
109
|
+
|
|
110
|
+
if (!isSelfContainedS3StorageSelected()) {
|
|
111
|
+
return configuredCdnPublicUrl;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const cdnPublicUrl = new URL(configuredCdnPublicUrl.href);
|
|
115
|
+
cdnPublicUrl.protocol = serverPublicUrl.protocol;
|
|
116
|
+
cdnPublicUrl.host = serverPublicUrl.host;
|
|
117
|
+
cdnPublicUrl.username = '';
|
|
118
|
+
cdnPublicUrl.password = '';
|
|
119
|
+
|
|
120
|
+
return cdnPublicUrl;
|
|
121
|
+
}
|
|
122
|
+
|
|
68
123
|
/**
|
|
69
124
|
* Checks whether the current environment should use the S3-compatible storage implementation.
|
|
70
125
|
*
|
|
@@ -91,6 +146,15 @@ function getS3CompatibleStorageMode(): string {
|
|
|
91
146
|
return (process.env.PTBK_FILE_STORAGE_MODE || process.env.CDN_PROVIDER || '').toLowerCase();
|
|
92
147
|
}
|
|
93
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Checks whether the bundled self-contained S3 storage mode is selected.
|
|
151
|
+
*
|
|
152
|
+
* @returns `true` when self-contained S3 is selected.
|
|
153
|
+
*/
|
|
154
|
+
export function isSelfContainedS3StorageSelected(): boolean {
|
|
155
|
+
return getS3CompatibleStorageMode() === 'self-contained-s3';
|
|
156
|
+
}
|
|
157
|
+
|
|
94
158
|
/**
|
|
95
159
|
* Resolves the S3 signing region used by AWS SDK requests.
|
|
96
160
|
*
|
|
@@ -102,7 +166,7 @@ function resolveS3CompatibleStorageRegion(): string {
|
|
|
102
166
|
return configuredRegion;
|
|
103
167
|
}
|
|
104
168
|
|
|
105
|
-
if (
|
|
169
|
+
if (isSelfContainedS3StorageSelected()) {
|
|
106
170
|
return SELF_CONTAINED_S3_DEFAULT_REGION;
|
|
107
171
|
}
|
|
108
172
|
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { access, readFile, readdir } from 'node:fs/promises';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import type { string_book } from '../../../../../src/book-2.0/agent-source/string_book';
|
|
4
|
+
import { DatabaseError } from '../../../../../src/errors/DatabaseError';
|
|
5
|
+
import { spaceTrim } from 'spacetrim';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Options for loading bundled default agent books.
|
|
9
|
+
*
|
|
10
|
+
* @private utility of Agents Server default-agent seeding
|
|
11
|
+
*/
|
|
12
|
+
export type LoadDefaultAgentBooksOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* Optional explicit directory containing `*.book` files.
|
|
15
|
+
*/
|
|
16
|
+
readonly defaultAgentDirectory?: string | null;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Candidate directories where bundled default agent books can be located.
|
|
21
|
+
*
|
|
22
|
+
* The app test suite runs from `apps/agents-server`, local development usually runs from the repository root, and
|
|
23
|
+
* installer scripts can pass an explicit directory through `LoadDefaultAgentBooksOptions`.
|
|
24
|
+
*
|
|
25
|
+
* @private utility of Agents Server default-agent seeding
|
|
26
|
+
*/
|
|
27
|
+
const DEFAULT_AGENT_DIRECTORY_CANDIDATES = [
|
|
28
|
+
resolve(process.cwd(), 'agents', 'default'),
|
|
29
|
+
resolve(process.cwd(), '..', '..', 'agents', 'default'),
|
|
30
|
+
resolve(__dirname, '../../../../../agents/default'),
|
|
31
|
+
] as const;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Loads all default agent books in deterministic filename order.
|
|
35
|
+
*
|
|
36
|
+
* @param options - Optional explicit default-agent directory.
|
|
37
|
+
* @returns Sorted default agent sources.
|
|
38
|
+
*
|
|
39
|
+
* @private utility of Agents Server default-agent seeding
|
|
40
|
+
*/
|
|
41
|
+
export async function loadDefaultAgentBooks(
|
|
42
|
+
options: LoadDefaultAgentBooksOptions = {},
|
|
43
|
+
): Promise<ReadonlyArray<string_book>> {
|
|
44
|
+
const defaultAgentDirectory = await resolveDefaultAgentDirectory(options);
|
|
45
|
+
const directoryEntries = await readdir(defaultAgentDirectory);
|
|
46
|
+
const defaultAgentFilenames = directoryEntries
|
|
47
|
+
.filter((entry) => entry.toLowerCase().endsWith('.book'))
|
|
48
|
+
.sort((leftFilename, rightFilename) => leftFilename.localeCompare(rightFilename));
|
|
49
|
+
|
|
50
|
+
return Promise.all(
|
|
51
|
+
defaultAgentFilenames.map(async (filename) => {
|
|
52
|
+
const filePath = resolve(defaultAgentDirectory, filename);
|
|
53
|
+
return (await readFile(filePath, 'utf-8')) as string_book;
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Resolves the repository directory that stores default agent books.
|
|
60
|
+
*
|
|
61
|
+
* @param options - Optional explicit default-agent directory.
|
|
62
|
+
* @returns Absolute path to `agents/default`.
|
|
63
|
+
*
|
|
64
|
+
* @private utility of Agents Server default-agent seeding
|
|
65
|
+
*/
|
|
66
|
+
export async function resolveDefaultAgentDirectory(options: LoadDefaultAgentBooksOptions = {}): Promise<string> {
|
|
67
|
+
const directoryCandidates = [
|
|
68
|
+
...(options.defaultAgentDirectory ? [resolve(options.defaultAgentDirectory)] : []),
|
|
69
|
+
...DEFAULT_AGENT_DIRECTORY_CANDIDATES,
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
for (const directoryCandidate of directoryCandidates) {
|
|
73
|
+
try {
|
|
74
|
+
await access(directoryCandidate);
|
|
75
|
+
return directoryCandidate;
|
|
76
|
+
} catch {
|
|
77
|
+
// Continue to the next candidate directory.
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
throw new DatabaseError(
|
|
82
|
+
spaceTrim(
|
|
83
|
+
(block) => `
|
|
84
|
+
Failed to locate the default Agents Server books directory.
|
|
85
|
+
|
|
86
|
+
Checked:
|
|
87
|
+
${block(directoryCandidates.map((candidate) => `- \`${normalizePathForLogs(candidate)}\``).join('\n'))}
|
|
88
|
+
`,
|
|
89
|
+
),
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Normalizes path separators for diagnostics.
|
|
95
|
+
*
|
|
96
|
+
* @param value - Raw filesystem path.
|
|
97
|
+
* @returns Slash-normalized path.
|
|
98
|
+
*
|
|
99
|
+
* @private utility of Agents Server default-agent seeding
|
|
100
|
+
*/
|
|
101
|
+
function normalizePathForLogs(value: string): string {
|
|
102
|
+
return value.split('\\').join('/');
|
|
103
|
+
}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
$provideCdnForServer,
|
|
3
|
+
isSelfContainedS3StorageSelected,
|
|
4
|
+
resolveCdnPublicUrlForServer,
|
|
5
|
+
} from '@/src/tools/$provideCdnForServer';
|
|
6
|
+
import { $provideServer } from '@/src/tools/$provideServer';
|
|
7
|
+
import { NotAllowed } from '../../../../../src/errors/NotAllowed';
|
|
2
8
|
import { InlineKnowledgeSourceUploader } from '../../../../../src/utils/knowledge/inlineKnowledgeSource';
|
|
3
9
|
import type { string_knowledge_source_link } from '../../../../../src/types/typeAliases';
|
|
4
10
|
import { getSafeCdnPath } from '../cdn/utils/getSafeCdnPath';
|
|
5
11
|
import { getUserFileCdnKey } from '../cdn/utils/getUserFileCdnKey';
|
|
12
|
+
import { resolveFileUploadAvailability } from '../upload/fileUploadAvailability';
|
|
6
13
|
|
|
7
14
|
/**
|
|
8
15
|
* Options for create inline knowledge uploader.
|
|
@@ -23,18 +30,30 @@ const uploadCache = new Map<string, Promise<string_knowledge_source_link>>();
|
|
|
23
30
|
export function createInlineKnowledgeSourceUploader(
|
|
24
31
|
options: CreateInlineKnowledgeUploaderOptions = {},
|
|
25
32
|
): InlineKnowledgeSourceUploader {
|
|
26
|
-
const cdn = $provideCdnForServer();
|
|
27
33
|
const { purpose = 'KNOWLEDGE', userId } = options;
|
|
28
34
|
|
|
29
35
|
return async (source) => {
|
|
36
|
+
const providedServer = await $provideServer();
|
|
37
|
+
const fileUploadAvailability = resolveFileUploadAvailability({
|
|
38
|
+
serverId: providedServer.id,
|
|
39
|
+
serverPublicUrl: providedServer.publicUrl,
|
|
40
|
+
isSelfContainedS3StorageSelected: isSelfContainedS3StorageSelected(),
|
|
41
|
+
});
|
|
42
|
+
if (!fileUploadAvailability.isUploadAvailable) {
|
|
43
|
+
throw new NotAllowed(fileUploadAvailability.message || 'File uploads are not available for this server.');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const cdnPublicUrl = resolveCdnPublicUrlForServer(providedServer.publicUrl);
|
|
47
|
+
const cdn = $provideCdnForServer({ cdnPublicUrl });
|
|
30
48
|
const rawKey = getUserFileCdnKey(source.buffer, source.filename);
|
|
31
49
|
const safeKey = getSafeCdnPath({
|
|
32
50
|
pathname: rawKey,
|
|
33
51
|
pathPrefix: process.env.NEXT_PUBLIC_CDN_PATH_PREFIX,
|
|
34
52
|
});
|
|
53
|
+
const uploadCacheKey = `${providedServer.tablePrefix}:${cdnPublicUrl.href}:${safeKey}`;
|
|
35
54
|
|
|
36
|
-
if (uploadCache.has(
|
|
37
|
-
return uploadCache.get(
|
|
55
|
+
if (uploadCache.has(uploadCacheKey)) {
|
|
56
|
+
return uploadCache.get(uploadCacheKey)!;
|
|
38
57
|
}
|
|
39
58
|
|
|
40
59
|
const promise: Promise<string_knowledge_source_link> = (async () => {
|
|
@@ -48,7 +67,7 @@ export function createInlineKnowledgeSourceUploader(
|
|
|
48
67
|
return cdn.getItemUrl(safeKey).href;
|
|
49
68
|
})();
|
|
50
69
|
|
|
51
|
-
uploadCache.set(
|
|
70
|
+
uploadCache.set(uploadCacheKey, promise);
|
|
52
71
|
return promise;
|
|
53
72
|
};
|
|
54
73
|
}
|
|
@@ -39,6 +39,15 @@ export type SpawnAgentLimits = {
|
|
|
39
39
|
readonly rateLimitWindowMs: number;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Dedicated subset consumed by the local coding-agent runner.
|
|
44
|
+
*
|
|
45
|
+
* @private internal Agents Server type
|
|
46
|
+
*/
|
|
47
|
+
export type LocalAgentRunnerLimits = {
|
|
48
|
+
readonly maxFailedAttempts: number;
|
|
49
|
+
};
|
|
50
|
+
|
|
42
51
|
/**
|
|
43
52
|
* Row shape loaded from the dedicated `ServerLimit` table.
|
|
44
53
|
*
|
|
@@ -250,6 +259,20 @@ export async function getSpawnAgentLimits(): Promise<SpawnAgentLimits> {
|
|
|
250
259
|
};
|
|
251
260
|
}
|
|
252
261
|
|
|
262
|
+
/**
|
|
263
|
+
* Loads the local coding-agent runner retry limits.
|
|
264
|
+
*
|
|
265
|
+
* @returns Dedicated local agent runner limits.
|
|
266
|
+
*
|
|
267
|
+
* @private internal Agents Server helper
|
|
268
|
+
*/
|
|
269
|
+
export async function getLocalAgentRunnerLimits(): Promise<LocalAgentRunnerLimits> {
|
|
270
|
+
const limits = await getServerLimits();
|
|
271
|
+
return {
|
|
272
|
+
maxFailedAttempts: limits[SERVER_LIMIT_KEYS.LOCAL_AGENT_RUNNER_MAX_FAILED_ATTEMPTS],
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
253
276
|
/**
|
|
254
277
|
* Normalizes one arbitrary key/value object into the supported dedicated server-limit payload.
|
|
255
278
|
*
|
|
@@ -277,7 +300,9 @@ export function normalizeServerLimitValues(rawValue: Record<string, unknown>): S
|
|
|
277
300
|
*/
|
|
278
301
|
async function loadLegacyServerLimits(): Promise<Partial<Record<ServerLimitKey, unknown>>> {
|
|
279
302
|
const metadata = await getMetadataMap(DEPRECATED_LIMIT_METADATA_KEYS);
|
|
280
|
-
const normalizedToolUsageLimits = normalizeToolUsageLimits(
|
|
303
|
+
const normalizedToolUsageLimits = normalizeToolUsageLimits(
|
|
304
|
+
parseJsonValue(metadata[TOOL_USAGE_LIMITS_METADATA_KEY]),
|
|
305
|
+
);
|
|
281
306
|
|
|
282
307
|
return {
|
|
283
308
|
[SERVER_LIMIT_KEYS.TIMEOUT_MAX_ACTIVE_PER_CHAT]: normalizedToolUsageLimits.timeout.maxActivePerChat,
|
package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerDefaultAgents.ts
CHANGED
|
@@ -1,26 +1,9 @@
|
|
|
1
|
-
import { access, readFile, readdir } from 'node:fs/promises';
|
|
2
|
-
import { resolve } from 'node:path';
|
|
3
|
-
import type { string_book } from '../../../../../../src/book-2.0/agent-source/string_book';
|
|
4
1
|
import { createAgentPersistenceRecords } from '../../../../../../src/collection/agent-collection/constructors/agent-collection-in-supabase/createAgentPersistenceRecords';
|
|
5
|
-
import { DatabaseError } from '../../../../../../src/errors/DatabaseError';
|
|
6
2
|
import type { Client } from 'pg';
|
|
7
|
-
import {
|
|
3
|
+
import { loadDefaultAgentBooks } from '../../defaultAgents/loadDefaultAgentBooks';
|
|
8
4
|
import { createInsertStatement, quoteIdentifier, type SqlRecorder } from './createSqlRecorder';
|
|
9
5
|
import type { NormalizedCreateServerInput } from './normalizeCreateServerInput';
|
|
10
6
|
|
|
11
|
-
/**
|
|
12
|
-
* Candidate directories where bundled default agent books can be located.
|
|
13
|
-
*
|
|
14
|
-
* The app test suite runs from `apps/agents-server`, while local development usually runs from the repository root.
|
|
15
|
-
*
|
|
16
|
-
* @private function of createManagedServer
|
|
17
|
-
*/
|
|
18
|
-
const DEFAULT_AGENT_DIRECTORY_CANDIDATES = [
|
|
19
|
-
resolve(process.cwd(), 'agents', 'default'),
|
|
20
|
-
resolve(process.cwd(), '..', '..', 'agents', 'default'),
|
|
21
|
-
resolve(__dirname, '../../../../../../agents/default'),
|
|
22
|
-
] as const;
|
|
23
|
-
|
|
24
7
|
/**
|
|
25
8
|
* Loads default agent books from the repository and persists them into the newly created server.
|
|
26
9
|
*
|
|
@@ -118,70 +101,3 @@ export async function seedServerDefaultAgents(
|
|
|
118
101
|
sqlRecorder.addStatement(createInsertStatement(`${input.tablePrefix}AgentHistory`, agentHistoryInsertRecord));
|
|
119
102
|
}
|
|
120
103
|
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Loads all default agent books in deterministic filename order.
|
|
124
|
-
*
|
|
125
|
-
* @returns Sorted default agent sources.
|
|
126
|
-
*
|
|
127
|
-
* @private function of `seedServerDefaultAgents`
|
|
128
|
-
*/
|
|
129
|
-
async function loadDefaultAgentBooks(): Promise<ReadonlyArray<string_book>> {
|
|
130
|
-
const defaultAgentDirectory = await resolveDefaultAgentDirectory();
|
|
131
|
-
const directoryEntries = await readdir(defaultAgentDirectory);
|
|
132
|
-
const defaultAgentFilenames = directoryEntries
|
|
133
|
-
.filter((entry) => entry.toLowerCase().endsWith('.book'))
|
|
134
|
-
.sort((leftFilename, rightFilename) => leftFilename.localeCompare(rightFilename));
|
|
135
|
-
|
|
136
|
-
return Promise.all(
|
|
137
|
-
defaultAgentFilenames.map(async (filename) => {
|
|
138
|
-
const filePath = resolve(defaultAgentDirectory, filename);
|
|
139
|
-
return (await readFile(filePath, 'utf-8')) as string_book;
|
|
140
|
-
}),
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Resolves the repository directory that stores default managed-server agents.
|
|
146
|
-
*
|
|
147
|
-
* @returns Absolute path to `agents/default`.
|
|
148
|
-
*
|
|
149
|
-
* @private function of `seedServerDefaultAgents`
|
|
150
|
-
*/
|
|
151
|
-
async function resolveDefaultAgentDirectory(): Promise<string> {
|
|
152
|
-
for (const directoryCandidate of DEFAULT_AGENT_DIRECTORY_CANDIDATES) {
|
|
153
|
-
try {
|
|
154
|
-
await access(directoryCandidate);
|
|
155
|
-
return directoryCandidate;
|
|
156
|
-
} catch {
|
|
157
|
-
// Continue to the next candidate directory.
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
throw new DatabaseError(
|
|
162
|
-
spaceTrim(
|
|
163
|
-
(block) => `
|
|
164
|
-
Failed to locate the default Agents Server books directory.
|
|
165
|
-
|
|
166
|
-
Checked:
|
|
167
|
-
${block(
|
|
168
|
-
DEFAULT_AGENT_DIRECTORY_CANDIDATES.map(
|
|
169
|
-
(candidate) => `- \`${normalizePathForLogs(candidate)}\``,
|
|
170
|
-
).join('\n'),
|
|
171
|
-
)}
|
|
172
|
-
`,
|
|
173
|
-
),
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Normalizes path separators for diagnostics.
|
|
179
|
-
*
|
|
180
|
-
* @param value - Raw filesystem path.
|
|
181
|
-
* @returns Slash-normalized path.
|
|
182
|
-
*
|
|
183
|
-
* @private function of `seedServerDefaultAgents`
|
|
184
|
-
*/
|
|
185
|
-
function normalizePathForLogs(value: string): string {
|
|
186
|
-
return value.split('\\').join('/');
|
|
187
|
-
}
|