@getpaseo/plugin 0.5.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/attachments.d.ts +24 -0
- package/dist/attachments.js +14 -0
- package/dist/client-state.d.ts +14 -0
- package/dist/client-state.js +29 -0
- package/dist/contracts.d.ts +152 -0
- package/dist/contracts.js +2 -0
- package/dist/host.d.ts +34 -0
- package/dist/host.js +30 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/paseo-context.d.ts +8 -0
- package/dist/paseo-context.js +13 -0
- package/dist/rpc-context.d.ts +9 -0
- package/dist/rpc-context.js +15 -0
- package/dist/rpc.d.ts +15 -0
- package/dist/rpc.js +13 -0
- package/dist/server.d.ts +6 -0
- package/dist/server.js +6 -0
- package/dist/shallow.d.ts +2 -0
- package/dist/shallow.js +45 -0
- package/package.json +55 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const PluginAttachmentItemSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
identifier: z.ZodString;
|
|
5
|
+
title: z.ZodString;
|
|
6
|
+
subtitle: z.ZodOptional<z.ZodString>;
|
|
7
|
+
url: z.ZodURL;
|
|
8
|
+
text: z.ZodString;
|
|
9
|
+
resourceType: z.ZodString;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
export declare const PluginAttachmentSearchPayloadSchema: z.ZodObject<{
|
|
12
|
+
items: z.ZodArray<z.ZodObject<{
|
|
13
|
+
id: z.ZodString;
|
|
14
|
+
identifier: z.ZodString;
|
|
15
|
+
title: z.ZodString;
|
|
16
|
+
subtitle: z.ZodOptional<z.ZodString>;
|
|
17
|
+
url: z.ZodURL;
|
|
18
|
+
text: z.ZodString;
|
|
19
|
+
resourceType: z.ZodString;
|
|
20
|
+
}, z.core.$strip>>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
export type PluginAttachmentItem = z.infer<typeof PluginAttachmentItemSchema>;
|
|
23
|
+
export type PluginAttachmentSearchPayload = z.infer<typeof PluginAttachmentSearchPayloadSchema>;
|
|
24
|
+
//# sourceMappingURL=attachments.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const PluginAttachmentItemSchema = z.object({
|
|
3
|
+
id: z.string(),
|
|
4
|
+
identifier: z.string(),
|
|
5
|
+
title: z.string(),
|
|
6
|
+
subtitle: z.string().optional(),
|
|
7
|
+
url: z.url(),
|
|
8
|
+
text: z.string(),
|
|
9
|
+
resourceType: z.string(),
|
|
10
|
+
});
|
|
11
|
+
export const PluginAttachmentSearchPayloadSchema = z.object({
|
|
12
|
+
items: z.array(PluginAttachmentItemSchema),
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=attachments.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { PluginAgentSnapshot, PluginWorkspaceSnapshot } from "./contracts.js";
|
|
3
|
+
export interface PluginClientStateSource {
|
|
4
|
+
subscribe(listener: () => void): () => void;
|
|
5
|
+
getWorkspace(id: string): PluginWorkspaceSnapshot | null;
|
|
6
|
+
getAgent(id: string): PluginAgentSnapshot | null;
|
|
7
|
+
}
|
|
8
|
+
export declare function useWorkspace<Selection>(workspaceId: string, selector: (workspace: PluginWorkspaceSnapshot) => Selection): Selection | null;
|
|
9
|
+
export declare function useAgent<Selection>(agentId: string, selector: (agent: PluginAgentSnapshot) => Selection): Selection | null;
|
|
10
|
+
export declare function PluginClientStateProvider({ children, source, }: {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
source: PluginClientStateSource;
|
|
13
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=client-state.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
|
|
4
|
+
import { shallowEqual } from "./shallow.js";
|
|
5
|
+
const PluginClientStateContext = createContext(null);
|
|
6
|
+
function usePluginEntity(input) {
|
|
7
|
+
const source = useContext(PluginClientStateContext);
|
|
8
|
+
if (!source)
|
|
9
|
+
throw new Error("Plugin state hooks must run inside a workspace panel");
|
|
10
|
+
return useSyncExternalStoreWithSelector(source.subscribe, () => input.read(source, input.id), () => input.read(source, input.id), (entity) => (entity ? input.selector(entity) : null), shallowEqual);
|
|
11
|
+
}
|
|
12
|
+
export function useWorkspace(workspaceId, selector) {
|
|
13
|
+
return usePluginEntity({
|
|
14
|
+
id: workspaceId,
|
|
15
|
+
read: (source, id) => source.getWorkspace(id),
|
|
16
|
+
selector,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export function useAgent(agentId, selector) {
|
|
20
|
+
return usePluginEntity({
|
|
21
|
+
id: agentId,
|
|
22
|
+
read: (source, id) => source.getAgent(id),
|
|
23
|
+
selector,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export function PluginClientStateProvider({ children, source, }) {
|
|
27
|
+
return (_jsx(PluginClientStateContext.Provider, { value: source, children: children }));
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=client-state.js.map
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { ComponentType } from "react";
|
|
2
|
+
import type { PaseoApi } from "@getpaseo/client";
|
|
3
|
+
import type { ZodType, input as ZodInput, output as ZodOutput } from "zod";
|
|
4
|
+
import type { PluginRpcContract } from "./rpc.js";
|
|
5
|
+
export interface PluginTheme {
|
|
6
|
+
readonly colors: {
|
|
7
|
+
readonly surface0: string;
|
|
8
|
+
readonly foreground: string;
|
|
9
|
+
readonly foregroundMuted: string;
|
|
10
|
+
readonly accent: string;
|
|
11
|
+
readonly accentForeground: string;
|
|
12
|
+
readonly statusDanger: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface PluginHostProps {
|
|
16
|
+
theme: PluginTheme;
|
|
17
|
+
host: {
|
|
18
|
+
id: string;
|
|
19
|
+
label: string;
|
|
20
|
+
};
|
|
21
|
+
layout: {
|
|
22
|
+
compact: boolean;
|
|
23
|
+
platform: "ios" | "android" | "web";
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export interface PluginSurfaceProps extends PluginHostProps {
|
|
27
|
+
}
|
|
28
|
+
export interface PluginWorkspaceSnapshot {
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly projectId: string;
|
|
31
|
+
readonly projectDisplayName: string;
|
|
32
|
+
readonly projectRootPath: string;
|
|
33
|
+
readonly directory: string;
|
|
34
|
+
readonly projectKind: "git" | "non_git" | "directory";
|
|
35
|
+
readonly kind: "directory" | "local_checkout" | "checkout" | "worktree";
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly title: string | null;
|
|
38
|
+
readonly status: "needs_input" | "failed" | "running" | "attention" | "done";
|
|
39
|
+
readonly statusEnteredAt: string | null;
|
|
40
|
+
readonly archivingAt: string | null;
|
|
41
|
+
readonly diffStat: {
|
|
42
|
+
readonly additions: number;
|
|
43
|
+
readonly deletions: number;
|
|
44
|
+
} | null;
|
|
45
|
+
}
|
|
46
|
+
export interface PluginAgentSnapshot {
|
|
47
|
+
readonly id: string;
|
|
48
|
+
readonly workspaceId: string;
|
|
49
|
+
readonly provider: string;
|
|
50
|
+
readonly status: "initializing" | "idle" | "running" | "error" | "closed";
|
|
51
|
+
readonly createdAt: string;
|
|
52
|
+
readonly updatedAt: string;
|
|
53
|
+
readonly lastActivityAt: string;
|
|
54
|
+
readonly title: string | null;
|
|
55
|
+
readonly cwd: string;
|
|
56
|
+
readonly model: string | null;
|
|
57
|
+
readonly currentModeId: string | null;
|
|
58
|
+
readonly thinkingOptionId: string | null;
|
|
59
|
+
readonly requiresAttention: boolean;
|
|
60
|
+
readonly attentionReason: "finished" | "error" | "permission" | null;
|
|
61
|
+
readonly parentAgentId: string | null;
|
|
62
|
+
readonly labels: Readonly<Record<string, string>>;
|
|
63
|
+
}
|
|
64
|
+
interface PluginWorkspacePanelBase {
|
|
65
|
+
id: string;
|
|
66
|
+
title: string;
|
|
67
|
+
icon: string;
|
|
68
|
+
}
|
|
69
|
+
export interface PluginWorkspacePanelProps extends PluginHostProps {
|
|
70
|
+
context: "workspace";
|
|
71
|
+
workspaceId: string;
|
|
72
|
+
}
|
|
73
|
+
export interface PluginAgentPanelProps extends PluginHostProps {
|
|
74
|
+
context: "agent";
|
|
75
|
+
workspaceId: string;
|
|
76
|
+
agentId: string;
|
|
77
|
+
}
|
|
78
|
+
export type PluginWorkspacePanelContribution = (PluginWorkspacePanelBase & {
|
|
79
|
+
context: "workspace";
|
|
80
|
+
Component: ComponentType<PluginWorkspacePanelProps>;
|
|
81
|
+
}) | (PluginWorkspacePanelBase & {
|
|
82
|
+
context: "agent";
|
|
83
|
+
Component: ComponentType<PluginAgentPanelProps>;
|
|
84
|
+
});
|
|
85
|
+
export interface PluginSurfaceContribution {
|
|
86
|
+
id: string;
|
|
87
|
+
Component: ComponentType<PluginSurfaceProps>;
|
|
88
|
+
}
|
|
89
|
+
export interface PluginSidebarContribution {
|
|
90
|
+
id: string;
|
|
91
|
+
title: string;
|
|
92
|
+
icon: string;
|
|
93
|
+
surface: string;
|
|
94
|
+
}
|
|
95
|
+
export interface PluginAttachmentSourceContribution {
|
|
96
|
+
id: string;
|
|
97
|
+
title: string;
|
|
98
|
+
icon: string;
|
|
99
|
+
pickerTitle: string;
|
|
100
|
+
searchPlaceholder: string;
|
|
101
|
+
search: PluginRpcContract;
|
|
102
|
+
}
|
|
103
|
+
export interface PluginCommandCapabilities {
|
|
104
|
+
paseo: PaseoApi;
|
|
105
|
+
rpc<InputSchema extends ZodType, OutputSchema extends ZodType>(contract: PluginRpcContract<InputSchema, OutputSchema>, input: ZodInput<InputSchema>): Promise<ZodOutput<OutputSchema>>;
|
|
106
|
+
openSurface(id: string): void;
|
|
107
|
+
}
|
|
108
|
+
export interface PluginGlobalCommandContext extends PluginCommandCapabilities {
|
|
109
|
+
context: "global";
|
|
110
|
+
}
|
|
111
|
+
export interface PluginWorkspaceCommandContext extends PluginCommandCapabilities {
|
|
112
|
+
context: "workspace";
|
|
113
|
+
workspace: PluginWorkspaceSnapshot;
|
|
114
|
+
openPanel(id: string): void;
|
|
115
|
+
}
|
|
116
|
+
export interface PluginAgentCommandContext extends PluginCommandCapabilities {
|
|
117
|
+
context: "agent";
|
|
118
|
+
workspace: PluginWorkspaceSnapshot;
|
|
119
|
+
agent: PluginAgentSnapshot;
|
|
120
|
+
openPanel(id: string): void;
|
|
121
|
+
}
|
|
122
|
+
interface PluginCommandCenterItemBase {
|
|
123
|
+
id: string;
|
|
124
|
+
title: string;
|
|
125
|
+
icon: string;
|
|
126
|
+
keywords?: readonly string[];
|
|
127
|
+
}
|
|
128
|
+
export type PluginCommandCenterItemContribution = (PluginCommandCenterItemBase & {
|
|
129
|
+
context: "global";
|
|
130
|
+
onSelect(context: PluginGlobalCommandContext): void | Promise<void>;
|
|
131
|
+
}) | (PluginCommandCenterItemBase & {
|
|
132
|
+
context: "workspace";
|
|
133
|
+
onSelect(context: PluginWorkspaceCommandContext): void | Promise<void>;
|
|
134
|
+
}) | (PluginCommandCenterItemBase & {
|
|
135
|
+
context: "agent";
|
|
136
|
+
onSelect(context: PluginAgentCommandContext): void | Promise<void>;
|
|
137
|
+
});
|
|
138
|
+
export interface PluginHandlerContext {
|
|
139
|
+
paseo: PaseoApi;
|
|
140
|
+
}
|
|
141
|
+
export interface PluginContext {
|
|
142
|
+
handle<InputSchema extends ZodType, OutputSchema extends ZodType>(contract: PluginRpcContract<InputSchema, OutputSchema>, handler: (input: ZodOutput<InputSchema>, context: PluginHandlerContext) => ZodInput<OutputSchema> | Promise<ZodInput<OutputSchema>>): void;
|
|
143
|
+
addSurface(id: string, Component: ComponentType<PluginSurfaceProps>): void;
|
|
144
|
+
addSidebarItem(contribution: PluginSidebarContribution): void;
|
|
145
|
+
addWorkspacePanel(contribution: PluginWorkspacePanelContribution): void;
|
|
146
|
+
addCommandCenterItem(contribution: PluginCommandCenterItemContribution): void;
|
|
147
|
+
addAttachmentSource(contribution: PluginAttachmentSourceContribution): void;
|
|
148
|
+
}
|
|
149
|
+
export type PluginCleanup = () => void | Promise<void>;
|
|
150
|
+
export type PluginContribution = (plugin: PluginContext) => PluginCleanup;
|
|
151
|
+
export {};
|
|
152
|
+
//# sourceMappingURL=contracts.d.ts.map
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export { PluginClientStateProvider, type PluginClientStateSource } from "./client-state.js";
|
|
2
|
+
import type { PluginAttachmentSourceContribution, PluginCommandCenterItemContribution, PluginContext, PluginSidebarContribution, PluginSurfaceContribution, PluginSurfaceProps, PluginWorkspacePanelContribution } from "./contracts.js";
|
|
3
|
+
import { PluginRpcProvider } from "./rpc-context.js";
|
|
4
|
+
import { PaseoApiProvider } from "./paseo-context.js";
|
|
5
|
+
import { callPluginRpc } from "./rpc.js";
|
|
6
|
+
import type { ComponentType } from "react";
|
|
7
|
+
interface PluginCollector {
|
|
8
|
+
addSurface(id: string, Component: ComponentType<PluginSurfaceProps>): void;
|
|
9
|
+
addSidebarItem(contribution: PluginSidebarContribution): void;
|
|
10
|
+
addWorkspacePanel(contribution: PluginWorkspacePanelContribution): void;
|
|
11
|
+
addCommandCenterItem(contribution: PluginCommandCenterItemContribution): void;
|
|
12
|
+
addAttachmentSource(contribution: PluginAttachmentSourceContribution): void;
|
|
13
|
+
}
|
|
14
|
+
export interface PluginRegistrationCollector {
|
|
15
|
+
surfaces: PluginSurfaceContribution[];
|
|
16
|
+
sidebarItems: PluginSidebarContribution[];
|
|
17
|
+
workspacePanels: PluginWorkspacePanelContribution[];
|
|
18
|
+
commandCenterItems: PluginCommandCenterItemContribution[];
|
|
19
|
+
attachmentSources: PluginAttachmentSourceContribution[];
|
|
20
|
+
}
|
|
21
|
+
export declare function createPluginContext(collector: PluginCollector): Pick<PluginContext, "addSurface" | "addSidebarItem" | "addWorkspacePanel" | "addCommandCenterItem" | "addAttachmentSource">;
|
|
22
|
+
export declare function searchPluginAttachments(source: PluginAttachmentSourceContribution, invoke: (method: string, input: unknown) => Promise<unknown>, query: string): Promise<{
|
|
23
|
+
items: {
|
|
24
|
+
id: string;
|
|
25
|
+
identifier: string;
|
|
26
|
+
title: string;
|
|
27
|
+
url: string;
|
|
28
|
+
text: string;
|
|
29
|
+
resourceType: string;
|
|
30
|
+
subtitle?: string | undefined;
|
|
31
|
+
}[];
|
|
32
|
+
}>;
|
|
33
|
+
export { callPluginRpc, PaseoApiProvider, PluginRpcProvider };
|
|
34
|
+
//# sourceMappingURL=host.d.ts.map
|
package/dist/host.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { PluginAttachmentSearchPayloadSchema } from "./attachments.js";
|
|
2
|
+
export { PluginClientStateProvider } from "./client-state.js";
|
|
3
|
+
import { PluginRpcProvider } from "./rpc-context.js";
|
|
4
|
+
import { PaseoApiProvider } from "./paseo-context.js";
|
|
5
|
+
import { callPluginRpc } from "./rpc.js";
|
|
6
|
+
export function createPluginContext(collector) {
|
|
7
|
+
return {
|
|
8
|
+
addSurface(id, Component) {
|
|
9
|
+
collector.addSurface(id, Component);
|
|
10
|
+
},
|
|
11
|
+
addSidebarItem(contribution) {
|
|
12
|
+
collector.addSidebarItem(contribution);
|
|
13
|
+
},
|
|
14
|
+
addWorkspacePanel(contribution) {
|
|
15
|
+
collector.addWorkspacePanel(contribution);
|
|
16
|
+
},
|
|
17
|
+
addCommandCenterItem(contribution) {
|
|
18
|
+
collector.addCommandCenterItem(contribution);
|
|
19
|
+
},
|
|
20
|
+
addAttachmentSource(contribution) {
|
|
21
|
+
collector.addAttachmentSource(contribution);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export async function searchPluginAttachments(source, invoke, query) {
|
|
26
|
+
const output = await callPluginRpc(source.search, invoke, { query });
|
|
27
|
+
return PluginAttachmentSearchPayloadSchema.parseAsync(output);
|
|
28
|
+
}
|
|
29
|
+
export { callPluginRpc, PaseoApiProvider, PluginRpcProvider };
|
|
30
|
+
//# sourceMappingURL=host.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { PluginAttachmentItemSchema, PluginAttachmentSearchPayloadSchema, defineAttachmentSource, defineRpc, type PluginAttachmentItem, type PluginAttachmentSearchPayload, type PluginRpcContract, } from "./server.js";
|
|
2
|
+
export type { PluginAttachmentSourceContribution, PluginAgentCommandContext, PluginAgentPanelProps, PluginAgentSnapshot, PluginCleanup, PluginCommandCapabilities, PluginCommandCenterItemContribution, PluginContribution, PluginContext, PluginGlobalCommandContext, PluginHandlerContext, PluginHostProps, PluginTheme, PluginSidebarContribution, PluginSurfaceContribution, PluginSurfaceProps, PluginWorkspaceCommandContext, PluginWorkspacePanelContribution, PluginWorkspacePanelProps, PluginWorkspaceSnapshot, } from "./contracts.js";
|
|
3
|
+
export { usePaseo } from "./paseo-context.js";
|
|
4
|
+
export { useAgent, useWorkspace } from "./client-state.js";
|
|
5
|
+
export { useRpc } from "./rpc-context.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { PluginAttachmentItemSchema, PluginAttachmentSearchPayloadSchema, defineAttachmentSource, defineRpc, } from "./server.js";
|
|
2
|
+
export { usePaseo } from "./paseo-context.js";
|
|
3
|
+
export { useAgent, useWorkspace } from "./client-state.js";
|
|
4
|
+
export { useRpc } from "./rpc-context.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PaseoApi } from "@getpaseo/client";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
export declare function PaseoApiProvider({ children, paseo }: {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
paseo: PaseoApi;
|
|
6
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare function usePaseo(): PaseoApi;
|
|
8
|
+
//# sourceMappingURL=paseo-context.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
const PaseoApiContext = createContext(null);
|
|
4
|
+
export function PaseoApiProvider({ children, paseo }) {
|
|
5
|
+
return _jsx(PaseoApiContext.Provider, { value: paseo, children: children });
|
|
6
|
+
}
|
|
7
|
+
export function usePaseo() {
|
|
8
|
+
const paseo = useContext(PaseoApiContext);
|
|
9
|
+
if (!paseo)
|
|
10
|
+
throw new Error("usePaseo must run inside a contributed plugin surface");
|
|
11
|
+
return paseo;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=paseo-context.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { ZodType, input as ZodInput, output as ZodOutput } from "zod";
|
|
3
|
+
import { type PluginRpcContract } from "./rpc.js";
|
|
4
|
+
export declare function PluginRpcProvider({ children, invoke, }: {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
invoke(method: string, input: unknown): Promise<unknown>;
|
|
7
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare function useRpc<InputSchema extends ZodType, OutputSchema extends ZodType>(contract: PluginRpcContract<InputSchema, OutputSchema>): (input: ZodInput<InputSchema>) => Promise<ZodOutput<OutputSchema>>;
|
|
9
|
+
//# sourceMappingURL=rpc-context.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useMemo } from "react";
|
|
3
|
+
import { callPluginRpc } from "./rpc.js";
|
|
4
|
+
const PluginRpcContext = createContext(null);
|
|
5
|
+
export function PluginRpcProvider({ children, invoke, }) {
|
|
6
|
+
const value = useMemo(() => ({ invoke }), [invoke]);
|
|
7
|
+
return _jsx(PluginRpcContext.Provider, { value: value, children: children });
|
|
8
|
+
}
|
|
9
|
+
export function useRpc(contract) {
|
|
10
|
+
const context = useContext(PluginRpcContext);
|
|
11
|
+
if (!context)
|
|
12
|
+
throw new Error("useRpc must run inside a contributed plugin surface");
|
|
13
|
+
return useCallback((input) => callPluginRpc(contract, context.invoke, input), [context, contract]);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=rpc-context.js.map
|
package/dist/rpc.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ZodType, input as ZodInput, output as ZodOutput } from "zod";
|
|
2
|
+
export interface PluginRpcContract<InputSchema extends ZodType = ZodType, OutputSchema extends ZodType = ZodType> {
|
|
3
|
+
name: string;
|
|
4
|
+
input: InputSchema;
|
|
5
|
+
output: OutputSchema;
|
|
6
|
+
}
|
|
7
|
+
interface RpcDefinition<InputSchema extends ZodType, OutputSchema extends ZodType> {
|
|
8
|
+
name: string;
|
|
9
|
+
input: InputSchema;
|
|
10
|
+
output: OutputSchema;
|
|
11
|
+
}
|
|
12
|
+
export declare function defineRpc<InputSchema extends ZodType, OutputSchema extends ZodType>(definition: RpcDefinition<InputSchema, OutputSchema>): PluginRpcContract<InputSchema, OutputSchema>;
|
|
13
|
+
export declare function callPluginRpc<InputSchema extends ZodType, OutputSchema extends ZodType>(contract: PluginRpcContract<InputSchema, OutputSchema>, invoke: (method: string, input: unknown) => Promise<unknown>, input: ZodInput<InputSchema>): Promise<ZodOutput<OutputSchema>>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=rpc.d.ts.map
|
package/dist/rpc.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const RPC_NAME = /^[a-z][a-z0-9._-]*$/;
|
|
2
|
+
export function defineRpc(definition) {
|
|
3
|
+
const name = definition.name.trim();
|
|
4
|
+
if (!RPC_NAME.test(name))
|
|
5
|
+
throw new Error(`Invalid plugin RPC method: ${definition.name}`);
|
|
6
|
+
return { ...definition, name };
|
|
7
|
+
}
|
|
8
|
+
export async function callPluginRpc(contract, invoke, input) {
|
|
9
|
+
const parsedInput = await contract.input.parseAsync(input);
|
|
10
|
+
const output = await invoke(contract.name, parsedInput);
|
|
11
|
+
return contract.output.parseAsync(output);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=rpc.js.map
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PluginAttachmentSourceContribution } from "./contracts.js";
|
|
2
|
+
export { PluginAttachmentItemSchema, PluginAttachmentSearchPayloadSchema, type PluginAttachmentItem, type PluginAttachmentSearchPayload, } from "./attachments.js";
|
|
3
|
+
export type { PluginAttachmentSourceContribution, PluginHandlerContext } from "./contracts.js";
|
|
4
|
+
export { defineRpc, type PluginRpcContract } from "./rpc.js";
|
|
5
|
+
export declare function defineAttachmentSource<Definition extends PluginAttachmentSourceContribution>(definition: Definition): Definition;
|
|
6
|
+
//# sourceMappingURL=server.d.ts.map
|
package/dist/server.js
ADDED
package/dist/shallow.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
function isIterable(value) {
|
|
2
|
+
return Symbol.iterator in value;
|
|
3
|
+
}
|
|
4
|
+
function hasEntries(value) {
|
|
5
|
+
return "entries" in value;
|
|
6
|
+
}
|
|
7
|
+
function compareEntries(left, right) {
|
|
8
|
+
const leftEntries = left instanceof Map ? left : new Map(left.entries());
|
|
9
|
+
const rightEntries = right instanceof Map ? right : new Map(right.entries());
|
|
10
|
+
if (leftEntries.size !== rightEntries.size)
|
|
11
|
+
return false;
|
|
12
|
+
for (const [key, value] of leftEntries) {
|
|
13
|
+
if (!rightEntries.has(key) || !Object.is(value, rightEntries.get(key)))
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
function compareIterables(left, right) {
|
|
19
|
+
const leftIterator = left[Symbol.iterator]();
|
|
20
|
+
const rightIterator = right[Symbol.iterator]();
|
|
21
|
+
let leftValue = leftIterator.next();
|
|
22
|
+
let rightValue = rightIterator.next();
|
|
23
|
+
while (!leftValue.done && !rightValue.done) {
|
|
24
|
+
if (!Object.is(leftValue.value, rightValue.value))
|
|
25
|
+
return false;
|
|
26
|
+
leftValue = leftIterator.next();
|
|
27
|
+
rightValue = rightIterator.next();
|
|
28
|
+
}
|
|
29
|
+
return Boolean(leftValue.done && rightValue.done);
|
|
30
|
+
}
|
|
31
|
+
export function shallowEqual(left, right) {
|
|
32
|
+
if (Object.is(left, right))
|
|
33
|
+
return true;
|
|
34
|
+
if (!left || !right || typeof left !== "object" || typeof right !== "object")
|
|
35
|
+
return false;
|
|
36
|
+
if (Object.getPrototypeOf(left) !== Object.getPrototypeOf(right))
|
|
37
|
+
return false;
|
|
38
|
+
if (isIterable(left) && isIterable(right)) {
|
|
39
|
+
if (hasEntries(left) && hasEntries(right))
|
|
40
|
+
return compareEntries(left, right);
|
|
41
|
+
return compareIterables(left, right);
|
|
42
|
+
}
|
|
43
|
+
return compareEntries({ entries: () => Object.entries(left) }, { entries: () => Object.entries(right) });
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=shallow.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@getpaseo/plugin",
|
|
3
|
+
"version": "0.5.0-beta.2",
|
|
4
|
+
"description": "Paseo plugin SDK package",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist",
|
|
7
|
+
"!dist/**/*.map"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"source": "./src/index.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./server": {
|
|
17
|
+
"types": "./dist/server.d.ts",
|
|
18
|
+
"source": "./src/server.ts",
|
|
19
|
+
"default": "./dist/server.js"
|
|
20
|
+
},
|
|
21
|
+
"./host": {
|
|
22
|
+
"types": "./dist/host.d.ts",
|
|
23
|
+
"source": "./src/host.ts",
|
|
24
|
+
"default": "./dist/host.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"clean": "node ../../scripts/clean-package-dist.mjs",
|
|
32
|
+
"build": "tsc -p tsconfig.json --incremental false",
|
|
33
|
+
"build:clean": "npm run clean && npm run build",
|
|
34
|
+
"prepack": "npm run build:clean",
|
|
35
|
+
"typecheck": "tsgo --noEmit && tsgo -p tsconfig.examples.json --noEmit",
|
|
36
|
+
"test": "vitest run"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"use-sync-external-store": "^1.6.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@getpaseo/client": "0.5.0-beta.2",
|
|
43
|
+
"@types/node": "^20.9.0",
|
|
44
|
+
"@types/react": "~19.2.0",
|
|
45
|
+
"react": "19.1.0",
|
|
46
|
+
"typescript": "^5.9.3",
|
|
47
|
+
"vitest": "^4.1.6",
|
|
48
|
+
"zod": "^4.4.3"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@getpaseo/client": "0.5.0-beta.2",
|
|
52
|
+
"react": "19.1.0",
|
|
53
|
+
"zod": "^4.4.3"
|
|
54
|
+
}
|
|
55
|
+
}
|