@workflow/core 4.0.1-beta.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.
Files changed (143) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +3 -0
  3. package/dist/builtins.d.ts +4 -0
  4. package/dist/builtins.d.ts.map +1 -0
  5. package/dist/builtins.js +13 -0
  6. package/dist/builtins.js.map +1 -0
  7. package/dist/create-hook.d.ts +123 -0
  8. package/dist/create-hook.d.ts.map +1 -0
  9. package/dist/create-hook.js +32 -0
  10. package/dist/create-hook.js.map +1 -0
  11. package/dist/define-hook.d.ts +53 -0
  12. package/dist/define-hook.d.ts.map +1 -0
  13. package/dist/define-hook.js +59 -0
  14. package/dist/define-hook.js.map +1 -0
  15. package/dist/events-consumer.d.ts +35 -0
  16. package/dist/events-consumer.d.ts.map +1 -0
  17. package/dist/events-consumer.js +72 -0
  18. package/dist/events-consumer.js.map +1 -0
  19. package/dist/global.d.ts +29 -0
  20. package/dist/global.d.ts.map +1 -0
  21. package/dist/global.js +50 -0
  22. package/dist/global.js.map +1 -0
  23. package/dist/index.d.ts +18 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +18 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/logger.d.ts +31 -0
  28. package/dist/logger.d.ts.map +1 -0
  29. package/dist/logger.js +32 -0
  30. package/dist/logger.js.map +1 -0
  31. package/dist/observability.d.ts +24 -0
  32. package/dist/observability.d.ts.map +1 -0
  33. package/dist/observability.js +126 -0
  34. package/dist/observability.js.map +1 -0
  35. package/dist/parse-name.d.ts +25 -0
  36. package/dist/parse-name.d.ts.map +1 -0
  37. package/dist/parse-name.js +40 -0
  38. package/dist/parse-name.js.map +1 -0
  39. package/dist/private.d.ts +26 -0
  40. package/dist/private.d.ts.map +1 -0
  41. package/dist/private.js +17 -0
  42. package/dist/private.js.map +1 -0
  43. package/dist/runtime/resume-hook.d.ts +71 -0
  44. package/dist/runtime/resume-hook.d.ts.map +1 -0
  45. package/dist/runtime/resume-hook.js +180 -0
  46. package/dist/runtime/resume-hook.js.map +1 -0
  47. package/dist/runtime/start.d.ts +28 -0
  48. package/dist/runtime/start.d.ts.map +1 -0
  49. package/dist/runtime/start.js +57 -0
  50. package/dist/runtime/start.js.map +1 -0
  51. package/dist/runtime/world.d.ts +24 -0
  52. package/dist/runtime/world.d.ts.map +1 -0
  53. package/dist/runtime/world.js +84 -0
  54. package/dist/runtime/world.js.map +1 -0
  55. package/dist/runtime.d.ts +121 -0
  56. package/dist/runtime.d.ts.map +1 -0
  57. package/dist/runtime.js +554 -0
  58. package/dist/runtime.js.map +1 -0
  59. package/dist/schemas.d.ts +29 -0
  60. package/dist/schemas.d.ts.map +1 -0
  61. package/dist/schemas.js +15 -0
  62. package/dist/schemas.js.map +1 -0
  63. package/dist/serialization.d.ts +188 -0
  64. package/dist/serialization.d.ts.map +1 -0
  65. package/dist/serialization.js +725 -0
  66. package/dist/serialization.js.map +1 -0
  67. package/dist/step/context-storage.d.ts +8 -0
  68. package/dist/step/context-storage.d.ts.map +1 -0
  69. package/dist/step/context-storage.js +3 -0
  70. package/dist/step/context-storage.js.map +1 -0
  71. package/dist/step/get-step-metadata.d.ts +38 -0
  72. package/dist/step/get-step-metadata.d.ts.map +1 -0
  73. package/dist/step/get-step-metadata.js +14 -0
  74. package/dist/step/get-step-metadata.js.map +1 -0
  75. package/dist/step/get-workflow-metadata.d.ts +7 -0
  76. package/dist/step/get-workflow-metadata.d.ts.map +1 -0
  77. package/dist/step/get-workflow-metadata.js +12 -0
  78. package/dist/step/get-workflow-metadata.js.map +1 -0
  79. package/dist/step.d.ts +4 -0
  80. package/dist/step.d.ts.map +1 -0
  81. package/dist/step.js +92 -0
  82. package/dist/step.js.map +1 -0
  83. package/dist/symbols.d.ts +9 -0
  84. package/dist/symbols.d.ts.map +1 -0
  85. package/dist/symbols.js +9 -0
  86. package/dist/symbols.js.map +1 -0
  87. package/dist/telemetry/semantic-conventions.d.ts +175 -0
  88. package/dist/telemetry/semantic-conventions.d.ts.map +1 -0
  89. package/dist/telemetry/semantic-conventions.js +121 -0
  90. package/dist/telemetry/semantic-conventions.js.map +1 -0
  91. package/dist/telemetry.d.ts +24 -0
  92. package/dist/telemetry.d.ts.map +1 -0
  93. package/dist/telemetry.js +121 -0
  94. package/dist/telemetry.js.map +1 -0
  95. package/dist/types.d.ts +10 -0
  96. package/dist/types.d.ts.map +1 -0
  97. package/dist/types.js +39 -0
  98. package/dist/types.js.map +1 -0
  99. package/dist/util.d.ts +43 -0
  100. package/dist/util.d.ts.map +1 -0
  101. package/dist/util.js +76 -0
  102. package/dist/util.js.map +1 -0
  103. package/dist/vm/index.d.ts +17 -0
  104. package/dist/vm/index.d.ts.map +1 -0
  105. package/dist/vm/index.js +93 -0
  106. package/dist/vm/index.js.map +1 -0
  107. package/dist/vm/uuid.d.ts +10 -0
  108. package/dist/vm/uuid.d.ts.map +1 -0
  109. package/dist/vm/uuid.js +30 -0
  110. package/dist/vm/uuid.js.map +1 -0
  111. package/dist/workflow/create-hook.d.ts +7 -0
  112. package/dist/workflow/create-hook.d.ts.map +1 -0
  113. package/dist/workflow/create-hook.js +22 -0
  114. package/dist/workflow/create-hook.js.map +1 -0
  115. package/dist/workflow/define-hook.d.ts +10 -0
  116. package/dist/workflow/define-hook.d.ts.map +1 -0
  117. package/dist/workflow/define-hook.js +15 -0
  118. package/dist/workflow/define-hook.js.map +1 -0
  119. package/dist/workflow/get-workflow-metadata.d.ts +17 -0
  120. package/dist/workflow/get-workflow-metadata.d.ts.map +1 -0
  121. package/dist/workflow/get-workflow-metadata.js +11 -0
  122. package/dist/workflow/get-workflow-metadata.js.map +1 -0
  123. package/dist/workflow/hook.d.ts +4 -0
  124. package/dist/workflow/hook.d.ts.map +1 -0
  125. package/dist/workflow/hook.js +101 -0
  126. package/dist/workflow/hook.js.map +1 -0
  127. package/dist/workflow/index.d.ts +10 -0
  128. package/dist/workflow/index.d.ts.map +1 -0
  129. package/dist/workflow/index.js +14 -0
  130. package/dist/workflow/index.js.map +1 -0
  131. package/dist/workflow/writable-stream.d.ts +3 -0
  132. package/dist/workflow/writable-stream.d.ts.map +1 -0
  133. package/dist/workflow/writable-stream.js +12 -0
  134. package/dist/workflow/writable-stream.js.map +1 -0
  135. package/dist/workflow.d.ts +3 -0
  136. package/dist/workflow.d.ts.map +1 -0
  137. package/dist/workflow.js +454 -0
  138. package/dist/workflow.js.map +1 -0
  139. package/dist/writable-stream.d.ts +22 -0
  140. package/dist/writable-stream.d.ts.map +1 -0
  141. package/dist/writable-stream.js +16 -0
  142. package/dist/writable-stream.js.map +1 -0
  143. package/package.json +73 -0
@@ -0,0 +1,57 @@
1
+ import { waitUntil } from '@vercel/functions';
2
+ import { WorkflowRuntimeError } from '@workflow/errors';
3
+ import { Run } from '../runtime.js';
4
+ import { dehydrateWorkflowArguments } from '../serialization.js';
5
+ import * as Attribute from '../telemetry/semantic-conventions.js';
6
+ import { serializeTraceCarrier, trace } from '../telemetry.js';
7
+ import { getWorld } from './world.js';
8
+ export async function start(workflow, argsOrOptions, options) {
9
+ // @ts-expect-error this field is added by our client transform
10
+ const workflowName = workflow.workflowId;
11
+ if (!workflowName) {
12
+ throw new WorkflowRuntimeError(`'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.`, { slug: 'start-invalid-workflow-function' });
13
+ }
14
+ return trace(`WORKFLOW.start ${workflowName}`, async (span) => {
15
+ span?.setAttributes({
16
+ ...Attribute.WorkflowName(workflowName),
17
+ ...Attribute.WorkflowOperation('start'),
18
+ });
19
+ let args = [];
20
+ let opts = options ?? {};
21
+ if (Array.isArray(argsOrOptions)) {
22
+ args = argsOrOptions;
23
+ }
24
+ else if (typeof argsOrOptions === 'object') {
25
+ opts = argsOrOptions;
26
+ }
27
+ span?.setAttributes({
28
+ ...Attribute.WorkflowArgumentsCount(args.length),
29
+ });
30
+ const world = getWorld();
31
+ const deploymentId = opts.deploymentId ?? (await world.getDeploymentId());
32
+ const ops = [];
33
+ const workflowArguments = dehydrateWorkflowArguments(args, ops);
34
+ // Serialize current trace context to propagate across queue boundary
35
+ const traceCarrier = await serializeTraceCarrier();
36
+ const runResponse = await world.runs.create({
37
+ deploymentId: deploymentId,
38
+ workflowName: workflowName,
39
+ input: workflowArguments,
40
+ executionContext: { traceCarrier },
41
+ });
42
+ waitUntil(Promise.all(ops));
43
+ span?.setAttributes({
44
+ ...Attribute.WorkflowRunId(runResponse.runId),
45
+ ...Attribute.WorkflowRunStatus(runResponse.status),
46
+ ...Attribute.DeploymentId(deploymentId),
47
+ });
48
+ await world.queue(`__wkf_workflow_${workflowName}`, {
49
+ runId: runResponse.runId,
50
+ traceCarrier,
51
+ }, {
52
+ deploymentId,
53
+ });
54
+ return new Run(runResponse.runId);
55
+ });
56
+ }
57
+ //# sourceMappingURL=start.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/runtime/start.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,SAAS,MAAM,sCAAsC,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAwCtC,MAAM,CAAC,KAAK,UAAU,KAAK,CACzB,QAA6D,EAC7D,aAAoC,EACpC,OAAsB;IAEtB,+DAA+D;IAC/D,MAAM,YAAY,GAAG,QAAQ,CAAC,UAAU,CAAC;IAEzC,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,oBAAoB,CAC5B,kKAAkK,EAClK,EAAE,IAAI,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AC,CAAC,CAAC;QAE5B,IAAI,EAAE,aAAa,CAAC;YAClB,GAAG,SAAS,CAAC,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC;YAC7C,GAAG,SAAS,CAAC,iBAAiB,CAAC,WAAW,CAAC,MAAM,CAAC;YAClD,GAAG,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC;SACxC,CAAC,CAAC;QAEH,MAAM,KAAK,CAAC,KAAK,CACf,kBAAkB,YAAY,EAAE,EAChC;YACE,KAAK,EAAE,WAAW,CAAC,KAAK;YACxB,YAAY;SACmB,EACjC;YACE,YAAY;SACb,CACF,CAAC;QAEF,OAAO,IAAI,GAAG,CAAU,WAAW,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { World } from '@workflow/world';
2
+ /**
3
+ * Create a new world instance based on environment variables.
4
+ * WORKFLOW_TARGET_WORLD is used to determine the target world.
5
+ * All other environment variables are specific to the target world
6
+ */
7
+ export declare const createWorld: () => World;
8
+ /**
9
+ * Some functions from the world are needed at build time, but we do NOT want
10
+ * to cache the world in those instances for general use, since we don't have
11
+ * the correct environment variables set yet. This is a safe function to
12
+ * call at build time, that only gives access to non-environment-bound world
13
+ * functions. The only binding value should be the target world.
14
+ * Once we migrate to a file-based configuration (workflow.config.ts), we should
15
+ * be able to re-combine getWorld and getWorldHandlers into one singleton.
16
+ */
17
+ export declare const getWorldHandlers: () => Pick<World, "createQueueHandler">;
18
+ export declare const getWorld: () => World;
19
+ /**
20
+ * Reset the cached world instance. This should be called when environment
21
+ * variables change and you need to reinitialize the world with new config.
22
+ */
23
+ export declare const setWorld: (world: World | undefined) => void;
24
+ //# sourceMappingURL=world.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"world.d.ts","sourceRoot":"","sources":["../../src/runtime/world.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAiB7C;;;;GAIG;AACH,eAAO,MAAM,WAAW,QAAO,KAkC9B,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,QAAO,IAAI,CAAC,KAAK,EAAE,oBAAoB,CASnE,CAAC;AAEF,eAAO,MAAM,QAAQ,QAAO,KAM3B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,KAAK,GAAG,SAAS,KAAG,IAGnD,CAAC"}
@@ -0,0 +1,84 @@
1
+ import { createRequire } from 'node:module';
2
+ import Path from 'node:path';
3
+ import { createEmbeddedWorld } from '@workflow/world-local';
4
+ import { createVercelWorld } from '@workflow/world-vercel';
5
+ const require = createRequire(Path.join(process.cwd(), 'index.js'));
6
+ let worldCache;
7
+ let stubbedWorldCache;
8
+ function defaultWorld() {
9
+ if (process.env.VERCEL_DEPLOYMENT_ID) {
10
+ return 'vercel';
11
+ }
12
+ return 'embedded';
13
+ }
14
+ /**
15
+ * Create a new world instance based on environment variables.
16
+ * WORKFLOW_TARGET_WORLD is used to determine the target world.
17
+ * All other environment variables are specific to the target world
18
+ */
19
+ export const createWorld = () => {
20
+ const targetWorld = process.env.WORKFLOW_TARGET_WORLD || defaultWorld();
21
+ if (targetWorld === 'vercel') {
22
+ return createVercelWorld({
23
+ baseUrl: process.env.WORKFLOW_VERCEL_PROXY_URL,
24
+ token: process.env.WORKFLOW_VERCEL_AUTH_TOKEN,
25
+ projectConfig: {
26
+ environment: process.env.WORKFLOW_VERCEL_ENV,
27
+ projectId: process.env.WORKFLOW_VERCEL_PROJECT,
28
+ teamId: process.env.WORKFLOW_VERCEL_TEAM,
29
+ },
30
+ });
31
+ }
32
+ if (targetWorld === 'embedded') {
33
+ return createEmbeddedWorld({
34
+ dataDir: process.env.WORKFLOW_EMBEDDED_DATA_DIR,
35
+ port: process.env.PORT ? Number(process.env.PORT) : undefined,
36
+ });
37
+ }
38
+ const mod = require(targetWorld);
39
+ if (typeof mod === 'function') {
40
+ return mod();
41
+ }
42
+ else if (typeof mod.default === 'function') {
43
+ return mod.default();
44
+ }
45
+ else if (typeof mod.createWorld === 'function') {
46
+ return mod.createWorld();
47
+ }
48
+ throw new Error(`Invalid target world module: ${targetWorld}, must export a default function or createWorld function that returns a World instance.`);
49
+ };
50
+ /**
51
+ * Some functions from the world are needed at build time, but we do NOT want
52
+ * to cache the world in those instances for general use, since we don't have
53
+ * the correct environment variables set yet. This is a safe function to
54
+ * call at build time, that only gives access to non-environment-bound world
55
+ * functions. The only binding value should be the target world.
56
+ * Once we migrate to a file-based configuration (workflow.config.ts), we should
57
+ * be able to re-combine getWorld and getWorldHandlers into one singleton.
58
+ */
59
+ export const getWorldHandlers = () => {
60
+ if (stubbedWorldCache) {
61
+ return stubbedWorldCache;
62
+ }
63
+ const _world = createWorld();
64
+ stubbedWorldCache = _world;
65
+ return {
66
+ createQueueHandler: _world.createQueueHandler,
67
+ };
68
+ };
69
+ export const getWorld = () => {
70
+ if (worldCache) {
71
+ return worldCache;
72
+ }
73
+ worldCache = createWorld();
74
+ return worldCache;
75
+ };
76
+ /**
77
+ * Reset the cached world instance. This should be called when environment
78
+ * variables change and you need to reinitialize the world with new config.
79
+ */
80
+ export const setWorld = (world) => {
81
+ worldCache = world;
82
+ stubbedWorldCache = world;
83
+ };
84
+ //# sourceMappingURL=world.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"world.js","sourceRoot":"","sources":["../../src/runtime/world.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC;AAEpE,IAAI,UAA6B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AAW,CAAC;IAChC,CAAC;SAAM,IAAI,OAAO,GAAG,CAAC,WAAW,KAAK,UAAU,EAAE,CAAC;QACjD,OAAO,GAAG,CAAC,WAAW,EAAW,CAAC;IACpC,CAAC;IAED,MAAM,IAAI,KAAK,CACb,gCAAgC,WAAW,yFAAyF,CACrI,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAsC,EAAE;IACtE,IAAI,iBAAiB,EAAE,CAAC;QACtB,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IACD,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,iBAAiB,GAAG,MAAM,CAAC;IAC3B,OAAO;QACL,kBAAkB,EAAE,MAAM,CAAC,kBAAkB;KAC9C,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAU,EAAE;IAClC,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,UAAU,GAAG,WAAW,EAAE,CAAC;IAC3B,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAwB,EAAQ,EAAE;IACzD,UAAU,GAAG,KAAK,CAAC;IACnB,iBAAiB,GAAG,KAAK,CAAC;AAC5B,CAAC,CAAC"}
@@ -0,0 +1,121 @@
1
+ import type { Event, WorkflowRun, WorkflowRunStatus } from '@workflow/world';
2
+ export type { Event, WorkflowRun };
3
+ export { WorkflowSuspension } from './global.js';
4
+ export { getHookByToken, resumeHook, resumeWebhook, } from './runtime/resume-hook.js';
5
+ export { type StartOptions, start } from './runtime/start.js';
6
+ export { createWorld, getWorld, getWorldHandlers, setWorld, } from './runtime/world.js';
7
+ /**
8
+ * Options for configuring a workflow's readable stream.
9
+ */
10
+ export interface WorkflowReadableStreamOptions {
11
+ /**
12
+ * An optional namespace to distinguish between multiple streams associated
13
+ * with the same workflow run.
14
+ */
15
+ namespace?: string;
16
+ /**
17
+ * The index number of the starting chunk to begin reading the stream from.
18
+ */
19
+ startIndex?: number;
20
+ /**
21
+ * Any asynchronous operations that need to be performed before the execution
22
+ * environment is paused / terminated
23
+ * (i.e. using [`waitUntil()`](https://developer.mozilla.org/docs/Web/API/ExtendableEvent/waitUntil) or similar).
24
+ */
25
+ ops?: Promise<any>[];
26
+ /**
27
+ * The global object to use for hydrating types from the global scope.
28
+ *
29
+ * Defaults to {@link [`globalThis`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/globalThis)}.
30
+ */
31
+ global?: Record<string, any>;
32
+ }
33
+ /**
34
+ * A handler class for a workflow run.
35
+ */
36
+ export declare class Run<TResult> {
37
+ /**
38
+ * The ID of the workflow run.
39
+ */
40
+ runId: string;
41
+ /**
42
+ * The world object.
43
+ * @internal
44
+ */
45
+ private world;
46
+ constructor(runId: string);
47
+ /**
48
+ * Cancels the workflow run.
49
+ */
50
+ cancel(): Promise<void>;
51
+ /**
52
+ * The status of the workflow run.
53
+ */
54
+ get status(): Promise<WorkflowRunStatus>;
55
+ /**
56
+ * The return value of the workflow run.
57
+ * Polls the workflow return value until it is completed.
58
+ */
59
+ get returnValue(): Promise<TResult>;
60
+ /**
61
+ * The name of the workflow.
62
+ */
63
+ get workflowName(): Promise<string>;
64
+ /**
65
+ * The timestamp when the workflow run was created.
66
+ */
67
+ get createdAt(): Promise<Date>;
68
+ /**
69
+ * The timestamp when the workflow run started execution.
70
+ * Returns undefined if the workflow has not started yet.
71
+ */
72
+ get startedAt(): Promise<Date | undefined>;
73
+ /**
74
+ * The timestamp when the workflow run completed.
75
+ * Returns undefined if the workflow has not completed yet.
76
+ */
77
+ get completedAt(): Promise<Date | undefined>;
78
+ /**
79
+ * The readable stream of the workflow run.
80
+ */
81
+ get readable(): ReadableStream;
82
+ /**
83
+ * Retrieves the workflow run's default readable stream, which reads chunks
84
+ * written to the corresponding writable stream {@link getWritable}.
85
+ *
86
+ * @param options - The options for the readable stream.
87
+ * @returns The `ReadableStream` for the workflow run.
88
+ */
89
+ getReadable<R = any>(options?: WorkflowReadableStreamOptions): ReadableStream<R>;
90
+ /**
91
+ * Polls the workflow return value every 1 second until it is completed.
92
+ * @internal
93
+ * @returns The workflow return value.
94
+ */
95
+ private pollReturnValue;
96
+ }
97
+ /**
98
+ * Retrieves a `Run` object for a given run ID.
99
+ *
100
+ * @param runId - The workflow run ID obtained from {@link start}.
101
+ * @returns A `Run` object.
102
+ * @throws WorkflowRunNotFoundError if the run ID is not found.
103
+ */
104
+ export declare function getRun<TResult>(runId: string): Run<TResult>;
105
+ /**
106
+ * Function that creates a single route which handles any workflow execution
107
+ * request and routes to the appropriate workflow function.
108
+ *
109
+ * @param workflowCode - The workflow bundle code containing all the workflow
110
+ * functions at the top level.
111
+ * @returns A function that can be used as a Vercel API route.
112
+ */
113
+ export declare function workflowEntrypoint(workflowCode: string): (req: Request) => Promise<Response>;
114
+ /**
115
+ * A single route that handles any step execution request and routes to the
116
+ * appropriate step function. We may eventually want to create different bundles
117
+ * for each step, this is temporary.
118
+ */
119
+ export declare const stepEntrypoint: (req: Request) => Promise<Response>;
120
+ export declare function runStep(): void;
121
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,KAAK,EACL,WAAW,EACX,iBAAiB,EAElB,MAAM,iBAAiB,CAAC;AA8BzB,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EACL,cAAc,EACd,UAAU,EACV,aAAa,GACd,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EACL,WAAW,EACX,QAAQ,EACR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