kind: AdaptiveDialog
beginDialog:
  kind: OnRecognizedIntent
  id: trigger_fQ8t2Lp
  intent:
    displayName: Compare the direct Word renderer
    triggerQueries:
      - Run a direct Word renderer comparison
      - Test the direct Word connector with synthetic fields
      - Create a renderer-only direct Word sample
  actions:
    - kind: SendActivity
      id: send_bN4w7Hx
      activity: |-
        This is a DIRECT WORD RENDERER-ONLY comparison, not generative drafting from rough notes.

        I will validate supplied synthetic content against the same eighteen-field contract, then pass the plain text to the Word connector. This method does not populate the controlled Word template and does not establish equivalent layout or styles. The reference criteria remain TDB-TECHNICAL-DESIGN-001 v0.1, a PROPOSED POC STANDARD.

        A sample is created only after your separate confirmation. It remains a DRAFT for human review in the demo OneDrive root, with existing access only. I will not move, delete, publish or change sharing.

    - kind: Question
      id: question_mV6r3Dz
      variable: init:Topic.RawDraft
      prompt: Paste the approved synthetic eighteen-field JSON object for this renderer-only comparison, with plain-text string values and no credentials, HTML, Markdown markup, RTF, encoded file data or file links. This input is supplied test content, not evidence of agent generation. Type cancel to stop.
      entity: StringPrebuiltEntity
      alwaysPrompt: true
      interruptionPolicy:
        allowInterruption: false

    - kind: ConditionGroup
      id: condition_kY9p4Cs
      conditions:
        - id: branch_rE3u8Wn
          condition: =Lower(Trim(Topic.RawDraft)) = "cancel"
          actions:
            - kind: SendActivity
              id: send_sT7a2Jv
              activity: Cancelled the direct Word comparison. No connector call or file creation was requested.
            - kind: EndDialog
              id: end_dL5x9Qh
        - id: branch_pB6m2Fg
          condition: =IsBlank(Trim(Topic.RawDraft)) || Len(Topic.RawDraft) > 100000
          actions:
            - kind: SendActivity
              id: send_uR8c3Ka
              activity: The comparison input must be non-empty JSON of at most 100,000 characters. No Word call was requested and nothing was truncated.
            - kind: EndDialog
              id: end_aH4v7Nz

    - kind: ParseValue
      id: parse_yM2k6Tp
      variable: Topic.Draft
      value: =Topic.RawDraft
      errorPolicy: DefaultBlank
      valueType:
        kind: Record
        properties:
          DocumentTitle: String
          ProjectName: String
          DocumentOwner: String
          PreparedDate: String
          DocumentVersion: String
          IntendedAudience: String
          ExecutiveSummary: String
          PurposeAndScope: String
          Requirements: String
          Architecture: String
          InterfacesAndData: String
          SecurityAndCompliance: String
          DeploymentAndRollback: String
          OperationsAndSupport: String
          TestingAndAcceptance: String
          RisksAssumptionsDecisions: String
          SourcesAndReferences: String
          ReviewActions: String

    - kind: SetVariable
      id: set_vC9e3Rw
      variable: init:Topic.ExactFieldSet
      value: |-
        =IfError(
          CountRows(ColumnNames(ParseJSON(Topic.RawDraft))) = 18 &&
          CountIf(ColumnNames(ParseJSON(Topic.RawDraft)),
            !(Value in ["DocumentTitle", "ProjectName", "DocumentOwner", "PreparedDate", "DocumentVersion", "IntendedAudience", "ExecutiveSummary", "PurposeAndScope", "Requirements", "Architecture", "InterfacesAndData", "SecurityAndCompliance", "DeploymentAndRollback", "OperationsAndSupport", "TestingAndAcceptance", "RisksAssumptionsDecisions", "SourcesAndReferences", "ReviewActions"])
          ) = 0,
          false
        )

    - kind: SetVariable
      id: set_gJ4n8Xb
      variable: init:Topic.AllFieldsAreStrings
      value: |-
        =IfError(
          CountIf(
            ColumnNames(ParseJSON(Topic.RawDraft)),
            !StartsWith(JSON(Column(ParseJSON(Topic.RawDraft), Value)), Char(34)) ||
            !EndsWith(JSON(Column(ParseJSON(Topic.RawDraft), Value)), Char(34))
          ) = 0,
          false
        )

    - kind: SetVariable
      id: set_wF7q2Ld
      variable: init:Topic.Fields
      value: |-
        =Table(
          {Name: "DocumentTitle", Content: Topic.Draft.DocumentTitle, Limit: 180},
          {Name: "ProjectName", Content: Topic.Draft.ProjectName, Limit: 180},
          {Name: "DocumentOwner", Content: Topic.Draft.DocumentOwner, Limit: 180},
          {Name: "PreparedDate", Content: Topic.Draft.PreparedDate, Limit: 40},
          {Name: "DocumentVersion", Content: Topic.Draft.DocumentVersion, Limit: 40},
          {Name: "IntendedAudience", Content: Topic.Draft.IntendedAudience, Limit: 240},
          {Name: "ExecutiveSummary", Content: Topic.Draft.ExecutiveSummary, Limit: 3000},
          {Name: "PurposeAndScope", Content: Topic.Draft.PurposeAndScope, Limit: 5000},
          {Name: "Requirements", Content: Topic.Draft.Requirements, Limit: 7000},
          {Name: "Architecture", Content: Topic.Draft.Architecture, Limit: 7000},
          {Name: "InterfacesAndData", Content: Topic.Draft.InterfacesAndData, Limit: 5000},
          {Name: "SecurityAndCompliance", Content: Topic.Draft.SecurityAndCompliance, Limit: 5000},
          {Name: "DeploymentAndRollback", Content: Topic.Draft.DeploymentAndRollback, Limit: 5000},
          {Name: "OperationsAndSupport", Content: Topic.Draft.OperationsAndSupport, Limit: 5000},
          {Name: "TestingAndAcceptance", Content: Topic.Draft.TestingAndAcceptance, Limit: 5000},
          {Name: "RisksAssumptionsDecisions", Content: Topic.Draft.RisksAssumptionsDecisions, Limit: 5000},
          {Name: "SourcesAndReferences", Content: Topic.Draft.SourcesAndReferences, Limit: 4000},
          {Name: "ReviewActions", Content: Topic.Draft.ReviewActions, Limit: 4000}
        )

    - kind: SetVariable
      id: set_zP5t8Ma
      variable: init:Topic.InvalidFields
      value: =Filter(Topic.Fields, IsBlank(Trim(Content)) || Len(Content) > Limit)

    - kind: ConditionGroup
      id: condition_hD3v9Ke
      conditions:
        - id: branch_jS6r2Qx
          condition: =Topic.ExactFieldSet <> true || Topic.AllFieldsAreStrings <> true || CountRows(Topic.InvalidFields) > 0
          actions:
            - kind: SendActivity
              id: send_nA8f4Uc
              activity: |-
                The renderer-only input is not a valid eighteen-field draft. Every exact field must be a non-empty JSON string within its contract limit, with no additional keys.

                Missing, blank or over-limit fields: {Concat(Topic.InvalidFields, Name, ", ")}.

                No Word connector call was requested. Correct the supplied test input and start a new comparison; I will not coerce types, drop fields or truncate content.
            - kind: EndDialog
              id: end_eW2m7By

    - kind: SetVariable
      id: set_qK4z8Vf
      variable: init:Topic.CaseId
      value: =Text(GUID())
    - kind: SetVariable
      id: set_sB7q4Nv
      variable: init:Topic.FileBaseName
      value: ="TDB-DIRECT-DRAFT-" & Topic.CaseId
    - kind: SetVariable
      id: set_xG9b3Nr
      variable: init:Topic.FileName
      value: =Topic.FileBaseName & ".docx"
    - kind: SetVariable
      id: set_cU6p2Hs
      variable: init:Topic.WordContent
      value: |-
        ="DIRECT WORD RENDERER-ONLY COMPARISON" & Char(10) &
        "DRAFT - HUMAN REVIEW REQUIRED" & Char(10) &
        "Method: Word Online (Business) CreateWordFileWithContent" & Char(10) &
        "Case: " & Topic.CaseId & Char(10) &
        "Reference criteria: TDB-TECHNICAL-DESIGN-001 v0.1 - PROPOSED POC STANDARD" & Char(10) &
        "This sample uses supplied synthetic test content. It is not proof of generative drafting or controlled-template fidelity." & Char(10) & Char(10) &
        Concat(Topic.Fields, Name & ":" & Char(10) & Content, Char(10) & Char(10))

    - kind: Question
      id: question_tE5w9Jk
      variable: init:Topic.ConfirmCreate
      prompt: |-
        Create exactly one renderer-only Word DRAFT named {Topic.FileName} in the DEMO OneDrive root?

        Confirm this is approved synthetic plain-text test content without credentials or encoded documents. The sample will remain where the connector creates it for human review. This does not approve the content, prove template fidelity, change permissions, move/delete files or publish anything. Choose No to cancel.
      entity: BooleanPrebuiltEntity
      alwaysPrompt: true
      interruptionPolicy:
        allowInterruption: false

    - kind: ConditionGroup
      id: condition_bR7n3Pw
      conditions:
        - id: branch_fL2c8Dm
          condition: =Topic.ConfirmCreate <> true
          actions:
            - kind: SendActivity
              id: send_aV9k4Yq
              activity: Cancelled. No direct Word call or new sample was requested.
            - kind: EndDialog
              id: end_mC6s2Xg

    - kind: InvokeConnectorAction
      id: word_rQ8u5Jn
      displayName: Create one direct Word renderer-only comparison sample
      connectionReference: tdb_WordRenderer
      connectionProperties:
        mode: Maker
      operationId: CreateWordFileWithContent
      input:
        binding:
          content: |-
            =Topic.WordContent
          fileName: =Topic.FileBaseName
      output:
        kind: SingleVariableOutputBinding
        variable: Topic.DirectFileUrl

    - kind: ConditionGroup
      id: condition_pH4x7Tb
      conditions:
        - id: branch_sN3e9Vz
          condition: =!IsBlank(Topic.DirectFileUrl) && StartsWith(Topic.DirectFileUrl, "https://")
          actions:
            - kind: SendActivity
              id: send_dF6m2Kc
              activity: |-
                The direct Word connector returned a document URL for this RENDERER-ONLY comparison.

                [Open the returned Word sample]({Topic.DirectFileUrl})

                Requested filename: {Topic.FileName}
                Method: CreateWordFileWithContent, plain-text input
                Comparison case: {Topic.CaseId}
                Native destination: DEMO OneDrive root

                The connector contract returns a URL, not a file ID; no file ID has been invented. Verify the actual filename, file metadata, content and formatting at the authenticated link and record them with this case.

                The sample is retained in place with existing access. It is a DRAFT for human review, not proof of agent-generated content or controlled-template fidelity. No move, cleanup, approval, publishing or sharing change was requested.
      elseActions:
        - kind: SendActivity
          id: send_kB8r3Ue
          activity: |-
            The direct Word response did not contain a usable HTTPS document URL. I cannot confirm an artifact and will not invent a link.

            Requested filename: {Topic.FileName}
            Method: CreateWordFileWithContent, renderer-only
            Comparison case: {Topic.CaseId}

            No retry, deletion or cleanup was requested. If creation may have completed, investigate this exact case before retrying; do not enumerate or move unrelated files.
    - kind: EndDialog
      id: end_vM5a9Rx
