@promptbook/cli 0.110.0-7 → 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 +467 -107
- 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/AgentChip/AgentChip.d.ts +5 -1
- 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 +10 -1
- 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/utils/toolCalls/getToolCallIdentity.d.ts +10 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +467 -107
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -48,7 +48,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
48
48
|
* @generated
|
|
49
49
|
* @see https://github.com/webgptorg/promptbook
|
|
50
50
|
*/
|
|
51
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.110.0-
|
|
51
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.110.0-9';
|
|
52
52
|
/**
|
|
53
53
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
54
54
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -15828,6 +15828,28 @@ class BaseCommitmentDefinition {
|
|
|
15828
15828
|
return currentMessage + separator + content;
|
|
15829
15829
|
});
|
|
15830
15830
|
}
|
|
15831
|
+
/**
|
|
15832
|
+
* Helper method to create a new requirements object with updated prompt suffix
|
|
15833
|
+
*/
|
|
15834
|
+
updatePromptSuffix(requirements, contentUpdate) {
|
|
15835
|
+
const newSuffix = typeof contentUpdate === 'string' ? contentUpdate : contentUpdate(requirements.promptSuffix);
|
|
15836
|
+
return {
|
|
15837
|
+
...requirements,
|
|
15838
|
+
promptSuffix: newSuffix,
|
|
15839
|
+
};
|
|
15840
|
+
}
|
|
15841
|
+
/**
|
|
15842
|
+
* Helper method to append content to the prompt suffix
|
|
15843
|
+
* Default separator is a single newline for bullet lists.
|
|
15844
|
+
*/
|
|
15845
|
+
appendToPromptSuffix(requirements, content, separator = '\n') {
|
|
15846
|
+
return this.updatePromptSuffix(requirements, (currentSuffix) => {
|
|
15847
|
+
if (!currentSuffix.trim()) {
|
|
15848
|
+
return content;
|
|
15849
|
+
}
|
|
15850
|
+
return `${currentSuffix}${separator}${content}`;
|
|
15851
|
+
});
|
|
15852
|
+
}
|
|
15831
15853
|
/**
|
|
15832
15854
|
* Helper method to add a comment section to the system message
|
|
15833
15855
|
* Comments are lines starting with # that will be removed from the final system message
|
|
@@ -16005,13 +16027,9 @@ class ClosedCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
16005
16027
|
`);
|
|
16006
16028
|
}
|
|
16007
16029
|
applyToAgentModelRequirements(requirements, _content) {
|
|
16008
|
-
const updatedMetadata = {
|
|
16009
|
-
...requirements.metadata,
|
|
16010
|
-
isClosed: true,
|
|
16011
|
-
};
|
|
16012
16030
|
return {
|
|
16013
16031
|
...requirements,
|
|
16014
|
-
|
|
16032
|
+
isClosed: true,
|
|
16015
16033
|
};
|
|
16016
16034
|
}
|
|
16017
16035
|
}
|
|
@@ -16289,12 +16307,12 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
16289
16307
|
return requirements;
|
|
16290
16308
|
}
|
|
16291
16309
|
// Get existing dictionary entries from metadata
|
|
16292
|
-
const existingDictionary = ((_a = requirements.
|
|
16310
|
+
const existingDictionary = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
|
|
16293
16311
|
// Merge the new dictionary entry with existing entries
|
|
16294
16312
|
const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
|
|
16295
16313
|
// Store the merged dictionary in metadata for debugging and inspection
|
|
16296
16314
|
const updatedMetadata = {
|
|
16297
|
-
...requirements.
|
|
16315
|
+
...requirements._metadata,
|
|
16298
16316
|
DICTIONARY: mergedDictionary,
|
|
16299
16317
|
};
|
|
16300
16318
|
// Create the dictionary section for the system message
|
|
@@ -16302,7 +16320,7 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
16302
16320
|
const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
|
|
16303
16321
|
return {
|
|
16304
16322
|
...this.appendToSystemMessage(requirements, dictionarySection),
|
|
16305
|
-
|
|
16323
|
+
_metadata: updatedMetadata,
|
|
16306
16324
|
};
|
|
16307
16325
|
}
|
|
16308
16326
|
}
|
|
@@ -16442,10 +16460,7 @@ class FromCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
16442
16460
|
applyToAgentModelRequirements(requirements, content) {
|
|
16443
16461
|
const trimmedContent = content.trim();
|
|
16444
16462
|
if (!trimmedContent) {
|
|
16445
|
-
return
|
|
16446
|
-
...requirements,
|
|
16447
|
-
parentAgentUrl: undefined,
|
|
16448
|
-
};
|
|
16463
|
+
return requirements;
|
|
16449
16464
|
}
|
|
16450
16465
|
if (trimmedContent.toUpperCase() === 'VOID' ||
|
|
16451
16466
|
trimmedContent.toUpperCase() === 'NULL' ||
|
|
@@ -16659,6 +16674,136 @@ class ImportCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
16659
16674
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
16660
16675
|
*/
|
|
16661
16676
|
|
|
16677
|
+
/**
|
|
16678
|
+
* @@@
|
|
16679
|
+
*
|
|
16680
|
+
* @private thing of inline knowledge
|
|
16681
|
+
*/
|
|
16682
|
+
const INLINE_KNOWLEDGE_BASE_NAME = 'inline-knowledge';
|
|
16683
|
+
/**
|
|
16684
|
+
* @@@
|
|
16685
|
+
*
|
|
16686
|
+
* @private thing of inline knowledge
|
|
16687
|
+
*/
|
|
16688
|
+
const INLINE_KNOWLEDGE_EXTENSION = '.txt';
|
|
16689
|
+
/**
|
|
16690
|
+
* @@@
|
|
16691
|
+
*
|
|
16692
|
+
* @private thing of inline knowledge
|
|
16693
|
+
*/
|
|
16694
|
+
const DATA_URL_PREFIX = 'data:';
|
|
16695
|
+
/**
|
|
16696
|
+
* @@@
|
|
16697
|
+
*
|
|
16698
|
+
* @private thing of inline knowledge
|
|
16699
|
+
*/
|
|
16700
|
+
function getFirstNonEmptyLine(content) {
|
|
16701
|
+
const lines = content.split(/\r?\n/);
|
|
16702
|
+
for (const line of lines) {
|
|
16703
|
+
const trimmed = line.trim();
|
|
16704
|
+
if (trimmed) {
|
|
16705
|
+
return trimmed;
|
|
16706
|
+
}
|
|
16707
|
+
}
|
|
16708
|
+
return null;
|
|
16709
|
+
}
|
|
16710
|
+
/**
|
|
16711
|
+
* @@@
|
|
16712
|
+
*
|
|
16713
|
+
* @private thing of inline knowledge
|
|
16714
|
+
*/
|
|
16715
|
+
function deriveBaseFilename(content) {
|
|
16716
|
+
const firstLine = getFirstNonEmptyLine(content);
|
|
16717
|
+
if (!firstLine) {
|
|
16718
|
+
return INLINE_KNOWLEDGE_BASE_NAME;
|
|
16719
|
+
}
|
|
16720
|
+
const normalized = normalizeToKebabCase(firstLine);
|
|
16721
|
+
return normalized || INLINE_KNOWLEDGE_BASE_NAME;
|
|
16722
|
+
}
|
|
16723
|
+
/**
|
|
16724
|
+
* Creates a data URL that represents the inline knowledge content as a text file.
|
|
16725
|
+
*
|
|
16726
|
+
* @private thing of inline knowledge
|
|
16727
|
+
*/
|
|
16728
|
+
function createInlineKnowledgeSourceFile(content) {
|
|
16729
|
+
const trimmedContent = content.trim();
|
|
16730
|
+
const baseName = deriveBaseFilename(trimmedContent);
|
|
16731
|
+
const filename = `${baseName}${INLINE_KNOWLEDGE_EXTENSION}`;
|
|
16732
|
+
const mimeType = 'text/plain';
|
|
16733
|
+
const base64 = Buffer.from(trimmedContent, 'utf-8').toString('base64');
|
|
16734
|
+
const encodedFilename = encodeURIComponent(filename);
|
|
16735
|
+
const url = `${DATA_URL_PREFIX}${mimeType};name=${encodedFilename};charset=utf-8;base64,${base64}`;
|
|
16736
|
+
return {
|
|
16737
|
+
filename,
|
|
16738
|
+
mimeType,
|
|
16739
|
+
url,
|
|
16740
|
+
};
|
|
16741
|
+
}
|
|
16742
|
+
/**
|
|
16743
|
+
* Checks whether the provided source string is a data URL that can be decoded.
|
|
16744
|
+
*
|
|
16745
|
+
* @private thing of inline knowledge
|
|
16746
|
+
*/
|
|
16747
|
+
function isDataUrlKnowledgeSource(source) {
|
|
16748
|
+
return typeof source === 'string' && source.startsWith(DATA_URL_PREFIX);
|
|
16749
|
+
}
|
|
16750
|
+
/**
|
|
16751
|
+
* Parses a data URL-based knowledge source into its raw buffer, filename, and MIME type.
|
|
16752
|
+
*
|
|
16753
|
+
* @private thing of inline knowledge
|
|
16754
|
+
*/
|
|
16755
|
+
function parseDataUrlKnowledgeSource(source) {
|
|
16756
|
+
if (!isDataUrlKnowledgeSource(source)) {
|
|
16757
|
+
return null;
|
|
16758
|
+
}
|
|
16759
|
+
const commaIndex = source.indexOf(',');
|
|
16760
|
+
if (commaIndex === -1) {
|
|
16761
|
+
return null;
|
|
16762
|
+
}
|
|
16763
|
+
const header = source.slice(DATA_URL_PREFIX.length, commaIndex);
|
|
16764
|
+
const payload = source.slice(commaIndex + 1);
|
|
16765
|
+
const tokens = header.split(';');
|
|
16766
|
+
const mediaType = tokens[0] || 'text/plain';
|
|
16767
|
+
let filename = `${INLINE_KNOWLEDGE_BASE_NAME}${INLINE_KNOWLEDGE_EXTENSION}`;
|
|
16768
|
+
let isBase64 = false;
|
|
16769
|
+
for (let i = 1; i < tokens.length; i++) {
|
|
16770
|
+
const token = tokens[i];
|
|
16771
|
+
if (!token) {
|
|
16772
|
+
continue;
|
|
16773
|
+
}
|
|
16774
|
+
if (token.toLowerCase() === 'base64') {
|
|
16775
|
+
isBase64 = true;
|
|
16776
|
+
continue;
|
|
16777
|
+
}
|
|
16778
|
+
const [key, value] = token.split('=');
|
|
16779
|
+
if (key === 'name' && value !== undefined) {
|
|
16780
|
+
try {
|
|
16781
|
+
filename = decodeURIComponent(value);
|
|
16782
|
+
}
|
|
16783
|
+
catch (_a) {
|
|
16784
|
+
filename = value;
|
|
16785
|
+
}
|
|
16786
|
+
}
|
|
16787
|
+
}
|
|
16788
|
+
if (!isBase64) {
|
|
16789
|
+
return null;
|
|
16790
|
+
}
|
|
16791
|
+
try {
|
|
16792
|
+
const buffer = Buffer.from(payload, 'base64');
|
|
16793
|
+
return {
|
|
16794
|
+
buffer,
|
|
16795
|
+
filename,
|
|
16796
|
+
mimeType: mediaType,
|
|
16797
|
+
};
|
|
16798
|
+
}
|
|
16799
|
+
catch (_b) {
|
|
16800
|
+
return null;
|
|
16801
|
+
}
|
|
16802
|
+
}
|
|
16803
|
+
/**
|
|
16804
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
16805
|
+
*/
|
|
16806
|
+
|
|
16662
16807
|
/**
|
|
16663
16808
|
* KNOWLEDGE commitment definition
|
|
16664
16809
|
*
|
|
@@ -16757,9 +16902,13 @@ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
16757
16902
|
return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
|
|
16758
16903
|
}
|
|
16759
16904
|
else {
|
|
16760
|
-
|
|
16761
|
-
const
|
|
16762
|
-
|
|
16905
|
+
const inlineSource = createInlineKnowledgeSourceFile(trimmedContent);
|
|
16906
|
+
const updatedRequirements = {
|
|
16907
|
+
...requirements,
|
|
16908
|
+
knowledgeSources: [...(requirements.knowledgeSources || []), inlineSource.url],
|
|
16909
|
+
};
|
|
16910
|
+
const knowledgeInfo = `Knowledge Source Inline: ${inlineSource.filename} (derived from inline content and processed for retrieval during chat)`;
|
|
16911
|
+
return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
|
|
16763
16912
|
}
|
|
16764
16913
|
}
|
|
16765
16914
|
}
|
|
@@ -17006,16 +17155,16 @@ class AgentMessageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
17006
17155
|
// and typically doesn't need to be added to the system prompt or model requirements directly.
|
|
17007
17156
|
// It is extracted separately for the chat interface.
|
|
17008
17157
|
var _a;
|
|
17009
|
-
const pendingUserMessage = (_a = requirements.
|
|
17158
|
+
const pendingUserMessage = (_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
|
|
17010
17159
|
if (pendingUserMessage) {
|
|
17011
17160
|
const newSample = { question: pendingUserMessage, answer: content };
|
|
17012
17161
|
const newSamples = [...(requirements.samples || []), newSample];
|
|
17013
|
-
const newMetadata = { ...requirements.
|
|
17162
|
+
const newMetadata = { ...requirements._metadata };
|
|
17014
17163
|
delete newMetadata.pendingUserMessage;
|
|
17015
17164
|
return {
|
|
17016
17165
|
...requirements,
|
|
17017
17166
|
samples: newSamples,
|
|
17018
|
-
|
|
17167
|
+
_metadata: newMetadata,
|
|
17019
17168
|
};
|
|
17020
17169
|
}
|
|
17021
17170
|
return requirements;
|
|
@@ -17263,8 +17412,8 @@ class UserMessageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
17263
17412
|
applyToAgentModelRequirements(requirements, content) {
|
|
17264
17413
|
return {
|
|
17265
17414
|
...requirements,
|
|
17266
|
-
|
|
17267
|
-
...requirements.
|
|
17415
|
+
_metadata: {
|
|
17416
|
+
...requirements._metadata,
|
|
17268
17417
|
pendingUserMessage: content,
|
|
17269
17418
|
},
|
|
17270
17419
|
};
|
|
@@ -18122,11 +18271,7 @@ class NoteCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18122
18271
|
if (trimmedContent === '') {
|
|
18123
18272
|
return requirements;
|
|
18124
18273
|
}
|
|
18125
|
-
|
|
18126
|
-
return {
|
|
18127
|
-
...requirements,
|
|
18128
|
-
notes: [...(requirements.notes || []), trimmedContent],
|
|
18129
|
-
};
|
|
18274
|
+
return requirements;
|
|
18130
18275
|
}
|
|
18131
18276
|
}
|
|
18132
18277
|
/**
|
|
@@ -18188,12 +18333,12 @@ class OpenCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18188
18333
|
// Since OPEN is default, we can just ensure isClosed is false
|
|
18189
18334
|
// But to be explicit we can set it
|
|
18190
18335
|
const updatedMetadata = {
|
|
18191
|
-
...requirements.
|
|
18336
|
+
...requirements._metadata,
|
|
18192
18337
|
isClosed: false,
|
|
18193
18338
|
};
|
|
18194
18339
|
return {
|
|
18195
18340
|
...requirements,
|
|
18196
|
-
|
|
18341
|
+
_metadata: updatedMetadata,
|
|
18197
18342
|
};
|
|
18198
18343
|
}
|
|
18199
18344
|
}
|
|
@@ -18274,7 +18419,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18274
18419
|
return requirements;
|
|
18275
18420
|
}
|
|
18276
18421
|
// Get existing persona content from metadata
|
|
18277
|
-
const existingPersonaContent = ((_a = requirements.
|
|
18422
|
+
const existingPersonaContent = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.PERSONA) || '';
|
|
18278
18423
|
// Merge the new content with existing persona content
|
|
18279
18424
|
// When multiple PERSONA commitments exist, they are merged into one
|
|
18280
18425
|
const mergedPersonaContent = existingPersonaContent
|
|
@@ -18282,12 +18427,12 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18282
18427
|
: trimmedContent;
|
|
18283
18428
|
// Store the merged persona content in metadata for debugging and inspection
|
|
18284
18429
|
const updatedMetadata = {
|
|
18285
|
-
...requirements.
|
|
18430
|
+
...requirements._metadata,
|
|
18286
18431
|
PERSONA: mergedPersonaContent,
|
|
18287
18432
|
};
|
|
18288
18433
|
// Get the agent name from metadata (which should contain the first line of agent source)
|
|
18289
18434
|
// If not available, extract from current system message as fallback
|
|
18290
|
-
let agentName = (_b = requirements.
|
|
18435
|
+
let agentName = (_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.agentName;
|
|
18291
18436
|
if (!agentName) {
|
|
18292
18437
|
// Fallback: extract from current system message
|
|
18293
18438
|
const currentMessage = requirements.systemMessage.trim();
|
|
@@ -18334,7 +18479,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18334
18479
|
return {
|
|
18335
18480
|
...requirements,
|
|
18336
18481
|
systemMessage: newSystemMessage,
|
|
18337
|
-
|
|
18482
|
+
_metadata: updatedMetadata,
|
|
18338
18483
|
};
|
|
18339
18484
|
}
|
|
18340
18485
|
}
|
|
@@ -18417,7 +18562,16 @@ class RuleCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18417
18562
|
}
|
|
18418
18563
|
// Add rule to the system message
|
|
18419
18564
|
const ruleSection = `Rule: ${trimmedContent}`;
|
|
18420
|
-
|
|
18565
|
+
const requirementsWithRule = this.appendToSystemMessage(requirements, ruleSection, '\n\n');
|
|
18566
|
+
const ruleLines = trimmedContent
|
|
18567
|
+
.split(/\r?\n/)
|
|
18568
|
+
.map((line) => line.trim())
|
|
18569
|
+
.filter(Boolean)
|
|
18570
|
+
.map((line) => `- ${line}`);
|
|
18571
|
+
if (ruleLines.length === 0) {
|
|
18572
|
+
return requirementsWithRule;
|
|
18573
|
+
}
|
|
18574
|
+
return this.appendToPromptSuffix(requirementsWithRule, ruleLines.join('\n'));
|
|
18421
18575
|
}
|
|
18422
18576
|
}
|
|
18423
18577
|
/**
|
|
@@ -18923,7 +19077,7 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18923
19077
|
if (teammates.length === 0) {
|
|
18924
19078
|
return requirements;
|
|
18925
19079
|
}
|
|
18926
|
-
const agentName = ((_a = requirements.
|
|
19080
|
+
const agentName = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.agentName) || 'Agent';
|
|
18927
19081
|
const teamEntries = teammates.map((teammate) => ({
|
|
18928
19082
|
toolName: createTeamToolName(teammate.url),
|
|
18929
19083
|
teammate,
|
|
@@ -18963,7 +19117,7 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18963
19117
|
},
|
|
18964
19118
|
});
|
|
18965
19119
|
}
|
|
18966
|
-
const existingTeammates = ((_b = requirements.
|
|
19120
|
+
const existingTeammates = ((_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.teammates) || [];
|
|
18967
19121
|
const updatedTeammates = [...existingTeammates];
|
|
18968
19122
|
for (const entry of teamEntries) {
|
|
18969
19123
|
if (updatedTeammates.some((existing) => existing.url === entry.teammate.url)) {
|
|
@@ -18992,8 +19146,8 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
18992
19146
|
return this.appendToSystemMessage({
|
|
18993
19147
|
...requirements,
|
|
18994
19148
|
tools: updatedTools,
|
|
18995
|
-
|
|
18996
|
-
...requirements.
|
|
19149
|
+
_metadata: {
|
|
19150
|
+
...requirements._metadata,
|
|
18997
19151
|
teammates: updatedTeammates,
|
|
18998
19152
|
},
|
|
18999
19153
|
}, teamSystemMessage);
|
|
@@ -19225,7 +19379,7 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19225
19379
|
if (!trimmedContent) {
|
|
19226
19380
|
// Store template mode flag in metadata
|
|
19227
19381
|
const updatedMetadata = {
|
|
19228
|
-
...requirements.
|
|
19382
|
+
...requirements._metadata,
|
|
19229
19383
|
templateMode: true,
|
|
19230
19384
|
};
|
|
19231
19385
|
// Add a general instruction about using structured templates
|
|
@@ -19235,21 +19389,21 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19235
19389
|
`);
|
|
19236
19390
|
return {
|
|
19237
19391
|
...this.appendToSystemMessage(requirements, templateModeInstruction, '\n\n'),
|
|
19238
|
-
|
|
19392
|
+
_metadata: updatedMetadata,
|
|
19239
19393
|
};
|
|
19240
19394
|
}
|
|
19241
19395
|
// If content is provided, add the specific template instructions
|
|
19242
19396
|
const templateSection = `Response Template: ${trimmedContent}`;
|
|
19243
19397
|
// Store the template in metadata for potential programmatic access
|
|
19244
|
-
const existingTemplates = ((_a = requirements.
|
|
19398
|
+
const existingTemplates = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.templates) || [];
|
|
19245
19399
|
const updatedMetadata = {
|
|
19246
|
-
...requirements.
|
|
19400
|
+
...requirements._metadata,
|
|
19247
19401
|
templates: [...existingTemplates, trimmedContent],
|
|
19248
19402
|
templateMode: true,
|
|
19249
19403
|
};
|
|
19250
19404
|
return {
|
|
19251
19405
|
...this.appendToSystemMessage(requirements, templateSection, '\n\n'),
|
|
19252
|
-
|
|
19406
|
+
_metadata: updatedMetadata,
|
|
19253
19407
|
};
|
|
19254
19408
|
}
|
|
19255
19409
|
}
|
|
@@ -19586,8 +19740,8 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19586
19740
|
return this.appendToSystemMessage({
|
|
19587
19741
|
...requirements,
|
|
19588
19742
|
tools: updatedTools,
|
|
19589
|
-
|
|
19590
|
-
...requirements.
|
|
19743
|
+
_metadata: {
|
|
19744
|
+
...requirements._metadata,
|
|
19591
19745
|
useBrowser: true,
|
|
19592
19746
|
},
|
|
19593
19747
|
}, spaceTrim$1(`
|
|
@@ -19816,8 +19970,8 @@ class UseEmailCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19816
19970
|
return this.appendToSystemMessage({
|
|
19817
19971
|
...requirements,
|
|
19818
19972
|
tools: updatedTools,
|
|
19819
|
-
|
|
19820
|
-
...requirements.
|
|
19973
|
+
_metadata: {
|
|
19974
|
+
...requirements._metadata,
|
|
19821
19975
|
useEmail: content || true,
|
|
19822
19976
|
},
|
|
19823
19977
|
}, spaceTrim$1((block) => `
|
|
@@ -19952,8 +20106,8 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19952
20106
|
return this.appendToSystemMessage({
|
|
19953
20107
|
...requirements,
|
|
19954
20108
|
tools: updatedTools,
|
|
19955
|
-
|
|
19956
|
-
...requirements.
|
|
20109
|
+
_metadata: {
|
|
20110
|
+
...requirements._metadata,
|
|
19957
20111
|
useImageGenerator: content || true,
|
|
19958
20112
|
},
|
|
19959
20113
|
}, spaceTrim$1(`
|
|
@@ -20244,8 +20398,8 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
20244
20398
|
return this.appendToSystemMessage({
|
|
20245
20399
|
...requirements,
|
|
20246
20400
|
tools: updatedTools,
|
|
20247
|
-
|
|
20248
|
-
...requirements.
|
|
20401
|
+
_metadata: {
|
|
20402
|
+
...requirements._metadata,
|
|
20249
20403
|
useSearchEngine: content || true,
|
|
20250
20404
|
},
|
|
20251
20405
|
}, spaceTrim$1((block) => `
|
|
@@ -20393,8 +20547,8 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
20393
20547
|
return this.appendToSystemMessage({
|
|
20394
20548
|
...requirements,
|
|
20395
20549
|
tools: updatedTools,
|
|
20396
|
-
|
|
20397
|
-
...requirements.
|
|
20550
|
+
_metadata: {
|
|
20551
|
+
...requirements._metadata,
|
|
20398
20552
|
},
|
|
20399
20553
|
}, spaceTrim$1((block) => `
|
|
20400
20554
|
Time and date context:
|
|
@@ -24972,6 +25126,66 @@ const OPENAI_MODELS = exportJson({
|
|
|
24972
25126
|
},
|
|
24973
25127
|
/**/
|
|
24974
25128
|
/**/
|
|
25129
|
+
{
|
|
25130
|
+
modelVariant: 'CHAT',
|
|
25131
|
+
modelTitle: 'gpt-5.2-codex',
|
|
25132
|
+
modelName: 'gpt-5.2-codex',
|
|
25133
|
+
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.',
|
|
25134
|
+
pricing: {
|
|
25135
|
+
prompt: pricing(`$1.75 / 1M tokens`),
|
|
25136
|
+
output: pricing(`$14.00 / 1M tokens`),
|
|
25137
|
+
},
|
|
25138
|
+
},
|
|
25139
|
+
/**/
|
|
25140
|
+
/**/
|
|
25141
|
+
{
|
|
25142
|
+
modelVariant: 'CHAT',
|
|
25143
|
+
modelTitle: 'gpt-5.1-codex-max',
|
|
25144
|
+
modelName: 'gpt-5.1-codex-max',
|
|
25145
|
+
modelDescription: 'Premium GPT-5.1 Codex flavor that mirrors gpt-5.1 in capability and pricing while adding Codex tooling optimizations.',
|
|
25146
|
+
pricing: {
|
|
25147
|
+
prompt: pricing(`$1.25 / 1M tokens`),
|
|
25148
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
25149
|
+
},
|
|
25150
|
+
},
|
|
25151
|
+
/**/
|
|
25152
|
+
/**/
|
|
25153
|
+
{
|
|
25154
|
+
modelVariant: 'CHAT',
|
|
25155
|
+
modelTitle: 'gpt-5.1-codex',
|
|
25156
|
+
modelName: 'gpt-5.1-codex',
|
|
25157
|
+
modelDescription: 'Core GPT-5.1 Codex model focused on agentic coding tasks with a balanced trade-off between reasoning and cost.',
|
|
25158
|
+
pricing: {
|
|
25159
|
+
prompt: pricing(`$1.25 / 1M tokens`),
|
|
25160
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
25161
|
+
},
|
|
25162
|
+
},
|
|
25163
|
+
/**/
|
|
25164
|
+
/**/
|
|
25165
|
+
{
|
|
25166
|
+
modelVariant: 'CHAT',
|
|
25167
|
+
modelTitle: 'gpt-5.1-codex-mini',
|
|
25168
|
+
modelName: 'gpt-5.1-codex-mini',
|
|
25169
|
+
modelDescription: 'Compact, cost-effective GPT-5.1 Codex variant with a smaller context window ideal for cheap assistant iterations that still require coding awareness.',
|
|
25170
|
+
pricing: {
|
|
25171
|
+
prompt: pricing(`$0.25 / 1M tokens`),
|
|
25172
|
+
output: pricing(`$2.00 / 1M tokens`),
|
|
25173
|
+
},
|
|
25174
|
+
},
|
|
25175
|
+
/**/
|
|
25176
|
+
/**/
|
|
25177
|
+
{
|
|
25178
|
+
modelVariant: 'CHAT',
|
|
25179
|
+
modelTitle: 'gpt-5-codex',
|
|
25180
|
+
modelName: 'gpt-5-codex',
|
|
25181
|
+
modelDescription: 'Legacy GPT-5 Codex model built for agentic coding workloads with the same pricing as GPT-5 and a focus on stability.',
|
|
25182
|
+
pricing: {
|
|
25183
|
+
prompt: pricing(`$1.25 / 1M tokens`),
|
|
25184
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
25185
|
+
},
|
|
25186
|
+
},
|
|
25187
|
+
/**/
|
|
25188
|
+
/**/
|
|
24975
25189
|
{
|
|
24976
25190
|
modelVariant: 'CHAT',
|
|
24977
25191
|
modelTitle: 'gpt-5-mini',
|
|
@@ -27000,6 +27214,32 @@ function isUnsupportedParameterError(error) {
|
|
|
27000
27214
|
errorMessage.includes('does not support'));
|
|
27001
27215
|
}
|
|
27002
27216
|
|
|
27217
|
+
/**
|
|
27218
|
+
* Provides access to the structured clone implementation when available.
|
|
27219
|
+
*/
|
|
27220
|
+
function getStructuredCloneFunction() {
|
|
27221
|
+
return globalThis.structuredClone;
|
|
27222
|
+
}
|
|
27223
|
+
/**
|
|
27224
|
+
* Checks whether the prompt is a chat prompt that carries file attachments.
|
|
27225
|
+
*/
|
|
27226
|
+
function hasChatPromptFiles(prompt) {
|
|
27227
|
+
return 'files' in prompt && Array.isArray(prompt.files);
|
|
27228
|
+
}
|
|
27229
|
+
/**
|
|
27230
|
+
* Creates a deep copy of the prompt while keeping attached files intact when structured clone is not available.
|
|
27231
|
+
*/
|
|
27232
|
+
function clonePromptPreservingFiles(prompt) {
|
|
27233
|
+
const structuredCloneFn = getStructuredCloneFunction();
|
|
27234
|
+
if (typeof structuredCloneFn === 'function') {
|
|
27235
|
+
return structuredCloneFn(prompt);
|
|
27236
|
+
}
|
|
27237
|
+
const clonedPrompt = JSON.parse(JSON.stringify(prompt));
|
|
27238
|
+
if (hasChatPromptFiles(prompt)) {
|
|
27239
|
+
clonedPrompt.files = prompt.files;
|
|
27240
|
+
}
|
|
27241
|
+
return clonedPrompt;
|
|
27242
|
+
}
|
|
27003
27243
|
/**
|
|
27004
27244
|
* Execution Tools for calling OpenAI API or other OpenAI compatible provider
|
|
27005
27245
|
*
|
|
@@ -27084,7 +27324,7 @@ class OpenAiCompatibleExecutionTools {
|
|
|
27084
27324
|
*/
|
|
27085
27325
|
async callChatModelStream(prompt, onProgress) {
|
|
27086
27326
|
// Deep clone prompt and modelRequirements to avoid mutation across calls
|
|
27087
|
-
const clonedPrompt =
|
|
27327
|
+
const clonedPrompt = clonePromptPreservingFiles(prompt);
|
|
27088
27328
|
// Use local Set for retried parameters to ensure independence and thread safety
|
|
27089
27329
|
const retriedUnsupportedParameters = new Set();
|
|
27090
27330
|
return this.callChatModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters, onProgress);
|
|
@@ -27111,7 +27351,10 @@ class OpenAiCompatibleExecutionTools {
|
|
|
27111
27351
|
// <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
|
|
27112
27352
|
// <- Note: [🧆]
|
|
27113
27353
|
}; // <- TODO: [💩] Guard here types better
|
|
27114
|
-
if (
|
|
27354
|
+
if (currentModelRequirements.responseFormat !== undefined) {
|
|
27355
|
+
modelSettings.response_format = currentModelRequirements.responseFormat;
|
|
27356
|
+
}
|
|
27357
|
+
else if (format === 'JSON') {
|
|
27115
27358
|
modelSettings.response_format = {
|
|
27116
27359
|
type: 'json_object',
|
|
27117
27360
|
};
|
|
@@ -29089,7 +29332,9 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
|
|
|
29089
29332
|
const processingStartedAtMs = Date.now();
|
|
29090
29333
|
for (const [index, source] of knowledgeSources.entries()) {
|
|
29091
29334
|
try {
|
|
29092
|
-
const
|
|
29335
|
+
const isDataUrl = isDataUrlKnowledgeSource(source);
|
|
29336
|
+
const isHttp = source.startsWith('http://') || source.startsWith('https://');
|
|
29337
|
+
const sourceType = isDataUrl ? 'data_url' : isHttp ? 'url' : 'file';
|
|
29093
29338
|
if (this.options.isVerbose) {
|
|
29094
29339
|
console.info('[🤰]', 'Processing knowledge source', {
|
|
29095
29340
|
index: index + 1,
|
|
@@ -29099,8 +29344,27 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
|
|
|
29099
29344
|
logLabel,
|
|
29100
29345
|
});
|
|
29101
29346
|
}
|
|
29102
|
-
|
|
29103
|
-
|
|
29347
|
+
if (isDataUrl) {
|
|
29348
|
+
const parsed = parseDataUrlKnowledgeSource(source);
|
|
29349
|
+
if (!parsed) {
|
|
29350
|
+
skippedSources.push({ source, reason: 'invalid_data_url' });
|
|
29351
|
+
if (this.options.isVerbose) {
|
|
29352
|
+
console.info('[🤰]', 'Skipping knowledge source (invalid data URL)', {
|
|
29353
|
+
source,
|
|
29354
|
+
sourceType,
|
|
29355
|
+
logLabel,
|
|
29356
|
+
});
|
|
29357
|
+
}
|
|
29358
|
+
continue;
|
|
29359
|
+
}
|
|
29360
|
+
const dataUrlFile = new File([parsed.buffer], parsed.filename, {
|
|
29361
|
+
type: parsed.mimeType,
|
|
29362
|
+
});
|
|
29363
|
+
fileStreams.push(dataUrlFile);
|
|
29364
|
+
totalBytes += parsed.buffer.length;
|
|
29365
|
+
continue;
|
|
29366
|
+
}
|
|
29367
|
+
if (isHttp) {
|
|
29104
29368
|
const downloadResult = await this.downloadKnowledgeSourceFile({
|
|
29105
29369
|
source,
|
|
29106
29370
|
timeoutMs: downloadTimeoutMs,
|
|
@@ -30985,11 +31249,14 @@ const _FormattedBookInMarkdownTranspilerRegistration = $bookTranspilersRegister.
|
|
|
30985
31249
|
function createEmptyAgentModelRequirements() {
|
|
30986
31250
|
return {
|
|
30987
31251
|
systemMessage: '',
|
|
31252
|
+
promptSuffix: '',
|
|
30988
31253
|
// modelName: 'gpt-5',
|
|
30989
31254
|
modelName: 'gemini-2.5-flash-lite',
|
|
30990
31255
|
temperature: 0.7,
|
|
30991
31256
|
topP: 0.9,
|
|
30992
31257
|
topK: 50,
|
|
31258
|
+
parentAgentUrl: null,
|
|
31259
|
+
isClosed: false,
|
|
30993
31260
|
};
|
|
30994
31261
|
}
|
|
30995
31262
|
/**
|
|
@@ -31423,8 +31690,8 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
31423
31690
|
// Store the agent name in metadata so commitments can access it
|
|
31424
31691
|
requirements = {
|
|
31425
31692
|
...requirements,
|
|
31426
|
-
|
|
31427
|
-
...requirements.
|
|
31693
|
+
_metadata: {
|
|
31694
|
+
...requirements._metadata,
|
|
31428
31695
|
agentName: parseResult.agentName,
|
|
31429
31696
|
},
|
|
31430
31697
|
};
|
|
@@ -32418,6 +32685,40 @@ function isAssistantPreparationToolCall(toolCall) {
|
|
|
32418
32685
|
return toolCall.name === ASSISTANT_PREPARATION_TOOL_CALL_NAME;
|
|
32419
32686
|
}
|
|
32420
32687
|
|
|
32688
|
+
/**
|
|
32689
|
+
* Builds a stable identity string for tool calls across partial updates.
|
|
32690
|
+
*
|
|
32691
|
+
* @param toolCall - Tool call entry to identify.
|
|
32692
|
+
* @returns Stable identity string for deduplication.
|
|
32693
|
+
*
|
|
32694
|
+
* @private function of <Chat/>
|
|
32695
|
+
*/
|
|
32696
|
+
function getToolCallIdentity(toolCall) {
|
|
32697
|
+
const rawToolCall = toolCall.rawToolCall;
|
|
32698
|
+
const rawId = (rawToolCall === null || rawToolCall === void 0 ? void 0 : rawToolCall.id) || (rawToolCall === null || rawToolCall === void 0 ? void 0 : rawToolCall.callId) || (rawToolCall === null || rawToolCall === void 0 ? void 0 : rawToolCall.call_id);
|
|
32699
|
+
if (rawId) {
|
|
32700
|
+
return `id:${rawId}`;
|
|
32701
|
+
}
|
|
32702
|
+
if (toolCall.createdAt) {
|
|
32703
|
+
return `time:${toolCall.createdAt}:${toolCall.name}`;
|
|
32704
|
+
}
|
|
32705
|
+
const argsKey = (() => {
|
|
32706
|
+
if (typeof toolCall.arguments === 'string') {
|
|
32707
|
+
return toolCall.arguments;
|
|
32708
|
+
}
|
|
32709
|
+
if (!toolCall.arguments) {
|
|
32710
|
+
return '';
|
|
32711
|
+
}
|
|
32712
|
+
try {
|
|
32713
|
+
return JSON.stringify(toolCall.arguments);
|
|
32714
|
+
}
|
|
32715
|
+
catch (_a) {
|
|
32716
|
+
return '';
|
|
32717
|
+
}
|
|
32718
|
+
})();
|
|
32719
|
+
return `fallback:${toolCall.name}:${argsKey}`;
|
|
32720
|
+
}
|
|
32721
|
+
|
|
32421
32722
|
/*! *****************************************************************************
|
|
32422
32723
|
Copyright (c) Microsoft Corporation.
|
|
32423
32724
|
|
|
@@ -32640,6 +32941,64 @@ function promptbookifyAiText(text) {
|
|
|
32640
32941
|
*/
|
|
32641
32942
|
|
|
32642
32943
|
const DEFAULT_AGENT_KIT_MODEL_NAME = 'gpt-5.2';
|
|
32944
|
+
const DEFAULT_JSON_SCHEMA_NAME = 'StructuredOutput';
|
|
32945
|
+
/*
|
|
32946
|
+
TODO: Use or remove
|
|
32947
|
+
const EMPTY_JSON_SCHEMA: JsonSchemaDefinition['schema'] = {
|
|
32948
|
+
type: 'object',
|
|
32949
|
+
properties: {},
|
|
32950
|
+
required: [],
|
|
32951
|
+
additionalProperties: true,
|
|
32952
|
+
};
|
|
32953
|
+
*/
|
|
32954
|
+
function buildJsonSchemaDefinition(jsonSchema) {
|
|
32955
|
+
var _a, _b, _c;
|
|
32956
|
+
const schema = (_a = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.schema) !== null && _a !== void 0 ? _a : {};
|
|
32957
|
+
return {
|
|
32958
|
+
type: 'json_schema',
|
|
32959
|
+
name: (_b = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.name) !== null && _b !== void 0 ? _b : DEFAULT_JSON_SCHEMA_NAME,
|
|
32960
|
+
strict: Boolean(jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.strict),
|
|
32961
|
+
schema: {
|
|
32962
|
+
type: 'object',
|
|
32963
|
+
properties: ((_c = schema.properties) !== null && _c !== void 0 ? _c : {}),
|
|
32964
|
+
required: Array.isArray(schema.required) ? schema.required : [],
|
|
32965
|
+
additionalProperties: schema.additionalProperties === undefined ? true : Boolean(schema.additionalProperties),
|
|
32966
|
+
description: schema.description,
|
|
32967
|
+
},
|
|
32968
|
+
};
|
|
32969
|
+
}
|
|
32970
|
+
/**
|
|
32971
|
+
* Maps OpenAI `response_format` payloads to AgentKit output types so the runner can forward
|
|
32972
|
+
* structured-output preferences to OpenAI while still reusing the same AgentKit agent instance.
|
|
32973
|
+
*
|
|
32974
|
+
* @param responseFormat - The OpenAI `response_format` payload from the user request.
|
|
32975
|
+
* @returns An Agent output type compatible with the requested schema or `undefined` when no impact is required.
|
|
32976
|
+
* @private utility of Open AI
|
|
32977
|
+
*/
|
|
32978
|
+
function mapResponseFormatToAgentOutputType(responseFormat) {
|
|
32979
|
+
if (!responseFormat) {
|
|
32980
|
+
return undefined;
|
|
32981
|
+
}
|
|
32982
|
+
if (typeof responseFormat === 'string') {
|
|
32983
|
+
if (responseFormat === 'text') {
|
|
32984
|
+
return 'text';
|
|
32985
|
+
}
|
|
32986
|
+
if (responseFormat === 'json_schema' || responseFormat === 'json_object') {
|
|
32987
|
+
return buildJsonSchemaDefinition();
|
|
32988
|
+
}
|
|
32989
|
+
return 'text';
|
|
32990
|
+
}
|
|
32991
|
+
switch (responseFormat.type) {
|
|
32992
|
+
case 'text':
|
|
32993
|
+
return 'text';
|
|
32994
|
+
case 'json_schema':
|
|
32995
|
+
return buildJsonSchemaDefinition(responseFormat.json_schema);
|
|
32996
|
+
case 'json_object':
|
|
32997
|
+
return buildJsonSchemaDefinition();
|
|
32998
|
+
default:
|
|
32999
|
+
return undefined;
|
|
33000
|
+
}
|
|
33001
|
+
}
|
|
32643
33002
|
/**
|
|
32644
33003
|
* Execution tools for OpenAI AgentKit (Agents SDK).
|
|
32645
33004
|
*
|
|
@@ -32687,6 +33046,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
32687
33046
|
...parameters,
|
|
32688
33047
|
modelName: this.agentKitModelName,
|
|
32689
33048
|
});
|
|
33049
|
+
const responseFormatOutputType = mapResponseFormatToAgentOutputType(modelRequirements.responseFormat);
|
|
32690
33050
|
const preparedAgentKitAgent = await this.prepareAgentKitAgent({
|
|
32691
33051
|
name: (prompt.title || 'Agent'),
|
|
32692
33052
|
instructions: modelRequirements.systemMessage || '',
|
|
@@ -32698,6 +33058,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
32698
33058
|
prompt,
|
|
32699
33059
|
rawPromptContent,
|
|
32700
33060
|
onProgress,
|
|
33061
|
+
responseFormatOutputType,
|
|
32701
33062
|
});
|
|
32702
33063
|
}
|
|
32703
33064
|
/**
|
|
@@ -32879,16 +33240,21 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
32879
33240
|
...prompt.parameters,
|
|
32880
33241
|
modelName: this.agentKitModelName,
|
|
32881
33242
|
});
|
|
33243
|
+
const agentForRun = options.responseFormatOutputType !== undefined
|
|
33244
|
+
? openAiAgentKitAgent.clone({
|
|
33245
|
+
outputType: options.responseFormatOutputType,
|
|
33246
|
+
})
|
|
33247
|
+
: openAiAgentKitAgent;
|
|
32882
33248
|
const start = $getCurrentDate();
|
|
32883
33249
|
let latestContent = '';
|
|
32884
33250
|
const toolCalls = [];
|
|
32885
33251
|
const toolCallIndexById = new Map();
|
|
32886
33252
|
const inputItems = await this.buildAgentKitInputItems(prompt, rawPromptContent);
|
|
32887
33253
|
const rawRequest = {
|
|
32888
|
-
agentName:
|
|
33254
|
+
agentName: agentForRun.name,
|
|
32889
33255
|
input: inputItems,
|
|
32890
33256
|
};
|
|
32891
|
-
const streamResult = await run(
|
|
33257
|
+
const streamResult = await run(agentForRun, inputItems, {
|
|
32892
33258
|
stream: true,
|
|
32893
33259
|
context: { parameters: prompt.parameters },
|
|
32894
33260
|
});
|
|
@@ -33236,22 +33602,28 @@ class AgentLlmExecutionTools {
|
|
|
33236
33602
|
throw new Error('AgentLlmExecutionTools only supports chat prompts');
|
|
33237
33603
|
}
|
|
33238
33604
|
const modelRequirements = await this.getModelRequirements();
|
|
33605
|
+
const { _metadata, promptSuffix, ...sanitizedRequirements } = modelRequirements;
|
|
33239
33606
|
const chatPrompt = prompt;
|
|
33240
33607
|
let underlyingLlmResult;
|
|
33241
|
-
|
|
33608
|
+
const chatPromptContentWithSuffix = promptSuffix
|
|
33609
|
+
? `${chatPrompt.content}\n\n${promptSuffix}`
|
|
33610
|
+
: chatPrompt.content;
|
|
33242
33611
|
const promptWithAgentModelRequirements = {
|
|
33243
33612
|
...chatPrompt,
|
|
33613
|
+
content: chatPromptContentWithSuffix,
|
|
33244
33614
|
modelRequirements: {
|
|
33245
33615
|
...chatPrompt.modelRequirements,
|
|
33246
|
-
...
|
|
33616
|
+
...sanitizedRequirements,
|
|
33247
33617
|
// Spread tools to convert readonly array to mutable
|
|
33248
|
-
tools:
|
|
33618
|
+
tools: sanitizedRequirements.tools
|
|
33619
|
+
? [...sanitizedRequirements.tools]
|
|
33620
|
+
: chatPrompt.modelRequirements.tools,
|
|
33249
33621
|
// Spread knowledgeSources to convert readonly array to mutable
|
|
33250
|
-
knowledgeSources:
|
|
33251
|
-
? [...
|
|
33622
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources
|
|
33623
|
+
? [...sanitizedRequirements.knowledgeSources]
|
|
33252
33624
|
: undefined,
|
|
33253
33625
|
// Prepend agent system message to existing system message
|
|
33254
|
-
systemMessage:
|
|
33626
|
+
systemMessage: sanitizedRequirements.systemMessage +
|
|
33255
33627
|
(chatPrompt.modelRequirements.systemMessage
|
|
33256
33628
|
? `\n\n${chatPrompt.modelRequirements.systemMessage}`
|
|
33257
33629
|
: ''),
|
|
@@ -33259,8 +33631,8 @@ class AgentLlmExecutionTools {
|
|
|
33259
33631
|
};
|
|
33260
33632
|
console.log('!!!! promptWithAgentModelRequirements:', promptWithAgentModelRequirements);
|
|
33261
33633
|
if (OpenAiAgentKitExecutionTools.isOpenAiAgentKitExecutionTools(this.options.llmTools)) {
|
|
33262
|
-
const requirementsHash = SHA256(JSON.stringify(
|
|
33263
|
-
const vectorStoreHash = SHA256(JSON.stringify((_a =
|
|
33634
|
+
const requirementsHash = SHA256(JSON.stringify(sanitizedRequirements)).toString();
|
|
33635
|
+
const vectorStoreHash = SHA256(JSON.stringify((_a = sanitizedRequirements.knowledgeSources) !== null && _a !== void 0 ? _a : [])).toString();
|
|
33264
33636
|
const cachedVectorStore = AgentLlmExecutionTools.vectorStoreCache.get(this.title);
|
|
33265
33637
|
const cachedAgentKit = AgentLlmExecutionTools.agentKitAgentCache.get(this.title);
|
|
33266
33638
|
let preparedAgentKit = this.options.assistantPreparationMode === 'external'
|
|
@@ -33287,7 +33659,7 @@ class AgentLlmExecutionTools {
|
|
|
33287
33659
|
agent: this.title,
|
|
33288
33660
|
});
|
|
33289
33661
|
}
|
|
33290
|
-
if (!vectorStoreId && ((_b =
|
|
33662
|
+
if (!vectorStoreId && ((_b = sanitizedRequirements.knowledgeSources) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
33291
33663
|
emitAssistantPreparationProgress({
|
|
33292
33664
|
onProgress,
|
|
33293
33665
|
prompt,
|
|
@@ -33303,9 +33675,9 @@ class AgentLlmExecutionTools {
|
|
|
33303
33675
|
});
|
|
33304
33676
|
preparedAgentKit = await this.options.llmTools.prepareAgentKitAgent({
|
|
33305
33677
|
name: this.title,
|
|
33306
|
-
instructions:
|
|
33307
|
-
knowledgeSources:
|
|
33308
|
-
tools:
|
|
33678
|
+
instructions: sanitizedRequirements.systemMessage || '',
|
|
33679
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources,
|
|
33680
|
+
tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
|
|
33309
33681
|
vectorStoreId,
|
|
33310
33682
|
});
|
|
33311
33683
|
}
|
|
@@ -33320,15 +33692,17 @@ class AgentLlmExecutionTools {
|
|
|
33320
33692
|
requirementsHash,
|
|
33321
33693
|
vectorStoreId: preparedAgentKit.vectorStoreId,
|
|
33322
33694
|
});
|
|
33695
|
+
const responseFormatOutputType = mapResponseFormatToAgentOutputType(promptWithAgentModelRequirements.modelRequirements.responseFormat);
|
|
33323
33696
|
underlyingLlmResult = await this.options.llmTools.callChatModelStreamWithPreparedAgent({
|
|
33324
33697
|
openAiAgentKitAgent: preparedAgentKit.agent,
|
|
33325
33698
|
prompt: promptWithAgentModelRequirements,
|
|
33326
33699
|
onProgress,
|
|
33700
|
+
responseFormatOutputType,
|
|
33327
33701
|
});
|
|
33328
33702
|
}
|
|
33329
33703
|
else if (OpenAiAssistantExecutionTools.isOpenAiAssistantExecutionTools(this.options.llmTools)) {
|
|
33330
33704
|
// ... deprecated path ...
|
|
33331
|
-
const requirementsHash = SHA256(JSON.stringify(
|
|
33705
|
+
const requirementsHash = SHA256(JSON.stringify(sanitizedRequirements)).toString();
|
|
33332
33706
|
const cached = AgentLlmExecutionTools.assistantCache.get(this.title);
|
|
33333
33707
|
let assistant;
|
|
33334
33708
|
if (this.options.assistantPreparationMode === 'external') {
|
|
@@ -33370,9 +33744,9 @@ class AgentLlmExecutionTools {
|
|
|
33370
33744
|
assistant = await this.options.llmTools.updateAssistant({
|
|
33371
33745
|
assistantId: cached.assistantId,
|
|
33372
33746
|
name: this.title,
|
|
33373
|
-
instructions:
|
|
33374
|
-
knowledgeSources:
|
|
33375
|
-
tools:
|
|
33747
|
+
instructions: sanitizedRequirements.systemMessage,
|
|
33748
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources,
|
|
33749
|
+
tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
|
|
33376
33750
|
});
|
|
33377
33751
|
AgentLlmExecutionTools.assistantCache.set(this.title, {
|
|
33378
33752
|
assistantId: assistant.assistantId,
|
|
@@ -33395,9 +33769,9 @@ class AgentLlmExecutionTools {
|
|
|
33395
33769
|
});
|
|
33396
33770
|
assistant = await this.options.llmTools.createNewAssistant({
|
|
33397
33771
|
name: this.title,
|
|
33398
|
-
instructions:
|
|
33399
|
-
knowledgeSources:
|
|
33400
|
-
tools:
|
|
33772
|
+
instructions: sanitizedRequirements.systemMessage,
|
|
33773
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources,
|
|
33774
|
+
tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
|
|
33401
33775
|
/*
|
|
33402
33776
|
!!!
|
|
33403
33777
|
metadata: {
|
|
@@ -33439,13 +33813,19 @@ class AgentLlmExecutionTools {
|
|
|
33439
33813
|
}
|
|
33440
33814
|
}
|
|
33441
33815
|
let content = underlyingLlmResult.content;
|
|
33442
|
-
|
|
33443
|
-
|
|
33444
|
-
|
|
33445
|
-
|
|
33816
|
+
if (typeof content === 'string') {
|
|
33817
|
+
// Note: Cleanup the AI artifacts from the content
|
|
33818
|
+
content = humanizeAiText(content);
|
|
33819
|
+
// Note: Make sure the content is Promptbook-like
|
|
33820
|
+
content = promptbookifyAiText(content);
|
|
33821
|
+
}
|
|
33822
|
+
else {
|
|
33823
|
+
// TODO: Maybe deep `humanizeAiText` + `promptbookifyAiText` inside of the object
|
|
33824
|
+
content = JSON.stringify(content);
|
|
33825
|
+
}
|
|
33446
33826
|
const agentResult = {
|
|
33447
33827
|
...underlyingLlmResult,
|
|
33448
|
-
content,
|
|
33828
|
+
content: content,
|
|
33449
33829
|
modelName: this.modelName,
|
|
33450
33830
|
};
|
|
33451
33831
|
return agentResult;
|
|
@@ -33634,7 +34014,6 @@ class Agent extends AgentLlmExecutionTools {
|
|
|
33634
34014
|
* Note: This method also implements the learning mechanism
|
|
33635
34015
|
*/
|
|
33636
34016
|
async callChatModelStream(prompt, onProgress) {
|
|
33637
|
-
var _a;
|
|
33638
34017
|
// [1] Check if the user is asking the same thing as in the samples
|
|
33639
34018
|
const modelRequirements = await this.getModelRequirements();
|
|
33640
34019
|
if (modelRequirements.samples) {
|
|
@@ -33682,7 +34061,7 @@ class Agent extends AgentLlmExecutionTools {
|
|
|
33682
34061
|
if (result.rawResponse && 'sample' in result.rawResponse) {
|
|
33683
34062
|
return result;
|
|
33684
34063
|
}
|
|
33685
|
-
if (
|
|
34064
|
+
if (modelRequirements.isClosed) {
|
|
33686
34065
|
return result;
|
|
33687
34066
|
}
|
|
33688
34067
|
// Note: [0] Notify start of self-learning
|
|
@@ -34072,26 +34451,7 @@ class RemoteAgent extends Agent {
|
|
|
34072
34451
|
};
|
|
34073
34452
|
};
|
|
34074
34453
|
const getToolCallKey = (toolCall) => {
|
|
34075
|
-
|
|
34076
|
-
const rawId = (_a = toolCall.rawToolCall) === null || _a === void 0 ? void 0 : _a.id;
|
|
34077
|
-
if (rawId) {
|
|
34078
|
-
return `id:${rawId}`;
|
|
34079
|
-
}
|
|
34080
|
-
const argsKey = (() => {
|
|
34081
|
-
if (typeof toolCall.arguments === 'string') {
|
|
34082
|
-
return toolCall.arguments;
|
|
34083
|
-
}
|
|
34084
|
-
if (!toolCall.arguments) {
|
|
34085
|
-
return '';
|
|
34086
|
-
}
|
|
34087
|
-
try {
|
|
34088
|
-
return JSON.stringify(toolCall.arguments);
|
|
34089
|
-
}
|
|
34090
|
-
catch (_a) {
|
|
34091
|
-
return '';
|
|
34092
|
-
}
|
|
34093
|
-
})();
|
|
34094
|
-
return `${toolCall.name}:${toolCall.createdAt || ''}:${argsKey}`;
|
|
34454
|
+
return getToolCallIdentity(toolCall);
|
|
34095
34455
|
};
|
|
34096
34456
|
const mergeToolCall = (existing, incoming) => {
|
|
34097
34457
|
const incomingResult = incoming.result;
|