@promptbook/browser 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 +765 -780
- 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 +2 -2
- package/umd/index.umd.js +765 -780
- 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
|
@@ -29,7 +29,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
29
29
|
* @generated
|
|
30
30
|
* @see https://github.com/webgptorg/promptbook
|
|
31
31
|
*/
|
|
32
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
32
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-58';
|
|
33
33
|
/**
|
|
34
34
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
35
35
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -15297,6 +15297,44 @@ function mapGoogleCalendarEvent(event) {
|
|
|
15297
15297
|
* @private constant of createUseCalendarTools
|
|
15298
15298
|
*/
|
|
15299
15299
|
const CALENDAR_URL_PARAMETER_DESCRIPTION = 'Google Calendar URL configured by USE CALENDAR (for example "https://calendar.google.com/...").';
|
|
15300
|
+
/**
|
|
15301
|
+
* Shared schema for string arrays used by USE CALENDAR tools.
|
|
15302
|
+
*
|
|
15303
|
+
* @private constant of createUseCalendarTools
|
|
15304
|
+
*/
|
|
15305
|
+
const STRING_ARRAY_ITEMS_SCHEMA = {
|
|
15306
|
+
type: 'string',
|
|
15307
|
+
};
|
|
15308
|
+
/**
|
|
15309
|
+
* Shared schema for integer arrays used by USE CALENDAR tools.
|
|
15310
|
+
*
|
|
15311
|
+
* @private constant of createUseCalendarTools
|
|
15312
|
+
*/
|
|
15313
|
+
const INTEGER_ARRAY_ITEMS_SCHEMA = {
|
|
15314
|
+
type: 'integer',
|
|
15315
|
+
};
|
|
15316
|
+
/**
|
|
15317
|
+
* Shared `sendUpdates` schema used by USE CALENDAR tools.
|
|
15318
|
+
*
|
|
15319
|
+
* @private constant of createUseCalendarTools
|
|
15320
|
+
*/
|
|
15321
|
+
const SEND_UPDATES_PARAMETER_SCHEMA = {
|
|
15322
|
+
type: 'string',
|
|
15323
|
+
description: 'Guest update policy ("all", "externalOnly", "none").',
|
|
15324
|
+
enum: ['all', 'externalOnly', 'none'],
|
|
15325
|
+
};
|
|
15326
|
+
/**
|
|
15327
|
+
* Creates an array parameter schema with explicit item definition so OpenAI accepts it.
|
|
15328
|
+
*
|
|
15329
|
+
* @private function of createUseCalendarTools
|
|
15330
|
+
*/
|
|
15331
|
+
function createArrayParameterSchema(description, items) {
|
|
15332
|
+
return {
|
|
15333
|
+
type: 'array',
|
|
15334
|
+
description,
|
|
15335
|
+
items,
|
|
15336
|
+
};
|
|
15337
|
+
}
|
|
15300
15338
|
/**
|
|
15301
15339
|
* Adds USE CALENDAR tool definitions while keeping already registered tools untouched.
|
|
15302
15340
|
*
|
|
@@ -15403,18 +15441,9 @@ function createUseCalendarTools(existingTools) {
|
|
|
15403
15441
|
type: 'string',
|
|
15404
15442
|
description: 'Optional timezone for datetime values.',
|
|
15405
15443
|
},
|
|
15406
|
-
attendees:
|
|
15407
|
-
|
|
15408
|
-
|
|
15409
|
-
},
|
|
15410
|
-
reminderMinutes: {
|
|
15411
|
-
type: 'array',
|
|
15412
|
-
description: 'Optional popup reminder minute offsets.',
|
|
15413
|
-
},
|
|
15414
|
-
sendUpdates: {
|
|
15415
|
-
type: 'string',
|
|
15416
|
-
description: 'Guest update policy ("all", "externalOnly", "none").',
|
|
15417
|
-
},
|
|
15444
|
+
attendees: createArrayParameterSchema('Optional guest email list.', STRING_ARRAY_ITEMS_SCHEMA),
|
|
15445
|
+
reminderMinutes: createArrayParameterSchema('Optional popup reminder minute offsets.', INTEGER_ARRAY_ITEMS_SCHEMA),
|
|
15446
|
+
sendUpdates: SEND_UPDATES_PARAMETER_SCHEMA,
|
|
15418
15447
|
},
|
|
15419
15448
|
required: ['summary', 'start', 'end'],
|
|
15420
15449
|
},
|
|
@@ -15457,18 +15486,9 @@ function createUseCalendarTools(existingTools) {
|
|
|
15457
15486
|
type: 'string',
|
|
15458
15487
|
description: 'Optional timezone for datetime values.',
|
|
15459
15488
|
},
|
|
15460
|
-
attendees:
|
|
15461
|
-
|
|
15462
|
-
|
|
15463
|
-
},
|
|
15464
|
-
reminderMinutes: {
|
|
15465
|
-
type: 'array',
|
|
15466
|
-
description: 'Optional replacement popup reminder minute offsets.',
|
|
15467
|
-
},
|
|
15468
|
-
sendUpdates: {
|
|
15469
|
-
type: 'string',
|
|
15470
|
-
description: 'Guest update policy ("all", "externalOnly", "none").',
|
|
15471
|
-
},
|
|
15489
|
+
attendees: createArrayParameterSchema('Optional replacement guest email list.', STRING_ARRAY_ITEMS_SCHEMA),
|
|
15490
|
+
reminderMinutes: createArrayParameterSchema('Optional replacement popup reminder minute offsets.', INTEGER_ARRAY_ITEMS_SCHEMA),
|
|
15491
|
+
sendUpdates: SEND_UPDATES_PARAMETER_SCHEMA,
|
|
15472
15492
|
},
|
|
15473
15493
|
required: ['eventId'],
|
|
15474
15494
|
},
|
|
@@ -15487,10 +15507,7 @@ function createUseCalendarTools(existingTools) {
|
|
|
15487
15507
|
type: 'string',
|
|
15488
15508
|
description: 'Google Calendar event id.',
|
|
15489
15509
|
},
|
|
15490
|
-
sendUpdates:
|
|
15491
|
-
type: 'string',
|
|
15492
|
-
description: 'Guest update policy ("all", "externalOnly", "none").',
|
|
15493
|
-
},
|
|
15510
|
+
sendUpdates: SEND_UPDATES_PARAMETER_SCHEMA,
|
|
15494
15511
|
},
|
|
15495
15512
|
required: ['eventId'],
|
|
15496
15513
|
},
|
|
@@ -15509,14 +15526,8 @@ function createUseCalendarTools(existingTools) {
|
|
|
15509
15526
|
type: 'string',
|
|
15510
15527
|
description: 'Google Calendar event id.',
|
|
15511
15528
|
},
|
|
15512
|
-
guests:
|
|
15513
|
-
|
|
15514
|
-
description: 'Guest email list to add to the event.',
|
|
15515
|
-
},
|
|
15516
|
-
sendUpdates: {
|
|
15517
|
-
type: 'string',
|
|
15518
|
-
description: 'Guest update policy ("all", "externalOnly", "none").',
|
|
15519
|
-
},
|
|
15529
|
+
guests: createArrayParameterSchema('Guest email list to add to the event.', STRING_ARRAY_ITEMS_SCHEMA),
|
|
15530
|
+
sendUpdates: SEND_UPDATES_PARAMETER_SCHEMA,
|
|
15520
15531
|
},
|
|
15521
15532
|
required: ['eventId', 'guests'],
|
|
15522
15533
|
},
|
|
@@ -20758,44 +20769,6 @@ function getSessionStorage() {
|
|
|
20758
20769
|
}
|
|
20759
20770
|
// Note: [🔵] Code for browser storage helper [getSessionStorage](src/storage/local-storage/getSessionStorage.ts) should never be published outside of `@promptbook/browser`
|
|
20760
20771
|
|
|
20761
|
-
/**
|
|
20762
|
-
* Normalizes a domain-like string into a comparable hostname form.
|
|
20763
|
-
*
|
|
20764
|
-
* The returned value is lowercased and stripped to hostname only
|
|
20765
|
-
* (protocol, path, query, hash, and port are removed).
|
|
20766
|
-
*
|
|
20767
|
-
* @param rawDomain - Raw domain value (for example `my-agent.com` or `https://my-agent.com/path`).
|
|
20768
|
-
* @returns Normalized hostname or `null` when the value cannot be normalized.
|
|
20769
|
-
*
|
|
20770
|
-
* @private utility for host/domain matching
|
|
20771
|
-
*/
|
|
20772
|
-
function normalizeDomainForMatching(rawDomain) {
|
|
20773
|
-
const trimmedDomain = rawDomain.trim();
|
|
20774
|
-
if (!trimmedDomain) {
|
|
20775
|
-
return null;
|
|
20776
|
-
}
|
|
20777
|
-
const candidateUrl = hasHttpProtocol(trimmedDomain) ? trimmedDomain : `https://${trimmedDomain}`;
|
|
20778
|
-
try {
|
|
20779
|
-
const parsedUrl = new URL(candidateUrl);
|
|
20780
|
-
const normalizedHostname = parsedUrl.hostname.trim().toLowerCase();
|
|
20781
|
-
return normalizedHostname || null;
|
|
20782
|
-
}
|
|
20783
|
-
catch (_a) {
|
|
20784
|
-
return null;
|
|
20785
|
-
}
|
|
20786
|
-
}
|
|
20787
|
-
/**
|
|
20788
|
-
* Checks whether the value already includes an HTTP(S) protocol prefix.
|
|
20789
|
-
*
|
|
20790
|
-
* @param value - Raw value to inspect.
|
|
20791
|
-
* @returns True when the value starts with `http://` or `https://`.
|
|
20792
|
-
*
|
|
20793
|
-
* @private utility for host/domain matching
|
|
20794
|
-
*/
|
|
20795
|
-
function hasHttpProtocol(value) {
|
|
20796
|
-
return value.startsWith('http://') || value.startsWith('https://');
|
|
20797
|
-
}
|
|
20798
|
-
|
|
20799
20772
|
/**
|
|
20800
20773
|
* Computes SHA-256 hash of the agent source
|
|
20801
20774
|
*
|
|
@@ -21062,126 +21035,16 @@ function parseParameters(text) {
|
|
|
21062
21035
|
}
|
|
21063
21036
|
|
|
21064
21037
|
/**
|
|
21065
|
-
*
|
|
21066
|
-
*
|
|
21067
|
-
* There are 2 similar functions:
|
|
21068
|
-
* - `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.
|
|
21069
|
-
* - `createAgentModelRequirements` which is an asynchronous function that creates model requirements it applies each commitment one by one and works asynchronously.
|
|
21070
|
-
*
|
|
21071
|
-
* @public exported from `@promptbook/core`
|
|
21072
|
-
*/
|
|
21073
|
-
function parseAgentSource(agentSource) {
|
|
21074
|
-
const parseResult = parseAgentSourceWithCommitments(agentSource);
|
|
21075
|
-
const resolvedAgentName = parseResult.agentName || createDefaultAgentName(agentSource);
|
|
21076
|
-
const personaDescription = extractAgentProfileText(parseResult.commitments);
|
|
21077
|
-
const initialMessage = extractInitialMessage(parseResult.commitments);
|
|
21078
|
-
const parsedProfile = extractParsedAgentProfile(parseResult.commitments);
|
|
21079
|
-
ensureMetaFullname(parsedProfile.meta, resolvedAgentName);
|
|
21080
|
-
return {
|
|
21081
|
-
agentName: normalizeAgentName(resolvedAgentName),
|
|
21082
|
-
agentHash: computeAgentHash(agentSource),
|
|
21083
|
-
permanentId: parsedProfile.meta.id,
|
|
21084
|
-
personaDescription,
|
|
21085
|
-
initialMessage,
|
|
21086
|
-
meta: parsedProfile.meta,
|
|
21087
|
-
links: parsedProfile.links,
|
|
21088
|
-
parameters: parseParameters(agentSource),
|
|
21089
|
-
capabilities: parsedProfile.capabilities,
|
|
21090
|
-
samples: parsedProfile.samples,
|
|
21091
|
-
knowledgeSources: parsedProfile.knowledgeSources,
|
|
21092
|
-
};
|
|
21093
|
-
}
|
|
21094
|
-
/**
|
|
21095
|
-
* Static capability descriptors for commitments that map one-to-one to a visible capability.
|
|
21096
|
-
*
|
|
21097
|
-
* @private internal utility of `parseAgentSource`
|
|
21098
|
-
*/
|
|
21099
|
-
const SIMPLE_CAPABILITY_BY_COMMITMENT_TYPE = {
|
|
21100
|
-
'USE BROWSER': {
|
|
21101
|
-
type: 'browser',
|
|
21102
|
-
label: 'Browser',
|
|
21103
|
-
iconName: 'Globe',
|
|
21104
|
-
},
|
|
21105
|
-
'USE SEARCH ENGINE': {
|
|
21106
|
-
type: 'search-engine',
|
|
21107
|
-
label: 'Internet',
|
|
21108
|
-
iconName: 'Search',
|
|
21109
|
-
},
|
|
21110
|
-
'USE SEARCH': {
|
|
21111
|
-
type: 'search-engine',
|
|
21112
|
-
label: 'Internet',
|
|
21113
|
-
iconName: 'Search',
|
|
21114
|
-
},
|
|
21115
|
-
'USE DEEPSEARCH': {
|
|
21116
|
-
type: 'search-engine',
|
|
21117
|
-
label: 'DeepSearch',
|
|
21118
|
-
iconName: 'Search',
|
|
21119
|
-
},
|
|
21120
|
-
'USE TIME': {
|
|
21121
|
-
type: 'time',
|
|
21122
|
-
label: 'Time',
|
|
21123
|
-
iconName: 'Clock',
|
|
21124
|
-
},
|
|
21125
|
-
'USE TIMEOUT': {
|
|
21126
|
-
type: 'timeout',
|
|
21127
|
-
label: 'Timers',
|
|
21128
|
-
iconName: 'Clock',
|
|
21129
|
-
},
|
|
21130
|
-
'USE USER LOCATION': {
|
|
21131
|
-
type: 'user-location',
|
|
21132
|
-
label: 'User location',
|
|
21133
|
-
iconName: 'MapPin',
|
|
21134
|
-
},
|
|
21135
|
-
'USE EMAIL': {
|
|
21136
|
-
type: 'email',
|
|
21137
|
-
label: 'Email',
|
|
21138
|
-
iconName: 'Mail',
|
|
21139
|
-
},
|
|
21140
|
-
'USE POPUP': {
|
|
21141
|
-
type: 'popup',
|
|
21142
|
-
label: 'Popup',
|
|
21143
|
-
iconName: 'SquareArrowOutUpRight',
|
|
21144
|
-
},
|
|
21145
|
-
'USE IMAGE GENERATOR': {
|
|
21146
|
-
type: 'image-generator',
|
|
21147
|
-
label: 'Image Generator',
|
|
21148
|
-
iconName: 'Image',
|
|
21149
|
-
},
|
|
21150
|
-
'USE PRIVACY': {
|
|
21151
|
-
type: 'privacy',
|
|
21152
|
-
label: 'Privacy',
|
|
21153
|
-
iconName: 'Shield',
|
|
21154
|
-
},
|
|
21155
|
-
'USE CALENDAR': {
|
|
21156
|
-
type: 'calendar',
|
|
21157
|
-
label: 'Calendar',
|
|
21158
|
-
iconName: 'Calendar',
|
|
21159
|
-
},
|
|
21160
|
-
};
|
|
21161
|
-
/**
|
|
21162
|
-
* Dedicated handlers for META-style commitments that directly map onto parsed meta fields.
|
|
21163
|
-
*
|
|
21164
|
-
* @private internal utility of `parseAgentSource`
|
|
21165
|
-
*/
|
|
21166
|
-
const META_COMMITMENT_APPLIERS = {
|
|
21167
|
-
'META AVATAR': applyMetaAvatarContent,
|
|
21168
|
-
'META LINK': applyMetaLinkContent,
|
|
21169
|
-
'META DOMAIN': applyMetaDomainContent,
|
|
21170
|
-
'META IMAGE': applyMetaImageContent,
|
|
21171
|
-
'META DESCRIPTION': applyMetaDescriptionContent,
|
|
21172
|
-
'META DISCLAIMER': applyMetaDisclaimerContent,
|
|
21173
|
-
'META INPUT PLACEHOLDER': applyMetaInputPlaceholderContent,
|
|
21174
|
-
'MESSAGE SUFFIX': applyMessageSuffixContent,
|
|
21175
|
-
'META COLOR': applyMetaColorContent,
|
|
21176
|
-
'META FONT': applyMetaFontContent,
|
|
21177
|
-
'META VOICE': applyMetaVoiceContent,
|
|
21178
|
-
};
|
|
21179
|
-
/**
|
|
21180
|
-
* Detects local slash-based references used by FROM and IMPORT commitments.
|
|
21038
|
+
* Ensures the parsed profile always exposes a fullname value.
|
|
21181
21039
|
*
|
|
21182
21040
|
* @private internal utility of `parseAgentSource`
|
|
21183
21041
|
*/
|
|
21184
|
-
|
|
21042
|
+
function ensureMetaFullname(meta, fallbackFullname) {
|
|
21043
|
+
if (!meta.fullname) {
|
|
21044
|
+
meta.fullname = fallbackFullname;
|
|
21045
|
+
}
|
|
21046
|
+
}
|
|
21047
|
+
|
|
21185
21048
|
/**
|
|
21186
21049
|
* Resolves the public agent profile text from the last GOAL/GOALS commitment,
|
|
21187
21050
|
* falling back to the deprecated PERSONA/PERSONAE commitments when no goal exists.
|
|
@@ -21211,6 +21074,7 @@ function extractAgentProfileText(commitments) {
|
|
|
21211
21074
|
}
|
|
21212
21075
|
return null;
|
|
21213
21076
|
}
|
|
21077
|
+
|
|
21214
21078
|
/**
|
|
21215
21079
|
* Resolves the last INITIAL MESSAGE commitment, which is the public initial-message value.
|
|
21216
21080
|
*
|
|
@@ -21225,53 +21089,194 @@ function extractInitialMessage(commitments) {
|
|
|
21225
21089
|
}
|
|
21226
21090
|
return initialMessage;
|
|
21227
21091
|
}
|
|
21092
|
+
|
|
21228
21093
|
/**
|
|
21229
|
-
*
|
|
21094
|
+
* Normalizes a domain-like string into a comparable hostname form.
|
|
21230
21095
|
*
|
|
21231
|
-
*
|
|
21232
|
-
|
|
21233
|
-
function extractParsedAgentProfile(commitments) {
|
|
21234
|
-
const state = {
|
|
21235
|
-
meta: {},
|
|
21236
|
-
links: [],
|
|
21237
|
-
capabilities: [],
|
|
21238
|
-
samples: [],
|
|
21239
|
-
knowledgeSources: [],
|
|
21240
|
-
pendingUserMessage: null,
|
|
21241
|
-
knownKnowledgeSourceUrls: new Set(),
|
|
21242
|
-
};
|
|
21243
|
-
for (const commitment of commitments) {
|
|
21244
|
-
processParsedCommitment(state, commitment);
|
|
21245
|
-
}
|
|
21246
|
-
return {
|
|
21247
|
-
meta: state.meta,
|
|
21248
|
-
links: state.links,
|
|
21249
|
-
capabilities: state.capabilities,
|
|
21250
|
-
samples: state.samples,
|
|
21251
|
-
knowledgeSources: state.knowledgeSources,
|
|
21252
|
-
};
|
|
21253
|
-
}
|
|
21254
|
-
/**
|
|
21255
|
-
* Processes one parsed commitment through the sample, capability, and meta stages.
|
|
21096
|
+
* The returned value is lowercased and stripped to hostname only
|
|
21097
|
+
* (protocol, path, query, hash, and port are removed).
|
|
21256
21098
|
*
|
|
21257
|
-
* @
|
|
21099
|
+
* @param rawDomain - Raw domain value (for example `my-agent.com` or `https://my-agent.com/path`).
|
|
21100
|
+
* @returns Normalized hostname or `null` when the value cannot be normalized.
|
|
21101
|
+
*
|
|
21102
|
+
* @private utility for host/domain matching
|
|
21258
21103
|
*/
|
|
21259
|
-
function
|
|
21260
|
-
|
|
21261
|
-
|
|
21104
|
+
function normalizeDomainForMatching(rawDomain) {
|
|
21105
|
+
const trimmedDomain = rawDomain.trim();
|
|
21106
|
+
if (!trimmedDomain) {
|
|
21107
|
+
return null;
|
|
21262
21108
|
}
|
|
21263
|
-
const
|
|
21264
|
-
|
|
21265
|
-
|
|
21266
|
-
|
|
21109
|
+
const candidateUrl = hasHttpProtocol(trimmedDomain) ? trimmedDomain : `https://${trimmedDomain}`;
|
|
21110
|
+
try {
|
|
21111
|
+
const parsedUrl = new URL(candidateUrl);
|
|
21112
|
+
const normalizedHostname = parsedUrl.hostname.trim().toLowerCase();
|
|
21113
|
+
return normalizedHostname || null;
|
|
21114
|
+
}
|
|
21115
|
+
catch (_a) {
|
|
21116
|
+
return null;
|
|
21267
21117
|
}
|
|
21268
|
-
applyMetaCommitment(state, commitment);
|
|
21269
21118
|
}
|
|
21270
21119
|
/**
|
|
21271
|
-
*
|
|
21120
|
+
* Checks whether the value already includes an HTTP(S) protocol prefix.
|
|
21272
21121
|
*
|
|
21273
|
-
* @
|
|
21274
|
-
|
|
21122
|
+
* @param value - Raw value to inspect.
|
|
21123
|
+
* @returns True when the value starts with `http://` or `https://`.
|
|
21124
|
+
*
|
|
21125
|
+
* @private utility for host/domain matching
|
|
21126
|
+
*/
|
|
21127
|
+
function hasHttpProtocol(value) {
|
|
21128
|
+
return value.startsWith('http://') || value.startsWith('https://');
|
|
21129
|
+
}
|
|
21130
|
+
|
|
21131
|
+
/**
|
|
21132
|
+
* Dedicated handlers for META-style commitments that directly map onto parsed meta fields.
|
|
21133
|
+
*/
|
|
21134
|
+
const META_COMMITMENT_APPLIERS = {
|
|
21135
|
+
'META AVATAR': applyMetaAvatarContent,
|
|
21136
|
+
'META LINK': applyMetaLinkContent,
|
|
21137
|
+
'META DOMAIN': applyMetaDomainContent,
|
|
21138
|
+
'META IMAGE': applyMetaImageContent,
|
|
21139
|
+
'META DESCRIPTION': applyMetaDescriptionContent,
|
|
21140
|
+
'META DISCLAIMER': applyMetaDisclaimerContent,
|
|
21141
|
+
'META INPUT PLACEHOLDER': applyMetaInputPlaceholderContent,
|
|
21142
|
+
'MESSAGE SUFFIX': applyMessageSuffixContent,
|
|
21143
|
+
'META COLOR': applyMetaColorContent,
|
|
21144
|
+
'META FONT': applyMetaFontContent,
|
|
21145
|
+
'META VOICE': applyMetaVoiceContent,
|
|
21146
|
+
};
|
|
21147
|
+
/**
|
|
21148
|
+
* Applies META-style commitments that mutate parsed profile metadata.
|
|
21149
|
+
*
|
|
21150
|
+
* @private internal utility of `parseAgentSource`
|
|
21151
|
+
*/
|
|
21152
|
+
function applyMetaCommitment(state, commitment) {
|
|
21153
|
+
const applyMetaContent = META_COMMITMENT_APPLIERS[commitment.type];
|
|
21154
|
+
if (applyMetaContent) {
|
|
21155
|
+
applyMetaContent(state, commitment.content);
|
|
21156
|
+
return;
|
|
21157
|
+
}
|
|
21158
|
+
if (commitment.type === 'META') {
|
|
21159
|
+
applyGenericMetaCommitment(state, commitment.content);
|
|
21160
|
+
}
|
|
21161
|
+
}
|
|
21162
|
+
/**
|
|
21163
|
+
* Applies the generic META commitment form (`META TYPE value`).
|
|
21164
|
+
*/
|
|
21165
|
+
function applyGenericMetaCommitment(state, content) {
|
|
21166
|
+
const metaTypeRaw = content.split(' ')[0] || 'NONE';
|
|
21167
|
+
const metaValue = spaceTrim$1(content.substring(metaTypeRaw.length));
|
|
21168
|
+
if (metaTypeRaw === 'LINK') {
|
|
21169
|
+
state.links.push(metaValue);
|
|
21170
|
+
}
|
|
21171
|
+
if (metaTypeRaw.toUpperCase() === 'AVATAR') {
|
|
21172
|
+
applyMetaAvatarContent(state, metaValue);
|
|
21173
|
+
return;
|
|
21174
|
+
}
|
|
21175
|
+
const metaType = normalizeTo_camelCase(metaTypeRaw);
|
|
21176
|
+
state.meta[metaType] = metaValue;
|
|
21177
|
+
}
|
|
21178
|
+
/**
|
|
21179
|
+
* Applies META AVATAR content into the canonical `meta.avatar` field.
|
|
21180
|
+
*/
|
|
21181
|
+
function applyMetaAvatarContent(state, content) {
|
|
21182
|
+
const avatarVisualId = resolveAvatarVisualId(content);
|
|
21183
|
+
if (avatarVisualId) {
|
|
21184
|
+
state.meta.avatar = avatarVisualId;
|
|
21185
|
+
return;
|
|
21186
|
+
}
|
|
21187
|
+
delete state.meta.avatar;
|
|
21188
|
+
}
|
|
21189
|
+
/**
|
|
21190
|
+
* Applies META LINK content into links and the canonical `meta.link` field.
|
|
21191
|
+
*/
|
|
21192
|
+
function applyMetaLinkContent(state, content) {
|
|
21193
|
+
const linkValue = spaceTrim$1(content);
|
|
21194
|
+
state.links.push(linkValue);
|
|
21195
|
+
state.meta.link = linkValue;
|
|
21196
|
+
}
|
|
21197
|
+
/**
|
|
21198
|
+
* Applies META DOMAIN content into the normalized `meta.domain` field.
|
|
21199
|
+
*/
|
|
21200
|
+
function applyMetaDomainContent(state, content) {
|
|
21201
|
+
state.meta.domain = normalizeMetaDomain(content);
|
|
21202
|
+
}
|
|
21203
|
+
/**
|
|
21204
|
+
* Applies META IMAGE content into the canonical `meta.image` field.
|
|
21205
|
+
*/
|
|
21206
|
+
function applyMetaImageContent(state, content) {
|
|
21207
|
+
state.meta.image = spaceTrim$1(content);
|
|
21208
|
+
}
|
|
21209
|
+
/**
|
|
21210
|
+
* Applies META DESCRIPTION content into the canonical `meta.description` field.
|
|
21211
|
+
*/
|
|
21212
|
+
function applyMetaDescriptionContent(state, content) {
|
|
21213
|
+
state.meta.description = spaceTrim$1(content);
|
|
21214
|
+
}
|
|
21215
|
+
/**
|
|
21216
|
+
* Applies META DISCLAIMER content into the canonical `meta.disclaimer` field.
|
|
21217
|
+
*/
|
|
21218
|
+
function applyMetaDisclaimerContent(state, content) {
|
|
21219
|
+
state.meta.disclaimer = content;
|
|
21220
|
+
}
|
|
21221
|
+
/**
|
|
21222
|
+
* Applies META INPUT PLACEHOLDER content into the canonical `meta.inputPlaceholder` field.
|
|
21223
|
+
*/
|
|
21224
|
+
function applyMetaInputPlaceholderContent(state, content) {
|
|
21225
|
+
state.meta.inputPlaceholder = spaceTrim$1(content);
|
|
21226
|
+
}
|
|
21227
|
+
/**
|
|
21228
|
+
* Applies MESSAGE SUFFIX content into the canonical `meta.messageSuffix` field.
|
|
21229
|
+
*/
|
|
21230
|
+
function applyMessageSuffixContent(state, content) {
|
|
21231
|
+
state.meta.messageSuffix = content;
|
|
21232
|
+
}
|
|
21233
|
+
/**
|
|
21234
|
+
* Applies META COLOR content into the canonical `meta.color` field.
|
|
21235
|
+
*/
|
|
21236
|
+
function applyMetaColorContent(state, content) {
|
|
21237
|
+
state.meta.color = normalizeSeparator(content);
|
|
21238
|
+
}
|
|
21239
|
+
/**
|
|
21240
|
+
* Applies META FONT content into the canonical `meta.font` field.
|
|
21241
|
+
*/
|
|
21242
|
+
function applyMetaFontContent(state, content) {
|
|
21243
|
+
state.meta.font = normalizeSeparator(content);
|
|
21244
|
+
}
|
|
21245
|
+
/**
|
|
21246
|
+
* Applies META VOICE content into the canonical `meta.voice` field.
|
|
21247
|
+
*/
|
|
21248
|
+
function applyMetaVoiceContent(state, content) {
|
|
21249
|
+
state.meta.voice = spaceTrim$1(content);
|
|
21250
|
+
}
|
|
21251
|
+
/**
|
|
21252
|
+
* Normalizes the separator in the content
|
|
21253
|
+
*
|
|
21254
|
+
* @param content - The content to normalize
|
|
21255
|
+
* @returns The content with normalized separators
|
|
21256
|
+
*/
|
|
21257
|
+
function normalizeSeparator(content) {
|
|
21258
|
+
const trimmed = spaceTrim$1(content);
|
|
21259
|
+
if (trimmed.includes(',')) {
|
|
21260
|
+
return trimmed;
|
|
21261
|
+
}
|
|
21262
|
+
return trimmed.split(/\s+/).join(', ');
|
|
21263
|
+
}
|
|
21264
|
+
/**
|
|
21265
|
+
* Normalizes META DOMAIN content to a hostname-like value when possible.
|
|
21266
|
+
*
|
|
21267
|
+
* @param content - Raw META DOMAIN content.
|
|
21268
|
+
* @returns Normalized domain or a trimmed fallback.
|
|
21269
|
+
*/
|
|
21270
|
+
function normalizeMetaDomain(content) {
|
|
21271
|
+
const trimmed = spaceTrim$1(content);
|
|
21272
|
+
return normalizeDomainForMatching(trimmed) || trimmed.toLowerCase();
|
|
21273
|
+
}
|
|
21274
|
+
|
|
21275
|
+
/**
|
|
21276
|
+
* Updates sample-conversation state for communication commitments.
|
|
21277
|
+
*
|
|
21278
|
+
* @private internal utility of `parseAgentSource`
|
|
21279
|
+
*/
|
|
21275
21280
|
function consumeConversationSampleCommitment(state, commitment) {
|
|
21276
21281
|
switch (commitment.type) {
|
|
21277
21282
|
case 'INITIAL MESSAGE':
|
|
@@ -21293,6 +21298,76 @@ function consumeConversationSampleCommitment(state, commitment) {
|
|
|
21293
21298
|
return false;
|
|
21294
21299
|
}
|
|
21295
21300
|
}
|
|
21301
|
+
|
|
21302
|
+
/**
|
|
21303
|
+
* Static capability descriptors for commitments that map one-to-one to a visible capability.
|
|
21304
|
+
*/
|
|
21305
|
+
const SIMPLE_CAPABILITY_BY_COMMITMENT_TYPE = {
|
|
21306
|
+
'USE BROWSER': {
|
|
21307
|
+
type: 'browser',
|
|
21308
|
+
label: 'Browser',
|
|
21309
|
+
iconName: 'Globe',
|
|
21310
|
+
},
|
|
21311
|
+
'USE SEARCH ENGINE': {
|
|
21312
|
+
type: 'search-engine',
|
|
21313
|
+
label: 'Internet',
|
|
21314
|
+
iconName: 'Search',
|
|
21315
|
+
},
|
|
21316
|
+
'USE SEARCH': {
|
|
21317
|
+
type: 'search-engine',
|
|
21318
|
+
label: 'Internet',
|
|
21319
|
+
iconName: 'Search',
|
|
21320
|
+
},
|
|
21321
|
+
'USE DEEPSEARCH': {
|
|
21322
|
+
type: 'search-engine',
|
|
21323
|
+
label: 'DeepSearch',
|
|
21324
|
+
iconName: 'Search',
|
|
21325
|
+
},
|
|
21326
|
+
'USE TIME': {
|
|
21327
|
+
type: 'time',
|
|
21328
|
+
label: 'Time',
|
|
21329
|
+
iconName: 'Clock',
|
|
21330
|
+
},
|
|
21331
|
+
'USE TIMEOUT': {
|
|
21332
|
+
type: 'timeout',
|
|
21333
|
+
label: 'Timers',
|
|
21334
|
+
iconName: 'Clock',
|
|
21335
|
+
},
|
|
21336
|
+
'USE USER LOCATION': {
|
|
21337
|
+
type: 'user-location',
|
|
21338
|
+
label: 'User location',
|
|
21339
|
+
iconName: 'MapPin',
|
|
21340
|
+
},
|
|
21341
|
+
'USE EMAIL': {
|
|
21342
|
+
type: 'email',
|
|
21343
|
+
label: 'Email',
|
|
21344
|
+
iconName: 'Mail',
|
|
21345
|
+
},
|
|
21346
|
+
'USE POPUP': {
|
|
21347
|
+
type: 'popup',
|
|
21348
|
+
label: 'Popup',
|
|
21349
|
+
iconName: 'SquareArrowOutUpRight',
|
|
21350
|
+
},
|
|
21351
|
+
'USE IMAGE GENERATOR': {
|
|
21352
|
+
type: 'image-generator',
|
|
21353
|
+
label: 'Image Generator',
|
|
21354
|
+
iconName: 'Image',
|
|
21355
|
+
},
|
|
21356
|
+
'USE PRIVACY': {
|
|
21357
|
+
type: 'privacy',
|
|
21358
|
+
label: 'Privacy',
|
|
21359
|
+
iconName: 'Shield',
|
|
21360
|
+
},
|
|
21361
|
+
'USE CALENDAR': {
|
|
21362
|
+
type: 'calendar',
|
|
21363
|
+
label: 'Calendar',
|
|
21364
|
+
iconName: 'Calendar',
|
|
21365
|
+
},
|
|
21366
|
+
};
|
|
21367
|
+
/**
|
|
21368
|
+
* Detects local slash-based references used by FROM and IMPORT commitments.
|
|
21369
|
+
*/
|
|
21370
|
+
const LOCAL_AGENT_REFERENCE_PREFIXES = ['./', '../', '/'];
|
|
21296
21371
|
/**
|
|
21297
21372
|
* Creates the visible capabilities produced by one parsed commitment.
|
|
21298
21373
|
*
|
|
@@ -21322,8 +21397,6 @@ function createCapabilitiesFromCommitment(state, commitment) {
|
|
|
21322
21397
|
}
|
|
21323
21398
|
/**
|
|
21324
21399
|
* Clones one static capability descriptor for a simple capability commitment.
|
|
21325
|
-
*
|
|
21326
|
-
* @private internal utility of `parseAgentSource`
|
|
21327
21400
|
*/
|
|
21328
21401
|
function createSimpleCapability(commitmentType) {
|
|
21329
21402
|
const capability = SIMPLE_CAPABILITY_BY_COMMITMENT_TYPE[commitmentType];
|
|
@@ -21331,8 +21404,6 @@ function createSimpleCapability(commitmentType) {
|
|
|
21331
21404
|
}
|
|
21332
21405
|
/**
|
|
21333
21406
|
* Creates the USE PROJECT capability badge.
|
|
21334
|
-
*
|
|
21335
|
-
* @private internal utility of `parseAgentSource`
|
|
21336
21407
|
*/
|
|
21337
21408
|
function createProjectCapability(content) {
|
|
21338
21409
|
var _a;
|
|
@@ -21346,8 +21417,6 @@ function createProjectCapability(content) {
|
|
|
21346
21417
|
}
|
|
21347
21418
|
/**
|
|
21348
21419
|
* Creates the FROM inheritance capability when the reference should stay visible in the profile.
|
|
21349
|
-
*
|
|
21350
|
-
* @private internal utility of `parseAgentSource`
|
|
21351
21420
|
*/
|
|
21352
21421
|
function createInheritanceCapability(content) {
|
|
21353
21422
|
const reference = extractFirstCommitmentLine(content);
|
|
@@ -21374,8 +21443,6 @@ function createInheritanceCapability(content) {
|
|
|
21374
21443
|
}
|
|
21375
21444
|
/**
|
|
21376
21445
|
* Creates the IMPORT capability badge.
|
|
21377
|
-
*
|
|
21378
|
-
* @private internal utility of `parseAgentSource`
|
|
21379
21446
|
*/
|
|
21380
21447
|
function createImportCapability(content) {
|
|
21381
21448
|
const reference = extractFirstCommitmentLine(content);
|
|
@@ -21403,8 +21470,6 @@ function createImportCapability(content) {
|
|
|
21403
21470
|
}
|
|
21404
21471
|
/**
|
|
21405
21472
|
* Creates TEAM capability badges for all parsed teammates.
|
|
21406
|
-
*
|
|
21407
|
-
* @private internal utility of `parseAgentSource`
|
|
21408
21473
|
*/
|
|
21409
21474
|
function createTeamCapabilities(content) {
|
|
21410
21475
|
const teammates = parseTeamCommitmentContent(content);
|
|
@@ -21417,8 +21482,6 @@ function createTeamCapabilities(content) {
|
|
|
21417
21482
|
}
|
|
21418
21483
|
/**
|
|
21419
21484
|
* Creates the KNOWLEDGE capability badge and records URL-based knowledge sources.
|
|
21420
|
-
*
|
|
21421
|
-
* @private internal utility of `parseAgentSource`
|
|
21422
21485
|
*/
|
|
21423
21486
|
function createKnowledgeCapability(state, content) {
|
|
21424
21487
|
const trimmedContent = spaceTrim$1(content);
|
|
@@ -21433,8 +21496,6 @@ function createKnowledgeCapability(state, content) {
|
|
|
21433
21496
|
}
|
|
21434
21497
|
/**
|
|
21435
21498
|
* Stores unique URL-based knowledge sources for later citation resolution.
|
|
21436
|
-
*
|
|
21437
|
-
* @private internal utility of `parseAgentSource`
|
|
21438
21499
|
*/
|
|
21439
21500
|
function rememberKnowledgeSources(state, extractedUrls) {
|
|
21440
21501
|
for (const extractedUrl of extractedUrls) {
|
|
@@ -21458,8 +21519,6 @@ function rememberKnowledgeSources(state, extractedUrls) {
|
|
|
21458
21519
|
}
|
|
21459
21520
|
/**
|
|
21460
21521
|
* Derives the visible KNOWLEDGE badge label and icon from commitment content.
|
|
21461
|
-
*
|
|
21462
|
-
* @private internal utility of `parseAgentSource`
|
|
21463
21522
|
*/
|
|
21464
21523
|
function createKnowledgeCapabilityPresentation(content, extractedUrls) {
|
|
21465
21524
|
let label = content;
|
|
@@ -21492,8 +21551,6 @@ function createKnowledgeCapabilityPresentation(content, extractedUrls) {
|
|
|
21492
21551
|
}
|
|
21493
21552
|
/**
|
|
21494
21553
|
* Shortens text-only KNOWLEDGE commitments into the same preview label as before.
|
|
21495
|
-
*
|
|
21496
|
-
* @private internal utility of `parseAgentSource`
|
|
21497
21554
|
*/
|
|
21498
21555
|
function createKnowledgeTextLabel(content) {
|
|
21499
21556
|
const words = content.split(/\s+/);
|
|
@@ -21503,185 +21560,88 @@ function createKnowledgeTextLabel(content) {
|
|
|
21503
21560
|
return content;
|
|
21504
21561
|
}
|
|
21505
21562
|
/**
|
|
21506
|
-
*
|
|
21507
|
-
*
|
|
21508
|
-
* @private internal utility of `parseAgentSource`
|
|
21509
|
-
*/
|
|
21510
|
-
function applyMetaCommitment(state, commitment) {
|
|
21511
|
-
const applyMetaContent = META_COMMITMENT_APPLIERS[commitment.type];
|
|
21512
|
-
if (applyMetaContent) {
|
|
21513
|
-
applyMetaContent(state, commitment.content);
|
|
21514
|
-
return;
|
|
21515
|
-
}
|
|
21516
|
-
if (commitment.type === 'META') {
|
|
21517
|
-
applyGenericMetaCommitment(state, commitment.content);
|
|
21518
|
-
}
|
|
21519
|
-
}
|
|
21520
|
-
/**
|
|
21521
|
-
* Applies the generic META commitment form (`META TYPE value`).
|
|
21522
|
-
*
|
|
21523
|
-
* @private internal utility of `parseAgentSource`
|
|
21524
|
-
*/
|
|
21525
|
-
function applyGenericMetaCommitment(state, content) {
|
|
21526
|
-
const metaTypeRaw = content.split(' ')[0] || 'NONE';
|
|
21527
|
-
const metaValue = spaceTrim$1(content.substring(metaTypeRaw.length));
|
|
21528
|
-
if (metaTypeRaw === 'LINK') {
|
|
21529
|
-
state.links.push(metaValue);
|
|
21530
|
-
}
|
|
21531
|
-
if (metaTypeRaw.toUpperCase() === 'AVATAR') {
|
|
21532
|
-
applyMetaAvatarContent(state, metaValue);
|
|
21533
|
-
return;
|
|
21534
|
-
}
|
|
21535
|
-
const metaType = normalizeTo_camelCase(metaTypeRaw);
|
|
21536
|
-
state.meta[metaType] = metaValue;
|
|
21537
|
-
}
|
|
21538
|
-
/**
|
|
21539
|
-
* Applies META AVATAR content into the canonical `meta.avatar` field.
|
|
21540
|
-
*
|
|
21541
|
-
* @private internal utility of `parseAgentSource`
|
|
21542
|
-
*/
|
|
21543
|
-
function applyMetaAvatarContent(state, content) {
|
|
21544
|
-
const avatarVisualId = resolveAvatarVisualId(content);
|
|
21545
|
-
if (avatarVisualId) {
|
|
21546
|
-
state.meta.avatar = avatarVisualId;
|
|
21547
|
-
return;
|
|
21548
|
-
}
|
|
21549
|
-
delete state.meta.avatar;
|
|
21550
|
-
}
|
|
21551
|
-
/**
|
|
21552
|
-
* Applies META LINK content into links and the canonical `meta.link` field.
|
|
21553
|
-
*
|
|
21554
|
-
* @private internal utility of `parseAgentSource`
|
|
21555
|
-
*/
|
|
21556
|
-
function applyMetaLinkContent(state, content) {
|
|
21557
|
-
const linkValue = spaceTrim$1(content);
|
|
21558
|
-
state.links.push(linkValue);
|
|
21559
|
-
state.meta.link = linkValue;
|
|
21560
|
-
}
|
|
21561
|
-
/**
|
|
21562
|
-
* Applies META DOMAIN content into the normalized `meta.domain` field.
|
|
21563
|
-
*
|
|
21564
|
-
* @private internal utility of `parseAgentSource`
|
|
21565
|
-
*/
|
|
21566
|
-
function applyMetaDomainContent(state, content) {
|
|
21567
|
-
state.meta.domain = normalizeMetaDomain(content);
|
|
21568
|
-
}
|
|
21569
|
-
/**
|
|
21570
|
-
* Applies META IMAGE content into the canonical `meta.image` field.
|
|
21571
|
-
*
|
|
21572
|
-
* @private internal utility of `parseAgentSource`
|
|
21573
|
-
*/
|
|
21574
|
-
function applyMetaImageContent(state, content) {
|
|
21575
|
-
state.meta.image = spaceTrim$1(content);
|
|
21576
|
-
}
|
|
21577
|
-
/**
|
|
21578
|
-
* Applies META DESCRIPTION content into the canonical `meta.description` field.
|
|
21579
|
-
*
|
|
21580
|
-
* @private internal utility of `parseAgentSource`
|
|
21581
|
-
*/
|
|
21582
|
-
function applyMetaDescriptionContent(state, content) {
|
|
21583
|
-
state.meta.description = spaceTrim$1(content);
|
|
21584
|
-
}
|
|
21585
|
-
/**
|
|
21586
|
-
* Applies META DISCLAIMER content into the canonical `meta.disclaimer` field.
|
|
21587
|
-
*
|
|
21588
|
-
* @private internal utility of `parseAgentSource`
|
|
21589
|
-
*/
|
|
21590
|
-
function applyMetaDisclaimerContent(state, content) {
|
|
21591
|
-
state.meta.disclaimer = content;
|
|
21592
|
-
}
|
|
21593
|
-
/**
|
|
21594
|
-
* Applies META INPUT PLACEHOLDER content into the canonical `meta.inputPlaceholder` field.
|
|
21595
|
-
*
|
|
21596
|
-
* @private internal utility of `parseAgentSource`
|
|
21597
|
-
*/
|
|
21598
|
-
function applyMetaInputPlaceholderContent(state, content) {
|
|
21599
|
-
state.meta.inputPlaceholder = spaceTrim$1(content);
|
|
21600
|
-
}
|
|
21601
|
-
/**
|
|
21602
|
-
* Applies MESSAGE SUFFIX content into the canonical `meta.messageSuffix` field.
|
|
21603
|
-
*
|
|
21604
|
-
* @private internal utility of `parseAgentSource`
|
|
21605
|
-
*/
|
|
21606
|
-
function applyMessageSuffixContent(state, content) {
|
|
21607
|
-
state.meta.messageSuffix = content;
|
|
21608
|
-
}
|
|
21609
|
-
/**
|
|
21610
|
-
* Applies META COLOR content into the canonical `meta.color` field.
|
|
21611
|
-
*
|
|
21612
|
-
* @private internal utility of `parseAgentSource`
|
|
21613
|
-
*/
|
|
21614
|
-
function applyMetaColorContent(state, content) {
|
|
21615
|
-
state.meta.color = normalizeSeparator(content);
|
|
21616
|
-
}
|
|
21617
|
-
/**
|
|
21618
|
-
* Applies META FONT content into the canonical `meta.font` field.
|
|
21619
|
-
*
|
|
21620
|
-
* @private internal utility of `parseAgentSource`
|
|
21621
|
-
*/
|
|
21622
|
-
function applyMetaFontContent(state, content) {
|
|
21623
|
-
state.meta.font = normalizeSeparator(content);
|
|
21624
|
-
}
|
|
21625
|
-
/**
|
|
21626
|
-
* Applies META VOICE content into the canonical `meta.voice` field.
|
|
21627
|
-
*
|
|
21628
|
-
* @private internal utility of `parseAgentSource`
|
|
21629
|
-
*/
|
|
21630
|
-
function applyMetaVoiceContent(state, content) {
|
|
21631
|
-
state.meta.voice = spaceTrim$1(content);
|
|
21632
|
-
}
|
|
21633
|
-
/**
|
|
21634
|
-
* Ensures the parsed profile always exposes a fullname value.
|
|
21635
|
-
*
|
|
21636
|
-
* @private internal utility of `parseAgentSource`
|
|
21637
|
-
*/
|
|
21638
|
-
function ensureMetaFullname(meta, fallbackFullname) {
|
|
21639
|
-
if (!meta.fullname) {
|
|
21640
|
-
meta.fullname = fallbackFullname;
|
|
21641
|
-
}
|
|
21642
|
-
}
|
|
21643
|
-
/**
|
|
21644
|
-
* Extracts the first logical line from multiline commitment content.
|
|
21645
|
-
*
|
|
21646
|
-
* @private internal utility of `parseAgentSource`
|
|
21563
|
+
* Extracts the first logical line from multiline commitment content.
|
|
21647
21564
|
*/
|
|
21648
21565
|
function extractFirstCommitmentLine(content) {
|
|
21649
21566
|
return spaceTrim$1(content).split(/\r?\n/)[0] || '';
|
|
21650
21567
|
}
|
|
21651
21568
|
/**
|
|
21652
21569
|
* Detects local FROM/IMPORT references that should use local-link labels and icons.
|
|
21653
|
-
*
|
|
21654
|
-
* @private internal utility of `parseAgentSource`
|
|
21655
21570
|
*/
|
|
21656
21571
|
function isLocalAgentReference(reference) {
|
|
21657
21572
|
return LOCAL_AGENT_REFERENCE_PREFIXES.some((prefix) => reference.startsWith(prefix));
|
|
21658
21573
|
}
|
|
21574
|
+
|
|
21659
21575
|
/**
|
|
21660
|
-
*
|
|
21661
|
-
*
|
|
21662
|
-
* @param content - The content to normalize
|
|
21663
|
-
* @returns The content with normalized separators
|
|
21576
|
+
* Collects capability, sample, meta, link, and knowledge-source data from commitments.
|
|
21664
21577
|
*
|
|
21665
21578
|
* @private internal utility of `parseAgentSource`
|
|
21666
21579
|
*/
|
|
21667
|
-
function
|
|
21668
|
-
const
|
|
21669
|
-
|
|
21670
|
-
|
|
21580
|
+
function extractParsedAgentProfile(commitments) {
|
|
21581
|
+
const state = {
|
|
21582
|
+
meta: {},
|
|
21583
|
+
links: [],
|
|
21584
|
+
capabilities: [],
|
|
21585
|
+
samples: [],
|
|
21586
|
+
knowledgeSources: [],
|
|
21587
|
+
pendingUserMessage: null,
|
|
21588
|
+
knownKnowledgeSourceUrls: new Set(),
|
|
21589
|
+
};
|
|
21590
|
+
for (const commitment of commitments) {
|
|
21591
|
+
processParsedCommitment(state, commitment);
|
|
21671
21592
|
}
|
|
21672
|
-
return
|
|
21593
|
+
return {
|
|
21594
|
+
meta: state.meta,
|
|
21595
|
+
links: state.links,
|
|
21596
|
+
capabilities: state.capabilities,
|
|
21597
|
+
samples: state.samples,
|
|
21598
|
+
knowledgeSources: state.knowledgeSources,
|
|
21599
|
+
};
|
|
21673
21600
|
}
|
|
21674
21601
|
/**
|
|
21675
|
-
*
|
|
21602
|
+
* Processes one parsed commitment through the sample, capability, and meta stages.
|
|
21603
|
+
*/
|
|
21604
|
+
function processParsedCommitment(state, commitment) {
|
|
21605
|
+
if (consumeConversationSampleCommitment(state, commitment)) {
|
|
21606
|
+
return;
|
|
21607
|
+
}
|
|
21608
|
+
const capabilities = createCapabilitiesFromCommitment(state, commitment);
|
|
21609
|
+
if (capabilities.length > 0) {
|
|
21610
|
+
state.capabilities.push(...capabilities);
|
|
21611
|
+
return;
|
|
21612
|
+
}
|
|
21613
|
+
applyMetaCommitment(state, commitment);
|
|
21614
|
+
}
|
|
21615
|
+
|
|
21616
|
+
/**
|
|
21617
|
+
* Parses basic information from agent source
|
|
21676
21618
|
*
|
|
21677
|
-
*
|
|
21678
|
-
*
|
|
21619
|
+
* There are 2 similar functions:
|
|
21620
|
+
* - `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.
|
|
21621
|
+
* - `createAgentModelRequirements` which is an asynchronous function that creates model requirements it applies each commitment one by one and works asynchronously.
|
|
21679
21622
|
*
|
|
21680
|
-
* @
|
|
21623
|
+
* @public exported from `@promptbook/core`
|
|
21681
21624
|
*/
|
|
21682
|
-
function
|
|
21683
|
-
const
|
|
21684
|
-
|
|
21625
|
+
function parseAgentSource(agentSource) {
|
|
21626
|
+
const parseResult = parseAgentSourceWithCommitments(agentSource);
|
|
21627
|
+
const resolvedAgentName = parseResult.agentName || createDefaultAgentName(agentSource);
|
|
21628
|
+
const personaDescription = extractAgentProfileText(parseResult.commitments);
|
|
21629
|
+
const initialMessage = extractInitialMessage(parseResult.commitments);
|
|
21630
|
+
const parsedProfile = extractParsedAgentProfile(parseResult.commitments);
|
|
21631
|
+
ensureMetaFullname(parsedProfile.meta, resolvedAgentName);
|
|
21632
|
+
return {
|
|
21633
|
+
agentName: normalizeAgentName(resolvedAgentName),
|
|
21634
|
+
agentHash: computeAgentHash(agentSource),
|
|
21635
|
+
permanentId: parsedProfile.meta.id,
|
|
21636
|
+
personaDescription,
|
|
21637
|
+
initialMessage,
|
|
21638
|
+
meta: parsedProfile.meta,
|
|
21639
|
+
links: parsedProfile.links,
|
|
21640
|
+
parameters: parseParameters(agentSource),
|
|
21641
|
+
capabilities: parsedProfile.capabilities,
|
|
21642
|
+
samples: parsedProfile.samples,
|
|
21643
|
+
knowledgeSources: parsedProfile.knowledgeSources,
|
|
21644
|
+
};
|
|
21685
21645
|
}
|
|
21686
21646
|
// TODO: [🕛] Unite `AgentBasicInformation`, `ChatParticipant`, `LlmExecutionTools` + `LlmToolsMetadata`
|
|
21687
21647
|
|
|
@@ -26547,321 +26507,22 @@ function getCommitmentDefinition(type) {
|
|
|
26547
26507
|
}
|
|
26548
26508
|
|
|
26549
26509
|
/**
|
|
26550
|
-
*
|
|
26510
|
+
* Commitment types whose content may contain compact agent references that must be resolved before applying the commitment.
|
|
26551
26511
|
*
|
|
26552
|
-
* @private
|
|
26512
|
+
* @private internal constant of `applyCommitmentsToAgentModelRequirements`
|
|
26553
26513
|
*/
|
|
26554
|
-
const
|
|
26555
|
-
name: 'agent-file-import-plugin',
|
|
26556
|
-
canImport(mimeType) {
|
|
26557
|
-
// [🧠] Should we have a specific MIME type for agent books?
|
|
26558
|
-
// For now, let's assume it's identified by .book extension or certain MIME types if provided
|
|
26559
|
-
return mimeType === 'text/x-promptbook' || mimeType === 'application/x-promptbook';
|
|
26560
|
-
},
|
|
26561
|
-
import(content) {
|
|
26562
|
-
const parseResult = parseAgentSourceWithCommitments(content);
|
|
26563
|
-
// Bring only the agent corpus (non-commitment lines and relevant commitments)
|
|
26564
|
-
// Stripping the agent name (which is usually the first line)
|
|
26565
|
-
const corpus = parseResult.nonCommitmentLines
|
|
26566
|
-
.filter((line, index) => index > 0 || !parseResult.agentName)
|
|
26567
|
-
.join('\n')
|
|
26568
|
-
.trim();
|
|
26569
|
-
// Also include relevant commitments that make up the "corpus" of the agent
|
|
26570
|
-
// For example PERSONA, RULE, KNOWLEDGE
|
|
26571
|
-
const relevantCommitments = parseResult.commitments
|
|
26572
|
-
.filter((c) => ['PERSONA', 'RULE', 'KNOWLEDGE'].includes(c.type))
|
|
26573
|
-
.map((c) => `${c.type} ${c.content}`)
|
|
26574
|
-
.join('\n\n');
|
|
26575
|
-
return spaceTrim$1((block) => `
|
|
26576
|
-
${block(relevantCommitments)}
|
|
26577
|
-
|
|
26578
|
-
${block(corpus)}
|
|
26579
|
-
`).trim();
|
|
26580
|
-
},
|
|
26581
|
-
};
|
|
26582
|
-
|
|
26514
|
+
const COMMITMENTS_WITH_AGENT_REFERENCES = new Set(['FROM', 'IMPORT', 'IMPORTS', 'TEAM']);
|
|
26583
26515
|
/**
|
|
26584
|
-
*
|
|
26516
|
+
* Applies parsed commitments one by one while keeping the per-commitment steps focused and easy to follow.
|
|
26585
26517
|
*
|
|
26586
|
-
* @
|
|
26518
|
+
* @param requirements - Current requirements snapshot.
|
|
26519
|
+
* @param commitments - Commitments already filtered for DELETE-like invalidations.
|
|
26520
|
+
* @param options - Optional reference and teammate resolvers.
|
|
26521
|
+
* @returns Requirements after all applicable commitments are processed.
|
|
26522
|
+
*
|
|
26523
|
+
* @private function of `createAgentModelRequirementsWithCommitments`
|
|
26587
26524
|
*/
|
|
26588
|
-
|
|
26589
|
-
name: 'json-file-import-plugin',
|
|
26590
|
-
canImport(mimeType) {
|
|
26591
|
-
return mimeType === 'application/json' || mimeType.endsWith('+json');
|
|
26592
|
-
},
|
|
26593
|
-
import(content) {
|
|
26594
|
-
try {
|
|
26595
|
-
const json = JSON.parse(content);
|
|
26596
|
-
const formattedJson = JSON.stringify(json, null, 4);
|
|
26597
|
-
return `\`\`\`json\n${formattedJson}\n\`\`\``;
|
|
26598
|
-
}
|
|
26599
|
-
catch (error) {
|
|
26600
|
-
// If JSON is invalid, still import it but maybe not as pretty JSON
|
|
26601
|
-
return `\`\`\`json\n${content}\n\`\`\``;
|
|
26602
|
-
}
|
|
26603
|
-
},
|
|
26604
|
-
};
|
|
26605
|
-
|
|
26606
|
-
/**
|
|
26607
|
-
* Plugin for importing generic text files
|
|
26608
|
-
*
|
|
26609
|
-
* @private [🥝] Maybe export the import plugins through some package
|
|
26610
|
-
*/
|
|
26611
|
-
const TextFileImportPlugin = {
|
|
26612
|
-
name: 'text-file-import-plugin',
|
|
26613
|
-
canImport(mimeType) {
|
|
26614
|
-
return (mimeType === 'text/plain' ||
|
|
26615
|
-
mimeType === 'text/markdown' ||
|
|
26616
|
-
mimeType === 'text/x-typescript' ||
|
|
26617
|
-
mimeType === 'text/javascript' ||
|
|
26618
|
-
mimeType === 'text/css' ||
|
|
26619
|
-
mimeType === 'text/html' ||
|
|
26620
|
-
mimeType.startsWith('text/'));
|
|
26621
|
-
},
|
|
26622
|
-
import(content, mimeType) {
|
|
26623
|
-
const extension = mimeTypeToExtension(mimeType);
|
|
26624
|
-
const codeBlockType = extension || 'txt';
|
|
26625
|
-
return `\`\`\`${codeBlockType}\n${content}\n\`\`\``;
|
|
26626
|
-
},
|
|
26627
|
-
};
|
|
26628
|
-
|
|
26629
|
-
/**
|
|
26630
|
-
* All available file import plugins
|
|
26631
|
-
*
|
|
26632
|
-
* @private [🥝] Maybe export the import plugins through some package
|
|
26633
|
-
*/
|
|
26634
|
-
const $fileImportPlugins = [
|
|
26635
|
-
AgentFileImportPlugin,
|
|
26636
|
-
JsonFileImportPlugin,
|
|
26637
|
-
TextFileImportPlugin,
|
|
26638
|
-
];
|
|
26639
|
-
|
|
26640
|
-
/**
|
|
26641
|
-
* Removes single-hash comment lines (`# Comment`) from a system message
|
|
26642
|
-
* This is used to clean up the final system message before sending it to the AI model
|
|
26643
|
-
* while preserving the original content with comments in metadata
|
|
26644
|
-
*
|
|
26645
|
-
* @param systemMessage The system message that may contain comment lines
|
|
26646
|
-
* @returns The system message with single-hash comment lines removed
|
|
26647
|
-
*
|
|
26648
|
-
* @private - TODO: [🧠] Maybe should be public?
|
|
26649
|
-
*/
|
|
26650
|
-
function removeCommentsFromSystemMessage(systemMessage) {
|
|
26651
|
-
if (!systemMessage) {
|
|
26652
|
-
return systemMessage;
|
|
26653
|
-
}
|
|
26654
|
-
const lines = systemMessage.split(/\r?\n/);
|
|
26655
|
-
const filteredLines = lines.filter((line) => {
|
|
26656
|
-
const trimmedLine = line.trim();
|
|
26657
|
-
// Remove only single-hash comment markers (`# Comment`) and keep markdown headings (`## Heading`).
|
|
26658
|
-
return !/^#(?!#)\s/.test(trimmedLine);
|
|
26659
|
-
});
|
|
26660
|
-
return filteredLines.join('\n').trim();
|
|
26661
|
-
}
|
|
26662
|
-
|
|
26663
|
-
/**
|
|
26664
|
-
* Commitment types whose content may contain compact agent references that must be resolved before applying the commitment.
|
|
26665
|
-
*
|
|
26666
|
-
* @private internal constant of `createAgentModelRequirementsWithCommitments`
|
|
26667
|
-
*/
|
|
26668
|
-
const COMMITMENTS_WITH_AGENT_REFERENCES = new Set(['FROM', 'IMPORT', 'IMPORTS', 'TEAM']);
|
|
26669
|
-
/**
|
|
26670
|
-
* DELETE-like commitment types that invalidate earlier tagged commitments.
|
|
26671
|
-
*
|
|
26672
|
-
* @private internal constant of `createAgentModelRequirementsWithCommitments`
|
|
26673
|
-
*/
|
|
26674
|
-
const DELETE_COMMITMENT_TYPES = new Set(['DELETE', 'CANCEL', 'DISCARD', 'REMOVE']);
|
|
26675
|
-
/**
|
|
26676
|
-
* Commitments whose earlier occurrences are overwritten by the last occurrence in source order.
|
|
26677
|
-
*
|
|
26678
|
-
* @private internal constant of `createAgentModelRequirementsWithCommitments`
|
|
26679
|
-
*/
|
|
26680
|
-
const OVERWRITTEN_COMMITMENT_GROUP_BY_TYPE = new Map([
|
|
26681
|
-
['GOAL', 'GOAL'],
|
|
26682
|
-
['GOALS', 'GOAL'],
|
|
26683
|
-
]);
|
|
26684
|
-
/**
|
|
26685
|
-
* Regex pattern matching markdown horizontal lines that should not be copied into the final system message.
|
|
26686
|
-
*
|
|
26687
|
-
* @private internal constant of `createAgentModelRequirementsWithCommitments`
|
|
26688
|
-
*/
|
|
26689
|
-
const HORIZONTAL_LINE_PATTERN = /^[\s]*[-_*][\s]*[-_*][\s]*[-_*][\s]*[-_*]*[\s]*$/;
|
|
26690
|
-
/**
|
|
26691
|
-
* MIME type prefixes treated as binary and therefore not eligible for text import plugins.
|
|
26692
|
-
*
|
|
26693
|
-
* @private internal constant of `createAgentModelRequirementsWithCommitments`
|
|
26694
|
-
*/
|
|
26695
|
-
const BINARY_MIME_TYPE_PREFIXES = [
|
|
26696
|
-
'image/',
|
|
26697
|
-
'video/',
|
|
26698
|
-
'audio/',
|
|
26699
|
-
'application/octet-stream',
|
|
26700
|
-
'application/pdf',
|
|
26701
|
-
'application/zip',
|
|
26702
|
-
];
|
|
26703
|
-
/**
|
|
26704
|
-
* Returns a safe fallback content when a resolver fails to transform a reference commitment.
|
|
26705
|
-
*
|
|
26706
|
-
* @param commitmentType - Commitment being resolved.
|
|
26707
|
-
* @param originalContent - Original unresolved commitment content.
|
|
26708
|
-
* @returns Fallback content that keeps requirement creation resilient.
|
|
26709
|
-
*
|
|
26710
|
-
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
26711
|
-
*/
|
|
26712
|
-
function getSafeReferenceCommitmentFallback(commitmentType, originalContent) {
|
|
26713
|
-
if (commitmentType === 'FROM') {
|
|
26714
|
-
return 'VOID';
|
|
26715
|
-
}
|
|
26716
|
-
if (commitmentType === 'IMPORT' || commitmentType === 'IMPORTS' || commitmentType === 'TEAM') {
|
|
26717
|
-
return '';
|
|
26718
|
-
}
|
|
26719
|
-
return originalContent;
|
|
26720
|
-
}
|
|
26721
|
-
/**
|
|
26722
|
-
* Creates agent model requirements by parsing commitments, applying them in source order,
|
|
26723
|
-
* and finalizing derived sections such as imports, example interactions, and inline knowledge uploads.
|
|
26724
|
-
*
|
|
26725
|
-
* @param agentSource - Agent source book to parse.
|
|
26726
|
-
* @param modelName - Optional override for the agent model name.
|
|
26727
|
-
* @param options - Additional options such as reference and teammate resolvers.
|
|
26728
|
-
* @returns Fully prepared model requirements for the parsed agent source.
|
|
26729
|
-
*
|
|
26730
|
-
* @private internal utility of `createAgentModelRequirements`
|
|
26731
|
-
*/
|
|
26732
|
-
async function createAgentModelRequirementsWithCommitments(agentSource, modelName, options) {
|
|
26733
|
-
const parseResult = parseAgentSourceWithCommitments(agentSource);
|
|
26734
|
-
const filteredCommitments = filterOverwrittenCommitments(filterDeletedCommitments(parseResult.commitments));
|
|
26735
|
-
let requirements = createInitialAgentModelRequirements(parseResult.agentName, modelName);
|
|
26736
|
-
requirements = await applyCommitmentsToRequirements(requirements, filteredCommitments, options);
|
|
26737
|
-
requirements = aggregateUseCommitmentSystemMessages(requirements, filteredCommitments);
|
|
26738
|
-
requirements = await importReferencedFiles(requirements);
|
|
26739
|
-
requirements = appendMcpServers(requirements, agentSource);
|
|
26740
|
-
requirements = appendNonCommitmentContent(requirements, parseResult);
|
|
26741
|
-
requirements = appendExampleInteractions(requirements, parseResult);
|
|
26742
|
-
requirements = await applyPendingInlineKnowledgeSources(requirements, options === null || options === void 0 ? void 0 : options.inlineKnowledgeSourceUploader);
|
|
26743
|
-
return finalizeRequirements(requirements);
|
|
26744
|
-
}
|
|
26745
|
-
/**
|
|
26746
|
-
* Removes earlier commitments that are overwritten by later commitments of the same semantic group.
|
|
26747
|
-
*
|
|
26748
|
-
* This currently keeps only the last `GOAL` / `GOALS` commitment so inheritance rewrites
|
|
26749
|
-
* and multi-goal sources expose one effective goal to the runtime.
|
|
26750
|
-
*
|
|
26751
|
-
* @param commitments - Parsed commitments after DELETE-like filtering.
|
|
26752
|
-
* @returns Commitments with overwritten entries removed while preserving source order.
|
|
26753
|
-
*
|
|
26754
|
-
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
26755
|
-
*/
|
|
26756
|
-
function filterOverwrittenCommitments(commitments) {
|
|
26757
|
-
const seenOverwriteGroups = new Set();
|
|
26758
|
-
const keptCommitments = [];
|
|
26759
|
-
for (let index = commitments.length - 1; index >= 0; index--) {
|
|
26760
|
-
const commitment = commitments[index];
|
|
26761
|
-
const overwriteGroup = OVERWRITTEN_COMMITMENT_GROUP_BY_TYPE.get(commitment.type);
|
|
26762
|
-
if (!overwriteGroup) {
|
|
26763
|
-
keptCommitments.push(commitment);
|
|
26764
|
-
continue;
|
|
26765
|
-
}
|
|
26766
|
-
if (seenOverwriteGroups.has(overwriteGroup)) {
|
|
26767
|
-
continue;
|
|
26768
|
-
}
|
|
26769
|
-
seenOverwriteGroups.add(overwriteGroup);
|
|
26770
|
-
keptCommitments.push(commitment);
|
|
26771
|
-
}
|
|
26772
|
-
return keptCommitments.reverse();
|
|
26773
|
-
}
|
|
26774
|
-
/**
|
|
26775
|
-
* Creates the initial requirements object with the parsed agent name stored in metadata and an optional model override.
|
|
26776
|
-
*
|
|
26777
|
-
* @param agentName - Parsed agent name from the source prelude.
|
|
26778
|
-
* @param modelName - Optional explicit model name override.
|
|
26779
|
-
* @returns Initial requirements before any commitment is applied.
|
|
26780
|
-
*
|
|
26781
|
-
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
26782
|
-
*/
|
|
26783
|
-
function createInitialAgentModelRequirements(agentName, modelName) {
|
|
26784
|
-
const initialRequirements = createBasicAgentModelRequirements(agentName);
|
|
26785
|
-
const requirementsWithMetadata = {
|
|
26786
|
-
...initialRequirements,
|
|
26787
|
-
_metadata: {
|
|
26788
|
-
...initialRequirements._metadata,
|
|
26789
|
-
agentName,
|
|
26790
|
-
},
|
|
26791
|
-
};
|
|
26792
|
-
if (!modelName) {
|
|
26793
|
-
return requirementsWithMetadata;
|
|
26794
|
-
}
|
|
26795
|
-
return {
|
|
26796
|
-
...requirementsWithMetadata,
|
|
26797
|
-
modelName,
|
|
26798
|
-
};
|
|
26799
|
-
}
|
|
26800
|
-
/**
|
|
26801
|
-
* Applies DELETE-like invalidation commitments and returns only commitments that should continue through the pipeline.
|
|
26802
|
-
*
|
|
26803
|
-
* @param commitments - Parsed commitments in original source order.
|
|
26804
|
-
* @returns Filtered commitments with earlier deleted items removed.
|
|
26805
|
-
*
|
|
26806
|
-
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
26807
|
-
*/
|
|
26808
|
-
function filterDeletedCommitments(commitments) {
|
|
26809
|
-
const filteredCommitments = [];
|
|
26810
|
-
for (const commitment of commitments) {
|
|
26811
|
-
if (!isDeleteCommitmentType(commitment.type)) {
|
|
26812
|
-
filteredCommitments.push(commitment);
|
|
26813
|
-
continue;
|
|
26814
|
-
}
|
|
26815
|
-
const targetParameterNames = getCommitmentParameterNames(commitment.content);
|
|
26816
|
-
if (targetParameterNames.length === 0) {
|
|
26817
|
-
continue;
|
|
26818
|
-
}
|
|
26819
|
-
for (let index = filteredCommitments.length - 1; index >= 0; index--) {
|
|
26820
|
-
const previousCommitment = filteredCommitments[index];
|
|
26821
|
-
const previousParameterNames = getCommitmentParameterNames(previousCommitment.content);
|
|
26822
|
-
const isTargeted = previousParameterNames.some((parameterName) => targetParameterNames.includes(parameterName));
|
|
26823
|
-
if (isTargeted) {
|
|
26824
|
-
filteredCommitments.splice(index, 1);
|
|
26825
|
-
}
|
|
26826
|
-
}
|
|
26827
|
-
}
|
|
26828
|
-
return filteredCommitments;
|
|
26829
|
-
}
|
|
26830
|
-
/**
|
|
26831
|
-
* Checks whether a commitment type behaves like DELETE and therefore invalidates earlier tagged commitments.
|
|
26832
|
-
*
|
|
26833
|
-
* @param commitmentType - Commitment type to check.
|
|
26834
|
-
* @returns `true` when the commitment removes prior tagged commitments.
|
|
26835
|
-
*
|
|
26836
|
-
* @private internal utility of `filterDeletedCommitments`
|
|
26837
|
-
*/
|
|
26838
|
-
function isDeleteCommitmentType(commitmentType) {
|
|
26839
|
-
return DELETE_COMMITMENT_TYPES.has(commitmentType);
|
|
26840
|
-
}
|
|
26841
|
-
/**
|
|
26842
|
-
* Extracts normalized parameter names used for DELETE-like invalidation matching.
|
|
26843
|
-
*
|
|
26844
|
-
* @param content - Commitment content to parse.
|
|
26845
|
-
* @returns Lower-cased non-empty parameter names.
|
|
26846
|
-
*
|
|
26847
|
-
* @private internal utility of `filterDeletedCommitments`
|
|
26848
|
-
*/
|
|
26849
|
-
function getCommitmentParameterNames(content) {
|
|
26850
|
-
return parseParameters(content)
|
|
26851
|
-
.map((parameter) => parameter.name.trim().toLowerCase())
|
|
26852
|
-
.filter(Boolean);
|
|
26853
|
-
}
|
|
26854
|
-
/**
|
|
26855
|
-
* Applies parsed commitments one by one while keeping the per-commitment steps focused and easy to follow.
|
|
26856
|
-
*
|
|
26857
|
-
* @param requirements - Current requirements snapshot.
|
|
26858
|
-
* @param commitments - Commitments already filtered for DELETE-like invalidations.
|
|
26859
|
-
* @param options - Optional reference and teammate resolvers.
|
|
26860
|
-
* @returns Requirements after all applicable commitments are processed.
|
|
26861
|
-
*
|
|
26862
|
-
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
26863
|
-
*/
|
|
26864
|
-
async function applyCommitmentsToRequirements(requirements, commitments, options) {
|
|
26525
|
+
async function applyCommitmentsToAgentModelRequirements(requirements, commitments, options) {
|
|
26865
26526
|
for (const [index, commitment] of commitments.entries()) {
|
|
26866
26527
|
if (shouldSkipCommitmentApplication(commitment, index, commitments.length)) {
|
|
26867
26528
|
continue;
|
|
@@ -26879,7 +26540,7 @@ async function applyCommitmentsToRequirements(requirements, commitments, options
|
|
|
26879
26540
|
* @param agentReferenceResolver - Optional resolver for compact agent references.
|
|
26880
26541
|
* @returns Original or resolved commitment content.
|
|
26881
26542
|
*
|
|
26882
|
-
* @private internal utility of `
|
|
26543
|
+
* @private internal utility of `applyCommitmentsToAgentModelRequirements`
|
|
26883
26544
|
*/
|
|
26884
26545
|
async function resolveCommitmentContent(commitment, agentReferenceResolver) {
|
|
26885
26546
|
if (!agentReferenceResolver || !isAgentReferenceCommitment(commitment.type)) {
|
|
@@ -26893,6 +26554,24 @@ async function resolveCommitmentContent(commitment, agentReferenceResolver) {
|
|
|
26893
26554
|
return getSafeReferenceCommitmentFallback(commitment.type, commitment.content);
|
|
26894
26555
|
}
|
|
26895
26556
|
}
|
|
26557
|
+
/**
|
|
26558
|
+
* Returns a safe fallback content when a resolver fails to transform a reference commitment.
|
|
26559
|
+
*
|
|
26560
|
+
* @param commitmentType - Commitment being resolved.
|
|
26561
|
+
* @param originalContent - Original unresolved commitment content.
|
|
26562
|
+
* @returns Fallback content that keeps requirement creation resilient.
|
|
26563
|
+
*
|
|
26564
|
+
* @private internal utility of `applyCommitmentsToAgentModelRequirements`
|
|
26565
|
+
*/
|
|
26566
|
+
function getSafeReferenceCommitmentFallback(commitmentType, originalContent) {
|
|
26567
|
+
if (commitmentType === 'FROM') {
|
|
26568
|
+
return 'VOID';
|
|
26569
|
+
}
|
|
26570
|
+
if (commitmentType === 'IMPORT' || commitmentType === 'IMPORTS' || commitmentType === 'TEAM') {
|
|
26571
|
+
return '';
|
|
26572
|
+
}
|
|
26573
|
+
return originalContent;
|
|
26574
|
+
}
|
|
26896
26575
|
/**
|
|
26897
26576
|
* Checks whether the commitment content may need agent-reference resolution before application.
|
|
26898
26577
|
*
|
|
@@ -26912,7 +26591,7 @@ function isAgentReferenceCommitment(commitmentType) {
|
|
|
26912
26591
|
* @param commitmentCount - Total number of filtered commitments.
|
|
26913
26592
|
* @returns `true` when the commitment should not be applied.
|
|
26914
26593
|
*
|
|
26915
|
-
* @private internal utility of `
|
|
26594
|
+
* @private internal utility of `applyCommitmentsToAgentModelRequirements`
|
|
26916
26595
|
*/
|
|
26917
26596
|
function shouldSkipCommitmentApplication(commitment, commitmentIndex, commitmentCount) {
|
|
26918
26597
|
return commitment.type === 'CLOSED' && commitmentIndex !== commitmentCount - 1;
|
|
@@ -26926,7 +26605,7 @@ function shouldSkipCommitmentApplication(commitment, commitmentIndex, commitment
|
|
|
26926
26605
|
* @param options - Optional teammate profile resolvers.
|
|
26927
26606
|
* @returns Requirements with pre-resolved teammate profiles stored in metadata when possible.
|
|
26928
26607
|
*
|
|
26929
|
-
* @private internal utility of `
|
|
26608
|
+
* @private internal utility of `applyCommitmentsToAgentModelRequirements`
|
|
26930
26609
|
*/
|
|
26931
26610
|
async function preResolveTeammateProfilesForTeamCommitment(requirements, commitment, commitmentContent, options) {
|
|
26932
26611
|
var _a;
|
|
@@ -26965,36 +26644,163 @@ async function preResolveTeammateProfilesForTeamCommitment(requirements, commitm
|
|
|
26965
26644
|
* @param metadata - Current requirements metadata.
|
|
26966
26645
|
* @returns Mutable copy of the cached teammate profile map.
|
|
26967
26646
|
*
|
|
26968
|
-
* @private internal utility of `preResolveTeammateProfilesForTeamCommitment`
|
|
26647
|
+
* @private internal utility of `preResolveTeammateProfilesForTeamCommitment`
|
|
26648
|
+
*/
|
|
26649
|
+
function clonePreResolvedTeammateProfiles(metadata) {
|
|
26650
|
+
var _a;
|
|
26651
|
+
return {
|
|
26652
|
+
...((_a = metadata === null || metadata === void 0 ? void 0 : metadata.preResolvedTeammateProfiles) !== null && _a !== void 0 ? _a : {}),
|
|
26653
|
+
};
|
|
26654
|
+
}
|
|
26655
|
+
/**
|
|
26656
|
+
* Applies the registered commitment definition while isolating the failure handling from the main loop.
|
|
26657
|
+
*
|
|
26658
|
+
* @param requirements - Current requirements snapshot.
|
|
26659
|
+
* @param commitment - Commitment whose definition should be applied.
|
|
26660
|
+
* @param commitmentContent - Final content passed into the definition.
|
|
26661
|
+
* @returns Updated requirements, or the original requirements when the commitment fails.
|
|
26662
|
+
*
|
|
26663
|
+
* @private internal utility of `applyCommitmentsToAgentModelRequirements`
|
|
26664
|
+
*/
|
|
26665
|
+
function applyCommitmentDefinitionSafely(requirements, commitment, commitmentContent) {
|
|
26666
|
+
const definition = getCommitmentDefinition(commitment.type);
|
|
26667
|
+
if (!definition) {
|
|
26668
|
+
return requirements;
|
|
26669
|
+
}
|
|
26670
|
+
try {
|
|
26671
|
+
return definition.applyToAgentModelRequirements(requirements, commitmentContent);
|
|
26672
|
+
}
|
|
26673
|
+
catch (error) {
|
|
26674
|
+
console.warn(`Failed to apply commitment ${commitment.type}:`, error);
|
|
26675
|
+
return requirements;
|
|
26676
|
+
}
|
|
26677
|
+
}
|
|
26678
|
+
|
|
26679
|
+
/**
|
|
26680
|
+
* Plugin for importing agent books *(`.book` files)*
|
|
26681
|
+
*
|
|
26682
|
+
* @private [🥝] Maybe export the import plugins through some package
|
|
26683
|
+
*/
|
|
26684
|
+
const AgentFileImportPlugin = {
|
|
26685
|
+
name: 'agent-file-import-plugin',
|
|
26686
|
+
canImport(mimeType) {
|
|
26687
|
+
// [🧠] Should we have a specific MIME type for agent books?
|
|
26688
|
+
// For now, let's assume it's identified by .book extension or certain MIME types if provided
|
|
26689
|
+
return mimeType === 'text/x-promptbook' || mimeType === 'application/x-promptbook';
|
|
26690
|
+
},
|
|
26691
|
+
import(content) {
|
|
26692
|
+
const parseResult = parseAgentSourceWithCommitments(content);
|
|
26693
|
+
// Bring only the agent corpus (non-commitment lines and relevant commitments)
|
|
26694
|
+
// Stripping the agent name (which is usually the first line)
|
|
26695
|
+
const corpus = parseResult.nonCommitmentLines
|
|
26696
|
+
.filter((line, index) => index > 0 || !parseResult.agentName)
|
|
26697
|
+
.join('\n')
|
|
26698
|
+
.trim();
|
|
26699
|
+
// Also include relevant commitments that make up the "corpus" of the agent
|
|
26700
|
+
// For example PERSONA, RULE, KNOWLEDGE
|
|
26701
|
+
const relevantCommitments = parseResult.commitments
|
|
26702
|
+
.filter((c) => ['PERSONA', 'RULE', 'KNOWLEDGE'].includes(c.type))
|
|
26703
|
+
.map((c) => `${c.type} ${c.content}`)
|
|
26704
|
+
.join('\n\n');
|
|
26705
|
+
return spaceTrim$1((block) => `
|
|
26706
|
+
${block(relevantCommitments)}
|
|
26707
|
+
|
|
26708
|
+
${block(corpus)}
|
|
26709
|
+
`).trim();
|
|
26710
|
+
},
|
|
26711
|
+
};
|
|
26712
|
+
|
|
26713
|
+
/**
|
|
26714
|
+
* Plugin for importing JSON files
|
|
26715
|
+
*
|
|
26716
|
+
* @private [🥝] Maybe export the import plugins through some package
|
|
26717
|
+
*/
|
|
26718
|
+
const JsonFileImportPlugin = {
|
|
26719
|
+
name: 'json-file-import-plugin',
|
|
26720
|
+
canImport(mimeType) {
|
|
26721
|
+
return mimeType === 'application/json' || mimeType.endsWith('+json');
|
|
26722
|
+
},
|
|
26723
|
+
import(content) {
|
|
26724
|
+
try {
|
|
26725
|
+
const json = JSON.parse(content);
|
|
26726
|
+
const formattedJson = JSON.stringify(json, null, 4);
|
|
26727
|
+
return `\`\`\`json\n${formattedJson}\n\`\`\``;
|
|
26728
|
+
}
|
|
26729
|
+
catch (error) {
|
|
26730
|
+
// If JSON is invalid, still import it but maybe not as pretty JSON
|
|
26731
|
+
return `\`\`\`json\n${content}\n\`\`\``;
|
|
26732
|
+
}
|
|
26733
|
+
},
|
|
26734
|
+
};
|
|
26735
|
+
|
|
26736
|
+
/**
|
|
26737
|
+
* Plugin for importing generic text files
|
|
26738
|
+
*
|
|
26739
|
+
* @private [🥝] Maybe export the import plugins through some package
|
|
26740
|
+
*/
|
|
26741
|
+
const TextFileImportPlugin = {
|
|
26742
|
+
name: 'text-file-import-plugin',
|
|
26743
|
+
canImport(mimeType) {
|
|
26744
|
+
return (mimeType === 'text/plain' ||
|
|
26745
|
+
mimeType === 'text/markdown' ||
|
|
26746
|
+
mimeType === 'text/x-typescript' ||
|
|
26747
|
+
mimeType === 'text/javascript' ||
|
|
26748
|
+
mimeType === 'text/css' ||
|
|
26749
|
+
mimeType === 'text/html' ||
|
|
26750
|
+
mimeType.startsWith('text/'));
|
|
26751
|
+
},
|
|
26752
|
+
import(content, mimeType) {
|
|
26753
|
+
const extension = mimeTypeToExtension(mimeType);
|
|
26754
|
+
const codeBlockType = extension || 'txt';
|
|
26755
|
+
return `\`\`\`${codeBlockType}\n${content}\n\`\`\``;
|
|
26756
|
+
},
|
|
26757
|
+
};
|
|
26758
|
+
|
|
26759
|
+
/**
|
|
26760
|
+
* All available file import plugins
|
|
26761
|
+
*
|
|
26762
|
+
* @private [🥝] Maybe export the import plugins through some package
|
|
26763
|
+
*/
|
|
26764
|
+
const $fileImportPlugins = [
|
|
26765
|
+
AgentFileImportPlugin,
|
|
26766
|
+
JsonFileImportPlugin,
|
|
26767
|
+
TextFileImportPlugin,
|
|
26768
|
+
];
|
|
26769
|
+
|
|
26770
|
+
/**
|
|
26771
|
+
* Regex pattern matching markdown horizontal lines that should not be copied into the final system message.
|
|
26772
|
+
*
|
|
26773
|
+
* @private internal constant of `augmentAgentModelRequirementsFromSource`
|
|
26774
|
+
*/
|
|
26775
|
+
const HORIZONTAL_LINE_PATTERN = /^[\s]*[-_*][\s]*[-_*][\s]*[-_*][\s]*[-_*]*[\s]*$/;
|
|
26776
|
+
/**
|
|
26777
|
+
* MIME type prefixes treated as binary and therefore not eligible for text import plugins.
|
|
26778
|
+
*
|
|
26779
|
+
* @private internal constant of `augmentAgentModelRequirementsFromSource`
|
|
26969
26780
|
*/
|
|
26970
|
-
|
|
26971
|
-
|
|
26972
|
-
|
|
26973
|
-
|
|
26974
|
-
|
|
26975
|
-
|
|
26781
|
+
const BINARY_MIME_TYPE_PREFIXES = [
|
|
26782
|
+
'image/',
|
|
26783
|
+
'video/',
|
|
26784
|
+
'audio/',
|
|
26785
|
+
'application/octet-stream',
|
|
26786
|
+
'application/pdf',
|
|
26787
|
+
'application/zip',
|
|
26788
|
+
];
|
|
26976
26789
|
/**
|
|
26977
|
-
*
|
|
26790
|
+
* Adds source-derived sections after commitments have been applied.
|
|
26978
26791
|
*
|
|
26979
|
-
* @param requirements -
|
|
26980
|
-
* @param
|
|
26981
|
-
* @param
|
|
26982
|
-
* @returns
|
|
26792
|
+
* @param requirements - Requirements after commitment application and USE aggregation.
|
|
26793
|
+
* @param parseResult - Parsed source used to recover non-commitment prose and examples.
|
|
26794
|
+
* @param agentSource - Original source used to recover MCP server declarations.
|
|
26795
|
+
* @returns Requirements with source-derived sections appended.
|
|
26983
26796
|
*
|
|
26984
|
-
* @private
|
|
26797
|
+
* @private function of `createAgentModelRequirementsWithCommitments`
|
|
26985
26798
|
*/
|
|
26986
|
-
function
|
|
26987
|
-
|
|
26988
|
-
|
|
26989
|
-
|
|
26990
|
-
|
|
26991
|
-
try {
|
|
26992
|
-
return definition.applyToAgentModelRequirements(requirements, commitmentContent);
|
|
26993
|
-
}
|
|
26994
|
-
catch (error) {
|
|
26995
|
-
console.warn(`Failed to apply commitment ${commitment.type}:`, error);
|
|
26996
|
-
return requirements;
|
|
26997
|
-
}
|
|
26799
|
+
async function augmentAgentModelRequirementsFromSource(requirements, parseResult, agentSource) {
|
|
26800
|
+
requirements = await importReferencedFiles(requirements);
|
|
26801
|
+
requirements = appendMcpServers(requirements, agentSource);
|
|
26802
|
+
requirements = appendNonCommitmentContent(requirements, parseResult);
|
|
26803
|
+
return appendExampleInteractions(requirements, parseResult);
|
|
26998
26804
|
}
|
|
26999
26805
|
/**
|
|
27000
26806
|
* Imports text files referenced by IMPORT commitments and appends their transformed content to the system message.
|
|
@@ -27002,7 +26808,7 @@ function applyCommitmentDefinitionSafely(requirements, commitment, commitmentCon
|
|
|
27002
26808
|
* @param requirements - Requirements possibly containing `importedFileUrls`.
|
|
27003
26809
|
* @returns Requirements with imported file content appended to the system message.
|
|
27004
26810
|
*
|
|
27005
|
-
* @private internal utility of `
|
|
26811
|
+
* @private internal utility of `augmentAgentModelRequirementsFromSource`
|
|
27006
26812
|
*/
|
|
27007
26813
|
async function importReferencedFiles(requirements) {
|
|
27008
26814
|
const importedFileUrls = requirements.importedFileUrls;
|
|
@@ -27088,7 +26894,7 @@ function normalizeImportedMimeType(mimeType) {
|
|
|
27088
26894
|
* @param agentSource - Original agent source used for MCP extraction.
|
|
27089
26895
|
* @returns Requirements with `mcpServers` set when MCP commitments are present.
|
|
27090
26896
|
*
|
|
27091
|
-
* @private internal utility of `
|
|
26897
|
+
* @private internal utility of `augmentAgentModelRequirementsFromSource`
|
|
27092
26898
|
*/
|
|
27093
26899
|
function appendMcpServers(requirements, agentSource) {
|
|
27094
26900
|
const mcpServers = extractMcpServers(agentSource);
|
|
@@ -27107,7 +26913,7 @@ function appendMcpServers(requirements, agentSource) {
|
|
|
27107
26913
|
* @param parseResult - Parsed source including non-commitment lines.
|
|
27108
26914
|
* @returns Requirements with the remaining prose appended to the system message.
|
|
27109
26915
|
*
|
|
27110
|
-
* @private internal utility of `
|
|
26916
|
+
* @private internal utility of `augmentAgentModelRequirementsFromSource`
|
|
27111
26917
|
*/
|
|
27112
26918
|
function appendNonCommitmentContent(requirements, parseResult) {
|
|
27113
26919
|
const nonCommitmentContent = getNonCommitmentContent(parseResult);
|
|
@@ -27150,7 +26956,7 @@ function isHorizontalLine(line) {
|
|
|
27150
26956
|
* @param parseResult - Parsed source used to recover initial message content.
|
|
27151
26957
|
* @returns Requirements with the example interaction block appended when examples exist.
|
|
27152
26958
|
*
|
|
27153
|
-
* @private internal utility of `
|
|
26959
|
+
* @private internal utility of `augmentAgentModelRequirementsFromSource`
|
|
27154
26960
|
*/
|
|
27155
26961
|
function appendExampleInteractions(requirements, parseResult) {
|
|
27156
26962
|
const exampleInteractionsContent = createExampleInteractionsContent(parseResult, requirements.samples);
|
|
@@ -27205,7 +27011,7 @@ function collectExampleInteractionLines(parseResult, samples) {
|
|
|
27205
27011
|
* @param section - Section content to append.
|
|
27206
27012
|
* @returns Requirements with the additional system-message block appended.
|
|
27207
27013
|
*
|
|
27208
|
-
* @private internal utility of `
|
|
27014
|
+
* @private internal utility of `augmentAgentModelRequirementsFromSource`
|
|
27209
27015
|
*/
|
|
27210
27016
|
function appendSystemMessageSection(requirements, section) {
|
|
27211
27017
|
return {
|
|
@@ -27214,29 +27020,149 @@ function appendSystemMessageSection(requirements, section) {
|
|
|
27214
27020
|
};
|
|
27215
27021
|
}
|
|
27216
27022
|
/**
|
|
27217
|
-
*
|
|
27023
|
+
* Mocked security check for imported files.
|
|
27218
27024
|
*
|
|
27219
|
-
* @param
|
|
27220
|
-
* @returns
|
|
27025
|
+
* @param urlOrPath - The URL or local path of the file to check.
|
|
27026
|
+
* @returns A promise that resolves if the file is considered safe.
|
|
27221
27027
|
*
|
|
27222
|
-
* @private internal utility of `
|
|
27028
|
+
* @private internal utility of `createImportedFileSystemMessage`
|
|
27223
27029
|
*/
|
|
27224
|
-
function
|
|
27225
|
-
|
|
27226
|
-
|
|
27227
|
-
|
|
27228
|
-
|
|
27030
|
+
async function mockedSecurityCheck(urlOrPath) {
|
|
27031
|
+
// TODO: Implement proper security checks
|
|
27032
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
27033
|
+
if (urlOrPath.includes('malicious')) {
|
|
27034
|
+
throw new Error(`Security check failed for: ${urlOrPath}`);
|
|
27035
|
+
}
|
|
27036
|
+
}
|
|
27037
|
+
/**
|
|
27038
|
+
* Checks whether the given MIME type belongs to a binary file.
|
|
27039
|
+
*
|
|
27040
|
+
* @param mimeType - The MIME type to check.
|
|
27041
|
+
* @returns `true` when the MIME type is treated as binary.
|
|
27042
|
+
*
|
|
27043
|
+
* @private internal utility of `createImportedFileSystemMessage`
|
|
27044
|
+
*/
|
|
27045
|
+
function isBinaryMimeType(mimeType) {
|
|
27046
|
+
return BINARY_MIME_TYPE_PREFIXES.some((prefix) => mimeType.startsWith(prefix));
|
|
27047
|
+
}
|
|
27048
|
+
|
|
27049
|
+
/**
|
|
27050
|
+
* DELETE-like commitment types that invalidate earlier tagged commitments.
|
|
27051
|
+
*
|
|
27052
|
+
* @private internal constant of `filterCommitmentsForAgentModelRequirements`
|
|
27053
|
+
*/
|
|
27054
|
+
const DELETE_COMMITMENT_TYPES = new Set(['DELETE', 'CANCEL', 'DISCARD', 'REMOVE']);
|
|
27055
|
+
/**
|
|
27056
|
+
* Commitments whose earlier occurrences are overwritten by the last occurrence in source order.
|
|
27057
|
+
*
|
|
27058
|
+
* @private internal constant of `filterCommitmentsForAgentModelRequirements`
|
|
27059
|
+
*/
|
|
27060
|
+
const OVERWRITTEN_COMMITMENT_GROUP_BY_TYPE = new Map([
|
|
27061
|
+
['GOAL', 'GOAL'],
|
|
27062
|
+
['GOALS', 'GOAL'],
|
|
27063
|
+
]);
|
|
27064
|
+
/**
|
|
27065
|
+
* Applies the commitment filtering rules used before commitment definitions are executed.
|
|
27066
|
+
*
|
|
27067
|
+
* @param commitments - Parsed commitments in original source order.
|
|
27068
|
+
* @returns Commitments after DELETE-like invalidation and overwritten-goal filtering.
|
|
27069
|
+
*
|
|
27070
|
+
* @private function of `createAgentModelRequirementsWithCommitments`
|
|
27071
|
+
*/
|
|
27072
|
+
function filterCommitmentsForAgentModelRequirements(commitments) {
|
|
27073
|
+
return filterOverwrittenCommitments(filterDeletedCommitments(commitments));
|
|
27074
|
+
}
|
|
27075
|
+
/**
|
|
27076
|
+
* Removes earlier commitments that are overwritten by later commitments of the same semantic group.
|
|
27077
|
+
*
|
|
27078
|
+
* @param commitments - Parsed commitments after DELETE-like filtering.
|
|
27079
|
+
* @returns Commitments with overwritten entries removed while preserving source order.
|
|
27080
|
+
*
|
|
27081
|
+
* @private internal utility of `filterCommitmentsForAgentModelRequirements`
|
|
27082
|
+
*/
|
|
27083
|
+
function filterOverwrittenCommitments(commitments) {
|
|
27084
|
+
const seenOverwriteGroups = new Set();
|
|
27085
|
+
const keptCommitments = [];
|
|
27086
|
+
for (let index = commitments.length - 1; index >= 0; index--) {
|
|
27087
|
+
const commitment = commitments[index];
|
|
27088
|
+
const overwriteGroup = OVERWRITTEN_COMMITMENT_GROUP_BY_TYPE.get(commitment.type);
|
|
27089
|
+
if (!overwriteGroup) {
|
|
27090
|
+
keptCommitments.push(commitment);
|
|
27091
|
+
continue;
|
|
27092
|
+
}
|
|
27093
|
+
if (seenOverwriteGroups.has(overwriteGroup)) {
|
|
27094
|
+
continue;
|
|
27095
|
+
}
|
|
27096
|
+
seenOverwriteGroups.add(overwriteGroup);
|
|
27097
|
+
keptCommitments.push(commitment);
|
|
27098
|
+
}
|
|
27099
|
+
return keptCommitments.reverse();
|
|
27100
|
+
}
|
|
27101
|
+
/**
|
|
27102
|
+
* Applies DELETE-like invalidation commitments and returns only commitments that should continue through the pipeline.
|
|
27103
|
+
*
|
|
27104
|
+
* @param commitments - Parsed commitments in original source order.
|
|
27105
|
+
* @returns Filtered commitments with earlier deleted items removed.
|
|
27106
|
+
*
|
|
27107
|
+
* @private internal utility of `filterCommitmentsForAgentModelRequirements`
|
|
27108
|
+
*/
|
|
27109
|
+
function filterDeletedCommitments(commitments) {
|
|
27110
|
+
const filteredCommitments = [];
|
|
27111
|
+
for (const commitment of commitments) {
|
|
27112
|
+
if (!isDeleteCommitmentType(commitment.type)) {
|
|
27113
|
+
filteredCommitments.push(commitment);
|
|
27114
|
+
continue;
|
|
27115
|
+
}
|
|
27116
|
+
const targetParameterNames = getCommitmentParameterNames(commitment.content);
|
|
27117
|
+
if (targetParameterNames.length === 0) {
|
|
27118
|
+
continue;
|
|
27119
|
+
}
|
|
27120
|
+
for (let index = filteredCommitments.length - 1; index >= 0; index--) {
|
|
27121
|
+
const previousCommitment = filteredCommitments[index];
|
|
27122
|
+
const previousParameterNames = getCommitmentParameterNames(previousCommitment.content);
|
|
27123
|
+
const isTargeted = previousParameterNames.some((parameterName) => targetParameterNames.includes(parameterName));
|
|
27124
|
+
if (isTargeted) {
|
|
27125
|
+
filteredCommitments.splice(index, 1);
|
|
27126
|
+
}
|
|
27127
|
+
}
|
|
27128
|
+
}
|
|
27129
|
+
return filteredCommitments;
|
|
27130
|
+
}
|
|
27131
|
+
/**
|
|
27132
|
+
* Checks whether a commitment type behaves like DELETE and therefore invalidates earlier tagged commitments.
|
|
27133
|
+
*
|
|
27134
|
+
* @param commitmentType - Commitment type to check.
|
|
27135
|
+
* @returns `true` when the commitment removes prior tagged commitments.
|
|
27136
|
+
*
|
|
27137
|
+
* @private internal utility of `filterDeletedCommitments`
|
|
27138
|
+
*/
|
|
27139
|
+
function isDeleteCommitmentType(commitmentType) {
|
|
27140
|
+
return DELETE_COMMITMENT_TYPES.has(commitmentType);
|
|
27141
|
+
}
|
|
27142
|
+
/**
|
|
27143
|
+
* Extracts normalized parameter names used for DELETE-like invalidation matching.
|
|
27144
|
+
*
|
|
27145
|
+
* @param content - Commitment content to parse.
|
|
27146
|
+
* @returns Lower-cased non-empty parameter names.
|
|
27147
|
+
*
|
|
27148
|
+
* @private internal utility of `filterDeletedCommitments`
|
|
27149
|
+
*/
|
|
27150
|
+
function getCommitmentParameterNames(content) {
|
|
27151
|
+
return parseParameters(content)
|
|
27152
|
+
.map((parameter) => parameter.name.trim().toLowerCase())
|
|
27153
|
+
.filter(Boolean);
|
|
27229
27154
|
}
|
|
27155
|
+
|
|
27230
27156
|
/**
|
|
27231
|
-
*
|
|
27157
|
+
* Converts staged inline knowledge files into the final knowledge source URLs stored on requirements.
|
|
27232
27158
|
*
|
|
27233
27159
|
* @param requirements - Current requirements snapshot.
|
|
27234
27160
|
* @param uploader - Optional uploader for inline knowledge files.
|
|
27235
27161
|
* @returns Requirements with inline knowledge converted into upload URLs or data URLs.
|
|
27236
27162
|
*
|
|
27237
|
-
* @private
|
|
27163
|
+
* @private function of `createAgentModelRequirementsWithCommitments`
|
|
27238
27164
|
*/
|
|
27239
|
-
async function
|
|
27165
|
+
async function materializeInlineKnowledgeSources(requirements, uploader) {
|
|
27240
27166
|
var _a;
|
|
27241
27167
|
const inlineSources = extractInlineKnowledgeSources(requirements._metadata);
|
|
27242
27168
|
if (inlineSources.length === 0) {
|
|
@@ -27262,7 +27188,7 @@ async function applyPendingInlineKnowledgeSources(requirements, uploader) {
|
|
|
27262
27188
|
* @param uploader - Upload implementation provided by the caller.
|
|
27263
27189
|
* @returns Uploaded knowledge URL or a legacy data URL fallback.
|
|
27264
27190
|
*
|
|
27265
|
-
* @private internal utility of `
|
|
27191
|
+
* @private internal utility of `materializeInlineKnowledgeSources`
|
|
27266
27192
|
*/
|
|
27267
27193
|
async function uploadInlineKnowledgeSourceWithFallback(inlineSource, uploader) {
|
|
27268
27194
|
try {
|
|
@@ -27282,7 +27208,7 @@ async function uploadInlineKnowledgeSourceWithFallback(inlineSource, uploader) {
|
|
|
27282
27208
|
* @param metadata - Current requirements metadata.
|
|
27283
27209
|
* @returns Inline knowledge files collected during commitment application.
|
|
27284
27210
|
*
|
|
27285
|
-
* @private internal utility of `
|
|
27211
|
+
* @private internal utility of `materializeInlineKnowledgeSources`
|
|
27286
27212
|
*/
|
|
27287
27213
|
function extractInlineKnowledgeSources(metadata) {
|
|
27288
27214
|
if (!metadata) {
|
|
@@ -27297,7 +27223,7 @@ function extractInlineKnowledgeSources(metadata) {
|
|
|
27297
27223
|
* @param metadata - Current requirements metadata.
|
|
27298
27224
|
* @returns Metadata without the temporary inline knowledge staging field.
|
|
27299
27225
|
*
|
|
27300
|
-
* @private internal utility of `
|
|
27226
|
+
* @private internal utility of `materializeInlineKnowledgeSources`
|
|
27301
27227
|
*/
|
|
27302
27228
|
function stripInlineKnowledgeMetadata(metadata) {
|
|
27303
27229
|
if (!metadata || !Object.prototype.hasOwnProperty.call(metadata, 'inlineKnowledgeSources')) {
|
|
@@ -27306,31 +27232,90 @@ function stripInlineKnowledgeMetadata(metadata) {
|
|
|
27306
27232
|
const { inlineKnowledgeSources: _unusedInlineKnowledgeSources, ...rest } = metadata;
|
|
27307
27233
|
return Object.keys(rest).length > 0 ? rest : undefined;
|
|
27308
27234
|
}
|
|
27235
|
+
|
|
27309
27236
|
/**
|
|
27310
|
-
*
|
|
27237
|
+
* Removes single-hash comment lines (`# Comment`) from a system message
|
|
27238
|
+
* This is used to clean up the final system message before sending it to the AI model
|
|
27239
|
+
* while preserving the original content with comments in metadata
|
|
27311
27240
|
*
|
|
27312
|
-
* @param
|
|
27313
|
-
* @returns
|
|
27241
|
+
* @param systemMessage The system message that may contain comment lines
|
|
27242
|
+
* @returns The system message with single-hash comment lines removed
|
|
27314
27243
|
*
|
|
27315
|
-
* @private
|
|
27244
|
+
* @private - TODO: [🧠] Maybe should be public?
|
|
27316
27245
|
*/
|
|
27317
|
-
|
|
27318
|
-
|
|
27319
|
-
|
|
27320
|
-
|
|
27321
|
-
|
|
27246
|
+
function removeCommentsFromSystemMessage(systemMessage) {
|
|
27247
|
+
if (!systemMessage) {
|
|
27248
|
+
return systemMessage;
|
|
27249
|
+
}
|
|
27250
|
+
const lines = systemMessage.split(/\r?\n/);
|
|
27251
|
+
const filteredLines = lines.filter((line) => {
|
|
27252
|
+
const trimmedLine = line.trim();
|
|
27253
|
+
// Remove only single-hash comment markers (`# Comment`) and keep markdown headings (`## Heading`).
|
|
27254
|
+
return !/^#(?!#)\s/.test(trimmedLine);
|
|
27255
|
+
});
|
|
27256
|
+
return filteredLines.join('\n').trim();
|
|
27257
|
+
}
|
|
27258
|
+
|
|
27259
|
+
/**
|
|
27260
|
+
* Creates agent model requirements by parsing commitments, applying them in source order,
|
|
27261
|
+
* and finalizing derived sections such as imports, example interactions, and inline knowledge uploads.
|
|
27262
|
+
*
|
|
27263
|
+
* @param agentSource - Agent source book to parse.
|
|
27264
|
+
* @param modelName - Optional override for the agent model name.
|
|
27265
|
+
* @param options - Additional options such as reference and teammate resolvers.
|
|
27266
|
+
* @returns Fully prepared model requirements for the parsed agent source.
|
|
27267
|
+
*
|
|
27268
|
+
* @private internal utility of `createAgentModelRequirements`
|
|
27269
|
+
*/
|
|
27270
|
+
async function createAgentModelRequirementsWithCommitments(agentSource, modelName, options) {
|
|
27271
|
+
const parseResult = parseAgentSourceWithCommitments(agentSource);
|
|
27272
|
+
const filteredCommitments = filterCommitmentsForAgentModelRequirements(parseResult.commitments);
|
|
27273
|
+
let requirements = createInitialAgentModelRequirements(parseResult.agentName, modelName);
|
|
27274
|
+
requirements = await applyCommitmentsToAgentModelRequirements(requirements, filteredCommitments, options);
|
|
27275
|
+
requirements = aggregateUseCommitmentSystemMessages(requirements, filteredCommitments);
|
|
27276
|
+
requirements = await augmentAgentModelRequirementsFromSource(requirements, parseResult, agentSource);
|
|
27277
|
+
requirements = await materializeInlineKnowledgeSources(requirements, options === null || options === void 0 ? void 0 : options.inlineKnowledgeSourceUploader);
|
|
27278
|
+
return finalizeRequirements(requirements);
|
|
27279
|
+
}
|
|
27280
|
+
/**
|
|
27281
|
+
* Creates the initial requirements object with the parsed agent name stored in metadata and an optional model override.
|
|
27282
|
+
*
|
|
27283
|
+
* @param agentName - Parsed agent name from the source prelude.
|
|
27284
|
+
* @param modelName - Optional explicit model name override.
|
|
27285
|
+
* @returns Initial requirements before any commitment is applied.
|
|
27286
|
+
*
|
|
27287
|
+
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
27288
|
+
*/
|
|
27289
|
+
function createInitialAgentModelRequirements(agentName, modelName) {
|
|
27290
|
+
const initialRequirements = createBasicAgentModelRequirements(agentName);
|
|
27291
|
+
const requirementsWithMetadata = {
|
|
27292
|
+
...initialRequirements,
|
|
27293
|
+
_metadata: {
|
|
27294
|
+
...initialRequirements._metadata,
|
|
27295
|
+
agentName,
|
|
27296
|
+
},
|
|
27297
|
+
};
|
|
27298
|
+
if (!modelName) {
|
|
27299
|
+
return requirementsWithMetadata;
|
|
27322
27300
|
}
|
|
27301
|
+
return {
|
|
27302
|
+
...requirementsWithMetadata,
|
|
27303
|
+
modelName,
|
|
27304
|
+
};
|
|
27323
27305
|
}
|
|
27324
27306
|
/**
|
|
27325
|
-
*
|
|
27307
|
+
* Performs the final system-message cleanup pass after all other augmentation steps are complete.
|
|
27326
27308
|
*
|
|
27327
|
-
* @param
|
|
27328
|
-
* @returns
|
|
27309
|
+
* @param requirements - Fully built requirements before final cleanup.
|
|
27310
|
+
* @returns Requirements with comment lines removed from the final system message.
|
|
27329
27311
|
*
|
|
27330
|
-
* @private internal utility of `
|
|
27312
|
+
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
27331
27313
|
*/
|
|
27332
|
-
function
|
|
27333
|
-
return
|
|
27314
|
+
function finalizeRequirements(requirements) {
|
|
27315
|
+
return {
|
|
27316
|
+
...requirements,
|
|
27317
|
+
systemMessage: removeCommentsFromSystemMessage(requirements.systemMessage),
|
|
27318
|
+
};
|
|
27334
27319
|
}
|
|
27335
27320
|
|
|
27336
27321
|
/**
|