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