@promptbook/browser 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 +2 -2
- package/umd/index.umd.js +487 -97
- package/umd/index.umd.js.map +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.110.0
|
|
32
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.110.0';
|
|
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
|
|
@@ -1330,6 +1330,28 @@ class BaseCommitmentDefinition {
|
|
|
1330
1330
|
return currentMessage + separator + content;
|
|
1331
1331
|
});
|
|
1332
1332
|
}
|
|
1333
|
+
/**
|
|
1334
|
+
* Helper method to create a new requirements object with updated prompt suffix
|
|
1335
|
+
*/
|
|
1336
|
+
updatePromptSuffix(requirements, contentUpdate) {
|
|
1337
|
+
const newSuffix = typeof contentUpdate === 'string' ? contentUpdate : contentUpdate(requirements.promptSuffix);
|
|
1338
|
+
return {
|
|
1339
|
+
...requirements,
|
|
1340
|
+
promptSuffix: newSuffix,
|
|
1341
|
+
};
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Helper method to append content to the prompt suffix
|
|
1345
|
+
* Default separator is a single newline for bullet lists.
|
|
1346
|
+
*/
|
|
1347
|
+
appendToPromptSuffix(requirements, content, separator = '\n') {
|
|
1348
|
+
return this.updatePromptSuffix(requirements, (currentSuffix) => {
|
|
1349
|
+
if (!currentSuffix.trim()) {
|
|
1350
|
+
return content;
|
|
1351
|
+
}
|
|
1352
|
+
return `${currentSuffix}${separator}${content}`;
|
|
1353
|
+
});
|
|
1354
|
+
}
|
|
1333
1355
|
/**
|
|
1334
1356
|
* Helper method to add a comment section to the system message
|
|
1335
1357
|
* Comments are lines starting with # that will be removed from the final system message
|
|
@@ -1524,13 +1546,9 @@ class ClosedCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
1524
1546
|
`);
|
|
1525
1547
|
}
|
|
1526
1548
|
applyToAgentModelRequirements(requirements, _content) {
|
|
1527
|
-
const updatedMetadata = {
|
|
1528
|
-
...requirements.metadata,
|
|
1529
|
-
isClosed: true,
|
|
1530
|
-
};
|
|
1531
1549
|
return {
|
|
1532
1550
|
...requirements,
|
|
1533
|
-
|
|
1551
|
+
isClosed: true,
|
|
1534
1552
|
};
|
|
1535
1553
|
}
|
|
1536
1554
|
}
|
|
@@ -1808,12 +1826,12 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
1808
1826
|
return requirements;
|
|
1809
1827
|
}
|
|
1810
1828
|
// Get existing dictionary entries from metadata
|
|
1811
|
-
const existingDictionary = ((_a = requirements.
|
|
1829
|
+
const existingDictionary = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
|
|
1812
1830
|
// Merge the new dictionary entry with existing entries
|
|
1813
1831
|
const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
|
|
1814
1832
|
// Store the merged dictionary in metadata for debugging and inspection
|
|
1815
1833
|
const updatedMetadata = {
|
|
1816
|
-
...requirements.
|
|
1834
|
+
...requirements._metadata,
|
|
1817
1835
|
DICTIONARY: mergedDictionary,
|
|
1818
1836
|
};
|
|
1819
1837
|
// Create the dictionary section for the system message
|
|
@@ -1821,7 +1839,7 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
1821
1839
|
const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
|
|
1822
1840
|
return {
|
|
1823
1841
|
...this.appendToSystemMessage(requirements, dictionarySection),
|
|
1824
|
-
|
|
1842
|
+
_metadata: updatedMetadata,
|
|
1825
1843
|
};
|
|
1826
1844
|
}
|
|
1827
1845
|
}
|
|
@@ -5966,10 +5984,7 @@ class FromCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
5966
5984
|
applyToAgentModelRequirements(requirements, content) {
|
|
5967
5985
|
const trimmedContent = content.trim();
|
|
5968
5986
|
if (!trimmedContent) {
|
|
5969
|
-
return
|
|
5970
|
-
...requirements,
|
|
5971
|
-
parentAgentUrl: undefined,
|
|
5972
|
-
};
|
|
5987
|
+
return requirements;
|
|
5973
5988
|
}
|
|
5974
5989
|
if (trimmedContent.toUpperCase() === 'VOID' ||
|
|
5975
5990
|
trimmedContent.toUpperCase() === 'NULL' ||
|
|
@@ -6183,6 +6198,136 @@ class ImportCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
6183
6198
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
6184
6199
|
*/
|
|
6185
6200
|
|
|
6201
|
+
/**
|
|
6202
|
+
* @@@
|
|
6203
|
+
*
|
|
6204
|
+
* @private thing of inline knowledge
|
|
6205
|
+
*/
|
|
6206
|
+
const INLINE_KNOWLEDGE_BASE_NAME = 'inline-knowledge';
|
|
6207
|
+
/**
|
|
6208
|
+
* @@@
|
|
6209
|
+
*
|
|
6210
|
+
* @private thing of inline knowledge
|
|
6211
|
+
*/
|
|
6212
|
+
const INLINE_KNOWLEDGE_EXTENSION = '.txt';
|
|
6213
|
+
/**
|
|
6214
|
+
* @@@
|
|
6215
|
+
*
|
|
6216
|
+
* @private thing of inline knowledge
|
|
6217
|
+
*/
|
|
6218
|
+
const DATA_URL_PREFIX = 'data:';
|
|
6219
|
+
/**
|
|
6220
|
+
* @@@
|
|
6221
|
+
*
|
|
6222
|
+
* @private thing of inline knowledge
|
|
6223
|
+
*/
|
|
6224
|
+
function getFirstNonEmptyLine(content) {
|
|
6225
|
+
const lines = content.split(/\r?\n/);
|
|
6226
|
+
for (const line of lines) {
|
|
6227
|
+
const trimmed = line.trim();
|
|
6228
|
+
if (trimmed) {
|
|
6229
|
+
return trimmed;
|
|
6230
|
+
}
|
|
6231
|
+
}
|
|
6232
|
+
return null;
|
|
6233
|
+
}
|
|
6234
|
+
/**
|
|
6235
|
+
* @@@
|
|
6236
|
+
*
|
|
6237
|
+
* @private thing of inline knowledge
|
|
6238
|
+
*/
|
|
6239
|
+
function deriveBaseFilename(content) {
|
|
6240
|
+
const firstLine = getFirstNonEmptyLine(content);
|
|
6241
|
+
if (!firstLine) {
|
|
6242
|
+
return INLINE_KNOWLEDGE_BASE_NAME;
|
|
6243
|
+
}
|
|
6244
|
+
const normalized = normalizeToKebabCase(firstLine);
|
|
6245
|
+
return normalized || INLINE_KNOWLEDGE_BASE_NAME;
|
|
6246
|
+
}
|
|
6247
|
+
/**
|
|
6248
|
+
* Creates a data URL that represents the inline knowledge content as a text file.
|
|
6249
|
+
*
|
|
6250
|
+
* @private thing of inline knowledge
|
|
6251
|
+
*/
|
|
6252
|
+
function createInlineKnowledgeSourceFile(content) {
|
|
6253
|
+
const trimmedContent = content.trim();
|
|
6254
|
+
const baseName = deriveBaseFilename(trimmedContent);
|
|
6255
|
+
const filename = `${baseName}${INLINE_KNOWLEDGE_EXTENSION}`;
|
|
6256
|
+
const mimeType = 'text/plain';
|
|
6257
|
+
const base64 = Buffer.from(trimmedContent, 'utf-8').toString('base64');
|
|
6258
|
+
const encodedFilename = encodeURIComponent(filename);
|
|
6259
|
+
const url = `${DATA_URL_PREFIX}${mimeType};name=${encodedFilename};charset=utf-8;base64,${base64}`;
|
|
6260
|
+
return {
|
|
6261
|
+
filename,
|
|
6262
|
+
mimeType,
|
|
6263
|
+
url,
|
|
6264
|
+
};
|
|
6265
|
+
}
|
|
6266
|
+
/**
|
|
6267
|
+
* Checks whether the provided source string is a data URL that can be decoded.
|
|
6268
|
+
*
|
|
6269
|
+
* @private thing of inline knowledge
|
|
6270
|
+
*/
|
|
6271
|
+
function isDataUrlKnowledgeSource(source) {
|
|
6272
|
+
return typeof source === 'string' && source.startsWith(DATA_URL_PREFIX);
|
|
6273
|
+
}
|
|
6274
|
+
/**
|
|
6275
|
+
* Parses a data URL-based knowledge source into its raw buffer, filename, and MIME type.
|
|
6276
|
+
*
|
|
6277
|
+
* @private thing of inline knowledge
|
|
6278
|
+
*/
|
|
6279
|
+
function parseDataUrlKnowledgeSource(source) {
|
|
6280
|
+
if (!isDataUrlKnowledgeSource(source)) {
|
|
6281
|
+
return null;
|
|
6282
|
+
}
|
|
6283
|
+
const commaIndex = source.indexOf(',');
|
|
6284
|
+
if (commaIndex === -1) {
|
|
6285
|
+
return null;
|
|
6286
|
+
}
|
|
6287
|
+
const header = source.slice(DATA_URL_PREFIX.length, commaIndex);
|
|
6288
|
+
const payload = source.slice(commaIndex + 1);
|
|
6289
|
+
const tokens = header.split(';');
|
|
6290
|
+
const mediaType = tokens[0] || 'text/plain';
|
|
6291
|
+
let filename = `${INLINE_KNOWLEDGE_BASE_NAME}${INLINE_KNOWLEDGE_EXTENSION}`;
|
|
6292
|
+
let isBase64 = false;
|
|
6293
|
+
for (let i = 1; i < tokens.length; i++) {
|
|
6294
|
+
const token = tokens[i];
|
|
6295
|
+
if (!token) {
|
|
6296
|
+
continue;
|
|
6297
|
+
}
|
|
6298
|
+
if (token.toLowerCase() === 'base64') {
|
|
6299
|
+
isBase64 = true;
|
|
6300
|
+
continue;
|
|
6301
|
+
}
|
|
6302
|
+
const [key, value] = token.split('=');
|
|
6303
|
+
if (key === 'name' && value !== undefined) {
|
|
6304
|
+
try {
|
|
6305
|
+
filename = decodeURIComponent(value);
|
|
6306
|
+
}
|
|
6307
|
+
catch (_a) {
|
|
6308
|
+
filename = value;
|
|
6309
|
+
}
|
|
6310
|
+
}
|
|
6311
|
+
}
|
|
6312
|
+
if (!isBase64) {
|
|
6313
|
+
return null;
|
|
6314
|
+
}
|
|
6315
|
+
try {
|
|
6316
|
+
const buffer = Buffer.from(payload, 'base64');
|
|
6317
|
+
return {
|
|
6318
|
+
buffer,
|
|
6319
|
+
filename,
|
|
6320
|
+
mimeType: mediaType,
|
|
6321
|
+
};
|
|
6322
|
+
}
|
|
6323
|
+
catch (_b) {
|
|
6324
|
+
return null;
|
|
6325
|
+
}
|
|
6326
|
+
}
|
|
6327
|
+
/**
|
|
6328
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
6329
|
+
*/
|
|
6330
|
+
|
|
6186
6331
|
/**
|
|
6187
6332
|
* KNOWLEDGE commitment definition
|
|
6188
6333
|
*
|
|
@@ -6281,9 +6426,13 @@ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
6281
6426
|
return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
|
|
6282
6427
|
}
|
|
6283
6428
|
else {
|
|
6284
|
-
|
|
6285
|
-
const
|
|
6286
|
-
|
|
6429
|
+
const inlineSource = createInlineKnowledgeSourceFile(trimmedContent);
|
|
6430
|
+
const updatedRequirements = {
|
|
6431
|
+
...requirements,
|
|
6432
|
+
knowledgeSources: [...(requirements.knowledgeSources || []), inlineSource.url],
|
|
6433
|
+
};
|
|
6434
|
+
const knowledgeInfo = `Knowledge Source Inline: ${inlineSource.filename} (derived from inline content and processed for retrieval during chat)`;
|
|
6435
|
+
return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
|
|
6287
6436
|
}
|
|
6288
6437
|
}
|
|
6289
6438
|
}
|
|
@@ -6530,16 +6679,16 @@ class AgentMessageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
6530
6679
|
// and typically doesn't need to be added to the system prompt or model requirements directly.
|
|
6531
6680
|
// It is extracted separately for the chat interface.
|
|
6532
6681
|
var _a;
|
|
6533
|
-
const pendingUserMessage = (_a = requirements.
|
|
6682
|
+
const pendingUserMessage = (_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
|
|
6534
6683
|
if (pendingUserMessage) {
|
|
6535
6684
|
const newSample = { question: pendingUserMessage, answer: content };
|
|
6536
6685
|
const newSamples = [...(requirements.samples || []), newSample];
|
|
6537
|
-
const newMetadata = { ...requirements.
|
|
6686
|
+
const newMetadata = { ...requirements._metadata };
|
|
6538
6687
|
delete newMetadata.pendingUserMessage;
|
|
6539
6688
|
return {
|
|
6540
6689
|
...requirements,
|
|
6541
6690
|
samples: newSamples,
|
|
6542
|
-
|
|
6691
|
+
_metadata: newMetadata,
|
|
6543
6692
|
};
|
|
6544
6693
|
}
|
|
6545
6694
|
return requirements;
|
|
@@ -6787,8 +6936,8 @@ class UserMessageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
6787
6936
|
applyToAgentModelRequirements(requirements, content) {
|
|
6788
6937
|
return {
|
|
6789
6938
|
...requirements,
|
|
6790
|
-
|
|
6791
|
-
...requirements.
|
|
6939
|
+
_metadata: {
|
|
6940
|
+
...requirements._metadata,
|
|
6792
6941
|
pendingUserMessage: content,
|
|
6793
6942
|
},
|
|
6794
6943
|
};
|
|
@@ -7646,11 +7795,7 @@ class NoteCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7646
7795
|
if (trimmedContent === '') {
|
|
7647
7796
|
return requirements;
|
|
7648
7797
|
}
|
|
7649
|
-
|
|
7650
|
-
return {
|
|
7651
|
-
...requirements,
|
|
7652
|
-
notes: [...(requirements.notes || []), trimmedContent],
|
|
7653
|
-
};
|
|
7798
|
+
return requirements;
|
|
7654
7799
|
}
|
|
7655
7800
|
}
|
|
7656
7801
|
/**
|
|
@@ -7712,12 +7857,12 @@ class OpenCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7712
7857
|
// Since OPEN is default, we can just ensure isClosed is false
|
|
7713
7858
|
// But to be explicit we can set it
|
|
7714
7859
|
const updatedMetadata = {
|
|
7715
|
-
...requirements.
|
|
7860
|
+
...requirements._metadata,
|
|
7716
7861
|
isClosed: false,
|
|
7717
7862
|
};
|
|
7718
7863
|
return {
|
|
7719
7864
|
...requirements,
|
|
7720
|
-
|
|
7865
|
+
_metadata: updatedMetadata,
|
|
7721
7866
|
};
|
|
7722
7867
|
}
|
|
7723
7868
|
}
|
|
@@ -7798,7 +7943,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7798
7943
|
return requirements;
|
|
7799
7944
|
}
|
|
7800
7945
|
// Get existing persona content from metadata
|
|
7801
|
-
const existingPersonaContent = ((_a = requirements.
|
|
7946
|
+
const existingPersonaContent = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.PERSONA) || '';
|
|
7802
7947
|
// Merge the new content with existing persona content
|
|
7803
7948
|
// When multiple PERSONA commitments exist, they are merged into one
|
|
7804
7949
|
const mergedPersonaContent = existingPersonaContent
|
|
@@ -7806,12 +7951,12 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7806
7951
|
: trimmedContent;
|
|
7807
7952
|
// Store the merged persona content in metadata for debugging and inspection
|
|
7808
7953
|
const updatedMetadata = {
|
|
7809
|
-
...requirements.
|
|
7954
|
+
...requirements._metadata,
|
|
7810
7955
|
PERSONA: mergedPersonaContent,
|
|
7811
7956
|
};
|
|
7812
7957
|
// Get the agent name from metadata (which should contain the first line of agent source)
|
|
7813
7958
|
// If not available, extract from current system message as fallback
|
|
7814
|
-
let agentName = (_b = requirements.
|
|
7959
|
+
let agentName = (_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.agentName;
|
|
7815
7960
|
if (!agentName) {
|
|
7816
7961
|
// Fallback: extract from current system message
|
|
7817
7962
|
const currentMessage = requirements.systemMessage.trim();
|
|
@@ -7858,7 +8003,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7858
8003
|
return {
|
|
7859
8004
|
...requirements,
|
|
7860
8005
|
systemMessage: newSystemMessage,
|
|
7861
|
-
|
|
8006
|
+
_metadata: updatedMetadata,
|
|
7862
8007
|
};
|
|
7863
8008
|
}
|
|
7864
8009
|
}
|
|
@@ -7941,7 +8086,16 @@ class RuleCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7941
8086
|
}
|
|
7942
8087
|
// Add rule to the system message
|
|
7943
8088
|
const ruleSection = `Rule: ${trimmedContent}`;
|
|
7944
|
-
|
|
8089
|
+
const requirementsWithRule = this.appendToSystemMessage(requirements, ruleSection, '\n\n');
|
|
8090
|
+
const ruleLines = trimmedContent
|
|
8091
|
+
.split(/\r?\n/)
|
|
8092
|
+
.map((line) => line.trim())
|
|
8093
|
+
.filter(Boolean)
|
|
8094
|
+
.map((line) => `- ${line}`);
|
|
8095
|
+
if (ruleLines.length === 0) {
|
|
8096
|
+
return requirementsWithRule;
|
|
8097
|
+
}
|
|
8098
|
+
return this.appendToPromptSuffix(requirementsWithRule, ruleLines.join('\n'));
|
|
7945
8099
|
}
|
|
7946
8100
|
}
|
|
7947
8101
|
/**
|
|
@@ -8443,11 +8597,12 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8443
8597
|
if (!trimmedContent) {
|
|
8444
8598
|
return requirements;
|
|
8445
8599
|
}
|
|
8446
|
-
|
|
8600
|
+
// Keep TEAM resilient: unresolved/malformed teammate entries are skipped, valid ones are still registered.
|
|
8601
|
+
const teammates = parseTeamCommitmentContent(trimmedContent, { strict: false });
|
|
8447
8602
|
if (teammates.length === 0) {
|
|
8448
8603
|
return requirements;
|
|
8449
8604
|
}
|
|
8450
|
-
const agentName = ((_a = requirements.
|
|
8605
|
+
const agentName = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.agentName) || 'Agent';
|
|
8451
8606
|
const teamEntries = teammates.map((teammate) => ({
|
|
8452
8607
|
toolName: createTeamToolName(teammate.url),
|
|
8453
8608
|
teammate,
|
|
@@ -8487,7 +8642,7 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8487
8642
|
},
|
|
8488
8643
|
});
|
|
8489
8644
|
}
|
|
8490
|
-
const existingTeammates = ((_b = requirements.
|
|
8645
|
+
const existingTeammates = ((_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.teammates) || [];
|
|
8491
8646
|
const updatedTeammates = [...existingTeammates];
|
|
8492
8647
|
for (const entry of teamEntries) {
|
|
8493
8648
|
if (updatedTeammates.some((existing) => existing.url === entry.teammate.url)) {
|
|
@@ -8516,8 +8671,8 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8516
8671
|
return this.appendToSystemMessage({
|
|
8517
8672
|
...requirements,
|
|
8518
8673
|
tools: updatedTools,
|
|
8519
|
-
|
|
8520
|
-
...requirements.
|
|
8674
|
+
_metadata: {
|
|
8675
|
+
...requirements._metadata,
|
|
8521
8676
|
teammates: updatedTeammates,
|
|
8522
8677
|
},
|
|
8523
8678
|
}, teamSystemMessage);
|
|
@@ -8749,7 +8904,7 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8749
8904
|
if (!trimmedContent) {
|
|
8750
8905
|
// Store template mode flag in metadata
|
|
8751
8906
|
const updatedMetadata = {
|
|
8752
|
-
...requirements.
|
|
8907
|
+
...requirements._metadata,
|
|
8753
8908
|
templateMode: true,
|
|
8754
8909
|
};
|
|
8755
8910
|
// Add a general instruction about using structured templates
|
|
@@ -8759,21 +8914,21 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8759
8914
|
`);
|
|
8760
8915
|
return {
|
|
8761
8916
|
...this.appendToSystemMessage(requirements, templateModeInstruction, '\n\n'),
|
|
8762
|
-
|
|
8917
|
+
_metadata: updatedMetadata,
|
|
8763
8918
|
};
|
|
8764
8919
|
}
|
|
8765
8920
|
// If content is provided, add the specific template instructions
|
|
8766
8921
|
const templateSection = `Response Template: ${trimmedContent}`;
|
|
8767
8922
|
// Store the template in metadata for potential programmatic access
|
|
8768
|
-
const existingTemplates = ((_a = requirements.
|
|
8923
|
+
const existingTemplates = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.templates) || [];
|
|
8769
8924
|
const updatedMetadata = {
|
|
8770
|
-
...requirements.
|
|
8925
|
+
...requirements._metadata,
|
|
8771
8926
|
templates: [...existingTemplates, trimmedContent],
|
|
8772
8927
|
templateMode: true,
|
|
8773
8928
|
};
|
|
8774
8929
|
return {
|
|
8775
8930
|
...this.appendToSystemMessage(requirements, templateSection, '\n\n'),
|
|
8776
|
-
|
|
8931
|
+
_metadata: updatedMetadata,
|
|
8777
8932
|
};
|
|
8778
8933
|
}
|
|
8779
8934
|
}
|
|
@@ -9110,8 +9265,8 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
9110
9265
|
return this.appendToSystemMessage({
|
|
9111
9266
|
...requirements,
|
|
9112
9267
|
tools: updatedTools,
|
|
9113
|
-
|
|
9114
|
-
...requirements.
|
|
9268
|
+
_metadata: {
|
|
9269
|
+
...requirements._metadata,
|
|
9115
9270
|
useBrowser: true,
|
|
9116
9271
|
},
|
|
9117
9272
|
}, spaceTrim$1(`
|
|
@@ -9340,8 +9495,8 @@ class UseEmailCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
9340
9495
|
return this.appendToSystemMessage({
|
|
9341
9496
|
...requirements,
|
|
9342
9497
|
tools: updatedTools,
|
|
9343
|
-
|
|
9344
|
-
...requirements.
|
|
9498
|
+
_metadata: {
|
|
9499
|
+
...requirements._metadata,
|
|
9345
9500
|
useEmail: content || true,
|
|
9346
9501
|
},
|
|
9347
9502
|
}, spaceTrim$1((block) => `
|
|
@@ -9476,8 +9631,8 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
9476
9631
|
return this.appendToSystemMessage({
|
|
9477
9632
|
...requirements,
|
|
9478
9633
|
tools: updatedTools,
|
|
9479
|
-
|
|
9480
|
-
...requirements.
|
|
9634
|
+
_metadata: {
|
|
9635
|
+
...requirements._metadata,
|
|
9481
9636
|
useImageGenerator: content || true,
|
|
9482
9637
|
},
|
|
9483
9638
|
}, spaceTrim$1(`
|
|
@@ -9768,8 +9923,8 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
9768
9923
|
return this.appendToSystemMessage({
|
|
9769
9924
|
...requirements,
|
|
9770
9925
|
tools: updatedTools,
|
|
9771
|
-
|
|
9772
|
-
...requirements.
|
|
9926
|
+
_metadata: {
|
|
9927
|
+
...requirements._metadata,
|
|
9773
9928
|
useSearchEngine: content || true,
|
|
9774
9929
|
},
|
|
9775
9930
|
}, spaceTrim$1((block) => `
|
|
@@ -9917,8 +10072,8 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
9917
10072
|
return this.appendToSystemMessage({
|
|
9918
10073
|
...requirements,
|
|
9919
10074
|
tools: updatedTools,
|
|
9920
|
-
|
|
9921
|
-
...requirements.
|
|
10075
|
+
_metadata: {
|
|
10076
|
+
...requirements._metadata,
|
|
9922
10077
|
},
|
|
9923
10078
|
}, spaceTrim$1((block) => `
|
|
9924
10079
|
Time and date context:
|
|
@@ -15648,11 +15803,14 @@ async function preparePersona(personaDescription, tools, options) {
|
|
|
15648
15803
|
function createEmptyAgentModelRequirements() {
|
|
15649
15804
|
return {
|
|
15650
15805
|
systemMessage: '',
|
|
15806
|
+
promptSuffix: '',
|
|
15651
15807
|
// modelName: 'gpt-5',
|
|
15652
15808
|
modelName: 'gemini-2.5-flash-lite',
|
|
15653
15809
|
temperature: 0.7,
|
|
15654
15810
|
topP: 0.9,
|
|
15655
15811
|
topK: 50,
|
|
15812
|
+
parentAgentUrl: null,
|
|
15813
|
+
isClosed: false,
|
|
15656
15814
|
};
|
|
15657
15815
|
}
|
|
15658
15816
|
/**
|
|
@@ -15798,14 +15956,42 @@ function removeCommentsFromSystemMessage(systemMessage) {
|
|
|
15798
15956
|
}
|
|
15799
15957
|
|
|
15800
15958
|
/**
|
|
15801
|
-
* Creates agent model requirements using the new commitment system
|
|
15959
|
+
* Creates agent model requirements using the new commitment system.
|
|
15960
|
+
*
|
|
15802
15961
|
* This function uses a reduce-like pattern where each commitment applies its changes
|
|
15803
|
-
* to build the final requirements starting from a basic empty model
|
|
15962
|
+
* to build the final requirements starting from a basic empty model.
|
|
15804
15963
|
*
|
|
15805
|
-
* @
|
|
15964
|
+
* @param agentSource - Agent source book to parse.
|
|
15965
|
+
* @param modelName - Optional override for the agent model name.
|
|
15966
|
+
* @param options - Additional options such as the agent reference resolver.
|
|
15967
|
+
*
|
|
15968
|
+
* @private @@@
|
|
15969
|
+
*/
|
|
15970
|
+
const COMMITMENTS_WITH_AGENT_REFERENCES = new Set(['FROM', 'IMPORT', 'IMPORTS', 'TEAM']);
|
|
15971
|
+
/**
|
|
15972
|
+
* Returns a safe fallback content when a resolver fails to transform a reference commitment.
|
|
15973
|
+
*
|
|
15974
|
+
* @param commitmentType - Commitment being resolved.
|
|
15975
|
+
* @param originalContent - Original unresolved commitment content.
|
|
15976
|
+
* @returns Fallback content that keeps requirement creation resilient.
|
|
15977
|
+
*/
|
|
15978
|
+
function getSafeReferenceCommitmentFallback(commitmentType, originalContent) {
|
|
15979
|
+
if (commitmentType === 'FROM') {
|
|
15980
|
+
return 'VOID';
|
|
15981
|
+
}
|
|
15982
|
+
if (commitmentType === 'IMPORT' || commitmentType === 'IMPORTS' || commitmentType === 'TEAM') {
|
|
15983
|
+
return '';
|
|
15984
|
+
}
|
|
15985
|
+
return originalContent;
|
|
15986
|
+
}
|
|
15987
|
+
/**
|
|
15988
|
+
* @@@
|
|
15989
|
+
*
|
|
15990
|
+
* @private @@@
|
|
15806
15991
|
*/
|
|
15807
|
-
async function createAgentModelRequirementsWithCommitments(agentSource, modelName) {
|
|
15992
|
+
async function createAgentModelRequirementsWithCommitments(agentSource, modelName, options) {
|
|
15808
15993
|
var _a;
|
|
15994
|
+
const agentReferenceResolver = options === null || options === void 0 ? void 0 : options.agentReferenceResolver;
|
|
15809
15995
|
// Parse the agent source to extract commitments
|
|
15810
15996
|
const parseResult = parseAgentSourceWithCommitments(agentSource);
|
|
15811
15997
|
// Apply DELETE filtering: remove prior commitments tagged by parameters targeted by DELETE/CANCEL/DISCARD/REMOVE
|
|
@@ -15842,8 +16028,8 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
15842
16028
|
// Store the agent name in metadata so commitments can access it
|
|
15843
16029
|
requirements = {
|
|
15844
16030
|
...requirements,
|
|
15845
|
-
|
|
15846
|
-
...requirements.
|
|
16031
|
+
_metadata: {
|
|
16032
|
+
...requirements._metadata,
|
|
15847
16033
|
agentName: parseResult.agentName,
|
|
15848
16034
|
},
|
|
15849
16035
|
};
|
|
@@ -15857,6 +16043,17 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
15857
16043
|
// Apply each commitment in order using reduce-like pattern
|
|
15858
16044
|
for (let i = 0; i < filteredCommitments.length; i++) {
|
|
15859
16045
|
const commitment = filteredCommitments[i];
|
|
16046
|
+
const isReferenceCommitment = Boolean(agentReferenceResolver && COMMITMENTS_WITH_AGENT_REFERENCES.has(commitment.type));
|
|
16047
|
+
let commitmentContent = commitment.content;
|
|
16048
|
+
if (isReferenceCommitment && agentReferenceResolver) {
|
|
16049
|
+
try {
|
|
16050
|
+
commitmentContent = await agentReferenceResolver.resolveCommitmentContent(commitment.type, commitment.content);
|
|
16051
|
+
}
|
|
16052
|
+
catch (error) {
|
|
16053
|
+
console.warn(`Failed to resolve commitment references for ${commitment.type}, falling back to safe defaults:`, error);
|
|
16054
|
+
commitmentContent = getSafeReferenceCommitmentFallback(commitment.type, commitment.content);
|
|
16055
|
+
}
|
|
16056
|
+
}
|
|
15860
16057
|
// CLOSED commitment should work only if its the last commitment in the book
|
|
15861
16058
|
if (commitment.type === 'CLOSED' && i !== filteredCommitments.length - 1) {
|
|
15862
16059
|
continue;
|
|
@@ -15864,7 +16061,7 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
15864
16061
|
const definition = getCommitmentDefinition(commitment.type);
|
|
15865
16062
|
if (definition) {
|
|
15866
16063
|
try {
|
|
15867
|
-
requirements = definition.applyToAgentModelRequirements(requirements,
|
|
16064
|
+
requirements = definition.applyToAgentModelRequirements(requirements, commitmentContent);
|
|
15868
16065
|
}
|
|
15869
16066
|
catch (error) {
|
|
15870
16067
|
console.warn(`Failed to apply commitment ${commitment.type}:`, error);
|
|
@@ -16012,23 +16209,28 @@ function isBinaryMimeType(mimeType) {
|
|
|
16012
16209
|
}
|
|
16013
16210
|
|
|
16014
16211
|
/**
|
|
16015
|
-
* Creates model requirements for an agent based on its source
|
|
16212
|
+
* Creates model requirements for an agent based on its source.
|
|
16016
16213
|
*
|
|
16017
16214
|
* There are 2 similar functions:
|
|
16018
16215
|
* - `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.
|
|
16019
16216
|
* - `createAgentModelRequirements` which is an asynchronous function that creates model requirements it applies each commitment one by one and works asynchronous.
|
|
16020
16217
|
*
|
|
16218
|
+
* @param agentSource - Book describing the agent.
|
|
16219
|
+
* @param modelName - Optional override for the agent's model.
|
|
16220
|
+
* @param availableModels - Models that could fulfill the agent.
|
|
16221
|
+
* @param llmTools - Execution tools used when selecting a best model.
|
|
16222
|
+
* @param options - Optional hooks such as the agent reference resolver.
|
|
16021
16223
|
* @public exported from `@promptbook/core`
|
|
16022
16224
|
*/
|
|
16023
|
-
async function createAgentModelRequirements(agentSource, modelName, availableModels, llmTools) {
|
|
16225
|
+
async function createAgentModelRequirements(agentSource, modelName, availableModels, llmTools, options) {
|
|
16024
16226
|
// If availableModels are provided and no specific modelName is given,
|
|
16025
16227
|
// use preparePersona to select the best model
|
|
16026
16228
|
if (availableModels && !modelName && llmTools) {
|
|
16027
16229
|
const selectedModelName = await selectBestModelUsingPersona(agentSource, llmTools);
|
|
16028
|
-
return createAgentModelRequirementsWithCommitments(agentSource, selectedModelName);
|
|
16230
|
+
return createAgentModelRequirementsWithCommitments(agentSource, selectedModelName, options);
|
|
16029
16231
|
}
|
|
16030
16232
|
// Use the new commitment-based system with provided or default model
|
|
16031
|
-
return createAgentModelRequirementsWithCommitments(agentSource, modelName);
|
|
16233
|
+
return createAgentModelRequirementsWithCommitments(agentSource, modelName, options);
|
|
16032
16234
|
}
|
|
16033
16235
|
/**
|
|
16034
16236
|
* Selects the best model using the preparePersona function
|
|
@@ -16326,6 +16528,66 @@ const OPENAI_MODELS = exportJson({
|
|
|
16326
16528
|
},
|
|
16327
16529
|
/**/
|
|
16328
16530
|
/**/
|
|
16531
|
+
{
|
|
16532
|
+
modelVariant: 'CHAT',
|
|
16533
|
+
modelTitle: 'gpt-5.2-codex',
|
|
16534
|
+
modelName: 'gpt-5.2-codex',
|
|
16535
|
+
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.',
|
|
16536
|
+
pricing: {
|
|
16537
|
+
prompt: pricing(`$1.75 / 1M tokens`),
|
|
16538
|
+
output: pricing(`$14.00 / 1M tokens`),
|
|
16539
|
+
},
|
|
16540
|
+
},
|
|
16541
|
+
/**/
|
|
16542
|
+
/**/
|
|
16543
|
+
{
|
|
16544
|
+
modelVariant: 'CHAT',
|
|
16545
|
+
modelTitle: 'gpt-5.1-codex-max',
|
|
16546
|
+
modelName: 'gpt-5.1-codex-max',
|
|
16547
|
+
modelDescription: 'Premium GPT-5.1 Codex flavor that mirrors gpt-5.1 in capability and pricing while adding Codex tooling optimizations.',
|
|
16548
|
+
pricing: {
|
|
16549
|
+
prompt: pricing(`$1.25 / 1M tokens`),
|
|
16550
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
16551
|
+
},
|
|
16552
|
+
},
|
|
16553
|
+
/**/
|
|
16554
|
+
/**/
|
|
16555
|
+
{
|
|
16556
|
+
modelVariant: 'CHAT',
|
|
16557
|
+
modelTitle: 'gpt-5.1-codex',
|
|
16558
|
+
modelName: 'gpt-5.1-codex',
|
|
16559
|
+
modelDescription: 'Core GPT-5.1 Codex model focused on agentic coding tasks with a balanced trade-off between reasoning and cost.',
|
|
16560
|
+
pricing: {
|
|
16561
|
+
prompt: pricing(`$1.25 / 1M tokens`),
|
|
16562
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
16563
|
+
},
|
|
16564
|
+
},
|
|
16565
|
+
/**/
|
|
16566
|
+
/**/
|
|
16567
|
+
{
|
|
16568
|
+
modelVariant: 'CHAT',
|
|
16569
|
+
modelTitle: 'gpt-5.1-codex-mini',
|
|
16570
|
+
modelName: 'gpt-5.1-codex-mini',
|
|
16571
|
+
modelDescription: 'Compact, cost-effective GPT-5.1 Codex variant with a smaller context window ideal for cheap assistant iterations that still require coding awareness.',
|
|
16572
|
+
pricing: {
|
|
16573
|
+
prompt: pricing(`$0.25 / 1M tokens`),
|
|
16574
|
+
output: pricing(`$2.00 / 1M tokens`),
|
|
16575
|
+
},
|
|
16576
|
+
},
|
|
16577
|
+
/**/
|
|
16578
|
+
/**/
|
|
16579
|
+
{
|
|
16580
|
+
modelVariant: 'CHAT',
|
|
16581
|
+
modelTitle: 'gpt-5-codex',
|
|
16582
|
+
modelName: 'gpt-5-codex',
|
|
16583
|
+
modelDescription: 'Legacy GPT-5 Codex model built for agentic coding workloads with the same pricing as GPT-5 and a focus on stability.',
|
|
16584
|
+
pricing: {
|
|
16585
|
+
prompt: pricing(`$1.25 / 1M tokens`),
|
|
16586
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
16587
|
+
},
|
|
16588
|
+
},
|
|
16589
|
+
/**/
|
|
16590
|
+
/**/
|
|
16329
16591
|
{
|
|
16330
16592
|
modelVariant: 'CHAT',
|
|
16331
16593
|
modelTitle: 'gpt-5-mini',
|
|
@@ -17030,6 +17292,32 @@ function isUnsupportedParameterError(error) {
|
|
|
17030
17292
|
errorMessage.includes('does not support'));
|
|
17031
17293
|
}
|
|
17032
17294
|
|
|
17295
|
+
/**
|
|
17296
|
+
* Provides access to the structured clone implementation when available.
|
|
17297
|
+
*/
|
|
17298
|
+
function getStructuredCloneFunction() {
|
|
17299
|
+
return globalThis.structuredClone;
|
|
17300
|
+
}
|
|
17301
|
+
/**
|
|
17302
|
+
* Checks whether the prompt is a chat prompt that carries file attachments.
|
|
17303
|
+
*/
|
|
17304
|
+
function hasChatPromptFiles(prompt) {
|
|
17305
|
+
return 'files' in prompt && Array.isArray(prompt.files);
|
|
17306
|
+
}
|
|
17307
|
+
/**
|
|
17308
|
+
* Creates a deep copy of the prompt while keeping attached files intact when structured clone is not available.
|
|
17309
|
+
*/
|
|
17310
|
+
function clonePromptPreservingFiles(prompt) {
|
|
17311
|
+
const structuredCloneFn = getStructuredCloneFunction();
|
|
17312
|
+
if (typeof structuredCloneFn === 'function') {
|
|
17313
|
+
return structuredCloneFn(prompt);
|
|
17314
|
+
}
|
|
17315
|
+
const clonedPrompt = JSON.parse(JSON.stringify(prompt));
|
|
17316
|
+
if (hasChatPromptFiles(prompt)) {
|
|
17317
|
+
clonedPrompt.files = prompt.files;
|
|
17318
|
+
}
|
|
17319
|
+
return clonedPrompt;
|
|
17320
|
+
}
|
|
17033
17321
|
/**
|
|
17034
17322
|
* Execution Tools for calling OpenAI API or other OpenAI compatible provider
|
|
17035
17323
|
*
|
|
@@ -17114,7 +17402,7 @@ class OpenAiCompatibleExecutionTools {
|
|
|
17114
17402
|
*/
|
|
17115
17403
|
async callChatModelStream(prompt, onProgress) {
|
|
17116
17404
|
// Deep clone prompt and modelRequirements to avoid mutation across calls
|
|
17117
|
-
const clonedPrompt =
|
|
17405
|
+
const clonedPrompt = clonePromptPreservingFiles(prompt);
|
|
17118
17406
|
// Use local Set for retried parameters to ensure independence and thread safety
|
|
17119
17407
|
const retriedUnsupportedParameters = new Set();
|
|
17120
17408
|
return this.callChatModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters, onProgress);
|
|
@@ -17141,7 +17429,10 @@ class OpenAiCompatibleExecutionTools {
|
|
|
17141
17429
|
// <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
|
|
17142
17430
|
// <- Note: [🧆]
|
|
17143
17431
|
}; // <- TODO: [💩] Guard here types better
|
|
17144
|
-
if (
|
|
17432
|
+
if (currentModelRequirements.responseFormat !== undefined) {
|
|
17433
|
+
modelSettings.response_format = currentModelRequirements.responseFormat;
|
|
17434
|
+
}
|
|
17435
|
+
else if (format === 'JSON') {
|
|
17145
17436
|
modelSettings.response_format = {
|
|
17146
17437
|
type: 'json_object',
|
|
17147
17438
|
};
|
|
@@ -18622,7 +18913,9 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
|
|
|
18622
18913
|
const processingStartedAtMs = Date.now();
|
|
18623
18914
|
for (const [index, source] of knowledgeSources.entries()) {
|
|
18624
18915
|
try {
|
|
18625
|
-
const
|
|
18916
|
+
const isDataUrl = isDataUrlKnowledgeSource(source);
|
|
18917
|
+
const isHttp = source.startsWith('http://') || source.startsWith('https://');
|
|
18918
|
+
const sourceType = isDataUrl ? 'data_url' : isHttp ? 'url' : 'file';
|
|
18626
18919
|
if (this.options.isVerbose) {
|
|
18627
18920
|
console.info('[🤰]', 'Processing knowledge source', {
|
|
18628
18921
|
index: index + 1,
|
|
@@ -18632,8 +18925,27 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
|
|
|
18632
18925
|
logLabel,
|
|
18633
18926
|
});
|
|
18634
18927
|
}
|
|
18635
|
-
|
|
18636
|
-
|
|
18928
|
+
if (isDataUrl) {
|
|
18929
|
+
const parsed = parseDataUrlKnowledgeSource(source);
|
|
18930
|
+
if (!parsed) {
|
|
18931
|
+
skippedSources.push({ source, reason: 'invalid_data_url' });
|
|
18932
|
+
if (this.options.isVerbose) {
|
|
18933
|
+
console.info('[🤰]', 'Skipping knowledge source (invalid data URL)', {
|
|
18934
|
+
source,
|
|
18935
|
+
sourceType,
|
|
18936
|
+
logLabel,
|
|
18937
|
+
});
|
|
18938
|
+
}
|
|
18939
|
+
continue;
|
|
18940
|
+
}
|
|
18941
|
+
const dataUrlFile = new File([parsed.buffer], parsed.filename, {
|
|
18942
|
+
type: parsed.mimeType,
|
|
18943
|
+
});
|
|
18944
|
+
fileStreams.push(dataUrlFile);
|
|
18945
|
+
totalBytes += parsed.buffer.length;
|
|
18946
|
+
continue;
|
|
18947
|
+
}
|
|
18948
|
+
if (isHttp) {
|
|
18637
18949
|
const downloadResult = await this.downloadKnowledgeSourceFile({
|
|
18638
18950
|
source,
|
|
18639
18951
|
timeoutMs: downloadTimeoutMs,
|
|
@@ -18735,6 +19047,64 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
|
|
|
18735
19047
|
}
|
|
18736
19048
|
|
|
18737
19049
|
const DEFAULT_AGENT_KIT_MODEL_NAME = 'gpt-5.2';
|
|
19050
|
+
const DEFAULT_JSON_SCHEMA_NAME = 'StructuredOutput';
|
|
19051
|
+
/*
|
|
19052
|
+
TODO: Use or remove
|
|
19053
|
+
const EMPTY_JSON_SCHEMA: JsonSchemaDefinition['schema'] = {
|
|
19054
|
+
type: 'object',
|
|
19055
|
+
properties: {},
|
|
19056
|
+
required: [],
|
|
19057
|
+
additionalProperties: true,
|
|
19058
|
+
};
|
|
19059
|
+
*/
|
|
19060
|
+
function buildJsonSchemaDefinition(jsonSchema) {
|
|
19061
|
+
var _a, _b, _c;
|
|
19062
|
+
const schema = (_a = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.schema) !== null && _a !== void 0 ? _a : {};
|
|
19063
|
+
return {
|
|
19064
|
+
type: 'json_schema',
|
|
19065
|
+
name: (_b = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.name) !== null && _b !== void 0 ? _b : DEFAULT_JSON_SCHEMA_NAME,
|
|
19066
|
+
strict: Boolean(jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.strict),
|
|
19067
|
+
schema: {
|
|
19068
|
+
type: 'object',
|
|
19069
|
+
properties: ((_c = schema.properties) !== null && _c !== void 0 ? _c : {}),
|
|
19070
|
+
required: Array.isArray(schema.required) ? schema.required : [],
|
|
19071
|
+
additionalProperties: schema.additionalProperties === undefined ? true : Boolean(schema.additionalProperties),
|
|
19072
|
+
description: schema.description,
|
|
19073
|
+
},
|
|
19074
|
+
};
|
|
19075
|
+
}
|
|
19076
|
+
/**
|
|
19077
|
+
* Maps OpenAI `response_format` payloads to AgentKit output types so the runner can forward
|
|
19078
|
+
* structured-output preferences to OpenAI while still reusing the same AgentKit agent instance.
|
|
19079
|
+
*
|
|
19080
|
+
* @param responseFormat - The OpenAI `response_format` payload from the user request.
|
|
19081
|
+
* @returns An Agent output type compatible with the requested schema or `undefined` when no impact is required.
|
|
19082
|
+
* @private utility of Open AI
|
|
19083
|
+
*/
|
|
19084
|
+
function mapResponseFormatToAgentOutputType(responseFormat) {
|
|
19085
|
+
if (!responseFormat) {
|
|
19086
|
+
return undefined;
|
|
19087
|
+
}
|
|
19088
|
+
if (typeof responseFormat === 'string') {
|
|
19089
|
+
if (responseFormat === 'text') {
|
|
19090
|
+
return 'text';
|
|
19091
|
+
}
|
|
19092
|
+
if (responseFormat === 'json_schema' || responseFormat === 'json_object') {
|
|
19093
|
+
return buildJsonSchemaDefinition();
|
|
19094
|
+
}
|
|
19095
|
+
return 'text';
|
|
19096
|
+
}
|
|
19097
|
+
switch (responseFormat.type) {
|
|
19098
|
+
case 'text':
|
|
19099
|
+
return 'text';
|
|
19100
|
+
case 'json_schema':
|
|
19101
|
+
return buildJsonSchemaDefinition(responseFormat.json_schema);
|
|
19102
|
+
case 'json_object':
|
|
19103
|
+
return buildJsonSchemaDefinition();
|
|
19104
|
+
default:
|
|
19105
|
+
return undefined;
|
|
19106
|
+
}
|
|
19107
|
+
}
|
|
18738
19108
|
/**
|
|
18739
19109
|
* Execution tools for OpenAI AgentKit (Agents SDK).
|
|
18740
19110
|
*
|
|
@@ -18782,6 +19152,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
18782
19152
|
...parameters,
|
|
18783
19153
|
modelName: this.agentKitModelName,
|
|
18784
19154
|
});
|
|
19155
|
+
const responseFormatOutputType = mapResponseFormatToAgentOutputType(modelRequirements.responseFormat);
|
|
18785
19156
|
const preparedAgentKitAgent = await this.prepareAgentKitAgent({
|
|
18786
19157
|
name: (prompt.title || 'Agent'),
|
|
18787
19158
|
instructions: modelRequirements.systemMessage || '',
|
|
@@ -18793,6 +19164,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
18793
19164
|
prompt,
|
|
18794
19165
|
rawPromptContent,
|
|
18795
19166
|
onProgress,
|
|
19167
|
+
responseFormatOutputType,
|
|
18796
19168
|
});
|
|
18797
19169
|
}
|
|
18798
19170
|
/**
|
|
@@ -18974,16 +19346,21 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
18974
19346
|
...prompt.parameters,
|
|
18975
19347
|
modelName: this.agentKitModelName,
|
|
18976
19348
|
});
|
|
19349
|
+
const agentForRun = options.responseFormatOutputType !== undefined
|
|
19350
|
+
? openAiAgentKitAgent.clone({
|
|
19351
|
+
outputType: options.responseFormatOutputType,
|
|
19352
|
+
})
|
|
19353
|
+
: openAiAgentKitAgent;
|
|
18977
19354
|
const start = $getCurrentDate();
|
|
18978
19355
|
let latestContent = '';
|
|
18979
19356
|
const toolCalls = [];
|
|
18980
19357
|
const toolCallIndexById = new Map();
|
|
18981
19358
|
const inputItems = await this.buildAgentKitInputItems(prompt, rawPromptContent);
|
|
18982
19359
|
const rawRequest = {
|
|
18983
|
-
agentName:
|
|
19360
|
+
agentName: agentForRun.name,
|
|
18984
19361
|
input: inputItems,
|
|
18985
19362
|
};
|
|
18986
|
-
const streamResult = await run(
|
|
19363
|
+
const streamResult = await run(agentForRun, inputItems, {
|
|
18987
19364
|
stream: true,
|
|
18988
19365
|
context: { parameters: prompt.parameters },
|
|
18989
19366
|
});
|
|
@@ -19972,22 +20349,28 @@ class AgentLlmExecutionTools {
|
|
|
19972
20349
|
throw new Error('AgentLlmExecutionTools only supports chat prompts');
|
|
19973
20350
|
}
|
|
19974
20351
|
const modelRequirements = await this.getModelRequirements();
|
|
20352
|
+
const { _metadata, promptSuffix, ...sanitizedRequirements } = modelRequirements;
|
|
19975
20353
|
const chatPrompt = prompt;
|
|
19976
20354
|
let underlyingLlmResult;
|
|
19977
|
-
|
|
20355
|
+
const chatPromptContentWithSuffix = promptSuffix
|
|
20356
|
+
? `${chatPrompt.content}\n\n${promptSuffix}`
|
|
20357
|
+
: chatPrompt.content;
|
|
19978
20358
|
const promptWithAgentModelRequirements = {
|
|
19979
20359
|
...chatPrompt,
|
|
20360
|
+
content: chatPromptContentWithSuffix,
|
|
19980
20361
|
modelRequirements: {
|
|
19981
20362
|
...chatPrompt.modelRequirements,
|
|
19982
|
-
...
|
|
20363
|
+
...sanitizedRequirements,
|
|
19983
20364
|
// Spread tools to convert readonly array to mutable
|
|
19984
|
-
tools:
|
|
20365
|
+
tools: sanitizedRequirements.tools
|
|
20366
|
+
? [...sanitizedRequirements.tools]
|
|
20367
|
+
: chatPrompt.modelRequirements.tools,
|
|
19985
20368
|
// Spread knowledgeSources to convert readonly array to mutable
|
|
19986
|
-
knowledgeSources:
|
|
19987
|
-
? [...
|
|
20369
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources
|
|
20370
|
+
? [...sanitizedRequirements.knowledgeSources]
|
|
19988
20371
|
: undefined,
|
|
19989
20372
|
// Prepend agent system message to existing system message
|
|
19990
|
-
systemMessage:
|
|
20373
|
+
systemMessage: sanitizedRequirements.systemMessage +
|
|
19991
20374
|
(chatPrompt.modelRequirements.systemMessage
|
|
19992
20375
|
? `\n\n${chatPrompt.modelRequirements.systemMessage}`
|
|
19993
20376
|
: ''),
|
|
@@ -19995,8 +20378,8 @@ class AgentLlmExecutionTools {
|
|
|
19995
20378
|
};
|
|
19996
20379
|
console.log('!!!! promptWithAgentModelRequirements:', promptWithAgentModelRequirements);
|
|
19997
20380
|
if (OpenAiAgentKitExecutionTools.isOpenAiAgentKitExecutionTools(this.options.llmTools)) {
|
|
19998
|
-
const requirementsHash = SHA256(JSON.stringify(
|
|
19999
|
-
const vectorStoreHash = SHA256(JSON.stringify((_a =
|
|
20381
|
+
const requirementsHash = SHA256(JSON.stringify(sanitizedRequirements)).toString();
|
|
20382
|
+
const vectorStoreHash = SHA256(JSON.stringify((_a = sanitizedRequirements.knowledgeSources) !== null && _a !== void 0 ? _a : [])).toString();
|
|
20000
20383
|
const cachedVectorStore = AgentLlmExecutionTools.vectorStoreCache.get(this.title);
|
|
20001
20384
|
const cachedAgentKit = AgentLlmExecutionTools.agentKitAgentCache.get(this.title);
|
|
20002
20385
|
let preparedAgentKit = this.options.assistantPreparationMode === 'external'
|
|
@@ -20023,7 +20406,7 @@ class AgentLlmExecutionTools {
|
|
|
20023
20406
|
agent: this.title,
|
|
20024
20407
|
});
|
|
20025
20408
|
}
|
|
20026
|
-
if (!vectorStoreId && ((_b =
|
|
20409
|
+
if (!vectorStoreId && ((_b = sanitizedRequirements.knowledgeSources) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
20027
20410
|
emitAssistantPreparationProgress({
|
|
20028
20411
|
onProgress,
|
|
20029
20412
|
prompt,
|
|
@@ -20039,9 +20422,9 @@ class AgentLlmExecutionTools {
|
|
|
20039
20422
|
});
|
|
20040
20423
|
preparedAgentKit = await this.options.llmTools.prepareAgentKitAgent({
|
|
20041
20424
|
name: this.title,
|
|
20042
|
-
instructions:
|
|
20043
|
-
knowledgeSources:
|
|
20044
|
-
tools:
|
|
20425
|
+
instructions: sanitizedRequirements.systemMessage || '',
|
|
20426
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources,
|
|
20427
|
+
tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
|
|
20045
20428
|
vectorStoreId,
|
|
20046
20429
|
});
|
|
20047
20430
|
}
|
|
@@ -20056,15 +20439,17 @@ class AgentLlmExecutionTools {
|
|
|
20056
20439
|
requirementsHash,
|
|
20057
20440
|
vectorStoreId: preparedAgentKit.vectorStoreId,
|
|
20058
20441
|
});
|
|
20442
|
+
const responseFormatOutputType = mapResponseFormatToAgentOutputType(promptWithAgentModelRequirements.modelRequirements.responseFormat);
|
|
20059
20443
|
underlyingLlmResult = await this.options.llmTools.callChatModelStreamWithPreparedAgent({
|
|
20060
20444
|
openAiAgentKitAgent: preparedAgentKit.agent,
|
|
20061
20445
|
prompt: promptWithAgentModelRequirements,
|
|
20062
20446
|
onProgress,
|
|
20447
|
+
responseFormatOutputType,
|
|
20063
20448
|
});
|
|
20064
20449
|
}
|
|
20065
20450
|
else if (OpenAiAssistantExecutionTools.isOpenAiAssistantExecutionTools(this.options.llmTools)) {
|
|
20066
20451
|
// ... deprecated path ...
|
|
20067
|
-
const requirementsHash = SHA256(JSON.stringify(
|
|
20452
|
+
const requirementsHash = SHA256(JSON.stringify(sanitizedRequirements)).toString();
|
|
20068
20453
|
const cached = AgentLlmExecutionTools.assistantCache.get(this.title);
|
|
20069
20454
|
let assistant;
|
|
20070
20455
|
if (this.options.assistantPreparationMode === 'external') {
|
|
@@ -20106,9 +20491,9 @@ class AgentLlmExecutionTools {
|
|
|
20106
20491
|
assistant = await this.options.llmTools.updateAssistant({
|
|
20107
20492
|
assistantId: cached.assistantId,
|
|
20108
20493
|
name: this.title,
|
|
20109
|
-
instructions:
|
|
20110
|
-
knowledgeSources:
|
|
20111
|
-
tools:
|
|
20494
|
+
instructions: sanitizedRequirements.systemMessage,
|
|
20495
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources,
|
|
20496
|
+
tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
|
|
20112
20497
|
});
|
|
20113
20498
|
AgentLlmExecutionTools.assistantCache.set(this.title, {
|
|
20114
20499
|
assistantId: assistant.assistantId,
|
|
@@ -20131,9 +20516,9 @@ class AgentLlmExecutionTools {
|
|
|
20131
20516
|
});
|
|
20132
20517
|
assistant = await this.options.llmTools.createNewAssistant({
|
|
20133
20518
|
name: this.title,
|
|
20134
|
-
instructions:
|
|
20135
|
-
knowledgeSources:
|
|
20136
|
-
tools:
|
|
20519
|
+
instructions: sanitizedRequirements.systemMessage,
|
|
20520
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources,
|
|
20521
|
+
tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
|
|
20137
20522
|
/*
|
|
20138
20523
|
!!!
|
|
20139
20524
|
metadata: {
|
|
@@ -20175,13 +20560,19 @@ class AgentLlmExecutionTools {
|
|
|
20175
20560
|
}
|
|
20176
20561
|
}
|
|
20177
20562
|
let content = underlyingLlmResult.content;
|
|
20178
|
-
|
|
20179
|
-
|
|
20180
|
-
|
|
20181
|
-
|
|
20563
|
+
if (typeof content === 'string') {
|
|
20564
|
+
// Note: Cleanup the AI artifacts from the content
|
|
20565
|
+
content = humanizeAiText(content);
|
|
20566
|
+
// Note: Make sure the content is Promptbook-like
|
|
20567
|
+
content = promptbookifyAiText(content);
|
|
20568
|
+
}
|
|
20569
|
+
else {
|
|
20570
|
+
// TODO: Maybe deep `humanizeAiText` + `promptbookifyAiText` inside of the object
|
|
20571
|
+
content = JSON.stringify(content);
|
|
20572
|
+
}
|
|
20182
20573
|
const agentResult = {
|
|
20183
20574
|
...underlyingLlmResult,
|
|
20184
|
-
content,
|
|
20575
|
+
content: content,
|
|
20185
20576
|
modelName: this.modelName,
|
|
20186
20577
|
};
|
|
20187
20578
|
return agentResult;
|
|
@@ -20370,7 +20761,6 @@ class Agent extends AgentLlmExecutionTools {
|
|
|
20370
20761
|
* Note: This method also implements the learning mechanism
|
|
20371
20762
|
*/
|
|
20372
20763
|
async callChatModelStream(prompt, onProgress) {
|
|
20373
|
-
var _a;
|
|
20374
20764
|
// [1] Check if the user is asking the same thing as in the samples
|
|
20375
20765
|
const modelRequirements = await this.getModelRequirements();
|
|
20376
20766
|
if (modelRequirements.samples) {
|
|
@@ -20418,7 +20808,7 @@ class Agent extends AgentLlmExecutionTools {
|
|
|
20418
20808
|
if (result.rawResponse && 'sample' in result.rawResponse) {
|
|
20419
20809
|
return result;
|
|
20420
20810
|
}
|
|
20421
|
-
if (
|
|
20811
|
+
if (modelRequirements.isClosed) {
|
|
20422
20812
|
return result;
|
|
20423
20813
|
}
|
|
20424
20814
|
// Note: [0] Notify start of self-learning
|