launchdarkly
它能做什么
这项技能描述 Agent-Native 应用中的服务器端和浏览器端代码如何从 LaunchDarkly 读取开关。如果 LaunchDarkly 未设置或无法访问,每次读取都会回退到默认值。适合已在使用 LaunchDarkly 管理开关的开发者。
适用场景
- ✓当某个操作、插件或组件需要读取保存在 LaunchDarkly 中的开关的时候。
- ✓当你在为应用设置 LaunchDarkly 密钥的时候。
- ✓当你需要在 LaunchDarkly 与内置开关系统之间做选择的时候。
技能链接
https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/launchdarkly/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请在这个应用中读取我们为新导出功能设置的 LaunchDarkly 开关;如果无法访问,使用安全的默认值。”
每周 5 个新技能,1 分钟读完。
工作原理
应用在服务器端或浏览器中通过 LaunchDarkly 辅助函数读取开关,只要 LaunchDarkly 无法给出答案,就使用默认值。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
LaunchDarkly
Rule
LaunchDarkly flags are read through @agent-native/core/launchdarkly on the
server and @agent-native/core/client/launchdarkly in the browser. Every read
fails closed to a caller-supplied default — LaunchDarkly being unconfigured,
unreachable, or slow is never an availability dependency for the caller.
LaunchDarkly vs. the built-in feature-flags skill
This repo already has its own rollout system (defineFeatureFlag,
isFeatureFlagEnabled, useFeatureFlag — see the feature-flags skill),
managed from the Analytics fleet control plane with no external dependency.
Use that system for a flag whose definition and targeting rules should live in
this codebase and be manageable from Analytics.
Use LaunchDarkly instead when the flag's definition and targeting genuinely need to live in the LaunchDarkly dashboard — for example, a flag shared with non-Agent-Native systems, or targeting rules (percentage experiments, multi-variate values, scheduled changes) beyond what the built-in system offers. Don't wire the same rollout through both systems.
Setup
Set LAUNCHDARKLY_SDK_KEY to a server-side SDK key from the agent-native
LaunchDarkly project's active environment. Unset, every read falls back to its
default value and LaunchDarkly is never contacted — there is no broken state
to debug, only an inactive one.
No client-side ID or LaunchDarkly JS SDK is used. Browser code reads evaluated
flags through the get-launchdarkly-flags action instead, so the SDK key never
reaches a bundle and no LaunchDarkly network connection opens from the browser.
Server usage
import { isLaunchDarklyFlagEnabled } from "@agent-native/core/launchdarkly";
run: async (args, ctx) => {
const enabled = await isLaunchDarklyFlagEnabled("new-checkout-flow", {
userEmail: ctx.userEmail,
orgId: ctx.orgId,
});
if (!enabled) throw new Error("New checkout flow is not enabled.");
// guarded operation
};
For a non-boolean flag (string/number/JSON variation), use
getLaunchDarklyVariation(key, actor, defaultValue) — the return type matches
defaultValue's type. getAllLaunchDarklyFlags(actor) returns every flag
LaunchDarkly currently evaluates for that context; prefer the single-flag
functions when only a few keys matter.
actor is { userEmail?, orgId?, anonymousId? }. A signed-in caller evaluates
by userEmail. A caller with neither userEmail nor anonymousId falls back
to one shared "anonymous" context — every such caller gets the same
variation from a percentage rollout, since LaunchDarkly buckets by context key.
Pass a stable anonymousId (a device or session id) when an unauthenticated
caller needs its own bucket.
Client usage
import { useLaunchDarklyFlag } from "@agent-native/core/client/launchdarkly";
function CheckoutButton() {
const enabled = useLaunchDarklyFlag("new-checkout-flow");
if (!enabled) return null;
return <Button>Checkout</Button>;
}
useLaunchDarklyFlag(key, defaultValue = false) calls the mounted
get-launchdarkly-flags action for the current session and requires a real
session — like useFeatureFlag, it never fires for a signed-out visitor and
resolves to defaultValue instead. useLaunchDarklyFlags(keys, defaultValue)
evaluates several keys in one request.
get-launchdarkly-flags action
Auto-mounted for every app (like get-feature-flags) — no plugin or
registration needed. Gateable per app via
frameworkTools.launchDarkly (see framework-tools.ts) if an app wants to
remove it from the agent's tool surface; the HTTP route stays mounted either
way so useLaunchDarklyFlag keeps working.
run("get-launchdarkly-flags", { keys: ["new-checkout-flow"], defaultValue: false })
// => { flags: { "new-checkout-flow": true } }
Never do this
- Never import
@agent-native/core/launchdarkly(the server module) from client/browser code — it pulls in the LaunchDarkly Node SDK. Use@agent-native/core/client/launchdarklyinstead. - Never treat a LaunchDarkly read as required for an operation to complete —
every function here already fails closed; don't wrap calls in retries or
turn a
false/default result into a thrown error unless the flag itself is an authorization gate the caller must respect. - Never put
LAUNCHDARKLY_SDK_KEYinagent-native.config.tsor any client-visible config — it is server-only.
Related skills
- feature-flags — the framework's own rollout system; read this first to
常见问题
如果没有配置 LaunchDarkly 会怎样?
每次读取都返回默认值,而且从不联系 LaunchDarkly。
我应该使用它还是内置开关?
技能说明,对于在本代码库中管理的开关使用内置系统;当规则必须保存在 LaunchDarkly 的控制台中时,才使用 LaunchDarkly。
需要哪个密钥?
技能说明需要从项目当前环境中设置一个服务器端 SDK 密钥。
详情
作者的原始描述
Server-side and client-side LaunchDarkly flag evaluation (project key `agent-native`). Use when reading a LaunchDarkly flag from an action, plugin, or component, or when wiring `LAUNCHDARKLY_SDK_KEY`. Distinct from the framework's own `feature-flags` system.
repo: BuilderIO/agent-native
热度
- GitHub 星标
- 7.6k
- 排名
- #13166
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …