@diagonal-hq/cli 0.33.8 → 0.33.9

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/dist/index.d.ts CHANGED
@@ -1053,7 +1053,7 @@ type ConfigBase = UidOption & SlugOption & WorkflowLabel & { description?: strin
1053
1053
  /**
1054
1054
  * The config of a `workflows/<name>.ts` or migration file: the first argument of
1055
1055
  * `export default defineWorkflow(config, handler)` from `@diagonal/workflow`, which adds the
1056
- * `input` schema and the `validate` function. The build reads every other option as static
1056
+ * `input` and `output` schemas and the `validate` function. The build reads every other option as static
1057
1057
  * data and never runs it. `diagonal check` writes a missing `uid`. A background trigger
1058
1058
  * (recordEvent, recordSchedule, scheduled, workflowEvent) needs `runAs`. A request workflow runs
1059
1059
  * as the caller (`'session'`) by default.
@@ -1,7 +1,7 @@
1
1
  import type { ResourceKeyWith } from '../data';
2
2
  import type { ContentDocument } from '../input';
3
3
  import type { DeepReadonly, Liquid, StaticLiquid } from '../liquid';
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": {
@@ -1,6 +1,6 @@
1
1
  import type { ResourceKeyWith } from './data';
2
2
  import type { ScriptHostContext } from './index';
3
- import { InputSchema, type InferInput, type InputFieldSpec, type InputShape } from './input';
3
+ import { type Infer, type InputField, InputSchema, type InferInput, type InputFieldSpec, type InputShape } from './input';
4
4
  import type { WorkflowConfig } from './workflow-config';
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/cli",
3
- "version": "0.33.8",
3
+ "version": "0.33.9",
4
4
  "description": "The diagonal CLI and the configuration helpers for file-based Diagonal workspaces.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {
@@ -48,8 +48,8 @@
48
48
  "bun": "1.4.4"
49
49
  },
50
50
  "optionalDependencies": {
51
- "@diagonal-hq/workflow-script-compiler-darwin-arm64": "0.1.0-hd5d396115b1e",
52
- "@diagonal-hq/workflow-script-compiler-linux-x64": "0.1.0-hd5d396115b1e",
53
- "@diagonal-hq/workflow-script-compiler-linux-arm64": "0.1.0-hd5d396115b1e"
51
+ "@diagonal-hq/workflow-script-compiler-darwin-arm64": "0.1.0-h0ff9e054aa50",
52
+ "@diagonal-hq/workflow-script-compiler-linux-x64": "0.1.0-h0ff9e054aa50",
53
+ "@diagonal-hq/workflow-script-compiler-linux-arm64": "0.1.0-h0ff9e054aa50"
54
54
  }
55
55
  }