Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T04:49:32.637Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

since_v0_0_6.rs

206 lines · 6.1 KB · rust
1use super::{latest, since_v0_1_0, since_v0_6_0};
2use crate::wasm_host::WasmState;
3use anyhow::Result;
4use extension::WorktreeDelegate;
5use gpui::BackgroundExecutor;
6use semver::Version;
7use std::sync::{Arc, OnceLock};
8use wasmtime::component::{Linker, Resource};
9
10pub const MIN_VERSION: Version = Version::new(0, 0, 6);
11
12wasmtime::component::bindgen!({
13    imports: {
14        default: async | trappable,
15    },
16    exports: {
17        default: async,
18    },
19    path: "../extension_api/wit/since_v0.0.6",
20    with: {
21        "worktree": ExtensionWorktree,
22        "zed:extension/github": since_v0_6_0::zed::extension::github,
23        "zed:extension/lsp": since_v0_1_0::zed::extension::lsp,
24        "zed:extension/nodejs": latest::zed::extension::nodejs,
25        "zed:extension/platform": since_v0_6_0::zed::extension::platform,
26    },
27});
28
29mod settings {
30    #![allow(dead_code)]
31    include!(concat!(env!("OUT_DIR"), "/since_v0.0.6/settings.rs"));
32}
33
34pub type ExtensionWorktree = Arc<dyn WorktreeDelegate>;
35
36pub fn linker(executor: &BackgroundExecutor) -> &'static Linker<WasmState> {
37    static LINKER: OnceLock<Linker<WasmState>> = OnceLock::new();
38    LINKER.get_or_init(|| {
39        super::new_linker(executor, |linker| {
40            Extension::add_to_linker::<_, WasmState>(linker, |s| s)
41        })
42    })
43}
44
45impl From<Command> for latest::Command {
46    fn from(value: Command) -> Self {
47        Self {
48            command: value.command,
49            args: value.args,
50            env: value.env,
51        }
52    }
53}
54
55impl From<SettingsLocation> for latest::SettingsLocation {
56    fn from(value: SettingsLocation) -> Self {
57        Self {
58            worktree_id: value.worktree_id,
59            path: value.path,
60        }
61    }
62}
63
64impl From<LanguageServerInstallationStatus> for latest::LanguageServerInstallationStatus {
65    fn from(value: LanguageServerInstallationStatus) -> Self {
66        match value {
67            LanguageServerInstallationStatus::None => Self::None,
68            LanguageServerInstallationStatus::Downloading => Self::Downloading,
69            LanguageServerInstallationStatus::CheckingForUpdate => Self::CheckingForUpdate,
70            LanguageServerInstallationStatus::Failed(message) => Self::Failed(message),
71        }
72    }
73}
74
75impl From<DownloadedFileType> for latest::DownloadedFileType {
76    fn from(value: DownloadedFileType) -> Self {
77        match value {
78            DownloadedFileType::Gzip => Self::Gzip,
79            DownloadedFileType::GzipTar => Self::GzipTar,
80            DownloadedFileType::Zip => Self::Zip,
81            DownloadedFileType::Uncompressed => Self::Uncompressed,
82        }
83    }
84}
85
86impl From<Range> for latest::Range {
87    fn from(value: Range) -> Self {
88        Self {
89            start: value.start,
90            end: value.end,
91        }
92    }
93}
94
95impl From<CodeLabelSpan> for latest::CodeLabelSpan {
96    fn from(value: CodeLabelSpan) -> Self {
97        match value {
98            CodeLabelSpan::CodeRange(range) => Self::CodeRange(range.into()),
99            CodeLabelSpan::Literal(literal) => Self::Literal(literal.into()),
100        }
101    }
102}
103
104impl From<CodeLabelSpanLiteral> for latest::CodeLabelSpanLiteral {
105    fn from(value: CodeLabelSpanLiteral) -> Self {
106        Self {
107            text: value.text,
108            highlight_name: value.highlight_name,
109        }
110    }
111}
112
113impl From<CodeLabel> for latest::CodeLabel {
114    fn from(value: CodeLabel) -> Self {
115        Self {
116            code: value.code,
117            spans: value.spans.into_iter().map(Into::into).collect(),
118            filter_range: value.filter_range.into(),
119        }
120    }
121}
122
123impl HostWorktree for WasmState {
124    async fn id(&mut self, delegate: Resource<Arc<dyn WorktreeDelegate>>) -> wasmtime::Result<u64> {
125        latest::HostWorktree::id(self, delegate).await
126    }
127
128    async fn root_path(
129        &mut self,
130        delegate: Resource<Arc<dyn WorktreeDelegate>>,
131    ) -> wasmtime::Result<String> {
132        latest::HostWorktree::root_path(self, delegate).await
133    }
134
135    async fn read_text_file(
136        &mut self,
137        delegate: Resource<Arc<dyn WorktreeDelegate>>,
138        path: String,
139    ) -> wasmtime::Result<Result<String, String>> {
140        latest::HostWorktree::read_text_file(self, delegate, path).await
141    }
142
143    async fn shell_env(
144        &mut self,
145        delegate: Resource<Arc<dyn WorktreeDelegate>>,
146    ) -> wasmtime::Result<EnvVars> {
147        latest::HostWorktree::shell_env(self, delegate).await
148    }
149
150    async fn which(
151        &mut self,
152        delegate: Resource<Arc<dyn WorktreeDelegate>>,
153        binary_name: String,
154    ) -> wasmtime::Result<Option<String>> {
155        latest::HostWorktree::which(self, delegate, binary_name).await
156    }
157
158    async fn drop(&mut self, _worktree: Resource<Worktree>) -> Result<()> {
159        // We only ever hand out borrows of worktrees.
160        Ok(())
161    }
162}
163
164impl ExtensionImports for WasmState {
165    async fn get_settings(
166        &mut self,
167        location: Option<self::SettingsLocation>,
168        category: String,
169        key: Option<String>,
170    ) -> wasmtime::Result<Result<String, String>> {
171        latest::ExtensionImports::get_settings(
172            self,
173            location.map(|location| location.into()),
174            category,
175            key,
176        )
177        .await
178    }
179
180    async fn set_language_server_installation_status(
181        &mut self,
182        server_name: String,
183        status: LanguageServerInstallationStatus,
184    ) -> wasmtime::Result<()> {
185        latest::ExtensionImports::set_language_server_installation_status(
186            self,
187            server_name,
188            status.into(),
189        )
190        .await
191    }
192
193    async fn download_file(
194        &mut self,
195        url: String,
196        path: String,
197        file_type: DownloadedFileType,
198    ) -> wasmtime::Result<Result<(), String>> {
199        latest::ExtensionImports::download_file(self, url, path, file_type.into()).await
200    }
201
202    async fn make_file_executable(&mut self, path: String) -> wasmtime::Result<Result<(), String>> {
203        latest::ExtensionImports::make_file_executable(self, path).await
204    }
205}
206
Served at tenant.openagents/omega Member data and write actions are omitted.