Compare commits
10
Commits
d04e00fc2c
...
e944633dd8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e944633dd8 | ||
|
|
cb046b4df0 | ||
|
|
8e4aea45a8 | ||
|
|
5278ce1f3a | ||
|
|
e74c009e02 | ||
|
|
78144b4dba | ||
|
|
e32c159f35 | ||
|
|
119518599e | ||
|
|
1f0a2e44c8 | ||
|
|
e48da3956c |
No files matched your search
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "bun",
|
||||
"request": "attach",
|
||||
"name": "Attach to Bun (TUI debug)",
|
||||
"url": "ws://localhost:8888/2dc3gzl5xot",
|
||||
"stopOnEntry": false,
|
||||
"internalConsoleOptions": "neverOpen"
|
||||
}
|
||||
]
|
||||
}
|
||||
+105
@@ -1,5 +1,110 @@
|
||||
# DEV-LOG
|
||||
|
||||
## GrowthBook 自定义服务器适配器 (2026-04-03)
|
||||
|
||||
GrowthBook 功能开关系统原为 Anthropic 内部构建设计,硬编码 SDK key 和 API 地址,外部构建因 `is1PEventLoggingEnabled()` 门控始终禁用。新增适配器模式,通过环境变量连接自定义 GrowthBook 服务器,无配置时所有 feature 读取返回代码默认值。
|
||||
|
||||
**修改文件:**
|
||||
|
||||
| 文件 | 变更 |
|
||||
|------|------|
|
||||
| `src/constants/keys.ts` | `getGrowthBookClientKey()` 优先读取 `CLAUDE_GB_ADAPTER_KEY` 环境变量 |
|
||||
| `src/services/analytics/growthbook.ts` | `isGrowthBookEnabled()` 适配器模式下直接返回 `true`,绕过 1P event logging 门控 |
|
||||
| `src/services/analytics/growthbook.ts` | `getGrowthBookClient()` base URL 优先使用 `CLAUDE_GB_ADAPTER_URL` |
|
||||
| `docs/internals/growthbook-adapter.mdx` | 新增适配器配置文档,含全部 ~58 个 feature key 列表 |
|
||||
|
||||
**用法:** `CLAUDE_GB_ADAPTER_URL=https://gb.example.com/ CLAUDE_GB_ADAPTER_KEY=sdk-xxx bun run dev`
|
||||
|
||||
---
|
||||
|
||||
## Datadog 日志端点可配置化 (2026-04-03)
|
||||
|
||||
将 Datadog 硬编码的 Anthropic 内部端点改为环境变量驱动,默认禁用。
|
||||
|
||||
**修改文件:**
|
||||
|
||||
| 文件 | 变更 |
|
||||
|------|------|
|
||||
| `src/services/analytics/datadog.ts` | `DATADOG_LOGS_ENDPOINT` 和 `DATADOG_CLIENT_TOKEN` 从硬编码常量改为读取 `process.env.DATADOG_LOGS_ENDPOINT` / `process.env.DATADOG_API_KEY`,默认空字符串;`initializeDatadog()` 增加守卫:端点或 Token 未配置时直接返回 `false` |
|
||||
| `docs/telemetry-remote-config-audit.md` | 更新第 1 节,反映新的环境变量配置方式 |
|
||||
|
||||
**效果:** 默认不向任何外部发送数据;设置两个环境变量即可接入自己的 Datadog 实例。原有 `DISABLE_TELEMETRY`、privacy level、sink killswitch 等防线保留。
|
||||
|
||||
**用法:** `DATADOG_LOGS_ENDPOINT=https://http-intake.logs.datadoghq.com/api/v2/logs DATADOG_API_KEY=xxx bun run dev`
|
||||
|
||||
---
|
||||
|
||||
## Sentry 错误上报集成 (2026-04-03)
|
||||
|
||||
恢复反编译过程中被移除的 Sentry 集成。通过 `SENTRY_DSN` 环境变量控制,未设置时所有函数为 no-op,不影响正常运行。
|
||||
|
||||
**新增文件:**
|
||||
|
||||
| 文件 | 说明 |
|
||||
|------|------|
|
||||
| `src/utils/sentry.ts` | 核心模块:`initSentry()`、`captureException()`、`setTag()`、`setUser()`、`closeSentry()`;`beforeSend` 过滤 auth headers 等敏感信息;忽略 ECONNREFUSED/AbortError 等非 actionable 错误 |
|
||||
|
||||
**修改文件:**
|
||||
|
||||
| 文件 | 变更 |
|
||||
|------|------|
|
||||
| `src/utils/errorLogSink.ts` | `logErrorImpl` 末尾调用 `captureException()`,所有经 `logError()` 的错误自动上报 |
|
||||
| `src/components/SentryErrorBoundary.ts` | 添加 `componentDidCatch`,React 组件渲染错误上报到 Sentry(含 componentStack) |
|
||||
| `src/entrypoints/init.ts` | 网络配置后调用 `initSentry()` |
|
||||
| `src/utils/gracefulShutdown.ts` | 优雅关闭时 flush Sentry 事件 |
|
||||
| `src/screens/REPL.tsx:2809` | `fireCompanionObserver` 调用增加 `typeof` 防护,BUDDY feature 启用时不报错(TODO: 待实现) |
|
||||
| `package.json` | devDependencies 新增 `@sentry/node` |
|
||||
|
||||
**用法:** `SENTRY_DSN=https://xxx@xxx.ingest.sentry.io/xxx bun run dev`
|
||||
|
||||
---
|
||||
|
||||
## 默认关闭自动更新 (2026-04-03)
|
||||
|
||||
修改 `src/utils/config.ts` — `getAutoUpdaterDisabledReason()`,在原有检查逻辑前插入默认关闭逻辑。未设置 `ENABLE_AUTOUPDATER=1` 时,自动更新始终返回 `{ type: 'config' }` 被禁用。
|
||||
|
||||
**启用方式:** `ENABLE_AUTOUPDATER=1 bun run dev`
|
||||
|
||||
**原因:** 本项目为逆向工程/反编译版本,自动更新会覆盖本地修改的代码。
|
||||
|
||||
**同时新增文档:** `docs/auto-updater.md` — 自动更新机制完整审计,涵盖三种安装类型的更新策略、后台轮询、版本门控、原生安装器架构、文件锁、配置项等。
|
||||
|
||||
---
|
||||
|
||||
## WebSearch Bing 适配器补全 (2026-04-03)
|
||||
|
||||
原始 `WebSearchTool` 仅支持 Anthropic API 服务端搜索(`web_search_20250305` server tool),在非官方 API 端点(第三方代理)下搜索功能不可用。本次改动引入适配器架构,新增 Bing 搜索页面解析作为 fallback。
|
||||
|
||||
**新增文件:**
|
||||
|
||||
| 文件 | 说明 |
|
||||
|------|------|
|
||||
| `src/tools/WebSearchTool/adapters/types.ts` | 适配器接口定义:`WebSearchAdapter`、`SearchResult`、`SearchOptions`、`SearchProgress` |
|
||||
| `src/tools/WebSearchTool/adapters/apiAdapter.ts` | API 适配器 — 将原有 `queryModelWithStreaming` 逻辑封装为 `ApiSearchAdapter` |
|
||||
| `src/tools/WebSearchTool/adapters/bingAdapter.ts` | Bing 适配器 — 直接抓取 Bing HTML,正则提取搜索结果 |
|
||||
| `src/tools/WebSearchTool/adapters/index.ts` | 适配器工厂 — 根据环境变量 / API Base URL 选择后端 |
|
||||
| `src/tools/WebSearchTool/__tests__/bingAdapter.test.ts` | Bing 适配器单元测试(32 cases:decodeHtmlEntities、extractBingResults、search mock) |
|
||||
| `src/tools/WebSearchTool/__tests__/bingAdapter.integration.ts` | Bing 适配器集成测试 — 真实网络请求验证 |
|
||||
|
||||
**重构文件:**
|
||||
|
||||
| 文件 | 变更 |
|
||||
|------|------|
|
||||
| `src/tools/WebSearchTool/WebSearchTool.ts` | 从直接调用 API 改为 `createAdapter()` 工厂模式;`isEnabled()` 始终返回 true;删除 ~200 行内联 API 调用逻辑 |
|
||||
| `src/tools/WebFetchTool/utils.ts` | `skipWebFetchPreflight` 默认值从 `!undefined`(即 true)改为显式 `=== false`,使域名预检默认启用 |
|
||||
|
||||
**Bing 适配器关键技术细节:**
|
||||
|
||||
1. **反爬绕过**:使用完整 Edge 浏览器请求头(含 `Sec-Ch-Ua`、`Sec-Fetch-*` 等 13 个标头),避免 Bing 返回 JS 渲染的空页面;`setmkt=en-US` 参数强制美式英语市场,避免 IP 地理定位导致的区域化结果(德语论坛、新加坡金价等不相关内容)
|
||||
2. **URL 解码**(`resolveBingUrl()`):Bing 返回的重定向 URL(`bing.com/ck/a?...&u=a1aHR0cHM6Ly9...`)中 `u` 参数为 base64 编码的真实 URL,需解码后使用
|
||||
3. **摘要提取**(`extractSnippet()`):三级降级策略 — `b_lineclamp` → `b_caption <p>` → `b_caption` 直接文本
|
||||
4. **HTML 实体解码**(`decodeHtmlEntities()`):处理 7 种常见 HTML 实体
|
||||
5. **域过滤**:客户端侧 `allowedDomains` / `blockedDomains` 过滤,支持子域名匹配
|
||||
|
||||
**当前状态**:`adapters/index.ts` 中 `createAdapter()` 硬编码返回 `BingSearchAdapter`,跳过了 API/Bing 自动选择逻辑(原逻辑被注释保留)。未来可通过取消注释恢复自动选择。
|
||||
|
||||
---
|
||||
|
||||
## 移除反蒸馏机制 (2026-04-02)
|
||||
|
||||
项目中发现三处 anti-distillation 相关代码,全部移除。
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
# Claude Code Best V3 (CCB)
|
||||
|
||||
[](https://github.com/claude-code-best/claude-code/stargazers)
|
||||
[](https://github.com/claude-code-best/claude-code/graphs/contributors)
|
||||
[](https://github.com/claude-code-best/claude-code/issues)
|
||||
[](https://github.com/claude-code-best/claude-code/blob/main/LICENSE)
|
||||
[](https://github.com/claude-code-best/claude-code/commits/main)
|
||||
[](https://bun.sh/)
|
||||
|
||||
> Which Claude do you like? The open source one is the best.
|
||||
|
||||
牢 A (Anthropic) 官方 [Claude Code](https://docs.anthropic.com/en/docs/claude-code) CLI 工具的源码反编译/逆向还原项目。目标是将 Claude Code 大部分功能及工程化能力复现 (问就是老佛爷已经付过钱了)。虽然很难绷, 但是它叫做 CCB(踩踩背)...
|
||||
|
||||
[文档在这里, 支持投稿 PR](https://ccb.agent-aura.top/)
|
||||
@@ -11,13 +20,19 @@
|
||||
- [ ] Biome 格式化可能不会先实施, 避免代码冲突
|
||||
- [x] 构建流水线完成, 产物 Node/Bun 都可以运行
|
||||
- [x] V3 会写大量文档, 完善文档站点
|
||||
- [ ] V4 会完成大量的测试文件, 以提高稳定性
|
||||
- [x] Buddy 小宠物回来啦
|
||||
- [x] Auto Mode 回归
|
||||
- [x] V4 会完成大量的测试文件, 以提高稳定性
|
||||
- [x] Buddy 小宠物回来啦 [文档](https://ccb.agent-aura.top/docs/features/buddy)
|
||||
- [x] Auto Mode 回归 [文档](https://ccb.agent-aura.top/docs/safety/auto-mode)
|
||||
- [x] 所有 Feature 现在可以通过环境变量配置, 而不是垃圾的 bun --feature
|
||||
- [x] V5 支持企业级的监控上报功能, 补全缺失的工具, 解除限制
|
||||
- [x] 移除牢 A 的反蒸馏代码!!!
|
||||
- [ ] V5 大规模重构石山代码, 全面模块分包
|
||||
- [ ] V5 将会为全新分支, 届时 main 分支将会封存为历史版本
|
||||
- [x] 补全 web search 能力(用的 Bing 搜索)!!! [文档](https://ccb.agent-aura.top/docs/features/web-browser-tool)
|
||||
- [x] 支持 Debug [文档](https://ccb.agent-aura.top/docs/features/debug-mode)
|
||||
- [x] 关闭自动更新;
|
||||
- [x] 添加自定义 sentry 错误上报支持 [文档](https://ccb.agent-aura.top/docs/internals/sentry-setup)
|
||||
- [x] 添加自定义 GrowthBook 支持 (GB 也是开源的, 现在你可以配置一个自定义的遥控平台) [文档](https://ccb.agent-aura.top/docs/internals/growthbook-adapter)
|
||||
- [ ] V6 大规模重构石山代码, 全面模块分包
|
||||
- [ ] V6 将会为全新分支, 届时 main 分支将会封存为历史版本
|
||||
|
||||
> 我不知道这个项目还会存在多久, Star + Fork + git clone + .zip 包最稳健; 说白了就是扛旗项目, 看看能走多远
|
||||
>
|
||||
@@ -26,14 +41,6 @@
|
||||
> Claude 已经烧了 1000$ 以上, 没钱了, 换成 GLM 继续玩; @zai-org GLM 5.1 非常可以;
|
||||
>
|
||||
|
||||
存活记录:
|
||||
|
||||
1. 开源后 36 小时, 9.7k star; 特权模式可以开启了, 新 feature 调控也加上了;加把劲明天就 10k 了;
|
||||
2. 开源后 48 小时: 突破 7k Star; 测试代码小有成效;
|
||||
3. 开源后 24 小时: 突破 6k Star, 感谢各位支持. 完成 docs 文档的站点构建, 达到 v3 版本, 后续开始进行测试用例维护, 完成之后可以接受 PR; 看来牢 A 是不想理我们了;
|
||||
4. 开源后 15 小时: 完成了构建产物的 node 支持, 现在是完全体了; star 快到 3k 了; 等待牢 A 的邮件
|
||||
5. 开源后 12 小时: 愚人节, star 破 1k, 并且牢 A 没有发邮件搞这个项目
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 环境要求
|
||||
@@ -65,9 +72,44 @@ bun run build
|
||||
|
||||
如果遇到 bug 请直接提一个 issues, 我们优先解决
|
||||
|
||||
## Feature Flags
|
||||
|
||||
所有功能开关通过 `FEATURE_<FLAG_NAME>=1` 环境变量启用,例如:
|
||||
|
||||
```bash
|
||||
FEATURE_BUDDY=1 FEATURE_FORK_SUBAGENT=1 bun run dev
|
||||
```
|
||||
|
||||
各 Feature 的详细说明见 [`docs/features/`](docs/features/) 目录,欢迎投稿补充。
|
||||
|
||||
## VS Code 调试
|
||||
|
||||
TUI (REPL) 模式需要真实终端,无法直接通过 VS Code launch 启动调试。使用 **attach 模式**:
|
||||
|
||||
### 步骤
|
||||
|
||||
1. **终端启动 inspect 服务**:
|
||||
```bash
|
||||
bun run dev:inspect
|
||||
```
|
||||
会输出类似 `ws://localhost:8888/xxxxxxxx` 的地址。
|
||||
|
||||
2. **VS Code 附着调试器**:
|
||||
- 在 `src/` 文件中打断点
|
||||
- F5 → 选择 **"Attach to Bun (TUI debug)"**
|
||||
|
||||
> 注意:`dev:inspect` 和 `launch.json` 中的 WebSocket 地址会在每次启动时变化,需要同步更新两处。
|
||||
|
||||
## 相关文档及网站
|
||||
|
||||
<https://deepwiki.com/claude-code-best/claude-code>
|
||||
- **在线文档(Mintlify)**: [ccb.agent-aura.top](https://ccb.agent-aura.top/) — 文档源码位于 [`docs/`](docs/) 目录,欢迎投稿 PR
|
||||
- **DeepWiki**: <https://deepwiki.com/claude-code-best/claude-code>
|
||||
|
||||
## Contributors
|
||||
|
||||
<a href="https://github.com/claude-code-best/claude-code/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=claude-code-best/claude-code" />
|
||||
</a>
|
||||
|
||||
## Star History
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
"@opentelemetry/sdk-metrics": "^2.6.1",
|
||||
"@opentelemetry/sdk-trace-base": "^2.6.1",
|
||||
"@opentelemetry/semantic-conventions": "^1.40.0",
|
||||
"@sentry/node": "^10.47.0",
|
||||
"@smithy/core": "^3.23.13",
|
||||
"@smithy/node-http-handler": "^4.5.1",
|
||||
"@types/bun": "^1.3.11",
|
||||
@@ -76,6 +77,7 @@
|
||||
"fuse.js": "^7.1.0",
|
||||
"get-east-asian-width": "^1.5.0",
|
||||
"google-auth-library": "^10.6.2",
|
||||
"he": "^1.2.0",
|
||||
"highlight.js": "^11.11.1",
|
||||
"https-proxy-agent": "^8.0.0",
|
||||
"ignore": "^7.0.5",
|
||||
@@ -315,6 +317,8 @@
|
||||
|
||||
"@emnapi/wasi-threads": ["@emnapi/wasi-threads@1.2.0", "https://registry.npmmirror.com/@emnapi/wasi-threads/-/wasi-threads-1.2.0.tgz", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-N10dEJNSsUx41Z6pZsXU8FjPjpBEplgH24sfkmITrBED1/U2Esum9F3lfLrMjKHHjmi557zQn7kR9R+XWXu5Rg=="],
|
||||
|
||||
"@fastify/otel": ["@fastify/otel@0.18.0", "https://registry.npmmirror.com/@fastify/otel/-/otel-0.18.0.tgz", { "dependencies": { "@opentelemetry/core": "^2.0.0", "@opentelemetry/instrumentation": "^0.212.0", "@opentelemetry/semantic-conventions": "^1.28.0", "minimatch": "^10.2.4" }, "peerDependencies": { "@opentelemetry/api": "^1.9.0" } }, "sha512-3TASCATfw+ctICSb4ymrv7iCm0qJ0N9CarB+CZ7zIJ7KqNbwI5JjyDL1/sxoC0ccTO1Zyd1iQ+oqncPg5FJXaA=="],
|
||||
|
||||
"@growthbook/growthbook": ["@growthbook/growthbook@1.6.5", "https://registry.npmmirror.com/@growthbook/growthbook/-/growthbook-1.6.5.tgz", { "dependencies": { "dom-mutator": "^0.6.0" } }, "sha512-mUaMsgeUTpRIUOTn33EUXHRK6j7pxBjwqH4WpQyq+pukjd1AIzWlEa6w7i6bInJUcweGgP2beXZmaP6b6UPn7A=="],
|
||||
|
||||
"@grpc/grpc-js": ["@grpc/grpc-js@1.14.3", "https://registry.npmmirror.com/@grpc/grpc-js/-/grpc-js-1.14.3.tgz", { "dependencies": { "@grpc/proto-loader": "^0.8.0", "@js-sdsl/ordered-map": "^4.4.2" } }, "sha512-Iq8QQQ/7X3Sac15oB6p0FmUg/klxQvXLeileoqrTRGJYLV+/9tubbr9ipz0GKHjmXVsgFPo/+W+2cA8eNcR+XA=="],
|
||||
@@ -421,6 +425,8 @@
|
||||
|
||||
"@opentelemetry/api-logs": ["@opentelemetry/api-logs@0.214.0", "https://registry.npmmirror.com/@opentelemetry/api-logs/-/api-logs-0.214.0.tgz", { "dependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-40lSJeqYO8Uz2Yj7u94/SJWE/wONa7rmMKjI1ZcIjgf3MHNHv1OZUCrCETGuaRF62d5pQD1wKIW+L4lmSMTzZA=="],
|
||||
|
||||
"@opentelemetry/context-async-hooks": ["@opentelemetry/context-async-hooks@2.6.1", "https://registry.npmmirror.com/@opentelemetry/context-async-hooks/-/context-async-hooks-2.6.1.tgz", { "peerDependencies": { "@opentelemetry/api": ">=1.0.0 <1.10.0" } }, "sha512-XHzhwRNkBpeP8Fs/qjGrAf9r9PRv67wkJQ/7ZPaBQQ68DYlTBBx5MF9LvPx7mhuXcDessKK2b+DcxqwpgkcivQ=="],
|
||||
|
||||
"@opentelemetry/core": ["@opentelemetry/core@2.6.1", "https://registry.npmmirror.com/@opentelemetry/core/-/core-2.6.1.tgz", { "dependencies": { "@opentelemetry/semantic-conventions": "^1.29.0" }, "peerDependencies": { "@opentelemetry/api": ">=1.0.0 <1.10.0" } }, "sha512-8xHSGWpJP9wBxgBpnqGL0R3PbdWQndL1Qp50qrg71+B28zK5OQmUgcDKLJgzyAAV38t4tOyLMGDD60LneR5W8g=="],
|
||||
|
||||
"@opentelemetry/exporter-logs-otlp-grpc": ["@opentelemetry/exporter-logs-otlp-grpc@0.214.0", "https://registry.npmmirror.com/@opentelemetry/exporter-logs-otlp-grpc/-/exporter-logs-otlp-grpc-0.214.0.tgz", { "dependencies": { "@grpc/grpc-js": "^1.14.3", "@opentelemetry/core": "2.6.1", "@opentelemetry/otlp-exporter-base": "0.214.0", "@opentelemetry/otlp-grpc-exporter-base": "0.214.0", "@opentelemetry/otlp-transformer": "0.214.0", "@opentelemetry/sdk-logs": "0.214.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-SwmFRwO8mi6nndzbsjPgSFg7qy1WeNHRFD+s6uCsdiUDUt3+yzI2qiHE3/ub2f37+/CbeGcG+Ugc8Gwr6nu2Aw=="],
|
||||
@@ -443,12 +449,60 @@
|
||||
|
||||
"@opentelemetry/exporter-trace-otlp-proto": ["@opentelemetry/exporter-trace-otlp-proto@0.214.0", "https://registry.npmmirror.com/@opentelemetry/exporter-trace-otlp-proto/-/exporter-trace-otlp-proto-0.214.0.tgz", { "dependencies": { "@opentelemetry/core": "2.6.1", "@opentelemetry/otlp-exporter-base": "0.214.0", "@opentelemetry/otlp-transformer": "0.214.0", "@opentelemetry/resources": "2.6.1", "@opentelemetry/sdk-trace-base": "2.6.1" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-ON0spYWb2yAdQ9b+ItNyK0c6qdtcs+0eVR4YFJkhJL7agfT8sHFg0e5EesauSRiTHPZHiDobI92k77q0lwAmqg=="],
|
||||
|
||||
"@opentelemetry/instrumentation": ["@opentelemetry/instrumentation@0.214.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation/-/instrumentation-0.214.0.tgz", { "dependencies": { "@opentelemetry/api-logs": "0.214.0", "import-in-the-middle": "^3.0.0", "require-in-the-middle": "^8.0.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-MHqEX5Dk59cqVah5LiARMACku7jXSVk9iVDWOea4x3cr7VfdByeDCURK6o1lntT1JS/Tsovw01UJrBhN3/uC5w=="],
|
||||
|
||||
"@opentelemetry/instrumentation-amqplib": ["@opentelemetry/instrumentation-amqplib@0.61.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-amqplib/-/instrumentation-amqplib-0.61.0.tgz", { "dependencies": { "@opentelemetry/core": "^2.0.0", "@opentelemetry/instrumentation": "^0.214.0", "@opentelemetry/semantic-conventions": "^1.33.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-mCKoyTGfRNisge4br0NpOFSy2Z1NnEW8hbCJdUDdJFHrPqVzc4IIBPA/vX0U+LUcQqrQvJX+HMIU0dbDRe0i0Q=="],
|
||||
|
||||
"@opentelemetry/instrumentation-connect": ["@opentelemetry/instrumentation-connect@0.57.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-connect/-/instrumentation-connect-0.57.0.tgz", { "dependencies": { "@opentelemetry/core": "^2.0.0", "@opentelemetry/instrumentation": "^0.214.0", "@opentelemetry/semantic-conventions": "^1.27.0", "@types/connect": "3.4.38" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-FMEBChnI4FLN5TE9DHwfH7QpNir1JzXno1uz/TAucVdLCyrG0jTrKIcNHt/i30A0M2AunNBCkcd8Ei26dIPKdg=="],
|
||||
|
||||
"@opentelemetry/instrumentation-dataloader": ["@opentelemetry/instrumentation-dataloader@0.31.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-dataloader/-/instrumentation-dataloader-0.31.0.tgz", { "dependencies": { "@opentelemetry/instrumentation": "^0.214.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-f654tZFQXS5YeLDNb9KySrwtg7SnqZN119FauD7acBoTzuLduaiGTNz88ixcVSOOMGZ+EjJu/RFtx5klObC95g=="],
|
||||
|
||||
"@opentelemetry/instrumentation-express": ["@opentelemetry/instrumentation-express@0.62.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-express/-/instrumentation-express-0.62.0.tgz", { "dependencies": { "@opentelemetry/core": "^2.0.0", "@opentelemetry/instrumentation": "^0.214.0", "@opentelemetry/semantic-conventions": "^1.27.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-Tvx+vgAZKEQxU3Rx+xWLiR0mLxHwmk69/8ya04+VsV9WYh8w6Lhx5hm5yAMvo1wy0KqWgFKBLwSeo3sHCwdOww=="],
|
||||
|
||||
"@opentelemetry/instrumentation-fs": ["@opentelemetry/instrumentation-fs@0.33.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-fs/-/instrumentation-fs-0.33.0.tgz", { "dependencies": { "@opentelemetry/core": "^2.0.0", "@opentelemetry/instrumentation": "^0.214.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-sCZWXGalQ01wr3tAhSR9ucqFJ0phidpAle6/17HVjD6gN8FLmZMK/8sKxdXYHy3PbnlV1P4zeiSVFNKpbFMNLA=="],
|
||||
|
||||
"@opentelemetry/instrumentation-generic-pool": ["@opentelemetry/instrumentation-generic-pool@0.57.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-generic-pool/-/instrumentation-generic-pool-0.57.0.tgz", { "dependencies": { "@opentelemetry/instrumentation": "^0.214.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-orhmlaK+ZIW9hKU+nHTbXrCSXZcH83AescTqmpamHRobRmYSQwRbD0a1odc0yAzuzOtxYiHiXAnpnIpaSSY7Ow=="],
|
||||
|
||||
"@opentelemetry/instrumentation-graphql": ["@opentelemetry/instrumentation-graphql@0.62.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-graphql/-/instrumentation-graphql-0.62.0.tgz", { "dependencies": { "@opentelemetry/instrumentation": "^0.214.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-3YNuLVPUxafXkH1jBAbGsKNsP3XVzcFDhCDCE3OqBwCwShlqQbLMRMFh1T/d5jaVZiGVmSsfof+ICKD2iOV8xg=="],
|
||||
|
||||
"@opentelemetry/instrumentation-hapi": ["@opentelemetry/instrumentation-hapi@0.60.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-hapi/-/instrumentation-hapi-0.60.0.tgz", { "dependencies": { "@opentelemetry/core": "^2.0.0", "@opentelemetry/instrumentation": "^0.214.0", "@opentelemetry/semantic-conventions": "^1.27.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-aNljZKYrEa7obLAxd1bCEDxF7kzCLGXTuTJZ8lMR9rIVEjmuKBXN1gfqpm/OB//Zc2zP4iIve1jBp7sr3mQV6w=="],
|
||||
|
||||
"@opentelemetry/instrumentation-http": ["@opentelemetry/instrumentation-http@0.214.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-http/-/instrumentation-http-0.214.0.tgz", { "dependencies": { "@opentelemetry/core": "2.6.1", "@opentelemetry/instrumentation": "0.214.0", "@opentelemetry/semantic-conventions": "^1.29.0", "forwarded-parse": "2.1.2" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-FlkDhZDRjDJDcO2LcSCtjRpkal1NJ8y0fBqBhTvfAR3JSYY2jAIj1kSS5IjmEBt4c3aWv+u/lqLuoCDrrKCSKg=="],
|
||||
|
||||
"@opentelemetry/instrumentation-ioredis": ["@opentelemetry/instrumentation-ioredis@0.62.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-ioredis/-/instrumentation-ioredis-0.62.0.tgz", { "dependencies": { "@opentelemetry/instrumentation": "^0.214.0", "@opentelemetry/redis-common": "^0.38.2", "@opentelemetry/semantic-conventions": "^1.33.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-ZYt//zcPve8qklaZX+5Z4MkU7UpEkFRrxsf2cnaKYBitqDnsCN69CPAuuMOX6NYdW2rG9sFy7V/QWtBlP5XiNQ=="],
|
||||
|
||||
"@opentelemetry/instrumentation-kafkajs": ["@opentelemetry/instrumentation-kafkajs@0.23.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-kafkajs/-/instrumentation-kafkajs-0.23.0.tgz", { "dependencies": { "@opentelemetry/instrumentation": "^0.214.0", "@opentelemetry/semantic-conventions": "^1.30.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-4K+nVo+zI+aDz0Z85SObwbdixIbzS9moIuKJaYsdlzcHYnKOPtB7ya8r8Ezivy/GVIBHiKJVq4tv+BEkgOMLaQ=="],
|
||||
|
||||
"@opentelemetry/instrumentation-knex": ["@opentelemetry/instrumentation-knex@0.58.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-knex/-/instrumentation-knex-0.58.0.tgz", { "dependencies": { "@opentelemetry/instrumentation": "^0.214.0", "@opentelemetry/semantic-conventions": "^1.33.1" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-Hc/o8fSsaWxZ8r1Yw4rNDLwTpUopTf4X32y4W6UhlHmW8Wizz8wfhgOKIelSeqFVTKBBPIDUOsQWuIMxBmu8Bw=="],
|
||||
|
||||
"@opentelemetry/instrumentation-koa": ["@opentelemetry/instrumentation-koa@0.62.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-koa/-/instrumentation-koa-0.62.0.tgz", { "dependencies": { "@opentelemetry/core": "^2.0.0", "@opentelemetry/instrumentation": "^0.214.0", "@opentelemetry/semantic-conventions": "^1.36.0" }, "peerDependencies": { "@opentelemetry/api": "^1.9.0" } }, "sha512-uVip0VuGUQXZ+vFxkKxAUNq8qNl+VFlyHDh/U6IQ8COOEDfbEchdaHnpFrMYF3psZRUuoSIgb7xOeXj00RdwDA=="],
|
||||
|
||||
"@opentelemetry/instrumentation-lru-memoizer": ["@opentelemetry/instrumentation-lru-memoizer@0.58.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-lru-memoizer/-/instrumentation-lru-memoizer-0.58.0.tgz", { "dependencies": { "@opentelemetry/instrumentation": "^0.214.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-6grM3TdMyHzlGY1cUA+mwoPueB1F3dYKgKtZIH6jOFXqfHAByyLTc+6PFjGM9tKh52CFBJaDwodNlL/Td39z7Q=="],
|
||||
|
||||
"@opentelemetry/instrumentation-mongodb": ["@opentelemetry/instrumentation-mongodb@0.67.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-mongodb/-/instrumentation-mongodb-0.67.0.tgz", { "dependencies": { "@opentelemetry/instrumentation": "^0.214.0", "@opentelemetry/semantic-conventions": "^1.33.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-1WJp5N1lYfHq2IhECOTewFs5Tf2NfUOwQRqs/rZdXKTezArMlucxgzAaqcgp3A3YREXopXTpXHsxZTGHjNhMdQ=="],
|
||||
|
||||
"@opentelemetry/instrumentation-mongoose": ["@opentelemetry/instrumentation-mongoose@0.60.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-mongoose/-/instrumentation-mongoose-0.60.0.tgz", { "dependencies": { "@opentelemetry/core": "^2.0.0", "@opentelemetry/instrumentation": "^0.214.0", "@opentelemetry/semantic-conventions": "^1.33.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-8BahAZpKsOoc+lrZGb7Ofn4g3z8qtp5IxDfvAVpKXsEheQN7ONMH5djT5ihy6yf8yyeQJGS0gXFfpEAEeEHqQg=="],
|
||||
|
||||
"@opentelemetry/instrumentation-mysql": ["@opentelemetry/instrumentation-mysql@0.60.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-mysql/-/instrumentation-mysql-0.60.0.tgz", { "dependencies": { "@opentelemetry/instrumentation": "^0.214.0", "@opentelemetry/semantic-conventions": "^1.33.0", "@types/mysql": "2.15.27" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-08pO8GFPEIz2zquKDGteBZDNmwketdgH8hTe9rVYgW9kCJXq1Psj3wPQGx+VaX4ZJKCfPeoLMYup9+cxHvZyVQ=="],
|
||||
|
||||
"@opentelemetry/instrumentation-mysql2": ["@opentelemetry/instrumentation-mysql2@0.60.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-mysql2/-/instrumentation-mysql2-0.60.0.tgz", { "dependencies": { "@opentelemetry/instrumentation": "^0.214.0", "@opentelemetry/semantic-conventions": "^1.33.0", "@opentelemetry/sql-common": "^0.41.2" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-m/5d3bxQALllCzezYDk/6vajh0tj5OijMMvOZGr+qN1NMXm1dzMNwyJ0gNZW7Fo3YFRyj/jJMxIw+W7d525dlw=="],
|
||||
|
||||
"@opentelemetry/instrumentation-pg": ["@opentelemetry/instrumentation-pg@0.66.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-pg/-/instrumentation-pg-0.66.0.tgz", { "dependencies": { "@opentelemetry/core": "^2.0.0", "@opentelemetry/instrumentation": "^0.214.0", "@opentelemetry/semantic-conventions": "^1.34.0", "@opentelemetry/sql-common": "^0.41.2", "@types/pg": "8.15.6", "@types/pg-pool": "2.0.7" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-KxfLGXBb7k2ueaPJfq2GXBDXBly8P+SpR/4Mj410hhNgmQF3sCqwXvUBQxZQkDAmsdBAoenM+yV1LhtsMRamcA=="],
|
||||
|
||||
"@opentelemetry/instrumentation-redis": ["@opentelemetry/instrumentation-redis@0.62.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-redis/-/instrumentation-redis-0.62.0.tgz", { "dependencies": { "@opentelemetry/instrumentation": "^0.214.0", "@opentelemetry/redis-common": "^0.38.2", "@opentelemetry/semantic-conventions": "^1.27.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-y3pPpot7WzR/8JtHcYlTYsyY8g+pbFhAqbwAuG5bLPnR6v6pt1rQc0DpH0OlGP/9CZbWBP+Zhwp9yFoygf/ZXQ=="],
|
||||
|
||||
"@opentelemetry/instrumentation-tedious": ["@opentelemetry/instrumentation-tedious@0.33.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-tedious/-/instrumentation-tedious-0.33.0.tgz", { "dependencies": { "@opentelemetry/instrumentation": "^0.214.0", "@opentelemetry/semantic-conventions": "^1.33.0", "@types/tedious": "^4.0.14" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-Q6WQwAD01MMTub31GlejoiFACYNw26J426wyjvU7by7fDIr2nZXNW4vhTGs7i7F0TnXBO3xN688g1tdUgYwJ5w=="],
|
||||
|
||||
"@opentelemetry/instrumentation-undici": ["@opentelemetry/instrumentation-undici@0.24.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation-undici/-/instrumentation-undici-0.24.0.tgz", { "dependencies": { "@opentelemetry/core": "^2.0.0", "@opentelemetry/instrumentation": "^0.214.0", "@opentelemetry/semantic-conventions": "^1.24.0" }, "peerDependencies": { "@opentelemetry/api": "^1.7.0" } }, "sha512-oKzZ3uvqP17sV0EsoQcJgjEfIp0kiZRbYu/eD8p13Cbahumf8lb/xpYeNr/hfAJ4owzEtIDcGIjprfLcYbIKBQ=="],
|
||||
|
||||
"@opentelemetry/otlp-exporter-base": ["@opentelemetry/otlp-exporter-base@0.214.0", "https://registry.npmmirror.com/@opentelemetry/otlp-exporter-base/-/otlp-exporter-base-0.214.0.tgz", { "dependencies": { "@opentelemetry/core": "2.6.1", "@opentelemetry/otlp-transformer": "0.214.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-u1Gdv0/E9wP+apqWf7Wv2npXmgJtxsW2XL0TEv9FZloTZRuMBKmu8cYVXwS4Hm3q/f/3FuCnPTgiwYvIqRSpRg=="],
|
||||
|
||||
"@opentelemetry/otlp-grpc-exporter-base": ["@opentelemetry/otlp-grpc-exporter-base@0.214.0", "https://registry.npmmirror.com/@opentelemetry/otlp-grpc-exporter-base/-/otlp-grpc-exporter-base-0.214.0.tgz", { "dependencies": { "@grpc/grpc-js": "^1.14.3", "@opentelemetry/core": "2.6.1", "@opentelemetry/otlp-exporter-base": "0.214.0", "@opentelemetry/otlp-transformer": "0.214.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-IDP6zcyA24RhNZ289MP6eToIZcinlmirHjX8v3zKCQ2ZhPpt5cGwkN91tCth337lqHIgWcTy90uKRiX/SzALDw=="],
|
||||
|
||||
"@opentelemetry/otlp-transformer": ["@opentelemetry/otlp-transformer@0.214.0", "https://registry.npmmirror.com/@opentelemetry/otlp-transformer/-/otlp-transformer-0.214.0.tgz", { "dependencies": { "@opentelemetry/api-logs": "0.214.0", "@opentelemetry/core": "2.6.1", "@opentelemetry/resources": "2.6.1", "@opentelemetry/sdk-logs": "0.214.0", "@opentelemetry/sdk-metrics": "2.6.1", "@opentelemetry/sdk-trace-base": "2.6.1", "protobufjs": "^7.0.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-DSaYcuBRh6uozfsWN3R8HsN0yDhCuWP7tOFdkUOVaWD1KVJg8m4qiLUsg/tNhTLS9HUYUcwNpwL2eroLtsZZ/w=="],
|
||||
|
||||
"@opentelemetry/redis-common": ["@opentelemetry/redis-common@0.38.2", "https://registry.npmmirror.com/@opentelemetry/redis-common/-/redis-common-0.38.2.tgz", {}, "sha512-1BCcU93iwSRZvDAgwUxC/DV4T/406SkMfxGqu5ojc3AvNI+I9GhV7v0J1HljsczuuhcnFLYqD5VmwVXfCGHzxA=="],
|
||||
|
||||
"@opentelemetry/resources": ["@opentelemetry/resources@2.6.1", "https://registry.npmmirror.com/@opentelemetry/resources/-/resources-2.6.1.tgz", { "dependencies": { "@opentelemetry/core": "2.6.1", "@opentelemetry/semantic-conventions": "^1.29.0" }, "peerDependencies": { "@opentelemetry/api": ">=1.3.0 <1.10.0" } }, "sha512-lID/vxSuKWXM55XhAKNoYXu9Cutoq5hFdkbTdI/zDKQktXzcWBVhNsOkiZFTMU9UtEWuGRNe0HUgmsFldIdxVA=="],
|
||||
|
||||
"@opentelemetry/sdk-logs": ["@opentelemetry/sdk-logs@0.214.0", "https://registry.npmmirror.com/@opentelemetry/sdk-logs/-/sdk-logs-0.214.0.tgz", { "dependencies": { "@opentelemetry/api-logs": "0.214.0", "@opentelemetry/core": "2.6.1", "@opentelemetry/resources": "2.6.1", "@opentelemetry/semantic-conventions": "^1.29.0" }, "peerDependencies": { "@opentelemetry/api": ">=1.4.0 <1.10.0" } }, "sha512-zf6acnScjhsaBUU22zXZ/sLWim1dfhUAbGXdMmHmNG3LfBnQ3DKsOCITb2IZwoUsNNMTogqFKBnlIPPftUgGwA=="],
|
||||
@@ -459,6 +513,8 @@
|
||||
|
||||
"@opentelemetry/semantic-conventions": ["@opentelemetry/semantic-conventions@1.40.0", "https://registry.npmmirror.com/@opentelemetry/semantic-conventions/-/semantic-conventions-1.40.0.tgz", {}, "sha512-cifvXDhcqMwwTlTK04GBNeIe7yyo28Mfby85QXFe1Yk8nmi36Ab/5UQwptOx84SsoGNRg+EVSjwzfSZMy6pmlw=="],
|
||||
|
||||
"@opentelemetry/sql-common": ["@opentelemetry/sql-common@0.41.2", "https://registry.npmmirror.com/@opentelemetry/sql-common/-/sql-common-0.41.2.tgz", { "dependencies": { "@opentelemetry/core": "^2.0.0" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0" } }, "sha512-4mhWm3Z8z+i508zQJ7r6Xi7y4mmoJpdvH0fZPFRkWrdp5fq7hhZ2HhYokEOLkfqSMgPR4Z9EyB3DBkbKGOqZiQ=="],
|
||||
|
||||
"@oxc-parser/binding-android-arm-eabi": ["@oxc-parser/binding-android-arm-eabi@0.121.0", "https://registry.npmmirror.com/@oxc-parser/binding-android-arm-eabi/-/binding-android-arm-eabi-0.121.0.tgz", { "os": "android", "cpu": "arm" }, "sha512-n07FQcySwOlzap424/PLMtOkbS7xOu8nsJduKL8P3COGHKgKoDYXwoAHCbChfgFpHnviehrLWIPX0lKGtbEk/A=="],
|
||||
|
||||
"@oxc-parser/binding-android-arm64": ["@oxc-parser/binding-android-arm64@0.121.0", "https://registry.npmmirror.com/@oxc-parser/binding-android-arm64/-/binding-android-arm64-0.121.0.tgz", { "os": "android", "cpu": "arm64" }, "sha512-/Dd1xIXboYAicw+twT2utxPD7bL8qh7d3ej0qvaYIMj3/EgIrGR+tSnjCUkiCT6g6uTC0neSS4JY8LxhdSU/sA=="],
|
||||
@@ -543,6 +599,8 @@
|
||||
|
||||
"@pondwader/socks5-server": ["@pondwader/socks5-server@1.0.10", "https://registry.npmmirror.com/@pondwader/socks5-server/-/socks5-server-1.0.10.tgz", {}, "sha512-bQY06wzzR8D2+vVCUoBsr5QS2U6UgPUQRmErNwtsuI6vLcyRKkafjkr3KxbtGFf9aBBIV2mcvlsKD1UYaIV+sg=="],
|
||||
|
||||
"@prisma/instrumentation": ["@prisma/instrumentation@7.6.0", "https://registry.npmmirror.com/@prisma/instrumentation/-/instrumentation-7.6.0.tgz", { "dependencies": { "@opentelemetry/instrumentation": "^0.207.0" }, "peerDependencies": { "@opentelemetry/api": "^1.8" } }, "sha512-ZPW2gRiwpPzEfgeZgaekhqXrbW+Y2RJKHVqUmlhZhKzRNCcvR6DykzylDrynpArKKRQtLxoZy36fK7U0p3pdgQ=="],
|
||||
|
||||
"@protobufjs/aspromise": ["@protobufjs/aspromise@1.1.2", "https://registry.npmmirror.com/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", {}, "sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ=="],
|
||||
|
||||
"@protobufjs/base64": ["@protobufjs/base64@1.1.2", "https://registry.npmmirror.com/@protobufjs/base64/-/base64-1.1.2.tgz", {}, "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg=="],
|
||||
@@ -565,6 +623,14 @@
|
||||
|
||||
"@sec-ant/readable-stream": ["@sec-ant/readable-stream@0.4.1", "https://registry.npmmirror.com/@sec-ant/readable-stream/-/readable-stream-0.4.1.tgz", {}, "sha512-831qok9r2t8AlxLko40y2ebgSDhenenCatLVeW/uBtnHPyhHOvG0C7TvfgecV+wHzIm5KUICgzmVpWS+IMEAeg=="],
|
||||
|
||||
"@sentry/core": ["@sentry/core@10.47.0", "https://registry.npmmirror.com/@sentry/core/-/core-10.47.0.tgz", {}, "sha512-nsYRAx3EWezDut+Zl+UwwP07thh9uY7CfSAi2whTdcJl5hu1nSp2z8bba7Vq/MGbNLnazkd3A+GITBEML924JA=="],
|
||||
|
||||
"@sentry/node": ["@sentry/node@10.47.0", "https://registry.npmmirror.com/@sentry/node/-/node-10.47.0.tgz", { "dependencies": { "@fastify/otel": "0.18.0", "@opentelemetry/api": "^1.9.1", "@opentelemetry/context-async-hooks": "^2.6.1", "@opentelemetry/core": "^2.6.1", "@opentelemetry/instrumentation": "^0.214.0", "@opentelemetry/instrumentation-amqplib": "0.61.0", "@opentelemetry/instrumentation-connect": "0.57.0", "@opentelemetry/instrumentation-dataloader": "0.31.0", "@opentelemetry/instrumentation-express": "0.62.0", "@opentelemetry/instrumentation-fs": "0.33.0", "@opentelemetry/instrumentation-generic-pool": "0.57.0", "@opentelemetry/instrumentation-graphql": "0.62.0", "@opentelemetry/instrumentation-hapi": "0.60.0", "@opentelemetry/instrumentation-http": "0.214.0", "@opentelemetry/instrumentation-ioredis": "0.62.0", "@opentelemetry/instrumentation-kafkajs": "0.23.0", "@opentelemetry/instrumentation-knex": "0.58.0", "@opentelemetry/instrumentation-koa": "0.62.0", "@opentelemetry/instrumentation-lru-memoizer": "0.58.0", "@opentelemetry/instrumentation-mongodb": "0.67.0", "@opentelemetry/instrumentation-mongoose": "0.60.0", "@opentelemetry/instrumentation-mysql": "0.60.0", "@opentelemetry/instrumentation-mysql2": "0.60.0", "@opentelemetry/instrumentation-pg": "0.66.0", "@opentelemetry/instrumentation-redis": "0.62.0", "@opentelemetry/instrumentation-tedious": "0.33.0", "@opentelemetry/instrumentation-undici": "0.24.0", "@opentelemetry/resources": "^2.6.1", "@opentelemetry/sdk-trace-base": "^2.6.1", "@opentelemetry/semantic-conventions": "^1.40.0", "@prisma/instrumentation": "7.6.0", "@sentry/core": "10.47.0", "@sentry/node-core": "10.47.0", "@sentry/opentelemetry": "10.47.0", "import-in-the-middle": "^3.0.0" } }, "sha512-R+btqPepv88o635G6HtVewLjqCLUedBg5HBs7Nq1qbbKvyti01uArUF2f+3DsLenk5B9LUNiRlE+frZA44Ahmw=="],
|
||||
|
||||
"@sentry/node-core": ["@sentry/node-core@10.47.0", "https://registry.npmmirror.com/@sentry/node-core/-/node-core-10.47.0.tgz", { "dependencies": { "@sentry/core": "10.47.0", "@sentry/opentelemetry": "10.47.0", "import-in-the-middle": "^3.0.0" }, "peerDependencies": { "@opentelemetry/api": "^1.9.0", "@opentelemetry/context-async-hooks": "^1.30.1 || ^2.1.0", "@opentelemetry/core": "^1.30.1 || ^2.1.0", "@opentelemetry/exporter-trace-otlp-http": ">=0.57.0 <1", "@opentelemetry/instrumentation": ">=0.57.1 <1", "@opentelemetry/resources": "^1.30.1 || ^2.1.0", "@opentelemetry/sdk-trace-base": "^1.30.1 || ^2.1.0", "@opentelemetry/semantic-conventions": "^1.39.0" }, "optionalPeers": ["@opentelemetry/api", "@opentelemetry/context-async-hooks", "@opentelemetry/core", "@opentelemetry/exporter-trace-otlp-http", "@opentelemetry/instrumentation", "@opentelemetry/resources", "@opentelemetry/sdk-trace-base", "@opentelemetry/semantic-conventions"] }, "sha512-qv6LsqHbkQmd0aQEUox/svRSz26J+l4gGjFOUNEay2armZu9XLD+Ct89jpFgZD5oIPNAj2jraodTRqydXiwS5w=="],
|
||||
|
||||
"@sentry/opentelemetry": ["@sentry/opentelemetry@10.47.0", "https://registry.npmmirror.com/@sentry/opentelemetry/-/opentelemetry-10.47.0.tgz", { "dependencies": { "@sentry/core": "10.47.0" }, "peerDependencies": { "@opentelemetry/api": "^1.9.0", "@opentelemetry/context-async-hooks": "^1.30.1 || ^2.1.0", "@opentelemetry/core": "^1.30.1 || ^2.1.0", "@opentelemetry/sdk-trace-base": "^1.30.1 || ^2.1.0", "@opentelemetry/semantic-conventions": "^1.39.0" } }, "sha512-f6Hw2lrpCjlOksiosP0Z2jK/+l+21SIdoNglVeG/sttMyx8C8ywONKh0Ha50sFsvB1VaB8n94RKzzf3hkh9V3g=="],
|
||||
|
||||
"@sindresorhus/merge-streams": ["@sindresorhus/merge-streams@4.0.0", "https://registry.npmmirror.com/@sindresorhus/merge-streams/-/merge-streams-4.0.0.tgz", {}, "sha512-tlqY9xq5ukxTUZBmoOp+m61cqwQD5pHJtFY3Mn8CA8ps6yghLH/Hw8UPdqg4OLmFW3IFlcXnQNmo/dh8HzXYIQ=="],
|
||||
|
||||
"@smithy/abort-controller": ["@smithy/abort-controller@2.2.0", "https://registry.npmmirror.com/@smithy/abort-controller/-/abort-controller-2.2.0.tgz", { "dependencies": { "@smithy/types": "^2.12.0", "tslib": "^2.6.2" } }, "sha512-wRlta7GuLWpTqtFfGo+nZyOO1vEvewdNR1R4rTxpC8XU6vG/NDyrFBhwLZsqg1NUoR1noVaXJPC/7ZK47QCySw=="],
|
||||
@@ -663,14 +729,22 @@
|
||||
|
||||
"@types/cacache": ["@types/cacache@20.0.1", "https://registry.npmmirror.com/@types/cacache/-/cacache-20.0.1.tgz", { "dependencies": { "@types/node": "*", "minipass": "*" } }, "sha512-QlKW3AFoFr/hvPHwFHMIVUH/ZCYeetBNou3PCmxu5LaNDvrtBlPJtIA6uhmU9JRt9oxj7IYoqoLcpxtzpPiTcw=="],
|
||||
|
||||
"@types/connect": ["@types/connect@3.4.38", "https://registry.npmmirror.com/@types/connect/-/connect-3.4.38.tgz", { "dependencies": { "@types/node": "*" } }, "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug=="],
|
||||
|
||||
"@types/lodash": ["@types/lodash@4.17.24", "https://registry.npmmirror.com/@types/lodash/-/lodash-4.17.24.tgz", {}, "sha512-gIW7lQLZbue7lRSWEFql49QJJWThrTFFeIMJdp3eH4tKoxm1OvEPg02rm4wCCSHS0cL3/Fizimb35b7k8atwsQ=="],
|
||||
|
||||
"@types/lodash-es": ["@types/lodash-es@4.17.12", "https://registry.npmmirror.com/@types/lodash-es/-/lodash-es-4.17.12.tgz", { "dependencies": { "@types/lodash": "*" } }, "sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ=="],
|
||||
|
||||
"@types/mute-stream": ["@types/mute-stream@0.0.4", "https://registry.npmmirror.com/@types/mute-stream/-/mute-stream-0.0.4.tgz", { "dependencies": { "@types/node": "*" } }, "sha512-CPM9nzrCPPJHQNA9keH9CVkVI+WR5kMa+7XEs5jcGQ0VoAGnLv242w8lIVgwAEfmE4oufJRaTc9PNLQl0ioAow=="],
|
||||
|
||||
"@types/mysql": ["@types/mysql@2.15.27", "https://registry.npmmirror.com/@types/mysql/-/mysql-2.15.27.tgz", { "dependencies": { "@types/node": "*" } }, "sha512-YfWiV16IY0OeBfBCk8+hXKmdTKrKlwKN1MNKAPBu5JYxLwBEZl7QzeEpGnlZb3VMGJrrGmB84gXiH+ofs/TezA=="],
|
||||
|
||||
"@types/node": ["@types/node@25.5.0", "https://registry.npmmirror.com/@types/node/-/node-25.5.0.tgz", { "dependencies": { "undici-types": "~7.18.0" } }, "sha512-jp2P3tQMSxWugkCUKLRPVUpGaL5MVFwF8RDuSRztfwgN1wmqJeMSbKlnEtQqU8UrhTmzEmZdu2I6v2dpp7XIxw=="],
|
||||
|
||||
"@types/pg": ["@types/pg@8.15.6", "https://registry.npmmirror.com/@types/pg/-/pg-8.15.6.tgz", { "dependencies": { "@types/node": "*", "pg-protocol": "*", "pg-types": "^2.2.0" } }, "sha512-NoaMtzhxOrubeL/7UZuNTrejB4MPAJ0RpxZqXQf2qXuVlTPuG6Y8p4u9dKRaue4yjmC7ZhzVO2/Yyyn25znrPQ=="],
|
||||
|
||||
"@types/pg-pool": ["@types/pg-pool@2.0.7", "https://registry.npmmirror.com/@types/pg-pool/-/pg-pool-2.0.7.tgz", { "dependencies": { "@types/pg": "*" } }, "sha512-U4CwmGVQcbEuqpyju8/ptOKg6gEC+Tqsvj2xS9o1g71bUh8twxnC6ZL5rZKCsGN0iyH0CwgUyc9VR5owNQF9Ng=="],
|
||||
|
||||
"@types/plist": ["@types/plist@3.0.5", "https://registry.npmmirror.com/@types/plist/-/plist-3.0.5.tgz", { "dependencies": { "@types/node": "*", "xmlbuilder": ">=11.0.1" } }, "sha512-E6OCaRmAe4WDmWNsL/9RMqdkkzDCY1etutkflWk4c+AcjDU07Pcz1fQwTX0TQz+Pxqn9i4L1TU3UFpjnrcDgxA=="],
|
||||
|
||||
"@types/react": ["@types/react@19.2.14", "https://registry.npmmirror.com/@types/react/-/react-19.2.14.tgz", { "dependencies": { "csstype": "^3.2.2" } }, "sha512-ilcTH/UniCkMdtexkoCN0bI7pMcJDvmQFPvuPvmEaYA/NSfFTAgdUSLAoVjaRJm7+6PvcM+q1zYOwS4wTYMF9w=="],
|
||||
@@ -679,6 +753,8 @@
|
||||
|
||||
"@types/sharp": ["@types/sharp@0.32.0", "https://registry.npmmirror.com/@types/sharp/-/sharp-0.32.0.tgz", { "dependencies": { "sharp": "*" } }, "sha512-OOi3kL+FZDnPhVzsfD37J88FNeZh6gQsGcLc95NbeURRGvmSjeXiDcyWzF2o3yh/gQAUn2uhh/e+CPCa5nwAxw=="],
|
||||
|
||||
"@types/tedious": ["@types/tedious@4.0.14", "https://registry.npmmirror.com/@types/tedious/-/tedious-4.0.14.tgz", { "dependencies": { "@types/node": "*" } }, "sha512-KHPsfX/FoVbUGbyYvk1q9MMQHLPeRZhRJZdO45Q4YjvFkv4hMNghCWTvy7rdKessBsmtz4euWCWAB6/tVpI1Iw=="],
|
||||
|
||||
"@types/turndown": ["@types/turndown@5.0.6", "https://registry.npmmirror.com/@types/turndown/-/turndown-5.0.6.tgz", {}, "sha512-ru00MoyeeouE5BX4gRL+6m/BsDfbRayOskWqUvh7CLGW+UXxHQItqALa38kKnOiZPqJrtzJUgAC2+F0rL1S4Pg=="],
|
||||
|
||||
"@types/wrap-ansi": ["@types/wrap-ansi@3.0.0", "https://registry.npmmirror.com/@types/wrap-ansi/-/wrap-ansi-3.0.0.tgz", {}, "sha512-ltIpx+kM7g/MLRZfkbL7EsCEjfzCcScLpkg37eXEtx5kmrAKBkTJwd1GIAjDSL8wTpM6Hzn5YO4pSb91BEwu1g=="],
|
||||
@@ -689,6 +765,10 @@
|
||||
|
||||
"accepts": ["accepts@2.0.0", "https://registry.npmmirror.com/accepts/-/accepts-2.0.0.tgz", { "dependencies": { "mime-types": "^3.0.0", "negotiator": "^1.0.0" } }, "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng=="],
|
||||
|
||||
"acorn": ["acorn@8.16.0", "https://registry.npmmirror.com/acorn/-/acorn-8.16.0.tgz", { "bin": { "acorn": "bin/acorn" } }, "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw=="],
|
||||
|
||||
"acorn-import-attributes": ["acorn-import-attributes@1.9.5", "https://registry.npmmirror.com/acorn-import-attributes/-/acorn-import-attributes-1.9.5.tgz", { "peerDependencies": { "acorn": "^8" } }, "sha512-n02Vykv5uA3eHGM/Z2dQrcD56kL8TyDb2p1+0P83PClMnC/nc+anbQRhIOWnSq4Ke/KvDPrY3C9hDtC/A3eHnQ=="],
|
||||
|
||||
"agent-base": ["agent-base@8.0.0", "https://registry.npmmirror.com/agent-base/-/agent-base-8.0.0.tgz", {}, "sha512-QT8i0hCz6C/KQ+KTAbSNwCHDGdmUJl2tp2ZpNlGSWCfhUNVbYG2WLE3MdZGBAgXPV4GAvjGMxo+C1hroyxmZEg=="],
|
||||
|
||||
"ajv": ["ajv@8.18.0", "https://registry.npmmirror.com/ajv/-/ajv-8.18.0.tgz", { "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2" } }, "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A=="],
|
||||
@@ -751,6 +831,8 @@
|
||||
|
||||
"chokidar": ["chokidar@5.0.0", "https://registry.npmmirror.com/chokidar/-/chokidar-5.0.0.tgz", { "dependencies": { "readdirp": "^5.0.0" } }, "sha512-TQMmc3w+5AxjpL8iIiwebF73dRDF4fBIieAqGn9RGCWaEVwQ6Fb2cGe31Yns0RRIzii5goJ1Y7xbMwo1TxMplw=="],
|
||||
|
||||
"cjs-module-lexer": ["cjs-module-lexer@2.2.0", "https://registry.npmmirror.com/cjs-module-lexer/-/cjs-module-lexer-2.2.0.tgz", {}, "sha512-4bHTS2YuzUvtoLjdy+98ykbNB5jS0+07EvFNXerqZQJ89F7DI6ET7OQo/HJuW6K0aVsKA9hj9/RVb2kQVOrPDQ=="],
|
||||
|
||||
"cli-boxes": ["cli-boxes@4.0.1", "https://registry.npmmirror.com/cli-boxes/-/cli-boxes-4.0.1.tgz", {}, "sha512-5IOn+jcCEHEraYolBPs/sT4BxYCe2nHg374OPiItB1O96KZFseS2gthU4twyYzeDcFew4DaUM/xwc5BQf08JJw=="],
|
||||
|
||||
"cli-highlight": ["cli-highlight@2.1.11", "https://registry.npmmirror.com/cli-highlight/-/cli-highlight-2.1.11.tgz", { "dependencies": { "chalk": "^4.0.0", "highlight.js": "^10.7.1", "mz": "^2.4.0", "parse5": "^5.1.1", "parse5-htmlparser2-tree-adapter": "^6.0.0", "yargs": "^16.0.0" }, "bin": { "highlight": "bin/highlight" } }, "sha512-9KDcoEVwyUXrjcJNvHD0NFc/hiwe/WPVYIleQh2O1N2Zro5gWJZ/K+3DGn8w8P/F6FxOgzyC5bxDyHIgCSPhGg=="],
|
||||
@@ -897,6 +979,8 @@
|
||||
|
||||
"forwarded": ["forwarded@0.2.0", "https://registry.npmmirror.com/forwarded/-/forwarded-0.2.0.tgz", {}, "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow=="],
|
||||
|
||||
"forwarded-parse": ["forwarded-parse@2.1.2", "https://registry.npmmirror.com/forwarded-parse/-/forwarded-parse-2.1.2.tgz", {}, "sha512-alTFZZQDKMporBH77856pXgzhEzaUVmLCDk+egLgIgHst3Tpndzz8MnKe+GzRJRfvVdn69HhpW7cmXzvtLvJAw=="],
|
||||
|
||||
"fresh": ["fresh@2.0.0", "https://registry.npmmirror.com/fresh/-/fresh-2.0.0.tgz", {}, "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A=="],
|
||||
|
||||
"fs-extra": ["fs-extra@10.1.0", "https://registry.npmmirror.com/fs-extra/-/fs-extra-10.1.0.tgz", { "dependencies": { "graceful-fs": "^4.2.0", "jsonfile": "^6.0.1", "universalify": "^2.0.0" } }, "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ=="],
|
||||
@@ -947,6 +1031,8 @@
|
||||
|
||||
"hasown": ["hasown@2.0.2", "https://registry.npmmirror.com/hasown/-/hasown-2.0.2.tgz", { "dependencies": { "function-bind": "^1.1.2" } }, "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ=="],
|
||||
|
||||
"he": ["he@1.2.0", "https://registry.npmmirror.com/he/-/he-1.2.0.tgz", { "bin": { "he": "bin/he" } }, "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw=="],
|
||||
|
||||
"highlight.js": ["highlight.js@11.11.1", "https://registry.npmmirror.com/highlight.js/-/highlight.js-11.11.1.tgz", {}, "sha512-Xwwo44whKBVCYoliBQwaPvtd/2tYFkRQtXDWj1nackaV2JPXx3L0+Jvd8/qCJ2p+ML0/XVkJ2q+Mr+UVdpJK5w=="],
|
||||
|
||||
"hono": ["hono@4.12.9", "https://registry.npmmirror.com/hono/-/hono-4.12.9.tgz", {}, "sha512-wy3T8Zm2bsEvxKZM5w21VdHDDcwVS1yUFFY6i8UobSsKfFceT7TOwhbhfKsDyx7tYQlmRM5FLpIuYvNFyjctiA=="],
|
||||
@@ -965,6 +1051,8 @@
|
||||
|
||||
"image-processor-napi": ["image-processor-napi@workspace:packages/image-processor-napi"],
|
||||
|
||||
"import-in-the-middle": ["import-in-the-middle@3.0.0", "https://registry.npmmirror.com/import-in-the-middle/-/import-in-the-middle-3.0.0.tgz", { "dependencies": { "acorn": "^8.15.0", "acorn-import-attributes": "^1.9.5", "cjs-module-lexer": "^2.2.0", "module-details-from-path": "^1.0.4" } }, "sha512-OnGy+eYT7wVejH2XWgLRgbmzujhhVIATQH0ztIeRilwHBjTeG3pD+XnH3PKX0r9gJ0BuJmJ68q/oh9qgXnNDQg=="],
|
||||
|
||||
"indent-string": ["indent-string@5.0.0", "https://registry.npmmirror.com/indent-string/-/indent-string-5.0.0.tgz", {}, "sha512-m6FAo/spmsW2Ab2fU35JTYwtOKa2yAwXSwgjSv1TJzh4Mh7mC3lzAOVLBprb72XsTrgkEIsl7YrFNAiDiRhIGg=="],
|
||||
|
||||
"inherits": ["inherits@2.0.4", "https://registry.npmmirror.com/inherits/-/inherits-2.0.4.tgz", {}, "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="],
|
||||
@@ -1081,6 +1169,8 @@
|
||||
|
||||
"modifiers-napi": ["modifiers-napi@workspace:packages/modifiers-napi"],
|
||||
|
||||
"module-details-from-path": ["module-details-from-path@1.0.4", "https://registry.npmmirror.com/module-details-from-path/-/module-details-from-path-1.0.4.tgz", {}, "sha512-EGWKgxALGMgzvxYF1UyGTy0HXX/2vHLkw6+NvDKW2jypWbHpjQuj4UMcqQWXHERJhVGKikolT06G3bcKe4fi7w=="],
|
||||
|
||||
"ms": ["ms@2.1.3", "https://registry.npmmirror.com/ms/-/ms-2.1.3.tgz", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="],
|
||||
|
||||
"mute-stream": ["mute-stream@1.0.0", "https://registry.npmmirror.com/mute-stream/-/mute-stream-1.0.0.tgz", {}, "sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA=="],
|
||||
@@ -1139,6 +1229,12 @@
|
||||
|
||||
"path-to-regexp": ["path-to-regexp@8.4.1", "https://registry.npmmirror.com/path-to-regexp/-/path-to-regexp-8.4.1.tgz", {}, "sha512-fvU78fIjZ+SBM9YwCknCvKOUKkLVqtWDVctl0s7xIqfmfb38t2TT4ZU2gHm+Z8xGwgW+QWEU3oQSAzIbo89Ggw=="],
|
||||
|
||||
"pg-int8": ["pg-int8@1.0.1", "https://registry.npmmirror.com/pg-int8/-/pg-int8-1.0.1.tgz", {}, "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw=="],
|
||||
|
||||
"pg-protocol": ["pg-protocol@1.13.0", "https://registry.npmmirror.com/pg-protocol/-/pg-protocol-1.13.0.tgz", {}, "sha512-zzdvXfS6v89r6v7OcFCHfHlyG/wvry1ALxZo4LqgUoy7W9xhBDMaqOuMiF3qEV45VqsN6rdlcehHrfDtlCPc8w=="],
|
||||
|
||||
"pg-types": ["pg-types@2.2.0", "https://registry.npmmirror.com/pg-types/-/pg-types-2.2.0.tgz", { "dependencies": { "pg-int8": "1.0.1", "postgres-array": "~2.0.0", "postgres-bytea": "~1.0.0", "postgres-date": "~1.0.4", "postgres-interval": "^1.1.0" } }, "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA=="],
|
||||
|
||||
"picocolors": ["picocolors@1.1.1", "https://registry.npmmirror.com/picocolors/-/picocolors-1.1.1.tgz", {}, "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA=="],
|
||||
|
||||
"picomatch": ["picomatch@4.0.4", "https://registry.npmmirror.com/picomatch/-/picomatch-4.0.4.tgz", {}, "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A=="],
|
||||
@@ -1149,6 +1245,14 @@
|
||||
|
||||
"pngjs": ["pngjs@5.0.0", "https://registry.npmmirror.com/pngjs/-/pngjs-5.0.0.tgz", {}, "sha512-40QW5YalBNfQo5yRYmiw7Yz6TKKVr3h6970B2YE+3fQpsWcrbj1PzJgxeJ19DRQjhMbKPIuMY8rFaXc8moolVw=="],
|
||||
|
||||
"postgres-array": ["postgres-array@2.0.0", "https://registry.npmmirror.com/postgres-array/-/postgres-array-2.0.0.tgz", {}, "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA=="],
|
||||
|
||||
"postgres-bytea": ["postgres-bytea@1.0.1", "https://registry.npmmirror.com/postgres-bytea/-/postgres-bytea-1.0.1.tgz", {}, "sha512-5+5HqXnsZPE65IJZSMkZtURARZelel2oXUEO8rH83VS/hxH5vv1uHquPg5wZs8yMAfdv971IU+kcPUczi7NVBQ=="],
|
||||
|
||||
"postgres-date": ["postgres-date@1.0.7", "https://registry.npmmirror.com/postgres-date/-/postgres-date-1.0.7.tgz", {}, "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q=="],
|
||||
|
||||
"postgres-interval": ["postgres-interval@1.2.0", "https://registry.npmmirror.com/postgres-interval/-/postgres-interval-1.2.0.tgz", { "dependencies": { "xtend": "^4.0.0" } }, "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ=="],
|
||||
|
||||
"pretty-bytes": ["pretty-bytes@5.6.0", "https://registry.npmmirror.com/pretty-bytes/-/pretty-bytes-5.6.0.tgz", {}, "sha512-FFw039TmrBqFK8ma/7OL3sDz/VytdtJr044/QUJtH0wK9lb9jLq9tJyIxUwtQJHwar2BqtiA4iCWSwo9JLkzFg=="],
|
||||
|
||||
"pretty-ms": ["pretty-ms@9.3.0", "https://registry.npmmirror.com/pretty-ms/-/pretty-ms-9.3.0.tgz", { "dependencies": { "parse-ms": "^4.0.0" } }, "sha512-gjVS5hOP+M3wMm5nmNOucbIrqudzs9v/57bWRHQWLYklXqoXKrVfYW2W9+glfGsqtPgpiz5WwyEEB+ksXIx3gQ=="],
|
||||
@@ -1183,6 +1287,8 @@
|
||||
|
||||
"require-from-string": ["require-from-string@2.0.2", "https://registry.npmmirror.com/require-from-string/-/require-from-string-2.0.2.tgz", {}, "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw=="],
|
||||
|
||||
"require-in-the-middle": ["require-in-the-middle@8.0.1", "https://registry.npmmirror.com/require-in-the-middle/-/require-in-the-middle-8.0.1.tgz", { "dependencies": { "debug": "^4.3.5", "module-details-from-path": "^1.0.3" } }, "sha512-QT7FVMXfWOYFbeRBF6nu+I6tr2Tf3u0q8RIEjNob/heKY/nh7drD/k7eeMFmSQgnTtCzLDcCu/XEnpW2wk4xCQ=="],
|
||||
|
||||
"require-main-filename": ["require-main-filename@2.0.0", "https://registry.npmmirror.com/require-main-filename/-/require-main-filename-2.0.0.tgz", {}, "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg=="],
|
||||
|
||||
"resolve-pkg-maps": ["resolve-pkg-maps@1.0.0", "https://registry.npmmirror.com/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", {}, "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw=="],
|
||||
@@ -1333,6 +1439,8 @@
|
||||
|
||||
"xss": ["xss@1.0.15", "https://registry.npmmirror.com/xss/-/xss-1.0.15.tgz", { "dependencies": { "commander": "^2.20.3", "cssfilter": "0.0.10" }, "bin": { "xss": "bin/xss" } }, "sha512-FVdlVVC67WOIPvfOwhoMETV72f6GbW7aOabBC3WxN/oUdoEMDyLz4OgRv5/gck2ZeNqEQu+Tb0kloovXOfpYVg=="],
|
||||
|
||||
"xtend": ["xtend@4.0.2", "https://registry.npmmirror.com/xtend/-/xtend-4.0.2.tgz", {}, "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ=="],
|
||||
|
||||
"y18n": ["y18n@5.0.8", "https://registry.npmmirror.com/y18n/-/y18n-5.0.8.tgz", {}, "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA=="],
|
||||
|
||||
"yallist": ["yallist@4.0.0", "https://registry.npmmirror.com/yallist/-/yallist-4.0.0.tgz", {}, "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="],
|
||||
@@ -1507,6 +1615,8 @@
|
||||
|
||||
"@aws-sdk/xml-builder/@smithy/types": ["@smithy/types@4.13.1", "https://registry.npmmirror.com/@smithy/types/-/types-4.13.1.tgz", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-787F3yzE2UiJIQ+wYW1CVg2odHjmaWLGksnKQHUrK/lYZSEcy1msuLVvxaR/sI2/aDe9U+TBuLsXnr3vod1g0g=="],
|
||||
|
||||
"@fastify/otel/@opentelemetry/instrumentation": ["@opentelemetry/instrumentation@0.212.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation/-/instrumentation-0.212.0.tgz", { "dependencies": { "@opentelemetry/api-logs": "0.212.0", "import-in-the-middle": "^2.0.6", "require-in-the-middle": "^8.0.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-IyXmpNnifNouMOe0I/gX7ENfv2ZCNdYTF0FpCsoBcpbIHzk81Ww9rQTYTnvghszCg7qGrIhNvWC8dhEifgX9Jg=="],
|
||||
|
||||
"@grpc/proto-loader/yargs": ["yargs@17.7.2", "https://registry.npmmirror.com/yargs/-/yargs-17.7.2.tgz", { "dependencies": { "cliui": "^8.0.1", "escalade": "^3.1.1", "get-caller-file": "^2.0.5", "require-directory": "^2.1.1", "string-width": "^4.2.3", "y18n": "^5.0.5", "yargs-parser": "^21.1.1" } }, "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w=="],
|
||||
|
||||
"@inquirer/core/@types/node": ["@types/node@22.19.15", "https://registry.npmmirror.com/@types/node/-/node-22.19.15.tgz", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-F0R/h2+dsy5wJAUe3tAU6oqa2qbWY5TpNfL/RGmo1y38hiyO1w3x2jPtt76wmuaJI4DQnOBu21cNXQ2STIUUWg=="],
|
||||
@@ -1515,6 +1625,8 @@
|
||||
|
||||
"@inquirer/core/wrap-ansi": ["wrap-ansi@6.2.0", "https://registry.npmmirror.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz", { "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", "strip-ansi": "^6.0.0" } }, "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA=="],
|
||||
|
||||
"@prisma/instrumentation/@opentelemetry/instrumentation": ["@opentelemetry/instrumentation@0.207.0", "https://registry.npmmirror.com/@opentelemetry/instrumentation/-/instrumentation-0.207.0.tgz", { "dependencies": { "@opentelemetry/api-logs": "0.207.0", "import-in-the-middle": "^2.0.0", "require-in-the-middle": "^8.0.0" }, "peerDependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-y6eeli9+TLKnznrR8AZlQMSJT7wILpXH+6EYq5Vf/4Ao+huI7EedxQHwRgVUOMLFbe7VFDvHJrX9/f4lcwnJsA=="],
|
||||
|
||||
"@smithy/config-resolver/@smithy/types": ["@smithy/types@4.13.1", "https://registry.npmmirror.com/@smithy/types/-/types-4.13.1.tgz", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-787F3yzE2UiJIQ+wYW1CVg2odHjmaWLGksnKQHUrK/lYZSEcy1msuLVvxaR/sI2/aDe9U+TBuLsXnr3vod1g0g=="],
|
||||
|
||||
"@smithy/core/@smithy/protocol-http": ["@smithy/protocol-http@5.3.12", "https://registry.npmmirror.com/@smithy/protocol-http/-/protocol-http-5.3.12.tgz", { "dependencies": { "@smithy/types": "^4.13.1", "tslib": "^2.6.2" } }, "sha512-fit0GZK9I1xoRlR4jXmbLhoN0OdEpa96ul8M65XdmXnxXkuMxM0Y8HDT0Fh0Xb4I85MBvBClOzgSrV1X2s1Hxw=="],
|
||||
@@ -1715,6 +1827,10 @@
|
||||
|
||||
"@aws-sdk/nested-clients/@smithy/util-base64/@smithy/util-buffer-from": ["@smithy/util-buffer-from@4.2.2", "https://registry.npmmirror.com/@smithy/util-buffer-from/-/util-buffer-from-4.2.2.tgz", { "dependencies": { "@smithy/is-array-buffer": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-FDXD7cvUoFWwN6vtQfEta540Y/YBe5JneK3SoZg9bThSoOAC/eGeYEua6RkBgKjGa/sz6Y+DuBZj3+YEY21y4Q=="],
|
||||
|
||||
"@fastify/otel/@opentelemetry/instrumentation/@opentelemetry/api-logs": ["@opentelemetry/api-logs@0.212.0", "https://registry.npmmirror.com/@opentelemetry/api-logs/-/api-logs-0.212.0.tgz", { "dependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-TEEVrLbNROUkYY51sBJGk7lO/OLjuepch8+hmpM6ffMJQ2z/KVCjdHuCFX6fJj8OkJP2zckPjrJzQtXU3IAsFg=="],
|
||||
|
||||
"@fastify/otel/@opentelemetry/instrumentation/import-in-the-middle": ["import-in-the-middle@2.0.6", "https://registry.npmmirror.com/import-in-the-middle/-/import-in-the-middle-2.0.6.tgz", { "dependencies": { "acorn": "^8.15.0", "acorn-import-attributes": "^1.9.5", "cjs-module-lexer": "^2.2.0", "module-details-from-path": "^1.0.4" } }, "sha512-3vZV3jX0XRFW3EJDTwzWoZa+RH1b8eTTx6YOCjglrLyPuepwoBti1k3L2dKwdCUrnVEfc5CuRuGstaC/uQJJaw=="],
|
||||
|
||||
"@grpc/proto-loader/yargs/cliui": ["cliui@8.0.1", "https://registry.npmmirror.com/cliui/-/cliui-8.0.1.tgz", { "dependencies": { "string-width": "^4.2.0", "strip-ansi": "^6.0.1", "wrap-ansi": "^7.0.0" } }, "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ=="],
|
||||
|
||||
"@grpc/proto-loader/yargs/string-width": ["string-width@4.2.3", "https://registry.npmmirror.com/string-width/-/string-width-4.2.3.tgz", { "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", "strip-ansi": "^6.0.1" } }, "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g=="],
|
||||
@@ -1729,6 +1845,10 @@
|
||||
|
||||
"@inquirer/core/wrap-ansi/string-width": ["string-width@4.2.3", "https://registry.npmmirror.com/string-width/-/string-width-4.2.3.tgz", { "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", "strip-ansi": "^6.0.1" } }, "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g=="],
|
||||
|
||||
"@prisma/instrumentation/@opentelemetry/instrumentation/@opentelemetry/api-logs": ["@opentelemetry/api-logs@0.207.0", "https://registry.npmmirror.com/@opentelemetry/api-logs/-/api-logs-0.207.0.tgz", { "dependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-lAb0jQRVyleQQGiuuvCOTDVspc14nx6XJjP4FspJ1sNARo3Regq4ZZbrc3rN4b1TYSuUCvgH+UXUPug4SLOqEQ=="],
|
||||
|
||||
"@prisma/instrumentation/@opentelemetry/instrumentation/import-in-the-middle": ["import-in-the-middle@2.0.6", "https://registry.npmmirror.com/import-in-the-middle/-/import-in-the-middle-2.0.6.tgz", { "dependencies": { "acorn": "^8.15.0", "acorn-import-attributes": "^1.9.5", "cjs-module-lexer": "^2.2.0", "module-details-from-path": "^1.0.4" } }, "sha512-3vZV3jX0XRFW3EJDTwzWoZa+RH1b8eTTx6YOCjglrLyPuepwoBti1k3L2dKwdCUrnVEfc5CuRuGstaC/uQJJaw=="],
|
||||
|
||||
"@smithy/core/@smithy/util-base64/@smithy/util-buffer-from": ["@smithy/util-buffer-from@4.2.2", "https://registry.npmmirror.com/@smithy/util-buffer-from/-/util-buffer-from-4.2.2.tgz", { "dependencies": { "@smithy/is-array-buffer": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-FDXD7cvUoFWwN6vtQfEta540Y/YBe5JneK3SoZg9bThSoOAC/eGeYEua6RkBgKjGa/sz6Y+DuBZj3+YEY21y4Q=="],
|
||||
|
||||
"@smithy/eventstream-serde-universal/@smithy/eventstream-codec/@aws-crypto/crc32": ["@aws-crypto/crc32@3.0.0", "https://registry.npmmirror.com/@aws-crypto/crc32/-/crc32-3.0.0.tgz", { "dependencies": { "@aws-crypto/util": "^3.0.0", "@aws-sdk/types": "^3.222.0", "tslib": "^1.11.1" } }, "sha512-IzSgsrxUcsrejQbPVilIKy16kAT52EwB6zSaI+M3xxIhKh5+aldEyvI+z6erM7TCLB2BJsFrtHjp6/4/sr+3dA=="],
|
||||
|
||||
@@ -0,0 +1,312 @@
|
||||
# 自动更新机制
|
||||
|
||||
## 概述
|
||||
|
||||
Claude Code 拥有一套复杂的多策略自动更新系统,支持三种安装方式、后台静默更新、手动 CLI 命令、服务端版本门控以及更新日志展示。系统设计目标是在最小用户干预下保持 CLI 最新,同时提供回滚和手动控制的兜底手段。
|
||||
|
||||
---
|
||||
|
||||
## 安装类型与更新策略
|
||||
|
||||
更新策略由安装方式决定,通过 `src/utils/doctorDiagnostic.ts` 检测:
|
||||
|
||||
| 安装类型 | 更新策略 | 自动安装? |
|
||||
|---|---|---|
|
||||
| `native` | 从 GCS/Artifactory 下载二进制文件,通过符号链接激活 | 是(静默) |
|
||||
| `npm-global` | `npm install -g` / `bun install -g` | 是(静默) |
|
||||
| `npm-local` | `npm install` 到 `~/.claude/local/` | 是(静默) |
|
||||
| `package-manager` | 显示通知,附带对应操作系统的升级命令 | 否(仅通知) |
|
||||
| `development` | 不适用 — 执行 `claude update` 时报错 | 不适用 |
|
||||
|
||||
### 策略路由
|
||||
|
||||
`src/components/AutoUpdaterWrapper.tsx` — 挂载在 React/Ink UI 树中 — 检测安装类型并渲染对应的更新组件:
|
||||
|
||||
- `native` → `NativeAutoUpdater`(二进制下载 + 符号链接)
|
||||
- `package-manager` → `PackageManagerAutoUpdater`(仅通知)
|
||||
- 其他 → `AutoUpdater`(基于 JS/npm)
|
||||
|
||||
---
|
||||
|
||||
## 后台自动更新循环
|
||||
|
||||
三个更新组件共享相同的轮询模式:
|
||||
|
||||
```typescript
|
||||
useInterval(checkForUpdates, 30 * 60 * 1000); // 每 30 分钟
|
||||
```
|
||||
|
||||
组件挂载时(即启动时)也会执行一次检查。
|
||||
|
||||
### 前置检查门控
|
||||
|
||||
任何更新尝试之前,系统会依次检查:
|
||||
|
||||
1. **自动更新是否被禁用?** — `getAutoUpdaterDisabledReason()`(`src/utils/config.ts:1735`)
|
||||
- `NODE_ENV === 'development'`
|
||||
- 设置了 `DISABLE_AUTOUPDATER` 环境变量
|
||||
- 仅限必要流量模式
|
||||
- `config.autoUpdates === false`(native 安装的保护模式除外)
|
||||
2. **最大版本上限?** — `getMaxVersion()`(`src/utils/autoUpdater.ts:108`)— 服务端熔断开关,防止更新到已知有问题的版本
|
||||
3. **是否跳过该版本?** — `shouldSkipVersion()`(`src/utils/autoUpdater.ts:145`)— 尊重用户的 `minimumVersion` 设置,防止切换到 stable 频道时发生意外的版本降级
|
||||
|
||||
### Native 自动更新器(`src/components/NativeAutoUpdater.tsx`)
|
||||
|
||||
1. 调用 `src/utils/nativeInstaller/installer.ts` 中的 `installLatest()`
|
||||
2. 通过 `src/utils/nativeInstaller/download.ts` 下载二进制文件(GCS 或 Artifactory)
|
||||
3. 验证 SHA256 校验和(3 次重试,60 秒卡顿检测)
|
||||
4. 将版本化二进制文件存储到 XDG 目录
|
||||
5. 更新符号链接(`~/.local/bin/claude` → 新版本二进制文件)
|
||||
6. 保留最近 2 个版本,清理旧版本
|
||||
7. 将错误分类上报分析(超时、校验和、权限、磁盘空间不足、npm、网络)
|
||||
|
||||
### JS/npm 自动更新器(`src/components/AutoUpdater.tsx`)
|
||||
|
||||
1. 调用 `getLatestVersion()` 获取当前 npm dist-tag
|
||||
2. 通过 semver `gte()` 比较版本
|
||||
3. 根据安装类型路由到本地或全局安装
|
||||
4. 使用文件锁(`acquireLock()` / `releaseLock()`)防止并发更新
|
||||
|
||||
### 包管理器通知器(`src/components/PackageManagerAutoUpdater.tsx`)
|
||||
|
||||
每 30 分钟通过 GCS 存储桶(非 npm)检查更新。**不会自动安装** — 仅显示对应操作系统的升级命令:
|
||||
|
||||
- macOS: `brew upgrade claude-code`
|
||||
- Windows: `winget upgrade Anthropic.ClaudeCode`
|
||||
- Alpine: `apk upgrade claude-code`
|
||||
|
||||
---
|
||||
|
||||
## 启动版本门控
|
||||
|
||||
`src/utils/autoUpdater.ts:70` — `assertMinVersion()`
|
||||
|
||||
从 `src/main.tsx:1775` 在启动时调用:
|
||||
|
||||
```typescript
|
||||
void assertMinVersion();
|
||||
```
|
||||
|
||||
1. 从 GrowthBook 动态配置获取 `tengu_version_config`
|
||||
2. 如果 `MACRO.VERSION < minVersion`,打印错误信息并调用 `gracefulShutdownSync(1)` — 强制用户更新
|
||||
3. 这是一个**硬性门控** — 低于最低版本的 CLI 将无法启动
|
||||
|
||||
---
|
||||
|
||||
## 手动 CLI 命令
|
||||
|
||||
### `claude update` / `claude upgrade`
|
||||
|
||||
**文件**: `src/cli/update.ts`
|
||||
|
||||
完整流程:
|
||||
1. 运行 `getDoctorDiagnostic()` 检查系统健康状态
|
||||
2. 检查是否存在多个安装及配置不一致
|
||||
3. 根据安装类型路由:
|
||||
- `development` → 报错("开发版本不支持自动更新")
|
||||
- `package-manager` → 打印对应操作系统的更新命令
|
||||
- `native` → 使用原生安装器的 `updateLatest()`
|
||||
- `npm-local` → 在 `~/.claude/local/` 执行 `npm install`
|
||||
- `npm-global` → 执行 `npm install -g`(含权限检查)
|
||||
4. 报告当前版本、最新版本、成功/失败状态
|
||||
|
||||
### `claude rollback [target]`(仅限内部)
|
||||
|
||||
回滚到之前的版本。支持 `--list`、`--dry-run`、`--safe` 标志。
|
||||
|
||||
### `claude install [target]`
|
||||
|
||||
安装或重新安装原生构建版本。接受可选的版本目标参数。
|
||||
|
||||
### `claude doctor`
|
||||
|
||||
检查自动更新器的健康状态,报告状态、权限和配置信息。
|
||||
|
||||
---
|
||||
|
||||
## 原生安装器架构
|
||||
|
||||
**文件**: `src/utils/nativeInstaller/installer.ts`
|
||||
|
||||
### 二进制文件存储布局
|
||||
|
||||
```
|
||||
~/.local/share/claude-code/
|
||||
├── versions/ # 版本化二进制文件 (claude-1.0.3, claude-1.0.4, ...)
|
||||
├── staging/ # 临时下载暂存区
|
||||
└── locks/ # 基于 PID 和 mtime 的锁文件
|
||||
|
||||
~/.local/bin/claude # 指向当前版本二进制文件的符号链接
|
||||
```
|
||||
|
||||
Windows 系统使用文件复制而非符号链接。
|
||||
|
||||
### 核心操作
|
||||
|
||||
| 函数 | 说明 |
|
||||
|---|---|
|
||||
| `updateLatest()` | 核心更新流程:最大版本上限 → 跳过检查 → 加锁 → 下载 → 安装 → 更新符号链接 |
|
||||
| `installLatest()` | Singleflight 包装版本,防止重复的进行中安装 |
|
||||
| `cleanupOldVersions()` | 保留最近 2 个版本,清理过期的暂存区和临时文件 |
|
||||
| `lockCurrentVersion()` | 进程生命周期锁,防止正在运行的版本被删除 |
|
||||
| `cleanupNpmInstallations()` | 迁移到原生安装时清理旧的 npm 安装 |
|
||||
|
||||
### 下载与校验
|
||||
|
||||
**文件**: `src/utils/nativeInstaller/download.ts`
|
||||
|
||||
1. 路由到 Artifactory(内部用户)或 GCS 存储桶(外部用户)
|
||||
2. 下载二进制文件并跟踪进度
|
||||
3. SHA256 校验和验证
|
||||
4. 60 秒卡顿检测(中止停滞的下载)
|
||||
5. 失败时自动重试 3 次
|
||||
|
||||
---
|
||||
|
||||
## 文件锁机制
|
||||
|
||||
**文件**: `src/utils/autoUpdater.ts:176-268`
|
||||
|
||||
防止并发更新进程破坏安装:
|
||||
|
||||
- 锁文件:`~/.claude/update.lock`(或等效路径)
|
||||
- 5 分钟超时 — 超过 5 分钟的锁被视为过期,强制获取
|
||||
- 进程将其 PID 写入锁文件
|
||||
- `acquireLock()` 和 `releaseLock()` 同时被 JS/npm 和原生安装器使用
|
||||
|
||||
---
|
||||
|
||||
## 配置
|
||||
|
||||
### 设置项
|
||||
|
||||
**文件**: `src/utils/settings/types.ts`
|
||||
|
||||
| 设置项 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| `autoUpdatesChannel` | `'latest' \| 'stable'` | 自动更新的发布频道 |
|
||||
| `minimumVersion` | string | 最低版本要求,防止意外的版本降级 |
|
||||
|
||||
### 全局配置
|
||||
|
||||
**文件**: `src/utils/config.ts:191-193`
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| `autoUpdates` | boolean | 启用/禁用自动更新(旧版) |
|
||||
| `autoUpdatesProtectedForNative` | boolean | 原生安装始终自动更新 |
|
||||
|
||||
### 配置迁移
|
||||
|
||||
**文件**: `src/migrations/migrateAutoUpdatesToSettings.ts`
|
||||
|
||||
一次性将旧版 `globalConfig.autoUpdates = false` 迁移为 settings 中的 `DISABLE_AUTOUPDATER=1` 环境变量。从 `src/main.tsx:325` 在启动时调用。
|
||||
|
||||
---
|
||||
|
||||
## 更新通知去重
|
||||
|
||||
**文件**: `src/hooks/useUpdateNotification.ts`
|
||||
|
||||
React hook `useUpdateNotification(updatedVersion)` — 确保每次 semver 变更(major.minor.patch)只显示一次"重启以更新"消息,避免同一版本的重复通知。
|
||||
|
||||
---
|
||||
|
||||
## 更新日志
|
||||
|
||||
**文件**: `src/utils/releaseNotes.ts`
|
||||
|
||||
1. 从 `src/setup.ts:387` 在每次启动时调用
|
||||
2. 从 GitHub 获取 changelog
|
||||
3. 缓存到 `~/.claude/cache/changelog.md`
|
||||
4. 展示比 `lastReleaseNotesSeen` 更新的版本的更新日志
|
||||
5. 使用 semver 比较确定需要展示哪些日志
|
||||
|
||||
---
|
||||
|
||||
## 版本比较
|
||||
|
||||
**文件**: `src/utils/semver.ts`
|
||||
|
||||
- 提供 `gt()`、`gte()`、`lt()`、`lte()`、`satisfies()`、`order()`
|
||||
- 在 Bun 环境下使用 `Bun.semver.order()`(快 20 倍)
|
||||
- 在 Node.js 环境下回退到 npm `semver` 包
|
||||
|
||||
---
|
||||
|
||||
## 分析事件
|
||||
|
||||
所有更新相关的遥测数据使用 `tengu_` 前缀的事件:
|
||||
|
||||
| 类别 | 事件 |
|
||||
|---|---|
|
||||
| 版本检查 | `tengu_version_check_success`、`tengu_version_check_failure` |
|
||||
| JS 自动更新器 | `tengu_auto_updater_start/success/fail/up_to_date/lock_contention` |
|
||||
| 原生自动更新器 | `tengu_native_auto_updater_start/success/fail` |
|
||||
| 原生更新 | `tengu_native_update_complete/skipped_max_version/skipped_minimum_version` |
|
||||
| 锁机制 | `tengu_version_lock_acquired/failed`、`tengu_native_update_lock_failed` |
|
||||
| 二进制下载 | `tengu_binary_download_attempt/success/failure`、`tengu_binary_manifest_fetch_failure` |
|
||||
| 清理 | `tengu_native_version_cleanup`、`tengu_native_staging_cleanup`、`tengu_native_stale_locks_cleanup` |
|
||||
| 安装 | `tengu_native_install_package_success/failure`、`tengu_native_install_binary_success/failure` |
|
||||
| 手动更新 | `tengu_update_check` |
|
||||
| 迁移 | `tengu_migrate_autoupdates_to_settings`、`tengu_migrate_autoupdates_error` |
|
||||
|
||||
---
|
||||
|
||||
## 关键文件索引
|
||||
|
||||
| 文件 | 职责 |
|
||||
|---|---|
|
||||
| `src/utils/autoUpdater.ts` | 核心逻辑:版本检查、npm 安装、文件锁、最低/最高版本门控 |
|
||||
| `src/cli/update.ts` | `claude update` 命令处理 |
|
||||
| `src/utils/nativeInstaller/installer.ts` | 原生二进制安装器:下载、版本管理、符号链接、清理 |
|
||||
| `src/utils/nativeInstaller/download.ts` | 从 GCS/Artifactory 下载二进制文件并校验 |
|
||||
| `src/utils/localInstaller.ts` | 本地安装器(`~/.claude/local/`)基于 npm |
|
||||
| `src/components/AutoUpdaterWrapper.tsx` | 基于安装类型的策略路由 |
|
||||
| `src/components/AutoUpdater.tsx` | JS/npm 后台自动更新器(30 分钟间隔) |
|
||||
| `src/components/NativeAutoUpdater.tsx` | 原生二进制后台自动更新器(30 分钟间隔) |
|
||||
| `src/components/PackageManagerAutoUpdater.tsx` | 包管理器通知(30 分钟,仅展示) |
|
||||
| `src/hooks/useUpdateNotification.ts` | 按 semver 去重更新通知 |
|
||||
| `src/utils/releaseNotes.ts` | Changelog 获取、缓存与展示 |
|
||||
| `src/utils/semver.ts` | Semver 版本比较(Bun 原生 + npm 回退) |
|
||||
| `src/utils/doctorDiagnostic.ts` | 安装类型检测与健康诊断 |
|
||||
| `src/utils/config.ts:1735` | `getAutoUpdaterDisabledReason()` — 禁用检查逻辑 |
|
||||
| `src/migrations/migrateAutoUpdatesToSettings.ts` | 旧版配置迁移 |
|
||||
| `src/screens/Doctor.tsx` | Doctor 命令 UI,展示自动更新状态 |
|
||||
|
||||
---
|
||||
|
||||
## 流程图
|
||||
|
||||
```
|
||||
启动阶段
|
||||
├── assertMinVersion() → 版本过低时硬性拦截,拒绝启动
|
||||
├── migrateAutoUpdatesToSettings() → 一次性配置迁移
|
||||
└── checkForReleaseNotes() → 展示新版本的更新日志
|
||||
|
||||
REPL 运行中(每 30 分钟)
|
||||
├── AutoUpdaterWrapper 检测安装类型
|
||||
│
|
||||
├── native → NativeAutoUpdater
|
||||
│ ├── 从 GCS/Artifactory 获取版本
|
||||
│ ├── 检查最大版本上限(服务端控制)
|
||||
│ ├── 检查 minimumVersion 设置(跳过)
|
||||
│ ├── acquireLock()
|
||||
│ ├── downloadAndVerifyBinary()(SHA256 校验,3 次重试)
|
||||
│ ├── 安装到 versions/ 目录
|
||||
│ ├── 更新符号链接
|
||||
│ └── cleanupOldVersions()(保留 2 个版本)
|
||||
│
|
||||
├── npm-global/local → AutoUpdater
|
||||
│ ├── 从 npm registry 获取最新版本
|
||||
│ ├── semver 版本比较
|
||||
│ ├── acquireLock()
|
||||
│ └── npm install -g / 本地安装
|
||||
│
|
||||
└── package-manager → PackageManagerAutoUpdater
|
||||
├── 从 GCS 获取版本
|
||||
└── 显示 "Run: brew upgrade ..."(不自动安装)
|
||||
|
||||
手动操作
|
||||
└── claude update → 完整诊断 + 安装编排
|
||||
```
|
||||
@@ -0,0 +1,87 @@
|
||||
---
|
||||
title: "Buddy 宠物系统"
|
||||
description: "Buddy 是 CLI 中的虚拟宠物伴侣,通过 /buddy 命令孵化、互动,会出现在输入框旁边陪伴你写代码。"
|
||||
keywords: ["buddy", "宠物", "companion", "伴侣", "虚拟宠物"]
|
||||
---
|
||||
|
||||
## 概述
|
||||
|
||||
Buddy 是 Claude Code 内置的虚拟宠物系统。在 REPL 中通过 `/buddy` 命令可以孵化一只随机生成的宠物伴侣,它会出现在输入框旁边,陪伴你的编码过程。
|
||||
|
||||
> Feature Flag: `FEATURE_BUDDY=1`
|
||||
|
||||
## 启用方式
|
||||
|
||||
```bash
|
||||
FEATURE_BUDDY=1 bun run dev
|
||||
```
|
||||
|
||||
孵化窗口:2026 年 4 月 1-7 日期间启动时,会在 REPL 顶部显示彩虹色的 `/buddy` 提示。4 月 7 日之后命令仍然可用,但不再自动提示。
|
||||
|
||||
## 命令
|
||||
|
||||
| 命令 | 说明 |
|
||||
|---|---|
|
||||
| `/buddy` | 查看当前宠物信息和属性 |
|
||||
| `/buddy hatch` | 孵化一只新宠物(首次使用) |
|
||||
| `/buddy rehatch` | 重新随机生成宠物(替换现有) |
|
||||
| `/buddy pet` | 撸宠物,触发爱心动画 |
|
||||
| `/buddy mute` | 静音宠物(隐藏) |
|
||||
| `/buddy unmute` | 取消静音 |
|
||||
|
||||
## 宠物属性
|
||||
|
||||
### 物种(18 种)
|
||||
|
||||
| | | | |
|
||||
|---|---|---|---|
|
||||
| Duck | Goose | Blob | Cat |
|
||||
| Dragon | Octopus | Owl | Penguin |
|
||||
| Turtle | Snail | Ghost | Axolotl |
|
||||
| Capybara | Cactus | Robot | Rabbit |
|
||||
| Mushroom | Chonk | | |
|
||||
|
||||
### 稀有度
|
||||
|
||||
| 稀有度 | 星级 | 权重 |
|
||||
|---|---|---|
|
||||
| Common | ★ | 60% |
|
||||
| Uncommon | ★★ | 25% |
|
||||
| Rare | ★★★ | 10% |
|
||||
| Epic | ★★★★ | 4% |
|
||||
| Legendary | ★★★★★ | 1% |
|
||||
|
||||
孵化时基于种子随机决定,存在极低概率出现 Shiny(闪光)变体。
|
||||
|
||||
### 属性值
|
||||
|
||||
每只宠物拥有 5 项属性(0-100):
|
||||
|
||||
- **DEBUGGING** — 调试能力
|
||||
- **PATIENCE** — 耐心程度
|
||||
- **CHAOS** — 混乱指数
|
||||
- **WISDOM** — 智慧值
|
||||
- **SNARK** — 毒舌度
|
||||
|
||||
### 外观
|
||||
|
||||
每只宠物还有随机的外观配件:
|
||||
|
||||
- **眼睛**: `·` `✦` `×` `◉` `@` `°`
|
||||
- **帽子**: none, crown, tophat, propeller, halo, wizard, beanie, tinyduck
|
||||
|
||||
## 数据存储
|
||||
|
||||
宠物信息存储在 `~/.claude.json` 的 `companion` 字段中。宠物的外观属性(物种、稀有度、属性值等)基于用户 ID 的哈希确定性生成,不可通过编辑配置文件来篡改稀有度。
|
||||
|
||||
## 相关源码
|
||||
|
||||
| 文件 | 说明 |
|
||||
|---|---|
|
||||
| `src/commands/buddy/buddy.ts` | `/buddy` 命令处理 |
|
||||
| `src/buddy/companion.ts` | 宠物生成与加载 |
|
||||
| `src/buddy/types.ts` | 类型定义(物种、稀有度、属性) |
|
||||
| `src/buddy/sprites.ts` | 终端像素画渲染 |
|
||||
| `src/buddy/CompanionSprite.tsx` | React 组件(输入框旁显示) |
|
||||
| `src/buddy/useBuddyNotification.tsx` | 启动提示通知 |
|
||||
| `src/buddy/prompt.ts` | 宠物相关 prompt 模板 |
|
||||
@@ -0,0 +1,48 @@
|
||||
---
|
||||
title: "Debug 模式"
|
||||
description: "通过 VS Code attach 模式调试 CLI 运行时,支持断点、单步执行和变量查看。"
|
||||
keywords: ["debug", "调试", "VS Code", "inspect", "断点"]
|
||||
---
|
||||
|
||||
## 概述
|
||||
|
||||
TUI (REPL) 模式需要真实终端,无法直接通过 VS Code launch 启动调试。使用 **attach 模式**连接到正在运行的 Bun 进程。
|
||||
|
||||
## 步骤
|
||||
|
||||
### 1. 终端启动 inspect 服务
|
||||
|
||||
```bash
|
||||
bun run dev:inspect
|
||||
```
|
||||
|
||||
会输出类似 `ws://localhost:8888/xxxxxxxx` 的地址。
|
||||
|
||||
### 2. VS Code 附着调试器
|
||||
|
||||
1. 在 `src/` 文件中打断点
|
||||
2. F5 → 选择 **"Attach to Bun (TUI debug)"**
|
||||
|
||||
> **注意**:`dev:inspect` 和 `launch.json` 中的 WebSocket 地址会在每次启动时变化,需要同步更新两处。
|
||||
|
||||
## 原理
|
||||
|
||||
`dev:inspect` 脚本实际执行的是:
|
||||
|
||||
```bash
|
||||
bun --inspect-wait=localhost:8888/<token> run scripts/dev.ts
|
||||
```
|
||||
|
||||
Bun 的 `--inspect-wait` 参数启动一个 Chrome DevTools Protocol 兼容的 inspect 服务,等待调试器连接后才开始执行。VS Code 的 `bun` 扩展通过 WebSocket 连接到这个地址实现 attach。
|
||||
|
||||
## JetBrains IDE
|
||||
|
||||
理论上 JetBrains 系列(WebStorm / IntelliJ 等)也支持 attach 到 Bun inspect 服务(Run → Attach to Process),但尚未实际验证过。如果你验证成功,欢迎补充文档。
|
||||
|
||||
## 相关文件
|
||||
|
||||
| 文件 | 说明 |
|
||||
|---|---|
|
||||
| `package.json` → `dev:inspect` | 启动 inspect 服务的 npm script |
|
||||
| `.vscode/launch.json` | VS Code attach 调试配置 |
|
||||
| `scripts/dev.ts` | dev 模式入口,注入 MACRO defines |
|
||||
@@ -0,0 +1,186 @@
|
||||
# WEB_SEARCH_TOOL — 网页搜索工具
|
||||
|
||||
> 实现状态:适配器架构完成,Bing 适配器为当前默认后端
|
||||
> 引用数:核心工具,无 feature flag 门控(始终启用)
|
||||
|
||||
## 一、功能概述
|
||||
|
||||
WebSearchTool 让模型可以搜索互联网获取最新信息。原始实现仅支持 Anthropic API 服务端搜索(`web_search_20250305` server tool),在第三方代理端点下不可用。现已重构为适配器架构,新增 Bing 搜索页面解析作为 fallback,确保任何 API 端点都能使用搜索功能。
|
||||
|
||||
## 二、实现架构
|
||||
|
||||
### 2.1 适配器模式
|
||||
|
||||
```
|
||||
WebSearchTool.call()
|
||||
│
|
||||
▼
|
||||
createAdapter() ← 适配器工厂
|
||||
│
|
||||
├── ApiSearchAdapter — Anthropic 官方 API 服务端搜索
|
||||
│ └── 使用 web_search_20250305 server tool
|
||||
│ 通过 queryModelWithStreaming 二次调用 API
|
||||
│
|
||||
└── BingSearchAdapter — Bing HTML 抓取 + 正则提取(当前默认)
|
||||
└── 直接抓取 Bing 搜索页 HTML
|
||||
正则提取 b_algo 块中的标题/URL/摘要
|
||||
```
|
||||
|
||||
### 2.2 模块结构
|
||||
|
||||
| 模块 | 文件 | 说明 |
|
||||
|------|------|------|
|
||||
| 工具入口 | `src/tools/WebSearchTool/WebSearchTool.ts` | `buildTool()` 定义:schema、权限、执行、输出格式化 |
|
||||
| 工具 prompt | `src/tools/WebSearchTool/prompt.ts` | 搜索工具的系统提示词 |
|
||||
| UI 渲染 | `src/tools/WebSearchTool/UI.tsx` | 搜索结果的终端渲染组件 |
|
||||
| 适配器接口 | `src/tools/WebSearchTool/adapters/types.ts` | `WebSearchAdapter` 接口、`SearchResult`/`SearchOptions`/`SearchProgress` 类型 |
|
||||
| 适配器工厂 | `src/tools/WebSearchTool/adapters/index.ts` | `createAdapter()` 工厂函数,选择后端 |
|
||||
| API 适配器 | `src/tools/WebSearchTool/adapters/apiAdapter.ts` | 封装原有 `queryModelWithStreaming` 逻辑,使用 server tool |
|
||||
| Bing 适配器 | `src/tools/WebSearchTool/adapters/bingAdapter.ts` | Bing HTML 抓取 + 正则解析 |
|
||||
| 单元测试 | `src/tools/WebSearchTool/__tests__/bingAdapter.test.ts` | 32 个测试用例 |
|
||||
| 集成测试 | `src/tools/WebSearchTool/__tests__/bingAdapter.integration.ts` | 真实网络请求验证 |
|
||||
|
||||
### 2.3 数据流
|
||||
|
||||
```
|
||||
模型调用 WebSearchTool(query, allowed_domains, blocked_domains)
|
||||
│
|
||||
▼
|
||||
validateInput() — 校验 query 非空、allowed/block 不共存
|
||||
│
|
||||
▼
|
||||
createAdapter() → BingSearchAdapter(当前硬编码)
|
||||
│
|
||||
▼
|
||||
adapter.search(query, { allowedDomains, blockedDomains, signal, onProgress })
|
||||
│
|
||||
├── onProgress({ type: 'query_update', query })
|
||||
│
|
||||
├── axios.get(bing.com/search?q=...&setmkt=en-US)
|
||||
│ └── 13 个 Edge 浏览器请求头
|
||||
│
|
||||
├── extractBingResults(html) — 正则提取 <li class="b_algo"> 块
|
||||
│ ├── resolveBingUrl() — 解码 base64 重定向 URL
|
||||
│ ├── extractSnippet() — 三级降级摘要提取
|
||||
│ └── decodeHtmlEntities() — he.decode
|
||||
│
|
||||
├── 客户端域名过滤 (allowedDomains / blockedDomains)
|
||||
│
|
||||
├── onProgress({ type: 'search_results_received', resultCount })
|
||||
│
|
||||
▼
|
||||
格式化为 markdown 链接列表返回给模型
|
||||
```
|
||||
|
||||
## 三、Bing 适配器技术细节
|
||||
|
||||
### 3.1 反爬绕过
|
||||
|
||||
使用 13 个 Edge 浏览器请求头(含 `Sec-Ch-Ua`、`Sec-Fetch-*` 等),避免 Bing 返回 JS 渲染的空页面:
|
||||
|
||||
```typescript
|
||||
const BROWSER_HEADERS = {
|
||||
'User-Agent': '...Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0',
|
||||
'Sec-Ch-Ua': '"Microsoft Edge";v="131", "Chromium";v="131", ...',
|
||||
'Sec-Fetch-Dest': 'document',
|
||||
'Sec-Fetch-Mode': 'navigate',
|
||||
'Sec-Fetch-Site': 'none',
|
||||
'Sec-Fetch-User': '?1',
|
||||
// ... 共 13 个标头
|
||||
}
|
||||
```
|
||||
|
||||
`setmkt=en-US` 参数强制美式英语市场,避免 IP 地理定位导致区域化结果。
|
||||
|
||||
### 3.2 URL 解码(`resolveBingUrl()`)
|
||||
|
||||
Bing 返回的重定向 URL 格式:`bing.com/ck/a?...&u=a1aHR0cHM6Ly9...`
|
||||
|
||||
- `u` 参数前 2 字符为协议前缀:`a1` = https,`a0` = http
|
||||
- 剩余部分为 base64url 编码的真实 URL
|
||||
- Bing 内部链接和相对路径被过滤返回 `undefined`
|
||||
|
||||
### 3.3 摘要提取(`extractSnippet()`)
|
||||
|
||||
三级降级策略:
|
||||
|
||||
1. `<p class="b_lineclamp...">` — Bing 的搜索摘要段落
|
||||
2. `<div class="b_caption">` 内的 `<p>` — 备选摘要位置
|
||||
3. `<div class="b_caption">` 直接文本 — 最终 fallback
|
||||
|
||||
### 3.4 域名过滤
|
||||
|
||||
客户端侧实现,支持子域名匹配:
|
||||
- `allowedDomains`:白名单,结果域名必须匹配列表中的某项(含子域名)
|
||||
- `blockedDomains`:黑名单,匹配的结果被过滤
|
||||
- 两者不可同时使用(`validateInput` 校验)
|
||||
|
||||
## 四、适配器选择逻辑
|
||||
|
||||
当前 `createAdapter()` 硬编码返回 `BingSearchAdapter`,原逻辑已注释保留:
|
||||
|
||||
```typescript
|
||||
export function createAdapter(): WebSearchAdapter {
|
||||
return new BingSearchAdapter()
|
||||
// 注释保留的选择逻辑:
|
||||
// 1. WEB_SEARCH_ADAPTER 环境变量强制指定 api|bing
|
||||
// 2. isFirstPartyAnthropicBaseUrl() → API 适配器
|
||||
// 3. 第三方端点 → Bing 适配器
|
||||
}
|
||||
```
|
||||
|
||||
恢复自动选择:取消 `index.ts` 中的注释即可。
|
||||
|
||||
## 五、接口定义
|
||||
|
||||
### WebSearchAdapter
|
||||
|
||||
```typescript
|
||||
interface WebSearchAdapter {
|
||||
search(query: string, options: SearchOptions): Promise<SearchResult[]>
|
||||
}
|
||||
|
||||
interface SearchResult {
|
||||
title: string
|
||||
url: string
|
||||
snippet?: string
|
||||
}
|
||||
|
||||
interface SearchOptions {
|
||||
allowedDomains?: string[]
|
||||
blockedDomains?: string[]
|
||||
signal?: AbortSignal
|
||||
onProgress?: (progress: SearchProgress) => void
|
||||
}
|
||||
|
||||
interface SearchProgress {
|
||||
type: 'query_update' | 'search_results_received'
|
||||
query?: string
|
||||
resultCount?: number
|
||||
}
|
||||
```
|
||||
|
||||
### 工具 Input Schema
|
||||
|
||||
```typescript
|
||||
{
|
||||
query: string // 搜索关键词,最少 2 字符
|
||||
allowed_domains?: string[] // 域名白名单
|
||||
blocked_domains?: string[] // 域名黑名单
|
||||
}
|
||||
```
|
||||
|
||||
## 六、文件索引
|
||||
|
||||
| 文件 | 职责 |
|
||||
|------|------|
|
||||
| `src/tools/WebSearchTool/WebSearchTool.ts` | 工具定义入口 |
|
||||
| `src/tools/WebSearchTool/prompt.ts` | 搜索工具 prompt |
|
||||
| `src/tools/WebSearchTool/UI.tsx` | 终端 UI 渲染 |
|
||||
| `src/tools/WebSearchTool/adapters/types.ts` | 适配器接口 |
|
||||
| `src/tools/WebSearchTool/adapters/index.ts` | 适配器工厂 |
|
||||
| `src/tools/WebSearchTool/adapters/apiAdapter.ts` | API 服务端搜索适配器 |
|
||||
| `src/tools/WebSearchTool/adapters/bingAdapter.ts` | Bing HTML 解析适配器 |
|
||||
| `src/tools/WebSearchTool/__tests__/bingAdapter.test.ts` | 单元测试 (32 cases) |
|
||||
| `src/tools/WebSearchTool/__tests__/bingAdapter.integration.ts` | 集成测试 |
|
||||
| `src/tools.ts` | 工具注册 |
|
||||
@@ -11,13 +11,13 @@ keywords: ["Ant 特权", "USER_TYPE", "身份门控", "内部功能", "Anthropic
|
||||
`USER_TYPE` 是一个构建时常量,通过 Bun 打包器的 `--define` 注入。在 Anthropic 的内部构建中它被设为 `'ant'`,在公开发布的版本中是 `'external'`:
|
||||
|
||||
```typescript
|
||||
// 反编译版本(src/entrypoints/cli.tsx 第 16 行)
|
||||
(globalThis as any).BUILD_TARGET = "external";
|
||||
// 反编译版本(src/types/global.d.ts 第 63 行)
|
||||
// Build-time constants BUILD_TARGET/BUILD_ENV/INTERFACE_TYPE — removed (zero runtime usage)
|
||||
```
|
||||
|
||||
由于这是编译时常量,Bun 会进行**常量折叠**——所有 `process.env.USER_TYPE === 'ant'` 在外部构建中直接变为 `false`,后续代码被 DCE 移除。但在反编译版本中,这些代码保留完整。
|
||||
`BUILD_TARGET` 等构建时常量在反编译版本中已被移除。`USER_TYPE` 通过 Bun 的 `--define` 或环境变量注入,Bun 会进行**常量折叠**——所有 `process.env.USER_TYPE === 'ant'` 在外部构建中直接变为 `false`,后续代码被 DCE 移除。但在反编译版本中,这些代码保留完整。
|
||||
|
||||
`USER_TYPE === 'ant'` 出现在代码库的 **60+ 个位置**,控制着工具、命令、API、UI 等方方面面。
|
||||
`USER_TYPE === 'ant'` 在代码库中出现 **377+ 次**(含 `=== 'ant'` 291 次、`(process.env.USER_TYPE) === 'ant'` 86 次),另有 `!== 'ant'` 53 次、其他引用约 35 次,总计 **465 处引用**,控制着工具、命令、API、UI 等方方面面。
|
||||
|
||||
## Ant-Only 工具
|
||||
|
||||
@@ -31,7 +31,9 @@ keywords: ["Ant 特权", "USER_TYPE", "身份门控", "内部功能", "Anthropic
|
||||
| **TungstenTool** | `src/tools/TungstenTool/` | 基于 tmux 的终端面板工具(反编译版中已 stub) |
|
||||
|
||||
```typescript
|
||||
// src/tools.ts 第 16-24 行
|
||||
// src/tools.ts 第 14-24 行——条件导入 + Dead Code Elimination 标记
|
||||
// Dead code elimination: conditional import for ant-only tools
|
||||
/* eslint-disable custom-rules/no-process-env-top-level, @typescript-eslint/no-require-imports */
|
||||
const REPLTool =
|
||||
process.env.USER_TYPE === 'ant'
|
||||
? require('./tools/REPLTool/REPLTool.js').REPLTool
|
||||
@@ -45,7 +47,7 @@ const SuggestBackgroundPRTool =
|
||||
|
||||
## Ant-Only 命令
|
||||
|
||||
`src/commands.ts` 注册了 25+ 个仅在内部构建中可用的斜杠命令:
|
||||
`src/commands.ts` 注册了 **28** 个仅在内部构建中可用的斜杠命令(`INTERNAL_ONLY_COMMANDS`,lines 225-254),在 `USER_TYPE === 'ant' && !IS_DEMO` 时才加载(line 343-345):
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="调试类">
|
||||
@@ -55,6 +57,7 @@ const SuggestBackgroundPRTool =
|
||||
- `env` — 显示环境变量
|
||||
- `mockLimits` — 模拟速率限制
|
||||
- `resetLimits` — 重置速率限制
|
||||
- `resetLimitsNonInteractive` — 重置速率限制(非交互式)
|
||||
</Accordion>
|
||||
<Accordion title="实验类">
|
||||
- `bughunter` — Bug 猎人模式
|
||||
@@ -69,6 +72,9 @@ const SuggestBackgroundPRTool =
|
||||
- `autofixPr` — 自动修复 PR 中的问题
|
||||
- `share` — 分享会话
|
||||
- `summary` — 生成摘要
|
||||
- `subscribePr` — 订阅 PR(需要 `KAIROS_GITHUB_WEBHOOKS` feature flag)
|
||||
- `forceSnip` — 强制截断历史(需要 `HISTORY_SNIP` feature flag)
|
||||
- `ultraplan` — 超级规划(需要 `ULTRAPLAN` feature flag)
|
||||
</Accordion>
|
||||
<Accordion title="基础设施类">
|
||||
- `backfillSessions` — 回填会话数据
|
||||
@@ -88,30 +94,72 @@ const SuggestBackgroundPRTool =
|
||||
|
||||
## Beta API Headers
|
||||
|
||||
Claude Code 向 API 发送的 beta headers 也分为公开和内部两类:
|
||||
Claude Code 向 API 发送的 beta headers 分布在 `src/constants/betas.ts`(主注册表)和其他文件中,按可见性分为以下几类:
|
||||
|
||||
| Header | 功能 | 可见性 |
|
||||
|--------|------|--------|
|
||||
| `claude-code-20250219` | Claude Code 标识 | 公开 |
|
||||
| `interleaved-thinking-2025-05-14` | 交错思考模式 | 公开 |
|
||||
| `context-1m-2025-08-07` | 1M 上下文窗口 | 公开 |
|
||||
| `context-management-2025-06-27` | 上下文管理 | 公开 |
|
||||
| `web-search-2025-03-05` | 网页搜索 | 公开 |
|
||||
| `effort-2025-11-24` | 推理强度控制 | 公开 |
|
||||
| `fast-mode-2026-02-01` | 快速模式 | 公开 |
|
||||
| `token-efficient-tools-2026-03-28` | Token 高效工具 | 公开 |
|
||||
| `advisor-tool-2026-03-01` | 顾问工具 | 公开 |
|
||||
| **`cli-internal-2026-02-09`** | 内部 CLI 功能 | **Ant-Only** |
|
||||
| **`afk-mode-2026-01-31`** | AFK 模式(离开键盘自动审批) | **Feature Flag** |
|
||||
| **`summarize-connector-text-2026-03-13`** | 连接器文本摘要 | **Feature Flag** |
|
||||
### 公开 Headers(所有构建均发送)
|
||||
|
||||
| Header | 功能 | 额外条件 |
|
||||
|--------|------|----------|
|
||||
| `claude-code-20250219` | Claude Code 标识 | 非 Haiku 时始终发送;Haiku 在 agentic 模式下也发送 |
|
||||
| `effort-2025-11-24` | 推理强度控制 | 动态注入 |
|
||||
| `task-budgets-2026-03-13` | 任务预算 | 始终通过 `addAgenticBetas()` 注入 |
|
||||
| `fast-mode-2026-02-01` | 快速模式 | 通过 sticky-on latch 动态注入 |
|
||||
| `advisor-tool-2026-03-01` | 顾问工具 | 启用 advisor 时动态注入 |
|
||||
| `advanced-tool-use-2025-11-20` | 工具搜索(1P) | Claude API / Foundry |
|
||||
| `tool-search-tool-2025-10-19` | 工具搜索(3P) | Vertex / Bedrock |
|
||||
|
||||
### 模型能力相关(有条件发送)
|
||||
|
||||
| Header | 功能 | 条件 |
|
||||
|--------|------|------|
|
||||
| `interleaved-thinking-2025-05-14` | 交错思考模式 | 模型支持 ISP 且未禁用 |
|
||||
| `context-1m-2025-08-07` | 1M 上下文窗口 | 模型支持 1M context |
|
||||
| `context-management-2025-06-27` | 上下文管理 | Claude 4+ 或 ant 手动启用 |
|
||||
| `structured-outputs-2025-12-15` | 结构化输出 | Claude 4.5/4.6 + GrowthBook `tengu_tool_pear` |
|
||||
| `web-search-2025-03-05` | 网页搜索 | Vertex (Claude 4+) / Foundry |
|
||||
| `redact-thinking-2026-02-12` | 思维摘要/脱敏 | ISP 模型 + 非交互 + 未强制显示思维 |
|
||||
| `prompt-caching-scope-2026-01-05` | 提示缓存作用域 | firstParty/foundry + 全局缓存 |
|
||||
|
||||
### Ant-Only Headers
|
||||
|
||||
| Header | 功能 | 条件 |
|
||||
|--------|------|------|
|
||||
| **`cli-internal-2026-02-09`** | 内部 CLI 功能 | `USER_TYPE === 'ant'` + CLI 入口 |
|
||||
| **`token-efficient-tools-2026-03-28`** | Token 高效工具 | `USER_TYPE === 'ant'` + GrowthBook `tengu_amber_json_tools` |
|
||||
|
||||
### Feature Flag Gated
|
||||
|
||||
| Header | 功能 | 条件 |
|
||||
|--------|------|------|
|
||||
| **`afk-mode-2026-01-31`** | AFK 模式(离开键盘自动审批) | `feature('TRANSCRIPT_CLASSIFIER')` |
|
||||
|
||||
### 其他特殊 Headers
|
||||
|
||||
| Header | 功能 | 来源 |
|
||||
|--------|------|------|
|
||||
| `oauth-2025-04-20` | OAuth 订阅者标识 | `src/constants/oauth.ts`,Pro/Max/Team/Enterprise |
|
||||
| `environments-2025-11-01` | Bridge 环境 API | `src/bridge/bridgeApi.ts`,仅 Bridge 模式 |
|
||||
|
||||
```typescript
|
||||
// src/constants/betas.ts 第 29-30 行
|
||||
// src/constants/betas.ts — 常量定义
|
||||
export const TOKEN_EFFICIENT_TOOLS_BETA_HEADER =
|
||||
'token-efficient-tools-2026-03-28'
|
||||
export const CLI_INTERNAL_BETA_HEADER =
|
||||
process.env.USER_TYPE === 'ant' ? 'cli-internal-2026-02-09' : ''
|
||||
```
|
||||
|
||||
`cli-internal` header 意味着 Anthropic 的 API 服务端也维护着一套 ant-only 的服务端行为——这不仅仅是客户端的门控。
|
||||
```typescript
|
||||
// src/utils/betas.ts 第 315-321 行——TOKEN_EFFICIENT_TOOLS 的实际门控逻辑
|
||||
if (
|
||||
process.env.USER_TYPE === 'ant' &&
|
||||
includeFirstPartyOnlyBetas &&
|
||||
tokenEfficientToolsEnabled // GrowthBook 'tengu_amber_json_tools' flag
|
||||
) {
|
||||
betaHeaders.push(TOKEN_EFFICIENT_TOOLS_BETA_HEADER)
|
||||
}
|
||||
```
|
||||
|
||||
`cli-internal` header 意味着 Anthropic 的 API 服务端也维护着一套 ant-only 的服务端行为——这不仅仅是客户端的门控。`token-efficient-tools` 进一步需要 GrowthBook flag 开启,说明 Ant 员工内部也有分层灰度。
|
||||
|
||||
## 内部代号体系
|
||||
|
||||
@@ -138,6 +186,8 @@ Anthropic 有浓厚的"动物命名"文化:
|
||||
- `DISABLE_AUTO_COMPACT` — 禁用自动压缩
|
||||
- `CLAUDE_CODE_DISABLE_AUTO_MEMORY` — 禁用自动记忆
|
||||
- `CLAUDE_CODE_DISABLE_BACKGROUND_TASKS` — 禁用后台任务
|
||||
- `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS` — 禁用实验性 beta headers
|
||||
- `USE_API_CONTEXT_MANAGEMENT` — 上下文管理工具清除(需 ant)
|
||||
</Accordion>
|
||||
<Accordion title="功能启用开关">
|
||||
- `CLAUDE_CODE_VERIFY_PLAN` — 启用 VerifyPlanExecutionTool
|
||||
@@ -151,6 +201,7 @@ Anthropic 有浓厚的"动物命名"文化:
|
||||
- `CLAUDE_CODE_COORDINATOR_MODE` — 启用 Coordinator 模式
|
||||
- `CLAUDE_INTERNAL_FC_OVERRIDES` — GrowthBook flag 覆盖(ant-only)
|
||||
- `IS_DEMO` — 演示模式(隐藏内部命令和敏感信息)
|
||||
- `CLAUDE_CODE_ENTRYPOINT` — 入口类型标识(`cli` | 其他)
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
---
|
||||
title: "GrowthBook 适配器 - 自定义 Feature Flag 服务器接入"
|
||||
description: "通过环境变量连接自定义 GrowthBook 服务器,实现远程 feature flag 控制。无配置时自动回退到代码默认值。"
|
||||
keywords: ["growthbook", "feature flags", "远程配置", "适配器", "环境变量"]
|
||||
---
|
||||
|
||||
## 概述
|
||||
|
||||
Claude Code 的 GrowthBook 系统支持通过环境变量连接自定义 GrowthBook 服务器,实现远程 feature flag 控制。
|
||||
|
||||
- **有配置时**:连接你的 GrowthBook 实例,拉取并缓存 feature 值
|
||||
- **无配置时**:所有 feature 读取直接返回代码中的默认值,零网络请求
|
||||
|
||||
## 环境变量
|
||||
|
||||
| 变量 | 必填 | 说明 |
|
||||
|---|---|---|
|
||||
| `CLAUDE_GB_ADAPTER_URL` | 是 | GrowthBook API 地址,如 `https://gb.example.com/` |
|
||||
| `CLAUDE_GB_ADAPTER_KEY` | 是 | GrowthBook SDK Client Key,如 `sdk-xxxxx` |
|
||||
|
||||
两个变量都设置时启用适配器模式,否则完全跳过 GrowthBook。
|
||||
|
||||
## 使用方式
|
||||
|
||||
### 基本用法
|
||||
|
||||
```bash
|
||||
CLAUDE_GB_ADAPTER_URL=https://gb.example.com/ \
|
||||
CLAUDE_GB_ADAPTER_KEY=sdk-abc123 \
|
||||
bun run dev
|
||||
```
|
||||
|
||||
### 不使用 GrowthBook(默认行为)
|
||||
|
||||
```bash
|
||||
bun run dev
|
||||
# 所有 getFeatureValue_CACHED_MAY_BE_STALE("xxx", defaultValue) 直接返回 defaultValue
|
||||
```
|
||||
|
||||
## GrowthBook 服务端配置
|
||||
|
||||
### 步骤
|
||||
|
||||
1. **部署 GrowthBook 服务端**(Docker 自托管或 Cloud 版)
|
||||
2. **创建 Environment**(如 `production`)
|
||||
3. **创建 SDK Connection**,获得 SDK Key(即 `CLAUDE_GB_ADAPTER_KEY`)
|
||||
4. **按需添加 Feature**,key 和类型见下方列表
|
||||
|
||||
### 核心原则
|
||||
|
||||
- **不配置任何 feature 也能正常运行**——代码中每个调用都提供了默认值
|
||||
- 只创建你想远程控制的 feature,其余走代码默认
|
||||
- GrowthBook 上配了某个 feature 后,其值会覆盖代码中的默认值
|
||||
|
||||
## Feature Key 列表
|
||||
|
||||
### 高频使用
|
||||
|
||||
| Feature Key | 类型 | 代码默认值 | 用途 |
|
||||
|---|---|---|---|
|
||||
| `tengu_hive_evidence` | boolean | `false` | 任务证据系统 |
|
||||
| `tengu_quartz_lantern` | boolean | `false` | 文件写入/编辑保护 |
|
||||
| `tengu_auto_background_agents` | boolean | `false` | 自动后台 Agent |
|
||||
| `tengu_agent_list_attach` | boolean | `false` | Agent 列表附件 |
|
||||
| `tengu_amber_stoat` | boolean | `true` | 内置 Agents |
|
||||
| `tengu_slim_subagent_claudemd` | boolean | `true` | 子 Agent CLAUDE.md |
|
||||
| `tengu_attribution_header` | boolean | `true` | API 归因 Header |
|
||||
| `tengu_cobalt_harbor` | boolean | `false` | Bridge 模式 |
|
||||
| `tengu_ccr_bridge` | boolean | `false` | CCR Bridge |
|
||||
| `tengu_cicada_nap_ms` | number | `0` | 后台刷新节流(毫秒) |
|
||||
| `tengu_miraculo_the_bard` | boolean | `false` | 启动欢迎信息 |
|
||||
|
||||
### Agent / 工具控制
|
||||
|
||||
| Feature Key | 类型 | 代码默认值 | 用途 |
|
||||
|---|---|---|---|
|
||||
| `tengu_surreal_dali` | boolean | `false` | 远程触发工具 |
|
||||
| `tengu_glacier_2xr` | boolean | `false` | 工具搜索增强 |
|
||||
| `tengu_plum_vx3` | boolean | `false` | Web Search 使用 Haiku |
|
||||
| `tengu_destructive_command_warning` | boolean | `false` | 危险命令警告 |
|
||||
| `tengu_birch_trellis` | boolean | `true` | Bash 权限控制 |
|
||||
| `tengu_harbor_permissions` | boolean | `false` | Harbor 权限模式 |
|
||||
|
||||
### Bridge / 远程连接
|
||||
|
||||
| Feature Key | 类型 | 代码默认值 | 用途 |
|
||||
|---|---|---|---|
|
||||
| `tengu_bridge_repl_v2` | boolean | `false` | Bridge REPL v2 |
|
||||
| `tengu_copper_bridge` | boolean | `false` | Copper Bridge |
|
||||
| `tengu_ccr_mirror` | boolean | `false` | CCR Mirror |
|
||||
|
||||
### 内存 / 上下文
|
||||
|
||||
| Feature Key | 类型 | 代码默认值 | 用途 |
|
||||
|---|---|---|---|
|
||||
| `tengu_coral_fern` | boolean | `false` | 内存目录功能 |
|
||||
| `tengu_passport_quail` | boolean | `false` | 内存路径配置 |
|
||||
| `tengu_slate_thimble` | boolean | `false` | Slate Thimble |
|
||||
| `tengu_herring_clock` | boolean | `false` | 跳过索引 |
|
||||
| `tengu_session_memory` | boolean | `false` | 会话内存 |
|
||||
| `tengu_pebble_leaf_prune` | boolean | `false` | 内存修剪 |
|
||||
|
||||
### UI / 体验
|
||||
|
||||
| Feature Key | 类型 | 代码默认值 | 用途 |
|
||||
|---|---|---|---|
|
||||
| `tengu_terminal_sidebar` | boolean | `false` | 终端侧边栏 |
|
||||
| `tengu_terminal_panel` | boolean | `false` | 终端面板 |
|
||||
| `tengu_willow_mode` | boolean | `false` | Willow 模式 |
|
||||
| `tengu_collage_kaleidoscope` | boolean | `false` | UI 效果 |
|
||||
| `tengu_chrome_auto_enable` | boolean | `false` | Chrome 自动启用 |
|
||||
| `tengu_immediate_model_command` | boolean | `false` | 即时模型切换 |
|
||||
| `tengu_remote_backend` | boolean | `false` | 远程后端 |
|
||||
|
||||
### 配置对象(动态配置)
|
||||
|
||||
| Feature Key | 类型 | 代码默认值 | 用途 |
|
||||
|---|---|---|---|
|
||||
| `tengu_file_read_limits` | object | `null` | 文件读取限制配置 |
|
||||
| `tengu_cobalt_raccoon` | object | `null` | Cobalt 配置 |
|
||||
| `tengu_cobalt_lantern` | object | `null` | Lantern 配置 |
|
||||
| `tengu_desktop_upsell` | object | `null` | 桌面版引导 |
|
||||
| `tengu_marble_sandcastle` | object | `null` | Marble 配置 |
|
||||
| `tengu_marble_fox` | object | `null` | Marble Fox 配置 |
|
||||
| `tengu_ultraplan_model` | string | `null` | Ultraplan 模型名 |
|
||||
|
||||
### Gate(布尔门控)
|
||||
|
||||
| Gate Key | 代码默认值 | 用途 |
|
||||
|---|---|---|
|
||||
| `tengu_chair_sermon` | `false` | 功能门控 |
|
||||
| `tengu_scratch` | `false` | Scratch 功能 |
|
||||
| `tengu_thinkback` | `false` | Thinkback 功能 |
|
||||
| `tengu_tool_pear` | `false` | Tool Pear 功能 |
|
||||
|
||||
## 读取优先级链
|
||||
|
||||
每个 feature 的值按以下顺序解析,第一个命中即返回:
|
||||
|
||||
```
|
||||
1. CLAUDE_INTERNAL_FC_OVERRIDES 环境变量(JSON 对象覆盖)
|
||||
↓ 未命中
|
||||
2. growthBookOverrides 配置(~/.claude.json,仅 ant 构建)
|
||||
↓ 未命中
|
||||
3. 内存缓存(remoteEvalFeatureValues,本次进程从服务器拉取)
|
||||
↓ 未命中
|
||||
4. 磁盘缓存(~/.claude.json 的 cachedGrowthBookFeatures)
|
||||
↓ 未命中
|
||||
5. 代码中的 defaultValue 参数
|
||||
```
|
||||
|
||||
## 缓存与刷新机制
|
||||
|
||||
| 机制 | 说明 |
|
||||
|---|---|
|
||||
| **磁盘缓存** | `~/.claude.json` 的 `cachedGrowthBookFeatures` 字段,跨进程持久化 |
|
||||
| **周期刷新** | 每 6 小时自动从服务器拉取最新值(`setInterval` + `unref`) |
|
||||
| **初始化超时** | 首次连接超时 5 秒,超时后使用磁盘缓存或默认值 |
|
||||
| **Auth 变更** | 登录/登出时自动销毁并重建客户端 |
|
||||
|
||||
## 实现细节
|
||||
|
||||
修改了 2 个文件共 3 处:
|
||||
|
||||
1. **`src/constants/keys.ts`** — `getGrowthBookClientKey()` 优先读取 `CLAUDE_GB_ADAPTER_KEY`
|
||||
2. **`src/services/analytics/growthbook.ts`** — `isGrowthBookEnabled()` 适配器模式下直接启用
|
||||
3. **`src/services/analytics/growthbook.ts`** — base URL 优先使用 `CLAUDE_GB_ADAPTER_URL`
|
||||
|
||||
所有 130+ 个调用方文件无需修改。
|
||||
@@ -0,0 +1,106 @@
|
||||
---
|
||||
title: "自定义 Sentry 错误上报配置"
|
||||
description: "通过环境变量连接自托管或 Cloud Sentry,实现 CLI 运行时的错误捕获与上报。不配置则完全静默。"
|
||||
keywords: ["sentry", "错误上报", "监控", "DSN", "自托管"]
|
||||
---
|
||||
|
||||
## 概述
|
||||
|
||||
Claude Code 支持通过 Sentry 捕获运行时异常并上报到你自己指定的 Sentry 实例。
|
||||
|
||||
- **配置了 `SENTRY_DSN`**:自动初始化 Sentry SDK,捕获未处理异常和关键错误
|
||||
- **未配置**:所有 Sentry 调用均为 no-op,零开销
|
||||
|
||||
## 环境变量
|
||||
|
||||
| 变量 | 必填 | 说明 |
|
||||
|---|---|---|
|
||||
| `SENTRY_DSN` | 是 | Sentry 项目 DSN,如 `https://xxx@o123456.ingest.sentry.io/789` |
|
||||
|
||||
只需要这一个变量,设置后即启用。
|
||||
|
||||
## 使用方式
|
||||
|
||||
### 自托管 Sentry
|
||||
|
||||
```bash
|
||||
SENTRY_DSN=https://public_key@your-sentry.example.com/123 \
|
||||
bun run dev
|
||||
```
|
||||
|
||||
### Sentry Cloud (SaaS)
|
||||
|
||||
```bash
|
||||
SENTRY_DSN=https://public_key@o123456.ingest.sentry.io/789 \
|
||||
bun run dev
|
||||
```
|
||||
|
||||
### 不使用 Sentry(默认行为)
|
||||
|
||||
```bash
|
||||
bun run dev
|
||||
# SENTRY_DSN 未设置,所有 sentry 函数为 no-op
|
||||
```
|
||||
|
||||
## Sentry 服务端配置
|
||||
|
||||
### 步骤
|
||||
|
||||
1. **部署 Sentry 实例**(Docker 自托管 或 使用 [sentry.io](https://sentry.io) Cloud)
|
||||
2. **创建 Project**,选择 **Node.js** 平台
|
||||
3. 获取项目的 **DSN**(Settings → Projects → Client Keys → DSN)
|
||||
4. 将 DSN 设置为 `SENTRY_DSN` 环境变量
|
||||
|
||||
## 功能详情
|
||||
|
||||
### 错误捕获
|
||||
|
||||
- **自动捕获**:`SentryErrorBoundary` 包裹关键 React 组件,捕获渲染错误
|
||||
- **手动上报**:`errorLogSink` 在写入错误日志时同步上报到 Sentry
|
||||
- **优雅关闭**:进程退出时 `closeSentry()` 确保事件发送完毕(2s 超时)
|
||||
|
||||
### 安全过滤
|
||||
|
||||
`beforeSend` 钩子会自动剥离以下敏感 header:
|
||||
|
||||
- `authorization`
|
||||
- `x-api-key`
|
||||
- `cookie`
|
||||
- `set-cookie`
|
||||
|
||||
### 忽略的错误类型
|
||||
|
||||
以下错误模式会被忽略,不会上报:
|
||||
|
||||
| 错误 | 原因 |
|
||||
|---|---|
|
||||
| `ECONNREFUSED` / `ECONNRESET` / `ENOTFOUND` / `ETIMEDOUT` | 网络不可达,不可操作 |
|
||||
| `AbortError` / `The user aborted a request` | 用户主动取消 |
|
||||
| `CancelError` | 交互式取消信号 |
|
||||
|
||||
### 其他配置
|
||||
|
||||
- **采样率**:`sampleRate: 1.0`(捕获全部错误事件)
|
||||
- **面包屑上限**:`maxBreadcrumbs: 20`(控制 payload 体积)
|
||||
- **性能事务**:已关闭(`beforeSendTransaction` 返回 `null`),仅上报错误
|
||||
|
||||
## API
|
||||
|
||||
| 函数 | 说明 |
|
||||
|---|---|
|
||||
| `initSentry()` | 初始化 SDK,在 `src/entrypoints/init.ts` 中自动调用 |
|
||||
| `captureException(error, context?)` | 手动上报异常,可附加额外上下文 |
|
||||
| `setTag(key, value)` | 设置标签,用于 Sentry 面板分组过滤 |
|
||||
| `setUser({ id, email, username })` | 设置用户上下文,用于错误归因 |
|
||||
| `closeSentry(timeoutMs?)` | 刷出队列并关闭客户端,进程退出时调用 |
|
||||
| `isSentryInitialized()` | 检查是否已初始化 |
|
||||
|
||||
## 实现文件
|
||||
|
||||
| 文件 | 说明 |
|
||||
|---|---|
|
||||
| `src/utils/sentry.ts` | 核心 SDK 初始化与封装 |
|
||||
| `src/components/SentryErrorBoundary.ts` | React Error Boundary 组件 |
|
||||
| `src/utils/errorLogSink.ts` | 错误日志 sink,集成 `captureException` |
|
||||
| `src/utils/gracefulShutdown.ts` | 优雅退出,调用 `closeSentry()` |
|
||||
| `src/entrypoints/init.ts` | 启动时调用 `initSentry()` |
|
||||
@@ -0,0 +1,155 @@
|
||||
# 遥测与远程配置下发系统审计(除 Sentry 外)
|
||||
|
||||
## 1. Datadog 日志
|
||||
|
||||
**文件**: `src/services/analytics/datadog.ts`
|
||||
|
||||
- **端点**: 通过环境变量 `DATADOG_LOGS_ENDPOINT` 配置(默认为空,即禁用)
|
||||
- **客户端 token**: 通过环境变量 `DATADOG_API_KEY` 配置(默认为空,即禁用)
|
||||
- **行为**: 批量发送日志(15s flush 间隔,100 条上限),仅限 1P(直连 Anthropic API)用户
|
||||
- **事件白名单**: `tengu_*` 系列事件(启动、错误、OAuth、工具调用等 ~35 种)
|
||||
- **基线数据**: 收集 model、platform、arch、version、userBucket(用户 hash 到 30 个桶)等
|
||||
- **仅限**: `NODE_ENV === 'production'`
|
||||
- **配置示例**: `DATADOG_LOGS_ENDPOINT=https://http-intake.logs.datadoghq.com/api/v2/logs DATADOG_API_KEY=xxx bun run dev`
|
||||
|
||||
## 2. 1P 事件日志(BigQuery)
|
||||
|
||||
**文件**: `src/services/analytics/firstPartyEventLogger.ts` + `firstPartyEventLoggingExporter.ts`
|
||||
|
||||
- **端点**: `https://api.anthropic.com/api/event_logging/batch`(staging 可切换)
|
||||
- **行为**: 使用 OpenTelemetry SDK 的 `BatchLogRecordProcessor`,批量导出到 Anthropic 自有的 BQ 管道
|
||||
- **数据**: 完整事件 metadata(session、model、env context、用户数据、subscription type 等)
|
||||
- **弹性**: 本地磁盘持久化失败事件(JSONL),二次退避重试,最多 8 次尝试
|
||||
- **Proto schema**: 事件序列化为 `ClaudeCodeInternalEvent` / `GrowthbookExperimentEvent` protobuf 格式
|
||||
- **Auth fallback**: 401 时自动去掉 auth header 重试
|
||||
|
||||
## 3. GrowthBook 远程 Feature Flags / 动态配置
|
||||
|
||||
**文件**: `src/services/analytics/growthbook.ts`
|
||||
|
||||
- **服务端**: `https://api.anthropic.com/`(remote eval 模式)
|
||||
- **行为**: 启动时拉取全量 feature flags,每 6h(外部用户)/ 20min(ant)定时刷新
|
||||
- **磁盘缓存**: feature values 写入 `~/.claude.json` 的 `cachedGrowthBookFeatures`
|
||||
- **用途**:
|
||||
- 控制 Datadog 开关(`tengu_log_datadog_events`)
|
||||
- 控制事件采样率(`tengu_event_sampling_config`)
|
||||
- 控制 sink killswitch(`tengu_frond_boric`)
|
||||
- 控制 BQ batch 配置(`tengu_1p_event_batch_config`)
|
||||
- 控制版本上限/自动更新 kill switch
|
||||
- 控制远程管理设置的安全检查 gate
|
||||
- **用户属性**: 发送 deviceId, sessionId, organizationUUID, accountUUID, email, subscriptionType 等
|
||||
|
||||
## 4. Remote Managed Settings(企业远程配置下发)
|
||||
|
||||
**文件**: `src/services/remoteManagedSettings/index.ts`
|
||||
|
||||
- **端点**: `{BASE_API_URL}/api/claude_code/settings`
|
||||
- **行为**: 企业用户配置下发,支持 ETag/304 缓存,每小时后台轮询
|
||||
- **安全**: 变更包含"危险设置"时弹窗让用户确认
|
||||
- **适用**: API key 用户全部可拉取;OAuth 用户仅 Enterprise/C4E/Team
|
||||
- **Fail-open**: 请求失败时使用本地缓存,无缓存则跳过
|
||||
|
||||
## 5. Settings Sync(设置同步)
|
||||
|
||||
**文件**: `src/services/settingsSync/index.ts`
|
||||
|
||||
- **端点**: `{BASE_API_URL}/api/claude_code/user_settings`
|
||||
- **行为**: CLI 上传本地设置/memory 到远程;CCR 模式从远程下载
|
||||
- **同步内容**: userSettings、userMemory、projectSettings、projectMemory
|
||||
- **Feature gate**: `UPLOAD_USER_SETTINGS` / `DOWNLOAD_USER_SETTINGS`
|
||||
- **文件大小限制**: 500KB/文件
|
||||
|
||||
## 6. OpenTelemetry 三方遥测
|
||||
|
||||
**文件**: `src/utils/telemetry/instrumentation.ts`
|
||||
|
||||
- **行为**: 完整的 OTEL SDK 初始化,支持 metrics / logs / traces 三种信号
|
||||
- **协议**: gRPC / http-json / http-protobuf(通过 `OTEL_EXPORTER_OTLP_PROTOCOL` 选择)
|
||||
- **exporter**: console / otlp / prometheus
|
||||
- **触发**: `CLAUDE_CODE_ENABLE_TELEMETRY=1` 环境变量
|
||||
- **增强 trace**: `feature('ENHANCED_TELEMETRY_BETA')` + GrowthBook gate `enhanced_telemetry_beta`
|
||||
|
||||
## 7. BigQuery Metrics Exporter(内部指标)
|
||||
|
||||
**文件**: `src/utils/telemetry/bigqueryExporter.ts`
|
||||
|
||||
- **端点**: `https://api.anthropic.com/api/claude_code/metrics`
|
||||
- **行为**: 定期(5min 间隔)导出 OTel metrics 到内部 BQ
|
||||
- **适用**: API 客户、C4E/Team 订阅者
|
||||
- **组织级 opt-out**: 通过 `checkMetricsEnabled()` API 查询(见下方第 8 项)
|
||||
|
||||
## 8. 组织级 Metrics Opt-out 查询
|
||||
|
||||
**文件**: `src/services/api/metricsOptOut.ts`
|
||||
|
||||
- **端点**: `https://api.anthropic.com/api/claude_code/organizations/metrics_enabled`
|
||||
- **行为**: 查询组织是否启用了 metrics,二级缓存(内存 1h + 磁盘 24h)
|
||||
- **作用**: 控制 BigQuery metrics exporter 是否导出
|
||||
|
||||
## 9. Startup Profiling
|
||||
|
||||
**文件**: `src/utils/startupProfiler.ts`
|
||||
|
||||
- **行为**: 采样启动性能数据(100% ant / 0.5% 外部),通过 `logEvent('tengu_startup_perf')` 上报
|
||||
- **详细模式**: `CLAUDE_CODE_PROFILE_STARTUP=1` 输出完整性能报告到文件
|
||||
|
||||
## 10. Beta Session Tracing
|
||||
|
||||
**文件**: `src/utils/telemetry/betaSessionTracing.ts`
|
||||
|
||||
- **行为**: 详细调试 trace,发送 system prompt、model output、tool schema 等
|
||||
- **触发**: `ENABLE_BETA_TRACING_DETAILED=1` + `BETA_TRACING_ENDPOINT`
|
||||
- **外部用户**: SDK/headless 模式自动启用,交互模式需要 GrowthBook gate `tengu_trace_lantern`
|
||||
|
||||
## 11. Bridge Poll Config(远程轮询间隔配置)
|
||||
|
||||
**文件**: `src/bridge/pollConfig.ts`
|
||||
|
||||
- **行为**: 从 GrowthBook 拉取 bridge 轮询间隔配置(`tengu_bridge_poll_interval_config`)
|
||||
- **控制**: 单会话和多会话的各种 poll interval
|
||||
|
||||
## 12. Plugin/MCP 遥测
|
||||
|
||||
**文件**: `src/utils/plugins/fetchTelemetry.ts`
|
||||
|
||||
- **行为**: 记录 plugin/marketplace 的网络请求(安装计数、marketplace clone/pull 等)
|
||||
- **事件**: `tengu_plugin_remote_fetch`,包含 host(已脱敏)、outcome、duration
|
||||
|
||||
---
|
||||
|
||||
## 全局禁用方式
|
||||
|
||||
```bash
|
||||
# 禁用所有遥测(Datadog + 1P + 调查问卷)
|
||||
DISABLE_TELEMETRY=1
|
||||
|
||||
# 更激进:禁用所有非必要网络(包括自动更新、grove、release notes 等)
|
||||
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
|
||||
|
||||
# 3P 提供商自动禁用
|
||||
CLAUDE_CODE_USE_BEDROCK=1 # 或 VERTEX/FOUNDRY
|
||||
```
|
||||
|
||||
`src/utils/privacyLevel.ts` 是集中控制点,三个级别:`default < no-telemetry < essential-traffic`。
|
||||
|
||||
---
|
||||
|
||||
## 数据流架构
|
||||
|
||||
```
|
||||
用户操作 → logEvent()
|
||||
↓
|
||||
sink.ts (路由层)
|
||||
↙ ↘
|
||||
trackDatadogEvent() logEventTo1P()
|
||||
↓ ↓
|
||||
Datadog HTTP API OTel BatchLogRecordProcessor
|
||||
(us5.datadoghq.com) ↓
|
||||
FirstPartyEventLoggingExporter
|
||||
↓
|
||||
api.anthropic.com/api/event_logging/batch
|
||||
↓
|
||||
BigQuery (ClaudeCodeInternalEvent proto)
|
||||
```
|
||||
|
||||
GrowthBook 作为独立通道,同时驱动上述两个 sink 的开关和配置。
|
||||
@@ -139,11 +139,137 @@ function getDeferredToolsCacheKey(deferredTools: Tools): string {
|
||||
|
||||
AI 的信息获取不局限于本地代码:
|
||||
|
||||
- **WebSearch**:搜索互联网获取最新信息
|
||||
- **WebFetch**:抓取特定网页内容,转换为 Markdown 供 AI 阅读
|
||||
- **WebSearch**(`src/tools/WebSearchTool/`):调用 Anthropic API 的 `web_search_20250305` server tool 搜索互联网
|
||||
- **WebFetch**(`src/tools/WebFetchTool/`):抓取特定 URL 内容,转换为 Markdown 供 AI 阅读
|
||||
|
||||
这让 AI 可以查阅文档、搜索 Stack Overflow、阅读 GitHub issue——和人类开发者的工作方式一致。
|
||||
|
||||
### WebSearch 实现机制
|
||||
|
||||
WebSearch 通过适配器模式支持两种搜索后端,由 `src/tools/WebSearchTool/adapters/` 中的工厂函数 `createAdapter()` 选择:
|
||||
|
||||
```
|
||||
适配器架构:
|
||||
WebSearchTool.call()
|
||||
→ createAdapter() 选择后端
|
||||
├─ ApiSearchAdapter — Anthropic API 服务端搜索(需官方 API 密钥)
|
||||
└─ BingSearchAdapter — 直接抓取 Bing 搜索页面解析(无需 API 密钥)
|
||||
→ adapter.search(query, options)
|
||||
→ 转换为统一 SearchResult[] 格式返回
|
||||
```
|
||||
|
||||
#### 适配器选择逻辑
|
||||
|
||||
`adapters/index.ts` 中的工厂函数按以下优先级选择后端:
|
||||
|
||||
| 优先级 | 条件 | 适配器 |
|
||||
|--------|------|--------|
|
||||
| 1 | 环境变量 `WEB_SEARCH_ADAPTER=api` | `ApiSearchAdapter` |
|
||||
| 2 | 环境变量 `WEB_SEARCH_ADAPTER=bing` | `BingSearchAdapter` |
|
||||
| 3 | API Base URL 指向 Anthropic 官方 | `ApiSearchAdapter` |
|
||||
| 4 | 第三方代理 / 非官方端点 | `BingSearchAdapter` |
|
||||
|
||||
适配器是无状态的,同一会话内缓存复用。
|
||||
|
||||
#### ApiSearchAdapter — API 服务端搜索
|
||||
|
||||
将搜索请求委托给 Anthropic API 的 `web_search_20250305` server tool:
|
||||
|
||||
```
|
||||
调用链:
|
||||
ApiSearchAdapter.search(query, options)
|
||||
→ queryModelWithStreaming() 发起独立的 API 调用
|
||||
→ 携带 extraToolSchemas: [BetaWebSearchTool20250305]
|
||||
→ API 服务端执行搜索,返回流式事件
|
||||
→ server_tool_use / web_search_tool_result / text 交替返回
|
||||
→ extractSearchResults() 从 content blocks 提取 SearchResult[]
|
||||
```
|
||||
|
||||
| 特性 | 实现 |
|
||||
|------|------|
|
||||
| **模型选择** | Feature flag `tengu_plum_vx3` 控制用 Haiku(强制 tool_choice)还是主模型 |
|
||||
| **搜索上限** | 每次调用最多 8 次搜索(`max_uses: 8`) |
|
||||
| **域过滤** | 支持 `allowedDomains` / `blockedDomains` |
|
||||
| **进度追踪** | 流式解析 `input_json_delta` 提取 query,实时回调 `onProgress` |
|
||||
|
||||
#### BingSearchAdapter — Bing 搜索页面解析
|
||||
|
||||
直接抓取 Bing 搜索 HTML 并用正则提取结果,无需 API 密钥:
|
||||
|
||||
```
|
||||
调用链:
|
||||
BingSearchAdapter.search(query, options)
|
||||
→ axios.get(bing.com/search?q=...) — 使用浏览器级别 headers 绕过反爬
|
||||
→ extractBingResults(html)
|
||||
→ 正则匹配 <li class="b_algo"> 块
|
||||
→ 提取 <h2><a> 标题和 URL
|
||||
→ resolveBingUrl() 解码 Bing 重定向链接
|
||||
→ extractSnippet() 三级降级提取摘要
|
||||
→ 客户端域过滤 (allowedDomains / blockedDomains)
|
||||
→ 返回 SearchResult[]
|
||||
```
|
||||
|
||||
**反爬策略**:Bing 对非浏览器 UA 返回需要 JS 渲染的空页面。适配器使用完整的 Edge 浏览器请求头(包含 `Sec-Ch-Ua`、`Sec-Fetch-*` 等现代浏览器标头)确保获得完整 HTML。同时使用 `setmkt=en-US` 参数统一市场定位,避免 Bing 基于用户 IP 做区域化定向(如跳转到德语/新加坡市场导致结果不相关)。
|
||||
|
||||
**URL 解码**:Bing 搜索结果中的 URL 为重定向格式(`bing.com/ck/a?...&u=a1aHR0cHM6Ly9...`),`resolveBingUrl()` 从 `u` 参数中 base64 解码出真实目标 URL(`a1` 前缀 = https,`a0` = http)。
|
||||
|
||||
**摘要提取**(`extractSnippet()`)按优先级尝试三个来源:
|
||||
1. `<p class="b_lineclamp...">` — 带行截断的摘要段落
|
||||
2. `<div class="b_caption">` 内的 `<p>` — 普通摘要段落
|
||||
3. `<div class="b_caption">` 的直接文本内容 — 兜底方案
|
||||
|
||||
| 特性 | 实现 |
|
||||
|------|------|
|
||||
| **超时** | 30 秒(`FETCH_TIMEOUT_MS`) |
|
||||
| **域过滤** | 支持 `allowedDomains` / `blockedDomains`,含子域名匹配 |
|
||||
| **进度追踪** | 发送 query_update 和 search_results_received 回调 |
|
||||
| **中止支持** | 外部 AbortSignal 传播到 axios 请求 |
|
||||
|
||||
### WebSearchTool 统一接口
|
||||
|
||||
`WebSearchTool`(`src/tools/WebSearchTool/WebSearchTool.ts`)是面向主循环的工具定义,所有 provider 均可使用(`isEnabled()` 始终返回 true)。它将适配器返回的 `SearchResult[]` 转换为内部 `Output` 格式,`mapToolResultToToolResultBlockParam` 将搜索结果格式化为带 markdown 超链接的文本,并附加 "REMINDER" 要求主模型在回复中包含 Sources。
|
||||
|
||||
### WebFetch 实现机制
|
||||
|
||||
WebFetch 是一个完整的 HTTP 客户端 + 内容处理管线:
|
||||
|
||||
```
|
||||
调用链:
|
||||
WebFetchTool.call({ url, prompt })
|
||||
→ getURLMarkdownContent(url)
|
||||
→ validateURL() — 长度≤2000、无用户名密码、公网域名
|
||||
→ URL_CACHE 命中检查(15 分钟 TTL LRU,50MB 上限)
|
||||
→ checkDomainBlocklist() — 调用 api.anthropic.com/api/web/domain_info 预检
|
||||
→ getWithPermittedRedirects() — axios 请求,自定义重定向处理
|
||||
→ HTML → Turndown 转 Markdown(懒加载单例,~1.4MB)
|
||||
→ 非 HTML → 原始文本
|
||||
→ 二进制(PDF 等)→ persistBinaryContent() 保存到磁盘
|
||||
→ applyPromptToMarkdown()
|
||||
→ 截断到 100K 字符
|
||||
→ queryHaiku() 用小模型按 prompt 提取信息
|
||||
→ 返回处理后的结果
|
||||
```
|
||||
|
||||
安全防护多层设计:
|
||||
|
||||
| 层级 | 机制 | 说明 |
|
||||
|------|------|------|
|
||||
| **域名预检** | `checkDomainBlocklist()` | 调用 `api.anthropic.com/api/web/domain_info?domain=…`,5 分钟缓存 |
|
||||
| **重定向控制** | `isPermittedRedirect()` | 仅允许同 host(±www)重定向,跨域重定向返回提示让 AI 重新调用 |
|
||||
| **重定向深度** | `MAX_REDIRECTS = 10` | 防止重定向循环无限挂起 |
|
||||
| **内容大小** | `MAX_HTTP_CONTENT_LENGTH = 10MB` | 单次响应上限 |
|
||||
| **请求超时** | `FETCH_TIMEOUT_MS = 60s` | 主请求超时;域名预检 10s |
|
||||
| **URL 验证** | `validateURL()` | 长度、协议、用户名密码、公网域名检查 |
|
||||
| **egress 检测** | `X-Proxy-Error: blocked-by-allowlist` | 检测企业代理拦截 |
|
||||
|
||||
预批准域名(`src/tools/WebFetchTool/preapproved.ts`):
|
||||
|
||||
用户无需手动授权即可抓取的域名列表,包含 ~90 个主流技术文档站点(MDN、Python docs、React docs、AWS docs 等)。列表分为 hostname-only 和 path-prefix 两类,查找复杂度 O(1)。
|
||||
|
||||
对预批准域名,WebFetch 跳过 Haiku 摘要步骤(如果内容是 Markdown 且 < 100K 字符),直接返回原文——因为技术文档本身的结构化程度已经足够好。
|
||||
|
||||
权限模型方面,WebFetch 按 hostname 生成 `domain:xxx` 规则匹配用户的 allow/deny/ask 规则,支持用户对特定域名配置永久允许或拒绝。
|
||||
|
||||
### ripgrep 的流式输出
|
||||
|
||||
对于交互式场景(如 QuickOpen),ripgrep 支持**流式输出**(`ripGrepStream()`):
|
||||
|
||||
@@ -106,8 +106,12 @@
|
||||
"docs/internals/three-tier-gating",
|
||||
"docs/internals/feature-flags",
|
||||
"docs/internals/growthbook-ab-testing",
|
||||
"docs/internals/growthbook-adapter",
|
||||
"docs/internals/sentry-setup",
|
||||
"docs/internals/hidden-features",
|
||||
"docs/internals/ant-only-world"
|
||||
"docs/internals/ant-only-world",
|
||||
"docs/features/debug-mode",
|
||||
"docs/features/buddy"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
+14
-11
@@ -37,6 +37,7 @@
|
||||
"scripts": {
|
||||
"build": "bun run build.ts",
|
||||
"dev": "bun run scripts/dev.ts",
|
||||
"dev:inspect": "bun --inspect-wait=localhost:8888/2dc3gzl5xot run scripts/dev.ts",
|
||||
"prepublishOnly": "bun run build",
|
||||
"lint": "biome lint src/",
|
||||
"lint:fix": "biome lint --fix src/",
|
||||
@@ -67,6 +68,7 @@
|
||||
"@aws-sdk/credential-provider-node": "^3.972.28",
|
||||
"@aws-sdk/credential-providers": "^3.1020.0",
|
||||
"@azure/identity": "^4.13.1",
|
||||
"@biomejs/biome": "^2.4.10",
|
||||
"@commander-js/extra-typings": "^14.0.0",
|
||||
"@growthbook/growthbook": "^1.6.5",
|
||||
"@modelcontextprotocol/sdk": "^1.29.0",
|
||||
@@ -88,8 +90,16 @@
|
||||
"@opentelemetry/sdk-metrics": "^2.6.1",
|
||||
"@opentelemetry/sdk-trace-base": "^2.6.1",
|
||||
"@opentelemetry/semantic-conventions": "^1.40.0",
|
||||
"@sentry/node": "^10.47.0",
|
||||
"@smithy/core": "^3.23.13",
|
||||
"@smithy/node-http-handler": "^4.5.1",
|
||||
"@types/bun": "^1.3.11",
|
||||
"@types/cacache": "^20.0.1",
|
||||
"@types/plist": "^3.0.5",
|
||||
"@types/react": "^19.2.14",
|
||||
"@types/react-reconciler": "^0.33.0",
|
||||
"@types/sharp": "^0.32.0",
|
||||
"@types/turndown": "^5.0.6",
|
||||
"ajv": "^8.18.0",
|
||||
"asciichart": "^1.5.25",
|
||||
"audio-capture-napi": "workspace:*",
|
||||
@@ -112,12 +122,14 @@
|
||||
"fuse.js": "^7.1.0",
|
||||
"get-east-asian-width": "^1.5.0",
|
||||
"google-auth-library": "^10.6.2",
|
||||
"he": "^1.2.0",
|
||||
"highlight.js": "^11.11.1",
|
||||
"https-proxy-agent": "^8.0.0",
|
||||
"ignore": "^7.0.5",
|
||||
"image-processor-napi": "workspace:*",
|
||||
"indent-string": "^5.0.0",
|
||||
"jsonc-parser": "^3.3.1",
|
||||
"knip": "^6.1.1",
|
||||
"lodash-es": "^4.17.23",
|
||||
"lru-cache": "^11.2.7",
|
||||
"marked": "^17.0.5",
|
||||
@@ -140,6 +152,7 @@
|
||||
"tree-kill": "^1.2.2",
|
||||
"turndown": "^7.2.2",
|
||||
"type-fest": "^5.5.0",
|
||||
"typescript": "^6.0.2",
|
||||
"undici": "^7.24.6",
|
||||
"url-handler-napi": "workspace:*",
|
||||
"usehooks-ts": "^3.1.1",
|
||||
@@ -150,16 +163,6 @@
|
||||
"ws": "^8.20.0",
|
||||
"xss": "^1.0.15",
|
||||
"yaml": "^2.8.3",
|
||||
"zod": "^4.3.6",
|
||||
"@biomejs/biome": "^2.4.10",
|
||||
"@types/bun": "^1.3.11",
|
||||
"@types/cacache": "^20.0.1",
|
||||
"@types/plist": "^3.0.5",
|
||||
"@types/react": "^19.2.14",
|
||||
"@types/react-reconciler": "^0.33.0",
|
||||
"@types/sharp": "^0.32.0",
|
||||
"@types/turndown": "^5.0.6",
|
||||
"knip": "^6.1.1",
|
||||
"typescript": "^6.0.2"
|
||||
"zod": "^4.3.6"
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
import * as React from 'react'
|
||||
import { captureException } from 'src/utils/sentry.js'
|
||||
|
||||
interface Props {
|
||||
children: React.ReactNode
|
||||
/** Optional label for identifying which component boundary caught the error */
|
||||
name?: string
|
||||
}
|
||||
|
||||
interface State {
|
||||
@@ -18,6 +21,13 @@ export class SentryErrorBoundary extends React.Component<Props, State> {
|
||||
return { hasError: true }
|
||||
}
|
||||
|
||||
componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void {
|
||||
captureException(error, {
|
||||
componentBoundary: this.props.name || 'SentryErrorBoundary',
|
||||
componentStack: errorInfo.componentStack,
|
||||
})
|
||||
}
|
||||
|
||||
render(): React.ReactNode {
|
||||
if (this.state.hasError) {
|
||||
return null
|
||||
|
||||
@@ -3,6 +3,10 @@ import { isEnvTruthy } from '../utils/envUtils.js'
|
||||
// Lazy read so ENABLE_GROWTHBOOK_DEV from globalSettings.env (applied after
|
||||
// module load) is picked up. USER_TYPE is a build-time define so it's safe.
|
||||
export function getGrowthBookClientKey(): string {
|
||||
// 适配器优先:自定义 GrowthBook 服务器
|
||||
const adapterKey = process.env.CLAUDE_GB_ADAPTER_KEY
|
||||
if (adapterKey) return adapterKey
|
||||
|
||||
return process.env.USER_TYPE === 'ant'
|
||||
? isEnvTruthy(process.env.ENABLE_GROWTHBOOK_DEV)
|
||||
? 'sdk-yZQvlplybuXjYh6L'
|
||||
|
||||
@@ -48,6 +48,7 @@ import { configureGlobalAgents } from '../utils/proxy.js'
|
||||
import { isBetaTracingEnabled } from '../utils/telemetry/betaSessionTracing.js'
|
||||
import { getTelemetryAttributes } from '../utils/telemetryAttributes.js'
|
||||
import { setShellIfWindows } from '../utils/windowsPaths.js'
|
||||
import { initSentry } from '../utils/sentry.js'
|
||||
|
||||
// initialize1PEventLogging is dynamically imported to defer OpenTelemetry sdk-logs/resources
|
||||
|
||||
@@ -150,6 +151,9 @@ export const init = memoize(async (): Promise<void> => {
|
||||
logForDebugging('[init] configureGlobalAgents complete')
|
||||
profileCheckpoint('init_network_configured')
|
||||
|
||||
// Initialize Sentry for error reporting (no-op if SENTRY_DSN not set)
|
||||
initSentry()
|
||||
|
||||
// Preconnect to the Anthropic API — overlap TCP+TLS handshake
|
||||
// (~100-200ms) with the ~100ms of action-handler work before the API
|
||||
// request. After CA certs + proxy agents are configured so the warmed
|
||||
|
||||
@@ -2805,7 +2805,8 @@ export function REPL({
|
||||
})) {
|
||||
onQueryEvent(event);
|
||||
}
|
||||
if (feature('BUDDY')) {
|
||||
// TODO: implement fireCompanionObserver — companion model reaction after each query turn
|
||||
if (feature('BUDDY') && typeof fireCompanionObserver === 'function') {
|
||||
void fireCompanionObserver(messagesRef.current, reaction => setAppState(prev => prev.companionReaction === reaction ? prev : {
|
||||
...prev,
|
||||
companionReaction: reaction as string | undefined
|
||||
|
||||
@@ -9,9 +9,17 @@ import { MODEL_COSTS } from '../../utils/modelCost.js'
|
||||
import { isAnalyticsDisabled } from './config.js'
|
||||
import { getEventMetadata } from './metadata.js'
|
||||
|
||||
/**
|
||||
* Datadog endpoint and token are configurable via environment variables.
|
||||
* If neither is set, Datadog logging is disabled entirely (no data sent).
|
||||
*
|
||||
* DATADOG_LOGS_ENDPOINT=https://http-intake.logs.datadoghq.com/api/v2/logs
|
||||
* DATADOG_API_KEY=<your-key>
|
||||
*/
|
||||
const DATADOG_LOGS_ENDPOINT =
|
||||
'https://http-intake.logs.us5.datadoghq.com/api/v2/logs'
|
||||
const DATADOG_CLIENT_TOKEN = 'pubbbf48e6d78dae54bceaa4acf463299bf'
|
||||
process.env.DATADOG_LOGS_ENDPOINT ?? ''
|
||||
const DATADOG_CLIENT_TOKEN =
|
||||
process.env.DATADOG_API_KEY ?? ''
|
||||
const DEFAULT_FLUSH_INTERVAL_MS = 15000
|
||||
const MAX_BATCH_SIZE = 100
|
||||
const NETWORK_TIMEOUT_MS = 5000
|
||||
@@ -133,6 +141,12 @@ export const initializeDatadog = memoize(async (): Promise<boolean> => {
|
||||
return false
|
||||
}
|
||||
|
||||
// No custom endpoint configured — skip Datadog entirely
|
||||
if (!DATADOG_LOGS_ENDPOINT || !DATADOG_CLIENT_TOKEN) {
|
||||
datadogInitialized = false
|
||||
return false
|
||||
}
|
||||
|
||||
try {
|
||||
datadogInitialized = true
|
||||
return true
|
||||
|
||||
@@ -420,6 +420,10 @@ function syncRemoteEvalToDisk(): void {
|
||||
* Check if GrowthBook operations should be enabled
|
||||
*/
|
||||
function isGrowthBookEnabled(): boolean {
|
||||
// 适配器模式:有自定义服务器配置时直接启用
|
||||
if (process.env.CLAUDE_GB_ADAPTER_URL && process.env.CLAUDE_GB_ADAPTER_KEY) {
|
||||
return true
|
||||
}
|
||||
// GrowthBook depends on 1P event logging.
|
||||
return is1PEventLoggingEnabled()
|
||||
}
|
||||
@@ -495,15 +499,17 @@ const getGrowthBookClient = memoize(
|
||||
|
||||
const attributes = getUserAttributes()
|
||||
const clientKey = getGrowthBookClientKey()
|
||||
const baseUrl =
|
||||
process.env.CLAUDE_GB_ADAPTER_URL
|
||||
|| (process.env.USER_TYPE === 'ant'
|
||||
? process.env.CLAUDE_CODE_GB_BASE_URL || 'https://api.anthropic.com/'
|
||||
: 'https://api.anthropic.com/')
|
||||
const isAdapterMode = !!(process.env.CLAUDE_GB_ADAPTER_URL && process.env.CLAUDE_GB_ADAPTER_KEY)
|
||||
if (process.env.USER_TYPE === 'ant') {
|
||||
logForDebugging(
|
||||
`GrowthBook: Creating client with clientKey=${clientKey}, attributes: ${jsonStringify(attributes)}`,
|
||||
)
|
||||
}
|
||||
const baseUrl =
|
||||
process.env.USER_TYPE === 'ant'
|
||||
? process.env.CLAUDE_CODE_GB_BASE_URL || 'https://api.anthropic.com/'
|
||||
: 'https://api.anthropic.com/'
|
||||
|
||||
// Skip auth if trust hasn't been established yet
|
||||
// This prevents executing apiKeyHelper commands before the trust dialog
|
||||
@@ -518,7 +524,8 @@ const getGrowthBookClient = memoize(
|
||||
const authHeaders = hasTrust
|
||||
? getAuthHeaders()
|
||||
: { headers: {}, error: 'trust not established' }
|
||||
const hasAuth = !authHeaders.error
|
||||
// 适配器模式下不需要 auth,GrowthBook Cloud 用 clientKey 即可
|
||||
const hasAuth = isAdapterMode || !authHeaders.error
|
||||
clientCreatedWithAuth = hasAuth
|
||||
|
||||
// Capture in local variable so the init callback operates on THIS client,
|
||||
@@ -527,9 +534,10 @@ const getGrowthBookClient = memoize(
|
||||
apiHost: baseUrl,
|
||||
clientKey,
|
||||
attributes,
|
||||
remoteEval: true,
|
||||
// Re-fetch when user ID or org changes (org change = login to different org)
|
||||
cacheKeyAttributes: ['id', 'organizationUUID'],
|
||||
// remoteEval only works with Anthropic internal API, GrowthBook Cloud doesn't support it
|
||||
remoteEval: !isAdapterMode,
|
||||
// cacheKeyAttributes only valid with remoteEval
|
||||
...(!isAdapterMode ? { cacheKeyAttributes: ['id', 'organizationUUID'] } : {}),
|
||||
// Add auth headers if available
|
||||
...(authHeaders.error
|
||||
? {}
|
||||
@@ -566,7 +574,7 @@ const getGrowthBookClient = memoize(
|
||||
|
||||
if (process.env.USER_TYPE === 'ant') {
|
||||
logForDebugging(
|
||||
`GrowthBook initialized successfully, source: ${result.source}, success: ${result.success}`,
|
||||
`GrowthBook initialized, source: ${result.source}, success: ${result.success}`,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -384,7 +384,7 @@ export async function getURLMarkdownContent(
|
||||
// This is for enterprise customers with restrictive security policies
|
||||
// that prevent outbound connections to claude.ai
|
||||
const settings = getSettings_DEPRECATED()
|
||||
if (!settings.skipWebFetchPreflight) {
|
||||
if (settings.skipWebFetchPreflight === false) {
|
||||
const checkResult = await checkDomainBlocklist(hostname)
|
||||
switch (checkResult.status) {
|
||||
case 'allowed':
|
||||
|
||||
@@ -1,19 +1,9 @@
|
||||
import type {
|
||||
BetaContentBlock,
|
||||
BetaWebSearchTool20250305,
|
||||
} from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs'
|
||||
import { getAPIProvider } from 'src/utils/model/providers.js'
|
||||
import type { PermissionResult } from 'src/utils/permissions/PermissionResult.js'
|
||||
import { z } from 'zod/v4'
|
||||
import { getFeatureValue_CACHED_MAY_BE_STALE } from '../../services/analytics/growthbook.js'
|
||||
import { queryModelWithStreaming } from '../../services/api/claude.js'
|
||||
import { buildTool, type ToolDef } from '../../Tool.js'
|
||||
import { lazySchema } from '../../utils/lazySchema.js'
|
||||
import { logError } from '../../utils/log.js'
|
||||
import { createUserMessage } from '../../utils/messages.js'
|
||||
import { getMainLoopModel, getSmallFastModel } from '../../utils/model/model.js'
|
||||
import { jsonParse, jsonStringify } from '../../utils/slowOperations.js'
|
||||
import { asSystemPrompt } from '../../utils/systemPromptType.js'
|
||||
import { jsonStringify } from '../../utils/slowOperations.js'
|
||||
import { createAdapter } from './adapters/index.js'
|
||||
import { getWebSearchPrompt, WEB_SEARCH_TOOL_NAME } from './prompt.js'
|
||||
import {
|
||||
getToolUseSummary,
|
||||
@@ -37,12 +27,11 @@ const inputSchema = lazySchema(() =>
|
||||
)
|
||||
type InputSchema = ReturnType<typeof inputSchema>
|
||||
|
||||
type Input = z.infer<InputSchema>
|
||||
|
||||
const searchResultSchema = lazySchema(() => {
|
||||
const searchHitSchema = z.object({
|
||||
title: z.string().describe('The title of the search result'),
|
||||
url: z.string().describe('The URL of the search result'),
|
||||
snippet: z.string().optional().describe('A short description of the search result'),
|
||||
})
|
||||
|
||||
return z.object({
|
||||
@@ -73,82 +62,6 @@ export type { WebSearchProgress } from '../../types/tools.js'
|
||||
|
||||
import type { WebSearchProgress } from '../../types/tools.js'
|
||||
|
||||
function makeToolSchema(input: Input): BetaWebSearchTool20250305 {
|
||||
return {
|
||||
type: 'web_search_20250305',
|
||||
name: 'web_search',
|
||||
allowed_domains: input.allowed_domains,
|
||||
blocked_domains: input.blocked_domains,
|
||||
max_uses: 8, // Hardcoded to 8 searches maximum
|
||||
}
|
||||
}
|
||||
|
||||
function makeOutputFromSearchResponse(
|
||||
result: BetaContentBlock[],
|
||||
query: string,
|
||||
durationSeconds: number,
|
||||
): Output {
|
||||
// The result is a sequence of these blocks:
|
||||
// - text to start -- always?
|
||||
// [
|
||||
// - server_tool_use
|
||||
// - web_search_tool_result
|
||||
// - text and citation blocks intermingled
|
||||
// ]+ (this block repeated for each search)
|
||||
|
||||
const results: (SearchResult | string)[] = []
|
||||
let textAcc = ''
|
||||
let inText = true
|
||||
|
||||
for (const block of result) {
|
||||
if (block.type === 'server_tool_use') {
|
||||
if (inText) {
|
||||
inText = false
|
||||
if (textAcc.trim().length > 0) {
|
||||
results.push(textAcc.trim())
|
||||
}
|
||||
textAcc = ''
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if (block.type === 'web_search_tool_result') {
|
||||
// Handle error case - content is a WebSearchToolResultError
|
||||
if (!Array.isArray(block.content)) {
|
||||
const errorMessage = `Web search error: ${block.content.error_code}`
|
||||
logError(new Error(errorMessage))
|
||||
results.push(errorMessage)
|
||||
continue
|
||||
}
|
||||
// Success case - add results to our collection
|
||||
const hits = block.content.map(r => ({ title: r.title, url: r.url }))
|
||||
results.push({
|
||||
tool_use_id: block.tool_use_id,
|
||||
content: hits,
|
||||
})
|
||||
}
|
||||
|
||||
if (block.type === 'text') {
|
||||
if (inText) {
|
||||
textAcc += block.text
|
||||
} else {
|
||||
inText = true
|
||||
textAcc = block.text
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (textAcc.length) {
|
||||
results.push(textAcc.trim())
|
||||
}
|
||||
|
||||
return {
|
||||
query,
|
||||
results,
|
||||
durationSeconds,
|
||||
}
|
||||
}
|
||||
|
||||
export const WebSearchTool = buildTool({
|
||||
name: WEB_SEARCH_TOOL_NAME,
|
||||
searchHint: 'search the web for current information',
|
||||
@@ -166,30 +79,9 @@ export const WebSearchTool = buildTool({
|
||||
return summary ? `Searching for ${summary}` : 'Searching the web'
|
||||
},
|
||||
isEnabled() {
|
||||
const provider = getAPIProvider()
|
||||
const model = getMainLoopModel()
|
||||
|
||||
// Enable for firstParty
|
||||
if (provider === 'firstParty') {
|
||||
// Always enabled — the adapter factory selects the appropriate backend
|
||||
// (API server-side search or Bing fallback) based on provider capabilities.
|
||||
return true
|
||||
}
|
||||
|
||||
// Enable for Vertex AI with supported models (Claude 4.0+)
|
||||
if (provider === 'vertex') {
|
||||
const supportsWebSearch =
|
||||
model.includes('claude-opus-4') ||
|
||||
model.includes('claude-sonnet-4') ||
|
||||
model.includes('claude-haiku-4')
|
||||
|
||||
return supportsWebSearch
|
||||
}
|
||||
|
||||
// Foundry only ships models that already support Web Search
|
||||
if (provider === 'foundry') {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
},
|
||||
get inputSchema(): InputSchema {
|
||||
return inputSchema()
|
||||
@@ -227,9 +119,6 @@ export const WebSearchTool = buildTool({
|
||||
renderToolUseProgressMessage,
|
||||
renderToolResultMessage,
|
||||
extractSearchText() {
|
||||
// renderToolResultMessage shows only "Did N searches in Xs" chrome —
|
||||
// the results[] content never appears on screen. Heuristic would index
|
||||
// string entries in results[] (phantom match). Nothing to search.
|
||||
return ''
|
||||
},
|
||||
async validateInput(input) {
|
||||
@@ -254,149 +143,42 @@ export const WebSearchTool = buildTool({
|
||||
async call(input, context, _canUseTool, _parentMessage, onProgress) {
|
||||
const startTime = performance.now()
|
||||
const { query } = input
|
||||
const userMessage = createUserMessage({
|
||||
content: 'Perform a web search for the query: ' + query,
|
||||
})
|
||||
const toolSchema = makeToolSchema(input)
|
||||
|
||||
const useHaiku = getFeatureValue_CACHED_MAY_BE_STALE(
|
||||
'tengu_plum_vx3',
|
||||
false,
|
||||
)
|
||||
|
||||
const appState = context.getAppState()
|
||||
const queryStream = queryModelWithStreaming({
|
||||
messages: [userMessage],
|
||||
systemPrompt: asSystemPrompt([
|
||||
'You are an assistant for performing a web search tool use',
|
||||
]),
|
||||
thinkingConfig: useHaiku
|
||||
? { type: 'disabled' as const }
|
||||
: context.options.thinkingConfig,
|
||||
tools: [],
|
||||
const adapter = createAdapter()
|
||||
const adapterResults = await adapter.search(query, {
|
||||
allowedDomains: input.allowed_domains,
|
||||
blockedDomains: input.blocked_domains,
|
||||
signal: context.abortController.signal,
|
||||
options: {
|
||||
getToolPermissionContext: async () => appState.toolPermissionContext,
|
||||
model: useHaiku ? getSmallFastModel() : context.options.mainLoopModel,
|
||||
toolChoice: useHaiku ? { type: 'tool', name: 'web_search' } : undefined,
|
||||
isNonInteractiveSession: context.options.isNonInteractiveSession,
|
||||
hasAppendSystemPrompt: !!context.options.appendSystemPrompt,
|
||||
extraToolSchemas: [toolSchema],
|
||||
querySource: 'web_search_tool',
|
||||
agents: context.options.agentDefinitions.activeAgents,
|
||||
mcpTools: [],
|
||||
agentId: context.agentId,
|
||||
effortValue: appState.effortValue,
|
||||
},
|
||||
})
|
||||
|
||||
const allContentBlocks: BetaContentBlock[] = []
|
||||
let currentToolUseId = null
|
||||
let currentToolUseJson = ''
|
||||
let progressCounter = 0
|
||||
const toolUseQueries = new Map() // Map of tool_use_id to query
|
||||
|
||||
for await (const event of queryStream) {
|
||||
if (event.type === 'assistant') {
|
||||
const msg = event as { message: { content: BetaContentBlock[] } }
|
||||
allContentBlocks.push(...msg.message.content)
|
||||
continue
|
||||
}
|
||||
|
||||
// Track tool use ID when server_tool_use starts
|
||||
if (
|
||||
event.type === 'stream_event'
|
||||
) {
|
||||
const streamEvt = event as { event?: { type: string; content_block?: { type: string; id?: string; tool_use_id?: string; content?: unknown; [key: string]: unknown }; delta?: { type: string; partial_json?: string; [key: string]: unknown }; [key: string]: unknown } }
|
||||
if (streamEvt.event?.type === 'content_block_start') {
|
||||
const contentBlock = streamEvt.event.content_block
|
||||
if (contentBlock && contentBlock.type === 'server_tool_use') {
|
||||
currentToolUseId = contentBlock.id as string
|
||||
currentToolUseJson = ''
|
||||
// Note: The ServerToolUseBlock doesn't contain input.query
|
||||
// The actual query comes through input_json_delta events
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Accumulate JSON for current tool use
|
||||
if (
|
||||
currentToolUseId &&
|
||||
streamEvt.event?.type === 'content_block_delta'
|
||||
) {
|
||||
const delta = streamEvt.event.delta
|
||||
if (delta?.type === 'input_json_delta' && delta.partial_json) {
|
||||
currentToolUseJson += delta.partial_json
|
||||
|
||||
// Try to extract query from partial JSON for progress updates
|
||||
try {
|
||||
// Look for a complete query field
|
||||
const queryMatch = currentToolUseJson.match(
|
||||
/"query"\s*:\s*"((?:[^"\\]|\\.)*)"/,
|
||||
)
|
||||
if (queryMatch && queryMatch[1]) {
|
||||
// The regex properly handles escaped characters
|
||||
const query = jsonParse('"' + queryMatch[1] + '"')
|
||||
|
||||
if (
|
||||
!toolUseQueries.has(currentToolUseId) ||
|
||||
toolUseQueries.get(currentToolUseId) !== query
|
||||
) {
|
||||
toolUseQueries.set(currentToolUseId, query)
|
||||
progressCounter++
|
||||
onProgress(progress) {
|
||||
if (onProgress) {
|
||||
const progressCounter = Date.now()
|
||||
onProgress({
|
||||
toolUseID: `search-progress-${progressCounter}`,
|
||||
data: {
|
||||
type: 'query_update',
|
||||
query,
|
||||
},
|
||||
data: progress,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Ignore parsing errors for partial JSON
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Yield progress when search results come in
|
||||
if (
|
||||
streamEvt.event?.type === 'content_block_start'
|
||||
) {
|
||||
const contentBlock = streamEvt.event.content_block
|
||||
if (contentBlock && contentBlock.type === 'web_search_tool_result') {
|
||||
// Get the actual query that was used for this search
|
||||
const toolUseId = contentBlock.tool_use_id
|
||||
const actualQuery = toolUseQueries.get(toolUseId) || query
|
||||
const content = contentBlock.content
|
||||
|
||||
progressCounter++
|
||||
if (onProgress) {
|
||||
onProgress({
|
||||
toolUseID: toolUseId || `search-progress-${progressCounter}`,
|
||||
data: {
|
||||
type: 'search_results_received',
|
||||
resultCount: Array.isArray(content) ? content.length : 0,
|
||||
query: actualQuery,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
} // end stream_event
|
||||
}
|
||||
|
||||
// Process the final result
|
||||
const endTime = performance.now()
|
||||
const durationSeconds = (endTime - startTime) / 1000
|
||||
|
||||
const data = makeOutputFromSearchResponse(
|
||||
allContentBlocks,
|
||||
// Convert adapter SearchResult[] to legacy Output format
|
||||
const results: (SearchResult | string)[] = []
|
||||
if (adapterResults.length > 0) {
|
||||
results.push({
|
||||
tool_use_id: 'adapter-search-1',
|
||||
content: adapterResults.map(r => ({ title: r.title, url: r.url, snippet: r.snippet })),
|
||||
})
|
||||
} else {
|
||||
results.push('No search results found.')
|
||||
}
|
||||
|
||||
const data: Output = {
|
||||
query,
|
||||
results,
|
||||
durationSeconds,
|
||||
)
|
||||
}
|
||||
return { data }
|
||||
},
|
||||
mapToolResultToToolResultBlockParam(output, toolUseID) {
|
||||
@@ -404,20 +186,23 @@ export const WebSearchTool = buildTool({
|
||||
|
||||
let formattedOutput = `Web search results for query: "${query}"\n\n`
|
||||
|
||||
// Process the results array - it can contain both string summaries and search result objects.
|
||||
// Guard against null/undefined entries that can appear after JSON round-tripping
|
||||
// (e.g., from compaction or transcript deserialization).
|
||||
;(results ?? []).forEach(result => {
|
||||
if (result == null) {
|
||||
return
|
||||
}
|
||||
if (typeof result === 'string') {
|
||||
// Text summary
|
||||
formattedOutput += result + '\n\n'
|
||||
} else {
|
||||
// Search result with links
|
||||
if (result.content?.length > 0) {
|
||||
formattedOutput += `Links: ${jsonStringify(result.content)}\n\n`
|
||||
formattedOutput += 'Links:\n'
|
||||
for (const link of result.content) {
|
||||
formattedOutput += ` - [${link.title}](${link.url})`
|
||||
if (link.snippet) {
|
||||
formattedOutput += `: ${link.snippet}`
|
||||
}
|
||||
formattedOutput += '\n'
|
||||
}
|
||||
formattedOutput += '\n'
|
||||
} else {
|
||||
formattedOutput += 'No links found.\n\n'
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Integration test for BingSearchAdapter — hits the real Bing search.
|
||||
*
|
||||
* Usage:
|
||||
* bun run src/tools/WebSearchTool/__tests__/bingAdapter.integration.ts
|
||||
*
|
||||
* Optional env vars:
|
||||
* BING_QUERY — search query (default: "Claude AI Anthropic")
|
||||
*/
|
||||
|
||||
// Provide MACRO globals needed by the codebase when running outside dev mode
|
||||
if (!globalThis.MACRO) {
|
||||
globalThis.MACRO = { VERSION: '0.0.0-test', BUILD_TIME: '0' } as any
|
||||
}
|
||||
|
||||
import { BingSearchAdapter, extractBingResults } from '../adapters/bingAdapter'
|
||||
|
||||
const query = process.env.BING_QUERY || 'Claude AI Anthropic'
|
||||
|
||||
async function main() {
|
||||
console.log(`\n🔍 Searching Bing for: "${query}"\n`)
|
||||
|
||||
const adapter = new BingSearchAdapter()
|
||||
const startTime = Date.now()
|
||||
|
||||
const results = await adapter.search(query, {
|
||||
onProgress: (p) => {
|
||||
if (p.type === 'query_update') {
|
||||
console.log(` → Query sent: ${p.query}`)
|
||||
}
|
||||
if (p.type === 'search_results_received') {
|
||||
console.log(` → Received ${p.resultCount} results`)
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const elapsed = Date.now() - startTime
|
||||
console.log(`\n✅ Done in ${elapsed}ms — ${results.length} result(s)\n`)
|
||||
|
||||
if (results.length === 0) {
|
||||
console.log('⚠️ No results returned. Possible causes:')
|
||||
console.log(' - Bing returned a CAPTCHA or rate-limited the request')
|
||||
console.log(' - Network/firewall issue')
|
||||
console.log(' - Bing HTML structure changed')
|
||||
console.log(' - Anti-bot detection triggered\n')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
for (const [i, r] of results.entries()) {
|
||||
console.log(` ${i + 1}. ${r.title}`)
|
||||
console.log(` ${r.url}`)
|
||||
if (r.snippet) {
|
||||
const snippet = r.snippet.replace(/\n/g, ' ')
|
||||
console.log(` ${snippet.slice(0, 150)}${snippet.length > 150 ? '…' : ''}`)
|
||||
}
|
||||
console.log()
|
||||
}
|
||||
|
||||
// Validate result structure
|
||||
let passed = true
|
||||
for (const [i, r] of results.entries()) {
|
||||
if (!r.title || typeof r.title !== 'string') {
|
||||
console.error(`❌ Result ${i + 1}: missing or non-string title`, r)
|
||||
passed = false
|
||||
}
|
||||
if (!r.url || !r.url.startsWith('http')) {
|
||||
console.error(`❌ Result ${i + 1}: missing or non-http url`, r)
|
||||
passed = false
|
||||
}
|
||||
}
|
||||
|
||||
if (passed) {
|
||||
console.log('✅ All results have valid structure.\n')
|
||||
} else {
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error('❌ Fatal error:', e)
|
||||
process.exit(1)
|
||||
})
|
||||
@@ -0,0 +1,499 @@
|
||||
import { describe, expect, mock, test } from 'bun:test'
|
||||
import { extractBingResults, decodeHtmlEntities } from '../adapters/bingAdapter'
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// decodeHtmlEntities
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
describe('decodeHtmlEntities', () => {
|
||||
test('decodes common named entities', () => {
|
||||
expect(decodeHtmlEntities('& < >')).toBe('& < >')
|
||||
})
|
||||
|
||||
test('decodes quote entities', () => {
|
||||
expect(decodeHtmlEntities('"hello"')).toBe('"hello"')
|
||||
})
|
||||
|
||||
test('decodes numeric and hex apostrophe entities', () => {
|
||||
expect(decodeHtmlEntities(''it's')).toBe("'it's")
|
||||
})
|
||||
|
||||
test('decodes to non-breaking space (\\u00A0)', () => {
|
||||
expect(decodeHtmlEntities('a b')).toBe('a\u00A0b')
|
||||
})
|
||||
|
||||
test('returns plain text unchanged', () => {
|
||||
expect(decodeHtmlEntities('hello world')).toBe('hello world')
|
||||
})
|
||||
|
||||
test('handles empty string', () => {
|
||||
expect(decodeHtmlEntities('')).toBe('')
|
||||
})
|
||||
|
||||
test('decodes multiple occurrences of the same entity', () => {
|
||||
expect(decodeHtmlEntities('a&b&c')).toBe('a&b&c')
|
||||
})
|
||||
|
||||
test('handles mixed entities in one string', () => {
|
||||
expect(decodeHtmlEntities('<a href="x">')).toBe('<a\u00A0href="x">')
|
||||
})
|
||||
})
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// extractBingResults
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
describe('extractBingResults', () => {
|
||||
test('extracts results from standard Bing HTML', () => {
|
||||
const html = `
|
||||
<ol id="b_results">
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://example.com/page1" h="ID=SERP,1">Example Title 1</a></h2>
|
||||
<div class="b_caption">
|
||||
<p class="b_lineclamp">First result description</p>
|
||||
</div>
|
||||
</li>
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://example.com/page2" h="ID=SERP,2">Example Title 2</a></h2>
|
||||
<div class="b_caption">
|
||||
<p class="b_lineclamp">Second result description</p>
|
||||
</div>
|
||||
</li>
|
||||
</ol>
|
||||
`
|
||||
const results = extractBingResults(html)
|
||||
expect(results).toHaveLength(2)
|
||||
expect(results[0]).toEqual({
|
||||
title: 'Example Title 1',
|
||||
url: 'https://example.com/page1',
|
||||
snippet: 'First result description',
|
||||
})
|
||||
expect(results[1]).toEqual({
|
||||
title: 'Example Title 2',
|
||||
url: 'https://example.com/page2',
|
||||
snippet: 'Second result description',
|
||||
})
|
||||
})
|
||||
|
||||
test('returns empty array when no b_algo blocks exist', () => {
|
||||
const html = `
|
||||
<ol id="b_results">
|
||||
<li class="b_ad">Ad result</li>
|
||||
<li class="b_ans">Answer card</li>
|
||||
</ol>
|
||||
`
|
||||
expect(extractBingResults(html)).toEqual([])
|
||||
})
|
||||
|
||||
test('returns empty array for empty HTML', () => {
|
||||
expect(extractBingResults('')).toEqual([])
|
||||
})
|
||||
|
||||
test('returns empty array for unrelated HTML', () => {
|
||||
expect(extractBingResults('<html><body>Hello</body></html>')).toEqual([])
|
||||
})
|
||||
|
||||
test('skips Bing-internal links', () => {
|
||||
const html = `
|
||||
<li class="b_algo">
|
||||
<h2><a href="/search?q=more">More results</a></h2>
|
||||
</li>
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://www.bing.com/videos">Bing Videos</a></h2>
|
||||
</li>
|
||||
<li class="b_algo">
|
||||
<h2><a href="#anchor">Jump link</a></h2>
|
||||
</li>
|
||||
`
|
||||
expect(extractBingResults(html)).toEqual([])
|
||||
})
|
||||
|
||||
test('strips HTML tags from titles', () => {
|
||||
const html = `
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://example.com">Result with <strong>bold</strong> and <em>italic</em></a></h2>
|
||||
</li>
|
||||
`
|
||||
const results = extractBingResults(html)
|
||||
expect(results).toHaveLength(1)
|
||||
expect(results[0].title).toBe('Result with bold and italic')
|
||||
})
|
||||
|
||||
test('decodes HTML entities in titles', () => {
|
||||
const html = `
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://example.com">Tom & Jerry <cartoon></a></h2>
|
||||
</li>
|
||||
`
|
||||
const results = extractBingResults(html)
|
||||
expect(results[0].title).toBe('Tom & Jerry <cartoon>')
|
||||
})
|
||||
|
||||
test('extracts snippet from b_lineclamp class', () => {
|
||||
const html = `
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://example.com">Title</a></h2>
|
||||
<p class="b_lineclamp3 b_algo_slug">Lineclamp snippet text here</p>
|
||||
</li>
|
||||
`
|
||||
const results = extractBingResults(html)
|
||||
expect(results[0].snippet).toBe('Lineclamp snippet text here')
|
||||
})
|
||||
|
||||
test('extracts snippet from b_caption paragraph fallback', () => {
|
||||
const html = `
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://example.com">Title</a></h2>
|
||||
<div class="b_caption">
|
||||
<p>Caption paragraph text</p>
|
||||
</div>
|
||||
</li>
|
||||
`
|
||||
const results = extractBingResults(html)
|
||||
expect(results[0].snippet).toBe('Caption paragraph text')
|
||||
})
|
||||
|
||||
test('extracts snippet from b_caption div fallback', () => {
|
||||
const html = `
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://example.com">Title</a></h2>
|
||||
<div class="b_caption">Direct caption text without p tag</div>
|
||||
</li>
|
||||
`
|
||||
const results = extractBingResults(html)
|
||||
expect(results[0].snippet).toBe('Direct caption text without p tag')
|
||||
})
|
||||
|
||||
test('returns undefined snippet when no caption exists', () => {
|
||||
const html = `
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://example.com">Title Only</a></h2>
|
||||
</li>
|
||||
`
|
||||
const results = extractBingResults(html)
|
||||
expect(results[0].snippet).toBeUndefined()
|
||||
})
|
||||
|
||||
test('handles mixed result types and only extracts b_algo', () => {
|
||||
const html = `
|
||||
<ol id="b_results">
|
||||
<li class="b_ad"><h2><a href="https://ad.com">Ad Title</a></h2></li>
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://real-result.com">Real Result</a></h2>
|
||||
<p class="b_lineclamp">A real snippet</p>
|
||||
</li>
|
||||
<li class="b_ans"><div>People also ask</div></li>
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://another.com">Another Result</a></h2>
|
||||
</li>
|
||||
</ol>
|
||||
`
|
||||
const results = extractBingResults(html)
|
||||
expect(results).toHaveLength(2)
|
||||
expect(results[0].title).toBe('Real Result')
|
||||
expect(results[1].title).toBe('Another Result')
|
||||
})
|
||||
|
||||
test('skips b_algo blocks without h2 > a structure', () => {
|
||||
const html = `
|
||||
<li class="b_algo">
|
||||
<div>No link here</div>
|
||||
</li>
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://example.com">Valid Result</a></h2>
|
||||
</li>
|
||||
`
|
||||
const results = extractBingResults(html)
|
||||
expect(results).toHaveLength(1)
|
||||
expect(results[0].title).toBe('Valid Result')
|
||||
})
|
||||
|
||||
test('handles extra whitespace in h2 > a structure', () => {
|
||||
const html = `
|
||||
<li class="b_algo">
|
||||
<h2>
|
||||
<a href="https://example.com" h="ID=SERP,1" >
|
||||
Whitespace Title
|
||||
</a>
|
||||
</h2>
|
||||
</li>
|
||||
`
|
||||
const results = extractBingResults(html)
|
||||
expect(results).toHaveLength(1)
|
||||
expect(results[0].title).toBe('Whitespace Title')
|
||||
})
|
||||
|
||||
test('handles snippet with HTML entities', () => {
|
||||
const html = `
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://example.com">Title</a></h2>
|
||||
<p class="b_lineclamp">5 < 10 & 10 > 5</p>
|
||||
</li>
|
||||
`
|
||||
const results = extractBingResults(html)
|
||||
expect(results[0].snippet).toBe('5 < 10 & 10 > 5')
|
||||
})
|
||||
|
||||
test('handles real-world Bing HTML structure', () => {
|
||||
const html = `
|
||||
<ol id="b_results" role="main">
|
||||
<li class="b_algo" data-id="">
|
||||
<div class="b_title">
|
||||
<h2>
|
||||
<a href="https://docs.python.org/3/tutorial/index.html" target="_blank" h="ID=SERP,5125.1">
|
||||
Python Tutorial
|
||||
</a>
|
||||
</h2>
|
||||
</div>
|
||||
<div class="b_caption">
|
||||
<div class="b_attribution" u="0|5125|4976674477245">
|
||||
<cite>https://docs.python.org</cite>
|
||||
</div>
|
||||
<p class="b_lineclamp3">
|
||||
Welcome to the Python Tutorial. This tutorial introduces you to the basic concepts and features...
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
<li class="b_algo">
|
||||
<h2>
|
||||
<a href="https://realpython.com/python-guide/" h="ID=SERP,5125.2">
|
||||
Real Python Guide
|
||||
</a>
|
||||
</h2>
|
||||
<div class="b_caption">
|
||||
<div class="b_attribution">
|
||||
<cite>https://realpython.com</cite>
|
||||
</div>
|
||||
<p>
|
||||
The ultimate Python guide for beginners and experts alike.
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
</ol>
|
||||
`
|
||||
const results = extractBingResults(html)
|
||||
expect(results).toHaveLength(2)
|
||||
expect(results[0].title).toBe('Python Tutorial')
|
||||
expect(results[0].url).toBe('https://docs.python.org/3/tutorial/index.html')
|
||||
expect(results[0].snippet).toContain('Welcome to the Python Tutorial')
|
||||
expect(results[1].title).toBe('Real Python Guide')
|
||||
expect(results[1].snippet).toContain('ultimate Python guide')
|
||||
})
|
||||
})
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// BingSearchAdapter.search (integration with mocked axios)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
describe('BingSearchAdapter.search', () => {
|
||||
// Dynamic import so mock.module() takes effect
|
||||
const createAdapter = async () => {
|
||||
const { BingSearchAdapter } = await import('../adapters/bingAdapter')
|
||||
return new BingSearchAdapter()
|
||||
}
|
||||
|
||||
const SAMPLE_HTML = `
|
||||
<ol id="b_results">
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://example.com/result1">Result One</a></h2>
|
||||
<p class="b_lineclamp">Snippet one</p>
|
||||
</li>
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://example.com/result2">Result Two</a></h2>
|
||||
<p class="b_lineclamp">Snippet two</p>
|
||||
</li>
|
||||
</ol>
|
||||
`
|
||||
|
||||
test('returns parsed results from fetched HTML', async () => {
|
||||
mock.module('axios', () => ({
|
||||
default: {
|
||||
get: mock(() => Promise.resolve({ data: SAMPLE_HTML })),
|
||||
isCancel: () => false,
|
||||
},
|
||||
}))
|
||||
mock.module('../../../utils/http', () => ({
|
||||
getWebFetchUserAgent: () => 'TestAgent/1.0',
|
||||
}))
|
||||
|
||||
const adapter = await createAdapter()
|
||||
const results = await adapter.search('test query', {})
|
||||
expect(results).toHaveLength(2)
|
||||
expect(results[0].title).toBe('Result One')
|
||||
expect(results[1].title).toBe('Result Two')
|
||||
})
|
||||
|
||||
test('calls onProgress with query_update and search_results_received', async () => {
|
||||
mock.module('axios', () => ({
|
||||
default: {
|
||||
get: mock(() => Promise.resolve({ data: SAMPLE_HTML })),
|
||||
isCancel: () => false,
|
||||
},
|
||||
}))
|
||||
mock.module('../../../utils/http', () => ({
|
||||
getWebFetchUserAgent: () => 'TestAgent/1.0',
|
||||
}))
|
||||
|
||||
const progressCalls: any[] = []
|
||||
const onProgress = (p: any) => progressCalls.push(p)
|
||||
|
||||
const adapter = await createAdapter()
|
||||
await adapter.search('test', { onProgress })
|
||||
|
||||
expect(progressCalls).toHaveLength(2)
|
||||
expect(progressCalls[0].type).toBe('query_update')
|
||||
expect(progressCalls[0].query).toBe('test')
|
||||
expect(progressCalls[1].type).toBe('search_results_received')
|
||||
expect(progressCalls[1].resultCount).toBe(2)
|
||||
})
|
||||
|
||||
test('filters results by allowedDomains', async () => {
|
||||
const mixedHtml = `
|
||||
<ol id="b_results">
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://allowed.com/a">Allowed Result</a></h2>
|
||||
</li>
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://blocked.com/b">Blocked Result</a></h2>
|
||||
</li>
|
||||
</ol>
|
||||
`
|
||||
mock.module('axios', () => ({
|
||||
default: {
|
||||
get: mock(() => Promise.resolve({ data: mixedHtml })),
|
||||
isCancel: () => false,
|
||||
},
|
||||
}))
|
||||
mock.module('../../../utils/http', () => ({
|
||||
getWebFetchUserAgent: () => 'TestAgent/1.0',
|
||||
}))
|
||||
|
||||
const adapter = await createAdapter()
|
||||
const results = await adapter.search('test', {
|
||||
allowedDomains: ['allowed.com'],
|
||||
})
|
||||
expect(results).toHaveLength(1)
|
||||
expect(results[0].url).toBe('https://allowed.com/a')
|
||||
})
|
||||
|
||||
test('filters results by blockedDomains', async () => {
|
||||
const mixedHtml = `
|
||||
<ol id="b_results">
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://good.com/a">Good Result</a></h2>
|
||||
</li>
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://spam.com/b">Spam Result</a></h2>
|
||||
</li>
|
||||
</ol>
|
||||
`
|
||||
mock.module('axios', () => ({
|
||||
default: {
|
||||
get: mock(() => Promise.resolve({ data: mixedHtml })),
|
||||
isCancel: () => false,
|
||||
},
|
||||
}))
|
||||
mock.module('../../../utils/http', () => ({
|
||||
getWebFetchUserAgent: () => 'TestAgent/1.0',
|
||||
}))
|
||||
|
||||
const adapter = await createAdapter()
|
||||
const results = await adapter.search('test', {
|
||||
blockedDomains: ['spam.com'],
|
||||
})
|
||||
expect(results).toHaveLength(1)
|
||||
expect(results[0].url).toBe('https://good.com/a')
|
||||
})
|
||||
|
||||
test('filters subdomains with allowedDomains', async () => {
|
||||
const html = `
|
||||
<ol id="b_results">
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://docs.example.com/page">Subdomain Result</a></h2>
|
||||
</li>
|
||||
<li class="b_algo">
|
||||
<h2><a href="https://other.com/page">Other Result</a></h2>
|
||||
</li>
|
||||
</ol>
|
||||
`
|
||||
mock.module('axios', () => ({
|
||||
default: {
|
||||
get: mock(() => Promise.resolve({ data: html })),
|
||||
isCancel: () => false,
|
||||
},
|
||||
}))
|
||||
mock.module('../../../utils/http', () => ({
|
||||
getWebFetchUserAgent: () => 'TestAgent/1.0',
|
||||
}))
|
||||
|
||||
const adapter = await createAdapter()
|
||||
const results = await adapter.search('test', {
|
||||
allowedDomains: ['example.com'],
|
||||
})
|
||||
expect(results).toHaveLength(1)
|
||||
expect(results[0].url).toBe('https://docs.example.com/page')
|
||||
})
|
||||
|
||||
test('throws AbortError when signal is already aborted', async () => {
|
||||
mock.module('axios', () => ({
|
||||
default: {
|
||||
get: mock((_url: string, config: any) => {
|
||||
if (config?.signal?.aborted) {
|
||||
const err = new Error('canceled')
|
||||
;(err as any).__CANCEL__ = true
|
||||
return Promise.reject(err)
|
||||
}
|
||||
return Promise.resolve({ data: SAMPLE_HTML })
|
||||
}),
|
||||
isCancel: (e: any) => e?.__CANCEL__ === true,
|
||||
},
|
||||
}))
|
||||
mock.module('../../../utils/http', () => ({
|
||||
getWebFetchUserAgent: () => 'TestAgent/1.0',
|
||||
}))
|
||||
|
||||
const adapter = await createAdapter()
|
||||
const controller = new AbortController()
|
||||
controller.abort()
|
||||
|
||||
const { AbortError } = await import('../../../utils/errors')
|
||||
await expect(
|
||||
adapter.search('test', { signal: controller.signal }),
|
||||
).rejects.toThrow(AbortError)
|
||||
})
|
||||
|
||||
test('re-throws non-abort axios errors', async () => {
|
||||
const networkError = new Error('Network error')
|
||||
mock.module('axios', () => ({
|
||||
default: {
|
||||
get: mock(() => Promise.reject(networkError)),
|
||||
isCancel: () => false,
|
||||
},
|
||||
}))
|
||||
mock.module('../../../utils/http', () => ({
|
||||
getWebFetchUserAgent: () => 'TestAgent/1.0',
|
||||
}))
|
||||
|
||||
const adapter = await createAdapter()
|
||||
await expect(adapter.search('test', {})).rejects.toThrow('Network error')
|
||||
})
|
||||
|
||||
test('encodes query parameter in URL', async () => {
|
||||
const axiosGet = mock(() => Promise.resolve({ data: SAMPLE_HTML }))
|
||||
mock.module('axios', () => ({
|
||||
default: {
|
||||
get: axiosGet,
|
||||
isCancel: () => false,
|
||||
},
|
||||
}))
|
||||
mock.module('../../../utils/http', () => ({
|
||||
getWebFetchUserAgent: () => 'TestAgent/1.0',
|
||||
}))
|
||||
|
||||
const adapter = await createAdapter()
|
||||
await adapter.search('hello world & special=chars', {})
|
||||
|
||||
const calledUrl = axiosGet.mock.calls[0][0] as string
|
||||
expect(calledUrl).toContain('q=hello%20world%20%26%20special%3Dchars')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,173 @@
|
||||
/**
|
||||
* API-based search adapter — delegates to Anthropic's server-side
|
||||
* web_search_20250305 tool via a secondary API call.
|
||||
*/
|
||||
|
||||
import type {
|
||||
BetaContentBlock,
|
||||
BetaWebSearchTool20250305,
|
||||
} from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs'
|
||||
import { getFeatureValue_CACHED_MAY_BE_STALE } from '../../../services/analytics/growthbook.js'
|
||||
import { queryModelWithStreaming } from '../../../services/api/claude.js'
|
||||
import { createUserMessage } from '../../../utils/messages.js'
|
||||
import { getMainLoopModel, getSmallFastModel } from '../../../utils/model/model.js'
|
||||
import { jsonParse } from '../../../utils/slowOperations.js'
|
||||
import { asSystemPrompt } from '../../../utils/systemPromptType.js'
|
||||
import type { SearchResult, SearchOptions, WebSearchAdapter } from './types.js'
|
||||
|
||||
function makeToolSchema(input: { allowedDomains?: string[]; blockedDomains?: string[] }): BetaWebSearchTool20250305 {
|
||||
return {
|
||||
type: 'web_search_20250305',
|
||||
name: 'web_search',
|
||||
allowed_domains: input.allowedDomains,
|
||||
blocked_domains: input.blockedDomains,
|
||||
max_uses: 8,
|
||||
}
|
||||
}
|
||||
|
||||
export class ApiSearchAdapter implements WebSearchAdapter {
|
||||
async search(
|
||||
query: string,
|
||||
options: SearchOptions,
|
||||
): Promise<SearchResult[]> {
|
||||
const { signal, onProgress, allowedDomains, blockedDomains } = options
|
||||
|
||||
const userMessage = createUserMessage({
|
||||
content: 'Perform a web search for the query: ' + query,
|
||||
})
|
||||
const toolSchema = makeToolSchema({ allowedDomains, blockedDomains })
|
||||
|
||||
const useHaiku = getFeatureValue_CACHED_MAY_BE_STALE('tengu_plum_vx3', false)
|
||||
|
||||
const queryStream = queryModelWithStreaming({
|
||||
messages: [userMessage],
|
||||
systemPrompt: asSystemPrompt([
|
||||
'You are an assistant for performing a web search tool use',
|
||||
]),
|
||||
thinkingConfig: useHaiku
|
||||
? { type: 'disabled' as const }
|
||||
: { type: 'enabled' as const, budgetTokens: 10000 },
|
||||
tools: [],
|
||||
signal: signal ?? new AbortController().signal,
|
||||
options: {
|
||||
getToolPermissionContext: async () => ({
|
||||
mode: 'default' as const,
|
||||
additionalWorkingDirectories: new Map(),
|
||||
alwaysAllowRules: {},
|
||||
alwaysDenyRules: {},
|
||||
alwaysAskRules: {},
|
||||
isBypassPermissionsModeAvailable: false,
|
||||
}),
|
||||
model: useHaiku ? getSmallFastModel() : getMainLoopModel(),
|
||||
toolChoice: useHaiku ? { type: 'tool' as const, name: 'web_search' } : undefined,
|
||||
isNonInteractiveSession: false,
|
||||
hasAppendSystemPrompt: false,
|
||||
extraToolSchemas: [toolSchema],
|
||||
querySource: 'web_search_tool' as const,
|
||||
agents: [],
|
||||
mcpTools: [],
|
||||
agentId: undefined,
|
||||
effortValue: undefined,
|
||||
},
|
||||
})
|
||||
|
||||
const allContentBlocks: BetaContentBlock[] = []
|
||||
let currentToolUseId: string | null = null
|
||||
let currentToolUseJson = ''
|
||||
const toolUseQueries = new Map<string, string>()
|
||||
let progressCounter = 0
|
||||
|
||||
for await (const event of queryStream) {
|
||||
if (event.type === 'assistant') {
|
||||
const msg = event as { message: { content: BetaContentBlock[] } }
|
||||
allContentBlocks.push(...msg.message.content)
|
||||
continue
|
||||
}
|
||||
|
||||
if (event.type === 'stream_event') {
|
||||
const streamEvt = event as {
|
||||
event?: {
|
||||
type: string
|
||||
content_block?: { type: string; id?: string; tool_use_id?: string; content?: unknown; [key: string]: unknown }
|
||||
delta?: { type: string; partial_json?: string; [key: string]: unknown }
|
||||
[key: string]: unknown
|
||||
}
|
||||
}
|
||||
|
||||
if (streamEvt.event?.type === 'content_block_start') {
|
||||
const contentBlock = streamEvt.event.content_block
|
||||
if (contentBlock && contentBlock.type === 'server_tool_use') {
|
||||
currentToolUseId = contentBlock.id as string
|
||||
currentToolUseJson = ''
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if (currentToolUseId && streamEvt.event?.type === 'content_block_delta') {
|
||||
const delta = streamEvt.event.delta
|
||||
if (delta?.type === 'input_json_delta' && delta.partial_json) {
|
||||
currentToolUseJson += delta.partial_json
|
||||
try {
|
||||
const queryMatch = currentToolUseJson.match(
|
||||
/"query"\s*:\s*"((?:[^"\\]|\\.)*)"/,
|
||||
)
|
||||
if (queryMatch && queryMatch[1]) {
|
||||
const parsedQuery = jsonParse('"' + queryMatch[1] + '"')
|
||||
if (
|
||||
!toolUseQueries.has(currentToolUseId) ||
|
||||
toolUseQueries.get(currentToolUseId) !== parsedQuery
|
||||
) {
|
||||
toolUseQueries.set(currentToolUseId, parsedQuery)
|
||||
progressCounter++
|
||||
onProgress?.({
|
||||
type: 'query_update',
|
||||
query: parsedQuery,
|
||||
})
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Ignore parsing errors for partial JSON
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (streamEvt.event?.type === 'content_block_start') {
|
||||
const contentBlock = streamEvt.event.content_block
|
||||
if (contentBlock && contentBlock.type === 'web_search_tool_result') {
|
||||
const toolUseId = contentBlock.tool_use_id as string
|
||||
const actualQuery = toolUseQueries.get(toolUseId) || query
|
||||
const content = contentBlock.content
|
||||
progressCounter++
|
||||
onProgress?.({
|
||||
type: 'search_results_received',
|
||||
resultCount: Array.isArray(content) ? content.length : 0,
|
||||
query: actualQuery,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Extract SearchResult[] from content blocks
|
||||
return extractSearchResults(allContentBlocks)
|
||||
}
|
||||
}
|
||||
|
||||
function extractSearchResults(
|
||||
blocks: BetaContentBlock[],
|
||||
): SearchResult[] {
|
||||
const results: SearchResult[] = []
|
||||
|
||||
for (const block of blocks) {
|
||||
if (block.type === 'web_search_tool_result' && Array.isArray(block.content)) {
|
||||
for (const r of block.content as Array<{ title: string; url: string; page_age?: string; type?: string }>) {
|
||||
results.push({
|
||||
title: r.title,
|
||||
url: r.url,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
/**
|
||||
* Bing-based search adapter — fetches Bing search pages and extracts
|
||||
* search results using regex pattern matching on raw HTML.
|
||||
*/
|
||||
|
||||
import axios from 'axios'
|
||||
import he from 'he'
|
||||
import { AbortError } from '../../../utils/errors.js'
|
||||
import type { SearchResult, SearchOptions, WebSearchAdapter } from './types.js'
|
||||
|
||||
const FETCH_TIMEOUT_MS = 30_000
|
||||
|
||||
/**
|
||||
* Browser-like headers to avoid Bing's anti-bot JS-rendered response.
|
||||
* These mimic Microsoft Edge on macOS to get full HTML search results.
|
||||
*/
|
||||
const BROWSER_HEADERS = {
|
||||
'User-Agent':
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0',
|
||||
Accept:
|
||||
'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8',
|
||||
'Accept-Language': 'en-US,en;q=0.9',
|
||||
'Accept-Encoding': 'gzip, deflate, br',
|
||||
'Cache-Control': 'no-cache',
|
||||
Pragma: 'no-cache',
|
||||
'Sec-Ch-Ua': '"Microsoft Edge";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
|
||||
'Sec-Ch-Ua-Mobile': '?0',
|
||||
'Sec-Ch-Ua-Platform': '"macOS"',
|
||||
'Sec-Fetch-Dest': 'document',
|
||||
'Sec-Fetch-Mode': 'navigate',
|
||||
'Sec-Fetch-Site': 'none',
|
||||
'Sec-Fetch-User': '?1',
|
||||
'Upgrade-Insecure-Requests': '1',
|
||||
} as const
|
||||
|
||||
export class BingSearchAdapter implements WebSearchAdapter {
|
||||
async search(
|
||||
query: string,
|
||||
options: SearchOptions,
|
||||
): Promise<SearchResult[]> {
|
||||
const { signal, onProgress, allowedDomains, blockedDomains } = options
|
||||
|
||||
if (signal?.aborted) {
|
||||
throw new AbortError()
|
||||
}
|
||||
|
||||
onProgress?.({ type: 'query_update', query })
|
||||
|
||||
const url = `https://www.bing.com/search?q=${encodeURIComponent(query)}&setmkt=en-US`
|
||||
|
||||
const abortController = new AbortController()
|
||||
if (signal) {
|
||||
signal.addEventListener('abort', () => abortController.abort(), { once: true })
|
||||
}
|
||||
|
||||
let html: string
|
||||
try {
|
||||
const response = await axios.get(url, {
|
||||
signal: abortController.signal,
|
||||
timeout: FETCH_TIMEOUT_MS,
|
||||
responseType: 'text',
|
||||
headers: BROWSER_HEADERS,
|
||||
})
|
||||
html = response.data
|
||||
} catch (e) {
|
||||
if (axios.isCancel(e) || abortController.signal.aborted) {
|
||||
throw new AbortError()
|
||||
}
|
||||
throw e
|
||||
}
|
||||
|
||||
if (abortController.signal.aborted) {
|
||||
throw new AbortError()
|
||||
}
|
||||
|
||||
const rawResults = extractBingResults(html)
|
||||
|
||||
// Client-side domain filtering
|
||||
const results = rawResults.filter((r) => {
|
||||
if (!r.url) return false
|
||||
try {
|
||||
const hostname = new URL(r.url).hostname
|
||||
if (allowedDomains?.length && !allowedDomains.some(d => hostname === d || hostname.endsWith('.' + d))) {
|
||||
return false
|
||||
}
|
||||
if (blockedDomains?.length && blockedDomains.some(d => hostname === d || hostname.endsWith('.' + d))) {
|
||||
return false
|
||||
}
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
onProgress?.({
|
||||
type: 'search_results_received',
|
||||
resultCount: results.length,
|
||||
query,
|
||||
})
|
||||
|
||||
return results
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract organic search results from Bing HTML.
|
||||
* Bing results live in <li class="b_algo"> blocks within <ol id="b_results">.
|
||||
*/
|
||||
export function extractBingResults(html: string): SearchResult[] {
|
||||
const results: SearchResult[] = []
|
||||
|
||||
const algoBlockRegex = /<li\s+class="b_algo"[^>]*>([\s\S]*?)<\/li>/gi
|
||||
let blockMatch: RegExpExecArray | null
|
||||
|
||||
while ((blockMatch = algoBlockRegex.exec(html)) !== null) {
|
||||
const block = blockMatch[1]
|
||||
|
||||
// Extract the primary link from <h2><a href="...">...</a></h2>
|
||||
const h2LinkRegex = /<h2[^>]*>\s*<a[^>]+href="([^"]+)"[^>]*>([\s\S]*?)<\/a>/i
|
||||
const linkMatch = h2LinkRegex.exec(block)
|
||||
if (!linkMatch) continue
|
||||
|
||||
const rawUrl = decodeHtmlEntities(linkMatch[1])
|
||||
const titleHtml = linkMatch[2]
|
||||
|
||||
// Resolve Bing redirect URLs (bing.com/ck/a?...&u=a1aHR0cHM6Ly9...)
|
||||
// or skip Bing-internal / relative links
|
||||
const url = resolveBingUrl(rawUrl)
|
||||
if (!url) continue
|
||||
|
||||
const title = decodeHtmlEntities(
|
||||
titleHtml.replace(/<[^>]+>/g, '').trim(),
|
||||
)
|
||||
|
||||
// Extract snippet: try b_lineclamp → b_caption <p> → b_caption fallback
|
||||
const snippet = extractSnippet(block)
|
||||
|
||||
results.push({ title, url, snippet })
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
function extractSnippet(block: string): string | undefined {
|
||||
// 1. Try <p class="b_lineclamp...">
|
||||
const lineclampRegex = /<p[^>]*class="b_lineclamp[^"]*"[^>]*>([\s\S]*?)<\/p>/i
|
||||
let match = lineclampRegex.exec(block)
|
||||
if (match) {
|
||||
return decodeHtmlEntities(match[1].replace(/<[^>]+>/g, '').trim())
|
||||
}
|
||||
|
||||
// 2. Try <p> inside b_caption
|
||||
const captionPRegex = /<div[^>]*class="b_caption[^"]*"[^>]*>[\s\S]*?<p[^>]*>([\s\S]*?)<\/p>/i
|
||||
match = captionPRegex.exec(block)
|
||||
if (match) {
|
||||
return decodeHtmlEntities(match[1].replace(/<[^>]+>/g, '').trim())
|
||||
}
|
||||
|
||||
// 3. Fallback: any text inside b_caption <div>
|
||||
const fallbackRegex = /<div[^>]*class="b_caption[^"]*"[^>]*>([\s\S]*?)<\/div>/i
|
||||
const fallbackMatch = fallbackRegex.exec(block)
|
||||
if (fallbackMatch) {
|
||||
const text = fallbackMatch[1].replace(/<[^>]+>/g, '').trim()
|
||||
if (text) return decodeHtmlEntities(text)
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
export const decodeHtmlEntities = he.decode
|
||||
|
||||
/**
|
||||
* Resolve a Bing redirect URL to the actual target URL.
|
||||
* Bing uses URLs like: https://www.bing.com/ck/a?...&u=a1aHR0cHM6Ly9leGFtcGxlLmNvbQ...
|
||||
* The `u` query parameter is a base64-encoded URL prefixed with a1 (https) or a0 (http).
|
||||
* Returns `undefined` for Bing-internal or relative links that should be skipped.
|
||||
*/
|
||||
export function resolveBingUrl(rawUrl: string): string | undefined {
|
||||
// Skip relative / anchor links
|
||||
if (rawUrl.startsWith('/') || rawUrl.startsWith('#')) return undefined
|
||||
|
||||
// Try to extract the `u` parameter from Bing redirect URLs
|
||||
const uMatch = rawUrl.match(/[?&]u=([a-zA-Z0-9+/_=-]+)/)
|
||||
if (uMatch) {
|
||||
const encoded = uMatch[1]
|
||||
if (encoded.length >= 3) {
|
||||
const prefix = encoded.slice(0, 2)
|
||||
const b64 = encoded.slice(2)
|
||||
try {
|
||||
// Base64url decode (pad as needed)
|
||||
const padded = b64.replace(/-/g, '+').replace(/_/g, '/')
|
||||
const decoded = Buffer.from(padded, 'base64').toString('utf-8')
|
||||
if (decoded.startsWith('http')) return decoded
|
||||
} catch {
|
||||
// Fall through — not a valid base64 redirect
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Direct external URL (not a Bing-internal page)
|
||||
if (!rawUrl.includes('bing.com')) return rawUrl
|
||||
|
||||
return undefined
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Search adapter factory — selects the appropriate backend by checking
|
||||
* whether the API base URL points to Anthropic's official endpoint.
|
||||
*/
|
||||
|
||||
import { isFirstPartyAnthropicBaseUrl } from '../../../utils/model/providers.js'
|
||||
import { ApiSearchAdapter } from './apiAdapter.js'
|
||||
import { BingSearchAdapter } from './bingAdapter.js'
|
||||
import type { WebSearchAdapter } from './types.js'
|
||||
|
||||
export type { SearchResult, SearchOptions, SearchProgress, WebSearchAdapter } from './types.js'
|
||||
|
||||
let cachedAdapter: WebSearchAdapter | null = null
|
||||
|
||||
export function createAdapter(): WebSearchAdapter {
|
||||
// 直接用 bing 适配器,跳过 API 适配器的选择逻辑
|
||||
return new BingSearchAdapter()
|
||||
// // Adapter is stateless — safe to reuse across calls within a session
|
||||
// if (cachedAdapter) return cachedAdapter
|
||||
|
||||
// // Env override: WEB_SEARCH_ADAPTER=api|bing forces specific backend
|
||||
// const envAdapter = process.env.WEB_SEARCH_ADAPTER
|
||||
// if (envAdapter === 'api') {
|
||||
// cachedAdapter = new ApiSearchAdapter()
|
||||
// return cachedAdapter
|
||||
// }
|
||||
// if (envAdapter === 'bing') {
|
||||
// cachedAdapter = new BingSearchAdapter()
|
||||
// return cachedAdapter
|
||||
// }
|
||||
|
||||
// // Anthropic official URL → API server-side search
|
||||
// if (isFirstPartyAnthropicBaseUrl()) {
|
||||
// cachedAdapter = new ApiSearchAdapter()
|
||||
// return cachedAdapter
|
||||
// }
|
||||
|
||||
// // Third-party proxies / non-Anthropic endpoints → Bing fallback
|
||||
// cachedAdapter = new BingSearchAdapter()
|
||||
// return cachedAdapter
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
export interface SearchResult {
|
||||
title: string
|
||||
url: string
|
||||
snippet?: string
|
||||
}
|
||||
|
||||
export interface SearchOptions {
|
||||
allowedDomains?: string[]
|
||||
blockedDomains?: string[]
|
||||
signal?: AbortSignal
|
||||
onProgress?: (progress: SearchProgress) => void
|
||||
}
|
||||
|
||||
export interface SearchProgress {
|
||||
type: 'query_update' | 'search_results_received'
|
||||
query?: string
|
||||
resultCount?: number
|
||||
}
|
||||
|
||||
export interface WebSearchAdapter {
|
||||
search(query: string, options: SearchOptions): Promise<SearchResult[]>
|
||||
}
|
||||
@@ -1736,6 +1736,10 @@ export function getAutoUpdaterDisabledReason(): AutoUpdaterDisabledReason | null
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
return { type: 'development' }
|
||||
}
|
||||
// 本项目默认关闭自动更新;通过 ENABLE_AUTOUPDATER=1 显式开启
|
||||
if (!isEnvTruthy(process.env.ENABLE_AUTOUPDATER)) {
|
||||
return { type: 'config' }
|
||||
}
|
||||
if (isEnvTruthy(process.env.DISABLE_AUTOUPDATER)) {
|
||||
return { type: 'env', envVar: 'DISABLE_AUTOUPDATER' }
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import { logForDebugging } from './debug.js'
|
||||
import { getFsImplementation } from './fsOperations.js'
|
||||
import { attachErrorLogSink, dateToFilename } from './log.js'
|
||||
import { jsonStringify } from './slowOperations.js'
|
||||
import { captureException } from './sentry.js'
|
||||
|
||||
const DATE = dateToFilename(new Date())
|
||||
|
||||
@@ -171,6 +172,9 @@ function logErrorImpl(error: Error): void {
|
||||
appendToLog(getErrorsPath(), {
|
||||
error: `${context}${errorStr}`,
|
||||
})
|
||||
|
||||
// Also report to Sentry (no-op if not initialized)
|
||||
captureException(error)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,6 +42,7 @@ import { logForDiagnosticsNoPII } from './diagLogs.js'
|
||||
import { isEnvTruthy } from './envUtils.js'
|
||||
import { getCurrentSessionTitle, sessionIdExists } from './sessionStorage.js'
|
||||
import { sleep } from './sleep.js'
|
||||
import { closeSentry } from './sentry.js'
|
||||
import { profileReport } from './startupProfiler.js'
|
||||
|
||||
/**
|
||||
@@ -503,7 +504,7 @@ export async function gracefulShutdown(
|
||||
// Lost analytics on slow networks are acceptable; a hanging exit is not.
|
||||
try {
|
||||
await Promise.race([
|
||||
Promise.all([shutdown1PEventLogging(), shutdownDatadog()]),
|
||||
Promise.all([shutdown1PEventLogging(), shutdownDatadog(), closeSentry(2000)]),
|
||||
sleep(500),
|
||||
])
|
||||
} catch {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
isTeamPremiumSubscriber,
|
||||
} from '../auth.js'
|
||||
import { getModelStrings } from './modelStrings.js'
|
||||
import { getAntModels } from './antModels.js'
|
||||
import {
|
||||
COST_TIER_3_15,
|
||||
COST_HAIKU_35,
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
/**
|
||||
* Sentry integration module
|
||||
*
|
||||
* Initializes Sentry SDK when SENTRY_DSN environment variable is set.
|
||||
* When DSN is not configured, all exports are no-ops.
|
||||
*/
|
||||
|
||||
import * as Sentry from '@sentry/node'
|
||||
import { logForDebugging } from './debug.js'
|
||||
|
||||
let initialized = false
|
||||
|
||||
/**
|
||||
* Initialize Sentry SDK. Safe to call multiple times — subsequent calls are no-ops.
|
||||
* Only activates when SENTRY_DSN environment variable is set.
|
||||
*/
|
||||
export function initSentry(): void {
|
||||
if (initialized) {
|
||||
return
|
||||
}
|
||||
|
||||
const dsn = process.env.SENTRY_DSN
|
||||
if (!dsn) {
|
||||
logForDebugging('[sentry] SENTRY_DSN not set, skipping initialization')
|
||||
return
|
||||
}
|
||||
|
||||
Sentry.init({
|
||||
dsn,
|
||||
release: typeof MACRO !== 'undefined' ? MACRO.VERSION : undefined,
|
||||
environment:
|
||||
typeof BUILD_ENV !== 'undefined' ? BUILD_ENV : process.env.NODE_ENV || 'development',
|
||||
|
||||
// Limit breadcrumbs and attachments to control payload size
|
||||
maxBreadcrumbs: 20,
|
||||
|
||||
// Sample rate for error events (1.0 = capture all)
|
||||
sampleRate: 1.0,
|
||||
|
||||
// Filter sensitive information before sending
|
||||
beforeSend(event) {
|
||||
// Strip auth headers from request data
|
||||
const request = event.request
|
||||
if (request?.headers) {
|
||||
const sensitiveHeaders = [
|
||||
'authorization',
|
||||
'x-api-key',
|
||||
'cookie',
|
||||
'set-cookie',
|
||||
]
|
||||
for (const key of Object.keys(request.headers)) {
|
||||
if (sensitiveHeaders.includes(key.toLowerCase())) {
|
||||
delete request.headers[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return event
|
||||
},
|
||||
|
||||
// Ignore specific error patterns
|
||||
ignoreErrors: [
|
||||
// Network errors from unreachable hosts — not actionable
|
||||
'ECONNREFUSED',
|
||||
'ECONNRESET',
|
||||
'ENOTFOUND',
|
||||
'ETIMEDOUT',
|
||||
// User-initiated aborts
|
||||
'AbortError',
|
||||
'The user aborted a request',
|
||||
// Interactive cancellation signals
|
||||
'CancelError',
|
||||
],
|
||||
|
||||
beforeSendTransaction(event) {
|
||||
// Don't send performance transactions for now — errors only
|
||||
return null
|
||||
},
|
||||
})
|
||||
|
||||
initialized = true
|
||||
logForDebugging('[sentry] Initialized successfully')
|
||||
}
|
||||
|
||||
/**
|
||||
* Capture an exception and send it to Sentry.
|
||||
* No-op if Sentry has not been initialized.
|
||||
*/
|
||||
export function captureException(error: unknown, context?: Record<string, unknown>): void {
|
||||
if (!initialized) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
Sentry.withScope(scope => {
|
||||
if (context) {
|
||||
scope.setExtras(context)
|
||||
}
|
||||
Sentry.captureException(error)
|
||||
})
|
||||
} catch {
|
||||
// Sentry itself failed — don't let it crash the app
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a tag on the current scope for grouping/filtering in Sentry.
|
||||
* No-op if Sentry has not been initialized.
|
||||
*/
|
||||
export function setTag(key: string, value: string): void {
|
||||
if (!initialized) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
Sentry.setTag(key, value)
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set user context in Sentry for error attribution.
|
||||
* No-op if Sentry has not been initialized.
|
||||
*/
|
||||
export function setUser(user: { id?: string; email?: string; username?: string }): void {
|
||||
if (!initialized) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
Sentry.setUser(user)
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush pending Sentry events and close the client.
|
||||
* Call during graceful shutdown to ensure events are sent.
|
||||
*/
|
||||
export async function closeSentry(timeoutMs = 2000): Promise<void> {
|
||||
if (!initialized) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await Sentry.close(timeoutMs)
|
||||
logForDebugging('[sentry] Closed successfully')
|
||||
} catch {
|
||||
// Ignore — we're shutting down anyway
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Sentry is initialized. Useful for conditional UI rendering.
|
||||
*/
|
||||
export function isSentryInitialized(): boolean {
|
||||
return initialized
|
||||
}
|
||||
Reference in new issue
Block a user