@q1k-oss/behaviour-tree-workflows 0.0.2 → 0.0.4
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/ai-sdk/index.cjs +296 -0
- package/dist/ai-sdk/index.d.cts +82 -0
- package/dist/ai-sdk/index.d.ts +82 -0
- package/dist/ai-sdk/index.js +269 -0
- package/dist/index.cjs +516 -12
- package/dist/index.d.cts +370 -821
- package/dist/index.d.ts +370 -821
- package/dist/index.js +510 -12
- package/dist/types-BJPlUisg.d.cts +931 -0
- package/dist/types-BJPlUisg.d.ts +931 -0
- package/package.json +48 -3
package/dist/index.js
CHANGED
|
@@ -2218,6 +2218,52 @@ var SoftAssert = class extends DecoratorNode {
|
|
|
2218
2218
|
}
|
|
2219
2219
|
};
|
|
2220
2220
|
|
|
2221
|
+
// src/decorators/streaming-sink.ts
|
|
2222
|
+
var StreamingSink = class extends DecoratorNode {
|
|
2223
|
+
channelId;
|
|
2224
|
+
channelKey;
|
|
2225
|
+
constructor(config) {
|
|
2226
|
+
super(config);
|
|
2227
|
+
if (!config.channelId && !config.channelKey) {
|
|
2228
|
+
throw new ConfigurationError(
|
|
2229
|
+
"StreamingSink requires either channelId or channelKey"
|
|
2230
|
+
);
|
|
2231
|
+
}
|
|
2232
|
+
this.channelId = config.channelId;
|
|
2233
|
+
this.channelKey = config.channelKey;
|
|
2234
|
+
}
|
|
2235
|
+
async executeTick(context) {
|
|
2236
|
+
if (!this.child) {
|
|
2237
|
+
throw new ConfigurationError(
|
|
2238
|
+
`${this.name}: Decorator must have a child`
|
|
2239
|
+
);
|
|
2240
|
+
}
|
|
2241
|
+
let resolvedChannelId = this.channelId;
|
|
2242
|
+
if (this.channelKey) {
|
|
2243
|
+
const varCtx = {
|
|
2244
|
+
blackboard: context.blackboard,
|
|
2245
|
+
input: context.input,
|
|
2246
|
+
testData: context.testData
|
|
2247
|
+
};
|
|
2248
|
+
resolvedChannelId = resolveValue(this.channelKey, varCtx);
|
|
2249
|
+
}
|
|
2250
|
+
const previousValue = context.blackboard.get("__streamChannelId");
|
|
2251
|
+
context.blackboard.set("__streamChannelId", resolvedChannelId);
|
|
2252
|
+
this.log(`Set streaming channel: ${resolvedChannelId}`);
|
|
2253
|
+
try {
|
|
2254
|
+
const childStatus = await this.child.tick(context);
|
|
2255
|
+
this._status = childStatus;
|
|
2256
|
+
return childStatus;
|
|
2257
|
+
} finally {
|
|
2258
|
+
if (previousValue !== void 0) {
|
|
2259
|
+
context.blackboard.set("__streamChannelId", previousValue);
|
|
2260
|
+
} else {
|
|
2261
|
+
context.blackboard.delete("__streamChannelId");
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
};
|
|
2266
|
+
|
|
2221
2267
|
// src/decorators/timeout.ts
|
|
2222
2268
|
import { CancellationScope, isCancellation } from "@temporalio/workflow";
|
|
2223
2269
|
var Timeout = class extends DecoratorNode {
|
|
@@ -2495,8 +2541,81 @@ var humanTaskSchema = createNodeSchema("HumanTask", {
|
|
|
2495
2541
|
outputKey: z5.string().optional()
|
|
2496
2542
|
});
|
|
2497
2543
|
|
|
2498
|
-
// src/
|
|
2544
|
+
// src/utilities/set-variable.schema.ts
|
|
2499
2545
|
import { z as z6 } from "zod";
|
|
2546
|
+
var setVariableSchema = createNodeSchema("SetVariable", {
|
|
2547
|
+
key: z6.string().min(1, "key is required"),
|
|
2548
|
+
value: z6.unknown()
|
|
2549
|
+
});
|
|
2550
|
+
|
|
2551
|
+
// src/actions/llm-tool-call.schema.ts
|
|
2552
|
+
import { z as z7 } from "zod";
|
|
2553
|
+
var toolDefinitionSchema = z7.object({
|
|
2554
|
+
name: z7.string().min(1),
|
|
2555
|
+
description: z7.string().min(1),
|
|
2556
|
+
inputSchema: z7.record(z7.string(), z7.unknown())
|
|
2557
|
+
});
|
|
2558
|
+
var llmToolCallSchema = createNodeSchema("LLMToolCall", {
|
|
2559
|
+
provider: z7.enum(["anthropic", "openai", "google", "ollama"]),
|
|
2560
|
+
model: z7.string().min(1, "Model is required"),
|
|
2561
|
+
systemPrompt: z7.string().optional(),
|
|
2562
|
+
messagesKey: z7.string().min(1, "messagesKey is required"),
|
|
2563
|
+
userMessageKey: z7.string().optional(),
|
|
2564
|
+
toolsKey: z7.string().optional(),
|
|
2565
|
+
tools: z7.array(toolDefinitionSchema).optional(),
|
|
2566
|
+
temperature: z7.number().min(0).max(2).optional(),
|
|
2567
|
+
maxTokens: z7.number().int().positive().optional(),
|
|
2568
|
+
outputKey: z7.string().min(1, "outputKey is required")
|
|
2569
|
+
});
|
|
2570
|
+
|
|
2571
|
+
// src/actions/tool-executor.schema.ts
|
|
2572
|
+
import { z as z8 } from "zod";
|
|
2573
|
+
var toolExecutorSchema = createNodeSchema("ToolExecutor", {
|
|
2574
|
+
responseKey: z8.string().min(1, "responseKey is required"),
|
|
2575
|
+
messagesKey: z8.string().min(1, "messagesKey is required"),
|
|
2576
|
+
outputKey: z8.string().optional()
|
|
2577
|
+
});
|
|
2578
|
+
|
|
2579
|
+
// src/actions/wait-for-signal.schema.ts
|
|
2580
|
+
import { z as z9 } from "zod";
|
|
2581
|
+
var waitForSignalSchema = createNodeSchema("WaitForSignal", {
|
|
2582
|
+
signalName: z9.string().min(1, "signalName is required"),
|
|
2583
|
+
signalKey: z9.string().optional(),
|
|
2584
|
+
timeoutMs: z9.number().int().positive().optional().default(864e5),
|
|
2585
|
+
outputKey: z9.string().min(1, "outputKey is required")
|
|
2586
|
+
});
|
|
2587
|
+
|
|
2588
|
+
// src/actions/tool-router.schema.ts
|
|
2589
|
+
import { z as z10 } from "zod";
|
|
2590
|
+
var toolDefinitionSchema2 = z10.object({
|
|
2591
|
+
name: z10.string().min(1),
|
|
2592
|
+
description: z10.string().min(1),
|
|
2593
|
+
inputSchema: z10.record(z10.string(), z10.unknown())
|
|
2594
|
+
});
|
|
2595
|
+
var ruleSchema = z10.object({
|
|
2596
|
+
pattern: z10.string().min(1),
|
|
2597
|
+
toolSets: z10.array(z10.string().min(1)).min(1)
|
|
2598
|
+
});
|
|
2599
|
+
var toolRouterSchema = createNodeSchema("ToolRouter", {
|
|
2600
|
+
intentKey: z10.string().min(1, "intentKey is required"),
|
|
2601
|
+
toolSets: z10.record(z10.string(), z10.array(toolDefinitionSchema2)),
|
|
2602
|
+
defaultTools: z10.array(z10.string()).optional(),
|
|
2603
|
+
rules: z10.array(ruleSchema).optional(),
|
|
2604
|
+
outputKey: z10.string().min(1, "outputKey is required")
|
|
2605
|
+
});
|
|
2606
|
+
|
|
2607
|
+
// src/decorators/streaming-sink.schema.ts
|
|
2608
|
+
import { z as z11 } from "zod";
|
|
2609
|
+
var streamingSinkSchema = createNodeSchema("StreamingSink", {
|
|
2610
|
+
channelId: z11.string().optional(),
|
|
2611
|
+
channelKey: z11.string().optional()
|
|
2612
|
+
}).refine(
|
|
2613
|
+
(data) => data.channelId || data.channelKey,
|
|
2614
|
+
{ message: "Either channelId or channelKey must be provided" }
|
|
2615
|
+
);
|
|
2616
|
+
|
|
2617
|
+
// src/schemas/validation.ts
|
|
2618
|
+
import { z as z12 } from "zod";
|
|
2500
2619
|
function zodErrorToConfigurationError(error, nodeType, nodeId) {
|
|
2501
2620
|
const nodeIdentifier = nodeId ? `${nodeType}:${nodeId}` : nodeType;
|
|
2502
2621
|
const issues = error.issues.map((issue) => {
|
|
@@ -2512,7 +2631,7 @@ function validateConfiguration(schema, config, nodeType, nodeId) {
|
|
|
2512
2631
|
try {
|
|
2513
2632
|
return schema.parse(config);
|
|
2514
2633
|
} catch (error) {
|
|
2515
|
-
if (error instanceof
|
|
2634
|
+
if (error instanceof z12.ZodError) {
|
|
2516
2635
|
throw zodErrorToConfigurationError(error, nodeType, nodeId);
|
|
2517
2636
|
}
|
|
2518
2637
|
throw error;
|
|
@@ -2531,14 +2650,14 @@ function safeValidateConfiguration(schema, config, nodeType, nodeId) {
|
|
|
2531
2650
|
}
|
|
2532
2651
|
|
|
2533
2652
|
// src/schemas/tree-definition.schema.ts
|
|
2534
|
-
import { z as
|
|
2535
|
-
var treeDefSchemaObject =
|
|
2536
|
-
type:
|
|
2537
|
-
id:
|
|
2538
|
-
name:
|
|
2539
|
-
props:
|
|
2540
|
-
children:
|
|
2541
|
-
|
|
2653
|
+
import { z as z13 } from "zod";
|
|
2654
|
+
var treeDefSchemaObject = z13.object({
|
|
2655
|
+
type: z13.string().min(1, "Node type is required"),
|
|
2656
|
+
id: z13.string().optional(),
|
|
2657
|
+
name: z13.string().optional(),
|
|
2658
|
+
props: z13.record(z13.string(), z13.unknown()).optional(),
|
|
2659
|
+
children: z13.array(
|
|
2660
|
+
z13.lazy(() => treeDefinitionSchema)
|
|
2542
2661
|
).optional()
|
|
2543
2662
|
});
|
|
2544
2663
|
var treeDefinitionSchema = treeDefSchemaObject;
|
|
@@ -2620,6 +2739,12 @@ var SchemaRegistry = class {
|
|
|
2620
2739
|
this.register("LLMChat", llmChatSchema);
|
|
2621
2740
|
this.register("BrowserAgent", browserAgentSchema);
|
|
2622
2741
|
this.register("HumanTask", humanTaskSchema);
|
|
2742
|
+
this.register("SetVariable", setVariableSchema);
|
|
2743
|
+
this.register("LLMToolCall", llmToolCallSchema);
|
|
2744
|
+
this.register("ToolExecutor", toolExecutorSchema);
|
|
2745
|
+
this.register("WaitForSignal", waitForSignalSchema);
|
|
2746
|
+
this.register("ToolRouter", toolRouterSchema);
|
|
2747
|
+
this.register("StreamingSink", streamingSinkSchema);
|
|
2623
2748
|
}
|
|
2624
2749
|
/**
|
|
2625
2750
|
* Register a validation schema for a node type
|
|
@@ -3089,8 +3214,32 @@ var CheckCondition = class extends ConditionNode {
|
|
|
3089
3214
|
this.operator = config.operator || "==";
|
|
3090
3215
|
this.value = config.value;
|
|
3091
3216
|
}
|
|
3217
|
+
/**
|
|
3218
|
+
* Resolve a potentially dotted key from the blackboard.
|
|
3219
|
+
* Tries exact key first (backward compatible), then dotted path traversal.
|
|
3220
|
+
*/
|
|
3221
|
+
resolveBlackboardValue(context) {
|
|
3222
|
+
const exact = context.blackboard.get(this.key);
|
|
3223
|
+
if (exact !== void 0) {
|
|
3224
|
+
return exact;
|
|
3225
|
+
}
|
|
3226
|
+
if (this.key.includes(".")) {
|
|
3227
|
+
const segments = this.key.split(".");
|
|
3228
|
+
const rootKey = segments[0];
|
|
3229
|
+
let current = context.blackboard.get(rootKey);
|
|
3230
|
+
for (let i = 1; i < segments.length; i++) {
|
|
3231
|
+
if (current == null || typeof current !== "object") {
|
|
3232
|
+
return void 0;
|
|
3233
|
+
}
|
|
3234
|
+
const segment = segments[i];
|
|
3235
|
+
current = current[segment];
|
|
3236
|
+
}
|
|
3237
|
+
return current;
|
|
3238
|
+
}
|
|
3239
|
+
return void 0;
|
|
3240
|
+
}
|
|
3092
3241
|
async executeTick(context) {
|
|
3093
|
-
const actualValue =
|
|
3242
|
+
const actualValue = this.resolveBlackboardValue(context);
|
|
3094
3243
|
let result = false;
|
|
3095
3244
|
switch (this.operator) {
|
|
3096
3245
|
case "==":
|
|
@@ -3282,6 +3431,35 @@ var RegexExtract = class extends ActionNode {
|
|
|
3282
3431
|
}
|
|
3283
3432
|
};
|
|
3284
3433
|
|
|
3434
|
+
// src/utilities/set-variable.ts
|
|
3435
|
+
var SetVariable = class extends ActionNode {
|
|
3436
|
+
key;
|
|
3437
|
+
value;
|
|
3438
|
+
constructor(config) {
|
|
3439
|
+
super(config);
|
|
3440
|
+
this.key = config.key;
|
|
3441
|
+
this.value = config.value;
|
|
3442
|
+
}
|
|
3443
|
+
async executeTick(context) {
|
|
3444
|
+
try {
|
|
3445
|
+
const varCtx = {
|
|
3446
|
+
blackboard: context.blackboard,
|
|
3447
|
+
input: context.input,
|
|
3448
|
+
testData: context.testData
|
|
3449
|
+
};
|
|
3450
|
+
const resolvedKey = typeof this.key === "string" ? resolveValue(this.key, varCtx) : String(this.key);
|
|
3451
|
+
const resolvedValue = typeof this.value === "string" ? resolveValue(this.value, varCtx) : this.value;
|
|
3452
|
+
context.blackboard.set(resolvedKey, resolvedValue);
|
|
3453
|
+
this.log(`Set ${resolvedKey} = ${JSON.stringify(resolvedValue)}`);
|
|
3454
|
+
return "SUCCESS" /* SUCCESS */;
|
|
3455
|
+
} catch (error) {
|
|
3456
|
+
this._lastError = error instanceof Error ? error.message : String(error);
|
|
3457
|
+
this.log(`SetVariable failed: ${this._lastError}`);
|
|
3458
|
+
return "FAILURE" /* FAILURE */;
|
|
3459
|
+
}
|
|
3460
|
+
}
|
|
3461
|
+
};
|
|
3462
|
+
|
|
3285
3463
|
// src/integrations/piece-executor.ts
|
|
3286
3464
|
var PROVIDER_TO_PIECE = {
|
|
3287
3465
|
// Google services
|
|
@@ -3331,7 +3509,8 @@ var PIECE_EXPORT_NAMES = {
|
|
|
3331
3509
|
"@activepieces/piece-discord": "discord",
|
|
3332
3510
|
"@activepieces/piece-notion": "notion",
|
|
3333
3511
|
"@activepieces/piece-github": "github",
|
|
3334
|
-
"@activepieces/piece-http": "http"
|
|
3512
|
+
"@activepieces/piece-http": "http",
|
|
3513
|
+
"@activepieces/piece-shopify": "shopify"
|
|
3335
3514
|
};
|
|
3336
3515
|
async function loadPiece(packageName) {
|
|
3337
3516
|
if (pieceCache.has(packageName)) {
|
|
@@ -4448,6 +4627,313 @@ function setNestedPath(obj, path2, value) {
|
|
|
4448
4627
|
}
|
|
4449
4628
|
}
|
|
4450
4629
|
|
|
4630
|
+
// src/actions/llm-tool-call.ts
|
|
4631
|
+
var LLMToolCall = class extends ActionNode {
|
|
4632
|
+
provider;
|
|
4633
|
+
model;
|
|
4634
|
+
systemPrompt;
|
|
4635
|
+
messagesKey;
|
|
4636
|
+
userMessageKey;
|
|
4637
|
+
toolsKey;
|
|
4638
|
+
tools;
|
|
4639
|
+
temperature;
|
|
4640
|
+
maxTokens;
|
|
4641
|
+
outputKey;
|
|
4642
|
+
constructor(config) {
|
|
4643
|
+
super(config);
|
|
4644
|
+
if (!config.provider) {
|
|
4645
|
+
throw new ConfigurationError("LLMToolCall requires provider");
|
|
4646
|
+
}
|
|
4647
|
+
if (!config.model) {
|
|
4648
|
+
throw new ConfigurationError("LLMToolCall requires model");
|
|
4649
|
+
}
|
|
4650
|
+
if (!config.messagesKey) {
|
|
4651
|
+
throw new ConfigurationError("LLMToolCall requires messagesKey");
|
|
4652
|
+
}
|
|
4653
|
+
if (!config.outputKey) {
|
|
4654
|
+
throw new ConfigurationError("LLMToolCall requires outputKey");
|
|
4655
|
+
}
|
|
4656
|
+
this.provider = config.provider;
|
|
4657
|
+
this.model = config.model;
|
|
4658
|
+
this.systemPrompt = config.systemPrompt;
|
|
4659
|
+
this.messagesKey = config.messagesKey;
|
|
4660
|
+
this.userMessageKey = config.userMessageKey;
|
|
4661
|
+
this.toolsKey = config.toolsKey;
|
|
4662
|
+
this.tools = config.tools;
|
|
4663
|
+
this.temperature = config.temperature;
|
|
4664
|
+
this.maxTokens = config.maxTokens;
|
|
4665
|
+
this.outputKey = config.outputKey;
|
|
4666
|
+
}
|
|
4667
|
+
async executeTick(context) {
|
|
4668
|
+
if (!context.activities?.agentLoopTurn) {
|
|
4669
|
+
this._lastError = "LLMToolCall requires activities.agentLoopTurn to be configured.";
|
|
4670
|
+
this.log(`Error: ${this._lastError}`);
|
|
4671
|
+
return "FAILURE" /* FAILURE */;
|
|
4672
|
+
}
|
|
4673
|
+
try {
|
|
4674
|
+
const varCtx = {
|
|
4675
|
+
blackboard: context.blackboard,
|
|
4676
|
+
input: context.input,
|
|
4677
|
+
testData: context.testData
|
|
4678
|
+
};
|
|
4679
|
+
let messages = context.blackboard.get(this.messagesKey) || [];
|
|
4680
|
+
if (this.userMessageKey) {
|
|
4681
|
+
const userMsg = context.blackboard.get(this.userMessageKey);
|
|
4682
|
+
if (userMsg !== void 0 && userMsg !== null) {
|
|
4683
|
+
const content = typeof userMsg === "string" ? userMsg : String(userMsg);
|
|
4684
|
+
messages = [...messages, { role: "user", content }];
|
|
4685
|
+
context.blackboard.set(this.userMessageKey, null);
|
|
4686
|
+
}
|
|
4687
|
+
}
|
|
4688
|
+
const tools = this.toolsKey ? context.blackboard.get(this.toolsKey) || [] : this.tools || [];
|
|
4689
|
+
const resolvedModel = resolveValue(this.model, varCtx);
|
|
4690
|
+
const resolvedSystemPrompt = this.systemPrompt ? resolveValue(this.systemPrompt, varCtx) : void 0;
|
|
4691
|
+
const streamChannelId = context.blackboard.get("__streamChannelId");
|
|
4692
|
+
const request = {
|
|
4693
|
+
provider: this.provider,
|
|
4694
|
+
model: resolvedModel,
|
|
4695
|
+
systemPrompt: resolvedSystemPrompt,
|
|
4696
|
+
messages,
|
|
4697
|
+
tools: tools.length > 0 ? tools : void 0,
|
|
4698
|
+
temperature: this.temperature,
|
|
4699
|
+
maxTokens: this.maxTokens,
|
|
4700
|
+
streamChannelId: streamChannelId || void 0
|
|
4701
|
+
};
|
|
4702
|
+
this.log(
|
|
4703
|
+
`LLMToolCall ${this.provider}/${resolvedModel} - ${messages.length} messages, ${tools.length} tools`
|
|
4704
|
+
);
|
|
4705
|
+
const result = await context.activities.agentLoopTurn(request);
|
|
4706
|
+
if (result.toolCalls && result.toolCalls.length > 0) {
|
|
4707
|
+
const contentBlocks = [];
|
|
4708
|
+
if (result.content) {
|
|
4709
|
+
contentBlocks.push({ type: "text", text: result.content });
|
|
4710
|
+
}
|
|
4711
|
+
for (const tc of result.toolCalls) {
|
|
4712
|
+
contentBlocks.push({
|
|
4713
|
+
type: "tool_use",
|
|
4714
|
+
id: tc.id,
|
|
4715
|
+
name: tc.name,
|
|
4716
|
+
input: tc.input
|
|
4717
|
+
});
|
|
4718
|
+
}
|
|
4719
|
+
messages = [...messages, { role: "assistant", content: contentBlocks }];
|
|
4720
|
+
} else {
|
|
4721
|
+
messages = [...messages, { role: "assistant", content: result.content }];
|
|
4722
|
+
}
|
|
4723
|
+
context.blackboard.set(this.messagesKey, messages);
|
|
4724
|
+
context.blackboard.set(this.outputKey, {
|
|
4725
|
+
content: result.content,
|
|
4726
|
+
toolCalls: result.toolCalls,
|
|
4727
|
+
stopReason: result.stopReason,
|
|
4728
|
+
usage: result.usage
|
|
4729
|
+
});
|
|
4730
|
+
this.log(
|
|
4731
|
+
`LLMToolCall completed: stopReason=${result.stopReason}, tools=${result.toolCalls?.length || 0}, tokens=${result.usage.totalTokens}`
|
|
4732
|
+
);
|
|
4733
|
+
return "SUCCESS" /* SUCCESS */;
|
|
4734
|
+
} catch (error) {
|
|
4735
|
+
this._lastError = error instanceof Error ? error.message : String(error);
|
|
4736
|
+
this.log(`LLMToolCall failed: ${this._lastError}`);
|
|
4737
|
+
return "FAILURE" /* FAILURE */;
|
|
4738
|
+
}
|
|
4739
|
+
}
|
|
4740
|
+
};
|
|
4741
|
+
|
|
4742
|
+
// src/actions/tool-executor.ts
|
|
4743
|
+
var ToolExecutor = class extends ActionNode {
|
|
4744
|
+
responseKey;
|
|
4745
|
+
messagesKey;
|
|
4746
|
+
outputKey;
|
|
4747
|
+
constructor(config) {
|
|
4748
|
+
super(config);
|
|
4749
|
+
if (!config.responseKey) {
|
|
4750
|
+
throw new ConfigurationError("ToolExecutor requires responseKey");
|
|
4751
|
+
}
|
|
4752
|
+
if (!config.messagesKey) {
|
|
4753
|
+
throw new ConfigurationError("ToolExecutor requires messagesKey");
|
|
4754
|
+
}
|
|
4755
|
+
this.responseKey = config.responseKey;
|
|
4756
|
+
this.messagesKey = config.messagesKey;
|
|
4757
|
+
this.outputKey = config.outputKey;
|
|
4758
|
+
}
|
|
4759
|
+
async executeTick(context) {
|
|
4760
|
+
if (!context.activities?.executeAgentTool) {
|
|
4761
|
+
this._lastError = "ToolExecutor requires activities.executeAgentTool to be configured.";
|
|
4762
|
+
this.log(`Error: ${this._lastError}`);
|
|
4763
|
+
return "FAILURE" /* FAILURE */;
|
|
4764
|
+
}
|
|
4765
|
+
try {
|
|
4766
|
+
const response = context.blackboard.get(this.responseKey);
|
|
4767
|
+
const toolCalls = response?.toolCalls;
|
|
4768
|
+
if (!toolCalls || toolCalls.length === 0) {
|
|
4769
|
+
this.log("No tool calls to execute");
|
|
4770
|
+
return "SUCCESS" /* SUCCESS */;
|
|
4771
|
+
}
|
|
4772
|
+
const toolResults = [];
|
|
4773
|
+
for (const tc of toolCalls) {
|
|
4774
|
+
this.log(`Executing tool: ${tc.name} (${tc.id})`);
|
|
4775
|
+
const result = await context.activities.executeAgentTool({
|
|
4776
|
+
toolName: tc.name,
|
|
4777
|
+
toolInput: tc.input
|
|
4778
|
+
});
|
|
4779
|
+
toolResults.push({
|
|
4780
|
+
toolUseId: tc.id,
|
|
4781
|
+
toolName: tc.name,
|
|
4782
|
+
content: result.content,
|
|
4783
|
+
isError: result.isError
|
|
4784
|
+
});
|
|
4785
|
+
this.log(
|
|
4786
|
+
`Tool ${tc.name} ${result.isError ? "errored" : "completed"}: ${result.content.substring(0, 100)}`
|
|
4787
|
+
);
|
|
4788
|
+
}
|
|
4789
|
+
const resultBlocks = toolResults.map((tr) => ({
|
|
4790
|
+
type: "tool_result",
|
|
4791
|
+
tool_use_id: tr.toolUseId,
|
|
4792
|
+
content: tr.content,
|
|
4793
|
+
is_error: tr.isError
|
|
4794
|
+
}));
|
|
4795
|
+
const messages = context.blackboard.get(this.messagesKey) || [];
|
|
4796
|
+
const updatedMessages = [
|
|
4797
|
+
...messages,
|
|
4798
|
+
{ role: "user", content: resultBlocks }
|
|
4799
|
+
];
|
|
4800
|
+
context.blackboard.set(this.messagesKey, updatedMessages);
|
|
4801
|
+
if (this.outputKey) {
|
|
4802
|
+
context.blackboard.set(this.outputKey, toolResults);
|
|
4803
|
+
}
|
|
4804
|
+
this.log(`Executed ${toolResults.length} tool(s), results appended to conversation`);
|
|
4805
|
+
return "SUCCESS" /* SUCCESS */;
|
|
4806
|
+
} catch (error) {
|
|
4807
|
+
this._lastError = error instanceof Error ? error.message : String(error);
|
|
4808
|
+
this.log(`ToolExecutor failed: ${this._lastError}`);
|
|
4809
|
+
return "FAILURE" /* FAILURE */;
|
|
4810
|
+
}
|
|
4811
|
+
}
|
|
4812
|
+
};
|
|
4813
|
+
|
|
4814
|
+
// src/actions/wait-for-signal.ts
|
|
4815
|
+
var WaitForSignal = class extends ActionNode {
|
|
4816
|
+
signalName;
|
|
4817
|
+
signalKey;
|
|
4818
|
+
timeoutMs;
|
|
4819
|
+
outputKey;
|
|
4820
|
+
constructor(config) {
|
|
4821
|
+
super(config);
|
|
4822
|
+
if (!config.signalName) {
|
|
4823
|
+
throw new ConfigurationError("WaitForSignal requires signalName");
|
|
4824
|
+
}
|
|
4825
|
+
if (!config.outputKey) {
|
|
4826
|
+
throw new ConfigurationError("WaitForSignal requires outputKey");
|
|
4827
|
+
}
|
|
4828
|
+
this.signalName = config.signalName;
|
|
4829
|
+
this.signalKey = config.signalKey;
|
|
4830
|
+
this.timeoutMs = config.timeoutMs ?? 864e5;
|
|
4831
|
+
this.outputKey = config.outputKey;
|
|
4832
|
+
}
|
|
4833
|
+
async executeTick(context) {
|
|
4834
|
+
if (!context.activities?.waitForSignal) {
|
|
4835
|
+
this._lastError = "WaitForSignal requires activities.waitForSignal to be configured. This is implemented as a Temporal condition in the workflow layer.";
|
|
4836
|
+
this.log(`Error: ${this._lastError}`);
|
|
4837
|
+
return "FAILURE" /* FAILURE */;
|
|
4838
|
+
}
|
|
4839
|
+
try {
|
|
4840
|
+
const varCtx = {
|
|
4841
|
+
blackboard: context.blackboard,
|
|
4842
|
+
input: context.input,
|
|
4843
|
+
testData: context.testData
|
|
4844
|
+
};
|
|
4845
|
+
const resolvedSignalKey = this.signalKey ? resolveValue(this.signalKey, varCtx) : void 0;
|
|
4846
|
+
this.log(
|
|
4847
|
+
`Waiting for signal "${this.signalName}"${resolvedSignalKey ? `:${resolvedSignalKey}` : ""} (timeout: ${this.timeoutMs}ms)`
|
|
4848
|
+
);
|
|
4849
|
+
const result = await context.activities.waitForSignal({
|
|
4850
|
+
signalName: this.signalName,
|
|
4851
|
+
signalKey: resolvedSignalKey,
|
|
4852
|
+
timeoutMs: this.timeoutMs
|
|
4853
|
+
});
|
|
4854
|
+
if (result.timedOut) {
|
|
4855
|
+
this._lastError = `Signal "${this.signalName}" timed out after ${this.timeoutMs}ms`;
|
|
4856
|
+
this.log(this._lastError);
|
|
4857
|
+
return "FAILURE" /* FAILURE */;
|
|
4858
|
+
}
|
|
4859
|
+
context.blackboard.set(this.outputKey, result.data);
|
|
4860
|
+
this.log(`Signal received, data stored at "${this.outputKey}"`);
|
|
4861
|
+
return "SUCCESS" /* SUCCESS */;
|
|
4862
|
+
} catch (error) {
|
|
4863
|
+
this._lastError = error instanceof Error ? error.message : String(error);
|
|
4864
|
+
this.log(`WaitForSignal failed: ${this._lastError}`);
|
|
4865
|
+
return "FAILURE" /* FAILURE */;
|
|
4866
|
+
}
|
|
4867
|
+
}
|
|
4868
|
+
};
|
|
4869
|
+
|
|
4870
|
+
// src/actions/tool-router.ts
|
|
4871
|
+
var ToolRouter = class extends ActionNode {
|
|
4872
|
+
intentKey;
|
|
4873
|
+
toolSets;
|
|
4874
|
+
defaultTools;
|
|
4875
|
+
rules;
|
|
4876
|
+
outputKey;
|
|
4877
|
+
constructor(config) {
|
|
4878
|
+
super(config);
|
|
4879
|
+
if (!config.intentKey) {
|
|
4880
|
+
throw new ConfigurationError("ToolRouter requires intentKey");
|
|
4881
|
+
}
|
|
4882
|
+
if (!config.toolSets || Object.keys(config.toolSets).length === 0) {
|
|
4883
|
+
throw new ConfigurationError("ToolRouter requires at least one toolSet");
|
|
4884
|
+
}
|
|
4885
|
+
if (!config.outputKey) {
|
|
4886
|
+
throw new ConfigurationError("ToolRouter requires outputKey");
|
|
4887
|
+
}
|
|
4888
|
+
this.intentKey = config.intentKey;
|
|
4889
|
+
this.toolSets = config.toolSets;
|
|
4890
|
+
this.defaultTools = config.defaultTools || [];
|
|
4891
|
+
this.rules = config.rules || [];
|
|
4892
|
+
this.outputKey = config.outputKey;
|
|
4893
|
+
}
|
|
4894
|
+
async executeTick(context) {
|
|
4895
|
+
try {
|
|
4896
|
+
const varCtx = {
|
|
4897
|
+
blackboard: context.blackboard,
|
|
4898
|
+
input: context.input,
|
|
4899
|
+
testData: context.testData
|
|
4900
|
+
};
|
|
4901
|
+
const intentRaw = context.blackboard.get(this.intentKey);
|
|
4902
|
+
const intent = typeof intentRaw === "string" ? intentRaw : "";
|
|
4903
|
+
const selectedSetNames = new Set(this.defaultTools);
|
|
4904
|
+
for (const rule of this.rules) {
|
|
4905
|
+
const regex = new RegExp(rule.pattern, "i");
|
|
4906
|
+
if (regex.test(intent)) {
|
|
4907
|
+
for (const setName of rule.toolSets) {
|
|
4908
|
+
selectedSetNames.add(setName);
|
|
4909
|
+
}
|
|
4910
|
+
}
|
|
4911
|
+
}
|
|
4912
|
+
const toolsByName = /* @__PURE__ */ new Map();
|
|
4913
|
+
for (const setName of selectedSetNames) {
|
|
4914
|
+
const tools = this.toolSets[setName];
|
|
4915
|
+
if (tools) {
|
|
4916
|
+
for (const tool of tools) {
|
|
4917
|
+
if (!toolsByName.has(tool.name)) {
|
|
4918
|
+
toolsByName.set(tool.name, tool);
|
|
4919
|
+
}
|
|
4920
|
+
}
|
|
4921
|
+
}
|
|
4922
|
+
}
|
|
4923
|
+
const selectedTools = Array.from(toolsByName.values());
|
|
4924
|
+
context.blackboard.set(this.outputKey, selectedTools);
|
|
4925
|
+
this.log(
|
|
4926
|
+
`Selected ${selectedTools.length} tools from sets [${Array.from(selectedSetNames).join(", ")}] for intent "${intent.substring(0, 50)}"`
|
|
4927
|
+
);
|
|
4928
|
+
return "SUCCESS" /* SUCCESS */;
|
|
4929
|
+
} catch (error) {
|
|
4930
|
+
this._lastError = error instanceof Error ? error.message : String(error);
|
|
4931
|
+
this.log(`ToolRouter failed: ${this._lastError}`);
|
|
4932
|
+
return "FAILURE" /* FAILURE */;
|
|
4933
|
+
}
|
|
4934
|
+
}
|
|
4935
|
+
};
|
|
4936
|
+
|
|
4451
4937
|
// src/registry-utils.ts
|
|
4452
4938
|
function registerStandardNodes(registry) {
|
|
4453
4939
|
registry.register("Sequence", Sequence, { category: "composite" });
|
|
@@ -4501,6 +4987,7 @@ function registerStandardNodes(registry) {
|
|
|
4501
4987
|
registry.register("WaitAction", WaitAction, { category: "action" });
|
|
4502
4988
|
registry.register("LogMessage", LogMessage, { category: "action" });
|
|
4503
4989
|
registry.register("RegexExtract", RegexExtract, { category: "action" });
|
|
4990
|
+
registry.register("SetVariable", SetVariable, { category: "action" });
|
|
4504
4991
|
registry.register("IntegrationAction", IntegrationAction, { category: "action" });
|
|
4505
4992
|
registry.register("PythonScript", PythonScript, { category: "action" });
|
|
4506
4993
|
registry.register("ParseFile", ParseFile, { category: "action" });
|
|
@@ -4512,6 +4999,11 @@ function registerStandardNodes(registry) {
|
|
|
4512
4999
|
registry.register("ClaudeAgent", ClaudeAgent, { category: "action" });
|
|
4513
5000
|
registry.register("GitHubAction", GitHubAction, { category: "action" });
|
|
4514
5001
|
registry.register("HumanTask", HumanTask, { category: "action" });
|
|
5002
|
+
registry.register("LLMToolCall", LLMToolCall, { category: "action" });
|
|
5003
|
+
registry.register("ToolExecutor", ToolExecutor, { category: "action" });
|
|
5004
|
+
registry.register("WaitForSignal", WaitForSignal, { category: "action" });
|
|
5005
|
+
registry.register("ToolRouter", ToolRouter, { category: "action" });
|
|
5006
|
+
registry.register("StreamingSink", StreamingSink, { category: "decorator" });
|
|
4515
5007
|
}
|
|
4516
5008
|
|
|
4517
5009
|
// src/data-store/memory-store.ts
|
|
@@ -5374,6 +5866,7 @@ export {
|
|
|
5374
5866
|
Invert,
|
|
5375
5867
|
KeepRunningUntilFailure,
|
|
5376
5868
|
LLMChat,
|
|
5869
|
+
LLMToolCall,
|
|
5377
5870
|
LogMessage,
|
|
5378
5871
|
MemoryDataStore,
|
|
5379
5872
|
MemorySequence,
|
|
@@ -5400,14 +5893,19 @@ export {
|
|
|
5400
5893
|
SemanticValidationError,
|
|
5401
5894
|
Sequence,
|
|
5402
5895
|
SequenceWithMemory,
|
|
5896
|
+
SetVariable,
|
|
5403
5897
|
SoftAssert,
|
|
5898
|
+
StreamingSink,
|
|
5404
5899
|
StructureValidationError,
|
|
5405
5900
|
SubTree,
|
|
5406
5901
|
SuccessNode,
|
|
5407
5902
|
Timeout,
|
|
5903
|
+
ToolExecutor,
|
|
5904
|
+
ToolRouter,
|
|
5408
5905
|
ValidationError,
|
|
5409
5906
|
ValidationErrors,
|
|
5410
5907
|
WaitAction,
|
|
5908
|
+
WaitForSignal,
|
|
5411
5909
|
While,
|
|
5412
5910
|
YamlSyntaxError,
|
|
5413
5911
|
clearPieceCache,
|