@q1k-oss/behaviour-tree-workflows 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +514 -11
- package/dist/index.d.cts +370 -821
- package/dist/index.d.ts +370 -821
- package/dist/index.js +508 -11
- package/dist/types-BJPlUisg.d.cts +931 -0
- package/dist/types-BJPlUisg.d.ts +931 -0
- package/package.json +35 -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
|
|
@@ -4448,6 +4626,313 @@ function setNestedPath(obj, path2, value) {
|
|
|
4448
4626
|
}
|
|
4449
4627
|
}
|
|
4450
4628
|
|
|
4629
|
+
// src/actions/llm-tool-call.ts
|
|
4630
|
+
var LLMToolCall = class extends ActionNode {
|
|
4631
|
+
provider;
|
|
4632
|
+
model;
|
|
4633
|
+
systemPrompt;
|
|
4634
|
+
messagesKey;
|
|
4635
|
+
userMessageKey;
|
|
4636
|
+
toolsKey;
|
|
4637
|
+
tools;
|
|
4638
|
+
temperature;
|
|
4639
|
+
maxTokens;
|
|
4640
|
+
outputKey;
|
|
4641
|
+
constructor(config) {
|
|
4642
|
+
super(config);
|
|
4643
|
+
if (!config.provider) {
|
|
4644
|
+
throw new ConfigurationError("LLMToolCall requires provider");
|
|
4645
|
+
}
|
|
4646
|
+
if (!config.model) {
|
|
4647
|
+
throw new ConfigurationError("LLMToolCall requires model");
|
|
4648
|
+
}
|
|
4649
|
+
if (!config.messagesKey) {
|
|
4650
|
+
throw new ConfigurationError("LLMToolCall requires messagesKey");
|
|
4651
|
+
}
|
|
4652
|
+
if (!config.outputKey) {
|
|
4653
|
+
throw new ConfigurationError("LLMToolCall requires outputKey");
|
|
4654
|
+
}
|
|
4655
|
+
this.provider = config.provider;
|
|
4656
|
+
this.model = config.model;
|
|
4657
|
+
this.systemPrompt = config.systemPrompt;
|
|
4658
|
+
this.messagesKey = config.messagesKey;
|
|
4659
|
+
this.userMessageKey = config.userMessageKey;
|
|
4660
|
+
this.toolsKey = config.toolsKey;
|
|
4661
|
+
this.tools = config.tools;
|
|
4662
|
+
this.temperature = config.temperature;
|
|
4663
|
+
this.maxTokens = config.maxTokens;
|
|
4664
|
+
this.outputKey = config.outputKey;
|
|
4665
|
+
}
|
|
4666
|
+
async executeTick(context) {
|
|
4667
|
+
if (!context.activities?.agentLoopTurn) {
|
|
4668
|
+
this._lastError = "LLMToolCall requires activities.agentLoopTurn to be configured.";
|
|
4669
|
+
this.log(`Error: ${this._lastError}`);
|
|
4670
|
+
return "FAILURE" /* FAILURE */;
|
|
4671
|
+
}
|
|
4672
|
+
try {
|
|
4673
|
+
const varCtx = {
|
|
4674
|
+
blackboard: context.blackboard,
|
|
4675
|
+
input: context.input,
|
|
4676
|
+
testData: context.testData
|
|
4677
|
+
};
|
|
4678
|
+
let messages = context.blackboard.get(this.messagesKey) || [];
|
|
4679
|
+
if (this.userMessageKey) {
|
|
4680
|
+
const userMsg = context.blackboard.get(this.userMessageKey);
|
|
4681
|
+
if (userMsg !== void 0 && userMsg !== null) {
|
|
4682
|
+
const content = typeof userMsg === "string" ? userMsg : String(userMsg);
|
|
4683
|
+
messages = [...messages, { role: "user", content }];
|
|
4684
|
+
context.blackboard.set(this.userMessageKey, null);
|
|
4685
|
+
}
|
|
4686
|
+
}
|
|
4687
|
+
const tools = this.toolsKey ? context.blackboard.get(this.toolsKey) || [] : this.tools || [];
|
|
4688
|
+
const resolvedModel = resolveValue(this.model, varCtx);
|
|
4689
|
+
const resolvedSystemPrompt = this.systemPrompt ? resolveValue(this.systemPrompt, varCtx) : void 0;
|
|
4690
|
+
const streamChannelId = context.blackboard.get("__streamChannelId");
|
|
4691
|
+
const request = {
|
|
4692
|
+
provider: this.provider,
|
|
4693
|
+
model: resolvedModel,
|
|
4694
|
+
systemPrompt: resolvedSystemPrompt,
|
|
4695
|
+
messages,
|
|
4696
|
+
tools: tools.length > 0 ? tools : void 0,
|
|
4697
|
+
temperature: this.temperature,
|
|
4698
|
+
maxTokens: this.maxTokens,
|
|
4699
|
+
streamChannelId: streamChannelId || void 0
|
|
4700
|
+
};
|
|
4701
|
+
this.log(
|
|
4702
|
+
`LLMToolCall ${this.provider}/${resolvedModel} - ${messages.length} messages, ${tools.length} tools`
|
|
4703
|
+
);
|
|
4704
|
+
const result = await context.activities.agentLoopTurn(request);
|
|
4705
|
+
if (result.toolCalls && result.toolCalls.length > 0) {
|
|
4706
|
+
const contentBlocks = [];
|
|
4707
|
+
if (result.content) {
|
|
4708
|
+
contentBlocks.push({ type: "text", text: result.content });
|
|
4709
|
+
}
|
|
4710
|
+
for (const tc of result.toolCalls) {
|
|
4711
|
+
contentBlocks.push({
|
|
4712
|
+
type: "tool_use",
|
|
4713
|
+
id: tc.id,
|
|
4714
|
+
name: tc.name,
|
|
4715
|
+
input: tc.input
|
|
4716
|
+
});
|
|
4717
|
+
}
|
|
4718
|
+
messages = [...messages, { role: "assistant", content: contentBlocks }];
|
|
4719
|
+
} else {
|
|
4720
|
+
messages = [...messages, { role: "assistant", content: result.content }];
|
|
4721
|
+
}
|
|
4722
|
+
context.blackboard.set(this.messagesKey, messages);
|
|
4723
|
+
context.blackboard.set(this.outputKey, {
|
|
4724
|
+
content: result.content,
|
|
4725
|
+
toolCalls: result.toolCalls,
|
|
4726
|
+
stopReason: result.stopReason,
|
|
4727
|
+
usage: result.usage
|
|
4728
|
+
});
|
|
4729
|
+
this.log(
|
|
4730
|
+
`LLMToolCall completed: stopReason=${result.stopReason}, tools=${result.toolCalls?.length || 0}, tokens=${result.usage.totalTokens}`
|
|
4731
|
+
);
|
|
4732
|
+
return "SUCCESS" /* SUCCESS */;
|
|
4733
|
+
} catch (error) {
|
|
4734
|
+
this._lastError = error instanceof Error ? error.message : String(error);
|
|
4735
|
+
this.log(`LLMToolCall failed: ${this._lastError}`);
|
|
4736
|
+
return "FAILURE" /* FAILURE */;
|
|
4737
|
+
}
|
|
4738
|
+
}
|
|
4739
|
+
};
|
|
4740
|
+
|
|
4741
|
+
// src/actions/tool-executor.ts
|
|
4742
|
+
var ToolExecutor = class extends ActionNode {
|
|
4743
|
+
responseKey;
|
|
4744
|
+
messagesKey;
|
|
4745
|
+
outputKey;
|
|
4746
|
+
constructor(config) {
|
|
4747
|
+
super(config);
|
|
4748
|
+
if (!config.responseKey) {
|
|
4749
|
+
throw new ConfigurationError("ToolExecutor requires responseKey");
|
|
4750
|
+
}
|
|
4751
|
+
if (!config.messagesKey) {
|
|
4752
|
+
throw new ConfigurationError("ToolExecutor requires messagesKey");
|
|
4753
|
+
}
|
|
4754
|
+
this.responseKey = config.responseKey;
|
|
4755
|
+
this.messagesKey = config.messagesKey;
|
|
4756
|
+
this.outputKey = config.outputKey;
|
|
4757
|
+
}
|
|
4758
|
+
async executeTick(context) {
|
|
4759
|
+
if (!context.activities?.executeAgentTool) {
|
|
4760
|
+
this._lastError = "ToolExecutor requires activities.executeAgentTool to be configured.";
|
|
4761
|
+
this.log(`Error: ${this._lastError}`);
|
|
4762
|
+
return "FAILURE" /* FAILURE */;
|
|
4763
|
+
}
|
|
4764
|
+
try {
|
|
4765
|
+
const response = context.blackboard.get(this.responseKey);
|
|
4766
|
+
const toolCalls = response?.toolCalls;
|
|
4767
|
+
if (!toolCalls || toolCalls.length === 0) {
|
|
4768
|
+
this.log("No tool calls to execute");
|
|
4769
|
+
return "SUCCESS" /* SUCCESS */;
|
|
4770
|
+
}
|
|
4771
|
+
const toolResults = [];
|
|
4772
|
+
for (const tc of toolCalls) {
|
|
4773
|
+
this.log(`Executing tool: ${tc.name} (${tc.id})`);
|
|
4774
|
+
const result = await context.activities.executeAgentTool({
|
|
4775
|
+
toolName: tc.name,
|
|
4776
|
+
toolInput: tc.input
|
|
4777
|
+
});
|
|
4778
|
+
toolResults.push({
|
|
4779
|
+
toolUseId: tc.id,
|
|
4780
|
+
toolName: tc.name,
|
|
4781
|
+
content: result.content,
|
|
4782
|
+
isError: result.isError
|
|
4783
|
+
});
|
|
4784
|
+
this.log(
|
|
4785
|
+
`Tool ${tc.name} ${result.isError ? "errored" : "completed"}: ${result.content.substring(0, 100)}`
|
|
4786
|
+
);
|
|
4787
|
+
}
|
|
4788
|
+
const resultBlocks = toolResults.map((tr) => ({
|
|
4789
|
+
type: "tool_result",
|
|
4790
|
+
tool_use_id: tr.toolUseId,
|
|
4791
|
+
content: tr.content,
|
|
4792
|
+
is_error: tr.isError
|
|
4793
|
+
}));
|
|
4794
|
+
const messages = context.blackboard.get(this.messagesKey) || [];
|
|
4795
|
+
const updatedMessages = [
|
|
4796
|
+
...messages,
|
|
4797
|
+
{ role: "user", content: resultBlocks }
|
|
4798
|
+
];
|
|
4799
|
+
context.blackboard.set(this.messagesKey, updatedMessages);
|
|
4800
|
+
if (this.outputKey) {
|
|
4801
|
+
context.blackboard.set(this.outputKey, toolResults);
|
|
4802
|
+
}
|
|
4803
|
+
this.log(`Executed ${toolResults.length} tool(s), results appended to conversation`);
|
|
4804
|
+
return "SUCCESS" /* SUCCESS */;
|
|
4805
|
+
} catch (error) {
|
|
4806
|
+
this._lastError = error instanceof Error ? error.message : String(error);
|
|
4807
|
+
this.log(`ToolExecutor failed: ${this._lastError}`);
|
|
4808
|
+
return "FAILURE" /* FAILURE */;
|
|
4809
|
+
}
|
|
4810
|
+
}
|
|
4811
|
+
};
|
|
4812
|
+
|
|
4813
|
+
// src/actions/wait-for-signal.ts
|
|
4814
|
+
var WaitForSignal = class extends ActionNode {
|
|
4815
|
+
signalName;
|
|
4816
|
+
signalKey;
|
|
4817
|
+
timeoutMs;
|
|
4818
|
+
outputKey;
|
|
4819
|
+
constructor(config) {
|
|
4820
|
+
super(config);
|
|
4821
|
+
if (!config.signalName) {
|
|
4822
|
+
throw new ConfigurationError("WaitForSignal requires signalName");
|
|
4823
|
+
}
|
|
4824
|
+
if (!config.outputKey) {
|
|
4825
|
+
throw new ConfigurationError("WaitForSignal requires outputKey");
|
|
4826
|
+
}
|
|
4827
|
+
this.signalName = config.signalName;
|
|
4828
|
+
this.signalKey = config.signalKey;
|
|
4829
|
+
this.timeoutMs = config.timeoutMs ?? 864e5;
|
|
4830
|
+
this.outputKey = config.outputKey;
|
|
4831
|
+
}
|
|
4832
|
+
async executeTick(context) {
|
|
4833
|
+
if (!context.activities?.waitForSignal) {
|
|
4834
|
+
this._lastError = "WaitForSignal requires activities.waitForSignal to be configured. This is implemented as a Temporal condition in the workflow layer.";
|
|
4835
|
+
this.log(`Error: ${this._lastError}`);
|
|
4836
|
+
return "FAILURE" /* FAILURE */;
|
|
4837
|
+
}
|
|
4838
|
+
try {
|
|
4839
|
+
const varCtx = {
|
|
4840
|
+
blackboard: context.blackboard,
|
|
4841
|
+
input: context.input,
|
|
4842
|
+
testData: context.testData
|
|
4843
|
+
};
|
|
4844
|
+
const resolvedSignalKey = this.signalKey ? resolveValue(this.signalKey, varCtx) : void 0;
|
|
4845
|
+
this.log(
|
|
4846
|
+
`Waiting for signal "${this.signalName}"${resolvedSignalKey ? `:${resolvedSignalKey}` : ""} (timeout: ${this.timeoutMs}ms)`
|
|
4847
|
+
);
|
|
4848
|
+
const result = await context.activities.waitForSignal({
|
|
4849
|
+
signalName: this.signalName,
|
|
4850
|
+
signalKey: resolvedSignalKey,
|
|
4851
|
+
timeoutMs: this.timeoutMs
|
|
4852
|
+
});
|
|
4853
|
+
if (result.timedOut) {
|
|
4854
|
+
this._lastError = `Signal "${this.signalName}" timed out after ${this.timeoutMs}ms`;
|
|
4855
|
+
this.log(this._lastError);
|
|
4856
|
+
return "FAILURE" /* FAILURE */;
|
|
4857
|
+
}
|
|
4858
|
+
context.blackboard.set(this.outputKey, result.data);
|
|
4859
|
+
this.log(`Signal received, data stored at "${this.outputKey}"`);
|
|
4860
|
+
return "SUCCESS" /* SUCCESS */;
|
|
4861
|
+
} catch (error) {
|
|
4862
|
+
this._lastError = error instanceof Error ? error.message : String(error);
|
|
4863
|
+
this.log(`WaitForSignal failed: ${this._lastError}`);
|
|
4864
|
+
return "FAILURE" /* FAILURE */;
|
|
4865
|
+
}
|
|
4866
|
+
}
|
|
4867
|
+
};
|
|
4868
|
+
|
|
4869
|
+
// src/actions/tool-router.ts
|
|
4870
|
+
var ToolRouter = class extends ActionNode {
|
|
4871
|
+
intentKey;
|
|
4872
|
+
toolSets;
|
|
4873
|
+
defaultTools;
|
|
4874
|
+
rules;
|
|
4875
|
+
outputKey;
|
|
4876
|
+
constructor(config) {
|
|
4877
|
+
super(config);
|
|
4878
|
+
if (!config.intentKey) {
|
|
4879
|
+
throw new ConfigurationError("ToolRouter requires intentKey");
|
|
4880
|
+
}
|
|
4881
|
+
if (!config.toolSets || Object.keys(config.toolSets).length === 0) {
|
|
4882
|
+
throw new ConfigurationError("ToolRouter requires at least one toolSet");
|
|
4883
|
+
}
|
|
4884
|
+
if (!config.outputKey) {
|
|
4885
|
+
throw new ConfigurationError("ToolRouter requires outputKey");
|
|
4886
|
+
}
|
|
4887
|
+
this.intentKey = config.intentKey;
|
|
4888
|
+
this.toolSets = config.toolSets;
|
|
4889
|
+
this.defaultTools = config.defaultTools || [];
|
|
4890
|
+
this.rules = config.rules || [];
|
|
4891
|
+
this.outputKey = config.outputKey;
|
|
4892
|
+
}
|
|
4893
|
+
async executeTick(context) {
|
|
4894
|
+
try {
|
|
4895
|
+
const varCtx = {
|
|
4896
|
+
blackboard: context.blackboard,
|
|
4897
|
+
input: context.input,
|
|
4898
|
+
testData: context.testData
|
|
4899
|
+
};
|
|
4900
|
+
const intentRaw = context.blackboard.get(this.intentKey);
|
|
4901
|
+
const intent = typeof intentRaw === "string" ? intentRaw : "";
|
|
4902
|
+
const selectedSetNames = new Set(this.defaultTools);
|
|
4903
|
+
for (const rule of this.rules) {
|
|
4904
|
+
const regex = new RegExp(rule.pattern, "i");
|
|
4905
|
+
if (regex.test(intent)) {
|
|
4906
|
+
for (const setName of rule.toolSets) {
|
|
4907
|
+
selectedSetNames.add(setName);
|
|
4908
|
+
}
|
|
4909
|
+
}
|
|
4910
|
+
}
|
|
4911
|
+
const toolsByName = /* @__PURE__ */ new Map();
|
|
4912
|
+
for (const setName of selectedSetNames) {
|
|
4913
|
+
const tools = this.toolSets[setName];
|
|
4914
|
+
if (tools) {
|
|
4915
|
+
for (const tool of tools) {
|
|
4916
|
+
if (!toolsByName.has(tool.name)) {
|
|
4917
|
+
toolsByName.set(tool.name, tool);
|
|
4918
|
+
}
|
|
4919
|
+
}
|
|
4920
|
+
}
|
|
4921
|
+
}
|
|
4922
|
+
const selectedTools = Array.from(toolsByName.values());
|
|
4923
|
+
context.blackboard.set(this.outputKey, selectedTools);
|
|
4924
|
+
this.log(
|
|
4925
|
+
`Selected ${selectedTools.length} tools from sets [${Array.from(selectedSetNames).join(", ")}] for intent "${intent.substring(0, 50)}"`
|
|
4926
|
+
);
|
|
4927
|
+
return "SUCCESS" /* SUCCESS */;
|
|
4928
|
+
} catch (error) {
|
|
4929
|
+
this._lastError = error instanceof Error ? error.message : String(error);
|
|
4930
|
+
this.log(`ToolRouter failed: ${this._lastError}`);
|
|
4931
|
+
return "FAILURE" /* FAILURE */;
|
|
4932
|
+
}
|
|
4933
|
+
}
|
|
4934
|
+
};
|
|
4935
|
+
|
|
4451
4936
|
// src/registry-utils.ts
|
|
4452
4937
|
function registerStandardNodes(registry) {
|
|
4453
4938
|
registry.register("Sequence", Sequence, { category: "composite" });
|
|
@@ -4501,6 +4986,7 @@ function registerStandardNodes(registry) {
|
|
|
4501
4986
|
registry.register("WaitAction", WaitAction, { category: "action" });
|
|
4502
4987
|
registry.register("LogMessage", LogMessage, { category: "action" });
|
|
4503
4988
|
registry.register("RegexExtract", RegexExtract, { category: "action" });
|
|
4989
|
+
registry.register("SetVariable", SetVariable, { category: "action" });
|
|
4504
4990
|
registry.register("IntegrationAction", IntegrationAction, { category: "action" });
|
|
4505
4991
|
registry.register("PythonScript", PythonScript, { category: "action" });
|
|
4506
4992
|
registry.register("ParseFile", ParseFile, { category: "action" });
|
|
@@ -4512,6 +4998,11 @@ function registerStandardNodes(registry) {
|
|
|
4512
4998
|
registry.register("ClaudeAgent", ClaudeAgent, { category: "action" });
|
|
4513
4999
|
registry.register("GitHubAction", GitHubAction, { category: "action" });
|
|
4514
5000
|
registry.register("HumanTask", HumanTask, { category: "action" });
|
|
5001
|
+
registry.register("LLMToolCall", LLMToolCall, { category: "action" });
|
|
5002
|
+
registry.register("ToolExecutor", ToolExecutor, { category: "action" });
|
|
5003
|
+
registry.register("WaitForSignal", WaitForSignal, { category: "action" });
|
|
5004
|
+
registry.register("ToolRouter", ToolRouter, { category: "action" });
|
|
5005
|
+
registry.register("StreamingSink", StreamingSink, { category: "decorator" });
|
|
4515
5006
|
}
|
|
4516
5007
|
|
|
4517
5008
|
// src/data-store/memory-store.ts
|
|
@@ -5374,6 +5865,7 @@ export {
|
|
|
5374
5865
|
Invert,
|
|
5375
5866
|
KeepRunningUntilFailure,
|
|
5376
5867
|
LLMChat,
|
|
5868
|
+
LLMToolCall,
|
|
5377
5869
|
LogMessage,
|
|
5378
5870
|
MemoryDataStore,
|
|
5379
5871
|
MemorySequence,
|
|
@@ -5400,14 +5892,19 @@ export {
|
|
|
5400
5892
|
SemanticValidationError,
|
|
5401
5893
|
Sequence,
|
|
5402
5894
|
SequenceWithMemory,
|
|
5895
|
+
SetVariable,
|
|
5403
5896
|
SoftAssert,
|
|
5897
|
+
StreamingSink,
|
|
5404
5898
|
StructureValidationError,
|
|
5405
5899
|
SubTree,
|
|
5406
5900
|
SuccessNode,
|
|
5407
5901
|
Timeout,
|
|
5902
|
+
ToolExecutor,
|
|
5903
|
+
ToolRouter,
|
|
5408
5904
|
ValidationError,
|
|
5409
5905
|
ValidationErrors,
|
|
5410
5906
|
WaitAction,
|
|
5907
|
+
WaitForSignal,
|
|
5411
5908
|
While,
|
|
5412
5909
|
YamlSyntaxError,
|
|
5413
5910
|
clearPieceCache,
|