@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/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-
|
|
26
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.104.0-3';
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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(),
|
|
@@ -6035,17 +6109,64 @@
|
|
|
6035
6109
|
};
|
|
6036
6110
|
}
|
|
6037
6111
|
const lines = agentSource.split('\n');
|
|
6038
|
-
|
|
6112
|
+
let agentName = null;
|
|
6113
|
+
let agentNameLineIndex = -1;
|
|
6114
|
+
// Find the agent name: first non-empty line that is not a commitment and not a horizontal line
|
|
6115
|
+
for (let i = 0; i < lines.length; i++) {
|
|
6116
|
+
const line = lines[i];
|
|
6117
|
+
if (line === undefined) {
|
|
6118
|
+
continue;
|
|
6119
|
+
}
|
|
6120
|
+
const trimmed = line.trim();
|
|
6121
|
+
if (!trimmed) {
|
|
6122
|
+
continue;
|
|
6123
|
+
}
|
|
6124
|
+
const isHorizontal = HORIZONTAL_LINE_PATTERN.test(line);
|
|
6125
|
+
if (isHorizontal) {
|
|
6126
|
+
continue;
|
|
6127
|
+
}
|
|
6128
|
+
let isCommitment = false;
|
|
6129
|
+
for (const definition of COMMITMENT_REGISTRY) {
|
|
6130
|
+
const typeRegex = definition.createTypeRegex();
|
|
6131
|
+
const match = typeRegex.exec(trimmed);
|
|
6132
|
+
if (match && ((_a = match.groups) === null || _a === void 0 ? void 0 : _a.type)) {
|
|
6133
|
+
isCommitment = true;
|
|
6134
|
+
break;
|
|
6135
|
+
}
|
|
6136
|
+
}
|
|
6137
|
+
if (!isCommitment) {
|
|
6138
|
+
agentName = trimmed;
|
|
6139
|
+
agentNameLineIndex = i;
|
|
6140
|
+
break;
|
|
6141
|
+
}
|
|
6142
|
+
}
|
|
6039
6143
|
const commitments = [];
|
|
6040
6144
|
const nonCommitmentLines = [];
|
|
6041
|
-
//
|
|
6042
|
-
|
|
6043
|
-
|
|
6145
|
+
// Add lines before agentName that are horizontal lines (they are non-commitment)
|
|
6146
|
+
for (let i = 0; i < agentNameLineIndex; i++) {
|
|
6147
|
+
const line = lines[i];
|
|
6148
|
+
if (line === undefined) {
|
|
6149
|
+
continue;
|
|
6150
|
+
}
|
|
6151
|
+
const trimmed = line.trim();
|
|
6152
|
+
if (!trimmed) {
|
|
6153
|
+
continue;
|
|
6154
|
+
}
|
|
6155
|
+
const isHorizontal = HORIZONTAL_LINE_PATTERN.test(line);
|
|
6156
|
+
if (isHorizontal) {
|
|
6157
|
+
nonCommitmentLines.push(line);
|
|
6158
|
+
}
|
|
6159
|
+
// Note: Commitments before agentName are not added to nonCommitmentLines
|
|
6160
|
+
}
|
|
6161
|
+
// Add the agent name line to non-commitment lines
|
|
6162
|
+
if (agentNameLineIndex >= 0) {
|
|
6163
|
+
nonCommitmentLines.push(lines[agentNameLineIndex]);
|
|
6044
6164
|
}
|
|
6045
6165
|
// Parse commitments with multiline support
|
|
6046
6166
|
let currentCommitment = null;
|
|
6047
|
-
// Process lines starting from the
|
|
6048
|
-
|
|
6167
|
+
// Process lines starting from after the agent name line
|
|
6168
|
+
const startIndex = agentNameLineIndex >= 0 ? agentNameLineIndex + 1 : 0;
|
|
6169
|
+
for (let i = startIndex; i < lines.length; i++) {
|
|
6049
6170
|
const line = lines[i];
|
|
6050
6171
|
if (line === undefined) {
|
|
6051
6172
|
continue;
|
|
@@ -6267,6 +6388,7 @@
|
|
|
6267
6388
|
return {
|
|
6268
6389
|
agentName: normalizeAgentName(parseResult.agentName || createDefaultAgentName(agentSource)),
|
|
6269
6390
|
agentHash,
|
|
6391
|
+
permanentId: meta.id,
|
|
6270
6392
|
personaDescription,
|
|
6271
6393
|
initialMessage,
|
|
6272
6394
|
meta,
|