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/README.md +98 -1362
- package/cli.ts +88 -0
- package/dist/ai.d.ts +5 -17
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +75 -0
- package/dist/deploy/types.d.ts +1 -1
- package/dist/env.d.ts +1 -0
- package/dist/graphql.d.ts +3 -1
- package/dist/health.d.ts +6 -0
- package/dist/i18n.d.ts +6 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.js +221 -67
- package/dist/mailer.d.ts +20 -0
- package/dist/serve.d.ts +4 -0
- package/dist/types.d.ts +2 -0
- package/docs/agent.md +44 -0
- package/docs/ai.md +93 -0
- package/docs/extra.md +67 -0
- package/docs/graphql.md +61 -0
- package/docs/messager.md +48 -0
- package/docs/middleware.md +131 -0
- package/docs/opencode.md +252 -0
- package/docs/postgres.md +162 -0
- package/docs/router.md +80 -0
- package/docs/tenant.md +174 -0
- package/docs/tsx.md +199 -0
- package/docs/user.md +167 -0
- package/package.json +9 -2
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
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
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
|
+
}
|
package/dist/deploy/types.d.ts
CHANGED
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):
|
|
12
|
+
export declare function graphql(handler: GraphQLHandler): {
|
|
13
|
+
router(): Router;
|
|
14
|
+
};
|
package/dist/health.d.ts
ADDED
package/dist/i18n.d.ts
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type { Context, Handler, Middleware, ErrorHandler } from './types.ts';
|
|
2
|
-
export {
|
|
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 {
|
|
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';
|