How do I pass data to an artifact?

Any tips on how to pass data to the artifact? I want to paste the same artifact many place in my forum, using a different JWT token in each place. I’ve been trying things like this but can’t get the creator to use it:


<div class="ai-artifact" data-jwt-token="my-jwt-token" data-ai-artifact-id="10"></div>

Or if the Web Creator could figure out what topic id it’s in, I could work with that.

2 Likes

Oh this is a tricky one, no this is not something the framework allows at the moment, it is a very interesting use case.

I like the feature request here of just passing along all data- attributes into the sandboxed artifact, it is an elegant solution.

One option that may work though is to lean on query params, but the sandboxed iframe had no access to that:

https://meta.discourse.org/discourse-ai/ai-bot/artifacts/166?222

@david do you think there is any security implication to passing in information about the outside world to an artifact? (leave sandbox, but I guess echo window.location.search into some sort of attribute?

3 Likes

Giving the artefact access to the query string sounds ok. Easiest thing would be to use Ruby to inject it into the untrusted html document. Maybe as a meta tag or something.

3 Likes

It was the bot’s idea. :slight_smile:

I would think it’s a very common use case for real-world artifacts. I have a financial analysis artifact that I want to run against many investments. The artifact pulls the performance data from an API, using the JWT to identify which investment. Making many different artifacts, each with a different hardcoded JWT, is a non-starter.

Not to push my luck, but if I could also get the user id and topic id in the artifact, that would open up a lot more applications.

2 Likes

topic id is easy to add, but user id can get a tiny bit more tricky, cause the artifact is heavily cached, we would have to reduce some of the caching to make that happen.

That would actually be better for my application than passing data attributes. There’s a 1:1 mapping between topics and my JWTs, so I can look up the JWT, without having to edit the JWT in each post.

That probably doesn’t handle other use cases though.

Technically, just passing the URL solves this, cause the topic id is part of the URL

Will sort this out next week, working on PDF support atm :slight_smile: