Skip to content

Commit d40a432

Browse files
committed
improvement(workflows): reuse the shared block label, drop the dead flag-hidden option, and align the splice docs
1 parent 733a67e commit d40a432

9 files changed

Lines changed: 33 additions & 21 deletions

File tree

‎apps/docs/content/docs/workflows/code/syntax.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ A secret is never printed. A literal value in a password field prints as `stored
196196

197197
### JSON fields
198198

199-
A field that holds JSON text, such as `responseFormat`, a table row's `data` or a response body, takes an object or array literal and stores it as formatted JSON. Each bare reference inside is quoted when the output is a string and left bare otherwise, because the run splices a string raw and any other value as JSON. A Function's `result`, or a field of it, has the type its JavaScript certainly returns there (a string literal, `String(…)`, `.toISOString().slice(…)` and the like are text; arithmetic, comparisons and literals are not); a Function `result` or an API `data` whose code or response may be text is untyped unless the code says. A reference no output type is known for is stored bare with `W_JSON_REF_UNTYPED`. A template is a JSON string, which is how a value becomes text on purpose. `source get` prints a stored quoted reference as the bare reference only when a declaration (the catalog, a variable's type, an input or response format) types it a string; one typed only by what a Function's code or a child workflow returns prints as ``t`${ref}` ``, so editing that code never changes how a field that reads it is stored. A resource helper inside the literal is `E_UNSUPPORTED_SYNTAX`.
199+
A field that holds JSON text, such as `responseFormat`, a table row's `data` or a response body, takes an object or array literal and stores it as formatted JSON. Each bare reference inside is quoted when the output is a string and left bare otherwise, because the run splices a bare string as JSON when it reads as JSON (`12345` would become a number) and quoted text always as text. A Function's `result`, or a field of it, has the type its JavaScript certainly returns there (a string literal, `String(…)`, `.toISOString().slice(…)` and the like are text; arithmetic, comparisons and literals are not); a Function `result` or an API `data` whose code or response may be text is untyped unless the code says. A reference no output type is known for is stored bare with `W_JSON_REF_UNTYPED`. A template is a JSON string, which is how a value becomes text on purpose. `source get` prints a stored quoted reference as the bare reference only when a declaration (the catalog, a variable's type, an input or response format) types it a string; one typed only by what a Function's code or a child workflow returns prints as ``t`${ref}` ``, so editing that code never changes how a field that reads it is stored. A resource helper inside the literal is `E_UNSUPPORTED_SYNTAX`.
200200

201201
### Input formats and tools
202202

‎apps/sim/lib/workflows/application/apply-workflow-operations.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
type ValidationError,
4949
} from '@/lib/workflows/editing/types'
5050
import { preValidateCredentialInputs } from '@/lib/workflows/editing/validation'
51+
import { quotedBlockLabel } from '@/lib/workflows/labels'
5152
import { assertNoWithheldBlockType } from '@/lib/workflows/persistence/block-access-guard'
5253
import { prepareWorkflowStateForPersistence } from '@/lib/workflows/persistence/prepare-state'
5354
import {
@@ -183,10 +184,10 @@ function applyBlockEnabledChanges(
183184
*/
184185
function describeRemovedEdges(
185186
removedEdges: readonly RemovedEdge[],
186-
blocks: Record<string, { name?: string }>
187+
nameOf: (blockId: string) => string | undefined
187188
): string[] {
188189
if (removedEdges.length === 0) return []
189-
const label = (blockId: string) => `"${blocks[blockId]?.name ?? blockId}"`
190+
const label = (blockId: string) => quotedBlockLabel(blockId, nameOf(blockId))
190191
const edges = removedEdges.map(
191192
(edge) =>
192193
`${label(edge.source)} -> ${label(edge.target)} (${edge.sourceHandle}): ${edge.reason}`
@@ -363,10 +364,11 @@ export const applyWorkflowOperations = defineAuthorizedWorkflowUseCase({
363364
* the findings exist; the findings themselves stay only in `lint`.
364365
*/
365366
const lintWarnings = hasWorkflowLintIssues(lint) ? [summarizeWorkflowLintIssues(lint)] : []
366-
const removedEdgeWarnings = describeRemovedEdges(removedEdges, {
367-
...asGraph(baseGraph).blocks,
368-
...graph.blocks,
369-
})
367+
const storedBlocks = asGraph(baseGraph).blocks
368+
const removedEdgeWarnings = describeRemovedEdges(
369+
removedEdges,
370+
(blockId) => graph.blocks[blockId]?.name ?? storedBlocks?.[blockId]?.name
371+
)
370372

371373
/**
372374
* A dry run still runs the whole engine — operations are applied, refusals

‎apps/sim/lib/workflows/editing/engine.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ export function applyOperationsToWorkflowState(
303303
// edge a move left crossing scopes is the move's documented effect, not a refusal.
304304
const { refusedEdgeIds, removedEdges } = removeInvalidScopeEdges(
305305
modifiedState,
306-
new Set(toArray<{ id: string }>(workflowState.edges).map((edge) => edge.id)),
306+
toArray<{ id: string }>(workflowState.edges),
307307
skippedItems
308308
)
309309
for (const edgeId of refusedEdgeIds) {
@@ -490,11 +490,14 @@ function resolvePendingConnections(
490490
*/
491491
function removeInvalidScopeEdges(
492492
modifiedState: any,
493-
storedEdgeIds: ReadonlySet<string>,
493+
storedEdges: readonly { id: string }[],
494494
skippedItems: SkippedItem[]
495495
): { refusedEdgeIds: string[]; removedEdges: RemovedEdge[] } {
496496
const { valid, dropped } = validateEdges(modifiedState.edges || [], modifiedState.blocks || {})
497497
modifiedState.edges = valid
498+
if (dropped.length === 0) return { refusedEdgeIds: [], removedEdges: [] }
499+
500+
const storedEdgeIds = new Set(storedEdges.map((edge) => edge.id))
498501

499502
const refusedEdgeIds: string[] = []
500503
const removedEdges: RemovedEdge[] = []

‎apps/sim/lib/workflows/editing/types.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,6 @@ export interface EdgeHandleValidationResult {
153153
normalizedHandle?: string
154154
}
155155

156-
/**
157-
* Result of applying operations to workflow state
158-
*/
159156
/** A stored edge the batch's moves left invalid, which the apply removed rather than refused. */
160157
export interface RemovedEdge {
161158
id: string
@@ -165,6 +162,9 @@ export interface RemovedEdge {
165162
reason: string
166163
}
167164

165+
/**
166+
* Result of applying operations to workflow state
167+
*/
168168
export interface ApplyOperationsResult {
169169
state: any
170170
validationErrors: ValidationError[]

‎packages/sim-cli/src/contract/types.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,6 @@ export interface FlagSpec {
173173
* owns that instead.
174174
*/
175175
omit?: boolean
176-
/** Accept and send this generated field, but hide its low-level flag from help. */
177-
hidden?: boolean
178176
}
179177

180178
/** How a route path parameter is exposed as a required named option. */

‎packages/sim-cli/src/runtime/options.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ function addFieldOption(
244244

245245
const hiddenNames = otherSpellings(flag).map(({ name }) => name)
246246
const option = new Option(`${short}--${name} ${placeholder}`, describe)
247-
if (flag.hidden) option.hideHelp()
248247
if (choices && !takesList) option.choices([...choices])
249248
if (descriptor.default !== undefined && field !== 'limit') {
250249
option.default(undefined, String(descriptor.default))

‎packages/workflow-code/DESIGN.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,11 @@ Function's code (or a child workflow's Response data) changes with an edit to th
410410
a bare reference to it would then compile bare, so an edit to one block would silently rewrite
411411
the storage of every unedited block that reads it (`refDeclaresString`). A quoted token prints bare
412412
only when a declaration (the catalog, a variable's type, an input or response format) types it a
413-
string. The runtime splice is not changed: a bare token outside a
414-
string is spliced raw by design (a string holding JSON text is nested on purpose), and the text is
415-
not valid JSON until the splice, so the resolver cannot tell where a value should be encoded. A string in the literal (a template or plain string) is always a JSON string. The
413+
string. At run time the resolver (`placeholderSplicer`) escapes a token inside a
414+
JSON string as string content and splices a bare one as JSON: a string becomes a JSON string unless
415+
it already reads as JSON (a string holding JSON text nests on purpose). So typing still matters for
416+
the one case the runtime cannot decide: text that reads as JSON (`12345`, `true`) stays text only
417+
when stored quoted. A string in the literal (a template or plain string) is always a JSON string. The
416418
printer writes stored text back as a literal only when serializing that literal reproduces the text
417419
byte for byte; print and compile decide each token's form through the same `refValueKind`, the
418420
printer reading only declarations for a quoted one. In a

‎packages/workflow-code/src/compile/SYNTAX.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ reordered tool never takes another tool's secret.
221221
A JSON code field (subBlock type `code`: `responseFormat`, table row `data`, a response body)
222222
written as an object or array literal compiles to `JSON.stringify(value, null, 2)` text. Each bare
223223
reference is stored by its output type: quoted (`"<a.b>"`) when the catalog or the workflow types it
224-
`string`, bare (`<a.b>`) otherwise, because the executor splices a string raw and any other value as
225-
JSON. A Function `result` field its JavaScript certainly returns as text (`return { tier: 'gold' }`) is
224+
`string`, bare (`<a.b>`) otherwise, because the executor splices a bare string as JSON when it reads
225+
as JSON (`12345` becomes a number) and a quoted one always as text. A Function `result` field its JavaScript certainly returns as text (`return { tier: 'gold' }`) is
226226
quoted too, and one it returns as a non-string (`return { total: a + b }`) is bare; so is the whole
227227
`result` when every `return` is text (`return new Date().toISOString()`) or none is. A reference
228228
nothing types, including a whole Function `result` or HTTP `data` its code or response may make

‎packages/workflow-code/src/print/params.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,15 @@ function printJsonField(ctx: PrintContext, block: CanonicalBlock, text: string):
169169
const tree = parseJsonField(text)
170170
if (tree === undefined) return null
171171
const isString = (token: string) => refValueKind(token, ctx.refTypes) === 'string'
172-
const printsBare = (token: string) => refDeclaresString(token, ctx.refTypes)
172+
const declared = new Map<string, boolean>()
173+
const printsBare = (token: string) => {
174+
let bare = declared.get(token)
175+
if (bare === undefined) {
176+
bare = refDeclaresString(token, ctx.refTypes)
177+
declared.set(token, bare)
178+
}
179+
return bare
180+
}
173181
let expressible = true
174182
const asCompiled = (node: JsonTree): JsonTree => {
175183
if (node instanceof JsonRef) {

0 commit comments

Comments
 (0)