Skip to content

TypeScript API / @laikacms/server/ai / DecapAiConfig

Interface: DecapAiConfig ​

Configuration for decapAi

Properties ​

authenticateAccessToken ​

ts
authenticateAccessToken: (rawToken) => Promise<User>;

Authenticate a Bearer access token and return the user. This should be the same callback used in @laikacms/server/api, backed by the same resolveBearer seam from laikacms/auth: { ...ctx.user, scopes: ctx.scopes }. Returning scopes lets decapAi enforce requiredScope instead of granting every authenticated user full AI/document access.

Parameters ​

ParameterType
rawTokenstring

Returns ​

Promise<User>


basePath? ​

ts
optional basePath?: string;

Base path for the AI endpoints (default: '/api/ai')


callbacks ​

ts
callbacks: AiSessionCallbacks;

Session storage callbacks


logger? ​

ts
optional logger?: Logger;

Logger instance


maxOutputTokens? ​

ts
optional maxOutputTokens?: number;

Maximum output tokens for response (default: 4096)


messages? ​

ts
optional messages?: object;

Localized messages for error responses and system prompts. If not provided, defaults to English messages.

errors ​

ts
errors: object;
errors.aiProcessingFailed ​
ts
aiProcessingFailed: string = 'AI processing failed';
errors.authenticationFailed ​
ts
authenticationFailed: string = 'Authentication failed';
errors.failedToDeleteSession ​
ts
failedToDeleteSession: string = 'Failed to delete session';
errors.failedToGetSession ​
ts
failedToGetSession: string = 'Failed to get session';
errors.failedToListSessions ​
ts
failedToListSessions: string = 'Failed to list sessions';
errors.insufficientScope ​
ts
insufficientScope: string = 'Insufficient scope for this request';
errors.invalidJsonBody ​
ts
invalidJsonBody: string = 'Invalid JSON body';
errors.methodNotAllowed ​
ts
methodNotAllowed: string = 'Method not allowed';
errors.missingAuthHeader ​
ts
missingAuthHeader: string = 'Missing or invalid Authorization header';
errors.missingDocumentContext ​
ts
missingDocumentContext: string = 'Missing document context';
errors.missingDocumentSlug ​
ts
missingDocumentSlug: string = 'Missing documentSlug query parameter';
errors.missingOrInvalidMessage ​
ts
missingOrInvalidMessage: string = 'Missing or invalid message';
errors.sessionAccessDenied ​
ts
sessionAccessDenied: string = 'Session access denied';
errors.sessionNotFound ​
ts
sessionNotFound: string = 'Session not found';
errors.unknownEndpoint ​
ts
unknownEndpoint: string = 'Unknown AI endpoint: %s';

systemPrompt ​

ts
systemPrompt: string;

Base system prompt - translatable, describes the AI's role


model ​

ts
model: LanguageModel;

LLM model to use (from Vercel AI SDK) Example: openai('gpt-4o'), anthropic('claude-3-5-sonnet-20241022')


requiredScope? ​

ts
optional requiredScope?: Scope;

Scope required to use the AI endpoints (chat + sessions), checked via hasScope against user.scopes when authenticateAccessToken returns one. Users with no scopes (legacy/full-admin sessions per the resolveBearer convention) are always allowed. Defaults to 'content:write' since the AI can edit documents via updateDocument.


systemPrompt? ​

ts
optional systemPrompt?: string;

System prompt for the AI assistant. Replaces the default prompt entirely — the built-in getDocumentData/updateDocument tool guidance is discarded when this is set. To extend the default rather than replace it, use the messages option instead: import en from '@laikacms/server/ai/i18n/en';messages: { ...en, systemPrompt: 'Your prefix.\n\n' + en.systemPrompt }


temperature? ​

ts
optional temperature?: number;

Temperature for response generation (default: 0.7)


tools? ​

ts
optional tools?: ToolSet;

Tools to provide to the AI. Use the standard Vercel AI SDK tool() function to create tools.

Client-side tools (getDocumentData, updateDocument) are executed by the CMS client (see the Dulla transport in laikacms/decap-cms), which is why they carry no execute. Server-side tools should have one.

Example ​

typescript
import { jsonSchema, tool } from '@laikacms/server/ai';

tools: {
  getCmsConfig: tool({
    description: 'Get the CMS configuration',
    inputSchema: jsonSchema({
      type: 'object',
      properties: {},
      additionalProperties: false,
    }),
    execute: async () => ({ configYaml: myConfigYaml }),
  }),
}

Released under the MIT License.