@dawn-ai/sdk

Use this when

Start here when you build a Dawn application. @dawn-ai/sdk owns the route-authoring types and helpers most application code uses. Reach for /pure only when an integration needs dependency-free path or hash utilities, and /testing when you author route scenarios for dawn test.

Install and import

bash
pnpm add @dawn-ai/sdk
ts
import { agent, defineMiddleware, defineMemory } from "@dawn-ai/sdk"
import { pureJoin } from "@dawn-ai/sdk/pure"
import { scenarios } from "@dawn-ai/sdk/testing"

Compatibility and audience

SurfaceRuntimePurityAudienceStability
@dawn-ai/sdkedge-safenot-claimedapplicationsupported
@dawn-ai/sdk/pureedge-safedependency-freeintegrationsupported
@dawn-ai/sdk/testingnode-onlynot-claimedtestingsupported

@dawn-ai/sdk/testing is the route-scoped scenario API used by dawn test; it is not the @dawn-ai/testing package, which provides a programmatic agent harness.

Public exports

@dawn-ai/sdk

ExportResponsibility
AgentConfigConfigure an agent route.
ConstraintContextDescribe the live context passed to a tool constraint.
ConstraintPredicateValidate one tool call before execution.
ConstraintVerdictExpress a constraint decision.
DawnAgentRepresent an authored agent route.
DelegationConfigConfigure subagent delegation policy.
DelegationConstraintPredicateValidate a delegated request.
DelegationContextDescribe a delegated request's live context.
DelegationRequestDescribe a delegated input.
DelegationRuleExpress one named delegation policy.
DelegationRulesMap subagent names to delegation policy.
DelegationVerdictExpress a delegation constraint decision.
ReasoningConfigConfigure model reasoning effort.
RetryConfigConfigure model-call retry attempts and delay.
SubagentMapMap local subagent names to agents.
ToolScopeSelect and gate route tools.
agentDeclare an agent route.
isDawnAgentTest whether a value is an authored Dawn agent.
BackendAdapterDefine a route backend adapter contract.
DawnErrorCodeName a registered Dawn error.
DawnErrorDescriptorDescribe a registered Dawn error.
DAWN_ERRORSRead the error descriptor registry.
describeErrorLook up an error descriptor.
errorDocsUrlBuild the documentation URL for an error code.
AnthropicModelIdName a curated Anthropic model.
GoogleModelIdName a curated Google model.
KnownModelIdOffer curated model autocomplete while accepting custom string IDs.
OpenAiModelIdName a curated OpenAI model.
XaiModelIdName a curated xAI model.
ANTHROPIC_MODEL_IDSList curated Anthropic model IDs.
CURATED_MODEL_IDSMap curated providers to model IDs.
GOOGLE_MODEL_IDSList curated Google model IDs.
OPENAI_MODEL_IDSList curated OpenAI model IDs.
XAI_MODEL_IDSList curated xAI model IDs.
DefinedMemoryRepresent a typed memory declaration.
MemoryScopeDimensionDefine one typed memory namespace dimension.
defineMemoryDeclare a typed long-term memory schema.
ContinueResultContinue middleware execution with optional context.
DawnMiddlewareDefine the middleware function contract.
MiddlewareRequestDescribe a middleware request.
MiddlewareResultExpress a middleware decision.
RejectResultStop middleware execution with a response.
allowContinue middleware execution.
defineMiddlewarePreserve types for a middleware function.
rejectStop middleware execution.
DawnThreadAccessDefine one thread-access action handler.
ThreadAccessAllowExpress an allow decision, optionally stamping a thread on create.
ThreadAccessDenyExpress a deny decision with an optional status and body.
ThreadAccessPolicyDeclare per-action thread authorization handlers.
ThreadAccessRequestDescribe the thread request being authorized.
ThreadAccessResultExpress a thread authorization decision.
ThreadActionName the coarse thread action being authorized.
ThreadOperationName the specific endpoint operation being authorized.
ThreadSubjectDescribe the thread a decision is made about.
THREAD_ACCESS_METADATA_KEYName the reserved metadata key holding the server-issued access stamp.
defineThreadAccessPreserve types for a thread access policy.
denyRefuse a thread request.
permitAllow a thread request, optionally stamping it on create.
BuiltInModelProviderIdName a built-in model provider.
ModelProviderIdName a built-in or custom model provider.
inferProviderInfer a provider from a model ID.
SUPPORTED_AGENT_PROVIDERSList providers built into agent materialization.
RouteConfigDescribe route metadata.
RouteKindName a supported route kind.
RouteStateMapExpose an open compatibility interface for route state.
RouteToolMapExpose an open compatibility interface for route tools.
RuntimeContextProvide request-scoped runtime data.
RuntimeToolDescribe a runtime tool callable.
ToolRegistryMap runtime tool names to callables.
PrettifyFlatten an object type for editor display.
ModelIdValidationRepresent advisory model-ID validation.
validateModelIdCheck a model ID against curated suggestions.
DawnToolContextProvide context to a Dawn tool.
WorkspaceFsDefine the workspace filesystem contract exposed to tools.

@dawn-ai/sdk/pure

ExportResponsibility
POSIX_SEPExpose the portable path separator.
pureBasenameRead the last path component.
pureDirnameRead the parent path.
pureJoinJoin path segments without Node dependencies.
pureRelativeCompute one portable relative path.
pureResolveResolve portable path segments.
sha1HexCompute a SHA-1 hexadecimal digest.
sha256HexCompute a SHA-256 hexadecimal digest.

@dawn-ai/sdk/testing

ExportResponsibility
RouteScenarioMapReceive generated route-to-tool augmentation.
RuntimeErrorExpectationDescribe an expected scenario error.
RuntimeExecutionBaseResultShare fields across scenario execution results.
RuntimeExecutionErrorDescribe a failed execution error.
RuntimeExecutionErrorKindName a runtime failure kind.
RuntimeExecutionFailureResultRepresent a failed execution.
RuntimeExecutionModeName the materialized route mode.
RuntimeExecutionResultRepresent either execution outcome.
RuntimeExecutionSuccessResultRepresent a successful execution.
RuntimeExecutionTimingDescribe execution timing.
RuntimeMetaExpectationDescribe expected runtime metadata.
ScenarioDescriptorRepresent one authored scenario.
ScenarioSuiteBuilderBuild route-scoped scenarios fluently.
ScenarioSuiteDescriptorRepresent a completed scenario suite.
ScenarioToolCallExpectationDescriptorDescribe an expected tool call.
ScenarioToolCallRecordRecord an observed tool call.
ScenarioToolMockDescriptorDescribe a mocked tool response.
expectErrorAssert a failed runtime result.
expectMetaAssert selected runtime metadata.
expectOutputAssert a successful runtime output.
isScenarioSuiteTest whether a value is a scenario suite.
readScenarioSuiteRead a scenario suite descriptor.
scenariosStart a typed scenario suite for a route.

Key contracts

agent() and AgentConfig

Use agent() as a route module's default export. model and systemPrompt are required; optional policy, retry, reasoning, subagent, and tool fields are preserved on the branded descriptor.

ts
export declare function agent<const Subagents extends SubagentMap = {}>(
  config: AgentConfig<Subagents>,
): DawnAgent<Subagents>
ts
export interface AgentConfig<Subagents extends SubagentMap = {}> {
  readonly delegation?: DelegationConfig<NoInfer<Extract<keyof Subagents, string>>>
  readonly description?: string
  readonly model: KnownModelId
  readonly provider?: ModelProviderId
  readonly reasoning?: ReasoningConfig
  readonly retry?: RetryConfig
  readonly recursionLimit?: number
  readonly subagents?: Subagents
  readonly tools?: ToolScope
  readonly systemPrompt: string
}

Fields: @dawn-ai/sdk#.:AgentConfig

FieldTypeRequiredDescription
readonly delegationDelegationConfig<NoInfer<Extract<keyof Subagents, string>>>noControl dispatch to named subagents.
readonly descriptionstringnoDescribe the agent for selection.
readonly modelKnownModelIdyesSelect the model.
readonly providerModelProviderIdnoOverride provider inference.
readonly reasoningReasoningConfignoTune reasoning effort.
readonly retryRetryConfignoTune transient retry behavior.
readonly recursionLimitnumbernoCap LangGraph super-steps.
readonly subagentsSubagentsnoRegister child agents by name.
readonly toolsToolScopenoScope and gate tools.
readonly systemPromptstringyesSet the agent's system instruction.

Behavior contract sdk.agent.descriptor-shape

agent() returns a branded descriptor and includes optional tool scope only when supplied.

Exact agent configuration signatures

ts
export interface ReasoningConfig {
  readonly effort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh"
}

Fields: @dawn-ai/sdk#.:ReasoningConfig

FieldTypeRequiredDescription
readonly effort"none" | "minimal" | "low" | "medium" | "high" | "xhigh"noSet the model reasoning budget.
ts
export interface RetryConfig {
  readonly maxAttempts?: number
  readonly baseDelay?: number
}

Fields: @dawn-ai/sdk#.:RetryConfig

FieldTypeRequiredDescription
readonly maxAttemptsnumbernoCap attempts for a model call.
readonly baseDelaynumbernoSet the base retry delay.
ts
export declare function isDawnAgent(value: unknown): value is DawnAgent

allow() and reject()

Middleware returns an explicit continue or reject result. Use allow(context?) to continue and reject(status, body?) to stop the request.

ts
export declare function defineMiddleware(fn: DawnMiddleware): DawnMiddleware
ts
export declare function allow(context?: Record<string, unknown>): ContinueResult
ts
export declare function reject(status: number, body?: unknown): RejectResult

Behavior contract sdk.middleware.result-shapes

allow() and reject() return discriminated result objects; omitted context and body properties are absent.

validateModelId()

Use this helper to improve author feedback for likely model-ID typos. It does not restrict custom model IDs.

ts
export declare function validateModelId(opts: {
  readonly model: string
  readonly provider?: string
}): ModelIdValidation

Behavior contract sdk.validate-model-id.advisory

Model validation is advisory: curated near-misses return provider-specific suggestions, while an uncurated or unresolved provider returns ok: true.

Application guidance

Treat ok: false as a warning for application feedback, not a runtime gate.

RouteConfig

runtime, streaming, and tags are reserved metadata and do not change execution today. Select deployment runtime with build.targets, select streaming through the endpoint or transport, and do not rely on tags for behavior.

ts
export interface RouteConfig {
  readonly runtime?: "node" | "edge"
  readonly streaming?: boolean
  readonly tags?: readonly string[]
}

Fields: @dawn-ai/sdk#.:RouteConfig

FieldTypeRequiredDescription
readonly runtime"node" | "edge"noReserved; has no effect.
readonly streamingbooleannoReserved; has no effect.
readonly tagsreadonly string[]noReserved; has no effect.

defineMemory()

Declare the typed schema, kind, and namespace dimensions for a route's memory.ts module. identity is optional; semantic memory defaults its reconciliation identity elsewhere.

ts
export declare function defineMemory<S extends z.ZodTypeAny>(def: {
  kind: DefinedMemory["kind"]
  scope: readonly MemoryScopeDimension[]
  schema: S
  identity?: readonly string[]
}): DefinedMemory<S>

Choosing a surface

Application routes normally import the root. Use /pure for infrastructure that must avoid runtime dependencies. Use /testing in *.scenario.ts files; use @dawn-ai/testing when a test needs a programmatic harness instead. Its detailed reference lands with the testing package page.

ts
import { agent } from "@dawn-ai/sdk"
 
export default agent({
  model: "gpt-5-mini",
  systemPrompt: "Answer concisely.",
})

Continue with Agents, Middleware, Long-term Memory, Scenario Testing, and Agent Test Harness.