Skip to content

feat: 宿主自定义能力 host.call、Button children、RadioButton;可作为 included build 被宿主 App 吃 - #9

Merged
HarlonWang merged 2 commits into
mainfrom
feat/host-capabilities
Sep 17, 2026
Merged

HarlonWang merged 2 commits into
mainfrom
feat/host-capabilities

Conversation

@HarlonWang

@HarlonWang HarlonWang commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

背景

TrendingAI 订阅页实战接入(docs/roadmap.md)触发的第三批框架补齐。订阅页需要 JS 调宿主自己的动作(下单、登录、埋点)、按钮内放加载指示、单选档位,并让 TrendingAI 经 local.properties 的 tinyui.dir 以 composite build 吃本仓源码。

改动

  • 宿主自定义能力(docs/native-api.md §7):J3 host.call<T>(name, args);Kotlin HostServices(capabilities = mapOf(name to HostCapability { argsJson -> … })),suspend、返回 JSON 文本,HostException 走 E3 码。与框架十个名字重合在构造时报错;挂载清单的 capabilities 列出框架名 + 宿主名。http.request 与能力共用同一个 settle 收口
  • Button children:text 改可选,有 children 时当标签渲染
  • RadioButton:selected(必填)/ enabled / onClick,选中态由 JS 持有
  • 可被宿主 include:gradle/composite-substitutions(wang.harlon:tinyui = :compose);gradle.parent != null 时不 include sample;compose 的 mustRunAfter 对不存在的 sample 项目做了防护

验证

  • pnpm build && pnpm test(core 41 / native 4 / cli 22)、pnpm schema:check、pnpm typecheck
  • :compose:testAndroidHostTest(21)、:compose:apiCheck(apiDump 已更新)、:sample:androidApp:assembleDebug
  • 在 TrendingAI 里 dependencyInsight 确认 wang.harlon:tinyui → project ':tinyui:compose',嵌套的 quickjs-kmp → project ':quickjs-kmp:library' 同样生效,:shared:compileAndroidMain 通过(TrendingAI 侧需把 AGP 升到 9.4.0 与两库对齐,composite 要求一致)

🤖 Generated with Claude Code

Sourcery 总结

启用宿主集成功能和订阅页面 UI 原语,同时使 TinyUI 可作为 Gradle 组合构建使用。

新功能:

  • 添加 host.call API,用于从页面调用宿主定义的异步功能。
  • 为 Button 添加子内容支持,并引入由 JS 控制的 RadioButton 组件。

增强功能:

  • 在挂载清单中公开宿主功能,并验证宿主定义的名称不会与框架功能冲突。
  • 统一自定义功能和 HTTP 请求的异步宿主调用错误处理及响应结算逻辑。

构建:

  • 支持将 TinyUI Compose 作为包含的 Gradle 构建使用,同时在宿主组合构建中排除示例应用。
  • 在示例项目不可用时,保护 Compose 任务排序逻辑。

文档:

  • 记录宿主定义的功能、Button 子内容和 RadioButton 行为。

测试:

  • 增加对自定义宿主功能解析、拒绝、不支持的调用以及原生 API 暴露的测试覆盖。
Original summary in English

Sourcery 总结

支持宿主应用集成和订阅页面 UI 原语,同时允许 TinyUI Compose 从宿主应用的 Gradle 组合构建中使用。

新功能:

  • 添加 host.call API,用于从页面调用由宿主异步定义的功能。
  • 为 Button 添加子内容支持,并引入由 JS 控制的 RadioButton 组件。

增强:

  • 在挂载清单中公开框架和宿主功能,拒绝名称冲突,并统一异步宿主调用的错误处理。
  • 为带前缀的宿主组件生成分组的 TypeScript 访问器和 JSX 类型定义。

构建:

  • 支持将 TinyUI Compose 作为包含的 Gradle 构建使用,同时在宿主组合构建中省略示例项目,并在示例项目缺失时保护任务顺序。

文档:

  • 记录由宿主定义的功能、Button 子内容渲染以及 RadioButton 的状态行为。

测试:

  • 添加对宿主功能解析、拒绝、不支持的调用以及生成的宿主组件类型定义的覆盖。
Original summary in English

Summary by Sourcery

Enable host application integration and subscription-page UI primitives while allowing TinyUI Compose to be consumed from a host application's Gradle composite build.

New Features:

  • Add the host.call API for invoking asynchronous host-defined capabilities from pages.
  • Add child-content support for Button and introduce the JS-controlled RadioButton component.

Enhancements:

  • Expose framework and host capabilities in the mount manifest, reject name collisions, and unify asynchronous host-call error handling.
  • Generate grouped TypeScript accessors and JSX typings for prefixed host components.

Build:

  • Support consuming TinyUI Compose as an included Gradle build while omitting sample projects from host composites and guarding task ordering when samples are absent.

Documentation:

  • Document host-defined capabilities, Button child rendering, and RadioButton state behavior.

Tests:

  • Add coverage for host capability resolution, rejection, unsupported calls, and generated host-component typings.

…d 被宿主 App 吃

TrendingAI 订阅页触发的第三批框架补齐:
- J3 `host.call(name, args)`:宿主经 `HostServices.capabilities` 按名注册,与框架名重合在构造时报错,挂载清单一并列出
- `Button` 的 `text` 改可选、支持 children(按钮内放加载指示);新内置 `RadioButton`,选中态由 JS 持有
- `gradle/composite-substitutions` 声明坐标映射;作为被包含构建时不再 include sample,
  嵌套的 quickjs-kmp 替换已在 TrendingAI 里验证生效

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @HarlonWang, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 2 days and 15 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@coderabbitai

coderabbitai Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 70f81f57-663d-415b-83f3-d94c9b1b8e3c


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Sep 17, 2026

Copy link
Copy Markdown

审查者指南

本 PR 在 J3 协议上增加可由宿主注册的异步 host.call 能力,并统一错误收口与能力清单;同时扩展 Button/新增 RadioButton,最后通过 composite substitution 和条件化 sample 配置支持宿主 App 直接引用本地 Compose 构建。

host.call 能力调度时序图

sequenceDiagram
    participant Page as Page JS
    participant Host as PageHost
    participant Capability as HostCapability
    participant PageAPI as Page JS Promise

    Page->>Host: __host_call(name, cbId, argsJson)
    Host->>Capability: call(argsJson)
    Capability-->>Host: JSON result or HostException
    alt capability succeeds
        Host->>Page: resolve(cbId, result)
        Page->>PageAPI: fulfill Promise
    else HostException
        Host->>Page: reject(cbId, code, message)
        Page->>PageAPI: reject with HostError
    else capability unavailable
        Host->>Page: reject(cbId, E_UNSUPPORTED, message)
        Page->>PageAPI: reject with HostError
    end
Loading

文件级变更

变更 详情 文件
扩展宿主与 JS 之间的能力调用协议,支持宿主注册自定义异步能力并统一处理结果与错误。
  • 新增 host.call<T> API 及 HostCapability suspend 回调。
  • 在 HostServices 构造时拒绝覆盖框架保留能力名,并将宿主能力加入挂载清单。
  • 将 http.request 与自定义能力统一收口到 settle,映射 HostException、通用异常和未注册能力的错误码。
  • 补充 native 与 Compose 端到端能力调用测试。
packages/native/src/host.ts
packages/native/src/index.ts
packages/native/test/native.test.ts
compose/src/commonMain/kotlin/wang/harlon/tinyui/HostServices.kt
compose/src/commonMain/kotlin/wang/harlon/tinyui/PageHost.kt
compose/src/commonTest/kotlin/wang/harlon/tinyui/PageHostTest.kt
docs/native-api.md
扩展内置组件模型,允许按钮以 children 作为内容并新增由 JS 控制选中态的 RadioButton。
  • 将 Button 的 text 改为可选,并在存在 children 时渲染 children。
  • 新增 RadioButton 的 selected、enabled 属性和 onClick 事件。
  • 更新组件 schema、生成代码、组件注册实现及组件文档。
schema/components/button.ts
schema/components/radio-button.ts
schema/index.ts
packages/core/src/generated/components.ts
compose/src/commonMain/kotlin/wang/harlon/tinyui/components/Builtins.kt
compose/src/commonMain/kotlin/wang/harlon/tinyui/components/generated/BuiltinSchemas.kt
docs/components.md
compose/api/compose.klib.api
支持 tinyui 作为宿主 App 的 Gradle included/composite build 使用,并避免宿主场景加载 sample 工程。
  • 新增 Maven 坐标到本地 :compose 项目的 composite substitution。
  • 通过 gradle.parent 条件仅在独立构建时包含 sample 工程。
  • 为不存在的 sample 项目保护 mustRunAfter 配置。
gradle/composite-substitutions
settings.gradle.kts
compose/build.gradle.kts
同步项目文档与路线图,记录本批框架能力和集成方式。
  • 补充宿主自定义能力的 API、错误语义和能力清单约定。
  • 更新组件清单及 Button/RadioButton 的状态管理说明。
  • 标记 TrendingAI 订阅页触发的相关工作已完成。
docs/native-api.md
docs/components.md
docs/roadmap.md

提示与命令

与 Sourcery 交互

  • 触发新的审查: 在 pull request 中评论 @sourcery-ai review。
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 根据审查评论生成 GitHub issue: 回复某条审查评论,请 Sourcery 根据该评论创建 issue。你也可以在审查评论中回复 @sourcery-ai issue,以根据该评论创建 issue。
  • 生成 pull request 标题: 在 pull request 标题的任意位置写入 @sourcery-ai,即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title,以随时重新生成标题。
  • 生成 pull request 摘要: 在 pull request 正文中任意位置写入 @sourcery-ai summary,即可在指定位置随时生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary,以随时重新生成摘要。
  • 生成审查者指南: 在 pull request 中评论 @sourcery-ai guide,即可随时重新生成审查者指南。
  • 解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,此功能会非常有用。
  • 忽略所有 Sourcery 审查: 在 pull request 中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 审查。如果你想从新的审查开始,这项功能尤其有用——别忘了评论 @sourcery-ai review 来触发新的审查!

自定义你的使用体验

访问你的控制面板以:

  • 启用或禁用审查功能,例如 Sourcery 生成的 pull request 摘要、审查者指南等。
  • 更改审查语言。
  • 添加、移除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English

Reviewer's Guide

本 PR 在 J3 协议上增加可由宿主注册的异步 host.call 能力,并统一错误收口与能力清单;同时扩展 Button/新增 RadioButton,最后通过 composite substitution 和条件化 sample 配置支持宿主 App 直接引用本地 Compose 构建。

Sequence diagram for host.call capability dispatch

sequenceDiagram
    participant Page as Page JS
    participant Host as PageHost
    participant Capability as HostCapability
    participant PageAPI as Page JS Promise

    Page->>Host: __host_call(name, cbId, argsJson)
    Host->>Capability: call(argsJson)
    Capability-->>Host: JSON result or HostException
    alt capability succeeds
        Host->>Page: resolve(cbId, result)
        Page->>PageAPI: fulfill Promise
    else HostException
        Host->>Page: reject(cbId, code, message)
        Page->>PageAPI: reject with HostError
    else capability unavailable
        Host->>Page: reject(cbId, E_UNSUPPORTED, message)
        Page->>PageAPI: reject with HostError
    end
Loading

File-Level Changes

Change Details Files
扩展宿主与 JS 之间的能力调用协议,支持宿主注册自定义异步能力并统一处理结果与错误。
  • 新增 host.call<T> API 及 HostCapability suspend 回调。
  • 在 HostServices 构造时拒绝覆盖框架保留能力名,并将宿主能力加入挂载清单。
  • 将 http.request 与自定义能力统一收口到 settle,映射 HostException、通用异常和未注册能力的错误码。
  • 补充 native 与 Compose 端到端能力调用测试。
packages/native/src/host.ts
packages/native/src/index.ts
packages/native/test/native.test.ts
compose/src/commonMain/kotlin/wang/harlon/tinyui/HostServices.kt
compose/src/commonMain/kotlin/wang/harlon/tinyui/PageHost.kt
compose/src/commonTest/kotlin/wang/harlon/tinyui/PageHostTest.kt
docs/native-api.md
扩展内置组件模型,允许按钮以 children 作为内容并新增由 JS 控制选中态的 RadioButton。
  • 将 Button 的 text 改为可选,并在存在 children 时渲染 children。
  • 新增 RadioButton 的 selected、enabled 属性和 onClick 事件。
  • 更新组件 schema、生成代码、组件注册实现及组件文档。
schema/components/button.ts
schema/components/radio-button.ts
schema/index.ts
packages/core/src/generated/components.ts
compose/src/commonMain/kotlin/wang/harlon/tinyui/components/Builtins.kt
compose/src/commonMain/kotlin/wang/harlon/tinyui/components/generated/BuiltinSchemas.kt
docs/components.md
compose/api/compose.klib.api
支持 tinyui 作为宿主 App 的 Gradle included/composite build 使用,并避免宿主场景加载 sample 工程。
  • 新增 Maven 坐标到本地 :compose 项目的 composite substitution。
  • 通过 gradle.parent 条件仅在独立构建时包含 sample 工程。
  • 为不存在的 sample 项目保护 mustRunAfter 配置。
gradle/composite-substitutions
settings.gradle.kts
compose/build.gradle.kts
同步项目文档与路线图,记录本批框架能力和集成方式。
  • 补充宿主自定义能力的 API、错误语义和能力清单约定。
  • 更新组件清单及 Button/RadioButton 的状态管理说明。
  • 标记 TrendingAI 订阅页触发的相关工作已完成。
docs/native-api.md
docs/components.md
docs/roadmap.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codeseerbot codeseerbot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CodeSeer 审查

结论:批准

摘要

本次改动为宿主侧新增了 host.call 能力注册与异步回调收口,并将能力清单传入挂载 manifest。同时扩展了 Button children、加入 RadioButton,并调整 Gradle 设置以支持作为 composite build 引入。基于给出的代码,未发现由这些增量明确引入的逻辑、异常处理、资源管理或构建配置问题。

整个 PR 至 021bab5 · gpt-5.6-terra

宿主类型包里 `<ta.Icon>` 要能直接写:生成 `export const ta = { Icon: "ta.Icon" } as const` 与
`declare module "@tiny-ui/core/jsx-runtime"` 的 IntrinsicElements 合并,不再需要手写胶水。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

@codeseerbot codeseerbot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CodeSeer 审查

结论:批准

摘要

本次增量为带命名空间的宿主组件生成前缀对象,并通过模块扩充将对应标签加入 @tiny-ui/core/jsx-runtime 的 JSX 类型命名空间。生成逻辑与现有组件类型生成路径一致,新增测试覆盖了前缀对象和模块扩充的文本输出。未发现可由当前代码证实的功能性问题。

增量 021bab5..5927ae7 · gpt-5.6-terra

@HarlonWang
HarlonWang merged commit 252e667 into main Sep 17, 2026
4 checks passed
@HarlonWang
HarlonWang deleted the feat/host-capabilities branch September 17, 2026 14:12
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.

1 participant