weifuwu 0.6.0 → 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.
@@ -0,0 +1,2 @@
1
+ import type { MessagerOptions, MessagerModule } from './types.ts';
2
+ export declare function messager(options: MessagerOptions): MessagerModule;
@@ -0,0 +1,2 @@
1
+ export { messager } from './client.ts';
2
+ export type { MessagerOptions, MessagerModule, Channel, ChannelMember, Message } from './types.ts';
@@ -0,0 +1,2 @@
1
+ import type { Sql } from 'postgres';
2
+ export declare function migrate(sql: Sql<{}>): Promise<void>;
@@ -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,2 @@
1
+ import type { TenantOptions, TenantModule } from './types.ts';
2
+ export declare function tenant(options: TenantOptions): TenantModule;
@@ -0,0 +1,3 @@
1
+ import type { Sql } from 'postgres';
2
+ import { Router } from '../router.ts';
3
+ export declare function buildGraphQLHandler(sql: Sql<{}>): Router;
@@ -0,0 +1,2 @@
1
+ export { tenant } from './client.ts';
2
+ export type { TenantOptions, TenantModule, TenantContext, FieldDef, FieldType, RelationDef, UserTableRow } from './types.ts';
@@ -0,0 +1,6 @@
1
+ import type { Sql } from 'postgres';
2
+ export interface MigrateOptions {
3
+ sql: Sql<{}>;
4
+ usersTable: string;
5
+ }
6
+ export declare function migrate(opts: MigrateOptions): Promise<void>;
@@ -0,0 +1,3 @@
1
+ import type { Sql } from 'postgres';
2
+ import { Router } from '../router.ts';
3
+ export declare function buildRouter(sql: Sql<{}>, usersTable: string): Router;
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weifuwu",
3
- "version": "0.6.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",
@@ -19,6 +19,7 @@
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",