@promptbook/legacy-documents 0.105.0-1 → 0.105.0-3

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 (38) hide show
  1. package/esm/index.es.js +90 -66
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/core.index.d.ts +2 -0
  4. package/esm/typings/src/_packages/types.index.d.ts +4 -0
  5. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +10 -3
  6. package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +11 -1
  7. package/esm/typings/src/book-2.0/agent-source/communication-samples.test.d.ts +1 -0
  8. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.blocks.test.d.ts +1 -0
  9. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.import.test.d.ts +1 -0
  10. package/esm/typings/src/book-2.0/agent-source/parseAgentSource.import.test.d.ts +1 -0
  11. package/esm/typings/src/book-2.0/agent-source/parseAgentSourceWithCommitments.blocks.test.d.ts +1 -0
  12. package/esm/typings/src/commitments/USE_TIME/USE_TIME.d.ts +40 -0
  13. package/esm/typings/src/commitments/USE_TIME/USE_TIME.test.d.ts +1 -0
  14. package/esm/typings/src/commitments/_base/BaseCommitmentDefinition.d.ts +8 -0
  15. package/esm/typings/src/commitments/_base/CommitmentDefinition.d.ts +8 -0
  16. package/esm/typings/src/commitments/index.d.ts +11 -2
  17. package/esm/typings/src/config.d.ts +1 -0
  18. package/esm/typings/src/import-plugins/$fileImportPlugins.d.ts +7 -0
  19. package/esm/typings/src/import-plugins/AgentFileImportPlugin.d.ts +7 -0
  20. package/esm/typings/src/import-plugins/FileImportPlugin.d.ts +24 -0
  21. package/esm/typings/src/import-plugins/JsonFileImportPlugin.d.ts +7 -0
  22. package/esm/typings/src/import-plugins/TextFileImportPlugin.d.ts +7 -0
  23. package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +2 -1
  24. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/countUsage.d.ts +2 -2
  25. package/esm/typings/src/llm-providers/agent/Agent.d.ts +9 -2
  26. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +3 -1
  27. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +10 -0
  28. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
  29. package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +6 -1
  30. package/esm/typings/src/types/ModelRequirements.d.ts +6 -12
  31. package/esm/typings/src/utils/execCommand/$execCommandNormalizeOptions.d.ts +2 -3
  32. package/esm/typings/src/utils/execCommand/ExecCommandOptions.d.ts +7 -1
  33. package/esm/typings/src/utils/organization/keepImported.d.ts +9 -0
  34. package/esm/typings/src/utils/organization/keepTypeImported.d.ts +0 -1
  35. package/esm/typings/src/version.d.ts +1 -1
  36. package/package.json +2 -2
  37. package/umd/index.umd.js +90 -66
  38. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -26,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
26
26
  * @generated
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- const PROMPTBOOK_ENGINE_VERSION = '0.105.0-1';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-3';
30
30
  /**
31
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
32
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -988,6 +988,7 @@ const PROMPTBOOK_COLOR = Color.fromString('promptbook');
988
988
  SEPARATOR: Color.fromHex('#cccccc'),
989
989
  COMMITMENT: Color.fromHex('#DA0F78'),
990
990
  PARAMETER: Color.fromHex('#8e44ad'),
991
+ CODE_BLOCK: Color.fromHex('#7700ffff'),
991
992
  });
992
993
  // <- TODO: [🧠][🈵] Using `Color` here increases the package size approx 3kb, maybe remove it
993
994
  /**
@@ -1309,6 +1310,7 @@ function $execCommandNormalizeOptions(options) {
1309
1310
  let args = [];
1310
1311
  let timeout;
1311
1312
  let isVerbose;
1313
+ let env;
1312
1314
  if (typeof options === 'string') {
1313
1315
  // TODO: [1] DRY default values
1314
1316
  command = options;
@@ -1316,6 +1318,7 @@ function $execCommandNormalizeOptions(options) {
1316
1318
  crashOnError = true;
1317
1319
  timeout = Infinity; // <- TODO: [⏳]
1318
1320
  isVerbose = DEFAULT_IS_VERBOSE;
1321
+ env = undefined;
1319
1322
  }
1320
1323
  else {
1321
1324
  /*
@@ -1332,6 +1335,7 @@ function $execCommandNormalizeOptions(options) {
1332
1335
  crashOnError = (_b = options.crashOnError) !== null && _b !== void 0 ? _b : true;
1333
1336
  timeout = (_c = options.timeout) !== null && _c !== void 0 ? _c : Infinity;
1334
1337
  isVerbose = (_d = options.isVerbose) !== null && _d !== void 0 ? _d : DEFAULT_IS_VERBOSE;
1338
+ env = options.env;
1335
1339
  }
1336
1340
  // TODO: /(-[a-zA-Z0-9-]+\s+[^\s]*)|[^\s]*/g
1337
1341
  const _ = Array.from(command.matchAll(/(".*")|([^\s]*)/g))
@@ -1350,7 +1354,7 @@ function $execCommandNormalizeOptions(options) {
1350
1354
  if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
1351
1355
  command = `${command}.cmd`;
1352
1356
  }
1353
- return { command, humanReadableCommand, args, cwd, crashOnError, timeout, isVerbose };
1357
+ return { command, humanReadableCommand, args, cwd, crashOnError, timeout, isVerbose, env };
1354
1358
  }
1355
1359
  // TODO: This should show type error> execCommandNormalizeOptions({ command: '', commands: [''] });
1356
1360
 
@@ -1371,7 +1375,7 @@ function $execCommand(options) {
1371
1375
  }
1372
1376
  return new Promise((resolve, reject) => {
1373
1377
  // eslint-disable-next-line prefer-const
1374
- const { command, humanReadableCommand, args, cwd, crashOnError, timeout, isVerbose = DEFAULT_IS_VERBOSE, } = $execCommandNormalizeOptions(options);
1378
+ const { command, humanReadableCommand, args, cwd, crashOnError, timeout, isVerbose = DEFAULT_IS_VERBOSE, env, } = $execCommandNormalizeOptions(options);
1375
1379
  if (timeout !== Infinity) {
1376
1380
  // TODO: In waitasecond forTime(Infinity) should be equivalent to forEver()
1377
1381
  forTime(timeout).then(() => {
@@ -1389,7 +1393,11 @@ function $execCommand(options) {
1389
1393
  console.info(colors.yellow(cwd) + ' ' + colors.green(command) + ' ' + colors.blue(args.join(' ')));
1390
1394
  }
1391
1395
  try {
1392
- const commandProcess = spawn(command, args, { cwd, shell: true });
1396
+ const commandProcess = spawn(command, args, {
1397
+ cwd,
1398
+ shell: true,
1399
+ env: env ? { ...process.env, ...env } : process.env,
1400
+ });
1393
1401
  if (isVerbose) {
1394
1402
  commandProcess.on('message', (message) => {
1395
1403
  console.info({ message });
@@ -3994,74 +4002,90 @@ function addUsage(...usageItems) {
3994
4002
  * in real-time through an observable.
3995
4003
  *
3996
4004
  * @param llmTools - The LLM tools to be intercepted and tracked
3997
- * @returns An augmented version of the tools that includes usage tracking capabilities
4005
+ * @returns Full proxy of the tools with added usage tracking capabilities
3998
4006
  * @public exported from `@promptbook/core`
3999
4007
  */
4000
4008
  function countUsage(llmTools) {
4001
4009
  let totalUsage = ZERO_USAGE;
4002
4010
  const spending = new Subject();
4003
- const proxyTools = {
4004
- get title() {
4005
- return `${llmTools.title} (+usage)`;
4006
- // <- TODO: [🧈] Maybe standartize the suffix when wrapping `LlmExecutionTools` up
4007
- // <- TODO: [🧈][🧠] Does it make sense to suffix "(+usage)"?
4008
- },
4009
- get description() {
4010
- return `${llmTools.description} (+usage)`;
4011
- // <- TODO: [🧈] Maybe standartize the suffix when wrapping `LlmExecutionTools` up
4012
- // <- TODO: [🧈][🧠] Does it make sense to suffix "(+usage)"?
4013
- },
4014
- checkConfiguration() {
4015
- return /* not await */ llmTools.checkConfiguration();
4016
- },
4017
- listModels() {
4018
- return /* not await */ llmTools.listModels();
4019
- },
4020
- spending() {
4021
- return spending.asObservable();
4022
- },
4023
- getTotalUsage() {
4024
- // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
4025
- return totalUsage;
4011
+ // Create a Proxy to intercept all property access and ensure full proxying of all properties
4012
+ const proxyTools = new Proxy(llmTools, {
4013
+ get(target, prop, receiver) {
4014
+ // Handle title property
4015
+ if (prop === 'title') {
4016
+ return `${target.title} (+usage)`;
4017
+ // <- TODO: [🧈] Maybe standartize the suffix when wrapping `LlmExecutionTools` up
4018
+ // <- TODO: [🧈][🧠] Does it make sense to suffix "(+usage)"?
4019
+ }
4020
+ // Handle description property
4021
+ if (prop === 'description') {
4022
+ return `${target.description} (+usage)`;
4023
+ // <- TODO: [🧈] Maybe standartize the suffix when wrapping `LlmExecutionTools` up
4024
+ // <- TODO: [🧈][🧠] Does it make sense to suffix "(+usage)"?
4025
+ }
4026
+ // Handle spending method (new method added by this wrapper)
4027
+ if (prop === 'spending') {
4028
+ return () => {
4029
+ return spending.asObservable();
4030
+ };
4031
+ }
4032
+ // Handle getTotalUsage method (new method added by this wrapper)
4033
+ if (prop === 'getTotalUsage') {
4034
+ // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
4035
+ return () => {
4036
+ return totalUsage;
4037
+ };
4038
+ }
4039
+ // Handle callChatModel method with usage counting
4040
+ if (prop === 'callChatModel' && target.callChatModel !== undefined) {
4041
+ return async (prompt) => {
4042
+ // console.info('[🚕] callChatModel through countTotalUsage');
4043
+ const promptResult = await target.callChatModel(prompt);
4044
+ totalUsage = addUsage(totalUsage, promptResult.usage);
4045
+ spending.next(promptResult.usage);
4046
+ return promptResult;
4047
+ };
4048
+ }
4049
+ // Handle callCompletionModel method with usage counting
4050
+ if (prop === 'callCompletionModel' && target.callCompletionModel !== undefined) {
4051
+ return async (prompt) => {
4052
+ // console.info('[🚕] callCompletionModel through countTotalUsage');
4053
+ const promptResult = await target.callCompletionModel(prompt);
4054
+ totalUsage = addUsage(totalUsage, promptResult.usage);
4055
+ spending.next(promptResult.usage);
4056
+ return promptResult;
4057
+ };
4058
+ }
4059
+ // Handle callEmbeddingModel method with usage counting
4060
+ if (prop === 'callEmbeddingModel' && target.callEmbeddingModel !== undefined) {
4061
+ return async (prompt) => {
4062
+ // console.info('[🚕] callEmbeddingModel through countTotalUsage');
4063
+ const promptResult = await target.callEmbeddingModel(prompt);
4064
+ totalUsage = addUsage(totalUsage, promptResult.usage);
4065
+ spending.next(promptResult.usage);
4066
+ return promptResult;
4067
+ };
4068
+ }
4069
+ // Handle callImageGenerationModel method with usage counting
4070
+ if (prop === 'callImageGenerationModel' && target.callImageGenerationModel !== undefined) {
4071
+ return async (prompt) => {
4072
+ // console.info('[🚕] callImageGenerationModel through countTotalUsage');
4073
+ const promptResult = await target.callImageGenerationModel(prompt);
4074
+ totalUsage = addUsage(totalUsage, promptResult.usage);
4075
+ spending.next(promptResult.usage);
4076
+ return promptResult;
4077
+ };
4078
+ }
4079
+ // <- Note: [🤖]
4080
+ // For all other properties and methods, delegate to the original target
4081
+ const value = Reflect.get(target, prop, receiver);
4082
+ // If it's a function, bind it to the target to preserve context
4083
+ if (typeof value === 'function') {
4084
+ return value.bind(target);
4085
+ }
4086
+ return value;
4026
4087
  },
4027
- };
4028
- if (llmTools.callChatModel !== undefined) {
4029
- proxyTools.callChatModel = async (prompt) => {
4030
- // console.info('[🚕] callChatModel through countTotalUsage');
4031
- const promptResult = await llmTools.callChatModel(prompt);
4032
- totalUsage = addUsage(totalUsage, promptResult.usage);
4033
- spending.next(promptResult.usage);
4034
- return promptResult;
4035
- };
4036
- }
4037
- if (llmTools.callCompletionModel !== undefined) {
4038
- proxyTools.callCompletionModel = async (prompt) => {
4039
- // console.info('[🚕] callCompletionModel through countTotalUsage');
4040
- const promptResult = await llmTools.callCompletionModel(prompt);
4041
- totalUsage = addUsage(totalUsage, promptResult.usage);
4042
- spending.next(promptResult.usage);
4043
- return promptResult;
4044
- };
4045
- }
4046
- if (llmTools.callEmbeddingModel !== undefined) {
4047
- proxyTools.callEmbeddingModel = async (prompt) => {
4048
- // console.info('[🚕] callEmbeddingModel through countTotalUsage');
4049
- const promptResult = await llmTools.callEmbeddingModel(prompt);
4050
- totalUsage = addUsage(totalUsage, promptResult.usage);
4051
- spending.next(promptResult.usage);
4052
- return promptResult;
4053
- };
4054
- }
4055
- if (llmTools.callImageGenerationModel !== undefined) {
4056
- proxyTools.callImageGenerationModel = async (prompt) => {
4057
- // console.info('[🚕] callImageGenerationModel through countTotalUsage');
4058
- const promptResult = await llmTools.callImageGenerationModel(prompt);
4059
- totalUsage = addUsage(totalUsage, promptResult.usage);
4060
- spending.next(promptResult.usage);
4061
- return promptResult;
4062
- };
4063
- }
4064
- // <- Note: [🤖]
4088
+ });
4065
4089
  return proxyTools;
4066
4090
  }
4067
4091
  /**