@promptbook/cli 0.112.0-112 → 0.112.0-114
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 +7 -7
- package/apps/agents-server/README.md +1 -1
- package/apps/agents-server/next.config.ts +20 -1
- package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/stream/route.ts +85 -56
- package/apps/agents-server/src/app/agents/[agentName]/chat/useAgentChatHistorySyncEffects.ts +7 -13
- package/apps/agents-server/src/app/api/admin/code-runners/route.ts +1 -1
- package/apps/agents-server/src/app/api/internal/user-chat-jobs/run/route.ts +1 -1
- package/apps/agents-server/src/database/migrations/2026-06-1300-user-chat-active-read-indexes.sql +7 -0
- package/apps/agents-server/src/instrumentation-client.ts +28 -0
- package/apps/agents-server/src/instrumentation.ts +16 -0
- package/apps/agents-server/src/sentry.edge.config.ts +18 -0
- package/apps/agents-server/src/sentry.server.config.ts +19 -0
- package/apps/agents-server/src/utils/agentRouting/resolveAgentRouteTarget.ts +38 -0
- package/apps/agents-server/src/utils/codeRunnerConfiguration.ts +1 -1
- package/apps/agents-server/src/utils/errorReporting/agentsServerSentryContext.ts +203 -0
- package/apps/agents-server/src/utils/errorReporting/registerServerErrorSentryLogging.ts +59 -9
- package/apps/agents-server/src/utils/errorReporting/sendApplicationErrorReportToSentry.ts +39 -3
- package/apps/agents-server/src/utils/errorReporting/sentrySdkConfig.ts +237 -0
- package/apps/agents-server/src/utils/errorReporting/sentryStore.ts +10 -0
- package/apps/agents-server/src/utils/externalChatRunner/createExternalAgentRepositoryFiles.ts +2 -2
- package/apps/agents-server/src/utils/userChat/createImmediateUserChatAnswerModelRequirements.ts +15 -12
- package/apps/agents-server/src/utils/userChat/createUserChatDetailPayload.ts +33 -18
- package/apps/agents-server/src/utils/userChat/hasPotentiallyPendingAssistantMessages.ts +26 -0
- package/apps/agents-server/src/utils/userChat/runImmediateUserChatAnswer.ts +1 -1
- package/apps/agents-server/src/utils/userChat/triggerUserChatJobWorker.ts +54 -19
- package/apps/agents-server/src/utils/vpsConfiguration.ts +1 -1
- package/esm/index.es.js +9285 -8807
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/run-agent-chat/executeAgentChatTurn.d.ts +28 -0
- package/esm/scripts/run-agent-chat/runAgentChat.d.ts +5 -0
- package/esm/scripts/run-agent-chat/runAgentExec.d.ts +11 -0
- package/esm/scripts/run-agent-messages/messages/createAgentRunnerSystemMessage.d.ts +10 -0
- package/esm/scripts/run-codex-prompts/common/resolveInlineOrFileText.d.ts +14 -0
- package/esm/scripts/run-codex-prompts/common/runGoScript/printLiveScriptChunk.d.ts +4 -0
- package/esm/src/_packages/node.index.d.ts +20 -0
- package/esm/src/_packages/types.index.d.ts +16 -0
- package/esm/src/book-3.0/BookNodeAgentSource.d.ts +38 -0
- package/esm/src/book-3.0/CliAgent.d.ts +68 -0
- package/esm/src/book-3.0/LiteAgent.d.ts +68 -0
- package/esm/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.d.ts +12 -0
- package/esm/src/cli/cli-commands/agent/agentCliOptions.d.ts +38 -0
- package/esm/src/cli/cli-commands/agent/chat.d.ts +10 -0
- package/esm/src/cli/cli-commands/agent/exec.d.ts +10 -0
- package/esm/src/cli/cli-commands/agent/run.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/agent.d.ts +14 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +3 -4
- package/esm/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +9 -9
- package/esm/src/version.d.ts +1 -1
- package/package.json +2 -1
- package/src/_packages/node.index.ts +20 -0
- package/src/_packages/types.index.ts +16 -0
- package/src/book-3.0/BookNodeAgentSource.ts +135 -0
- package/src/book-3.0/CliAgent.ts +236 -0
- package/src/book-3.0/LiteAgent.ts +468 -0
- package/src/book-components/BookEditor/BookEditor.module.css +61 -0
- package/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.tsx +74 -0
- package/src/book-components/BookEditor/BookEditorActionbar.tsx +3 -3
- package/src/cli/cli-commands/agent/agentCliOptions.ts +92 -0
- package/src/cli/cli-commands/agent/chat.ts +54 -0
- package/src/cli/cli-commands/agent/exec.ts +60 -0
- package/src/cli/cli-commands/agent.ts +44 -0
- package/src/cli/cli-commands/agents-server/startAgentsServer.ts +3 -19
- package/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.ts +1 -1
- package/src/cli/cli-commands/common/promptRunnerCliOptions.ts +27 -23
- package/src/cli/promptbookCli.ts +2 -0
- package/src/other/templates/getTemplatesPipelineCollection.ts +747 -771
- package/src/version.ts +2 -2
- package/src/versions.txt +2 -0
- package/umd/index.umd.js +9285 -8807
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/run-agent-chat/executeAgentChatTurn.d.ts +28 -0
- package/umd/scripts/run-agent-chat/runAgentChat.d.ts +5 -0
- package/umd/scripts/run-agent-chat/runAgentExec.d.ts +11 -0
- package/umd/scripts/run-agent-messages/messages/createAgentRunnerSystemMessage.d.ts +10 -0
- package/umd/scripts/run-codex-prompts/common/resolveInlineOrFileText.d.ts +14 -0
- package/umd/scripts/run-codex-prompts/common/runGoScript/printLiveScriptChunk.d.ts +4 -0
- package/umd/src/_packages/node.index.d.ts +20 -0
- package/umd/src/_packages/types.index.d.ts +16 -0
- package/umd/src/book-3.0/BookNodeAgentSource.d.ts +38 -0
- package/umd/src/book-3.0/CliAgent.d.ts +68 -0
- package/umd/src/book-3.0/CliAgent.test.d.ts +1 -0
- package/umd/src/book-3.0/LiteAgent.d.ts +68 -0
- package/umd/src/book-3.0/LiteAgent.test.d.ts +1 -0
- package/umd/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.d.ts +12 -0
- package/umd/src/cli/cli-commands/agent/agentCliOptions.d.ts +38 -0
- package/umd/src/cli/cli-commands/agent/chat.d.ts +10 -0
- package/umd/src/cli/cli-commands/agent/exec.d.ts +10 -0
- package/umd/src/cli/cli-commands/agent/run.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/agent.d.ts +14 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +3 -4
- package/umd/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +9 -9
- package/umd/src/version.d.ts +1 -1
- /package/esm/src/{cli/cli-commands/agents-server/startAgentsServer.test.d.ts → book-3.0/CliAgent.test.d.ts} +0 -0
- /package/{umd/src/cli/cli-commands/agents-server/startAgentsServer.test.d.ts → esm/src/book-3.0/LiteAgent.test.d.ts} +0 -0
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Agent as AgentFromKit,
|
|
3
|
+
fileSearchTool,
|
|
4
|
+
run,
|
|
5
|
+
setDefaultOpenAIClient,
|
|
6
|
+
setDefaultOpenAIKey,
|
|
7
|
+
} from '@openai/agents';
|
|
8
|
+
import { readFile } from 'fs/promises';
|
|
9
|
+
import { basename, resolve } from 'path';
|
|
10
|
+
import { fileURLToPath } from 'url';
|
|
11
|
+
import type { CreateAgentModelRequirementsOptions } from '../book-2.0/agent-source/CreateAgentModelRequirementsOptions';
|
|
12
|
+
import { createAgentModelRequirements } from '../book-2.0/agent-source/createAgentModelRequirements';
|
|
13
|
+
import type { AgentModelRequirements } from '../book-2.0/agent-source/AgentModelRequirements';
|
|
14
|
+
import { NotAllowed } from '../errors/NotAllowed';
|
|
15
|
+
import type { ScriptExecutionTools } from '../execution/ScriptExecutionTools';
|
|
16
|
+
import { OpenAiAgentKitExecutionToolsToolBuilder } from '../llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder';
|
|
17
|
+
import { OpenAiVectorStoreHandler } from '../llm-providers/openai/OpenAiVectorStoreHandler';
|
|
18
|
+
import { OPENAI_MODELS } from '../llm-providers/openai/openai-models';
|
|
19
|
+
import { computeOpenAiUsage } from '../llm-providers/openai/computeOpenAiUsage';
|
|
20
|
+
import { $provideScriptingForNode } from '../scrapers/_common/register/$provideScriptingForNode';
|
|
21
|
+
import type { string_knowledge_source_link } from '../types/string_knowledge_source_content';
|
|
22
|
+
import type { string_markdown, string_markdown_text } from '../types/string_markdown';
|
|
23
|
+
import type { string_model_name } from '../types/string_model_name';
|
|
24
|
+
import type { string_title } from '../types/string_title';
|
|
25
|
+
import type { TODO_any } from '../utils/organization/TODO_any';
|
|
26
|
+
import { spaceTrim } from '../utils/organization/spaceTrim';
|
|
27
|
+
import type { BookNodeAgentSourceOptions } from './BookNodeAgentSource';
|
|
28
|
+
import { resolveBookNodeAgentSource } from './BookNodeAgentSource';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Default OpenAI model used by `LiteAgent` when the Book does not request one explicitly.
|
|
32
|
+
*
|
|
33
|
+
* @private internal constant of `LiteAgent`
|
|
34
|
+
*/
|
|
35
|
+
const DEFAULT_LITE_AGENT_MODEL_NAME = 'gpt-5.4-mini' as string_model_name;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Options for constructing one `LiteAgent`.
|
|
39
|
+
*
|
|
40
|
+
* `LiteAgent` is intentionally smaller than the CLI harnesses. It runs the Book through the
|
|
41
|
+
* OpenAI Agents SDK directly, while keeping Promptbook tool definitions and hosted knowledge
|
|
42
|
+
* whenever those features fit inside the lighter runtime.
|
|
43
|
+
*
|
|
44
|
+
* @public exported from `@promptbook/node`
|
|
45
|
+
*/
|
|
46
|
+
export type LiteAgentOptions = BookNodeAgentSourceOptions & {
|
|
47
|
+
readonly apiKey?: string;
|
|
48
|
+
readonly baseURL?: string;
|
|
49
|
+
readonly createAgentModelRequirementsOptions?: CreateAgentModelRequirementsOptions;
|
|
50
|
+
readonly isVerbose?: boolean;
|
|
51
|
+
readonly maxRequestsPerMinute?: number;
|
|
52
|
+
readonly modelName?: string_model_name;
|
|
53
|
+
readonly organization?: string;
|
|
54
|
+
readonly project?: string;
|
|
55
|
+
readonly scriptExecutionTools?: ScriptExecutionTools | ReadonlyArray<ScriptExecutionTools>;
|
|
56
|
+
readonly userId?: string;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Per-run options for `LiteAgent`.
|
|
61
|
+
*
|
|
62
|
+
* @public exported from `@promptbook/node`
|
|
63
|
+
*/
|
|
64
|
+
export type LiteAgentRunOptions = {
|
|
65
|
+
readonly context?: string;
|
|
66
|
+
readonly signal?: AbortSignal;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Prepared OpenAI SDK runtime cached on one `LiteAgent` instance.
|
|
71
|
+
*
|
|
72
|
+
* @private internal utility of `LiteAgent`
|
|
73
|
+
*/
|
|
74
|
+
type PreparedLiteAgent = {
|
|
75
|
+
readonly agent: AgentFromKit;
|
|
76
|
+
readonly modelRequirements: AgentModelRequirements;
|
|
77
|
+
readonly toolBuilder: OpenAiAgentKitExecutionToolsToolBuilder | null;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Lightweight Node.js wrapper around the OpenAI Agents SDK for Promptbook Books.
|
|
82
|
+
*
|
|
83
|
+
* This path is intentionally simpler than `ptbk agent exec`: it prepares one SDK agent in-process
|
|
84
|
+
* and reuses it across calls, which keeps JavaScript integration small while still honoring the
|
|
85
|
+
* compiled Promptbook system message, prompt suffix, tools, and hosted knowledge when supported.
|
|
86
|
+
*
|
|
87
|
+
* @public exported from `@promptbook/node`
|
|
88
|
+
*/
|
|
89
|
+
export class LiteAgent {
|
|
90
|
+
private preparedAgentPromise: Promise<PreparedLiteAgent> | null = null;
|
|
91
|
+
|
|
92
|
+
public constructor(private readonly options: LiteAgentOptions) {}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Runs one user message through the prepared OpenAI Agents SDK agent.
|
|
96
|
+
*
|
|
97
|
+
* @param message - User message sent to the agent.
|
|
98
|
+
* @param options - Optional context and cancellation signal.
|
|
99
|
+
* @returns Final text returned by the SDK agent.
|
|
100
|
+
*/
|
|
101
|
+
public async run(message: string, options: LiteAgentRunOptions = {}): Promise<string> {
|
|
102
|
+
const normalizedMessage = message.trim();
|
|
103
|
+
|
|
104
|
+
if (!normalizedMessage) {
|
|
105
|
+
throw new NotAllowed(
|
|
106
|
+
spaceTrim(`
|
|
107
|
+
Pass a non-empty message to \`LiteAgent.run(...)\`.
|
|
108
|
+
`),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const preparedAgent = await this.prepareAgent();
|
|
113
|
+
preparedAgent.toolBuilder?.clearRunState();
|
|
114
|
+
|
|
115
|
+
const result = await run(
|
|
116
|
+
preparedAgent.agent,
|
|
117
|
+
createLiteAgentPromptText(normalizedMessage, options.context, preparedAgent.modelRequirements.promptSuffix),
|
|
118
|
+
options.signal ? { signal: options.signal } : undefined,
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
return formatLiteAgentOutput(result.finalOutput);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Lazily prepares and caches the underlying OpenAI Agents SDK runtime.
|
|
126
|
+
*
|
|
127
|
+
* @private internal utility of `LiteAgent`
|
|
128
|
+
*/
|
|
129
|
+
private async prepareAgent(): Promise<PreparedLiteAgent> {
|
|
130
|
+
if (!this.preparedAgentPromise) {
|
|
131
|
+
this.preparedAgentPromise = this.createPreparedAgent().catch((error) => {
|
|
132
|
+
this.preparedAgentPromise = null;
|
|
133
|
+
throw error;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return this.preparedAgentPromise;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Builds the in-process OpenAI Agents SDK runtime from the Book source.
|
|
142
|
+
*
|
|
143
|
+
* @private internal utility of `LiteAgent`
|
|
144
|
+
*/
|
|
145
|
+
private async createPreparedAgent(): Promise<PreparedLiteAgent> {
|
|
146
|
+
const resolvedSource = await resolveBookNodeAgentSource(this.options);
|
|
147
|
+
const modelRequirements = await createAgentModelRequirements(
|
|
148
|
+
resolvedSource.agentSource,
|
|
149
|
+
this.options.modelName,
|
|
150
|
+
undefined,
|
|
151
|
+
undefined,
|
|
152
|
+
this.options.createAgentModelRequirementsOptions,
|
|
153
|
+
);
|
|
154
|
+
const resolvedModelName = resolveLiteAgentModelName(modelRequirements, this.options.modelName);
|
|
155
|
+
const scriptExecutionTools = await resolveLiteAgentScriptExecutionTools(this.options, modelRequirements);
|
|
156
|
+
const runtime = new LiteAgentOpenAiRuntime({
|
|
157
|
+
apiKey: this.options.apiKey,
|
|
158
|
+
baseURL: this.options.baseURL,
|
|
159
|
+
executionTools: scriptExecutionTools ? { script: scriptExecutionTools } : undefined,
|
|
160
|
+
isProxied: false,
|
|
161
|
+
isVerbose: this.options.isVerbose,
|
|
162
|
+
maxRequestsPerMinute: this.options.maxRequestsPerMinute,
|
|
163
|
+
organization: this.options.organization,
|
|
164
|
+
project: this.options.project,
|
|
165
|
+
userId: this.options.userId,
|
|
166
|
+
});
|
|
167
|
+
const client = await runtime.getClient();
|
|
168
|
+
|
|
169
|
+
setDefaultOpenAIClient(client as TODO_any);
|
|
170
|
+
|
|
171
|
+
if (this.options.apiKey) {
|
|
172
|
+
setDefaultOpenAIKey(this.options.apiKey);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const toolBuilder =
|
|
176
|
+
modelRequirements.tools && modelRequirements.tools.length > 0
|
|
177
|
+
? new OpenAiAgentKitExecutionToolsToolBuilder({
|
|
178
|
+
options: {
|
|
179
|
+
apiKey: this.options.apiKey,
|
|
180
|
+
baseURL: this.options.baseURL,
|
|
181
|
+
executionTools: scriptExecutionTools ? { script: scriptExecutionTools } : undefined,
|
|
182
|
+
isProxied: false,
|
|
183
|
+
isVerbose: this.options.isVerbose,
|
|
184
|
+
maxRequestsPerMinute: this.options.maxRequestsPerMinute,
|
|
185
|
+
organization: this.options.organization,
|
|
186
|
+
project: this.options.project,
|
|
187
|
+
userId: this.options.userId,
|
|
188
|
+
},
|
|
189
|
+
agentKitModelName: resolvedModelName,
|
|
190
|
+
})
|
|
191
|
+
: null;
|
|
192
|
+
const agentTools =
|
|
193
|
+
toolBuilder?.buildAgentKitTools({
|
|
194
|
+
tools: modelRequirements.tools ? [...modelRequirements.tools] : undefined,
|
|
195
|
+
}) || [];
|
|
196
|
+
const normalizedKnowledgeSources = await normalizeLiteAgentKnowledgeSources(
|
|
197
|
+
modelRequirements.knowledgeSources || [],
|
|
198
|
+
resolvedSource.sourceDirectoryPath,
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
if (normalizedKnowledgeSources.length > 0) {
|
|
202
|
+
const vectorStore = await runtime.createHostedKnowledgeVectorStore({
|
|
203
|
+
knowledgeSources: normalizedKnowledgeSources,
|
|
204
|
+
name: resolvedSource.agentName,
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
agentTools.unshift(fileSearchTool(vectorStore.vectorStoreId));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
agent: new AgentFromKit({
|
|
212
|
+
name: resolvedSource.agentName,
|
|
213
|
+
model: resolvedModelName,
|
|
214
|
+
instructions: modelRequirements.systemMessage || 'You are a helpful assistant.',
|
|
215
|
+
modelSettings: createLiteAgentModelSettings(modelRequirements) as TODO_any,
|
|
216
|
+
tools: agentTools,
|
|
217
|
+
}),
|
|
218
|
+
modelRequirements,
|
|
219
|
+
toolBuilder,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Minimal concrete OpenAI runtime used by `LiteAgent` for client and vector-store management.
|
|
226
|
+
*
|
|
227
|
+
* @private helper of `LiteAgent`
|
|
228
|
+
*/
|
|
229
|
+
class LiteAgentOpenAiRuntime extends OpenAiVectorStoreHandler {
|
|
230
|
+
public get title(): string_title & string_markdown_text {
|
|
231
|
+
return 'OpenAI LiteAgent';
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
public get description(): string_markdown {
|
|
235
|
+
return 'Internal OpenAI runtime used by Promptbook LiteAgent';
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Exposes hosted vector-store preparation needed by `LiteAgent`.
|
|
240
|
+
*/
|
|
241
|
+
public async createHostedKnowledgeVectorStore(options: {
|
|
242
|
+
readonly knowledgeSources: ReadonlyArray<string_knowledge_source_link>;
|
|
243
|
+
readonly name: string;
|
|
244
|
+
}): Promise<{ readonly vectorStoreId: string }> {
|
|
245
|
+
const result = await this.createVectorStoreWithKnowledgeSources({
|
|
246
|
+
client: await this.getClient(),
|
|
247
|
+
knowledgeSources: options.knowledgeSources,
|
|
248
|
+
logLabel: 'lite-agent',
|
|
249
|
+
name: options.name as string_title,
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
return {
|
|
253
|
+
vectorStoreId: result.vectorStoreId,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
protected get HARDCODED_MODELS() {
|
|
258
|
+
return OPENAI_MODELS;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
protected computeUsage = computeOpenAiUsage;
|
|
262
|
+
|
|
263
|
+
protected getDefaultChatModel() {
|
|
264
|
+
return this.getDefaultModel('gpt-5');
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
protected getDefaultCompletionModel() {
|
|
268
|
+
return this.getDefaultModel('gpt-3.5-turbo-instruct');
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
protected getDefaultEmbeddingModel() {
|
|
272
|
+
return this.getDefaultModel('text-embedding-3-large');
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
protected getDefaultImageGenerationModel() {
|
|
276
|
+
return this.getDefaultModel('dall-e-3');
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Resolves the model name used by the OpenAI Agents SDK runtime.
|
|
282
|
+
*
|
|
283
|
+
* @private internal utility of `LiteAgent`
|
|
284
|
+
*/
|
|
285
|
+
function resolveLiteAgentModelName(
|
|
286
|
+
modelRequirements: AgentModelRequirements,
|
|
287
|
+
explicitModelName: string_model_name | undefined,
|
|
288
|
+
): string_model_name {
|
|
289
|
+
return explicitModelName || (modelRequirements.modelName as string_model_name) || DEFAULT_LITE_AGENT_MODEL_NAME;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Resolves the script execution tools needed for Promptbook function tools.
|
|
294
|
+
*
|
|
295
|
+
* @private internal utility of `LiteAgent`
|
|
296
|
+
*/
|
|
297
|
+
async function resolveLiteAgentScriptExecutionTools(
|
|
298
|
+
options: LiteAgentOptions,
|
|
299
|
+
modelRequirements: AgentModelRequirements,
|
|
300
|
+
): Promise<ReadonlyArray<ScriptExecutionTools> | undefined> {
|
|
301
|
+
if (!modelRequirements.tools || modelRequirements.tools.length === 0) {
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (options.scriptExecutionTools) {
|
|
306
|
+
return Array.isArray(options.scriptExecutionTools)
|
|
307
|
+
? options.scriptExecutionTools
|
|
308
|
+
: [options.scriptExecutionTools];
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return $provideScriptingForNode({
|
|
312
|
+
isVerbose: options.isVerbose,
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Creates the final user prompt text passed into the OpenAI Agents SDK.
|
|
318
|
+
*
|
|
319
|
+
* @private internal utility of `LiteAgent`
|
|
320
|
+
*/
|
|
321
|
+
function createLiteAgentPromptText(message: string, context: string | undefined, promptSuffix: string): string {
|
|
322
|
+
const normalizedContext = context?.trim();
|
|
323
|
+
const normalizedPromptSuffix = promptSuffix.trim();
|
|
324
|
+
|
|
325
|
+
return spaceTrim(
|
|
326
|
+
(block) => `
|
|
327
|
+
${block(message)}
|
|
328
|
+
${block(
|
|
329
|
+
normalizedContext
|
|
330
|
+
? `
|
|
331
|
+
## Additional context
|
|
332
|
+
|
|
333
|
+
${normalizedContext}
|
|
334
|
+
`
|
|
335
|
+
: '',
|
|
336
|
+
)}
|
|
337
|
+
${block(normalizedPromptSuffix)}
|
|
338
|
+
`,
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Normalizes the final output returned by the OpenAI Agents SDK.
|
|
344
|
+
*
|
|
345
|
+
* @private internal utility of `LiteAgent`
|
|
346
|
+
*/
|
|
347
|
+
function formatLiteAgentOutput(output: unknown): string {
|
|
348
|
+
if (output === undefined || output === null || output === '') {
|
|
349
|
+
return '(OpenAI Agents SDK returned no text response.)';
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (typeof output === 'string') {
|
|
353
|
+
return output;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
try {
|
|
357
|
+
return JSON.stringify(output, null, 2);
|
|
358
|
+
} catch {
|
|
359
|
+
return String(output);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Creates SDK model settings from compiled Book requirements.
|
|
365
|
+
*
|
|
366
|
+
* `topK` is intentionally omitted because the OpenAI Agents SDK model settings do not expose it.
|
|
367
|
+
*
|
|
368
|
+
* @private internal utility of `LiteAgent`
|
|
369
|
+
*/
|
|
370
|
+
function createLiteAgentModelSettings(modelRequirements: AgentModelRequirements): Record<string, number> | undefined {
|
|
371
|
+
const modelSettingsEntries = Object.entries({
|
|
372
|
+
temperature: modelRequirements.temperature,
|
|
373
|
+
topP: modelRequirements.topP,
|
|
374
|
+
}).filter(([, value]) => typeof value === 'number') as Array<[string, number]>;
|
|
375
|
+
|
|
376
|
+
if (modelSettingsEntries.length === 0) {
|
|
377
|
+
return undefined;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return Object.fromEntries(modelSettingsEntries);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Converts local knowledge-source paths into data URLs so the shared vector-store upload pipeline can ingest them.
|
|
385
|
+
*
|
|
386
|
+
* @private internal utility of `LiteAgent`
|
|
387
|
+
*/
|
|
388
|
+
async function normalizeLiteAgentKnowledgeSources(
|
|
389
|
+
knowledgeSources: ReadonlyArray<string_knowledge_source_link>,
|
|
390
|
+
sourceDirectoryPath: string,
|
|
391
|
+
): Promise<ReadonlyArray<string_knowledge_source_link>> {
|
|
392
|
+
const normalizedKnowledgeSources: Array<string_knowledge_source_link> = [];
|
|
393
|
+
|
|
394
|
+
for (const knowledgeSource of knowledgeSources) {
|
|
395
|
+
if (isHttpKnowledgeSource(knowledgeSource) || knowledgeSource.startsWith('data:')) {
|
|
396
|
+
normalizedKnowledgeSources.push(knowledgeSource);
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
normalizedKnowledgeSources.push(
|
|
401
|
+
await convertLiteAgentLocalKnowledgeSourceToDataUrl(knowledgeSource, sourceDirectoryPath),
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
return normalizedKnowledgeSources;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Detects HTTP(S) knowledge sources that can already be handled by the shared uploader.
|
|
410
|
+
*
|
|
411
|
+
* @private internal utility of `LiteAgent`
|
|
412
|
+
*/
|
|
413
|
+
function isHttpKnowledgeSource(knowledgeSource: string): boolean {
|
|
414
|
+
return knowledgeSource.startsWith('http://') || knowledgeSource.startsWith('https://');
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Converts one local file knowledge source into a base64 data URL.
|
|
419
|
+
*
|
|
420
|
+
* @private internal utility of `LiteAgent`
|
|
421
|
+
*/
|
|
422
|
+
async function convertLiteAgentLocalKnowledgeSourceToDataUrl(
|
|
423
|
+
knowledgeSource: string,
|
|
424
|
+
sourceDirectoryPath: string,
|
|
425
|
+
): Promise<string_knowledge_source_link> {
|
|
426
|
+
const absolutePath = knowledgeSource.startsWith('file:')
|
|
427
|
+
? fileURLToPath(knowledgeSource)
|
|
428
|
+
: resolve(sourceDirectoryPath, knowledgeSource);
|
|
429
|
+
const fileContent = await readFile(absolutePath);
|
|
430
|
+
const fileName = basename(absolutePath);
|
|
431
|
+
const mimeType = resolveLiteAgentKnowledgeSourceMimeType(fileName);
|
|
432
|
+
|
|
433
|
+
return `data:${mimeType};name=${encodeURIComponent(fileName)};base64,${fileContent.toString(
|
|
434
|
+
'base64',
|
|
435
|
+
)}` as string_knowledge_source_link;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Resolves one MIME type for local knowledge-source uploads.
|
|
440
|
+
*
|
|
441
|
+
* @private internal utility of `LiteAgent`
|
|
442
|
+
*/
|
|
443
|
+
function resolveLiteAgentKnowledgeSourceMimeType(fileName: string): string {
|
|
444
|
+
const extension = fileName.includes('.') ? (fileName.split('.').pop() || '').toLowerCase() : '';
|
|
445
|
+
|
|
446
|
+
switch (extension) {
|
|
447
|
+
case 'csv':
|
|
448
|
+
return 'text/csv';
|
|
449
|
+
case 'html':
|
|
450
|
+
case 'htm':
|
|
451
|
+
return 'text/html';
|
|
452
|
+
case 'json':
|
|
453
|
+
return 'application/json';
|
|
454
|
+
case 'markdown':
|
|
455
|
+
case 'md':
|
|
456
|
+
return 'text/markdown';
|
|
457
|
+
case 'pdf':
|
|
458
|
+
return 'application/pdf';
|
|
459
|
+
case 'xml':
|
|
460
|
+
return 'application/xml';
|
|
461
|
+
case 'yaml':
|
|
462
|
+
case 'yml':
|
|
463
|
+
return 'text/yaml';
|
|
464
|
+
case 'txt':
|
|
465
|
+
default:
|
|
466
|
+
return 'text/plain';
|
|
467
|
+
}
|
|
468
|
+
}
|
|
@@ -348,6 +348,67 @@
|
|
|
348
348
|
color: #b91c1c;
|
|
349
349
|
}
|
|
350
350
|
|
|
351
|
+
.aboutPromptbookInformation {
|
|
352
|
+
max-width: 680px;
|
|
353
|
+
color: #111827;
|
|
354
|
+
font-family: var(--font-poppins, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
|
|
355
|
+
font-size: 0.95rem;
|
|
356
|
+
line-height: 1.6;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
.aboutPromptbookInformation > :first-child {
|
|
360
|
+
margin-top: 0;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
.aboutPromptbookInformation > :last-child {
|
|
364
|
+
margin-bottom: 0;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
.aboutPromptbookInformation h1,
|
|
368
|
+
.aboutPromptbookInformation h2 {
|
|
369
|
+
color: #0f172a;
|
|
370
|
+
font-weight: 650;
|
|
371
|
+
line-height: 1.25;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
.aboutPromptbookInformation h1 {
|
|
375
|
+
margin: 0 0 0.75rem;
|
|
376
|
+
font-size: 1.5rem;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
.aboutPromptbookInformation h2 {
|
|
380
|
+
margin: 1.35rem 0 0.55rem;
|
|
381
|
+
font-size: 1.15rem;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
.aboutPromptbookInformation p {
|
|
385
|
+
margin: 0 0 0.9rem;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
.aboutPromptbookInformation ul,
|
|
389
|
+
.aboutPromptbookInformation ol {
|
|
390
|
+
display: grid;
|
|
391
|
+
gap: 0.35rem;
|
|
392
|
+
margin: 0.55rem 0 1rem;
|
|
393
|
+
padding-left: 1.35rem;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
.aboutPromptbookInformation a {
|
|
397
|
+
color: #2563eb;
|
|
398
|
+
text-decoration: underline;
|
|
399
|
+
text-underline-offset: 0.16em;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
.aboutPromptbookInformation code {
|
|
403
|
+
padding: 0.12em 0.34em;
|
|
404
|
+
border: 1px solid rgba(15, 23, 42, 0.12);
|
|
405
|
+
border-radius: 6px;
|
|
406
|
+
background: rgba(15, 23, 42, 0.06);
|
|
407
|
+
color: #111827;
|
|
408
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
|
|
409
|
+
font-size: 0.9em;
|
|
410
|
+
}
|
|
411
|
+
|
|
351
412
|
@keyframes fadeOut {
|
|
352
413
|
0% {
|
|
353
414
|
opacity: 0;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { PUBLIC_AGENTS_SERVERS } from '../../../servers';
|
|
2
|
+
import { CLAIM, IS_COST_PREVENTED, NAME } from '../../config';
|
|
3
|
+
import { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION } from '../../version';
|
|
4
|
+
import { $detectRuntimeEnvironment } from '../../utils/environment/$detectRuntimeEnvironment';
|
|
5
|
+
import type { AboutPromptbookInformationOptions } from '../../utils/misc/aboutPromptbookInformation';
|
|
6
|
+
import { valueToString } from '../../utils/parameters/valueToString';
|
|
7
|
+
import styles from './BookEditor.module.css';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Browser-safe Promptbook information used by `BookEditor`.
|
|
11
|
+
*
|
|
12
|
+
* The shared `AboutPromptbookInformation` component renders markdown through the
|
|
13
|
+
* chat markdown pipeline, which has a server-side JSDOM sanitizer path. Keeping
|
|
14
|
+
* this component plain JSX prevents BookEditor from pulling JSDOM into client
|
|
15
|
+
* bundles.
|
|
16
|
+
*
|
|
17
|
+
* @private Internal component used by `BookEditorActionbar`
|
|
18
|
+
*/
|
|
19
|
+
export function BookEditorAboutPromptbookInformation(props: AboutPromptbookInformationOptions = {}) {
|
|
20
|
+
const { isServersInfoIncluded = true, isRuntimeEnvironmentInfoIncluded = true } = props;
|
|
21
|
+
const runtimeEnvironmentInfo = {
|
|
22
|
+
...$detectRuntimeEnvironment(),
|
|
23
|
+
isCostPrevented: IS_COST_PREVENTED,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<div className={styles.aboutPromptbookInformation}>
|
|
28
|
+
<h1>{NAME}</h1>
|
|
29
|
+
<p>{CLAIM}</p>
|
|
30
|
+
|
|
31
|
+
<ul>
|
|
32
|
+
<li>
|
|
33
|
+
<a href="https://github.com/webgptorg/promptbook" target="_blank" rel="noopener noreferrer">
|
|
34
|
+
Promptbook engine version <code>{PROMPTBOOK_ENGINE_VERSION}</code>
|
|
35
|
+
</a>
|
|
36
|
+
</li>
|
|
37
|
+
<li>
|
|
38
|
+
<a href="https://github.com/webgptorg/book" target="_blank" rel="noopener noreferrer">
|
|
39
|
+
Book language version <code>{BOOK_LANGUAGE_VERSION}</code>
|
|
40
|
+
</a>
|
|
41
|
+
</li>
|
|
42
|
+
</ul>
|
|
43
|
+
|
|
44
|
+
{isServersInfoIncluded && (
|
|
45
|
+
<>
|
|
46
|
+
<h2>Servers</h2>
|
|
47
|
+
<ol>
|
|
48
|
+
{PUBLIC_AGENTS_SERVERS.map(({ title, description, url }) => (
|
|
49
|
+
<li key={url}>
|
|
50
|
+
<strong>{title}</strong> {description}{' '}
|
|
51
|
+
<a href={url} target="_blank" rel="noopener noreferrer">
|
|
52
|
+
{url}
|
|
53
|
+
</a>
|
|
54
|
+
</li>
|
|
55
|
+
))}
|
|
56
|
+
</ol>
|
|
57
|
+
</>
|
|
58
|
+
)}
|
|
59
|
+
|
|
60
|
+
{isRuntimeEnvironmentInfoIncluded && (
|
|
61
|
+
<>
|
|
62
|
+
<h2>Environment</h2>
|
|
63
|
+
<ul>
|
|
64
|
+
{Object.entries(runtimeEnvironmentInfo).map(([key, value]) => (
|
|
65
|
+
<li key={key}>
|
|
66
|
+
<strong>{key}:</strong> {valueToString(value)}
|
|
67
|
+
</li>
|
|
68
|
+
))}
|
|
69
|
+
</ul>
|
|
70
|
+
</>
|
|
71
|
+
)}
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
@@ -7,7 +7,6 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
|
7
7
|
// TODO: [🧠] Is there a better way to get the version?
|
|
8
8
|
import { DEFAULT_BOOK, validateBook } from '../../book-2.0/agent-source/string_book';
|
|
9
9
|
import { $induceBookDownload } from '../../utils/files/$induceBookDownload';
|
|
10
|
-
import { AboutPromptbookInformation } from '../../utils/misc/xAboutPromptbookInformation';
|
|
11
10
|
import { AboutIcon } from '../icons/AboutIcon';
|
|
12
11
|
import { AttachmentIcon } from '../icons/AttachmentIcon';
|
|
13
12
|
import { CameraIcon } from '../icons/CameraIcon';
|
|
@@ -18,6 +17,7 @@ import { Dropdown } from '../_common/Dropdown/Dropdown';
|
|
|
18
17
|
import type { HoistedMenuItem } from '../_common/MenuHoisting/MenuHoistingContext';
|
|
19
18
|
import { useMenuHoisting } from '../_common/MenuHoisting/MenuHoistingContext';
|
|
20
19
|
import { Modal } from '../_common/Modal/Modal';
|
|
20
|
+
import { BookEditorAboutPromptbookInformation } from './BookEditorAboutPromptbookInformation';
|
|
21
21
|
import styles from './BookEditor.module.css';
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -157,7 +157,7 @@ export function BookEditorActionbar(props: BookEditorActionbarProps) {
|
|
|
157
157
|
setIsAboutModalOpen(false);
|
|
158
158
|
}}
|
|
159
159
|
>
|
|
160
|
-
<
|
|
160
|
+
<BookEditorAboutPromptbookInformation />
|
|
161
161
|
</Modal>
|
|
162
162
|
)}
|
|
163
163
|
</>
|
|
@@ -183,7 +183,7 @@ export function BookEditorActionbar(props: BookEditorActionbarProps) {
|
|
|
183
183
|
setIsAboutModalOpen(false);
|
|
184
184
|
}}
|
|
185
185
|
>
|
|
186
|
-
<
|
|
186
|
+
<BookEditorAboutPromptbookInformation />
|
|
187
187
|
</Modal>
|
|
188
188
|
)}
|
|
189
189
|
</div>
|