@yolk-sdk/vercel-workflows 0.1.0-canary.30 → 0.1.0-canary.32

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 CHANGED
@@ -16,6 +16,7 @@ Canary APIs are unstable. Keep all `@yolk-sdk/*` packages on the same version.
16
16
  | --- | --- |
17
17
  | `@yolk-sdk/vercel-workflows` | Workflow-safe agent loop orchestration APIs |
18
18
  | `@yolk-sdk/vercel-workflows/workflow` | Explicit equivalent subpath |
19
+ | `@yolk-sdk/vercel-workflows/effect` | Effect-native wrapper around public `workflow/api` APIs |
19
20
 
20
21
  ## Imports
21
22
 
@@ -33,6 +34,23 @@ import {
33
34
 
34
35
  The `./workflow` subpath is also exported for explicit imports.
35
36
 
37
+ Use `./effect` at host boundaries that start, replay, resume, or cancel Workflow runs:
38
+
39
+ ```ts
40
+ import { Effect } from 'effect'
41
+ import { VercelWorkflows } from '@yolk-sdk/vercel-workflows/effect'
42
+
43
+ const program = Effect.gen(function* () {
44
+ const workflows = yield* VercelWorkflows
45
+ const run = yield* workflows.start(runAgentWorkflow, [{ request, context }])
46
+
47
+ return yield* run.getReadable<Uint8Array>()
48
+ }).pipe(Effect.provide(VercelWorkflows.layer))
49
+ ```
50
+
51
+ The API wrapper keeps Vercel's SDK underneath. It does not reimplement Vercel backend HTTP,
52
+ queues, hooks, or stream storage.
53
+
36
54
  ## Runtime model
37
55
 
38
56
  `runVercelAgentWorkflow` coordinates host-provided callbacks:
@@ -0,0 +1,56 @@
1
+ import { Context, Effect, Layer } from "effect";
2
+ import { WorkflowReadableStream, WorkflowReadableStreamOptions, WorkflowRun } from "workflow/api";
3
+
4
+ //#region src/effect.d.ts
5
+ type VercelWorkflowsOperation = 'start' | 'getRun' | 'getReadable' | 'tailIndex' | 'resumeHook' | 'cancel' | 'status' | 'returnValue';
6
+ declare const VercelWorkflowsError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => import("effect/Cause").YieldableError & {
7
+ readonly _tag: "VercelWorkflowsError";
8
+ } & Readonly<A>;
9
+ declare class VercelWorkflowsError extends VercelWorkflowsError_base<{
10
+ readonly operation: VercelWorkflowsOperation;
11
+ readonly message: string;
12
+ readonly cause: unknown;
13
+ }> {}
14
+ type VercelWorkflowFunction<TArgs extends unknown[], TResult> = (...args: TArgs) => Promise<TResult>;
15
+ type VercelWorkflowReadableOptions = WorkflowReadableStreamOptions;
16
+ type VercelWorkflowReadableStream<Chunk> = WorkflowReadableStream<Chunk>;
17
+ type VercelWorkflowRunStatus = WorkflowRun['status'];
18
+ type VercelWorkflowsSdkRun<TResult> = {
19
+ readonly runId: string;
20
+ readonly getReadable: <Chunk>(options?: VercelWorkflowReadableOptions) => VercelWorkflowReadableStream<Chunk>;
21
+ readonly cancel: () => Promise<void>;
22
+ readonly status: Promise<VercelWorkflowRunStatus>;
23
+ readonly returnValue: Promise<TResult>;
24
+ };
25
+ type VercelWorkflowsSdkClient = {
26
+ readonly start: <TArgs extends unknown[], TResult>(workflow: VercelWorkflowFunction<TArgs, TResult>, args: TArgs) => Promise<VercelWorkflowsSdkRun<TResult>>;
27
+ readonly getRun: <TResult>(runId: string) => VercelWorkflowsSdkRun<TResult>;
28
+ readonly resumeHook: (token: string, payload: unknown) => Promise<unknown>;
29
+ };
30
+ type VercelWorkflowRun<TResult> = {
31
+ readonly runId: string;
32
+ readonly getReadable: <Chunk>(options?: VercelWorkflowReadableOptions) => Effect.Effect<VercelWorkflowReadableStream<Chunk>, VercelWorkflowsError>;
33
+ readonly cancel: Effect.Effect<void, VercelWorkflowsError>;
34
+ readonly status: Effect.Effect<VercelWorkflowRunStatus, VercelWorkflowsError>;
35
+ readonly returnValue: Effect.Effect<TResult, VercelWorkflowsError>;
36
+ };
37
+ type VercelWorkflowsClient = {
38
+ readonly start: <TArgs extends unknown[], TResult>(workflow: VercelWorkflowFunction<TArgs, TResult>, args: TArgs) => Effect.Effect<VercelWorkflowRun<TResult>, VercelWorkflowsError>;
39
+ readonly getRun: <TResult>(runId: string) => Effect.Effect<VercelWorkflowRun<TResult>, VercelWorkflowsError>;
40
+ readonly getReadable: <Chunk>(runId: string, options?: VercelWorkflowReadableOptions) => Effect.Effect<VercelWorkflowReadableStream<Chunk>, VercelWorkflowsError>;
41
+ readonly tailIndex: (runId: string) => Effect.Effect<number, VercelWorkflowsError>;
42
+ readonly resumeHook: (token: string, payload: unknown) => Effect.Effect<void, VercelWorkflowsError>;
43
+ readonly cancel: (runId: string) => Effect.Effect<void, VercelWorkflowsError>;
44
+ };
45
+ declare const VercelWorkflowsSdk_base: Context.ServiceClass<VercelWorkflowsSdk, "@yolk-sdk/vercel-workflows/VercelWorkflowsSdk", VercelWorkflowsSdkClient>;
46
+ declare class VercelWorkflowsSdk extends VercelWorkflowsSdk_base {}
47
+ declare const VercelWorkflows_base: Context.ServiceClass<VercelWorkflows, "@yolk-sdk/vercel-workflows/VercelWorkflows", VercelWorkflowsClient> & {
48
+ readonly make: Effect.Effect<VercelWorkflowsClient, never, VercelWorkflowsSdk>;
49
+ };
50
+ declare class VercelWorkflows extends VercelWorkflows_base {
51
+ static layer: Layer.Layer<VercelWorkflows, never, never>;
52
+ static layerFromSdk: Layer.Layer<VercelWorkflows, never, VercelWorkflowsSdk>;
53
+ }
54
+ //#endregion
55
+ export { VercelWorkflowFunction, VercelWorkflowReadableOptions, VercelWorkflowReadableStream, VercelWorkflowRun, VercelWorkflowRunStatus, VercelWorkflows, VercelWorkflowsClient, VercelWorkflowsError, VercelWorkflowsOperation, VercelWorkflowsSdk, VercelWorkflowsSdkClient, VercelWorkflowsSdkRun };
56
+ //# sourceMappingURL=effect.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect.d.mts","names":[],"sources":["../src/effect.ts"],"mappings":";;;;KAUY,wBAAA;AAAA,cAQK,yBAAA;;;cAEJ,oBAAA,SAA6B,yBAAA;EAAA,SAC/B,S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A,CAAkB,OAAA,GAAU,oBAAA;EAAA,SACtC,MAAA,YACP,KAAA,aACG,MAAA,CAAO,MAAA,CAAO,iBAAA,CAAkB,OAAA,GAAU,oBAAA;EAAA,SACtC,WAAA,UACP,KAAA,UACA,OAAA,GAAU,6BAAA,KACP,MAAA,CAAO,MAAA,CAAO,4BAAA,CAA6B,KAAA,GAAQ,oBAAA;EAAA,SAC/C,SAAA,GAAY,KAAA,aAAkB,MAAA,CAAO,MAAA,SAAe,oBAAA;EAAA,SACpD,UAAA,GACP,KAAA,UACA,OAAA,cACG,MAAA,CAAO,MAAA,OAAa,oBAAA;EAAA,SAChB,MAAA,GAAS,KAAA,aAAkB,MAAA,CAAO,MAAA,OAAa,oBAAA;AAAA;AAAA,cACzD,uBAAA;cAEY,kBAAA,SAA2B,uBAGY;AAAA,cAAG,oBAAA;;;cA2D1C,eAAA,SAAwB,oBAAA;EAAA,OAiF5B,KAAA,EAAK,KAAA,CAAA,KAAA,CAAA,eAAA;EAAA,OACL,YAAA,EAAY,KAAA,CAAA,KAAA,CAAA,eAAA,SAAA,kBAAA;AAAA"}
@@ -0,0 +1,66 @@
1
+ import { Context, Data, Effect, Layer } from "effect";
2
+ import { getRun, resumeHook, start } from "workflow/api";
3
+ //#region src/effect.ts
4
+ var VercelWorkflowsError = class extends Data.TaggedError("VercelWorkflowsError") {};
5
+ var VercelWorkflowsSdk = class extends Context.Service()("@yolk-sdk/vercel-workflows/VercelWorkflowsSdk") {};
6
+ const workflowsError = (operation, cause) => new VercelWorkflowsError({
7
+ operation,
8
+ message: `Vercel Workflow ${operation} failed`,
9
+ cause
10
+ });
11
+ const spanAttributes = (runId) => ({ "workflow.run.id": runId });
12
+ const makeWorkflowRun = (run) => ({
13
+ runId: run.runId,
14
+ getReadable: (options) => Effect.try({
15
+ try: () => run.getReadable(options),
16
+ catch: (cause) => workflowsError("getReadable", cause)
17
+ }).pipe(Effect.withSpan("VercelWorkflows.run.getReadable", { attributes: spanAttributes(run.runId) })),
18
+ cancel: Effect.tryPromise({
19
+ try: () => run.cancel(),
20
+ catch: (cause) => workflowsError("cancel", cause)
21
+ }).pipe(Effect.withSpan("VercelWorkflows.run.cancel", { attributes: spanAttributes(run.runId) })),
22
+ status: Effect.tryPromise({
23
+ try: () => run.status,
24
+ catch: (cause) => workflowsError("status", cause)
25
+ }).pipe(Effect.withSpan("VercelWorkflows.run.status", { attributes: spanAttributes(run.runId) })),
26
+ returnValue: Effect.tryPromise({
27
+ try: () => run.returnValue,
28
+ catch: (cause) => workflowsError("returnValue", cause)
29
+ }).pipe(Effect.withSpan("VercelWorkflows.run.returnValue", { attributes: spanAttributes(run.runId) }))
30
+ });
31
+ const VercelWorkflowsSdkLive = Layer.succeed(VercelWorkflowsSdk, {
32
+ start: (workflow, args) => start(workflow, args),
33
+ getRun: (runId) => getRun(runId),
34
+ resumeHook: (token, payload) => resumeHook(token, payload)
35
+ });
36
+ var VercelWorkflows = class extends Context.Service()("@yolk-sdk/vercel-workflows/VercelWorkflows", { make: Effect.gen(function* () {
37
+ const sdk = yield* VercelWorkflowsSdk;
38
+ const getRun = (runId) => Effect.try({
39
+ try: () => makeWorkflowRun(sdk.getRun(runId)),
40
+ catch: (cause) => workflowsError("getRun", cause)
41
+ }).pipe(Effect.withSpan("VercelWorkflows.getRun", { attributes: spanAttributes(runId) }));
42
+ return {
43
+ start: (workflow, args) => Effect.tryPromise({
44
+ try: () => sdk.start(workflow, args),
45
+ catch: (cause) => workflowsError("start", cause)
46
+ }).pipe(Effect.map(makeWorkflowRun), Effect.withSpan("VercelWorkflows.start")),
47
+ getRun,
48
+ getReadable: (runId, options) => getRun(runId).pipe(Effect.flatMap((run) => run.getReadable(options)), Effect.withSpan("VercelWorkflows.getReadable", { attributes: spanAttributes(runId) })),
49
+ tailIndex: (runId) => getRun(runId).pipe(Effect.flatMap((run) => run.getReadable({ startIndex: -1 })), Effect.flatMap((readable) => Effect.tryPromise({
50
+ try: () => readable.getTailIndex(),
51
+ catch: (cause) => workflowsError("tailIndex", cause)
52
+ })), Effect.withSpan("VercelWorkflows.tailIndex", { attributes: spanAttributes(runId) })),
53
+ resumeHook: (token, payload) => Effect.tryPromise({
54
+ try: () => sdk.resumeHook(token, payload).then(() => void 0),
55
+ catch: (cause) => workflowsError("resumeHook", cause)
56
+ }).pipe(Effect.withSpan("VercelWorkflows.resumeHook")),
57
+ cancel: (runId) => getRun(runId).pipe(Effect.flatMap((run) => run.cancel), Effect.withSpan("VercelWorkflows.cancel", { attributes: spanAttributes(runId) }))
58
+ };
59
+ }) }) {
60
+ static layer = Layer.effect(this, this.make).pipe(Layer.provide(VercelWorkflowsSdkLive));
61
+ static layerFromSdk = Layer.effect(this, this.make);
62
+ };
63
+ //#endregion
64
+ export { VercelWorkflows, VercelWorkflowsError, VercelWorkflowsSdk };
65
+
66
+ //# sourceMappingURL=effect.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect.mjs","names":["workflowStart","workflowGetRun","workflowResumeHook"],"sources":["../src/effect.ts"],"sourcesContent":["import { Context, Data, Effect, Layer } from 'effect'\nimport {\n getRun as workflowGetRun,\n resumeHook as workflowResumeHook,\n start as workflowStart,\n type WorkflowReadableStream,\n type WorkflowReadableStreamOptions,\n type WorkflowRun\n} from 'workflow/api'\n\nexport type VercelWorkflowsOperation =\n | 'start'\n | 'getRun'\n | 'getReadable'\n | 'tailIndex'\n | 'resumeHook'\n | 'cancel'\n | 'status'\n | 'returnValue'\n\nexport class VercelWorkflowsError extends Data.TaggedError('VercelWorkflowsError')<{\n readonly operation: VercelWorkflowsOperation\n readonly message: string\n readonly cause: unknown\n}> {}\n\nexport type VercelWorkflowFunction<TArgs extends unknown[], TResult> = (\n ...args: TArgs\n) => Promise<TResult>\n\nexport type VercelWorkflowReadableOptions = WorkflowReadableStreamOptions\nexport type VercelWorkflowReadableStream<Chunk> = WorkflowReadableStream<Chunk>\nexport type VercelWorkflowRunStatus = WorkflowRun['status']\n\nexport type VercelWorkflowsSdkRun<TResult> = {\n readonly runId: string\n readonly getReadable: <Chunk>(\n options?: VercelWorkflowReadableOptions\n ) => VercelWorkflowReadableStream<Chunk>\n readonly cancel: () => Promise<void>\n readonly status: Promise<VercelWorkflowRunStatus>\n readonly returnValue: Promise<TResult>\n}\n\nexport type VercelWorkflowsSdkClient = {\n readonly start: <TArgs extends unknown[], TResult>(\n workflow: VercelWorkflowFunction<TArgs, TResult>,\n args: TArgs\n ) => Promise<VercelWorkflowsSdkRun<TResult>>\n readonly getRun: <TResult>(runId: string) => VercelWorkflowsSdkRun<TResult>\n readonly resumeHook: (token: string, payload: unknown) => Promise<unknown>\n}\n\nexport type VercelWorkflowRun<TResult> = {\n readonly runId: string\n readonly getReadable: <Chunk>(\n options?: VercelWorkflowReadableOptions\n ) => Effect.Effect<VercelWorkflowReadableStream<Chunk>, VercelWorkflowsError>\n readonly cancel: Effect.Effect<void, VercelWorkflowsError>\n readonly status: Effect.Effect<VercelWorkflowRunStatus, VercelWorkflowsError>\n readonly returnValue: Effect.Effect<TResult, VercelWorkflowsError>\n}\n\nexport type VercelWorkflowsClient = {\n readonly start: <TArgs extends unknown[], TResult>(\n workflow: VercelWorkflowFunction<TArgs, TResult>,\n args: TArgs\n ) => Effect.Effect<VercelWorkflowRun<TResult>, VercelWorkflowsError>\n readonly getRun: <TResult>(\n runId: string\n ) => Effect.Effect<VercelWorkflowRun<TResult>, VercelWorkflowsError>\n readonly getReadable: <Chunk>(\n runId: string,\n options?: VercelWorkflowReadableOptions\n ) => Effect.Effect<VercelWorkflowReadableStream<Chunk>, VercelWorkflowsError>\n readonly tailIndex: (runId: string) => Effect.Effect<number, VercelWorkflowsError>\n readonly resumeHook: (\n token: string,\n payload: unknown\n ) => Effect.Effect<void, VercelWorkflowsError>\n readonly cancel: (runId: string) => Effect.Effect<void, VercelWorkflowsError>\n}\n\nexport class VercelWorkflowsSdk extends Context.Service<\n VercelWorkflowsSdk,\n VercelWorkflowsSdkClient\n>()('@yolk-sdk/vercel-workflows/VercelWorkflowsSdk') {}\n\nconst workflowsError = (operation: VercelWorkflowsOperation, cause: unknown) =>\n new VercelWorkflowsError({\n operation,\n message: `Vercel Workflow ${operation} failed`,\n cause\n })\n\nconst spanAttributes = (runId: string) => ({ 'workflow.run.id': runId })\n\nconst makeWorkflowRun = <TResult>(\n run: VercelWorkflowsSdkRun<TResult>\n): VercelWorkflowRun<TResult> => ({\n runId: run.runId,\n getReadable: <Chunk>(options?: VercelWorkflowReadableOptions) =>\n Effect.try({\n try: () => run.getReadable<Chunk>(options),\n catch: cause => workflowsError('getReadable', cause)\n }).pipe(\n Effect.withSpan('VercelWorkflows.run.getReadable', {\n attributes: spanAttributes(run.runId)\n })\n ),\n cancel: Effect.tryPromise({\n try: () => run.cancel(),\n catch: cause => workflowsError('cancel', cause)\n }).pipe(\n Effect.withSpan('VercelWorkflows.run.cancel', {\n attributes: spanAttributes(run.runId)\n })\n ),\n status: Effect.tryPromise({\n try: () => run.status,\n catch: cause => workflowsError('status', cause)\n }).pipe(\n Effect.withSpan('VercelWorkflows.run.status', {\n attributes: spanAttributes(run.runId)\n })\n ),\n returnValue: Effect.tryPromise({\n try: () => run.returnValue,\n catch: cause => workflowsError('returnValue', cause)\n }).pipe(\n Effect.withSpan('VercelWorkflows.run.returnValue', {\n attributes: spanAttributes(run.runId)\n })\n )\n})\n\nconst VercelWorkflowsSdkLive = Layer.succeed(VercelWorkflowsSdk, {\n start: <TArgs extends unknown[], TResult>(\n workflow: VercelWorkflowFunction<TArgs, TResult>,\n args: TArgs\n ) => workflowStart(workflow, args),\n getRun: <TResult>(runId: string) => workflowGetRun<TResult>(runId),\n resumeHook: (token: string, payload: unknown) => workflowResumeHook<unknown>(token, payload)\n})\n\nexport class VercelWorkflows extends Context.Service<\n VercelWorkflows,\n VercelWorkflowsClient\n>()(\n '@yolk-sdk/vercel-workflows/VercelWorkflows',\n {\n make: Effect.gen(function* () {\n const sdk = yield* VercelWorkflowsSdk\n\n const getRun = <TResult>(\n runId: string\n ): Effect.Effect<VercelWorkflowRun<TResult>, VercelWorkflowsError> =>\n Effect.try({\n try: () => makeWorkflowRun(sdk.getRun<TResult>(runId)),\n catch: cause => workflowsError('getRun', cause)\n }).pipe(\n Effect.withSpan('VercelWorkflows.getRun', {\n attributes: spanAttributes(runId)\n })\n )\n\n return {\n start: <TArgs extends unknown[], TResult>(\n workflow: VercelWorkflowFunction<TArgs, TResult>,\n args: TArgs\n ): Effect.Effect<VercelWorkflowRun<TResult>, VercelWorkflowsError> =>\n Effect.tryPromise({\n try: () => sdk.start(workflow, args),\n catch: cause => workflowsError('start', cause)\n }).pipe(\n Effect.map(makeWorkflowRun),\n Effect.withSpan('VercelWorkflows.start')\n ),\n\n getRun,\n\n getReadable: <Chunk>(\n runId: string,\n options?: VercelWorkflowReadableOptions\n ): Effect.Effect<VercelWorkflowReadableStream<Chunk>, VercelWorkflowsError> =>\n getRun<unknown>(runId).pipe(\n Effect.flatMap(run => run.getReadable<Chunk>(options)),\n Effect.withSpan('VercelWorkflows.getReadable', {\n attributes: spanAttributes(runId)\n })\n ),\n\n tailIndex: (runId: string): Effect.Effect<number, VercelWorkflowsError> =>\n getRun<unknown>(runId).pipe(\n Effect.flatMap(run => run.getReadable<unknown>({ startIndex: -1 })),\n Effect.flatMap(readable =>\n Effect.tryPromise({\n try: () => readable.getTailIndex(),\n catch: cause => workflowsError('tailIndex', cause)\n })\n ),\n Effect.withSpan('VercelWorkflows.tailIndex', {\n attributes: spanAttributes(runId)\n })\n ),\n\n resumeHook: (\n token: string,\n payload: unknown\n ): Effect.Effect<void, VercelWorkflowsError> =>\n Effect.tryPromise({\n try: () => sdk.resumeHook(token, payload).then(() => undefined),\n catch: cause => workflowsError('resumeHook', cause)\n }).pipe(Effect.withSpan('VercelWorkflows.resumeHook')),\n\n cancel: (runId: string): Effect.Effect<void, VercelWorkflowsError> =>\n getRun<unknown>(runId).pipe(\n Effect.flatMap(run => run.cancel),\n Effect.withSpan('VercelWorkflows.cancel', {\n attributes: spanAttributes(runId)\n })\n )\n }\n })\n }\n) {\n static layer = Layer.effect(this, this.make).pipe(Layer.provide(VercelWorkflowsSdkLive))\n static layerFromSdk = Layer.effect(this, this.make)\n}\n"],"mappings":";;;AAoBA,IAAa,uBAAb,cAA0C,KAAK,YAAY,sBAAsB,EAI9E,CAAC;AA2DJ,IAAa,qBAAb,cAAwC,QAAQ,QAG9C,EAAE,+CAA+C,EAAE,CAAC;AAEtD,MAAM,kBAAkB,WAAqC,UAC3D,IAAI,qBAAqB;CACvB;CACA,SAAS,mBAAmB,UAAU;CACtC;AACF,CAAC;AAEH,MAAM,kBAAkB,WAAmB,EAAE,mBAAmB,MAAM;AAEtE,MAAM,mBACJ,SACgC;CAChC,OAAO,IAAI;CACX,cAAqB,YACnB,OAAO,IAAI;EACT,WAAW,IAAI,YAAmB,OAAO;EACzC,QAAO,UAAS,eAAe,eAAe,KAAK;CACrD,CAAC,EAAE,KACD,OAAO,SAAS,mCAAmC,EACjD,YAAY,eAAe,IAAI,KAAK,EACtC,CAAC,CACH;CACF,QAAQ,OAAO,WAAW;EACxB,WAAW,IAAI,OAAO;EACtB,QAAO,UAAS,eAAe,UAAU,KAAK;CAChD,CAAC,EAAE,KACD,OAAO,SAAS,8BAA8B,EAC5C,YAAY,eAAe,IAAI,KAAK,EACtC,CAAC,CACH;CACA,QAAQ,OAAO,WAAW;EACxB,WAAW,IAAI;EACf,QAAO,UAAS,eAAe,UAAU,KAAK;CAChD,CAAC,EAAE,KACD,OAAO,SAAS,8BAA8B,EAC5C,YAAY,eAAe,IAAI,KAAK,EACtC,CAAC,CACH;CACA,aAAa,OAAO,WAAW;EAC7B,WAAW,IAAI;EACf,QAAO,UAAS,eAAe,eAAe,KAAK;CACrD,CAAC,EAAE,KACD,OAAO,SAAS,mCAAmC,EACjD,YAAY,eAAe,IAAI,KAAK,EACtC,CAAC,CACH;AACF;AAEA,MAAM,yBAAyB,MAAM,QAAQ,oBAAoB;CAC/D,QACE,UACA,SACGA,MAAc,UAAU,IAAI;C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SAAS,UACP,OAAgB,KAAK,EAAE,KACrB,OAAO,SAAQ,QAAO,IAAI,MAAM,GAChC,OAAO,SAAS,0BAA0B,EACxC,YAAY,eAAe,KAAK,EAClC,CAAC,CACH;CACJ;AACF,CAAC,EACH,CACF,EAAE;CACA,OAAO,QAAQ,MAAM,OAAO,MAAM,KAAK,IAAI,EAAE,KAAK,MAAM,QAAQ,sBAAsB,CAAC;CACvF,OAAO,eAAe,MAAM,OAAO,MAAM,KAAK,IAAI;AACpD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yolk-sdk/vercel-workflows",
3
- "version": "0.1.0-canary.30",
3
+ "version": "0.1.0-canary.32",
4
4
  "description": "Vercel Workflow orchestration primitives for Yolk agent loops.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -35,6 +35,11 @@
35
35
  "types": "./dist/workflow.d.mts",
36
36
  "import": "./dist/workflow.mjs",
37
37
  "default": "./dist/workflow.mjs"
38
+ },
39
+ "./effect": {
40
+ "types": "./dist/effect.d.mts",
41
+ "import": "./dist/effect.mjs",
42
+ "default": "./dist/effect.mjs"
38
43
  }
39
44
  },
40
45
  "files": [
package/src/effect.ts ADDED
@@ -0,0 +1,229 @@
1
+ import { Context, Data, Effect, Layer } from 'effect'
2
+ import {
3
+ getRun as workflowGetRun,
4
+ resumeHook as workflowResumeHook,
5
+ start as workflowStart,
6
+ type WorkflowReadableStream,
7
+ type WorkflowReadableStreamOptions,
8
+ type WorkflowRun
9
+ } from 'workflow/api'
10
+
11
+ export type VercelWorkflowsOperation =
12
+ | 'start'
13
+ | 'getRun'
14
+ | 'getReadable'
15
+ | 'tailIndex'
16
+ | 'resumeHook'
17
+ | 'cancel'
18
+ | 'status'
19
+ | 'returnValue'
20
+
21
+ export class VercelWorkflowsError extends Data.TaggedError('VercelWorkflowsError')<{
22
+ readonly operation: VercelWorkflowsOperation
23
+ readonly message: string
24
+ readonly cause: unknown
25
+ }> {}
26
+
27
+ export type VercelWorkflowFunction<TArgs extends unknown[], TResult> = (
28
+ ...args: TArgs
29
+ ) => Promise<TResult>
30
+
31
+ export type VercelWorkflowReadableOptions = WorkflowReadableStreamOptions
32
+ export type VercelWorkflowReadableStream<Chunk> = WorkflowReadableStream<Chunk>
33
+ export type VercelWorkflowRunStatus = WorkflowRun['status']
34
+
35
+ export type VercelWorkflowsSdkRun<TResult> = {
36
+ readonly runId: string
37
+ readonly getReadable: <Chunk>(
38
+ options?: VercelWorkflowReadableOptions
39
+ ) => VercelWorkflowReadableStream<Chunk>
40
+ readonly cancel: () => Promise<void>
41
+ readonly status: Promise<VercelWorkflowRunStatus>
42
+ readonly returnValue: Promise<TResult>
43
+ }
44
+
45
+ export type VercelWorkflowsSdkClient = {
46
+ readonly start: <TArgs extends unknown[], TResult>(
47
+ workflow: VercelWorkflowFunction<TArgs, TResult>,
48
+ args: TArgs
49
+ ) => Promise<VercelWorkflowsSdkRun<TResult>>
50
+ readonly getRun: <TResult>(runId: string) => VercelWorkflowsSdkRun<TResult>
51
+ readonly resumeHook: (token: string, payload: unknown) => Promise<unknown>
52
+ }
53
+
54
+ export type VercelWorkflowRun<TResult> = {
55
+ readonly runId: string
56
+ readonly getReadable: <Chunk>(
57
+ options?: VercelWorkflowReadableOptions
58
+ ) => Effect.Effect<VercelWorkflowReadableStream<Chunk>, VercelWorkflowsError>
59
+ readonly cancel: Effect.Effect<void, VercelWorkflowsError>
60
+ readonly status: Effect.Effect<VercelWorkflowRunStatus, VercelWorkflowsError>
61
+ readonly returnValue: Effect.Effect<TResult, VercelWorkflowsError>
62
+ }
63
+
64
+ export type VercelWorkflowsClient = {
65
+ readonly start: <TArgs extends unknown[], TResult>(
66
+ workflow: VercelWorkflowFunction<TArgs, TResult>,
67
+ args: TArgs
68
+ ) => Effect.Effect<VercelWorkflowRun<TResult>, VercelWorkflowsError>
69
+ readonly getRun: <TResult>(
70
+ runId: string
71
+ ) => Effect.Effect<VercelWorkflowRun<TResult>, VercelWorkflowsError>
72
+ readonly getReadable: <Chunk>(
73
+ runId: string,
74
+ options?: VercelWorkflowReadableOptions
75
+ ) => Effect.Effect<VercelWorkflowReadableStream<Chunk>, VercelWorkflowsError>
76
+ readonly tailIndex: (runId: string) => Effect.Effect<number, VercelWorkflowsError>
77
+ readonly resumeHook: (
78
+ token: string,
79
+ payload: unknown
80
+ ) => Effect.Effect<void, VercelWorkflowsError>
81
+ readonly cancel: (runId: string) => Effect.Effect<void, VercelWorkflowsError>
82
+ }
83
+
84
+ export class VercelWorkflowsSdk extends Context.Service<
85
+ VercelWorkflowsSdk,
86
+ VercelWorkflowsSdkClient
87
+ >()('@yolk-sdk/vercel-workflows/VercelWorkflowsSdk') {}
88
+
89
+ const workflowsError = (operation: VercelWorkflowsOperation, cause: unknown) =>
90
+ new VercelWorkflowsError({
91
+ operation,
92
+ message: `Vercel Workflow ${operation} failed`,
93
+ cause
94
+ })
95
+
96
+ const spanAttributes = (runId: string) => ({ 'workflow.run.id': runId })
97
+
98
+ const makeWorkflowRun = <TResult>(
99
+ run: VercelWorkflowsSdkRun<TResult>
100
+ ): VercelWorkflowRun<TResult> => ({
101
+ runId: run.runId,
102
+ getReadable: <Chunk>(options?: VercelWorkflowReadableOptions) =>
103
+ Effect.try({
104
+ try: () => run.getReadable<Chunk>(options),
105
+ catch: cause => workflowsError('getReadable', cause)
106
+ }).pipe(
107
+ Effect.withSpan('VercelWorkflows.run.getReadable', {
108
+ attributes: spanAttributes(run.runId)
109
+ })
110
+ ),
111
+ cancel: Effect.tryPromise({
112
+ try: () => run.cancel(),
113
+ catch: cause => workflowsError('cancel', cause)
114
+ }).pipe(
115
+ Effect.withSpan('VercelWorkflows.run.cancel', {
116
+ attributes: spanAttributes(run.runId)
117
+ })
118
+ ),
119
+ status: Effect.tryPromise({
120
+ try: () => run.status,
121
+ catch: cause => workflowsError('status', cause)
122
+ }).pipe(
123
+ Effect.withSpan('VercelWorkflows.run.status', {
124
+ attributes: spanAttributes(run.runId)
125
+ })
126
+ ),
127
+ returnValue: Effect.tryPromise({
128
+ try: () => run.returnValue,
129
+ catch: cause => workflowsError('returnValue', cause)
130
+ }).pipe(
131
+ Effect.withSpan('VercelWorkflows.run.returnValue', {
132
+ attributes: spanAttributes(run.runId)
133
+ })
134
+ )
135
+ })
136
+
137
+ const VercelWorkflowsSdkLive = Layer.succeed(VercelWorkflowsSdk, {
138
+ start: <TArgs extends unknown[], TResult>(
139
+ workflow: VercelWorkflowFunction<TArgs, TResult>,
140
+ args: TArgs
141
+ ) => workflowStart(workflow, args),
142
+ getRun: <TResult>(runId: string) => workflowGetRun<TResult>(runId),
143
+ resumeHook: (token: string, payload: unknown) => workflowResumeHook<unknown>(token, payload)
144
+ })
145
+
146
+ export class VercelWorkflows extends Context.Service<
147
+ VercelWorkflows,
148
+ VercelWorkflowsClient
149
+ >()(
150
+ '@yolk-sdk/vercel-workflows/VercelWorkflows',
151
+ {
152
+ make: Effect.gen(function* () {
153
+ const sdk = yield* VercelWorkflowsSdk
154
+
155
+ const getRun = <TResult>(
156
+ runId: string
157
+ ): Effect.Effect<VercelWorkflowRun<TResult>, VercelWorkflowsError> =>
158
+ Effect.try({
159
+ try: () => makeWorkflowRun(sdk.getRun<TResult>(runId)),
160
+ catch: cause => workflowsError('getRun', cause)
161
+ }).pipe(
162
+ Effect.withSpan('VercelWorkflows.getRun', {
163
+ attributes: spanAttributes(runId)
164
+ })
165
+ )
166
+
167
+ return {
168
+ start: <TArgs extends unknown[], TResult>(
169
+ workflow: VercelWorkflowFunction<TArgs, TResult>,
170
+ args: TArgs
171
+ ): Effect.Effect<VercelWorkflowRun<TResult>, VercelWorkflowsError> =>
172
+ Effect.tryPromise({
173
+ try: () => sdk.start(workflow, args),
174
+ catch: cause => workflowsError('start', cause)
175
+ }).pipe(
176
+ Effect.map(makeWorkflowRun),
177
+ Effect.withSpan('VercelWorkflows.start')
178
+ ),
179
+
180
+ getRun,
181
+
182
+ getReadable: <Chunk>(
183
+ runId: string,
184
+ options?: VercelWorkflowReadableOptions
185
+ ): Effect.Effect<VercelWorkflowReadableStream<Chunk>, VercelWorkflowsError> =>
186
+ getRun<unknown>(runId).pipe(
187
+ Effect.flatMap(run => run.getReadable<Chunk>(options)),
188
+ Effect.withSpan('VercelWorkflows.getReadable', {
189
+ attributes: spanAttributes(runId)
190
+ })
191
+ ),
192
+
193
+ tailIndex: (runId: string): Effect.Effect<number, VercelWorkflowsError> =>
194
+ getRun<unknown>(runId).pipe(
195
+ Effect.flatMap(run => run.getReadable<unknown>({ startIndex: -1 })),
196
+ Effect.flatMap(readable =>
197
+ Effect.tryPromise({
198
+ try: () => readable.getTailIndex(),
199
+ catch: cause => workflowsError('tailIndex', cause)
200
+ })
201
+ ),
202
+ Effect.withSpan('VercelWorkflows.tailIndex', {
203
+ attributes: spanAttributes(runId)
204
+ })
205
+ ),
206
+
207
+ resumeHook: (
208
+ token: string,
209
+ payload: unknown
210
+ ): Effect.Effect<void, VercelWorkflowsError> =>
211
+ Effect.tryPromise({
212
+ try: () => sdk.resumeHook(token, payload).then(() => undefined),
213
+ catch: cause => workflowsError('resumeHook', cause)
214
+ }).pipe(Effect.withSpan('VercelWorkflows.resumeHook')),
215
+
216
+ cancel: (runId: string): Effect.Effect<void, VercelWorkflowsError> =>
217
+ getRun<unknown>(runId).pipe(
218
+ Effect.flatMap(run => run.cancel),
219
+ Effect.withSpan('VercelWorkflows.cancel', {
220
+ attributes: spanAttributes(runId)
221
+ })
222
+ )
223
+ }
224
+ })
225
+ }
226
+ ) {
227
+ static layer = Layer.effect(this, this.make).pipe(Layer.provide(VercelWorkflowsSdkLive))
228
+ static layerFromSdk = Layer.effect(this, this.make)
229
+ }