Skip to content

Commit 2198d4c

Browse files
Merge branch 'guardrails' of github.com:invariantlabs-ai/docs into guardrails
2 parents 8786f53 + 1036f0c commit 2198d4c

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

docs/assets/invariant.css

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ body {
2727
position: relative;
2828
}
2929

30-
.trace-iframe {
31-
width: 100%;
32-
border: none;
33-
height: 500px;
34-
}
35-
3630
h1 {
3731
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
3832
}

docs/assets/js/highlight.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
11
BASE_URL = 'http://localhost/';
22

3-
function changeTraceElements(codeElements) {
3+
function changeElements(codeElements, endpoint) {
44
// Add a button to each pre element
55
codeElements.forEach(function(codeElement) {
66

77
// replace the code element with an iframe
88
const textContent = codeElement.textContent || codeElement.innerText;
99
const encodedContent = btoa(textContent);
10-
const iframe = document.createElement('iframe', { id: 'traceview-' + encodedContent });
11-
iframe.src = `${BASE_URL}traceview?trace=${encodedContent}`;
10+
// get a UUID
11+
const id = crypto.randomUUID().toString();
12+
const iframe = document.createElement('iframe', { id: id });
13+
iframe.src = `${BASE_URL}embed/${endpoint}=${encodedContent}&id=${id}`;
1214
codeElement.replaceWith(iframe);
1315

1416
window.addEventListener('message', function(event) {
15-
if (event.data.type === 'resize') {
16-
console.log('resize', event.data);
17+
//check which element the message is coming from
18+
if (event.data.type === 'resize' && event.data.id === id) {
1719
iframe.style.height = event.data.height + 'px';
1820
}
1921
});
2022

2123
});
2224
}
2325

24-
2526
document.addEventListener('DOMContentLoaded', function() {
2627
// check if BASE_URL is defined and reachable
27-
fetch(`${BASE_URL}`)
28+
fetch(`${BASE_URL}embed/traceview`)
2829
.then(response => {
2930
if (!response.ok) {
31+
console.log('Network response was not ok');
3032
throw new Error('Network response was not ok');
3133
}
3234
return response.text();
3335
})
3436
.then(data => {
3537
// if we can reach it, add buttons to trace and guardrail elements
3638
// currently disabled as the traceview endpoint is not yet enabled on explorer
37-
//changeTraceElements(document.querySelectorAll('div.language-trace'))
38-
//changeGuardrailElements(document.querySelectorAll('div.language-guardrail'))
39+
changeElements(document.querySelectorAll('div.language-trace'), 'traceview?trace')
40+
changeElements(document.querySelectorAll('div.language-guardrail'), 'playground?policy')
3941
})
4042
.catch(error => {
4143
console.error('There was a problem with the fetch operation:', error);

0 commit comments

Comments
 (0)