<?xml version="1.0" encoding="UTF-8"?>
<GenericConnectorDescriptor requireConnectionForBrowse="false">
    <description>Send text-based documents to the JEV decision API and receive structured, confidence-gated results.</description>

    <!-- ===================== Connection ===================== -->
    <field id="baseUrl" label="Base URL" type="string">
        <helpText>Root URL of the JEV API, without a trailing path. Example: https://api.typesafe.ai</helpText>
        <defaultValue>https://api.typesafe.ai</defaultValue>
    </field>
    <field id="endpointPath" label="Decision Endpoint Path" type="string">
        <helpText>Path of the decision endpoint, appended to the Base URL.</helpText>
        <defaultValue>/v1/systemone</defaultValue>
    </field>
    <field id="apiKey" label="API Key" type="password">
        <helpText>JEV API key. Sent in the authentication header on every request.</helpText>
    </field>
    <field id="authHeaderName" label="Auth Header Name" type="string">
        <helpText>HTTP header that carries the API key.</helpText>
        <defaultValue>Authorization</defaultValue>
    </field>
    <field id="authScheme" label="Auth Scheme" type="string">
        <helpText>Prefix placed before the API key in the auth header (for example "Bearer"). Leave blank to send the raw key.</helpText>
        <defaultValue>Bearer</defaultValue>
    </field>
    <field id="defaultModel" label="Default Model" type="string">
        <helpText>Model used when the operation does not specify one.</helpText>
        <defaultValue>jev-latest</defaultValue>
    </field>
    <field id="connectTimeoutMs" label="Connect Timeout (ms)" type="integer">
        <defaultValue>10000</defaultValue>
    </field>
    <field id="readTimeoutMs" label="Read Timeout (ms)" type="integer">
        <defaultValue>60000</defaultValue>
    </field>
    <field id="maxRetries" label="Max Retries" type="integer">
        <helpText>Retries for rate limiting (429), server errors (502/503/504) and network failures. Uses exponential backoff and honours Retry-After.</helpText>
        <defaultValue>2</defaultValue>
    </field>

    <testConnection method="CUSTOM"/>

    <!-- ===================== Operation ===================== -->
    <operation types="EXECUTE" customTypeId="REVIEW" customTypeLabel="Review Document" supportsBrowse="true">
        <field id="requestMode" label="Request Mode" type="string">
            <helpText>Document Review: the input document becomes the JEV "state" and the Question Set below is applied. Raw Request: the input document is already a complete JEV request body.</helpText>
            <defaultValue>DOCUMENT_REVIEW</defaultValue>
            <allowedValue label="Document Review">
                <value>DOCUMENT_REVIEW</value>
            </allowedValue>
            <allowedValue label="Raw Request">
                <value>RAW_REQUEST</value>
            </allowedValue>
        </field>
        <field id="questionSet" label="Question Set (JSON)" type="string" displayType="textarea" overrideable="true">
            <helpText>JSON object of questions keyed by ID. Each question needs "type" (choice, score or noul) and "instructions". Choice questions also need "criteria" as an object of option ID to description; score questions need "criteria" as an array of 2 to 10 level descriptions, lowest first. Required in Document Review mode (or supplied per document).</helpText>
            <visibilityCondition>
                <valueCondition fieldId="requestMode">
                    <value>DOCUMENT_REVIEW</value>
                </valueCondition>
            </visibilityCondition>
        </field>
        <field id="model" label="Model" type="string" overrideable="true">
            <helpText>Overrides the connection's Default Model. Leave blank to use the default.</helpText>
        </field>
        <field id="stateFormat" label="Document Format" type="string">
            <helpText>How the input document is sent as state. Auto: valid JSON is sent as JSON, anything else as text. JSON: the document must be valid JSON. Text: always sent as a string.</helpText>
            <defaultValue>AUTO</defaultValue>
            <allowedValue label="Auto-detect">
                <value>AUTO</value>
            </allowedValue>
            <allowedValue label="JSON">
                <value>JSON</value>
            </allowedValue>
            <allowedValue label="Text">
                <value>TEXT</value>
            </allowedValue>
            <visibilityCondition>
                <valueCondition fieldId="requestMode">
                    <value>DOCUMENT_REVIEW</value>
                </valueCondition>
            </visibilityCondition>
        </field>
        <field id="stateKey" label="State Wrapper Key" type="string">
            <helpText>Optional. When set, the document is wrapped as {"&lt;key&gt;": document} before it is sent as state.</helpText>
            <visibilityCondition>
                <valueCondition fieldId="requestMode">
                    <value>DOCUMENT_REVIEW</value>
                </valueCondition>
            </visibilityCondition>
        </field>
        <field id="confidenceThreshold" label="Confidence Threshold" type="string" overrideable="true">
            <helpText>Number between 0 and 1. Any answer below it marks the document NEEDS_REVIEW instead of DECIDED. Leave blank to disable gating.</helpText>
            <defaultValue>0.8</defaultValue>
        </field>
        <field id="includeRawResponse" label="Include Raw JEV Response" type="boolean">
            <helpText>Adds the unmodified JEV response under "raw" in the output document.</helpText>
            <defaultValue>false</defaultValue>
        </field>
        <field id="maxDocumentSizeKb" label="Max Document Size (KB)" type="integer">
            <helpText>Documents larger than this are rejected before calling JEV.</helpText>
            <defaultValue>1024</defaultValue>
        </field>
        <field id="maxConcurrentRequests" label="Max Concurrent Requests" type="integer">
            <helpText>How many JEV requests may be in flight at once when several documents reach the shape together. 1 sends them one after another. Higher values (up to 16) process the documents in groups of that size, in parallel, and return results in the original order. If the runtime does not allow worker threads, the connector logs a warning and sends requests one at a time.</helpText>
            <defaultValue>1</defaultValue>
        </field>
        <field id="setDocumentProperties" label="Set Document Properties" type="boolean">
            <helpText>Adds the result as dynamic document properties on each output document: jevStatus, jevModel, jevReviewReasons, jevInputTokens, jevOutputTokens, and per question jev_&lt;id&gt;, jev_&lt;id&gt;_confidence, jev_&lt;id&gt;_passed and jev_&lt;id&gt;_level (score). Use them in Decision, Route or Map shapes without a profile.</helpText>
            <defaultValue>false</defaultValue>
        </field>
        <field id="keepOriginalDocument" label="Keep Original Document" type="boolean">
            <helpText>Also stores the input document text in the dynamic document property jevOriginalDocument, because the output document replaces it.</helpText>
            <defaultValue>false</defaultValue>
            <visibilityCondition>
                <valueCondition fieldId="setDocumentProperties">
                    <value>true</value>
                </valueCondition>
            </visibilityCondition>
        </field>
        <field id="setTrackedProperties" label="Set Tracked Properties" type="boolean">
            <helpText>Records JEV Status, Model, Summary, Review Reasons and token counts as tracked properties, so they appear in Process Reporting.</helpText>
            <defaultValue>false</defaultValue>
        </field>
        <trackedProperty id="jevStatus" label="JEV Status"/>
        <trackedProperty id="jevModel" label="JEV Model"/>
        <trackedProperty id="jevSummary" label="JEV Summary"/>
        <trackedProperty id="jevReviewReasons" label="JEV Review Reasons"/>
        <trackedProperty id="jevInputTokens" label="JEV Input Tokens"/>
        <trackedProperty id="jevOutputTokens" label="JEV Output Tokens"/>
    </operation>

    <!-- Per-document values, set with a Set Properties shape (Connectors > JEV). They take precedence over the operation. -->
    <dynamicProperty id="jevQuestionSet" label="JEV Question Set (JSON)" type="string"/>
    <dynamicProperty id="jevModel" label="JEV Model" type="string"/>
    <dynamicProperty id="jevConfidenceThreshold" label="JEV Confidence Threshold" type="string"/>
</GenericConnectorDescriptor>
