Skip to content
中文

ToolCatalogEntry ​

SUPPORT · type · Type contract

Public declaration surface of one tool, without registry internals.

Import ​

ts
import type { ToolCatalogEntry } from '@jangts/agent-core/support';
js
/** @typedef {import('@jangts/agent-core/support').ToolCatalogEntry} ToolCatalogEntry */

Other public entry points:@jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/support.

Definition ​

Type: ToolCatalogEntry<App, Tool>

Type expression
ts
type ToolCatalogEntry<App, Tool extends ToolDefinition<unknown, unknown, App>> = Tool extends ToolDefinition<unknown, unknown, App>
    ? Pick<Tool, keyof ToolDefinition<unknown, unknown, App>>
    : never;

Type parameters ​

Type parameterConstraintDefault type
App——
ToolToolDefinition<unknown, unknown, App>—

Field structure ​

FieldTypeRequiredDescription
idstringRequiredRead-only. Stable id; also the name the model calls.
descriptionstringRequiredRead-only. Model-visible explanation of when to call the tool.
resolve((input: unknown, context: Readonly<{ stageId: string; }>) => ToolProposal) | undefinedOptionalRead-only. See the type definition and usage context.
inputSchemaSchemaAdapter<unknown>RequiredRead-only. Schema applied to raw model arguments before authorize and execute.
activeToolCondition<App> | undefinedOptionalRead-only. Omitted means active. Authorization remains a separate execution boundary.
asIntentAsIntent<App> | undefinedOptionalRead-only. Omitted means this tool is not advertised by withIntent().
kindstringRequiredRead-only. Declared grouping used by registries and documentation; not an authorization boundary.
authorize(input: unknown, context: OperationContext<App>) => MaybePromise<void>RequiredHost permission check. Runs before execution and may be asynchronous.
execute(input: unknown, context: OperationContext<App> & NodeReportingContext) => unknownRequiredExecutes the already-authorized input; must not repeat authorization decisions.
debugSteps((result: unknown, context: import("../debug.js").NodeReportingContext) => void) | undefinedOptionalOptional result hook; writes through context.createSubFlowLogger() are recorded immediately.
parseOutput(value: unknown) => unknownRequiredValidates untrusted output (for example a cached replay) before it is returned.

Member index ​

MemberPurpose
authorizeHost permission check. Runs before execution and may be asynchronous.
executeExecutes the already-authorized input; must not repeat authorization decisions.
parseOutputValidates untrusted output (for example a cached replay) before it is returned.

Member details ​

authorize ​

Host permission check. Runs before execution and may be asynchronous.

ts
ToolCatalogEntry.authorize(input: unknown, context: OperationContext<App>): MaybePromise<void>

Host permission check. Runs before execution and may be asynchronous.

ParameterTypePassingDescription
inputunknownRequired—
contextOperationContext<App>Required—
Fields of context
FieldTypeRequiredDescription
appunknown extends App ? App : Readonly<App>RequiredRead-only. See the type definition and usage context.
loggerSubFlowLog | undefinedOptionalRead-only. Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignalRequiredRead-only. Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Diagnostic scope of the enclosing call, when recording is enabled.

Returns: MaybePromise<void>.

Awaited value: void.

execute ​

Executes the already-authorized input; must not repeat authorization decisions.

ts
ToolCatalogEntry.execute(input: unknown, context: OperationContext<App> & NodeReportingContext): unknown

Executes the already-authorized input; must not repeat authorization decisions.

ParameterTypePassingDescription
inputunknownRequired—
contextOperationContext<App> & NodeReportingContextRequired—
Fields of context
FieldTypeRequiredDescription
appunknown extends App ? App : Readonly<App>RequiredRead-only. See the type definition and usage context.
loggerSubFlowLog | undefinedOptionalRead-only. Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignalRequiredRead-only. Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Diagnostic scope of the enclosing call, when recording is enabled.
report(update: import("./execution/workflow.js").WorkflowNodeReport) => voidRequiredReports progress for the active node; Core supplies the execution identity.
createSubFlowLogger() => SubFlowLoggerRequiredBound to this context and owned by runtime; repeated calls in one visit return the same instance.

Returns: unknown.

parseOutput ​

Validates untrusted output (for example a cached replay) before it is returned.

ts
ToolCatalogEntry.parseOutput(value: unknown): unknown

Validates untrusted output (for example a cached replay) before it is returned.

ParameterTypePassingDescription
valueunknownRequired—

Returns: unknown.

Examples ​

Define and use a read-only tool ​

Beginner · Node.js

ts
import { Support } from '@jangts/agent-core';
const inputSchema = Support.defineSchema({
  jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
  parse(value: unknown) {
    if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length) throw new TypeError('需要空对象');
    return {};
  },
});
const catalog = Support.defineToolCatalog([{ id: 'get_status', kind: 'read', description: '读取服务状态', inputSchema,
  authorize() {},
  execute() { return '服务运行正常'; },
  parseOutput(value: unknown) { if (typeof value !== 'string') throw new TypeError('需要字符串'); return value; },
}]);
const tools = catalog.bind({ app: undefined });
console.log((await tools.invoke({ toolId: 'get_status', input: {} })).value);
console.log(catalog.tools.ids());
js
import { Support } from '@jangts/agent-core';
const inputSchema = Support.defineSchema({
    jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
    parse(value) {
        if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length)
            throw new TypeError('需要空对象');
        return {};
    },
});
const catalog = Support.defineToolCatalog([{ id: 'get_status', kind: 'read', description: '读取服务状态', inputSchema,
        authorize() { },
        execute() { return '服务运行正常'; },
        parseOutput(value) { if (typeof value !== 'string')
            throw new TypeError('需要字符串'); return value; },
    }]);
const tools = catalog.bind({ app: undefined });
console.log((await tools.invoke({ toolId: 'get_status', input: {} })).value);
console.log(catalog.tools.ids());

Keep the list and add this request's permissions and service dependencies ​

Configuration · Node.js

ts
import { Support } from '@jangts/agent-core';
import type { OperationContext } from '@jangts/agent-core/types';
type App = { allowed: boolean; readStatus(): Promise<string> };
const inputSchema = Support.defineSchema({
  jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
  parse(value: unknown) {
    if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length) throw new TypeError('需要空对象');
    return {};
  },
});
const catalog = Support.defineToolCatalog<App>([{ id: 'get_status', kind: 'read', description: '读取状态', inputSchema,
  authorize(_input: {}, { app }: OperationContext<App>) { if (!app.allowed) throw new Error('当前请求没有读取权限'); },
  execute(_input: {}, { app }: OperationContext<App>) { return app.readStatus(); },
  parseOutput(value: unknown) { if (typeof value !== 'string') throw new TypeError('需要字符串'); return value; },
}]);
const tools = catalog.bind({ app: { allowed: true, readStatus: async () => '服务运行正常' },
  execution: { signal: AbortSignal.timeout(10000) },
});
console.log((await tools.invoke({ toolId: 'get_status', input: {} })).value);
js
import { Support } from '@jangts/agent-core';
const inputSchema = Support.defineSchema({
    jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
    parse(value) {
        if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length)
            throw new TypeError('需要空对象');
        return {};
    },
});
const catalog = Support.defineToolCatalog([{ id: 'get_status', kind: 'read', description: '读取状态', inputSchema,
        authorize(_input, { app }) { if (!app.allowed)
            throw new Error('当前请求没有读取权限'); },
        execute(_input, { app }) { return app.readStatus(); },
        parseOutput(value) { if (typeof value !== 'string')
            throw new TypeError('需要字符串'); return value; },
    }]);
const tools = catalog.bind({ app: { allowed: true, readStatus: async () => '服务运行正常' },
    execution: { signal: AbortSignal.timeout(10000) },
});
console.log((await tools.invoke({ toolId: 'get_status', input: {} })).value);

API reference, usage examples and developer guides.