Repository navigation
Commit 68250f6
feat(studio): author context packs (ai_context) in Studio — a form, and a related-lists block scoped to each child (#37315)
<!-- claude-projects-attribution: {"github_login":"os-alice"} -->
_Requested by **Alice** · [project
thread](https://claude.ai/code/project/chan_01NoziMoftaSPmzgKNjJGePH?thread=cmsg_01NoziMoftaSPmzgKNjJGePH8HwrkPJDQVtqCcoED6n6og)_
Fixes #37143
Clause-②: yes (widening) — one new public export, `aiContextForm` from
`@objectstack/spec/ai`, and `/meta/types` now serves a form for
`ai_context`; no key is added to what a pack may hold
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:应用作者在 Studio
里可以新建、编辑资料包:选根对象和它的字段,选指向它的关联列表并为每个列表选列,选正文字段,再保存发布。
- 为什么做:记录 AI 问询专题的第 7 步,让资料包不必写在代码包里(运行时可编辑)。
- 出错会怎样:最坏是编辑界面选项不对或保存被拒;已有的资料包和对象的关联列表编辑不受影响,可以直接撤回。
- 要你做的:无。
## What changes
ADR-0160 D1, clause 2 (runtime authoring). The type was already
registered with `allowRuntimeCreate: true` and its author defects are
already reported at save (`validateAiContext` on the runtime publish
door); what was missing was a form, so Studio's generic metadata editor
had nothing to lay a pack out with.
- **`aiContextForm`** (`packages/spec/src/ai/ai-context.form.ts`,
exported from `@objectstack/spec/ai`, registered as `ai_context` in
`METADATA_FORM_REGISTRY`), by the `skill.form.ts` precedent. Two
sections: Basics (`name`, `label`, the root `object` through
`ref:object`) and Material (`fields` as `field-multi` with `dependsOn:
'object'`, the `page.form.ts` precedent; `related` as
`related-list-entries` with `dependsOn: 'object'`, the `object.form.ts`
precedent; `body` as a composite whose `field` is a `field-ref` over the
root). The form names every top-level key `AiContextSchema` accepts and
no other (the registry-wide reconciliation test).
- **The `related-list-entries` block learns the pack's entry shape**
(`ui/packages/app-shell/src/views/metadata-admin/ContextPackRelatedEntries.tsx`).
A pack entry is `{ object, field?, fields? }`, not the object form's
bare name or `{ list, label?, columns? }`, so the block now tells the
two apart by the entry schema it is handed (`items.properties.object`),
never by the type's name:
- the add picker offers every reference field of a served object whose
target is the root, resolved with the spec's own `REFERENCE_VALUE_TYPES`
and `referenceTargetOf`, the link `validateAiContext` resolves (a
self-reference and each of a child's several links included); a pick is
written `{ object, field }`;
- each entry's columns are picked from THAT child object's fields
(`useObjectFields`, draft-overlaid), never the root's;
- it stops at the schema's `maxItems` (3 lists, 10 columns), and an
emptied list or column set removes its key (both arrays are `minItems:
1`);
- a stored entry the catalog shows no link for is kept and marked; the
save-time report is its judge.
- The object form's `relatedLists` keeps its chip face, unchanged
(`RelatedListNameEntries`, the old body).
- while the object list is loading, or after it failed
(`getTypeStatus('object')`), no stored entry is marked unlinked and the
add picker says loading / could not load, never "no reference field".
- **An emptied picker removes its key** (L2 review on this PR, S1).
Removing the last chip of a `field-multi` whose schema has `minItems >=
1` (the pack's `fields`) removes the key instead of writing `[]`; in a
composite, a cleared sub-field drops its key (as `setField` already does
at the top level), and a composite left empty while its schema requires
a key that has no default is removed (the pack's `body` after "None")
instead of written as `{ field: '' }`. A composite whose required keys
all carry a default keeps `{}` (S3: `/meta/types` serves the output
derivation, which lists a defaulted key as required; a view's
`pagination: {}` and `selection: {}` are read by their presence). Both
were drafts the save door refuses with no way back in the form.
`SchemaForm.tsx` (`compositeWith`) and `widgets.tsx`
(`emptyArrayRefused`).
- **Words**: eleven `engine.form.contextPack.*` keys in the studio
namespace (en, zh); the platform's `metadataForms.ai_context` bundles
regenerated (`node scripts/check-i18n-bundles.mjs --write`), with the
zh-CN leaves translated by hand, and the console's zh-CN overlay rows
(`metadata-form-zh-cn.ts`) copied from them.
- `api-surface/ai.json` and `export-origins/ai.json` regenerated for the
one new export.
#37180's outcome, read for the soft dependency: PR #37209 (merged by the
maintainer) puts `ai_context` in ADR-0150's package-scoped bucket beside
`skill`. A pack created in Studio is therefore saved the way a skill
created in Studio is, into the package the editor is working in; nothing
in this PR picks a package for it, and the reader move is #37216.
## Tests
- `packages/spec/src/ai/ai-context.form.test.ts`: the registry entry,
the identity rows, and every picker scoped by `object`.
-
`ui/packages/app-shell/src/views/metadata-admin/ContextPackRelatedEntries-37143.test.tsx`
(12): the four rework pins (loading / idle / error catalog marks
nothing; the pack's last root field removed writes no key; an array
without `minItems` still writes `[]`; "None" for the body removes
`body`, a composite requiring nothing keeps `{}`), and the original
eight: the schema discriminator; the links offered (four, the
self-reference and both links of one child, an unrelated object absent);
a pick written as `{ object, field }`; columns offered from the child,
not the root; column and list removal dropping their keys; an unlinked
stored entry kept and marked and a listed link not offered again; the
bound and the no-root state; the host id on the add picker. Every value
the block writes is parsed with `AiContextSchema`.
- `RelatedListEntriesWidget-35923.test.tsx` (the object form's face)
still passes unchanged.
- `openPathObjectReaders-12811.test.ts` (app-shell console): one row,
`ContextPackRelatedEntries.tsx` classified `off` among the readers of
`useMetadata().objects` (the block reads the served object list for its
link catalog and is mounted only in the metadata admin, never on an
app's object-list open).
- `bare-type-display-echo-decisions.test.ts` and
`object-lifecycle-panel-echo-decisions.test.ts` (platform-objects):
literal counts and a dated comment row only, because `ai_context` now
has a form and its eighteen leaves are authored in zh-CN, ja-JP and
es-ES (surface widened by the seat, claim amendment 1).
<details><summary>Local runs (head 4b6929e)</summary>
- `pnpm --filter @objectstack/spec test`: exit 0. `pnpm --filter
@objectstack/spec typecheck`: exit 0.
- `pnpm --filter @objectstack/platform-objects test`: Test Files 126
passed (126), Tests 2161 passed (2161). typecheck: exit 0.
- `ui`: `pnpm exec vitest run
packages/app-shell/src/views/metadata-admin/
packages/app-shell/src/__tests__/`: Test Files 824 passed (824), Tests
9036 passed, 1 skipped. `packages/i18n/`: Test Files 111 passed (111).
The rest of app-shell's suite is left to `Test UI` (a full local run did
not finish in 54 minutes on the shared box and was stopped).
- Ablation, once: the pack branch of `RelatedListEntriesWidget` disabled
(`if (false && isContextPackEntrySchema(schema))`, written and restored
by `scripts/ablation-replace.mjs`, blob equal to HEAD after restore)
turns the new file red, 7 failed of 8; the one that stays green is the
helper-only case.
- `node scripts/check-i18n-bundles.mjs`: exit 0, every bundle in sync.
`pnpm --filter @objectstack/spec check:generated`: api-surface and
export-origins regenerated with `--fix`, then clean.
- After the merge of `main` and the reader-table row:
`packages/app-shell/src/console/__tests__/openPathObjectReaders-12811.test.ts`
3/3 (it was the one red file of `Test UI (15/16)` at 7d37a1d); spec 894
files and platform-objects 126/2161 green again after the merge.
- `node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack
--ran`: at 4b6929e, 93 derived, 92 run, 1 NOT-MEASURED (exit 3,
prerequisite not met here: `check-plugin-teardown-shape.mjs
--self-test`), 0 UNRUN.
- CI at 3a215ad: 59 success, 10 expected skip, 0 failed. At 6ada5fd:
57 success, 10 expected skip, 2 failed (`Test UI (5/16)` and its
aggregator), the one failure
`packages/auth/src/__tests__/AuthProvider.test.tsx` (objectstack#36972
pin, `mounts` 2 vs 1), in a package this PR does not touch; it passed 3
of 3 runs locally at 6ada5fd. At 4b6929e: 59 success, 10 expected
skip, 0 failed.
- Rework (6ada5fd): `ui` `pnpm exec vitest run
packages/app-shell/src/views/metadata-admin/
packages/app-shell/src/console/__tests__/openPathObjectReaders-12811.test.ts`:
Test Files 800 passed (800), Tests 8588 passed, 1 skipped. Ablation, one
at a time with `scripts/ablation-replace.mjs` (blob equal to HEAD after
each restore): the `field-multi` prune off, the composite's
empty-required prune deleted, the catalog state forced `ready`; each
turns exactly its own pin red (1 failed of 12).
- Rework 2 (4b6929e): `ui` `pnpm exec vitest run
packages/app-shell/src/views/metadata-admin/`: Test Files 799 passed
(799), Tests 8589 passed, 1 skipped;
`ContextPackRelatedEntries-37143.test.tsx` 16/16, its new pins built on
the SERVED derivation (`z.toJSONSchema(getMetadataTypeSchema(type), {
unrepresentable: 'any' })`): view `pagination`, `selection`, `gallery`
keep `{}`, view `kanban` and the pack's `body` are removed. Ablation:
the default check removed (every required key counts) turns those three
red (3 failed of 16), restored to HEAD. Swept every composite row of the
registered forms against the served derivation: the rows whose required
keys all carry defaults (view `selection`, `pagination`, `gallery`,
`userFilters`, `appearance`, `userActions`, `navigation`, `sharing`;
object `enable`, `access`, `publicSharing`; field `currencyConfig`; hook
`retryPolicy`; report and dashboard `dateRange`, dashboard `header`;
page `interfaceConfig.appearance`, `interfaceConfig.userActions`; agent
`planning`; flow `errorHandling`) keep `{}`; the rest have a required
key with no default and are removed when emptied.
- NOT MEASURED locally: `@object-ui/app-shell` and `@object-ui/i18n`
type-check (the ui workspace's own packages have no `dist/` in this
container, so tsc stops on module resolution); `Type Check UI` is the
reading.
</details>
## Acceptance notes
- The card's end-to-end clause (an author creates a pack in Studio and
`get_record_context` serves it) is covered here in pieces, not by one
booted host: the block's every write parses as a pack; the metadata API
save of an `ai_context` row is `protocol.runtime-authoring-gate.test.ts`
(metadata-protocol); the record-context door reads the protocol's merged
`ai_context` listing (`mcp-record-context-tools-bridge.test.ts`,
runtime). Measured once live as well (showcase booted with `objectstack
dev --seed-admin`, the `ui/` console served by Vite against it, Chromium
via Playwright, at the rework's source): Studio → AI → AI Context Pack →
create `project_brief` on `showcase_project` saved and published (`PUT
…/meta/ai_context/project_brief?mode=draft` 200, `POST …/publish` 200);
edit: root fields `name`, `status`; the add picker offered the four
links to the root (`showcase_client_brief.project`,
`showcase_field_zoo.f_master_detail`,
`showcase_project_membership.project`, `showcase_task.project`); the
columns offered were `showcase_task`'s fields; body chosen then set to
"None"; saved body `{"name":"project_brief","label":"Project
brief","object":"showcase_project","fields":["name","status"],"related":[{"object":"showcase_task","field":"project","fields":["title","status"]}]}`
(no `body` key), 200 and published. A second edit removed both root
fields: saved without `fields`, 200. Then MCP `get_record_context`
(`objectName: showcase_project`, `context: project_brief`) on a seeded
project answered the pack, with the task rows' `title` and `status`.
- The body picker offers every root field, not only the long-text ones:
`field-ref` has no type filter, and a non-long-text pick is reported at
save (`ai-context-body-not-long-text`).
- The link catalog is the console's served object list
(`useMetadata().objects`); an object it does not serve is not offered,
and a stored entry naming one is kept and marked.
## Verification
Two minutes: open Studio, pick a package, open AI → AI Context Pack
(advanced fold), create one; choose a root object with a child list
(showcase: an object another object looks up), add the related list and
pick a column. Expected: the column picker lists the child object's
fields, and the Source tab shows `related: [{ object, field, fields }]`.
Read first, by risk: `ContextPackRelatedEntries.tsx`
(`contextPackLinks`, `ContextPackRelatedEntries`), the dispatch at the
top of `RelatedListEntriesWidget` in `widgets.tsx`,
`ai-context.form.ts`.
---
_Generated by [Claude
Code](https://claude.ai/code/session_011y7As7YaCaudBfnWZagi4R)_
<!-- signed: repo:objectstack#7 · os-alice ·
session_011y7As6JrAPNfuwC2RLXXGu -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent c3c04a2 commit 68250f6
35 files changed
Lines changed: 1513 additions & 25 deletions
File tree
- .changeset
- packages
- platform-objects/src/apps/translations
- spec
- api-surface
- export-origins
- src
- ai
- system
- ui/packages
- app-shell/src
- console/__tests__
- views/metadata-admin
- i18n/src/namespaces/studio
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3161 | 3161 | | |
3162 | 3162 | | |
3163 | 3163 | | |
3164 | | - | |
| 3164 | + | |
| 3165 | + | |
| 3166 | + | |
| 3167 | + | |
| 3168 | + | |
| 3169 | + | |
| 3170 | + | |
| 3171 | + | |
| 3172 | + | |
| 3173 | + | |
| 3174 | + | |
| 3175 | + | |
| 3176 | + | |
| 3177 | + | |
| 3178 | + | |
| 3179 | + | |
| 3180 | + | |
| 3181 | + | |
| 3182 | + | |
| 3183 | + | |
| 3184 | + | |
| 3185 | + | |
| 3186 | + | |
| 3187 | + | |
| 3188 | + | |
| 3189 | + | |
| 3190 | + | |
| 3191 | + | |
| 3192 | + | |
| 3193 | + | |
| 3194 | + | |
| 3195 | + | |
| 3196 | + | |
| 3197 | + | |
| 3198 | + | |
| 3199 | + | |
| 3200 | + | |
| 3201 | + | |
| 3202 | + | |
| 3203 | + | |
| 3204 | + | |
3165 | 3205 | | |
3166 | 3206 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
21 | 39 | | |
22 | 40 | | |
23 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
813 | 813 | | |
814 | 814 | | |
815 | 815 | | |
816 | | - | |
817 | | - | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
818 | 820 | | |
819 | | - | |
| 821 | + | |
820 | 822 | | |
821 | 823 | | |
822 | 824 | | |
823 | | - | |
824 | | - | |
825 | | - | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
826 | 828 | | |
827 | 829 | | |
828 | 830 | | |
| |||
904 | 906 | | |
905 | 907 | | |
906 | 908 | | |
907 | | - | |
| 909 | + | |
908 | 910 | | |
909 | 911 | | |
910 | 912 | | |
911 | 913 | | |
912 | 914 | | |
913 | | - | |
| 915 | + | |
914 | 916 | | |
915 | 917 | | |
916 | 918 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3161 | 3161 | | |
3162 | 3162 | | |
3163 | 3163 | | |
3164 | | - | |
| 3164 | + | |
| 3165 | + | |
| 3166 | + | |
| 3167 | + | |
| 3168 | + | |
| 3169 | + | |
| 3170 | + | |
| 3171 | + | |
| 3172 | + | |
| 3173 | + | |
| 3174 | + | |
| 3175 | + | |
| 3176 | + | |
| 3177 | + | |
| 3178 | + | |
| 3179 | + | |
| 3180 | + | |
| 3181 | + | |
| 3182 | + | |
| 3183 | + | |
| 3184 | + | |
| 3185 | + | |
| 3186 | + | |
| 3187 | + | |
| 3188 | + | |
| 3189 | + | |
| 3190 | + | |
| 3191 | + | |
| 3192 | + | |
| 3193 | + | |
| 3194 | + | |
| 3195 | + | |
| 3196 | + | |
| 3197 | + | |
| 3198 | + | |
| 3199 | + | |
| 3200 | + | |
| 3201 | + | |
| 3202 | + | |
| 3203 | + | |
| 3204 | + | |
3165 | 3205 | | |
3166 | 3206 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
26 | 44 | | |
27 | 45 | | |
28 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3161 | 3161 | | |
3162 | 3162 | | |
3163 | 3163 | | |
3164 | | - | |
| 3164 | + | |
| 3165 | + | |
| 3166 | + | |
| 3167 | + | |
| 3168 | + | |
| 3169 | + | |
| 3170 | + | |
| 3171 | + | |
| 3172 | + | |
| 3173 | + | |
| 3174 | + | |
| 3175 | + | |
| 3176 | + | |
| 3177 | + | |
| 3178 | + | |
| 3179 | + | |
| 3180 | + | |
| 3181 | + | |
| 3182 | + | |
| 3183 | + | |
| 3184 | + | |
| 3185 | + | |
| 3186 | + | |
| 3187 | + | |
| 3188 | + | |
| 3189 | + | |
| 3190 | + | |
| 3191 | + | |
| 3192 | + | |
| 3193 | + | |
| 3194 | + | |
| 3195 | + | |
| 3196 | + | |
| 3197 | + | |
| 3198 | + | |
| 3199 | + | |
| 3200 | + | |
| 3201 | + | |
| 3202 | + | |
| 3203 | + | |
| 3204 | + | |
3165 | 3205 | | |
3166 | 3206 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3161 | 3161 | | |
3162 | 3162 | | |
3163 | 3163 | | |
3164 | | - | |
| 3164 | + | |
| 3165 | + | |
| 3166 | + | |
| 3167 | + | |
| 3168 | + | |
| 3169 | + | |
| 3170 | + | |
| 3171 | + | |
| 3172 | + | |
| 3173 | + | |
| 3174 | + | |
| 3175 | + | |
| 3176 | + | |
| 3177 | + | |
| 3178 | + | |
| 3179 | + | |
| 3180 | + | |
| 3181 | + | |
| 3182 | + | |
| 3183 | + | |
| 3184 | + | |
| 3185 | + | |
| 3186 | + | |
| 3187 | + | |
| 3188 | + | |
| 3189 | + | |
| 3190 | + | |
| 3191 | + | |
| 3192 | + | |
| 3193 | + | |
| 3194 | + | |
| 3195 | + | |
| 3196 | + | |
| 3197 | + | |
| 3198 | + | |
| 3199 | + | |
| 3200 | + | |
| 3201 | + | |
| 3202 | + | |
| 3203 | + | |
| 3204 | + | |
3165 | 3205 | | |
3166 | 3206 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3161 | 3161 | | |
3162 | 3162 | | |
3163 | 3163 | | |
3164 | | - | |
| 3164 | + | |
| 3165 | + | |
| 3166 | + | |
| 3167 | + | |
| 3168 | + | |
| 3169 | + | |
| 3170 | + | |
| 3171 | + | |
| 3172 | + | |
| 3173 | + | |
| 3174 | + | |
| 3175 | + | |
| 3176 | + | |
| 3177 | + | |
| 3178 | + | |
| 3179 | + | |
| 3180 | + | |
| 3181 | + | |
| 3182 | + | |
| 3183 | + | |
| 3184 | + | |
| 3185 | + | |
| 3186 | + | |
| 3187 | + | |
| 3188 | + | |
| 3189 | + | |
| 3190 | + | |
| 3191 | + | |
| 3192 | + | |
| 3193 | + | |
| 3194 | + | |
| 3195 | + | |
| 3196 | + | |
| 3197 | + | |
| 3198 | + | |
| 3199 | + | |
| 3200 | + | |
| 3201 | + | |
| 3202 | + | |
| 3203 | + | |
| 3204 | + | |
3165 | 3205 | | |
3166 | 3206 | | |
0 commit comments