@promptbook/cli 0.112.0-109 → 0.112.0-110
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/agents/[agentName]/api/user-chats/[chatId]/stream/route.ts +86 -4
- package/apps/agents-server/src/database/loadAgentsServerEnvFile.ts +29 -0
- package/apps/agents-server/src/database/migrate.ts +2 -25
- package/apps/agents-server/src/database/seedDefaultAgents.ts +2 -26
- package/apps/agents-server/src/utils/agentRouting/resolveAgentRouteTarget.ts +56 -0
- package/apps/agents-server/src/utils/importAgent.ts +57 -1
- package/apps/agents-server/src/utils/importAgentWithFallback.ts +10 -0
- package/apps/agents-server/src/utils/userChat/getUserChatRevision.ts +145 -0
- package/apps/agents-server/src/utils/userChat.ts +1 -0
- package/esm/index.es.js +226 -105
- package/esm/index.es.js.map +1 -1
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer.d.ts +17 -1
- package/esm/src/cli/cli-commands/agents-server/run.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +7 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/book-components/Chat/Chat/Chat.module.css +5 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer.ts +48 -14
- package/src/cli/cli-commands/agents-server/run.ts +103 -31
- package/src/cli/cli-commands/agents-server/startAgentsServer.ts +111 -35
- package/src/cli/cli-commands/agents-server.ts +7 -1
- package/src/other/templates/getTemplatesPipelineCollection.ts +1081 -516
- package/src/version.ts +2 -2
- package/src/versions.txt +1 -0
- package/umd/index.umd.js +226 -105
- package/umd/index.umd.js.map +1 -1
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer.d.ts +17 -1
- package/umd/src/cli/cli-commands/agents-server/run.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +7 -0
- package/umd/src/version.d.ts +1 -1
|
@@ -34,6 +34,14 @@ export type AgentsServerBuildArtifacts = {
|
|
|
34
34
|
readonly nodeModulesPath: string;
|
|
35
35
|
readonly nextCliPath: string;
|
|
36
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Runtime paths resolved for Agents Server commands before choosing build or dev execution.
|
|
39
|
+
*
|
|
40
|
+
* @private internal type of `ptbk agents-server`
|
|
41
|
+
*/
|
|
42
|
+
export type PreparedAgentsServerRuntime = AgentsServerBuildArtifacts & {
|
|
43
|
+
readonly isAppPathMaterialized: boolean;
|
|
44
|
+
};
|
|
37
45
|
/**
|
|
38
46
|
* Input paths required to validate or update the cached Agents Server build.
|
|
39
47
|
*
|
|
@@ -48,7 +56,15 @@ type AgentsServerBuildCacheOptions = {
|
|
|
48
56
|
*
|
|
49
57
|
* @private internal utility of `ptbk agents-server`
|
|
50
58
|
*/
|
|
51
|
-
export declare function ensureAgentsServerBuild(options?: EnsureAgentsServerBuildOptions): Promise<
|
|
59
|
+
export declare function ensureAgentsServerBuild(options?: EnsureAgentsServerBuildOptions): Promise<PreparedAgentsServerRuntime>;
|
|
60
|
+
/**
|
|
61
|
+
* Resolves the runtime app and dependency paths shared by Agents Server start and dev commands.
|
|
62
|
+
*
|
|
63
|
+
* @private internal utility of `ptbk agents-server`
|
|
64
|
+
*/
|
|
65
|
+
export declare function prepareAgentsServerRuntime(options?: {
|
|
66
|
+
readonly appPath?: string;
|
|
67
|
+
}): Promise<PreparedAgentsServerRuntime>;
|
|
52
68
|
/**
|
|
53
69
|
* Returns true when the production build marker and source fingerprint still match.
|
|
54
70
|
*
|
|
@@ -6,6 +6,12 @@ import type { $side_effect } from '../../../utils/organization/$side_effect';
|
|
|
6
6
|
* @private internal function of `promptbookCli`
|
|
7
7
|
*/
|
|
8
8
|
export declare function $initializeAgentsServerStartCommand(program: Program): $side_effect;
|
|
9
|
+
/**
|
|
10
|
+
* Initializes `agents-server dev` command for Promptbook CLI utilities.
|
|
11
|
+
*
|
|
12
|
+
* @private internal function of `promptbookCli`
|
|
13
|
+
*/
|
|
14
|
+
export declare function $initializeAgentsServerDevCommand(program: Program): $side_effect;
|
|
9
15
|
/**
|
|
10
16
|
* Initializes `agents-server build` command for Promptbook CLI utilities.
|
|
11
17
|
*
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { ThinkingLevel } from '../coder/ThinkingLevel';
|
|
2
2
|
import type { PromptRunnerAgentName } from '../common/promptRunnerCliOptions';
|
|
3
3
|
import type { number_port } from '../../../types/number_positive';
|
|
4
|
+
/**
|
|
5
|
+
* Next runtime mode supported by the local Agents Server foreground launcher.
|
|
6
|
+
*
|
|
7
|
+
* @private internal type of `ptbk agents-server`
|
|
8
|
+
*/
|
|
9
|
+
export type AgentsServerNextRuntimeMode = 'start' | 'dev';
|
|
4
10
|
/**
|
|
5
11
|
* Options required to start the foreground Agents Server service group.
|
|
6
12
|
*
|
|
@@ -13,6 +19,7 @@ export type StartAgentsServerOptions = {
|
|
|
13
19
|
readonly noUi: boolean;
|
|
14
20
|
readonly thinkingLevel?: ThinkingLevel;
|
|
15
21
|
readonly allowCredits: boolean;
|
|
22
|
+
readonly nextRuntimeMode: AgentsServerNextRuntimeMode;
|
|
16
23
|
readonly isBuildForced: boolean;
|
|
17
24
|
};
|
|
18
25
|
/**
|
package/esm/src/version.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
|
|
|
15
15
|
export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
|
|
16
16
|
/**
|
|
17
17
|
* Represents the version string of the Promptbook engine.
|
|
18
|
-
* It follows semantic versioning (e.g., `0.112.0-
|
|
18
|
+
* It follows semantic versioning (e.g., `0.112.0-109`).
|
|
19
19
|
*
|
|
20
20
|
* @generated
|
|
21
21
|
*/
|
package/package.json
CHANGED
|
@@ -176,6 +176,15 @@ export type AgentsServerBuildArtifacts = {
|
|
|
176
176
|
readonly nextCliPath: string;
|
|
177
177
|
};
|
|
178
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Runtime paths resolved for Agents Server commands before choosing build or dev execution.
|
|
181
|
+
*
|
|
182
|
+
* @private internal type of `ptbk agents-server`
|
|
183
|
+
*/
|
|
184
|
+
export type PreparedAgentsServerRuntime = AgentsServerBuildArtifacts & {
|
|
185
|
+
readonly isAppPathMaterialized: boolean;
|
|
186
|
+
};
|
|
187
|
+
|
|
179
188
|
/**
|
|
180
189
|
* Input paths required to validate or update the cached Agents Server build.
|
|
181
190
|
*
|
|
@@ -193,39 +202,64 @@ type AgentsServerBuildCacheOptions = {
|
|
|
193
202
|
*/
|
|
194
203
|
export async function ensureAgentsServerBuild(
|
|
195
204
|
options: EnsureAgentsServerBuildOptions = {},
|
|
196
|
-
): Promise<
|
|
205
|
+
): Promise<PreparedAgentsServerRuntime> {
|
|
197
206
|
const environment = options.environment ?? process.env;
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
const appPath = await resolveAgentsServerBuildAppPath({
|
|
201
|
-
sourceAppPath: options.appPath ?? (await resolveAgentsServerAppPath()),
|
|
202
|
-
nodeModulesPath,
|
|
207
|
+
const preparedRuntime = await prepareAgentsServerRuntime({
|
|
208
|
+
appPath: options.appPath,
|
|
203
209
|
});
|
|
204
|
-
const buildEnvironment = createAgentsServerRuntimeEnvironment(environment, nodeModulesPath, {
|
|
205
|
-
isNextValidationIgnored:
|
|
210
|
+
const buildEnvironment = createAgentsServerRuntimeEnvironment(environment, preparedRuntime.nodeModulesPath, {
|
|
211
|
+
isNextValidationIgnored: preparedRuntime.isAppPathMaterialized,
|
|
206
212
|
});
|
|
207
213
|
|
|
208
214
|
if (
|
|
209
215
|
!options.isBuildForced &&
|
|
210
216
|
(await isAgentsServerBuildCacheCurrent({
|
|
211
|
-
appPath,
|
|
217
|
+
appPath: preparedRuntime.appPath,
|
|
212
218
|
environment: buildEnvironment,
|
|
213
219
|
}))
|
|
214
220
|
) {
|
|
215
221
|
options.onBuildEvent?.('Using the cached Agents Server Next app build.');
|
|
216
|
-
return
|
|
222
|
+
return preparedRuntime;
|
|
217
223
|
}
|
|
218
224
|
|
|
219
225
|
options.onBuildEvent?.('Building the Agents Server Next app.');
|
|
220
226
|
await runNextBuild({
|
|
221
|
-
appPath,
|
|
227
|
+
appPath: preparedRuntime.appPath,
|
|
222
228
|
environment: buildEnvironment,
|
|
223
|
-
nextCliPath,
|
|
229
|
+
nextCliPath: preparedRuntime.nextCliPath,
|
|
224
230
|
onBuildOutput: options.onBuildOutput,
|
|
225
231
|
});
|
|
226
|
-
await writeAgentsServerBuildCache({
|
|
232
|
+
await writeAgentsServerBuildCache({
|
|
233
|
+
appPath: preparedRuntime.appPath,
|
|
234
|
+
environment: buildEnvironment,
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
return preparedRuntime;
|
|
238
|
+
}
|
|
227
239
|
|
|
228
|
-
|
|
240
|
+
/**
|
|
241
|
+
* Resolves the runtime app and dependency paths shared by Agents Server start and dev commands.
|
|
242
|
+
*
|
|
243
|
+
* @private internal utility of `ptbk agents-server`
|
|
244
|
+
*/
|
|
245
|
+
export async function prepareAgentsServerRuntime(
|
|
246
|
+
options: {
|
|
247
|
+
readonly appPath?: string;
|
|
248
|
+
} = {},
|
|
249
|
+
): Promise<PreparedAgentsServerRuntime> {
|
|
250
|
+
const nextCliPath = resolveNextCliPath();
|
|
251
|
+
const nodeModulesPath = resolveNodeModulesPath(nextCliPath);
|
|
252
|
+
const appPath = await resolveAgentsServerBuildAppPath({
|
|
253
|
+
sourceAppPath: options.appPath ?? (await resolveAgentsServerAppPath()),
|
|
254
|
+
nodeModulesPath,
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
appPath,
|
|
259
|
+
nextCliPath,
|
|
260
|
+
nodeModulesPath,
|
|
261
|
+
isAppPathMaterialized: isAgentsServerAppPathMaterialized(appPath),
|
|
262
|
+
};
|
|
229
263
|
}
|
|
230
264
|
|
|
231
265
|
/**
|
|
@@ -17,23 +17,39 @@ import {
|
|
|
17
17
|
PROMPT_RUNNER_DESCRIPTION,
|
|
18
18
|
} from '../common/promptRunnerCliOptions';
|
|
19
19
|
import { ensureAgentsServerBuild } from './buildAgentsServer';
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
loadAgentsServerProjectEnvironment,
|
|
22
|
+
startAgentsServer,
|
|
23
|
+
type AgentsServerNextRuntimeMode,
|
|
24
|
+
} from './startAgentsServer';
|
|
21
25
|
|
|
22
26
|
/**
|
|
23
|
-
* Default port used by `ptbk agents-server start`.
|
|
27
|
+
* Default port used by `ptbk agents-server start` and `ptbk agents-server dev`.
|
|
24
28
|
*
|
|
25
29
|
* @private internal constant of `ptbk agents-server`
|
|
26
30
|
*/
|
|
27
31
|
const DEFAULT_AGENTS_SERVER_PORT = '4440';
|
|
28
32
|
|
|
29
33
|
/**
|
|
30
|
-
* CLI options accepted by `ptbk agents-server start`.
|
|
34
|
+
* CLI options accepted by `ptbk agents-server start` and `ptbk agents-server dev`.
|
|
31
35
|
*
|
|
32
36
|
* @private internal type of `ptbk agents-server`
|
|
33
37
|
*/
|
|
34
|
-
type
|
|
38
|
+
type AgentsServerRuntimeCliOptions = PromptRunnerSelectionCliOptions & {
|
|
35
39
|
readonly port: string;
|
|
36
|
-
readonly forceBuild
|
|
40
|
+
readonly forceBuild?: boolean;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Shared command definition for one Agents Server runtime subcommand.
|
|
45
|
+
*
|
|
46
|
+
* @private internal type of `ptbk agents-server`
|
|
47
|
+
*/
|
|
48
|
+
type AgentsServerRuntimeCommandDefinition = {
|
|
49
|
+
readonly commandName: 'start' | 'dev';
|
|
50
|
+
readonly description: string;
|
|
51
|
+
readonly nextRuntimeMode: AgentsServerNextRuntimeMode;
|
|
52
|
+
readonly isForceBuildSupported: boolean;
|
|
37
53
|
};
|
|
38
54
|
|
|
39
55
|
/**
|
|
@@ -42,19 +58,59 @@ type AgentsServerStartCliOptions = PromptRunnerSelectionCliOptions & {
|
|
|
42
58
|
* @private internal function of `promptbookCli`
|
|
43
59
|
*/
|
|
44
60
|
export function $initializeAgentsServerStartCommand(program: Program): $side_effect {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
Start the Agents Server web app and the local coding-agent message runners
|
|
61
|
+
initializeAgentsServerRuntimeCommand(program, {
|
|
62
|
+
commandName: 'start',
|
|
63
|
+
description: createAgentsServerRuntimeCommandDescription(
|
|
64
|
+
'Start the Agents Server web app and the local coding-agent message runners',
|
|
65
|
+
),
|
|
66
|
+
nextRuntimeMode: 'start',
|
|
67
|
+
isForceBuildSupported: true,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
49
70
|
|
|
50
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Initializes `agents-server dev` command for Promptbook CLI utilities.
|
|
73
|
+
*
|
|
74
|
+
* @private internal function of `promptbookCli`
|
|
75
|
+
*/
|
|
76
|
+
export function $initializeAgentsServerDevCommand(program: Program): $side_effect {
|
|
77
|
+
initializeAgentsServerRuntimeCommand(program, {
|
|
78
|
+
commandName: 'dev',
|
|
79
|
+
description: createAgentsServerRuntimeCommandDescription(
|
|
80
|
+
'Start the Agents Server web app in development mode with hot reloading and the local coding-agent message runners',
|
|
81
|
+
),
|
|
82
|
+
nextRuntimeMode: 'dev',
|
|
83
|
+
isForceBuildSupported: false,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
51
86
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Initializes `agents-server build` command for Promptbook CLI utilities.
|
|
89
|
+
*
|
|
90
|
+
* @private internal function of `promptbookCli`
|
|
91
|
+
*/
|
|
92
|
+
export function $initializeAgentsServerBuildCommand(program: Program): $side_effect {
|
|
93
|
+
const command = program.command('build');
|
|
94
|
+
command.description('Build the Agents Server Next app for later local startup');
|
|
95
|
+
command.action(
|
|
96
|
+
handleActionErrors(async () => {
|
|
97
|
+
console.info(colors.gray('Building Promptbook Agents Server.'));
|
|
98
|
+
loadAgentsServerProjectEnvironment(process.cwd());
|
|
99
|
+
await ensureAgentsServerBuild({ isBuildForced: true });
|
|
100
|
+
}),
|
|
56
101
|
);
|
|
102
|
+
}
|
|
57
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Registers one shared Agents Server runtime command backed by either `next start` or `next dev`.
|
|
106
|
+
*/
|
|
107
|
+
function initializeAgentsServerRuntimeCommand(
|
|
108
|
+
program: Program,
|
|
109
|
+
definition: AgentsServerRuntimeCommandDefinition,
|
|
110
|
+
): $side_effect {
|
|
111
|
+
const command = program.command(definition.commandName);
|
|
112
|
+
|
|
113
|
+
command.description(definition.description);
|
|
58
114
|
addPromptRunnerSelectionOptions(command);
|
|
59
115
|
addPromptRunnerRuntimeOptions(command);
|
|
60
116
|
command.addOption(
|
|
@@ -62,18 +118,21 @@ export function $initializeAgentsServerStartCommand(program: Program): $side_eff
|
|
|
62
118
|
.env('PORT')
|
|
63
119
|
.default(DEFAULT_AGENTS_SERVER_PORT),
|
|
64
120
|
);
|
|
65
|
-
|
|
121
|
+
|
|
122
|
+
if (definition.isForceBuildSupported) {
|
|
123
|
+
command.option('--force-build', 'Rebuild the Agents Server Next app before startup', false);
|
|
124
|
+
}
|
|
66
125
|
|
|
67
126
|
command.action(
|
|
68
127
|
handleActionErrors(
|
|
69
128
|
async (cliOptions) => {
|
|
70
|
-
const options = cliOptions as
|
|
129
|
+
const options = cliOptions as AgentsServerRuntimeCliOptions;
|
|
71
130
|
const port = parseAgentsServerPort(options.port);
|
|
72
131
|
const runnerOptions = normalizePromptRunnerSelectionCliOptions(options, {
|
|
73
132
|
isAgentRequired: true,
|
|
74
133
|
});
|
|
75
134
|
|
|
76
|
-
console.info(colors.gray(
|
|
135
|
+
console.info(colors.gray(createAgentsServerRuntimeStartupMessage(port, definition.nextRuntimeMode)));
|
|
77
136
|
await startAgentsServer({
|
|
78
137
|
port,
|
|
79
138
|
agentName: runnerOptions.agentName!,
|
|
@@ -81,7 +140,8 @@ export function $initializeAgentsServerStartCommand(program: Program): $side_eff
|
|
|
81
140
|
noUi: runnerOptions.noUi,
|
|
82
141
|
thinkingLevel: runnerOptions.thinkingLevel,
|
|
83
142
|
allowCredits: runnerOptions.allowCredits,
|
|
84
|
-
|
|
143
|
+
nextRuntimeMode: definition.nextRuntimeMode,
|
|
144
|
+
isBuildForced: definition.isForceBuildSupported && options.forceBuild === true,
|
|
85
145
|
});
|
|
86
146
|
},
|
|
87
147
|
{
|
|
@@ -92,20 +152,32 @@ export function $initializeAgentsServerStartCommand(program: Program): $side_eff
|
|
|
92
152
|
}
|
|
93
153
|
|
|
94
154
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* @private internal function of `promptbookCli`
|
|
155
|
+
* Creates the shared help description for Agents Server runtime commands.
|
|
98
156
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
);
|
|
157
|
+
function createAgentsServerRuntimeCommandDescription(summary: string): string {
|
|
158
|
+
return spaceTrim(`
|
|
159
|
+
${summary}
|
|
160
|
+
|
|
161
|
+
${PROMPT_RUNNER_DESCRIPTION}
|
|
162
|
+
|
|
163
|
+
The current working directory stores:
|
|
164
|
+
- Agent runner folders in \`.promptbook/agents-server/agents\`
|
|
165
|
+
- Foreground service logs in \`.logs\`
|
|
166
|
+
`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Creates the startup log line for one Agents Server runtime mode.
|
|
171
|
+
*/
|
|
172
|
+
function createAgentsServerRuntimeStartupMessage(
|
|
173
|
+
port: number_port,
|
|
174
|
+
nextRuntimeMode: AgentsServerNextRuntimeMode,
|
|
175
|
+
): string {
|
|
176
|
+
if (nextRuntimeMode === 'dev') {
|
|
177
|
+
return `Starting Promptbook Agents Server on port ${port} in development mode.`;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return `Starting Promptbook Agents Server on port ${port}.`;
|
|
109
181
|
}
|
|
110
182
|
|
|
111
183
|
/**
|
|
@@ -17,6 +17,8 @@ import type { CoderRunUiHandle } from '../../../../scripts/run-codex-prompts/ui/
|
|
|
17
17
|
import {
|
|
18
18
|
createAgentsServerRuntimeEnvironment,
|
|
19
19
|
ensureAgentsServerBuild,
|
|
20
|
+
prepareAgentsServerRuntime,
|
|
21
|
+
type PreparedAgentsServerRuntime,
|
|
20
22
|
resolveAgentsServerAppPath,
|
|
21
23
|
} from './buildAgentsServer';
|
|
22
24
|
import { DEFAULT_LOCAL_AGENT_RUNNER_MAX_FAILED_ATTEMPTS } from '../../../../apps/agents-server/src/constants/serverLimits';
|
|
@@ -112,6 +114,13 @@ const PTBK_HOSTNAME_ENV = 'PTBK_HOSTNAME';
|
|
|
112
114
|
*/
|
|
113
115
|
const LOCAL_USER_CHAT_WORKER_TOKEN_BYTE_LENGTH = 32;
|
|
114
116
|
|
|
117
|
+
/**
|
|
118
|
+
* Next runtime mode supported by the local Agents Server foreground launcher.
|
|
119
|
+
*
|
|
120
|
+
* @private internal type of `ptbk agents-server`
|
|
121
|
+
*/
|
|
122
|
+
export type AgentsServerNextRuntimeMode = 'start' | 'dev';
|
|
123
|
+
|
|
115
124
|
/**
|
|
116
125
|
* Options required to start the foreground Agents Server service group.
|
|
117
126
|
*
|
|
@@ -124,6 +133,7 @@ export type StartAgentsServerOptions = {
|
|
|
124
133
|
readonly noUi: boolean;
|
|
125
134
|
readonly thinkingLevel?: ThinkingLevel;
|
|
126
135
|
readonly allowCredits: boolean;
|
|
136
|
+
readonly nextRuntimeMode: AgentsServerNextRuntimeMode;
|
|
127
137
|
readonly isBuildForced: boolean;
|
|
128
138
|
};
|
|
129
139
|
|
|
@@ -178,6 +188,17 @@ type AgentsServerSupervisorState = {
|
|
|
178
188
|
};
|
|
179
189
|
};
|
|
180
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Prepared Next runtime and child environment used by one foreground launch.
|
|
193
|
+
*
|
|
194
|
+
* @private internal type of `ptbk agents-server`
|
|
195
|
+
*/
|
|
196
|
+
type PreparedAgentsServerLaunch = {
|
|
197
|
+
readonly runtimeArtifacts: PreparedAgentsServerRuntime;
|
|
198
|
+
readonly runtimeChildEnvironment: AgentsServerChildEnvironment;
|
|
199
|
+
readonly runtimePaths: AgentsServerRuntimePaths;
|
|
200
|
+
};
|
|
201
|
+
|
|
181
202
|
/**
|
|
182
203
|
* Local runner limits loaded from the running Agents Server app.
|
|
183
204
|
*
|
|
@@ -216,52 +237,31 @@ export async function startAgentsServer(options: StartAgentsServerOptions): Prom
|
|
|
216
237
|
process.once('exit', processExitHandler);
|
|
217
238
|
|
|
218
239
|
try {
|
|
219
|
-
const
|
|
220
|
-
appPath: runtimePaths.appPath,
|
|
221
|
-
environment: childEnvironment,
|
|
222
|
-
isBuildForced: options.isBuildForced,
|
|
223
|
-
onBuildEvent: (event) => {
|
|
224
|
-
logRunnerEvent(logStreams.runner, event);
|
|
225
|
-
forwardChildOutput(`${event}\n`, {
|
|
226
|
-
label: 'next-build',
|
|
227
|
-
logStream: logStreams.next,
|
|
228
|
-
state,
|
|
229
|
-
});
|
|
230
|
-
},
|
|
231
|
-
onBuildOutput: (chunk) => {
|
|
232
|
-
forwardChildOutput(chunk, {
|
|
233
|
-
label: 'next-build',
|
|
234
|
-
logStream: logStreams.next,
|
|
235
|
-
state,
|
|
236
|
-
});
|
|
237
|
-
},
|
|
238
|
-
});
|
|
239
|
-
const runtimeChildEnvironment = createAgentsServerRuntimeEnvironment(
|
|
240
|
+
const preparedLaunch = await prepareAgentsServerLaunch({
|
|
240
241
|
childEnvironment,
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
};
|
|
242
|
+
logStreams,
|
|
243
|
+
options,
|
|
244
|
+
runtimePaths,
|
|
245
|
+
state,
|
|
246
|
+
});
|
|
247
247
|
|
|
248
248
|
nextServerProcess = startNextServer({
|
|
249
|
-
nextCliPath:
|
|
249
|
+
nextCliPath: preparedLaunch.runtimeArtifacts.nextCliPath,
|
|
250
250
|
options,
|
|
251
|
-
runtimePaths:
|
|
252
|
-
childEnvironment: runtimeChildEnvironment,
|
|
251
|
+
runtimePaths: preparedLaunch.runtimePaths,
|
|
252
|
+
childEnvironment: preparedLaunch.runtimeChildEnvironment,
|
|
253
253
|
logStreams,
|
|
254
254
|
state,
|
|
255
255
|
});
|
|
256
256
|
const localAgentRunnerLimits = await waitForLocalAgentRunnerLimits({
|
|
257
257
|
port: options.port,
|
|
258
|
-
environment: runtimeChildEnvironment,
|
|
258
|
+
environment: preparedLaunch.runtimeChildEnvironment,
|
|
259
259
|
logStreams,
|
|
260
260
|
state,
|
|
261
261
|
});
|
|
262
262
|
stopUserChatJobWorkerPump = startUserChatJobWorkerPump({
|
|
263
263
|
port: options.port,
|
|
264
|
-
environment: runtimeChildEnvironment,
|
|
264
|
+
environment: preparedLaunch.runtimeChildEnvironment,
|
|
265
265
|
logStreams,
|
|
266
266
|
state,
|
|
267
267
|
});
|
|
@@ -290,6 +290,70 @@ export async function startAgentsServer(options: StartAgentsServerOptions): Prom
|
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
+
/**
|
|
294
|
+
* Prepares the shared Next runtime for either production start or hot-reloading development mode.
|
|
295
|
+
*/
|
|
296
|
+
async function prepareAgentsServerLaunch(options: {
|
|
297
|
+
readonly childEnvironment: AgentsServerChildEnvironment;
|
|
298
|
+
readonly logStreams: AgentsServerLogStreams;
|
|
299
|
+
readonly options: StartAgentsServerOptions;
|
|
300
|
+
readonly runtimePaths: AgentsServerRuntimePaths;
|
|
301
|
+
readonly state: AgentsServerSupervisorState;
|
|
302
|
+
}): Promise<PreparedAgentsServerLaunch> {
|
|
303
|
+
const runtimeArtifacts =
|
|
304
|
+
options.options.nextRuntimeMode === 'start'
|
|
305
|
+
? await ensureAgentsServerBuild({
|
|
306
|
+
appPath: options.runtimePaths.appPath,
|
|
307
|
+
environment: options.childEnvironment,
|
|
308
|
+
isBuildForced: options.options.isBuildForced,
|
|
309
|
+
onBuildEvent: (event) => {
|
|
310
|
+
logRunnerEvent(options.logStreams.runner, event);
|
|
311
|
+
forwardChildOutput(`${event}\n`, {
|
|
312
|
+
label: 'next-build',
|
|
313
|
+
logStream: options.logStreams.next,
|
|
314
|
+
state: options.state,
|
|
315
|
+
});
|
|
316
|
+
},
|
|
317
|
+
onBuildOutput: (chunk) => {
|
|
318
|
+
forwardChildOutput(chunk, {
|
|
319
|
+
label: 'next-build',
|
|
320
|
+
logStream: options.logStreams.next,
|
|
321
|
+
state: options.state,
|
|
322
|
+
});
|
|
323
|
+
},
|
|
324
|
+
})
|
|
325
|
+
: await prepareAgentsServerDevelopmentRuntime(options.runtimePaths.appPath, options.logStreams.runner);
|
|
326
|
+
|
|
327
|
+
return {
|
|
328
|
+
runtimeArtifacts,
|
|
329
|
+
runtimeChildEnvironment: createAgentsServerRuntimeEnvironment(
|
|
330
|
+
options.childEnvironment,
|
|
331
|
+
runtimeArtifacts.nodeModulesPath,
|
|
332
|
+
{
|
|
333
|
+
isNextValidationIgnored: runtimeArtifacts.isAppPathMaterialized,
|
|
334
|
+
},
|
|
335
|
+
) as AgentsServerChildEnvironment,
|
|
336
|
+
runtimePaths: {
|
|
337
|
+
...options.runtimePaths,
|
|
338
|
+
appPath: runtimeArtifacts.appPath,
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Resolves the hot-reloading Next runtime without running the production build step.
|
|
345
|
+
*/
|
|
346
|
+
async function prepareAgentsServerDevelopmentRuntime(
|
|
347
|
+
appPath: string,
|
|
348
|
+
runnerLogStream: WriteStream,
|
|
349
|
+
): Promise<PreparedAgentsServerRuntime> {
|
|
350
|
+
logRunnerEvent(runnerLogStream, 'Preparing the Agents Server Next development runtime.');
|
|
351
|
+
|
|
352
|
+
return prepareAgentsServerRuntime({
|
|
353
|
+
appPath,
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
|
|
293
357
|
/**
|
|
294
358
|
* Loads launch-directory `.env` values without overriding explicit process environment.
|
|
295
359
|
*
|
|
@@ -318,7 +382,7 @@ async function resolveAgentsServerRuntimePaths(): Promise<AgentsServerRuntimePat
|
|
|
318
382
|
}
|
|
319
383
|
|
|
320
384
|
/**
|
|
321
|
-
* Starts the
|
|
385
|
+
* Starts the configured Next server mode and wires its logs into the foreground dashboard.
|
|
322
386
|
*/
|
|
323
387
|
function startNextServer(options: {
|
|
324
388
|
readonly nextCliPath: string;
|
|
@@ -328,8 +392,13 @@ function startNextServer(options: {
|
|
|
328
392
|
readonly logStreams: AgentsServerLogStreams;
|
|
329
393
|
readonly state: AgentsServerSupervisorState;
|
|
330
394
|
}): ChildProcess {
|
|
331
|
-
|
|
332
|
-
|
|
395
|
+
const nextRuntimeModeLabel = describeAgentsServerNextRuntimeMode(options.options.nextRuntimeMode);
|
|
396
|
+
|
|
397
|
+
logRunnerEvent(
|
|
398
|
+
options.logStreams.runner,
|
|
399
|
+
`Starting the Agents Server Next process in ${nextRuntimeModeLabel} mode.`,
|
|
400
|
+
);
|
|
401
|
+
const nextArguments = [options.nextCliPath, options.options.nextRuntimeMode, '--port', String(options.options.port)];
|
|
333
402
|
const hostname = options.childEnvironment[PTBK_HOSTNAME_ENV]?.trim();
|
|
334
403
|
|
|
335
404
|
if (hostname) {
|
|
@@ -367,6 +436,13 @@ function startNextServer(options: {
|
|
|
367
436
|
return commandProcess;
|
|
368
437
|
}
|
|
369
438
|
|
|
439
|
+
/**
|
|
440
|
+
* Converts one Next runtime mode into a readable label for logs.
|
|
441
|
+
*/
|
|
442
|
+
function describeAgentsServerNextRuntimeMode(nextRuntimeMode: AgentsServerNextRuntimeMode): string {
|
|
443
|
+
return nextRuntimeMode === 'dev' ? 'development' : 'production';
|
|
444
|
+
}
|
|
445
|
+
|
|
370
446
|
/**
|
|
371
447
|
* Connects child stdout/stderr to the persisted Next log and visible terminal output.
|
|
372
448
|
*/
|
|
@@ -5,7 +5,11 @@ import type {
|
|
|
5
5
|
import { spaceTrim } from 'spacetrim';
|
|
6
6
|
import type { $side_effect } from '../../utils/organization/$side_effect';
|
|
7
7
|
import { $initializeAgentsServerInitCommand } from './agents-server/init';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
$initializeAgentsServerBuildCommand,
|
|
10
|
+
$initializeAgentsServerDevCommand,
|
|
11
|
+
$initializeAgentsServerStartCommand,
|
|
12
|
+
} from './agents-server/run';
|
|
9
13
|
|
|
10
14
|
/**
|
|
11
15
|
* Initializes `agents-server` command with subcommands for Promptbook CLI utilities.
|
|
@@ -20,12 +24,14 @@ export function $initializeAgentsServerCommand(program: Program): $side_effect {
|
|
|
20
24
|
|
|
21
25
|
Subcommands:
|
|
22
26
|
- build: Build the web server for later local startup
|
|
27
|
+
- dev: Start the web server in development mode with hot reloading
|
|
23
28
|
- init: Initialize local web server configuration
|
|
24
29
|
- start: Start the web server and local coding-agent message runners
|
|
25
30
|
`),
|
|
26
31
|
);
|
|
27
32
|
|
|
28
33
|
$initializeAgentsServerBuildCommand(agentsServerCommand);
|
|
34
|
+
$initializeAgentsServerDevCommand(agentsServerCommand);
|
|
29
35
|
$initializeAgentsServerInitCommand(agentsServerCommand);
|
|
30
36
|
$initializeAgentsServerStartCommand(agentsServerCommand);
|
|
31
37
|
|