Skip to content

Commit 19978df

Browse files
committed
fix(server): use shared RPC instrumentation for voice streams
1 parent 6bcc540 commit 19978df

2 files changed

Lines changed: 41 additions & 44 deletions

File tree

‎apps/server/src/observability/RpcInstrumentation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type WsRpcMethod = RpcGroup.Rpcs<typeof WsRpcGroup>["_tag"];
1414
* even where they differ from the method prefix.
1515
*/
1616
const RPC_AGGREGATES = {
17+
[WS_METHODS.providerVoiceSession]: "provider",
1718
[ORCHESTRATION_V2_WS_METHODS.dispatchCommand]: "orchestrationV2",
1819
[ORCHESTRATION_V2_WS_METHODS.getWorkflowScript]: "orchestration",
1920
[ORCHESTRATION_V2_WS_METHODS.stopWorkflow]: "orchestration",

‎apps/server/src/ws.ts‎

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,51 +2308,47 @@ export const layerWsRpc = (
23082308
),
23092309
),
23102310
[WS_METHODS.providerVoiceSession]: (input) =>
2311-
observeRpcStream(
2312-
WS_METHODS.providerVoiceSession,
2313-
Stream.unwrap(
2314-
Effect.gen(function* () {
2315-
const voiceError = (detail: string) =>
2316-
new ProviderVoiceSessionError({ threadId: input.threadId, detail });
2317-
const projection = yield* threadManagement.getThreadRecords(input.threadId, [
2318-
"providerThreads",
2319-
]);
2320-
const providerThread =
2321-
projection.providerThreads.find(
2322-
(candidate) => candidate.id === projection.thread.activeProviderThreadId,
2323-
) ?? projection.providerThreads.at(-1);
2324-
const providerSessionId = providerThread?.providerSessionId ?? null;
2325-
if (providerThread === undefined || providerSessionId === null) {
2326-
return yield* voiceError("Send a message before starting voice.");
2327-
}
2328-
const runtime = Option.getOrNull(yield* providerSessionsV2.get(providerSessionId));
2329-
if (runtime === null) {
2330-
return yield* voiceError(
2331-
"The provider session is no longer running. Send a message first.",
2332-
);
2333-
}
2334-
if (runtime.startVoiceSession === undefined) {
2335-
return yield* voiceError(
2336-
`Provider '${runtime.driver}' does not support voice conversations.`,
2337-
);
2338-
}
2339-
return runtime.startVoiceSession({ providerThread, offerSdp: input.offerSdp });
2340-
}),
2341-
).pipe(
2342-
Stream.mapError((cause) =>
2343-
cause._tag === "ProviderVoiceSessionError"
2344-
? cause
2345-
: new ProviderVoiceSessionError({
2346-
threadId: input.threadId,
2347-
detail:
2348-
"detail" in cause && typeof cause.detail === "string"
2349-
? cause.detail
2350-
: cause.message,
2351-
cause,
2352-
}),
2353-
),
2311+
Stream.unwrap(
2312+
Effect.gen(function* () {
2313+
const voiceError = (detail: string) =>
2314+
new ProviderVoiceSessionError({ threadId: input.threadId, detail });
2315+
const projection = yield* threadManagement.getThreadRecords(input.threadId, [
2316+
"providerThreads",
2317+
]);
2318+
const providerThread =
2319+
projection.providerThreads.find(
2320+
(candidate) => candidate.id === projection.thread.activeProviderThreadId,
2321+
) ?? projection.providerThreads.at(-1);
2322+
const providerSessionId = providerThread?.providerSessionId ?? null;
2323+
if (providerThread === undefined || providerSessionId === null) {
2324+
return yield* voiceError("Send a message before starting voice.");
2325+
}
2326+
const runtime = Option.getOrNull(yield* providerSessionsV2.get(providerSessionId));
2327+
if (runtime === null) {
2328+
return yield* voiceError(
2329+
"The provider session is no longer running. Send a message first.",
2330+
);
2331+
}
2332+
if (runtime.startVoiceSession === undefined) {
2333+
return yield* voiceError(
2334+
`Provider '${runtime.driver}' does not support voice conversations.`,
2335+
);
2336+
}
2337+
return runtime.startVoiceSession({ providerThread, offerSdp: input.offerSdp });
2338+
}),
2339+
).pipe(
2340+
Stream.mapError((cause) =>
2341+
cause._tag === "ProviderVoiceSessionError"
2342+
? cause
2343+
: new ProviderVoiceSessionError({
2344+
threadId: input.threadId,
2345+
detail:
2346+
"detail" in cause && typeof cause.detail === "string"
2347+
? cause.detail
2348+
: cause.message,
2349+
cause,
2350+
}),
23542351
),
2355-
{ "rpc.aggregate": "provider" },
23562352
),
23572353
[WS_METHODS.serverUpdateProvider]: (input) =>
23582354
providerMaintenanceRunner.updateProvider(input),

0 commit comments

Comments
 (0)