@promptbook/wizard 0.100.0 โ 0.100.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.
- package/esm/index.es.js +55 -20
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/book-2.0/agent-source/parseAgentSource.d.ts +2 -2
- package/esm/typings/src/book-2.0/commitments/_base/CommitmentDefinition.d.ts +2 -2
- package/esm/typings/src/book-2.0/commitments/_misc/AgentModelRequirements.d.ts +2 -2
- package/esm/typings/src/book-2.0/commitments/_misc/AgentSourceParseResult.d.ts +2 -2
- package/esm/typings/src/book-2.0/commitments/_misc/ParsedCommitment.d.ts +2 -2
- package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/AvatarProfile.d.ts +3 -0
- package/esm/typings/src/book-components/BookEditor/BookEditor.d.ts +5 -0
- package/esm/typings/src/book-components/Chat/types/ChatParticipant.d.ts +4 -4
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +3 -6
- package/esm/typings/src/execution/utils/validatePromptResult.d.ts +4 -4
- package/esm/typings/src/llm-providers/_common/profiles/llmProviderProfiles.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +3 -4
- package/esm/typings/src/utils/color/Color.d.ts +1 -2
- package/esm/typings/src/utils/take/interfaces/ITakeChain.d.ts +2 -2
- package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +1 -1
- package/esm/typings/src/version.d.ts +1 -1
- package/esm/typings/src/wizard/wizard.d.ts +2 -2
- package/package.json +2 -2
- package/umd/index.umd.js +54 -19
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
@@ -11,7 +11,7 @@ import { spawn } from 'child_process';
|
|
11
11
|
import { forTime } from 'waitasecond';
|
12
12
|
import { SHA256 } from 'crypto-js';
|
13
13
|
import hexEncoder from 'crypto-js/enc-hex';
|
14
|
-
import { basename, join, dirname, relative } from 'path';
|
14
|
+
import { basename, join, dirname, isAbsolute, relative } from 'path';
|
15
15
|
import parserHtml from 'prettier/parser-html';
|
16
16
|
import parserMarkdown from 'prettier/parser-markdown';
|
17
17
|
import { format } from 'prettier/standalone';
|
@@ -39,7 +39,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
39
39
|
* @generated
|
40
40
|
* @see https://github.com/webgptorg/promptbook
|
41
41
|
*/
|
42
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.100.
|
42
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.100.2';
|
43
43
|
/**
|
44
44
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
45
45
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
@@ -1401,7 +1401,7 @@ const LLM_PROVIDER_PROFILES = {
|
|
1401
1401
|
};
|
1402
1402
|
/**
|
1403
1403
|
* TODO: Refactor this - each profile must be alongside the provider definition
|
1404
|
-
* TODO: Unite `AvatarProfileProps`
|
1404
|
+
* TODO: [๐] Unite `AvatarProfileProps`, `ChatParticipant`, `LlmExecutionTools` + `LlmToolsMetadata`
|
1405
1405
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
1406
1406
|
*/
|
1407
1407
|
|
@@ -6217,7 +6217,7 @@ function removeEmojis(text) {
|
|
6217
6217
|
}
|
6218
6218
|
|
6219
6219
|
/**
|
6220
|
-
* Tests if given string is valid
|
6220
|
+
* Tests if given string is valid file path.
|
6221
6221
|
*
|
6222
6222
|
* Note: This does not check if the file exists only if the path is valid
|
6223
6223
|
* @public exported from `@promptbook/utils`
|
@@ -6229,18 +6229,25 @@ function isValidFilePath(filename) {
|
|
6229
6229
|
if (filename.split('\n').length > 1) {
|
6230
6230
|
return false;
|
6231
6231
|
}
|
6232
|
-
|
6233
|
-
|
6232
|
+
// Normalize slashes early so heuristics can detect path-like inputs
|
6233
|
+
const filenameSlashes = filename.replace(/\\/g, '/');
|
6234
|
+
// Reject strings that look like sentences (informational text)
|
6235
|
+
// Heuristic: contains multiple spaces and ends with a period, or contains typical sentence punctuation
|
6236
|
+
// But skip this heuristic if the string looks like a path (contains '/' or starts with a drive letter)
|
6237
|
+
if (filename.trim().length > 60 && // long enough to be a sentence
|
6238
|
+
/[.!?]/.test(filename) && // contains sentence punctuation
|
6239
|
+
filename.split(' ').length > 8 && // has many words
|
6240
|
+
!/\/|^[A-Z]:/i.test(filenameSlashes) // do NOT treat as sentence if looks like a path
|
6241
|
+
) {
|
6234
6242
|
return false;
|
6235
6243
|
}
|
6236
|
-
const filenameSlashes = filename.split('\\').join('/');
|
6237
6244
|
// Absolute Unix path: /hello.txt
|
6238
6245
|
if (/^(\/)/i.test(filenameSlashes)) {
|
6239
6246
|
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
6240
6247
|
return true;
|
6241
6248
|
}
|
6242
|
-
// Absolute Windows path:
|
6243
|
-
if (/^
|
6249
|
+
// Absolute Windows path: C:/ or C:\ (allow spaces and multiple dots in filename)
|
6250
|
+
if (/^[A-Z]:\/.+$/i.test(filenameSlashes)) {
|
6244
6251
|
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
6245
6252
|
return true;
|
6246
6253
|
}
|
@@ -8150,9 +8157,15 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
8150
8157
|
}
|
8151
8158
|
if (isValidUrl(knowledgeSourceContent)) {
|
8152
8159
|
const url = knowledgeSourceContent;
|
8160
|
+
if (isVerbose) {
|
8161
|
+
console.info(`๐ [1] "${name}" is available at "${url}"`);
|
8162
|
+
}
|
8153
8163
|
const response = await fetch(url); // <- TODO: [๐ง ] Scraping and fetch proxy
|
8154
8164
|
const mimeType = ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
8155
8165
|
if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [๐ต] */)) {
|
8166
|
+
if (isVerbose) {
|
8167
|
+
console.info(`๐ [2] "${name}" tools.fs is not available or URL is not a PDF.`);
|
8168
|
+
}
|
8156
8169
|
return {
|
8157
8170
|
source: name,
|
8158
8171
|
filename: null,
|
@@ -8188,13 +8201,17 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
8188
8201
|
await tools.fs.mkdir(dirname(join(rootDirname, filepath)), { recursive: true });
|
8189
8202
|
}
|
8190
8203
|
catch (error) {
|
8204
|
+
if (isVerbose) {
|
8205
|
+
console.info(`๐ [3] "${name}" error creating cache directory`);
|
8206
|
+
}
|
8191
8207
|
// Note: If we can't create cache directory, we'll handle it when trying to write the file
|
8192
8208
|
// This handles read-only filesystems, permission issues, and missing parent directories
|
8193
|
-
if (error instanceof Error &&
|
8194
|
-
error.message.includes('
|
8195
|
-
|
8196
|
-
|
8197
|
-
|
8209
|
+
if (error instanceof Error &&
|
8210
|
+
(error.message.includes('EROFS') ||
|
8211
|
+
error.message.includes('read-only') ||
|
8212
|
+
error.message.includes('EACCES') ||
|
8213
|
+
error.message.includes('EPERM') ||
|
8214
|
+
error.message.includes('ENOENT'))) ;
|
8198
8215
|
else {
|
8199
8216
|
// Re-throw other unexpected errors
|
8200
8217
|
throw error;
|
@@ -8209,13 +8226,17 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
8209
8226
|
await tools.fs.writeFile(join(rootDirname, filepath), fileContent);
|
8210
8227
|
}
|
8211
8228
|
catch (error) {
|
8229
|
+
if (isVerbose) {
|
8230
|
+
console.info(`๐ [4] "${name}" error writing cache file`);
|
8231
|
+
}
|
8212
8232
|
// Note: If we can't write to cache, we'll process the file directly from memory
|
8213
8233
|
// This handles read-only filesystems like Vercel
|
8214
|
-
if (error instanceof Error &&
|
8215
|
-
error.message.includes('
|
8216
|
-
|
8217
|
-
|
8218
|
-
|
8234
|
+
if (error instanceof Error &&
|
8235
|
+
(error.message.includes('EROFS') ||
|
8236
|
+
error.message.includes('read-only') ||
|
8237
|
+
error.message.includes('EACCES') ||
|
8238
|
+
error.message.includes('EPERM') ||
|
8239
|
+
error.message.includes('ENOENT'))) {
|
8219
8240
|
// Return a handler that works directly with the downloaded content
|
8220
8241
|
return {
|
8221
8242
|
source: name,
|
@@ -8237,6 +8258,9 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
8237
8258
|
}
|
8238
8259
|
// TODO: [๐ต] Check the file security
|
8239
8260
|
// TODO: [๐งน][๐ง ] Delete the file after the scraping is done
|
8261
|
+
if (isVerbose) {
|
8262
|
+
console.info(`๐ [5] "${name}" cached at "${join(rootDirname, filepath)}"`);
|
8263
|
+
}
|
8240
8264
|
return makeKnowledgeSourceHandler({ name, knowledgeSourceContent: filepath }, tools, {
|
8241
8265
|
...options,
|
8242
8266
|
rootDirname,
|
@@ -8251,7 +8275,12 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
8251
8275
|
throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
|
8252
8276
|
// <- TODO: [๐ง ] What is the best error type here`
|
8253
8277
|
}
|
8254
|
-
const filename =
|
8278
|
+
const filename = isAbsolute(knowledgeSourceContent)
|
8279
|
+
? knowledgeSourceContent
|
8280
|
+
: join(rootDirname, knowledgeSourceContent).split('\\').join('/');
|
8281
|
+
if (isVerbose) {
|
8282
|
+
console.info(`๐ [6] "${name}" is a valid file "${filename}"`);
|
8283
|
+
}
|
8255
8284
|
const fileExtension = getFileExtension(filename);
|
8256
8285
|
const mimeType = extensionToMimeType(fileExtension || '');
|
8257
8286
|
if (!(await isFileExisting(filename, tools.fs))) {
|
@@ -8293,6 +8322,12 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
8293
8322
|
};
|
8294
8323
|
}
|
8295
8324
|
else {
|
8325
|
+
if (isVerbose) {
|
8326
|
+
console.info(`๐ [7] "${name}" is just a explicit string text with a knowledge source`);
|
8327
|
+
console.info('---');
|
8328
|
+
console.info(knowledgeSourceContent);
|
8329
|
+
console.info('---');
|
8330
|
+
}
|
8296
8331
|
return {
|
8297
8332
|
source: name,
|
8298
8333
|
filename: null,
|