@promptbook/browser 0.104.0-1 โ†’ 0.104.0-10

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 (42) hide show
  1. package/esm/index.es.js +177 -97
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/servers.d.ts +8 -0
  4. package/esm/typings/src/_packages/core.index.d.ts +2 -0
  5. package/esm/typings/src/_packages/types.index.d.ts +10 -2
  6. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +6 -1
  7. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirements.d.ts +6 -6
  8. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.closed.test.d.ts +1 -0
  9. package/esm/typings/src/book-2.0/utils/generatePlaceholderAgentProfileImageUrl.d.ts +3 -3
  10. package/esm/typings/src/book-components/Chat/Chat/ChatMessageItem.d.ts +5 -1
  11. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +5 -0
  12. package/esm/typings/src/book-components/Chat/CodeBlock/CodeBlock.d.ts +13 -0
  13. package/esm/typings/src/book-components/Chat/MarkdownContent/MarkdownContent.d.ts +1 -0
  14. package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +7 -11
  15. package/esm/typings/src/book-components/_common/Dropdown/Dropdown.d.ts +2 -2
  16. package/esm/typings/src/book-components/_common/MenuHoisting/MenuHoistingContext.d.ts +56 -0
  17. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +21 -11
  18. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +80 -14
  19. package/esm/typings/src/commitments/DICTIONARY/DICTIONARY.d.ts +46 -0
  20. package/esm/typings/src/commitments/index.d.ts +2 -1
  21. package/esm/typings/src/llm-providers/_multiple/MultipleLlmExecutionTools.d.ts +6 -2
  22. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +1 -1
  23. package/esm/typings/src/llm-providers/ollama/OllamaExecutionTools.d.ts +1 -1
  24. package/esm/typings/src/llm-providers/openai/createOpenAiCompatibleExecutionTools.d.ts +1 -1
  25. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -0
  26. package/esm/typings/src/types/Message.d.ts +49 -0
  27. package/esm/typings/src/types/ModelRequirements.d.ts +38 -14
  28. package/esm/typings/src/types/typeAliases.d.ts +23 -1
  29. package/esm/typings/src/utils/color/utils/colorToDataUrl.d.ts +2 -1
  30. package/esm/typings/src/utils/environment/$detectRuntimeEnvironment.d.ts +4 -4
  31. package/esm/typings/src/utils/environment/$isRunningInBrowser.d.ts +1 -1
  32. package/esm/typings/src/utils/environment/$isRunningInJest.d.ts +1 -1
  33. package/esm/typings/src/utils/environment/$isRunningInNode.d.ts +1 -1
  34. package/esm/typings/src/utils/environment/$isRunningInWebWorker.d.ts +1 -1
  35. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +2 -2
  36. package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
  37. package/esm/typings/src/utils/random/$randomBase58.d.ts +12 -0
  38. package/esm/typings/src/version.d.ts +1 -1
  39. package/package.json +2 -2
  40. package/umd/index.umd.js +179 -99
  41. package/umd/index.umd.js.map +1 -1
  42. package/esm/typings/src/book-2.0/utils/generateGravatarUrl.d.ts +0 -10
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-10';
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
  */
@@ -2048,44 +2049,6 @@
2048
2049
  * TODO: [๐ŸŒบ] Use some intermediate util splitWords
2049
2050
  */
2050
2051
 
2051
- /**
2052
- * Generates a gravatar URL based on agent name for fallback avatar
2053
- *
2054
- * @param agentName The agent name to generate avatar for
2055
- * @returns Gravatar URL
2056
- *
2057
- * @private - [๐Ÿคน] The fact that profile image is Gravatar is just implementation detail which should be hidden for consumer
2058
- */
2059
- function generateGravatarUrl(agentName) {
2060
- // Use a default name if none provided
2061
- const safeName = agentName || 'Anonymous Agent';
2062
- // Create a simple hash from the name for consistent avatar
2063
- let hash = 0;
2064
- for (let i = 0; i < safeName.length; i++) {
2065
- const char = safeName.charCodeAt(i);
2066
- hash = (hash << 5) - hash + char;
2067
- hash = hash & hash; // Convert to 32bit integer
2068
- }
2069
- const avatarId = Math.abs(hash).toString();
2070
- return `https://www.gravatar.com/avatar/${avatarId}?default=robohash&size=200&rating=x`;
2071
- }
2072
-
2073
- /**
2074
- * Generates an image for the agent to use as profile image
2075
- *
2076
- * @param agentName The agent name to generate avatar for
2077
- * @returns The placeholder profile image URL for the agent
2078
- *
2079
- * @public exported from `@promptbook/core`
2080
- */
2081
- function generatePlaceholderAgentProfileImageUrl(agentName) {
2082
- // Note: [๐Ÿคน] The fact that profile image is Gravatar is just implementation detail which should be hidden for consumer
2083
- return generateGravatarUrl(agentName);
2084
- }
2085
- /**
2086
- * TODO: [๐Ÿคน] Figure out best placeholder image generator https://i.pravatar.cc/1000?u=568
2087
- */
2088
-
2089
2052
  /**
2090
2053
  * Format either small or big number
2091
2054
  *
@@ -2661,42 +2624,6 @@
2661
2624
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
2662
2625
  */
2663
2626
 
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
2627
  /**
2701
2628
  * Normalizes agent name from arbitrary string to valid agent name
2702
2629
  *
@@ -3175,6 +3102,114 @@
3175
3102
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
3176
3103
  */
3177
3104
 
3105
+ /**
3106
+ * DICTIONARY commitment definition
3107
+ *
3108
+ * The DICTIONARY commitment defines specific terms and their meanings that the agent should use correctly
3109
+ * in its reasoning and responses. This ensures consistent terminology usage.
3110
+ *
3111
+ * Key features:
3112
+ * - Multiple DICTIONARY commitments are automatically merged into one
3113
+ * - Content is placed in a dedicated section of the system message
3114
+ * - Terms and definitions are stored in metadata.DICTIONARY for debugging
3115
+ * - Agent should use the defined terms correctly in responses
3116
+ *
3117
+ * Example usage in agent source:
3118
+ *
3119
+ * ```book
3120
+ * Legal Assistant
3121
+ *
3122
+ * PERSONA You are a knowledgeable legal assistant
3123
+ * DICTIONARY Misdemeanor is a minor wrongdoing or criminal offense
3124
+ * DICTIONARY Felony is a serious crime usually punishable by imprisonment for more than one year
3125
+ * DICTIONARY Tort is a civil wrong that causes harm or loss to another person, leading to legal liability
3126
+ * ```
3127
+ *
3128
+ * @private [๐Ÿช”] Maybe export the commitments through some package
3129
+ */
3130
+ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
3131
+ constructor() {
3132
+ super('DICTIONARY');
3133
+ }
3134
+ /**
3135
+ * Short one-line description of DICTIONARY.
3136
+ */
3137
+ get description() {
3138
+ return 'Define terms and their meanings for consistent terminology usage.';
3139
+ }
3140
+ /**
3141
+ * Icon for this commitment.
3142
+ */
3143
+ get icon() {
3144
+ return '๐Ÿ“š';
3145
+ }
3146
+ /**
3147
+ * Markdown documentation for DICTIONARY commitment.
3148
+ */
3149
+ get documentation() {
3150
+ return spaceTrim$1.spaceTrim(`
3151
+ # DICTIONARY
3152
+
3153
+ Defines specific terms and their meanings that the agent should use correctly in reasoning and responses.
3154
+
3155
+ ## Key aspects
3156
+
3157
+ - Multiple \`DICTIONARY\` commitments are merged together.
3158
+ - Terms are defined in the format: "Term is definition"
3159
+ - The agent should use these terms consistently in responses.
3160
+ - Definitions help ensure accurate and consistent terminology.
3161
+
3162
+ ## Examples
3163
+
3164
+ \`\`\`book
3165
+ Legal Assistant
3166
+
3167
+ PERSONA You are a knowledgeable legal assistant specializing in criminal law
3168
+ DICTIONARY Misdemeanor is a minor wrongdoing or criminal offense
3169
+ DICTIONARY Felony is a serious crime usually punishable by imprisonment for more than one year
3170
+ DICTIONARY Tort is a civil wrong that causes harm or loss to another person, leading to legal liability
3171
+ \`\`\`
3172
+
3173
+ \`\`\`book
3174
+ Medical Assistant
3175
+
3176
+ PERSONA You are a helpful medical assistant
3177
+ DICTIONARY Hypertension is persistently high blood pressure
3178
+ DICTIONARY Diabetes is a chronic condition that affects how the body processes blood sugar
3179
+ DICTIONARY Vaccine is a biological preparation that provides active immunity to a particular disease
3180
+ \`\`\`
3181
+ `);
3182
+ }
3183
+ applyToAgentModelRequirements(requirements, content) {
3184
+ var _a;
3185
+ const trimmedContent = content.trim();
3186
+ if (!trimmedContent) {
3187
+ return requirements;
3188
+ }
3189
+ // Get existing dictionary entries from metadata
3190
+ const existingDictionary = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
3191
+ // Merge the new dictionary entry with existing entries
3192
+ const mergedDictionary = existingDictionary
3193
+ ? `${existingDictionary}\n${trimmedContent}`
3194
+ : trimmedContent;
3195
+ // Store the merged dictionary in metadata for debugging and inspection
3196
+ const updatedMetadata = {
3197
+ ...requirements.metadata,
3198
+ DICTIONARY: mergedDictionary,
3199
+ };
3200
+ // Create the dictionary section for the system message
3201
+ // Format: "# DICTIONARY\nTerm: definition\nTerm: definition..."
3202
+ const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
3203
+ return {
3204
+ ...this.appendToSystemMessage(requirements, dictionarySection),
3205
+ metadata: updatedMetadata,
3206
+ };
3207
+ }
3208
+ }
3209
+ /**
3210
+ * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
3211
+ */
3212
+
3178
3213
  /**
3179
3214
  * FORMAT commitment definition
3180
3215
  *
@@ -5995,6 +6030,7 @@
5995
6030
  new DeleteCommitmentDefinition('CANCEL'),
5996
6031
  new DeleteCommitmentDefinition('DISCARD'),
5997
6032
  new DeleteCommitmentDefinition('REMOVE'),
6033
+ new DictionaryCommitmentDefinition(),
5998
6034
  new OpenCommitmentDefinition(),
5999
6035
  new ClosedCommitmentDefinition(),
6000
6036
  new UseBrowserCommitmentDefinition(),
@@ -6035,17 +6071,64 @@
6035
6071
  };
6036
6072
  }
6037
6073
  const lines = agentSource.split('\n');
6038
- const agentName = (((_a = lines[0]) === null || _a === void 0 ? void 0 : _a.trim()) || null);
6074
+ let agentName = null;
6075
+ let agentNameLineIndex = -1;
6076
+ // Find the agent name: first non-empty line that is not a commitment and not a horizontal line
6077
+ for (let i = 0; i < lines.length; i++) {
6078
+ const line = lines[i];
6079
+ if (line === undefined) {
6080
+ continue;
6081
+ }
6082
+ const trimmed = line.trim();
6083
+ if (!trimmed) {
6084
+ continue;
6085
+ }
6086
+ const isHorizontal = HORIZONTAL_LINE_PATTERN.test(line);
6087
+ if (isHorizontal) {
6088
+ continue;
6089
+ }
6090
+ let isCommitment = false;
6091
+ for (const definition of COMMITMENT_REGISTRY) {
6092
+ const typeRegex = definition.createTypeRegex();
6093
+ const match = typeRegex.exec(trimmed);
6094
+ if (match && ((_a = match.groups) === null || _a === void 0 ? void 0 : _a.type)) {
6095
+ isCommitment = true;
6096
+ break;
6097
+ }
6098
+ }
6099
+ if (!isCommitment) {
6100
+ agentName = trimmed;
6101
+ agentNameLineIndex = i;
6102
+ break;
6103
+ }
6104
+ }
6039
6105
  const commitments = [];
6040
6106
  const nonCommitmentLines = [];
6041
- // Always add the first line (agent name) to non-commitment lines
6042
- if (lines[0] !== undefined) {
6043
- nonCommitmentLines.push(lines[0]);
6107
+ // Add lines before agentName that are horizontal lines (they are non-commitment)
6108
+ for (let i = 0; i < agentNameLineIndex; i++) {
6109
+ const line = lines[i];
6110
+ if (line === undefined) {
6111
+ continue;
6112
+ }
6113
+ const trimmed = line.trim();
6114
+ if (!trimmed) {
6115
+ continue;
6116
+ }
6117
+ const isHorizontal = HORIZONTAL_LINE_PATTERN.test(line);
6118
+ if (isHorizontal) {
6119
+ nonCommitmentLines.push(line);
6120
+ }
6121
+ // Note: Commitments before agentName are not added to nonCommitmentLines
6122
+ }
6123
+ // Add the agent name line to non-commitment lines
6124
+ if (agentNameLineIndex >= 0) {
6125
+ nonCommitmentLines.push(lines[agentNameLineIndex]);
6044
6126
  }
6045
6127
  // Parse commitments with multiline support
6046
6128
  let currentCommitment = null;
6047
- // Process lines starting from the second line (skip agent name)
6048
- for (let i = 1; i < lines.length; i++) {
6129
+ // Process lines starting from after the agent name line
6130
+ const startIndex = agentNameLineIndex >= 0 ? agentNameLineIndex + 1 : 0;
6131
+ for (let i = startIndex; i < lines.length; i++) {
6049
6132
  const line = lines[i];
6050
6133
  if (line === undefined) {
6051
6134
  continue;
@@ -6252,10 +6335,6 @@
6252
6335
  const metaType = normalizeTo_camelCase(metaTypeRaw);
6253
6336
  meta[metaType] = spaceTrim__default["default"](commitment.content.substring(metaTypeRaw.length));
6254
6337
  }
6255
- // Generate gravatar fallback if no meta image specified
6256
- if (!meta.image) {
6257
- meta.image = generatePlaceholderAgentProfileImageUrl(parseResult.agentName || '!!');
6258
- }
6259
6338
  // Generate fullname fallback if no meta fullname specified
6260
6339
  if (!meta.fullname) {
6261
6340
  meta.fullname = parseResult.agentName || createDefaultAgentName(agentSource);
@@ -6267,6 +6346,7 @@
6267
6346
  return {
6268
6347
  agentName: normalizeAgentName(parseResult.agentName || createDefaultAgentName(agentSource)),
6269
6348
  agentHash,
6349
+ permanentId: meta.id,
6270
6350
  personaDescription,
6271
6351
  initialMessage,
6272
6352
  meta,