@chatbotkit/next 0.0.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/.eslintrc ADDED
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @typedef {Generator<object>|AsyncGenerator<object>} IterableObject
3
+ *
4
+ * @param {IterableObject|{stream: () => IterableObject}} source
5
+ * @returns {Response}
6
+ */
7
+ export function stream(source) {
8
+ const encoder = new TextEncoder();
9
+ return new Response(new ReadableStream({
10
+ async start(controller) {
11
+ /** @type {IterableObject} */
12
+ let it;
13
+ if ('next' in source && typeof source.next === 'function') {
14
+ it = source;
15
+ }
16
+ else if ('stream' in source && typeof source.stream === 'function') {
17
+ it = source.stream();
18
+ }
19
+ else {
20
+ throw new Error('Invald source');
21
+ }
22
+ try {
23
+ for await (const event of it) {
24
+ controller.enqueue(encoder.encode(`${JSON.stringify(event)}\n`));
25
+ }
26
+ }
27
+ catch (e) {
28
+ controller.error(e);
29
+ }
30
+ controller.close();
31
+ },
32
+ }), { headers: { 'Content-Type': 'application/jsonl' } });
33
+ }
34
+ export default stream;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @typedef {Generator<object>|AsyncGenerator<object>} IterableObject
3
+ *
4
+ * @param {IterableObject|{stream: () => IterableObject}} source
5
+ * @returns {Response}
6
+ */
7
+ export function stream(source: IterableObject | {
8
+ stream: () => IterableObject;
9
+ }): Response;
10
+ export default stream;
11
+ export type IterableObject = Generator<object> | AsyncGenerator<object>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @typedef {Generator<object>|AsyncGenerator<object>} IterableObject
3
+ *
4
+ * @param {IterableObject|{stream: () => IterableObject}} source
5
+ * @returns {Response}
6
+ */
7
+ export function stream(source: IterableObject | {
8
+ stream: () => IterableObject;
9
+ }): Response;
10
+ export default stream;
11
+ export type IterableObject = Generator<object> | AsyncGenerator<object>;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @typedef {Generator<object>|AsyncGenerator<object>} IterableObject
3
+ *
4
+ * @param {IterableObject|{stream: () => IterableObject}} source
5
+ * @returns {Response}
6
+ */
7
+ export function stream(source) {
8
+ const encoder = new TextEncoder();
9
+ return new Response(new ReadableStream({
10
+ async start(controller) {
11
+ /** @type {IterableObject} */
12
+ let it;
13
+ if ('next' in source && typeof source.next === 'function') {
14
+ it = source;
15
+ }
16
+ else if ('stream' in source && typeof source.stream === 'function') {
17
+ it = source.stream();
18
+ }
19
+ else {
20
+ throw new Error('Invald source');
21
+ }
22
+ try {
23
+ for await (const event of it) {
24
+ controller.enqueue(encoder.encode(`${JSON.stringify(event)}\n`));
25
+ }
26
+ }
27
+ catch (e) {
28
+ controller.error(e);
29
+ }
30
+ controller.close();
31
+ },
32
+ }), { headers: { 'Content-Type': 'application/jsonl' } });
33
+ }
34
+ export default stream;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,96 @@
1
+ {
2
+ "name": "@chatbotkit/next",
3
+ "version": "0.0.0",
4
+ "description": "Utility library for ChatbotKit for Next.js",
5
+ "license": "ISC",
6
+ "engines": {
7
+ "node": ">=18.16.0"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/chatbotkit/node-sdk.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/chatbotkit/node-sdk/issues"
15
+ },
16
+ "homepage": "https://github.com/chatbotkit/node-sdk#readme",
17
+ "author": "",
18
+ "keywords": [
19
+ "chatbotkit",
20
+ "cbk",
21
+ "next.js"
22
+ ],
23
+ "type": "module",
24
+ "main": "./dist/esm/index.js",
25
+ "exports": {
26
+ "./edge": {
27
+ "require": {
28
+ "types": "./dist/cjs/edge.d.ts",
29
+ "default": "./dist/cjs/edge.cjs"
30
+ },
31
+ "import": {
32
+ "types": "./dist/esm/edge.d.ts",
33
+ "default": "./dist/esm/edge.js"
34
+ }
35
+ },
36
+ "./edge.js": {
37
+ "require": {
38
+ "types": "./dist/cjs/edge.d.ts",
39
+ "default": "./dist/cjs/edge.cjs"
40
+ },
41
+ "import": {
42
+ "types": "./dist/esm/edge.d.ts",
43
+ "default": "./dist/esm/edge.js"
44
+ }
45
+ },
46
+ ".": {
47
+ "require": {
48
+ "types": "./dist/cjs/index.d.ts",
49
+ "default": "./dist/cjs/index.cjs"
50
+ },
51
+ "import": {
52
+ "types": "./dist/esm/index.d.ts",
53
+ "default": "./dist/esm/index.js"
54
+ }
55
+ },
56
+ "./index": {
57
+ "require": {
58
+ "types": "./dist/cjs/index.d.ts",
59
+ "default": "./dist/cjs/index.cjs"
60
+ },
61
+ "import": {
62
+ "types": "./dist/esm/index.d.ts",
63
+ "default": "./dist/esm/index.js"
64
+ }
65
+ },
66
+ "./index.js": {
67
+ "require": {
68
+ "types": "./dist/cjs/index.d.ts",
69
+ "default": "./dist/cjs/index.cjs"
70
+ },
71
+ "import": {
72
+ "types": "./dist/esm/index.d.ts",
73
+ "default": "./dist/esm/index.js"
74
+ }
75
+ }
76
+ },
77
+ "scripts": {
78
+ "build": "run-s build:*",
79
+ "build:cjs": "tsc -p tsconfig.cjs.json",
80
+ "build:cjs_rename": "node ../../scripts/rename-cjs.js",
81
+ "build:cjs_rewrite_cjs": "node ../../scripts/rewrite-cjs.js",
82
+ "build:cjs_rewrite_ts": "node ../../scripts/rewrite-ts.js",
83
+ "build:esm": "tsc -p tsconfig.esm.json",
84
+ "build:exports": "node ../../scripts/build-exports.js",
85
+ "check": "tsc --noEmit",
86
+ "export": "node ../../scripts/create-exports.js",
87
+ "lint": "eslint .",
88
+ "postpublish": "npm run export",
89
+ "test": "true"
90
+ },
91
+ "types": "./dist/esm/index.d.ts",
92
+ "dependencies": {},
93
+ "devDependencies": {
94
+ "@system/toolchain": "*"
95
+ }
96
+ }