Skip to content

Commit 43a9a4b

Browse files
committed
fix(workflow-code): refuse an inputFormat record entry that names no type
A bare number, boolean, null or array, or a record without a string type, compiled to a field with no type. The SDK types each entry as a type string or a spec with type, so compile now reports it.
1 parent 728d233 commit 43a9a4b

4 files changed

Lines changed: 38 additions & 6 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,10 @@ template.
215215
### Structured fields
216216

217217
- inputFormat (`structured: 'inputFormat'`) as a record: `name: 'string'` →
218-
`{ name, type: 'string', value: '' }`; `name: { type, … }` → `{ name, type, … }`; `{}` is the empty
219-
list. Arrays pass through. The printer writes a list the record cannot carry (an integer-like or
220-
repeated name, an unknown key) as `raw([…])`.
218+
`{ name, type: 'string', value: '' }`; `name: { type, … }` → `{ name, type, … }`; an entry with
219+
no type string (`count: 5`, `count: { value: 5 }`) is refused; `{}` is the empty list. Arrays
220+
pass through. The printer writes a list the record cannot carry (an integer-like or repeated name,
221+
an unknown key) as `raw([…])`.
221222
- Tools (`valueKind: 'tools'`): an array of
222223
- `ns.tool.method(params, options?)` (`slack.tool.sendMessage(…)`), or `builder.tool(params, options?)`
223224
for a builder at the namespace root (`agent.tool(…)`);

‎packages/workflow-code/src/compile/blocks.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type { CatalogBlock, CatalogSubBlock } from '../catalog/types'
2222
import { type CodeFileLanguage, codeFileLanguage, fromCodeFile } from '../code-files'
2323
import { isIdentifierName } from '../code-files/ref-path'
2424
import { branchesAtTopLevel, ELSE_KEY, isElseTrue } from '../forms/condition'
25-
import { inputFormatItems, renamedInputFields } from '../forms/input-format'
25+
import { inputFormatItems, renamedInputFields, untypedInputFields } from '../forms/input-format'
2626
import { compileResponseParam, usesResponseForm } from '../forms/response'
2727
import { CODE_FILE_EXTENSIONS, utf8Bytes } from '../limits'
2828
import {
@@ -724,6 +724,15 @@ function compileField(
724724
decl.key
725725
)
726726
}
727+
for (const key of untypedInputFields(value)) {
728+
unsupported(
729+
ctx,
730+
property.value,
731+
`The ${key} field names no type.`,
732+
`Write ${key}: 'string', or ${key}: { type: 'number', value: 5 }.`,
733+
decl.key
734+
)
735+
}
727736
value = inputFormatItems(value)
728737
}
729738
setOwn(params, target.id, { kind: 'value', value })

‎packages/workflow-code/src/compile/ergonomics.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,16 @@ describe('JSON field literals', () => {
388388
expect(codes(result)).toEqual(['E_UNSUPPORTED_SYNTAX'])
389389
})
390390

391+
it.each(['5', 'true', 'null', "['string']", '{ value: 5 }', '{ type: 5 }'])(
392+
'refuses an inputFormat entry %s that names no type',
393+
(entry) => {
394+
const result = run(
395+
source(` const start = trigger.start('Start', { inputFormat: { count: ${entry} } })`)
396+
)
397+
expect(codes(result)).toEqual(['E_UNSUPPORTED_SYNTAX'])
398+
}
399+
)
400+
391401
it("types a human form's fields under submission, as the SDK does", () => {
392402
const workflow = compiled(
393403
source(

‎packages/workflow-code/src/forms/input-format.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ export function renamedInputFields(value: Value): Array<{ key: string; name: Val
4646
)
4747
}
4848

49+
/**
50+
* The record keys whose entry names no type: neither a type string nor a record with a string
51+
* `type`. The SDK types every entry as one of those, so a bare value (`count: 5`) is refused rather
52+
* than stored as a field with no type.
53+
*/
54+
export function untypedInputFields(value: Value): string[] {
55+
if (!isPlainRecord(value)) return []
56+
return Object.entries(value).flatMap(([key, entry]) =>
57+
typeof entry === 'string' || (isPlainRecord(entry) && typeof entry.type === 'string')
58+
? []
59+
: [key]
60+
)
61+
}
62+
4963
/**
5064
* The record sugar compiled: `{ name: 'string' }` or `{ name: { type, ... } }` → stored item list.
5165
* The record key is always the field name; an entry's own `name` never replaces it.
@@ -59,8 +73,6 @@ export function inputFormatItems(value: Value): Value {
5973
for (const [key, field] of Object.entries(entry)) {
6074
if (key !== 'name') setOwn(item, key, field)
6175
}
62-
} else {
63-
setOwn(item, 'value', entry)
6476
}
6577
return item
6678
})

0 commit comments

Comments
 (0)