@diagonal-hq/workflows 0.10.0 → 0.10.2

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
@@ -91,7 +91,7 @@ The QuickJS build has no `Intl` and no locale data. `toLocaleDateString`, `toLoc
91
91
 
92
92
  ## Build the package
93
93
 
94
- `npm run build:workflows-package` (`scripts/build-workflows-package.mjs`) writes `dist/` and packs `scripts/dist/npm/diagonal-hq-workflows-<version>.tgz`. esbuild writes one ESM file for each entry point, and the entry points share chunks, so the root entry and `/testing` use one transport slot. TypeScript writes the declarations next to them. `npm run generate-typescript` runs the script.
94
+ `npm run build:workflows-package` (`scripts/build-workflows-package.mjs`) writes `dist/` and packs `scripts/dist/npm/diagonal-hq-workflows-<version>.tgz`. esbuild writes one ESM file for each entry point, and the entry points share chunks, so the root entry and `/testing` use one transport slot. TypeScript writes the declarations next to them. `npm run generate-typescript` runs the script with `--declarations-only`. That mode writes only the declarations, which the Files editor and the draft editors bundle. It does not write the ESM files or the tarball. `npm run build:npm-packages` builds and packs all the packages.
95
95
 
96
96
  `node scripts/smoke-workflows-package.mjs [tarball]` installs the packed tarball in a consumer outside the repository. It checks the packed file list and the manifest, imports each entry point in Node, runs a workflow through `/testing`, and runs `tsc` against the packed declarations. The `generated-assets` job of PR CI runs it.
97
97
 
@@ -97,7 +97,7 @@ function isFailure(value2) {
97
97
  }
98
98
 
99
99
  // packages/workflows/src/generated/capabilities.ts
100
- var SDK_VERSION = 76;
100
+ var SDK_VERSION = 77;
101
101
  var ai = {
102
102
  /** Ask a decisions model typed questions about some content and get labelled answers with their probabilities */
103
103
  decide: (input) => invoke("ai.decide", input),
@@ -1,7 +1,7 @@
1
1
  import type { ResourceKeyWith } from "../data.js";
2
2
  import type { ContentDocument } from "../input.js";
3
3
  import type { DeepReadonly, Liquid, StaticLiquid } from "../liquid.js";
4
- export declare const SDK_VERSION = 76;
4
+ export declare const SDK_VERSION = 77;
5
5
  export interface WorkspaceSystemFields {
6
6
  "ai_custom_system_prompt": string | null;
7
7
  "brand_kit": {
package/dist/index.js CHANGED
@@ -37,7 +37,7 @@ import {
37
37
  web,
38
38
  workflow,
39
39
  workspace
40
- } from "./chunks/chunk-B2ACQBED.js";
40
+ } from "./chunks/chunk-GDVUCCNR.js";
41
41
  import {
42
42
  InputField,
43
43
  InputSchema,
@@ -35,7 +35,7 @@ import {
35
35
  web,
36
36
  workflow,
37
37
  workspace
38
- } from "../chunks/chunk-B2ACQBED.js";
38
+ } from "../chunks/chunk-GDVUCCNR.js";
39
39
  import {
40
40
  InputField,
41
41
  InputSchema,
@@ -1,7 +1,7 @@
1
1
  /**
2
- * The options of `defineWorkflow(config, handler)` other than `input` and `validate`. The build
3
- * reads them as static data, checks them, and removes them from the compiled script, so the
4
- * compiler sees only `input` and `validate`. `@diagonal-hq/cli` replaces this declaration with its
5
- * `WorkflowConfig`, so the editor checks each option.
2
+ * The options of `defineWorkflow(config, handler)` other than `input`, `output`, and `validate`.
3
+ * The build reads them as static data, checks them, and removes them from the compiled script, so
4
+ * the compiler sees only `input`, `output`, and `validate`. `@diagonal-hq/cli` replaces this
5
+ * declaration with its `WorkflowConfig`, so the editor checks each option.
6
6
  */
7
7
  export type WorkflowConfig = Record<never, never>;
@@ -1,6 +1,6 @@
1
1
  import type { ResourceKeyWith } from "./data.js";
2
2
  import type { ScriptHostContext } from "./index.js";
3
- import { InputSchema, type InferInput, type InputFieldSpec, type InputShape } from "./input.js";
3
+ import { type Infer, type InputField, InputSchema, type InferInput, type InputFieldSpec, type InputShape } from "./input.js";
4
4
  import type { WorkflowConfig } from "./workflow-config.js";
5
5
  export interface Identity {
6
6
  id: string;
@@ -90,23 +90,40 @@ export type InputValidator<I> = (input: I, ctx: WorkflowContext) => InputErrors<
90
90
  /** Runs a script's input validator and ends the run with a validation error when it reports one. */
91
91
  export declare function validateWorkflowInput<I>(validator: InputValidator<I>, input: I, ctx: WorkflowContext): Promise<void>;
92
92
  type Handler<I, O> = (input: I, ctx: WorkflowContext) => Promise<O> | O;
93
+ /** A declared output: any `v` field, usually `v.object({ ... })`. */
94
+ type OutputField = InputField<unknown, boolean>;
95
+ /** The handler input of a config: the type of its `input` schema, or `I` without one. */
96
+ type ConfigInput<C, I> = C extends InputSchema<infer S> ? InferInput<S> : I;
97
+ /**
98
+ * A value of a declared output type that a handler may return. A const context makes a returned
99
+ * array a readonly tuple, so arrays and objects may be readonly at every level.
100
+ */
101
+ type Returnable<T> = T extends readonly (infer E)[] ? readonly Returnable<E>[] : T extends object ? {
102
+ readonly [K in keyof T]: Returnable<T[K]>;
103
+ } : T;
104
+ /** The handler result of a config: the type of its `output` schema, or `O` without one. */
105
+ type ConfigOutput<F, O> = F extends OutputField ? Infer<F> : O;
93
106
  /**
94
107
  * Declares a workflow. A file-based workflow passes its config first, as `definePage` does. The
95
108
  * build reads the config as static data. With an `input` schema in the config, or a schema first,
96
109
  * the platform validates every run's input against it before the script starts, and the handler's
97
110
  * `input` type comes from the schema. A `validate` function in the config runs after that check
98
- * and before the handler, with the same input type.
111
+ * and before the handler, with the same input type. With an `output` schema in the config of a
112
+ * file-based workflow, the handler must return a value of that type: the platform documents it as
113
+ * the response of a Request workflow and verifies each return value against it.
99
114
  */
100
- export declare function defineWorkflow<S extends InputShape, O = unknown>(config: WorkflowConfig & {
101
- readonly input: InputSchema<S>;
102
- readonly validate?: InputValidator<InferInput<S>>;
103
- }, handler: Handler<InferInput<S>, O>): WorkflowDefinition<InferInput<S>, O>;
115
+ export declare function defineWorkflow<const O, C extends InputSchema<InputShape> | undefined = undefined, I = Record<string, unknown>>(config: WorkflowConfig & {
116
+ readonly input?: C;
117
+ readonly output: InputField<O, boolean>;
118
+ readonly validate?: InputValidator<ConfigInput<C, I>>;
119
+ }, handler: Handler<ConfigInput<C, I>, Returnable<NoInfer<O>>>): WorkflowDefinition<ConfigInput<C, I>, O>;
104
120
  export declare function defineWorkflow<S extends InputShape, O = unknown>(input: InputSchema<S>, handler: Handler<InferInput<S>, O>): WorkflowDefinition<InferInput<S>, O>;
105
- export declare function defineWorkflow<I = Record<string, unknown>, O = unknown>(config: WorkflowConfig & {
106
- readonly input?: undefined;
107
- readonly validate?: InputValidator<I>;
108
- }, handler: Handler<I, O>): WorkflowDefinition<I, O>;
109
121
  export declare function defineWorkflow<I = Record<string, unknown>, O = unknown>(handler: Handler<I, O>): WorkflowDefinition<I, O>;
122
+ export declare function defineWorkflow<I = Record<string, unknown>, O = unknown, C extends InputSchema<InputShape> | undefined = undefined, F extends OutputField | undefined = undefined>(config: WorkflowConfig & {
123
+ readonly input?: C;
124
+ readonly output?: F;
125
+ readonly validate?: InputValidator<ConfigInput<C, I>>;
126
+ }, handler: Handler<ConfigInput<C, I>, ConfigOutput<F, O>>): WorkflowDefinition<ConfigInput<C, I>, ConfigOutput<F, O>>;
110
127
  export type ResponseOutput = {
111
128
  $response_status: number;
112
129
  $response_body: unknown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagonal-hq/workflows",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "description": "The authoring API of Diagonal managed workflows, their capabilities, and the workflow test helpers.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {