weifuwu 0.23.0 → 0.23.2

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.
@@ -1,8 +1,8 @@
1
- // cli/template/ui/app/page.tsx
1
+ // ui/app/page.tsx
2
2
  import { useState } from "react";
3
3
  import { useWebsocket, useLoaderData, useLocale, useTheme } from "weifuwu/react";
4
4
 
5
- // cli/template/ui/components/Greeting.tsx
5
+ // ui/components/Greeting.tsx
6
6
  import { jsxs } from "react/jsx-runtime";
7
7
  function Greeting({ name }) {
8
8
  return /* @__PURE__ */ jsxs("span", { className: "text-red-500 font-bold", children: [
@@ -11,7 +11,7 @@ function Greeting({ name }) {
11
11
  ] });
12
12
  }
13
13
 
14
- // cli/template/ui/app/page.tsx
14
+ // ui/app/page.tsx
15
15
  import { jsx, jsxs as jsxs2 } from "react/jsx-runtime";
16
16
  function Home() {
17
17
  const [input, setInput] = useState("");
@@ -0,0 +1,14 @@
1
+ // ui/app/layout.tsx
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ function RootLayout({ children }) {
4
+ return /* @__PURE__ */ jsxs("html", { lang: "en", children: [
5
+ /* @__PURE__ */ jsxs("head", { children: [
6
+ /* @__PURE__ */ jsx("meta", { charSet: "utf-8" }),
7
+ /* @__PURE__ */ jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1" })
8
+ ] }),
9
+ /* @__PURE__ */ jsx("body", { children: /* @__PURE__ */ jsx("main", { children }) })
10
+ ] });
11
+ }
12
+ export {
13
+ RootLayout as default
14
+ };
@@ -1,6 +1,6 @@
1
1
  declare function applyTheme(theme: string): void;
2
2
  export declare function useTheme(): {
3
- theme: any;
3
+ theme: string;
4
4
  resolvedTheme: string;
5
5
  setTheme: (t: string) => Promise<void>;
6
6
  };
package/dist/index.js CHANGED
@@ -851,7 +851,7 @@ function sendHttpResponseOnSocket(socket, response) {
851
851
 
852
852
  // tsx-context.ts
853
853
  import { useSyncExternalStore, createContext } from "react";
854
- var DEFAULT_CTX = { params: {}, query: {}, parsed: {}, loaderData: {}, env: {}, user: {} };
854
+ var DEFAULT_CTX = { params: {}, query: {}, parsed: {}, loaderData: {}, env: {}, user: {}, flash: {} };
855
855
  var KEY = "__WEIFUWU_CTX_STORE";
856
856
  function getStore() {
857
857
  if (typeof globalThis !== "undefined" && globalThis[KEY]) {
@@ -2441,7 +2441,7 @@ function aiProvider(options) {
2441
2441
  return result.embedding;
2442
2442
  },
2443
2443
  async embedMany(texts) {
2444
- const result = await aiEmbedMany({ model: this.embeddingModel(), value: texts });
2444
+ const result = await aiEmbedMany({ model: this.embeddingModel(), values: texts });
2445
2445
  return result.embeddings;
2446
2446
  },
2447
2447
  generateText(params) {
@@ -3993,7 +3993,7 @@ function attachCron(q, handlers) {
3993
3993
  function createMemoryQueue(opts) {
3994
3994
  const pollInterval = opts?.pollInterval ?? 200;
3995
3995
  const handlers = /* @__PURE__ */ new Map();
3996
- const jobs = [];
3996
+ const pending = [];
3997
3997
  const failed = [];
3998
3998
  const MAX_FAILED = 1e3;
3999
3999
  let running = false;
@@ -4004,8 +4004,8 @@ function createMemoryQueue(opts) {
4004
4004
  const MAX_CONCURRENT = 16;
4005
4005
  function insertJob(job) {
4006
4006
  let i = 0;
4007
- while (i < jobs.length && jobs[i].runAt <= job.runAt) i++;
4008
- jobs.splice(i, 0, job);
4007
+ while (i < pending.length && pending[i].runAt <= job.runAt) i++;
4008
+ pending.splice(i, 0, job);
4009
4009
  }
4010
4010
  async function execute(job, handler) {
4011
4011
  inflight++;
@@ -4030,8 +4030,8 @@ function createMemoryQueue(opts) {
4030
4030
  async function poll() {
4031
4031
  if (!running) return;
4032
4032
  const now = Date.now();
4033
- while (running && inflight < MAX_CONCURRENT && jobs.length > 0 && jobs[0].runAt <= now) {
4034
- const job = jobs.shift();
4033
+ while (running && inflight < MAX_CONCURRENT && pending.length > 0 && pending[0].runAt <= now) {
4034
+ const job = pending.shift();
4035
4035
  const handler = handlers.get(job.type);
4036
4036
  if (handler) execute(job, handler);
4037
4037
  }
@@ -4081,8 +4081,8 @@ function createMemoryQueue(opts) {
4081
4081
  mw.stop();
4082
4082
  while (inflight > 0) await new Promise((r) => setTimeout(r, 50));
4083
4083
  };
4084
- mw.jobs = async function jobs2(limit) {
4085
- return jobs2.slice(0, limit ?? 50);
4084
+ mw.jobs = async function(limit) {
4085
+ return pending.slice(0, limit ?? 50);
4086
4086
  };
4087
4087
  mw.failedJobs = async function failedJobs(limit) {
4088
4088
  return failed.slice(0, limit ?? 50);
@@ -5626,7 +5626,7 @@ function createRunner(deps) {
5626
5626
  }
5627
5627
  }
5628
5628
  async function addKnowledge(agentId, title, content) {
5629
- const chunks = chunkContent(content);
5629
+ const chunks = chunkContent(content, 1024, 128);
5630
5630
  const [first] = chunks;
5631
5631
  const embedding = await provider.embed(first);
5632
5632
  const vec = `[${embedding.join(",")}]`;
@@ -7400,12 +7400,28 @@ async function init() {
7400
7400
  const app = createElement(TsxContext.Provider, { value: _ctx },
7401
7401
  createElement(Page));
7402
7402
  ${isDev2 ? `
7403
+ // Stable proxy \u2014 same function ref = React preserves fiber + useState state across HMR
7404
+ const _pageImpl = { current: Page };
7405
+ const _pageProxy = new Proxy(function __wfw_page(){}, {
7406
+ apply(_target, _thisArg, args) {
7407
+ return Reflect.apply(_pageImpl.current, _thisArg, args);
7408
+ },
7409
+ });
7410
+
7403
7411
  const reactRoot = createRoot(_root);
7404
- reactRoot.render(app);
7412
+ let _tick = 0;
7413
+ function renderPage() {
7414
+ reactRoot.render(createElement(TsxContext.Provider, { value: _ctx },
7415
+ createElement(_pageProxy, { __t: _tick })));
7416
+ }
7417
+ renderPage();
7418
+
7405
7419
  window.__WFW_REFRESH = async (NewComponent) => {
7406
7420
  const store = globalThis.__WEIFUWU_CTX_STORE?._ctx || _ctx;
7421
+ _pageImpl.current = NewComponent;
7422
+ _tick++;
7407
7423
  reactRoot.render(createElement(TsxContext.Provider, { value: store },
7408
- createElement(NewComponent)));
7424
+ createElement(_pageProxy, { __t: _tick })));
7409
7425
  };
7410
7426
  ` : `
7411
7427
  hydrateRoot(_root, app);
package/dist/react.js CHANGED
@@ -155,7 +155,7 @@ async function runInterceptors(url) {
155
155
 
156
156
  // tsx-context.ts
157
157
  import { useSyncExternalStore, createContext } from "react";
158
- var DEFAULT_CTX = { params: {}, query: {}, parsed: {}, loaderData: {}, env: {}, user: {} };
158
+ var DEFAULT_CTX = { params: {}, query: {}, parsed: {}, loaderData: {}, env: {}, user: {}, flash: {} };
159
159
  var KEY = "__WEIFUWU_CTX_STORE";
160
160
  function getStore() {
161
161
  if (typeof globalThis !== "undefined" && globalThis[KEY]) {
@@ -5,11 +5,19 @@ export interface PageContext {
5
5
  id?: string;
6
6
  };
7
7
  parsed: Record<string, unknown>;
8
- theme?: string;
8
+ theme?: {
9
+ value: string;
10
+ set?: (value: string, loc?: string) => Response;
11
+ };
9
12
  i18n?: {
10
13
  locale: string;
14
+ messages?: Record<string, unknown>;
11
15
  t: (key: string, params?: Record<string, string>, fallback?: string) => string;
12
16
  };
17
+ flash?: {
18
+ value?: string;
19
+ set?: (data: any, loc?: string) => Response;
20
+ };
13
21
  loaderData: Record<string, unknown>;
14
22
  env: Record<string, string>;
15
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weifuwu",
3
- "version": "0.23.0",
3
+ "version": "0.23.2",
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",