Type-Safe Agents: Leveraging apcore-js in TypeScript
While Python dominates the AI research space, TypeScript is the engine of the modern full-stack web. From high-performance Node.js backends to complex React frontends, TypeScript provides the structure and safety that large-scale engineering teams demand. When we built the apcore-js SDK, we didn't just want to "port" the Python logic. We wanted to create a first-class, type-safe experience that leverages the unique strengths of the JavaScript ecosystem. In this twentieth article of our series, we explore how to build AI-Perceivable modules in TypeScript using apcore and TypeBox . The Goal: Cross-Language Parity A core tenet of the apcore protocol is that a module’s behavior should be identical regardless of the implementation language. A module named executor.user.get must accept the same JSON input and produce the same output in both Python and TypeScript. apcore-js achieves this by using TypeBox as its core schema engine. TypeBox allows us to define JSON Schemas that double as TypeScript types, giving us compile-time safety and runtime validation in a single definition. Defining Type-Safe Schemas In apcore-js, you define your module's contract using TypeBox's Static and Type primitives: import { Type , Static } from ' @sinclair/typebox ' ; export const InputSchema = Type . Object ({ userId : Type . String ({ description : " The unique UUID of the user. " }), includePrivate : Type . Boolean ({ default : false , description : " Whether to include sensitive fields. " }) }); export type Input = Static < typeof InputSchema > ; By adding the description field directly into the TypeBox definition, you are creating the "Cognitive Interface" for the AI while simultaneously providing type hints for your IDE. Building the Module apcore-js supports both class-based and functional module definitions. The class-based approach is idiomatic for TypeScript developers: import { ClassModule , ModuleAnnotations , Context } from ' @apcore/core ' ; export class GetUserModule extends Cl