freesail 0.0.1 → 0.1.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.
- package/README.md +190 -5
- package/docs/A2UX_Protocol.md +183 -0
- package/docs/Agents.md +218 -0
- package/docs/Architecture.md +285 -0
- package/docs/CatalogReference.md +377 -0
- package/docs/GettingStarted.md +230 -0
- package/examples/demo/package.json +21 -0
- package/examples/demo/public/index.html +381 -0
- package/examples/demo/server.js +253 -0
- package/package.json +38 -5
- package/packages/core/package.json +48 -0
- package/packages/core/src/functions.ts +403 -0
- package/packages/core/src/index.ts +214 -0
- package/packages/core/src/parser.ts +270 -0
- package/packages/core/src/protocol.ts +254 -0
- package/packages/core/src/store.ts +452 -0
- package/packages/core/src/transport.ts +439 -0
- package/packages/core/src/types.ts +209 -0
- package/packages/core/tsconfig.json +10 -0
- package/packages/lit-ui/package.json +44 -0
- package/packages/lit-ui/src/catalogs/standard/catalog.json +405 -0
- package/packages/lit-ui/src/catalogs/standard/elements/Badge.ts +96 -0
- package/packages/lit-ui/src/catalogs/standard/elements/Button.ts +147 -0
- package/packages/lit-ui/src/catalogs/standard/elements/Card.ts +78 -0
- package/packages/lit-ui/src/catalogs/standard/elements/Checkbox.ts +94 -0
- package/packages/lit-ui/src/catalogs/standard/elements/Column.ts +66 -0
- package/packages/lit-ui/src/catalogs/standard/elements/Divider.ts +59 -0
- package/packages/lit-ui/src/catalogs/standard/elements/Image.ts +54 -0
- package/packages/lit-ui/src/catalogs/standard/elements/Input.ts +125 -0
- package/packages/lit-ui/src/catalogs/standard/elements/Progress.ts +79 -0
- package/packages/lit-ui/src/catalogs/standard/elements/Row.ts +68 -0
- package/packages/lit-ui/src/catalogs/standard/elements/Select.ts +110 -0
- package/packages/lit-ui/src/catalogs/standard/elements/Spacer.ts +37 -0
- package/packages/lit-ui/src/catalogs/standard/elements/Spinner.ts +76 -0
- package/packages/lit-ui/src/catalogs/standard/elements/Text.ts +86 -0
- package/packages/lit-ui/src/catalogs/standard/elements/index.ts +18 -0
- package/packages/lit-ui/src/catalogs/standard/index.ts +17 -0
- package/packages/lit-ui/src/index.ts +84 -0
- package/packages/lit-ui/src/renderer.ts +211 -0
- package/packages/lit-ui/src/types.ts +49 -0
- package/packages/lit-ui/src/utils/define-props.ts +157 -0
- package/packages/lit-ui/src/utils/index.ts +2 -0
- package/packages/lit-ui/src/utils/registry.ts +139 -0
- package/packages/lit-ui/tsconfig.json +11 -0
- package/packages/server/package.json +61 -0
- package/packages/server/src/adapters/index.ts +5 -0
- package/packages/server/src/adapters/langchain.ts +175 -0
- package/packages/server/src/adapters/openai.ts +209 -0
- package/packages/server/src/catalog-loader.ts +311 -0
- package/packages/server/src/index.ts +142 -0
- package/packages/server/src/stream.ts +329 -0
- package/packages/server/tsconfig.json +11 -0
- package/tsconfig.base.json +23 -0
- package/index.js +0 -3
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Freesail Demo Server
|
|
3
|
+
*
|
|
4
|
+
* A simple Express server demonstrating the Freesail SDK.
|
|
5
|
+
* This example shows how to:
|
|
6
|
+
* - Set up SSE streaming
|
|
7
|
+
* - Send A2UX protocol messages
|
|
8
|
+
* - Handle user actions
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import express from 'express';
|
|
12
|
+
import { fileURLToPath } from 'url';
|
|
13
|
+
import { dirname, join } from 'path';
|
|
14
|
+
import {
|
|
15
|
+
FreesailStream,
|
|
16
|
+
CatalogToToolConverter,
|
|
17
|
+
createSSEHandler,
|
|
18
|
+
createActionHandler,
|
|
19
|
+
} from '@freesail/server';
|
|
20
|
+
|
|
21
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
22
|
+
const __dirname = dirname(__filename);
|
|
23
|
+
|
|
24
|
+
const app = express();
|
|
25
|
+
const PORT = process.env.PORT || 3000;
|
|
26
|
+
|
|
27
|
+
// Middleware
|
|
28
|
+
app.use(express.json());
|
|
29
|
+
app.use(express.static(join(__dirname, 'public')));
|
|
30
|
+
|
|
31
|
+
// Load catalog for tool generation
|
|
32
|
+
const catalogId = 'standard_catalog_v1';
|
|
33
|
+
|
|
34
|
+
// Store active conversations (in production, use a proper store)
|
|
35
|
+
const conversations = new Map();
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* SSE Endpoint - Streams UI to the client
|
|
39
|
+
*/
|
|
40
|
+
app.get('/api/stream', createSSEHandler(async (stream, req) => {
|
|
41
|
+
console.log(`[Demo] New connection: ${stream.id}`);
|
|
42
|
+
|
|
43
|
+
// Store stream for later use
|
|
44
|
+
conversations.set(stream.id, { stream, state: {} });
|
|
45
|
+
|
|
46
|
+
// Send initial UI
|
|
47
|
+
await sendWelcomeUI(stream);
|
|
48
|
+
|
|
49
|
+
// Keep connection open - in real app, this would be driven by LLM
|
|
50
|
+
// For demo, we'll just wait
|
|
51
|
+
}));
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Action Endpoint - Handles user interactions
|
|
55
|
+
*/
|
|
56
|
+
app.post('/api/action', express.json(), createActionHandler(async (action, req) => {
|
|
57
|
+
console.log(`[Demo] User action:`, action);
|
|
58
|
+
|
|
59
|
+
// Find the stream for this surface (simplified - in real app, track properly)
|
|
60
|
+
for (const [id, conv] of conversations) {
|
|
61
|
+
if (!conv.stream.closed) {
|
|
62
|
+
await handleUserAction(conv.stream, action);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Send welcome UI to client
|
|
70
|
+
*/
|
|
71
|
+
async function sendWelcomeUI(stream) {
|
|
72
|
+
// Create surface
|
|
73
|
+
stream.createSurface('main', catalogId);
|
|
74
|
+
|
|
75
|
+
// Small delay to ensure surface is ready
|
|
76
|
+
await sleep(100);
|
|
77
|
+
|
|
78
|
+
// Send components
|
|
79
|
+
stream.send({
|
|
80
|
+
updateComponents: {
|
|
81
|
+
surfaceId: 'main',
|
|
82
|
+
components: [
|
|
83
|
+
{
|
|
84
|
+
id: 'root',
|
|
85
|
+
component: 'Column',
|
|
86
|
+
gap: '24px',
|
|
87
|
+
padding: '24px',
|
|
88
|
+
children: ['header', 'card', 'actions'],
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
id: 'header',
|
|
92
|
+
component: 'Row',
|
|
93
|
+
justify: 'between',
|
|
94
|
+
align: 'center',
|
|
95
|
+
children: ['title', 'badge'],
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: 'title',
|
|
99
|
+
component: 'Text',
|
|
100
|
+
text: 'Welcome to Freesail',
|
|
101
|
+
variant: 'h2',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
id: 'badge',
|
|
105
|
+
component: 'Badge',
|
|
106
|
+
text: 'Demo',
|
|
107
|
+
variant: 'primary',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
id: 'card',
|
|
111
|
+
component: 'Card',
|
|
112
|
+
title: 'Generative UI Demo',
|
|
113
|
+
subtitle: 'This UI was generated via the A2UX protocol',
|
|
114
|
+
children: ['card-content'],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: 'card-content',
|
|
118
|
+
component: 'Column',
|
|
119
|
+
gap: '16px',
|
|
120
|
+
children: ['description', 'input-name', 'input-email', 'checkbox'],
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
id: 'description',
|
|
124
|
+
component: 'Text',
|
|
125
|
+
text: 'Freesail decouples AI agents from the frontend, allowing any LLM to drive any UI through a standardized JSON protocol.',
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
id: 'input-name',
|
|
129
|
+
component: 'Input',
|
|
130
|
+
label: 'Your Name',
|
|
131
|
+
placeholder: 'Enter your name',
|
|
132
|
+
bindPath: '/user/name',
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
id: 'input-email',
|
|
136
|
+
component: 'Input',
|
|
137
|
+
label: 'Email',
|
|
138
|
+
placeholder: 'Enter your email',
|
|
139
|
+
type: 'email',
|
|
140
|
+
bindPath: '/user/email',
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
id: 'checkbox',
|
|
144
|
+
component: 'Checkbox',
|
|
145
|
+
label: 'Subscribe to updates',
|
|
146
|
+
bindPath: '/user/subscribe',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
id: 'actions',
|
|
150
|
+
component: 'Row',
|
|
151
|
+
gap: '12px',
|
|
152
|
+
justify: 'end',
|
|
153
|
+
children: ['btn-cancel', 'btn-submit'],
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
id: 'btn-cancel',
|
|
157
|
+
component: 'Button',
|
|
158
|
+
label: 'Cancel',
|
|
159
|
+
variant: 'outline',
|
|
160
|
+
action: 'cancel',
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
id: 'btn-submit',
|
|
164
|
+
component: 'Button',
|
|
165
|
+
label: 'Submit',
|
|
166
|
+
variant: 'primary',
|
|
167
|
+
action: 'submit',
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// Initialize data model
|
|
174
|
+
stream.updateDataModel('main', {
|
|
175
|
+
user: {
|
|
176
|
+
name: '',
|
|
177
|
+
email: '',
|
|
178
|
+
subscribe: false,
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Handle user actions
|
|
185
|
+
*/
|
|
186
|
+
async function handleUserAction(stream, action) {
|
|
187
|
+
const { surfaceId, action: actionType, context } = action;
|
|
188
|
+
|
|
189
|
+
switch (actionType) {
|
|
190
|
+
case 'submit':
|
|
191
|
+
console.log('[Demo] Form submitted with:', context);
|
|
192
|
+
|
|
193
|
+
// Update UI to show success
|
|
194
|
+
stream.send({
|
|
195
|
+
updateComponents: {
|
|
196
|
+
surfaceId: 'main',
|
|
197
|
+
components: [
|
|
198
|
+
{
|
|
199
|
+
id: 'card-content',
|
|
200
|
+
component: 'Column',
|
|
201
|
+
gap: '16px',
|
|
202
|
+
align: 'center',
|
|
203
|
+
children: ['success-icon', 'success-text'],
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
id: 'success-icon',
|
|
207
|
+
component: 'Badge',
|
|
208
|
+
text: '✓',
|
|
209
|
+
variant: 'success',
|
|
210
|
+
size: 'large',
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
id: 'success-text',
|
|
214
|
+
component: 'Text',
|
|
215
|
+
text: `Thank you, ${context?.user?.name || 'User'}! Your submission was received.`,
|
|
216
|
+
align: 'center',
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
break;
|
|
222
|
+
|
|
223
|
+
case 'cancel':
|
|
224
|
+
console.log('[Demo] Form cancelled');
|
|
225
|
+
|
|
226
|
+
// Reset the form
|
|
227
|
+
stream.updateDataModel('main', {
|
|
228
|
+
user: { name: '', email: '', subscribe: false },
|
|
229
|
+
});
|
|
230
|
+
break;
|
|
231
|
+
|
|
232
|
+
default:
|
|
233
|
+
console.log(`[Demo] Unknown action: ${actionType}`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function sleep(ms) {
|
|
238
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Start server
|
|
242
|
+
app.listen(PORT, () => {
|
|
243
|
+
console.log(`
|
|
244
|
+
╔═══════════════════════════════════════════════════════════╗
|
|
245
|
+
║ ║
|
|
246
|
+
║ 🚀 Freesail Demo Server ║
|
|
247
|
+
║ ║
|
|
248
|
+
║ Server running at: http://localhost:${PORT} ║
|
|
249
|
+
║ Open in browser to see the demo ║
|
|
250
|
+
║ ║
|
|
251
|
+
╚═══════════════════════════════════════════════════════════╝
|
|
252
|
+
`);
|
|
253
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "freesail",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Industrial Strength Generative UI SDK",
|
|
5
|
+
"workspaces": [
|
|
6
|
+
"packages/*"
|
|
7
|
+
],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "npm run build --workspaces",
|
|
10
|
+
"build:core": "npm run build --workspace=@freesail/core",
|
|
11
|
+
"build:lit": "npm run build --workspace=@freesail/lit-ui",
|
|
12
|
+
"build:server": "npm run build --workspace=@freesail/server",
|
|
13
|
+
"dev": "npm run dev --workspaces --if-present",
|
|
14
|
+
"test": "npm run test --workspaces --if-present",
|
|
15
|
+
"lint": "npm run lint --workspaces --if-present",
|
|
16
|
+
"clean": "rm -rf packages/*/dist packages/*/node_modules node_modules"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/freesail/freesail.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"generative-ui",
|
|
24
|
+
"ai-agents",
|
|
25
|
+
"llm",
|
|
26
|
+
"sse",
|
|
27
|
+
"web-components",
|
|
28
|
+
"lit",
|
|
29
|
+
"a2ux",
|
|
30
|
+
"headless"
|
|
31
|
+
],
|
|
32
|
+
"author": "Freesail Team",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=18.0.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"typescript": "^5.3.3"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@freesail/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Freesail Core - A2UX Protocol Parser, Transport & State Management",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./protocol": {
|
|
15
|
+
"types": "./dist/protocol.d.ts",
|
|
16
|
+
"import": "./dist/protocol.js"
|
|
17
|
+
},
|
|
18
|
+
"./transport": {
|
|
19
|
+
"types": "./dist/transport.d.ts",
|
|
20
|
+
"import": "./dist/transport.js"
|
|
21
|
+
},
|
|
22
|
+
"./store": {
|
|
23
|
+
"types": "./dist/store.d.ts",
|
|
24
|
+
"import": "./dist/store.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc",
|
|
32
|
+
"dev": "tsc --watch",
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"test:watch": "vitest",
|
|
35
|
+
"lint": "eslint src --ext .ts"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"typescript": "^5.3.3",
|
|
39
|
+
"vitest": "^1.2.0"
|
|
40
|
+
},
|
|
41
|
+
"keywords": [
|
|
42
|
+
"a2ux",
|
|
43
|
+
"protocol",
|
|
44
|
+
"sse",
|
|
45
|
+
"transport"
|
|
46
|
+
],
|
|
47
|
+
"license": "MIT"
|
|
48
|
+
}
|