@ raintrust/ 时间
安装
此软件包有同伴依赖性, 您必须同时安装 :
npm install @braintrust/temporal braintrust @temporalio/client @temporalio/worker @temporalio/workflow @temporalio/activity @temporalio/common
# or
yarn add @braintrust/temporal braintrust @temporalio/client @temporalio/worker @temporalio/workflow @temporalio/activity @temporalio/common
# or
pnpm add @braintrust/temporal braintrust @temporalio/client @temporalio/worker @temporalio/workflow @temporalio/activity @temporalio/common
所需资源
braintrust@temporalio/client@temporalio/worker@temporalio/workflow@temporalio/activity@temporalio/common
快速启动
初始化Braintust,然后在Temperal客户端和工人身上安装插件.
import { Client, Connection } from "@temporalio/client";
import { Worker } from "@temporalio/worker";
import * as braintrust from "braintrust";
import { BraintrustTemporalPlugin } from "@braintrust/temporal";
braintrust.initLogger({ projectName: "my-project" });
const plugin = new BraintrustTemporalPlugin();
const client = new Client({
connection: await Connection.connect(),
plugins: [plugin],
});
// ESM-safe resolution (recommended for ESM projects):
const workflowsUrl = new URL("./workflows", import.meta.url);
const workflowsPath = workflowsUrl.pathname;
// CommonJS resolution (existing/example usage):
// const workflowsPath = require.resolve("./workflows");
const worker = await Worker.create({
taskQueue: "my-queue",
workflowsPath: workflowsPath,
activities,
plugins: [plugin],
});
工作流程截取器
这个软件包还输出装入Temperal工作流程隔离的工作流程截取器:
@braintrust/temporal/workflow-interceptors
这个 BraintrustTemporalPlugin 自动配置 workflowModules 包括用在工人身上的拦截器.
实例
见以下例子: examples/temporal-cjs, (中文(简体) ), examples/temporal-esm,以及 examples/temporal-ai-sdk。 。 。 .