跳到正文
Skillpedia
分析与电子表格7.6k · #13152

data-programs

它能做什么

这项技能把一次性的数据脚本(用于获取、合并并汇总信息)转化为一个已保存的程序。该程序会存储结果,并按计划刷新,使多个界面可以复用。适合在 Agent-Native 应用中构建仪表板和报告的人。

适用场景

  • ✓当临时分析应变成其他人可以复用的实时数据源的时候。
  • ✓当许多视图不断重复执行相同的数据获取,你希望缓存它的时候。
  • ✓当你希望图表或表格显示从多个来源收集的数据的时候。

技能链接

https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/data-programs/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/data-programs/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“你能把这个合并销售和支持数据的脚本保存为一个数据源,让我的仪表板可以刷新吗?”

每周 5 个新技能,1 分钟读完。

工作原理

智能体先编写并测试脚本,然后将其保存为数据程序。该程序运行后会缓存其小型结果表,并根据缓存策略进行刷新。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Data Programs

A data program is a named, stored, agent-authored JS script that fetches, joins, filters, or aggregates data — provider APIs via providerFetch / providerFetchAll / providerSearchAll, app data via appAction, or Resources-backed workspace files — and emits a small { rows, schema } result that gets cached in SQL. Any app can render that result through its own table/chart components; nothing about the primitive is analytics-specific.

This ships automatically wherever run-code is available — there is nothing to mount, wire, or configure per app. If your app already has run-code enabled, save-data-program / preview-data-program / run-data-program / list-data-programs / get-data-program / delete-data-program are already registered actions.

Why this exists

Without it, "build a live view of X" tends to end in one of two bad places: a hardcoded action per vendor/query shape (brittle, doesn't scale to every customer's custom fields), or re-running the same fetch/join logic from scratch on every page view (slow, and it re-spends the same provider quota every time someone looks at a chart). A data program is the middle ground: write the fetch/join/aggregate logic once as ordinary run-code, save it, and let the cache + refresh policy handle "how often does this actually need to re-run."

Authoring workflow

  1. Prototype the fetch/join/aggregate logic as a normal run-code script and confirm it returns the rows you expect.
  2. Change it to call emit(rows, schema?) exactly once at the end instead of returning or printing the result.
  3. Save it with save-data-program({ name, title, description, code, defaultParams?, refreshMode?, refreshTtlMs?, background? }). This dry-runs the code with defaultParams before persisting and rejects the save with a structured error if it fails, so a broken program is never stored. On success it returns { programId, rowCount, columns, sampleRows } — use that as proof the program produces the rows you expect.
  4. Bind whatever UI needs the result. Your app's own read path calls run-data-program({ programId, params?, forceRefresh?, includeRows? }) and gets back rows/schema/cache metadata to hand to your own table/chart components — there is no dashboard-specific plumbing baked into the primitive itself. (The analytics template's "program" dashboard panel source is one such adoption, not a required pattern — see its data-programs skill if you want a concrete UI wiring reference.)
  5. Iterate without persisting via preview-data-program({ code, params? }) — same dry-run path, no stored row.

The sandbox surface

Exactly the run-code globals (providerFetch, providerFetchAll, providerSearchAll, appAction, webFetch, workspace* Resources helpers), plus:

  • params — a frozen global object holding the params for this run. Read-only; mutating it throws.
  • emit(rows, schema?) — call exactly once, at the end. rows must be an array of plain objects. schema, when provided, is { name: string, type: string }[]; when omitted it's inferred from the first 50 rows (a column is "json" if rows disagree on primitive type, otherwise "number" / "string" / "boolean"). console.log remains free for debugging and never interferes with parsing the emitted result.

Caps enforced on every run:

Limit Value
Max emitted rows 10,000 (excess dropped, truncated: true)
Max emitted result size 4 MiB (rows dropped from the end to fit; a single oversized row is a hard failure)
Max active programs per app 200
Minimum refresh TTL 60,000 ms
Run rows kept per (program, params) 5 most recent

Truncation is always explicit (truncated: true) — never a silent drop.

Caching and refresh model

Every (programId, paramsHash) pair has its own run history:

Situation Behavior
Fresh cache (younger than refreshTtlMs, or refreshMode: "manual" with a prior success) Returns cached rows instantly, cacheHit: true
Stale cache Re-executes synchronously (25s budget for view-triggered reads, 120s for agent/manual calls), replacing the cache on success
refreshMode: "manual" Only refreshes on explicit forceRefresh: true
No cache yet Executes synchronously like a normal first fetch
background: true program with no fresh cache Serves the last good run with stale: true and enqueues a du
常见问题

结果存储在哪里?

结果以一小组行和架构的形式缓存在应用的 SQL 数据库中。

谁可以使用已保存的数据?

任何渲染该结果的应用界面都可以使用,包括有权限的其他用户。

每个应用都需要单独设置吗?

不需要。只要启用了运行代码功能,它就可以使用,因此无需额外配置。

详情

作者的原始描述

Save a run-code fetch/join/aggregate script as a stored, refreshable data source any app's own charts/tables can render, instead of a hardcoded provider action or a per-view re-fetch. Use when an ad-hoc run-code or provider-api-request analysis should become a live, cached data source other users or panels can reuse.

repo: BuilderIO/agent-native

热度

GitHub 星标
7.6k
排名
#13152
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能