Skip to content

Protocol Standardization: Runtime Validation + NoSQL + AI Actions#389

Merged
hotlong merged 5 commits intomainfrom
copilot/architectural-review-objectstack-protocol
Jan 30, 2026
Merged

Protocol Standardization: Runtime Validation + NoSQL + AI Actions#389
hotlong merged 5 commits intomainfrom
copilot/architectural-review-objectstack-protocol

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 30, 2026

Architecture review identified three critical protocol gaps: API contracts lack runtime validation, NoSQL databases unsupported, AI agents cannot manipulate UI.

Changes

API Protocol: Interface → Zod Schemas

Replaced api/protocol.ts TypeScript interfaces with runtime-validated Zod schemas in api/protocol.zod.ts.

// Before: Type-erased at runtime
export interface IObjectStackProtocol {
  getMetaItem(type: string, name: string): any;
}

// After: Runtime validated, JSON Schema exportable
export const GetMetaItemRequestSchema = z.object({
  type: z.string().describe('Metadata type'),
  name: z.string().regex(/^[a-z_][a-z0-9_]*$/).describe('Item name'),
});

Enables: Gateway validation, RPC verification, OpenAPI generation, SDK auto-generation.

NoSQL Driver Protocol

Implemented system/driver-nosql.zod.ts with unified interface for MongoDB, DynamoDB, Cassandra, Redis, Elasticsearch, Neo4j.

Key features:

  • Consistency levels (all/quorum/one/eventual) for distributed systems
  • Sharding configuration (hash/range/zone strategies)
  • Replication settings (read preferences, write concerns)
  • Aggregation pipelines (MongoDB-style $match/$group/$sort)
  • Index definitions (single/compound/text/geospatial/TTL)
const config: NoSQLDriverConfig = {
  type: 'nosql',
  databaseType: 'mongodb',
  consistency: 'quorum',
  replication: {
    enabled: true,
    replicas: 3,
    writeConcern: 'majority'
  },
  sharding: {
    enabled: true,
    shardKey: '_id',
    strategy: 'hash'
  }
};

AI Agent Action Protocol

Created ai/agent-action.zod.ts mapping natural language intents to structured UI operations.

52 action types across 6 categories:

  • Navigation: navigate_to_object_list, navigate_to_record_detail, open_tab
  • View: change_view_mode, apply_filter, export_data
  • Form: create_record, fill_field, submit_form
  • Data: select_record, bulk_update, bulk_delete
  • Workflow: trigger_flow, send_email, schedule_task
  • Component: open_modal, show_notification
// Multi-step sequence: "Create contact for John Doe"
const sequence: AgentActionSequence = {
  actions: [
    { type: 'navigate_to_object_form', params: { object: 'contact' } },
    { type: 'fill_field', params: { fieldValues: { first_name: 'John', ... } } },
    { type: 'submit_form', params: {} }
  ],
  mode: 'sequential',
  atomic: true  // All-or-nothing
};

Intent mapping for NLQ integration:

const mapping: IntentActionMapping = {
  intent: 'create_new_account',
  examples: ['Create account', 'Add customer', 'New account form'],
  actionTemplate: { type: 'navigate_to_object_form', params: { object: 'account' } },
  minConfidence: 0.8
};

Impact

  • Runtime Safety: All 73+ protocol definitions now Zod-validated
  • Multi-Database: Unified driver interface abstracts 8+ NoSQL engines
  • AI Automation: Agents can now execute 52 UI operations via structured actions
  • Standards Alignment: Matches Salesforce Meta-Model, Kubernetes CRD patterns

Backward compatible via legacy interface exports. 2,305 tests passing.

Original prompt

作为企业管理软件领域的顶级架构师,我已完成对 objectstack-ai/spec 仓库中现有协议的深度扫描与评估。以下是基于全球最佳实践及微内核架构理念的架构师评估报告。

🏗️ ObjectStack 协议架构评估报告 (Architectural Review Report)

评估对象: objectstack-ai/spec (核心协议定义)
评估日期: 2026-01-30
架构理念: 微内核 (Micro-kernel) + 插件化 (Plugin-based) + 元数据驱动 (Metadata-driven)


1. 总体评价 (Executive Summary)

当前状态: 🟢 架构成型,核心稳固
ObjectStack 采用了极其先进的 "Schema-First" (Zod优先) 设计理念。通过 Zod 定义协议,同时生成 TypeScript 类型、JSON Schema 和运行时验证器,这是构建强类型、高可靠企业级系统的最佳实践。

  • 分类合理性: ✅ 优秀。将协议划分为 Data (数据), UI (界面), System (系统), Auth (权限), AI (智能) 五大命名空间,边界清晰。
  • 微内核设计: ✅ 达标。stack.zod.ts 作为总线定义了系统的全貌,而具体能力通过 manifest 和插件机制扩展,符合微内核设计。

2. 协议详细评估与调整建议 (Detailed Evaluation & Adjustments)

通过扫描现有代码 (packages/spec/src/**/*.ts),我对具体模块提出以下架构级建议:

2.1 API 协议层 (Critical Adjustment)
  • 发现: packages/spec/src/api/protocol.ts 目前定义为 TypeScript interface (IObjectStackProtocol)。
  • 问题: 纯 Interface 在运行时会被擦除,无法用于微服务间的 RPC 调用验证或前端的动态 API 发现。
  • 调整建议: 必须将其重构为 Zod Schema
    • 应定义 ProtocolRequestSchemaProtocolResponseSchema
    • 这允许我们在网关层自动校验进出微内核的所有数据包。
2.2 UI 协议层 (Complexity & Conflict)
  • 发现: page.zod.ts (页面布局), view.zod.ts (数据视图), block.zod.ts (组件属性) 三者并存。
  • 潜在冲突: view.zod.ts 中定义了 ViewDataSchema (数据源),而 block.zod.ts 中的 RecordRelatedListProps 也隐含了数据获取逻辑。
  • 调整建议: 解耦数据与表现
    • 建议将 ViewDataSchema 剥离为独立的 DataSourceProvider 协议。
    • UI 组件(Block)只应引用 ProviderID,而不应直接定义 HTTP 请求参数。这样可以统一由微内核的数据加载器(DataLoader)处理缓存和权限。
2.3 AI 协议层 (Enhancement)
  • 发现: nlq.zod.ts (自然语言查询) 设计精良,涵盖了 Intent 和 Entity 识别。
  • 补充建议: 缺少 "Agent Action Protocol" (智能体动作协议)
    • 目前的 NLQ 解析后变成了 ObjectQL,这很好。但 AI Agent 还需要能够操作 UI(如“打开新建窗口”)。
    • 建议新增 packages/spec/src/ai/agent-action.zod.ts,将自然语言意图映射为 UI.Action
2.4 数据协议层 (Foundation)
  • 发现: hook.zod.ts 定义了完善的生命周期 (beforeInsert, afterUpdate),非常符合企业级开发需求。
  • 调整建议: 增加 "Validation Hook" 的显式分类。目前逻辑都在 handler 里,建议将"数据校验"作为独立于"业务逻辑"的配置项,以便前端能预先读取规则进行即时校验。

3. 冲突与重复检测 (Conflict & Duplication Analysis)

协议/模块 检测到的问题 严重性 建议方案
ui/view.zod.ts vs ui/block.zod.ts 职责重叠: 列表组件(RecordRelatedList)与视图定义(ListView)在列定义上有重复。 统一使用 ListColumnSchema 作为标准列定义,Block 引用 View ID 而非重写列配置。
api/protocol.ts 风格不统一: 使用 Interface 而非 Zod。 重构为 Zod Schema 以保持"运行时类型安全"。
system/datasource.zod 定义模糊: 似乎与 hub/space.zod.ts 中的资源定义有概念重叠。 明确 Datasource 是逻辑连接,Space 是物理资源容器。

4. 下一步改进计划 (Next Steps & Roadmap)

基于 IMPLEMENTATION_CHECKLIST.md 的缺失项及上述评估,制定以下行动计划:

阶段一:内核标准化 (The Core Standardization) [T+1 Week]

  1. 重构 API 协议: 将 IObjectStackProtocol 转换为 Zod Schema,确保 RPC 通信标准化。
  2. 统一 UI 数据源: 提取通用 DataProviderSchema,消除 Page 和 View 之间的数据定义冲突。

阶段二:关键缺失补全 (Critical Gaps) [T+2 Weeks]
3. Driver 协议族: 编写 driver-sql.zod.tsdriver-nosql.zod.ts。这是微内核连接外部世���的桥梁,优先级最高。
* 规范要求: 必须定义 ConnectionConfig, QueryCapabilities (该驱动支持哪些 ObjectQL 特性)。
4. Security 协议: 定义 security/encryption.zod.ts (字段级加密配置) 和 security/audit.zod.ts (审计日志格式)。

阶段三:AI 增强 (AI Empowerment) [T+1 Month]
5. Agent Protocol: 完善 AI 与 UI 交互的协议,使 AI 不仅能查数,还能操作界面。


5. 架构师结语

ObjectStack 目前的协议设计已经达到了全球领先的企业级软件标准(对标 Salesforce Meta-Model 和 K8s CRD)。它成功地将"代码"抽象为"数据"(Schema),这是构建低代码/无代码平台以及 AI 生成应用的核心基础。

只要补齐 Driver 抽象层API 运行时校验,这套协议将具备支撑万亿级企业应用生态的能力。

是否需要我立即开始编写 driver-sql.zod.ts 或重构 api/protocol.ts


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel
Copy link
Copy Markdown

vercel bot commented Jan 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Ready Ready Preview, Comment Jan 30, 2026 1:47pm

Request Review

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
…hemas

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Add architectural review for ObjectStack protocols Protocol Standardization: Runtime Validation + NoSQL + AI Actions Jan 30, 2026
Copilot AI requested a review from hotlong January 30, 2026 13:47
@hotlong hotlong marked this pull request as ready for review January 30, 2026 13:50
Copilot AI review requested due to automatic review settings January 30, 2026 13:50
@hotlong hotlong merged commit 2e24959 into main Jan 30, 2026
5 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request successfully implements three critical protocol improvements for ObjectStack:

Changes:

  • API Protocol: Converted TypeScript interfaces to runtime-validated Zod schemas in api/protocol.zod.ts
  • NoSQL Driver Protocol: Implemented comprehensive multi-database support in system/driver-nosql.zod.ts
  • AI Agent Action Protocol: Created UI automation capabilities in ai/agent-action.zod.ts

Reviewed changes

Copilot reviewed 85 out of 85 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/spec/src/api/protocol.zod.ts NEW - Runtime-validated API protocol schemas (39 request/response pairs)
packages/spec/src/system/driver-nosql.zod.ts NEW - NoSQL database driver protocol supporting 8+ databases
packages/spec/src/system/driver-nosql.test.ts NEW - Comprehensive test coverage (25 tests)
packages/spec/src/ai/agent-action.zod.ts NEW - AI agent UI automation protocol (52 action types across 6 categories)
packages/spec/src/ai/agent-action.test.ts NEW - Complete test coverage (24 tests)
packages/spec/src/*/index.ts UPDATED - Export new schemas
packages/spec/json-schema/**/*.json GENERATED - 76 JSON schema files for documentation
content/docs/references/**/*.mdx GENERATED - Auto-generated documentation
IMPLEMENTATION_SUMMARY.md NEW - Comprehensive implementation documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants