@voicethere/agent 0.1.6 → 0.1.7
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/package.json +1 -1
- package/templates/README.md +17 -0
- package/templates/echo.ts +65 -0
package/package.json
CHANGED
package/templates/README.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Agent templates
|
|
2
2
|
|
|
3
|
+
## `echo.ts`
|
|
4
|
+
|
|
5
|
+
Full echo debug agent for the VoiceThere dashboard — speaks **"you said: …"** on voice finals and text chat, relays speech events over DataChannel, and echoes chat replies on DC.
|
|
6
|
+
|
|
7
|
+
**Build:**
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @voicethere/agent
|
|
11
|
+
npx @voicethere/agent build --entry templates/echo.ts
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Platform auto-seeds the built bundle when a project is created with the **Echo (voice + chat)** template.
|
|
15
|
+
|
|
16
|
+
## `echo-dc.ts`
|
|
17
|
+
|
|
18
|
+
Data-channel-only echo — relays speech events and chat text over DC without TTS. Use when debugging the dashboard chat panel without agent playback.
|
|
19
|
+
|
|
3
20
|
## `agent.ts`
|
|
4
21
|
|
|
5
22
|
Full starter bundle covering every speech event from `@node-webrtc-rust/sdk/voice`:
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Full echo agent — speaks and chats back "you said: …" for voice and text.
|
|
3
|
+
*
|
|
4
|
+
* Build:
|
|
5
|
+
* npm install @voicethere/agent
|
|
6
|
+
* npx @voicethere/agent build --entry templates/echo.ts
|
|
7
|
+
*/
|
|
8
|
+
import {
|
|
9
|
+
agentLog,
|
|
10
|
+
defineAgent,
|
|
11
|
+
parseChatText,
|
|
12
|
+
sendToClient,
|
|
13
|
+
speak,
|
|
14
|
+
type SpeechEvent,
|
|
15
|
+
} from "@voicethere/agent";
|
|
16
|
+
|
|
17
|
+
const echoPrefix =
|
|
18
|
+
(process.env.AGENT_ECHO_PREFIX ?? "you said:").trim() || "you said:";
|
|
19
|
+
|
|
20
|
+
function formatEcho(text: string): string {
|
|
21
|
+
return `${echoPrefix} ${text}`.trim();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
defineAgent({
|
|
25
|
+
onSessionStart({ sessionId }) {
|
|
26
|
+
sendToClient(sessionId, {
|
|
27
|
+
type: "agent_event",
|
|
28
|
+
event: "session_start",
|
|
29
|
+
sessionId,
|
|
30
|
+
});
|
|
31
|
+
agentLog("info", `echo session_start ${sessionId}`);
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
onSpeechEvent({ sessionId }, event: SpeechEvent) {
|
|
35
|
+
sendToClient(sessionId, {
|
|
36
|
+
type: "agent_event",
|
|
37
|
+
event: event.type,
|
|
38
|
+
text: event.text,
|
|
39
|
+
raw: event,
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
onUserSpeechFinal({ sessionId, text }) {
|
|
44
|
+
const reply = formatEcho(text);
|
|
45
|
+
speak(sessionId, reply);
|
|
46
|
+
sendToClient(sessionId, { type: "chat_reply", text: reply });
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
onDataChannelMessage(ctx) {
|
|
50
|
+
const text = parseChatText(ctx.message);
|
|
51
|
+
if (!text) return;
|
|
52
|
+
const reply = formatEcho(text);
|
|
53
|
+
sendToClient(ctx.sessionId, { type: "chat_reply", text: reply });
|
|
54
|
+
speak(ctx.sessionId, reply);
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
onSessionEnd({ sessionId }) {
|
|
58
|
+
sendToClient(sessionId, {
|
|
59
|
+
type: "agent_event",
|
|
60
|
+
event: "session_end",
|
|
61
|
+
sessionId,
|
|
62
|
+
});
|
|
63
|
+
agentLog("info", `echo session_end ${sessionId}`);
|
|
64
|
+
},
|
|
65
|
+
});
|