@openai/agents-realtime 0.0.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/LICENSE +21 -0
- package/README.md +13 -0
- package/dist/bundle/openai-realtime-agents.mjs +8777 -0
- package/dist/bundle/openai-realtime-agents.umd.js +11 -0
- package/dist/clientMessages.d.ts +40 -0
- package/dist/clientMessages.js +2 -0
- package/dist/clientMessages.js.map +1 -0
- package/dist/clientMessages.mjs +2 -0
- package/dist/clientMessages.mjs.map +1 -0
- package/dist/guardrail.d.ts +32 -0
- package/dist/guardrail.js +34 -0
- package/dist/guardrail.js.map +1 -0
- package/dist/guardrail.mjs +34 -0
- package/dist/guardrail.mjs.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +13 -0
- package/dist/index.mjs.map +1 -0
- package/dist/items.d.ts +183 -0
- package/dist/items.js +47 -0
- package/dist/items.js.map +1 -0
- package/dist/items.mjs +47 -0
- package/dist/items.mjs.map +1 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +4 -0
- package/dist/logger.js.map +1 -0
- package/dist/logger.mjs +4 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/metadata.d.ts +9 -0
- package/dist/metadata.js +11 -0
- package/dist/metadata.js.map +1 -0
- package/dist/metadata.mjs +11 -0
- package/dist/metadata.mjs.map +1 -0
- package/dist/openaiRealtimeBase.d.ts +143 -0
- package/dist/openaiRealtimeBase.js +449 -0
- package/dist/openaiRealtimeBase.js.map +1 -0
- package/dist/openaiRealtimeBase.mjs +449 -0
- package/dist/openaiRealtimeBase.mjs.map +1 -0
- package/dist/openaiRealtimeEvents.d.ts +3242 -0
- package/dist/openaiRealtimeEvents.js +439 -0
- package/dist/openaiRealtimeEvents.js.map +1 -0
- package/dist/openaiRealtimeEvents.mjs +439 -0
- package/dist/openaiRealtimeEvents.mjs.map +1 -0
- package/dist/openaiRealtimeWebRtc.d.ts +102 -0
- package/dist/openaiRealtimeWebRtc.js +245 -0
- package/dist/openaiRealtimeWebRtc.js.map +1 -0
- package/dist/openaiRealtimeWebRtc.mjs +245 -0
- package/dist/openaiRealtimeWebRtc.mjs.map +1 -0
- package/dist/openaiRealtimeWebsocket.d.ts +126 -0
- package/dist/openaiRealtimeWebsocket.js +293 -0
- package/dist/openaiRealtimeWebsocket.js.map +1 -0
- package/dist/openaiRealtimeWebsocket.mjs +293 -0
- package/dist/openaiRealtimeWebsocket.mjs.map +1 -0
- package/dist/realtimeAgent.d.ts +49 -0
- package/dist/realtimeAgent.js +37 -0
- package/dist/realtimeAgent.js.map +1 -0
- package/dist/realtimeAgent.mjs +37 -0
- package/dist/realtimeAgent.mjs.map +1 -0
- package/dist/realtimeSession.d.ts +210 -0
- package/dist/realtimeSession.js +469 -0
- package/dist/realtimeSession.js.map +1 -0
- package/dist/realtimeSession.mjs +469 -0
- package/dist/realtimeSession.mjs.map +1 -0
- package/dist/realtimeSessionEvents.d.ts +118 -0
- package/dist/realtimeSessionEvents.js +2 -0
- package/dist/realtimeSessionEvents.js.map +1 -0
- package/dist/realtimeSessionEvents.mjs +2 -0
- package/dist/realtimeSessionEvents.mjs.map +1 -0
- package/dist/shims/shims-browser.d.ts +9 -0
- package/dist/shims/shims-browser.js +6 -0
- package/dist/shims/shims-browser.js.map +1 -0
- package/dist/shims/shims-browser.mjs +6 -0
- package/dist/shims/shims-browser.mjs.map +1 -0
- package/dist/shims/shims-node.d.ts +2 -0
- package/dist/shims/shims-node.js +5 -0
- package/dist/shims/shims-node.js.map +1 -0
- package/dist/shims/shims-node.mjs +5 -0
- package/dist/shims/shims-node.mjs.map +1 -0
- package/dist/shims/shims.d.ts +1 -0
- package/dist/shims/shims.js +2 -0
- package/dist/shims/shims.js.map +1 -0
- package/dist/shims/shims.mjs +2 -0
- package/dist/shims/shims.mjs.map +1 -0
- package/dist/transportLayer.d.ts +96 -0
- package/dist/transportLayer.js +2 -0
- package/dist/transportLayer.js.map +1 -0
- package/dist/transportLayer.mjs +2 -0
- package/dist/transportLayer.mjs.map +1 -0
- package/dist/transportLayerEvents.d.ts +99 -0
- package/dist/transportLayerEvents.js +2 -0
- package/dist/transportLayerEvents.js.map +1 -0
- package/dist/transportLayerEvents.mjs +2 -0
- package/dist/transportLayerEvents.mjs.map +1 -0
- package/dist/utils.d.ts +61 -0
- package/dist/utils.js +183 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +183 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
import { getHandoff, getTransferMessage, ModelBehaviorError, OutputGuardrailTripwireTriggered, RunContext, RunToolApprovalItem, } from '@openai/agents-core';
|
|
2
|
+
import { RuntimeEventEmitter } from '@openai/agents-core/_shims';
|
|
3
|
+
import { isZodObject, toSmartString } from '@openai/agents-core/utils';
|
|
4
|
+
import { defineRealtimeOutputGuardrail, getRealtimeGuardrailFeedbackMessage, getRealtimeGuardrailSettings, } from "./guardrail.js";
|
|
5
|
+
import { OpenAIRealtimeWebRTC } from "./openaiRealtimeWebRtc.js";
|
|
6
|
+
import { OpenAIRealtimeWebSocket } from "./openaiRealtimeWebsocket.js";
|
|
7
|
+
import { getLastTextFromAudioOutputMessage, hasWebRTCSupport, updateRealtimeHistory, } from "./utils.js";
|
|
8
|
+
import logger from "./logger.js";
|
|
9
|
+
/**
|
|
10
|
+
* A `RealtimeSession` is the corner piece of building Voice Agents. It's the equivalent of a
|
|
11
|
+
* Runner in text-based agents except that it automatically handles multiple turns by maintaining a
|
|
12
|
+
* connection with the underlying transport layer.
|
|
13
|
+
*
|
|
14
|
+
* The session handles managing the local history copy, executes tools, runs output guardrails, and
|
|
15
|
+
* facilities handoffs.
|
|
16
|
+
*
|
|
17
|
+
* The actual audio handling and generation of model responses is handled by the underlying
|
|
18
|
+
* transport layer. By default if you are using a browser with WebRTC support, the session will
|
|
19
|
+
* automatically use the WebRTC version of the OpenAI Realtime API. On the server or if you pass
|
|
20
|
+
* `websocket` as the transport layer, the session will establish a connection using WebSockets.
|
|
21
|
+
*
|
|
22
|
+
* In the case of WebRTC, in the browser, the transport layer will also automatically configure the
|
|
23
|
+
* microphone and audio output to be used by the session.
|
|
24
|
+
*
|
|
25
|
+
* You can also create a transport layer instance yourself and pass it in to have more control over
|
|
26
|
+
* the configuration or even extend the existing ones. Check out the `TwilioRealtimeTransportLayer`
|
|
27
|
+
* for an example of how to create a custom transport layer.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const agent = new RealtimeAgent({
|
|
32
|
+
* name: 'my-agent',
|
|
33
|
+
* instructions: 'You are a helpful assistant that can answer questions and help with tasks.',
|
|
34
|
+
* })
|
|
35
|
+
*
|
|
36
|
+
* const session = new RealtimeSession(agent);
|
|
37
|
+
* session.connect({
|
|
38
|
+
* apiKey: 'your-api-key',
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export class RealtimeSession extends RuntimeEventEmitter {
|
|
43
|
+
initialAgent;
|
|
44
|
+
options;
|
|
45
|
+
#transport;
|
|
46
|
+
#currentAgent;
|
|
47
|
+
#currentTools = [];
|
|
48
|
+
#context;
|
|
49
|
+
#outputGuardrails = [];
|
|
50
|
+
#outputGuardrailSettings;
|
|
51
|
+
#transcribedTextDeltas = {};
|
|
52
|
+
#history = [];
|
|
53
|
+
#shouldIncludeAudioData;
|
|
54
|
+
constructor(initialAgent, options = {}) {
|
|
55
|
+
super();
|
|
56
|
+
this.initialAgent = initialAgent;
|
|
57
|
+
this.options = options;
|
|
58
|
+
if ((typeof options.transport === 'undefined' && hasWebRTCSupport()) ||
|
|
59
|
+
options.transport === 'webrtc') {
|
|
60
|
+
this.#transport = new OpenAIRealtimeWebRTC();
|
|
61
|
+
}
|
|
62
|
+
else if (options.transport === 'websocket' ||
|
|
63
|
+
typeof options.transport === 'undefined') {
|
|
64
|
+
this.#transport = new OpenAIRealtimeWebSocket();
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this.#transport = options.transport;
|
|
68
|
+
}
|
|
69
|
+
this.#currentAgent = initialAgent;
|
|
70
|
+
this.#context = new RunContext({
|
|
71
|
+
...(options.context ?? {}),
|
|
72
|
+
history: this.#history,
|
|
73
|
+
});
|
|
74
|
+
this.#outputGuardrails = (options.outputGuardrails ?? []).map(defineRealtimeOutputGuardrail);
|
|
75
|
+
this.#outputGuardrailSettings = getRealtimeGuardrailSettings(options.outputGuardrailSettings ?? {});
|
|
76
|
+
this.#shouldIncludeAudioData = options.historyStoreAudio ?? false;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The transport layer used by the session.
|
|
80
|
+
*/
|
|
81
|
+
get transport() {
|
|
82
|
+
return this.#transport;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The current agent in the session.
|
|
86
|
+
*/
|
|
87
|
+
get currentAgent() {
|
|
88
|
+
return this.#currentAgent;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The current usage of the session.
|
|
92
|
+
*/
|
|
93
|
+
get usage() {
|
|
94
|
+
return this.#context.usage;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The current context of the session.
|
|
98
|
+
*/
|
|
99
|
+
get context() {
|
|
100
|
+
return this.#context;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Whether the session is muted. Might be `null` if the underlying transport layer does not
|
|
104
|
+
* support muting.
|
|
105
|
+
*/
|
|
106
|
+
get muted() {
|
|
107
|
+
return this.#transport.muted;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The history of the session.
|
|
111
|
+
*/
|
|
112
|
+
get history() {
|
|
113
|
+
return this.#history;
|
|
114
|
+
}
|
|
115
|
+
async #setCurrentAgent(agent) {
|
|
116
|
+
this.#currentAgent = agent;
|
|
117
|
+
const handoffs = this.#currentAgent.handoffs.map(getHandoff);
|
|
118
|
+
const handoffTools = handoffs.map((handoff) => handoff.getHandoffAsFunctionTool());
|
|
119
|
+
this.#currentTools = [
|
|
120
|
+
...(await this.#currentAgent.getAllTools()).filter((tool) => tool.type === 'function'),
|
|
121
|
+
...handoffTools,
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
async #getSessionConfig(additionalConfig = {}) {
|
|
125
|
+
const instructions = await this.#currentAgent.getSystemPrompt(this.#context);
|
|
126
|
+
const tracingConfig = this.options
|
|
127
|
+
.tracingDisabled
|
|
128
|
+
? null
|
|
129
|
+
: this.options.workflowName
|
|
130
|
+
? {
|
|
131
|
+
workflow_name: this.options.workflowName,
|
|
132
|
+
}
|
|
133
|
+
: 'auto';
|
|
134
|
+
if (tracingConfig !== null && tracingConfig !== 'auto') {
|
|
135
|
+
if (this.options.groupId) {
|
|
136
|
+
tracingConfig.group_id = this.options.groupId;
|
|
137
|
+
}
|
|
138
|
+
if (this.options.traceMetadata) {
|
|
139
|
+
tracingConfig.metadata = this.options.traceMetadata;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else if (this.options.groupId || this.options.traceMetadata) {
|
|
143
|
+
logger.warn('In order to set traceMetadata or a groupId you need to specify a workflowName.');
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
instructions,
|
|
147
|
+
voice: this.#currentAgent.voice,
|
|
148
|
+
model: this.options.model,
|
|
149
|
+
tools: this.#currentTools,
|
|
150
|
+
tracing: tracingConfig,
|
|
151
|
+
...additionalConfig,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
async updateAgent(newAgent) {
|
|
155
|
+
this.#currentAgent.emit('agent_handoff', this.#context, newAgent);
|
|
156
|
+
this.emit('agent_handoff', this.#context, this.#currentAgent, newAgent);
|
|
157
|
+
await this.#setCurrentAgent(newAgent);
|
|
158
|
+
await this.#transport.updateSessionConfig(await this.#getSessionConfig());
|
|
159
|
+
return newAgent;
|
|
160
|
+
}
|
|
161
|
+
async #handleHandoff(toolCall, handoff) {
|
|
162
|
+
const newAgent = (await handoff.onInvokeHandoff(this.#context, toolCall.arguments));
|
|
163
|
+
this.#currentAgent.emit('agent_handoff', this.#context, newAgent);
|
|
164
|
+
this.emit('agent_handoff', this.#context, this.#currentAgent, newAgent);
|
|
165
|
+
// update session with new agent
|
|
166
|
+
await this.#setCurrentAgent(newAgent);
|
|
167
|
+
await this.#transport.updateSessionConfig(await this.#getSessionConfig());
|
|
168
|
+
const output = getTransferMessage(newAgent);
|
|
169
|
+
this.#transport.sendFunctionCallOutput(toolCall, output, true);
|
|
170
|
+
return newAgent;
|
|
171
|
+
}
|
|
172
|
+
async #handleFunctionToolCall(toolCall, tool) {
|
|
173
|
+
this.#context.context.history = JSON.parse(JSON.stringify(this.#history)); // deep copy of the history
|
|
174
|
+
let parsedArgs = toolCall.arguments;
|
|
175
|
+
if (tool.parameters) {
|
|
176
|
+
if (isZodObject(tool.parameters)) {
|
|
177
|
+
parsedArgs = tool.parameters.parse(parsedArgs);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
parsedArgs = JSON.parse(parsedArgs);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const needsApproval = await tool.needsApproval(this.#context, parsedArgs, toolCall.callId);
|
|
184
|
+
if (needsApproval) {
|
|
185
|
+
const approval = this.context.isToolApproved({
|
|
186
|
+
toolName: tool.name,
|
|
187
|
+
callId: toolCall.callId,
|
|
188
|
+
});
|
|
189
|
+
if (approval === false) {
|
|
190
|
+
this.emit('agent_tool_start', this.#context, this.#currentAgent, tool);
|
|
191
|
+
this.#currentAgent.emit('agent_tool_start', this.#context, tool);
|
|
192
|
+
const result = 'Tool execution was not approved.';
|
|
193
|
+
this.#transport.sendFunctionCallOutput(toolCall, result, true);
|
|
194
|
+
this.emit('agent_tool_end', this.#context, this.#currentAgent, tool, result);
|
|
195
|
+
this.#currentAgent.emit('agent_tool_end', this.#context, tool, result);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
else if (typeof approval === 'undefined') {
|
|
199
|
+
this.emit('tool_approval_requested', this.#context, this.#currentAgent, {
|
|
200
|
+
type: 'function_approval',
|
|
201
|
+
tool,
|
|
202
|
+
approvalItem: new RunToolApprovalItem(toolCall, this.#currentAgent),
|
|
203
|
+
});
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
this.emit('agent_tool_start', this.#context, this.#currentAgent, tool);
|
|
208
|
+
this.#currentAgent.emit('agent_tool_start', this.#context, tool);
|
|
209
|
+
this.#context.context.history = JSON.parse(JSON.stringify(this.#history)); // deep copy of the history
|
|
210
|
+
const result = await tool.invoke(this.#context, toolCall.arguments);
|
|
211
|
+
const stringResult = toSmartString(result);
|
|
212
|
+
this.#transport.sendFunctionCallOutput(toolCall, stringResult, true);
|
|
213
|
+
this.emit('agent_tool_end', this.#context, this.#currentAgent, tool, stringResult);
|
|
214
|
+
this.#currentAgent.emit('agent_tool_end', this.#context, tool, stringResult);
|
|
215
|
+
}
|
|
216
|
+
async #handleFunctionCall(toolCall) {
|
|
217
|
+
const handoffMap = new Map(this.#currentAgent.handoffs
|
|
218
|
+
.map(getHandoff)
|
|
219
|
+
.map((handoff) => [handoff.toolName, handoff]));
|
|
220
|
+
const functionToolMap = new Map((await this.#currentAgent.getAllTools()).map((tool) => [tool.name, tool]));
|
|
221
|
+
const possibleHandoff = handoffMap.get(toolCall.name);
|
|
222
|
+
if (possibleHandoff) {
|
|
223
|
+
await this.#handleHandoff(toolCall, possibleHandoff);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
const functionTool = functionToolMap.get(toolCall.name);
|
|
227
|
+
if (functionTool && functionTool.type === 'function') {
|
|
228
|
+
await this.#handleFunctionToolCall(toolCall, functionTool);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
throw new ModelBehaviorError(`Tool ${toolCall.name} not found`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async #runOutputGuardrails(output) {
|
|
236
|
+
if (this.#outputGuardrails.length === 0) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const guardrailArgs = {
|
|
240
|
+
agent: this.#currentAgent,
|
|
241
|
+
agentOutput: output,
|
|
242
|
+
context: this.#context,
|
|
243
|
+
};
|
|
244
|
+
const results = await Promise.all(this.#outputGuardrails.map((guardrail) => guardrail.run(guardrailArgs)));
|
|
245
|
+
for (const result of results) {
|
|
246
|
+
if (result.output.tripwireTriggered) {
|
|
247
|
+
const error = new OutputGuardrailTripwireTriggered(`Output guardrail triggered: ${JSON.stringify(result.output.outputInfo)}`, result);
|
|
248
|
+
this.emit('guardrail_tripped', this.#context, this.#currentAgent, error);
|
|
249
|
+
this.interrupt();
|
|
250
|
+
const feedbackText = getRealtimeGuardrailFeedbackMessage(result);
|
|
251
|
+
this.sendMessage(feedbackText);
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
#setEventListeners() {
|
|
257
|
+
this.#transport.on('*', (event) => {
|
|
258
|
+
this.emit('transport_event', event);
|
|
259
|
+
});
|
|
260
|
+
this.#transport.on('audio', (event) => {
|
|
261
|
+
this.emit('audio', event);
|
|
262
|
+
});
|
|
263
|
+
this.#transport.on('turn_started', () => {
|
|
264
|
+
this.emit('agent_start', this.#context, this.#currentAgent);
|
|
265
|
+
this.#currentAgent.emit('agent_start', this.#context, this.#currentAgent);
|
|
266
|
+
});
|
|
267
|
+
this.#transport.on('turn_done', (event) => {
|
|
268
|
+
const item = event.response.output[event.response.output.length - 1];
|
|
269
|
+
const textOutput = getLastTextFromAudioOutputMessage(item) ?? '';
|
|
270
|
+
this.emit('agent_end', this.#context, this.#currentAgent, textOutput);
|
|
271
|
+
this.#currentAgent.emit('agent_end', this.#context, textOutput);
|
|
272
|
+
this.#runOutputGuardrails(textOutput);
|
|
273
|
+
});
|
|
274
|
+
this.#transport.on('audio_done', () => {
|
|
275
|
+
this.emit('audio_stopped', this.#context, this.#currentAgent);
|
|
276
|
+
});
|
|
277
|
+
let lastRunIndex = 0;
|
|
278
|
+
let lastItemId;
|
|
279
|
+
this.#transport.on('audio_transcript_delta', (event) => {
|
|
280
|
+
try {
|
|
281
|
+
const delta = event.delta;
|
|
282
|
+
const itemId = event.itemId;
|
|
283
|
+
if (lastItemId !== itemId) {
|
|
284
|
+
lastItemId = itemId;
|
|
285
|
+
lastRunIndex = 0;
|
|
286
|
+
}
|
|
287
|
+
const currentText = this.#transcribedTextDeltas[itemId] ?? '';
|
|
288
|
+
const newText = currentText + delta;
|
|
289
|
+
this.#transcribedTextDeltas[itemId] = newText;
|
|
290
|
+
if (this.#outputGuardrailSettings.debounceTextLength < 0) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const newRunIndex = Math.floor(newText.length / this.#outputGuardrailSettings.debounceTextLength);
|
|
294
|
+
if (newRunIndex > lastRunIndex) {
|
|
295
|
+
lastRunIndex = newRunIndex;
|
|
296
|
+
// We don't cancel existing runs because we want the first one to fail to fail
|
|
297
|
+
// The transport layer should upon failure handle the interruption and stop the model
|
|
298
|
+
// from generating further
|
|
299
|
+
this.#runOutputGuardrails(newText);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
catch (err) {
|
|
303
|
+
this.emit('error', {
|
|
304
|
+
type: 'error',
|
|
305
|
+
error: err,
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
this.#transport.on('item_update', (event) => {
|
|
310
|
+
try {
|
|
311
|
+
const isNew = !this.#history.some((item) => item.itemId === event.itemId);
|
|
312
|
+
this.#history = updateRealtimeHistory(this.#history, event, this.#shouldIncludeAudioData);
|
|
313
|
+
this.#context.context.history = this.#history;
|
|
314
|
+
if (isNew) {
|
|
315
|
+
const addedItem = this.#history.find((item) => item.itemId === event.itemId);
|
|
316
|
+
if (addedItem) {
|
|
317
|
+
this.emit('history_added', addedItem);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
this.emit('history_updated', this.#history);
|
|
321
|
+
}
|
|
322
|
+
catch (err) {
|
|
323
|
+
this.emit('error', {
|
|
324
|
+
type: 'error',
|
|
325
|
+
error: err,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
this.#transport.on('item_deleted', (event) => {
|
|
330
|
+
try {
|
|
331
|
+
this.#history = this.#history.filter((item) => item.itemId !== event.itemId);
|
|
332
|
+
this.#context.context.history = this.#history;
|
|
333
|
+
this.emit('history_updated', this.#history);
|
|
334
|
+
}
|
|
335
|
+
catch (err) {
|
|
336
|
+
this.emit('error', {
|
|
337
|
+
type: 'error',
|
|
338
|
+
error: err,
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
this.#transport.on('function_call', async (event) => {
|
|
343
|
+
try {
|
|
344
|
+
await this.#handleFunctionCall(event);
|
|
345
|
+
}
|
|
346
|
+
catch (error) {
|
|
347
|
+
logger.error('Error handling function call', error);
|
|
348
|
+
this.emit('error', {
|
|
349
|
+
type: 'error',
|
|
350
|
+
error,
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
this.#transport.on('usage_update', (usage) => {
|
|
355
|
+
this.#context.usage.add(usage);
|
|
356
|
+
});
|
|
357
|
+
this.#transport.on('audio_interrupted', () => {
|
|
358
|
+
this.emit('audio_interrupted', this.#context, this.#currentAgent);
|
|
359
|
+
});
|
|
360
|
+
this.#transport.on('error', (error) => {
|
|
361
|
+
this.emit('error', error);
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Connect to the session. This will establish the connection to the underlying transport layer
|
|
366
|
+
* and start the session.
|
|
367
|
+
*
|
|
368
|
+
* After connecting, the session will also emit a `history_updated` event with an empty history.
|
|
369
|
+
*
|
|
370
|
+
* @param options - The options for the connection.
|
|
371
|
+
*/
|
|
372
|
+
async connect(options) {
|
|
373
|
+
// makes sure the current agent is correctly set and loads the tools
|
|
374
|
+
await this.#setCurrentAgent(this.initialAgent);
|
|
375
|
+
this.#setEventListeners();
|
|
376
|
+
await this.#transport.connect({
|
|
377
|
+
apiKey: options.apiKey ?? this.options.apiKey,
|
|
378
|
+
model: this.options.model,
|
|
379
|
+
initialSessionConfig: await this.#getSessionConfig(this.options.config),
|
|
380
|
+
});
|
|
381
|
+
this.#history = [];
|
|
382
|
+
this.emit('history_updated', this.#history);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Update the history of the session.
|
|
386
|
+
* @param newHistory - The new history to set.
|
|
387
|
+
*/
|
|
388
|
+
updateHistory(newHistory) {
|
|
389
|
+
let updatedHistory;
|
|
390
|
+
if (typeof newHistory === 'function') {
|
|
391
|
+
updatedHistory = newHistory(this.#history);
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
updatedHistory = newHistory;
|
|
395
|
+
}
|
|
396
|
+
this.#transport.resetHistory(this.#history, updatedHistory);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Send a message to the session.
|
|
400
|
+
* @param message - The message to send.
|
|
401
|
+
* @param otherEventData - Additional event data to send.
|
|
402
|
+
*/
|
|
403
|
+
sendMessage(message, otherEventData = {}) {
|
|
404
|
+
this.#transport.sendMessage(message, otherEventData);
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Mute the session.
|
|
408
|
+
* @param muted - Whether to mute the session.
|
|
409
|
+
*/
|
|
410
|
+
mute(muted) {
|
|
411
|
+
this.#transport.mute(muted);
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Disconnect from the session.
|
|
415
|
+
*/
|
|
416
|
+
close() {
|
|
417
|
+
this.#transport.close();
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Send audio to the session.
|
|
421
|
+
* @param audio - The audio to send.
|
|
422
|
+
* @param options - Additional options.
|
|
423
|
+
* @param options.commit - Whether to finish the turn with this audio.
|
|
424
|
+
*/
|
|
425
|
+
sendAudio(audio, options = {}) {
|
|
426
|
+
this.#transport.sendAudio(audio, options);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Interrupt the session artificially for example if you want to build a "stop talking"
|
|
430
|
+
* button.
|
|
431
|
+
*/
|
|
432
|
+
interrupt() {
|
|
433
|
+
this.#transport.interrupt();
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Approve a tool call. This will also trigger the tool call to the agent.
|
|
437
|
+
* @param approvalItem - The approval item to approve.
|
|
438
|
+
* @param options - Additional options.
|
|
439
|
+
* @param options.alwaysApprove - Whether to always approve the tool call.
|
|
440
|
+
*/
|
|
441
|
+
async approve(approvalItem, options = { alwaysApprove: false }) {
|
|
442
|
+
this.#context.approveTool(approvalItem, options);
|
|
443
|
+
const tool = this.#currentAgent.tools.find((tool) => tool.name === approvalItem.rawItem.name);
|
|
444
|
+
if (tool && tool.type === 'function') {
|
|
445
|
+
await this.#handleFunctionToolCall(approvalItem.rawItem, tool);
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
throw new ModelBehaviorError(`Tool ${approvalItem.rawItem.name} not found`);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Reject a tool call. This will also trigger the tool call to the agent.
|
|
453
|
+
* @param approvalItem - The approval item to reject.
|
|
454
|
+
* @param options - Additional options.
|
|
455
|
+
* @param options.alwaysReject - Whether to always reject the tool call.
|
|
456
|
+
*/
|
|
457
|
+
async reject(approvalItem, options = { alwaysReject: false }) {
|
|
458
|
+
this.#context.rejectTool(approvalItem, options);
|
|
459
|
+
// we still need to simulate a tool call to the agent to let the agent know
|
|
460
|
+
const tool = this.#currentAgent.tools.find((tool) => tool.name === approvalItem.rawItem.name);
|
|
461
|
+
if (tool && tool.type === 'function') {
|
|
462
|
+
await this.#handleFunctionToolCall(approvalItem.rawItem, tool);
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
throw new ModelBehaviorError(`Tool ${approvalItem.rawItem.name} not found`);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
//# sourceMappingURL=realtimeSession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"realtimeSession.js","sourceRoot":"","sources":["../src/realtimeSession.ts"],"names":[],"mappings":"OAAO,EAEL,UAAU,EACV,kBAAkB,EAElB,kBAAkB,EAElB,gCAAgC,EAChC,UAAU,EAEV,mBAAmB,GAEpB,MAAM,qBAAqB;OACrB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B;OACzD,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,2BAA2B;OAO/D,EACL,6BAA6B,EAC7B,mCAAmC,EACnC,4BAA4B,GAI7B;OAGM,EAAE,oBAAoB,EAAE;OACxB,EAAE,uBAAuB,EAAE;OAK3B,EACL,iCAAiC,EACjC,gBAAgB,EAChB,qBAAqB,GACtB;OACM,MAAM;AA6Fb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,OAAO,eAEX,SAAQ,mBAA4D;IAclD;IAGA;IAhBlB,UAAU,CAAyB;IACnC,aAAa,CAEwC;IACrD,aAAa,GAA6B,EAAE,CAAC;IAC7C,QAAQ,CAAgD;IACxD,iBAAiB,GAAwC,EAAE,CAAC;IAC5D,wBAAwB,CAAkC;IAC1D,sBAAsB,GAA2B,EAAE,CAAC;IACpD,QAAQ,GAAmB,EAAE,CAAC;IAC9B,uBAAuB,CAAU;IAEjC,YACkB,YAEoC,EACpC,UAAyD,EAAE;QAE3E,KAAK,EAAE,CAAC;QALQ,iBAAY,GAAZ,YAAY,CAEwB;QACpC,YAAO,GAAP,OAAO,CAAoD;QAI3E,IACE,CAAC,OAAO,OAAO,CAAC,SAAS,KAAK,WAAW,IAAI,gBAAgB,EAAE,CAAC;YAChE,OAAO,CAAC,SAAS,KAAK,QAAQ,EAC9B,CAAC;YACD,IAAI,CAAC,UAAU,GAAG,IAAI,oBAAoB,EAAE,CAAC;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