weifuwu 0.5.1 → 0.7.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 +411 -6
- package/dist/agent/client.d.ts +2 -0
- package/dist/agent/index.d.ts +2 -0
- package/dist/agent/migrate.d.ts +6 -0
- package/dist/agent/rest.d.ts +12 -0
- package/dist/agent/run.d.ts +14 -0
- package/dist/agent/types.d.ts +51 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +24342 -1927
- package/dist/messager/client.d.ts +2 -0
- package/dist/messager/index.d.ts +2 -0
- package/dist/messager/migrate.d.ts +2 -0
- package/dist/messager/rest.d.ts +9 -0
- package/dist/messager/types.d.ts +53 -0
- package/dist/messager/ws.d.ts +9 -0
- package/dist/queue/index.d.ts +2 -0
- package/dist/queue/types.d.ts +32 -0
- package/dist/redis/index.d.ts +3 -0
- package/dist/redis/types.d.ts +16 -0
- package/dist/tenant/client.d.ts +2 -0
- package/dist/tenant/graphql.d.ts +3 -0
- package/dist/tenant/index.d.ts +2 -0
- package/dist/tenant/migrate.d.ts +6 -0
- package/dist/tenant/rest.d.ts +3 -0
- package/dist/tenant/schema.d.ts +5 -0
- package/dist/tenant/types.d.ts +47 -0
- package/dist/tenant/utils.d.ts +10 -0
- package/dist/user/client.d.ts +2 -0
- package/dist/user/index.d.ts +2 -0
- package/dist/user/migrate.d.ts +6 -0
- package/dist/user/oauth2.d.ts +20 -0
- package/dist/user/types.d.ts +54 -0
- package/dist/workflow/engine.d.ts +1 -1
- package/dist/workflow/llm.d.ts +1 -1
- package/dist/workflow/route.d.ts +1 -1
- package/dist/workflow/types.d.ts +2 -2
- package/package.json +6 -2
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Sql } from 'postgres';
|
|
2
|
+
import { Router } from '../router.ts';
|
|
3
|
+
import type { AgentModule } from '../agent/types.ts';
|
|
4
|
+
interface RestDeps {
|
|
5
|
+
sql: Sql<{}>;
|
|
6
|
+
agents?: AgentModule;
|
|
7
|
+
}
|
|
8
|
+
export declare function buildRouter(deps: RestDeps): Router;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { AgentModule } from '../agent/types.ts';
|
|
2
|
+
export interface MessagerOptions {
|
|
3
|
+
pg: any;
|
|
4
|
+
agents?: AgentModule;
|
|
5
|
+
webhookTimeout?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface Channel {
|
|
8
|
+
id: number;
|
|
9
|
+
tenant_id: string | null;
|
|
10
|
+
name: string;
|
|
11
|
+
type: 'channel' | 'dm';
|
|
12
|
+
created_by: number;
|
|
13
|
+
created_at: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ChannelMember {
|
|
16
|
+
id: number;
|
|
17
|
+
channel_id: number;
|
|
18
|
+
member_id: number;
|
|
19
|
+
member_type: 'user' | 'agent' | 'webhook';
|
|
20
|
+
role: 'admin' | 'member';
|
|
21
|
+
last_read_id: number | null;
|
|
22
|
+
}
|
|
23
|
+
export interface Message {
|
|
24
|
+
id: number;
|
|
25
|
+
channel_id: number;
|
|
26
|
+
sender_id: number;
|
|
27
|
+
sender_type: 'user' | 'agent' | 'webhook';
|
|
28
|
+
type: 'text' | 'image' | 'file' | 'system';
|
|
29
|
+
content: string;
|
|
30
|
+
file_url: string | null;
|
|
31
|
+
file_name: string | null;
|
|
32
|
+
file_size: number | null;
|
|
33
|
+
mime_type: string | null;
|
|
34
|
+
created_at: string;
|
|
35
|
+
}
|
|
36
|
+
export interface MessagerModule {
|
|
37
|
+
migrate: () => Promise<void>;
|
|
38
|
+
router: () => any;
|
|
39
|
+
wsHandler: () => any;
|
|
40
|
+
send: (channelId: number, content: string, opts?: {
|
|
41
|
+
sender_type?: string;
|
|
42
|
+
sender_id?: number;
|
|
43
|
+
type?: string;
|
|
44
|
+
}) => Promise<Message>;
|
|
45
|
+
close: () => Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
export interface WSMessage {
|
|
48
|
+
type: 'message' | 'typing' | 'read';
|
|
49
|
+
channel_id: number;
|
|
50
|
+
content?: string;
|
|
51
|
+
is_typing?: boolean;
|
|
52
|
+
last_message_id?: number;
|
|
53
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Sql } from 'postgres';
|
|
2
|
+
import type { AgentModule } from '../agent/types.ts';
|
|
3
|
+
interface WSDeps {
|
|
4
|
+
sql: Sql<{}>;
|
|
5
|
+
agents?: AgentModule;
|
|
6
|
+
}
|
|
7
|
+
export declare function broadcastToChannel(channelId: number, data: any): void;
|
|
8
|
+
export declare function createWSHandler(deps: WSDeps): any;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Redis } from 'ioredis';
|
|
2
|
+
import type { Context, Handler } from '../types.ts';
|
|
3
|
+
declare module '../types.ts' {
|
|
4
|
+
interface Context {
|
|
5
|
+
queue: Queue;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export interface QueueJob<T = unknown> {
|
|
9
|
+
id: string;
|
|
10
|
+
type: string;
|
|
11
|
+
payload: T;
|
|
12
|
+
createdAt: number;
|
|
13
|
+
runAt: number;
|
|
14
|
+
schedule?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface QueueOptions {
|
|
17
|
+
redis?: Redis;
|
|
18
|
+
url?: string;
|
|
19
|
+
prefix?: string;
|
|
20
|
+
pollInterval?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface Queue {
|
|
23
|
+
(req: Request, ctx: Context, next: Handler): Response | Promise<Response>;
|
|
24
|
+
add<T>(type: string, payload: T, opts?: {
|
|
25
|
+
delay?: number;
|
|
26
|
+
schedule?: string;
|
|
27
|
+
}): Promise<string>;
|
|
28
|
+
process<T>(type: string, handler: (job: QueueJob<T>) => Promise<void>): void;
|
|
29
|
+
run(): Promise<void>;
|
|
30
|
+
stop(): void;
|
|
31
|
+
close(): Promise<void>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Redis, RedisOptions as IORedisOptions } from 'ioredis';
|
|
2
|
+
import type { Context, Handler } from '../types.ts';
|
|
3
|
+
declare module '../types.ts' {
|
|
4
|
+
interface Context {
|
|
5
|
+
redis: Redis;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export type { Redis };
|
|
9
|
+
export type RedisOptions = IORedisOptions & {
|
|
10
|
+
url?: string;
|
|
11
|
+
};
|
|
12
|
+
export interface RedisClient {
|
|
13
|
+
(req: Request, ctx: Context, next: Handler): Response | Promise<Response>;
|
|
14
|
+
redis: Redis;
|
|
15
|
+
close: () => Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { FieldDef } from './types.ts';
|
|
2
|
+
export declare function createTableSQL(tenantId: string, slug: string, fields: FieldDef[]): string;
|
|
3
|
+
export declare function addColumnSQL(tenantId: string, slug: string, field: FieldDef): string;
|
|
4
|
+
export declare function dropTableSQL(tenantId: string, slug: string): string;
|
|
5
|
+
export declare function createIndexesSQL(tenantId: string, slug: string, fields: FieldDef[]): string[];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Context } from '../types.ts';
|
|
2
|
+
declare module '../types.ts' {
|
|
3
|
+
interface Context {
|
|
4
|
+
tenant: TenantContext;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export interface TenantContext {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
role: string;
|
|
11
|
+
}
|
|
12
|
+
export type FieldType = 'string' | 'integer' | 'float' | 'boolean' | 'text' | 'datetime' | 'date' | 'enum' | 'json' | 'vector';
|
|
13
|
+
export interface RelationDef {
|
|
14
|
+
table: string;
|
|
15
|
+
field?: string;
|
|
16
|
+
onDelete?: 'cascade' | 'restrict' | 'setnull';
|
|
17
|
+
}
|
|
18
|
+
export interface FieldDef {
|
|
19
|
+
name: string;
|
|
20
|
+
type: FieldType;
|
|
21
|
+
required?: boolean;
|
|
22
|
+
unique?: boolean;
|
|
23
|
+
index?: boolean | 'desc' | 'gin' | 'hnsw';
|
|
24
|
+
default?: unknown;
|
|
25
|
+
options?: string[];
|
|
26
|
+
dimensions?: number;
|
|
27
|
+
relation?: RelationDef;
|
|
28
|
+
}
|
|
29
|
+
export interface UserTableRow {
|
|
30
|
+
id: number;
|
|
31
|
+
tenant_id: string;
|
|
32
|
+
slug: string;
|
|
33
|
+
label: string;
|
|
34
|
+
fields: FieldDef[];
|
|
35
|
+
created_at: string;
|
|
36
|
+
}
|
|
37
|
+
export interface TenantOptions {
|
|
38
|
+
pg: any;
|
|
39
|
+
usersTable: string;
|
|
40
|
+
}
|
|
41
|
+
export interface TenantModule {
|
|
42
|
+
migrate: () => Promise<void>;
|
|
43
|
+
middleware: () => (req: Request, ctx: Context, next: any) => Promise<Response>;
|
|
44
|
+
router: () => any;
|
|
45
|
+
graphql: () => any;
|
|
46
|
+
close: () => Promise<void>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FieldDef } from './types.ts';
|
|
2
|
+
export declare function internalTableName(tenantId: string, slug: string): string;
|
|
3
|
+
export declare function pascalCase(slug: string): string;
|
|
4
|
+
export declare function sqlTypeForField(field: FieldDef): string;
|
|
5
|
+
export declare function validateSlug(slug: string): string | null;
|
|
6
|
+
export declare function validateFieldDefs(fields: FieldDef[]): string[];
|
|
7
|
+
export declare function formatDefault(field: FieldDef): string;
|
|
8
|
+
export declare function mapFieldToZod(field: FieldDef): string;
|
|
9
|
+
export declare function getRelationFields(fields: FieldDef[]): FieldDef[];
|
|
10
|
+
export declare function findRelation(fields: FieldDef[], targetSlug: string): FieldDef | undefined;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Context } from '../types.ts';
|
|
2
|
+
import type { OAuth2Client } from './types.ts';
|
|
3
|
+
interface OAuth2Deps {
|
|
4
|
+
pg: any;
|
|
5
|
+
usersTable: string;
|
|
6
|
+
jwtSecret: string;
|
|
7
|
+
expiresIn: string | number;
|
|
8
|
+
}
|
|
9
|
+
export declare function createOAuth2Server(deps: OAuth2Deps): {
|
|
10
|
+
authorizeHandler: (req: Request, _ctx: Context) => Promise<Response>;
|
|
11
|
+
consentHandler: (req: Request) => Promise<Response>;
|
|
12
|
+
tokenHandler: (req: Request) => Promise<Response>;
|
|
13
|
+
registerClient: (data: {
|
|
14
|
+
name: string;
|
|
15
|
+
redirectUris: string[];
|
|
16
|
+
}) => Promise<OAuth2Client>;
|
|
17
|
+
getClient: (clientId: string) => Promise<OAuth2Client | null>;
|
|
18
|
+
revokeClient: (clientId: string) => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Middleware } from '../types.ts';
|
|
2
|
+
import type { Router } from '../router.ts';
|
|
3
|
+
export interface UserData {
|
|
4
|
+
id: number;
|
|
5
|
+
email: string;
|
|
6
|
+
name: string;
|
|
7
|
+
role: string;
|
|
8
|
+
created_at: Date;
|
|
9
|
+
updated_at: Date;
|
|
10
|
+
}
|
|
11
|
+
export interface AuthResult {
|
|
12
|
+
user: Omit<UserData, 'password'>;
|
|
13
|
+
token: string;
|
|
14
|
+
}
|
|
15
|
+
export interface OAuth2Client {
|
|
16
|
+
id: number;
|
|
17
|
+
name: string;
|
|
18
|
+
clientId: string;
|
|
19
|
+
clientSecret: string;
|
|
20
|
+
redirectUris: string[];
|
|
21
|
+
scopes: string;
|
|
22
|
+
}
|
|
23
|
+
export interface OAuth2ServerOptions {
|
|
24
|
+
server: true;
|
|
25
|
+
}
|
|
26
|
+
export interface UserOptions {
|
|
27
|
+
pg: any;
|
|
28
|
+
jwtSecret: string;
|
|
29
|
+
table?: string;
|
|
30
|
+
expiresIn?: string | number;
|
|
31
|
+
oauth2?: OAuth2ServerOptions;
|
|
32
|
+
}
|
|
33
|
+
export interface UserModule {
|
|
34
|
+
router: () => Router;
|
|
35
|
+
middleware: () => Middleware;
|
|
36
|
+
migrate: () => Promise<void>;
|
|
37
|
+
register: (data: {
|
|
38
|
+
email: string;
|
|
39
|
+
password: string;
|
|
40
|
+
name: string;
|
|
41
|
+
}) => Promise<AuthResult>;
|
|
42
|
+
login: (data: {
|
|
43
|
+
email: string;
|
|
44
|
+
password: string;
|
|
45
|
+
}) => Promise<AuthResult>;
|
|
46
|
+
verify: (token: string) => Promise<Omit<UserData, 'password'> | null>;
|
|
47
|
+
registerClient: (data: {
|
|
48
|
+
name: string;
|
|
49
|
+
redirectUris: string[];
|
|
50
|
+
}) => Promise<OAuth2Client>;
|
|
51
|
+
getClient: (clientId: string) => Promise<OAuth2Client | null>;
|
|
52
|
+
revokeClient: (clientId: string) => Promise<void>;
|
|
53
|
+
close: () => Promise<void>;
|
|
54
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Tool, WorkflowEngine, SSEManager } from './types.ts';
|
|
2
2
|
import { type LanguageModel } from 'ai';
|
|
3
3
|
export declare function createWorkflowEngine(options: {
|
|
4
|
-
tools: Record<string, Tool
|
|
4
|
+
tools: Record<string, Tool<any, any>>;
|
|
5
5
|
sseManager?: SSEManager;
|
|
6
6
|
model?: LanguageModel;
|
|
7
7
|
}): WorkflowEngine;
|
package/dist/workflow/llm.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Tool, Workflow } from './types.ts';
|
|
2
|
-
export declare function generateWorkflow(goal: string, tools: Record<string, Tool
|
|
2
|
+
export declare function generateWorkflow(goal: string, tools: Record<string, Tool<any, any>>, generateFn: (prompt: {
|
|
3
3
|
system: string;
|
|
4
4
|
messages: {
|
|
5
5
|
role: string;
|
package/dist/workflow/route.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Router } from '../router.ts';
|
|
|
2
2
|
import type { Tool as WfTool } from './types.ts';
|
|
3
3
|
import type { generateText } from 'ai';
|
|
4
4
|
export interface WorkflowOptions {
|
|
5
|
-
tools: Record<string, WfTool
|
|
5
|
+
tools: Record<string, WfTool<any, any>>;
|
|
6
6
|
model?: Parameters<typeof generateText>[0]['model'];
|
|
7
7
|
stream?: boolean;
|
|
8
8
|
}
|
package/dist/workflow/types.d.ts
CHANGED
|
@@ -63,7 +63,7 @@ export interface WorkflowContext {
|
|
|
63
63
|
stepCount: number;
|
|
64
64
|
maxSteps: number;
|
|
65
65
|
input: Record<string, unknown>;
|
|
66
|
-
toolRegistry: Map<string, Tool
|
|
66
|
+
toolRegistry: Map<string, Tool<any, any>>;
|
|
67
67
|
sseManager?: SSEManager;
|
|
68
68
|
workflowId?: string;
|
|
69
69
|
onNodeEvent?: (event: SSEEvent) => void;
|
|
@@ -74,7 +74,7 @@ export interface SSEManager {
|
|
|
74
74
|
close: (workflowId: string) => void;
|
|
75
75
|
}
|
|
76
76
|
export interface EngineOptions {
|
|
77
|
-
tools: Record<string, Tool
|
|
77
|
+
tools: Record<string, Tool<any, any>>;
|
|
78
78
|
model?: unknown;
|
|
79
79
|
sseManager?: SSEManager;
|
|
80
80
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weifuwu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
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",
|
|
@@ -14,15 +14,18 @@
|
|
|
14
14
|
"LICENSE"
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
|
-
"build": "esbuild index.ts --bundle --format=esm --platform=node --outfile=dist/index.js --external:react --external:react-dom --external:esbuild --external:graphql --external:ws --external:zod --external:@graphql-tools/schema --external:ai --external:postgres",
|
|
17
|
+
"build": "esbuild index.ts --bundle --format=esm --platform=node --outfile=dist/index.js --external:react --external:react-dom --external:esbuild --external:graphql --external:ws --external:zod --external:@graphql-tools/schema --external:ai --external:postgres --external:jsonwebtoken",
|
|
18
18
|
"prepublishOnly": "npm run build && tsc --emitDeclarationOnly --outdir dist",
|
|
19
19
|
"test": "node --test 'test/**/*.test.ts'"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@ai-sdk/openai": "^3.0.66",
|
|
22
23
|
"@graphql-tools/schema": "^10",
|
|
23
24
|
"ai": "^6",
|
|
24
25
|
"esbuild": "^0.28.0",
|
|
25
26
|
"graphql": "^16",
|
|
27
|
+
"ioredis": "^5.11.0",
|
|
28
|
+
"jsonwebtoken": "^9.0.3",
|
|
26
29
|
"postgres": "^3.4.9",
|
|
27
30
|
"react": "^19",
|
|
28
31
|
"react-dom": "^19",
|
|
@@ -32,6 +35,7 @@
|
|
|
32
35
|
"type": "module",
|
|
33
36
|
"license": "MIT",
|
|
34
37
|
"devDependencies": {
|
|
38
|
+
"@types/jsonwebtoken": "^9.0.10",
|
|
35
39
|
"@types/react": "^19",
|
|
36
40
|
"@types/react-dom": "^19",
|
|
37
41
|
"@types/ws": "^8.18.1",
|