@genesislcap/ai-assistant 15.46.5 → 15.47.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.
Files changed (52) hide show
  1. package/dist/custom-elements.json +426 -214
  2. package/dist/dts/genesis/config.d.ts +30 -6
  3. package/dist/dts/genesis/config.d.ts.map +1 -1
  4. package/dist/dts/genesis/consumes.d.ts.map +1 -1
  5. package/dist/dts/genesis/event-fields.d.ts.map +1 -1
  6. package/dist/dts/genesis/filter-fields.d.ts +31 -0
  7. package/dist/dts/genesis/filter-fields.d.ts.map +1 -1
  8. package/dist/dts/genesis/index.d.ts +3 -1
  9. package/dist/dts/genesis/index.d.ts.map +1 -1
  10. package/dist/dts/genesis/reference-check.d.ts +83 -0
  11. package/dist/dts/genesis/reference-check.d.ts.map +1 -0
  12. package/dist/dts/genesis/reference-existence.d.ts +110 -0
  13. package/dist/dts/genesis/reference-existence.d.ts.map +1 -0
  14. package/dist/dts/genesis/resource-tools.d.ts +4 -4
  15. package/dist/dts/genesis/resource-tools.d.ts.map +1 -1
  16. package/dist/dts/genesis/review-model.d.ts +2 -2
  17. package/dist/dts/genesis/review-model.d.ts.map +1 -1
  18. package/dist/dts/genesis/row-source.d.ts +32 -0
  19. package/dist/dts/genesis/row-source.d.ts.map +1 -1
  20. package/dist/dts/genesis/server-text.d.ts +29 -0
  21. package/dist/dts/genesis/server-text.d.ts.map +1 -1
  22. package/dist/dts/genesis/types.d.ts +32 -5
  23. package/dist/dts/genesis/types.d.ts.map +1 -1
  24. package/dist/dts/genesis/write-payload.d.ts +14 -1
  25. package/dist/dts/genesis/write-payload.d.ts.map +1 -1
  26. package/dist/dts/genesis/write-plan.d.ts +8 -2
  27. package/dist/dts/genesis/write-plan.d.ts.map +1 -1
  28. package/dist/dts/genesis/write-tools.d.ts +5 -3
  29. package/dist/dts/genesis/write-tools.d.ts.map +1 -1
  30. package/dist/dts/genesis/write-turn.d.ts +4 -1
  31. package/dist/dts/genesis/write-turn.d.ts.map +1 -1
  32. package/dist/esm/genesis/config.js +152 -20
  33. package/dist/esm/genesis/consumes.js +2 -1
  34. package/dist/esm/genesis/event-fields.js +5 -8
  35. package/dist/esm/genesis/filter-fields.js +159 -78
  36. package/dist/esm/genesis/index.js +1 -0
  37. package/dist/esm/genesis/reference-check.js +132 -0
  38. package/dist/esm/genesis/reference-existence.js +283 -0
  39. package/dist/esm/genesis/resource-tools.js +135 -18
  40. package/dist/esm/genesis/review-model.js +3 -1
  41. package/dist/esm/genesis/row-source.js +107 -16
  42. package/dist/esm/genesis/server-text.js +52 -0
  43. package/dist/esm/genesis/write-payload.js +32 -4
  44. package/dist/esm/genesis/write-plan.js +3 -2
  45. package/dist/esm/genesis/write-tools.js +248 -44
  46. package/dist/genesis-consumes.cjs +3 -2
  47. package/dist/genesis-consumes.cjs.map +2 -2
  48. package/dist/genesis-consumes.mjs +3 -2
  49. package/dist/genesis-consumes.mjs.map +2 -2
  50. package/docs/genesis.md +131 -21
  51. package/package.json +17 -17
  52. package/scripts/smoke-genesis-consumes-node.mjs +2 -2
package/docs/genesis.md CHANGED
@@ -7,7 +7,7 @@ model providers from the platform tier table, turns the app's resources into cha
7
7
  hands back one agent to bind to `<foundation-ai-assistant>`. It is what a generated app's mount
8
8
  code calls; the app supplies configuration, never a model id, endpoint or key.
9
9
 
10
- The API is `@beta`. Each `REQ_` resource becomes a read tool. An `EVENT_` resource becomes a write
10
+ The API is `@beta`. Each `REQ_` resource and each query becomes a read tool. An `EVENT_` resource becomes a write
11
11
  tool that shows the user every row it would write and commits only the ones they select, unless
12
12
  it is one of the shapes that get none (see [Write tools](#write-tools)).
13
13
 
@@ -90,7 +90,8 @@ that table, unless asked), then the extensions' prompt.
90
90
  "systemPrompt": "You help traders find and understand their trades.",
91
91
  "resources": [
92
92
  { "name": "REQ_TRADE", "kind": "request", "context": "Trades booked in the app.", "maxRows": 200 },
93
- { "name": "EVENT_TRADE_INSERT", "kind": "event", "op": "insert", "context": "Book a trade." }
93
+ { "name": "EVENT_TRADE_INSERT", "kind": "event", "op": "insert", "context": "Book a trade." },
94
+ { "name": "ALL_TRADES", "kind": "query", "context": "Live trades, as the trades grid shows them." }
94
95
  ]
95
96
  }
96
97
  ```
@@ -99,22 +100,23 @@ that table, unless asked), then the extensions' prompt.
99
100
  | -------------- | ------------------------------------------------------------------------------------------- |
100
101
  | `vendor` | A tier-table vendor. Defaults to `gemini`. |
101
102
  | `tier` | `low`, `high` or `reasoning`. Defaults to `high`. |
102
- | `name` | `REQ_<NAME>` or `EVENT_<NAME>`, unique; the tool name is the lowercased name (≤ 64 chars). |
103
- | `kind` | Must match the prefix: `request` for `REQ_`, `event` for `EVENT_`. |
103
+ | `name` | Unique; the tool name is the lowercased name (≤ 64 chars). `REQ_<NAME>` for a request, `EVENT_<NAME>` for an event, and for a query the dataserver query's own name in upper-case letters, digits and underscores. |
104
+ | `kind` | `request`, `event` or `query`. The kind decides which name rule applies, never the name: a query named `REQ_…` is still a query. |
104
105
  | `context` | Required. Becomes the tool description, so write it for the model. |
105
106
  | `op` | Events only: `insert`, `modify`, `delete` or `custom`. |
106
- | `maxRows` | Requests only: a whole number from 1 to 1000. Defaults to 50. |
107
+ | `maxRows` | Requests and queries: a whole number from 1 to 1000. Defaults to 50. |
107
108
  | `customCode` | Insert, modify and delete events only: the event's handler runs custom code. See [Custom code](#custom-code). |
109
+ | `references` | Inserts and modifies: the values that must match another table's row. See [Reference checks](#reference-checks). |
108
110
 
109
111
  A rule about the config **as a whole** — `enabled`, `vendor`, `tier`, `systemPrompt`, and
110
112
  `resources` being a list — blocks the assistant. A rule about **one resource** leaves that resource
111
113
  out and keeps the rest: it gets no tool, and the console names it and says why. A duplicated name
112
114
  leaves out every copy, since which one is meant is unknown. A `kind` this version does not read
113
- (`request` and `event`) is left out the same way. That keeps an app working when a newer generator
114
- emits one, but it is not support for it. If the config lists resources and every one of them is
115
- left out, the assistant runs on the app's extension tools, and the console names each resource
116
- left out. With no extension tool either, it is blocked: a chat that can reach nothing would still
117
- look like it works.
115
+ (it reads `request`, `event` and `query`) is left out the same way. That keeps an app working when
116
+ a newer generator emits one, but it is not support for it. If the config lists resources and every
117
+ one of them is left out, the assistant runs on the app's extension tools, and the console names
118
+ each resource left out. With no extension tool either, it is blocked: a chat that can reach nothing
119
+ would still look like it works.
118
120
 
119
121
  No `resources` at all, absent or `[]`, is accepted: an assistant whose tools all come from the
120
122
  app's extensions, or a chat helper with none, is a real configuration. It is also exactly what a
@@ -129,8 +131,8 @@ import { GENESIS_AI_CONSUMES } from '@genesislcap/ai-assistant/genesis/consumes'
129
131
 
130
132
  GENESIS_AI_CONSUMES;
131
133
  // {
132
- // kinds: ['request', 'event'],
133
- // resourceFields: ['name', 'kind', 'op', 'context', 'maxRows', 'customCode'],
134
+ // kinds: ['request', 'event', 'query'],
135
+ // resourceFields: ['name', 'kind', 'op', 'context', 'maxRows', 'customCode', 'references'],
134
136
  // vendors: ['anthropic', 'gemini'],
135
137
  // tiers: ['low', 'high', 'reasoning'],
136
138
  // }
@@ -161,7 +163,8 @@ equal to foundation-ai's `AI_TIER_VENDORS` and `AI_TIER_IDS`, which the validato
161
163
 
162
164
  ## Read tools
163
165
 
164
- A `REQ_TRADE` resource becomes the tool `req_trade` with two optional parameters:
166
+ A `REQ_TRADE` resource becomes the tool `req_trade`, and a dataserver query `ALL_TRADES` the tool
167
+ `all_trades` (see [Query reads](#query-reads)). Both take two optional parameters:
165
168
 
166
169
  - `filters` — a list of `{field, op, value}`, all of which must match.
167
170
  - `max_rows` — clamped to the resource's `maxRows`; the resource default when omitted.
@@ -181,7 +184,8 @@ free-text criteria parameter.**
181
184
  reply's fields are what can be filtered on: `REPLY_FIELD`, or `REPLY.FIELD` on a class-typed
182
185
  `requestReply<Input, Output>`. A top-level `FIELD` there describes the **input** class and is
183
186
  never read as the reply. Types and any `VALID_VALUES` come from the same reply. A resource that
184
- describes no fields gets a tool with no `filters` parameter.
187
+ describes no fields gets a tool with no `filters` parameter, and so does a request whose
188
+ metadata comes back as a dataserver's (`TYPE: DATASERVER`), which is never read as a request's.
185
189
  - A field whose allowed values cannot be read — an `ENUM` with no values, or a `VALID_VALUES`
186
190
  that is neither an array nor a pipe-separated string, or a list with any member that does not
187
191
  read — is **not offered as a filter**, and the console names it. Offered without its list, a
@@ -211,13 +215,44 @@ A read never throws. Every result carries `source: 'app-database'` and `untruste
211
215
  { source, untrusted, resource, rows, truncated, note? }
212
216
  // failure
213
217
  { source, untrusted, resource,
214
- error: 'not_connected' | 'invalid_filter' | 'rejected' | 'request_failed', message }
218
+ error: 'not_connected' | 'invalid_filter' | 'rejected' | 'request_failed' | 'unexpected_shape',
219
+ message }
215
220
  ```
216
221
 
217
- `truncated` is the server's `MORE_ROWS` when it sends one; otherwise the rule the platform's own
218
- request datasource uses (an advancing `NEXT_OFFSET` or a full page means there may be more). A
219
- truncated result carries a `note` telling the model these rows are not the full set, and what it
220
- can do: narrow with filters when the tool has any, raise `max_rows` when it is below the cap.
222
+ `truncated` means these rows may not be the full set. For a request it is the server's `MORE_ROWS`
223
+ when it sends one; otherwise the rule the platform's own request datasource uses (an advancing
224
+ `NEXT_OFFSET` or a full page means there may be more). A truncated result carries a `note` telling
225
+ the model these rows are not the full set, and what it can do: narrow with filters when the tool has
226
+ any, raise `max_rows` when it is below the cap.
227
+
228
+ ### Query reads
229
+
230
+ A `kind: 'query'` resource reads a dataserver query once. The bridge sends one `DATA_LOGON` with
231
+ `MAX_ROWS` (always: the server's own default is 250) and the filters' `CRITERIA_MATCH`, and nothing
232
+ else a dataserver takes. The socket logs off on the first update. Filters, `max_rows` and the
233
+ untrusted stamp work as they do for a request.
234
+
235
+ - The query's metadata is fetched under its name exactly as configured, and its fields are the
236
+ dataserver's top-level `FIELD` list. Every typed field of a filterable type, with readable
237
+ allowed values, is offered as a filter; one the server cannot filter on is refused in the
238
+ server's own words.
239
+ - The reply is read as a `QUERY_UPDATE` (`QUERY_HTTP_UPDATE` is also accepted). No `ROW` is an
240
+ empty result only when the reply carries `MORE_ROWS`. Any other shape, or a row that is not an
241
+ `INSERT`, is `error: 'unexpected_shape'`, never zero rows.
242
+ - `MORE_ROWS` is the only truncation signal, and a reply that does not say reads as truncated, with
243
+ a note saying so. `ROWS_COUNT` is never read: it counts an index range and ignores the criteria
244
+ and the user's rights. Rows are also cut to `max_rows` in the bridge.
245
+ - A refusal (no such query, a right the user lacks, a criteria the server rejects) reaches the model
246
+ in the app's own words unless it reads like compiler output. A connection failure is
247
+ `request_failed`, never a refusal.
248
+ - A read the app never answers ends as `request_failed`, without inviting a retry. Known limit: the
249
+ bridge cannot log off a read that timed out, so its server subscription stays open until the
250
+ socket closes.
251
+ - The dataserver's `ROW_REF` is taken off each row, so a query row carries no column a request row
252
+ of that record lacks, apart from fields the query itself declares.
253
+ - A query is never a write's row source, even one named `REQ_<T>`: a dataserver's cache can lag the
254
+ very change a staleness check exists to catch. See
255
+ [A modify needs somewhere to read its rows from](#a-modify-needs-somewhere-to-read-its-rows-from).
221
256
 
222
257
  `createGenesisResourceTools(resources, { connect })` builds the same tools without registering
223
258
  anything, for an app that assembles its own agent.
@@ -306,8 +341,8 @@ return any text, including a perfect copy of a write result. The key is random,
306
341
  return, so nothing that stores or returns data can know it. A session replayed from an earlier
307
342
  registration carries an older key, and its feedback then reads as data. An app with no event
308
343
  that could get a write tool carries no exception in its prompt at all. That includes an app whose
309
- events the config itself refuses: a `custom` op, a `rowSources` entry naming another source, or a
310
- modify or delete whose table's `REQ_` was left out. The metadata read later can still withhold a
344
+ events the config itself refuses: a `custom` op, a `rowSources` entry naming another source, a
345
+ malformed `references`, or a modify or delete whose table's `REQ_` was left out. The metadata read later can still withhold a
311
346
  tool from an event the config allows, and that cannot be known at registration.
312
347
  `createGenesisWriteTools` returns these events as `writableEvents`.
313
348
 
@@ -490,6 +525,10 @@ name that matches an existing entity, view or query.
490
525
  - An **insert that requires a `NANO_TIMESTAMP`**. Its unit has not been confirmed on a live app,
491
526
  so a model may not set one. A modify carries the row's own value through unchanged, and is
492
527
  refused if a JSON number cannot hold that value exactly.
528
+ - An **insert with a required field whose reference cannot be checked**, and an insert or modify
529
+ whose every settable field is one. See [Reference checks](#reference-checks).
530
+ - An **insert or modify with a reference whose target cannot be described right now**: no write
531
+ tool yet, and it is asked again next turn.
493
532
 
494
533
  An event with no usable row source **gets no tool at all**, and the console says why, as the write
495
534
  tools are built (before `registerGenesisAssistant` returns). When the
@@ -501,6 +540,76 @@ unless asking again could help — a request that failed, or a metadata reply th
501
540
  (Connect caches every other reply, errors included, so asking again would only repeat it). A tool that refused every call would teach the model nothing and cost a turn each time,
502
541
  and the tool list should be a true map of what the assistant can do.
503
542
 
543
+ ### Reference checks
544
+
545
+ Nothing in a generated app checks that a `COUNTERPARTY_ID` names a counterparty: its handlers
546
+ write what they are sent. So an insert or a modify declares the values that must match another
547
+ table's row, and the assistant checks them itself:
548
+
549
+ ```json
550
+ {
551
+ "name": "EVENT_TRADE_INSERT",
552
+ "kind": "event",
553
+ "op": "insert",
554
+ "context": "Book a trade.",
555
+ "references": [
556
+ {
557
+ "resource": "REQ_COUNTERPARTY",
558
+ "fields": [{ "field": "COUNTERPARTY_ID", "targetField": "COUNTERPARTY_ID" }]
559
+ }
560
+ ]
561
+ }
562
+ ```
563
+
564
+ Each group names the target table's own `REQ_` and pairs this write's fields with the target's. A
565
+ group of several pairs must match one row on all of them. A malformed `references` leaves the
566
+ resource out, with a warning, like any other rule about one resource.
567
+
568
+ **Before the review**, every value a row sets is looked up through that read. A value that
569
+ matches no row the user can see refuses the row, and the model is told which read to copy it
570
+ from; a value that could not be looked up refuses it too. A refused row is shown in the review
571
+ but cannot be ticked. Each distinct value is read once per call, at most four at a time, all under
572
+ one 30-second deadline. A call that needs more than 50 lookups is
573
+ refused whole, and the tool description says so. A modify looks up only the references it
574
+ changes, so a row that already points at something gone stays editable while nobody touches that
575
+ field. A composite reference with some parts empty is refused; with every part empty it is no
576
+ reference, and nothing is looked up.
577
+
578
+ **As each row is written**, its references are looked up again beside the row's own staleness
579
+ read. One that no longer matches reports `reference_gone`, and nothing is written for that row.
580
+ The rows after it still go ahead.
581
+
582
+ "A row the user can see" is meant exactly: the lookup runs as the user, so a row their
583
+ permissions hide reads as missing. Writing a reference through the assistant needs the view
584
+ right on the **target** table as well as the right to write this one.
585
+
586
+ What is not checked, or cannot be:
587
+
588
+ - **A target that cannot be described right now**: its metadata request timed out, the
589
+ connection dropped, or the app refused it (which reaches the assistant as a failed request
590
+ today). The insert or modify has no write tool yet, and it is asked again next turn.
591
+ - **A reference that cannot be checked is never offered as though it were.** That is a target
592
+ read the config does not have, one whose metadata came back as an error, a target field it cannot be
593
+ searched by, a field this write does not declare, or two fields holding different kinds of
594
+ value. On an insert, a required one costs the event its tool, and an optional one is left out:
595
+ a value sent anyway is refused by name. On a modify the row's value is kept, and a new one is
596
+ refused. The console says which and why, once.
597
+ - **A target field that is a `DATE` or `DATETIME`.** A timestamp cannot be matched exactly, and
598
+ a date's time zone has not been confirmed. Such a reference is treated as one that cannot be
599
+ checked.
600
+ - **Rows proposed in the same batch do not count yet.** A row whose reference names another row
601
+ of the same call, or its own generated key, is refused. Write the parent first, in its own
602
+ review.
603
+ - **The first row of a required reference to its own table**, such as a `MANAGER_ID` every
604
+ employee must have, cannot be inserted through the chat: there is no parent yet, and a row
605
+ pointing at its own key reads as missing.
606
+ - **No `references` at all**, as in a config from before they existed: nothing is checked, and
607
+ the console says so once. An empty list declares none and says nothing.
608
+ - **Writes through MCP.** The check is the chat's own.
609
+
610
+ The model is told what is checked: a checked field's description says which row it must match,
611
+ and the tool's description lists the checked references and the 50-value cap.
612
+
504
613
  ### Reading the result
505
614
 
506
615
  The result's `decision` is what the user answered: `approved`, `denied`, `changes_requested` or
@@ -517,6 +626,7 @@ one — that is how a row gets written twice.
517
626
  | `not_selected` | The user did not tick it. Nothing was sent. |
518
627
  | `invalid_payload` | Refused before the review, or the server found the details malformed. |
519
628
  | `changed_since_review` | Somebody changed the row while the review was open. Nothing was sent. |
629
+ | `reference_gone` | A reference it sets matched no row when it was written. Nothing was sent. |
520
630
  | `gone` | The row a modify or delete named no longer exists. |
521
631
  | `duplicate` | A record with that key already exists. |
522
632
  | `refused_by_app` | The app's own validation said no. Nothing to retry. |
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/ai-assistant",
3
3
  "description": "Genesis AI Assistant micro-frontend",
4
- "version": "15.46.5",
4
+ "version": "15.47.0",
5
5
  "license": "SEE LICENSE IN license.txt",
6
6
  "main": "dist/esm/index.js",
7
7
  "types": "dist/ai-assistant.d.ts",
@@ -92,31 +92,31 @@
92
92
  }
93
93
  },
94
94
  "devDependencies": {
95
- "@genesislcap/foundation-comms": "15.46.5",
96
- "@genesislcap/foundation-testing": "15.46.5",
97
- "@genesislcap/genx": "15.46.5",
98
- "@genesislcap/ts-builder": "15.46.5",
99
- "@genesislcap/uvu-playwright-builder": "15.46.5",
100
- "@genesislcap/vite-builder": "15.46.5",
101
- "@genesislcap/webpack-builder": "15.46.5",
95
+ "@genesislcap/foundation-comms": "15.47.0",
96
+ "@genesislcap/foundation-testing": "15.47.0",
97
+ "@genesislcap/genx": "15.47.0",
98
+ "@genesislcap/ts-builder": "15.47.0",
99
+ "@genesislcap/uvu-playwright-builder": "15.47.0",
100
+ "@genesislcap/vite-builder": "15.47.0",
101
+ "@genesislcap/webpack-builder": "15.47.0",
102
102
  "@types/dompurify": "^3.0.5",
103
103
  "@types/marked": "^5.0.2",
104
104
  "esbuild": "0.25.12"
105
105
  },
106
106
  "dependencies": {
107
- "@genesislcap/foundation-ai": "15.46.5",
108
- "@genesislcap/foundation-logger": "15.46.5",
109
- "@genesislcap/foundation-notifications": "15.46.5",
110
- "@genesislcap/foundation-redux": "15.46.5",
111
- "@genesislcap/foundation-ui": "15.46.5",
112
- "@genesislcap/foundation-utils": "15.46.5",
113
- "@genesislcap/rapid-design-system": "15.46.5",
114
- "@genesislcap/web-core": "15.46.5",
107
+ "@genesislcap/foundation-ai": "15.47.0",
108
+ "@genesislcap/foundation-logger": "15.47.0",
109
+ "@genesislcap/foundation-notifications": "15.47.0",
110
+ "@genesislcap/foundation-redux": "15.47.0",
111
+ "@genesislcap/foundation-ui": "15.47.0",
112
+ "@genesislcap/foundation-utils": "15.47.0",
113
+ "@genesislcap/rapid-design-system": "15.47.0",
114
+ "@genesislcap/web-core": "15.47.0",
115
115
  "dompurify": "^3.3.1",
116
116
  "marked": "^17.0.3"
117
117
  },
118
118
  "peerDependencies": {
119
- "@genesislcap/foundation-comms": "^15.46.5"
119
+ "@genesislcap/foundation-comms": "^15.47.0"
120
120
  },
121
121
  "peerDependenciesMeta": {
122
122
  "@genesislcap/foundation-comms": {
@@ -20,8 +20,8 @@ const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
20
20
  const require = createRequire(import.meta.url);
21
21
 
22
22
  const EXPECTED = {
23
- kinds: ['request', 'event'],
24
- resourceFields: ['name', 'kind', 'op', 'context', 'maxRows', 'customCode'],
23
+ kinds: ['request', 'event', 'query'],
24
+ resourceFields: ['name', 'kind', 'op', 'context', 'maxRows', 'customCode', 'references'],
25
25
  vendors: ['anthropic', 'gemini'],
26
26
  tiers: ['low', 'high', 'reasoning'],
27
27
  };