@promptbook/cli 0.112.0-103 → 0.112.0-104
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/AddAgentButton.tsx +0 -5
- package/apps/agents-server/src/app/actions.ts +50 -0
- package/apps/agents-server/src/app/agents/[agentName]/AgentProfileChat.tsx +3 -4
- package/apps/agents-server/src/app/api/health/route.ts +18 -0
- package/apps/agents-server/src/components/AgentProfile/AgentProfile.tsx +1 -4
- package/apps/agents-server/src/components/Header/Header.tsx +0 -11
- package/apps/agents-server/src/components/Header/useHeaderAgentMenus.tsx +0 -5
- package/apps/agents-server/src/components/NewAgentDialog/useNewAgentDialog.tsx +39 -16
- package/apps/agents-server/src/constants/defaultAgentAvatarVisual.ts +1 -1
- package/apps/agents-server/src/database/migrations/2026-06-0200-default-agent-avatar-visual-octopus3d3.sql +16 -0
- package/apps/agents-server/src/middleware.ts +2 -1
- package/apps/agents-server/src/tools/$provideCdnForServer.ts +43 -2
- package/apps/agents-server/src/utils/agentRouting/resolveAgentRouteTarget.ts +27 -4
- package/apps/agents-server/src/utils/defaultAgents/defaultAgents.ts +168 -0
- package/apps/agents-server/src/utils/defaultAgents/installDefaultAgents.ts +139 -0
- package/esm/index.es.js +518 -7
- package/esm/index.es.js.map +1 -1
- package/esm/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
- package/esm/src/avatars/visuals/octopus3d3AvatarVisual.d.ts +7 -0
- package/package.json +1 -1
- package/src/avatars/types/AvatarVisualDefinition.ts +1 -0
- package/src/avatars/visuals/avatarVisualRegistry.ts +2 -0
- package/src/avatars/visuals/octopus3d3AvatarVisual.ts +903 -0
- package/src/other/templates/getTemplatesPipelineCollection.ts +784 -716
- package/src/utils/agents/resolveAgentAvatarImageUrl.ts +1 -1
- package/src/version.ts +1 -1
- package/src/versions.txt +1 -1
- package/umd/index.umd.js +518 -7
- package/umd/index.umd.js.map +1 -1
- package/umd/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
- package/umd/src/avatars/visuals/octopus3d3AvatarVisual.d.ts +7 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { readdir, readFile } from 'fs/promises';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import type { AgentBasicInformation, AgentCollection, string_book } from '@promptbook-local/types';
|
|
4
|
+
import { parseAgentSource } from '../../../../../src/book-2.0/agent-source/parseAgentSource';
|
|
5
|
+
import { DEFAULT_AGENT_VISIBILITY } from '../agentVisibility';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Installation status for one default agent book.
|
|
9
|
+
*
|
|
10
|
+
* @private shared utility for Agents Server default-agent installation
|
|
11
|
+
*/
|
|
12
|
+
export type DefaultAgentInstallStatus = 'installed' | 'skipped';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Result for one processed default agent book.
|
|
16
|
+
*
|
|
17
|
+
* @private shared utility for Agents Server default-agent installation
|
|
18
|
+
*/
|
|
19
|
+
export type DefaultAgentInstallRecord = {
|
|
20
|
+
/**
|
|
21
|
+
* Source book filename.
|
|
22
|
+
*/
|
|
23
|
+
readonly fileName: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Parsed canonical agent name.
|
|
27
|
+
*/
|
|
28
|
+
readonly agentName: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Whether the agent was created or skipped because an active agent with the same name already exists.
|
|
32
|
+
*/
|
|
33
|
+
readonly status: DefaultAgentInstallStatus;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Permanent id of the newly created agent, if created.
|
|
37
|
+
*/
|
|
38
|
+
readonly permanentId?: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Aggregate default-agent installation result.
|
|
43
|
+
*
|
|
44
|
+
* @private shared utility for Agents Server default-agent installation
|
|
45
|
+
*/
|
|
46
|
+
export type DefaultAgentInstallResult = {
|
|
47
|
+
/**
|
|
48
|
+
* Number of newly created agents.
|
|
49
|
+
*/
|
|
50
|
+
readonly installedCount: number;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Number of already-present agents skipped by name.
|
|
54
|
+
*/
|
|
55
|
+
readonly skippedCount: number;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Per-book processing records.
|
|
59
|
+
*/
|
|
60
|
+
readonly records: ReadonlyArray<DefaultAgentInstallRecord>;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Options for installing default agents from a directory.
|
|
65
|
+
*
|
|
66
|
+
* @private shared utility for Agents Server default-agent installation
|
|
67
|
+
*/
|
|
68
|
+
export type InstallDefaultAgentsFromDirectoryOptions = {
|
|
69
|
+
/**
|
|
70
|
+
* Agent collection used for persistence.
|
|
71
|
+
*/
|
|
72
|
+
readonly collection: AgentCollection;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Directory containing the repository default `*.book` files.
|
|
76
|
+
*/
|
|
77
|
+
readonly defaultAgentsDirectoryPath: string;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Optional logger for install-time progress.
|
|
81
|
+
*/
|
|
82
|
+
readonly logger?: Pick<Console, 'info'>;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Lists repository default book filenames in stable install order.
|
|
87
|
+
*
|
|
88
|
+
* @param defaultAgentsDirectoryPath - Directory containing default `*.book` files.
|
|
89
|
+
* @returns Sorted book filenames.
|
|
90
|
+
*
|
|
91
|
+
* @private shared utility for Agents Server default-agent installation
|
|
92
|
+
*/
|
|
93
|
+
export async function listDefaultAgentBookFileNames(defaultAgentsDirectoryPath: string): Promise<ReadonlyArray<string>> {
|
|
94
|
+
const directoryEntries = await readdir(defaultAgentsDirectoryPath, { withFileTypes: true });
|
|
95
|
+
|
|
96
|
+
return directoryEntries
|
|
97
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith('.book'))
|
|
98
|
+
.map((entry) => entry.name)
|
|
99
|
+
.sort((left, right) => left.localeCompare(right));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Creates default agents from repository `*.book` files, skipping already-active agents with matching names.
|
|
104
|
+
*
|
|
105
|
+
* @param options - Installation options.
|
|
106
|
+
* @returns Aggregate installation result.
|
|
107
|
+
*
|
|
108
|
+
* @private shared utility for Agents Server default-agent installation
|
|
109
|
+
*/
|
|
110
|
+
export async function installDefaultAgentsFromDirectory(
|
|
111
|
+
options: InstallDefaultAgentsFromDirectoryOptions,
|
|
112
|
+
): Promise<DefaultAgentInstallResult> {
|
|
113
|
+
const fileNames = await listDefaultAgentBookFileNames(options.defaultAgentsDirectoryPath);
|
|
114
|
+
const existingAgentNames = new Set((await options.collection.listAgents()).map((agent) => agent.agentName));
|
|
115
|
+
const records: Array<DefaultAgentInstallRecord> = [];
|
|
116
|
+
|
|
117
|
+
for (const [index, fileName] of fileNames.entries()) {
|
|
118
|
+
const agentSource = (await readFile(join(options.defaultAgentsDirectoryPath, fileName), 'utf-8')) as string_book;
|
|
119
|
+
const parsedAgentProfile = parseAgentSource(agentSource);
|
|
120
|
+
const agentName = parsedAgentProfile.agentName;
|
|
121
|
+
|
|
122
|
+
if (existingAgentNames.has(agentName)) {
|
|
123
|
+
options.logger?.info(`[default-agents] Skipping existing agent "${agentName}" from ${fileName}.`);
|
|
124
|
+
records.push({
|
|
125
|
+
fileName,
|
|
126
|
+
agentName,
|
|
127
|
+
status: 'skipped',
|
|
128
|
+
});
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const createdAgent = await options.collection.createAgent(agentSource, {
|
|
133
|
+
sortOrder: index + 1,
|
|
134
|
+
visibility: DEFAULT_AGENT_VISIBILITY,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
existingAgentNames.add(createdAgent.agentName);
|
|
138
|
+
options.logger?.info(`[default-agents] Installed "${createdAgent.agentName}" from ${fileName}.`);
|
|
139
|
+
records.push(createInstalledDefaultAgentRecord(fileName, createdAgent));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
installedCount: records.filter((record) => record.status === 'installed').length,
|
|
144
|
+
skippedCount: records.filter((record) => record.status === 'skipped').length,
|
|
145
|
+
records,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Creates a typed result record for a newly installed default agent.
|
|
151
|
+
*
|
|
152
|
+
* @param fileName - Source book filename.
|
|
153
|
+
* @param createdAgent - Created agent profile returned by the collection.
|
|
154
|
+
* @returns Installation record.
|
|
155
|
+
*
|
|
156
|
+
* @private utility of `installDefaultAgentsFromDirectory`
|
|
157
|
+
*/
|
|
158
|
+
function createInstalledDefaultAgentRecord(
|
|
159
|
+
fileName: string,
|
|
160
|
+
createdAgent: AgentBasicInformation & Required<Pick<AgentBasicInformation, 'permanentId'>>,
|
|
161
|
+
): DefaultAgentInstallRecord {
|
|
162
|
+
return {
|
|
163
|
+
fileName,
|
|
164
|
+
agentName: createdAgent.agentName,
|
|
165
|
+
status: 'installed',
|
|
166
|
+
permanentId: createdAgent.permanentId,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import * as dotenv from 'dotenv';
|
|
2
|
+
import { createClient, type SupabaseClient } from '@supabase/supabase-js';
|
|
3
|
+
import { AgentCollectionInSupabase } from '../../../../../src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase';
|
|
4
|
+
import type { AgentCollection } from '../../../../../src/collection/agent-collection/AgentCollection';
|
|
5
|
+
import { isAgentsServerSqliteMode } from '../../database/agentsServerDatabaseMode';
|
|
6
|
+
import { $provideLocalSqliteSupabase } from '../../database/sqlite/$provideLocalSqliteSupabase';
|
|
7
|
+
import { installDefaultAgentsFromDirectory } from './defaultAgents';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Environment variable pointing to the installed Agents Server `.env` file.
|
|
11
|
+
*
|
|
12
|
+
* @private install-time default-agent utility
|
|
13
|
+
*/
|
|
14
|
+
const AGENTS_SERVER_ENV_FILE_ENV_NAME = 'PTBK_AGENTS_SERVER_ENV_FILE';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Environment variable pointing to the repository `agents/default` directory.
|
|
18
|
+
*
|
|
19
|
+
* @private install-time default-agent utility
|
|
20
|
+
*/
|
|
21
|
+
const DEFAULT_AGENTS_DIRECTORY_ENV_NAME = 'PTBK_DEFAULT_AGENTS_DIR';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Environment variable containing the current server table prefix.
|
|
25
|
+
*
|
|
26
|
+
* @private install-time default-agent utility
|
|
27
|
+
*/
|
|
28
|
+
const SUPABASE_TABLE_PREFIX_ENV_NAME = 'SUPABASE_TABLE_PREFIX';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Public Supabase URL environment variable.
|
|
32
|
+
*
|
|
33
|
+
* @private install-time default-agent utility
|
|
34
|
+
*/
|
|
35
|
+
const NEXT_PUBLIC_SUPABASE_URL_ENV_NAME = 'NEXT_PUBLIC_SUPABASE_URL';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Supabase service role key environment variable.
|
|
39
|
+
*
|
|
40
|
+
* @private install-time default-agent utility
|
|
41
|
+
*/
|
|
42
|
+
const SUPABASE_SERVICE_ROLE_KEY_ENV_NAME = 'SUPABASE_SERVICE_ROLE_KEY';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Public Supabase anon key environment variable used as a fallback when service role is unavailable.
|
|
46
|
+
*
|
|
47
|
+
* @private install-time default-agent utility
|
|
48
|
+
*/
|
|
49
|
+
const NEXT_PUBLIC_SUPABASE_ANON_KEY_ENV_NAME = 'NEXT_PUBLIC_SUPABASE_ANON_KEY';
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Loads the installed Agents Server environment for the detached installer script.
|
|
53
|
+
*
|
|
54
|
+
* @private install-time default-agent utility
|
|
55
|
+
*/
|
|
56
|
+
function loadDefaultAgentInstallEnvironment(): void {
|
|
57
|
+
const explicitEnvFilePath = process.env[AGENTS_SERVER_ENV_FILE_ENV_NAME]?.trim();
|
|
58
|
+
if (explicitEnvFilePath) {
|
|
59
|
+
const explicitLoadResult = dotenv.config({ path: explicitEnvFilePath });
|
|
60
|
+
if (!explicitLoadResult.error) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
dotenv.config();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Creates the install-time agent collection using the same database backend as the server.
|
|
70
|
+
*
|
|
71
|
+
* @returns Agent collection bound to the configured table prefix.
|
|
72
|
+
*
|
|
73
|
+
* @private install-time default-agent utility
|
|
74
|
+
*/
|
|
75
|
+
function createDefaultAgentInstallCollection(): AgentCollection {
|
|
76
|
+
return new AgentCollectionInSupabase(createDefaultAgentInstallSupabaseClient(), {
|
|
77
|
+
tablePrefix: process.env[SUPABASE_TABLE_PREFIX_ENV_NAME] || '',
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Creates the Supabase-shaped client used by the install-time agent collection.
|
|
83
|
+
*
|
|
84
|
+
* @returns Supabase or local SQLite client.
|
|
85
|
+
*
|
|
86
|
+
* @private install-time default-agent utility
|
|
87
|
+
*/
|
|
88
|
+
function createDefaultAgentInstallSupabaseClient(): SupabaseClient {
|
|
89
|
+
if (isAgentsServerSqliteMode()) {
|
|
90
|
+
return $provideLocalSqliteSupabase();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const supabaseUrl = process.env[NEXT_PUBLIC_SUPABASE_URL_ENV_NAME];
|
|
94
|
+
const supabaseKey =
|
|
95
|
+
process.env[SUPABASE_SERVICE_ROLE_KEY_ENV_NAME] || process.env[NEXT_PUBLIC_SUPABASE_ANON_KEY_ENV_NAME];
|
|
96
|
+
|
|
97
|
+
if (!supabaseUrl || !supabaseKey) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
`Missing \`${NEXT_PUBLIC_SUPABASE_URL_ENV_NAME}\` and \`${SUPABASE_SERVICE_ROLE_KEY_ENV_NAME}\` for Supabase default-agent installation.`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return createClient(supabaseUrl, supabaseKey, {
|
|
104
|
+
auth: {
|
|
105
|
+
autoRefreshToken: false,
|
|
106
|
+
persistSession: false,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Runs the default-agent install command.
|
|
113
|
+
*
|
|
114
|
+
* @private install-time default-agent utility
|
|
115
|
+
*/
|
|
116
|
+
async function installDefaultAgents(): Promise<void> {
|
|
117
|
+
loadDefaultAgentInstallEnvironment();
|
|
118
|
+
|
|
119
|
+
const defaultAgentsDirectoryPath = process.env[DEFAULT_AGENTS_DIRECTORY_ENV_NAME]?.trim();
|
|
120
|
+
if (!defaultAgentsDirectoryPath) {
|
|
121
|
+
throw new Error(`Missing \`${DEFAULT_AGENTS_DIRECTORY_ENV_NAME}\` environment variable.`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const result = await installDefaultAgentsFromDirectory({
|
|
125
|
+
collection: createDefaultAgentInstallCollection(),
|
|
126
|
+
defaultAgentsDirectoryPath,
|
|
127
|
+
logger: console,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
console.info(
|
|
131
|
+
`[default-agents] Finished. Installed ${result.installedCount}, skipped ${result.skippedCount}.`,
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
installDefaultAgents().catch((error) => {
|
|
136
|
+
console.error('[default-agents] Failed to install default agents.');
|
|
137
|
+
console.error(error instanceof Error ? error.message : error);
|
|
138
|
+
process.exitCode = 1;
|
|
139
|
+
});
|