Skip to content
中文

Protocol registry: one list drives matching and validation ​

Register specifications under the App's own protocol IDs; Core has no built-in business stage names.

ProtocolRegistry extends Map, but set forbids duplicate IDs and empty values; require throws when nothing is found. What is registered is an App-defined protocol contract; it does not automatically create state machines, model prompts, or execution permissions.

An App can let the same list drive model-visible descriptions, parsing, and handler entries, avoiding two parallel sets for model enumeration and program dispatch. Do not promote the state of a particular Kit to a required field for all Apps.

Progressive examples for the same business case ​

A queryable protocol list ​

Beginner · Node.js

ts
import { ProtocolRegistry } from '@jangts/agent-core/protocols';
const protocols = new ProtocolRegistry([['reply', { description: '最终正文', terminal: true }]]);
console.log(protocols.require('reply'), protocols.ids());
js
import { ProtocolRegistry } from '@jangts/agent-core/protocols';
const protocols = new ProtocolRegistry([['reply', { description: '最终正文', terminal: true }]]);
console.log(protocols.require('reply'), protocols.ids());

Generate the same catalog from typed declarations ​

Configuration · Node.js

ts
import { ProtocolRegistry } from '@jangts/agent-core/protocols';
const definitions = [
  { id: 'reply', terminal: true },
  { id: 'lookup', terminal: false },
];
const protocols = new ProtocolRegistry(definitions.map(definition => [definition.id, definition] as const));
console.log(protocols.require('lookup').terminal);
js
import { ProtocolRegistry } from '@jangts/agent-core/protocols';
const definitions = [
    { id: 'reply', terminal: true },
    { id: 'lookup', terminal: false },
];
const protocols = new ProtocolRegistry(definitions.map(definition => [definition.id, definition]));
console.log(protocols.require('lookup').terminal);

API reference, usage examples and developer guides.