@pylonsync/functions 0.22.34 → 0.22.35

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Campbell Venture Studio, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -19,7 +19,7 @@
19
19
  */
20
20
  export { query, mutation, action } from "./define";
21
21
  export { v } from "./validators";
22
- export { workflow } from "./workflows";
22
+ export { isWorkflowSignal, workflow } from "./workflows";
23
23
  export type { RawResponse, RawResponseInit } from "./response";
24
24
  export { agent, isAgentDefinition, validatorToJsonSchema, validatorSchemaToJsonSchema, } from "./agent";
25
25
  export type { AgentDefinition, AgentTool, AgentToolRun, AgentCallArgs, AgentResult, } from "./agent";
@@ -137,6 +137,17 @@ export declare function workflow<TInput = unknown>(name: string, fn: (wf: Workfl
137
137
  }): WorkflowDefinition<TInput>;
138
138
  /** Runtime shape check for a `workflows/` file's default export. */
139
139
  export declare function isWorkflowDefinition(v: unknown): v is WorkflowDefinition;
140
+ /**
141
+ * Whether `err` is the engine pausing the workflow (a slice boundary or a
142
+ * wait), not a failure. A `try`/`catch` around steps in a workflow body must
143
+ * rethrow these untouched, or the workflow treats every pause as a crash:
144
+ *
145
+ * catch (err) {
146
+ * if (isWorkflowSignal(err)) throw err;
147
+ * // real failure handling
148
+ * }
149
+ */
150
+ export declare function isWorkflowSignal(err: unknown): boolean;
140
151
  /**
141
152
  * Execute one slice of `def` for `request`, returning the engine verdict.
142
153
  * Never throws for handler errors — a step failure becomes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pylonsync/functions",
3
- "version": "0.22.34",
3
+ "version": "0.22.35",
4
4
  "description": "TypeScript function runtime for pylon — defines server-side queries, mutations, and actions.",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -30,7 +30,8 @@
30
30
  "src",
31
31
  "dist",
32
32
  "assets",
33
- "README.md"
33
+ "README.md",
34
+ "LICENSE"
34
35
  ],
35
36
  "scripts": {
36
37
  "check": "tsc --noEmit",
@@ -45,7 +46,7 @@
45
46
  "functions",
46
47
  "database"
47
48
  ],
48
- "license": "MIT OR Apache-2.0",
49
+ "license": "MIT",
49
50
  "dependencies": {
50
51
  "satori": "^0.26.0",
51
52
  "@resvg/resvg-wasm": "^2.6.2",
package/src/index.ts CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  export { query, mutation, action } from "./define";
22
22
  export { v } from "./validators";
23
- export { workflow } from "./workflows";
23
+ export { isWorkflowSignal, workflow } from "./workflows";
24
24
  export type { RawResponse, RawResponseInit } from "./response";
25
25
  export {
26
26
  agent,
@@ -15,6 +15,7 @@ import { describe, expect, test } from "bun:test";
15
15
  import {
16
16
  executeWorkflowSlice,
17
17
  isWorkflowDefinition,
18
+ isWorkflowSignal,
18
19
  workflow,
19
20
  type WorkflowRunRequest,
20
21
  type WorkflowStepResult,
@@ -264,3 +265,41 @@ describe("executeWorkflowSlice", () => {
264
265
  expect(res).toEqual({ action: "complete", output: { echoed: 42 } });
265
266
  });
266
267
  });
268
+
269
+ describe("catching errors around steps", () => {
270
+ test("a pause is a workflow signal, not a failure, when the body catches it", async () => {
271
+ const failures: unknown[] = [];
272
+ const guarded = workflow("guarded", async (wf) => {
273
+ try {
274
+ await wf.step("one", () => 1);
275
+ await wf.step("two", () => 2);
276
+ return { ok: true };
277
+ } catch (err) {
278
+ if (isWorkflowSignal(err)) throw err;
279
+ failures.push(err);
280
+ throw err;
281
+ }
282
+ });
283
+ // Slice 0 runs step one and pauses at step two's boundary.
284
+ const res = await executeWorkflowSlice(guarded, req(0, []), ctx);
285
+ expect(res).toMatchObject({ action: "step_complete", step_name: "one" });
286
+ expect(failures).toEqual([]);
287
+ });
288
+
289
+ test("without the check, the body sees the pause as an error (the bug the helper prevents)", async () => {
290
+ const seen: string[] = [];
291
+ const careless = workflow("careless", async (wf) => {
292
+ try {
293
+ await wf.step("one", () => 1);
294
+ await wf.step("two", () => 2);
295
+ } catch (err) {
296
+ seen.push((err as Error).message);
297
+ throw err;
298
+ }
299
+ });
300
+ await executeWorkflowSlice(careless, req(0, []), ctx);
301
+ expect(seen).toEqual(["slice boundary"]);
302
+ expect(isWorkflowSignal(new Error("slice boundary"))).toBe(false);
303
+ });
304
+ });
305
+
package/src/workflows.ts CHANGED
@@ -178,6 +178,20 @@ class SliceBoundary extends Error {
178
178
  }
179
179
  }
180
180
 
181
+ /**
182
+ * Whether `err` is the engine pausing the workflow (a slice boundary or a
183
+ * wait), not a failure. A `try`/`catch` around steps in a workflow body must
184
+ * rethrow these untouched, or the workflow treats every pause as a crash:
185
+ *
186
+ * catch (err) {
187
+ * if (isWorkflowSignal(err)) throw err;
188
+ * // real failure handling
189
+ * }
190
+ */
191
+ export function isWorkflowSignal(err: unknown): boolean {
192
+ return err instanceof SliceBoundary || err instanceof WorkflowPaused;
193
+ }
194
+
181
195
  /**
182
196
  * Execute one slice of `def` for `request`, returning the engine verdict.
183
197
  * Never throws for handler errors — a step failure becomes