mirror of
https://github.com/discourse/discourse.git
synced 2026-08-12 03:37:13 +08:00
Previously, workflow fields were only known after execution or from pinned data, limiting editor previews and AI-generated expressions. This change adds versioned, configuration-aware output contracts using JSON Schema. Mostly based on what AI was doing with schemas, but we migrated to JSON schema and adds helpers functions for AI to convert it to the format used by AI.
84 lines
2.3 KiB
Ruby
Vendored
84 lines
2.3 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module DiscourseAssign
|
|
module Workflows
|
|
module Schema
|
|
ASSIGNEE_SCHEMA = {
|
|
"type" => "object",
|
|
"properties" => {
|
|
"type" => {
|
|
"type" => %w[string null],
|
|
},
|
|
"user" => {
|
|
"type" => "object",
|
|
"properties" => DiscourseWorkflows::Schema::BASIC_USER_PROPERTIES,
|
|
},
|
|
"group" => {
|
|
"type" => "object",
|
|
"properties" => DiscourseWorkflows::Schema::BASIC_GROUP_PROPERTIES,
|
|
},
|
|
},
|
|
}.freeze
|
|
|
|
ASSIGN_TOPIC_OUTPUT_SCHEMA = {
|
|
"$schema" => DiscourseWorkflows::Schema::DRAFT_URI,
|
|
"type" => "object",
|
|
"properties" => {
|
|
"assignee" => ASSIGNEE_SCHEMA,
|
|
"previously_assigned" => ASSIGNEE_SCHEMA,
|
|
},
|
|
}.freeze
|
|
|
|
ASSIGNMENT_SCHEMA = {
|
|
"$schema" => DiscourseWorkflows::Schema::DRAFT_URI,
|
|
"type" => "object",
|
|
"properties" => {
|
|
"assignment" => {
|
|
"type" => "object",
|
|
"properties" => {
|
|
"id" => {
|
|
"type" => "integer",
|
|
},
|
|
"target_type" => {
|
|
"type" => "string",
|
|
},
|
|
"target_id" => {
|
|
"type" => "integer",
|
|
},
|
|
"topic_id" => {
|
|
"type" => "integer",
|
|
},
|
|
"topic_assignment" => {
|
|
"type" => "boolean",
|
|
},
|
|
"assigned_to_id" => {
|
|
"type" => "integer",
|
|
},
|
|
"assigned_to_type" => {
|
|
"type" => "string",
|
|
},
|
|
"assigned_to" => ASSIGNEE_SCHEMA,
|
|
"assigned_by_user" => {
|
|
"type" => "object",
|
|
"properties" => DiscourseWorkflows::Schema::BASIC_USER_PROPERTIES,
|
|
},
|
|
"note" => {
|
|
"type" => %w[string null],
|
|
},
|
|
"status" => {
|
|
"type" => %w[string null],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}.freeze
|
|
|
|
ASSIGNED_OUTPUT_SCHEMA =
|
|
DiscourseWorkflows::Schema.merge(
|
|
DiscourseWorkflows::Schema::POST_SCHEMA,
|
|
DiscourseWorkflows::Schema::TOPIC_LIST_ITEM_SCHEMA,
|
|
ASSIGNMENT_SCHEMA,
|
|
).freeze
|
|
end
|
|
end
|
|
end
|