Files
headroom/scripts/verify_docs_anthropic_sdk.mjs
dependabot[bot]andJerrettDavis 65bcc4c313 deps: qualify latest Anthropic SDK 1.4.0 in docs (#4556)
Qualify the docs development dependency `@anthropic-ai/sdk` against the
latest stable 1.4.0 client under the user-requested newest secure
compatible dependency scope. This supersedes the original 1.3.0 target.
npm registry `version` returned 1.4.0 during qualification. The SDK
remains unused by the docs application itself; this is explicitly
required compatibility qualification, not a claim of a site runtime bug
or newly required vendor endpoint.

## Dependency assessment

Anthropic maintains the official SDK:
https://github.com/anthropics/anthropic-sdk-typescript/releases/tag/sdk-v1.4.0.
It remains a development dependency; published Headroom runtime behavior
is unchanged. The package declares standardwebhooks, json-schema-to-ts
and @opentelemetry/api dependencies, unchanged from the prior 1.3.0
candidate; there is no new install lifecycle hook or exporter. Existing
OpenTelemetry tracing can use an application-registered provider; this
proof does not qualify tracing/export behavior. npm audit reports zero
vulnerabilities, not a guarantee of upstream security history.

Compared with the prior candidate, only the root Anthropic version range
and SDK tarball version/integrity change. Unrelated platform/libc
metadata is preserved. Registry downloads and the docs existing Fumadocs
generation/build lifecycle remain install surfaces. The SDK makes
provider requests only when invoked; the new qualification uses explicit
fake credentials and an owned loopback server.

## Real behavior proof

Windows, Node 22.22.0, npm 10.9.4; main `038af599e` merged cleanly. From
`docs/`:

```sh
npm ci --ignore-scripts=false --no-audit --no-fund
npm run types:check
npm run build
npm audit --json
```

All passed, audit zero vulnerabilities. From repository root:

```sh
node scripts/verify_docs_anthropic_sdk.mjs
```

Actual installed Anthropic 1.4.0 client makes one real HTTP request to
the ephemeral loopback server. PASS: `/v1/messages`, default
`anthropic-version: 2026-10-21`, Bearer authentication, exact
thinking/cache/tool/system/metadata serialization, parsed thinking/text
response. Initial older fixture expectations for the old
API-version/API-key headers failed during earlier 1.3.0 qualification;
the fixture was corrected to assert the actual new SDK defaults, which
also pass on 1.4.0. The real client is used with fake credentials; no
external provider request is made.

Built Next.js production server returned HTTP 200 for
`/docs/anthropic-sdk`, 239099 bytes with expected Anthropic content;
owned server terminated afterward. `git diff --check` passes. Logs
retained locally as
`.codex/dep4556-latest-{ci,types,build,audit,route}.*`.

Untested: live vendor inference/authentication, streaming, real
signed-thinking validation, new SDK APIs, browser/other operating
systems, tracing export, and Headroom middleware transport (this is a
direct docs dependency proof). Hosted CI must qualify the final remote
head. No push, approval, merge or release performed by this
qualification.


Supply-chain metadata: SDK 1.4.0 declares Apache-2.0; the base lockfile
declared MIT.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
2026-11-03 17:07:21 -06:00

49 lines
2.6 KiB
JavaScript

// From the repository root: npm --prefix docs ci
// Then: node scripts/verify_docs_anthropic_sdk.mjs
// Exercises the development SDK directly against an owned loopback server.
import assert from 'node:assert/strict';
import { createServer } from 'node:http';
import { createRequire } from 'node:module';
const require = createRequire(new URL('../docs/package.json', import.meta.url));
const { Anthropic } = require('@anthropic-ai/sdk');
const requests = [];
const server = createServer(async (request, response) => {
const chunks = [];
for await (const chunk of request) chunks.push(chunk);
requests.push({ path: request.url, headers: request.headers, body: JSON.parse(Buffer.concat(chunks).toString('utf8')) });
response.writeHead(200, { 'content-type': 'application/json' });
response.end(JSON.stringify({
id: 'msg_loopback', type: 'message', role: 'assistant', model: 'claude-sonnet-4-6',
content: [{ type: 'thinking', thinking: 'Local SDK compatibility check.', signature: 'loopback-signature' }, { type: 'text', text: 'loopback-ok' }],
stop_reason: 'end_turn', stop_sequence: null,
usage: { input_tokens: 10, output_tokens: 4 },
}));
});
await new Promise((resolve, reject) => {
server.once('error', reject);
server.listen(0, '127.0.0.1', resolve);
});
try {
const client = new Anthropic({ apiKey: 'loopback-only', baseURL: `http://127.0.0.1:${server.address().port}`, maxRetries: 0, timeout: 5000 });
const input = {
model: 'claude-sonnet-4-6', max_tokens: 4096,
thinking: { type: 'enabled', budget_tokens: 1024 },
system: [{ type: 'text', text: 'Local SDK check.', cache_control: { type: 'ephemeral' } }],
tools: [{ name: 'lookup', description: 'Local fixture.', input_schema: { type: 'object', properties: { key: { type: 'string' } }, required: ['key'] }, cache_control: { type: 'ephemeral' } }],
messages: [{ role: 'user', content: [{ type: 'text', text: 'Test the local fixture.' }] }],
metadata: { user_id: 'docs-compatibility-check' },
};
const result = await client.messages.create(input);
assert.equal(requests.length, 1);
assert.equal(requests[0].path, '/v1/messages');
assert.equal(requests[0].headers['anthropic-version'], '2026-10-21');
assert.equal(requests[0].headers.authorization, 'Bearer loopback-only');
assert.deepEqual(requests[0].body, input);
assert.equal(result.content[0].type, 'thinking');
assert.equal(result.content[1].text, 'loopback-ok');
console.log(JSON.stringify({ passed: true, requests: 1, thinking: true, cachedSystemAndTool: true, metadata: true }));
} finally {
await new Promise((resolve, reject) => server.close(error => error ? reject(error) : resolve()));
}