@@ -14,12 +14,67 @@ Needs[ "Wolfram`AgentTools`Common`" ];
1414$toolUIAssociations = < |
1515 "NotebookViewer" -> "ui://wolfram/notebook-viewer" ,
1616 "MCPAppsTest" -> "ui://wolfram/mcp-apps-test" ,
17- "WolframAlpha" -> "ui://wolfram/wolframalpha-viewer" ,
18- "WolframLanguageEvaluator" -> "ui://wolfram/evaluator-viewer"
17+ "WolframLanguageEvaluator" -> "ui://wolfram/evaluator-viewer" ,
18+ (* The WolframAlpha tool does not have a text-only fallback app view, so we make it conditional *)
19+ "WolframAlpha" :> If [ $deployCloudNotebooks , "ui://wolfram/wolframalpha-viewer" , None ]
1920|> ;
2021
22+ $deployedNotebookRoot = "AgentTools/Notebooks" ;
23+ $deployCloudNotebooks := $deployCloudNotebooks = $CloudConnected ; (* must be connected to deploy notebooks *)
24+
2125(* ::**************************************************************************************************************:: *)
2226(* ::Section::Closed:: *)
27+ (*Cloud Notebooks*)
28+
29+ (* ::**************************************************************************************************************:: *)
30+ (* ::Subsection::Closed:: *)
31+ (*deployCloudNotebookForMCPApp*)
32+ deployCloudNotebookForMCPApp // beginDefinition ;
33+
34+ deployCloudNotebookForMCPApp [ nb_ Notebook , identifier_ ] := Enclose [
35+ Module [ { hash , target , deployed },
36+
37+ (* This should be true if this function is being called: *)
38+ ConfirmAssert [ $deployCloudNotebooks , "DeployCloudNotebooksAssert" ];
39+
40+ hash = ConfirmBy [ Hash [ Unevaluated @ identifier , Automatic , "HexString" ], StringQ , "Hash" ];
41+
42+ target = ConfirmMatch [
43+ FileNameJoin @ {
44+ CloudObject [ $deployedNotebookRoot , Permissions -> { "All" -> { "Read" , "Interact" } } ],
45+ hash <> ".nb"
46+ },
47+ _ CloudObject ,
48+ "Target"
49+ ];
50+
51+ deployed = CloudDeploy [
52+ nb ,
53+ target ,
54+ AppearanceElements -> None ,
55+ AutoRemove -> True ,
56+ IconRules -> { },
57+ Permissions -> { "All" -> { "Read" , "Interact" } }
58+ ];
59+
60+ If [ MatchQ [ deployed , _ CloudObject ],
61+ ConfirmBy [ First @ deployed , StringQ , "Result" ],
62+ (* If deploying failed, disable cloud notebook deployment for the remainder of the session: *)
63+ $deployCloudNotebooks = False ;
64+ $Failed
65+ ]
66+ ],
67+ throwInternalFailure
68+ ];
69+
70+ deployCloudNotebookForMCPApp // endDefinition ;
71+
72+ (* ::**************************************************************************************************************:: *)
73+ (* ::Section::Closed:: *)
74+ (*MCP Integration Helpers*)
75+
76+ (* ::**************************************************************************************************************:: *)
77+ (* ::Subsection::Closed:: *)
2378(*clientSupportsUIQ*)
2479clientSupportsUIQ // beginDefinition ;
2580
@@ -31,7 +86,7 @@ clientSupportsUIQ[ _ ] := False;
3186clientSupportsUIQ // endDefinition ;
3287
3388(* ::**************************************************************************************************************:: *)
34- (* ::Section ::Closed:: *)
89+ (* ::Subsection ::Closed:: *)
3590(*mcpAppsEnabledQ*)
3691mcpAppsEnabledQ // beginDefinition ;
3792
@@ -43,7 +98,7 @@ mcpAppsEnabledQ[ ] :=
4398mcpAppsEnabledQ // endDefinition ;
4499
45100(* ::**************************************************************************************************************:: *)
46- (* ::Section ::Closed:: *)
101+ (* ::Subsection ::Closed:: *)
47102(*initializeUIResources*)
48103initializeUIResources // beginDefinition ;
49104
@@ -98,7 +153,7 @@ loadUIResource[ htmlFile_String ] := Enclose[
98153loadUIResource // endDefinition ;
99154
100155(* ::**************************************************************************************************************:: *)
101- (* ::Section ::Closed:: *)
156+ (* ::Subsection ::Closed:: *)
102157(*listUIResources*)
103158listUIResources // beginDefinition ;
104159
@@ -121,7 +176,7 @@ listUIResources[ ] :=
121176listUIResources // endDefinition ;
122177
123178(* ::**************************************************************************************************************:: *)
124- (* ::Section ::Closed:: *)
179+ (* ::Subsection ::Closed:: *)
125180(*readUIResource*)
126181readUIResource // beginDefinition ;
127182
@@ -147,7 +202,7 @@ readUIResource[ msg_Association, req_ ] := Enclose[
147202readUIResource // endDefinition ;
148203
149204(* ::**************************************************************************************************************:: *)
150- (* ::Section ::Closed:: *)
205+ (* ::Subsection ::Closed:: *)
151206(*toolUIMetadata*)
152207toolUIMetadata // beginDefinition ;
153208
@@ -165,7 +220,7 @@ toolUIMetadata[ toolName_String, None ] := { };
165220toolUIMetadata // endDefinition ;
166221
167222(* ::**************************************************************************************************************:: *)
168- (* ::Section ::Closed:: *)
223+ (* ::Subsection ::Closed:: *)
169224(*withToolUIMetadata*)
170225withToolUIMetadata // beginDefinition ;
171226
0 commit comments