@voiceflow/sdk-runtime 1.11.0 → 1.12.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.
@@ -1,4 +1,5 @@
1
1
  export * from './runtime';
2
2
  export * from './sdk';
3
3
  export * from './trace';
4
+ export * from './v2/runtime.client';
4
5
  //# sourceMappingURL=main.d.ts.map
@@ -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"}
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,qBAAqB,CAAC"}
package/build/cjs/main.js CHANGED
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./runtime"), exports);
18
18
  __exportStar(require("./sdk"), exports);
19
19
  __exportStar(require("./trace"), exports);
20
+ __exportStar(require("./v2/runtime.client"), exports);
@@ -0,0 +1,8 @@
1
+ import type { EventSourceMessage } from 'eventsource-parser';
2
+ import type { TraceService } from './trace.service';
3
+ export declare class InteractTraceStream<T> extends TransformStream<EventSourceMessage, T> {
4
+ private readonly createContext;
5
+ private readonly trace;
6
+ constructor(createContext: () => T, trace: TraceService<T>);
7
+ }
8
+ //# sourceMappingURL=interact-trace.stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interact-trace.stream.d.ts","sourceRoot":"","sources":["../../../src/v2/interact-trace.stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,qBAAa,mBAAmB,CAAC,CAAC,CAAE,SAAQ,eAAe,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAE9E,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,KAAK;gBADL,aAAa,EAAE,MAAM,CAAC,EACtB,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC;CAY1C"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InteractTraceStream = void 0;
4
+ class InteractTraceStream extends TransformStream {
5
+ constructor(createContext, trace) {
6
+ super({
7
+ transform: async (chunk, controller) => {
8
+ const data = JSON.parse(chunk.data);
9
+ const trace = await this.trace.processTrace(this.createContext(), data);
10
+ if (!trace)
11
+ return;
12
+ controller.enqueue(trace);
13
+ },
14
+ });
15
+ this.createContext = createContext;
16
+ this.trace = trace;
17
+ }
18
+ }
19
+ exports.InteractTraceStream = InteractTraceStream;
@@ -0,0 +1,20 @@
1
+ import type { RuntimeAction } from '../runtime';
2
+ import type { TraceOptions } from '../trace';
3
+ import { TraceService } from './trace.service';
4
+ export interface RuntimeClientOptions<T> extends TraceOptions<T> {
5
+ baseURL: string;
6
+ }
7
+ export interface InteractStreamRequest {
8
+ projectID: string;
9
+ userID: string;
10
+ environment?: string;
11
+ action: RuntimeAction;
12
+ }
13
+ export declare class RuntimeClient<T> {
14
+ private readonly options;
15
+ private readonly trace;
16
+ private readonly fetch;
17
+ constructor(options: RuntimeClientOptions<T>, trace?: TraceService<T>);
18
+ interactStream(createContext: () => T, { projectID, userID, environment, action }: InteractStreamRequest): Promise<ReadableStream<T>>;
19
+ }
20
+ //# sourceMappingURL=runtime.client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.client.d.ts","sourceRoot":"","sources":["../../../src/v2/runtime.client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,WAAW,oBAAoB,CAAC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAC;IAC9D,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,MAAM,EAAE,aAAa,CAAC;CACvB;AAED,qBAAa,aAAa,CAAC,CAAC;IAIxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAJxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAsD;gBAGzD,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAChC,KAAK,kBAA+C;IAGjE,cAAc,CAAC,aAAa,EAAE,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,qBAAqB;CAqB/G"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RuntimeClient = void 0;
4
+ const fetch_1 = require("@voiceflow/fetch");
5
+ const stream_1 = require("eventsource-parser/stream");
6
+ const interact_trace_stream_1 = require("./interact-trace.stream");
7
+ const trace_service_1 = require("./trace.service");
8
+ class RuntimeClient {
9
+ constructor(options, trace = new trace_service_1.TraceService({ traces: options.traces })) {
10
+ this.options = options;
11
+ this.trace = trace;
12
+ this.fetch = new fetch_1.FetchClient({ baseURL: this.options.baseURL });
13
+ }
14
+ async interactStream(createContext, { projectID, userID, environment, action }) {
15
+ const result = await this.fetch.post(`/v2/public/project/${projectID}/user/${encodeURIComponent(userID)}/interact/stream`, {
16
+ query: new URLSearchParams({
17
+ completion_events: String(true),
18
+ ...(environment && { environment }),
19
+ }),
20
+ json: { action },
21
+ });
22
+ if (!result.body) {
23
+ throw new Error('interact stream body is empty');
24
+ }
25
+ return result.body
26
+ .pipeThrough(new TextDecoderStream())
27
+ .pipeThrough(new stream_1.EventSourceParserStream())
28
+ .pipeThrough(new interact_trace_stream_1.InteractTraceStream(createContext, this.trace));
29
+ }
30
+ }
31
+ exports.RuntimeClient = RuntimeClient;
@@ -0,0 +1,9 @@
1
+ import { Trace } from '@voiceflow/base-types';
2
+ import type { TraceDeclaration, TraceOptions } from '../trace';
3
+ export declare class TraceService<T = unknown> {
4
+ private readonly traces;
5
+ constructor(options?: TraceOptions<T>);
6
+ registerTrace(step: TraceDeclaration<T, any>): this;
7
+ processTrace(context: T, data: Trace.AnyTrace): Promise<T | null>;
8
+ }
9
+ //# sourceMappingURL=trace.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace.service.d.ts","sourceRoot":"","sources":["../../../src/v2/trace.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE9D,qBAAa,YAAY,CAAC,CAAC,GAAG,OAAO;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkC;gBAEtC,OAAO,GAAE,YAAY,CAAC,CAAC,CAAM;IAIzC,aAAa,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI;IAK7C,YAAY,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;CAM/E"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TraceService = void 0;
4
+ class TraceService {
5
+ constructor(options = {}) {
6
+ this.traces = [];
7
+ this.traces = options.traces ?? [];
8
+ }
9
+ registerTrace(step) {
10
+ this.traces.push(step);
11
+ return this;
12
+ }
13
+ async processTrace(context, data) {
14
+ const trace = this.traces.find((trace) => trace.canHandle(data));
15
+ if (!trace)
16
+ return null;
17
+ return trace.handle({ context }, data);
18
+ }
19
+ }
20
+ exports.TraceService = TraceService;
@@ -1,4 +1,5 @@
1
1
  export * from './runtime/index.js';
2
2
  export * from './sdk/index.js';
3
3
  export * from './trace/index.js';
4
+ export * from './v2/runtime.client.js';
4
5
  //# sourceMappingURL=main.d.ts.map
@@ -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"}
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,qBAAqB,CAAC"}
package/build/esm/main.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './runtime/index.js';
2
2
  export * from './sdk/index.js';
3
3
  export * from './trace/index.js';
4
+ export * from './v2/runtime.client.js';
@@ -0,0 +1,8 @@
1
+ import type { EventSourceMessage } from 'eventsource-parser';
2
+ import type { TraceService } from './trace.service.js';
3
+ export declare class InteractTraceStream<T> extends TransformStream<EventSourceMessage, T> {
4
+ private readonly createContext;
5
+ private readonly trace;
6
+ constructor(createContext: () => T, trace: TraceService<T>);
7
+ }
8
+ //# sourceMappingURL=interact-trace.stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interact-trace.stream.d.ts","sourceRoot":"","sources":["../../../src/v2/interact-trace.stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,qBAAa,mBAAmB,CAAC,CAAC,CAAE,SAAQ,eAAe,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAE9E,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,KAAK;gBADL,aAAa,EAAE,MAAM,CAAC,EACtB,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC;CAY1C"}
@@ -0,0 +1,15 @@
1
+ export class InteractTraceStream extends TransformStream {
2
+ constructor(createContext, trace) {
3
+ super({
4
+ transform: async (chunk, controller) => {
5
+ const data = JSON.parse(chunk.data);
6
+ const trace = await this.trace.processTrace(this.createContext(), data);
7
+ if (!trace)
8
+ return;
9
+ controller.enqueue(trace);
10
+ },
11
+ });
12
+ this.createContext = createContext;
13
+ this.trace = trace;
14
+ }
15
+ }
@@ -0,0 +1,20 @@
1
+ import type { RuntimeAction } from '../runtime/index.js';
2
+ import type { TraceOptions } from '../trace/index.js';
3
+ import { TraceService } from './trace.service.js';
4
+ export interface RuntimeClientOptions<T> extends TraceOptions<T> {
5
+ baseURL: string;
6
+ }
7
+ export interface InteractStreamRequest {
8
+ projectID: string;
9
+ userID: string;
10
+ environment?: string;
11
+ action: RuntimeAction;
12
+ }
13
+ export declare class RuntimeClient<T> {
14
+ private readonly options;
15
+ private readonly trace;
16
+ private readonly fetch;
17
+ constructor(options: RuntimeClientOptions<T>, trace?: TraceService<T>);
18
+ interactStream(createContext: () => T, { projectID, userID, environment, action }: InteractStreamRequest): Promise<ReadableStream<T>>;
19
+ }
20
+ //# sourceMappingURL=runtime.client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.client.d.ts","sourceRoot":"","sources":["../../../src/v2/runtime.client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,WAAW,oBAAoB,CAAC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAC;IAC9D,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,MAAM,EAAE,aAAa,CAAC;CACvB;AAED,qBAAa,aAAa,CAAC,CAAC;IAIxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAJxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAsD;gBAGzD,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAChC,KAAK,kBAA+C;IAGjE,cAAc,CAAC,aAAa,EAAE,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,qBAAqB;CAqB/G"}
@@ -0,0 +1,27 @@
1
+ import { FetchClient } from '@voiceflow/fetch';
2
+ import { EventSourceParserStream } from 'eventsource-parser/stream';
3
+ import { InteractTraceStream } from './interact-trace.stream.js';
4
+ import { TraceService } from './trace.service.js';
5
+ export class RuntimeClient {
6
+ constructor(options, trace = new TraceService({ traces: options.traces })) {
7
+ this.options = options;
8
+ this.trace = trace;
9
+ this.fetch = new FetchClient({ baseURL: this.options.baseURL });
10
+ }
11
+ async interactStream(createContext, { projectID, userID, environment, action }) {
12
+ const result = await this.fetch.post(`/v2/public/project/${projectID}/user/${encodeURIComponent(userID)}/interact/stream`, {
13
+ query: new URLSearchParams({
14
+ completion_events: String(true),
15
+ ...(environment && { environment }),
16
+ }),
17
+ json: { action },
18
+ });
19
+ if (!result.body) {
20
+ throw new Error('interact stream body is empty');
21
+ }
22
+ return result.body
23
+ .pipeThrough(new TextDecoderStream())
24
+ .pipeThrough(new EventSourceParserStream())
25
+ .pipeThrough(new InteractTraceStream(createContext, this.trace));
26
+ }
27
+ }
@@ -0,0 +1,9 @@
1
+ import { Trace } from '@voiceflow/base-types';
2
+ import type { TraceDeclaration, TraceOptions } from '../trace/index.js';
3
+ export declare class TraceService<T = unknown> {
4
+ private readonly traces;
5
+ constructor(options?: TraceOptions<T>);
6
+ registerTrace(step: TraceDeclaration<T, any>): this;
7
+ processTrace(context: T, data: Trace.AnyTrace): Promise<T | null>;
8
+ }
9
+ //# sourceMappingURL=trace.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace.service.d.ts","sourceRoot":"","sources":["../../../src/v2/trace.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE9D,qBAAa,YAAY,CAAC,CAAC,GAAG,OAAO;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkC;gBAEtC,OAAO,GAAE,YAAY,CAAC,CAAC,CAAM;IAIzC,aAAa,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI;IAK7C,YAAY,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;CAM/E"}
@@ -0,0 +1,16 @@
1
+ export class TraceService {
2
+ constructor(options = {}) {
3
+ this.traces = [];
4
+ this.traces = options.traces ?? [];
5
+ }
6
+ registerTrace(step) {
7
+ this.traces.push(step);
8
+ return this;
9
+ }
10
+ async processTrace(context, data) {
11
+ const trace = this.traces.find((trace) => trace.canHandle(data));
12
+ if (!trace)
13
+ return null;
14
+ return trace.handle({ context }, data);
15
+ }
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voiceflow/sdk-runtime",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./build/esm/main.js",
@@ -27,10 +27,11 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@voiceflow/base-types": "2.113.1",
30
+ "eventsource-parser": "3.0.0",
30
31
  "http-errors": "2.0.0"
31
32
  },
32
33
  "devDependencies": {
33
- "@types/http-errors": "^1.8.2"
34
+ "@types/http-errors": "1.8.2"
34
35
  },
35
36
  "volta": {
36
37
  "extends": "../../package.json"
@@ -38,5 +39,5 @@
38
39
  "publishConfig": {
39
40
  "access": "public"
40
41
  },
41
- "gitHead": "8f7a30096b299f1f627adcbd760a5f7564684819"
42
+ "gitHead": "f931229794b4f2f3e103c8cee007fbf7ccfcd7ab"
42
43
  }