@amplitude/ai 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/commands/instrument-with-amplitude-ai.md +12 -0
- package/.cursor/skills/instrument-with-amplitude-ai/SKILL.md +4 -42
- package/AGENTS.md +86 -28
- package/README.md +190 -111
- package/amplitude-ai.md +463 -0
- package/bin/amplitude-ai-doctor.mjs +0 -0
- package/bin/amplitude-ai-instrument.mjs +0 -0
- package/bin/amplitude-ai-mcp.mjs +0 -0
- package/bin/amplitude-ai-register-catalog.mjs +0 -0
- package/bin/amplitude-ai-status.mjs +0 -0
- package/bin/amplitude-ai.mjs +14 -5
- package/data/agent_event_catalog.json +52 -2
- package/dist/bound-agent.d.ts +18 -14
- package/dist/bound-agent.d.ts.map +1 -1
- package/dist/bound-agent.js +4 -1
- package/dist/bound-agent.js.map +1 -1
- package/dist/cli/status.d.ts.map +1 -1
- package/dist/cli/status.js +31 -19
- package/dist/cli/status.js.map +1 -1
- package/dist/client.d.ts +14 -14
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +38 -0
- package/dist/client.js.map +1 -1
- package/dist/context.d.ts +5 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +4 -0
- package/dist/context.js.map +1 -1
- package/dist/core/constants.d.ts +3 -1
- package/dist/core/constants.d.ts.map +1 -1
- package/dist/core/constants.js +3 -1
- package/dist/core/constants.js.map +1 -1
- package/dist/core/tracking.d.ts +12 -2
- package/dist/core/tracking.d.ts.map +1 -1
- package/dist/core/tracking.js +13 -2
- package/dist/core/tracking.js.map +1 -1
- package/dist/decorators.d.ts +1 -1
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +4 -3
- package/dist/decorators.js.map +1 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.js +5 -2
- package/dist/mcp/contract.d.ts +4 -0
- package/dist/mcp/contract.d.ts.map +1 -1
- package/dist/mcp/contract.js +6 -2
- package/dist/mcp/contract.js.map +1 -1
- package/dist/mcp/generate-verify-test.d.ts +7 -0
- package/dist/mcp/generate-verify-test.d.ts.map +1 -0
- package/dist/mcp/generate-verify-test.js +25 -0
- package/dist/mcp/generate-verify-test.js.map +1 -0
- package/dist/mcp/index.d.ts +2 -1
- package/dist/mcp/index.js +2 -1
- package/dist/mcp/instrument-file.d.ts +14 -0
- package/dist/mcp/instrument-file.d.ts.map +1 -0
- package/dist/mcp/instrument-file.js +139 -0
- package/dist/mcp/instrument-file.js.map +1 -0
- package/dist/mcp/scan-project.d.ts +52 -0
- package/dist/mcp/scan-project.d.ts.map +1 -0
- package/dist/mcp/scan-project.js +309 -0
- package/dist/mcp/scan-project.js.map +1 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +79 -4
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/validate-file.d.ts +4 -0
- package/dist/mcp/validate-file.d.ts.map +1 -1
- package/dist/mcp/validate-file.js +559 -11
- package/dist/mcp/validate-file.js.map +1 -1
- package/dist/middleware.js +2 -1
- package/dist/middleware.js.map +1 -1
- package/dist/node_modules/.pnpm/acorn-typescript@1.4.13_acorn@8.16.0/node_modules/acorn-typescript/lib/index.js +2389 -0
- package/dist/node_modules/.pnpm/acorn-typescript@1.4.13_acorn@8.16.0/node_modules/acorn-typescript/lib/index.js.map +1 -0
- package/dist/node_modules/.pnpm/acorn@8.16.0/node_modules/acorn/dist/acorn.js +5128 -0
- package/dist/node_modules/.pnpm/acorn@8.16.0/node_modules/acorn/dist/acorn.js.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js +1 -1
- package/dist/patching.d.ts.map +1 -1
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +1 -0
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/base.d.ts +2 -1
- package/dist/providers/base.d.ts.map +1 -1
- package/dist/providers/base.js +4 -0
- package/dist/providers/base.js.map +1 -1
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +2 -0
- package/dist/providers/openai.js.map +1 -1
- package/dist/serverless.d.ts +19 -0
- package/dist/serverless.d.ts.map +1 -0
- package/dist/serverless.js +35 -0
- package/dist/serverless.js.map +1 -0
- package/dist/session.d.ts +24 -8
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +20 -1
- package/dist/session.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/llms-full.txt +353 -69
- package/llms.txt +6 -2
- package/mcp.schema.json +7 -3
- package/package.json +10 -5
- package/bin/amplitude-ai-init.mjs +0 -27
- package/dist/cli/init.d.ts +0 -14
- package/dist/cli/init.d.ts.map +0 -1
- package/dist/cli/init.js +0 -40
- package/dist/cli/init.js.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Auto-instrument a JS/TS AI app with @amplitude/ai.
|
|
3
|
+
allowed-tools: mcp__amplitude-ai__scan_project, mcp__amplitude-ai__validate_file, mcp__amplitude-ai__instrument_file, mcp__amplitude-ai__generate_verify_test, mcp__amplitude-ai__validate_setup, mcp__amplitude-ai__suggest_instrumentation, mcp__amplitude-ai__get_event_schema, mcp__amplitude-ai__get_integration_pattern, mcp__amplitude-ai__search_docs, Bash, Read, Write, Edit, Glob, Grep
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /instrument-with-amplitude-ai
|
|
7
|
+
|
|
8
|
+
Read and follow `node_modules/@amplitude/ai/amplitude-ai.md` step by step.
|
|
9
|
+
|
|
10
|
+
That file contains the complete 4-phase workflow: **Detect → Discover → Instrument → Verify**.
|
|
11
|
+
|
|
12
|
+
If the `amplitude-ai` MCP server is connected, use `scan_project`, `validate_file`, `instrument_file`, and `generate_verify_test` tools to accelerate each phase.
|
|
@@ -1,50 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: instrument-with-amplitude-ai
|
|
3
|
-
description:
|
|
3
|
+
description: Auto-instrument a JS/TS AI app with @amplitude/ai. Detects framework, discovers agents and LLM call sites, applies instrumentation, and verifies with tests.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# /instrument-with-amplitude-ai
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Read and follow `node_modules/@amplitude/ai/amplitude-ai.md` step by step.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
That file contains the complete 4-phase workflow: **Detect → Discover → Instrument → Verify**.
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
1. Detect project type from `package.json` and lockfiles:
|
|
15
|
-
- web apps: `next`, `react`, `vite`
|
|
16
|
-
- APIs: `express`, `fastify`, `hono`
|
|
17
|
-
- workers/CLI: no web framework, but provider SDKs present
|
|
18
|
-
2. Install deps:
|
|
19
|
-
- `pnpm add @amplitude/ai`
|
|
20
|
-
- provider packages used by the app (`openai`, `@anthropic-ai/sdk`, etc.)
|
|
21
|
-
3. Scaffold bootstrap:
|
|
22
|
-
- run `amplitude-ai init`
|
|
23
|
-
- ensure `AMPLITUDE_AI_API_KEY` is documented in `.env.example`
|
|
24
|
-
4. Identify likely LLM call sites (priority order):
|
|
25
|
-
- provider SDK direct calls:
|
|
26
|
-
- `openai.chat.completions.create`
|
|
27
|
-
- `openai.responses.create`
|
|
28
|
-
- `anthropic.messages.create`
|
|
29
|
-
- framework integrations:
|
|
30
|
-
- route handlers (`app.get/post`, `router.*`, Next route handlers)
|
|
31
|
-
- agent orchestration loops and tool executors
|
|
32
|
-
5. Add instrumentation (choose one path):
|
|
33
|
-
- zero-code: `patch({ amplitudeAI })`
|
|
34
|
-
- explicit wrappers: `wrap(existingClient, amplitudeAI)`
|
|
35
|
-
- explicit lifecycle: `ai.agent(agentId, { userId }).session({ sessionId })`
|
|
36
|
-
- function tracing: `tool(...)` / `observe(...)`
|
|
37
|
-
6. Validate:
|
|
38
|
-
- run `amplitude-ai doctor`
|
|
39
|
-
- run tests and typecheck
|
|
40
|
-
- verify generated files are fresh: `pnpm --filter @amplitude/ai check:generated`
|
|
41
|
-
7. Suggested ripgrep probes:
|
|
42
|
-
- `openai|anthropic|chat\\.completions|responses\\.create|messages\\.create`
|
|
43
|
-
- `agent\\(|session\\(|tool\\(|observe\\(`
|
|
44
|
-
|
|
45
|
-
## Safety checks
|
|
46
|
-
|
|
47
|
-
- Do not modify unrelated files.
|
|
48
|
-
- Prefer adding instrumentation near existing provider calls.
|
|
49
|
-
- Keep content mode explicit if privacy constraints apply.
|
|
50
|
-
- Do not duplicate instrumentation (avoid wrapping and patching the same call path twice).
|
|
12
|
+
If the `amplitude-ai` MCP server is connected, use `scan_project`, `validate_file`, `instrument_file`, and `generate_verify_test` tools to accelerate each phase.
|
package/AGENTS.md
CHANGED
|
@@ -1,12 +1,55 @@
|
|
|
1
|
-
<!-- GENERATED FILE: do not edit manually -->
|
|
2
|
-
|
|
3
1
|
# AGENTS.md
|
|
4
2
|
|
|
5
|
-
Package: `@amplitude/ai` v0.
|
|
3
|
+
Package: `@amplitude/ai` v0.3.0
|
|
6
4
|
|
|
7
5
|
## Install
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @amplitude/ai
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## MCP Server Setup
|
|
12
|
+
|
|
13
|
+
The SDK ships an MCP server for AI coding agents. It provides project scanning,
|
|
14
|
+
file validation, instrumentation, test generation, and the complete API reference.
|
|
15
|
+
|
|
16
|
+
### Cursor
|
|
17
|
+
|
|
18
|
+
Add to `.cursor/mcp.json` in your project root:
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"mcpServers": {
|
|
22
|
+
"amplitude-ai": {
|
|
23
|
+
"command": "npx",
|
|
24
|
+
"args": ["amplitude-ai", "mcp"]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
Then point the agent at the instrumentation guide: `node_modules/@amplitude/ai/amplitude-ai.md`
|
|
30
|
+
|
|
31
|
+
### Claude Code
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
claude mcp add amplitude-ai -- npx amplitude-ai mcp
|
|
35
|
+
```
|
|
36
|
+
Then point the agent at the instrumentation guide: `node_modules/@amplitude/ai/amplitude-ai.md`
|
|
37
|
+
|
|
38
|
+
### OpenAI Codex CLI
|
|
39
|
+
|
|
40
|
+
Add to `~/.codex/config.toml`:
|
|
41
|
+
```toml
|
|
42
|
+
[mcp_servers.amplitude-ai]
|
|
43
|
+
command = "npx"
|
|
44
|
+
args = ["amplitude-ai", "mcp"]
|
|
45
|
+
```
|
|
46
|
+
Codex auto-reads this `AGENTS.md` file for context.
|
|
47
|
+
|
|
48
|
+
### Generic (any MCP-compatible agent)
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{ "amplitude-ai": { "command": "npx", "args": ["amplitude-ai", "mcp"] } }
|
|
52
|
+
```
|
|
10
53
|
|
|
11
54
|
## Decision Tree
|
|
12
55
|
|
|
@@ -15,28 +58,53 @@ Package: `@amplitude/ai` v0.2.1
|
|
|
15
58
|
- Need user/session lineage: use `ai.agent(...).session(...)`.
|
|
16
59
|
- Multiple agents collaborating: use `session.runAs(childAgent, fn)` for automatic identity propagation.
|
|
17
60
|
- Need tool telemetry: use `tool()`.
|
|
61
|
+
- Need span/observability: use `observe()`.
|
|
18
62
|
- Need agent-assistant guidance: run MCP prompt `instrument_app`.
|
|
19
63
|
|
|
20
|
-
##
|
|
64
|
+
## MCP Surface
|
|
21
65
|
|
|
22
|
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
66
|
+
Tools:
|
|
67
|
+
- `get_event_schema`
|
|
68
|
+
- `get_integration_pattern`
|
|
69
|
+
- `validate_setup`
|
|
70
|
+
- `suggest_instrumentation`
|
|
71
|
+
- `validate_file`
|
|
72
|
+
- `search_docs`
|
|
73
|
+
- `scan_project`
|
|
74
|
+
- `generate_verify_test`
|
|
75
|
+
- `instrument_file`
|
|
76
|
+
|
|
77
|
+
Resources:
|
|
78
|
+
- `amplitude-ai://event-schema`
|
|
79
|
+
- `amplitude-ai://integration-patterns`
|
|
80
|
+
- `amplitude-ai://instrument-guide`
|
|
81
|
+
|
|
82
|
+
Prompt:
|
|
83
|
+
- `instrument_app` — Full guided instrumentation with embedded SKILL.md
|
|
28
84
|
|
|
29
|
-
##
|
|
85
|
+
## Canonical Patterns
|
|
30
86
|
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
87
|
+
- zero-code patching — `patch({ amplitudeAI: ai })`
|
|
88
|
+
- wrap-openai — `wrap(existingClient, ai)`
|
|
89
|
+
- bound-agent-session — `ai.agent('id').session({ userId }).run(fn)`
|
|
90
|
+
- multi-agent-runas — `s.runAs(childAgent, fn)`
|
|
91
|
+
- tool-decorator — `tool(fn, { name: 'tool_name' })`
|
|
92
|
+
- observe-spans — `observe(fn, { name: 'span-name' })`
|
|
93
|
+
- express-middleware — `createAmplitudeAIMiddleware({ amplitudeAI: ai, userIdResolver })`
|
|
34
94
|
|
|
35
95
|
## Gotchas
|
|
36
96
|
|
|
37
97
|
- `tool()` in Node requires explicit JSON schema for robust agent input shaping.
|
|
38
98
|
- Keep `AMPLITUDE_AI_API_KEY` available in runtime env for telemetry delivery.
|
|
39
99
|
- Use `MockAmplitudeAI` for deterministic tests.
|
|
100
|
+
- Call `ai.flush()` before returning from serverless handlers (Next.js, Lambda, Vercel).
|
|
101
|
+
- `session.run()` relies on `AsyncLocalStorage`; not available in Edge Runtime.
|
|
102
|
+
|
|
103
|
+
## CLI
|
|
104
|
+
|
|
105
|
+
- `amplitude-ai mcp` — Start the MCP server for AI coding agents
|
|
106
|
+
- `amplitude-ai doctor [--json]` — Validate environment, deps, and event pipeline
|
|
107
|
+
- `amplitude-ai status [--json]` — Show SDK version, installed providers, and env config
|
|
40
108
|
|
|
41
109
|
## Testing
|
|
42
110
|
|
|
@@ -44,13 +112,6 @@ Package: `@amplitude/ai` v0.2.1
|
|
|
44
112
|
- Run typecheck: `pnpm --filter @amplitude/ai test:typescript`
|
|
45
113
|
- Run docs freshness: `node scripts/generate-agent-docs.mjs --check`
|
|
46
114
|
|
|
47
|
-
## CLI
|
|
48
|
-
|
|
49
|
-
- `amplitude-ai init [--dry-run] [--force]`
|
|
50
|
-
- `amplitude-ai doctor`
|
|
51
|
-
- `amplitude-ai status`
|
|
52
|
-
- `amplitude-ai mcp`
|
|
53
|
-
|
|
54
115
|
## Examples
|
|
55
116
|
|
|
56
117
|
- `examples/zero-code.ts`
|
|
@@ -59,13 +120,10 @@ Package: `@amplitude/ai` v0.2.1
|
|
|
59
120
|
- `examples/framework-integration.ts`
|
|
60
121
|
- `examples/real-openai.ts` (requires OPENAI_API_KEY)
|
|
61
122
|
|
|
62
|
-
##
|
|
63
|
-
|
|
64
|
-
- `llms-full.txt` — Full API signatures and canonical patterns for LLM agents
|
|
65
|
-
|
|
66
|
-
## Cursor Skill
|
|
123
|
+
## Instrumentation Guide
|
|
67
124
|
|
|
68
|
-
-
|
|
125
|
+
- `amplitude-ai.md` — **Start here.** Complete 4-phase instrumentation workflow + API reference. Paste into any coding agent.
|
|
126
|
+
- `llms-full.txt` — Extended API reference with MCP tools and patterns
|
|
69
127
|
|
|
70
128
|
## Event Schema (names)
|
|
71
129
|
|