@voiceflow/sdk-runtime 1.2.1 → 1.3.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/CHANGELOG.md +12 -0
- package/build/cjs/runtime/index.d.ts +2 -0
- package/build/cjs/runtime/index.d.ts.map +1 -1
- package/build/cjs/runtime/index.js +2 -0
- package/build/cjs/runtime/runtime.interface.d.ts +10 -2
- package/build/cjs/runtime/runtime.interface.d.ts.map +1 -1
- package/build/cjs/runtime/runtime.interface.js +9 -1
- package/build/cjs/runtime/runtime.service.auth.d.ts +8 -0
- package/build/cjs/runtime/runtime.service.auth.d.ts.map +1 -0
- package/build/cjs/runtime/runtime.service.auth.js +23 -0
- package/build/cjs/runtime/runtime.service.d.ts +4 -4
- package/build/cjs/runtime/runtime.service.d.ts.map +1 -1
- package/build/cjs/runtime/runtime.service.js +0 -13
- package/build/cjs/runtime/runtime.service.public.d.ts +8 -0
- package/build/cjs/runtime/runtime.service.public.d.ts.map +1 -0
- package/build/cjs/runtime/runtime.service.public.js +21 -0
- package/build/cjs/sdk/sdk.service.d.ts +1 -1
- package/build/cjs/sdk/sdk.service.d.ts.map +1 -1
- package/build/cjs/sdk/sdk.service.js +12 -5
- package/build/cjs/trace/trace.interface.d.ts +1 -3
- package/build/cjs/trace/trace.interface.d.ts.map +1 -1
- package/build/cjs/trace/trace.service.d.ts +2 -2
- package/build/cjs/trace/trace.service.d.ts.map +1 -1
- package/build/cjs/trace/trace.service.js +2 -6
- package/build/esm/runtime/index.d.ts +2 -0
- package/build/esm/runtime/index.d.ts.map +1 -1
- package/build/esm/runtime/index.js +2 -0
- package/build/esm/runtime/runtime.interface.d.ts +10 -2
- package/build/esm/runtime/runtime.interface.d.ts.map +1 -1
- package/build/esm/runtime/runtime.interface.js +6 -0
- package/build/esm/runtime/runtime.service.auth.d.ts +8 -0
- package/build/esm/runtime/runtime.service.auth.d.ts.map +1 -0
- package/build/esm/runtime/runtime.service.auth.js +19 -0
- package/build/esm/runtime/runtime.service.d.ts +4 -4
- package/build/esm/runtime/runtime.service.d.ts.map +1 -1
- package/build/esm/runtime/runtime.service.js +0 -13
- package/build/esm/runtime/runtime.service.public.d.ts +8 -0
- package/build/esm/runtime/runtime.service.public.d.ts.map +1 -0
- package/build/esm/runtime/runtime.service.public.js +17 -0
- package/build/esm/sdk/sdk.service.d.ts +1 -1
- package/build/esm/sdk/sdk.service.d.ts.map +1 -1
- package/build/esm/sdk/sdk.service.js +11 -4
- package/build/esm/trace/trace.interface.d.ts +1 -3
- package/build/esm/trace/trace.interface.d.ts.map +1 -1
- package/build/esm/trace/trace.service.d.ts +2 -2
- package/build/esm/trace/trace.service.d.ts.map +1 -1
- package/build/esm/trace/trace.service.js +2 -6
- package/package.json +2 -2
- package/src/runtime/index.ts +2 -0
- package/src/runtime/runtime.interface.ts +22 -2
- package/src/runtime/runtime.service.auth.ts +31 -0
- package/src/runtime/runtime.service.public.ts +32 -0
- package/src/runtime/runtime.service.ts +7 -17
- package/src/sdk/sdk.service.ts +17 -5
- package/src/trace/trace.interface.ts +1 -3
- package/src/trace/trace.service.ts +3 -11
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.3.1](https://github.com/voiceflow/adapters/compare/@voiceflow/sdk-runtime@1.3.0...@voiceflow/sdk-runtime@1.3.1) (2022-10-03)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* more lenient typing for sample use case (CT-1046) ([861de03](https://github.com/voiceflow/adapters/commit/861de03c9e05d56c0e1439c5355bb057e7f7381b))
|
|
11
|
+
|
|
12
|
+
# [1.3.0](https://github.com/voiceflow/adapters/compare/@voiceflow/sdk-runtime@1.2.1...@voiceflow/sdk-runtime@1.3.0) (2022-10-03)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* public interaction endpoint (CT-1046) ([#41](https://github.com/voiceflow/adapters/issues/41)) ([2f33365](https://github.com/voiceflow/adapters/commit/2f33365796386b4389d0400c9f9d729174e4e2f9))
|
|
17
|
+
|
|
6
18
|
## 1.2.1 (2022-09-06)
|
|
7
19
|
|
|
8
20
|
**Note:** Version bump only for package @voiceflow/sdk-runtime
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC"}
|
|
@@ -15,4 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./runtime.interface.js"), exports);
|
|
18
|
+
__exportStar(require("./runtime.service.auth.js"), exports);
|
|
18
19
|
__exportStar(require("./runtime.service.js"), exports);
|
|
20
|
+
__exportStar(require("./runtime.service.public.js"), exports);
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
declare type FetchFn = (...parameters: any[]) => Promise<any>;
|
|
2
|
-
export interface RuntimeOptions {
|
|
2
|
+
export interface RuntimeOptions<V = AuthVerify | PublicVerify> {
|
|
3
3
|
url: string;
|
|
4
|
-
|
|
4
|
+
verify: V;
|
|
5
5
|
/**
|
|
6
6
|
* A ponyfill to use for `fetch()`.
|
|
7
7
|
* Defaults to the global `fetch()`.
|
|
8
8
|
*/
|
|
9
9
|
fetchPonyfill?: FetchFn;
|
|
10
10
|
}
|
|
11
|
+
export interface AuthVerify {
|
|
12
|
+
authorization: string;
|
|
13
|
+
}
|
|
14
|
+
export interface PublicVerify {
|
|
15
|
+
projectID: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const isAuthRuntimeOptions: (options: RuntimeOptions<Partial<AuthVerify & PublicVerify>>) => options is RuntimeOptions<AuthVerify>;
|
|
18
|
+
export declare const isPublicRuntimeOptions: (options: RuntimeOptions<Partial<AuthVerify & PublicVerify>>) => options is RuntimeOptions<PublicVerify>;
|
|
11
19
|
export interface RuntimeInteractRequest {
|
|
12
20
|
action: RuntimeAction;
|
|
13
21
|
sessionID: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.interface.d.ts","sourceRoot":"","sources":["../../../src/runtime/runtime.interface.ts"],"names":[],"mappings":"AACA,aAAK,OAAO,GAAG,CAAC,GAAG,UAAU,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAEtD,MAAM,WAAW,cAAc;
|
|
1
|
+
{"version":3,"file":"runtime.interface.d.ts","sourceRoot":"","sources":["../../../src/runtime/runtime.interface.ts"],"names":[],"mappings":"AACA,aAAK,OAAO,GAAG,CAAC,GAAG,UAAU,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAEtD,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,UAAU,GAAG,YAAY;IAC3D,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,CAAC,CAAC;IAEV;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IACzB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,oBAAoB,YACtB,eAAe,QAAQ,UAAU,GAAG,YAAY,CAAC,CAAC,0CAG5D,CAAC;AAEF,eAAO,MAAM,sBAAsB,YACxB,eAAe,QAAQ,UAAU,GA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MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB"}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isStreamTrace = exports.isVisualTrace = exports.isTextTrace = exports.isSpeakTrace = exports.isPayloadTrace = exports.isEndTrace = exports.isChoiceTrace = exports.isCardTrace = exports.isRuntimeTrace = exports.isRuntimeTraceType = exports.RuntimeTraceTypeSet = exports.createIntentAction = exports.isIntentAction = exports.isRuntimeAction = exports.isRuntimeActionType = exports.RuntimeActionTypeSet = void 0;
|
|
3
|
+
exports.isStreamTrace = exports.isVisualTrace = exports.isTextTrace = exports.isSpeakTrace = exports.isPayloadTrace = exports.isEndTrace = exports.isChoiceTrace = exports.isCardTrace = exports.isRuntimeTrace = exports.isRuntimeTraceType = exports.RuntimeTraceTypeSet = exports.createIntentAction = exports.isIntentAction = exports.isRuntimeAction = exports.isRuntimeActionType = exports.RuntimeActionTypeSet = exports.isPublicRuntimeOptions = exports.isAuthRuntimeOptions = void 0;
|
|
4
|
+
const isAuthRuntimeOptions = (options) => {
|
|
5
|
+
return !!options?.verify?.authorization;
|
|
6
|
+
};
|
|
7
|
+
exports.isAuthRuntimeOptions = isAuthRuntimeOptions;
|
|
8
|
+
const isPublicRuntimeOptions = (options) => {
|
|
9
|
+
return typeof options?.verify?.projectID === 'string';
|
|
10
|
+
};
|
|
11
|
+
exports.isPublicRuntimeOptions = isPublicRuntimeOptions;
|
|
4
12
|
exports.RuntimeActionTypeSet = new Set(['launch', 'intent', 'text', '...etc']);
|
|
5
13
|
const isRuntimeActionType = (value) => typeof value === 'string' && exports.RuntimeActionTypeSet.has(value);
|
|
6
14
|
exports.isRuntimeActionType = isRuntimeActionType;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AuthVerify, RuntimeInteractRequest, RuntimeInteractResponse, RuntimeOptions } from '../runtime/runtime.interface.js';
|
|
2
|
+
import { RuntimeService } from '../runtime/runtime.service';
|
|
3
|
+
export declare class AuthRuntimeService extends RuntimeService {
|
|
4
|
+
private readonly authorization;
|
|
5
|
+
constructor(options: RuntimeOptions<AuthVerify>);
|
|
6
|
+
interact(request: RuntimeInteractRequest): Promise<RuntimeInteractResponse>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=runtime.service.auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.service.auth.d.ts","sourceRoot":"","sources":["../../../src/runtime/runtime.service.auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EACf,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,qBAAa,kBAAmB,SAAQ,cAAc;IACpD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;gBAEpB,OAAO,EAAE,cAAc,CAAC,UAAU,CAAC;IAMzC,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,uBAAuB,CAAC;CAazF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthRuntimeService = void 0;
|
|
4
|
+
const runtime_service_1 = require("../runtime/runtime.service");
|
|
5
|
+
class AuthRuntimeService extends runtime_service_1.RuntimeService {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super(options);
|
|
8
|
+
this.authorization = options.verify.authorization;
|
|
9
|
+
}
|
|
10
|
+
async interact(request) {
|
|
11
|
+
const { action, config, sessionID, versionID } = request;
|
|
12
|
+
return this.send(`state/user/${sessionID}/interact`, {
|
|
13
|
+
method: 'POST',
|
|
14
|
+
body: { action, config },
|
|
15
|
+
headers: {
|
|
16
|
+
authorization: this.authorization,
|
|
17
|
+
...(versionID ? { versionID } : {}),
|
|
18
|
+
},
|
|
19
|
+
params: new URLSearchParams({ verbose: 'true' }),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.AuthRuntimeService = AuthRuntimeService;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { RuntimeInteractRequest, RuntimeInteractResponse, RuntimeOptions } from '
|
|
2
|
-
export declare class RuntimeService {
|
|
1
|
+
import type { RuntimeHttpRequest, RuntimeInteractRequest, RuntimeInteractResponse, RuntimeOptions } from './runtime.interface';
|
|
2
|
+
export declare abstract class RuntimeService {
|
|
3
3
|
private readonly options;
|
|
4
4
|
private readonly fetch;
|
|
5
5
|
constructor(options: RuntimeOptions);
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
abstract interact(request: RuntimeInteractRequest): Promise<Partial<RuntimeInteractResponse> & Pick<RuntimeInteractResponse, 'trace'>>;
|
|
7
|
+
protected send<T>(path: string, args?: RuntimeHttpRequest): Promise<T>;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=runtime.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.service.d.ts","sourceRoot":"","sources":["../../../src/runtime/runtime.service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"runtime.service.d.ts","sourceRoot":"","sources":["../../../src/runtime/runtime.service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EACf,MAAM,qBAAqB,CAAC;AAE7B,8BAAsB,cAAc;IAGf,OAAO,CAAC,QAAQ,CAAC,OAAO;IAF3C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA0B;gBAEZ,OAAO,EAAE,cAAc;aAO3C,QAAQ,CACtB,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,OAAO,CAAC,uBAAuB,CAAC,GAAG,IAAI,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;cAErE,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,kBAAuB,GAAG,OAAO,CAAC,CAAC,CAAC;CAoBjF"}
|
|
@@ -31,18 +31,5 @@ class RuntimeService {
|
|
|
31
31
|
}
|
|
32
32
|
return json;
|
|
33
33
|
}
|
|
34
|
-
async interact(request) {
|
|
35
|
-
return this.send(`state/${request.versionID}/user/${request.sessionID}/interact`, {
|
|
36
|
-
method: 'POST',
|
|
37
|
-
body: {
|
|
38
|
-
action: request.action,
|
|
39
|
-
config: request.config,
|
|
40
|
-
},
|
|
41
|
-
headers: {
|
|
42
|
-
authorization: this.options.authorization,
|
|
43
|
-
},
|
|
44
|
-
params: new URLSearchParams({ verbose: 'true' }),
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
34
|
}
|
|
48
35
|
exports.RuntimeService = RuntimeService;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PublicVerify, RuntimeInteractRequest, RuntimeInteractResponse, RuntimeOptions } from '../runtime/runtime.interface.js';
|
|
2
|
+
import { RuntimeService } from '../runtime/runtime.service';
|
|
3
|
+
export declare class PublicRuntimeService extends RuntimeService {
|
|
4
|
+
private readonly projectID;
|
|
5
|
+
constructor(options: RuntimeOptions<PublicVerify>);
|
|
6
|
+
interact(request: RuntimeInteractRequest): Promise<Pick<RuntimeInteractResponse, 'trace'>>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=runtime.service.public.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.service.public.d.ts","sourceRoot":"","sources":["../../../src/runtime/runtime.service.public.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EACf,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,qBAAa,oBAAqB,SAAQ,cAAc;IACtD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAEhB,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC;IAM3C,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;CAcxG"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PublicRuntimeService = void 0;
|
|
4
|
+
const runtime_service_1 = require("../runtime/runtime.service");
|
|
5
|
+
class PublicRuntimeService extends runtime_service_1.RuntimeService {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super(options);
|
|
8
|
+
this.projectID = options.verify.projectID;
|
|
9
|
+
}
|
|
10
|
+
async interact(request) {
|
|
11
|
+
const { action, config, sessionID, versionID } = request;
|
|
12
|
+
return this.send(`public/${this.projectID}/state/user/${sessionID}/interact`, {
|
|
13
|
+
method: 'POST',
|
|
14
|
+
body: { action, config },
|
|
15
|
+
headers: {
|
|
16
|
+
...(versionID ? { versionID } : {}),
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.PublicRuntimeService = PublicRuntimeService;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IntentActionPayload, RuntimeInteractRequest } from '../runtime
|
|
1
|
+
import type { IntentActionPayload, RuntimeInteractRequest } from '../runtime';
|
|
2
2
|
import type { TraceDeclaration } from '../trace/trace.interface.js';
|
|
3
3
|
import type { VoiceflowRuntimeOptions } from './sdk.interface.js';
|
|
4
4
|
export declare class VoiceflowRuntime<T> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.service.d.ts","sourceRoot":"","sources":["../../../src/sdk/sdk.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,
|
|
1
|
+
{"version":3,"file":"sdk.service.d.ts","sourceRoot":"","sources":["../../../src/sdk/sdk.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,EAAkB,MAAM,WAAW,CAAC;AAQ7F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAGnE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAElE,qBAAa,gBAAgB,CAAC,CAAC;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IAEzC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkB;gBAErB,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC;IAY/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;IAKvE,MAAM,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,CAAC,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,mBAAmB,CAAA;KAAE,GAAG,OAAO,CAAC,CAAC,CAAC;CAMpG"}
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VoiceflowRuntime = void 0;
|
|
4
|
-
const
|
|
5
|
-
const runtime_service_js_1 = require("../runtime/runtime.service.js");
|
|
4
|
+
const runtime_1 = require("../runtime");
|
|
6
5
|
const trace_service_js_1 = require("../trace/trace.service.js");
|
|
7
6
|
class VoiceflowRuntime {
|
|
8
7
|
constructor(options) {
|
|
9
|
-
this.runtime = new runtime_service_js_1.RuntimeService(options);
|
|
10
8
|
this.trace = new trace_service_js_1.TraceService(options);
|
|
9
|
+
if ((0, runtime_1.isAuthRuntimeOptions)(options)) {
|
|
10
|
+
this.runtime = new runtime_1.AuthRuntimeService(options);
|
|
11
|
+
}
|
|
12
|
+
else if ((0, runtime_1.isPublicRuntimeOptions)(options)) {
|
|
13
|
+
this.runtime = new runtime_1.PublicRuntimeService(options);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
throw new Error('invalid runtime options');
|
|
17
|
+
}
|
|
11
18
|
}
|
|
12
19
|
registerStep(step) {
|
|
13
20
|
this.trace.registerTrace(step);
|
|
@@ -15,11 +22,11 @@ class VoiceflowRuntime {
|
|
|
15
22
|
}
|
|
16
23
|
async interact(context, request) {
|
|
17
24
|
const response = await this.runtime.interact(request);
|
|
18
|
-
return this.trace.processTrace(context,
|
|
25
|
+
return this.trace.processTrace(context, response);
|
|
19
26
|
}
|
|
20
27
|
intent(request) {
|
|
21
28
|
return this.interact(request.context, {
|
|
22
|
-
action: (0,
|
|
29
|
+
action: (0, runtime_1.createIntentAction)(request.payload),
|
|
23
30
|
sessionID: request.sessionID,
|
|
24
31
|
});
|
|
25
32
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RuntimeTrace } from '../runtime/runtime.interface';
|
|
2
2
|
export interface TraceOptions<T> {
|
|
3
3
|
traces?: TraceDeclaration<T, any>[];
|
|
4
4
|
}
|
|
@@ -8,8 +8,6 @@ export interface TraceDeclaration<Context, Trace extends RuntimeTrace> {
|
|
|
8
8
|
}
|
|
9
9
|
export declare type TraceCanHandle<Trace extends RuntimeTrace> = (trace: Trace) => boolean;
|
|
10
10
|
export interface TraceHandlerMeta<Context> {
|
|
11
|
-
request: RuntimeInteractRequest;
|
|
12
|
-
state: RuntimeState;
|
|
13
11
|
context: Context;
|
|
14
12
|
}
|
|
15
13
|
export declare type TraceAccumulator<Context, Trace extends RuntimeTrace> = (meta: TraceHandlerMeta<Context>, trace: Trace) => Context;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace.interface.d.ts","sourceRoot":"","sources":["../../../src/trace/trace.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"trace.interface.d.ts","sourceRoot":"","sources":["../../../src/trace/trace.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,MAAM,CAAC,EAAE,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;CACrC;AAED,MAAM,WAAW,gBAAgB,CAAC,OAAO,EAAE,KAAK,SAAS,YAAY;IACnE,SAAS,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;CAC1C;AAED,oBAAY,cAAc,CAAC,KAAK,SAAS,YAAY,IAAI,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC;AAEnF,MAAM,WAAW,gBAAgB,CAAC,OAAO;IACvC,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,oBAAY,gBAAgB,CAAC,OAAO,EAAE,KAAK,SAAS,YAAY,IAAI,CAClE,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,EAC/B,KAAK,EAAE,KAAK,KACT,OAAO,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RuntimeInteractResponse } from '../runtime/runtime.interface.js';
|
|
2
2
|
import type { TraceDeclaration, TraceOptions } from './trace.interface';
|
|
3
3
|
export declare class TraceService<T = unknown> {
|
|
4
4
|
private readonly traces;
|
|
5
5
|
constructor(options?: TraceOptions<T>);
|
|
6
6
|
registerTrace(step: TraceDeclaration<T, any>): this;
|
|
7
7
|
registerTraces(steps: TraceDeclaration<T, any>[]): this;
|
|
8
|
-
processTrace(context: T,
|
|
8
|
+
processTrace(context: T, response: Pick<RuntimeInteractResponse, 'trace'>): Promise<T>;
|
|
9
9
|
}
|
|
10
10
|
//# sourceMappingURL=trace.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace.service.d.ts","sourceRoot":"","sources":["../../../src/trace/trace.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"trace.service.d.ts","sourceRoot":"","sources":["../../../src/trace/trace.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAE9E,OAAO,KAAK,EAAE,gBAAgB,EAAoB,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAE1F,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;IAKnD,cAAc,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,IAAI;IAKjD,YAAY,CAAC,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,uBAAuB,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAYpG"}
|
|
@@ -14,12 +14,8 @@ class TraceService {
|
|
|
14
14
|
steps.forEach((step) => this.registerTrace(step));
|
|
15
15
|
return this;
|
|
16
16
|
}
|
|
17
|
-
async processTrace(context,
|
|
18
|
-
const meta = {
|
|
19
|
-
request,
|
|
20
|
-
state: response.state,
|
|
21
|
-
context,
|
|
22
|
-
};
|
|
17
|
+
async processTrace(context, response) {
|
|
18
|
+
const meta = { context };
|
|
23
19
|
for (const trace of response.trace) {
|
|
24
20
|
const step = this.traces.find((step) => step.canHandle(trace));
|
|
25
21
|
if (step) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC"}
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
declare type FetchFn = (...parameters: any[]) => Promise<any>;
|
|
2
|
-
export interface RuntimeOptions {
|
|
2
|
+
export interface RuntimeOptions<V = AuthVerify | PublicVerify> {
|
|
3
3
|
url: string;
|
|
4
|
-
|
|
4
|
+
verify: V;
|
|
5
5
|
/**
|
|
6
6
|
* A ponyfill to use for `fetch()`.
|
|
7
7
|
* Defaults to the global `fetch()`.
|
|
8
8
|
*/
|
|
9
9
|
fetchPonyfill?: FetchFn;
|
|
10
10
|
}
|
|
11
|
+
export interface AuthVerify {
|
|
12
|
+
authorization: string;
|
|
13
|
+
}
|
|
14
|
+
export interface PublicVerify {
|
|
15
|
+
projectID: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const isAuthRuntimeOptions: (options: RuntimeOptions<Partial<AuthVerify & PublicVerify>>) => options is RuntimeOptions<AuthVerify>;
|
|
18
|
+
export declare const isPublicRuntimeOptions: (options: RuntimeOptions<Partial<AuthVerify & PublicVerify>>) => options is RuntimeOptions<PublicVerify>;
|
|
11
19
|
export interface RuntimeInteractRequest {
|
|
12
20
|
action: RuntimeAction;
|
|
13
21
|
sessionID: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.interface.d.ts","sourceRoot":"","sources":["../../../src/runtime/runtime.interface.ts"],"names":[],"mappings":"AACA,aAAK,OAAO,GAAG,CAAC,GAAG,UAAU,EAAE,GAAG,EA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AE,gBAAgB,CAAC,CAAC;AAE/D,eAAO,MAAM,WAAW,UAAW,OAAO,uBAAuE,CAAC;AAElH,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,oBAAY,WAAW,GAAG,YAAY,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;AAErE,eAAO,MAAM,aAAa,UAAW,OAAO,yBAA2E,CAAC;AAExH,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,OAAO,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,oBAAY,WAAW,GAAG,YAAY,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;AAErE,eAAO,MAAM,aAAa,UAAW,OAAO,yBAA2E,CAAC;AAExH,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB"}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
export const isAuthRuntimeOptions = (options) => {
|
|
2
|
+
return !!options?.verify?.authorization;
|
|
3
|
+
};
|
|
4
|
+
export const isPublicRuntimeOptions = (options) => {
|
|
5
|
+
return typeof options?.verify?.projectID === 'string';
|
|
6
|
+
};
|
|
1
7
|
export const RuntimeActionTypeSet = new Set(['launch', 'intent', 'text', '...etc']);
|
|
2
8
|
export const isRuntimeActionType = (value) => typeof value === 'string' && RuntimeActionTypeSet.has(value);
|
|
3
9
|
export const isRuntimeAction = (value) => typeof value === 'object' &&
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AuthVerify, RuntimeInteractRequest, RuntimeInteractResponse, RuntimeOptions } from '../runtime/runtime.interface.js';
|
|
2
|
+
import { RuntimeService } from '../runtime/runtime.service.js';
|
|
3
|
+
export declare class AuthRuntimeService extends RuntimeService {
|
|
4
|
+
private readonly authorization;
|
|
5
|
+
constructor(options: RuntimeOptions<AuthVerify>);
|
|
6
|
+
interact(request: RuntimeInteractRequest): Promise<RuntimeInteractResponse>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=runtime.service.auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.service.auth.d.ts","sourceRoot":"","sources":["../../../src/runtime/runtime.service.auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EACf,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,qBAAa,kBAAmB,SAAQ,cAAc;IACpD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;gBAEpB,OAAO,EAAE,cAAc,CAAC,UAAU,CAAC;IAMzC,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,uBAAuB,CAAC;CAazF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RuntimeService } from '../runtime/runtime.service.js';
|
|
2
|
+
export class AuthRuntimeService extends RuntimeService {
|
|
3
|
+
constructor(options) {
|
|
4
|
+
super(options);
|
|
5
|
+
this.authorization = options.verify.authorization;
|
|
6
|
+
}
|
|
7
|
+
async interact(request) {
|
|
8
|
+
const { action, config, sessionID, versionID } = request;
|
|
9
|
+
return this.send(`state/user/${sessionID}/interact`, {
|
|
10
|
+
method: 'POST',
|
|
11
|
+
body: { action, config },
|
|
12
|
+
headers: {
|
|
13
|
+
authorization: this.authorization,
|
|
14
|
+
...(versionID ? { versionID } : {}),
|
|
15
|
+
},
|
|
16
|
+
params: new URLSearchParams({ verbose: 'true' }),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { RuntimeInteractRequest, RuntimeInteractResponse, RuntimeOptions } from '
|
|
2
|
-
export declare class RuntimeService {
|
|
1
|
+
import type { RuntimeHttpRequest, RuntimeInteractRequest, RuntimeInteractResponse, RuntimeOptions } from './runtime.interface.js';
|
|
2
|
+
export declare abstract class RuntimeService {
|
|
3
3
|
private readonly options;
|
|
4
4
|
private readonly fetch;
|
|
5
5
|
constructor(options: RuntimeOptions);
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
abstract interact(request: RuntimeInteractRequest): Promise<Partial<RuntimeInteractResponse> & Pick<RuntimeInteractResponse, 'trace'>>;
|
|
7
|
+
protected send<T>(path: string, args?: RuntimeHttpRequest): Promise<T>;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=runtime.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.service.d.ts","sourceRoot":"","sources":["../../../src/runtime/runtime.service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"runtime.service.d.ts","sourceRoot":"","sources":["../../../src/runtime/runtime.service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EACf,MAAM,qBAAqB,CAAC;AAE7B,8BAAsB,cAAc;IAGf,OAAO,CAAC,QAAQ,CAAC,OAAO;IAF3C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA0B;gBAEZ,OAAO,EAAE,cAAc;aAO3C,QAAQ,CACtB,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,OAAO,CAAC,uBAAuB,CAAC,GAAG,IAAI,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;cAErE,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,kBAAuB,GAAG,OAAO,CAAC,CAAC,CAAC;CAoBjF"}
|
|
@@ -25,17 +25,4 @@ export class RuntimeService {
|
|
|
25
25
|
}
|
|
26
26
|
return json;
|
|
27
27
|
}
|
|
28
|
-
async interact(request) {
|
|
29
|
-
return this.send(`state/${request.versionID}/user/${request.sessionID}/interact`, {
|
|
30
|
-
method: 'POST',
|
|
31
|
-
body: {
|
|
32
|
-
action: request.action,
|
|
33
|
-
config: request.config,
|
|
34
|
-
},
|
|
35
|
-
headers: {
|
|
36
|
-
authorization: this.options.authorization,
|
|
37
|
-
},
|
|
38
|
-
params: new URLSearchParams({ verbose: 'true' }),
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
28
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PublicVerify, RuntimeInteractRequest, RuntimeInteractResponse, RuntimeOptions } from '../runtime/runtime.interface.js';
|
|
2
|
+
import { RuntimeService } from '../runtime/runtime.service.js';
|
|
3
|
+
export declare class PublicRuntimeService extends RuntimeService {
|
|
4
|
+
private readonly projectID;
|
|
5
|
+
constructor(options: RuntimeOptions<PublicVerify>);
|
|
6
|
+
interact(request: RuntimeInteractRequest): Promise<Pick<RuntimeInteractResponse, 'trace'>>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=runtime.service.public.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.service.public.d.ts","sourceRoot":"","sources":["../../../src/runtime/runtime.service.public.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EACf,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,qBAAa,oBAAqB,SAAQ,cAAc;IACtD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAEhB,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC;IAM3C,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;CAcxG"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RuntimeService } from '../runtime/runtime.service.js';
|
|
2
|
+
export class PublicRuntimeService extends RuntimeService {
|
|
3
|
+
constructor(options) {
|
|
4
|
+
super(options);
|
|
5
|
+
this.projectID = options.verify.projectID;
|
|
6
|
+
}
|
|
7
|
+
async interact(request) {
|
|
8
|
+
const { action, config, sessionID, versionID } = request;
|
|
9
|
+
return this.send(`public/${this.projectID}/state/user/${sessionID}/interact`, {
|
|
10
|
+
method: 'POST',
|
|
11
|
+
body: { action, config },
|
|
12
|
+
headers: {
|
|
13
|
+
...(versionID ? { versionID } : {}),
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IntentActionPayload, RuntimeInteractRequest } from '../runtime/
|
|
1
|
+
import type { IntentActionPayload, RuntimeInteractRequest } from '../runtime/index.js';
|
|
2
2
|
import type { TraceDeclaration } from '../trace/trace.interface.js';
|
|
3
3
|
import type { VoiceflowRuntimeOptions } from './sdk.interface.js';
|
|
4
4
|
export declare class VoiceflowRuntime<T> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.service.d.ts","sourceRoot":"","sources":["../../../src/sdk/sdk.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,
|
|
1
|
+
{"version":3,"file":"sdk.service.d.ts","sourceRoot":"","sources":["../../../src/sdk/sdk.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,EAAkB,MAAM,WAAW,CAAC;AAQ7F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAGnE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAElE,qBAAa,gBAAgB,CAAC,CAAC;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IAEzC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkB;gBAErB,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC;IAY/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;IAKvE,MAAM,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,CAAC,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,mBAAmB,CAAA;KAAE,GAAG,OAAO,CAAC,CAAC,CAAC;CAMpG"}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import { createIntentAction } from '../runtime/
|
|
2
|
-
import { RuntimeService } from '../runtime/runtime.service.js';
|
|
1
|
+
import { AuthRuntimeService, createIntentAction, isAuthRuntimeOptions, isPublicRuntimeOptions, PublicRuntimeService, } from '../runtime/index.js';
|
|
3
2
|
import { TraceService } from '../trace/trace.service.js';
|
|
4
3
|
export class VoiceflowRuntime {
|
|
5
4
|
constructor(options) {
|
|
6
|
-
this.runtime = new RuntimeService(options);
|
|
7
5
|
this.trace = new TraceService(options);
|
|
6
|
+
if (isAuthRuntimeOptions(options)) {
|
|
7
|
+
this.runtime = new AuthRuntimeService(options);
|
|
8
|
+
}
|
|
9
|
+
else if (isPublicRuntimeOptions(options)) {
|
|
10
|
+
this.runtime = new PublicRuntimeService(options);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
throw new Error('invalid runtime options');
|
|
14
|
+
}
|
|
8
15
|
}
|
|
9
16
|
registerStep(step) {
|
|
10
17
|
this.trace.registerTrace(step);
|
|
@@ -12,7 +19,7 @@ export class VoiceflowRuntime {
|
|
|
12
19
|
}
|
|
13
20
|
async interact(context, request) {
|
|
14
21
|
const response = await this.runtime.interact(request);
|
|
15
|
-
return this.trace.processTrace(context,
|
|
22
|
+
return this.trace.processTrace(context, response);
|
|
16
23
|
}
|
|
17
24
|
intent(request) {
|
|
18
25
|
return this.interact(request.context, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RuntimeTrace } from '../runtime/runtime.interface.js';
|
|
2
2
|
export interface TraceOptions<T> {
|
|
3
3
|
traces?: TraceDeclaration<T, any>[];
|
|
4
4
|
}
|
|
@@ -8,8 +8,6 @@ export interface TraceDeclaration<Context, Trace extends RuntimeTrace> {
|
|
|
8
8
|
}
|
|
9
9
|
export declare type TraceCanHandle<Trace extends RuntimeTrace> = (trace: Trace) => boolean;
|
|
10
10
|
export interface TraceHandlerMeta<Context> {
|
|
11
|
-
request: RuntimeInteractRequest;
|
|
12
|
-
state: RuntimeState;
|
|
13
11
|
context: Context;
|
|
14
12
|
}
|
|
15
13
|
export declare type TraceAccumulator<Context, Trace extends RuntimeTrace> = (meta: TraceHandlerMeta<Context>, trace: Trace) => Context;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace.interface.d.ts","sourceRoot":"","sources":["../../../src/trace/trace.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"trace.interface.d.ts","sourceRoot":"","sources":["../../../src/trace/trace.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,MAAM,CAAC,EAAE,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;CACrC;AAED,MAAM,WAAW,gBAAgB,CAAC,OAAO,EAAE,KAAK,SAAS,YAAY;IACnE,SAAS,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;CAC1C;AAED,oBAAY,cAAc,CAAC,KAAK,SAAS,YAAY,IAAI,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC;AAEnF,MAAM,WAAW,gBAAgB,CAAC,OAAO;IACvC,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,oBAAY,gBAAgB,CAAC,OAAO,EAAE,KAAK,SAAS,YAAY,IAAI,CAClE,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,EAC/B,KAAK,EAAE,KAAK,KACT,OAAO,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RuntimeInteractResponse } from '../runtime/runtime.interface.js';
|
|
2
2
|
import type { TraceDeclaration, TraceOptions } from './trace.interface.js';
|
|
3
3
|
export declare class TraceService<T = unknown> {
|
|
4
4
|
private readonly traces;
|
|
5
5
|
constructor(options?: TraceOptions<T>);
|
|
6
6
|
registerTrace(step: TraceDeclaration<T, any>): this;
|
|
7
7
|
registerTraces(steps: TraceDeclaration<T, any>[]): this;
|
|
8
|
-
processTrace(context: T,
|
|
8
|
+
processTrace(context: T, response: Pick<RuntimeInteractResponse, 'trace'>): Promise<T>;
|
|
9
9
|
}
|
|
10
10
|
//# sourceMappingURL=trace.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace.service.d.ts","sourceRoot":"","sources":["../../../src/trace/trace.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"trace.service.d.ts","sourceRoot":"","sources":["../../../src/trace/trace.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAE9E,OAAO,KAAK,EAAE,gBAAgB,EAAoB,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAE1F,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;IAKnD,cAAc,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,IAAI;IAKjD,YAAY,CAAC,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,uBAAuB,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAYpG"}
|
|
@@ -11,12 +11,8 @@ export class TraceService {
|
|
|
11
11
|
steps.forEach((step) => this.registerTrace(step));
|
|
12
12
|
return this;
|
|
13
13
|
}
|
|
14
|
-
async processTrace(context,
|
|
15
|
-
const meta = {
|
|
16
|
-
request,
|
|
17
|
-
state: response.state,
|
|
18
|
-
context,
|
|
19
|
-
};
|
|
14
|
+
async processTrace(context, response) {
|
|
15
|
+
const meta = { context };
|
|
20
16
|
for (const trace of response.trace) {
|
|
21
17
|
const step = this.traces.find((step) => step.canHandle(trace));
|
|
22
18
|
if (step) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voiceflow/sdk-runtime",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
6
|
"import": "./build/esm/main.js",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "6f122cb59f0427fdf466508f1472ca973f181d6e"
|
|
45
45
|
}
|
package/src/runtime/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Super broad type so that differing fetch types (ex. builtin, node-fetch, etc.) don't conflict with it
|
|
2
2
|
type FetchFn = (...parameters: any[]) => Promise<any>;
|
|
3
3
|
|
|
4
|
-
export interface RuntimeOptions {
|
|
4
|
+
export interface RuntimeOptions<V = AuthVerify | PublicVerify> {
|
|
5
5
|
url: string;
|
|
6
|
-
|
|
6
|
+
verify: V;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* A ponyfill to use for `fetch()`.
|
|
@@ -12,6 +12,26 @@ export interface RuntimeOptions {
|
|
|
12
12
|
fetchPonyfill?: FetchFn;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
export interface AuthVerify {
|
|
16
|
+
authorization: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface PublicVerify {
|
|
20
|
+
projectID: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const isAuthRuntimeOptions = (
|
|
24
|
+
options: RuntimeOptions<Partial<AuthVerify & PublicVerify>>
|
|
25
|
+
): options is RuntimeOptions<AuthVerify> => {
|
|
26
|
+
return !!options?.verify?.authorization;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const isPublicRuntimeOptions = (
|
|
30
|
+
options: RuntimeOptions<Partial<AuthVerify & PublicVerify>>
|
|
31
|
+
): options is RuntimeOptions<PublicVerify> => {
|
|
32
|
+
return typeof options?.verify?.projectID === 'string';
|
|
33
|
+
};
|
|
34
|
+
|
|
15
35
|
export interface RuntimeInteractRequest {
|
|
16
36
|
action: RuntimeAction;
|
|
17
37
|
sessionID: string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AuthVerify,
|
|
3
|
+
RuntimeInteractRequest,
|
|
4
|
+
RuntimeInteractResponse,
|
|
5
|
+
RuntimeOptions,
|
|
6
|
+
} from '@/runtime/runtime.interface.js';
|
|
7
|
+
import { RuntimeService } from '@/runtime/runtime.service';
|
|
8
|
+
|
|
9
|
+
export class AuthRuntimeService extends RuntimeService {
|
|
10
|
+
private readonly authorization: string;
|
|
11
|
+
|
|
12
|
+
public constructor(options: RuntimeOptions<AuthVerify>) {
|
|
13
|
+
super(options);
|
|
14
|
+
|
|
15
|
+
this.authorization = options.verify.authorization;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public async interact(request: RuntimeInteractRequest): Promise<RuntimeInteractResponse> {
|
|
19
|
+
const { action, config, sessionID, versionID } = request;
|
|
20
|
+
|
|
21
|
+
return this.send<RuntimeInteractResponse>(`state/user/${sessionID}/interact`, {
|
|
22
|
+
method: 'POST',
|
|
23
|
+
body: { action, config },
|
|
24
|
+
headers: {
|
|
25
|
+
authorization: this.authorization,
|
|
26
|
+
...(versionID ? { versionID } : {}),
|
|
27
|
+
},
|
|
28
|
+
params: new URLSearchParams({ verbose: 'true' }),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
PublicVerify,
|
|
3
|
+
RuntimeInteractRequest,
|
|
4
|
+
RuntimeInteractResponse,
|
|
5
|
+
RuntimeOptions,
|
|
6
|
+
} from '@/runtime/runtime.interface.js';
|
|
7
|
+
import { RuntimeService } from '@/runtime/runtime.service';
|
|
8
|
+
|
|
9
|
+
export class PublicRuntimeService extends RuntimeService {
|
|
10
|
+
private readonly projectID: string;
|
|
11
|
+
|
|
12
|
+
public constructor(options: RuntimeOptions<PublicVerify>) {
|
|
13
|
+
super(options);
|
|
14
|
+
|
|
15
|
+
this.projectID = options.verify.projectID;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public async interact(request: RuntimeInteractRequest): Promise<Pick<RuntimeInteractResponse, 'trace'>> {
|
|
19
|
+
const { action, config, sessionID, versionID } = request;
|
|
20
|
+
|
|
21
|
+
return this.send<Pick<RuntimeInteractResponse, 'trace'>>(
|
|
22
|
+
`public/${this.projectID}/state/user/${sessionID}/interact`,
|
|
23
|
+
{
|
|
24
|
+
method: 'POST',
|
|
25
|
+
body: { action, config },
|
|
26
|
+
headers: {
|
|
27
|
+
...(versionID ? { versionID } : {}),
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -5,9 +5,9 @@ import type {
|
|
|
5
5
|
RuntimeInteractRequest,
|
|
6
6
|
RuntimeInteractResponse,
|
|
7
7
|
RuntimeOptions,
|
|
8
|
-
} from '
|
|
8
|
+
} from './runtime.interface';
|
|
9
9
|
|
|
10
|
-
export class RuntimeService {
|
|
10
|
+
export abstract class RuntimeService {
|
|
11
11
|
private readonly fetch: typeof globalThis.fetch;
|
|
12
12
|
|
|
13
13
|
public constructor(private readonly options: RuntimeOptions) {
|
|
@@ -17,7 +17,11 @@ export class RuntimeService {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
public abstract interact(
|
|
21
|
+
request: RuntimeInteractRequest
|
|
22
|
+
): Promise<Partial<RuntimeInteractResponse> & Pick<RuntimeInteractResponse, 'trace'>>;
|
|
23
|
+
|
|
24
|
+
protected async send<T>(path: string, args: RuntimeHttpRequest = {}): Promise<T> {
|
|
21
25
|
const url = new URL(path, this.options.url);
|
|
22
26
|
if (args.params) url.search = args.params.toString();
|
|
23
27
|
|
|
@@ -37,18 +41,4 @@ export class RuntimeService {
|
|
|
37
41
|
|
|
38
42
|
return json;
|
|
39
43
|
}
|
|
40
|
-
|
|
41
|
-
public async interact(request: RuntimeInteractRequest): Promise<RuntimeInteractResponse> {
|
|
42
|
-
return this.send<RuntimeInteractResponse>(`state/${request.versionID}/user/${request.sessionID}/interact`, {
|
|
43
|
-
method: 'POST',
|
|
44
|
-
body: {
|
|
45
|
-
action: request.action,
|
|
46
|
-
config: request.config,
|
|
47
|
-
},
|
|
48
|
-
headers: {
|
|
49
|
-
authorization: this.options.authorization,
|
|
50
|
-
},
|
|
51
|
-
params: new URLSearchParams({ verbose: 'true' }),
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
44
|
}
|
package/src/sdk/sdk.service.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import type { IntentActionPayload, RuntimeInteractRequest } from '@/runtime
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import type { IntentActionPayload, RuntimeInteractRequest, RuntimeService } from '@/runtime';
|
|
2
|
+
import {
|
|
3
|
+
AuthRuntimeService,
|
|
4
|
+
createIntentAction,
|
|
5
|
+
isAuthRuntimeOptions,
|
|
6
|
+
isPublicRuntimeOptions,
|
|
7
|
+
PublicRuntimeService,
|
|
8
|
+
} from '@/runtime';
|
|
4
9
|
import type { TraceDeclaration } from '@/trace/trace.interface.js';
|
|
5
10
|
import { TraceService } from '@/trace/trace.service.js';
|
|
6
11
|
|
|
@@ -12,8 +17,15 @@ export class VoiceflowRuntime<T> {
|
|
|
12
17
|
private readonly trace: TraceService<T>;
|
|
13
18
|
|
|
14
19
|
public constructor(options: VoiceflowRuntimeOptions<T>) {
|
|
15
|
-
this.runtime = new RuntimeService(options);
|
|
16
20
|
this.trace = new TraceService(options);
|
|
21
|
+
|
|
22
|
+
if (isAuthRuntimeOptions(options)) {
|
|
23
|
+
this.runtime = new AuthRuntimeService(options);
|
|
24
|
+
} else if (isPublicRuntimeOptions(options)) {
|
|
25
|
+
this.runtime = new PublicRuntimeService(options);
|
|
26
|
+
} else {
|
|
27
|
+
throw new Error('invalid runtime options');
|
|
28
|
+
}
|
|
17
29
|
}
|
|
18
30
|
|
|
19
31
|
public registerStep(step: TraceDeclaration<T, any>) {
|
|
@@ -23,7 +35,7 @@ export class VoiceflowRuntime<T> {
|
|
|
23
35
|
|
|
24
36
|
public async interact(context: T, request: RuntimeInteractRequest): Promise<T> {
|
|
25
37
|
const response = await this.runtime.interact(request);
|
|
26
|
-
return this.trace.processTrace(context,
|
|
38
|
+
return this.trace.processTrace(context, response);
|
|
27
39
|
}
|
|
28
40
|
|
|
29
41
|
public intent(request: { context: T; sessionID: string; payload: IntentActionPayload }): Promise<T> {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RuntimeTrace } from '@/runtime/runtime.interface';
|
|
2
2
|
|
|
3
3
|
export interface TraceOptions<T> {
|
|
4
4
|
traces?: TraceDeclaration<T, any>[];
|
|
@@ -12,8 +12,6 @@ export interface TraceDeclaration<Context, Trace extends RuntimeTrace> {
|
|
|
12
12
|
export type TraceCanHandle<Trace extends RuntimeTrace> = (trace: Trace) => boolean;
|
|
13
13
|
|
|
14
14
|
export interface TraceHandlerMeta<Context> {
|
|
15
|
-
request: RuntimeInteractRequest;
|
|
16
|
-
state: RuntimeState;
|
|
17
15
|
context: Context;
|
|
18
16
|
}
|
|
19
17
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RuntimeInteractResponse } from '@/runtime/runtime.interface.js';
|
|
2
2
|
|
|
3
3
|
import type { TraceDeclaration, TraceHandlerMeta, TraceOptions } from './trace.interface';
|
|
4
4
|
|
|
@@ -19,16 +19,8 @@ export class TraceService<T = unknown> {
|
|
|
19
19
|
return this;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
public async processTrace(
|
|
23
|
-
|
|
24
|
-
request: RuntimeInteractRequest,
|
|
25
|
-
response: RuntimeInteractResponse
|
|
26
|
-
): Promise<T> {
|
|
27
|
-
const meta: TraceHandlerMeta<T> = {
|
|
28
|
-
request,
|
|
29
|
-
state: response.state,
|
|
30
|
-
context,
|
|
31
|
-
};
|
|
22
|
+
public async processTrace(context: T, response: Pick<RuntimeInteractResponse, 'trace'>): Promise<T> {
|
|
23
|
+
const meta: TraceHandlerMeta<T> = { context };
|
|
32
24
|
|
|
33
25
|
for (const trace of response.trace) {
|
|
34
26
|
const step = this.traces.find((step) => step.canHandle(trace));
|