@modelrelay/sdk 4.0.0 → 5.3.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/README.md +19 -64
- package/dist/api-7TVb2cnl.d.cts +5319 -0
- package/dist/api-7TVb2cnl.d.ts +5319 -0
- package/dist/{api-CzFaWgs_.d.cts → api-B9x3HA3Z.d.cts} +10 -13
- package/dist/{api-CzFaWgs_.d.ts → api-B9x3HA3Z.d.ts} +10 -13
- package/dist/api-BRAJe_xm.d.cts +5315 -0
- package/dist/api-BRAJe_xm.d.ts +5315 -0
- package/dist/{api-jqOwvH6O.d.cts → api-HVh8Lusf.d.cts} +2650 -2111
- package/dist/{api-jqOwvH6O.d.ts → api-HVh8Lusf.d.ts} +2650 -2111
- package/dist/billing/index.d.cts +1 -1
- package/dist/billing/index.d.ts +1 -1
- package/dist/{chunk-EMQKOEF3.js → chunk-BL7GWXRZ.js} +1 -1
- package/dist/{chunk-ADQ74R7T.js → chunk-G5H7EY4F.js} +16 -14
- package/dist/{chunk-LW6SC7NQ.js → chunk-HLJAMT7F.js} +1 -1
- package/dist/{chunk-ZBQKY2W2.js → chunk-LZDGY24E.js} +2 -63
- package/dist/chunk-OJFVI3QJ.js +1133 -0
- package/dist/chunk-Z6R4G2TU.js +1133 -0
- package/dist/index.cjs +192 -504
- package/dist/index.d.cts +179 -623
- package/dist/index.d.ts +179 -623
- package/dist/index.js +185 -496
- package/dist/node.cjs +155 -2
- package/dist/node.d.cts +9 -0
- package/dist/node.d.ts +9 -0
- package/dist/node.js +155 -2
- package/dist/{tools-DAqAFZ8F.d.ts → tools-Db-F5rIL.d.cts} +6 -9
- package/dist/{tools-DAqAFZ8F.d.cts → tools-Db-F5rIL.d.ts} +6 -9
- package/package.json +1 -1
- package/dist/tools-Cnl2MgVa.d.cts +0 -1174
- package/dist/tools-Cnl2MgVa.d.ts +0 -1174
package/dist/index.js
CHANGED
|
@@ -64,7 +64,7 @@ import {
|
|
|
64
64
|
toolResultMessage,
|
|
65
65
|
tryParseToolArgs,
|
|
66
66
|
zodToJsonSchema
|
|
67
|
-
} from "./chunk-
|
|
67
|
+
} from "./chunk-LZDGY24E.js";
|
|
68
68
|
import {
|
|
69
69
|
__export
|
|
70
70
|
} from "./chunk-MLKGABMK.js";
|
|
@@ -1804,11 +1804,10 @@ function parseOutputName(raw) {
|
|
|
1804
1804
|
|
|
1805
1805
|
// src/runs_types.ts
|
|
1806
1806
|
var WorkflowKinds = {
|
|
1807
|
-
|
|
1807
|
+
WorkflowIntent: "workflow"
|
|
1808
1808
|
};
|
|
1809
|
-
var
|
|
1810
|
-
|
|
1811
|
-
RouteSwitch: "route.switch",
|
|
1809
|
+
var WorkflowNodeTypesLite = {
|
|
1810
|
+
LLM: "llm",
|
|
1812
1811
|
JoinAll: "join.all",
|
|
1813
1812
|
JoinAny: "join.any",
|
|
1814
1813
|
JoinCollect: "join.collect",
|
|
@@ -2179,6 +2178,9 @@ var RunsClient = class {
|
|
|
2179
2178
|
if (options.idempotencyKey?.trim()) {
|
|
2180
2179
|
payload.options = { idempotency_key: options.idempotencyKey.trim() };
|
|
2181
2180
|
}
|
|
2181
|
+
if (options.input) {
|
|
2182
|
+
payload.input = options.input;
|
|
2183
|
+
}
|
|
2182
2184
|
const out = await this.http.json(RUNS_PATH, {
|
|
2183
2185
|
method: "POST",
|
|
2184
2186
|
headers,
|
|
@@ -2369,7 +2371,7 @@ var WorkflowsClient = class {
|
|
|
2369
2371
|
this.metrics = cfg.metrics;
|
|
2370
2372
|
this.trace = cfg.trace;
|
|
2371
2373
|
}
|
|
2372
|
-
async
|
|
2374
|
+
async compile(spec, options = {}) {
|
|
2373
2375
|
const metrics = mergeMetrics(this.metrics, options.metrics);
|
|
2374
2376
|
const trace = mergeTrace(this.trace, options.trace);
|
|
2375
2377
|
const authHeaders = await this.auth.authForResponses();
|
|
@@ -2874,21 +2876,16 @@ var LocalSession = class _LocalSession {
|
|
|
2874
2876
|
const input = await this.buildInput(options);
|
|
2875
2877
|
const tools = mergeTools(this.defaultTools, options.tools);
|
|
2876
2878
|
const spec = {
|
|
2877
|
-
kind: "workflow
|
|
2879
|
+
kind: "workflow",
|
|
2878
2880
|
name: `session-${this.id}-turn-${this.nextSeq}`,
|
|
2881
|
+
model: options.model || this.defaultModel,
|
|
2879
2882
|
nodes: [
|
|
2880
2883
|
{
|
|
2881
2884
|
id: "main",
|
|
2882
|
-
type: "llm
|
|
2883
|
-
input
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
model: options.model || this.defaultModel,
|
|
2887
|
-
input,
|
|
2888
|
-
tools
|
|
2889
|
-
},
|
|
2890
|
-
tool_execution: this.toolRegistry ? { mode: "client" } : void 0
|
|
2891
|
-
}
|
|
2885
|
+
type: "llm",
|
|
2886
|
+
input,
|
|
2887
|
+
tools,
|
|
2888
|
+
tool_execution: this.toolRegistry ? { mode: "client" } : void 0
|
|
2892
2889
|
}
|
|
2893
2890
|
],
|
|
2894
2891
|
outputs: [{ name: "result", from: "main" }]
|
|
@@ -3369,21 +3366,16 @@ var RemoteSession = class _RemoteSession {
|
|
|
3369
3366
|
const input = await this.buildInput(options);
|
|
3370
3367
|
const tools = mergeTools2(this.defaultTools, options.tools);
|
|
3371
3368
|
const spec = {
|
|
3372
|
-
kind: "workflow
|
|
3369
|
+
kind: "workflow",
|
|
3373
3370
|
name: `session-${this.id}-turn-${this.nextSeq}`,
|
|
3371
|
+
model: options.model || this.defaultModel,
|
|
3374
3372
|
nodes: [
|
|
3375
3373
|
{
|
|
3376
3374
|
id: "main",
|
|
3377
|
-
type: "llm
|
|
3378
|
-
input
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
model: options.model || this.defaultModel,
|
|
3382
|
-
input,
|
|
3383
|
-
tools
|
|
3384
|
-
},
|
|
3385
|
-
tool_execution: this.toolRegistry ? { mode: "client" } : void 0
|
|
3386
|
-
}
|
|
3375
|
+
type: "llm",
|
|
3376
|
+
input,
|
|
3377
|
+
tools,
|
|
3378
|
+
tool_execution: this.toolRegistry ? { mode: "client" } : void 0
|
|
3387
3379
|
}
|
|
3388
3380
|
],
|
|
3389
3381
|
outputs: [{ name: "result", from: "main" }]
|
|
@@ -4539,253 +4531,185 @@ function JoinOutput(nodeId) {
|
|
|
4539
4531
|
// src/workflow_builder.ts
|
|
4540
4532
|
var LLM_TEXT_OUTPUT = LLMOutputText;
|
|
4541
4533
|
var LLM_USER_MESSAGE_TEXT = LLMInputUserText;
|
|
4542
|
-
|
|
4543
|
-
return pointer ? { from, pointer } : { from };
|
|
4544
|
-
}
|
|
4545
|
-
function transformJSONObject(object) {
|
|
4546
|
-
return { object };
|
|
4547
|
-
}
|
|
4548
|
-
function transformJSONMerge(merge) {
|
|
4549
|
-
return { merge: merge.slice() };
|
|
4550
|
-
}
|
|
4551
|
-
function wireRequest(req) {
|
|
4552
|
-
const raw = req;
|
|
4553
|
-
if (raw && typeof raw === "object") {
|
|
4554
|
-
if ("input" in raw) {
|
|
4555
|
-
return req;
|
|
4556
|
-
}
|
|
4557
|
-
if ("body" in raw) {
|
|
4558
|
-
return raw.body ?? {};
|
|
4559
|
-
}
|
|
4560
|
-
}
|
|
4561
|
-
return asInternal(req).body;
|
|
4562
|
-
}
|
|
4563
|
-
var INPUT_POINTER_PATTERN = /^\/input\/(\d+)(?:\/content\/(\d+))?/;
|
|
4564
|
-
var BindingTargetError = class extends Error {
|
|
4565
|
-
constructor(nodeId, bindingIndex, pointer, message) {
|
|
4566
|
-
super(`node "${nodeId}" binding ${bindingIndex}: ${message}`);
|
|
4567
|
-
this.name = "BindingTargetError";
|
|
4568
|
-
this.nodeId = nodeId;
|
|
4569
|
-
this.bindingIndex = bindingIndex;
|
|
4570
|
-
this.pointer = pointer;
|
|
4571
|
-
}
|
|
4572
|
-
};
|
|
4573
|
-
var MapFanoutInputError = class extends Error {
|
|
4574
|
-
constructor(nodeId, message) {
|
|
4575
|
-
super(`node "${nodeId}": ${message}`);
|
|
4576
|
-
this.name = "MapFanoutInputError";
|
|
4577
|
-
this.nodeId = nodeId;
|
|
4578
|
-
}
|
|
4579
|
-
};
|
|
4580
|
-
function validateBindingTargets(nodeId, input, bindings) {
|
|
4581
|
-
for (let i = 0; i < bindings.length; i++) {
|
|
4582
|
-
const binding = bindings[i];
|
|
4583
|
-
if (!binding.to) continue;
|
|
4584
|
-
const error = validateInputPointer(binding.to, input);
|
|
4585
|
-
if (error) {
|
|
4586
|
-
throw new BindingTargetError(nodeId, i, binding.to, error);
|
|
4587
|
-
}
|
|
4588
|
-
}
|
|
4589
|
-
}
|
|
4590
|
-
function validateInputPointer(pointer, input) {
|
|
4591
|
-
if (!pointer.startsWith("/input/")) {
|
|
4592
|
-
return void 0;
|
|
4593
|
-
}
|
|
4594
|
-
const match = pointer.match(INPUT_POINTER_PATTERN);
|
|
4595
|
-
if (!match) {
|
|
4596
|
-
return void 0;
|
|
4597
|
-
}
|
|
4598
|
-
const msgIndex = parseInt(match[1], 10);
|
|
4599
|
-
if (msgIndex >= input.length) {
|
|
4600
|
-
return `targets ${pointer} but request only has ${input.length} messages (indices 0-${input.length - 1}); add placeholder messages or adjust binding target`;
|
|
4601
|
-
}
|
|
4602
|
-
if (match[2] !== void 0) {
|
|
4603
|
-
const contentIndex = parseInt(match[2], 10);
|
|
4604
|
-
const msg = input[msgIndex];
|
|
4605
|
-
if (contentIndex >= msg.content.length) {
|
|
4606
|
-
return `targets ${pointer} but message ${msgIndex} only has ${msg.content.length} content blocks (indices 0-${msg.content.length - 1})`;
|
|
4607
|
-
}
|
|
4608
|
-
}
|
|
4609
|
-
return void 0;
|
|
4610
|
-
}
|
|
4611
|
-
function validateMapFanoutInput(nodeId, input) {
|
|
4612
|
-
const subnode = input.subnode;
|
|
4613
|
-
if ((subnode.type === WorkflowNodeTypesV1.LLMResponses || subnode.type === WorkflowNodeTypesV1.RouteSwitch) && subnode.input.bindings && subnode.input.bindings.length > 0) {
|
|
4614
|
-
throw new MapFanoutInputError(nodeId, "map.fanout subnode bindings are not allowed");
|
|
4615
|
-
}
|
|
4616
|
-
if (subnode.type !== WorkflowNodeTypesV1.TransformJSON) {
|
|
4617
|
-
return;
|
|
4618
|
-
}
|
|
4619
|
-
if (input.item_bindings && input.item_bindings.length > 0) {
|
|
4620
|
-
throw new MapFanoutInputError(
|
|
4621
|
-
nodeId,
|
|
4622
|
-
"map.fanout transform.json subnode cannot use item_bindings"
|
|
4623
|
-
);
|
|
4624
|
-
}
|
|
4625
|
-
const hasObject = !!subnode.input.object && Object.keys(subnode.input.object).length > 0;
|
|
4626
|
-
const hasMerge = !!subnode.input.merge && subnode.input.merge.length > 0;
|
|
4627
|
-
if (hasObject === hasMerge) {
|
|
4628
|
-
throw new MapFanoutInputError(
|
|
4629
|
-
nodeId,
|
|
4630
|
-
"map.fanout transform.json must provide exactly one of object or merge"
|
|
4631
|
-
);
|
|
4632
|
-
}
|
|
4633
|
-
if (hasObject) {
|
|
4634
|
-
for (const [key, value] of Object.entries(subnode.input.object ?? {})) {
|
|
4635
|
-
if (!key.trim()) continue;
|
|
4636
|
-
if (String(value.from) !== "item") {
|
|
4637
|
-
throw new MapFanoutInputError(
|
|
4638
|
-
nodeId,
|
|
4639
|
-
`map.fanout transform.json object.${key}.from must be "item"`
|
|
4640
|
-
);
|
|
4641
|
-
}
|
|
4642
|
-
}
|
|
4643
|
-
}
|
|
4644
|
-
if (hasMerge) {
|
|
4645
|
-
for (const [index, value] of (subnode.input.merge ?? []).entries()) {
|
|
4646
|
-
if (String(value.from) !== "item") {
|
|
4647
|
-
throw new MapFanoutInputError(
|
|
4648
|
-
nodeId,
|
|
4649
|
-
`map.fanout transform.json merge[${index}].from must be "item"`
|
|
4650
|
-
);
|
|
4651
|
-
}
|
|
4652
|
-
}
|
|
4653
|
-
}
|
|
4654
|
-
}
|
|
4655
|
-
var WorkflowBuilderV1 = class _WorkflowBuilderV1 {
|
|
4534
|
+
var WorkflowIntentBuilder = class _WorkflowIntentBuilder {
|
|
4656
4535
|
constructor(state = { nodes: [], edges: [], outputs: [] }) {
|
|
4657
4536
|
this.state = state;
|
|
4658
4537
|
}
|
|
4659
|
-
static new() {
|
|
4660
|
-
return new _WorkflowBuilderV1();
|
|
4661
|
-
}
|
|
4662
4538
|
with(patch) {
|
|
4663
|
-
return new
|
|
4539
|
+
return new _WorkflowIntentBuilder({
|
|
4664
4540
|
...this.state,
|
|
4665
|
-
...patch
|
|
4541
|
+
...patch,
|
|
4542
|
+
nodes: patch.nodes ?? this.state.nodes,
|
|
4543
|
+
edges: patch.edges ?? this.state.edges,
|
|
4544
|
+
outputs: patch.outputs ?? this.state.outputs
|
|
4666
4545
|
});
|
|
4667
4546
|
}
|
|
4668
4547
|
name(name) {
|
|
4669
|
-
return this.with({ name: name.trim()
|
|
4548
|
+
return this.with({ name: name.trim() });
|
|
4670
4549
|
}
|
|
4671
|
-
|
|
4672
|
-
return this.with({
|
|
4550
|
+
model(model) {
|
|
4551
|
+
return this.with({ model: model.trim() });
|
|
4673
4552
|
}
|
|
4674
4553
|
node(node) {
|
|
4675
4554
|
return this.with({ nodes: [...this.state.nodes, node] });
|
|
4676
4555
|
}
|
|
4677
|
-
|
|
4678
|
-
const
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4556
|
+
llm(id, configure) {
|
|
4557
|
+
const builder = new LLMNodeBuilder(id);
|
|
4558
|
+
const configured = configure ? configure(builder) : builder;
|
|
4559
|
+
return this.node(configured.build());
|
|
4560
|
+
}
|
|
4561
|
+
joinAll(id) {
|
|
4562
|
+
return this.node({ id, type: WorkflowNodeTypesLite.JoinAll });
|
|
4563
|
+
}
|
|
4564
|
+
joinAny(id, predicate) {
|
|
4565
|
+
return this.node({ id, type: WorkflowNodeTypesLite.JoinAny, predicate });
|
|
4566
|
+
}
|
|
4567
|
+
joinCollect(id, options) {
|
|
4689
4568
|
return this.node({
|
|
4690
4569
|
id,
|
|
4691
|
-
type:
|
|
4692
|
-
|
|
4570
|
+
type: WorkflowNodeTypesLite.JoinCollect,
|
|
4571
|
+
limit: options.limit,
|
|
4572
|
+
timeout_ms: options.timeoutMs,
|
|
4573
|
+
predicate: options.predicate
|
|
4693
4574
|
});
|
|
4694
4575
|
}
|
|
4695
|
-
|
|
4696
|
-
const wiredRequest = wireRequest(request);
|
|
4697
|
-
if (options.bindings) {
|
|
4698
|
-
validateBindingTargets(id, wiredRequest.input, options.bindings);
|
|
4699
|
-
}
|
|
4700
|
-
const input = {
|
|
4701
|
-
request: wiredRequest,
|
|
4702
|
-
...options.stream === void 0 ? {} : { stream: options.stream },
|
|
4703
|
-
...options.toolExecution === void 0 ? {} : { tool_execution: { mode: options.toolExecution } },
|
|
4704
|
-
...options.toolLimits === void 0 ? {} : { tool_limits: { ...options.toolLimits } },
|
|
4705
|
-
...options.bindings === void 0 ? {} : { bindings: options.bindings.slice() }
|
|
4706
|
-
};
|
|
4576
|
+
transformJSON(id, object, merge) {
|
|
4707
4577
|
return this.node({
|
|
4708
4578
|
id,
|
|
4709
|
-
type:
|
|
4710
|
-
|
|
4579
|
+
type: WorkflowNodeTypesLite.TransformJSON,
|
|
4580
|
+
object,
|
|
4581
|
+
merge
|
|
4711
4582
|
});
|
|
4712
4583
|
}
|
|
4713
|
-
|
|
4714
|
-
return this.node({ id, type: WorkflowNodeTypesV1.JoinAll });
|
|
4715
|
-
}
|
|
4716
|
-
joinAny(id, input) {
|
|
4584
|
+
mapFanout(id, options) {
|
|
4717
4585
|
return this.node({
|
|
4718
4586
|
id,
|
|
4719
|
-
type:
|
|
4720
|
-
|
|
4587
|
+
type: WorkflowNodeTypesLite.MapFanout,
|
|
4588
|
+
items_from: options.itemsFrom,
|
|
4589
|
+
items_from_input: options.itemsFromInput,
|
|
4590
|
+
items_path: options.itemsPath,
|
|
4591
|
+
subnode: options.subnode,
|
|
4592
|
+
max_parallelism: options.maxParallelism
|
|
4721
4593
|
});
|
|
4722
4594
|
}
|
|
4723
|
-
|
|
4724
|
-
return this.
|
|
4725
|
-
}
|
|
4726
|
-
transformJSON(id, input) {
|
|
4727
|
-
return this.node({ id, type: WorkflowNodeTypesV1.TransformJSON, input });
|
|
4728
|
-
}
|
|
4729
|
-
mapFanout(id, input) {
|
|
4730
|
-
validateMapFanoutInput(id, input);
|
|
4731
|
-
return this.node({ id, type: WorkflowNodeTypesV1.MapFanout, input });
|
|
4732
|
-
}
|
|
4733
|
-
edge(from, to, when) {
|
|
4734
|
-
return this.with({
|
|
4735
|
-
edges: [...this.state.edges, { from, to, ...when ? { when } : {} }]
|
|
4736
|
-
});
|
|
4595
|
+
edge(from, to) {
|
|
4596
|
+
return this.with({ edges: [...this.state.edges, { from, to }] });
|
|
4737
4597
|
}
|
|
4738
4598
|
output(name, from, pointer) {
|
|
4739
4599
|
return this.with({
|
|
4740
|
-
outputs: [
|
|
4741
|
-
...this.state.outputs,
|
|
4742
|
-
{ name, from, ...pointer ? { pointer } : {} }
|
|
4743
|
-
]
|
|
4600
|
+
outputs: [...this.state.outputs, { name, from, pointer }]
|
|
4744
4601
|
});
|
|
4745
4602
|
}
|
|
4746
4603
|
build() {
|
|
4747
|
-
const
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
const
|
|
4754
|
-
if (
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
const
|
|
4765
|
-
if (
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
if (af > bf) return 1;
|
|
4771
|
-
const ap = a.pointer ?? "";
|
|
4772
|
-
const bp = b.pointer ?? "";
|
|
4773
|
-
if (ap < bp) return -1;
|
|
4774
|
-
if (ap > bp) return 1;
|
|
4775
|
-
return 0;
|
|
4776
|
-
});
|
|
4604
|
+
const nodes = this.state.nodes.map((node) => ({
|
|
4605
|
+
...node,
|
|
4606
|
+
depends_on: node.depends_on ? [...node.depends_on] : void 0
|
|
4607
|
+
}));
|
|
4608
|
+
const byId = /* @__PURE__ */ new Map();
|
|
4609
|
+
for (let idx = 0; idx < nodes.length; idx++) {
|
|
4610
|
+
const id = nodes[idx].id;
|
|
4611
|
+
if (byId.has(id)) {
|
|
4612
|
+
throw new Error(`duplicate node id "${id}"`);
|
|
4613
|
+
}
|
|
4614
|
+
byId.set(id, idx);
|
|
4615
|
+
}
|
|
4616
|
+
for (const edge of this.state.edges) {
|
|
4617
|
+
const idx = byId.get(edge.to);
|
|
4618
|
+
if (idx === void 0) {
|
|
4619
|
+
throw new Error(`edge to unknown node ${edge.to}`);
|
|
4620
|
+
}
|
|
4621
|
+
const existing = nodes[idx].depends_on ?? [];
|
|
4622
|
+
if (!existing.includes(edge.from)) {
|
|
4623
|
+
existing.push(edge.from);
|
|
4624
|
+
}
|
|
4625
|
+
nodes[idx].depends_on = existing;
|
|
4626
|
+
}
|
|
4777
4627
|
return {
|
|
4778
|
-
kind: WorkflowKinds.
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
nodes
|
|
4782
|
-
...
|
|
4783
|
-
outputs
|
|
4628
|
+
kind: WorkflowKinds.WorkflowIntent,
|
|
4629
|
+
name: this.state.name,
|
|
4630
|
+
model: this.state.model,
|
|
4631
|
+
nodes,
|
|
4632
|
+
outputs: [...this.state.outputs]
|
|
4784
4633
|
};
|
|
4785
4634
|
}
|
|
4786
4635
|
};
|
|
4787
|
-
|
|
4788
|
-
|
|
4636
|
+
var LLMNodeBuilder = class {
|
|
4637
|
+
constructor(id) {
|
|
4638
|
+
this.node = { id, type: WorkflowNodeTypesLite.LLM };
|
|
4639
|
+
}
|
|
4640
|
+
system(text) {
|
|
4641
|
+
this.node.system = text;
|
|
4642
|
+
return this;
|
|
4643
|
+
}
|
|
4644
|
+
user(text) {
|
|
4645
|
+
this.node.user = text;
|
|
4646
|
+
return this;
|
|
4647
|
+
}
|
|
4648
|
+
input(items) {
|
|
4649
|
+
this.node.input = items;
|
|
4650
|
+
return this;
|
|
4651
|
+
}
|
|
4652
|
+
model(model) {
|
|
4653
|
+
this.node.model = model;
|
|
4654
|
+
return this;
|
|
4655
|
+
}
|
|
4656
|
+
stream(enabled) {
|
|
4657
|
+
this.node.stream = enabled;
|
|
4658
|
+
return this;
|
|
4659
|
+
}
|
|
4660
|
+
toolExecution(mode) {
|
|
4661
|
+
this.node.tool_execution = { mode };
|
|
4662
|
+
return this;
|
|
4663
|
+
}
|
|
4664
|
+
tools(tools) {
|
|
4665
|
+
this.node.tools = tools;
|
|
4666
|
+
return this;
|
|
4667
|
+
}
|
|
4668
|
+
build() {
|
|
4669
|
+
return { ...this.node };
|
|
4670
|
+
}
|
|
4671
|
+
};
|
|
4672
|
+
function workflowIntent() {
|
|
4673
|
+
return new WorkflowIntentBuilder();
|
|
4674
|
+
}
|
|
4675
|
+
function llm(id, configure) {
|
|
4676
|
+
const builder = new LLMNodeBuilder(parseNodeId(id));
|
|
4677
|
+
const configured = configure ? configure(builder) : builder;
|
|
4678
|
+
return configured.build();
|
|
4679
|
+
}
|
|
4680
|
+
function chain(steps, options) {
|
|
4681
|
+
let builder = new WorkflowIntentBuilder();
|
|
4682
|
+
if (options?.name) {
|
|
4683
|
+
builder = builder.name(options.name);
|
|
4684
|
+
}
|
|
4685
|
+
if (options?.model) {
|
|
4686
|
+
builder = builder.model(options.model);
|
|
4687
|
+
}
|
|
4688
|
+
for (const step of steps) {
|
|
4689
|
+
builder = builder.node(step);
|
|
4690
|
+
}
|
|
4691
|
+
for (let i = 1; i < steps.length; i++) {
|
|
4692
|
+
builder = builder.edge(steps[i - 1].id, steps[i].id);
|
|
4693
|
+
}
|
|
4694
|
+
return builder;
|
|
4695
|
+
}
|
|
4696
|
+
function parallel(steps, options) {
|
|
4697
|
+
let builder = new WorkflowIntentBuilder();
|
|
4698
|
+
const joinId = parseNodeId(options?.joinId ?? "join");
|
|
4699
|
+
if (options?.name) {
|
|
4700
|
+
builder = builder.name(options.name);
|
|
4701
|
+
}
|
|
4702
|
+
if (options?.model) {
|
|
4703
|
+
builder = builder.model(options.model);
|
|
4704
|
+
}
|
|
4705
|
+
for (const step of steps) {
|
|
4706
|
+
builder = builder.node(step);
|
|
4707
|
+
}
|
|
4708
|
+
builder = builder.joinAll(joinId);
|
|
4709
|
+
for (const step of steps) {
|
|
4710
|
+
builder = builder.edge(step.id, joinId);
|
|
4711
|
+
}
|
|
4712
|
+
return builder;
|
|
4789
4713
|
}
|
|
4790
4714
|
|
|
4791
4715
|
// src/testing.ts
|
|
@@ -5008,260 +4932,26 @@ var generated_exports = {};
|
|
|
5008
4932
|
// src/workflow/index.ts
|
|
5009
4933
|
var workflow_exports = {};
|
|
5010
4934
|
__export(workflow_exports, {
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
FanoutReduceV1: () => FanoutReduceV1,
|
|
5014
|
-
KindV1: () => KindV1,
|
|
4935
|
+
KindIntent: () => KindIntent,
|
|
4936
|
+
LLMNodeBuilder: () => LLMNodeBuilder,
|
|
5015
4937
|
LLM_TEXT_OUTPUT: () => LLM_TEXT_OUTPUT,
|
|
5016
4938
|
LLM_USER_MESSAGE_TEXT: () => LLM_USER_MESSAGE_TEXT,
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
ToolExecutionModes: () => ToolExecutionModes,
|
|
5020
|
-
WorkflowBuilderV1: () => WorkflowBuilderV1,
|
|
5021
|
-
bindFrom: () => bindFrom,
|
|
5022
|
-
bindToPlaceholder: () => bindToPlaceholder,
|
|
5023
|
-
bindToPointer: () => bindToPointer,
|
|
4939
|
+
NodeTypesLite: () => NodeTypesLite,
|
|
4940
|
+
WorkflowIntentBuilder: () => WorkflowIntentBuilder,
|
|
5024
4941
|
parseNodeId: () => parseNodeId,
|
|
5025
4942
|
parseOutputName: () => parseOutputName,
|
|
5026
4943
|
parsePlanHash: () => parsePlanHash,
|
|
5027
4944
|
parseRunId: () => parseRunId,
|
|
5028
|
-
|
|
5029
|
-
whenOutputExists: () => whenOutputExists,
|
|
5030
|
-
whenOutputMatches: () => whenOutputMatches,
|
|
5031
|
-
whenStatusEquals: () => whenStatusEquals,
|
|
5032
|
-
whenStatusExists: () => whenStatusExists,
|
|
5033
|
-
whenStatusMatches: () => whenStatusMatches,
|
|
5034
|
-
workflowV1: () => workflowV1
|
|
4945
|
+
workflowIntent: () => workflowIntent
|
|
5035
4946
|
});
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
function whenOutputExists(path) {
|
|
5045
|
-
return { source: "node_output", op: "exists", path };
|
|
5046
|
-
}
|
|
5047
|
-
function whenStatusEquals(path, value) {
|
|
5048
|
-
return { source: "node_status", op: "equals", path, value };
|
|
5049
|
-
}
|
|
5050
|
-
function whenStatusMatches(path, pattern) {
|
|
5051
|
-
return { source: "node_status", op: "matches", path, value: pattern };
|
|
5052
|
-
}
|
|
5053
|
-
function whenStatusExists(path) {
|
|
5054
|
-
return { source: "node_status", op: "exists", path };
|
|
5055
|
-
}
|
|
5056
|
-
function bindToPlaceholder(from, placeholder, opts) {
|
|
5057
|
-
return {
|
|
5058
|
-
from,
|
|
5059
|
-
...opts?.pointer ? { pointer: opts.pointer } : {},
|
|
5060
|
-
to_placeholder: placeholder,
|
|
5061
|
-
encoding: opts?.encoding ?? "json_string"
|
|
5062
|
-
};
|
|
5063
|
-
}
|
|
5064
|
-
function bindToPointer(from, to, opts) {
|
|
5065
|
-
return {
|
|
5066
|
-
from,
|
|
5067
|
-
...opts?.pointer ? { pointer: opts.pointer } : {},
|
|
5068
|
-
to,
|
|
5069
|
-
encoding: opts?.encoding ?? "json_string"
|
|
5070
|
-
};
|
|
5071
|
-
}
|
|
5072
|
-
function bindFrom(from) {
|
|
5073
|
-
return new BindingBuilder(from);
|
|
5074
|
-
}
|
|
5075
|
-
var BindingBuilder = class {
|
|
5076
|
-
constructor(from) {
|
|
5077
|
-
this._encoding = "json_string";
|
|
5078
|
-
this._from = from;
|
|
5079
|
-
}
|
|
5080
|
-
/**
|
|
5081
|
-
* Set the source pointer to extract from the node's output.
|
|
5082
|
-
*/
|
|
5083
|
-
pointer(ptr) {
|
|
5084
|
-
this._pointer = ptr;
|
|
5085
|
-
return this;
|
|
5086
|
-
}
|
|
5087
|
-
/**
|
|
5088
|
-
* Set the destination JSON pointer in the request.
|
|
5089
|
-
*/
|
|
5090
|
-
to(ptr) {
|
|
5091
|
-
this._to = ptr;
|
|
5092
|
-
this._toPlaceholder = void 0;
|
|
5093
|
-
return this;
|
|
5094
|
-
}
|
|
5095
|
-
/**
|
|
5096
|
-
* Set the destination placeholder name.
|
|
5097
|
-
*/
|
|
5098
|
-
toPlaceholder(name) {
|
|
5099
|
-
this._toPlaceholder = name;
|
|
5100
|
-
this._to = void 0;
|
|
5101
|
-
return this;
|
|
5102
|
-
}
|
|
5103
|
-
/**
|
|
5104
|
-
* Set the encoding for the binding value.
|
|
5105
|
-
*/
|
|
5106
|
-
encoding(enc) {
|
|
5107
|
-
this._encoding = enc;
|
|
5108
|
-
return this;
|
|
5109
|
-
}
|
|
5110
|
-
/**
|
|
5111
|
-
* Build the binding object.
|
|
5112
|
-
*/
|
|
5113
|
-
build() {
|
|
5114
|
-
const binding = {
|
|
5115
|
-
from: this._from,
|
|
5116
|
-
encoding: this._encoding
|
|
5117
|
-
};
|
|
5118
|
-
if (this._pointer) binding.pointer = this._pointer;
|
|
5119
|
-
if (this._to) binding.to = this._to;
|
|
5120
|
-
if (this._toPlaceholder) binding.to_placeholder = this._toPlaceholder;
|
|
5121
|
-
return binding;
|
|
5122
|
-
}
|
|
5123
|
-
};
|
|
5124
|
-
|
|
5125
|
-
// src/workflow/patterns_v1.ts
|
|
5126
|
-
function wireRequest2(req) {
|
|
5127
|
-
const raw = req;
|
|
5128
|
-
if (raw && typeof raw === "object") {
|
|
5129
|
-
if ("input" in raw) {
|
|
5130
|
-
return req;
|
|
5131
|
-
}
|
|
5132
|
-
if ("body" in raw) {
|
|
5133
|
-
return raw.body ?? {};
|
|
5134
|
-
}
|
|
5135
|
-
}
|
|
5136
|
-
return asInternal(req).body;
|
|
5137
|
-
}
|
|
5138
|
-
var RouterV1 = class {
|
|
5139
|
-
constructor(config) {
|
|
5140
|
-
this.config = config;
|
|
5141
|
-
}
|
|
5142
|
-
/**
|
|
5143
|
-
* Build the workflow specification.
|
|
5144
|
-
*/
|
|
5145
|
-
build() {
|
|
5146
|
-
const {
|
|
5147
|
-
name,
|
|
5148
|
-
classifier,
|
|
5149
|
-
classifierId = "router",
|
|
5150
|
-
routePath = "$.route",
|
|
5151
|
-
routes,
|
|
5152
|
-
aggregator,
|
|
5153
|
-
outputName = "final"
|
|
5154
|
-
} = this.config;
|
|
5155
|
-
let builder = new WorkflowBuilderV1();
|
|
5156
|
-
if (name) {
|
|
5157
|
-
builder = builder.name(name);
|
|
5158
|
-
}
|
|
5159
|
-
builder = builder.routeSwitch(classifierId, classifier);
|
|
5160
|
-
const joinId = "__router_join";
|
|
5161
|
-
builder = builder.joinAny(joinId);
|
|
5162
|
-
for (let i = 0; i < routes.length; i++) {
|
|
5163
|
-
const route = routes[i];
|
|
5164
|
-
const handlerId = route.id ?? `handler_${i}`;
|
|
5165
|
-
builder = builder.llmResponses(handlerId, route.handler, {
|
|
5166
|
-
bindings: route.bindings
|
|
5167
|
-
});
|
|
5168
|
-
builder = builder.edge(classifierId, handlerId, whenOutputEquals(routePath, route.value));
|
|
5169
|
-
builder = builder.edge(handlerId, joinId);
|
|
5170
|
-
}
|
|
5171
|
-
if (aggregator) {
|
|
5172
|
-
const aggId = aggregator.id ?? "aggregate";
|
|
5173
|
-
const placeholder = aggregator.placeholder ?? "route_output";
|
|
5174
|
-
builder = builder.llmResponses(aggId, aggregator.request, {
|
|
5175
|
-
bindings: [bindToPlaceholder(joinId, placeholder)]
|
|
5176
|
-
});
|
|
5177
|
-
builder = builder.edge(joinId, aggId);
|
|
5178
|
-
builder = builder.output(outputName, aggId);
|
|
5179
|
-
} else {
|
|
5180
|
-
builder = builder.output(outputName, joinId);
|
|
5181
|
-
}
|
|
5182
|
-
return builder.build();
|
|
5183
|
-
}
|
|
5184
|
-
};
|
|
5185
|
-
var FanoutReduceV1 = class {
|
|
5186
|
-
constructor(config) {
|
|
5187
|
-
this.config = config;
|
|
5188
|
-
}
|
|
5189
|
-
/**
|
|
5190
|
-
* Build the workflow specification.
|
|
5191
|
-
*/
|
|
5192
|
-
build() {
|
|
5193
|
-
const {
|
|
5194
|
-
name,
|
|
5195
|
-
generator,
|
|
5196
|
-
generatorId = "generator",
|
|
5197
|
-
itemsPath = "/items",
|
|
5198
|
-
mapper,
|
|
5199
|
-
mapperPlaceholder = "item",
|
|
5200
|
-
maxParallelism = 4,
|
|
5201
|
-
reducer,
|
|
5202
|
-
reducerId = "reducer",
|
|
5203
|
-
reducerBinding,
|
|
5204
|
-
outputName = "final"
|
|
5205
|
-
} = this.config;
|
|
5206
|
-
let builder = new WorkflowBuilderV1();
|
|
5207
|
-
if (name) {
|
|
5208
|
-
builder = builder.name(name);
|
|
5209
|
-
}
|
|
5210
|
-
builder = builder.llmResponses(generatorId, generator);
|
|
5211
|
-
const fanoutId = "__fanout";
|
|
5212
|
-
const itemBindings = [
|
|
5213
|
-
{
|
|
5214
|
-
path: "$",
|
|
5215
|
-
to_placeholder: mapperPlaceholder,
|
|
5216
|
-
encoding: "json_string"
|
|
5217
|
-
}
|
|
5218
|
-
];
|
|
5219
|
-
const mapperRequest = wireRequest2(mapper);
|
|
5220
|
-
builder = builder.mapFanout(fanoutId, {
|
|
5221
|
-
items: { from: generatorId, path: itemsPath },
|
|
5222
|
-
item_bindings: itemBindings,
|
|
5223
|
-
subnode: {
|
|
5224
|
-
id: "__mapper",
|
|
5225
|
-
type: "llm.responses",
|
|
5226
|
-
input: { request: mapperRequest }
|
|
5227
|
-
},
|
|
5228
|
-
max_parallelism: maxParallelism
|
|
5229
|
-
});
|
|
5230
|
-
builder = builder.edge(generatorId, fanoutId);
|
|
5231
|
-
const pointer = reducerBinding?.pointer ?? "/results";
|
|
5232
|
-
const binding = reducerBinding?.placeholder ? bindToPlaceholder(fanoutId, reducerBinding.placeholder, { pointer }) : {
|
|
5233
|
-
from: fanoutId,
|
|
5234
|
-
pointer,
|
|
5235
|
-
to: reducerBinding?.to ?? "/input/0/content/0/text",
|
|
5236
|
-
encoding: "json_string"
|
|
5237
|
-
};
|
|
5238
|
-
builder = builder.llmResponses(reducerId, reducer, {
|
|
5239
|
-
bindings: [binding]
|
|
5240
|
-
});
|
|
5241
|
-
builder = builder.edge(fanoutId, reducerId);
|
|
5242
|
-
builder = builder.output(outputName, reducerId);
|
|
5243
|
-
return builder.build();
|
|
5244
|
-
}
|
|
5245
|
-
};
|
|
5246
|
-
|
|
5247
|
-
// src/workflow/index.ts
|
|
5248
|
-
var KindV1 = WorkflowKinds.WorkflowV1;
|
|
5249
|
-
var NodeTypesV1 = {
|
|
5250
|
-
LLMResponses: WorkflowNodeTypesV1.LLMResponses,
|
|
5251
|
-
RouteSwitch: WorkflowNodeTypesV1.RouteSwitch,
|
|
5252
|
-
JoinAll: WorkflowNodeTypesV1.JoinAll,
|
|
5253
|
-
JoinAny: WorkflowNodeTypesV1.JoinAny,
|
|
5254
|
-
JoinCollect: WorkflowNodeTypesV1.JoinCollect,
|
|
5255
|
-
TransformJSON: WorkflowNodeTypesV1.TransformJSON,
|
|
5256
|
-
MapFanout: WorkflowNodeTypesV1.MapFanout
|
|
5257
|
-
};
|
|
5258
|
-
var BindingEncodings = {
|
|
5259
|
-
JSON: "json",
|
|
5260
|
-
JSONString: "json_string"
|
|
5261
|
-
};
|
|
5262
|
-
var ToolExecutionModes = {
|
|
5263
|
-
Server: "server",
|
|
5264
|
-
Client: "client"
|
|
4947
|
+
var KindIntent = WorkflowKinds.WorkflowIntent;
|
|
4948
|
+
var NodeTypesLite = {
|
|
4949
|
+
LLM: WorkflowNodeTypesLite.LLM,
|
|
4950
|
+
JoinAll: WorkflowNodeTypesLite.JoinAll,
|
|
4951
|
+
JoinAny: WorkflowNodeTypesLite.JoinAny,
|
|
4952
|
+
JoinCollect: WorkflowNodeTypesLite.JoinCollect,
|
|
4953
|
+
TransformJSON: WorkflowNodeTypesLite.TransformJSON,
|
|
4954
|
+
MapFanout: WorkflowNodeTypesLite.MapFanout
|
|
5265
4955
|
};
|
|
5266
4956
|
|
|
5267
4957
|
// src/index.ts
|
|
@@ -5328,7 +5018,6 @@ export {
|
|
|
5328
5018
|
APIError,
|
|
5329
5019
|
AuthClient,
|
|
5330
5020
|
BillingProviders,
|
|
5331
|
-
BindingTargetError,
|
|
5332
5021
|
ConfigError,
|
|
5333
5022
|
ContentPartTypes,
|
|
5334
5023
|
CustomerResponsesClient,
|
|
@@ -5350,6 +5039,7 @@ export {
|
|
|
5350
5039
|
LLMInputPath,
|
|
5351
5040
|
LLMInputSystemText,
|
|
5352
5041
|
LLMInputUserText,
|
|
5042
|
+
LLMNodeBuilder,
|
|
5353
5043
|
LLMOutput,
|
|
5354
5044
|
LLMOutputContentItemPath,
|
|
5355
5045
|
LLMOutputContentPath,
|
|
@@ -5358,7 +5048,6 @@ export {
|
|
|
5358
5048
|
LLM_TEXT_OUTPUT,
|
|
5359
5049
|
LLM_USER_MESSAGE_TEXT,
|
|
5360
5050
|
LocalSession,
|
|
5361
|
-
MapFanoutInputError,
|
|
5362
5051
|
MemorySessionStore,
|
|
5363
5052
|
MessageRoles,
|
|
5364
5053
|
ModelRelay,
|
|
@@ -5390,10 +5079,10 @@ export {
|
|
|
5390
5079
|
TransportError,
|
|
5391
5080
|
WORKFLOWS_COMPILE_PATH,
|
|
5392
5081
|
WebToolIntents,
|
|
5393
|
-
|
|
5082
|
+
WorkflowIntentBuilder,
|
|
5394
5083
|
WorkflowKinds,
|
|
5395
|
-
|
|
5396
|
-
|
|
5084
|
+
WorkflowNodeTypesLite as WorkflowNodeTypes,
|
|
5085
|
+
WorkflowNodeTypesLite,
|
|
5397
5086
|
WorkflowValidationError,
|
|
5398
5087
|
WorkflowsClient,
|
|
5399
5088
|
asModelId,
|
|
@@ -5403,6 +5092,7 @@ export {
|
|
|
5403
5092
|
assistantMessageWithToolCalls,
|
|
5404
5093
|
buildDelayedNDJSONResponse,
|
|
5405
5094
|
buildNDJSONResponse,
|
|
5095
|
+
chain,
|
|
5406
5096
|
createAccessTokenAuth,
|
|
5407
5097
|
createApiKeyAuth,
|
|
5408
5098
|
createAssistantMessage,
|
|
@@ -5430,12 +5120,14 @@ export {
|
|
|
5430
5120
|
hasRetryableErrors,
|
|
5431
5121
|
hasToolCalls,
|
|
5432
5122
|
isSecretKey,
|
|
5123
|
+
llm,
|
|
5433
5124
|
mergeMetrics,
|
|
5434
5125
|
mergeTrace,
|
|
5435
5126
|
modelToString,
|
|
5436
5127
|
normalizeModelId,
|
|
5437
5128
|
normalizeStopReason,
|
|
5438
5129
|
outputFormatFromZod,
|
|
5130
|
+
parallel,
|
|
5439
5131
|
parseApiKey,
|
|
5440
5132
|
parseErrorResponse,
|
|
5441
5133
|
parseNodeId,
|
|
@@ -5451,12 +5143,9 @@ export {
|
|
|
5451
5143
|
toolChoiceNone,
|
|
5452
5144
|
toolChoiceRequired,
|
|
5453
5145
|
toolResultMessage,
|
|
5454
|
-
transformJSONMerge,
|
|
5455
|
-
transformJSONObject,
|
|
5456
|
-
transformJSONValue,
|
|
5457
5146
|
tryParseToolArgs,
|
|
5458
5147
|
validateWithZod,
|
|
5459
5148
|
workflow_exports as workflow,
|
|
5460
|
-
|
|
5149
|
+
workflowIntent,
|
|
5461
5150
|
zodToJsonSchema
|
|
5462
5151
|
};
|