From a557f31c85c1023f0cac387aba9d2e2a1d1f62cb Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 20:12:57 +0000 Subject: [PATCH 1/2] fix(app-shell): the connector action Input repeater follows the run's declared-keys rule The repeater now reads the action's input schema the way the connector_action node does: a schema listing properties is closed, a key-admitting keyword or a non-false additionalProperties opens it. A closed schema keeps the repeater only for declared keys no typed field edits, and marks every other key as one the run refuses. Claude-Session: https://claude.ai/code/session_01ADHkmNs7VguNqTeS9xDmJQ Co-authored-by: Claude --- .changeset/33838-connector-extras-run-rule.md | 14 ++ .../inspectors/FlowKeyValueField.tsx | 14 ++ .../inspectors/FlowNodeConfigField.tsx | 24 ++++ .../FlowNodeInspector.connectorInput.test.tsx | 56 +++++++- .../inspectors/connector-input-fields.test.ts | 109 +++++++++++++--- .../inspectors/connector-input-fields.ts | 121 ++++++++++++++---- .../inspectors/flow-node-config.ts | 9 ++ ui/packages/i18n/src/namespaces/studio/en.ts | 2 + ui/packages/i18n/src/namespaces/studio/zh.ts | 1 + 9 files changed, 305 insertions(+), 45 deletions(-) create mode 100644 .changeset/33838-connector-extras-run-rule.md diff --git a/.changeset/33838-connector-extras-run-rule.md b/.changeset/33838-connector-extras-run-rule.md new file mode 100644 index 00000000000..bef10ad8c8a --- /dev/null +++ b/.changeset/33838-connector-extras-run-rule.md @@ -0,0 +1,14 @@ +--- +'@object-ui/i18n': patch +'@object-ui/app-shell': patch +'@object-ui/console': patch +--- + +fix(app-shell): the Studio connector action Input repeater follows the run's declared-keys rule + +Clause-②: yes (widening) — `@object-ui/i18n` gains the studio pack key `engine.inspector.flowNode.kv.undeclaredKey` (en, zh). Nothing is removed or narrowed. +Metadata-protocol: none + +- **The repeater offers extras only where the run accepts them.** A `connector_action` step refuses, at run time, an input key the action's input schema does not declare. Studio now reads the schema the same way: an action whose schema lists `properties` (every shipped connector) is closed, and one that carries `additionalProperties` or `unevaluatedProperties` other than `false`, a `$ref`, `allOf` / `anyOf` / `oneOf`, `patternProperties` or another key-admitting keyword, or no `properties` at all, is open. An open action keeps the key/value repeater beside its typed fields, as before. A closed action keeps it only for a key it declares that no typed field can edit, such as an OpenAPI operation's `$ref` or schemaless request `body`, or Slack's `blocks`, and suggests those keys in the key cell. When every declared key has a typed field, the repeater is gone. +- **Keys the run refuses are marked, not dropped.** On a closed action, a stored input key the schema does not declare (one left behind by an older flow or an action switch) stays in the repeater with a line under it saying that the run refuses it and how to fix it. A key typed into the repeater that the action does not declare gets the same line. Studio never removes such a key on its own; the author removes it. +- An OpenAPI operation whose only input is a schemaless body now gets the judged repeater too, where it used to get the generic one. diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/FlowKeyValueField.tsx b/ui/packages/app-shell/src/views/metadata-admin/inspectors/FlowKeyValueField.tsx index b52b2a2d01d..f7f3c454bae 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/FlowKeyValueField.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/FlowKeyValueField.tsx @@ -271,6 +271,13 @@ export interface FlowKeyValueFieldProps { * {@link valueEnvelope}. */ valueRefusal?: (value: unknown) => string[] | null; + /** + * objectstack#33838: the judge of one KEY — what the cell says under a row + * whose key the consumer refuses (a connector input key the action does not + * declare), or `null` when the key is accepted. The row stays as it is: a + * refused key is marked, never dropped. Omitted, no key is judged. + */ + keyRefusal?: (key: string) => string | null; } /** @@ -308,6 +315,7 @@ export function FlowKeyValueField({ keysByLabel, valueMode, valueRefusal = valueEnvelopeRefusal, + keyRefusal, }: FlowKeyValueFieldProps) { const keyListId = React.useId(); const suggestsKeys = !!keyOptions && keyOptions.length > 0; @@ -406,6 +414,7 @@ export function FlowKeyValueField({ const shownRefusal = refusal ? [...new Set(refusal.map((m) => (blankText && isBlankExpressionRefusal(m) ? blankText : m)))] : null; + const keyRefused = keyRefusal && row.key.trim() !== '' ? keyRefusal(row.key.trim()) : null; return (
{/* @@ -454,6 +463,11 @@ export function FlowKeyValueField({
+ {keyRefused && ( +

+ {keyRefused} +

+ )}
; } +/** + * objectstack#33838 — the key-cell props of a `keyValue` map judged against a + * closed key set ({@link FlowConfigField.acceptedKeys}): a key outside it is + * marked as refused, and the accepted keys no sibling field owns (`omitKeys`) + * are suggested. The key stays free text, so a marked key is still editable. + */ +function acceptedKeyProps( + acceptedKeys: readonly string[], + omitKeys: readonly string[] | undefined, + locale: string | undefined, +): Pick { + const accepted = new Set(acceptedKeys); + const offered = acceptedKeys.filter((k) => !omitKeys?.includes(k)); + return { + keyRefusal: (key) => (accepted.has(key) ? null : t('engine.inspector.flowNode.kv.undeclaredKey', locale)), + ...(offered.length > 0 ? { keyOptions: offered.map((k) => ({ value: k, label: k })) } : {}), + }; +} + export function FlowNodeConfigField({ field, value, onCommit, disabled, locale, context, scopeGroups, approvalScopeGroups, triggerScope, inactiveRetained, onClearInactive, required, requiredColumns }: FlowNodeConfigFieldProps) { // A text / textarea field with no override is a literal (no picker spelling). const refMode: 'expression' | 'hole' | undefined = @@ -777,6 +796,11 @@ export function FlowNodeConfigField({ field, value, onCommit, disabled, locale, // `headers`) renders `{{ }}` holes in each value cell. valueMode: field.refMode === 'hole' ? 'hole' : undefined, valueRefusal: isFilterOperandSlot(context?.node?.type, field.path) ? filterOperandRefusal : undefined, + // objectstack#33838 — a map the run judges against a closed key set + // (a connector action's declared inputs): each other key is marked + // as refused, and the declared keys no sibling field types are + // suggested in the key cell. + ...(field.acceptedKeys ? acceptedKeyProps(field.acceptedKeys, field.omitKeys, locale) : {}), }; // objectui#11788 — a record node's field-value map: its keys are fields // of the node's own target object, so the key cell lists them. The diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/FlowNodeInspector.connectorInput.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/inspectors/FlowNodeInspector.connectorInput.test.tsx index 1453c9dacab..b556f6700df 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/FlowNodeInspector.connectorInput.test.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/FlowNodeInspector.connectorInput.test.tsx @@ -48,6 +48,12 @@ const SLACK_POST_MESSAGE = { }, }; +/** The slack schema without `blocks` (which no field can type) — CLOSED, every declared key typed. */ +const SLACK_TYPED_ONLY = { + ...SLACK_POST_MESSAGE, + properties: Object.fromEntries(Object.entries(SLACK_POST_MESSAGE.properties).filter(([k]) => k !== 'blocks')), +}; + function mockRegistry(actions: unknown[]) { vi.stubGlobal( 'fetch', @@ -168,7 +174,7 @@ describe('#4305 — the Input section derives typed fields from the descriptor i expect(patchedInput(onPatch)).toEqual({ channel: 'C123', legacy_note: 'keep me', text: 'hello' }); }); - it('an undeclared stored key stays editable in the extras repeater (schema is OPEN)', async () => { + it('an undeclared stored key stays editable in the extras repeater (never hidden or dropped)', async () => { mockRegistry([{ key: 'chat.postMessage', label: 'Post Message', inputSchema: SLACK_POST_MESSAGE }]); renderInspector(makeDraft()); @@ -199,12 +205,12 @@ describe('#4305 — the Input section derives typed fields from the descriptor i expect(patchedInput(onPatch)).toEqual({ channel: 'C123', legacy_note: 'edited' }); }); - it('a CLOSED schema (additionalProperties:false) drops the repeater', async () => { + it('a CLOSED schema whose every declared key is typed drops the repeater', async () => { mockRegistry([ { key: 'chat.postMessage', label: 'Post Message', - inputSchema: { ...SLACK_POST_MESSAGE, additionalProperties: false }, + inputSchema: SLACK_TYPED_ONLY, }, ]); renderInspector(makeDraft({ channel: 'C123' })); @@ -233,6 +239,50 @@ describe('#4305 — the Input section derives typed fields from the descriptor i }); }); +describe('objectstack#33838 — the extras repeater follows the run\'s declared-keys rule', () => { + it('a stored key a CLOSED schema does not declare is shown and marked as refused by the run', async () => { + mockRegistry([{ key: 'chat.postMessage', label: 'Post Message', inputSchema: SLACK_TYPED_ONLY }]); + const { onPatch } = renderInspector(makeDraft()); + + await screen.findByText('Channel'); + await waitFor(() => expect(screen.queryByDisplayValue('channel')).toBeNull()); + expect(screen.getByDisplayValue('legacy_note')).toBeTruthy(); + const marks = screen.getAllByTestId('flow-kv-key-refusal'); + expect(marks).toHaveLength(1); + expect(marks[0].getAttribute('role')).toBe('alert'); + // Marked, not dropped: rendering alone writes nothing. + expect(onPatch).not.toHaveBeenCalled(); + }); + + it('an OPEN schema (a key-admitting `allOf`) keeps the repeater and marks no key', async () => { + mockRegistry([ + { key: 'chat.postMessage', label: 'Post Message', inputSchema: { ...SLACK_TYPED_ONLY, allOf: [{ type: 'object' }] } }, + ]); + renderInspector(makeDraft()); + + await screen.findByText('Channel'); + await waitFor(() => expect(screen.queryByDisplayValue('channel')).toBeNull()); + expect(screen.getByDisplayValue('legacy_note')).toBeTruthy(); + expect(screen.queryByTestId('flow-kv-key-refusal')).toBeNull(); + }); + + it('a declared key no field types (an openapi `body: {}`) is offered by the repeater and not marked', async () => { + mockRegistry([ + { + key: 'chat.postMessage', + label: 'Post Message', + inputSchema: { type: 'object', properties: { channel: { type: 'string' }, body: {} } }, + }, + ]); + renderInspector(makeDraft({ channel: 'C123', body: '{"a":1}' })); + + await screen.findByText('Channel'); + await waitFor(() => expect(screen.queryByDisplayValue('channel')).toBeNull()); + expect(screen.getByDisplayValue('body')).toBeTruthy(); + expect(screen.queryByTestId('flow-kv-key-refusal')).toBeNull(); + }); +}); + describe('#4305 — pins that must NOT move', () => { it('a descriptor with NO inputSchema keeps the generic repeater, showing every key', async () => { mockRegistry([{ key: 'plain', label: 'Plain' }]); diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/connector-input-fields.test.ts b/ui/packages/app-shell/src/views/metadata-admin/inspectors/connector-input-fields.test.ts index d7930e0085e..d1b321b010e 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/connector-input-fields.test.ts +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/connector-input-fields.test.ts @@ -17,6 +17,7 @@ import { describe, it, expect } from 'vitest'; import { CONNECTOR_INPUT_PATH, connectorActionInputSchema, + connectorInputContractKeys, connectorInputFields, connectorInputExtras, mergeConnectorInputExtras, @@ -36,6 +37,12 @@ const SLACK_POST_MESSAGE = { }, }; +/** The slack schema without `blocks` — every key it declares gets a typed field. */ +const SLACK_TYPED_ONLY = { + ...SLACK_POST_MESSAGE, + properties: Object.fromEntries(Object.entries(SLACK_POST_MESSAGE.properties).filter(([k]) => k !== 'blocks')), +}; + /** A registry payload shaped like the dispatcher's `{ data: { connectors } }`. */ const CONNECTORS = [ { @@ -183,20 +190,46 @@ describe('connectorInputFields — re-rooting onto connectorConfig.input', () => }); }); -describe('connectorInputFields — measured additionalProperties semantics', () => { - it('treats an ABSENT additionalProperties as OPEN (every shipped connector omits it)', () => { - expect(connectorInputFields(SLACK_POST_MESSAGE)!.open).toBe(true); +/** + * objectstack#33838 — the run's rule, mirrored. Since objectstack#33614 the + * `connector_action` node refuses an input key the action's schema does not + * declare (`service-automation` `connector-input-schema.ts` `declaredKeysOf`), + * reading `properties` as the contract rather than JSON Schema's open default. + */ +describe('connectorInputContractKeys — the run\'s declared-keys rule', () => { + it('a schema listing `properties` (every shipped connector, no `additionalProperties`) is CLOSED', () => { + expect(connectorInputContractKeys(SLACK_POST_MESSAGE)).toEqual(['channel', 'text', 'thread_ts', 'blocks']); + expect(connectorInputFields(SLACK_POST_MESSAGE)!.open).toBe(false); + }); + + it('declares the `required` names too, even ones `properties` does not list', () => { + expect(connectorInputContractKeys({ type: 'object', properties: { a: { type: 'string' } }, required: ['a', 'b'] })) + .toEqual(['a', 'b']); }); - it('treats `additionalProperties: false` as CLOSED', () => { - expect(connectorInputFields({ ...SLACK_POST_MESSAGE, additionalProperties: false })!.open).toBe(false); + it('`additionalProperties: false` is CLOSED, and with no `properties` declares none', () => { + expect(connectorInputContractKeys({ ...SLACK_POST_MESSAGE, additionalProperties: false })) + .toEqual(['channel', 'text', 'thread_ts', 'blocks']); + expect(connectorInputContractKeys({ type: 'object', additionalProperties: false })).toEqual([]); }); - it('treats `additionalProperties: true` / a value schema as OPEN', () => { + it('`additionalProperties` / `unevaluatedProperties` set to `true` or a schema is OPEN', () => { + expect(connectorInputContractKeys({ ...SLACK_POST_MESSAGE, additionalProperties: true })).toBeNull(); + expect(connectorInputContractKeys({ ...SLACK_POST_MESSAGE, additionalProperties: { type: 'string' } })).toBeNull(); + expect(connectorInputContractKeys({ ...SLACK_POST_MESSAGE, unevaluatedProperties: true })).toBeNull(); expect(connectorInputFields({ ...SLACK_POST_MESSAGE, additionalProperties: true })!.open).toBe(true); - expect( - connectorInputFields({ ...SLACK_POST_MESSAGE, additionalProperties: { type: 'string' } })!.open, - ).toBe(true); + }); + + it('a key-admitting keyword (`$ref`, `allOf`, `patternProperties`, …) is OPEN', () => { + for (const k of ['$ref', 'allOf', 'anyOf', 'oneOf', 'patternProperties', 'if', 'dependentSchemas']) { + expect(connectorInputContractKeys({ ...SLACK_POST_MESSAGE, [k]: k === '$ref' ? '#/x' : [] })).toBeNull(); + } + }); + + it('a schema listing no `properties` (and not closed) is OPEN; a non-object is not judged', () => { + expect(connectorInputContractKeys({ type: 'object' })).toBeNull(); + expect(connectorInputContractKeys(undefined)).toBeNull(); + expect(connectorInputContractKeys([])).toBeNull(); }); }); @@ -265,21 +298,24 @@ describe('applyConnectorInputForm — splicing into the connector_action group', 'connectorConfig.input.channel', 'connectorConfig.input.text', 'connectorConfig.input.thread_ts', - 'connectorConfig.input', // the extras repeater, still open-schema + 'connectorConfig.input', // the repeater, kept for the declared `blocks` no field types 'timeoutMs', ]); }); - it('an OPEN schema keeps the repeater, carrying the declared keys as omitKeys', () => { - const form = connectorInputFields(SLACK_POST_MESSAGE)!; + it('an OPEN schema keeps the repeater, carrying the typed keys as omitKeys and judging no key', () => { + const form = connectorInputFields({ ...SLACK_POST_MESSAGE, allOf: [{ type: 'object' }] })!; + expect(form.open).toBe(true); const repeater = applyConnectorInputForm(base(), form).find((f) => f.id === 'connectorConfig.input')!; expect(repeater.kind).toBe('keyValue'); expect(repeater.omitKeys).toEqual(['channel', 'text', 'thread_ts']); + expect(repeater.acceptedKeys).toBeUndefined(); }); - it('a CLOSED schema drops the repeater entirely', () => { - const form = connectorInputFields({ ...SLACK_POST_MESSAGE, additionalProperties: false })!; - const out = applyConnectorInputForm(base(), form); + it('a CLOSED schema whose every declared key is typed drops the repeater entirely', () => { + const form = connectorInputFields(SLACK_TYPED_ONLY)!; + expect(form.open).toBe(false); + const out = applyConnectorInputForm(base(), form, { channel: 'C123' }); expect(out.some((f) => f.id === 'connectorConfig.input')).toBe(false); expect(out.map((f) => f.id)).toEqual([ 'connectorConfig.connectorId', @@ -291,6 +327,49 @@ describe('applyConnectorInputForm — splicing into the connector_action group', ]); }); + it('a CLOSED schema keeps the repeater for a declared key no field types (slack `blocks`), judging every key', () => { + const form = connectorInputFields(SLACK_POST_MESSAGE)!; + const repeater = applyConnectorInputForm(base(), form, { channel: 'C123' }).find((f) => f.id === 'connectorConfig.input')!; + expect(repeater.omitKeys).toEqual(['channel', 'text', 'thread_ts']); + expect(repeater.acceptedKeys).toEqual(['channel', 'text', 'thread_ts', 'blocks']); + }); + + it('an openapi operation whose `$ref` / schemaless body is declared as `body: {}` offers `body` in the repeater', () => { + // openapi-connector.ts `buildInputSchema`: an unresolved `$ref` request + // body (or content with no `schema`) is declared `body: {}` — any value. + // No field can type it, so the repeater is its only editor; the top level + // stays closed, so anything else typed there is judged. + const form = connectorInputFields({ + type: 'object', + properties: { + path: { type: 'object', properties: { id: { type: 'string' } }, required: ['id'] }, + body: {}, + }, + required: ['path'], + })!; + expect(form.open).toBe(false); + expect(form.declaredKeys).toEqual(['path']); + const repeater = applyConnectorInputForm(base(), form).find((f) => f.id === 'connectorConfig.input')!; + expect(repeater.omitKeys).toEqual(['path']); + expect(repeater.acceptedKeys).toEqual(['path', 'body']); + }); + + it('a body-only openapi operation still resolves: the closed schema keeps a judged repeater with no typed field', () => { + const form = connectorInputFields({ type: 'object', properties: { body: {} } })!; + expect(form).not.toBeNull(); + expect(form.fields).toEqual([]); + const repeater = applyConnectorInputForm(base(), form).find((f) => f.id === 'connectorConfig.input')!; + expect(repeater.acceptedKeys).toEqual(['body']); + }); + + it('a stored key a CLOSED schema does not declare keeps the repeater, judged — never dropped', () => { + const form = connectorInputFields(SLACK_TYPED_ONLY)!; + const stored = { channel: 'C123', legacy_note: 'keep me' }; + const repeater = applyConnectorInputForm(base(), form, stored).find((f) => f.id === 'connectorConfig.input')!; + expect(repeater.acceptedKeys).toEqual(['channel', 'text', 'thread_ts']); + expect(connectorInputExtras(stored, repeater.omitKeys!)).toEqual({ legacy_note: 'keep me' }); + }); + it('leaves a group that has no Input field untouched', () => { const form = connectorInputFields(SLACK_POST_MESSAGE)!; const httpFields = fieldsForNodeType('http'); diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/connector-input-fields.ts b/ui/packages/app-shell/src/views/metadata-admin/inspectors/connector-input-fields.ts index 6e9abd94768..e9f3dd5c3bc 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/connector-input-fields.ts +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/connector-input-fields.ts @@ -22,8 +22,9 @@ * `handler((cfg.input ?? {}) as Record, handlerCtx)`). * * Anything the resolver declines to map (an `array` with no `items`, a bare - * `{type:'object'}`, a union) is simply not claimed here either — it stays - * editable in the repeater, so no descriptor can make a stored key unreachable. + * `{type:'object'}`, a union, a schemaless `{}`) is simply not claimed here + * either — it stays editable in the repeater, so no descriptor can make a + * declared or stored key unreachable. * * ## The measured schema language * @@ -42,21 +43,34 @@ * — a per-key `required: true` map, not JSON Schema. They are different contracts * that share a name; only the descriptor one is read here. * - * ## additionalProperties — measured, then followed + * ## Open or closed — the run's rule, mirrored * - * No shipped connector emits `additionalProperties` at all, and JSON Schema's - * default for an absent one is OPEN. The runtime agrees: the executor passes the - * whole input map to the handler unvalidated, so undeclared keys really are - * accepted. So the rule is the JSON-Schema rule — CLOSED iff - * `additionalProperties === false`, OPEN otherwise (absent, `true`, or a value - * schema) — and an open schema keeps the repeater alongside the typed fields for - * exactly the keys the typed fields don't own. + * Since objectstack#33614 the `connector_action` node REFUSES, at run time, an + * input key the action's schema does not declare (`service-automation` + * `connector-input-schema.ts`, `declaredKeysOf` and the `refuseUndeclaredKeys` + * walk; the node door passes `{ refuseUndeclaredKeys: true }` in + * `builtin/connector-nodes.ts`). Not JSON Schema's open default: no shipped + * connector writes `additionalProperties`, so under that default every key + * would pass. {@link connectorInputContractKeys} mirrors that judgment for the + * top level of the input map: + * • DECLARED = the names in `properties` plus those in `required`; + * • OPEN (every key accepted) when `additionalProperties` or + * `unevaluatedProperties` is anything but `false`, when a key-admitting + * keyword is present (`$ref`, `allOf` / `anyOf` / `oneOf`, + * `patternProperties`, …), or when the schema lists no `properties` and + * does not say `additionalProperties: false`; + * • CLOSED otherwise. * - * A closed schema drops the repeater, EXCEPT when the stored map already holds - * undeclared keys: this package's standing rule is that a field is shown when it - * holds a stored value "so existing config is never hidden" - * ({@link isFieldVisible}), and silently hiding a key an older flow committed - * would be worse than offering an editor the new schema no longer invites. + * The extras repeater follows it. An open schema keeps the repeater for every + * key the typed fields don't own. A closed schema keeps it only for a key it + * DECLARES that the resolver cannot type — an openapi operation's `$ref` or + * schemaless request `body` (declared `body: {}`), slack's item-less `blocks` + * — and the repeater then marks every key the schema does not declare as one + * the run refuses ({@link FlowConfigField.acceptedKeys}). A stored undeclared + * key on a closed schema keeps the repeater too, flagged rather than hidden or + * dropped: this package's standing rule is that a field holding a stored value + * is shown "so existing config is never hidden" ({@link isFieldVisible}), and + * the author is the one to remove it. * * NOT represented: JSON Schema `required`. `FlowConfigField` has no requiredness * concept, so the typed fields cannot mark it — a descriptor's `required: [...]` @@ -87,7 +101,14 @@ export interface ConnectorInputForm { * property the resolver declined is absent here and stays repeater-editable. */ declaredKeys: string[]; - /** Whether undeclared keys are accepted (`additionalProperties !== false`). */ + /** + * The top-level keys the action DECLARES, as the run judges them + * ({@link connectorInputContractKeys}), or `null` when its input is open. + * A superset of {@link declaredKeys}: it also holds the declared keys the + * resolver could not type, which the repeater still offers. + */ + contractKeys: string[] | null; + /** Whether the run accepts undeclared keys: `contractKeys === null`. */ open: boolean; } @@ -118,6 +139,39 @@ export function connectorActionInputSchema( return isPlainObject(schema) ? schema : undefined; } +/** + * Keywords that can admit a key not listed in `properties` / `required`: + * pattern-matched keys, and every way a schema pulls in another schema's keys. + * A schema carrying one reads as OPEN. The run's list, verbatim + * (`service-automation` `connector-input-schema.ts` `KEY_ADMITTING_KEYWORDS`). + */ +const KEY_ADMITTING_KEYWORDS = [ + 'patternProperties', '$ref', '$dynamicRef', '$recursiveRef', 'allOf', 'anyOf', 'oneOf', + 'if', 'then', 'else', 'dependentSchemas', 'dependencies', +]; + +/** + * The keys an action's input schema DECLARES at the top level, or `null` when + * the run reads its input as OPEN and accepts any key — the mirror of the + * run's `declaredKeysOf` (`service-automation` `connector-input-schema.ts`), + * which the `connector_action` node refuses undeclared keys by. A non-object + * schema declares nothing judgeable: `null`. + */ +export function connectorInputContractKeys(schema: unknown): string[] | null { + if (!isPlainObject(schema)) return null; + if (KEY_ADMITTING_KEYWORDS.some((k) => Object.prototype.hasOwnProperty.call(schema, k))) return null; + const additional = schema.additionalProperties; + if (additional !== undefined && additional !== false) return null; + const unevaluated = schema.unevaluatedProperties; + if (unevaluated !== undefined && unevaluated !== false) return null; + const properties = isPlainObject(schema.properties) ? schema.properties : undefined; + if (!properties && additional !== false) return null; + const required = Array.isArray(schema.required) + ? schema.required.filter((k): k is string => typeof k === 'string') + : []; + return [...new Set([...Object.keys(properties ?? {}), ...required])]; +} + /** Re-root one resolver field from `config.*` onto `connectorConfig.input.*`. */ function reroot(field: FlowConfigField): FlowConfigField { const out: FlowConfigField = { @@ -137,12 +191,17 @@ function reroot(field: FlowConfigField): FlowConfigField { /** * Resolve a descriptor `inputSchema` into the Input section's typed fields, or - * `null` when it is not a usable object schema (so the caller keeps the generic - * repeater unchanged). + * `null` when there is nothing to change: no object schema, or an OPEN one the + * resolver types no field of (so the caller keeps the generic repeater + * unchanged). A CLOSED schema always resolves — even with no typed field (an + * openapi operation whose only input is a schemaless `body`), the run refuses + * every key it does not declare, and the repeater has to say so. */ export function connectorInputFields(schema: unknown): ConnectorInputForm | null { - const raw = jsonSchemaToFlowFields(schema); - if (!raw || raw.length === 0) return null; + if (!isPlainObject(schema)) return null; + const contractKeys = connectorInputContractKeys(schema); + const raw = jsonSchemaToFlowFields(schema) ?? []; + if (raw.length === 0 && contractKeys === null) return null; const fields = raw.map(reroot); // The owned key is the first segment after `connectorConfig.input` — so a // flattened group (`…input.retry.attempts`) is claimed by `retry`, once. @@ -151,8 +210,7 @@ export function connectorInputFields(schema: unknown): ConnectorInputForm | null const key = f.path[CONNECTOR_INPUT_PATH.length]; if (key && !declaredKeys.includes(key)) declaredKeys.push(key); } - const additional = isPlainObject(schema) ? (schema as { additionalProperties?: unknown }).additionalProperties : undefined; - return { fields, declaredKeys, open: additional !== false }; + return { fields, declaredKeys, contractKeys, open: contractKeys === null }; } /** @@ -205,9 +263,12 @@ export function mergeConnectorInputExtras( * repeater IN PLACE (so the connector / action pickers above it and `timeoutMs` * below it keep their positions). * - * The repeater is kept after the typed fields when the schema is open, or when - * the stored map still holds undeclared keys (never hide existing config); it - * then carries `omitKeys` so it edits only what the typed fields don't own. + * The repeater is kept after the typed fields when the schema is open, when it + * declares a key the typed fields don't own, or when the stored map still holds + * a key no typed field owns (never hide existing config); it then carries + * `omitKeys` so it edits only what the typed fields don't own. On a closed + * schema it also carries `acceptedKeys` — the declared keys — so a key the run + * refuses is marked as such, stored or newly typed. * Returns the input array unchanged (same reference) when there is nothing to do. */ export function applyConnectorInputForm( @@ -223,11 +284,17 @@ export function applyConnectorInputForm( if (at === -1) return fields; const repeater = fields[at]; const hasExtras = Object.keys(connectorInputExtras(storedInput, form.declaredKeys)).length > 0; - const keepRepeater = form.open || hasExtras; + const untyped = form.contractKeys?.filter((k) => !form.declaredKeys.includes(k)) ?? []; + const keepRepeater = form.open || untyped.length > 0 || hasExtras; + const kept: FlowConfigField = { + ...repeater, + omitKeys: form.declaredKeys, + ...(form.contractKeys ? { acceptedKeys: form.contractKeys } : {}), + }; return [ ...fields.slice(0, at), ...form.fields, - ...(keepRepeater ? [{ ...repeater, omitKeys: form.declaredKeys }] : []), + ...(keepRepeater ? [kept] : []), ...fields.slice(at + 1), ]; } diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/flow-node-config.ts b/ui/packages/app-shell/src/views/metadata-admin/inspectors/flow-node-config.ts index aa3d830d2ae..5b743cf5596 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/flow-node-config.ts +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/flow-node-config.ts @@ -357,6 +357,15 @@ export interface FlowConfigField { * the stored map round-trips whole. */ omitKeys?: string[]; + /** + * For a `keyValue` field whose map the run judges against a CLOSED key set + * (objectstack#33838): the keys it accepts. Any other key in the map is + * marked, row by row, as one the run refuses — never dropped, so the author + * sees it and removes it. The connector Input repeater gets it from the + * action's input schema (`connector-input-fields.ts`); absent, every key is + * accepted and nothing is marked. + */ + acceptedKeys?: string[]; /** Reference target for `reference` fields — drives the combobox data source. */ ref?: FlowReferenceSpec; /** diff --git a/ui/packages/i18n/src/namespaces/studio/en.ts b/ui/packages/i18n/src/namespaces/studio/en.ts index e87a8e3a020..f43d7ad5d10 100644 --- a/ui/packages/i18n/src/namespaces/studio/en.ts +++ b/ui/packages/i18n/src/namespaces/studio/en.ts @@ -728,6 +728,8 @@ const STUDIO_EN: Record = { 'engine.inspector.flowNode.kv.asExpression': 'Write as a CEL expression', 'engine.inspector.flowNode.kv.expressionPlaceholder': 'CEL expression, e.g. joinNonEmpty(…)', 'engine.inspector.flowNode.kv.expressionNeeded': 'This value needs an expression. Write one, or switch the value back to text.', + // objectstack#33838 — a connector Input key the action does not declare: the run refuses it. + 'engine.inspector.flowNode.kv.undeclaredKey': 'The action does not declare this input, so the run refuses it. Remove it, or pick an action that declares it.', // objectstack#27834 — the Update Records filter's "Triggering record" target. 'engine.inspector.flowNode.triggeringRecord.use': 'Update the triggering record', 'engine.inspector.flowNode.triggeringRecord.hint': 'Targets the {object} record that started this flow.', diff --git a/ui/packages/i18n/src/namespaces/studio/zh.ts b/ui/packages/i18n/src/namespaces/studio/zh.ts index 616725823e5..4aa83f20d02 100644 --- a/ui/packages/i18n/src/namespaces/studio/zh.ts +++ b/ui/packages/i18n/src/namespaces/studio/zh.ts @@ -618,6 +618,7 @@ const STUDIO_ZH: Record = { 'engine.inspector.flowNode.kv.asExpression': '写成 CEL 表达式', 'engine.inspector.flowNode.kv.expressionPlaceholder': 'CEL 表达式,例如 joinNonEmpty(…)', 'engine.inspector.flowNode.kv.expressionNeeded': '这个值需要一个表达式。请填写表达式,或把这个值切回文本。', + 'engine.inspector.flowNode.kv.undeclaredKey': '该动作没有声明这个输入,运行时会拒绝它。请删除它,或选择声明了它的动作。', // objectstack#27834 — the Update Records filter's "Triggering record" target. 'engine.inspector.flowNode.triggeringRecord.use': '更新触发记录', 'engine.inspector.flowNode.triggeringRecord.hint': '目标为启动此流程的那条 {object} 记录。', From 3b90535e66c38798de992e94edadb927154ba896 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 20:49:53 +0000 Subject: [PATCH 2/2] test(app-shell): pay the lint load at collection in the connector input harness Claude-Session: https://claude.ai/code/session_01ADHkmNs7VguNqTeS9xDmJQ Co-authored-by: Claude --- .../inspectors/FlowNodeInspector.connectorInput.test.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/FlowNodeInspector.connectorInput.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/inspectors/FlowNodeInspector.connectorInput.test.tsx index b556f6700df..bb15263a49d 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/FlowNodeInspector.connectorInput.test.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/FlowNodeInspector.connectorInput.test.tsx @@ -16,6 +16,9 @@ * undeclared extras and their order all survive). */ +// The source loads this lazily; pay that load at collection, not inside a +// case's clocked window. +import '@objectstack/lint'; import { describe, it, expect, vi, afterEach } from 'vitest'; import { render, screen, cleanup, fireEvent, waitFor } from '@testing-library/react';