weifuwu 0.25.2 → 0.27.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.
Files changed (208) hide show
  1. package/README.md +291 -2489
  2. package/ai/provider.ts +129 -0
  3. package/ai/stream.ts +63 -0
  4. package/cli.ts +55 -257
  5. package/core/cookie.ts +114 -0
  6. package/core/env.ts +142 -0
  7. package/core/logger.ts +72 -0
  8. package/core/router.ts +795 -0
  9. package/core/serve.ts +294 -0
  10. package/core/sse.ts +85 -0
  11. package/core/trace.ts +146 -0
  12. package/graphql.ts +267 -0
  13. package/hub.ts +133 -0
  14. package/index.ts +71 -0
  15. package/mailer.ts +81 -0
  16. package/middleware/compress.ts +103 -0
  17. package/middleware/cors.ts +81 -0
  18. package/middleware/csrf.ts +112 -0
  19. package/middleware/flash.ts +144 -0
  20. package/middleware/health.ts +44 -0
  21. package/middleware/helmet.ts +98 -0
  22. package/middleware/i18n.ts +175 -0
  23. package/middleware/rate-limit.ts +167 -0
  24. package/middleware/request-id.ts +60 -0
  25. package/middleware/static.ts +149 -0
  26. package/middleware/theme.ts +84 -0
  27. package/middleware/upload.ts +168 -0
  28. package/middleware/validate.ts +186 -0
  29. package/package.json +14 -36
  30. package/postgres/client.ts +132 -0
  31. package/postgres/index.ts +4 -0
  32. package/postgres/module.ts +37 -0
  33. package/postgres/schema/columns.ts +186 -0
  34. package/postgres/schema/index.ts +36 -0
  35. package/postgres/schema/sql.ts +39 -0
  36. package/postgres/schema/table.ts +548 -0
  37. package/postgres/schema/where.ts +99 -0
  38. package/postgres/types.ts +48 -0
  39. package/queue/cron.ts +90 -0
  40. package/queue/index.ts +654 -0
  41. package/queue/types.ts +60 -0
  42. package/redis/client.ts +24 -0
  43. package/{dist/redis/index.d.ts → redis/index.ts} +2 -2
  44. package/redis/types.ts +28 -0
  45. package/types.ts +78 -0
  46. package/cli/template/app.ts +0 -22
  47. package/cli/template/index.ts +0 -10
  48. package/cli/template/locales/en.json +0 -13
  49. package/cli/template/locales/zh-CN.json +0 -13
  50. package/cli/template/locales/zh-TW.json +0 -13
  51. package/cli/template/locales/zh.json +0 -13
  52. package/cli/template/ui/app/globals.css +0 -2
  53. package/cli/template/ui/app/layout.tsx +0 -15
  54. package/cli/template/ui/app/page.tsx +0 -124
  55. package/cli/template/ui/components/Greeting.tsx +0 -3
  56. package/dist/agent/client.d.ts +0 -2
  57. package/dist/agent/index.d.ts +0 -2
  58. package/dist/agent/rest.d.ts +0 -14
  59. package/dist/agent/run.d.ts +0 -19
  60. package/dist/agent/types.d.ts +0 -55
  61. package/dist/ai/provider.d.ts +0 -45
  62. package/dist/ai/utils.d.ts +0 -5
  63. package/dist/ai/workflow.d.ts +0 -17
  64. package/dist/ai-sdk.d.ts +0 -2
  65. package/dist/ai.d.ts +0 -13
  66. package/dist/analytics.d.ts +0 -45
  67. package/dist/auth.d.ts +0 -22
  68. package/dist/cache.d.ts +0 -74
  69. package/dist/cli.d.ts +0 -2
  70. package/dist/cli.js +0 -302
  71. package/dist/client-locale.d.ts +0 -25
  72. package/dist/client-pref.d.ts +0 -3
  73. package/dist/client-router.d.ts +0 -300
  74. package/dist/client-state.d.ts +0 -22
  75. package/dist/client-theme.d.ts +0 -36
  76. package/dist/compile.d.ts +0 -15
  77. package/dist/compress.d.ts +0 -20
  78. package/dist/cookie.d.ts +0 -36
  79. package/dist/cors.d.ts +0 -25
  80. package/dist/cron-utils.d.ts +0 -73
  81. package/dist/csrf.d.ts +0 -47
  82. package/dist/deploy/config.d.ts +0 -2
  83. package/dist/deploy/gateway.d.ts +0 -2
  84. package/dist/deploy/index.d.ts +0 -4
  85. package/dist/deploy/manager.d.ts +0 -16
  86. package/dist/deploy/process.d.ts +0 -14
  87. package/dist/deploy/types.d.ts +0 -53
  88. package/dist/env.d.ts +0 -69
  89. package/dist/error-boundary.d.ts +0 -2
  90. package/dist/flash.d.ts +0 -90
  91. package/dist/fts.d.ts +0 -36
  92. package/dist/graphql.d.ts +0 -16
  93. package/dist/head.d.ts +0 -6
  94. package/dist/health.d.ts +0 -24
  95. package/dist/helmet.d.ts +0 -33
  96. package/dist/html-shell.d.ts +0 -1
  97. package/dist/hub.d.ts +0 -37
  98. package/dist/i18n.d.ts +0 -39
  99. package/dist/iii/client.d.ts +0 -2
  100. package/dist/iii/index.d.ts +0 -4
  101. package/dist/iii/register-worker.d.ts +0 -9
  102. package/dist/iii/rest.d.ts +0 -3
  103. package/dist/iii/stream.d.ts +0 -82
  104. package/dist/iii/types.d.ts +0 -121
  105. package/dist/iii/worker.d.ts +0 -2
  106. package/dist/iii/ws.d.ts +0 -22
  107. package/dist/index.d.ts +0 -101
  108. package/dist/index.js +0 -12752
  109. package/dist/kb/index.d.ts +0 -3
  110. package/dist/kb/types.d.ts +0 -72
  111. package/dist/layout.d.ts +0 -2
  112. package/dist/live.d.ts +0 -7
  113. package/dist/logdb/client.d.ts +0 -2
  114. package/dist/logdb/index.d.ts +0 -2
  115. package/dist/logdb/rest.d.ts +0 -5
  116. package/dist/logdb/types.d.ts +0 -27
  117. package/dist/logger.d.ts +0 -16
  118. package/dist/mailer.d.ts +0 -51
  119. package/dist/mcp.d.ts +0 -34
  120. package/dist/messager/agent.d.ts +0 -11
  121. package/dist/messager/client.d.ts +0 -2
  122. package/dist/messager/index.d.ts +0 -2
  123. package/dist/messager/rest.d.ts +0 -15
  124. package/dist/messager/types.d.ts +0 -57
  125. package/dist/messager/ws.d.ts +0 -14
  126. package/dist/module-server.d.ts +0 -9
  127. package/dist/not-found.d.ts +0 -2
  128. package/dist/notifier/client.d.ts +0 -2
  129. package/dist/notifier/index.d.ts +0 -2
  130. package/dist/notifier/types.d.ts +0 -105
  131. package/dist/opencode/client.d.ts +0 -2
  132. package/dist/opencode/index.d.ts +0 -2
  133. package/dist/opencode/permissions.d.ts +0 -5
  134. package/dist/opencode/prompt.d.ts +0 -8
  135. package/dist/opencode/rest.d.ts +0 -16
  136. package/dist/opencode/run.d.ts +0 -13
  137. package/dist/opencode/session.d.ts +0 -26
  138. package/dist/opencode/skills.d.ts +0 -4
  139. package/dist/opencode/tools/bash.d.ts +0 -6
  140. package/dist/opencode/tools/edit.d.ts +0 -19
  141. package/dist/opencode/tools/glob.d.ts +0 -9
  142. package/dist/opencode/tools/grep.d.ts +0 -17
  143. package/dist/opencode/tools/index.d.ts +0 -12
  144. package/dist/opencode/tools/question.d.ts +0 -5
  145. package/dist/opencode/tools/read.d.ts +0 -16
  146. package/dist/opencode/tools/skill.d.ts +0 -18
  147. package/dist/opencode/tools/web.d.ts +0 -18
  148. package/dist/opencode/tools/write.d.ts +0 -13
  149. package/dist/opencode/types.d.ts +0 -90
  150. package/dist/opencode/ws.d.ts +0 -21
  151. package/dist/permissions.d.ts +0 -51
  152. package/dist/postgres/client.d.ts +0 -4
  153. package/dist/postgres/index.d.ts +0 -4
  154. package/dist/postgres/module.d.ts +0 -17
  155. package/dist/postgres/schema/columns.d.ts +0 -99
  156. package/dist/postgres/schema/index.d.ts +0 -6
  157. package/dist/postgres/schema/sql.d.ts +0 -22
  158. package/dist/postgres/schema/table.d.ts +0 -141
  159. package/dist/postgres/schema/where.d.ts +0 -29
  160. package/dist/postgres/types.d.ts +0 -50
  161. package/dist/queue/index.d.ts +0 -2
  162. package/dist/queue/types.d.ts +0 -62
  163. package/dist/rate-limit.d.ts +0 -45
  164. package/dist/react.d.ts +0 -14
  165. package/dist/react.js +0 -751
  166. package/dist/redis/client.d.ts +0 -2
  167. package/dist/redis/types.d.ts +0 -18
  168. package/dist/request-id.d.ts +0 -40
  169. package/dist/router.d.ts +0 -73
  170. package/dist/s3.d.ts +0 -68
  171. package/dist/seo.d.ts +0 -104
  172. package/dist/serve.d.ts +0 -38
  173. package/dist/server-registry.d.ts +0 -10
  174. package/dist/session.d.ts +0 -117
  175. package/dist/sse.d.ts +0 -47
  176. package/dist/ssr-entries.d.ts +0 -4
  177. package/dist/ssr.d.ts +0 -11
  178. package/dist/static.d.ts +0 -23
  179. package/dist/stream.d.ts +0 -24
  180. package/dist/tailwind.d.ts +0 -15
  181. package/dist/tenant/client.d.ts +0 -2
  182. package/dist/tenant/graphql.d.ts +0 -3
  183. package/dist/tenant/index.d.ts +0 -2
  184. package/dist/tenant/rest.d.ts +0 -3
  185. package/dist/tenant/schema.d.ts +0 -5
  186. package/dist/tenant/types.d.ts +0 -48
  187. package/dist/tenant/utils.d.ts +0 -9
  188. package/dist/test-utils.d.ts +0 -194
  189. package/dist/theme.d.ts +0 -31
  190. package/dist/trace.d.ts +0 -95
  191. package/dist/tsx-context.d.ts +0 -32
  192. package/dist/types.d.ts +0 -47
  193. package/dist/upload.d.ts +0 -55
  194. package/dist/use-action.d.ts +0 -42
  195. package/dist/use-agent-stream.d.ts +0 -49
  196. package/dist/use-flash-message.d.ts +0 -17
  197. package/dist/use-websocket.d.ts +0 -42
  198. package/dist/user/client.d.ts +0 -30
  199. package/dist/user/index.d.ts +0 -2
  200. package/dist/user/oauth-login.d.ts +0 -21
  201. package/dist/user/oauth2.d.ts +0 -31
  202. package/dist/user/types.d.ts +0 -178
  203. package/dist/validate.d.ts +0 -32
  204. package/dist/vendor.d.ts +0 -7
  205. package/dist/webhook.d.ts +0 -79
  206. package/opencode/ui/app/globals.css +0 -1
  207. package/opencode/ui/app/layout.tsx +0 -13
  208. package/opencode/ui/app/page.tsx +0 -523
@@ -0,0 +1,48 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import type { SqlClient, Context, Middleware, Closeable } from '../types.ts'
3
+ import type { ColumnBuilder, BoundTable, Table } from './schema/index.ts'
4
+
5
+ declare module '../types.ts' {
6
+ interface Context {
7
+ sql: SqlClient
8
+ }
9
+ }
10
+
11
+ export interface PostgresInjected {
12
+ sql: SqlClient
13
+ }
14
+
15
+ export interface PostgresOptions {
16
+ connection?: string | Record<string, unknown>
17
+ signal?: AbortSignal
18
+ closeTimeout?: number
19
+ max?: number
20
+ ssl?: boolean | Record<string, unknown>
21
+ idle_timeout?: number
22
+ connect_timeout?: number
23
+ /** Per-statement timeout in ms. Set to 0 to disable. Default: 30_000. */
24
+ statementTimeout?: number
25
+ /** Called after every query completes. Receives query text, duration in ms, and row count. */
26
+ onQuery?: (query: string, durationMs: number, rowCount: number) => void
27
+ }
28
+
29
+ export interface PostgresClient extends Middleware<Context, Context & PostgresInjected>, Closeable {
30
+ sql: SqlClient
31
+ /** Creates the migration tracking table (_weifuwu_migrations). Called once at startup. */
32
+ migrate: () => Promise<void>
33
+ /** Record that a module's migration has been applied (idempotent). */
34
+ markMigrated: (moduleName: string) => Promise<void>
35
+ /** Check whether a module has already been migrated. */
36
+ isMigrated: (moduleName: string) => Promise<boolean>
37
+ table: {
38
+ <R extends Record<string, unknown>>(
39
+ tableName: string,
40
+ builders: { [K in keyof R]: ColumnBuilder<R[K]> },
41
+ ): BoundTable<R>
42
+ <R extends Record<string, unknown>>(schema: Table<R>): BoundTable<R>
43
+ }
44
+ transaction: <T>(fn: (sql: any) => Promise<T>, retryOpts?: { maxRetries?: number }) => Promise<T>
45
+ /** Snapshot of connection pool state: active, idle, waiting, max connections. */
46
+ poolStats: () => { active: number; idle: number; waiting: number; max: number }
47
+ close: () => Promise<void>
48
+ }
package/queue/cron.ts ADDED
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Cron expression parsing utilities (moved from cron-utils.ts).
3
+ * Used internally by queue for scheduled job execution.
4
+ *
5
+ * All functions operate in local timezone.
6
+ */
7
+
8
+ function parseField(field: string, min: number, max: number): Set<number> {
9
+ const values = new Set<number>()
10
+
11
+ for (const part of field.split(',')) {
12
+ if (part === '*') {
13
+ for (let i = min; i <= max; i++) values.add(i)
14
+ } else if (part.includes('/')) {
15
+ const [range, stepStr] = part.split('/')
16
+ const step = parseInt(stepStr, 10)
17
+ if (isNaN(step) || step < 1) throw new Error(`Invalid cron step: ${part}`)
18
+ let start = min
19
+ let end = max
20
+ if (range !== '*') {
21
+ const rangeParts = range.split('-')
22
+ start = parseInt(rangeParts[0], 10)
23
+ end = rangeParts.length > 1 ? parseInt(rangeParts[1], 10) : max
24
+ }
25
+ for (let i = start; i <= end; i += step) values.add(i)
26
+ } else if (part.includes('-')) {
27
+ const [s, e] = part.split('-').map(Number)
28
+ if (isNaN(s) || isNaN(e)) throw new Error(`Invalid cron range: ${part}`)
29
+ for (let i = s; i <= e; i++) values.add(i)
30
+ } else {
31
+ const val = parseInt(part, 10)
32
+ if (isNaN(val)) throw new Error(`Invalid cron value: ${part}`)
33
+ values.add(val)
34
+ }
35
+ }
36
+
37
+ const result = new Set<number>()
38
+ for (const v of values) {
39
+ if (v >= min && v <= max) result.add(v)
40
+ }
41
+ return result
42
+ }
43
+
44
+ const FIELD_RANGES: [number, number][] = [
45
+ [0, 59],
46
+ [0, 23],
47
+ [1, 31],
48
+ [1, 12],
49
+ [0, 6],
50
+ ]
51
+
52
+ export function parsePattern(pattern: string): Set<number>[] {
53
+ const fields = pattern.trim().split(/\s+/)
54
+ if (fields.length !== 5) {
55
+ throw new Error(`Invalid cron pattern "${pattern}": expected 5 fields, got ${fields.length}`)
56
+ }
57
+ return fields.map((f, i) => parseField(f, FIELD_RANGES[i][0], FIELD_RANGES[i][1]))
58
+ }
59
+
60
+ export function matches(fields: Set<number>[], date: Date): boolean {
61
+ return (
62
+ fields[0].has(date.getMinutes()) &&
63
+ fields[1].has(date.getHours()) &&
64
+ fields[2].has(date.getDate()) &&
65
+ fields[3].has(date.getMonth() + 1) &&
66
+ fields[4].has(date.getDay())
67
+ )
68
+ }
69
+
70
+ export function cronNext(expr: string, from: Date = new Date()): number {
71
+ const fields = parsePattern(expr)
72
+
73
+ const candidate = new Date(from.getTime() + 60_000)
74
+ candidate.setSeconds(0, 0)
75
+
76
+ for (let i = 0; i < 525600; i++) {
77
+ if (
78
+ fields[4].has(candidate.getDay()) &&
79
+ fields[3].has(candidate.getMonth() + 1) &&
80
+ fields[2].has(candidate.getDate()) &&
81
+ fields[1].has(candidate.getHours()) &&
82
+ fields[0].has(candidate.getMinutes())
83
+ ) {
84
+ return candidate.getTime()
85
+ }
86
+ candidate.setTime(candidate.getTime() + 60_000)
87
+ }
88
+
89
+ throw new Error(`No future date found for cron expression "${expr}"`)
90
+ }