@voiceflow/sdk-runtime 1.26.1-e7a9a604.10 → 1.27.1-5ab45311.15
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/build/cjs/main.d.ts +1 -0
- package/build/cjs/main.d.ts.map +1 -1
- package/build/cjs/main.js +1 -0
- package/build/cjs/main.js.map +1 -1
- package/build/cjs/runtime/runtime.interface.d.ts +5 -0
- package/build/cjs/runtime/runtime.interface.d.ts.map +1 -1
- package/build/cjs/runtime/runtime.interface.js +1 -1
- package/build/cjs/runtime/runtime.interface.js.map +1 -1
- package/build/cjs/sdk/sdk.service.d.ts +2 -1
- package/build/cjs/sdk/sdk.service.d.ts.map +1 -1
- package/build/cjs/sdk/sdk.service.js +6 -0
- package/build/cjs/sdk/sdk.service.js.map +1 -1
- package/build/cjs/v2/runtime.interface.d.ts +2 -0
- package/build/cjs/v2/runtime.interface.d.ts.map +1 -1
- package/build/cjs/v2/websocket-runtime.client.d.ts +61 -0
- package/build/cjs/v2/websocket-runtime.client.d.ts.map +1 -0
- package/build/cjs/v2/websocket-runtime.client.js +322 -0
- package/build/cjs/v2/websocket-runtime.client.js.map +1 -0
- package/build/cjs/v2/websocket-trace.stream.d.ts +14 -0
- package/build/cjs/v2/websocket-trace.stream.d.ts.map +1 -0
- package/build/cjs/v2/websocket-trace.stream.js +84 -0
- package/build/cjs/v2/websocket-trace.stream.js.map +1 -0
- package/build/esm/main.d.ts +1 -0
- package/build/esm/main.d.ts.map +1 -1
- package/build/esm/main.js +1 -0
- package/build/esm/main.js.map +1 -1
- package/build/esm/runtime/runtime.interface.d.ts +5 -0
- package/build/esm/runtime/runtime.interface.d.ts.map +1 -1
- package/build/esm/runtime/runtime.interface.js +1 -1
- package/build/esm/runtime/runtime.interface.js.map +1 -1
- package/build/esm/sdk/sdk.service.d.ts +2 -1
- package/build/esm/sdk/sdk.service.d.ts.map +1 -1
- package/build/esm/sdk/sdk.service.js +6 -0
- package/build/esm/sdk/sdk.service.js.map +1 -1
- package/build/esm/v2/runtime.interface.d.ts +2 -0
- package/build/esm/v2/runtime.interface.d.ts.map +1 -1
- package/build/esm/v2/websocket-runtime.client.d.ts +61 -0
- package/build/esm/v2/websocket-runtime.client.d.ts.map +1 -0
- package/build/esm/v2/websocket-runtime.client.js +318 -0
- package/build/esm/v2/websocket-runtime.client.js.map +1 -0
- package/build/esm/v2/websocket-trace.stream.d.ts +14 -0
- package/build/esm/v2/websocket-trace.stream.d.ts.map +1 -0
- package/build/esm/v2/websocket-trace.stream.js +80 -0
- package/build/esm/v2/websocket-trace.stream.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebSocketTraceStream = void 0;
|
|
4
|
+
const hasFinalize = (trace) => {
|
|
5
|
+
return typeof trace === 'object' && trace !== null && 'finalize' in trace && typeof trace.finalize === 'function';
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Transform WebSocket messages into trace format expected by the trace system.
|
|
9
|
+
* WebSocket messages have a different structure than HTTP trace events, so we need to convert them.
|
|
10
|
+
*/
|
|
11
|
+
const isCompletionMessage = (chunk) => {
|
|
12
|
+
return chunk.type === 'action' && chunk.payload?.status === 'completed';
|
|
13
|
+
};
|
|
14
|
+
const extractTraceFromPayload = (payload) => {
|
|
15
|
+
// Direct trace with type and payload
|
|
16
|
+
if (payload.type && payload.payload !== undefined) {
|
|
17
|
+
return payload;
|
|
18
|
+
}
|
|
19
|
+
// Nested trace data
|
|
20
|
+
if (payload.trace) {
|
|
21
|
+
return payload.trace;
|
|
22
|
+
}
|
|
23
|
+
// Traces array
|
|
24
|
+
if (Array.isArray(payload.traces) && payload.traces.length > 0) {
|
|
25
|
+
return payload.traces[0];
|
|
26
|
+
}
|
|
27
|
+
// Payload with type (completion, text, etc.)
|
|
28
|
+
if (payload.type) {
|
|
29
|
+
return payload;
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
};
|
|
33
|
+
// No need to validate specific trace types - let the trace handlers decide with canHandle()
|
|
34
|
+
const transformWebSocketMessageToTrace = (chunk) => {
|
|
35
|
+
// Early return for completion messages
|
|
36
|
+
if (isCompletionMessage(chunk)) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
// Process payload if it exists and is an object
|
|
40
|
+
if (chunk.payload && typeof chunk.payload === 'object') {
|
|
41
|
+
const traceFromPayload = extractTraceFromPayload(chunk.payload);
|
|
42
|
+
if (traceFromPayload) {
|
|
43
|
+
return traceFromPayload;
|
|
44
|
+
}
|
|
45
|
+
// Try using the payload as a trace (let trace handlers validate with canHandle)
|
|
46
|
+
return chunk.payload;
|
|
47
|
+
}
|
|
48
|
+
// Fallback: treat chunk as trace if it has a valid type
|
|
49
|
+
if (chunk.type && chunk.type !== 'action') {
|
|
50
|
+
return chunk;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
};
|
|
54
|
+
class WebSocketTraceStream extends TransformStream {
|
|
55
|
+
constructor(createContext, trace, onTrace) {
|
|
56
|
+
super({
|
|
57
|
+
transform: async (chunk, controller) => {
|
|
58
|
+
// Handle completion message
|
|
59
|
+
if (chunk.type === 'action' && chunk.payload?.status === 'completed') {
|
|
60
|
+
controller.terminate();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
// Transform WebSocket message to trace format
|
|
64
|
+
const traceData = transformWebSocketMessageToTrace(chunk);
|
|
65
|
+
if (!traceData)
|
|
66
|
+
return;
|
|
67
|
+
const context = this.createContext();
|
|
68
|
+
await this.onTrace?.(context, traceData);
|
|
69
|
+
const trace = await this.trace.processTrace(context, traceData);
|
|
70
|
+
if (!trace)
|
|
71
|
+
return;
|
|
72
|
+
controller.enqueue(trace);
|
|
73
|
+
if (hasFinalize(trace)) {
|
|
74
|
+
await trace.finalize();
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
this.createContext = createContext;
|
|
79
|
+
this.trace = trace;
|
|
80
|
+
this.onTrace = onTrace;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.WebSocketTraceStream = WebSocketTraceStream;
|
|
84
|
+
//# sourceMappingURL=websocket-trace.stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket-trace.stream.js","sourceRoot":"","sources":["../../../src/v2/websocket-trace.stream.ts"],"names":[],"mappings":";;;AASA,MAAM,WAAW,GAAG,CAAC,KAAc,EAA8C,EAAE;IACjF,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,UAAU,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,QAAQ,KAAK,UAAU,CAAC;AACpH,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,mBAAmB,GAAG,CAAC,KAAuB,EAAW,EAAE;IAC/D,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,EAAE,MAAM,KAAK,WAAW,CAAC;AAC1E,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAAC,OAAY,EAAmB,EAAE;IAChE,qCAAqC;IACrC,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAClD,OAAO,OAAmB,CAAC;IAC7B,CAAC;IAED,oBAAoB;IACpB,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,OAAO,OAAO,CAAC,KAAiB,CAAC;IACnC,CAAC;IAED,eAAe;IACf,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/D,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAa,CAAC;IACvC,CAAC;IAED,6CAA6C;IAC7C,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;Q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CAAC;gBAErC,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;gBAEzC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;gBAChE,IAAI,CAAC,KAAK;oBAAE,OAAO;gBAEnB,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBAE1B,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;oBACvB,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC;gBACzB,CAAC;YACH,CAAC;SACF,CAAC,CAAC;QA7Bc,kBAAa,GAAb,aAAa,CAAS;QACtB,UAAK,GAAL,KAAK,CAAiB;QACtB,YAAO,GAAP,OAAO,CAAwD;IA4BlF,CAAC;CACF;AAjCD,oDAiCC"}
|
package/build/esm/main.d.ts
CHANGED
|
@@ -6,4 +6,5 @@ export * from './v2/public-runtime.client.js';
|
|
|
6
6
|
export type { RuntimeInteractStreamRequest } from './v2/runtime.interface.js';
|
|
7
7
|
export { IRuntimeClient } from './v2/runtime.interface.js';
|
|
8
8
|
export * from './v2/shareable-link-runtime.client.js';
|
|
9
|
+
export * from './v2/websocket-runtime.client.js';
|
|
9
10
|
//# sourceMappingURL=main.d.ts.map
|
package/build/esm/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,YAAY,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,cAAc,oCAAoC,CAAC"}
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,YAAY,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC"}
|
package/build/esm/main.js
CHANGED
|
@@ -4,4 +4,5 @@ export * from './trace/index.js';
|
|
|
4
4
|
export * from './v2/private-runtime.client.js';
|
|
5
5
|
export * from './v2/public-runtime.client.js';
|
|
6
6
|
export * from './v2/shareable-link-runtime.client.js';
|
|
7
|
+
export * from './v2/websocket-runtime.client.js';
|
|
7
8
|
//# sourceMappingURL=main.js.map
|
package/build/esm/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAG3C,cAAc,oCAAoC,CAAC"}
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAG3C,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC"}
|
|
@@ -9,6 +9,11 @@ export interface RuntimeOptions<V = AuthVerify | PublicVerify | PrototypeVerify>
|
|
|
9
9
|
* Defaults to the global `fetch()`.
|
|
10
10
|
*/
|
|
11
11
|
fetchPonyfill?: FetchFn;
|
|
12
|
+
/**
|
|
13
|
+
* Whether WebSocket transport is being used.
|
|
14
|
+
* When true, some operations like endTranscript may be handled differently.
|
|
15
|
+
*/
|
|
16
|
+
useWebSocket?: boolean;
|
|
12
17
|
}
|
|
13
18
|
export interface AuthVerify {
|
|
14
19
|
authorization: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.interface.d.ts","sourceRoot":"","sources":["../../../src/runtime/runtime.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACrH,OAAO,EAAe,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAGlE,KAAK,OAAO,GAAG,CAAC,GAAG,UAAU,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAEtD,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,UAAU,GAAG,YAAY,GAAG,eAAe;IAC7E,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,CAAC,CAAC;IAEV;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.interface.d.ts","sourceRoot":"","sources":["../../../src/runtime/runtime.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACrH,OAAO,EAAe,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAGlE,KAAK,OAAO,GAAG,CAAC,GAAG,UAAU,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAEtD,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,UAAU,GAAG,YAAY,GAAG,eAAe;IAC7E,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,CAAC,CAA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,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB"}
|
|
@@ -8,7 +8,7 @@ export const isPublicRuntimeOptions = (options) => {
|
|
|
8
8
|
export const isPrototypeRuntimeOptions = (options) => {
|
|
9
9
|
return (options?.verify?.prototype === true &&
|
|
10
10
|
typeof options?.verify?.versionID === 'string' &&
|
|
11
|
-
typeof options?.verify?.
|
|
11
|
+
typeof options?.verify?.projectID === 'string' &&
|
|
12
12
|
typeof options?.verify?.authorization === 'string');
|
|
13
13
|
};
|
|
14
14
|
export const isShareableLinkRuntimeOptions = (options) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.interface.js","sourceRoot":"","sources":["../../../src/runtime/runtime.interface.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.interface.js","sourceRoot":"","sources":["../../../src/runtime/runtime.interface.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AA6ClE,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,OAAkC,EAAyC,EAAE;IAChH,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,OAAkC,EAA2C,EAAE;IACpH,OAA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AAC,KAAK,EAAE,MAAM,CAAC;IACnD,kBAAkB,CAAE,KAAa,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -4,12 +4,13 @@ import type { VoiceflowRuntimeOptions } from './sdk.interface.js';
|
|
|
4
4
|
export declare class VoiceflowRuntime<T> {
|
|
5
5
|
private readonly runtime;
|
|
6
6
|
private readonly trace;
|
|
7
|
+
private readonly useWebSocket;
|
|
7
8
|
constructor(options: VoiceflowRuntimeOptions<T>);
|
|
8
9
|
registerStep(step: TraceDeclaration<T, any>): this;
|
|
9
10
|
interact(context: T, request: RuntimeInteractRequest): Promise<T>;
|
|
10
11
|
feedback(request: RuntimeFeedbackRequest): Promise<void>;
|
|
11
12
|
getPublishing<T extends Record<string, unknown>>(...options: Parameters<RuntimeService['getPublishing']>): Promise<T>;
|
|
12
13
|
createTranscript(...options: Parameters<RuntimeService['createTranscript']>): Promise<import("../runtime/index.js").Transcript>;
|
|
13
|
-
endTranscript(...options: Parameters<RuntimeService['endTranscript']>): Promise<void>;
|
|
14
|
+
endTranscript(...options: Parameters<RuntimeService['endTranscript']>): Promise<void | null>;
|
|
14
15
|
}
|
|
15
16
|
//# sourceMappingURL=sdk.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.service.d.ts","sourceRoot":"","sources":["../../../src/sdk/sdk.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAUhG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAGhE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE/D,qBAAa,gBAAgB,CAAC,CAAC;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IAEzC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkB;
|
|
1
|
+
{"version":3,"file":"sdk.service.d.ts","sourceRoot":"","sources":["../../../src/sdk/sdk.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAUhG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAGhE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE/D,qBAAa,gBAAgB,CAAC,CAAC;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IAEzC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkB;IAExC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAU;gBAEpB,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC;IAiB/C,YAAY,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC;IAKrC,QAAQ,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,CAAC,CAAC;IAKjE,QAAQ,CAAC,OAAO,EAAE,sBAAsB;IAIxC,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1D,GAAG,OAAO,EAAE,UAAU,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IAK5C,gBAAgB,CAAC,GAAG,OAAO,EAAE,UAAU,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;IAI3E,aAAa,CAAC,GAAG,OAAO,EAAE,UAAU,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;CAQnF"}
|
|
@@ -3,6 +3,7 @@ import { TraceService } from '../trace/trace.service.js';
|
|
|
3
3
|
export class VoiceflowRuntime {
|
|
4
4
|
constructor(options) {
|
|
5
5
|
this.trace = new TraceService(options);
|
|
6
|
+
this.useWebSocket = options.useWebSocket ?? false;
|
|
6
7
|
if (isPrototypeRuntimeOptions(options)) {
|
|
7
8
|
this.runtime = new PrototypeRuntimeService(options);
|
|
8
9
|
}
|
|
@@ -37,6 +38,11 @@ export class VoiceflowRuntime {
|
|
|
37
38
|
return this.runtime.createTranscript(...options);
|
|
38
39
|
}
|
|
39
40
|
async endTranscript(...options) {
|
|
41
|
+
if (this.useWebSocket) {
|
|
42
|
+
// Skip HTTP endTranscript call for WebSocket connections
|
|
43
|
+
// The WebSocket connection handles transcript lifecycle
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
40
46
|
return this.runtime.endTranscript(...options);
|
|
41
47
|
}
|
|
42
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.service.js","sourceRoot":"","sources":["../../../src/sdk/sdk.service.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,yBAAyB,EACzB,sBAAsB,EACtB,6BAA6B,EAC7B,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAIrD,MAAM,OAAO,gBAAgB;
|
|
1
|
+
{"version":3,"file":"sdk.service.js","sourceRoot":"","sources":["../../../src/sdk/sdk.service.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,yBAAyB,EACzB,sBAAsB,EACtB,6BAA6B,EAC7B,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAIrD,MAAM,OAAO,gBAAgB;IAO3B,YAAmB,OAAmC;QACpD,IAAI,CAAC,KAAK,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;QACvC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,KAAK,CAAC;QAElD,IAAI,yBAAyB,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC,OAAO,GAAG,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAC;QACtD,CAAC;aA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CAAC,GAAG,OAAoD;QAChF,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,yDAAyD;YACzD,wDAAwD;YACxD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC,CAAC;IAChD,CAAC;CACF"}
|
|
@@ -6,6 +6,7 @@ export interface RuntimeClientOptions<T> extends TraceOptions<T> {
|
|
|
6
6
|
onTrace?: (context: T, trace: AnyTrace) => Promise<void> | void;
|
|
7
7
|
authorization?: string;
|
|
8
8
|
onStateChange?: (context: T, state: Record<string, any>) => void;
|
|
9
|
+
inactivityTimeout?: number;
|
|
9
10
|
}
|
|
10
11
|
export interface RuntimeInteractStreamRequest {
|
|
11
12
|
userID: string;
|
|
@@ -16,6 +17,7 @@ export interface RuntimeInteractStreamRequest {
|
|
|
16
17
|
guidedNavigation?: boolean;
|
|
17
18
|
}
|
|
18
19
|
export interface IRuntimeClient<T> {
|
|
20
|
+
init?: (request: RuntimeInteractStreamRequest) => Promise<void>;
|
|
19
21
|
resetState?(state?: Record<string, any> | null): void;
|
|
20
22
|
patchState?(state: Record<string, any>): void;
|
|
21
23
|
setInitialState?(state: Record<string, any>): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.interface.d.ts","sourceRoot":"","sources":["../../../src/v2/runtime.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,MAAM,WAAW,oBAAoB,CAAC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAC;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,KA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,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,UAAU,CAAC,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;IACtD,UAAU,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IAC9C,eAAe,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IACnD,cAAc,CAAC,aAAa,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,4BAA4B,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;CAC3G"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { AudioEncoding, Modality } from '@voiceflow/dtos-interact';
|
|
2
|
+
import type { IRuntimeClient, RuntimeClientOptions, RuntimeInteractStreamRequest } from './runtime.interface.js';
|
|
3
|
+
import { TraceService } from './trace.service.js';
|
|
4
|
+
export interface InitialDialogSessionMetadata {
|
|
5
|
+
userID: string;
|
|
6
|
+
sessionID?: string;
|
|
7
|
+
environmentID?: string;
|
|
8
|
+
config?: {
|
|
9
|
+
completionEvents?: boolean;
|
|
10
|
+
audioEvents?: boolean;
|
|
11
|
+
audioEncoding?: AudioEncoding;
|
|
12
|
+
platform?: string;
|
|
13
|
+
modality?: Modality;
|
|
14
|
+
recording?: {
|
|
15
|
+
url?: string | null;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
declare enum ConnectionState {
|
|
20
|
+
DISCONNECTED = "disconnected",
|
|
21
|
+
CONNECTING = "connecting",
|
|
22
|
+
CONNECTED = "connected",
|
|
23
|
+
SESSION_STARTED = "session_started",
|
|
24
|
+
ERROR = "error"
|
|
25
|
+
}
|
|
26
|
+
export declare class WebSocketRuntimeClient<T> implements IRuntimeClient<T> {
|
|
27
|
+
private readonly options;
|
|
28
|
+
private readonly trace;
|
|
29
|
+
private state;
|
|
30
|
+
private ws;
|
|
31
|
+
private connectionState;
|
|
32
|
+
private pendingInteractions;
|
|
33
|
+
private currentInteraction;
|
|
34
|
+
private inactivityTimer;
|
|
35
|
+
private readonly inactivityTimeout;
|
|
36
|
+
private reconnectAttempts;
|
|
37
|
+
private readonly maxReconnectAttempts;
|
|
38
|
+
private reconnectDelay;
|
|
39
|
+
constructor(options: RuntimeClientOptions<T>, trace?: TraceService<T>);
|
|
40
|
+
setState: (context: T, state: Record<string, any>) => void;
|
|
41
|
+
resetState(state?: Record<string, any> | null): void;
|
|
42
|
+
patchState(state: Record<string, any>): void;
|
|
43
|
+
setInitialState(state: Record<string, any>): void;
|
|
44
|
+
private startInactivityTimer;
|
|
45
|
+
private clearInactivityTimer;
|
|
46
|
+
private resetInactivityTimer;
|
|
47
|
+
init(request: RuntimeInteractStreamRequest): Promise<void>;
|
|
48
|
+
private ensureConnection;
|
|
49
|
+
private connect;
|
|
50
|
+
private startSession;
|
|
51
|
+
interactStream(createContext: () => T, request: RuntimeInteractStreamRequest): Promise<ReadableStream<T>>;
|
|
52
|
+
private processInteraction;
|
|
53
|
+
private processNextInteraction;
|
|
54
|
+
private handleDisconnection;
|
|
55
|
+
disconnect(): Promise<void>;
|
|
56
|
+
private delay;
|
|
57
|
+
getConnectionState(): ConnectionState;
|
|
58
|
+
isReady(): boolean;
|
|
59
|
+
}
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=websocket-runtime.client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket-runtime.client.d.ts","sourceRoot":"","sources":["../../../src/v2/websocket-runtime.client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAe,MAAM,0BAA0B,CAAC;AAEhF,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAC9G,OAAO,EAAE,YAAY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GvD;IAEK,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI;IAIpD,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAI5C,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAMxD,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,oBAAoB;IAOf,IAAI,CAAC,OAAO,EAAE,4BAA4B,GAAG,OAAO,CAAC,IAAI,CAAC;YAiBzD,gBAAgB;YAchB,OAAO;YAuCP,YAAY;IAoDpB,cAAc,CAAC,aAAa,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,4BAA4B,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAoB/G,OAAO,CAAC,kBAAkB;IAoE1B,OAAO,CAAC,sBAAsB;IAQ9B,OAAO,CAAC,mBAAmB;IA2Bd,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAkCxC,OAAO,CAAC,KAAK;IAON,kBAAkB,IAAI,eAAe;IAIrC,OAAO,IAAI,OAAO;CAG1B"}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { AudioEncoding, Modality, RequestType } from '@voiceflow/dtos-interact';
|
|
2
|
+
import { TraceService } from './trace.service.js';
|
|
3
|
+
import { WebSocketTraceStream } from './websocket-trace.stream.js';
|
|
4
|
+
// Define the Environment enum locally if not available
|
|
5
|
+
var Environment;
|
|
6
|
+
(function (Environment) {
|
|
7
|
+
Environment["DEVELOPMENT"] = "development";
|
|
8
|
+
Environment["STAGING"] = "staging";
|
|
9
|
+
Environment["PRODUCTION"] = "production";
|
|
10
|
+
})(Environment || (Environment = {}));
|
|
11
|
+
// Simplified connection state enum
|
|
12
|
+
var ConnectionState;
|
|
13
|
+
(function (ConnectionState) {
|
|
14
|
+
ConnectionState["DISCONNECTED"] = "disconnected";
|
|
15
|
+
ConnectionState["CONNECTING"] = "connecting";
|
|
16
|
+
ConnectionState["CONNECTED"] = "connected";
|
|
17
|
+
ConnectionState["SESSION_STARTED"] = "session_started";
|
|
18
|
+
ConnectionState["ERROR"] = "error";
|
|
19
|
+
})(ConnectionState || (ConnectionState = {}));
|
|
20
|
+
export class WebSocketRuntimeClient {
|
|
21
|
+
constructor(options, trace = new TraceService({ traces: options.traces })) {
|
|
22
|
+
this.options = options;
|
|
23
|
+
this.trace = trace;
|
|
24
|
+
this.state = null;
|
|
25
|
+
this.ws = null;
|
|
26
|
+
this.connectionState = ConnectionState.DISCONNECTED;
|
|
27
|
+
this.pendingInteractions = [];
|
|
28
|
+
this.currentInteraction = null;
|
|
29
|
+
this.inactivityTimer = null;
|
|
30
|
+
this.inactivityTimeout = 2 * 60 * 1000;
|
|
31
|
+
this.reconnectAttempts = 0;
|
|
32
|
+
this.maxReconnectAttempts = 3;
|
|
33
|
+
this.reconnectDelay = 1000;
|
|
34
|
+
this.setState = (context, state) => {
|
|
35
|
+
this.state = state;
|
|
36
|
+
this.options.onStateChange?.(context, state);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
resetState(state) {
|
|
40
|
+
this.state = state ?? null;
|
|
41
|
+
}
|
|
42
|
+
patchState(state) {
|
|
43
|
+
this.state = { ...this.state, ...state };
|
|
44
|
+
}
|
|
45
|
+
setInitialState(state) {
|
|
46
|
+
if (this.state === null) {
|
|
47
|
+
this.state = state;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
startInactivityTimer() {
|
|
51
|
+
this.clearInactivityTimer();
|
|
52
|
+
this.inactivityTimer = setTimeout(() => {
|
|
53
|
+
this.disconnect();
|
|
54
|
+
}, this.inactivityTimeout);
|
|
55
|
+
}
|
|
56
|
+
clearInactivityTimer() {
|
|
57
|
+
if (this.inactivityTimer) {
|
|
58
|
+
clearTimeout(this.inactivityTimer);
|
|
59
|
+
this.inactivityTimer = null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
resetInactivityTimer() {
|
|
63
|
+
if (this.connectionState === ConnectionState.SESSION_STARTED) {
|
|
64
|
+
this.startInactivityTimer();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Simplified init method - only ensures connection is ready
|
|
68
|
+
async init(request) {
|
|
69
|
+
if (this.connectionState === ConnectionState.SESSION_STARTED) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (this.connectionState === ConnectionState.ERROR ||
|
|
73
|
+
(this.ws && (this.ws.readyState === WebSocket.CLOSING || this.ws.readyState === WebSocket.CLOSED))) {
|
|
74
|
+
await this.disconnect();
|
|
75
|
+
await this.delay(50); // Small delay to ensure cleanup
|
|
76
|
+
}
|
|
77
|
+
await this.ensureConnection(request);
|
|
78
|
+
}
|
|
79
|
+
// Combined connection and session establishment
|
|
80
|
+
async ensureConnection(request) {
|
|
81
|
+
if (this.connectionState === ConnectionState.SESSION_STARTED) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (this.connectionState === ConnectionState.DISCONNECTED) {
|
|
85
|
+
await this.connect();
|
|
86
|
+
}
|
|
87
|
+
if (this.connectionState === ConnectionState.CONNECTED) {
|
|
88
|
+
await this.startSession(request);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async connect() {
|
|
92
|
+
if (this.connectionState === ConnectionState.CONNECTING) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this.connectionState = ConnectionState.CONNECTING;
|
|
96
|
+
const wsUrl = `${this.options.baseURL.replace(/^http/, 'ws')}/v3/interact/socket`;
|
|
97
|
+
try {
|
|
98
|
+
await new Promise((resolve, reject) => {
|
|
99
|
+
this.ws = new WebSocket(wsUrl);
|
|
100
|
+
const timeout = setTimeout(() => {
|
|
101
|
+
reject(new Error('WebSocket connection timeout'));
|
|
102
|
+
}, 10000);
|
|
103
|
+
this.ws.onopen = () => {
|
|
104
|
+
clearTimeout(timeout);
|
|
105
|
+
this.connectionState = ConnectionState.CONNECTED;
|
|
106
|
+
this.reconnectAttempts = 0; // Reset on successful connection
|
|
107
|
+
resolve();
|
|
108
|
+
};
|
|
109
|
+
this.ws.onerror = (error) => {
|
|
110
|
+
clearTimeout(timeout);
|
|
111
|
+
this.connectionState = ConnectionState.ERROR;
|
|
112
|
+
reject(new Error(`WebSocket connection failed: ${error}`));
|
|
113
|
+
};
|
|
114
|
+
this.ws.onclose = () => {
|
|
115
|
+
this.handleDisconnection();
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
this.connectionState = ConnectionState.ERROR;
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async startSession(request) {
|
|
125
|
+
if (!this.ws || this.connectionState !== ConnectionState.CONNECTED) {
|
|
126
|
+
throw new Error('Cannot start session: not connected');
|
|
127
|
+
}
|
|
128
|
+
const startMessage = {
|
|
129
|
+
type: 'start',
|
|
130
|
+
payload: {
|
|
131
|
+
userID: request.userID,
|
|
132
|
+
projectID: request.projectID,
|
|
133
|
+
sessionID: undefined,
|
|
134
|
+
environmentID: request.environment || Environment.DEVELOPMENT,
|
|
135
|
+
state: this.state,
|
|
136
|
+
config: {
|
|
137
|
+
completionEvents: true,
|
|
138
|
+
audioEvents: request.audioEvents || false,
|
|
139
|
+
audioEncoding: AudioEncoding.PCM,
|
|
140
|
+
modality: Modality.CHAT,
|
|
141
|
+
},
|
|
142
|
+
...(this.options.authorization && { authorization: this.options.authorization }),
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
await new Promise((resolve, reject) => {
|
|
146
|
+
const timeout = setTimeout(() => {
|
|
147
|
+
reject(new Error('Start session timeout'));
|
|
148
|
+
}, 10000);
|
|
149
|
+
const originalOnMessage = this.ws.onmessage;
|
|
150
|
+
this.ws.onmessage = (event) => {
|
|
151
|
+
try {
|
|
152
|
+
const message = JSON.parse(event.data);
|
|
153
|
+
if (message.type === 'start') {
|
|
154
|
+
clearTimeout(timeout);
|
|
155
|
+
this.connectionState = ConnectionState.SESSION_STARTED;
|
|
156
|
+
this.ws.onmessage = originalOnMessage;
|
|
157
|
+
this.startInactivityTimer();
|
|
158
|
+
resolve();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
clearTimeout(timeout);
|
|
163
|
+
this.ws.onmessage = originalOnMessage;
|
|
164
|
+
reject(new Error(`Failed to parse start response: ${error}`));
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
this.ws.send(JSON.stringify(startMessage));
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
async interactStream(createContext, request) {
|
|
171
|
+
// Ensure connection and session are ready
|
|
172
|
+
await this.init(request);
|
|
173
|
+
return new Promise((resolve, reject) => {
|
|
174
|
+
const pendingInteraction = {
|
|
175
|
+
createContext,
|
|
176
|
+
request,
|
|
177
|
+
resolve,
|
|
178
|
+
reject,
|
|
179
|
+
};
|
|
180
|
+
if (!this.currentInteraction) {
|
|
181
|
+
this.processInteraction(pendingInteraction);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
this.pendingInteractions.push(pendingInteraction);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
processInteraction(interaction) {
|
|
189
|
+
if (!this.ws || this.connectionState !== ConnectionState.SESSION_STARTED) {
|
|
190
|
+
interaction.reject(new Error('WebSocket session not ready'));
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
this.currentInteraction = interaction;
|
|
194
|
+
const { createContext, request, resolve, reject } = interaction;
|
|
195
|
+
const interactMessage = {
|
|
196
|
+
type: 'action',
|
|
197
|
+
payload: {
|
|
198
|
+
action: request.action ?? { type: RequestType.LAUNCH, payload: { resetState: false } },
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
try {
|
|
202
|
+
this.resetInactivityTimer();
|
|
203
|
+
this.ws.send(JSON.stringify(interactMessage));
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
reject(new Error(`Failed to send interaction: ${error}`));
|
|
207
|
+
this.processNextInteraction();
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
let controller = null;
|
|
211
|
+
const readable = new ReadableStream({
|
|
212
|
+
start(ctrl) {
|
|
213
|
+
controller = ctrl;
|
|
214
|
+
},
|
|
215
|
+
cancel: () => {
|
|
216
|
+
if (this.currentInteraction === interaction) {
|
|
217
|
+
this.processNextInteraction();
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
this.ws.onmessage = (event) => {
|
|
222
|
+
try {
|
|
223
|
+
this.resetInactivityTimer();
|
|
224
|
+
const message = JSON.parse(event.data);
|
|
225
|
+
if (controller) {
|
|
226
|
+
controller.enqueue(message);
|
|
227
|
+
}
|
|
228
|
+
if (message.type === 'action' && message.payload?.status === 'completed') {
|
|
229
|
+
if (controller) {
|
|
230
|
+
controller.close();
|
|
231
|
+
}
|
|
232
|
+
this.processNextInteraction();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
if (controller) {
|
|
237
|
+
controller.error(new Error(`Failed to parse WebSocket message: ${error}`));
|
|
238
|
+
}
|
|
239
|
+
this.processNextInteraction();
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
const streamWithTraceProcessing = readable.pipeThrough(new WebSocketTraceStream(createContext, this.trace, this.options.onTrace));
|
|
243
|
+
resolve(streamWithTraceProcessing);
|
|
244
|
+
}
|
|
245
|
+
processNextInteraction() {
|
|
246
|
+
this.currentInteraction = null;
|
|
247
|
+
const nextInteraction = this.pendingInteractions.shift();
|
|
248
|
+
if (nextInteraction) {
|
|
249
|
+
this.processInteraction(nextInteraction);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
handleDisconnection() {
|
|
253
|
+
if (this.connectionState === ConnectionState.DISCONNECTED) {
|
|
254
|
+
return; // Already handled
|
|
255
|
+
}
|
|
256
|
+
this.connectionState = ConnectionState.DISCONNECTED;
|
|
257
|
+
this.clearInactivityTimer();
|
|
258
|
+
// Clean up WebSocket
|
|
259
|
+
if (this.ws) {
|
|
260
|
+
this.ws.onopen = null;
|
|
261
|
+
this.ws.onclose = null;
|
|
262
|
+
this.ws.onerror = null;
|
|
263
|
+
this.ws.onmessage = null;
|
|
264
|
+
this.ws = null;
|
|
265
|
+
}
|
|
266
|
+
// Reject pending interactions
|
|
267
|
+
[...this.pendingInteractions, this.currentInteraction].forEach((interaction) => {
|
|
268
|
+
if (interaction) {
|
|
269
|
+
interaction.reject(new Error('WebSocket disconnected'));
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
this.pendingInteractions = [];
|
|
273
|
+
this.currentInteraction = null;
|
|
274
|
+
}
|
|
275
|
+
async disconnect() {
|
|
276
|
+
this.connectionState = ConnectionState.DISCONNECTED;
|
|
277
|
+
this.clearInactivityTimer();
|
|
278
|
+
if (this.ws) {
|
|
279
|
+
try {
|
|
280
|
+
if (this.ws.readyState === WebSocket.OPEN) {
|
|
281
|
+
this.ws.close();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
// Ignore errors during close
|
|
286
|
+
}
|
|
287
|
+
// Force cleanup
|
|
288
|
+
this.ws.onopen = null;
|
|
289
|
+
this.ws.onclose = null;
|
|
290
|
+
this.ws.onerror = null;
|
|
291
|
+
this.ws.onmessage = null;
|
|
292
|
+
this.ws = null;
|
|
293
|
+
}
|
|
294
|
+
// Reject any pending interactions
|
|
295
|
+
[...this.pendingInteractions, this.currentInteraction].forEach((interaction) => {
|
|
296
|
+
if (interaction) {
|
|
297
|
+
interaction.reject(new Error('WebSocket disconnected'));
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
this.pendingInteractions = [];
|
|
301
|
+
this.currentInteraction = null;
|
|
302
|
+
// Small delay to ensure cleanup is complete
|
|
303
|
+
await this.delay(100);
|
|
304
|
+
}
|
|
305
|
+
delay(ms) {
|
|
306
|
+
return new Promise((resolve) => {
|
|
307
|
+
setTimeout(resolve, ms);
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
// Additional getter for debugging/monitoring
|
|
311
|
+
getConnectionState() {
|
|
312
|
+
return this.connectionState;
|
|
313
|
+
}
|
|
314
|
+
isReady() {
|
|
315
|
+
return this.connectionState === ConnectionState.SESSION_STARTED;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
//# sourceMappingURL=websocket-runtime.client.js.map
|