Skill站外收录 @skilllib/skill-2117939930272418120
ark-sdk-development
实现 ARK 栈内类型系统的端到端管理,从 Kubernetes CRD 生成 Python 类型,经由 API 模型转换为 OpenAPI 规范,最终生成前端 TypeScript 类型,支持全链路类型同步与调试,确保跨服务类型一致性。
开发运维 AI 技能
Skills.MD
# ARK SDK and Type Development
## Type Generation Pipeline
Types flow through the ARK stack:
```
CRD YAML (ark/config/crd/)
↓ make ark-sdk-build (automatic)
ark-sdk Python types + overlay utilities
↓
ark-api Pydantic models (manual updates if exposing new fields)
↓ make ark-api-build → generates openapi.json
ark-dashboard TypeScript types
↓ npm run generate:api → generates types.ts
```
## ark-sdk: Automatic Type Generation
CRD types are **automatically generated** from Kubernetes CRD YAML files.
```bash
make ark-sdk-build
```
This runs:
1. `crd_to_openapi.py` - converts CRDs to OpenAPI schema
2. `openapi-generator-cli` - generates Python types from schema
3. Copies overlay files on top of generated code
4. Builds wheel package
### Adding Custom SDK Functionality (Overlays)
The `lib/ark-sdk/gen_sdk/overlay/python/ark_sdk/` directory contains custom Python modules that are copied on top of generated code. This is how utilities like `client.py`, `k8s.py`, and `executor.py` are added.
To add custom SDK functionality:
1. Add Python files to `lib/ark-sdk/gen_sdk/overlay/python/ark_sdk/`
2. Run `make ark-sdk-build`
## ark-api: Manual Model Updates
The ark-api has **manually written** Pydantic models in `services/ark-api/ark-api/src/ark_api/models/`.
When to update ark-api models:
- When exposing new CRD fields via the HTTP API
- When adding new API response types
```bash
make ark-api-build
```
This generates `services/ark-api/openapi.json` from FastAPI routes and Pydantic models.
### Pydantic Model Naming (CRITICAL)
Pydantic model class names **MUST be globally unique** across all model files. When multiple files define classes with the same name (e.g., `ConfigMapKeyRef`, `Header`, `ValueFrom`), FastAPI generates non-deterministic OpenAPI schema names like `ark_api__models__agents__Header-Input`. These names depend on import order and cause CI failures when `types.ts` differs between environments.
**Solution**: Prefix class names with their domain context:
| File | Naming Pattern | Examples |
|------|---------------|----------|
| `agents.py` | `Agent*` | `AgentHeader`, `AgentValueFrom`, `AgentParameter` |
| `evaluators.py` | `Evaluator*` | `EvaluatorParameter`, `EvaluatorValueSource` |
| `mcp_servers.py` | `MCPServer*` | `MCPServerHeader`, `MCPServerValueSource` |
| `queries.py` | `Query*` | `QueryParameter`, `QueryLabelSelector` |
| `models.py` | `Model*` | `ModelValueSource` |
**Safety net**: `generate_openapi.py` fails if any schema name contains `__models__`, catching collisions at build time.
See: https://github.com/mckinsey/agents-at-scale-ark/issues/656
## ark-dashboard: TypeScript Type Generation
```bash
cd services/ark-dashboard/ark-dashboard
cp ../../ark-api/openapi.json ../out/
npm run generate:api
npm run build # verify types compile
```
## Debugging Type Errors
When you see:
```
Property 'SomeSchema' does not exist on type
```
1. **Regenerate types.ts** from latest openapi.json
2. **Find the correct schema name:**
```bash
grep "SomeSchema" services/ark-dashboard/ark-dashboard/lib/api/generated/types.ts
```
3. **Update service files** to use correct schema names
If you see schema names with `__models__` pattern (e.g., `ark_api__models__agents__Header-Input`):
- This indicates a Pydantic model naming collision
- Fix by renaming the Python class to be unique (see naming convention above)
- Do NOT work around by using the `__models__` name - fix the root cause
## Key Files
| File | Purpose |
|------|---------|
| `ark/config/crd/bases/*.yaml` | Source of truth - Kubernetes CRDs |
| `lib/ark-sdk/gen_sdk/overlay/` | Custom SDK utilities (copied on top of generated) |
| `services/ark-api/ark-api/src/ark_api/models/` | Manually written Pydantic models |
| `services/ark-api/ark-api/generate_openapi.py` | Generates openapi.json with collision safety net |
| `services/ark-api/openapi.json` | Generated OpenAPI spec from FastAPI |
| `services/ark-dashboard/out/openapi.json` | Copy used for dashboard type generation |
| `services/ark-dashboard/ark-dashboard/lib/api/generated/types.ts` | Generated TypeScript types |
评论 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
举报「ark-sdk-development」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次