Skip to content

Commit 082b838

Browse files
committed
Plugins as resources #73
1 parent 12efbd1 commit 082b838

File tree

40 files changed

+2911
-262
lines changed

40 files changed

+2911
-262
lines changed

Cargo.lock

Lines changed: 543 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

atomic-plugin/src/bindings.rs

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ pub mod atomic {
557557
use super::super::super::_rt;
558558
pub type ResourceJson = super::super::super::atomic::class_extender::types::ResourceJson;
559559
#[allow(unused_unsafe, clippy::all)]
560+
/// Returns a resource by subject.
560561
pub fn get_resource(
561562
subject: &str,
562563
agent: Option<&str>,
@@ -679,6 +680,7 @@ pub mod atomic {
679680
}
680681
}
681682
#[allow(unused_unsafe, clippy::all)]
683+
/// Returns a list of resources that match the query.
682684
pub fn query(
683685
property: &str,
684686
value: &str,
@@ -866,6 +868,43 @@ pub mod atomic {
866868
result5
867869
}
868870
}
871+
#[allow(unused_unsafe, clippy::all)]
872+
/// Returns the JSON config of the plugin as a string. The user can edit this config at any time.
873+
pub fn get_config() -> _rt::String {
874+
unsafe {
875+
#[cfg_attr(target_pointer_width = "64", repr(align(8)))]
876+
#[cfg_attr(target_pointer_width = "32", repr(align(4)))]
877+
struct RetArea(
878+
[::core::mem::MaybeUninit<
879+
u8,
880+
>; 2 * ::core::mem::size_of::<*const u8>()],
881+
);
882+
let mut ret_area = RetArea(
883+
[::core::mem::MaybeUninit::uninit(); 2
884+
* ::core::mem::size_of::<*const u8>()],
885+
);
886+
let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
887+
#[cfg(target_arch = "wasm32")]
888+
#[link(wasm_import_module = "atomic:class-extender/[email protected]")]
889+
unsafe extern "C" {
890+
#[link_name = "get-config"]
891+
fn wit_import1(_: *mut u8);
892+
}
893+
#[cfg(not(target_arch = "wasm32"))]
894+
unsafe extern "C" fn wit_import1(_: *mut u8) {
895+
unreachable!()
896+
}
897+
unsafe { wit_import1(ptr0) };
898+
let l2 = *ptr0.add(0).cast::<*mut u8>();
899+
let l3 = *ptr0
900+
.add(::core::mem::size_of::<*const u8>())
901+
.cast::<usize>();
902+
let len4 = l3;
903+
let bytes4 = _rt::Vec::from_raw_parts(l2.cast(), len4, len4);
904+
let result5 = _rt::string_lift(bytes4);
905+
result5
906+
}
907+
}
869908
}
870909
}
871910
}
@@ -935,8 +974,8 @@ pub(crate) use __export_class_extender_impl as export;
935974
#[unsafe(link_section = "component-type:wit-bindgen:0.41.0:atomic:[email protected]:class-extender:encoded world")]
936975
#[doc(hidden)]
937976
#[allow(clippy::octal_escapes)]
938-
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 950] = *b"\
939-
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xb1\x06\x01A\x02\x01\
977+
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 965] = *b"\
978+
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xc0\x06\x01A\x02\x01\
940979
A\x17\x01B\x0b\x01r\x01\x07subjects\x04\0\x0catomic-agent\x03\0\0\x01r\x02\x07su\
941980
bjects\x07json-ads\x04\0\x0dresource-json\x03\0\x02\x01p\x03\x01r\x02\x07primary\
942981
\x03\x0areferenced\x04\x04\0\x11resource-response\x03\0\x05\x01r\x04\x0brequest-\
@@ -945,18 +984,18 @@ t\x03\0\x07\x01r\x03\x07subjects\x0bcommit-jsons\x08snapshot\x03\x04\0\x0ecommit
945984
-context\x03\0\x09\x03\0!atomic:class-extender/[email protected]\x05\0\x02\x03\0\0\x11\
946985
resource-response\x03\0\x11resource-response\x03\0\x01\x02\x03\0\0\x0bget-contex\
947986
t\x03\0\x0bget-context\x03\0\x03\x02\x03\0\0\x0ecommit-context\x03\0\x0ecommit-c\
948-
ontext\x03\0\x05\x02\x03\0\0\x0dresource-json\x02\x03\0\0\x0catomic-agent\x01B\x0e\
987+
ontext\x03\0\x05\x02\x03\0\0\x0dresource-json\x02\x03\0\0\x0catomic-agent\x01B\x0f\
949988
\x02\x03\x02\x01\x07\x04\0\x0dresource-json\x03\0\0\x02\x03\x02\x01\x08\x04\0\x0c\
950989
atomic-agent\x03\0\x02\x01ks\x01j\x01\x01\x01s\x01@\x02\x07subjects\x05agent\x04\
951990
\0\x05\x04\0\x0cget-resource\x01\x06\x01p\x01\x01j\x01\x07\x01s\x01@\x03\x08prop\
952991
ertys\x05values\x05agent\x04\0\x08\x04\0\x05query\x01\x09\x01@\0\0s\x04\0\x10get\
953-
-plugin-agent\x01\x0a\x03\0\x20atomic:class-extender/[email protected]\x05\x09\x01ps\x01\
954-
@\0\0\x0a\x04\0\x09class-url\x01\x0b\x01k\x02\x01j\x01\x0c\x01s\x01@\x01\x03ctx\x04\
955-
\0\x0d\x04\0\x0fon-resource-get\x01\x0e\x01j\0\x01s\x01@\x01\x03ctx\x06\0\x0f\x04\
956-
\0\x0dbefore-commit\x01\x10\x04\0\x0cafter-commit\x01\x10\x04\0*atomic:class-ext\
957-
ender/[email protected]\x04\0\x0b\x14\x01\0\x0eclass-extender\x03\0\0\0G\x09p\
958-
roducers\x01\x0cprocessed-by\x02\x0dwit-component\x070.227.1\x10wit-bindgen-rust\
959-
\x060.41.0";
992+
-plugin-agent\x01\x0a\x04\0\x0aget-config\x01\x0a\x03\0\x20atomic:class-extender\
993+
/[email protected]\x05\x09\x01ps\x01@\0\0\x0a\x04\0\x09class-url\x01\x0b\x01k\x02\x01j\x01\
994+
\x0c\x01s\x01@\x01\x03ctx\x04\0\x0d\x04\0\x0fon-resource-get\x01\x0e\x01j\0\x01s\
995+
\x01@\x01\x03ctx\x06\0\x0f\x04\0\x0dbefore-commit\x01\x10\x04\0\x0cafter-commit\x01\
996+
\x10\x04\0*atomic:class-extender/[email protected]\x04\0\x0b\x14\x01\0\x0ecla\
997+
ss-extender\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x07\
998+
0.227.1\x10wit-bindgen-rust\x060.41.0";
960999
#[inline(never)]
9611000
#[doc(hidden)]
9621001
pub fn __link_custom_section_describing_imports() {

atomic-plugin/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ pub fn query(
167167
})?
168168
}
169169

170+
pub fn get_config<'a, T>() -> Result<T, String>
171+
where
172+
T: for<'de> Deserialize<'de>,
173+
{
174+
let config_str = host::get_config();
175+
serde_json::from_str::<T>(&config_str)
176+
.map_err(|e| format!("Failed to deserialize config: {}", e))
177+
}
178+
170179
impl TryFrom<ResourceJson> for Resource {
171180
type Error = String;
172181

atomic-plugin/src/packaging.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ pub mod packaging_impl {
8080
.unix_permissions(0o755);
8181

8282
// Add WASM
83-
// Rename to [namespace].[name].wasm
84-
let wasm_filename = format!("{}.{}.wasm", namespace, name);
85-
zip.start_file(&wasm_filename, options)?;
83+
zip.start_file("plugin.wasm", options)?;
8684
let mut wasm_file = File::open(&wasm_path).context("Failed to open WASM file")?;
8785
let mut buffer = Vec::new();
8886
wasm_file.read_to_end(&mut buffer)?;
@@ -94,7 +92,6 @@ pub mod packaging_impl {
9492
zip.write_all(descriptor_content.as_bytes())?;
9593

9694
// Add Assets
97-
// Rename assets folder to [namespace]
9895
if assets_path.exists() {
9996
let walk = WalkDir::new(&assets_path);
10097
for entry in walk {
@@ -105,8 +102,8 @@ pub mod packaging_impl {
105102
}
106103

107104
let relative_path = path.strip_prefix(&assets_path)?;
108-
// Place inside [namespace]/...
109-
let zip_path = Path::new(namespace).join(relative_path);
105+
// Place inside assets/...
106+
let zip_path = Path::new("assets").join(relative_path);
110107
let zip_path_str = zip_path.to_string_lossy();
111108

112109
zip.start_file(zip_path_str, options)?;

atomic-plugin/wit/class-extender.wit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ package atomic:[email protected];
33
interface host {
44
use types.{resource-json, atomic-agent};
55

6+
// Returns a resource by subject.
67
get-resource: func(subject: string, agent: option<string>) -> result<resource-json, string>;
8+
// Returns a list of resources that match the query.
79
query: func(property: string, value: string, agent: option<string>) -> result<list<resource-json>, string>;
810
get-plugin-agent: func() -> string;
11+
// Returns the JSON config of the plugin as a string. The user can edit this config at any time.
12+
get-config: func() -> string;
913
}
1014

1115
interface types {

browser/data-browser/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@
5050
"@tomic/react": "workspace:*",
5151
"@uiw/codemirror-theme-github": "^4.25.3",
5252
"@uiw/react-codemirror": "^4.25.3",
53-
"@wuchale/jsx": "^0.9.5",
54-
"@wuchale/vite-plugin": "^0.15.3",
53+
"@wuchale/jsx": "^0.10.1",
54+
"@wuchale/vite-plugin": "^0.16.3",
55+
"@zip.js/zip.js": "^2.8.15",
5556
"ai": "^5.0.101",
5657
"clsx": "^2.1.1",
58+
"codemirror-json-schema": "^0.8.1",
5759
"downshift": "^9.0.10",
5860
"emoji-mart": "^5.6.0",
5961
"ollama-ai-provider-v2": "^1.5.5",
@@ -77,7 +79,7 @@
7779
"remark-gfm": "^4.0.1",
7880
"styled-components": "^6.1.19",
7981
"stylis": "4.3.0",
80-
"wuchale": "^0.18.5",
82+
"wuchale": "^0.19.4",
8183
"y-protocols": "^1.0.6",
8284
"yjs": "^13.6.27",
8385
"zod": "^4.1.13"

0 commit comments

Comments
 (0)