@voiceflow/sdk-runtime 1.27.1-5ab45311.15 → 1.28.0
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 +2 -1
- package/build/cjs/main.d.ts.map +1 -1
- package/build/cjs/main.js +2 -1
- package/build/cjs/main.js.map +1 -1
- package/build/cjs/sdk/sdk.service.d.ts +1 -2
- package/build/cjs/sdk/sdk.service.d.ts.map +1 -1
- package/build/cjs/sdk/sdk.service.js +0 -6
- package/build/cjs/sdk/sdk.service.js.map +1 -1
- package/build/cjs/v2/interact-trace.stream.d.ts +3 -0
- package/build/cjs/v2/interact-trace.stream.d.ts.map +1 -1
- package/build/cjs/v2/interact-trace.stream.js +3 -2
- package/build/cjs/v2/interact-trace.stream.js.map +1 -1
- package/build/cjs/v2/runtime.interface.d.ts +6 -0
- package/build/cjs/v2/runtime.interface.d.ts.map +1 -1
- package/build/cjs/v2/runtime.interface.js +8 -0
- package/build/cjs/v2/runtime.interface.js.map +1 -1
- package/build/cjs/v2/{websocket-runtime.client.d.ts → websocket-runtime/websocket-runtime.client.d.ts} +5 -32
- package/build/cjs/v2/websocket-runtime/websocket-runtime.client.d.ts.map +1 -0
- package/build/cjs/v2/{websocket-runtime.client.js → websocket-runtime/websocket-runtime.client.js} +77 -128
- package/build/cjs/v2/websocket-runtime/websocket-runtime.client.js.map +1 -0
- package/build/cjs/v2/websocket-runtime/websocket-runtime.interface.d.ts +61 -0
- package/build/cjs/v2/websocket-runtime/websocket-runtime.interface.d.ts.map +1 -0
- package/build/cjs/v2/websocket-runtime/websocket-runtime.interface.js +19 -0
- package/build/cjs/v2/websocket-runtime/websocket-runtime.interface.js.map +1 -0
- package/build/cjs/v2/websocket-runtime/websocket-runtime.utils.d.ts +6 -0
- package/build/cjs/v2/websocket-runtime/websocket-runtime.utils.d.ts.map +1 -0
- package/build/cjs/v2/websocket-runtime/websocket-runtime.utils.js +22 -0
- package/build/cjs/v2/websocket-runtime/websocket-runtime.utils.js.map +1 -0
- package/build/cjs/v2/{websocket-trace.stream.d.ts → websocket-runtime/websocket-trace.stream.d.ts} +3 -6
- package/build/cjs/v2/websocket-runtime/websocket-trace.stream.d.ts.map +1 -0
- package/build/cjs/v2/websocket-runtime/websocket-trace.stream.js +26 -0
- package/build/cjs/v2/websocket-runtime/websocket-trace.stream.js.map +1 -0
- package/build/esm/main.d.ts +2 -1
- package/build/esm/main.d.ts.map +1 -1
- package/build/esm/main.js +2 -1
- package/build/esm/main.js.map +1 -1
- package/build/esm/sdk/sdk.service.d.ts +1 -2
- package/build/esm/sdk/sdk.service.d.ts.map +1 -1
- package/build/esm/sdk/sdk.service.js +0 -6
- package/build/esm/sdk/sdk.service.js.map +1 -1
- package/build/esm/v2/interact-trace.stream.d.ts +3 -0
- package/build/esm/v2/interact-trace.stream.d.ts.map +1 -1
- package/build/esm/v2/interact-trace.stream.js +1 -1
- package/build/esm/v2/interact-trace.stream.js.map +1 -1
- package/build/esm/v2/runtime.interface.d.ts +6 -0
- package/build/esm/v2/runtime.interface.d.ts.map +1 -1
- package/build/esm/v2/runtime.interface.js +7 -1
- package/build/esm/v2/runtime.interface.js.map +1 -1
- package/build/esm/v2/{websocket-runtime.client.d.ts → websocket-runtime/websocket-runtime.client.d.ts} +5 -32
- package/build/esm/v2/websocket-runtime/websocket-runtime.client.d.ts.map +1 -0
- package/build/esm/v2/{websocket-runtime.client.js → websocket-runtime/websocket-runtime.client.js} +60 -111
- package/build/esm/v2/websocket-runtime/websocket-runtime.client.js.map +1 -0
- package/build/esm/v2/websocket-runtime/websocket-runtime.interface.d.ts +61 -0
- package/build/esm/v2/websocket-runtime/websocket-runtime.interface.d.ts.map +1 -0
- package/build/esm/v2/websocket-runtime/websocket-runtime.interface.js +16 -0
- package/build/esm/v2/websocket-runtime/websocket-runtime.interface.js.map +1 -0
- package/build/esm/v2/websocket-runtime/websocket-runtime.utils.d.ts +6 -0
- package/build/esm/v2/websocket-runtime/websocket-runtime.utils.d.ts.map +1 -0
- package/build/esm/v2/websocket-runtime/websocket-runtime.utils.js +15 -0
- package/build/esm/v2/websocket-runtime/websocket-runtime.utils.js.map +1 -0
- package/build/esm/v2/{websocket-trace.stream.d.ts → websocket-runtime/websocket-trace.stream.d.ts} +3 -6
- package/build/esm/v2/websocket-runtime/websocket-trace.stream.d.ts.map +1 -0
- package/build/esm/v2/websocket-runtime/websocket-trace.stream.js +22 -0
- package/build/esm/v2/websocket-runtime/websocket-trace.stream.js.map +1 -0
- package/package.json +4 -3
- package/build/cjs/v2/websocket-runtime.client.d.ts.map +0 -1
- package/build/cjs/v2/websocket-runtime.client.js.map +0 -1
- package/build/cjs/v2/websocket-trace.stream.d.ts.map +0 -1
- package/build/cjs/v2/websocket-trace.stream.js +0 -84
- package/build/cjs/v2/websocket-trace.stream.js.map +0 -1
- package/build/esm/v2/websocket-runtime.client.d.ts.map +0 -1
- package/build/esm/v2/websocket-runtime.client.js.map +0 -1
- package/build/esm/v2/websocket-trace.stream.d.ts.map +0 -1
- package/build/esm/v2/websocket-trace.stream.js +0 -80
- package/build/esm/v2/websocket-trace.stream.js.map +0 -1
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
const hasFinalize = (trace) => {
|
|
2
|
-
return typeof trace === 'object' && trace !== null && 'finalize' in trace && typeof trace.finalize === 'function';
|
|
3
|
-
};
|
|
4
|
-
/**
|
|
5
|
-
* Transform WebSocket messages into trace format expected by the trace system.
|
|
6
|
-
* WebSocket messages have a different structure than HTTP trace events, so we need to convert them.
|
|
7
|
-
*/
|
|
8
|
-
const isCompletionMessage = (chunk) => {
|
|
9
|
-
return chunk.type === 'action' && chunk.payload?.status === 'completed';
|
|
10
|
-
};
|
|
11
|
-
const extractTraceFromPayload = (payload) => {
|
|
12
|
-
// Direct trace with type and payload
|
|
13
|
-
if (payload.type && payload.payload !== undefined) {
|
|
14
|
-
return payload;
|
|
15
|
-
}
|
|
16
|
-
// Nested trace data
|
|
17
|
-
if (payload.trace) {
|
|
18
|
-
return payload.trace;
|
|
19
|
-
}
|
|
20
|
-
// Traces array
|
|
21
|
-
if (Array.isArray(payload.traces) && payload.traces.length > 0) {
|
|
22
|
-
return payload.traces[0];
|
|
23
|
-
}
|
|
24
|
-
// Payload with type (completion, text, etc.)
|
|
25
|
-
if (payload.type) {
|
|
26
|
-
return payload;
|
|
27
|
-
}
|
|
28
|
-
return null;
|
|
29
|
-
};
|
|
30
|
-
// No need to validate specific trace types - let the trace handlers decide with canHandle()
|
|
31
|
-
const transformWebSocketMessageToTrace = (chunk) => {
|
|
32
|
-
// Early return for completion messages
|
|
33
|
-
if (isCompletionMessage(chunk)) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
// Process payload if it exists and is an object
|
|
37
|
-
if (chunk.payload && typeof chunk.payload === 'object') {
|
|
38
|
-
const traceFromPayload = extractTraceFromPayload(chunk.payload);
|
|
39
|
-
if (traceFromPayload) {
|
|
40
|
-
return traceFromPayload;
|
|
41
|
-
}
|
|
42
|
-
// Try using the payload as a trace (let trace handlers validate with canHandle)
|
|
43
|
-
return chunk.payload;
|
|
44
|
-
}
|
|
45
|
-
// Fallback: treat chunk as trace if it has a valid type
|
|
46
|
-
if (chunk.type && chunk.type !== 'action') {
|
|
47
|
-
return chunk;
|
|
48
|
-
}
|
|
49
|
-
return null;
|
|
50
|
-
};
|
|
51
|
-
export class WebSocketTraceStream extends TransformStream {
|
|
52
|
-
constructor(createContext, trace, onTrace) {
|
|
53
|
-
super({
|
|
54
|
-
transform: async (chunk, controller) => {
|
|
55
|
-
// Handle completion message
|
|
56
|
-
if (chunk.type === 'action' && chunk.payload?.status === 'completed') {
|
|
57
|
-
controller.terminate();
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
// Transform WebSocket message to trace format
|
|
61
|
-
const traceData = transformWebSocketMessageToTrace(chunk);
|
|
62
|
-
if (!traceData)
|
|
63
|
-
return;
|
|
64
|
-
const context = this.createContext();
|
|
65
|
-
await this.onTrace?.(context, traceData);
|
|
66
|
-
const trace = await this.trace.processTrace(context, traceData);
|
|
67
|
-
if (!trace)
|
|
68
|
-
return;
|
|
69
|
-
controller.enqueue(trace);
|
|
70
|
-
if (hasFinalize(trace)) {
|
|
71
|
-
await trace.finalize();
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
this.createContext = createContext;
|
|
76
|
-
this.trace = trace;
|
|
77
|
-
this.onTrace = onTrace;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
//# sourceMappingURL=websocket-trace.stream.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,CA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