@tristan2828/ui-foundation 4.70.0 → 4.71.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,25 +3,26 @@
3
3
  <!-- index: written by `npm run docs:index` in the package from the headings below; never edit it by hand -->
4
4
  ## Index
5
5
 
6
- - [The reference files](#the-reference-files) · lines 40–62
7
- - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 64–749
8
- - Step 1: Add `<Entity>` to `openapi.yaml` · lines 106–113
9
- - Step 2: `npm run gen:api` · lines 114–115
10
- - Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 116–127
11
- - Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 128–137
12
- - Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 138–142
13
- - Step 6: Copy the reference files, one for one, not just the two screens · lines 143–638
14
- - Step 7: Register routes · lines 639–652
15
- - Step 8: Add Playwright specs for all three screens · lines 653–731
16
- - Step 9: Register the nav entry and route names · lines 732–746
17
- - Step 10: `npm run verify`. · lines 747–749
18
- - [How a list opens a record](#how-a-list-opens-a-record) · lines 751–854
19
- - [The record view](#the-record-view) · lines 829–854
20
- - [What not to copy](#what-not-to-copy) · lines 856–882
21
- - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 884–901
22
- - [Deleting](#deleting) · lines 903–932
23
- - [Fields only a script writes](#fields-only-a-script-writes) · lines 934–955
24
- - [Searching one part of the app](#searching-one-part-of-the-app) · lines 957–966
6
+ - [The reference files](#the-reference-files) · lines 41–63
7
+ - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 65–752
8
+ - Step 1: Add `<Entity>` to `openapi.yaml` · lines 107–114
9
+ - Step 2: `npm run gen:api` · lines 115–116
10
+ - Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 117–128
11
+ - Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 129–138
12
+ - Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 139–143
13
+ - Step 6: Copy the reference files, one for one, not just the two screens · lines 144–639
14
+ - Step 7: Register routes · lines 640–655
15
+ - Step 8: Add Playwright specs for all three screens · lines 656–734
16
+ - Step 9: Register the nav entry and route names · lines 735–749
17
+ - Step 10: `npm run verify`. · lines 750–752
18
+ - [How a list opens a record](#how-a-list-opens-a-record) · lines 754–892
19
+ - [The record view](#the-record-view) · lines 867–892
20
+ - [What not to copy](#what-not-to-copy) · lines 894–920
21
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 922–939
22
+ - [Deleting](#deleting) · lines 941–970
23
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 972–993
24
+ - [Searching one part of the app](#searching-one-part-of-the-app) · lines 995–1004
25
+ - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1007–1046
25
26
 
26
27
  <!-- /index -->
27
28
 
@@ -649,7 +650,9 @@ is a filled-in example while the Widgets demo is still here).
649
650
  it shows under the module while you're in it.
650
651
  If the plan says records **open in a dialog** over the list (`opens`
651
652
  kind `dialog` or `dialog-only`), the view's route is the list route's
652
- child instead: see [How a list opens a record](#how-a-list-opens-a-record).
653
+ child instead (or, for a list at `/<entity>/list`, its sibling under
654
+ `listPath`; a sub-record opens over its parent's page the same way):
655
+ see [How a list opens a record](#how-a-list-opens-a-record).
653
656
  8. **Add Playwright specs for all three screens**, one test per state
654
657
  (`loading`, `empty`, `error`, `validation`, `success`), forced through
655
658
  MSW overrides — `forceMswOverride`, `waitForMswReady` and the
@@ -789,6 +792,41 @@ plan allows it.
789
792
  <Board renderCard={(item) => <RecordLink to={`/<entity>/${item.id}`}>{item.name}</RecordLink>} … />
790
793
  ```
791
794
 
795
+ **A list that isn't the record's parent route** (4.71: the list at
796
+ `/<entity>/list`, the record at `/<entity>/:id`): the route the two share
797
+ wraps them, with `listPath`. The list's own route has no element (the
798
+ `list` prop draws it), and every other child is a record. Opened from
799
+ the list, the record is the dialog over it; closing goes back to
800
+ `/<entity>/list`; a deep link is the full page, as above.
801
+
802
+ ```tsx
803
+ {
804
+ path: '<entity>',
805
+ element: <RecordDialogRoute list={<<Entity>sTableRoute />} listPath="list" label="<Entity>" />,
806
+ children: [{ path: 'list' }, { path: ':id', element: <<Entity>ViewRoute /> }],
807
+ },
808
+ ```
809
+
810
+ **A sub-record over its parent's page** (4.71: a parent's documents,
811
+ `/<parents>/7/<children>/31`): the same dialog one level down. The
812
+ parent's page is the `list`, the sub-record its child, and
813
+ `fullPage={false}`, so a reload of the sub-record's address is the dialog
814
+ over the parent again. The parent's table of sub-records says
815
+ `` opens={{ kind: 'dialog-only', to: (row) => `/<parents>/${row.parentId}/<children>/${row.id}` }} ``,
816
+ and the sub-record's view is its ordinary `EntityView` (`back` to the
817
+ parent). Keep the parent's other routes (its `edit`) siblings of
818
+ `<parents>/:id`, not its children: every child of the route is drawn in
819
+ the dialog.
820
+
821
+ ```tsx
822
+ {
823
+ path: '<parents>/:id',
824
+ element: <RecordDialogRoute list={<<Parent>ViewRoute />} label="<Child>" fullPage={false} />,
825
+ children: [{ path: '<children>/:childId', element: <<Child>ViewRoute /> }],
826
+ },
827
+ { path: '<parents>/:id/edit', element: <<Parent>FormRoute /> }, // a sibling, not a child
828
+ ```
829
+
792
830
  - **The row opens it**: a click on the row, Enter on it, ↑/↓ between
793
831
  rows. So does a click on a link in the row to the record's own address
794
832
  (the name cell can stay a plain `<Link>`), and in a card layout a click
@@ -964,3 +1002,45 @@ question isn't handed purchases and comics too. The tool's description
964
1002
  lists each group's entities, and `group` is offered only when some entity
965
1003
  has one; an unknown group is a refusal naming the ones there are. An
966
1004
  entity with no group is searched only when no group is given.
1005
+
1006
+
1007
+ ## What a chat is told about an entity
1008
+
1009
+ Four more things an app sets for AI chats (4.71), each in
1010
+ `backend/app/mcp_entities.py`:
1011
+
1012
+ - **`description`** on the `McpEntity`: what the entity is, in a sentence
1013
+ (`description="A purchase: what was bought, where and for how much"`).
1014
+ It's shown beside the entity's name in the `search`, `list` and
1015
+ `create` tools, so a chat picks the right one.
1016
+ - **`text_edits`**: the wire names of its long-text fields (notes, a body)
1017
+ that a chat changes in part with the `edit_text` tool
1018
+ (`text_edits=("notes",)`): `old` and `new` replace one passage, which
1019
+ must be found exactly once (missing, or found twice, is a refusal that
1020
+ says so and saves nothing), or `append` adds text on a new line at the
1021
+ end. It saves and logs as `update` does, so a long note isn't sent back
1022
+ whole to change a line. Each must be a text field of `update_schema`
1023
+ and not `script_only`; the backend refuses to start otherwise.
1024
+ - **The server's instructions** a chat gets when it connects:
1025
+ `register_entities(ENTITIES, instructions="…")` (or
1026
+ `register_instructions("…")`) adds the app's own words after the
1027
+ built-in ones; `register_instructions("…", replace=True)` sends only
1028
+ the app's. The built-in ones are written from the entities: which can
1029
+ be deleted (soft only, with restore; "Nothing can be deleted" only when
1030
+ none can) and which texts `edit_text` changes.
1031
+ - **An answer note**, `register_answer_note(note)`: a function given the
1032
+ caller, the tool's name, its arguments and the entities whose records
1033
+ the answer shows, which returns text appended to the answer after a
1034
+ blank line, or `None`. Plain or async. It runs after every answer (not
1035
+ a refusal); one that raises is reported and left out, and the answer
1036
+ stands.
1037
+
1038
+ ```python
1039
+ def note(caller, tool, arguments, entities):
1040
+ if any(e.group == "health" for e in entities):
1041
+ return "Health records are the person's own notes, not medical advice."
1042
+ return None
1043
+
1044
+ register_entities(ENTITIES, instructions="Amounts are in the account's currency.")
1045
+ register_answer_note(note)
1046
+ ```
@@ -17,8 +17,17 @@ export type RecordDialogRouteProps = {
17
17
  * over the list. True by default.
18
18
  */
19
19
  fullPage?: boolean;
20
+ /**
21
+ * Where the list lives when it isn't this route's own address: a child
22
+ * route of this one with no element (`'list'` for `/things/list`), or
23
+ * an absolute path under it. This route's other children are its
24
+ * records (`/things/12`), drawn over the list when opened from it. Left
25
+ * out, the list is this route's own address and its children are the
26
+ * records (the nested pattern).
27
+ */
28
+ listPath?: string;
20
29
  };
21
- export declare function RecordDialogRoute({ list, label, className, fullPage }: RecordDialogRouteProps): import("react").JSX.Element;
30
+ export declare function RecordDialogRoute({ list, label, className, fullPage, listPath: listAt }: RecordDialogRouteProps): import("react").JSX.Element | null;
22
31
  export type RecordLinkProps = Omit<ComponentProps<typeof Link>, 'state'>;
23
32
  /**
24
33
  * A link to a record that opens it over the current list (a board's card,
@@ -28,6 +28,25 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
28
28
  // another page opens the dialog over its own list, at the list's plain
29
29
  // address.
30
30
  //
31
+ // A list that isn't the record's parent route (`listPath`, 4.71): the
32
+ // list at /things/list, the record at /things/12, siblings. The route the
33
+ // two share wraps them, its `list` drawn at `listPath` (whose own route
34
+ // has no element) and every other child the record:
35
+ //
36
+ // { path: 'things', element: <RecordDialogRoute list={<ThingsList />} listPath="list" label="Thing" />,
37
+ // children: [{ path: 'list' }, { path: ':id', element: <ThingView /> }] }
38
+ //
39
+ // Opened from the list, /things/12 is the dialog over /things/list, and
40
+ // closing goes back to it; a deep link is the full page, as above.
41
+ //
42
+ // A sub-record over its parent's page (4.71) is the same route one level
43
+ // down: the parent's page is the `list`, the sub-record its child, and
44
+ // `fullPage={false}`, so a reload of /parents/7/children/31 is the dialog
45
+ // over the parent again:
46
+ //
47
+ // { path: 'parents/:id', element: <RecordDialogRoute list={<ParentView />} label="Document" fullPage={false} />,
48
+ // children: [{ path: 'children/:childId', element: <ChildView /> }] }
49
+ //
31
50
  // Inside, the record's route renders as it always does. EntityView sees
32
51
  // the dialog (useRecordDialog): its heading names the dialog, its back link
33
52
  // gives way to the dialog's own bar, and not found's way out closes the
@@ -40,19 +59,24 @@ import { Button, buttonVariants } from '../ui/button.js';
40
59
  import { Dialog, DialogClose, DialogContent } from '../ui/dialog.js';
41
60
  import { escapePassedThrough } from './escape-passthrough.js';
42
61
  import { backgroundOf, recordDialogState, RecordDialogContext } from './record-dialog-context.js';
43
- export function RecordDialogRoute({ list, label, className, fullPage = true }) {
62
+ // Two paths are the same address, give or take a trailing slash.
63
+ const samePath = (a, b) => a.replace(/\/+$/, '') === b.replace(/\/+$/, '');
64
+ export function RecordDialogRoute({ list, label, className, fullPage = true, listPath: listAt }) {
44
65
  const location = useLocation();
45
66
  const navigationType = useNavigationType();
46
67
  const navigate = useNavigate();
47
- const outlet = useOutlet();
68
+ const childOutlet = useOutlet();
48
69
  const titleId = useId();
49
- const listPath = useResolvedPath('.').pathname;
70
+ const listPath = useResolvedPath(listAt ?? '.').pathname;
71
+ // With `listPath`, its own (element-less) child is the list, not a record.
72
+ const atList = listAt !== undefined && samePath(location.pathname, listPath);
73
+ const outlet = atList ? null : childOutlet;
50
74
  const opened = backgroundOf(location.state);
51
75
  // Over its own list only: opened from anywhere else, the list under it
52
76
  // would be a page the user wasn't on.
53
77
  // With no full page, a record opened any other way is the dialog over
54
78
  // the list's plain address, with nothing to go back over.
55
- const background = opened && opened.pathname === listPath
79
+ const background = opened && samePath(opened.pathname, listPath)
56
80
  ? opened
57
81
  : !fullPage && outlet !== null
58
82
  ? { pathname: listPath, search: '', hash: '', depth: 0 }
@@ -77,6 +101,10 @@ export function RecordDialogRoute({ list, label, className, fullPage = true }) {
77
101
  // The record's full page: a deep link, or "Open full page".
78
102
  if (outlet !== null && !open)
79
103
  return outlet;
104
+ // `listPath` given and this route's own address (no index route): there
105
+ // is no list here to draw.
106
+ if (listAt !== undefined && outlet === null && !atList)
107
+ return null;
80
108
  return (_jsxs(_Fragment, { children: [_jsx(LocationContext.Provider, { value: listContext, children: list }), _jsx(Dialog, { open: open, onOpenChange: (next, details) => {
81
109
  if (next)
82
110
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.70.0",
3
+ "version": "4.71.0",
4
4
  "description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
5
5
  "license": "MIT",
6
6
  "repository": {