Skip to main content

contracts.ts

Source: sdks/typescript/packages/sdk/src/contracts.ts. Back to the TypeScript SDK reference index.

note

This page is generated by tools/docs/gen_sdk_reference.py from the SDK sources and the OpenAPI text folders. Do not edit it by hand: change the source and regenerate.

Interface ContractIssue​

Validation error of a document against a contract.

Fields:

NameTypeRequiredDescription
pathstringyesJSON pointer of the invalid value (/ for the root).
messagestringyesStatus message (up to 2000 characters).
keywordstringyesJSON Schema keyword that failed.

Interface ContractValidationResult​

Result of a contract validation: validity and errors.

Fields:

NameTypeRequiredDescription
validbooleanyesWhether the document is valid.
errorsContractIssue[]yesValidation errors (ContractIssue), empty when the document is valid.

Interface ContractInfo​

Entry of contracts/index.json: name, title, manifest kind, type, schema file and example.

Fields:

NameTypeRequiredDescription
namestringyesName of the contract (ContractName).
titlestringyesTitle of the contract.
kindstring | nullyesManifest kind matched by the contract, or null for a contract that is not a manifest.
typestringyesType of the contract, as listed in contracts/index.json.
filestringyesSchema file of the contract (for example v1/agent-manifest.schema.json).
examplestringyesExample document of the contract, as listed in contracts/index.json.

Type alias CONTRACTS​

Entries of contracts/index.json bundled with the SDK, one ContractInfo per contract.

Definition: readonly ContractInfo[].

Functions​

getContractSchema​

getContractSchema(name: ContractName | string): Record<string, unknown> | undefined

Returns the bundled JSON Schema of a contract.

NameTypeDefaultRequiredDescription
nameContractName | stringyesName of the contract (ContractName), such as agent-manifest.

Returns: Record<string, unknown> \| undefined. JSON Schema of the contract, or undefined for an unknown name.

validateContract​

validateContract(name: ContractName | string, doc: unknown, locale: Locale = "en"): ContractValidationResult

Validates a document against a v1 contract using the schemas bundled with the SDK.

NameTypeDefaultRequiredDescription
nameContractName | stringyesName of the contract (ContractName), such as agent-manifest.
docunknownyesDocument to validate.
localeLocale"en"noLanguage of the error messages (en by default).

Returns: ContractValidationResult. Validity and errors (ContractValidationResult); throws ContractValidationError for an unknown contract.

Raises: ContractValidationError.

assertContract​

assertContract(name: N, doc: unknown, locale: Locale = "en"): ContractTypes[N]

Validates and throws ContractValidationError when the document is invalid.

NameTypeDefaultRequiredDescription
nameNyesName of the contract (ContractName), such as agent-manifest.
docunknownyesDocument to validate.
localeLocale"en"noLanguage of the error messages (en by default).

Returns: ContractTypes[N]. A ContractTypes: Maps each contract name of contracts/index.json to its TypeScript model.

Raises: ContractValidationError.

contractForKind​

contractForKind(kind: ManifestKind | string): ContractName | undefined

Finds the manifest contract matching a kind (Agent, Model, Tool, Skill, Plugin, Connector, Channel).

NameTypeDefaultRequiredDescription
kindManifestKind | stringyesManifest kind, such as Agent.

Returns: ContractName \| undefined. Name of the matching contract, or undefined when no contract has this kind.

validateManifest​

validateManifest(doc: Manifest | Record<string, unknown>, locale: Locale = "en"): ContractValidationResult

Validates a manifest by detecting its contract from kind.

NameTypeDefaultRequiredDescription
docManifest | Record<string, unknown>yesManifest to validate.
localeLocale"en"noLanguage of the error messages (en by default).

Returns: ContractValidationResult. Validity and errors (ContractValidationResult); an unknown kind gives an error on /kind.