@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/dist/index.cjs CHANGED
@@ -33,7 +33,6 @@ __export(index_exports, {
33
33
  APIError: () => APIError,
34
34
  AuthClient: () => AuthClient,
35
35
  BillingProviders: () => BillingProviders,
36
- BindingTargetError: () => BindingTargetError,
37
36
  ConfigError: () => ConfigError,
38
37
  ContentPartTypes: () => ContentPartTypes,
39
38
  CustomerResponsesClient: () => CustomerResponsesClient,
@@ -55,6 +54,7 @@ __export(index_exports, {
55
54
  LLMInputPath: () => LLMInputPath,
56
55
  LLMInputSystemText: () => LLMInputSystemText,
57
56
  LLMInputUserText: () => LLMInputUserText,
57
+ LLMNodeBuilder: () => LLMNodeBuilder,
58
58
  LLMOutput: () => LLMOutput,
59
59
  LLMOutputContentItemPath: () => LLMOutputContentItemPath,
60
60
  LLMOutputContentPath: () => LLMOutputContentPath,
@@ -63,7 +63,6 @@ __export(index_exports, {
63
63
  LLM_TEXT_OUTPUT: () => LLM_TEXT_OUTPUT,
64
64
  LLM_USER_MESSAGE_TEXT: () => LLM_USER_MESSAGE_TEXT,
65
65
  LocalSession: () => LocalSession,
66
- MapFanoutInputError: () => MapFanoutInputError,
67
66
  MemorySessionStore: () => MemorySessionStore,
68
67
  MessageRoles: () => MessageRoles,
69
68
  ModelRelay: () => ModelRelay,
@@ -95,10 +94,10 @@ __export(index_exports, {
95
94
  TransportError: () => TransportError,
96
95
  WORKFLOWS_COMPILE_PATH: () => WORKFLOWS_COMPILE_PATH,
97
96
  WebToolIntents: () => WebToolIntents,
98
- WorkflowBuilderV1: () => WorkflowBuilderV1,
97
+ WorkflowIntentBuilder: () => WorkflowIntentBuilder,
99
98
  WorkflowKinds: () => WorkflowKinds,
100
- WorkflowNodeTypes: () => WorkflowNodeTypesV1,
101
- WorkflowNodeTypesV1: () => WorkflowNodeTypesV1,
99
+ WorkflowNodeTypes: () => WorkflowNodeTypesLite,
100
+ WorkflowNodeTypesLite: () => WorkflowNodeTypesLite,
102
101
  WorkflowValidationError: () => WorkflowValidationError,
103
102
  WorkflowsClient: () => WorkflowsClient,
104
103
  asModelId: () => asModelId,
@@ -108,6 +107,7 @@ __export(index_exports, {
108
107
  assistantMessageWithToolCalls: () => assistantMessageWithToolCalls,
109
108
  buildDelayedNDJSONResponse: () => buildDelayedNDJSONResponse,
110
109
  buildNDJSONResponse: () => buildNDJSONResponse,
110
+ chain: () => chain,
111
111
  createAccessTokenAuth: () => createAccessTokenAuth,
112
112
  createApiKeyAuth: () => createApiKeyAuth,
113
113
  createAssistantMessage: () => createAssistantMessage,
@@ -135,12 +135,14 @@ __export(index_exports, {
135
135
  hasRetryableErrors: () => hasRetryableErrors,
136
136
  hasToolCalls: () => hasToolCalls,
137
137
  isSecretKey: () => isSecretKey,
138
+ llm: () => llm,
138
139
  mergeMetrics: () => mergeMetrics,
139
140
  mergeTrace: () => mergeTrace,
140
141
  modelToString: () => modelToString,
141
142
  normalizeModelId: () => normalizeModelId,
142
143
  normalizeStopReason: () => normalizeStopReason,
143
144
  outputFormatFromZod: () => outputFormatFromZod,
145
+ parallel: () => parallel,
144
146
  parseApiKey: () => parseApiKey,
145
147
  parseErrorResponse: () => parseErrorResponse,
146
148
  parseNodeId: () => parseNodeId,
@@ -156,13 +158,10 @@ __export(index_exports, {
156
158
  toolChoiceNone: () => toolChoiceNone,
157
159
  toolChoiceRequired: () => toolChoiceRequired,
158
160
  toolResultMessage: () => toolResultMessage,
159
- transformJSONMerge: () => transformJSONMerge,
160
- transformJSONObject: () => transformJSONObject,
161
- transformJSONValue: () => transformJSONValue,
162
161
  tryParseToolArgs: () => tryParseToolArgs,
163
162
  validateWithZod: () => validateWithZod,
164
163
  workflow: () => workflow_exports,
165
- workflowV1: () => workflowV1,
164
+ workflowIntent: () => workflowIntent,
166
165
  zodToJsonSchema: () => zodToJsonSchema
167
166
  });
168
167
  module.exports = __toCommonJS(index_exports);
@@ -416,7 +415,7 @@ function isSecretKey(key) {
416
415
  // package.json
417
416
  var package_default = {
418
417
  name: "@modelrelay/sdk",
419
- version: "4.0.0",
418
+ version: "5.3.0",
420
419
  description: "TypeScript SDK for the ModelRelay API",
421
420
  type: "module",
422
421
  main: "dist/index.cjs",
@@ -2968,11 +2967,10 @@ function parseOutputName(raw) {
2968
2967
 
2969
2968
  // src/runs_types.ts
2970
2969
  var WorkflowKinds = {
2971
- WorkflowV1: "workflow.v1"
2970
+ WorkflowIntent: "workflow"
2972
2971
  };
2973
- var WorkflowNodeTypesV1 = {
2974
- LLMResponses: "llm.responses",
2975
- RouteSwitch: "route.switch",
2972
+ var WorkflowNodeTypesLite = {
2973
+ LLM: "llm",
2976
2974
  JoinAll: "join.all",
2977
2975
  JoinAny: "join.any",
2978
2976
  JoinCollect: "join.collect",
@@ -3343,6 +3341,9 @@ var RunsClient = class {
3343
3341
  if (options.idempotencyKey?.trim()) {
3344
3342
  payload.options = { idempotency_key: options.idempotencyKey.trim() };
3345
3343
  }
3344
+ if (options.input) {
3345
+ payload.input = options.input;
3346
+ }
3346
3347
  const out = await this.http.json(RUNS_PATH, {
3347
3348
  method: "POST",
3348
3349
  headers,
@@ -3533,7 +3534,7 @@ var WorkflowsClient = class {
3533
3534
  this.metrics = cfg.metrics;
3534
3535
  this.trace = cfg.trace;
3535
3536
  }
3536
- async compileV1(spec, options = {}) {
3537
+ async compile(spec, options = {}) {
3537
3538
  const metrics = mergeMetrics(this.metrics, options.metrics);
3538
3539
  const trace = mergeTrace(this.trace, options.trace);
3539
3540
  const authHeaders = await this.auth.authForResponses();
@@ -4038,21 +4039,16 @@ var LocalSession = class _LocalSession {
4038
4039
  const input = await this.buildInput(options);
4039
4040
  const tools = mergeTools(this.defaultTools, options.tools);
4040
4041
  const spec = {
4041
- kind: "workflow.v1",
4042
+ kind: "workflow",
4042
4043
  name: `session-${this.id}-turn-${this.nextSeq}`,
4044
+ model: options.model || this.defaultModel,
4043
4045
  nodes: [
4044
4046
  {
4045
4047
  id: "main",
4046
- type: "llm.responses",
4047
- input: {
4048
- request: {
4049
- provider: options.provider || this.defaultProvider,
4050
- model: options.model || this.defaultModel,
4051
- input,
4052
- tools
4053
- },
4054
- tool_execution: this.toolRegistry ? { mode: "client" } : void 0
4055
- }
4048
+ type: "llm",
4049
+ input,
4050
+ tools,
4051
+ tool_execution: this.toolRegistry ? { mode: "client" } : void 0
4056
4052
  }
4057
4053
  ],
4058
4054
  outputs: [{ name: "result", from: "main" }]
@@ -4533,21 +4529,16 @@ var RemoteSession = class _RemoteSession {
4533
4529
  const input = await this.buildInput(options);
4534
4530
  const tools = mergeTools2(this.defaultTools, options.tools);
4535
4531
  const spec = {
4536
- kind: "workflow.v1",
4532
+ kind: "workflow",
4537
4533
  name: `session-${this.id}-turn-${this.nextSeq}`,
4534
+ model: options.model || this.defaultModel,
4538
4535
  nodes: [
4539
4536
  {
4540
4537
  id: "main",
4541
- type: "llm.responses",
4542
- input: {
4543
- request: {
4544
- provider: options.provider || this.defaultProvider,
4545
- model: options.model || this.defaultModel,
4546
- input,
4547
- tools
4548
- },
4549
- tool_execution: this.toolRegistry ? { mode: "client" } : void 0
4550
- }
4538
+ type: "llm",
4539
+ input,
4540
+ tools,
4541
+ tool_execution: this.toolRegistry ? { mode: "client" } : void 0
4551
4542
  }
4552
4543
  ],
4553
4544
  outputs: [{ name: "result", from: "main" }]
@@ -5703,253 +5694,185 @@ function JoinOutput(nodeId) {
5703
5694
  // src/workflow_builder.ts
5704
5695
  var LLM_TEXT_OUTPUT = LLMOutputText;
5705
5696
  var LLM_USER_MESSAGE_TEXT = LLMInputUserText;
5706
- function transformJSONValue(from, pointer) {
5707
- return pointer ? { from, pointer } : { from };
5708
- }
5709
- function transformJSONObject(object) {
5710
- return { object };
5711
- }
5712
- function transformJSONMerge(merge) {
5713
- return { merge: merge.slice() };
5714
- }
5715
- function wireRequest(req) {
5716
- const raw = req;
5717
- if (raw && typeof raw === "object") {
5718
- if ("input" in raw) {
5719
- return req;
5720
- }
5721
- if ("body" in raw) {
5722
- return raw.body ?? {};
5723
- }
5724
- }
5725
- return asInternal(req).body;
5726
- }
5727
- var INPUT_POINTER_PATTERN = /^\/input\/(\d+)(?:\/content\/(\d+))?/;
5728
- var BindingTargetError = class extends Error {
5729
- constructor(nodeId, bindingIndex, pointer, message) {
5730
- super(`node "${nodeId}" binding ${bindingIndex}: ${message}`);
5731
- this.name = "BindingTargetError";
5732
- this.nodeId = nodeId;
5733
- this.bindingIndex = bindingIndex;
5734
- this.pointer = pointer;
5735
- }
5736
- };
5737
- var MapFanoutInputError = class extends Error {
5738
- constructor(nodeId, message) {
5739
- super(`node "${nodeId}": ${message}`);
5740
- this.name = "MapFanoutInputError";
5741
- this.nodeId = nodeId;
5742
- }
5743
- };
5744
- function validateBindingTargets(nodeId, input, bindings) {
5745
- for (let i = 0; i < bindings.length; i++) {
5746
- const binding = bindings[i];
5747
- if (!binding.to) continue;
5748
- const error = validateInputPointer(binding.to, input);
5749
- if (error) {
5750
- throw new BindingTargetError(nodeId, i, binding.to, error);
5751
- }
5752
- }
5753
- }
5754
- function validateInputPointer(pointer, input) {
5755
- if (!pointer.startsWith("/input/")) {
5756
- return void 0;
5757
- }
5758
- const match = pointer.match(INPUT_POINTER_PATTERN);
5759
- if (!match) {
5760
- return void 0;
5761
- }
5762
- const msgIndex = parseInt(match[1], 10);
5763
- if (msgIndex >= input.length) {
5764
- return `targets ${pointer} but request only has ${input.length} messages (indices 0-${input.length - 1}); add placeholder messages or adjust binding target`;
5765
- }
5766
- if (match[2] !== void 0) {
5767
- const contentIndex = parseInt(match[2], 10);
5768
- const msg = input[msgIndex];
5769
- if (contentIndex >= msg.content.length) {
5770
- return `targets ${pointer} but message ${msgIndex} only has ${msg.content.length} content blocks (indices 0-${msg.content.length - 1})`;
5771
- }
5772
- }
5773
- return void 0;
5774
- }
5775
- function validateMapFanoutInput(nodeId, input) {
5776
- const subnode = input.subnode;
5777
- if ((subnode.type === WorkflowNodeTypesV1.LLMResponses || subnode.type === WorkflowNodeTypesV1.RouteSwitch) && subnode.input.bindings && subnode.input.bindings.length > 0) {
5778
- throw new MapFanoutInputError(nodeId, "map.fanout subnode bindings are not allowed");
5779
- }
5780
- if (subnode.type !== WorkflowNodeTypesV1.TransformJSON) {
5781
- return;
5782
- }
5783
- if (input.item_bindings && input.item_bindings.length > 0) {
5784
- throw new MapFanoutInputError(
5785
- nodeId,
5786
- "map.fanout transform.json subnode cannot use item_bindings"
5787
- );
5788
- }
5789
- const hasObject = !!subnode.input.object && Object.keys(subnode.input.object).length > 0;
5790
- const hasMerge = !!subnode.input.merge && subnode.input.merge.length > 0;
5791
- if (hasObject === hasMerge) {
5792
- throw new MapFanoutInputError(
5793
- nodeId,
5794
- "map.fanout transform.json must provide exactly one of object or merge"
5795
- );
5796
- }
5797
- if (hasObject) {
5798
- for (const [key, value] of Object.entries(subnode.input.object ?? {})) {
5799
- if (!key.trim()) continue;
5800
- if (String(value.from) !== "item") {
5801
- throw new MapFanoutInputError(
5802
- nodeId,
5803
- `map.fanout transform.json object.${key}.from must be "item"`
5804
- );
5805
- }
5806
- }
5807
- }
5808
- if (hasMerge) {
5809
- for (const [index, value] of (subnode.input.merge ?? []).entries()) {
5810
- if (String(value.from) !== "item") {
5811
- throw new MapFanoutInputError(
5812
- nodeId,
5813
- `map.fanout transform.json merge[${index}].from must be "item"`
5814
- );
5815
- }
5816
- }
5817
- }
5818
- }
5819
- var WorkflowBuilderV1 = class _WorkflowBuilderV1 {
5697
+ var WorkflowIntentBuilder = class _WorkflowIntentBuilder {
5820
5698
  constructor(state = { nodes: [], edges: [], outputs: [] }) {
5821
5699
  this.state = state;
5822
5700
  }
5823
- static new() {
5824
- return new _WorkflowBuilderV1();
5825
- }
5826
5701
  with(patch) {
5827
- return new _WorkflowBuilderV1({
5702
+ return new _WorkflowIntentBuilder({
5828
5703
  ...this.state,
5829
- ...patch
5704
+ ...patch,
5705
+ nodes: patch.nodes ?? this.state.nodes,
5706
+ edges: patch.edges ?? this.state.edges,
5707
+ outputs: patch.outputs ?? this.state.outputs
5830
5708
  });
5831
5709
  }
5832
5710
  name(name) {
5833
- return this.with({ name: name.trim() || void 0 });
5711
+ return this.with({ name: name.trim() });
5834
5712
  }
5835
- execution(execution) {
5836
- return this.with({ execution });
5713
+ model(model) {
5714
+ return this.with({ model: model.trim() });
5837
5715
  }
5838
5716
  node(node) {
5839
5717
  return this.with({ nodes: [...this.state.nodes, node] });
5840
5718
  }
5841
- llmResponses(id, request, options = {}) {
5842
- const wiredRequest = wireRequest(request);
5843
- if (options.bindings) {
5844
- validateBindingTargets(id, wiredRequest.input, options.bindings);
5845
- }
5846
- const input = {
5847
- request: wiredRequest,
5848
- ...options.stream === void 0 ? {} : { stream: options.stream },
5849
- ...options.toolExecution === void 0 ? {} : { tool_execution: { mode: options.toolExecution } },
5850
- ...options.toolLimits === void 0 ? {} : { tool_limits: { ...options.toolLimits } },
5851
- ...options.bindings === void 0 ? {} : { bindings: options.bindings.slice() }
5852
- };
5719
+ llm(id, configure) {
5720
+ const builder = new LLMNodeBuilder(id);
5721
+ const configured = configure ? configure(builder) : builder;
5722
+ return this.node(configured.build());
5723
+ }
5724
+ joinAll(id) {
5725
+ return this.node({ id, type: WorkflowNodeTypesLite.JoinAll });
5726
+ }
5727
+ joinAny(id, predicate) {
5728
+ return this.node({ id, type: WorkflowNodeTypesLite.JoinAny, predicate });
5729
+ }
5730
+ joinCollect(id, options) {
5853
5731
  return this.node({
5854
5732
  id,
5855
- type: WorkflowNodeTypesV1.LLMResponses,
5856
- input
5733
+ type: WorkflowNodeTypesLite.JoinCollect,
5734
+ limit: options.limit,
5735
+ timeout_ms: options.timeoutMs,
5736
+ predicate: options.predicate
5857
5737
  });
5858
5738
  }
5859
- routeSwitch(id, request, options = {}) {
5860
- const wiredRequest = wireRequest(request);
5861
- if (options.bindings) {
5862
- validateBindingTargets(id, wiredRequest.input, options.bindings);
5863
- }
5864
- const input = {
5865
- request: wiredRequest,
5866
- ...options.stream === void 0 ? {} : { stream: options.stream },
5867
- ...options.toolExecution === void 0 ? {} : { tool_execution: { mode: options.toolExecution } },
5868
- ...options.toolLimits === void 0 ? {} : { tool_limits: { ...options.toolLimits } },
5869
- ...options.bindings === void 0 ? {} : { bindings: options.bindings.slice() }
5870
- };
5739
+ transformJSON(id, object, merge) {
5871
5740
  return this.node({
5872
5741
  id,
5873
- type: WorkflowNodeTypesV1.RouteSwitch,
5874
- input
5742
+ type: WorkflowNodeTypesLite.TransformJSON,
5743
+ object,
5744
+ merge
5875
5745
  });
5876
5746
  }
5877
- joinAll(id) {
5878
- return this.node({ id, type: WorkflowNodeTypesV1.JoinAll });
5879
- }
5880
- joinAny(id, input) {
5747
+ mapFanout(id, options) {
5881
5748
  return this.node({
5882
5749
  id,
5883
- type: WorkflowNodeTypesV1.JoinAny,
5884
- ...input ? { input } : {}
5750
+ type: WorkflowNodeTypesLite.MapFanout,
5751
+ items_from: options.itemsFrom,
5752
+ items_from_input: options.itemsFromInput,
5753
+ items_path: options.itemsPath,
5754
+ subnode: options.subnode,
5755
+ max_parallelism: options.maxParallelism
5885
5756
  });
5886
5757
  }
5887
- joinCollect(id, input) {
5888
- return this.node({ id, type: WorkflowNodeTypesV1.JoinCollect, input });
5889
- }
5890
- transformJSON(id, input) {
5891
- return this.node({ id, type: WorkflowNodeTypesV1.TransformJSON, input });
5892
- }
5893
- mapFanout(id, input) {
5894
- validateMapFanoutInput(id, input);
5895
- return this.node({ id, type: WorkflowNodeTypesV1.MapFanout, input });
5896
- }
5897
- edge(from, to, when) {
5898
- return this.with({
5899
- edges: [...this.state.edges, { from, to, ...when ? { when } : {} }]
5900
- });
5758
+ edge(from, to) {
5759
+ return this.with({ edges: [...this.state.edges, { from, to }] });
5901
5760
  }
5902
5761
  output(name, from, pointer) {
5903
5762
  return this.with({
5904
- outputs: [
5905
- ...this.state.outputs,
5906
- { name, from, ...pointer ? { pointer } : {} }
5907
- ]
5763
+ outputs: [...this.state.outputs, { name, from, pointer }]
5908
5764
  });
5909
5765
  }
5910
5766
  build() {
5911
- const edges = this.state.edges.slice().sort((a, b) => {
5912
- const af = String(a.from);
5913
- const bf = String(b.from);
5914
- if (af < bf) return -1;
5915
- if (af > bf) return 1;
5916
- const at = String(a.to);
5917
- const bt = String(b.to);
5918
- if (at < bt) return -1;
5919
- if (at > bt) return 1;
5920
- const aw = a.when ? JSON.stringify(a.when) : "";
5921
- const bw = b.when ? JSON.stringify(b.when) : "";
5922
- if (aw < bw) return -1;
5923
- if (aw > bw) return 1;
5924
- return 0;
5925
- });
5926
- const outputs = this.state.outputs.slice().sort((a, b) => {
5927
- const an = String(a.name);
5928
- const bn = String(b.name);
5929
- if (an < bn) return -1;
5930
- if (an > bn) return 1;
5931
- const af = String(a.from);
5932
- const bf = String(b.from);
5933
- if (af < bf) return -1;
5934
- if (af > bf) return 1;
5935
- const ap = a.pointer ?? "";
5936
- const bp = b.pointer ?? "";
5937
- if (ap < bp) return -1;
5938
- if (ap > bp) return 1;
5939
- return 0;
5940
- });
5767
+ const nodes = this.state.nodes.map((node) => ({
5768
+ ...node,
5769
+ depends_on: node.depends_on ? [...node.depends_on] : void 0
5770
+ }));
5771
+ const byId = /* @__PURE__ */ new Map();
5772
+ for (let idx = 0; idx < nodes.length; idx++) {
5773
+ const id = nodes[idx].id;
5774
+ if (byId.has(id)) {
5775
+ throw new Error(`duplicate node id "${id}"`);
5776
+ }
5777
+ byId.set(id, idx);
5778
+ }
5779
+ for (const edge of this.state.edges) {
5780
+ const idx = byId.get(edge.to);
5781
+ if (idx === void 0) {
5782
+ throw new Error(`edge to unknown node ${edge.to}`);
5783
+ }
5784
+ const existing = nodes[idx].depends_on ?? [];
5785
+ if (!existing.includes(edge.from)) {
5786
+ existing.push(edge.from);
5787
+ }
5788
+ nodes[idx].depends_on = existing;
5789
+ }
5941
5790
  return {
5942
- kind: WorkflowKinds.WorkflowV1,
5943
- ...this.state.name ? { name: this.state.name } : {},
5944
- ...this.state.execution ? { execution: this.state.execution } : {},
5945
- nodes: this.state.nodes.slice(),
5946
- ...edges.length ? { edges } : {},
5947
- outputs
5791
+ kind: WorkflowKinds.WorkflowIntent,
5792
+ name: this.state.name,
5793
+ model: this.state.model,
5794
+ nodes,
5795
+ outputs: [...this.state.outputs]
5948
5796
  };
5949
5797
  }
5950
5798
  };
5951
- function workflowV1() {
5952
- return WorkflowBuilderV1.new();
5799
+ var LLMNodeBuilder = class {
5800
+ constructor(id) {
5801
+ this.node = { id, type: WorkflowNodeTypesLite.LLM };
5802
+ }
5803
+ system(text) {
5804
+ this.node.system = text;
5805
+ return this;
5806
+ }
5807
+ user(text) {
5808
+ this.node.user = text;
5809
+ return this;
5810
+ }
5811
+ input(items) {
5812
+ this.node.input = items;
5813
+ return this;
5814
+ }
5815
+ model(model) {
5816
+ this.node.model = model;
5817
+ return this;
5818
+ }
5819
+ stream(enabled) {
5820
+ this.node.stream = enabled;
5821
+ return this;
5822
+ }
5823
+ toolExecution(mode) {
5824
+ this.node.tool_execution = { mode };
5825
+ return this;
5826
+ }
5827
+ tools(tools) {
5828
+ this.node.tools = tools;
5829
+ return this;
5830
+ }
5831
+ build() {
5832
+ return { ...this.node };
5833
+ }
5834
+ };
5835
+ function workflowIntent() {
5836
+ return new WorkflowIntentBuilder();
5837
+ }
5838
+ function llm(id, configure) {
5839
+ const builder = new LLMNodeBuilder(parseNodeId(id));
5840
+ const configured = configure ? configure(builder) : builder;
5841
+ return configured.build();
5842
+ }
5843
+ function chain(steps, options) {
5844
+ let builder = new WorkflowIntentBuilder();
5845
+ if (options?.name) {
5846
+ builder = builder.name(options.name);
5847
+ }
5848
+ if (options?.model) {
5849
+ builder = builder.model(options.model);
5850
+ }
5851
+ for (const step of steps) {
5852
+ builder = builder.node(step);
5853
+ }
5854
+ for (let i = 1; i < steps.length; i++) {
5855
+ builder = builder.edge(steps[i - 1].id, steps[i].id);
5856
+ }
5857
+ return builder;
5858
+ }
5859
+ function parallel(steps, options) {
5860
+ let builder = new WorkflowIntentBuilder();
5861
+ const joinId = parseNodeId(options?.joinId ?? "join");
5862
+ if (options?.name) {
5863
+ builder = builder.name(options.name);
5864
+ }
5865
+ if (options?.model) {
5866
+ builder = builder.model(options.model);
5867
+ }
5868
+ for (const step of steps) {
5869
+ builder = builder.node(step);
5870
+ }
5871
+ builder = builder.joinAll(joinId);
5872
+ for (const step of steps) {
5873
+ builder = builder.edge(step.id, joinId);
5874
+ }
5875
+ return builder;
5953
5876
  }
5954
5877
 
5955
5878
  // src/testing.ts
@@ -6172,260 +6095,26 @@ var generated_exports = {};
6172
6095
  // src/workflow/index.ts
6173
6096
  var workflow_exports = {};
6174
6097
  __export(workflow_exports, {
6175
- BindingBuilder: () => BindingBuilder,
6176
- BindingEncodings: () => BindingEncodings,
6177
- FanoutReduceV1: () => FanoutReduceV1,
6178
- KindV1: () => KindV1,
6098
+ KindIntent: () => KindIntent,
6099
+ LLMNodeBuilder: () => LLMNodeBuilder,
6179
6100
  LLM_TEXT_OUTPUT: () => LLM_TEXT_OUTPUT,
6180
6101
  LLM_USER_MESSAGE_TEXT: () => LLM_USER_MESSAGE_TEXT,
6181
- NodeTypesV1: () => NodeTypesV1,
6182
- RouterV1: () => RouterV1,
6183
- ToolExecutionModes: () => ToolExecutionModes,
6184
- WorkflowBuilderV1: () => WorkflowBuilderV1,
6185
- bindFrom: () => bindFrom,
6186
- bindToPlaceholder: () => bindToPlaceholder,
6187
- bindToPointer: () => bindToPointer,
6102
+ NodeTypesLite: () => NodeTypesLite,
6103
+ WorkflowIntentBuilder: () => WorkflowIntentBuilder,
6188
6104
  parseNodeId: () => parseNodeId,
6189
6105
  parseOutputName: () => parseOutputName,
6190
6106
  parsePlanHash: () => parsePlanHash,
6191
6107
  parseRunId: () => parseRunId,
6192
- whenOutputEquals: () => whenOutputEquals,
6193
- whenOutputExists: () => whenOutputExists,
6194
- whenOutputMatches: () => whenOutputMatches,
6195
- whenStatusEquals: () => whenStatusEquals,
6196
- whenStatusExists: () => whenStatusExists,
6197
- whenStatusMatches: () => whenStatusMatches,
6198
- workflowV1: () => workflowV1
6108
+ workflowIntent: () => workflowIntent
6199
6109
  });
6200
-
6201
- // src/workflow/helpers_v1.ts
6202
- function whenOutputEquals(path, value) {
6203
- return { source: "node_output", op: "equals", path, value };
6204
- }
6205
- function whenOutputMatches(path, pattern) {
6206
- return { source: "node_output", op: "matches", path, value: pattern };
6207
- }
6208
- function whenOutputExists(path) {
6209
- return { source: "node_output", op: "exists", path };
6210
- }
6211
- function whenStatusEquals(path, value) {
6212
- return { source: "node_status", op: "equals", path, value };
6213
- }
6214
- function whenStatusMatches(path, pattern) {
6215
- return { source: "node_status", op: "matches", path, value: pattern };
6216
- }
6217
- function whenStatusExists(path) {
6218
- return { source: "node_status", op: "exists", path };
6219
- }
6220
- function bindToPlaceholder(from, placeholder, opts) {
6221
- return {
6222
- from,
6223
- ...opts?.pointer ? { pointer: opts.pointer } : {},
6224
- to_placeholder: placeholder,
6225
- encoding: opts?.encoding ?? "json_string"
6226
- };
6227
- }
6228
- function bindToPointer(from, to, opts) {
6229
- return {
6230
- from,
6231
- ...opts?.pointer ? { pointer: opts.pointer } : {},
6232
- to,
6233
- encoding: opts?.encoding ?? "json_string"
6234
- };
6235
- }
6236
- function bindFrom(from) {
6237
- return new BindingBuilder(from);
6238
- }
6239
- var BindingBuilder = class {
6240
- constructor(from) {
6241
- this._encoding = "json_string";
6242
- this._from = from;
6243
- }
6244
- /**
6245
- * Set the source pointer to extract from the node's output.
6246
- */
6247
- pointer(ptr) {
6248
- this._pointer = ptr;
6249
- return this;
6250
- }
6251
- /**
6252
- * Set the destination JSON pointer in the request.
6253
- */
6254
- to(ptr) {
6255
- this._to = ptr;
6256
- this._toPlaceholder = void 0;
6257
- return this;
6258
- }
6259
- /**
6260
- * Set the destination placeholder name.
6261
- */
6262
- toPlaceholder(name) {
6263
- this._toPlaceholder = name;
6264
- this._to = void 0;
6265
- return this;
6266
- }
6267
- /**
6268
- * Set the encoding for the binding value.
6269
- */
6270
- encoding(enc) {
6271
- this._encoding = enc;
6272
- return this;
6273
- }
6274
- /**
6275
- * Build the binding object.
6276
- */
6277
- build() {
6278
- const binding = {
6279
- from: this._from,
6280
- encoding: this._encoding
6281
- };
6282
- if (this._pointer) binding.pointer = this._pointer;
6283
- if (this._to) binding.to = this._to;
6284
- if (this._toPlaceholder) binding.to_placeholder = this._toPlaceholder;
6285
- return binding;
6286
- }
6287
- };
6288
-
6289
- // src/workflow/patterns_v1.ts
6290
- function wireRequest2(req) {
6291
- const raw = req;
6292
- if (raw && typeof raw === "object") {
6293
- if ("input" in raw) {
6294
- return req;
6295
- }
6296
- if ("body" in raw) {
6297
- return raw.body ?? {};
6298
- }
6299
- }
6300
- return asInternal(req).body;
6301
- }
6302
- var RouterV1 = class {
6303
- constructor(config) {
6304
- this.config = config;
6305
- }
6306
- /**
6307
- * Build the workflow specification.
6308
- */
6309
- build() {
6310
- const {
6311
- name,
6312
- classifier,
6313
- classifierId = "router",
6314
- routePath = "$.route",
6315
- routes,
6316
- aggregator,
6317
- outputName = "final"
6318
- } = this.config;
6319
- let builder = new WorkflowBuilderV1();
6320
- if (name) {
6321
- builder = builder.name(name);
6322
- }
6323
- builder = builder.routeSwitch(classifierId, classifier);
6324
- const joinId = "__router_join";
6325
- builder = builder.joinAny(joinId);
6326
- for (let i = 0; i < routes.length; i++) {
6327
- const route = routes[i];
6328
- const handlerId = route.id ?? `handler_${i}`;
6329
- builder = builder.llmResponses(handlerId, route.handler, {
6330
- bindings: route.bindings
6331
- });
6332
- builder = builder.edge(classifierId, handlerId, whenOutputEquals(routePath, route.value));
6333
- builder = builder.edge(handlerId, joinId);
6334
- }
6335
- if (aggregator) {
6336
- const aggId = aggregator.id ?? "aggregate";
6337
- const placeholder = aggregator.placeholder ?? "route_output";
6338
- builder = builder.llmResponses(aggId, aggregator.request, {
6339
- bindings: [bindToPlaceholder(joinId, placeholder)]
6340
- });
6341
- builder = builder.edge(joinId, aggId);
6342
- builder = builder.output(outputName, aggId);
6343
- } else {
6344
- builder = builder.output(outputName, joinId);
6345
- }
6346
- return builder.build();
6347
- }
6348
- };
6349
- var FanoutReduceV1 = class {
6350
- constructor(config) {
6351
- this.config = config;
6352
- }
6353
- /**
6354
- * Build the workflow specification.
6355
- */
6356
- build() {
6357
- const {
6358
- name,
6359
- generator,
6360
- generatorId = "generator",
6361
- itemsPath = "/items",
6362
- mapper,
6363
- mapperPlaceholder = "item",
6364
- maxParallelism = 4,
6365
- reducer,
6366
- reducerId = "reducer",
6367
- reducerBinding,
6368
- outputName = "final"
6369
- } = this.config;
6370
- let builder = new WorkflowBuilderV1();
6371
- if (name) {
6372
- builder = builder.name(name);
6373
- }
6374
- builder = builder.llmResponses(generatorId, generator);
6375
- const fanoutId = "__fanout";
6376
- const itemBindings = [
6377
- {
6378
- path: "$",
6379
- to_placeholder: mapperPlaceholder,
6380
- encoding: "json_string"
6381
- }
6382
- ];
6383
- const mapperRequest = wireRequest2(mapper);
6384
- builder = builder.mapFanout(fanoutId, {
6385
- items: { from: generatorId, path: itemsPath },
6386
- item_bindings: itemBindings,
6387
- subnode: {
6388
- id: "__mapper",
6389
- type: "llm.responses",
6390
- input: { request: mapperRequest }
6391
- },
6392
- max_parallelism: maxParallelism
6393
- });
6394
- builder = builder.edge(generatorId, fanoutId);
6395
- const pointer = reducerBinding?.pointer ?? "/results";
6396
- const binding = reducerBinding?.placeholder ? bindToPlaceholder(fanoutId, reducerBinding.placeholder, { pointer }) : {
6397
- from: fanoutId,
6398
- pointer,
6399
- to: reducerBinding?.to ?? "/input/0/content/0/text",
6400
- encoding: "json_string"
6401
- };
6402
- builder = builder.llmResponses(reducerId, reducer, {
6403
- bindings: [binding]
6404
- });
6405
- builder = builder.edge(fanoutId, reducerId);
6406
- builder = builder.output(outputName, reducerId);
6407
- return builder.build();
6408
- }
6409
- };
6410
-
6411
- // src/workflow/index.ts
6412
- var KindV1 = WorkflowKinds.WorkflowV1;
6413
- var NodeTypesV1 = {
6414
- LLMResponses: WorkflowNodeTypesV1.LLMResponses,
6415
- RouteSwitch: WorkflowNodeTypesV1.RouteSwitch,
6416
- JoinAll: WorkflowNodeTypesV1.JoinAll,
6417
- JoinAny: WorkflowNodeTypesV1.JoinAny,
6418
- JoinCollect: WorkflowNodeTypesV1.JoinCollect,
6419
- TransformJSON: WorkflowNodeTypesV1.TransformJSON,
6420
- MapFanout: WorkflowNodeTypesV1.MapFanout
6421
- };
6422
- var BindingEncodings = {
6423
- JSON: "json",
6424
- JSONString: "json_string"
6425
- };
6426
- var ToolExecutionModes = {
6427
- Server: "server",
6428
- Client: "client"
6110
+ var KindIntent = WorkflowKinds.WorkflowIntent;
6111
+ var NodeTypesLite = {
6112
+ LLM: WorkflowNodeTypesLite.LLM,
6113
+ JoinAll: WorkflowNodeTypesLite.JoinAll,
6114
+ JoinAny: WorkflowNodeTypesLite.JoinAny,
6115
+ JoinCollect: WorkflowNodeTypesLite.JoinCollect,
6116
+ TransformJSON: WorkflowNodeTypesLite.TransformJSON,
6117
+ MapFanout: WorkflowNodeTypesLite.MapFanout
6429
6118
  };
6430
6119
 
6431
6120
  // src/index.ts
@@ -6493,7 +6182,6 @@ function resolveBaseUrl(override) {
6493
6182
  APIError,
6494
6183
  AuthClient,
6495
6184
  BillingProviders,
6496
- BindingTargetError,
6497
6185
  ConfigError,
6498
6186
  ContentPartTypes,
6499
6187
  CustomerResponsesClient,
@@ -6515,6 +6203,7 @@ function resolveBaseUrl(override) {
6515
6203
  LLMInputPath,
6516
6204
  LLMInputSystemText,
6517
6205
  LLMInputUserText,
6206
+ LLMNodeBuilder,
6518
6207
  LLMOutput,
6519
6208
  LLMOutputContentItemPath,
6520
6209
  LLMOutputContentPath,
@@ -6523,7 +6212,6 @@ function resolveBaseUrl(override) {
6523
6212
  LLM_TEXT_OUTPUT,
6524
6213
  LLM_USER_MESSAGE_TEXT,
6525
6214
  LocalSession,
6526
- MapFanoutInputError,
6527
6215
  MemorySessionStore,
6528
6216
  MessageRoles,
6529
6217
  ModelRelay,
@@ -6555,10 +6243,10 @@ function resolveBaseUrl(override) {
6555
6243
  TransportError,
6556
6244
  WORKFLOWS_COMPILE_PATH,
6557
6245
  WebToolIntents,
6558
- WorkflowBuilderV1,
6246
+ WorkflowIntentBuilder,
6559
6247
  WorkflowKinds,
6560
6248
  WorkflowNodeTypes,
6561
- WorkflowNodeTypesV1,
6249
+ WorkflowNodeTypesLite,
6562
6250
  WorkflowValidationError,
6563
6251
  WorkflowsClient,
6564
6252
  asModelId,
@@ -6568,6 +6256,7 @@ function resolveBaseUrl(override) {
6568
6256
  assistantMessageWithToolCalls,
6569
6257
  buildDelayedNDJSONResponse,
6570
6258
  buildNDJSONResponse,
6259
+ chain,
6571
6260
  createAccessTokenAuth,
6572
6261
  createApiKeyAuth,
6573
6262
  createAssistantMessage,
@@ -6595,12 +6284,14 @@ function resolveBaseUrl(override) {
6595
6284
  hasRetryableErrors,
6596
6285
  hasToolCalls,
6597
6286
  isSecretKey,
6287
+ llm,
6598
6288
  mergeMetrics,
6599
6289
  mergeTrace,
6600
6290
  modelToString,
6601
6291
  normalizeModelId,
6602
6292
  normalizeStopReason,
6603
6293
  outputFormatFromZod,
6294
+ parallel,
6604
6295
  parseApiKey,
6605
6296
  parseErrorResponse,
6606
6297
  parseNodeId,
@@ -6616,12 +6307,9 @@ function resolveBaseUrl(override) {
6616
6307
  toolChoiceNone,
6617
6308
  toolChoiceRequired,
6618
6309
  toolResultMessage,
6619
- transformJSONMerge,
6620
- transformJSONObject,
6621
- transformJSONValue,
6622
6310
  tryParseToolArgs,
6623
6311
  validateWithZod,
6624
6312
  workflow,
6625
- workflowV1,
6313
+ workflowIntent,
6626
6314
  zodToJsonSchema
6627
6315
  });