How to Create Custom Context Types
To create a custom context type with Vault Java SDK:
-
Create a Context Type Runtime Handler:
@ExecuteAs(ExecuteAsUser.REQUEST_OWNER) @AiContextTypeRuntimeHandlerInfo(scope = AiScope.DOCUMENT) public class MyContextTypeRuntimeHandler implements AiContextTypeRuntimeHandler{ @Override public AiContextTypeResolveResponse onResolve(AiContextTypeResolveContext context){ AiDocumentScopeSource documentScopeSource = context.getScopeSource(AiScopeType.DOCUMENT); DocumentVersion documentVersion = documentScopeSource.getDocumentVersion(); String documentName = documentVersion.getValue("name__v", ValueType.STRING); AiContextTypeOutputItem contextOutput = context.newOutputItemBuilder() .withText("The current document name is [" + documentName + "]") .build(); return context.newSuccessResponseBuilder() .appendOutputItem(contextOutput) .build(); } } -
Create an
AicontexttyperuntimecodeMDL record referencing theAiContextTypeRuntimeHandler, and create anAicontexttypeMDL record:RECREATE Aicontexttype my_custom_context_type__c ( label('My Context Type'), admin_configurable(true), runtime_code('Aicontexttyperuntimecode.com.veeva.vault.custom.context.MyContextTypeRuntimeHandler') );