Skill站外收录 @skilllib/skill-2117939930272411152
lindy-multi-env-setup
实现跨开发、预发和生产环境的 Lindy AI 配置管理,支持基于环境变量加载 API 密钥与代理实例,通过密钥前缀校验和运行时防护机制确保环境隔离安全,适用于多环境部署的自动化配置场景。
效率工具 AI 技能
Skills.MD
# Lindy Multi Env Setup
## Overview
Configure Lindy AI across development, staging, and production environments.
## Prerequisites
- Separate Lindy API keys per environment
- Secret management solution (Vault, AWS Secrets Manager, etc.)
- CI/CD pipeline with environment variables
- Environment detection in application
## Instructions
### Step 1: Create Environment Configuration
```typescript
// config/lindy.ts
interface LindyConfig {
apiKey: string;
environment: 'development' | 'staging' | 'production';
baseUrl?: string;
timeout: number;
retries: number;
}
const configs: Record<string, LindyConfig> = {
development: {
apiKey: process.env.LINDY_DEV_API_KEY!,
environment: 'development',
timeout: 60000,
retries: 1,
},
staging: {
apiKey: process.env.LINDY_STAGING_API_KEY!,
environment: 'staging',
timeout: 45000,
retries: 2,
},
production: {
apiKey: process.env.LINDY_PROD_API_KEY!,
environment: 'production',
timeout: 30000,
retries: 3,
},
};
export function getLindyConfig(): LindyConfig {
const env = process.env.NODE_ENV || 'development';
return configs[env] || configs.development;
}
```
### Step 2: Implement Environment Detection
```typescript
// lib/lindy-client.ts
import { Lindy } from '@lindy-ai/sdk';
import { getLindyConfig } from '../config/lindy';
let client: Lindy | null = null;
export function getLindyClient(): Lindy {
if (!client) {
const config = getLindyConfig();
// Validate environment
if (config.environment === 'production') {
if (!config.apiKey.startsWith('lnd_prod_')) {
throw new Error('Production requires production API key');
}
}
client = new Lindy({
apiKey: config.apiKey,
timeout: config.timeout,
retries: config.retries,
});
}
return client;
}
```
### Step 3: Configure Secrets by Environment
```yaml
# AWS Secrets Manager structure
secrets/
├── lindy/development
│ └── api_key: lnd_dev_xxx
├── lindy/staging
│ └── api_key: lnd_stg_xxx
└── lindy/production
└── api_key: lnd_prod_xxx
```
```typescript
// secrets/lindy.ts
import { SecretsManager } from '@aws-sdk/client-secrets-manager';
export async function getLindyApiKey(env: string): Promise<string> {
const client = new SecretsManager({ region: 'us-east-1' });
const response = await client.getSecretValue({
SecretId: `lindy/${env}`,
});
const secret = JSON.parse(response.SecretString!);
return secret.api_key;
}
```
### Step 4: Environment-Specific Agents
```typescript
// agents/config.ts
interface AgentMapping {
development: string;
staging: string;
production: string;
}
const agentMappings: Record<string, AgentMapping> = {
support: {
development: 'agt_dev_support',
staging: 'agt_stg_support',
production: 'agt_prod_support',
},
sales: {
development: 'agt_dev_sales',
staging: 'agt_stg_sales',
production: 'agt_prod_sales',
},
};
export function getAgentId(agentName: string): string {
const env = process.env.NODE_ENV || 'development';
const mapping = agentMappings[agentName];
if (!mapping) {
throw new Error(`Unknown agent: ${agentName}`);
}
return mapping[env as keyof AgentMapping];
}
```
### Step 5: Add Environment Guards
```typescript
// guards/production.ts
export function requireProduction(): void {
if (process.env.NODE_ENV !== 'production') {
throw new Error('This operation requires production environment');
}
}
export function preventProduction(): void {
if (process.env.NODE_ENV === 'production') {
throw new Error('This operation is not allowed in production');
}
}
// Usage
async function dangerousOperation() {
preventProduction();
// ... destructive test operation
}
async function productionOnlyOperation() {
requireProduction();
// ... production-only logic
}
```
## Output
- Multi-environment configuration
- Environment detection logic
- Secure secret management
- Environment-specific agents
- Production safeguards
## Error Handling
| Issue | Cause | Solution |
|-------|-------|----------|
| Wrong key for env | Config error | Validate key prefix |
| Secret not found | Not provisioned | Create in secrets manager |
| Agent not found | Wrong environment | Check agent mapping |
## Examples
### Complete Environment Setup
```typescript
// index.ts
import { getLindyClient } from './lib/lindy-client';
import { getAgentId } from './agents/config';
async function main() {
const lindy = getLindyClient();
const agentId = getAgentId('support');
console.log(`Environment: ${process.env.NODE_ENV}`);
console.log(`Agent: ${agentId}`);
const result = await lindy.agents.run(agentId, {
input: 'Test message',
});
console.log('Response:', result.output);
}
main().catch(console.error);
```
## Resources
- [Lindy Environments Guide](https://docs.lindy.ai/environments)
- [12-Factor App Config](https://12factor.net/config)
- [AWS Secrets Manager](https://aws.amazon.com/secrets-manager/)
## Next Steps
Proceed to `lindy-observability` for monitoring setup.
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「lindy-multi-env-setup」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次