@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.
@@ -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"}
@@ -1,2 +1,3 @@
1
1
  export * from './stamp';
2
+ export * from './gpt';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -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
@@ -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) => typeof stamp;
8
- export declare function stamp(name: string): void;
9
- export declare function end(): void;
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":"AAYA;;;;;GAKG;AACH,eAAO,MAAM,WAAW,+BASvB,CAAC;AAEF,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,QAajC;AAED,wBAAgB,GAAG,SAIlB"}
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,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.end = exports.stamp = exports.createStamp = void 0;
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
- if (!context.id) {
18
- context.id = id;
19
- context.idx = (Date.now() * Math.random() * 1e6).toString(36);
20
- context.now = Date.now();
21
- context.step = Date.now();
22
- }
23
- return stamp;
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 (!context.id) {
28
- return;
30
+ if (!this.id) {
31
+ return this;
29
32
  }
30
- const diff = Date.now() - context.step;
31
- context.step = Date.now();
32
- console.log(`[STAMP][${context.idx}][${context.id}] ${name} took ${diff}ms, total: ${Date.now() - context.now}ms`);
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
- context.id = '';
37
- context.now = 0;
38
- context.step = 0;
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":";;;AAAA,MAAM,OAAO,GAKT;IACA,EAAE,EAAE,EAAE;IACN,GAAG,EAAE,EAAE;IACP,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;CACT,CAAC;AAEF;;;;;GAKG;AACI,MAAM,WAAW,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE;IACnC,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE;QACb,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC9D,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACzB,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;KAC7B;IAED,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AATW,QAAA,WAAW,eAStB;AAEF,SAAgB,KAAK,CAAC,IAAY;IAC9B,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE;QACb,OAAO;KACV;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IACvC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE1B,OAAO,CAAC,GAAG,CACP,WAAW,OAAO,CAAC,GAAG,KAAK,OAAO,CAAC,EAAE,KAAK,IAAI,SAAS,IAAI,cACvD,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,GACzB,IAAI,CACP,CAAC;AACN,CAAC;AAbD,sBAaC;AAED,SAAgB,GAAG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AI,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"}
@@ -1,2 +1,3 @@
1
1
  export * from './stamp';
2
+ export * from './gpt';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -1,2 +1,3 @@
1
1
  export * from './stamp';
2
+ export * from './gpt';
2
3
  //# sourceMappingURL=index.js.map
@@ -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) => typeof stamp;
8
- export declare function stamp(name: string): void;
9
- export declare function end(): void;
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":"AAYA;;;;;GAKG;AACH,eAAO,MAAM,WAAW,+BASvB,CAAC;AAEF,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,QAajC;AAED,wBAAgB,GAAG,SAIlB"}
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
- const context = {
2
- id: '',
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
- if (!context.id) {
15
- context.id = id;
16
- context.idx = (Date.now() * Math.random() * 1e6).toString(36);
17
- context.now = Date.now();
18
- context.step = Date.now();
19
- }
20
- return stamp;
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 (!context.id) {
24
- return;
26
+ if (!this.id) {
27
+ return this;
25
28
  }
26
- const diff = Date.now() - context.step;
27
- context.step = Date.now();
28
- console.log(`[STAMP][${context.idx}][${context.id}] ${name} took ${diff}ms, total: ${Date.now() - context.now}ms`);
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
- export function end() {
31
- context.id = '';
32
- context.now = 0;
33
- context.step = 0;
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,MAAM,OAAO,GAKT;IACA,EAAE,EAAE,EAAE;IACN,GAAG,EAAE,EAAE;IACP,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;CACT,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE;IACnC,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE;QACb,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC9D,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACzB,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;KAC7B;IAED,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,UAAU,KAAK,CAAC,IAAY;IAC9B,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE;QACb,OAAO;KACV;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IACvC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE1B,OAAO,CAAC,GAAG,CACP,WAAW,OAAO,CAAC,GAAG,KAAK,OAAO,CAAC,EAAE,KAAK,IAAI,SAAS,IAAI,cACvD,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,GACzB,IAAI,CACP,CAAC;AACN,CAAC;AAED,MAAM,UAAU,GAAG;IACf,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IACh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AI,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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluslabs/utils",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "A set of utilities used across projects",
5
5
  "keywords": [
6
6
  "javascript",
@@ -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
@@ -1 +1,2 @@
1
1
  export * from './stamp';
2
+ export * from './gpt';
@@ -1,13 +1,12 @@
1
- const context: {
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
- if (!context.id) {
21
- context.id = id;
22
- context.idx = (Date.now() * Math.random() * 1e6).toString(36);
23
- context.now = Date.now();
24
- context.step = Date.now();
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
- return stamp;
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 (!context.id) {
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() - context.step;
36
- context.step = Date.now();
42
+ const diff = Date.now() - this.step;
43
+ this.step = Date.now();
37
44
 
38
45
  console.log(
39
- `[STAMP][${context.idx}][${context.id}] ${name} took ${diff}ms, total: ${
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
- export function end() {
46
- context.id = '';
47
- context.now = 0;
48
- context.step = 0;
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
  }