@aexol/spectral 0.9.169 → 0.9.171
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/agent/agents.d.ts.map +1 -1
- package/dist/agent/agents.js +30 -42
- package/dist/generated/graphql-client.d.ts +39 -0
- package/dist/generated/graphql-client.d.ts.map +1 -0
- package/dist/generated/graphql-client.js +74 -0
- package/dist/generated/scalars.d.ts +24 -0
- package/dist/generated/scalars.d.ts.map +1 -0
- package/dist/generated/scalars.js +30 -0
- package/dist/generated/zeus/const.d.ts +8 -0
- package/dist/generated/zeus/const.d.ts.map +1 -0
- package/dist/generated/zeus/const.js +1626 -0
- package/dist/generated/zeus/index.d.ts +8565 -0
- package/dist/generated/zeus/index.d.ts.map +1 -0
- package/dist/generated/zeus/index.js +791 -0
- package/dist/mcp/ui-stream-types.d.ts +2 -2
- package/dist/relay/models-fetch.d.ts +4 -5
- package/dist/relay/models-fetch.d.ts.map +1 -1
- package/dist/relay/models-fetch.js +50 -79
- package/package.json +1 -1
|
@@ -0,0 +1,791 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import { AllTypesProps, ReturnTypes, Ops } from './const.js';
|
|
3
|
+
export const HOST = "Specify host";
|
|
4
|
+
export const HEADERS = {};
|
|
5
|
+
export const apiSubscription = (options) => (query) => {
|
|
6
|
+
try {
|
|
7
|
+
const queryString = options[0] + '?query=' + encodeURIComponent(query);
|
|
8
|
+
const wsString = queryString.replace('http', 'ws');
|
|
9
|
+
const host = (options.length > 1 && options[1]?.websocket?.[0]) || wsString;
|
|
10
|
+
const webSocketOptions = options[1]?.websocket || [host];
|
|
11
|
+
const ws = new WebSocket(...webSocketOptions);
|
|
12
|
+
return {
|
|
13
|
+
ws,
|
|
14
|
+
on: (e) => {
|
|
15
|
+
ws.onmessage = (event) => {
|
|
16
|
+
if (event.data) {
|
|
17
|
+
const parsed = JSON.parse(event.data);
|
|
18
|
+
const data = parsed.data;
|
|
19
|
+
return e(data);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
off: (e) => {
|
|
24
|
+
ws.onclose = e;
|
|
25
|
+
},
|
|
26
|
+
error: (e) => {
|
|
27
|
+
ws.onerror = e;
|
|
28
|
+
},
|
|
29
|
+
open: (e) => {
|
|
30
|
+
ws.onopen = e;
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
throw new Error('No websockets implemented');
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export const apiSubscriptionSSE = (options) => (query, variables) => {
|
|
39
|
+
const url = options[0];
|
|
40
|
+
const fetchOptions = options[1] || {};
|
|
41
|
+
let abortController = null;
|
|
42
|
+
let reader = null;
|
|
43
|
+
let onCallback = null;
|
|
44
|
+
let errorCallback = null;
|
|
45
|
+
let openCallback = null;
|
|
46
|
+
let offCallback = null;
|
|
47
|
+
let isClosing = false; // Flag to track intentional close
|
|
48
|
+
const startStream = async () => {
|
|
49
|
+
try {
|
|
50
|
+
abortController = new AbortController();
|
|
51
|
+
const response = await fetch(url, {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
headers: {
|
|
54
|
+
Accept: 'text/event-stream',
|
|
55
|
+
'Content-Type': 'application/json',
|
|
56
|
+
'Cache-Control': 'no-cache',
|
|
57
|
+
...fetchOptions.headers,
|
|
58
|
+
},
|
|
59
|
+
body: JSON.stringify({ query, variables }),
|
|
60
|
+
signal: abortController.signal,
|
|
61
|
+
...fetchOptions,
|
|
62
|
+
});
|
|
63
|
+
if (!response.ok) {
|
|
64
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
65
|
+
}
|
|
66
|
+
if (openCallback) {
|
|
67
|
+
openCallback();
|
|
68
|
+
}
|
|
69
|
+
reader = response.body?.getReader() || null;
|
|
70
|
+
if (!reader) {
|
|
71
|
+
throw new Error('No response body');
|
|
72
|
+
}
|
|
73
|
+
const decoder = new TextDecoder();
|
|
74
|
+
let buffer = '';
|
|
75
|
+
while (true) {
|
|
76
|
+
const { done, value } = await reader.read();
|
|
77
|
+
if (done) {
|
|
78
|
+
if (offCallback) {
|
|
79
|
+
offCallback({ data: null, code: 1000, reason: 'Stream completed' });
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
buffer += decoder.decode(value, { stream: true });
|
|
84
|
+
const lines = buffer.split('\n');
|
|
85
|
+
buffer = lines.pop() || '';
|
|
86
|
+
for (const line of lines) {
|
|
87
|
+
if (line.startsWith('data: ')) {
|
|
88
|
+
try {
|
|
89
|
+
const data = line.slice(6);
|
|
90
|
+
const parsed = JSON.parse(data);
|
|
91
|
+
if (parsed.errors) {
|
|
92
|
+
if (errorCallback) {
|
|
93
|
+
errorCallback({ data: parsed.data, errors: parsed.errors });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else if (onCallback && parsed.data) {
|
|
97
|
+
onCallback(parsed.data);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
if (errorCallback) {
|
|
102
|
+
errorCallback({ errors: ['Failed to parse SSE data'] });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
const error = err;
|
|
111
|
+
// Don't report errors if we're intentionally closing (AbortError) or during cleanup
|
|
112
|
+
if (error.name !== 'AbortError' && !isClosing && errorCallback) {
|
|
113
|
+
errorCallback({ errors: [error.message || 'Unknown error'] });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
on: (e) => {
|
|
119
|
+
onCallback = e;
|
|
120
|
+
},
|
|
121
|
+
off: (e) => {
|
|
122
|
+
offCallback = e;
|
|
123
|
+
},
|
|
124
|
+
error: (e) => {
|
|
125
|
+
errorCallback = e;
|
|
126
|
+
},
|
|
127
|
+
open: (e) => {
|
|
128
|
+
if (e) {
|
|
129
|
+
openCallback = e;
|
|
130
|
+
}
|
|
131
|
+
startStream();
|
|
132
|
+
},
|
|
133
|
+
close: () => {
|
|
134
|
+
isClosing = true; // Mark as intentionally closing to suppress error callbacks
|
|
135
|
+
if (abortController) {
|
|
136
|
+
abortController.abort();
|
|
137
|
+
}
|
|
138
|
+
if (reader) {
|
|
139
|
+
// Wrap in try-catch to suppress AbortError during cleanup
|
|
140
|
+
reader.cancel().catch(() => {
|
|
141
|
+
// Ignore cancel errors - stream may already be closed
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
const handleFetchResponse = (response) => {
|
|
148
|
+
if (!response.ok) {
|
|
149
|
+
return new Promise((_, reject) => {
|
|
150
|
+
response
|
|
151
|
+
.text()
|
|
152
|
+
.then((text) => {
|
|
153
|
+
try {
|
|
154
|
+
reject(JSON.parse(text));
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
reject(text);
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
.catch(reject);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return response.json();
|
|
164
|
+
};
|
|
165
|
+
export const apiFetch = (options) => (query, variables = {}) => {
|
|
166
|
+
const fetchOptions = options[1] || {};
|
|
167
|
+
if (fetchOptions.method && fetchOptions.method === 'GET') {
|
|
168
|
+
return fetch(`${options[0]}?query=${encodeURIComponent(query)}`, fetchOptions)
|
|
169
|
+
.then(handleFetchResponse)
|
|
170
|
+
.then((response) => {
|
|
171
|
+
if (response.errors) {
|
|
172
|
+
throw new GraphQLError(response);
|
|
173
|
+
}
|
|
174
|
+
return response.data;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return fetch(`${options[0]}`, {
|
|
178
|
+
body: JSON.stringify({ query, variables }),
|
|
179
|
+
method: 'POST',
|
|
180
|
+
headers: {
|
|
181
|
+
'Content-Type': 'application/json',
|
|
182
|
+
},
|
|
183
|
+
...fetchOptions,
|
|
184
|
+
})
|
|
185
|
+
.then(handleFetchResponse)
|
|
186
|
+
.then((response) => {
|
|
187
|
+
if (response.errors) {
|
|
188
|
+
throw new GraphQLError(response);
|
|
189
|
+
}
|
|
190
|
+
return response.data;
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
export const InternalsBuildQuery = ({ ops, props, returns, options, scalars, }) => {
|
|
194
|
+
const ibb = (k, o, p = '', root = true, vars = []) => {
|
|
195
|
+
const keyForPath = purifyGraphQLKey(k);
|
|
196
|
+
const newPath = [p, keyForPath].join(SEPARATOR);
|
|
197
|
+
if (!o) {
|
|
198
|
+
return '';
|
|
199
|
+
}
|
|
200
|
+
if (typeof o === 'boolean' || typeof o === 'number') {
|
|
201
|
+
return k;
|
|
202
|
+
}
|
|
203
|
+
if (typeof o === 'string') {
|
|
204
|
+
return `${k} ${o}`;
|
|
205
|
+
}
|
|
206
|
+
if (Array.isArray(o)) {
|
|
207
|
+
const args = InternalArgsBuilt({
|
|
208
|
+
props,
|
|
209
|
+
returns,
|
|
210
|
+
ops,
|
|
211
|
+
scalars,
|
|
212
|
+
vars,
|
|
213
|
+
})(o[0], newPath);
|
|
214
|
+
return `${ibb(args ? `${k}(${args})` : k, o[1], p, false, vars)}`;
|
|
215
|
+
}
|
|
216
|
+
if (k === '__alias') {
|
|
217
|
+
return Object.entries(o)
|
|
218
|
+
.map(([alias, objectUnderAlias]) => {
|
|
219
|
+
if (typeof objectUnderAlias !== 'object' || Array.isArray(objectUnderAlias)) {
|
|
220
|
+
throw new Error('Invalid alias it should be __alias:{ YOUR_ALIAS_NAME: { OPERATION_NAME: { ...selectors }}}');
|
|
221
|
+
}
|
|
222
|
+
const operationName = Object.keys(objectUnderAlias)[0];
|
|
223
|
+
const operation = objectUnderAlias[operationName];
|
|
224
|
+
return ibb(`${alias}:${operationName}`, operation, p, false, vars);
|
|
225
|
+
})
|
|
226
|
+
.join('\n');
|
|
227
|
+
}
|
|
228
|
+
const hasOperationName = root && options?.operationName ? ' ' + options.operationName : '';
|
|
229
|
+
const keyForDirectives = o.__directives ?? '';
|
|
230
|
+
const query = `{${Object.entries(o)
|
|
231
|
+
.filter(([k]) => k !== '__directives')
|
|
232
|
+
.map((e) => ibb(...e, [p, `field<>${keyForPath}`].join(SEPARATOR), false, vars))
|
|
233
|
+
.join('\n')}}`;
|
|
234
|
+
if (!root) {
|
|
235
|
+
return `${k} ${keyForDirectives}${hasOperationName} ${query}`;
|
|
236
|
+
}
|
|
237
|
+
const varsString = vars.map((v) => `${v.name}: ${v.graphQLType}`).join(', ');
|
|
238
|
+
return `${k} ${keyForDirectives}${hasOperationName}${varsString ? `(${varsString})` : ''} ${query}`;
|
|
239
|
+
};
|
|
240
|
+
return ibb;
|
|
241
|
+
};
|
|
242
|
+
export const Thunder = (fn, thunderGraphQLOptions) => (operation, graphqlOptions) => (o, ops) => {
|
|
243
|
+
const options = {
|
|
244
|
+
...thunderGraphQLOptions,
|
|
245
|
+
...graphqlOptions,
|
|
246
|
+
};
|
|
247
|
+
return fn(Zeus(operation, o, {
|
|
248
|
+
operationOptions: ops,
|
|
249
|
+
scalars: options?.scalars,
|
|
250
|
+
}), ops?.variables).then((data) => {
|
|
251
|
+
if (options?.scalars) {
|
|
252
|
+
return decodeScalarsInResponse({
|
|
253
|
+
response: data,
|
|
254
|
+
initialOp: operation,
|
|
255
|
+
initialZeusQuery: o,
|
|
256
|
+
returns: ReturnTypes,
|
|
257
|
+
scalars: options.scalars,
|
|
258
|
+
ops: Ops,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
return data;
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
export const Chain = (...options) => Thunder(apiFetch(options));
|
|
265
|
+
export const SubscriptionThunder = (fn, thunderGraphQLOptions) => (operation, graphqlOptions) => (o, ops) => {
|
|
266
|
+
const options = {
|
|
267
|
+
...thunderGraphQLOptions,
|
|
268
|
+
...graphqlOptions,
|
|
269
|
+
};
|
|
270
|
+
const returnedFunction = fn(Zeus(operation, o, {
|
|
271
|
+
operationOptions: ops,
|
|
272
|
+
scalars: options?.scalars,
|
|
273
|
+
}));
|
|
274
|
+
if (returnedFunction?.on && options?.scalars) {
|
|
275
|
+
const wrapped = returnedFunction.on;
|
|
276
|
+
returnedFunction.on = (fnToCall) => wrapped((data) => {
|
|
277
|
+
if (options?.scalars) {
|
|
278
|
+
return fnToCall(decodeScalarsInResponse({
|
|
279
|
+
response: data,
|
|
280
|
+
initialOp: operation,
|
|
281
|
+
initialZeusQuery: o,
|
|
282
|
+
returns: ReturnTypes,
|
|
283
|
+
scalars: options.scalars,
|
|
284
|
+
ops: Ops,
|
|
285
|
+
}));
|
|
286
|
+
}
|
|
287
|
+
return fnToCall(data);
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
return returnedFunction;
|
|
291
|
+
};
|
|
292
|
+
export const Subscription = (...options) => SubscriptionThunder(apiSubscription(options));
|
|
293
|
+
export const SubscriptionThunderSSE = (fn, thunderGraphQLOptions) => (operation, graphqlOptions) => (o, ops) => {
|
|
294
|
+
const options = {
|
|
295
|
+
...thunderGraphQLOptions,
|
|
296
|
+
...graphqlOptions,
|
|
297
|
+
};
|
|
298
|
+
const returnedFunction = fn(Zeus(operation, o, {
|
|
299
|
+
operationOptions: ops,
|
|
300
|
+
scalars: options?.scalars,
|
|
301
|
+
}), ops?.variables);
|
|
302
|
+
if (returnedFunction?.on && options?.scalars) {
|
|
303
|
+
const wrapped = returnedFunction.on;
|
|
304
|
+
returnedFunction.on = (fnToCall) => wrapped((data) => {
|
|
305
|
+
if (options?.scalars) {
|
|
306
|
+
return fnToCall(decodeScalarsInResponse({
|
|
307
|
+
response: data,
|
|
308
|
+
initialOp: operation,
|
|
309
|
+
initialZeusQuery: o,
|
|
310
|
+
returns: ReturnTypes,
|
|
311
|
+
scalars: options.scalars,
|
|
312
|
+
ops: Ops,
|
|
313
|
+
}));
|
|
314
|
+
}
|
|
315
|
+
return fnToCall(data);
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
return returnedFunction;
|
|
319
|
+
};
|
|
320
|
+
export const SubscriptionSSE = (...options) => SubscriptionThunderSSE(apiSubscriptionSSE(options));
|
|
321
|
+
export const Zeus = (operation, o, ops) => InternalsBuildQuery({
|
|
322
|
+
props: AllTypesProps,
|
|
323
|
+
returns: ReturnTypes,
|
|
324
|
+
ops: Ops,
|
|
325
|
+
options: ops?.operationOptions,
|
|
326
|
+
scalars: ops?.scalars,
|
|
327
|
+
})(operation, o);
|
|
328
|
+
export const ZeusSelect = () => ((t) => t);
|
|
329
|
+
export const Selector = (key) => key && ZeusSelect();
|
|
330
|
+
export const TypeFromSelector = (key) => key && ZeusSelect();
|
|
331
|
+
export const Gql = Chain(HOST, {
|
|
332
|
+
headers: {
|
|
333
|
+
'Content-Type': 'application/json',
|
|
334
|
+
...HEADERS,
|
|
335
|
+
},
|
|
336
|
+
});
|
|
337
|
+
export const ZeusScalars = ZeusSelect();
|
|
338
|
+
export const fields = (k) => {
|
|
339
|
+
const t = ReturnTypes[k];
|
|
340
|
+
const fnType = k in AllTypesProps ? AllTypesProps[k] : undefined;
|
|
341
|
+
const hasFnTypes = typeof fnType === 'object' ? fnType : undefined;
|
|
342
|
+
const o = Object.fromEntries(Object.entries(t)
|
|
343
|
+
.filter(([k, value]) => {
|
|
344
|
+
const isFunctionType = hasFnTypes && k in hasFnTypes && !!hasFnTypes[k];
|
|
345
|
+
if (isFunctionType)
|
|
346
|
+
return false;
|
|
347
|
+
const isReturnType = ReturnTypes[value];
|
|
348
|
+
if (!isReturnType)
|
|
349
|
+
return true;
|
|
350
|
+
if (typeof isReturnType !== 'string')
|
|
351
|
+
return false;
|
|
352
|
+
if (isReturnType.startsWith('scalar.')) {
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
355
|
+
return false;
|
|
356
|
+
})
|
|
357
|
+
.map(([key]) => [key, true]));
|
|
358
|
+
return o;
|
|
359
|
+
};
|
|
360
|
+
export const decodeScalarsInResponse = ({ response, scalars, returns, ops, initialZeusQuery, initialOp, }) => {
|
|
361
|
+
if (!scalars) {
|
|
362
|
+
return response;
|
|
363
|
+
}
|
|
364
|
+
const builder = PrepareScalarPaths({
|
|
365
|
+
ops,
|
|
366
|
+
returns,
|
|
367
|
+
});
|
|
368
|
+
const scalarPaths = builder(initialOp, ops[initialOp], initialZeusQuery);
|
|
369
|
+
if (scalarPaths) {
|
|
370
|
+
const r = traverseResponse({ scalarPaths, resolvers: scalars })(initialOp, response, [ops[initialOp]]);
|
|
371
|
+
return r;
|
|
372
|
+
}
|
|
373
|
+
return response;
|
|
374
|
+
};
|
|
375
|
+
export const traverseResponse = ({ resolvers, scalarPaths, }) => {
|
|
376
|
+
const ibb = (k, o, p = []) => {
|
|
377
|
+
if (Array.isArray(o)) {
|
|
378
|
+
return o.map((eachO) => ibb(k, eachO, p));
|
|
379
|
+
}
|
|
380
|
+
if (o == null) {
|
|
381
|
+
return o;
|
|
382
|
+
}
|
|
383
|
+
const scalarPathString = p.join(SEPARATOR);
|
|
384
|
+
const currentScalarString = scalarPaths[scalarPathString];
|
|
385
|
+
if (currentScalarString) {
|
|
386
|
+
const currentDecoder = resolvers[currentScalarString.split('.')[1]]?.decode;
|
|
387
|
+
if (currentDecoder) {
|
|
388
|
+
return currentDecoder(o);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (typeof o === 'boolean' || typeof o === 'number' || typeof o === 'string' || !o) {
|
|
392
|
+
return o;
|
|
393
|
+
}
|
|
394
|
+
const entries = Object.entries(o).map(([k, v]) => [k, ibb(k, v, [...p, purifyGraphQLKey(k)])]);
|
|
395
|
+
const objectFromEntries = entries.reduce((a, [k, v]) => {
|
|
396
|
+
a[k] = v;
|
|
397
|
+
return a;
|
|
398
|
+
}, {});
|
|
399
|
+
return objectFromEntries;
|
|
400
|
+
};
|
|
401
|
+
return ibb;
|
|
402
|
+
};
|
|
403
|
+
export const SEPARATOR = '|';
|
|
404
|
+
export class GraphQLError extends Error {
|
|
405
|
+
response;
|
|
406
|
+
constructor(response) {
|
|
407
|
+
super(response.errors?.[0]?.message || 'GraphQL Response Error');
|
|
408
|
+
this.response = response;
|
|
409
|
+
console.error(response);
|
|
410
|
+
}
|
|
411
|
+
toString() {
|
|
412
|
+
return 'GraphQL Response Error';
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
const ExtractScalar = (mappedParts, returns) => {
|
|
416
|
+
if (mappedParts.length === 0) {
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
const oKey = mappedParts[0];
|
|
420
|
+
const returnP1 = returns[oKey];
|
|
421
|
+
if (typeof returnP1 === 'object') {
|
|
422
|
+
const returnP2 = returnP1[mappedParts[1]];
|
|
423
|
+
if (returnP2) {
|
|
424
|
+
return ExtractScalar([returnP2, ...mappedParts.slice(2)], returns);
|
|
425
|
+
}
|
|
426
|
+
return undefined;
|
|
427
|
+
}
|
|
428
|
+
return returnP1;
|
|
429
|
+
};
|
|
430
|
+
export const PrepareScalarPaths = ({ ops, returns }) => {
|
|
431
|
+
const ibb = (k, originalKey, o, p = [], pOriginals = [], root = true) => {
|
|
432
|
+
if (!o) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
if (typeof o === 'boolean' || typeof o === 'number' || typeof o === 'string') {
|
|
436
|
+
const extractionArray = [...pOriginals, originalKey];
|
|
437
|
+
const isScalar = ExtractScalar(extractionArray, returns);
|
|
438
|
+
if (isScalar?.startsWith('scalar')) {
|
|
439
|
+
const partOfTree = {
|
|
440
|
+
[[...p, k].join(SEPARATOR)]: isScalar,
|
|
441
|
+
};
|
|
442
|
+
return partOfTree;
|
|
443
|
+
}
|
|
444
|
+
return {};
|
|
445
|
+
}
|
|
446
|
+
if (Array.isArray(o)) {
|
|
447
|
+
return ibb(k, k, o[1], p, pOriginals, false);
|
|
448
|
+
}
|
|
449
|
+
if (k === '__alias') {
|
|
450
|
+
return Object.entries(o)
|
|
451
|
+
.map(([alias, objectUnderAlias]) => {
|
|
452
|
+
if (typeof objectUnderAlias !== 'object' || Array.isArray(objectUnderAlias)) {
|
|
453
|
+
throw new Error('Invalid alias it should be __alias:{ YOUR_ALIAS_NAME: { OPERATION_NAME: { ...selectors }}}');
|
|
454
|
+
}
|
|
455
|
+
const operationName = Object.keys(objectUnderAlias)[0];
|
|
456
|
+
const operation = objectUnderAlias[operationName];
|
|
457
|
+
return ibb(alias, operationName, operation, p, pOriginals, false);
|
|
458
|
+
})
|
|
459
|
+
.reduce((a, b) => ({
|
|
460
|
+
...a,
|
|
461
|
+
...b,
|
|
462
|
+
}));
|
|
463
|
+
}
|
|
464
|
+
const keyName = root ? ops[k] : k;
|
|
465
|
+
return Object.entries(o)
|
|
466
|
+
.filter(([k]) => k !== '__directives')
|
|
467
|
+
.map(([k, v]) => {
|
|
468
|
+
// Inline fragments shouldn't be added to the path as they aren't a field
|
|
469
|
+
const isInlineFragment = originalKey.match(/^...\s*on/) != null;
|
|
470
|
+
return ibb(k, k, v, isInlineFragment ? p : [...p, purifyGraphQLKey(keyName || k)], isInlineFragment ? pOriginals : [...pOriginals, purifyGraphQLKey(originalKey)], false);
|
|
471
|
+
})
|
|
472
|
+
.reduce((a, b) => ({
|
|
473
|
+
...a,
|
|
474
|
+
...b,
|
|
475
|
+
}));
|
|
476
|
+
};
|
|
477
|
+
return ibb;
|
|
478
|
+
};
|
|
479
|
+
export const purifyGraphQLKey = (k) => k.replace(/\([^)]*\)/g, '').replace(/^[^:]*\:/g, '');
|
|
480
|
+
const mapPart = (p) => {
|
|
481
|
+
const [isArg, isField] = p.split('<>');
|
|
482
|
+
if (isField) {
|
|
483
|
+
return {
|
|
484
|
+
v: isField,
|
|
485
|
+
__type: 'field',
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
return {
|
|
489
|
+
v: isArg,
|
|
490
|
+
__type: 'arg',
|
|
491
|
+
};
|
|
492
|
+
};
|
|
493
|
+
export const ResolveFromPath = (props, returns, ops) => {
|
|
494
|
+
const ResolvePropsType = (mappedParts) => {
|
|
495
|
+
const oKey = ops[mappedParts[0].v];
|
|
496
|
+
const propsP1 = oKey ? props[oKey] : props[mappedParts[0].v];
|
|
497
|
+
if (propsP1 === 'enum' && mappedParts.length === 1) {
|
|
498
|
+
return 'enum';
|
|
499
|
+
}
|
|
500
|
+
if (typeof propsP1 === 'string' && propsP1.startsWith('scalar.') && mappedParts.length === 1) {
|
|
501
|
+
return propsP1;
|
|
502
|
+
}
|
|
503
|
+
if (typeof propsP1 === 'object') {
|
|
504
|
+
if (mappedParts.length < 2) {
|
|
505
|
+
return 'not';
|
|
506
|
+
}
|
|
507
|
+
const propsP2 = propsP1[mappedParts[1].v];
|
|
508
|
+
if (typeof propsP2 === 'string') {
|
|
509
|
+
return rpp(`${propsP2}${SEPARATOR}${mappedParts
|
|
510
|
+
.slice(2)
|
|
511
|
+
.map((mp) => mp.v)
|
|
512
|
+
.join(SEPARATOR)}`);
|
|
513
|
+
}
|
|
514
|
+
if (typeof propsP2 === 'object') {
|
|
515
|
+
if (mappedParts.length < 3) {
|
|
516
|
+
return 'not';
|
|
517
|
+
}
|
|
518
|
+
const propsP3 = propsP2[mappedParts[2].v];
|
|
519
|
+
if (propsP3 && mappedParts[2].__type === 'arg') {
|
|
520
|
+
return rpp(`${propsP3}${SEPARATOR}${mappedParts
|
|
521
|
+
.slice(3)
|
|
522
|
+
.map((mp) => mp.v)
|
|
523
|
+
.join(SEPARATOR)}`);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
const ResolveReturnType = (mappedParts) => {
|
|
529
|
+
if (mappedParts.length === 0) {
|
|
530
|
+
return 'not';
|
|
531
|
+
}
|
|
532
|
+
const oKey = ops[mappedParts[0].v];
|
|
533
|
+
const returnP1 = oKey ? returns[oKey] : returns[mappedParts[0].v];
|
|
534
|
+
if (typeof returnP1 === 'object') {
|
|
535
|
+
if (mappedParts.length < 2)
|
|
536
|
+
return 'not';
|
|
537
|
+
const returnP2 = returnP1[mappedParts[1].v];
|
|
538
|
+
if (returnP2) {
|
|
539
|
+
return rpp(`${returnP2}${SEPARATOR}${mappedParts
|
|
540
|
+
.slice(2)
|
|
541
|
+
.map((mp) => mp.v)
|
|
542
|
+
.join(SEPARATOR)}`);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
const rpp = (path) => {
|
|
547
|
+
const parts = path.split(SEPARATOR).filter((l) => l.length > 0);
|
|
548
|
+
const mappedParts = parts.map(mapPart);
|
|
549
|
+
const propsP1 = ResolvePropsType(mappedParts);
|
|
550
|
+
if (propsP1) {
|
|
551
|
+
return propsP1;
|
|
552
|
+
}
|
|
553
|
+
const returnP1 = ResolveReturnType(mappedParts);
|
|
554
|
+
if (returnP1) {
|
|
555
|
+
return returnP1;
|
|
556
|
+
}
|
|
557
|
+
return 'not';
|
|
558
|
+
};
|
|
559
|
+
return rpp;
|
|
560
|
+
};
|
|
561
|
+
export const InternalArgsBuilt = ({ props, ops, returns, scalars, vars, }) => {
|
|
562
|
+
const arb = (a, p = '', root = true) => {
|
|
563
|
+
if (typeof a === 'string') {
|
|
564
|
+
if (a.startsWith(START_VAR_NAME)) {
|
|
565
|
+
const [varName, graphQLType] = a.replace(START_VAR_NAME, '$').split(GRAPHQL_TYPE_SEPARATOR);
|
|
566
|
+
const v = vars.find((v) => v.name === varName);
|
|
567
|
+
if (!v) {
|
|
568
|
+
vars.push({
|
|
569
|
+
name: varName,
|
|
570
|
+
graphQLType,
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
else {
|
|
574
|
+
if (v.graphQLType !== graphQLType) {
|
|
575
|
+
throw new Error(`Invalid variable exists with two different GraphQL Types, "${v.graphQLType}" and ${graphQLType}`);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
return varName;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
const checkType = ResolveFromPath(props, returns, ops)(p);
|
|
582
|
+
if (checkType.startsWith('scalar.')) {
|
|
583
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
584
|
+
const [_, ...splittedScalar] = checkType.split('.');
|
|
585
|
+
const scalarKey = splittedScalar.join('.');
|
|
586
|
+
return scalars?.[scalarKey]?.encode?.(a) || JSON.stringify(a);
|
|
587
|
+
}
|
|
588
|
+
if (Array.isArray(a)) {
|
|
589
|
+
return `[${a.map((arr) => arb(arr, p, false)).join(', ')}]`;
|
|
590
|
+
}
|
|
591
|
+
if (typeof a === 'string') {
|
|
592
|
+
if (checkType === 'enum') {
|
|
593
|
+
return a;
|
|
594
|
+
}
|
|
595
|
+
return `${JSON.stringify(a)}`;
|
|
596
|
+
}
|
|
597
|
+
if (typeof a === 'object') {
|
|
598
|
+
if (a === null) {
|
|
599
|
+
return `null`;
|
|
600
|
+
}
|
|
601
|
+
const returnedObjectString = Object.entries(a)
|
|
602
|
+
.filter(([, v]) => typeof v !== 'undefined')
|
|
603
|
+
.map(([k, v]) => `${k}: ${arb(v, [p, k].join(SEPARATOR), false)}`)
|
|
604
|
+
.join(',\n');
|
|
605
|
+
if (!root) {
|
|
606
|
+
return `{${returnedObjectString}}`;
|
|
607
|
+
}
|
|
608
|
+
return returnedObjectString;
|
|
609
|
+
}
|
|
610
|
+
return `${a}`;
|
|
611
|
+
};
|
|
612
|
+
return arb;
|
|
613
|
+
};
|
|
614
|
+
export const resolverFor = (_type, _field, fn) => fn;
|
|
615
|
+
export const START_VAR_NAME = `$ZEUS_VAR`;
|
|
616
|
+
export const GRAPHQL_TYPE_SEPARATOR = `__$GRAPHQL__`;
|
|
617
|
+
export const $ = (name, graphqlType) => {
|
|
618
|
+
return (START_VAR_NAME + name + GRAPHQL_TYPE_SEPARATOR + graphqlType);
|
|
619
|
+
};
|
|
620
|
+
export var GlobalRole;
|
|
621
|
+
(function (GlobalRole) {
|
|
622
|
+
GlobalRole["ADMIN"] = "ADMIN";
|
|
623
|
+
GlobalRole["MAINTAINER"] = "MAINTAINER";
|
|
624
|
+
})(GlobalRole || (GlobalRole = {}));
|
|
625
|
+
export var TeamRole;
|
|
626
|
+
(function (TeamRole) {
|
|
627
|
+
TeamRole["OWNER"] = "OWNER";
|
|
628
|
+
TeamRole["MODERATOR"] = "MODERATOR";
|
|
629
|
+
TeamRole["MEMBER"] = "MEMBER";
|
|
630
|
+
})(TeamRole || (TeamRole = {}));
|
|
631
|
+
export var TeamUsageTaskType;
|
|
632
|
+
(function (TeamUsageTaskType) {
|
|
633
|
+
TeamUsageTaskType["INFERENCE"] = "INFERENCE";
|
|
634
|
+
TeamUsageTaskType["FROM"] = "FROM";
|
|
635
|
+
TeamUsageTaskType["AGENT"] = "AGENT";
|
|
636
|
+
})(TeamUsageTaskType || (TeamUsageTaskType = {}));
|
|
637
|
+
export var TeamInviteStatus;
|
|
638
|
+
(function (TeamInviteStatus) {
|
|
639
|
+
TeamInviteStatus["ACTIVE"] = "ACTIVE";
|
|
640
|
+
TeamInviteStatus["EXPIRED"] = "EXPIRED";
|
|
641
|
+
TeamInviteStatus["ACCEPTED"] = "ACCEPTED";
|
|
642
|
+
TeamInviteStatus["REVOKED"] = "REVOKED";
|
|
643
|
+
})(TeamInviteStatus || (TeamInviteStatus = {}));
|
|
644
|
+
export var ProjectAccess;
|
|
645
|
+
(function (ProjectAccess) {
|
|
646
|
+
ProjectAccess["OWNER"] = "OWNER";
|
|
647
|
+
ProjectAccess["WRITE"] = "WRITE";
|
|
648
|
+
ProjectAccess["READ"] = "READ";
|
|
649
|
+
})(ProjectAccess || (ProjectAccess = {}));
|
|
650
|
+
export var PresetScope;
|
|
651
|
+
(function (PresetScope) {
|
|
652
|
+
PresetScope["TEAM"] = "TEAM";
|
|
653
|
+
PresetScope["PROJECT"] = "PROJECT";
|
|
654
|
+
})(PresetScope || (PresetScope = {}));
|
|
655
|
+
export var PresetCategory;
|
|
656
|
+
(function (PresetCategory) {
|
|
657
|
+
PresetCategory["PR"] = "PR";
|
|
658
|
+
PresetCategory["ANALYSIS"] = "ANALYSIS";
|
|
659
|
+
PresetCategory["OPTIONS"] = "OPTIONS";
|
|
660
|
+
PresetCategory["SAFE"] = "SAFE";
|
|
661
|
+
PresetCategory["MAP"] = "MAP";
|
|
662
|
+
PresetCategory["EMERGENCY"] = "EMERGENCY";
|
|
663
|
+
})(PresetCategory || (PresetCategory = {}));
|
|
664
|
+
export var CostTier;
|
|
665
|
+
(function (CostTier) {
|
|
666
|
+
CostTier["LOW"] = "LOW";
|
|
667
|
+
CostTier["MEDIUM"] = "MEDIUM";
|
|
668
|
+
CostTier["HIGH"] = "HIGH";
|
|
669
|
+
CostTier["VERY_HIGH"] = "VERY_HIGH";
|
|
670
|
+
})(CostTier || (CostTier = {}));
|
|
671
|
+
export var RiskLevel;
|
|
672
|
+
(function (RiskLevel) {
|
|
673
|
+
RiskLevel["LOW"] = "LOW";
|
|
674
|
+
RiskLevel["MEDIUM"] = "MEDIUM";
|
|
675
|
+
RiskLevel["HIGH"] = "HIGH";
|
|
676
|
+
})(RiskLevel || (RiskLevel = {}));
|
|
677
|
+
export var LanguageTag;
|
|
678
|
+
(function (LanguageTag) {
|
|
679
|
+
LanguageTag["TYPESCRIPT"] = "TYPESCRIPT";
|
|
680
|
+
LanguageTag["JAVASCRIPT"] = "JAVASCRIPT";
|
|
681
|
+
LanguageTag["PYTHON"] = "PYTHON";
|
|
682
|
+
LanguageTag["RUST"] = "RUST";
|
|
683
|
+
LanguageTag["GO"] = "GO";
|
|
684
|
+
LanguageTag["JAVA"] = "JAVA";
|
|
685
|
+
LanguageTag["KOTLIN"] = "KOTLIN";
|
|
686
|
+
LanguageTag["SWIFT"] = "SWIFT";
|
|
687
|
+
LanguageTag["RUBY"] = "RUBY";
|
|
688
|
+
LanguageTag["PHP"] = "PHP";
|
|
689
|
+
LanguageTag["CSHARP"] = "CSHARP";
|
|
690
|
+
LanguageTag["CPP"] = "CPP";
|
|
691
|
+
LanguageTag["ELIXIR"] = "ELIXIR";
|
|
692
|
+
LanguageTag["SCALA"] = "SCALA";
|
|
693
|
+
LanguageTag["DART"] = "DART";
|
|
694
|
+
LanguageTag["ZIG"] = "ZIG";
|
|
695
|
+
})(LanguageTag || (LanguageTag = {}));
|
|
696
|
+
export var PresetSource;
|
|
697
|
+
(function (PresetSource) {
|
|
698
|
+
PresetSource["SYSTEM"] = "SYSTEM";
|
|
699
|
+
PresetSource["USER"] = "USER";
|
|
700
|
+
})(PresetSource || (PresetSource = {}));
|
|
701
|
+
export var AgentMode;
|
|
702
|
+
(function (AgentMode) {
|
|
703
|
+
AgentMode["SUBAGENT"] = "SUBAGENT";
|
|
704
|
+
AgentMode["PRIMARY"] = "PRIMARY";
|
|
705
|
+
})(AgentMode || (AgentMode = {}));
|
|
706
|
+
export var AgentSource;
|
|
707
|
+
(function (AgentSource) {
|
|
708
|
+
AgentSource["SYSTEM"] = "SYSTEM";
|
|
709
|
+
AgentSource["USER"] = "USER";
|
|
710
|
+
})(AgentSource || (AgentSource = {}));
|
|
711
|
+
export var LeadType;
|
|
712
|
+
(function (LeadType) {
|
|
713
|
+
LeadType["SELF_SERVE_TRIAL"] = "SELF_SERVE_TRIAL";
|
|
714
|
+
LeadType["SALES_ASSISTED_DEMO"] = "SALES_ASSISTED_DEMO";
|
|
715
|
+
})(LeadType || (LeadType = {}));
|
|
716
|
+
export var LeadStatus;
|
|
717
|
+
(function (LeadStatus) {
|
|
718
|
+
LeadStatus["NEW"] = "NEW";
|
|
719
|
+
LeadStatus["CONTACTED"] = "CONTACTED";
|
|
720
|
+
LeadStatus["QUALIFIED"] = "QUALIFIED";
|
|
721
|
+
LeadStatus["WON"] = "WON";
|
|
722
|
+
LeadStatus["LOST"] = "LOST";
|
|
723
|
+
})(LeadStatus || (LeadStatus = {}));
|
|
724
|
+
export var LeadEventType;
|
|
725
|
+
(function (LeadEventType) {
|
|
726
|
+
LeadEventType["CREATED"] = "CREATED";
|
|
727
|
+
LeadEventType["STATUS_CHANGED"] = "STATUS_CHANGED";
|
|
728
|
+
LeadEventType["NOTE_ADDED"] = "NOTE_ADDED";
|
|
729
|
+
LeadEventType["ASSIGNED"] = "ASSIGNED";
|
|
730
|
+
LeadEventType["UTM_UPDATED"] = "UTM_UPDATED";
|
|
731
|
+
})(LeadEventType || (LeadEventType = {}));
|
|
732
|
+
export var InferenceStatus;
|
|
733
|
+
(function (InferenceStatus) {
|
|
734
|
+
InferenceStatus["PENDING"] = "PENDING";
|
|
735
|
+
InferenceStatus["RUNNING"] = "RUNNING";
|
|
736
|
+
InferenceStatus["COMPLETED"] = "COMPLETED";
|
|
737
|
+
InferenceStatus["FAILED"] = "FAILED";
|
|
738
|
+
InferenceStatus["CANCELLED"] = "CANCELLED";
|
|
739
|
+
})(InferenceStatus || (InferenceStatus = {}));
|
|
740
|
+
export var ArtifactType;
|
|
741
|
+
(function (ArtifactType) {
|
|
742
|
+
ArtifactType["GRAPHQL"] = "GRAPHQL";
|
|
743
|
+
ArtifactType["FRONTEND"] = "FRONTEND";
|
|
744
|
+
ArtifactType["E2E"] = "E2E";
|
|
745
|
+
ArtifactType["BACKEND"] = "BACKEND";
|
|
746
|
+
})(ArtifactType || (ArtifactType = {}));
|
|
747
|
+
export var ModelApiFormat;
|
|
748
|
+
(function (ModelApiFormat) {
|
|
749
|
+
ModelApiFormat["AUTO"] = "AUTO";
|
|
750
|
+
ModelApiFormat["CHAT_COMPLETIONS"] = "CHAT_COMPLETIONS";
|
|
751
|
+
ModelApiFormat["RESPONSES"] = "RESPONSES";
|
|
752
|
+
})(ModelApiFormat || (ModelApiFormat = {}));
|
|
753
|
+
export var ConnectedAccountProvider;
|
|
754
|
+
(function (ConnectedAccountProvider) {
|
|
755
|
+
ConnectedAccountProvider["OPENAI"] = "OPENAI";
|
|
756
|
+
})(ConnectedAccountProvider || (ConnectedAccountProvider = {}));
|
|
757
|
+
export var SubscriptionStatus;
|
|
758
|
+
(function (SubscriptionStatus) {
|
|
759
|
+
SubscriptionStatus["ACTIVE"] = "ACTIVE";
|
|
760
|
+
SubscriptionStatus["CANCELED"] = "CANCELED";
|
|
761
|
+
SubscriptionStatus["PAST_DUE"] = "PAST_DUE";
|
|
762
|
+
SubscriptionStatus["INCOMPLETE"] = "INCOMPLETE";
|
|
763
|
+
SubscriptionStatus["TRIALING"] = "TRIALING";
|
|
764
|
+
SubscriptionStatus["INACTIVE"] = "INACTIVE";
|
|
765
|
+
})(SubscriptionStatus || (SubscriptionStatus = {}));
|
|
766
|
+
export var DedicatedEndpointStatus;
|
|
767
|
+
(function (DedicatedEndpointStatus) {
|
|
768
|
+
DedicatedEndpointStatus["NONE"] = "NONE";
|
|
769
|
+
DedicatedEndpointStatus["PENDING"] = "PENDING";
|
|
770
|
+
DedicatedEndpointStatus["STARTING"] = "STARTING";
|
|
771
|
+
DedicatedEndpointStatus["STARTED"] = "STARTED";
|
|
772
|
+
DedicatedEndpointStatus["STOPPING"] = "STOPPING";
|
|
773
|
+
DedicatedEndpointStatus["STOPPED"] = "STOPPED";
|
|
774
|
+
DedicatedEndpointStatus["ERROR"] = "ERROR";
|
|
775
|
+
})(DedicatedEndpointStatus || (DedicatedEndpointStatus = {}));
|
|
776
|
+
export var FineTuneStatus;
|
|
777
|
+
(function (FineTuneStatus) {
|
|
778
|
+
FineTuneStatus["PENDING"] = "PENDING";
|
|
779
|
+
FineTuneStatus["GENERATING_DATASET"] = "GENERATING_DATASET";
|
|
780
|
+
FineTuneStatus["FILTERING_DATASET"] = "FILTERING_DATASET";
|
|
781
|
+
FineTuneStatus["UPLOADING_DATASET"] = "UPLOADING_DATASET";
|
|
782
|
+
FineTuneStatus["TRAINING"] = "TRAINING";
|
|
783
|
+
FineTuneStatus["COMPLETED"] = "COMPLETED";
|
|
784
|
+
FineTuneStatus["FAILED"] = "FAILED";
|
|
785
|
+
FineTuneStatus["CANCELLED"] = "CANCELLED";
|
|
786
|
+
})(FineTuneStatus || (FineTuneStatus = {}));
|
|
787
|
+
export var ModelScope;
|
|
788
|
+
(function (ModelScope) {
|
|
789
|
+
ModelScope["STUDIO"] = "STUDIO";
|
|
790
|
+
ModelScope["AGENT"] = "AGENT";
|
|
791
|
+
})(ModelScope || (ModelScope = {}));
|