@epam/statgpt-shared-toolkit 0.3.0-rc.1 → 0.3.0-rc.10
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/index.js +1 -1
- package/index.mjs +90 -61
- package/package.json +3 -2
- package/utils/conversation-attachments.d.ts +3 -0
- package/utils/conversation-name.d.ts +1 -0
- package/utils/conversation-url.d.ts +3 -0
- package/utils/index.d.ts +1 -0
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("date-fns"),_={CHAT:"/api/chat"},R="CUSTOM_PERIOD",l={decimal:"0.0",decimalSymbol:",",digitGroupingSymbol:" "},g="application/json",N="Content-Type",a="Api-Key",T="X-CONVERSATION-ID",u="Ocp-Apim-Subscription-Key",h={BAD_REQUEST:400,UNAUTHORIZED:401,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_ALLOWED:405,CONFLICT:409,TOO_MANY_REQUESTS:429,INTERNAL_SERVER_ERROR:500,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504},f="onboarding",S="share";class v extends Error{constructor(e){super(e.message),this.isHttpError=!0,this.name="HttpError",this.code=e.code,this.status=e.status,this.details=e.details,this.displayMessage=e.displayMessage}}function y(t){return typeof t=="object"&&t!==null&&t.isHttpError===!0&&typeof t.status=="number"&&typeof t.message=="string"&&(t.code===void 0||typeof t.code=="string")}var p=(t=>(t.MONTH="month",t.DAY="day",t))(p||{}),A=(t=>(t.UK="uk",t.EN="en",t))(A||{}),O=(t=>(t.IN="in",t.BETWEEN="between",t))(O||{});function D(t,e){const n=t.split("/")[0],r=e.split("/").pop();return`${n}/${r}`}const b=t=>t.messages.flatMap(e=>{const n=e.custom_content?.attachments??[],r=e.custom_content?.stages?.flatMap(({attachments:s})=>s??[])??[];return[...n,...r]}),C=t=>b(t),P=t=>[...new Set(C(t).map(e=>e.url).filter(e=>!!e))],m=t=>t?.split(/-\d+$/)[0]??"",U=t=>t?.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"").replace(/-/g," ")||"";function H(t,e){return`${t?.[0]}/${e}/${t?.[1]}`}const M=(t,e)=>(Math.round(t*10**e)/10**e).toString(),B=(t,e)=>{const n=e?.decimal||l.decimal,r=e?.decimalSymbol||l.decimalSymbol,s=e?.digitGroupingSymbol??l.digitGroupingSymbol,o=Number(t);if(o==null||Number.isNaN(o)||t===null||t==="")return"";const i=n.replace("0.",""),E=`${n==="0"?Math.trunc(o):M(o,i.length)} `.split(".");return E[0]=E[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g,`$1${s}`),`${E.join(r)}`},F=t=>{if(!t.includes("T")){for(const n of L){const r=c.parse(t,n,new Date);if(c.isValid(r))return r}return null}const e=c.parseISO(t);return c.isValid(e)?e:null},L=["yyyy-MM-dd","MM-dd-yyyy"],x=(t,e,n)=>{const r={[N]:e?.contentType||g};return e?.jwt?r.Authorization=`Bearer ${e.jwt}`:t&&(r[a]=t),e?.chatReference&&(r[T]=e.chatReference),{...r,...n}},$=t=>{const e={...t};return e[a]&&(e[a]=e[a].substring(0,8)+"...[REDACTED]"),e.Authorization&&(e.Authorization="Bearer [REDACTED]"),e[u]&&(e[u]=e[u].substring(0,8)+"...[REDACTED]"),e},w=t=>({"Content-Type":`multipart/form-data; boundary=${t}`}),G=t=>t?.toLowerCase()==="true",V=async(t,e,n)=>await fetch(t,{method:n.method||"GET",headers:e,body:n.body?JSON.stringify(n.body):void 0}),Y=(t,e)=>t?.split("/")?.filter(n=>n!==e)?.join("/"),j=t=>t.replace(/^conversations\//,""),z=t=>t.split("/").slice(0,-1).join("/"),K=t=>m(decodeURIComponent(t.split("/").at(-1)??"")),W=t=>t.map(e=>({...e,name:m(e.name)})),k=new Set([")","]","}",">",",",".","!","?",":",";"]);function I(t){let e=t.length;for(;e>0&&k.has(t[e-1]);)e--;return e===t.length?{cleanUrl:t,trailing:""}:{cleanUrl:t.slice(0,e),trailing:t.slice(e)}}function X(t){if(!t)return[{type:"text",value:""}];const e=[];let n=0;for(const r of t.matchAll(/\bhttps?:\/\/[^\s<>"']+/gi)){const s=r[0],o=r.index??0;o>n&&e.push({type:"text",value:t.slice(n,o)});const{cleanUrl:i,trailing:d}=I(s);i?e.push({type:"link",value:i}):e.push({type:"text",value:s}),d&&e.push({type:"text",value:d}),n=o+s.length}return n<t.length&&e.push({type:"text",value:t.slice(n)}),e.length?e:[{type:"text",value:t}]}exports.API_KEY_HEADER=a;exports.API_ROUTES=_;exports.APPLICATION_JSON=g;exports.CONTENT_TYPE_HEADER=N;exports.CUSTOM_PERIOD=R;exports.CalendarResolution=p;exports.HTTP_ERROR_CODES=h;exports.HttpError=v;exports.Locale=A;exports.OCP_APIM_SUBSCRIPTION_KEY_HEADER=u;exports.ONBOARDING_MODEL_POSTFIX=f;exports.QueryFilterType=O;exports.SHARE_CONVERSATION_ROUTE=S;exports.X_CONVERSATION_ID_HEADER=T;exports.cleanConversationNames=W;exports.defaultFormatNumbers=l;exports.deleteConversationNamePostfix=m;exports.formatNumberBySign=B;exports.getClearedConversationName=U;exports.getConversationAttachmentUrls=P;exports.getConversationAttachments=C;exports.getConversationFolderIdFromConversationId=z;exports.getConversationId=H;exports.getConversationIdFromResourceUrl=j;exports.getConversationNameFromConversationId=K;exports.getConversationNavPath=D;exports.getConversationUrlWithoutLocale=Y;exports.getHeaders=x;exports.getMultipartHeaders=w;exports.getTimePeriod=F;exports.isHttpError=y;exports.linkifyText=X;exports.parseBoolean=G;exports.sanitizeHeaders=$;exports.sendRequest=V;exports.splitTrailingPunctuation=I;
|
package/index.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { parse as p, isValid as m, parseISO as g } from "date-fns";
|
|
2
|
+
const b = {
|
|
2
3
|
CHAT: "/api/chat"
|
|
3
|
-
},
|
|
4
|
+
}, v = "CUSTOM_PERIOD", u = {
|
|
4
5
|
decimal: "0.0",
|
|
5
6
|
decimalSymbol: ",",
|
|
6
7
|
digitGroupingSymbol: " "
|
|
7
|
-
},
|
|
8
|
+
}, A = "application/json", N = "Content-Type", i = "Api-Key", T = "X-CONVERSATION-ID", d = "Ocp-Apim-Subscription-Key", U = {
|
|
8
9
|
BAD_REQUEST: 400,
|
|
9
10
|
UNAUTHORIZED: 401,
|
|
10
11
|
FORBIDDEN: 403,
|
|
@@ -16,51 +17,73 @@ const f = {
|
|
|
16
17
|
BAD_GATEWAY: 502,
|
|
17
18
|
SERVICE_UNAVAILABLE: 503,
|
|
18
19
|
GATEWAY_TIMEOUT: 504
|
|
19
|
-
},
|
|
20
|
-
class
|
|
20
|
+
}, M = "onboarding", H = "share";
|
|
21
|
+
class P extends Error {
|
|
21
22
|
constructor(e) {
|
|
22
23
|
super(e.message), this.isHttpError = !0, this.name = "HttpError", this.code = e.code, this.status = e.status, this.details = e.details, this.displayMessage = e.displayMessage;
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
function
|
|
26
|
+
function x(t) {
|
|
26
27
|
return typeof t == "object" && t !== null && t.isHttpError === !0 && typeof t.status == "number" && typeof t.message == "string" && (t.code === void 0 || typeof t.code == "string");
|
|
27
28
|
}
|
|
28
|
-
var
|
|
29
|
-
function
|
|
29
|
+
var h = /* @__PURE__ */ ((t) => (t.MONTH = "month", t.DAY = "day", t))(h || {}), f = /* @__PURE__ */ ((t) => (t.UK = "uk", t.EN = "en", t))(f || {}), O = /* @__PURE__ */ ((t) => (t.IN = "in", t.BETWEEN = "between", t))(O || {});
|
|
30
|
+
function B(t, e) {
|
|
30
31
|
const n = t.split("/")[0], r = e.split("/").pop();
|
|
31
32
|
return `${n}/${r}`;
|
|
32
33
|
}
|
|
33
|
-
const
|
|
34
|
-
|
|
34
|
+
const I = (t) => t.messages.flatMap((e) => {
|
|
35
|
+
const n = e.custom_content?.attachments ?? [], r = e.custom_content?.stages?.flatMap(
|
|
36
|
+
({ attachments: s }) => s ?? []
|
|
37
|
+
) ?? [];
|
|
38
|
+
return [...n, ...r];
|
|
39
|
+
}), R = (t) => I(t), $ = (t) => [
|
|
40
|
+
...new Set(
|
|
41
|
+
R(t).map((e) => e.url).filter((e) => !!e)
|
|
42
|
+
)
|
|
43
|
+
], E = (t) => t?.split(/-\d+$/)[0] ?? "", L = (t) => t?.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "-").replace(/^-+|-+$/g, "").replace(/-/g, " ") || "";
|
|
44
|
+
function w(t, e) {
|
|
35
45
|
return `${t?.[0]}/${e}/${t?.[1]}`;
|
|
36
46
|
}
|
|
37
|
-
const
|
|
38
|
-
const n = e?.decimal || u.decimal, r = e?.decimalSymbol || u.decimalSymbol,
|
|
39
|
-
if (
|
|
47
|
+
const y = (t, e) => (Math.round(t * 10 ** e) / 10 ** e).toString(), F = (t, e) => {
|
|
48
|
+
const n = e?.decimal || u.decimal, r = e?.decimalSymbol || u.decimalSymbol, s = e?.digitGroupingSymbol ?? u.digitGroupingSymbol, o = Number(t);
|
|
49
|
+
if (o == null || Number.isNaN(o) || t === null || t === "")
|
|
40
50
|
return "";
|
|
41
|
-
const
|
|
51
|
+
const a = n.replace("0.", ""), l = `${n === "0" ? Math.trunc(o) : y(o, a.length)} `.split(".");
|
|
42
52
|
return l[0] = l[0].replace(
|
|
43
53
|
/(\d)(?=(\d\d\d)+(?!\d))/g,
|
|
44
|
-
`$1${
|
|
54
|
+
`$1${s}`
|
|
45
55
|
), `${l.join(r)}`;
|
|
46
|
-
},
|
|
56
|
+
}, G = (t) => {
|
|
57
|
+
if (!t.includes("T")) {
|
|
58
|
+
for (const n of C) {
|
|
59
|
+
const r = p(t, n, /* @__PURE__ */ new Date());
|
|
60
|
+
if (m(r))
|
|
61
|
+
return r;
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const e = g(t);
|
|
66
|
+
return m(e) ? e : null;
|
|
67
|
+
}, C = ["yyyy-MM-dd", "MM-dd-yyyy"], j = (t, e, n) => {
|
|
47
68
|
const r = {
|
|
48
|
-
[
|
|
69
|
+
[N]: e?.contentType || A
|
|
49
70
|
};
|
|
50
|
-
return e?.jwt ? r.Authorization = `Bearer ${e.jwt}` : t && (r[
|
|
51
|
-
},
|
|
71
|
+
return e?.jwt ? r.Authorization = `Bearer ${e.jwt}` : t && (r[i] = t), e?.chatReference && (r[T] = e.chatReference), { ...r, ...n };
|
|
72
|
+
}, V = (t) => {
|
|
52
73
|
const e = { ...t };
|
|
53
|
-
return e[
|
|
54
|
-
},
|
|
74
|
+
return e[i] && (e[i] = e[i].substring(0, 8) + "...[REDACTED]"), e.Authorization && (e.Authorization = "Bearer [REDACTED]"), e[d] && (e[d] = e[d].substring(0, 8) + "...[REDACTED]"), e;
|
|
75
|
+
}, Y = (t) => ({
|
|
55
76
|
"Content-Type": `multipart/form-data; boundary=${t}`
|
|
56
|
-
}),
|
|
77
|
+
}), z = (t) => t?.toLowerCase() === "true", W = async (t, e, n) => await fetch(t, {
|
|
57
78
|
method: n.method || "GET",
|
|
58
79
|
headers: e,
|
|
59
80
|
body: n.body ? JSON.stringify(n.body) : void 0
|
|
60
|
-
}),
|
|
81
|
+
}), k = (t, e) => t?.split("/")?.filter((n) => n !== e)?.join("/"), K = (t) => t.replace(/^conversations\//, ""), X = (t) => t.split("/").slice(0, -1).join("/"), J = (t) => E(
|
|
82
|
+
decodeURIComponent(t.split("/").at(-1) ?? "")
|
|
83
|
+
), q = (t) => t.map((e) => ({
|
|
61
84
|
...e,
|
|
62
|
-
name: e.name
|
|
63
|
-
})),
|
|
85
|
+
name: E(e.name)
|
|
86
|
+
})), _ = /* @__PURE__ */ new Set([
|
|
64
87
|
")",
|
|
65
88
|
"]",
|
|
66
89
|
"}",
|
|
@@ -72,56 +95,62 @@ const A = (t, e) => (Math.round(t * 10 ** e) / 10 ** e).toString(), v = (t, e) =
|
|
|
72
95
|
":",
|
|
73
96
|
";"
|
|
74
97
|
]);
|
|
75
|
-
function
|
|
98
|
+
function S(t) {
|
|
76
99
|
let e = t.length;
|
|
77
|
-
for (; e > 0 &&
|
|
100
|
+
for (; e > 0 && _.has(t[e - 1]); )
|
|
78
101
|
e--;
|
|
79
102
|
return e === t.length ? { cleanUrl: t, trailing: "" } : {
|
|
80
103
|
cleanUrl: t.slice(0, e),
|
|
81
104
|
trailing: t.slice(e)
|
|
82
105
|
};
|
|
83
106
|
}
|
|
84
|
-
function
|
|
107
|
+
function Q(t) {
|
|
85
108
|
if (!t) return [{ type: "text", value: "" }];
|
|
86
109
|
const e = [];
|
|
87
110
|
let n = 0;
|
|
88
111
|
for (const r of t.matchAll(/\bhttps?:\/\/[^\s<>"']+/gi)) {
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
const { cleanUrl:
|
|
92
|
-
|
|
112
|
+
const s = r[0], o = r.index ?? 0;
|
|
113
|
+
o > n && e.push({ type: "text", value: t.slice(n, o) });
|
|
114
|
+
const { cleanUrl: a, trailing: c } = S(s);
|
|
115
|
+
a ? e.push({ type: "link", value: a }) : e.push({ type: "text", value: s }), c && e.push({ type: "text", value: c }), n = o + s.length;
|
|
93
116
|
}
|
|
94
117
|
return n < t.length && e.push({ type: "text", value: t.slice(n) }), e.length ? e : [{ type: "text", value: t }];
|
|
95
118
|
}
|
|
96
119
|
export {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
120
|
+
i as API_KEY_HEADER,
|
|
121
|
+
b as API_ROUTES,
|
|
122
|
+
A as APPLICATION_JSON,
|
|
123
|
+
N as CONTENT_TYPE_HEADER,
|
|
124
|
+
v as CUSTOM_PERIOD,
|
|
125
|
+
h as CalendarResolution,
|
|
126
|
+
U as HTTP_ERROR_CODES,
|
|
127
|
+
P as HttpError,
|
|
128
|
+
f as Locale,
|
|
129
|
+
d as OCP_APIM_SUBSCRIPTION_KEY_HEADER,
|
|
130
|
+
M as ONBOARDING_MODEL_POSTFIX,
|
|
131
|
+
O as QueryFilterType,
|
|
132
|
+
H as SHARE_CONVERSATION_ROUTE,
|
|
133
|
+
T as X_CONVERSATION_ID_HEADER,
|
|
134
|
+
q as cleanConversationNames,
|
|
112
135
|
u as defaultFormatNumbers,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
136
|
+
E as deleteConversationNamePostfix,
|
|
137
|
+
F as formatNumberBySign,
|
|
138
|
+
L as getClearedConversationName,
|
|
139
|
+
$ as getConversationAttachmentUrls,
|
|
140
|
+
R as getConversationAttachments,
|
|
141
|
+
X as getConversationFolderIdFromConversationId,
|
|
142
|
+
w as getConversationId,
|
|
143
|
+
K as getConversationIdFromResourceUrl,
|
|
144
|
+
J as getConversationNameFromConversationId,
|
|
145
|
+
B as getConversationNavPath,
|
|
146
|
+
k as getConversationUrlWithoutLocale,
|
|
147
|
+
j as getHeaders,
|
|
148
|
+
Y as getMultipartHeaders,
|
|
149
|
+
G as getTimePeriod,
|
|
150
|
+
x as isHttpError,
|
|
151
|
+
Q as linkifyText,
|
|
152
|
+
z as parseBoolean,
|
|
153
|
+
V as sanitizeHeaders,
|
|
154
|
+
W as sendRequest,
|
|
155
|
+
S as splitTrailingPunctuation
|
|
127
156
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@epam/statgpt-shared-toolkit",
|
|
3
|
-
"version": "0.3.0-rc.
|
|
3
|
+
"version": "0.3.0-rc.10",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"module": "./index.mjs",
|
|
15
15
|
"types": "./index.d.ts",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@epam/ai-dial-shared": "^0.43.3"
|
|
17
|
+
"@epam/ai-dial-shared": "^0.43.3",
|
|
18
|
+
"date-fns": "^4.1.0"
|
|
18
19
|
}
|
|
19
20
|
}
|
|
@@ -1 +1,4 @@
|
|
|
1
1
|
export declare const getConversationUrlWithoutLocale: (resourceUrl: string, locale: string) => string;
|
|
2
|
+
export declare const getConversationIdFromResourceUrl: (resourceUrl: string) => string;
|
|
3
|
+
export declare const getConversationFolderIdFromConversationId: (conversationId: string) => string;
|
|
4
|
+
export declare const getConversationNameFromConversationId: (conversationId: string) => string;
|