@promptbook/browser 0.110.0-8 → 0.110.0

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