@promptbook/remote-server 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 +2 -2
- package/umd/index.umd.js +467 -107
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -40,7 +40,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
40
40
|
* @generated
|
|
41
41
|
* @see https://github.com/webgptorg/promptbook
|
|
42
42
|
*/
|
|
43
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.110.0-
|
|
43
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.110.0-9';
|
|
44
44
|
/**
|
|
45
45
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
46
46
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -10801,6 +10801,28 @@ class BaseCommitmentDefinition {
|
|
|
10801
10801
|
return currentMessage + separator + content;
|
|
10802
10802
|
});
|
|
10803
10803
|
}
|
|
10804
|
+
/**
|
|
10805
|
+
* Helper method to create a new requirements object with updated prompt suffix
|
|
10806
|
+
*/
|
|
10807
|
+
updatePromptSuffix(requirements, contentUpdate) {
|
|
10808
|
+
const newSuffix = typeof contentUpdate === 'string' ? contentUpdate : contentUpdate(requirements.promptSuffix);
|
|
10809
|
+
return {
|
|
10810
|
+
...requirements,
|
|
10811
|
+
promptSuffix: newSuffix,
|
|
10812
|
+
};
|
|
10813
|
+
}
|
|
10814
|
+
/**
|
|
10815
|
+
* Helper method to append content to the prompt suffix
|
|
10816
|
+
* Default separator is a single newline for bullet lists.
|
|
10817
|
+
*/
|
|
10818
|
+
appendToPromptSuffix(requirements, content, separator = '\n') {
|
|
10819
|
+
return this.updatePromptSuffix(requirements, (currentSuffix) => {
|
|
10820
|
+
if (!currentSuffix.trim()) {
|
|
10821
|
+
return content;
|
|
10822
|
+
}
|
|
10823
|
+
return `${currentSuffix}${separator}${content}`;
|
|
10824
|
+
});
|
|
10825
|
+
}
|
|
10804
10826
|
/**
|
|
10805
10827
|
* Helper method to add a comment section to the system message
|
|
10806
10828
|
* Comments are lines starting with # that will be removed from the final system message
|
|
@@ -10978,13 +11000,9 @@ class ClosedCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
10978
11000
|
`);
|
|
10979
11001
|
}
|
|
10980
11002
|
applyToAgentModelRequirements(requirements, _content) {
|
|
10981
|
-
const updatedMetadata = {
|
|
10982
|
-
...requirements.metadata,
|
|
10983
|
-
isClosed: true,
|
|
10984
|
-
};
|
|
10985
11003
|
return {
|
|
10986
11004
|
...requirements,
|
|
10987
|
-
|
|
11005
|
+
isClosed: true,
|
|
10988
11006
|
};
|
|
10989
11007
|
}
|
|
10990
11008
|
}
|
|
@@ -11262,12 +11280,12 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
11262
11280
|
return requirements;
|
|
11263
11281
|
}
|
|
11264
11282
|
// Get existing dictionary entries from metadata
|
|
11265
|
-
const existingDictionary = ((_a = requirements.
|
|
11283
|
+
const existingDictionary = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
|
|
11266
11284
|
// Merge the new dictionary entry with existing entries
|
|
11267
11285
|
const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
|
|
11268
11286
|
// Store the merged dictionary in metadata for debugging and inspection
|
|
11269
11287
|
const updatedMetadata = {
|
|
11270
|
-
...requirements.
|
|
11288
|
+
...requirements._metadata,
|
|
11271
11289
|
DICTIONARY: mergedDictionary,
|
|
11272
11290
|
};
|
|
11273
11291
|
// Create the dictionary section for the system message
|
|
@@ -11275,7 +11293,7 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
11275
11293
|
const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
|
|
11276
11294
|
return {
|
|
11277
11295
|
...this.appendToSystemMessage(requirements, dictionarySection),
|
|
11278
|
-
|
|
11296
|
+
_metadata: updatedMetadata,
|
|
11279
11297
|
};
|
|
11280
11298
|
}
|
|
11281
11299
|
}
|
|
@@ -11415,10 +11433,7 @@ class FromCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
11415
11433
|
applyToAgentModelRequirements(requirements, content) {
|
|
11416
11434
|
const trimmedContent = content.trim();
|
|
11417
11435
|
if (!trimmedContent) {
|
|
11418
|
-
return
|
|
11419
|
-
...requirements,
|
|
11420
|
-
parentAgentUrl: undefined,
|
|
11421
|
-
};
|
|
11436
|
+
return requirements;
|
|
11422
11437
|
}
|
|
11423
11438
|
if (trimmedContent.toUpperCase() === 'VOID' ||
|
|
11424
11439
|
trimmedContent.toUpperCase() === 'NULL' ||
|
|
@@ -11632,6 +11647,136 @@ class ImportCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
11632
11647
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
11633
11648
|
*/
|
|
11634
11649
|
|
|
11650
|
+
/**
|
|
11651
|
+
* @@@
|
|
11652
|
+
*
|
|
11653
|
+
* @private thing of inline knowledge
|
|
11654
|
+
*/
|
|
11655
|
+
const INLINE_KNOWLEDGE_BASE_NAME = 'inline-knowledge';
|
|
11656
|
+
/**
|
|
11657
|
+
* @@@
|
|
11658
|
+
*
|
|
11659
|
+
* @private thing of inline knowledge
|
|
11660
|
+
*/
|
|
11661
|
+
const INLINE_KNOWLEDGE_EXTENSION = '.txt';
|
|
11662
|
+
/**
|
|
11663
|
+
* @@@
|
|
11664
|
+
*
|
|
11665
|
+
* @private thing of inline knowledge
|
|
11666
|
+
*/
|
|
11667
|
+
const DATA_URL_PREFIX = 'data:';
|
|
11668
|
+
/**
|
|
11669
|
+
* @@@
|
|
11670
|
+
*
|
|
11671
|
+
* @private thing of inline knowledge
|
|
11672
|
+
*/
|
|
11673
|
+
function getFirstNonEmptyLine(content) {
|
|
11674
|
+
const lines = content.split(/\r?\n/);
|
|
11675
|
+
for (const line of lines) {
|
|
11676
|
+
const trimmed = line.trim();
|
|
11677
|
+
if (trimmed) {
|
|
11678
|
+
return trimmed;
|
|
11679
|
+
}
|
|
11680
|
+
}
|
|
11681
|
+
return null;
|
|
11682
|
+
}
|
|
11683
|
+
/**
|
|
11684
|
+
* @@@
|
|
11685
|
+
*
|
|
11686
|
+
* @private thing of inline knowledge
|
|
11687
|
+
*/
|
|
11688
|
+
function deriveBaseFilename(content) {
|
|
11689
|
+
const firstLine = getFirstNonEmptyLine(content);
|
|
11690
|
+
if (!firstLine) {
|
|
11691
|
+
return INLINE_KNOWLEDGE_BASE_NAME;
|
|
11692
|
+
}
|
|
11693
|
+
const normalized = normalizeToKebabCase(firstLine);
|
|
11694
|
+
return normalized || INLINE_KNOWLEDGE_BASE_NAME;
|
|
11695
|
+
}
|
|
11696
|
+
/**
|
|
11697
|
+
* Creates a data URL that represents the inline knowledge content as a text file.
|
|
11698
|
+
*
|
|
11699
|
+
* @private thing of inline knowledge
|
|
11700
|
+
*/
|
|
11701
|
+
function createInlineKnowledgeSourceFile(content) {
|
|
11702
|
+
const trimmedContent = content.trim();
|
|
11703
|
+
const baseName = deriveBaseFilename(trimmedContent);
|
|
11704
|
+
const filename = `${baseName}${INLINE_KNOWLEDGE_EXTENSION}`;
|
|
11705
|
+
const mimeType = 'text/plain';
|
|
11706
|
+
const base64 = Buffer.from(trimmedContent, 'utf-8').toString('base64');
|
|
11707
|
+
const encodedFilename = encodeURIComponent(filename);
|
|
11708
|
+
const url = `${DATA_URL_PREFIX}${mimeType};name=${encodedFilename};charset=utf-8;base64,${base64}`;
|
|
11709
|
+
return {
|
|
11710
|
+
filename,
|
|
11711
|
+
mimeType,
|
|
11712
|
+
url,
|
|
11713
|
+
};
|
|
11714
|
+
}
|
|
11715
|
+
/**
|
|
11716
|
+
* Checks whether the provided source string is a data URL that can be decoded.
|
|
11717
|
+
*
|
|
11718
|
+
* @private thing of inline knowledge
|
|
11719
|
+
*/
|
|
11720
|
+
function isDataUrlKnowledgeSource(source) {
|
|
11721
|
+
return typeof source === 'string' && source.startsWith(DATA_URL_PREFIX);
|
|
11722
|
+
}
|
|
11723
|
+
/**
|
|
11724
|
+
* Parses a data URL-based knowledge source into its raw buffer, filename, and MIME type.
|
|
11725
|
+
*
|
|
11726
|
+
* @private thing of inline knowledge
|
|
11727
|
+
*/
|
|
11728
|
+
function parseDataUrlKnowledgeSource(source) {
|
|
11729
|
+
if (!isDataUrlKnowledgeSource(source)) {
|
|
11730
|
+
return null;
|
|
11731
|
+
}
|
|
11732
|
+
const commaIndex = source.indexOf(',');
|
|
11733
|
+
if (commaIndex === -1) {
|
|
11734
|
+
return null;
|
|
11735
|
+
}
|
|
11736
|
+
const header = source.slice(DATA_URL_PREFIX.length, commaIndex);
|
|
11737
|
+
const payload = source.slice(commaIndex + 1);
|
|
11738
|
+
const tokens = header.split(';');
|
|
11739
|
+
const mediaType = tokens[0] || 'text/plain';
|
|
11740
|
+
let filename = `${INLINE_KNOWLEDGE_BASE_NAME}${INLINE_KNOWLEDGE_EXTENSION}`;
|
|
11741
|
+
let isBase64 = false;
|
|
11742
|
+
for (let i = 1; i < tokens.length; i++) {
|
|
11743
|
+
const token = tokens[i];
|
|
11744
|
+
if (!token) {
|
|
11745
|
+
continue;
|
|
11746
|
+
}
|
|
11747
|
+
if (token.toLowerCase() === 'base64') {
|
|
11748
|
+
isBase64 = true;
|
|
11749
|
+
continue;
|
|
11750
|
+
}
|
|
11751
|
+
const [key, value] = token.split('=');
|
|
11752
|
+
if (key === 'name' && value !== undefined) {
|
|
11753
|
+
try {
|
|
11754
|
+
filename = decodeURIComponent(value);
|
|
11755
|
+
}
|
|
11756
|
+
catch (_a) {
|
|
11757
|
+
filename = value;
|
|
11758
|
+
}
|
|
11759
|
+
}
|
|
11760
|
+
}
|
|
11761
|
+
if (!isBase64) {
|
|
11762
|
+
return null;
|
|
11763
|
+
}
|
|
11764
|
+
try {
|
|
11765
|
+
const buffer = Buffer.from(payload, 'base64');
|
|
11766
|
+
return {
|
|
11767
|
+
buffer,
|
|
11768
|
+
filename,
|
|
11769
|
+
mimeType: mediaType,
|
|
11770
|
+
};
|
|
11771
|
+
}
|
|
11772
|
+
catch (_b) {
|
|
11773
|
+
return null;
|
|
11774
|
+
}
|
|
11775
|
+
}
|
|
11776
|
+
/**
|
|
11777
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
11778
|
+
*/
|
|
11779
|
+
|
|
11635
11780
|
/**
|
|
11636
11781
|
* KNOWLEDGE commitment definition
|
|
11637
11782
|
*
|
|
@@ -11730,9 +11875,13 @@ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
11730
11875
|
return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
|
|
11731
11876
|
}
|
|
11732
11877
|
else {
|
|
11733
|
-
|
|
11734
|
-
const
|
|
11735
|
-
|
|
11878
|
+
const inlineSource = createInlineKnowledgeSourceFile(trimmedContent);
|
|
11879
|
+
const updatedRequirements = {
|
|
11880
|
+
...requirements,
|
|
11881
|
+
knowledgeSources: [...(requirements.knowledgeSources || []), inlineSource.url],
|
|
11882
|
+
};
|
|
11883
|
+
const knowledgeInfo = `Knowledge Source Inline: ${inlineSource.filename} (derived from inline content and processed for retrieval during chat)`;
|
|
11884
|
+
return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
|
|
11736
11885
|
}
|
|
11737
11886
|
}
|
|
11738
11887
|
}
|
|
@@ -11979,16 +12128,16 @@ class AgentMessageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
11979
12128
|
// and typically doesn't need to be added to the system prompt or model requirements directly.
|
|
11980
12129
|
// It is extracted separately for the chat interface.
|
|
11981
12130
|
var _a;
|
|
11982
|
-
const pendingUserMessage = (_a = requirements.
|
|
12131
|
+
const pendingUserMessage = (_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
|
|
11983
12132
|
if (pendingUserMessage) {
|
|
11984
12133
|
const newSample = { question: pendingUserMessage, answer: content };
|
|
11985
12134
|
const newSamples = [...(requirements.samples || []), newSample];
|
|
11986
|
-
const newMetadata = { ...requirements.
|
|
12135
|
+
const newMetadata = { ...requirements._metadata };
|
|
11987
12136
|
delete newMetadata.pendingUserMessage;
|
|
11988
12137
|
return {
|
|
11989
12138
|
...requirements,
|
|
11990
12139
|
samples: newSamples,
|
|
11991
|
-
|
|
12140
|
+
_metadata: newMetadata,
|
|
11992
12141
|
};
|
|
11993
12142
|
}
|
|
11994
12143
|
return requirements;
|
|
@@ -12236,8 +12385,8 @@ class UserMessageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
12236
12385
|
applyToAgentModelRequirements(requirements, content) {
|
|
12237
12386
|
return {
|
|
12238
12387
|
...requirements,
|
|
12239
|
-
|
|
12240
|
-
...requirements.
|
|
12388
|
+
_metadata: {
|
|
12389
|
+
...requirements._metadata,
|
|
12241
12390
|
pendingUserMessage: content,
|
|
12242
12391
|
},
|
|
12243
12392
|
};
|
|
@@ -13095,11 +13244,7 @@ class NoteCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
13095
13244
|
if (trimmedContent === '') {
|
|
13096
13245
|
return requirements;
|
|
13097
13246
|
}
|
|
13098
|
-
|
|
13099
|
-
return {
|
|
13100
|
-
...requirements,
|
|
13101
|
-
notes: [...(requirements.notes || []), trimmedContent],
|
|
13102
|
-
};
|
|
13247
|
+
return requirements;
|
|
13103
13248
|
}
|
|
13104
13249
|
}
|
|
13105
13250
|
/**
|
|
@@ -13161,12 +13306,12 @@ class OpenCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
13161
13306
|
// Since OPEN is default, we can just ensure isClosed is false
|
|
13162
13307
|
// But to be explicit we can set it
|
|
13163
13308
|
const updatedMetadata = {
|
|
13164
|
-
...requirements.
|
|
13309
|
+
...requirements._metadata,
|
|
13165
13310
|
isClosed: false,
|
|
13166
13311
|
};
|
|
13167
13312
|
return {
|
|
13168
13313
|
...requirements,
|
|
13169
|
-
|
|
13314
|
+
_metadata: updatedMetadata,
|
|
13170
13315
|
};
|
|
13171
13316
|
}
|
|
13172
13317
|
}
|
|
@@ -13247,7 +13392,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
13247
13392
|
return requirements;
|
|
13248
13393
|
}
|
|
13249
13394
|
// Get existing persona content from metadata
|
|
13250
|
-
const existingPersonaContent = ((_a = requirements.
|
|
13395
|
+
const existingPersonaContent = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.PERSONA) || '';
|
|
13251
13396
|
// Merge the new content with existing persona content
|
|
13252
13397
|
// When multiple PERSONA commitments exist, they are merged into one
|
|
13253
13398
|
const mergedPersonaContent = existingPersonaContent
|
|
@@ -13255,12 +13400,12 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
13255
13400
|
: trimmedContent;
|
|
13256
13401
|
// Store the merged persona content in metadata for debugging and inspection
|
|
13257
13402
|
const updatedMetadata = {
|
|
13258
|
-
...requirements.
|
|
13403
|
+
...requirements._metadata,
|
|
13259
13404
|
PERSONA: mergedPersonaContent,
|
|
13260
13405
|
};
|
|
13261
13406
|
// Get the agent name from metadata (which should contain the first line of agent source)
|
|
13262
13407
|
// If not available, extract from current system message as fallback
|
|
13263
|
-
let agentName = (_b = requirements.
|
|
13408
|
+
let agentName = (_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.agentName;
|
|
13264
13409
|
if (!agentName) {
|
|
13265
13410
|
// Fallback: extract from current system message
|
|
13266
13411
|
const currentMessage = requirements.systemMessage.trim();
|
|
@@ -13307,7 +13452,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
13307
13452
|
return {
|
|
13308
13453
|
...requirements,
|
|
13309
13454
|
systemMessage: newSystemMessage,
|
|
13310
|
-
|
|
13455
|
+
_metadata: updatedMetadata,
|
|
13311
13456
|
};
|
|
13312
13457
|
}
|
|
13313
13458
|
}
|
|
@@ -13390,7 +13535,16 @@ class RuleCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
13390
13535
|
}
|
|
13391
13536
|
// Add rule to the system message
|
|
13392
13537
|
const ruleSection = `Rule: ${trimmedContent}`;
|
|
13393
|
-
|
|
13538
|
+
const requirementsWithRule = this.appendToSystemMessage(requirements, ruleSection, '\n\n');
|
|
13539
|
+
const ruleLines = trimmedContent
|
|
13540
|
+
.split(/\r?\n/)
|
|
13541
|
+
.map((line) => line.trim())
|
|
13542
|
+
.filter(Boolean)
|
|
13543
|
+
.map((line) => `- ${line}`);
|
|
13544
|
+
if (ruleLines.length === 0) {
|
|
13545
|
+
return requirementsWithRule;
|
|
13546
|
+
}
|
|
13547
|
+
return this.appendToPromptSuffix(requirementsWithRule, ruleLines.join('\n'));
|
|
13394
13548
|
}
|
|
13395
13549
|
}
|
|
13396
13550
|
/**
|
|
@@ -13896,7 +14050,7 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
13896
14050
|
if (teammates.length === 0) {
|
|
13897
14051
|
return requirements;
|
|
13898
14052
|
}
|
|
13899
|
-
const agentName = ((_a = requirements.
|
|
14053
|
+
const agentName = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.agentName) || 'Agent';
|
|
13900
14054
|
const teamEntries = teammates.map((teammate) => ({
|
|
13901
14055
|
toolName: createTeamToolName(teammate.url),
|
|
13902
14056
|
teammate,
|
|
@@ -13936,7 +14090,7 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
13936
14090
|
},
|
|
13937
14091
|
});
|
|
13938
14092
|
}
|
|
13939
|
-
const existingTeammates = ((_b = requirements.
|
|
14093
|
+
const existingTeammates = ((_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.teammates) || [];
|
|
13940
14094
|
const updatedTeammates = [...existingTeammates];
|
|
13941
14095
|
for (const entry of teamEntries) {
|
|
13942
14096
|
if (updatedTeammates.some((existing) => existing.url === entry.teammate.url)) {
|
|
@@ -13965,8 +14119,8 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
13965
14119
|
return this.appendToSystemMessage({
|
|
13966
14120
|
...requirements,
|
|
13967
14121
|
tools: updatedTools,
|
|
13968
|
-
|
|
13969
|
-
...requirements.
|
|
14122
|
+
_metadata: {
|
|
14123
|
+
...requirements._metadata,
|
|
13970
14124
|
teammates: updatedTeammates,
|
|
13971
14125
|
},
|
|
13972
14126
|
}, teamSystemMessage);
|
|
@@ -14198,7 +14352,7 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
14198
14352
|
if (!trimmedContent) {
|
|
14199
14353
|
// Store template mode flag in metadata
|
|
14200
14354
|
const updatedMetadata = {
|
|
14201
|
-
...requirements.
|
|
14355
|
+
...requirements._metadata,
|
|
14202
14356
|
templateMode: true,
|
|
14203
14357
|
};
|
|
14204
14358
|
// Add a general instruction about using structured templates
|
|
@@ -14208,21 +14362,21 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
14208
14362
|
`);
|
|
14209
14363
|
return {
|
|
14210
14364
|
...this.appendToSystemMessage(requirements, templateModeInstruction, '\n\n'),
|
|
14211
|
-
|
|
14365
|
+
_metadata: updatedMetadata,
|
|
14212
14366
|
};
|
|
14213
14367
|
}
|
|
14214
14368
|
// If content is provided, add the specific template instructions
|
|
14215
14369
|
const templateSection = `Response Template: ${trimmedContent}`;
|
|
14216
14370
|
// Store the template in metadata for potential programmatic access
|
|
14217
|
-
const existingTemplates = ((_a = requirements.
|
|
14371
|
+
const existingTemplates = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.templates) || [];
|
|
14218
14372
|
const updatedMetadata = {
|
|
14219
|
-
...requirements.
|
|
14373
|
+
...requirements._metadata,
|
|
14220
14374
|
templates: [...existingTemplates, trimmedContent],
|
|
14221
14375
|
templateMode: true,
|
|
14222
14376
|
};
|
|
14223
14377
|
return {
|
|
14224
14378
|
...this.appendToSystemMessage(requirements, templateSection, '\n\n'),
|
|
14225
|
-
|
|
14379
|
+
_metadata: updatedMetadata,
|
|
14226
14380
|
};
|
|
14227
14381
|
}
|
|
14228
14382
|
}
|
|
@@ -14559,8 +14713,8 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
14559
14713
|
return this.appendToSystemMessage({
|
|
14560
14714
|
...requirements,
|
|
14561
14715
|
tools: updatedTools,
|
|
14562
|
-
|
|
14563
|
-
...requirements.
|
|
14716
|
+
_metadata: {
|
|
14717
|
+
...requirements._metadata,
|
|
14564
14718
|
useBrowser: true,
|
|
14565
14719
|
},
|
|
14566
14720
|
}, spaceTrim$1(`
|
|
@@ -14789,8 +14943,8 @@ class UseEmailCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
14789
14943
|
return this.appendToSystemMessage({
|
|
14790
14944
|
...requirements,
|
|
14791
14945
|
tools: updatedTools,
|
|
14792
|
-
|
|
14793
|
-
...requirements.
|
|
14946
|
+
_metadata: {
|
|
14947
|
+
...requirements._metadata,
|
|
14794
14948
|
useEmail: content || true,
|
|
14795
14949
|
},
|
|
14796
14950
|
}, spaceTrim$1((block) => `
|
|
@@ -14925,8 +15079,8 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
14925
15079
|
return this.appendToSystemMessage({
|
|
14926
15080
|
...requirements,
|
|
14927
15081
|
tools: updatedTools,
|
|
14928
|
-
|
|
14929
|
-
...requirements.
|
|
15082
|
+
_metadata: {
|
|
15083
|
+
...requirements._metadata,
|
|
14930
15084
|
useImageGenerator: content || true,
|
|
14931
15085
|
},
|
|
14932
15086
|
}, spaceTrim$1(`
|
|
@@ -15217,8 +15371,8 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
15217
15371
|
return this.appendToSystemMessage({
|
|
15218
15372
|
...requirements,
|
|
15219
15373
|
tools: updatedTools,
|
|
15220
|
-
|
|
15221
|
-
...requirements.
|
|
15374
|
+
_metadata: {
|
|
15375
|
+
...requirements._metadata,
|
|
15222
15376
|
useSearchEngine: content || true,
|
|
15223
15377
|
},
|
|
15224
15378
|
}, spaceTrim$1((block) => `
|
|
@@ -15366,8 +15520,8 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
15366
15520
|
return this.appendToSystemMessage({
|
|
15367
15521
|
...requirements,
|
|
15368
15522
|
tools: updatedTools,
|
|
15369
|
-
|
|
15370
|
-
...requirements.
|
|
15523
|
+
_metadata: {
|
|
15524
|
+
...requirements._metadata,
|
|
15371
15525
|
},
|
|
15372
15526
|
}, spaceTrim$1((block) => `
|
|
15373
15527
|
Time and date context:
|
|
@@ -17414,6 +17568,40 @@ function isAssistantPreparationToolCall(toolCall) {
|
|
|
17414
17568
|
return toolCall.name === ASSISTANT_PREPARATION_TOOL_CALL_NAME;
|
|
17415
17569
|
}
|
|
17416
17570
|
|
|
17571
|
+
/**
|
|
17572
|
+
* Builds a stable identity string for tool calls across partial updates.
|
|
17573
|
+
*
|
|
17574
|
+
* @param toolCall - Tool call entry to identify.
|
|
17575
|
+
* @returns Stable identity string for deduplication.
|
|
17576
|
+
*
|
|
17577
|
+
* @private function of <Chat/>
|
|
17578
|
+
*/
|
|
17579
|
+
function getToolCallIdentity(toolCall) {
|
|
17580
|
+
const rawToolCall = toolCall.rawToolCall;
|
|
17581
|
+
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);
|
|
17582
|
+
if (rawId) {
|
|
17583
|
+
return `id:${rawId}`;
|
|
17584
|
+
}
|
|
17585
|
+
if (toolCall.createdAt) {
|
|
17586
|
+
return `time:${toolCall.createdAt}:${toolCall.name}`;
|
|
17587
|
+
}
|
|
17588
|
+
const argsKey = (() => {
|
|
17589
|
+
if (typeof toolCall.arguments === 'string') {
|
|
17590
|
+
return toolCall.arguments;
|
|
17591
|
+
}
|
|
17592
|
+
if (!toolCall.arguments) {
|
|
17593
|
+
return '';
|
|
17594
|
+
}
|
|
17595
|
+
try {
|
|
17596
|
+
return JSON.stringify(toolCall.arguments);
|
|
17597
|
+
}
|
|
17598
|
+
catch (_a) {
|
|
17599
|
+
return '';
|
|
17600
|
+
}
|
|
17601
|
+
})();
|
|
17602
|
+
return `fallback:${toolCall.name}:${argsKey}`;
|
|
17603
|
+
}
|
|
17604
|
+
|
|
17417
17605
|
/*! *****************************************************************************
|
|
17418
17606
|
Copyright (c) Microsoft Corporation.
|
|
17419
17607
|
|
|
@@ -18052,11 +18240,14 @@ function asUpdatableSubject(value) {
|
|
|
18052
18240
|
function createEmptyAgentModelRequirements() {
|
|
18053
18241
|
return {
|
|
18054
18242
|
systemMessage: '',
|
|
18243
|
+
promptSuffix: '',
|
|
18055
18244
|
// modelName: 'gpt-5',
|
|
18056
18245
|
modelName: 'gemini-2.5-flash-lite',
|
|
18057
18246
|
temperature: 0.7,
|
|
18058
18247
|
topP: 0.9,
|
|
18059
18248
|
topK: 50,
|
|
18249
|
+
parentAgentUrl: null,
|
|
18250
|
+
isClosed: false,
|
|
18060
18251
|
};
|
|
18061
18252
|
}
|
|
18062
18253
|
/**
|
|
@@ -18246,8 +18437,8 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
18246
18437
|
// Store the agent name in metadata so commitments can access it
|
|
18247
18438
|
requirements = {
|
|
18248
18439
|
...requirements,
|
|
18249
|
-
|
|
18250
|
-
...requirements.
|
|
18440
|
+
_metadata: {
|
|
18441
|
+
...requirements._metadata,
|
|
18251
18442
|
agentName: parseResult.agentName,
|
|
18252
18443
|
},
|
|
18253
18444
|
};
|
|
@@ -18730,6 +18921,66 @@ const OPENAI_MODELS = exportJson({
|
|
|
18730
18921
|
},
|
|
18731
18922
|
/**/
|
|
18732
18923
|
/**/
|
|
18924
|
+
{
|
|
18925
|
+
modelVariant: 'CHAT',
|
|
18926
|
+
modelTitle: 'gpt-5.2-codex',
|
|
18927
|
+
modelName: 'gpt-5.2-codex',
|
|
18928
|
+
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.',
|
|
18929
|
+
pricing: {
|
|
18930
|
+
prompt: pricing(`$1.75 / 1M tokens`),
|
|
18931
|
+
output: pricing(`$14.00 / 1M tokens`),
|
|
18932
|
+
},
|
|
18933
|
+
},
|
|
18934
|
+
/**/
|
|
18935
|
+
/**/
|
|
18936
|
+
{
|
|
18937
|
+
modelVariant: 'CHAT',
|
|
18938
|
+
modelTitle: 'gpt-5.1-codex-max',
|
|
18939
|
+
modelName: 'gpt-5.1-codex-max',
|
|
18940
|
+
modelDescription: 'Premium GPT-5.1 Codex flavor that mirrors gpt-5.1 in capability and pricing while adding Codex tooling optimizations.',
|
|
18941
|
+
pricing: {
|
|
18942
|
+
prompt: pricing(`$1.25 / 1M tokens`),
|
|
18943
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
18944
|
+
},
|
|
18945
|
+
},
|
|
18946
|
+
/**/
|
|
18947
|
+
/**/
|
|
18948
|
+
{
|
|
18949
|
+
modelVariant: 'CHAT',
|
|
18950
|
+
modelTitle: 'gpt-5.1-codex',
|
|
18951
|
+
modelName: 'gpt-5.1-codex',
|
|
18952
|
+
modelDescription: 'Core GPT-5.1 Codex model focused on agentic coding tasks with a balanced trade-off between reasoning and cost.',
|
|
18953
|
+
pricing: {
|
|
18954
|
+
prompt: pricing(`$1.25 / 1M tokens`),
|
|
18955
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
18956
|
+
},
|
|
18957
|
+
},
|
|
18958
|
+
/**/
|
|
18959
|
+
/**/
|
|
18960
|
+
{
|
|
18961
|
+
modelVariant: 'CHAT',
|
|
18962
|
+
modelTitle: 'gpt-5.1-codex-mini',
|
|
18963
|
+
modelName: 'gpt-5.1-codex-mini',
|
|
18964
|
+
modelDescription: 'Compact, cost-effective GPT-5.1 Codex variant with a smaller context window ideal for cheap assistant iterations that still require coding awareness.',
|
|
18965
|
+
pricing: {
|
|
18966
|
+
prompt: pricing(`$0.25 / 1M tokens`),
|
|
18967
|
+
output: pricing(`$2.00 / 1M tokens`),
|
|
18968
|
+
},
|
|
18969
|
+
},
|
|
18970
|
+
/**/
|
|
18971
|
+
/**/
|
|
18972
|
+
{
|
|
18973
|
+
modelVariant: 'CHAT',
|
|
18974
|
+
modelTitle: 'gpt-5-codex',
|
|
18975
|
+
modelName: 'gpt-5-codex',
|
|
18976
|
+
modelDescription: 'Legacy GPT-5 Codex model built for agentic coding workloads with the same pricing as GPT-5 and a focus on stability.',
|
|
18977
|
+
pricing: {
|
|
18978
|
+
prompt: pricing(`$1.25 / 1M tokens`),
|
|
18979
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
18980
|
+
},
|
|
18981
|
+
},
|
|
18982
|
+
/**/
|
|
18983
|
+
/**/
|
|
18733
18984
|
{
|
|
18734
18985
|
modelVariant: 'CHAT',
|
|
18735
18986
|
modelTitle: 'gpt-5-mini',
|
|
@@ -19434,6 +19685,32 @@ function isUnsupportedParameterError(error) {
|
|
|
19434
19685
|
errorMessage.includes('does not support'));
|
|
19435
19686
|
}
|
|
19436
19687
|
|
|
19688
|
+
/**
|
|
19689
|
+
* Provides access to the structured clone implementation when available.
|
|
19690
|
+
*/
|
|
19691
|
+
function getStructuredCloneFunction() {
|
|
19692
|
+
return globalThis.structuredClone;
|
|
19693
|
+
}
|
|
19694
|
+
/**
|
|
19695
|
+
* Checks whether the prompt is a chat prompt that carries file attachments.
|
|
19696
|
+
*/
|
|
19697
|
+
function hasChatPromptFiles(prompt) {
|
|
19698
|
+
return 'files' in prompt && Array.isArray(prompt.files);
|
|
19699
|
+
}
|
|
19700
|
+
/**
|
|
19701
|
+
* Creates a deep copy of the prompt while keeping attached files intact when structured clone is not available.
|
|
19702
|
+
*/
|
|
19703
|
+
function clonePromptPreservingFiles(prompt) {
|
|
19704
|
+
const structuredCloneFn = getStructuredCloneFunction();
|
|
19705
|
+
if (typeof structuredCloneFn === 'function') {
|
|
19706
|
+
return structuredCloneFn(prompt);
|
|
19707
|
+
}
|
|
19708
|
+
const clonedPrompt = JSON.parse(JSON.stringify(prompt));
|
|
19709
|
+
if (hasChatPromptFiles(prompt)) {
|
|
19710
|
+
clonedPrompt.files = prompt.files;
|
|
19711
|
+
}
|
|
19712
|
+
return clonedPrompt;
|
|
19713
|
+
}
|
|
19437
19714
|
/**
|
|
19438
19715
|
* Execution Tools for calling OpenAI API or other OpenAI compatible provider
|
|
19439
19716
|
*
|
|
@@ -19518,7 +19795,7 @@ class OpenAiCompatibleExecutionTools {
|
|
|
19518
19795
|
*/
|
|
19519
19796
|
async callChatModelStream(prompt, onProgress) {
|
|
19520
19797
|
// Deep clone prompt and modelRequirements to avoid mutation across calls
|
|
19521
|
-
const clonedPrompt =
|
|
19798
|
+
const clonedPrompt = clonePromptPreservingFiles(prompt);
|
|
19522
19799
|
// Use local Set for retried parameters to ensure independence and thread safety
|
|
19523
19800
|
const retriedUnsupportedParameters = new Set();
|
|
19524
19801
|
return this.callChatModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters, onProgress);
|
|
@@ -19545,7 +19822,10 @@ class OpenAiCompatibleExecutionTools {
|
|
|
19545
19822
|
// <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
|
|
19546
19823
|
// <- Note: [🧆]
|
|
19547
19824
|
}; // <- TODO: [💩] Guard here types better
|
|
19548
|
-
if (
|
|
19825
|
+
if (currentModelRequirements.responseFormat !== undefined) {
|
|
19826
|
+
modelSettings.response_format = currentModelRequirements.responseFormat;
|
|
19827
|
+
}
|
|
19828
|
+
else if (format === 'JSON') {
|
|
19549
19829
|
modelSettings.response_format = {
|
|
19550
19830
|
type: 'json_object',
|
|
19551
19831
|
};
|
|
@@ -21026,7 +21306,9 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
|
|
|
21026
21306
|
const processingStartedAtMs = Date.now();
|
|
21027
21307
|
for (const [index, source] of knowledgeSources.entries()) {
|
|
21028
21308
|
try {
|
|
21029
|
-
const
|
|
21309
|
+
const isDataUrl = isDataUrlKnowledgeSource(source);
|
|
21310
|
+
const isHttp = source.startsWith('http://') || source.startsWith('https://');
|
|
21311
|
+
const sourceType = isDataUrl ? 'data_url' : isHttp ? 'url' : 'file';
|
|
21030
21312
|
if (this.options.isVerbose) {
|
|
21031
21313
|
console.info('[🤰]', 'Processing knowledge source', {
|
|
21032
21314
|
index: index + 1,
|
|
@@ -21036,8 +21318,27 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
|
|
|
21036
21318
|
logLabel,
|
|
21037
21319
|
});
|
|
21038
21320
|
}
|
|
21039
|
-
|
|
21040
|
-
|
|
21321
|
+
if (isDataUrl) {
|
|
21322
|
+
const parsed = parseDataUrlKnowledgeSource(source);
|
|
21323
|
+
if (!parsed) {
|
|
21324
|
+
skippedSources.push({ source, reason: 'invalid_data_url' });
|
|
21325
|
+
if (this.options.isVerbose) {
|
|
21326
|
+
console.info('[🤰]', 'Skipping knowledge source (invalid data URL)', {
|
|
21327
|
+
source,
|
|
21328
|
+
sourceType,
|
|
21329
|
+
logLabel,
|
|
21330
|
+
});
|
|
21331
|
+
}
|
|
21332
|
+
continue;
|
|
21333
|
+
}
|
|
21334
|
+
const dataUrlFile = new File([parsed.buffer], parsed.filename, {
|
|
21335
|
+
type: parsed.mimeType,
|
|
21336
|
+
});
|
|
21337
|
+
fileStreams.push(dataUrlFile);
|
|
21338
|
+
totalBytes += parsed.buffer.length;
|
|
21339
|
+
continue;
|
|
21340
|
+
}
|
|
21341
|
+
if (isHttp) {
|
|
21041
21342
|
const downloadResult = await this.downloadKnowledgeSourceFile({
|
|
21042
21343
|
source,
|
|
21043
21344
|
timeoutMs: downloadTimeoutMs,
|
|
@@ -21139,6 +21440,64 @@ class OpenAiVectorStoreHandler extends OpenAiExecutionTools {
|
|
|
21139
21440
|
}
|
|
21140
21441
|
|
|
21141
21442
|
const DEFAULT_AGENT_KIT_MODEL_NAME = 'gpt-5.2';
|
|
21443
|
+
const DEFAULT_JSON_SCHEMA_NAME = 'StructuredOutput';
|
|
21444
|
+
/*
|
|
21445
|
+
TODO: Use or remove
|
|
21446
|
+
const EMPTY_JSON_SCHEMA: JsonSchemaDefinition['schema'] = {
|
|
21447
|
+
type: 'object',
|
|
21448
|
+
properties: {},
|
|
21449
|
+
required: [],
|
|
21450
|
+
additionalProperties: true,
|
|
21451
|
+
};
|
|
21452
|
+
*/
|
|
21453
|
+
function buildJsonSchemaDefinition(jsonSchema) {
|
|
21454
|
+
var _a, _b, _c;
|
|
21455
|
+
const schema = (_a = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.schema) !== null && _a !== void 0 ? _a : {};
|
|
21456
|
+
return {
|
|
21457
|
+
type: 'json_schema',
|
|
21458
|
+
name: (_b = jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.name) !== null && _b !== void 0 ? _b : DEFAULT_JSON_SCHEMA_NAME,
|
|
21459
|
+
strict: Boolean(jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.strict),
|
|
21460
|
+
schema: {
|
|
21461
|
+
type: 'object',
|
|
21462
|
+
properties: ((_c = schema.properties) !== null && _c !== void 0 ? _c : {}),
|
|
21463
|
+
required: Array.isArray(schema.required) ? schema.required : [],
|
|
21464
|
+
additionalProperties: schema.additionalProperties === undefined ? true : Boolean(schema.additionalProperties),
|
|
21465
|
+
description: schema.description,
|
|
21466
|
+
},
|
|
21467
|
+
};
|
|
21468
|
+
}
|
|
21469
|
+
/**
|
|
21470
|
+
* Maps OpenAI `response_format` payloads to AgentKit output types so the runner can forward
|
|
21471
|
+
* structured-output preferences to OpenAI while still reusing the same AgentKit agent instance.
|
|
21472
|
+
*
|
|
21473
|
+
* @param responseFormat - The OpenAI `response_format` payload from the user request.
|
|
21474
|
+
* @returns An Agent output type compatible with the requested schema or `undefined` when no impact is required.
|
|
21475
|
+
* @private utility of Open AI
|
|
21476
|
+
*/
|
|
21477
|
+
function mapResponseFormatToAgentOutputType(responseFormat) {
|
|
21478
|
+
if (!responseFormat) {
|
|
21479
|
+
return undefined;
|
|
21480
|
+
}
|
|
21481
|
+
if (typeof responseFormat === 'string') {
|
|
21482
|
+
if (responseFormat === 'text') {
|
|
21483
|
+
return 'text';
|
|
21484
|
+
}
|
|
21485
|
+
if (responseFormat === 'json_schema' || responseFormat === 'json_object') {
|
|
21486
|
+
return buildJsonSchemaDefinition();
|
|
21487
|
+
}
|
|
21488
|
+
return 'text';
|
|
21489
|
+
}
|
|
21490
|
+
switch (responseFormat.type) {
|
|
21491
|
+
case 'text':
|
|
21492
|
+
return 'text';
|
|
21493
|
+
case 'json_schema':
|
|
21494
|
+
return buildJsonSchemaDefinition(responseFormat.json_schema);
|
|
21495
|
+
case 'json_object':
|
|
21496
|
+
return buildJsonSchemaDefinition();
|
|
21497
|
+
default:
|
|
21498
|
+
return undefined;
|
|
21499
|
+
}
|
|
21500
|
+
}
|
|
21142
21501
|
/**
|
|
21143
21502
|
* Execution tools for OpenAI AgentKit (Agents SDK).
|
|
21144
21503
|
*
|
|
@@ -21186,6 +21545,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
21186
21545
|
...parameters,
|
|
21187
21546
|
modelName: this.agentKitModelName,
|
|
21188
21547
|
});
|
|
21548
|
+
const responseFormatOutputType = mapResponseFormatToAgentOutputType(modelRequirements.responseFormat);
|
|
21189
21549
|
const preparedAgentKitAgent = await this.prepareAgentKitAgent({
|
|
21190
21550
|
name: (prompt.title || 'Agent'),
|
|
21191
21551
|
instructions: modelRequirements.systemMessage || '',
|
|
@@ -21197,6 +21557,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
21197
21557
|
prompt,
|
|
21198
21558
|
rawPromptContent,
|
|
21199
21559
|
onProgress,
|
|
21560
|
+
responseFormatOutputType,
|
|
21200
21561
|
});
|
|
21201
21562
|
}
|
|
21202
21563
|
/**
|
|
@@ -21378,16 +21739,21 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
21378
21739
|
...prompt.parameters,
|
|
21379
21740
|
modelName: this.agentKitModelName,
|
|
21380
21741
|
});
|
|
21742
|
+
const agentForRun = options.responseFormatOutputType !== undefined
|
|
21743
|
+
? openAiAgentKitAgent.clone({
|
|
21744
|
+
outputType: options.responseFormatOutputType,
|
|
21745
|
+
})
|
|
21746
|
+
: openAiAgentKitAgent;
|
|
21381
21747
|
const start = $getCurrentDate();
|
|
21382
21748
|
let latestContent = '';
|
|
21383
21749
|
const toolCalls = [];
|
|
21384
21750
|
const toolCallIndexById = new Map();
|
|
21385
21751
|
const inputItems = await this.buildAgentKitInputItems(prompt, rawPromptContent);
|
|
21386
21752
|
const rawRequest = {
|
|
21387
|
-
agentName:
|
|
21753
|
+
agentName: agentForRun.name,
|
|
21388
21754
|
input: inputItems,
|
|
21389
21755
|
};
|
|
21390
|
-
const streamResult = await run(
|
|
21756
|
+
const streamResult = await run(agentForRun, inputItems, {
|
|
21391
21757
|
stream: true,
|
|
21392
21758
|
context: { parameters: prompt.parameters },
|
|
21393
21759
|
});
|
|
@@ -22376,22 +22742,28 @@ class AgentLlmExecutionTools {
|
|
|
22376
22742
|
throw new Error('AgentLlmExecutionTools only supports chat prompts');
|
|
22377
22743
|
}
|
|
22378
22744
|
const modelRequirements = await this.getModelRequirements();
|
|
22745
|
+
const { _metadata, promptSuffix, ...sanitizedRequirements } = modelRequirements;
|
|
22379
22746
|
const chatPrompt = prompt;
|
|
22380
22747
|
let underlyingLlmResult;
|
|
22381
|
-
|
|
22748
|
+
const chatPromptContentWithSuffix = promptSuffix
|
|
22749
|
+
? `${chatPrompt.content}\n\n${promptSuffix}`
|
|
22750
|
+
: chatPrompt.content;
|
|
22382
22751
|
const promptWithAgentModelRequirements = {
|
|
22383
22752
|
...chatPrompt,
|
|
22753
|
+
content: chatPromptContentWithSuffix,
|
|
22384
22754
|
modelRequirements: {
|
|
22385
22755
|
...chatPrompt.modelRequirements,
|
|
22386
|
-
...
|
|
22756
|
+
...sanitizedRequirements,
|
|
22387
22757
|
// Spread tools to convert readonly array to mutable
|
|
22388
|
-
tools:
|
|
22758
|
+
tools: sanitizedRequirements.tools
|
|
22759
|
+
? [...sanitizedRequirements.tools]
|
|
22760
|
+
: chatPrompt.modelRequirements.tools,
|
|
22389
22761
|
// Spread knowledgeSources to convert readonly array to mutable
|
|
22390
|
-
knowledgeSources:
|
|
22391
|
-
? [...
|
|
22762
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources
|
|
22763
|
+
? [...sanitizedRequirements.knowledgeSources]
|
|
22392
22764
|
: undefined,
|
|
22393
22765
|
// Prepend agent system message to existing system message
|
|
22394
|
-
systemMessage:
|
|
22766
|
+
systemMessage: sanitizedRequirements.systemMessage +
|
|
22395
22767
|
(chatPrompt.modelRequirements.systemMessage
|
|
22396
22768
|
? `\n\n${chatPrompt.modelRequirements.systemMessage}`
|
|
22397
22769
|
: ''),
|
|
@@ -22399,8 +22771,8 @@ class AgentLlmExecutionTools {
|
|
|
22399
22771
|
};
|
|
22400
22772
|
console.log('!!!! promptWithAgentModelRequirements:', promptWithAgentModelRequirements);
|
|
22401
22773
|
if (OpenAiAgentKitExecutionTools.isOpenAiAgentKitExecutionTools(this.options.llmTools)) {
|
|
22402
|
-
const requirementsHash = SHA256(JSON.stringify(
|
|
22403
|
-
const vectorStoreHash = SHA256(JSON.stringify((_a =
|
|
22774
|
+
const requirementsHash = SHA256(JSON.stringify(sanitizedRequirements)).toString();
|
|
22775
|
+
const vectorStoreHash = SHA256(JSON.stringify((_a = sanitizedRequirements.knowledgeSources) !== null && _a !== void 0 ? _a : [])).toString();
|
|
22404
22776
|
const cachedVectorStore = AgentLlmExecutionTools.vectorStoreCache.get(this.title);
|
|
22405
22777
|
const cachedAgentKit = AgentLlmExecutionTools.agentKitAgentCache.get(this.title);
|
|
22406
22778
|
let preparedAgentKit = this.options.assistantPreparationMode === 'external'
|
|
@@ -22427,7 +22799,7 @@ class AgentLlmExecutionTools {
|
|
|
22427
22799
|
agent: this.title,
|
|
22428
22800
|
});
|
|
22429
22801
|
}
|
|
22430
|
-
if (!vectorStoreId && ((_b =
|
|
22802
|
+
if (!vectorStoreId && ((_b = sanitizedRequirements.knowledgeSources) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
22431
22803
|
emitAssistantPreparationProgress({
|
|
22432
22804
|
onProgress,
|
|
22433
22805
|
prompt,
|
|
@@ -22443,9 +22815,9 @@ class AgentLlmExecutionTools {
|
|
|
22443
22815
|
});
|
|
22444
22816
|
preparedAgentKit = await this.options.llmTools.prepareAgentKitAgent({
|
|
22445
22817
|
name: this.title,
|
|
22446
|
-
instructions:
|
|
22447
|
-
knowledgeSources:
|
|
22448
|
-
tools:
|
|
22818
|
+
instructions: sanitizedRequirements.systemMessage || '',
|
|
22819
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources,
|
|
22820
|
+
tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
|
|
22449
22821
|
vectorStoreId,
|
|
22450
22822
|
});
|
|
22451
22823
|
}
|
|
@@ -22460,15 +22832,17 @@ class AgentLlmExecutionTools {
|
|
|
22460
22832
|
requirementsHash,
|
|
22461
22833
|
vectorStoreId: preparedAgentKit.vectorStoreId,
|
|
22462
22834
|
});
|
|
22835
|
+
const responseFormatOutputType = mapResponseFormatToAgentOutputType(promptWithAgentModelRequirements.modelRequirements.responseFormat);
|
|
22463
22836
|
underlyingLlmResult = await this.options.llmTools.callChatModelStreamWithPreparedAgent({
|
|
22464
22837
|
openAiAgentKitAgent: preparedAgentKit.agent,
|
|
22465
22838
|
prompt: promptWithAgentModelRequirements,
|
|
22466
22839
|
onProgress,
|
|
22840
|
+
responseFormatOutputType,
|
|
22467
22841
|
});
|
|
22468
22842
|
}
|
|
22469
22843
|
else if (OpenAiAssistantExecutionTools.isOpenAiAssistantExecutionTools(this.options.llmTools)) {
|
|
22470
22844
|
// ... deprecated path ...
|
|
22471
|
-
const requirementsHash = SHA256(JSON.stringify(
|
|
22845
|
+
const requirementsHash = SHA256(JSON.stringify(sanitizedRequirements)).toString();
|
|
22472
22846
|
const cached = AgentLlmExecutionTools.assistantCache.get(this.title);
|
|
22473
22847
|
let assistant;
|
|
22474
22848
|
if (this.options.assistantPreparationMode === 'external') {
|
|
@@ -22510,9 +22884,9 @@ class AgentLlmExecutionTools {
|
|
|
22510
22884
|
assistant = await this.options.llmTools.updateAssistant({
|
|
22511
22885
|
assistantId: cached.assistantId,
|
|
22512
22886
|
name: this.title,
|
|
22513
|
-
instructions:
|
|
22514
|
-
knowledgeSources:
|
|
22515
|
-
tools:
|
|
22887
|
+
instructions: sanitizedRequirements.systemMessage,
|
|
22888
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources,
|
|
22889
|
+
tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
|
|
22516
22890
|
});
|
|
22517
22891
|
AgentLlmExecutionTools.assistantCache.set(this.title, {
|
|
22518
22892
|
assistantId: assistant.assistantId,
|
|
@@ -22535,9 +22909,9 @@ class AgentLlmExecutionTools {
|
|
|
22535
22909
|
});
|
|
22536
22910
|
assistant = await this.options.llmTools.createNewAssistant({
|
|
22537
22911
|
name: this.title,
|
|
22538
|
-
instructions:
|
|
22539
|
-
knowledgeSources:
|
|
22540
|
-
tools:
|
|
22912
|
+
instructions: sanitizedRequirements.systemMessage,
|
|
22913
|
+
knowledgeSources: sanitizedRequirements.knowledgeSources,
|
|
22914
|
+
tools: sanitizedRequirements.tools ? [...sanitizedRequirements.tools] : undefined,
|
|
22541
22915
|
/*
|
|
22542
22916
|
!!!
|
|
22543
22917
|
metadata: {
|
|
@@ -22579,13 +22953,19 @@ class AgentLlmExecutionTools {
|
|
|
22579
22953
|
}
|
|
22580
22954
|
}
|
|
22581
22955
|
let content = underlyingLlmResult.content;
|
|
22582
|
-
|
|
22583
|
-
|
|
22584
|
-
|
|
22585
|
-
|
|
22956
|
+
if (typeof content === 'string') {
|
|
22957
|
+
// Note: Cleanup the AI artifacts from the content
|
|
22958
|
+
content = humanizeAiText(content);
|
|
22959
|
+
// Note: Make sure the content is Promptbook-like
|
|
22960
|
+
content = promptbookifyAiText(content);
|
|
22961
|
+
}
|
|
22962
|
+
else {
|
|
22963
|
+
// TODO: Maybe deep `humanizeAiText` + `promptbookifyAiText` inside of the object
|
|
22964
|
+
content = JSON.stringify(content);
|
|
22965
|
+
}
|
|
22586
22966
|
const agentResult = {
|
|
22587
22967
|
...underlyingLlmResult,
|
|
22588
|
-
content,
|
|
22968
|
+
content: content,
|
|
22589
22969
|
modelName: this.modelName,
|
|
22590
22970
|
};
|
|
22591
22971
|
return agentResult;
|
|
@@ -22774,7 +23154,6 @@ class Agent extends AgentLlmExecutionTools {
|
|
|
22774
23154
|
* Note: This method also implements the learning mechanism
|
|
22775
23155
|
*/
|
|
22776
23156
|
async callChatModelStream(prompt, onProgress) {
|
|
22777
|
-
var _a;
|
|
22778
23157
|
// [1] Check if the user is asking the same thing as in the samples
|
|
22779
23158
|
const modelRequirements = await this.getModelRequirements();
|
|
22780
23159
|
if (modelRequirements.samples) {
|
|
@@ -22822,7 +23201,7 @@ class Agent extends AgentLlmExecutionTools {
|
|
|
22822
23201
|
if (result.rawResponse && 'sample' in result.rawResponse) {
|
|
22823
23202
|
return result;
|
|
22824
23203
|
}
|
|
22825
|
-
if (
|
|
23204
|
+
if (modelRequirements.isClosed) {
|
|
22826
23205
|
return result;
|
|
22827
23206
|
}
|
|
22828
23207
|
// Note: [0] Notify start of self-learning
|
|
@@ -23212,26 +23591,7 @@ class RemoteAgent extends Agent {
|
|
|
23212
23591
|
};
|
|
23213
23592
|
};
|
|
23214
23593
|
const getToolCallKey = (toolCall) => {
|
|
23215
|
-
|
|
23216
|
-
const rawId = (_a = toolCall.rawToolCall) === null || _a === void 0 ? void 0 : _a.id;
|
|
23217
|
-
if (rawId) {
|
|
23218
|
-
return `id:${rawId}`;
|
|
23219
|
-
}
|
|
23220
|
-
const argsKey = (() => {
|
|
23221
|
-
if (typeof toolCall.arguments === 'string') {
|
|
23222
|
-
return toolCall.arguments;
|
|
23223
|
-
}
|
|
23224
|
-
if (!toolCall.arguments) {
|
|
23225
|
-
return '';
|
|
23226
|
-
}
|
|
23227
|
-
try {
|
|
23228
|
-
return JSON.stringify(toolCall.arguments);
|
|
23229
|
-
}
|
|
23230
|
-
catch (_a) {
|
|
23231
|
-
return '';
|
|
23232
|
-
}
|
|
23233
|
-
})();
|
|
23234
|
-
return `${toolCall.name}:${toolCall.createdAt || ''}:${argsKey}`;
|
|
23594
|
+
return getToolCallIdentity(toolCall);
|
|
23235
23595
|
};
|
|
23236
23596
|
const mergeToolCall = (existing, incoming) => {
|
|
23237
23597
|
const incomingResult = incoming.result;
|