@pluslabs/utils 0.1.1 → 0.2.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/dist/main/gpt/index.d.ts +18 -0
- package/dist/main/gpt/index.d.ts.map +1 -0
- package/dist/main/gpt/index.js +27 -0
- package/dist/main/gpt/index.js.map +1 -0
- package/dist/main/index.d.ts +1 -0
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +1 -0
- package/dist/main/index.js.map +1 -1
- package/dist/main/stamp/index.d.ts +16 -3
- package/dist/main/stamp/index.d.ts.map +1 -1
- package/dist/main/stamp/index.js +29 -23
- package/dist/main/stamp/index.js.map +1 -1
- package/dist/module/gpt/index.d.ts +18 -0
- package/dist/module/gpt/index.d.ts.map +1 -0
- package/dist/module/gpt/index.js +25 -0
- package/dist/module/gpt/index.js.map +1 -0
- package/dist/module/index.d.ts +1 -0
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +1 -0
- package/dist/module/index.js.map +1 -1
- package/dist/module/stamp/index.d.ts +16 -3
- package/dist/module/stamp/index.d.ts.map +1 -1
- package/dist/module/stamp/index.js +29 -22
- package/dist/module/stamp/index.js.map +1 -1
- package/package.json +1 -1
- package/src/gpt/index.ts +36 -0
- package/src/index.ts +1 -0
- package/src/stamp/index.ts +38 -25
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type ProactiveRequestData = {
|
|
2
|
+
request_id: string;
|
|
3
|
+
assistant_id: string;
|
|
4
|
+
client_id: string;
|
|
5
|
+
client_phone_number: string;
|
|
6
|
+
};
|
|
7
|
+
declare const gpt: {
|
|
8
|
+
extension: {
|
|
9
|
+
/**
|
|
10
|
+
* Send a proactive request to MagicGPT extension
|
|
11
|
+
* @param source String to identify the source of the request
|
|
12
|
+
* @param data ProactiveRequestData to send to the GPT
|
|
13
|
+
*/
|
|
14
|
+
proactiveRequest: (source: string, data: ProactiveRequestData) => void;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export default gpt;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/gpt/index.ts"],"names":[],"mappings":"AAAA,KAAK,oBAAoB,GAAG;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF,QAAA,MAAM,GAAG;;QAED;;;;WAIG;mCACwB,MAAM,QAAQ,oBAAoB;;CAmBpE,CAAC;AAEF,eAAe,GAAG,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const gpt = {
|
|
4
|
+
extension: {
|
|
5
|
+
/**
|
|
6
|
+
* Send a proactive request to MagicGPT extension
|
|
7
|
+
* @param source String to identify the source of the request
|
|
8
|
+
* @param data ProactiveRequestData to send to the GPT
|
|
9
|
+
*/
|
|
10
|
+
proactiveRequest: (source, data) => {
|
|
11
|
+
window.postMessage(JSON.stringify({
|
|
12
|
+
action: 'proactive.request',
|
|
13
|
+
data: btoa(JSON.stringify({
|
|
14
|
+
source,
|
|
15
|
+
data: {
|
|
16
|
+
request_id: data.request_id,
|
|
17
|
+
assistant_id: data.assistant_id,
|
|
18
|
+
client_id: data.client_id,
|
|
19
|
+
client_phone_number: data.client_phone_number
|
|
20
|
+
}
|
|
21
|
+
}))
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.default = gpt;
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/gpt/index.ts"],"names":[],"mappings":";;AAOA,MAAM,GAAG,GAAG;IACR,SAAS,EAAE;QACP;;;;WAIG;QACH,gBAAgB,EAAE,CAAC,MAAc,EAAE,IAA0B,EAAE,EAAE;YAC7D,MAAM,CAAC,WAAW,CACd,IAAI,CAAC,SAAS,CAAC;gBACX,MAAM,EAAE,mBAAmB;gBAC3B,IAAI,EAAE,IAAI,CACN,IAAI,CAAC,SAAS,CAAC;oBACX,MAAM;oBACN,IAAI,EAAE;wBACF,UAAU,EAAE,IAAI,CAAC,UAAU;wBAC3B,YAAY,EAAE,IAAI,CAAC,YAAY;wBAC/B,SAAS,EAAE,IAAI,CAAC,SAAS;wBACzB,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;qBAChD;iBACJ,CAAC,CACL;aACJ,CAAC,CACL,CAAC;QACN,CAAC;KACJ;CACJ,CAAC;AAEF,kBAAe,GAAG,CAAC"}
|
package/dist/main/index.d.ts
CHANGED
package/dist/main/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC"}
|
package/dist/main/index.js
CHANGED
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./stamp"), exports);
|
|
18
|
+
__exportStar(require("./gpt"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
package/dist/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,wCAAsB"}
|
|
@@ -1,10 +1,23 @@
|
|
|
1
|
+
type context = {
|
|
2
|
+
id: string;
|
|
3
|
+
idx: string;
|
|
4
|
+
step: number;
|
|
5
|
+
now: number;
|
|
6
|
+
end: () => void;
|
|
7
|
+
};
|
|
1
8
|
/**
|
|
2
9
|
* The idea is that you can create a stamp with an id, and then use that id to mark different steps in your code.
|
|
3
10
|
* `createStamp` should be called at the beginning of the execution context and then createStamp
|
|
4
11
|
* @param id String to identify the stamp
|
|
5
12
|
* @returns
|
|
6
13
|
*/
|
|
7
|
-
export declare const createStamp: (id?: string) =>
|
|
8
|
-
|
|
9
|
-
|
|
14
|
+
export declare const createStamp: (id?: string) => {
|
|
15
|
+
stamp: (name: string) => context;
|
|
16
|
+
end: () => context;
|
|
17
|
+
};
|
|
18
|
+
export declare function stamp(this: context, name: string): context;
|
|
19
|
+
export declare namespace stamp {
|
|
20
|
+
var end: (this: context) => context;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
10
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stamp/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stamp/index.ts"],"names":[],"mappings":"AAGA,KAAK,OAAO,GAAG;IACX,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW;;;CAiBvB,CAAC;AAEF,wBAAgB,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAahD;yBAbe,KAAK"}
|
package/dist/main/stamp/index.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// Copy/pasta from https://github.com/pluslabs/magic-professional/blob/main/packages/stamp/index.ts
|
|
3
|
+
// since yarn cant do subdirectories from a monorepo
|
|
2
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const context = {
|
|
5
|
-
id: '',
|
|
6
|
-
idx: '',
|
|
7
|
-
step: 0,
|
|
8
|
-
now: 0
|
|
9
|
-
};
|
|
5
|
+
exports.stamp = exports.createStamp = void 0;
|
|
10
6
|
/**
|
|
11
7
|
* The idea is that you can create a stamp with an id, and then use that id to mark different steps in your code.
|
|
12
8
|
* `createStamp` should be called at the beginning of the execution context and then createStamp
|
|
@@ -14,28 +10,38 @@ const context = {
|
|
|
14
10
|
* @returns
|
|
15
11
|
*/
|
|
16
12
|
const createStamp = (id = '') => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
const ctx = {
|
|
14
|
+
id,
|
|
15
|
+
idx: (Date.now() * Math.random() * 1e6).toString(36),
|
|
16
|
+
now: Date.now(),
|
|
17
|
+
step: Date.now(),
|
|
18
|
+
end: () => { }
|
|
19
|
+
};
|
|
20
|
+
// Bind the end function to the context
|
|
21
|
+
// so we can curry it
|
|
22
|
+
ctx.end = end.bind(ctx);
|
|
23
|
+
return {
|
|
24
|
+
stamp: stamp.bind(ctx),
|
|
25
|
+
end: end.bind(ctx)
|
|
26
|
+
};
|
|
24
27
|
};
|
|
25
28
|
exports.createStamp = createStamp;
|
|
26
29
|
function stamp(name) {
|
|
27
|
-
if (!
|
|
28
|
-
return;
|
|
30
|
+
if (!this.id) {
|
|
31
|
+
return this;
|
|
29
32
|
}
|
|
30
|
-
const diff = Date.now() -
|
|
31
|
-
|
|
32
|
-
console.log(`[STAMP][${
|
|
33
|
+
const diff = Date.now() - this.step;
|
|
34
|
+
this.step = Date.now();
|
|
35
|
+
console.log(`[STAMP][${this.idx}][${this.id}] ${name} took ${diff}ms, total: ${Date.now() - this.now}ms`);
|
|
36
|
+
return this;
|
|
33
37
|
}
|
|
34
38
|
exports.stamp = stamp;
|
|
39
|
+
stamp.end = end;
|
|
35
40
|
function end() {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
this.id = '';
|
|
42
|
+
this.now = 0;
|
|
43
|
+
this.step = 0;
|
|
44
|
+
const ctx = this;
|
|
45
|
+
return ctx;
|
|
39
46
|
}
|
|
40
|
-
exports.end = end;
|
|
41
47
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stamp/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stamp/index.ts"],"names":[],"mappings":";AAAA,mGAAmG;AACnG,oDAAoD;;;AAUpD;;;;;GAKG;AACI,MAAM,WAAW,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE;IACnC,MAAM,GAAG,GAAG;QACR,EAAE;QACF,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpD,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE;QACf,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;QAChB,GAAG,EAAE,GAAG,EAAE,GAAE,CAAC;KACL,CAAC;IAEb,uCAAuC;IACvC,qBAAqB;IACrB,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAExB,OAAO;QACH,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;QACtB,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;KACrB,CAAC;AACN,CAAC,CAAC;AAjBW,QAAA,WAAW,eAiBtB;AAEF,SAAgB,KAAK,CAAgB,IAAY;IAC7C,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE;QACV,OAAO,IAAI,CAAC;KACf;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC;IACpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAEvB,OAAO,CAAC,GAAG,CACP,WAAW,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC,EAAE,KAAK,IAAI,SAAS,IAAI,cAAc,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAC/F,CAAC;IAEF,OAAO,IAAI,CAAC;AAChB,CAAC;AAbD,sBAaC;AAED,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC;AAEhB,SAAS,GAAG;IACR,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACb,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;IACb,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;IAEd,MAAM,GAAG,GAAG,IAAe,CAAC;IAE5B,OAAO,GAAG,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type ProactiveRequestData = {
|
|
2
|
+
request_id: string;
|
|
3
|
+
assistant_id: string;
|
|
4
|
+
client_id: string;
|
|
5
|
+
client_phone_number: string;
|
|
6
|
+
};
|
|
7
|
+
declare const gpt: {
|
|
8
|
+
extension: {
|
|
9
|
+
/**
|
|
10
|
+
* Send a proactive request to MagicGPT extension
|
|
11
|
+
* @param source String to identify the source of the request
|
|
12
|
+
* @param data ProactiveRequestData to send to the GPT
|
|
13
|
+
*/
|
|
14
|
+
proactiveRequest: (source: string, data: ProactiveRequestData) => void;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export default gpt;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/gpt/index.ts"],"names":[],"mappings":"AAAA,KAAK,oBAAoB,GAAG;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF,QAAA,MAAM,GAAG;;QAED;;;;WAIG;mCACwB,MAAM,QAAQ,oBAAoB;;CAmBpE,CAAC;AAEF,eAAe,GAAG,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const gpt = {
|
|
2
|
+
extension: {
|
|
3
|
+
/**
|
|
4
|
+
* Send a proactive request to MagicGPT extension
|
|
5
|
+
* @param source String to identify the source of the request
|
|
6
|
+
* @param data ProactiveRequestData to send to the GPT
|
|
7
|
+
*/
|
|
8
|
+
proactiveRequest: (source, data) => {
|
|
9
|
+
window.postMessage(JSON.stringify({
|
|
10
|
+
action: 'proactive.request',
|
|
11
|
+
data: btoa(JSON.stringify({
|
|
12
|
+
source,
|
|
13
|
+
data: {
|
|
14
|
+
request_id: data.request_id,
|
|
15
|
+
assistant_id: data.assistant_id,
|
|
16
|
+
client_id: data.client_id,
|
|
17
|
+
client_phone_number: data.client_phone_number
|
|
18
|
+
}
|
|
19
|
+
}))
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export default gpt;
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/gpt/index.ts"],"names":[],"mappings":"AAOA,MAAM,GAAG,GAAG;IACR,SAAS,EAAE;QACP;;;;WAIG;QACH,gBAAgB,EAAE,CAAC,MAAc,EAAE,IAA0B,EAAE,EAAE;YAC7D,MAAM,CAAC,WAAW,CACd,IAAI,CAAC,SAAS,CAAC;gBACX,MAAM,EAAE,mBAAmB;gBAC3B,IAAI,EAAE,IAAI,CACN,IAAI,CAAC,SAAS,CAAC;oBACX,MAAM;oBACN,IAAI,EAAE;wBACF,UAAU,EAAE,IAAI,CAAC,UAAU;wBAC3B,YAAY,EAAE,IAAI,CAAC,YAAY;wBAC/B,SAAS,EAAE,IAAI,CAAC,SAAS;wBACzB,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;qBAChD;iBACJ,CAAC,CACL;aACJ,CAAC,CACL,CAAC;QACN,CAAC;KACJ;CACJ,CAAC;AAEF,eAAe,GAAG,CAAC"}
|
package/dist/module/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC"}
|
package/dist/module/index.js
CHANGED
package/dist/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC"}
|
|
@@ -1,10 +1,23 @@
|
|
|
1
|
+
type context = {
|
|
2
|
+
id: string;
|
|
3
|
+
idx: string;
|
|
4
|
+
step: number;
|
|
5
|
+
now: number;
|
|
6
|
+
end: () => void;
|
|
7
|
+
};
|
|
1
8
|
/**
|
|
2
9
|
* The idea is that you can create a stamp with an id, and then use that id to mark different steps in your code.
|
|
3
10
|
* `createStamp` should be called at the beginning of the execution context and then createStamp
|
|
4
11
|
* @param id String to identify the stamp
|
|
5
12
|
* @returns
|
|
6
13
|
*/
|
|
7
|
-
export declare const createStamp: (id?: string) =>
|
|
8
|
-
|
|
9
|
-
|
|
14
|
+
export declare const createStamp: (id?: string) => {
|
|
15
|
+
stamp: (name: string) => context;
|
|
16
|
+
end: () => context;
|
|
17
|
+
};
|
|
18
|
+
export declare function stamp(this: context, name: string): context;
|
|
19
|
+
export declare namespace stamp {
|
|
20
|
+
var end: (this: context) => context;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
10
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stamp/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stamp/index.ts"],"names":[],"mappings":"AAGA,KAAK,OAAO,GAAG;IACX,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW;;;CAiBvB,CAAC;AAEF,wBAAgB,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAahD;yBAbe,KAAK"}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
idx: '',
|
|
4
|
-
step: 0,
|
|
5
|
-
now: 0
|
|
6
|
-
};
|
|
1
|
+
// Copy/pasta from https://github.com/pluslabs/magic-professional/blob/main/packages/stamp/index.ts
|
|
2
|
+
// since yarn cant do subdirectories from a monorepo
|
|
7
3
|
/**
|
|
8
4
|
* The idea is that you can create a stamp with an id, and then use that id to mark different steps in your code.
|
|
9
5
|
* `createStamp` should be called at the beginning of the execution context and then createStamp
|
|
@@ -11,25 +7,36 @@ const context = {
|
|
|
11
7
|
* @returns
|
|
12
8
|
*/
|
|
13
9
|
export const createStamp = (id = '') => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
const ctx = {
|
|
11
|
+
id,
|
|
12
|
+
idx: (Date.now() * Math.random() * 1e6).toString(36),
|
|
13
|
+
now: Date.now(),
|
|
14
|
+
step: Date.now(),
|
|
15
|
+
end: () => { }
|
|
16
|
+
};
|
|
17
|
+
// Bind the end function to the context
|
|
18
|
+
// so we can curry it
|
|
19
|
+
ctx.end = end.bind(ctx);
|
|
20
|
+
return {
|
|
21
|
+
stamp: stamp.bind(ctx),
|
|
22
|
+
end: end.bind(ctx)
|
|
23
|
+
};
|
|
21
24
|
};
|
|
22
25
|
export function stamp(name) {
|
|
23
|
-
if (!
|
|
24
|
-
return;
|
|
26
|
+
if (!this.id) {
|
|
27
|
+
return this;
|
|
25
28
|
}
|
|
26
|
-
const diff = Date.now() -
|
|
27
|
-
|
|
28
|
-
console.log(`[STAMP][${
|
|
29
|
+
const diff = Date.now() - this.step;
|
|
30
|
+
this.step = Date.now();
|
|
31
|
+
console.log(`[STAMP][${this.idx}][${this.id}] ${name} took ${diff}ms, total: ${Date.now() - this.now}ms`);
|
|
32
|
+
return this;
|
|
29
33
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
stamp.end = end;
|
|
35
|
+
function end() {
|
|
36
|
+
this.id = '';
|
|
37
|
+
this.now = 0;
|
|
38
|
+
this.step = 0;
|
|
39
|
+
const ctx = this;
|
|
40
|
+
return ctx;
|
|
34
41
|
}
|
|
35
42
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stamp/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stamp/index.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,oDAAoD;AAUpD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE;IACnC,MAAM,GAAG,GAAG;QACR,EAAE;QACF,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpD,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE;QACf,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;QAChB,GAAG,EAAE,GAAG,EAAE,GAAE,CAAC;KACL,CAAC;IAEb,uCAAuC;IACvC,qBAAqB;IACrB,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAExB,OAAO;QACH,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;QACtB,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;KACrB,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,UAAU,KAAK,CAAgB,IAAY;IAC7C,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE;QACV,OAAO,IAAI,CAAC;KACf;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC;IACpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAEvB,OAAO,CAAC,GAAG,CACP,WAAW,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC,EAAE,KAAK,IAAI,SAAS,IAAI,cAAc,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAC/F,CAAC;IAEF,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC;AAEhB,SAAS,GAAG;IACR,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACb,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;IACb,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;IAEd,MAAM,GAAG,GAAG,IAAe,CAAC;IAE5B,OAAO,GAAG,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
package/src/gpt/index.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
type ProactiveRequestData = {
|
|
2
|
+
request_id: string;
|
|
3
|
+
assistant_id: string;
|
|
4
|
+
client_id: string;
|
|
5
|
+
client_phone_number: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const gpt = {
|
|
9
|
+
extension: {
|
|
10
|
+
/**
|
|
11
|
+
* Send a proactive request to MagicGPT extension
|
|
12
|
+
* @param source String to identify the source of the request
|
|
13
|
+
* @param data ProactiveRequestData to send to the GPT
|
|
14
|
+
*/
|
|
15
|
+
proactiveRequest: (source: string, data: ProactiveRequestData) => {
|
|
16
|
+
window.postMessage(
|
|
17
|
+
JSON.stringify({
|
|
18
|
+
action: 'proactive.request',
|
|
19
|
+
data: btoa(
|
|
20
|
+
JSON.stringify({
|
|
21
|
+
source,
|
|
22
|
+
data: {
|
|
23
|
+
request_id: data.request_id,
|
|
24
|
+
assistant_id: data.assistant_id,
|
|
25
|
+
client_id: data.client_id,
|
|
26
|
+
client_phone_number: data.client_phone_number
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
)
|
|
30
|
+
})
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default gpt;
|
package/src/index.ts
CHANGED
package/src/stamp/index.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
// Copy/pasta from https://github.com/pluslabs/magic-professional/blob/main/packages/stamp/index.ts
|
|
2
|
+
// since yarn cant do subdirectories from a monorepo
|
|
3
|
+
|
|
4
|
+
type context = {
|
|
2
5
|
id: string;
|
|
3
6
|
idx: string;
|
|
4
7
|
step: number;
|
|
5
8
|
now: number;
|
|
6
|
-
|
|
7
|
-
id: '',
|
|
8
|
-
idx: '',
|
|
9
|
-
step: 0,
|
|
10
|
-
now: 0
|
|
9
|
+
end: () => void;
|
|
11
10
|
};
|
|
12
11
|
|
|
13
12
|
/**
|
|
@@ -17,33 +16,47 @@ const context: {
|
|
|
17
16
|
* @returns
|
|
18
17
|
*/
|
|
19
18
|
export const createStamp = (id = '') => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
const ctx = {
|
|
20
|
+
id,
|
|
21
|
+
idx: (Date.now() * Math.random() * 1e6).toString(36),
|
|
22
|
+
now: Date.now(),
|
|
23
|
+
step: Date.now(),
|
|
24
|
+
end: () => {}
|
|
25
|
+
} as context;
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
// Bind the end function to the context
|
|
28
|
+
// so we can curry it
|
|
29
|
+
ctx.end = end.bind(ctx);
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
stamp: stamp.bind(ctx),
|
|
33
|
+
end: end.bind(ctx)
|
|
34
|
+
};
|
|
28
35
|
};
|
|
29
36
|
|
|
30
|
-
export function stamp(name: string) {
|
|
31
|
-
if (!
|
|
32
|
-
return;
|
|
37
|
+
export function stamp(this: context, name: string) {
|
|
38
|
+
if (!this.id) {
|
|
39
|
+
return this;
|
|
33
40
|
}
|
|
34
41
|
|
|
35
|
-
const diff = Date.now() -
|
|
36
|
-
|
|
42
|
+
const diff = Date.now() - this.step;
|
|
43
|
+
this.step = Date.now();
|
|
37
44
|
|
|
38
45
|
console.log(
|
|
39
|
-
`[STAMP][${
|
|
40
|
-
Date.now() - context.now
|
|
41
|
-
}ms`
|
|
46
|
+
`[STAMP][${this.idx}][${this.id}] ${name} took ${diff}ms, total: ${Date.now() - this.now}ms`
|
|
42
47
|
);
|
|
48
|
+
|
|
49
|
+
return this;
|
|
43
50
|
}
|
|
44
51
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
stamp.end = end;
|
|
53
|
+
|
|
54
|
+
function end(this: context) {
|
|
55
|
+
this.id = '';
|
|
56
|
+
this.now = 0;
|
|
57
|
+
this.step = 0;
|
|
58
|
+
|
|
59
|
+
const ctx = this as context;
|
|
60
|
+
|
|
61
|
+
return ctx;
|
|
49
62
|
}
|