npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vectorx/functions-framework

v1.0.1

Published

VectorX Functions Framework

Readme

VectorX Functions Framework

VectorX Functions Framework 是一个用于构建和运行云函数的框架,提供了完整的日志系统支持。

日志系统

框架内置了完整的日志系统,支持请求日志记录和用户代码日志记录。

配置

在初始化框架时,可以配置日志系统:

import { createAgentServerFramework } from '@vectorx/functions-framework';

const framework = createAgentServerFramework({
    port: 3000,
    logging: {
        dirname: '/path/to/logs',  // 日志存储目录
        maxSize: '20m',           // 单个日志文件最大大小
        maxFiles: 14              // 保留的日志文件数量
    }
});

日志类型

框架支持两种类型的日志:

  • ACCESS: 访问日志,记录所有 HTTP 请求
  • USERCODE: 用户代码日志,记录用户函数中的日志

日志查询 API

框架提供了日志查询 API,用于查看和调试日志:

GET /@logs

查询参数

| 参数名 | 类型 | 必填 | 说明 | |--------|------|------|------| | type | string | 否 | 日志类型,可选值:ACCESS/USERCODE,默认 ACCESS | | limit | number | 否 | 返回的日志条数限制,默认 100 | | eventId | string | 否 | 按 eventId 过滤日志 |

示例

  1. 查询所有访问日志:
curl 'http://localhost:3000/@logs?type=ACCESS'
  1. 查询特定 eventId 的日志:
curl 'http://localhost:3000/@logs?eventId=550e8400-e29b-41d4-a716-446655440000'
  1. 限制返回条数:
curl 'http://localhost:3000/@logs?limit=10'
  1. 组合查询:
curl 'http://localhost:3000/@logs?type=USERCODE&eventId=550e8400-e29b-41d4-a716-446655440000&limit=20'

响应格式

成功响应:

{
    "success": true,
    "data": [
        {
            "@timestamp": "2024-03-21T10:30:00.000Z",
            "level": "info",
            "eventId": "550e8400-e29b-41d4-a716-446655440000",
            "message": "Request started",
            "method": "GET",
            "url": "/api/example"
        }
    ]
}

错误响应:

{
    "success": false,
    "error": "错误信息"
}

在代码中使用日志

import { functionsLogger } from '@vectorx/functions-framework';
import { LogLevel } from '@vectorx/functions-framework';

// 记录访问日志
functionsLogger.logAccesslog(LogLevel.INFO, 'Custom message', {
    customField: 'value'
});

// 记录用户代码日志
functionsLogger.logUserCodelog([
    { message: 'User log message', level: 'info' }
]);

日志格式

每条日志都包含以下字段:

  • @timestamp: 日志时间戳
  • level: 日志级别
  • eventId: 请求 ID
  • message: 日志消息
  • 其他自定义字段

开发

运行测试

npm test

构建

npm run build

环境管理

读取 .env 文件,校验 env 文件的可用性,获取当前运行环境

rcb-ff 自动检测项目类型

当直接使用 rcb-ff 命令启动服务时,如果未指定 --mode 参数,会自动检测项目类型:

检测规则

  1. Agent 项目检测

    • 如果存在 project.config.json 文件且包含 agentId 字段,则判定为 agent 项目
  2. Fun 项目检测

    • 如果不存在 project.config.jsonproject.config.json 中不存在 agentId 字段
    • 且存在 agent-cloudbase-functions.json 配置文件
    • 则判定为 fun 项目
  3. 默认行为

    • 如果无法确定项目类型,默认使用 agent 模式(保持向后兼容)

使用示例

# 自动检测项目类型(推荐)
rcb-ff --directory ./my-project

# 明确指定模式(覆盖自动检测)
rcb-ff --directory ./my-project --mode fun
rcb-ff --directory ./my-project --mode agent