NetlifyDeployer
NetlifyDeployer 類別透過調整 Mastra 的輸出,建立伺服器的最佳化版本,以處理封裝、設定及部署。它在基礎 Deployer 類別上加入 Netlify 專用功能,讓你可以在 Netlify 無伺服器函式或邊緣函式中執行 Mastra。
安裝安裝 的直接連結
要使用 NetlifyDeployer,你需要安裝 @mastra/deployer-netlify 套件:
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/deployer-netlify@latest
pnpm add @mastra/deployer-netlify@latest
yarn add @mastra/deployer-netlify@latest
bun add @mastra/deployer-netlify@latest
使用範例使用範例 的直接連結
匯入 NetlifyDeployer,並在 Mastra 設定中將其設為 deployer:
src/mastra/index.ts
import { Mastra } from '@mastra/core'
import { NetlifyDeployer } from '@mastra/deployer-netlify'
export const mastra = new Mastra({
deployer: new NetlifyDeployer(),
})
建構函式選項建構函式選項 的直接連結
target?: 'serverless' | 'edge':Netlify 的部署目標。預設為'serverless'。'serverless':標準 Netlify Functions(Node.js 運行階段,預設逾時時間為 60 秒)。'edge':Netlify Edge Functions(以 Deno 為基礎的運行階段,在最接近使用者的邊緣位置執行,沒有固定逾時時間)。
Edge Functions 範例Edge Functions 範例 的直接連結
src/mastra/index.ts
import { Mastra } from '@mastra/core'
import { NetlifyDeployer } from '@mastra/deployer-netlify'
export const mastra = new Mastra({
deployer: new NetlifyDeployer({
target: 'edge',
}),
})
輸出輸出 的直接連結
執行 mastra build 後,deployer 會產生 .netlify 資料夾。建置輸出包括項目中的所有 Agent、Tool 和 Workflow,以及用來設定 Netlify Frameworks API 的 config.json 檔案。
無伺服器輸出(預設)無伺服器輸出(預設) 的直接連結
your-project/
└── .netlify/
└── v1/
├── config.json
└── functions/
└── api/
├── index.mjs
├── package.json
└── node_modules/
config.json 檔案包含:
{
"functions": {
"directory": ".netlify/v1/functions",
"node_bundler": "none",
"included_files": [".netlify/v1/functions/**"]
},
"redirects": [
{
"force": true,
"from": "/*",
"to": "/.netlify/functions/api/:splat",
"status": 200
}
]
}
Edge 輸出Edge 輸出 的直接連結
your-project/
└── .netlify/
└── v1/
├── config.json
└── edge-functions/
├── index.mjs
├── package.json
└── node_modules/
config.json 檔案包含:
{
"edge_functions": [
{
"function": "index",
"path": "/*"
}
]
}