@promptbook/node 0.114.0-2 → 0.114.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 +98 -18
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/run-codex-prompts/common/runGoScript/scriptExecutionLog.d.ts +7 -0
- package/esm/scripts/run-codex-prompts/main/resolvePromptRunner.d.ts +8 -1
- package/esm/src/book-components/Chat/utils/$provideServerDomWindow.d.ts +11 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerRuntimeEnvironment.d.ts +7 -0
- package/esm/src/cli/cli-commands/coder/ping.d.ts +2 -5
- package/esm/src/cli/cli-commands/coder.d.ts +1 -1
- package/esm/src/cli/cli-commands/common/coderGitSyncCliOptions.d.ts +34 -0
- package/esm/src/cli/cli-commands/common/coderGitSyncCliOptions.test.d.ts +1 -0
- package/esm/src/cli/common/loadPromptsModule.d.ts +16 -0
- package/esm/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
- package/esm/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
- package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +1 -1
- package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.d.ts +1 -1
- package/esm/src/llm-providers/openai/OpenAiAssistantExecutionToolsStreamRunner.d.ts +1 -1
- package/esm/src/llm-providers/openai/OpenAiAssistantExecutionToolsToolRunner.d.ts +1 -1
- package/esm/src/llm-providers/openai/OpenAiCompatibleNonChatPromptCaller.d.ts +1 -1
- package/esm/src/llm-providers/openai/OpenAiCompatibleRequestManager.d.ts +1 -1
- package/esm/src/llm-providers/openai/utils/callOpenAiCompatibleChatModel.d.ts +1 -1
- package/esm/src/llm-providers/openai/utils/loadOpenAiAgentsModule.d.ts +203 -0
- package/esm/src/llm-providers/openai/utils/uploadFilesToOpenAi.d.ts +1 -1
- package/esm/src/utils/misc/createLazyModuleLoader.d.ts +14 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +117 -34
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/run-codex-prompts/common/runGoScript/scriptExecutionLog.d.ts +7 -0
- package/umd/scripts/run-codex-prompts/main/resolvePromptRunner.d.ts +8 -1
- package/umd/src/book-components/Chat/utils/$provideServerDomWindow.d.ts +11 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerRuntimeEnvironment.d.ts +7 -0
- package/umd/src/cli/cli-commands/coder/ping.d.ts +2 -5
- package/umd/src/cli/cli-commands/coder.d.ts +1 -1
- package/umd/src/cli/cli-commands/common/coderGitSyncCliOptions.d.ts +34 -0
- package/umd/src/cli/cli-commands/common/coderGitSyncCliOptions.test.d.ts +1 -0
- package/umd/src/cli/common/loadPromptsModule.d.ts +16 -0
- package/umd/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
- package/umd/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
- package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +1 -1
- package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.d.ts +1 -1
- package/umd/src/llm-providers/openai/OpenAiAssistantExecutionToolsStreamRunner.d.ts +1 -1
- package/umd/src/llm-providers/openai/OpenAiAssistantExecutionToolsToolRunner.d.ts +1 -1
- package/umd/src/llm-providers/openai/OpenAiCompatibleNonChatPromptCaller.d.ts +1 -1
- package/umd/src/llm-providers/openai/OpenAiCompatibleRequestManager.d.ts +1 -1
- package/umd/src/llm-providers/openai/utils/callOpenAiCompatibleChatModel.d.ts +1 -1
- package/umd/src/llm-providers/openai/utils/loadOpenAiAgentsModule.d.ts +203 -0
- package/umd/src/llm-providers/openai/utils/uploadFilesToOpenAi.d.ts +1 -1
- package/umd/src/utils/misc/createLazyModuleLoader.d.ts +14 -0
- package/umd/src/version.d.ts +1 -1
package/esm/index.es.js
CHANGED
|
@@ -3,14 +3,10 @@ import { unlink, mkdir, appendFile, writeFile, readFile, stat, access, constants
|
|
|
3
3
|
import _spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
4
4
|
import colors from 'colors';
|
|
5
5
|
import { spawn } from 'child_process';
|
|
6
|
-
import { fileSearchTool, tool, Agent as Agent$1, webSearchTool, run, setDefaultOpenAIClient, setDefaultOpenAIKey } from '@openai/agents';
|
|
7
6
|
import { fileURLToPath } from 'url';
|
|
8
|
-
import { Readability } from '@mozilla/readability';
|
|
9
|
-
import { JSDOM } from 'jsdom';
|
|
10
7
|
import CryptoJS from 'crypto-js';
|
|
11
8
|
import hexEncoder from 'crypto-js/enc-hex';
|
|
12
9
|
import showdown from 'showdown';
|
|
13
|
-
import JSZip from 'jszip';
|
|
14
10
|
import { forTime } from 'waitasecond';
|
|
15
11
|
import * as dotenv from 'dotenv';
|
|
16
12
|
import sha256 from 'crypto-js/sha256';
|
|
@@ -20,7 +16,6 @@ import moment from 'moment';
|
|
|
20
16
|
import { lookup, extension } from 'mime-types';
|
|
21
17
|
import papaparse from 'papaparse';
|
|
22
18
|
import Bottleneck from 'bottleneck';
|
|
23
|
-
import OpenAI from 'openai';
|
|
24
19
|
|
|
25
20
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
26
21
|
/**
|
|
@@ -36,7 +31,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
36
31
|
* @generated
|
|
37
32
|
* @see https://github.com/webgptorg/promptbook
|
|
38
33
|
*/
|
|
39
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.114.0-
|
|
34
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.114.0-3';
|
|
40
35
|
/**
|
|
41
36
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
42
37
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -2936,6 +2931,13 @@ function toPosixPath(filePath) {
|
|
|
2936
2931
|
* Environment variable read by the shell wrapper to tee live output into the temporary runtime log file.
|
|
2937
2932
|
*/
|
|
2938
2933
|
const PTBK_CODER_LOG_FILE_ENV_NAME = 'PTBK_CODER_LOG_FILE';
|
|
2934
|
+
/**
|
|
2935
|
+
* Log line which separates the raw script input from the raw script output of one execution section.
|
|
2936
|
+
*
|
|
2937
|
+
* Readers of a runtime log split on this marker to look only at what the harness really produced,
|
|
2938
|
+
* without the generated script and the prompt it embeds.
|
|
2939
|
+
*/
|
|
2940
|
+
const SCRIPT_EXECUTION_LOG_RAW_OUTPUT_MARKER = '--- raw output ---';
|
|
2939
2941
|
/**
|
|
2940
2942
|
* Small bash wrapper that preserves stdout/stderr streams while teeing both into the runtime log file.
|
|
2941
2943
|
*/
|
|
@@ -2971,7 +2973,7 @@ async function appendScriptExecutionLogStart({ scriptPath, scriptContent, logPat
|
|
|
2971
2973
|
--- raw input ---
|
|
2972
2974
|
${block(normalizedInput)}
|
|
2973
2975
|
|
|
2974
|
-
|
|
2976
|
+
${SCRIPT_EXECUTION_LOG_RAW_OUTPUT_MARKER}
|
|
2975
2977
|
`);
|
|
2976
2978
|
await appendFile(logPath, `${logSection}\n`, 'utf-8');
|
|
2977
2979
|
}
|
|
@@ -32903,6 +32905,41 @@ function buildToolInvocationScript(options) {
|
|
|
32903
32905
|
`;
|
|
32904
32906
|
}
|
|
32905
32907
|
|
|
32908
|
+
/**
|
|
32909
|
+
* Creates a loader which imports one module on the first call and reuses the very same module afterwards
|
|
32910
|
+
*
|
|
32911
|
+
* Note: [🐌] Heavy third-party dependencies are imported lazily to keep the startup of the Promptbook CLI fast.
|
|
32912
|
+
* A statically imported dependency is loaded every single time the bundle is loaded, even when the running
|
|
32913
|
+
* command never touches it. A lazily imported dependency is loaded only when the feature is really used.
|
|
32914
|
+
*
|
|
32915
|
+
* @example
|
|
32916
|
+
* const loadJsdomModule = createLazyModuleLoader(() => import('jsdom'));
|
|
32917
|
+
* const { JSDOM } = await loadJsdomModule();
|
|
32918
|
+
*
|
|
32919
|
+
* @private internal utility of Promptbook
|
|
32920
|
+
*/
|
|
32921
|
+
function createLazyModuleLoader(importModule) {
|
|
32922
|
+
let importedModulePromise = null;
|
|
32923
|
+
return function loadModule() {
|
|
32924
|
+
if (importedModulePromise === null) {
|
|
32925
|
+
importedModulePromise = importModule();
|
|
32926
|
+
}
|
|
32927
|
+
return importedModulePromise;
|
|
32928
|
+
};
|
|
32929
|
+
}
|
|
32930
|
+
// Note: [🐌] Do not convert the lazy `import(...)` calls back to static `import` statements, it would bring back the
|
|
32931
|
+
// slow startup of the `ptbk` CLI utility
|
|
32932
|
+
|
|
32933
|
+
/**
|
|
32934
|
+
* Loads the OpenAI AgentKit SDK (`@openai/agents`) on demand
|
|
32935
|
+
*
|
|
32936
|
+
* Note: [🐌] The AgentKit SDK is one of the heaviest dependencies of Promptbook, loading it eagerly would slow down
|
|
32937
|
+
* every single run of the `ptbk` CLI utility even when no AgentKit agent is used
|
|
32938
|
+
*
|
|
32939
|
+
* @private internal utility of `@promptbook/openai`
|
|
32940
|
+
*/
|
|
32941
|
+
const loadOpenAiAgentsModule = createLazyModuleLoader(() => import('@openai/agents'));
|
|
32942
|
+
|
|
32906
32943
|
/**
|
|
32907
32944
|
* Constant for default model used for nested DeepSearch tool invocations.
|
|
32908
32945
|
*/
|
|
@@ -32956,8 +32993,9 @@ class OpenAiAgentKitExecutionToolsToolBuilder {
|
|
|
32956
32993
|
/**
|
|
32957
32994
|
* Builds the tool list for AgentKit, including hosted file search when applicable.
|
|
32958
32995
|
*/
|
|
32959
|
-
buildAgentKitTools(options) {
|
|
32996
|
+
async buildAgentKitTools(options) {
|
|
32960
32997
|
const { tools, vectorStoreId } = options;
|
|
32998
|
+
const { fileSearchTool, tool: agentKitTool } = await loadOpenAiAgentsModule();
|
|
32961
32999
|
const agentKitTools = [];
|
|
32962
33000
|
if (vectorStoreId) {
|
|
32963
33001
|
agentKitTools.push(fileSearchTool(vectorStoreId));
|
|
@@ -32968,11 +33006,11 @@ class OpenAiAgentKitExecutionToolsToolBuilder {
|
|
|
32968
33006
|
let scriptTools = null;
|
|
32969
33007
|
for (const toolDefinition of tools) {
|
|
32970
33008
|
if (this.isDeepSearchToolDefinition(toolDefinition)) {
|
|
32971
|
-
agentKitTools.push(this.createDeepSearchAgentKitTool(toolDefinition));
|
|
33009
|
+
agentKitTools.push(await this.createDeepSearchAgentKitTool(toolDefinition));
|
|
32972
33010
|
continue;
|
|
32973
33011
|
}
|
|
32974
33012
|
scriptTools !== null && scriptTools !== void 0 ? scriptTools : (scriptTools = this.resolveScriptTools());
|
|
32975
|
-
agentKitTools.push(
|
|
33013
|
+
agentKitTools.push(agentKitTool({
|
|
32976
33014
|
name: toolDefinition.name,
|
|
32977
33015
|
description: toolDefinition.description,
|
|
32978
33016
|
parameters: this.normalizeAgentKitToolParameters(toolDefinition.parameters),
|
|
@@ -33179,8 +33217,9 @@ class OpenAiAgentKitExecutionToolsToolBuilder {
|
|
|
33179
33217
|
/**
|
|
33180
33218
|
* Creates the native Agent SDK tool used for `USE DEEPSEARCH`.
|
|
33181
33219
|
*/
|
|
33182
|
-
createDeepSearchAgentKitTool(toolDefinition) {
|
|
33183
|
-
const
|
|
33220
|
+
async createDeepSearchAgentKitTool(toolDefinition) {
|
|
33221
|
+
const { Agent: AgentFromKit, webSearchTool } = await loadOpenAiAgentsModule();
|
|
33222
|
+
const deepSearchAgent = new AgentFromKit({
|
|
33184
33223
|
name: 'DeepSearch',
|
|
33185
33224
|
model: DEFAULT_DEEP_SEARCH_MODEL_NAME,
|
|
33186
33225
|
instructions: this.createDeepSearchAgentInstructions(toolDefinition.description),
|
|
@@ -33748,6 +33787,14 @@ class OpenAiCompatibleNonChatPromptCaller {
|
|
|
33748
33787
|
}
|
|
33749
33788
|
}
|
|
33750
33789
|
|
|
33790
|
+
/**
|
|
33791
|
+
* Loads the OpenAI SDK (`openai`) on demand
|
|
33792
|
+
*
|
|
33793
|
+
* Note: [🐌] Loaded lazily to keep the startup of the `ptbk` CLI utility fast
|
|
33794
|
+
*
|
|
33795
|
+
* @private internal utility of `OpenAiCompatibleRequestManager`
|
|
33796
|
+
*/
|
|
33797
|
+
const loadOpenAiModule = createLazyModuleLoader(() => import('openai'));
|
|
33751
33798
|
/**
|
|
33752
33799
|
* Manages OpenAI-compatible client creation plus shared retry and rate-limit behavior.
|
|
33753
33800
|
*
|
|
@@ -33774,6 +33821,7 @@ class OpenAiCompatibleRequestManager {
|
|
|
33774
33821
|
timeout: API_REQUEST_TIMEOUT,
|
|
33775
33822
|
maxRetries: CONNECTION_RETRIES_LIMIT,
|
|
33776
33823
|
};
|
|
33824
|
+
const { default: OpenAI } = await loadOpenAiModule();
|
|
33777
33825
|
this.client = new OpenAI(enhancedOptions);
|
|
33778
33826
|
}
|
|
33779
33827
|
return this.client;
|
|
@@ -36120,7 +36168,23 @@ function createShowdownConverter() {
|
|
|
36120
36168
|
});
|
|
36121
36169
|
}
|
|
36122
36170
|
|
|
36123
|
-
|
|
36171
|
+
/**
|
|
36172
|
+
* Loads `jsdom` on demand
|
|
36173
|
+
*
|
|
36174
|
+
* Note: [🐌] `jsdom` is by far the heaviest dependency of Promptbook, loading it eagerly would slow down every single
|
|
36175
|
+
* run of the `ptbk` CLI utility even when no website is scraped
|
|
36176
|
+
*
|
|
36177
|
+
* @private internal utility of `WebsiteScraper`
|
|
36178
|
+
*/
|
|
36179
|
+
const loadJsdomModule = createLazyModuleLoader(() => import('jsdom'));
|
|
36180
|
+
/**
|
|
36181
|
+
* Loads `@mozilla/readability` on demand
|
|
36182
|
+
*
|
|
36183
|
+
* Note: [🐌] Loaded lazily to keep the startup of the `ptbk` CLI utility fast
|
|
36184
|
+
*
|
|
36185
|
+
* @private internal utility of `WebsiteScraper`
|
|
36186
|
+
*/
|
|
36187
|
+
const loadReadabilityModule = createLazyModuleLoader(() => import('@mozilla/readability'));
|
|
36124
36188
|
/**
|
|
36125
36189
|
* Scraper for websites
|
|
36126
36190
|
*
|
|
@@ -36156,6 +36220,7 @@ class WebsiteScraper {
|
|
|
36156
36220
|
if (this.tools.fs === undefined) {
|
|
36157
36221
|
throw new EnvironmentMismatchError('Can not scrape websites without filesystem tools');
|
|
36158
36222
|
}
|
|
36223
|
+
const [{ JSDOM }, { Readability }] = await Promise.all([loadJsdomModule(), loadReadabilityModule()]);
|
|
36159
36224
|
const jsdom = new JSDOM(await source.asText(), {
|
|
36160
36225
|
url: source.url,
|
|
36161
36226
|
});
|
|
@@ -39419,6 +39484,7 @@ class LiteAgent {
|
|
|
39419
39484
|
}
|
|
39420
39485
|
const preparedAgent = await this.prepareAgent();
|
|
39421
39486
|
(_a = preparedAgent.toolBuilder) === null || _a === void 0 ? void 0 : _a.clearRunState();
|
|
39487
|
+
const { run } = await loadOpenAiAgentsModule();
|
|
39422
39488
|
const result = await run(preparedAgent.agent, createLiteAgentPromptText(normalizedMessage, options.context, preparedAgent.modelRequirements.promptSuffix), options.signal ? { signal: options.signal } : undefined);
|
|
39423
39489
|
return formatLiteAgentOutput(result.finalOutput);
|
|
39424
39490
|
}
|
|
@@ -39458,6 +39524,7 @@ class LiteAgent {
|
|
|
39458
39524
|
userId: this.options.userId,
|
|
39459
39525
|
});
|
|
39460
39526
|
const client = await runtime.getClient();
|
|
39527
|
+
const { Agent: AgentFromKit, fileSearchTool, setDefaultOpenAIClient, setDefaultOpenAIKey, } = await loadOpenAiAgentsModule();
|
|
39461
39528
|
setDefaultOpenAIClient(client);
|
|
39462
39529
|
if (this.options.apiKey) {
|
|
39463
39530
|
setDefaultOpenAIKey(this.options.apiKey);
|
|
@@ -39478,9 +39545,9 @@ class LiteAgent {
|
|
|
39478
39545
|
agentKitModelName: resolvedModelName,
|
|
39479
39546
|
})
|
|
39480
39547
|
: null;
|
|
39481
|
-
const agentTools = (toolBuilder === null || toolBuilder === void 0 ? void 0 : toolBuilder.buildAgentKitTools({
|
|
39548
|
+
const agentTools = (await (toolBuilder === null || toolBuilder === void 0 ? void 0 : toolBuilder.buildAgentKitTools({
|
|
39482
39549
|
tools: modelRequirements.tools ? [...modelRequirements.tools] : undefined,
|
|
39483
|
-
})) || [];
|
|
39550
|
+
}))) || [];
|
|
39484
39551
|
const normalizedKnowledgeSources = await normalizeLiteAgentKnowledgeSources(modelRequirements.knowledgeSources || [], resolvedSource.sourceDirectoryPath);
|
|
39485
39552
|
if (normalizedKnowledgeSources.length > 0) {
|
|
39486
39553
|
const vectorStore = await runtime.createHostedKnowledgeVectorStore({
|
|
@@ -39490,7 +39557,7 @@ class LiteAgent {
|
|
|
39490
39557
|
agentTools.unshift(fileSearchTool(vectorStore.vectorStoreId));
|
|
39491
39558
|
}
|
|
39492
39559
|
return {
|
|
39493
|
-
agent: new
|
|
39560
|
+
agent: new AgentFromKit({
|
|
39494
39561
|
name: resolvedSource.agentName,
|
|
39495
39562
|
model: resolvedModelName,
|
|
39496
39563
|
instructions: modelRequirements.systemMessage || 'You are a helpful assistant.',
|
|
@@ -39699,6 +39766,15 @@ function resolveLiteAgentKnowledgeSourceMimeType(fileName) {
|
|
|
39699
39766
|
}
|
|
39700
39767
|
}
|
|
39701
39768
|
|
|
39769
|
+
/**
|
|
39770
|
+
* Loads the ZIP archive library (`jszip`) on demand
|
|
39771
|
+
*
|
|
39772
|
+
* Note: [🐌] Loaded lazily to keep the startup of the `ptbk` CLI utility fast
|
|
39773
|
+
*
|
|
39774
|
+
* @private internal utility of `loadArchive` and `saveArchive`
|
|
39775
|
+
*/
|
|
39776
|
+
const loadJsZipModule = createLazyModuleLoader(() => import('jszip'));
|
|
39777
|
+
|
|
39702
39778
|
/**
|
|
39703
39779
|
* Loads the books from the archive file with `.bookc` extension
|
|
39704
39780
|
*
|
|
@@ -39713,6 +39789,7 @@ async function loadArchive(filePath, fs) {
|
|
|
39713
39789
|
throw new UnexpectedError(`Archive file must have '.bookc' extension`);
|
|
39714
39790
|
}
|
|
39715
39791
|
const data = await fs.readFile(filePath);
|
|
39792
|
+
const { default: JSZip } = await loadJsZipModule();
|
|
39716
39793
|
const archive = await JSZip.loadAsync(data);
|
|
39717
39794
|
const indexFile = archive.file('index.book.json');
|
|
39718
39795
|
if (!indexFile) {
|
|
@@ -46085,8 +46162,9 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
46085
46162
|
vectorStoreId,
|
|
46086
46163
|
});
|
|
46087
46164
|
}
|
|
46088
|
-
const
|
|
46089
|
-
const
|
|
46165
|
+
const { Agent: AgentFromKit } = await loadOpenAiAgentsModule();
|
|
46166
|
+
const agentKitTools = await this.buildAgentKitTools({ tools, vectorStoreId });
|
|
46167
|
+
const openAiAgentKitAgent = new AgentFromKit({
|
|
46090
46168
|
name,
|
|
46091
46169
|
model: this.agentKitModelName,
|
|
46092
46170
|
instructions: instructions || 'You are a helpful assistant.',
|
|
@@ -46131,6 +46209,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
46131
46209
|
agentName: agentForRun.name,
|
|
46132
46210
|
input: inputItems,
|
|
46133
46211
|
};
|
|
46212
|
+
const { run } = await loadOpenAiAgentsModule();
|
|
46134
46213
|
const streamResult = await run(agentForRun, inputItems, {
|
|
46135
46214
|
stream: true,
|
|
46136
46215
|
maxTurns: 200,
|
|
@@ -46273,6 +46352,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
46273
46352
|
* Ensures the AgentKit SDK is wired to the OpenAI client and API key.
|
|
46274
46353
|
*/
|
|
46275
46354
|
async ensureAgentKitDefaults() {
|
|
46355
|
+
const { setDefaultOpenAIClient, setDefaultOpenAIKey } = await loadOpenAiAgentsModule();
|
|
46276
46356
|
const client = await this.getClient();
|
|
46277
46357
|
setDefaultOpenAIClient(client);
|
|
46278
46358
|
const apiKey = this.agentKitOptions.apiKey;
|