@promptbook/wizard 0.104.0-1 → 0.104.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 (31) hide show
  1. package/esm/index.es.js +194 -34
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/types.index.d.ts +8 -2
  4. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +6 -1
  5. package/esm/typings/src/book-components/Chat/Chat/ChatMessageItem.d.ts +5 -1
  6. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +5 -0
  7. package/esm/typings/src/book-components/Chat/CodeBlock/CodeBlock.d.ts +13 -0
  8. package/esm/typings/src/book-components/Chat/MarkdownContent/MarkdownContent.d.ts +1 -0
  9. package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +7 -11
  10. package/esm/typings/src/book-components/_common/Dropdown/Dropdown.d.ts +2 -2
  11. package/esm/typings/src/book-components/_common/MenuHoisting/MenuHoistingContext.d.ts +56 -0
  12. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +13 -7
  13. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +6 -0
  14. package/esm/typings/src/commitments/DICTIONARY/DICTIONARY.d.ts +46 -0
  15. package/esm/typings/src/commitments/index.d.ts +2 -1
  16. package/esm/typings/src/llm-providers/ollama/OllamaExecutionTools.d.ts +1 -1
  17. package/esm/typings/src/llm-providers/openai/createOpenAiCompatibleExecutionTools.d.ts +1 -1
  18. package/esm/typings/src/types/Message.d.ts +49 -0
  19. package/esm/typings/src/types/typeAliases.d.ts +12 -0
  20. package/esm/typings/src/utils/environment/$detectRuntimeEnvironment.d.ts +4 -4
  21. package/esm/typings/src/utils/environment/$isRunningInBrowser.d.ts +1 -1
  22. package/esm/typings/src/utils/environment/$isRunningInJest.d.ts +1 -1
  23. package/esm/typings/src/utils/environment/$isRunningInNode.d.ts +1 -1
  24. package/esm/typings/src/utils/environment/$isRunningInWebWorker.d.ts +1 -1
  25. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +2 -2
  26. package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
  27. package/esm/typings/src/utils/random/$randomBase58.d.ts +12 -0
  28. package/esm/typings/src/version.d.ts +1 -1
  29. package/package.json +2 -2
  30. package/umd/index.umd.js +200 -40
  31. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -36,7 +36,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
36
36
  * @generated
37
37
  * @see https://github.com/webgptorg/promptbook
38
38
  */
39
- const PROMPTBOOK_ENGINE_VERSION = '0.104.0-1';
39
+ const PROMPTBOOK_ENGINE_VERSION = '0.104.0-3';
40
40
  /**
41
41
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
42
42
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -4699,13 +4699,15 @@ const _AzureOpenAiRegistration = $llmToolsRegister.register(createAzureOpenAiExe
4699
4699
  *
4700
4700
  * @public exported from `@promptbook/utils`
4701
4701
  */
4702
- const $isRunningInJest = new Function(`
4702
+ function $isRunningInJest() {
4703
+ var _a;
4703
4704
  try {
4704
- return process.env.JEST_WORKER_ID !== undefined;
4705
- } catch (e) {
4705
+ return typeof process !== 'undefined' && ((_a = process.env) === null || _a === void 0 ? void 0 : _a.JEST_WORKER_ID) !== undefined;
4706
+ }
4707
+ catch (e) {
4706
4708
  return false;
4707
4709
  }
4708
- `);
4710
+ }
4709
4711
  /**
4710
4712
  * TODO: [🎺]
4711
4713
  */
@@ -5565,13 +5567,14 @@ const _OllamaMetadataRegistration = $llmToolsMetadataRegister.register({
5565
5567
  *
5566
5568
  * @public exported from `@promptbook/utils`
5567
5569
  */
5568
- const $isRunningInBrowser = new Function(`
5570
+ function $isRunningInBrowser() {
5569
5571
  try {
5570
- return this === window;
5571
- } catch (e) {
5572
+ return typeof window !== 'undefined' && typeof window.document !== 'undefined';
5573
+ }
5574
+ catch (e) {
5572
5575
  return false;
5573
5576
  }
5574
- `);
5577
+ }
5575
5578
  /**
5576
5579
  * TODO: [🎺]
5577
5580
  */
@@ -5583,17 +5586,17 @@ const $isRunningInBrowser = new Function(`
5583
5586
  *
5584
5587
  * @public exported from `@promptbook/utils`
5585
5588
  */
5586
- const $isRunningInWebWorker = new Function(`
5589
+ function $isRunningInWebWorker() {
5587
5590
  try {
5588
- if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
5589
- return true;
5590
- } else {
5591
- return false;
5592
- }
5593
- } catch (e) {
5591
+ // Note: Check for importScripts which is specific to workers
5592
+ // and not available in the main browser thread
5593
+ return (typeof self !== 'undefined' &&
5594
+ typeof self.importScripts === 'function');
5595
+ }
5596
+ catch (e) {
5594
5597
  return false;
5595
5598
  }
5596
- `);
5599
+ }
5597
5600
  /**
5598
5601
  * TODO: [🎺]
5599
5602
  */
@@ -5825,7 +5828,7 @@ class OpenAiCompatibleExecutionTools {
5825
5828
  let threadMessages = [];
5826
5829
  if ('thread' in prompt && Array.isArray(prompt.thread)) {
5827
5830
  threadMessages = prompt.thread.map((msg) => ({
5828
- role: msg.role === 'assistant' ? 'assistant' : 'user',
5831
+ role: msg.sender === 'assistant' ? 'assistant' : 'user',
5829
5832
  content: msg.content,
5830
5833
  }));
5831
5834
  }
@@ -6781,10 +6784,10 @@ class OllamaExecutionTools extends OpenAiCompatibleExecutionTools {
6781
6784
  // <- TODO: [🛄]
6782
6785
  }
6783
6786
  /**
6784
- * Default model for image generation variant.
6787
+ * Default model for completion variant.
6785
6788
  */
6786
6789
  getDefaultImageGenerationModel() {
6787
- return this.getDefaultModel('!!!'); // <- TODO: [🧠] Pick the best default model
6790
+ return this.getDefaultModel('dall-e-3');
6788
6791
  // <- TODO: [🛄]
6789
6792
  }
6790
6793
  }
@@ -7599,11 +7602,10 @@ class HardcodedOpenAiCompatibleExecutionTools extends OpenAiCompatibleExecutionT
7599
7602
  throw new PipelineExecutionError(`${this.title} does not support EMBEDDING model variant`);
7600
7603
  }
7601
7604
  /**
7602
- * Default model for image generation variant.
7605
+ * Default model for completion variant.
7603
7606
  */
7604
7607
  getDefaultImageGenerationModel() {
7605
- return this.getDefaultModel('!!!'); // <- TODO: [🧠] Pick the best default model
7606
- // <- TODO: [🛄]
7608
+ throw new PipelineExecutionError(`${this.title} does not support IMAGE_GENERATION model variant`);
7607
7609
  }
7608
7610
  }
7609
7611
  /**
@@ -7695,13 +7697,14 @@ const $scrapersRegister = new $Register('scraper_constructors');
7695
7697
  *
7696
7698
  * @public exported from `@promptbook/utils`
7697
7699
  */
7698
- const $isRunningInNode = new Function(`
7700
+ function $isRunningInNode() {
7699
7701
  try {
7700
- return this === global;
7701
- } catch (e) {
7702
+ return typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
7703
+ }
7704
+ catch (e) {
7702
7705
  return false;
7703
7706
  }
7704
- `);
7707
+ }
7705
7708
  /**
7706
7709
  * TODO: [🎺]
7707
7710
  */
@@ -14121,6 +14124,114 @@ class DeleteCommitmentDefinition extends BaseCommitmentDefinition {
14121
14124
  * Note: [💞] Ignore a discrepancy between file name and entity name
14122
14125
  */
14123
14126
 
14127
+ /**
14128
+ * DICTIONARY commitment definition
14129
+ *
14130
+ * The DICTIONARY commitment defines specific terms and their meanings that the agent should use correctly
14131
+ * in its reasoning and responses. This ensures consistent terminology usage.
14132
+ *
14133
+ * Key features:
14134
+ * - Multiple DICTIONARY commitments are automatically merged into one
14135
+ * - Content is placed in a dedicated section of the system message
14136
+ * - Terms and definitions are stored in metadata.DICTIONARY for debugging
14137
+ * - Agent should use the defined terms correctly in responses
14138
+ *
14139
+ * Example usage in agent source:
14140
+ *
14141
+ * ```book
14142
+ * Legal Assistant
14143
+ *
14144
+ * PERSONA You are a knowledgeable legal assistant
14145
+ * DICTIONARY Misdemeanor is a minor wrongdoing or criminal offense
14146
+ * DICTIONARY Felony is a serious crime usually punishable by imprisonment for more than one year
14147
+ * DICTIONARY Tort is a civil wrong that causes harm or loss to another person, leading to legal liability
14148
+ * ```
14149
+ *
14150
+ * @private [🪔] Maybe export the commitments through some package
14151
+ */
14152
+ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
14153
+ constructor() {
14154
+ super('DICTIONARY');
14155
+ }
14156
+ /**
14157
+ * Short one-line description of DICTIONARY.
14158
+ */
14159
+ get description() {
14160
+ return 'Define terms and their meanings for consistent terminology usage.';
14161
+ }
14162
+ /**
14163
+ * Icon for this commitment.
14164
+ */
14165
+ get icon() {
14166
+ return '📚';
14167
+ }
14168
+ /**
14169
+ * Markdown documentation for DICTIONARY commitment.
14170
+ */
14171
+ get documentation() {
14172
+ return spaceTrim$1(`
14173
+ # DICTIONARY
14174
+
14175
+ Defines specific terms and their meanings that the agent should use correctly in reasoning and responses.
14176
+
14177
+ ## Key aspects
14178
+
14179
+ - Multiple \`DICTIONARY\` commitments are merged together.
14180
+ - Terms are defined in the format: "Term is definition"
14181
+ - The agent should use these terms consistently in responses.
14182
+ - Definitions help ensure accurate and consistent terminology.
14183
+
14184
+ ## Examples
14185
+
14186
+ \`\`\`book
14187
+ Legal Assistant
14188
+
14189
+ PERSONA You are a knowledgeable legal assistant specializing in criminal law
14190
+ DICTIONARY Misdemeanor is a minor wrongdoing or criminal offense
14191
+ DICTIONARY Felony is a serious crime usually punishable by imprisonment for more than one year
14192
+ DICTIONARY Tort is a civil wrong that causes harm or loss to another person, leading to legal liability
14193
+ \`\`\`
14194
+
14195
+ \`\`\`book
14196
+ Medical Assistant
14197
+
14198
+ PERSONA You are a helpful medical assistant
14199
+ DICTIONARY Hypertension is persistently high blood pressure
14200
+ DICTIONARY Diabetes is a chronic condition that affects how the body processes blood sugar
14201
+ DICTIONARY Vaccine is a biological preparation that provides active immunity to a particular disease
14202
+ \`\`\`
14203
+ `);
14204
+ }
14205
+ applyToAgentModelRequirements(requirements, content) {
14206
+ var _a;
14207
+ const trimmedContent = content.trim();
14208
+ if (!trimmedContent) {
14209
+ return requirements;
14210
+ }
14211
+ // Get existing dictionary entries from metadata
14212
+ const existingDictionary = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
14213
+ // Merge the new dictionary entry with existing entries
14214
+ const mergedDictionary = existingDictionary
14215
+ ? `${existingDictionary}\n${trimmedContent}`
14216
+ : trimmedContent;
14217
+ // Store the merged dictionary in metadata for debugging and inspection
14218
+ const updatedMetadata = {
14219
+ ...requirements.metadata,
14220
+ DICTIONARY: mergedDictionary,
14221
+ };
14222
+ // Create the dictionary section for the system message
14223
+ // Format: "# DICTIONARY\nTerm: definition\nTerm: definition..."
14224
+ const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
14225
+ return {
14226
+ ...this.appendToSystemMessage(requirements, dictionarySection),
14227
+ metadata: updatedMetadata,
14228
+ };
14229
+ }
14230
+ }
14231
+ /**
14232
+ * Note: [💞] Ignore a discrepancy between file name and entity name
14233
+ */
14234
+
14124
14235
  /**
14125
14236
  * FORMAT commitment definition
14126
14237
  *
@@ -16941,6 +17052,7 @@ const COMMITMENT_REGISTRY = [
16941
17052
  new DeleteCommitmentDefinition('CANCEL'),
16942
17053
  new DeleteCommitmentDefinition('DISCARD'),
16943
17054
  new DeleteCommitmentDefinition('REMOVE'),
17055
+ new DictionaryCommitmentDefinition(),
16944
17056
  new OpenCommitmentDefinition(),
16945
17057
  new ClosedCommitmentDefinition(),
16946
17058
  new UseBrowserCommitmentDefinition(),
@@ -17025,17 +17137,64 @@ function parseAgentSourceWithCommitments(agentSource) {
17025
17137
  };
17026
17138
  }
17027
17139
  const lines = agentSource.split('\n');
17028
- const agentName = (((_a = lines[0]) === null || _a === void 0 ? void 0 : _a.trim()) || null);
17140
+ let agentName = null;
17141
+ let agentNameLineIndex = -1;
17142
+ // Find the agent name: first non-empty line that is not a commitment and not a horizontal line
17143
+ for (let i = 0; i < lines.length; i++) {
17144
+ const line = lines[i];
17145
+ if (line === undefined) {
17146
+ continue;
17147
+ }
17148
+ const trimmed = line.trim();
17149
+ if (!trimmed) {
17150
+ continue;
17151
+ }
17152
+ const isHorizontal = HORIZONTAL_LINE_PATTERN.test(line);
17153
+ if (isHorizontal) {
17154
+ continue;
17155
+ }
17156
+ let isCommitment = false;
17157
+ for (const definition of COMMITMENT_REGISTRY) {
17158
+ const typeRegex = definition.createTypeRegex();
17159
+ const match = typeRegex.exec(trimmed);
17160
+ if (match && ((_a = match.groups) === null || _a === void 0 ? void 0 : _a.type)) {
17161
+ isCommitment = true;
17162
+ break;
17163
+ }
17164
+ }
17165
+ if (!isCommitment) {
17166
+ agentName = trimmed;
17167
+ agentNameLineIndex = i;
17168
+ break;
17169
+ }
17170
+ }
17029
17171
  const commitments = [];
17030
17172
  const nonCommitmentLines = [];
17031
- // Always add the first line (agent name) to non-commitment lines
17032
- if (lines[0] !== undefined) {
17033
- nonCommitmentLines.push(lines[0]);
17173
+ // Add lines before agentName that are horizontal lines (they are non-commitment)
17174
+ for (let i = 0; i < agentNameLineIndex; i++) {
17175
+ const line = lines[i];
17176
+ if (line === undefined) {
17177
+ continue;
17178
+ }
17179
+ const trimmed = line.trim();
17180
+ if (!trimmed) {
17181
+ continue;
17182
+ }
17183
+ const isHorizontal = HORIZONTAL_LINE_PATTERN.test(line);
17184
+ if (isHorizontal) {
17185
+ nonCommitmentLines.push(line);
17186
+ }
17187
+ // Note: Commitments before agentName are not added to nonCommitmentLines
17188
+ }
17189
+ // Add the agent name line to non-commitment lines
17190
+ if (agentNameLineIndex >= 0) {
17191
+ nonCommitmentLines.push(lines[agentNameLineIndex]);
17034
17192
  }
17035
17193
  // Parse commitments with multiline support
17036
17194
  let currentCommitment = null;
17037
- // Process lines starting from the second line (skip agent name)
17038
- for (let i = 1; i < lines.length; i++) {
17195
+ // Process lines starting from after the agent name line
17196
+ const startIndex = agentNameLineIndex >= 0 ? agentNameLineIndex + 1 : 0;
17197
+ for (let i = startIndex; i < lines.length; i++) {
17039
17198
  const line = lines[i];
17040
17199
  if (line === undefined) {
17041
17200
  continue;
@@ -17827,6 +17986,7 @@ function parseAgentSource(agentSource) {
17827
17986
  return {
17828
17987
  agentName: normalizeAgentName(parseResult.agentName || createDefaultAgentName(agentSource)),
17829
17988
  agentHash,
17989
+ permanentId: meta.id,
17830
17990
  personaDescription,
17831
17991
  initialMessage,
17832
17992
  meta,
@@ -18552,7 +18712,7 @@ function $registeredLlmToolsMessage() {
18552
18712
  ${i + 1}) **${title}** \`${className}\` from \`${packageName}\`
18553
18713
  ${morePieces.join('; ')}
18554
18714
  `);
18555
- if ($isRunningInNode) {
18715
+ if ($isRunningInNode()) {
18556
18716
  if (isInstalled && isFullyConfigured) {
18557
18717
  providerMessage = colors.green(providerMessage);
18558
18718
  }