package golem:agent;

interface common {
  use golem:rpc/types@0.2.2.{value-and-type, wit-type, wit-value};

  type url = string;

  enum agent-mode {
    durable,
    ephemeral
  }

  record agent-type {
    type-name:    string,
    description:  string,
    %constructor: agent-constructor,
    methods:      list<agent-method>,
    dependencies: list<agent-dependency>,
    mode:         agent-mode,
  }

  record agent-dependency {
    type-name:    string,
    description:  option<string>,
    %constructor: agent-constructor,
    methods:      list<agent-method>,
  }

  record agent-method {
    name:          string,
    description:   string,
    prompt-hint:   option<string>,
    input-schema:  data-schema,
    output-schema: data-schema,
  }

  record agent-constructor {
    name:          option<string>,
    description:   string,
    prompt-hint:   option<string>,
    input-schema:  data-schema,
  }

  variant data-schema {
    /// List of named elements
    %tuple(list<tuple<string, element-schema>>),
    /// List of named variants that can be used 0 or more times in a multimodal `data-value`
    multimodal(list<tuple<string, element-schema>>),
  }

  variant data-value {
    /// List of element values, each corresponding to an element of the tuple `data-schema`
    %tuple(list<element-value>),
    /// List of element values and their schema names; each name points to one named element of the corresponding
    /// multimodal `data-schema`.
    multimodal(list<tuple<string, element-value>>),
  }

  variant element-schema {
    component-model(wit-type),
    unstructured-text(text-descriptor),
    unstructured-binary(binary-descriptor),
  }

  variant element-value {
    component-model(wit-value),
    unstructured-text(text-reference),
    unstructured-binary(binary-reference),
  }

  record text-type {
    language-code: string,
  }

  variant text-reference {
    url(string),
    inline(text-source),
  }

  record text-source {
    data:      string,
    text-type: option<text-type>,
  }

  record text-descriptor {
    restrictions: option<list<text-type>>,
  }

  record binary-descriptor {
    restrictions: option<list<binary-type>>,
  }

  record binary-type {
    mime-type: string,
  }

  variant binary-reference {
    url(url),
    inline(binary-source),
  }

  record binary-source {
    data:        list<u8>,
    binary-type: binary-type,
  }

  variant agent-error {
    invalid-input(string),
    invalid-method(string),
    invalid-type(string),
    invalid-agent-id(string),
    custom-error(value-and-type),
  }
}
