@h-ai/api-contract 1.0.0-beta.2 → 1.0.0-beta.21
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 +51 -35
- package/README.ja.md +50 -34
- package/README.md +50 -34
- package/dist/ai/index.d.ts +15 -14
- package/dist/ai/index.js +2 -2
- package/dist/{chunk-5UEDYQLG.js → chunk-5LBEMLDK.js} +6 -3
- package/dist/chunk-5LBEMLDK.js.map +1 -0
- package/dist/{chunk-ZM7KM6V3.js → chunk-BAEWPPKY.js} +54 -11
- package/dist/chunk-BAEWPPKY.js.map +1 -0
- package/dist/{chunk-LD5PSL4C.js → chunk-NMTOSEVA.js} +84 -18
- package/dist/chunk-NMTOSEVA.js.map +1 -0
- package/dist/chunk-PS3OHILQ.js +571 -0
- package/dist/chunk-PS3OHILQ.js.map +1 -0
- package/dist/chunk-VEUL2AEK.js +330 -0
- package/dist/chunk-VEUL2AEK.js.map +1 -0
- package/dist/chunk-XFW626TI.js +115 -0
- package/dist/chunk-XFW626TI.js.map +1 -0
- package/dist/feedback/index.d.ts +30 -29
- package/dist/feedback/index.js +2 -2
- package/dist/iam/index.d.ts +4 -3
- package/dist/iam/index.js +2 -2
- package/dist/index.d.ts +26 -25
- package/dist/index.js +12 -12
- package/dist/payment/index.d.ts +6 -5
- package/dist/payment/index.js +2 -2
- package/dist/storage/index.d.ts +2 -1
- package/dist/storage/index.js +2 -2
- package/package.json +9 -9
- package/dist/chunk-5UEDYQLG.js.map +0 -1
- package/dist/chunk-CXOK55BY.js +0 -274
- package/dist/chunk-CXOK55BY.js.map +0 -1
- package/dist/chunk-FGB5O4VA.js +0 -164
- package/dist/chunk-FGB5O4VA.js.map +0 -1
- package/dist/chunk-LD5PSL4C.js.map +0 -1
- package/dist/chunk-M4DEKGOP.js +0 -67
- package/dist/chunk-M4DEKGOP.js.map +0 -1
- package/dist/chunk-ZM7KM6V3.js.map +0 -1
package/README.en.md
CHANGED
|
@@ -4,28 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
[Framework home](../../README.en.md) · Related modules: [@h-ai/core](../core/README.en.md)
|
|
6
6
|
|
|
7
|
-
## Introduction
|
|
8
|
-
|
|
9
7
|
Public HTTP API contracts for hai-framework, with oRPC contract + Zod as the single source of truth.
|
|
10
8
|
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
- `apiContract.iam`, `apiContract.storage`, `apiContract.ai`, `apiContract.payment`: domain contracts.
|
|
14
|
-
- `apiContract.create()`: compose enabled domain contracts for an application.
|
|
15
|
-
- `apiContract.route()`: define custom HTTP route metadata for reuse in application contracts.
|
|
16
|
-
- `apiContract.pathOf()`: read the authoritative business path from a contract procedure for middleware/client reuse.
|
|
17
|
-
- `apiContract.haiResultSchema()` / `apiContract.voidResultSchema` / `apiContract.paginatedSchema()`: shared DTO schema factories.
|
|
18
|
-
- Shared DTO schemas: every HTTP output is wrapped in `HaiResult<T>`.
|
|
19
|
-
- IAM token DTOs support httpOnly cookies: `refreshToken` may be absent from the response body and managed by the server through `Set-Cookie`.
|
|
20
|
-
- IAM `auth.currentUser` returns the user profile and the current server session's `roles` / `permissions`; clients need not persist a permission snapshot to restore a session.
|
|
21
|
-
|
|
22
|
-
Payment creation inputs and outputs accept WeChat `jsapi`, Alipay `h5`, and Stripe `h5` only; WeChat requires `userId` (openid). App, Native, mini-program, and other combinations fail validation. Alipay returns `{ gateway, fields }` page parameters; creation success does not establish payment. See [Payment](../payment/README.en.md) for client handling.
|
|
23
|
-
|
|
24
|
-
User listing accepts `sortBy` (username/email/displayName/enabled/createdAt) and `sortDirection` (asc/desc) for header sorting before pagination.
|
|
25
|
-
|
|
26
|
-
## Getting started
|
|
27
|
-
|
|
28
|
-
### Quick start
|
|
9
|
+
## Quick Start
|
|
29
10
|
|
|
30
11
|
```ts
|
|
31
12
|
import { apiContract } from '@h-ai/api-contract'
|
|
@@ -45,11 +26,46 @@ import { z } from 'zod'
|
|
|
45
26
|
|
|
46
27
|
export const appContract = {
|
|
47
28
|
ping: apiContract
|
|
48
|
-
.route({
|
|
49
|
-
|
|
29
|
+
.route({
|
|
30
|
+
method: 'POST',
|
|
31
|
+
path: '/app/ping',
|
|
32
|
+
operationId: 'app.ping',
|
|
33
|
+
tags: ['app']
|
|
34
|
+
})
|
|
35
|
+
.output(apiContract.haiResultSchema(z.object({
|
|
36
|
+
pong: z.boolean()
|
|
37
|
+
}))),
|
|
50
38
|
}
|
|
51
39
|
```
|
|
52
40
|
|
|
41
|
+
## Features
|
|
42
|
+
|
|
43
|
+
### Purpose, inputs and outputs
|
|
44
|
+
|
|
45
|
+
This package declares routes and validation schemas; it sends no requests and has no init/close lifecycle. A returned Schema is a validator. Check safeParse.success when parsing: it is separate from HaiResult.success inside a business response. Serv and clients consume the input/output schemas when the application mounts the routes.
|
|
46
|
+
|
|
47
|
+
| Entry | Use case | Input (`—` means none) | Return value | Call example |
|
|
48
|
+
| ------------------------------ | -------------------------------------- | ------------------------------------------ | --------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
|
49
|
+
| `apiContract.create` | Compose application routes | `{ iam: apiContract.iam, payment: false }` | `{ iam: IamContract }` | `apiContract.create({ iam: apiContract.iam, payment: false })` |
|
|
50
|
+
| `apiContract.route` | Declare an HTTP endpoint | `{ method: "GET", path: "/status" }` | `ContractProcedureBuilder` | `apiContract.route({ method: "GET", path: "/status" })` |
|
|
51
|
+
| `apiContract.pathOf` | Read the declared business path | `apiContract.iam.auth.login` | `string: "/auth/login"` | `apiContract.pathOf(apiContract.iam.auth.login)` |
|
|
52
|
+
| `apiContract.haiResultSchema` | Validate a success or failure result | `z.string()` | `ZodSchema<HaiResult<string>>` | `apiContract.haiResultSchema(z.string())` |
|
|
53
|
+
| `apiContract.voidResultSchema` | Validate results without business data | `{ success: true, data: undefined }` | `ZodSchema<HaiResult<void>>` | `apiContract.voidResultSchema.safeParse({ success: true, data: undefined })` |
|
|
54
|
+
| `apiContract.paginatedSchema` | Validate a page of items | `z.object({ id: z.string() })` | `ZodSchema<{ items: { id: string }[], total: number, page: number, pageSize: number }>` | `apiContract.paginatedSchema(z.object({ id: z.string() }))` |
|
|
55
|
+
| `apiContract.iam` | Identity routes | `—` | `iam contract router` | `apiContract.create({ iam: apiContract.iam })` |
|
|
56
|
+
| `apiContract.storage` | Storage routes | `—` | `storage contract router` | `apiContract.create({ storage: apiContract.storage })` |
|
|
57
|
+
| `apiContract.ai` | AI routes | `—` | `ai contract router` | `apiContract.create({ ai: apiContract.ai })` |
|
|
58
|
+
| `apiContract.payment` | Payment routes | `—` | `payment contract router` | `apiContract.create({ payment: apiContract.payment })` |
|
|
59
|
+
| `apiContract.feedback` | Feedback routes | `—` | `feedback contract router` | `apiContract.create({ feedback: apiContract.feedback })` |
|
|
60
|
+
|
|
61
|
+
- Shared DTO schemas: every HTTP output is wrapped in `HaiResult<T>`.
|
|
62
|
+
- IAM token DTOs support httpOnly cookies: `refreshToken` may be absent from the response body and managed by the server through `Set-Cookie`.
|
|
63
|
+
- IAM `auth.currentUser` returns the user profile and the current server session's `roles` / `permissions`; clients need not persist a permission snapshot to restore a session.
|
|
64
|
+
|
|
65
|
+
Payment creation inputs and outputs accept WeChat `jsapi`, Alipay `h5`, and Stripe `h5` only; WeChat requires `userId` (openid). App, Native, mini-program, and other combinations fail validation. Alipay returns `{ gateway, fields }` page parameters; creation success does not establish payment. See [Payment](../payment/README.en.md) for client handling.
|
|
66
|
+
|
|
67
|
+
User listing accepts `sortBy` (username/email/displayName/enabled/createdAt) and `sortDirection` (asc/desc) for header sorting before pagination.
|
|
68
|
+
|
|
53
69
|
### API contracts
|
|
54
70
|
|
|
55
71
|
For standalone contract declaration builds, this package re-exports the upstream public types `ContractProcedureBuilderWithInputOutput`, `ContractProcedureBuilderWithOutput`, and `Schema`, preserving inference for custom routes. Import explicit types from `@h-ai/api-contract` with `import type`; do not reference internal dependency installation paths.
|
|
@@ -103,10 +119,6 @@ Batch deletion via `storage.files.deleteMany` returns `{ deletedKeys, failures:
|
|
|
103
119
|
|
|
104
120
|
Write each business path directly in its `*-contract.ts` file. Inline output schemas used only once in `.output(...)`; schemas reused within the same contract file may be private constants, but must not be exported from schemas.
|
|
105
121
|
|
|
106
|
-
### Configuration
|
|
107
|
-
|
|
108
|
-
This package has no runtime configuration and does not read environment variables.
|
|
109
|
-
|
|
110
122
|
### Configuration driven authentication
|
|
111
123
|
|
|
112
124
|
Password login submits only `identifier` and `password`; `AuthPanel` maps the `LoginForm` field `username` to `identifier`. Server settings `session.maxAge` / `session.refreshTokenMaxAge` control session lifetimes. The login form has no per-login persistent-session option.
|
|
@@ -117,15 +129,11 @@ IAM adds GET /auth/config and POST /auth/login/ldap, /auth/password-reset/reques
|
|
|
117
129
|
|
|
118
130
|
[完整 IAM 配置 / IAM configuration](../iam/README.en.md)
|
|
119
131
|
|
|
120
|
-
###
|
|
121
|
-
|
|
122
|
-
Contracts describe input and output structures only. Procedures express business errors with `HaiResult<T>`, so clients need not catch business exceptions.
|
|
123
|
-
|
|
124
|
-
## Input limits and HTTP capabilities
|
|
132
|
+
### Input limits and HTTP capabilities
|
|
125
133
|
|
|
126
134
|
Object keys are limited to 1024 UTF-8 bytes and reject absolute paths, backslashes, control characters and dot segments. Each public HTTP batch delete accepts 1–1000 entries. `@h-ai/storage/schemas` exposes the shared browser-safe rules. Presign expiry is an integer from 1 to 604800 seconds (Node default 3600, HTTP default 900). Upload signing accepts only key/contentType/expiresIn; contentLength/maxSize/metadata/checksum are unsupported. Invalid input returns HTTP 400 and the typed client maps it to VALIDATION_FAILED. FileUpload limits guide file selection; applications must validate actual objects on the server. Node streaming/checksum/conditional-write options have no default HTTP endpoints. See the [capability and authorization matrix (Chinese)](../storage/README.md#存储输入约束与跨端能力).
|
|
127
135
|
|
|
128
|
-
|
|
136
|
+
### Feedback domain contract
|
|
129
137
|
|
|
130
138
|
`FeedbackJob.type` and `FeedbackRetryInput.target` support independent `webhook` jobs. Details expose status, attempts and safe error codes in jobs. Business collectors and callback settings belong to trusted server initialization, not HTTP input. Read text and ZIP/GZIP through existing APIs; see [feedback](../feedback/README.en.md).
|
|
131
139
|
|
|
@@ -141,17 +149,25 @@ const contract = apiContract.create({ feedback: apiContract.feedback })
|
|
|
141
149
|
const path = apiContract.pathOf(contract.feedback.reports.submit)
|
|
142
150
|
```
|
|
143
151
|
|
|
144
|
-
|
|
152
|
+
### Optional interactive challenges
|
|
145
153
|
|
|
146
154
|
IamCreateCaptchaInputSchema/IamCaptchaChallengeSchema define POST /auth/captcha purposes and public challenges. Interactive inputs accept optional captcha up to4096 characters; public configuration exposes only enabled, defaulting false. Schemas validate structure; IAM enforces expiry, purpose and one-use consumption server-side.
|
|
147
155
|
|
|
148
156
|
See policy, defaults and recovery boundaries in [IAM](../iam/README.en.md).
|
|
149
157
|
|
|
150
|
-
|
|
158
|
+
### Page exit session policy
|
|
151
159
|
|
|
152
160
|
`session.endOnPageHide` defaults to `false`. Hosts call `actions.bindPageExit({ enabled: config.session.endOnPageHide })` and invoke its returned cleanup on unmount; standard admin/H5/fullstack templates already bind it. A non-BFCache `pagehide` (including reload and full document navigation) makes a best effort POST to `/auth/session/close`, revoking the held access and related refresh through the existing CSRF/encrypted transport with `keepalive` and no automatic refresh. This response does not clear cookies/local credentials, avoiding a late old response overwriting a new login. Explicit logout still revokes and clears current credentials normally. Browsers may omit page exit requests; configure server `idleTimeout`/`absoluteTimeout` as appropriate. Immediate revocation on browser close is not guaranteed.
|
|
153
161
|
|
|
154
|
-
##
|
|
162
|
+
## Configuration
|
|
163
|
+
|
|
164
|
+
This package has no runtime configuration and does not read environment variables.
|
|
165
|
+
|
|
166
|
+
## Error Handling
|
|
167
|
+
|
|
168
|
+
Contracts describe input and output structures; procedures express business errors with `HaiResult<T>`. Direct Zod `parse()` calls throw on invalid input. For external input, use `safeParse()` and check its `success`, separately from `HaiResult.success` inside a business response.
|
|
169
|
+
|
|
170
|
+
## Development
|
|
155
171
|
|
|
156
172
|
```bash
|
|
157
173
|
pnpm --filter @h-ai/api-contract test
|
package/README.ja.md
CHANGED
|
@@ -4,28 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
[フレームワークのホーム](../../README.ja.md) · 関連モジュール:[@h-ai/core](../core/README.ja.md)
|
|
6
6
|
|
|
7
|
-
## 概要
|
|
8
|
-
|
|
9
7
|
hai-framework の公開 HTTP API 契約パッケージ。oRPC contract + Zod を唯一の定義元として使用します。
|
|
10
8
|
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
- `apiContract.iam`、`apiContract.storage`、`apiContract.ai`、`apiContract.payment`:ドメイン単位の contract。
|
|
14
|
-
- `apiContract.create()`:アプリケーションに必要なドメインの contract を組み合わせる。
|
|
15
|
-
- `apiContract.route()`:アプリケーションの contract で再利用する独自 HTTP ルートのメタデータを定義。
|
|
16
|
-
- `apiContract.pathOf()`:contract procedure から業務パスを取得し、middleware/client で再利用。
|
|
17
|
-
- `apiContract.haiResultSchema()` / `apiContract.voidResultSchema` / `apiContract.paginatedSchema()`:共通 DTO Schema のファクトリー。
|
|
18
|
-
- 共通 DTO Schema:すべての HTTP 出力を `HaiResult<T>` でラップ。
|
|
19
|
-
- IAM Token DTO は httpOnly cookie に対応。レスポンス本文に `refreshToken` が含まれない場合は、サーバーが `Set-Cookie` で管理します。
|
|
20
|
-
- IAM の `auth.currentUser` はユーザー情報と現在のサーバーセッションの `roles` / `permissions` を返します。セッション復元のためにクライアントが権限のスナップショットを永続化する必要はありません。
|
|
21
|
-
|
|
22
|
-
支払い作成の入出力は WeChat `jsapi`・Alipay `h5`・Stripe `h5` のみ受け付け、WeChat は `userId`(openid)が必須です。App・Native・ミニプログラムなどは検証で拒否します。Alipay は `{ gateway, fields }` のページパラメーターを返し、作成成功は支払い完了を意味しません。クライアント処理は [Payment](../payment/README.ja.md) を参照してください。
|
|
23
|
-
|
|
24
|
-
ユーザー一覧は `sortBy`(username/email/displayName/enabled/createdAt)と `sortDirection`(asc/desc)でページ分割前に並べ替えます。
|
|
25
|
-
|
|
26
|
-
## 使い始める
|
|
27
|
-
|
|
28
|
-
### クイックスタート
|
|
9
|
+
## クイックスタート
|
|
29
10
|
|
|
30
11
|
```ts
|
|
31
12
|
import { apiContract } from '@h-ai/api-contract'
|
|
@@ -45,11 +26,46 @@ import { z } from 'zod'
|
|
|
45
26
|
|
|
46
27
|
export const appContract = {
|
|
47
28
|
ping: apiContract
|
|
48
|
-
.route({
|
|
49
|
-
|
|
29
|
+
.route({
|
|
30
|
+
method: 'POST',
|
|
31
|
+
path: '/app/ping',
|
|
32
|
+
operationId: 'app.ping',
|
|
33
|
+
tags: ['app']
|
|
34
|
+
})
|
|
35
|
+
.output(apiContract.haiResultSchema(z.object({
|
|
36
|
+
pong: z.boolean()
|
|
37
|
+
}))),
|
|
50
38
|
}
|
|
51
39
|
```
|
|
52
40
|
|
|
41
|
+
## 機能
|
|
42
|
+
|
|
43
|
+
### 用途・入力・出力
|
|
44
|
+
|
|
45
|
+
このパッケージはルートと検証構造を定義し、通信や init/close は行いません。戻り値の Schema は検証器です。safeParse の success と、業務応答内の HaiResult.success は別の結果なので区別してください。入力・出力 Schema はアプリが Serv やクライアントに組み込む際に使われます。
|
|
46
|
+
|
|
47
|
+
| 入口 | 使用場面 | 入力(`—` は引数なし) | 戻り値 | 呼出例 |
|
|
48
|
+
| ------------------------------ | ------------------------------ | ------------------------------------------ | --------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
|
49
|
+
| `apiContract.create` | アプリの契約を組み合わせる | `{ iam: apiContract.iam, payment: false }` | `{ iam: IamContract }` | `apiContract.create({ iam: apiContract.iam, payment: false })` |
|
|
50
|
+
| `apiContract.route` | HTTP エンドポイントを定義する | `{ method: "GET", path: "/status" }` | `ContractProcedureBuilder` | `apiContract.route({ method: "GET", path: "/status" })` |
|
|
51
|
+
| `apiContract.pathOf` | 定義したパスを取得する | `apiContract.iam.auth.login` | `string: "/auth/login"` | `apiContract.pathOf(apiContract.iam.auth.login)` |
|
|
52
|
+
| `apiContract.haiResultSchema` | 成功・失敗の結果を検証する | `z.string()` | `ZodSchema<HaiResult<string>>` | `apiContract.haiResultSchema(z.string())` |
|
|
53
|
+
| `apiContract.voidResultSchema` | データを返さない結果を検証する | `{ success: true, data: undefined }` | `ZodSchema<HaiResult<void>>` | `apiContract.voidResultSchema.safeParse({ success: true, data: undefined })` |
|
|
54
|
+
| `apiContract.paginatedSchema` | ページ付き一覧を検証する | `z.object({ id: z.string() })` | `ZodSchema<{ items: { id: string }[], total: number, page: number, pageSize: number }>` | `apiContract.paginatedSchema(z.object({ id: z.string() }))` |
|
|
55
|
+
| `apiContract.iam` | 認証・アカウントの契約 | `—` | `iam contract router` | `apiContract.create({ iam: apiContract.iam })` |
|
|
56
|
+
| `apiContract.storage` | ファイルの契約 | `—` | `storage contract router` | `apiContract.create({ storage: apiContract.storage })` |
|
|
57
|
+
| `apiContract.ai` | AI の契約 | `—` | `ai contract router` | `apiContract.create({ ai: apiContract.ai })` |
|
|
58
|
+
| `apiContract.payment` | 決済の契約 | `—` | `payment contract router` | `apiContract.create({ payment: apiContract.payment })` |
|
|
59
|
+
| `apiContract.feedback` | フィードバックの契約 | `—` | `feedback contract router` | `apiContract.create({ feedback: apiContract.feedback })` |
|
|
60
|
+
|
|
61
|
+
- 共通 DTO Schema:すべての HTTP 出力を `HaiResult<T>` でラップ。
|
|
62
|
+
- IAM Token DTO は httpOnly cookie に対応。レスポンス本文に `refreshToken` が含まれない場合は、サーバーが `Set-Cookie` で管理します。
|
|
63
|
+
- IAM の `auth.currentUser` はユーザー情報と現在のサーバーセッションの `roles` / `permissions` を返します。セッション復元のためにクライアントが権限のスナップショットを永続化する必要はありません。
|
|
64
|
+
|
|
65
|
+
支払い作成の入出力は WeChat `jsapi`・Alipay `h5`・Stripe `h5` のみ受け付け、WeChat は `userId`(openid)が必須です。App・Native・ミニプログラムなどは検証で拒否します。Alipay は `{ gateway, fields }` のページパラメーターを返し、作成成功は支払い完了を意味しません。クライアント処理は [Payment](../payment/README.ja.md) を参照してください。
|
|
66
|
+
|
|
67
|
+
ユーザー一覧は `sortBy`(username/email/displayName/enabled/createdAt)と `sortDirection`(asc/desc)でページ分割前に並べ替えます。
|
|
68
|
+
|
|
53
69
|
### API 契約
|
|
54
70
|
|
|
55
71
|
独立した contract パッケージの宣言ファイルを生成するため、上流の公開型 `ContractProcedureBuilderWithInputOutput`、`ContractProcedureBuilderWithOutput`、`Schema` を本パッケージから再エクスポートしています。独自ルートの入出力の型推論を維持し、明示的な型が必要な場合は `@h-ai/api-contract` から `import type` で取得してください。依存パッケージの内部インストールパスは参照しないでください。
|
|
@@ -103,10 +119,6 @@ const app = serv.createApp({
|
|
|
103
119
|
|
|
104
120
|
業務 path は対応する `*-contract.ts` に直接記述します。一度しか使わない出力 Schema は `.output(...)` にインラインで定義します。同じ contract ファイル内で再利用する場合は非公開の定数にできますが、schemas からエクスポートしてはいけません。
|
|
105
121
|
|
|
106
|
-
### 設定
|
|
107
|
-
|
|
108
|
-
このパッケージには実行時設定がなく、環境変数も読み込みません。
|
|
109
|
-
|
|
110
122
|
### 設定による認証画面
|
|
111
123
|
|
|
112
124
|
パスワードログインの送信項目は `identifier` と `password` のみです。`AuthPanel` は `LoginForm` の `username` を `identifier` に変換します。有効期間はサーバーの `session.maxAge` / `session.refreshTokenMaxAge` で設定し、フォームにログインごとの永続セッション選択肢はありません。
|
|
@@ -117,15 +129,11 @@ IAM に公開設定、LDAP、復旧要求と確定の標準 route を追加し
|
|
|
117
129
|
|
|
118
130
|
[完整 IAM 配置 / IAM configuration](../iam/README.ja.md)
|
|
119
131
|
|
|
120
|
-
###
|
|
121
|
-
|
|
122
|
-
Contract は入出力構造のみを定義します。業務エラーは procedure が返す `HaiResult<T>` で表し、クライアント側で業務例外を捕捉する必要はありません。
|
|
123
|
-
|
|
124
|
-
## 入力制約と HTTP 機能
|
|
132
|
+
### 入力制約と HTTP 機能
|
|
125
133
|
|
|
126
134
|
キーは UTF-8 で最大 1024 バイトで、絶対パス、バックスラッシュ、制御文字、ドットセグメントを拒否します。公開 HTTP 一括削除は一度に 1–1000 件です。共通規則はブラウザー対応の `@h-ai/storage/schemas` から参照できます。署名有効期限は整数 1–604800 秒(Node 既定 3600、HTTP 既定 900)。アップロード署名の入力は key/contentType/expiresIn のみで、contentLength/maxSize/metadata/checksum は未対応です。不正入力は HTTP 400、typed client では VALIDATION_FAILED です。FileUpload の制限は選択時の補助であり、実際のオブジェクトはサーバーで検証してください。Node のストリーム/checksum/条件付き書き込みには既定の HTTP エンドポイントがありません。[機能と認可の対応表(中国語)](../storage/README.md#存储输入约束与跨端能力)を参照してください。
|
|
127
135
|
|
|
128
|
-
|
|
136
|
+
### フィードバック領域の契約
|
|
129
137
|
|
|
130
138
|
FeedbackJob.type と FeedbackRetryInput.target は独立した webhook タスクに対応し、詳細 jobs に状態・試行回数・安全なエラーコードを含みます。業務収集関数と宛先は信頼するサーバーで設定し、HTTP 入力では指定できません。本文と ZIP/GZIP は既存 API で取得します。[feedback](../feedback/README.ja.md) を参照してください。
|
|
131
139
|
|
|
@@ -141,16 +149,24 @@ const contract = apiContract.create({ feedback: apiContract.feedback })
|
|
|
141
149
|
const path = apiContract.pathOf(contract.feedback.reports.submit)
|
|
142
150
|
```
|
|
143
151
|
|
|
144
|
-
|
|
152
|
+
### 任意の対話チャレンジ
|
|
145
153
|
|
|
146
154
|
IamCreateCaptchaInputSchema/IamCaptchaChallengeSchema は POST /auth/captcha の用途と公開チャレンジを定義します。対話入力の captcha は任意で最大4096文字、公開設定は既定 false の enabled のみです。Schema は構造を検証し、期限・用途・単用消費はサーバー IAM が実行します。
|
|
147
155
|
|
|
148
156
|
方針・既定値・復旧範囲は次を参照: [IAM](../iam/README.ja.md)。
|
|
149
157
|
|
|
150
|
-
|
|
158
|
+
### ページ離脱時のセッション方針
|
|
151
159
|
|
|
152
160
|
`session.endOnPageHide` の既定値は `false` です。ホストは `actions.bindPageExit({ enabled: config.session.endOnPageHide })` を呼び、破棄時に戻り値の解除関数を実行します。標準 admin/H5/fullstack テンプレートは接続済みです。BFCache 以外の `pagehide`(再読み込み、文書全体の移動を含む)で POST `/auth/session/close` を最善努力で送信し、保持する access と関連 refresh を失効します。既存の CSRF/暗号化転送を使用し、`keepalive` を付け、自動更新しません。古い応答が新しいログインを上書きしないよう Cookie/ローカル資格情報を消去しません。明示的ログアウトは通常どおり失効と消去を行います。ブラウザーが離脱要求を送らない場合もあるため、業務に応じてサーバーの `idleTimeout`/`absoluteTimeout` を併用してください。閉じた瞬間の失効は保証できません。
|
|
153
161
|
|
|
162
|
+
## 設定
|
|
163
|
+
|
|
164
|
+
このパッケージには実行時設定がなく、環境変数も読み込みません。
|
|
165
|
+
|
|
166
|
+
## エラー処理
|
|
167
|
+
|
|
168
|
+
Contract は入出力構造を定義し、業務エラーは procedure が返す `HaiResult<T>` で表します。Zod の `parse()` を直接呼ぶと不正な入力で検証例外が発生します。外部入力には `safeParse()` を使い、その `success` と業務応答内の `HaiResult.success` を別々に確認してください。
|
|
169
|
+
|
|
154
170
|
## 開発とテスト
|
|
155
171
|
|
|
156
172
|
```bash
|
package/README.md
CHANGED
|
@@ -4,28 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
[框架首页](../../README.md) · 相关模块:[@h-ai/core](../core/README.md)
|
|
6
6
|
|
|
7
|
-
## 简介
|
|
8
|
-
|
|
9
7
|
hai-framework 的公共 HTTP API 契约包,用 oRPC contract 和 Zod 让前后端共用接口路径、输入输出校验与类型。
|
|
10
8
|
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
- `apiContract.iam`、`apiContract.storage`、`apiContract.ai`、`apiContract.payment`:领域级 contract。
|
|
14
|
-
- `apiContract.create()`:按应用场景组合启用的领域 contract。
|
|
15
|
-
- `apiContract.route()`:定义自定义 HTTP 路由元数据,供应用级 contract 复用。
|
|
16
|
-
- `apiContract.pathOf()`:从 contract procedure 读取唯一业务路径,供 middleware/client 复用。
|
|
17
|
-
- `apiContract.haiResultSchema()` / `apiContract.voidResultSchema` / `apiContract.paginatedSchema()`:公共 DTO Schema 工厂。
|
|
18
|
-
- 公共 DTO Schema:所有 HTTP 输出统一包装为 `HaiResult<T>`。
|
|
19
|
-
- IAM token DTO 兼容 httpOnly cookie 模式:响应体中 `refreshToken` 可能不存在,由服务端 `Set-Cookie` 管理。
|
|
20
|
-
- IAM `auth.currentUser` 返回用户资料以及服务端当前会话的 `roles` / `permissions`,客户端恢复会话时无需持久化权限快照。
|
|
21
|
-
|
|
22
|
-
支付创建输入和输出仅接受微信 `jsapi`、支付宝 `h5`、Stripe `h5`;微信输入必填 `userId`(openid)。App、Native、小程序与其它组合会在输入校验时失败。支付宝输出是 `{ gateway, fields }` 页面参数,创建成功不代表支付完成;客户端处理见 [Payment](../payment/README.md)。
|
|
23
|
-
|
|
24
|
-
用户列表支持 `sortBy`(username/email/displayName/enabled/createdAt)和 `sortDirection`(asc/desc),供列头排序在分页前执行。
|
|
25
|
-
|
|
26
|
-
## 使用入门
|
|
27
|
-
|
|
28
|
-
### 快速开始
|
|
9
|
+
## 快速开始
|
|
29
10
|
|
|
30
11
|
```ts
|
|
31
12
|
import { apiContract } from '@h-ai/api-contract'
|
|
@@ -45,11 +26,46 @@ import { z } from 'zod'
|
|
|
45
26
|
|
|
46
27
|
export const appContract = {
|
|
47
28
|
ping: apiContract
|
|
48
|
-
.route({
|
|
49
|
-
|
|
29
|
+
.route({
|
|
30
|
+
method: 'POST',
|
|
31
|
+
path: '/app/ping',
|
|
32
|
+
operationId: 'app.ping',
|
|
33
|
+
tags: ['app']
|
|
34
|
+
})
|
|
35
|
+
.output(apiContract.haiResultSchema(z.object({
|
|
36
|
+
pong: z.boolean()
|
|
37
|
+
}))),
|
|
50
38
|
}
|
|
51
39
|
```
|
|
52
40
|
|
|
41
|
+
## 功能
|
|
42
|
+
|
|
43
|
+
### 用途、输入与输出
|
|
44
|
+
|
|
45
|
+
本包声明接口和校验结构,不发送请求,也没有 init/close。表中 Schema 是校验器本身;调用 safeParse 后检查其 success。业务响应中的 HaiResult.success 与校验器的 success 属于不同层,不能混用。路由的输入/输出 Schema 由应用挂载到 Serv 或客户端后实际使用。
|
|
46
|
+
|
|
47
|
+
| 入口 | 使用场景 | 输入(`—` 表示无参数) | 返回值 | 调用示例 |
|
|
48
|
+
| ------------------------------ | -------------------- | ------------------------------------------ | --------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
|
49
|
+
| `apiContract.create` | 组合应用接口 | `{ iam: apiContract.iam, payment: false }` | `{ iam: IamContract }` | `apiContract.create({ iam: apiContract.iam, payment: false })` |
|
|
50
|
+
| `apiContract.route` | 声明 HTTP 接口 | `{ method: "GET", path: "/status" }` | `ContractProcedureBuilder` | `apiContract.route({ method: "GET", path: "/status" })` |
|
|
51
|
+
| `apiContract.pathOf` | 取唯一业务路径 | `apiContract.iam.auth.login` | `string: "/auth/login"` | `apiContract.pathOf(apiContract.iam.auth.login)` |
|
|
52
|
+
| `apiContract.haiResultSchema` | 校验成功或失败结果 | `z.string()` | `ZodSchema<HaiResult<string>>` | `apiContract.haiResultSchema(z.string())` |
|
|
53
|
+
| `apiContract.voidResultSchema` | 校验无业务数据的结果 | `{ success: true, data: undefined }` | `ZodSchema<HaiResult<void>>` | `apiContract.voidResultSchema.safeParse({ success: true, data: undefined })` |
|
|
54
|
+
| `apiContract.paginatedSchema` | 校验分页列表 | `z.object({ id: z.string() })` | `ZodSchema<{ items: { id: string }[], total: number, page: number, pageSize: number }>` | `apiContract.paginatedSchema(z.object({ id: z.string() }))` |
|
|
55
|
+
| `apiContract.iam` | 认证与账号接口 | `—` | `iam contract router` | `apiContract.create({ iam: apiContract.iam })` |
|
|
56
|
+
| `apiContract.storage` | 文件接口 | `—` | `storage contract router` | `apiContract.create({ storage: apiContract.storage })` |
|
|
57
|
+
| `apiContract.ai` | AI 接口 | `—` | `ai contract router` | `apiContract.create({ ai: apiContract.ai })` |
|
|
58
|
+
| `apiContract.payment` | 支付接口 | `—` | `payment contract router` | `apiContract.create({ payment: apiContract.payment })` |
|
|
59
|
+
| `apiContract.feedback` | 反馈接口 | `—` | `feedback contract router` | `apiContract.create({ feedback: apiContract.feedback })` |
|
|
60
|
+
|
|
61
|
+
- 公共 DTO Schema:所有 HTTP 输出统一包装为 `HaiResult<T>`。
|
|
62
|
+
- IAM token DTO 兼容 httpOnly cookie 模式:响应体中 `refreshToken` 可能不存在,由服务端 `Set-Cookie` 管理。
|
|
63
|
+
- IAM `auth.currentUser` 返回用户资料以及服务端当前会话的 `roles` / `permissions`,客户端恢复会话时无需持久化权限快照。
|
|
64
|
+
|
|
65
|
+
支付创建输入和输出仅接受微信 `jsapi`、支付宝 `h5`、Stripe `h5`;微信输入必填 `userId`(openid)。App、Native、小程序与其它组合会在输入校验时失败。支付宝输出是 `{ gateway, fields }` 页面参数,创建成功不代表支付完成;客户端处理见 [Payment](../payment/README.md)。
|
|
66
|
+
|
|
67
|
+
用户列表支持 `sortBy`(username/email/displayName/enabled/createdAt)和 `sortDirection`(asc/desc),供列头排序在分页前执行。
|
|
68
|
+
|
|
53
69
|
### API 契约
|
|
54
70
|
|
|
55
71
|
独立 contract 包构建声明文件时,`ContractProcedureBuilderWithInputOutput`、`ContractProcedureBuilderWithOutput` 和 `Schema` 由本包按上游真实类型公开转出,保持自定义路由的输入输出推导。需要显式类型时从 `@h-ai/api-contract` 使用 `import type`,不要引用依赖的内部安装路径。
|
|
@@ -103,10 +119,6 @@ const app = serv.createApp({
|
|
|
103
119
|
|
|
104
120
|
业务 path 必须直接写在对应 `*-contract.ts`。只使用一次的输出 Schema 直接内联到 `.output(...)`;同一 contract 文件内重复使用时可保留私有常量,但不得从 schemas 导出。
|
|
105
121
|
|
|
106
|
-
### 配置
|
|
107
|
-
|
|
108
|
-
本包无运行时配置,不读取环境变量。
|
|
109
|
-
|
|
110
122
|
### 配置驱动认证页面
|
|
111
123
|
|
|
112
124
|
密码登录只提交 `identifier` 和 `password`;`AuthPanel` 将 `LoginForm` 的 `username` 映射为 `identifier`。会话有效期由服务端 `session.maxAge` / `session.refreshTokenMaxAge` 配置决定,登录表单不提供按次登录的持久会话选项。
|
|
@@ -117,15 +129,11 @@ const app = serv.createApp({
|
|
|
117
129
|
|
|
118
130
|
[完整 IAM 配置 / IAM configuration](../iam/README.md)
|
|
119
131
|
|
|
120
|
-
###
|
|
121
|
-
|
|
122
|
-
Contract 只描述输入输出结构。业务错误由 procedure 返回 `HaiResult<T>` 表达,客户端不需要捕获业务异常。
|
|
123
|
-
|
|
124
|
-
## 输入约束与 HTTP 能力
|
|
132
|
+
### 输入约束与 HTTP 能力
|
|
125
133
|
|
|
126
134
|
存储 key 按 UTF-8 最多 1024 字节,并拒绝绝对路径、反斜线、控制字符及点路径段;公开 HTTP 批量删除每次 1–1000 项。`@h-ai/storage/schemas` 提供浏览器安全的共同规则。预签名有效期为整数 1–604800 秒(Node 默认 3600,HTTP 默认 900);HTTP 上传仅接受 key/contentType/expiresIn,不支持 contentLength/maxSize/metadata/checksum。无效输入返回 HTTP 400,typed client 映射 VALIDATION_FAILED。FileUpload 的大小/类型限制仅为前端体验,实际对象须由应用服务端复核。Node 流式读写/checksum/条件写等没有默认 HTTP 端点。完整映射与授权边界见 [存储 API 能力](../storage/README.md#存储输入约束与跨端能力)。
|
|
127
135
|
|
|
128
|
-
|
|
136
|
+
### 反馈领域契约
|
|
129
137
|
|
|
130
138
|
`FeedbackJob.type` 与 `FeedbackRetryInput.target` 支持独立 `webhook` 任务;状态、尝试次数和安全错误码见详情 jobs。业务采集函数与回调配置仅在可信服务端注册,不接受 HTTP 输入指定。正文与 ZIP/GZIP 通过既有证据/附件接口取得,接入见 [feedback](../feedback/README.md)。
|
|
131
139
|
|
|
@@ -141,16 +149,24 @@ const contract = apiContract.create({ feedback: apiContract.feedback })
|
|
|
141
149
|
const path = apiContract.pathOf(contract.feedback.reports.submit)
|
|
142
150
|
```
|
|
143
151
|
|
|
144
|
-
|
|
152
|
+
### 可选交互挑战
|
|
145
153
|
|
|
146
154
|
IamCreateCaptchaInputSchema / IamCaptchaChallengeSchema 定义 POST /auth/captcha 的用途与可公开挑战,交互鉴别输入允许最多4096字符的可选 captcha。IamPublicConfigSchema.captcha 仅含 enabled,缺省关闭。Schema 校验结构,证明有效期、用途和单次消费由服务端 IAM 执行。
|
|
147
155
|
|
|
148
156
|
策略、默认值和恢复边界见 [IAM](../iam/README.md)。
|
|
149
157
|
|
|
150
|
-
|
|
158
|
+
### 页面离开会话策略
|
|
151
159
|
|
|
152
160
|
`session.endOnPageHide` 默认 `false`。启用后宿主调用 `actions.bindPageExit({ enabled: config.session.endOnPageHide })` 并在卸载时调用返回的清理函数;标准 admin/H5/fullstack 模板已经接入。非 BFCache 的 `pagehide`(也包括刷新、整页导航)通过 POST `/auth/session/close` 尽力撤销当前 access 及关联 refresh,沿用 CSRF/传输加密,使用 `keepalive` 且不自动刷新会话。该响应不清 Cookie/本地凭据,避免旧响应覆盖下一次登录。显式退出仍使用正常 logout,可靠撤销并清理当前凭据。浏览器可能不发送页面离开请求,因此必须按业务配合服务端 `idleTimeout`/`absoluteTimeout`;不能据此保证关闭即撤销。
|
|
153
161
|
|
|
162
|
+
## 配置
|
|
163
|
+
|
|
164
|
+
本包无运行时配置,不读取环境变量。
|
|
165
|
+
|
|
166
|
+
## 错误处理
|
|
167
|
+
|
|
168
|
+
Contract 只描述输入输出结构,业务错误由 procedure 返回 `HaiResult<T>` 表达。直接调用 Zod `parse()` 会在输入无效时抛校验异常;读取外部输入时可用 `safeParse()` 并检查其 `success`。这个校验结果与业务响应里的 `HaiResult.success` 分别处理。
|
|
169
|
+
|
|
154
170
|
## 开发测试
|
|
155
171
|
|
|
156
172
|
```bash
|
package/dist/ai/index.d.ts
CHANGED
|
@@ -260,9 +260,9 @@ declare const aiContract: {
|
|
|
260
260
|
}, zod_v4_core.$strict>>>;
|
|
261
261
|
}, zod_v4_core.$strip>;
|
|
262
262
|
finish_reason: zod.ZodEnum<{
|
|
263
|
-
length: "length";
|
|
264
263
|
tool_calls: "tool_calls";
|
|
265
264
|
stop: "stop";
|
|
265
|
+
length: "length";
|
|
266
266
|
content_filter: "content_filter";
|
|
267
267
|
}>;
|
|
268
268
|
}, zod_v4_core.$strip>>;
|
|
@@ -424,11 +424,11 @@ declare const aiContract: {
|
|
|
424
424
|
query: zod.ZodString;
|
|
425
425
|
topK: zod.ZodOptional<zod.ZodNumber>;
|
|
426
426
|
types: zod.ZodOptional<zod.ZodArray<zod.ZodEnum<{
|
|
427
|
-
instruction: "instruction";
|
|
428
427
|
fact: "fact";
|
|
429
428
|
preference: "preference";
|
|
430
429
|
event: "event";
|
|
431
430
|
entity: "entity";
|
|
431
|
+
instruction: "instruction";
|
|
432
432
|
}>>>;
|
|
433
433
|
minImportance: zod.ZodOptional<zod.ZodNumber>;
|
|
434
434
|
objectId: zod.ZodOptional<zod.ZodString>;
|
|
@@ -439,11 +439,11 @@ declare const aiContract: {
|
|
|
439
439
|
id: zod.ZodString;
|
|
440
440
|
content: zod.ZodString;
|
|
441
441
|
type: zod.ZodEnum<{
|
|
442
|
-
instruction: "instruction";
|
|
443
442
|
fact: "fact";
|
|
444
443
|
preference: "preference";
|
|
445
444
|
event: "event";
|
|
446
445
|
entity: "entity";
|
|
446
|
+
instruction: "instruction";
|
|
447
447
|
}>;
|
|
448
448
|
importance: zod.ZodNumber;
|
|
449
449
|
objectId: zod.ZodOptional<zod.ZodString>;
|
|
@@ -469,11 +469,11 @@ declare const aiContract: {
|
|
|
469
469
|
}, zod_v4_core.$strip>], "success">, Record<never, never>, Record<never, never>>;
|
|
470
470
|
list: _orpc_contract.ContractProcedureBuilderWithInputOutput<zod.ZodObject<{
|
|
471
471
|
types: zod.ZodOptional<zod.ZodArray<zod.ZodEnum<{
|
|
472
|
-
instruction: "instruction";
|
|
473
472
|
fact: "fact";
|
|
474
473
|
preference: "preference";
|
|
475
474
|
event: "event";
|
|
476
475
|
entity: "entity";
|
|
476
|
+
instruction: "instruction";
|
|
477
477
|
}>>>;
|
|
478
478
|
objectId: zod.ZodOptional<zod.ZodString>;
|
|
479
479
|
offset: zod.ZodOptional<zod.ZodNumber>;
|
|
@@ -485,11 +485,11 @@ declare const aiContract: {
|
|
|
485
485
|
id: zod.ZodString;
|
|
486
486
|
content: zod.ZodString;
|
|
487
487
|
type: zod.ZodEnum<{
|
|
488
|
-
instruction: "instruction";
|
|
489
488
|
fact: "fact";
|
|
490
489
|
preference: "preference";
|
|
491
490
|
event: "event";
|
|
492
491
|
entity: "entity";
|
|
492
|
+
instruction: "instruction";
|
|
493
493
|
}>;
|
|
494
494
|
importance: zod.ZodNumber;
|
|
495
495
|
objectId: zod.ZodOptional<zod.ZodString>;
|
|
@@ -934,9 +934,9 @@ declare const AiChatCompletionChoiceSchema: z.ZodObject<{
|
|
|
934
934
|
}, z.core.$strict>>>;
|
|
935
935
|
}, z.core.$strip>;
|
|
936
936
|
finish_reason: z.ZodEnum<{
|
|
937
|
-
length: "length";
|
|
938
937
|
tool_calls: "tool_calls";
|
|
939
938
|
stop: "stop";
|
|
939
|
+
length: "length";
|
|
940
940
|
content_filter: "content_filter";
|
|
941
941
|
}>;
|
|
942
942
|
}, z.core.$strip>;
|
|
@@ -990,9 +990,9 @@ declare const AiChatCompletionDataSchema: z.ZodObject<{
|
|
|
990
990
|
}, z.core.$strict>>>;
|
|
991
991
|
}, z.core.$strip>;
|
|
992
992
|
finish_reason: z.ZodEnum<{
|
|
993
|
-
length: "length";
|
|
994
993
|
tool_calls: "tool_calls";
|
|
995
994
|
stop: "stop";
|
|
995
|
+
length: "length";
|
|
996
996
|
content_filter: "content_filter";
|
|
997
997
|
}>;
|
|
998
998
|
}, z.core.$strip>>;
|
|
@@ -1055,11 +1055,11 @@ declare const AiSendMessageDataSchema: z.ZodObject<{
|
|
|
1055
1055
|
* ```
|
|
1056
1056
|
*/
|
|
1057
1057
|
declare const AiMemoryTypeSchema: z.ZodEnum<{
|
|
1058
|
-
instruction: "instruction";
|
|
1059
1058
|
fact: "fact";
|
|
1060
1059
|
preference: "preference";
|
|
1061
1060
|
event: "event";
|
|
1062
1061
|
entity: "entity";
|
|
1062
|
+
instruction: "instruction";
|
|
1063
1063
|
}>;
|
|
1064
1064
|
/**
|
|
1065
1065
|
* 记忆条目 Schema。
|
|
@@ -1083,11 +1083,11 @@ declare const AiMemoryEntrySchema: z.ZodObject<{
|
|
|
1083
1083
|
id: z.ZodString;
|
|
1084
1084
|
content: z.ZodString;
|
|
1085
1085
|
type: z.ZodEnum<{
|
|
1086
|
-
instruction: "instruction";
|
|
1087
1086
|
fact: "fact";
|
|
1088
1087
|
preference: "preference";
|
|
1089
1088
|
event: "event";
|
|
1090
1089
|
entity: "entity";
|
|
1090
|
+
instruction: "instruction";
|
|
1091
1091
|
}>;
|
|
1092
1092
|
importance: z.ZodNumber;
|
|
1093
1093
|
objectId: z.ZodOptional<z.ZodString>;
|
|
@@ -1112,11 +1112,11 @@ declare const AiMemoryRecallInputSchema: z.ZodObject<{
|
|
|
1112
1112
|
query: z.ZodString;
|
|
1113
1113
|
topK: z.ZodOptional<z.ZodNumber>;
|
|
1114
1114
|
types: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
1115
|
-
instruction: "instruction";
|
|
1116
1115
|
fact: "fact";
|
|
1117
1116
|
preference: "preference";
|
|
1118
1117
|
event: "event";
|
|
1119
1118
|
entity: "entity";
|
|
1119
|
+
instruction: "instruction";
|
|
1120
1120
|
}>>>;
|
|
1121
1121
|
minImportance: z.ZodOptional<z.ZodNumber>;
|
|
1122
1122
|
objectId: z.ZodOptional<z.ZodString>;
|
|
@@ -1148,11 +1148,11 @@ declare const AiMemoryRecallDataSchema: z.ZodObject<{
|
|
|
1148
1148
|
id: z.ZodString;
|
|
1149
1149
|
content: z.ZodString;
|
|
1150
1150
|
type: z.ZodEnum<{
|
|
1151
|
-
instruction: "instruction";
|
|
1152
1151
|
fact: "fact";
|
|
1153
1152
|
preference: "preference";
|
|
1154
1153
|
event: "event";
|
|
1155
1154
|
entity: "entity";
|
|
1155
|
+
instruction: "instruction";
|
|
1156
1156
|
}>;
|
|
1157
1157
|
importance: z.ZodNumber;
|
|
1158
1158
|
objectId: z.ZodOptional<z.ZodString>;
|
|
@@ -1174,11 +1174,11 @@ declare const AiMemoryRecallDataSchema: z.ZodObject<{
|
|
|
1174
1174
|
*/
|
|
1175
1175
|
declare const AiMemoryListInputSchema: z.ZodObject<{
|
|
1176
1176
|
types: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
1177
|
-
instruction: "instruction";
|
|
1178
1177
|
fact: "fact";
|
|
1179
1178
|
preference: "preference";
|
|
1180
1179
|
event: "event";
|
|
1181
1180
|
entity: "entity";
|
|
1181
|
+
instruction: "instruction";
|
|
1182
1182
|
}>>>;
|
|
1183
1183
|
objectId: z.ZodOptional<z.ZodString>;
|
|
1184
1184
|
offset: z.ZodOptional<z.ZodNumber>;
|
|
@@ -1212,11 +1212,11 @@ declare const AiMemoryListDataSchema: z.ZodObject<{
|
|
|
1212
1212
|
id: z.ZodString;
|
|
1213
1213
|
content: z.ZodString;
|
|
1214
1214
|
type: z.ZodEnum<{
|
|
1215
|
-
instruction: "instruction";
|
|
1216
1215
|
fact: "fact";
|
|
1217
1216
|
preference: "preference";
|
|
1218
1217
|
event: "event";
|
|
1219
1218
|
entity: "entity";
|
|
1219
|
+
instruction: "instruction";
|
|
1220
1220
|
}>;
|
|
1221
1221
|
importance: z.ZodNumber;
|
|
1222
1222
|
objectId: z.ZodOptional<z.ZodString>;
|
|
@@ -1751,4 +1751,5 @@ type AiChatHistoryInput = z.infer<typeof AiChatHistoryInputSchema>;
|
|
|
1751
1751
|
*/
|
|
1752
1752
|
type AiChatRecord = z.infer<typeof AiChatRecordSchema>;
|
|
1753
1753
|
|
|
1754
|
-
export { AUDIO_WS_PATH, AiAssistantMessageSchema, AiChatCompletionChoiceSchema,
|
|
1754
|
+
export { AUDIO_WS_PATH, AiAssistantMessageSchema, AiChatCompletionChoiceSchema, AiChatCompletionDataSchema, AiChatCompletionInputSchema, AiChatHistoryDataSchema, AiChatHistoryInputSchema, AiChatMessageSchema, AiChatRecordSchema, AiImageContentSchema, AiMemoryEntrySchema, AiMemoryListDataSchema, AiMemoryListInputSchema, AiMemoryRecallDataSchema, AiMemoryRecallInputSchema, AiMemoryTypeSchema, AiMessageContentSchema, AiMessageRoleSchema, AiSendMessageDataSchema, AiSendMessageInputSchema, AiSessionInfoSchema, AiSessionListDataSchema, AiSessionListInputSchema, AiTextContentSchema, AiTokenUsageSchema, AiToolCallSchema, AiToolDefinitionSchema, AudioFormatSchema, AudioWsClientMessageSchema, AudioWsDoneMessageSchema, AudioWsStartMessageSchema, AudioWsTextMessageSchema, aiContract };
|
|
1755
|
+
export type { AiChatCompletionData, AiChatCompletionInput, AiChatCompletionOutput, AiChatHistoryInput, AiChatRecord, AiContract, AiMemoryListInput, AiMemoryRecallInput, AiSendMessageData, AiSendMessageInput, AiSendMessageOutput, AiSessionListInput };
|
package/dist/ai/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AUDIO_WS_PATH, AiAssistantMessageSchema, AiChatCompletionChoiceSchema, AiChatCompletionDataSchema, AiChatCompletionInputSchema, AiChatHistoryDataSchema, AiChatHistoryInputSchema, AiChatMessageSchema, AiChatRecordSchema, AiImageContentSchema, AiMemoryEntrySchema, AiMemoryListDataSchema, AiMemoryListInputSchema, AiMemoryRecallDataSchema, AiMemoryRecallInputSchema, AiMemoryTypeSchema, AiMessageContentSchema, AiMessageRoleSchema, AiSendMessageDataSchema, AiSendMessageInputSchema, AiSessionInfoSchema, AiSessionListDataSchema, AiSessionListInputSchema, AiTextContentSchema, AiTokenUsageSchema, AiToolCallSchema, AiToolDefinitionSchema, AudioFormatSchema, AudioWsClientMessageSchema, AudioWsDoneMessageSchema, AudioWsStartMessageSchema, AudioWsTextMessageSchema, aiContract } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
export { AUDIO_WS_PATH, AiAssistantMessageSchema, AiChatCompletionChoiceSchema, AiChatCompletionDataSchema, AiChatCompletionInputSchema, AiChatHistoryDataSchema, AiChatHistoryInputSchema, AiChatMessageSchema, AiChatRecordSchema, AiImageContentSchema, AiMemoryEntrySchema, AiMemoryListDataSchema, AiMemoryListInputSchema, AiMemoryRecallDataSchema, AiMemoryRecallInputSchema, AiMemoryTypeSchema, AiMessageContentSchema, AiMessageRoleSchema, AiSendMessageDataSchema, AiSendMessageInputSchema, AiSessionInfoSchema, AiSessionListDataSchema, AiSessionListInputSchema, AiTextContentSchema, AiTokenUsageSchema, AiToolCallSchema, AiToolDefinitionSchema, AudioFormatSchema, AudioWsClientMessageSchema, AudioWsDoneMessageSchema, AudioWsStartMessageSchema, AudioWsTextMessageSchema, aiContract } from '../chunk-NMTOSEVA.js';
|
|
2
|
+
import '../chunk-5LBEMLDK.js';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -3,7 +3,10 @@ import { oc } from '@orpc/contract';
|
|
|
3
3
|
|
|
4
4
|
// src/common/result-schemas.ts
|
|
5
5
|
var HaiErrorSchema = z.object({
|
|
6
|
-
code: z.union([
|
|
6
|
+
code: z.union([
|
|
7
|
+
z.string(),
|
|
8
|
+
z.number()
|
|
9
|
+
]),
|
|
7
10
|
message: z.string(),
|
|
8
11
|
traceId: z.string().max(128).optional(),
|
|
9
12
|
httpStatus: z.number().optional(),
|
|
@@ -35,5 +38,5 @@ function pathOf(procedure) {
|
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
export { HaiErrorSchema, HaiVoidResultSchema, haiResultSchema, pathOf, route };
|
|
38
|
-
//# sourceMappingURL=chunk-
|
|
39
|
-
//# sourceMappingURL=chunk-
|
|
41
|
+
//# sourceMappingURL=chunk-5LBEMLDK.js.map
|
|
42
|
+
//# sourceMappingURL=chunk-5LBEMLDK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/common/result-schemas.ts","../src/common/route.ts"],"names":[],"mappings":";;;;AA0BO,IAAM,cAAA,GAAiB,EAAE,MAAA,CAAO;AAAA,EACrC,IAAA,EAAM,EAAE,KAAA,CAAM;AAAA,IACZ,EAAE,MAAA,EAAO;AAAA,IACT,EAAE,MAAA;AAAO,GACV,CAAA;AAAA,EACD,OAAA,EAAS,EAAE,MAAA,EAAO;AAAA,EAClB,SAAS,CAAA,CAAE,MAAA,GAAS,GAAA,CAAI,GAAG,EAAE,QAAA,EAAS;AAAA,EACtC,UAAA,EAAY,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAChC,MAAA,EAAQ,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC5B,MAAA,EAAQ,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC5B,KAAA,EAAO,CAAA,CAAE,OAAA,EAAQ,CAAE,QAAA,EAAS;AAAA,EAC5B,UAAA,EAAY,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAChC,GAAA,EAAK,CAAA,CAAE,MAAA,CAAO,CAAA,CAAE,MAAA,IAAU,CAAA,CAAE,OAAA,EAAS,CAAA,CAAE,QAAA;AACzC,CAAC;AAiBM,SAAS,gBAAqC,UAAA,EAAe;AAClE,EAAA,OAAO,CAAA,CAAE,mBAAmB,SAAA,EAAW;AAAA,IACrC,EAAE,MAAA,CAAO;AAAA,MACP,OAAA,EAAS,CAAA,CAAE,OAAA,CAAQ,IAAI,CAAA;AAAA,MACvB,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,IACD,EAAE,MAAA,CAAO;AAAA,MACP,OAAA,EAAS,CAAA,CAAE,OAAA,CAAQ,KAAK,CAAA;AAAA,MACxB,KAAA,EAAO;AAAA,KACR;AAAA,GACF,CAAA;AACH;AAYO,IAAM,mBAAA,GAAsB,eAAA,CAAgB,CAAA,CAAE,IAAA,EAAM;ACzDpD,IAAM,QAAyB,CAAA,GAAI,IAAA,KAAS,EAAA,CAAG,KAAA,CAAM,GAAG,IAAI;AAkB5D,SAAS,OAAO,SAAA,EAA+C;AACpE,EAAA,MAAM,IAAA,GAAO,SAAA,CAAU,OAAO,CAAA,CAAE,KAAA,CAAM,IAAA;AACtC,EAAA,IAAI,CAAC,IAAA;AACH,IAAA,MAAM,IAAI,MAAM,6CAA6C,CAAA;AAC/D,EAAA,OAAO,IAAA;AACT","file":"chunk-5LBEMLDK.js","sourcesContent":["/**\n * @h-ai/api-contract — HaiResult Schema\n *\n * 提供与 `@h-ai/core` HaiResult<T> 结构一致的 Zod Schema 工厂,\n * 用于 oRPC contract 的 output 定义和客户端响应校验。\n * @module result-schemas\n */\n\nimport { z } from 'zod'\n\n/**\n * HaiError 的跨端 JSON Schema。\n *\n * 仅描述公共错误字段,不暴露内部异常对象结构。\n * @example\n * ```ts\n * import { HaiErrorSchema } from '@h-ai/api-contract'\n *\n * const value = HaiErrorSchema.parse({\n * code: 'app:orders:001',\n * message: 'Order not found',\n * httpStatus: 404\n * })\n * void value\n * ```\n */\nexport const HaiErrorSchema = z.object({\n code: z.union([\n z.string(),\n z.number(),\n ]),\n message: z.string(),\n traceId: z.string().max(128).optional(),\n httpStatus: z.number().optional(),\n system: z.string().optional(),\n module: z.string().optional(),\n cause: z.unknown().optional(),\n suggestion: z.string().optional(),\n ext: z.record(z.string(), z.unknown()).optional(),\n})\n\n/**\n * 创建与 @h-ai/core HaiResult<T> 一致的响应 Schema。\n *\n * @param dataSchema - 成功分支 data 字段 Schema\n * @returns HaiResult<T> 的 Zod Schema\n * @example\n * ```ts\n * import { apiContract } from '@h-ai/api-contract'\n * import { z } from 'zod'\n *\n * const result = apiContract.haiResultSchema(z.object({ id: z.string() }))\n * .parse({ success: true, data: { id: 'order_1' } })\n * if (result.success) void result.data.id\n * ```\n */\nexport function haiResultSchema<T extends z.ZodType>(dataSchema: T) {\n return z.discriminatedUnion('success', [\n z.object({\n success: z.literal(true),\n data: dataSchema,\n }),\n z.object({\n success: z.literal(false),\n error: HaiErrorSchema,\n }),\n ])\n}\n\n/**\n * 无内容成功响应 Schema。\n * @example\n * ```ts\n * import { apiContract } from '@h-ai/api-contract'\n *\n * const result = apiContract.voidResultSchema.parse({ success: true, data: undefined })\n * if (!result.success) throw new Error(result.error.message)\n * ```\n */\nexport const HaiVoidResultSchema = haiResultSchema(z.void())\n","/**\n * @h-ai/api-contract — route builder\n *\n * 统一封装 oRPC 的 route builder。应用与契约包通过 `apiContract.route(...)`\n * 定义 HTTP 路由元数据,不需要直接依赖 `@orpc/contract` 或 `@h-ai/serv`。\n */\n\nimport type { AnyContractProcedure } from '@orpc/contract'\nimport { oc } from '@orpc/contract'\n\n/**\n * 创建 oRPC contract 路由节点。\n * @example\n * ```ts\n * import { apiContract } from '@h-ai/api-contract'\n * import { z } from 'zod'\n *\n * const health = apiContract.route({ method: 'GET', path: '/health' })\n * .output(z.object({ healthy: z.boolean() }))\n * void health\n * ```\n */\nexport const route: typeof oc.route = (...args) => oc.route(...args)\n\n/**\n * 读取 contract procedure 中声明的业务路径。\n *\n * 路径只在对应 `*-contract.ts` 的 route 定义中维护;transport、client 与\n * middleware 通过本函数读取,避免再维护一份路由常量。\n *\n * @param procedure - 已声明 HTTP route 的 oRPC contract procedure\n * @returns contract 中的绝对业务路径\n * @example\n * ```ts\n * import { apiContract } from '@h-ai/api-contract'\n *\n * const path = apiContract.pathOf(apiContract.iam.auth.login)\n * void path\n * ```\n */\nexport function pathOf(procedure: AnyContractProcedure): `/${string}` {\n const path = procedure['~orpc'].route.path\n if (!path)\n throw new Error('Contract procedure must define an HTTP path')\n return path\n}\n"]}
|