princejs 1.6.2 → 1.6.3
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 +1 -2
- package/dist/helpers.js +1 -43
- package/package.json +2 -2
package/Readme.md
CHANGED
|
@@ -127,13 +127,12 @@ app
|
|
|
127
127
|
## New Tree-Shakable Features
|
|
128
128
|
|
|
129
129
|
```ts
|
|
130
|
-
import { cache, email,
|
|
130
|
+
import { cache, email, upload } from "princejs/helpers";
|
|
131
131
|
import { cron, openapi } from "princejs/scheduler";
|
|
132
132
|
```
|
|
133
133
|
|
|
134
134
|
* `cache(60)(handler)` — In-memory cache
|
|
135
135
|
* `email(to, subject, html)` — Resend.com
|
|
136
|
-
* `ai(prompt)` — Grok / OpenAI / Hugging Face
|
|
137
136
|
* `upload()` — 1-line file upload
|
|
138
137
|
* `cron("*/2 * * * *", task)` — Cron support
|
|
139
138
|
* `openapi({ title, version })` — Auto docs
|
package/dist/helpers.js
CHANGED
|
@@ -20,47 +20,6 @@ var email = async (to, subject, html) => {
|
|
|
20
20
|
body: JSON.stringify({ from: "no-reply@princejs.dev", to, subject, html })
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
|
-
var DEFAULTS = {
|
|
24
|
-
openai: { url: "https://api.openai.com/v1/chat/completions", model: "gpt-4o-mini" },
|
|
25
|
-
grok: { url: "https://api.x.ai/v1/chat/completions", model: "grok-beta" },
|
|
26
|
-
huggingface: { url: "" }
|
|
27
|
-
};
|
|
28
|
-
var ai = async (prompt, opts = {}) => {
|
|
29
|
-
const provider = opts.provider || "openai";
|
|
30
|
-
const config = DEFAULTS[provider];
|
|
31
|
-
if (provider === "huggingface" && !opts.model) {
|
|
32
|
-
throw new Error("Hugging Face requires 'model' option (e.g. meta-llama/Llama-3.3-70B-Instruct)");
|
|
33
|
-
}
|
|
34
|
-
const apiKey = opts.apiKey || Bun.env[`${provider.toUpperCase()}_API_KEY`];
|
|
35
|
-
if (!apiKey) {
|
|
36
|
-
throw new Error(`Missing ${provider.toUpperCase()}_API_KEY in environment`);
|
|
37
|
-
}
|
|
38
|
-
const url = provider === "huggingface" ? `https://api-inference.huggingface.co/models/${opts.model}` : config.url;
|
|
39
|
-
const headers = {
|
|
40
|
-
"Content-Type": "application/json",
|
|
41
|
-
Authorization: `Bearer ${apiKey}`
|
|
42
|
-
};
|
|
43
|
-
const body = provider === "huggingface" ? { inputs: prompt, parameters: { temperature: opts.temperature ?? 0.7 } } : {
|
|
44
|
-
model: opts.model || config.model,
|
|
45
|
-
messages: [{ role: "user", content: prompt }],
|
|
46
|
-
temperature: opts.temperature ?? 0.7,
|
|
47
|
-
max_tokens: 1024
|
|
48
|
-
};
|
|
49
|
-
const res = await fetch(url, {
|
|
50
|
-
method: "POST",
|
|
51
|
-
headers,
|
|
52
|
-
body: JSON.stringify(body)
|
|
53
|
-
});
|
|
54
|
-
if (!res.ok) {
|
|
55
|
-
const err = await res.text();
|
|
56
|
-
throw new Error(`${provider} API error ${res.status}: ${err}`);
|
|
57
|
-
}
|
|
58
|
-
const data = await res.json();
|
|
59
|
-
if (provider === "huggingface") {
|
|
60
|
-
return (data[0]?.generated_text || "").trim();
|
|
61
|
-
}
|
|
62
|
-
return data.choices?.[0]?.message?.content?.trim() || "No response";
|
|
63
|
-
};
|
|
64
23
|
var upload = () => {
|
|
65
24
|
return async (req) => {
|
|
66
25
|
const form = await req.formData();
|
|
@@ -71,6 +30,5 @@ var upload = () => {
|
|
|
71
30
|
export {
|
|
72
31
|
upload,
|
|
73
32
|
email,
|
|
74
|
-
cache
|
|
75
|
-
ai
|
|
33
|
+
cache
|
|
76
34
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "princejs",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.3",
|
|
4
4
|
"description": "An easy and fast backend framework — by a 13yo developer, for developers.",
|
|
5
5
|
"main": "dist/prince.js",
|
|
6
6
|
"types": "dist/prince.d.ts",
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/bun": "^1.3.2",
|
|
64
64
|
"bun-types": "latest",
|
|
65
|
-
"typescript": "^5.9.3",
|
|
66
65
|
"fast-jwt": "^5.0.0",
|
|
66
|
+
"typescript": "^5.9.3",
|
|
67
67
|
"zod": "^4.1.12"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|