@xyne/workflow-sdk 3.2.55 → 3.2.56

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.
Files changed (90) hide show
  1. package/dist/agents/agent-step.d.ts +30 -15
  2. package/dist/agents/agent-step.d.ts.map +1 -1
  3. package/dist/agents/agent-step.js +15 -5
  4. package/dist/agents/agent-step.js.map +1 -1
  5. package/dist/agents/citation-resolve.js +1 -1
  6. package/dist/agents/citation-resolve.js.map +1 -1
  7. package/dist/agents/contract.d.ts +16 -8
  8. package/dist/agents/contract.d.ts.map +1 -1
  9. package/dist/agents/host-agent-step.d.ts +20 -10
  10. package/dist/agents/host-agent-step.d.ts.map +1 -1
  11. package/dist/agents/host-agent-step.js +4 -3
  12. package/dist/agents/host-agent-step.js.map +1 -1
  13. package/dist/agents/provider.d.ts +2 -2
  14. package/dist/agents/tool-types.d.ts +13 -2
  15. package/dist/agents/tool-types.d.ts.map +1 -1
  16. package/dist/client/workflow-client.js +1 -1
  17. package/dist/client/workflow-client.js.map +1 -1
  18. package/dist/common/attachment.d.ts +15 -7
  19. package/dist/common/attachment.d.ts.map +1 -1
  20. package/dist/common/attachment.js +14 -7
  21. package/dist/common/attachment.js.map +1 -1
  22. package/dist/common/multipart-values.d.ts +21 -0
  23. package/dist/common/multipart-values.d.ts.map +1 -0
  24. package/dist/common/multipart-values.js +63 -0
  25. package/dist/common/multipart-values.js.map +1 -0
  26. package/dist/completion/attach.d.ts +4 -16
  27. package/dist/completion/attach.d.ts.map +1 -1
  28. package/dist/completion/attach.js +7 -62
  29. package/dist/completion/attach.js.map +1 -1
  30. package/dist/completion/index.d.ts +1 -1
  31. package/dist/completion/index.d.ts.map +1 -1
  32. package/dist/completion/index.js +1 -1
  33. package/dist/completion/index.js.map +1 -1
  34. package/dist/completion/types.d.ts +10 -8
  35. package/dist/completion/types.d.ts.map +1 -1
  36. package/dist/completion/types.js.map +1 -1
  37. package/dist/connectors/builtin/steps/code.step.d.ts +20 -10
  38. package/dist/connectors/builtin/steps/code.step.d.ts.map +1 -1
  39. package/dist/connectors/builtin/steps/code.step.js +14 -7
  40. package/dist/connectors/builtin/steps/code.step.js.map +1 -1
  41. package/dist/connectors/builtin/steps/http-request.step.d.ts +100 -50
  42. package/dist/connectors/builtin/steps/http-request.step.d.ts.map +1 -1
  43. package/dist/connectors/builtin/steps/http-request.step.js +14 -15
  44. package/dist/connectors/builtin/steps/http-request.step.js.map +1 -1
  45. package/dist/connectors/builtin/steps/multipart-body.d.ts +23 -0
  46. package/dist/connectors/builtin/steps/multipart-body.d.ts.map +1 -0
  47. package/dist/connectors/builtin/steps/multipart-body.js +40 -0
  48. package/dist/connectors/builtin/steps/multipart-body.js.map +1 -0
  49. package/dist/engine/workflow-executor.d.ts.map +1 -1
  50. package/dist/engine/workflow-executor.js +5 -1
  51. package/dist/engine/workflow-executor.js.map +1 -1
  52. package/dist/index.d.ts +3 -1
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +1 -0
  55. package/dist/index.js.map +1 -1
  56. package/dist/router/approval-context.d.ts +1 -1
  57. package/dist/router/approval-context.d.ts.map +1 -1
  58. package/dist/router/approval-context.js +3 -3
  59. package/dist/router/approval-context.js.map +1 -1
  60. package/dist/router/types.d.ts +18 -7
  61. package/dist/router/types.d.ts.map +1 -1
  62. package/dist/router/workflow-router.d.ts.map +1 -1
  63. package/dist/router/workflow-router.js +109 -110
  64. package/dist/router/workflow-router.js.map +1 -1
  65. package/dist/runtime/workflow-runtime.d.ts +18 -0
  66. package/dist/runtime/workflow-runtime.d.ts.map +1 -1
  67. package/dist/runtime/workflow-runtime.js +49 -14
  68. package/dist/runtime/workflow-runtime.js.map +1 -1
  69. package/dist/steps/base-step.d.ts +9 -6
  70. package/dist/steps/base-step.d.ts.map +1 -1
  71. package/dist/steps/base-step.js.map +1 -1
  72. package/dist/storage/files.d.ts +39 -0
  73. package/dist/storage/files.d.ts.map +1 -0
  74. package/dist/storage/files.js +75 -0
  75. package/dist/storage/files.js.map +1 -0
  76. package/dist/storage/in-memory-adapter.d.ts +15 -8
  77. package/dist/storage/in-memory-adapter.d.ts.map +1 -1
  78. package/dist/storage/in-memory-adapter.js +36 -18
  79. package/dist/storage/in-memory-adapter.js.map +1 -1
  80. package/dist/storage/types.d.ts +36 -26
  81. package/dist/storage/types.d.ts.map +1 -1
  82. package/dist/storage/types.js +5 -6
  83. package/dist/storage/types.js.map +1 -1
  84. package/dist/testing/mock-step-context.d.ts +7 -2
  85. package/dist/testing/mock-step-context.d.ts.map +1 -1
  86. package/dist/testing/mock-step-context.js +2 -1
  87. package/dist/testing/mock-step-context.js.map +1 -1
  88. package/dist/types/workflow-variable.d.ts +20 -10
  89. package/dist/types/workflow-variable.d.ts.map +1 -1
  90. package/package.json +1 -1
@@ -31,7 +31,9 @@ import { OPERATOR_DESCRIPTORS } from '../types/operators.js';
31
31
  import { getAvailableContext } from '../engine/available-context.js';
32
32
  import { executionTopic, workflowTopic, folderTopic, rootTopic } from '../events/types.js';
33
33
  import { isExecutable } from '../common/executable-check.js';
34
+ import { createFileAccess } from '../storage/files.js';
34
35
  import { isAttachmentArrayProperty } from '../common/attachment.js';
36
+ import { addMultipartValue, coerceTextFields } from '../common/multipart-values.js';
35
37
  import { createEventChannel } from '../util/event-channel.js';
36
38
  import { AccessDeniedError, ResourceNotFoundError } from '../authz/default.js';
37
39
  import { conversationRoutes } from '../conversational-flow/server/routes.js';
@@ -64,50 +66,18 @@ function objectBody(body) {
64
66
  ? body
65
67
  : {};
66
68
  }
67
- function parseMultipartValue(value) {
68
- if (Array.isArray(value))
69
- return value.map((entry) => parseMultipartValue(entry));
70
- if (typeof value !== 'string')
71
- return value;
72
- const trimmed = value.trim();
73
- if (!trimmed)
74
- return value;
75
- try {
76
- return JSON.parse(trimmed);
77
- }
78
- catch {
79
- return value;
80
- }
81
- }
82
- function addMultipartValue(payload, key, value) {
83
- const current = payload[key];
84
- if (current === undefined) {
85
- payload[key] = value;
86
- }
87
- else if (Array.isArray(current)) {
88
- current.push(value);
89
- }
90
- else {
91
- payload[key] = [current, value];
92
- }
93
- }
94
- async function buildMultipartTriggerPayload(req, storage, scope, inputSchema) {
95
- const payload = {};
96
- for (const [key, value] of Object.entries(objectBody(req.body))) {
97
- addMultipartValue(payload, key, parseMultipartValue(value));
98
- }
69
+ function buildMultipartTriggerPayload(req, inputSchema) {
70
+ // Re-read against the declared input schema, the same way a wait callback's
71
+ // fields are read against its contract — a field declared as a string stays
72
+ // one rather than being parsed into a number.
73
+ const payload = { ...coerceTextFields(objectBody(req.body), inputSchema) };
99
74
  const groupedFiles = new Map();
100
75
  for (const file of req.files ?? []) {
101
76
  if (!file.fieldName) {
102
- throw new Error(`Uploaded file "${file.name}" is missing a multipart field name`);
77
+ throw new Error(`Uploaded file "${file.attachment.name}" is missing a multipart field name`);
103
78
  }
104
- const attachment = await storage.store(scope, {
105
- name: file.name,
106
- mimeType: file.mimeType,
107
- bytes: file.bytes,
108
- });
109
79
  const group = groupedFiles.get(file.fieldName) ?? [];
110
- group.push(attachment);
80
+ group.push(file.attachment);
111
81
  groupedFiles.set(file.fieldName, group);
112
82
  }
113
83
  for (const [fieldName, attachments] of groupedFiles) {
@@ -117,6 +87,32 @@ async function buildMultipartTriggerPayload(req, storage, scope, inputSchema) {
117
87
  }
118
88
  return payload;
119
89
  }
90
+ /**
91
+ * Give back files the route is about to refuse.
92
+ *
93
+ * Bytes are streamed into storage while the request is parsed, so by the time a
94
+ * handler can judge them they already exist. Best-effort on purpose: a failed
95
+ * delete must not turn a clean 400 into a 500, and the host's sweep for
96
+ * unreferenced objects is the backstop.
97
+ */
98
+ async function discardFiles(storage, files, scope) {
99
+ if (!storage || !files || files.length === 0)
100
+ return;
101
+ await Promise.all(files.map((f) => storage.delete(f.attachment, scope).catch(() => {
102
+ /* left for the sweep */
103
+ })));
104
+ }
105
+ /** The perimeter rule on uploads, as a message — null when nothing is refused. */
106
+ function executableRefusal(files, allowExecutables) {
107
+ if (allowExecutables || !files)
108
+ return null;
109
+ for (const { attachment } of files) {
110
+ const reason = isExecutable(attachment.mimeType, attachment.name);
111
+ if (reason)
112
+ return `"${attachment.name}" rejected: ${reason}`;
113
+ }
114
+ return null;
115
+ }
120
116
  /** Format a single SSE message. */
121
117
  function formatSSE(event, data) {
122
118
  return `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`;
@@ -596,18 +592,16 @@ opts) {
596
592
  if (!runtime.storage) {
597
593
  return error(501, 'No StorageAdapter configured — multipart trigger uploads are disabled');
598
594
  }
599
- const files = req.files;
600
- if (files && files.length > 0 && !runtime.allowExecutableUploads) {
601
- for (const file of files) {
602
- const reason = isExecutable(file.mimeType, file.name);
603
- if (reason) {
604
- return badRequest(`"${file.name}" rejected: ${reason}`);
605
- }
606
- }
595
+ // Perimeter first: dangerous content is refused before any lookup, and
596
+ // the handle already encodes ownership, so the discard needs no scope.
597
+ const refusal = executableRefusal(req.files, runtime.allowExecutableUploads);
598
+ if (refusal) {
599
+ await discardFiles(runtime.storage, req.files);
600
+ return badRequest(refusal);
607
601
  }
608
602
  try {
609
603
  const target = await runtime.getApiTriggerTarget(workflowId);
610
- const payload = await buildMultipartTriggerPayload(req, runtime.storage, target.storageScope, target.inputSchema);
604
+ const payload = buildMultipartTriggerPayload(req, target.inputSchema);
611
605
  const executionId = await runtime.triggerViaApi(workflowId, payload);
612
606
  return created({ executionId });
613
607
  }
@@ -637,38 +631,23 @@ opts) {
637
631
  if (!files || files.length === 0) {
638
632
  return badRequest('No files in request — did the host run a multipart parser?');
639
633
  }
640
- // Perimeter check: reject executables unless the host opted in. This
641
- // applies to ALL uploads regardless of workflow — the upload route
642
- // doesn't know which workflow the files are for yet.
643
- if (!runtime.allowExecutableUploads) {
644
- for (const file of files) {
645
- const reason = isExecutable(file.mimeType, file.name);
646
- if (reason) {
647
- return badRequest(`"${file.name}" rejected: ${reason}`);
648
- }
649
- }
650
- }
651
634
  // The host's auth context IS its storage scope for caller-initiated work: an
652
635
  // upload has a person and no workflow yet. Not provable here (TCtx is unbound
653
636
  // at this point), so the host's adapter validates and rejects a scope it
654
637
  // cannot read a tenant from.
655
638
  const scope = auth;
656
- try {
657
- const attachments = [];
658
- for (const file of files) {
659
- attachments.push(await runtime.storage.store(scope, {
660
- name: file.name,
661
- mimeType: file.mimeType,
662
- bytes: file.bytes,
663
- }));
664
- }
665
- return created({ attachments });
666
- }
667
- catch (err) {
668
- if (err instanceof AccessDeniedError)
669
- throw err;
670
- return error(500, err instanceof Error ? err.message : 'Upload failed');
671
- }
639
+ // Perimeter check: reject executables unless the host opted in. This
640
+ // applies to ALL uploads regardless of workflow — the upload route
641
+ // doesn't know which workflow the files are for yet. The bytes are
642
+ // already stored by now, so a refusal has to take them back out.
643
+ const refusal = executableRefusal(files, runtime.allowExecutableUploads);
644
+ if (refusal) {
645
+ await discardFiles(runtime.storage, files, scope);
646
+ return badRequest(refusal);
647
+ }
648
+ // Nothing to do but hand the references back: the host streamed each part
649
+ // into storage as it parsed, so this route never sees a byte.
650
+ return created({ attachments: files.map((f) => f.attachment) });
672
651
  },
673
652
  });
674
653
  // ─── Attachment download (serve bytes / redirect to signed URL) ───
@@ -690,7 +669,7 @@ opts) {
690
669
  return badRequest('Missing required query param: ref');
691
670
  const name = typeof req.query['name'] === 'string' ? req.query['name'] : 'download';
692
671
  const mime = typeof req.query['mime'] === 'string' ? req.query['mime'] : 'application/octet-stream';
693
- const attachment = { name, mimeType: mime, data: ref };
672
+ const attachment = { name, mimeType: mime, handle: ref };
694
673
  try {
695
674
  if (runtime.storage.signUrl) {
696
675
  const url = await runtime.storage.signUrl(attachment, 300);
@@ -698,10 +677,19 @@ opts) {
698
677
  }
699
678
  // Pass the caller so a tenant-enforcing adapter can refuse a reference
700
679
  // owned by another workspace. `ref` is client-supplied.
701
- const bytes = await runtime.storage.read(attachment, auth);
680
+ //
681
+ // Piped, not read: without `signUrl` the bytes do cross this process,
682
+ // but they pass through it rather than pile up in it. `info` supplies
683
+ // Content-Length without touching the object's contents.
684
+ const scope = auth;
685
+ const known = await runtime.storage.info(attachment, scope);
686
+ if (!known)
687
+ return notFound('Attachment not found');
688
+ const body = await runtime.storage.stream(attachment, scope);
702
689
  return {
703
690
  status: 200,
704
- body: bytes,
691
+ body: null,
692
+ bodyStream: body,
705
693
  headers: {
706
694
  'Content-Type': mime,
707
695
  // Force download; never inline-render. An uploaded HTML/SVG must not
@@ -711,7 +699,7 @@ opts) {
711
699
  'Content-Disposition': `attachment; filename="${encodeURIComponent(name)}"`,
712
700
  'X-Content-Type-Options': 'nosniff',
713
701
  'Content-Security-Policy': "default-src 'none'; sandbox",
714
- 'Content-Length': String(bytes.byteLength),
702
+ 'Content-Length': String(known.size),
715
703
  },
716
704
  };
717
705
  }
@@ -842,25 +830,18 @@ opts) {
842
830
  const nodePath = req.query['nodePath'];
843
831
  const fence = Number(req.query['fence']);
844
832
  const deliveryId = req.headers['x-delivery-id'];
833
+ const refusal = executableRefusal(req.files, runtime.allowExecutableUploads);
834
+ if (refusal) {
835
+ await discardFiles(runtime.storage, req.files);
836
+ return badRequest(refusal);
837
+ }
845
838
  const files = [];
846
839
  for (const file of req.files ?? []) {
847
- if (!runtime.storage) {
848
- return error(501, 'No StorageAdapter configured — file deliveries are disabled');
849
- }
850
840
  if (!file.fieldName) {
851
- return badRequest(`Uploaded file "${file.name}" is missing a multipart field name`);
852
- }
853
- if (!runtime.allowExecutableUploads) {
854
- const reason = isExecutable(file.mimeType, file.name);
855
- if (reason)
856
- return badRequest(`"${file.name}" rejected: ${reason}`);
841
+ await discardFiles(runtime.storage, req.files);
842
+ return badRequest(`Uploaded file "${file.attachment.name}" is missing a multipart field name`);
857
843
  }
858
- files.push({
859
- fieldName: file.fieldName,
860
- name: file.name,
861
- mimeType: file.mimeType,
862
- bytes: file.bytes,
863
- });
844
+ files.push({ fieldName: file.fieldName, attachment: file.attachment });
864
845
  }
865
846
  // Only how it arrived is decided here. What a text field means is the
866
847
  // gate contract's business, and the contract is on the parked record,
@@ -1707,9 +1688,10 @@ opts) {
1707
1688
  if (typeof att.attachment.size === 'number' && att.attachment.size > MAX_MOUNT_BYTES)
1708
1689
  continue;
1709
1690
  try {
1710
- const bytes = await runtime.storage.read(att.attachment, auth);
1691
+ const bytes = await createFileAccess(runtime.storage, auth)
1692
+ .buffer(att.attachment, { maxBytes: MAX_MOUNT_BYTES });
1711
1693
  preloadFiles.push({ path: att.sandboxPath, bytes });
1712
- mountedPaths.set(att.attachment.data, att.sandboxPath);
1694
+ mountedPaths.set(att.attachment.handle, att.sandboxPath);
1713
1695
  }
1714
1696
  catch {
1715
1697
  // Unavailable — left unmounted; annotated with sandboxPath: null.
@@ -1797,8 +1779,8 @@ opts) {
1797
1779
  }
1798
1780
  let messages = [...body.messages];
1799
1781
  const uploadedFile = req.files?.[0];
1800
- if (uploadedFile) {
1801
- const fileText = aiBuilderExtractFileText(uploadedFile);
1782
+ if (uploadedFile && runtime.storage) {
1783
+ const fileText = await aiBuilderFileText(runtime.storage, uploadedFile.attachment, auth);
1802
1784
  if (fileText) {
1803
1785
  const lastUserIdx = [...messages].reverse().findIndex((m) => m.role === 'user');
1804
1786
  if (lastUserIdx !== -1) {
@@ -1806,7 +1788,7 @@ opts) {
1806
1788
  messages = [...messages];
1807
1789
  messages[idx] = {
1808
1790
  ...messages[idx],
1809
- content: `${messages[idx].content}\n\n--- Attached: ${uploadedFile.name} ---\n${fileText}`,
1791
+ content: `${messages[idx].content}\n\n--- Attached: ${uploadedFile.attachment.name} ---\n${fileText}`,
1810
1792
  };
1811
1793
  }
1812
1794
  }
@@ -1966,18 +1948,35 @@ The user's most recent message is the only thing that matters. Answer it directl
1966
1948
  \`\`\`json:formfill
1967
1949
  { "fieldKey": "user-provided value" }
1968
1950
  \`\`\``;
1969
- function aiBuilderExtractFileText(file) {
1970
- const mime = file.mimeType;
1971
- const name = file.name.toLowerCase();
1972
- const isText = mime.startsWith('text/') ||
1973
- mime === 'application/json' ||
1951
+ /** Is this something whose text we can paste into a prompt? */
1952
+ function aiBuilderIsText(ref) {
1953
+ const name = ref.name.toLowerCase();
1954
+ return (ref.mimeType.startsWith('text/') ||
1955
+ ref.mimeType === 'application/json' ||
1974
1956
  name.endsWith('.md') ||
1975
1957
  name.endsWith('.txt') ||
1976
1958
  name.endsWith('.json') ||
1977
- name.endsWith('.csv');
1978
- if (isText)
1979
- return new TextDecoder().decode(file.bytes);
1980
- return undefined;
1959
+ name.endsWith('.csv'));
1960
+ }
1961
+ /**
1962
+ * The attached file's text, for the builder prompt.
1963
+ *
1964
+ * Capped: this ends up inside a model request, so a file too big to be a prompt
1965
+ * is not worth reading in the first place.
1966
+ */
1967
+ const AI_BUILDER_MAX_FILE_BYTES = 1024 * 1024;
1968
+ async function aiBuilderFileText(storage, ref, scope) {
1969
+ if (!aiBuilderIsText(ref))
1970
+ return undefined;
1971
+ try {
1972
+ const bytes = await createFileAccess(storage, scope).buffer(ref, {
1973
+ maxBytes: AI_BUILDER_MAX_FILE_BYTES,
1974
+ });
1975
+ return new TextDecoder().decode(bytes);
1976
+ }
1977
+ catch {
1978
+ return undefined;
1979
+ }
1981
1980
  }
1982
1981
  function parseWorkflowPatch(text) {
1983
1982
  const fenceRegex = /```(?:json)?\s*([\s\S]*?)```/gm;
@@ -2067,11 +2066,11 @@ function parseResumePayload(raw) {
2067
2066
  const rec = a;
2068
2067
  if (typeof rec['name'] === 'string' &&
2069
2068
  typeof rec['mimeType'] === 'string' &&
2070
- typeof rec['data'] === 'string') {
2069
+ typeof rec['handle'] === 'string') {
2071
2070
  cleaned.push({
2072
2071
  name: rec['name'],
2073
2072
  mimeType: rec['mimeType'],
2074
- data: rec['data'],
2073
+ handle: rec['handle'],
2075
2074
  });
2076
2075
  }
2077
2076
  }