Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions apps/console/src/lib/server/web-research.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ export type LoadWebResearchOptions = {
readonly emptyOk?: boolean;
};

// Anonymous operation: some commonplace-api builds return HTTP 400 with an empty
// body for named operations (e.g. ConsoleRustyWebSearch) on this field.
const RUSTY_WEB_SEARCH_QUERY = `
query ConsoleRustyWebSearch($query: String!, $limit: Int, $providers: [String!]) {
query ($query: String!, $limit: Int, $providers: [String!]) {
rustyWebSearch(query: $query, limit: $limit, providers: $providers)
}
`;
Expand Down Expand Up @@ -79,23 +81,35 @@ export async function loadWebResearch(
}

const timeout = startHarnessRequestTimeout();
const graphqlPath = (() => {
try {
return new URL(endpoint).pathname || '/graphql';
} catch {
return '/graphql';
}
})();
const body = JSON.stringify({
query: RUSTY_WEB_SEARCH_QUERY,
variables: {
query,
limit,
providers: [...RUSTYWEB_LIVE_SEARCH_PROVIDERS],
},
});
let upstream: Response;
try {
upstream = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...credentialHeaders(credential.credential),
...credentialHeaders(credential.credential, {
method: 'POST',
path: graphqlPath,
body,
}),
Comment on lines 104 to +109
Comment on lines +105 to +109

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Confirm the helper declaration and the changed call.
rg -n -A16 -B3 'export function credentialHeaders' \
  apps/console/src/lib/server/upstream-credential.ts

rg -n -A10 -B4 'credentialHeaders\(credential\.credential' \
  apps/console/src/lib/server/web-research.ts

Repository: Travis-Gilbert/CommonPlace

Length of output: 1228


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "## Candidate files:"
git ls-files | rg '(^|/)src/lib/server/(upstream-credential|web-research)\.ts$' || true

echo
echo "## upstream-credential declarations:"
cat -n apps/console/src/lib/server/upstream-credential.ts | sed -n '1,120p'

echo
echo "## web-research relevant section:"
cat -n apps/console/src/lib/server/web-research.ts | sed -n '80,120p'

echo
echo "## TypeScript type-check behavior for call signature (from file text via tsc if available):"
if command -v tsc >/dev/null 2>&1; then
  tsc --noEmit --strict --target es2022 --module esnext --moduleResolution bundler --noImplicitAny false --strictNullChecks true --skipLibCheck false apps/console/src/lib/server/web-research.ts apps/console/src/lib/server/upstream-credential.ts 2>&1 || true
else
  echo "tsc not available"
fi

echo
echo "## JavaScript arity observation from installed TypeScript if available:"
node - <<'JS'
function credentialHeaders(credential) {
  return { 'x-api-key': credential.key };
}
const result = credentialHeaders(
  { kind: 'service_key', key: 'key1' },
  { method: 'POST', path: '/graphql', body: '{}', credential: { kind: 'service_key', key: 'key1' } }
);
console.log(JSON.stringify({ argumentCount: 2, returnedHeaders: result }));
JS

Repository: Travis-Gilbert/CommonPlace

Length of output: 9281


Fix the credentialHeaders call to match its signature.

credentialHeaders is declared with one parameter but this call passes (credential.credential, { method, path, body }), which should fail TypeScript. Update the signer/contract to accept and use these fields, or call a helper that supports signed-request custody.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/console/src/lib/server/web-research.ts` around lines 105 - 109, The
credentialHeaders call passes request fields unsupported by its current
signature. Update credentialHeaders and its signer contract to accept and use
credential.credential plus method, path, and body, or replace it with the
existing helper that supports signed-request custody while preserving the
generated authentication headers.

...principalTenantHeaders(principal),
},
body: JSON.stringify({
query: RUSTY_WEB_SEARCH_QUERY,
variables: {
query,
limit,
providers: [...RUSTYWEB_LIVE_SEARCH_PROVIDERS],
},
}),
body,
cache: 'no-store',
signal: AbortSignal.any([request.signal, timeout.signal]),
});
Expand Down
Loading