aboutsummaryrefslogtreecommitdiffstats
path: root/public/app.js
blob: d780e5ae3deb29a9f49e82e2bb3f0d19cab118af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
"use strict";

let registry = [];
let champions = [];

const sectorUseCases = {
  tourism: [
    {
      title: "Supplier and booking request routing",
      description: "Classify multilingual requests, retrieve the relevant reservation or supplier record, and route the proposed action to a staff member for approval.",
      tasks: ["agent"]
    },
    {
      title: "Disruption triage across properties",
      description: "Coordinate cancellations, late arrivals, maintenance incidents, and supplier disruptions across shared property systems.",
      tasks: ["agent"]
    },
    {
      title: "Multilingual service operations",
      description: "Summarise incoming messages, retain citations to the original request, and prepare a reviewed response in the guest or supplier language.",
      tasks: ["docs", "agent"]
    }
  ],
  manufacturing: [
    {
      title: "Human-supervised visual quality inspection",
      description: "Flag likely defects on the production line while keeping acceptance and rejection decisions with trained operators.",
      tasks: ["vision"]
    },
    {
      title: "Inspection evidence and rework analysis",
      description: "Link inspection images to acceptance criteria and production records to identify repeat causes of rework.",
      tasks: ["docs"]
    }
  ],
  logistics: [
    {
      title: "Shipment exception routing",
      description: "Detect delayed or incomplete shipments and assign each case to the correct operational team with an auditable reason.",
      tasks: ["agent"]
    },
    {
      title: "Freight document triage",
      description: "Classify multilingual freight documents, identify missing evidence, and prepare cases for human review.",
      tasks: ["docs"]
    }
  ],
  public: [
    {
      title: "Citation-backed permit review",
      description: "Retrieve the applicable rules and evidence for a permit case while leaving the accountable decision with a public official.",
      tasks: ["docs"]
    },
    {
      title: "Case-file completeness checks",
      description: "Identify missing documents and conflicting information before a case enters the formal assessment workflow.",
      tasks: ["docs", "agent"]
    }
  ]
};

const labels = {
  task: { all: "Any capability", docs: "Document intelligence", audio: "Speech transcription", vision: "Visual inspection", agent: "Workflow agent" },
  sector: { tourism: "Tourism and hospitality", manufacturing: "Manufacturing", logistics: "Transport and logistics", public: "Public services" },
  deployment: { all: "Any verified deployment", local: "Company-controlled infrastructure", eu: "Managed inference in the EU" },
  language: { all: "Any language", multi: "Multilingual", fr: "French", nl: "Dutch", de: "German" },
  assurance: { standard: "Standard business use", sensitive: "Sensitive operational data" }
};

const form = document.querySelector("#search-form");
const task = document.querySelector("#task");
const sector = document.querySelector("#sector");
const deployment = document.querySelector("#deployment");
const language = document.querySelector("#language");
const assurance = document.querySelector("#assurance");
const requirement = document.querySelector("#requirement");
const results = document.querySelector("#results");
const resultCount = document.querySelector("#result-count");
const championRecommendationsPanel = document.querySelector("#champion-recommendations");
const brief = document.querySelector("#build-brief");
const actionMessage = document.querySelector("#action-message");

function valueLabel(group, value) {
  return labels[group][value] || value;
}

function escapeHtml(value) {
  return String(value).replace(/[&<>"']/g, character => ({
    "&": "&amp;",
    "<": "&lt;",
    ">": "&gt;",
    "\"": "&quot;",
    "'": "&#039;"
  })[character]);
}

function findMatches() {
  return registry.filter(tool =>
    (task.value === "all" || tool.tasks.includes(task.value)) &&
    (deployment.value === "all" || tool.deployment.includes(deployment.value)) &&
    (language.value === "all" || tool.languages.includes(language.value)) &&
    tool.assurance.includes(assurance.value)
  );
}

function recommendedChampions() {
  const exact = champions.filter(champion => champion.sectors.includes(sector.value) && (task.value === "all" || champion.tasks.includes(task.value)));
  const related = champions.filter(champion =>
    !exact.includes(champion) &&
    (champion.sectors.includes(sector.value) || task.value === "all" || champion.tasks.includes(task.value))
  );
  return [...exact, ...related].slice(0, 2);
}

function moreUseCases() {
  const useCases = sectorUseCases[sector.value] || [];
  return `<details class="champion-more-use-cases">
    <summary><span>Show more use cases</span><small>${useCases.length} in this sector</small></summary>
    <div class="champion-use-case-list">
      ${useCases.map(useCase => `<article>
        <strong>${useCase.title}</strong>
        <p>${useCase.description}</p>
      </article>`).join("")}
    </div>
  </details>`;
}

function championRecommendations() {
  const recommendations = recommendedChampions();
  const capabilityLabel = valueLabel("task", task.value);
  const sectorLabel = valueLabel("sector", sector.value);
  const requirementText = requirement.value.trim() || "Define the operational problem this tool should address.";
  return `<section class="champion-section" aria-labelledby="champion-title">
    <div class="panel-heading champion-panel-heading">
      <span class="step">03</span>
      <div>
        <h2 id="champion-title">Implementation champions</h2>
        <p>${recommendations.length} source-backed recommendations</p>
      </div>
    </div>
    <div class="champion-use-case">
      <span>Use case</span>
      <strong>${escapeHtml(capabilityLabel)} for ${escapeHtml(sectorLabel)}</strong>
      <p>${escapeHtml(requirementText)}</p>
    </div>
    ${moreUseCases()}
    <p class="champion-intro">European organizations with a named public implementation reference. Open the source to assess transferability.</p>
    <div class="champion-list">${recommendations.map((champion, index) => `
      <article class="champion-row">
        <div class="champion-company"><strong>${champion.company}</strong><span>${champion.country}</span></div>
        <div class="champion-detail"><strong>${champion.implementation}</strong><span>${champion.evidence.publisher} · ${champion.evidence.level === "case_study" ? "case study" : "public reference"}</span></div>
        <div class="champion-outcome">${champion.outcome}</div>
        <a class="champion-action" href="${champion.evidence.url}" target="_blank" rel="noreferrer" data-champion="${index}">View evidence</a>
      </article>`).join("")}</div>
  </section>`;
}

function renderChampionRecommendations() {
  championRecommendationsPanel.innerHTML = championRecommendations();
}

function renderMatches(matches) {
  brief.hidden = true;
  actionMessage.textContent = "";
  resultCount.textContent = `${matches.length} European ${matches.length === 1 ? "capability" : "capabilities"} meet the requirement`;
  results.innerHTML = `<div class="match-summary">EU/EEA stewardship is source-backed. GitHub activity, licence, release, and security signals are refreshed by the catalogue scanner; review flags remain visible.</div>
    <table class="registry-table">
      <thead><tr><th>Capability</th><th>Deployment</th><th>Licence</th><th>Status</th><th></th></tr></thead>
      <tbody>${matches.map(tool => `
        <tr>
          <td><a class="tool-name" href="${tool.github_metrics.url}" target="_blank" rel="noreferrer">${tool.name}</a><span class="tool-description">${tool.description}</span><span class="tool-meta">${tool.steward.country} · ${tool.github_metrics.stars.toLocaleString()} GitHub stars · evidence score ${tool.verification.score}/100</span></td>
          <td>${tool.deployment.includes("local") ? "Company controlled" : "EU managed"}</td>
          <td>${tool.licence}</td>
          <td><span class="status-text">${tool.maturity}</span><br><span class="tool-description">Reviewed ${tool.verification.reviewed_at}</span></td>
          <td><button class="row-action" type="button">Shortlist</button></td>
        </tr>`).join("")}</tbody>
    </table>`;
  results.querySelectorAll(".row-action").forEach(button => button.addEventListener("click", () => {
    const selected = button.classList.toggle("selected");
    button.textContent = selected ? "Shortlisted" : "Shortlist";
  }));
  renderChampionRecommendations();
}

function renderNoMatch() {
  brief.hidden = true;
  actionMessage.textContent = "";
  resultCount.textContent = "No catalogued European capability meets all requirements";
  results.innerHTML = `<div class="no-match">
      <div class="no-match-header">
        <h3>Capability gap identified</h3>
        <p>Do not force-fit an unsuitable tool. Convert this requirement into a reusable open build.</p>
      </div>
      <div class="requirement-review">
        <h4>Requirement submitted</h4>
        <dl>
          <div><dt>Capability</dt><dd>${valueLabel("task", task.value)}</dd></div>
          <div><dt>Sector</dt><dd>${valueLabel("sector", sector.value)}</dd></div>
          <div><dt>Deployment</dt><dd>${valueLabel("deployment", deployment.value)}</dd></div>
          <div><dt>Language</dt><dd>${valueLabel("language", language.value)}</dd></div>
          <div><dt>Assurance</dt><dd>${valueLabel("assurance", assurance.value)}</dd></div>
        </dl>
      </div>
      <div class="build-route">
        <p>The Commons can validate shared demand, commission an open implementation, and publish the resulting assets for reuse.</p>
        <button class="primary-button" id="create-brief" type="button">Create build brief</button>
      </div>
    </div>`;
  document.querySelector("#create-brief").addEventListener("click", createBuildBrief);
  renderChampionRecommendations();
}

function createBuildBrief() {
  document.querySelector("#brief-need").textContent = requirement.value.trim() || "Operational need to be validated with participating companies.";
  document.querySelector("#brief-capability").textContent = valueLabel("task", task.value);
  document.querySelector("#brief-sector").textContent = valueLabel("sector", sector.value);
  document.querySelector("#brief-deployment").textContent = valueLabel("deployment", deployment.value);
  document.querySelector("#brief-language").textContent = valueLabel("language", language.value);
  document.querySelector("#brief-assurance").textContent = valueLabel("assurance", assurance.value);
  document.querySelector("#brief-champion-list").innerHTML = recommendedChampions().map(champion => `
    <div class="brief-champion"><strong>${champion.company}</strong><span>${champion.outcome} · ${champion.evidence.publisher}</span></div>`
  ).join("");
  brief.hidden = false;
  brief.scrollIntoView({ behavior: "smooth", block: "start" });
}

function runSearch(event) {
  if (event) event.preventDefault();
  const matches = findMatches();
  if (matches.length) renderMatches(matches);
  else renderNoMatch();
}

form.addEventListener("submit", runSearch);
sector.addEventListener("change", runSearch);

document.querySelector("#copy-brief").addEventListener("click", async () => {
  const text = [
    "OPEN EU COMMONS — BUILD BRIEF OAC-2026-014",
    `Need: ${document.querySelector("#brief-need").textContent}`,
    `Capability: ${document.querySelector("#brief-capability").textContent}`,
    `Sector: ${valueLabel("sector", sector.value)}`,
    `Deployment: ${document.querySelector("#brief-deployment").textContent}`,
    `Language: ${document.querySelector("#brief-language").textContent}`,
    `Assurance: ${document.querySelector("#brief-assurance").textContent}`,
    `Source-backed implementation examples: ${recommendedChampions().map(champion => champion.company).join(", ")}`,
    "Public contribution scenario: up to €420,000",
    "Delivery: problem validation, working reference, independent pilot, public release."
  ].join("\n");
  try {
    await navigator.clipboard.writeText(text);
    actionMessage.textContent = "Build brief copied.";
  } catch (_) {
    actionMessage.textContent = "Copy unavailable in this browser.";
  }
});

document.querySelector("#register-demand").addEventListener("click", () => {
  const calls = document.querySelector("#open-calls");
  calls.textContent = String(Number(calls.textContent) + 1);
  actionMessage.textContent = "Demand signal registered for validation.";
});

async function loadCatalogue() {
  resultCount.textContent = "Loading the European catalogue";
  try {
    const response = await fetch("data/catalogue.json", { cache: "no-store" });
    if (!response.ok) throw new Error(`Catalogue request failed: ${response.status}`);
    const catalogue = await response.json();
    registry = catalogue.projects;
    champions = catalogue.champions;
    document.querySelector("#verified-packages").textContent = String(catalogue.summary.verified_projects);
    document.querySelector("#catalogued-packages").textContent = String(catalogue.summary.projects);
    document.querySelector("#discovery-candidates").textContent = String(catalogue.summary.discovery_candidates);
    document.querySelector("#last-review").textContent = catalogue.generated_at.slice(0, 10);
    runSearch();
  } catch (error) {
    resultCount.textContent = "Catalogue unavailable";
    results.innerHTML = `<div class="no-match"><div class="no-match-header"><h3>Could not load catalogue</h3><p>${error.message}</p></div></div>`;
    championRecommendationsPanel.innerHTML = `<div class="panel-heading champion-panel-heading"><span class="step">03</span><div><h2>Implementation champions</h2><p>Recommendations unavailable</p></div></div>`;
  }
}

loadCatalogue();