weifuwu 0.18.2 → 0.18.4
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/cli.ts +10 -101
- package/dist/cli.js +7 -95
- package/dist/dist/agent/client.d.ts +2 -0
- package/dist/dist/agent/index.d.ts +2 -0
- package/dist/dist/agent/migrate.d.ts +6 -0
- package/dist/dist/agent/rest.d.ts +13 -0
- package/dist/dist/agent/run.d.ts +17 -0
- package/dist/dist/agent/types.d.ts +51 -0
- package/dist/dist/ai/workflow.d.ts +14 -0
- package/dist/dist/analytics.d.ts +15 -0
- package/dist/dist/client-locale.d.ts +5 -0
- package/dist/dist/client-pref.d.ts +3 -0
- package/dist/dist/client-state.d.ts +22 -0
- package/dist/dist/client-theme.d.ts +7 -0
- package/dist/dist/compress.d.ts +6 -0
- package/dist/dist/cookie.d.ts +12 -0
- package/dist/dist/deploy/config.d.ts +2 -0
- package/dist/dist/deploy/gateway.d.ts +2 -0
- package/dist/dist/deploy/index.d.ts +4 -0
- package/dist/dist/deploy/manager.d.ts +16 -0
- package/dist/dist/deploy/process.d.ts +14 -0
- package/dist/dist/deploy/types.d.ts +62 -0
- package/dist/dist/head.d.ts +6 -0
- package/dist/dist/helmet.d.ts +18 -0
- package/dist/dist/iii/client.d.ts +2 -0
- package/dist/dist/iii/index.d.ts +4 -0
- package/dist/dist/iii/register-worker.d.ts +10 -0
- package/dist/dist/iii/rest.d.ts +3 -0
- package/dist/dist/iii/stream.d.ts +82 -0
- package/dist/dist/iii/types.d.ts +133 -0
- package/dist/dist/iii/worker.d.ts +2 -0
- package/dist/dist/iii/ws.d.ts +29 -0
- package/dist/dist/index.js +8180 -0
- package/dist/dist/messager/agent.d.ts +6 -0
- package/dist/dist/messager/client.d.ts +2 -0
- package/dist/dist/messager/index.d.ts +2 -0
- package/dist/dist/messager/migrate.d.ts +2 -0
- package/dist/dist/messager/rest.d.ts +15 -0
- package/dist/dist/messager/types.d.ts +56 -0
- package/dist/dist/messager/ws.d.ts +14 -0
- package/dist/dist/preferences.d.ts +14 -0
- package/dist/dist/react.d.ts +12 -0
- package/dist/dist/react.js +637 -0
- package/dist/dist/request-id.d.ts +6 -0
- package/dist/dist/seo.d.ts +39 -0
- package/dist/dist/ssr/compile.d.ts +2 -0
- package/dist/{ssr → dist/ssr}/index.d.ts +1 -1
- package/dist/{ssr → dist/ssr}/index.js +372 -375
- package/dist/dist/ssr/ssr.d.ts +2 -0
- package/dist/dist/tenant/client.d.ts +2 -0
- package/dist/dist/tenant/graphql.d.ts +3 -0
- package/dist/dist/tenant/index.d.ts +2 -0
- package/dist/dist/tenant/migrate.d.ts +6 -0
- package/dist/dist/tenant/rest.d.ts +3 -0
- package/dist/dist/tenant/schema.d.ts +5 -0
- package/dist/dist/tenant/types.d.ts +48 -0
- package/dist/dist/tenant/utils.d.ts +10 -0
- package/dist/dist/types.d.ts +19 -0
- package/dist/dist/use-flash-message.d.ts +1 -0
- package/dist/error-boundary.d.ts +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +213 -53
- package/dist/layout.d.ts +2 -0
- package/dist/live.d.ts +6 -0
- package/dist/not-found.d.ts +2 -0
- package/dist/router.d.ts +9 -9
- package/dist/ssr.d.ts +2 -0
- package/dist/stream.d.ts +14 -0
- package/dist/tailwind.d.ts +2 -0
- package/package.json +3 -4
- package/dist/ssr/ssr.d.ts +0 -3
- /package/dist/{ssr/compile.d.ts → compile.d.ts} +0 -0
- /package/dist/{ssr → dist/ssr}/error-boundary.d.ts +0 -0
- /package/dist/{ssr → dist/ssr}/layout.d.ts +0 -0
- /package/dist/{ssr → dist/ssr}/live.d.ts +0 -0
- /package/dist/{ssr → dist/ssr}/not-found.d.ts +0 -0
- /package/dist/{ssr → dist/ssr}/stream.d.ts +0 -0
- /package/dist/{ssr → dist/ssr}/tailwind.d.ts +0 -0
package/cli.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { mkdir, writeFile, copyFile, readFile } from 'node:fs/promises'
|
|
2
|
+
import { mkdir, writeFile, copyFile, readFile, cp } from 'node:fs/promises'
|
|
3
3
|
import { existsSync } from 'node:fs'
|
|
4
4
|
import { execSync } from 'node:child_process'
|
|
5
5
|
import { homedir } from 'node:os'
|
|
@@ -31,12 +31,17 @@ async function cmdInit(name: string) {
|
|
|
31
31
|
|
|
32
32
|
await mkdir(targetDir, { recursive: true })
|
|
33
33
|
|
|
34
|
+
// Copy code templates
|
|
35
|
+
const templateDir = join(__dirname, 'template')
|
|
36
|
+
await cp(templateDir, targetDir, { recursive: true })
|
|
37
|
+
|
|
38
|
+
// Write config files
|
|
34
39
|
await writeFile(join(targetDir, 'package.json'), JSON.stringify({
|
|
35
40
|
name,
|
|
36
41
|
type: 'module',
|
|
37
42
|
scripts: {
|
|
38
|
-
dev: 'node --watch
|
|
39
|
-
start: 'NODE_ENV=production node
|
|
43
|
+
dev: 'node --watch index.ts',
|
|
44
|
+
start: 'NODE_ENV=production node index.ts',
|
|
40
45
|
},
|
|
41
46
|
dependencies: {
|
|
42
47
|
weifuwu: `^${v}`,
|
|
@@ -62,7 +67,6 @@ async function cmdInit(name: string) {
|
|
|
62
67
|
}, null, 2) + '\n')
|
|
63
68
|
|
|
64
69
|
await writeFile(join(targetDir, '.gitignore'), 'node_modules\ndist\n.env\n.sessions\n')
|
|
65
|
-
|
|
66
70
|
await writeFile(join(targetDir, '.env'), 'PORT=3000\n')
|
|
67
71
|
|
|
68
72
|
await writeFile(join(targetDir, 'AGENTS.md'), [
|
|
@@ -72,7 +76,7 @@ async function cmdInit(name: string) {
|
|
|
72
76
|
'',
|
|
73
77
|
'## Before you start',
|
|
74
78
|
'',
|
|
75
|
-
'Read `node_modules/weifuwu/README.md` first.
|
|
79
|
+
'Read `node_modules/weifuwu/README.md` first.',
|
|
76
80
|
'',
|
|
77
81
|
'## Commands',
|
|
78
82
|
'',
|
|
@@ -81,104 +85,9 @@ async function cmdInit(name: string) {
|
|
|
81
85
|
'- `npm install` — install dependencies',
|
|
82
86
|
'- `npx tsc --noEmit` — type-check without emitting',
|
|
83
87
|
'',
|
|
84
|
-
'## TypeScript',
|
|
85
|
-
'',
|
|
86
|
-
'- Node.js v24+ runs TypeScript natively (no build step needed)',
|
|
87
|
-
"- All imports use explicit `.ts` extensions (e.g. `import { x } from './foo.ts'`)",
|
|
88
|
-
'- For JSX/React SSR, use `.tsx` files',
|
|
89
|
-
'',
|
|
90
88
|
'## API Reference',
|
|
91
89
|
'',
|
|
92
|
-
'See `node_modules/weifuwu/README.md` for the full weifuwu API documentation
|
|
93
|
-
'',
|
|
94
|
-
].join('\n'))
|
|
95
|
-
|
|
96
|
-
await writeFile(join(targetDir, 'app.ts'), [
|
|
97
|
-
"import { serve, Router, loadEnv } from 'weifuwu'",
|
|
98
|
-
"import { ssr, layout } from 'weifuwu/ssr'",
|
|
99
|
-
'',
|
|
100
|
-
"loadEnv()",
|
|
101
|
-
"const port = Number(process.env.PORT) || 3000",
|
|
102
|
-
'',
|
|
103
|
-
"const app = new Router()",
|
|
104
|
-
"app.use(layout('./ui/layout.tsx'))",
|
|
105
|
-
"app.get('/', ssr('./ui/page.tsx'))",
|
|
106
|
-
'',
|
|
107
|
-
"app.get('/api/ping', () => Response.json({ pong: true, time: new Date().toISOString() }))",
|
|
108
|
-
'',
|
|
109
|
-
"app.ws('/ws/echo', { message(ws, _ctx, data) { ws.send(`echo: ${data}`) } })",
|
|
110
|
-
'',
|
|
111
|
-
"const server = serve(app.handler(), { port, websocket: app.websocketHandler() })",
|
|
112
|
-
"await server.ready",
|
|
113
|
-
"console.log(`Listening on http://localhost:${server.port}`)",
|
|
114
|
-
'',
|
|
115
|
-
].join('\n'))
|
|
116
|
-
|
|
117
|
-
await mkdir(join(targetDir, 'ui'), { recursive: true })
|
|
118
|
-
|
|
119
|
-
await writeFile(join(targetDir, 'ui', 'app.css'), '@import "tailwindcss";\n')
|
|
120
|
-
|
|
121
|
-
await writeFile(join(targetDir, 'ui', 'layout.tsx'), [
|
|
122
|
-
"import { ReactNode } from 'react'",
|
|
123
|
-
'',
|
|
124
|
-
'export default function RootLayout({ children }: { children: ReactNode }) {',
|
|
125
|
-
' return (',
|
|
126
|
-
' <html lang="en">',
|
|
127
|
-
' <head>',
|
|
128
|
-
' <meta charSet="utf-8" />',
|
|
129
|
-
' <meta name="viewport" content="width=device-width, initial-scale=1" />',
|
|
130
|
-
' </head>',
|
|
131
|
-
' <body>',
|
|
132
|
-
' <main>{children}</main>',
|
|
133
|
-
' </body>',
|
|
134
|
-
' </html>',
|
|
135
|
-
' )',
|
|
136
|
-
'}',
|
|
137
|
-
'',
|
|
138
|
-
].join('\n'))
|
|
139
|
-
|
|
140
|
-
await writeFile(join(targetDir, 'ui', 'page.tsx'), [
|
|
141
|
-
"import { useState } from 'react'",
|
|
142
|
-
"import { useWebsocket } from 'weifuwu/react'",
|
|
143
|
-
'',
|
|
144
|
-
'export default function Home() {',
|
|
145
|
-
' const [input, setInput] = useState("")',
|
|
146
|
-
' const { send, lastMessage, readyState } = useWebsocket("/ws/echo")',
|
|
147
|
-
'',
|
|
148
|
-
' return (',
|
|
149
|
-
' <div className="p-8 max-w-xl mx-auto">',
|
|
150
|
-
' <h1 className="text-3xl font-bold mb-2">Hello, Weifuwu!</h1>',
|
|
151
|
-
' <p className="text-gray-600 mb-6">',
|
|
152
|
-
' Welcome to your weifuwu application.',
|
|
153
|
-
' </p>',
|
|
154
|
-
' <div className="border rounded-lg p-4 space-y-3">',
|
|
155
|
-
' <p className="text-sm text-gray-500">',
|
|
156
|
-
' WebSocket: {readyState === 1 ? "Connected" : readyState === 0 ? "Connecting..." : "Disconnected"}',
|
|
157
|
-
' </p>',
|
|
158
|
-
' <div className="flex gap-2">',
|
|
159
|
-
' <input',
|
|
160
|
-
' value={input}',
|
|
161
|
-
' onChange={e => setInput(e.target.value)}',
|
|
162
|
-
' onKeyDown={e => { if (e.key === "Enter") { send(input); setInput("") } }}',
|
|
163
|
-
' placeholder="Type a message..."',
|
|
164
|
-
' className="flex-1 border rounded px-3 py-2 text-sm"',
|
|
165
|
-
' />',
|
|
166
|
-
' <button',
|
|
167
|
-
' onClick={() => { send(input); setInput("") }}',
|
|
168
|
-
' className="bg-blue-600 text-white px-4 py-2 rounded text-sm"',
|
|
169
|
-
' >',
|
|
170
|
-
' Send',
|
|
171
|
-
' </button>',
|
|
172
|
-
' </div>',
|
|
173
|
-
' {lastMessage && (',
|
|
174
|
-
' <div className="text-sm bg-gray-50 rounded p-2">',
|
|
175
|
-
' <span className="font-medium">Echo:</span> {lastMessage}',
|
|
176
|
-
' </div>',
|
|
177
|
-
' )}',
|
|
178
|
-
' </div>',
|
|
179
|
-
' </div>',
|
|
180
|
-
' )',
|
|
181
|
-
'}',
|
|
90
|
+
'See `node_modules/weifuwu/README.md` for the full weifuwu API documentation.',
|
|
182
91
|
'',
|
|
183
92
|
].join('\n'))
|
|
184
93
|
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// cli.ts
|
|
4
|
-
import { mkdir, writeFile, copyFile, readFile } from "node:fs/promises";
|
|
4
|
+
import { mkdir, writeFile, copyFile, readFile, cp } from "node:fs/promises";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import { execSync } from "node:child_process";
|
|
7
7
|
import { homedir } from "node:os";
|
|
@@ -26,12 +26,14 @@ async function cmdInit(name) {
|
|
|
26
26
|
const v = pkg.version;
|
|
27
27
|
const depVer = (depName) => `^${pkg.devDependencies[depName].replace(/^\^/, "")}`;
|
|
28
28
|
await mkdir(targetDir, { recursive: true });
|
|
29
|
+
const templateDir = join(__dirname, "template");
|
|
30
|
+
await cp(templateDir, targetDir, { recursive: true });
|
|
29
31
|
await writeFile(join(targetDir, "package.json"), JSON.stringify({
|
|
30
32
|
name,
|
|
31
33
|
type: "module",
|
|
32
34
|
scripts: {
|
|
33
|
-
dev: "node --watch
|
|
34
|
-
start: "NODE_ENV=production node
|
|
35
|
+
dev: "node --watch index.ts",
|
|
36
|
+
start: "NODE_ENV=production node index.ts"
|
|
35
37
|
},
|
|
36
38
|
dependencies: {
|
|
37
39
|
weifuwu: `^${v}`
|
|
@@ -63,7 +65,7 @@ async function cmdInit(name) {
|
|
|
63
65
|
"",
|
|
64
66
|
"## Before you start",
|
|
65
67
|
"",
|
|
66
|
-
"Read `node_modules/weifuwu/README.md` first.
|
|
68
|
+
"Read `node_modules/weifuwu/README.md` first.",
|
|
67
69
|
"",
|
|
68
70
|
"## Commands",
|
|
69
71
|
"",
|
|
@@ -72,99 +74,9 @@ async function cmdInit(name) {
|
|
|
72
74
|
"- `npm install` \u2014 install dependencies",
|
|
73
75
|
"- `npx tsc --noEmit` \u2014 type-check without emitting",
|
|
74
76
|
"",
|
|
75
|
-
"## TypeScript",
|
|
76
|
-
"",
|
|
77
|
-
"- Node.js v24+ runs TypeScript natively (no build step needed)",
|
|
78
|
-
"- All imports use explicit `.ts` extensions (e.g. `import { x } from './foo.ts'`)",
|
|
79
|
-
"- For JSX/React SSR, use `.tsx` files",
|
|
80
|
-
"",
|
|
81
77
|
"## API Reference",
|
|
82
78
|
"",
|
|
83
|
-
"See `node_modules/weifuwu/README.md` for the full weifuwu API documentation
|
|
84
|
-
""
|
|
85
|
-
].join("\n"));
|
|
86
|
-
await writeFile(join(targetDir, "app.ts"), [
|
|
87
|
-
"import { serve, Router, loadEnv } from 'weifuwu'",
|
|
88
|
-
"import { ssr, layout } from 'weifuwu/ssr'",
|
|
89
|
-
"",
|
|
90
|
-
"loadEnv()",
|
|
91
|
-
"const port = Number(process.env.PORT) || 3000",
|
|
92
|
-
"",
|
|
93
|
-
"const app = new Router()",
|
|
94
|
-
"app.use(layout('./ui/layout.tsx'))",
|
|
95
|
-
"app.get('/', ssr('./ui/page.tsx'))",
|
|
96
|
-
"",
|
|
97
|
-
"app.get('/api/ping', () => Response.json({ pong: true, time: new Date().toISOString() }))",
|
|
98
|
-
"",
|
|
99
|
-
"app.ws('/ws/echo', { message(ws, _ctx, data) { ws.send(`echo: ${data}`) } })",
|
|
100
|
-
"",
|
|
101
|
-
"const server = serve(app.handler(), { port, websocket: app.websocketHandler() })",
|
|
102
|
-
"await server.ready",
|
|
103
|
-
"console.log(`Listening on http://localhost:${server.port}`)",
|
|
104
|
-
""
|
|
105
|
-
].join("\n"));
|
|
106
|
-
await mkdir(join(targetDir, "ui"), { recursive: true });
|
|
107
|
-
await writeFile(join(targetDir, "ui", "app.css"), '@import "tailwindcss";\n');
|
|
108
|
-
await writeFile(join(targetDir, "ui", "layout.tsx"), [
|
|
109
|
-
"import { ReactNode } from 'react'",
|
|
110
|
-
"",
|
|
111
|
-
"export default function RootLayout({ children }: { children: ReactNode }) {",
|
|
112
|
-
" return (",
|
|
113
|
-
' <html lang="en">',
|
|
114
|
-
" <head>",
|
|
115
|
-
' <meta charSet="utf-8" />',
|
|
116
|
-
' <meta name="viewport" content="width=device-width, initial-scale=1" />',
|
|
117
|
-
" </head>",
|
|
118
|
-
" <body>",
|
|
119
|
-
" <main>{children}</main>",
|
|
120
|
-
" </body>",
|
|
121
|
-
" </html>",
|
|
122
|
-
" )",
|
|
123
|
-
"}",
|
|
124
|
-
""
|
|
125
|
-
].join("\n"));
|
|
126
|
-
await writeFile(join(targetDir, "ui", "page.tsx"), [
|
|
127
|
-
"import { useState } from 'react'",
|
|
128
|
-
"import { useWebsocket } from 'weifuwu/react'",
|
|
129
|
-
"",
|
|
130
|
-
"export default function Home() {",
|
|
131
|
-
' const [input, setInput] = useState("")',
|
|
132
|
-
' const { send, lastMessage, readyState } = useWebsocket("/ws/echo")',
|
|
133
|
-
"",
|
|
134
|
-
" return (",
|
|
135
|
-
' <div className="p-8 max-w-xl mx-auto">',
|
|
136
|
-
' <h1 className="text-3xl font-bold mb-2">Hello, Weifuwu!</h1>',
|
|
137
|
-
' <p className="text-gray-600 mb-6">',
|
|
138
|
-
" Welcome to your weifuwu application.",
|
|
139
|
-
" </p>",
|
|
140
|
-
' <div className="border rounded-lg p-4 space-y-3">',
|
|
141
|
-
' <p className="text-sm text-gray-500">',
|
|
142
|
-
' WebSocket: {readyState === 1 ? "Connected" : readyState === 0 ? "Connecting..." : "Disconnected"}',
|
|
143
|
-
" </p>",
|
|
144
|
-
' <div className="flex gap-2">',
|
|
145
|
-
" <input",
|
|
146
|
-
" value={input}",
|
|
147
|
-
" onChange={e => setInput(e.target.value)}",
|
|
148
|
-
' onKeyDown={e => { if (e.key === "Enter") { send(input); setInput("") } }}',
|
|
149
|
-
' placeholder="Type a message..."',
|
|
150
|
-
' className="flex-1 border rounded px-3 py-2 text-sm"',
|
|
151
|
-
" />",
|
|
152
|
-
" <button",
|
|
153
|
-
' onClick={() => { send(input); setInput("") }}',
|
|
154
|
-
' className="bg-blue-600 text-white px-4 py-2 rounded text-sm"',
|
|
155
|
-
" >",
|
|
156
|
-
" Send",
|
|
157
|
-
" </button>",
|
|
158
|
-
" </div>",
|
|
159
|
-
" {lastMessage && (",
|
|
160
|
-
' <div className="text-sm bg-gray-50 rounded p-2">',
|
|
161
|
-
' <span className="font-medium">Echo:</span> {lastMessage}',
|
|
162
|
-
" </div>",
|
|
163
|
-
" )}",
|
|
164
|
-
" </div>",
|
|
165
|
-
" </div>",
|
|
166
|
-
" )",
|
|
167
|
-
"}",
|
|
79
|
+
"See `node_modules/weifuwu/README.md` for the full weifuwu API documentation.",
|
|
168
80
|
""
|
|
169
81
|
].join("\n"));
|
|
170
82
|
console.log("\nInstalling dependencies...");
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Router } from '../router.ts';
|
|
2
|
+
import type { BoundTable } from '../postgres/schema/index.ts';
|
|
3
|
+
import type { RunParams } from './types.ts';
|
|
4
|
+
interface RestDeps {
|
|
5
|
+
agents: BoundTable<any>;
|
|
6
|
+
knowledge: BoundTable<any>;
|
|
7
|
+
runner: {
|
|
8
|
+
run: (agentId: number, params: RunParams) => Promise<any>;
|
|
9
|
+
addKnowledge: (agentId: number, title: string, content: string) => Promise<any>;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare function buildRouter(deps: RestDeps): Router;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type LanguageModel, type EmbeddingModel, type Tool } from 'ai';
|
|
2
|
+
import type { Sql } from '../vendor.ts';
|
|
3
|
+
import type { BoundTable } from '../postgres/schema/index.ts';
|
|
4
|
+
import type { RunParams, RunResult, KnowledgeDoc } from './types.ts';
|
|
5
|
+
interface RunnerDeps {
|
|
6
|
+
sql: Sql<{}>;
|
|
7
|
+
agents: BoundTable<any>;
|
|
8
|
+
knowledge: BoundTable<any>;
|
|
9
|
+
getModel: () => LanguageModel;
|
|
10
|
+
getEmbeddingModel: () => EmbeddingModel;
|
|
11
|
+
userTools?: Record<string, Tool>;
|
|
12
|
+
}
|
|
13
|
+
export declare function createRunner(deps: RunnerDeps): {
|
|
14
|
+
run: (agentId: number, params: RunParams) => Promise<RunResult>;
|
|
15
|
+
addKnowledge: (agentId: number, title: string, content: string) => Promise<KnowledgeDoc>;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Router } from '../router.ts';
|
|
2
|
+
import type { LanguageModel, EmbeddingModel, Tool } from 'ai';
|
|
3
|
+
export interface AgentConfig {
|
|
4
|
+
id: number;
|
|
5
|
+
tenant_id: string | null;
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
type: 'chat' | 'tool-use';
|
|
9
|
+
model: string;
|
|
10
|
+
system_prompt: string;
|
|
11
|
+
owner_id: number;
|
|
12
|
+
active: boolean;
|
|
13
|
+
created_at: string;
|
|
14
|
+
updated_at: string;
|
|
15
|
+
}
|
|
16
|
+
export interface KnowledgeDoc {
|
|
17
|
+
id: number;
|
|
18
|
+
agent_id: number;
|
|
19
|
+
title: string;
|
|
20
|
+
content: string;
|
|
21
|
+
embedding?: number[];
|
|
22
|
+
metadata: Record<string, unknown>;
|
|
23
|
+
created_at: string;
|
|
24
|
+
}
|
|
25
|
+
export interface RunParams {
|
|
26
|
+
input: string;
|
|
27
|
+
stream?: boolean;
|
|
28
|
+
messages?: Array<{
|
|
29
|
+
role: string;
|
|
30
|
+
content: string;
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
33
|
+
export type RunResult = {
|
|
34
|
+
output: string;
|
|
35
|
+
elapsed: number;
|
|
36
|
+
} | {
|
|
37
|
+
stream: ReadableStream<Uint8Array>;
|
|
38
|
+
};
|
|
39
|
+
export interface AgentOptions {
|
|
40
|
+
pg: import('../postgres/types.ts').PostgresClient;
|
|
41
|
+
model?: LanguageModel;
|
|
42
|
+
embeddingModel?: EmbeddingModel;
|
|
43
|
+
embeddingDimension?: number;
|
|
44
|
+
tools?: Record<string, Tool>;
|
|
45
|
+
}
|
|
46
|
+
export interface AgentModule extends Router {
|
|
47
|
+
migrate: () => Promise<void>;
|
|
48
|
+
run: (agentId: number, params: RunParams) => Promise<RunResult>;
|
|
49
|
+
addKnowledge: (agentId: number, title: string, content: string) => Promise<KnowledgeDoc>;
|
|
50
|
+
close: () => Promise<void>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { LanguageModel } from 'ai';
|
|
2
|
+
export declare function runWorkflow(opts?: {
|
|
3
|
+
tools?: Record<string, any>;
|
|
4
|
+
model?: LanguageModel;
|
|
5
|
+
maxSteps?: number;
|
|
6
|
+
}): import("ai").Tool<{
|
|
7
|
+
goal: string;
|
|
8
|
+
nodes?: any[];
|
|
9
|
+
}, {
|
|
10
|
+
result: unknown;
|
|
11
|
+
nodeOutputs: {
|
|
12
|
+
[k: string]: unknown;
|
|
13
|
+
};
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Middleware } from './types.ts';
|
|
2
|
+
import { Router } from './router.ts';
|
|
3
|
+
export interface AnalyticsOptions {
|
|
4
|
+
excluded?: string[];
|
|
5
|
+
pg?: {
|
|
6
|
+
sql: (strings: TemplateStringsArray, ...values: any[]) => Promise<any[]>;
|
|
7
|
+
table: (name: string, cols: any) => any;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface AnalyticsModule extends Router {
|
|
11
|
+
middleware: () => Middleware;
|
|
12
|
+
migrate: () => Promise<void>;
|
|
13
|
+
close: () => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export declare function analytics(options?: AnalyticsOptions): AnalyticsModule;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type SetPartial<T> = Partial<T> | ((prev: T) => Partial<T>);
|
|
2
|
+
export interface StoreApi<T> {
|
|
3
|
+
(): T;
|
|
4
|
+
<S>(selector: (state: T) => S): S;
|
|
5
|
+
getState: () => T;
|
|
6
|
+
setState: (partial: SetPartial<T>) => void;
|
|
7
|
+
subscribe: (listener: () => void) => () => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function createStore<T extends Record<string, unknown>>(initial: T): StoreApi<T>;
|
|
10
|
+
interface UseFetchResult<T> {
|
|
11
|
+
data: T | undefined;
|
|
12
|
+
error: Error | undefined;
|
|
13
|
+
loading: boolean;
|
|
14
|
+
mutate: (data?: T) => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
interface UseFetchOptions<T> {
|
|
17
|
+
fallback?: T;
|
|
18
|
+
ttl?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function useFetch<T = unknown>(url: string | null, options?: UseFetchOptions<T>): UseFetchResult<T>;
|
|
21
|
+
export declare function useQueryState(key: string, defaultValue?: string): [string, (val: string | ((prev: string) => string)) => void];
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface CookieOptions {
|
|
2
|
+
domain?: string;
|
|
3
|
+
path?: string;
|
|
4
|
+
maxAge?: number;
|
|
5
|
+
expires?: Date;
|
|
6
|
+
httpOnly?: boolean;
|
|
7
|
+
secure?: boolean;
|
|
8
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
9
|
+
}
|
|
10
|
+
export declare function getCookies(req: Request): Record<string, string>;
|
|
11
|
+
export declare function setCookie(res: Response, name: string, value: string, options?: CookieOptions): Response;
|
|
12
|
+
export declare function deleteCookie(res: Response, name: string, options?: Omit<CookieOptions, 'maxAge'>): Response;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DeployConfig, DeployServer } from './types.ts';
|
|
2
|
+
export { defineConfig } from './config.ts';
|
|
3
|
+
export type { DeployConfig, AppConfig, DeployServer, AppStatus, GatewayResult } from './types.ts';
|
|
4
|
+
export declare function deploy(config: DeployConfig): Promise<DeployServer>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Router } from '../router.ts';
|
|
2
|
+
import type { DeployConfig, AppStatus } from './types.ts';
|
|
3
|
+
export interface AppRuntime {
|
|
4
|
+
config: import('./types.ts').AppConfig;
|
|
5
|
+
status: AppStatus;
|
|
6
|
+
logs: string[];
|
|
7
|
+
process: import('node:child_process').ChildProcess | null;
|
|
8
|
+
currentPort: number;
|
|
9
|
+
startedAt: number | null;
|
|
10
|
+
restartCount: number;
|
|
11
|
+
restartTimer: ReturnType<typeof setTimeout> | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare function createManager(config: DeployConfig, apps: Map<string, AppRuntime>, manager: {
|
|
14
|
+
deployApp(name: string): Promise<void>;
|
|
15
|
+
reloadConfig(): Promise<void>;
|
|
16
|
+
}): Router;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ChildProcess } from 'node:child_process';
|
|
2
|
+
export interface ManagedProcess {
|
|
3
|
+
child: ChildProcess;
|
|
4
|
+
port: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function forkApp(opts: {
|
|
7
|
+
cwd: string;
|
|
8
|
+
entry: string;
|
|
9
|
+
port: number;
|
|
10
|
+
env?: Record<string, string>;
|
|
11
|
+
onLog?: (line: string) => void;
|
|
12
|
+
}): ManagedProcess;
|
|
13
|
+
export declare function stopProcess(mp: ManagedProcess, timeout?: number): Promise<void>;
|
|
14
|
+
export declare function healthCheck(port: number, path?: string): Promise<boolean>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { IncomingMessage } from 'node:http';
|
|
2
|
+
import type { Duplex } from 'node:stream';
|
|
3
|
+
import type { Handler } from '../types.ts';
|
|
4
|
+
export interface DeployConfig {
|
|
5
|
+
domain: string;
|
|
6
|
+
port?: number;
|
|
7
|
+
ssl?: {
|
|
8
|
+
email: string;
|
|
9
|
+
staging?: boolean;
|
|
10
|
+
};
|
|
11
|
+
deployToken?: string;
|
|
12
|
+
webhookSecret?: string;
|
|
13
|
+
appsDir?: string;
|
|
14
|
+
defaultApp?: string;
|
|
15
|
+
apps: Record<string, AppConfig>;
|
|
16
|
+
}
|
|
17
|
+
export interface AppConfig {
|
|
18
|
+
repo: string;
|
|
19
|
+
branch?: string;
|
|
20
|
+
subdomain?: string;
|
|
21
|
+
path?: string;
|
|
22
|
+
port: number;
|
|
23
|
+
ports?: [number, number];
|
|
24
|
+
entry: string;
|
|
25
|
+
env?: Record<string, string>;
|
|
26
|
+
healthEndpoint?: string;
|
|
27
|
+
buildCommand?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface AppStatus {
|
|
30
|
+
name: string;
|
|
31
|
+
status: 'starting' | 'running' | 'stopped' | 'error';
|
|
32
|
+
port: number;
|
|
33
|
+
subdomain?: string;
|
|
34
|
+
path?: string;
|
|
35
|
+
pid?: number;
|
|
36
|
+
uptime?: number;
|
|
37
|
+
error?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface DeployServer {
|
|
40
|
+
close(): Promise<void>;
|
|
41
|
+
ready: Promise<void>;
|
|
42
|
+
url: string;
|
|
43
|
+
apps: {
|
|
44
|
+
list(): AppStatus[];
|
|
45
|
+
status(name: string): AppStatus | undefined;
|
|
46
|
+
deploy(name: string): Promise<void>;
|
|
47
|
+
restart(name: string): Promise<void>;
|
|
48
|
+
stop(name: string): Promise<void>;
|
|
49
|
+
start(name: string): Promise<void>;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export interface GatewayResult {
|
|
53
|
+
handler: Handler;
|
|
54
|
+
wsHandler: (req: IncomingMessage, socket: Duplex, head: Buffer) => void;
|
|
55
|
+
}
|
|
56
|
+
declare module '../types.ts' {
|
|
57
|
+
interface Context {
|
|
58
|
+
deploy?: {
|
|
59
|
+
appName?: string;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Middleware } from './types.ts';
|
|
2
|
+
export interface HelmetOptions {
|
|
3
|
+
contentSecurityPolicy?: string | false;
|
|
4
|
+
crossOriginEmbedderPolicy?: string | false;
|
|
5
|
+
crossOriginOpenerPolicy?: string | false;
|
|
6
|
+
crossOriginResourcePolicy?: string | false;
|
|
7
|
+
originAgentCluster?: string | false;
|
|
8
|
+
referrerPolicy?: string | false;
|
|
9
|
+
strictTransportSecurity?: string | false;
|
|
10
|
+
xContentTypeOptions?: string | false;
|
|
11
|
+
xDnsPrefetchControl?: string | false;
|
|
12
|
+
xDownloadOptions?: string | false;
|
|
13
|
+
xFrameOptions?: string | false;
|
|
14
|
+
xPermittedCrossDomainPolicies?: string | false;
|
|
15
|
+
xXssProtection?: string | false;
|
|
16
|
+
permissionsPolicy?: string | false;
|
|
17
|
+
}
|
|
18
|
+
export declare function helmet(options?: HelmetOptions): Middleware;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { iii } from './client.ts';
|
|
2
|
+
export { createWorker } from './worker.ts';
|
|
3
|
+
export { registerWorker } from './register-worker.ts';
|
|
4
|
+
export type { IIIModule, IIIOptions, Worker, WorkerInfo, FunctionInfo, TriggerInfo, FunctionHandler, FunctionContext, TriggerInput, RemoteWorker } from './types.ts';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FunctionHandler, TriggerInput, TriggerRequest } from './types.ts';
|
|
2
|
+
export declare function registerWorker(url: string): {
|
|
3
|
+
registerFunction(id: string, handler: FunctionHandler): void;
|
|
4
|
+
unregisterFunction(id: string): void;
|
|
5
|
+
registerTrigger(input: TriggerInput): void;
|
|
6
|
+
unregisterTrigger(functionId: string): void;
|
|
7
|
+
trigger(request: TriggerRequest): Promise<unknown>;
|
|
8
|
+
onStream(handler: (data: any) => void): void;
|
|
9
|
+
shutdown(): void;
|
|
10
|
+
};
|