discourse-ai/assets/javascripts/discourse
Sam fdf0ff8a25
FEATURE: persistent key-value storage for AI Artifacts (#1417)
Introduces a persistent, user-scoped key-value storage system for
AI Artifacts, enabling them to be stateful and interactive. This
transforms artifacts from static content into mini-applications that can
save user input, preferences, and other data.

The core components of this feature are:

1.  **Model and API**:
    - A new `AiArtifactKeyValue` model and corresponding database table to
      store data associated with a user and an artifact.
    - A new `ArtifactKeyValuesController` provides a RESTful API for
      CRUD operations (`index`, `set`, `destroy`) on the key-value data.
    - Permissions are enforced: users can only modify their own data but
      can view public data from other users.

2.  **Secure JavaScript Bridge**:
    - A `postMessage` communication bridge is established between the
      sandboxed artifact `iframe` and the parent Discourse window.
    - A JavaScript API is exposed to the artifact as `window.discourseArtifact`
      with async methods: `get(key)`, `set(key, value, options)`,
      `delete(key)`, and `index(filter)`.
    - The parent window handles these requests, makes authenticated calls to the
      new controller, and returns the results to the iframe. This ensures
      security by keeping untrusted JS isolated.

3.  **AI Tool Integration**:
    - The `create_artifact` tool is updated with a `requires_storage`
      boolean parameter.
    - If an artifact requires storage, its metadata is flagged, and the
      system prompt for the code-generating AI is augmented with detailed
      documentation for the new storage API.

4.  **Configuration**:
    - Adds hidden site settings `ai_artifact_kv_value_max_length` and
      `ai_artifact_max_keys_per_user_per_artifact` for throttling.

This also includes a minor fix to use `jsonb_set` when updating
artifact metadata, ensuring other metadata fields are preserved.
2025-06-11 06:59:46 +10:00
..
admin FEATURE: Display features that rely on multiple personas. (#1411) 2025-06-09 16:13:09 -03:00
components FEATURE: persistent key-value storage for AI Artifacts (#1417) 2025-06-11 06:59:46 +10:00
connectors FEATURE: Use different personas to power AI helper features. 2025-06-04 14:23:00 -03:00
controllers FEATURE: hashtag and mention autocomplete for first bot message (#1342) 2025-05-16 16:19:20 +10:00
lib FEATURE: simplify streaming implementation - rush last update (#1380) 2025-05-30 06:50:12 +10:00
routes
services DEV: Add condition for force-conversations-sidebar AppEvent (#1418) 2025-06-10 11:29:38 -05:00
templates FEATURE: hashtag and mention autocomplete for first bot message (#1342) 2025-05-16 16:19:20 +10:00
admin-discourse-ai-plugin-route-map.js
admin-discourse-ai-route-map.js
discourse-ai-bot-dashboard-route-map.js
discourse-ai-shared-conversation-show-route-map.js
preferences-ai-route-map.js