@or-sdk/knowledge-models 0.12.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.
Files changed (40) hide show
  1. package/dist/cjs/KnowledgeModels.js +1244 -0
  2. package/dist/cjs/KnowledgeModels.js.map +1 -0
  3. package/dist/cjs/constants.js +5 -0
  4. package/dist/cjs/constants.js.map +1 -0
  5. package/dist/cjs/index.js +17 -0
  6. package/dist/cjs/index.js.map +1 -0
  7. package/dist/cjs/types.js +3 -0
  8. package/dist/cjs/types.js.map +1 -0
  9. package/dist/cjs/utils/getEntityBody.js +40 -0
  10. package/dist/cjs/utils/getEntityBody.js.map +1 -0
  11. package/dist/cjs/utils/index.js +9 -0
  12. package/dist/cjs/utils/index.js.map +1 -0
  13. package/dist/esm/KnowledgeModels.js +860 -0
  14. package/dist/esm/KnowledgeModels.js.map +1 -0
  15. package/dist/esm/constants.js +2 -0
  16. package/dist/esm/constants.js.map +1 -0
  17. package/dist/esm/index.js +3 -0
  18. package/dist/esm/index.js.map +1 -0
  19. package/dist/esm/types.js +2 -0
  20. package/dist/esm/types.js.map +1 -0
  21. package/dist/esm/utils/getEntityBody.js +27 -0
  22. package/dist/esm/utils/getEntityBody.js.map +1 -0
  23. package/dist/esm/utils/index.js +2 -0
  24. package/dist/esm/utils/index.js.map +1 -0
  25. package/dist/types/KnowledgeModels.d.ts +331 -0
  26. package/dist/types/constants.d.ts +1 -0
  27. package/dist/types/index.d.ts +2 -0
  28. package/dist/types/types.d.ts +306 -0
  29. package/dist/types/utils/getEntityBody.d.ts +6 -0
  30. package/dist/types/utils/index.d.ts +1 -0
  31. package/package.json +29 -0
  32. package/src/KnowledgeModels.ts +1302 -0
  33. package/src/constants.ts +1 -0
  34. package/src/index.ts +2 -0
  35. package/src/types.ts +347 -0
  36. package/src/utils/getEntityBody.ts +37 -0
  37. package/src/utils/index.ts +4 -0
  38. package/tsconfig.esm.json +9 -0
  39. package/tsconfig.json +7 -0
  40. package/tsconfig.types.json +9 -0
@@ -0,0 +1 @@
1
+ export const SERVICE_KEY = 'nlu-api';
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { KnowledgeModels } from './KnowledgeModels';
2
+ export * from './types';
package/src/types.ts ADDED
@@ -0,0 +1,347 @@
1
+ import { Token } from '@or-sdk/base';
2
+
3
+ export type KnowledgeModelsConfig = {
4
+ /**
5
+ * token
6
+ */
7
+ token: Token;
8
+ /**
9
+ * Url of OneReach service discovery api
10
+ */
11
+ discoveryUrl: string;
12
+ };
13
+
14
+ export type Version = {
15
+ versionId: string;
16
+ trainStatus: {
17
+ status: string;
18
+ message: string;
19
+ modelId: string;
20
+ date: number;
21
+ };
22
+ prebuiltModelIds?: string[];
23
+ };
24
+
25
+ export type KnowledgeModel = {
26
+ extensions: string[];
27
+ name: string;
28
+ desc: string;
29
+ imageSrc: string;
30
+ createdBy: string;
31
+ createdDate: number;
32
+ modifiedBy: string;
33
+ modifiedDate: number;
34
+ config: {
35
+ [key: string]: unknown;
36
+ };
37
+ culture: string;
38
+ versions: Version[];
39
+ endpoints: {
40
+ PRODUCTION: {
41
+ publishedDateTime: number | null;
42
+ publishedAppId: string;
43
+ publishedVersionId: string | null;
44
+ currentVersionId: string;
45
+ modifiedDateTime: number | null;
46
+ trainStatus: {
47
+ status: string;
48
+ message: string;
49
+ modelId: string;
50
+ date: number | null;
51
+ };
52
+ status: string;
53
+ endpointUrl?: string;
54
+ isStaging?: boolean;
55
+ region?: string;
56
+ endpointRegion?: string;
57
+ };
58
+ };
59
+ id: string;
60
+ };
61
+
62
+ export type KnowledgeModelOptionalFields = { id: string; } & {
63
+ [K in keyof KnowledgeModel]?: KnowledgeModel[K];
64
+ };
65
+
66
+ export type PartialListResponse<T> = {
67
+ total: {
68
+ value: number;
69
+ relation: string;
70
+ };
71
+ items: T[];
72
+ last?: string;
73
+ };
74
+
75
+ export type KnowledgeModelCreateParams = {
76
+ name: string;
77
+ desc: string;
78
+ imageSrc: string;
79
+ config?: {
80
+ [key: string]: unknown;
81
+ };
82
+ culture: string;
83
+ extensions: string[];
84
+ };
85
+
86
+ export type LimitsResponse = string[];
87
+
88
+ export type PrebuiltEntity = {
89
+ name: string;
90
+ description?: string;
91
+ examples?: string;
92
+ };
93
+
94
+ type EntityFeature = {
95
+ featureName: string;
96
+ isRequired: boolean;
97
+ };
98
+
99
+ type EntityChild = {
100
+ name: string;
101
+ features?: EntityFeature[];
102
+ children?: EntityChild[];
103
+ id: string;
104
+ };
105
+
106
+ export type Entity = {
107
+ name: string;
108
+ roles?: string[];
109
+ children?: EntityChild[];
110
+ features?: EntityFeature[];
111
+ kbId?: string;
112
+ prebuiltModelId?: string;
113
+ versionId?: string | null;
114
+ id: string;
115
+ };
116
+
117
+ export type Feature = {
118
+ kbId: string;
119
+ name: string;
120
+ mode: boolean;
121
+ words: string;
122
+ activated: boolean;
123
+ enabledForAllModels: boolean;
124
+ versionId: string | null;
125
+ id: string;
126
+ };
127
+
128
+ type UtteranceEntityChild = {
129
+ entity: string;
130
+ children: UtteranceEntityChild[];
131
+ startPos: number;
132
+ endPos: number;
133
+ };
134
+
135
+ export type UtteranceEntity = {
136
+ entity: string;
137
+ value: string;
138
+ role: string | null;
139
+ startPos: number;
140
+ endPos: number;
141
+ children: UtteranceEntityChild[];
142
+ };
143
+
144
+ export type Utterance = {
145
+ text: string;
146
+ intent: string;
147
+ entities: UtteranceEntity[];
148
+ entityPredictions: unknown[];
149
+ prebuiltModelId?: string;
150
+ dateCreated: number;
151
+ autoGenerated: boolean;
152
+ unrecognized: boolean;
153
+ intentCreated: number;
154
+ appCreated: number;
155
+ id: string;
156
+ versionId?: string | null;
157
+ application?: string;
158
+ kbId?: string;
159
+ };
160
+
161
+ type IntentFeature = EntityFeature;
162
+
163
+ export type Intent = {
164
+ id: string;
165
+ name: string;
166
+ type: string;
167
+ kbId: string;
168
+ prebuiltModelId?: string;
169
+ application: string;
170
+ dateCreated: number;
171
+ postprocessFlows: string[];
172
+ customData?: {
173
+ [key: string]: unknown;
174
+ };
175
+ features: IntentFeature[];
176
+ versionId: string | null;
177
+ };
178
+
179
+ export type Application = {
180
+ luis_schema_version: string;
181
+ versionId: string | null;
182
+ luisId: string;
183
+ name: string;
184
+ desc: string;
185
+ culture: string;
186
+ endpoints: {
187
+ PRODUCTION: {
188
+ publishedDateTime: number | null;
189
+ publishedVersionId: number | null;
190
+ modifiedDateTime: number;
191
+ trainStatus: {
192
+ status: string;
193
+ message: string;
194
+ modelId: string;
195
+ date: number | null;
196
+ };
197
+ status: string;
198
+ };
199
+ };
200
+ composites: string[];
201
+ closedLists: string[];
202
+ patternAnyEntities: string[];
203
+ model_features: string[];
204
+ regex_features: string[];
205
+ patterns: string[];
206
+ settings: string[];
207
+ id: string;
208
+ dateCreated: number;
209
+ intents: Intent[];
210
+ utterances: Utterance[];
211
+ };
212
+
213
+ export type IntentLabelsResponse = {
214
+ [key: string]: {
215
+ utterances: number;
216
+ patterns: number;
217
+ };
218
+ };
219
+
220
+ export type PatternEntity = {
221
+ entity: string;
222
+ order: number;
223
+ };
224
+
225
+ export type Pattern = {
226
+ kbId: string;
227
+ appCreated: number;
228
+ pattern: string;
229
+ intent: string;
230
+ intentCreated: number;
231
+ entities: PatternEntity[];
232
+ application: string;
233
+ versionId: string | null;
234
+ dateCreated: number;
235
+ id: string;
236
+ };
237
+
238
+ type PrebuiltModelEntity = {
239
+ name: string;
240
+ children: PrebuiltModelEntity[];
241
+ type: string;
242
+ };
243
+
244
+ export type PrebuiltModel = {
245
+ id: string;
246
+ name: string;
247
+ description: string;
248
+ versionId: string;
249
+ dateCreated: number;
250
+ responses: string[];
251
+ entities: PrebuiltModelEntity[];
252
+ language: string;
253
+ };
254
+
255
+ type PrebuiltModelDetailsResponse = {
256
+ name: string;
257
+ id: string;
258
+ };
259
+
260
+ type PrebuiltModelDetailsEntity = {
261
+ name: string;
262
+ id: string;
263
+ };
264
+
265
+ export type PrebuiltModelDetails = {
266
+ responses: PrebuiltModelDetailsResponse[];
267
+ entities: PrebuiltModelDetailsEntity[];
268
+ application: string;
269
+ };
270
+
271
+ export type Pair = {
272
+ application: Application;
273
+ intent: Intent;
274
+ utterance?: Utterance;
275
+ pattern?: Pattern;
276
+ };
277
+
278
+ export type CreatePairsResponse = {
279
+ accepted: Utterance[];
280
+ failed: {
281
+ utterance: Utterance;
282
+ reason: string;
283
+ }[];
284
+ };
285
+
286
+ export type UpdatedPairsResponse = CreatePairsResponse;
287
+
288
+ export type TrainStatusResponse = {
289
+ status: string;
290
+ message: string;
291
+ details: string;
292
+ priority?: number;
293
+ date: number;
294
+ };
295
+
296
+ export type TrainResponse = {
297
+ status: string;
298
+ };
299
+
300
+ export type PublishResponse = {
301
+ status: string;
302
+ };
303
+
304
+ export type ImportResponse = {
305
+ createdKb: KnowledgeModel;
306
+ };
307
+
308
+ export type CloneResponse = ImportResponse;
309
+
310
+ type MeaningAnswer = {
311
+ answer: string;
312
+ answerId: string;
313
+ type: string;
314
+ score: number;
315
+ contextId: string;
316
+ context: string;
317
+ };
318
+
319
+ type MeaningPatternsMatch = {
320
+ answer: string;
321
+ answerId: string;
322
+ type: string;
323
+ score: number | null;
324
+ contextId: string;
325
+ context: string;
326
+ pattern: string;
327
+ };
328
+
329
+ type MeaningEntity = UtteranceEntity;
330
+
331
+ export type MeaningResponse = {
332
+ result: {
333
+ question: string;
334
+ answer: string;
335
+ answerId: string;
336
+ type: string;
337
+ contextId: string;
338
+ context: string;
339
+ luisId: string;
340
+ topAnswers: MeaningAnswer[];
341
+ entities: MeaningEntity[];
342
+ patternsMatches: MeaningPatternsMatch[];
343
+ };
344
+ targetQuestion: string;
345
+ confidence: number;
346
+ tokenizedText: string[];
347
+ };
@@ -0,0 +1,37 @@
1
+ function getEntityBody(type: string, data: { [key: string]: unknown; }): { [key: string]: unknown; } {
2
+ const base = {
3
+ name: data.name,
4
+ roles: data.roles,
5
+ };
6
+ switch (type) {
7
+ case 'simple':
8
+ return {
9
+ ...base,
10
+ features: data.features,
11
+ children: data.children,
12
+ };
13
+ case 'regex':
14
+ return {
15
+ ...base,
16
+ regexPattern: data.regexPattern,
17
+ };
18
+ case 'prebuilt':
19
+ return base;
20
+ case 'postprocess':
21
+ return {
22
+ name: data.name,
23
+ processFlow: data.processFlow,
24
+ };
25
+ case 'list':
26
+ return {
27
+ ...base,
28
+ subLists: data.subLists,
29
+ };
30
+ case 'patternany':
31
+ return base;
32
+ default:
33
+ throw new Error(`Unknown entity type ${type}`);
34
+ }
35
+ }
36
+
37
+ export default getEntityBody;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @internal
3
+ */
4
+ export { default as getEntityBody } from './getEntityBody';
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "ES6",
5
+ "target": "es6",
6
+ "outDir": "./dist/esm/",
7
+ "rootDir": "./src"
8
+ }
9
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/cjs/",
5
+ "rootDir": "./src"
6
+ }
7
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/types/",
5
+ "rootDir": "./src",
6
+ "declaration": true,
7
+ "emitDeclarationOnly": true
8
+ }
9
+ }