Skip to content
中文

ScopeRegistry ​

KIT · class · Runtime value

Generic scope relationships; categories, intent policy and extra fields belong to the host.

A scope is addressable by its id or by any of its aliases; aliases resolve to the declaring scope, and a name may be claimed only once across both namespaces.

Import ​

ts
import { ScopeRegistry } from '@jangts/agent-core/kits/domains';
js
import { ScopeRegistry } from '@jangts/agent-core/kits/domains';

Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/kits/domains, @jangts/agent-core/kits.

Definition ​

ts
class ScopeRegistry<Definition>

Type parameters ​

Type parameterConstraintDefault type
DefinitionScopeDefinitionScopeDefinition

Constructor ​

ts
new ScopeRegistry<Definition extends ScopeDefinition = ScopeDefinition>(policy?: ScopeRegistryPolicy<Definition>): ScopeRegistry<Definition>
ParameterTypePassingDescription
policyScopeRegistryPolicy<Definition>Optional—
Fields of policy
FieldTypeRequiredDescription
requireGoalsboolean | undefinedOptionalRead-only. Require at least one Tool id per scope.
requireSourcesboolean | undefinedOptionalRead-only. Require at least one query scope or knowledge topic per scope.
requireToolsboolean | undefinedOptionalRead-only. Require at least one tool id per scope.
idPatternRegExp | undefinedOptionalRead-only. Pattern every id and alias must match.
categoriesreadonly string[] | undefinedOptionalRead-only. Allowed category values; undefined accepts any value.
assertDefinition((definition: Definition) => void) | undefinedOptionalRead-only. Extra App assertion, called after the built-in checks; must return void synchronously.
acceptsTool((definition: Readonly<Definition>, goal: string) => boolean) | undefinedOptionalRead-only. Replaces the default intent membership test; must return boolean synchronously.
tagsreadonly string[] | undefinedOptionalRead-only. Diagnostic tags attached to registration rejections.
errors{ readonly sealed?: BreakReason; readonly invalid?: BreakReason; } | undefinedOptionalRead-only. See the type definition and usage context.

Returns: ScopeRegistry<Definition>.

Instance properties ​

FieldTypeRequiredDescription
definitionsreadonly Readonly<Omit<Readonly<ScopeDefinition & RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ScopeListKey> & RegisteredScopeLists<Definition> & { evidence: ScopeEvidenceList<Definition>; }>[]RequiredRead-only. Registered scopes in registration order.

Member index ​

MemberPurpose
createStatic. Create and seal a complete scope catalog in one call.
registerValidate, freeze and add one scope together with its aliases. Every name is checked for conflicts before any of them is stored, so a rejected scope leaves no partial alias entry behind.
registerAllRegister every scope in iteration order.
sealFinalize the registry; no registration is accepted afterwards.
idsRegistered scope ids in registration order; aliases are not included.
valuesIterate the registered scopes.
entriesIterate [id, scope] pairs.
requireRegistered scope for an id or alias.
normalizeResolve an alias to its scope id; unknown names are returned unchanged.
getRegistered scope for an id or alias, or undefined for a null/unknown name.
hasWhether the name resolves to a registered scope.
acceptsToolWhether a scope accepts an intent. The App may override the declared goalIds through acceptsTool; without an override the membership check applies.
acceptsQueryWhether the scope declares this query scope; a null scope accepts nothing.
isWhether the scope belongs to the given App category.
queryScopeIdsEvery query scope declared by any registered scope, deduplicated.
topicsKnowledge topic ids of one scope; copied so callers cannot mutate the registry.
evidenceEvidence declarations of one scope; copied so callers cannot mutate the registry.
contextTierDeclared context tier of one scope, if any.
describeCopy the scopes that accept at least one of the given goals.

Member details ​

create ​

Static member.

Create and seal a complete scope catalog in one call.

ts
ScopeRegistry.create<Definition extends ScopeDefinition>(definitions: Iterable<Definition>, policy?: ScopeRegistryPolicy<Definition>): ScopeRegistry<Definition>

Create and seal a complete catalog; use the constructor for incremental installation.

Type parameterConstraintDefault type
DefinitionScopeDefinition—
ParameterTypePassingDescription
definitionsIterable<Definition>Required—
policyScopeRegistryPolicy<Definition>Optional—
Fields of policy
FieldTypeRequiredDescription
requireGoalsboolean | undefinedOptionalRead-only. Require at least one Tool id per scope.
requireSourcesboolean | undefinedOptionalRead-only. Require at least one query scope or knowledge topic per scope.
requireToolsboolean | undefinedOptionalRead-only. Require at least one tool id per scope.
idPatternRegExp | undefinedOptionalRead-only. Pattern every id and alias must match.
categoriesreadonly string[] | undefinedOptionalRead-only. Allowed category values; undefined accepts any value.
assertDefinition((definition: Definition) => void) | undefinedOptionalRead-only. Extra App assertion, called after the built-in checks; must return void synchronously.
acceptsTool((definition: Readonly<Definition>, goal: string) => boolean) | undefinedOptionalRead-only. Replaces the default intent membership test; must return boolean synchronously.
tagsreadonly string[] | undefinedOptionalRead-only. Diagnostic tags attached to registration rejections.
errors{ readonly sealed?: BreakReason; readonly invalid?: BreakReason; } | undefinedOptionalRead-only. See the type definition and usage context.

Returns: ScopeRegistry<Definition>.

register ​

Instance method.

Validate, freeze and add one scope together with its aliases.

Every name is checked for conflicts before any of them is stored, so a rejected scope leaves no partial alias entry behind.

ts
register(input: Definition): ScopeRegistry<Definition>

Validate, freeze and add one scope together with its aliases.

Every name is checked for conflicts before any of them is stored, so a rejected scope leaves no partial alias entry behind.

ParameterTypePassingDescription
inputDefinitionRequired—

Returns: ScopeRegistry<Definition>.

registerAll ​

Instance method.

Register every scope in iteration order.

ts
registerAll(definitions: Iterable<Definition>): ScopeRegistry<Definition>

Register every scope in iteration order.

ParameterTypePassingDescription
definitionsIterable<Definition>Required—

Returns: ScopeRegistry<Definition>.

seal ​

Instance method.

Finalize the registry; no registration is accepted afterwards.

ts
seal(): ScopeRegistry<Definition>

Finalize the registry; no registration is accepted afterwards.

No call parameters.

Returns: ScopeRegistry<Definition>.

ids ​

Instance method.

Registered scope ids in registration order; aliases are not included.

ts
ids(): readonly string[]

Registered scope ids in registration order; aliases are not included.

No call parameters.

Returns: readonly string[].

values ​

Instance method.

Iterate the registered scopes.

ts
values(): MapIterator<Readonly<Omit<Readonly<ScopeDefinition & RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ScopeListKey> & RegisteredScopeLists<Definition> & { evidence: ScopeEvidenceList<Definition>; }>>

Iterate the registered scopes.

No call parameters.

Returns: MapIterator<Readonly<Omit<Readonly<ScopeDefinition & RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" \| ScopeListKey> & RegisteredScopeLists<Definition> & { evidence: ScopeEvidenceList<Definition>; }>>.

entries ​

Instance method.

Iterate [id, scope] pairs.

ts
entries(): MapIterator<[string, Readonly<Omit<Readonly<ScopeDefinition & RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ScopeListKey> & RegisteredScopeLists<Definition> & { evidence: ScopeEvidenceList<Definition>; }>]>

Iterate [id, scope] pairs.

No call parameters.

Returns: MapIterator<[string, Readonly<Omit<Readonly<ScopeDefinition & RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" \| ScopeListKey> & RegisteredScopeLists<Definition> & { evidence: ScopeEvidenceList<Definition>; }>]>.

require ​

Instance method.

Registered scope for an id or alias.

ts
require(id: string): Readonly<Omit<Readonly<ScopeDefinition & RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ScopeListKey> & RegisteredScopeLists<Definition> & { evidence: ScopeEvidenceList<Definition>; }>

Registered scope for an id or alias.

ParameterTypePassingDescription
idstringRequired—

Returns: Readonly<Omit<Readonly<ScopeDefinition & RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" \| ScopeListKey> & RegisteredScopeLists<Definition> & { evidence: ScopeEvidenceList<Definition>; }>.

Return value structure
FieldTypeRequiredDescription
id(Omit<Readonly<ScopeDefinition & RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ScopeListKey> & RegisteredScopeLists<Definition> & { evidence: ScopeEvidenceList<Definition>; })["id"]RequiredUnique scope id, matched against the policy's idPattern when configured.
description(Omit<Readonly<ScopeDefinition & RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ScopeListKey> & RegisteredScopeLists<Definition> & { evidence: ScopeEvidenceList<Definition>; })["description"]RequiredNon-blank description.
category(Omit<Readonly<ScopeDefinition & RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ScopeListKey> & RegisteredScopeLists<Definition> & { evidence: ScopeEvidenceList<Definition>; })["category"]RequiredScope category; validated against policy.categories when that is set.
contextTier(Omit<Readonly<ScopeDefinition & RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ScopeListKey> & RegisteredScopeLists<Definition> & { evidence: ScopeEvidenceList<Definition>; })["contextTier"] | undefinedOptionalApp-declared context tier, passed through for the App's own policy.
evidence(Omit<Readonly<ScopeDefinition & RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ScopeListKey> & RegisteredScopeLists<Definition> & { evidence: ScopeEvidenceList<Definition>; })["evidence"]RequiredSee the type definition and usage context.

normalize ​

Instance method.

Resolve an alias to its scope id; unknown names are returned unchanged.

ts
normalize(scope: string): string

Resolve an alias to its scope id; unknown names are returned unchanged.

ParameterTypePassingDescription
scopestringRequired—

Returns: string.

get ​

Instance method.

Registered scope for an id or alias, or undefined for a null/unknown name.

ts
get(scope?: string | null): RegisteredScope<Definition> | undefined

Registered scope for an id or alias, or undefined for a null/unknown name.

ParameterTypePassingDescription
scopestring | null | undefinedOptional—

Returns: Readonly<Omit<Readonly<ScopeDefinition & RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" \| ScopeListKey> & RegisteredScopeLists<Definition> & { evidence: ScopeEvidenceList<Definition>; }> \| undefined.

Optional shapes of Return value: choose one shape; required fields for each branch are listed separately.

Branch 1

undefined

Branch 2
FieldTypeRequiredDescription
id(Omit<Readonly<ScopeDefinition & RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ScopeListKey> & RegisteredScopeLists<Definition> & { evidence: ScopeEvidenceList<Definition>; })["id"]RequiredUnique scope id, matched against the policy's idPattern when configured.
description(Omit<Readonly<ScopeDefinition & RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ScopeListKey> & RegisteredScopeLists<Definition> & { evidence: ScopeEvidenceList<Definition>; })["description"]RequiredNon-blank description.
category(Omit<Readonly<ScopeDefinition & RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ScopeListKey> & RegisteredScopeLists<Definition> & { evidence: ScopeEvidenceList<Definition>; })["category"]RequiredScope category; validated against policy.categories when that is set.
contextTier(Omit<Readonly<ScopeDefinition & RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ScopeListKey> & RegisteredScopeLists<Definition> & { evidence: ScopeEvidenceList<Definition>; })["contextTier"] | undefinedOptionalApp-declared context tier, passed through for the App's own policy.
evidence(Omit<Readonly<ScopeDefinition & RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ScopeListKey> & RegisteredScopeLists<Definition> & { evidence: ScopeEvidenceList<Definition>; })["evidence"]RequiredSee the type definition and usage context.

has ​

Instance method.

Whether the name resolves to a registered scope.

ts
has(scope?: string | null): boolean

Whether the name resolves to a registered scope.

ParameterTypePassingDescription
scopestring | null | undefinedOptional—

Returns: boolean.

acceptsTool ​

Instance method.

Whether a scope accepts an intent.

The App may override the declared goalIds through acceptsTool; without an override the membership check applies.

ts
acceptsTool(scope: string, goal: string): boolean

Whether a scope accepts an intent.

The App may override the declared goalIds through acceptsTool; without an override the membership check applies.

ParameterTypePassingDescription
scopestringRequired—
goalstringRequired—

Returns: boolean.

acceptsQuery ​

Instance method.

Whether the scope declares this query scope; a null scope accepts nothing.

ts
acceptsQuery(scope: string | null, queryScope: string): boolean

Whether the scope declares this query scope; a null scope accepts nothing.

ParameterTypePassingDescription
scopestring | nullRequired—
queryScopestringRequired—

Returns: boolean.

is ​

Instance method.

Whether the scope belongs to the given App category.

ts
is(scope: string | null | undefined, category: Definition["category"]): boolean

Whether the scope belongs to the given App category.

ParameterTypePassingDescription
scopestring | null | undefinedRequired—
categoryDefinition["category"]Required—

Returns: boolean.

queryScopeIds ​

Instance method.

Every query scope declared by any registered scope, deduplicated.

ts
queryScopeIds(): string[]

Every query scope declared by any registered scope, deduplicated.

No call parameters.

Returns: string[].

topics ​

Instance method.

Knowledge topic ids of one scope; copied so callers cannot mutate the registry.

ts
topics(scope?: string | null): string[]

Knowledge topic ids of one scope; copied so callers cannot mutate the registry.

ParameterTypePassingDescription
scopestring | null | undefinedOptional—

Returns: string[].

evidence ​

Instance method.

Evidence declarations of one scope; copied so callers cannot mutate the registry.

ts
evidence(scope?: string | null): RegisteredScopeEvidence<Definition>[]

Evidence declarations of one scope; copied so callers cannot mutate the registry.

ParameterTypePassingDescription
scopestring | null | undefinedOptional—

Returns: Readonly<RegistrationData<NonNullable<Definition["evidence"]>[number]>>[].

contextTier ​

Instance method.

Declared context tier of one scope, if any.

ts
contextTier(scope?: string | null): Definition["contextTier"] | undefined

Declared context tier of one scope, if any.

ParameterTypePassingDescription
scopestring | null | undefinedOptional—

Returns: Definition["contextTier"] \| undefined.

describe ​

Instance method.

Copy the scopes that accept at least one of the given goals.

ts
describe(goals?: readonly string[]): ScopeDescription<Definition>[]

Copy the scopes that accept at least one of the given goals.

ParameterTypePassingDescription
goalsreadonly string[] | undefinedOptional—

Returns: ScopeDescription<Definition>[].

Examples ​

Register one tool that explains an interface ​

Beginner · Node.js

ts
import { IntentRegistry, ScopeRegistry } from '@jangts/agent-core/kits/domains';
const tools = IntentRegistry.create([
  { id: 'explain', description: '根据资料解释 SDK', delegates: ['read', 'reply'], asIntent: true },
]);
console.log(tools.ids(), tools.allows('explain', 'read'));
const scopes = ScopeRegistry.create([
  { id: 'sdk', description: 'SDK 说明资料', category: 'knowledge' },
]);
console.log(scopes.require('sdk').knowledgeTopicIds);
js
import { IntentRegistry, ScopeRegistry } from '@jangts/agent-core/kits/domains';
const tools = IntentRegistry.create([
    { id: 'explain', description: '根据资料解释 SDK', delegates: ['read', 'reply'], asIntent: true },
]);
console.log(tools.ids(), tools.allows('explain', 'read'));
const scopes = ScopeRegistry.create([
    { id: 'sdk', description: 'SDK 说明资料', category: 'knowledge' },
]);
console.log(scopes.require('sdk').knowledgeTopicIds);

Add constraints and scope relationships while keeping the same query entry ​

Configuration · Node.js

ts
import { IntentRegistry, ScopeRegistry } from '@jangts/agent-core/kits/domains';
const tools = new IntentRegistry({ idPattern: /^[a-z-]+$/, delegates: ['read', 'reply'] })
  .registerAll([{ id: 'explain', description: '根据资料解释 SDK', delegates: ['read', 'reply'], asIntent: '用户希望了解 SDK 接口或用法。' }]).seal();
const scopes = ScopeRegistry.create([
  { id: 'sdk', description: 'SDK 说明资料', category: 'knowledge', aliases: ['agent-core'], goalIds: ['explain'], knowledgeTopicIds: ['manual'], toolIds: ['read-source'] },
], { categories: ['knowledge'], requireGoals: true, requireSources: true });
console.log(tools.describe(), scopes.normalize('agent-core'));
console.log(scopes.acceptsTool('agent-core', 'explain'), scopes.topics('sdk'));
js
import { IntentRegistry, ScopeRegistry } from '@jangts/agent-core/kits/domains';
const tools = new IntentRegistry({ idPattern: /^[a-z-]+$/, delegates: ['read', 'reply'] })
    .registerAll([{ id: 'explain', description: '根据资料解释 SDK', delegates: ['read', 'reply'], asIntent: '用户希望了解 SDK 接口或用法。' }]).seal();
const scopes = ScopeRegistry.create([
    { id: 'sdk', description: 'SDK 说明资料', category: 'knowledge', aliases: ['agent-core'], goalIds: ['explain'], knowledgeTopicIds: ['manual'], toolIds: ['read-source'] },
], { categories: ['knowledge'], requireGoals: true, requireSources: true });
console.log(tools.describe(), scopes.normalize('agent-core'));
console.log(scopes.acceptsTool('agent-core', 'explain'), scopes.topics('sdk'));

API reference, usage examples and developer guides.