@memberjunction/ng-react 6.1.3 → 6.2.0-edge.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/lib/components/mj-react-component.component.d.ts +6 -2
- package/dist/lib/components/mj-react-component.component.js +14 -92
- package/dist/lib/components/mj-react-component.component.js.map +1 -1
- package/package.json +10 -10
- package/dist/__tests__/runtime-utilities-ml.test.d.ts +0 -1
- package/dist/__tests__/runtime-utilities-ml.test.js +0 -170
- package/dist/__tests__/runtime-utilities-ml.test.js.map +0 -1
- package/dist/lib/utilities/runtime-utilities.d.ts +0 -80
- package/dist/lib/utilities/runtime-utilities.js +0 -396
- package/dist/lib/utilities/runtime-utilities.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ng-react",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0-edge.0",
|
|
4
4
|
"description": "Angular components for hosting React components in MemberJunction applications",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,21 +34,21 @@
|
|
|
34
34
|
"styles"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@memberjunction/ai-vectors-memory": "6.
|
|
38
|
-
"@memberjunction/core": "6.
|
|
39
|
-
"@memberjunction/core-entities": "6.
|
|
40
|
-
"@memberjunction/global": "6.
|
|
41
|
-
"@memberjunction/graphql-dataprovider": "6.
|
|
42
|
-
"@memberjunction/interactive-component-types": "6.
|
|
43
|
-
"@memberjunction/ng-notifications": "6.
|
|
44
|
-
"@memberjunction/react-runtime": "6.
|
|
37
|
+
"@memberjunction/ai-vectors-memory": "6.2.0-edge.0",
|
|
38
|
+
"@memberjunction/core": "6.2.0-edge.0",
|
|
39
|
+
"@memberjunction/core-entities": "6.2.0-edge.0",
|
|
40
|
+
"@memberjunction/global": "6.2.0-edge.0",
|
|
41
|
+
"@memberjunction/graphql-dataprovider": "6.2.0-edge.0",
|
|
42
|
+
"@memberjunction/interactive-component-types": "6.2.0-edge.0",
|
|
43
|
+
"@memberjunction/ng-notifications": "6.2.0-edge.0",
|
|
44
|
+
"@memberjunction/react-runtime": "6.2.0-edge.0",
|
|
45
45
|
"@babel/standalone": "^7.29.1",
|
|
46
46
|
"react": "^19.2.4",
|
|
47
47
|
"react-dom": "^19.2.4",
|
|
48
48
|
"rxjs": "^7.8.2",
|
|
49
49
|
"@types/react": "^19.2.13",
|
|
50
50
|
"@types/react-dom": "^19.2.3",
|
|
51
|
-
"@memberjunction/ng-base-types": "6.
|
|
51
|
+
"@memberjunction/ng-base-types": "6.2.0-edge.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@angular/compiler": "21.2.22",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @vitest-environment jsdom
|
|
3
|
-
*
|
|
4
|
-
* Focused tests for the ML tools surface (`ComponentUtilities.ml`) built by RuntimeUtilities.
|
|
5
|
-
* The provider statics and the Predictive Studio Remote Operation are mocked so we can exercise
|
|
6
|
-
* the listModels RunView mapping and the score Remote-Op marshalling without a live backend.
|
|
7
|
-
*/
|
|
8
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
9
|
-
// Hoisted so the `vi.mock` factories (which are themselves hoisted above the imports) can
|
|
10
|
-
// safely reference these without a "before initialization" error.
|
|
11
|
-
const { MockGraphQLDataProvider, mockProviderInstance, mockRunView, mockScoreExecute } = vi.hoisted(() => {
|
|
12
|
-
class MockGraphQLDataProvider {
|
|
13
|
-
}
|
|
14
|
-
return {
|
|
15
|
-
// Mock the GraphQL provider so `BaseEntity.Provider instanceof GraphQLDataProvider` is true.
|
|
16
|
-
MockGraphQLDataProvider,
|
|
17
|
-
mockProviderInstance: new MockGraphQLDataProvider(),
|
|
18
|
-
// Controllable RunView mock.
|
|
19
|
-
mockRunView: vi.fn(),
|
|
20
|
-
// Controllable Remote Operation mock.
|
|
21
|
-
mockScoreExecute: vi.fn()
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
vi.mock('@memberjunction/core', async (importOriginal) => {
|
|
25
|
-
const actual = await importOriginal();
|
|
26
|
-
return {
|
|
27
|
-
...actual,
|
|
28
|
-
LogError: vi.fn(),
|
|
29
|
-
BaseEntity: { Provider: mockProviderInstance },
|
|
30
|
-
// RuntimeUtilities now reads through a provider rather than constructing a global RunView,
|
|
31
|
-
// so the mock has to answer the static factory and the global-provider fallback.
|
|
32
|
-
Metadata: Object.assign(class {
|
|
33
|
-
constructor() {
|
|
34
|
-
this.Entities = [];
|
|
35
|
-
this.GetEntityObject = vi.fn();
|
|
36
|
-
}
|
|
37
|
-
}, { Provider: mockProviderInstance }),
|
|
38
|
-
RunView: Object.assign(class {
|
|
39
|
-
constructor() {
|
|
40
|
-
this.RunView = mockRunView;
|
|
41
|
-
this.RunViews = vi.fn();
|
|
42
|
-
}
|
|
43
|
-
}, { FromMetadataProvider: () => ({ RunView: mockRunView, RunViews: vi.fn() }) }),
|
|
44
|
-
RunQuery: class {
|
|
45
|
-
constructor() {
|
|
46
|
-
this.RunQuery = vi.fn();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
vi.mock('@memberjunction/graphql-dataprovider', () => ({
|
|
52
|
-
GraphQLDataProvider: MockGraphQLDataProvider
|
|
53
|
-
}));
|
|
54
|
-
vi.mock('@memberjunction/core-entities', () => ({
|
|
55
|
-
GeoDataEngine: { Instance: undefined },
|
|
56
|
-
MJMLModelEntity: class {
|
|
57
|
-
},
|
|
58
|
-
PredictiveStudioScoreRecordSetOperation: class {
|
|
59
|
-
constructor() {
|
|
60
|
-
this.Execute = mockScoreExecute;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}));
|
|
64
|
-
vi.mock('@memberjunction/ai-vectors-memory', () => ({
|
|
65
|
-
SimpleVectorService: class {
|
|
66
|
-
}
|
|
67
|
-
}));
|
|
68
|
-
vi.mock('@memberjunction/global', async (importOriginal) => {
|
|
69
|
-
const actual = await importOriginal();
|
|
70
|
-
return { ...actual };
|
|
71
|
-
});
|
|
72
|
-
import { RuntimeUtilities } from '../lib/utilities/runtime-utilities';
|
|
73
|
-
describe('RuntimeUtilities — SimpleMLTools', () => {
|
|
74
|
-
beforeEach(() => {
|
|
75
|
-
vi.spyOn(console, 'log').mockImplementation(() => { });
|
|
76
|
-
vi.spyOn(console, 'error').mockImplementation(() => { });
|
|
77
|
-
mockRunView.mockReset();
|
|
78
|
-
mockScoreExecute.mockReset();
|
|
79
|
-
});
|
|
80
|
-
it('exposes an `ml` capability when a GraphQL provider is present', () => {
|
|
81
|
-
const u = new RuntimeUtilities().buildUtilities();
|
|
82
|
-
expect(u.ml).toBeDefined();
|
|
83
|
-
expect(typeof u.ml.listModels).toBe('function');
|
|
84
|
-
expect(typeof u.ml.score).toBe('function');
|
|
85
|
-
});
|
|
86
|
-
it('listModels maps MJ: ML Models rows and parses JSON metrics', async () => {
|
|
87
|
-
mockRunView.mockResolvedValue({
|
|
88
|
-
Success: true,
|
|
89
|
-
Results: [
|
|
90
|
-
{
|
|
91
|
-
ID: 'M1',
|
|
92
|
-
Pipeline: 'Renewal Pipeline',
|
|
93
|
-
Version: 3,
|
|
94
|
-
TargetVariable: 'Renewed',
|
|
95
|
-
ProblemType: 'classification',
|
|
96
|
-
Status: 'Published',
|
|
97
|
-
Metrics: '{"auc":0.91}',
|
|
98
|
-
HoldoutMetrics: 'not-json'
|
|
99
|
-
}
|
|
100
|
-
]
|
|
101
|
-
});
|
|
102
|
-
const u = new RuntimeUtilities().buildUtilities();
|
|
103
|
-
const models = await u.ml.listModels();
|
|
104
|
-
expect(mockRunView).toHaveBeenCalledTimes(1);
|
|
105
|
-
const params = mockRunView.mock.calls[0][0];
|
|
106
|
-
expect(params.EntityName).toBe('MJ: ML Models');
|
|
107
|
-
expect(params.ExtraFilter).toBe("Status='Published'");
|
|
108
|
-
expect(params.OrderBy).toBe('Version DESC');
|
|
109
|
-
expect(models).toHaveLength(1);
|
|
110
|
-
expect(models[0]).toMatchObject({
|
|
111
|
-
id: 'M1',
|
|
112
|
-
pipeline: 'Renewal Pipeline',
|
|
113
|
-
version: 3,
|
|
114
|
-
targetVariable: 'Renewed',
|
|
115
|
-
problemType: 'classification',
|
|
116
|
-
status: 'Published',
|
|
117
|
-
metrics: { auc: 0.91 }
|
|
118
|
-
});
|
|
119
|
-
// Invalid JSON is defensively dropped to undefined.
|
|
120
|
-
expect(models[0].holdoutMetrics).toBeUndefined();
|
|
121
|
-
});
|
|
122
|
-
it('listModels applies status/targetVariable/maxResults filter and returns [] on failure', async () => {
|
|
123
|
-
mockRunView.mockResolvedValue({ Success: false, ErrorMessage: 'boom', Results: [] });
|
|
124
|
-
const u = new RuntimeUtilities().buildUtilities();
|
|
125
|
-
const models = await u.ml.listModels({ status: 'Validated', targetVariable: "O'Brien", maxResults: 5 });
|
|
126
|
-
const params = mockRunView.mock.calls[0][0];
|
|
127
|
-
expect(params.ExtraFilter).toBe("Status='Validated' AND TargetVariable='O''Brien'");
|
|
128
|
-
expect(params.MaxRows).toBe(5);
|
|
129
|
-
expect(models).toEqual([]);
|
|
130
|
-
});
|
|
131
|
-
it('score normalizes record keys, requests ephemeral predictions, and maps the result', async () => {
|
|
132
|
-
mockScoreExecute.mockResolvedValue({
|
|
133
|
-
Success: true,
|
|
134
|
-
Output: {
|
|
135
|
-
scored: 2,
|
|
136
|
-
failed: 0,
|
|
137
|
-
skipped: 1,
|
|
138
|
-
wroteBack: false,
|
|
139
|
-
predictions: [
|
|
140
|
-
{ recordId: 'R1', score: 0.8, class: 'Yes' },
|
|
141
|
-
{ recordId: 'R2', score: 0.2, class: 'No' }
|
|
142
|
-
]
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
const u = new RuntimeUtilities().buildUtilities();
|
|
146
|
-
const result = await u.ml.score('M1', ['R1', { ID: 'R2' }, { Other: 'R3' }], { primaryKeyField: 'ID' });
|
|
147
|
-
expect(mockScoreExecute).toHaveBeenCalledTimes(1);
|
|
148
|
-
const [input, ctx] = mockScoreExecute.mock.calls[0];
|
|
149
|
-
expect(input.modelId).toBe('M1');
|
|
150
|
-
expect(input.scope).toEqual({ records: ['R1', 'R2'] }); // Other-keyed object dropped (no ID)
|
|
151
|
-
expect(input.writeBack).toBeUndefined(); // ephemeral
|
|
152
|
-
expect(ctx.provider).toBe(mockProviderInstance);
|
|
153
|
-
expect(result).toEqual({
|
|
154
|
-
scoredCount: 2,
|
|
155
|
-
failedCount: 0,
|
|
156
|
-
skippedCount: 1,
|
|
157
|
-
predictions: [
|
|
158
|
-
{ recordId: 'R1', score: 0.8, class: 'Yes' },
|
|
159
|
-
{ recordId: 'R2', score: 0.2, class: 'No' }
|
|
160
|
-
]
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
it('score returns a zeroed result with records counted as failed on error', async () => {
|
|
164
|
-
mockScoreExecute.mockResolvedValue({ Success: false, ErrorMessage: 'no model' });
|
|
165
|
-
const u = new RuntimeUtilities().buildUtilities();
|
|
166
|
-
const result = await u.ml.score('M1', ['R1', 'R2']);
|
|
167
|
-
expect(result).toEqual({ scoredCount: 0, failedCount: 2, skippedCount: 0, predictions: [] });
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
//# sourceMappingURL=runtime-utilities-ml.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-utilities-ml.test.js","sourceRoot":"","sources":["../../src/__tests__/runtime-utilities-ml.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAE9D,0FAA0F;AAC1F,kEAAkE;AAClE,MAAM,EAAE,uBAAuB,EAAE,oBAAoB,E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BAAoB,CAAC,CAAC;QAEhD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;YACrB,WAAW,EAAE,CAAC;YACd,WAAW,EAAE,CAAC;YACd,YAAY,EAAE,CAAC;YACf,WAAW,EAAE;gBACX,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE;gBAC5C,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE;aAC5C;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uEAAuE,EAAE,KAAK,IAAI,EAAE;QACrF,gBAAgB,CAAC,iBAAiB,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC,CAAC;QAEjF,MAAM,CAAC,GAAG,IAAI,gBAAgB,EAAE,CAAC,cAAc,EAAE,CAAC;QAClD,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,EAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QAErD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;IAC/F,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/**\n * @vitest-environment jsdom\n *\n * Focused tests for the ML tools surface (`ComponentUtilities.ml`) built by RuntimeUtilities.\n * The provider statics and the Predictive Studio Remote Operation are mocked so we can exercise\n * the listModels RunView mapping and the score Remote-Op marshalling without a live backend.\n */\nimport { describe, it, expect, vi, beforeEach } from 'vitest';\n\n// Hoisted so the `vi.mock` factories (which are themselves hoisted above the imports) can\n// safely reference these without a \"before initialization\" error.\nconst { MockGraphQLDataProvider, mockProviderInstance, mockRunView, mockScoreExecute } = vi.hoisted(() => {\n class MockGraphQLDataProvider {}\n return {\n // Mock the GraphQL provider so `BaseEntity.Provider instanceof GraphQLDataProvider` is true.\n MockGraphQLDataProvider,\n mockProviderInstance: new MockGraphQLDataProvider(),\n // Controllable RunView mock.\n mockRunView: vi.fn(),\n // Controllable Remote Operation mock.\n mockScoreExecute: vi.fn()\n };\n});\n\nvi.mock('@memberjunction/core', async (importOriginal) => {\n const actual = await importOriginal<typeof import('@memberjunction/core')>();\n return {\n ...actual,\n LogError: vi.fn(),\n BaseEntity: { Provider: mockProviderInstance },\n // RuntimeUtilities now reads through a provider rather than constructing a global RunView,\n // so the mock has to answer the static factory and the global-provider fallback.\n Metadata: Object.assign(\n class {\n Entities = [];\n GetEntityObject = vi.fn();\n },\n { Provider: mockProviderInstance },\n ),\n RunView: Object.assign(\n class {\n RunView = mockRunView;\n RunViews = vi.fn();\n },\n { FromMetadataProvider: () => ({ RunView: mockRunView, RunViews: vi.fn() }) },\n ),\n RunQuery: class {\n RunQuery = vi.fn();\n }\n };\n});\n\nvi.mock('@memberjunction/graphql-dataprovider', () => ({\n GraphQLDataProvider: MockGraphQLDataProvider\n}));\n\nvi.mock('@memberjunction/core-entities', () => ({\n GeoDataEngine: { Instance: undefined },\n MJMLModelEntity: class {},\n PredictiveStudioScoreRecordSetOperation: class {\n Execute = mockScoreExecute;\n }\n}));\n\nvi.mock('@memberjunction/ai-vectors-memory', () => ({\n SimpleVectorService: class {}\n}));\n\nvi.mock('@memberjunction/global', async (importOriginal) => {\n const actual = await importOriginal<typeof import('@memberjunction/global')>();\n return { ...actual };\n});\n\nimport { RuntimeUtilities } from '../lib/utilities/runtime-utilities';\n\ndescribe('RuntimeUtilities — SimpleMLTools', () => {\n beforeEach(() => {\n vi.spyOn(console, 'log').mockImplementation(() => {});\n vi.spyOn(console, 'error').mockImplementation(() => {});\n mockRunView.mockReset();\n mockScoreExecute.mockReset();\n });\n\n it('exposes an `ml` capability when a GraphQL provider is present', () => {\n const u = new RuntimeUtilities().buildUtilities();\n expect(u.ml).toBeDefined();\n expect(typeof u.ml!.listModels).toBe('function');\n expect(typeof u.ml!.score).toBe('function');\n });\n\n it('listModels maps MJ: ML Models rows and parses JSON metrics', async () => {\n mockRunView.mockResolvedValue({\n Success: true,\n Results: [\n {\n ID: 'M1',\n Pipeline: 'Renewal Pipeline',\n Version: 3,\n TargetVariable: 'Renewed',\n ProblemType: 'classification',\n Status: 'Published',\n Metrics: '{\"auc\":0.91}',\n HoldoutMetrics: 'not-json'\n }\n ]\n });\n\n const u = new RuntimeUtilities().buildUtilities();\n const models = await u.ml!.listModels();\n\n expect(mockRunView).toHaveBeenCalledTimes(1);\n const params = mockRunView.mock.calls[0][0];\n expect(params.EntityName).toBe('MJ: ML Models');\n expect(params.ExtraFilter).toBe(\"Status='Published'\");\n expect(params.OrderBy).toBe('Version DESC');\n\n expect(models).toHaveLength(1);\n expect(models[0]).toMatchObject({\n id: 'M1',\n pipeline: 'Renewal Pipeline',\n version: 3,\n targetVariable: 'Renewed',\n problemType: 'classification',\n status: 'Published',\n metrics: { auc: 0.91 }\n });\n // Invalid JSON is defensively dropped to undefined.\n expect(models[0].holdoutMetrics).toBeUndefined();\n });\n\n it('listModels applies status/targetVariable/maxResults filter and returns [] on failure', async () => {\n mockRunView.mockResolvedValue({ Success: false, ErrorMessage: 'boom', Results: [] });\n\n const u = new RuntimeUtilities().buildUtilities();\n const models = await u.ml!.listModels({ status: 'Validated', targetVariable: \"O'Brien\", maxResults: 5 });\n\n const params = mockRunView.mock.calls[0][0];\n expect(params.ExtraFilter).toBe(\"Status='Validated' AND TargetVariable='O''Brien'\");\n expect(params.MaxRows).toBe(5);\n expect(models).toEqual([]);\n });\n\n it('score normalizes record keys, requests ephemeral predictions, and maps the result', async () => {\n mockScoreExecute.mockResolvedValue({\n Success: true,\n Output: {\n scored: 2,\n failed: 0,\n skipped: 1,\n wroteBack: false,\n predictions: [\n { recordId: 'R1', score: 0.8, class: 'Yes' },\n { recordId: 'R2', score: 0.2, class: 'No' }\n ]\n }\n });\n\n const u = new RuntimeUtilities().buildUtilities();\n const result = await u.ml!.score('M1', ['R1', { ID: 'R2' }, { Other: 'R3' }], { primaryKeyField: 'ID' });\n\n expect(mockScoreExecute).toHaveBeenCalledTimes(1);\n const [input, ctx] = mockScoreExecute.mock.calls[0];\n expect(input.modelId).toBe('M1');\n expect(input.scope).toEqual({ records: ['R1', 'R2'] }); // Other-keyed object dropped (no ID)\n expect(input.writeBack).toBeUndefined(); // ephemeral\n expect(ctx.provider).toBe(mockProviderInstance);\n\n expect(result).toEqual({\n scoredCount: 2,\n failedCount: 0,\n skippedCount: 1,\n predictions: [\n { recordId: 'R1', score: 0.8, class: 'Yes' },\n { recordId: 'R2', score: 0.2, class: 'No' }\n ]\n });\n });\n\n it('score returns a zeroed result with records counted as failed on error', async () => {\n mockScoreExecute.mockResolvedValue({ Success: false, ErrorMessage: 'no model' });\n\n const u = new RuntimeUtilities().buildUtilities();\n const result = await u.ml!.score('M1', ['R1', 'R2']);\n\n expect(result).toEqual({ scoredCount: 0, failedCount: 2, skippedCount: 0, predictions: [] });\n });\n});\n"]}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Runtime utilities for React components providing access to MemberJunction core functionality
|
|
3
|
-
* @module @memberjunction/ng-react/utilities
|
|
4
|
-
*/
|
|
5
|
-
import { IMetadataProvider } from '@memberjunction/core';
|
|
6
|
-
import { ComponentUtilities } from '@memberjunction/interactive-component-types';
|
|
7
|
-
/**
|
|
8
|
-
* Base class for providing runtime utilities to React components in Angular.
|
|
9
|
-
* This class can be extended and registered with MJ's ClassFactory
|
|
10
|
-
* to provide custom implementations of data access methods.
|
|
11
|
-
*/
|
|
12
|
-
export declare class RuntimeUtilities {
|
|
13
|
-
private debug;
|
|
14
|
-
/**
|
|
15
|
-
* The provider every read in the built utilities goes through. Always set by
|
|
16
|
-
* {@link buildUtilities} before use — falls back to the global provider there
|
|
17
|
-
* (`provider ?? Metadata.Provider`) when the host doesn't supply one.
|
|
18
|
-
*/
|
|
19
|
-
private provider;
|
|
20
|
-
/**
|
|
21
|
-
* Builds the complete utilities object for React components
|
|
22
|
-
* This is the main method that components will use
|
|
23
|
-
*
|
|
24
|
-
* @param provider the host's provider. A React component mounted under a non-default provider
|
|
25
|
-
* passes its own `ProviderToUse`; omitting it falls back to the global default, named
|
|
26
|
-
* explicitly rather than reached for via `new Metadata()`.
|
|
27
|
-
*/
|
|
28
|
-
buildUtilities(debug?: boolean, provider?: IMetadataProvider): ComponentUtilities;
|
|
29
|
-
/**
|
|
30
|
-
* Sets up the utilities object - copied from skip-chat implementation
|
|
31
|
-
*/
|
|
32
|
-
private SetupUtilities;
|
|
33
|
-
private CreateSimpleAITools;
|
|
34
|
-
/**
|
|
35
|
-
* Creates the ML tools surface for components — listing trained models and scoring records.
|
|
36
|
-
* `listModels` reads the `MJ: ML Models` catalog via RunView; `score` marshals the
|
|
37
|
-
* `PredictiveStudio.ScoreRecordSet` Remote Operation over GraphQL to the server engine (the
|
|
38
|
-
* Python sidecar lives server-side and cannot run in the browser). Returns `undefined` when no
|
|
39
|
-
* GraphQL provider is available, so the `ml` capability degrades cleanly.
|
|
40
|
-
*/
|
|
41
|
-
private CreateSimpleMLTools;
|
|
42
|
-
/**
|
|
43
|
-
* Loads the trained-model catalog from `MJ: ML Models`, newest version first, mapping each row
|
|
44
|
-
* to a {@link SimpleMLModelInfo}. Resilient — logs and returns `[]` on any failure.
|
|
45
|
-
*/
|
|
46
|
-
private listMLModels;
|
|
47
|
-
/**
|
|
48
|
-
* Builds the ExtraFilter clause for {@link listMLModels}. Defaults to `Status='Published'` so
|
|
49
|
-
* components only see promoted models unless the caller overrides the status.
|
|
50
|
-
*/
|
|
51
|
-
private buildMLModelsFilter;
|
|
52
|
-
/** Maps a single `MJ: ML Models` row to the component-facing {@link SimpleMLModelInfo} shape. */
|
|
53
|
-
private mapMLModel;
|
|
54
|
-
/** Defensively parses a JSON metrics blob; returns `undefined` for null/empty/invalid JSON. */
|
|
55
|
-
private parseMLMetrics;
|
|
56
|
-
/**
|
|
57
|
-
* Scores records with a trained model by invoking the `PredictiveStudio.ScoreRecordSet` Remote
|
|
58
|
-
* Operation. Normalizes `records` to primary-key strings, requests ephemeral predictions (no
|
|
59
|
-
* write-back), and maps the result. Resilient — logs and returns a zeroed result with the input
|
|
60
|
-
* records counted as failed on any error.
|
|
61
|
-
*/
|
|
62
|
-
private scoreMLRecords;
|
|
63
|
-
/**
|
|
64
|
-
* Normalizes a mixed array of primary-key strings and row objects into an array of primary-key
|
|
65
|
-
* strings, reading `primaryKeyField` from objects. Drops entries without a resolvable key.
|
|
66
|
-
*/
|
|
67
|
-
private normalizeRecordKeys;
|
|
68
|
-
/** Escapes single quotes for safe inlining into a RunView ExtraFilter SQL string literal. */
|
|
69
|
-
private escapeSqlLiteral;
|
|
70
|
-
private CreateSimpleMetadata;
|
|
71
|
-
private CreateSimpleGeoDataEngine;
|
|
72
|
-
private CreateSimpleRunQuery;
|
|
73
|
-
private CreateSimpleRunView;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Factory function to create RuntimeUtilities
|
|
77
|
-
* In a Node.js environment, this will use MJ's ClassFactory for runtime substitution
|
|
78
|
-
* In a browser environment, it will use the base class directly
|
|
79
|
-
*/
|
|
80
|
-
export declare function createRuntimeUtilities(): RuntimeUtilities;
|