@botpress/runtime 1.11.9 → 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/library.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
|
|
|
@@ -34045,12 +34045,12 @@ If the question is not related to the knowledge bases, do NOT use this tool.`.tr
|
|
|
34045
34045
|
input: z2.string().describe("The query to search for.").min(1).max(1024),
|
|
34046
34046
|
output: z2.string().describe("The search results."),
|
|
34047
34047
|
handler: async (query) => {
|
|
34048
|
-
const
|
|
34048
|
+
const client2 = context.get("client");
|
|
34049
34049
|
const citations = context.get("citations");
|
|
34050
|
-
if (!
|
|
34050
|
+
if (!client2) {
|
|
34051
34051
|
throw new Error("Client is not available in this context. Make sure to run in a context with a client.");
|
|
34052
34052
|
}
|
|
34053
|
-
const { passages } = await
|
|
34053
|
+
const { passages } = await client2.searchFiles({
|
|
34054
34054
|
query,
|
|
34055
34055
|
withContext: true,
|
|
34056
34056
|
includeBreadcrumb: true,
|
|
@@ -34431,9 +34431,9 @@ var init_actions = __esm({
|
|
|
34431
34431
|
return handler;
|
|
34432
34432
|
}
|
|
34433
34433
|
let integrations;
|
|
34434
|
-
let
|
|
34434
|
+
let client2;
|
|
34435
34435
|
integrations ??= context.get("integrations", { optional: true });
|
|
34436
|
-
|
|
34436
|
+
client2 ??= context.get("client", { optional: true });
|
|
34437
34437
|
const integrationName = propertyName.replace("__", "/");
|
|
34438
34438
|
return new Proxy(
|
|
34439
34439
|
{},
|
|
@@ -34443,19 +34443,19 @@ var init_actions = __esm({
|
|
|
34443
34443
|
return void 0;
|
|
34444
34444
|
}
|
|
34445
34445
|
integrations ??= context.get("integrations", { optional: true });
|
|
34446
|
-
|
|
34446
|
+
client2 ??= context.get("client", { optional: true });
|
|
34447
34447
|
const integration = integrations.find((i) => i.alias === integrationName);
|
|
34448
34448
|
const actionDef = integration?.definition.actions?.[actionName];
|
|
34449
34449
|
const handler = async (params) => {
|
|
34450
34450
|
integrations ??= context.get("integrations", { optional: true });
|
|
34451
|
-
|
|
34451
|
+
client2 ??= context.get("client", { optional: true });
|
|
34452
34452
|
if (!integration || !actionDef) {
|
|
34453
34453
|
throw new Error(`Could not find integration "${integrationName}" and action "${actionName}"`);
|
|
34454
34454
|
}
|
|
34455
34455
|
if (!integration.definition.actions?.[actionName]) {
|
|
34456
34456
|
throw new Error(`Action "${actionName}" not found in integration "${integrationName}"`);
|
|
34457
34457
|
}
|
|
34458
|
-
return
|
|
34458
|
+
return client2.callAction({
|
|
34459
34459
|
type: `${integration.alias}:${actionName}`,
|
|
34460
34460
|
input: params
|
|
34461
34461
|
}).then((res) => res.output);
|
|
@@ -35107,7 +35107,7 @@ var init_workflow = __esm({
|
|
|
35107
35107
|
* @returns The workflow instance
|
|
35108
35108
|
*/
|
|
35109
35109
|
async getOrCreate(props) {
|
|
35110
|
-
const
|
|
35110
|
+
const client2 = context.get("client");
|
|
35111
35111
|
const statuses = props.statuses || ["pending", "in_progress", "listening", "paused"];
|
|
35112
35112
|
const validatedInput = this._inputSchema.parse(props.input);
|
|
35113
35113
|
const tags = {};
|
|
@@ -35125,10 +35125,10 @@ var init_workflow = __esm({
|
|
|
35125
35125
|
timeoutAt: new Date(Date.now() + (this.timeout ?? (0, import_ms.default)("5m"))).toISOString(),
|
|
35126
35126
|
...discriminator && { discriminateBy: { tags: discriminator } }
|
|
35127
35127
|
};
|
|
35128
|
-
let { workflow } = await
|
|
35128
|
+
let { workflow } = await client2._inner.getOrCreateWorkflow(createArgs);
|
|
35129
35129
|
if (props.key && !statuses.includes(workflow.status)) {
|
|
35130
|
-
await
|
|
35131
|
-
({ workflow } = await
|
|
35130
|
+
await client2._inner.deleteWorkflow({ id: workflow.id });
|
|
35131
|
+
({ workflow } = await client2._inner.getOrCreateWorkflow(createArgs));
|
|
35132
35132
|
}
|
|
35133
35133
|
return await BaseWorkflowInstance.load({
|
|
35134
35134
|
id: workflow.id,
|
|
@@ -35146,9 +35146,9 @@ var init_workflow = __esm({
|
|
|
35146
35146
|
* }
|
|
35147
35147
|
*/
|
|
35148
35148
|
async provide(event, data) {
|
|
35149
|
-
const
|
|
35149
|
+
const client2 = context.get("client");
|
|
35150
35150
|
const { workflowId, stepName } = event.payload;
|
|
35151
|
-
const state = createWorkflowExecutionState(
|
|
35151
|
+
const state = createWorkflowExecutionState(client2._inner, workflowId);
|
|
35152
35152
|
await state.load();
|
|
35153
35153
|
if (!state.value) {
|
|
35154
35154
|
throw new Error(`Workflow execution state not found for workflow ${workflowId}`);
|
|
@@ -35167,7 +35167,7 @@ var init_workflow = __esm({
|
|
|
35167
35167
|
}
|
|
35168
35168
|
state.value.revision++;
|
|
35169
35169
|
await state.save();
|
|
35170
|
-
await
|
|
35170
|
+
await client2.createEvent({
|
|
35171
35171
|
type: WorkflowContinueEvent.name,
|
|
35172
35172
|
workflowId,
|
|
35173
35173
|
payload: {}
|
|
@@ -35175,10 +35175,10 @@ var init_workflow = __esm({
|
|
|
35175
35175
|
}
|
|
35176
35176
|
async start(input) {
|
|
35177
35177
|
const validatedInput = this._inputSchema.parse(input);
|
|
35178
|
-
const
|
|
35178
|
+
const client2 = context.get("client");
|
|
35179
35179
|
const event = context.get("event", { optional: true });
|
|
35180
35180
|
const workflow = context.get("workflow", { optional: true });
|
|
35181
|
-
const res = await
|
|
35181
|
+
const res = await client2._inner.createWorkflow({
|
|
35182
35182
|
name: this.name,
|
|
35183
35183
|
status: event ? "in_progress" : "pending",
|
|
35184
35184
|
eventId: event?.id,
|
|
@@ -35432,8 +35432,8 @@ var init_action = __esm({
|
|
|
35432
35432
|
/**
|
|
35433
35433
|
* Execute the action with input validation and output validation
|
|
35434
35434
|
*/
|
|
35435
|
-
async execute({ input, client }) {
|
|
35436
|
-
return await this.handler({ input, client });
|
|
35435
|
+
async execute({ input, client: client2 }) {
|
|
35436
|
+
return await this.handler({ input, client: client2 });
|
|
35437
35437
|
}
|
|
35438
35438
|
};
|
|
35439
35439
|
}
|
|
@@ -35499,9 +35499,9 @@ var init_computed_columns = __esm({
|
|
|
35499
35499
|
isFinished: z9.boolean(),
|
|
35500
35500
|
rows: z9.array(z9.any())
|
|
35501
35501
|
}),
|
|
35502
|
-
handler: async ({ input, client }) => {
|
|
35502
|
+
handler: async ({ input, client: client2 }) => {
|
|
35503
35503
|
const { tableId, requests } = input;
|
|
35504
|
-
const { table: remoteTable } = await
|
|
35504
|
+
const { table: remoteTable } = await client2._inner.getTable({ table: tableId });
|
|
35505
35505
|
const table = adk.project.tables.find((x) => x.name === remoteTable.name);
|
|
35506
35506
|
async function computeRow(row, columnsToRecompute) {
|
|
35507
35507
|
const newRow = { id: row.id };
|
|
@@ -35574,7 +35574,35 @@ __export(adk_exports, {
|
|
|
35574
35574
|
register: () => register,
|
|
35575
35575
|
registerIntegration: () => registerIntegration
|
|
35576
35576
|
});
|
|
35577
|
+
import { BotSpecificClient } from "@botpress/sdk";
|
|
35577
35578
|
import { Zai } from "@botpress/zai";
|
|
35579
|
+
import { Cognitive as Cognitive2 } from "@botpress/cognitive";
|
|
35580
|
+
import { Client } from "@botpress/client";
|
|
35581
|
+
function getStandaloneCognitive() {
|
|
35582
|
+
return getSingleton("__ADK_GLOBAL_STANDALONE_COGNITIVE", () => {
|
|
35583
|
+
const token = process.env.BP_TOKEN || process.env.ADK_TOKEN;
|
|
35584
|
+
if (!token) {
|
|
35585
|
+
throw new Error(
|
|
35586
|
+
'No token found. Set BP_TOKEN or ADK_TOKEN environment variable, or run this script using "adk run".'
|
|
35587
|
+
);
|
|
35588
|
+
}
|
|
35589
|
+
const botId = process.env.ADK_BOT_ID;
|
|
35590
|
+
if (!botId) {
|
|
35591
|
+
throw new Error('No bot ID found. Set ADK_BOT_ID environment variable, or run this script using "adk run".');
|
|
35592
|
+
}
|
|
35593
|
+
const apiUrl = process.env.ADK_API_URL || "https://api.botpress.cloud";
|
|
35594
|
+
const vanillaClient = new Client({
|
|
35595
|
+
token,
|
|
35596
|
+
apiUrl,
|
|
35597
|
+
botId
|
|
35598
|
+
});
|
|
35599
|
+
const botClient = new BotSpecificClient(vanillaClient);
|
|
35600
|
+
return new Cognitive2({
|
|
35601
|
+
client: botClient,
|
|
35602
|
+
__experimental_beta: true
|
|
35603
|
+
});
|
|
35604
|
+
});
|
|
35605
|
+
}
|
|
35578
35606
|
function initialize(options) {
|
|
35579
35607
|
const state = getState();
|
|
35580
35608
|
if (state.initialized) {
|
|
@@ -35662,8 +35690,10 @@ var init_adk = __esm({
|
|
|
35662
35690
|
return Environment;
|
|
35663
35691
|
},
|
|
35664
35692
|
get zai() {
|
|
35693
|
+
const contextCognitive = context.get("cognitive", { optional: true });
|
|
35694
|
+
const cognitive = contextCognitive ?? getStandaloneCognitive();
|
|
35665
35695
|
return new Zai({
|
|
35666
|
-
client:
|
|
35696
|
+
client: cognitive,
|
|
35667
35697
|
modelId: Array.isArray(adk.project.config.defaultModels.zai) ? adk.project.config.defaultModels.zai[0] ?? "auto" : adk.project.config.defaultModels.zai
|
|
35668
35698
|
});
|
|
35669
35699
|
},
|
|
@@ -35688,6 +35718,29 @@ var init_adk = __esm({
|
|
|
35688
35718
|
conversations: state.primitives.conversations,
|
|
35689
35719
|
triggers: state.primitives.triggers
|
|
35690
35720
|
};
|
|
35721
|
+
},
|
|
35722
|
+
async execute(props) {
|
|
35723
|
+
const contextCognitive = context.get("cognitive", { optional: true });
|
|
35724
|
+
const cognitive = contextCognitive ?? getStandaloneCognitive();
|
|
35725
|
+
const defaultModel = adk.project.config.defaultModels.autonomous;
|
|
35726
|
+
const { execute: llmz_execute, getValue: getValue2 } = await import("llmz");
|
|
35727
|
+
return llmz_execute({
|
|
35728
|
+
client: cognitive,
|
|
35729
|
+
instructions: props.instructions,
|
|
35730
|
+
...props.tools && { tools: props.tools },
|
|
35731
|
+
...props.objects && { objects: props.objects },
|
|
35732
|
+
...props.exits && { exits: props.exits },
|
|
35733
|
+
...props.signal && { signal: props.signal },
|
|
35734
|
+
temperature: async (ctx) => props.temperature ? await getValue2(props.temperature, ctx) : 0.7,
|
|
35735
|
+
model: async (ctx) => props.model ? await getValue2(props.model, ctx) : defaultModel,
|
|
35736
|
+
options: { loop: props.iterations ?? 10 },
|
|
35737
|
+
...props.hooks?.onTrace && { onTrace: props.hooks.onTrace },
|
|
35738
|
+
...props.hooks?.onIterationEnd && { onIterationEnd: props.hooks.onIterationEnd },
|
|
35739
|
+
...props.hooks?.onBeforeTool && { onBeforeTool: props.hooks.onBeforeTool },
|
|
35740
|
+
...props.hooks?.onAfterTool && { onAfterTool: props.hooks.onAfterTool },
|
|
35741
|
+
...props.hooks?.onBeforeExecution && { onBeforeExecution: props.hooks.onBeforeExecution },
|
|
35742
|
+
...props.hooks?.onExit && { onExit: props.hooks.onExit }
|
|
35743
|
+
});
|
|
35691
35744
|
}
|
|
35692
35745
|
};
|
|
35693
35746
|
}
|
|
@@ -35729,7 +35782,7 @@ var init_workflow_utils = __esm({
|
|
|
35729
35782
|
init_runtime();
|
|
35730
35783
|
init_events();
|
|
35731
35784
|
updateWorkflow = async (props) => {
|
|
35732
|
-
const
|
|
35785
|
+
const client2 = context.get("client");
|
|
35733
35786
|
const workflowId = props.id;
|
|
35734
35787
|
const workflowsToUpdate = [];
|
|
35735
35788
|
const ctxWorkflow = context.get("workflow", { optional: true });
|
|
@@ -35748,7 +35801,7 @@ var init_workflow_utils = __esm({
|
|
|
35748
35801
|
if (workflowAlreadyDone) {
|
|
35749
35802
|
return { workflow: workflowAlreadyDone };
|
|
35750
35803
|
}
|
|
35751
|
-
const response = await
|
|
35804
|
+
const response = await client2.updateWorkflow(props);
|
|
35752
35805
|
for (const wf of workflowsToUpdate) {
|
|
35753
35806
|
Object.assign(wf, response.workflow);
|
|
35754
35807
|
}
|
|
@@ -35986,9 +36039,9 @@ var init_workflow_step = __esm({
|
|
|
35986
36039
|
async () => {
|
|
35987
36040
|
const remainingTime = context.get("runtime").getRemainingExecutionTimeInMs();
|
|
35988
36041
|
if (remainingTime - MIN_STEP_REMAINING_TIME_MS <= ms3 || ms3 >= 1e4) {
|
|
35989
|
-
const
|
|
36042
|
+
const client2 = context.get("client");
|
|
35990
36043
|
const workflowControlContext = context.get("workflowControlContext");
|
|
35991
|
-
await
|
|
36044
|
+
await client2.createEvent({
|
|
35992
36045
|
type: WorkflowContinueEvent.name,
|
|
35993
36046
|
payload: {},
|
|
35994
36047
|
workflowId: workflowControlContext.workflow.id,
|
|
@@ -36024,13 +36077,13 @@ var init_workflow_step = __esm({
|
|
|
36024
36077
|
return await _step(
|
|
36025
36078
|
name,
|
|
36026
36079
|
async () => {
|
|
36027
|
-
const
|
|
36080
|
+
const client2 = context.get("client");
|
|
36028
36081
|
const state = createWorkflowExecutionState(
|
|
36029
36082
|
context.get("client")._inner,
|
|
36030
36083
|
workflowControlContext.workflow.id
|
|
36031
36084
|
);
|
|
36032
36085
|
assert(state.value, "State is not loaded");
|
|
36033
|
-
const { workflow } = await
|
|
36086
|
+
const { workflow } = await client2.getWorkflow({ id: workflowId });
|
|
36034
36087
|
if (isWorkflowFinished(workflow.status)) {
|
|
36035
36088
|
return workflow;
|
|
36036
36089
|
}
|
|
@@ -36118,7 +36171,7 @@ var init_workflow_step = __esm({
|
|
|
36118
36171
|
actualStepName,
|
|
36119
36172
|
async () => {
|
|
36120
36173
|
const workflowControlContext = context.get("workflowControlContext");
|
|
36121
|
-
const
|
|
36174
|
+
const client2 = context.get("client");
|
|
36122
36175
|
if (!workflowControlContext.workflow.conversationId) {
|
|
36123
36176
|
throw new Error(`Cannot request data: workflow ${workflowControlContext.workflow.id} has no conversationId`);
|
|
36124
36177
|
}
|
|
@@ -36132,14 +36185,14 @@ var init_workflow_step = __esm({
|
|
|
36132
36185
|
`Request "${request}" not found in workflow "${workflowDef.name}". Available requests: ${Object.keys(workflowDef._requestsSchemas || {}).join(", ") || "none"}`
|
|
36133
36186
|
);
|
|
36134
36187
|
}
|
|
36135
|
-
const state = createWorkflowExecutionState(
|
|
36188
|
+
const state = createWorkflowExecutionState(client2._inner, workflowControlContext.workflow.id);
|
|
36136
36189
|
if (!state.value) {
|
|
36137
36190
|
throw new Error("Workflow execution state not loaded");
|
|
36138
36191
|
}
|
|
36139
36192
|
if (state.value.steps?.[actualStepName]?.output !== void 0) {
|
|
36140
36193
|
return requestSchema.parse(state.value.steps[actualStepName].output);
|
|
36141
36194
|
}
|
|
36142
|
-
await
|
|
36195
|
+
await client2.createEvent({
|
|
36143
36196
|
type: WorkflowDataRequestEvent2.name,
|
|
36144
36197
|
conversationId: workflowControlContext.workflow.conversationId,
|
|
36145
36198
|
payload: {
|
|
@@ -36169,7 +36222,7 @@ var init_workflow_step = __esm({
|
|
|
36169
36222
|
|
|
36170
36223
|
// src/primitives/workflow-cancellation-monitor.ts
|
|
36171
36224
|
function startWorkflowCancellationMonitor(props) {
|
|
36172
|
-
const { client, workflowId, workflowControlContext, abortSignal, pollIntervalMs = 1e3 } = props;
|
|
36225
|
+
const { client: client2, workflowId, workflowControlContext, abortSignal, pollIntervalMs = 1e3 } = props;
|
|
36173
36226
|
if (abortSignal.aborted) {
|
|
36174
36227
|
return () => {
|
|
36175
36228
|
};
|
|
@@ -36180,7 +36233,7 @@ function startWorkflowCancellationMonitor(props) {
|
|
|
36180
36233
|
return;
|
|
36181
36234
|
}
|
|
36182
36235
|
try {
|
|
36183
|
-
const { workflow } = await
|
|
36236
|
+
const { workflow } = await client2.getWorkflow({ id: workflowId });
|
|
36184
36237
|
const isTerminated = workflow.status === "cancelled" || workflow.status === "failed" || workflow.status === "timedout";
|
|
36185
36238
|
if (isTerminated) {
|
|
36186
36239
|
workflowControlContext.aborted = true;
|
|
@@ -36224,10 +36277,10 @@ function createStepSignal() {
|
|
|
36224
36277
|
[StepSymbol]: true
|
|
36225
36278
|
};
|
|
36226
36279
|
}
|
|
36227
|
-
function createWorkflowExecutionState(
|
|
36280
|
+
function createWorkflowExecutionState(client2, workflowId) {
|
|
36228
36281
|
return TrackedState.create({
|
|
36229
36282
|
type: "workflow",
|
|
36230
|
-
client,
|
|
36283
|
+
client: client2,
|
|
36231
36284
|
id: workflowId,
|
|
36232
36285
|
schema: workflowExecutionContextSchema,
|
|
36233
36286
|
name: BUILT_IN_STATES.workflowSteps
|
|
@@ -36285,18 +36338,18 @@ var init_workflow_instance = __esm({
|
|
|
36285
36338
|
TrackedState;
|
|
36286
36339
|
// @internal
|
|
36287
36340
|
TrackedTags;
|
|
36288
|
-
constructor(workflow,
|
|
36341
|
+
constructor(workflow, client2) {
|
|
36289
36342
|
const definition = adk.project.workflows.find((w) => w.name === workflow.name);
|
|
36290
36343
|
this.TrackedState = TrackedState.create({
|
|
36291
36344
|
type: "workflow",
|
|
36292
|
-
client:
|
|
36345
|
+
client: client2._inner,
|
|
36293
36346
|
id: workflow.id,
|
|
36294
36347
|
schema: definition?.stateSchema,
|
|
36295
36348
|
name: BUILT_IN_STATES.workflowState
|
|
36296
36349
|
});
|
|
36297
36350
|
this.TrackedTags = TrackedTags.create({
|
|
36298
36351
|
type: "workflow",
|
|
36299
|
-
client:
|
|
36352
|
+
client: client2._inner,
|
|
36300
36353
|
id: workflow.id,
|
|
36301
36354
|
initialTags: workflow.tags
|
|
36302
36355
|
});
|
|
@@ -36306,7 +36359,7 @@ var init_workflow_instance = __esm({
|
|
|
36306
36359
|
this.input = workflow.input;
|
|
36307
36360
|
this.createdAt = new Date(workflow.createdAt);
|
|
36308
36361
|
this.updatedAt = new Date(workflow.updatedAt);
|
|
36309
|
-
this.client =
|
|
36362
|
+
this.client = client2;
|
|
36310
36363
|
this.workflow = workflow;
|
|
36311
36364
|
}
|
|
36312
36365
|
get tags() {
|
|
@@ -36327,19 +36380,19 @@ var init_workflow_instance = __esm({
|
|
|
36327
36380
|
}
|
|
36328
36381
|
static Primitive = "workflow_instance";
|
|
36329
36382
|
static async load(props) {
|
|
36330
|
-
const
|
|
36331
|
-
const workflow = props.workflow ? props.workflow : await
|
|
36383
|
+
const client2 = context.get("client");
|
|
36384
|
+
const workflow = props.workflow ? props.workflow : await client2.getWorkflow({ id: props.id }).then((x) => x.workflow);
|
|
36332
36385
|
if (!adk.project.workflows.find((w) => w.name === workflow.name)) {
|
|
36333
36386
|
throw new Error(`No ADK Workflow definition found for "${workflow.name}"`);
|
|
36334
36387
|
}
|
|
36335
36388
|
TrackedTags.create({
|
|
36336
36389
|
type: "workflow",
|
|
36337
|
-
client:
|
|
36390
|
+
client: client2._inner,
|
|
36338
36391
|
id: workflow.id,
|
|
36339
36392
|
initialTags: workflow.tags
|
|
36340
36393
|
});
|
|
36341
36394
|
await TrackedTags.loadAll();
|
|
36342
|
-
return new _BaseWorkflowInstance(workflow,
|
|
36395
|
+
return new _BaseWorkflowInstance(workflow, client2);
|
|
36343
36396
|
}
|
|
36344
36397
|
/**
|
|
36345
36398
|
* Executes the workflow with the provided autonomous engine configuration.
|
|
@@ -36376,8 +36429,8 @@ var init_workflow_instance = __esm({
|
|
|
36376
36429
|
* }
|
|
36377
36430
|
*/
|
|
36378
36431
|
async provide(request, data) {
|
|
36379
|
-
const
|
|
36380
|
-
const state = createWorkflowExecutionState(
|
|
36432
|
+
const client2 = context.get("client");
|
|
36433
|
+
const state = createWorkflowExecutionState(client2._inner, this.id);
|
|
36381
36434
|
await state.load();
|
|
36382
36435
|
if (!state.value) {
|
|
36383
36436
|
throw new Error(`Workflow execution state not found for workflow ${this.id}`);
|
|
@@ -36396,7 +36449,7 @@ var init_workflow_instance = __esm({
|
|
|
36396
36449
|
}
|
|
36397
36450
|
state.value.revision++;
|
|
36398
36451
|
await state.save();
|
|
36399
|
-
await
|
|
36452
|
+
await client2.createEvent({
|
|
36400
36453
|
type: WorkflowContinueEvent.name,
|
|
36401
36454
|
workflowId: this.id,
|
|
36402
36455
|
payload: {}
|
|
@@ -36447,8 +36500,8 @@ var init_workflow_instance = __esm({
|
|
|
36447
36500
|
}
|
|
36448
36501
|
};
|
|
36449
36502
|
try {
|
|
36450
|
-
const
|
|
36451
|
-
const workflowExecutionState = createWorkflowExecutionState(
|
|
36503
|
+
const client2 = context.get("client");
|
|
36504
|
+
const workflowExecutionState = createWorkflowExecutionState(client2._inner, this.id);
|
|
36452
36505
|
await workflowExecutionState.load();
|
|
36453
36506
|
await this.TrackedState.load();
|
|
36454
36507
|
abortSignal.throwIfAborted();
|
|
@@ -36470,7 +36523,7 @@ var init_workflow_instance = __esm({
|
|
|
36470
36523
|
}
|
|
36471
36524
|
context.set("workflowControlContext", workflowControlContext);
|
|
36472
36525
|
const stopCancellationMonitor = startWorkflowCancellationMonitor({
|
|
36473
|
-
client:
|
|
36526
|
+
client: client2._inner,
|
|
36474
36527
|
workflowId: this.id,
|
|
36475
36528
|
workflowControlContext,
|
|
36476
36529
|
abortSignal
|
|
@@ -36835,14 +36888,14 @@ var init_tracked_state = __esm({
|
|
|
36835
36888
|
}
|
|
36836
36889
|
static async loadAll() {
|
|
36837
36890
|
await span("state.loadAll", {}, async () => {
|
|
36838
|
-
const
|
|
36891
|
+
const client2 = context.get("client")._inner;
|
|
36839
36892
|
const botId = context.get("botId", { optional: true });
|
|
36840
36893
|
const user2 = context.get("user", { optional: true });
|
|
36841
36894
|
const conversation = context.get("conversation", { optional: true });
|
|
36842
36895
|
const { adk: adk2 } = await Promise.resolve().then(() => (init_adk(), adk_exports));
|
|
36843
36896
|
if (botId) {
|
|
36844
36897
|
_TrackedState.create({
|
|
36845
|
-
client,
|
|
36898
|
+
client: client2,
|
|
36846
36899
|
name: BUILT_IN_STATES.bot,
|
|
36847
36900
|
type: "bot",
|
|
36848
36901
|
id: botId,
|
|
@@ -36851,7 +36904,7 @@ var init_tracked_state = __esm({
|
|
|
36851
36904
|
}
|
|
36852
36905
|
if (user2) {
|
|
36853
36906
|
_TrackedState.create({
|
|
36854
|
-
client,
|
|
36907
|
+
client: client2,
|
|
36855
36908
|
name: BUILT_IN_STATES.user,
|
|
36856
36909
|
type: "user",
|
|
36857
36910
|
id: user2.id,
|
|
@@ -36868,7 +36921,7 @@ var init_tracked_state = __esm({
|
|
|
36868
36921
|
}
|
|
36869
36922
|
});
|
|
36870
36923
|
_TrackedState.create({
|
|
36871
|
-
client,
|
|
36924
|
+
client: client2,
|
|
36872
36925
|
name: BUILT_IN_STATES.conversation,
|
|
36873
36926
|
type: "conversation",
|
|
36874
36927
|
id: conversation.id,
|
|
@@ -37175,7 +37228,7 @@ var init_events2 = __esm({
|
|
|
37175
37228
|
// src/runtime/context/handlers.ts
|
|
37176
37229
|
import * as sdk from "@botpress/sdk";
|
|
37177
37230
|
import { CitationsManager } from "llmz";
|
|
37178
|
-
import { Client } from "@botpress/client";
|
|
37231
|
+
import { Client as Client2 } from "@botpress/client";
|
|
37179
37232
|
import { ulid as ulid2 } from "ulid";
|
|
37180
37233
|
var init_handlers = __esm({
|
|
37181
37234
|
"src/runtime/context/handlers.ts"() {
|
|
@@ -37899,12 +37952,12 @@ var init_conversation_instance = __esm({
|
|
|
37899
37952
|
TrackedState;
|
|
37900
37953
|
// @internal
|
|
37901
37954
|
TrackedTags;
|
|
37902
|
-
constructor(conversation,
|
|
37955
|
+
constructor(conversation, client2) {
|
|
37903
37956
|
this.id = conversation.id;
|
|
37904
37957
|
this.channel = `${conversation.integration}.${conversation.channel}`;
|
|
37905
37958
|
this.integration = conversation.integration;
|
|
37906
37959
|
this.conversation = conversation;
|
|
37907
|
-
this.client =
|
|
37960
|
+
this.client = client2;
|
|
37908
37961
|
const states = context.get("states", { optional: true });
|
|
37909
37962
|
const existingState = states?.find(
|
|
37910
37963
|
(s) => s.type === "conversation" && s.id === conversation.id && s.name === BUILT_IN_STATES.conversation
|
|
@@ -37918,7 +37971,7 @@ var init_conversation_instance = __esm({
|
|
|
37918
37971
|
const tags = TrackedTags.create({
|
|
37919
37972
|
type: "conversation",
|
|
37920
37973
|
id: conversation.id,
|
|
37921
|
-
client:
|
|
37974
|
+
client: client2._inner,
|
|
37922
37975
|
initialTags: conversation.tags
|
|
37923
37976
|
});
|
|
37924
37977
|
this.TrackedTags = tags;
|
|
@@ -38086,9 +38139,9 @@ var init_conversation = __esm({
|
|
|
38086
38139
|
const message = context.get("message", { optional: true });
|
|
38087
38140
|
const event = context.get("event", { optional: true });
|
|
38088
38141
|
const chat = context.get("chat");
|
|
38089
|
-
const
|
|
38142
|
+
const client2 = context.get("client");
|
|
38090
38143
|
const botpressConversation = context.get("conversation");
|
|
38091
|
-
const conversationInstance = new BaseConversationInstance(botpressConversation,
|
|
38144
|
+
const conversationInstance = new BaseConversationInstance(botpressConversation, client2);
|
|
38092
38145
|
const startTypingPromise = conversationInstance.startTyping().catch(() => {
|
|
38093
38146
|
});
|
|
38094
38147
|
let type;
|
|
@@ -38125,7 +38178,7 @@ var init_conversation = __esm({
|
|
|
38125
38178
|
if (controller.signal.aborted) {
|
|
38126
38179
|
return;
|
|
38127
38180
|
}
|
|
38128
|
-
const { events } = await
|
|
38181
|
+
const { events } = await client2.listEvents({
|
|
38129
38182
|
conversationId: conversationInstance.id,
|
|
38130
38183
|
status: "pending"
|
|
38131
38184
|
});
|
|
@@ -38198,7 +38251,7 @@ var init_conversation = __esm({
|
|
|
38198
38251
|
request: requestObject,
|
|
38199
38252
|
conversation: conversationInstance,
|
|
38200
38253
|
state: stateProxy,
|
|
38201
|
-
client,
|
|
38254
|
+
client: client2,
|
|
38202
38255
|
execute
|
|
38203
38256
|
});
|
|
38204
38257
|
controller.abort();
|
|
@@ -40463,7 +40516,7 @@ var init_source_website = __esm({
|
|
|
40463
40516
|
return createSyncWorkflow({
|
|
40464
40517
|
type: "website",
|
|
40465
40518
|
state: State,
|
|
40466
|
-
async handler({ input, step: step2, state, client }) {
|
|
40519
|
+
async handler({ input, step: step2, state, client: client2 }) {
|
|
40467
40520
|
const crypto3 = await import("crypto");
|
|
40468
40521
|
console.log(
|
|
40469
40522
|
`Starting sync for WebsiteSource [${this.id}] in mode [${this.mode}, maxPages=${this.maxPages}, maxDepth=${this.maxDepth}, baseUrl=${this.baseUrl}, sitemapUrl=${this.sitemapUrl}]`
|
|
@@ -40484,7 +40537,7 @@ var init_source_website = __esm({
|
|
|
40484
40537
|
console.log(`Will process up to ${this.maxPages} pages`);
|
|
40485
40538
|
const existingFiles = await step2(
|
|
40486
40539
|
"list existing files",
|
|
40487
|
-
() =>
|
|
40540
|
+
() => client2._inner.list.files({
|
|
40488
40541
|
tags
|
|
40489
40542
|
}).collect()
|
|
40490
40543
|
);
|
|
@@ -40495,7 +40548,7 @@ var init_source_website = __esm({
|
|
|
40495
40548
|
await step2.map(
|
|
40496
40549
|
"deleting all existing files for recrawl",
|
|
40497
40550
|
existingFiles,
|
|
40498
|
-
(f) =>
|
|
40551
|
+
(f) => client2.deleteFile({ id: f.id }).catch(() => null),
|
|
40499
40552
|
{ concurrency: 5 }
|
|
40500
40553
|
);
|
|
40501
40554
|
console.log(`\u2705 Deleted ${existingFiles.length} files, starting fresh crawl`);
|
|
@@ -40527,7 +40580,7 @@ var init_source_website = __esm({
|
|
|
40527
40580
|
const deleted = await step2.map(
|
|
40528
40581
|
"deleting removed urls",
|
|
40529
40582
|
toRemove,
|
|
40530
|
-
(f) =>
|
|
40583
|
+
(f) => client2.deleteFile({ id: f.id }).catch(() => null).then(
|
|
40531
40584
|
() => ({
|
|
40532
40585
|
file: f.id,
|
|
40533
40586
|
name: f.key,
|
|
@@ -40552,7 +40605,7 @@ var init_source_website = __esm({
|
|
|
40552
40605
|
contentType = content.includes("<html") ? "text/html" : "text/markdown";
|
|
40553
40606
|
}
|
|
40554
40607
|
const key = `data_source://${this.type}/${this.id}/${encodeURIComponent(url2)}`;
|
|
40555
|
-
const uploaded = await
|
|
40608
|
+
const uploaded = await client2.uploadFile({
|
|
40556
40609
|
key,
|
|
40557
40610
|
content,
|
|
40558
40611
|
contentType,
|
|
@@ -40612,7 +40665,7 @@ var init_source_website = __esm({
|
|
|
40612
40665
|
await step2("register web page source", async () => {
|
|
40613
40666
|
try {
|
|
40614
40667
|
const botId = context.get("botId");
|
|
40615
|
-
const getStateResult = await
|
|
40668
|
+
const getStateResult = await client2._inner.getState({ id: botId, type: "bot", name: "dsData" }).catch(() => ({ state: null }));
|
|
40616
40669
|
const freshState = getStateResult.state;
|
|
40617
40670
|
const existingPayload = freshState?.payload || {};
|
|
40618
40671
|
const kbPayload = existingPayload[input.kbId] || {};
|
|
@@ -40634,7 +40687,7 @@ var init_source_website = __esm({
|
|
|
40634
40687
|
data: { websiteUrl, pages: [], indexingJobs: [] }
|
|
40635
40688
|
};
|
|
40636
40689
|
existingPayload[input.kbId] = kbPayload;
|
|
40637
|
-
await
|
|
40690
|
+
await client2._inner.setState({
|
|
40638
40691
|
id: botId,
|
|
40639
40692
|
type: "bot",
|
|
40640
40693
|
name: "dsData",
|
|
@@ -47512,7 +47565,7 @@ var init_source_directory = __esm({
|
|
|
47512
47565
|
return createSyncWorkflow({
|
|
47513
47566
|
type: "directory",
|
|
47514
47567
|
state: z24.object({}),
|
|
47515
|
-
handler: async ({ input, step: step2, client }) => {
|
|
47568
|
+
handler: async ({ input, step: step2, client: client2 }) => {
|
|
47516
47569
|
if (!adk.environment.isDevelopment()) {
|
|
47517
47570
|
console.log("Directory ingestion is only supported in development environment");
|
|
47518
47571
|
return {
|
|
@@ -47564,7 +47617,7 @@ var init_source_directory = __esm({
|
|
|
47564
47617
|
);
|
|
47565
47618
|
const existingFiles = await step2(
|
|
47566
47619
|
"list existing files",
|
|
47567
|
-
() =>
|
|
47620
|
+
() => client2._inner.list.files({
|
|
47568
47621
|
tags
|
|
47569
47622
|
}).collect()
|
|
47570
47623
|
);
|
|
@@ -47578,7 +47631,7 @@ var init_source_directory = __esm({
|
|
|
47578
47631
|
const deleted = await step2.map(
|
|
47579
47632
|
"deleting removed files",
|
|
47580
47633
|
toRemove,
|
|
47581
|
-
(f) =>
|
|
47634
|
+
(f) => client2.deleteFile({ id: f.id }).catch(() => null).then(
|
|
47582
47635
|
() => ({
|
|
47583
47636
|
file: f.id,
|
|
47584
47637
|
name: f.key,
|
|
@@ -47592,7 +47645,7 @@ var init_source_directory = __esm({
|
|
|
47592
47645
|
const key = `data_source://${this.type}/${this.id}/${local.rel}`;
|
|
47593
47646
|
const content = await fs3.readFile(local.abs);
|
|
47594
47647
|
const hash = crypto3.createHash("sha256").update(content).digest("hex");
|
|
47595
|
-
const { file } = await
|
|
47648
|
+
const { file } = await client2.getFile({ id: key }).catch(() => ({ file: null }));
|
|
47596
47649
|
if (!input.force && file?.metadata?.hash === hash) {
|
|
47597
47650
|
console.log(`Skipping unchanged file: ${local.rel}`);
|
|
47598
47651
|
return null;
|
|
@@ -47601,7 +47654,7 @@ var init_source_directory = __esm({
|
|
|
47601
47654
|
console.log(`Force re-indexing file (unchanged): ${local.rel}`);
|
|
47602
47655
|
}
|
|
47603
47656
|
const title = path4.basename(local.name, path4.extname(local.name));
|
|
47604
|
-
const uploaded = await
|
|
47657
|
+
const uploaded = await client2.uploadFile({
|
|
47605
47658
|
key,
|
|
47606
47659
|
content,
|
|
47607
47660
|
accessPolicies: [],
|
|
@@ -47712,8 +47765,8 @@ var init_knowledge = __esm({
|
|
|
47712
47765
|
* Look up the KB ID from Botpress
|
|
47713
47766
|
*/
|
|
47714
47767
|
async getKbId() {
|
|
47715
|
-
const
|
|
47716
|
-
const kbs = await
|
|
47768
|
+
const client2 = context.get("client")._inner;
|
|
47769
|
+
const kbs = await client2.list.knowledgeBases({}).collect();
|
|
47717
47770
|
const remoteKb = kbs.find((k) => k.name === this.name);
|
|
47718
47771
|
if (!remoteKb) {
|
|
47719
47772
|
throw new Error(`KB '${this.name}' not found in Botpress - run 'adk deploy' or approve KB sync in 'adk dev'`);
|
|
@@ -48206,7 +48259,7 @@ var init_tracked_tags = __esm({
|
|
|
48206
48259
|
}
|
|
48207
48260
|
static async loadAll() {
|
|
48208
48261
|
await span("tags.loadAll", {}, async () => {
|
|
48209
|
-
const
|
|
48262
|
+
const client2 = context.get("client")._inner;
|
|
48210
48263
|
const bot2 = context.get("bot", { optional: true });
|
|
48211
48264
|
const user2 = context.get("user", { optional: true });
|
|
48212
48265
|
const conversation = context.get("conversation", { optional: true });
|
|
@@ -48214,7 +48267,7 @@ var init_tracked_tags = __esm({
|
|
|
48214
48267
|
if (bot2) {
|
|
48215
48268
|
const botTags = bot2.tags;
|
|
48216
48269
|
_TrackedTags.create({
|
|
48217
|
-
client,
|
|
48270
|
+
client: client2,
|
|
48218
48271
|
type: "bot",
|
|
48219
48272
|
id: bot2.id,
|
|
48220
48273
|
...botTags && { initialTags: botTags }
|
|
@@ -48223,7 +48276,7 @@ var init_tracked_tags = __esm({
|
|
|
48223
48276
|
if (user2) {
|
|
48224
48277
|
const userTags = user2.tags;
|
|
48225
48278
|
_TrackedTags.create({
|
|
48226
|
-
client,
|
|
48279
|
+
client: client2,
|
|
48227
48280
|
type: "user",
|
|
48228
48281
|
id: user2.id,
|
|
48229
48282
|
...userTags && { initialTags: userTags }
|
|
@@ -48232,7 +48285,7 @@ var init_tracked_tags = __esm({
|
|
|
48232
48285
|
if (conversation) {
|
|
48233
48286
|
const conversationTags = conversation.tags;
|
|
48234
48287
|
_TrackedTags.create({
|
|
48235
|
-
client,
|
|
48288
|
+
client: client2,
|
|
48236
48289
|
type: "conversation",
|
|
48237
48290
|
id: conversation.id,
|
|
48238
48291
|
...conversationTags && { initialTags: conversationTags }
|
|
@@ -48241,7 +48294,7 @@ var init_tracked_tags = __esm({
|
|
|
48241
48294
|
if (workflow) {
|
|
48242
48295
|
const workflowTags = workflow.tags;
|
|
48243
48296
|
_TrackedTags.create({
|
|
48244
|
-
client,
|
|
48297
|
+
client: client2,
|
|
48245
48298
|
type: "workflow",
|
|
48246
48299
|
id: workflow.id,
|
|
48247
48300
|
...workflowTags && { initialTags: workflowTags }
|
|
@@ -48381,6 +48434,51 @@ var init_tracked_tags = __esm({
|
|
|
48381
48434
|
}
|
|
48382
48435
|
});
|
|
48383
48436
|
|
|
48437
|
+
// src/runtime/client.ts
|
|
48438
|
+
import { Client as Client3 } from "@botpress/client";
|
|
48439
|
+
function getStandaloneClient() {
|
|
48440
|
+
return getSingleton("__ADK_GLOBAL_STANDALONE_CLIENT", () => {
|
|
48441
|
+
const token = process.env.BP_TOKEN || process.env.ADK_TOKEN;
|
|
48442
|
+
if (!token) {
|
|
48443
|
+
throw new Error(
|
|
48444
|
+
'No token found. Set BP_TOKEN or ADK_TOKEN environment variable, or run this script using "adk run".'
|
|
48445
|
+
);
|
|
48446
|
+
}
|
|
48447
|
+
const botId = process.env.ADK_BOT_ID;
|
|
48448
|
+
if (!botId) {
|
|
48449
|
+
throw new Error(
|
|
48450
|
+
'No bot ID found. Set ADK_BOT_ID environment variable, or run this script using "adk run".'
|
|
48451
|
+
);
|
|
48452
|
+
}
|
|
48453
|
+
const apiUrl = process.env.ADK_API_URL || "https://api.botpress.cloud";
|
|
48454
|
+
return new Client3({
|
|
48455
|
+
token,
|
|
48456
|
+
apiUrl,
|
|
48457
|
+
botId
|
|
48458
|
+
});
|
|
48459
|
+
});
|
|
48460
|
+
}
|
|
48461
|
+
var client;
|
|
48462
|
+
var init_client = __esm({
|
|
48463
|
+
"src/runtime/client.ts"() {
|
|
48464
|
+
"use strict";
|
|
48465
|
+
init_define_BUILD();
|
|
48466
|
+
init_define_PACKAGE_VERSIONS();
|
|
48467
|
+
init_context();
|
|
48468
|
+
init_singletons();
|
|
48469
|
+
client = new Proxy({}, {
|
|
48470
|
+
get(_target, prop) {
|
|
48471
|
+
const contextClient = context.get("client", { optional: true });
|
|
48472
|
+
if (contextClient) {
|
|
48473
|
+
return contextClient[prop];
|
|
48474
|
+
}
|
|
48475
|
+
const standaloneClient = getStandaloneClient();
|
|
48476
|
+
return standaloneClient[prop];
|
|
48477
|
+
}
|
|
48478
|
+
});
|
|
48479
|
+
}
|
|
48480
|
+
});
|
|
48481
|
+
|
|
48384
48482
|
// src/runtime/index.ts
|
|
48385
48483
|
var init_runtime2 = __esm({
|
|
48386
48484
|
"src/runtime/index.ts"() {
|
|
@@ -48399,18 +48497,20 @@ var init_runtime2 = __esm({
|
|
|
48399
48497
|
init_tracked_tags();
|
|
48400
48498
|
init_actions();
|
|
48401
48499
|
init_events2();
|
|
48500
|
+
init_client();
|
|
48402
48501
|
}
|
|
48403
48502
|
});
|
|
48404
48503
|
|
|
48405
48504
|
// src/library.ts
|
|
48406
48505
|
import { z as z27 } from "@botpress/sdk";
|
|
48407
|
-
import { Cognitive as
|
|
48506
|
+
import { Cognitive as Cognitive3 } from "@botpress/cognitive";
|
|
48408
48507
|
import { Zai as Zai2 } from "@botpress/zai";
|
|
48409
48508
|
var init_library = __esm({
|
|
48410
48509
|
"src/library.ts"() {
|
|
48411
48510
|
init_define_BUILD();
|
|
48412
48511
|
init_define_PACKAGE_VERSIONS();
|
|
48413
48512
|
init_runtime2();
|
|
48513
|
+
init_client();
|
|
48414
48514
|
init_primitives();
|
|
48415
48515
|
init_workflow_utils();
|
|
48416
48516
|
init_events();
|
|
@@ -48429,7 +48529,7 @@ export {
|
|
|
48429
48529
|
Action,
|
|
48430
48530
|
Autonomous,
|
|
48431
48531
|
BaseConversationInstance,
|
|
48432
|
-
|
|
48532
|
+
Cognitive3 as Cognitive,
|
|
48433
48533
|
BaseConversation as Conversation,
|
|
48434
48534
|
DataSource2 as DataSource,
|
|
48435
48535
|
Errors,
|
|
@@ -48443,6 +48543,7 @@ export {
|
|
|
48443
48543
|
actions,
|
|
48444
48544
|
adk,
|
|
48445
48545
|
bot,
|
|
48546
|
+
client,
|
|
48446
48547
|
configuration,
|
|
48447
48548
|
context,
|
|
48448
48549
|
defineConfig,
|