ToolInvocationPorts
CORE · interface · 类型合同
Optional tools the lifecycle resolves from the host context for one invocation.
导入
ts
import type { ToolInvocationPorts } from '@jangts/agent-core/tools';js
/** @typedef {import('@jangts/agent-core/tools').ToolInvocationPorts} ToolInvocationPorts */其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/tools。
定义
ts
interface ToolInvocationPorts<Context>泛型参数
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Context | — | — |
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
logger | ((context: Context) => import("../debug.js").SubFlowLogger | undefined) | undefined | 可省略 | 只读。Explicit recorder selected for this invocation only. |
diagnostics | ((context: Context) => import("../diagnostics.js").DiagnosticContext | undefined) | undefined | 可省略 | 只读。Diagnostic scope; omitted disables recording for this tool. |
signal | ((context: Context) => AbortSignal | undefined) | undefined | 可省略 | 只读。Extra cancellation; must not replace the tool execution signal. |
journal | ((context: Context) => ToolJournal | undefined) | undefined | 可省略 | 只读。Journal receiving begin/finish receipts. |
checkpoint | ((context: Context) => unknown) | undefined | 可省略 | 只读。Extracts the domain checkpoint recorded with the receipt. |
receipt | ((context: Context, checkpoint: unknown) => unknown) | undefined | 可省略 | 只读。Builds the domain receipt from a checkpoint after execution. |
receiptError | ((error: unknown) => unknown) | undefined | 可省略 | 只读。Converts an error into the receipt's replacement value. |
使用示例
- 宿主已选定调用的同步执行适配:为宿主已经选定的同步调用统一记录开始、完成和失败,不替代选工具与授权。
执行 App 已选定的本地调用
入门 · Node.js
ts
import { executeInvocation } from '@jangts/agent-core/tools';
const state = { status: '' };
executeInvocation({ id: 'read-status', call(_input: {}, context: typeof state) {
context.status = '服务正常';
} }, {}, state);
console.log(state.status);js
import { executeInvocation } from '@jangts/agent-core/tools';
const state = { status: '' };
executeInvocation({ id: 'read-status', call(_input, context) {
context.status = '服务正常';
} }, {}, state);
console.log(state.status);接入同一请求 journal 和取消信号
配置 · Node.js
ts
import { executeInvocation } from '@jangts/agent-core/tools';
import { ContextJournal } from '@jangts/agent-core/journal';
const state = { status: '', journal: new ContextJournal(), signal: new AbortController().signal };
executeInvocation({ id: 'read-status', call(_input: {}, context: typeof state) { context.status = '服务正常'; } }, {}, state, {
signal: context => context.signal,
journal: context => context.journal,
receipt: context => context.status,
});
console.log(state.journal.snapshot());js
import { executeInvocation } from '@jangts/agent-core/tools';
import { ContextJournal } from '@jangts/agent-core/journal';
const state = { status: '', journal: new ContextJournal(), signal: new AbortController().signal };
executeInvocation({ id: 'read-status', call(_input, context) { context.status = '服务正常'; } }, {}, state, {
signal: context => context.signal,
journal: context => context.journal,
receipt: context => context.status,
});
console.log(state.journal.snapshot());