sim 2.3.0-preview.332.1 → 2.3.1-preview.334.1
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/generated/v2-api.d.ts +1 -0
- package/dist/index.js +35 -24
- package/dist/runtime.js +35 -24
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -35184,7 +35184,9 @@ Block settings, beside inputs in an add's or edit's params:
|
|
|
35184
35184
|
5xx, not when the host does not resolve or refuses the connection; "retry" covers that.
|
|
35185
35185
|
Outputs:
|
|
35186
35186
|
A block that fails outputs {"error":"<message>"}: connect its error handle and read
|
|
35187
|
-
<name.error> there (without one, the run fails). A
|
|
35187
|
+
<name.error> there (without one, the run fails). A Function's error leads with the line and
|
|
35188
|
+
code that threw; its <name.errorMessage> is the thrown message alone, the one to reply with.
|
|
35189
|
+
A Workflow block's result is the child's
|
|
35188
35190
|
output; a child ending in a Response block gives {data, status, headers}, so read
|
|
35189
35191
|
<call.result.data.x>.`;
|
|
35190
35192
|
var BLOCK_DETAIL_GUIDE = `
|
|
@@ -35195,7 +35197,8 @@ Reading it for \`sim workflows operations apply\`:
|
|
|
35195
35197
|
inputDefinitions the block's inputs by name; one a pair of fields shares (tableId for
|
|
35196
35198
|
tableSelector and manualTableId) is accepted in place of the pair
|
|
35197
35199
|
outputs what it outputs on success; a failed block outputs {"error":"…"}
|
|
35198
|
-
instead, read on its error path as <name.error>
|
|
35200
|
+
instead, read on its error path as <name.error> (a Function also
|
|
35201
|
+
outputs <name.errorMessage>, the thrown message without line or code)
|
|
35199
35202
|
Block settings such as retry are not fields: \`sim workflows operations apply --help\`.`;
|
|
35200
35203
|
var WORKFLOW_SET_BLOCK_ENABLED_HELP = 'Blocks to enable or disable, applied after --operations: [{"block_id":"<uuid>","enabled":false}]. Disabling a loop or parallel cascades to its unlocked descendants; enabling a block whose container is disabled is declined';
|
|
35201
35204
|
var WORKFLOW_VARIABLE_OPERATIONS_HELP = 'Variable changes to apply in order, keyed by operation: [{"operation":"add","name":"my_var","type":"string","value":"hello"},{"operation":"edit","name":"my_var","value":"updated"},{"operation":"delete","name":"my_var"}]';
|
|
@@ -40823,6 +40826,9 @@ export default workflow('Cookbook', { description: 'One example of each common b
|
|
|
40823
40826
|
dataMode: 'json',
|
|
40824
40827
|
data: { status: 'rejected' },
|
|
40825
40828
|
})
|
|
40829
|
+
// Error path: shape.onError(invalid) runs invalid when the code throws. shape.error leads with
|
|
40830
|
+
// the line and code that threw; shape.errorMessage is the thrown message alone, for the caller.
|
|
40831
|
+
const invalid = response('Respond Invalid', { body: { error: shape.errorMessage }, status: 422 })
|
|
40826
40832
|
|
|
40827
40833
|
// Wiring: a.to(b) chains; a block can fan out to several targets.
|
|
40828
40834
|
start.to(check)
|
|
@@ -40837,6 +40843,7 @@ export default workflow('Cookbook', { description: 'One example of each common b
|
|
|
40837
40843
|
docs.to(shape)
|
|
40838
40844
|
route.else.to(shape)
|
|
40839
40845
|
shape.to(reply)
|
|
40846
|
+
shape.onError(invalid)
|
|
40840
40847
|
nightly.to(recent)
|
|
40841
40848
|
recent.to(each)
|
|
40842
40849
|
each.to(report)
|
|
@@ -40933,7 +40940,7 @@ export default workflow(
|
|
|
40933
40940
|
)
|
|
40934
40941
|
` };
|
|
40935
40942
|
// ../workflow-sdk/src/codegen/core-text.generated.ts
|
|
40936
|
-
var CORE_DTS = "/**\n * The authoring surface for Sim workflows written as TypeScript.\n *\n * Nothing declared here runs. `@sim/workflow-code` compiles a workflow file statically, and every\n * runtime export of this package throws `SimSdkNotExecutable`. These declarations exist so an\n * editor, `tsc` (the type-check command `sim` prints) or an agent can check a workflow file before\n * the compiler sees it.\n *\n * Block builders (`slack.sendMessage`, `agent`, `trigger.gmail.poller`, ...) are not declared here:\n * they are generated from the block catalog into `blocks/{type}.d.ts`, which augment this module.\n * The generic `block(type, name, params)` covers any stored type without a builder.\n *\n * Every workflow file starts with the SDK header line, before any import:\n *\n * ```ts\n * // @sim-sdk 1\n * import { agent, trigger, workflow } from '@sim/workflow-sdk'\n * ```\n *\n * The number is the SDK major version the file is written against. A file without the header is\n * refused with `E_SDK_HEADER`, and one written for a newer major than the server supports with\n * `E_SDK_MAJOR`.\n */\n\n/** Plain JSON. */\nexport type Json = null | boolean | number | string | Json[] | { [key: string]: Json }\n\ndeclare const REF: unique symbol\ndeclare const TEMPLATE: unique symbol\ndeclare const ENV: unique symbol\ndeclare const RESOURCE: unique symbol\ndeclare const TOOL: unique symbol\ndeclare const NODE: unique symbol\ndeclare const CODE_FILE: unique symbol\ndeclare const RAW: unique symbol\ndeclare const UNTYPED: unique symbol\n\n/** Any reference, whatever it points at. */\nexport interface AnyRef {\n readonly [REF]: unknown\n}\n\n/** Marks a reference into untyped JSON, which any param accepts: its value is known only at run time. */\ninterface Untyped {\n readonly [UNTYPED]: true\n}\n\n/**\n * A reference into untyped JSON, where any path is allowed at any depth. An interface rather than\n * `Ref<Json>`, which TypeScript stops resolving after one step (`a.b.c` failed at `c`).\n */\ninterface UntypedRef extends Untyped {\n readonly [REF]: Json\n readonly [key: string]: UntypedRef\n}\n\ntype RefPaths<T> = [Json] extends [T]\n ? Untyped & { readonly [key: string]: UntypedRef }\n : T extends readonly (infer E)[]\n ? { readonly [index: number]: Ref<E>; readonly length: Ref<number> }\n : T extends object\n ? { readonly [K in keyof T]-?: Ref<T[K]> }\n : unknown\n\n/**\n * A typed reference to a block output, compiled to `<blockkey.path>`.\n * Paths map exactly: `.seg`, `['seg']` and `[n]`. Untyped JSON allows any path.\n */\nexport type Ref<T> = { readonly [REF]: T } & RefPaths<T>\n\n/** Text with references in it, written with one of the tags below. */\nexport type Template = string & { readonly [TEMPLATE]: true }\n\n/** A workspace environment variable, compiled to `{{NAME}}`. */\nexport interface EnvRef {\n readonly [ENV]: string\n}\n\n/**\n * What a reference must hold to fill a param of type `T`. A param taking some strings takes any\n * string (an option id computed at run time); `null` (an output a step left empty) fits anywhere.\n */\ntype RefValue<T> = [Extract<T, string>] extends [never] ? T | null : T | string | null\n\n/**\n * A reference that fits a param of type `T`: one whose value has that type, or one into untyped\n * JSON. A whole block is not a value: reference one of its outputs.\n */\nexport type RefTo<T> = ({ readonly [REF]: RefValue<T> } | (AnyRef & Untyped)) & {\n readonly [NODE]?: never\n}\n\n/** A param value: a literal, a reference of a fitting type, a template or an environment variable. */\nexport type Value<T> = T | RefTo<T> | Template | EnvRef\n\n/** JSON whose leaves may be references, templates or environment variables. */\nexport type JsonWithRefs =\n | null\n | boolean\n | number\n | string\n | AnyRef\n | Template\n | EnvRef\n | JsonWithRefs[]\n | { [key: string]: JsonWithRefs }\n\n/** A literal union that still accepts any other string (option ids read from values). */\nexport type LiteralUnion<T extends string> = T | (string & {})\n\n/** A `time-input` value, `HH:MM`. */\nexport type TimeString = `${number}:${number}`\n\n/** A reference written into text: any output or variable, but not a whole block. */\ntype InterpolatedRef = AnyRef & { readonly [NODE]?: never }\n\ntype Interpolation = InterpolatedRef | EnvRef | VarRef | string | number | boolean\n\n/** Text with interpolated references: `` t`New ${cls.category} ticket` ``. */\nexport declare function t(strings: TemplateStringsArray, ...values: Interpolation[]): Template\n/** JavaScript code (condition expressions, inline function code). */\nexport declare const js: typeof t\n/** Python code. */\nexport declare const py: typeof t\n/** Shell code. */\nexport declare const sh: typeof t\n/**\n * JSON text kept verbatim, for bodies an object literal cannot reproduce byte for byte. In a JSON\n * field an object literal is the usual form: a bare reference keeps its value's type (`n: score.value`\n * is a number), and a template is text.\n */\nexport declare const json: typeof t\n/** Markdown text (note content). */\nexport declare const md: typeof t\n\n/** A reference with a non-canonical spelling, such as `ref('Classify.content')`. */\nexport declare function ref(path: string): Ref<Json>\n\n/** A stored value outside the generated type (a legacy option id, say), kept verbatim. */\nexport declare function raw<T = never>(value: unknown): T & { readonly [RAW]: true }\n\n/** A required value that is still missing; compiles to absent, so canvas drafts type-check. */\nexport declare function todo(): never\n\n/**\n * Keeps the value the stored workflow holds for this param, without showing it: the printer writes\n * it for a secret pasted into a password field. Valid only on a param of a block the stored\n * workflow already has (same name and type) and holds a value for; anything else is\n * `E_STORED_VALUE_MISSING`.\n */\nexport declare function stored(): never\n\n/** Function code kept in a file next to the workflow (`.js`, `.py` or `.sh`), stored verbatim. */\nexport interface CodeFileRef {\n readonly [CODE_FILE]: string\n}\nexport declare function codeFile(path: `./${string}`): CodeFileRef\n\n/**\n * Environment variable names known to the workspace. `workspace.d.ts` adds one member per name;\n * until it exists `env` accepts any name.\n */\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceEnv {}\n\nexport declare const env: keyof WorkspaceEnv extends never\n ? { readonly [name: string]: EnvRef }\n : { readonly [K in keyof WorkspaceEnv]: EnvRef }\n\n/**\n * Workspace resources by stable key, filled in by the generated `workspace.d.ts`. Each map's\n * values describe the resource: a table's row type, a credential's provider, a workflow's inputs.\n */\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceTables {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceKnowledgeBases {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceCredentials {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceWorkflows {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceSkills {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceCustomTools {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceMcpServers {}\n\ntype KeyOf<M> = keyof M extends never ? string : Extract<keyof M, string>\n\nexport type TableKey = KeyOf<WorkspaceTables>\nexport type KnowledgeBaseKey = KeyOf<WorkspaceKnowledgeBases>\nexport type CredentialKey = KeyOf<WorkspaceCredentials>\nexport type WorkflowKey = KeyOf<WorkspaceWorkflows>\nexport type SkillKey = KeyOf<WorkspaceSkills>\nexport type CustomToolKey = KeyOf<WorkspaceCustomTools>\nexport type McpServerKey = KeyOf<WorkspaceMcpServers>\n/**\n * The tool names of MCP server `K`, as `workspace.d.ts` records them from the server's last\n * listing; any name for a server it could not list or does not know.\n */\nexport type McpToolName<K extends string> = K extends keyof WorkspaceMcpServers\n ? WorkspaceMcpServers[K] extends { tools: infer T extends string }\n ? T\n : string\n : string\n\n/** A workspace resource by stable key, compiled to the resource's internal id. */\nexport interface ResourceRef<Kind extends string, Key extends string = string> {\n readonly [RESOURCE]: Kind\n readonly key: Key\n}\n\n/** A saved credential: `credential('support-slack')`. */\nexport type CredentialRef<Key extends string = string> = ResourceRef<'credential', Key>\n\n/**\n * Keys of the saved credentials for one of `Providers`, as `workspace.d.ts` records each\n * credential's provider; any key until it exists.\n */\nexport type CredentialKeyFor<Providers extends string> = keyof WorkspaceCredentials extends never\n ? string\n : {\n [K in Extract<keyof WorkspaceCredentials, string>]: WorkspaceCredentials[K] extends {\n provider: Providers\n }\n ? K\n : never\n }[Extract<keyof WorkspaceCredentials, string>]\nexport declare function credential<K extends CredentialKey>(key: K): CredentialRef<K>\n\n/**\n * The other form a credential field takes beside `credential('key')`: a credential id produced at\n * run time by a reference, a template or an environment variable, stored in the field's advanced\n * twin (`manualCredential`). Literal text is not one, so a pasted token never type-checks; a\n * literal id the stored workflow already holds prints as `raw('…')`.\n */\nexport type CredentialIdValue = RefTo<string> | Template | EnvRef\n\n/** The columns of a workspace table, or loose JSON when `workspace.d.ts` does not know it. */\nexport type TableColumns<K extends string> = K extends keyof WorkspaceTables\n ? WorkspaceTables[K]\n : { [column: string]: Json }\n/**\n * One row as the table blocks output it: the row id, and its cells keyed by column name under\n * `data` (`row.data.status`). Times are ISO strings.\n */\nexport interface TableRow<K extends string> {\n id: string\n data: TableColumns<K>\n position: number\n createdAt: string\n updatedAt: string\n}\n/**\n * A value written to a field of type `T` (a table cell, a child workflow input): a JSON or JSON\n * array field takes JSON with references in it, and `null` leaves the field empty.\n */\ntype FieldValue<T> = [Json] extends [T]\n ? JsonWithRefs\n : [Json[]] extends [T]\n ? JsonWithRefs\n : Value<T> | null\n\n/** The columns of table `K` every row must hold: those whose cell type does not admit `null`. */\ntype RequiredColumns<K extends keyof WorkspaceTables> = {\n [C in keyof WorkspaceTables[K]]-?: null extends WorkspaceTables[K][C] ? never : C\n}[keyof WorkspaceTables[K]]\n\n/**\n * A whole row, as an insert, an upsert or a batch insert writes it, each value checked against\n * its column's type. A required column must be present and not `null`: the table refuses a row\n * without it (`Missing required field`), and an upsert checks the whole row before it looks for a\n * match.\n */\nexport type TableData<K extends string> = K extends keyof WorkspaceTables\n ? { [C in RequiredColumns<K>]-?: Exclude<FieldValue<WorkspaceTables[K][C]>, null> } & {\n [C in Exclude<keyof WorkspaceTables[K], RequiredColumns<K>>]?: FieldValue<\n WorkspaceTables[K][C]\n >\n }\n : { [column: string]: JsonWithRefs }\n\n/**\n * The cells an update writes, each checked against its column's type. Every column is optional:\n * an update merges these cells over the stored row.\n */\nexport type TableDataPatch<K extends string> = K extends keyof WorkspaceTables\n ? { [C in keyof WorkspaceTables[K]]?: FieldValue<WorkspaceTables[K][C]> }\n : { [column: string]: JsonWithRefs }\n\n/** A workspace table: `table('leads')`. Table block operations live on `table.*`. */\nexport type TableRef<Key extends string = string> = ResourceRef<'table', Key>\nexport declare function table<K extends TableKey>(key: K): TableRef<K>\n\n/** A knowledge base: `knowledgeBase('docs')`. */\nexport type KnowledgeBaseRef<Key extends string = string> = ResourceRef<'knowledge-base', Key>\nexport declare function knowledgeBase<K extends KnowledgeBaseKey>(key: K): KnowledgeBaseRef<K>\n\n/** A workspace skill: `skill('triage')`. */\nexport type SkillRef<Key extends string = string> = ResourceRef<'skill', Key>\nexport declare function skill<K extends SkillKey>(key: K): SkillRef<K>\n\n/** A workspace folder: `folder('reports')`. */\nexport type FolderRef = ResourceRef<'file-folder'>\nexport declare function folder(key: string): FolderRef\n\n/** A workspace file: `file('contracts/acme.pdf')`. File block operations live on `file.*`. */\nexport type FileRef = ResourceRef<'file'>\nexport declare function file(path: string): FileRef\n\n/**\n * A file a file-upload field holds, as the editor stores it: one uploaded in place, or a workspace\n * file chosen by `key` (written `file('path')` when the workspace resolves it).\n */\nexport interface UploadedFile {\n name: string\n path: string\n size?: number\n type?: string\n key?: string | FileRef\n id?: string\n folderPath?: string\n}\n\n/** A file produced at run time (`file` / `file[]` outputs). */\nexport interface SimFile {\n id: string\n name: string\n url: string\n size: number\n type: string\n key: string\n}\n\n// Agent tools\n\n/** One entry of an agent's `tools` list. */\nexport interface Tool {\n readonly [TOOL]: true\n}\n\n/** How the model may use a tool, and the stored tool fields a print carries. */\nexport interface ToolOpts {\n usageControl?: 'auto' | 'force' | 'none'\n usageControlExpression?: string\n title?: string\n /** The stored operation, when the method does not pin it. */\n operation?: string\n toolId?: string\n /** Pair modes of the tool's params, which pick the member the agent reads. */\n modes?: Record<string, 'basic' | 'advanced'>\n customTool?: JsonWithRefs\n operationPolicy?: Json\n /** Unknown stored tool keys, kept verbatim. */\n extra?: Json\n}\n\n/**\n * A workspace custom tool by key, as an agent tool: `customTool('lookup-order')`. A stored tool\n * whose definition was copied into the workflow (and may have drifted from the workspace tool)\n * prints as `raw(tool)` instead.\n */\nexport declare function customTool<K extends CustomToolKey>(key: K, options?: ToolUsage): Tool\n\n/** How the model may use a tool the SDK writes by name (`customTool`, `mcp().tool`, `asTool`). */\nexport type ToolUsage = Pick<ToolOpts, 'usageControl' | 'usageControlExpression'>\n\n/** An MCP tool's arguments and the editor's snapshot of its server. */\nexport interface McpToolOpts extends ToolUsage {\n /** Argument values the workflow fixes; the model fills in the rest. */\n args?: Record<string, JsonWithRefs>\n /**\n * What the editor saved about the server and the tool's input schema when the tool was picked.\n * Shown in the editor; never run.\n */\n snapshot?: { serverName?: string; serverUrl?: string; schema?: Json }\n}\n\n/** An MCP server by key: `mcp('linear')`. */\nexport interface McpServerRef<Key extends string = string> extends ResourceRef<'mcp-server', Key> {\n /** One of the server's tools, as an agent tool: `mcp('linear').tool('create_issue')`. */\n tool(name: McpToolName<Key>, options?: McpToolOpts): Tool\n}\nexport declare function mcp<K extends McpServerKey>(key: K): McpServerRef<K>\n\n// Graph\n\n/** Block-level fields (`BlockState`), written as the third builder argument. */\nexport interface BlockMeta {\n /**\n * A legacy key the display name cannot carry (a `name~n` collision key or a reserved name such\n * as `Loop`). Printed only for such a stored block; apply accepts it only for a key the stored\n * workflow already has, so it can never introduce one.\n */\n key?: string\n /** Stored as `enabled: false`. */\n disabled?: true\n /** Locked: apply refuses any change to this block. */\n locked?: true\n /** Exposes the error port without an `onError` edge. */\n errorPort?: boolean\n /** The block-level advanced toggle (`advancedMode`). */\n advancedMode?: boolean\n /**\n * Runs the block as its trigger (`triggerMode`). Trigger builders (`trigger.gmail.poller`) set\n * it themselves; write it on any other builder only for a block stored in trigger mode.\n */\n triggerMode?: boolean\n /** The stored retry policy, written whole. */\n retry?: BlockRetryConfig\n /**\n * Per branch key of a condition or router, the row's display `title` and any stored fields the\n * SDK has no syntax for (`extra`, plain JSON). `title: null` keeps a row stored with no title,\n * which the executor never takes for `else`.\n */\n branches?: Record<string, { title?: string | null; extra?: Record<string, Json> }>\n /**\n * Stored params that run but have no SDK syntax: a schema-agnostic custom block's inputs, the\n * agent's legacy prompt fields, a container's stored params. Values the block keeps but never\n * runs are not written; apply keeps them from the stored workflow.\n */\n extra?: Record<string, unknown>\n /**\n * A loop or parallel's `block.data` subflow keys the loader could not read as config, kept\n * verbatim (plain JSON).\n */\n subflowData?: Record<string, Json>\n}\n\n/** A block's retry policy, field for field the stored `BlockRetryConfig`. */\nexport interface BlockRetryConfig {\n /** Absent config and `false` mean the same thing: the block runs once. */\n enabled: boolean\n /** Total tries including the first. */\n maxTries: number\n /** Delay between tries. */\n waitBetweenTriesMs: number\n}\n\n/** Anything an edge can point at. */\nexport type Target = Node | Group\n\n/** A block or container in the graph. */\nexport interface Node {\n readonly [NODE]: true\n /** Wires this node's default port to each target. Returns the target, or a group of them. */\n to<const T extends Target[]>(...targets: T): T extends [infer One] ? One : Group\n /** Wires this node's error port to each target. */\n onError(...targets: Target[]): void\n}\n\n/** Several nodes; `.to()` wires every member (fan-in). */\nexport interface Group {\n to(...targets: Target[]): Group\n}\n\n/**\n * The failure message a block outputs when an error edge leaves it (`x.onError(y)` runs `y` with\n * `x.error`); a check refuses `x.error` on a block without one, which fails the run instead.\n */\ntype ErrorOutput<O> = [O] extends [{ error: unknown }] ? unknown : { readonly error: Ref<string> }\n\n/** A block: a node whose outputs can be referenced, and `error` after an `onError` edge. */\nexport type Block<O> = Node & Ref<O> & ErrorOutput<O>\n\n/** The named ports of a condition or router. */\nexport type Branches<K extends string> = { readonly [P in K]: Node }\n\n/** Trigger builders (`trigger.start`, `trigger.gmail.poller`, ...), generated from the catalog. */\nexport declare namespace trigger {}\n\n/** Builders for hidden legacy block versions (`legacy.slack.send`), generated from the catalog. */\nexport declare namespace legacy {}\n\n/** A raw edge from a handle the SDK has no name for (a legacy or unknown port). */\nexport declare function edge(from: Node, handle: string, to: Target): void\n\n/** Any stored block type without a builder (legacy, unknown or custom), with untyped outputs. */\nexport declare function block(\n type: string,\n name: string,\n params: Record<string, unknown>,\n meta?: BlockMeta\n): Block<Json>\n\n// Workflow and variables\n\nexport type VariableType = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'plain'\n\n/** A workflow variable declared in `workflow(name, { variables })`: its type and initial value. */\nexport interface VariableDeclaration {\n /**\n * The display name, written only when it differs from the key. It must normalize to the key\n * (lowercased, spaces and dots removed), as `'Total Count'` does to `totalcount`.\n */\n name?: string\n type: VariableType\n value: Json\n}\n\n/** The variables a workflow declares, by name. */\nexport type VariableDeclarations = Record<string, VariableDeclaration>\n\ndeclare const VAR: unique symbol\n\n/** A workflow variable, compiled to `<variable.name>`. */\nexport interface VarRef {\n readonly [VAR]: string\n}\n\ntype VariableValue<T extends VariableType> = T extends 'number'\n ? number\n : T extends 'boolean'\n ? boolean\n : T extends 'string' | 'plain'\n ? string\n : Json\n\n/** `vars` in the workflow body: one typed reference per declared variable. */\nexport type VarRefs<V extends VariableDeclarations> = {\n readonly [K in keyof V]: VarRef & Ref<VariableValue<V[K]['type']>>\n}\n\n/**\n * Workflow variables by name, untyped. Prefer the `vars` the `workflow()` body receives, which is\n * typed from the declared variables.\n */\nexport declare const vars: { readonly [name: string]: VarRef & Ref<Json> }\n\ndeclare const WORKFLOW_DEF: unique symbol\n\n/** The default export of a workflow file. */\nexport interface WorkflowDef {\n readonly [WORKFLOW_DEF]: true\n}\n\n/** A child workflow by key, for `runWorkflow` or as an agent tool. */\nexport interface WorkflowRef<Key extends string = string> extends ResourceRef<'workflow', Key> {\n /**\n * The workflow as an agent tool, as the editor's tool picker adds it:\n * `childWorkflow('enrich-lead').asTool()`. A tool with fixed inputs is written `raw(tool)`.\n */\n asTool(options?: ToolUsage): Tool\n}\n\n/**\n * Declares a workflow. The body wires blocks; it never runs. With no description or variables the\n * options may be left out: `workflow('Name', () => { ... })`.\n */\nexport declare function workflow<const V extends VariableDeclarations = Record<never, never>>(\n name: string,\n options: { description?: string; variables?: V },\n body: (scope: { vars: VarRefs<V> }) => void\n): WorkflowDef\nexport declare function workflow(\n name: string,\n body: (scope: { vars: VarRefs<Record<never, never>> }) => void\n): WorkflowDef\n/** A child workflow by key: `childWorkflow('enrich-lead')`. */\nexport declare function childWorkflow<K extends WorkflowKey>(key: K): WorkflowRef<K>\n\n// Containers\n\ntype ItemOf<C> = C extends { readonly [REF]: readonly (infer E)[] }\n ? E\n : C extends readonly (infer E)[]\n ? E\n : Json\n\n/** Inside a loop or parallel body. As a node it is the container's start port: `p.to(first)`. */\nexport interface SubflowScope<Item> extends Node {\n readonly index: Ref<number>\n readonly currentItem: Ref<Item>\n readonly items: Ref<Item[]>\n}\n\n/**\n * A container's outputs, plus its iteration fields by name (`outer.index`), which a block inside\n * the container reads (in a nested container too: an outer loop's index or item). Outside the\n * container only `results` resolves: check reports `W_REF_OUT_OF_SCOPE` on `outer.index` there.\n */\nexport interface SubflowOutput {\n results: Json[]\n index: number\n currentItem: Json\n items: Json[]\n}\n\n/** A loop or parallel container. Its `.to()` wires the port taken after it finishes. */\nexport type Container = Block<SubflowOutput>\n\ntype Collection = AnyRef | Template | Json[] | string\n\nexport declare const loop: {\n for(\n name: string,\n params: { count?: number },\n body: (scope: SubflowScope<never>) => void,\n meta?: BlockMeta\n ): Container\n forEach<const C extends Collection>(\n name: string,\n params: { collection: C },\n body: (scope: SubflowScope<ItemOf<C>>) => void,\n meta?: BlockMeta\n ): Container\n while(\n name: string,\n params: { condition: Template | string },\n body: (scope: SubflowScope<never>) => void,\n meta?: BlockMeta\n ): Container\n doWhile(\n name: string,\n params: { condition?: Template | string; count?: number },\n body: (scope: SubflowScope<never>) => void,\n meta?: BlockMeta\n ): Container\n}\n\nexport declare const parallel: {\n /** A parallel with no stored type, which the loader runs as `count`. */\n (\n name: string,\n params: { count?: number; collection?: Collection; batchSize?: number },\n body: (scope: SubflowScope<Json>) => void,\n meta?: BlockMeta\n ): Container\n count(\n name: string,\n params: { count: number; batchSize?: number },\n body: (scope: SubflowScope<never>) => void,\n meta?: BlockMeta\n ): Container\n collection<const C extends Collection>(\n name: string,\n params: { collection: C; batchSize?: number },\n body: (scope: SubflowScope<ItemOf<C>>) => void,\n meta?: BlockMeta\n ): Container\n}\n\n// Blocks with a source form of their own\n\n/**\n * Params and outputs of the blocks below, generated from the catalog. Each entry is\n * `{ params; output }`; without generated types the params are loose.\n */\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface SpecialBuilderTypes {}\n\ntype SpecialParams<K extends string> = K extends keyof SpecialBuilderTypes\n ? SpecialBuilderTypes[K] extends { params: infer P }\n ? P\n : never\n : Record<string, unknown>\n\ntype SpecialOutput<K extends string> = K extends keyof SpecialBuilderTypes\n ? SpecialBuilderTypes[K] extends { output: infer O }\n ? O\n : never\n : Json\n\n/** A condition expression, or `true` for the `else` branch. */\nexport type BranchExpression = Template | string | true\n\ndeclare const ONLY_ELSE: unique symbol\n\n/** What a branch other than `else` written as `true` must be, which no value is: the error names it. */\ninterface OnlyElseMayBeTrue {\n readonly [ONLY_ELSE]: true\n}\n\n/**\n * A condition's branches: every key holds an expression, and only `else` may be `true`. Another\n * branch written as `true` is checked against {@link OnlyElseMayBeTrue}, so the error names that\n * branch alone.\n */\ntype ConditionBranches<B> = {\n [K in keyof B]: K extends 'else'\n ? BranchExpression\n : B[K] extends true\n ? OnlyElseMayBeTrue\n : Template | string\n}\n\n/**\n * Keys of a condition written with no rows (`condition('Name', {})`, the source form of rows\n * that were never persisted): the implicit `if` and `else` ports stay addressable.\n */\ntype ConditionKeys<B> = keyof B extends never ? 'if' | 'else' : Extract<keyof B, string>\ntype RouterKeys<R> = keyof R extends never ? 'route0' : Extract<keyof R, string>\n\n/** A condition: named branches, the last one `else` when there are two or more. */\nexport declare function condition<const B extends Record<string, BranchExpression>>(\n name: string,\n branches: B & ConditionBranches<B>,\n meta?: BlockMeta\n): Block<SpecialOutput<'condition'>> & Branches<ConditionKeys<B>>\n\n/** A router: named routes described for the model. */\nexport declare function router<const R extends Record<string, string | Template>>(\n name: string,\n params: SpecialParams<'router'> & { routes: R },\n meta?: BlockMeta\n): Block<SpecialOutput<'router'>> & Branches<RouterKeys<R>>\n\n/** A function block. `code` is inline (`` js`...` ``) or a code file (`codeFile('./functions/x.js')`). */\nexport declare function fn(\n name: string,\n params: SpecialParams<'fn'> & { code: Template | CodeFileRef | string },\n meta?: BlockMeta\n): Block<SpecialOutput<'fn'>>\n\n/**\n * The inputs of a child workflow by key, each checked against the input its start block\n * declares when `workspace.d.ts` knows the workflow; loose JSON otherwise.\n */\nexport type WorkflowInputMapping<K extends string> = K extends keyof WorkspaceWorkflows\n ? WorkspaceWorkflows[K] extends { inputs: infer I }\n ? { [N in keyof I]?: FieldValue<I[N]> }\n : InputMapping\n : InputMapping\n\n/**\n * Runs a child workflow. A `childWorkflow('key')` checks `inputMapping` against its inputs. Its\n * `result` is the child's output: its first response block's `{ data, status, headers }` (a body\n * field is `result.data.field`), else the output of the last block it ran.\n */\nexport declare function runWorkflow<K extends string = string>(\n name: string,\n params: Omit<SpecialParams<'runWorkflow'>, 'workflowId' | 'inputMapping'> & {\n workflowId: WorkflowRef<K> | Exclude<SpecialParams<'runWorkflow'>['workflowId'], WorkflowRef>\n inputMapping?: WorkflowInputMapping<K>\n },\n meta?: BlockMeta\n): Block<SpecialOutput<'runWorkflow'>>\n\n/**\n * Pauses for a person; the form in `inputFormat` types `submission`. A resumed block also holds\n * each form field at its top level (the runtime copies the submission up, over any output of the\n * same name), so `approval.approved` and `approval.submission.approved` both read it.\n */\nexport declare function human<const F extends InputFields = Record<never, never>>(\n name: string,\n params: SpecialParams<'human'> & { inputFormat?: F },\n meta?: BlockMeta\n): Block<\n Omit<SpecialOutput<'human'>, 'submission' | keyof F> & {\n submission: InputFieldsOutput<F>\n } & InputFieldsOutput<F>\n>\n\n/**\n * A response's body, status and headers: the editor's JSON mode, `body` standing for\n * `{ dataMode: 'json', data }`. An object or array `body` is JSON whose references keep their\n * types; a template or reference is the body text as written.\n */\nexport interface ResponseBody {\n body: JsonWithRefs\n /** HTTP status; 200 when omitted. A template or reference must produce a number. */\n status?: number | RefTo<number> | Template | EnvRef\n /** Response headers by name. */\n headers?: Record<string, Value<string>>\n}\n\n/**\n * Ends the workflow with an API response: `response('Reply', { body: { ok: true }, status: 201 })`\n * (`body` is short for `dataMode: 'json'` with `data`), or the block's own params (`dataMode`,\n * `builderData`, ...) when the body is built field by field.\n */\nexport declare function response(\n name: string,\n params: ResponseBody,\n meta?: BlockMeta\n): Block<SpecialOutput<'response'>>\nexport declare function response(\n name: string,\n params: SpecialParams<'response'>,\n meta?: BlockMeta\n): Block<SpecialOutput<'response'>>\n\n/** Assigns workflow variables. */\nexport declare function setVariables(\n name: string,\n params: SpecialParams<'setVariables'>,\n meta?: BlockMeta\n): Block<SpecialOutput<'setVariables'>>\n\ndeclare const ANNOTATION: unique symbol\n\n/** A canvas note: no edges, no outputs. */\nexport interface Annotation {\n readonly [ANNOTATION]: true\n}\nexport declare function note(\n name: string,\n params: SpecialParams<'note'>,\n meta?: BlockMeta\n): Annotation\n\n// Structured param shapes\n\n/** Type names an input-format field may declare. */\nexport type InputFieldType = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'file[]'\n\n/** A structured input field: its type plus a default value, description or required flag. */\nexport interface InputFieldSpec {\n type: InputFieldType\n value?: JsonWithRefs\n description?: string\n required?: boolean\n}\n\n/** `input-format` fields by name: `{ subject: 'string', amount: { type: 'number', value: 0 } }`. */\nexport type InputFields = Record<string, InputFieldType | InputFieldSpec>\n\ntype InputFieldValue<T> = T extends 'string'\n ? string\n : T extends 'number'\n ? number\n : T extends 'boolean'\n ? boolean\n : T extends 'array'\n ? Json[]\n : T extends 'file[]'\n ? SimFile[]\n : Json\n\n/** The outputs an `input-format` declares. */\nexport type InputFieldsOutput<F> = {\n [K in keyof F]: F[K] extends { type: infer T } ? InputFieldValue<T> : InputFieldValue<F[K]>\n}\n\n/**\n * One `response-format` field as the editor's builder stores it. An `object` or `array` field's\n * `value` may hold nested fields. A response is usually written with `body` instead.\n */\nexport interface ResponseField {\n id?: string\n name: string\n type: string\n value?: JsonWithRefs\n collapsed?: boolean\n}\n\n/** `response-format` fields: `[{ name: 'ok', type: 'boolean', value: true }]`. */\nexport type ResponseFields = ResponseField[]\n\n/** An agent message. */\nexport interface Message {\n role: 'system' | 'user' | 'assistant'\n content: Value<string>\n}\n\n/** One `variables-input` assignment, with any other stored keys kept. */\nexport interface VariableAssignment {\n variableId: VarRef\n value?: JsonWithRefs\n [key: string]: JsonWithRefs | VarRef | undefined\n}\n\n/** Child workflow inputs by name (`input-mapping`, `workflow-input-mapper`). */\nexport type InputMapping = Record<string, JsonWithRefs>\n\n/** An operator a table filter condition or builder rule can use. */\nexport type FilterOperator = LiteralUnion<\n | 'eq'\n | 'ne'\n | 'gt'\n | 'gte'\n | 'lt'\n | 'lte'\n | 'in'\n | 'nin'\n | 'like'\n | 'ilike'\n | 'nlike'\n | 'nilike'\n | 'contains'\n | 'ncontains'\n | 'startsWith'\n | 'endsWith'\n | 'isNull'\n | 'isNotNull'\n | 'isEmpty'\n | 'isNotEmpty'\n>\n\n/** One row of the editor's filter builder, as it stores it. */\nexport interface FilterRule {\n id?: string\n /** How this row joins the rows before it; `and` when omitted. */\n logicalOperator?: 'and' | 'or'\n column: string\n operator: FilterOperator\n value: Value<string | number | boolean>\n collapsed?: boolean\n}\n\n/** A filter-builder value: the editor's rows, `[{ column: 'status', operator: 'eq', value: 'new' }]`. */\nexport type Filter = FilterRule[]\n\n/** One table filter condition: `{ field: 'status', op: 'eq', value: 'new' }`. */\nexport interface TableCondition {\n field: string\n op: FilterOperator\n value?: JsonWithRefs\n}\n\n/**\n * A table predicate: a condition, or an `all` (and) / `any` (or) group of predicates. The\n * `{ status: { $eq: 'new' } }` operator-object grammar is not one: the runtime refuses it.\n */\nexport type TablePredicate = TableCondition | { all: TablePredicate[] } | { any: TablePredicate[] }\n\n/** A table sort by column: `{ createdAt: 'desc' }`. */\nexport type Sort =\n | Record<string, 'asc' | 'desc'>\n | Array<{ column: string; direction: 'asc' | 'desc' }>\n\n/** One knowledge tag filter. */\nexport interface TagFilter {\n tagName: string\n tagValue: Value<string>\n [key: string]: JsonWithRefs\n}\n\n/** One document tag. */\nexport interface DocumentTag {\n tagName: string\n value: Value<string>\n [key: string]: JsonWithRefs\n}\n\n/** One `eval-input` metric. */\nexport interface EvalMetric {\n name: string\n description?: string\n range?: { min: number; max: number }\n [key: string]: JsonWithRefs | undefined\n}\n\n/** One `model-fallback-list` entry. */\nexport interface ModelFallback {\n model: LiteralUnion<Model>\n [key: string]: JsonWithRefs\n}\n\n/**\n * Model ids, generated into `models.d.ts` (which adds one member per model). Kept apart from the\n * block files so a model-list change touches one file.\n */\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface ModelIds {}\nexport type Model = Extract<keyof ModelIds, string>\n\n/** A JSON Schema `responseFormat`, or `{ name, strict, schema }` around one. */\nexport type ResponseFormat = JsonWithRefs\n\ntype Depth = [never, 0, 1, 2, 3, 4]\n\ntype FromSchema<S, D extends number> = [D] extends [never]\n ? Json\n : S extends { enum: readonly (infer E)[] }\n ? E\n : S extends { type: 'object'; properties: infer P }\n ? { [K in keyof P]: FromSchema<P[K], Depth[D]> }\n : S extends { type: 'array'; items: infer I }\n ? FromSchema<I, Depth[D]>[]\n : S extends { type: 'string' }\n ? string\n : S extends { type: 'number' | 'integer' }\n ? number\n : S extends { type: 'boolean' }\n ? boolean\n : Json\n\n/**\n * The outputs a literal `responseFormat` adds, read from its JSON Schema with recursion capped at\n * depth 4. A template or reference adds untyped JSON.\n */\nexport type ResponseFormatOutput<RF> = [RF] extends [undefined]\n ? unknown\n : RF extends { schema: infer S }\n ? FromSchema<S, 4>\n : RF extends { type: 'object'; properties: object }\n ? FromSchema<RF, 4>\n : { [key: string]: Json }\n";
|
|
40943
|
+
var CORE_DTS = "/**\n * The authoring surface for Sim workflows written as TypeScript.\n *\n * Nothing declared here runs. `@sim/workflow-code` compiles a workflow file statically, and every\n * runtime export of this package throws `SimSdkNotExecutable`. These declarations exist so an\n * editor, `tsc` (the type-check command `sim` prints) or an agent can check a workflow file before\n * the compiler sees it.\n *\n * Block builders (`slack.sendMessage`, `agent`, `trigger.gmail.poller`, ...) are not declared here:\n * they are generated from the block catalog into `blocks/{type}.d.ts`, which augment this module.\n * The generic `block(type, name, params)` covers any stored type without a builder.\n *\n * Every workflow file starts with the SDK header line, before any import:\n *\n * ```ts\n * // @sim-sdk 1\n * import { agent, trigger, workflow } from '@sim/workflow-sdk'\n * ```\n *\n * The number is the SDK major version the file is written against. A file without the header is\n * refused with `E_SDK_HEADER`, and one written for a newer major than the server supports with\n * `E_SDK_MAJOR`.\n */\n\n/** Plain JSON. */\nexport type Json = null | boolean | number | string | Json[] | { [key: string]: Json }\n\ndeclare const REF: unique symbol\ndeclare const TEMPLATE: unique symbol\ndeclare const ENV: unique symbol\ndeclare const RESOURCE: unique symbol\ndeclare const TOOL: unique symbol\ndeclare const NODE: unique symbol\ndeclare const CODE_FILE: unique symbol\ndeclare const RAW: unique symbol\ndeclare const UNTYPED: unique symbol\n\n/** Any reference, whatever it points at. */\nexport interface AnyRef {\n readonly [REF]: unknown\n}\n\n/** Marks a reference into untyped JSON, which any param accepts: its value is known only at run time. */\ninterface Untyped {\n readonly [UNTYPED]: true\n}\n\n/**\n * A reference into untyped JSON, where any path is allowed at any depth. An interface rather than\n * `Ref<Json>`, which TypeScript stops resolving after one step (`a.b.c` failed at `c`).\n */\ninterface UntypedRef extends Untyped {\n readonly [REF]: Json\n readonly [key: string]: UntypedRef\n}\n\ntype RefPaths<T> = [Json] extends [T]\n ? Untyped & { readonly [key: string]: UntypedRef }\n : T extends readonly (infer E)[]\n ? { readonly [index: number]: Ref<E>; readonly length: Ref<number> }\n : T extends object\n ? { readonly [K in keyof T]-?: Ref<T[K]> }\n : unknown\n\n/**\n * A typed reference to a block output, compiled to `<blockkey.path>`.\n * Paths map exactly: `.seg`, `['seg']` and `[n]`. Untyped JSON allows any path.\n */\nexport type Ref<T> = { readonly [REF]: T } & RefPaths<T>\n\n/** Text with references in it, written with one of the tags below. */\nexport type Template = string & { readonly [TEMPLATE]: true }\n\n/** A workspace environment variable, compiled to `{{NAME}}`. */\nexport interface EnvRef {\n readonly [ENV]: string\n}\n\n/**\n * What a reference must hold to fill a param of type `T`. A param taking some strings takes any\n * string (an option id computed at run time); `null` (an output a step left empty) fits anywhere.\n */\ntype RefValue<T> = [Extract<T, string>] extends [never] ? T | null : T | string | null\n\n/**\n * A reference that fits a param of type `T`: one whose value has that type, or one into untyped\n * JSON. A whole block is not a value: reference one of its outputs.\n */\nexport type RefTo<T> = ({ readonly [REF]: RefValue<T> } | (AnyRef & Untyped)) & {\n readonly [NODE]?: never\n}\n\n/** A param value: a literal, a reference of a fitting type, a template or an environment variable. */\nexport type Value<T> = T | RefTo<T> | Template | EnvRef\n\n/** JSON whose leaves may be references, templates or environment variables. */\nexport type JsonWithRefs =\n | null\n | boolean\n | number\n | string\n | AnyRef\n | Template\n | EnvRef\n | JsonWithRefs[]\n | { [key: string]: JsonWithRefs }\n\n/** A literal union that still accepts any other string (option ids read from values). */\nexport type LiteralUnion<T extends string> = T | (string & {})\n\n/** A `time-input` value, `HH:MM`. */\nexport type TimeString = `${number}:${number}`\n\n/** A reference written into text: any output or variable, but not a whole block. */\ntype InterpolatedRef = AnyRef & { readonly [NODE]?: never }\n\ntype Interpolation = InterpolatedRef | EnvRef | VarRef | string | number | boolean\n\n/** Text with interpolated references: `` t`New ${cls.category} ticket` ``. */\nexport declare function t(strings: TemplateStringsArray, ...values: Interpolation[]): Template\n/** JavaScript code (condition expressions, inline function code). */\nexport declare const js: typeof t\n/** Python code. */\nexport declare const py: typeof t\n/** Shell code. */\nexport declare const sh: typeof t\n/**\n * JSON text kept verbatim, for bodies an object literal cannot reproduce byte for byte. In a JSON\n * field an object literal is the usual form: a bare reference keeps its value's type (`n: score.value`\n * is a number), and a template is text.\n */\nexport declare const json: typeof t\n/** Markdown text (note content). */\nexport declare const md: typeof t\n\n/** A reference with a non-canonical spelling, such as `ref('Classify.content')`. */\nexport declare function ref(path: string): Ref<Json>\n\n/** A stored value outside the generated type (a legacy option id, say), kept verbatim. */\nexport declare function raw<T = never>(value: unknown): T & { readonly [RAW]: true }\n\n/** A required value that is still missing; compiles to absent, so canvas drafts type-check. */\nexport declare function todo(): never\n\n/**\n * Keeps the value the stored workflow holds for this param, without showing it: the printer writes\n * it for a secret pasted into a password field. Valid only on a param of a block the stored\n * workflow already has (same name and type) and holds a value for; anything else is\n * `E_STORED_VALUE_MISSING`.\n */\nexport declare function stored(): never\n\n/** Function code kept in a file next to the workflow (`.js`, `.py` or `.sh`), stored verbatim. */\nexport interface CodeFileRef {\n readonly [CODE_FILE]: string\n}\nexport declare function codeFile(path: `./${string}`): CodeFileRef\n\n/**\n * Environment variable names known to the workspace. `workspace.d.ts` adds one member per name;\n * until it exists `env` accepts any name.\n */\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceEnv {}\n\nexport declare const env: keyof WorkspaceEnv extends never\n ? { readonly [name: string]: EnvRef }\n : { readonly [K in keyof WorkspaceEnv]: EnvRef }\n\n/**\n * Workspace resources by stable key, filled in by the generated `workspace.d.ts`. Each map's\n * values describe the resource: a table's row type, a credential's provider, a workflow's inputs.\n */\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceTables {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceKnowledgeBases {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceCredentials {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceWorkflows {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceSkills {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceCustomTools {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceMcpServers {}\n\ntype KeyOf<M> = keyof M extends never ? string : Extract<keyof M, string>\n\nexport type TableKey = KeyOf<WorkspaceTables>\nexport type KnowledgeBaseKey = KeyOf<WorkspaceKnowledgeBases>\nexport type CredentialKey = KeyOf<WorkspaceCredentials>\nexport type WorkflowKey = KeyOf<WorkspaceWorkflows>\nexport type SkillKey = KeyOf<WorkspaceSkills>\nexport type CustomToolKey = KeyOf<WorkspaceCustomTools>\nexport type McpServerKey = KeyOf<WorkspaceMcpServers>\n/**\n * The tool names of MCP server `K`, as `workspace.d.ts` records them from the server's last\n * listing; any name for a server it could not list or does not know.\n */\nexport type McpToolName<K extends string> = K extends keyof WorkspaceMcpServers\n ? WorkspaceMcpServers[K] extends { tools: infer T extends string }\n ? T\n : string\n : string\n\n/** A workspace resource by stable key, compiled to the resource's internal id. */\nexport interface ResourceRef<Kind extends string, Key extends string = string> {\n readonly [RESOURCE]: Kind\n readonly key: Key\n}\n\n/** A saved credential: `credential('support-slack')`. */\nexport type CredentialRef<Key extends string = string> = ResourceRef<'credential', Key>\n\n/**\n * Keys of the saved credentials for one of `Providers`, as `workspace.d.ts` records each\n * credential's provider; any key until it exists.\n */\nexport type CredentialKeyFor<Providers extends string> = keyof WorkspaceCredentials extends never\n ? string\n : {\n [K in Extract<keyof WorkspaceCredentials, string>]: WorkspaceCredentials[K] extends {\n provider: Providers\n }\n ? K\n : never\n }[Extract<keyof WorkspaceCredentials, string>]\nexport declare function credential<K extends CredentialKey>(key: K): CredentialRef<K>\n\n/**\n * The other form a credential field takes beside `credential('key')`: a credential id produced at\n * run time by a reference, a template or an environment variable, stored in the field's advanced\n * twin (`manualCredential`). Literal text is not one, so a pasted token never type-checks; a\n * literal id the stored workflow already holds prints as `raw('…')`.\n */\nexport type CredentialIdValue = RefTo<string> | Template | EnvRef\n\n/** The columns of a workspace table, or loose JSON when `workspace.d.ts` does not know it. */\nexport type TableColumns<K extends string> = K extends keyof WorkspaceTables\n ? WorkspaceTables[K]\n : { [column: string]: Json }\n/**\n * One row as the table blocks output it: the row id, and its cells keyed by column name under\n * `data` (`row.data.status`). Times are ISO strings.\n */\nexport interface TableRow<K extends string> {\n id: string\n data: TableColumns<K>\n position: number\n createdAt: string\n updatedAt: string\n}\n/**\n * A value written to a field of type `T` (a table cell, a child workflow input): a JSON or JSON\n * array field takes JSON with references in it, and `null` leaves the field empty.\n */\ntype FieldValue<T> = [Json] extends [T]\n ? JsonWithRefs\n : [Json[]] extends [T]\n ? JsonWithRefs\n : Value<T> | null\n\n/** The columns of table `K` every row must hold: those whose cell type does not admit `null`. */\ntype RequiredColumns<K extends keyof WorkspaceTables> = {\n [C in keyof WorkspaceTables[K]]-?: null extends WorkspaceTables[K][C] ? never : C\n}[keyof WorkspaceTables[K]]\n\n/**\n * A whole row, as an insert, an upsert or a batch insert writes it, each value checked against\n * its column's type. A required column must be present and not `null`: the table refuses a row\n * without it (`Missing required field`), and an upsert checks the whole row before it looks for a\n * match.\n */\nexport type TableData<K extends string> = K extends keyof WorkspaceTables\n ? { [C in RequiredColumns<K>]-?: Exclude<FieldValue<WorkspaceTables[K][C]>, null> } & {\n [C in Exclude<keyof WorkspaceTables[K], RequiredColumns<K>>]?: FieldValue<\n WorkspaceTables[K][C]\n >\n }\n : { [column: string]: JsonWithRefs }\n\n/**\n * The cells an update writes, each checked against its column's type. Every column is optional:\n * an update merges these cells over the stored row.\n */\nexport type TableDataPatch<K extends string> = K extends keyof WorkspaceTables\n ? { [C in keyof WorkspaceTables[K]]?: FieldValue<WorkspaceTables[K][C]> }\n : { [column: string]: JsonWithRefs }\n\n/** A workspace table: `table('leads')`. Table block operations live on `table.*`. */\nexport type TableRef<Key extends string = string> = ResourceRef<'table', Key>\nexport declare function table<K extends TableKey>(key: K): TableRef<K>\n\n/** A knowledge base: `knowledgeBase('docs')`. */\nexport type KnowledgeBaseRef<Key extends string = string> = ResourceRef<'knowledge-base', Key>\nexport declare function knowledgeBase<K extends KnowledgeBaseKey>(key: K): KnowledgeBaseRef<K>\n\n/** A workspace skill: `skill('triage')`. */\nexport type SkillRef<Key extends string = string> = ResourceRef<'skill', Key>\nexport declare function skill<K extends SkillKey>(key: K): SkillRef<K>\n\n/** A workspace folder: `folder('reports')`. */\nexport type FolderRef = ResourceRef<'file-folder'>\nexport declare function folder(key: string): FolderRef\n\n/** A workspace file: `file('contracts/acme.pdf')`. File block operations live on `file.*`. */\nexport type FileRef = ResourceRef<'file'>\nexport declare function file(path: string): FileRef\n\n/**\n * A file a file-upload field holds, as the editor stores it: one uploaded in place, or a workspace\n * file chosen by `key` (written `file('path')` when the workspace resolves it).\n */\nexport interface UploadedFile {\n name: string\n path: string\n size?: number\n type?: string\n key?: string | FileRef\n id?: string\n folderPath?: string\n}\n\n/** A file produced at run time (`file` / `file[]` outputs). */\nexport interface SimFile {\n id: string\n name: string\n url: string\n size: number\n type: string\n key: string\n}\n\n// Agent tools\n\n/** One entry of an agent's `tools` list. */\nexport interface Tool {\n readonly [TOOL]: true\n}\n\n/** How the model may use a tool, and the stored tool fields a print carries. */\nexport interface ToolOpts {\n usageControl?: 'auto' | 'force' | 'none'\n usageControlExpression?: string\n title?: string\n /** The stored operation, when the method does not pin it. */\n operation?: string\n toolId?: string\n /** Pair modes of the tool's params, which pick the member the agent reads. */\n modes?: Record<string, 'basic' | 'advanced'>\n customTool?: JsonWithRefs\n operationPolicy?: Json\n /** Unknown stored tool keys, kept verbatim. */\n extra?: Json\n}\n\n/**\n * A workspace custom tool by key, as an agent tool: `customTool('lookup-order')`. A stored tool\n * whose definition was copied into the workflow (and may have drifted from the workspace tool)\n * prints as `raw(tool)` instead.\n */\nexport declare function customTool<K extends CustomToolKey>(key: K, options?: ToolUsage): Tool\n\n/** How the model may use a tool the SDK writes by name (`customTool`, `mcp().tool`, `asTool`). */\nexport type ToolUsage = Pick<ToolOpts, 'usageControl' | 'usageControlExpression'>\n\n/** An MCP tool's arguments and the editor's snapshot of its server. */\nexport interface McpToolOpts extends ToolUsage {\n /** Argument values the workflow fixes; the model fills in the rest. */\n args?: Record<string, JsonWithRefs>\n /**\n * What the editor saved about the server and the tool's input schema when the tool was picked.\n * Shown in the editor; never run.\n */\n snapshot?: { serverName?: string; serverUrl?: string; schema?: Json }\n}\n\n/** An MCP server by key: `mcp('linear')`. */\nexport interface McpServerRef<Key extends string = string> extends ResourceRef<'mcp-server', Key> {\n /** One of the server's tools, as an agent tool: `mcp('linear').tool('create_issue')`. */\n tool(name: McpToolName<Key>, options?: McpToolOpts): Tool\n}\nexport declare function mcp<K extends McpServerKey>(key: K): McpServerRef<K>\n\n// Graph\n\n/** Block-level fields (`BlockState`), written as the third builder argument. */\nexport interface BlockMeta {\n /**\n * A legacy key the display name cannot carry (a `name~n` collision key or a reserved name such\n * as `Loop`). Printed only for such a stored block; apply accepts it only for a key the stored\n * workflow already has, so it can never introduce one.\n */\n key?: string\n /** Stored as `enabled: false`. */\n disabled?: true\n /** Locked: apply refuses any change to this block. */\n locked?: true\n /** Exposes the error port without an `onError` edge. */\n errorPort?: boolean\n /** The block-level advanced toggle (`advancedMode`). */\n advancedMode?: boolean\n /**\n * Runs the block as its trigger (`triggerMode`). Trigger builders (`trigger.gmail.poller`) set\n * it themselves; write it on any other builder only for a block stored in trigger mode.\n */\n triggerMode?: boolean\n /** The stored retry policy, written whole. */\n retry?: BlockRetryConfig\n /**\n * Per branch key of a condition or router, the row's display `title` and any stored fields the\n * SDK has no syntax for (`extra`, plain JSON). `title: null` keeps a row stored with no title,\n * which the executor never takes for `else`.\n */\n branches?: Record<string, { title?: string | null; extra?: Record<string, Json> }>\n /**\n * Stored params that run but have no SDK syntax: a schema-agnostic custom block's inputs, the\n * agent's legacy prompt fields, a container's stored params. Values the block keeps but never\n * runs are not written; apply keeps them from the stored workflow.\n */\n extra?: Record<string, unknown>\n /**\n * A loop or parallel's `block.data` subflow keys the loader could not read as config, kept\n * verbatim (plain JSON).\n */\n subflowData?: Record<string, Json>\n}\n\n/** A block's retry policy, field for field the stored `BlockRetryConfig`. */\nexport interface BlockRetryConfig {\n /** Absent config and `false` mean the same thing: the block runs once. */\n enabled: boolean\n /** Total tries including the first. */\n maxTries: number\n /** Delay between tries. */\n waitBetweenTriesMs: number\n}\n\n/** Anything an edge can point at. */\nexport type Target = Node | Group\n\n/** A block or container in the graph. */\nexport interface Node {\n readonly [NODE]: true\n /** Wires this node's default port to each target. Returns the target, or a group of them. */\n to<const T extends Target[]>(...targets: T): T extends [infer One] ? One : Group\n /** Wires this node's error port to each target. */\n onError(...targets: Target[]): void\n}\n\n/** Several nodes; `.to()` wires every member (fan-in). */\nexport interface Group {\n to(...targets: Target[]): Group\n}\n\n/**\n * What a block outputs when it fails and an error edge leaves it (`x.onError(y)` runs `y` with\n * `x.error`): the failure message `error` on every block, plus the error outputs `E` its catalog\n * entry declares (a Function's `errorMessage`, the thrown message without its line and code). A\n * check refuses each on a block without an error edge, which fails the run instead. An output the\n * block declares under the same name keeps its declared type.\n */\ntype ErrorOutputs<O, E extends string> = {\n readonly [K in 'error' | E as [O] extends [Record<K, unknown>] ? never : K]: Ref<string>\n}\n\n/** A block: a node whose outputs can be referenced, and its error outputs after an `onError` edge. */\nexport type Block<O, E extends string = never> = Node & Ref<O> & ErrorOutputs<O, E>\n\n/** The named ports of a condition or router. */\nexport type Branches<K extends string> = { readonly [P in K]: Node }\n\n/** Trigger builders (`trigger.start`, `trigger.gmail.poller`, ...), generated from the catalog. */\nexport declare namespace trigger {}\n\n/** Builders for hidden legacy block versions (`legacy.slack.send`), generated from the catalog. */\nexport declare namespace legacy {}\n\n/** A raw edge from a handle the SDK has no name for (a legacy or unknown port). */\nexport declare function edge(from: Node, handle: string, to: Target): void\n\n/** Any stored block type without a builder (legacy, unknown or custom), with untyped outputs. */\nexport declare function block(\n type: string,\n name: string,\n params: Record<string, unknown>,\n meta?: BlockMeta\n): Block<Json>\n\n// Workflow and variables\n\nexport type VariableType = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'plain'\n\n/** A workflow variable declared in `workflow(name, { variables })`: its type and initial value. */\nexport interface VariableDeclaration {\n /**\n * The display name, written only when it differs from the key. It must normalize to the key\n * (lowercased, spaces and dots removed), as `'Total Count'` does to `totalcount`.\n */\n name?: string\n type: VariableType\n value: Json\n}\n\n/** The variables a workflow declares, by name. */\nexport type VariableDeclarations = Record<string, VariableDeclaration>\n\ndeclare const VAR: unique symbol\n\n/** A workflow variable, compiled to `<variable.name>`. */\nexport interface VarRef {\n readonly [VAR]: string\n}\n\ntype VariableValue<T extends VariableType> = T extends 'number'\n ? number\n : T extends 'boolean'\n ? boolean\n : T extends 'string' | 'plain'\n ? string\n : Json\n\n/** `vars` in the workflow body: one typed reference per declared variable. */\nexport type VarRefs<V extends VariableDeclarations> = {\n readonly [K in keyof V]: VarRef & Ref<VariableValue<V[K]['type']>>\n}\n\n/**\n * Workflow variables by name, untyped. Prefer the `vars` the `workflow()` body receives, which is\n * typed from the declared variables.\n */\nexport declare const vars: { readonly [name: string]: VarRef & Ref<Json> }\n\ndeclare const WORKFLOW_DEF: unique symbol\n\n/** The default export of a workflow file. */\nexport interface WorkflowDef {\n readonly [WORKFLOW_DEF]: true\n}\n\n/** A child workflow by key, for `runWorkflow` or as an agent tool. */\nexport interface WorkflowRef<Key extends string = string> extends ResourceRef<'workflow', Key> {\n /**\n * The workflow as an agent tool, as the editor's tool picker adds it:\n * `childWorkflow('enrich-lead').asTool()`. A tool with fixed inputs is written `raw(tool)`.\n */\n asTool(options?: ToolUsage): Tool\n}\n\n/**\n * Declares a workflow. The body wires blocks; it never runs. With no description or variables the\n * options may be left out: `workflow('Name', () => { ... })`.\n */\nexport declare function workflow<const V extends VariableDeclarations = Record<never, never>>(\n name: string,\n options: { description?: string; variables?: V },\n body: (scope: { vars: VarRefs<V> }) => void\n): WorkflowDef\nexport declare function workflow(\n name: string,\n body: (scope: { vars: VarRefs<Record<never, never>> }) => void\n): WorkflowDef\n/** A child workflow by key: `childWorkflow('enrich-lead')`. */\nexport declare function childWorkflow<K extends WorkflowKey>(key: K): WorkflowRef<K>\n\n// Containers\n\ntype ItemOf<C> = C extends { readonly [REF]: readonly (infer E)[] }\n ? E\n : C extends readonly (infer E)[]\n ? E\n : Json\n\n/** Inside a loop or parallel body. As a node it is the container's start port: `p.to(first)`. */\nexport interface SubflowScope<Item> extends Node {\n readonly index: Ref<number>\n readonly currentItem: Ref<Item>\n readonly items: Ref<Item[]>\n}\n\n/**\n * A container's outputs, plus its iteration fields by name (`outer.index`), which a block inside\n * the container reads (in a nested container too: an outer loop's index or item). Outside the\n * container only `results` resolves: check reports `W_REF_OUT_OF_SCOPE` on `outer.index` there.\n */\nexport interface SubflowOutput {\n results: Json[]\n index: number\n currentItem: Json\n items: Json[]\n}\n\n/** A loop or parallel container. Its `.to()` wires the port taken after it finishes. */\nexport type Container = Block<SubflowOutput>\n\ntype Collection = AnyRef | Template | Json[] | string\n\nexport declare const loop: {\n for(\n name: string,\n params: { count?: number },\n body: (scope: SubflowScope<never>) => void,\n meta?: BlockMeta\n ): Container\n forEach<const C extends Collection>(\n name: string,\n params: { collection: C },\n body: (scope: SubflowScope<ItemOf<C>>) => void,\n meta?: BlockMeta\n ): Container\n while(\n name: string,\n params: { condition: Template | string },\n body: (scope: SubflowScope<never>) => void,\n meta?: BlockMeta\n ): Container\n doWhile(\n name: string,\n params: { condition?: Template | string; count?: number },\n body: (scope: SubflowScope<never>) => void,\n meta?: BlockMeta\n ): Container\n}\n\nexport declare const parallel: {\n /** A parallel with no stored type, which the loader runs as `count`. */\n (\n name: string,\n params: { count?: number; collection?: Collection; batchSize?: number },\n body: (scope: SubflowScope<Json>) => void,\n meta?: BlockMeta\n ): Container\n count(\n name: string,\n params: { count: number; batchSize?: number },\n body: (scope: SubflowScope<never>) => void,\n meta?: BlockMeta\n ): Container\n collection<const C extends Collection>(\n name: string,\n params: { collection: C; batchSize?: number },\n body: (scope: SubflowScope<ItemOf<C>>) => void,\n meta?: BlockMeta\n ): Container\n}\n\n// Blocks with a source form of their own\n\n/**\n * Params and outputs of the blocks below, generated from the catalog. Each entry is\n * `{ params; output }`, with `errorOutputs` when the block declares any; without generated types\n * the params are loose.\n */\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface SpecialBuilderTypes {}\n\ntype SpecialParams<K extends string> = K extends keyof SpecialBuilderTypes\n ? SpecialBuilderTypes[K] extends { params: infer P }\n ? P\n : never\n : Record<string, unknown>\n\ntype SpecialOutput<K extends string> = K extends keyof SpecialBuilderTypes\n ? SpecialBuilderTypes[K] extends { output: infer O }\n ? O\n : never\n : Json\n\n/** The error outputs a special builder's block declares; a builder whose block has any passes them. */\ntype SpecialErrorOutputs<K extends string> = K extends keyof SpecialBuilderTypes\n ? SpecialBuilderTypes[K] extends { errorOutputs: infer E extends string }\n ? E\n : never\n : never\n\n/** A condition expression, or `true` for the `else` branch. */\nexport type BranchExpression = Template | string | true\n\ndeclare const ONLY_ELSE: unique symbol\n\n/** What a branch other than `else` written as `true` must be, which no value is: the error names it. */\ninterface OnlyElseMayBeTrue {\n readonly [ONLY_ELSE]: true\n}\n\n/**\n * A condition's branches: every key holds an expression, and only `else` may be `true`. Another\n * branch written as `true` is checked against {@link OnlyElseMayBeTrue}, so the error names that\n * branch alone.\n */\ntype ConditionBranches<B> = {\n [K in keyof B]: K extends 'else'\n ? BranchExpression\n : B[K] extends true\n ? OnlyElseMayBeTrue\n : Template | string\n}\n\n/**\n * Keys of a condition written with no rows (`condition('Name', {})`, the source form of rows\n * that were never persisted): the implicit `if` and `else` ports stay addressable.\n */\ntype ConditionKeys<B> = keyof B extends never ? 'if' | 'else' : Extract<keyof B, string>\ntype RouterKeys<R> = keyof R extends never ? 'route0' : Extract<keyof R, string>\n\n/** A condition: named branches, the last one `else` when there are two or more. */\nexport declare function condition<const B extends Record<string, BranchExpression>>(\n name: string,\n branches: B & ConditionBranches<B>,\n meta?: BlockMeta\n): Block<SpecialOutput<'condition'>> & Branches<ConditionKeys<B>>\n\n/** A router: named routes described for the model. */\nexport declare function router<const R extends Record<string, string | Template>>(\n name: string,\n params: SpecialParams<'router'> & { routes: R },\n meta?: BlockMeta\n): Block<SpecialOutput<'router'>> & Branches<RouterKeys<R>>\n\n/** A function block. `code` is inline (`` js`...` ``) or a code file (`codeFile('./functions/x.js')`). */\nexport declare function fn(\n name: string,\n params: SpecialParams<'fn'> & { code: Template | CodeFileRef | string },\n meta?: BlockMeta\n): Block<SpecialOutput<'fn'>, SpecialErrorOutputs<'fn'>>\n\n/**\n * The inputs of a child workflow by key, each checked against the input its start block\n * declares when `workspace.d.ts` knows the workflow; loose JSON otherwise.\n */\nexport type WorkflowInputMapping<K extends string> = K extends keyof WorkspaceWorkflows\n ? WorkspaceWorkflows[K] extends { inputs: infer I }\n ? { [N in keyof I]?: FieldValue<I[N]> }\n : InputMapping\n : InputMapping\n\n/**\n * Runs a child workflow. A `childWorkflow('key')` checks `inputMapping` against its inputs. Its\n * `result` is the child's output: its first response block's `{ data, status, headers }` (a body\n * field is `result.data.field`), else the output of the last block it ran.\n */\nexport declare function runWorkflow<K extends string = string>(\n name: string,\n params: Omit<SpecialParams<'runWorkflow'>, 'workflowId' | 'inputMapping'> & {\n workflowId: WorkflowRef<K> | Exclude<SpecialParams<'runWorkflow'>['workflowId'], WorkflowRef>\n inputMapping?: WorkflowInputMapping<K>\n },\n meta?: BlockMeta\n): Block<SpecialOutput<'runWorkflow'>>\n\n/**\n * Pauses for a person; the form in `inputFormat` types `submission`. A resumed block also holds\n * each form field at its top level (the runtime copies the submission up, over any output of the\n * same name), so `approval.approved` and `approval.submission.approved` both read it.\n */\nexport declare function human<const F extends InputFields = Record<never, never>>(\n name: string,\n params: SpecialParams<'human'> & { inputFormat?: F },\n meta?: BlockMeta\n): Block<\n Omit<SpecialOutput<'human'>, 'submission' | keyof F> & {\n submission: InputFieldsOutput<F>\n } & InputFieldsOutput<F>\n>\n\n/**\n * A response's body, status and headers: the editor's JSON mode, `body` standing for\n * `{ dataMode: 'json', data }`. An object or array `body` is JSON whose references keep their\n * types; a template or reference is the body text as written.\n */\nexport interface ResponseBody {\n body: JsonWithRefs\n /** HTTP status; 200 when omitted. A template or reference must produce a number. */\n status?: number | RefTo<number> | Template | EnvRef\n /** Response headers by name. */\n headers?: Record<string, Value<string>>\n}\n\n/**\n * Ends the workflow with an API response: `response('Reply', { body: { ok: true }, status: 201 })`\n * (`body` is short for `dataMode: 'json'` with `data`), or the block's own params (`dataMode`,\n * `builderData`, ...) when the body is built field by field.\n */\nexport declare function response(\n name: string,\n params: ResponseBody,\n meta?: BlockMeta\n): Block<SpecialOutput<'response'>>\nexport declare function response(\n name: string,\n params: SpecialParams<'response'>,\n meta?: BlockMeta\n): Block<SpecialOutput<'response'>>\n\n/** Assigns workflow variables. */\nexport declare function setVariables(\n name: string,\n params: SpecialParams<'setVariables'>,\n meta?: BlockMeta\n): Block<SpecialOutput<'setVariables'>>\n\ndeclare const ANNOTATION: unique symbol\n\n/** A canvas note: no edges, no outputs. */\nexport interface Annotation {\n readonly [ANNOTATION]: true\n}\nexport declare function note(\n name: string,\n params: SpecialParams<'note'>,\n meta?: BlockMeta\n): Annotation\n\n// Structured param shapes\n\n/** Type names an input-format field may declare. */\nexport type InputFieldType = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'file[]'\n\n/** A structured input field: its type plus a default value, description or required flag. */\nexport interface InputFieldSpec {\n type: InputFieldType\n value?: JsonWithRefs\n description?: string\n required?: boolean\n}\n\n/** `input-format` fields by name: `{ subject: 'string', amount: { type: 'number', value: 0 } }`. */\nexport type InputFields = Record<string, InputFieldType | InputFieldSpec>\n\ntype InputFieldValue<T> = T extends 'string'\n ? string\n : T extends 'number'\n ? number\n : T extends 'boolean'\n ? boolean\n : T extends 'array'\n ? Json[]\n : T extends 'file[]'\n ? SimFile[]\n : Json\n\n/** The outputs an `input-format` declares. */\nexport type InputFieldsOutput<F> = {\n [K in keyof F]: F[K] extends { type: infer T } ? InputFieldValue<T> : InputFieldValue<F[K]>\n}\n\n/**\n * One `response-format` field as the editor's builder stores it. An `object` or `array` field's\n * `value` may hold nested fields. A response is usually written with `body` instead.\n */\nexport interface ResponseField {\n id?: string\n name: string\n type: string\n value?: JsonWithRefs\n collapsed?: boolean\n}\n\n/** `response-format` fields: `[{ name: 'ok', type: 'boolean', value: true }]`. */\nexport type ResponseFields = ResponseField[]\n\n/** An agent message. */\nexport interface Message {\n role: 'system' | 'user' | 'assistant'\n content: Value<string>\n}\n\n/** One `variables-input` assignment, with any other stored keys kept. */\nexport interface VariableAssignment {\n variableId: VarRef\n value?: JsonWithRefs\n [key: string]: JsonWithRefs | VarRef | undefined\n}\n\n/** Child workflow inputs by name (`input-mapping`, `workflow-input-mapper`). */\nexport type InputMapping = Record<string, JsonWithRefs>\n\n/** An operator a table filter condition or builder rule can use. */\nexport type FilterOperator = LiteralUnion<\n | 'eq'\n | 'ne'\n | 'gt'\n | 'gte'\n | 'lt'\n | 'lte'\n | 'in'\n | 'nin'\n | 'like'\n | 'ilike'\n | 'nlike'\n | 'nilike'\n | 'contains'\n | 'ncontains'\n | 'startsWith'\n | 'endsWith'\n | 'isNull'\n | 'isNotNull'\n | 'isEmpty'\n | 'isNotEmpty'\n>\n\n/** One row of the editor's filter builder, as it stores it. */\nexport interface FilterRule {\n id?: string\n /** How this row joins the rows before it; `and` when omitted. */\n logicalOperator?: 'and' | 'or'\n column: string\n operator: FilterOperator\n value: Value<string | number | boolean>\n collapsed?: boolean\n}\n\n/** A filter-builder value: the editor's rows, `[{ column: 'status', operator: 'eq', value: 'new' }]`. */\nexport type Filter = FilterRule[]\n\n/** One table filter condition: `{ field: 'status', op: 'eq', value: 'new' }`. */\nexport interface TableCondition {\n field: string\n op: FilterOperator\n value?: JsonWithRefs\n}\n\n/**\n * A table predicate: a condition, or an `all` (and) / `any` (or) group of predicates. The\n * `{ status: { $eq: 'new' } }` operator-object grammar is not one: the runtime refuses it.\n */\nexport type TablePredicate = TableCondition | { all: TablePredicate[] } | { any: TablePredicate[] }\n\n/** A table sort by column: `{ createdAt: 'desc' }`. */\nexport type Sort =\n | Record<string, 'asc' | 'desc'>\n | Array<{ column: string; direction: 'asc' | 'desc' }>\n\n/** One knowledge tag filter. */\nexport interface TagFilter {\n tagName: string\n tagValue: Value<string>\n [key: string]: JsonWithRefs\n}\n\n/** One document tag. */\nexport interface DocumentTag {\n tagName: string\n value: Value<string>\n [key: string]: JsonWithRefs\n}\n\n/** One `eval-input` metric. */\nexport interface EvalMetric {\n name: string\n description?: string\n range?: { min: number; max: number }\n [key: string]: JsonWithRefs | undefined\n}\n\n/** One `model-fallback-list` entry. */\nexport interface ModelFallback {\n model: LiteralUnion<Model>\n [key: string]: JsonWithRefs\n}\n\n/**\n * Model ids, generated into `models.d.ts` (which adds one member per model). Kept apart from the\n * block files so a model-list change touches one file.\n */\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface ModelIds {}\nexport type Model = Extract<keyof ModelIds, string>\n\n/** A JSON Schema `responseFormat`, or `{ name, strict, schema }` around one. */\nexport type ResponseFormat = JsonWithRefs\n\ntype Depth = [never, 0, 1, 2, 3, 4]\n\ntype FromSchema<S, D extends number> = [D] extends [never]\n ? Json\n : S extends { enum: readonly (infer E)[] }\n ? E\n : S extends { type: 'object'; properties: infer P }\n ? { [K in keyof P]: FromSchema<P[K], Depth[D]> }\n : S extends { type: 'array'; items: infer I }\n ? FromSchema<I, Depth[D]>[]\n : S extends { type: 'string' }\n ? string\n : S extends { type: 'number' | 'integer' }\n ? number\n : S extends { type: 'boolean' }\n ? boolean\n : Json\n\n/**\n * The outputs a literal `responseFormat` adds, read from its JSON Schema with recursion capped at\n * depth 4. A template or reference adds untyped JSON.\n */\nexport type ResponseFormatOutput<RF> = [RF] extends [undefined]\n ? unknown\n : RF extends { schema: infer S }\n ? FromSchema<S, 4>\n : RF extends { type: 'object'; properties: object }\n ? FromSchema<RF, 4>\n : { [key: string]: Json }\n";
|
|
40937
40944
|
// ../workflow-code/src/anchors.ts
|
|
40938
40945
|
function portKey(port) {
|
|
40939
40946
|
switch (port.kind) {
|
|
@@ -41776,6 +41783,13 @@ function blockOutputSchemas(catalog, block, options) {
|
|
|
41776
41783
|
const trigger = triggerId === undefined ? undefined : catalogTrigger(catalog, triggerId);
|
|
41777
41784
|
return trigger ? trigger.outputs : block.outputs;
|
|
41778
41785
|
}
|
|
41786
|
+
function isErrorOutputName(block, name) {
|
|
41787
|
+
return name === "error" || (block?.errorOutputs?.includes(name) ?? false);
|
|
41788
|
+
}
|
|
41789
|
+
function errorOutputOf(block, segments) {
|
|
41790
|
+
const [first] = segments;
|
|
41791
|
+
return segments.length === 1 && first?.kind === "name" && isErrorOutputName(block, first.name) ? first.name : null;
|
|
41792
|
+
}
|
|
41779
41793
|
function builderOutputSchemas(catalog, block, builder) {
|
|
41780
41794
|
return blockOutputSchemas(catalog, block, {
|
|
41781
41795
|
triggerMode: builder?.triggerMode === true,
|
|
@@ -42766,10 +42780,7 @@ function refValueKind(token, scope) {
|
|
|
42766
42780
|
if (type !== undefined)
|
|
42767
42781
|
return type === "string" ? "string" : "typed";
|
|
42768
42782
|
}
|
|
42769
|
-
|
|
42770
|
-
if (segments.length === 1 && first?.kind === "name" && first.name === "error")
|
|
42771
|
-
return "string";
|
|
42772
|
-
return "untyped";
|
|
42783
|
+
return errorOutputOf(declared, segments) ? "string" : "untyped";
|
|
42773
42784
|
}
|
|
42774
42785
|
function storedValue(block, id) {
|
|
42775
42786
|
const param = getOwn(block.params, id);
|
|
@@ -44593,21 +44604,19 @@ function checkOutputPath(ctx, at, target, segments, blockKey) {
|
|
|
44593
44604
|
const outputs = builderOutputSchemas(ctx.catalog, block, builder);
|
|
44594
44605
|
if (outputKnown(outputs, segments))
|
|
44595
44606
|
return;
|
|
44596
|
-
|
|
44597
|
-
|
|
44607
|
+
const errorOutput = errorOutputOf(block, segments);
|
|
44608
|
+
if (errorOutput) {
|
|
44609
|
+
ctx.errorOutputRefs.push({ at, target, blockKey, output: errorOutput });
|
|
44598
44610
|
return;
|
|
44599
44611
|
}
|
|
44600
44612
|
ctx.reporter.report("W_UNKNOWN_OUTPUT_PATH", `${target.name} has no output ${formatStoredPath(segments)}.`, at, { hint: () => unknownOutputHint(outputs, segments), blockKey });
|
|
44601
44613
|
}
|
|
44602
|
-
function isErrorOutput(segments) {
|
|
44603
|
-
return segments.length === 1 && segments[0].kind === "name" && segments[0].name === "error";
|
|
44604
|
-
}
|
|
44605
44614
|
function checkErrorOutputRefs(ctx, erroring) {
|
|
44606
|
-
for (const { at, target, blockKey } of ctx.errorOutputRefs) {
|
|
44615
|
+
for (const { at, target, blockKey, output } of ctx.errorOutputRefs) {
|
|
44607
44616
|
if (erroring.has(target.key))
|
|
44608
44617
|
continue;
|
|
44609
|
-
ctx.reporter.report("W_OUTPUT_PATH_UNDECLARED", `${target.name} has no output
|
|
44610
|
-
hint: `Wire ${target.ident ?? "the block"}.onError(<handler>) and read ${target.ident ?? "it"}
|
|
44618
|
+
ctx.reporter.report("W_OUTPUT_PATH_UNDECLARED", `${target.name} has no output ${output}: only a block with an error edge outputs its failure message.`, at, {
|
|
44619
|
+
hint: `Wire ${target.ident ?? "the block"}.onError(<handler>) and read ${target.ident ?? "it"}.${output} in the handler.`,
|
|
44611
44620
|
blockKey
|
|
44612
44621
|
});
|
|
44613
44622
|
}
|
|
@@ -44645,8 +44654,9 @@ function checkDynamicOutputRefs(ctx, blockOf) {
|
|
|
44645
44654
|
const outputs = builderOutputSchemas(ctx.catalog, block, builder);
|
|
44646
44655
|
if (outputKnown(outputs, segments))
|
|
44647
44656
|
continue;
|
|
44648
|
-
|
|
44649
|
-
|
|
44657
|
+
const errorOutput = errorOutputOf(block, segments);
|
|
44658
|
+
if (errorOutput) {
|
|
44659
|
+
ctx.errorOutputRefs.push({ at, target, blockKey, output: errorOutput });
|
|
44650
44660
|
continue;
|
|
44651
44661
|
}
|
|
44652
44662
|
const known = [...fields, ...Object.keys(outputs)];
|
|
@@ -51489,7 +51499,7 @@ var RUNTIME_SEMANTICS = [
|
|
|
51489
51499
|
"## How it runs",
|
|
51490
51500
|
"",
|
|
51491
51501
|
"- **Two retries, nested.** An `api` block's `retries`, `retryDelayMs` and `retryMaxDelayMs` repeat the HTTP request inside one run of the block: only after a timeout, a connection reset, a 429 or a 5xx (a host that does not resolve or refuses the connection fails at once), only for GET, HEAD, PUT and DELETE unless `retryNonIdempotent: true`, with jittered exponential backoff capped at `retryMaxDelayMs` (a `Retry-After` beyond the cap ends the retries). `meta.retry` (`{ enabled, maxTries, waitBetweenTriesMs }`) reruns the whole block, request retries included, after any failure but a stop or a failed child workflow; `maxTries` counts every try. So `retries: 2` under `maxTries: 3` sends up to 9 requests. Only the last try's failure reaches `onError`. Triggers and `human` never retry.",
|
|
51492
|
-
"- **`onError`.** `x.onError(y)` makes a failure of `x` an output, `{ error: '<message>' }`, and runs `y` instead of `x`'s other targets; the run goes on. `y` reads the message as `x.error` (only a block with an `onError` edge has it). In a loop or parallel body (`y` must be in the same body) the iteration ends normally and the loop moves to the next item, with that error output as `x`'s entry for the iteration. Without `onError`, a failure in any iteration fails the run and stops the loop.",
|
|
51502
|
+
"- **`onError`.** `x.onError(y)` makes a failure of `x` an output, `{ error: '<message>' }`, and runs `y` instead of `x`'s other targets; the run goes on. `y` reads the message as `x.error` (only a block with an `onError` edge has it); a Function's `error` leads with the line and code that threw, and its `x.errorMessage` is the thrown message alone, the one to reply with (a failure that throws nothing, such as a timeout, repeats `error` there). In a loop or parallel body (`y` must be in the same body) the iteration ends normally and the loop moves to the next item, with that error output as `x`'s entry for the iteration. Without `onError`, a failure in any iteration fails the run and stops the loop.",
|
|
51493
51503
|
"- **Joins run once.** A block with several incoming edges runs once, after every one of them has fired or been ruled out (a condition or router branch not taken, the normal edge of a block that failed into `onError`). `a.to(join)`, `b.to(join)`, `c.to(join)` wait for all three; behind a condition only the taken branch fires, and the join runs once after it. A block never runs once per incoming branch. A reference to a block that did not run (on the branch not taken) resolves empty: `null` as a whole value, in function code or in a condition, `''` inside text.",
|
|
51494
51504
|
"- **Loop and parallel results.** `x.results` holds one entry per iteration (a parallel: per branch), and each entry is the list of outputs of the body blocks that ran in it, in the order they finished. With one block in the body its output is `x.results[i][0]`; `x.results.flat()` lists every output.",
|
|
51495
51505
|
"- **Outputs in function code.** In `fn` code, `${a.content}` inside js`` is not spliced in as text: it becomes an expression that evaluates to the output's value, a string as a string and an object as an object. Write it where an expression goes (`const reply = ${a.content}`, `[${a.content}, ${b.content}]`) and never wrap it in quotes. Written inside a JavaScript string or template literal it splices in as JSON, quotes included (`'Hi ${a.content}'` gives `Hi \"hello\"`). Python code works the same way.",
|
|
@@ -51793,6 +51803,7 @@ function builderTypes(catalog, entry) {
|
|
|
51793
51803
|
};
|
|
51794
51804
|
const outputRef = `${outputName}${outputGeneric ? genericArgs : ""}`;
|
|
51795
51805
|
const outputType = plan?.outputExtension ? `Omit<${outputRef}, keyof ${plan.outputExtension}> & ${plan.outputExtension}` : outputRef;
|
|
51806
|
+
const errorOutputs = block.errorOutputs?.length ? union(block.errorOutputs.map(literal)) : "";
|
|
51796
51807
|
const method = entry.path[entry.path.length - 1];
|
|
51797
51808
|
const label = entry.builder.operation ? operationLabel(block, entry.builder.operation) : undefined;
|
|
51798
51809
|
const jsdocSummary = [
|
|
@@ -51802,13 +51813,13 @@ function builderTypes(catalog, entry) {
|
|
|
51802
51813
|
].filter(Boolean).join(" ");
|
|
51803
51814
|
const signature = entry.special ? [] : [
|
|
51804
51815
|
...jsdoc([jsdocSummary], ""),
|
|
51805
|
-
`export function ${method}${typeParameterList(plan, true)}(name: string, params: ${paramsName}${genericArgs}, meta?: BlockMeta): Block<${outputType}>`
|
|
51816
|
+
`export function ${method}${typeParameterList(plan, true)}(name: string, params: ${paramsName}${genericArgs}, meta?: BlockMeta): Block<${outputType}${errorOutputs ? `, ${errorOutputs}` : ""}>`
|
|
51806
51817
|
];
|
|
51807
51818
|
const tool = !entry.special && hasToolForm(entry.key, entry.builder, block) ? [
|
|
51808
51819
|
...jsdoc([`${jsdocSummary}, as an agent tool`], ""),
|
|
51809
51820
|
`export function ${method}(params?: Partial<${paramsName}>, options?: ToolOpts): Tool`
|
|
51810
51821
|
] : null;
|
|
51811
|
-
const special = entry.special ? `${entry.key}: { params: ${paramsName}; output: ${outputName} }` : null;
|
|
51822
|
+
const special = entry.special ? `${entry.key}: { params: ${paramsName}; output: ${outputName}${errorOutputs ? `; errorOutputs: ${errorOutputs}` : ""} }` : null;
|
|
51812
51823
|
return {
|
|
51813
51824
|
params: paramsDeclaration,
|
|
51814
51825
|
output,
|
|
@@ -56663,12 +56674,12 @@ var MAX_SNIPPET_BYTES = 4096;
|
|
|
56663
56674
|
var PARAMS_COMMAND = "sim workflows source params";
|
|
56664
56675
|
function sharedRules(group, extraRenames = "") {
|
|
56665
56676
|
return `- **Identity**: a block is its entry in \`${SOURCE_LOCK_FILE}\`, which binds it by its const name or its display name. Change the display name (first argument) freely: references through the const follow it, and the apply rewrites every \`$ref.<old key>\` and \`<old key.…>\` to the new key and reprints the files (don't hand-edit them). Renaming the const too keeps it when settings, neighbours or references still tie it to the old block; otherwise the apply refuses a delete (\`E_APPLY_BLOCK_DELETE\`). Safest: keep the const.
|
|
56666
|
-
- **References**: in \`${SOURCE_ENTRY_FILE}\` read an output as \`x.content\`, a loop or parallel item as \`p.currentItem\` (\`p.index\`), text as \`\` t\`…\` \`\`, env as \`env.NAME\`. In a function
|
|
56677
|
+
- **References**: in \`${SOURCE_ENTRY_FILE}\` read an output as \`x.content\`, a loop or parallel item as \`p.currentItem\` (\`p.index\`), text as \`\` t\`…\` \`\`, env as \`env.NAME\`. In a function file (\`codeFile('./functions/x.js')\`) read an output as \`$ref.<key>.<path>\`, the key: the display name lowercased, whitespace and dots removed ("Triage Agent" → \`$ref.triageagent.content\`); in a loop body \`$ref.loop.currentItem\` / \`$ref.loop.index\`, in a parallel \`$ref.parallel.currentItem\` / \`$ref.parallel.index\`; env as \`$env.NAME\`. In \`.py\`/\`.sh\` files write \`<key.path>\` and \`{{NAME}}\`, not \`$ref\`/\`$env\`. Read an index or item only inside its container (\`E_APPLY_REF_OUT_OF_SCOPE\`), after it its \`.results\`. A \`$ref\` naming no block is an error in a function file you edited (\`E_APPLY_UNRESOLVED_REF\`).
|
|
56667
56678
|
- **Renames**: one variable per apply (two at once read as a delete and an add).${extraRenames}
|
|
56668
|
-
- **Look up a builder**: \`${PARAMS_COMMAND} <builder>\` (\`agent\`, \`trigger.schedule\`; a namespace like \`gmail\` lists
|
|
56679
|
+
- **Look up a builder**: \`${PARAMS_COMMAND} <builder>\` (\`agent\`, \`trigger.schedule\`; a namespace like \`gmail\` lists them), offline.
|
|
56669
56680
|
- **Credentials**: \`sim credentials connect <provider> --name "<Name>"\`, give the owner its link, then \`credential('<key>')\` (\`sim workflows source resources\`).
|
|
56670
|
-
- **Failures**: \`x.onError(y)\` runs \`y\` when \`x\` fails, reading the message as \`x.error
|
|
56671
|
-
- **Run and debug**: \`sim workflows run <workflowId> --manual --input '{…}'\` runs the saved draft
|
|
56681
|
+
- **Failures**: \`x.onError(y)\` runs \`y\` when \`x\` fails, reading the message as \`x.error\` (a Function's \`x.errorMessage\` drops the line and code: reply with it). Retry is block meta (third argument): \`agent('Name', {…}, { retry: { enabled: true, maxTries: 3, waitBetweenTriesMs: 2000 } })\`. Each replying branch needs its own \`response\`.
|
|
56682
|
+
- **Run and debug**: \`sim workflows run <workflowId> --manual --input '{…}'\` runs the saved draft (without it, the deployed version). Runs write real data (rows, emails): use test resources. With \`--dir <the workflow's folder>\`, a failed run names the failing file and line; then \`sim logs get <runId> --trace --no-include-workflow-state\` (spans hold resolved inputs).
|
|
56672
56683
|
- **Exit codes**: 0 ok, 1 errors, ${SOURCE_STALE_EXIT_CODE} stale (\`${group} get --dir <fresh dir>\`, redo the edit there), ${RATE_LIMITED_EXIT_CODE} rate limited, ${SOURCE_BUSY_EXIT_CODE} busy, ${SOURCE_LOCAL_CHANGES_EXIT_CODE}/${SOURCE_DRIFT_EXIT_CODE} \`status\`: your edits / the server changed. Every code: \`${SOURCE_AGENTS_FILE}\`.`;
|
|
56673
56684
|
}
|
|
56674
56685
|
var WORKFLOW_PRIMER = `# Sim workflow source: primer
|
package/dist/runtime.js
CHANGED
|
@@ -35233,7 +35233,9 @@ Block settings, beside inputs in an add's or edit's params:
|
|
|
35233
35233
|
5xx, not when the host does not resolve or refuses the connection; "retry" covers that.
|
|
35234
35234
|
Outputs:
|
|
35235
35235
|
A block that fails outputs {"error":"<message>"}: connect its error handle and read
|
|
35236
|
-
<name.error> there (without one, the run fails). A
|
|
35236
|
+
<name.error> there (without one, the run fails). A Function's error leads with the line and
|
|
35237
|
+
code that threw; its <name.errorMessage> is the thrown message alone, the one to reply with.
|
|
35238
|
+
A Workflow block's result is the child's
|
|
35237
35239
|
output; a child ending in a Response block gives {data, status, headers}, so read
|
|
35238
35240
|
<call.result.data.x>.`;
|
|
35239
35241
|
var BLOCK_DETAIL_GUIDE = `
|
|
@@ -35244,7 +35246,8 @@ Reading it for \`sim workflows operations apply\`:
|
|
|
35244
35246
|
inputDefinitions the block's inputs by name; one a pair of fields shares (tableId for
|
|
35245
35247
|
tableSelector and manualTableId) is accepted in place of the pair
|
|
35246
35248
|
outputs what it outputs on success; a failed block outputs {"error":"…"}
|
|
35247
|
-
instead, read on its error path as <name.error>
|
|
35249
|
+
instead, read on its error path as <name.error> (a Function also
|
|
35250
|
+
outputs <name.errorMessage>, the thrown message without line or code)
|
|
35248
35251
|
Block settings such as retry are not fields: \`sim workflows operations apply --help\`.`;
|
|
35249
35252
|
var WORKFLOW_SET_BLOCK_ENABLED_HELP = 'Blocks to enable or disable, applied after --operations: [{"block_id":"<uuid>","enabled":false}]. Disabling a loop or parallel cascades to its unlocked descendants; enabling a block whose container is disabled is declined';
|
|
35250
35253
|
var WORKFLOW_VARIABLE_OPERATIONS_HELP = 'Variable changes to apply in order, keyed by operation: [{"operation":"add","name":"my_var","type":"string","value":"hello"},{"operation":"edit","name":"my_var","value":"updated"},{"operation":"delete","name":"my_var"}]';
|
|
@@ -40872,6 +40875,9 @@ export default workflow('Cookbook', { description: 'One example of each common b
|
|
|
40872
40875
|
dataMode: 'json',
|
|
40873
40876
|
data: { status: 'rejected' },
|
|
40874
40877
|
})
|
|
40878
|
+
// Error path: shape.onError(invalid) runs invalid when the code throws. shape.error leads with
|
|
40879
|
+
// the line and code that threw; shape.errorMessage is the thrown message alone, for the caller.
|
|
40880
|
+
const invalid = response('Respond Invalid', { body: { error: shape.errorMessage }, status: 422 })
|
|
40875
40881
|
|
|
40876
40882
|
// Wiring: a.to(b) chains; a block can fan out to several targets.
|
|
40877
40883
|
start.to(check)
|
|
@@ -40886,6 +40892,7 @@ export default workflow('Cookbook', { description: 'One example of each common b
|
|
|
40886
40892
|
docs.to(shape)
|
|
40887
40893
|
route.else.to(shape)
|
|
40888
40894
|
shape.to(reply)
|
|
40895
|
+
shape.onError(invalid)
|
|
40889
40896
|
nightly.to(recent)
|
|
40890
40897
|
recent.to(each)
|
|
40891
40898
|
each.to(report)
|
|
@@ -40982,7 +40989,7 @@ export default workflow(
|
|
|
40982
40989
|
)
|
|
40983
40990
|
` };
|
|
40984
40991
|
// ../workflow-sdk/src/codegen/core-text.generated.ts
|
|
40985
|
-
var CORE_DTS = "/**\n * The authoring surface for Sim workflows written as TypeScript.\n *\n * Nothing declared here runs. `@sim/workflow-code` compiles a workflow file statically, and every\n * runtime export of this package throws `SimSdkNotExecutable`. These declarations exist so an\n * editor, `tsc` (the type-check command `sim` prints) or an agent can check a workflow file before\n * the compiler sees it.\n *\n * Block builders (`slack.sendMessage`, `agent`, `trigger.gmail.poller`, ...) are not declared here:\n * they are generated from the block catalog into `blocks/{type}.d.ts`, which augment this module.\n * The generic `block(type, name, params)` covers any stored type without a builder.\n *\n * Every workflow file starts with the SDK header line, before any import:\n *\n * ```ts\n * // @sim-sdk 1\n * import { agent, trigger, workflow } from '@sim/workflow-sdk'\n * ```\n *\n * The number is the SDK major version the file is written against. A file without the header is\n * refused with `E_SDK_HEADER`, and one written for a newer major than the server supports with\n * `E_SDK_MAJOR`.\n */\n\n/** Plain JSON. */\nexport type Json = null | boolean | number | string | Json[] | { [key: string]: Json }\n\ndeclare const REF: unique symbol\ndeclare const TEMPLATE: unique symbol\ndeclare const ENV: unique symbol\ndeclare const RESOURCE: unique symbol\ndeclare const TOOL: unique symbol\ndeclare const NODE: unique symbol\ndeclare const CODE_FILE: unique symbol\ndeclare const RAW: unique symbol\ndeclare const UNTYPED: unique symbol\n\n/** Any reference, whatever it points at. */\nexport interface AnyRef {\n readonly [REF]: unknown\n}\n\n/** Marks a reference into untyped JSON, which any param accepts: its value is known only at run time. */\ninterface Untyped {\n readonly [UNTYPED]: true\n}\n\n/**\n * A reference into untyped JSON, where any path is allowed at any depth. An interface rather than\n * `Ref<Json>`, which TypeScript stops resolving after one step (`a.b.c` failed at `c`).\n */\ninterface UntypedRef extends Untyped {\n readonly [REF]: Json\n readonly [key: string]: UntypedRef\n}\n\ntype RefPaths<T> = [Json] extends [T]\n ? Untyped & { readonly [key: string]: UntypedRef }\n : T extends readonly (infer E)[]\n ? { readonly [index: number]: Ref<E>; readonly length: Ref<number> }\n : T extends object\n ? { readonly [K in keyof T]-?: Ref<T[K]> }\n : unknown\n\n/**\n * A typed reference to a block output, compiled to `<blockkey.path>`.\n * Paths map exactly: `.seg`, `['seg']` and `[n]`. Untyped JSON allows any path.\n */\nexport type Ref<T> = { readonly [REF]: T } & RefPaths<T>\n\n/** Text with references in it, written with one of the tags below. */\nexport type Template = string & { readonly [TEMPLATE]: true }\n\n/** A workspace environment variable, compiled to `{{NAME}}`. */\nexport interface EnvRef {\n readonly [ENV]: string\n}\n\n/**\n * What a reference must hold to fill a param of type `T`. A param taking some strings takes any\n * string (an option id computed at run time); `null` (an output a step left empty) fits anywhere.\n */\ntype RefValue<T> = [Extract<T, string>] extends [never] ? T | null : T | string | null\n\n/**\n * A reference that fits a param of type `T`: one whose value has that type, or one into untyped\n * JSON. A whole block is not a value: reference one of its outputs.\n */\nexport type RefTo<T> = ({ readonly [REF]: RefValue<T> } | (AnyRef & Untyped)) & {\n readonly [NODE]?: never\n}\n\n/** A param value: a literal, a reference of a fitting type, a template or an environment variable. */\nexport type Value<T> = T | RefTo<T> | Template | EnvRef\n\n/** JSON whose leaves may be references, templates or environment variables. */\nexport type JsonWithRefs =\n | null\n | boolean\n | number\n | string\n | AnyRef\n | Template\n | EnvRef\n | JsonWithRefs[]\n | { [key: string]: JsonWithRefs }\n\n/** A literal union that still accepts any other string (option ids read from values). */\nexport type LiteralUnion<T extends string> = T | (string & {})\n\n/** A `time-input` value, `HH:MM`. */\nexport type TimeString = `${number}:${number}`\n\n/** A reference written into text: any output or variable, but not a whole block. */\ntype InterpolatedRef = AnyRef & { readonly [NODE]?: never }\n\ntype Interpolation = InterpolatedRef | EnvRef | VarRef | string | number | boolean\n\n/** Text with interpolated references: `` t`New ${cls.category} ticket` ``. */\nexport declare function t(strings: TemplateStringsArray, ...values: Interpolation[]): Template\n/** JavaScript code (condition expressions, inline function code). */\nexport declare const js: typeof t\n/** Python code. */\nexport declare const py: typeof t\n/** Shell code. */\nexport declare const sh: typeof t\n/**\n * JSON text kept verbatim, for bodies an object literal cannot reproduce byte for byte. In a JSON\n * field an object literal is the usual form: a bare reference keeps its value's type (`n: score.value`\n * is a number), and a template is text.\n */\nexport declare const json: typeof t\n/** Markdown text (note content). */\nexport declare const md: typeof t\n\n/** A reference with a non-canonical spelling, such as `ref('Classify.content')`. */\nexport declare function ref(path: string): Ref<Json>\n\n/** A stored value outside the generated type (a legacy option id, say), kept verbatim. */\nexport declare function raw<T = never>(value: unknown): T & { readonly [RAW]: true }\n\n/** A required value that is still missing; compiles to absent, so canvas drafts type-check. */\nexport declare function todo(): never\n\n/**\n * Keeps the value the stored workflow holds for this param, without showing it: the printer writes\n * it for a secret pasted into a password field. Valid only on a param of a block the stored\n * workflow already has (same name and type) and holds a value for; anything else is\n * `E_STORED_VALUE_MISSING`.\n */\nexport declare function stored(): never\n\n/** Function code kept in a file next to the workflow (`.js`, `.py` or `.sh`), stored verbatim. */\nexport interface CodeFileRef {\n readonly [CODE_FILE]: string\n}\nexport declare function codeFile(path: `./${string}`): CodeFileRef\n\n/**\n * Environment variable names known to the workspace. `workspace.d.ts` adds one member per name;\n * until it exists `env` accepts any name.\n */\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceEnv {}\n\nexport declare const env: keyof WorkspaceEnv extends never\n ? { readonly [name: string]: EnvRef }\n : { readonly [K in keyof WorkspaceEnv]: EnvRef }\n\n/**\n * Workspace resources by stable key, filled in by the generated `workspace.d.ts`. Each map's\n * values describe the resource: a table's row type, a credential's provider, a workflow's inputs.\n */\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceTables {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceKnowledgeBases {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceCredentials {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceWorkflows {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceSkills {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceCustomTools {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceMcpServers {}\n\ntype KeyOf<M> = keyof M extends never ? string : Extract<keyof M, string>\n\nexport type TableKey = KeyOf<WorkspaceTables>\nexport type KnowledgeBaseKey = KeyOf<WorkspaceKnowledgeBases>\nexport type CredentialKey = KeyOf<WorkspaceCredentials>\nexport type WorkflowKey = KeyOf<WorkspaceWorkflows>\nexport type SkillKey = KeyOf<WorkspaceSkills>\nexport type CustomToolKey = KeyOf<WorkspaceCustomTools>\nexport type McpServerKey = KeyOf<WorkspaceMcpServers>\n/**\n * The tool names of MCP server `K`, as `workspace.d.ts` records them from the server's last\n * listing; any name for a server it could not list or does not know.\n */\nexport type McpToolName<K extends string> = K extends keyof WorkspaceMcpServers\n ? WorkspaceMcpServers[K] extends { tools: infer T extends string }\n ? T\n : string\n : string\n\n/** A workspace resource by stable key, compiled to the resource's internal id. */\nexport interface ResourceRef<Kind extends string, Key extends string = string> {\n readonly [RESOURCE]: Kind\n readonly key: Key\n}\n\n/** A saved credential: `credential('support-slack')`. */\nexport type CredentialRef<Key extends string = string> = ResourceRef<'credential', Key>\n\n/**\n * Keys of the saved credentials for one of `Providers`, as `workspace.d.ts` records each\n * credential's provider; any key until it exists.\n */\nexport type CredentialKeyFor<Providers extends string> = keyof WorkspaceCredentials extends never\n ? string\n : {\n [K in Extract<keyof WorkspaceCredentials, string>]: WorkspaceCredentials[K] extends {\n provider: Providers\n }\n ? K\n : never\n }[Extract<keyof WorkspaceCredentials, string>]\nexport declare function credential<K extends CredentialKey>(key: K): CredentialRef<K>\n\n/**\n * The other form a credential field takes beside `credential('key')`: a credential id produced at\n * run time by a reference, a template or an environment variable, stored in the field's advanced\n * twin (`manualCredential`). Literal text is not one, so a pasted token never type-checks; a\n * literal id the stored workflow already holds prints as `raw('…')`.\n */\nexport type CredentialIdValue = RefTo<string> | Template | EnvRef\n\n/** The columns of a workspace table, or loose JSON when `workspace.d.ts` does not know it. */\nexport type TableColumns<K extends string> = K extends keyof WorkspaceTables\n ? WorkspaceTables[K]\n : { [column: string]: Json }\n/**\n * One row as the table blocks output it: the row id, and its cells keyed by column name under\n * `data` (`row.data.status`). Times are ISO strings.\n */\nexport interface TableRow<K extends string> {\n id: string\n data: TableColumns<K>\n position: number\n createdAt: string\n updatedAt: string\n}\n/**\n * A value written to a field of type `T` (a table cell, a child workflow input): a JSON or JSON\n * array field takes JSON with references in it, and `null` leaves the field empty.\n */\ntype FieldValue<T> = [Json] extends [T]\n ? JsonWithRefs\n : [Json[]] extends [T]\n ? JsonWithRefs\n : Value<T> | null\n\n/** The columns of table `K` every row must hold: those whose cell type does not admit `null`. */\ntype RequiredColumns<K extends keyof WorkspaceTables> = {\n [C in keyof WorkspaceTables[K]]-?: null extends WorkspaceTables[K][C] ? never : C\n}[keyof WorkspaceTables[K]]\n\n/**\n * A whole row, as an insert, an upsert or a batch insert writes it, each value checked against\n * its column's type. A required column must be present and not `null`: the table refuses a row\n * without it (`Missing required field`), and an upsert checks the whole row before it looks for a\n * match.\n */\nexport type TableData<K extends string> = K extends keyof WorkspaceTables\n ? { [C in RequiredColumns<K>]-?: Exclude<FieldValue<WorkspaceTables[K][C]>, null> } & {\n [C in Exclude<keyof WorkspaceTables[K], RequiredColumns<K>>]?: FieldValue<\n WorkspaceTables[K][C]\n >\n }\n : { [column: string]: JsonWithRefs }\n\n/**\n * The cells an update writes, each checked against its column's type. Every column is optional:\n * an update merges these cells over the stored row.\n */\nexport type TableDataPatch<K extends string> = K extends keyof WorkspaceTables\n ? { [C in keyof WorkspaceTables[K]]?: FieldValue<WorkspaceTables[K][C]> }\n : { [column: string]: JsonWithRefs }\n\n/** A workspace table: `table('leads')`. Table block operations live on `table.*`. */\nexport type TableRef<Key extends string = string> = ResourceRef<'table', Key>\nexport declare function table<K extends TableKey>(key: K): TableRef<K>\n\n/** A knowledge base: `knowledgeBase('docs')`. */\nexport type KnowledgeBaseRef<Key extends string = string> = ResourceRef<'knowledge-base', Key>\nexport declare function knowledgeBase<K extends KnowledgeBaseKey>(key: K): KnowledgeBaseRef<K>\n\n/** A workspace skill: `skill('triage')`. */\nexport type SkillRef<Key extends string = string> = ResourceRef<'skill', Key>\nexport declare function skill<K extends SkillKey>(key: K): SkillRef<K>\n\n/** A workspace folder: `folder('reports')`. */\nexport type FolderRef = ResourceRef<'file-folder'>\nexport declare function folder(key: string): FolderRef\n\n/** A workspace file: `file('contracts/acme.pdf')`. File block operations live on `file.*`. */\nexport type FileRef = ResourceRef<'file'>\nexport declare function file(path: string): FileRef\n\n/**\n * A file a file-upload field holds, as the editor stores it: one uploaded in place, or a workspace\n * file chosen by `key` (written `file('path')` when the workspace resolves it).\n */\nexport interface UploadedFile {\n name: string\n path: string\n size?: number\n type?: string\n key?: string | FileRef\n id?: string\n folderPath?: string\n}\n\n/** A file produced at run time (`file` / `file[]` outputs). */\nexport interface SimFile {\n id: string\n name: string\n url: string\n size: number\n type: string\n key: string\n}\n\n// Agent tools\n\n/** One entry of an agent's `tools` list. */\nexport interface Tool {\n readonly [TOOL]: true\n}\n\n/** How the model may use a tool, and the stored tool fields a print carries. */\nexport interface ToolOpts {\n usageControl?: 'auto' | 'force' | 'none'\n usageControlExpression?: string\n title?: string\n /** The stored operation, when the method does not pin it. */\n operation?: string\n toolId?: string\n /** Pair modes of the tool's params, which pick the member the agent reads. */\n modes?: Record<string, 'basic' | 'advanced'>\n customTool?: JsonWithRefs\n operationPolicy?: Json\n /** Unknown stored tool keys, kept verbatim. */\n extra?: Json\n}\n\n/**\n * A workspace custom tool by key, as an agent tool: `customTool('lookup-order')`. A stored tool\n * whose definition was copied into the workflow (and may have drifted from the workspace tool)\n * prints as `raw(tool)` instead.\n */\nexport declare function customTool<K extends CustomToolKey>(key: K, options?: ToolUsage): Tool\n\n/** How the model may use a tool the SDK writes by name (`customTool`, `mcp().tool`, `asTool`). */\nexport type ToolUsage = Pick<ToolOpts, 'usageControl' | 'usageControlExpression'>\n\n/** An MCP tool's arguments and the editor's snapshot of its server. */\nexport interface McpToolOpts extends ToolUsage {\n /** Argument values the workflow fixes; the model fills in the rest. */\n args?: Record<string, JsonWithRefs>\n /**\n * What the editor saved about the server and the tool's input schema when the tool was picked.\n * Shown in the editor; never run.\n */\n snapshot?: { serverName?: string; serverUrl?: string; schema?: Json }\n}\n\n/** An MCP server by key: `mcp('linear')`. */\nexport interface McpServerRef<Key extends string = string> extends ResourceRef<'mcp-server', Key> {\n /** One of the server's tools, as an agent tool: `mcp('linear').tool('create_issue')`. */\n tool(name: McpToolName<Key>, options?: McpToolOpts): Tool\n}\nexport declare function mcp<K extends McpServerKey>(key: K): McpServerRef<K>\n\n// Graph\n\n/** Block-level fields (`BlockState`), written as the third builder argument. */\nexport interface BlockMeta {\n /**\n * A legacy key the display name cannot carry (a `name~n` collision key or a reserved name such\n * as `Loop`). Printed only for such a stored block; apply accepts it only for a key the stored\n * workflow already has, so it can never introduce one.\n */\n key?: string\n /** Stored as `enabled: false`. */\n disabled?: true\n /** Locked: apply refuses any change to this block. */\n locked?: true\n /** Exposes the error port without an `onError` edge. */\n errorPort?: boolean\n /** The block-level advanced toggle (`advancedMode`). */\n advancedMode?: boolean\n /**\n * Runs the block as its trigger (`triggerMode`). Trigger builders (`trigger.gmail.poller`) set\n * it themselves; write it on any other builder only for a block stored in trigger mode.\n */\n triggerMode?: boolean\n /** The stored retry policy, written whole. */\n retry?: BlockRetryConfig\n /**\n * Per branch key of a condition or router, the row's display `title` and any stored fields the\n * SDK has no syntax for (`extra`, plain JSON). `title: null` keeps a row stored with no title,\n * which the executor never takes for `else`.\n */\n branches?: Record<string, { title?: string | null; extra?: Record<string, Json> }>\n /**\n * Stored params that run but have no SDK syntax: a schema-agnostic custom block's inputs, the\n * agent's legacy prompt fields, a container's stored params. Values the block keeps but never\n * runs are not written; apply keeps them from the stored workflow.\n */\n extra?: Record<string, unknown>\n /**\n * A loop or parallel's `block.data` subflow keys the loader could not read as config, kept\n * verbatim (plain JSON).\n */\n subflowData?: Record<string, Json>\n}\n\n/** A block's retry policy, field for field the stored `BlockRetryConfig`. */\nexport interface BlockRetryConfig {\n /** Absent config and `false` mean the same thing: the block runs once. */\n enabled: boolean\n /** Total tries including the first. */\n maxTries: number\n /** Delay between tries. */\n waitBetweenTriesMs: number\n}\n\n/** Anything an edge can point at. */\nexport type Target = Node | Group\n\n/** A block or container in the graph. */\nexport interface Node {\n readonly [NODE]: true\n /** Wires this node's default port to each target. Returns the target, or a group of them. */\n to<const T extends Target[]>(...targets: T): T extends [infer One] ? One : Group\n /** Wires this node's error port to each target. */\n onError(...targets: Target[]): void\n}\n\n/** Several nodes; `.to()` wires every member (fan-in). */\nexport interface Group {\n to(...targets: Target[]): Group\n}\n\n/**\n * The failure message a block outputs when an error edge leaves it (`x.onError(y)` runs `y` with\n * `x.error`); a check refuses `x.error` on a block without one, which fails the run instead.\n */\ntype ErrorOutput<O> = [O] extends [{ error: unknown }] ? unknown : { readonly error: Ref<string> }\n\n/** A block: a node whose outputs can be referenced, and `error` after an `onError` edge. */\nexport type Block<O> = Node & Ref<O> & ErrorOutput<O>\n\n/** The named ports of a condition or router. */\nexport type Branches<K extends string> = { readonly [P in K]: Node }\n\n/** Trigger builders (`trigger.start`, `trigger.gmail.poller`, ...), generated from the catalog. */\nexport declare namespace trigger {}\n\n/** Builders for hidden legacy block versions (`legacy.slack.send`), generated from the catalog. */\nexport declare namespace legacy {}\n\n/** A raw edge from a handle the SDK has no name for (a legacy or unknown port). */\nexport declare function edge(from: Node, handle: string, to: Target): void\n\n/** Any stored block type without a builder (legacy, unknown or custom), with untyped outputs. */\nexport declare function block(\n type: string,\n name: string,\n params: Record<string, unknown>,\n meta?: BlockMeta\n): Block<Json>\n\n// Workflow and variables\n\nexport type VariableType = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'plain'\n\n/** A workflow variable declared in `workflow(name, { variables })`: its type and initial value. */\nexport interface VariableDeclaration {\n /**\n * The display name, written only when it differs from the key. It must normalize to the key\n * (lowercased, spaces and dots removed), as `'Total Count'` does to `totalcount`.\n */\n name?: string\n type: VariableType\n value: Json\n}\n\n/** The variables a workflow declares, by name. */\nexport type VariableDeclarations = Record<string, VariableDeclaration>\n\ndeclare const VAR: unique symbol\n\n/** A workflow variable, compiled to `<variable.name>`. */\nexport interface VarRef {\n readonly [VAR]: string\n}\n\ntype VariableValue<T extends VariableType> = T extends 'number'\n ? number\n : T extends 'boolean'\n ? boolean\n : T extends 'string' | 'plain'\n ? string\n : Json\n\n/** `vars` in the workflow body: one typed reference per declared variable. */\nexport type VarRefs<V extends VariableDeclarations> = {\n readonly [K in keyof V]: VarRef & Ref<VariableValue<V[K]['type']>>\n}\n\n/**\n * Workflow variables by name, untyped. Prefer the `vars` the `workflow()` body receives, which is\n * typed from the declared variables.\n */\nexport declare const vars: { readonly [name: string]: VarRef & Ref<Json> }\n\ndeclare const WORKFLOW_DEF: unique symbol\n\n/** The default export of a workflow file. */\nexport interface WorkflowDef {\n readonly [WORKFLOW_DEF]: true\n}\n\n/** A child workflow by key, for `runWorkflow` or as an agent tool. */\nexport interface WorkflowRef<Key extends string = string> extends ResourceRef<'workflow', Key> {\n /**\n * The workflow as an agent tool, as the editor's tool picker adds it:\n * `childWorkflow('enrich-lead').asTool()`. A tool with fixed inputs is written `raw(tool)`.\n */\n asTool(options?: ToolUsage): Tool\n}\n\n/**\n * Declares a workflow. The body wires blocks; it never runs. With no description or variables the\n * options may be left out: `workflow('Name', () => { ... })`.\n */\nexport declare function workflow<const V extends VariableDeclarations = Record<never, never>>(\n name: string,\n options: { description?: string; variables?: V },\n body: (scope: { vars: VarRefs<V> }) => void\n): WorkflowDef\nexport declare function workflow(\n name: string,\n body: (scope: { vars: VarRefs<Record<never, never>> }) => void\n): WorkflowDef\n/** A child workflow by key: `childWorkflow('enrich-lead')`. */\nexport declare function childWorkflow<K extends WorkflowKey>(key: K): WorkflowRef<K>\n\n// Containers\n\ntype ItemOf<C> = C extends { readonly [REF]: readonly (infer E)[] }\n ? E\n : C extends readonly (infer E)[]\n ? E\n : Json\n\n/** Inside a loop or parallel body. As a node it is the container's start port: `p.to(first)`. */\nexport interface SubflowScope<Item> extends Node {\n readonly index: Ref<number>\n readonly currentItem: Ref<Item>\n readonly items: Ref<Item[]>\n}\n\n/**\n * A container's outputs, plus its iteration fields by name (`outer.index`), which a block inside\n * the container reads (in a nested container too: an outer loop's index or item). Outside the\n * container only `results` resolves: check reports `W_REF_OUT_OF_SCOPE` on `outer.index` there.\n */\nexport interface SubflowOutput {\n results: Json[]\n index: number\n currentItem: Json\n items: Json[]\n}\n\n/** A loop or parallel container. Its `.to()` wires the port taken after it finishes. */\nexport type Container = Block<SubflowOutput>\n\ntype Collection = AnyRef | Template | Json[] | string\n\nexport declare const loop: {\n for(\n name: string,\n params: { count?: number },\n body: (scope: SubflowScope<never>) => void,\n meta?: BlockMeta\n ): Container\n forEach<const C extends Collection>(\n name: string,\n params: { collection: C },\n body: (scope: SubflowScope<ItemOf<C>>) => void,\n meta?: BlockMeta\n ): Container\n while(\n name: string,\n params: { condition: Template | string },\n body: (scope: SubflowScope<never>) => void,\n meta?: BlockMeta\n ): Container\n doWhile(\n name: string,\n params: { condition?: Template | string; count?: number },\n body: (scope: SubflowScope<never>) => void,\n meta?: BlockMeta\n ): Container\n}\n\nexport declare const parallel: {\n /** A parallel with no stored type, which the loader runs as `count`. */\n (\n name: string,\n params: { count?: number; collection?: Collection; batchSize?: number },\n body: (scope: SubflowScope<Json>) => void,\n meta?: BlockMeta\n ): Container\n count(\n name: string,\n params: { count: number; batchSize?: number },\n body: (scope: SubflowScope<never>) => void,\n meta?: BlockMeta\n ): Container\n collection<const C extends Collection>(\n name: string,\n params: { collection: C; batchSize?: number },\n body: (scope: SubflowScope<ItemOf<C>>) => void,\n meta?: BlockMeta\n ): Container\n}\n\n// Blocks with a source form of their own\n\n/**\n * Params and outputs of the blocks below, generated from the catalog. Each entry is\n * `{ params; output }`; without generated types the params are loose.\n */\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface SpecialBuilderTypes {}\n\ntype SpecialParams<K extends string> = K extends keyof SpecialBuilderTypes\n ? SpecialBuilderTypes[K] extends { params: infer P }\n ? P\n : never\n : Record<string, unknown>\n\ntype SpecialOutput<K extends string> = K extends keyof SpecialBuilderTypes\n ? SpecialBuilderTypes[K] extends { output: infer O }\n ? O\n : never\n : Json\n\n/** A condition expression, or `true` for the `else` branch. */\nexport type BranchExpression = Template | string | true\n\ndeclare const ONLY_ELSE: unique symbol\n\n/** What a branch other than `else` written as `true` must be, which no value is: the error names it. */\ninterface OnlyElseMayBeTrue {\n readonly [ONLY_ELSE]: true\n}\n\n/**\n * A condition's branches: every key holds an expression, and only `else` may be `true`. Another\n * branch written as `true` is checked against {@link OnlyElseMayBeTrue}, so the error names that\n * branch alone.\n */\ntype ConditionBranches<B> = {\n [K in keyof B]: K extends 'else'\n ? BranchExpression\n : B[K] extends true\n ? OnlyElseMayBeTrue\n : Template | string\n}\n\n/**\n * Keys of a condition written with no rows (`condition('Name', {})`, the source form of rows\n * that were never persisted): the implicit `if` and `else` ports stay addressable.\n */\ntype ConditionKeys<B> = keyof B extends never ? 'if' | 'else' : Extract<keyof B, string>\ntype RouterKeys<R> = keyof R extends never ? 'route0' : Extract<keyof R, string>\n\n/** A condition: named branches, the last one `else` when there are two or more. */\nexport declare function condition<const B extends Record<string, BranchExpression>>(\n name: string,\n branches: B & ConditionBranches<B>,\n meta?: BlockMeta\n): Block<SpecialOutput<'condition'>> & Branches<ConditionKeys<B>>\n\n/** A router: named routes described for the model. */\nexport declare function router<const R extends Record<string, string | Template>>(\n name: string,\n params: SpecialParams<'router'> & { routes: R },\n meta?: BlockMeta\n): Block<SpecialOutput<'router'>> & Branches<RouterKeys<R>>\n\n/** A function block. `code` is inline (`` js`...` ``) or a code file (`codeFile('./functions/x.js')`). */\nexport declare function fn(\n name: string,\n params: SpecialParams<'fn'> & { code: Template | CodeFileRef | string },\n meta?: BlockMeta\n): Block<SpecialOutput<'fn'>>\n\n/**\n * The inputs of a child workflow by key, each checked against the input its start block\n * declares when `workspace.d.ts` knows the workflow; loose JSON otherwise.\n */\nexport type WorkflowInputMapping<K extends string> = K extends keyof WorkspaceWorkflows\n ? WorkspaceWorkflows[K] extends { inputs: infer I }\n ? { [N in keyof I]?: FieldValue<I[N]> }\n : InputMapping\n : InputMapping\n\n/**\n * Runs a child workflow. A `childWorkflow('key')` checks `inputMapping` against its inputs. Its\n * `result` is the child's output: its first response block's `{ data, status, headers }` (a body\n * field is `result.data.field`), else the output of the last block it ran.\n */\nexport declare function runWorkflow<K extends string = string>(\n name: string,\n params: Omit<SpecialParams<'runWorkflow'>, 'workflowId' | 'inputMapping'> & {\n workflowId: WorkflowRef<K> | Exclude<SpecialParams<'runWorkflow'>['workflowId'], WorkflowRef>\n inputMapping?: WorkflowInputMapping<K>\n },\n meta?: BlockMeta\n): Block<SpecialOutput<'runWorkflow'>>\n\n/**\n * Pauses for a person; the form in `inputFormat` types `submission`. A resumed block also holds\n * each form field at its top level (the runtime copies the submission up, over any output of the\n * same name), so `approval.approved` and `approval.submission.approved` both read it.\n */\nexport declare function human<const F extends InputFields = Record<never, never>>(\n name: string,\n params: SpecialParams<'human'> & { inputFormat?: F },\n meta?: BlockMeta\n): Block<\n Omit<SpecialOutput<'human'>, 'submission' | keyof F> & {\n submission: InputFieldsOutput<F>\n } & InputFieldsOutput<F>\n>\n\n/**\n * A response's body, status and headers: the editor's JSON mode, `body` standing for\n * `{ dataMode: 'json', data }`. An object or array `body` is JSON whose references keep their\n * types; a template or reference is the body text as written.\n */\nexport interface ResponseBody {\n body: JsonWithRefs\n /** HTTP status; 200 when omitted. A template or reference must produce a number. */\n status?: number | RefTo<number> | Template | EnvRef\n /** Response headers by name. */\n headers?: Record<string, Value<string>>\n}\n\n/**\n * Ends the workflow with an API response: `response('Reply', { body: { ok: true }, status: 201 })`\n * (`body` is short for `dataMode: 'json'` with `data`), or the block's own params (`dataMode`,\n * `builderData`, ...) when the body is built field by field.\n */\nexport declare function response(\n name: string,\n params: ResponseBody,\n meta?: BlockMeta\n): Block<SpecialOutput<'response'>>\nexport declare function response(\n name: string,\n params: SpecialParams<'response'>,\n meta?: BlockMeta\n): Block<SpecialOutput<'response'>>\n\n/** Assigns workflow variables. */\nexport declare function setVariables(\n name: string,\n params: SpecialParams<'setVariables'>,\n meta?: BlockMeta\n): Block<SpecialOutput<'setVariables'>>\n\ndeclare const ANNOTATION: unique symbol\n\n/** A canvas note: no edges, no outputs. */\nexport interface Annotation {\n readonly [ANNOTATION]: true\n}\nexport declare function note(\n name: string,\n params: SpecialParams<'note'>,\n meta?: BlockMeta\n): Annotation\n\n// Structured param shapes\n\n/** Type names an input-format field may declare. */\nexport type InputFieldType = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'file[]'\n\n/** A structured input field: its type plus a default value, description or required flag. */\nexport interface InputFieldSpec {\n type: InputFieldType\n value?: JsonWithRefs\n description?: string\n required?: boolean\n}\n\n/** `input-format` fields by name: `{ subject: 'string', amount: { type: 'number', value: 0 } }`. */\nexport type InputFields = Record<string, InputFieldType | InputFieldSpec>\n\ntype InputFieldValue<T> = T extends 'string'\n ? string\n : T extends 'number'\n ? number\n : T extends 'boolean'\n ? boolean\n : T extends 'array'\n ? Json[]\n : T extends 'file[]'\n ? SimFile[]\n : Json\n\n/** The outputs an `input-format` declares. */\nexport type InputFieldsOutput<F> = {\n [K in keyof F]: F[K] extends { type: infer T } ? InputFieldValue<T> : InputFieldValue<F[K]>\n}\n\n/**\n * One `response-format` field as the editor's builder stores it. An `object` or `array` field's\n * `value` may hold nested fields. A response is usually written with `body` instead.\n */\nexport interface ResponseField {\n id?: string\n name: string\n type: string\n value?: JsonWithRefs\n collapsed?: boolean\n}\n\n/** `response-format` fields: `[{ name: 'ok', type: 'boolean', value: true }]`. */\nexport type ResponseFields = ResponseField[]\n\n/** An agent message. */\nexport interface Message {\n role: 'system' | 'user' | 'assistant'\n content: Value<string>\n}\n\n/** One `variables-input` assignment, with any other stored keys kept. */\nexport interface VariableAssignment {\n variableId: VarRef\n value?: JsonWithRefs\n [key: string]: JsonWithRefs | VarRef | undefined\n}\n\n/** Child workflow inputs by name (`input-mapping`, `workflow-input-mapper`). */\nexport type InputMapping = Record<string, JsonWithRefs>\n\n/** An operator a table filter condition or builder rule can use. */\nexport type FilterOperator = LiteralUnion<\n | 'eq'\n | 'ne'\n | 'gt'\n | 'gte'\n | 'lt'\n | 'lte'\n | 'in'\n | 'nin'\n | 'like'\n | 'ilike'\n | 'nlike'\n | 'nilike'\n | 'contains'\n | 'ncontains'\n | 'startsWith'\n | 'endsWith'\n | 'isNull'\n | 'isNotNull'\n | 'isEmpty'\n | 'isNotEmpty'\n>\n\n/** One row of the editor's filter builder, as it stores it. */\nexport interface FilterRule {\n id?: string\n /** How this row joins the rows before it; `and` when omitted. */\n logicalOperator?: 'and' | 'or'\n column: string\n operator: FilterOperator\n value: Value<string | number | boolean>\n collapsed?: boolean\n}\n\n/** A filter-builder value: the editor's rows, `[{ column: 'status', operator: 'eq', value: 'new' }]`. */\nexport type Filter = FilterRule[]\n\n/** One table filter condition: `{ field: 'status', op: 'eq', value: 'new' }`. */\nexport interface TableCondition {\n field: string\n op: FilterOperator\n value?: JsonWithRefs\n}\n\n/**\n * A table predicate: a condition, or an `all` (and) / `any` (or) group of predicates. The\n * `{ status: { $eq: 'new' } }` operator-object grammar is not one: the runtime refuses it.\n */\nexport type TablePredicate = TableCondition | { all: TablePredicate[] } | { any: TablePredicate[] }\n\n/** A table sort by column: `{ createdAt: 'desc' }`. */\nexport type Sort =\n | Record<string, 'asc' | 'desc'>\n | Array<{ column: string; direction: 'asc' | 'desc' }>\n\n/** One knowledge tag filter. */\nexport interface TagFilter {\n tagName: string\n tagValue: Value<string>\n [key: string]: JsonWithRefs\n}\n\n/** One document tag. */\nexport interface DocumentTag {\n tagName: string\n value: Value<string>\n [key: string]: JsonWithRefs\n}\n\n/** One `eval-input` metric. */\nexport interface EvalMetric {\n name: string\n description?: string\n range?: { min: number; max: number }\n [key: string]: JsonWithRefs | undefined\n}\n\n/** One `model-fallback-list` entry. */\nexport interface ModelFallback {\n model: LiteralUnion<Model>\n [key: string]: JsonWithRefs\n}\n\n/**\n * Model ids, generated into `models.d.ts` (which adds one member per model). Kept apart from the\n * block files so a model-list change touches one file.\n */\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface ModelIds {}\nexport type Model = Extract<keyof ModelIds, string>\n\n/** A JSON Schema `responseFormat`, or `{ name, strict, schema }` around one. */\nexport type ResponseFormat = JsonWithRefs\n\ntype Depth = [never, 0, 1, 2, 3, 4]\n\ntype FromSchema<S, D extends number> = [D] extends [never]\n ? Json\n : S extends { enum: readonly (infer E)[] }\n ? E\n : S extends { type: 'object'; properties: infer P }\n ? { [K in keyof P]: FromSchema<P[K], Depth[D]> }\n : S extends { type: 'array'; items: infer I }\n ? FromSchema<I, Depth[D]>[]\n : S extends { type: 'string' }\n ? string\n : S extends { type: 'number' | 'integer' }\n ? number\n : S extends { type: 'boolean' }\n ? boolean\n : Json\n\n/**\n * The outputs a literal `responseFormat` adds, read from its JSON Schema with recursion capped at\n * depth 4. A template or reference adds untyped JSON.\n */\nexport type ResponseFormatOutput<RF> = [RF] extends [undefined]\n ? unknown\n : RF extends { schema: infer S }\n ? FromSchema<S, 4>\n : RF extends { type: 'object'; properties: object }\n ? FromSchema<RF, 4>\n : { [key: string]: Json }\n";
|
|
40992
|
+
var CORE_DTS = "/**\n * The authoring surface for Sim workflows written as TypeScript.\n *\n * Nothing declared here runs. `@sim/workflow-code` compiles a workflow file statically, and every\n * runtime export of this package throws `SimSdkNotExecutable`. These declarations exist so an\n * editor, `tsc` (the type-check command `sim` prints) or an agent can check a workflow file before\n * the compiler sees it.\n *\n * Block builders (`slack.sendMessage`, `agent`, `trigger.gmail.poller`, ...) are not declared here:\n * they are generated from the block catalog into `blocks/{type}.d.ts`, which augment this module.\n * The generic `block(type, name, params)` covers any stored type without a builder.\n *\n * Every workflow file starts with the SDK header line, before any import:\n *\n * ```ts\n * // @sim-sdk 1\n * import { agent, trigger, workflow } from '@sim/workflow-sdk'\n * ```\n *\n * The number is the SDK major version the file is written against. A file without the header is\n * refused with `E_SDK_HEADER`, and one written for a newer major than the server supports with\n * `E_SDK_MAJOR`.\n */\n\n/** Plain JSON. */\nexport type Json = null | boolean | number | string | Json[] | { [key: string]: Json }\n\ndeclare const REF: unique symbol\ndeclare const TEMPLATE: unique symbol\ndeclare const ENV: unique symbol\ndeclare const RESOURCE: unique symbol\ndeclare const TOOL: unique symbol\ndeclare const NODE: unique symbol\ndeclare const CODE_FILE: unique symbol\ndeclare const RAW: unique symbol\ndeclare const UNTYPED: unique symbol\n\n/** Any reference, whatever it points at. */\nexport interface AnyRef {\n readonly [REF]: unknown\n}\n\n/** Marks a reference into untyped JSON, which any param accepts: its value is known only at run time. */\ninterface Untyped {\n readonly [UNTYPED]: true\n}\n\n/**\n * A reference into untyped JSON, where any path is allowed at any depth. An interface rather than\n * `Ref<Json>`, which TypeScript stops resolving after one step (`a.b.c` failed at `c`).\n */\ninterface UntypedRef extends Untyped {\n readonly [REF]: Json\n readonly [key: string]: UntypedRef\n}\n\ntype RefPaths<T> = [Json] extends [T]\n ? Untyped & { readonly [key: string]: UntypedRef }\n : T extends readonly (infer E)[]\n ? { readonly [index: number]: Ref<E>; readonly length: Ref<number> }\n : T extends object\n ? { readonly [K in keyof T]-?: Ref<T[K]> }\n : unknown\n\n/**\n * A typed reference to a block output, compiled to `<blockkey.path>`.\n * Paths map exactly: `.seg`, `['seg']` and `[n]`. Untyped JSON allows any path.\n */\nexport type Ref<T> = { readonly [REF]: T } & RefPaths<T>\n\n/** Text with references in it, written with one of the tags below. */\nexport type Template = string & { readonly [TEMPLATE]: true }\n\n/** A workspace environment variable, compiled to `{{NAME}}`. */\nexport interface EnvRef {\n readonly [ENV]: string\n}\n\n/**\n * What a reference must hold to fill a param of type `T`. A param taking some strings takes any\n * string (an option id computed at run time); `null` (an output a step left empty) fits anywhere.\n */\ntype RefValue<T> = [Extract<T, string>] extends [never] ? T | null : T | string | null\n\n/**\n * A reference that fits a param of type `T`: one whose value has that type, or one into untyped\n * JSON. A whole block is not a value: reference one of its outputs.\n */\nexport type RefTo<T> = ({ readonly [REF]: RefValue<T> } | (AnyRef & Untyped)) & {\n readonly [NODE]?: never\n}\n\n/** A param value: a literal, a reference of a fitting type, a template or an environment variable. */\nexport type Value<T> = T | RefTo<T> | Template | EnvRef\n\n/** JSON whose leaves may be references, templates or environment variables. */\nexport type JsonWithRefs =\n | null\n | boolean\n | number\n | string\n | AnyRef\n | Template\n | EnvRef\n | JsonWithRefs[]\n | { [key: string]: JsonWithRefs }\n\n/** A literal union that still accepts any other string (option ids read from values). */\nexport type LiteralUnion<T extends string> = T | (string & {})\n\n/** A `time-input` value, `HH:MM`. */\nexport type TimeString = `${number}:${number}`\n\n/** A reference written into text: any output or variable, but not a whole block. */\ntype InterpolatedRef = AnyRef & { readonly [NODE]?: never }\n\ntype Interpolation = InterpolatedRef | EnvRef | VarRef | string | number | boolean\n\n/** Text with interpolated references: `` t`New ${cls.category} ticket` ``. */\nexport declare function t(strings: TemplateStringsArray, ...values: Interpolation[]): Template\n/** JavaScript code (condition expressions, inline function code). */\nexport declare const js: typeof t\n/** Python code. */\nexport declare const py: typeof t\n/** Shell code. */\nexport declare const sh: typeof t\n/**\n * JSON text kept verbatim, for bodies an object literal cannot reproduce byte for byte. In a JSON\n * field an object literal is the usual form: a bare reference keeps its value's type (`n: score.value`\n * is a number), and a template is text.\n */\nexport declare const json: typeof t\n/** Markdown text (note content). */\nexport declare const md: typeof t\n\n/** A reference with a non-canonical spelling, such as `ref('Classify.content')`. */\nexport declare function ref(path: string): Ref<Json>\n\n/** A stored value outside the generated type (a legacy option id, say), kept verbatim. */\nexport declare function raw<T = never>(value: unknown): T & { readonly [RAW]: true }\n\n/** A required value that is still missing; compiles to absent, so canvas drafts type-check. */\nexport declare function todo(): never\n\n/**\n * Keeps the value the stored workflow holds for this param, without showing it: the printer writes\n * it for a secret pasted into a password field. Valid only on a param of a block the stored\n * workflow already has (same name and type) and holds a value for; anything else is\n * `E_STORED_VALUE_MISSING`.\n */\nexport declare function stored(): never\n\n/** Function code kept in a file next to the workflow (`.js`, `.py` or `.sh`), stored verbatim. */\nexport interface CodeFileRef {\n readonly [CODE_FILE]: string\n}\nexport declare function codeFile(path: `./${string}`): CodeFileRef\n\n/**\n * Environment variable names known to the workspace. `workspace.d.ts` adds one member per name;\n * until it exists `env` accepts any name.\n */\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceEnv {}\n\nexport declare const env: keyof WorkspaceEnv extends never\n ? { readonly [name: string]: EnvRef }\n : { readonly [K in keyof WorkspaceEnv]: EnvRef }\n\n/**\n * Workspace resources by stable key, filled in by the generated `workspace.d.ts`. Each map's\n * values describe the resource: a table's row type, a credential's provider, a workflow's inputs.\n */\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceTables {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceKnowledgeBases {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceCredentials {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceWorkflows {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceSkills {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceCustomTools {}\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface WorkspaceMcpServers {}\n\ntype KeyOf<M> = keyof M extends never ? string : Extract<keyof M, string>\n\nexport type TableKey = KeyOf<WorkspaceTables>\nexport type KnowledgeBaseKey = KeyOf<WorkspaceKnowledgeBases>\nexport type CredentialKey = KeyOf<WorkspaceCredentials>\nexport type WorkflowKey = KeyOf<WorkspaceWorkflows>\nexport type SkillKey = KeyOf<WorkspaceSkills>\nexport type CustomToolKey = KeyOf<WorkspaceCustomTools>\nexport type McpServerKey = KeyOf<WorkspaceMcpServers>\n/**\n * The tool names of MCP server `K`, as `workspace.d.ts` records them from the server's last\n * listing; any name for a server it could not list or does not know.\n */\nexport type McpToolName<K extends string> = K extends keyof WorkspaceMcpServers\n ? WorkspaceMcpServers[K] extends { tools: infer T extends string }\n ? T\n : string\n : string\n\n/** A workspace resource by stable key, compiled to the resource's internal id. */\nexport interface ResourceRef<Kind extends string, Key extends string = string> {\n readonly [RESOURCE]: Kind\n readonly key: Key\n}\n\n/** A saved credential: `credential('support-slack')`. */\nexport type CredentialRef<Key extends string = string> = ResourceRef<'credential', Key>\n\n/**\n * Keys of the saved credentials for one of `Providers`, as `workspace.d.ts` records each\n * credential's provider; any key until it exists.\n */\nexport type CredentialKeyFor<Providers extends string> = keyof WorkspaceCredentials extends never\n ? string\n : {\n [K in Extract<keyof WorkspaceCredentials, string>]: WorkspaceCredentials[K] extends {\n provider: Providers\n }\n ? K\n : never\n }[Extract<keyof WorkspaceCredentials, string>]\nexport declare function credential<K extends CredentialKey>(key: K): CredentialRef<K>\n\n/**\n * The other form a credential field takes beside `credential('key')`: a credential id produced at\n * run time by a reference, a template or an environment variable, stored in the field's advanced\n * twin (`manualCredential`). Literal text is not one, so a pasted token never type-checks; a\n * literal id the stored workflow already holds prints as `raw('…')`.\n */\nexport type CredentialIdValue = RefTo<string> | Template | EnvRef\n\n/** The columns of a workspace table, or loose JSON when `workspace.d.ts` does not know it. */\nexport type TableColumns<K extends string> = K extends keyof WorkspaceTables\n ? WorkspaceTables[K]\n : { [column: string]: Json }\n/**\n * One row as the table blocks output it: the row id, and its cells keyed by column name under\n * `data` (`row.data.status`). Times are ISO strings.\n */\nexport interface TableRow<K extends string> {\n id: string\n data: TableColumns<K>\n position: number\n createdAt: string\n updatedAt: string\n}\n/**\n * A value written to a field of type `T` (a table cell, a child workflow input): a JSON or JSON\n * array field takes JSON with references in it, and `null` leaves the field empty.\n */\ntype FieldValue<T> = [Json] extends [T]\n ? JsonWithRefs\n : [Json[]] extends [T]\n ? JsonWithRefs\n : Value<T> | null\n\n/** The columns of table `K` every row must hold: those whose cell type does not admit `null`. */\ntype RequiredColumns<K extends keyof WorkspaceTables> = {\n [C in keyof WorkspaceTables[K]]-?: null extends WorkspaceTables[K][C] ? never : C\n}[keyof WorkspaceTables[K]]\n\n/**\n * A whole row, as an insert, an upsert or a batch insert writes it, each value checked against\n * its column's type. A required column must be present and not `null`: the table refuses a row\n * without it (`Missing required field`), and an upsert checks the whole row before it looks for a\n * match.\n */\nexport type TableData<K extends string> = K extends keyof WorkspaceTables\n ? { [C in RequiredColumns<K>]-?: Exclude<FieldValue<WorkspaceTables[K][C]>, null> } & {\n [C in Exclude<keyof WorkspaceTables[K], RequiredColumns<K>>]?: FieldValue<\n WorkspaceTables[K][C]\n >\n }\n : { [column: string]: JsonWithRefs }\n\n/**\n * The cells an update writes, each checked against its column's type. Every column is optional:\n * an update merges these cells over the stored row.\n */\nexport type TableDataPatch<K extends string> = K extends keyof WorkspaceTables\n ? { [C in keyof WorkspaceTables[K]]?: FieldValue<WorkspaceTables[K][C]> }\n : { [column: string]: JsonWithRefs }\n\n/** A workspace table: `table('leads')`. Table block operations live on `table.*`. */\nexport type TableRef<Key extends string = string> = ResourceRef<'table', Key>\nexport declare function table<K extends TableKey>(key: K): TableRef<K>\n\n/** A knowledge base: `knowledgeBase('docs')`. */\nexport type KnowledgeBaseRef<Key extends string = string> = ResourceRef<'knowledge-base', Key>\nexport declare function knowledgeBase<K extends KnowledgeBaseKey>(key: K): KnowledgeBaseRef<K>\n\n/** A workspace skill: `skill('triage')`. */\nexport type SkillRef<Key extends string = string> = ResourceRef<'skill', Key>\nexport declare function skill<K extends SkillKey>(key: K): SkillRef<K>\n\n/** A workspace folder: `folder('reports')`. */\nexport type FolderRef = ResourceRef<'file-folder'>\nexport declare function folder(key: string): FolderRef\n\n/** A workspace file: `file('contracts/acme.pdf')`. File block operations live on `file.*`. */\nexport type FileRef = ResourceRef<'file'>\nexport declare function file(path: string): FileRef\n\n/**\n * A file a file-upload field holds, as the editor stores it: one uploaded in place, or a workspace\n * file chosen by `key` (written `file('path')` when the workspace resolves it).\n */\nexport interface UploadedFile {\n name: string\n path: string\n size?: number\n type?: string\n key?: string | FileRef\n id?: string\n folderPath?: string\n}\n\n/** A file produced at run time (`file` / `file[]` outputs). */\nexport interface SimFile {\n id: string\n name: string\n url: string\n size: number\n type: string\n key: string\n}\n\n// Agent tools\n\n/** One entry of an agent's `tools` list. */\nexport interface Tool {\n readonly [TOOL]: true\n}\n\n/** How the model may use a tool, and the stored tool fields a print carries. */\nexport interface ToolOpts {\n usageControl?: 'auto' | 'force' | 'none'\n usageControlExpression?: string\n title?: string\n /** The stored operation, when the method does not pin it. */\n operation?: string\n toolId?: string\n /** Pair modes of the tool's params, which pick the member the agent reads. */\n modes?: Record<string, 'basic' | 'advanced'>\n customTool?: JsonWithRefs\n operationPolicy?: Json\n /** Unknown stored tool keys, kept verbatim. */\n extra?: Json\n}\n\n/**\n * A workspace custom tool by key, as an agent tool: `customTool('lookup-order')`. A stored tool\n * whose definition was copied into the workflow (and may have drifted from the workspace tool)\n * prints as `raw(tool)` instead.\n */\nexport declare function customTool<K extends CustomToolKey>(key: K, options?: ToolUsage): Tool\n\n/** How the model may use a tool the SDK writes by name (`customTool`, `mcp().tool`, `asTool`). */\nexport type ToolUsage = Pick<ToolOpts, 'usageControl' | 'usageControlExpression'>\n\n/** An MCP tool's arguments and the editor's snapshot of its server. */\nexport interface McpToolOpts extends ToolUsage {\n /** Argument values the workflow fixes; the model fills in the rest. */\n args?: Record<string, JsonWithRefs>\n /**\n * What the editor saved about the server and the tool's input schema when the tool was picked.\n * Shown in the editor; never run.\n */\n snapshot?: { serverName?: string; serverUrl?: string; schema?: Json }\n}\n\n/** An MCP server by key: `mcp('linear')`. */\nexport interface McpServerRef<Key extends string = string> extends ResourceRef<'mcp-server', Key> {\n /** One of the server's tools, as an agent tool: `mcp('linear').tool('create_issue')`. */\n tool(name: McpToolName<Key>, options?: McpToolOpts): Tool\n}\nexport declare function mcp<K extends McpServerKey>(key: K): McpServerRef<K>\n\n// Graph\n\n/** Block-level fields (`BlockState`), written as the third builder argument. */\nexport interface BlockMeta {\n /**\n * A legacy key the display name cannot carry (a `name~n` collision key or a reserved name such\n * as `Loop`). Printed only for such a stored block; apply accepts it only for a key the stored\n * workflow already has, so it can never introduce one.\n */\n key?: string\n /** Stored as `enabled: false`. */\n disabled?: true\n /** Locked: apply refuses any change to this block. */\n locked?: true\n /** Exposes the error port without an `onError` edge. */\n errorPort?: boolean\n /** The block-level advanced toggle (`advancedMode`). */\n advancedMode?: boolean\n /**\n * Runs the block as its trigger (`triggerMode`). Trigger builders (`trigger.gmail.poller`) set\n * it themselves; write it on any other builder only for a block stored in trigger mode.\n */\n triggerMode?: boolean\n /** The stored retry policy, written whole. */\n retry?: BlockRetryConfig\n /**\n * Per branch key of a condition or router, the row's display `title` and any stored fields the\n * SDK has no syntax for (`extra`, plain JSON). `title: null` keeps a row stored with no title,\n * which the executor never takes for `else`.\n */\n branches?: Record<string, { title?: string | null; extra?: Record<string, Json> }>\n /**\n * Stored params that run but have no SDK syntax: a schema-agnostic custom block's inputs, the\n * agent's legacy prompt fields, a container's stored params. Values the block keeps but never\n * runs are not written; apply keeps them from the stored workflow.\n */\n extra?: Record<string, unknown>\n /**\n * A loop or parallel's `block.data` subflow keys the loader could not read as config, kept\n * verbatim (plain JSON).\n */\n subflowData?: Record<string, Json>\n}\n\n/** A block's retry policy, field for field the stored `BlockRetryConfig`. */\nexport interface BlockRetryConfig {\n /** Absent config and `false` mean the same thing: the block runs once. */\n enabled: boolean\n /** Total tries including the first. */\n maxTries: number\n /** Delay between tries. */\n waitBetweenTriesMs: number\n}\n\n/** Anything an edge can point at. */\nexport type Target = Node | Group\n\n/** A block or container in the graph. */\nexport interface Node {\n readonly [NODE]: true\n /** Wires this node's default port to each target. Returns the target, or a group of them. */\n to<const T extends Target[]>(...targets: T): T extends [infer One] ? One : Group\n /** Wires this node's error port to each target. */\n onError(...targets: Target[]): void\n}\n\n/** Several nodes; `.to()` wires every member (fan-in). */\nexport interface Group {\n to(...targets: Target[]): Group\n}\n\n/**\n * What a block outputs when it fails and an error edge leaves it (`x.onError(y)` runs `y` with\n * `x.error`): the failure message `error` on every block, plus the error outputs `E` its catalog\n * entry declares (a Function's `errorMessage`, the thrown message without its line and code). A\n * check refuses each on a block without an error edge, which fails the run instead. An output the\n * block declares under the same name keeps its declared type.\n */\ntype ErrorOutputs<O, E extends string> = {\n readonly [K in 'error' | E as [O] extends [Record<K, unknown>] ? never : K]: Ref<string>\n}\n\n/** A block: a node whose outputs can be referenced, and its error outputs after an `onError` edge. */\nexport type Block<O, E extends string = never> = Node & Ref<O> & ErrorOutputs<O, E>\n\n/** The named ports of a condition or router. */\nexport type Branches<K extends string> = { readonly [P in K]: Node }\n\n/** Trigger builders (`trigger.start`, `trigger.gmail.poller`, ...), generated from the catalog. */\nexport declare namespace trigger {}\n\n/** Builders for hidden legacy block versions (`legacy.slack.send`), generated from the catalog. */\nexport declare namespace legacy {}\n\n/** A raw edge from a handle the SDK has no name for (a legacy or unknown port). */\nexport declare function edge(from: Node, handle: string, to: Target): void\n\n/** Any stored block type without a builder (legacy, unknown or custom), with untyped outputs. */\nexport declare function block(\n type: string,\n name: string,\n params: Record<string, unknown>,\n meta?: BlockMeta\n): Block<Json>\n\n// Workflow and variables\n\nexport type VariableType = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'plain'\n\n/** A workflow variable declared in `workflow(name, { variables })`: its type and initial value. */\nexport interface VariableDeclaration {\n /**\n * The display name, written only when it differs from the key. It must normalize to the key\n * (lowercased, spaces and dots removed), as `'Total Count'` does to `totalcount`.\n */\n name?: string\n type: VariableType\n value: Json\n}\n\n/** The variables a workflow declares, by name. */\nexport type VariableDeclarations = Record<string, VariableDeclaration>\n\ndeclare const VAR: unique symbol\n\n/** A workflow variable, compiled to `<variable.name>`. */\nexport interface VarRef {\n readonly [VAR]: string\n}\n\ntype VariableValue<T extends VariableType> = T extends 'number'\n ? number\n : T extends 'boolean'\n ? boolean\n : T extends 'string' | 'plain'\n ? string\n : Json\n\n/** `vars` in the workflow body: one typed reference per declared variable. */\nexport type VarRefs<V extends VariableDeclarations> = {\n readonly [K in keyof V]: VarRef & Ref<VariableValue<V[K]['type']>>\n}\n\n/**\n * Workflow variables by name, untyped. Prefer the `vars` the `workflow()` body receives, which is\n * typed from the declared variables.\n */\nexport declare const vars: { readonly [name: string]: VarRef & Ref<Json> }\n\ndeclare const WORKFLOW_DEF: unique symbol\n\n/** The default export of a workflow file. */\nexport interface WorkflowDef {\n readonly [WORKFLOW_DEF]: true\n}\n\n/** A child workflow by key, for `runWorkflow` or as an agent tool. */\nexport interface WorkflowRef<Key extends string = string> extends ResourceRef<'workflow', Key> {\n /**\n * The workflow as an agent tool, as the editor's tool picker adds it:\n * `childWorkflow('enrich-lead').asTool()`. A tool with fixed inputs is written `raw(tool)`.\n */\n asTool(options?: ToolUsage): Tool\n}\n\n/**\n * Declares a workflow. The body wires blocks; it never runs. With no description or variables the\n * options may be left out: `workflow('Name', () => { ... })`.\n */\nexport declare function workflow<const V extends VariableDeclarations = Record<never, never>>(\n name: string,\n options: { description?: string; variables?: V },\n body: (scope: { vars: VarRefs<V> }) => void\n): WorkflowDef\nexport declare function workflow(\n name: string,\n body: (scope: { vars: VarRefs<Record<never, never>> }) => void\n): WorkflowDef\n/** A child workflow by key: `childWorkflow('enrich-lead')`. */\nexport declare function childWorkflow<K extends WorkflowKey>(key: K): WorkflowRef<K>\n\n// Containers\n\ntype ItemOf<C> = C extends { readonly [REF]: readonly (infer E)[] }\n ? E\n : C extends readonly (infer E)[]\n ? E\n : Json\n\n/** Inside a loop or parallel body. As a node it is the container's start port: `p.to(first)`. */\nexport interface SubflowScope<Item> extends Node {\n readonly index: Ref<number>\n readonly currentItem: Ref<Item>\n readonly items: Ref<Item[]>\n}\n\n/**\n * A container's outputs, plus its iteration fields by name (`outer.index`), which a block inside\n * the container reads (in a nested container too: an outer loop's index or item). Outside the\n * container only `results` resolves: check reports `W_REF_OUT_OF_SCOPE` on `outer.index` there.\n */\nexport interface SubflowOutput {\n results: Json[]\n index: number\n currentItem: Json\n items: Json[]\n}\n\n/** A loop or parallel container. Its `.to()` wires the port taken after it finishes. */\nexport type Container = Block<SubflowOutput>\n\ntype Collection = AnyRef | Template | Json[] | string\n\nexport declare const loop: {\n for(\n name: string,\n params: { count?: number },\n body: (scope: SubflowScope<never>) => void,\n meta?: BlockMeta\n ): Container\n forEach<const C extends Collection>(\n name: string,\n params: { collection: C },\n body: (scope: SubflowScope<ItemOf<C>>) => void,\n meta?: BlockMeta\n ): Container\n while(\n name: string,\n params: { condition: Template | string },\n body: (scope: SubflowScope<never>) => void,\n meta?: BlockMeta\n ): Container\n doWhile(\n name: string,\n params: { condition?: Template | string; count?: number },\n body: (scope: SubflowScope<never>) => void,\n meta?: BlockMeta\n ): Container\n}\n\nexport declare const parallel: {\n /** A parallel with no stored type, which the loader runs as `count`. */\n (\n name: string,\n params: { count?: number; collection?: Collection; batchSize?: number },\n body: (scope: SubflowScope<Json>) => void,\n meta?: BlockMeta\n ): Container\n count(\n name: string,\n params: { count: number; batchSize?: number },\n body: (scope: SubflowScope<never>) => void,\n meta?: BlockMeta\n ): Container\n collection<const C extends Collection>(\n name: string,\n params: { collection: C; batchSize?: number },\n body: (scope: SubflowScope<ItemOf<C>>) => void,\n meta?: BlockMeta\n ): Container\n}\n\n// Blocks with a source form of their own\n\n/**\n * Params and outputs of the blocks below, generated from the catalog. Each entry is\n * `{ params; output }`, with `errorOutputs` when the block declares any; without generated types\n * the params are loose.\n */\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface SpecialBuilderTypes {}\n\ntype SpecialParams<K extends string> = K extends keyof SpecialBuilderTypes\n ? SpecialBuilderTypes[K] extends { params: infer P }\n ? P\n : never\n : Record<string, unknown>\n\ntype SpecialOutput<K extends string> = K extends keyof SpecialBuilderTypes\n ? SpecialBuilderTypes[K] extends { output: infer O }\n ? O\n : never\n : Json\n\n/** The error outputs a special builder's block declares; a builder whose block has any passes them. */\ntype SpecialErrorOutputs<K extends string> = K extends keyof SpecialBuilderTypes\n ? SpecialBuilderTypes[K] extends { errorOutputs: infer E extends string }\n ? E\n : never\n : never\n\n/** A condition expression, or `true` for the `else` branch. */\nexport type BranchExpression = Template | string | true\n\ndeclare const ONLY_ELSE: unique symbol\n\n/** What a branch other than `else` written as `true` must be, which no value is: the error names it. */\ninterface OnlyElseMayBeTrue {\n readonly [ONLY_ELSE]: true\n}\n\n/**\n * A condition's branches: every key holds an expression, and only `else` may be `true`. Another\n * branch written as `true` is checked against {@link OnlyElseMayBeTrue}, so the error names that\n * branch alone.\n */\ntype ConditionBranches<B> = {\n [K in keyof B]: K extends 'else'\n ? BranchExpression\n : B[K] extends true\n ? OnlyElseMayBeTrue\n : Template | string\n}\n\n/**\n * Keys of a condition written with no rows (`condition('Name', {})`, the source form of rows\n * that were never persisted): the implicit `if` and `else` ports stay addressable.\n */\ntype ConditionKeys<B> = keyof B extends never ? 'if' | 'else' : Extract<keyof B, string>\ntype RouterKeys<R> = keyof R extends never ? 'route0' : Extract<keyof R, string>\n\n/** A condition: named branches, the last one `else` when there are two or more. */\nexport declare function condition<const B extends Record<string, BranchExpression>>(\n name: string,\n branches: B & ConditionBranches<B>,\n meta?: BlockMeta\n): Block<SpecialOutput<'condition'>> & Branches<ConditionKeys<B>>\n\n/** A router: named routes described for the model. */\nexport declare function router<const R extends Record<string, string | Template>>(\n name: string,\n params: SpecialParams<'router'> & { routes: R },\n meta?: BlockMeta\n): Block<SpecialOutput<'router'>> & Branches<RouterKeys<R>>\n\n/** A function block. `code` is inline (`` js`...` ``) or a code file (`codeFile('./functions/x.js')`). */\nexport declare function fn(\n name: string,\n params: SpecialParams<'fn'> & { code: Template | CodeFileRef | string },\n meta?: BlockMeta\n): Block<SpecialOutput<'fn'>, SpecialErrorOutputs<'fn'>>\n\n/**\n * The inputs of a child workflow by key, each checked against the input its start block\n * declares when `workspace.d.ts` knows the workflow; loose JSON otherwise.\n */\nexport type WorkflowInputMapping<K extends string> = K extends keyof WorkspaceWorkflows\n ? WorkspaceWorkflows[K] extends { inputs: infer I }\n ? { [N in keyof I]?: FieldValue<I[N]> }\n : InputMapping\n : InputMapping\n\n/**\n * Runs a child workflow. A `childWorkflow('key')` checks `inputMapping` against its inputs. Its\n * `result` is the child's output: its first response block's `{ data, status, headers }` (a body\n * field is `result.data.field`), else the output of the last block it ran.\n */\nexport declare function runWorkflow<K extends string = string>(\n name: string,\n params: Omit<SpecialParams<'runWorkflow'>, 'workflowId' | 'inputMapping'> & {\n workflowId: WorkflowRef<K> | Exclude<SpecialParams<'runWorkflow'>['workflowId'], WorkflowRef>\n inputMapping?: WorkflowInputMapping<K>\n },\n meta?: BlockMeta\n): Block<SpecialOutput<'runWorkflow'>>\n\n/**\n * Pauses for a person; the form in `inputFormat` types `submission`. A resumed block also holds\n * each form field at its top level (the runtime copies the submission up, over any output of the\n * same name), so `approval.approved` and `approval.submission.approved` both read it.\n */\nexport declare function human<const F extends InputFields = Record<never, never>>(\n name: string,\n params: SpecialParams<'human'> & { inputFormat?: F },\n meta?: BlockMeta\n): Block<\n Omit<SpecialOutput<'human'>, 'submission' | keyof F> & {\n submission: InputFieldsOutput<F>\n } & InputFieldsOutput<F>\n>\n\n/**\n * A response's body, status and headers: the editor's JSON mode, `body` standing for\n * `{ dataMode: 'json', data }`. An object or array `body` is JSON whose references keep their\n * types; a template or reference is the body text as written.\n */\nexport interface ResponseBody {\n body: JsonWithRefs\n /** HTTP status; 200 when omitted. A template or reference must produce a number. */\n status?: number | RefTo<number> | Template | EnvRef\n /** Response headers by name. */\n headers?: Record<string, Value<string>>\n}\n\n/**\n * Ends the workflow with an API response: `response('Reply', { body: { ok: true }, status: 201 })`\n * (`body` is short for `dataMode: 'json'` with `data`), or the block's own params (`dataMode`,\n * `builderData`, ...) when the body is built field by field.\n */\nexport declare function response(\n name: string,\n params: ResponseBody,\n meta?: BlockMeta\n): Block<SpecialOutput<'response'>>\nexport declare function response(\n name: string,\n params: SpecialParams<'response'>,\n meta?: BlockMeta\n): Block<SpecialOutput<'response'>>\n\n/** Assigns workflow variables. */\nexport declare function setVariables(\n name: string,\n params: SpecialParams<'setVariables'>,\n meta?: BlockMeta\n): Block<SpecialOutput<'setVariables'>>\n\ndeclare const ANNOTATION: unique symbol\n\n/** A canvas note: no edges, no outputs. */\nexport interface Annotation {\n readonly [ANNOTATION]: true\n}\nexport declare function note(\n name: string,\n params: SpecialParams<'note'>,\n meta?: BlockMeta\n): Annotation\n\n// Structured param shapes\n\n/** Type names an input-format field may declare. */\nexport type InputFieldType = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'file[]'\n\n/** A structured input field: its type plus a default value, description or required flag. */\nexport interface InputFieldSpec {\n type: InputFieldType\n value?: JsonWithRefs\n description?: string\n required?: boolean\n}\n\n/** `input-format` fields by name: `{ subject: 'string', amount: { type: 'number', value: 0 } }`. */\nexport type InputFields = Record<string, InputFieldType | InputFieldSpec>\n\ntype InputFieldValue<T> = T extends 'string'\n ? string\n : T extends 'number'\n ? number\n : T extends 'boolean'\n ? boolean\n : T extends 'array'\n ? Json[]\n : T extends 'file[]'\n ? SimFile[]\n : Json\n\n/** The outputs an `input-format` declares. */\nexport type InputFieldsOutput<F> = {\n [K in keyof F]: F[K] extends { type: infer T } ? InputFieldValue<T> : InputFieldValue<F[K]>\n}\n\n/**\n * One `response-format` field as the editor's builder stores it. An `object` or `array` field's\n * `value` may hold nested fields. A response is usually written with `body` instead.\n */\nexport interface ResponseField {\n id?: string\n name: string\n type: string\n value?: JsonWithRefs\n collapsed?: boolean\n}\n\n/** `response-format` fields: `[{ name: 'ok', type: 'boolean', value: true }]`. */\nexport type ResponseFields = ResponseField[]\n\n/** An agent message. */\nexport interface Message {\n role: 'system' | 'user' | 'assistant'\n content: Value<string>\n}\n\n/** One `variables-input` assignment, with any other stored keys kept. */\nexport interface VariableAssignment {\n variableId: VarRef\n value?: JsonWithRefs\n [key: string]: JsonWithRefs | VarRef | undefined\n}\n\n/** Child workflow inputs by name (`input-mapping`, `workflow-input-mapper`). */\nexport type InputMapping = Record<string, JsonWithRefs>\n\n/** An operator a table filter condition or builder rule can use. */\nexport type FilterOperator = LiteralUnion<\n | 'eq'\n | 'ne'\n | 'gt'\n | 'gte'\n | 'lt'\n | 'lte'\n | 'in'\n | 'nin'\n | 'like'\n | 'ilike'\n | 'nlike'\n | 'nilike'\n | 'contains'\n | 'ncontains'\n | 'startsWith'\n | 'endsWith'\n | 'isNull'\n | 'isNotNull'\n | 'isEmpty'\n | 'isNotEmpty'\n>\n\n/** One row of the editor's filter builder, as it stores it. */\nexport interface FilterRule {\n id?: string\n /** How this row joins the rows before it; `and` when omitted. */\n logicalOperator?: 'and' | 'or'\n column: string\n operator: FilterOperator\n value: Value<string | number | boolean>\n collapsed?: boolean\n}\n\n/** A filter-builder value: the editor's rows, `[{ column: 'status', operator: 'eq', value: 'new' }]`. */\nexport type Filter = FilterRule[]\n\n/** One table filter condition: `{ field: 'status', op: 'eq', value: 'new' }`. */\nexport interface TableCondition {\n field: string\n op: FilterOperator\n value?: JsonWithRefs\n}\n\n/**\n * A table predicate: a condition, or an `all` (and) / `any` (or) group of predicates. The\n * `{ status: { $eq: 'new' } }` operator-object grammar is not one: the runtime refuses it.\n */\nexport type TablePredicate = TableCondition | { all: TablePredicate[] } | { any: TablePredicate[] }\n\n/** A table sort by column: `{ createdAt: 'desc' }`. */\nexport type Sort =\n | Record<string, 'asc' | 'desc'>\n | Array<{ column: string; direction: 'asc' | 'desc' }>\n\n/** One knowledge tag filter. */\nexport interface TagFilter {\n tagName: string\n tagValue: Value<string>\n [key: string]: JsonWithRefs\n}\n\n/** One document tag. */\nexport interface DocumentTag {\n tagName: string\n value: Value<string>\n [key: string]: JsonWithRefs\n}\n\n/** One `eval-input` metric. */\nexport interface EvalMetric {\n name: string\n description?: string\n range?: { min: number; max: number }\n [key: string]: JsonWithRefs | undefined\n}\n\n/** One `model-fallback-list` entry. */\nexport interface ModelFallback {\n model: LiteralUnion<Model>\n [key: string]: JsonWithRefs\n}\n\n/**\n * Model ids, generated into `models.d.ts` (which adds one member per model). Kept apart from the\n * block files so a model-list change touches one file.\n */\n// biome-ignore lint/suspicious/noEmptyInterface: an empty interface is the merge target generated declarations augment\nexport interface ModelIds {}\nexport type Model = Extract<keyof ModelIds, string>\n\n/** A JSON Schema `responseFormat`, or `{ name, strict, schema }` around one. */\nexport type ResponseFormat = JsonWithRefs\n\ntype Depth = [never, 0, 1, 2, 3, 4]\n\ntype FromSchema<S, D extends number> = [D] extends [never]\n ? Json\n : S extends { enum: readonly (infer E)[] }\n ? E\n : S extends { type: 'object'; properties: infer P }\n ? { [K in keyof P]: FromSchema<P[K], Depth[D]> }\n : S extends { type: 'array'; items: infer I }\n ? FromSchema<I, Depth[D]>[]\n : S extends { type: 'string' }\n ? string\n : S extends { type: 'number' | 'integer' }\n ? number\n : S extends { type: 'boolean' }\n ? boolean\n : Json\n\n/**\n * The outputs a literal `responseFormat` adds, read from its JSON Schema with recursion capped at\n * depth 4. A template or reference adds untyped JSON.\n */\nexport type ResponseFormatOutput<RF> = [RF] extends [undefined]\n ? unknown\n : RF extends { schema: infer S }\n ? FromSchema<S, 4>\n : RF extends { type: 'object'; properties: object }\n ? FromSchema<RF, 4>\n : { [key: string]: Json }\n";
|
|
40986
40993
|
// ../workflow-code/src/anchors.ts
|
|
40987
40994
|
function portKey(port) {
|
|
40988
40995
|
switch (port.kind) {
|
|
@@ -41825,6 +41832,13 @@ function blockOutputSchemas(catalog, block, options) {
|
|
|
41825
41832
|
const trigger = triggerId === undefined ? undefined : catalogTrigger(catalog, triggerId);
|
|
41826
41833
|
return trigger ? trigger.outputs : block.outputs;
|
|
41827
41834
|
}
|
|
41835
|
+
function isErrorOutputName(block, name) {
|
|
41836
|
+
return name === "error" || (block?.errorOutputs?.includes(name) ?? false);
|
|
41837
|
+
}
|
|
41838
|
+
function errorOutputOf(block, segments) {
|
|
41839
|
+
const [first] = segments;
|
|
41840
|
+
return segments.length === 1 && first?.kind === "name" && isErrorOutputName(block, first.name) ? first.name : null;
|
|
41841
|
+
}
|
|
41828
41842
|
function builderOutputSchemas(catalog, block, builder) {
|
|
41829
41843
|
return blockOutputSchemas(catalog, block, {
|
|
41830
41844
|
triggerMode: builder?.triggerMode === true,
|
|
@@ -42815,10 +42829,7 @@ function refValueKind(token, scope) {
|
|
|
42815
42829
|
if (type !== undefined)
|
|
42816
42830
|
return type === "string" ? "string" : "typed";
|
|
42817
42831
|
}
|
|
42818
|
-
|
|
42819
|
-
if (segments.length === 1 && first?.kind === "name" && first.name === "error")
|
|
42820
|
-
return "string";
|
|
42821
|
-
return "untyped";
|
|
42832
|
+
return errorOutputOf(declared, segments) ? "string" : "untyped";
|
|
42822
42833
|
}
|
|
42823
42834
|
function storedValue(block, id) {
|
|
42824
42835
|
const param = getOwn(block.params, id);
|
|
@@ -44642,21 +44653,19 @@ function checkOutputPath(ctx, at, target, segments, blockKey) {
|
|
|
44642
44653
|
const outputs = builderOutputSchemas(ctx.catalog, block, builder);
|
|
44643
44654
|
if (outputKnown(outputs, segments))
|
|
44644
44655
|
return;
|
|
44645
|
-
|
|
44646
|
-
|
|
44656
|
+
const errorOutput = errorOutputOf(block, segments);
|
|
44657
|
+
if (errorOutput) {
|
|
44658
|
+
ctx.errorOutputRefs.push({ at, target, blockKey, output: errorOutput });
|
|
44647
44659
|
return;
|
|
44648
44660
|
}
|
|
44649
44661
|
ctx.reporter.report("W_UNKNOWN_OUTPUT_PATH", `${target.name} has no output ${formatStoredPath(segments)}.`, at, { hint: () => unknownOutputHint(outputs, segments), blockKey });
|
|
44650
44662
|
}
|
|
44651
|
-
function isErrorOutput(segments) {
|
|
44652
|
-
return segments.length === 1 && segments[0].kind === "name" && segments[0].name === "error";
|
|
44653
|
-
}
|
|
44654
44663
|
function checkErrorOutputRefs(ctx, erroring) {
|
|
44655
|
-
for (const { at, target, blockKey } of ctx.errorOutputRefs) {
|
|
44664
|
+
for (const { at, target, blockKey, output } of ctx.errorOutputRefs) {
|
|
44656
44665
|
if (erroring.has(target.key))
|
|
44657
44666
|
continue;
|
|
44658
|
-
ctx.reporter.report("W_OUTPUT_PATH_UNDECLARED", `${target.name} has no output
|
|
44659
|
-
hint: `Wire ${target.ident ?? "the block"}.onError(<handler>) and read ${target.ident ?? "it"}
|
|
44667
|
+
ctx.reporter.report("W_OUTPUT_PATH_UNDECLARED", `${target.name} has no output ${output}: only a block with an error edge outputs its failure message.`, at, {
|
|
44668
|
+
hint: `Wire ${target.ident ?? "the block"}.onError(<handler>) and read ${target.ident ?? "it"}.${output} in the handler.`,
|
|
44660
44669
|
blockKey
|
|
44661
44670
|
});
|
|
44662
44671
|
}
|
|
@@ -44694,8 +44703,9 @@ function checkDynamicOutputRefs(ctx, blockOf) {
|
|
|
44694
44703
|
const outputs = builderOutputSchemas(ctx.catalog, block, builder);
|
|
44695
44704
|
if (outputKnown(outputs, segments))
|
|
44696
44705
|
continue;
|
|
44697
|
-
|
|
44698
|
-
|
|
44706
|
+
const errorOutput = errorOutputOf(block, segments);
|
|
44707
|
+
if (errorOutput) {
|
|
44708
|
+
ctx.errorOutputRefs.push({ at, target, blockKey, output: errorOutput });
|
|
44699
44709
|
continue;
|
|
44700
44710
|
}
|
|
44701
44711
|
const known = [...fields, ...Object.keys(outputs)];
|
|
@@ -51538,7 +51548,7 @@ var RUNTIME_SEMANTICS = [
|
|
|
51538
51548
|
"## How it runs",
|
|
51539
51549
|
"",
|
|
51540
51550
|
"- **Two retries, nested.** An `api` block's `retries`, `retryDelayMs` and `retryMaxDelayMs` repeat the HTTP request inside one run of the block: only after a timeout, a connection reset, a 429 or a 5xx (a host that does not resolve or refuses the connection fails at once), only for GET, HEAD, PUT and DELETE unless `retryNonIdempotent: true`, with jittered exponential backoff capped at `retryMaxDelayMs` (a `Retry-After` beyond the cap ends the retries). `meta.retry` (`{ enabled, maxTries, waitBetweenTriesMs }`) reruns the whole block, request retries included, after any failure but a stop or a failed child workflow; `maxTries` counts every try. So `retries: 2` under `maxTries: 3` sends up to 9 requests. Only the last try's failure reaches `onError`. Triggers and `human` never retry.",
|
|
51541
|
-
"- **`onError`.** `x.onError(y)` makes a failure of `x` an output, `{ error: '<message>' }`, and runs `y` instead of `x`'s other targets; the run goes on. `y` reads the message as `x.error` (only a block with an `onError` edge has it). In a loop or parallel body (`y` must be in the same body) the iteration ends normally and the loop moves to the next item, with that error output as `x`'s entry for the iteration. Without `onError`, a failure in any iteration fails the run and stops the loop.",
|
|
51551
|
+
"- **`onError`.** `x.onError(y)` makes a failure of `x` an output, `{ error: '<message>' }`, and runs `y` instead of `x`'s other targets; the run goes on. `y` reads the message as `x.error` (only a block with an `onError` edge has it); a Function's `error` leads with the line and code that threw, and its `x.errorMessage` is the thrown message alone, the one to reply with (a failure that throws nothing, such as a timeout, repeats `error` there). In a loop or parallel body (`y` must be in the same body) the iteration ends normally and the loop moves to the next item, with that error output as `x`'s entry for the iteration. Without `onError`, a failure in any iteration fails the run and stops the loop.",
|
|
51542
51552
|
"- **Joins run once.** A block with several incoming edges runs once, after every one of them has fired or been ruled out (a condition or router branch not taken, the normal edge of a block that failed into `onError`). `a.to(join)`, `b.to(join)`, `c.to(join)` wait for all three; behind a condition only the taken branch fires, and the join runs once after it. A block never runs once per incoming branch. A reference to a block that did not run (on the branch not taken) resolves empty: `null` as a whole value, in function code or in a condition, `''` inside text.",
|
|
51543
51553
|
"- **Loop and parallel results.** `x.results` holds one entry per iteration (a parallel: per branch), and each entry is the list of outputs of the body blocks that ran in it, in the order they finished. With one block in the body its output is `x.results[i][0]`; `x.results.flat()` lists every output.",
|
|
51544
51554
|
"- **Outputs in function code.** In `fn` code, `${a.content}` inside js`` is not spliced in as text: it becomes an expression that evaluates to the output's value, a string as a string and an object as an object. Write it where an expression goes (`const reply = ${a.content}`, `[${a.content}, ${b.content}]`) and never wrap it in quotes. Written inside a JavaScript string or template literal it splices in as JSON, quotes included (`'Hi ${a.content}'` gives `Hi \"hello\"`). Python code works the same way.",
|
|
@@ -51842,6 +51852,7 @@ function builderTypes(catalog, entry) {
|
|
|
51842
51852
|
};
|
|
51843
51853
|
const outputRef = `${outputName}${outputGeneric ? genericArgs : ""}`;
|
|
51844
51854
|
const outputType = plan?.outputExtension ? `Omit<${outputRef}, keyof ${plan.outputExtension}> & ${plan.outputExtension}` : outputRef;
|
|
51855
|
+
const errorOutputs = block.errorOutputs?.length ? union(block.errorOutputs.map(literal)) : "";
|
|
51845
51856
|
const method = entry.path[entry.path.length - 1];
|
|
51846
51857
|
const label = entry.builder.operation ? operationLabel(block, entry.builder.operation) : undefined;
|
|
51847
51858
|
const jsdocSummary = [
|
|
@@ -51851,13 +51862,13 @@ function builderTypes(catalog, entry) {
|
|
|
51851
51862
|
].filter(Boolean).join(" ");
|
|
51852
51863
|
const signature = entry.special ? [] : [
|
|
51853
51864
|
...jsdoc([jsdocSummary], ""),
|
|
51854
|
-
`export function ${method}${typeParameterList(plan, true)}(name: string, params: ${paramsName}${genericArgs}, meta?: BlockMeta): Block<${outputType}>`
|
|
51865
|
+
`export function ${method}${typeParameterList(plan, true)}(name: string, params: ${paramsName}${genericArgs}, meta?: BlockMeta): Block<${outputType}${errorOutputs ? `, ${errorOutputs}` : ""}>`
|
|
51855
51866
|
];
|
|
51856
51867
|
const tool = !entry.special && hasToolForm(entry.key, entry.builder, block) ? [
|
|
51857
51868
|
...jsdoc([`${jsdocSummary}, as an agent tool`], ""),
|
|
51858
51869
|
`export function ${method}(params?: Partial<${paramsName}>, options?: ToolOpts): Tool`
|
|
51859
51870
|
] : null;
|
|
51860
|
-
const special = entry.special ? `${entry.key}: { params: ${paramsName}; output: ${outputName} }` : null;
|
|
51871
|
+
const special = entry.special ? `${entry.key}: { params: ${paramsName}; output: ${outputName}${errorOutputs ? `; errorOutputs: ${errorOutputs}` : ""} }` : null;
|
|
51861
51872
|
return {
|
|
51862
51873
|
params: paramsDeclaration,
|
|
51863
51874
|
output,
|
|
@@ -56712,12 +56723,12 @@ var MAX_SNIPPET_BYTES = 4096;
|
|
|
56712
56723
|
var PARAMS_COMMAND = "sim workflows source params";
|
|
56713
56724
|
function sharedRules(group, extraRenames = "") {
|
|
56714
56725
|
return `- **Identity**: a block is its entry in \`${SOURCE_LOCK_FILE}\`, which binds it by its const name or its display name. Change the display name (first argument) freely: references through the const follow it, and the apply rewrites every \`$ref.<old key>\` and \`<old key.…>\` to the new key and reprints the files (don't hand-edit them). Renaming the const too keeps it when settings, neighbours or references still tie it to the old block; otherwise the apply refuses a delete (\`E_APPLY_BLOCK_DELETE\`). Safest: keep the const.
|
|
56715
|
-
- **References**: in \`${SOURCE_ENTRY_FILE}\` read an output as \`x.content\`, a loop or parallel item as \`p.currentItem\` (\`p.index\`), text as \`\` t\`…\` \`\`, env as \`env.NAME\`. In a function
|
|
56726
|
+
- **References**: in \`${SOURCE_ENTRY_FILE}\` read an output as \`x.content\`, a loop or parallel item as \`p.currentItem\` (\`p.index\`), text as \`\` t\`…\` \`\`, env as \`env.NAME\`. In a function file (\`codeFile('./functions/x.js')\`) read an output as \`$ref.<key>.<path>\`, the key: the display name lowercased, whitespace and dots removed ("Triage Agent" → \`$ref.triageagent.content\`); in a loop body \`$ref.loop.currentItem\` / \`$ref.loop.index\`, in a parallel \`$ref.parallel.currentItem\` / \`$ref.parallel.index\`; env as \`$env.NAME\`. In \`.py\`/\`.sh\` files write \`<key.path>\` and \`{{NAME}}\`, not \`$ref\`/\`$env\`. Read an index or item only inside its container (\`E_APPLY_REF_OUT_OF_SCOPE\`), after it its \`.results\`. A \`$ref\` naming no block is an error in a function file you edited (\`E_APPLY_UNRESOLVED_REF\`).
|
|
56716
56727
|
- **Renames**: one variable per apply (two at once read as a delete and an add).${extraRenames}
|
|
56717
|
-
- **Look up a builder**: \`${PARAMS_COMMAND} <builder>\` (\`agent\`, \`trigger.schedule\`; a namespace like \`gmail\` lists
|
|
56728
|
+
- **Look up a builder**: \`${PARAMS_COMMAND} <builder>\` (\`agent\`, \`trigger.schedule\`; a namespace like \`gmail\` lists them), offline.
|
|
56718
56729
|
- **Credentials**: \`sim credentials connect <provider> --name "<Name>"\`, give the owner its link, then \`credential('<key>')\` (\`sim workflows source resources\`).
|
|
56719
|
-
- **Failures**: \`x.onError(y)\` runs \`y\` when \`x\` fails, reading the message as \`x.error
|
|
56720
|
-
- **Run and debug**: \`sim workflows run <workflowId> --manual --input '{…}'\` runs the saved draft
|
|
56730
|
+
- **Failures**: \`x.onError(y)\` runs \`y\` when \`x\` fails, reading the message as \`x.error\` (a Function's \`x.errorMessage\` drops the line and code: reply with it). Retry is block meta (third argument): \`agent('Name', {…}, { retry: { enabled: true, maxTries: 3, waitBetweenTriesMs: 2000 } })\`. Each replying branch needs its own \`response\`.
|
|
56731
|
+
- **Run and debug**: \`sim workflows run <workflowId> --manual --input '{…}'\` runs the saved draft (without it, the deployed version). Runs write real data (rows, emails): use test resources. With \`--dir <the workflow's folder>\`, a failed run names the failing file and line; then \`sim logs get <runId> --trace --no-include-workflow-state\` (spans hold resolved inputs).
|
|
56721
56732
|
- **Exit codes**: 0 ok, 1 errors, ${SOURCE_STALE_EXIT_CODE} stale (\`${group} get --dir <fresh dir>\`, redo the edit there), ${RATE_LIMITED_EXIT_CODE} rate limited, ${SOURCE_BUSY_EXIT_CODE} busy, ${SOURCE_LOCAL_CHANGES_EXIT_CODE}/${SOURCE_DRIFT_EXIT_CODE} \`status\`: your edits / the server changed. Every code: \`${SOURCE_AGENTS_FILE}\`.`;
|
|
56722
56733
|
}
|
|
56723
56734
|
var WORKFLOW_PRIMER = `# Sim workflow source: primer
|