@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/umd/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('path'), require('fs/promises'), require('spacetrim'), require('colors'), require('child_process'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'path', 'fs/promises', 'spacetrim', 'colors', 'child_process', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-node"] = {}, global.path, global.promises, global._spaceTrim, global.colors, global.child_process, global.
|
|
5
|
-
})(this, (function (exports, path, promises, _spaceTrim, colors, child_process,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('path'), require('fs/promises'), require('spacetrim'), require('colors'), require('child_process'), require('url'), require('crypto-js'), require('crypto-js/enc-hex'), require('showdown'), require('waitasecond'), require('dotenv'), require('crypto-js/sha256'), require('rxjs'), require('crypto'), require('moment'), require('mime-types'), require('papaparse'), require('bottleneck')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'path', 'fs/promises', 'spacetrim', 'colors', 'child_process', 'url', 'crypto-js', 'crypto-js/enc-hex', 'showdown', 'waitasecond', 'dotenv', 'crypto-js/sha256', 'rxjs', 'crypto', 'moment', 'mime-types', 'papaparse', 'bottleneck'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-node"] = {}, global.path, global.promises, global._spaceTrim, global.colors, global.child_process, global.url, global.CryptoJS, global.hexEncoder, global.showdown, global.waitasecond, global.dotenv, global.sha256, global.rxjs, null, global.moment, global.mimeTypes, global.papaparse, global.Bottleneck));
|
|
5
|
+
})(this, (function (exports, path, promises, _spaceTrim, colors, child_process, url, CryptoJS, hexEncoder, showdown, waitasecond, dotenv, sha256, rxjs, crypto, moment, mimeTypes, papaparse, Bottleneck) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -29,13 +29,11 @@
|
|
|
29
29
|
var CryptoJS__default = /*#__PURE__*/_interopDefaultLegacy(CryptoJS);
|
|
30
30
|
var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
|
|
31
31
|
var showdown__default = /*#__PURE__*/_interopDefaultLegacy(showdown);
|
|
32
|
-
var JSZip__default = /*#__PURE__*/_interopDefaultLegacy(JSZip);
|
|
33
32
|
var dotenv__namespace = /*#__PURE__*/_interopNamespace(dotenv);
|
|
34
33
|
var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
|
|
35
34
|
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
36
35
|
var papaparse__default = /*#__PURE__*/_interopDefaultLegacy(papaparse);
|
|
37
36
|
var Bottleneck__default = /*#__PURE__*/_interopDefaultLegacy(Bottleneck);
|
|
38
|
-
var OpenAI__default = /*#__PURE__*/_interopDefaultLegacy(OpenAI);
|
|
39
37
|
|
|
40
38
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
41
39
|
/**
|
|
@@ -51,7 +49,7 @@
|
|
|
51
49
|
* @generated
|
|
52
50
|
* @see https://github.com/webgptorg/promptbook
|
|
53
51
|
*/
|
|
54
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.114.0-
|
|
52
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.114.0-3';
|
|
55
53
|
/**
|
|
56
54
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
57
55
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -2951,6 +2949,13 @@
|
|
|
2951
2949
|
* Environment variable read by the shell wrapper to tee live output into the temporary runtime log file.
|
|
2952
2950
|
*/
|
|
2953
2951
|
const PTBK_CODER_LOG_FILE_ENV_NAME = 'PTBK_CODER_LOG_FILE';
|
|
2952
|
+
/**
|
|
2953
|
+
* Log line which separates the raw script input from the raw script output of one execution section.
|
|
2954
|
+
*
|
|
2955
|
+
* Readers of a runtime log split on this marker to look only at what the harness really produced,
|
|
2956
|
+
* without the generated script and the prompt it embeds.
|
|
2957
|
+
*/
|
|
2958
|
+
const SCRIPT_EXECUTION_LOG_RAW_OUTPUT_MARKER = '--- raw output ---';
|
|
2954
2959
|
/**
|
|
2955
2960
|
* Small bash wrapper that preserves stdout/stderr streams while teeing both into the runtime log file.
|
|
2956
2961
|
*/
|
|
@@ -2986,7 +2991,7 @@
|
|
|
2986
2991
|
--- raw input ---
|
|
2987
2992
|
${block(normalizedInput)}
|
|
2988
2993
|
|
|
2989
|
-
|
|
2994
|
+
${SCRIPT_EXECUTION_LOG_RAW_OUTPUT_MARKER}
|
|
2990
2995
|
`);
|
|
2991
2996
|
await promises.appendFile(logPath, `${logSection}\n`, 'utf-8');
|
|
2992
2997
|
}
|
|
@@ -4329,6 +4334,7 @@
|
|
|
4329
4334
|
` -c model_reasoning_effort="${thinkingLevel}" \\`,
|
|
4330
4335
|
` --ask-for-approval ${options.askForApproval} \\`,
|
|
4331
4336
|
` exec --model ${options.model} \\`,
|
|
4337
|
+
...(options.isMachineReadableProgressEnabled ? [' --json \\'] : []),
|
|
4332
4338
|
' --local-provider none \\',
|
|
4333
4339
|
` --sandbox ${options.sandbox} \\`,
|
|
4334
4340
|
` -C ${projectPath} \\`,
|
|
@@ -4645,6 +4651,10 @@
|
|
|
4645
4651
|
* Output line that marks finished Codex usage summary.
|
|
4646
4652
|
*/
|
|
4647
4653
|
const CODEX_COMPLETION_LINE = /^\s*tokens used\b/i;
|
|
4654
|
+
/**
|
|
4655
|
+
* Output line that marks the completed Codex turn in JSONL output mode.
|
|
4656
|
+
*/
|
|
4657
|
+
const CODEX_JSON_COMPLETION_LINE = /^\s*\{"type":"turn\.(?:completed|failed)"/u;
|
|
4648
4658
|
/**
|
|
4649
4659
|
* Idle timeout after completion marker to capture trailing output.
|
|
4650
4660
|
*/
|
|
@@ -4721,6 +4731,7 @@
|
|
|
4721
4731
|
sandbox: this.options.sandbox,
|
|
4722
4732
|
askForApproval: this.options.askForApproval,
|
|
4723
4733
|
allowCredits: this.options.allowCredits,
|
|
4734
|
+
isMachineReadableProgressEnabled: this.options.isMachineReadableProgressEnabled,
|
|
4724
4735
|
codexCommand: this.options.codexCommand,
|
|
4725
4736
|
});
|
|
4726
4737
|
for (let retryIndex = 0;; retryIndex++) {
|
|
@@ -4735,7 +4746,9 @@
|
|
|
4735
4746
|
const output = await $runGoScriptUntilMarkerIdle({
|
|
4736
4747
|
scriptPath: options.scriptPath,
|
|
4737
4748
|
scriptContent,
|
|
4738
|
-
completionLineMatcher:
|
|
4749
|
+
completionLineMatcher: this.options.isMachineReadableProgressEnabled
|
|
4750
|
+
? CODEX_JSON_COMPLETION_LINE
|
|
4751
|
+
: CODEX_COMPLETION_LINE,
|
|
4739
4752
|
idleTimeoutMs: CODEX_COMPLETION_IDLE_MS,
|
|
4740
4753
|
logPath: options.logPath,
|
|
4741
4754
|
shouldPrintLiveOutput: options.shouldPrintLiveOutput,
|
|
@@ -4985,6 +4998,7 @@
|
|
|
4985
4998
|
sandbox: 'danger-full-access',
|
|
4986
4999
|
askForApproval: 'never',
|
|
4987
5000
|
allowCredits: options.allowCredits,
|
|
5001
|
+
isMachineReadableProgressEnabled: options.isMachineReadableProgressEnabled,
|
|
4988
5002
|
});
|
|
4989
5003
|
if (!options.allowCredits && options.isVerbose === true) {
|
|
4990
5004
|
console.info(colors__default["default"].gray('OpenAI Codex credit spending is disabled. Use `--allow-credits` to explicitly opt in.'));
|
|
@@ -32909,6 +32923,41 @@
|
|
|
32909
32923
|
`;
|
|
32910
32924
|
}
|
|
32911
32925
|
|
|
32926
|
+
/**
|
|
32927
|
+
* Creates a loader which imports one module on the first call and reuses the very same module afterwards
|
|
32928
|
+
*
|
|
32929
|
+
* Note: [🐌] Heavy third-party dependencies are imported lazily to keep the startup of the Promptbook CLI fast.
|
|
32930
|
+
* A statically imported dependency is loaded every single time the bundle is loaded, even when the running
|
|
32931
|
+
* command never touches it. A lazily imported dependency is loaded only when the feature is really used.
|
|
32932
|
+
*
|
|
32933
|
+
* @example
|
|
32934
|
+
* const loadJsdomModule = createLazyModuleLoader(() => import('jsdom'));
|
|
32935
|
+
* const { JSDOM } = await loadJsdomModule();
|
|
32936
|
+
*
|
|
32937
|
+
* @private internal utility of Promptbook
|
|
32938
|
+
*/
|
|
32939
|
+
function createLazyModuleLoader(importModule) {
|
|
32940
|
+
let importedModulePromise = null;
|
|
32941
|
+
return function loadModule() {
|
|
32942
|
+
if (importedModulePromise === null) {
|
|
32943
|
+
importedModulePromise = importModule();
|
|
32944
|
+
}
|
|
32945
|
+
return importedModulePromise;
|
|
32946
|
+
};
|
|
32947
|
+
}
|
|
32948
|
+
// Note: [🐌] Do not convert the lazy `import(...)` calls back to static `import` statements, it would bring back the
|
|
32949
|
+
// slow startup of the `ptbk` CLI utility
|
|
32950
|
+
|
|
32951
|
+
/**
|
|
32952
|
+
* Loads the OpenAI AgentKit SDK (`@openai/agents`) on demand
|
|
32953
|
+
*
|
|
32954
|
+
* Note: [🐌] The AgentKit SDK is one of the heaviest dependencies of Promptbook, loading it eagerly would slow down
|
|
32955
|
+
* every single run of the `ptbk` CLI utility even when no AgentKit agent is used
|
|
32956
|
+
*
|
|
32957
|
+
* @private internal utility of `@promptbook/openai`
|
|
32958
|
+
*/
|
|
32959
|
+
const loadOpenAiAgentsModule = createLazyModuleLoader(() => import('@openai/agents'));
|
|
32960
|
+
|
|
32912
32961
|
/**
|
|
32913
32962
|
* Constant for default model used for nested DeepSearch tool invocations.
|
|
32914
32963
|
*/
|
|
@@ -32962,11 +33011,12 @@
|
|
|
32962
33011
|
/**
|
|
32963
33012
|
* Builds the tool list for AgentKit, including hosted file search when applicable.
|
|
32964
33013
|
*/
|
|
32965
|
-
buildAgentKitTools(options) {
|
|
33014
|
+
async buildAgentKitTools(options) {
|
|
32966
33015
|
const { tools, vectorStoreId } = options;
|
|
33016
|
+
const { fileSearchTool, tool: agentKitTool } = await loadOpenAiAgentsModule();
|
|
32967
33017
|
const agentKitTools = [];
|
|
32968
33018
|
if (vectorStoreId) {
|
|
32969
|
-
agentKitTools.push(
|
|
33019
|
+
agentKitTools.push(fileSearchTool(vectorStoreId));
|
|
32970
33020
|
}
|
|
32971
33021
|
if (!tools || tools.length === 0) {
|
|
32972
33022
|
return agentKitTools;
|
|
@@ -32974,11 +33024,11 @@
|
|
|
32974
33024
|
let scriptTools = null;
|
|
32975
33025
|
for (const toolDefinition of tools) {
|
|
32976
33026
|
if (this.isDeepSearchToolDefinition(toolDefinition)) {
|
|
32977
|
-
agentKitTools.push(this.createDeepSearchAgentKitTool(toolDefinition));
|
|
33027
|
+
agentKitTools.push(await this.createDeepSearchAgentKitTool(toolDefinition));
|
|
32978
33028
|
continue;
|
|
32979
33029
|
}
|
|
32980
33030
|
scriptTools !== null && scriptTools !== void 0 ? scriptTools : (scriptTools = this.resolveScriptTools());
|
|
32981
|
-
agentKitTools.push(
|
|
33031
|
+
agentKitTools.push(agentKitTool({
|
|
32982
33032
|
name: toolDefinition.name,
|
|
32983
33033
|
description: toolDefinition.description,
|
|
32984
33034
|
parameters: this.normalizeAgentKitToolParameters(toolDefinition.parameters),
|
|
@@ -33185,12 +33235,13 @@
|
|
|
33185
33235
|
/**
|
|
33186
33236
|
* Creates the native Agent SDK tool used for `USE DEEPSEARCH`.
|
|
33187
33237
|
*/
|
|
33188
|
-
createDeepSearchAgentKitTool(toolDefinition) {
|
|
33189
|
-
const
|
|
33238
|
+
async createDeepSearchAgentKitTool(toolDefinition) {
|
|
33239
|
+
const { Agent: AgentFromKit, webSearchTool } = await loadOpenAiAgentsModule();
|
|
33240
|
+
const deepSearchAgent = new AgentFromKit({
|
|
33190
33241
|
name: 'DeepSearch',
|
|
33191
33242
|
model: DEFAULT_DEEP_SEARCH_MODEL_NAME,
|
|
33192
33243
|
instructions: this.createDeepSearchAgentInstructions(toolDefinition.description),
|
|
33193
|
-
tools: [
|
|
33244
|
+
tools: [webSearchTool({ searchContextSize: 'high' })],
|
|
33194
33245
|
});
|
|
33195
33246
|
return deepSearchAgent.asTool({
|
|
33196
33247
|
toolName: toolDefinition.name,
|
|
@@ -33754,6 +33805,14 @@
|
|
|
33754
33805
|
}
|
|
33755
33806
|
}
|
|
33756
33807
|
|
|
33808
|
+
/**
|
|
33809
|
+
* Loads the OpenAI SDK (`openai`) on demand
|
|
33810
|
+
*
|
|
33811
|
+
* Note: [🐌] Loaded lazily to keep the startup of the `ptbk` CLI utility fast
|
|
33812
|
+
*
|
|
33813
|
+
* @private internal utility of `OpenAiCompatibleRequestManager`
|
|
33814
|
+
*/
|
|
33815
|
+
const loadOpenAiModule = createLazyModuleLoader(() => import('openai'));
|
|
33757
33816
|
/**
|
|
33758
33817
|
* Manages OpenAI-compatible client creation plus shared retry and rate-limit behavior.
|
|
33759
33818
|
*
|
|
@@ -33780,7 +33839,8 @@
|
|
|
33780
33839
|
timeout: API_REQUEST_TIMEOUT,
|
|
33781
33840
|
maxRetries: CONNECTION_RETRIES_LIMIT,
|
|
33782
33841
|
};
|
|
33783
|
-
|
|
33842
|
+
const { default: OpenAI } = await loadOpenAiModule();
|
|
33843
|
+
this.client = new OpenAI(enhancedOptions);
|
|
33784
33844
|
}
|
|
33785
33845
|
return this.client;
|
|
33786
33846
|
}
|
|
@@ -36126,7 +36186,23 @@
|
|
|
36126
36186
|
});
|
|
36127
36187
|
}
|
|
36128
36188
|
|
|
36129
|
-
|
|
36189
|
+
/**
|
|
36190
|
+
* Loads `jsdom` on demand
|
|
36191
|
+
*
|
|
36192
|
+
* Note: [🐌] `jsdom` is by far the heaviest dependency of Promptbook, loading it eagerly would slow down every single
|
|
36193
|
+
* run of the `ptbk` CLI utility even when no website is scraped
|
|
36194
|
+
*
|
|
36195
|
+
* @private internal utility of `WebsiteScraper`
|
|
36196
|
+
*/
|
|
36197
|
+
const loadJsdomModule = createLazyModuleLoader(() => import('jsdom'));
|
|
36198
|
+
/**
|
|
36199
|
+
* Loads `@mozilla/readability` on demand
|
|
36200
|
+
*
|
|
36201
|
+
* Note: [🐌] Loaded lazily to keep the startup of the `ptbk` CLI utility fast
|
|
36202
|
+
*
|
|
36203
|
+
* @private internal utility of `WebsiteScraper`
|
|
36204
|
+
*/
|
|
36205
|
+
const loadReadabilityModule = createLazyModuleLoader(() => import('@mozilla/readability'));
|
|
36130
36206
|
/**
|
|
36131
36207
|
* Scraper for websites
|
|
36132
36208
|
*
|
|
@@ -36162,14 +36238,15 @@
|
|
|
36162
36238
|
if (this.tools.fs === undefined) {
|
|
36163
36239
|
throw new EnvironmentMismatchError('Can not scrape websites without filesystem tools');
|
|
36164
36240
|
}
|
|
36165
|
-
const
|
|
36241
|
+
const [{ JSDOM }, { Readability }] = await Promise.all([loadJsdomModule(), loadReadabilityModule()]);
|
|
36242
|
+
const jsdom = new JSDOM(await source.asText(), {
|
|
36166
36243
|
url: source.url,
|
|
36167
36244
|
});
|
|
36168
|
-
const reader = new
|
|
36245
|
+
const reader = new Readability(jsdom.window.document);
|
|
36169
36246
|
const article = reader.parse();
|
|
36170
36247
|
// console.log(article);
|
|
36171
36248
|
// await forTime(10000);
|
|
36172
|
-
let html = (article === null || article === void 0 ? void 0 : article.content) || (article === null || article === void 0 ? void 0 : article.textContent) || jsdom
|
|
36249
|
+
let html = (article === null || article === void 0 ? void 0 : article.content) || (article === null || article === void 0 ? void 0 : article.textContent) || jsdom.window.document.body.innerHTML;
|
|
36173
36250
|
// Note: Unwrap html such as it is convertable by `markdownConverter`
|
|
36174
36251
|
for (let i = 0; i < 2; i++) {
|
|
36175
36252
|
html = html.replace(/<div\s*(?:id="readability-page-\d+"\s+class="page")?>(.*)<\/div>/is, '$1');
|
|
@@ -36202,7 +36279,7 @@
|
|
|
36202
36279
|
throw error;
|
|
36203
36280
|
}
|
|
36204
36281
|
}
|
|
36205
|
-
const markdown = this.showdownConverter.makeMarkdown(html, jsdom
|
|
36282
|
+
const markdown = this.showdownConverter.makeMarkdown(html, jsdom.window.document);
|
|
36206
36283
|
return { ...cacheFilehandler, markdown };
|
|
36207
36284
|
}
|
|
36208
36285
|
/**
|
|
@@ -39425,7 +39502,8 @@
|
|
|
39425
39502
|
}
|
|
39426
39503
|
const preparedAgent = await this.prepareAgent();
|
|
39427
39504
|
(_a = preparedAgent.toolBuilder) === null || _a === void 0 ? void 0 : _a.clearRunState();
|
|
39428
|
-
const
|
|
39505
|
+
const { run } = await loadOpenAiAgentsModule();
|
|
39506
|
+
const result = await run(preparedAgent.agent, createLiteAgentPromptText(normalizedMessage, options.context, preparedAgent.modelRequirements.promptSuffix), options.signal ? { signal: options.signal } : undefined);
|
|
39429
39507
|
return formatLiteAgentOutput(result.finalOutput);
|
|
39430
39508
|
}
|
|
39431
39509
|
/**
|
|
@@ -39464,9 +39542,10 @@
|
|
|
39464
39542
|
userId: this.options.userId,
|
|
39465
39543
|
});
|
|
39466
39544
|
const client = await runtime.getClient();
|
|
39467
|
-
|
|
39545
|
+
const { Agent: AgentFromKit, fileSearchTool, setDefaultOpenAIClient, setDefaultOpenAIKey, } = await loadOpenAiAgentsModule();
|
|
39546
|
+
setDefaultOpenAIClient(client);
|
|
39468
39547
|
if (this.options.apiKey) {
|
|
39469
|
-
|
|
39548
|
+
setDefaultOpenAIKey(this.options.apiKey);
|
|
39470
39549
|
}
|
|
39471
39550
|
const toolBuilder = modelRequirements.tools && modelRequirements.tools.length > 0
|
|
39472
39551
|
? new OpenAiAgentKitExecutionToolsToolBuilder({
|
|
@@ -39484,19 +39563,19 @@
|
|
|
39484
39563
|
agentKitModelName: resolvedModelName,
|
|
39485
39564
|
})
|
|
39486
39565
|
: null;
|
|
39487
|
-
const agentTools = (toolBuilder === null || toolBuilder === void 0 ? void 0 : toolBuilder.buildAgentKitTools({
|
|
39566
|
+
const agentTools = (await (toolBuilder === null || toolBuilder === void 0 ? void 0 : toolBuilder.buildAgentKitTools({
|
|
39488
39567
|
tools: modelRequirements.tools ? [...modelRequirements.tools] : undefined,
|
|
39489
|
-
})) || [];
|
|
39568
|
+
}))) || [];
|
|
39490
39569
|
const normalizedKnowledgeSources = await normalizeLiteAgentKnowledgeSources(modelRequirements.knowledgeSources || [], resolvedSource.sourceDirectoryPath);
|
|
39491
39570
|
if (normalizedKnowledgeSources.length > 0) {
|
|
39492
39571
|
const vectorStore = await runtime.createHostedKnowledgeVectorStore({
|
|
39493
39572
|
knowledgeSources: normalizedKnowledgeSources,
|
|
39494
39573
|
name: resolvedSource.agentName,
|
|
39495
39574
|
});
|
|
39496
|
-
agentTools.unshift(
|
|
39575
|
+
agentTools.unshift(fileSearchTool(vectorStore.vectorStoreId));
|
|
39497
39576
|
}
|
|
39498
39577
|
return {
|
|
39499
|
-
agent: new
|
|
39578
|
+
agent: new AgentFromKit({
|
|
39500
39579
|
name: resolvedSource.agentName,
|
|
39501
39580
|
model: resolvedModelName,
|
|
39502
39581
|
instructions: modelRequirements.systemMessage || 'You are a helpful assistant.',
|
|
@@ -39705,6 +39784,15 @@
|
|
|
39705
39784
|
}
|
|
39706
39785
|
}
|
|
39707
39786
|
|
|
39787
|
+
/**
|
|
39788
|
+
* Loads the ZIP archive library (`jszip`) on demand
|
|
39789
|
+
*
|
|
39790
|
+
* Note: [🐌] Loaded lazily to keep the startup of the `ptbk` CLI utility fast
|
|
39791
|
+
*
|
|
39792
|
+
* @private internal utility of `loadArchive` and `saveArchive`
|
|
39793
|
+
*/
|
|
39794
|
+
const loadJsZipModule = createLazyModuleLoader(() => import('jszip'));
|
|
39795
|
+
|
|
39708
39796
|
/**
|
|
39709
39797
|
* Loads the books from the archive file with `.bookc` extension
|
|
39710
39798
|
*
|
|
@@ -39719,7 +39807,8 @@
|
|
|
39719
39807
|
throw new UnexpectedError(`Archive file must have '.bookc' extension`);
|
|
39720
39808
|
}
|
|
39721
39809
|
const data = await fs.readFile(filePath);
|
|
39722
|
-
const
|
|
39810
|
+
const { default: JSZip } = await loadJsZipModule();
|
|
39811
|
+
const archive = await JSZip.loadAsync(data);
|
|
39723
39812
|
const indexFile = archive.file('index.book.json');
|
|
39724
39813
|
if (!indexFile) {
|
|
39725
39814
|
throw new UnexpectedError(`Archive does not contain 'index.book.json' file`);
|
|
@@ -46091,8 +46180,9 @@
|
|
|
46091
46180
|
vectorStoreId,
|
|
46092
46181
|
});
|
|
46093
46182
|
}
|
|
46094
|
-
const
|
|
46095
|
-
const
|
|
46183
|
+
const { Agent: AgentFromKit } = await loadOpenAiAgentsModule();
|
|
46184
|
+
const agentKitTools = await this.buildAgentKitTools({ tools, vectorStoreId });
|
|
46185
|
+
const openAiAgentKitAgent = new AgentFromKit({
|
|
46096
46186
|
name,
|
|
46097
46187
|
model: this.agentKitModelName,
|
|
46098
46188
|
instructions: instructions || 'You are a helpful assistant.',
|
|
@@ -46137,7 +46227,8 @@
|
|
|
46137
46227
|
agentName: agentForRun.name,
|
|
46138
46228
|
input: inputItems,
|
|
46139
46229
|
};
|
|
46140
|
-
const
|
|
46230
|
+
const { run } = await loadOpenAiAgentsModule();
|
|
46231
|
+
const streamResult = await run(agentForRun, inputItems, {
|
|
46141
46232
|
stream: true,
|
|
46142
46233
|
maxTurns: 200,
|
|
46143
46234
|
context: {
|
|
@@ -46279,11 +46370,12 @@
|
|
|
46279
46370
|
* Ensures the AgentKit SDK is wired to the OpenAI client and API key.
|
|
46280
46371
|
*/
|
|
46281
46372
|
async ensureAgentKitDefaults() {
|
|
46373
|
+
const { setDefaultOpenAIClient, setDefaultOpenAIKey } = await loadOpenAiAgentsModule();
|
|
46282
46374
|
const client = await this.getClient();
|
|
46283
|
-
|
|
46375
|
+
setDefaultOpenAIClient(client);
|
|
46284
46376
|
const apiKey = this.agentKitOptions.apiKey;
|
|
46285
46377
|
if (apiKey && typeof apiKey === 'string') {
|
|
46286
|
-
|
|
46378
|
+
setDefaultOpenAIKey(apiKey);
|
|
46287
46379
|
}
|
|
46288
46380
|
}
|
|
46289
46381
|
/**
|