greentic-runner
主要的生产运行时,负责托管和执行 flows、管理 sessions,并协调所有平台服务。
Greentic 采用分层架构,并对关注点进行清晰分离:
┌─────────────────────────────────────────────────────────┐│ Messaging Channels ││ (Slack, Teams, Telegram, WhatsApp, WebChat) │└─────────────────────────────────────────────────────────┘ │ ▼┌─────────────────────────────────────────────────────────┐│ Gateway (HTTP) ││ Public Endpoint Router │└─────────────────────────────────────────────────────────┘ │ ▼┌─────────────────────────────────────────────────────────┐│ greentic-runner ││ (Production Runtime Host) ││ ┌─────────────────────────────────────────────────┐ ││ │ Flow Executor │ ││ │ (Wasmtime Component Model) │ ││ └─────────────────────────────────────────────────┘ ││ ┌─────────────────────────────────────────────────┐ ││ │ Session Manager │ ││ │ (Memory / Redis) │ ││ └─────────────────────────────────────────────────┘ │└─────────────────────────────────────────────────────────┘ │ ▼┌─────────────────────────────────────────────────────────┐│ WASM Components ││ (Flows, Providers, MCP Tools, Custom Components) │└─────────────────────────────────────────────────────────┘greentic-runner
主要的生产运行时,负责托管和执行 flows、管理 sessions,并协调所有平台服务。
greentic-flow
用于 .ygtc 文件的 flow schema 定义、中间表示(IR)、加载器与校验器。
greentic-pack
Pack 构建 CLI,用于创建已签名的 .gtpack 归档,其中包含 flows、components 和 assets。
greentic-component
用于构建 WASM components 的组件编写 CLI 与运行时工具集。
| 层级 | 技术 | 用途 |
|---|---|---|
| WASM Runtime | Wasmtime v41 | Component model 执行 |
| Async Runtime | Tokio v1 | 异步 I/O、任务调度 |
| HTTP Server | Axum v0.8 | REST API、webhooks |
| Message Bus | Internal event bus | 事件分发、发布/订阅 |
| Session Store | Memory/Redis | Flow 状态持久化 |
| Secrets | AWS/Azure/GCP/Vault | 凭证管理 |
1. External Message (e.g., Slack) │2. Webhook Handler (Provider Ingress) │3. Message bus: greentic.messaging.ingress.{env}.{tenant}.{team}.{channel} │4. Flow Router (tenant/team resolution) │5. Flow Executor (WASM component execution) │6. Session State Update │7. Reply/Action Nodes │8. Message bus: greentic.messaging.egress.{env}.{tenant}.{team}.{channel} │9. Provider Egress → External Service1. Bundle Configuration (greentic.demo.yaml) │2. Pack Resolver (local/OCI registry) │3. Signature Verification (ed25519-dalek) │4. CBOR Metadata Parsing │5. WASM Component Instantiation │6. WIT Interface Binding │7. Runtime RegistrationGreentic 在每一层都实现了租户隔离:
Tenant └── Environment (prod, staging, dev) └── Team └── Channel (messaging provider instance) └── Session (user conversation state)TenantCtx 结构体会贯穿所有操作:
pub struct TenantCtx { pub tenant_id: String, pub env_id: String, pub team_id: Option<String>,}Greentic 使用 WebAssembly Interface Types (WIT) 规范来定义组件接口:
// greentic-interfaces/wit/greentic/component@0.6.0/package.witpackage greentic:component@0.6.0;
interface control { should-cancel: func() -> bool; yield-now: func();}
interface node { use greentic:types-core/core@0.6.0.{capability-id, component-id, flow-id, node-error, step-id, tenant-ctx};
record invocation-envelope { ctx: tenant-ctx, flow-id: flow-id, step-id: step-id, component-id: component-id, attempt: u32, payload-cbor: list<u8>, metadata-cbor: option<list<u8>>, }
record invocation-result { ok: bool, output-cbor: list<u8>, output-metadata-cbor: option<list<u8>>, }
variant schema-source { cbor-schema-id(string), inline-cbor(list<u8>), ref-pack-path(string), ref-uri(string), }
record io-schema { schema: schema-source, content-type: string, schema-version: option<string>, }
record example { title: string, input-cbor: list<u8>, output-cbor: list<u8>, }
record schema-ref { id: string, content-type: string, blake3-hash: string, version: string, bytes: option<list<u8>>, uri: option<string>, }
record setup-example { title: string, answers-cbor: list<u8>, }
record setup-template-scaffold { template-ref: string, output-layout: option<string>, }
variant setup-output { config-only, template-scaffold(setup-template-scaffold), }
record setup-contract { qa-spec: schema-source, answers-schema: schema-source, examples: list<setup-example>, outputs: list<setup-output>, }
record op { name: string, summary: option<string>, input: io-schema, output: io-schema, examples: list<example>, }
record component-descriptor { name: string, version: string, summary: option<string>, capabilities: list<capability-id>, ops: list<op>, schemas: list<schema-ref>, setup: option<setup-contract>, }
describe: func() -> component-descriptor; invoke: func(op: string, envelope: invocation-envelope) -> result<invocation-result, node-error>;}
world component { import control; export node;}greentic-types ─────────────────────────── (foundation) ↑greentic-telemetrygreentic-interfaces ← greentic-typesgreentic-config ← greentic-types ↑greentic-session ← greentic-typesgreentic-state ← greentic-types + greentic-interfacesgreentic-flow ← greentic-interfaces + greentic-types ↑greentic-pack ← greentic-flow + greentic-typesgreentic-component ← greentic-interfaces + greentic-typesgreentic-mcp ← greentic-interfaces + greentic-types ↑greentic-runner ← ALL of the aboveGreentic 使用 OpenTelemetry 实现分布式追踪与指标采集: