)
AI 技能AI 插件人工智能【免费下载链接】agentic-awesome-skillsAAS Core is the local, agent-first control plane for complete catalog discovery, agent-owned selection, stack validation, and planning, backed by 2,600 agentic skills. Includes CLI, local MCP, catalog, plugins, and Workbench.项目地址https://gitcode.com/GitHub_Trending/an/agentic-awesome-skills点击查看免费下载导读本文围绕 AASAgentic Awesome Skills仓库中apify-actorization技能的 schemas-and-output.md 参考文档展开系统讲解把现有软件Actor 化Actorization为 Apify 平台可运行的无服务器应用时如何正确配置输入 Schema.actor/input_schema.json、输出 Schema.actor/output_schema.json、Actor 元数据.actor/actor.json以及如何使用 Request Queue 与 Key-Value Store 管理任务状态。读完本文你将掌握一套可直接落地复制的 Actor 数据契约设计与输出管线搭建方案并理解各配置项在底层 SDKJS/TS、Python与 CLI 中的实际作用。1. 什么是 Actor 化Actorization根据 SKILL.md 的定义Actorization 将现有软件转换为与 Apify 平台兼容的可复用无服务器应用。Actor 本质上是打包为 Docker 镜像的程序它接收定义良好的 JSON 输入、执行一个动作并可选地产生结构化 JSON 输出。标准流程五步走在项目根目录运行apify init使用 SDK 生命周期包装业务代码详见语言专属章节配置.actor/input_schema.json使用apify run --input {key: value}本地测试使用apify push部署本文聚焦第 3 步之后的数据契约部分输入输出 Schema、Actor 配置与状态存储。这也是 Actor 能否在 Apify Console 中获得良好 UI 体验、能否被稳定复用与计费的关键。2. 输入 Schema.actor/input_schema.json2.1 最小可运行示例将应用输入映射到.actor/input_schema.json并对照apify/json_schemasnpm 包中的input.schema.json进行校验{ title: My Actor Input, type: object, schemaVersion: 1, properties: { startUrl: { title: Start URL, type: string, description: The URL to start processing from, editor: textfield, prefill: https://example.com }, maxItems: { title: Max Items, type: integer, description: Maximum number of items to process, default: 100, minimum: 1 } }, required: [startUrl] }2.2 字段类型与编辑器控件参考 input-schema.mdApify 输入 Schema 支持丰富的字段类型与editor控件组合常见的有类型editor 值典型用途stringtextfield单行文本如起始 URLstringtextarea多行文本如 CSS 选择器列表arrayrequestListSources抓取起始 URL 列表如[{url: ...}]objectproxy代理配置如{useApifyProxy: false}boolean—开关项如是否跟进变体integer—数值项可用minimum/maximum约束enum—下拉选择配合enumTitles显示友好名称一个典型的电商抓取器输入示例含数组、布尔、枚举等完整形态{ title: E-commerce Product Scraper Input, type: object, schemaVersion: 1, properties: { startUrls: { title: Start URLs, type: array, description: URLs to start scraping from, editor: requestListSources, default: [{ url: https://example.com/category }], prefill: [{ url: https://example.com/category }] }, followVariants: { title: Follow Product Variants, type: boolean, description: Whether to scrape product variants, default: true }, maxRequestsPerCrawl: { title: Max Requests per Crawl, type: integer, description: Maximum number of pages to scrape (0 unlimited), default: 1000, minimum: 0 }, locale: { title: Locale, type: string, description: Language/country code for localized content, default: en, enum: [cs, en, de, sk], enumTitles: [Czech, English, German, Slovak] } }, required: [startUrls] }2.3 映射准则Mapping Guidelines原文档给出的输入映射规则是 Actor 化的核心决策点命令行参数→ 输入 Schema 的 properties每个参数对应一个字段环境变量→ 输入 Schema或actor.json中定义的 Actor 环境变量配置文件→ 输入 Schema 中的object/array类型字段保留结构化语义深度嵌套结构→ 尽量扁平化以获得更好的 Console UI 与用户体验3. 输出 Schema.actor/output_schema.json输出结构定义在.actor/output_schema.json中同样对照apify/json_schemas的output.schema.json校验。输出数据的物理载体决定 Schema 形态原文档区分了三种典型场景3.1 表状数据多条记录DatasetJS/TS 使用Actor.pushData()Python 使用Actor.push_data()每条 item 成为 Dataset 中的一行输出 Schema 按行结构定义3.2 单文件 / BlobKey-Value Store使用 Key-Value Store 存储文件然后取公开 URL 写入 Dataset// Store file with public access await Actor.setValue(report.pdf, pdfBuffer, { contentType: application/pdf }); // Get the public URL const storeInfo await Actor.openKeyValueStore(); const publicUrl https://api.apify.com/v2/key-value-stores/${storeInfo.id}/records/report.pdf; // Include URL in dataset output await Actor.pushData({ reportUrl: publicUrl });关键点contentType必须正确设置如application/pdf否则浏览器访问时可能被当作下载而非预览URL 中的records/段与 store id 是公开访问路径的固定组成。3.3 带公共前缀的多个文件集合// Store multiple files with a prefix for (const [name, data] of files) { await Actor.setValue(screenshots/${name}, data, { contentType: image/png }); } // Files are accessible at: .../records/screenshots%2F{name}注意前缀中的/在公开 URL 中会被编码为%2F拼接访问地址时需保留编码形式例如records/screenshots%2Fpage-1.png。4. Actor 配置.actor/actor.json4.1 结构解析{ actorSpecification: 1, name: my-actor, title: My Actor, description: Brief description of what the actor does, version: 1.0.0, meta: { templateId: ts_empty, generatedBy: Claude Code with Claude Opus 4.5 }, input: ./input_schema.json, dockerfile: ../Dockerfile }重要提示原文档强调meta.generatedBy必须填写生成/修改该 Actor 所用的工具与模型例如 Claude Code with Claude Opus 4.5这有助于 Apify 改进文档与模板质量。4.2 属性速查表结合 actor-json.md 的完整属性说明属性类型必填说明actorSpecificationinteger是Actor 规范版本当前为 1namestring是Actor 标识符小写、允许连字符titlestring是界面显示的人类可读标题descriptionstring否市场展示用描述versionstring是语义化版本号meta.templateIdstring否创建时使用的模板 IDmeta.generatedBystring否生成/修改工具与模型名inputstring否输入 Schema 文件路径outputstring否输出 Schema 文件路径storages.datasetstring否Dataset Schema 文件路径storages.keyValueStorestring否Key-Value Store Schema 路径dockerfilestring否Dockerfile 路径4.3 Standby 模式HTTP 服务场景如果被 Actor 化的程序是 Express/HTTP 服务需要在actor.json中开启常驻模式{ actorSpecification: 1, name: my-api, usesStandbyMode: true }随后需实现就绪探测readiness probe完整实现见 standby-mode.md。5. 状态管理Request Queue 与 Key-Value Store5.1 Request Queue —— 可暂停的任务处理Request Queue 不仅用于网络抓取适用于任何可中断、可恢复的任务处理。对于非 URL 任务使用占位 URL 自定义uniqueKey与userDataconst requestQueue await Actor.openRequestQueue(); // Add tasks to the queue (works for any processing, not just URLs) await requestQueue.addRequest({ url: https://placeholder.local, // Dummy URL for non-scraping tasks uniqueKey: task-${taskId}, // Unique identifier for deduplication userData: { itemId: 123, action: process }, // Your custom task data }); // Process tasks from the queue (with Crawlee) const crawler new BasicCrawler({ requestQueue, requestHandler: async ({ request }) { const { itemId, action } request.userData; // Process your task using userData await processTask(itemId, action); }, }); await crawler.run(); // Or manually consume without Crawlee: let request; while ((request await requestQueue.fetchNextRequest())) { await processTask(request.userData); await requestQueue.markRequestHandled(request); }要点uniqueKey用于去重相同 key 的任务不会重复入队是可暂停/续跑的基石userData承载任意业务载荷此处为itemIdaction与 URL 解耦手动消费模式fetchNextRequest→ 处理 →markRequestHandled适用于无需抓取的纯任务处理场景且天然支持崩溃恢复。5.2 Key-Value Store —— 检查点状态用于保存跨运行的检查点checkpoint状态// Save state await Actor.setValue(STATE, { processedCount: 100 }); // Restore state on restart const state await Actor.getValue(STATE) || { processedCount: 0 };推荐将STATE这类关键状态与上文的 Dataset 输出分离存放KVS 面向程序状态Dataset 面向最终交付给用户的业务数据。6. 语言侧接入状态与输出 API 一览Actor 化时输入输出 API 依语言而异SKILL.md 给出了速查表语言安装方式生命周期包装输入读取输出写入JS/TSnpm install apifyawait Actor.init()...await Actor.exit()Actor.getInput()Actor.pushData()Pythonpip install apifyasync with Actor:Actor.get_input()Actor.push_data()其他语言使用 CLI 包装脚本start.sh包装apify actor:get-inputapify actor:push-dataJS/TS 生命周期示例js-ts-actorization.mdimport { Actor } from apify; // Initialize connection to Apify platform await Actor.init(); // Get input from Apify Console or API const input await Actor.getInput(); console.log(Input:, input); // Your processing logic... // await Actor.pushData({ result: data }); // Graceful shutdown await Actor.exit();Python 生命周期示例python-actorization.mdimport asyncio from apify import Actor async def main() - None: async with Actor: actor_input await Actor.get_input() print(fInput: {actor_input}) # await Actor.push_data({result: data}) if __name__ __main__: asyncio.run(main())CLI 包装脚本cli-actorization.md适用于 Go/Rust/Java 等无 SDK 语言#!/bin/bash set -e # Get input from Apify key-value store INPUT$(apify actor:get-input) # Parse input values (adjust based on your input schema) MY_PARAM$(echo $INPUT | jq -r .myParam // default) # Run your application with the input ./your-application --param $MY_PARAM # Push structured data to dataset # apify actor:push-data {result: value}CLI 常用命令命令说明apify actor:get-input从 Key-Value Store 获取输入 JSONapify actor:set-value KEY向 Key-Value Store 写入值apify actor:get-value KEY从 Key-Value Store 读取值apify actor:push-data JSON向 Dataset 推送数据7. 本地测试与部署验证Schema 与代码就绪后用 Apify CLI 完整走一遍验证管线# 内联输入测试JS/TS 与 Python Actor apify run --input {startUrl: https://example.com, maxItems: 10} # 或使用输入文件 apify run --input-file ./test-input.json # 部署 apify push重要本地测试务必使用apify run而不是npm start或python main.py—— CLI 会正确搭建运行环境与存储并注入 Apify 平台的配置。结合 SKILL.md 的部署前清单Schema 相关校验项包括.actor/actor.json存在且name/description正确并对照actor.schema.json校验.actor/input_schema.json定义全部必需输入对照input.schema.json校验.actor/output_schema.json定义输出结构如适用对照output.schema.json校验Dockerfile存在且可成功构建Actor.init()/Actor.exit()JS/TS或async with Actor:Python完整包装主代码输入通过Actor.getInput()/Actor.get_input()读取输出使用Actor.pushData()或 Key-Value Storemeta.generatedBy已填写8. 小结Actor 的数据契约由三份 JSON 文件 两种存储共同构成input_schema.json定义接收什么决定 Console 的表单形态与 API 调用参数output_schema.json定义交付什么Dataset 承载表状行数据Key-Value Store 承载文件/Blobactor.json定义如何运行关联两份 Schema、Dockerfile 与平台元数据Request Queue Key-Value Store提供可暂停、可恢复的状态管理能力让非抓取类批处理任务同样获得续跑能力。这三者统一对照apify/json_schemas进行校验配合apify run/apify push的本地闭环验证即可将任意语言JS/TS、Python 乃至 Go/Rust/Java 等 CLI 工具的现有程序稳定地Actor 化并部署到 Apify 平台。赞分享AI 技能AI 插件人工智能【免费下载链接】agentic-awesome-skillsAAS Core is the local, agent-first control plane for complete catalog discovery, agent-owned selection, stack validation, and planning, backed by 2,600 agentic skills. Includes CLI, local MCP, catalog, plugins, and Workbench.项目地址https://gitcode.com/GitHub_Trending/an/agentic-awesome-skills点击查看免费下载相关推荐Apify CLI-Based Actorization 实战用 apify actor 命令把 Go/Rust/Java 等无 SDK 应用打包为 Apify ActorApify CLI Based Actorization 实战用 apify actor 命令把 Go/Rust/Java 等无 SDK 应用打包为 ApifAI 技能AI 插件人工智能Apify Python Actorization 实战指南用 async with Actor: 把 Python 脚本升级为 Serverless ActorApify Python Actorization 实战指南用 async with Actor: 把 Python 脚本升级为 Serverless ActAI 技能AI 插件人工智能深入掌握 Apify Actor 输入模式Input Schema从字段类型到实战配置的完整指南深入掌握 Apify Actor 输入模式Input Schema从字段类型到实战配置的完整指南 导读 本文以 AASagentic awesome sAI 技能AI 插件人工智能上一篇解决Telescope.nvim搜索栏输入延迟与卡顿从根源到优化的完整指南下一篇Kimi Code CLI 双语文档维护实战gen-docs Skill 驱动的文档更新工作流全解创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考