@promptbook/browser 0.104.0-1 → 0.104.0-2

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/esm/index.es.js +124 -49
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/types.index.d.ts +6 -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/_common/Dropdown/Dropdown.d.ts +2 -2
  10. package/esm/typings/src/book-components/_common/MenuHoisting/MenuHoistingContext.d.ts +56 -0
  11. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +13 -7
  12. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +6 -0
  13. package/esm/typings/src/commitments/DICTIONARY/DICTIONARY.d.ts +46 -0
  14. package/esm/typings/src/commitments/index.d.ts +2 -1
  15. package/esm/typings/src/llm-providers/ollama/OllamaExecutionTools.d.ts +1 -1
  16. package/esm/typings/src/llm-providers/openai/createOpenAiCompatibleExecutionTools.d.ts +1 -1
  17. package/esm/typings/src/types/typeAliases.d.ts +12 -0
  18. package/esm/typings/src/utils/environment/$detectRuntimeEnvironment.d.ts +4 -4
  19. package/esm/typings/src/utils/environment/$isRunningInBrowser.d.ts +1 -1
  20. package/esm/typings/src/utils/environment/$isRunningInJest.d.ts +1 -1
  21. package/esm/typings/src/utils/environment/$isRunningInNode.d.ts +1 -1
  22. package/esm/typings/src/utils/environment/$isRunningInWebWorker.d.ts +1 -1
  23. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +2 -2
  24. package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
  25. package/esm/typings/src/utils/random/$randomBase58.d.ts +12 -0
  26. package/esm/typings/src/version.d.ts +1 -1
  27. package/package.json +2 -2
  28. package/umd/index.umd.js +126 -51
  29. package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js CHANGED
@@ -23,7 +23,7 @@
23
23
  * @generated
24
24
  * @see https://github.com/webgptorg/promptbook
25
25
  */
26
- const PROMPTBOOK_ENGINE_VERSION = '0.104.0-1';
26
+ const PROMPTBOOK_ENGINE_VERSION = '0.104.0-2';
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
@@ -122,13 +122,14 @@
122
122
  *
123
123
  * @public exported from `@promptbook/utils`
124
124
  */
125
- const $isRunningInBrowser = new Function(`
126
- try {
127
- return this === window;
128
- } catch (e) {
129
- return false;
125
+ function $isRunningInBrowser() {
126
+ try {
127
+ return typeof window !== 'undefined' && typeof window.document !== 'undefined';
128
+ }
129
+ catch (e) {
130
+ return false;
131
+ }
130
132
  }
131
- `);
132
133
  /**
133
134
  * TODO: [🎺]
134
135
  */
@@ -140,17 +141,17 @@
140
141
  *
141
142
  * @public exported from `@promptbook/utils`
142
143
  */
143
- const $isRunningInWebWorker = new Function(`
144
- try {
145
- if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
146
- return true;
147
- } else {
144
+ function $isRunningInWebWorker() {
145
+ try {
146
+ // Note: Check for importScripts which is specific to workers
147
+ // and not available in the main browser thread
148
+ return (typeof self !== 'undefined' &&
149
+ typeof self.importScripts === 'function');
150
+ }
151
+ catch (e) {
148
152
  return false;
149
153
  }
150
- } catch (e) {
151
- return false;
152
154
  }
153
- `);
154
155
  /**
155
156
  * TODO: [🎺]
156
157
  */
@@ -2661,42 +2662,6 @@
2661
2662
  * Note: [💞] Ignore a discrepancy between file name and entity name
2662
2663
  */
2663
2664
 
2664
- /**
2665
- * Detects if the code is running in jest environment
2666
- *
2667
- * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
2668
- *
2669
- * @public exported from `@promptbook/utils`
2670
- */
2671
- new Function(`
2672
- try {
2673
- return process.env.JEST_WORKER_ID !== undefined;
2674
- } catch (e) {
2675
- return false;
2676
- }
2677
- `);
2678
- /**
2679
- * TODO: [🎺]
2680
- */
2681
-
2682
- /**
2683
- * Detects if the code is running in a Node.js environment
2684
- *
2685
- * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
2686
- *
2687
- * @public exported from `@promptbook/utils`
2688
- */
2689
- new Function(`
2690
- try {
2691
- return this === global;
2692
- } catch (e) {
2693
- return false;
2694
- }
2695
- `);
2696
- /**
2697
- * TODO: [🎺]
2698
- */
2699
-
2700
2665
  /**
2701
2666
  * Normalizes agent name from arbitrary string to valid agent name
2702
2667
  *
@@ -3175,6 +3140,114 @@
3175
3140
  * Note: [💞] Ignore a discrepancy between file name and entity name
3176
3141
  */
3177
3142
 
3143
+ /**
3144
+ * DICTIONARY commitment definition
3145
+ *
3146
+ * The DICTIONARY commitment defines specific terms and their meanings that the agent should use correctly
3147
+ * in its reasoning and responses. This ensures consistent terminology usage.
3148
+ *
3149
+ * Key features:
3150
+ * - Multiple DICTIONARY commitments are automatically merged into one
3151
+ * - Content is placed in a dedicated section of the system message
3152
+ * - Terms and definitions are stored in metadata.DICTIONARY for debugging
3153
+ * - Agent should use the defined terms correctly in responses
3154
+ *
3155
+ * Example usage in agent source:
3156
+ *
3157
+ * ```book
3158
+ * Legal Assistant
3159
+ *
3160
+ * PERSONA You are a knowledgeable legal assistant
3161
+ * DICTIONARY Misdemeanor is a minor wrongdoing or criminal offense
3162
+ * DICTIONARY Felony is a serious crime usually punishable by imprisonment for more than one year
3163
+ * DICTIONARY Tort is a civil wrong that causes harm or loss to another person, leading to legal liability
3164
+ * ```
3165
+ *
3166
+ * @private [🪔] Maybe export the commitments through some package
3167
+ */
3168
+ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
3169
+ constructor() {
3170
+ super('DICTIONARY');
3171
+ }
3172
+ /**
3173
+ * Short one-line description of DICTIONARY.
3174
+ */
3175
+ get description() {
3176
+ return 'Define terms and their meanings for consistent terminology usage.';
3177
+ }
3178
+ /**
3179
+ * Icon for this commitment.
3180
+ */
3181
+ get icon() {
3182
+ return '📚';
3183
+ }
3184
+ /**
3185
+ * Markdown documentation for DICTIONARY commitment.
3186
+ */
3187
+ get documentation() {
3188
+ return spaceTrim$1.spaceTrim(`
3189
+ # DICTIONARY
3190
+
3191
+ Defines specific terms and their meanings that the agent should use correctly in reasoning and responses.
3192
+
3193
+ ## Key aspects
3194
+
3195
+ - Multiple \`DICTIONARY\` commitments are merged together.
3196
+ - Terms are defined in the format: "Term is definition"
3197
+ - The agent should use these terms consistently in responses.
3198
+ - Definitions help ensure accurate and consistent terminology.
3199
+
3200
+ ## Examples
3201
+
3202
+ \`\`\`book
3203
+ Legal Assistant
3204
+
3205
+ PERSONA You are a knowledgeable legal assistant specializing in criminal law
3206
+ DICTIONARY Misdemeanor is a minor wrongdoing or criminal offense
3207
+ DICTIONARY Felony is a serious crime usually punishable by imprisonment for more than one year
3208
+ DICTIONARY Tort is a civil wrong that causes harm or loss to another person, leading to legal liability
3209
+ \`\`\`
3210
+
3211
+ \`\`\`book
3212
+ Medical Assistant
3213
+
3214
+ PERSONA You are a helpful medical assistant
3215
+ DICTIONARY Hypertension is persistently high blood pressure
3216
+ DICTIONARY Diabetes is a chronic condition that affects how the body processes blood sugar
3217
+ DICTIONARY Vaccine is a biological preparation that provides active immunity to a particular disease
3218
+ \`\`\`
3219
+ `);
3220
+ }
3221
+ applyToAgentModelRequirements(requirements, content) {
3222
+ var _a;
3223
+ const trimmedContent = content.trim();
3224
+ if (!trimmedContent) {
3225
+ return requirements;
3226
+ }
3227
+ // Get existing dictionary entries from metadata
3228
+ const existingDictionary = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
3229
+ // Merge the new dictionary entry with existing entries
3230
+ const mergedDictionary = existingDictionary
3231
+ ? `${existingDictionary}\n${trimmedContent}`
3232
+ : trimmedContent;
3233
+ // Store the merged dictionary in metadata for debugging and inspection
3234
+ const updatedMetadata = {
3235
+ ...requirements.metadata,
3236
+ DICTIONARY: mergedDictionary,
3237
+ };
3238
+ // Create the dictionary section for the system message
3239
+ // Format: "# DICTIONARY\nTerm: definition\nTerm: definition..."
3240
+ const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
3241
+ return {
3242
+ ...this.appendToSystemMessage(requirements, dictionarySection),
3243
+ metadata: updatedMetadata,
3244
+ };
3245
+ }
3246
+ }
3247
+ /**
3248
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3249
+ */
3250
+
3178
3251
  /**
3179
3252
  * FORMAT commitment definition
3180
3253
  *
@@ -5995,6 +6068,7 @@
5995
6068
  new DeleteCommitmentDefinition('CANCEL'),
5996
6069
  new DeleteCommitmentDefinition('DISCARD'),
5997
6070
  new DeleteCommitmentDefinition('REMOVE'),
6071
+ new DictionaryCommitmentDefinition(),
5998
6072
  new OpenCommitmentDefinition(),
5999
6073
  new ClosedCommitmentDefinition(),
6000
6074
  new UseBrowserCommitmentDefinition(),
@@ -6267,6 +6341,7 @@
6267
6341
  return {
6268
6342
  agentName: normalizeAgentName(parseResult.agentName || createDefaultAgentName(agentSource)),
6269
6343
  agentHash,
6344
+ permanentId: meta.id,
6270
6345
  personaDescription,
6271
6346
  initialMessage,
6272
6347
  meta,