@botpress/runtime 1.11.8 → 1.12.0
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/dist/definition.js +178 -78
- package/dist/definition.js.map +4 -4
- package/dist/internal.js +182 -82
- package/dist/internal.js.map +4 -4
- package/dist/library.d.ts +1 -0
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +184 -83
- package/dist/library.js.map +4 -4
- package/dist/runtime/adk.d.ts +7 -0
- package/dist/runtime/adk.d.ts.map +1 -1
- package/dist/runtime/client.d.ts +29 -0
- package/dist/runtime/client.d.ts.map +1 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime.js +192 -91
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
package/dist/internal.js
CHANGED
|
@@ -48,7 +48,7 @@ var init_define_BUILD = __esm({
|
|
|
48
48
|
var define_PACKAGE_VERSIONS_default;
|
|
49
49
|
var init_define_PACKAGE_VERSIONS = __esm({
|
|
50
50
|
"<define:__PACKAGE_VERSIONS__>"() {
|
|
51
|
-
define_PACKAGE_VERSIONS_default = { runtime: "1.
|
|
51
|
+
define_PACKAGE_VERSIONS_default = { runtime: "1.12.0", adk: "1.12.0", sdk: "4.20.2", llmz: "0.0.33", zai: "2.5.0", cognitive: "0.2.0" };
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
54
|
|
|
@@ -34245,12 +34245,12 @@ If the question is not related to the knowledge bases, do NOT use this tool.`.tr
|
|
|
34245
34245
|
input: z3.string().describe("The query to search for.").min(1).max(1024),
|
|
34246
34246
|
output: z3.string().describe("The search results."),
|
|
34247
34247
|
handler: async (query) => {
|
|
34248
|
-
const
|
|
34248
|
+
const client2 = context.get("client");
|
|
34249
34249
|
const citations = context.get("citations");
|
|
34250
|
-
if (!
|
|
34250
|
+
if (!client2) {
|
|
34251
34251
|
throw new Error("Client is not available in this context. Make sure to run in a context with a client.");
|
|
34252
34252
|
}
|
|
34253
|
-
const { passages } = await
|
|
34253
|
+
const { passages } = await client2.searchFiles({
|
|
34254
34254
|
query,
|
|
34255
34255
|
withContext: true,
|
|
34256
34256
|
includeBreadcrumb: true,
|
|
@@ -34631,9 +34631,9 @@ var init_actions = __esm({
|
|
|
34631
34631
|
return handler;
|
|
34632
34632
|
}
|
|
34633
34633
|
let integrations;
|
|
34634
|
-
let
|
|
34634
|
+
let client2;
|
|
34635
34635
|
integrations ??= context.get("integrations", { optional: true });
|
|
34636
|
-
|
|
34636
|
+
client2 ??= context.get("client", { optional: true });
|
|
34637
34637
|
const integrationName = propertyName.replace("__", "/");
|
|
34638
34638
|
return new Proxy(
|
|
34639
34639
|
{},
|
|
@@ -34643,19 +34643,19 @@ var init_actions = __esm({
|
|
|
34643
34643
|
return void 0;
|
|
34644
34644
|
}
|
|
34645
34645
|
integrations ??= context.get("integrations", { optional: true });
|
|
34646
|
-
|
|
34646
|
+
client2 ??= context.get("client", { optional: true });
|
|
34647
34647
|
const integration = integrations.find((i) => i.alias === integrationName);
|
|
34648
34648
|
const actionDef = integration?.definition.actions?.[actionName];
|
|
34649
34649
|
const handler = async (params) => {
|
|
34650
34650
|
integrations ??= context.get("integrations", { optional: true });
|
|
34651
|
-
|
|
34651
|
+
client2 ??= context.get("client", { optional: true });
|
|
34652
34652
|
if (!integration || !actionDef) {
|
|
34653
34653
|
throw new Error(`Could not find integration "${integrationName}" and action "${actionName}"`);
|
|
34654
34654
|
}
|
|
34655
34655
|
if (!integration.definition.actions?.[actionName]) {
|
|
34656
34656
|
throw new Error(`Action "${actionName}" not found in integration "${integrationName}"`);
|
|
34657
34657
|
}
|
|
34658
|
-
return
|
|
34658
|
+
return client2.callAction({
|
|
34659
34659
|
type: `${integration.alias}:${actionName}`,
|
|
34660
34660
|
input: params
|
|
34661
34661
|
}).then((res) => res.output);
|
|
@@ -35162,7 +35162,7 @@ var init_workflow = __esm({
|
|
|
35162
35162
|
* @returns The workflow instance
|
|
35163
35163
|
*/
|
|
35164
35164
|
async getOrCreate(props) {
|
|
35165
|
-
const
|
|
35165
|
+
const client2 = context.get("client");
|
|
35166
35166
|
const statuses = props.statuses || ["pending", "in_progress", "listening", "paused"];
|
|
35167
35167
|
const validatedInput = this._inputSchema.parse(props.input);
|
|
35168
35168
|
const tags = {};
|
|
@@ -35180,10 +35180,10 @@ var init_workflow = __esm({
|
|
|
35180
35180
|
timeoutAt: new Date(Date.now() + (this.timeout ?? (0, import_ms.default)("5m"))).toISOString(),
|
|
35181
35181
|
...discriminator && { discriminateBy: { tags: discriminator } }
|
|
35182
35182
|
};
|
|
35183
|
-
let { workflow } = await
|
|
35183
|
+
let { workflow } = await client2._inner.getOrCreateWorkflow(createArgs);
|
|
35184
35184
|
if (props.key && !statuses.includes(workflow.status)) {
|
|
35185
|
-
await
|
|
35186
|
-
({ workflow } = await
|
|
35185
|
+
await client2._inner.deleteWorkflow({ id: workflow.id });
|
|
35186
|
+
({ workflow } = await client2._inner.getOrCreateWorkflow(createArgs));
|
|
35187
35187
|
}
|
|
35188
35188
|
return await BaseWorkflowInstance.load({
|
|
35189
35189
|
id: workflow.id,
|
|
@@ -35201,9 +35201,9 @@ var init_workflow = __esm({
|
|
|
35201
35201
|
* }
|
|
35202
35202
|
*/
|
|
35203
35203
|
async provide(event, data) {
|
|
35204
|
-
const
|
|
35204
|
+
const client2 = context.get("client");
|
|
35205
35205
|
const { workflowId, stepName } = event.payload;
|
|
35206
|
-
const state = createWorkflowExecutionState(
|
|
35206
|
+
const state = createWorkflowExecutionState(client2._inner, workflowId);
|
|
35207
35207
|
await state.load();
|
|
35208
35208
|
if (!state.value) {
|
|
35209
35209
|
throw new Error(`Workflow execution state not found for workflow ${workflowId}`);
|
|
@@ -35222,7 +35222,7 @@ var init_workflow = __esm({
|
|
|
35222
35222
|
}
|
|
35223
35223
|
state.value.revision++;
|
|
35224
35224
|
await state.save();
|
|
35225
|
-
await
|
|
35225
|
+
await client2.createEvent({
|
|
35226
35226
|
type: WorkflowContinueEvent.name,
|
|
35227
35227
|
workflowId,
|
|
35228
35228
|
payload: {}
|
|
@@ -35230,10 +35230,10 @@ var init_workflow = __esm({
|
|
|
35230
35230
|
}
|
|
35231
35231
|
async start(input) {
|
|
35232
35232
|
const validatedInput = this._inputSchema.parse(input);
|
|
35233
|
-
const
|
|
35233
|
+
const client2 = context.get("client");
|
|
35234
35234
|
const event = context.get("event", { optional: true });
|
|
35235
35235
|
const workflow = context.get("workflow", { optional: true });
|
|
35236
|
-
const res = await
|
|
35236
|
+
const res = await client2._inner.createWorkflow({
|
|
35237
35237
|
name: this.name,
|
|
35238
35238
|
status: event ? "in_progress" : "pending",
|
|
35239
35239
|
eventId: event?.id,
|
|
@@ -35487,8 +35487,8 @@ var init_action = __esm({
|
|
|
35487
35487
|
/**
|
|
35488
35488
|
* Execute the action with input validation and output validation
|
|
35489
35489
|
*/
|
|
35490
|
-
async execute({ input, client }) {
|
|
35491
|
-
return await this.handler({ input, client });
|
|
35490
|
+
async execute({ input, client: client2 }) {
|
|
35491
|
+
return await this.handler({ input, client: client2 });
|
|
35492
35492
|
}
|
|
35493
35493
|
};
|
|
35494
35494
|
}
|
|
@@ -35554,9 +35554,9 @@ var init_computed_columns = __esm({
|
|
|
35554
35554
|
isFinished: z10.boolean(),
|
|
35555
35555
|
rows: z10.array(z10.any())
|
|
35556
35556
|
}),
|
|
35557
|
-
handler: async ({ input, client }) => {
|
|
35557
|
+
handler: async ({ input, client: client2 }) => {
|
|
35558
35558
|
const { tableId, requests } = input;
|
|
35559
|
-
const { table: remoteTable } = await
|
|
35559
|
+
const { table: remoteTable } = await client2._inner.getTable({ table: tableId });
|
|
35560
35560
|
const table = adk.project.tables.find((x) => x.name === remoteTable.name);
|
|
35561
35561
|
async function computeRow(row, columnsToRecompute) {
|
|
35562
35562
|
const newRow = { id: row.id };
|
|
@@ -35629,7 +35629,35 @@ __export(adk_exports, {
|
|
|
35629
35629
|
register: () => register,
|
|
35630
35630
|
registerIntegration: () => registerIntegration
|
|
35631
35631
|
});
|
|
35632
|
+
import { BotSpecificClient } from "@botpress/sdk";
|
|
35632
35633
|
import { Zai } from "@botpress/zai";
|
|
35634
|
+
import { Cognitive as Cognitive2 } from "@botpress/cognitive";
|
|
35635
|
+
import { Client } from "@botpress/client";
|
|
35636
|
+
function getStandaloneCognitive() {
|
|
35637
|
+
return getSingleton("__ADK_GLOBAL_STANDALONE_COGNITIVE", () => {
|
|
35638
|
+
const token = process.env.BP_TOKEN || process.env.ADK_TOKEN;
|
|
35639
|
+
if (!token) {
|
|
35640
|
+
throw new Error(
|
|
35641
|
+
'No token found. Set BP_TOKEN or ADK_TOKEN environment variable, or run this script using "adk run".'
|
|
35642
|
+
);
|
|
35643
|
+
}
|
|
35644
|
+
const botId = process.env.ADK_BOT_ID;
|
|
35645
|
+
if (!botId) {
|
|
35646
|
+
throw new Error('No bot ID found. Set ADK_BOT_ID environment variable, or run this script using "adk run".');
|
|
35647
|
+
}
|
|
35648
|
+
const apiUrl = process.env.ADK_API_URL || "https://api.botpress.cloud";
|
|
35649
|
+
const vanillaClient = new Client({
|
|
35650
|
+
token,
|
|
35651
|
+
apiUrl,
|
|
35652
|
+
botId
|
|
35653
|
+
});
|
|
35654
|
+
const botClient = new BotSpecificClient(vanillaClient);
|
|
35655
|
+
return new Cognitive2({
|
|
35656
|
+
client: botClient,
|
|
35657
|
+
__experimental_beta: true
|
|
35658
|
+
});
|
|
35659
|
+
});
|
|
35660
|
+
}
|
|
35633
35661
|
function initialize(options) {
|
|
35634
35662
|
const state = getState();
|
|
35635
35663
|
if (state.initialized) {
|
|
@@ -35717,8 +35745,10 @@ var init_adk = __esm({
|
|
|
35717
35745
|
return Environment;
|
|
35718
35746
|
},
|
|
35719
35747
|
get zai() {
|
|
35748
|
+
const contextCognitive = context.get("cognitive", { optional: true });
|
|
35749
|
+
const cognitive = contextCognitive ?? getStandaloneCognitive();
|
|
35720
35750
|
return new Zai({
|
|
35721
|
-
client:
|
|
35751
|
+
client: cognitive,
|
|
35722
35752
|
modelId: Array.isArray(adk.project.config.defaultModels.zai) ? adk.project.config.defaultModels.zai[0] ?? "auto" : adk.project.config.defaultModels.zai
|
|
35723
35753
|
});
|
|
35724
35754
|
},
|
|
@@ -35743,6 +35773,29 @@ var init_adk = __esm({
|
|
|
35743
35773
|
conversations: state.primitives.conversations,
|
|
35744
35774
|
triggers: state.primitives.triggers
|
|
35745
35775
|
};
|
|
35776
|
+
},
|
|
35777
|
+
async execute(props) {
|
|
35778
|
+
const contextCognitive = context.get("cognitive", { optional: true });
|
|
35779
|
+
const cognitive = contextCognitive ?? getStandaloneCognitive();
|
|
35780
|
+
const defaultModel = adk.project.config.defaultModels.autonomous;
|
|
35781
|
+
const { execute: llmz_execute, getValue: getValue2 } = await import("llmz");
|
|
35782
|
+
return llmz_execute({
|
|
35783
|
+
client: cognitive,
|
|
35784
|
+
instructions: props.instructions,
|
|
35785
|
+
...props.tools && { tools: props.tools },
|
|
35786
|
+
...props.objects && { objects: props.objects },
|
|
35787
|
+
...props.exits && { exits: props.exits },
|
|
35788
|
+
...props.signal && { signal: props.signal },
|
|
35789
|
+
temperature: async (ctx) => props.temperature ? await getValue2(props.temperature, ctx) : 0.7,
|
|
35790
|
+
model: async (ctx) => props.model ? await getValue2(props.model, ctx) : defaultModel,
|
|
35791
|
+
options: { loop: props.iterations ?? 10 },
|
|
35792
|
+
...props.hooks?.onTrace && { onTrace: props.hooks.onTrace },
|
|
35793
|
+
...props.hooks?.onIterationEnd && { onIterationEnd: props.hooks.onIterationEnd },
|
|
35794
|
+
...props.hooks?.onBeforeTool && { onBeforeTool: props.hooks.onBeforeTool },
|
|
35795
|
+
...props.hooks?.onAfterTool && { onAfterTool: props.hooks.onAfterTool },
|
|
35796
|
+
...props.hooks?.onBeforeExecution && { onBeforeExecution: props.hooks.onBeforeExecution },
|
|
35797
|
+
...props.hooks?.onExit && { onExit: props.hooks.onExit }
|
|
35798
|
+
});
|
|
35746
35799
|
}
|
|
35747
35800
|
};
|
|
35748
35801
|
}
|
|
@@ -35857,14 +35910,14 @@ var init_tracked_state = __esm({
|
|
|
35857
35910
|
}
|
|
35858
35911
|
static async loadAll() {
|
|
35859
35912
|
await span("state.loadAll", {}, async () => {
|
|
35860
|
-
const
|
|
35913
|
+
const client2 = context.get("client")._inner;
|
|
35861
35914
|
const botId = context.get("botId", { optional: true });
|
|
35862
35915
|
const user2 = context.get("user", { optional: true });
|
|
35863
35916
|
const conversation = context.get("conversation", { optional: true });
|
|
35864
35917
|
const { adk: adk2 } = await Promise.resolve().then(() => (init_adk(), adk_exports));
|
|
35865
35918
|
if (botId) {
|
|
35866
35919
|
_TrackedState.create({
|
|
35867
|
-
client,
|
|
35920
|
+
client: client2,
|
|
35868
35921
|
name: BUILT_IN_STATES.bot,
|
|
35869
35922
|
type: "bot",
|
|
35870
35923
|
id: botId,
|
|
@@ -35873,7 +35926,7 @@ var init_tracked_state = __esm({
|
|
|
35873
35926
|
}
|
|
35874
35927
|
if (user2) {
|
|
35875
35928
|
_TrackedState.create({
|
|
35876
|
-
client,
|
|
35929
|
+
client: client2,
|
|
35877
35930
|
name: BUILT_IN_STATES.user,
|
|
35878
35931
|
type: "user",
|
|
35879
35932
|
id: user2.id,
|
|
@@ -35890,7 +35943,7 @@ var init_tracked_state = __esm({
|
|
|
35890
35943
|
}
|
|
35891
35944
|
});
|
|
35892
35945
|
_TrackedState.create({
|
|
35893
|
-
client,
|
|
35946
|
+
client: client2,
|
|
35894
35947
|
name: BUILT_IN_STATES.conversation,
|
|
35895
35948
|
type: "conversation",
|
|
35896
35949
|
id: conversation.id,
|
|
@@ -36197,7 +36250,7 @@ var init_events = __esm({
|
|
|
36197
36250
|
// src/runtime/context/handlers.ts
|
|
36198
36251
|
import * as sdk from "@botpress/sdk";
|
|
36199
36252
|
import { CitationsManager } from "llmz";
|
|
36200
|
-
import { Client } from "@botpress/client";
|
|
36253
|
+
import { Client as Client2 } from "@botpress/client";
|
|
36201
36254
|
import { ulid } from "ulid";
|
|
36202
36255
|
var init_handlers = __esm({
|
|
36203
36256
|
"src/runtime/context/handlers.ts"() {
|
|
@@ -36940,12 +36993,12 @@ var init_conversation_instance = __esm({
|
|
|
36940
36993
|
TrackedState;
|
|
36941
36994
|
// @internal
|
|
36942
36995
|
TrackedTags;
|
|
36943
|
-
constructor(conversation,
|
|
36996
|
+
constructor(conversation, client2) {
|
|
36944
36997
|
this.id = conversation.id;
|
|
36945
36998
|
this.channel = `${conversation.integration}.${conversation.channel}`;
|
|
36946
36999
|
this.integration = conversation.integration;
|
|
36947
37000
|
this.conversation = conversation;
|
|
36948
|
-
this.client =
|
|
37001
|
+
this.client = client2;
|
|
36949
37002
|
const states = context.get("states", { optional: true });
|
|
36950
37003
|
const existingState = states?.find(
|
|
36951
37004
|
(s) => s.type === "conversation" && s.id === conversation.id && s.name === BUILT_IN_STATES.conversation
|
|
@@ -36959,7 +37012,7 @@ var init_conversation_instance = __esm({
|
|
|
36959
37012
|
const tags = TrackedTags.create({
|
|
36960
37013
|
type: "conversation",
|
|
36961
37014
|
id: conversation.id,
|
|
36962
|
-
client:
|
|
37015
|
+
client: client2._inner,
|
|
36963
37016
|
initialTags: conversation.tags
|
|
36964
37017
|
});
|
|
36965
37018
|
this.TrackedTags = tags;
|
|
@@ -37127,9 +37180,9 @@ var init_conversation = __esm({
|
|
|
37127
37180
|
const message = context.get("message", { optional: true });
|
|
37128
37181
|
const event = context.get("event", { optional: true });
|
|
37129
37182
|
const chat = context.get("chat");
|
|
37130
|
-
const
|
|
37183
|
+
const client2 = context.get("client");
|
|
37131
37184
|
const botpressConversation = context.get("conversation");
|
|
37132
|
-
const conversationInstance = new BaseConversationInstance(botpressConversation,
|
|
37185
|
+
const conversationInstance = new BaseConversationInstance(botpressConversation, client2);
|
|
37133
37186
|
const startTypingPromise = conversationInstance.startTyping().catch(() => {
|
|
37134
37187
|
});
|
|
37135
37188
|
let type;
|
|
@@ -37166,7 +37219,7 @@ var init_conversation = __esm({
|
|
|
37166
37219
|
if (controller.signal.aborted) {
|
|
37167
37220
|
return;
|
|
37168
37221
|
}
|
|
37169
|
-
const { events } = await
|
|
37222
|
+
const { events } = await client2.listEvents({
|
|
37170
37223
|
conversationId: conversationInstance.id,
|
|
37171
37224
|
status: "pending"
|
|
37172
37225
|
});
|
|
@@ -37239,7 +37292,7 @@ var init_conversation = __esm({
|
|
|
37239
37292
|
request: requestObject,
|
|
37240
37293
|
conversation: conversationInstance,
|
|
37241
37294
|
state: stateProxy,
|
|
37242
|
-
client,
|
|
37295
|
+
client: client2,
|
|
37243
37296
|
execute
|
|
37244
37297
|
});
|
|
37245
37298
|
controller.abort();
|
|
@@ -37297,7 +37350,7 @@ var init_workflow_utils = __esm({
|
|
|
37297
37350
|
init_runtime();
|
|
37298
37351
|
init_events2();
|
|
37299
37352
|
updateWorkflow = async (props) => {
|
|
37300
|
-
const
|
|
37353
|
+
const client2 = context.get("client");
|
|
37301
37354
|
const workflowId = props.id;
|
|
37302
37355
|
const workflowsToUpdate = [];
|
|
37303
37356
|
const ctxWorkflow = context.get("workflow", { optional: true });
|
|
@@ -37316,7 +37369,7 @@ var init_workflow_utils = __esm({
|
|
|
37316
37369
|
if (workflowAlreadyDone) {
|
|
37317
37370
|
return { workflow: workflowAlreadyDone };
|
|
37318
37371
|
}
|
|
37319
|
-
const response = await
|
|
37372
|
+
const response = await client2.updateWorkflow(props);
|
|
37320
37373
|
for (const wf of workflowsToUpdate) {
|
|
37321
37374
|
Object.assign(wf, response.workflow);
|
|
37322
37375
|
}
|
|
@@ -37460,7 +37513,7 @@ var init_tracked_tags = __esm({
|
|
|
37460
37513
|
}
|
|
37461
37514
|
static async loadAll() {
|
|
37462
37515
|
await span("tags.loadAll", {}, async () => {
|
|
37463
|
-
const
|
|
37516
|
+
const client2 = context.get("client")._inner;
|
|
37464
37517
|
const bot2 = context.get("bot", { optional: true });
|
|
37465
37518
|
const user2 = context.get("user", { optional: true });
|
|
37466
37519
|
const conversation = context.get("conversation", { optional: true });
|
|
@@ -37468,7 +37521,7 @@ var init_tracked_tags = __esm({
|
|
|
37468
37521
|
if (bot2) {
|
|
37469
37522
|
const botTags = bot2.tags;
|
|
37470
37523
|
_TrackedTags.create({
|
|
37471
|
-
client,
|
|
37524
|
+
client: client2,
|
|
37472
37525
|
type: "bot",
|
|
37473
37526
|
id: bot2.id,
|
|
37474
37527
|
...botTags && { initialTags: botTags }
|
|
@@ -37477,7 +37530,7 @@ var init_tracked_tags = __esm({
|
|
|
37477
37530
|
if (user2) {
|
|
37478
37531
|
const userTags = user2.tags;
|
|
37479
37532
|
_TrackedTags.create({
|
|
37480
|
-
client,
|
|
37533
|
+
client: client2,
|
|
37481
37534
|
type: "user",
|
|
37482
37535
|
id: user2.id,
|
|
37483
37536
|
...userTags && { initialTags: userTags }
|
|
@@ -37486,7 +37539,7 @@ var init_tracked_tags = __esm({
|
|
|
37486
37539
|
if (conversation) {
|
|
37487
37540
|
const conversationTags = conversation.tags;
|
|
37488
37541
|
_TrackedTags.create({
|
|
37489
|
-
client,
|
|
37542
|
+
client: client2,
|
|
37490
37543
|
type: "conversation",
|
|
37491
37544
|
id: conversation.id,
|
|
37492
37545
|
...conversationTags && { initialTags: conversationTags }
|
|
@@ -37495,7 +37548,7 @@ var init_tracked_tags = __esm({
|
|
|
37495
37548
|
if (workflow) {
|
|
37496
37549
|
const workflowTags = workflow.tags;
|
|
37497
37550
|
_TrackedTags.create({
|
|
37498
|
-
client,
|
|
37551
|
+
client: client2,
|
|
37499
37552
|
type: "workflow",
|
|
37500
37553
|
id: workflow.id,
|
|
37501
37554
|
...workflowTags && { initialTags: workflowTags }
|
|
@@ -37635,6 +37688,51 @@ var init_tracked_tags = __esm({
|
|
|
37635
37688
|
}
|
|
37636
37689
|
});
|
|
37637
37690
|
|
|
37691
|
+
// src/runtime/client.ts
|
|
37692
|
+
import { Client as Client3 } from "@botpress/client";
|
|
37693
|
+
function getStandaloneClient() {
|
|
37694
|
+
return getSingleton("__ADK_GLOBAL_STANDALONE_CLIENT", () => {
|
|
37695
|
+
const token = process.env.BP_TOKEN || process.env.ADK_TOKEN;
|
|
37696
|
+
if (!token) {
|
|
37697
|
+
throw new Error(
|
|
37698
|
+
'No token found. Set BP_TOKEN or ADK_TOKEN environment variable, or run this script using "adk run".'
|
|
37699
|
+
);
|
|
37700
|
+
}
|
|
37701
|
+
const botId = process.env.ADK_BOT_ID;
|
|
37702
|
+
if (!botId) {
|
|
37703
|
+
throw new Error(
|
|
37704
|
+
'No bot ID found. Set ADK_BOT_ID environment variable, or run this script using "adk run".'
|
|
37705
|
+
);
|
|
37706
|
+
}
|
|
37707
|
+
const apiUrl = process.env.ADK_API_URL || "https://api.botpress.cloud";
|
|
37708
|
+
return new Client3({
|
|
37709
|
+
token,
|
|
37710
|
+
apiUrl,
|
|
37711
|
+
botId
|
|
37712
|
+
});
|
|
37713
|
+
});
|
|
37714
|
+
}
|
|
37715
|
+
var client;
|
|
37716
|
+
var init_client = __esm({
|
|
37717
|
+
"src/runtime/client.ts"() {
|
|
37718
|
+
"use strict";
|
|
37719
|
+
init_define_BUILD();
|
|
37720
|
+
init_define_PACKAGE_VERSIONS();
|
|
37721
|
+
init_context();
|
|
37722
|
+
init_singletons();
|
|
37723
|
+
client = new Proxy({}, {
|
|
37724
|
+
get(_target, prop) {
|
|
37725
|
+
const contextClient = context.get("client", { optional: true });
|
|
37726
|
+
if (contextClient) {
|
|
37727
|
+
return contextClient[prop];
|
|
37728
|
+
}
|
|
37729
|
+
const standaloneClient = getStandaloneClient();
|
|
37730
|
+
return standaloneClient[prop];
|
|
37731
|
+
}
|
|
37732
|
+
});
|
|
37733
|
+
}
|
|
37734
|
+
});
|
|
37735
|
+
|
|
37638
37736
|
// src/runtime/index.ts
|
|
37639
37737
|
var init_runtime2 = __esm({
|
|
37640
37738
|
"src/runtime/index.ts"() {
|
|
@@ -37653,12 +37751,13 @@ var init_runtime2 = __esm({
|
|
|
37653
37751
|
init_tracked_tags();
|
|
37654
37752
|
init_actions();
|
|
37655
37753
|
init_events();
|
|
37754
|
+
init_client();
|
|
37656
37755
|
}
|
|
37657
37756
|
});
|
|
37658
37757
|
|
|
37659
37758
|
// src/library.ts
|
|
37660
37759
|
import { z as z18 } from "@botpress/sdk";
|
|
37661
|
-
import { Cognitive as
|
|
37760
|
+
import { Cognitive as Cognitive3 } from "@botpress/cognitive";
|
|
37662
37761
|
import { Zai as Zai2 } from "@botpress/zai";
|
|
37663
37762
|
var init_library = __esm({
|
|
37664
37763
|
"src/library.ts"() {
|
|
@@ -37666,6 +37765,7 @@ var init_library = __esm({
|
|
|
37666
37765
|
init_define_BUILD();
|
|
37667
37766
|
init_define_PACKAGE_VERSIONS();
|
|
37668
37767
|
init_runtime2();
|
|
37768
|
+
init_client();
|
|
37669
37769
|
init_primitives();
|
|
37670
37770
|
init_workflow_utils();
|
|
37671
37771
|
init_events2();
|
|
@@ -37909,9 +38009,9 @@ var init_workflow_step = __esm({
|
|
|
37909
38009
|
async () => {
|
|
37910
38010
|
const remainingTime = context.get("runtime").getRemainingExecutionTimeInMs();
|
|
37911
38011
|
if (remainingTime - MIN_STEP_REMAINING_TIME_MS <= ms3 || ms3 >= 1e4) {
|
|
37912
|
-
const
|
|
38012
|
+
const client2 = context.get("client");
|
|
37913
38013
|
const workflowControlContext = context.get("workflowControlContext");
|
|
37914
|
-
await
|
|
38014
|
+
await client2.createEvent({
|
|
37915
38015
|
type: WorkflowContinueEvent.name,
|
|
37916
38016
|
payload: {},
|
|
37917
38017
|
workflowId: workflowControlContext.workflow.id,
|
|
@@ -37947,13 +38047,13 @@ var init_workflow_step = __esm({
|
|
|
37947
38047
|
return await _step(
|
|
37948
38048
|
name,
|
|
37949
38049
|
async () => {
|
|
37950
|
-
const
|
|
38050
|
+
const client2 = context.get("client");
|
|
37951
38051
|
const state = createWorkflowExecutionState(
|
|
37952
38052
|
context.get("client")._inner,
|
|
37953
38053
|
workflowControlContext.workflow.id
|
|
37954
38054
|
);
|
|
37955
38055
|
assert(state.value, "State is not loaded");
|
|
37956
|
-
const { workflow } = await
|
|
38056
|
+
const { workflow } = await client2.getWorkflow({ id: workflowId });
|
|
37957
38057
|
if (isWorkflowFinished(workflow.status)) {
|
|
37958
38058
|
return workflow;
|
|
37959
38059
|
}
|
|
@@ -38041,7 +38141,7 @@ var init_workflow_step = __esm({
|
|
|
38041
38141
|
actualStepName,
|
|
38042
38142
|
async () => {
|
|
38043
38143
|
const workflowControlContext = context.get("workflowControlContext");
|
|
38044
|
-
const
|
|
38144
|
+
const client2 = context.get("client");
|
|
38045
38145
|
if (!workflowControlContext.workflow.conversationId) {
|
|
38046
38146
|
throw new Error(`Cannot request data: workflow ${workflowControlContext.workflow.id} has no conversationId`);
|
|
38047
38147
|
}
|
|
@@ -38055,14 +38155,14 @@ var init_workflow_step = __esm({
|
|
|
38055
38155
|
`Request "${request}" not found in workflow "${workflowDef.name}". Available requests: ${Object.keys(workflowDef._requestsSchemas || {}).join(", ") || "none"}`
|
|
38056
38156
|
);
|
|
38057
38157
|
}
|
|
38058
|
-
const state = createWorkflowExecutionState(
|
|
38158
|
+
const state = createWorkflowExecutionState(client2._inner, workflowControlContext.workflow.id);
|
|
38059
38159
|
if (!state.value) {
|
|
38060
38160
|
throw new Error("Workflow execution state not loaded");
|
|
38061
38161
|
}
|
|
38062
38162
|
if (state.value.steps?.[actualStepName]?.output !== void 0) {
|
|
38063
38163
|
return requestSchema.parse(state.value.steps[actualStepName].output);
|
|
38064
38164
|
}
|
|
38065
|
-
await
|
|
38165
|
+
await client2.createEvent({
|
|
38066
38166
|
type: WorkflowDataRequestEvent2.name,
|
|
38067
38167
|
conversationId: workflowControlContext.workflow.conversationId,
|
|
38068
38168
|
payload: {
|
|
@@ -38092,7 +38192,7 @@ var init_workflow_step = __esm({
|
|
|
38092
38192
|
|
|
38093
38193
|
// src/primitives/workflow-cancellation-monitor.ts
|
|
38094
38194
|
function startWorkflowCancellationMonitor(props) {
|
|
38095
|
-
const { client, workflowId, workflowControlContext, abortSignal, pollIntervalMs = 1e3 } = props;
|
|
38195
|
+
const { client: client2, workflowId, workflowControlContext, abortSignal, pollIntervalMs = 1e3 } = props;
|
|
38096
38196
|
if (abortSignal.aborted) {
|
|
38097
38197
|
return () => {
|
|
38098
38198
|
};
|
|
@@ -38103,7 +38203,7 @@ function startWorkflowCancellationMonitor(props) {
|
|
|
38103
38203
|
return;
|
|
38104
38204
|
}
|
|
38105
38205
|
try {
|
|
38106
|
-
const { workflow } = await
|
|
38206
|
+
const { workflow } = await client2.getWorkflow({ id: workflowId });
|
|
38107
38207
|
const isTerminated = workflow.status === "cancelled" || workflow.status === "failed" || workflow.status === "timedout";
|
|
38108
38208
|
if (isTerminated) {
|
|
38109
38209
|
workflowControlContext.aborted = true;
|
|
@@ -38147,10 +38247,10 @@ function createStepSignal() {
|
|
|
38147
38247
|
[StepSymbol]: true
|
|
38148
38248
|
};
|
|
38149
38249
|
}
|
|
38150
|
-
function createWorkflowExecutionState(
|
|
38250
|
+
function createWorkflowExecutionState(client2, workflowId) {
|
|
38151
38251
|
return TrackedState.create({
|
|
38152
38252
|
type: "workflow",
|
|
38153
|
-
client,
|
|
38253
|
+
client: client2,
|
|
38154
38254
|
id: workflowId,
|
|
38155
38255
|
schema: workflowExecutionContextSchema,
|
|
38156
38256
|
name: BUILT_IN_STATES.workflowSteps
|
|
@@ -38208,18 +38308,18 @@ var init_workflow_instance = __esm({
|
|
|
38208
38308
|
TrackedState;
|
|
38209
38309
|
// @internal
|
|
38210
38310
|
TrackedTags;
|
|
38211
|
-
constructor(workflow,
|
|
38311
|
+
constructor(workflow, client2) {
|
|
38212
38312
|
const definition = adk.project.workflows.find((w) => w.name === workflow.name);
|
|
38213
38313
|
this.TrackedState = TrackedState.create({
|
|
38214
38314
|
type: "workflow",
|
|
38215
|
-
client:
|
|
38315
|
+
client: client2._inner,
|
|
38216
38316
|
id: workflow.id,
|
|
38217
38317
|
schema: definition?.stateSchema,
|
|
38218
38318
|
name: BUILT_IN_STATES.workflowState
|
|
38219
38319
|
});
|
|
38220
38320
|
this.TrackedTags = TrackedTags.create({
|
|
38221
38321
|
type: "workflow",
|
|
38222
|
-
client:
|
|
38322
|
+
client: client2._inner,
|
|
38223
38323
|
id: workflow.id,
|
|
38224
38324
|
initialTags: workflow.tags
|
|
38225
38325
|
});
|
|
@@ -38229,7 +38329,7 @@ var init_workflow_instance = __esm({
|
|
|
38229
38329
|
this.input = workflow.input;
|
|
38230
38330
|
this.createdAt = new Date(workflow.createdAt);
|
|
38231
38331
|
this.updatedAt = new Date(workflow.updatedAt);
|
|
38232
|
-
this.client =
|
|
38332
|
+
this.client = client2;
|
|
38233
38333
|
this.workflow = workflow;
|
|
38234
38334
|
}
|
|
38235
38335
|
get tags() {
|
|
@@ -38250,19 +38350,19 @@ var init_workflow_instance = __esm({
|
|
|
38250
38350
|
}
|
|
38251
38351
|
static Primitive = "workflow_instance";
|
|
38252
38352
|
static async load(props) {
|
|
38253
|
-
const
|
|
38254
|
-
const workflow = props.workflow ? props.workflow : await
|
|
38353
|
+
const client2 = context.get("client");
|
|
38354
|
+
const workflow = props.workflow ? props.workflow : await client2.getWorkflow({ id: props.id }).then((x) => x.workflow);
|
|
38255
38355
|
if (!adk.project.workflows.find((w) => w.name === workflow.name)) {
|
|
38256
38356
|
throw new Error(`No ADK Workflow definition found for "${workflow.name}"`);
|
|
38257
38357
|
}
|
|
38258
38358
|
TrackedTags.create({
|
|
38259
38359
|
type: "workflow",
|
|
38260
|
-
client:
|
|
38360
|
+
client: client2._inner,
|
|
38261
38361
|
id: workflow.id,
|
|
38262
38362
|
initialTags: workflow.tags
|
|
38263
38363
|
});
|
|
38264
38364
|
await TrackedTags.loadAll();
|
|
38265
|
-
return new _BaseWorkflowInstance(workflow,
|
|
38365
|
+
return new _BaseWorkflowInstance(workflow, client2);
|
|
38266
38366
|
}
|
|
38267
38367
|
/**
|
|
38268
38368
|
* Executes the workflow with the provided autonomous engine configuration.
|
|
@@ -38299,8 +38399,8 @@ var init_workflow_instance = __esm({
|
|
|
38299
38399
|
* }
|
|
38300
38400
|
*/
|
|
38301
38401
|
async provide(request, data) {
|
|
38302
|
-
const
|
|
38303
|
-
const state = createWorkflowExecutionState(
|
|
38402
|
+
const client2 = context.get("client");
|
|
38403
|
+
const state = createWorkflowExecutionState(client2._inner, this.id);
|
|
38304
38404
|
await state.load();
|
|
38305
38405
|
if (!state.value) {
|
|
38306
38406
|
throw new Error(`Workflow execution state not found for workflow ${this.id}`);
|
|
@@ -38319,7 +38419,7 @@ var init_workflow_instance = __esm({
|
|
|
38319
38419
|
}
|
|
38320
38420
|
state.value.revision++;
|
|
38321
38421
|
await state.save();
|
|
38322
|
-
await
|
|
38422
|
+
await client2.createEvent({
|
|
38323
38423
|
type: WorkflowContinueEvent.name,
|
|
38324
38424
|
workflowId: this.id,
|
|
38325
38425
|
payload: {}
|
|
@@ -38370,8 +38470,8 @@ var init_workflow_instance = __esm({
|
|
|
38370
38470
|
}
|
|
38371
38471
|
};
|
|
38372
38472
|
try {
|
|
38373
|
-
const
|
|
38374
|
-
const workflowExecutionState = createWorkflowExecutionState(
|
|
38473
|
+
const client2 = context.get("client");
|
|
38474
|
+
const workflowExecutionState = createWorkflowExecutionState(client2._inner, this.id);
|
|
38375
38475
|
await workflowExecutionState.load();
|
|
38376
38476
|
await this.TrackedState.load();
|
|
38377
38477
|
abortSignal.throwIfAborted();
|
|
@@ -38393,7 +38493,7 @@ var init_workflow_instance = __esm({
|
|
|
38393
38493
|
}
|
|
38394
38494
|
context.set("workflowControlContext", workflowControlContext);
|
|
38395
38495
|
const stopCancellationMonitor = startWorkflowCancellationMonitor({
|
|
38396
|
-
client:
|
|
38496
|
+
client: client2._inner,
|
|
38397
38497
|
workflowId: this.id,
|
|
38398
38498
|
workflowControlContext,
|
|
38399
38499
|
abortSignal
|
|
@@ -40677,7 +40777,7 @@ var init_source_website = __esm({
|
|
|
40677
40777
|
return createSyncWorkflow({
|
|
40678
40778
|
type: "website",
|
|
40679
40779
|
state: State,
|
|
40680
|
-
async handler({ input, step: step2, state, client }) {
|
|
40780
|
+
async handler({ input, step: step2, state, client: client2 }) {
|
|
40681
40781
|
const crypto3 = await import("crypto");
|
|
40682
40782
|
console.log(
|
|
40683
40783
|
`Starting sync for WebsiteSource [${this.id}] in mode [${this.mode}, maxPages=${this.maxPages}, maxDepth=${this.maxDepth}, baseUrl=${this.baseUrl}, sitemapUrl=${this.sitemapUrl}]`
|
|
@@ -40698,7 +40798,7 @@ var init_source_website = __esm({
|
|
|
40698
40798
|
console.log(`Will process up to ${this.maxPages} pages`);
|
|
40699
40799
|
const existingFiles = await step2(
|
|
40700
40800
|
"list existing files",
|
|
40701
|
-
() =>
|
|
40801
|
+
() => client2._inner.list.files({
|
|
40702
40802
|
tags
|
|
40703
40803
|
}).collect()
|
|
40704
40804
|
);
|
|
@@ -40709,7 +40809,7 @@ var init_source_website = __esm({
|
|
|
40709
40809
|
await step2.map(
|
|
40710
40810
|
"deleting all existing files for recrawl",
|
|
40711
40811
|
existingFiles,
|
|
40712
|
-
(f) =>
|
|
40812
|
+
(f) => client2.deleteFile({ id: f.id }).catch(() => null),
|
|
40713
40813
|
{ concurrency: 5 }
|
|
40714
40814
|
);
|
|
40715
40815
|
console.log(`\u2705 Deleted ${existingFiles.length} files, starting fresh crawl`);
|
|
@@ -40741,7 +40841,7 @@ var init_source_website = __esm({
|
|
|
40741
40841
|
const deleted = await step2.map(
|
|
40742
40842
|
"deleting removed urls",
|
|
40743
40843
|
toRemove,
|
|
40744
|
-
(f) =>
|
|
40844
|
+
(f) => client2.deleteFile({ id: f.id }).catch(() => null).then(
|
|
40745
40845
|
() => ({
|
|
40746
40846
|
file: f.id,
|
|
40747
40847
|
name: f.key,
|
|
@@ -40766,7 +40866,7 @@ var init_source_website = __esm({
|
|
|
40766
40866
|
contentType = content.includes("<html") ? "text/html" : "text/markdown";
|
|
40767
40867
|
}
|
|
40768
40868
|
const key = `data_source://${this.type}/${this.id}/${encodeURIComponent(url2)}`;
|
|
40769
|
-
const uploaded = await
|
|
40869
|
+
const uploaded = await client2.uploadFile({
|
|
40770
40870
|
key,
|
|
40771
40871
|
content,
|
|
40772
40872
|
contentType,
|
|
@@ -40826,7 +40926,7 @@ var init_source_website = __esm({
|
|
|
40826
40926
|
await step2("register web page source", async () => {
|
|
40827
40927
|
try {
|
|
40828
40928
|
const botId = context.get("botId");
|
|
40829
|
-
const getStateResult = await
|
|
40929
|
+
const getStateResult = await client2._inner.getState({ id: botId, type: "bot", name: "dsData" }).catch(() => ({ state: null }));
|
|
40830
40930
|
const freshState = getStateResult.state;
|
|
40831
40931
|
const existingPayload = freshState?.payload || {};
|
|
40832
40932
|
const kbPayload = existingPayload[input.kbId] || {};
|
|
@@ -40848,7 +40948,7 @@ var init_source_website = __esm({
|
|
|
40848
40948
|
data: { websiteUrl, pages: [], indexingJobs: [] }
|
|
40849
40949
|
};
|
|
40850
40950
|
existingPayload[input.kbId] = kbPayload;
|
|
40851
|
-
await
|
|
40951
|
+
await client2._inner.setState({
|
|
40852
40952
|
id: botId,
|
|
40853
40953
|
type: "bot",
|
|
40854
40954
|
name: "dsData",
|
|
@@ -47726,7 +47826,7 @@ var init_source_directory = __esm({
|
|
|
47726
47826
|
return createSyncWorkflow({
|
|
47727
47827
|
type: "directory",
|
|
47728
47828
|
state: z25.object({}),
|
|
47729
|
-
handler: async ({ input, step: step2, client }) => {
|
|
47829
|
+
handler: async ({ input, step: step2, client: client2 }) => {
|
|
47730
47830
|
if (!adk.environment.isDevelopment()) {
|
|
47731
47831
|
console.log("Directory ingestion is only supported in development environment");
|
|
47732
47832
|
return {
|
|
@@ -47778,7 +47878,7 @@ var init_source_directory = __esm({
|
|
|
47778
47878
|
);
|
|
47779
47879
|
const existingFiles = await step2(
|
|
47780
47880
|
"list existing files",
|
|
47781
|
-
() =>
|
|
47881
|
+
() => client2._inner.list.files({
|
|
47782
47882
|
tags
|
|
47783
47883
|
}).collect()
|
|
47784
47884
|
);
|
|
@@ -47792,7 +47892,7 @@ var init_source_directory = __esm({
|
|
|
47792
47892
|
const deleted = await step2.map(
|
|
47793
47893
|
"deleting removed files",
|
|
47794
47894
|
toRemove,
|
|
47795
|
-
(f) =>
|
|
47895
|
+
(f) => client2.deleteFile({ id: f.id }).catch(() => null).then(
|
|
47796
47896
|
() => ({
|
|
47797
47897
|
file: f.id,
|
|
47798
47898
|
name: f.key,
|
|
@@ -47806,7 +47906,7 @@ var init_source_directory = __esm({
|
|
|
47806
47906
|
const key = `data_source://${this.type}/${this.id}/${local.rel}`;
|
|
47807
47907
|
const content = await fs3.readFile(local.abs);
|
|
47808
47908
|
const hash = crypto3.createHash("sha256").update(content).digest("hex");
|
|
47809
|
-
const { file } = await
|
|
47909
|
+
const { file } = await client2.getFile({ id: key }).catch(() => ({ file: null }));
|
|
47810
47910
|
if (!input.force && file?.metadata?.hash === hash) {
|
|
47811
47911
|
console.log(`Skipping unchanged file: ${local.rel}`);
|
|
47812
47912
|
return null;
|
|
@@ -47815,7 +47915,7 @@ var init_source_directory = __esm({
|
|
|
47815
47915
|
console.log(`Force re-indexing file (unchanged): ${local.rel}`);
|
|
47816
47916
|
}
|
|
47817
47917
|
const title = path5.basename(local.name, path5.extname(local.name));
|
|
47818
|
-
const uploaded = await
|
|
47918
|
+
const uploaded = await client2.uploadFile({
|
|
47819
47919
|
key,
|
|
47820
47920
|
content,
|
|
47821
47921
|
accessPolicies: [],
|
|
@@ -47926,8 +48026,8 @@ var init_knowledge = __esm({
|
|
|
47926
48026
|
* Look up the KB ID from Botpress
|
|
47927
48027
|
*/
|
|
47928
48028
|
async getKbId() {
|
|
47929
|
-
const
|
|
47930
|
-
const kbs = await
|
|
48029
|
+
const client2 = context.get("client")._inner;
|
|
48030
|
+
const kbs = await client2.list.knowledgeBases({}).collect();
|
|
47931
48031
|
const remoteKb = kbs.find((k) => k.name === this.name);
|
|
47932
48032
|
if (!remoteKb) {
|
|
47933
48033
|
throw new Error(`KB '${this.name}' not found in Botpress - run 'adk deploy' or approve KB sync in 'adk dev'`);
|