Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 5d95ed0

Browse files
committed
storage api in update strategy
fix incorrect drift in artifact controller
1 parent 581a25d commit 5d95ed0

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

app/controllers/discourse_ai/ai_bot/artifacts_controller.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ def show
2020
end
2121

2222
name = artifact.name
23+
artifact_version = nil
2324

2425
if params[:version].present?
25-
artifact = artifact.versions.find_by(version_number: params[:version])
26-
raise Discourse::NotFound if !artifact
26+
artifact_version = artifact.versions.find_by(version_number: params[:version])
27+
raise Discourse::NotFound if !artifact_version
2728
end
2829

29-
untrusted_html = build_untrusted_html(artifact, name)
30-
trusted_html = build_trusted_html(artifact, name, untrusted_html)
30+
untrusted_html = build_untrusted_html(artifact_version || artifact, name)
31+
trusted_html = build_trusted_html(artifact, artifact_version, name, untrusted_html)
3132

3233
set_security_headers
3334
render html: trusted_html.html_safe, layout: false, content_type: "text/html"
@@ -57,7 +58,7 @@ def build_untrusted_html(artifact, name)
5758
HTML
5859
end
5960

60-
def build_trusted_html(artifact, name, untrusted_html)
61+
def build_trusted_html(artifact, artifact_version, name, untrusted_html)
6162
<<~HTML
6263
<!DOCTYPE html>
6364
<html>

lib/personas/artifact_update_strategies/base.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ def apply(&progress)
3131
apply_changes(parsed_changes)
3232
end
3333

34+
def storage_api
35+
if @artifact.metadata.is_a?(Hash) && @artifact.metadata["requires_storage"]
36+
DiscourseAi::Personas::Tools::CreateArtifact.storage_api
37+
end
38+
end
39+
3440
private
3541

3642
def generate_changes(&progress)

lib/personas/artifact_update_strategies/diff.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ def system_prompt
186186
JavaScript libraries must be sourced from the following CDNs, otherwise CSP will reject it:
187187
#{AiArtifact::ALLOWED_CDN_SOURCES.join("\n")}
188188
189+
#{storage_api}
190+
189191
Reply Format:
190192
[HTML]
191193
(changes or empty if no changes or entire HTML)

lib/personas/artifact_update_strategies/full.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ def system_prompt
7676
JavaScript libraries must be sourced from the following CDNs, otherwise CSP will reject it:
7777
#{AiArtifact::ALLOWED_CDN_SOURCES.join("\n")}
7878
79+
#{storage_api}
80+
7981
Always adhere to the format when replying:
8082
8183
[HTML]

0 commit comments

Comments
 (0)