@promptbook/browser 0.104.0-0 → 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/esm/index.es.js CHANGED
@@ -19,7 +19,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
19
19
  * @generated
20
20
  * @see https://github.com/webgptorg/promptbook
21
21
  */
22
- const PROMPTBOOK_ENGINE_VERSION = '0.104.0-0';
22
+ const PROMPTBOOK_ENGINE_VERSION = '0.104.0-2';
23
23
  /**
24
24
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
25
25
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -118,13 +118,14 @@ class EnvironmentMismatchError extends Error {
118
118
  *
119
119
  * @public exported from `@promptbook/utils`
120
120
  */
121
- const $isRunningInBrowser = new Function(`
121
+ function $isRunningInBrowser() {
122
122
  try {
123
- return this === window;
124
- } catch (e) {
123
+ return typeof window !== 'undefined' && typeof window.document !== 'undefined';
124
+ }
125
+ catch (e) {
125
126
  return false;
126
127
  }
127
- `);
128
+ }
128
129
  /**
129
130
  * TODO: [🎺]
130
131
  */
@@ -136,17 +137,17 @@ const $isRunningInBrowser = new Function(`
136
137
  *
137
138
  * @public exported from `@promptbook/utils`
138
139
  */
139
- const $isRunningInWebWorker = new Function(`
140
+ function $isRunningInWebWorker() {
140
141
  try {
141
- if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
142
- return true;
143
- } else {
144
- return false;
145
- }
146
- } catch (e) {
142
+ // Note: Check for importScripts which is specific to workers
143
+ // and not available in the main browser thread
144
+ return (typeof self !== 'undefined' &&
145
+ typeof self.importScripts === 'function');
146
+ }
147
+ catch (e) {
147
148
  return false;
148
149
  }
149
- `);
150
+ }
150
151
  /**
151
152
  * TODO: [🎺]
152
153
  */
@@ -2657,42 +2658,6 @@ function titleToName(value) {
2657
2658
  * Note: [💞] Ignore a discrepancy between file name and entity name
2658
2659
  */
2659
2660
 
2660
- /**
2661
- * Detects if the code is running in jest environment
2662
- *
2663
- * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
2664
- *
2665
- * @public exported from `@promptbook/utils`
2666
- */
2667
- new Function(`
2668
- try {
2669
- return process.env.JEST_WORKER_ID !== undefined;
2670
- } catch (e) {
2671
- return false;
2672
- }
2673
- `);
2674
- /**
2675
- * TODO: [🎺]
2676
- */
2677
-
2678
- /**
2679
- * Detects if the code is running in a Node.js environment
2680
- *
2681
- * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
2682
- *
2683
- * @public exported from `@promptbook/utils`
2684
- */
2685
- new Function(`
2686
- try {
2687
- return this === global;
2688
- } catch (e) {
2689
- return false;
2690
- }
2691
- `);
2692
- /**
2693
- * TODO: [🎺]
2694
- */
2695
-
2696
2661
  /**
2697
2662
  * Normalizes agent name from arbitrary string to valid agent name
2698
2663
  *
@@ -3171,6 +3136,114 @@ class DeleteCommitmentDefinition extends BaseCommitmentDefinition {
3171
3136
  * Note: [💞] Ignore a discrepancy between file name and entity name
3172
3137
  */
3173
3138
 
3139
+ /**
3140
+ * DICTIONARY commitment definition
3141
+ *
3142
+ * The DICTIONARY commitment defines specific terms and their meanings that the agent should use correctly
3143
+ * in its reasoning and responses. This ensures consistent terminology usage.
3144
+ *
3145
+ * Key features:
3146
+ * - Multiple DICTIONARY commitments are automatically merged into one
3147
+ * - Content is placed in a dedicated section of the system message
3148
+ * - Terms and definitions are stored in metadata.DICTIONARY for debugging
3149
+ * - Agent should use the defined terms correctly in responses
3150
+ *
3151
+ * Example usage in agent source:
3152
+ *
3153
+ * ```book
3154
+ * Legal Assistant
3155
+ *
3156
+ * PERSONA You are a knowledgeable legal assistant
3157
+ * DICTIONARY Misdemeanor is a minor wrongdoing or criminal offense
3158
+ * DICTIONARY Felony is a serious crime usually punishable by imprisonment for more than one year
3159
+ * DICTIONARY Tort is a civil wrong that causes harm or loss to another person, leading to legal liability
3160
+ * ```
3161
+ *
3162
+ * @private [🪔] Maybe export the commitments through some package
3163
+ */
3164
+ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
3165
+ constructor() {
3166
+ super('DICTIONARY');
3167
+ }
3168
+ /**
3169
+ * Short one-line description of DICTIONARY.
3170
+ */
3171
+ get description() {
3172
+ return 'Define terms and their meanings for consistent terminology usage.';
3173
+ }
3174
+ /**
3175
+ * Icon for this commitment.
3176
+ */
3177
+ get icon() {
3178
+ return '📚';
3179
+ }
3180
+ /**
3181
+ * Markdown documentation for DICTIONARY commitment.
3182
+ */
3183
+ get documentation() {
3184
+ return spaceTrim$1(`
3185
+ # DICTIONARY
3186
+
3187
+ Defines specific terms and their meanings that the agent should use correctly in reasoning and responses.
3188
+
3189
+ ## Key aspects
3190
+
3191
+ - Multiple \`DICTIONARY\` commitments are merged together.
3192
+ - Terms are defined in the format: "Term is definition"
3193
+ - The agent should use these terms consistently in responses.
3194
+ - Definitions help ensure accurate and consistent terminology.
3195
+
3196
+ ## Examples
3197
+
3198
+ \`\`\`book
3199
+ Legal Assistant
3200
+
3201
+ PERSONA You are a knowledgeable legal assistant specializing in criminal law
3202
+ DICTIONARY Misdemeanor is a minor wrongdoing or criminal offense
3203
+ DICTIONARY Felony is a serious crime usually punishable by imprisonment for more than one year
3204
+ DICTIONARY Tort is a civil wrong that causes harm or loss to another person, leading to legal liability
3205
+ \`\`\`
3206
+
3207
+ \`\`\`book
3208
+ Medical Assistant
3209
+
3210
+ PERSONA You are a helpful medical assistant
3211
+ DICTIONARY Hypertension is persistently high blood pressure
3212
+ DICTIONARY Diabetes is a chronic condition that affects how the body processes blood sugar
3213
+ DICTIONARY Vaccine is a biological preparation that provides active immunity to a particular disease
3214
+ \`\`\`
3215
+ `);
3216
+ }
3217
+ applyToAgentModelRequirements(requirements, content) {
3218
+ var _a;
3219
+ const trimmedContent = content.trim();
3220
+ if (!trimmedContent) {
3221
+ return requirements;
3222
+ }
3223
+ // Get existing dictionary entries from metadata
3224
+ const existingDictionary = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
3225
+ // Merge the new dictionary entry with existing entries
3226
+ const mergedDictionary = existingDictionary
3227
+ ? `${existingDictionary}\n${trimmedContent}`
3228
+ : trimmedContent;
3229
+ // Store the merged dictionary in metadata for debugging and inspection
3230
+ const updatedMetadata = {
3231
+ ...requirements.metadata,
3232
+ DICTIONARY: mergedDictionary,
3233
+ };
3234
+ // Create the dictionary section for the system message
3235
+ // Format: "# DICTIONARY\nTerm: definition\nTerm: definition..."
3236
+ const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
3237
+ return {
3238
+ ...this.appendToSystemMessage(requirements, dictionarySection),
3239
+ metadata: updatedMetadata,
3240
+ };
3241
+ }
3242
+ }
3243
+ /**
3244
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3245
+ */
3246
+
3174
3247
  /**
3175
3248
  * FORMAT commitment definition
3176
3249
  *
@@ -5991,6 +6064,7 @@ const COMMITMENT_REGISTRY = [
5991
6064
  new DeleteCommitmentDefinition('CANCEL'),
5992
6065
  new DeleteCommitmentDefinition('DISCARD'),
5993
6066
  new DeleteCommitmentDefinition('REMOVE'),
6067
+ new DictionaryCommitmentDefinition(),
5994
6068
  new OpenCommitmentDefinition(),
5995
6069
  new ClosedCommitmentDefinition(),
5996
6070
  new UseBrowserCommitmentDefinition(),
@@ -6263,6 +6337,7 @@ function parseAgentSource(agentSource) {
6263
6337
  return {
6264
6338
  agentName: normalizeAgentName(parseResult.agentName || createDefaultAgentName(agentSource)),
6265
6339
  agentHash,
6340
+ permanentId: meta.id,
6266
6341
  personaDescription,
6267
6342
  initialMessage,
6268
6343
  meta,