Use workspace from plugin context instead of accepting it as parameter

- Removed workspaceId parameter from ctx.folder.list() and ctx.httpRequest.list()
- Updated event handlers to get workspace from plugin context
- Use proper generated TypeScript types in Context interface
This commit is contained in:
Gregory Schier
2025-12-28 14:14:09 -08:00
parent 6d5ba685f1
commit 07d743db21
8 changed files with 60 additions and 30 deletions

File diff suppressed because one or more lines are too long

View File

@@ -12,7 +12,7 @@ export type HttpRequest = { model: "http_request", id: string, createdAt: string
export type HttpRequestHeader = { enabled?: boolean, name: string, value: string, id?: string, };
export type HttpResponse = { model: "http_response", id: string, createdAt: string, updatedAt: string, workspaceId: string, requestId: string, bodyPath: string | null, contentLength: number | null, contentLengthCompressed: number | null, elapsed: number, elapsedHeaders: number, error: string | null, headers: Array<HttpResponseHeader>, remoteAddr: string | null, requestContentLength: number | null, requestHeaders: Array<HttpResponseHeader>, status: number, statusReason: string | null, state: HttpResponseState, url: string, version: string | null, };
export type HttpResponse = { model: "http_response", id: string, createdAt: string, updatedAt: string, workspaceId: string, requestId: string, bodyPath: string | null, contentLength: bigint | null, contentLengthCompressed: bigint | null, elapsed: number, elapsedHeaders: number, error: string | null, headers: Array<HttpResponseHeader>, remoteAddr: string | null, requestContentLength: bigint | null, requestHeaders: Array<HttpResponseHeader>, status: number, statusReason: string | null, state: HttpResponseState, url: string, version: string | null, };
export type HttpResponseHeader = { name: string, value: string, };

View File

@@ -6,6 +6,10 @@ import type {
GetHttpRequestByIdRequest,
GetHttpRequestByIdResponse,
ListCookieNamesResponse,
ListFoldersRequest,
ListFoldersResponse,
ListHttpRequestsRequest,
ListHttpRequestsResponse,
OpenWindowRequest,
PromptTextRequest,
PromptTextResponse,
@@ -57,10 +61,10 @@ export interface Context {
send(args: SendHttpRequestRequest): Promise<SendHttpRequestResponse['httpResponse']>;
getById(args: GetHttpRequestByIdRequest): Promise<GetHttpRequestByIdResponse['httpRequest']>;
render(args: RenderHttpRequestRequest): Promise<RenderHttpRequestResponse['httpRequest']>;
list(args: { workspaceId?: string; folderId?: string }): Promise<Array<any>>;
list(args?: ListHttpRequestsRequest): Promise<ListHttpRequestsResponse['httpRequests']>;
};
folder: {
list(args: { workspaceId?: string }): Promise<Array<any>>;
list(args?: ListFoldersRequest): Promise<ListFoldersResponse['folders']>;
};
httpResponse: {
find(args: FindHttpResponsesRequest): Promise<FindHttpResponsesResponse['httpResponses']>;

View File

@@ -642,22 +642,19 @@ export class PluginInstance {
);
return httpRequest;
},
list: async (args: { workspaceId?: string; folderId?: string }) => {
list: async (args?: { folderId?: string }) => {
const payload = {
type: 'list_http_requests_request',
// plugin events use camelCase field names in Rust -> snake_case mapping
folderId: args.folderId,
workspaceId: args.workspaceId,
folderId: args?.folderId,
} as any;
const { httpRequests } = await this.#sendForReply<any>(context, payload);
return httpRequests as any[];
},
},
folder: {
list: async (args: { workspaceId?: string }) => {
list: async () => {
const payload = {
type: 'list_folders_request',
workspaceId: args.workspaceId,
} as any;
const { folders } = await this.#sendForReply<any>(context, payload);
return folders as any[];

View File

@@ -63,23 +63,25 @@ pub(crate) async fn handle_plugin_event<R: Runtime>(
})))
}
InternalEventPayload::ListHttpRequestsRequest(req) => {
let mut http_requests = Vec::new();
if let Some(folder_id) = req.folder_id {
http_requests =
app_handle.db().list_http_requests_for_folder_recursive(&folder_id)?;
} else if let Some(workspace_id) = req.workspace_id {
http_requests = app_handle.db().list_http_requests(&workspace_id)?;
}
let w = get_window_from_plugin_context(app_handle, &plugin_context)?;
let workspace = workspace_from_window(&w)
.ok_or(PluginErr("Failed to get workspace from window".into()))?;
let http_requests = if let Some(folder_id) = req.folder_id {
app_handle.db().list_http_requests_for_folder_recursive(&folder_id)?
} else {
app_handle.db().list_http_requests(&workspace.id)?
};
Ok(Some(InternalEventPayload::ListHttpRequestsResponse(ListHttpRequestsResponse {
http_requests,
})))
}
InternalEventPayload::ListFoldersRequest(req) => {
let mut folders = Vec::new();
if let Some(workspace_id) = req.workspace_id {
folders = app_handle.db().list_folders(&workspace_id)?;
}
InternalEventPayload::ListFoldersRequest(_req) => {
let w = get_window_from_plugin_context(app_handle, &plugin_context)?;
let workspace = workspace_from_window(&w)
.ok_or(PluginErr("Failed to get workspace from window".into()))?;
let folders = app_handle.db().list_folders(&workspace.id)?;
Ok(Some(InternalEventPayload::ListFoldersResponse(
yaak_plugins::events::ListFoldersResponse { folders },

File diff suppressed because one or more lines are too long

View File

@@ -12,7 +12,7 @@ export type HttpRequest = { model: "http_request", id: string, createdAt: string
export type HttpRequestHeader = { enabled?: boolean, name: string, value: string, id?: string, };
export type HttpResponse = { model: "http_response", id: string, createdAt: string, updatedAt: string, workspaceId: string, requestId: string, bodyPath: string | null, contentLength: number | null, contentLengthCompressed: number | null, elapsed: number, elapsedHeaders: number, error: string | null, headers: Array<HttpResponseHeader>, remoteAddr: string | null, requestContentLength: number | null, requestHeaders: Array<HttpResponseHeader>, status: number, statusReason: string | null, state: HttpResponseState, url: string, version: string | null, };
export type HttpResponse = { model: "http_response", id: string, createdAt: string, updatedAt: string, workspaceId: string, requestId: string, bodyPath: string | null, contentLength: bigint | null, contentLengthCompressed: bigint | null, elapsed: number, elapsedHeaders: number, error: string | null, headers: Array<HttpResponseHeader>, remoteAddr: string | null, requestContentLength: bigint | null, requestHeaders: Array<HttpResponseHeader>, status: number, statusReason: string | null, state: HttpResponseState, url: string, version: string | null, };
export type HttpResponseHeader = { name: string, value: string, };

View File

@@ -1235,8 +1235,6 @@ pub struct FindHttpResponsesResponse {
pub struct ListHttpRequestsRequest {
#[ts(optional)]
pub folder_id: Option<String>,
#[ts(optional)]
pub workspace_id: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
@@ -1249,10 +1247,7 @@ pub struct ListHttpRequestsResponse {
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export, export_to = "gen_events.ts")]
pub struct ListFoldersRequest {
#[ts(optional)]
pub workspace_id: Option<String>,
}
pub struct ListFoldersRequest {}
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
#[serde(default, rename_all = "camelCase")]