@promptbook/cli 0.110.0-8 → 0.110.0-9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +432 -87
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/components.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +4 -0
- package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +22 -21
- 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 +15 -0
- package/esm/typings/src/book-components/Chat/Chat/ChatSoundToggle.d.ts +19 -0
- package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +6 -0
- package/esm/typings/src/commitments/_base/BaseCommitmentDefinition.d.ts +9 -0
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.test.d.ts +1 -0
- package/esm/typings/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +39 -0
- package/esm/typings/src/types/LlmToolDefinition.d.ts +1 -0
- package/esm/typings/src/types/ModelRequirements.d.ts +9 -0
- package/esm/typings/src/utils/DEFAULT_THINKING_MESSAGES.d.ts +8 -0
- package/esm/typings/src/utils/knowledge/inlineKnowledgeSource.d.ts +38 -0
- package/esm/typings/src/utils/knowledge/inlineKnowledgeSource.test.d.ts +1 -0
- package/esm/typings/src/utils/language/getBrowserPreferredSpeechRecognitionLanguage.d.ts +35 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +432 -87
- package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js
CHANGED
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
* @generated
|
|
57
57
|
* @see https://github.com/webgptorg/promptbook
|
|
58
58
|
*/
|
|
59
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.110.0-
|
|
59
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.110.0-9';
|
|
60
60
|
/**
|
|
61
61
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
62
62
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -15836,6 +15836,28 @@
|
|
|
15836
15836
|
return currentMessage + separator + content;
|
|
15837
15837
|
});
|
|
15838
15838
|
}
|
|
15839
|
+
/**
|
|
15840
|
+
* Helper method to create a new requirements object with updated prompt suffix
|
|
15841
|
+
*/
|
|
15842
|
+
updatePromptSuffix(requirements, contentUpdate) {
|
|
15843
|
+
const newSuffix = typeof contentUpdate === 'string' ? contentUpdate : contentUpdate(requirements.promptSuffix);
|
|
15844
|
+
return {
|
|
15845
|
+
...requirements,
|
|
15846
|
+
promptSuffix: newSuffix,
|
|
15847
|
+
};
|
|
15848
|
+
}
|
|
15849
|
+
/**
|
|
15850
|
+
* Helper method to append content to the prompt suffix
|
|
15851
|
+
* Default separator is a single newline for bullet lists.
|
|
15852
|
+
*/
|
|
15853
|
+
appendToPromptSuffix(requirements, content, separator = '\n') {
|
|
15854
|
+
return this.updatePromptSuffix(requirements, (currentSuffix) => {
|
|
15855
|
+
if (!currentSuffix.trim()) {
|
|
15856
|
+
return content;
|
|
15857
|
+
}
|
|
15858
|
+
return `${currentSuffix}${separator}${content}`;
|
|
15859
|
+
});
|
|
15860
|
+
}
|
|
15839
15861
|
/**
|
|
15840
15862
|
* Helper method to add a comment section to the system message
|
|
15841
15863
|
* Comments are lines starting with # that will be removed from the final system message
|
|
@@ -16013,13 +16035,9 @@
|
|
|
16013
16035
|
`);
|
|
16014
16036
|
}
|
|
16015
16037
|
applyToAgentModelRequirements(requirements, _content) {
|
|
16016
|
-
const updatedMetadata = {
|
|
16017
|
-
...requirements.metadata,
|
|
16018
|
-
isClosed: true,
|
|
16019
|
-
};
|
|
16020
16038
|
return {
|
|
16021
16039
|
...requirements,
|
|
16022
|
-
|
|
16040
|
+
isClosed: true,
|
|
16023
16041
|
};
|
|
16024
16042
|
}
|
|
16025
16043
|
}
|
|
@@ -16297,12 +16315,12 @@
|
|
|
16297
16315
|
return requirements;
|
|
16298
16316
|
}
|
|
16299
16317
|
// Get existing dictionary entries from metadata
|
|
16300
|
-
const existingDictionary = ((_a = requirements.
|
|
16318
|
+
const existingDictionary = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
|
|
16301
16319
|
// Merge the new dictionary entry with existing entries
|
|
16302
16320
|
const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
|
|
16303
16321
|
// Store the merged dictionary in metadata for debugging and inspection
|
|
16304
16322
|
const updatedMetadata = {
|
|
16305
|
-
...requirements.
|
|
16323
|
+
...requirements._metadata,
|
|
16306
16324
|
DICTIONARY: mergedDictionary,
|
|
16307
16325
|
};
|
|
16308
16326
|
// Create the dictionary section for the system message
|
|
@@ -16310,7 +16328,7 @@
|
|
|
16310
16328
|
const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
|
|
16311
16329
|
return {
|
|
16312
16330
|
...this.appendToSystemMessage(requirements, dictionarySection),
|
|
16313
|
-
|
|
16331
|
+
_metadata: updatedMetadata,
|
|
16314
16332
|
};
|
|
16315
16333
|
}
|
|
16316
16334
|
}
|
|
@@ -16450,10 +16468,7 @@
|
|
|
16450
16468
|
applyToAgentModelRequirements(requirements, content) {
|
|
16451
16469
|
const trimmedContent = content.trim();
|
|
16452
16470
|
if (!trimmedContent) {
|
|
16453
|
-
return
|
|
16454
|
-
...requirements,
|
|
16455
|
-
parentAgentUrl: undefined,
|
|
16456
|
-
};
|
|
16471
|
+
return requirements;
|
|
16457
16472
|
}
|
|
16458
16473
|
if (trimmedContent.toUpperCase() === 'VOID' ||
|
|
16459
16474
|
trimmedContent.toUpperCase() === 'NULL' ||
|
|
@@ -16667,6 +16682,136 @@
|
|
|
16667
16682
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
16668
16683
|
*/
|
|
16669
16684
|
|
|
16685
|
+
/**
|
|
16686
|
+
* @@@
|
|
16687
|
+
*
|
|
16688
|
+
* @private thing of inline knowledge
|
|
16689
|
+
*/
|
|
16690
|
+
const INLINE_KNOWLEDGE_BASE_NAME = 'inline-knowledge';
|
|
16691
|
+
/**
|
|
16692
|
+
* @@@
|
|
16693
|
+
*
|
|
16694
|
+
* @private thing of inline knowledge
|
|
16695
|
+
*/
|
|
16696
|
+
const INLINE_KNOWLEDGE_EXTENSION = '.txt';
|
|
16697
|
+
/**
|
|
16698
|
+
* @@@
|
|
16699
|
+
*
|
|
16700
|
+
* @private thing of inline knowledge
|
|
16701
|
+
*/
|
|
16702
|
+
const DATA_URL_PREFIX = 'data:';
|
|
16703
|
+
/**
|
|
16704
|
+
* @@@
|
|
16705
|
+
*
|
|
16706
|
+
* @private thing of inline knowledge
|
|
16707
|
+
*/
|
|
16708
|
+
function getFirstNonEmptyLine(content) {
|
|
16709
|
+
const lines = content.split(/\r?\n/);
|
|
16710
|
+
for (const line of lines) {
|
|
16711
|
+
const trimmed = line.trim();
|
|
16712
|
+
if (trimmed) {
|
|
16713
|
+
return trimmed;
|
|
16714
|
+
}
|
|
16715
|
+
}
|
|
16716
|
+
return null;
|
|
16717
|
+
}
|
|
16718
|
+
/**
|
|
16719
|
+
* @@@
|
|
16720
|
+
*
|
|
16721
|
+
* @private thing of inline knowledge
|
|
16722
|
+
*/
|
|
16723
|
+
function deriveBaseFilename(content) {
|
|
16724
|
+
const firstLine = getFirstNonEmptyLine(content);
|
|
16725
|
+
if (!firstLine) {
|
|
16726
|
+
return INLINE_KNOWLEDGE_BASE_NAME;
|
|
16727
|
+
}
|
|
16728
|
+
const normalized = normalizeToKebabCase(firstLine);
|
|
16729
|
+
return normalized || INLINE_KNOWLEDGE_BASE_NAME;
|
|
16730
|
+
}
|
|
16731
|
+
/**
|
|
16732
|
+
* Creates a data URL that represents the inline knowledge content as a text file.
|
|
16733
|
+
*
|
|
16734
|
+
* @private thing of inline knowledge
|
|
16735
|
+
*/
|
|
16736
|
+
function createInlineKnowledgeSourceFile(content) {
|
|
16737
|
+
const trimmedContent = content.trim();
|
|
16738
|
+
const baseName = deriveBaseFilename(trimmedContent);
|
|
16739
|
+
const filename = `${baseName}${INLINE_KNOWLEDGE_EXTENSION}`;
|
|
16740
|
+
const mimeType = 'text/plain';
|
|
16741
|
+
const base64 = Buffer.from(trimmedContent, 'utf-8').toString('base64');
|
|
16742
|
+
const encodedFilename = encodeURIComponent(filename);
|
|
16743
|
+
const url = `${DATA_URL_PREFIX}${mimeType};name=${encodedFilename};charset=utf-8;base64,${base64}`;
|
|
16744
|
+
return {
|
|
16745
|
+
filename,
|
|
16746
|
+
mimeType,
|
|
16747
|
+
url,
|
|
16748
|
+
};
|
|
16749
|
+
}
|
|
16750
|
+
/**
|
|
16751
|
+
* Checks whether the provided source string is a data URL that can be decoded.
|
|
16752
|
+
*
|
|
16753
|
+
* @private thing of inline knowledge
|
|
16754
|
+
*/
|
|
16755
|
+
function isDataUrlKnowledgeSource(source) {
|
|
16756
|
+
return typeof source === 'string' && source.startsWith(DATA_URL_PREFIX);
|
|
16757
|
+
}
|
|
16758
|
+
/**
|
|
16759
|
+
* Parses a data URL-based knowledge source into its raw buffer, filename, and MIME type.
|
|
16760
|
+
*
|
|
16761
|
+
* @private thing of inline knowledge
|
|
16762
|
+
*/
|
|
16763
|
+
function parseDataUrlKnowledgeSource(source) {
|
|
16764
|
+
if (!isDataUrlKnowledgeSource(source)) {
|
|
16765
|
+
return null;
|
|
16766
|
+
}
|
|
16767
|
+
const commaIndex = source.indexOf(',');
|
|
16768
|
+
if (commaIndex === -1) {
|
|
16769
|
+
return null;
|
|
16770
|
+
}
|
|
16771
|
+
const header = source.slice(DATA_URL_PREFIX.length, commaIndex);
|
|
16772
|
+
const payload = source.slice(commaIndex + 1);
|
|
16773
|
+
const tokens = header.split(';');
|
|
16774
|
+
const mediaType = tokens[0] || 'text/plain';
|
|
16775
|
+
let filename = `${INLINE_KNOWLEDGE_BASE_NAME}${INLINE_KNOWLEDGE_EXTENSION}`;
|
|
16776
|
+
let isBase64 = false;
|
|
16777
|
+
for (let i = 1; i < tokens.length; i++) {
|
|
16778
|
+
const token = tokens[i];
|
|
16779
|
+
if (!token) {
|
|
16780
|
+
continue;
|
|
16781
|
+
}
|
|
16782
|
+
if (token.toLowerCase() === 'base64') {
|
|
16783
|
+
isBase64 = true;
|
|
16784
|
+
continue;
|
|
16785
|
+
}
|
|
16786
|
+
const [key, value] = token.split('=');
|
|
16787
|
+
if (key === 'name' && value !== undefined) {
|
|
16788
|
+
try {
|
|
16789
|
+
filename = decodeURIComponent(value);
|
|
16790
|
+
}
|
|
16791
|
+
catch (_a) {
|
|
16792
|
+
filename = value;
|
|
16793
|
+
}
|
|
16794
|
+
}
|
|
16795
|
+
}
|
|
16796
|
+
if (!isBase64) {
|
|
16797
|
+
return null;
|
|
16798
|
+
}
|
|
16799
|
+
try {
|
|
16800
|
+
const buffer = Buffer.from(payload, 'base64');
|
|
16801
|
+
return {
|
|
16802
|
+
buffer,
|
|
16803
|
+
filename,
|
|
16804
|
+
mimeType: mediaType,
|
|
16805
|
+
};
|
|
16806
|
+
}
|
|
16807
|
+
catch (_b) {
|
|
16808
|
+
return null;
|
|
16809
|
+
}
|
|
16810
|
+
}
|
|
16811
|
+
/**
|
|
16812
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
16813
|
+
*/
|
|
16814
|
+
|
|
16670
16815
|
/**
|
|
16671
16816
|
* KNOWLEDGE commitment definition
|
|
16672
16817
|
*
|
|
@@ -16765,9 +16910,13 @@
|
|
|
16765
16910
|
return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
|
|
16766
16911
|
}
|
|
16767
16912
|
else {
|
|
16768
|
-
|
|
16769
|
-
const
|
|
16770
|
-
|
|
16913
|
+
const inlineSource = createInlineKnowledgeSourceFile(trimmedContent);
|
|
16914
|
+
const updatedRequirements = {
|
|
16915
|
+
...requirements,
|
|
16916
|
+
knowledgeSources: [...(requirements.knowledgeSources || []), inlineSource.url],
|
|
16917
|
+
};
|
|
16918
|
+
const knowledgeInfo = `Knowledge Source Inline: ${inlineSource.filename} (derived from inline content and processed for retrieval during chat)`;
|
|
16919
|
+
return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
|
|
16771
16920
|
}
|
|
16772
16921
|
}
|
|
16773
16922
|
}
|
|
@@ -17014,16 +17163,16 @@
|
|
|
17014
17163
|
// and typically doesn't need to be added to the system prompt or model requirements directly.
|
|
17015
17164
|
// It is extracted separately for the chat interface.
|
|
17016
17165
|
var _a;
|
|
17017
|
-
const pendingUserMessage = (_a = requirements.
|
|
17166
|
+
const pendingUserMessage = (_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
|
|
17018
17167
|
if (pendingUserMessage) {
|
|
17019
17168
|
const newSample = { question: pendingUserMessage, answer: content };
|
|
17020
17169
|
const newSamples = [...(requirements.samples || []), newSample];
|
|
17021
|
-
const newMetadata = { ...requirements.
|
|
17170
|
+
const newMetadata = { ...requirements._metadata };
|
|
17022
17171
|
delete newMetadata.pendingUserMessage;
|
|
17023
17172
|
return {
|
|
17024
17173
|
...requirements,
|
|
17025
17174
|
samples: newSamples,
|
|
17026
|
-
|
|
17175
|
+
_metadata: newMetadata,
|
|
17027
17176
|
};
|
|
17028
17177
|
}
|
|
17029
17178
|
return requirements;
|
|
@@ -17271,8 +17420,8 @@
|
|
|
17271
17420
|
applyToAgentModelRequirements(requirements, content) {
|
|
17272
17421
|
return {
|
|
17273
17422
|
...requirements,
|
|
17274
|
-
|
|
17275
|
-
...requirements.
|
|
17423
|
+
_metadata: {
|
|
17424
|
+
...requirements._metadata,
|
|
17276
17425
|
pendingUserMessage: content,
|
|
17277
17426
|
},
|
|
17278
17427
|
};
|
|
@@ -18130,11 +18279,7 @@
|
|
|
18130
18279
|
if (trimmedContent === '') {
|
|
18131
18280
|
return requirements;
|
|
18132
18281
|
}
|
|
18133
|
-
|
|
18134
|
-
return {
|
|
18135
|
-
...requirements,
|
|
18136
|
-
notes: [...(requirements.notes || []), trimmedContent],
|
|
18137
|
-
};
|
|
18282
|
+
return requirements;
|
|
18138
18283
|
}
|
|
18139
18284
|
}
|
|
18140
18285
|
/**
|
|
@@ -18196,12 +18341,12 @@
|
|
|
18196
18341
|
// Since OPEN is default, we can just ensure isClosed is false
|
|
18197
18342
|
// But to be explicit we can set it
|
|
18198
18343
|
const updatedMetadata = {
|
|
18199
|
-
...requirements.
|
|
18344
|
+
...requirements._metadata,
|
|
18200
18345
|
isClosed: false,
|
|
18201
18346
|
};
|
|
18202
18347
|
return {
|
|
18203
18348
|
...requirements,
|
|
18204
|
-
|
|
18349
|
+
_metadata: updatedMetadata,
|
|
18205
18350
|
};
|
|
18206
18351
|
}
|
|
18207
18352
|
}
|
|
@@ -18282,7 +18427,7 @@
|
|
|
18282
18427
|
return requirements;
|
|
18283
18428
|
}
|
|
18284
18429
|
// Get existing persona content from metadata
|
|
18285
|
-
const existingPersonaContent = ((_a = requirements.
|
|
18430
|
+
const existingPersonaContent = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.PERSONA) || '';
|
|
18286
18431
|
// Merge the new content with existing persona content
|
|
18287
18432
|
// When multiple PERSONA commitments exist, they are merged into one
|
|
18288
18433
|
const mergedPersonaContent = existingPersonaContent
|
|
@@ -18290,12 +18435,12 @@
|
|
|
18290
18435
|
: trimmedContent;
|
|
18291
18436
|
// Store the merged persona content in metadata for debugging and inspection
|
|
18292
18437
|
const updatedMetadata = {
|
|
18293
|
-
...requirements.
|
|
18438
|
+
...requirements._metadata,
|
|
18294
18439
|
PERSONA: mergedPersonaContent,
|
|
18295
18440
|
};
|
|
18296
18441
|
// Get the agent name from metadata (which should contain the first line of agent source)
|
|
18297
18442
|
// If not available, extract from current system message as fallback
|
|
18298
|
-
let agentName = (_b = requirements.
|
|
18443
|
+
let agentName = (_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.agentName;
|
|
18299
18444
|
if (!agentName) {
|
|
18300
18445
|
// Fallback: extract from current system message
|
|
18301
18446
|
const currentMessage = requirements.systemMessage.trim();
|
|
@@ -18342,7 +18487,7 @@
|
|
|
18342
18487
|
return {
|
|
18343
18488
|
...requirements,
|
|
18344
18489
|
systemMessage: newSystemMessage,
|
|
18345
|
-
|
|
18490
|
+
_metadata: updatedMetadata,
|
|
18346
18491
|
};
|
|
18347
18492
|
}
|
|
18348
18493
|
}
|
|
@@ -18425,7 +18570,16 @@
|
|
|
18425
18570
|
}
|
|
18426
18571
|
// Add rule to the system message
|
|
18427
18572
|
const ruleSection = `Rule: ${trimmedContent}`;
|
|
18428
|
-
|
|
18573
|
+
const requirementsWithRule = this.appendToSystemMessage(requirements, ruleSection, '\n\n');
|
|
18574
|
+
const ruleLines = trimmedContent
|
|
18575
|
+
.split(/\r?\n/)
|
|
18576
|
+
.map((line) => line.trim())
|
|
18577
|
+
.filter(Boolean)
|
|
18578
|
+
.map((line) => `- ${line}`);
|
|
18579
|
+
if (ruleLines.length === 0) {
|
|
18580
|
+
return requirementsWithRule;
|
|
18581
|
+
}
|
|
18582
|
+
return this.appendToPromptSuffix(requirementsWithRule, ruleLines.join('\n'));
|
|
18429
18583
|
}
|
|
18430
18584
|
}
|
|
18431
18585
|
/**
|
|
@@ -18931,7 +19085,7 @@
|
|
|
18931
19085
|
if (teammates.length === 0) {
|
|
18932
19086
|
return requirements;
|
|
18933
19087
|
}
|
|
18934
|
-
const agentName = ((_a = requirements.
|
|
19088
|
+
const agentName = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.agentName) || 'Agent';
|
|
18935
19089
|
const teamEntries = teammates.map((teammate) => ({
|
|
18936
19090
|
toolName: createTeamToolName(teammate.url),
|
|
18937
19091
|
teammate,
|
|
@@ -18971,7 +19125,7 @@
|
|
|
18971
19125
|
},
|
|
18972
19126
|
});
|
|
18973
19127
|
}
|
|
18974
|
-
const existingTeammates = ((_b = requirements.
|
|
19128
|
+
const existingTeammates = ((_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.teammates) || [];
|
|
18975
19129
|
const updatedTeammates = [...existingTeammates];
|
|
18976
19130
|
for (const entry of teamEntries) {
|
|
18977
19131
|
if (updatedTeammates.some((existing) => existing.url === entry.teammate.url)) {
|
|
@@ -19000,8 +19154,8 @@
|
|
|
19000
19154
|
return this.appendToSystemMessage({
|
|
19001
19155
|
...requirements,
|
|
19002
19156
|
tools: updatedTools,
|
|
19003
|
-
|
|
19004
|
-
...requirements.
|
|
19157
|
+
_metadata: {
|
|
19158
|
+
...requirements._metadata,
|
|
19005
19159
|
teammates: updatedTeammates,
|
|
19006
19160
|
},
|
|
19007
19161
|
}, teamSystemMessage);
|
|
@@ -19233,7 +19387,7 @@
|
|
|
19233
19387
|
if (!trimmedContent) {
|
|
19234
19388
|
// Store template mode flag in metadata
|
|
19235
19389
|
const updatedMetadata = {
|
|
19236
|
-
...requirements.
|
|
19390
|
+
...requirements._metadata,
|
|
19237
19391
|
templateMode: true,
|
|
19238
19392
|
};
|
|
19239
19393
|
// Add a general instruction about using structured templates
|
|
@@ -19243,21 +19397,21 @@
|
|
|
19243
19397
|
`);
|
|
19244
19398
|
return {
|
|
19245
19399
|
...this.appendToSystemMessage(requirements, templateModeInstruction, '\n\n'),
|
|
19246
|
-
|
|
19400
|
+
_metadata: updatedMetadata,
|
|
19247
19401
|
};
|
|
19248
19402
|
}
|
|
19249
19403
|
// If content is provided, add the specific template instructions
|
|
19250
19404
|
const templateSection = `Response Template: ${trimmedContent}`;
|
|
19251
19405
|
// Store the template in metadata for potential programmatic access
|
|
19252
|
-
const existingTemplates = ((_a = requirements.
|
|
19406
|
+
const existingTemplates = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.templates) || [];
|
|
19253
19407
|
const updatedMetadata = {
|
|
19254
|
-
...requirements.
|
|
19408
|
+
...requirements._metadata,
|
|
19255
19409
|
templates: [...existingTemplates, trimmedContent],
|
|
19256
19410
|
templateMode: true,
|
|
19257
19411
|
};
|
|
19258
19412
|
return {
|
|
19259
19413
|
...this.appendToSystemMessage(requirements, templateSection, '\n\n'),
|
|
19260
|
-
|
|
19414
|
+
_metadata: updatedMetadata,
|
|
19261
19415
|
};
|
|
19262
19416
|
}
|
|
19263
19417
|
}
|
|
@@ -19594,8 +19748,8 @@
|
|
|
19594
19748
|
return this.appendToSystemMessage({
|
|
19595
19749
|
...requirements,
|
|
19596
19750
|
tools: updatedTools,
|
|
19597
|
-
|
|
19598
|
-
...requirements.
|
|
19751
|
+
_metadata: {
|
|
19752
|
+
...requirements._metadata,
|
|
19599
19753
|
useBrowser: true,
|
|
19600
19754
|
},
|
|
19601
19755
|
}, spaceTrim$1.spaceTrim(`
|
|
@@ -19824,8 +19978,8 @@
|
|
|
19824
19978
|
return this.appendToSystemMessage({
|
|
19825
19979
|
...requirements,
|
|
19826
19980
|
tools: updatedTools,
|
|
19827
|
-
|
|
19828
|
-
...requirements.
|
|
19981
|
+
_metadata: {
|
|
19982
|
+
...requirements._metadata,
|
|
19829
19983
|
useEmail: content || true,
|
|
19830
19984
|
},
|
|
19831
19985
|
}, spaceTrim$1.spaceTrim((block) => `
|
|
@@ -19960,8 +20114,8 @@
|
|
|
19960
20114
|
return this.appendToSystemMessage({
|
|
19961
20115
|
...requirements,
|
|
19962
20116
|
tools: updatedTools,
|
|
19963
|
-
|
|
19964
|
-
...requirements.
|
|
20117
|
+
_metadata: {
|
|
20118
|
+
...requirements._metadata,
|
|
19965
20119
|
useImageGenerator: content || true,
|
|
19966
20120
|
},
|
|
19967
20121
|
}, spaceTrim$1.spaceTrim(`
|
|
@@ -20252,8 +20406,8 @@
|
|
|
20252
20406
|
return this.appendToSystemMessage({
|
|
20253
20407
|
...requirements,
|
|
20254
20408
|
tools: updatedTools,
|
|
20255
|
-
|
|
20256
|
-
...requirements.
|
|
20409
|
+
_metadata: {
|
|
20410
|
+
...requirements._metadata,
|
|
20257
20411
|
useSearchEngine: content || true,
|
|
20258
20412
|
},
|
|
20259
20413
|
}, spaceTrim$1.spaceTrim((block) => `
|
|
@@ -20401,8 +20555,8 @@
|
|
|
20401
20555
|
return this.appendToSystemMessage({
|
|
20402
20556
|
...requirements,
|
|
20403
20557
|
tools: updatedTools,
|
|
20404
|
-
|
|
20405
|
-
...requirements.
|
|
20558
|
+
_metadata: {
|
|
20559
|
+
...requirements._metadata,
|
|
20406
20560
|
},
|
|
20407
20561
|
}, spaceTrim$1.spaceTrim((block) => `
|
|
20408
20562
|
Time and date context:
|
|
@@ -24980,6 +25134,66 @@
|
|
|
24980
25134
|
},
|
|
24981
25135
|
/**/
|
|
24982
25136
|
/**/
|
|
25137
|
+
{
|
|
25138
|
+
modelVariant: 'CHAT',
|
|
25139
|
+
modelTitle: 'gpt-5.2-codex',
|
|
25140
|
+
modelName: 'gpt-5.2-codex',
|
|
25141
|
+
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.',
|
|
25142
|
+
pricing: {
|
|
25143
|
+
prompt: pricing(`$1.75 / 1M tokens`),
|
|
25144
|
+
output: pricing(`$14.00 / 1M tokens`),
|
|
25145
|
+
},
|
|
25146
|
+
},
|
|
25147
|
+
/**/
|
|
25148
|
+
/**/
|
|
25149
|
+
{
|
|
25150
|
+
modelVariant: 'CHAT',
|
|
25151
|
+
modelTitle: 'gpt-5.1-codex-max',
|
|
25152
|
+
modelName: 'gpt-5.1-codex-max',
|
|
25153
|
+
modelDescription: 'Premium GPT-5.1 Codex flavor that mirrors gpt-5.1 in capability and pricing while adding Codex tooling optimizations.',
|
|
25154
|
+
pricing: {
|
|
25155
|
+
prompt: pricing(`$1.25 / 1M tokens`),
|
|
25156
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
25157
|
+
},
|
|
25158
|
+
},
|
|
25159
|
+
/**/
|
|
25160
|
+
/**/
|
|
25161
|
+
{
|
|
25162
|
+
modelVariant: 'CHAT',
|
|
25163
|
+
modelTitle: 'gpt-5.1-codex',
|
|
25164
|
+
modelName: 'gpt-5.1-codex',
|
|
25165
|
+
modelDescription: 'Core GPT-5.1 Codex model focused on agentic coding tasks with a balanced trade-off between reasoning and cost.',
|
|
25166
|
+
pricing: {
|
|
25167
|
+
prompt: pricing(`$1.25 / 1M tokens`),
|
|
25168
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
25169
|
+
},
|
|
25170
|
+
},
|
|
25171
|
+
/**/
|
|
25172
|
+
/**/
|
|
25173
|
+
{
|
|
25174
|
+
modelVariant: 'CHAT',
|
|
25175
|
+
modelTitle: 'gpt-5.1-codex-mini',
|
|
25176
|
+
modelName: 'gpt-5.1-codex-mini',
|
|
25177
|
+
modelDescription: 'Compact, cost-effective GPT-5.1 Codex variant with a smaller context window ideal for cheap assistant iterations that still require coding awareness.',
|
|
25178
|
+
pricing: {
|
|
25179
|
+
prompt: pricing(`$0.25 / 1M tokens`),
|
|
25180
|
+
output: pricing(`$2.00 / 1M tokens`),
|
|
25181
|
+
},
|
|
25182
|
+
},
|
|
25183
|
+
/**/
|
|
25184
|
+
/**/
|
|
25185
|
+
{
|
|
25186
|
+
modelVariant: 'CHAT',
|
|
25187
|
+
modelTitle: 'gpt-5-codex',
|
|
25188
|
+
modelName: 'gpt-5-codex',
|
|
25189
|
+
modelDescription: 'Legacy GPT-5 Codex model built for agentic coding workloads with the same pricing as GPT-5 and a focus on stability.',
|
|
25190
|
+
pricing: {
|
|
25191
|
+
prompt: pricing(`$1.25 / 1M tokens`),
|
|
25192
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
25193
|
+
},
|
|
25194
|
+
},
|
|
25195
|
+
/**/
|
|
25196
|
+
/**/
|
|
24983
25197
|
{
|
|
24984
25198
|
modelVariant: 'CHAT',
|
|
24985
25199
|
modelTitle: 'gpt-5-mini',
|
|
@@ -27008,6 +27222,32 @@
|
|
|
27008
27222
|
errorMessage.includes('does not support'));
|
|
27009
27223
|
}
|
|
27010
27224
|
|
|
27225
|
+
/**
|
|
27226
|
+
* Provides access to the structured clone implementation when available.
|
|
27227
|
+
*/
|
|
27228
|
+
function getStructuredCloneFunction() {
|
|
27229
|
+
return globalThis.structuredClone;
|
|
27230
|
+
}
|
|
27231
|
+
/**
|
|
27232
|
+
* Checks whether the prompt is a chat prompt that carries file attachments.
|
|
27233
|
+
*/
|
|
27234
|
+
function hasChatPromptFiles(prompt) {
|
|
27235
|
+
return 'files' in prompt && Array.isArray(prompt.files);
|
|
27236
|
+
}
|
|
27237
|
+
/**
|
|
27238
|
+
* Creates a deep copy of the prompt while keeping attached files intact when structured clone is not available.
|
|
27239
|
+
*/
|
|
27240
|
+
function clonePromptPreservingFiles(prompt) {
|
|
27241
|
+
const structuredCloneFn = getStructuredCloneFunction();
|
|
27242
|
+
if (typeof structuredCloneFn === 'function') {
|
|
27243
|
+
return structuredCloneFn(prompt);
|
|
27244
|
+
}
|
|
27245
|
+
const clonedPrompt = JSON.parse(JSON.stringify(prompt));
|
|
27246
|
+
if (hasChatPromptFiles(prompt)) {
|
|
27247
|
+
clonedPrompt.files = prompt.files;
|
|
27248
|
+
}
|
|
27249
|
+
return clonedPrompt;
|
|
27250
|
+
}
|
|
27011
27251
|
/**
|
|
27012
27252
|
* Execution Tools for calling OpenAI API or other OpenAI compatible provider
|
|
27013
27253
|
*
|
|
@@ -27092,7 +27332,7 @@
|
|
|
27092
27332
|
*/
|
|
27093
27333
|
async callChatModelStream(prompt, onProgress) {
|
|
27094
27334
|
// Deep clone prompt and modelRequirements to avoid mutation across calls
|
|
27095
|
-
const clonedPrompt =
|
|
27335
|
+
const clonedPrompt = clonePromptPreservingFiles(prompt);
|
|
27096
27336
|
// Use local Set for retried parameters to ensure independence and thread safety
|
|
27097
27337
|
const retriedUnsupportedParameters = new Set();
|
|
27098
27338
|
return this.callChatModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters, onProgress);
|
|
@@ -27119,7 +27359,10 @@
|
|
|
27119
27359
|
// <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
|
|
27120
27360
|
// <- Note: [🧆]
|
|
27121
27361
|
}; // <- TODO: [💩] Guard here types better
|
|
27122
|
-
if (
|
|
27362
|
+
if (currentModelRequirements.responseFormat !== undefined) {
|
|
27363
|
+
modelSettings.response_format = currentModelRequirements.responseFormat;
|
|
27364
|
+
}
|
|
27365
|
+
else if (format === 'JSON') {
|
|
27123
27366
|
modelSettings.response_format = {
|
|
27124
27367
|
type: 'json_object',
|
|
27125
27368
|
};
|
|
@@ -29097,7 +29340,9 @@
|
|
|
29097
29340
|
const processingStartedAtMs = Date.now();
|
|
29098
29341
|
for (const [index, source] of knowledgeSources.entries()) {
|
|
29099
29342
|
try {
|
|
29100
|
-
const
|
|
29343
|
+
const isDataUrl = isDataUrlKnowledgeSource(source);
|
|
29344
|
+
const isHttp = source.startsWith('http://') || source.startsWith('https://');
|
|
29345
|
+
const sourceType = isDataUrl ? 'data_url' : isHttp ? 'url' : 'file';
|
|
29101
29346
|
if (this.options.isVerbose) {
|
|
29102
29347
|
console.info('[🤰]', 'Processing knowledge source', {
|
|
29103
29348
|
index: index + 1,
|
|
@@ -29107,8 +29352,27 @@
|
|
|
29107
29352
|
logLabel,
|
|
29108
29353
|
});
|
|
29109
29354
|
}
|
|
29110
|
-
|
|
29111
|
-
|
|
29355
|
+
if (isDataUrl) {
|
|
29356
|
+
const parsed = parseDataUrlKnowledgeSource(source);
|
|
29357
|
+
if (!parsed) {
|
|
29358
|
+
skippedSources.push({ source, reason: 'invalid_data_url' });
|
|
29359
|
+
if (this.options.isVerbose) {
|
|
29360
|
+
console.info('[🤰]', 'Skipping knowledge source (invalid data URL)', {
|
|
29361
|
+
source,
|
|
29362
|
+
sourceType,
|
|
29363
|
+
logLabel,
|
|
29364
|
+
});
|
|
29365
|
+
}
|
|
29366
|
+
continue;
|
|
29367
|
+
}
|
|
29368
|
+
const dataUrlFile = new File([parsed.buffer], parsed.filename, {
|
|
29369
|
+
type: parsed.mimeType,
|
|
29370
|
+
});
|
|
29371
|
+
fileStreams.push(dataUrlFile);
|
|
29372
|
+
totalBytes += parsed.buffer.length;
|
|
29373
|
+
continue;
|
|
29374
|
+
}
|
|
29375
|
+
if (isHttp) {
|
|
29112
29376
|
const downloadResult = await this.downloadKnowledgeSourceFile({
|
|
29113
29377
|
source,
|
|
29114
29378
|
timeoutMs: downloadTimeoutMs,
|
|
@@ -30993,11 +31257,14 @@
|
|
|
30993
31257
|
function createEmptyAgentModelRequirements() {
|
|
30994
31258
|
return {
|
|
30995
31259
|
systemMessage: '',
|
|
31260
|
+
promptSuffix: '',
|
|
30996
31261
|
// modelName: 'gpt-5',
|
|
30997
31262
|
modelName: 'gemini-2.5-flash-lite',
|
|
30998
31263
|
temperature: 0.7,
|
|
30999
31264
|
topP: 0.9,
|
|
31000
31265
|
topK: 50,
|
|
31266
|
+
parentAgentUrl: null,
|
|
31267
|
+
isClosed: false,
|
|
31001
31268
|
};
|
|
31002
31269
|
}
|
|
31003
31270
|
/**
|
|
@@ -31431,8 +31698,8 @@
|
|
|
31431
31698
|
// Store the agent name in metadata so commitments can access it
|
|
31432
31699
|
requirements = {
|
|
31433
31700
|
...requirements,
|
|
31434
|
-
|
|
31435
|
-
...requirements.
|
|
31701
|
+
_metadata: {
|
|
31702
|
+
...requirements._metadata,
|
|
31436
31703
|
agentName: parseResult.agentName,
|
|
31437
31704
|
},
|
|
31438
31705
|
};
|
|
@@ -32682,6 +32949,64 @@
|
|
|
32682
32949
|
*/
|
|
32683
32950
|
|
|
32684
32951
|
const DEFAULT_AGENT_KIT_MODEL_NAME = 'gpt-5.2';
|
|
32952
|
+
const DEFAULT_JSON_SCHEMA_NAME = 'StructuredOutput';
|
|
32953
|
+
/*
|
|
32954
|
+
TODO: Use or remove
|
|
32955
|
+
const EMPTY_JSON_SCHEMA: JsonSchemaDefinition['schema'] = {
|
|
32956
|
+
type: 'object',
|
|
32957
|
+
properties: {},
|
|
32958
|
+
required: [],
|
|
32959
|
+
additionalProperties: true,
|
|
32960
|
+
};
|
|
32961
|
+
*/
|
|
32962
|
+
function buildJsonSchemaDefinition(jsonSchema) {
|
|
32963
|
+
var _a, _b, _c;
|
|
32964
|
+
const schema = (_a = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.schema) !== null && _a !== void 0 ? _a : {};
|
|
32965
|
+
return {
|
|
32966
|
+
type: 'json_schema',
|
|
32967
|
+
name: (_b = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.name) !== null && _b !== void 0 ? _b : DEFAULT_JSON_SCHEMA_NAME,
|
|
32968
|
+
strict: Boolean(jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.strict),
|
|
32969
|
+
schema: {
|
|
32970
|
+
type: 'object',
|
|
32971
|
+
properties: ((_c = schema.properties) !== null && _c !== void 0 ? _c : {}),
|
|
32972
|
+
required: Array.isArray(schema.required) ? schema.required : [],
|
|
32973
|
+
additionalProperties: schema.additionalProperties === undefined ? true : Boolean(schema.additionalProperties),
|
|
32974
|
+
description: schema.description,
|
|
32975
|
+
},
|
|
32976
|
+
};
|
|
32977
|
+
}
|
|
32978
|
+
/**
|
|
32979
|
+
* Maps OpenAI `response_format` payloads to AgentKit output types so the runner can forward
|
|
32980
|
+
* structured-output preferences to OpenAI while still reusing the same AgentKit agent instance.
|
|
32981
|
+
*
|
|
32982
|
+
* @param responseFormat - The OpenAI `response_format` payload from the user request.
|
|
32983
|
+
* @returns An Agent output type compatible with the requested schema or `undefined` when no impact is required.
|
|
32984
|
+
* @private utility of Open AI
|
|
32985
|
+
*/
|
|
32986
|
+
function mapResponseFormatToAgentOutputType(responseFormat) {
|
|
32987
|
+
if (!responseFormat) {
|
|
32988
|
+
return undefined;
|
|
32989
|
+
}
|
|
32990
|
+
if (typeof responseFormat === 'string') {
|
|
32991
|
+
if (responseFormat === 'text') {
|
|
32992
|
+
return 'text';
|
|
32993
|
+
}
|
|
32994
|
+
if (responseFormat === 'json_schema' || responseFormat === 'json_object') {
|
|
32995
|
+
return buildJsonSchemaDefinition();
|
|
32996
|
+
}
|
|
32997
|
+
return 'text';
|
|
32998
|
+
}
|
|
32999
|
+
switch (responseFormat.type) {
|
|
33000
|
+
case 'text':
|
|
33001
|
+
return 'text';
|
|
33002
|
+
case 'json_schema':
|
|
33003
|
+
return buildJsonSchemaDefinition(responseFormat.json_schema);
|
|
33004
|
+
case 'json_object':
|
|
33005
|
+
return buildJsonSchemaDefinition();
|
|
33006
|
+
default:
|
|
33007
|
+
return undefined;
|
|
33008
|
+
}
|
|
33009
|
+
}
|
|
32685
33010
|
/**
|
|
32686
33011
|
* Execution tools for OpenAI AgentKit (Agents SDK).
|
|
32687
33012
|
*
|
|
@@ -32729,6 +33054,7 @@
|
|
|
32729
33054
|
...parameters,
|
|
32730
33055
|
modelName: this.agentKitModelName,
|
|
32731
33056
|
});
|
|
33057
|
+
const responseFormatOutputType = mapResponseFormatToAgentOutputType(modelRequirements.responseFormat);
|
|
32732
33058
|
const preparedAgentKitAgent = await this.prepareAgentKitAgent({
|
|
32733
33059
|
name: (prompt.title || 'Agent'),
|
|
32734
33060
|
instructions: modelRequirements.systemMessage || '',
|
|
@@ -32740,6 +33066,7 @@
|
|
|
32740
33066
|
prompt,
|
|
32741
33067
|
rawPromptContent,
|
|
32742
33068
|
onProgress,
|
|
33069
|
+
responseFormatOutputType,
|
|
32743
33070
|
});
|
|
32744
33071
|
}
|
|
32745
33072
|
/**
|
|
@@ -32921,16 +33248,21 @@
|
|
|
32921
33248
|
...prompt.parameters,
|
|
32922
33249
|
modelName: this.agentKitModelName,
|
|
32923
33250
|
});
|
|
33251
|
+
const agentForRun = options.responseFormatOutputType !== undefined
|
|
33252
|
+
? openAiAgentKitAgent.clone({
|
|
33253
|
+
outputType: options.responseFormatOutputType,
|
|
33254
|
+
})
|
|
33255
|
+
: openAiAgentKitAgent;
|
|
32924
33256
|
const start = $getCurrentDate();
|
|
32925
33257
|
let latestContent = '';
|
|
32926
33258
|
const toolCalls = [];
|
|
32927
33259
|
const toolCallIndexById = new Map();
|
|
32928
33260
|
const inputItems = await this.buildAgentKitInputItems(prompt, rawPromptContent);
|
|
32929
33261
|
const rawRequest = {
|
|
32930
|
-
agentName:
|
|
33262
|
+
agentName: agentForRun.name,
|
|
32931
33263
|
input: inputItems,
|
|
32932
33264
|
};
|
|
32933
|
-
const streamResult = await agents.run(
|
|
33265
|
+
const streamResult = await agents.run(agentForRun, inputItems, {
|
|
32934
33266
|
stream: true,
|
|
32935
33267
|
context: { parameters: prompt.parameters },
|
|
32936
33268
|
});
|
|
@@ -33278,22 +33610,28 @@
|
|
|
33278
33610
|
throw new Error('AgentLlmExecutionTools only supports chat prompts');
|
|
33279
33611
|
}
|
|
33280
33612
|
const modelRequirements = await this.getModelRequirements();
|
|
33613
|
+
const { _metadata, promptSuffix, ...sanitizedRequirements } = modelRequirements;
|
|
33281
33614
|
const chatPrompt = prompt;
|
|
33282
33615
|
let underlyingLlmResult;
|
|
33283
|
-
|
|
33616
|
+
const chatPromptContentWithSuffix = promptSuffix
|
|
33617
|
+
? `${chatPrompt.content}\n\n${promptSuffix}`
|
|
33618
|
+
: chatPrompt.content;
|
|
33284
33619
|
const promptWithAgentModelRequirements = {
|
|
33285
33620
|
...chatPrompt,
|
|
33621
|
+
content: chatPromptContentWithSuffix,
|
|
33286
33622
|
modelRequirements: {
|
|
33287
33623
|
...chatPrompt.modelRequirements,
|
|
33288
|
-
...
|
|
33624
|
+
...sanitizedRequirements,
|
|
33289
33625
|
// Spread tools to convert readonly array to mutable
|
|
33290
|
-
tools:
|
|
33626
|
+
tools: sanitizedRequirements.tools
|
|
33627
|
+
? [...sanitizedRequirements.tools]
|
|
33628
|
+
: chatPrompt.modelRequirements.tools,
|
|
33291
33629
|
// Spread knowledgeSources to convert readonly array to mutable
|
|
33292
|
-
knowledgeSources:
|
|
33293
|
-
? [...
|
|
33630
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources
|
|
33631
|
+
? [...sanitizedRequirements.knowledgeSources]
|
|
33294
33632
|
: undefined,
|
|
33295
33633
|
// Prepend agent system message to existing system message
|
|
33296
|
-
systemMessage:
|
|
33634
|
+
systemMessage: sanitizedRequirements.systemMessage +
|
|
33297
33635
|
(chatPrompt.modelRequirements.systemMessage
|
|
33298
33636
|
? `\n\n${chatPrompt.modelRequirements.systemMessage}`
|
|
33299
33637
|
: ''),
|
|
@@ -33301,8 +33639,8 @@
|
|
|
33301
33639
|
};
|
|
33302
33640
|
console.log('!!!! promptWithAgentModelRequirements:', promptWithAgentModelRequirements);
|
|
33303
33641
|
if (OpenAiAgentKitExecutionTools.isOpenAiAgentKitExecutionTools(this.options.llmTools)) {
|
|
33304
|
-
const requirementsHash = cryptoJs.SHA256(JSON.stringify(
|
|
33305
|
-
const vectorStoreHash = cryptoJs.SHA256(JSON.stringify((_a =
|
|
33642
|
+
const requirementsHash = cryptoJs.SHA256(JSON.stringify(sanitizedRequirements)).toString();
|
|
33643
|
+
const vectorStoreHash = cryptoJs.SHA256(JSON.stringify((_a = sanitizedRequirements.knowledgeSources) !== null && _a !== void 0 ? _a : [])).toString();
|
|
33306
33644
|
const cachedVectorStore = AgentLlmExecutionTools.vectorStoreCache.get(this.title);
|
|
33307
33645
|
const cachedAgentKit = AgentLlmExecutionTools.agentKitAgentCache.get(this.title);
|
|
33308
33646
|
let preparedAgentKit = this.options.assistantPreparationMode === 'external'
|
|
@@ -33329,7 +33667,7 @@
|
|
|
33329
33667
|
agent: this.title,
|
|
33330
33668
|
});
|
|
33331
33669
|
}
|
|
33332
|
-
if (!vectorStoreId && ((_b =
|
|
33670
|
+
if (!vectorStoreId && ((_b = sanitizedRequirements.knowledgeSources) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
33333
33671
|
emitAssistantPreparationProgress({
|
|
33334
33672
|
onProgress,
|
|
33335
33673
|
prompt,
|
|
@@ -33345,9 +33683,9 @@
|
|
|
33345
33683
|
});
|
|
33346
33684
|
preparedAgentKit = await this.options.llmTools.prepareAgentKitAgent({
|
|
33347
33685
|
name: this.title,
|
|
33348
|
-
instructions:
|
|
33349
|
-
knowledgeSources:
|
|
33350
|
-
tools:
|
|
33686
|
+
instructions: sanitizedRequirements.systemMessage || '',
|
|
33687
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources,
|
|
33688
|
+
tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
|
|
33351
33689
|
vectorStoreId,
|
|
33352
33690
|
});
|
|
33353
33691
|
}
|
|
@@ -33362,15 +33700,17 @@
|
|
|
33362
33700
|
requirementsHash,
|
|
33363
33701
|
vectorStoreId: preparedAgentKit.vectorStoreId,
|
|
33364
33702
|
});
|
|
33703
|
+
const responseFormatOutputType = mapResponseFormatToAgentOutputType(promptWithAgentModelRequirements.modelRequirements.responseFormat);
|
|
33365
33704
|
underlyingLlmResult = await this.options.llmTools.callChatModelStreamWithPreparedAgent({
|
|
33366
33705
|
openAiAgentKitAgent: preparedAgentKit.agent,
|
|
33367
33706
|
prompt: promptWithAgentModelRequirements,
|
|
33368
33707
|
onProgress,
|
|
33708
|
+
responseFormatOutputType,
|
|
33369
33709
|
});
|
|
33370
33710
|
}
|
|
33371
33711
|
else if (OpenAiAssistantExecutionTools.isOpenAiAssistantExecutionTools(this.options.llmTools)) {
|
|
33372
33712
|
// ... deprecated path ...
|
|
33373
|
-
const requirementsHash = cryptoJs.SHA256(JSON.stringify(
|
|
33713
|
+
const requirementsHash = cryptoJs.SHA256(JSON.stringify(sanitizedRequirements)).toString();
|
|
33374
33714
|
const cached = AgentLlmExecutionTools.assistantCache.get(this.title);
|
|
33375
33715
|
let assistant;
|
|
33376
33716
|
if (this.options.assistantPreparationMode === 'external') {
|
|
@@ -33412,9 +33752,9 @@
|
|
|
33412
33752
|
assistant = await this.options.llmTools.updateAssistant({
|
|
33413
33753
|
assistantId: cached.assistantId,
|
|
33414
33754
|
name: this.title,
|
|
33415
|
-
instructions:
|
|
33416
|
-
knowledgeSources:
|
|
33417
|
-
tools:
|
|
33755
|
+
instructions: sanitizedRequirements.systemMessage,
|
|
33756
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources,
|
|
33757
|
+
tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
|
|
33418
33758
|
});
|
|
33419
33759
|
AgentLlmExecutionTools.assistantCache.set(this.title, {
|
|
33420
33760
|
assistantId: assistant.assistantId,
|
|
@@ -33437,9 +33777,9 @@
|
|
|
33437
33777
|
});
|
|
33438
33778
|
assistant = await this.options.llmTools.createNewAssistant({
|
|
33439
33779
|
name: this.title,
|
|
33440
|
-
instructions:
|
|
33441
|
-
knowledgeSources:
|
|
33442
|
-
tools:
|
|
33780
|
+
instructions: sanitizedRequirements.systemMessage,
|
|
33781
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources,
|
|
33782
|
+
tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
|
|
33443
33783
|
/*
|
|
33444
33784
|
!!!
|
|
33445
33785
|
metadata: {
|
|
@@ -33481,13 +33821,19 @@
|
|
|
33481
33821
|
}
|
|
33482
33822
|
}
|
|
33483
33823
|
let content = underlyingLlmResult.content;
|
|
33484
|
-
|
|
33485
|
-
|
|
33486
|
-
|
|
33487
|
-
|
|
33824
|
+
if (typeof content === 'string') {
|
|
33825
|
+
// Note: Cleanup the AI artifacts from the content
|
|
33826
|
+
content = humanizeAiText(content);
|
|
33827
|
+
// Note: Make sure the content is Promptbook-like
|
|
33828
|
+
content = promptbookifyAiText(content);
|
|
33829
|
+
}
|
|
33830
|
+
else {
|
|
33831
|
+
// TODO: Maybe deep `humanizeAiText` + `promptbookifyAiText` inside of the object
|
|
33832
|
+
content = JSON.stringify(content);
|
|
33833
|
+
}
|
|
33488
33834
|
const agentResult = {
|
|
33489
33835
|
...underlyingLlmResult,
|
|
33490
|
-
content,
|
|
33836
|
+
content: content,
|
|
33491
33837
|
modelName: this.modelName,
|
|
33492
33838
|
};
|
|
33493
33839
|
return agentResult;
|
|
@@ -33676,7 +34022,6 @@
|
|
|
33676
34022
|
* Note: This method also implements the learning mechanism
|
|
33677
34023
|
*/
|
|
33678
34024
|
async callChatModelStream(prompt, onProgress) {
|
|
33679
|
-
var _a;
|
|
33680
34025
|
// [1] Check if the user is asking the same thing as in the samples
|
|
33681
34026
|
const modelRequirements = await this.getModelRequirements();
|
|
33682
34027
|
if (modelRequirements.samples) {
|
|
@@ -33724,7 +34069,7 @@
|
|
|
33724
34069
|
if (result.rawResponse && 'sample' in result.rawResponse) {
|
|
33725
34070
|
return result;
|
|
33726
34071
|
}
|
|
33727
|
-
if (
|
|
34072
|
+
if (modelRequirements.isClosed) {
|
|
33728
34073
|
return result;
|
|
33729
34074
|
}
|
|
33730
34075
|
// Note: [0] Notify start of self-learning
|