@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/umd/index.umd.js CHANGED
@@ -48,7 +48,7 @@
48
48
  * @generated
49
49
  * @see https://github.com/webgptorg/promptbook
50
50
  */
51
- const PROMPTBOOK_ENGINE_VERSION = '0.104.0-1';
51
+ const PROMPTBOOK_ENGINE_VERSION = '0.104.0-3';
52
52
  /**
53
53
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
54
54
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -4711,13 +4711,15 @@
4711
4711
  *
4712
4712
  * @public exported from `@promptbook/utils`
4713
4713
  */
4714
- const $isRunningInJest = new Function(`
4715
- try {
4716
- return process.env.JEST_WORKER_ID !== undefined;
4717
- } catch (e) {
4718
- return false;
4714
+ function $isRunningInJest() {
4715
+ var _a;
4716
+ try {
4717
+ return typeof process !== 'undefined' && ((_a = process.env) === null || _a === void 0 ? void 0 : _a.JEST_WORKER_ID) !== undefined;
4718
+ }
4719
+ catch (e) {
4720
+ return false;
4721
+ }
4719
4722
  }
4720
- `);
4721
4723
  /**
4722
4724
  * TODO: [🎺]
4723
4725
  */
@@ -5577,13 +5579,14 @@
5577
5579
  *
5578
5580
  * @public exported from `@promptbook/utils`
5579
5581
  */
5580
- const $isRunningInBrowser = new Function(`
5581
- try {
5582
- return this === window;
5583
- } catch (e) {
5584
- return false;
5582
+ function $isRunningInBrowser() {
5583
+ try {
5584
+ return typeof window !== 'undefined' && typeof window.document !== 'undefined';
5585
+ }
5586
+ catch (e) {
5587
+ return false;
5588
+ }
5585
5589
  }
5586
- `);
5587
5590
  /**
5588
5591
  * TODO: [🎺]
5589
5592
  */
@@ -5595,17 +5598,17 @@
5595
5598
  *
5596
5599
  * @public exported from `@promptbook/utils`
5597
5600
  */
5598
- const $isRunningInWebWorker = new Function(`
5599
- try {
5600
- if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
5601
- return true;
5602
- } else {
5601
+ function $isRunningInWebWorker() {
5602
+ try {
5603
+ // Note: Check for importScripts which is specific to workers
5604
+ // and not available in the main browser thread
5605
+ return (typeof self !== 'undefined' &&
5606
+ typeof self.importScripts === 'function');
5607
+ }
5608
+ catch (e) {
5603
5609
  return false;
5604
5610
  }
5605
- } catch (e) {
5606
- return false;
5607
5611
  }
5608
- `);
5609
5612
  /**
5610
5613
  * TODO: [🎺]
5611
5614
  */
@@ -5837,7 +5840,7 @@
5837
5840
  let threadMessages = [];
5838
5841
  if ('thread' in prompt && Array.isArray(prompt.thread)) {
5839
5842
  threadMessages = prompt.thread.map((msg) => ({
5840
- role: msg.role === 'assistant' ? 'assistant' : 'user',
5843
+ role: msg.sender === 'assistant' ? 'assistant' : 'user',
5841
5844
  content: msg.content,
5842
5845
  }));
5843
5846
  }
@@ -6793,10 +6796,10 @@
6793
6796
  // <- TODO: [🛄]
6794
6797
  }
6795
6798
  /**
6796
- * Default model for image generation variant.
6799
+ * Default model for completion variant.
6797
6800
  */
6798
6801
  getDefaultImageGenerationModel() {
6799
- return this.getDefaultModel('!!!'); // <- TODO: [🧠] Pick the best default model
6802
+ return this.getDefaultModel('dall-e-3');
6800
6803
  // <- TODO: [🛄]
6801
6804
  }
6802
6805
  }
@@ -7611,11 +7614,10 @@
7611
7614
  throw new PipelineExecutionError(`${this.title} does not support EMBEDDING model variant`);
7612
7615
  }
7613
7616
  /**
7614
- * Default model for image generation variant.
7617
+ * Default model for completion variant.
7615
7618
  */
7616
7619
  getDefaultImageGenerationModel() {
7617
- return this.getDefaultModel('!!!'); // <- TODO: [🧠] Pick the best default model
7618
- // <- TODO: [🛄]
7620
+ throw new PipelineExecutionError(`${this.title} does not support IMAGE_GENERATION model variant`);
7619
7621
  }
7620
7622
  }
7621
7623
  /**
@@ -7707,13 +7709,14 @@
7707
7709
  *
7708
7710
  * @public exported from `@promptbook/utils`
7709
7711
  */
7710
- const $isRunningInNode = new Function(`
7711
- try {
7712
- return this === global;
7713
- } catch (e) {
7714
- return false;
7712
+ function $isRunningInNode() {
7713
+ try {
7714
+ return typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
7715
+ }
7716
+ catch (e) {
7717
+ return false;
7718
+ }
7715
7719
  }
7716
- `);
7717
7720
  /**
7718
7721
  * TODO: [🎺]
7719
7722
  */
@@ -14133,6 +14136,114 @@
14133
14136
  * Note: [💞] Ignore a discrepancy between file name and entity name
14134
14137
  */
14135
14138
 
14139
+ /**
14140
+ * DICTIONARY commitment definition
14141
+ *
14142
+ * The DICTIONARY commitment defines specific terms and their meanings that the agent should use correctly
14143
+ * in its reasoning and responses. This ensures consistent terminology usage.
14144
+ *
14145
+ * Key features:
14146
+ * - Multiple DICTIONARY commitments are automatically merged into one
14147
+ * - Content is placed in a dedicated section of the system message
14148
+ * - Terms and definitions are stored in metadata.DICTIONARY for debugging
14149
+ * - Agent should use the defined terms correctly in responses
14150
+ *
14151
+ * Example usage in agent source:
14152
+ *
14153
+ * ```book
14154
+ * Legal Assistant
14155
+ *
14156
+ * PERSONA You are a knowledgeable legal assistant
14157
+ * DICTIONARY Misdemeanor is a minor wrongdoing or criminal offense
14158
+ * DICTIONARY Felony is a serious crime usually punishable by imprisonment for more than one year
14159
+ * DICTIONARY Tort is a civil wrong that causes harm or loss to another person, leading to legal liability
14160
+ * ```
14161
+ *
14162
+ * @private [🪔] Maybe export the commitments through some package
14163
+ */
14164
+ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
14165
+ constructor() {
14166
+ super('DICTIONARY');
14167
+ }
14168
+ /**
14169
+ * Short one-line description of DICTIONARY.
14170
+ */
14171
+ get description() {
14172
+ return 'Define terms and their meanings for consistent terminology usage.';
14173
+ }
14174
+ /**
14175
+ * Icon for this commitment.
14176
+ */
14177
+ get icon() {
14178
+ return '📚';
14179
+ }
14180
+ /**
14181
+ * Markdown documentation for DICTIONARY commitment.
14182
+ */
14183
+ get documentation() {
14184
+ return spaceTrim$1.spaceTrim(`
14185
+ # DICTIONARY
14186
+
14187
+ Defines specific terms and their meanings that the agent should use correctly in reasoning and responses.
14188
+
14189
+ ## Key aspects
14190
+
14191
+ - Multiple \`DICTIONARY\` commitments are merged together.
14192
+ - Terms are defined in the format: "Term is definition"
14193
+ - The agent should use these terms consistently in responses.
14194
+ - Definitions help ensure accurate and consistent terminology.
14195
+
14196
+ ## Examples
14197
+
14198
+ \`\`\`book
14199
+ Legal Assistant
14200
+
14201
+ PERSONA You are a knowledgeable legal assistant specializing in criminal law
14202
+ DICTIONARY Misdemeanor is a minor wrongdoing or criminal offense
14203
+ DICTIONARY Felony is a serious crime usually punishable by imprisonment for more than one year
14204
+ DICTIONARY Tort is a civil wrong that causes harm or loss to another person, leading to legal liability
14205
+ \`\`\`
14206
+
14207
+ \`\`\`book
14208
+ Medical Assistant
14209
+
14210
+ PERSONA You are a helpful medical assistant
14211
+ DICTIONARY Hypertension is persistently high blood pressure
14212
+ DICTIONARY Diabetes is a chronic condition that affects how the body processes blood sugar
14213
+ DICTIONARY Vaccine is a biological preparation that provides active immunity to a particular disease
14214
+ \`\`\`
14215
+ `);
14216
+ }
14217
+ applyToAgentModelRequirements(requirements, content) {
14218
+ var _a;
14219
+ const trimmedContent = content.trim();
14220
+ if (!trimmedContent) {
14221
+ return requirements;
14222
+ }
14223
+ // Get existing dictionary entries from metadata
14224
+ const existingDictionary = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
14225
+ // Merge the new dictionary entry with existing entries
14226
+ const mergedDictionary = existingDictionary
14227
+ ? `${existingDictionary}\n${trimmedContent}`
14228
+ : trimmedContent;
14229
+ // Store the merged dictionary in metadata for debugging and inspection
14230
+ const updatedMetadata = {
14231
+ ...requirements.metadata,
14232
+ DICTIONARY: mergedDictionary,
14233
+ };
14234
+ // Create the dictionary section for the system message
14235
+ // Format: "# DICTIONARY\nTerm: definition\nTerm: definition..."
14236
+ const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
14237
+ return {
14238
+ ...this.appendToSystemMessage(requirements, dictionarySection),
14239
+ metadata: updatedMetadata,
14240
+ };
14241
+ }
14242
+ }
14243
+ /**
14244
+ * Note: [💞] Ignore a discrepancy between file name and entity name
14245
+ */
14246
+
14136
14247
  /**
14137
14248
  * FORMAT commitment definition
14138
14249
  *
@@ -16953,6 +17064,7 @@
16953
17064
  new DeleteCommitmentDefinition('CANCEL'),
16954
17065
  new DeleteCommitmentDefinition('DISCARD'),
16955
17066
  new DeleteCommitmentDefinition('REMOVE'),
17067
+ new DictionaryCommitmentDefinition(),
16956
17068
  new OpenCommitmentDefinition(),
16957
17069
  new ClosedCommitmentDefinition(),
16958
17070
  new UseBrowserCommitmentDefinition(),
@@ -17037,17 +17149,64 @@
17037
17149
  };
17038
17150
  }
17039
17151
  const lines = agentSource.split('\n');
17040
- const agentName = (((_a = lines[0]) === null || _a === void 0 ? void 0 : _a.trim()) || null);
17152
+ let agentName = null;
17153
+ let agentNameLineIndex = -1;
17154
+ // Find the agent name: first non-empty line that is not a commitment and not a horizontal line
17155
+ for (let i = 0; i < lines.length; i++) {
17156
+ const line = lines[i];
17157
+ if (line === undefined) {
17158
+ continue;
17159
+ }
17160
+ const trimmed = line.trim();
17161
+ if (!trimmed) {
17162
+ continue;
17163
+ }
17164
+ const isHorizontal = HORIZONTAL_LINE_PATTERN.test(line);
17165
+ if (isHorizontal) {
17166
+ continue;
17167
+ }
17168
+ let isCommitment = false;
17169
+ for (const definition of COMMITMENT_REGISTRY) {
17170
+ const typeRegex = definition.createTypeRegex();
17171
+ const match = typeRegex.exec(trimmed);
17172
+ if (match && ((_a = match.groups) === null || _a === void 0 ? void 0 : _a.type)) {
17173
+ isCommitment = true;
17174
+ break;
17175
+ }
17176
+ }
17177
+ if (!isCommitment) {
17178
+ agentName = trimmed;
17179
+ agentNameLineIndex = i;
17180
+ break;
17181
+ }
17182
+ }
17041
17183
  const commitments = [];
17042
17184
  const nonCommitmentLines = [];
17043
- // Always add the first line (agent name) to non-commitment lines
17044
- if (lines[0] !== undefined) {
17045
- nonCommitmentLines.push(lines[0]);
17185
+ // Add lines before agentName that are horizontal lines (they are non-commitment)
17186
+ for (let i = 0; i < agentNameLineIndex; i++) {
17187
+ const line = lines[i];
17188
+ if (line === undefined) {
17189
+ continue;
17190
+ }
17191
+ const trimmed = line.trim();
17192
+ if (!trimmed) {
17193
+ continue;
17194
+ }
17195
+ const isHorizontal = HORIZONTAL_LINE_PATTERN.test(line);
17196
+ if (isHorizontal) {
17197
+ nonCommitmentLines.push(line);
17198
+ }
17199
+ // Note: Commitments before agentName are not added to nonCommitmentLines
17200
+ }
17201
+ // Add the agent name line to non-commitment lines
17202
+ if (agentNameLineIndex >= 0) {
17203
+ nonCommitmentLines.push(lines[agentNameLineIndex]);
17046
17204
  }
17047
17205
  // Parse commitments with multiline support
17048
17206
  let currentCommitment = null;
17049
- // Process lines starting from the second line (skip agent name)
17050
- for (let i = 1; i < lines.length; i++) {
17207
+ // Process lines starting from after the agent name line
17208
+ const startIndex = agentNameLineIndex >= 0 ? agentNameLineIndex + 1 : 0;
17209
+ for (let i = startIndex; i < lines.length; i++) {
17051
17210
  const line = lines[i];
17052
17211
  if (line === undefined) {
17053
17212
  continue;
@@ -17839,6 +17998,7 @@
17839
17998
  return {
17840
17999
  agentName: normalizeAgentName(parseResult.agentName || createDefaultAgentName(agentSource)),
17841
18000
  agentHash,
18001
+ permanentId: meta.id,
17842
18002
  personaDescription,
17843
18003
  initialMessage,
17844
18004
  meta,
@@ -18564,7 +18724,7 @@
18564
18724
  ${i + 1}) **${title}** \`${className}\` from \`${packageName}\`
18565
18725
  ${morePieces.join('; ')}
18566
18726
  `);
18567
- if ($isRunningInNode) {
18727
+ if ($isRunningInNode()) {
18568
18728
  if (isInstalled && isFullyConfigured) {
18569
18729
  providerMessage = colors__default["default"].green(providerMessage);
18570
18730
  }