r1-create 1.3.0 → 1.3.1
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 +47 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/llm/index.d.ts +125 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +237 -4
- package/dist/llm/index.js.map +1 -1
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -1
- package/examples/README.md +36 -0
- package/examples/camera/index.html +160 -0
- package/examples/device-controls/index.html +191 -0
- package/examples/hardware-game/index.html +165 -0
- package/examples/messaging-test/index.html +359 -0
- package/examples/nextjs-test-app/README.md +72 -0
- package/examples/nextjs-test-app/app/globals.css +282 -0
- package/examples/nextjs-test-app/app/layout.jsx +14 -0
- package/examples/nextjs-test-app/app/page.jsx +1265 -0
- package/examples/nextjs-test-app/log-relay/device-console-bridge.js +91 -0
- package/examples/nextjs-test-app/log-relay/server.js +55 -0
- package/examples/nextjs-test-app/next.config.js +8 -0
- package/examples/nextjs-test-app/package-lock.json +1227 -0
- package/examples/nextjs-test-app/package.json +18 -0
- package/examples/text-to-speech/index.html +128 -0
- package/examples/ui-design/index.html +189 -0
- package/examples/voice-recorder/index.html +149 -0
- package/examples/web-search/index.html +147 -0
- package/package.json +1 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Device Console Bridge (Socket.IO)
|
|
3
|
+
Usage on device creation page:
|
|
4
|
+
|
|
5
|
+
<script src="https://cdn.socket.io/4.8.1/socket.io.min.js"></script>
|
|
6
|
+
<script src="device-console-bridge.js"></script>
|
|
7
|
+
|
|
8
|
+
Set relay URL before loading this file if needed:
|
|
9
|
+
window.__R1_RELAY_URL__ = 'http://YOUR_HOST:3031';
|
|
10
|
+
*/
|
|
11
|
+
(function () {
|
|
12
|
+
if (typeof window === 'undefined') return;
|
|
13
|
+
if (typeof io === 'undefined') {
|
|
14
|
+
console.warn('[relay] socket.io client not found (missing CDN script).');
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const relayUrl = window.__R1_RELAY_URL__ || 'http://localhost:3031';
|
|
19
|
+
const deviceId = window.__R1_DEVICE_ID__ || 'r1-device';
|
|
20
|
+
const socket = io(relayUrl, {
|
|
21
|
+
transports: ['websocket', 'polling']
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
function stringify(value) {
|
|
25
|
+
if (typeof value === 'string') return value;
|
|
26
|
+
try {
|
|
27
|
+
return JSON.stringify(value);
|
|
28
|
+
} catch {
|
|
29
|
+
return String(value);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function emit(level, args, extras) {
|
|
34
|
+
try {
|
|
35
|
+
socket.emit('console_log', {
|
|
36
|
+
level,
|
|
37
|
+
args: Array.prototype.map.call(args, stringify),
|
|
38
|
+
url: location.href,
|
|
39
|
+
stack: extras && extras.stack ? String(extras.stack) : null
|
|
40
|
+
});
|
|
41
|
+
} catch {
|
|
42
|
+
// no-op
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
socket.on('connect', function () {
|
|
47
|
+
socket.emit('register', { role: 'device', deviceId: deviceId });
|
|
48
|
+
emit('info', ['[relay] connected', relayUrl], null);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
socket.on('connect_error', function (err) {
|
|
52
|
+
// keep local so dev sees failure even without relay
|
|
53
|
+
console.warn('[relay] connect_error', err && err.message ? err.message : err);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
var original = {
|
|
57
|
+
log: console.log.bind(console),
|
|
58
|
+
info: console.info.bind(console),
|
|
59
|
+
warn: console.warn.bind(console),
|
|
60
|
+
error: console.error.bind(console)
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
console.log = function () {
|
|
64
|
+
original.log.apply(console, arguments);
|
|
65
|
+
emit('log', arguments, null);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
console.info = function () {
|
|
69
|
+
original.info.apply(console, arguments);
|
|
70
|
+
emit('info', arguments, null);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
console.warn = function () {
|
|
74
|
+
original.warn.apply(console, arguments);
|
|
75
|
+
emit('warn', arguments, null);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
console.error = function () {
|
|
79
|
+
original.error.apply(console, arguments);
|
|
80
|
+
emit('error', arguments, null);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
window.addEventListener('error', function (event) {
|
|
84
|
+
emit('error', [event.message || 'window.error'], { stack: event.error && event.error.stack });
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
window.addEventListener('unhandledrejection', function (event) {
|
|
88
|
+
var reason = event.reason && event.reason.message ? event.reason.message : stringify(event.reason);
|
|
89
|
+
emit('error', ['unhandledrejection', reason], { stack: event.reason && event.reason.stack });
|
|
90
|
+
});
|
|
91
|
+
})();
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const http = require('http');
|
|
2
|
+
const { Server } = require('socket.io');
|
|
3
|
+
|
|
4
|
+
const PORT = process.env.RELAY_PORT ? Number(process.env.RELAY_PORT) : 3031;
|
|
5
|
+
|
|
6
|
+
const server = http.createServer((req, res) => {
|
|
7
|
+
res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
8
|
+
res.end('R1 log relay is running\n');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const io = new Server(server, {
|
|
12
|
+
cors: {
|
|
13
|
+
origin: '*',
|
|
14
|
+
methods: ['GET', 'POST']
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
io.on('connection', (socket) => {
|
|
19
|
+
console.log(`[relay] client connected ${socket.id}`);
|
|
20
|
+
|
|
21
|
+
socket.on('register', (payload) => {
|
|
22
|
+
const role = payload?.role || 'unknown';
|
|
23
|
+
const deviceId = payload?.deviceId || 'unknown';
|
|
24
|
+
socket.data.role = role;
|
|
25
|
+
socket.data.deviceId = deviceId;
|
|
26
|
+
console.log(`[relay] register role=${role} device=${deviceId} id=${socket.id}`);
|
|
27
|
+
socket.emit('relay_info', { ok: true, id: socket.id, role, deviceId });
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
socket.on('console_log', (payload) => {
|
|
31
|
+
const event = {
|
|
32
|
+
time: new Date().toISOString(),
|
|
33
|
+
socketId: socket.id,
|
|
34
|
+
role: socket.data.role || 'unknown',
|
|
35
|
+
deviceId: socket.data.deviceId || 'unknown',
|
|
36
|
+
level: payload?.level || 'log',
|
|
37
|
+
args: Array.isArray(payload?.args) ? payload.args : [String(payload?.args ?? '')],
|
|
38
|
+
url: payload?.url || null,
|
|
39
|
+
stack: payload?.stack || null
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const line = `[relay][${event.level}] (${event.role}:${event.deviceId}) ${event.args.join(' ')}`;
|
|
43
|
+
console.log(line);
|
|
44
|
+
|
|
45
|
+
io.emit('relay_log', event);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
socket.on('disconnect', (reason) => {
|
|
49
|
+
console.log(`[relay] client disconnected ${socket.id} reason=${reason}`);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
server.listen(PORT, '0.0.0.0', () => {
|
|
54
|
+
console.log(`[relay] listening on 0.0.0.0:${PORT}`);
|
|
55
|
+
});
|