@seip/bluebird-js 0.1.4 → 0.1.6

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,98 +1,98 @@
1
- export const route = "/about";
2
- export const cache = 300;
3
- export const layout = "main";
4
- export const seo = true;
5
-
6
- export const head = () => ({
7
- title: "About Us — Blue Bird Framework",
8
- description: "Learn about the architecture and design philosophy of Blue Bird.",
9
- });
10
-
11
- /**
12
- * About page React JSX view module.
13
- */
14
- export default function AboutView() {
15
- return (
16
- <>
17
- <section className="py-10 md:py-14 border-b border-slate-800/80">
18
- <h1 className="mt-3 text-3xl md:text-5xl font-extrabold tracking-tight bg-gradient-to-r from-sky-400 via-blue-500 to-indigo-400 bg-clip-text text-transparent">
19
- About Blue Bird
20
- </h1>
21
- <p className="mt-4 text-base md:text-lg text-slate-300 max-w-2xl leading-relaxed">
22
- Built for performance, simplicity, and raw speed with native React JSX SSR.
23
- </p>
24
- </section>
25
-
26
- <article className="mt-8 rounded-2xl border border-slate-800 bg-slate-900/60 p-6 md:p-8">
27
- <header>
28
- <h2 className="text-xl font-bold text-sky-400 mb-3">Our Philosophy</h2>
29
- </header>
30
- <p className="text-slate-300 leading-relaxed">
31
- Blue Bird was born out of a desire for a clean, performance-first approach to web development. We
32
- believe in harnessing the raw power of Express.js and modern Node.js ESM, stripping away unnecessary bloat, and
33
- providing developers with a robust foundation that just works.
34
- </p>
35
- <p className="text-slate-300 leading-relaxed mt-4">
36
- By combining server-rendered React JSX views with selective client hydration, anti-CLS skeletons, and native browser View Transitions,
37
- Blue Bird eliminates heavy compilation pipelines and excessive memory usage.
38
- </p>
39
- </article>
40
-
41
- <div className="mt-8">
42
- <h2 className="text-xl font-bold text-slate-100 mb-4">Why Blue Bird?</h2>
43
-
44
- <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
45
- <div className="space-y-4">
46
- <details
47
- className="rounded-xl border border-slate-800 bg-slate-900/50 p-4 open:border-slate-700 transition-colors"
48
- open
49
- >
50
- <summary className="font-semibold text-slate-200 cursor-pointer select-none">
51
- Production Ready
52
- </summary>
53
- <p className="mt-2 text-sm text-slate-400 leading-relaxed">
54
- Seamless transition from development to production with PM2 clustering, systemd, and high performance multi-level caching.
55
- </p>
56
- </details>
57
- <details
58
- className="rounded-xl border border-slate-800 bg-slate-900/50 p-4 open:border-slate-700 transition-colors"
59
- open
60
- >
61
- <summary className="font-semibold text-slate-200 cursor-pointer select-none">
62
- Military Grade Security
63
- </summary>
64
- <p className="mt-2 text-sm text-slate-400 leading-relaxed">
65
- Built-in AES-256-GCM JWT encryption, secure HttpOnly cookie sessions, security headers, and rate limiting.
66
- </p>
67
- </details>
68
- </div>
69
- <div className="space-y-4">
70
- <details
71
- className="rounded-xl border border-slate-800 bg-slate-900/50 p-4 open:border-slate-700 transition-colors"
72
- open
73
- >
74
- <summary className="font-semibold text-slate-200 cursor-pointer select-none">
75
- Multi-Tier Caching
76
- </summary>
77
- <p className="mt-2 text-sm text-slate-400 leading-relaxed">
78
- In-memory LRU, Redis clustering, and persistent file caching for maximum requests per second with minimum CPU usage.
79
- </p>
80
- </details>
81
- <details
82
- className="rounded-xl border border-slate-800 bg-slate-900/50 p-4 open:border-slate-700 transition-colors"
83
- open
84
- >
85
- <summary className="font-semibold text-slate-200 cursor-pointer select-none">
86
- React JSX SSR &amp; Auto-Routes
87
- </summary>
88
- <p className="mt-2 text-sm text-slate-400 leading-relaxed">
89
- Write clean JSX components with declarative route exports (<code>cache</code>, <code>middlewares</code>, <code>layout</code>) and zero build steps.
90
- </p>
91
- </details>
92
- </div>
93
- </div>
94
- </div>
95
- </>
96
- );
97
- }
98
-
1
+ export const route = "/about";
2
+ export const cache = 300;
3
+ export const layout = "main";
4
+ export const seo = true;
5
+
6
+ export const head = () => ({
7
+ title: "About Us — Blue Bird Framework",
8
+ description: "Learn about the architecture and design philosophy of Blue Bird.",
9
+ });
10
+
11
+ /**
12
+ * About page React JSX view module.
13
+ */
14
+ export default function AboutView() {
15
+ return (
16
+ <>
17
+ <section className="py-10 md:py-14 border-b border-slate-800/80">
18
+ <h1 className="mt-3 text-3xl md:text-5xl font-extrabold tracking-tight bg-gradient-to-r from-sky-400 via-blue-500 to-indigo-400 bg-clip-text text-transparent">
19
+ About Blue Bird
20
+ </h1>
21
+ <p className="mt-4 text-base md:text-lg text-slate-300 max-w-2xl leading-relaxed">
22
+ Built for performance, simplicity, and raw speed with native React JSX SSR.
23
+ </p>
24
+ </section>
25
+
26
+ <article className="mt-8 rounded-2xl border border-slate-800 bg-slate-900/60 p-6 md:p-8">
27
+ <header>
28
+ <h2 className="text-xl font-bold text-sky-400 mb-3">Our Philosophy</h2>
29
+ </header>
30
+ <p className="text-slate-300 leading-relaxed">
31
+ Blue Bird was born out of a desire for a clean, performance-first approach to web development. We
32
+ believe in harnessing the raw power of Express.js and modern Node.js ESM, stripping away unnecessary bloat, and
33
+ providing developers with a robust foundation that just works.
34
+ </p>
35
+ <p className="text-slate-300 leading-relaxed mt-4">
36
+ By combining server-rendered React JSX views with selective client hydration, anti-CLS skeletons, and native browser View Transitions,
37
+ Blue Bird eliminates heavy compilation pipelines and excessive memory usage.
38
+ </p>
39
+ </article>
40
+
41
+ <div className="mt-8">
42
+ <h2 className="text-xl font-bold text-slate-100 mb-4">Why Blue Bird?</h2>
43
+
44
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
45
+ <div className="space-y-4">
46
+ <details
47
+ className="rounded-xl border border-slate-800 bg-slate-900/50 p-4 open:border-slate-700 transition-colors"
48
+ open
49
+ >
50
+ <summary className="font-semibold text-slate-200 cursor-pointer select-none">
51
+ Production Ready
52
+ </summary>
53
+ <p className="mt-2 text-sm text-slate-400 leading-relaxed">
54
+ Seamless transition from development to production with PM2 clustering, systemd, and high performance multi-level caching.
55
+ </p>
56
+ </details>
57
+ <details
58
+ className="rounded-xl border border-slate-800 bg-slate-900/50 p-4 open:border-slate-700 transition-colors"
59
+ open
60
+ >
61
+ <summary className="font-semibold text-slate-200 cursor-pointer select-none">
62
+ Military Grade Security
63
+ </summary>
64
+ <p className="mt-2 text-sm text-slate-400 leading-relaxed">
65
+ Built-in AES-256-GCM JWT encryption, secure HttpOnly cookie sessions, security headers, and rate limiting.
66
+ </p>
67
+ </details>
68
+ </div>
69
+ <div className="space-y-4">
70
+ <details
71
+ className="rounded-xl border border-slate-800 bg-slate-900/50 p-4 open:border-slate-700 transition-colors"
72
+ open
73
+ >
74
+ <summary className="font-semibold text-slate-200 cursor-pointer select-none">
75
+ Multi-Tier Caching
76
+ </summary>
77
+ <p className="mt-2 text-sm text-slate-400 leading-relaxed">
78
+ In-memory LRU, Redis clustering, and persistent file caching for maximum requests per second with minimum CPU usage.
79
+ </p>
80
+ </details>
81
+ <details
82
+ className="rounded-xl border border-slate-800 bg-slate-900/50 p-4 open:border-slate-700 transition-colors"
83
+ open
84
+ >
85
+ <summary className="font-semibold text-slate-200 cursor-pointer select-none">
86
+ React JSX SSR &amp; Auto-Routes
87
+ </summary>
88
+ <p className="mt-2 text-sm text-slate-400 leading-relaxed">
89
+ Write clean JSX components with declarative route exports (<code>cache</code>, <code>middlewares</code>, <code>layout</code>) and zero build steps.
90
+ </p>
91
+ </details>
92
+ </div>
93
+ </div>
94
+ </div>
95
+ </>
96
+ );
97
+ }
98
+
@@ -1,9 +1,9 @@
1
- import { useState, useEffect } from "@seip/bluebird-js/core/jsx.js";
1
+ import { useState, useEffect, useAction } from "@seip/bluebird-js/core/jsx.js";
2
2
  import { html } from "@seip/bluebird-js/core/html.js";
3
3
 
4
4
  /**
5
5
  * Reusable reactive Client Counter component for `<Client component={LiveCounter} ... />`.
6
- * Powered by Bluebird's zero-build client runtime with hooks (useState, useEffect, html).
6
+ * Powered by Bluebird's zero-build client runtime with hooks (useState, useEffect, useAction, html).
7
7
  *
8
8
  * @param {Object} props
9
9
  * @param {number} [props.initial=7]
@@ -12,15 +12,8 @@ import { html } from "@seip/bluebird-js/core/html.js";
12
12
  */
13
13
  export default function LiveCounter({ initial = 7, label = "Client Component Counter" }) {
14
14
  const [count, setCount] = useState(Number(initial) || 0);
15
-
16
- useEffect(() => {
17
- const badge = document.getElementById("header-counter-badge");
18
- if (badge) badge.textContent = String(count);
19
- }, [count]);
20
-
21
- const syncServer = async () => {
22
- if (window.Bluebird?.action) {
23
- const res = await window.Bluebird.action("syncCount", { count });
15
+ const [sync, isPending] = useAction("syncCount", {
16
+ onSuccess(res) {
24
17
  if (res?.data?.message && typeof window.toast === "function") {
25
18
  window.toast({
26
19
  title: "Server Action Executed",
@@ -28,13 +21,18 @@ export default function LiveCounter({ initial = 7, label = "Client Component Cou
28
21
  type: "success",
29
22
  });
30
23
  }
31
- }
32
- };
24
+ },
25
+ });
26
+
27
+ useEffect(() => {
28
+ const badge = document.getElementById("header-counter-badge");
29
+ if (badge) badge.textContent = String(count);
30
+ }, [count]);
33
31
 
34
32
  return html`
35
33
  <div class="h-14 rounded-xl border border-slate-800 bg-slate-950/90 px-4 flex items-center justify-between">
36
34
  <div class="flex items-center gap-2.5">
37
- <span class="w-2 h-2 rounded-full bg-emerald-400 animate-pulse"></span>
35
+ <span class="w-2 h-2 rounded-full ${isPending ? "bg-amber-400" : "bg-emerald-400"} animate-pulse"></span>
38
36
  <span class="text-xs font-medium text-slate-300">${label}:</span>
39
37
  <strong data-counter-val class="font-mono text-base text-sky-400">${count}</strong>
40
38
  </div>
@@ -55,10 +53,11 @@ export default function LiveCounter({ initial = 7, label = "Client Component Cou
55
53
  </button>
56
54
  <button
57
55
  type="button"
58
- onClick=${syncServer}
59
- class="px-2.5 py-1 rounded-lg border border-emerald-500/30 bg-emerald-500/15 hover:bg-emerald-500/25 text-xs font-semibold text-emerald-300 transition-colors"
56
+ onClick=${() => sync({ count })}
57
+ disabled=${isPending}
58
+ class="px-2.5 py-1 rounded-lg border border-emerald-500/30 bg-emerald-500/15 hover:bg-emerald-500/25 text-xs font-semibold text-emerald-300 transition-colors disabled:opacity-50"
60
59
  >
61
- Sync Action
60
+ ${isPending ? "Syncing..." : "Sync Action"}
62
61
  </button>
63
62
  </div>
64
63
  </div>
package/core/ai.d.ts ADDED
@@ -0,0 +1,151 @@
1
+ import type { Request, Response, NextFunction, RequestHandler } from "express";
2
+
3
+ export interface AIOptions {
4
+ provider?: "deepseek" | "gemini" | "openai" | "custom";
5
+ model?: string;
6
+ apiKey?: string;
7
+ baseURL?: string;
8
+ temperature?: number;
9
+ thinking?: boolean | { type: string };
10
+ reasoningEffort?: "low" | "medium" | "high";
11
+ rateLimit?: number | { minute?: number; day?: number } | { max: number; windowMs: number };
12
+ rateWindow?: number;
13
+ cacheTtl?: number | boolean;
14
+ system?: string;
15
+ }
16
+
17
+ export interface AIAskOptions {
18
+ data?: Record<string, any>;
19
+ sensitiveKeys?: string[];
20
+ request?: Request | any;
21
+ req?: Request | any;
22
+ user?: string;
23
+ system?: string;
24
+ json?: boolean;
25
+ schema?: Record<string, any>;
26
+ temperature?: number;
27
+ model?: string;
28
+ provider?: "deepseek" | "gemini" | "openai" | "custom";
29
+ apiKey?: string;
30
+ baseURL?: string;
31
+ cache?: number | boolean;
32
+ thinking?: boolean | { type: string };
33
+ reasoningEffort?: "low" | "medium" | "high";
34
+ maxTokens?: number;
35
+ rateLimit?: number | { minute?: number; day?: number } | { max: number; windowMs: number };
36
+ }
37
+
38
+ export interface AIUsage {
39
+ prompt_tokens?: number;
40
+ completion_tokens?: number;
41
+ total_tokens?: number;
42
+ [key: string]: any;
43
+ }
44
+
45
+ export interface AIResult<T = any> {
46
+ success: boolean;
47
+ text?: string;
48
+ rawText?: string;
49
+ parsed?: T;
50
+ valid?: boolean;
51
+ errors?: any;
52
+ reasoning?: string | null;
53
+ cached?: boolean;
54
+ latency?: number;
55
+ provider?: string;
56
+ model?: string;
57
+ usage?: AIUsage;
58
+ maskedKeys?: string[];
59
+ error?: string;
60
+ message?: string;
61
+ retryAfter?: number;
62
+ }
63
+
64
+ export interface AIStreamChunk {
65
+ text: string;
66
+ done: boolean;
67
+ }
68
+
69
+ export interface MaskResult {
70
+ maskedPrompt: string;
71
+ maskedData: Record<string, any> | null;
72
+ tokenMap: Record<string, string>;
73
+ reverseTokenMap: Record<string, string>;
74
+ }
75
+
76
+ export declare function getClientIp(req: Request | any): string;
77
+
78
+ export declare function maskSensitiveData(
79
+ prompt?: string,
80
+ data?: Record<string, any> | null,
81
+ sensitiveKeys?: string[]
82
+ ): MaskResult;
83
+
84
+ export declare function unmaskSensitiveData(
85
+ text?: string,
86
+ reverseTokenMap?: Record<string, string>
87
+ ): string;
88
+
89
+ export declare function extractJsonString(text?: string): string;
90
+
91
+ export declare class AI {
92
+ provider: string;
93
+ model: string;
94
+ apiKey: string;
95
+ baseURL: string;
96
+ temperature: number;
97
+ thinking: boolean | Object;
98
+ reasoningEffort?: "low" | "medium" | "high";
99
+ rateLimit?: any;
100
+ rateWindow: number;
101
+ cacheTtl: number | boolean;
102
+ system: string;
103
+
104
+ constructor(options?: AIOptions);
105
+
106
+ checkRateLimit(
107
+ clientKey: string,
108
+ limitConfig?: any
109
+ ): { allowed: boolean; retryAfter: number };
110
+
111
+ ask<T = any>(prompt: string | any[], options?: AIAskOptions): Promise<AIResult<T>>;
112
+
113
+ askStream(
114
+ prompt: string | any[],
115
+ options?: AIAskOptions
116
+ ): AsyncGenerator<AIStreamChunk, void, unknown>;
117
+
118
+ pipe(
119
+ res: Response | any,
120
+ prompt: string | any[],
121
+ options?: AIAskOptions & { sse?: boolean }
122
+ ): Promise<void>;
123
+
124
+ stream(
125
+ res: Response | any,
126
+ prompt: string | any[],
127
+ options?: AIAskOptions & { sse?: boolean }
128
+ ): Promise<void>;
129
+
130
+ middleware(options?: { rateLimit?: any; message?: string }): RequestHandler;
131
+
132
+ protect(options?: { rateLimit?: any; message?: string }): RequestHandler;
133
+
134
+ static getClientIp(req: Request | any): string;
135
+
136
+ static mask(
137
+ prompt: string,
138
+ data?: Record<string, any> | null,
139
+ sensitiveKeys?: string[]
140
+ ): MaskResult;
141
+
142
+ static unmask(text: string, reverseTokenMap: Record<string, string>): string;
143
+
144
+ static protect(options?: AIOptions & { message?: string }): RequestHandler;
145
+
146
+ static resetRateLimits(): void;
147
+ }
148
+
149
+ export declare const ai: AI;
150
+ export default AI;
151
+