@h-ai/kit 0.1.0-alpha.66 → 0.1.0-alpha.67

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/README.en.md CHANGED
@@ -4,23 +4,11 @@
4
4
 
5
5
  [Framework home](../../README.en.md) · Related modules: [@h-ai/core](../core/README.en.md) · [@h-ai/crypto](../crypto/README.en.md) · [@h-ai/iam](../iam/README.en.md)
6
6
 
7
- `@h-ai/kit` integrates SvelteKit with hai-framework, providing a shared request pipeline and same-origin endpoint utilities:
8
-
9
- - `kit.createHandle()`: session parsing, route guards, middleware chains, and optional transport/cookie encryption.
10
- - `kit.handler()`: an exception boundary for API endpoints.
11
- - `kit.guard` / `kit.response` / `kit.validate` / `kit.auth` / `kit.client` / `kit.crud`
7
+ ## Introduction
12
8
 
13
- > Shared cross-platform HTTP contracts belong in `@h-ai/api-contract`, are mounted by `@h-ai/serv`, and are called through the `@h-ai/api-client` typed client. `@h-ai/kit` does not define or host business API contracts.
14
-
15
- ## Installation
16
-
17
- ```bash
18
- npm install @h-ai/kit
19
- npm install svelte @sveltejs/kit zod
20
- npm install -D @sveltejs/vite-plugin-svelte vite
21
- ```
9
+ `@h-ai/kit` integrates SvelteKit with hai-framework, providing a shared request pipeline and same-origin endpoint utilities:
22
10
 
23
- ## Capabilities
11
+ ## Core features
24
12
 
25
13
  - Handle hook composition (`createHandle` / `sequence`)
26
14
  - Authentication/role/permission guards (`guard.require` / `guard.check`)
@@ -32,14 +20,24 @@ npm install -D @sveltejs/vite-plugin-svelte vite
32
20
  - A2A integration: discovery defaults to `/.well-known/agent-card.json`. With `authenticate` configured, null/undefined returns 401; anonymous access is allowed only without authentication configured. API Key parameters come from the complete Agent Card's `securitySchemes.apiKey`. Hooks and explicit A2A routes share JSON-RPC parse-error and SSE cancellation cleanup logic.
33
21
  - Dual build mode (`createAdapter()`)
34
22
 
35
- ## Dependencies
23
+ ## Getting started
24
+
25
+ ### Installation
26
+
27
+ ```bash
28
+ npm install @h-ai/kit @h-ai/core sm-crypto@0.5.7
29
+ npm install svelte @sveltejs/kit zod
30
+ npm install -D @sveltejs/vite-plugin-svelte vite
31
+ ```
32
+
33
+ ### Dependencies
36
34
 
37
35
  - `@h-ai/iam`: optional authentication/authorization for A2A; initialize before using kit's A2A features.
38
36
  - `@h-ai/crypto`: optional transport/cookie encryption; initialize before using encryption in kit.
39
37
 
40
- ## Quick start
38
+ ### Quick start
41
39
 
42
- ### Project configuration
40
+ #### Project configuration
43
41
 
44
42
  **svelte.config.js**:
45
43
 
@@ -70,11 +68,13 @@ import { defineConfig } from 'vite'
70
68
  export default defineConfig({
71
69
  plugins: [sveltekit(), tailwindcss()],
72
70
  optimizeDeps: { exclude: ['bits-ui'] },
73
- ssr: { noExternal: [/@h-ai\//] },
71
+ ssr: { noExternal: ['@h-ai/ui', '@h-ai/kit'], external: ['@h-ai/core', 'sm-crypto'] },
74
72
  })
75
73
  ```
76
74
 
77
- ### Build the request pipeline
75
+ When using Crypto or Kit/IAM, include `sm-crypto@0.5.7` in application production dependencies. CLI projects already do this; for manual setup, run `pnpm add sm-crypto@0.5.7`. The external option alone is insufficient: adapter-node also uses direct production dependencies to preserve native package loading.
76
+
77
+ #### Build the request pipeline
78
78
 
79
79
  **src/hooks.server.ts**:
80
80
 
@@ -98,7 +98,7 @@ const haiHandle = kit.createHandle({
98
98
  export const handle: Handle = haiHandle
99
99
  ```
100
100
 
101
- ### API endpoints
101
+ #### API endpoints
102
102
 
103
103
  ```typescript
104
104
  import { kit } from '@h-ai/kit'
@@ -116,7 +116,7 @@ export const POST = kit.handler(async ({ request, locals }) => {
116
116
  })
117
117
  ```
118
118
 
119
- ### Browser client
119
+ #### Browser client
120
120
 
121
121
  `kit.client.create()` targets SvelteKit same-origin endpoints. Use `@h-ai/api-client` for cross-origin access to public APIs from Web, apps, or mini programs.
122
122
 
@@ -139,7 +139,7 @@ const response = await apiFetch('/api/users', { method: 'GET' })
139
139
  >
140
140
  > Authentication: prefer httpOnly cookies for same-origin SvelteKit endpoints and verify them on the server. Browsers need not write sensitive tokens to `localStorage`. If Bearer headers are required, provide a custom `BrowserTokenStore`, or set an in-memory token with `kit.auth.setBrowserToken()` before `kit.client.create({ auth: true })`.
141
141
 
142
- ### Same-origin transport encryption
142
+ #### Same-origin transport encryption
143
143
 
144
144
  kit delegates transport encryption to `@h-ai/crypto`. The server creates a manager with `crypto.transport.createServer()`; the browser installs a same-origin fetch wrapper with one call to `kit.client.installBrowserTransport(kitConfig, { crypto })`. Applications only configure the top-level `crypto` handle.
145
145
 
@@ -203,7 +203,7 @@ Transport applies by default to same-origin `/api/*` endpoints, SvelteKit `__dat
203
203
 
204
204
  Security defaults to fail-closed: with `requireEncryption: true`, protected paths without `X-Client-Id` return 400. An unavailable transport manager, unencryptable response, or encryption size limit returns an error rather than forwarding plaintext business data. `requireEncryption: false` is for staged migration only and is not recommended in production.
205
205
 
206
- ### Shared transport configuration with `_kit.yml`
206
+ #### Shared transport configuration with `_kit.yml`
207
207
 
208
208
  `@h-ai/kit` provides `KitConfigSchema` / `resolveKitConfig()` so a single `_kit.yml`
209
209
  can drive both `hooks.server.ts` and browser `kit.client.installBrowserTransport()`:
@@ -236,7 +236,7 @@ export const appKitConfig = resolveKitConfig(parse(rawKitConfig) ?? {})
236
236
  For server-only configuration, use `core.config.validate('kit', KitConfigSchema)` as well.
237
237
  Because the browser may read this configuration, `_kit.yml` must contain only public server/transport paths and switches, never secrets.
238
238
 
239
- ## Configuration
239
+ ### Configuration
240
240
 
241
241
  `kit.createHandle()` options:
242
242
 
@@ -253,7 +253,7 @@ Because the browser may read this configuration, `_kit.yml` must contain only pu
253
253
 
254
254
  With `crypto.encryptedCookies`, also provide `crypto.cookieEncryptionKey` or `HAI_KIT_COOKIE_KEY`. Missing keys fail immediately in `createHandle()`. Plaintext, damaged ciphertext, or decryption failures for protected cookies are treated as absent; encryption failures never fall back to writing plaintext.
255
255
 
256
- ## Export paths
256
+ ### Export paths
257
257
 
258
258
  - `@h-ai/kit`: main entry, with the `kit` namespace and types.
259
259
  - `@h-ai/kit/client`: browser client.
@@ -262,7 +262,7 @@ With `crypto.encryptedCookies`, also provide `crypto.cookieEncryptionKey` or `HA
262
262
  - `@h-ai/kit/a2a`: A2A integration.
263
263
  - `@h-ai/kit/crypto`: crypto integration.
264
264
 
265
- ## Configuration driven authentication
265
+ ### Configuration driven authentication
266
266
 
267
267
  Agreements support configuration-loaded userAgreementMarkdown/privacyPolicyMarkdown and URLs. Markdown takes priority for the same agreement and is safely rendered in a modal.
268
268
 
@@ -270,13 +270,25 @@ Export standard handlers from kit.auth.createApi(iam), use kit.auth.publicPaths
270
270
 
271
271
  [完整 IAM 配置 / IAM configuration](../iam/README.en.md)
272
272
 
273
- ## Error handling
273
+ ### Error handling
274
274
 
275
275
  - Wrap API endpoints with `kit.handler()`.
276
276
  - `kit.validate.body` / `kit.guard.require` throw `Response` for SvelteKit control flow.
277
277
  - `kit.handler()` converts non-control-flow exceptions into `500 INTERNAL_ERROR` responses.
278
278
 
279
- ## Tests
279
+ ### CRUD fields
280
+
281
+ Declarative CRUD fields support `colSpan: 'auto' | 1 | 2` for UI form widths. `validation.message` accepts a string or `() => string` for current-locale validation messages. Configure layout through `CrudPage.form`; validate independently on the server.
282
+
283
+ ### Runtime behavior and limits
284
+
285
+ - `kit.createHandle()`: session parsing, route guards, middleware chains, and optional transport/cookie encryption.
286
+ - `kit.handler()`: an exception boundary for API endpoints.
287
+ - `kit.guard` / `kit.response` / `kit.validate` / `kit.auth` / `kit.client` / `kit.crud`
288
+
289
+ > Shared cross-platform HTTP contracts belong in `@h-ai/api-contract`, are mounted by `@h-ai/serv`, and are called through the `@h-ai/api-client` typed client. `@h-ai/kit` does not define or host business API contracts.
290
+
291
+ ## Development and testing
280
292
 
281
293
  ```bash
282
294
  pnpm --filter @h-ai/kit test
@@ -285,7 +297,3 @@ pnpm --filter @h-ai/kit test
285
297
  ## License
286
298
 
287
299
  Apache-2.0
288
-
289
- ## CRUD fields
290
-
291
- Declarative CRUD fields support `colSpan: 'auto' | 1 | 2` for UI form widths. `validation.message` accepts a string or `() => string` for current-locale validation messages. Configure layout through `CrudPage.form`; validate independently on the server.
package/README.ja.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  [フレームワークのホーム](../../README.ja.md) · 関連モジュール:[@h-ai/core](../core/README.ja.md) · [@h-ai/crypto](../crypto/README.ja.md) · [@h-ai/iam](../iam/README.ja.md)
6
6
 
7
+ ## 概要
8
+
7
9
  `@h-ai/kit` は hai-framework の SvelteKit 統合モジュールで、共通のリクエストパイプラインと同一オリジンの endpoint ツールを提供します:
8
10
 
9
11
  - `kit.createHandle()`:セッション解析、ルートガード、middleware チェーン、任意の通信・Cookie 暗号化。
@@ -12,14 +14,6 @@
12
14
 
13
15
  > クロスプラットフォームの公開 HTTP contract は `@h-ai/api-contract` で定義し、`@h-ai/serv` にマウント、`@h-ai/api-client` の型付きクライアントで呼び出します。`@h-ai/kit` は業務 API contract を定義・提供しません。
14
16
 
15
- ## インストール
16
-
17
- ```bash
18
- npm install @h-ai/kit
19
- npm install svelte @sveltejs/kit zod
20
- npm install -D @sveltejs/vite-plugin-svelte vite
21
- ```
22
-
23
17
  ## 主な機能
24
18
 
25
19
  - Handle Hook の合成(`createHandle` / `sequence`)
@@ -32,14 +26,24 @@ npm install -D @sveltejs/vite-plugin-svelte vite
32
26
  - A2A 統合:既定の検出パスは `/.well-known/agent-card.json`。`authenticate` 設定時は null/undefined が 401 となり、認証未設定時のみ匿名を許可します。API Key の引数は完全な Agent Card の `securitySchemes.apiKey` から取得します。Hook と明示的 A2A ルートは JSON-RPC 解析エラー・SSE キャンセル時の解放処理を共有します。
33
27
  - 2 種類のビルドモード(`createAdapter()`)
34
28
 
35
- ## 依存関係
29
+ ## 使い始める
30
+
31
+ ### インストール
32
+
33
+ ```bash
34
+ npm install @h-ai/kit @h-ai/core sm-crypto@0.5.7
35
+ npm install svelte @sveltejs/kit zod
36
+ npm install -D @sveltejs/vite-plugin-svelte vite
37
+ ```
38
+
39
+ ### 依存関係
36
40
 
37
41
  - `@h-ai/iam`:A2A 用の認証・認可(任意)。A2A 機能を使う前に初期化。
38
42
  - `@h-ai/crypto`:通信・Cookie 暗号化(任意)。暗号化を使う前に初期化。
39
43
 
40
- ## クイックスタート
44
+ ### クイックスタート
41
45
 
42
- ### プロジェクト設定
46
+ #### プロジェクト設定
43
47
 
44
48
  **svelte.config.js**:
45
49
 
@@ -70,11 +74,13 @@ import { defineConfig } from 'vite'
70
74
  export default defineConfig({
71
75
  plugins: [sveltekit(), tailwindcss()],
72
76
  optimizeDeps: { exclude: ['bits-ui'] },
73
- ssr: { noExternal: [/@h-ai\//] },
77
+ ssr: { noExternal: ['@h-ai/ui', '@h-ai/kit'], external: ['@h-ai/core', 'sm-crypto'] },
74
78
  })
75
79
  ```
76
80
 
77
- ### リクエストパイプラインの構築
81
+ Crypto または Kit/IAM を使う場合、アプリの本番依存に `sm-crypto@0.5.7` を含めます。CLI 生成済みのプロジェクトでは設定済みです。手動導入は `pnpm add sm-crypto@0.5.7` を実行してください。adapter-node は直接の本番依存も参照するため、external 指定だけでは不十分です。
82
+
83
+ #### リクエストパイプラインの構築
78
84
 
79
85
  **src/hooks.server.ts**:
80
86
 
@@ -98,7 +104,7 @@ const haiHandle = kit.createHandle({
98
104
  export const handle: Handle = haiHandle
99
105
  ```
100
106
 
101
- ### API endpoint
107
+ #### API endpoint
102
108
 
103
109
  ```typescript
104
110
  import { kit } from '@h-ai/kit'
@@ -116,7 +122,7 @@ export const POST = kit.handler(async ({ request, locals }) => {
116
122
  })
117
123
  ```
118
124
 
119
- ### ブラウザークライアント
125
+ #### ブラウザークライアント
120
126
 
121
127
  `kit.client.create()` は SvelteKit の同一オリジン endpoint 向けです。Web・アプリ・ミニプログラムからクロスオリジンで公開 API を使う場合は `@h-ai/api-client` を使用してください。
122
128
 
@@ -139,7 +145,7 @@ const response = await apiFetch('/api/users', { method: 'GET' })
139
145
  >
140
146
  > 認証:同一オリジンの SvelteKit endpoint は httpOnly Cookie を優先し、サーバーで Cookie を読んで認証します。機密 Token を `localStorage` に保存する必要はありません。Bearer Header が必要なら独自の `BrowserTokenStore`、または `kit.auth.setBrowserToken()` でページ内メモリーに保存してから `kit.client.create({ auth: true })` を使います。
141
147
 
142
- ### 同一オリジンの通信暗号化
148
+ #### 同一オリジンの通信暗号化
143
149
 
144
150
  kit の通信暗号化は `@h-ai/crypto` に委譲します。サーバーは `crypto.transport.createServer()` で管理器を作成し、ブラウザーは `kit.client.installBrowserTransport(kitConfig, { crypto })` の 1 行で同一オリジンの fetch ラッパーを導入します。アプリ側はトップレベルの `crypto` のみを設定します。
145
151
 
@@ -203,7 +209,7 @@ transport は既定で同一オリジンの `/api/*`、SvelteKit の `__data.jso
203
209
 
204
210
  既定の安全方針は fail-closed です。`requireEncryption: true` で保護パスに `X-Client-Id` がなければ 400 を返します。管理器の利用不可、応答の暗号化失敗、暗号化サイズ上限超過はエラーになり、平文の業務応答は渡しません。`requireEncryption: false` は段階的移行用で、本番では推奨しません。
205
211
 
206
- ### `_kit.yml` による共通 transport 設定
212
+ #### `_kit.yml` による共通 transport 設定
207
213
 
208
214
  `@h-ai/kit` は `KitConfigSchema` / `resolveKitConfig()` を提供し、同じ `_kit.yml` から
209
215
  `hooks.server.ts` とブラウザーの `kit.client.installBrowserTransport()` の両方を設定できます:
@@ -236,7 +242,7 @@ export const appKitConfig = resolveKitConfig(parse(rawKitConfig) ?? {})
236
242
  サーバーのみで設定を読む場合は `core.config.validate('kit', KitConfigSchema)` も利用できます。
237
243
  ブラウザーも読む可能性があるため、`_kit.yml` は公開 server/transport パスとスイッチのみを含め、秘密鍵などを書かないでください。
238
244
 
239
- ## 設定
245
+ ### 設定
240
246
 
241
247
  `kit.createHandle()` の設定項目:
242
248
 
@@ -253,7 +259,7 @@ export const appKitConfig = resolveKitConfig(parse(rawKitConfig) ?? {})
253
259
 
254
260
  `crypto.encryptedCookies` を設定する場合、`crypto.cookieEncryptionKey` または `HAI_KIT_COOKIE_KEY` が必要です。鍵がなければ `createHandle()` ですぐエラーになります。保護対象 Cookie の平文・破損暗号文・復号失敗は未存在として扱い、暗号化失敗時も平文保存に切り替えません。
255
261
 
256
- ## エクスポートパス
262
+ ### エクスポートパス
257
263
 
258
264
  - `@h-ai/kit`:主入口。`kit` 名前空間と型を提供。
259
265
  - `@h-ai/kit/client`:ブラウザークライアント。
@@ -262,7 +268,7 @@ export const appKitConfig = resolveKitConfig(parse(rawKitConfig) ?? {})
262
268
  - `@h-ai/kit/a2a`:A2A 統合。
263
269
  - `@h-ai/kit/crypto`:暗号モジュール統合。
264
270
 
265
- ## 設定による認証画面
271
+ ### 設定による認証画面
266
272
 
267
273
  規約は設定の userAgreementMarkdown/privacyPolicyMarkdown または URL を使用できます。同じ規約は Markdown 本文を優先して安全な Modal で描画します。
268
274
 
@@ -270,22 +276,22 @@ kit.auth.createApi(iam) の標準 handler と kit.auth.publicPaths を使用し
270
276
 
271
277
  [完整 IAM 配置 / IAM configuration](../iam/README.ja.md)
272
278
 
273
- ## エラー処理
279
+ ### エラー処理
274
280
 
275
281
  - API endpoint は `kit.handler()` でラップすることを推奨。
276
282
  - `kit.validate.body` / `kit.guard.require` は SvelteKit の制御フローとして `Response` を throw。
277
283
  - 制御フロー以外の例外は `kit.handler()` が `500 INTERNAL_ERROR` 応答に変換。
278
284
 
279
- ## テスト
285
+ ### CRUD fields
286
+
287
+ 宣言型 CRUD 項目は UI フォームの幅を指定する `colSpan: 'auto' | 1 | 2` に対応します。`validation.message` は文字列または `() => string` を受け取り、現在の言語で表示できます。レイアウトは `CrudPage.form` で設定し、サーバーでも検証してください。
288
+
289
+ ## 開発とテスト
280
290
 
281
291
  ```bash
282
292
  pnpm --filter @h-ai/kit test
283
293
  ```
284
294
 
285
- ## License
295
+ ## ライセンス
286
296
 
287
297
  Apache-2.0
288
-
289
- ## CRUD fields
290
-
291
- 宣言型 CRUD 項目は UI フォームの幅を指定する `colSpan: 'auto' | 1 | 2` に対応します。`validation.message` は文字列または `() => string` を受け取り、現在の言語で表示できます。レイアウトは `CrudPage.form` で設定し、サーバーでも検証してください。
package/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  [框架首页](../../README.md) · 相关模块:[@h-ai/core](../core/README.md) · [@h-ai/crypto](../crypto/README.md) · [@h-ai/iam](../iam/README.md)
6
6
 
7
+ ## 简介
8
+
7
9
  `@h-ai/kit` 是 hai-framework 的 SvelteKit 集成模块,提供统一的请求管道与同源 endpoint 工具:
8
10
 
9
11
  - `kit.createHandle()`:会话解析、路由守卫、中间件链、可选传输加密与 Cookie 加密
@@ -12,15 +14,7 @@
12
14
 
13
15
  > 公共跨端 HTTP API contract 统一放在 `@h-ai/api-contract`,由 `@h-ai/serv` 挂载,客户端通过 `@h-ai/api-client` typed client 调用;`@h-ai/kit` 不定义也不承载业务 API contract。
14
16
 
15
- ## 安装
16
-
17
- ```bash
18
- npm install @h-ai/kit
19
- npm install svelte @sveltejs/kit zod
20
- npm install -D @sveltejs/vite-plugin-svelte vite
21
- ```
22
-
23
- ## 支持的能力
17
+ ## 核心功能清单
24
18
 
25
19
  - Handle Hook 组合(`createHandle` / `sequence`)
26
20
  - 认证/角色/权限守卫(`guard.require` / `guard.check`)
@@ -32,14 +26,24 @@ npm install -D @sveltejs/vite-plugin-svelte vite
32
26
  - A2A 协议集成:默认发现路径 `/.well-known/agent-card.json`;配置 `authenticate` 后 null/undefined 返回 401,仅未配置认证时允许匿名。API Key 参数从完整 Agent Card 的 `securitySchemes.apiKey` 读取。Hook 与显式 A2A 路由共享 JSON-RPC 解析错误和 SSE 取消清理逻辑。
33
27
  - 双构建模式(`createAdapter()`)
34
28
 
35
- ## 依赖
29
+ ## 使用入门
30
+
31
+ ### 安装
32
+
33
+ ```bash
34
+ npm install @h-ai/kit @h-ai/core sm-crypto@0.5.7
35
+ npm install svelte @sveltejs/kit zod
36
+ npm install -D @sveltejs/vite-plugin-svelte vite
37
+ ```
38
+
39
+ ### 依赖
36
40
 
37
41
  - `@h-ai/iam` — 身份认证与授权(A2A 认证),可选;使用 A2A 功能时需在 kit 使用前初始化
38
42
  - `@h-ai/crypto` — 加密(传输加密 / Cookie 加密),可选;启用加密时需在 kit 使用前初始化
39
43
 
40
- ## 快速开始
44
+ ### 快速开始
41
45
 
42
- ### 项目配置
46
+ #### 项目配置
43
47
 
44
48
  **svelte.config.js**:
45
49
 
@@ -70,11 +74,13 @@ import { defineConfig } from 'vite'
70
74
  export default defineConfig({
71
75
  plugins: [sveltekit(), tailwindcss()],
72
76
  optimizeDeps: { exclude: ['bits-ui'] },
73
- ssr: { noExternal: [/@h-ai\//] },
77
+ ssr: { noExternal: ['@h-ai/ui', '@h-ai/kit'], external: ['@h-ai/core', 'sm-crypto'] },
74
78
  })
75
79
  ```
76
80
 
77
- ### 搭建请求管道
81
+ 使用 Crypto 或依赖它的 Kit/IAM 时,应用生产依赖需包含 `sm-crypto@0.5.7`。CLI 已配好这一项;手工接入时运行 `pnpm add sm-crypto@0.5.7`。仅设置 external 不够,adapter-node 还需要这项直接依赖声明才能保留原包加载。
82
+
83
+ #### 搭建请求管道
78
84
 
79
85
  **src/hooks.server.ts**:
80
86
 
@@ -98,7 +104,7 @@ const haiHandle = kit.createHandle({
98
104
  export const handle: Handle = haiHandle
99
105
  ```
100
106
 
101
- ### API 端点
107
+ #### API 端点
102
108
 
103
109
  ```typescript
104
110
  import { kit } from '@h-ai/kit'
@@ -116,7 +122,7 @@ export const POST = kit.handler(async ({ request, locals }) => {
116
122
  })
117
123
  ```
118
124
 
119
- ### 浏览器客户端
125
+ #### 浏览器客户端
120
126
 
121
127
  `kit.client.create()` 面向 SvelteKit 同源 endpoint;Web / App / 小程序跨域访问公共 API 时,请使用 `@h-ai/api-client`。
122
128
 
@@ -139,7 +145,7 @@ const response = await apiFetch('/api/users', { method: 'GET' })
139
145
  >
140
146
  > 认证建议:同源 SvelteKit endpoint 优先使用 httpOnly Cookie,由服务端读取 Cookie 完成鉴权,浏览器端不需要把敏感 Token 写入 `localStorage`。如确需注入 Bearer Header,请传入自定义 `BrowserTokenStore`,或先用 `kit.auth.setBrowserToken()` 写入页面内存后再使用 `kit.client.create({ auth: true })`。
141
147
 
142
- ### 同源传输加密
148
+ #### 同源传输加密
143
149
 
144
150
  kit 的传输加密也统一委托 `@h-ai/crypto`:服务端通过 `crypto.transport.createServer()` 创建管理器,浏览器端通过 `kit.client.installBrowserTransport(kitConfig, { crypto })` 一行安装同源 fetch 包装。应用层只配置顶层 `crypto` 句柄。
145
151
 
@@ -203,7 +209,7 @@ transport 默认作用于同源 `/api/*` endpoint 与 SvelteKit `__data.json`
203
209
 
204
210
  安全策略默认 fail-closed:`requireEncryption: true` 时,受保护路径缺少 `X-Client-Id` 会直接返回 400;服务端 transport 管理器不可用、响应体无法加密或超过单次加密上限时返回错误,不会把业务明文响应透传给客户端。`requireEncryption: false` 仅用于迁移期灰度,不建议在生产启用。
205
211
 
206
- ### 使用 `_kit.yml` 统一 transport 配置
212
+ #### 使用 `_kit.yml` 统一 transport 配置
207
213
 
208
214
  `@h-ai/kit` 提供 `KitConfigSchema` / `resolveKitConfig()`,方便应用用同一份 `_kit.yml`
209
215
  同时驱动 `hooks.server.ts` 与浏览器端 `kit.client.installBrowserTransport()`:
@@ -236,7 +242,7 @@ export const appKitConfig = resolveKitConfig(parse(rawKitConfig) ?? {})
236
242
  如只在服务端读取配置,也可配合 `core.config.validate('kit', KitConfigSchema)` 使用。
237
243
  由于浏览器端也可能读取这份配置,`_kit.yml` 只应放公开的 server/transport 路径与开关,不要写入密钥。
238
244
 
239
- ## 配置
245
+ ### 配置
240
246
 
241
247
  `kit.createHandle()` 配置项:
242
248
 
@@ -253,7 +259,7 @@ export const appKitConfig = resolveKitConfig(parse(rawKitConfig) ?? {})
253
259
 
254
260
  配置 `crypto.encryptedCookies` 时必须同时提供 `crypto.cookieEncryptionKey`,或设置 `HAI_KIT_COOKIE_KEY`。缺少密钥会在 `createHandle()` 时立即报错;受保护 Cookie 的明文、损坏密文或解密失败都按不存在处理,加密失败也不会回退写入明文。
255
261
 
256
- ## 导出路径
262
+ ### 导出路径
257
263
 
258
264
  - `@h-ai/kit`:主入口,提供 `kit` 命名空间与类型。
259
265
  - `@h-ai/kit/client`:浏览器端客户端。
@@ -262,7 +268,7 @@ export const appKitConfig = resolveKitConfig(parse(rawKitConfig) ?? {})
262
268
  - `@h-ai/kit/a2a`:A2A 协议集成。
263
269
  - `@h-ai/kit/crypto`:加密模块集成。
264
270
 
265
- ## 配置驱动认证页面
271
+ ### 配置驱动认证页面
266
272
 
267
273
  协议支持配置中的 userAgreementMarkdown/privacyPolicyMarkdown 正文及 URL;同主题优先 Markdown,由安全渲染器在弹窗显示。
268
274
 
@@ -270,22 +276,22 @@ export const appKitConfig = resolveKitConfig(parse(rawKitConfig) ?? {})
270
276
 
271
277
  [完整 IAM 配置 / IAM configuration](../iam/README.md)
272
278
 
273
- ## 错误处理
279
+ ### 错误处理
274
280
 
275
281
  - 推荐使用 `kit.handler()` 包装 API 端点。
276
282
  - `kit.validate.body` / `kit.guard.require` 会抛出 `Response`(SvelteKit 控制流)。
277
283
  - 非控制流异常会由 `kit.handler()` 统一转换为 `500 INTERNAL_ERROR` 响应。
278
284
 
279
- ## 测试
285
+ ### CRUD fields
286
+
287
+ 声明式 CRUD 字段支持 `colSpan: 'auto' | 1 | 2`,供 UI 双列表单决定字段宽度;`validation.message` 支持字符串或 `() => string`,便于随当前语言显示校验错误。UI 布局在 `CrudPage.form` 上配置,服务端仍须独立校验。
288
+
289
+ ## 开发测试
280
290
 
281
291
  ```bash
282
292
  pnpm --filter @h-ai/kit test
283
293
  ```
284
294
 
285
- ## License
295
+ ## 许可证
286
296
 
287
297
  Apache-2.0
288
-
289
- ## CRUD fields
290
-
291
- 声明式 CRUD 字段支持 `colSpan: 'auto' | 1 | 2`,供 UI 双列表单决定字段宽度;`validation.message` 支持字符串或 `() => string`,便于随当前语言显示校验错误。UI 布局在 `CrudPage.form` 上配置,服务端仍须独立校验。
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@h-ai/kit",
3
3
  "type": "module",
4
- "version": "0.1.0-alpha.66",
4
+ "version": "0.1.0-alpha.67",
5
5
  "description": "Hai Framework SvelteKit integration module.",
6
6
  "license": "Apache-2.0",
7
7
  "exports": {
@@ -58,10 +58,10 @@
58
58
  }
59
59
  },
60
60
  "dependencies": {
61
- "@h-ai/api-contract": "0.1.0-alpha.66",
62
- "@h-ai/core": "0.1.0-alpha.66",
63
- "@h-ai/crypto": "0.1.0-alpha.66",
64
- "@h-ai/iam": "0.1.0-alpha.66",
61
+ "@h-ai/api-contract": "0.1.0-alpha.67",
62
+ "@h-ai/core": "0.1.0-alpha.67",
63
+ "@h-ai/crypto": "0.1.0-alpha.67",
64
+ "@h-ai/iam": "0.1.0-alpha.67",
65
65
  "zod": "^4.6.5"
66
66
  },
67
67
  "devDependencies": {