codmir 0.3.2 → 0.4.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/LICENSE +55 -0
- package/README.md +219 -14
- package/dist/analyze-LULBI4ZC.mjs +7 -0
- package/dist/chunk-ASGAT3Z5.mjs +756 -0
- package/dist/chunk-EBO3CZXG.mjs +15 -0
- package/dist/{chunk-7HVQNURM.mjs → chunk-GU32P57R.mjs} +70 -0
- package/dist/cli/index.js +2018 -146
- package/dist/cli/index.mjs +1166 -139
- package/dist/index.d.mts +76 -1
- package/dist/index.d.ts +76 -1
- package/dist/index.js +70 -0
- package/dist/index.mjs +2 -1
- package/dist/voice-agent/index.d.mts +134 -0
- package/dist/voice-agent/index.d.ts +134 -0
- package/dist/voice-agent/index.js +220 -0
- package/dist/voice-agent/index.mjs +187 -0
- package/dist/voice-daemon/index.d.mts +354 -0
- package/dist/voice-daemon/index.d.ts +354 -0
- package/dist/voice-daemon/index.js +1089 -0
- package/dist/voice-daemon/index.mjs +1046 -0
- package/package.json +49 -12
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/voice-agent/index.ts
|
|
31
|
+
var voice_agent_exports = {};
|
|
32
|
+
__export(voice_agent_exports, {
|
|
33
|
+
VoiceAgent: () => VoiceAgent,
|
|
34
|
+
default: () => voice_agent_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(voice_agent_exports);
|
|
37
|
+
var import_ws = __toESM(require("ws"));
|
|
38
|
+
var DEFAULT_OPTIONS = {
|
|
39
|
+
url: "ws://127.0.0.1:9410",
|
|
40
|
+
clientId: "sdk-client",
|
|
41
|
+
clientType: "other",
|
|
42
|
+
autoReconnect: true,
|
|
43
|
+
reconnectDelay: 2e3
|
|
44
|
+
};
|
|
45
|
+
var VoiceAgent = class {
|
|
46
|
+
constructor(options = {}) {
|
|
47
|
+
this.ws = null;
|
|
48
|
+
this.connected = false;
|
|
49
|
+
this.reconnecting = false;
|
|
50
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
51
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Connect to the voice daemon.
|
|
55
|
+
*/
|
|
56
|
+
async connect() {
|
|
57
|
+
if (this.connected) return;
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
try {
|
|
60
|
+
this.ws = new import_ws.default(this.options.url);
|
|
61
|
+
this.ws.on("open", () => {
|
|
62
|
+
this.connected = true;
|
|
63
|
+
this.reconnecting = false;
|
|
64
|
+
this.sendIdentify();
|
|
65
|
+
this.emit("connected");
|
|
66
|
+
resolve();
|
|
67
|
+
});
|
|
68
|
+
this.ws.on("message", (data) => {
|
|
69
|
+
this.handleMessage(data.toString("utf8"));
|
|
70
|
+
});
|
|
71
|
+
this.ws.on("close", () => {
|
|
72
|
+
this.connected = false;
|
|
73
|
+
this.emit("disconnected");
|
|
74
|
+
if (this.options.autoReconnect && !this.reconnecting) {
|
|
75
|
+
this.scheduleReconnect();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
this.ws.on("error", (err) => {
|
|
79
|
+
if (!this.connected) {
|
|
80
|
+
reject(err);
|
|
81
|
+
} else {
|
|
82
|
+
this.emit("error", err.message);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
} catch (err) {
|
|
86
|
+
reject(err);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Disconnect from the voice daemon.
|
|
92
|
+
*/
|
|
93
|
+
disconnect() {
|
|
94
|
+
this.reconnecting = false;
|
|
95
|
+
if (this.ws) {
|
|
96
|
+
this.ws.close();
|
|
97
|
+
this.ws = null;
|
|
98
|
+
}
|
|
99
|
+
this.connected = false;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Check if connected to the daemon.
|
|
103
|
+
*/
|
|
104
|
+
isConnected() {
|
|
105
|
+
return this.connected;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Register an event listener.
|
|
109
|
+
*/
|
|
110
|
+
on(event, callback) {
|
|
111
|
+
if (!this.listeners.has(event)) {
|
|
112
|
+
this.listeners.set(event, /* @__PURE__ */ new Set());
|
|
113
|
+
}
|
|
114
|
+
const callbacks = this.listeners.get(event);
|
|
115
|
+
callbacks.add(callback);
|
|
116
|
+
return () => {
|
|
117
|
+
callbacks.delete(callback);
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Execute a command on the daemon.
|
|
122
|
+
*/
|
|
123
|
+
async executeCommand(command) {
|
|
124
|
+
this.send({ type: "execute_command", command });
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Mute the voice assistant.
|
|
128
|
+
*/
|
|
129
|
+
mute() {
|
|
130
|
+
this.send({ type: "mute" });
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Unmute the voice assistant.
|
|
134
|
+
*/
|
|
135
|
+
unmute() {
|
|
136
|
+
this.send({ type: "unmute" });
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Ping the daemon.
|
|
140
|
+
*/
|
|
141
|
+
ping() {
|
|
142
|
+
this.send({ type: "ping", timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Simulate a wake word detection (for testing).
|
|
146
|
+
*/
|
|
147
|
+
simulateWake(wakeword = "codmir") {
|
|
148
|
+
this.send({ type: "wake_detected", wakeword, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
149
|
+
}
|
|
150
|
+
sendIdentify() {
|
|
151
|
+
this.send({
|
|
152
|
+
type: "identify",
|
|
153
|
+
clientId: this.options.clientId,
|
|
154
|
+
clientType: this.options.clientType,
|
|
155
|
+
version: "0.1.0"
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
send(message) {
|
|
159
|
+
if (this.ws && this.ws.readyState === import_ws.default.OPEN) {
|
|
160
|
+
this.ws.send(JSON.stringify(message));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
handleMessage(raw) {
|
|
164
|
+
let msg;
|
|
165
|
+
try {
|
|
166
|
+
msg = JSON.parse(raw);
|
|
167
|
+
} catch {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
switch (msg.type) {
|
|
171
|
+
case "daemon_started":
|
|
172
|
+
break;
|
|
173
|
+
case "pong":
|
|
174
|
+
break;
|
|
175
|
+
case "state_change":
|
|
176
|
+
this.emit("stateChange", msg.state, msg.previousState);
|
|
177
|
+
break;
|
|
178
|
+
case "wake":
|
|
179
|
+
this.emit("wake", msg.wakeword);
|
|
180
|
+
break;
|
|
181
|
+
case "transcript":
|
|
182
|
+
this.emit("transcript", msg.text, msg.isFinal);
|
|
183
|
+
break;
|
|
184
|
+
case "response":
|
|
185
|
+
this.emit("response", msg.text, msg.commands);
|
|
186
|
+
break;
|
|
187
|
+
case "command_executed":
|
|
188
|
+
this.emit("commandExecuted", msg.command, msg.success, msg.error);
|
|
189
|
+
break;
|
|
190
|
+
case "error":
|
|
191
|
+
this.emit("error", msg.message, msg.code);
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
emit(event, ...args) {
|
|
196
|
+
const callbacks = this.listeners.get(event);
|
|
197
|
+
if (!callbacks) return;
|
|
198
|
+
for (const cb of callbacks) {
|
|
199
|
+
try {
|
|
200
|
+
cb(...args);
|
|
201
|
+
} catch (err) {
|
|
202
|
+
console.error(`Error in ${event} listener:`, err);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
scheduleReconnect() {
|
|
207
|
+
this.reconnecting = true;
|
|
208
|
+
setTimeout(() => {
|
|
209
|
+
if (this.reconnecting) {
|
|
210
|
+
this.connect().catch(() => {
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}, this.options.reconnectDelay);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
var voice_agent_default = VoiceAgent;
|
|
217
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
218
|
+
0 && (module.exports = {
|
|
219
|
+
VoiceAgent
|
|
220
|
+
});
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import "../chunk-EBO3CZXG.mjs";
|
|
2
|
+
|
|
3
|
+
// src/voice-agent/index.ts
|
|
4
|
+
import WebSocket from "ws";
|
|
5
|
+
var DEFAULT_OPTIONS = {
|
|
6
|
+
url: "ws://127.0.0.1:9410",
|
|
7
|
+
clientId: "sdk-client",
|
|
8
|
+
clientType: "other",
|
|
9
|
+
autoReconnect: true,
|
|
10
|
+
reconnectDelay: 2e3
|
|
11
|
+
};
|
|
12
|
+
var VoiceAgent = class {
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
this.ws = null;
|
|
15
|
+
this.connected = false;
|
|
16
|
+
this.reconnecting = false;
|
|
17
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
18
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Connect to the voice daemon.
|
|
22
|
+
*/
|
|
23
|
+
async connect() {
|
|
24
|
+
if (this.connected) return;
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
try {
|
|
27
|
+
this.ws = new WebSocket(this.options.url);
|
|
28
|
+
this.ws.on("open", () => {
|
|
29
|
+
this.connected = true;
|
|
30
|
+
this.reconnecting = false;
|
|
31
|
+
this.sendIdentify();
|
|
32
|
+
this.emit("connected");
|
|
33
|
+
resolve();
|
|
34
|
+
});
|
|
35
|
+
this.ws.on("message", (data) => {
|
|
36
|
+
this.handleMessage(data.toString("utf8"));
|
|
37
|
+
});
|
|
38
|
+
this.ws.on("close", () => {
|
|
39
|
+
this.connected = false;
|
|
40
|
+
this.emit("disconnected");
|
|
41
|
+
if (this.options.autoReconnect && !this.reconnecting) {
|
|
42
|
+
this.scheduleReconnect();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
this.ws.on("error", (err) => {
|
|
46
|
+
if (!this.connected) {
|
|
47
|
+
reject(err);
|
|
48
|
+
} else {
|
|
49
|
+
this.emit("error", err.message);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
} catch (err) {
|
|
53
|
+
reject(err);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Disconnect from the voice daemon.
|
|
59
|
+
*/
|
|
60
|
+
disconnect() {
|
|
61
|
+
this.reconnecting = false;
|
|
62
|
+
if (this.ws) {
|
|
63
|
+
this.ws.close();
|
|
64
|
+
this.ws = null;
|
|
65
|
+
}
|
|
66
|
+
this.connected = false;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Check if connected to the daemon.
|
|
70
|
+
*/
|
|
71
|
+
isConnected() {
|
|
72
|
+
return this.connected;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Register an event listener.
|
|
76
|
+
*/
|
|
77
|
+
on(event, callback) {
|
|
78
|
+
if (!this.listeners.has(event)) {
|
|
79
|
+
this.listeners.set(event, /* @__PURE__ */ new Set());
|
|
80
|
+
}
|
|
81
|
+
const callbacks = this.listeners.get(event);
|
|
82
|
+
callbacks.add(callback);
|
|
83
|
+
return () => {
|
|
84
|
+
callbacks.delete(callback);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Execute a command on the daemon.
|
|
89
|
+
*/
|
|
90
|
+
async executeCommand(command) {
|
|
91
|
+
this.send({ type: "execute_command", command });
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Mute the voice assistant.
|
|
95
|
+
*/
|
|
96
|
+
mute() {
|
|
97
|
+
this.send({ type: "mute" });
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Unmute the voice assistant.
|
|
101
|
+
*/
|
|
102
|
+
unmute() {
|
|
103
|
+
this.send({ type: "unmute" });
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Ping the daemon.
|
|
107
|
+
*/
|
|
108
|
+
ping() {
|
|
109
|
+
this.send({ type: "ping", timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Simulate a wake word detection (for testing).
|
|
113
|
+
*/
|
|
114
|
+
simulateWake(wakeword = "codmir") {
|
|
115
|
+
this.send({ type: "wake_detected", wakeword, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
116
|
+
}
|
|
117
|
+
sendIdentify() {
|
|
118
|
+
this.send({
|
|
119
|
+
type: "identify",
|
|
120
|
+
clientId: this.options.clientId,
|
|
121
|
+
clientType: this.options.clientType,
|
|
122
|
+
version: "0.1.0"
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
send(message) {
|
|
126
|
+
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
127
|
+
this.ws.send(JSON.stringify(message));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
handleMessage(raw) {
|
|
131
|
+
let msg;
|
|
132
|
+
try {
|
|
133
|
+
msg = JSON.parse(raw);
|
|
134
|
+
} catch {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
switch (msg.type) {
|
|
138
|
+
case "daemon_started":
|
|
139
|
+
break;
|
|
140
|
+
case "pong":
|
|
141
|
+
break;
|
|
142
|
+
case "state_change":
|
|
143
|
+
this.emit("stateChange", msg.state, msg.previousState);
|
|
144
|
+
break;
|
|
145
|
+
case "wake":
|
|
146
|
+
this.emit("wake", msg.wakeword);
|
|
147
|
+
break;
|
|
148
|
+
case "transcript":
|
|
149
|
+
this.emit("transcript", msg.text, msg.isFinal);
|
|
150
|
+
break;
|
|
151
|
+
case "response":
|
|
152
|
+
this.emit("response", msg.text, msg.commands);
|
|
153
|
+
break;
|
|
154
|
+
case "command_executed":
|
|
155
|
+
this.emit("commandExecuted", msg.command, msg.success, msg.error);
|
|
156
|
+
break;
|
|
157
|
+
case "error":
|
|
158
|
+
this.emit("error", msg.message, msg.code);
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
emit(event, ...args) {
|
|
163
|
+
const callbacks = this.listeners.get(event);
|
|
164
|
+
if (!callbacks) return;
|
|
165
|
+
for (const cb of callbacks) {
|
|
166
|
+
try {
|
|
167
|
+
cb(...args);
|
|
168
|
+
} catch (err) {
|
|
169
|
+
console.error(`Error in ${event} listener:`, err);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
scheduleReconnect() {
|
|
174
|
+
this.reconnecting = true;
|
|
175
|
+
setTimeout(() => {
|
|
176
|
+
if (this.reconnecting) {
|
|
177
|
+
this.connect().catch(() => {
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}, this.options.reconnectDelay);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
var voice_agent_default = VoiceAgent;
|
|
184
|
+
export {
|
|
185
|
+
VoiceAgent,
|
|
186
|
+
voice_agent_default as default
|
|
187
|
+
};
|