跳到主要内容

Mastra.addGateway()

动态向 Mastra 实例添加 gateway。可在初始化期间或之后使用。

使用示例
使用示例的直接链接

import { Mastra } from '@mastra/core'

const mastra = new Mastra()

// Add with explicit key
mastra.addGateway(new MyCustomGateway(), 'myGateway')

// Add using gateway's ID as the key
mastra.addGateway(new MyCustomGateway())
// Stored with key 'my-custom-gateway' (the gateway's id)

参数
参数的直接链接

gateway:

MastraModelGateway
要添加的 gateway 实例

key?:

string
可选的注册键。如果未提供,则使用 gateway.getId()

返回值
返回值的直接链接

无返回值。gateway 会添加到内部注册表。

行为
行为的直接链接

  • 如果已存在具有相同键的 gateway,则跳过添加
  • 在开发模式(MASTRA_DEV=true)下,会自动触发自定义 gateway 的类型生成
  • gateway 会立即可用于模型解析