Skip to content
2 min read · 453 words

Class: Identity ​

Defined in: src/lib/classes/identity.ts:129

An immutable, validated participant identity attached to a @nhtio/adk!Message.

Remarks ​

Carries two distinct representations of the same participant: identifier is the system-facing key (e.g. a database ID) used to correlate messages programmatically; representation is what the model sees when it needs to distinguish between participants sharing the same role. The representation is always a @nhtio/adk!Tokenizable so token cost can be estimated inline.

Constructors ​

Constructor ​

ts
new Identity(raw: RawIdentity): Identity;

Defined in: src/lib/classes/identity.ts:174

Parameters ​

ParameterTypeDescription
rawRawIdentityThe raw identity input validated against rawIdentitySchema.

Returns ​

Identity

Throws ​

@nhtio/adk!E_INVALID_INITIAL_IDENTITY_VALUE when raw does not satisfy the schema.

Properties ​

PropertyModifierTypeDefault valueDescriptionDefined in
identifierreadonlystring | numberundefinedThe system-facing identifier for this participant — never sent to the model directly.src/lib/classes/identity.ts:159
representationreadonlyTokenizableundefinedHow this participant is presented to the model, as a @nhtio/adk!Tokenizable for inline token estimation.src/lib/classes/identity.ts:165
schemastaticAlternativesSchema<any>identityOrRawIdentitySchemaValidator schema that accepts a RawIdentity object OR an existing Identity instance. Remarks Reusable fragment for any schema that needs to validate or nest an identity — for example, as a required field inside a message schema. A locally branded Identity passes through unchanged (its private state is preserved, so it still encodes losslessly); foreign/cross-realm identities and plain RawIdentity values are validated field-by-field and rebuilt locally. See identityOrRawIdentitySchema.src/lib/classes/identity.ts:140

Methods ​

[ENCODE_METHOD]() ​

ts
ENCODE_METHOD: unknown;

Defined in: src/lib/classes/identity.ts:214

Serialise this Identity into an @nhtio/encoder snapshot.

Returns ​

unknown

A RawIdentity-shaped snapshot.

Remarks ​

Emits a RawIdentity-shaped object; representation is the live @nhtio/adk!Tokenizable instance (the encoder recurses into it). Round-trips via Identity.[DECODE_METHOD], which re-validates through the constructor.


[DECODE_METHOD]() ​

ts
static DECODE_METHOD: Identity;

Defined in: src/lib/classes/identity.ts:227

Reconstruct an Identity from an Identity.[ENCODE_METHOD] snapshot.

Parameters ​

ParameterTypeDescription
dataunknownThe snapshot produced by Identity.[ENCODE_METHOD].

Returns ​

Identity

A fully-validated Identity.


isIdentity() ​

ts
static isIdentity(value: unknown): value is Identity;

Defined in: src/lib/classes/identity.ts:152

Returns true if value is an Identity instance.

Parameters ​

ParameterTypeDescription
valueunknownThe value to test.

Returns ​

value is Identity

true when value is an Identity instance.

Remarks ​

Uses @nhtio/adk!isInstanceOf for cross-realm safety — instanceof would fail for instances created in a different module copy or VM context.