@promptbook/openai 0.110.0 → 0.111.0-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 (29) hide show
  1. package/README.md +4 -0
  2. package/esm/index.es.js +55 -29
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/utils.index.d.ts +12 -0
  5. package/esm/typings/src/book-2.0/agent-source/BookEditable.d.ts +41 -0
  6. package/esm/typings/src/book-2.0/agent-source/CreateAgentModelRequirementsOptions.d.ts +5 -0
  7. package/esm/typings/src/book-components/Chat/Chat/ImagePromptRenderer.d.ts +21 -0
  8. package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +5 -0
  9. package/esm/typings/src/book-components/Chat/LlmChat/defaults.d.ts +9 -0
  10. package/esm/typings/src/book-components/Chat/save/_common/ChatSaveFormatDefinition.d.ts +7 -1
  11. package/esm/typings/src/book-components/Chat/save/html/htmlSaveFormatDefinition.d.ts +6 -5
  12. package/esm/typings/src/book-components/Chat/save/index.d.ts +3 -3
  13. package/esm/typings/src/book-components/Chat/save/pdf/buildChatPdf.d.ts +11 -0
  14. package/esm/typings/src/book-components/Chat/save/pdf/pdfSaveFormatDefinition.d.ts +2 -2
  15. package/esm/typings/src/book-components/Chat/utils/parseImagePrompts.d.ts +42 -0
  16. package/esm/typings/src/book-components/Chat/utils/parseImagePrompts.test.d.ts +1 -0
  17. package/esm/typings/src/commitments/MEMORY/MEMORY.d.ts +67 -0
  18. package/esm/typings/src/commitments/MEMORY/MEMORY.test.d.ts +1 -0
  19. package/esm/typings/src/commitments/_common/toolRuntimeContext.d.ts +49 -0
  20. package/esm/typings/src/constants/streaming.d.ts +20 -0
  21. package/esm/typings/src/llm-providers/openai/utils/buildToolInvocationScript.d.ts +9 -0
  22. package/esm/typings/src/utils/clientVersion.d.ts +51 -0
  23. package/esm/typings/src/utils/knowledge/inlineKnowledgeSource.d.ts +13 -9
  24. package/esm/typings/src/utils/normalization/constructImageFilename.d.ts +18 -0
  25. package/esm/typings/src/utils/normalization/constructImageFilename.test.d.ts +1 -0
  26. package/esm/typings/src/version.d.ts +1 -1
  27. package/package.json +2 -2
  28. package/umd/index.umd.js +55 -29
  29. package/umd/index.umd.js.map +1 -1
package/README.md CHANGED
@@ -27,6 +27,10 @@ Turn your company's scattered knowledge into AI ready Books
27
27
 
28
28
 
29
29
 
30
+ <blockquote style="color: #ff8811">
31
+ <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
32
+ </blockquote>
33
+
30
34
  ## 📦 Package `@promptbook/openai`
31
35
 
32
36
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
package/esm/index.es.js CHANGED
@@ -23,7 +23,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
23
23
  * @generated
24
24
  * @see https://github.com/webgptorg/promptbook
25
25
  */
26
- const PROMPTBOOK_ENGINE_VERSION = '0.110.0';
26
+ const PROMPTBOOK_ENGINE_VERSION = '0.111.0-0';
27
27
  /**
28
28
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
29
29
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -3480,6 +3480,44 @@ function mapToolsToOpenAi(tools) {
3480
3480
  }));
3481
3481
  }
3482
3482
 
3483
+ /**
3484
+ * Prompt parameter key used to pass hidden runtime context to tool execution.
3485
+ *
3486
+ * @private internal runtime wiring for commitment tools
3487
+ */
3488
+ const TOOL_RUNTIME_CONTEXT_PARAMETER = 'promptbookToolRuntimeContext';
3489
+ /**
3490
+ * Hidden argument key used to pass runtime context into individual tool calls.
3491
+ *
3492
+ * @private internal runtime wiring for commitment tools
3493
+ */
3494
+ const TOOL_RUNTIME_CONTEXT_ARGUMENT = '__promptbookToolRuntimeContext';
3495
+ /**
3496
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3497
+ */
3498
+
3499
+ /**
3500
+ * Builds a tool invocation script that injects hidden runtime context into tool args.
3501
+ *
3502
+ * @private utility of OpenAI tool execution wrappers
3503
+ */
3504
+ function buildToolInvocationScript(options) {
3505
+ const { functionName, functionArgsExpression } = options;
3506
+ return `
3507
+ const args = ${functionArgsExpression};
3508
+ const runtimeContextRaw =
3509
+ typeof ${TOOL_RUNTIME_CONTEXT_PARAMETER} === 'undefined'
3510
+ ? undefined
3511
+ : ${TOOL_RUNTIME_CONTEXT_PARAMETER};
3512
+
3513
+ if (runtimeContextRaw !== undefined && args && typeof args === 'object' && !Array.isArray(args)) {
3514
+ args.${TOOL_RUNTIME_CONTEXT_ARGUMENT} = runtimeContextRaw;
3515
+ }
3516
+
3517
+ return await ${functionName}(args);
3518
+ `;
3519
+ }
3520
+
3483
3521
  /**
3484
3522
  * Parses an OpenAI error message to identify which parameter is unsupported
3485
3523
  *
@@ -3833,10 +3871,10 @@ class OpenAiCompatibleExecutionTools {
3833
3871
  const scriptTool = scriptTools[0]; // <- TODO: [🧠] Which script tool to use?
3834
3872
  functionResponse = await scriptTool.execute({
3835
3873
  scriptLanguage: 'javascript',
3836
- script: `
3837
- const args = ${functionArgs};
3838
- return await ${functionName}(args);
3839
- `,
3874
+ script: buildToolInvocationScript({
3875
+ functionName,
3876
+ functionArgsExpression: functionArgs,
3877
+ }),
3840
3878
  parameters: prompt.parameters,
3841
3879
  });
3842
3880
  }
@@ -4521,23 +4559,11 @@ class OpenAiExecutionTools extends OpenAiCompatibleExecutionTools {
4521
4559
  }
4522
4560
  }
4523
4561
 
4524
- /**
4525
- * @@@
4526
- *
4527
- * @private thing of inline knowledge
4528
- */
4562
+ /** @private The default base name for inline knowledge files when the content lacks identifying text */
4529
4563
  const INLINE_KNOWLEDGE_BASE_NAME = 'inline-knowledge';
4530
- /**
4531
- * @@@
4532
- *
4533
- * @private thing of inline knowledge
4534
- */
4564
+ /** @private The default file extension used for inline knowledge uploads */
4535
4565
  const INLINE_KNOWLEDGE_EXTENSION = '.txt';
4536
- /**
4537
- * @@@
4538
- *
4539
- * @private thing of inline knowledge
4540
- */
4566
+ /** @private Prefix that identifies base64 data URLs */
4541
4567
  const DATA_URL_PREFIX = 'data:';
4542
4568
  /**
4543
4569
  * Checks whether the provided source string is a data URL that can be decoded.
@@ -4550,7 +4576,7 @@ function isDataUrlKnowledgeSource(source) {
4550
4576
  /**
4551
4577
  * Parses a data URL-based knowledge source into its raw buffer, filename, and MIME type.
4552
4578
  *
4553
- * @private thing of inline knowledge
4579
+ * @private utility of inline knowledge processing
4554
4580
  */
4555
4581
  function parseDataUrlKnowledgeSource(source) {
4556
4582
  if (!isDataUrlKnowledgeSource(source)) {
@@ -5592,10 +5618,10 @@ class OpenAiAssistantExecutionTools extends OpenAiVectorStoreHandler {
5592
5618
  const scriptTool = scriptTools[0]; // <- TODO: [🧠] Which script tool to use?
5593
5619
  functionResponse = await scriptTool.execute({
5594
5620
  scriptLanguage: 'javascript',
5595
- script: `
5596
- const args = ${JSON.stringify(functionArgs)};
5597
- return await ${functionName}(args);
5598
- `,
5621
+ script: buildToolInvocationScript({
5622
+ functionName,
5623
+ functionArgsExpression: JSON.stringify(functionArgs),
5624
+ }),
5599
5625
  parameters: prompt.parameters,
5600
5626
  });
5601
5627
  if (this.options.isVerbose) {
@@ -6586,10 +6612,10 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
6586
6612
  try {
6587
6613
  return await scriptTool.execute({
6588
6614
  scriptLanguage: 'javascript',
6589
- script: `
6590
- const args = ${JSON.stringify(functionArgs)};
6591
- return await ${functionName}(args);
6592
- `,
6615
+ script: buildToolInvocationScript({
6616
+ functionName,
6617
+ functionArgsExpression: JSON.stringify(functionArgs),
6618
+ }),
6593
6619
  parameters: (_c = (_b = runContext === null || runContext === void 0 ? void 0 : runContext.context) === null || _b === void 0 ? void 0 : _b.parameters) !== null && _c !== void 0 ? _c : {},
6594
6620
  });
6595
6621
  }