@promptbook/cli 0.114.0-29 → 0.114.0-30
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/about/page.tsx +1 -1
- package/apps/agents-server/src/app/page.tsx +1 -1
- package/apps/agents-server/src/constants/federatedAgentImport.ts +7 -0
- package/apps/agents-server/src/middleware/createMiddlewareRequestContext/loadRegisteredServers.ts +8 -0
- package/apps/agents-server/src/tools/$provideServer.ts +2 -1
- package/apps/agents-server/src/tools/mapRegisteredServerContexts.ts +1 -1
- package/apps/agents-server/src/utils/agentProjects/listAllAgentProjectSummaries.ts +2 -1
- package/apps/agents-server/src/utils/createWellKnownAgentUrl.ts +17 -0
- package/apps/agents-server/src/utils/currentServerRegistryContext.ts +2 -1
- package/apps/agents-server/src/utils/customDomainRouting.ts +143 -10
- package/apps/agents-server/src/utils/getFederatedServers.ts +5 -15
- package/apps/agents-server/src/utils/getWellKnownAgentUrl.ts +2 -3
- package/apps/agents-server/src/utils/parseFederatedServers.ts +14 -0
- package/apps/agents-server/src/utils/serverManagement/getManagedServerById.ts +1 -1
- package/apps/agents-server/src/utils/serverManagement/listManagedServers.ts +1 -1
- package/apps/agents-server/src/utils/serverRegistry.ts +0 -24
- package/apps/agents-server/src/utils/serverRegistryNode.ts +27 -0
- package/esm/apps/agents-server/src/constants/federatedAgentImport.d.ts +6 -0
- package/esm/index.es.js +35 -10
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/run-codex-prompts/runners/openai-codex/buildCodexUsageFromOutput.d.ts +4 -1
- package/esm/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/cli/cli-commands/common/promptRunnerCliOptions.ts +2 -0
- package/src/other/templates/getTemplatesPipelineCollection.ts +750 -853
- package/src/version.ts +2 -2
- package/src/versions.txt +1 -0
- package/umd/apps/agents-server/src/constants/federatedAgentImport.d.ts +6 -0
- package/umd/index.umd.js +35 -10
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/run-codex-prompts/runners/openai-codex/buildCodexUsageFromOutput.d.ts +4 -1
- package/umd/src/version.d.ts +1 -1
- package/esm/apps/agents-server/src/database/sqlite/$provideAgentsServerSqliteDatabase.d.ts +0 -69
- package/esm/apps/agents-server/src/database/sqlite/localSqliteSupabase/ensureTable.d.ts +0 -7
- package/esm/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteSql.d.ts +0 -30
- package/esm/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteTableSchema.d.ts +0 -76
- package/esm/apps/agents-server/src/database/sqlite/resolveAgentsServerSqliteDatabasePath.d.ts +0 -4
- package/esm/apps/agents-server/src/database/sqlite/resolveServerSqliteDatabasePath.d.ts +0 -28
- package/esm/apps/agents-server/src/database/sqlite/standaloneServerRegistryStore.d.ts +0 -110
- package/umd/apps/agents-server/src/database/sqlite/$provideAgentsServerSqliteDatabase.d.ts +0 -69
- package/umd/apps/agents-server/src/database/sqlite/localSqliteSupabase/ensureTable.d.ts +0 -7
- package/umd/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteSql.d.ts +0 -30
- package/umd/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteTableSchema.d.ts +0 -76
- package/umd/apps/agents-server/src/database/sqlite/resolveAgentsServerSqliteDatabasePath.d.ts +0 -4
- package/umd/apps/agents-server/src/database/sqlite/resolveServerSqliteDatabasePath.d.ts +0 -28
- package/umd/apps/agents-server/src/database/sqlite/standaloneServerRegistryStore.d.ts +0 -110
|
@@ -30,7 +30,7 @@ import { Card } from '../../../components/Homepage/Card';
|
|
|
30
30
|
import { Section } from '../../../components/Homepage/Section';
|
|
31
31
|
import { isUserAdmin } from '../../../utils/isUserAdmin';
|
|
32
32
|
import { getSession } from '../../../utils/session';
|
|
33
|
-
import { listRegisteredServersUsingServiceRole } from '../../../utils/
|
|
33
|
+
import { listRegisteredServersUsingServiceRole } from '../../../utils/serverRegistryNode';
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Constant for promptbook about text.
|
|
@@ -11,10 +11,10 @@ import { isUserAdmin } from '../utils/isUserAdmin';
|
|
|
11
11
|
import { isUserGlobalAdmin } from '../utils/isUserGlobalAdmin';
|
|
12
12
|
import {
|
|
13
13
|
createServerPublicUrl,
|
|
14
|
-
listRegisteredServersUsingServiceRole,
|
|
15
14
|
resolveRegisteredServerByHost,
|
|
16
15
|
type ServerRecord,
|
|
17
16
|
} from '../utils/serverRegistry';
|
|
17
|
+
import { listRegisteredServersUsingServiceRole } from '../utils/serverRegistryNode';
|
|
18
18
|
import { isStandaloneVpsRawIpBootstrapActive } from '../utils/standaloneVpsRawIpBootstrap';
|
|
19
19
|
import { getHomePageAgents } from './_data/getHomePageAgents';
|
|
20
20
|
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata key storing the comma-separated federated server URL list.
|
|
3
|
+
*
|
|
4
|
+
* @private shared Agents Server constant
|
|
5
|
+
*/
|
|
6
|
+
export const FEDERATED_SERVERS_METADATA_KEY = 'FEDERATED_SERVERS' as const;
|
|
7
|
+
|
|
1
8
|
/**
|
|
2
9
|
* Metadata key storing the delay between retry attempts when importing federated agent books.
|
|
3
10
|
*
|
package/apps/agents-server/src/middleware/createMiddlewareRequestContext/loadRegisteredServers.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { isAgentsServerSqliteMode } from '../../database/agentsServerDatabaseMode';
|
|
1
2
|
import {
|
|
3
|
+
listEnvironmentRegisteredServers,
|
|
2
4
|
listRegisteredServersUsingServiceRole,
|
|
3
5
|
type ServerRecord,
|
|
4
6
|
} from '../../utils/serverRegistry';
|
|
@@ -12,6 +14,12 @@ import {
|
|
|
12
14
|
*/
|
|
13
15
|
export async function loadRegisteredServers(): Promise<Array<ServerRecord>> {
|
|
14
16
|
try {
|
|
17
|
+
if (isAgentsServerSqliteMode()) {
|
|
18
|
+
// Note: Edge middleware cannot open the standalone SQLite registry. `SERVERS`
|
|
19
|
+
// supplies the domain list required for its host-routing decisions.
|
|
20
|
+
return listEnvironmentRegisteredServers();
|
|
21
|
+
}
|
|
22
|
+
|
|
15
23
|
return await listRegisteredServersUsingServiceRole();
|
|
16
24
|
} catch (error) {
|
|
17
25
|
console.error('Error loading server registry in middleware:', error);
|
|
@@ -3,7 +3,8 @@ import { headers } from 'next/headers';
|
|
|
3
3
|
import { cache } from 'react';
|
|
4
4
|
import { isAgentsServerSqliteMode } from '../database/agentsServerDatabaseMode';
|
|
5
5
|
import { resolveInternalServerOrigin } from '../utils/resolveInternalServerOrigin';
|
|
6
|
-
import { createServerPublicUrl
|
|
6
|
+
import { createServerPublicUrl } from '../utils/serverRegistry';
|
|
7
|
+
import { listRegisteredServersUsingServiceRole } from '../utils/serverRegistryNode';
|
|
7
8
|
import { resolveServerSelection } from '../utils/serverSelection';
|
|
8
9
|
import { getServerContextOverride } from './serverContextOverride';
|
|
9
10
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createServerPublicUrl,
|
|
3
|
-
listRegisteredServersUsingServiceRole,
|
|
4
3
|
normalizeServerDomain,
|
|
5
4
|
resolveRegisteredServerByHost,
|
|
6
5
|
type ServerRecord,
|
|
7
6
|
} from '../utils/serverRegistry';
|
|
7
|
+
import { listRegisteredServersUsingServiceRole } from '../utils/serverRegistryNode';
|
|
8
8
|
import type { ProvidedServer } from './$provideServer';
|
|
9
9
|
import { runWithServerContextOverride } from './serverContextOverride';
|
|
10
10
|
|
|
@@ -5,7 +5,8 @@ import { runWithServerContextOverride } from '@/src/tools/serverContextOverride'
|
|
|
5
5
|
import { DatabaseError } from '../../../../../src/errors/DatabaseError';
|
|
6
6
|
import { spaceTrim } from '../../../../../src/utils/organization/spaceTrim';
|
|
7
7
|
import { createLocalAgentDirectoryName, resolveLocalAgentRootPath } from '../localChatRunner/ensureLocalAgentFolder';
|
|
8
|
-
import { createServerPublicUrl, type ServerRecord
|
|
8
|
+
import { createServerPublicUrl, type ServerRecord } from '../serverRegistry';
|
|
9
|
+
import { listRegisteredServersUsingServiceRole } from '../serverRegistryNode';
|
|
9
10
|
import type { AgentProjectsSummary, AllAgentProjectsReport } from './AgentProjectInfo';
|
|
10
11
|
import { listAgentProjects } from './listAgentProjects';
|
|
11
12
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CORE_AGENTS_SERVER_WELL_KNOWN_AGENT_NAMES } from '../../../../servers';
|
|
2
|
+
import type { string_agent_url } from '../../../../src/_packages/types.index';
|
|
3
|
+
import { createLocalAgentUrl } from './localAgentRouteReferences';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates the local profile URL of one bundled well-known agent.
|
|
7
|
+
*
|
|
8
|
+
* @param localServerUrl - Public origin of the owning Agents Server.
|
|
9
|
+
* @param agentName - Logical well-known agent identifier.
|
|
10
|
+
* @returns Canonical URL for the bundled agent.
|
|
11
|
+
*/
|
|
12
|
+
export function createWellKnownAgentUrl(
|
|
13
|
+
localServerUrl: string,
|
|
14
|
+
agentName: keyof typeof CORE_AGENTS_SERVER_WELL_KNOWN_AGENT_NAMES,
|
|
15
|
+
): string_agent_url {
|
|
16
|
+
return createLocalAgentUrl(localServerUrl, CORE_AGENTS_SERVER_WELL_KNOWN_AGENT_NAMES[agentName]);
|
|
17
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { headers } from 'next/headers';
|
|
2
|
-
import {
|
|
2
|
+
import type { ServerRecord } from './serverRegistry';
|
|
3
|
+
import { listRegisteredServersUsingServiceRole } from './serverRegistryNode';
|
|
3
4
|
import { resolveServerSelection } from './serverSelection';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -12,12 +12,15 @@ import { NotFoundError } from '../../../../src/errors/NotFoundError';
|
|
|
12
12
|
import { ParseError } from '../../../../src/errors/ParseError';
|
|
13
13
|
import { spaceTrim } from '../../../../src/utils/organization/spaceTrim';
|
|
14
14
|
import { normalizeDomainForMatching } from '../../../../src/utils/validators/url/normalizeDomainForMatching';
|
|
15
|
-
import
|
|
15
|
+
import {
|
|
16
|
+
DEFAULT_FEDERATED_AGENT_IMPORT_CONFIGURATION,
|
|
17
|
+
FEDERATED_AGENT_IMPORT_MAX_ATTEMPTS,
|
|
18
|
+
FEDERATED_AGENT_IMPORT_RETRY_DELAY_MS_METADATA_KEY,
|
|
19
|
+
FEDERATED_SERVERS_METADATA_KEY,
|
|
20
|
+
type FederatedAgentImportConfiguration,
|
|
21
|
+
} from '../constants/federatedAgentImport';
|
|
16
22
|
import { isSameAgentPermanentId } from './agentIdentifier';
|
|
17
23
|
import { createServerAgentReferenceResolver } from './agentReferenceResolver/createServerAgentReferenceResolver';
|
|
18
|
-
import { loadFederatedAgentImportConfiguration } from './federatedAgentImportConfiguration';
|
|
19
|
-
import { getFederatedServers } from './getFederatedServers';
|
|
20
|
-
import { getWellKnownAgentUrl } from './getWellKnownAgentUrl';
|
|
21
24
|
import {
|
|
22
25
|
createLocalAgentUrl,
|
|
23
26
|
normalizeLocalAgentUrlReferences,
|
|
@@ -26,6 +29,8 @@ import {
|
|
|
26
29
|
} from './localAgentRouteReferences';
|
|
27
30
|
import { createMissingImportedAgentFallback } from './createMissingImportedAgentFallback';
|
|
28
31
|
import { resolveInheritedAgentSource, type AgentSourceImporter } from './resolveInheritedAgentSource';
|
|
32
|
+
import { createWellKnownAgentUrl } from './createWellKnownAgentUrl';
|
|
33
|
+
import { parseFederatedServers } from './parseFederatedServers';
|
|
29
34
|
import { createServerPublicUrl, type ServerRecord } from './serverRegistry';
|
|
30
35
|
|
|
31
36
|
/**
|
|
@@ -38,6 +43,16 @@ const HTTP_PROTOCOL_PREFIX = 'http://';
|
|
|
38
43
|
*/
|
|
39
44
|
const HTTPS_PROTOCOL_PREFIX = 'https://';
|
|
40
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Metadata values needed to resolve inherited custom-domain agent sources in Edge middleware.
|
|
48
|
+
*
|
|
49
|
+
* @private constant of custom-domain routing
|
|
50
|
+
*/
|
|
51
|
+
const CUSTOM_DOMAIN_FEDERATED_METADATA_KEYS = [
|
|
52
|
+
FEDERATED_SERVERS_METADATA_KEY,
|
|
53
|
+
FEDERATED_AGENT_IMPORT_RETRY_DELAY_MS_METADATA_KEY,
|
|
54
|
+
] as const;
|
|
55
|
+
|
|
41
56
|
/**
|
|
42
57
|
* Candidate values used when searching one custom host in `agentProfile`.
|
|
43
58
|
*/
|
|
@@ -134,6 +149,35 @@ type CustomDomainAgentRow = {
|
|
|
134
149
|
*/
|
|
135
150
|
type ResolvedCustomDomainMetadata = Pick<AgentBasicInformation, 'links' | 'meta'>;
|
|
136
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Metadata row shape needed while resolving a custom-domain agent in Edge middleware.
|
|
154
|
+
*
|
|
155
|
+
* @private type of custom-domain routing
|
|
156
|
+
*/
|
|
157
|
+
type CustomDomainMetadataRow = {
|
|
158
|
+
readonly key: unknown;
|
|
159
|
+
readonly value: unknown;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Dedicated server-limit row shape needed while resolving a custom-domain agent in Edge middleware.
|
|
164
|
+
*
|
|
165
|
+
* @private type of custom-domain routing
|
|
166
|
+
*/
|
|
167
|
+
type CustomDomainServerLimitRow = {
|
|
168
|
+
readonly value: unknown;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Federation dependencies scoped to the server currently considered for a custom-domain match.
|
|
173
|
+
*
|
|
174
|
+
* @private type of custom-domain routing
|
|
175
|
+
*/
|
|
176
|
+
type CustomDomainFederatedDependencies = {
|
|
177
|
+
readonly federatedAgentImportConfiguration: FederatedAgentImportConfiguration;
|
|
178
|
+
readonly federatedServers: ReadonlyArray<string>;
|
|
179
|
+
};
|
|
180
|
+
|
|
137
181
|
/**
|
|
138
182
|
* Creates a minimal local collection used only for compact-reference initialization.
|
|
139
183
|
*
|
|
@@ -426,12 +470,6 @@ export async function resolveCustomDomainAgent(
|
|
|
426
470
|
return null;
|
|
427
471
|
}
|
|
428
472
|
|
|
429
|
-
const [federatedServers, adamAgentUrl, federatedAgentImportConfiguration] = await Promise.all([
|
|
430
|
-
getFederatedServers(),
|
|
431
|
-
getWellKnownAgentUrl('ADAM'),
|
|
432
|
-
loadFederatedAgentImportConfiguration(),
|
|
433
|
-
]);
|
|
434
|
-
|
|
435
473
|
for (const server of servers) {
|
|
436
474
|
try {
|
|
437
475
|
const tableName = `${server.tablePrefix}Agent`;
|
|
@@ -455,6 +493,9 @@ export async function resolveCustomDomainAgent(
|
|
|
455
493
|
}
|
|
456
494
|
|
|
457
495
|
const localServerUrl = createServerPublicUrl(server.domain).href;
|
|
496
|
+
const { federatedServers, federatedAgentImportConfiguration } =
|
|
497
|
+
await loadCustomDomainFederatedDependencies(supabase, server);
|
|
498
|
+
const adamAgentUrl = createWellKnownAgentUrl(localServerUrl, 'ADAM');
|
|
458
499
|
const agentCollection = createResolverAgentCollection(
|
|
459
500
|
resolverReferenceAgents as Array<CustomDomainAgentRow>,
|
|
460
501
|
);
|
|
@@ -502,6 +543,98 @@ export async function resolveCustomDomainAgent(
|
|
|
502
543
|
return null;
|
|
503
544
|
}
|
|
504
545
|
|
|
546
|
+
/**
|
|
547
|
+
* Loads federation settings for the server currently checked for a custom-domain agent.
|
|
548
|
+
*
|
|
549
|
+
* Middleware already owns an Edge-compatible Supabase client. Reading the needed rows through
|
|
550
|
+
* that client keeps custom-domain routing usable in the Edge runtime and avoids request-scoped
|
|
551
|
+
* Node database helpers, which can load the standalone SQLite backend.
|
|
552
|
+
*
|
|
553
|
+
* @param supabase - Edge-compatible Supabase client supplied by middleware.
|
|
554
|
+
* @param server - Candidate server whose inherited agent source is being resolved.
|
|
555
|
+
* @returns Federation dependencies, falling back to safe defaults when configuration is unavailable.
|
|
556
|
+
*
|
|
557
|
+
* @private function of custom-domain routing
|
|
558
|
+
*/
|
|
559
|
+
async function loadCustomDomainFederatedDependencies(
|
|
560
|
+
supabase: SupabaseClient,
|
|
561
|
+
server: ServerRecord,
|
|
562
|
+
): Promise<CustomDomainFederatedDependencies> {
|
|
563
|
+
try {
|
|
564
|
+
const metadataTableName = `${server.tablePrefix}Metadata`;
|
|
565
|
+
const serverLimitTableName = `${server.tablePrefix}ServerLimit`;
|
|
566
|
+
const [metadataResponse, serverLimitResponse] = await Promise.all([
|
|
567
|
+
supabase.from(metadataTableName).select('key, value').in('key', CUSTOM_DOMAIN_FEDERATED_METADATA_KEYS),
|
|
568
|
+
supabase
|
|
569
|
+
.from(serverLimitTableName)
|
|
570
|
+
.select('value')
|
|
571
|
+
.eq('key', FEDERATED_AGENT_IMPORT_RETRY_DELAY_MS_METADATA_KEY)
|
|
572
|
+
.maybeSingle(),
|
|
573
|
+
]);
|
|
574
|
+
const metadataRows = metadataResponse.error
|
|
575
|
+
? []
|
|
576
|
+
: ((Array.isArray(metadataResponse.data) ? metadataResponse.data : []) as Array<CustomDomainMetadataRow>);
|
|
577
|
+
const serverLimitRow = serverLimitResponse.error
|
|
578
|
+
? null
|
|
579
|
+
: (serverLimitResponse.data as CustomDomainServerLimitRow | null);
|
|
580
|
+
const federatedServersValue = readCustomDomainMetadataValue(metadataRows, FEDERATED_SERVERS_METADATA_KEY);
|
|
581
|
+
const legacyRetryDelayValue = readCustomDomainMetadataValue(
|
|
582
|
+
metadataRows,
|
|
583
|
+
FEDERATED_AGENT_IMPORT_RETRY_DELAY_MS_METADATA_KEY,
|
|
584
|
+
);
|
|
585
|
+
|
|
586
|
+
return {
|
|
587
|
+
federatedServers: parseFederatedServers(federatedServersValue),
|
|
588
|
+
federatedAgentImportConfiguration: {
|
|
589
|
+
maxAttempts: FEDERATED_AGENT_IMPORT_MAX_ATTEMPTS,
|
|
590
|
+
retryDelayMs: normalizeFederatedAgentImportRetryDelayMs(
|
|
591
|
+
serverLimitRow?.value ?? legacyRetryDelayValue,
|
|
592
|
+
),
|
|
593
|
+
},
|
|
594
|
+
};
|
|
595
|
+
} catch {
|
|
596
|
+
return {
|
|
597
|
+
federatedServers: [],
|
|
598
|
+
federatedAgentImportConfiguration: DEFAULT_FEDERATED_AGENT_IMPORT_CONFIGURATION,
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Reads one named metadata value from a custom-domain routing query result.
|
|
605
|
+
*
|
|
606
|
+
* @param rows - Raw metadata rows loaded for the candidate server.
|
|
607
|
+
* @param key - Metadata key to read.
|
|
608
|
+
* @returns Stored string value, or `undefined` when unavailable.
|
|
609
|
+
*
|
|
610
|
+
* @private function of custom-domain routing
|
|
611
|
+
*/
|
|
612
|
+
function readCustomDomainMetadataValue(
|
|
613
|
+
rows: ReadonlyArray<CustomDomainMetadataRow>,
|
|
614
|
+
key: string,
|
|
615
|
+
): string | undefined {
|
|
616
|
+
const row = rows.find((candidate) => candidate.key === key);
|
|
617
|
+
return typeof row?.value === 'string' ? row.value : undefined;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Normalizes the one federation retry delay used by Edge custom-domain routing.
|
|
622
|
+
*
|
|
623
|
+
* @param value - Dedicated limit or legacy metadata value.
|
|
624
|
+
* @returns A finite non-negative retry delay, or the shared default.
|
|
625
|
+
*
|
|
626
|
+
* @private function of custom-domain routing
|
|
627
|
+
*/
|
|
628
|
+
function normalizeFederatedAgentImportRetryDelayMs(value: unknown): number {
|
|
629
|
+
const parsedValue = Number(value);
|
|
630
|
+
|
|
631
|
+
if (!Number.isFinite(parsedValue) || parsedValue < 0) {
|
|
632
|
+
return DEFAULT_FEDERATED_AGENT_IMPORT_CONFIGURATION.retryDelayMs;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
return Math.floor(parsedValue);
|
|
636
|
+
}
|
|
637
|
+
|
|
505
638
|
/**
|
|
506
639
|
* Returns unique, non-empty values while keeping original order.
|
|
507
640
|
*
|
|
@@ -1,24 +1,14 @@
|
|
|
1
|
-
import { string_promptbook_server_url } from '@promptbook-local/types';
|
|
1
|
+
import type { string_promptbook_server_url } from '@promptbook-local/types';
|
|
2
|
+
import { FEDERATED_SERVERS_METADATA_KEY } from '../constants/federatedAgentImport';
|
|
2
3
|
import { getMetadataMap } from '../database/getMetadata';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Metadata key storing the comma-separated federated servers list.
|
|
6
|
-
*
|
|
7
|
-
* @private
|
|
8
|
-
*/
|
|
9
|
-
const FEDERATED_SERVERS_METADATA_KEY = 'FEDERATED_SERVERS';
|
|
4
|
+
import { parseFederatedServers } from './parseFederatedServers';
|
|
10
5
|
|
|
11
6
|
/**
|
|
12
7
|
* Reads FEDERATED_SERVERS metadata and returns a normalized list of server URLs.
|
|
13
8
|
*
|
|
14
9
|
* @public exported from `apps/agents-server`
|
|
15
10
|
*/
|
|
16
|
-
export async function getFederatedServers(): Promise<string_promptbook_server_url
|
|
11
|
+
export async function getFederatedServers(): Promise<Array<string_promptbook_server_url>> {
|
|
17
12
|
const metadata = await getMetadataMap([FEDERATED_SERVERS_METADATA_KEY]);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return federatedServersString
|
|
21
|
-
.split(',')
|
|
22
|
-
.map((server) => server.trim())
|
|
23
|
-
.filter((server): server is string_promptbook_server_url => server !== '');
|
|
13
|
+
return parseFederatedServers(metadata[FEDERATED_SERVERS_METADATA_KEY]);
|
|
24
14
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CORE_AGENTS_SERVER_WELL_KNOWN_AGENT_NAMES } from '../../../../servers';
|
|
2
2
|
import { string_agent_url } from '../../../../src/_packages/types.index'; // <- [🚾]
|
|
3
|
+
import { createWellKnownAgentUrl } from './createWellKnownAgentUrl';
|
|
3
4
|
import { resolveCurrentOrInternalServerOrigin } from './resolveCurrentOrInternalServerOrigin';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -14,7 +15,5 @@ export async function getWellKnownAgentUrl(
|
|
|
14
15
|
agentName: keyof typeof CORE_AGENTS_SERVER_WELL_KNOWN_AGENT_NAMES,
|
|
15
16
|
): Promise<string_agent_url> {
|
|
16
17
|
const localServerOrigin = await resolveCurrentOrInternalServerOrigin();
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return `${normalizedServerOrigin}/agents/${CORE_AGENTS_SERVER_WELL_KNOWN_AGENT_NAMES[agentName]}` as string_agent_url;
|
|
18
|
+
return createWellKnownAgentUrl(localServerOrigin, agentName);
|
|
20
19
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { string_promptbook_server_url } from '@promptbook-local/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parses a comma-separated federated-server metadata value.
|
|
5
|
+
*
|
|
6
|
+
* @param value - Raw stored metadata value.
|
|
7
|
+
* @returns Normalized non-empty server URL values.
|
|
8
|
+
*/
|
|
9
|
+
export function parseFederatedServers(value: string | null | undefined): Array<string_promptbook_server_url> {
|
|
10
|
+
return (value || '')
|
|
11
|
+
.split(',')
|
|
12
|
+
.map((serverUrl) => serverUrl.trim())
|
|
13
|
+
.filter((serverUrl): serverUrl is string_promptbook_server_url => serverUrl !== '');
|
|
14
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spaceTrim } from 'spacetrim';
|
|
2
2
|
import { NotFoundError } from '../../../../../src/errors/NotFoundError';
|
|
3
3
|
import type { ServerRecord } from '../serverRegistry';
|
|
4
|
-
import { listRegisteredServersUsingServiceRole } from '../
|
|
4
|
+
import { listRegisteredServersUsingServiceRole } from '../serverRegistryNode';
|
|
5
5
|
import { SERVER_REGISTRY_TABLE_NAME } from './SERVER_REGISTRY_TABLE_NAME';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ServerRecord } from '../serverRegistry';
|
|
2
|
-
import { listRegisteredServersUsingServiceRole } from '../
|
|
2
|
+
import { listRegisteredServersUsingServiceRole } from '../serverRegistryNode';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Loads all registered servers directly from the shared registry cache.
|
|
@@ -140,21 +140,6 @@ export async function listRegisteredServersUsingServiceRole(options?: {
|
|
|
140
140
|
}): Promise<Array<ServerRecord>> {
|
|
141
141
|
const environmentServers = listEnvironmentRegisteredServers();
|
|
142
142
|
|
|
143
|
-
if (isAgentsServerSqliteMode()) {
|
|
144
|
-
if (isEdgeRuntime()) {
|
|
145
|
-
// Note: The Edge middleware cannot open SQLite files. It only needs the domain list
|
|
146
|
-
// for host matching and never queries server tables in SQLite mode, so the
|
|
147
|
-
// environment-derived rows are sufficient there.
|
|
148
|
-
return environmentServers;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Note: In standalone SQLite mode the VPS registry database is the source of truth.
|
|
152
|
-
// Every server row carries its own unique table prefix selecting the isolated
|
|
153
|
-
// per-server database file, so servers cannot leak data into each other.
|
|
154
|
-
const { listStandaloneRegisteredServers } = await import('../database/sqlite/standaloneServerRegistryStore');
|
|
155
|
-
return listStandaloneRegisteredServers();
|
|
156
|
-
}
|
|
157
|
-
|
|
158
143
|
const shouldReuseCache =
|
|
159
144
|
!options?.forceRefresh &&
|
|
160
145
|
cachedServerRegistry !== null &&
|
|
@@ -217,15 +202,6 @@ export function listEnvironmentRegisteredServers(): Array<ServerRecord> {
|
|
|
217
202
|
}));
|
|
218
203
|
}
|
|
219
204
|
|
|
220
|
-
/**
|
|
221
|
-
* Checks whether the current code runs inside the Next.js Edge runtime.
|
|
222
|
-
*
|
|
223
|
-
* @returns `true` when running in the Edge runtime (for example in middleware).
|
|
224
|
-
*/
|
|
225
|
-
function isEdgeRuntime(): boolean {
|
|
226
|
-
return process.env.NEXT_RUNTIME === 'edge';
|
|
227
|
-
}
|
|
228
|
-
|
|
229
205
|
/**
|
|
230
206
|
* Finds one registered server by incoming host header.
|
|
231
207
|
*
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { isAgentsServerSqliteMode } from '../database/agentsServerDatabaseMode';
|
|
2
|
+
import { listStandaloneRegisteredServers } from '../database/sqlite/standaloneServerRegistryStore';
|
|
3
|
+
import {
|
|
4
|
+
listRegisteredServersUsingServiceRole as listSupabaseRegisteredServersUsingServiceRole,
|
|
5
|
+
type ServerRecord,
|
|
6
|
+
} from './serverRegistry';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Loads registered servers for a Node.js request or background task.
|
|
10
|
+
*
|
|
11
|
+
* The standalone SQLite registry is deliberately imported only by this Node.js-only
|
|
12
|
+
* module. Edge middleware must use environment-derived server rows instead, because
|
|
13
|
+
* importing SQLite code makes Next.js compile native database dependencies into its
|
|
14
|
+
* Edge bundle.
|
|
15
|
+
*
|
|
16
|
+
* @param options - Cache controls for the Supabase registry lookup.
|
|
17
|
+
* @returns Registered servers ordered by name.
|
|
18
|
+
*/
|
|
19
|
+
export async function listRegisteredServersUsingServiceRole(options?: {
|
|
20
|
+
readonly forceRefresh?: boolean;
|
|
21
|
+
}): Promise<Array<ServerRecord>> {
|
|
22
|
+
if (isAgentsServerSqliteMode()) {
|
|
23
|
+
return listStandaloneRegisteredServers();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return listSupabaseRegisteredServersUsingServiceRole(options);
|
|
27
|
+
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata key storing the comma-separated federated server URL list.
|
|
3
|
+
*
|
|
4
|
+
* @private shared Agents Server constant
|
|
5
|
+
*/
|
|
6
|
+
export declare const FEDERATED_SERVERS_METADATA_KEY: "FEDERATED_SERVERS";
|
|
1
7
|
/**
|
|
2
8
|
* Metadata key storing the delay between retry attempts when importing federated agent books.
|
|
3
9
|
*
|
package/esm/index.es.js
CHANGED
|
@@ -48,7 +48,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
48
48
|
* @generated
|
|
49
49
|
* @see https://github.com/webgptorg/promptbook
|
|
50
50
|
*/
|
|
51
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.114.0-
|
|
51
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.114.0-30';
|
|
52
52
|
/**
|
|
53
53
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
54
54
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -1843,6 +1843,8 @@ const PROMPT_RUNNER_MODEL_OPTION_DESCRIPTION = spaceTrim$1(`
|
|
|
1843
1843
|
OpenAI examples: gpt-5.2-codex, default
|
|
1844
1844
|
Gemini examples: gemini-3-flash-preview, default
|
|
1845
1845
|
Qwen examples: qwen3.8-max, default
|
|
1846
|
+
|
|
1847
|
+
For openai-codex, "default" overrides no model at all and keeps the one configured in Codex itself, which is what a ChatGPT-account login accepts
|
|
1846
1848
|
`);
|
|
1847
1849
|
/**
|
|
1848
1850
|
* Commander description for the `--git-changes` option.
|
|
@@ -26860,6 +26862,9 @@ function buildCodexScript(options) {
|
|
|
26860
26862
|
fi
|
|
26861
26863
|
`);
|
|
26862
26864
|
const thinkingLevel = (_a = options.thinkingLevel) !== null && _a !== void 0 ? _a : DEFAULT_CODEX_THINKING_LEVEL;
|
|
26865
|
+
// Note: Without an explicit model Codex keeps the model of its own configuration, which is what a
|
|
26866
|
+
// ChatGPT-account login needs — it rejects every model that Codex itself does not offer
|
|
26867
|
+
const modelArgument = options.model ? ` --model ${options.model}` : '';
|
|
26863
26868
|
const lines = [
|
|
26864
26869
|
'if [ -n "${PTBK_AGENTS_SERVER_ENV_FILE:-}" ] && [ -f "${PTBK_AGENTS_SERVER_ENV_FILE}" ]; then',
|
|
26865
26870
|
'set -a',
|
|
@@ -26886,7 +26891,7 @@ function buildCodexScript(options) {
|
|
|
26886
26891
|
' "${CODEX_LOGIN_METHOD_ARGUMENTS[@]}" \\',
|
|
26887
26892
|
` -c model_reasoning_effort="${thinkingLevel}" \\`,
|
|
26888
26893
|
` --ask-for-approval ${options.askForApproval} \\`,
|
|
26889
|
-
` exec
|
|
26894
|
+
` exec${modelArgument} \\`,
|
|
26890
26895
|
...(options.isMachineReadableProgressEnabled ? [' --json \\'] : []),
|
|
26891
26896
|
' --local-provider none \\',
|
|
26892
26897
|
` --sandbox ${options.sandbox} \\`,
|
|
@@ -26934,6 +26939,9 @@ const CODEX_FALLBACK_PRICING_MODEL = 'gpt-5.1';
|
|
|
26934
26939
|
const DEFAULT_CODEX_COMPLETION_SHARE = 0.1;
|
|
26935
26940
|
/**
|
|
26936
26941
|
* Builds usage stats from Codex CLI output.
|
|
26942
|
+
*
|
|
26943
|
+
* The `modelName` is omitted when Codex ran without a model override, in which case only Codex knows which
|
|
26944
|
+
* model it picked and the price can be estimated from the fallback pricing alone.
|
|
26937
26945
|
*/
|
|
26938
26946
|
function buildCodexUsageFromOutput(output, modelName) {
|
|
26939
26947
|
const breakdown = parseCodexTokenBreakdown(output);
|
|
@@ -27070,18 +27078,25 @@ function parseCodexTokenCount(value) {
|
|
|
27070
27078
|
}
|
|
27071
27079
|
/**
|
|
27072
27080
|
* Resolves a pricing model to estimate Codex cost from total tokens.
|
|
27081
|
+
*
|
|
27082
|
+
* An unknown model — and a run without any model override, where Codex picked the model itself — is priced
|
|
27083
|
+
* with `CODEX_FALLBACK_PRICING_MODEL`, so the estimate stays in the right order of magnitude.
|
|
27073
27084
|
*/
|
|
27074
27085
|
function resolveCodexPricing(modelName) {
|
|
27075
27086
|
var _a, _b, _c;
|
|
27076
|
-
const
|
|
27087
|
+
const fallbackPricing = (_a = OPENAI_MODELS.find((model) => model.modelName === CODEX_FALLBACK_PRICING_MODEL)) === null || _a === void 0 ? void 0 : _a.pricing;
|
|
27088
|
+
if (modelName === undefined) {
|
|
27089
|
+
return fallbackPricing;
|
|
27090
|
+
}
|
|
27091
|
+
const exactMatch = (_b = OPENAI_MODELS.find((model) => model.modelName === modelName)) === null || _b === void 0 ? void 0 : _b.pricing;
|
|
27077
27092
|
if (exactMatch) {
|
|
27078
27093
|
return exactMatch;
|
|
27079
27094
|
}
|
|
27080
|
-
const prefixMatch = (
|
|
27095
|
+
const prefixMatch = (_c = OPENAI_MODELS.find((model) => modelName.startsWith(model.modelName))) === null || _c === void 0 ? void 0 : _c.pricing;
|
|
27081
27096
|
if (prefixMatch) {
|
|
27082
27097
|
return prefixMatch;
|
|
27083
27098
|
}
|
|
27084
|
-
return
|
|
27099
|
+
return fallbackPricing;
|
|
27085
27100
|
}
|
|
27086
27101
|
|
|
27087
27102
|
/**
|
|
@@ -27890,9 +27905,9 @@ class QwenCodeRunner {
|
|
|
27890
27905
|
}
|
|
27891
27906
|
|
|
27892
27907
|
/**
|
|
27893
|
-
*
|
|
27908
|
+
* Value of `--model` which asks for the default model of the selected harness instead of naming one.
|
|
27894
27909
|
*/
|
|
27895
|
-
const
|
|
27910
|
+
const DEFAULT_MODEL_NAME = 'default';
|
|
27896
27911
|
/**
|
|
27897
27912
|
* Constant for cline model.
|
|
27898
27913
|
*/
|
|
@@ -27919,7 +27934,7 @@ function resolvePromptRunner(options) {
|
|
|
27919
27934
|
return createRunnerResolution(options, new ClineRunner({ model: CLINE_MODEL }));
|
|
27920
27935
|
}
|
|
27921
27936
|
if (agentName === 'github-copilot') {
|
|
27922
|
-
const actualRunnerModel = options.model ===
|
|
27937
|
+
const actualRunnerModel = options.model === DEFAULT_MODEL_NAME ? undefined : options.model;
|
|
27923
27938
|
return createRunnerResolution(options, new GitHubCopilotRunner({
|
|
27924
27939
|
model: actualRunnerModel,
|
|
27925
27940
|
thinkingLevel: options.thinkingLevel,
|
|
@@ -27951,7 +27966,9 @@ function createOpenAiCodexRunnerResolution(options) {
|
|
|
27951
27966
|
const actualRunnerModel = resolveRequiredModel({
|
|
27952
27967
|
agentName: 'openai-codex',
|
|
27953
27968
|
providedModel: options.model,
|
|
27954
|
-
|
|
27969
|
+
// Note: Codex must not be pinned to any model of ours, because a ChatGPT-account login only accepts the
|
|
27970
|
+
// models which Codex itself offers — `default` therefore keeps the model from `~/.codex/config.toml`
|
|
27971
|
+
defaultModel: undefined,
|
|
27955
27972
|
availableModels: OPENAI_MODELS.filter((model) => model.modelVariant === 'CHAT').map((model) => model.modelName),
|
|
27956
27973
|
exampleUsages: ['--harness openai-codex --model gpt-5.2-codex', '--harness openai-codex --model default'],
|
|
27957
27974
|
});
|
|
@@ -28034,12 +28051,15 @@ function isModelRequiringHarnessName(agentName) {
|
|
|
28034
28051
|
}
|
|
28035
28052
|
/**
|
|
28036
28053
|
* Resolves a runner model, allowing `default` but otherwise requiring an explicit value.
|
|
28054
|
+
*
|
|
28055
|
+
* The `defaultModel` of a harness is either the model name which `--model default` stands for, or `undefined`
|
|
28056
|
+
* when the harness must be started **without any model override** and keep the model of its own configuration.
|
|
28037
28057
|
*/
|
|
28038
28058
|
function resolveRequiredModel(options) {
|
|
28039
28059
|
if (!options.providedModel) {
|
|
28040
28060
|
exitForMissingModel(options.agentName, options.availableModels, options.exampleUsages);
|
|
28041
28061
|
}
|
|
28042
|
-
if (options.providedModel ===
|
|
28062
|
+
if (options.providedModel === DEFAULT_MODEL_NAME) {
|
|
28043
28063
|
return options.defaultModel;
|
|
28044
28064
|
}
|
|
28045
28065
|
return options.providedModel;
|
|
@@ -41408,6 +41428,11 @@ function stopChildProcess(commandProcess) {
|
|
|
41408
41428
|
commandProcess.kill();
|
|
41409
41429
|
}
|
|
41410
41430
|
|
|
41431
|
+
/**
|
|
41432
|
+
* Metadata key storing the comma-separated federated server URL list.
|
|
41433
|
+
*
|
|
41434
|
+
* @private shared Agents Server constant
|
|
41435
|
+
*/
|
|
41411
41436
|
/**
|
|
41412
41437
|
* Metadata key storing the delay between retry attempts when importing federated agent books.
|
|
41413
41438
|
*
|