@dxos/functions

中文文档
0.10.0发布于 2026/07/03FSL-1.1-Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 2576

Functions API.

原始使用文档
文档目录6 节
  1. Installation
  2. Writing functions
  3. Running functions with the dev server:
  4. Invoking functions
  5. DXOS Resources
  6. Contributions

@dxos/functions

Functions SDK.

Installation

pnpm i @dxos/functions

Writing functions

Create a manifest file at the package root:

functions:
  hello:
    description: Test function.

NOTE: The function name must match the filename (e.g., src/functions/hello.ts).

Create an example function:

import { FunctionContext } from '@dxos/functions';

export default (event: any, context: FunctionContext) => {
  const identity = context.client.halo.identity.get();
  return context.status(200).succeed({
    message: `Hello ${identity?.profile?.displayName}`,
  });
};

Running functions with the dev server:

Configure the agent to run functions on a given port:

# ~/.config/dx/profile/default.yml
runtime:
  agent:
    functions:
      port: 7001

Start functions in dev mode (from the related package):

dx function dev -r ts-node/register --verbose

NOTE: -r ts-node/register configures native TypesScript support.

Install nodemon to support live reloading:

npm i -g nodemon

nodemon -w ./src -e ts --exec $(git rev-parse --show-toplevel)/packages/devtools/cli/bin/dev \
  function dev -r ts-node/register --verbose

Invoking functions

NOTE: The port (7001) must match the one in config.

curl http://localhost:7001/dev/hello -X POST -H 'Content-Type: application/json' -w '\n' --data '{ "message": "Hello World!" }'

DXOS Resources

Contributions

Your ideas, issues, and code are most welcome. Please take a look at our community code of conduct, the issue guide, and the PR contribution guide.

License: FSL-1.1-Apache-2.0 Copyright 2022 © DXOS

版本与发布记录

@dxos/functions 共发布 2,242 个版本,首次发布于 2023/07/13;过去 12 个月发布了 57 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.10.0latest2026/07/034 个月前
0.9.1-staging.ee54ba693anext2026/07/024 个月前
0.9.1-main.c7dcc2e112main2026/06/194 个月前
0.9.02026/06/164 个月前
0.8.4-staging.60fe92afc82026/06/135 个月前
0.8.4-main.43cb7592742026/06/055 个月前

其他发布通道:labs → 0.7.5-labs.d199c0f,main → 0.9.1-main.c7dcc2e112,next → 0.9.1-staging.ee54ba693a。

关于 @dxos/functions 的常见问题

@dxos/functions 是什么?

Functions API.

如何安装 @dxos/functions?

在项目目录运行 npm install @dxos/functions,或使用 pnpm add / yarn add / bun add。

@dxos/functions 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dxos/functions 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dxos/functions 可以商用吗?

@dxos/functions 使用 FSL-1.1-Apache-2.0 许可。声明的许可为 FSL-1.1-Apache-2.0,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@dxos/functions 的下载量有多少?

根据 npm 官方下载统计,@dxos/functions 在 2026/10/13 – 2026/11/11 这 30 天内被下载 2,576 次,日均约 86 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dxos/functions 还在维护吗?

最新版本 0.10.0 发布于 2026/07/03(4 个月前);至今共发布 2242 个版本,其中过去 12 个月发布了 57 个;首次发布于 2023/07/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。