forked from openclaw/openclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-facades.ts
More file actions
60 lines (58 loc) · 2.15 KB
/
Copy pathapi-facades.ts
File metadata and controls
60 lines (58 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import type { OpenClawPluginApi } from "./types.js";
type PluginApiFacadeFields = Pick<
OpenClawPluginApi,
"agent" | "lifecycle" | "runContext" | "session"
>;
export type OpenClawPluginApiWithoutFacades = Omit<OpenClawPluginApi, keyof PluginApiFacadeFields>;
type PluginApiFacadeSource = Pick<
OpenClawPluginApi,
| "clearRunContext"
| "emitAgentEvent"
| "enqueueNextTurnInjection"
| "getRunContext"
| "registerAgentEventSubscription"
| "registerControlUiDescriptor"
| "registerRuntimeLifecycle"
| "registerSessionAction"
| "registerSessionExtension"
| "registerSessionSchedulerJob"
| "scheduleSessionTurn"
| "sendSessionAttachment"
| "setRunContext"
| "unscheduleSessionTurnsByTag"
>;
export function attachPluginApiFacades<T extends object>(
api: T & PluginApiFacadeSource & Partial<PluginApiFacadeFields>,
): T & PluginApiFacadeFields {
api.session = {
state: {
registerSessionExtension: (...args) => api.registerSessionExtension(...args),
},
workflow: {
enqueueNextTurnInjection: (...args) => api.enqueueNextTurnInjection(...args),
registerSessionSchedulerJob: (...args) => api.registerSessionSchedulerJob(...args),
sendSessionAttachment: (...args) => api.sendSessionAttachment(...args),
scheduleSessionTurn: (...args) => api.scheduleSessionTurn(...args),
unscheduleSessionTurnsByTag: (...args) => api.unscheduleSessionTurnsByTag(...args),
},
controls: {
registerSessionAction: (...args) => api.registerSessionAction(...args),
registerControlUiDescriptor: (...args) => api.registerControlUiDescriptor(...args),
},
};
api.agent = {
events: {
registerAgentEventSubscription: (...args) => api.registerAgentEventSubscription(...args),
emitAgentEvent: (...args) => api.emitAgentEvent(...args),
},
};
api.runContext = {
setRunContext: (...args) => api.setRunContext(...args),
getRunContext: (...args) => api.getRunContext(...args),
clearRunContext: (...args) => api.clearRunContext(...args),
};
api.lifecycle = {
registerRuntimeLifecycle: (...args) => api.registerRuntimeLifecycle(...args),
};
return api as T & PluginApiFacadeFields;
}