@jskit-ai/agent-docs 0.1.353 → 0.1.355
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.
- package/guide/agent/app-extras/assistant.md +70 -0
- package/guide/agent/app-setup/authentication.md +157 -2
- package/guide/agent/app-setup/database-layer.md +49 -15
- package/guide/agent/app-setup/service-keys.md +103 -0
- package/guide/agent/app-setup/upgrading-jskit.md +17 -5
- package/guide/agent/framework/data-access.md +13 -0
- package/guide/agent/framework/material-3.md +3 -4
- package/guide/agent/framework/speed-pass.md +7 -1
- package/guide/agent/framework/typed-features.md +56 -25
- package/guide/agent/index.md +2 -0
- package/package.json +1 -1
- package/patterns/feature-package/example/booking-engine/package.json +1 -1
- package/patterns/minimal-foundation/example/package.json +6 -6
- package/patterns/shell-foundation/example/package.json +7 -7
- package/patterns/shell-foundation/example/packages/main/package.json +1 -1
- package/patterns/shell-foundation/example/src/components/menus/TabLinkItem.vue +5 -0
- package/reference/autogen/PATTERN_INDEX.md +49 -38
- package/reference/autogen/packages/agent-runtime.md +1 -1
- package/reference/autogen/packages/assistant-core.md +44 -8
- package/reference/autogen/packages/assistant-runtime.md +25 -0
- package/reference/autogen/packages/assistant-voice-sherpa.md +2 -1
- package/reference/autogen/packages/auth-core.md +4 -0
- package/reference/autogen/packages/auth-provider-local-core.md +13 -0
- package/reference/autogen/packages/auth-web.md +60 -16
- package/reference/autogen/packages/crud-core.md +3 -1
- package/reference/autogen/packages/database-runtime.md +1 -0
- package/reference/autogen/packages/http-web.md +1 -0
- package/reference/autogen/packages/kernel.md +1 -1
- package/reference/autogen/packages/material-web.md +2 -0
- package/reference/autogen/packages/realtime.md +2 -1
- package/reference/autogen/packages/resource-runtime.md +9 -0
- package/reference/autogen/packages/shell-web.md +35 -0
- package/reference/autogen/tooling/jskit-catalog.md +21 -8
- package/reference/autogen/tooling/testUtils.md +1 -0
- package/skills/jskit/references/data-access.md +13 -0
- package/skills/jskit/references/database-layer.md +49 -15
- package/skills/jskit/references/heuristics/placements.md +1 -0
- package/skills/jskit/references/heuristics/row-policies.md +1 -1
- package/skills/jskit/references/heuristics/ui-testing.md +3 -3
- package/skills/jskit/references/material-3.md +3 -4
- package/skills/jskit/references/pattern-index.md +49 -38
- package/skills/jskit/references/patterns/app/minimal-foundation/example/package.json +6 -6
- package/skills/jskit/references/patterns/app/shell-foundation/example/package.json +7 -7
- package/skills/jskit/references/patterns/app/shell-foundation/example/packages/main/package.json +1 -1
- package/skills/jskit/references/patterns/app/shell-foundation/example/src/components/menus/TabLinkItem.vue +5 -0
- package/skills/jskit/references/patterns/auth/accounts-hub/example/package.json +3 -3
- package/skills/jskit/references/patterns/auth/auth-surface/PATTERN.md +3 -0
- package/skills/jskit/references/patterns/auth/oidc-sign-in/example/package.json +2 -2
- package/skills/jskit/references/patterns/auth/own-design-sign-in/PATTERN.md +141 -0
- package/skills/jskit/references/patterns/auth/own-design-sign-in/example/src/components/ConfirmItsYouDialog.vue +182 -0
- package/skills/jskit/references/patterns/auth/own-design-sign-in/example/src/theme/tokens.css +35 -0
- package/skills/jskit/references/patterns/auth/own-design-sign-in/example/src/views/auth/LoginView.vue +473 -0
- package/skills/jskit/references/patterns/auth/supabase-auth/example/package.json +1 -1
- package/skills/jskit/references/patterns/connectors/calendar-cli/example/package.json +5 -5
- package/skills/jskit/references/patterns/crud/crud-feature-package/example/packages/books/package.json +3 -3
- package/skills/jskit/references/patterns/crud/crud-screen-set/example/books/BookListPage.vue +1 -1
- package/skills/jskit/references/patterns/database/mysql-application/example/package.json +2 -2
- package/skills/jskit/references/patterns/database/postgres-application/example/package.json +2 -2
- package/skills/jskit/references/patterns/realtime/realtime-application/PATTERN.md +5 -1
- package/skills/jskit/references/patterns/realtime/realtime-application/example/package.json +2 -2
- package/skills/jskit/references/patterns/server/feature-package/example/booking-engine/package.json +1 -1
- package/skills/jskit/references/patterns/shell/application-shell/example/src/components/menus/TabLinkItem.vue +5 -0
- package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users/package.json +3 -3
- package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users-workspace/package.json +6 -6
- package/skills/jskit/references/speed-pass.md +7 -1
- package/skills/jskit/references/typed-features.md +56 -25
|
@@ -778,6 +778,36 @@ action's own logs, events and writes stay the app's; `isExecutionLogged(context)
|
|
|
778
778
|
from `@jskit-ai/kernel/server/actions` is false during an unsaved call, so the
|
|
779
779
|
action and its policy can keep their own logs quiet too.
|
|
780
780
|
|
|
781
|
+
### Action hints for clients that ask first
|
|
782
|
+
|
|
783
|
+
A client that asks a person before a change, such as an MCP client, reads three
|
|
784
|
+
hints from each tool. A `query` action is read-only. A command is a change; it
|
|
785
|
+
says more when it declares:
|
|
786
|
+
|
|
787
|
+
```js
|
|
788
|
+
extensions: {
|
|
789
|
+
assistant: {
|
|
790
|
+
destructive: true, // removes or overwrites what cannot be had back
|
|
791
|
+
sendsOutside: true // reaches people or systems outside the app: mail, a payment, another service
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
```
|
|
795
|
+
|
|
796
|
+
Any value other than `true` or `false` stops the catalogue with an error naming
|
|
797
|
+
the action. A JSON:API CRUD feature's generated delete is destructive; its list,
|
|
798
|
+
view, create and update are not, unless the feature says so for a table whose
|
|
799
|
+
every change a client should ask about first:
|
|
800
|
+
|
|
801
|
+
```js
|
|
802
|
+
defineCrudFeature({ crud, surface: "admin", assistantHints: { create: { destructive: true }, update: { destructive: true } } });
|
|
803
|
+
```
|
|
804
|
+
|
|
805
|
+
`assistantHints` names only the feature's own create, update or delete, each
|
|
806
|
+
with `destructive` or `sendsOutside` as `true` or `false`; anything else stops
|
|
807
|
+
the server, naming the hint. Its custom actions declare hints in their own
|
|
808
|
+
`extensions`, and one without an assistant description is described by its
|
|
809
|
+
route's `summary`, so a client reads what its route says it does.
|
|
810
|
+
|
|
781
811
|
### Database surface conversation lifecycle
|
|
782
812
|
|
|
783
813
|
The client receives answer text incrementally and shows working status before
|
|
@@ -981,3 +1011,43 @@ one provider-error conversation, and verify global or cross-workspace isolation.
|
|
|
981
1011
|
Do not add a second model client beside the runtime, copy its repositories or
|
|
982
1012
|
routes, infer a surface, store keys in source, or keep generator markers,
|
|
983
1013
|
questionnaire answers, receipts, or provenance.
|
|
1014
|
+
|
|
1015
|
+
## MCP endpoint
|
|
1016
|
+
|
|
1017
|
+
`AssistantMcpFeature` from `@jskit-ai/assistant-runtime/server` serves the
|
|
1018
|
+
actions of one surface as the tools of a remote MCP server, at `POST /api/mcp`,
|
|
1019
|
+
or `POST /api/w/:workspaceSlug/mcp` for a workspace surface. It is one of
|
|
1020
|
+
assistant-runtime's server providers and serves nothing until the app names the
|
|
1021
|
+
surface:
|
|
1022
|
+
|
|
1023
|
+
```js
|
|
1024
|
+
config.assistantMcp = { surfaceId: "admin" };
|
|
1025
|
+
```
|
|
1026
|
+
|
|
1027
|
+
Its callers are other applications' servers. Each POST signs in by a
|
|
1028
|
+
[service key](/guide/app-setup/service-keys) and names the user it acts as
|
|
1029
|
+
(`Authorization: Bearer <key>` and `Act-As-User: <user id or email>`), never by
|
|
1030
|
+
a browser's cookies, and the answer names that user's id in `Acting-As-User`.
|
|
1031
|
+
`assistantMcp.rateLimit` (`{ max, timeWindow }`, as a route's) limits the calls
|
|
1032
|
+
from one address, from which a key's server calls for all its users.
|
|
1033
|
+
|
|
1034
|
+
Each POST carries one JSON-RPC message (`initialize`, `ping`, `tools/list`,
|
|
1035
|
+
`tools/call`) and gets its answer as JSON; a notification gets `202` with no
|
|
1036
|
+
body. The endpoint keeps no session and opens no stream: `GET` and `DELETE`
|
|
1037
|
+
answer `405`. Every message runs as the user the key acts as, through
|
|
1038
|
+
the endpoint's own action (`assistant.mcp.request`), so a tool sees the same
|
|
1039
|
+
permissions, surface and workspace as that surface's HTTP routes, and a person
|
|
1040
|
+
lists and calls only what they may run.
|
|
1041
|
+
|
|
1042
|
+
Every automation action of the surface is a tool of its own, named like the
|
|
1043
|
+
assistant's tools (`crud.ports.list` is `crud_ports_list`), with its input schema
|
|
1044
|
+
and its hints as MCP annotations (`readOnlyHint`, `destructiveHint`,
|
|
1045
|
+
`openWorldHint`). Unlike the in-app assistant, there are no discovery tools, and
|
|
1046
|
+
an action without an output schema is a tool too: it answers as it ran, as its
|
|
1047
|
+
route does. Unsaved actions and streams are never tools here, nor are the
|
|
1048
|
+
actions that change how the person signs in (`auth.*` and `settings.security.*`:
|
|
1049
|
+
signing out, their sessions, sign-in methods and linked providers), since a
|
|
1050
|
+
key acts as the person and their sign-in stays theirs. `tools/list` pages
|
|
1051
|
+
50 tools at a time. The surface's `assistantServer` barred ids and skipped
|
|
1052
|
+
prefixes apply too, and a result is held to 256 KiB unless the surface sets
|
|
1053
|
+
`maxToolResultBytes`.
|
|
@@ -27,6 +27,10 @@ npm install @jskit-ai/auth-provider-oidc-core @jskit-ai/auth-web
|
|
|
27
27
|
The dependency graph supplies `@jskit-ai/auth-core`. Do not install two
|
|
28
28
|
providers for the same `auth.service` capability.
|
|
29
29
|
|
|
30
|
+
With local auth, another application's server can also call the app's bearer
|
|
31
|
+
routes as one of its users at a time, with a service key an administrator
|
|
32
|
+
makes: see [Service keys](/guide/app-setup/service-keys).
|
|
33
|
+
|
|
30
34
|
## Provider ownership
|
|
31
35
|
|
|
32
36
|
The selected provider owns identity verification and sessions. The application
|
|
@@ -299,7 +303,9 @@ const refund = () => run(() => api.refund(orderId));
|
|
|
299
303
|
|
|
300
304
|
`isSecondFactorRequired(error)` from `@jskit-ai/auth-core/shared/authSecondFactor`
|
|
301
305
|
tells that refusal apart elsewhere, such as a page that asks for the second
|
|
302
|
-
factor before it shows anything.
|
|
306
|
+
factor before it shows anything. An app with its own design system builds the
|
|
307
|
+
prompt and the settings in its own look on the composables behind these
|
|
308
|
+
components, as "Sign-in screens in an app's own design" below says.
|
|
303
309
|
|
|
304
310
|
**Codes.** A code is accepted within one 30-second step either side of the
|
|
305
311
|
server's clock, and only once: no code of an accepted step or an earlier one
|
|
@@ -325,6 +331,31 @@ an application that keeps an audit log installs the
|
|
|
325
331
|
`auth.local.second-factor-events` capability, a function given each event after
|
|
326
332
|
it is stored. Without one, local auth logs them.
|
|
327
333
|
|
|
334
|
+
**A code for an account the application names.** A caller with no session of
|
|
335
|
+
the account, such as a command signed in with an API key that must show its
|
|
336
|
+
creator's code before it answers, asks `auth.service`'s
|
|
337
|
+
`verifySecondFactorOf({ userId, proof })`, `proof` being `{ code }` or
|
|
338
|
+
`{ recoveryCode }`. Whose account and when are the application's decision. It
|
|
339
|
+
is the session's own check: wrong codes through either count toward the same
|
|
340
|
+
wait, and a code or recovery code accepted by one is used up for both. It
|
|
341
|
+
answers `{ verifiedAt, method, recoveryCodesLeft }` and marks no session.
|
|
342
|
+
Each refusal throws with its code: 404
|
|
343
|
+
`auth.local.secondFactor.accountNotFound` (no account has that id), 403
|
|
344
|
+
`auth.local.secondFactor.accountDisabled` (the account is disabled, even with
|
|
345
|
+
the right code), 409 `auth.local.secondFactor.notSetUp` (no confirmed
|
|
346
|
+
authenticator), 429
|
|
347
|
+
`auth.local.secondFactor.locked` (the account waits; `Retry-After` gives the
|
|
348
|
+
seconds), and 400 `codeInvalid`, `codeUsed`, `recoveryCodeInvalid` or
|
|
349
|
+
`proofRequired`. The application records its own event from the answer or the
|
|
350
|
+
refusal. Local auth's second-factor events for it say `via: "application"`,
|
|
351
|
+
with no request's address (`ip` ""); a session's own events have no `via`.
|
|
352
|
+
|
|
353
|
+
To refuse before asking for the code, `accountStateOf({ userId })` answers
|
|
354
|
+
whether the account is `"active"`, `"disabled"` or `"missing"`, as
|
|
355
|
+
`verifySecondFactorOf` would find it: one read of the account, which checks no
|
|
356
|
+
code, spends no attempt and records no event. Like `verifySecondFactorOf`, it
|
|
357
|
+
is a second-factor operation (`features.secondFactor`).
|
|
358
|
+
|
|
328
359
|
## How a session was signed in (local auth)
|
|
329
360
|
|
|
330
361
|
An action that grants much (root on a machine, say) can ask more of the
|
|
@@ -1053,12 +1084,136 @@ page's own `?code=` or `?error=` still reads as a callback; name such a filter
|
|
|
1053
1084
|
otherwise.
|
|
1054
1085
|
|
|
1055
1086
|
Never restyle the views' own classes (`.login-screen`, `.auth-card`) or wrap
|
|
1056
|
-
them in a frame of the app's; the brand slot is the one way
|
|
1087
|
+
them in a frame of the app's; the brand slot is the one way into the Material
|
|
1088
|
+
views. An app with its own design system writes its own views instead (below).
|
|
1057
1089
|
|
|
1058
1090
|
Initial load errors stay inside the affected surface. Failed login, reset, and
|
|
1059
1091
|
other transient mutations use the application toast and do not shift the form.
|
|
1060
1092
|
Loading uses skeletons when content geometry is known.
|
|
1061
1093
|
|
|
1094
|
+
## Sign-in screens in an app's own design
|
|
1095
|
+
|
|
1096
|
+
An app with its own design system writes its own sign-in screens with these
|
|
1097
|
+
composables; Material stays JSKIT's default. Each `Default*View` is a Material
|
|
1098
|
+
3 rendering of one composable, and the composable holds everything the screen
|
|
1099
|
+
does. An app's own view calls the same composable, so it keeps every sign-in
|
|
1100
|
+
behavior with its own markup and CSS, and needs no Vuetify. Each comes from its
|
|
1101
|
+
own path, so a page loads only what it uses:
|
|
1102
|
+
|
|
1103
|
+
| Screen | Composable | Material view |
|
|
1104
|
+
|---|---|---|
|
|
1105
|
+
| Sign in, register, forgot password, one-time code, confirm your email | `useLoginView({ fallbackReturnTo })` from `@jskit-ai/auth-web/client/composables/useLoginView` | `DefaultLoginView` |
|
|
1106
|
+
| Password reset | `useResetPasswordView()` from `@jskit-ai/auth-web/client/composables/useResetPasswordView` | `DefaultResetPasswordView` |
|
|
1107
|
+
| Email change link | `useEmailChangeView()` from `@jskit-ai/auth-web/client/composables/useEmailChangeView` | `DefaultEmailChangeView` |
|
|
1108
|
+
| Sign out | `useSignOutView()` from `@jskit-ai/auth-web/client/composables/useSignOutView` | `DefaultSignOutView` |
|
|
1109
|
+
| A code or recovery code form | `useSecondFactorProof({ submit, onDone })` from `@jskit-ai/auth-web/client/composables/useSecondFactorProof` | `SecondFactorPrompt`, `SecondFactorDialog` |
|
|
1110
|
+
| The authenticator settings | `useSecondFactorSettings()` from `@jskit-ai/auth-web/client/composables/useSecondFactorSettings` | `SecondFactorSettings` |
|
|
1111
|
+
| A request asking for a fresh code | `useSecondFactorStepUp()` from `@jskit-ai/auth-web/client/composables/useSecondFactorStepUp` (also from `@jskit-ai/auth-web/client`) | `SecondFactorDialog` |
|
|
1112
|
+
|
|
1113
|
+
A proof form submits one of the second-factor requests from
|
|
1114
|
+
`@jskit-ai/auth-web/client/runtime/secondFactorRequests`: `verifySecondFactor`
|
|
1115
|
+
for a prompt, and `confirmSecondFactorSetup`,
|
|
1116
|
+
`replaceSecondFactorRecoveryCodes` and `removeSecondFactor` for the settings,
|
|
1117
|
+
which read with `readSecondFactor` and start with `startSecondFactorSetup`.
|
|
1118
|
+
|
|
1119
|
+
`useLoginView()` returns the mode (`isLogin`, `isRegister`, `isForgot`,
|
|
1120
|
+
`isOtp`, `isEmailConfirmationPending`) with `switchMode(mode)`, what the
|
|
1121
|
+
provider offers (`canUsePasswordLogin`, `canRegister`,
|
|
1122
|
+
`canRequestPasswordRecovery`, `canUseOtp`, `canUseOAuth`, ...), the fields as
|
|
1123
|
+
refs (`email`, `password`, `confirmPassword`, `otpCode`, `setupCode`,
|
|
1124
|
+
`confirmationCode`) with their error messages (`emailErrorMessages`, ...,
|
|
1125
|
+
shown once a field is touched or a submit was tried), `submitAuth`,
|
|
1126
|
+
`canSubmit`, `submitLabel`, `authTitle` and `authSubtitle`, the provider
|
|
1127
|
+
buttons (`oauthProviders`, `oauthProviderButtonLabel(provider)`,
|
|
1128
|
+
`startOAuthSignIn(id)`, `oauthRetryProvider`), the remembered account, the
|
|
1129
|
+
paused sign-in (`signInPausedMinutes`) and `redirectingSignedIn`, true while a
|
|
1130
|
+
browser already signed in is sent on, when the view shows no form. It handles
|
|
1131
|
+
invitations, the returnTo landing, a provider's callback and the session check
|
|
1132
|
+
on mount and on return to the page, as for `DefaultLoginView`. A refusal sets
|
|
1133
|
+
`errorMessage` (news such as a sent code sets `infoMessage`), which an own view
|
|
1134
|
+
shows beside the form; it also reaches the shell's error runtime, as from the
|
|
1135
|
+
Material view, whose host presents it. `oauthProviderIcon` is the Material view's
|
|
1136
|
+
icon alias; an own view picks its icon from `provider.id`. Text comes from
|
|
1137
|
+
`useJskitText()` of `@jskit-ai/kernel/client`, whose `jskit.auth.*` messages
|
|
1138
|
+
are the ones the Material views show, so the app's translations apply.
|
|
1139
|
+
|
|
1140
|
+
The `auth/auth-surface` pattern still supplies the auth surface, the pages,
|
|
1141
|
+
the brand and the managed-preview login; the `auth/own-design-sign-in` pattern
|
|
1142
|
+
replaces its `src/views/auth/LoginView.vue` with a plain HTML and CSS view on
|
|
1143
|
+
`useLoginView()` and adds a second-factor prompt in the app's design (a native
|
|
1144
|
+
`<dialog>` on `useSecondFactorProof()`) for `useSecondFactorStepUp()`. The app
|
|
1145
|
+
renders `AppBrand.vue` there in its own style, and keeps its colours in
|
|
1146
|
+
`src/theme/`.
|
|
1147
|
+
|
|
1148
|
+
### JSKIT's screens with an app's own buttons, dialog and type
|
|
1149
|
+
|
|
1150
|
+
An app on Vuetify that keeps JSKIT's auth views, rather than writing its own,
|
|
1151
|
+
gives them its design system's button, dialog frame and text classes through
|
|
1152
|
+
shell-web's UI kit, `@jskit-ai/shell-web/client/ui`. It provides the kit once,
|
|
1153
|
+
before the app mounts, for example as one of `bootstrapClientShellApp()`'s
|
|
1154
|
+
`appPlugins` in `src/main.js`:
|
|
1155
|
+
|
|
1156
|
+
```js
|
|
1157
|
+
import { provideShellUi } from "@jskit-ai/shell-web/client/ui";
|
|
1158
|
+
import AppButton from "./components/ui/AppButton.vue";
|
|
1159
|
+
import AppDialog from "./components/ui/AppDialog.vue";
|
|
1160
|
+
|
|
1161
|
+
const uiKit = {
|
|
1162
|
+
install: (app) =>
|
|
1163
|
+
provideShellUi(app, {
|
|
1164
|
+
Button: AppButton,
|
|
1165
|
+
Dialog: AppDialog,
|
|
1166
|
+
text: { title: "app-title", heading: "app-heading", body: "app-body", caption: "app-caption" }
|
|
1167
|
+
})
|
|
1168
|
+
};
|
|
1169
|
+
// appPlugins: [pinia, [VueQueryPlugin, { queryClient }], vuetify, uiKit]
|
|
1170
|
+
```
|
|
1171
|
+
|
|
1172
|
+
The kit is partial: a role it leaves out, or a text role its `text` leaves out,
|
|
1173
|
+
stays Material 3's, and an app that provides no kit sees the Material screens
|
|
1174
|
+
as before. An unknown role or text role, a role that is not a Vue component or
|
|
1175
|
+
a text class that is not a string throws when the app provides it. A view
|
|
1176
|
+
reads the kit with `useShellUi()`, which returns `{ Button, Dialog, text }`.
|
|
1177
|
+
|
|
1178
|
+
`Button` draws every button of `DefaultLoginView`, `DefaultResetPasswordView`,
|
|
1179
|
+
`DefaultEmailChangeView`, `DefaultSignOutView`, `SecondFactorSettings` and the
|
|
1180
|
+
second-factor forms, with these props, and its label in its default slot:
|
|
1181
|
+
|
|
1182
|
+
| Prop | Values | Meaning |
|
|
1183
|
+
|---|---|---|
|
|
1184
|
+
| `emphasis` | `"high"`, `"medium"` (default), `"subtle"`, `"low"` | The screen's main action; a secondary action with a fill; a secondary action with an outline, such as one of several equal choices (the provider buttons); an action drawn as text alone. Material: flat, tonal, outlined, text. |
|
|
1185
|
+
| `tone` | `"accent"` (default), `"neutral"`, `"danger"` | Material: primary, secondary, error. |
|
|
1186
|
+
| `size` | `"default"`, `"large"` | A form's main action is `"large"`. |
|
|
1187
|
+
| `type` | `"button"` (default), `"submit"` | |
|
|
1188
|
+
| `disabled` | Boolean | |
|
|
1189
|
+
| `pending` | Boolean | The action is running. |
|
|
1190
|
+
| `block` | Boolean | The button takes its container's width. |
|
|
1191
|
+
| `href` | String | The button is a link. |
|
|
1192
|
+
| `icon` | String | A leading icon, as an icon alias (`"$google"`, `"$refresh"`); an app's button maps the aliases it draws. |
|
|
1193
|
+
|
|
1194
|
+
Other attributes reach the button: `class`, `data-testid`, `aria-*`, a
|
|
1195
|
+
`@click` listener, and `form`, which the step-up dialog's Confirm uses to
|
|
1196
|
+
submit the code form from the dialog's actions, so the app's button passes
|
|
1197
|
+
them to its `<button>` (Vue does this for a single root element).
|
|
1198
|
+
|
|
1199
|
+
`Dialog` is `SecondFactorDialog`'s frame: props `open` (Boolean) and `title`
|
|
1200
|
+
(the dialog's name and heading), the event `close` (Escape, a click outside or
|
|
1201
|
+
the frame's own close control; the view closes it and gives focus back to the
|
|
1202
|
+
control that sent the request), the body in its default slot and the actions,
|
|
1203
|
+
Cancel and then Confirm, in its `actions` slot. A native `<dialog>` opened with
|
|
1204
|
+
`showModal()` while `open`, named by its title, does all of it.
|
|
1205
|
+
|
|
1206
|
+
`text` maps each text role to a class: `title` (a screen's `h1`), `heading`,
|
|
1207
|
+
`subheading`, `strong`, `lead`, `body` and `caption`; Material's are
|
|
1208
|
+
`text-headline-medium`, `text-title-large`, `text-title-medium`,
|
|
1209
|
+
`text-title-small`, `text-body-large`, `text-body-medium` and
|
|
1210
|
+
`text-body-small`.
|
|
1211
|
+
|
|
1212
|
+
The fields, the Sign in and Register switch, the remember-me checkbox, the
|
|
1213
|
+
screen's card and its alerts stay Vuetify components drawn by the app's
|
|
1214
|
+
Vuetify theme, so this app still runs Vuetify; an app with no Vuetify writes
|
|
1215
|
+
its own screens on the composables above.
|
|
1216
|
+
|
|
1062
1217
|
## Verification
|
|
1063
1218
|
|
|
1064
1219
|
Test successful and failed registration/login, sign-out, password reset,
|
|
@@ -371,15 +371,25 @@ script) does this with `@jskit-ai/database-runtime/server/testDatabases`, from
|
|
|
371
371
|
the application's `knexfile.js`:
|
|
372
372
|
|
|
373
373
|
- Each test file running at once gets a database of its own for as long as it
|
|
374
|
-
runs, as both `DB_NAME` and `TEST_DB_NAME
|
|
375
|
-
copies named `<TEST_DB_NAME>_1`, `_2`, ... up to
|
|
376
|
-
as many as the database user may create.
|
|
374
|
+
runs, as both `DB_NAME` and `TEST_DB_NAME`, with the app's `DB_CLIENT`:
|
|
375
|
+
`TEST_DB_NAME` itself, then copies named `<TEST_DB_NAME>_1`, `_2`, ... up to
|
|
376
|
+
the machine's test budget, as many as the database user may create. So the
|
|
377
|
+
user needs them all: on MySQL and MariaDB a grant on `TEST_DB_NAME` and on
|
|
378
|
+
`` `<TEST_DB_NAME>\_%`.* `` (a grant reads an unescaped `_` as any
|
|
379
|
+
character), on PostgreSQL `CREATEDB`. A run that gets fewer databases than
|
|
380
|
+
the files its budget would run at once says so, and why, at its start and
|
|
381
|
+
its end (`jskit test: test files run 1 at a time, not the 4 this machine's
|
|
382
|
+
test budget allows: the database user may not create shop_test_1. ...`),
|
|
383
|
+
and fails once its tests have run: a machine meant to run files in parallel
|
|
384
|
+
never runs them one at a time unnoticed. With no usable `TEST_DB_NAME`
|
|
377
385
|
(unset, the connected database itself, or one the database user may not
|
|
378
|
-
prepare)
|
|
379
|
-
|
|
380
|
-
`
|
|
381
|
-
|
|
382
|
-
|
|
386
|
+
prepare) the files run one at a time on the connected database, the same
|
|
387
|
+
way. To run that way on purpose, set the budget to what the databases allow
|
|
388
|
+
(`V64_TEST_CONCURRENCY=1`); a focused run of one file loses nothing and only
|
|
389
|
+
says which database it used. A copy named like the application's database,
|
|
390
|
+
`STAGING_DB_NAME` or `PRODUCTION_DB_NAME`, or a server that cannot be
|
|
391
|
+
reached, fails the run instead. So does a run while `PROD_DB_NAME`, which
|
|
392
|
+
those two replaced, is set.
|
|
383
393
|
Every file starts from the snapshot, rows included: a copy an earlier file of
|
|
384
394
|
the run used is restored before the next file takes it, so no file sees what
|
|
385
395
|
another wrote.
|
|
@@ -391,6 +401,15 @@ the application's `knexfile.js`:
|
|
|
391
401
|
a later run in the same tree restores them instead of replaying the
|
|
392
402
|
migrations. Only the copies the run made are dropped, and none a session is
|
|
393
403
|
connected to, such as another run's: the run names each copy it kept and why.
|
|
404
|
+
- A run that never reached its end (killed with `SIGKILL`, stopped at a
|
|
405
|
+
command's time limit, or on a machine that went down) leaves its copies. So
|
|
406
|
+
every run, a browser run's `prepare` module included, starts by dropping the
|
|
407
|
+
numbered copies of its database it will not make itself (`<name>_<count>` and
|
|
408
|
+
up), none a session is connected to, and its summary says so
|
|
409
|
+
(`dropped 1 numbered test database(s) earlier runs left (shop_test_7)`): a
|
|
410
|
+
killed run's copies last until the next run starts, never longer. Only names
|
|
411
|
+
JSKIT gives a copy count: `<name>_snapshot` and a project's own lettered
|
|
412
|
+
copies stay. Two runs at once on one database name still are not supported.
|
|
394
413
|
- The snapshot holds the schema as the engine reports it and the rows the
|
|
395
414
|
migrations wrote, including the migration ledger. On MySQL and MariaDB it is
|
|
396
415
|
each table's `SHOW CREATE TABLE` and rows, in
|
|
@@ -420,6 +439,17 @@ the application's `knexfile.js`:
|
|
|
420
439
|
`knex.migrate.latest()`), and `files` lists every file it reads, its own
|
|
421
440
|
module included, relative to the application root: their contents join the
|
|
422
441
|
digest, so changing one takes a new snapshot.
|
|
442
|
+
- A test file that needs a scratch database beside its own copy, an empty one
|
|
443
|
+
for tables the test creates or several at once, takes each from
|
|
444
|
+
`createPackageTestKnex(t, { environment: process.env })` (from
|
|
445
|
+
`@jskit-ai/resource-runtime/test`): with the run's `DB_CLIENT` in the file's
|
|
446
|
+
environment, each call on MySQL or MariaDB claims one of the 26 lettered
|
|
447
|
+
copies of the run's designated database, `<TEST_DB_NAME>_a` to `_z`,
|
|
448
|
+
recreated empty and dropped after the test, and on PostgreSQL a schema of
|
|
449
|
+
its own in the file's database
|
|
450
|
+
([data access tests](/guide/framework/data-access#tests)). A file is the
|
|
451
|
+
unit that starts from the snapshot: tests that each need the snapshot's
|
|
452
|
+
database afresh go in files of their own.
|
|
423
453
|
- A test that runs migrations up or down, or otherwise changes the tables,
|
|
424
454
|
leaves its database dirty: its tables or migration ledger differ from the
|
|
425
455
|
snapshot's. The harness restores the snapshot before another test file uses
|
|
@@ -479,12 +509,16 @@ disable email, payments or other external effects: configure those test controls
|
|
|
479
509
|
and verify the actual server identity before destructive requests.
|
|
480
510
|
|
|
481
511
|
A host's browser test target, such as a Vibe64 Outputs target with
|
|
482
|
-
``- Data: `test` ``, runs `jskit browser-test-server <host> <port>`:
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
512
|
+
``- Data: `test` ``, runs `jskit browser-test-server <host> <port> <workers>`:
|
|
513
|
+
`<workers>` servers of the app's own `browserTestConfig()` (1 to 64, else one),
|
|
514
|
+
worker *i* on `<port>`+*i*, on the production build, each with the database its
|
|
515
|
+
`prepare` module gives that worker (`BROWSER_TEST_DB_NAME` itself for the first
|
|
516
|
+
in the database patterns), its test-only `env` and `APP_ENV=test`, on the host's
|
|
486
517
|
address. The JSKIT Stack piece declares that target as `test-app`, so
|
|
487
518
|
`vibe64-helper playwright --target test-app npm-run test:e2e` runs the app's
|
|
488
|
-
suite against its own test database from the first commit
|
|
489
|
-
|
|
490
|
-
|
|
519
|
+
suite against its own test database from the first commit, one Playwright worker
|
|
520
|
+
per server: the host lists them in `PLAYWRIGHT_WORKER_TARGETS`, and
|
|
521
|
+
`browserTestConfig()` gives each worker its own server and signed-in state and
|
|
522
|
+
refuses another worker count. The target signs nothing in; the host supplies
|
|
523
|
+
each worker's login state through the target's Preview identity, the same
|
|
524
|
+
command as the normal target's.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<!-- Generated by `npm run agent-docs:build` from `packages/agent-docs/site/guide/app-setup/service-keys.md`. Do not edit manually. -->
|
|
2
|
+
|
|
3
|
+
# Service keys (local auth)
|
|
4
|
+
|
|
5
|
+
A service key lets another application's server, such as an assistant that
|
|
6
|
+
works for the people of a household or a team, call this app's bearer routes
|
|
7
|
+
(the [MCP endpoint](/guide/app-extras/assistant#mcp-endpoint) among them) as one
|
|
8
|
+
of the app's users at a time. Each call names the user it acts as and runs with
|
|
9
|
+
exactly that user's rights: what they may see and do, in their workspaces,
|
|
10
|
+
recorded as done by them through the key. The key never acts as itself, and no
|
|
11
|
+
person signs in anywhere for it.
|
|
12
|
+
|
|
13
|
+
## Making a key
|
|
14
|
+
|
|
15
|
+
A key belongs to a dedicated service user, an ordinary local auth account
|
|
16
|
+
(enabled, with no password anyone uses) whose display name names the key in
|
|
17
|
+
what the app records, such as "Mercbot (Smith home)". An administrator makes the
|
|
18
|
+
key with the app's own tooling, which writes one row of the sessions store:
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
import { createServiceKeyRecord } from "@jskit-ai/auth-provider-local-core/server/lib/index";
|
|
22
|
+
|
|
23
|
+
const { key, record } = createServiceKeyRecord({ userId: serviceUser.id, days: 365 });
|
|
24
|
+
await backend.withTransaction((tx) => tx.sessions.create(record));
|
|
25
|
+
// Show `key` once: the store keeps only its hash.
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`record` is a session with purpose `service-key` (`SERVICE_KEY_PURPOSE`),
|
|
29
|
+
lasting `days` whole days (365 unless given, at most 3650). No table or column
|
|
30
|
+
changes: a key is a row of the table local auth already keeps sessions in.
|
|
31
|
+
Revoking that row (`tx.sessions.revoke(record.id)`) ends the key from the next
|
|
32
|
+
call, and so does disabling the service user, which ends all its keys. A key
|
|
33
|
+
never signs in a browser: cookie authentication takes only ordinary sessions.
|
|
34
|
+
|
|
35
|
+
## Calling as a user
|
|
36
|
+
|
|
37
|
+
```http
|
|
38
|
+
POST /api/w/acme/mcp
|
|
39
|
+
Authorization: Bearer svk_…
|
|
40
|
+
Act-As-User: 42
|
|
41
|
+
Content-Type: application/json
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`Act-As-User` names the user by id, or by email (any value with an `@`). An
|
|
45
|
+
email names a user only when exactly one enabled account has it: in an app
|
|
46
|
+
whose accounts may share an email, more than one enabled account with it names
|
|
47
|
+
no one, and the caller acts by the user's id instead. The MCP endpoint answers
|
|
48
|
+
the id it acted as in `Acting-As-User`, so a caller that started from an email
|
|
49
|
+
names the id from then on.
|
|
50
|
+
|
|
51
|
+
A backend answers every account with an email through
|
|
52
|
+
`users.findAllByEmail(email)`, the disabled ones too; one whose emails are
|
|
53
|
+
unique answers one or none. The file and database backends do; an app's own
|
|
54
|
+
backend adds it, and without it acting by email fails naming the fix.
|
|
55
|
+
|
|
56
|
+
Only routes that declare `config: { credentials: "bearer" }` take a key. Every
|
|
57
|
+
other route ignores `Authorization` and signs in by cookies alone, and a cookie
|
|
58
|
+
never signs in a bearer route, so a key never becomes a browser session and a
|
|
59
|
+
browser session never acts as anyone. auth-core holds both ways whatever the
|
|
60
|
+
provider answers: a route that takes cookies treats a bearer answer as signed
|
|
61
|
+
out, and a bearer route a cookie answer. A bearer route takes no CSRF token, since
|
|
62
|
+
it reads no cookies. The call's sign-in has no address and no second factor, so
|
|
63
|
+
a route that asks for either refuses it.
|
|
64
|
+
|
|
65
|
+
## Refusals
|
|
66
|
+
|
|
67
|
+
Each refusal says why, with its code, and none falls back to the key's own
|
|
68
|
+
service user:
|
|
69
|
+
|
|
70
|
+
| Status | Code | When |
|
|
71
|
+
| --- | --- | --- |
|
|
72
|
+
| 401 | `auth.serviceKey.required` | No `Authorization` header. |
|
|
73
|
+
| 401 | `auth.serviceKey.invalid` | The key is unknown, revoked or expired, or its service user is disabled. |
|
|
74
|
+
| 403 | `auth.serviceKey.notServiceKey` | A person's own sign-in token instead of a key. |
|
|
75
|
+
| 400 | `auth.serviceKey.actAsRequired` | No `Act-As-User`. |
|
|
76
|
+
| 403 | `auth.serviceKey.actAsUnknown` | No user has that id or email. |
|
|
77
|
+
| 403 | `auth.serviceKey.actAsInactive` | That user is disabled. |
|
|
78
|
+
| 403 | `auth.serviceKey.actAsAmbiguous` | More than one enabled account has that email. |
|
|
79
|
+
| 403 | `auth.serviceKey.actAsSelf` | It names the key's own service user. |
|
|
80
|
+
|
|
81
|
+
A 401 carries `WWW-Authenticate: Bearer`, with `error="invalid_token"` when a
|
|
82
|
+
token was sent. The answer's body is the usual `{ error, code }`.
|
|
83
|
+
|
|
84
|
+
## Who did it
|
|
85
|
+
|
|
86
|
+
The action context of a key's call has the user it acts as as `actor`, as any
|
|
87
|
+
signed-in request does, and the key as `actingVia: { userId, name }` (the
|
|
88
|
+
service user's id and display name). An app's audit records the actor as who
|
|
89
|
+
did it and `actingVia.name` as how, for example "Anna Smith, via Mercbot (Smith
|
|
90
|
+
home)".
|
|
91
|
+
|
|
92
|
+
## A bearer route of your own
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
router.register("POST", "/api/books/export", {
|
|
96
|
+
auth: "required",
|
|
97
|
+
config: { credentials: "bearer" },
|
|
98
|
+
meta: { tags: ["books"], summary: "Export the books of the user the key acts as." }
|
|
99
|
+
}, handler);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
It needs an auth provider that signs bearer requests in: local auth does with
|
|
103
|
+
service keys; another provider's answer is refused.
|
|
@@ -92,6 +92,14 @@ with an unknown `email_verified_at` column. Read each package's CHANGELOG
|
|
|
92
92
|
**Upgrading** section too, for the changes the application itself must make,
|
|
93
93
|
such as a feature to register.
|
|
94
94
|
|
|
95
|
+
The updater compares each package's migration files with the ones its previous
|
|
96
|
+
version installed in `node_modules`. In a checkout that was never installed,
|
|
97
|
+
such as a fresh worktree, it compares through the previous `package-lock.json`
|
|
98
|
+
instead: a package at the same version adds none, and a package the lock lacked
|
|
99
|
+
adds all of its own. A package whose version moved has no earlier files there
|
|
100
|
+
to compare, so the updater names it (`<package> <previous> -> <new>`) rather
|
|
101
|
+
than counting its migrations as new, and says to run `npm run db:migrate`.
|
|
102
|
+
|
|
95
103
|
## Separately composed packages
|
|
96
104
|
|
|
97
105
|
Pass each additional manifest explicitly to both commands:
|
|
@@ -164,7 +172,7 @@ For example:
|
|
|
164
172
|
```json
|
|
165
173
|
{
|
|
166
174
|
"scripts": {
|
|
167
|
-
"verify": "npm run jskit:check && npm run lint && npm test && npm run
|
|
175
|
+
"verify": "npm run jskit:check && npm run lint && npm test && npm run test:client && npm run test:e2e"
|
|
168
176
|
}
|
|
169
177
|
}
|
|
170
178
|
```
|
|
@@ -225,8 +233,11 @@ An application adopts it once, at the upgrade that brings `jskit test`:
|
|
|
225
233
|
1. Its test scripts run `jskit test` with their own files or globs, for
|
|
226
234
|
example `"test": "jskit test"`, never `node --test` or
|
|
227
235
|
`--test-concurrency`.
|
|
228
|
-
2. `playwright.config.*`
|
|
229
|
-
|
|
236
|
+
2. `playwright.config.*` is `browserTestConfig()`, or sets
|
|
237
|
+
`workers: browserTestWorkers()` with
|
|
238
|
+
`import { browserTestWorkers } from "@jskit-ai/jskit-catalog/browser-tests";`
|
|
239
|
+
(half the budget: each worker drives a browser), and the Vitest config sets
|
|
240
|
+
`maxWorkers: testConcurrency()`, with
|
|
230
241
|
`import { testConcurrency } from "@jskit-ai/jskit-catalog/test-budget";`,
|
|
231
242
|
and no script passes `--workers`, `-j` or `--maxWorkers`.
|
|
232
243
|
3. Files that collide when run together get their own port, temporary
|
|
@@ -254,8 +265,9 @@ application:
|
|
|
254
265
|
`defineConfig(browserTestConfig({ testDir: "./tests/e2e", prepare: "tests/e2e/databases.js" }))`
|
|
255
266
|
from `@jskit-ai/jskit-catalog/browser-tests`, with `server`, `build`, `env`
|
|
256
267
|
or `port` only where its own differ from `node ./bin/server.js`,
|
|
257
|
-
`npm run build` and
|
|
258
|
-
|
|
268
|
+
`npm run build` and free ports (`port` only for a port its host must
|
|
269
|
+
use), `globalTimeout` only for a suite measured to need more than its
|
|
270
|
+
default (80 worker-minutes, never under 20 minutes), and `actionTimeout` or `navigationTimeout` only
|
|
259
271
|
for an action or page measured to need more than 15 or 30 seconds (a stale
|
|
260
272
|
locator should fail in seconds, not minutes). Settings a config adds (projects, a globalSetup
|
|
261
273
|
that proves the server's identity, `timezoneId`) spread over the result:
|
|
@@ -2143,6 +2143,19 @@ it. Check and judge, for each file:
|
|
|
2143
2143
|
- its statements per row are still measured, as any write path's are: a batch
|
|
2144
2144
|
of 200 rows costs about what a batch of 10 does.
|
|
2145
2145
|
|
|
2146
|
+
Tables the application's people define while it runs, which no table resource
|
|
2147
|
+
describes, can live in json-rest-api's AnyAPI storage, built in such an
|
|
2148
|
+
infrastructure module from `@jskit-ai/resource-runtime/server/anyapi`:
|
|
2149
|
+
`AnyapiRegistry`, `JsonRestApi`, `RestApiAnyapiKnexPlugin`, `RestApiPlugin`,
|
|
2150
|
+
`RowPolicyPlugin` and `ensureAnyApiSchema`, the very objects of the
|
|
2151
|
+
json-rest-api copy the runtime's handles run on. Import them from there and
|
|
2152
|
+
declare no json-rest-api in the application: json-rest-api knows the
|
|
2153
|
+
transactions `api.transaction` opened by identity, so an AnyAPI write given a
|
|
2154
|
+
handle's `txOptions.trx` joins that transaction only on the runtime's copy,
|
|
2155
|
+
and beside a second copy it fails with "transaction must be an active
|
|
2156
|
+
transaction from api.transaction". `npm run jskit:update` then moves the one
|
|
2157
|
+
copy with the catalog.
|
|
2158
|
+
|
|
2146
2159
|
`jskit check` also fails:
|
|
2147
2160
|
|
|
2148
2161
|
- a table with two table resources;
|
|
@@ -240,8 +240,8 @@ JSKIT ships these exact sizes; an app never re-implements or overrides them:
|
|
|
240
240
|
and the 48dp target. No icon button is under 32dp, and a target stops at
|
|
241
241
|
the edge of a button beside it, so each of a row's touching icon buttons
|
|
242
242
|
answers its own press;
|
|
243
|
-
- one-line button labels, ending in an ellipsis: keep labels short,
|
|
244
|
-
one that can run long, such as a name, its full label as `title`;
|
|
243
|
+
- one-line button and chip labels, ending in an ellipsis: keep labels short,
|
|
244
|
+
and give one that can run long, such as a name, its full label as `title`;
|
|
245
245
|
- 12dp cards: flat (the default) and tonal at level 0, `variant="elevated"`
|
|
246
246
|
at level 1; flat expansion panels;
|
|
247
247
|
- 28dp dialogs and bottom-sheet top corners, square full-screen dialogs;
|
|
@@ -313,8 +313,7 @@ dialog, chip or FAB.
|
|
|
313
313
|
color alone.
|
|
314
314
|
- Surfaces are separated by tone (`surface-container-lowest` to
|
|
315
315
|
`-highest`), not borders: no `variant="outlined"` cards and no `border` on
|
|
316
|
-
cards or sheets.
|
|
317
|
-
and tonal cards.
|
|
316
|
+
cards or sheets.
|
|
318
317
|
- Keep WCAG AA contrast in both schemes. Use elevation `0` through `5` and
|
|
319
318
|
component variants instead of arbitrary shadows.
|
|
320
319
|
|
|
@@ -48,9 +48,15 @@ database time, apply that page to the path.
|
|
|
48
48
|
that runs files one at a time ([test-run rules](/guide/framework/typed-features#test-run-rules)).
|
|
49
49
|
- Files that collide are isolated, never run one at a time: a port from
|
|
50
50
|
`listen(0)`, a directory from `mkdtemp`, the database `jskit test --databases`
|
|
51
|
-
gives each file,
|
|
51
|
+
gives each file, a scratch database from
|
|
52
|
+
`createPackageTestKnex(t, { environment: process.env })` for a test that
|
|
53
|
+
needs an empty one (or several), and a Vite `cacheDir` of its own. The
|
|
52
54
|
`// jskit-test: alone - <reason>` marker is only for a file that holds a
|
|
53
55
|
resource of the whole machine.
|
|
56
|
+
- A `jskit test --databases` run whose databases let fewer files run at once
|
|
57
|
+
than the budget (no `TEST_DB_NAME`, or copies the database user may not
|
|
58
|
+
create) says why at its start and end and fails: give the user its copies
|
|
59
|
+
([Integration test databases](/guide/app-setup/database-layer#integration-test-databases)).
|
|
54
60
|
- `jskit test --databases` restores each file's database from a snapshot
|
|
55
61
|
rebuilt only when the migrations' digest changes. A file that runs
|
|
56
62
|
`knex.migrate.latest()` itself replays the whole history for every file:
|