contracts.ts
Source: sdks/typescript/packages/sdk/src/contracts.ts. Back to the TypeScript SDK reference index.
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:
| Name | Type | Required | Description |
|---|---|---|---|
path | string | yes | JSON pointer of the invalid value (/ for the root). |
message | string | yes | Status message (up to 2000 characters). |
keyword | string | yes | JSON Schema keyword that failed. |
Interface ContractValidationResult
Result of a contract validation: validity and errors.
Fields:
| Name | Type | Required | Description |
|---|---|---|---|
valid | boolean | yes | Whether the document is valid. |
errors | ContractIssue[] | yes | Validation 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:
| Name | Type | Required | Description |
|---|---|---|---|
name | string | yes | Name of the contract (ContractName). |
title | string | yes | Title of the contract. |
kind | string | null | yes | Manifest kind matched by the contract, or null for a contract that is not a manifest. |
type | string | yes | Type of the contract, as listed in contracts/index.json. |
file | string | yes | Schema file of the contract (for example v1/agent-manifest.schema.json). |
example | string | yes | Example 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.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
name | ContractName | string | yes | Name 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.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
name | ContractName | string | yes | Name of the contract (ContractName), such as agent-manifest. | |
doc | unknown | yes | Document to validate. | |
locale | Locale | "en" | no | Language 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.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
name | N | yes | Name of the contract (ContractName), such as agent-manifest. | |
doc | unknown | yes | Document to validate. | |
locale | Locale | "en" | no | Language 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).
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
kind | ManifestKind | string | yes | Manifest 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.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
doc | Manifest | Record<string, unknown> | yes | Manifest to validate. | |
locale | Locale | "en" | no | Language of the error messages (en by default). |
Returns: ContractValidationResult. Validity and errors (ContractValidationResult); an unknown kind gives an error on /kind.