首页 时政热点 科技头条 智能AI 安全攻防 数码硬件 开发者生态 归档 标签 关于

GitHub 热门项目:sdk-js

2026-07-20 1 阅读 约8分钟阅读 GitHub Trending
分享:
字号:
GitHub 项目:sdk-js 仓库地址:https://github.com/astrid-runtime/sdk-js 星级:8187 | 作者:astrid-runtime 项目描述:用于构建 Astrid 胶囊的 JavaScript 和 TypeScript SDK。 =================================================== 自述文件内容: # sdk-js [![许可证:MIT 或 Apache-2.0](https://img.shields.io/badge/License-MIT%20OR%20Apache--2.0-blue.svg)](LICENSE-MIT) [![节点:>=20](https://img.shields.io/badge/Node-%3E%3D20-blue)](https://nodejs.org) [![TypeScript: 5.2+](https://img.shields.io/badge/TypeScript-5.2%2B-blue)](https://www.typescriptlang.org) **用于构建 [Astrid](https://github.com/astrid-runtime/astrid) 胶囊的 JavaScript / TypeScript SDK。** [sdk-rust](https://github.com/astrid-runtime/sdk-rust) 的伴侣。相同的 WIT 合约、相同的 wasip2 组件模型输出、相同的“.capsule”存档格式 - 您的内核无法分辨哪种语言构建了二进制文件。 Rust SDK 感觉就像针对“std”编写,而这个感觉就像针对“node:fs/promises”/WHATWG/Node 的“EventEmitter”编写。相同的主机 ABI,翻译成语。 ## 套餐 |套餐 |角色 | |---|---| | `@unicity-astrid/sdk` |胶囊作者 API。 `astrid-sdk` 的 `prelude` 的逐模块镜像 — `fs`、`net`、`process`、`env`、`time`、`log`,以及 Astrid 特定的 `ipc`、`kv`、`http`、`hooks`、`uplink`、`identity`、`approval`、`runtime`、`elicit`、`capability`、`interceptors`。 TypeScript 装饰器(`@capsule`、`@tool`、`@interceptor`、`@command`、`@install`、`@upgrade`、`@run`)替换 `#[capsule]`。 | | `@unicity-astrid/build` |构建协调器。运行 `tsc` + esbuild + ComponentizeJS 编程 API。发出一个“wasm32-wasip2”组件,Rust 端“astrid-build”将其打包到“.capsule”存档中。 | | `@unicity-astrid/sdk/contracts` |从 `astrid-contracts.wit` 自动生成的 TS 类型 — IPC 事件类型(`Message`、`ToolCall`、`GenerateRequest`、`StreamEvent` 等)可在跨胶囊 IPC 的两端使用。 | ## 快速开始 ````bash mkdir 我的胶囊 && cd 我的胶囊 npm 初始化 -y npm 安装@unicity-astrid/sdk npm install --save-dev @unicity-astrid/build typescript ```` `胶囊.toml`: ````汤姆 [包装] 名称 =“我的胶囊” 版本=“0.1.0” [[组件]] id =“我的胶囊” 文件=“我的胶囊.wasm” 类型=“可执行文件” [能力] ipc_publish = ["工具.v1.execute.*"] kv = [“*”] ```` `src/index.ts`: ``打字稿 从“@unicity-astrid/sdk”导入{capsule、tool、install、log、kv}; @胶囊 导出类 MyCapsule { 问候=0; @tool("问候", { 可变: true }) 问候({名称}:{名称:字符串}):{消息:字符串;计数:数量 } { this.greetings++; log.info(`问候语 ${name} (#${this.greetings})`); return { message: `你好,${name}!`, count: this.greetings }; } @安装 onInstall(): 无效 { log.info("我的胶囊已安装"); } } ```` 构建: ````bash astrid build # 或:astridcapsule install 。 ```` 就是这样。 `tsc` 编译你的 TypeScript,SDK 中的 esbuild 包,ComponentizeJS 生成一个 `wasip2` 组件,Rust 端的 `astrid-build` 将其打包到 `dist/my-capsule.capsule` 中。 ## 构建胶囊 端到端管道: ```` src/*.ts ↓ tsc(类型检查 + 发出 dist/*.js) ↓ esbuild(将 dist/ + @unicity-astrid/sdk 捆绑到一个 ESM 中,ma
这篇文章对您有帮助吗?

订阅66必读

每日精选科技资讯,直达你的邮箱