@promptbook/node 0.114.0-1 → 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/README.md +16 -15
- package/esm/index.es.js +108 -19
- 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-2.0/book-language-documentation/BookLanguageManualDictionary.d.ts +1 -15
- package/esm/src/book-2.0/book-language-documentation/getBookLanguageManualCommitmentGroups.d.ts +1 -1
- package/esm/src/book-2.0/book-language-documentation/renderCommitmentCatalogSection.d.ts +0 -4
- package/esm/src/book-components/Chat/utils/$provideServerDomWindow.d.ts +11 -0
- package/esm/src/book-components/Chat/utils/renderMarkdown.d.ts +7 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerRuntimeEnvironment.d.ts +7 -0
- package/esm/src/cli/cli-commands/coder/agentCodingFile.d.ts +2 -3
- package/esm/src/cli/cli-commands/coder/ping.d.ts +10 -0
- package/esm/src/cli/cli-commands/coder/ping.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/coder.d.ts +1 -0
- 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 +127 -35
- 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-2.0/book-language-documentation/BookLanguageManualDictionary.d.ts +1 -15
- package/umd/src/book-2.0/book-language-documentation/getBookLanguageManualCommitmentGroups.d.ts +1 -1
- package/umd/src/book-2.0/book-language-documentation/renderCommitmentCatalogSection.d.ts +0 -4
- package/umd/src/book-components/Chat/utils/$provideServerDomWindow.d.ts +11 -0
- package/umd/src/book-components/Chat/utils/renderMarkdown.d.ts +7 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer/createAgentsServerRuntimeEnvironment.d.ts +7 -0
- package/umd/src/cli/cli-commands/coder/agentCodingFile.d.ts +2 -3
- package/umd/src/cli/cli-commands/coder/ping.d.ts +10 -0
- package/umd/src/cli/cli-commands/coder/ping.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/coder.d.ts +1 -0
- 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/README.md
CHANGED
|
@@ -562,26 +562,27 @@ ptbk coder verify
|
|
|
562
562
|
| ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --- | ------ | ---- | ----- | ------------------------------------------------------------------------ |
|
|
563
563
|
| `ptbk coder init` | Creates `prompts/`, `prompts/done/`, the project-generic template files materialized in `prompts/templates/` (currently `common.md`), and a starter `AGENTS.md`; ensures `.env` contains `CODING_AGENT_GIT_NAME`, `CODING_AGENT_GIT_EMAIL`, and `CODING_AGENT_GIT_SIGNING_KEY`; adds helper coder scripts to `package.json`; ensures `.gitignore` contains `/.promptbook`; and configures `.vscode/settings.json` to save pasted prompt images into `prompts/screenshots/`. |
|
|
564
564
|
| `ptbk coder generate-boilerplates` | Creates new prompt markdown files with fresh emoji tags so you can quickly fill in coding tasks; `--template` accepts either a built-in alias or a markdown file path relative to the project root. |
|
|
565
|
-
| `ptbk coder run` | Picks the next ready prompt, appends optional context, runs it through the selected coding agent, can optionally verify each attempt with a shell test command and feed failing output back for retries, then marks success or failure, commits the result, and pushes only when `--auto-push` is enabled.
|
|
565
|
+
| `ptbk coder run` | Picks the next ready prompt, can run tests before coding to stop or repair pre-existing failures, appends optional context, runs it through the selected coding agent, can optionally verify each attempt with a shell test command and feed failing output back for retries, then marks success or failure, commits the result, and pushes only when `--auto-push` is enabled. |
|
|
566
566
|
| `ptbk coder find-refactor-candidates` | Scans the repository for oversized or overpacked files and writes prompt files for likely refactors; `--level <xlow | low | medium | high | xhigh | extreme>` ranges from a very benevolent scan to a very aggressive sweep. |
|
|
567
567
|
| `ptbk coder verify` | Walks through completed prompts, archives truly finished work, and adds follow-up repair prompts for unfinished results. |
|
|
568
568
|
|
|
569
569
|
#### Most useful `ptbk coder run` flags
|
|
570
570
|
|
|
571
|
-
| Flag | Purpose
|
|
572
|
-
| -------------------------- |
|
|
573
|
-
| `--harness <name>` | Selects the coding harness.
|
|
574
|
-
| `--model <model>` | Chooses the runner model; required for `openai-codex` and `gemini`, optional for `github-copilot`.
|
|
575
|
-
| `--context <text-or-file>` | Appends extra instructions inline or from a file like `AGENTS.md`.
|
|
576
|
-
| `--test <command>` | Runs a verification command after each prompt attempt and feeds failing output back for retries.
|
|
577
|
-
| `--
|
|
578
|
-
| `--
|
|
579
|
-
| `--
|
|
580
|
-
| `--
|
|
581
|
-
| `--
|
|
582
|
-
| `--
|
|
583
|
-
| `--
|
|
584
|
-
| `--auto-
|
|
571
|
+
| Flag | Purpose |
|
|
572
|
+
| -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
573
|
+
| `--harness <name>` | Selects the coding harness. |
|
|
574
|
+
| `--model <model>` | Chooses the runner model; required for `openai-codex` and `gemini`, optional for `github-copilot`. |
|
|
575
|
+
| `--context <text-or-file>` | Appends extra instructions inline or from a file like `AGENTS.md`. |
|
|
576
|
+
| `--test <command>` | Runs a verification command after each prompt attempt and feeds failing output back for retries. |
|
|
577
|
+
| `--test-before <mode>` | Runs tests before coding: `no` (default), `yes-and-fail` (stop with results), or `yes-and-fix` (create one repair prompt first); defaults to `npm test` when enabled without `--test`. |
|
|
578
|
+
| `--thinking-level <level>` | Sets reasoning effort for supported runners. |
|
|
579
|
+
| `--no-auto` | Waits for user confirmation before each prompt instead of running automatically through the queue. |
|
|
580
|
+
| `--ignore-git-changes` | Disables the clean-working-tree guard. |
|
|
581
|
+
| `--priority <n>` | Runs only prompts at or above the given priority. |
|
|
582
|
+
| `--dry-run` | Prints which prompts are ready instead of executing them. |
|
|
583
|
+
| `--allow-credits` | Lets OpenAI Codex spend credits when required. |
|
|
584
|
+
| `--auto-push` | Pushes each successful coding-agent commit to the configured remote. |
|
|
585
|
+
| `--auto-migrate` | Runs testing-server database migrations after each successful prompt. |
|
|
585
586
|
|
|
586
587
|
#### Typical usage pattern
|
|
587
588
|
|
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
|
}
|
|
@@ -4314,6 +4316,7 @@ function buildCodexScript(options) {
|
|
|
4314
4316
|
` -c model_reasoning_effort="${thinkingLevel}" \\`,
|
|
4315
4317
|
` --ask-for-approval ${options.askForApproval} \\`,
|
|
4316
4318
|
` exec --model ${options.model} \\`,
|
|
4319
|
+
...(options.isMachineReadableProgressEnabled ? [' --json \\'] : []),
|
|
4317
4320
|
' --local-provider none \\',
|
|
4318
4321
|
` --sandbox ${options.sandbox} \\`,
|
|
4319
4322
|
` -C ${projectPath} \\`,
|
|
@@ -4630,6 +4633,10 @@ function matchesAnyPattern(text, patterns) {
|
|
|
4630
4633
|
* Output line that marks finished Codex usage summary.
|
|
4631
4634
|
*/
|
|
4632
4635
|
const CODEX_COMPLETION_LINE = /^\s*tokens used\b/i;
|
|
4636
|
+
/**
|
|
4637
|
+
* Output line that marks the completed Codex turn in JSONL output mode.
|
|
4638
|
+
*/
|
|
4639
|
+
const CODEX_JSON_COMPLETION_LINE = /^\s*\{"type":"turn\.(?:completed|failed)"/u;
|
|
4633
4640
|
/**
|
|
4634
4641
|
* Idle timeout after completion marker to capture trailing output.
|
|
4635
4642
|
*/
|
|
@@ -4706,6 +4713,7 @@ class OpenAiCodexRunner {
|
|
|
4706
4713
|
sandbox: this.options.sandbox,
|
|
4707
4714
|
askForApproval: this.options.askForApproval,
|
|
4708
4715
|
allowCredits: this.options.allowCredits,
|
|
4716
|
+
isMachineReadableProgressEnabled: this.options.isMachineReadableProgressEnabled,
|
|
4709
4717
|
codexCommand: this.options.codexCommand,
|
|
4710
4718
|
});
|
|
4711
4719
|
for (let retryIndex = 0;; retryIndex++) {
|
|
@@ -4720,7 +4728,9 @@ class OpenAiCodexRunner {
|
|
|
4720
4728
|
const output = await $runGoScriptUntilMarkerIdle({
|
|
4721
4729
|
scriptPath: options.scriptPath,
|
|
4722
4730
|
scriptContent,
|
|
4723
|
-
completionLineMatcher:
|
|
4731
|
+
completionLineMatcher: this.options.isMachineReadableProgressEnabled
|
|
4732
|
+
? CODEX_JSON_COMPLETION_LINE
|
|
4733
|
+
: CODEX_COMPLETION_LINE,
|
|
4724
4734
|
idleTimeoutMs: CODEX_COMPLETION_IDLE_MS,
|
|
4725
4735
|
logPath: options.logPath,
|
|
4726
4736
|
shouldPrintLiveOutput: options.shouldPrintLiveOutput,
|
|
@@ -4970,6 +4980,7 @@ function createOpenAiCodexRunnerResolution(options) {
|
|
|
4970
4980
|
sandbox: 'danger-full-access',
|
|
4971
4981
|
askForApproval: 'never',
|
|
4972
4982
|
allowCredits: options.allowCredits,
|
|
4983
|
+
isMachineReadableProgressEnabled: options.isMachineReadableProgressEnabled,
|
|
4973
4984
|
});
|
|
4974
4985
|
if (!options.allowCredits && options.isVerbose === true) {
|
|
4975
4986
|
console.info(colors.gray('OpenAI Codex credit spending is disabled. Use `--allow-credits` to explicitly opt in.'));
|
|
@@ -32894,6 +32905,41 @@ function buildToolInvocationScript(options) {
|
|
|
32894
32905
|
`;
|
|
32895
32906
|
}
|
|
32896
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
|
+
|
|
32897
32943
|
/**
|
|
32898
32944
|
* Constant for default model used for nested DeepSearch tool invocations.
|
|
32899
32945
|
*/
|
|
@@ -32947,8 +32993,9 @@ class OpenAiAgentKitExecutionToolsToolBuilder {
|
|
|
32947
32993
|
/**
|
|
32948
32994
|
* Builds the tool list for AgentKit, including hosted file search when applicable.
|
|
32949
32995
|
*/
|
|
32950
|
-
buildAgentKitTools(options) {
|
|
32996
|
+
async buildAgentKitTools(options) {
|
|
32951
32997
|
const { tools, vectorStoreId } = options;
|
|
32998
|
+
const { fileSearchTool, tool: agentKitTool } = await loadOpenAiAgentsModule();
|
|
32952
32999
|
const agentKitTools = [];
|
|
32953
33000
|
if (vectorStoreId) {
|
|
32954
33001
|
agentKitTools.push(fileSearchTool(vectorStoreId));
|
|
@@ -32959,11 +33006,11 @@ class OpenAiAgentKitExecutionToolsToolBuilder {
|
|
|
32959
33006
|
let scriptTools = null;
|
|
32960
33007
|
for (const toolDefinition of tools) {
|
|
32961
33008
|
if (this.isDeepSearchToolDefinition(toolDefinition)) {
|
|
32962
|
-
agentKitTools.push(this.createDeepSearchAgentKitTool(toolDefinition));
|
|
33009
|
+
agentKitTools.push(await this.createDeepSearchAgentKitTool(toolDefinition));
|
|
32963
33010
|
continue;
|
|
32964
33011
|
}
|
|
32965
33012
|
scriptTools !== null && scriptTools !== void 0 ? scriptTools : (scriptTools = this.resolveScriptTools());
|
|
32966
|
-
agentKitTools.push(
|
|
33013
|
+
agentKitTools.push(agentKitTool({
|
|
32967
33014
|
name: toolDefinition.name,
|
|
32968
33015
|
description: toolDefinition.description,
|
|
32969
33016
|
parameters: this.normalizeAgentKitToolParameters(toolDefinition.parameters),
|
|
@@ -33170,8 +33217,9 @@ class OpenAiAgentKitExecutionToolsToolBuilder {
|
|
|
33170
33217
|
/**
|
|
33171
33218
|
* Creates the native Agent SDK tool used for `USE DEEPSEARCH`.
|
|
33172
33219
|
*/
|
|
33173
|
-
createDeepSearchAgentKitTool(toolDefinition) {
|
|
33174
|
-
const
|
|
33220
|
+
async createDeepSearchAgentKitTool(toolDefinition) {
|
|
33221
|
+
const { Agent: AgentFromKit, webSearchTool } = await loadOpenAiAgentsModule();
|
|
33222
|
+
const deepSearchAgent = new AgentFromKit({
|
|
33175
33223
|
name: 'DeepSearch',
|
|
33176
33224
|
model: DEFAULT_DEEP_SEARCH_MODEL_NAME,
|
|
33177
33225
|
instructions: this.createDeepSearchAgentInstructions(toolDefinition.description),
|
|
@@ -33739,6 +33787,14 @@ class OpenAiCompatibleNonChatPromptCaller {
|
|
|
33739
33787
|
}
|
|
33740
33788
|
}
|
|
33741
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'));
|
|
33742
33798
|
/**
|
|
33743
33799
|
* Manages OpenAI-compatible client creation plus shared retry and rate-limit behavior.
|
|
33744
33800
|
*
|
|
@@ -33765,6 +33821,7 @@ class OpenAiCompatibleRequestManager {
|
|
|
33765
33821
|
timeout: API_REQUEST_TIMEOUT,
|
|
33766
33822
|
maxRetries: CONNECTION_RETRIES_LIMIT,
|
|
33767
33823
|
};
|
|
33824
|
+
const { default: OpenAI } = await loadOpenAiModule();
|
|
33768
33825
|
this.client = new OpenAI(enhancedOptions);
|
|
33769
33826
|
}
|
|
33770
33827
|
return this.client;
|
|
@@ -36111,7 +36168,23 @@ function createShowdownConverter() {
|
|
|
36111
36168
|
});
|
|
36112
36169
|
}
|
|
36113
36170
|
|
|
36114
|
-
|
|
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'));
|
|
36115
36188
|
/**
|
|
36116
36189
|
* Scraper for websites
|
|
36117
36190
|
*
|
|
@@ -36147,6 +36220,7 @@ class WebsiteScraper {
|
|
|
36147
36220
|
if (this.tools.fs === undefined) {
|
|
36148
36221
|
throw new EnvironmentMismatchError('Can not scrape websites without filesystem tools');
|
|
36149
36222
|
}
|
|
36223
|
+
const [{ JSDOM }, { Readability }] = await Promise.all([loadJsdomModule(), loadReadabilityModule()]);
|
|
36150
36224
|
const jsdom = new JSDOM(await source.asText(), {
|
|
36151
36225
|
url: source.url,
|
|
36152
36226
|
});
|
|
@@ -39410,6 +39484,7 @@ class LiteAgent {
|
|
|
39410
39484
|
}
|
|
39411
39485
|
const preparedAgent = await this.prepareAgent();
|
|
39412
39486
|
(_a = preparedAgent.toolBuilder) === null || _a === void 0 ? void 0 : _a.clearRunState();
|
|
39487
|
+
const { run } = await loadOpenAiAgentsModule();
|
|
39413
39488
|
const result = await run(preparedAgent.agent, createLiteAgentPromptText(normalizedMessage, options.context, preparedAgent.modelRequirements.promptSuffix), options.signal ? { signal: options.signal } : undefined);
|
|
39414
39489
|
return formatLiteAgentOutput(result.finalOutput);
|
|
39415
39490
|
}
|
|
@@ -39449,6 +39524,7 @@ class LiteAgent {
|
|
|
39449
39524
|
userId: this.options.userId,
|
|
39450
39525
|
});
|
|
39451
39526
|
const client = await runtime.getClient();
|
|
39527
|
+
const { Agent: AgentFromKit, fileSearchTool, setDefaultOpenAIClient, setDefaultOpenAIKey, } = await loadOpenAiAgentsModule();
|
|
39452
39528
|
setDefaultOpenAIClient(client);
|
|
39453
39529
|
if (this.options.apiKey) {
|
|
39454
39530
|
setDefaultOpenAIKey(this.options.apiKey);
|
|
@@ -39469,9 +39545,9 @@ class LiteAgent {
|
|
|
39469
39545
|
agentKitModelName: resolvedModelName,
|
|
39470
39546
|
})
|
|
39471
39547
|
: null;
|
|
39472
|
-
const agentTools = (toolBuilder === null || toolBuilder === void 0 ? void 0 : toolBuilder.buildAgentKitTools({
|
|
39548
|
+
const agentTools = (await (toolBuilder === null || toolBuilder === void 0 ? void 0 : toolBuilder.buildAgentKitTools({
|
|
39473
39549
|
tools: modelRequirements.tools ? [...modelRequirements.tools] : undefined,
|
|
39474
|
-
})) || [];
|
|
39550
|
+
}))) || [];
|
|
39475
39551
|
const normalizedKnowledgeSources = await normalizeLiteAgentKnowledgeSources(modelRequirements.knowledgeSources || [], resolvedSource.sourceDirectoryPath);
|
|
39476
39552
|
if (normalizedKnowledgeSources.length > 0) {
|
|
39477
39553
|
const vectorStore = await runtime.createHostedKnowledgeVectorStore({
|
|
@@ -39481,7 +39557,7 @@ class LiteAgent {
|
|
|
39481
39557
|
agentTools.unshift(fileSearchTool(vectorStore.vectorStoreId));
|
|
39482
39558
|
}
|
|
39483
39559
|
return {
|
|
39484
|
-
agent: new
|
|
39560
|
+
agent: new AgentFromKit({
|
|
39485
39561
|
name: resolvedSource.agentName,
|
|
39486
39562
|
model: resolvedModelName,
|
|
39487
39563
|
instructions: modelRequirements.systemMessage || 'You are a helpful assistant.',
|
|
@@ -39690,6 +39766,15 @@ function resolveLiteAgentKnowledgeSourceMimeType(fileName) {
|
|
|
39690
39766
|
}
|
|
39691
39767
|
}
|
|
39692
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
|
+
|
|
39693
39778
|
/**
|
|
39694
39779
|
* Loads the books from the archive file with `.bookc` extension
|
|
39695
39780
|
*
|
|
@@ -39704,6 +39789,7 @@ async function loadArchive(filePath, fs) {
|
|
|
39704
39789
|
throw new UnexpectedError(`Archive file must have '.bookc' extension`);
|
|
39705
39790
|
}
|
|
39706
39791
|
const data = await fs.readFile(filePath);
|
|
39792
|
+
const { default: JSZip } = await loadJsZipModule();
|
|
39707
39793
|
const archive = await JSZip.loadAsync(data);
|
|
39708
39794
|
const indexFile = archive.file('index.book.json');
|
|
39709
39795
|
if (!indexFile) {
|
|
@@ -46076,8 +46162,9 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
46076
46162
|
vectorStoreId,
|
|
46077
46163
|
});
|
|
46078
46164
|
}
|
|
46079
|
-
const
|
|
46080
|
-
const
|
|
46165
|
+
const { Agent: AgentFromKit } = await loadOpenAiAgentsModule();
|
|
46166
|
+
const agentKitTools = await this.buildAgentKitTools({ tools, vectorStoreId });
|
|
46167
|
+
const openAiAgentKitAgent = new AgentFromKit({
|
|
46081
46168
|
name,
|
|
46082
46169
|
model: this.agentKitModelName,
|
|
46083
46170
|
instructions: instructions || 'You are a helpful assistant.',
|
|
@@ -46122,6 +46209,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
46122
46209
|
agentName: agentForRun.name,
|
|
46123
46210
|
input: inputItems,
|
|
46124
46211
|
};
|
|
46212
|
+
const { run } = await loadOpenAiAgentsModule();
|
|
46125
46213
|
const streamResult = await run(agentForRun, inputItems, {
|
|
46126
46214
|
stream: true,
|
|
46127
46215
|
maxTurns: 200,
|
|
@@ -46264,6 +46352,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
|
|
|
46264
46352
|
* Ensures the AgentKit SDK is wired to the OpenAI client and API key.
|
|
46265
46353
|
*/
|
|
46266
46354
|
async ensureAgentKitDefaults() {
|
|
46355
|
+
const { setDefaultOpenAIClient, setDefaultOpenAIKey } = await loadOpenAiAgentsModule();
|
|
46267
46356
|
const client = await this.getClient();
|
|
46268
46357
|
setDefaultOpenAIClient(client);
|
|
46269
46358
|
const apiKey = this.agentKitOptions.apiKey;
|