Skip to content
Agentpost robot in sunglasses on a red circleAgentpost

Event types

client.eventTypes reads and manages the type registry. Every method takes its request and returns the contract’s typed response. Use a project’s secret key for changes; a workspace key with the client’s project option can only list and get types.

The examples use request.assigned from the EventWolf quickstart.

Read types

import { createClient } from '@agentpost-tools/eventwolf-sdk';

const client = createClient({ token: process.env.AGENTPOST_SECRET_KEY });
const page = await client.eventTypes.list({ origin: 'registered', limit: 20 });
const { eventType } = await client.eventTypes.get('request.assigned');

list takes optional origin, status, after, and limit. When the page has next, pass it as after with the same filters to read the next page. get returns the type with every schema version.

Register or update a type

const registered = await client.eventTypes.put('request.assigned', {
  description: 'A request assigned to a person',
  schema: {
    type: 'object',
    required: ['assignee'],
    properties: {
      assignee: {
        type: 'object',
        required: ['id'],
        properties: { id: { type: 'string' } },
      },
    },
  },
  refPaths: { 'assignee.id': { type: 'user' } },
});

An omitted field keeps its value. A different schema makes a new version; schema: null removes the current schema, and refPaths: null removes the reference paths. The answer holds eventType.

Check a schema

const checked = await client.eventTypes.validate('request.assigned', {
  items: [{ data: { assignee: { id: 'u_ana' } } }],
});
const first = checked.items[0];

validate checks 1 to 200 items without writing anything. Send {} for an event without data. Pass schema to try a candidate schema, or omit it to use the type’s current schema. If the type has no current schema, you must pass one. The answer includes the schema source and one { valid, issues } in items per event, in the order sent.

To check a candidate schema against the type’s newest stored events, checkRecent reads them with events.query and checks their data in one validate call. count is how many to read, 1 to 200, and is required. Reading events takes read access to them.

const recent = await client.eventTypes.checkRecent('request.assigned', {
  schema: {
    type: 'object',
    required: ['assignee'],
    properties: {
      assignee: {
        type: 'object',
        required: ['id'],
        properties: { id: { type: 'string', minLength: 1 } },
      },
    },
  },
  count: 50,
});
const rejected = recent.events.filter((e) => !e.valid);

The answer holds events, newest first, each with its sequence, id, valid, and issues, and the schema the check used. When the type has no stored events, events is empty and nothing is sent to check.

Deprecate a type

const deprecated = await client.eventTypes.deprecate('request.assigned');

The answer holds eventType with status: 'deprecated'. Its events are still accepted and checked.

Errors

These methods take the same optional CallOptions as the other JSON calls, such as { signal }. Pass { idempotencyKey } to put or deprecate to retry a write, as Retrying a write describes. validate and checkRecent write nothing and need no idempotency key. A method throws EventwolfApiError when the API answers with an error. With a workspace key, the API answers forbidden to put, validate, and deprecate, and to the validation call that checkRecent makes when it finds events. The event types reference has every field and error.