@promptbook/core 0.112.0-56 → 0.112.0-58
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/esm/index.es.js +1069 -1084
- package/esm/index.es.js.map +1 -1
- package/esm/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments/ParsedAgentSourceWithCommitments.d.ts +7 -0
- package/esm/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments/applyCommitmentsToAgentModelRequirements.d.ts +14 -0
- package/esm/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments/augmentAgentModelRequirementsFromSource.d.ts +14 -0
- package/esm/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments/filterCommitmentsForAgentModelRequirements.d.ts +10 -0
- package/esm/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments/materializeInlineKnowledgeSources.d.ts +12 -0
- package/esm/src/book-2.0/agent-source/parseAgentSource/ParseAgentSourceState.d.ts +10 -0
- package/esm/src/book-2.0/agent-source/parseAgentSource/ParsedAgentProfile.d.ts +7 -0
- package/esm/src/book-2.0/agent-source/parseAgentSource/applyMetaCommitment.d.ts +8 -0
- package/esm/src/book-2.0/agent-source/parseAgentSource/consumeConversationSampleCommitment.d.ts +8 -0
- package/esm/src/book-2.0/agent-source/parseAgentSource/createCapabilitiesFromCommitment.d.ts +9 -0
- package/esm/src/book-2.0/agent-source/parseAgentSource/ensureMetaFullname.d.ts +7 -0
- package/esm/src/book-2.0/agent-source/parseAgentSource/extractAgentProfileText.d.ts +8 -0
- package/esm/src/book-2.0/agent-source/parseAgentSource/extractInitialMessage.d.ts +7 -0
- package/esm/src/book-2.0/agent-source/parseAgentSource/extractParsedAgentProfile.d.ts +8 -0
- package/esm/src/types/LlmToolDefinition.d.ts +17 -7
- package/esm/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +1069 -1084
- package/umd/index.umd.js.map +1 -1
- package/umd/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments/ParsedAgentSourceWithCommitments.d.ts +7 -0
- package/umd/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments/applyCommitmentsToAgentModelRequirements.d.ts +14 -0
- package/umd/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments/augmentAgentModelRequirementsFromSource.d.ts +14 -0
- package/umd/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments/filterCommitmentsForAgentModelRequirements.d.ts +10 -0
- package/umd/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments/materializeInlineKnowledgeSources.d.ts +12 -0
- package/umd/src/book-2.0/agent-source/parseAgentSource/ParseAgentSourceState.d.ts +10 -0
- package/umd/src/book-2.0/agent-source/parseAgentSource/ParsedAgentProfile.d.ts +7 -0
- package/umd/src/book-2.0/agent-source/parseAgentSource/applyMetaCommitment.d.ts +8 -0
- package/umd/src/book-2.0/agent-source/parseAgentSource/consumeConversationSampleCommitment.d.ts +8 -0
- package/umd/src/book-2.0/agent-source/parseAgentSource/createCapabilitiesFromCommitment.d.ts +9 -0
- package/umd/src/book-2.0/agent-source/parseAgentSource/ensureMetaFullname.d.ts +7 -0
- package/umd/src/book-2.0/agent-source/parseAgentSource/extractAgentProfileText.d.ts +8 -0
- package/umd/src/book-2.0/agent-source/parseAgentSource/extractInitialMessage.d.ts +7 -0
- package/umd/src/book-2.0/agent-source/parseAgentSource/extractParsedAgentProfile.d.ts +8 -0
- package/umd/src/types/LlmToolDefinition.d.ts +17 -7
- package/umd/src/version.d.ts +1 -1
package/esm/index.es.js
CHANGED
|
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
28
28
|
* @generated
|
|
29
29
|
* @see https://github.com/webgptorg/promptbook
|
|
30
30
|
*/
|
|
31
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
31
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-58';
|
|
32
32
|
/**
|
|
33
33
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
34
34
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -7891,6 +7891,186 @@ function createBasicAgentModelRequirements(agentName) {
|
|
|
7891
7891
|
}
|
|
7892
7892
|
// TODO: [🐤] Deduplicate `AgentModelRequirements` and `ModelRequirements` model requirements
|
|
7893
7893
|
|
|
7894
|
+
/**
|
|
7895
|
+
* @@@
|
|
7896
|
+
*
|
|
7897
|
+
* @private utility for commitments
|
|
7898
|
+
*/
|
|
7899
|
+
function formatOptionalInstructionBlock(label, content) {
|
|
7900
|
+
const trimmedContent = spaceTrim$1(content);
|
|
7901
|
+
if (!trimmedContent) {
|
|
7902
|
+
return '';
|
|
7903
|
+
}
|
|
7904
|
+
return spaceTrim$1((block) => `
|
|
7905
|
+
- ${label}:
|
|
7906
|
+
${block(trimmedContent
|
|
7907
|
+
.split(/\r?\n/)
|
|
7908
|
+
.map((line) => `- ${line}`)
|
|
7909
|
+
.join('\n'))}
|
|
7910
|
+
`);
|
|
7911
|
+
}
|
|
7912
|
+
|
|
7913
|
+
/**
|
|
7914
|
+
* All `USE` commitment types currently participating in final system-message aggregation.
|
|
7915
|
+
*
|
|
7916
|
+
* @private internal constant for `aggregateUseCommitmentSystemMessages`
|
|
7917
|
+
*/
|
|
7918
|
+
const AGGREGATED_USE_COMMITMENT_TYPES = [
|
|
7919
|
+
'USE BROWSER',
|
|
7920
|
+
'USE DEEPSEARCH',
|
|
7921
|
+
'USE SEARCH ENGINE',
|
|
7922
|
+
'USE TIME',
|
|
7923
|
+
];
|
|
7924
|
+
/**
|
|
7925
|
+
* Prefix used for temporary in-system-message placeholders that preserve the first-occurrence position of aggregated `USE` sections.
|
|
7926
|
+
*
|
|
7927
|
+
* @private internal constant for `appendAggregatedUseCommitmentPlaceholder`
|
|
7928
|
+
*/
|
|
7929
|
+
const AGGREGATED_USE_COMMITMENT_PLACEHOLDER_PREFIX = '# AGGREGATED USE COMMITMENT: ';
|
|
7930
|
+
/**
|
|
7931
|
+
* Type guard for `USE` commitment types that are aggregated in the final system message.
|
|
7932
|
+
*
|
|
7933
|
+
* @param type - Commitment type to check.
|
|
7934
|
+
* @returns `true` when the commitment participates in `USE` system-message aggregation.
|
|
7935
|
+
*
|
|
7936
|
+
* @private internal utility of `aggregateUseCommitmentSystemMessages`
|
|
7937
|
+
*/
|
|
7938
|
+
function isAggregatedUseCommitmentType(type) {
|
|
7939
|
+
return AGGREGATED_USE_COMMITMENT_TYPES.includes(type);
|
|
7940
|
+
}
|
|
7941
|
+
/**
|
|
7942
|
+
* Creates the placeholder token used to reserve the first-occurrence position of an aggregated `USE` system-message section.
|
|
7943
|
+
*
|
|
7944
|
+
* @param type - Aggregated `USE` commitment type.
|
|
7945
|
+
* @returns Single-line placeholder comment stored in the interim system message.
|
|
7946
|
+
*
|
|
7947
|
+
* @private internal utility of `appendAggregatedUseCommitmentPlaceholder`
|
|
7948
|
+
*/
|
|
7949
|
+
function getAggregatedUseCommitmentPlaceholder(type) {
|
|
7950
|
+
return `${AGGREGATED_USE_COMMITMENT_PLACEHOLDER_PREFIX}${type}`;
|
|
7951
|
+
}
|
|
7952
|
+
/**
|
|
7953
|
+
* Combines distinct additional instruction blocks in source order.
|
|
7954
|
+
*
|
|
7955
|
+
* @param additionalInstructions - Deduplicated instruction blocks collected from the agent source.
|
|
7956
|
+
* @returns Combined instruction text ready for `formatOptionalInstructionBlock`.
|
|
7957
|
+
*
|
|
7958
|
+
* @private internal utility of `createAggregatedUseCommitmentSystemMessage`
|
|
7959
|
+
*/
|
|
7960
|
+
function combineAdditionalInstructions(additionalInstructions) {
|
|
7961
|
+
return additionalInstructions.join('\n');
|
|
7962
|
+
}
|
|
7963
|
+
/**
|
|
7964
|
+
* Creates the final aggregated system-message section for a supported `USE` commitment type.
|
|
7965
|
+
*
|
|
7966
|
+
* @param type - Aggregated `USE` commitment type.
|
|
7967
|
+
* @param additionalInstructions - Distinct additional instructions in source order.
|
|
7968
|
+
* @returns Final system-message block for the commitment type.
|
|
7969
|
+
*
|
|
7970
|
+
* @private internal utility of `aggregateUseCommitmentSystemMessages`
|
|
7971
|
+
*/
|
|
7972
|
+
function createAggregatedUseCommitmentSystemMessage(type, additionalInstructions) {
|
|
7973
|
+
const combinedAdditionalInstructions = combineAdditionalInstructions(additionalInstructions);
|
|
7974
|
+
switch (type) {
|
|
7975
|
+
case 'USE TIME':
|
|
7976
|
+
return spaceTrim$1((block) => `
|
|
7977
|
+
Time and date context:
|
|
7978
|
+
- It is ${moment().format('MMMM YYYY')} now.
|
|
7979
|
+
- If you need more precise current time information, use the tool "get_current_time".
|
|
7980
|
+
${block(formatOptionalInstructionBlock('Time instructions', combinedAdditionalInstructions))}
|
|
7981
|
+
`);
|
|
7982
|
+
case 'USE BROWSER':
|
|
7983
|
+
return spaceTrim$1((block) => `
|
|
7984
|
+
You have access to browser tools to fetch and access content from the internet.
|
|
7985
|
+
- Use "fetch_url_content" to retrieve content from specific URLs (webpages or documents) using scrapers.
|
|
7986
|
+
- Use "run_browser" for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
|
|
7987
|
+
When you need to know information from a specific website or document, use the fetch_url_content tool.
|
|
7988
|
+
${block(formatOptionalInstructionBlock('Browser instructions', combinedAdditionalInstructions))}
|
|
7989
|
+
`);
|
|
7990
|
+
case 'USE SEARCH ENGINE':
|
|
7991
|
+
return spaceTrim$1((block) => `
|
|
7992
|
+
Tool:
|
|
7993
|
+
- You have access to the web search engine via the tool "web_search".
|
|
7994
|
+
- Use it to find up-to-date information or facts that you don't know.
|
|
7995
|
+
- When you need to know some information from the internet, use the tool provided to you.
|
|
7996
|
+
- Do not make up information when you can search for it.
|
|
7997
|
+
- Do not tell the user you cannot search for information, YOU CAN.
|
|
7998
|
+
${block(formatOptionalInstructionBlock('Search instructions', combinedAdditionalInstructions))}
|
|
7999
|
+
`);
|
|
8000
|
+
case 'USE DEEPSEARCH':
|
|
8001
|
+
return spaceTrim$1((block) => `
|
|
8002
|
+
Tool:
|
|
8003
|
+
- You have access to DeepSearch via the tool "deep_search".
|
|
8004
|
+
- Use it for broader research tasks that need multi-step investigation, comparison, or synthesis across multiple sources.
|
|
8005
|
+
- Prefer it over quick search when the user asks for a well-grounded brief, report, or deeper investigation.
|
|
8006
|
+
- Do not pretend you cannot research current information when this tool is available.
|
|
8007
|
+
${block(formatOptionalInstructionBlock('DeepSearch instructions', combinedAdditionalInstructions))}
|
|
8008
|
+
`);
|
|
8009
|
+
}
|
|
8010
|
+
}
|
|
8011
|
+
/**
|
|
8012
|
+
* Adds the placeholder for an aggregated `USE` system-message section only once, preserving the section position from the first occurrence.
|
|
8013
|
+
*
|
|
8014
|
+
* @param requirements - Current model requirements.
|
|
8015
|
+
* @param type - Aggregated `USE` commitment type being applied.
|
|
8016
|
+
* @returns Requirements with the placeholder inserted when it was not already present.
|
|
8017
|
+
*
|
|
8018
|
+
* @private internal utility of `USE` commitments
|
|
8019
|
+
*/
|
|
8020
|
+
function appendAggregatedUseCommitmentPlaceholder(requirements, type) {
|
|
8021
|
+
const placeholder = getAggregatedUseCommitmentPlaceholder(type);
|
|
8022
|
+
if (requirements.systemMessage.includes(placeholder)) {
|
|
8023
|
+
return requirements;
|
|
8024
|
+
}
|
|
8025
|
+
const systemMessage = requirements.systemMessage.trim()
|
|
8026
|
+
? `${requirements.systemMessage}\n\n${placeholder}`
|
|
8027
|
+
: placeholder;
|
|
8028
|
+
return {
|
|
8029
|
+
...requirements,
|
|
8030
|
+
systemMessage,
|
|
8031
|
+
};
|
|
8032
|
+
}
|
|
8033
|
+
/**
|
|
8034
|
+
* Replaces temporary `USE` placeholders with one aggregated system-message block per commitment type.
|
|
8035
|
+
*
|
|
8036
|
+
* Distinct additional-instruction blocks are merged in stable source order while the hard-coded section is emitted only once.
|
|
8037
|
+
*
|
|
8038
|
+
* @param requirements - Model requirements produced by commitment-by-commitment application.
|
|
8039
|
+
* @param commitments - Filtered commitments in their original source order.
|
|
8040
|
+
* @returns Requirements with aggregated `USE` system-message sections.
|
|
8041
|
+
*
|
|
8042
|
+
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
8043
|
+
*/
|
|
8044
|
+
function aggregateUseCommitmentSystemMessages(requirements, commitments) {
|
|
8045
|
+
const additionalInstructionsByType = new Map();
|
|
8046
|
+
for (const commitment of commitments) {
|
|
8047
|
+
if (!isAggregatedUseCommitmentType(commitment.type)) {
|
|
8048
|
+
continue;
|
|
8049
|
+
}
|
|
8050
|
+
let additionalInstructions = additionalInstructionsByType.get(commitment.type);
|
|
8051
|
+
if (!additionalInstructions) {
|
|
8052
|
+
additionalInstructions = [];
|
|
8053
|
+
additionalInstructionsByType.set(commitment.type, additionalInstructions);
|
|
8054
|
+
}
|
|
8055
|
+
const normalizedContent = spaceTrim$1(commitment.content);
|
|
8056
|
+
if (normalizedContent && !additionalInstructions.includes(normalizedContent)) {
|
|
8057
|
+
additionalInstructions.push(normalizedContent);
|
|
8058
|
+
}
|
|
8059
|
+
}
|
|
8060
|
+
let systemMessage = requirements.systemMessage;
|
|
8061
|
+
for (const [type, additionalInstructions] of additionalInstructionsByType) {
|
|
8062
|
+
const placeholder = getAggregatedUseCommitmentPlaceholder(type);
|
|
8063
|
+
if (!systemMessage.includes(placeholder)) {
|
|
8064
|
+
continue;
|
|
8065
|
+
}
|
|
8066
|
+
systemMessage = systemMessage.replace(placeholder, createAggregatedUseCommitmentSystemMessage(type, additionalInstructions));
|
|
8067
|
+
}
|
|
8068
|
+
return {
|
|
8069
|
+
...requirements,
|
|
8070
|
+
systemMessage,
|
|
8071
|
+
};
|
|
8072
|
+
}
|
|
8073
|
+
|
|
7894
8074
|
/**
|
|
7895
8075
|
* Generates a regex pattern to match a specific commitment
|
|
7896
8076
|
*
|
|
@@ -12077,25 +12257,6 @@ class LanguageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
12077
12257
|
}
|
|
12078
12258
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
12079
12259
|
|
|
12080
|
-
/**
|
|
12081
|
-
* @@@
|
|
12082
|
-
*
|
|
12083
|
-
* @private utility for commitments
|
|
12084
|
-
*/
|
|
12085
|
-
function formatOptionalInstructionBlock(label, content) {
|
|
12086
|
-
const trimmedContent = spaceTrim$1(content);
|
|
12087
|
-
if (!trimmedContent) {
|
|
12088
|
-
return '';
|
|
12089
|
-
}
|
|
12090
|
-
return spaceTrim$1((block) => `
|
|
12091
|
-
- ${label}:
|
|
12092
|
-
${block(trimmedContent
|
|
12093
|
-
.split(/\r?\n/)
|
|
12094
|
-
.map((line) => `- ${line}`)
|
|
12095
|
-
.join('\n'))}
|
|
12096
|
-
`);
|
|
12097
|
-
}
|
|
12098
|
-
|
|
12099
12260
|
/**
|
|
12100
12261
|
* Names of tools used by the MEMORY commitment.
|
|
12101
12262
|
*
|
|
@@ -19023,206 +19184,45 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19023
19184
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
19024
19185
|
|
|
19025
19186
|
/**
|
|
19026
|
-
*
|
|
19027
|
-
*
|
|
19028
|
-
* @private internal constant for `aggregateUseCommitmentSystemMessages`
|
|
19029
|
-
*/
|
|
19030
|
-
const AGGREGATED_USE_COMMITMENT_TYPES = [
|
|
19031
|
-
'USE BROWSER',
|
|
19032
|
-
'USE DEEPSEARCH',
|
|
19033
|
-
'USE SEARCH ENGINE',
|
|
19034
|
-
'USE TIME',
|
|
19035
|
-
];
|
|
19036
|
-
/**
|
|
19037
|
-
* Prefix used for temporary in-system-message placeholders that preserve the first-occurrence position of aggregated `USE` sections.
|
|
19187
|
+
* Client-side safe wrapper for fetching URL content
|
|
19038
19188
|
*
|
|
19039
|
-
*
|
|
19040
|
-
|
|
19041
|
-
const AGGREGATED_USE_COMMITMENT_PLACEHOLDER_PREFIX = '# AGGREGATED USE COMMITMENT: ';
|
|
19042
|
-
/**
|
|
19043
|
-
* Type guard for `USE` commitment types that are aggregated in the final system message.
|
|
19189
|
+
* This function proxies requests to the Agents Server API endpoint for scraping,
|
|
19190
|
+
* making it safe to use in browser environments.
|
|
19044
19191
|
*
|
|
19045
|
-
* @param
|
|
19046
|
-
* @
|
|
19192
|
+
* @param url The URL to fetch and scrape
|
|
19193
|
+
* @param agentsServerUrl The base URL of the agents server (defaults to current origin)
|
|
19194
|
+
* @returns Markdown content from the URL
|
|
19047
19195
|
*
|
|
19048
|
-
* @private internal utility
|
|
19196
|
+
* @private internal utility for USE BROWSER commitment
|
|
19049
19197
|
*/
|
|
19050
|
-
function
|
|
19051
|
-
|
|
19198
|
+
async function fetchUrlContentViaBrowser(url, agentsServerUrl) {
|
|
19199
|
+
try {
|
|
19200
|
+
// Determine the agents server URL
|
|
19201
|
+
const baseUrl = agentsServerUrl || (typeof window !== 'undefined' ? window.location.origin : '');
|
|
19202
|
+
if (!baseUrl) {
|
|
19203
|
+
throw new Error('Agents server URL is required in non-browser environments');
|
|
19204
|
+
}
|
|
19205
|
+
// Build the API endpoint URL
|
|
19206
|
+
const apiUrl = new URL('/api/scrape', baseUrl);
|
|
19207
|
+
apiUrl.searchParams.set('url', url);
|
|
19208
|
+
// Fetch from the API endpoint
|
|
19209
|
+
const response = await fetch(apiUrl.toString());
|
|
19210
|
+
if (!response.ok) {
|
|
19211
|
+
const errorData = await response.json().catch(() => ({ error: 'Unknown error' }));
|
|
19212
|
+
throw new Error(`Failed to scrape URL: ${errorData.error || response.statusText}`);
|
|
19213
|
+
}
|
|
19214
|
+
const data = await response.json();
|
|
19215
|
+
if (!data.success || !data.content) {
|
|
19216
|
+
throw new Error(`Scraping failed: ${data.error || 'No content returned'}`);
|
|
19217
|
+
}
|
|
19218
|
+
return data.content;
|
|
19219
|
+
}
|
|
19220
|
+
catch (error) {
|
|
19221
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
19222
|
+
throw new Error(`Error fetching URL content via browser: ${errorMessage}`);
|
|
19223
|
+
}
|
|
19052
19224
|
}
|
|
19053
|
-
|
|
19054
|
-
* Creates the placeholder token used to reserve the first-occurrence position of an aggregated `USE` system-message section.
|
|
19055
|
-
*
|
|
19056
|
-
* @param type - Aggregated `USE` commitment type.
|
|
19057
|
-
* @returns Single-line placeholder comment stored in the interim system message.
|
|
19058
|
-
*
|
|
19059
|
-
* @private internal utility of `appendAggregatedUseCommitmentPlaceholder`
|
|
19060
|
-
*/
|
|
19061
|
-
function getAggregatedUseCommitmentPlaceholder(type) {
|
|
19062
|
-
return `${AGGREGATED_USE_COMMITMENT_PLACEHOLDER_PREFIX}${type}`;
|
|
19063
|
-
}
|
|
19064
|
-
/**
|
|
19065
|
-
* Combines distinct additional instruction blocks in source order.
|
|
19066
|
-
*
|
|
19067
|
-
* @param additionalInstructions - Deduplicated instruction blocks collected from the agent source.
|
|
19068
|
-
* @returns Combined instruction text ready for `formatOptionalInstructionBlock`.
|
|
19069
|
-
*
|
|
19070
|
-
* @private internal utility of `createAggregatedUseCommitmentSystemMessage`
|
|
19071
|
-
*/
|
|
19072
|
-
function combineAdditionalInstructions(additionalInstructions) {
|
|
19073
|
-
return additionalInstructions.join('\n');
|
|
19074
|
-
}
|
|
19075
|
-
/**
|
|
19076
|
-
* Creates the final aggregated system-message section for a supported `USE` commitment type.
|
|
19077
|
-
*
|
|
19078
|
-
* @param type - Aggregated `USE` commitment type.
|
|
19079
|
-
* @param additionalInstructions - Distinct additional instructions in source order.
|
|
19080
|
-
* @returns Final system-message block for the commitment type.
|
|
19081
|
-
*
|
|
19082
|
-
* @private internal utility of `aggregateUseCommitmentSystemMessages`
|
|
19083
|
-
*/
|
|
19084
|
-
function createAggregatedUseCommitmentSystemMessage(type, additionalInstructions) {
|
|
19085
|
-
const combinedAdditionalInstructions = combineAdditionalInstructions(additionalInstructions);
|
|
19086
|
-
switch (type) {
|
|
19087
|
-
case 'USE TIME':
|
|
19088
|
-
return spaceTrim$1((block) => `
|
|
19089
|
-
Time and date context:
|
|
19090
|
-
- It is ${moment().format('MMMM YYYY')} now.
|
|
19091
|
-
- If you need more precise current time information, use the tool "get_current_time".
|
|
19092
|
-
${block(formatOptionalInstructionBlock('Time instructions', combinedAdditionalInstructions))}
|
|
19093
|
-
`);
|
|
19094
|
-
case 'USE BROWSER':
|
|
19095
|
-
return spaceTrim$1((block) => `
|
|
19096
|
-
You have access to browser tools to fetch and access content from the internet.
|
|
19097
|
-
- Use "fetch_url_content" to retrieve content from specific URLs (webpages or documents) using scrapers.
|
|
19098
|
-
- Use "run_browser" for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
|
|
19099
|
-
When you need to know information from a specific website or document, use the fetch_url_content tool.
|
|
19100
|
-
${block(formatOptionalInstructionBlock('Browser instructions', combinedAdditionalInstructions))}
|
|
19101
|
-
`);
|
|
19102
|
-
case 'USE SEARCH ENGINE':
|
|
19103
|
-
return spaceTrim$1((block) => `
|
|
19104
|
-
Tool:
|
|
19105
|
-
- You have access to the web search engine via the tool "web_search".
|
|
19106
|
-
- Use it to find up-to-date information or facts that you don't know.
|
|
19107
|
-
- When you need to know some information from the internet, use the tool provided to you.
|
|
19108
|
-
- Do not make up information when you can search for it.
|
|
19109
|
-
- Do not tell the user you cannot search for information, YOU CAN.
|
|
19110
|
-
${block(formatOptionalInstructionBlock('Search instructions', combinedAdditionalInstructions))}
|
|
19111
|
-
`);
|
|
19112
|
-
case 'USE DEEPSEARCH':
|
|
19113
|
-
return spaceTrim$1((block) => `
|
|
19114
|
-
Tool:
|
|
19115
|
-
- You have access to DeepSearch via the tool "deep_search".
|
|
19116
|
-
- Use it for broader research tasks that need multi-step investigation, comparison, or synthesis across multiple sources.
|
|
19117
|
-
- Prefer it over quick search when the user asks for a well-grounded brief, report, or deeper investigation.
|
|
19118
|
-
- Do not pretend you cannot research current information when this tool is available.
|
|
19119
|
-
${block(formatOptionalInstructionBlock('DeepSearch instructions', combinedAdditionalInstructions))}
|
|
19120
|
-
`);
|
|
19121
|
-
}
|
|
19122
|
-
}
|
|
19123
|
-
/**
|
|
19124
|
-
* Adds the placeholder for an aggregated `USE` system-message section only once, preserving the section position from the first occurrence.
|
|
19125
|
-
*
|
|
19126
|
-
* @param requirements - Current model requirements.
|
|
19127
|
-
* @param type - Aggregated `USE` commitment type being applied.
|
|
19128
|
-
* @returns Requirements with the placeholder inserted when it was not already present.
|
|
19129
|
-
*
|
|
19130
|
-
* @private internal utility of `USE` commitments
|
|
19131
|
-
*/
|
|
19132
|
-
function appendAggregatedUseCommitmentPlaceholder(requirements, type) {
|
|
19133
|
-
const placeholder = getAggregatedUseCommitmentPlaceholder(type);
|
|
19134
|
-
if (requirements.systemMessage.includes(placeholder)) {
|
|
19135
|
-
return requirements;
|
|
19136
|
-
}
|
|
19137
|
-
const systemMessage = requirements.systemMessage.trim()
|
|
19138
|
-
? `${requirements.systemMessage}\n\n${placeholder}`
|
|
19139
|
-
: placeholder;
|
|
19140
|
-
return {
|
|
19141
|
-
...requirements,
|
|
19142
|
-
systemMessage,
|
|
19143
|
-
};
|
|
19144
|
-
}
|
|
19145
|
-
/**
|
|
19146
|
-
* Replaces temporary `USE` placeholders with one aggregated system-message block per commitment type.
|
|
19147
|
-
*
|
|
19148
|
-
* Distinct additional-instruction blocks are merged in stable source order while the hard-coded section is emitted only once.
|
|
19149
|
-
*
|
|
19150
|
-
* @param requirements - Model requirements produced by commitment-by-commitment application.
|
|
19151
|
-
* @param commitments - Filtered commitments in their original source order.
|
|
19152
|
-
* @returns Requirements with aggregated `USE` system-message sections.
|
|
19153
|
-
*
|
|
19154
|
-
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
19155
|
-
*/
|
|
19156
|
-
function aggregateUseCommitmentSystemMessages(requirements, commitments) {
|
|
19157
|
-
const additionalInstructionsByType = new Map();
|
|
19158
|
-
for (const commitment of commitments) {
|
|
19159
|
-
if (!isAggregatedUseCommitmentType(commitment.type)) {
|
|
19160
|
-
continue;
|
|
19161
|
-
}
|
|
19162
|
-
let additionalInstructions = additionalInstructionsByType.get(commitment.type);
|
|
19163
|
-
if (!additionalInstructions) {
|
|
19164
|
-
additionalInstructions = [];
|
|
19165
|
-
additionalInstructionsByType.set(commitment.type, additionalInstructions);
|
|
19166
|
-
}
|
|
19167
|
-
const normalizedContent = spaceTrim$1(commitment.content);
|
|
19168
|
-
if (normalizedContent && !additionalInstructions.includes(normalizedContent)) {
|
|
19169
|
-
additionalInstructions.push(normalizedContent);
|
|
19170
|
-
}
|
|
19171
|
-
}
|
|
19172
|
-
let systemMessage = requirements.systemMessage;
|
|
19173
|
-
for (const [type, additionalInstructions] of additionalInstructionsByType) {
|
|
19174
|
-
const placeholder = getAggregatedUseCommitmentPlaceholder(type);
|
|
19175
|
-
if (!systemMessage.includes(placeholder)) {
|
|
19176
|
-
continue;
|
|
19177
|
-
}
|
|
19178
|
-
systemMessage = systemMessage.replace(placeholder, createAggregatedUseCommitmentSystemMessage(type, additionalInstructions));
|
|
19179
|
-
}
|
|
19180
|
-
return {
|
|
19181
|
-
...requirements,
|
|
19182
|
-
systemMessage,
|
|
19183
|
-
};
|
|
19184
|
-
}
|
|
19185
|
-
|
|
19186
|
-
/**
|
|
19187
|
-
* Client-side safe wrapper for fetching URL content
|
|
19188
|
-
*
|
|
19189
|
-
* This function proxies requests to the Agents Server API endpoint for scraping,
|
|
19190
|
-
* making it safe to use in browser environments.
|
|
19191
|
-
*
|
|
19192
|
-
* @param url The URL to fetch and scrape
|
|
19193
|
-
* @param agentsServerUrl The base URL of the agents server (defaults to current origin)
|
|
19194
|
-
* @returns Markdown content from the URL
|
|
19195
|
-
*
|
|
19196
|
-
* @private internal utility for USE BROWSER commitment
|
|
19197
|
-
*/
|
|
19198
|
-
async function fetchUrlContentViaBrowser(url, agentsServerUrl) {
|
|
19199
|
-
try {
|
|
19200
|
-
// Determine the agents server URL
|
|
19201
|
-
const baseUrl = agentsServerUrl || (typeof window !== 'undefined' ? window.location.origin : '');
|
|
19202
|
-
if (!baseUrl) {
|
|
19203
|
-
throw new Error('Agents server URL is required in non-browser environments');
|
|
19204
|
-
}
|
|
19205
|
-
// Build the API endpoint URL
|
|
19206
|
-
const apiUrl = new URL('/api/scrape', baseUrl);
|
|
19207
|
-
apiUrl.searchParams.set('url', url);
|
|
19208
|
-
// Fetch from the API endpoint
|
|
19209
|
-
const response = await fetch(apiUrl.toString());
|
|
19210
|
-
if (!response.ok) {
|
|
19211
|
-
const errorData = await response.json().catch(() => ({ error: 'Unknown error' }));
|
|
19212
|
-
throw new Error(`Failed to scrape URL: ${errorData.error || response.statusText}`);
|
|
19213
|
-
}
|
|
19214
|
-
const data = await response.json();
|
|
19215
|
-
if (!data.success || !data.content) {
|
|
19216
|
-
throw new Error(`Scraping failed: ${data.error || 'No content returned'}`);
|
|
19217
|
-
}
|
|
19218
|
-
return data.content;
|
|
19219
|
-
}
|
|
19220
|
-
catch (error) {
|
|
19221
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
19222
|
-
throw new Error(`Error fetching URL content via browser: ${errorMessage}`);
|
|
19223
|
-
}
|
|
19224
|
-
}
|
|
19225
|
-
|
|
19225
|
+
|
|
19226
19226
|
/**
|
|
19227
19227
|
* USE BROWSER commitment definition
|
|
19228
19228
|
*
|
|
@@ -20226,6 +20226,44 @@ function mapGoogleCalendarEvent(event) {
|
|
|
20226
20226
|
* @private constant of createUseCalendarTools
|
|
20227
20227
|
*/
|
|
20228
20228
|
const CALENDAR_URL_PARAMETER_DESCRIPTION = 'Google Calendar URL configured by USE CALENDAR (for example "https://calendar.google.com/...").';
|
|
20229
|
+
/**
|
|
20230
|
+
* Shared schema for string arrays used by USE CALENDAR tools.
|
|
20231
|
+
*
|
|
20232
|
+
* @private constant of createUseCalendarTools
|
|
20233
|
+
*/
|
|
20234
|
+
const STRING_ARRAY_ITEMS_SCHEMA = {
|
|
20235
|
+
type: 'string',
|
|
20236
|
+
};
|
|
20237
|
+
/**
|
|
20238
|
+
* Shared schema for integer arrays used by USE CALENDAR tools.
|
|
20239
|
+
*
|
|
20240
|
+
* @private constant of createUseCalendarTools
|
|
20241
|
+
*/
|
|
20242
|
+
const INTEGER_ARRAY_ITEMS_SCHEMA = {
|
|
20243
|
+
type: 'integer',
|
|
20244
|
+
};
|
|
20245
|
+
/**
|
|
20246
|
+
* Shared `sendUpdates` schema used by USE CALENDAR tools.
|
|
20247
|
+
*
|
|
20248
|
+
* @private constant of createUseCalendarTools
|
|
20249
|
+
*/
|
|
20250
|
+
const SEND_UPDATES_PARAMETER_SCHEMA = {
|
|
20251
|
+
type: 'string',
|
|
20252
|
+
description: 'Guest update policy ("all", "externalOnly", "none").',
|
|
20253
|
+
enum: ['all', 'externalOnly', 'none'],
|
|
20254
|
+
};
|
|
20255
|
+
/**
|
|
20256
|
+
* Creates an array parameter schema with explicit item definition so OpenAI accepts it.
|
|
20257
|
+
*
|
|
20258
|
+
* @private function of createUseCalendarTools
|
|
20259
|
+
*/
|
|
20260
|
+
function createArrayParameterSchema(description, items) {
|
|
20261
|
+
return {
|
|
20262
|
+
type: 'array',
|
|
20263
|
+
description,
|
|
20264
|
+
items,
|
|
20265
|
+
};
|
|
20266
|
+
}
|
|
20229
20267
|
/**
|
|
20230
20268
|
* Adds USE CALENDAR tool definitions while keeping already registered tools untouched.
|
|
20231
20269
|
*
|
|
@@ -20332,18 +20370,9 @@ function createUseCalendarTools(existingTools) {
|
|
|
20332
20370
|
type: 'string',
|
|
20333
20371
|
description: 'Optional timezone for datetime values.',
|
|
20334
20372
|
},
|
|
20335
|
-
attendees:
|
|
20336
|
-
|
|
20337
|
-
|
|
20338
|
-
},
|
|
20339
|
-
reminderMinutes: {
|
|
20340
|
-
type: 'array',
|
|
20341
|
-
description: 'Optional popup reminder minute offsets.',
|
|
20342
|
-
},
|
|
20343
|
-
sendUpdates: {
|
|
20344
|
-
type: 'string',
|
|
20345
|
-
description: 'Guest update policy ("all", "externalOnly", "none").',
|
|
20346
|
-
},
|
|
20373
|
+
attendees: createArrayParameterSchema('Optional guest email list.', STRING_ARRAY_ITEMS_SCHEMA),
|
|
20374
|
+
reminderMinutes: createArrayParameterSchema('Optional popup reminder minute offsets.', INTEGER_ARRAY_ITEMS_SCHEMA),
|
|
20375
|
+
sendUpdates: SEND_UPDATES_PARAMETER_SCHEMA,
|
|
20347
20376
|
},
|
|
20348
20377
|
required: ['summary', 'start', 'end'],
|
|
20349
20378
|
},
|
|
@@ -20386,18 +20415,9 @@ function createUseCalendarTools(existingTools) {
|
|
|
20386
20415
|
type: 'string',
|
|
20387
20416
|
description: 'Optional timezone for datetime values.',
|
|
20388
20417
|
},
|
|
20389
|
-
attendees:
|
|
20390
|
-
|
|
20391
|
-
|
|
20392
|
-
},
|
|
20393
|
-
reminderMinutes: {
|
|
20394
|
-
type: 'array',
|
|
20395
|
-
description: 'Optional replacement popup reminder minute offsets.',
|
|
20396
|
-
},
|
|
20397
|
-
sendUpdates: {
|
|
20398
|
-
type: 'string',
|
|
20399
|
-
description: 'Guest update policy ("all", "externalOnly", "none").',
|
|
20400
|
-
},
|
|
20418
|
+
attendees: createArrayParameterSchema('Optional replacement guest email list.', STRING_ARRAY_ITEMS_SCHEMA),
|
|
20419
|
+
reminderMinutes: createArrayParameterSchema('Optional replacement popup reminder minute offsets.', INTEGER_ARRAY_ITEMS_SCHEMA),
|
|
20420
|
+
sendUpdates: SEND_UPDATES_PARAMETER_SCHEMA,
|
|
20401
20421
|
},
|
|
20402
20422
|
required: ['eventId'],
|
|
20403
20423
|
},
|
|
@@ -20416,10 +20436,7 @@ function createUseCalendarTools(existingTools) {
|
|
|
20416
20436
|
type: 'string',
|
|
20417
20437
|
description: 'Google Calendar event id.',
|
|
20418
20438
|
},
|
|
20419
|
-
sendUpdates:
|
|
20420
|
-
type: 'string',
|
|
20421
|
-
description: 'Guest update policy ("all", "externalOnly", "none").',
|
|
20422
|
-
},
|
|
20439
|
+
sendUpdates: SEND_UPDATES_PARAMETER_SCHEMA,
|
|
20423
20440
|
},
|
|
20424
20441
|
required: ['eventId'],
|
|
20425
20442
|
},
|
|
@@ -20438,14 +20455,8 @@ function createUseCalendarTools(existingTools) {
|
|
|
20438
20455
|
type: 'string',
|
|
20439
20456
|
description: 'Google Calendar event id.',
|
|
20440
20457
|
},
|
|
20441
|
-
guests:
|
|
20442
|
-
|
|
20443
|
-
description: 'Guest email list to add to the event.',
|
|
20444
|
-
},
|
|
20445
|
-
sendUpdates: {
|
|
20446
|
-
type: 'string',
|
|
20447
|
-
description: 'Guest update policy ("all", "externalOnly", "none").',
|
|
20448
|
-
},
|
|
20458
|
+
guests: createArrayParameterSchema('Guest email list to add to the event.', STRING_ARRAY_ITEMS_SCHEMA),
|
|
20459
|
+
sendUpdates: SEND_UPDATES_PARAMETER_SCHEMA,
|
|
20449
20460
|
},
|
|
20450
20461
|
required: ['eventId', 'guests'],
|
|
20451
20462
|
},
|
|
@@ -25081,49 +25092,219 @@ function getCommitmentDefinition(type) {
|
|
|
25081
25092
|
}
|
|
25082
25093
|
|
|
25083
25094
|
/**
|
|
25084
|
-
*
|
|
25095
|
+
* Commitment types whose content may contain compact agent references that must be resolved before applying the commitment.
|
|
25085
25096
|
*
|
|
25086
|
-
*
|
|
25087
|
-
|
|
25088
|
-
|
|
25097
|
+
* @private internal constant of `applyCommitmentsToAgentModelRequirements`
|
|
25098
|
+
*/
|
|
25099
|
+
const COMMITMENTS_WITH_AGENT_REFERENCES = new Set(['FROM', 'IMPORT', 'IMPORTS', 'TEAM']);
|
|
25100
|
+
/**
|
|
25101
|
+
* Applies parsed commitments one by one while keeping the per-commitment steps focused and easy to follow.
|
|
25089
25102
|
*
|
|
25090
|
-
* @param
|
|
25091
|
-
* @
|
|
25103
|
+
* @param requirements - Current requirements snapshot.
|
|
25104
|
+
* @param commitments - Commitments already filtered for DELETE-like invalidations.
|
|
25105
|
+
* @param options - Optional reference and teammate resolvers.
|
|
25106
|
+
* @returns Requirements after all applicable commitments are processed.
|
|
25092
25107
|
*
|
|
25093
|
-
* @private
|
|
25108
|
+
* @private function of `createAgentModelRequirementsWithCommitments`
|
|
25094
25109
|
*/
|
|
25095
|
-
function
|
|
25096
|
-
const
|
|
25097
|
-
|
|
25098
|
-
const line = lines[lineIndex];
|
|
25099
|
-
if (line === undefined) {
|
|
25100
|
-
continue;
|
|
25101
|
-
}
|
|
25102
|
-
const trimmedLine = line.trim();
|
|
25103
|
-
if (!trimmedLine) {
|
|
25110
|
+
async function applyCommitmentsToAgentModelRequirements(requirements, commitments, options) {
|
|
25111
|
+
for (const [index, commitment] of commitments.entries()) {
|
|
25112
|
+
if (shouldSkipCommitmentApplication(commitment, index, commitments.length)) {
|
|
25104
25113
|
continue;
|
|
25105
25114
|
}
|
|
25106
|
-
|
|
25107
|
-
|
|
25108
|
-
|
|
25109
|
-
agentNameLineIndex: lineIndex,
|
|
25110
|
-
agentNameLineNumber: lineIndex + 1,
|
|
25111
|
-
};
|
|
25115
|
+
const commitmentContent = await resolveCommitmentContent(commitment, options === null || options === void 0 ? void 0 : options.agentReferenceResolver);
|
|
25116
|
+
requirements = await preResolveTeammateProfilesForTeamCommitment(requirements, commitment, commitmentContent, options);
|
|
25117
|
+
requirements = applyCommitmentDefinitionSafely(requirements, commitment, commitmentContent);
|
|
25112
25118
|
}
|
|
25113
|
-
return
|
|
25114
|
-
lines,
|
|
25115
|
-
agentName: null,
|
|
25116
|
-
agentNameLineIndex: -1,
|
|
25117
|
-
};
|
|
25119
|
+
return requirements;
|
|
25118
25120
|
}
|
|
25119
|
-
|
|
25120
|
-
/**
|
|
25121
|
-
* Regex pattern to match horizontal lines (markdown thematic breaks)
|
|
25122
|
-
* Matches 3 or more hyphens, underscores, or asterisks (with optional spaces between)
|
|
25123
|
-
*/
|
|
25124
|
-
const HORIZONTAL_LINE_PATTERN$1 = /^[\s]*[-_*][\s]*[-_*][\s]*[-_*][\s]*[-_*]*[\s]*$/;
|
|
25125
25121
|
/**
|
|
25126
|
-
*
|
|
25122
|
+
* Resolves compact agent references for commitment types that support them.
|
|
25123
|
+
*
|
|
25124
|
+
* @param commitment - Commitment currently being applied.
|
|
25125
|
+
* @param agentReferenceResolver - Optional resolver for compact agent references.
|
|
25126
|
+
* @returns Original or resolved commitment content.
|
|
25127
|
+
*
|
|
25128
|
+
* @private internal utility of `applyCommitmentsToAgentModelRequirements`
|
|
25129
|
+
*/
|
|
25130
|
+
async function resolveCommitmentContent(commitment, agentReferenceResolver) {
|
|
25131
|
+
if (!agentReferenceResolver || !isAgentReferenceCommitment(commitment.type)) {
|
|
25132
|
+
return commitment.content;
|
|
25133
|
+
}
|
|
25134
|
+
try {
|
|
25135
|
+
return await agentReferenceResolver.resolveCommitmentContent(commitment.type, commitment.content);
|
|
25136
|
+
}
|
|
25137
|
+
catch (error) {
|
|
25138
|
+
console.warn(`Failed to resolve commitment references for ${commitment.type}, falling back to safe defaults:`, error);
|
|
25139
|
+
return getSafeReferenceCommitmentFallback(commitment.type, commitment.content);
|
|
25140
|
+
}
|
|
25141
|
+
}
|
|
25142
|
+
/**
|
|
25143
|
+
* Returns a safe fallback content when a resolver fails to transform a reference commitment.
|
|
25144
|
+
*
|
|
25145
|
+
* @param commitmentType - Commitment being resolved.
|
|
25146
|
+
* @param originalContent - Original unresolved commitment content.
|
|
25147
|
+
* @returns Fallback content that keeps requirement creation resilient.
|
|
25148
|
+
*
|
|
25149
|
+
* @private internal utility of `applyCommitmentsToAgentModelRequirements`
|
|
25150
|
+
*/
|
|
25151
|
+
function getSafeReferenceCommitmentFallback(commitmentType, originalContent) {
|
|
25152
|
+
if (commitmentType === 'FROM') {
|
|
25153
|
+
return 'VOID';
|
|
25154
|
+
}
|
|
25155
|
+
if (commitmentType === 'IMPORT' || commitmentType === 'IMPORTS' || commitmentType === 'TEAM') {
|
|
25156
|
+
return '';
|
|
25157
|
+
}
|
|
25158
|
+
return originalContent;
|
|
25159
|
+
}
|
|
25160
|
+
/**
|
|
25161
|
+
* Checks whether the commitment content may need agent-reference resolution before application.
|
|
25162
|
+
*
|
|
25163
|
+
* @param commitmentType - Commitment type to check.
|
|
25164
|
+
* @returns `true` when the commitment can contain compact agent references.
|
|
25165
|
+
*
|
|
25166
|
+
* @private internal utility of `resolveCommitmentContent`
|
|
25167
|
+
*/
|
|
25168
|
+
function isAgentReferenceCommitment(commitmentType) {
|
|
25169
|
+
return COMMITMENTS_WITH_AGENT_REFERENCES.has(commitmentType);
|
|
25170
|
+
}
|
|
25171
|
+
/**
|
|
25172
|
+
* Determines whether a commitment should be skipped before resolution or application.
|
|
25173
|
+
*
|
|
25174
|
+
* @param commitment - Commitment under consideration.
|
|
25175
|
+
* @param commitmentIndex - Zero-based position among filtered commitments.
|
|
25176
|
+
* @param commitmentCount - Total number of filtered commitments.
|
|
25177
|
+
* @returns `true` when the commitment should not be applied.
|
|
25178
|
+
*
|
|
25179
|
+
* @private internal utility of `applyCommitmentsToAgentModelRequirements`
|
|
25180
|
+
*/
|
|
25181
|
+
function shouldSkipCommitmentApplication(commitment, commitmentIndex, commitmentCount) {
|
|
25182
|
+
return commitment.type === 'CLOSED' && commitmentIndex !== commitmentCount - 1;
|
|
25183
|
+
}
|
|
25184
|
+
/**
|
|
25185
|
+
* Pre-resolves teammate profiles for TEAM commitments so the TEAM commitment definition can reuse richer metadata.
|
|
25186
|
+
*
|
|
25187
|
+
* @param requirements - Current requirements snapshot.
|
|
25188
|
+
* @param commitment - Commitment currently being prepared.
|
|
25189
|
+
* @param commitmentContent - Already resolved TEAM commitment content.
|
|
25190
|
+
* @param options - Optional teammate profile resolvers.
|
|
25191
|
+
* @returns Requirements with pre-resolved teammate profiles stored in metadata when possible.
|
|
25192
|
+
*
|
|
25193
|
+
* @private internal utility of `applyCommitmentsToAgentModelRequirements`
|
|
25194
|
+
*/
|
|
25195
|
+
async function preResolveTeammateProfilesForTeamCommitment(requirements, commitment, commitmentContent, options) {
|
|
25196
|
+
var _a;
|
|
25197
|
+
const profileResolver = (_a = options === null || options === void 0 ? void 0 : options.teammateProfileResolver) !== null && _a !== void 0 ? _a : options === null || options === void 0 ? void 0 : options.agentReferenceResolver;
|
|
25198
|
+
if (commitment.type !== 'TEAM' || !(profileResolver === null || profileResolver === void 0 ? void 0 : profileResolver.resolveTeammateProfile)) {
|
|
25199
|
+
return requirements;
|
|
25200
|
+
}
|
|
25201
|
+
try {
|
|
25202
|
+
const parsedTeammates = parseTeamCommitmentContent(commitmentContent, { strict: false });
|
|
25203
|
+
const preResolvedTeammateProfiles = clonePreResolvedTeammateProfiles(requirements._metadata);
|
|
25204
|
+
for (const teammate of parsedTeammates) {
|
|
25205
|
+
if (preResolvedTeammateProfiles[teammate.url]) {
|
|
25206
|
+
continue;
|
|
25207
|
+
}
|
|
25208
|
+
const profile = await profileResolver.resolveTeammateProfile(teammate.url);
|
|
25209
|
+
if (profile) {
|
|
25210
|
+
preResolvedTeammateProfiles[teammate.url] = profile;
|
|
25211
|
+
}
|
|
25212
|
+
}
|
|
25213
|
+
return {
|
|
25214
|
+
...requirements,
|
|
25215
|
+
_metadata: {
|
|
25216
|
+
...requirements._metadata,
|
|
25217
|
+
preResolvedTeammateProfiles,
|
|
25218
|
+
},
|
|
25219
|
+
};
|
|
25220
|
+
}
|
|
25221
|
+
catch (error) {
|
|
25222
|
+
console.warn('Failed to pre-resolve teammate profiles for TEAM commitment:', error);
|
|
25223
|
+
return requirements;
|
|
25224
|
+
}
|
|
25225
|
+
}
|
|
25226
|
+
/**
|
|
25227
|
+
* Clones the metadata bucket used to cache teammate profiles resolved ahead of TEAM commitment application.
|
|
25228
|
+
*
|
|
25229
|
+
* @param metadata - Current requirements metadata.
|
|
25230
|
+
* @returns Mutable copy of the cached teammate profile map.
|
|
25231
|
+
*
|
|
25232
|
+
* @private internal utility of `preResolveTeammateProfilesForTeamCommitment`
|
|
25233
|
+
*/
|
|
25234
|
+
function clonePreResolvedTeammateProfiles(metadata) {
|
|
25235
|
+
var _a;
|
|
25236
|
+
return {
|
|
25237
|
+
...((_a = metadata === null || metadata === void 0 ? void 0 : metadata.preResolvedTeammateProfiles) !== null && _a !== void 0 ? _a : {}),
|
|
25238
|
+
};
|
|
25239
|
+
}
|
|
25240
|
+
/**
|
|
25241
|
+
* Applies the registered commitment definition while isolating the failure handling from the main loop.
|
|
25242
|
+
*
|
|
25243
|
+
* @param requirements - Current requirements snapshot.
|
|
25244
|
+
* @param commitment - Commitment whose definition should be applied.
|
|
25245
|
+
* @param commitmentContent - Final content passed into the definition.
|
|
25246
|
+
* @returns Updated requirements, or the original requirements when the commitment fails.
|
|
25247
|
+
*
|
|
25248
|
+
* @private internal utility of `applyCommitmentsToAgentModelRequirements`
|
|
25249
|
+
*/
|
|
25250
|
+
function applyCommitmentDefinitionSafely(requirements, commitment, commitmentContent) {
|
|
25251
|
+
const definition = getCommitmentDefinition(commitment.type);
|
|
25252
|
+
if (!definition) {
|
|
25253
|
+
return requirements;
|
|
25254
|
+
}
|
|
25255
|
+
try {
|
|
25256
|
+
return definition.applyToAgentModelRequirements(requirements, commitmentContent);
|
|
25257
|
+
}
|
|
25258
|
+
catch (error) {
|
|
25259
|
+
console.warn(`Failed to apply commitment ${commitment.type}:`, error);
|
|
25260
|
+
return requirements;
|
|
25261
|
+
}
|
|
25262
|
+
}
|
|
25263
|
+
|
|
25264
|
+
/**
|
|
25265
|
+
* Consumes the agent-name prelude from raw source.
|
|
25266
|
+
*
|
|
25267
|
+
* Leading whitespace-only lines are skipped. The first subsequent line that contains any
|
|
25268
|
+
* non-whitespace characters is always treated as plain-text agent name, even when it starts
|
|
25269
|
+
* with a commitment keyword or other book syntax.
|
|
25270
|
+
*
|
|
25271
|
+
* @param agentSource - Raw agent source.
|
|
25272
|
+
* @returns Parsed prelude with shared line metadata.
|
|
25273
|
+
*
|
|
25274
|
+
* @private internal utility of book agent-source parsing
|
|
25275
|
+
*/
|
|
25276
|
+
function parseAgentSourcePrelude(agentSource) {
|
|
25277
|
+
const lines = agentSource.split(/\r?\n/);
|
|
25278
|
+
for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
|
25279
|
+
const line = lines[lineIndex];
|
|
25280
|
+
if (line === undefined) {
|
|
25281
|
+
continue;
|
|
25282
|
+
}
|
|
25283
|
+
const trimmedLine = line.trim();
|
|
25284
|
+
if (!trimmedLine) {
|
|
25285
|
+
continue;
|
|
25286
|
+
}
|
|
25287
|
+
return {
|
|
25288
|
+
lines,
|
|
25289
|
+
agentName: trimmedLine,
|
|
25290
|
+
agentNameLineIndex: lineIndex,
|
|
25291
|
+
agentNameLineNumber: lineIndex + 1,
|
|
25292
|
+
};
|
|
25293
|
+
}
|
|
25294
|
+
return {
|
|
25295
|
+
lines,
|
|
25296
|
+
agentName: null,
|
|
25297
|
+
agentNameLineIndex: -1,
|
|
25298
|
+
};
|
|
25299
|
+
}
|
|
25300
|
+
|
|
25301
|
+
/**
|
|
25302
|
+
* Regex pattern to match horizontal lines (markdown thematic breaks)
|
|
25303
|
+
* Matches 3 or more hyphens, underscores, or asterisks (with optional spaces between)
|
|
25304
|
+
*/
|
|
25305
|
+
const HORIZONTAL_LINE_PATTERN$1 = /^[\s]*[-_*][\s]*[-_*][\s]*[-_*][\s]*[-_*]*[\s]*$/;
|
|
25306
|
+
/**
|
|
25307
|
+
* Parses agent source using the new commitment system with multiline support
|
|
25127
25308
|
* This function replaces the hardcoded commitment parsing in the original parseAgentSource
|
|
25128
25309
|
*
|
|
25129
25310
|
* The first non-empty line is always consumed as plain-text agent name. Commitment parsing
|
|
@@ -25348,422 +25529,39 @@ const $fileImportPlugins = [
|
|
|
25348
25529
|
];
|
|
25349
25530
|
|
|
25350
25531
|
/**
|
|
25351
|
-
*
|
|
25352
|
-
* 1. @Parameter - single word parameter starting with @
|
|
25353
|
-
* 2. {parameterName} or {parameter with multiple words} or {parameterName: description text}
|
|
25354
|
-
*
|
|
25355
|
-
* Both notations represent the same syntax feature - parameters
|
|
25532
|
+
* Regex pattern matching markdown horizontal lines that should not be copied into the final system message.
|
|
25356
25533
|
*
|
|
25357
|
-
* @
|
|
25358
|
-
|
|
25534
|
+
* @private internal constant of `augmentAgentModelRequirementsFromSource`
|
|
25535
|
+
*/
|
|
25536
|
+
const HORIZONTAL_LINE_PATTERN = /^[\s]*[-_*][\s]*[-_*][\s]*[-_*][\s]*[-_*]*[\s]*$/;
|
|
25537
|
+
/**
|
|
25538
|
+
* MIME type prefixes treated as binary and therefore not eligible for text import plugins.
|
|
25359
25539
|
*
|
|
25360
|
-
* @
|
|
25540
|
+
* @private internal constant of `augmentAgentModelRequirementsFromSource`
|
|
25361
25541
|
*/
|
|
25362
|
-
|
|
25363
|
-
|
|
25364
|
-
|
|
25365
|
-
|
|
25366
|
-
|
|
25367
|
-
|
|
25368
|
-
|
|
25369
|
-
|
|
25370
|
-
parameters.push({
|
|
25371
|
-
text: match,
|
|
25372
|
-
notation: 'at',
|
|
25373
|
-
name: parameterName,
|
|
25374
|
-
});
|
|
25375
|
-
return match;
|
|
25376
|
-
});
|
|
25377
|
-
// Extract {parameter} notation (parameters in braces)
|
|
25378
|
-
const braceParameterRegex = /\{([^}]+)\}/gim;
|
|
25379
|
-
text.replace(braceParameterRegex, (match, content) => {
|
|
25380
|
-
// Check if the parameter has a description (parameterName: description)
|
|
25381
|
-
const colonIndex = content.indexOf(':');
|
|
25382
|
-
if (colonIndex !== -1) {
|
|
25383
|
-
const name = content.substring(0, colonIndex).trim();
|
|
25384
|
-
const description = content.substring(colonIndex + 1).trim();
|
|
25385
|
-
parameters.push({
|
|
25386
|
-
text: match,
|
|
25387
|
-
notation: 'brace',
|
|
25388
|
-
name,
|
|
25389
|
-
description,
|
|
25390
|
-
});
|
|
25391
|
-
}
|
|
25392
|
-
else {
|
|
25393
|
-
// Simple parameter without description
|
|
25394
|
-
parameters.push({
|
|
25395
|
-
text: match,
|
|
25396
|
-
notation: 'brace',
|
|
25397
|
-
name: content.trim(),
|
|
25398
|
-
});
|
|
25399
|
-
}
|
|
25400
|
-
return match;
|
|
25401
|
-
});
|
|
25402
|
-
// Remove duplicates based on name (keep the first occurrence)
|
|
25403
|
-
const uniqueParameters = parameters.filter((parameter, index, array) => {
|
|
25404
|
-
return array.findIndex((parameterItem) => parameterItem.name === parameter.name) === index;
|
|
25405
|
-
});
|
|
25406
|
-
return uniqueParameters;
|
|
25407
|
-
}
|
|
25408
|
-
|
|
25542
|
+
const BINARY_MIME_TYPE_PREFIXES = [
|
|
25543
|
+
'image/',
|
|
25544
|
+
'video/',
|
|
25545
|
+
'audio/',
|
|
25546
|
+
'application/octet-stream',
|
|
25547
|
+
'application/pdf',
|
|
25548
|
+
'application/zip',
|
|
25549
|
+
];
|
|
25409
25550
|
/**
|
|
25410
|
-
*
|
|
25411
|
-
* This is used to clean up the final system message before sending it to the AI model
|
|
25412
|
-
* while preserving the original content with comments in metadata
|
|
25551
|
+
* Adds source-derived sections after commitments have been applied.
|
|
25413
25552
|
*
|
|
25414
|
-
* @param
|
|
25415
|
-
* @
|
|
25553
|
+
* @param requirements - Requirements after commitment application and USE aggregation.
|
|
25554
|
+
* @param parseResult - Parsed source used to recover non-commitment prose and examples.
|
|
25555
|
+
* @param agentSource - Original source used to recover MCP server declarations.
|
|
25556
|
+
* @returns Requirements with source-derived sections appended.
|
|
25416
25557
|
*
|
|
25417
|
-
* @private
|
|
25558
|
+
* @private function of `createAgentModelRequirementsWithCommitments`
|
|
25418
25559
|
*/
|
|
25419
|
-
function
|
|
25420
|
-
if (!systemMessage) {
|
|
25421
|
-
return systemMessage;
|
|
25422
|
-
}
|
|
25423
|
-
const lines = systemMessage.split(/\r?\n/);
|
|
25424
|
-
const filteredLines = lines.filter((line) => {
|
|
25425
|
-
const trimmedLine = line.trim();
|
|
25426
|
-
// Remove only single-hash comment markers (`# Comment`) and keep markdown headings (`## Heading`).
|
|
25427
|
-
return !/^#(?!#)\s/.test(trimmedLine);
|
|
25428
|
-
});
|
|
25429
|
-
return filteredLines.join('\n').trim();
|
|
25430
|
-
}
|
|
25431
|
-
|
|
25432
|
-
/**
|
|
25433
|
-
* Commitment types whose content may contain compact agent references that must be resolved before applying the commitment.
|
|
25434
|
-
*
|
|
25435
|
-
* @private internal constant of `createAgentModelRequirementsWithCommitments`
|
|
25436
|
-
*/
|
|
25437
|
-
const COMMITMENTS_WITH_AGENT_REFERENCES = new Set(['FROM', 'IMPORT', 'IMPORTS', 'TEAM']);
|
|
25438
|
-
/**
|
|
25439
|
-
* DELETE-like commitment types that invalidate earlier tagged commitments.
|
|
25440
|
-
*
|
|
25441
|
-
* @private internal constant of `createAgentModelRequirementsWithCommitments`
|
|
25442
|
-
*/
|
|
25443
|
-
const DELETE_COMMITMENT_TYPES = new Set(['DELETE', 'CANCEL', 'DISCARD', 'REMOVE']);
|
|
25444
|
-
/**
|
|
25445
|
-
* Commitments whose earlier occurrences are overwritten by the last occurrence in source order.
|
|
25446
|
-
*
|
|
25447
|
-
* @private internal constant of `createAgentModelRequirementsWithCommitments`
|
|
25448
|
-
*/
|
|
25449
|
-
const OVERWRITTEN_COMMITMENT_GROUP_BY_TYPE = new Map([
|
|
25450
|
-
['GOAL', 'GOAL'],
|
|
25451
|
-
['GOALS', 'GOAL'],
|
|
25452
|
-
]);
|
|
25453
|
-
/**
|
|
25454
|
-
* Regex pattern matching markdown horizontal lines that should not be copied into the final system message.
|
|
25455
|
-
*
|
|
25456
|
-
* @private internal constant of `createAgentModelRequirementsWithCommitments`
|
|
25457
|
-
*/
|
|
25458
|
-
const HORIZONTAL_LINE_PATTERN = /^[\s]*[-_*][\s]*[-_*][\s]*[-_*][\s]*[-_*]*[\s]*$/;
|
|
25459
|
-
/**
|
|
25460
|
-
* MIME type prefixes treated as binary and therefore not eligible for text import plugins.
|
|
25461
|
-
*
|
|
25462
|
-
* @private internal constant of `createAgentModelRequirementsWithCommitments`
|
|
25463
|
-
*/
|
|
25464
|
-
const BINARY_MIME_TYPE_PREFIXES = [
|
|
25465
|
-
'image/',
|
|
25466
|
-
'video/',
|
|
25467
|
-
'audio/',
|
|
25468
|
-
'application/octet-stream',
|
|
25469
|
-
'application/pdf',
|
|
25470
|
-
'application/zip',
|
|
25471
|
-
];
|
|
25472
|
-
/**
|
|
25473
|
-
* Returns a safe fallback content when a resolver fails to transform a reference commitment.
|
|
25474
|
-
*
|
|
25475
|
-
* @param commitmentType - Commitment being resolved.
|
|
25476
|
-
* @param originalContent - Original unresolved commitment content.
|
|
25477
|
-
* @returns Fallback content that keeps requirement creation resilient.
|
|
25478
|
-
*
|
|
25479
|
-
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
25480
|
-
*/
|
|
25481
|
-
function getSafeReferenceCommitmentFallback(commitmentType, originalContent) {
|
|
25482
|
-
if (commitmentType === 'FROM') {
|
|
25483
|
-
return 'VOID';
|
|
25484
|
-
}
|
|
25485
|
-
if (commitmentType === 'IMPORT' || commitmentType === 'IMPORTS' || commitmentType === 'TEAM') {
|
|
25486
|
-
return '';
|
|
25487
|
-
}
|
|
25488
|
-
return originalContent;
|
|
25489
|
-
}
|
|
25490
|
-
/**
|
|
25491
|
-
* Creates agent model requirements by parsing commitments, applying them in source order,
|
|
25492
|
-
* and finalizing derived sections such as imports, example interactions, and inline knowledge uploads.
|
|
25493
|
-
*
|
|
25494
|
-
* @param agentSource - Agent source book to parse.
|
|
25495
|
-
* @param modelName - Optional override for the agent model name.
|
|
25496
|
-
* @param options - Additional options such as reference and teammate resolvers.
|
|
25497
|
-
* @returns Fully prepared model requirements for the parsed agent source.
|
|
25498
|
-
*
|
|
25499
|
-
* @private internal utility of `createAgentModelRequirements`
|
|
25500
|
-
*/
|
|
25501
|
-
async function createAgentModelRequirementsWithCommitments(agentSource, modelName, options) {
|
|
25502
|
-
const parseResult = parseAgentSourceWithCommitments(agentSource);
|
|
25503
|
-
const filteredCommitments = filterOverwrittenCommitments(filterDeletedCommitments(parseResult.commitments));
|
|
25504
|
-
let requirements = createInitialAgentModelRequirements(parseResult.agentName, modelName);
|
|
25505
|
-
requirements = await applyCommitmentsToRequirements(requirements, filteredCommitments, options);
|
|
25506
|
-
requirements = aggregateUseCommitmentSystemMessages(requirements, filteredCommitments);
|
|
25560
|
+
async function augmentAgentModelRequirementsFromSource(requirements, parseResult, agentSource) {
|
|
25507
25561
|
requirements = await importReferencedFiles(requirements);
|
|
25508
25562
|
requirements = appendMcpServers(requirements, agentSource);
|
|
25509
25563
|
requirements = appendNonCommitmentContent(requirements, parseResult);
|
|
25510
|
-
|
|
25511
|
-
requirements = await applyPendingInlineKnowledgeSources(requirements, options === null || options === void 0 ? void 0 : options.inlineKnowledgeSourceUploader);
|
|
25512
|
-
return finalizeRequirements(requirements);
|
|
25513
|
-
}
|
|
25514
|
-
/**
|
|
25515
|
-
* Removes earlier commitments that are overwritten by later commitments of the same semantic group.
|
|
25516
|
-
*
|
|
25517
|
-
* This currently keeps only the last `GOAL` / `GOALS` commitment so inheritance rewrites
|
|
25518
|
-
* and multi-goal sources expose one effective goal to the runtime.
|
|
25519
|
-
*
|
|
25520
|
-
* @param commitments - Parsed commitments after DELETE-like filtering.
|
|
25521
|
-
* @returns Commitments with overwritten entries removed while preserving source order.
|
|
25522
|
-
*
|
|
25523
|
-
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
25524
|
-
*/
|
|
25525
|
-
function filterOverwrittenCommitments(commitments) {
|
|
25526
|
-
const seenOverwriteGroups = new Set();
|
|
25527
|
-
const keptCommitments = [];
|
|
25528
|
-
for (let index = commitments.length - 1; index >= 0; index--) {
|
|
25529
|
-
const commitment = commitments[index];
|
|
25530
|
-
const overwriteGroup = OVERWRITTEN_COMMITMENT_GROUP_BY_TYPE.get(commitment.type);
|
|
25531
|
-
if (!overwriteGroup) {
|
|
25532
|
-
keptCommitments.push(commitment);
|
|
25533
|
-
continue;
|
|
25534
|
-
}
|
|
25535
|
-
if (seenOverwriteGroups.has(overwriteGroup)) {
|
|
25536
|
-
continue;
|
|
25537
|
-
}
|
|
25538
|
-
seenOverwriteGroups.add(overwriteGroup);
|
|
25539
|
-
keptCommitments.push(commitment);
|
|
25540
|
-
}
|
|
25541
|
-
return keptCommitments.reverse();
|
|
25542
|
-
}
|
|
25543
|
-
/**
|
|
25544
|
-
* Creates the initial requirements object with the parsed agent name stored in metadata and an optional model override.
|
|
25545
|
-
*
|
|
25546
|
-
* @param agentName - Parsed agent name from the source prelude.
|
|
25547
|
-
* @param modelName - Optional explicit model name override.
|
|
25548
|
-
* @returns Initial requirements before any commitment is applied.
|
|
25549
|
-
*
|
|
25550
|
-
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
25551
|
-
*/
|
|
25552
|
-
function createInitialAgentModelRequirements(agentName, modelName) {
|
|
25553
|
-
const initialRequirements = createBasicAgentModelRequirements(agentName);
|
|
25554
|
-
const requirementsWithMetadata = {
|
|
25555
|
-
...initialRequirements,
|
|
25556
|
-
_metadata: {
|
|
25557
|
-
...initialRequirements._metadata,
|
|
25558
|
-
agentName,
|
|
25559
|
-
},
|
|
25560
|
-
};
|
|
25561
|
-
if (!modelName) {
|
|
25562
|
-
return requirementsWithMetadata;
|
|
25563
|
-
}
|
|
25564
|
-
return {
|
|
25565
|
-
...requirementsWithMetadata,
|
|
25566
|
-
modelName,
|
|
25567
|
-
};
|
|
25568
|
-
}
|
|
25569
|
-
/**
|
|
25570
|
-
* Applies DELETE-like invalidation commitments and returns only commitments that should continue through the pipeline.
|
|
25571
|
-
*
|
|
25572
|
-
* @param commitments - Parsed commitments in original source order.
|
|
25573
|
-
* @returns Filtered commitments with earlier deleted items removed.
|
|
25574
|
-
*
|
|
25575
|
-
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
25576
|
-
*/
|
|
25577
|
-
function filterDeletedCommitments(commitments) {
|
|
25578
|
-
const filteredCommitments = [];
|
|
25579
|
-
for (const commitment of commitments) {
|
|
25580
|
-
if (!isDeleteCommitmentType(commitment.type)) {
|
|
25581
|
-
filteredCommitments.push(commitment);
|
|
25582
|
-
continue;
|
|
25583
|
-
}
|
|
25584
|
-
const targetParameterNames = getCommitmentParameterNames(commitment.content);
|
|
25585
|
-
if (targetParameterNames.length === 0) {
|
|
25586
|
-
continue;
|
|
25587
|
-
}
|
|
25588
|
-
for (let index = filteredCommitments.length - 1; index >= 0; index--) {
|
|
25589
|
-
const previousCommitment = filteredCommitments[index];
|
|
25590
|
-
const previousParameterNames = getCommitmentParameterNames(previousCommitment.content);
|
|
25591
|
-
const isTargeted = previousParameterNames.some((parameterName) => targetParameterNames.includes(parameterName));
|
|
25592
|
-
if (isTargeted) {
|
|
25593
|
-
filteredCommitments.splice(index, 1);
|
|
25594
|
-
}
|
|
25595
|
-
}
|
|
25596
|
-
}
|
|
25597
|
-
return filteredCommitments;
|
|
25598
|
-
}
|
|
25599
|
-
/**
|
|
25600
|
-
* Checks whether a commitment type behaves like DELETE and therefore invalidates earlier tagged commitments.
|
|
25601
|
-
*
|
|
25602
|
-
* @param commitmentType - Commitment type to check.
|
|
25603
|
-
* @returns `true` when the commitment removes prior tagged commitments.
|
|
25604
|
-
*
|
|
25605
|
-
* @private internal utility of `filterDeletedCommitments`
|
|
25606
|
-
*/
|
|
25607
|
-
function isDeleteCommitmentType(commitmentType) {
|
|
25608
|
-
return DELETE_COMMITMENT_TYPES.has(commitmentType);
|
|
25609
|
-
}
|
|
25610
|
-
/**
|
|
25611
|
-
* Extracts normalized parameter names used for DELETE-like invalidation matching.
|
|
25612
|
-
*
|
|
25613
|
-
* @param content - Commitment content to parse.
|
|
25614
|
-
* @returns Lower-cased non-empty parameter names.
|
|
25615
|
-
*
|
|
25616
|
-
* @private internal utility of `filterDeletedCommitments`
|
|
25617
|
-
*/
|
|
25618
|
-
function getCommitmentParameterNames(content) {
|
|
25619
|
-
return parseParameters(content)
|
|
25620
|
-
.map((parameter) => parameter.name.trim().toLowerCase())
|
|
25621
|
-
.filter(Boolean);
|
|
25622
|
-
}
|
|
25623
|
-
/**
|
|
25624
|
-
* Applies parsed commitments one by one while keeping the per-commitment steps focused and easy to follow.
|
|
25625
|
-
*
|
|
25626
|
-
* @param requirements - Current requirements snapshot.
|
|
25627
|
-
* @param commitments - Commitments already filtered for DELETE-like invalidations.
|
|
25628
|
-
* @param options - Optional reference and teammate resolvers.
|
|
25629
|
-
* @returns Requirements after all applicable commitments are processed.
|
|
25630
|
-
*
|
|
25631
|
-
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
25632
|
-
*/
|
|
25633
|
-
async function applyCommitmentsToRequirements(requirements, commitments, options) {
|
|
25634
|
-
for (const [index, commitment] of commitments.entries()) {
|
|
25635
|
-
if (shouldSkipCommitmentApplication(commitment, index, commitments.length)) {
|
|
25636
|
-
continue;
|
|
25637
|
-
}
|
|
25638
|
-
const commitmentContent = await resolveCommitmentContent(commitment, options === null || options === void 0 ? void 0 : options.agentReferenceResolver);
|
|
25639
|
-
requirements = await preResolveTeammateProfilesForTeamCommitment(requirements, commitment, commitmentContent, options);
|
|
25640
|
-
requirements = applyCommitmentDefinitionSafely(requirements, commitment, commitmentContent);
|
|
25641
|
-
}
|
|
25642
|
-
return requirements;
|
|
25643
|
-
}
|
|
25644
|
-
/**
|
|
25645
|
-
* Resolves compact agent references for commitment types that support them.
|
|
25646
|
-
*
|
|
25647
|
-
* @param commitment - Commitment currently being applied.
|
|
25648
|
-
* @param agentReferenceResolver - Optional resolver for compact agent references.
|
|
25649
|
-
* @returns Original or resolved commitment content.
|
|
25650
|
-
*
|
|
25651
|
-
* @private internal utility of `applyCommitmentsToRequirements`
|
|
25652
|
-
*/
|
|
25653
|
-
async function resolveCommitmentContent(commitment, agentReferenceResolver) {
|
|
25654
|
-
if (!agentReferenceResolver || !isAgentReferenceCommitment(commitment.type)) {
|
|
25655
|
-
return commitment.content;
|
|
25656
|
-
}
|
|
25657
|
-
try {
|
|
25658
|
-
return await agentReferenceResolver.resolveCommitmentContent(commitment.type, commitment.content);
|
|
25659
|
-
}
|
|
25660
|
-
catch (error) {
|
|
25661
|
-
console.warn(`Failed to resolve commitment references for ${commitment.type}, falling back to safe defaults:`, error);
|
|
25662
|
-
return getSafeReferenceCommitmentFallback(commitment.type, commitment.content);
|
|
25663
|
-
}
|
|
25664
|
-
}
|
|
25665
|
-
/**
|
|
25666
|
-
* Checks whether the commitment content may need agent-reference resolution before application.
|
|
25667
|
-
*
|
|
25668
|
-
* @param commitmentType - Commitment type to check.
|
|
25669
|
-
* @returns `true` when the commitment can contain compact agent references.
|
|
25670
|
-
*
|
|
25671
|
-
* @private internal utility of `resolveCommitmentContent`
|
|
25672
|
-
*/
|
|
25673
|
-
function isAgentReferenceCommitment(commitmentType) {
|
|
25674
|
-
return COMMITMENTS_WITH_AGENT_REFERENCES.has(commitmentType);
|
|
25675
|
-
}
|
|
25676
|
-
/**
|
|
25677
|
-
* Determines whether a commitment should be skipped before resolution or application.
|
|
25678
|
-
*
|
|
25679
|
-
* @param commitment - Commitment under consideration.
|
|
25680
|
-
* @param commitmentIndex - Zero-based position among filtered commitments.
|
|
25681
|
-
* @param commitmentCount - Total number of filtered commitments.
|
|
25682
|
-
* @returns `true` when the commitment should not be applied.
|
|
25683
|
-
*
|
|
25684
|
-
* @private internal utility of `applyCommitmentsToRequirements`
|
|
25685
|
-
*/
|
|
25686
|
-
function shouldSkipCommitmentApplication(commitment, commitmentIndex, commitmentCount) {
|
|
25687
|
-
return commitment.type === 'CLOSED' && commitmentIndex !== commitmentCount - 1;
|
|
25688
|
-
}
|
|
25689
|
-
/**
|
|
25690
|
-
* Pre-resolves teammate profiles for TEAM commitments so the TEAM commitment definition can reuse richer metadata.
|
|
25691
|
-
*
|
|
25692
|
-
* @param requirements - Current requirements snapshot.
|
|
25693
|
-
* @param commitment - Commitment currently being prepared.
|
|
25694
|
-
* @param commitmentContent - Already resolved TEAM commitment content.
|
|
25695
|
-
* @param options - Optional teammate profile resolvers.
|
|
25696
|
-
* @returns Requirements with pre-resolved teammate profiles stored in metadata when possible.
|
|
25697
|
-
*
|
|
25698
|
-
* @private internal utility of `applyCommitmentsToRequirements`
|
|
25699
|
-
*/
|
|
25700
|
-
async function preResolveTeammateProfilesForTeamCommitment(requirements, commitment, commitmentContent, options) {
|
|
25701
|
-
var _a;
|
|
25702
|
-
const profileResolver = (_a = options === null || options === void 0 ? void 0 : options.teammateProfileResolver) !== null && _a !== void 0 ? _a : options === null || options === void 0 ? void 0 : options.agentReferenceResolver;
|
|
25703
|
-
if (commitment.type !== 'TEAM' || !(profileResolver === null || profileResolver === void 0 ? void 0 : profileResolver.resolveTeammateProfile)) {
|
|
25704
|
-
return requirements;
|
|
25705
|
-
}
|
|
25706
|
-
try {
|
|
25707
|
-
const parsedTeammates = parseTeamCommitmentContent(commitmentContent, { strict: false });
|
|
25708
|
-
const preResolvedTeammateProfiles = clonePreResolvedTeammateProfiles(requirements._metadata);
|
|
25709
|
-
for (const teammate of parsedTeammates) {
|
|
25710
|
-
if (preResolvedTeammateProfiles[teammate.url]) {
|
|
25711
|
-
continue;
|
|
25712
|
-
}
|
|
25713
|
-
const profile = await profileResolver.resolveTeammateProfile(teammate.url);
|
|
25714
|
-
if (profile) {
|
|
25715
|
-
preResolvedTeammateProfiles[teammate.url] = profile;
|
|
25716
|
-
}
|
|
25717
|
-
}
|
|
25718
|
-
return {
|
|
25719
|
-
...requirements,
|
|
25720
|
-
_metadata: {
|
|
25721
|
-
...requirements._metadata,
|
|
25722
|
-
preResolvedTeammateProfiles,
|
|
25723
|
-
},
|
|
25724
|
-
};
|
|
25725
|
-
}
|
|
25726
|
-
catch (error) {
|
|
25727
|
-
console.warn('Failed to pre-resolve teammate profiles for TEAM commitment:', error);
|
|
25728
|
-
return requirements;
|
|
25729
|
-
}
|
|
25730
|
-
}
|
|
25731
|
-
/**
|
|
25732
|
-
* Clones the metadata bucket used to cache teammate profiles resolved ahead of TEAM commitment application.
|
|
25733
|
-
*
|
|
25734
|
-
* @param metadata - Current requirements metadata.
|
|
25735
|
-
* @returns Mutable copy of the cached teammate profile map.
|
|
25736
|
-
*
|
|
25737
|
-
* @private internal utility of `preResolveTeammateProfilesForTeamCommitment`
|
|
25738
|
-
*/
|
|
25739
|
-
function clonePreResolvedTeammateProfiles(metadata) {
|
|
25740
|
-
var _a;
|
|
25741
|
-
return {
|
|
25742
|
-
...((_a = metadata === null || metadata === void 0 ? void 0 : metadata.preResolvedTeammateProfiles) !== null && _a !== void 0 ? _a : {}),
|
|
25743
|
-
};
|
|
25744
|
-
}
|
|
25745
|
-
/**
|
|
25746
|
-
* Applies the registered commitment definition while isolating the failure handling from the main loop.
|
|
25747
|
-
*
|
|
25748
|
-
* @param requirements - Current requirements snapshot.
|
|
25749
|
-
* @param commitment - Commitment whose definition should be applied.
|
|
25750
|
-
* @param commitmentContent - Final content passed into the definition.
|
|
25751
|
-
* @returns Updated requirements, or the original requirements when the commitment fails.
|
|
25752
|
-
*
|
|
25753
|
-
* @private internal utility of `applyCommitmentsToRequirements`
|
|
25754
|
-
*/
|
|
25755
|
-
function applyCommitmentDefinitionSafely(requirements, commitment, commitmentContent) {
|
|
25756
|
-
const definition = getCommitmentDefinition(commitment.type);
|
|
25757
|
-
if (!definition) {
|
|
25758
|
-
return requirements;
|
|
25759
|
-
}
|
|
25760
|
-
try {
|
|
25761
|
-
return definition.applyToAgentModelRequirements(requirements, commitmentContent);
|
|
25762
|
-
}
|
|
25763
|
-
catch (error) {
|
|
25764
|
-
console.warn(`Failed to apply commitment ${commitment.type}:`, error);
|
|
25765
|
-
return requirements;
|
|
25766
|
-
}
|
|
25564
|
+
return appendExampleInteractions(requirements, parseResult);
|
|
25767
25565
|
}
|
|
25768
25566
|
/**
|
|
25769
25567
|
* Imports text files referenced by IMPORT commitments and appends their transformed content to the system message.
|
|
@@ -25771,7 +25569,7 @@ function applyCommitmentDefinitionSafely(requirements, commitment, commitmentCon
|
|
|
25771
25569
|
* @param requirements - Requirements possibly containing `importedFileUrls`.
|
|
25772
25570
|
* @returns Requirements with imported file content appended to the system message.
|
|
25773
25571
|
*
|
|
25774
|
-
* @private internal utility of `
|
|
25572
|
+
* @private internal utility of `augmentAgentModelRequirementsFromSource`
|
|
25775
25573
|
*/
|
|
25776
25574
|
async function importReferencedFiles(requirements) {
|
|
25777
25575
|
const importedFileUrls = requirements.importedFileUrls;
|
|
@@ -25857,7 +25655,7 @@ function normalizeImportedMimeType(mimeType) {
|
|
|
25857
25655
|
* @param agentSource - Original agent source used for MCP extraction.
|
|
25858
25656
|
* @returns Requirements with `mcpServers` set when MCP commitments are present.
|
|
25859
25657
|
*
|
|
25860
|
-
* @private internal utility of `
|
|
25658
|
+
* @private internal utility of `augmentAgentModelRequirementsFromSource`
|
|
25861
25659
|
*/
|
|
25862
25660
|
function appendMcpServers(requirements, agentSource) {
|
|
25863
25661
|
const mcpServers = extractMcpServers(agentSource);
|
|
@@ -25876,7 +25674,7 @@ function appendMcpServers(requirements, agentSource) {
|
|
|
25876
25674
|
* @param parseResult - Parsed source including non-commitment lines.
|
|
25877
25675
|
* @returns Requirements with the remaining prose appended to the system message.
|
|
25878
25676
|
*
|
|
25879
|
-
* @private internal utility of `
|
|
25677
|
+
* @private internal utility of `augmentAgentModelRequirementsFromSource`
|
|
25880
25678
|
*/
|
|
25881
25679
|
function appendNonCommitmentContent(requirements, parseResult) {
|
|
25882
25680
|
const nonCommitmentContent = getNonCommitmentContent(parseResult);
|
|
@@ -25919,7 +25717,7 @@ function isHorizontalLine(line) {
|
|
|
25919
25717
|
* @param parseResult - Parsed source used to recover initial message content.
|
|
25920
25718
|
* @returns Requirements with the example interaction block appended when examples exist.
|
|
25921
25719
|
*
|
|
25922
|
-
* @private internal utility of `
|
|
25720
|
+
* @private internal utility of `augmentAgentModelRequirementsFromSource`
|
|
25923
25721
|
*/
|
|
25924
25722
|
function appendExampleInteractions(requirements, parseResult) {
|
|
25925
25723
|
const exampleInteractionsContent = createExampleInteractionsContent(parseResult, requirements.samples);
|
|
@@ -25965,47 +25763,226 @@ function collectExampleInteractionLines(parseResult, samples) {
|
|
|
25965
25763
|
examples.push(`User: ${sample.question}\nAgent: ${sample.answer}`);
|
|
25966
25764
|
}
|
|
25967
25765
|
}
|
|
25968
|
-
return examples;
|
|
25766
|
+
return examples;
|
|
25767
|
+
}
|
|
25768
|
+
/**
|
|
25769
|
+
* Appends a single system-message section using the same blank-line separation used throughout the original implementation.
|
|
25770
|
+
*
|
|
25771
|
+
* @param requirements - Current requirements snapshot.
|
|
25772
|
+
* @param section - Section content to append.
|
|
25773
|
+
* @returns Requirements with the additional system-message block appended.
|
|
25774
|
+
*
|
|
25775
|
+
* @private internal utility of `augmentAgentModelRequirementsFromSource`
|
|
25776
|
+
*/
|
|
25777
|
+
function appendSystemMessageSection(requirements, section) {
|
|
25778
|
+
return {
|
|
25779
|
+
...requirements,
|
|
25780
|
+
systemMessage: requirements.systemMessage + '\n\n' + section,
|
|
25781
|
+
};
|
|
25782
|
+
}
|
|
25783
|
+
/**
|
|
25784
|
+
* Mocked security check for imported files.
|
|
25785
|
+
*
|
|
25786
|
+
* @param urlOrPath - The URL or local path of the file to check.
|
|
25787
|
+
* @returns A promise that resolves if the file is considered safe.
|
|
25788
|
+
*
|
|
25789
|
+
* @private internal utility of `createImportedFileSystemMessage`
|
|
25790
|
+
*/
|
|
25791
|
+
async function mockedSecurityCheck(urlOrPath) {
|
|
25792
|
+
// TODO: Implement proper security checks
|
|
25793
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
25794
|
+
if (urlOrPath.includes('malicious')) {
|
|
25795
|
+
throw new Error(`Security check failed for: ${urlOrPath}`);
|
|
25796
|
+
}
|
|
25797
|
+
}
|
|
25798
|
+
/**
|
|
25799
|
+
* Checks whether the given MIME type belongs to a binary file.
|
|
25800
|
+
*
|
|
25801
|
+
* @param mimeType - The MIME type to check.
|
|
25802
|
+
* @returns `true` when the MIME type is treated as binary.
|
|
25803
|
+
*
|
|
25804
|
+
* @private internal utility of `createImportedFileSystemMessage`
|
|
25805
|
+
*/
|
|
25806
|
+
function isBinaryMimeType(mimeType) {
|
|
25807
|
+
return BINARY_MIME_TYPE_PREFIXES.some((prefix) => mimeType.startsWith(prefix));
|
|
25808
|
+
}
|
|
25809
|
+
|
|
25810
|
+
/**
|
|
25811
|
+
* Parses parameters from text using both supported notations:
|
|
25812
|
+
* 1. @Parameter - single word parameter starting with @
|
|
25813
|
+
* 2. {parameterName} or {parameter with multiple words} or {parameterName: description text}
|
|
25814
|
+
*
|
|
25815
|
+
* Both notations represent the same syntax feature - parameters
|
|
25816
|
+
*
|
|
25817
|
+
* @param text - Text to extract parameters from
|
|
25818
|
+
* @returns Array of parsed parameters with unified representation
|
|
25819
|
+
*
|
|
25820
|
+
* @public exported from `@promptbook/core`
|
|
25821
|
+
*/
|
|
25822
|
+
function parseParameters(text) {
|
|
25823
|
+
const parameters = [];
|
|
25824
|
+
// [🧠] Parameter syntax parsing - unified approach for two different notations of the same syntax feature
|
|
25825
|
+
// The Book language supports parameters in two different notations but they represent the same concept
|
|
25826
|
+
// Extract @Parameter notation (single word parameters starting with @)
|
|
25827
|
+
const atParameterRegex = /@[\w\u00C0-\u017F\u0100-\u024F\u1E00-\u1EFF]+/gim;
|
|
25828
|
+
text.replace(atParameterRegex, (match) => {
|
|
25829
|
+
const parameterName = match.slice(1); // Remove the @ symbol
|
|
25830
|
+
parameters.push({
|
|
25831
|
+
text: match,
|
|
25832
|
+
notation: 'at',
|
|
25833
|
+
name: parameterName,
|
|
25834
|
+
});
|
|
25835
|
+
return match;
|
|
25836
|
+
});
|
|
25837
|
+
// Extract {parameter} notation (parameters in braces)
|
|
25838
|
+
const braceParameterRegex = /\{([^}]+)\}/gim;
|
|
25839
|
+
text.replace(braceParameterRegex, (match, content) => {
|
|
25840
|
+
// Check if the parameter has a description (parameterName: description)
|
|
25841
|
+
const colonIndex = content.indexOf(':');
|
|
25842
|
+
if (colonIndex !== -1) {
|
|
25843
|
+
const name = content.substring(0, colonIndex).trim();
|
|
25844
|
+
const description = content.substring(colonIndex + 1).trim();
|
|
25845
|
+
parameters.push({
|
|
25846
|
+
text: match,
|
|
25847
|
+
notation: 'brace',
|
|
25848
|
+
name,
|
|
25849
|
+
description,
|
|
25850
|
+
});
|
|
25851
|
+
}
|
|
25852
|
+
else {
|
|
25853
|
+
// Simple parameter without description
|
|
25854
|
+
parameters.push({
|
|
25855
|
+
text: match,
|
|
25856
|
+
notation: 'brace',
|
|
25857
|
+
name: content.trim(),
|
|
25858
|
+
});
|
|
25859
|
+
}
|
|
25860
|
+
return match;
|
|
25861
|
+
});
|
|
25862
|
+
// Remove duplicates based on name (keep the first occurrence)
|
|
25863
|
+
const uniqueParameters = parameters.filter((parameter, index, array) => {
|
|
25864
|
+
return array.findIndex((parameterItem) => parameterItem.name === parameter.name) === index;
|
|
25865
|
+
});
|
|
25866
|
+
return uniqueParameters;
|
|
25867
|
+
}
|
|
25868
|
+
|
|
25869
|
+
/**
|
|
25870
|
+
* DELETE-like commitment types that invalidate earlier tagged commitments.
|
|
25871
|
+
*
|
|
25872
|
+
* @private internal constant of `filterCommitmentsForAgentModelRequirements`
|
|
25873
|
+
*/
|
|
25874
|
+
const DELETE_COMMITMENT_TYPES = new Set(['DELETE', 'CANCEL', 'DISCARD', 'REMOVE']);
|
|
25875
|
+
/**
|
|
25876
|
+
* Commitments whose earlier occurrences are overwritten by the last occurrence in source order.
|
|
25877
|
+
*
|
|
25878
|
+
* @private internal constant of `filterCommitmentsForAgentModelRequirements`
|
|
25879
|
+
*/
|
|
25880
|
+
const OVERWRITTEN_COMMITMENT_GROUP_BY_TYPE = new Map([
|
|
25881
|
+
['GOAL', 'GOAL'],
|
|
25882
|
+
['GOALS', 'GOAL'],
|
|
25883
|
+
]);
|
|
25884
|
+
/**
|
|
25885
|
+
* Applies the commitment filtering rules used before commitment definitions are executed.
|
|
25886
|
+
*
|
|
25887
|
+
* @param commitments - Parsed commitments in original source order.
|
|
25888
|
+
* @returns Commitments after DELETE-like invalidation and overwritten-goal filtering.
|
|
25889
|
+
*
|
|
25890
|
+
* @private function of `createAgentModelRequirementsWithCommitments`
|
|
25891
|
+
*/
|
|
25892
|
+
function filterCommitmentsForAgentModelRequirements(commitments) {
|
|
25893
|
+
return filterOverwrittenCommitments(filterDeletedCommitments(commitments));
|
|
25894
|
+
}
|
|
25895
|
+
/**
|
|
25896
|
+
* Removes earlier commitments that are overwritten by later commitments of the same semantic group.
|
|
25897
|
+
*
|
|
25898
|
+
* @param commitments - Parsed commitments after DELETE-like filtering.
|
|
25899
|
+
* @returns Commitments with overwritten entries removed while preserving source order.
|
|
25900
|
+
*
|
|
25901
|
+
* @private internal utility of `filterCommitmentsForAgentModelRequirements`
|
|
25902
|
+
*/
|
|
25903
|
+
function filterOverwrittenCommitments(commitments) {
|
|
25904
|
+
const seenOverwriteGroups = new Set();
|
|
25905
|
+
const keptCommitments = [];
|
|
25906
|
+
for (let index = commitments.length - 1; index >= 0; index--) {
|
|
25907
|
+
const commitment = commitments[index];
|
|
25908
|
+
const overwriteGroup = OVERWRITTEN_COMMITMENT_GROUP_BY_TYPE.get(commitment.type);
|
|
25909
|
+
if (!overwriteGroup) {
|
|
25910
|
+
keptCommitments.push(commitment);
|
|
25911
|
+
continue;
|
|
25912
|
+
}
|
|
25913
|
+
if (seenOverwriteGroups.has(overwriteGroup)) {
|
|
25914
|
+
continue;
|
|
25915
|
+
}
|
|
25916
|
+
seenOverwriteGroups.add(overwriteGroup);
|
|
25917
|
+
keptCommitments.push(commitment);
|
|
25918
|
+
}
|
|
25919
|
+
return keptCommitments.reverse();
|
|
25920
|
+
}
|
|
25921
|
+
/**
|
|
25922
|
+
* Applies DELETE-like invalidation commitments and returns only commitments that should continue through the pipeline.
|
|
25923
|
+
*
|
|
25924
|
+
* @param commitments - Parsed commitments in original source order.
|
|
25925
|
+
* @returns Filtered commitments with earlier deleted items removed.
|
|
25926
|
+
*
|
|
25927
|
+
* @private internal utility of `filterCommitmentsForAgentModelRequirements`
|
|
25928
|
+
*/
|
|
25929
|
+
function filterDeletedCommitments(commitments) {
|
|
25930
|
+
const filteredCommitments = [];
|
|
25931
|
+
for (const commitment of commitments) {
|
|
25932
|
+
if (!isDeleteCommitmentType(commitment.type)) {
|
|
25933
|
+
filteredCommitments.push(commitment);
|
|
25934
|
+
continue;
|
|
25935
|
+
}
|
|
25936
|
+
const targetParameterNames = getCommitmentParameterNames(commitment.content);
|
|
25937
|
+
if (targetParameterNames.length === 0) {
|
|
25938
|
+
continue;
|
|
25939
|
+
}
|
|
25940
|
+
for (let index = filteredCommitments.length - 1; index >= 0; index--) {
|
|
25941
|
+
const previousCommitment = filteredCommitments[index];
|
|
25942
|
+
const previousParameterNames = getCommitmentParameterNames(previousCommitment.content);
|
|
25943
|
+
const isTargeted = previousParameterNames.some((parameterName) => targetParameterNames.includes(parameterName));
|
|
25944
|
+
if (isTargeted) {
|
|
25945
|
+
filteredCommitments.splice(index, 1);
|
|
25946
|
+
}
|
|
25947
|
+
}
|
|
25948
|
+
}
|
|
25949
|
+
return filteredCommitments;
|
|
25969
25950
|
}
|
|
25970
25951
|
/**
|
|
25971
|
-
*
|
|
25952
|
+
* Checks whether a commitment type behaves like DELETE and therefore invalidates earlier tagged commitments.
|
|
25972
25953
|
*
|
|
25973
|
-
* @param
|
|
25974
|
-
* @
|
|
25975
|
-
* @returns Requirements with the additional system-message block appended.
|
|
25954
|
+
* @param commitmentType - Commitment type to check.
|
|
25955
|
+
* @returns `true` when the commitment removes prior tagged commitments.
|
|
25976
25956
|
*
|
|
25977
|
-
* @private internal utility of `
|
|
25957
|
+
* @private internal utility of `filterDeletedCommitments`
|
|
25978
25958
|
*/
|
|
25979
|
-
function
|
|
25980
|
-
return
|
|
25981
|
-
...requirements,
|
|
25982
|
-
systemMessage: requirements.systemMessage + '\n\n' + section,
|
|
25983
|
-
};
|
|
25959
|
+
function isDeleteCommitmentType(commitmentType) {
|
|
25960
|
+
return DELETE_COMMITMENT_TYPES.has(commitmentType);
|
|
25984
25961
|
}
|
|
25985
25962
|
/**
|
|
25986
|
-
*
|
|
25963
|
+
* Extracts normalized parameter names used for DELETE-like invalidation matching.
|
|
25987
25964
|
*
|
|
25988
|
-
* @param
|
|
25989
|
-
* @returns
|
|
25965
|
+
* @param content - Commitment content to parse.
|
|
25966
|
+
* @returns Lower-cased non-empty parameter names.
|
|
25990
25967
|
*
|
|
25991
|
-
* @private internal utility of `
|
|
25968
|
+
* @private internal utility of `filterDeletedCommitments`
|
|
25992
25969
|
*/
|
|
25993
|
-
function
|
|
25994
|
-
return
|
|
25995
|
-
|
|
25996
|
-
|
|
25997
|
-
};
|
|
25970
|
+
function getCommitmentParameterNames(content) {
|
|
25971
|
+
return parseParameters(content)
|
|
25972
|
+
.map((parameter) => parameter.name.trim().toLowerCase())
|
|
25973
|
+
.filter(Boolean);
|
|
25998
25974
|
}
|
|
25975
|
+
|
|
25999
25976
|
/**
|
|
26000
|
-
*
|
|
25977
|
+
* Converts staged inline knowledge files into the final knowledge source URLs stored on requirements.
|
|
26001
25978
|
*
|
|
26002
25979
|
* @param requirements - Current requirements snapshot.
|
|
26003
25980
|
* @param uploader - Optional uploader for inline knowledge files.
|
|
26004
25981
|
* @returns Requirements with inline knowledge converted into upload URLs or data URLs.
|
|
26005
25982
|
*
|
|
26006
|
-
* @private
|
|
25983
|
+
* @private function of `createAgentModelRequirementsWithCommitments`
|
|
26007
25984
|
*/
|
|
26008
|
-
async function
|
|
25985
|
+
async function materializeInlineKnowledgeSources(requirements, uploader) {
|
|
26009
25986
|
var _a;
|
|
26010
25987
|
const inlineSources = extractInlineKnowledgeSources(requirements._metadata);
|
|
26011
25988
|
if (inlineSources.length === 0) {
|
|
@@ -26031,7 +26008,7 @@ async function applyPendingInlineKnowledgeSources(requirements, uploader) {
|
|
|
26031
26008
|
* @param uploader - Upload implementation provided by the caller.
|
|
26032
26009
|
* @returns Uploaded knowledge URL or a legacy data URL fallback.
|
|
26033
26010
|
*
|
|
26034
|
-
* @private internal utility of `
|
|
26011
|
+
* @private internal utility of `materializeInlineKnowledgeSources`
|
|
26035
26012
|
*/
|
|
26036
26013
|
async function uploadInlineKnowledgeSourceWithFallback(inlineSource, uploader) {
|
|
26037
26014
|
try {
|
|
@@ -26051,7 +26028,7 @@ async function uploadInlineKnowledgeSourceWithFallback(inlineSource, uploader) {
|
|
|
26051
26028
|
* @param metadata - Current requirements metadata.
|
|
26052
26029
|
* @returns Inline knowledge files collected during commitment application.
|
|
26053
26030
|
*
|
|
26054
|
-
* @private internal utility of `
|
|
26031
|
+
* @private internal utility of `materializeInlineKnowledgeSources`
|
|
26055
26032
|
*/
|
|
26056
26033
|
function extractInlineKnowledgeSources(metadata) {
|
|
26057
26034
|
if (!metadata) {
|
|
@@ -26066,7 +26043,7 @@ function extractInlineKnowledgeSources(metadata) {
|
|
|
26066
26043
|
* @param metadata - Current requirements metadata.
|
|
26067
26044
|
* @returns Metadata without the temporary inline knowledge staging field.
|
|
26068
26045
|
*
|
|
26069
|
-
* @private internal utility of `
|
|
26046
|
+
* @private internal utility of `materializeInlineKnowledgeSources`
|
|
26070
26047
|
*/
|
|
26071
26048
|
function stripInlineKnowledgeMetadata(metadata) {
|
|
26072
26049
|
if (!metadata || !Object.prototype.hasOwnProperty.call(metadata, 'inlineKnowledgeSources')) {
|
|
@@ -26075,69 +26052,90 @@ function stripInlineKnowledgeMetadata(metadata) {
|
|
|
26075
26052
|
const { inlineKnowledgeSources: _unusedInlineKnowledgeSources, ...rest } = metadata;
|
|
26076
26053
|
return Object.keys(rest).length > 0 ? rest : undefined;
|
|
26077
26054
|
}
|
|
26055
|
+
|
|
26078
26056
|
/**
|
|
26079
|
-
*
|
|
26057
|
+
* Removes single-hash comment lines (`# Comment`) from a system message
|
|
26058
|
+
* This is used to clean up the final system message before sending it to the AI model
|
|
26059
|
+
* while preserving the original content with comments in metadata
|
|
26080
26060
|
*
|
|
26081
|
-
* @param
|
|
26082
|
-
* @returns
|
|
26061
|
+
* @param systemMessage The system message that may contain comment lines
|
|
26062
|
+
* @returns The system message with single-hash comment lines removed
|
|
26083
26063
|
*
|
|
26084
|
-
* @private
|
|
26064
|
+
* @private - TODO: [🧠] Maybe should be public?
|
|
26085
26065
|
*/
|
|
26086
|
-
|
|
26087
|
-
|
|
26088
|
-
|
|
26089
|
-
if (urlOrPath.includes('malicious')) {
|
|
26090
|
-
throw new Error(`Security check failed for: ${urlOrPath}`);
|
|
26066
|
+
function removeCommentsFromSystemMessage(systemMessage) {
|
|
26067
|
+
if (!systemMessage) {
|
|
26068
|
+
return systemMessage;
|
|
26091
26069
|
}
|
|
26070
|
+
const lines = systemMessage.split(/\r?\n/);
|
|
26071
|
+
const filteredLines = lines.filter((line) => {
|
|
26072
|
+
const trimmedLine = line.trim();
|
|
26073
|
+
// Remove only single-hash comment markers (`# Comment`) and keep markdown headings (`## Heading`).
|
|
26074
|
+
return !/^#(?!#)\s/.test(trimmedLine);
|
|
26075
|
+
});
|
|
26076
|
+
return filteredLines.join('\n').trim();
|
|
26092
26077
|
}
|
|
26078
|
+
|
|
26093
26079
|
/**
|
|
26094
|
-
*
|
|
26080
|
+
* Creates agent model requirements by parsing commitments, applying them in source order,
|
|
26081
|
+
* and finalizing derived sections such as imports, example interactions, and inline knowledge uploads.
|
|
26095
26082
|
*
|
|
26096
|
-
* @param
|
|
26097
|
-
* @
|
|
26083
|
+
* @param agentSource - Agent source book to parse.
|
|
26084
|
+
* @param modelName - Optional override for the agent model name.
|
|
26085
|
+
* @param options - Additional options such as reference and teammate resolvers.
|
|
26086
|
+
* @returns Fully prepared model requirements for the parsed agent source.
|
|
26098
26087
|
*
|
|
26099
|
-
* @private internal utility of `
|
|
26088
|
+
* @private internal utility of `createAgentModelRequirements`
|
|
26100
26089
|
*/
|
|
26101
|
-
function
|
|
26102
|
-
|
|
26090
|
+
async function createAgentModelRequirementsWithCommitments(agentSource, modelName, options) {
|
|
26091
|
+
const parseResult = parseAgentSourceWithCommitments(agentSource);
|
|
26092
|
+
const filteredCommitments = filterCommitmentsForAgentModelRequirements(parseResult.commitments);
|
|
26093
|
+
let requirements = createInitialAgentModelRequirements(parseResult.agentName, modelName);
|
|
26094
|
+
requirements = await applyCommitmentsToAgentModelRequirements(requirements, filteredCommitments, options);
|
|
26095
|
+
requirements = aggregateUseCommitmentSystemMessages(requirements, filteredCommitments);
|
|
26096
|
+
requirements = await augmentAgentModelRequirementsFromSource(requirements, parseResult, agentSource);
|
|
26097
|
+
requirements = await materializeInlineKnowledgeSources(requirements, options === null || options === void 0 ? void 0 : options.inlineKnowledgeSourceUploader);
|
|
26098
|
+
return finalizeRequirements(requirements);
|
|
26103
26099
|
}
|
|
26104
|
-
|
|
26105
26100
|
/**
|
|
26106
|
-
*
|
|
26107
|
-
*
|
|
26108
|
-
* The returned value is lowercased and stripped to hostname only
|
|
26109
|
-
* (protocol, path, query, hash, and port are removed).
|
|
26101
|
+
* Creates the initial requirements object with the parsed agent name stored in metadata and an optional model override.
|
|
26110
26102
|
*
|
|
26111
|
-
* @param
|
|
26112
|
-
* @
|
|
26103
|
+
* @param agentName - Parsed agent name from the source prelude.
|
|
26104
|
+
* @param modelName - Optional explicit model name override.
|
|
26105
|
+
* @returns Initial requirements before any commitment is applied.
|
|
26113
26106
|
*
|
|
26114
|
-
* @private utility
|
|
26107
|
+
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
26115
26108
|
*/
|
|
26116
|
-
function
|
|
26117
|
-
const
|
|
26118
|
-
|
|
26119
|
-
|
|
26120
|
-
|
|
26121
|
-
|
|
26122
|
-
|
|
26123
|
-
|
|
26124
|
-
|
|
26125
|
-
|
|
26126
|
-
|
|
26127
|
-
catch (_a) {
|
|
26128
|
-
return null;
|
|
26109
|
+
function createInitialAgentModelRequirements(agentName, modelName) {
|
|
26110
|
+
const initialRequirements = createBasicAgentModelRequirements(agentName);
|
|
26111
|
+
const requirementsWithMetadata = {
|
|
26112
|
+
...initialRequirements,
|
|
26113
|
+
_metadata: {
|
|
26114
|
+
...initialRequirements._metadata,
|
|
26115
|
+
agentName,
|
|
26116
|
+
},
|
|
26117
|
+
};
|
|
26118
|
+
if (!modelName) {
|
|
26119
|
+
return requirementsWithMetadata;
|
|
26129
26120
|
}
|
|
26121
|
+
return {
|
|
26122
|
+
...requirementsWithMetadata,
|
|
26123
|
+
modelName,
|
|
26124
|
+
};
|
|
26130
26125
|
}
|
|
26131
26126
|
/**
|
|
26132
|
-
*
|
|
26127
|
+
* Performs the final system-message cleanup pass after all other augmentation steps are complete.
|
|
26133
26128
|
*
|
|
26134
|
-
* @param
|
|
26135
|
-
* @returns
|
|
26129
|
+
* @param requirements - Fully built requirements before final cleanup.
|
|
26130
|
+
* @returns Requirements with comment lines removed from the final system message.
|
|
26136
26131
|
*
|
|
26137
|
-
* @private utility
|
|
26132
|
+
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
26138
26133
|
*/
|
|
26139
|
-
function
|
|
26140
|
-
return
|
|
26134
|
+
function finalizeRequirements(requirements) {
|
|
26135
|
+
return {
|
|
26136
|
+
...requirements,
|
|
26137
|
+
systemMessage: removeCommentsFromSystemMessage(requirements.systemMessage),
|
|
26138
|
+
};
|
|
26141
26139
|
}
|
|
26142
26140
|
|
|
26143
26141
|
/**
|
|
@@ -26162,126 +26160,16 @@ function createDefaultAgentName(agentSource) {
|
|
|
26162
26160
|
}
|
|
26163
26161
|
|
|
26164
26162
|
/**
|
|
26165
|
-
*
|
|
26166
|
-
*
|
|
26167
|
-
* There are 2 similar functions:
|
|
26168
|
-
* - `parseAgentSource` which is a lightweight parser for agent source, it parses basic information and its purpose is to be quick and synchronous. The commitments there are hardcoded.
|
|
26169
|
-
* - `createAgentModelRequirements` which is an asynchronous function that creates model requirements it applies each commitment one by one and works asynchronously.
|
|
26170
|
-
*
|
|
26171
|
-
* @public exported from `@promptbook/core`
|
|
26172
|
-
*/
|
|
26173
|
-
function parseAgentSource(agentSource) {
|
|
26174
|
-
const parseResult = parseAgentSourceWithCommitments(agentSource);
|
|
26175
|
-
const resolvedAgentName = parseResult.agentName || createDefaultAgentName(agentSource);
|
|
26176
|
-
const personaDescription = extractAgentProfileText(parseResult.commitments);
|
|
26177
|
-
const initialMessage = extractInitialMessage(parseResult.commitments);
|
|
26178
|
-
const parsedProfile = extractParsedAgentProfile(parseResult.commitments);
|
|
26179
|
-
ensureMetaFullname(parsedProfile.meta, resolvedAgentName);
|
|
26180
|
-
return {
|
|
26181
|
-
agentName: normalizeAgentName(resolvedAgentName),
|
|
26182
|
-
agentHash: computeAgentHash(agentSource),
|
|
26183
|
-
permanentId: parsedProfile.meta.id,
|
|
26184
|
-
personaDescription,
|
|
26185
|
-
initialMessage,
|
|
26186
|
-
meta: parsedProfile.meta,
|
|
26187
|
-
links: parsedProfile.links,
|
|
26188
|
-
parameters: parseParameters(agentSource),
|
|
26189
|
-
capabilities: parsedProfile.capabilities,
|
|
26190
|
-
samples: parsedProfile.samples,
|
|
26191
|
-
knowledgeSources: parsedProfile.knowledgeSources,
|
|
26192
|
-
};
|
|
26193
|
-
}
|
|
26194
|
-
/**
|
|
26195
|
-
* Static capability descriptors for commitments that map one-to-one to a visible capability.
|
|
26196
|
-
*
|
|
26197
|
-
* @private internal utility of `parseAgentSource`
|
|
26198
|
-
*/
|
|
26199
|
-
const SIMPLE_CAPABILITY_BY_COMMITMENT_TYPE = {
|
|
26200
|
-
'USE BROWSER': {
|
|
26201
|
-
type: 'browser',
|
|
26202
|
-
label: 'Browser',
|
|
26203
|
-
iconName: 'Globe',
|
|
26204
|
-
},
|
|
26205
|
-
'USE SEARCH ENGINE': {
|
|
26206
|
-
type: 'search-engine',
|
|
26207
|
-
label: 'Internet',
|
|
26208
|
-
iconName: 'Search',
|
|
26209
|
-
},
|
|
26210
|
-
'USE SEARCH': {
|
|
26211
|
-
type: 'search-engine',
|
|
26212
|
-
label: 'Internet',
|
|
26213
|
-
iconName: 'Search',
|
|
26214
|
-
},
|
|
26215
|
-
'USE DEEPSEARCH': {
|
|
26216
|
-
type: 'search-engine',
|
|
26217
|
-
label: 'DeepSearch',
|
|
26218
|
-
iconName: 'Search',
|
|
26219
|
-
},
|
|
26220
|
-
'USE TIME': {
|
|
26221
|
-
type: 'time',
|
|
26222
|
-
label: 'Time',
|
|
26223
|
-
iconName: 'Clock',
|
|
26224
|
-
},
|
|
26225
|
-
'USE TIMEOUT': {
|
|
26226
|
-
type: 'timeout',
|
|
26227
|
-
label: 'Timers',
|
|
26228
|
-
iconName: 'Clock',
|
|
26229
|
-
},
|
|
26230
|
-
'USE USER LOCATION': {
|
|
26231
|
-
type: 'user-location',
|
|
26232
|
-
label: 'User location',
|
|
26233
|
-
iconName: 'MapPin',
|
|
26234
|
-
},
|
|
26235
|
-
'USE EMAIL': {
|
|
26236
|
-
type: 'email',
|
|
26237
|
-
label: 'Email',
|
|
26238
|
-
iconName: 'Mail',
|
|
26239
|
-
},
|
|
26240
|
-
'USE POPUP': {
|
|
26241
|
-
type: 'popup',
|
|
26242
|
-
label: 'Popup',
|
|
26243
|
-
iconName: 'SquareArrowOutUpRight',
|
|
26244
|
-
},
|
|
26245
|
-
'USE IMAGE GENERATOR': {
|
|
26246
|
-
type: 'image-generator',
|
|
26247
|
-
label: 'Image Generator',
|
|
26248
|
-
iconName: 'Image',
|
|
26249
|
-
},
|
|
26250
|
-
'USE PRIVACY': {
|
|
26251
|
-
type: 'privacy',
|
|
26252
|
-
label: 'Privacy',
|
|
26253
|
-
iconName: 'Shield',
|
|
26254
|
-
},
|
|
26255
|
-
'USE CALENDAR': {
|
|
26256
|
-
type: 'calendar',
|
|
26257
|
-
label: 'Calendar',
|
|
26258
|
-
iconName: 'Calendar',
|
|
26259
|
-
},
|
|
26260
|
-
};
|
|
26261
|
-
/**
|
|
26262
|
-
* Dedicated handlers for META-style commitments that directly map onto parsed meta fields.
|
|
26263
|
-
*
|
|
26264
|
-
* @private internal utility of `parseAgentSource`
|
|
26265
|
-
*/
|
|
26266
|
-
const META_COMMITMENT_APPLIERS = {
|
|
26267
|
-
'META AVATAR': applyMetaAvatarContent,
|
|
26268
|
-
'META LINK': applyMetaLinkContent,
|
|
26269
|
-
'META DOMAIN': applyMetaDomainContent,
|
|
26270
|
-
'META IMAGE': applyMetaImageContent,
|
|
26271
|
-
'META DESCRIPTION': applyMetaDescriptionContent,
|
|
26272
|
-
'META DISCLAIMER': applyMetaDisclaimerContent,
|
|
26273
|
-
'META INPUT PLACEHOLDER': applyMetaInputPlaceholderContent,
|
|
26274
|
-
'MESSAGE SUFFIX': applyMessageSuffixContent,
|
|
26275
|
-
'META COLOR': applyMetaColorContent,
|
|
26276
|
-
'META FONT': applyMetaFontContent,
|
|
26277
|
-
'META VOICE': applyMetaVoiceContent,
|
|
26278
|
-
};
|
|
26279
|
-
/**
|
|
26280
|
-
* Detects local slash-based references used by FROM and IMPORT commitments.
|
|
26163
|
+
* Ensures the parsed profile always exposes a fullname value.
|
|
26281
26164
|
*
|
|
26282
26165
|
* @private internal utility of `parseAgentSource`
|
|
26283
26166
|
*/
|
|
26284
|
-
|
|
26167
|
+
function ensureMetaFullname(meta, fallbackFullname) {
|
|
26168
|
+
if (!meta.fullname) {
|
|
26169
|
+
meta.fullname = fallbackFullname;
|
|
26170
|
+
}
|
|
26171
|
+
}
|
|
26172
|
+
|
|
26285
26173
|
/**
|
|
26286
26174
|
* Resolves the public agent profile text from the last GOAL/GOALS commitment,
|
|
26287
26175
|
* falling back to the deprecated PERSONA/PERSONAE commitments when no goal exists.
|
|
@@ -26311,6 +26199,7 @@ function extractAgentProfileText(commitments) {
|
|
|
26311
26199
|
}
|
|
26312
26200
|
return null;
|
|
26313
26201
|
}
|
|
26202
|
+
|
|
26314
26203
|
/**
|
|
26315
26204
|
* Resolves the last INITIAL MESSAGE commitment, which is the public initial-message value.
|
|
26316
26205
|
*
|
|
@@ -26325,48 +26214,189 @@ function extractInitialMessage(commitments) {
|
|
|
26325
26214
|
}
|
|
26326
26215
|
return initialMessage;
|
|
26327
26216
|
}
|
|
26217
|
+
|
|
26328
26218
|
/**
|
|
26329
|
-
*
|
|
26219
|
+
* Normalizes a domain-like string into a comparable hostname form.
|
|
26330
26220
|
*
|
|
26331
|
-
*
|
|
26221
|
+
* The returned value is lowercased and stripped to hostname only
|
|
26222
|
+
* (protocol, path, query, hash, and port are removed).
|
|
26223
|
+
*
|
|
26224
|
+
* @param rawDomain - Raw domain value (for example `my-agent.com` or `https://my-agent.com/path`).
|
|
26225
|
+
* @returns Normalized hostname or `null` when the value cannot be normalized.
|
|
26226
|
+
*
|
|
26227
|
+
* @private utility for host/domain matching
|
|
26332
26228
|
*/
|
|
26333
|
-
function
|
|
26334
|
-
const
|
|
26335
|
-
|
|
26336
|
-
|
|
26337
|
-
|
|
26338
|
-
|
|
26339
|
-
|
|
26340
|
-
|
|
26341
|
-
|
|
26342
|
-
|
|
26343
|
-
|
|
26344
|
-
|
|
26229
|
+
function normalizeDomainForMatching(rawDomain) {
|
|
26230
|
+
const trimmedDomain = rawDomain.trim();
|
|
26231
|
+
if (!trimmedDomain) {
|
|
26232
|
+
return null;
|
|
26233
|
+
}
|
|
26234
|
+
const candidateUrl = hasHttpProtocol(trimmedDomain) ? trimmedDomain : `https://${trimmedDomain}`;
|
|
26235
|
+
try {
|
|
26236
|
+
const parsedUrl = new URL(candidateUrl);
|
|
26237
|
+
const normalizedHostname = parsedUrl.hostname.trim().toLowerCase();
|
|
26238
|
+
return normalizedHostname || null;
|
|
26239
|
+
}
|
|
26240
|
+
catch (_a) {
|
|
26241
|
+
return null;
|
|
26345
26242
|
}
|
|
26346
|
-
return {
|
|
26347
|
-
meta: state.meta,
|
|
26348
|
-
links: state.links,
|
|
26349
|
-
capabilities: state.capabilities,
|
|
26350
|
-
samples: state.samples,
|
|
26351
|
-
knowledgeSources: state.knowledgeSources,
|
|
26352
|
-
};
|
|
26353
26243
|
}
|
|
26354
26244
|
/**
|
|
26355
|
-
*
|
|
26245
|
+
* Checks whether the value already includes an HTTP(S) protocol prefix.
|
|
26246
|
+
*
|
|
26247
|
+
* @param value - Raw value to inspect.
|
|
26248
|
+
* @returns True when the value starts with `http://` or `https://`.
|
|
26249
|
+
*
|
|
26250
|
+
* @private utility for host/domain matching
|
|
26251
|
+
*/
|
|
26252
|
+
function hasHttpProtocol(value) {
|
|
26253
|
+
return value.startsWith('http://') || value.startsWith('https://');
|
|
26254
|
+
}
|
|
26255
|
+
|
|
26256
|
+
/**
|
|
26257
|
+
* Dedicated handlers for META-style commitments that directly map onto parsed meta fields.
|
|
26258
|
+
*/
|
|
26259
|
+
const META_COMMITMENT_APPLIERS = {
|
|
26260
|
+
'META AVATAR': applyMetaAvatarContent,
|
|
26261
|
+
'META LINK': applyMetaLinkContent,
|
|
26262
|
+
'META DOMAIN': applyMetaDomainContent,
|
|
26263
|
+
'META IMAGE': applyMetaImageContent,
|
|
26264
|
+
'META DESCRIPTION': applyMetaDescriptionContent,
|
|
26265
|
+
'META DISCLAIMER': applyMetaDisclaimerContent,
|
|
26266
|
+
'META INPUT PLACEHOLDER': applyMetaInputPlaceholderContent,
|
|
26267
|
+
'MESSAGE SUFFIX': applyMessageSuffixContent,
|
|
26268
|
+
'META COLOR': applyMetaColorContent,
|
|
26269
|
+
'META FONT': applyMetaFontContent,
|
|
26270
|
+
'META VOICE': applyMetaVoiceContent,
|
|
26271
|
+
};
|
|
26272
|
+
/**
|
|
26273
|
+
* Applies META-style commitments that mutate parsed profile metadata.
|
|
26356
26274
|
*
|
|
26357
26275
|
* @private internal utility of `parseAgentSource`
|
|
26358
26276
|
*/
|
|
26359
|
-
function
|
|
26360
|
-
|
|
26277
|
+
function applyMetaCommitment(state, commitment) {
|
|
26278
|
+
const applyMetaContent = META_COMMITMENT_APPLIERS[commitment.type];
|
|
26279
|
+
if (applyMetaContent) {
|
|
26280
|
+
applyMetaContent(state, commitment.content);
|
|
26361
26281
|
return;
|
|
26362
26282
|
}
|
|
26363
|
-
|
|
26364
|
-
|
|
26365
|
-
|
|
26283
|
+
if (commitment.type === 'META') {
|
|
26284
|
+
applyGenericMetaCommitment(state, commitment.content);
|
|
26285
|
+
}
|
|
26286
|
+
}
|
|
26287
|
+
/**
|
|
26288
|
+
* Applies the generic META commitment form (`META TYPE value`).
|
|
26289
|
+
*/
|
|
26290
|
+
function applyGenericMetaCommitment(state, content) {
|
|
26291
|
+
const metaTypeRaw = content.split(' ')[0] || 'NONE';
|
|
26292
|
+
const metaValue = spaceTrim$1(content.substring(metaTypeRaw.length));
|
|
26293
|
+
if (metaTypeRaw === 'LINK') {
|
|
26294
|
+
state.links.push(metaValue);
|
|
26295
|
+
}
|
|
26296
|
+
if (metaTypeRaw.toUpperCase() === 'AVATAR') {
|
|
26297
|
+
applyMetaAvatarContent(state, metaValue);
|
|
26366
26298
|
return;
|
|
26367
26299
|
}
|
|
26368
|
-
|
|
26300
|
+
const metaType = normalizeTo_camelCase(metaTypeRaw);
|
|
26301
|
+
state.meta[metaType] = metaValue;
|
|
26302
|
+
}
|
|
26303
|
+
/**
|
|
26304
|
+
* Applies META AVATAR content into the canonical `meta.avatar` field.
|
|
26305
|
+
*/
|
|
26306
|
+
function applyMetaAvatarContent(state, content) {
|
|
26307
|
+
const avatarVisualId = resolveAvatarVisualId(content);
|
|
26308
|
+
if (avatarVisualId) {
|
|
26309
|
+
state.meta.avatar = avatarVisualId;
|
|
26310
|
+
return;
|
|
26311
|
+
}
|
|
26312
|
+
delete state.meta.avatar;
|
|
26313
|
+
}
|
|
26314
|
+
/**
|
|
26315
|
+
* Applies META LINK content into links and the canonical `meta.link` field.
|
|
26316
|
+
*/
|
|
26317
|
+
function applyMetaLinkContent(state, content) {
|
|
26318
|
+
const linkValue = spaceTrim$1(content);
|
|
26319
|
+
state.links.push(linkValue);
|
|
26320
|
+
state.meta.link = linkValue;
|
|
26321
|
+
}
|
|
26322
|
+
/**
|
|
26323
|
+
* Applies META DOMAIN content into the normalized `meta.domain` field.
|
|
26324
|
+
*/
|
|
26325
|
+
function applyMetaDomainContent(state, content) {
|
|
26326
|
+
state.meta.domain = normalizeMetaDomain(content);
|
|
26327
|
+
}
|
|
26328
|
+
/**
|
|
26329
|
+
* Applies META IMAGE content into the canonical `meta.image` field.
|
|
26330
|
+
*/
|
|
26331
|
+
function applyMetaImageContent(state, content) {
|
|
26332
|
+
state.meta.image = spaceTrim$1(content);
|
|
26333
|
+
}
|
|
26334
|
+
/**
|
|
26335
|
+
* Applies META DESCRIPTION content into the canonical `meta.description` field.
|
|
26336
|
+
*/
|
|
26337
|
+
function applyMetaDescriptionContent(state, content) {
|
|
26338
|
+
state.meta.description = spaceTrim$1(content);
|
|
26339
|
+
}
|
|
26340
|
+
/**
|
|
26341
|
+
* Applies META DISCLAIMER content into the canonical `meta.disclaimer` field.
|
|
26342
|
+
*/
|
|
26343
|
+
function applyMetaDisclaimerContent(state, content) {
|
|
26344
|
+
state.meta.disclaimer = content;
|
|
26345
|
+
}
|
|
26346
|
+
/**
|
|
26347
|
+
* Applies META INPUT PLACEHOLDER content into the canonical `meta.inputPlaceholder` field.
|
|
26348
|
+
*/
|
|
26349
|
+
function applyMetaInputPlaceholderContent(state, content) {
|
|
26350
|
+
state.meta.inputPlaceholder = spaceTrim$1(content);
|
|
26351
|
+
}
|
|
26352
|
+
/**
|
|
26353
|
+
* Applies MESSAGE SUFFIX content into the canonical `meta.messageSuffix` field.
|
|
26354
|
+
*/
|
|
26355
|
+
function applyMessageSuffixContent(state, content) {
|
|
26356
|
+
state.meta.messageSuffix = content;
|
|
26357
|
+
}
|
|
26358
|
+
/**
|
|
26359
|
+
* Applies META COLOR content into the canonical `meta.color` field.
|
|
26360
|
+
*/
|
|
26361
|
+
function applyMetaColorContent(state, content) {
|
|
26362
|
+
state.meta.color = normalizeSeparator(content);
|
|
26363
|
+
}
|
|
26364
|
+
/**
|
|
26365
|
+
* Applies META FONT content into the canonical `meta.font` field.
|
|
26366
|
+
*/
|
|
26367
|
+
function applyMetaFontContent(state, content) {
|
|
26368
|
+
state.meta.font = normalizeSeparator(content);
|
|
26369
|
+
}
|
|
26370
|
+
/**
|
|
26371
|
+
* Applies META VOICE content into the canonical `meta.voice` field.
|
|
26372
|
+
*/
|
|
26373
|
+
function applyMetaVoiceContent(state, content) {
|
|
26374
|
+
state.meta.voice = spaceTrim$1(content);
|
|
26375
|
+
}
|
|
26376
|
+
/**
|
|
26377
|
+
* Normalizes the separator in the content
|
|
26378
|
+
*
|
|
26379
|
+
* @param content - The content to normalize
|
|
26380
|
+
* @returns The content with normalized separators
|
|
26381
|
+
*/
|
|
26382
|
+
function normalizeSeparator(content) {
|
|
26383
|
+
const trimmed = spaceTrim$1(content);
|
|
26384
|
+
if (trimmed.includes(',')) {
|
|
26385
|
+
return trimmed;
|
|
26386
|
+
}
|
|
26387
|
+
return trimmed.split(/\s+/).join(', ');
|
|
26388
|
+
}
|
|
26389
|
+
/**
|
|
26390
|
+
* Normalizes META DOMAIN content to a hostname-like value when possible.
|
|
26391
|
+
*
|
|
26392
|
+
* @param content - Raw META DOMAIN content.
|
|
26393
|
+
* @returns Normalized domain or a trimmed fallback.
|
|
26394
|
+
*/
|
|
26395
|
+
function normalizeMetaDomain(content) {
|
|
26396
|
+
const trimmed = spaceTrim$1(content);
|
|
26397
|
+
return normalizeDomainForMatching(trimmed) || trimmed.toLowerCase();
|
|
26369
26398
|
}
|
|
26399
|
+
|
|
26370
26400
|
/**
|
|
26371
26401
|
* Updates sample-conversation state for communication commitments.
|
|
26372
26402
|
*
|
|
@@ -26393,6 +26423,76 @@ function consumeConversationSampleCommitment(state, commitment) {
|
|
|
26393
26423
|
return false;
|
|
26394
26424
|
}
|
|
26395
26425
|
}
|
|
26426
|
+
|
|
26427
|
+
/**
|
|
26428
|
+
* Static capability descriptors for commitments that map one-to-one to a visible capability.
|
|
26429
|
+
*/
|
|
26430
|
+
const SIMPLE_CAPABILITY_BY_COMMITMENT_TYPE = {
|
|
26431
|
+
'USE BROWSER': {
|
|
26432
|
+
type: 'browser',
|
|
26433
|
+
label: 'Browser',
|
|
26434
|
+
iconName: 'Globe',
|
|
26435
|
+
},
|
|
26436
|
+
'USE SEARCH ENGINE': {
|
|
26437
|
+
type: 'search-engine',
|
|
26438
|
+
label: 'Internet',
|
|
26439
|
+
iconName: 'Search',
|
|
26440
|
+
},
|
|
26441
|
+
'USE SEARCH': {
|
|
26442
|
+
type: 'search-engine',
|
|
26443
|
+
label: 'Internet',
|
|
26444
|
+
iconName: 'Search',
|
|
26445
|
+
},
|
|
26446
|
+
'USE DEEPSEARCH': {
|
|
26447
|
+
type: 'search-engine',
|
|
26448
|
+
label: 'DeepSearch',
|
|
26449
|
+
iconName: 'Search',
|
|
26450
|
+
},
|
|
26451
|
+
'USE TIME': {
|
|
26452
|
+
type: 'time',
|
|
26453
|
+
label: 'Time',
|
|
26454
|
+
iconName: 'Clock',
|
|
26455
|
+
},
|
|
26456
|
+
'USE TIMEOUT': {
|
|
26457
|
+
type: 'timeout',
|
|
26458
|
+
label: 'Timers',
|
|
26459
|
+
iconName: 'Clock',
|
|
26460
|
+
},
|
|
26461
|
+
'USE USER LOCATION': {
|
|
26462
|
+
type: 'user-location',
|
|
26463
|
+
label: 'User location',
|
|
26464
|
+
iconName: 'MapPin',
|
|
26465
|
+
},
|
|
26466
|
+
'USE EMAIL': {
|
|
26467
|
+
type: 'email',
|
|
26468
|
+
label: 'Email',
|
|
26469
|
+
iconName: 'Mail',
|
|
26470
|
+
},
|
|
26471
|
+
'USE POPUP': {
|
|
26472
|
+
type: 'popup',
|
|
26473
|
+
label: 'Popup',
|
|
26474
|
+
iconName: 'SquareArrowOutUpRight',
|
|
26475
|
+
},
|
|
26476
|
+
'USE IMAGE GENERATOR': {
|
|
26477
|
+
type: 'image-generator',
|
|
26478
|
+
label: 'Image Generator',
|
|
26479
|
+
iconName: 'Image',
|
|
26480
|
+
},
|
|
26481
|
+
'USE PRIVACY': {
|
|
26482
|
+
type: 'privacy',
|
|
26483
|
+
label: 'Privacy',
|
|
26484
|
+
iconName: 'Shield',
|
|
26485
|
+
},
|
|
26486
|
+
'USE CALENDAR': {
|
|
26487
|
+
type: 'calendar',
|
|
26488
|
+
label: 'Calendar',
|
|
26489
|
+
iconName: 'Calendar',
|
|
26490
|
+
},
|
|
26491
|
+
};
|
|
26492
|
+
/**
|
|
26493
|
+
* Detects local slash-based references used by FROM and IMPORT commitments.
|
|
26494
|
+
*/
|
|
26495
|
+
const LOCAL_AGENT_REFERENCE_PREFIXES = ['./', '../', '/'];
|
|
26396
26496
|
/**
|
|
26397
26497
|
* Creates the visible capabilities produced by one parsed commitment.
|
|
26398
26498
|
*
|
|
@@ -26422,8 +26522,6 @@ function createCapabilitiesFromCommitment(state, commitment) {
|
|
|
26422
26522
|
}
|
|
26423
26523
|
/**
|
|
26424
26524
|
* Clones one static capability descriptor for a simple capability commitment.
|
|
26425
|
-
*
|
|
26426
|
-
* @private internal utility of `parseAgentSource`
|
|
26427
26525
|
*/
|
|
26428
26526
|
function createSimpleCapability(commitmentType) {
|
|
26429
26527
|
const capability = SIMPLE_CAPABILITY_BY_COMMITMENT_TYPE[commitmentType];
|
|
@@ -26431,8 +26529,6 @@ function createSimpleCapability(commitmentType) {
|
|
|
26431
26529
|
}
|
|
26432
26530
|
/**
|
|
26433
26531
|
* Creates the USE PROJECT capability badge.
|
|
26434
|
-
*
|
|
26435
|
-
* @private internal utility of `parseAgentSource`
|
|
26436
26532
|
*/
|
|
26437
26533
|
function createProjectCapability(content) {
|
|
26438
26534
|
var _a;
|
|
@@ -26446,8 +26542,6 @@ function createProjectCapability(content) {
|
|
|
26446
26542
|
}
|
|
26447
26543
|
/**
|
|
26448
26544
|
* Creates the FROM inheritance capability when the reference should stay visible in the profile.
|
|
26449
|
-
*
|
|
26450
|
-
* @private internal utility of `parseAgentSource`
|
|
26451
26545
|
*/
|
|
26452
26546
|
function createInheritanceCapability(content) {
|
|
26453
26547
|
const reference = extractFirstCommitmentLine(content);
|
|
@@ -26474,8 +26568,6 @@ function createInheritanceCapability(content) {
|
|
|
26474
26568
|
}
|
|
26475
26569
|
/**
|
|
26476
26570
|
* Creates the IMPORT capability badge.
|
|
26477
|
-
*
|
|
26478
|
-
* @private internal utility of `parseAgentSource`
|
|
26479
26571
|
*/
|
|
26480
26572
|
function createImportCapability(content) {
|
|
26481
26573
|
const reference = extractFirstCommitmentLine(content);
|
|
@@ -26503,8 +26595,6 @@ function createImportCapability(content) {
|
|
|
26503
26595
|
}
|
|
26504
26596
|
/**
|
|
26505
26597
|
* Creates TEAM capability badges for all parsed teammates.
|
|
26506
|
-
*
|
|
26507
|
-
* @private internal utility of `parseAgentSource`
|
|
26508
26598
|
*/
|
|
26509
26599
|
function createTeamCapabilities(content) {
|
|
26510
26600
|
const teammates = parseTeamCommitmentContent(content);
|
|
@@ -26517,8 +26607,6 @@ function createTeamCapabilities(content) {
|
|
|
26517
26607
|
}
|
|
26518
26608
|
/**
|
|
26519
26609
|
* Creates the KNOWLEDGE capability badge and records URL-based knowledge sources.
|
|
26520
|
-
*
|
|
26521
|
-
* @private internal utility of `parseAgentSource`
|
|
26522
26610
|
*/
|
|
26523
26611
|
function createKnowledgeCapability(state, content) {
|
|
26524
26612
|
const trimmedContent = spaceTrim$1(content);
|
|
@@ -26533,8 +26621,6 @@ function createKnowledgeCapability(state, content) {
|
|
|
26533
26621
|
}
|
|
26534
26622
|
/**
|
|
26535
26623
|
* Stores unique URL-based knowledge sources for later citation resolution.
|
|
26536
|
-
*
|
|
26537
|
-
* @private internal utility of `parseAgentSource`
|
|
26538
26624
|
*/
|
|
26539
26625
|
function rememberKnowledgeSources(state, extractedUrls) {
|
|
26540
26626
|
for (const extractedUrl of extractedUrls) {
|
|
@@ -26558,8 +26644,6 @@ function rememberKnowledgeSources(state, extractedUrls) {
|
|
|
26558
26644
|
}
|
|
26559
26645
|
/**
|
|
26560
26646
|
* Derives the visible KNOWLEDGE badge label and icon from commitment content.
|
|
26561
|
-
*
|
|
26562
|
-
* @private internal utility of `parseAgentSource`
|
|
26563
26647
|
*/
|
|
26564
26648
|
function createKnowledgeCapabilityPresentation(content, extractedUrls) {
|
|
26565
26649
|
let label = content;
|
|
@@ -26592,8 +26676,6 @@ function createKnowledgeCapabilityPresentation(content, extractedUrls) {
|
|
|
26592
26676
|
}
|
|
26593
26677
|
/**
|
|
26594
26678
|
* Shortens text-only KNOWLEDGE commitments into the same preview label as before.
|
|
26595
|
-
*
|
|
26596
|
-
* @private internal utility of `parseAgentSource`
|
|
26597
26679
|
*/
|
|
26598
26680
|
function createKnowledgeTextLabel(content) {
|
|
26599
26681
|
const words = content.split(/\s+/);
|
|
@@ -26602,186 +26684,89 @@ function createKnowledgeTextLabel(content) {
|
|
|
26602
26684
|
}
|
|
26603
26685
|
return content;
|
|
26604
26686
|
}
|
|
26605
|
-
/**
|
|
26606
|
-
* Applies META-style commitments that mutate parsed profile metadata.
|
|
26607
|
-
*
|
|
26608
|
-
* @private internal utility of `parseAgentSource`
|
|
26609
|
-
*/
|
|
26610
|
-
function applyMetaCommitment(state, commitment) {
|
|
26611
|
-
const applyMetaContent = META_COMMITMENT_APPLIERS[commitment.type];
|
|
26612
|
-
if (applyMetaContent) {
|
|
26613
|
-
applyMetaContent(state, commitment.content);
|
|
26614
|
-
return;
|
|
26615
|
-
}
|
|
26616
|
-
if (commitment.type === 'META') {
|
|
26617
|
-
applyGenericMetaCommitment(state, commitment.content);
|
|
26618
|
-
}
|
|
26619
|
-
}
|
|
26620
|
-
/**
|
|
26621
|
-
* Applies the generic META commitment form (`META TYPE value`).
|
|
26622
|
-
*
|
|
26623
|
-
* @private internal utility of `parseAgentSource`
|
|
26624
|
-
*/
|
|
26625
|
-
function applyGenericMetaCommitment(state, content) {
|
|
26626
|
-
const metaTypeRaw = content.split(' ')[0] || 'NONE';
|
|
26627
|
-
const metaValue = spaceTrim$1(content.substring(metaTypeRaw.length));
|
|
26628
|
-
if (metaTypeRaw === 'LINK') {
|
|
26629
|
-
state.links.push(metaValue);
|
|
26630
|
-
}
|
|
26631
|
-
if (metaTypeRaw.toUpperCase() === 'AVATAR') {
|
|
26632
|
-
applyMetaAvatarContent(state, metaValue);
|
|
26633
|
-
return;
|
|
26634
|
-
}
|
|
26635
|
-
const metaType = normalizeTo_camelCase(metaTypeRaw);
|
|
26636
|
-
state.meta[metaType] = metaValue;
|
|
26637
|
-
}
|
|
26638
|
-
/**
|
|
26639
|
-
* Applies META AVATAR content into the canonical `meta.avatar` field.
|
|
26640
|
-
*
|
|
26641
|
-
* @private internal utility of `parseAgentSource`
|
|
26642
|
-
*/
|
|
26643
|
-
function applyMetaAvatarContent(state, content) {
|
|
26644
|
-
const avatarVisualId = resolveAvatarVisualId(content);
|
|
26645
|
-
if (avatarVisualId) {
|
|
26646
|
-
state.meta.avatar = avatarVisualId;
|
|
26647
|
-
return;
|
|
26648
|
-
}
|
|
26649
|
-
delete state.meta.avatar;
|
|
26650
|
-
}
|
|
26651
|
-
/**
|
|
26652
|
-
* Applies META LINK content into links and the canonical `meta.link` field.
|
|
26653
|
-
*
|
|
26654
|
-
* @private internal utility of `parseAgentSource`
|
|
26655
|
-
*/
|
|
26656
|
-
function applyMetaLinkContent(state, content) {
|
|
26657
|
-
const linkValue = spaceTrim$1(content);
|
|
26658
|
-
state.links.push(linkValue);
|
|
26659
|
-
state.meta.link = linkValue;
|
|
26660
|
-
}
|
|
26661
|
-
/**
|
|
26662
|
-
* Applies META DOMAIN content into the normalized `meta.domain` field.
|
|
26663
|
-
*
|
|
26664
|
-
* @private internal utility of `parseAgentSource`
|
|
26665
|
-
*/
|
|
26666
|
-
function applyMetaDomainContent(state, content) {
|
|
26667
|
-
state.meta.domain = normalizeMetaDomain(content);
|
|
26668
|
-
}
|
|
26669
|
-
/**
|
|
26670
|
-
* Applies META IMAGE content into the canonical `meta.image` field.
|
|
26671
|
-
*
|
|
26672
|
-
* @private internal utility of `parseAgentSource`
|
|
26673
|
-
*/
|
|
26674
|
-
function applyMetaImageContent(state, content) {
|
|
26675
|
-
state.meta.image = spaceTrim$1(content);
|
|
26676
|
-
}
|
|
26677
|
-
/**
|
|
26678
|
-
* Applies META DESCRIPTION content into the canonical `meta.description` field.
|
|
26679
|
-
*
|
|
26680
|
-
* @private internal utility of `parseAgentSource`
|
|
26681
|
-
*/
|
|
26682
|
-
function applyMetaDescriptionContent(state, content) {
|
|
26683
|
-
state.meta.description = spaceTrim$1(content);
|
|
26684
|
-
}
|
|
26685
|
-
/**
|
|
26686
|
-
* Applies META DISCLAIMER content into the canonical `meta.disclaimer` field.
|
|
26687
|
-
*
|
|
26688
|
-
* @private internal utility of `parseAgentSource`
|
|
26689
|
-
*/
|
|
26690
|
-
function applyMetaDisclaimerContent(state, content) {
|
|
26691
|
-
state.meta.disclaimer = content;
|
|
26692
|
-
}
|
|
26693
|
-
/**
|
|
26694
|
-
* Applies META INPUT PLACEHOLDER content into the canonical `meta.inputPlaceholder` field.
|
|
26695
|
-
*
|
|
26696
|
-
* @private internal utility of `parseAgentSource`
|
|
26697
|
-
*/
|
|
26698
|
-
function applyMetaInputPlaceholderContent(state, content) {
|
|
26699
|
-
state.meta.inputPlaceholder = spaceTrim$1(content);
|
|
26700
|
-
}
|
|
26701
|
-
/**
|
|
26702
|
-
* Applies MESSAGE SUFFIX content into the canonical `meta.messageSuffix` field.
|
|
26703
|
-
*
|
|
26704
|
-
* @private internal utility of `parseAgentSource`
|
|
26705
|
-
*/
|
|
26706
|
-
function applyMessageSuffixContent(state, content) {
|
|
26707
|
-
state.meta.messageSuffix = content;
|
|
26708
|
-
}
|
|
26709
|
-
/**
|
|
26710
|
-
* Applies META COLOR content into the canonical `meta.color` field.
|
|
26711
|
-
*
|
|
26712
|
-
* @private internal utility of `parseAgentSource`
|
|
26713
|
-
*/
|
|
26714
|
-
function applyMetaColorContent(state, content) {
|
|
26715
|
-
state.meta.color = normalizeSeparator(content);
|
|
26716
|
-
}
|
|
26717
|
-
/**
|
|
26718
|
-
* Applies META FONT content into the canonical `meta.font` field.
|
|
26719
|
-
*
|
|
26720
|
-
* @private internal utility of `parseAgentSource`
|
|
26721
|
-
*/
|
|
26722
|
-
function applyMetaFontContent(state, content) {
|
|
26723
|
-
state.meta.font = normalizeSeparator(content);
|
|
26724
|
-
}
|
|
26725
|
-
/**
|
|
26726
|
-
* Applies META VOICE content into the canonical `meta.voice` field.
|
|
26727
|
-
*
|
|
26728
|
-
* @private internal utility of `parseAgentSource`
|
|
26729
|
-
*/
|
|
26730
|
-
function applyMetaVoiceContent(state, content) {
|
|
26731
|
-
state.meta.voice = spaceTrim$1(content);
|
|
26732
|
-
}
|
|
26733
|
-
/**
|
|
26734
|
-
* Ensures the parsed profile always exposes a fullname value.
|
|
26735
|
-
*
|
|
26736
|
-
* @private internal utility of `parseAgentSource`
|
|
26737
|
-
*/
|
|
26738
|
-
function ensureMetaFullname(meta, fallbackFullname) {
|
|
26739
|
-
if (!meta.fullname) {
|
|
26740
|
-
meta.fullname = fallbackFullname;
|
|
26741
|
-
}
|
|
26742
|
-
}
|
|
26743
26687
|
/**
|
|
26744
26688
|
* Extracts the first logical line from multiline commitment content.
|
|
26745
|
-
*
|
|
26746
|
-
* @private internal utility of `parseAgentSource`
|
|
26747
26689
|
*/
|
|
26748
26690
|
function extractFirstCommitmentLine(content) {
|
|
26749
26691
|
return spaceTrim$1(content).split(/\r?\n/)[0] || '';
|
|
26750
26692
|
}
|
|
26751
26693
|
/**
|
|
26752
26694
|
* Detects local FROM/IMPORT references that should use local-link labels and icons.
|
|
26753
|
-
*
|
|
26754
|
-
* @private internal utility of `parseAgentSource`
|
|
26755
26695
|
*/
|
|
26756
26696
|
function isLocalAgentReference(reference) {
|
|
26757
26697
|
return LOCAL_AGENT_REFERENCE_PREFIXES.some((prefix) => reference.startsWith(prefix));
|
|
26758
26698
|
}
|
|
26699
|
+
|
|
26759
26700
|
/**
|
|
26760
|
-
*
|
|
26761
|
-
*
|
|
26762
|
-
* @param content - The content to normalize
|
|
26763
|
-
* @returns The content with normalized separators
|
|
26701
|
+
* Collects capability, sample, meta, link, and knowledge-source data from commitments.
|
|
26764
26702
|
*
|
|
26765
26703
|
* @private internal utility of `parseAgentSource`
|
|
26766
26704
|
*/
|
|
26767
|
-
function
|
|
26768
|
-
const
|
|
26769
|
-
|
|
26770
|
-
|
|
26705
|
+
function extractParsedAgentProfile(commitments) {
|
|
26706
|
+
const state = {
|
|
26707
|
+
meta: {},
|
|
26708
|
+
links: [],
|
|
26709
|
+
capabilities: [],
|
|
26710
|
+
samples: [],
|
|
26711
|
+
knowledgeSources: [],
|
|
26712
|
+
pendingUserMessage: null,
|
|
26713
|
+
knownKnowledgeSourceUrls: new Set(),
|
|
26714
|
+
};
|
|
26715
|
+
for (const commitment of commitments) {
|
|
26716
|
+
processParsedCommitment(state, commitment);
|
|
26771
26717
|
}
|
|
26772
|
-
return
|
|
26718
|
+
return {
|
|
26719
|
+
meta: state.meta,
|
|
26720
|
+
links: state.links,
|
|
26721
|
+
capabilities: state.capabilities,
|
|
26722
|
+
samples: state.samples,
|
|
26723
|
+
knowledgeSources: state.knowledgeSources,
|
|
26724
|
+
};
|
|
26773
26725
|
}
|
|
26774
26726
|
/**
|
|
26775
|
-
*
|
|
26727
|
+
* Processes one parsed commitment through the sample, capability, and meta stages.
|
|
26728
|
+
*/
|
|
26729
|
+
function processParsedCommitment(state, commitment) {
|
|
26730
|
+
if (consumeConversationSampleCommitment(state, commitment)) {
|
|
26731
|
+
return;
|
|
26732
|
+
}
|
|
26733
|
+
const capabilities = createCapabilitiesFromCommitment(state, commitment);
|
|
26734
|
+
if (capabilities.length > 0) {
|
|
26735
|
+
state.capabilities.push(...capabilities);
|
|
26736
|
+
return;
|
|
26737
|
+
}
|
|
26738
|
+
applyMetaCommitment(state, commitment);
|
|
26739
|
+
}
|
|
26740
|
+
|
|
26741
|
+
/**
|
|
26742
|
+
* Parses basic information from agent source
|
|
26776
26743
|
*
|
|
26777
|
-
*
|
|
26778
|
-
*
|
|
26744
|
+
* There are 2 similar functions:
|
|
26745
|
+
* - `parseAgentSource` which is a lightweight parser for agent source, it parses basic information and its purpose is to be quick and synchronous. The commitments there are hardcoded.
|
|
26746
|
+
* - `createAgentModelRequirements` which is an asynchronous function that creates model requirements it applies each commitment one by one and works asynchronously.
|
|
26779
26747
|
*
|
|
26780
|
-
* @
|
|
26748
|
+
* @public exported from `@promptbook/core`
|
|
26781
26749
|
*/
|
|
26782
|
-
function
|
|
26783
|
-
const
|
|
26784
|
-
|
|
26750
|
+
function parseAgentSource(agentSource) {
|
|
26751
|
+
const parseResult = parseAgentSourceWithCommitments(agentSource);
|
|
26752
|
+
const resolvedAgentName = parseResult.agentName || createDefaultAgentName(agentSource);
|
|
26753
|
+
const personaDescription = extractAgentProfileText(parseResult.commitments);
|
|
26754
|
+
const initialMessage = extractInitialMessage(parseResult.commitments);
|
|
26755
|
+
const parsedProfile = extractParsedAgentProfile(parseResult.commitments);
|
|
26756
|
+
ensureMetaFullname(parsedProfile.meta, resolvedAgentName);
|
|
26757
|
+
return {
|
|
26758
|
+
agentName: normalizeAgentName(resolvedAgentName),
|
|
26759
|
+
agentHash: computeAgentHash(agentSource),
|
|
26760
|
+
permanentId: parsedProfile.meta.id,
|
|
26761
|
+
personaDescription,
|
|
26762
|
+
initialMessage,
|
|
26763
|
+
meta: parsedProfile.meta,
|
|
26764
|
+
links: parsedProfile.links,
|
|
26765
|
+
parameters: parseParameters(agentSource),
|
|
26766
|
+
capabilities: parsedProfile.capabilities,
|
|
26767
|
+
samples: parsedProfile.samples,
|
|
26768
|
+
knowledgeSources: parsedProfile.knowledgeSources,
|
|
26769
|
+
};
|
|
26785
26770
|
}
|
|
26786
26771
|
// TODO: [🕛] Unite `AgentBasicInformation`, `ChatParticipant`, `LlmExecutionTools` + `LlmToolsMetadata`
|
|
26787
26772
|
|