Skip to content

Commit fcd2e65

Browse files
committed
fix(core,react,runtime,cli,app-shell): read the template envelope on an action's description, helpText and outcomeMessages
Readers first (#27948, ruling A, step 2): the next commit types these three keys as `template` slots, so a parsed action carries `{ dialect: 'template', source }` where it carried a string. Each reader that took a string now takes the envelope, pinned and reverse-checked: - core ActionRunner hands the param-collection handler the action and params with `description` / each `helpText` reduced to their text (`actionCopyText`), and composeSuccessMessage reads an outcome envelope's source; - react useActionTextLocalizer keeps an outcomeMessages envelope's shape instead of collapsing it to the word "template"; - runtime summarizeActionParams reads helpText's text for the MCP param description, never "[object Object]"; - cli i18n-extract seeds the envelope's text exactly as the bare string's on description, helpText and outcomeMessages; - app-shell ActionPreview (Studio) draws helpText, confirmText and successMessage from the envelope's source; it drew helpText raw, an object as a React child. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibwQ8tWwY7TiHQPMCHR
1 parent 776c1d8 commit fcd2e65

12 files changed

Lines changed: 487 additions & 19 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@object-ui/core': patch
3+
'@object-ui/react': patch
4+
---
5+
6+
fix(core,react): an action's `description`, a param's `helpText` and an `outcomeMessages` entry read the `template` envelope
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
objectstack#27948 step 2 types these three as `template` slots, so a served action can carry `{ dialect: 'template', source }` where it carried a string.
12+
13+
- **Param dialog.** The runner hands the param-collection handler the action and params with `description` and each `helpText` reduced to their text (`actionCopyText`), so the dialog draws the sentence, never `[object Object]`; a locale map is handed on unchanged for the host to localize.
14+
- **Outcome toast.** `useActionTextLocalizer` keeps an `outcomeMessages` envelope's shape (a bundle entry replaces its `source`) instead of collapsing it to the word "template", and the runner fills the envelope's holes as it fills the string's.
15+
16+
- **Studio's action preview** (`@object-ui/app-shell`, unpublished) draws a param's `helpText`, `confirmText` and `successMessage` from the envelope's `source`: it drew `helpText` raw (an object as a React child) and read the other two as a locale map, which showed the word "template".
17+
18+
What to do: nothing. `${…}` copy written before the migration keeps reading.

‎packages/cli/src/utils/i18n-extract.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,10 @@ function pushDerived(
721721
}
722722

723723
/**
724-
* [#24814] An action's `confirmText` / `successMessage` is a `template` slot
725-
* that also takes an inline locale map: a bare string, the parsed
724+
* [#24814, #27948] An action's `confirmText` / `successMessage` /
725+
* `description` / `outcomeMessages` entry is a `template` slot that also takes
726+
* an inline locale map, and a param's `helpText` one without it: a bare
727+
* string, the parsed
726728
* `{ dialect: 'template', source }` envelope, or the map. The envelope and the
727729
* string are the same authored sentence, so the envelope is read through the
728730
* template judge's one reader and seeded like the string; anything else (the
@@ -801,7 +803,7 @@ function pushActionParams(
801803
} else {
802804
pushDerived(out, [...base, 'label'], literalLabel ?? pname, param.label, kind, { objectName });
803805
}
804-
pushOptional(out, [...base, 'helpText'], param.helpText, kind, { objectName });
806+
pushOptional(out, [...base, 'helpText'], actionCopy(param.helpText), kind, { objectName });
805807
pushOptional(out, [...base, 'placeholder'], param.placeholder, kind, { objectName });
806808
if (Array.isArray(param.options)) {
807809
for (const opt of param.options) {
@@ -839,7 +841,7 @@ function pushActionOutcomeMessages(
839841
const messages = action?.outcomeMessages;
840842
if (!messages || typeof messages !== 'object' || Array.isArray(messages)) return;
841843
for (const [outcome, message] of Object.entries<unknown>(messages)) {
842-
pushOptional(out, [...actionRoot, 'outcomeMessages', outcome], message, kind, { objectName });
844+
pushOptional(out, [...actionRoot, 'outcomeMessages', outcome], actionCopy(message), kind, { objectName });
843845
}
844846
}
845847

@@ -1522,7 +1524,7 @@ export function collectExpectedEntries(
15221524
const aname = action.name as string;
15231525
const aroot = ['objects', objectName, '_actions', aname];
15241526
pushDerived(out, [...aroot, 'label'], inlineText(action.label) ?? aname, action.label, 'action', { objectName });
1525-
pushOptional(out, [...aroot, 'description'], action.description, 'action', { objectName });
1527+
pushOptional(out, [...aroot, 'description'], actionCopy(action.description), 'action', { objectName });
15261528
pushOptional(out, [...aroot, 'confirmText'], actionCopy(action.confirmText), 'action', { objectName });
15271529
pushOptional(out, [...aroot, 'successMessage'], actionCopy(action.successMessage), 'action', { objectName });
15281530
pushOptional(out, [...aroot, 'disabledReason'], action.disabledReason, 'action', { objectName });
@@ -1617,7 +1619,7 @@ export function collectExpectedEntries(
16171619
// string when the action declares none, so an undeclared description is
16181620
// not an i18n gap to seed (`pushDerived` would invent an English source
16191621
// string nothing authored). #7367.
1620-
pushOptional(out, [...root, 'description'], action.description, kind, { objectName });
1622+
pushOptional(out, [...root, 'description'], actionCopy(action.description), kind, { objectName });
16211623
pushOptional(out, [...root, 'confirmText'], actionCopy(action.confirmText), kind, { objectName });
16221624
pushOptional(out, [...root, 'successMessage'], actionCopy(action.successMessage), kind, { objectName });
16231625
// [#26619] OPTIONAL-not-derived like `description`: an action that gives no
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #27948 (ruling A, step 2): an action's `description`, each param's
5+
* `helpText` and an `outcomeMessages` entry become ADR-0032 `template` slots,
6+
* as `confirmText` / `successMessage` already are (#24814). A parsed slot is
7+
* the `{ dialect: 'template', source }` envelope, so the extraction walk must
8+
* seed the envelope's `source` exactly as it seeds the bare string — read as
9+
* a plain value, the envelope was recorded like an absent key and nothing was
10+
* left to translate.
11+
*
12+
* Both action walks are driven (the object's own `actions[]` and the top-level
13+
* `actions[]`), the regression `i18n-walk-output-parity` exists for.
14+
*/
15+
import { describe, it, expect } from 'vitest';
16+
import { collectExpectedEntries } from '../src/utils/i18n-extract.js';
17+
18+
const envelope = (source: string) => ({ dialect: 'template', source });
19+
20+
/** One action carrying the three slots, either as strings or as envelopes. */
21+
function action(name: string, wrap: (s: string) => unknown, extra: Record<string, unknown> = {}) {
22+
return {
23+
name,
24+
label: 'Pause',
25+
type: 'script',
26+
target: 'pause',
27+
description: wrap('Pause {{ record.name }}?'),
28+
params: [{ name: 'reason', label: 'Reason', type: 'text', helpText: wrap('Why pause {{ record.name }}?') }],
29+
outcomeMessages: { paused: wrap('Paused {{ result.name }}.') },
30+
...extra,
31+
};
32+
}
33+
34+
function config(wrap: (s: string) => unknown): any {
35+
return {
36+
objects: [{ name: 'crm_account', label: 'Account', fields: { name: { label: 'Name' } }, actions: [action('pause_account', wrap)] }],
37+
actions: [action('pause_all', wrap, { objectName: 'crm_account' }), action('pause_global', wrap)],
38+
};
39+
}
40+
41+
/** `path → sourceValue` for the three slots on every action walk. */
42+
function seeds(wrap: (s: string) => unknown): Record<string, unknown> {
43+
const out: Record<string, unknown> = {};
44+
for (const e of collectExpectedEntries(config(wrap))) {
45+
const key = e.path.join('.');
46+
if (key.startsWith('metadataForms.')) continue;
47+
if (/\.(description|helpText|outcomeMessages\.paused)$/.test(key) && /pause_(account|all|global)/.test(key)) {
48+
out[key] = e.sourceValue;
49+
}
50+
}
51+
return out;
52+
}
53+
54+
describe('i18n extraction reads the template envelope on description / helpText / outcomeMessages (#27948)', () => {
55+
it('seeds each envelope exactly as the bare string, on every action walk', () => {
56+
const fromStrings = seeds((s) => s);
57+
const fromEnvelopes = seeds(envelope);
58+
// 3 actions × 3 slots, every one seeded with the authored sentence.
59+
expect(Object.keys(fromStrings)).toHaveLength(9);
60+
expect(Object.values(fromStrings).every((v) => typeof v === 'string' && v.includes('{{'))).toBe(true);
61+
expect(fromEnvelopes).toEqual(fromStrings);
62+
});
63+
64+
it('an inline locale map is still authored, never seeded (unchanged)', () => {
65+
const map = { en: 'Pause it?', 'zh-CN': '暂停?' };
66+
const entry = collectExpectedEntries({
67+
objects: [],
68+
actions: [{ name: 'pause_map', label: 'Pause', type: 'script', target: 'pause', description: map }],
69+
} as any).find((e) => e.path.join('.') === 'globalActions.pause_map.description');
70+
expect(entry).toBeDefined();
71+
expect(entry?.sourceValue).not.toEqual(map);
72+
});
73+
});

‎packages/runtime/src/action-execution.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import { validateActionParams, type ActionSession, type ResolvedActionParam } from '@objectstack/spec/ui';
19+
import { templateSlotSource } from '@objectstack/spec/automation';
1920
// [#15124] The facade's `find` judges its own parameter against the SAME
2021
// declaration its type names, so the refusal and the type cannot drift apart.
2122
import { EngineQueryOptionsSchema, DATA_ACTION_TO_API_OPERATION } from '@objectstack/spec/data';
@@ -2494,7 +2495,10 @@ export function summarizeActionParams(deps: ActionExecutionDeps, action: any, ob
24942495
if (!name) continue;
24952496
const type = jsonTypeOf(deps, p?.type ?? field?.type);
24962497
const label = typeof p?.label === 'string' ? p.label : field?.label;
2497-
const help = p?.helpText ?? field?.description;
2498+
// A param's `helpText` is a `template` slot (#27948, ruling A): the
2499+
// parsed value is `{ dialect: 'template', source }`, so the tool
2500+
// schema reads its text, never the object.
2501+
const help = templateSlotSource(p?.helpText) ?? field?.description;
24982502
const description = [label, help].filter(Boolean).join(' — ') || undefined;
24992503
const optionSource = p?.options ?? field?.options;
25002504
const enumVals = Array.isArray(optionSource)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #27948 (ruling A, step 2): a param's `helpText` becomes an ADR-0032
5+
* `template` slot, so a parsed declaration carries
6+
* `{ dialect: 'template', source }` where it carried a string.
7+
* `summarizeActionParams` joins the help into the agent-facing param
8+
* description; read as a plain value, the envelope printed
9+
* `Reason — [object Object]`. It reads the slot's text, the same sentence the
10+
* bare string gives.
11+
*/
12+
13+
import { describe, it, expect } from 'vitest';
14+
15+
import { summarizeActionParams } from './action-execution.js';
16+
17+
const NO_DEPS: any = {};
18+
const SOURCE = 'Why pause {{ record.name }}?';
19+
20+
const actionWith = (helpText: unknown): any => ({
21+
name: 'pause_account',
22+
type: 'script',
23+
params: [{ name: 'reason', label: 'Reason', type: 'text', helpText }],
24+
});
25+
26+
describe('summarizeActionParams reads a template-envelope helpText (#27948)', () => {
27+
it('the envelope gives the same param description as the bare string', () => {
28+
const fromString = summarizeActionParams(NO_DEPS, actionWith(SOURCE), undefined);
29+
const fromEnvelope = summarizeActionParams(NO_DEPS, actionWith({ dialect: 'template', source: SOURCE }), undefined);
30+
expect(fromString[0].description).toBe(`Reason — ${SOURCE}`);
31+
expect(fromEnvelope).toEqual(fromString);
32+
});
33+
34+
it('an envelope with no source falls back to the bound field description, as an absent helpText does', () => {
35+
const obj = { fields: { reason: { label: 'Reason', type: 'text', description: 'The field help' } } };
36+
const action = (helpText: unknown): any => ({
37+
name: 'pause_account',
38+
params: [{ field: 'reason', ...(helpText === undefined ? {} : { helpText }) }],
39+
});
40+
const absent = summarizeActionParams(NO_DEPS, action(undefined), obj);
41+
expect(absent[0].description).toBe('Reason — The field help');
42+
expect(summarizeActionParams(NO_DEPS, action({ dialect: 'template' }), obj)).toEqual(absent);
43+
});
44+
});

‎ui/packages/app-shell/src/views/metadata-admin/previews/ActionPreview.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
SelectValue,
5454
} from '@object-ui/components';
5555
import type { ActionParam } from '@object-ui/types';
56+
import { actionCopySource, isActionCopyEnvelope } from '@object-ui/core';
5657
import { paramDegradesWithoutTarget } from '../../../utils/paramToField.js';
5758
import { resolveParamWidgetType } from '@object-ui/fields';
5859
import type { MetadataPreviewProps } from '../preview-registry.js';
@@ -87,9 +88,18 @@ interface ResultDialog {
8788
fields?: ResultDialogField[];
8889
}
8990

91+
/**
92+
* The text a copy value shows: a string, an `I18nLabel` map's English (else
93+
* first) value, or — for an action's `template` copy slots (`confirmText`,
94+
* `successMessage`, and since objectstack#27948 `description`, a param's
95+
* `helpText`, an `outcomeMessages` entry) — the `{ dialect: 'template',
96+
* source }` envelope's `source`. Read as a map, the envelope gave the word
97+
* `template`.
98+
*/
9099
function localize(v: unknown): string {
91100
if (v == null) return '';
92101
if (typeof v === 'string') return v;
102+
if (isActionCopyEnvelope(v)) return actionCopySource(v) ?? '';
93103
if (typeof v === 'object') {
94104
const o = v as Record<string, string>;
95105
return o.en ?? o['en-US'] ?? Object.values(o)[0] ?? '';
@@ -456,7 +466,7 @@ function DialogMock({
456466
{p.type && <span className="font-mono text-[9px] text-muted-foreground">{p.type}</span>}
457467
</label>
458468
{renderFieldMock(p, fieldLabel, locale)}
459-
{p.helpText && <div className="text-[10px] text-muted-foreground">{p.helpText}</div>}
469+
{localize(p.helpText) && <div className="text-[10px] text-muted-foreground">{localize(p.helpText)}</div>}
460470
</div>
461471
);
462472
})}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#27948 (ruling A, step 2) — an action's copy slots are `template`
5+
* slots, so a parsed definition carries `{ dialect: 'template', source }`
6+
* where it carried a string: `confirmText` / `successMessage` since #24814,
7+
* a param's `helpText` (and `description`, an `outcomeMessages` entry) now.
8+
*
9+
* The preview drew a param's `helpText` raw — an envelope as a React child,
10+
* the #31 crash — and read `confirmText` / `successMessage` as an `I18nLabel`
11+
* map, which shows the word "template". It reads the envelope's `source`.
12+
*/
13+
14+
import * as React from 'react';
15+
import { describe, it, expect, afterEach } from 'vitest';
16+
import { render, screen, cleanup } from '@testing-library/react';
17+
18+
import { ActionPreview } from '../ActionPreview';
19+
20+
afterEach(cleanup);
21+
22+
const envelope = (source: string) => ({ dialect: 'template', source });
23+
24+
function renderDraft(copy: (s: string) => unknown) {
25+
return render(
26+
<ActionPreview
27+
type="action"
28+
name="pause_account"
29+
draft={{
30+
name: 'pause_account',
31+
label: 'Pause',
32+
type: 'script',
33+
target: 'pauseAccount',
34+
locations: ['record_header'],
35+
confirmText: copy('Pause {{ record.name }}?'),
36+
successMessage: copy('Paused {{ record.name }}'),
37+
params: [{ name: 'reason', label: 'Reason', type: 'text', helpText: copy('Why {{ record.name }} is paused') }],
38+
}}
39+
/>,
40+
);
41+
}
42+
43+
describe('ActionPreview reads the template envelope on action copy (objectstack#27948)', () => {
44+
it('draws each envelope\'s source, never the word "template"', () => {
45+
renderDraft(envelope);
46+
expect(screen.getAllByText('Why {{ record.name }} is paused').length).toBeGreaterThan(0);
47+
expect(screen.getAllByText('Pause {{ record.name }}?').length).toBeGreaterThan(0);
48+
expect(screen.getAllByText('Paused {{ record.name }}').length).toBeGreaterThan(0);
49+
expect(screen.queryByText('template')).toBeNull();
50+
});
51+
52+
it('CONTROL: the bare strings draw the same text', () => {
53+
renderDraft((s) => s);
54+
expect(screen.getAllByText('Why {{ record.name }} is paused').length).toBeGreaterThan(0);
55+
expect(screen.getAllByText('Pause {{ record.name }}?').length).toBeGreaterThan(0);
56+
});
57+
});

‎ui/packages/core/src/actions/ActionRunner.ts‎

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import type { ActionContext, ActionResult, RunnableActionType, UIActionSchema } from '@object-ui/types';
2525
import type { Action as SpecActionInput } from '@objectstack/spec/ui';
2626
import { ExpressionEvaluator } from '../evaluator/ExpressionEvaluator.js';
27-
import { actionCopySource, fillTemplateHoles, fillTransitionalCopy, hasTemplateHoles, type ActionCopyTemplate } from './actionCopyTemplate.js';
27+
import { actionCopySource, actionCopyText, fillTemplateHoles, fillTransitionalCopy, hasTemplateHoles, type ActionCopyTemplate } from './actionCopyTemplate.js';
2828
import { hasDeclaredPredicate } from '../evaluator/declaredPredicate.js';
2929
import { globalUndoManager } from './UndoManager.js';
3030
import { warnOnDeprecatedObjectParams, warnOnUnknownActionKeys } from './actionKeys.js';
@@ -1711,10 +1711,13 @@ export class ActionRunner {
17111711

17121712
// The dialog's `description` / `helpText` read the dispatch's record
17131713
// as `record`: a row dispatch binds none in the runner's context
1714-
// (objectui#12967).
1714+
// (objectui#12967). Both are `template` slots, so a served value may
1715+
// be the envelope: the handler is handed their TEXT
1716+
// (`dialogCopyOf`), as it localizes a string or a locale map.
1717+
const dialogCopy = dialogCopyOf(action, paramDefs);
17151718
const collected = await this.paramCollectionHandler(
1716-
paramDefs,
1717-
action,
1719+
dialogCopy.params,
1720+
dialogCopy.action,
17181721
this.dialogCopyFiller(action),
17191722
run,
17201723
);
@@ -1958,9 +1961,10 @@ export class ActionRunner {
19581961
? (outcomeMessages as Record<string, unknown>)[outcome]
19591962
: undefined;
19601963
const resultRoots = { result: payload, record: this.dispatchRecord(action) };
1961-
if (typeof outcomeCopy === 'string' && outcomeCopy.trim() !== '') {
1964+
const outcomeText = actionCopySource(outcomeCopy);
1965+
if (outcomeText !== undefined && outcomeText.trim() !== '') {
19621966
return fillTransitionalCopy(
1963-
outcomeCopy,
1967+
outcomeText,
19641968
(source) => fillTemplateHoles(source, resultRoots, this.displayLocale?.(), this.tenantCurrency?.()),
19651969
(source) => substituteScopeTokens(source, { result: payload }, (value) => value),
19661970
);
@@ -3234,6 +3238,33 @@ export function readOnSuccessNavigation(value: unknown): OnSuccessNavigation | n
32343238
return value as OnSuccessNavigation;
32353239
}
32363240

3241+
/**
3242+
* The action and param list a param-collection handler is handed, with the
3243+
* two `template` slots the dialog draws — the action's `description` and each
3244+
* param's `helpText` (objectstack#27948, ruling A) — reduced from the
3245+
* envelope to its text (`actionCopyText`). The handler localizes them (a
3246+
* bundle entry over the literal, `pickLocalized` over a locale map) before
3247+
* `interpolate` fills their holes, and both take a string: an envelope handed
3248+
* on would localize to nothing and reach the dialog as an object. A string or
3249+
* a locale map is handed on as written, and so is everything else on the
3250+
* action. Copies only what changes: the runner's own `action` is the one the
3251+
* collected values are merged onto.
3252+
*/
3253+
function dialogCopyOf(
3254+
action: ActionDef,
3255+
params: ActionParamDef[],
3256+
): { action: ActionDef; params: ActionParamDef[] } {
3257+
const description = actionCopyText(action.description);
3258+
const dialogAction = description === action.description
3259+
? action
3260+
: { ...action, description: description as ActionDef['description'] };
3261+
const dialogParams = params.map((param) => {
3262+
const helpText = actionCopyText(param.helpText as unknown);
3263+
return helpText === param.helpText ? param : { ...param, helpText: helpText as string | undefined };
3264+
});
3265+
return { action: dialogAction, params: dialogParams };
3266+
}
3267+
32373268
/**
32383269
* The runner's ONE `${scope.path}` token grammar — the substitution behind
32393270
* `interpolateTarget` (url / api targets and the `onSuccess.navigate` hop) and

0 commit comments

Comments
 (0)