Implement tokens support

Created on 26 June 2024, 5 months ago
Updated 23 July 2024, 4 months ago

Problem/Motivation

User should be able to use tokens when configuring segments.

Proposed resolution

These fields should support tokens:

  1. Text segment - text configuration field.
  2. Views segment: "View contextual filters", "View URL parameters" configuration fields.
  3. "Prompt (config storage)" and "Prompt (content storage)" segments should allow to create prompt relationship with tokens. Maybe a new "select" field, where user could choose how to create prompt relationship: with entity autocomplete widget or another widget which allows to enter token. If token evaluates to non-valid entity relationship, segment preview should indicate that segment has broken values and segment should render nothing for a final prompt.

Therefore, in summary, segment configuration should replace values with tokens before render even begins. Token replace has to happen on configuration values.

There has to be straightforward way for developers to add token support to their configuration fields. For example, there has to be available API methods to call for segment plugins in AIPromptSegmentBase:

  1. A method to get "token_tree_link" from token module element to list available tokens (module will now depend on token module).

By default module should provide global tokens, as well as, tokens of aiprompt entity itself (like field values of aiprompt entity etc.). Later more different token types will be added.

Remaining tasks

User interface changes

API changes

New methods under AIPromptSegmentBase

  • public function getPluginConfigTokenized() - get all configuration token replaced.
  • public function getPluginConfigValueTokenized() - get specific configuration value token replaced.
  • public function getAvailableTokensTreeBuildElement() - get form element to render available tokens.
  • public function getAvailableTokensData() - defines available tokens

Data model changes

Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

🇱🇹Lithuania mindaugasd

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024