@promptbook/cli 0.110.0-8 → 0.110.0
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/README.md +0 -4
- package/esm/index.es.js +487 -97
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/components.index.d.ts +6 -0
- package/esm/typings/src/_packages/core.index.d.ts +2 -2
- package/esm/typings/src/_packages/types.index.d.ts +10 -0
- package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +22 -21
- package/esm/typings/src/book-2.0/agent-source/AgentReferenceResolver.d.ts +18 -0
- package/esm/typings/src/book-2.0/agent-source/CreateAgentModelRequirementsOptions.d.ts +12 -0
- package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirements.d.ts +8 -2
- package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.agentReferenceResolver.test.d.ts +1 -0
- package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.d.ts +4 -5
- package/esm/typings/src/book-components/BookEditor/BookEditor.d.ts +42 -0
- package/esm/typings/src/book-components/Chat/Chat/ChatActionsBar.d.ts +0 -2
- package/esm/typings/src/book-components/Chat/Chat/ChatInputArea.d.ts +1 -0
- package/esm/typings/src/book-components/Chat/Chat/ChatMessageItem.d.ts +4 -0
- package/esm/typings/src/book-components/Chat/Chat/ChatMessageList.d.ts +1 -0
- package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +26 -0
- package/esm/typings/src/book-components/Chat/Chat/ChatSoundToggle.d.ts +31 -0
- package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +6 -0
- package/esm/typings/src/book-components/Chat/hooks/useChatRatings.d.ts +24 -2
- package/esm/typings/src/book-components/Chat/utils/getToolCallChipletInfo.d.ts +2 -10
- package/esm/typings/src/book-components/Chat/utils/parseCitationMarker.d.ts +75 -0
- package/esm/typings/src/book-components/Chat/utils/parseCitationsFromContent.d.ts +3 -1
- package/esm/typings/src/book-components/Chat/utils/parseCitationsFromContent.test.d.ts +1 -0
- package/esm/typings/src/book-components/icons/ArrowIcon.d.ts +17 -4
- package/esm/typings/src/commitments/_base/BaseCommitmentDefinition.d.ts +9 -0
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.test.d.ts +1 -0
- package/esm/typings/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +39 -0
- package/esm/typings/src/types/LlmToolDefinition.d.ts +1 -0
- package/esm/typings/src/types/ModelRequirements.d.ts +9 -0
- package/esm/typings/src/utils/DEFAULT_THINKING_MESSAGES.d.ts +8 -0
- package/esm/typings/src/utils/knowledge/inlineKnowledgeSource.d.ts +38 -0
- package/esm/typings/src/utils/knowledge/inlineKnowledgeSource.test.d.ts +1 -0
- package/esm/typings/src/utils/language/getBrowserPreferredSpeechRecognitionLanguage.d.ts +35 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +487 -97
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -48,7 +48,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
48
48
|
* @generated
|
|
49
49
|
* @see https://github.com/webgptorg/promptbook
|
|
50
50
|
*/
|
|
51
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.110.0
|
|
51
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.110.0';
|
|
52
52
|
/**
|
|
53
53
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
54
54
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -15828,6 +15828,28 @@ class BaseCommitmentDefinition {
|
|
|
15828
15828
|
return currentMessage + separator + content;
|
|
15829
15829
|
});
|
|
15830
15830
|
}
|
|
15831
|
+
/**
|
|
15832
|
+
* Helper method to create a new requirements object with updated prompt suffix
|
|
15833
|
+
*/
|
|
15834
|
+
updatePromptSuffix(requirements, contentUpdate) {
|
|
15835
|
+
const newSuffix = typeof contentUpdate === 'string' ? contentUpdate : contentUpdate(requirements.promptSuffix);
|
|
15836
|
+
return {
|
|
15837
|
+
...requirements,
|
|
15838
|
+
promptSuffix: newSuffix,
|
|
15839
|
+
};
|
|
15840
|
+
}
|
|
15841
|
+
/**
|
|
15842
|
+
* Helper method to append content to the prompt suffix
|
|
15843
|
+
* Default separator is a single newline for bullet lists.
|
|
15844
|
+
*/
|
|
15845
|
+
appendToPromptSuffix(requirements, content, separator = '\n') {
|
|
15846
|
+
return this.updatePromptSuffix(requirements, (currentSuffix) => {
|
|
15847
|
+
if (!currentSuffix.trim()) {
|
|
15848
|
+
return content;
|
|
15849
|
+
}
|
|
15850
|
+
return `${currentSuffix}${separator}${content}`;
|
|
15851
|
+
});
|
|
15852
|
+
}
|
|
15831
15853
|
/**
|
|
15832
15854
|
* Helper method to add a comment section to the system message
|
|
15833
15855
|
* Comments are lines starting with # that will be removed from the final system message
|
|
@@ -16005,13 +16027,9 @@ class ClosedCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
16005
16027
|
`);
|
|
16006
16028
|
}
|
|
16007
16029
|
applyToAgentModelRequirements(requirements, _content) {
|
|
16008
|
-
const updatedMetadata = {
|
|
16009
|
-
...requirements.metadata,
|
|
16010
|
-
isClosed: true,
|
|
16011
|
-
};
|
|
16012
16030
|
return {
|
|
16013
16031
|
...requirements,
|
|
16014
|
-
|
|
16032
|
+
isClosed: true,
|
|
16015
16033
|
};
|
|
16016
16034
|
}
|
|
16017
16035
|
}
|
|
@@ -16289,12 +16307,12 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
16289
16307
|
return requirements;
|
|
16290
16308
|
}
|
|
16291
16309
|
// Get existing dictionary entries from metadata
|
|
16292
|
-
const existingDictionary = ((_a = requirements.
|
|
16310
|
+
const existingDictionary = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
|
|
16293
16311
|
// Merge the new dictionary entry with existing entries
|
|
16294
16312
|
const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
|
|
16295
16313
|
// Store the merged dictionary in metadata for debugging and inspection
|
|
16296
16314
|
const updatedMetadata = {
|
|
16297
|
-
...requirements.
|
|
16315
|
+
...requirements._metadata,
|
|
16298
16316
|
DICTIONARY: mergedDictionary,
|
|
16299
16317
|
};
|
|
16300
16318
|
// Create the dictionary section for the system message
|
|
@@ -16302,7 +16320,7 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
16302
16320
|
const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
|
|
16303
16321
|
return {
|
|
16304
16322
|
...this.appendToSystemMessage(requirements, dictionarySection),
|
|
16305
|
-
|
|
16323
|
+
_metadata: updatedMetadata,
|
|
16306
16324
|
};
|
|
16307
16325
|
}
|
|
16308
16326
|
}
|
|
@@ -16442,10 +16460,7 @@ class FromCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
16442
16460
|
applyToAgentModelRequirements(requirements, content) {
|
|
16443
16461
|
const trimmedContent = content.trim();
|
|
16444
16462
|
if (!trimmedContent) {
|
|
16445
|
-
return
|
|
16446
|
-
...requirements,
|
|
16447
|
-
parentAgentUrl: undefined,
|
|
16448
|
-
};
|
|
16463
|
+
return requirements;
|
|
16449
16464
|
}
|
|
16450
16465
|
if (trimmedContent.toUpperCase() === 'VOID' ||
|
|
16451
16466
|
trimmedContent.toUpperCase() === 'NULL' ||
|
|
@@ -16659,6 +16674,136 @@ class ImportCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
16659
16674
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
16660
16675
|
*/
|
|
16661
16676
|
|
|
16677
|
+
/**
|
|
16678
|
+
* @@@
|
|
16679
|
+
*
|
|
16680
|
+
* @private thing of inline knowledge
|
|
16681
|
+
*/
|
|
16682
|
+
const INLINE_KNOWLEDGE_BASE_NAME = 'inline-knowledge';
|
|
16683
|
+
/**
|
|
16684
|
+
* @@@
|
|
16685
|
+
*
|
|
16686
|
+
* @private thing of inline knowledge
|
|
16687
|
+
*/
|
|
16688
|
+
const INLINE_KNOWLEDGE_EXTENSION = '.txt';
|
|
16689
|
+
/**
|
|
16690
|
+
* @@@
|
|
16691
|
+
*
|
|
16692
|
+
* @private thing of inline knowledge
|
|
16693
|
+
*/
|
|
16694
|
+
const DATA_URL_PREFIX = 'data:';
|
|
16695
|
+
/**
|
|
16696
|
+
* @@@
|
|
16697
|
+
*
|
|
16698
|
+
* @private thing of inline knowledge
|
|
16699
|
+
*/
|
|
16700
|
+
function getFirstNonEmptyLine(content) {
|
|
16701
|
+
const lines = content.split(/\r?\n/);
|
|
16702
|
+
for (const line of lines) {
|
|
16703
|
+
const trimmed = line.trim();
|
|
16704
|
+
if (trimmed) {
|
|
16705
|
+
return trimmed;
|
|
16706
|
+
}
|
|
16707
|
+
}
|
|
16708
|
+
return null;
|
|
16709
|
+
}
|
|
16710
|
+
/**
|
|
16711
|
+
* @@@
|
|
16712
|
+
*
|
|
16713
|
+
* @private thing of inline knowledge
|
|
16714
|
+
*/
|
|
16715
|
+
function deriveBaseFilename(content) {
|
|
16716
|
+
const firstLine = getFirstNonEmptyLine(content);
|
|
16717
|
+
if (!firstLine) {
|
|
16718
|
+
return INLINE_KNOWLEDGE_BASE_NAME;
|
|
16719
|
+
}
|
|
16720
|
+
const normalized = normalizeToKebabCase(firstLine);
|
|
16721
|
+
return normalized || INLINE_KNOWLEDGE_BASE_NAME;
|
|
16722
|
+
}
|
|
16723
|
+
/**
|
|
16724
|
+
* Creates a data URL that represents the inline knowledge content as a text file.
|
|
16725
|
+
*
|
|
16726
|
+
* @private thing of inline knowledge
|
|
16727
|
+
*/
|
|
16728
|
+
function createInlineKnowledgeSourceFile(content) {
|
|
16729
|
+
const trimmedContent = content.trim();
|
|
16730
|
+
const baseName = deriveBaseFilename(trimmedContent);
|
|
16731
|
+
const filename = `${baseName}${INLINE_KNOWLEDGE_EXTENSION}`;
|
|
16732
|
+
const mimeType = 'text/plain';
|
|
16733
|
+
const base64 = Buffer.from(trimmedContent, 'utf-8').toString('base64');
|
|
16734
|
+
const encodedFilename = encodeURIComponent(filename);
|
|
16735
|
+
const url = `${DATA_URL_PREFIX}${mimeType};name=${encodedFilename};charset=utf-8;base64,${base64}`;
|
|
16736
|
+
return {
|
|
16737
|
+
filename,
|
|
16738
|
+
mimeType,
|
|
16739
|
+
url,
|
|
16740
|
+
};
|
|
16741
|
+
}
|
|
16742
|
+
/**
|
|
16743
|
+
* Checks whether the provided source string is a data URL that can be decoded.
|
|
16744
|
+
*
|
|
16745
|
+
* @private thing of inline knowledge
|
|
16746
|
+
*/
|
|
16747
|
+
function isDataUrlKnowledgeSource(source) {
|
|
16748
|
+
return typeof source === 'string' && source.startsWith(DATA_URL_PREFIX);
|
|
16749
|
+
}
|
|
16750
|
+
/**
|
|
16751
|
+
* Parses a data URL-based knowledge source into its raw buffer, filename, and MIME type.
|
|
16752
|
+
*
|
|
16753
|
+
* @private thing of inline knowledge
|
|
16754
|
+
*/
|
|
16755
|
+
function parseDataUrlKnowledgeSource(source) {
|
|
16756
|
+
if (!isDataUrlKnowledgeSource(source)) {
|
|
16757
|
+
return null;
|
|
16758
|
+
}
|
|
16759
|
+
const commaIndex = source.indexOf(',');
|
|
16760
|
+
if (commaIndex === -1) {
|
|
16761
|
+
return null;
|
|
16762
|
+
}
|
|
16763
|
+
const header = source.slice(DATA_URL_PREFIX.length, commaIndex);
|
|
16764
|
+
const payload = source.slice(commaIndex + 1);
|
|
16765
|
+
const tokens = header.split(';');
|
|
16766
|
+
const mediaType = tokens[0] || 'text/plain';
|
|
16767
|
+
let filename = `${INLINE_KNOWLEDGE_BASE_NAME}${INLINE_KNOWLEDGE_EXTENSION}`;
|
|
16768
|
+
let isBase64 = false;
|
|
16769
|
+
for (let i = 1; i < tokens.length; i++) {
|
|
16770
|
+
const token = tokens[i];
|
|
16771
|
+
if (!token) {
|
|
16772
|
+
continue;
|
|
16773
|
+
}
|
|
16774
|
+
if (token.toLowerCase() === 'base64') {
|
|
16775
|
+
isBase64 = true;
|
|
16776
|
+
continue;
|
|
16777
|
+
}
|
|
16778
|
+
const [key, value] = token.split('=');
|
|
16779
|
+
if (key === 'name' && value !== undefined) {
|
|
16780
|
+
try {
|
|
16781
|
+
filename = decodeURIComponent(value);
|
|
16782
|
+
}
|
|
16783
|
+
catch (_a) {
|
|
16784
|
+
filename = value;
|
|
16785
|
+
}
|
|
16786
|
+
}
|
|
16787
|
+
}
|
|
16788
|
+
if (!isBase64) {
|
|
16789
|
+
return null;
|
|
16790
|
+
}
|
|
16791
|
+
try {
|
|
16792
|
+
const buffer = Buffer.from(payload, 'base64');
|
|
16793
|
+
return {
|
|
16794
|
+
buffer,
|
|
16795
|
+
filename,
|
|
16796
|
+
mimeType: mediaType,
|
|
16797
|
+
};
|
|
16798
|
+
}
|
|
16799
|
+
catch (_b) {
|
|
16800
|
+
return null;
|
|
16801
|
+
}
|
|
16802
|
+
}
|
|
16803
|
+
/**
|
|
16804
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
16805
|
+
*/
|
|
16806
|
+
|
|
16662
16807
|
/**
|
|
16663
16808
|
* KNOWLEDGE commitment definition
|
|
16664
16809
|
*
|
|
@@ -16757,9 +16902,13 @@ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
16757
16902
|
return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
|
|
16758
16903
|
}
|
|
16759
16904
|
else {
|
|
16760
|
-
|
|
16761
|
-
const
|
|
16762
|
-
|
|
16905
|
+
const inlineSource = createInlineKnowledgeSourceFile(trimmedContent);
|
|
16906
|
+
const updatedRequirements = {
|
|
16907
|
+
...requirements,
|
|
16908
|
+
knowledgeSources: [...(requirements.knowledgeSources || []), inlineSource.url],
|
|
16909
|
+
};
|
|
16910
|
+
const knowledgeInfo = `Knowledge Source Inline: ${inlineSource.filename} (derived from inline content and processed for retrieval during chat)`;
|
|
16911
|
+
return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
|
|
16763
16912
|
}
|
|
16764
16913
|
}
|
|
16765
16914
|
}
|
|
@@ -17006,16 +17155,16 @@ class AgentMessageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
17006
17155
|
// and typically doesn't need to be added to the system prompt or model requirements directly.
|
|
17007
17156
|
// It is extracted separately for the chat interface.
|
|
17008
17157
|
var _a;
|
|
17009
|
-
const pendingUserMessage = (_a = requirements.
|
|
17158
|
+
const pendingUserMessage = (_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
|
|
17010
17159
|
if (pendingUserMessage) {
|
|
17011
17160
|
const newSample = { question: pendingUserMessage, answer: content };
|
|
17012
17161
|
const newSamples = [...(requirements.samples || []), newSample];
|
|
17013
|
-
const newMetadata = { ...requirements.
|
|
17162
|
+
const newMetadata = { ...requirements._metadata };
|
|
17014
17163
|
delete newMetadata.pendingUserMessage;
|
|
17015
17164
|
return {
|
|
17016
17165
|
...requirements,
|
|
17017
17166
|
samples: newSamples,
|
|
17018
|
-
|
|
17167
|
+
_metadata: newMetadata,
|
|
17019
17168
|
};
|
|
17020
17169
|
}
|
|
17021
17170
|
return requirements;
|
|
@@ -17263,8 +17412,8 @@ class UserMessageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
17263
17412
|
applyToAgentModelRequirements(requirements, content) {
|
|
17264
17413
|
return {
|
|
17265
17414
|
...requirements,
|
|
17266
|
-
|
|
17267
|
-
...requirements.
|
|
17415
|
+
_metadata: {
|
|
17416
|
+
...requirements._metadata,
|
|
17268
17417
|
pendingUserMessage: content,
|
|
17269
17418
|
},
|
|
17270
17419
|
};
|
|
@@ -18122,11 +18271,7 @@ class NoteCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18122
18271
|
if (trimmedContent === '') {
|
|
18123
18272
|
return requirements;
|
|
18124
18273
|
}
|
|
18125
|
-
|
|
18126
|
-
return {
|
|
18127
|
-
...requirements,
|
|
18128
|
-
notes: [...(requirements.notes || []), trimmedContent],
|
|
18129
|
-
};
|
|
18274
|
+
return requirements;
|
|
18130
18275
|
}
|
|
18131
18276
|
}
|
|
18132
18277
|
/**
|
|
@@ -18188,12 +18333,12 @@ class OpenCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18188
18333
|
// Since OPEN is default, we can just ensure isClosed is false
|
|
18189
18334
|
// But to be explicit we can set it
|
|
18190
18335
|
const updatedMetadata = {
|
|
18191
|
-
...requirements.
|
|
18336
|
+
...requirements._metadata,
|
|
18192
18337
|
isClosed: false,
|
|
18193
18338
|
};
|
|
18194
18339
|
return {
|
|
18195
18340
|
...requirements,
|
|
18196
|
-
|
|
18341
|
+
_metadata: updatedMetadata,
|
|
18197
18342
|
};
|
|
18198
18343
|
}
|
|
18199
18344
|
}
|
|
@@ -18274,7 +18419,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18274
18419
|
return requirements;
|
|
18275
18420
|
}
|
|
18276
18421
|
// Get existing persona content from metadata
|
|
18277
|
-
const existingPersonaContent = ((_a = requirements.
|
|
18422
|
+
const existingPersonaContent = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.PERSONA) || '';
|
|
18278
18423
|
// Merge the new content with existing persona content
|
|
18279
18424
|
// When multiple PERSONA commitments exist, they are merged into one
|
|
18280
18425
|
const mergedPersonaContent = existingPersonaContent
|
|
@@ -18282,12 +18427,12 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18282
18427
|
: trimmedContent;
|
|
18283
18428
|
// Store the merged persona content in metadata for debugging and inspection
|
|
18284
18429
|
const updatedMetadata = {
|
|
18285
|
-
...requirements.
|
|
18430
|
+
...requirements._metadata,
|
|
18286
18431
|
PERSONA: mergedPersonaContent,
|
|
18287
18432
|
};
|
|
18288
18433
|
// Get the agent name from metadata (which should contain the first line of agent source)
|
|
18289
18434
|
// If not available, extract from current system message as fallback
|
|
18290
|
-
let agentName = (_b = requirements.
|
|
18435
|
+
let agentName = (_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.agentName;
|
|
18291
18436
|
if (!agentName) {
|
|
18292
18437
|
// Fallback: extract from current system message
|
|
18293
18438
|
const currentMessage = requirements.systemMessage.trim();
|
|
@@ -18334,7 +18479,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18334
18479
|
return {
|
|
18335
18480
|
...requirements,
|
|
18336
18481
|
systemMessage: newSystemMessage,
|
|
18337
|
-
|
|
18482
|
+
_metadata: updatedMetadata,
|
|
18338
18483
|
};
|
|
18339
18484
|
}
|
|
18340
18485
|
}
|
|
@@ -18417,7 +18562,16 @@ class RuleCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18417
18562
|
}
|
|
18418
18563
|
// Add rule to the system message
|
|
18419
18564
|
const ruleSection = `Rule: ${trimmedContent}`;
|
|
18420
|
-
|
|
18565
|
+
const requirementsWithRule = this.appendToSystemMessage(requirements, ruleSection, '\n\n');
|
|
18566
|
+
const ruleLines = trimmedContent
|
|
18567
|
+
.split(/\r?\n/)
|
|
18568
|
+
.map((line) => line.trim())
|
|
18569
|
+
.filter(Boolean)
|
|
18570
|
+
.map((line) => `- ${line}`);
|
|
18571
|
+
if (ruleLines.length === 0) {
|
|
18572
|
+
return requirementsWithRule;
|
|
18573
|
+
}
|
|
18574
|
+
return this.appendToPromptSuffix(requirementsWithRule, ruleLines.join('\n'));
|
|
18421
18575
|
}
|
|
18422
18576
|
}
|
|
18423
18577
|
/**
|
|
@@ -18919,11 +19073,12 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18919
19073
|
if (!trimmedContent) {
|
|
18920
19074
|
return requirements;
|
|
18921
19075
|
}
|
|
18922
|
-
|
|
19076
|
+
// Keep TEAM resilient: unresolved/malformed teammate entries are skipped, valid ones are still registered.
|
|
19077
|
+
const teammates = parseTeamCommitmentContent(trimmedContent, { strict: false });
|
|
18923
19078
|
if (teammates.length === 0) {
|
|
18924
19079
|
return requirements;
|
|
18925
19080
|
}
|
|
18926
|
-
const agentName = ((_a = requirements.
|
|
19081
|
+
const agentName = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.agentName) || 'Agent';
|
|
18927
19082
|
const teamEntries = teammates.map((teammate) => ({
|
|
18928
19083
|
toolName: createTeamToolName(teammate.url),
|
|
18929
19084
|
teammate,
|
|
@@ -18963,7 +19118,7 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18963
19118
|
},
|
|
18964
19119
|
});
|
|
18965
19120
|
}
|
|
18966
|
-
const existingTeammates = ((_b = requirements.
|
|
19121
|
+
const existingTeammates = ((_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.teammates) || [];
|
|
18967
19122
|
const updatedTeammates = [...existingTeammates];
|
|
18968
19123
|
for (const entry of teamEntries) {
|
|
18969
19124
|
if (updatedTeammates.some((existing) => existing.url === entry.teammate.url)) {
|
|
@@ -18992,8 +19147,8 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18992
19147
|
return this.appendToSystemMessage({
|
|
18993
19148
|
...requirements,
|
|
18994
19149
|
tools: updatedTools,
|
|
18995
|
-
|
|
18996
|
-
...requirements.
|
|
19150
|
+
_metadata: {
|
|
19151
|
+
...requirements._metadata,
|
|
18997
19152
|
teammates: updatedTeammates,
|
|
18998
19153
|
},
|
|
18999
19154
|
}, teamSystemMessage);
|
|
@@ -19225,7 +19380,7 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19225
19380
|
if (!trimmedContent) {
|
|
19226
19381
|
// Store template mode flag in metadata
|
|
19227
19382
|
const updatedMetadata = {
|
|
19228
|
-
...requirements.
|
|
19383
|
+
...requirements._metadata,
|
|
19229
19384
|
templateMode: true,
|
|
19230
19385
|
};
|
|
19231
19386
|
// Add a general instruction about using structured templates
|
|
@@ -19235,21 +19390,21 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19235
19390
|
`);
|
|
19236
19391
|
return {
|
|
19237
19392
|
...this.appendToSystemMessage(requirements, templateModeInstruction, '\n\n'),
|
|
19238
|
-
|
|
19393
|
+
_metadata: updatedMetadata,
|
|
19239
19394
|
};
|
|
19240
19395
|
}
|
|
19241
19396
|
// If content is provided, add the specific template instructions
|
|
19242
19397
|
const templateSection = `Response Template: ${trimmedContent}`;
|
|
19243
19398
|
// Store the template in metadata for potential programmatic access
|
|
19244
|
-
const existingTemplates = ((_a = requirements.
|
|
19399
|
+
const existingTemplates = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.templates) || [];
|
|
19245
19400
|
const updatedMetadata = {
|
|
19246
|
-
...requirements.
|
|
19401
|
+
...requirements._metadata,
|
|
19247
19402
|
templates: [...existingTemplates, trimmedContent],
|
|
19248
19403
|
templateMode: true,
|
|
19249
19404
|
};
|
|
19250
19405
|
return {
|
|
19251
19406
|
...this.appendToSystemMessage(requirements, templateSection, '\n\n'),
|
|
19252
|
-
|
|
19407
|
+
_metadata: updatedMetadata,
|
|
19253
19408
|
};
|
|
19254
19409
|
}
|
|
19255
19410
|
}
|
|
@@ -19586,8 +19741,8 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19586
19741
|
return this.appendToSystemMessage({
|
|
19587
19742
|
...requirements,
|
|
19588
19743
|
tools: updatedTools,
|
|
19589
|
-
|
|
19590
|
-
...requirements.
|
|
19744
|
+
_metadata: {
|
|
19745
|
+
...requirements._metadata,
|
|
19591
19746
|
useBrowser: true,
|
|
19592
19747
|
},
|
|
19593
19748
|
}, spaceTrim$1(`
|
|
@@ -19816,8 +19971,8 @@ class UseEmailCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19816
19971
|
return this.appendToSystemMessage({
|
|
19817
19972
|
...requirements,
|
|
19818
19973
|
tools: updatedTools,
|
|
19819
|
-
|
|
19820
|
-
...requirements.
|
|
19974
|
+
_metadata: {
|
|
19975
|
+
...requirements._metadata,
|
|
19821
19976
|
useEmail: content || true,
|
|
19822
19977
|
},
|
|
19823
19978
|
}, spaceTrim$1((block) => `
|
|
@@ -19952,8 +20107,8 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19952
20107
|
return this.appendToSystemMessage({
|
|
19953
20108
|
...requirements,
|
|
19954
20109
|
tools: updatedTools,
|
|
19955
|
-
|
|
19956
|
-
...requirements.
|
|
20110
|
+
_metadata: {
|
|
20111
|
+
...requirements._metadata,
|
|
19957
20112
|
useImageGenerator: content || true,
|
|
19958
20113
|
},
|
|
19959
20114
|
}, spaceTrim$1(`
|
|
@@ -20244,8 +20399,8 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
20244
20399
|
return this.appendToSystemMessage({
|
|
20245
20400
|
...requirements,
|
|
20246
20401
|
tools: updatedTools,
|
|
20247
|
-
|
|
20248
|
-
...requirements.
|
|
20402
|
+
_metadata: {
|
|
20403
|
+
...requirements._metadata,
|
|
20249
20404
|
useSearchEngine: content || true,
|
|
20250
20405
|
},
|
|
20251
20406
|
}, spaceTrim$1((block) => `
|
|
@@ -20393,8 +20548,8 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
20393
20548
|
return this.appendToSystemMessage({
|
|
20394
20549
|
...requirements,
|
|
20395
20550
|
tools: updatedTools,
|
|
20396
|
-
|
|
20397
|
-
...requirements.
|
|
20551
|
+
_metadata: {
|
|
20552
|
+
...requirements._metadata,
|
|
20398
20553
|
},
|
|
20399
20554
|
}, spaceTrim$1((block) => `
|
|
20400
20555
|
Time and date context:
|
|
@@ -24972,6 +25127,66 @@ const OPENAI_MODELS = exportJson({
|
|
|
24972
25127
|
},
|
|
24973
25128
|
/**/
|
|
24974
25129
|
/**/
|
|
25130
|
+
{
|
|
25131
|
+
modelVariant: 'CHAT',
|
|
25132
|
+
modelTitle: 'gpt-5.2-codex',
|
|
25133
|
+
modelName: 'gpt-5.2-codex',
|
|
25134
|
+
modelDescription: 'High-capability Codex variant tuned for agentic code generation with large contexts and reasoning effort controls. Ideal for long-horizon coding workflows and multi-step reasoning.',
|
|
25135
|
+
pricing: {
|
|
25136
|
+
prompt: pricing(`$1.75 / 1M tokens`),
|
|
25137
|
+
output: pricing(`$14.00 / 1M tokens`),
|
|
25138
|
+
},
|
|
25139
|
+
},
|
|
25140
|
+
/**/
|
|
25141
|
+
/**/
|
|
25142
|
+
{
|
|
25143
|
+
modelVariant: 'CHAT',
|
|
25144
|
+
modelTitle: 'gpt-5.1-codex-max',
|
|
25145
|
+
modelName: 'gpt-5.1-codex-max',
|
|
25146
|
+
modelDescription: 'Premium GPT-5.1 Codex flavor that mirrors gpt-5.1 in capability and pricing while adding Codex tooling optimizations.',
|
|
25147
|
+
pricing: {
|
|
25148
|
+
prompt: pricing(`$1.25 / 1M tokens`),
|
|
25149
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
25150
|
+
},
|
|
25151
|
+
},
|
|
25152
|
+
/**/
|
|
25153
|
+
/**/
|
|
25154
|
+
{
|
|
25155
|
+
modelVariant: 'CHAT',
|
|
25156
|
+
modelTitle: 'gpt-5.1-codex',
|
|
25157
|
+
modelName: 'gpt-5.1-codex',
|
|
25158
|
+
modelDescription: 'Core GPT-5.1 Codex model focused on agentic coding tasks with a balanced trade-off between reasoning and cost.',
|
|
25159
|
+
pricing: {
|
|
25160
|
+
prompt: pricing(`$1.25 / 1M tokens`),
|
|
25161
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
25162
|
+
},
|
|
25163
|
+
},
|
|
25164
|
+
/**/
|
|
25165
|
+
/**/
|
|
25166
|
+
{
|
|
25167
|
+
modelVariant: 'CHAT',
|
|
25168
|
+
modelTitle: 'gpt-5.1-codex-mini',
|
|
25169
|
+
modelName: 'gpt-5.1-codex-mini',
|
|
25170
|
+
modelDescription: 'Compact, cost-effective GPT-5.1 Codex variant with a smaller context window ideal for cheap assistant iterations that still require coding awareness.',
|
|
25171
|
+
pricing: {
|
|
25172
|
+
prompt: pricing(`$0.25 / 1M tokens`),
|
|
25173
|
+
output: pricing(`$2.00 / 1M tokens`),
|
|
25174
|
+
},
|
|
25175
|
+
},
|
|
25176
|
+
/**/
|
|
25177
|
+
/**/
|
|
25178
|
+
{
|
|
25179
|
+
modelVariant: 'CHAT',
|
|
25180
|
+
modelTitle: 'gpt-5-codex',
|
|
25181
|
+
modelName: 'gpt-5-codex',
|
|
25182
|
+
modelDescription: 'Legacy GPT-5 Codex model built for agentic coding workloads with the same pricing as GPT-5 and a focus on stability.',
|
|
25183
|
+
pricing: {
|
|
25184
|
+
prompt: pricing(`$1.25 / 1M tokens`),
|
|
25185
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
25186
|
+
},
|
|
25187
|
+
},
|
|
25188
|
+
/**/
|
|
25189
|
+
/**/
|
|
24975
25190
|
{
|
|
24976
25191
|
modelVariant: 'CHAT',
|
|
24977
25192
|
modelTitle: 'gpt-5-mini',
|
|
@@ -27000,6 +27215,32 @@ function isUnsupportedParameterError(error) {
|
|
|
27000
27215
|
errorMessage.includes('does not support'));
|
|
27001
27216
|
}
|
|
27002
27217
|
|
|
27218
|
+
/**
|
|
27219
|
+
* Provides access to the structured clone implementation when available.
|
|
27220
|
+
*/
|
|
27221
|
+
function getStructuredCloneFunction() {
|
|
27222
|
+
return globalThis.structuredClone;
|
|
27223
|
+
}
|
|
27224
|
+
/**
|
|
27225
|
+
* Checks whether the prompt is a chat prompt that carries file attachments.
|
|
27226
|
+
*/
|
|
27227
|
+
function hasChatPromptFiles(prompt) {
|
|
27228
|
+
return 'files' in prompt && Array.isArray(prompt.files);
|
|
27229
|
+
}
|
|
27230
|
+
/**
|
|
27231
|
+
* Creates a deep copy of the prompt while keeping attached files intact when structured clone is not available.
|
|
27232
|
+
*/
|
|
27233
|
+
function clonePromptPreservingFiles(prompt) {
|
|
27234
|
+
const structuredCloneFn = getStructuredCloneFunction();
|
|
27235
|
+
if (typeof structuredCloneFn === 'function') {
|
|
27236
|
+
return structuredCloneFn(prompt);
|
|
27237
|
+
}
|
|
27238
|
+
const clonedPrompt = JSON.parse(JSON.stringify(prompt));
|
|
27239
|
+
if (hasChatPromptFiles(prompt)) {
|
|
27240
|
+
clonedPrompt.files = prompt.files;
|
|
27241
|
+
}
|
|
27242
|
+
return clonedPrompt;
|
|
27243
|
+
}
|
|
27003
27244
|
/**
|
|
27004
27245
|
* Execution Tools for calling OpenAI API or other OpenAI compatible provider
|
|
27005
27246
|
*
|
|
@@ -27084,7 +27325,7 @@ class OpenAiCompatibleExecutionTools {
|
|
|
27084
27325
|
*/
|
|
27085
27326
|
async callChatModelStream(prompt, onProgress) {
|
|
27086
27327
|
// Deep clone prompt and modelRequirements to avoid mutation across calls
|
|
27087
|
-
const clonedPrompt =
|
|
27328
|
+
const clonedPrompt = clonePromptPreservingFiles(prompt);
|
|
27088
27329
|
// Use local Set for retried parameters to ensure independence and thread safety
|
|
27089
27330
|
const retriedUnsupportedParameters = new Set();
|
|
27090
27331
|
return this.callChatModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters, onProgress);
|
|
@@ -27111,7 +27352,10 @@ class OpenAiCompatibleExecutionTools {
|
|
|
27111
27352
|
// <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
|
|
27112
27353
|
// <- Note: [🧆]
|
|
27113
27354
|
}; // <- TODO: [💩] Guard here types better
|
|
27114
|
-
if (
|
|
27355
|
+
if (currentModelRequirements.responseFormat !== undefined) {
|
|
27356
|
+
modelSettings.response_format = currentModelRequirements.responseFormat;
|
|
27357
|
+
}
|
|
27358
|
+
else if (format === 'JSON') {
|
|
27115
27359
|
modelSettings.response_format = {
|
|
27116
27360
|
type: 'json_object',
|
|
27117
27361
|
};
|
|
@@ -29089,7 +29333,9 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
|
|
|
29089
29333
|
const processingStartedAtMs = Date.now();
|
|
29090
29334
|
for (const [index, source] of knowledgeSources.entries()) {
|
|
29091
29335
|
try {
|
|
29092
|
-
const
|
|
29336
|
+
const isDataUrl = isDataUrlKnowledgeSource(source);
|
|
29337
|
+
const isHttp = source.startsWith('http://') || source.startsWith('https://');
|
|
29338
|
+
const sourceType = isDataUrl ? 'data_url' : isHttp ? 'url' : 'file';
|
|
29093
29339
|
if (this.options.isVerbose) {
|
|
29094
29340
|
console.info('[🤰]', 'Processing knowledge source', {
|
|
29095
29341
|
index: index + 1,
|
|
@@ -29099,8 +29345,27 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
|
|
|
29099
29345
|
logLabel,
|
|
29100
29346
|
});
|
|
29101
29347
|
}
|
|
29102
|
-
|
|
29103
|
-
|
|
29348
|
+
if (isDataUrl) {
|
|
29349
|
+
const parsed = parseDataUrlKnowledgeSource(source);
|
|
29350
|
+
if (!parsed) {
|
|
29351
|
+
skippedSources.push({ source, reason: 'invalid_data_url' });
|
|
29352
|
+
if (this.options.isVerbose) {
|
|
29353
|
+
console.info('[🤰]', 'Skipping knowledge source (invalid data URL)', {
|
|
29354
|
+
source,
|
|
29355
|
+
sourceType,
|
|
29356
|
+
logLabel,
|
|
29357
|
+
});
|
|
29358
|
+
}
|
|
29359
|
+
continue;
|
|
29360
|
+
}
|
|
29361
|
+
const dataUrlFile = new File([parsed.buffer], parsed.filename, {
|
|
29362
|
+
type: parsed.mimeType,
|
|
29363
|
+
});
|
|
29364
|
+
fileStreams.push(dataUrlFile);
|
|
29365
|
+
totalBytes += parsed.buffer.length;
|
|
29366
|
+
continue;
|
|
29367
|
+
}
|
|
29368
|
+
if (isHttp) {
|
|
29104
29369
|
const downloadResult = await this.downloadKnowledgeSourceFile({
|
|
29105
29370
|
source,
|
|
29106
29371
|
timeoutMs: downloadTimeoutMs,
|
|
@@ -30985,11 +31250,14 @@ const _FormattedBookInMarkdownTranspilerRegistration = $bookTranspilersRegister.
|
|
|
30985
31250
|
function createEmptyAgentModelRequirements() {
|
|
30986
31251
|
return {
|
|
30987
31252
|
systemMessage: '',
|
|
31253
|
+
promptSuffix: '',
|
|
30988
31254
|
// modelName: 'gpt-5',
|
|
30989
31255
|
modelName: 'gemini-2.5-flash-lite',
|
|
30990
31256
|
temperature: 0.7,
|
|
30991
31257
|
topP: 0.9,
|
|
30992
31258
|
topK: 50,
|
|
31259
|
+
parentAgentUrl: null,
|
|
31260
|
+
isClosed: false,
|
|
30993
31261
|
};
|
|
30994
31262
|
}
|
|
30995
31263
|
/**
|
|
@@ -31379,14 +31647,42 @@ function removeCommentsFromSystemMessage(systemMessage) {
|
|
|
31379
31647
|
}
|
|
31380
31648
|
|
|
31381
31649
|
/**
|
|
31382
|
-
* Creates agent model requirements using the new commitment system
|
|
31650
|
+
* Creates agent model requirements using the new commitment system.
|
|
31651
|
+
*
|
|
31383
31652
|
* This function uses a reduce-like pattern where each commitment applies its changes
|
|
31384
|
-
* to build the final requirements starting from a basic empty model
|
|
31653
|
+
* to build the final requirements starting from a basic empty model.
|
|
31385
31654
|
*
|
|
31386
|
-
* @
|
|
31655
|
+
* @param agentSource - Agent source book to parse.
|
|
31656
|
+
* @param modelName - Optional override for the agent model name.
|
|
31657
|
+
* @param options - Additional options such as the agent reference resolver.
|
|
31658
|
+
*
|
|
31659
|
+
* @private @@@
|
|
31387
31660
|
*/
|
|
31388
|
-
|
|
31661
|
+
const COMMITMENTS_WITH_AGENT_REFERENCES = new Set(['FROM', 'IMPORT', 'IMPORTS', 'TEAM']);
|
|
31662
|
+
/**
|
|
31663
|
+
* Returns a safe fallback content when a resolver fails to transform a reference commitment.
|
|
31664
|
+
*
|
|
31665
|
+
* @param commitmentType - Commitment being resolved.
|
|
31666
|
+
* @param originalContent - Original unresolved commitment content.
|
|
31667
|
+
* @returns Fallback content that keeps requirement creation resilient.
|
|
31668
|
+
*/
|
|
31669
|
+
function getSafeReferenceCommitmentFallback(commitmentType, originalContent) {
|
|
31670
|
+
if (commitmentType === 'FROM') {
|
|
31671
|
+
return 'VOID';
|
|
31672
|
+
}
|
|
31673
|
+
if (commitmentType === 'IMPORT' || commitmentType === 'IMPORTS' || commitmentType === 'TEAM') {
|
|
31674
|
+
return '';
|
|
31675
|
+
}
|
|
31676
|
+
return originalContent;
|
|
31677
|
+
}
|
|
31678
|
+
/**
|
|
31679
|
+
* @@@
|
|
31680
|
+
*
|
|
31681
|
+
* @private @@@
|
|
31682
|
+
*/
|
|
31683
|
+
async function createAgentModelRequirementsWithCommitments(agentSource, modelName, options) {
|
|
31389
31684
|
var _a;
|
|
31685
|
+
const agentReferenceResolver = options === null || options === void 0 ? void 0 : options.agentReferenceResolver;
|
|
31390
31686
|
// Parse the agent source to extract commitments
|
|
31391
31687
|
const parseResult = parseAgentSourceWithCommitments(agentSource);
|
|
31392
31688
|
// Apply DELETE filtering: remove prior commitments tagged by parameters targeted by DELETE/CANCEL/DISCARD/REMOVE
|
|
@@ -31423,8 +31719,8 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
31423
31719
|
// Store the agent name in metadata so commitments can access it
|
|
31424
31720
|
requirements = {
|
|
31425
31721
|
...requirements,
|
|
31426
|
-
|
|
31427
|
-
...requirements.
|
|
31722
|
+
_metadata: {
|
|
31723
|
+
...requirements._metadata,
|
|
31428
31724
|
agentName: parseResult.agentName,
|
|
31429
31725
|
},
|
|
31430
31726
|
};
|
|
@@ -31438,6 +31734,17 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
31438
31734
|
// Apply each commitment in order using reduce-like pattern
|
|
31439
31735
|
for (let i = 0; i < filteredCommitments.length; i++) {
|
|
31440
31736
|
const commitment = filteredCommitments[i];
|
|
31737
|
+
const isReferenceCommitment = Boolean(agentReferenceResolver && COMMITMENTS_WITH_AGENT_REFERENCES.has(commitment.type));
|
|
31738
|
+
let commitmentContent = commitment.content;
|
|
31739
|
+
if (isReferenceCommitment && agentReferenceResolver) {
|
|
31740
|
+
try {
|
|
31741
|
+
commitmentContent = await agentReferenceResolver.resolveCommitmentContent(commitment.type, commitment.content);
|
|
31742
|
+
}
|
|
31743
|
+
catch (error) {
|
|
31744
|
+
console.warn(`Failed to resolve commitment references for ${commitment.type}, falling back to safe defaults:`, error);
|
|
31745
|
+
commitmentContent = getSafeReferenceCommitmentFallback(commitment.type, commitment.content);
|
|
31746
|
+
}
|
|
31747
|
+
}
|
|
31441
31748
|
// CLOSED commitment should work only if its the last commitment in the book
|
|
31442
31749
|
if (commitment.type === 'CLOSED' && i !== filteredCommitments.length - 1) {
|
|
31443
31750
|
continue;
|
|
@@ -31445,7 +31752,7 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
31445
31752
|
const definition = getCommitmentDefinition(commitment.type);
|
|
31446
31753
|
if (definition) {
|
|
31447
31754
|
try {
|
|
31448
|
-
requirements = definition.applyToAgentModelRequirements(requirements,
|
|
31755
|
+
requirements = definition.applyToAgentModelRequirements(requirements, commitmentContent);
|
|
31449
31756
|
}
|
|
31450
31757
|
catch (error) {
|
|
31451
31758
|
console.warn(`Failed to apply commitment ${commitment.type}:`, error);
|
|
@@ -31904,23 +32211,28 @@ function normalizeSeparator(content) {
|
|
|
31904
32211
|
*/
|
|
31905
32212
|
|
|
31906
32213
|
/**
|
|
31907
|
-
* Creates model requirements for an agent based on its source
|
|
32214
|
+
* Creates model requirements for an agent based on its source.
|
|
31908
32215
|
*
|
|
31909
32216
|
* There are 2 similar functions:
|
|
31910
32217
|
* - `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.
|
|
31911
32218
|
* - `createAgentModelRequirements` which is an asynchronous function that creates model requirements it applies each commitment one by one and works asynchronous.
|
|
31912
32219
|
*
|
|
32220
|
+
* @param agentSource - Book describing the agent.
|
|
32221
|
+
* @param modelName - Optional override for the agent's model.
|
|
32222
|
+
* @param availableModels - Models that could fulfill the agent.
|
|
32223
|
+
* @param llmTools - Execution tools used when selecting a best model.
|
|
32224
|
+
* @param options - Optional hooks such as the agent reference resolver.
|
|
31913
32225
|
* @public exported from `@promptbook/core`
|
|
31914
32226
|
*/
|
|
31915
|
-
async function createAgentModelRequirements(agentSource, modelName, availableModels, llmTools) {
|
|
32227
|
+
async function createAgentModelRequirements(agentSource, modelName, availableModels, llmTools, options) {
|
|
31916
32228
|
// If availableModels are provided and no specific modelName is given,
|
|
31917
32229
|
// use preparePersona to select the best model
|
|
31918
32230
|
if (availableModels && !modelName && llmTools) {
|
|
31919
32231
|
const selectedModelName = await selectBestModelUsingPersona(agentSource, llmTools);
|
|
31920
|
-
return createAgentModelRequirementsWithCommitments(agentSource, selectedModelName);
|
|
32232
|
+
return createAgentModelRequirementsWithCommitments(agentSource, selectedModelName, options);
|
|
31921
32233
|
}
|
|
31922
32234
|
// Use the new commitment-based system with provided or default model
|
|
31923
|
-
return createAgentModelRequirementsWithCommitments(agentSource, modelName);
|
|
32235
|
+
return createAgentModelRequirementsWithCommitments(agentSource, modelName, options);
|
|
31924
32236
|
}
|
|
31925
32237
|
/**
|
|
31926
32238
|
* Selects the best model using the preparePersona function
|
|
@@ -32674,6 +32986,64 @@ function promptbookifyAiText(text) {
|
|
|
32674
32986
|
*/
|
|
32675
32987
|
|
|
32676
32988
|
const DEFAULT_AGENT_KIT_MODEL_NAME = 'gpt-5.2';
|
|
32989
|
+
const DEFAULT_JSON_SCHEMA_NAME = 'StructuredOutput';
|
|
32990
|
+
/*
|
|
32991
|
+
TODO: Use or remove
|
|
32992
|
+
const EMPTY_JSON_SCHEMA: JsonSchemaDefinition['schema'] = {
|
|
32993
|
+
type: 'object',
|
|
32994
|
+
properties: {},
|
|
32995
|
+
required: [],
|
|
32996
|
+
additionalProperties: true,
|
|
32997
|
+
};
|
|
32998
|
+
*/
|
|
32999
|
+
function buildJsonSchemaDefinition(jsonSchema) {
|
|
33000
|
+
var _a, _b, _c;
|
|
33001
|
+
const schema = (_a = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.schema) !== null && _a !== void 0 ? _a : {};
|
|
33002
|
+
return {
|
|
33003
|
+
type: 'json_schema',
|
|
33004
|
+
name: (_b = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.name) !== null && _b !== void 0 ? _b : DEFAULT_JSON_SCHEMA_NAME,
|
|
33005
|
+
strict: Boolean(jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.strict),
|
|
33006
|
+
schema: {
|
|
33007
|
+
type: 'object',
|
|
33008
|
+
properties: ((_c = schema.properties) !== null && _c !== void 0 ? _c : {}),
|
|
33009
|
+
required: Array.isArray(schema.required) ? schema.required : [],
|
|
33010
|
+
additionalProperties: schema.additionalProperties === undefined ? true : Boolean(schema.additionalProperties),
|
|
33011
|
+
description: schema.description,
|
|
33012
|
+
},
|
|
33013
|
+
};
|
|
33014
|
+
}
|
|
33015
|
+
/**
|
|
33016
|
+
* Maps OpenAI `response_format` payloads to AgentKit output types so the runner can forward
|
|
33017
|
+
* structured-output preferences to OpenAI while still reusing the same AgentKit agent instance.
|
|
33018
|
+
*
|
|
33019
|
+
* @param responseFormat - The OpenAI `response_format` payload from the user request.
|
|
33020
|
+
* @returns An Agent output type compatible with the requested schema or `undefined` when no impact is required.
|
|
33021
|
+
* @private utility of Open AI
|
|
33022
|
+
*/
|
|
33023
|
+
function mapResponseFormatToAgentOutputType(responseFormat) {
|
|
33024
|
+
if (!responseFormat) {
|
|
33025
|
+
return undefined;
|
|
33026
|
+
}
|
|
33027
|
+
if (typeof responseFormat === 'string') {
|
|
33028
|
+
if (responseFormat === 'text') {
|
|
33029
|
+
return 'text';
|
|
33030
|
+
}
|
|
33031
|
+
if (responseFormat === 'json_schema' || responseFormat === 'json_object') {
|
|
33032
|
+
return buildJsonSchemaDefinition();
|
|
33033
|
+
}
|
|
33034
|
+
return 'text';
|
|
33035
|
+
}
|
|
33036
|
+
switch (responseFormat.type) {
|
|
33037
|
+
case 'text':
|
|
33038
|
+
return 'text';
|
|
33039
|
+
case 'json_schema':
|
|
33040
|
+
return buildJsonSchemaDefinition(responseFormat.json_schema);
|
|
33041
|
+
case 'json_object':
|
|
33042
|
+
return buildJsonSchemaDefinition();
|
|
33043
|
+
default:
|
|
33044
|
+
return undefined;
|
|
33045
|
+
}
|
|
33046
|
+
}
|
|
32677
33047
|
/**
|
|
32678
33048
|
* Execution tools for OpenAI AgentKit (Agents SDK).
|
|
32679
33049
|
*
|
|
@@ -32721,6 +33091,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
32721
33091
|
...parameters,
|
|
32722
33092
|
modelName: this.agentKitModelName,
|
|
32723
33093
|
});
|
|
33094
|
+
const responseFormatOutputType = mapResponseFormatToAgentOutputType(modelRequirements.responseFormat);
|
|
32724
33095
|
const preparedAgentKitAgent = await this.prepareAgentKitAgent({
|
|
32725
33096
|
name: (prompt.title || 'Agent'),
|
|
32726
33097
|
instructions: modelRequirements.systemMessage || '',
|
|
@@ -32732,6 +33103,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
32732
33103
|
prompt,
|
|
32733
33104
|
rawPromptContent,
|
|
32734
33105
|
onProgress,
|
|
33106
|
+
responseFormatOutputType,
|
|
32735
33107
|
});
|
|
32736
33108
|
}
|
|
32737
33109
|
/**
|
|
@@ -32913,16 +33285,21 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
32913
33285
|
...prompt.parameters,
|
|
32914
33286
|
modelName: this.agentKitModelName,
|
|
32915
33287
|
});
|
|
33288
|
+
const agentForRun = options.responseFormatOutputType !== undefined
|
|
33289
|
+
? openAiAgentKitAgent.clone({
|
|
33290
|
+
outputType: options.responseFormatOutputType,
|
|
33291
|
+
})
|
|
33292
|
+
: openAiAgentKitAgent;
|
|
32916
33293
|
const start = $getCurrentDate();
|
|
32917
33294
|
let latestContent = '';
|
|
32918
33295
|
const toolCalls = [];
|
|
32919
33296
|
const toolCallIndexById = new Map();
|
|
32920
33297
|
const inputItems = await this.buildAgentKitInputItems(prompt, rawPromptContent);
|
|
32921
33298
|
const rawRequest = {
|
|
32922
|
-
agentName:
|
|
33299
|
+
agentName: agentForRun.name,
|
|
32923
33300
|
input: inputItems,
|
|
32924
33301
|
};
|
|
32925
|
-
const streamResult = await run(
|
|
33302
|
+
const streamResult = await run(agentForRun, inputItems, {
|
|
32926
33303
|
stream: true,
|
|
32927
33304
|
context: { parameters: prompt.parameters },
|
|
32928
33305
|
});
|
|
@@ -33270,22 +33647,28 @@ class AgentLlmExecutionTools {
|
|
|
33270
33647
|
throw new Error('AgentLlmExecutionTools only supports chat prompts');
|
|
33271
33648
|
}
|
|
33272
33649
|
const modelRequirements = await this.getModelRequirements();
|
|
33650
|
+
const { _metadata, promptSuffix, ...sanitizedRequirements } = modelRequirements;
|
|
33273
33651
|
const chatPrompt = prompt;
|
|
33274
33652
|
let underlyingLlmResult;
|
|
33275
|
-
|
|
33653
|
+
const chatPromptContentWithSuffix = promptSuffix
|
|
33654
|
+
? `${chatPrompt.content}\n\n${promptSuffix}`
|
|
33655
|
+
: chatPrompt.content;
|
|
33276
33656
|
const promptWithAgentModelRequirements = {
|
|
33277
33657
|
...chatPrompt,
|
|
33658
|
+
content: chatPromptContentWithSuffix,
|
|
33278
33659
|
modelRequirements: {
|
|
33279
33660
|
...chatPrompt.modelRequirements,
|
|
33280
|
-
...
|
|
33661
|
+
...sanitizedRequirements,
|
|
33281
33662
|
// Spread tools to convert readonly array to mutable
|
|
33282
|
-
tools:
|
|
33663
|
+
tools: sanitizedRequirements.tools
|
|
33664
|
+
? [...sanitizedRequirements.tools]
|
|
33665
|
+
: chatPrompt.modelRequirements.tools,
|
|
33283
33666
|
// Spread knowledgeSources to convert readonly array to mutable
|
|
33284
|
-
knowledgeSources:
|
|
33285
|
-
? [...
|
|
33667
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources
|
|
33668
|
+
? [...sanitizedRequirements.knowledgeSources]
|
|
33286
33669
|
: undefined,
|
|
33287
33670
|
// Prepend agent system message to existing system message
|
|
33288
|
-
systemMessage:
|
|
33671
|
+
systemMessage: sanitizedRequirements.systemMessage +
|
|
33289
33672
|
(chatPrompt.modelRequirements.systemMessage
|
|
33290
33673
|
? `\n\n${chatPrompt.modelRequirements.systemMessage}`
|
|
33291
33674
|
: ''),
|
|
@@ -33293,8 +33676,8 @@ class AgentLlmExecutionTools {
|
|
|
33293
33676
|
};
|
|
33294
33677
|
console.log('!!!! promptWithAgentModelRequirements:', promptWithAgentModelRequirements);
|
|
33295
33678
|
if (OpenAiAgentKitExecutionTools.isOpenAiAgentKitExecutionTools(this.options.llmTools)) {
|
|
33296
|
-
const requirementsHash = SHA256(JSON.stringify(
|
|
33297
|
-
const vectorStoreHash = SHA256(JSON.stringify((_a =
|
|
33679
|
+
const requirementsHash = SHA256(JSON.stringify(sanitizedRequirements)).toString();
|
|
33680
|
+
const vectorStoreHash = SHA256(JSON.stringify((_a = sanitizedRequirements.knowledgeSources) !== null && _a !== void 0 ? _a : [])).toString();
|
|
33298
33681
|
const cachedVectorStore = AgentLlmExecutionTools.vectorStoreCache.get(this.title);
|
|
33299
33682
|
const cachedAgentKit = AgentLlmExecutionTools.agentKitAgentCache.get(this.title);
|
|
33300
33683
|
let preparedAgentKit = this.options.assistantPreparationMode === 'external'
|
|
@@ -33321,7 +33704,7 @@ class AgentLlmExecutionTools {
|
|
|
33321
33704
|
agent: this.title,
|
|
33322
33705
|
});
|
|
33323
33706
|
}
|
|
33324
|
-
if (!vectorStoreId && ((_b =
|
|
33707
|
+
if (!vectorStoreId && ((_b = sanitizedRequirements.knowledgeSources) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
33325
33708
|
emitAssistantPreparationProgress({
|
|
33326
33709
|
onProgress,
|
|
33327
33710
|
prompt,
|
|
@@ -33337,9 +33720,9 @@ class AgentLlmExecutionTools {
|
|
|
33337
33720
|
});
|
|
33338
33721
|
preparedAgentKit = await this.options.llmTools.prepareAgentKitAgent({
|
|
33339
33722
|
name: this.title,
|
|
33340
|
-
instructions:
|
|
33341
|
-
knowledgeSources:
|
|
33342
|
-
tools:
|
|
33723
|
+
instructions: sanitizedRequirements.systemMessage || '',
|
|
33724
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources,
|
|
33725
|
+
tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
|
|
33343
33726
|
vectorStoreId,
|
|
33344
33727
|
});
|
|
33345
33728
|
}
|
|
@@ -33354,15 +33737,17 @@ class AgentLlmExecutionTools {
|
|
|
33354
33737
|
requirementsHash,
|
|
33355
33738
|
vectorStoreId: preparedAgentKit.vectorStoreId,
|
|
33356
33739
|
});
|
|
33740
|
+
const responseFormatOutputType = mapResponseFormatToAgentOutputType(promptWithAgentModelRequirements.modelRequirements.responseFormat);
|
|
33357
33741
|
underlyingLlmResult = await this.options.llmTools.callChatModelStreamWithPreparedAgent({
|
|
33358
33742
|
openAiAgentKitAgent: preparedAgentKit.agent,
|
|
33359
33743
|
prompt: promptWithAgentModelRequirements,
|
|
33360
33744
|
onProgress,
|
|
33745
|
+
responseFormatOutputType,
|
|
33361
33746
|
});
|
|
33362
33747
|
}
|
|
33363
33748
|
else if (OpenAiAssistantExecutionTools.isOpenAiAssistantExecutionTools(this.options.llmTools)) {
|
|
33364
33749
|
// ... deprecated path ...
|
|
33365
|
-
const requirementsHash = SHA256(JSON.stringify(
|
|
33750
|
+
const requirementsHash = SHA256(JSON.stringify(sanitizedRequirements)).toString();
|
|
33366
33751
|
const cached = AgentLlmExecutionTools.assistantCache.get(this.title);
|
|
33367
33752
|
let assistant;
|
|
33368
33753
|
if (this.options.assistantPreparationMode === 'external') {
|
|
@@ -33404,9 +33789,9 @@ class AgentLlmExecutionTools {
|
|
|
33404
33789
|
assistant = await this.options.llmTools.updateAssistant({
|
|
33405
33790
|
assistantId: cached.assistantId,
|
|
33406
33791
|
name: this.title,
|
|
33407
|
-
instructions:
|
|
33408
|
-
knowledgeSources:
|
|
33409
|
-
tools:
|
|
33792
|
+
instructions: sanitizedRequirements.systemMessage,
|
|
33793
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources,
|
|
33794
|
+
tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
|
|
33410
33795
|
});
|
|
33411
33796
|
AgentLlmExecutionTools.assistantCache.set(this.title, {
|
|
33412
33797
|
assistantId: assistant.assistantId,
|
|
@@ -33429,9 +33814,9 @@ class AgentLlmExecutionTools {
|
|
|
33429
33814
|
});
|
|
33430
33815
|
assistant = await this.options.llmTools.createNewAssistant({
|
|
33431
33816
|
name: this.title,
|
|
33432
|
-
instructions:
|
|
33433
|
-
knowledgeSources:
|
|
33434
|
-
tools:
|
|
33817
|
+
instructions: sanitizedRequirements.systemMessage,
|
|
33818
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources,
|
|
33819
|
+
tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
|
|
33435
33820
|
/*
|
|
33436
33821
|
!!!
|
|
33437
33822
|
metadata: {
|
|
@@ -33473,13 +33858,19 @@ class AgentLlmExecutionTools {
|
|
|
33473
33858
|
}
|
|
33474
33859
|
}
|
|
33475
33860
|
let content = underlyingLlmResult.content;
|
|
33476
|
-
|
|
33477
|
-
|
|
33478
|
-
|
|
33479
|
-
|
|
33861
|
+
if (typeof content === 'string') {
|
|
33862
|
+
// Note: Cleanup the AI artifacts from the content
|
|
33863
|
+
content = humanizeAiText(content);
|
|
33864
|
+
// Note: Make sure the content is Promptbook-like
|
|
33865
|
+
content = promptbookifyAiText(content);
|
|
33866
|
+
}
|
|
33867
|
+
else {
|
|
33868
|
+
// TODO: Maybe deep `humanizeAiText` + `promptbookifyAiText` inside of the object
|
|
33869
|
+
content = JSON.stringify(content);
|
|
33870
|
+
}
|
|
33480
33871
|
const agentResult = {
|
|
33481
33872
|
...underlyingLlmResult,
|
|
33482
|
-
content,
|
|
33873
|
+
content: content,
|
|
33483
33874
|
modelName: this.modelName,
|
|
33484
33875
|
};
|
|
33485
33876
|
return agentResult;
|
|
@@ -33668,7 +34059,6 @@ class Agent extends AgentLlmExecutionTools {
|
|
|
33668
34059
|
* Note: This method also implements the learning mechanism
|
|
33669
34060
|
*/
|
|
33670
34061
|
async callChatModelStream(prompt, onProgress) {
|
|
33671
|
-
var _a;
|
|
33672
34062
|
// [1] Check if the user is asking the same thing as in the samples
|
|
33673
34063
|
const modelRequirements = await this.getModelRequirements();
|
|
33674
34064
|
if (modelRequirements.samples) {
|
|
@@ -33716,7 +34106,7 @@ class Agent extends AgentLlmExecutionTools {
|
|
|
33716
34106
|
if (result.rawResponse && 'sample' in result.rawResponse) {
|
|
33717
34107
|
return result;
|
|
33718
34108
|
}
|
|
33719
|
-
if (
|
|
34109
|
+
if (modelRequirements.isClosed) {
|
|
33720
34110
|
return result;
|
|
33721
34111
|
}
|
|
33722
34112
|
// Note: [0] Notify start of self-learning
|