weifuwu 0.23.3 → 0.23.4
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/dist/env.d.ts +8 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +22 -7
- package/package.json +2 -2
- package/dist/kb.d.ts +0 -70
- package/dist/oauth-client.d.ts +0 -41
- package/dist/preferences.d.ts +0 -18
- package/dist/server.d.ts +0 -1
package/dist/env.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether this code is running from the compiled `dist/index.js` bundle.
|
|
3
|
+
* `false` when running TypeScript source directly (dev workflow in weifuwu repo).
|
|
4
|
+
*
|
|
5
|
+
* Used by modules that need to resolve package-internal files differently
|
|
6
|
+
* depending on whether they are compiled (published npm package) or raw TS.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isBundled(): boolean;
|
|
1
9
|
/**
|
|
2
10
|
* Whether `NODE_ENV` is explicitly set to `'development'`.
|
|
3
11
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type { Context, Handler, Middleware, ErrorHandler } from './types.ts';
|
|
2
2
|
export { currentTraceId, currentTrace, runWithTrace, traceElapsed } from './trace.ts';
|
|
3
3
|
export type { TraceContext } from './trace.ts';
|
|
4
|
-
export { loadEnv, isDev, isProd } from './env.ts';
|
|
4
|
+
export { loadEnv, isDev, isProd, isBundled } from './env.ts';
|
|
5
5
|
export { serve, createTestServer, DEFAULT_MAX_BODY } from './serve.ts';
|
|
6
6
|
export type { ServeOptions, Server } from './serve.ts';
|
|
7
7
|
export { Router } from './router.ts';
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,9 @@ function traceElapsed() {
|
|
|
28
28
|
// env.ts
|
|
29
29
|
import { readFileSync } from "node:fs";
|
|
30
30
|
import { resolve } from "node:path";
|
|
31
|
+
function isBundled() {
|
|
32
|
+
return true ? true : false;
|
|
33
|
+
}
|
|
31
34
|
function isDev() {
|
|
32
35
|
return process.env.NODE_ENV === "development";
|
|
33
36
|
}
|
|
@@ -6778,13 +6781,24 @@ async function compileVendorBundle() {
|
|
|
6778
6781
|
const keys = Object.keys(mod).filter((k) => !k.startsWith("_") && k !== "default");
|
|
6779
6782
|
modules[request] = keys;
|
|
6780
6783
|
}
|
|
6781
|
-
const
|
|
6782
|
-
const
|
|
6784
|
+
const baseDir = import.meta.dirname ?? __dirname;
|
|
6785
|
+
const reactAbsPath = isBundled() ? resolve3(baseDir, "react.js") : resolve3(baseDir, "react.ts");
|
|
6786
|
+
const reactSrc = readFileSync2(reactAbsPath, "utf-8");
|
|
6783
6787
|
const wfwKeys = [];
|
|
6784
|
-
|
|
6785
|
-
const
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
+
if (reactAbsPath.endsWith(".ts")) {
|
|
6789
|
+
for (const line of reactSrc.split("\n")) {
|
|
6790
|
+
const m = line.match(/^export\s+\{[^}]+\}\s*from/);
|
|
6791
|
+
if (m) {
|
|
6792
|
+
const names = line.slice(line.indexOf("{") + 1, line.indexOf("}")).split(",").map((s) => s.trim()).filter(Boolean);
|
|
6793
|
+
for (const n of names) {
|
|
6794
|
+
if (!n.startsWith("type ") && !wfwKeys.includes(n)) wfwKeys.push(n);
|
|
6795
|
+
}
|
|
6796
|
+
}
|
|
6797
|
+
}
|
|
6798
|
+
} else {
|
|
6799
|
+
const exportMatch = reactSrc.match(/\bexport\s*\{([^}]+)\}\s*;/);
|
|
6800
|
+
if (exportMatch) {
|
|
6801
|
+
const names = exportMatch[1].split(",").map((s) => s.trim()).filter(Boolean);
|
|
6788
6802
|
for (const n of names) {
|
|
6789
6803
|
if (!n.startsWith("type ") && !wfwKeys.includes(n)) wfwKeys.push(n);
|
|
6790
6804
|
}
|
|
@@ -6797,7 +6811,7 @@ async function compileVendorBundle() {
|
|
|
6797
6811
|
if (unique.length > 0) stmts.push(`export { ${unique.join(", ")} } from ${JSON.stringify(request)};`);
|
|
6798
6812
|
}
|
|
6799
6813
|
const uidWfw = wfwKeys.filter((k) => !used.has(k) && used.add(k));
|
|
6800
|
-
if (uidWfw.length > 0) stmts.push(`export { ${uidWfw.join(", ")} } from ${JSON.stringify(
|
|
6814
|
+
if (uidWfw.length > 0) stmts.push(`export { ${uidWfw.join(", ")} } from ${JSON.stringify(reactAbsPath)};`);
|
|
6801
6815
|
const result = await esbuild.build({
|
|
6802
6816
|
stdin: { contents: stmts.join("\n"), resolveDir: process.cwd() },
|
|
6803
6817
|
format: "esm",
|
|
@@ -11550,6 +11564,7 @@ export {
|
|
|
11550
11564
|
helmet,
|
|
11551
11565
|
i18n,
|
|
11552
11566
|
iii,
|
|
11567
|
+
isBundled,
|
|
11553
11568
|
isDev,
|
|
11554
11569
|
isProd,
|
|
11555
11570
|
knowledgeBase,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weifuwu",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.4",
|
|
4
4
|
"description": "Web-standard HTTP framework for Node.js — (req, ctx) => Response",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"scripts": {
|
|
23
23
|
"dev": "cd cli/template && NODE_ENV=development node --watch index.ts",
|
|
24
24
|
"start": "cd cli/template && node index.ts",
|
|
25
|
-
"build": "esbuild index.ts --bundle --format=esm --platform=node --outfile=dist/index.js --packages=external && esbuild cli.ts --bundle --format=esm --platform=node --outfile=dist/cli.js --packages=external && esbuild react.ts --bundle --format=esm --outfile=dist/react.js --external:react --external:react-dom",
|
|
25
|
+
"build": "esbuild index.ts --bundle --format=esm --platform=node --outfile=dist/index.js --packages=external --define:__WFW_BUNDLED__=true && esbuild cli.ts --bundle --format=esm --platform=node --outfile=dist/cli.js --packages=external && esbuild react.ts --bundle --format=esm --outfile=dist/react.js --external:react --external:react-dom",
|
|
26
26
|
"prepublishOnly": "npm run build && tsc --emitDeclarationOnly --outdir dist",
|
|
27
27
|
"test": "node --test 'test/**/*.test.ts'",
|
|
28
28
|
"test:unit": "bash scripts/test-unit.sh",
|
package/dist/kb.d.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type { Sql } from './vendor.ts';
|
|
2
|
-
import type { Middleware } from './types.ts';
|
|
3
|
-
export interface KBOptions {
|
|
4
|
-
/** Postgres SQL client (with pgvector extension enabled). */
|
|
5
|
-
sql: Sql<{}>;
|
|
6
|
-
/**
|
|
7
|
-
* Embedding function.
|
|
8
|
-
* Takes a text string, returns a vector of numbers.
|
|
9
|
-
* Example: (text) => embed({ model: openai.embedding('text-embedding-3-small'), value: text }).then(r => r.embedding)
|
|
10
|
-
*/
|
|
11
|
-
embedding: (text: string) => Promise<number[]>;
|
|
12
|
-
/** Vector dimensions (default: 1536 for text-embedding-3-small). */
|
|
13
|
-
dimensions?: number;
|
|
14
|
-
/** Table name (default: '_kb_docs'). */
|
|
15
|
-
table?: string;
|
|
16
|
-
/** Default chunk size in characters (default: 512). */
|
|
17
|
-
chunkSize?: number;
|
|
18
|
-
/** Default chunk overlap in characters (default: 64). */
|
|
19
|
-
chunkOverlap?: number;
|
|
20
|
-
/** Default search limit (default: 5). */
|
|
21
|
-
searchLimit?: number;
|
|
22
|
-
/** Minimum similarity score threshold (0–1, default: 0). Set higher for stricter matches. */
|
|
23
|
-
searchThreshold?: number;
|
|
24
|
-
}
|
|
25
|
-
export interface KBIngestOptions {
|
|
26
|
-
title?: string;
|
|
27
|
-
metadata?: Record<string, unknown>;
|
|
28
|
-
chunkSize?: number;
|
|
29
|
-
chunkOverlap?: number;
|
|
30
|
-
}
|
|
31
|
-
export interface KBSearchResult {
|
|
32
|
-
id: number;
|
|
33
|
-
key: string;
|
|
34
|
-
title: string;
|
|
35
|
-
content: string;
|
|
36
|
-
score: number;
|
|
37
|
-
metadata: Record<string, unknown>;
|
|
38
|
-
}
|
|
39
|
-
export interface KBSearchOptions {
|
|
40
|
-
limit?: number;
|
|
41
|
-
/** Minimum cosine similarity score (0–1). Results below this are excluded. */
|
|
42
|
-
threshold?: number;
|
|
43
|
-
}
|
|
44
|
-
export interface KBListEntry {
|
|
45
|
-
key: string;
|
|
46
|
-
title: string;
|
|
47
|
-
chunks: number;
|
|
48
|
-
}
|
|
49
|
-
export interface KBModule {
|
|
50
|
-
/**
|
|
51
|
-
* Ingest a document: chunk → embed → store.
|
|
52
|
-
* If a document with the same key exists, it is replaced (delete + re-insert).
|
|
53
|
-
* Returns the number of chunks created.
|
|
54
|
-
*/
|
|
55
|
-
ingest(key: string, content: string, options?: KBIngestOptions): Promise<number>;
|
|
56
|
-
/**
|
|
57
|
-
* Search the knowledge base by semantic similarity.
|
|
58
|
-
* Query is embedded, then vector similarity search returns top results.
|
|
59
|
-
*/
|
|
60
|
-
search(query: string, searchOptions?: KBSearchOptions): Promise<KBSearchResult[]>;
|
|
61
|
-
/** Delete all chunks for a document key. */
|
|
62
|
-
delete(key: string): Promise<void>;
|
|
63
|
-
/** List all document keys with title and chunk count. */
|
|
64
|
-
list(): Promise<KBListEntry[]>;
|
|
65
|
-
/** Create the table and HNSW index. Safe to call multiple times. */
|
|
66
|
-
migrate(): Promise<void>;
|
|
67
|
-
/** Middleware that injects `ctx.kb` with `.search()` method. */
|
|
68
|
-
middleware(): Middleware;
|
|
69
|
-
}
|
|
70
|
-
export declare function knowledgeBase(options: KBOptions): KBModule;
|
package/dist/oauth-client.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { PostgresClient } from './postgres/types.ts';
|
|
2
|
-
import { Router } from './router.ts';
|
|
3
|
-
export interface OAuthProviderConfig {
|
|
4
|
-
clientId: string;
|
|
5
|
-
clientSecret: string;
|
|
6
|
-
scope?: string;
|
|
7
|
-
/** Custom auth URL (overrides built-in provider default). */
|
|
8
|
-
authUrl?: string;
|
|
9
|
-
/** Custom token URL (overrides built-in provider default). */
|
|
10
|
-
tokenUrl?: string;
|
|
11
|
-
/** Custom user info URL (overrides built-in provider default). */
|
|
12
|
-
userUrl?: string;
|
|
13
|
-
/**
|
|
14
|
-
* Custom user parser.
|
|
15
|
-
* Required when any of authUrl/tokenUrl/userUrl is custom.
|
|
16
|
-
* Receives the raw response from userUrl + the access token.
|
|
17
|
-
*/
|
|
18
|
-
parseUser?: (data: any, accessToken: string) => ProviderUser;
|
|
19
|
-
}
|
|
20
|
-
export interface OAuthClientOptions {
|
|
21
|
-
/** Postgres client (required). */
|
|
22
|
-
pg: PostgresClient;
|
|
23
|
-
/** JWT secret — must match user() module's jwtSecret. */
|
|
24
|
-
jwtSecret: string;
|
|
25
|
-
/** JWT expiry (default: '24h'). */
|
|
26
|
-
expiresIn?: string | number;
|
|
27
|
-
/** Where to redirect after successful login (default: '/'). */
|
|
28
|
-
redirectUrl?: string;
|
|
29
|
-
/** Provider configurations. */
|
|
30
|
-
providers: Record<string, OAuthProviderConfig>;
|
|
31
|
-
/** Table name for provider-user links (default: '_auth_providers'). */
|
|
32
|
-
table?: string;
|
|
33
|
-
}
|
|
34
|
-
interface ProviderUser {
|
|
35
|
-
id: string;
|
|
36
|
-
email: string;
|
|
37
|
-
name: string;
|
|
38
|
-
avatarUrl?: string;
|
|
39
|
-
}
|
|
40
|
-
export declare function oauthClient(options: OAuthClientOptions): Router;
|
|
41
|
-
export {};
|
package/dist/preferences.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Context, Middleware } from './types.ts';
|
|
2
|
-
export interface PrefOptions {
|
|
3
|
-
dir?: string;
|
|
4
|
-
locale?: {
|
|
5
|
-
default?: string;
|
|
6
|
-
cookie?: string;
|
|
7
|
-
fromAcceptLanguage?: boolean;
|
|
8
|
-
};
|
|
9
|
-
theme?: {
|
|
10
|
-
default?: string;
|
|
11
|
-
cookie?: string;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export declare function preferences(options: PrefOptions): Middleware<Context, Context & {
|
|
15
|
-
prefs: Record<string, string>;
|
|
16
|
-
t: NonNullable<Context['t']>;
|
|
17
|
-
setPref: NonNullable<Context['setPref']>;
|
|
18
|
-
}>;
|
package/dist/server.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|