Skip to content
Changelog

Report a bug

SDK Reference

@type-dot-com/sdk is the official TypeScript SDK for Type. Use it to write code automations, custom webhook adapters, and scripts that call the Type API.

Terminal window
bun add @type-dot-com/sdk zod@4 neverthrow@8

The SDK runs in Bun. It also includes ESM JavaScript and type declarations for Node 22 or later. Install zod and neverthrow directly, because automation code imports them.

  • Type typechecks your code against its own SDK when you deploy. A deploy can fail even if your local typecheck passes.
  • The npm release can be older than the SDK in Type. Some exports, for example SlackMessageEvent and replyInSlackThread, are in Type before they are on npm. If an import is missing locally, deploy to check it, or use the type from this reference.
  • Type records the automation API version for each saved revision. If a later Type release changes the API, Type marks older automations as upgrade_available or unsupported. See Create and Manage Automations.

Automation code runs in a QuickJS VM, not in Node or Bun. It can import only these modules:

ModuleUse it for
@type-dot-com/sdkTypeApiError and shared types.
@type-dot-com/sdk/automationsAutomation types and helpers.
@type-dot-com/sdk/webhooksWebhook adapter types and helpers. Use it in adapter files.
zodSchemas.
neverthrowResult, ResultAsync, ok, and err.
Relative files, for example ./format.tsYour own modules in the same project.

These are not available: fetch, Node APIs, Bun APIs, the file system, a shell, other npm packages, and compiler macros. Use ctx.tools, ctx.read, and ctx.write for network access. Use sandbox commands for shell work.

Import pathContents
@type-dot-com/sdkThe Type API client, TypeApiError, defineAutomation and defineTask for skill scripts, z, and shared types.
@type-dot-com/sdk/automationsCode automation types, event contracts, and helpers. See below.
@type-dot-com/sdk/webhooksIntegrationWebhook, webhookEvent(), and adapter context types. See Webhook Adapter API.
@type-dot-com/sdk/rpccreateTypeRpcClient(), the client that Type CLI uses.
@type-dot-com/sdk/contracts/*Zod wire schemas, for example contracts/api and contracts/automation-matchers.
@type-dot-com/sdk/apps, /apps/react, /apps/templatesThe SDK for Type Apps. React and Convex are optional peer dependencies.
ExportKindMeaning
AutomationDeploymentTypeThe shape of the deployment export. See Deployment API.
DeploymentSubscriptionTypeOne entry in deployment.subscriptions.
AutomationContextTypeThe ctx argument. See Context reference.
RecurringEventType{ scheduledAt: string }. The event for a recurring source.
IntegrationEvent<Data>TypeThe envelope of an integration event.
SlackMessageEventTypeA Slack message event.
AutomationCheckpointType{ value, version }.
AutomationExecutionIdentityTypeThe fields of ctx.identity.
AutomationMutationOptionsType{ effectKey, signal?, timeoutMs? } for writes.
AutomationMatcherTypeThe match field.
AutomationDebounceTypeThe debounce field.
AutomationExpirationTypeThe expiration field.
IntegrationEventSource, RecurringSourceTypeThe source field.
AutomationJevRequest, AutomationJevResultTypeAI questions and answers.
Action, ActionLog, AutomationActionsTypectx.action and ctx.mutativeAction.
SubscriptionHandlers<Events>TypeMaps subscription keys to method signatures.
ExportMeaning
replyInSlackThread(ctx, event, { connectionId, text, effectKey? })Replies in the Slack thread of the message that started the run. Resolves to { channelId, threadTs, ts }. The default effect key is slack-reply:<channel>:<ts>.
slackMessageEventSchemaThe Zod schema for SlackMessageEvent.

replyInSlackThread posts under the message, or in the thread that the message is already in. It fails if Slack does not confirm that the reply is in that thread. In a fixture, its request is:

{
"service": "slack",
"name": "slack_post_message",
"organizationIntegrationId": "orgint_...",
"arguments": { "channel_id": "C0123456789", "thread_ts": "1712345678.000100", "text": "..." }
}

These Zod schemas validate the same shapes on the server. Use them for your own checks.

automationDebounceSchema, automationExpirationSchema, automationMatcherSchema, automationJevRequestSchema, automationJevResultSchema, integrationEventSourceSchema, recurringSourceSchema, recurringEventSchema, subscriptionDefinitionSchema, automationManifestSchema.

The module also exports Automation, integrationEvent(), recurring(), SubscribedAutomation, PureCodeAutomation, CanTriggerAgentAutomation, and WillAlwaysTriggerAgentAutomation. These are for automations that were saved in older formats. Do not use them in new code. Use the deployment export and a default class.

All SDK errors are TypeApiError objects.

class TypeApiError extends Error {
readonly code: TypeErrorCode;
readonly status?: number; // HTTP status, if any
readonly details?: unknown; // structured API details, if any
get isVersionConflict(): boolean; // true for HTTP 409 version_conflict
}
codeMeaning
configurationThe client has a missing or wrong setting.
authenticationType did not accept the credentials.
networkThe request did not get a response. A write can still be complete.
timeoutThe request took too long. A write can still be complete.
abortedThe signal stopped the request.
invalid_responseThe response did not match the expected shape or your schema.
http_errorType returned an HTTP error. Read status and details.
invalid_inputThe input was not valid.

Create your own errors with the same class:

return err(new TypeApiError("The order has no ID", "invalid_response"));

See Errors for messages that the deploy and the runtime return.

Type is a client for the Type agent HTTP API. Use it in scripts and skill code, not in automation code. In automation code, use ctx, which gives the same operations with automation access checks.

import { Type } from "@type-dot-com/sdk";
const type = Type.fromEnvironment(process.env);
const result = await type.search.workspace("quarterly plan");
if (result.isErr()) console.error(result.error.code, result.error.message);
ResourceOperations
dataread, record, list, delete, withSchema
toolsservices, find, call, callWithSchema
integrationssearch, connect, request, requestWithSchema, webhooks
skillslist, create, update, delete, files, readFile, addFile, updateFile, deleteFile, versions
taskslist, get, create, update, testCode, delete
spaceslist, messages
threadslist, messages, batch
searchworkspace, messages
messagessend
  • Each method accepts a last argument { signal, timeoutMs }. The default timeout is 60 seconds.
  • The client does not retry. After a timeout or a network error, a write can still be complete.
  • Type.fromEnvironment() reads TYPE_SERVER_URL, TYPE_ACCESS_TOKEN, TYPE_AGENT_ID, TYPE_CHANNEL_ID, and TYPE_AUTOMATION_ID.
  • tasks.delete archives the task. It does not delete it permanently.

defineAutomation and defineTask from @type-dot-com/sdk are for skill scripts. They are not code automations. A skill script runs when an agent or a person runs the skill. A code automation runs on a schedule or an event. To make a code automation, use the deployment export and a default class.