@promptbook/browser 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.
- package/esm/index.es.js +177 -55
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/types.index.d.ts +8 -2
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +6 -1
- package/esm/typings/src/book-components/Chat/Chat/ChatMessageItem.d.ts +5 -1
- package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +5 -0
- package/esm/typings/src/book-components/Chat/CodeBlock/CodeBlock.d.ts +13 -0
- package/esm/typings/src/book-components/Chat/MarkdownContent/MarkdownContent.d.ts +1 -0
- package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +7 -11
- package/esm/typings/src/book-components/_common/Dropdown/Dropdown.d.ts +2 -2
- package/esm/typings/src/book-components/_common/MenuHoisting/MenuHoistingContext.d.ts +56 -0
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +13 -7
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +6 -0
- package/esm/typings/src/commitments/DICTIONARY/DICTIONARY.d.ts +46 -0
- package/esm/typings/src/commitments/index.d.ts +2 -1
- package/esm/typings/src/llm-providers/ollama/OllamaExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/createOpenAiCompatibleExecutionTools.d.ts +1 -1
- package/esm/typings/src/types/Message.d.ts +49 -0
- package/esm/typings/src/types/typeAliases.d.ts +12 -0
- package/esm/typings/src/utils/environment/$detectRuntimeEnvironment.d.ts +4 -4
- package/esm/typings/src/utils/environment/$isRunningInBrowser.d.ts +1 -1
- package/esm/typings/src/utils/environment/$isRunningInJest.d.ts +1 -1
- package/esm/typings/src/utils/environment/$isRunningInNode.d.ts +1 -1
- package/esm/typings/src/utils/environment/$isRunningInWebWorker.d.ts +1 -1
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +2 -2
- package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
- package/esm/typings/src/utils/random/$randomBase58.d.ts +12 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +179 -57
- 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-
|
|
22
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.104.0-3';
|
|
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
|
-
|
|
121
|
+
function $isRunningInBrowser() {
|
|
122
122
|
try {
|
|
123
|
-
return
|
|
124
|
-
}
|
|
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
|
-
|
|
140
|
+
function $isRunningInWebWorker() {
|
|
140
141
|
try {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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(),
|
|
@@ -6031,17 +6105,64 @@ function parseAgentSourceWithCommitments(agentSource) {
|
|
|
6031
6105
|
};
|
|
6032
6106
|
}
|
|
6033
6107
|
const lines = agentSource.split('\n');
|
|
6034
|
-
|
|
6108
|
+
let agentName = null;
|
|
6109
|
+
let agentNameLineIndex = -1;
|
|
6110
|
+
// Find the agent name: first non-empty line that is not a commitment and not a horizontal line
|
|
6111
|
+
for (let i = 0; i < lines.length; i++) {
|
|
6112
|
+
const line = lines[i];
|
|
6113
|
+
if (line === undefined) {
|
|
6114
|
+
continue;
|
|
6115
|
+
}
|
|
6116
|
+
const trimmed = line.trim();
|
|
6117
|
+
if (!trimmed) {
|
|
6118
|
+
continue;
|
|
6119
|
+
}
|
|
6120
|
+
const isHorizontal = HORIZONTAL_LINE_PATTERN.test(line);
|
|
6121
|
+
if (isHorizontal) {
|
|
6122
|
+
continue;
|
|
6123
|
+
}
|
|
6124
|
+
let isCommitment = false;
|
|
6125
|
+
for (const definition of COMMITMENT_REGISTRY) {
|
|
6126
|
+
const typeRegex = definition.createTypeRegex();
|
|
6127
|
+
const match = typeRegex.exec(trimmed);
|
|
6128
|
+
if (match && ((_a = match.groups) === null || _a === void 0 ? void 0 : _a.type)) {
|
|
6129
|
+
isCommitment = true;
|
|
6130
|
+
break;
|
|
6131
|
+
}
|
|
6132
|
+
}
|
|
6133
|
+
if (!isCommitment) {
|
|
6134
|
+
agentName = trimmed;
|
|
6135
|
+
agentNameLineIndex = i;
|
|
6136
|
+
break;
|
|
6137
|
+
}
|
|
6138
|
+
}
|
|
6035
6139
|
const commitments = [];
|
|
6036
6140
|
const nonCommitmentLines = [];
|
|
6037
|
-
//
|
|
6038
|
-
|
|
6039
|
-
|
|
6141
|
+
// Add lines before agentName that are horizontal lines (they are non-commitment)
|
|
6142
|
+
for (let i = 0; i < agentNameLineIndex; i++) {
|
|
6143
|
+
const line = lines[i];
|
|
6144
|
+
if (line === undefined) {
|
|
6145
|
+
continue;
|
|
6146
|
+
}
|
|
6147
|
+
const trimmed = line.trim();
|
|
6148
|
+
if (!trimmed) {
|
|
6149
|
+
continue;
|
|
6150
|
+
}
|
|
6151
|
+
const isHorizontal = HORIZONTAL_LINE_PATTERN.test(line);
|
|
6152
|
+
if (isHorizontal) {
|
|
6153
|
+
nonCommitmentLines.push(line);
|
|
6154
|
+
}
|
|
6155
|
+
// Note: Commitments before agentName are not added to nonCommitmentLines
|
|
6156
|
+
}
|
|
6157
|
+
// Add the agent name line to non-commitment lines
|
|
6158
|
+
if (agentNameLineIndex >= 0) {
|
|
6159
|
+
nonCommitmentLines.push(lines[agentNameLineIndex]);
|
|
6040
6160
|
}
|
|
6041
6161
|
// Parse commitments with multiline support
|
|
6042
6162
|
let currentCommitment = null;
|
|
6043
|
-
// Process lines starting from the
|
|
6044
|
-
|
|
6163
|
+
// Process lines starting from after the agent name line
|
|
6164
|
+
const startIndex = agentNameLineIndex >= 0 ? agentNameLineIndex + 1 : 0;
|
|
6165
|
+
for (let i = startIndex; i < lines.length; i++) {
|
|
6045
6166
|
const line = lines[i];
|
|
6046
6167
|
if (line === undefined) {
|
|
6047
6168
|
continue;
|
|
@@ -6263,6 +6384,7 @@ function parseAgentSource(agentSource) {
|
|
|
6263
6384
|
return {
|
|
6264
6385
|
agentName: normalizeAgentName(parseResult.agentName || createDefaultAgentName(agentSource)),
|
|
6265
6386
|
agentHash,
|
|
6387
|
+
permanentId: meta.id,
|
|
6266
6388
|
personaDescription,
|
|
6267
6389
|
initialMessage,
|
|
6268
6390
|
meta,
|