Repository navigation
Commit 148c6eb
feat(spec,studio): a Studio form to create and edit a knowledge source (#38329)
Fixes #37309
Clause-②: yes (widening) — a new exported metadata form,
`knowledgeSourceForm` from `@objectstack/spec/ai`, registered in
`METADATA_FORM_REGISTRY` for `knowledge_source`; no schema key is added
Metadata-protocol: none
Skills-docs: none — the form adds no key and no authoring rule; what a
source may hold, and the cost note it repeats, are already in the
knowledge docs and the skill
## 维护者速读
- 用户能看到什么变化:管理员在 Studio
里可以新建、编辑并发布知识源:选对象,勾选要检索的内容字段和筛选字段,写过滤条件,选切分方式;之前 Studio 没有这个表单。
- 为什么做:知识平台专题第三阶段「不写代码也能配置哪些数据可被检索」,替不写代码的应用作者解决。
- 出错会怎样:作者在保存或发布知识源时碰到表单字段选择器为空或保存被拒;只影响新类型的表单,其它类型的编辑器绑定方式不变,可直接撤回本改动。
- 要你做什么:无。
## What changes
- **`packages/spec/src/ai/knowledge-source.metadata-form.ts`** (new,
exported from `@objectstack/spec/ai`, registered as `knowledge_source`).
Sections Basics (`name`, `label`, `description`, `aiExposed`, `adapter`
as optional free text whose help says blank means the deployment's
store), Records (the `source` composite: `kind`, `object` via
`ref:object`, `content` and `metadataFields` as `field-multi` with
`dependsOn: 'object'`, `where`, `split.strategy|maxChars|minChars`, with
`strategy` marked required and the group's help saying the blank default
holds only when the whole group is blank, so a passage length needs a
strategy) and Refresh (`refresh.onRecordChange`). No control for
`embedding`, `vectorStore`, `adapterConfig`, `refresh.cron` or a
wildcard member.
- **The egress and cost note** sits in `content`'s help, worded after
the knowledge docs' cost section: the first build sends the text of
every listed field of every matching record to the embedding provider,
which bills for it, and keeps it in an index; a rebuild after a change
of embedding model or split sends it again. `adapter`'s help carries the
docs' memory-store callout (every boot rebuilds and re-sends).
- **Studio binds field pickers to the object the form declares**
(`ui/packages/app-shell/src/views/metadata-admin/formBoundObject.ts`,
one line in `ResourceEditPage.tsx`). See the nested `dependsOn` finding
below.
- **Translations**: the form's strings entered every `metadataForms`
bundle through `os i18n extract`; zh-CN, ja-JP and es-ES are translated,
the other locales carry the English text with their source hashes, as
the i18n gate takes for every metadata form.
- **Studio's own zh-CN overlay**
(`ui/packages/app-shell/src/views/metadata-admin/metadata-form-zh-cn.ts`)
names `knowledge_source`: the type label and the field labels, copied
leaf for leaf from the platform's zh-CN bundle, as for every registered
form.
- **API surface**: `api-surface/ai.json` and `export-origins/ai.json`
regenerated for the one new export.
- Changeset `.changeset/37309-knowledge-source-studio-form.md`
(`@objectstack/spec`, `@objectstack/platform-objects`,
`@object-ui/app-shell`, all patch).
### What I found about a nested `dependsOn` for `field-multi`
`field-multi` (like `field-ref`, `filter-builder` and `action-multi`)
reads no `dependsOn` at all: it draws the one field catalog the editor
binds for the whole form (`WidgetContext.objectFields`). The editor
found that object on a fixed list of draft paths
(`interfaceConfig.source`, `data.object`, `object`, `objectName`), so a
knowledge source, whose object is `source.object`, got pickers that
offered nothing whatever its rows declared. The `view.metadata-form.ts`
precedent works only because `data.object` is on that list, not because
a nested path is read. The fix reads the path the form declares — the
first catalog row's `dependsOn`, prefixed by the composites it sits in
(the `page.metadata-form.ts` spelling, `columns` inside
`interfaceConfig` naming `source`) — and only after the fixed list, so
every type it already served binds as before; the test asserts the
derived path agrees with the fixed list for `ai_context`, `page` and
`view`. A repeater's rows are not walked (their `dependsOn` names a key
of each row).
## Tests
Final head `59defa6ffe`, a merge of `origin/main` at `600197a6ae`
(`63dfdc103f`) plus three commits. Every heavy run went through
`os-verify-lock.sh`, and each `VERDICT` line read command-exit 0. The
runs at `0b20f7cce9` are spec, platform-objects, dogfood and the
`ResourceEditPage` suite. The one commit after it adds only Studio's
zh-CN overlay entry, and its tests ran on that tree.
- **Spec**: `pnpm --filter @objectstack/spec test` — `Test Files 913
passed (913)`, `Tests 28897 passed | 1 todo`; `typecheck` exit 0.
`src/ai/knowledge-source.metadata-form.test.ts` now has 9 tests. The new
one shows that `split: { maxChars: 600 }` alone is refused at
`source.split.strategy`; its control shows the same length with a
strategy parses, and so does a blank group.
- **Studio editor** (`ui/`): `pnpm exec vitest run
packages/app-shell/src/views/metadata-admin/ResourceEditPage` — `Test
Files 66 passed (66)`, `Tests 337 passed (337)`. New in
`ResourceEditPage.formBoundObject-37309.test.tsx`: the real editor opens
a source authored in Studio and enters Edit. It types into the Label and
Longest passage controls and clicks Save. The body it writes is the
edit, with every other value as it was. The form i18n tests
(`metadata-form-i18n`, `metadata-form-option-names`, the two
`SchemaForm` label tests) and `src/preview` read `Test Files 55 passed
(55)`, `Tests 427 passed (427)`. `@object-ui/app-shell type-check` exit
0.
- **Translations**: `pnpm --filter @objectstack/platform-objects test` —
`Test Files 130 passed (130)`, `Tests 2214 passed (2214)`; `typecheck`
exit 0.
- **Round trip on a booted showcase**:
`test/knowledge-source-studio-roundtrip.dogfood.test.ts` — `Test Files 1
passed (1)`, `Tests 5 passed (5)`; `@objectstack/dogfood typecheck` exit
0. New: an edit. The test reads the saved source back, changes the
label, the content order and the split, and saves it through the same
door (draft PUT, publish). The read-back shows the change with nothing
else moved, and `search_knowledge` names the new label with no restart.
- Earlier rounds: CLI `i18n-coverage` 32/32, `metadata-protocol`
`protocol.meta-types-*` 46/46, `lint` `validate-predicate-path-refs`
62/62.
<details><summary>Ablation of the form-declared binding (one run,
restored)</summary>
`scripts/ablation-replace.mjs` replaced the `|| objectNameAt(draft,
declaredBoundObjectPath(entry?.form))` fallback in
`ResourceEditPage.tsx` (anchor 1 to 0, blob `189514d7b2f1` to
`e617589c7a53`). The binding test went red on the real-editor case: `×
reads the catalog of source.object, and the content picker draws that
object's field labels`, `Tests 1 failed | 4 passed (5)`. Restored: blob
equal to HEAD and `git diff HEAD` empty. The test imports the editor
from source, so no build sits between the mutation and the run.
</details>
<details><summary>Counts and translations this form moves</summary>
- The display-echo ledgers count `knowledge_source` as a panel type now
that it has a form: bare 17 to 16, panel 18 to 19, 27 bare leaves. The
translated-label control is main's 846 (#37402) plus this form's twenty
labels, 866. The merge resolved that line by hand as main's number plus
this form's delta.
- The eleven bundles were regenerated after the merge with `node
scripts/check-i18n-bundles.mjs --write`. Only `en` changed, for the
reworded split help, which shows the auto-merged bundles were what
regeneration writes. zh-CN, ja-JP and es-ES carry the reworded help,
re-translated by hand as the bundle headers require. The form's four
select choices are named in all ten locales.
</details>
## Acceptance notes
- **`source.where` uses the JSON editor, not `filter-builder`** (the
card named `filter-builder`). `filter-builder` writes a view rule list
(`[{ field, operator, value }]`); `where` is an ObjectQL filter record,
which `KnowledgeSourceSchema` refuses as a list — pinned in the form
test. The JSON editor is the `report.metadata-form.ts` `runtimeFilter`
precedent.
- **Create seed**: none added. The seed is optional in Studio's editor
(`specCreateSeed` in `ResourceEditPage.tsx`): with none, create opens
the form blank and the author picks the kind and the object. A seed, if
one is wanted, is row 5b's.
- **Save-time refusals** (`manage_knowledge_sources`, source admission
as the author) are row 3a's, pinned in
`packages/rest/src/meta-type-write-capability.test.ts` and
`packages/metadata-core/src/knowledge-source-save-admission.test.ts`;
Studio shows them through the same refusal path as every kind. This PR
adds no refusal-specific UI test.
- **Browser run**: not done here, because this container has no browser.
The round trip is pinned in two legs. (1) Form to body: the real
`MetadataResourceEditPage` binds the pickers to `source.object`, and its
controls write the body Save sends (label and passage length, for an
edit). (2) Body to search: a booted showcase takes such a body through
the draft PUT and publish that Studio's Save sends, for a create and
then an edit, and `search_knowledge` over the live `/mcp` transport
follows each with no restart. The read-back parses with
`KnowledgeSourceSchema`. Not driven: the select and field-picker
controls typed end to end. The dogfood body is a literal of the keys the
form offers.
- **Nested `required`**: the editor judges a `required` mark only on
top-level rows, so `split.strategy`'s mark is the asterisk. The group's
help and the length rows' help carry the rule, and the save door's
refusal is the enforcement.
## Verification
Read first (by risk):
1. `ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.tsx`
— the `sourceObjectName` hunk: the declared path is the last fallback,
so no existing type changes binding.
2. `ui/packages/app-shell/src/views/metadata-admin/formBoundObject.ts` —
the composite walk.
3. `packages/spec/src/ai/knowledge-source.metadata-form.ts` — the rows
and the cost wording.
Two-minute check: `pnpm --filter @objectstack/spec exec vitest run
--maxWorkers=2 src/ai/knowledge-source.metadata-form.test.ts` — expect 9
tests passing.
<details><summary>Derived gates (local subset)</summary>
At `59defa6ffe`, `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 94 commands. All 94 ran and exited
0. `--ran` reconciliation: `94 derived famil(ies) accounted for — 94
run, 0 NOT-MEASURED`. That includes `check:dual-build-cjs-loads`, now
measured, plus `check:query-options-erasure`, `check:type-check-debt`
and `pnpm --dir ui exec vitest run scripts/` (`Test Files 172 passed | 2
skipped`). The full dogfood battery is not owed: the title has no `!`
and there is no `(narrowing)` arm.
CI on `59defa6ffe`: 71 check-runs, 61 success and 10 skipped, none
failed. `Test UI (1/16)`, which was red on `0b20f7cce9` for the missing
zh-CN overlay, is green. The PR reads `mergeable_state: clean`.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
<!-- signed: repo:objectstack#1 · os-elon-musk ·
session_016WV4cwPhGV4g9p1BGQaZbP -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent ce51400 commit 148c6eb
32 files changed
Lines changed: 2080 additions & 21 deletions
File tree
- .changeset
- packages
- platform-objects/src/apps/translations
- qa/dogfood/test
- spec
- api-surface
- export-origins
- src
- ai
- system
- ui/packages/app-shell/src/views/metadata-admin
| 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 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3494 | 3494 | | |
3495 | 3495 | | |
3496 | 3496 | | |
3497 | | - | |
| 3497 | + | |
| 3498 | + | |
| 3499 | + | |
| 3500 | + | |
| 3501 | + | |
| 3502 | + | |
| 3503 | + | |
| 3504 | + | |
| 3505 | + | |
| 3506 | + | |
| 3507 | + | |
| 3508 | + | |
| 3509 | + | |
| 3510 | + | |
| 3511 | + | |
| 3512 | + | |
| 3513 | + | |
| 3514 | + | |
| 3515 | + | |
| 3516 | + | |
| 3517 | + | |
| 3518 | + | |
| 3519 | + | |
| 3520 | + | |
| 3521 | + | |
| 3522 | + | |
| 3523 | + | |
| 3524 | + | |
| 3525 | + | |
| 3526 | + | |
| 3527 | + | |
| 3528 | + | |
| 3529 | + | |
| 3530 | + | |
| 3531 | + | |
| 3532 | + | |
| 3533 | + | |
| 3534 | + | |
| 3535 | + | |
| 3536 | + | |
| 3537 | + | |
| 3538 | + | |
| 3539 | + | |
| 3540 | + | |
| 3541 | + | |
| 3542 | + | |
| 3543 | + | |
| 3544 | + | |
| 3545 | + | |
| 3546 | + | |
| 3547 | + | |
| 3548 | + | |
| 3549 | + | |
| 3550 | + | |
| 3551 | + | |
| 3552 | + | |
| 3553 | + | |
| 3554 | + | |
| 3555 | + | |
| 3556 | + | |
| 3557 | + | |
| 3558 | + | |
| 3559 | + | |
| 3560 | + | |
| 3561 | + | |
| 3562 | + | |
| 3563 | + | |
| 3564 | + | |
| 3565 | + | |
| 3566 | + | |
| 3567 | + | |
| 3568 | + | |
| 3569 | + | |
| 3570 | + | |
| 3571 | + | |
| 3572 | + | |
| 3573 | + | |
| 3574 | + | |
| 3575 | + | |
| 3576 | + | |
| 3577 | + | |
| 3578 | + | |
| 3579 | + | |
| 3580 | + | |
| 3581 | + | |
| 3582 | + | |
| 3583 | + | |
| 3584 | + | |
| 3585 | + | |
| 3586 | + | |
| 3587 | + | |
| 3588 | + | |
| 3589 | + | |
3498 | 3590 | | |
3499 | 3591 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
53 | 93 | | |
54 | 94 | | |
55 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
821 | 821 | | |
822 | 822 | | |
823 | 823 | | |
824 | | - | |
825 | | - | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
826 | 828 | | |
827 | 829 | | |
828 | 830 | | |
829 | 831 | | |
830 | 832 | | |
831 | | - | |
832 | | - | |
833 | | - | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
834 | 837 | | |
835 | 838 | | |
836 | 839 | | |
| |||
912 | 915 | | |
913 | 916 | | |
914 | 917 | | |
915 | | - | |
| 918 | + | |
916 | 919 | | |
917 | 920 | | |
918 | 921 | | |
919 | 922 | | |
920 | 923 | | |
921 | | - | |
| 924 | + | |
922 | 925 | | |
923 | 926 | | |
924 | 927 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3494 | 3494 | | |
3495 | 3495 | | |
3496 | 3496 | | |
3497 | | - | |
| 3497 | + | |
| 3498 | + | |
| 3499 | + | |
| 3500 | + | |
| 3501 | + | |
| 3502 | + | |
| 3503 | + | |
| 3504 | + | |
| 3505 | + | |
| 3506 | + | |
| 3507 | + | |
| 3508 | + | |
| 3509 | + | |
| 3510 | + | |
| 3511 | + | |
| 3512 | + | |
| 3513 | + | |
| 3514 | + | |
| 3515 | + | |
| 3516 | + | |
| 3517 | + | |
| 3518 | + | |
| 3519 | + | |
| 3520 | + | |
| 3521 | + | |
| 3522 | + | |
| 3523 | + | |
| 3524 | + | |
| 3525 | + | |
| 3526 | + | |
| 3527 | + | |
| 3528 | + | |
| 3529 | + | |
| 3530 | + | |
| 3531 | + | |
| 3532 | + | |
| 3533 | + | |
| 3534 | + | |
| 3535 | + | |
| 3536 | + | |
| 3537 | + | |
| 3538 | + | |
| 3539 | + | |
| 3540 | + | |
| 3541 | + | |
| 3542 | + | |
| 3543 | + | |
| 3544 | + | |
| 3545 | + | |
| 3546 | + | |
| 3547 | + | |
| 3548 | + | |
| 3549 | + | |
| 3550 | + | |
| 3551 | + | |
| 3552 | + | |
| 3553 | + | |
| 3554 | + | |
| 3555 | + | |
| 3556 | + | |
| 3557 | + | |
| 3558 | + | |
| 3559 | + | |
| 3560 | + | |
| 3561 | + | |
| 3562 | + | |
| 3563 | + | |
| 3564 | + | |
| 3565 | + | |
| 3566 | + | |
| 3567 | + | |
| 3568 | + | |
| 3569 | + | |
| 3570 | + | |
| 3571 | + | |
| 3572 | + | |
| 3573 | + | |
| 3574 | + | |
| 3575 | + | |
| 3576 | + | |
| 3577 | + | |
| 3578 | + | |
| 3579 | + | |
| 3580 | + | |
| 3581 | + | |
| 3582 | + | |
| 3583 | + | |
| 3584 | + | |
| 3585 | + | |
| 3586 | + | |
| 3587 | + | |
| 3588 | + | |
| 3589 | + | |
3498 | 3590 | | |
3499 | 3591 | | |
0 commit comments