weifuwu 0.30.0 → 0.30.1
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/package.json +1 -1
- package/dist/ai/provider.d.ts +0 -45
- package/dist/ai/stream.d.ts +0 -13
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -178
- package/dist/react/index.js +0 -2573
package/package.json
CHANGED
package/dist/ai/provider.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { Context, Middleware } from '../types.ts';
|
|
2
|
-
import { generateText as aiGenerateText, streamText as aiStreamText, type LanguageModel, type EmbeddingModel } from 'ai';
|
|
3
|
-
declare module '../types.ts' {
|
|
4
|
-
interface Context {
|
|
5
|
-
ai: AIProvider;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
export interface AIProviderInjected {
|
|
9
|
-
ai: AIProvider;
|
|
10
|
-
}
|
|
11
|
-
export interface AIProviderOptions {
|
|
12
|
-
/** API base URL (default: OPENAI_BASE_URL env or http://localhost:11434/v1). */
|
|
13
|
-
baseURL?: string;
|
|
14
|
-
/** API key (default: OPENAI_API_KEY env or 'ollama'). */
|
|
15
|
-
apiKey?: string;
|
|
16
|
-
/** Chat model name (default: OPENAI_MODEL env or 'qwen3:0.6b'). */
|
|
17
|
-
model?: string;
|
|
18
|
-
/** Embedding model name (default: OPENAI_EMBEDDING_MODEL env or 'qwen3-embedding:0.6b'). */
|
|
19
|
-
embeddingModel?: string;
|
|
20
|
-
/** Vector dimension (default: EMBEDDING_DIMENSION env or 1024). */
|
|
21
|
-
embeddingDimension?: number;
|
|
22
|
-
}
|
|
23
|
-
export interface AIProvider {
|
|
24
|
-
/** Get the language model. Caches by default; pass a name to override. */
|
|
25
|
-
model(name?: string): LanguageModel;
|
|
26
|
-
/** Get the embedding model. Caches by default; pass a name to override. */
|
|
27
|
-
embeddingModel(name?: string): EmbeddingModel;
|
|
28
|
-
/** Embed a single text string into a vector. */
|
|
29
|
-
embed(text: string): Promise<number[]>;
|
|
30
|
-
/** Embed multiple text strings in batch. */
|
|
31
|
-
embedMany(texts: string[]): Promise<number[][]>;
|
|
32
|
-
/** The configured vector dimension. */
|
|
33
|
-
readonly dimension: number;
|
|
34
|
-
/**
|
|
35
|
-
* Generate text using the configured model.
|
|
36
|
-
* All options are passed through to the AI SDK's `generateText`, with `model` auto-injected.
|
|
37
|
-
*/
|
|
38
|
-
generateText(params: Omit<Parameters<typeof aiGenerateText>[0], 'model'>): ReturnType<typeof aiGenerateText>;
|
|
39
|
-
/**
|
|
40
|
-
* Stream text using the configured model.
|
|
41
|
-
* All options are passed through to the AI SDK's `streamText`, with `model` auto-injected.
|
|
42
|
-
*/
|
|
43
|
-
streamText(params: Omit<Parameters<typeof aiStreamText>[0], 'model'>): ReturnType<typeof aiStreamText>;
|
|
44
|
-
}
|
|
45
|
-
export declare function aiProvider(options?: AIProviderOptions): Middleware<Context, Context & AIProviderInjected> & AIProvider;
|
package/dist/ai/stream.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Context } from '../types.ts';
|
|
2
|
-
import { Router } from '../core/router.ts';
|
|
3
|
-
import type { AIProvider } from './provider.ts';
|
|
4
|
-
export type AIHandler = (req: Request, ctx: Context) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
5
|
-
export declare const _ai: Record<string, any>;
|
|
6
|
-
/**
|
|
7
|
-
* Create a streaming AI endpoint.
|
|
8
|
-
*
|
|
9
|
-
* @param handler - Returns options for `streamText` or `streamObject` (if `schema` is present).
|
|
10
|
-
* @param provider - Optional AI provider. If provided and the handler does not return a `model`,
|
|
11
|
-
* `provider.model()` is used as the default.
|
|
12
|
-
*/
|
|
13
|
-
export declare function aiStream(handler: AIHandler, provider?: AIProvider): Promise<Router>;
|
package/dist/cli.d.ts
DELETED
package/dist/cli.js
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// cli.ts
|
|
4
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
5
|
-
import { existsSync } from "node:fs";
|
|
6
|
-
import { execSync } from "node:child_process";
|
|
7
|
-
import { join, dirname, resolve } from "node:path";
|
|
8
|
-
import { fileURLToPath } from "node:url";
|
|
9
|
-
import { parseArgs } from "node:util";
|
|
10
|
-
var __filename = fileURLToPath(import.meta.url);
|
|
11
|
-
var __dirname = dirname(__filename);
|
|
12
|
-
var pkgRoot = existsSync(join(__dirname, "package.json")) ? __dirname : resolve(__dirname, "..");
|
|
13
|
-
async function readPkg() {
|
|
14
|
-
return JSON.parse(
|
|
15
|
-
await import("node:fs/promises").then(
|
|
16
|
-
(fs) => fs.readFile(join(pkgRoot, "package.json"), "utf-8")
|
|
17
|
-
)
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
async function cmdVersion() {
|
|
21
|
-
const pkg = await readPkg();
|
|
22
|
-
console.log(pkg.version);
|
|
23
|
-
}
|
|
24
|
-
async function cmdInit(name, opts) {
|
|
25
|
-
const targetDir = resolve(process.cwd(), name);
|
|
26
|
-
if (existsSync(targetDir)) {
|
|
27
|
-
console.error(`Directory ${name} already exists.`);
|
|
28
|
-
process.exit(1);
|
|
29
|
-
}
|
|
30
|
-
const pkg = await readPkg();
|
|
31
|
-
const typesNodeVersion = pkg.devDependencies?.["@types/node"] || "^22";
|
|
32
|
-
if (opts.ssr) {
|
|
33
|
-
await generateReactSsr(targetDir, name, pkg.version, typesNodeVersion, opts.skipInstall);
|
|
34
|
-
} else {
|
|
35
|
-
await generateMinimal(targetDir, name, pkg.version, typesNodeVersion, opts.skipInstall);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
async function generateMinimal(targetDir, name, version, typesNodeVersion, skipInstall) {
|
|
39
|
-
await mkdir(targetDir, { recursive: true });
|
|
40
|
-
await writeFile(
|
|
41
|
-
join(targetDir, "app.ts"),
|
|
42
|
-
[
|
|
43
|
-
`import { Router } from 'weifuwu'`,
|
|
44
|
-
``,
|
|
45
|
-
`export const app = new Router()`,
|
|
46
|
-
``,
|
|
47
|
-
`app.get('/', () => new Response('Hello from ${name}!'))`,
|
|
48
|
-
`app.get('/api/ping', () => Response.json({ pong: true, time: new Date().toISOString() }))`,
|
|
49
|
-
``
|
|
50
|
-
].join("\n")
|
|
51
|
-
);
|
|
52
|
-
await writeFile(
|
|
53
|
-
join(targetDir, "index.ts"),
|
|
54
|
-
[
|
|
55
|
-
`import { loadEnv, serve } from 'weifuwu'`,
|
|
56
|
-
`import { app } from './app.ts'`,
|
|
57
|
-
``,
|
|
58
|
-
`loadEnv()`,
|
|
59
|
-
`const port = Number(process.env.PORT) || 3000`,
|
|
60
|
-
`serve(app.handler(), { port })`,
|
|
61
|
-
``
|
|
62
|
-
].join("\n")
|
|
63
|
-
);
|
|
64
|
-
await writePackageJson(targetDir, name, version, typesNodeVersion, {});
|
|
65
|
-
await writeCommonFiles(targetDir);
|
|
66
|
-
await finishInit(targetDir, skipInstall);
|
|
67
|
-
}
|
|
68
|
-
async function generateReactSsr(targetDir, name, version, typesNodeVersion, skipInstall) {
|
|
69
|
-
const templateDir = join(pkgRoot, "cli", "template", "react");
|
|
70
|
-
await copyRecursive(templateDir, targetDir);
|
|
71
|
-
await writePackageJson(targetDir, name, version, typesNodeVersion, {
|
|
72
|
-
dependencies: {
|
|
73
|
-
react: "^19",
|
|
74
|
-
"react-dom": "^19",
|
|
75
|
-
"@tailwindcss/postcss": "^4",
|
|
76
|
-
tailwindcss: "^4",
|
|
77
|
-
postcss: "^8"
|
|
78
|
-
},
|
|
79
|
-
devDependencies: {
|
|
80
|
-
"@types/react": "^19",
|
|
81
|
-
"@types/react-dom": "^19",
|
|
82
|
-
esbuild: "^0.28"
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
await writeFile(join(targetDir, ".gitignore"), "node_modules\n.env\n.weifuwu\n");
|
|
86
|
-
await finishInit(targetDir, skipInstall);
|
|
87
|
-
}
|
|
88
|
-
async function copyRecursive(src, dest) {
|
|
89
|
-
const { readdir, stat, copyFile } = await import("node:fs/promises");
|
|
90
|
-
const entries = await readdir(src, { withFileTypes: true });
|
|
91
|
-
for (const entry of entries) {
|
|
92
|
-
const srcPath = join(src, entry.name);
|
|
93
|
-
const destPath = join(dest, entry.name);
|
|
94
|
-
if (entry.isDirectory()) {
|
|
95
|
-
await mkdir(destPath, { recursive: true });
|
|
96
|
-
await copyRecursive(srcPath, destPath);
|
|
97
|
-
} else if (entry.isFile()) {
|
|
98
|
-
await copyFile(srcPath, destPath);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
async function writePackageJson(targetDir, name, version, typesNodeVersion, extra) {
|
|
103
|
-
const pkg = {
|
|
104
|
-
name,
|
|
105
|
-
type: "module",
|
|
106
|
-
scripts: {
|
|
107
|
-
dev: "node --watch index.ts",
|
|
108
|
-
start: "node index.ts"
|
|
109
|
-
},
|
|
110
|
-
dependencies: {
|
|
111
|
-
weifuwu: "^" + version
|
|
112
|
-
},
|
|
113
|
-
devDependencies: {
|
|
114
|
-
"@types/node": typesNodeVersion
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
if (extra) {
|
|
118
|
-
if (extra.dependencies) {
|
|
119
|
-
Object.assign(pkg.dependencies, extra.dependencies);
|
|
120
|
-
}
|
|
121
|
-
if (extra.devDependencies) {
|
|
122
|
-
Object.assign(pkg.devDependencies, extra.devDependencies);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
await writeFile(join(targetDir, "package.json"), JSON.stringify(pkg, null, 2) + "\n");
|
|
126
|
-
}
|
|
127
|
-
async function writeCommonFiles(targetDir) {
|
|
128
|
-
await writeFile(join(targetDir, ".gitignore"), "node_modules\n.env\n.weifuwu\n");
|
|
129
|
-
await writeFile(join(targetDir, ".env"), "PORT=3000\n");
|
|
130
|
-
}
|
|
131
|
-
async function finishInit(targetDir, skipInstall) {
|
|
132
|
-
if (!skipInstall) {
|
|
133
|
-
console.log("\nInstalling dependencies...");
|
|
134
|
-
execSync("npm install", { cwd: targetDir, stdio: "inherit" });
|
|
135
|
-
}
|
|
136
|
-
console.log(`
|
|
137
|
-
\u2705 Created ${targetDir.split("/").pop()}/`);
|
|
138
|
-
console.log(` cd ${targetDir.split("/").pop()}`);
|
|
139
|
-
if (skipInstall) console.log(` npm install`);
|
|
140
|
-
console.log(` npm run dev`);
|
|
141
|
-
}
|
|
142
|
-
var cmd = process.argv[2];
|
|
143
|
-
var HELP = `
|
|
144
|
-
weifuwu \u2014 Web-standard HTTP microframework for Node.js
|
|
145
|
-
|
|
146
|
-
Usage:
|
|
147
|
-
npx weifuwu init <name> Create a new API project
|
|
148
|
-
npx weifuwu init <name> --ssr Create a React SSR project
|
|
149
|
-
npx weifuwu init <name> --skip-install Skip npm install
|
|
150
|
-
npx weifuwu version Print version
|
|
151
|
-
`;
|
|
152
|
-
if (cmd === "version" || cmd === "-v" || cmd === "--version") {
|
|
153
|
-
cmdVersion().catch(console.error);
|
|
154
|
-
} else if (cmd === "init") {
|
|
155
|
-
const { values, positionals } = parseArgs({
|
|
156
|
-
args: process.argv.slice(3),
|
|
157
|
-
options: {
|
|
158
|
-
"skip-install": { type: "boolean" },
|
|
159
|
-
"ssr": { type: "boolean" },
|
|
160
|
-
"react": { type: "boolean" }
|
|
161
|
-
},
|
|
162
|
-
strict: false,
|
|
163
|
-
allowPositionals: true
|
|
164
|
-
});
|
|
165
|
-
const name = positionals[0];
|
|
166
|
-
if (!name) {
|
|
167
|
-
console.error("Usage: npx weifuwu init <name> [--ssr] [--skip-install]");
|
|
168
|
-
process.exit(1);
|
|
169
|
-
}
|
|
170
|
-
cmdInit(name, {
|
|
171
|
-
skipInstall: !!values["skip-install"],
|
|
172
|
-
ssr: !!(values["ssr"] || values["react"])
|
|
173
|
-
}).catch(
|
|
174
|
-
console.error
|
|
175
|
-
);
|
|
176
|
-
} else {
|
|
177
|
-
console.log(HELP);
|
|
178
|
-
}
|