11import { consume } from "@lit/context" ;
22import { initialState , Task } from "@lit/task" ;
3- import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice" ;
43import { html , nothing } from "lit" ;
54import { property } from "lit/decorators.js" ;
6- import type { GatewaySessionRow , SessionsListResult } from "../../api/types.ts" ;
75import { applicationContext , type ApplicationGatewaySnapshot } from "../../app/context.ts" ;
8- import { loadSettings } from "../../app/settings.ts" ;
96import { renderHubTabs } from "../../components/hub-tabs.ts" ;
107import "../../components/tooltip.ts" ;
118import { t } from "../../i18n/index.ts" ;
12- import { canCallGatewayMethod } from "../../lib/gateway-methods.ts" ;
13- import { readSessionMethodAccess } from "../../lib/session-method-access.ts" ;
14- import { resolveSessionKey } from "../../lib/sessions/index.ts" ;
159import { sessionNavigationTarget } from "../../lib/sessions/route-navigation.ts" ;
1610import { normalizeAgentId } from "../../lib/sessions/session-key.ts" ;
1711import { filterSkillWorkshopProposals } from "../../lib/skill-workshop/index.ts" ;
1812import { OpenClawLightDomElement } from "../../lit/openclaw-element.ts" ;
1913import { SubscriptionsController } from "../../lit/subscriptions-controller.ts" ;
2014import { PLUGINS_HUB_PANEL_ID , pluginsHubTabs } from "../plugins/plugins-hub.ts" ;
15+ import { canCallWorkshopAdminMethod , resolveWorkshopAccess } from "./access.ts" ;
2116import { renderSkillWorkshopHeaderControls , setSkillWorkshopMode } from "./header-controls.ts" ;
2217import {
2318 loadSkillWorkshopPageData ,
2419 runSkillWorkshopPageHistoryScan ,
2520} from "./history-scan-page-controller.ts" ;
26- import type {
27- SkillWorkshopProposal ,
28- SkillWorkshopRenderContext ,
29- SkillWorkshopRevisionRequest ,
30- } from "./page-types.ts" ;
21+ import type { SkillWorkshopRenderContext , SkillWorkshopRevisionRequest } from "./page-types.ts" ;
3122import { selectPluginsHubTab } from "./plugins-hub-navigation.ts" ;
3223import {
3324 countSkillWorkshopProposals ,
@@ -39,6 +30,7 @@ import {
3930 type SkillWorkshopRouteData ,
4031 type SkillWorkshopState ,
4132} from "./proposals.ts" ;
33+ import { resolveSkillWorkshopRevisionSessionKey } from "./revision-session.ts" ;
4234import { resolveSelfLearning , setSelfLearningEnabled } from "./self-learning.ts" ;
4335import {
4436 captureSkillWorkshopSourceScope ,
@@ -49,76 +41,6 @@ import {
4941import { loadSkillWorkshopMode , loadSkillWorkshopUseCurrentChatForRevisions } from "./storage.ts" ;
5042import { renderSkillWorkshop } from "./view.ts" ;
5143
52- function findRevisionSessionRow (
53- result : SessionsListResult | null ,
54- sessionKey : string | undefined ,
55- ) : GatewaySessionRow | null {
56- const key = sessionKey ?. trim ( ) ;
57- return key ? ( result ?. sessions . find ( ( row ) => row . key === key ) ?? null ) : null ;
58- }
59-
60- function isUsableRevisionSession ( row : GatewaySessionRow | null ) : row is GatewaySessionRow {
61- return Boolean ( row && ! row . archived && ! row . hasActiveRun ) ;
62- }
63-
64- async function loadRevisionSessionsForAgent (
65- context : SkillWorkshopPageContext ,
66- agentId : string ,
67- ) : Promise < SessionsListResult | null > {
68- const current = context . sessions . state ;
69- if ( current . agentId === agentId && current . result ?. sessions . length ) {
70- return current . result ;
71- }
72- return context . sessions . list ( { agentId } ) ;
73- }
74-
75- async function resolveRevisionSessionKey (
76- state : SkillWorkshopState ,
77- context : SkillWorkshopPageContext ,
78- proposal : SkillWorkshopProposal ,
79- proposalAgentId : string ,
80- isCurrent : ( ) => boolean ,
81- ) : Promise < string | null > {
82- if ( ! isCurrent ( ) ) {
83- return null ;
84- }
85- const gatewayHello = context . gateway . snapshot . hello ;
86- if ( state . skillWorkshopUseCurrentChatForRevisions ) {
87- return resolveSessionKey ( loadSettings ( ) . sessionKey , gatewayHello ) . trim ( ) || null ;
88- }
89-
90- const agentId = normalizeAgentId ( proposal . origin ?. agentId ?? proposalAgentId ) ;
91- const sessions = await loadRevisionSessionsForAgent ( context , agentId ) ;
92- if ( ! isCurrent ( ) ) {
93- return null ;
94- }
95- const originRow = findRevisionSessionRow ( sessions , proposal . origin ?. sessionKey ) ;
96- if ( isUsableRevisionSession ( originRow ) ) {
97- return originRow . key ;
98- }
99-
100- const createParams = {
101- agentId,
102- label : truncateUtf16Safe ( `Skill Workshop: ${ proposal . slug || proposal . key } ` , 80 ) ,
103- } ;
104- const createAccess = readSessionMethodAccess ( context . gateway . snapshot , {
105- method : "sessions.create" ,
106- params : createParams ,
107- } ) ;
108- if ( ! createAccess . allowed ) {
109- throw new Error ( createAccess . reason ) ;
110- }
111- if ( ! isCurrent ( ) ) {
112- return null ;
113- }
114- const createdKey = await context . sessions . create ( createParams ) ;
115- const sessionKey = resolveSessionKey ( createdKey , gatewayHello ) . trim ( ) ;
116- if ( ! sessionKey ) {
117- throw new Error ( context . sessions . state . error ?? "Could not prepare a Skill Workshop thread." ) ;
118- }
119- return sessionKey ;
120- }
121-
12244function renderSkillWorkshopPage (
12345 state : SkillWorkshopState ,
12446 renderContext : SkillWorkshopRenderContext ,
@@ -137,15 +59,7 @@ function renderSkillWorkshopPage(
13759 state . skillWorkshopMode === "today"
13860 ? "content--skill-workshop content--skill-workshop-today"
13961 : "content--skill-workshop" ;
140- const canCall = ( method : string ) =>
141- canCallGatewayMethod ( context . gateway . snapshot , method , "operator.admin" ) ;
142- const access = {
143- canEvaluate : canCall ( "skills.proposals.evaluate" ) ,
144- canApply : canCall ( "skills.proposals.apply" ) ,
145- canRevise : canCall ( "skills.proposals.requestRevision" ) ,
146- canReject : canCall ( "skills.proposals.reject" ) ,
147- canScanHistory : canCall ( "skills.proposals.historyScan" ) ,
148- } ;
62+ const access = resolveWorkshopAccess ( context . gateway . snapshot ) ;
14963
15064 return html `
15165 < section class =${ pageClass } >
@@ -280,7 +194,9 @@ function renderSkillWorkshopPage(
280194 onPrev : ( ) => selectRelativeProposal ( - 1 ) ,
281195 onNext : ( ) => selectRelativeProposal ( 1 ) ,
282196 onApply : ( key ) => {
283- if ( ! canCall ( "skills.proposals.apply" ) ) {
197+ if (
198+ ! canCallWorkshopAdminMethod ( context . gateway . snapshot , "skills.proposals.apply" )
199+ ) {
284200 return ;
285201 }
286202 void runSkillWorkshopLifecycleAction ( state , context , "apply" , key ) . finally (
@@ -289,22 +205,31 @@ function renderSkillWorkshopPage(
289205 requestUpdate ( ) ;
290206 } ,
291207 onEvaluate : ( key ) => {
292- if ( ! canCall ( "skills.proposals.evaluate" ) ) {
208+ if (
209+ ! canCallWorkshopAdminMethod ( context . gateway . snapshot , "skills.proposals.evaluate" )
210+ ) {
293211 return ;
294212 }
295213 void runSkillWorkshopEvaluation ( state , context , key ) . finally ( requestUpdate ) ;
296214 requestUpdate ( ) ;
297215 } ,
298216 onRevise : ( key ) => {
299- if ( ! canCall ( "skills.proposals.requestRevision" ) ) {
217+ if (
218+ ! canCallWorkshopAdminMethod (
219+ context . gateway . snapshot ,
220+ "skills.proposals.requestRevision" ,
221+ )
222+ ) {
300223 return ;
301224 }
302225 state . skillWorkshopRevisionKey = key ;
303226 state . skillWorkshopRevisionDraft = "" ;
304227 requestUpdate ( ) ;
305228 } ,
306229 onReject : ( key ) => {
307- if ( ! canCall ( "skills.proposals.reject" ) ) {
230+ if (
231+ ! canCallWorkshopAdminMethod ( context . gateway . snapshot , "skills.proposals.reject" )
232+ ) {
308233 return ;
309234 }
310235 void runSkillWorkshopLifecycleAction ( state , context , "reject" , key ) . finally (
@@ -322,7 +247,11 @@ function renderSkillWorkshopPage(
322247 requestUpdate ( ) ;
323248 } ,
324249 onRevisionSubmit : ( key ) =>
325- onRevisionRequest && canCall ( "skills.proposals.requestRevision" )
250+ onRevisionRequest &&
251+ canCallWorkshopAdminMethod (
252+ context . gateway . snapshot ,
253+ "skills.proposals.requestRevision" ,
254+ )
326255 ? void requestSkillWorkshopRevision (
327256 state ,
328257 context ,
@@ -507,7 +436,7 @@ class SkillWorkshopPage extends OpenClawLightDomElement {
507436 }
508437 let sessionKey : string | null ;
509438 try {
510- sessionKey = await resolveRevisionSessionKey (
439+ sessionKey = await resolveSkillWorkshopRevisionSessionKey (
511440 scope . state ,
512441 scope . context ,
513442 proposal ,
@@ -656,11 +585,7 @@ class SkillWorkshopPage extends OpenClawLightDomElement {
656585
657586 private readonly handleHistoryScan = ( ) => {
658587 if (
659- ! canCallGatewayMethod (
660- this . context ?. gateway ?. snapshot ,
661- "skills.proposals.historyScan" ,
662- "operator.admin" ,
663- )
588+ ! canCallWorkshopAdminMethod ( this . context ?. gateway ?. snapshot , "skills.proposals.historyScan" )
664589 ) {
665590 return ;
666591 }
@@ -685,7 +610,7 @@ class SkillWorkshopPage extends OpenClawLightDomElement {
685610 } ;
686611
687612 private async applySelfLearningToggle ( enabled : boolean ) : Promise < void > {
688- if ( ! canCallGatewayMethod ( this . context ?. gateway ?. snapshot , "config.patch" , "operator.admin ") ) {
613+ if ( ! canCallWorkshopAdminMethod ( this . context ?. gateway ?. snapshot , "config.patch" ) ) {
689614 return ;
690615 }
691616 const runtimeConfig = this . context ?. runtimeConfig ;
@@ -731,7 +656,7 @@ class SkillWorkshopPage extends OpenClawLightDomElement {
731656 this . context . runtimeConfig ,
732657 this . selfLearningBusy ,
733658 this . selfLearningError ,
734- canCallGatewayMethod ( this . context . gateway . snapshot , "config.patch" , "operator.admin ") ,
659+ canCallWorkshopAdminMethod ( this . context . gateway . snapshot , "config.patch" ) ,
735660 ) ,
736661 onSelfLearningToggle : this . handleSelfLearningToggle ,
737662 onHistoryScan : this . handleHistoryScan ,
0 commit comments