weifuwu 0.11.0 → 0.13.0

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/cli.ts ADDED
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+ import { mkdir, writeFile, copyFile, readdir } from 'node:fs/promises'
3
+ import { homedir } from 'node:os'
4
+ import { join, dirname, resolve } from 'node:path'
5
+ import { fileURLToPath } from 'node:url'
6
+
7
+ const __filename = fileURLToPath(import.meta.url)
8
+ const __dirname = dirname(__filename)
9
+
10
+ const pkgRoot = resolve(__dirname, '..')
11
+
12
+ async function cmdSkill() {
13
+ const targetDir = join(homedir(), '.agents', 'skills', 'weifuwu')
14
+ const docsTarget = join(targetDir, 'docs')
15
+
16
+ await mkdir(docsTarget, { recursive: true })
17
+ await copyFile(join(pkgRoot, 'README.md'), join(targetDir, 'SKILL.md'))
18
+
19
+ const docDir = join(pkgRoot, 'docs')
20
+ const entries = await readdir(docDir)
21
+ for (const entry of entries) {
22
+ if (entry.endsWith('.md')) {
23
+ await copyFile(join(docDir, entry), join(docsTarget, entry))
24
+ }
25
+ }
26
+
27
+ console.log('✅ Installed weifuwu skill to ~/.agents/skills/weifuwu/')
28
+ }
29
+
30
+ async function cmdInit(name: string) {
31
+ const targetDir = resolve(process.cwd(), name)
32
+ await mkdir(targetDir, { recursive: true })
33
+
34
+ await writeFile(join(targetDir, 'package.json'), JSON.stringify({
35
+ name,
36
+ type: 'module',
37
+ scripts: {
38
+ dev: 'node --watch app.ts',
39
+ start: 'node app.ts',
40
+ },
41
+ dependencies: {
42
+ weifuwu: 'latest',
43
+ },
44
+ }, null, 2) + '\n')
45
+
46
+ await writeFile(join(targetDir, 'tsconfig.json'), JSON.stringify({
47
+ compilerOptions: {
48
+ target: 'ESNext',
49
+ module: 'NodeNext',
50
+ moduleResolution: 'NodeNext',
51
+ strict: true,
52
+ jsx: 'react-jsx',
53
+ skipLibCheck: true,
54
+ },
55
+ include: ['*.ts'],
56
+ }, null, 2) + '\n')
57
+
58
+ await writeFile(join(targetDir, '.gitignore'), 'node_modules\ndist\n.env\n.sessions\n')
59
+
60
+ await writeFile(join(targetDir, '.env'), 'PORT=3000\n')
61
+
62
+ await writeFile(join(targetDir, 'app.ts'), [
63
+ "import { serve, loadEnv } from 'weifuwu'",
64
+ '',
65
+ "loadEnv()",
66
+ "const port = Number(process.env.PORT) || 3000",
67
+ '',
68
+ "serve((req, ctx) => new Response('Hello, Weifuwu!'), { port })",
69
+ '',
70
+ ].join('\n'))
71
+
72
+ console.log(`✅ Created ${name}/ — cd ${name} && npm install && npm run dev`)
73
+ }
74
+
75
+ const cmd = process.argv[2]
76
+
77
+ if (cmd === 'skill') {
78
+ cmdSkill().catch(console.error)
79
+ } else if (cmd === 'init') {
80
+ const name = process.argv[3]
81
+ if (!name) {
82
+ console.error('Usage: npx weifuwu init <name>')
83
+ process.exit(1)
84
+ }
85
+ cmdInit(name).catch(console.error)
86
+ } else {
87
+ console.log('\nUsage:\n npx weifuwu init <name> Create a new weifuwu project\n npx weifuwu skill Install weifuwu skill to ~/.agents/skills/\n')
88
+ }
package/dist/ai.d.ts CHANGED
@@ -1,19 +1,7 @@
1
1
  import type { Context } from './types.ts';
2
2
  import { Router } from './router.ts';
3
- type StreamTextParams = {
4
- model: unknown;
5
- prompt?: string;
6
- system?: string;
7
- messages?: unknown[];
8
- maxTokens?: number;
9
- temperature?: number;
10
- [key: string]: unknown;
11
- };
12
- export type AIHandler = (req: Request, ctx: Context) => StreamTextParams | Promise<StreamTextParams>;
13
- export declare const _ai: {
14
- streamText: (params: StreamTextParams) => {
15
- toTextStreamResponse: () => Response;
16
- };
17
- };
18
- export declare function ai(handler: AIHandler): Promise<Router>;
19
- export {};
3
+ export type AIHandler = (req: Request, ctx: Context) => Record<string, unknown> | Promise<Record<string, unknown>>;
4
+ export declare const _ai: Record<string, any>;
5
+ export declare function aiStream(handler: AIHandler): Promise<{
6
+ router(): Router;
7
+ }>;
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+
3
+ // cli.ts
4
+ import { mkdir, writeFile, copyFile, readdir } from "node:fs/promises";
5
+ import { homedir } from "node:os";
6
+ import { join, dirname, resolve } from "node:path";
7
+ import { fileURLToPath } from "node:url";
8
+ var __filename = fileURLToPath(import.meta.url);
9
+ var __dirname = dirname(__filename);
10
+ var pkgRoot = resolve(__dirname, "..");
11
+ async function cmdSkill() {
12
+ const targetDir = join(homedir(), ".agents", "skills", "weifuwu");
13
+ const docsTarget = join(targetDir, "docs");
14
+ await mkdir(docsTarget, { recursive: true });
15
+ await copyFile(join(pkgRoot, "README.md"), join(targetDir, "SKILL.md"));
16
+ const docDir = join(pkgRoot, "docs");
17
+ const entries = await readdir(docDir);
18
+ for (const entry of entries) {
19
+ if (entry.endsWith(".md")) {
20
+ await copyFile(join(docDir, entry), join(docsTarget, entry));
21
+ }
22
+ }
23
+ console.log("\u2705 Installed weifuwu skill to ~/.agents/skills/weifuwu/");
24
+ }
25
+ async function cmdInit(name) {
26
+ const targetDir = resolve(process.cwd(), name);
27
+ await mkdir(targetDir, { recursive: true });
28
+ await writeFile(join(targetDir, "package.json"), JSON.stringify({
29
+ name,
30
+ type: "module",
31
+ scripts: {
32
+ dev: "node --watch app.ts",
33
+ start: "node app.ts"
34
+ },
35
+ dependencies: {
36
+ weifuwu: "latest"
37
+ }
38
+ }, null, 2) + "\n");
39
+ await writeFile(join(targetDir, "tsconfig.json"), JSON.stringify({
40
+ compilerOptions: {
41
+ target: "ESNext",
42
+ module: "NodeNext",
43
+ moduleResolution: "NodeNext",
44
+ strict: true,
45
+ jsx: "react-jsx",
46
+ skipLibCheck: true
47
+ },
48
+ include: ["*.ts"]
49
+ }, null, 2) + "\n");
50
+ await writeFile(join(targetDir, ".gitignore"), "node_modules\ndist\n.env\n.sessions\n");
51
+ await writeFile(join(targetDir, ".env"), "PORT=3000\n");
52
+ await writeFile(join(targetDir, "app.ts"), [
53
+ "import { serve, loadEnv } from 'weifuwu'",
54
+ "",
55
+ "loadEnv()",
56
+ "const port = Number(process.env.PORT) || 3000",
57
+ "",
58
+ "serve((req, ctx) => new Response('Hello, Weifuwu!'), { port })",
59
+ ""
60
+ ].join("\n"));
61
+ console.log(`\u2705 Created ${name}/ \u2014 cd ${name} && npm install && npm run dev`);
62
+ }
63
+ var cmd = process.argv[2];
64
+ if (cmd === "skill") {
65
+ cmdSkill().catch(console.error);
66
+ } else if (cmd === "init") {
67
+ const name = process.argv[3];
68
+ if (!name) {
69
+ console.error("Usage: npx weifuwu init <name>");
70
+ process.exit(1);
71
+ }
72
+ cmdInit(name).catch(console.error);
73
+ } else {
74
+ console.log("\nUsage:\n npx weifuwu init <name> Create a new weifuwu project\n npx weifuwu skill Install weifuwu skill to ~/.agents/skills/\n");
75
+ }
@@ -37,7 +37,7 @@ export interface AppStatus {
37
37
  error?: string;
38
38
  }
39
39
  export interface DeployServer {
40
- stop(): Promise<void>;
40
+ close(): Promise<void>;
41
41
  ready: Promise<void>;
42
42
  url: string;
43
43
  apps: {
package/dist/env.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function loadEnv(path?: string): void;
package/dist/graphql.d.ts CHANGED
@@ -9,4 +9,6 @@ export interface GraphQLOptions {
9
9
  graphiql?: boolean;
10
10
  }
11
11
  export type GraphQLHandler = (req: Request, ctx: Context) => GraphQLOptions | Promise<GraphQLOptions>;
12
- export declare function graphql(handler: GraphQLHandler): Router;
12
+ export declare function graphql(handler: GraphQLHandler): {
13
+ router(): Router;
14
+ };
@@ -0,0 +1,6 @@
1
+ import { Router } from './router.ts';
2
+ export interface HealthOptions {
3
+ path?: string;
4
+ check?: () => Promise<void>;
5
+ }
6
+ export declare function health(options?: HealthOptions): Router;
package/dist/i18n.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { Middleware } from './types.ts';
2
+ export interface I18nOptions {
3
+ dir: string;
4
+ defaultLocale?: string;
5
+ }
6
+ export declare function i18n(options: I18nOptions): Middleware;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export type { Context, Handler, Middleware, ErrorHandler } from './types.ts';
2
- export { serve } from './serve.ts';
2
+ export { loadEnv } from './env.ts';
3
+ export { serve, createTestServer } from './serve.ts';
3
4
  export type { ServeOptions, Server } from './serve.ts';
4
5
  export { Router } from './router.ts';
5
6
  export type { WebSocketHandler } from './router.ts';
@@ -21,7 +22,7 @@ export { compress } from './compress.ts';
21
22
  export type { CompressOptions } from './compress.ts';
22
23
  export { graphql } from './graphql.ts';
23
24
  export type { GraphQLOptions, GraphQLHandler } from './graphql.ts';
24
- export { ai } from './ai.ts';
25
+ export { aiStream } from './ai.ts';
25
26
  export type { AIHandler } from './ai.ts';
26
27
  export { runWorkflow } from './ai/workflow.ts';
27
28
  export { postgres } from './postgres/index.ts';
@@ -42,3 +43,9 @@ export { deploy, defineConfig } from './deploy/index.ts';
42
43
  export type { DeployConfig, AppConfig, DeployServer, AppStatus } from './deploy/types.ts';
43
44
  export { opencode } from './opencode/index.ts';
44
45
  export type { OpencodeOptions, OpencodeModule, SkillDef, OpencodePermissions, Session as OpencodeSession } from './opencode/types.ts';
46
+ export { health } from './health.ts';
47
+ export type { HealthOptions } from './health.ts';
48
+ export { i18n } from './i18n.ts';
49
+ export type { I18nOptions } from './i18n.ts';
50
+ export { mailer } from './mailer.ts';
51
+ export type { MailerOptions, MailOptions, Mailer } from './mailer.ts';