@xyne/workflow-sdk 3.2.54 → 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 (172) 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 +7 -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 +24 -7
  19. package/dist/common/attachment.d.ts.map +1 -1
  20. package/dist/common/attachment.js +34 -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/address.d.ts +27 -0
  27. package/dist/completion/address.d.ts.map +1 -0
  28. package/dist/completion/address.js +62 -0
  29. package/dist/completion/address.js.map +1 -0
  30. package/dist/completion/attach.d.ts +20 -0
  31. package/dist/completion/attach.d.ts.map +1 -0
  32. package/dist/completion/attach.js +37 -0
  33. package/dist/completion/attach.js.map +1 -0
  34. package/dist/completion/index.d.ts +6 -0
  35. package/dist/completion/index.d.ts.map +1 -0
  36. package/dist/completion/index.js +4 -0
  37. package/dist/completion/index.js.map +1 -0
  38. package/dist/completion/types.d.ts +109 -0
  39. package/dist/completion/types.d.ts.map +1 -0
  40. package/dist/completion/types.js +35 -0
  41. package/dist/completion/types.js.map +1 -0
  42. package/dist/connectors/builtin/builtin-connector.d.ts.map +1 -1
  43. package/dist/connectors/builtin/builtin-connector.js +6 -2
  44. package/dist/connectors/builtin/builtin-connector.js.map +1 -1
  45. package/dist/connectors/builtin/steps/code.step.d.ts +20 -10
  46. package/dist/connectors/builtin/steps/code.step.d.ts.map +1 -1
  47. package/dist/connectors/builtin/steps/code.step.js +14 -7
  48. package/dist/connectors/builtin/steps/code.step.js.map +1 -1
  49. package/dist/connectors/builtin/steps/cycle.step.d.ts +36 -7
  50. package/dist/connectors/builtin/steps/cycle.step.d.ts.map +1 -1
  51. package/dist/connectors/builtin/steps/cycle.step.js +84 -6
  52. package/dist/connectors/builtin/steps/cycle.step.js.map +1 -1
  53. package/dist/connectors/builtin/steps/delay.step.d.ts +49 -0
  54. package/dist/connectors/builtin/steps/delay.step.d.ts.map +1 -0
  55. package/dist/connectors/builtin/steps/delay.step.js +40 -0
  56. package/dist/connectors/builtin/steps/delay.step.js.map +1 -0
  57. package/dist/connectors/builtin/steps/http-request.step.d.ts +100 -50
  58. package/dist/connectors/builtin/steps/http-request.step.d.ts.map +1 -1
  59. package/dist/connectors/builtin/steps/http-request.step.js +14 -15
  60. package/dist/connectors/builtin/steps/http-request.step.js.map +1 -1
  61. package/dist/connectors/builtin/steps/map.step.d.ts.map +1 -1
  62. package/dist/connectors/builtin/steps/map.step.js +9 -2
  63. package/dist/connectors/builtin/steps/map.step.js.map +1 -1
  64. package/dist/connectors/builtin/steps/multipart-body.d.ts +23 -0
  65. package/dist/connectors/builtin/steps/multipart-body.d.ts.map +1 -0
  66. package/dist/connectors/builtin/steps/multipart-body.js +40 -0
  67. package/dist/connectors/builtin/steps/multipart-body.js.map +1 -0
  68. package/dist/connectors/builtin/steps/parallel.step.d.ts.map +1 -1
  69. package/dist/connectors/builtin/steps/parallel.step.js +9 -2
  70. package/dist/connectors/builtin/steps/parallel.step.js.map +1 -1
  71. package/dist/connectors/builtin/steps/wait-for-api-call.step.d.ts +80 -0
  72. package/dist/connectors/builtin/steps/wait-for-api-call.step.d.ts.map +1 -0
  73. package/dist/connectors/builtin/steps/wait-for-api-call.step.js +104 -0
  74. package/dist/connectors/builtin/steps/wait-for-api-call.step.js.map +1 -0
  75. package/dist/connectors/builtin/steps/wait-for-human.step.d.ts +1057 -0
  76. package/dist/connectors/builtin/steps/wait-for-human.step.d.ts.map +1 -0
  77. package/dist/connectors/builtin/steps/wait-for-human.step.js +222 -0
  78. package/dist/connectors/builtin/steps/wait-for-human.step.js.map +1 -0
  79. package/dist/connectors/builtin/steps/wait-for-webhook.step.d.ts +80 -0
  80. package/dist/connectors/builtin/steps/wait-for-webhook.step.d.ts.map +1 -0
  81. package/dist/connectors/builtin/steps/wait-for-webhook.step.js +104 -0
  82. package/dist/connectors/builtin/steps/wait-for-webhook.step.js.map +1 -0
  83. package/dist/connectors/builtin/steps/wait.step.d.ts +10 -35
  84. package/dist/connectors/builtin/steps/wait.step.d.ts.map +1 -1
  85. package/dist/connectors/builtin/steps/wait.step.js +11 -57
  86. package/dist/connectors/builtin/steps/wait.step.js.map +1 -1
  87. package/dist/conversational-flow/create.d.ts +2 -1
  88. package/dist/conversational-flow/create.d.ts.map +1 -1
  89. package/dist/conversational-flow/create.js +2 -2
  90. package/dist/conversational-flow/create.js.map +1 -1
  91. package/dist/conversational-flow/edit/build.js +1 -1
  92. package/dist/conversational-flow/edit/build.js.map +1 -1
  93. package/dist/conversational-flow/edit/questions.d.ts +35 -0
  94. package/dist/conversational-flow/edit/questions.d.ts.map +1 -0
  95. package/dist/conversational-flow/edit/questions.js +188 -0
  96. package/dist/conversational-flow/edit/questions.js.map +1 -0
  97. package/dist/conversational-flow/questions.d.ts +32 -0
  98. package/dist/conversational-flow/questions.d.ts.map +1 -0
  99. package/dist/conversational-flow/questions.js +122 -0
  100. package/dist/conversational-flow/questions.js.map +1 -0
  101. package/dist/engine/config-validator.d.ts.map +1 -1
  102. package/dist/engine/config-validator.js +29 -0
  103. package/dist/engine/config-validator.js.map +1 -1
  104. package/dist/engine/pause-step.d.ts +21 -4
  105. package/dist/engine/pause-step.d.ts.map +1 -1
  106. package/dist/engine/pause-step.js +11 -2
  107. package/dist/engine/pause-step.js.map +1 -1
  108. package/dist/engine/read-config.d.ts +12 -0
  109. package/dist/engine/read-config.d.ts.map +1 -0
  110. package/dist/engine/read-config.js +50 -0
  111. package/dist/engine/read-config.js.map +1 -0
  112. package/dist/engine/workflow-executor.d.ts.map +1 -1
  113. package/dist/engine/workflow-executor.js +38 -56
  114. package/dist/engine/workflow-executor.js.map +1 -1
  115. package/dist/index.d.ts +14 -6
  116. package/dist/index.d.ts.map +1 -1
  117. package/dist/index.js +6 -2
  118. package/dist/index.js.map +1 -1
  119. package/dist/persistence/in-memory-adapter.d.ts +3 -18
  120. package/dist/persistence/in-memory-adapter.d.ts.map +1 -1
  121. package/dist/persistence/in-memory-adapter.js +9 -61
  122. package/dist/persistence/in-memory-adapter.js.map +1 -1
  123. package/dist/persistence/types.d.ts +29 -58
  124. package/dist/persistence/types.d.ts.map +1 -1
  125. package/dist/router/approval-context.d.ts +1 -1
  126. package/dist/router/approval-context.d.ts.map +1 -1
  127. package/dist/router/approval-context.js +3 -3
  128. package/dist/router/approval-context.js.map +1 -1
  129. package/dist/router/types.d.ts +18 -7
  130. package/dist/router/types.d.ts.map +1 -1
  131. package/dist/router/workflow-router.d.ts.map +1 -1
  132. package/dist/router/workflow-router.js +164 -123
  133. package/dist/router/workflow-router.js.map +1 -1
  134. package/dist/runtime/workflow-runtime.d.ts +40 -45
  135. package/dist/runtime/workflow-runtime.d.ts.map +1 -1
  136. package/dist/runtime/workflow-runtime.js +188 -123
  137. package/dist/runtime/workflow-runtime.js.map +1 -1
  138. package/dist/steps/base-step.d.ts +11 -10
  139. package/dist/steps/base-step.d.ts.map +1 -1
  140. package/dist/steps/base-step.js.map +1 -1
  141. package/dist/storage/files.d.ts +39 -0
  142. package/dist/storage/files.d.ts.map +1 -0
  143. package/dist/storage/files.js +75 -0
  144. package/dist/storage/files.js.map +1 -0
  145. package/dist/storage/in-memory-adapter.d.ts +15 -8
  146. package/dist/storage/in-memory-adapter.d.ts.map +1 -1
  147. package/dist/storage/in-memory-adapter.js +36 -18
  148. package/dist/storage/in-memory-adapter.js.map +1 -1
  149. package/dist/storage/types.d.ts +36 -26
  150. package/dist/storage/types.d.ts.map +1 -1
  151. package/dist/storage/types.js +5 -6
  152. package/dist/storage/types.js.map +1 -1
  153. package/dist/testing/mock-step-context.d.ts +7 -2
  154. package/dist/testing/mock-step-context.d.ts.map +1 -1
  155. package/dist/testing/mock-step-context.js +2 -1
  156. package/dist/testing/mock-step-context.js.map +1 -1
  157. package/dist/testing/test-connector.d.ts +1 -1
  158. package/dist/testing/test-connector.js +1 -1
  159. package/dist/types/index.d.ts +2 -2
  160. package/dist/types/index.d.ts.map +1 -1
  161. package/dist/types/index.js +1 -1
  162. package/dist/types/index.js.map +1 -1
  163. package/dist/types/known-types.d.ts +51 -1
  164. package/dist/types/known-types.d.ts.map +1 -1
  165. package/dist/types/known-types.js +54 -1
  166. package/dist/types/known-types.js.map +1 -1
  167. package/dist/types/pause-state.d.ts +0 -8
  168. package/dist/types/pause-state.d.ts.map +1 -1
  169. package/dist/types/pause-state.js.map +1 -1
  170. package/dist/types/workflow-variable.d.ts +20 -10
  171. package/dist/types/workflow-variable.d.ts.map +1 -1
  172. package/package.json +1 -1
@@ -23,6 +23,7 @@
23
23
  * }
24
24
  * ```
25
25
  */
26
+ import { httpStatusFor } from '../completion/types.js';
26
27
  import { agentLoop } from '@earendil-works/pi-agent-core';
27
28
  import { createChatAgentTools } from '../agents/builtin/chat-tools.js';
28
29
  import { buildWorkflowContext, buildExecutionDataFile, collectExecutionAttachments, EXECUTION_DATA_PATH } from './approval-context.js';
@@ -30,6 +31,9 @@ import { OPERATOR_DESCRIPTORS } from '../types/operators.js';
30
31
  import { getAvailableContext } from '../engine/available-context.js';
31
32
  import { executionTopic, workflowTopic, folderTopic, rootTopic } from '../events/types.js';
32
33
  import { isExecutable } from '../common/executable-check.js';
34
+ import { createFileAccess } from '../storage/files.js';
35
+ import { isAttachmentArrayProperty } from '../common/attachment.js';
36
+ import { addMultipartValue, coerceTextFields } from '../common/multipart-values.js';
33
37
  import { createEventChannel } from '../util/event-channel.js';
34
38
  import { AccessDeniedError, ResourceNotFoundError } from '../authz/default.js';
35
39
  import { conversationRoutes } from '../conversational-flow/server/routes.js';
@@ -62,74 +66,53 @@ function objectBody(body) {
62
66
  ? body
63
67
  : {};
64
68
  }
65
- function parseMultipartValue(value) {
66
- if (Array.isArray(value))
67
- return value.map((entry) => parseMultipartValue(entry));
68
- if (typeof value !== 'string')
69
- return value;
70
- const trimmed = value.trim();
71
- if (!trimmed)
72
- return value;
73
- try {
74
- return JSON.parse(trimmed);
75
- }
76
- catch {
77
- return value;
78
- }
79
- }
80
- function addMultipartValue(payload, key, value) {
81
- const current = payload[key];
82
- if (current === undefined) {
83
- payload[key] = value;
84
- }
85
- else if (Array.isArray(current)) {
86
- current.push(value);
87
- }
88
- else {
89
- payload[key] = [current, value];
90
- }
91
- }
92
- function schemaProperties(inputSchema) {
93
- const props = inputSchema?.['properties'];
94
- return props && typeof props === 'object' && !Array.isArray(props)
95
- ? props
96
- : {};
97
- }
98
- function isAttachmentArrayField(inputSchema, key) {
99
- const prop = schemaProperties(inputSchema)[key];
100
- const items = prop?.['items'];
101
- return prop?.['type'] === 'array' &&
102
- Boolean(items) &&
103
- typeof items === 'object' &&
104
- !Array.isArray(items) &&
105
- items['format'] === 'attachment';
106
- }
107
- async function buildMultipartTriggerPayload(req, storage, scope, inputSchema) {
108
- const payload = {};
109
- for (const [key, value] of Object.entries(objectBody(req.body))) {
110
- addMultipartValue(payload, key, parseMultipartValue(value));
111
- }
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) };
112
74
  const groupedFiles = new Map();
113
75
  for (const file of req.files ?? []) {
114
76
  if (!file.fieldName) {
115
- 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`);
116
78
  }
117
- const attachment = await storage.store(scope, {
118
- name: file.name,
119
- mimeType: file.mimeType,
120
- bytes: file.bytes,
121
- });
122
79
  const group = groupedFiles.get(file.fieldName) ?? [];
123
- group.push(attachment);
80
+ group.push(file.attachment);
124
81
  groupedFiles.set(file.fieldName, group);
125
82
  }
126
83
  for (const [fieldName, attachments] of groupedFiles) {
127
- addMultipartValue(payload, fieldName, isAttachmentArrayField(inputSchema, fieldName) || attachments.length > 1
84
+ addMultipartValue(payload, fieldName, isAttachmentArrayProperty(inputSchema, fieldName) || attachments.length > 1
128
85
  ? attachments
129
86
  : attachments[0]);
130
87
  }
131
88
  return payload;
132
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
+ }
133
116
  /** Format a single SSE message. */
134
117
  function formatSSE(event, data) {
135
118
  return `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`;
@@ -609,18 +592,16 @@ opts) {
609
592
  if (!runtime.storage) {
610
593
  return error(501, 'No StorageAdapter configured — multipart trigger uploads are disabled');
611
594
  }
612
- const files = req.files;
613
- if (files && files.length > 0 && !runtime.allowExecutableUploads) {
614
- for (const file of files) {
615
- const reason = isExecutable(file.mimeType, file.name);
616
- if (reason) {
617
- return badRequest(`"${file.name}" rejected: ${reason}`);
618
- }
619
- }
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);
620
601
  }
621
602
  try {
622
603
  const target = await runtime.getApiTriggerTarget(workflowId);
623
- const payload = await buildMultipartTriggerPayload(req, runtime.storage, target.storageScope, target.inputSchema);
604
+ const payload = buildMultipartTriggerPayload(req, target.inputSchema);
624
605
  const executionId = await runtime.triggerViaApi(workflowId, payload);
625
606
  return created({ executionId });
626
607
  }
@@ -650,38 +631,23 @@ opts) {
650
631
  if (!files || files.length === 0) {
651
632
  return badRequest('No files in request — did the host run a multipart parser?');
652
633
  }
653
- // Perimeter check: reject executables unless the host opted in. This
654
- // applies to ALL uploads regardless of workflow — the upload route
655
- // doesn't know which workflow the files are for yet.
656
- if (!runtime.allowExecutableUploads) {
657
- for (const file of files) {
658
- const reason = isExecutable(file.mimeType, file.name);
659
- if (reason) {
660
- return badRequest(`"${file.name}" rejected: ${reason}`);
661
- }
662
- }
663
- }
664
634
  // The host's auth context IS its storage scope for caller-initiated work: an
665
635
  // upload has a person and no workflow yet. Not provable here (TCtx is unbound
666
636
  // at this point), so the host's adapter validates and rejects a scope it
667
637
  // cannot read a tenant from.
668
638
  const scope = auth;
669
- try {
670
- const attachments = [];
671
- for (const file of files) {
672
- attachments.push(await runtime.storage.store(scope, {
673
- name: file.name,
674
- mimeType: file.mimeType,
675
- bytes: file.bytes,
676
- }));
677
- }
678
- return created({ attachments });
679
- }
680
- catch (err) {
681
- if (err instanceof AccessDeniedError)
682
- throw err;
683
- return error(500, err instanceof Error ? err.message : 'Upload failed');
684
- }
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) });
685
651
  },
686
652
  });
687
653
  // ─── Attachment download (serve bytes / redirect to signed URL) ───
@@ -703,7 +669,7 @@ opts) {
703
669
  return badRequest('Missing required query param: ref');
704
670
  const name = typeof req.query['name'] === 'string' ? req.query['name'] : 'download';
705
671
  const mime = typeof req.query['mime'] === 'string' ? req.query['mime'] : 'application/octet-stream';
706
- const attachment = { name, mimeType: mime, data: ref };
672
+ const attachment = { name, mimeType: mime, handle: ref };
707
673
  try {
708
674
  if (runtime.storage.signUrl) {
709
675
  const url = await runtime.storage.signUrl(attachment, 300);
@@ -711,10 +677,19 @@ opts) {
711
677
  }
712
678
  // Pass the caller so a tenant-enforcing adapter can refuse a reference
713
679
  // owned by another workspace. `ref` is client-supplied.
714
- 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);
715
689
  return {
716
690
  status: 200,
717
- body: bytes,
691
+ body: null,
692
+ bodyStream: body,
718
693
  headers: {
719
694
  'Content-Type': mime,
720
695
  // Force download; never inline-render. An uploaded HTML/SVG must not
@@ -724,7 +699,7 @@ opts) {
724
699
  'Content-Disposition': `attachment; filename="${encodeURIComponent(name)}"`,
725
700
  'X-Content-Type-Options': 'nosniff',
726
701
  'Content-Security-Policy': "default-src 'none'; sandbox",
727
- 'Content-Length': String(bytes.byteLength),
702
+ 'Content-Length': String(known.size),
728
703
  },
729
704
  };
730
705
  }
@@ -826,6 +801,66 @@ opts) {
826
801
  }
827
802
  },
828
803
  });
804
+ // ─── Continuing a run from outside ───
805
+ /**
806
+ * What an external system reports back to a run that is waiting for it.
807
+ *
808
+ * `provider`, like the trigger routes: the SDK authenticates nobody. A host
809
+ * mounts this where its own gate already is — ours mounts it on the app
810
+ * router, so an install may answer a run of a workflow it is attached to, and
811
+ * nothing else. The engine has no principal to ask about, which is why the
812
+ * decision belongs to that mount rather than here.
813
+ *
814
+ * The outcome picks the status. `ignored` is deliberately 2xx: a non-2xx
815
+ * would have a sender's recovery worker redeliver what we dropped on purpose.
816
+ */
817
+ routes.push({
818
+ method: 'POST',
819
+ path: '/executions/:execId/waits/:stepId',
820
+ access: 'provider',
821
+ // Either content type on one URL: a sender with a result posts JSON, and one
822
+ // with a result and a file posts multipart. A gate's contract describes both
823
+ // the same way, so which was used is not the author's concern.
824
+ multipart: 'any',
825
+ handler: async (req) => {
826
+ const executionId = req.params['execId'] ?? '';
827
+ const stepId = req.params['stepId'] ?? '';
828
+ if (executionId === '' || stepId === '')
829
+ return badRequest('Missing execution or step');
830
+ const nodePath = req.query['nodePath'];
831
+ const fence = Number(req.query['fence']);
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
+ }
838
+ const files = [];
839
+ for (const file of req.files ?? []) {
840
+ if (!file.fieldName) {
841
+ await discardFiles(runtime.storage, req.files);
842
+ return badRequest(`Uploaded file "${file.attachment.name}" is missing a multipart field name`);
843
+ }
844
+ files.push({ fieldName: file.fieldName, attachment: file.attachment });
845
+ }
846
+ // Only how it arrived is decided here. What a text field means is the
847
+ // gate contract's business, and the contract is on the parked record,
848
+ // which only `deliver` has resolved by the time it matters.
849
+ const multipart = String(req.headers['content-type'] ?? '').includes('multipart/form-data');
850
+ const outcome = await runtime.deliver({
851
+ executionId,
852
+ stepId,
853
+ ...(typeof nodePath === 'string' && nodePath !== '' ? { nodePath } : {}),
854
+ ...(Number.isInteger(fence) ? { fence } : {}),
855
+ }, {
856
+ payload: multipart ? objectBody(req.body) : req.body,
857
+ ...(files.length > 0 ? { files } : {}),
858
+ ...(multipart ? { encoding: 'multipart' } : {}),
859
+ ...(typeof deliveryId === 'string' && deliveryId !== '' ? { deliveryId } : {}),
860
+ });
861
+ return { status: httpStatusFor(outcome), body: outcome };
862
+ },
863
+ });
829
864
  // Per-step activity events (agent thinking / tool calls / logs) for the run
830
865
  // view's activity timeline. Lazy: fetched only when a step panel is opened,
831
866
  // so the execution-detail payload stays lean. Live runs append the SSE
@@ -924,18 +959,6 @@ opts) {
924
959
  return webhookResponse(reply);
925
960
  },
926
961
  });
927
- // ─── Wait callbacks (no auth — validated by workflow secret in path) ───
928
- routes.push({
929
- method: 'POST',
930
- path: '/wait/callback/:secret/:executionId',
931
- access: 'provider',
932
- handler: async (req, _auth) => {
933
- const secret = req.params['secret'] ?? '';
934
- const executionId = req.params['executionId'] ?? '';
935
- const result = await runtime.handleWaitCallback(secret, executionId, req.body);
936
- return { status: result.status, body: result.body };
937
- },
938
- });
939
962
  // ─── Schema metadata (for UI) ───
940
963
  routes.push({
941
964
  method: 'GET',
@@ -1665,9 +1688,10 @@ opts) {
1665
1688
  if (typeof att.attachment.size === 'number' && att.attachment.size > MAX_MOUNT_BYTES)
1666
1689
  continue;
1667
1690
  try {
1668
- 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 });
1669
1693
  preloadFiles.push({ path: att.sandboxPath, bytes });
1670
- mountedPaths.set(att.attachment.data, att.sandboxPath);
1694
+ mountedPaths.set(att.attachment.handle, att.sandboxPath);
1671
1695
  }
1672
1696
  catch {
1673
1697
  // Unavailable — left unmounted; annotated with sandboxPath: null.
@@ -1755,8 +1779,8 @@ opts) {
1755
1779
  }
1756
1780
  let messages = [...body.messages];
1757
1781
  const uploadedFile = req.files?.[0];
1758
- if (uploadedFile) {
1759
- const fileText = aiBuilderExtractFileText(uploadedFile);
1782
+ if (uploadedFile && runtime.storage) {
1783
+ const fileText = await aiBuilderFileText(runtime.storage, uploadedFile.attachment, auth);
1760
1784
  if (fileText) {
1761
1785
  const lastUserIdx = [...messages].reverse().findIndex((m) => m.role === 'user');
1762
1786
  if (lastUserIdx !== -1) {
@@ -1764,7 +1788,7 @@ opts) {
1764
1788
  messages = [...messages];
1765
1789
  messages[idx] = {
1766
1790
  ...messages[idx],
1767
- content: `${messages[idx].content}\n\n--- Attached: ${uploadedFile.name} ---\n${fileText}`,
1791
+ content: `${messages[idx].content}\n\n--- Attached: ${uploadedFile.attachment.name} ---\n${fileText}`,
1768
1792
  };
1769
1793
  }
1770
1794
  }
@@ -1924,18 +1948,35 @@ The user's most recent message is the only thing that matters. Answer it directl
1924
1948
  \`\`\`json:formfill
1925
1949
  { "fieldKey": "user-provided value" }
1926
1950
  \`\`\``;
1927
- function aiBuilderExtractFileText(file) {
1928
- const mime = file.mimeType;
1929
- const name = file.name.toLowerCase();
1930
- const isText = mime.startsWith('text/') ||
1931
- 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' ||
1932
1956
  name.endsWith('.md') ||
1933
1957
  name.endsWith('.txt') ||
1934
1958
  name.endsWith('.json') ||
1935
- name.endsWith('.csv');
1936
- if (isText)
1937
- return new TextDecoder().decode(file.bytes);
1938
- 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
+ }
1939
1980
  }
1940
1981
  function parseWorkflowPatch(text) {
1941
1982
  const fenceRegex = /```(?:json)?\s*([\s\S]*?)```/gm;
@@ -2025,11 +2066,11 @@ function parseResumePayload(raw) {
2025
2066
  const rec = a;
2026
2067
  if (typeof rec['name'] === 'string' &&
2027
2068
  typeof rec['mimeType'] === 'string' &&
2028
- typeof rec['data'] === 'string') {
2069
+ typeof rec['handle'] === 'string') {
2029
2070
  cleaned.push({
2030
2071
  name: rec['name'],
2031
2072
  mimeType: rec['mimeType'],
2032
- data: rec['data'],
2073
+ handle: rec['handle'],
2033
2074
  });
2034
2075
  }
2035
2076
  }