Agent SDK · Start here

Configuration.

Configure the shared core, or isolate a Runner with its own client and auth.

configureClient(options)

Configures the default MatildaCore singleton used by defaultRunner and the convenience functions (run, stream, streamText, runText). Returns nothing.

TypeScript
import { configureClient } from '@maincode-ai/matilda-agent-sdk';

configureClient({
  baseUrl: 'https://matilda.maincode.com/api',
  getToken: async () => myAccessToken,
});

Options

Extends ClientConfig. All fields are optional except baseUrl.

Fieldtypedescription
baseUrlstringThe Matilda API base URL. Must be absolute for auth flows. Defaults to '/api'.
accessTokenstringA static access token. Use for quick testing only — prefer managed auth.
getTokenGetTokenDynamic token provider. Called on every request. The SDK's TokenManager implements this.
apiVersionstring | nullAPI version sent via the X-Matilda-API-Version header. Omit to use the current version.
urlPolicyTrustedApiBaseUrlPolicyURL validation policy for trustApiBaseUrl().
getCsrfToken() => string | nullCSRF token provider for web BFF cookie auth.

MatildaCore

The underlying API client. The agent SDK re-exports it from @matilda/api-client. Each Runner can hold its own MatildaCore instance for isolation, or share the process-wide default.

TypeScript
import { MatildaCore, Runner } from '@maincode-ai/matilda-agent-sdk';

const core = new MatildaCore({
  baseUrl: 'https://matilda.maincode.com/api',
  accessToken: process.env.MATILDA_ACCESS_TOKEN!,
});

const runner = new Runner({ core });

Runner

The main agent execution class. Optionally accepts an explicit MatildaCore for isolation.

TypeScript
import { Runner, MatildaCore } from '@maincode-ai/matilda-agent-sdk';

// Uses the default core singleton (configured via configureClient)
const defaultRunner = new Runner();

// Uses an isolated core — independent config, auth, and token lifecycle
const isolatedRunner = new Runner({
  core: new MatildaCore({ baseUrl: 'https://matilda.maincode.com/api' }),
});
Fieldtypedescription
coreMatildaCoreOptional explicit core. If omitted, the default singleton is used.

Environment URLs

EnvironmentBase URL
Productionhttps://matilda.maincode.com/api

Instance isolation

Each Runner holds its own MatildaCore (either explicit or the default singleton). Resources (auth, files, conversations, feedback) resolve their core lazily, so configureClient() replacing the default singleton is picked up correctly.

TypeScript
import { Runner, MatildaCore, configureClient } from '@maincode-ai/matilda-agent-sdk';

const runnerA = new Runner({
  core: new MatildaCore({ baseUrl: 'https://matilda.maincode.com/api' }),
});
const runnerB = new Runner({
  core: new MatildaCore({ baseUrl: 'https://matilda.maincode.com/api' }),
});

// Each runner is fully isolated — independent auth, config, and token lifecycle
await runnerA.auth.loginWithDeviceFlow({ clientId: 'matilda-code' });
await runnerB.auth.loginWithBrowser({ clientId: 'matilda-code' });

Other re-exported configuration utilities

ExportDescription
configureClient(options)Configure the default MatildaCore singleton.
getClientConfig()Get the current default core's config.
getDefaultCore()Get the default MatildaCore singleton.
trustApiBaseUrl(rawUrl, policy?)Validate and brand a URL as a trusted API base URL.
MATILDA_API_VERSION_HEADERThe API version header name.
MATILDA_CURRENT_API_VERSIONThe current API version string.