开发 development
IMPORTANT
Adobe LLM Apps当前在Beta中。
此处显示的功能、工作流和UI不一定表示产品的最终状态。 要加入Beta,请发送电子邮件至llm-apps-beta@adobe.com 。
本节介绍Adobe LLM Apps的处理程序项目结构、本地开发工作流和测试设置。 有关处理程序协定和示例代码,请参阅编写操作处理程序。
项目结构
您的链接存储库遵循以下布局:
your-llm-app/
├── entry.js # Webpack entry — do not modify
├── actions/ # One folder per action
│ ├── search-products/
│ │ └── index.js # Handler (async function)
│ ├── get-product-details/
│ │ └── index.js
│ └── echo/
│ └── index.js
├── test/
│ ├── actions/
│ │ └── search-products.test.js
│ ├── fixtures/
│ │ └── actions.json
│ ├── html-transform.js
│ ├── jest.setup.js
│ └── server.test.js
├── server/
│ └── local.js # Local dev server (port 9080)
├── actions.json # Gitignored — local copy of UI metadata
├── app.config.yaml # Adobe I/O Runtime config
├── webpack.config.js
└── package.json
要点:
entry.js是webpack入口点。 在生成时,它会发现每actions/*/index.js个文件并将它们捆绑到单个dist/index.js中。 请勿修改。actions.json已授权。 从UI中的“操作”页面下载以进行本地开发。 对于部署,管道会自动从API写入它。- 测试位于
test/actions/下,不在actions/内。 Webpack将actions/下的所有内容捆绑到已部署的工件中 — 共同定位测试会将它们发往Adobe I/O Runtime。
本地开发
您可以在本地开发和测试处理程序,而无需使用Adobe凭据:
npm install
npm run dev:local
这将使用webpack生成项目,并在http://localhost:9080上启动纯Node.js HTTP服务器。 服务器自动发现actions/下的处理程序文件,并将它们注册为MCP工具。
下载actions.json
若要让本地服务器知道您的操作元数据(名称、描述、输入架构),请从LLM Apps UI的“操作”页面下载actions.json,并将其放在存储库根目录下。 如果没有它,服务器将发现您的处理程序,但使用最少的元数据注册它们。
您还可以将actions.example.json复制到actions.json作为起点。
使用curl进行测试
# List all registered tools
curl -sX POST "http://localhost:9080" \
-H 'content-type: application/json' \
-H 'accept: application/json;q=1.0, text/event-stream;q=0.5' \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'
# Call the search-products action
curl -sX POST "http://localhost:9080" \
-H 'content-type: application/json' \
-H 'accept: application/json;q=1.0, text/event-stream;q=0.5' \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"search-products","arguments":{"category":"bagged-coffee"}}}'
使用MCP检查器进行测试
npx @modelcontextprotocol/inspector
将 传输类型 设置为streamable-http并将 URL 设置为http://localhost:9080。
测试
处理程序单元测试位于test/actions/下并镜像actions/布局:
// test/actions/search-products.test.js
const handler = require('../../actions/search-products/index.js')
test('returns all products when no filter is given', async () => {
const result = await handler({})
expect(result.content[0].text).toContain('product')
expect(result.structuredContent.products.length).toBeGreaterThan(0)
})
test('filters by category', async () => {
const result = await handler({ category: 'bagged-coffee' })
expect(result.structuredContent.products.every(
(p) => p.category === 'bagged-coffee'
)).toBe(true)
})
test('filters by query', async () => {
const result = await handler({ query: 'dark-roast' })
expect(result.structuredContent.products.length).toBeGreaterThan(0)
})
test('returns empty result for unknown category', async () => {
const result = await handler({ category: 'nonexistent' })
expect(result.structuredContent.products).toHaveLength(0)
})
运行测试:
npm test # all tests
npx jest test/actions/search-products # one action only
部署
您不会手动生成或部署。 有关部署管道的完整演练,请参阅部署您的应用程序。
您的日常工作流程是:
步骤
操作
1. 编写或编辑处理程序
actions/<name>/index.js2. 下载元数据
“操作”页面→ 下载actions.json
3. 本地测试
npm run dev:local4. 推送代码
git push5. 部署
部署→应用程序详细信息页面
recommendation-more-help
llm-apps-help-main-toc