@jambonz/sdk 0.3.0 → 0.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.
Files changed (40) hide show
  1. package/AGENTS.md +715 -0
  2. package/examples/agent/ws-app.ts +138 -0
  3. package/examples/assemblyai-autogenerate-prompt/app.js +92 -0
  4. package/examples/assemblyai-autogenerate-prompt/package.json +14 -0
  5. package/examples/bedrock-agent.ts +267 -0
  6. package/examples/call-recording/README.md +24 -0
  7. package/examples/call-recording/app.ts +70 -0
  8. package/examples/call-recording/ws-app.ts +47 -0
  9. package/examples/deepgram-voice-agent/ws-app.ts +118 -0
  10. package/examples/dial/app.ts +22 -0
  11. package/examples/echo/app.ts +65 -0
  12. package/examples/echo/ws-app.ts +67 -0
  13. package/examples/elevenlabs-voice-agent/ws-app.ts +81 -0
  14. package/examples/hello-world/README.md +15 -0
  15. package/examples/hello-world/app.js +20 -0
  16. package/examples/hello-world/app.ts +19 -0
  17. package/examples/hello-world/ws-app.ts +18 -0
  18. package/examples/ivr-menu/README.md +15 -0
  19. package/examples/ivr-menu/app.js +85 -0
  20. package/examples/ivr-menu/app.ts +70 -0
  21. package/examples/listen-record/app.ts +22 -0
  22. package/examples/llm-streaming/ws-app.ts +96 -0
  23. package/examples/openai-realtime/ws-app.ts +131 -0
  24. package/examples/queue-with-hold/README.md +19 -0
  25. package/examples/queue-with-hold/app.ts +68 -0
  26. package/examples/queue-with-hold/ws-app.ts +41 -0
  27. package/examples/realtime-translator/src/app.ts +21 -0
  28. package/examples/realtime-translator/src/routes/translator.ts +108 -0
  29. package/examples/realtime-translator/src/utils/config.ts +21 -0
  30. package/examples/realtime-translator/src/utils/translate.ts +23 -0
  31. package/examples/retell-hosted/src/app.ts +22 -0
  32. package/examples/retell-hosted/src/config.ts +53 -0
  33. package/examples/retell-hosted/src/retell.ts +166 -0
  34. package/examples/two-stage-dialer/app.ts +96 -0
  35. package/examples/ultravox-voice-agent/ws-app.ts +116 -0
  36. package/examples/voice-agent/README.md +19 -0
  37. package/examples/voice-agent/app.js +133 -0
  38. package/examples/voice-agent/app.ts +132 -0
  39. package/examples/voice-agent/ws-app.ts +137 -0
  40. package/package.json +8 -3
@@ -0,0 +1,137 @@
1
+ import http from 'http';
2
+ import { createEndpoint } from '@jambonz/sdk/websocket';
3
+
4
+ const server = http.createServer();
5
+ const makeService = createEndpoint({
6
+ server,
7
+ port: 3000,
8
+ envVars: {
9
+ OPENAI_API_KEY: {
10
+ type: 'string',
11
+ description: 'OpenAI API key',
12
+ required: true,
13
+ obscure: true,
14
+ },
15
+ },
16
+ });
17
+
18
+ const svc = makeService({ path: '/' });
19
+
20
+ const SYSTEM_PROMPT = `You are a helpful customer service agent for Acme Corp.
21
+ You help customers with order inquiries, returns, and general questions.
22
+ Be concise and friendly. Keep responses under 2-3 sentences when possible.
23
+ If you need to look up an order, use the lookupOrder function.
24
+ If the customer wants to speak to a human, use the transferToAgent function.`;
25
+
26
+ svc.on('session:new', (session) => {
27
+ console.log(`Incoming call: ${session.callSid}`);
28
+
29
+ const apiKey = session.data.env_vars?.OPENAI_API_KEY;
30
+ if (!apiKey) throw new Error('Set OPENAI_API_KEY in your jambonz application environment variables');
31
+
32
+ session
33
+ .config({
34
+ synthesizer: {
35
+ vendor: 'elevenlabs',
36
+ voice: 'Rachel',
37
+ language: 'en-US',
38
+ },
39
+ recognizer: {
40
+ vendor: 'deepgram',
41
+ language: 'en-US',
42
+ deepgramOptions: { model: 'nova-2', smartFormatting: true },
43
+ },
44
+ fillerNoise: {
45
+ enable: true,
46
+ url: 'https://example.com/sounds/typing.wav',
47
+ startDelaySecs: 2,
48
+ },
49
+ })
50
+ .openai_s2s({
51
+ model: 'gpt-4o',
52
+ auth: { apiKey },
53
+ llmOptions: {
54
+ messages: [{ role: 'system', content: SYSTEM_PROMPT }],
55
+ temperature: 0.7,
56
+ tools: [
57
+ {
58
+ type: 'function',
59
+ function: {
60
+ name: 'lookupOrder',
61
+ description: 'Look up an order by order number',
62
+ parameters: {
63
+ type: 'object',
64
+ properties: {
65
+ orderNumber: { type: 'string', description: 'The order number (e.g. ORD-12345)' },
66
+ },
67
+ required: ['orderNumber'],
68
+ },
69
+ },
70
+ },
71
+ {
72
+ type: 'function',
73
+ function: {
74
+ name: 'transferToAgent',
75
+ description: 'Transfer the call to a human agent',
76
+ parameters: {
77
+ type: 'object',
78
+ properties: {
79
+ reason: { type: 'string', description: 'Why the caller wants a human agent' },
80
+ },
81
+ required: ['reason'],
82
+ },
83
+ },
84
+ },
85
+ ],
86
+ },
87
+ actionHook: '/llm-complete',
88
+ })
89
+ .send();
90
+
91
+ // Handle tool calls over the WebSocket
92
+ session.on('llm:tool-call', (data: Record<string, unknown>) => {
93
+ const tool = data.tool as { name: string; args: Record<string, string>; tool_call_id: string };
94
+
95
+ switch (tool.name) {
96
+ case 'lookupOrder': {
97
+ const order = {
98
+ orderNumber: tool.args.orderNumber,
99
+ status: 'shipped',
100
+ trackingNumber: 'TRK-98765',
101
+ estimatedDelivery: '2026-02-20',
102
+ };
103
+ session.sendToolOutput(tool.tool_call_id, { result: JSON.stringify(order) });
104
+ break;
105
+ }
106
+
107
+ case 'transferToAgent': {
108
+ session.sendToolOutput(tool.tool_call_id, { result: 'Transferring to agent' });
109
+ session
110
+ .say({ text: 'Let me connect you to a human agent. Please hold.' })
111
+ .dial({
112
+ target: [{ type: 'user', name: 'support-queue' }],
113
+ answerOnBridge: true,
114
+ timeout: 60,
115
+ })
116
+ .say({ text: 'Sorry, no agents are available. Please try again later.' })
117
+ .hangup()
118
+ .send();
119
+ break;
120
+ }
121
+
122
+ default:
123
+ session.sendToolOutput(tool.tool_call_id, { result: 'Unknown tool' });
124
+ }
125
+ });
126
+
127
+ // Handle LLM conversation end
128
+ session.on('/llm-complete', (data: Record<string, unknown>) => {
129
+ console.log('LLM conversation ended:', data.reason);
130
+ session
131
+ .say({ text: 'Thank you for calling Acme Corp. Goodbye!' })
132
+ .hangup()
133
+ .reply();
134
+ });
135
+ });
136
+
137
+ console.log('Voice agent ws app listening on port 3000');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jambonz/sdk",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "jambonz SDK for building voice applications — optimized for AI agents",
5
5
  "author": "Dave Horton",
6
6
  "license": "MIT",
@@ -77,7 +77,9 @@
77
77
  }
78
78
  },
79
79
  "files": [
80
- "dist"
80
+ "dist",
81
+ "AGENTS.md",
82
+ "examples"
81
83
  ],
82
84
  "scripts": {
83
85
  "build": "tsup",
@@ -87,7 +89,10 @@
87
89
  "typecheck": "tsc --noEmit",
88
90
  "lint": "eslint src/",
89
91
  "docs": "typedoc",
90
- "prepublishOnly": "npm run build"
92
+ "copy-docs": "cp ../AGENTS.md . && cp -r ../examples .",
93
+ "clean-docs": "rm -f AGENTS.md && rm -rf examples",
94
+ "prepublishOnly": "npm run copy-docs && npm run build",
95
+ "postpublish": "npm run clean-docs"
91
96
  },
92
97
  "dependencies": {
93
98
  "@jambonz/schema": "^0.2.1",