@h-ai/serv 0.1.0-alpha.56 → 0.1.0-alpha.58
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 +657 -0
- package/README.ja.md +657 -0
- package/README.md +11 -1
- package/dist/{chunk-KIWHKWLD.js → chunk-R354OMWL.js} +5 -2
- package/dist/chunk-R354OMWL.js.map +1 -0
- package/dist/features/ai.d.ts +19 -19
- package/dist/features/ai.js +1 -1
- package/dist/features/iam.d.ts +57 -57
- package/dist/features/iam.js +1 -1
- package/dist/features/storage.d.ts +17 -17
- package/dist/features/storage.js +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +17 -12
- package/dist/index.js.map +1 -1
- package/dist/{serv-context-jc3rZxbj.d.ts → serv-context-CkbS0M9G.d.ts} +4 -4
- package/package.json +23 -22
- package/dist/chunk-KIWHKWLD.js.map +0 -1
|
@@ -2,7 +2,7 @@ import * as _orpc_server from '@orpc/server';
|
|
|
2
2
|
import * as zod_v4_core from 'zod/v4/core';
|
|
3
3
|
import * as zod from 'zod';
|
|
4
4
|
import { StorageFunctions } from '@h-ai/storage';
|
|
5
|
-
import {
|
|
5
|
+
import { S as ServContext } from '../serv-context-CkbS0M9G.js';
|
|
6
6
|
import '@h-ai/core';
|
|
7
7
|
|
|
8
8
|
/** Storage 默认 procedures 依赖。 */
|
|
@@ -11,8 +11,8 @@ interface StorageProcedureDeps {
|
|
|
11
11
|
}
|
|
12
12
|
/** 创建 Storage 默认 procedures。 */
|
|
13
13
|
declare function createStorageProcedures(deps: StorageProcedureDeps): {
|
|
14
|
-
presignedUrls:
|
|
15
|
-
createDownload: _orpc_server.
|
|
14
|
+
presignedUrls: {
|
|
15
|
+
createDownload: _orpc_server.Procedure<ServContext & {}, any, zod.ZodObject<{
|
|
16
16
|
key: zod.ZodString;
|
|
17
17
|
expiresIn: zod.ZodOptional<zod.ZodNumber>;
|
|
18
18
|
}, zod_v4_core.$strip>, zod.ZodDiscriminatedUnion<[zod.ZodObject<{
|
|
@@ -34,8 +34,8 @@ declare function createStorageProcedures(deps: StorageProcedureDeps): {
|
|
|
34
34
|
suggestion: zod.ZodOptional<zod.ZodString>;
|
|
35
35
|
ext: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodUnknown>>;
|
|
36
36
|
}, zod_v4_core.$strip>;
|
|
37
|
-
}, zod_v4_core.$strip>], "success">, Record<never, never>, Record<never, never
|
|
38
|
-
createUpload: _orpc_server.
|
|
37
|
+
}, zod_v4_core.$strip>], "success">, Record<never, never>, Record<never, never>>;
|
|
38
|
+
createUpload: _orpc_server.Procedure<ServContext & {}, any, zod.ZodObject<{
|
|
39
39
|
key: zod.ZodString;
|
|
40
40
|
contentType: zod.ZodOptional<zod.ZodString>;
|
|
41
41
|
contentLength: zod.ZodOptional<zod.ZodNumber>;
|
|
@@ -59,10 +59,10 @@ declare function createStorageProcedures(deps: StorageProcedureDeps): {
|
|
|
59
59
|
suggestion: zod.ZodOptional<zod.ZodString>;
|
|
60
60
|
ext: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodUnknown>>;
|
|
61
61
|
}, zod_v4_core.$strip>;
|
|
62
|
-
}, zod_v4_core.$strip>], "success">, Record<never, never>, Record<never, never
|
|
63
|
-
}
|
|
64
|
-
files:
|
|
65
|
-
list: _orpc_server.
|
|
62
|
+
}, zod_v4_core.$strip>], "success">, Record<never, never>, Record<never, never>>;
|
|
63
|
+
};
|
|
64
|
+
files: {
|
|
65
|
+
list: _orpc_server.Procedure<ServContext & {}, any, zod.ZodObject<{
|
|
66
66
|
prefix: zod.ZodOptional<zod.ZodString>;
|
|
67
67
|
maxKeys: zod.ZodOptional<zod.ZodCoercedNumber<unknown>>;
|
|
68
68
|
continuationToken: zod.ZodOptional<zod.ZodString>;
|
|
@@ -94,8 +94,8 @@ declare function createStorageProcedures(deps: StorageProcedureDeps): {
|
|
|
94
94
|
suggestion: zod.ZodOptional<zod.ZodString>;
|
|
95
95
|
ext: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodUnknown>>;
|
|
96
96
|
}, zod_v4_core.$strip>;
|
|
97
|
-
}, zod_v4_core.$strip>], "success">, Record<never, never>, Record<never, never
|
|
98
|
-
getMetadata: _orpc_server.
|
|
97
|
+
}, zod_v4_core.$strip>], "success">, Record<never, never>, Record<never, never>>;
|
|
98
|
+
getMetadata: _orpc_server.Procedure<ServContext & {}, any, zod.ZodObject<{
|
|
99
99
|
key: zod.ZodString;
|
|
100
100
|
}, zod_v4_core.$strip>, zod.ZodDiscriminatedUnion<[zod.ZodObject<{
|
|
101
101
|
success: zod.ZodLiteral<true>;
|
|
@@ -119,8 +119,8 @@ declare function createStorageProcedures(deps: StorageProcedureDeps): {
|
|
|
119
119
|
suggestion: zod.ZodOptional<zod.ZodString>;
|
|
120
120
|
ext: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodUnknown>>;
|
|
121
121
|
}, zod_v4_core.$strip>;
|
|
122
|
-
}, zod_v4_core.$strip>], "success">, Record<never, never>, Record<never, never
|
|
123
|
-
delete: _orpc_server.
|
|
122
|
+
}, zod_v4_core.$strip>], "success">, Record<never, never>, Record<never, never>>;
|
|
123
|
+
delete: _orpc_server.Procedure<ServContext & {}, any, zod.ZodObject<{
|
|
124
124
|
key: zod.ZodString;
|
|
125
125
|
}, zod_v4_core.$strip>, zod.ZodDiscriminatedUnion<[zod.ZodObject<{
|
|
126
126
|
success: zod.ZodLiteral<true>;
|
|
@@ -137,8 +137,8 @@ declare function createStorageProcedures(deps: StorageProcedureDeps): {
|
|
|
137
137
|
suggestion: zod.ZodOptional<zod.ZodString>;
|
|
138
138
|
ext: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodUnknown>>;
|
|
139
139
|
}, zod_v4_core.$strip>;
|
|
140
|
-
}, zod_v4_core.$strip>], "success">, Record<never, never>, Record<never, never
|
|
141
|
-
deleteMany: _orpc_server.
|
|
140
|
+
}, zod_v4_core.$strip>], "success">, Record<never, never>, Record<never, never>>;
|
|
141
|
+
deleteMany: _orpc_server.Procedure<ServContext & {}, any, zod.ZodObject<{
|
|
142
142
|
keys: zod.ZodArray<zod.ZodString>;
|
|
143
143
|
}, zod_v4_core.$strip>, zod.ZodDiscriminatedUnion<[zod.ZodObject<{
|
|
144
144
|
success: zod.ZodLiteral<true>;
|
|
@@ -155,8 +155,8 @@ declare function createStorageProcedures(deps: StorageProcedureDeps): {
|
|
|
155
155
|
suggestion: zod.ZodOptional<zod.ZodString>;
|
|
156
156
|
ext: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodUnknown>>;
|
|
157
157
|
}, zod_v4_core.$strip>;
|
|
158
|
-
}, zod_v4_core.$strip>], "success">, Record<never, never>, Record<never, never
|
|
159
|
-
}
|
|
158
|
+
}, zod_v4_core.$strip>], "success">, Record<never, never>, Record<never, never>>;
|
|
159
|
+
};
|
|
160
160
|
};
|
|
161
161
|
|
|
162
162
|
export { type StorageProcedureDeps, createStorageProcedures };
|
package/dist/features/storage.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mapHaiResult } from '../chunk-27PCPE37.js';
|
|
2
|
-
import { implement, servM } from '../chunk-
|
|
2
|
+
import { implement, servM } from '../chunk-R354OMWL.js';
|
|
3
3
|
import { apiContract } from '@h-ai/api-contract';
|
|
4
4
|
import { ok, err, HaiCommonError } from '@h-ai/core';
|
|
5
5
|
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import * as _h_ai_core from '@h-ai/core';
|
|
|
2
2
|
import { HaiResult, ValidationFormError } from '@h-ai/core';
|
|
3
3
|
import { AIFunctions, AudioWsStartMessage, AudioFormat } from '@h-ai/ai';
|
|
4
4
|
import { AnyContractRouter, OpenAPI } from '@orpc/contract';
|
|
5
|
-
import { ProcedureHandler, ErrorMap, Meta, ProcedureHandlerOptions, ORPCErrorConstructorMap, Router, ContractRouter, Context, ContractProcedure, InferSchemaInput, InferSchemaOutput } from '@orpc/server';
|
|
6
|
-
import {
|
|
7
|
-
export { d as CreateServContextInput, N as NativeRefreshTokenTransportConfig, e as RefreshTokenPair } from './serv-context-
|
|
5
|
+
import { ProcedureHandler, ErrorMap, Meta, ProcedureHandlerOptions, ORPCErrorConstructorMap, Router, ContractRouter, Context, ContractProcedure, InferSchemaInput, InferSchemaOutput, UnlaziedRouter } from '@orpc/server';
|
|
6
|
+
import { a as ServSession, S as ServContext, b as ServIam, R as RefreshCookieConfig, C as CreateServContext, p as parseRequestContext, c as buildAuthContextFactory } from './serv-context-CkbS0M9G.js';
|
|
7
|
+
export { d as CreateServContextInput, N as NativeRefreshTokenTransportConfig, e as RefreshTokenPair } from './serv-context-CkbS0M9G.js';
|
|
8
8
|
import { MiddlewareHandler } from 'hono';
|
|
9
9
|
import { z, ZodType } from 'zod';
|
|
10
10
|
import { CryptoFunctions, TransportKeyStore } from '@h-ai/crypto';
|
|
@@ -713,8 +713,8 @@ interface ServRouteMethod<TContract extends ServContract, TInitialContext extend
|
|
|
713
713
|
<TPath extends TRemaining>(path: TPath): ServRouteRegistration<TContract, TInitialContext, TCurrentContext, TRemaining, TPath>;
|
|
714
714
|
}
|
|
715
715
|
type ServRouterBuilderBuild<TContract extends ServContract, TInitialContext extends Context, TRemaining> = [TRemaining] extends [never] ? {
|
|
716
|
-
/**
|
|
717
|
-
readonly build: () => Router<TContract, TInitialContext
|
|
716
|
+
/** 同步返回完整的普通 router,允许按需选用嵌套的默认 procedures。 */
|
|
717
|
+
readonly build: () => UnlaziedRouter<Router<TContract, TInitialContext>>;
|
|
718
718
|
} : {
|
|
719
719
|
/** 仅供 TypeScript/IDE 展示尚未实现的 route;运行时不存在。 */
|
|
720
720
|
readonly missingRoutes: TRemaining;
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { servM, WILDCARD_ROLE, WILDCARD_PERMISSION, implement, normalizeServLocale, buildHaiErrorBody } from './chunk-
|
|
1
|
+
import { servM, WILDCARD_ROLE, WILDCARD_PERMISSION, implement, normalizeServLocale, buildHaiErrorBody } from './chunk-R354OMWL.js';
|
|
2
2
|
import process from 'process';
|
|
3
|
-
import { serve } from '@hono/node-server';
|
|
3
|
+
import { upgradeWebSocket, serve } from '@hono/node-server';
|
|
4
4
|
import { apiContract, AUDIO_WS_PATH, AudioWsClientMessageSchema } from '@h-ai/api-contract';
|
|
5
5
|
import { core, ok, err, HaiCommonError } from '@h-ai/core';
|
|
6
|
-
import { createNodeWebSocket } from '@hono/node-ws';
|
|
7
6
|
import { OpenAPIHandler } from '@orpc/openapi/fetch';
|
|
8
7
|
import { RPCHandler } from '@orpc/server/fetch';
|
|
9
8
|
import { Hono } from 'hono';
|
|
9
|
+
import { WebSocketServer } from 'ws';
|
|
10
10
|
import { Buffer } from 'buffer';
|
|
11
11
|
import { z } from 'zod';
|
|
12
12
|
import { getCookie } from 'hono/cookie';
|
|
@@ -36,7 +36,7 @@ var CODE_PROTOCOL = "hai:ai:050";
|
|
|
36
36
|
var CODE_TICKET = "hai:ai:054";
|
|
37
37
|
var CODE_TOO_LARGE = "hai:ai:058";
|
|
38
38
|
var CODE_TIMEOUT = "hai:ai:057";
|
|
39
|
-
function registerAudioWsRoute(app, path,
|
|
39
|
+
function registerAudioWsRoute(app, path, upgradeWebSocket2, deps) {
|
|
40
40
|
const limits = {
|
|
41
41
|
maxMessageBytes: deps.maxMessageBytes ?? DEFAULT_MAX_MESSAGE_BYTES,
|
|
42
42
|
maxBufferedBytes: deps.maxBufferedBytes ?? DEFAULT_MAX_BUFFERED_BYTES,
|
|
@@ -46,7 +46,7 @@ function registerAudioWsRoute(app, path, upgradeWebSocket, deps) {
|
|
|
46
46
|
};
|
|
47
47
|
const maxSessionMs = deps.maxSessionMs ?? DEFAULT_MAX_SESSION_MS;
|
|
48
48
|
const preAuthTimeoutMs = deps.preAuthTimeoutMs ?? DEFAULT_PRE_AUTH_TIMEOUT_MS;
|
|
49
|
-
app.get(path,
|
|
49
|
+
app.get(path, upgradeWebSocket2((c) => {
|
|
50
50
|
const ticket = c.req.query("ticket");
|
|
51
51
|
const conn = new AudioConnection(deps, ticket, limits);
|
|
52
52
|
let sessionTimer;
|
|
@@ -77,6 +77,7 @@ var AsyncQueue = class {
|
|
|
77
77
|
constructor(maxItems) {
|
|
78
78
|
this.maxItems = maxItems;
|
|
79
79
|
}
|
|
80
|
+
maxItems;
|
|
80
81
|
items = [];
|
|
81
82
|
waiting = null;
|
|
82
83
|
ended = false;
|
|
@@ -130,6 +131,9 @@ var AudioConnection = class {
|
|
|
130
131
|
this.audioQueue = new AsyncQueue(MAX_QUEUE_ITEMS);
|
|
131
132
|
this.textQueue = new AsyncQueue(MAX_QUEUE_ITEMS);
|
|
132
133
|
}
|
|
134
|
+
deps;
|
|
135
|
+
ticket;
|
|
136
|
+
limits;
|
|
133
137
|
state = "connecting";
|
|
134
138
|
start;
|
|
135
139
|
session;
|
|
@@ -1145,10 +1149,14 @@ function isEncryptedPayloadShape(value) {
|
|
|
1145
1149
|
|
|
1146
1150
|
// src/serv-app.ts
|
|
1147
1151
|
var API_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"];
|
|
1148
|
-
var
|
|
1152
|
+
var audioWsServers = /* @__PURE__ */ new WeakMap();
|
|
1149
1153
|
function createApp(options) {
|
|
1150
1154
|
const http = resolveServHttpConfig(options.http);
|
|
1151
1155
|
const app = new Hono();
|
|
1156
|
+
app.notFound((c) => c.json(buildHaiErrorBody(
|
|
1157
|
+
HaiCommonError.NOT_FOUND,
|
|
1158
|
+
core.i18n.coreM("core_errorNotFound", { locale: resolveRequestLocale(c.req.raw.headers) })
|
|
1159
|
+
), 404));
|
|
1152
1160
|
const iamRef = options.iam;
|
|
1153
1161
|
const verifyToken = options.verifyToken ?? (iamRef ? (token) => iamRef.session.verifyToken(token) : void 0);
|
|
1154
1162
|
const createContext = options.createContext ?? (verifyToken ? buildAuthContextFactory(verifyToken) : parseRequestContext);
|
|
@@ -1180,7 +1188,6 @@ function createApp(options) {
|
|
|
1180
1188
|
if (options.refreshCookie)
|
|
1181
1189
|
mountRefreshCookieRoutes(app, http.apiPrefix, options.refreshCookie, options.iam);
|
|
1182
1190
|
if (options.audio) {
|
|
1183
|
-
const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app });
|
|
1184
1191
|
const audioPath = `${http.apiPrefix}${options.audio.path ?? AUDIO_WS_PATH}`;
|
|
1185
1192
|
registerAudioWsRoute(app, audioPath, upgradeWebSocket, {
|
|
1186
1193
|
ai: options.audio.ai,
|
|
@@ -1195,7 +1202,7 @@ function createApp(options) {
|
|
|
1195
1202
|
maxPendingMessages: options.audio.maxPendingMessages,
|
|
1196
1203
|
maxSendBufferBytes: options.audio.maxSendBufferBytes
|
|
1197
1204
|
});
|
|
1198
|
-
|
|
1205
|
+
audioWsServers.set(app, new WebSocketServer({ noServer: true }));
|
|
1199
1206
|
}
|
|
1200
1207
|
mountOpenAPIRoutes(app, options.procedures, http.apiPrefix, createContext);
|
|
1201
1208
|
if (http.rpc !== false)
|
|
@@ -1310,13 +1317,11 @@ var DEFAULT_SERV_PORT = 3e3;
|
|
|
1310
1317
|
function listen(app, options = {}) {
|
|
1311
1318
|
const host = options.host ?? DEFAULT_SERV_HOST;
|
|
1312
1319
|
const port = options.port ?? DEFAULT_SERV_PORT;
|
|
1320
|
+
const audioServer = audioWsServers.get(app);
|
|
1313
1321
|
const server = serve(
|
|
1314
|
-
{ fetch: app.fetch, hostname: host, port },
|
|
1322
|
+
{ fetch: app.fetch, hostname: host, port, websocket: audioServer ? { server: audioServer } : void 0 },
|
|
1315
1323
|
options.onListening
|
|
1316
1324
|
);
|
|
1317
|
-
const injectWebSocket = audioWsInjectors.get(app);
|
|
1318
|
-
if (injectWebSocket)
|
|
1319
|
-
injectWebSocket(server);
|
|
1320
1325
|
const handle = {
|
|
1321
1326
|
server,
|
|
1322
1327
|
address: { host, port },
|