@promptbook/browser 0.104.0-0 โ†’ 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/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-10';
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
  */
@@ -2044,44 +2045,6 @@ function normalizeTo_camelCase(text, _isFirstLetterCapital = false) {
2044
2045
  * TODO: [๐ŸŒบ] Use some intermediate util splitWords
2045
2046
  */
2046
2047
 
2047
- /**
2048
- * Generates a gravatar URL based on agent name for fallback avatar
2049
- *
2050
- * @param agentName The agent name to generate avatar for
2051
- * @returns Gravatar URL
2052
- *
2053
- * @private - [๐Ÿคน] The fact that profile image is Gravatar is just implementation detail which should be hidden for consumer
2054
- */
2055
- function generateGravatarUrl(agentName) {
2056
- // Use a default name if none provided
2057
- const safeName = agentName || 'Anonymous Agent';
2058
- // Create a simple hash from the name for consistent avatar
2059
- let hash = 0;
2060
- for (let i = 0; i < safeName.length; i++) {
2061
- const char = safeName.charCodeAt(i);
2062
- hash = (hash << 5) - hash + char;
2063
- hash = hash & hash; // Convert to 32bit integer
2064
- }
2065
- const avatarId = Math.abs(hash).toString();
2066
- return `https://www.gravatar.com/avatar/${avatarId}?default=robohash&size=200&rating=x`;
2067
- }
2068
-
2069
- /**
2070
- * Generates an image for the agent to use as profile image
2071
- *
2072
- * @param agentName The agent name to generate avatar for
2073
- * @returns The placeholder profile image URL for the agent
2074
- *
2075
- * @public exported from `@promptbook/core`
2076
- */
2077
- function generatePlaceholderAgentProfileImageUrl(agentName) {
2078
- // Note: [๐Ÿคน] The fact that profile image is Gravatar is just implementation detail which should be hidden for consumer
2079
- return generateGravatarUrl(agentName);
2080
- }
2081
- /**
2082
- * TODO: [๐Ÿคน] Figure out best placeholder image generator https://i.pravatar.cc/1000?u=568
2083
- */
2084
-
2085
2048
  /**
2086
2049
  * Format either small or big number
2087
2050
  *
@@ -2657,42 +2620,6 @@ function titleToName(value) {
2657
2620
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
2658
2621
  */
2659
2622
 
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
2623
  /**
2697
2624
  * Normalizes agent name from arbitrary string to valid agent name
2698
2625
  *
@@ -3171,6 +3098,114 @@ class DeleteCommitmentDefinition extends BaseCommitmentDefinition {
3171
3098
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
3172
3099
  */
3173
3100
 
3101
+ /**
3102
+ * DICTIONARY commitment definition
3103
+ *
3104
+ * The DICTIONARY commitment defines specific terms and their meanings that the agent should use correctly
3105
+ * in its reasoning and responses. This ensures consistent terminology usage.
3106
+ *
3107
+ * Key features:
3108
+ * - Multiple DICTIONARY commitments are automatically merged into one
3109
+ * - Content is placed in a dedicated section of the system message
3110
+ * - Terms and definitions are stored in metadata.DICTIONARY for debugging
3111
+ * - Agent should use the defined terms correctly in responses
3112
+ *
3113
+ * Example usage in agent source:
3114
+ *
3115
+ * ```book
3116
+ * Legal Assistant
3117
+ *
3118
+ * PERSONA You are a knowledgeable legal assistant
3119
+ * DICTIONARY Misdemeanor is a minor wrongdoing or criminal offense
3120
+ * DICTIONARY Felony is a serious crime usually punishable by imprisonment for more than one year
3121
+ * DICTIONARY Tort is a civil wrong that causes harm or loss to another person, leading to legal liability
3122
+ * ```
3123
+ *
3124
+ * @private [๐Ÿช”] Maybe export the commitments through some package
3125
+ */
3126
+ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
3127
+ constructor() {
3128
+ super('DICTIONARY');
3129
+ }
3130
+ /**
3131
+ * Short one-line description of DICTIONARY.
3132
+ */
3133
+ get description() {
3134
+ return 'Define terms and their meanings for consistent terminology usage.';
3135
+ }
3136
+ /**
3137
+ * Icon for this commitment.
3138
+ */
3139
+ get icon() {
3140
+ return '๐Ÿ“š';
3141
+ }
3142
+ /**
3143
+ * Markdown documentation for DICTIONARY commitment.
3144
+ */
3145
+ get documentation() {
3146
+ return spaceTrim$1(`
3147
+ # DICTIONARY
3148
+
3149
+ Defines specific terms and their meanings that the agent should use correctly in reasoning and responses.
3150
+
3151
+ ## Key aspects
3152
+
3153
+ - Multiple \`DICTIONARY\` commitments are merged together.
3154
+ - Terms are defined in the format: "Term is definition"
3155
+ - The agent should use these terms consistently in responses.
3156
+ - Definitions help ensure accurate and consistent terminology.
3157
+
3158
+ ## Examples
3159
+
3160
+ \`\`\`book
3161
+ Legal Assistant
3162
+
3163
+ PERSONA You are a knowledgeable legal assistant specializing in criminal law
3164
+ DICTIONARY Misdemeanor is a minor wrongdoing or criminal offense
3165
+ DICTIONARY Felony is a serious crime usually punishable by imprisonment for more than one year
3166
+ DICTIONARY Tort is a civil wrong that causes harm or loss to another person, leading to legal liability
3167
+ \`\`\`
3168
+
3169
+ \`\`\`book
3170
+ Medical Assistant
3171
+
3172
+ PERSONA You are a helpful medical assistant
3173
+ DICTIONARY Hypertension is persistently high blood pressure
3174
+ DICTIONARY Diabetes is a chronic condition that affects how the body processes blood sugar
3175
+ DICTIONARY Vaccine is a biological preparation that provides active immunity to a particular disease
3176
+ \`\`\`
3177
+ `);
3178
+ }
3179
+ applyToAgentModelRequirements(requirements, content) {
3180
+ var _a;
3181
+ const trimmedContent = content.trim();
3182
+ if (!trimmedContent) {
3183
+ return requirements;
3184
+ }
3185
+ // Get existing dictionary entries from metadata
3186
+ const existingDictionary = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
3187
+ // Merge the new dictionary entry with existing entries
3188
+ const mergedDictionary = existingDictionary
3189
+ ? `${existingDictionary}\n${trimmedContent}`
3190
+ : trimmedContent;
3191
+ // Store the merged dictionary in metadata for debugging and inspection
3192
+ const updatedMetadata = {
3193
+ ...requirements.metadata,
3194
+ DICTIONARY: mergedDictionary,
3195
+ };
3196
+ // Create the dictionary section for the system message
3197
+ // Format: "# DICTIONARY\nTerm: definition\nTerm: definition..."
3198
+ const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
3199
+ return {
3200
+ ...this.appendToSystemMessage(requirements, dictionarySection),
3201
+ metadata: updatedMetadata,
3202
+ };
3203
+ }
3204
+ }
3205
+ /**
3206
+ * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
3207
+ */
3208
+
3174
3209
  /**
3175
3210
  * FORMAT commitment definition
3176
3211
  *
@@ -5991,6 +6026,7 @@ const COMMITMENT_REGISTRY = [
5991
6026
  new DeleteCommitmentDefinition('CANCEL'),
5992
6027
  new DeleteCommitmentDefinition('DISCARD'),
5993
6028
  new DeleteCommitmentDefinition('REMOVE'),
6029
+ new DictionaryCommitmentDefinition(),
5994
6030
  new OpenCommitmentDefinition(),
5995
6031
  new ClosedCommitmentDefinition(),
5996
6032
  new UseBrowserCommitmentDefinition(),
@@ -6031,17 +6067,64 @@ function parseAgentSourceWithCommitments(agentSource) {
6031
6067
  };
6032
6068
  }
6033
6069
  const lines = agentSource.split('\n');
6034
- const agentName = (((_a = lines[0]) === null || _a === void 0 ? void 0 : _a.trim()) || null);
6070
+ let agentName = null;
6071
+ let agentNameLineIndex = -1;
6072
+ // Find the agent name: first non-empty line that is not a commitment and not a horizontal line
6073
+ for (let i = 0; i < lines.length; i++) {
6074
+ const line = lines[i];
6075
+ if (line === undefined) {
6076
+ continue;
6077
+ }
6078
+ const trimmed = line.trim();
6079
+ if (!trimmed) {
6080
+ continue;
6081
+ }
6082
+ const isHorizontal = HORIZONTAL_LINE_PATTERN.test(line);
6083
+ if (isHorizontal) {
6084
+ continue;
6085
+ }
6086
+ let isCommitment = false;
6087
+ for (const definition of COMMITMENT_REGISTRY) {
6088
+ const typeRegex = definition.createTypeRegex();
6089
+ const match = typeRegex.exec(trimmed);
6090
+ if (match && ((_a = match.groups) === null || _a === void 0 ? void 0 : _a.type)) {
6091
+ isCommitment = true;
6092
+ break;
6093
+ }
6094
+ }
6095
+ if (!isCommitment) {
6096
+ agentName = trimmed;
6097
+ agentNameLineIndex = i;
6098
+ break;
6099
+ }
6100
+ }
6035
6101
  const commitments = [];
6036
6102
  const nonCommitmentLines = [];
6037
- // Always add the first line (agent name) to non-commitment lines
6038
- if (lines[0] !== undefined) {
6039
- nonCommitmentLines.push(lines[0]);
6103
+ // Add lines before agentName that are horizontal lines (they are non-commitment)
6104
+ for (let i = 0; i < agentNameLineIndex; i++) {
6105
+ const line = lines[i];
6106
+ if (line === undefined) {
6107
+ continue;
6108
+ }
6109
+ const trimmed = line.trim();
6110
+ if (!trimmed) {
6111
+ continue;
6112
+ }
6113
+ const isHorizontal = HORIZONTAL_LINE_PATTERN.test(line);
6114
+ if (isHorizontal) {
6115
+ nonCommitmentLines.push(line);
6116
+ }
6117
+ // Note: Commitments before agentName are not added to nonCommitmentLines
6118
+ }
6119
+ // Add the agent name line to non-commitment lines
6120
+ if (agentNameLineIndex >= 0) {
6121
+ nonCommitmentLines.push(lines[agentNameLineIndex]);
6040
6122
  }
6041
6123
  // Parse commitments with multiline support
6042
6124
  let currentCommitment = null;
6043
- // Process lines starting from the second line (skip agent name)
6044
- for (let i = 1; i < lines.length; i++) {
6125
+ // Process lines starting from after the agent name line
6126
+ const startIndex = agentNameLineIndex >= 0 ? agentNameLineIndex + 1 : 0;
6127
+ for (let i = startIndex; i < lines.length; i++) {
6045
6128
  const line = lines[i];
6046
6129
  if (line === undefined) {
6047
6130
  continue;
@@ -6248,10 +6331,6 @@ function parseAgentSource(agentSource) {
6248
6331
  const metaType = normalizeTo_camelCase(metaTypeRaw);
6249
6332
  meta[metaType] = spaceTrim$2(commitment.content.substring(metaTypeRaw.length));
6250
6333
  }
6251
- // Generate gravatar fallback if no meta image specified
6252
- if (!meta.image) {
6253
- meta.image = generatePlaceholderAgentProfileImageUrl(parseResult.agentName || '!!');
6254
- }
6255
6334
  // Generate fullname fallback if no meta fullname specified
6256
6335
  if (!meta.fullname) {
6257
6336
  meta.fullname = parseResult.agentName || createDefaultAgentName(agentSource);
@@ -6263,6 +6342,7 @@ function parseAgentSource(agentSource) {
6263
6342
  return {
6264
6343
  agentName: normalizeAgentName(parseResult.agentName || createDefaultAgentName(agentSource)),
6265
6344
  agentHash,
6345
+ permanentId: meta.id,
6266
6346
  personaDescription,
6267
6347
  initialMessage,
6268
6348
  meta,