@jskit-ai/agent-docs 0.1.305 → 0.1.307

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 (41) hide show
  1. package/guide/agent/app-extras/assistant.md +9 -0
  2. package/guide/agent/app-setup/multi-homing.md +6 -3
  3. package/guide/agent/framework/data-access.md +98 -5
  4. package/guide/agent/framework/material-3.md +8 -2
  5. package/guide/agent/framework/sanity-checks.md +2 -0
  6. package/guide/agent/framework/translation.md +13 -0
  7. package/guide/agent/framework/typed-features.md +8 -0
  8. package/package.json +1 -1
  9. package/patterns/feature-package/example/booking-engine/package.json +1 -1
  10. package/patterns/minimal-foundation/example/package.json +4 -4
  11. package/patterns/shell-foundation/example/package.json +5 -5
  12. package/patterns/shell-foundation/example/packages/main/package.json +1 -1
  13. package/reference/autogen/PATTERN_INDEX.md +38 -38
  14. package/reference/autogen/packages/http-web.md +1 -1
  15. package/reference/autogen/packages/kernel.md +1 -0
  16. package/reference/autogen/packages/resource-runtime.md +3 -1
  17. package/reference/autogen/packages/shell-web.md +7 -0
  18. package/reference/autogen/tooling/config-eslint.md +2 -0
  19. package/reference/autogen/tooling/jskit-catalog.md +1 -0
  20. package/skills/jskit/references/data-access.md +98 -5
  21. package/skills/jskit/references/heuristics/live-actions.md +3 -0
  22. package/skills/jskit/references/material-3.md +8 -2
  23. package/skills/jskit/references/multi-homing.md +6 -3
  24. package/skills/jskit/references/pattern-index.md +38 -38
  25. package/skills/jskit/references/patterns/app/minimal-foundation/example/package.json +4 -4
  26. package/skills/jskit/references/patterns/app/shell-foundation/example/package.json +5 -5
  27. package/skills/jskit/references/patterns/app/shell-foundation/example/packages/main/package.json +1 -1
  28. package/skills/jskit/references/patterns/auth/accounts-hub/example/package.json +3 -3
  29. package/skills/jskit/references/patterns/auth/oidc-sign-in/example/package.json +2 -2
  30. package/skills/jskit/references/patterns/auth/supabase-auth/example/package.json +1 -1
  31. package/skills/jskit/references/patterns/connectors/calendar-cli/example/package.json +4 -4
  32. package/skills/jskit/references/patterns/crud/crud-feature-package/example/packages/books/package.json +3 -3
  33. package/skills/jskit/references/patterns/database/mysql-application/example/package.json +2 -2
  34. package/skills/jskit/references/patterns/database/postgres-application/example/package.json +2 -2
  35. package/skills/jskit/references/patterns/realtime/realtime-application/example/package.json +2 -2
  36. package/skills/jskit/references/patterns/server/feature-package/example/booking-engine/package.json +1 -1
  37. package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users/package.json +3 -3
  38. package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users-workspace/package.json +6 -6
  39. package/skills/jskit/references/sanity-checks.md +2 -0
  40. package/skills/jskit/references/translation.md +13 -0
  41. package/skills/jskit/references/typed-features.md +8 -0
@@ -516,6 +516,15 @@ arguments and result pass 64 KiB. The model must still write the call in one
516
516
  step: the API engine asks for at most 32,000 output tokens a step, and a model's
517
517
  own output limit, or its reasoning, can leave less.
518
518
 
519
+ By default the assistant refuses a tool's arguments past 32 KiB and its result
520
+ past 48 KiB ([limits](./assistant-conversation.md#application-tools)). An
521
+ action that takes a whole document (a template, a plan, a long settings record)
522
+ as its input usually works on small documents and fails on the largest, and
523
+ the model must write the whole document again on every edit. Prefer actions
524
+ shaped as changes for the assistant (add, update or remove one part, by id),
525
+ and call each tool with the largest real document, seeded and library records
526
+ included, not only with the small ones tests create.
527
+
519
528
  ### Framework account and workspace actions
520
529
 
521
530
  Account and workspace action owners supply assistant-specific descriptions,
@@ -228,9 +228,12 @@ To send invitation email, provide the optional `workspaces.invite-mailer`
228
228
  capability from one of the application's providers. Without one, invitations
229
229
  are still created and delivery reports `mailer_unconfigured`. The mailer, typed
230
230
  `WorkspaceInviteMailer` in `@jskit-ai/workspaces-core/server/types`, is an
231
- object whose `sendWorkspaceInvite(message, options)` receives `{ email,
232
- inviteUrl, workspace, inviter, roleSid, expiresAt, message }`, where the inner
233
- `message` is the rendered `{ subject, text, html }`:
231
+ object whose `sendWorkspaceInvite(message, options)` receives `{ inviteId,
232
+ email, inviteUrl, workspace, inviter, roleSid, expiresAt, locale, message }`,
233
+ where the inner `message` is the rendered `{ subject, text, html }`. `inviteId`
234
+ is the saved invitation's id and `workspace.id` its workspace's, so a mailer
235
+ that holds email until delivery is set up can record which invitation each one
236
+ belongs to without reading `workspace_invites`:
234
237
 
235
238
  ```js
236
239
  const InviteMailerProvider = defineProvider({
@@ -463,6 +463,38 @@ async function noticeVisibilityPolicy({ query, caller, context, column, value })
463
463
  }
464
464
  ```
465
465
 
466
+ A policy narrows with `where` calls only: `where`, `andWhere`, `orWhere` and
467
+ their kin (`whereIn`, `whereExists`, `whereNot`, `orWhereNull`...). Its calls
468
+ run inside one parenthesised `where` group, where Knex compiles predicates and
469
+ drops a join without a word, which would leave the policy hiding nothing; any
470
+ other call (`join`, `leftJoin`, `select`) throws a TypeError naming the
471
+ feature, the policy and the table. To narrow through another table, tie a
472
+ subquery to the row with `whereExists`: over `ownTable(name)`, which may join
473
+ the owner's other tables, or over another owner's join source. A policy is told
474
+ the call's `options`, `{ context, trx }` as the caller passed them, and passes
475
+ them on unchanged to `joinSource({ alias }, options)`, so the join source reads
476
+ in the caller's scope and transaction; never build them by hand.
477
+
478
+ ```js
479
+ // good: a member of the document's team sees it, through the teams owner's join source
480
+ async function teamDocumentsPolicy({ query, caller, column, options, requires }) {
481
+ if (caller.kind !== "user") {
482
+ return caller.kind !== "anonymous";
483
+ }
484
+ const member = await requires.teams.joinSource({ alias: "tm" }, options);
485
+ query.whereExists(
486
+ member.query.select(1).whereColumn(member.column("teamId"), column("teamId")).where(member.column("userId"), caller.userId)
487
+ );
488
+ return true;
489
+ }
490
+
491
+ // bad: a join inside the policy, which Knex would drop from the where group; it throws
492
+ function teamDocumentsPolicy({ query, caller, column }) {
493
+ query.join("team_members as tm", "tm.team_id", column("teamId")).where("tm.user_id", caller.userId);
494
+ return true;
495
+ }
496
+ ```
497
+
466
498
  A rule that depends on the caller's role reads `context.permissions` with
467
499
  `hasPermission(context.permissions, "bookings.view-all")` from
468
500
  `@jskit-ai/kernel/shared/support`, never with `includes()`. A role may hold
@@ -762,6 +794,47 @@ is `FOR NO KEY UPDATE`, which still keeps every other lock and write of the row
762
794
  out but lets those inserts through; MySQL, MariaDB and SQLite lock as for the
763
795
  default `"update"`. Any other value throws a `TypeError` before anything runs.
764
796
 
797
+ A check that only reads rows, and needs them unchanged until the transaction
798
+ ends while other checks read them at once (is the membership still active
799
+ while this document is filed under it?), takes a shared lock: `lockMode:
800
+ "share"` on `lock`, `lockMany` or `lockWhere`, and so on an owner API that
801
+ passes its options on, such as `workspaces.lock(workspaceId, { ...txOptions,
802
+ lockMode: "share" })` or
803
+ `workspaces.memberships.lockByWorkspaceIdAndUserId(workspaceId, userId, {
804
+ ...txOptions, lockMode: "share" })`. It is `FOR SHARE` on PostgreSQL and `LOCK
805
+ IN SHARE MODE` on MySQL and MariaDB: other reads, shared locks and inserts of
806
+ rows that reference the locked ones go on, and an update, a delete or an
807
+ exclusive lock of them waits until the transaction ends; SQLite still runs one
808
+ transaction at a time. Never write a row the transaction holds shared: two
809
+ transactions that each hold it shared and then write it wait for each other,
810
+ and the database fails one as a deadlock. Lock a row the work will write with
811
+ the default `"update"` from the start. `claim`, `patchWhere` and
812
+ `lockOrCreate` refuse `"share"` with a `TypeError`, since they take or write
813
+ their rows.
814
+
815
+ ```js
816
+ // good: concurrent filings check the membership at once; a change to it waits until this commits
817
+ const file = (input, options) => documents.withTransaction(options, async (txOptions) => {
818
+ const membership = await memberships.lock(input.membershipId, { ...txOptions, lockMode: "share", fields: ["status"] });
819
+ if (membership.status !== "active") {
820
+ throw new ConflictError("documents.membershipInactive");
821
+ }
822
+ return documents.create(input, txOptions);
823
+ });
824
+
825
+ // bad: the transaction holds the membership shared, then writes it; two such filings deadlock
826
+ await memberships.patch(input.membershipId, { lastFiledAt: new Date() }, txOptions);
827
+ ```
828
+
829
+ Locks stay on the owner's handle and its owner API. A `scopedQuery()` or
830
+ `joinSource()` builder takes no lock, and a row policy is not told a read's
831
+ lock mode: it says which rows a caller may see, the same for every read. Rows
832
+ of several owners are never locked in one statement over a join, which on
833
+ MySQL and MariaDB locks every joined row the read examines: lock each owner's
834
+ rows with its own `lock`, `lockMany` or `lockWhere`, the owners in one fixed
835
+ order on every path (a parent's owner before its children's), so two
836
+ transactions never take them in opposite orders.
837
+
765
838
  A record that a person edits from a form it read earlier carries a version
766
839
  number: the table resource names it with `lockVersionField`, an integer field
767
840
  over a non-null integer column with `defaultTo: 0`.
@@ -1217,10 +1290,30 @@ three more times, so the work must
1217
1290
  be safe to repeat: an HTTP call or an email goes after commit, or into an
1218
1291
  outbox row written inside it. Work that cannot be repeated passes `{ ...options, retry: false }`, and work that must
1219
1292
  commit before its caller goes on passes `{ ...options, outermost: true }`.
1220
- Code never asks whether it runs in a transaction: `withTransaction` joins the
1221
- caller's, `outermost` refuses one, and `lock`, `lockMany`, `lockWhere` and
1222
- `claim` refuse to run outside one; `lockOrCreate` opens its own (and retries a
1223
- lost insert race only then).
1293
+ Work that must commit or roll back with its caller's transaction, and so must
1294
+ never open one of its own, passes `{ ...options, joinOnly: true }`: called
1295
+ outside a transaction it throws a TypeError before the work runs. Code never
1296
+ asks whether it runs in a transaction: `withTransaction` joins the caller's,
1297
+ `outermost` refuses one, `joinOnly` requires one, and `lock`, `lockMany`,
1298
+ `lockWhere` and `claim` refuse to run outside one; `lockOrCreate` opens its own
1299
+ (and retries a lost insert race only then).
1300
+
1301
+ ```js
1302
+ // good: both moves land with the caller's transaction, or neither does
1303
+ async function moveStock(transfer, options) {
1304
+ return stock.withTransaction({ ...options, joinOnly: true }, async (txOptions) => {
1305
+ await stock.patch(transfer.fromId, { quantity: transfer.fromQuantity }, txOptions);
1306
+ await stock.patch(transfer.toId, { quantity: transfer.toQuantity }, txOptions);
1307
+ });
1308
+ }
1309
+
1310
+ // bad: asks whether it runs in a transaction by reading it out of options
1311
+ async function moveStock(transfer, options) {
1312
+ if (!options.trx) throw new Error("moveStock runs inside its caller's transaction");
1313
+ await stock.patch(transfer.fromId, { quantity: transfer.fromQuantity }, options);
1314
+ await stock.patch(transfer.toId, { quantity: transfer.toQuantity }, options);
1315
+ }
1316
+ ```
1224
1317
 
1225
1318
  When the work throws, the transaction rolls back and the caller gets the
1226
1319
  work's own error, with its status and code, reporting `transactionOutcome:
@@ -1505,7 +1598,7 @@ server code is server code. Neither `eslint-disable`, an inline
1505
1598
  | Rule | Reports | Section |
1506
1599
  | --- | --- | --- |
1507
1600
  | `jskit/no-direct-knex` | a table reached by name with Knex, a `.knex` read or `knex` destructured, a transaction opened by hand | [The resource is the only door](#the-resource-is-the-only-door) |
1508
- | `jskit/no-transaction-reader` | `options.trx`, `trx \|\| knex`, a `trx = knex` default, `trx` destructured from options, any key but `context` and `trx` read from the `txOptions` work receives | [Transactions](#transactions) |
1601
+ | `jskit/no-transaction-reader` | `options.trx`, `trx \|\| knex`, a `trx = knex` default, `trx` destructured from options, any key but `context` and `trx` read from the `txOptions` work receives; a read an `if` tests before throwing points to `joinOnly` or `outermost` | [Transactions](#transactions) |
1509
1602
  | `jskit/no-hand-scope` | a hand-written `where` on `workspace_id` or `workspaceId` | [Layer 1: the table resource](#layer-1-the-table-resource) |
1510
1603
  | `jskit/sql-literal` | raw SQL built from strings or templates instead of one literal with bindings | [Layer 5: reports the resource cannot express](#layer-5-reports-the-resource-cannot-express) |
1511
1604
  | `jskit/no-hand-context` | a system context made with `createSystemContext` or `declareSystemScope`, a context's `scopeValues` written by hand | [Background work](#background-work) |
@@ -97,7 +97,13 @@ Exactly this, and nothing more:
97
97
  top-level: no arrow, a fresh trail. Placements are literal declarative data,
98
98
  one `addPlacement({ ... })` per destination with plain string `surface`,
99
99
  `scopedSuffix` and `unscopedSuffix`, never built by a helper, a spread or a
100
- template, so a reader and `jskit check` can map every destination.
100
+ template, so a reader and `jskit check` can map every destination. One
101
+ dynamic page may serve several destinations: `modules/[moduleKey]/index.vue`
102
+ renders each module a placement names literally (`scopedSuffix:
103
+ "/modules/incidents"`, `"/modules/hazards"`), so it is top-level and declares
104
+ no parent. A literal destination is served by a page whose route matches it
105
+ segment by segment, each `:param` standing for exactly one segment; the
106
+ page's deeper pages (`modules/[moduleKey]/settings.vue`) are inner pages.
101
107
  3. **Every in-app link and navigation goes through JSKIT navigation:**
102
108
  `:to="paths.page('/suppliers')"` and `router.push(paths.page(...))` with
103
109
  `usePaths()`, the CRUD runtime's `resolveViewUrl()`, `resolveEditUrl()` and
@@ -133,7 +139,7 @@ Exactly this, and nothing more:
133
139
  | `nav/raw-link` | a hand-built in-app path in `to`, `href`, `router.push()`, `router.replace()` or a `to:`/`href:` object key outside a placement |
134
140
  | `nav/back-control` | any back control but the shell's Up that navigates the app: "Back to X", "← Suppliers", back arrows and navigating chevrons, breadcrumbs, a custom app-bar back button, a back component (`<ContextBackButton />` or `<page-back-link>`, and its import), a `goBack()`-style handler |
135
141
  | `nav/missing-parent` | an inner page of a shell surface without a declared parent, when it always renders under the shell's top app bar (a layout that also renders its pages without `ShellLayout`, such as a shop device's sign-in in a `v-if`, leaves its pages unjudged) |
136
- | `nav/top-level-parent` | a main-navigation destination that declares a parent |
142
+ | `nav/top-level-parent` | a main-navigation destination that declares a parent, including a dynamic page whose route serves a literal destination (`/modules/:moduleKey` for `/modules/incidents`) |
137
143
  | `nav/placement-data` | a main-navigation placement that isn't literal data (no page is judged for a missing parent until it is) |
138
144
  | `nav/missing-shell-layout` | a page that declares a parent with no shell layout rendering it, so its title, Up and actions never show |
139
145
  | `nav/surface-parent` | a parent declared beside `jskit.surface`, which the shell never reads |
@@ -57,6 +57,8 @@ truthful model-facing output; the assistant validates the result against
57
57
  `extensions.assistant.output` and rejects unexpected fields, so a contract
58
58
  that promises what execution cannot return fails at run time, not at review
59
59
  ([Assistant](/guide/app-extras/assistant#database-surface-action-tools)).
60
+ Call it with the largest real input too, seeded records included: a tool's
61
+ arguments stop at 32 KiB and its result at 48 KiB by default.
60
62
 
61
63
  **Example:** sparse primary fields stay sparse, and an included record is read
62
64
  from its lookup container (`items[0].lookups.pet.name`); a contract that
@@ -210,6 +210,19 @@ translate a key and show any other string as written:
210
210
  { label: "Reports" }
211
211
  ```
212
212
 
213
+ ## Content the app ships as data
214
+
215
+ Names and descriptions in records the app seeds or ships, such as a
216
+ catalogue's items or a library's templates, are the app's own text. Prefer
217
+ storing their message key (`app.templates.starter.name`) with the English in
218
+ the app's `en` messages, and show the field with `text()` from
219
+ `useJskitText()`, the helper placement labels use: it translates a key and
220
+ shows any other string as written. Stored English cannot follow the user's
221
+ language, and matching it back to a key breaks once someone edits it. When a
222
+ person renames their own copy, the field takes what they wrote and shows it as
223
+ written. Server code that writes such a field into an email or an export
224
+ resolves the key with `createServerI18n` (see [Emails](#emails)).
225
+
213
226
  ## Dates and numbers
214
227
 
215
228
  JSKIT formats dates, times, numbers and relative times with `Intl` in the
@@ -824,6 +824,14 @@ for anything that reads or writes the domain.**
824
824
  address and refuses with 429, `kernel.http.rateLimited` and `Retry-After`.
825
825
  A limit worth changing per application is read from its config, as
826
826
  `config.auth.rateLimits` is.
827
+ - A route's `body` is validated by the kernel, on every method, DELETE
828
+ included. A request without a body is validated as an empty one: a body
829
+ validated in `create` or `replace` mode answers 400 `validation_failed`
830
+ naming its required fields, and one in the default `patch` mode, or with no
831
+ required fields, reaches the handler as `{}`. A body that is not a JSON
832
+ object answers 400 with the field error `request: "must be object"`. On the
833
+ client, a `useCommand()` DELETE sends its parsed input as the body when the
834
+ command declares `input` or `buildRawPayload`.
827
835
 
828
836
  Why: an action is the one place a domain operation's policy, input and
829
837
  events are declared.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/agent-docs",
3
- "version": "0.1.305",
3
+ "version": "0.1.307",
4
4
  "description": "Distributed JSKIT agent references, prompts, guides, and generated reference maps.",
5
5
  "type": "module",
6
6
  "files": [
@@ -5,7 +5,7 @@
5
5
  "private": true,
6
6
  "type": "module",
7
7
  "dependencies": {
8
- "@jskit-ai/kernel": "0.2.20",
8
+ "@jskit-ai/kernel": "0.2.21",
9
9
  "json-rest-schema": "^1.0.20"
10
10
  },
11
11
  "exports": {
@@ -34,7 +34,7 @@
34
34
  "dependencies": {
35
35
  "@local/main": "0.1.0",
36
36
  "@fastify/static": "^10.1.3",
37
- "@jskit-ai/kernel": "0.2.20",
37
+ "@jskit-ai/kernel": "0.2.21",
38
38
  "@jskit-ai/material-web": "0.1.5",
39
39
  "@tanstack/vue-query": "^5.101.0",
40
40
  "fastify": "^5.12.7",
@@ -44,13 +44,13 @@
44
44
  "vue": "^3.5.44",
45
45
  "vue-router": "^5.3.1",
46
46
  "vuetify": "^4.3.0",
47
- "@jskit-ai/http-runtime": "0.2.20",
47
+ "@jskit-ai/http-runtime": "0.2.21",
48
48
  "@fastify/fast-json-stringify-compiler": "^5.1.0",
49
49
  "@vue/devtools-api": "^8.2.1"
50
50
  },
51
51
  "devDependencies": {
52
- "@jskit-ai/config-eslint": "0.1.250",
53
- "@jskit-ai/jskit-catalog": "0.2.57",
52
+ "@jskit-ai/config-eslint": "0.1.251",
53
+ "@jskit-ai/jskit-catalog": "0.2.59",
54
54
  "@playwright/test": "1.61.1",
55
55
  "@vitejs/plugin-vue": "^6.0.7",
56
56
  "eslint": "^10.8.0",
@@ -34,7 +34,7 @@
34
34
  "dependencies": {
35
35
  "@local/main": "0.1.0",
36
36
  "@fastify/static": "^10.1.3",
37
- "@jskit-ai/kernel": "0.2.20",
37
+ "@jskit-ai/kernel": "0.2.21",
38
38
  "@jskit-ai/material-web": "0.1.5",
39
39
  "@tanstack/vue-query": "^5.101.0",
40
40
  "fastify": "^5.12.7",
@@ -44,14 +44,14 @@
44
44
  "vue": "^3.5.44",
45
45
  "vue-router": "^5.3.1",
46
46
  "vuetify": "^4.3.0",
47
- "@jskit-ai/http-runtime": "0.2.20",
48
- "@jskit-ai/shell-web": "0.2.27",
47
+ "@jskit-ai/http-runtime": "0.2.21",
48
+ "@jskit-ai/shell-web": "0.2.28",
49
49
  "@fastify/fast-json-stringify-compiler": "^5.1.0",
50
50
  "@vue/devtools-api": "^8.2.1"
51
51
  },
52
52
  "devDependencies": {
53
- "@jskit-ai/config-eslint": "0.1.250",
54
- "@jskit-ai/jskit-catalog": "0.2.57",
53
+ "@jskit-ai/config-eslint": "0.1.251",
54
+ "@jskit-ai/jskit-catalog": "0.2.59",
55
55
  "@playwright/test": "1.61.1",
56
56
  "@vitejs/plugin-vue": "^6.0.7",
57
57
  "eslint": "^10.8.0",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "description": "App-local runtime composition and lightweight glue.",
11
11
  "dependencies": {
12
- "@jskit-ai/kernel": "0.2.20"
12
+ "@jskit-ai/kernel": "0.2.21"
13
13
  },
14
14
  "jskit": {
15
15
  "kind": "runtime",