@promptbook/wizard 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
|
@@ -38,7 +38,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
38
38
|
* @generated
|
|
39
39
|
* @see https://github.com/webgptorg/promptbook
|
|
40
40
|
*/
|
|
41
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.110.0
|
|
41
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.110.0';
|
|
42
42
|
/**
|
|
43
43
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
44
44
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -3776,6 +3776,66 @@ const OPENAI_MODELS = exportJson({
|
|
|
3776
3776
|
},
|
|
3777
3777
|
/**/
|
|
3778
3778
|
/**/
|
|
3779
|
+
{
|
|
3780
|
+
modelVariant: 'CHAT',
|
|
3781
|
+
modelTitle: 'gpt-5.2-codex',
|
|
3782
|
+
modelName: 'gpt-5.2-codex',
|
|
3783
|
+
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.',
|
|
3784
|
+
pricing: {
|
|
3785
|
+
prompt: pricing(`$1.75 / 1M tokens`),
|
|
3786
|
+
output: pricing(`$14.00 / 1M tokens`),
|
|
3787
|
+
},
|
|
3788
|
+
},
|
|
3789
|
+
/**/
|
|
3790
|
+
/**/
|
|
3791
|
+
{
|
|
3792
|
+
modelVariant: 'CHAT',
|
|
3793
|
+
modelTitle: 'gpt-5.1-codex-max',
|
|
3794
|
+
modelName: 'gpt-5.1-codex-max',
|
|
3795
|
+
modelDescription: 'Premium GPT-5.1 Codex flavor that mirrors gpt-5.1 in capability and pricing while adding Codex tooling optimizations.',
|
|
3796
|
+
pricing: {
|
|
3797
|
+
prompt: pricing(`$1.25 / 1M tokens`),
|
|
3798
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
3799
|
+
},
|
|
3800
|
+
},
|
|
3801
|
+
/**/
|
|
3802
|
+
/**/
|
|
3803
|
+
{
|
|
3804
|
+
modelVariant: 'CHAT',
|
|
3805
|
+
modelTitle: 'gpt-5.1-codex',
|
|
3806
|
+
modelName: 'gpt-5.1-codex',
|
|
3807
|
+
modelDescription: 'Core GPT-5.1 Codex model focused on agentic coding tasks with a balanced trade-off between reasoning and cost.',
|
|
3808
|
+
pricing: {
|
|
3809
|
+
prompt: pricing(`$1.25 / 1M tokens`),
|
|
3810
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
3811
|
+
},
|
|
3812
|
+
},
|
|
3813
|
+
/**/
|
|
3814
|
+
/**/
|
|
3815
|
+
{
|
|
3816
|
+
modelVariant: 'CHAT',
|
|
3817
|
+
modelTitle: 'gpt-5.1-codex-mini',
|
|
3818
|
+
modelName: 'gpt-5.1-codex-mini',
|
|
3819
|
+
modelDescription: 'Compact, cost-effective GPT-5.1 Codex variant with a smaller context window ideal for cheap assistant iterations that still require coding awareness.',
|
|
3820
|
+
pricing: {
|
|
3821
|
+
prompt: pricing(`$0.25 / 1M tokens`),
|
|
3822
|
+
output: pricing(`$2.00 / 1M tokens`),
|
|
3823
|
+
},
|
|
3824
|
+
},
|
|
3825
|
+
/**/
|
|
3826
|
+
/**/
|
|
3827
|
+
{
|
|
3828
|
+
modelVariant: 'CHAT',
|
|
3829
|
+
modelTitle: 'gpt-5-codex',
|
|
3830
|
+
modelName: 'gpt-5-codex',
|
|
3831
|
+
modelDescription: 'Legacy GPT-5 Codex model built for agentic coding workloads with the same pricing as GPT-5 and a focus on stability.',
|
|
3832
|
+
pricing: {
|
|
3833
|
+
prompt: pricing(`$1.25 / 1M tokens`),
|
|
3834
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
3835
|
+
},
|
|
3836
|
+
},
|
|
3837
|
+
/**/
|
|
3838
|
+
/**/
|
|
3779
3839
|
{
|
|
3780
3840
|
modelVariant: 'CHAT',
|
|
3781
3841
|
modelTitle: 'gpt-5-mini',
|
|
@@ -8671,6 +8731,32 @@ function isUnsupportedParameterError(error) {
|
|
|
8671
8731
|
errorMessage.includes('does not support'));
|
|
8672
8732
|
}
|
|
8673
8733
|
|
|
8734
|
+
/**
|
|
8735
|
+
* Provides access to the structured clone implementation when available.
|
|
8736
|
+
*/
|
|
8737
|
+
function getStructuredCloneFunction() {
|
|
8738
|
+
return globalThis.structuredClone;
|
|
8739
|
+
}
|
|
8740
|
+
/**
|
|
8741
|
+
* Checks whether the prompt is a chat prompt that carries file attachments.
|
|
8742
|
+
*/
|
|
8743
|
+
function hasChatPromptFiles(prompt) {
|
|
8744
|
+
return 'files' in prompt && Array.isArray(prompt.files);
|
|
8745
|
+
}
|
|
8746
|
+
/**
|
|
8747
|
+
* Creates a deep copy of the prompt while keeping attached files intact when structured clone is not available.
|
|
8748
|
+
*/
|
|
8749
|
+
function clonePromptPreservingFiles(prompt) {
|
|
8750
|
+
const structuredCloneFn = getStructuredCloneFunction();
|
|
8751
|
+
if (typeof structuredCloneFn === 'function') {
|
|
8752
|
+
return structuredCloneFn(prompt);
|
|
8753
|
+
}
|
|
8754
|
+
const clonedPrompt = JSON.parse(JSON.stringify(prompt));
|
|
8755
|
+
if (hasChatPromptFiles(prompt)) {
|
|
8756
|
+
clonedPrompt.files = prompt.files;
|
|
8757
|
+
}
|
|
8758
|
+
return clonedPrompt;
|
|
8759
|
+
}
|
|
8674
8760
|
/**
|
|
8675
8761
|
* Execution Tools for calling OpenAI API or other OpenAI compatible provider
|
|
8676
8762
|
*
|
|
@@ -8755,7 +8841,7 @@ class OpenAiCompatibleExecutionTools {
|
|
|
8755
8841
|
*/
|
|
8756
8842
|
async callChatModelStream(prompt, onProgress) {
|
|
8757
8843
|
// Deep clone prompt and modelRequirements to avoid mutation across calls
|
|
8758
|
-
const clonedPrompt =
|
|
8844
|
+
const clonedPrompt = clonePromptPreservingFiles(prompt);
|
|
8759
8845
|
// Use local Set for retried parameters to ensure independence and thread safety
|
|
8760
8846
|
const retriedUnsupportedParameters = new Set();
|
|
8761
8847
|
return this.callChatModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters, onProgress);
|
|
@@ -8782,7 +8868,10 @@ class OpenAiCompatibleExecutionTools {
|
|
|
8782
8868
|
// <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
|
|
8783
8869
|
// <- Note: [🧆]
|
|
8784
8870
|
}; // <- TODO: [💩] Guard here types better
|
|
8785
|
-
if (
|
|
8871
|
+
if (currentModelRequirements.responseFormat !== undefined) {
|
|
8872
|
+
modelSettings.response_format = currentModelRequirements.responseFormat;
|
|
8873
|
+
}
|
|
8874
|
+
else if (format === 'JSON') {
|
|
8786
8875
|
modelSettings.response_format = {
|
|
8787
8876
|
type: 'json_object',
|
|
8788
8877
|
};
|
|
@@ -10124,6 +10213,136 @@ class OpenAiExecutionTools extends OpenAiCompatibleExecutionTools {
|
|
|
10124
10213
|
}
|
|
10125
10214
|
}
|
|
10126
10215
|
|
|
10216
|
+
/**
|
|
10217
|
+
* @@@
|
|
10218
|
+
*
|
|
10219
|
+
* @private thing of inline knowledge
|
|
10220
|
+
*/
|
|
10221
|
+
const INLINE_KNOWLEDGE_BASE_NAME = 'inline-knowledge';
|
|
10222
|
+
/**
|
|
10223
|
+
* @@@
|
|
10224
|
+
*
|
|
10225
|
+
* @private thing of inline knowledge
|
|
10226
|
+
*/
|
|
10227
|
+
const INLINE_KNOWLEDGE_EXTENSION = '.txt';
|
|
10228
|
+
/**
|
|
10229
|
+
* @@@
|
|
10230
|
+
*
|
|
10231
|
+
* @private thing of inline knowledge
|
|
10232
|
+
*/
|
|
10233
|
+
const DATA_URL_PREFIX = 'data:';
|
|
10234
|
+
/**
|
|
10235
|
+
* @@@
|
|
10236
|
+
*
|
|
10237
|
+
* @private thing of inline knowledge
|
|
10238
|
+
*/
|
|
10239
|
+
function getFirstNonEmptyLine(content) {
|
|
10240
|
+
const lines = content.split(/\r?\n/);
|
|
10241
|
+
for (const line of lines) {
|
|
10242
|
+
const trimmed = line.trim();
|
|
10243
|
+
if (trimmed) {
|
|
10244
|
+
return trimmed;
|
|
10245
|
+
}
|
|
10246
|
+
}
|
|
10247
|
+
return null;
|
|
10248
|
+
}
|
|
10249
|
+
/**
|
|
10250
|
+
* @@@
|
|
10251
|
+
*
|
|
10252
|
+
* @private thing of inline knowledge
|
|
10253
|
+
*/
|
|
10254
|
+
function deriveBaseFilename(content) {
|
|
10255
|
+
const firstLine = getFirstNonEmptyLine(content);
|
|
10256
|
+
if (!firstLine) {
|
|
10257
|
+
return INLINE_KNOWLEDGE_BASE_NAME;
|
|
10258
|
+
}
|
|
10259
|
+
const normalized = normalizeToKebabCase(firstLine);
|
|
10260
|
+
return normalized || INLINE_KNOWLEDGE_BASE_NAME;
|
|
10261
|
+
}
|
|
10262
|
+
/**
|
|
10263
|
+
* Creates a data URL that represents the inline knowledge content as a text file.
|
|
10264
|
+
*
|
|
10265
|
+
* @private thing of inline knowledge
|
|
10266
|
+
*/
|
|
10267
|
+
function createInlineKnowledgeSourceFile(content) {
|
|
10268
|
+
const trimmedContent = content.trim();
|
|
10269
|
+
const baseName = deriveBaseFilename(trimmedContent);
|
|
10270
|
+
const filename = `${baseName}${INLINE_KNOWLEDGE_EXTENSION}`;
|
|
10271
|
+
const mimeType = 'text/plain';
|
|
10272
|
+
const base64 = Buffer.from(trimmedContent, 'utf-8').toString('base64');
|
|
10273
|
+
const encodedFilename = encodeURIComponent(filename);
|
|
10274
|
+
const url = `${DATA_URL_PREFIX}${mimeType};name=${encodedFilename};charset=utf-8;base64,${base64}`;
|
|
10275
|
+
return {
|
|
10276
|
+
filename,
|
|
10277
|
+
mimeType,
|
|
10278
|
+
url,
|
|
10279
|
+
};
|
|
10280
|
+
}
|
|
10281
|
+
/**
|
|
10282
|
+
* Checks whether the provided source string is a data URL that can be decoded.
|
|
10283
|
+
*
|
|
10284
|
+
* @private thing of inline knowledge
|
|
10285
|
+
*/
|
|
10286
|
+
function isDataUrlKnowledgeSource(source) {
|
|
10287
|
+
return typeof source === 'string' && source.startsWith(DATA_URL_PREFIX);
|
|
10288
|
+
}
|
|
10289
|
+
/**
|
|
10290
|
+
* Parses a data URL-based knowledge source into its raw buffer, filename, and MIME type.
|
|
10291
|
+
*
|
|
10292
|
+
* @private thing of inline knowledge
|
|
10293
|
+
*/
|
|
10294
|
+
function parseDataUrlKnowledgeSource(source) {
|
|
10295
|
+
if (!isDataUrlKnowledgeSource(source)) {
|
|
10296
|
+
return null;
|
|
10297
|
+
}
|
|
10298
|
+
const commaIndex = source.indexOf(',');
|
|
10299
|
+
if (commaIndex === -1) {
|
|
10300
|
+
return null;
|
|
10301
|
+
}
|
|
10302
|
+
const header = source.slice(DATA_URL_PREFIX.length, commaIndex);
|
|
10303
|
+
const payload = source.slice(commaIndex + 1);
|
|
10304
|
+
const tokens = header.split(';');
|
|
10305
|
+
const mediaType = tokens[0] || 'text/plain';
|
|
10306
|
+
let filename = `${INLINE_KNOWLEDGE_BASE_NAME}${INLINE_KNOWLEDGE_EXTENSION}`;
|
|
10307
|
+
let isBase64 = false;
|
|
10308
|
+
for (let i = 1; i < tokens.length; i++) {
|
|
10309
|
+
const token = tokens[i];
|
|
10310
|
+
if (!token) {
|
|
10311
|
+
continue;
|
|
10312
|
+
}
|
|
10313
|
+
if (token.toLowerCase() === 'base64') {
|
|
10314
|
+
isBase64 = true;
|
|
10315
|
+
continue;
|
|
10316
|
+
}
|
|
10317
|
+
const [key, value] = token.split('=');
|
|
10318
|
+
if (key === 'name' && value !== undefined) {
|
|
10319
|
+
try {
|
|
10320
|
+
filename = decodeURIComponent(value);
|
|
10321
|
+
}
|
|
10322
|
+
catch (_a) {
|
|
10323
|
+
filename = value;
|
|
10324
|
+
}
|
|
10325
|
+
}
|
|
10326
|
+
}
|
|
10327
|
+
if (!isBase64) {
|
|
10328
|
+
return null;
|
|
10329
|
+
}
|
|
10330
|
+
try {
|
|
10331
|
+
const buffer = Buffer.from(payload, 'base64');
|
|
10332
|
+
return {
|
|
10333
|
+
buffer,
|
|
10334
|
+
filename,
|
|
10335
|
+
mimeType: mediaType,
|
|
10336
|
+
};
|
|
10337
|
+
}
|
|
10338
|
+
catch (_b) {
|
|
10339
|
+
return null;
|
|
10340
|
+
}
|
|
10341
|
+
}
|
|
10342
|
+
/**
|
|
10343
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
10344
|
+
*/
|
|
10345
|
+
|
|
10127
10346
|
const DEFAULT_KNOWLEDGE_SOURCE_DOWNLOAD_TIMEOUT_MS = 30000;
|
|
10128
10347
|
const DEFAULT_KNOWLEDGE_SOURCE_UPLOAD_TIMEOUT_MS = 900000;
|
|
10129
10348
|
const VECTOR_STORE_PROGRESS_LOG_INTERVAL_MIN_MS = 15000;
|
|
@@ -10760,7 +10979,9 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
|
|
|
10760
10979
|
const processingStartedAtMs = Date.now();
|
|
10761
10980
|
for (const [index, source] of knowledgeSources.entries()) {
|
|
10762
10981
|
try {
|
|
10763
|
-
const
|
|
10982
|
+
const isDataUrl = isDataUrlKnowledgeSource(source);
|
|
10983
|
+
const isHttp = source.startsWith('http://') || source.startsWith('https://');
|
|
10984
|
+
const sourceType = isDataUrl ? 'data_url' : isHttp ? 'url' : 'file';
|
|
10764
10985
|
if (this.options.isVerbose) {
|
|
10765
10986
|
console.info('[🤰]', 'Processing knowledge source', {
|
|
10766
10987
|
index: index + 1,
|
|
@@ -10770,8 +10991,27 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
|
|
|
10770
10991
|
logLabel,
|
|
10771
10992
|
});
|
|
10772
10993
|
}
|
|
10773
|
-
|
|
10774
|
-
|
|
10994
|
+
if (isDataUrl) {
|
|
10995
|
+
const parsed = parseDataUrlKnowledgeSource(source);
|
|
10996
|
+
if (!parsed) {
|
|
10997
|
+
skippedSources.push({ source, reason: 'invalid_data_url' });
|
|
10998
|
+
if (this.options.isVerbose) {
|
|
10999
|
+
console.info('[🤰]', 'Skipping knowledge source (invalid data URL)', {
|
|
11000
|
+
source,
|
|
11001
|
+
sourceType,
|
|
11002
|
+
logLabel,
|
|
11003
|
+
});
|
|
11004
|
+
}
|
|
11005
|
+
continue;
|
|
11006
|
+
}
|
|
11007
|
+
const dataUrlFile = new File([parsed.buffer], parsed.filename, {
|
|
11008
|
+
type: parsed.mimeType,
|
|
11009
|
+
});
|
|
11010
|
+
fileStreams.push(dataUrlFile);
|
|
11011
|
+
totalBytes += parsed.buffer.length;
|
|
11012
|
+
continue;
|
|
11013
|
+
}
|
|
11014
|
+
if (isHttp) {
|
|
10775
11015
|
const downloadResult = await this.downloadKnowledgeSourceFile({
|
|
10776
11016
|
source,
|
|
10777
11017
|
timeoutMs: downloadTimeoutMs,
|
|
@@ -17175,11 +17415,14 @@ const _FormattedBookInMarkdownTranspilerRegistration = $bookTranspilersRegister.
|
|
|
17175
17415
|
function createEmptyAgentModelRequirements() {
|
|
17176
17416
|
return {
|
|
17177
17417
|
systemMessage: '',
|
|
17418
|
+
promptSuffix: '',
|
|
17178
17419
|
// modelName: 'gpt-5',
|
|
17179
17420
|
modelName: 'gemini-2.5-flash-lite',
|
|
17180
17421
|
temperature: 0.7,
|
|
17181
17422
|
topP: 0.9,
|
|
17182
17423
|
topK: 50,
|
|
17424
|
+
parentAgentUrl: null,
|
|
17425
|
+
isClosed: false,
|
|
17183
17426
|
};
|
|
17184
17427
|
}
|
|
17185
17428
|
/**
|
|
@@ -17296,6 +17539,28 @@ class BaseCommitmentDefinition {
|
|
|
17296
17539
|
return currentMessage + separator + content;
|
|
17297
17540
|
});
|
|
17298
17541
|
}
|
|
17542
|
+
/**
|
|
17543
|
+
* Helper method to create a new requirements object with updated prompt suffix
|
|
17544
|
+
*/
|
|
17545
|
+
updatePromptSuffix(requirements, contentUpdate) {
|
|
17546
|
+
const newSuffix = typeof contentUpdate === 'string' ? contentUpdate : contentUpdate(requirements.promptSuffix);
|
|
17547
|
+
return {
|
|
17548
|
+
...requirements,
|
|
17549
|
+
promptSuffix: newSuffix,
|
|
17550
|
+
};
|
|
17551
|
+
}
|
|
17552
|
+
/**
|
|
17553
|
+
* Helper method to append content to the prompt suffix
|
|
17554
|
+
* Default separator is a single newline for bullet lists.
|
|
17555
|
+
*/
|
|
17556
|
+
appendToPromptSuffix(requirements, content, separator = '\n') {
|
|
17557
|
+
return this.updatePromptSuffix(requirements, (currentSuffix) => {
|
|
17558
|
+
if (!currentSuffix.trim()) {
|
|
17559
|
+
return content;
|
|
17560
|
+
}
|
|
17561
|
+
return `${currentSuffix}${separator}${content}`;
|
|
17562
|
+
});
|
|
17563
|
+
}
|
|
17299
17564
|
/**
|
|
17300
17565
|
* Helper method to add a comment section to the system message
|
|
17301
17566
|
* Comments are lines starting with # that will be removed from the final system message
|
|
@@ -17473,13 +17738,9 @@ class ClosedCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
17473
17738
|
`);
|
|
17474
17739
|
}
|
|
17475
17740
|
applyToAgentModelRequirements(requirements, _content) {
|
|
17476
|
-
const updatedMetadata = {
|
|
17477
|
-
...requirements.metadata,
|
|
17478
|
-
isClosed: true,
|
|
17479
|
-
};
|
|
17480
17741
|
return {
|
|
17481
17742
|
...requirements,
|
|
17482
|
-
|
|
17743
|
+
isClosed: true,
|
|
17483
17744
|
};
|
|
17484
17745
|
}
|
|
17485
17746
|
}
|
|
@@ -17757,12 +18018,12 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
17757
18018
|
return requirements;
|
|
17758
18019
|
}
|
|
17759
18020
|
// Get existing dictionary entries from metadata
|
|
17760
|
-
const existingDictionary = ((_a = requirements.
|
|
18021
|
+
const existingDictionary = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
|
|
17761
18022
|
// Merge the new dictionary entry with existing entries
|
|
17762
18023
|
const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
|
|
17763
18024
|
// Store the merged dictionary in metadata for debugging and inspection
|
|
17764
18025
|
const updatedMetadata = {
|
|
17765
|
-
...requirements.
|
|
18026
|
+
...requirements._metadata,
|
|
17766
18027
|
DICTIONARY: mergedDictionary,
|
|
17767
18028
|
};
|
|
17768
18029
|
// Create the dictionary section for the system message
|
|
@@ -17770,7 +18031,7 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
17770
18031
|
const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
|
|
17771
18032
|
return {
|
|
17772
18033
|
...this.appendToSystemMessage(requirements, dictionarySection),
|
|
17773
|
-
|
|
18034
|
+
_metadata: updatedMetadata,
|
|
17774
18035
|
};
|
|
17775
18036
|
}
|
|
17776
18037
|
}
|
|
@@ -17910,10 +18171,7 @@ class FromCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
17910
18171
|
applyToAgentModelRequirements(requirements, content) {
|
|
17911
18172
|
const trimmedContent = content.trim();
|
|
17912
18173
|
if (!trimmedContent) {
|
|
17913
|
-
return
|
|
17914
|
-
...requirements,
|
|
17915
|
-
parentAgentUrl: undefined,
|
|
17916
|
-
};
|
|
18174
|
+
return requirements;
|
|
17917
18175
|
}
|
|
17918
18176
|
if (trimmedContent.toUpperCase() === 'VOID' ||
|
|
17919
18177
|
trimmedContent.toUpperCase() === 'NULL' ||
|
|
@@ -18225,9 +18483,13 @@ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18225
18483
|
return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
|
|
18226
18484
|
}
|
|
18227
18485
|
else {
|
|
18228
|
-
|
|
18229
|
-
const
|
|
18230
|
-
|
|
18486
|
+
const inlineSource = createInlineKnowledgeSourceFile(trimmedContent);
|
|
18487
|
+
const updatedRequirements = {
|
|
18488
|
+
...requirements,
|
|
18489
|
+
knowledgeSources: [...(requirements.knowledgeSources || []), inlineSource.url],
|
|
18490
|
+
};
|
|
18491
|
+
const knowledgeInfo = `Knowledge Source Inline: ${inlineSource.filename} (derived from inline content and processed for retrieval during chat)`;
|
|
18492
|
+
return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
|
|
18231
18493
|
}
|
|
18232
18494
|
}
|
|
18233
18495
|
}
|
|
@@ -18474,16 +18736,16 @@ class AgentMessageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18474
18736
|
// and typically doesn't need to be added to the system prompt or model requirements directly.
|
|
18475
18737
|
// It is extracted separately for the chat interface.
|
|
18476
18738
|
var _a;
|
|
18477
|
-
const pendingUserMessage = (_a = requirements.
|
|
18739
|
+
const pendingUserMessage = (_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
|
|
18478
18740
|
if (pendingUserMessage) {
|
|
18479
18741
|
const newSample = { question: pendingUserMessage, answer: content };
|
|
18480
18742
|
const newSamples = [...(requirements.samples || []), newSample];
|
|
18481
|
-
const newMetadata = { ...requirements.
|
|
18743
|
+
const newMetadata = { ...requirements._metadata };
|
|
18482
18744
|
delete newMetadata.pendingUserMessage;
|
|
18483
18745
|
return {
|
|
18484
18746
|
...requirements,
|
|
18485
18747
|
samples: newSamples,
|
|
18486
|
-
|
|
18748
|
+
_metadata: newMetadata,
|
|
18487
18749
|
};
|
|
18488
18750
|
}
|
|
18489
18751
|
return requirements;
|
|
@@ -18731,8 +18993,8 @@ class UserMessageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18731
18993
|
applyToAgentModelRequirements(requirements, content) {
|
|
18732
18994
|
return {
|
|
18733
18995
|
...requirements,
|
|
18734
|
-
|
|
18735
|
-
...requirements.
|
|
18996
|
+
_metadata: {
|
|
18997
|
+
...requirements._metadata,
|
|
18736
18998
|
pendingUserMessage: content,
|
|
18737
18999
|
},
|
|
18738
19000
|
};
|
|
@@ -19590,11 +19852,7 @@ class NoteCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19590
19852
|
if (trimmedContent === '') {
|
|
19591
19853
|
return requirements;
|
|
19592
19854
|
}
|
|
19593
|
-
|
|
19594
|
-
return {
|
|
19595
|
-
...requirements,
|
|
19596
|
-
notes: [...(requirements.notes || []), trimmedContent],
|
|
19597
|
-
};
|
|
19855
|
+
return requirements;
|
|
19598
19856
|
}
|
|
19599
19857
|
}
|
|
19600
19858
|
/**
|
|
@@ -19656,12 +19914,12 @@ class OpenCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19656
19914
|
// Since OPEN is default, we can just ensure isClosed is false
|
|
19657
19915
|
// But to be explicit we can set it
|
|
19658
19916
|
const updatedMetadata = {
|
|
19659
|
-
...requirements.
|
|
19917
|
+
...requirements._metadata,
|
|
19660
19918
|
isClosed: false,
|
|
19661
19919
|
};
|
|
19662
19920
|
return {
|
|
19663
19921
|
...requirements,
|
|
19664
|
-
|
|
19922
|
+
_metadata: updatedMetadata,
|
|
19665
19923
|
};
|
|
19666
19924
|
}
|
|
19667
19925
|
}
|
|
@@ -19742,7 +20000,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19742
20000
|
return requirements;
|
|
19743
20001
|
}
|
|
19744
20002
|
// Get existing persona content from metadata
|
|
19745
|
-
const existingPersonaContent = ((_a = requirements.
|
|
20003
|
+
const existingPersonaContent = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.PERSONA) || '';
|
|
19746
20004
|
// Merge the new content with existing persona content
|
|
19747
20005
|
// When multiple PERSONA commitments exist, they are merged into one
|
|
19748
20006
|
const mergedPersonaContent = existingPersonaContent
|
|
@@ -19750,12 +20008,12 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19750
20008
|
: trimmedContent;
|
|
19751
20009
|
// Store the merged persona content in metadata for debugging and inspection
|
|
19752
20010
|
const updatedMetadata = {
|
|
19753
|
-
...requirements.
|
|
20011
|
+
...requirements._metadata,
|
|
19754
20012
|
PERSONA: mergedPersonaContent,
|
|
19755
20013
|
};
|
|
19756
20014
|
// Get the agent name from metadata (which should contain the first line of agent source)
|
|
19757
20015
|
// If not available, extract from current system message as fallback
|
|
19758
|
-
let agentName = (_b = requirements.
|
|
20016
|
+
let agentName = (_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.agentName;
|
|
19759
20017
|
if (!agentName) {
|
|
19760
20018
|
// Fallback: extract from current system message
|
|
19761
20019
|
const currentMessage = requirements.systemMessage.trim();
|
|
@@ -19802,7 +20060,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19802
20060
|
return {
|
|
19803
20061
|
...requirements,
|
|
19804
20062
|
systemMessage: newSystemMessage,
|
|
19805
|
-
|
|
20063
|
+
_metadata: updatedMetadata,
|
|
19806
20064
|
};
|
|
19807
20065
|
}
|
|
19808
20066
|
}
|
|
@@ -19885,7 +20143,16 @@ class RuleCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19885
20143
|
}
|
|
19886
20144
|
// Add rule to the system message
|
|
19887
20145
|
const ruleSection = `Rule: ${trimmedContent}`;
|
|
19888
|
-
|
|
20146
|
+
const requirementsWithRule = this.appendToSystemMessage(requirements, ruleSection, '\n\n');
|
|
20147
|
+
const ruleLines = trimmedContent
|
|
20148
|
+
.split(/\r?\n/)
|
|
20149
|
+
.map((line) => line.trim())
|
|
20150
|
+
.filter(Boolean)
|
|
20151
|
+
.map((line) => `- ${line}`);
|
|
20152
|
+
if (ruleLines.length === 0) {
|
|
20153
|
+
return requirementsWithRule;
|
|
20154
|
+
}
|
|
20155
|
+
return this.appendToPromptSuffix(requirementsWithRule, ruleLines.join('\n'));
|
|
19889
20156
|
}
|
|
19890
20157
|
}
|
|
19891
20158
|
/**
|
|
@@ -20387,11 +20654,12 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
20387
20654
|
if (!trimmedContent) {
|
|
20388
20655
|
return requirements;
|
|
20389
20656
|
}
|
|
20390
|
-
|
|
20657
|
+
// Keep TEAM resilient: unresolved/malformed teammate entries are skipped, valid ones are still registered.
|
|
20658
|
+
const teammates = parseTeamCommitmentContent(trimmedContent, { strict: false });
|
|
20391
20659
|
if (teammates.length === 0) {
|
|
20392
20660
|
return requirements;
|
|
20393
20661
|
}
|
|
20394
|
-
const agentName = ((_a = requirements.
|
|
20662
|
+
const agentName = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.agentName) || 'Agent';
|
|
20395
20663
|
const teamEntries = teammates.map((teammate) => ({
|
|
20396
20664
|
toolName: createTeamToolName(teammate.url),
|
|
20397
20665
|
teammate,
|
|
@@ -20431,7 +20699,7 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
20431
20699
|
},
|
|
20432
20700
|
});
|
|
20433
20701
|
}
|
|
20434
|
-
const existingTeammates = ((_b = requirements.
|
|
20702
|
+
const existingTeammates = ((_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.teammates) || [];
|
|
20435
20703
|
const updatedTeammates = [...existingTeammates];
|
|
20436
20704
|
for (const entry of teamEntries) {
|
|
20437
20705
|
if (updatedTeammates.some((existing) => existing.url === entry.teammate.url)) {
|
|
@@ -20460,8 +20728,8 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
20460
20728
|
return this.appendToSystemMessage({
|
|
20461
20729
|
...requirements,
|
|
20462
20730
|
tools: updatedTools,
|
|
20463
|
-
|
|
20464
|
-
...requirements.
|
|
20731
|
+
_metadata: {
|
|
20732
|
+
...requirements._metadata,
|
|
20465
20733
|
teammates: updatedTeammates,
|
|
20466
20734
|
},
|
|
20467
20735
|
}, teamSystemMessage);
|
|
@@ -20693,7 +20961,7 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
20693
20961
|
if (!trimmedContent) {
|
|
20694
20962
|
// Store template mode flag in metadata
|
|
20695
20963
|
const updatedMetadata = {
|
|
20696
|
-
...requirements.
|
|
20964
|
+
...requirements._metadata,
|
|
20697
20965
|
templateMode: true,
|
|
20698
20966
|
};
|
|
20699
20967
|
// Add a general instruction about using structured templates
|
|
@@ -20703,21 +20971,21 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
20703
20971
|
`);
|
|
20704
20972
|
return {
|
|
20705
20973
|
...this.appendToSystemMessage(requirements, templateModeInstruction, '\n\n'),
|
|
20706
|
-
|
|
20974
|
+
_metadata: updatedMetadata,
|
|
20707
20975
|
};
|
|
20708
20976
|
}
|
|
20709
20977
|
// If content is provided, add the specific template instructions
|
|
20710
20978
|
const templateSection = `Response Template: ${trimmedContent}`;
|
|
20711
20979
|
// Store the template in metadata for potential programmatic access
|
|
20712
|
-
const existingTemplates = ((_a = requirements.
|
|
20980
|
+
const existingTemplates = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.templates) || [];
|
|
20713
20981
|
const updatedMetadata = {
|
|
20714
|
-
...requirements.
|
|
20982
|
+
...requirements._metadata,
|
|
20715
20983
|
templates: [...existingTemplates, trimmedContent],
|
|
20716
20984
|
templateMode: true,
|
|
20717
20985
|
};
|
|
20718
20986
|
return {
|
|
20719
20987
|
...this.appendToSystemMessage(requirements, templateSection, '\n\n'),
|
|
20720
|
-
|
|
20988
|
+
_metadata: updatedMetadata,
|
|
20721
20989
|
};
|
|
20722
20990
|
}
|
|
20723
20991
|
}
|
|
@@ -21054,8 +21322,8 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
21054
21322
|
return this.appendToSystemMessage({
|
|
21055
21323
|
...requirements,
|
|
21056
21324
|
tools: updatedTools,
|
|
21057
|
-
|
|
21058
|
-
...requirements.
|
|
21325
|
+
_metadata: {
|
|
21326
|
+
...requirements._metadata,
|
|
21059
21327
|
useBrowser: true,
|
|
21060
21328
|
},
|
|
21061
21329
|
}, spaceTrim$1(`
|
|
@@ -21284,8 +21552,8 @@ class UseEmailCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
21284
21552
|
return this.appendToSystemMessage({
|
|
21285
21553
|
...requirements,
|
|
21286
21554
|
tools: updatedTools,
|
|
21287
|
-
|
|
21288
|
-
...requirements.
|
|
21555
|
+
_metadata: {
|
|
21556
|
+
...requirements._metadata,
|
|
21289
21557
|
useEmail: content || true,
|
|
21290
21558
|
},
|
|
21291
21559
|
}, spaceTrim$1((block) => `
|
|
@@ -21420,8 +21688,8 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
21420
21688
|
return this.appendToSystemMessage({
|
|
21421
21689
|
...requirements,
|
|
21422
21690
|
tools: updatedTools,
|
|
21423
|
-
|
|
21424
|
-
...requirements.
|
|
21691
|
+
_metadata: {
|
|
21692
|
+
...requirements._metadata,
|
|
21425
21693
|
useImageGenerator: content || true,
|
|
21426
21694
|
},
|
|
21427
21695
|
}, spaceTrim$1(`
|
|
@@ -21712,8 +21980,8 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
21712
21980
|
return this.appendToSystemMessage({
|
|
21713
21981
|
...requirements,
|
|
21714
21982
|
tools: updatedTools,
|
|
21715
|
-
|
|
21716
|
-
...requirements.
|
|
21983
|
+
_metadata: {
|
|
21984
|
+
...requirements._metadata,
|
|
21717
21985
|
useSearchEngine: content || true,
|
|
21718
21986
|
},
|
|
21719
21987
|
}, spaceTrim$1((block) => `
|
|
@@ -21861,8 +22129,8 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
21861
22129
|
return this.appendToSystemMessage({
|
|
21862
22130
|
...requirements,
|
|
21863
22131
|
tools: updatedTools,
|
|
21864
|
-
|
|
21865
|
-
...requirements.
|
|
22132
|
+
_metadata: {
|
|
22133
|
+
...requirements._metadata,
|
|
21866
22134
|
},
|
|
21867
22135
|
}, spaceTrim$1((block) => `
|
|
21868
22136
|
Time and date context:
|
|
@@ -22446,14 +22714,42 @@ function removeCommentsFromSystemMessage(systemMessage) {
|
|
|
22446
22714
|
}
|
|
22447
22715
|
|
|
22448
22716
|
/**
|
|
22449
|
-
* Creates agent model requirements using the new commitment system
|
|
22717
|
+
* Creates agent model requirements using the new commitment system.
|
|
22718
|
+
*
|
|
22450
22719
|
* This function uses a reduce-like pattern where each commitment applies its changes
|
|
22451
|
-
* to build the final requirements starting from a basic empty model
|
|
22720
|
+
* to build the final requirements starting from a basic empty model.
|
|
22452
22721
|
*
|
|
22453
|
-
* @
|
|
22722
|
+
* @param agentSource - Agent source book to parse.
|
|
22723
|
+
* @param modelName - Optional override for the agent model name.
|
|
22724
|
+
* @param options - Additional options such as the agent reference resolver.
|
|
22725
|
+
*
|
|
22726
|
+
* @private @@@
|
|
22454
22727
|
*/
|
|
22455
|
-
|
|
22728
|
+
const COMMITMENTS_WITH_AGENT_REFERENCES = new Set(['FROM', 'IMPORT', 'IMPORTS', 'TEAM']);
|
|
22729
|
+
/**
|
|
22730
|
+
* Returns a safe fallback content when a resolver fails to transform a reference commitment.
|
|
22731
|
+
*
|
|
22732
|
+
* @param commitmentType - Commitment being resolved.
|
|
22733
|
+
* @param originalContent - Original unresolved commitment content.
|
|
22734
|
+
* @returns Fallback content that keeps requirement creation resilient.
|
|
22735
|
+
*/
|
|
22736
|
+
function getSafeReferenceCommitmentFallback(commitmentType, originalContent) {
|
|
22737
|
+
if (commitmentType === 'FROM') {
|
|
22738
|
+
return 'VOID';
|
|
22739
|
+
}
|
|
22740
|
+
if (commitmentType === 'IMPORT' || commitmentType === 'IMPORTS' || commitmentType === 'TEAM') {
|
|
22741
|
+
return '';
|
|
22742
|
+
}
|
|
22743
|
+
return originalContent;
|
|
22744
|
+
}
|
|
22745
|
+
/**
|
|
22746
|
+
* @@@
|
|
22747
|
+
*
|
|
22748
|
+
* @private @@@
|
|
22749
|
+
*/
|
|
22750
|
+
async function createAgentModelRequirementsWithCommitments(agentSource, modelName, options) {
|
|
22456
22751
|
var _a;
|
|
22752
|
+
const agentReferenceResolver = options === null || options === void 0 ? void 0 : options.agentReferenceResolver;
|
|
22457
22753
|
// Parse the agent source to extract commitments
|
|
22458
22754
|
const parseResult = parseAgentSourceWithCommitments(agentSource);
|
|
22459
22755
|
// Apply DELETE filtering: remove prior commitments tagged by parameters targeted by DELETE/CANCEL/DISCARD/REMOVE
|
|
@@ -22490,8 +22786,8 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
22490
22786
|
// Store the agent name in metadata so commitments can access it
|
|
22491
22787
|
requirements = {
|
|
22492
22788
|
...requirements,
|
|
22493
|
-
|
|
22494
|
-
...requirements.
|
|
22789
|
+
_metadata: {
|
|
22790
|
+
...requirements._metadata,
|
|
22495
22791
|
agentName: parseResult.agentName,
|
|
22496
22792
|
},
|
|
22497
22793
|
};
|
|
@@ -22505,6 +22801,17 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
22505
22801
|
// Apply each commitment in order using reduce-like pattern
|
|
22506
22802
|
for (let i = 0; i < filteredCommitments.length; i++) {
|
|
22507
22803
|
const commitment = filteredCommitments[i];
|
|
22804
|
+
const isReferenceCommitment = Boolean(agentReferenceResolver && COMMITMENTS_WITH_AGENT_REFERENCES.has(commitment.type));
|
|
22805
|
+
let commitmentContent = commitment.content;
|
|
22806
|
+
if (isReferenceCommitment && agentReferenceResolver) {
|
|
22807
|
+
try {
|
|
22808
|
+
commitmentContent = await agentReferenceResolver.resolveCommitmentContent(commitment.type, commitment.content);
|
|
22809
|
+
}
|
|
22810
|
+
catch (error) {
|
|
22811
|
+
console.warn(`Failed to resolve commitment references for ${commitment.type}, falling back to safe defaults:`, error);
|
|
22812
|
+
commitmentContent = getSafeReferenceCommitmentFallback(commitment.type, commitment.content);
|
|
22813
|
+
}
|
|
22814
|
+
}
|
|
22508
22815
|
// CLOSED commitment should work only if its the last commitment in the book
|
|
22509
22816
|
if (commitment.type === 'CLOSED' && i !== filteredCommitments.length - 1) {
|
|
22510
22817
|
continue;
|
|
@@ -22512,7 +22819,7 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
22512
22819
|
const definition = getCommitmentDefinition(commitment.type);
|
|
22513
22820
|
if (definition) {
|
|
22514
22821
|
try {
|
|
22515
|
-
requirements = definition.applyToAgentModelRequirements(requirements,
|
|
22822
|
+
requirements = definition.applyToAgentModelRequirements(requirements, commitmentContent);
|
|
22516
22823
|
}
|
|
22517
22824
|
catch (error) {
|
|
22518
22825
|
console.warn(`Failed to apply commitment ${commitment.type}:`, error);
|
|
@@ -22971,23 +23278,28 @@ function normalizeSeparator(content) {
|
|
|
22971
23278
|
*/
|
|
22972
23279
|
|
|
22973
23280
|
/**
|
|
22974
|
-
* Creates model requirements for an agent based on its source
|
|
23281
|
+
* Creates model requirements for an agent based on its source.
|
|
22975
23282
|
*
|
|
22976
23283
|
* There are 2 similar functions:
|
|
22977
23284
|
* - `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.
|
|
22978
23285
|
* - `createAgentModelRequirements` which is an asynchronous function that creates model requirements it applies each commitment one by one and works asynchronous.
|
|
22979
23286
|
*
|
|
23287
|
+
* @param agentSource - Book describing the agent.
|
|
23288
|
+
* @param modelName - Optional override for the agent's model.
|
|
23289
|
+
* @param availableModels - Models that could fulfill the agent.
|
|
23290
|
+
* @param llmTools - Execution tools used when selecting a best model.
|
|
23291
|
+
* @param options - Optional hooks such as the agent reference resolver.
|
|
22980
23292
|
* @public exported from `@promptbook/core`
|
|
22981
23293
|
*/
|
|
22982
|
-
async function createAgentModelRequirements(agentSource, modelName, availableModels, llmTools) {
|
|
23294
|
+
async function createAgentModelRequirements(agentSource, modelName, availableModels, llmTools, options) {
|
|
22983
23295
|
// If availableModels are provided and no specific modelName is given,
|
|
22984
23296
|
// use preparePersona to select the best model
|
|
22985
23297
|
if (availableModels && !modelName && llmTools) {
|
|
22986
23298
|
const selectedModelName = await selectBestModelUsingPersona(agentSource, llmTools);
|
|
22987
|
-
return createAgentModelRequirementsWithCommitments(agentSource, selectedModelName);
|
|
23299
|
+
return createAgentModelRequirementsWithCommitments(agentSource, selectedModelName, options);
|
|
22988
23300
|
}
|
|
22989
23301
|
// Use the new commitment-based system with provided or default model
|
|
22990
|
-
return createAgentModelRequirementsWithCommitments(agentSource, modelName);
|
|
23302
|
+
return createAgentModelRequirementsWithCommitments(agentSource, modelName, options);
|
|
22991
23303
|
}
|
|
22992
23304
|
/**
|
|
22993
23305
|
* Selects the best model using the preparePersona function
|
|
@@ -29540,6 +29852,64 @@ function promptbookifyAiText(text) {
|
|
|
29540
29852
|
*/
|
|
29541
29853
|
|
|
29542
29854
|
const DEFAULT_AGENT_KIT_MODEL_NAME = 'gpt-5.2';
|
|
29855
|
+
const DEFAULT_JSON_SCHEMA_NAME = 'StructuredOutput';
|
|
29856
|
+
/*
|
|
29857
|
+
TODO: Use or remove
|
|
29858
|
+
const EMPTY_JSON_SCHEMA: JsonSchemaDefinition['schema'] = {
|
|
29859
|
+
type: 'object',
|
|
29860
|
+
properties: {},
|
|
29861
|
+
required: [],
|
|
29862
|
+
additionalProperties: true,
|
|
29863
|
+
};
|
|
29864
|
+
*/
|
|
29865
|
+
function buildJsonSchemaDefinition(jsonSchema) {
|
|
29866
|
+
var _a, _b, _c;
|
|
29867
|
+
const schema = (_a = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.schema) !== null && _a !== void 0 ? _a : {};
|
|
29868
|
+
return {
|
|
29869
|
+
type: 'json_schema',
|
|
29870
|
+
name: (_b = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.name) !== null && _b !== void 0 ? _b : DEFAULT_JSON_SCHEMA_NAME,
|
|
29871
|
+
strict: Boolean(jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.strict),
|
|
29872
|
+
schema: {
|
|
29873
|
+
type: 'object',
|
|
29874
|
+
properties: ((_c = schema.properties) !== null && _c !== void 0 ? _c : {}),
|
|
29875
|
+
required: Array.isArray(schema.required) ? schema.required : [],
|
|
29876
|
+
additionalProperties: schema.additionalProperties === undefined ? true : Boolean(schema.additionalProperties),
|
|
29877
|
+
description: schema.description,
|
|
29878
|
+
},
|
|
29879
|
+
};
|
|
29880
|
+
}
|
|
29881
|
+
/**
|
|
29882
|
+
* Maps OpenAI `response_format` payloads to AgentKit output types so the runner can forward
|
|
29883
|
+
* structured-output preferences to OpenAI while still reusing the same AgentKit agent instance.
|
|
29884
|
+
*
|
|
29885
|
+
* @param responseFormat - The OpenAI `response_format` payload from the user request.
|
|
29886
|
+
* @returns An Agent output type compatible with the requested schema or `undefined` when no impact is required.
|
|
29887
|
+
* @private utility of Open AI
|
|
29888
|
+
*/
|
|
29889
|
+
function mapResponseFormatToAgentOutputType(responseFormat) {
|
|
29890
|
+
if (!responseFormat) {
|
|
29891
|
+
return undefined;
|
|
29892
|
+
}
|
|
29893
|
+
if (typeof responseFormat === 'string') {
|
|
29894
|
+
if (responseFormat === 'text') {
|
|
29895
|
+
return 'text';
|
|
29896
|
+
}
|
|
29897
|
+
if (responseFormat === 'json_schema' || responseFormat === 'json_object') {
|
|
29898
|
+
return buildJsonSchemaDefinition();
|
|
29899
|
+
}
|
|
29900
|
+
return 'text';
|
|
29901
|
+
}
|
|
29902
|
+
switch (responseFormat.type) {
|
|
29903
|
+
case 'text':
|
|
29904
|
+
return 'text';
|
|
29905
|
+
case 'json_schema':
|
|
29906
|
+
return buildJsonSchemaDefinition(responseFormat.json_schema);
|
|
29907
|
+
case 'json_object':
|
|
29908
|
+
return buildJsonSchemaDefinition();
|
|
29909
|
+
default:
|
|
29910
|
+
return undefined;
|
|
29911
|
+
}
|
|
29912
|
+
}
|
|
29543
29913
|
/**
|
|
29544
29914
|
* Execution tools for OpenAI AgentKit (Agents SDK).
|
|
29545
29915
|
*
|
|
@@ -29587,6 +29957,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
29587
29957
|
...parameters,
|
|
29588
29958
|
modelName: this.agentKitModelName,
|
|
29589
29959
|
});
|
|
29960
|
+
const responseFormatOutputType = mapResponseFormatToAgentOutputType(modelRequirements.responseFormat);
|
|
29590
29961
|
const preparedAgentKitAgent = await this.prepareAgentKitAgent({
|
|
29591
29962
|
name: (prompt.title || 'Agent'),
|
|
29592
29963
|
instructions: modelRequirements.systemMessage || '',
|
|
@@ -29598,6 +29969,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
29598
29969
|
prompt,
|
|
29599
29970
|
rawPromptContent,
|
|
29600
29971
|
onProgress,
|
|
29972
|
+
responseFormatOutputType,
|
|
29601
29973
|
});
|
|
29602
29974
|
}
|
|
29603
29975
|
/**
|
|
@@ -29779,16 +30151,21 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
29779
30151
|
...prompt.parameters,
|
|
29780
30152
|
modelName: this.agentKitModelName,
|
|
29781
30153
|
});
|
|
30154
|
+
const agentForRun = options.responseFormatOutputType !== undefined
|
|
30155
|
+
? openAiAgentKitAgent.clone({
|
|
30156
|
+
outputType: options.responseFormatOutputType,
|
|
30157
|
+
})
|
|
30158
|
+
: openAiAgentKitAgent;
|
|
29782
30159
|
const start = $getCurrentDate();
|
|
29783
30160
|
let latestContent = '';
|
|
29784
30161
|
const toolCalls = [];
|
|
29785
30162
|
const toolCallIndexById = new Map();
|
|
29786
30163
|
const inputItems = await this.buildAgentKitInputItems(prompt, rawPromptContent);
|
|
29787
30164
|
const rawRequest = {
|
|
29788
|
-
agentName:
|
|
30165
|
+
agentName: agentForRun.name,
|
|
29789
30166
|
input: inputItems,
|
|
29790
30167
|
};
|
|
29791
|
-
const streamResult = await run(
|
|
30168
|
+
const streamResult = await run(agentForRun, inputItems, {
|
|
29792
30169
|
stream: true,
|
|
29793
30170
|
context: { parameters: prompt.parameters },
|
|
29794
30171
|
});
|
|
@@ -30136,22 +30513,28 @@ class AgentLlmExecutionTools {
|
|
|
30136
30513
|
throw new Error('AgentLlmExecutionTools only supports chat prompts');
|
|
30137
30514
|
}
|
|
30138
30515
|
const modelRequirements = await this.getModelRequirements();
|
|
30516
|
+
const { _metadata, promptSuffix, ...sanitizedRequirements } = modelRequirements;
|
|
30139
30517
|
const chatPrompt = prompt;
|
|
30140
30518
|
let underlyingLlmResult;
|
|
30141
|
-
|
|
30519
|
+
const chatPromptContentWithSuffix = promptSuffix
|
|
30520
|
+
? `${chatPrompt.content}\n\n${promptSuffix}`
|
|
30521
|
+
: chatPrompt.content;
|
|
30142
30522
|
const promptWithAgentModelRequirements = {
|
|
30143
30523
|
...chatPrompt,
|
|
30524
|
+
content: chatPromptContentWithSuffix,
|
|
30144
30525
|
modelRequirements: {
|
|
30145
30526
|
...chatPrompt.modelRequirements,
|
|
30146
|
-
...
|
|
30527
|
+
...sanitizedRequirements,
|
|
30147
30528
|
// Spread tools to convert readonly array to mutable
|
|
30148
|
-
tools:
|
|
30529
|
+
tools: sanitizedRequirements.tools
|
|
30530
|
+
? [...sanitizedRequirements.tools]
|
|
30531
|
+
: chatPrompt.modelRequirements.tools,
|
|
30149
30532
|
// Spread knowledgeSources to convert readonly array to mutable
|
|
30150
|
-
knowledgeSources:
|
|
30151
|
-
? [...
|
|
30533
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources
|
|
30534
|
+
? [...sanitizedRequirements.knowledgeSources]
|
|
30152
30535
|
: undefined,
|
|
30153
30536
|
// Prepend agent system message to existing system message
|
|
30154
|
-
systemMessage:
|
|
30537
|
+
systemMessage: sanitizedRequirements.systemMessage +
|
|
30155
30538
|
(chatPrompt.modelRequirements.systemMessage
|
|
30156
30539
|
? `\n\n${chatPrompt.modelRequirements.systemMessage}`
|
|
30157
30540
|
: ''),
|
|
@@ -30159,8 +30542,8 @@ class AgentLlmExecutionTools {
|
|
|
30159
30542
|
};
|
|
30160
30543
|
console.log('!!!! promptWithAgentModelRequirements:', promptWithAgentModelRequirements);
|
|
30161
30544
|
if (OpenAiAgentKitExecutionTools.isOpenAiAgentKitExecutionTools(this.options.llmTools)) {
|
|
30162
|
-
const requirementsHash = SHA256(JSON.stringify(
|
|
30163
|
-
const vectorStoreHash = SHA256(JSON.stringify((_a =
|
|
30545
|
+
const requirementsHash = SHA256(JSON.stringify(sanitizedRequirements)).toString();
|
|
30546
|
+
const vectorStoreHash = SHA256(JSON.stringify((_a = sanitizedRequirements.knowledgeSources) !== null && _a !== void 0 ? _a : [])).toString();
|
|
30164
30547
|
const cachedVectorStore = AgentLlmExecutionTools.vectorStoreCache.get(this.title);
|
|
30165
30548
|
const cachedAgentKit = AgentLlmExecutionTools.agentKitAgentCache.get(this.title);
|
|
30166
30549
|
let preparedAgentKit = this.options.assistantPreparationMode === 'external'
|
|
@@ -30187,7 +30570,7 @@ class AgentLlmExecutionTools {
|
|
|
30187
30570
|
agent: this.title,
|
|
30188
30571
|
});
|
|
30189
30572
|
}
|
|
30190
|
-
if (!vectorStoreId && ((_b =
|
|
30573
|
+
if (!vectorStoreId && ((_b = sanitizedRequirements.knowledgeSources) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
30191
30574
|
emitAssistantPreparationProgress({
|
|
30192
30575
|
onProgress,
|
|
30193
30576
|
prompt,
|
|
@@ -30203,9 +30586,9 @@ class AgentLlmExecutionTools {
|
|
|
30203
30586
|
});
|
|
30204
30587
|
preparedAgentKit = await this.options.llmTools.prepareAgentKitAgent({
|
|
30205
30588
|
name: this.title,
|
|
30206
|
-
instructions:
|
|
30207
|
-
knowledgeSources:
|
|
30208
|
-
tools:
|
|
30589
|
+
instructions: sanitizedRequirements.systemMessage || '',
|
|
30590
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources,
|
|
30591
|
+
tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
|
|
30209
30592
|
vectorStoreId,
|
|
30210
30593
|
});
|
|
30211
30594
|
}
|
|
@@ -30220,15 +30603,17 @@ class AgentLlmExecutionTools {
|
|
|
30220
30603
|
requirementsHash,
|
|
30221
30604
|
vectorStoreId: preparedAgentKit.vectorStoreId,
|
|
30222
30605
|
});
|
|
30606
|
+
const responseFormatOutputType = mapResponseFormatToAgentOutputType(promptWithAgentModelRequirements.modelRequirements.responseFormat);
|
|
30223
30607
|
underlyingLlmResult = await this.options.llmTools.callChatModelStreamWithPreparedAgent({
|
|
30224
30608
|
openAiAgentKitAgent: preparedAgentKit.agent,
|
|
30225
30609
|
prompt: promptWithAgentModelRequirements,
|
|
30226
30610
|
onProgress,
|
|
30611
|
+
responseFormatOutputType,
|
|
30227
30612
|
});
|
|
30228
30613
|
}
|
|
30229
30614
|
else if (OpenAiAssistantExecutionTools.isOpenAiAssistantExecutionTools(this.options.llmTools)) {
|
|
30230
30615
|
// ... deprecated path ...
|
|
30231
|
-
const requirementsHash = SHA256(JSON.stringify(
|
|
30616
|
+
const requirementsHash = SHA256(JSON.stringify(sanitizedRequirements)).toString();
|
|
30232
30617
|
const cached = AgentLlmExecutionTools.assistantCache.get(this.title);
|
|
30233
30618
|
let assistant;
|
|
30234
30619
|
if (this.options.assistantPreparationMode === 'external') {
|
|
@@ -30270,9 +30655,9 @@ class AgentLlmExecutionTools {
|
|
|
30270
30655
|
assistant = await this.options.llmTools.updateAssistant({
|
|
30271
30656
|
assistantId: cached.assistantId,
|
|
30272
30657
|
name: this.title,
|
|
30273
|
-
instructions:
|
|
30274
|
-
knowledgeSources:
|
|
30275
|
-
tools:
|
|
30658
|
+
instructions: sanitizedRequirements.systemMessage,
|
|
30659
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources,
|
|
30660
|
+
tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
|
|
30276
30661
|
});
|
|
30277
30662
|
AgentLlmExecutionTools.assistantCache.set(this.title, {
|
|
30278
30663
|
assistantId: assistant.assistantId,
|
|
@@ -30295,9 +30680,9 @@ class AgentLlmExecutionTools {
|
|
|
30295
30680
|
});
|
|
30296
30681
|
assistant = await this.options.llmTools.createNewAssistant({
|
|
30297
30682
|
name: this.title,
|
|
30298
|
-
instructions:
|
|
30299
|
-
knowledgeSources:
|
|
30300
|
-
tools:
|
|
30683
|
+
instructions: sanitizedRequirements.systemMessage,
|
|
30684
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources,
|
|
30685
|
+
tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
|
|
30301
30686
|
/*
|
|
30302
30687
|
!!!
|
|
30303
30688
|
metadata: {
|
|
@@ -30339,13 +30724,19 @@ class AgentLlmExecutionTools {
|
|
|
30339
30724
|
}
|
|
30340
30725
|
}
|
|
30341
30726
|
let content = underlyingLlmResult.content;
|
|
30342
|
-
|
|
30343
|
-
|
|
30344
|
-
|
|
30345
|
-
|
|
30727
|
+
if (typeof content === 'string') {
|
|
30728
|
+
// Note: Cleanup the AI artifacts from the content
|
|
30729
|
+
content = humanizeAiText(content);
|
|
30730
|
+
// Note: Make sure the content is Promptbook-like
|
|
30731
|
+
content = promptbookifyAiText(content);
|
|
30732
|
+
}
|
|
30733
|
+
else {
|
|
30734
|
+
// TODO: Maybe deep `humanizeAiText` + `promptbookifyAiText` inside of the object
|
|
30735
|
+
content = JSON.stringify(content);
|
|
30736
|
+
}
|
|
30346
30737
|
const agentResult = {
|
|
30347
30738
|
...underlyingLlmResult,
|
|
30348
|
-
content,
|
|
30739
|
+
content: content,
|
|
30349
30740
|
modelName: this.modelName,
|
|
30350
30741
|
};
|
|
30351
30742
|
return agentResult;
|
|
@@ -30534,7 +30925,6 @@ class Agent extends AgentLlmExecutionTools {
|
|
|
30534
30925
|
* Note: This method also implements the learning mechanism
|
|
30535
30926
|
*/
|
|
30536
30927
|
async callChatModelStream(prompt, onProgress) {
|
|
30537
|
-
var _a;
|
|
30538
30928
|
// [1] Check if the user is asking the same thing as in the samples
|
|
30539
30929
|
const modelRequirements = await this.getModelRequirements();
|
|
30540
30930
|
if (modelRequirements.samples) {
|
|
@@ -30582,7 +30972,7 @@ class Agent extends AgentLlmExecutionTools {
|
|
|
30582
30972
|
if (result.rawResponse && 'sample' in result.rawResponse) {
|
|
30583
30973
|
return result;
|
|
30584
30974
|
}
|
|
30585
|
-
if (
|
|
30975
|
+
if (modelRequirements.isClosed) {
|
|
30586
30976
|
return result;
|
|
30587
30977
|
}
|
|
30588
30978
|
// Note: [0] Notify start of self-learning
|