Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

2.0 KB
Raw Blame
// Helper to wait for postMessage response from iframe
function waitForIframeMessage(action) {
  return new Promise(resolve => {
    const listener = e => {
      if (e.data && e.data.action === action) {
        window.removeEventListener('message', listener);
        resolve(e.data);
      }
    };
    window.addEventListener('message', listener);
  });
}

// Helper to compare tool objects that should conform to the `RegisteredTool`
// dictionary.
function toolsAreEqual(actual, expected) {
  if (actual.name !== expected.name) {
    return `names are unequal: ${actual.name} !== ${expected.name}`;
  }
  if (actual.description !== expected.description) {
    return `descriptions are unequal: ${actual.description} !== ${expected.description}`;
  }
  if (JSON.stringify(actual.inputSchema) !==
      JSON.stringify(expected.inputSchema)) {
    return `inputSchemas are unequal: ${
        JSON.stringify(
            actual.inputSchema)} !== ${JSON.stringify(expected.inputSchema)}`;
  }
  if (actual.origin !== expected.origin) {
    return `origins are unequal: ${actual.origin} !== ${expected.origin}`;
  }
  if (actual.annotations?.readOnlyHint !== expected.annotations?.readOnlyHint) {
    return `readOnlyHints are unequal: ${actual.annotations?.readOnlyHint} !== ${expected.annotations?.readOnlyHint}`;
  }
  if (actual.annotations?.untrustedContentHint !== expected.annotations?.untrustedContentHint) {
    return `untrustedContentHints are unequal: ${actual.annotations?.untrustedContentHint} !== ${expected.annotations?.untrustedContentHint}`;
  }
  if (actual.annotations?.consequentialHint !== expected.annotations?.consequentialHint) {
    return `consequentialHints are unequal: ${actual.annotations?.consequentialHint} !== ${expected.annotations?.consequentialHint}`;
  }
  if (actual.annotations?.debugging !== expected.annotations?.debugging) {
    return `debuggings are unequal: ${actual.annotations?.debugging} !== ${
        expected.annotations?.debugging}`;
  }

  return true;
}