@h-ai/api-contract 0.1.0-alpha.67 → 0.1.0-alpha.68

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
@@ -19,6 +19,8 @@ Public HTTP API contracts for hai-framework, with oRPC contract + Zod as the sin
19
19
  - IAM token DTOs support httpOnly cookies: `refreshToken` may be absent from the response body and managed by the server through `Set-Cookie`.
20
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
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
+
22
24
  ## Getting started
23
25
 
24
26
  ### Quick start
@@ -48,6 +50,8 @@ export const appContract = {
48
50
 
49
51
  ### API contracts
50
52
 
53
+ 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.
54
+
51
55
  ```ts
52
56
  import { apiContract } from '@h-ai/api-contract'
53
57
 
@@ -58,6 +62,8 @@ myContract.storage.presignedUrls.createUpload
58
62
  myContract.ai.chats.createCompletion
59
63
  ```
60
64
 
65
+ `ai.chats.createCompletion` is `POST /ai/chats/completions` and returns a non-streaming `HaiResult<AiChatCompletionData>`. Its strict input rejects undeclared fields, including `stream`. Function tools preserve their complete nested JSON Schema and `strict`; choices support `auto`, `none`, `required`, or a supplied function name. Role-specific messages accept text for system/assistant/tool and images for user; tool results require a nonempty `tool_call_id`, and assistants require content or `tool_calls`. Applications authorize and execute tools and define a separate contract for streaming.
66
+
61
67
  Clients call nested methods directly through `@h-ai/api-client`:
62
68
 
63
69
  ```ts
@@ -91,6 +97,8 @@ const app = serv.createApp({
91
97
  - `apiContract.haiResultSchema(dataSchema)` / `apiContract.voidResultSchema` / `apiContract.paginatedSchema(itemSchema)`: shared DTO schema factories.
92
98
  - `Iam*Schema` / `Storage*Schema` / `Ai*Schema` / `Payment*Schema`: inputs and data structures reused across APIs and layers.
93
99
 
100
+ Batch deletion via `storage.files.deleteMany` returns `{ deletedKeys, failures: [] }` on success. Failures preserve progress in `error.ext.deleteMany` (`failed / unknown / notAttempted`); HTTP 200 alone does not mean completion. See [Storage batch deletion](../storage/README.en.md#api-overview).
101
+
94
102
  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.
95
103
 
96
104
  ### Configuration
@@ -99,6 +107,8 @@ This package has no runtime configuration and does not read environment variable
99
107
 
100
108
  ### Configuration driven authentication
101
109
 
110
+ 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.
111
+
102
112
  Agreements support configuration-loaded userAgreementMarkdown/privacyPolicyMarkdown and URLs. Markdown takes priority for the same agreement and is safely rendered in a modal.
103
113
 
104
114
  IAM adds GET /auth/config and POST /auth/login/ldap, /auth/password-reset/request and /auth/password-reset/confirm. Public config is a schema whitelist; IamLdapLoginInput and IamPublicConfig are exported. Password lengths follow the configured IAM policy.
@@ -109,6 +119,10 @@ IAM adds GET /auth/config and POST /auth/login/ldap, /auth/password-reset/reques
109
119
 
110
120
  Contracts describe input and output structures only. Procedures express business errors with `HaiResult<T>`, so clients need not catch business exceptions.
111
121
 
122
+ ## Input limits and HTTP capabilities
123
+
124
+ 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#存储输入约束与跨端能力).
125
+
112
126
  ## Development and testing
113
127
 
114
128
  ```bash
@@ -116,6 +130,8 @@ pnpm --filter @h-ai/api-contract test
116
130
  pnpm --filter @h-ai/api-contract typecheck
117
131
  ```
118
132
 
133
+ Schemas, inferred types and composition helpers include typechecked examples; see the [JSDoc conventions (Chinese)](../../.agents/instructions/module-conventions.md#jsdoc-与示例验证). Schema samples use validated local data and do not prove provider execution.
134
+
119
135
  ## License
120
136
 
121
137
  Apache-2.0
package/README.ja.md CHANGED
@@ -19,6 +19,8 @@ hai-framework の公開 HTTP API 契約パッケージ。oRPC contract + Zod を
19
19
  - IAM Token DTO は httpOnly cookie に対応。レスポンス本文に `refreshToken` が含まれない場合は、サーバーが `Set-Cookie` で管理します。
20
20
  - IAM の `auth.currentUser` はユーザー情報と現在のサーバーセッションの `roles` / `permissions` を返します。セッション復元のためにクライアントが権限のスナップショットを永続化する必要はありません。
21
21
 
22
+ 支払い作成の入出力は WeChat `jsapi`・Alipay `h5`・Stripe `h5` のみ受け付け、WeChat は `userId`(openid)が必須です。App・Native・ミニプログラムなどは検証で拒否します。Alipay は `{ gateway, fields }` のページパラメーターを返し、作成成功は支払い完了を意味しません。クライアント処理は [Payment](../payment/README.ja.md) を参照してください。
23
+
22
24
  ## 使い始める
23
25
 
24
26
  ### クイックスタート
@@ -48,6 +50,8 @@ export const appContract = {
48
50
 
49
51
  ### API 契約
50
52
 
53
+ 独立した contract パッケージの宣言ファイルを生成するため、上流の公開型 `ContractProcedureBuilderWithInputOutput`、`ContractProcedureBuilderWithOutput`、`Schema` を本パッケージから再エクスポートしています。独自ルートの入出力の型推論を維持し、明示的な型が必要な場合は `@h-ai/api-contract` から `import type` で取得してください。依存パッケージの内部インストールパスは参照しないでください。
54
+
51
55
  ```ts
52
56
  import { apiContract } from '@h-ai/api-contract'
53
57
 
@@ -58,6 +62,8 @@ myContract.storage.presignedUrls.createUpload
58
62
  myContract.ai.chats.createCompletion
59
63
  ```
60
64
 
65
+ `ai.chats.createCompletion` は `POST /ai/chats/completions` で、非ストリーミングの `HaiResult<AiChatCompletionData>` を返します。厳密な入力 Schema は `stream` など未定義のフィールドを拒否します。function ツールのネストした JSON Schema と `strict` を保持し、選択は `auto` / `none` / `required` / 提供した関数名に対応します。system/assistant/tool はテキスト、user は画像にも対応し、ツール結果の空でない `tool_call_id`、助手の内容または `tool_calls` が必須です。アプリがツールを認可・実行し、ストリーミング用には別の契約を定義します。
66
+
61
67
  クライアントは `@h-ai/api-client` でネストしたメソッドを直接呼び出します:
62
68
 
63
69
  ```ts
@@ -91,6 +97,8 @@ const app = serv.createApp({
91
97
  - `apiContract.haiResultSchema(dataSchema)` / `apiContract.voidResultSchema` / `apiContract.paginatedSchema(itemSchema)`:共通 DTO Schema のファクトリー。
92
98
  - `Iam*Schema` / `Storage*Schema` / `Ai*Schema` / `Payment*Schema`:複数の API・層で再利用する入力とデータ構造。
93
99
 
100
+ `storage.files.deleteMany` の成功データは `{ deletedKeys, failures: [] }` です。失敗進捗は `error.ext.deleteMany`(`failed / unknown / notAttempted`)にあり、HTTP 200 だけで完了と判断しません。[Storage の一括削除](../storage/README.ja.md#api-一覧)を参照してください。
101
+
94
102
  業務 path は対応する `*-contract.ts` に直接記述します。一度しか使わない出力 Schema は `.output(...)` にインラインで定義します。同じ contract ファイル内で再利用する場合は非公開の定数にできますが、schemas からエクスポートしてはいけません。
95
103
 
96
104
  ### 設定
@@ -99,6 +107,8 @@ const app = serv.createApp({
99
107
 
100
108
  ### 設定による認証画面
101
109
 
110
+ パスワードログインの送信項目は `identifier` と `password` のみです。`AuthPanel` は `LoginForm` の `username` を `identifier` に変換します。有効期間はサーバーの `session.maxAge` / `session.refreshTokenMaxAge` で設定し、フォームにログインごとの永続セッション選択肢はありません。
111
+
102
112
  規約は設定の userAgreementMarkdown/privacyPolicyMarkdown または URL を使用できます。同じ規約は Markdown 本文を優先して安全な Modal で描画します。
103
113
 
104
114
  IAM に公開設定、LDAP、復旧要求と確定の標準 route を追加しました。IamPublicConfig は安全な Schema で、登録パスワードの長さは IAM 設定に従います。
@@ -109,6 +119,10 @@ IAM に公開設定、LDAP、復旧要求と確定の標準 route を追加し
109
119
 
110
120
  Contract は入出力構造のみを定義します。業務エラーは procedure が返す `HaiResult<T>` で表し、クライアント側で業務例外を捕捉する必要はありません。
111
121
 
122
+ ## 入力制約と HTTP 機能
123
+
124
+ キーは 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#存储输入约束与跨端能力)を参照してください。
125
+
112
126
  ## 開発とテスト
113
127
 
114
128
  ```bash
@@ -116,6 +130,8 @@ pnpm --filter @h-ai/api-contract test
116
130
  pnpm --filter @h-ai/api-contract typecheck
117
131
  ```
118
132
 
133
+ Schema、推論型と組合せツールには型検査できる例があります。[JSDoc 規約(中国語)](../../.agents/instructions/module-conventions.md#jsdoc-与示例验证) を参照してください。Schema のローカル例は provider の実行証明ではありません。
134
+
119
135
  ## ライセンス
120
136
 
121
137
  Apache-2.0
package/README.md CHANGED
@@ -19,6 +19,8 @@ hai-framework 的公共 HTTP API 契约包,用 oRPC contract 和 Zod 让前后
19
19
  - IAM token DTO 兼容 httpOnly cookie 模式:响应体中 `refreshToken` 可能不存在,由服务端 `Set-Cookie` 管理。
20
20
  - IAM `auth.currentUser` 返回用户资料以及服务端当前会话的 `roles` / `permissions`,客户端恢复会话时无需持久化权限快照。
21
21
 
22
+ 支付创建输入和输出仅接受微信 `jsapi`、支付宝 `h5`、Stripe `h5`;微信输入必填 `userId`(openid)。App、Native、小程序与其它组合会在输入校验时失败。支付宝输出是 `{ gateway, fields }` 页面参数,创建成功不代表支付完成;客户端处理见 [Payment](../payment/README.md)。
23
+
22
24
  ## 使用入门
23
25
 
24
26
  ### 快速开始
@@ -48,6 +50,8 @@ export const appContract = {
48
50
 
49
51
  ### API 契约
50
52
 
53
+ 独立 contract 包构建声明文件时,`ContractProcedureBuilderWithInputOutput`、`ContractProcedureBuilderWithOutput` 和 `Schema` 由本包按上游真实类型公开转出,保持自定义路由的输入输出推导。需要显式类型时从 `@h-ai/api-contract` 使用 `import type`,不要引用依赖的内部安装路径。
54
+
51
55
  ```ts
52
56
  import { apiContract } from '@h-ai/api-contract'
53
57
 
@@ -58,6 +62,8 @@ myContract.storage.presignedUrls.createUpload
58
62
  myContract.ai.chats.createCompletion
59
63
  ```
60
64
 
65
+ `ai.chats.createCompletion` 为 `POST /ai/chats/completions`,只返回非流式 `HaiResult<AiChatCompletionData>`;输入严格拒绝 `stream` 等未声明字段。function 工具保留完整嵌套 JSON Schema 和 `strict`,工具选择支持 `auto` / `none` / `required` / 已提供的函数名。消息按角色校验:system/assistant/tool 接收文本,user 另支持图片;工具结果必填非空 `tool_call_id`,助手必须包含内容或 `tool_calls`。默认工具调用由业务方授权与执行,流式能力由应用定义独立契约。
66
+
61
67
  客户端通过 `@h-ai/api-client` 直接调用嵌套方法:
62
68
 
63
69
  ```ts
@@ -91,6 +97,8 @@ const app = serv.createApp({
91
97
  - `apiContract.haiResultSchema(dataSchema)` / `apiContract.voidResultSchema` / `apiContract.paginatedSchema(itemSchema)`:公共 DTO Schema 工厂。
92
98
  - `Iam*Schema` / `Storage*Schema` / `Ai*Schema` / `Payment*Schema`:真正跨接口、跨层复用的输入与数据结构。
93
99
 
100
+ 批量删除 `storage.files.deleteMany` 成功时返回 `{ deletedKeys, failures: [] }`;失败进度位于 `error.ext.deleteMany`(`failed / unknown / notAttempted`),不能只根据 HTTP 200 判断完成。详见 [Storage 批量删除](../storage/README.md#api-概览)。
101
+
94
102
  业务 path 必须直接写在对应 `*-contract.ts`。只使用一次的输出 Schema 直接内联到 `.output(...)`;同一 contract 文件内重复使用时可保留私有常量,但不得从 schemas 导出。
95
103
 
96
104
  ### 配置
@@ -99,6 +107,8 @@ const app = serv.createApp({
99
107
 
100
108
  ### 配置驱动认证页面
101
109
 
110
+ 密码登录只提交 `identifier` 和 `password`;`AuthPanel` 将 `LoginForm` 的 `username` 映射为 `identifier`。会话有效期由服务端 `session.maxAge` / `session.refreshTokenMaxAge` 配置决定,登录表单不提供按次登录的持久会话选项。
111
+
102
112
  协议支持配置中的 userAgreementMarkdown/privacyPolicyMarkdown 正文及 URL;同主题优先 Markdown,由安全渲染器在弹窗显示。
103
113
 
104
114
  标准 IAM contract 新增 GET /auth/config、POST /auth/login/ldap、POST /auth/password-reset/request、POST /auth/password-reset/confirm。公开配置 Schema 是安全白名单。IamLdapLoginInput、IamPublicConfig 对调用方提供真实类型。密码长度以 IAM 运行时策略为准,contract 不固定注册密码最小长度。
@@ -109,6 +119,10 @@ const app = serv.createApp({
109
119
 
110
120
  Contract 只描述输入输出结构。业务错误由 procedure 返回 `HaiResult<T>` 表达,客户端不需要捕获业务异常。
111
121
 
122
+ ## 输入约束与 HTTP 能力
123
+
124
+ 存储 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#存储输入约束与跨端能力)。
125
+
112
126
  ## 开发测试
113
127
 
114
128
  ```bash
@@ -116,6 +130,8 @@ pnpm --filter @h-ai/api-contract test
116
130
  pnpm --filter @h-ai/api-contract typecheck
117
131
  ```
118
132
 
133
+ Schema、推导类型与组合工具均提供可类型检查的示例;见[模块 JSDoc 约定](../../.agents/instructions/module-conventions.md#jsdoc-与示例验证)。Schema 示例使用受约束的本地数据,不代表 provider 已执行。
134
+
119
135
  ## 许可证
120
136
 
121
137
  Apache-2.0