Skip to content

feat(examples): migrate unique examples from arcjet-js - #193

Open
davidmytton wants to merge 7 commits into
mainfrom
migrate-examples-from-arcjet-js
Open

feat(examples): migrate unique examples from arcjet-js#193
davidmytton wants to merge 7 commits into
mainfrom
migrate-examples-from-arcjet-js

Conversation

@davidmytton

@davidmytton davidmytton commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Consolidates the remaining unique examples from arcjet/arcjet-js examples/ into this repository, rebuilt to the canonical example pattern (package metadata, templated README, Dockerfile, compose.yaml, devcontainer, LICENSE) with Arcjet packages pinned to published versions.

Paired with the removal PR in arcjet-js: arcjet/arcjet-js#6217. Mastra helpers landed in arcjet/arcjet-js#6226. Claude Agent SDK helpers land in arcjet/arcjet-js#6229.

Examples added (11)

Example Demonstrates Compose/CI Arcjet version
bun Canonical Bun runtime example (mirrors deno) 1.8.0
express-newman Testing Arcjet-protected Express routes with Newman/Postman 1.8.0
nextjs-bot-categories Advanced bot category allow/deny + per-bot filtering 1.8.0
react-router-middleware React Router v8 middleware pattern 1.8.0
nextjs-ai-agent Arcjet Guard AI agent guardrails standalone 1.10.0-rc.0
nextjs-sensitive-info Sensitive info detection incl. Rampart NER backend + Guard standalone 1.9.1
nextjs-guard-policy Remotely-configured Guard policy for AI tool calls standalone 1.10.0-rc.0
node-guard-policy Guard policy on a plain Node.js server standalone 1.10.0-rc.0
mastra-agent @arcjet/guard/mastra/v1 — processor, tool, hooks (#6226) standalone unpublished
eve-agent @arcjet/guard/vercel-eve/v0 — inbound, approval, tool, hooks (#6208) standalone 1.10.0
claude-agent @arcjet/guard/claude-agent-sdk/v0 — guardTool, guardHooks, canUseTool is not a gate (#6229) standalone unpublished (vendored)

The first four are wired into the root compose.yaml and the Docker build CI matrix. Guard/AI examples are standalone (AI gateway key, dashboard policy, native NER, or unpublished Guard APIs) and stay out of the default compose/CI run.

Pre-release note

nextjs-guard-policy and node-guard-policy need the Guard remote-policy API (policyInput, guardTool actor, launchArcjet({ sensitiveInfoBackend }), decision.policyResults) which is not on npm yet. They are pinned to 1.10.0-rc.0 with a README note that npm ci + build will fail until that API ships.

mastra-agent depends on @arcjet/guard/mastra/v1, which is not published yet (arcjet-js#6226 merged; publish is arcjet-js#6227). eve-agent uses @arcjet/guard/vercel-eve/v0, which shipped in 1.10.0 (arcjet-js#6208). claude-agent depends on @arcjet/guard/claude-agent-sdk/v0 (arcjet-js#6229) and vendors a built @arcjet/guard from adapter SHA 69dd6010 because npm cannot install a monorepo subdir from git.

Review follow-ups (resolved)

  • Lockfiles present for npm ci on the compose/CI examples
  • React Router compose: dev 5173 / prod 3000
  • nextjs-ai-agent: sliding-window (5/60s by IP) + 2,000-char cap before the workflow; 429 on DENY
  • Bot-category diagnostic headers gated on ARCJET_DEMO_BOT_HEADERS=1
  • Guard-policy context endpoint returns labels only
  • Node + Mastra JSON body cap 32 KiB
  • Bun devcontainer uses oven/bun:1 (no pipe-to-bash)
  • Workflow context is a plain serializable { correlationId, metadata } record

Wiring

  • Root compose.yaml — 4 non-AI examples
  • .github/workflows/docker-build.yml — same 4
  • scripts/prepare-to-publish.ts — all 11 registered
  • README.md — all 11 listed

Consolidates the remaining unique examples from the `arcjet/arcjet-js`
`examples/` directory into this repository, rebuilt to the canonical
example pattern (canonical metadata, README, Dockerfile, compose.yaml,
devcontainer, LICENSE) with Arcjet packages pinned to published versions.

Examples added:

- bun — canonical Bun runtime example (mirrors the Deno example)
- express-newman — testing Arcjet-protected Express routes with Newman
- nextjs-bot-categories — advanced bot category allow/deny + filtering
- react-router-middleware — React Router v8 middleware pattern
- nextjs-ai-agent — Arcjet Guard AI agent guardrails
- nextjs-sensitive-info — sensitive info detection incl. Rampart NER backend
- nextjs-guard-policy — remotely-configured Guard policy for AI tool calls
- node-guard-policy — Guard policy on a plain Node.js server

The first four are wired into the root `compose.yaml` and the Docker
build CI matrix. The Guard/AI examples are standalone (they need an AI
gateway key, dashboard policy config, or a native NER backend) and are
excluded from the default compose/CI run.

Note: nextjs-guard-policy and node-guard-policy depend on the Arcjet
Guard remote-policy API which is not yet published to npm; they are
pinned to 1.10.0-rc.0 and documented as not building until that API
ships. nextjs-ai-agent is pinned to 1.10.0-rc.0 (first release with the
agent guardrail API) and nextjs-sensitive-info to 1.9.1 (Rampart's
earliest release).

All examples are registered in scripts/prepare-to-publish.ts for
publishing to their own repositories.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@socket-security

socket-security Bot commented Aug 7, 2026

Copy link
Copy Markdown

@socket-security

This comment was marked as low quality.

@davidmytton
davidmytton marked this pull request as ready for review August 7, 2026 19:10
@davidmytton

This comment was marked as resolved.

arcjet-review[bot]

This comment was marked as resolved.

davidmytton and others added 3 commits August 7, 2026 15:26
Migrates the Vercel Eve agent example from arcjet-js, demonstrating
Arcjet Guard AI guardrails (guardTool, guardApproval, guardInbound) on a
Vercel Eve agent. Standalone example (not wired into compose/CI).

Pinned to @arcjet/guard@1.10.0-rc.0; the Eve integration subpath
(@arcjet/guard/vercel-eve) is not yet published to npm, so the README
notes it will not build until that API ships.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds a standalone Mastra agent example demonstrating @arcjet/guard/mastra/v1:
inbound prompt injection via guardProcessor, tool deny via guardTool
(structured result, no throw), PII on args, rate limiting, fail-closed
defaults, correlation via mastraAgentContext (thread → resource → run;
never mint an id), and guardHooks for unwrapped tools (proceed: false
on DENY). Not wired into root compose/CI, matching other Guard/AI examples.

Pinned to @arcjet/guard@1.10.0-rc.0; the Mastra integration subpath
(@arcjet/guard/mastra/v1) is not yet published to npm, so the README
notes it will not build until that API ships.

Co-authored-by: David Mytton <davidmytton@users.noreply.github.com>
Align the React Router middleware compose/dev port on 5173 and the
production image on 3000. Cap JSON bodies on the Node and Mastra demo
servers. Bound AI question/message length. Replace the Bun
devcontainer pipe-to-bash install with the official oven/bun image.
Document accepted demo risk for unauthenticated AI routes, bot-category
headers, and synthetic policy fixtures.

Co-authored-by: David Mytton <davidmytton@users.noreply.github.com>
@cursor

cursor Bot commented Aug 14, 2026

Copy link
Copy Markdown

Sorted the open review threads on this PR (no new PR). Summary of the High Risk notes that did not have their own inline thread:

  • Bun install-script supply chain: replaced the devcontainer curl | bash installer with the official oven/bun:1 image (same source as the example Dockerfile).
  • Workflow serializability of ArcjetAgentContext: createAgentContext returns a plain { correlationId, metadata } record. Commented that on the workflow input and the route so it stays JSON-safe for Workflow DevKit replay.
  • Mastra example: no later inline threads. Added the same demo-risk README warning as the other AI examples, plus a 32 KiB JSON body cap and a 2,000-character message bound.

All 8 inline threads are replied to and resolved.

Add an Arcjet sliding-window rate limit and question-length cap before
start(workflow), gate bot diagnostic headers behind ARCJET_DEMO_BOT_HEADERS,
and return labels only from the Guard policy context endpoint.

Co-authored-by: David Mytton <davidmytton@users.noreply.github.com>
@cursor

cursor Bot commented Aug 14, 2026

Copy link
Copy Markdown

Follow-up on the remaining review items (HEAD e80581e, no new PR):

  • AI agent route: Arcjet sliding-window rate limit (5/60s) and 2,000-character question cap now run before start(workflow). DENY returns 429.
  • Bot-categories headers: gated behind ARCJET_DEMO_BOT_HEADERS=1 (default off).
  • Guard policy context: labels only; records/prompts stay server-side.
  • Lockfiles, compose 5173/3000, 32 KiB body cap: confirmed on HEAD.
  • Bun install-script: still using oven/bun:1 (no pipe-to-bash).
  • Workflow serializability: createAgentContext remains a plain { correlationId, metadata } record, commented on the workflow input and route.
  • Mastra: no inline review threads. Existing 32 KiB body cap and 2,000-character message bound remain.

All 8 inline review threads were resolved via resolveReviewThread.

arcjet-review[bot]

This comment was marked as outdated.

arcjet-review[bot]

This comment was marked as duplicate.

@arcjet-review arcjet-review Bot added the needs review Awaiting human review label Aug 14, 2026
Adds a standalone Claude Agent SDK example demonstrating
@arcjet/guard/claude-agent-sdk/v0 (UserPromptSubmit, PreToolUse, guardTool)
from unpublished adapter SHA 69dd6010. Vendors @arcjet/guard via
file:./vendor/arcjet-guard. Not wired into root compose/CI.

Co-authored-by: David Mytton <davidmytton@users.noreply.github.com>
@arcjet-review arcjet-review Bot added needs review Awaiting human review and removed needs review Awaiting human review labels Aug 15, 2026
Standalone Graph API (StateGraph + ToolNode) demo of unpublished
@arcjet/guard/langgraph/v1: guardTool, guardToolNode, inbound screen
before invoke, interrupt() as HITL not policy, caller-owned thread_id.
Vendored from arcjet-js@baa23e7f (david/cursor/guard-langgraph-v1-e852).

Co-authored-by: David Mytton <davidmytton@users.noreply.github.com>
@arcjet-review arcjet-review Bot added needs review Awaiting human review and removed needs review Awaiting human review labels Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs review Awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants