MCPcopy Create free account
hub / github.com/GordonChen19/Prompt-Relay / parseCardModelOptions

Function parseCardModelOptions

static/js/index.js:35–69  ·  view source on GitHub ↗
(card)

Source from the content-addressed store, hash-verified

33 };
34
35 const parseCardModelOptions = (card) => {
36 const raw = card.dataset.modelConfig;
37 if (!raw) {
38 return defaultModelOptions;
39 }
40
41 try {
42 const parsed = JSON.parse(raw);
43 if (!Array.isArray(parsed)) {
44 return defaultModelOptions;
45 }
46
47 const seen = new Set();
48 const options = parsed
49 .filter((item) => item && typeof item === 'object')
50 .map((item) => {
51 const key = normalizeModelKey(item.key || item.label);
52 const label = String(item.label || item.key || '').trim();
53 return { key, label };
54 })
55 .filter((item) => item.key && item.label)
56 .filter((item) => {
57 if (seen.has(item.key)) {
58 return false;
59 }
60 seen.add(item.key);
61 return true;
62 });
63
64 return options.length > 0 ? options : defaultModelOptions;
65 } catch (error) {
66 console.warn('Invalid model configuration on card:', error);
67 return defaultModelOptions;
68 }
69 };
70
71 const getCardModelSource = (card, modelKey) => {
72 return card.getAttribute(`data-model-${modelKey}`);

Callers 1

index.jsFile · 0.85

Calls 1

normalizeModelKeyFunction · 0.85

Tested by

no test coverage detected